From 58140ad583a802994c58cd57a86d778ffdfb240c Mon Sep 17 00:00:00 2001 From: Onek8 Date: Wed, 9 Jul 2025 23:18:52 +0000 Subject: [PATCH] Update leenkx/Shaders/std/shadows.glsl --- leenkx/Shaders/std/shadows.glsl | 77 +++++++++++++++++++++++++-------- 1 file changed, 59 insertions(+), 18 deletions(-) diff --git a/leenkx/Shaders/std/shadows.glsl b/leenkx/Shaders/std/shadows.glsl index 7f74a78..a1c01f4 100644 --- a/leenkx/Shaders/std/shadows.glsl +++ b/leenkx/Shaders/std/shadows.glsl @@ -251,28 +251,69 @@ vec3 PCFFakeCube(sampler2DShadow shadowMap, #endif if (any(lessThan(uvtiled, vec2(0.0))) || any(greaterThan(uvtiled, vec2(1.0)))) { - return vec3(1.0); // Or handle edge cases differently + return vec3(1.0); // Handle edge cases by returning full light } vec3 result = vec3(0.0); - // In PCFFakeCube(), modify the sampling pattern to be more robust: - const vec2 offsets[9] = vec2[]( - vec2(0, 0), - vec2(1, 0), vec2(-1, 0), vec2(0, 1), vec2(0, -1), - vec2(1, 1), vec2(-1, 1), vec2(1, -1), vec2(-1, -1) - ); + result.x += texture(shadowMap, vec3(uvtiled, compare)); + // soft shadowing + int newFaceIndex = 0; + uvtiled = transformOffsetedUV(faceIndex, newFaceIndex, vec2(uv + (vec2(-1.0, 0.0) / smSize))); + pointLightTile = pointLightDataArray[lightIndex + newFaceIndex]; + uvtiled = pointLightTile.z * uvtiled + pointLightTile.xy; + #ifdef _FlipY + uvtiled.y = 1.0 - uvtiled.y; // invert Y coordinates for direct3d coordinate system + #endif + result.x += texture(shadowMap, vec3(uvtiled, compare)); + + uvtiled = transformOffsetedUV(faceIndex, newFaceIndex, vec2(uv + (vec2(0.0, -1.0) / smSize))); + pointLightTile = pointLightDataArray[lightIndex + newFaceIndex]; + uvtiled = pointLightTile.z * uvtiled + pointLightTile.xy; + #ifdef _FlipY + uvtiled.y = 1.0 - uvtiled.y; // invert Y coordinates for direct3d coordinate system + #endif + result.x += texture(shadowMap, vec3(uvtiled, compare)); + + uvtiled = transformOffsetedUV(faceIndex, newFaceIndex, vec2(uv + (vec2(-1.0, -1.0) / smSize))); + pointLightTile = pointLightDataArray[lightIndex + newFaceIndex]; + uvtiled = pointLightTile.z * uvtiled + pointLightTile.xy; + #ifdef _FlipY + uvtiled.y = 1.0 - uvtiled.y; // invert Y coordinates for direct3d coordinate system + #endif + result.x += texture(shadowMap, vec3(uvtiled, compare)); + + uvtiled = transformOffsetedUV(faceIndex, newFaceIndex, vec2(uv + (vec2(0.0, 1.0) / smSize))); + pointLightTile = pointLightDataArray[lightIndex + newFaceIndex]; + uvtiled = pointLightTile.z * uvtiled + pointLightTile.xy; + #ifdef _FlipY + uvtiled.y = 1.0 - uvtiled.y; // invert Y coordinates for direct3d coordinate system + #endif + result.x += texture(shadowMap, vec3(uvtiled, compare)); + + uvtiled = transformOffsetedUV(faceIndex, newFaceIndex, vec2(uv + (vec2(1.0, -1.0) / smSize))); + pointLightTile = pointLightDataArray[lightIndex + newFaceIndex]; + uvtiled = pointLightTile.z * uvtiled + pointLightTile.xy; + #ifdef _FlipY + uvtiled.y = 1.0 - uvtiled.y; // invert Y coordinates for direct3d coordinate system + #endif + result.x += texture(shadowMap, vec3(uvtiled, compare)); + + uvtiled = transformOffsetedUV(faceIndex, newFaceIndex, vec2(uv + (vec2(1.0, 0.0) / smSize))); + pointLightTile = pointLightDataArray[lightIndex + newFaceIndex]; + uvtiled = pointLightTile.z * uvtiled + pointLightTile.xy; + #ifdef _FlipY + uvtiled.y = 1.0 - uvtiled.y; // invert Y coordinates for direct3d coordinate system + #endif + result.x += texture(shadowMap, vec3(uvtiled, compare)); + + uvtiled = transformOffsetedUV(faceIndex, newFaceIndex, vec2(uv + (vec2(1.0, 1.0) / smSize))); + pointLightTile = pointLightDataArray[lightIndex + newFaceIndex]; + uvtiled = pointLightTile.z * uvtiled + pointLightTile.xy; + #ifdef _FlipY + uvtiled.y = 1.0 - uvtiled.y; // invert Y coordinates for direct3d coordinate system + #endif + result.x += texture(shadowMap, vec3(uvtiled, compare)); - for (int i = 0; i < 9; i++) { - vec2 sampleUV = uv + offsets[i] / smSize; - int newFaceIndex; - vec2 transformedUV = transformOffsetedUV(faceIndex, newFaceIndex, sampleUV); - pointLightTile = pointLightDataArray[lightIndex + newFaceIndex]; - uvtiled = pointLightTile.z * transformedUV + pointLightTile.xy; - #ifdef _FlipY - uvtiled.y = 1.0 - uvtiled.y; - #endif - result.x += texture(shadowMap, vec3(uvtiled, compare)); - } result = result.xxx / 9.0; pointLightTile = pointLightDataArray[lightIndex + faceIndex]; // x: tile X offset, y: tile Y offset, z: tile size relative to atlas