   Normal in Fragment Shader
  For example, lighting per pixel is much better quality than fixed functionality(http://www.lighthouse3d.com/opengl/glsl/index.php?pointlight)On shader program, normal is derived in vertex shader and is transfered to fragment shader using 'varying'.For calculating light, normal and light direction are required, but those are calculated in vertex shader.Though nothing about pixel's position is derived in fragment shader, why per pixel lighting is possible?I don't know how fragment shader knows current pixel's position for calculating light.   
Quote:Though nothing about pixel's position is derived in fragment shader, why per pixel lighting is possible?pass it from the vs to the frag shader-- vs --varying vec3 pos;void main(){ pos = gl_Vertex.xyz;}now u can access the pos in the fs + it will be correct ie cause ofa triangle has 3 corners A,B,C (use barycentric equation)if a point is at position A then the calculation = A*1+B*0+C*0 = posif a point is halfway between position A + B then the calculation = A*0.5+B*0.5+C*0 = pos   ;Quote:Original post by ilys4Though nothing about pixel's position is derived in fragment shader, why per pixel lighting is possible?I don't know how fragment shader knows current pixel's position for calculating light.That's a very good question, and I'd like to know the answer myself.More specifically, when you calculate the vector from the light to the object, you don't appear to change the vector in the fragment shader, but the vector apparently changes, since the per-pixel lighting is varied per-fragment. I've done per-pixel lighting successfully, but I don't fully understand how that bit works.;  that's why we got a vertex shader...on vertex shader we know the position of each vertex after spatial transformation, we thus calculate the local direction of the light (pos - lightpos), we also have the normal of this vertex.With all that, the pipeline is able, when a primitive (say a triangle) is drawed, to retrieve these informations for all vertices... and then when rasterinzing the primitive, the pipeline interpolates these values, to produce a new value FOR EACH pixel (fragment in fact)And that's the main point of fragments, (if we forget about multisampling for educationnal reasons) a fragment is a pixel PLUS those infos interpolated associted to it.So a fragment has : a position (on screen), a depth(the thrid componant of position), a normal, a light vector (in our example)Does that clear some things ?JFD   ;  Thanks it is almost clear :)rest of obscure is.... I didn't read about it in my books :((I'm reading opengl yellow book)I believe it may be shown soon in my book.   