Jump to content
  • Advertisement
Sign in to follow this  
MARS_999

OpenGL Which is better for lighting quality?

This topic is 4432 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
The way you do it, you have one normal per vertex.
Those are interpolated across each fragment.. it looks good for spheres and, such things, but you get no details.
A normal-map can make it appear like you have loads more vertices than you actually have, just look at Doom3. :D

Another problem you have is you normalize your normals in the vertex program.
When these are later interpolated and sent to the fragment program, some of these will NOT be normalized anymore, and the lightning quality will be bad...
Normalize in your fragment program, or use a normal-texture for kick-ass lighting. :D

Share this post


Link to post
Share on other sites
Ok, so this will still be the case even if I renormalize the normal in the FS, that the normalmap will be better quality still. Thanks for the info.

Share this post


Link to post
Share on other sites
Quote:
Original post by gulgi
Normalize in your fragment program, or use a normal-texture for kick-ass lighting. :D


and you should prefer to use normilisation in the FS over a texture for newer hardware (9700 and up and GF6 and up) as using a texture wastes bandwidth and cache.

Share this post


Link to post
Share on other sites
Quote:
Original post by phantom
Quote:
Original post by gulgi
Normalize in your fragment program, or use a normal-texture for kick-ass lighting. :D


and you should prefer to use normilisation in the FS over a texture for newer hardware (9700 and up and GF6 and up) as using a texture wastes bandwidth and cache.
..if we were talking about a normalization cubemap that is. :D
I just meant use a normalmap OR interpolated renormalized vertexnormals. And yes, on newer gfx cards, normalize with math, and on something old as my GeForce5800, a a cubemap is way faster.. :)

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
Quote:
Original post by MARS_999
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.

*** Source Snippet Removed ***

thanks for any help...


Right now it seems that you're calculating lightDir as the vector from the eye point to the light source. (Assuming gl_LightSource[0].position is specified in view-space, I always forget).

Anyway, you need to calculate the vector from the vertex to the light source.

Share this post


Link to post
Share on other sites
Quote:
Original post by mhamlin
Quote:
Original post by MARS_999
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.

*** Source Snippet Removed ***

thanks for any help...


Right now it seems that you're calculating lightDir as the vector from the eye point to the light source. (Assuming gl_LightSource[0].position is specified in view-space, I always forget).

Anyway, you need to calculate the vector from the vertex to the light source.


So this then? If so that isn't working either... :(

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



Share this post


Link to post
Share on other sites
Well I think I got it working but I am doing bumpmapping with tangent space and as of now I am thinking the Lighting looks a lot better than the VS/FS lighting... I thought doing the lighting in the FS was supposed to be PPL... But it doesn't look this good... Anyone care to comment on this, to help me understand why. Thanks

Share this post


Link to post
Share on other sites
It is difficult to give you a definitive answer whithout the complete VS / FS.

Therefore, I will just suggest to have a look at Lighthouse3D GLSL tutorial which explains how to perform PPL for directional / spot / omni lights and compare PPL to vertex lighting.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!