Просмотр исходного кода

Cleanup of GLSL shadow code, try using texture2D instead of texture2DProj on OpenGL ES.

Lasse Öörni 13 лет назад
Родитель
Сommit
682714f400
2 измененных файлов с 23 добавлено и 21 удалено
  1. 22 20
      Bin/CoreData/Shaders/GLSL/Lighting.frag
  2. 1 1
      Bin/CoreData/Shaders/HLSL/Lighting.hlsl

+ 22 - 20
Bin/CoreData/Shaders/GLSL/Lighting.frag

@@ -39,15 +39,15 @@ float GetIntensity(vec3 color)
 #ifdef SHADOW
 float GetShadow(vec4 shadowPos)
 {
-    // Note: in case of sampling a point light cube shadow, we optimize out the w divide as it has already been performed
-    #ifndef LQSHADOW
-        // Take four samples and average them
-        #ifndef POINTLIGHT
-            vec2 offsets = cShadowMapInvSize * shadowPos.w;
-        #else
-            vec2 offsets = cShadowMapInvSize;
-        #endif
-        #ifndef GL_ES
+    #ifndef GL_ES
+        #ifndef LQSHADOW
+            // 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
+            #ifndef POINTLIGHT
+                vec2 offsets = cShadowMapInvSize * shadowPos.w;
+            #else
+                vec2 offsets = cShadowMapInvSize;
+            #endif
             vec4 inLight = vec4(
                 shadow2DProj(sShadowMap, shadowPos).r,
                 shadow2DProj(sShadowMap, vec4(shadowPos.x + offsets.x, shadowPos.yzw)).r,
@@ -56,20 +56,22 @@ float GetShadow(vec4 shadowPos)
             );
             return cShadowIntensity.y + dot(inLight, vec4(cShadowIntensity.x));
         #else
-            float compare = shadowPos.z / shadowPos.w;
-            vec2 inLight = vec2(
-                texture2DProj(sShadowMap, shadowPos).r > compare,
-                texture2DProj(sShadowMap, vec4(shadowPos.x + offsets.x, shadowPos.yzw)).r > compare
-            );
-            return 0.5 * (inLight.x + inLight.y);
-        #endif
-    #else
-        // Take one sample
-        #ifndef GL_ES
+            // Take one sample
             float inLight = shadow2DProj(sShadowMap, shadowPos).r;
             return cShadowIntensity.y + cShadowIntensity.x * inLight;
+        #endif
+    #else
+        vec3 projShadowPos = shadowPos.xyz / shadowPos.w;
+        #ifndef LQSHADOW
+            // Take two samples and average them
+            vec2 inLight = vec2(
+                texture2D(sShadowMap, projShadowPos.xy).r > projShadowPos.z,
+                texture2D(sShadowMap, vec2(projShadowPos.x + cShadowMapInvSize.x, projShadowPos.y)).r > projShadowPos.z
+            );
+            return dot(inLight, vec2(0.5));
         #else
-            return texture2DProj(sShadowMap, shadowPos).r * shadowPos.w > shadowPos.z ? 1.0 : 0.0;
+            // Take one sample
+            return texture2D(sShadowMap, projShadowPos.xy).r > projShadowPos.z ? 1.0 : 0.0;
         #endif
     #endif
 }

+ 1 - 1
Bin/CoreData/Shaders/HLSL/Lighting.hlsl

@@ -98,9 +98,9 @@ float GetVertexLightVolumetric(int index, float3 worldPos)
 #ifdef SHADOW
 float GetShadow(float4 shadowPos)
 {
-    // Note: in case of sampling a point light cube shadow, we optimize out the w divide as it has already been performed
     #ifndef LQSHADOW
         // 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
         #ifndef POINTLIGHT
             float2 offsets = cShadowMapInvSize * shadowPos.w;
         #else