Procházet zdrojové kódy

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

Lasse Öörni před 14 roky
rodič
revize
7b5c761d20
1 změnil soubory, kde provedl 10 přidání a 3 odebrání
  1. 10 3
      SourceAssets/Shaders/Prepass/Light.hlsl

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

@@ -100,20 +100,27 @@ void ps(
             diff *= evaluateShadow(shadowPos);
             diff *= evaluateShadow(shadowPos);
         #endif
         #endif
 
 
+        const float3 rgbDot = 1.0 / 3.0;
+        float shapeFactor;
         #ifdef SPOTLIGHT
         #ifdef SPOTLIGHT
             float4 spotPos = mul(float4(worldPos, 1.0), cSpotProjPS);
             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
         #else
             #ifdef CUBEMASK
             #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
             #else
+                shapeFactor = 1.0;
                 lightColor = cLightColor.rgb;
                 lightColor = cLightColor.rgb;
             #endif
             #endif
         #endif
         #endif
 
 
         #ifdef SPECULAR
         #ifdef SPECULAR
             float spec = evaluateSpecular(normal, worldPos, lightDir, normalInput.a * 255.0);
             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
         #else
             oColor = float4(diff * lightColor, 0.0);
             oColor = float4(diff * lightColor, 0.0);
         #endif
         #endif