I'm new in GLSL, whats the difference between per-vertex lighting & per-pixel lighting?

Started by
3 comments, last by 50_Cal 11 years, 7 months ago
As the title, im wondering whats the difference between them.
Cuz vertex shader deals with every vertex the program transfers, and how can it deal with the pixels ?
Advertisement
in per-vertex lighting, lighting computation is done at each of the vertices of a model in the glsl vertex shader and the resulting pixel color is an interpolation of the color values of vertices on a face passed from the vertex shader. In per pixel lighting, all lighting computation is done pixel wise in the fragment shader. If the faces on a model are too big, per vertex lighting produces incorrect and undesirable and will require tessellation or subdivision of the faces.
Per vertex is faster since less computation is involved. Per pixel lighting gives correct result but requires pixel wise computation.
Information from the vertex shader is interpolated pixel wise into the fragment shader
1) Per vertex lighting is computed in vertex (or geometry or tessel) shader, with setting apropriate interpolation that OpenGL will use to get lighting per pixel.
2) Per pixel lighting is computed in part on vertex (geo or tess) shader for normal vectors, with setting apropriate interpolation that OpenGL will use to get normals per pixel. But actual lightning is computed in fragment shader based on that interpolated normal, with manual control over how relusting color must be incorporated into framebuffer.

There are few consequences:
Per vertex lighting put computation in vertex (geo or tess) shader stages so it is less computational intensive.
Per pixel lighting allow for more accurate color for every pixel.
Per vertex lighting interpolate color but only inside of primitive so it there is other primitive near by it can have different color which reasult in more artificial look.
Per pixel lighting interpolate normals but only inside of primitive *but* for near by primitives normals will vary only slightly, so relusting color should be not so different, giving impresion of "smoothnes".
Thanks for your replies. Now I get the differences between them.

This topic is closed to new replies.

Advertisement