Browse Source

Fixed erroneous specular lighting outside the light cone in prepass rendering.

Lasse Öörni 14 years ago
parent
commit
7b5c761d20
1 changed files with 10 additions and 3 deletions
  1. 10 3
      SourceAssets/Shaders/Prepass/Light.hlsl

+ 10 - 3
SourceAssets/Shaders/Prepass/Light.hlsl

@@ -100,20 +100,27 @@ void ps(
             diff *= evaluateShadow(shadowPos);
         #endif
 
+        const float3 rgbDot = 1.0 / 3.0;
+        float shapeFactor;
         #ifdef SPOTLIGHT
             float4 spotPos = mul(float4(worldPos, 1.0), cSpotProjPS);
-            lightColor = spotPos.w > 0.0 ? tex2Dproj(sLightSpotMap, spotPos).rgb * cLightColor.rgb : 0.0;
+            float3 shapeColor = spotPos.w > 0.0 ? tex2Dproj(sLightSpotMap, spotPos).rgb : 0.0;
+            shapeFactor = dot(shapeColor, rgbDot);
+            lightColor = shapeColor * cLightColor.rgb;
         #else
             #ifdef CUBEMASK
-                lightColor = texCUBE(sLightCubeMap, mul(lightVec, cLightVecRot)).rgb * cLightColor.rgb;
+                float3 shapeColor = texCUBE(sLightCubeMap, mul(lightVec, cLightVecRot)).rgb;
+                shapeFactor = dot(shapeColor, rgbDot);
+                lightColor = shapeColor * cLightColor.rgb;
             #else
+                shapeFactor = 1.0;
                 lightColor = cLightColor.rgb;
             #endif
         #endif
 
         #ifdef SPECULAR
             float spec = evaluateSpecular(normal, worldPos, lightDir, normalInput.a * 255.0);
-            oColor = diff * float4(lightColor, spec * cLightColor.a);
+            oColor = diff * float4(lightColor, spec * shapeFactor * cLightColor.a);
         #else
             oColor = float4(diff * lightColor, 0.0);
         #endif