浏览代码

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.

(cherry picked from commit 3c3cc2cb7b8ba0879b5d77ae4bfd1d6ca9bd0b95)

(cherry picked from commit 3c3cc2cb7b8ba0879b5d77ae4bfd1d6ca9bd0b95)
Gareth Fouche 10 年之前
父节点
当前提交
991c2ffd6c
共有 2 个文件被更改,包括 11 次插入4 次删除
  1. 10 3
      Resources/CoreData/Shaders/HLSL/LitSolid.hlsl
  2. 1 1
      Resources/CoreData/Techniques/DiffLightMap.xml

+ 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" />