Sfoglia il codice sorgente

Use 2 shadow samples maximum on Android & iOS.

Lasse Öörni 13 anni fa
parent
commit
1410d331a1
2 ha cambiato i file con 13 aggiunte e 7 eliminazioni
  1. 7 7
      Bin/CoreData/Shaders/GLSL/Lighting.frag
  2. 6 0
      Engine/Graphics/Batch.cpp

+ 7 - 7
Bin/CoreData/Shaders/GLSL/Lighting.frag

@@ -54,15 +54,15 @@ float GetShadow(vec4 shadowPos)
                 shadow2DProj(sShadowMap, vec4(shadowPos.x, shadowPos.y + offsets.y, shadowPos.zw)).r,
                 shadow2DProj(sShadowMap, vec4(shadowPos.xy + offsets.xy, shadowPos.zw)).r
             );
-        #else
-            vec4 inLight = vec4(
-                texture2DProj(sShadowMap, shadowPos).r * shadowPos.w > shadowPos.z,
-                texture2DProj(sShadowMap, vec4(shadowPos.x + offsets.x, shadowPos.yzw)).r * shadowPos.w > shadowPos.z,
-                texture2DProj(sShadowMap, vec4(shadowPos.x, shadowPos.y + offsets.y, shadowPos.zw)).r * shadowPos.w > shadowPos.z,
-                texture2DProj(sShadowMap, vec4(shadowPos.xy + offsets.xy, shadowPos.zw)).r * shadowPos.w > shadowPos.z
+            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 cShadowIntensity.y + dot(inLight, vec2(cShadowIntensity.x));
         #endif
-        return cShadowIntensity.y + dot(inLight, vec4(cShadowIntensity.x));
     #else
         // Take one sample
         #ifndef GL_ES

+ 6 - 0
Engine/Graphics/Batch.cpp

@@ -130,7 +130,9 @@ void CalculateShadowMatrix(Matrix4& dest, LightBatchQueue* queue, unsigned split
     if (renderer->GetShadowQuality() & SHADOWQUALITY_HIGH_16BIT)
     {
         offset.x_ -= 0.5f / width;
+        #if !defined(ANDROID) && !defined(IOS)
         offset.y_ -= 0.5f / height;
+        #endif
     }
     texAdjust.SetTranslation(Vector3(offset.x_, offset.y_, 0.5f));
     texAdjust.SetScale(Vector3(scale.x_, scale.y_, 0.5f));
@@ -559,7 +561,11 @@ void Batch::Prepare(Graphics* graphics, Renderer* renderer, bool setModelTransfo
                 if (fadeStart > 0.0f && fadeEnd > 0.0f && fadeEnd > fadeStart)
                     intensity = Lerp(intensity, 1.0f, Clamp((light->GetDistance() - fadeStart) / (fadeEnd - fadeStart), 0.0f, 1.0f));
                 float pcfValues = (1.0f - intensity);
+                #if !defined(ANDROID) && !defined(IOS)
                 float samples = renderer->GetShadowQuality() >= SHADOWQUALITY_HIGH_16BIT ? 4.0f : 1.0f;
+                #else
+                float samples = renderer->GetShadowQuality() >= SHADOWQUALITY_HIGH_16BIT ? 2.0f : 1.0f;
+                #endif
                 graphics->SetShaderParameter(PSP_SHADOWINTENSITY, Vector4(pcfValues / samples, intensity, 0.0f, 0.0f));
             }