Game Development Community

Jagged edges on specular highlights

by Rob Evans · in Torque Game Engine Advanced · 07/18/2007 (8:38 am) · 17 replies

Hi, I've just got hold of TSE and have been playing around with the materials. Could someone explain why I'm getting a jagged effect on my planet? See image:

v2.wastedwebspace.co.uk/gamedev/planet_problem.png
My material definition looks like this:

new Material(PlanetBump)
{
   
   baseTex[0] = "earthMap4";
   bumpTex[0] = "earthMap4_bump";

   pixelSpecular[0] = true;
   specular[0] = "0.1 0.1 0.1 1.0";
   specularPower[0] = 3.0;

};

Interestingly, if I move the camera around to face the sun-lit side of the planet, the jagged edges slowly disappear as I move round. I suspect that's to do with the specular lighting.

Any ideas how I can get rid of the jagged edges?

#1
07/18/2007 (10:03 am)
Anti-aliasing? which doesn't work in TGEA at the moment. used to.
#2
07/18/2007 (10:18 am)
Ah I see where you have been confused with my post... I'm not talking about the edges of the sphere... look at the center of the image. See where the light and dark parts of the planet "join"? There are lots of triangular bits!
#3
07/18/2007 (10:26 am)
I think you're right. It looks like a geometry and specular issue to me. Perhaps raising the specular power would make this less apparent?
#4
07/19/2007 (3:04 am)
It's true that altering the specular power reduces the amount that the effect is visible, but then I don't get the lighting I want! Can someone from GG staff / employee suggest a work-around? Should I be using multiple levels of detail on my model or something?
#5
07/19/2007 (12:40 pm)
It looks weirdly like the triangles are showing. Which shouldnt happen with pixel specular really should it.

How about your object normals? did you check to make sure youre normals are all pointing correctly? If you have some flipped normals I guess you could get something like that.
#6
07/23/2007 (9:24 am)
What are object normals? LOL. I just created a sphere in MAX and then applied a texture and exported.
#7
07/23/2007 (9:33 am)
What does your planet look like w/o any specular? It also looks like maybe you're not getting good diffuse shading. I ask because there is a fix posted in another thread re: bad shading on scaled objects.
www.garagegames.com/mg/forums/result.thread.php?qt=63890
Perhaps this applies here and the specular jaggies are related.
#8
07/23/2007 (9:40 am)
Without specular, the planet looks basically perfect. No jagged triangle bits or anything! Spec lighting is definitely the cause of the issue... I just don't know why! I also have a bump map on the planet and it is not scaled in the engine, it's scaled in max then exported. The scale in the mission file is 1 1 1.

Help! :o)
#9
07/23/2007 (2:02 pm)
What graphics card are you using, and what Shader model does it support?
#10
07/23/2007 (3:05 pm)
It shouldn't be a shader model issue though. It's a specular issue. That's odd that you had it even when you used the normal map. Perhaps you could post an image of the normal map?
#11
07/23/2007 (3:35 pm)
I'm using a GeForce 7900 GTX with SM 3.0 support. I thought the normal map might have something to do with it but when I turn that off or on, I get the same effect. It's definitely a specular problem though as you say. Turning off specular removes the problem.

To me it looks like it's highlighting based upon the triangles that make up the sphere. What confuses me is that the specular is supposed to be per-pixel, not per-vertex so I can't see how that effect would be created!

Here is the normal map I'm using (I've saved it to the web as a jpeg but in the game it's a png):

v2.wastedwebspace.co.uk/gamedev/earthMap4_bump.jpg
Also, what did Phil mean about flipped normals? How do I check the the normals are... normal?
#12
07/23/2007 (4:29 pm)
Isnt there some problem in scaling the object in max, if you just select the whole object and scale it (as opposed to scaling in vertex mode)?

I might be wrong, but since you said you scaled it in max, i though i would bring it up.
#13
07/23/2007 (6:10 pm)
I've tested a sphere with specular on my machine, and I'm getting the same problem. So its not specific to his hardware. The sphere I tested with, I exported from max ensuring correct normals, so its not a geometry issue either.

Gabe
#14
07/24/2007 (3:52 am)
@Gabriel - Thanks for confirming the issue isn't just on my machine or with my geometry!

If you are able to reproduce the error, then it must be an engine-based bug, or at least something we're both doing wrong!
#15
07/24/2007 (4:58 am)
Have you tried the noolness normal shaders (nVidia shaders port)? I thought they gave better results w/specularity than the stock shaders.
#16
07/27/2007 (1:23 pm)
The problem is that the specular lighting is modulated by the per-vertex diffuse lighting. This causes the vertices to show up when using low specular powers.

You can remove the attenuation by modifying the shader generator. Open shaderGen/pixSpecular.cpp and find this block, in PixelSpecular::processPix:

if( fd.features[GFXShaderFeatureData::BumpMap] )
      {
         meta->addStatement( new GenOp( "   @ = saturate( dot(@.xyz * 2.0 - 1.0, @) ) * @.w;\r\n", specDecl, normal, halfAng, lightVec ) );
      }
      else
      {
         meta->addStatement( new GenOp( "   @ = saturate( dot(@.xyz, @) ) * @.w;\r\n", specDecl, normal, halfAng, lightVec ) );
      }

Replace by:
if( fd.features[GFXShaderFeatureData::BumpMap] )
      {		 
         meta->addStatement( new GenOp( "   @ = saturate( dot(@.xyz * 2.0 - 1.0, @) );\r\n", specDecl, normal, halfAng ) );
      }
      else
      {
	 if (GFX->getPixelShaderVersion() >= 2.0)
		 meta->addStatement( new GenOp( "   @ = saturate( dot(normalize(@.xyz), @) );\r\n", specDecl, normal, halfAng ) );
	 else
		 meta->addStatement( new GenOp( "   @ = saturate( dot(@.xyz, @) );\r\n", specDecl, normal, halfAng ) );
      }

But be aware that low power specular values will "bleed" into beyond the dark areas in the model. If you don't want that, you'll have to do further modifications to use per-pixel attenuation.
#17
07/28/2007 (6:13 am)
Yeah tested that it seems to fix it.

Gabriel