Browse Source

Fixes to the LitSolid shader to ensure that lights that don't have "cast shadows" enabled don't contribute their lighting value to the lighting calculation for lightmapped objects, and made sure that the environment map is shaded by the lightmap properly, if both are used.

Also fixed bugs in the DiffLightMap technique. Like DiffLightMapEnvCube, it needs to subtract, not add the lighting, and define the LIGHTMAP shader define for the VS and PS in order for the lighting to be calculated correctly, or again, you have lights contributing light info to lightmapped objects in incorrect ways.
Gareth Fouche 9 years ago
parent
commit
e121939bc9

+ 10 - 3
Resources/CoreData/Shaders/HLSL/LitSolid.hlsl

@@ -231,6 +231,8 @@ void PS(
             finalColor = diff * diffColor.rgb * cAmbientColor;
 
             oColor = float4(GetLitFog(finalColor, fogFactor), diffColor.a);
+		#elif defined(LIGHTMAP)            
+            oColor = float4(0.0, 0.0, 0.0, 0.0);
         #else
             float diff = GetDiffuse(normal, iWorldPos.xyz, lightDir);
 
@@ -310,11 +312,16 @@ void PS(
             finalColor += lightInput.rgb * diffColor.rgb + lightSpecColor * specColor;
         #endif
 
-        #ifdef ENVCUBEMAP
-            finalColor += cMatEnvMapColor * SampleCube(EnvCubeMap, reflect(iReflectionVec, normal)).rgb;
-        #endif
         #ifdef LIGHTMAP
             finalColor += Sample2D(EmissiveMap, iTexCoord2).rgb * diffColor.rgb;
+			
+			#ifdef ENVCUBEMAP
+				finalColor += cMatEnvMapColor * SampleCube(EnvCubeMap, reflect(iReflectionVec, normal)).rgb * Sample2D(EmissiveMap, iTexCoord2).rgb;
+			#endif
+		#else
+			#ifdef ENVCUBEMAP
+				finalColor += cMatEnvMapColor * SampleCube(EnvCubeMap, reflect(iReflectionVec, normal)).rgb;
+			#endif
         #endif
         #ifdef EMISSIVEMAP
             finalColor += cMatEmissiveColor * Sample2D(EmissiveMap, iTexCoord.xy).rgb;

+ 1 - 1
Resources/CoreData/Techniques/DiffLightMap.xml

@@ -1,6 +1,6 @@
 <technique vs="LitSolid" ps="LitSolid" psdefines="DIFFMAP">
     <pass name="base" vsdefines="LIGHTMAP" psdefines="LIGHTMAP" />
-    <pass name="light" depthtest="equal" depthwrite="false" blend="add" />
+    <pass name="light" vsdefines="LIGHTMAP" psdefines="LIGHTMAP" depthtest="equal" depthwrite="false" blend="subtract" />
     <pass name="prepass" psdefines="PREPASS" />
     <pass name="material" vsdefines="LIGHTMAP" psdefines="MATERIAL LIGHTMAP" depthtest="equal" depthwrite="false" />
     <pass name="deferred" vsdefines="LIGHTMAP" psdefines="DEFERRED LIGHTMAP" />