瀏覽代碼

VSM works with point light and spot light in direct3d9

Xavier Maupeu 10 年之前
父節點
當前提交
33a278449b
共有 2 個文件被更改,包括 8 次插入6 次删除
  1. 7 5
      bin/CoreData/Shaders/HLSL/Lighting.hlsl
  2. 1 1
      bin/CoreData/Shaders/HLSL/Shadow.hlsl

+ 7 - 5
bin/CoreData/Shaders/HLSL/Lighting.hlsl

@@ -179,12 +179,11 @@ float Chebyshev(float2 Moments, float depth)
 
 float GetShadow(float4 shadowPos)
 {
-    #ifdef D3D11
-        shadowPos.xyz /= shadowPos.w;
-    #endif
-
     #if defined(SIMPLE_SHADOW)
         // Take one sample
+        #ifdef D3D11
+            shadowPos.xyz /= shadowPos.w;
+        #endif
         float inLight = SampleShadow(ShadowMap, shadowPos).r;
         #ifndef SHADOWCMP
             return cShadowIntensity.y + cShadowIntensity.x * inLight;
@@ -199,6 +198,9 @@ float GetShadow(float4 shadowPos)
     #elif defined(PCF_SHADOW)
         // Take four samples and average them
         // Note: in case of sampling a point light cube shadow, we optimize out the w divide as it has already been performed
+        #ifdef D3D11
+            shadowPos.xyz /= shadowPos.w;
+        #endif
         #if !defined(POINTLIGHT) && !defined(D3D11)
             float2 offsets = cShadowMapInvSize * shadowPos.w;
         #else
@@ -225,7 +227,7 @@ float GetShadow(float4 shadowPos)
         #endif
     
     #elif defined(VSM_SHADOW)
-        float2 samples = Sample2D(ShadowMap, shadowPos.xy).rg;
+        float2 samples = Sample2D(ShadowMap, shadowPos.xy / shadowPos.w).rg;
         return cShadowIntensity.y + cShadowIntensity.x * Chebyshev(samples, shadowPos.z/shadowPos.w);
     #endif
 }

+ 1 - 1
bin/CoreData/Shaders/HLSL/Shadow.hlsl

@@ -22,7 +22,7 @@ void VS(float4 iPos : POSITION,
     float3 worldPos = GetWorldPos(modelMatrix);
     oPos = GetClipPos(worldPos);
     #ifdef VSM_SHADOW
-        oTexCoord = float3(GetTexCoord(iTexCoord), GetDepth(oPos));
+        oTexCoord = float3(GetTexCoord(iTexCoord), oPos.z/oPos.w);
     #else
         oTexCoord = GetTexCoord(iTexCoord);
     #endif