Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Which is better for lighting quality?

  1. #1
    Senior Member Frequent Contributor Mars_999's Avatar
    Join Date
    Mar 2001
    Location
    Sioux Falls, SD, USA
    Posts
    519

    Which is better for lighting quality?

    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

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

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Feb 2006
    Location
    Sweden
    Posts
    744

    Re: Which is better for lighting quality?

    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.

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Jul 2001
    Location
    France
    Posts
    1,662

    Re: Which is better for lighting quality?

    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...

  4. #4
    Senior Member Frequent Contributor
    Join Date
    Feb 2006
    Location
    Sweden
    Posts
    744

    Re: Which is better for lighting quality?

    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.

  5. #5
    Senior Member Frequent Contributor Mars_999's Avatar
    Join Date
    Mar 2001
    Location
    Sioux Falls, SD, USA
    Posts
    519

    Re: Which is better for lighting quality?

    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

  6. #6
    Senior Member OpenGL Pro
    Join Date
    May 2000
    Location
    Naarn, Austria
    Posts
    1,102

    Re: Which is better for lighting quality?

    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.

  7. #7
    Senior Member OpenGL Pro
    Join Date
    Jul 2001
    Location
    France
    Posts
    1,662

    Re: Which is better for lighting quality?

    And it all depends on the lighting model you want to simulate (Gouraud, Phong...).

  8. #8
    Senior Member Frequent Contributor Mars_999's Avatar
    Join Date
    Mar 2001
    Location
    Sioux Falls, SD, USA
    Posts
    519

    Re: Which is better for lighting quality?

    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.

    Code :
    //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

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

  9. #9
    Senior Member Frequent Contributor
    Join Date
    May 2005
    Location
    Prague, Czech Republic
    Posts
    913

    Re: Which is better for lighting quality?

    How do you upload your light position? Light position is transformed by modelview matrix set at time light position was specified.

  10. #10
    Senior Member Frequent Contributor Mars_999's Avatar
    Join Date
    Mar 2001
    Location
    Sioux Falls, SD, USA
    Posts
    519

    Re: Which is better for lighting quality?

    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

    Code :
    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...

Page 1 of 2 12 LastLast

Similar Threads

  1. HELP!!! Textures are low quality!
    By Matt3214 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-23-2013, 01:25 AM
  2. OGL reder quality
    By towsim in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 06-04-2013, 11:14 AM
  3. Pbuffer Quality
    By Saqib in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 03-01-2004, 09:33 AM
  4. Bad Quality
    By ImpactDNI in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-20-2002, 12:48 PM
  5. Texture Quality
    By Mongoose in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 12-05-2000, 12:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean