Browse Source

VSM works with point light and spot light in openGL

Xavier Maupeu 10 years ago
parent
commit
b1beaf4ad1

+ 5 - 4
bin/CoreData/Shaders/GLSL/Lighting.glsl

@@ -203,8 +203,8 @@ float GetShadow(vec4 shadowPos)
             #endif
 
         #elif defined(VSM_SHADOW)
-            vec2 samples = texture2D(sShadowMap, shadowPos.xy).rg;
-            return cShadowIntensity.y + cShadowIntensity.x * Chebyshev(samples, shadowPos.z/shadowPos.w);
+            vec2 samples = texture2D(sShadowMap, shadowPos.xy / shadowPos.w).rg; 
+            return cShadowIntensity.y + cShadowIntensity.x * Chebyshev(samples, shadowPos.z / shadowPos.w);
         #endif
     #else
         #if defined(SIMPLE_SHADOW)
@@ -221,9 +221,10 @@ float GetShadow(vec4 shadowPos)
                 texture2DProj(sShadowMap, vec4(shadowPos.xy + offsets.xy, shadowPos.zw)).r * shadowPos.w > shadowPos.z
             );
             return cShadowIntensity.y + dot(inLight, vec4(cShadowIntensity.x));
+            
         #elif defined(VSM_SHADOW)
-            vec2 samples = texture2D(sShadowMap, shadowPos.xy).rg;
-            return cShadowIntensity.y + cShadowIntensity.x * Chebyshev(samples, shadowPos.z/shadowPos.w);
+            vec2 samples = texture2D(sShadowMap, shadowPos.xy / shadowPos.w).rg; 
+            return cShadowIntensity.y + cShadowIntensity.x * Chebyshev(samples, shadowPos.z / shadowPos.w);
         #endif
     #endif
 }

+ 1 - 1
bin/CoreData/Shaders/GLSL/Shadow.glsl

@@ -14,7 +14,7 @@ void VS()
     vec3 worldPos = GetWorldPos(modelMatrix);
     gl_Position = GetClipPos(worldPos);
     #ifdef VSM_SHADOW
-        vTexCoord = vec3(GetTexCoord(iTexCoord), GetDepth(gl_Position));
+        vTexCoord = vec3(GetTexCoord(iTexCoord), gl_Position.z / gl_Position.w * 0.5 + 0.5);
     #else
         vTexCoord = GetTexCoord(iTexCoord);
     #endif

BIN
bin/Data/Models/barn.mdl