From 7ae351bac3b91d84d472ecb1404073307cd67ebc Mon Sep 17 00:00:00 2001 From: allen hux Date: Mon, 19 Dec 2022 14:11:52 -0800 Subject: [PATCH] improved specular. --- src/shaders/terrainPS.hlsl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/shaders/terrainPS.hlsl b/src/shaders/terrainPS.hlsl index 3a92805..8d70255 100644 --- a/src/shaders/terrainPS.hlsl +++ b/src/shaders/terrainPS.hlsl @@ -39,22 +39,22 @@ float3 evaluateLight(in float3 normal, in float3 pos, in float3 tex) { float ambient = 0.1f; + // diffuse // directional light. from the point toward the light is the opposite direction. float3 pointToLight = -g_lightDir.xyz; float diffuse = saturate(dot(pointToLight, normal)); + float3 color = max(ambient, diffuse) * g_lightColor.xyz * tex; + // specular float3 eyeToPoint = normalize(pos - g_eyePos.xyz); - float3 reflected = reflect(eyeToPoint, normal); + float3 reflected = normalize(reflect(eyeToPoint, normal)); float specDot = saturate(dot(reflected, pointToLight)); - float specular = pow(specDot, g_specularColor.a); + float3 specular = pow(specDot, g_specularColor.a) * g_specularColor.xyz; - float3 color = max(ambient, diffuse) * g_lightColor.xyz; - color *= tex; - color = pow(color, 1.0f / 1.3f); + // gamma + color = pow(color + specular, 1.0f / 1.5f); color = saturate(color); - color += (specular * g_specularColor.xyz); - return color; }