문제

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.

도움이 되었습니까?

해결책

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)

다른 팁

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).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top