我剛剛嘗試實施高光反射。問題在於,當遠離表面移動時,突出部分變得越來越強,突出部分的邊緣變得非常嚴酷。當移動到表面太近時,高光完全消失。反射高光取決於相機距離
這是我的片段着色器的相關部分。所有的計算都在視圖空間中。我使用定向太陽光。
// samplers
vec3 normal = texture2D(normals, coord).xyz;
vec3 position = texture2D(positions, coord).xyz;
float shininess = texture2D(speculars, coord).x;
// normalize directional light source
vec3 source;
if(directional) source = position + normalize(light);
else source = light;
// reflection
float specular = 0;
vec3 lookat = vec3(0, 0, 1);
float reflection = max(0, dot(reflect(position, normal), lookat));
int power = 5;
specular = shininess * pow(reflection, power);
// ...
// output
image = color * attenuation * intensity * (fraction + specular);
這是我的照明緩衝區的屏幕截圖。你可以看到最重要的鏡筒沒有任何鏡面反射,而遠處的鏡筒太強烈。中間的桶根據需要點亮。
我在做什麼錯?
顯示您的客戶端代碼,尤其是光矢量。確保你不要將方向與位置混淆。 –
對於定向光源,我將位置視爲方向。例如,太陽的位置是「0.5,1.0,1.5」。這是否會造成問題?但問題是方向燈和點燈相同。 – danijar
沒有足夠的代碼。顯示如何構建模型視圖矩陣。例如,如果您的向量看起來像l,x,y,z,1那麼它可能是個問題 –