4/09/2007

Shading components

To represent objects in a physically realistic way, we need at least three shading components, namely diffuse, specular and reflection. Admittedly there are other factors that contribute for creating believable images such as ambient, emmisive, transparency, sub-surface scattering, fresnel reflection, anisotrophic reflection, and so on. However, if the three components are in your hand, you can represent most of what you want to depict above a certain level.

Let's summarize how these three components are calculated in HLSL.




1. diffuse component

diffuse = saturate(dot(N, L))


'N' is a normalized surface normal vector that is transformed from object space to world space.
'L' is a normalized light vector in world space.

'saturate' is used to make sure that diffuse is not less than zero.


2. specular component

specular = pow(max(0, dot(N, H)), specularPower);

'N' is a normalized surface normal vector that is transformed from object space to world space. 'H' is the so-called 'half vector'.
H = normalize(L+V);
'V' is a normalized eye vector in world space. 'max' is used to make sure that specular is not less than zero.
'spacularPower' , or sometimes 'shininess' controls concentration of highlight.
'max' is used to make sure that the result value is not less than zero.


3. reflection component

R = -reflect(V,N)
reflection = texCUBE(reflectionTextureSampler, R);

'R' is a reflection vector.
'V' is a normalized eye vector in world space.
'N' is a normalized surface normal vector that is transformed from object space to world space.

Since the ray-tracing is not in use in most cases, a cube map is used to show the reflected images.


No comments:

Tag