Question

I am using a simple form of Phong Shading Model where the scene is lit by a directional light shining in the direction -y, with monochromatic light of intensity 1. The viewpoint is infinitely far away, looking along the direction given by the vector (-1, 0, -1).

In this case, the shading equation is given by

I = k_d*L(N dot L)+k_s*L(R dot V)^n_s

where L is the Directional Light source, kd, ks both are 0.5 and n_s = 50

In this case, how can I compute the R vector?

I am confused because for computing finite vectors we need finite coordinates. In case of the Directional Light, it's infinitely far away in the -y direction.

Was it helpful?

Solution

Reflect vector can be calculated by using reflect function from GLSL.

vec3 toEye = normalize(vec3(0.0) - vVaryingPos);    
vec3 lightRef = normalize(reflect(-light, normal)); 
float spec = pow(dot(lightRef, toEye), 64.0f);  
specularColor = vec3(1.0)*max(spec, 0.0); 

calculations are done in eye space... so the eyePos is in vec3(0.0)

OTHER TIPS

Those equations use normal vectors. So in your case, when you are using directional light it simply means that L is constant and equals [x=0, y=1, z=0] (or [0, -1, 0], I don't remember, you should check if in your equation L points to the point or away from the point).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top