Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Light position coordinate in phong shading

Tags:

c

opengl

glsl

I'm learning Phong shading and get some confuses:

  1. What coordinate of light position in Phong shading? (model space, modelview or what else?)
  2. According to this: http://www.ozone3d.net/tutorials/glsl_lighting_phong_p2.php:

Vertex shader is:

varying vec3 normal, lightDir, eyeVec;

void main()
{   
    normal = gl_NormalMatrix * gl_Normal;
    vec3 vVertex = vec3(gl_ModelViewMatrix * gl_Vertex);

    lightDir = vec3(gl_LightSource[0].position.xyz - vVertex);
    eyeVec = -vVertex;

    gl_Position = ftransform();
}

Why eyeVec = -vVertex?

like image 508
Bình Nguyên Avatar asked Feb 21 '23 06:02

Bình Nguyên


1 Answers

  1. The coordinate frame is not relevant to the kind of shading. You could do phong shading in model space, world space, view space, or any made up space you want. The only important thing is to make sure that all relevant vectors in the formula are transformed into the same space.
  2. In this case it looks like the shading is being done in view space. In view space, the vertex coordinates are defined relative to the eye. So the vector from a vertex to the eye (eyeVec) is the negation of the vector from the eye to the vertex (vVertex).
like image 109
Tim Avatar answered Feb 27 '23 08:02

Tim