PDA

View Full Version : Which is better for lighting quality?



Mars_999
04-29-2006, 08:13 PM
I just got the Gems6 book this week... I read the chapter on Vertex texturing with PS3.0 for terrain rendering. The author states that lighting quality is better if you calculate a normal map and use that in the FS vs. calculating the normals in the VS and then sending them to the FS? Right now I calculate my normals and send them to OpenGL and in the vertex shader I


normal = normalize(gl_NormalMatrix * gl_Normal);and send that normal to the FS. Is this true? Thanks

zeoverlord
04-30-2006, 09:33 AM
Using a normal map does indeed produce a better result, the only problem with it is when you move, deform or animate geometry.
In wich case you have to adjust the light's position for every vertex somehow to reflect this change in the mesh.

jide
04-30-2006, 10:56 AM
No, I do not agree (but some people here might tell it better in fact) that normal maps can produce better results. It depends on several factors.

What is said in that book (according to what I read from the post) is that doing the lighting calculations in the fragment shader will produce better results than doing them in the vertex shader. This is what called per pixel/fragment lighting versus per vertex lighting.

Normal maps can have approximately the same results, can be a bit faster (if I'm not wrong) but that depends extensively on the map precision: using 8 bits for each axis will definately have worst results that using floats, this turns out...

zeoverlord
04-30-2006, 04:14 PM
Originally posted by jide:
Normal maps can have approximately the same results, can be a bit faster (if I'm not wrong) but that depends extensively on the map precision: using 8 bits for each axis will definately have worst results that using floats, this turns out... Yes but that is only true if you are doing exactly what is possible with fragment lighting, normal maps make it possible to have better control over the normals than before.
Float normal maps may be great, but they do use up a lot of memory, and in a normal map it's better to have higher pixel density than higher precision (within resonable limit's that is).

Just to be clear: Vertex lighting is not the same as calcylating the normals in the vertex shader and sending them to the fragment shader.

Mars_999
04-30-2006, 11:36 PM
so as of now I am still unclear as to which way is better quality? My terrain mesh is static so the dynamic nature isn't an issue. I was just looking for a answer and explaination to what I read about the normal map vs. calculating them in the shaders... Thanks

Overmind
05-01-2006, 04:38 AM
If your terrain has surface details that are smaller than the resolution of the vertex mesh, then a normal map will give you better results, because it has a higher resolution.

If not, there will be no difference between the normalmap and the interpolated normals, so it's a waste of memory.

jide
05-01-2006, 05:47 AM
And it all depends on the lighting model you want to simulate (Gouraud, Phong...).

Mars_999
05-02-2006, 11:50 PM
Ok, I am trying to implement a normalmap for my PPL lighting. I am having a issue with my lighting moving around on me when I move my camera and must have to do something with the way I am calculating my lightDir? I am using a directional light.


//vs
lightDir = normalize(vec3(gl_LightSource[0].position));

//fs
vec3 n = texture2D(normalmap, gl_TexCoord[0].xy);
n = vec3(2.0) * (n - vec3(.5));
vec4 lightColor = ambient;
float NdotL = max(dot(n, lightDir), 0.0);thanks for any help... BTW doing this also and doesn't make a difference


lightDir = normalize(vec3(gl_LightSource[0].position) - vec3(gl_Vertex));

Komat
05-03-2006, 04:06 AM
How do you upload your light position? Light position is transformed by modelview matrix set at time light position was specified.

Mars_999
05-03-2006, 10:53 AM
Originally posted by Komat:
How do you upload your light position? Light position is transformed by modelview matrix set at time light position was specified. Like this


glLoadIdentity();
g_Camera.LookAt();
glLightfv(GL_LIGHT0, GL_POSITION, gterrain.lightPosition);the thing is I dont' have this issue when I dont' use the normalmap, and just use the VS/FS to do PPL...

Mars_999
05-03-2006, 12:15 PM
I think I got it working and looks like to me that the normalmap version looks better...