First I would like to show is per-pixel lighting which I've done by myself after reading The Cg Tutorial. It is an awesome book and recommended to all beginners in shader programming.
Per-pixel lighting is simple, basically it is like per-vertex lighting but instead of putting all the codes in vertex shader, u put it in pixel shader. Well, in order to optimize the code, remember do all the position calculation in vertex shader first and only pass them to the pixel shader so that pixel shader don't need to do so many works.
Simple ey?
The only thing you need to know is, the theory of lighting in computer graphics!
Basically the equation of lighting is:
lighting = emissive + ambient + diffuse + specular
(Actually the emissive term doesn't seems like really important)
The formula above is the most basic lighting formula. Of cause there are more like adding attenuation. I haven't try that personally so I'm not going to talk more about that yet.
Enough of talking, here are some screenshots:
*Ambient light only
*Diffuse light only
*Specular light only
*Ambient + Diffuse + Specular (Facing the light)
*Ambient + Diffuse + Specular (Doesn't facing the light)
Video Demo:
Key control:
1: All lighting added together
2: Ambient light only
3: Diffuse light only
4: Specular light only
No comments:
Post a Comment