Update leenkx/Shaders/std/shadows.glsl

This commit is contained in:
LeenkxTeam 2025-03-14 19:59:02 +00:00
parent 448898a634
commit 42eff22cbb

View File

@ -87,6 +87,35 @@ float lpToDepth(vec3 lp, const vec2 lightProj) {
return zcomp * 0.5 + 0.5;
}
#ifndef _ShadowMapAtlas
float PCFCube(samplerCubeShadow shadowMapCube, vec3 lp, vec3 ml, float bias, vec2 lightProj, vec3 n) {
const float s = shadowmapCubePcfSize;
float compare = lpToDepth(lp, lightProj) - bias * 1.5;
ml = ml + n * bias * 20;
#ifdef _InvY
ml.y = -ml.y;
#endif
float result = 0.0;
// Simple PCF for non-atlas mode, using samplerCubeShadow format
result = texture(shadowMapCube, vec4(ml, compare));
result += texture(shadowMapCube, vec4(ml + vec3(s, s, s), compare));
result += texture(shadowMapCube, vec4(ml + vec3(-s, s, s), compare));
result += texture(shadowMapCube, vec4(ml + vec3(s, -s, s), compare));
result += texture(shadowMapCube, vec4(ml + vec3(s, s, -s), compare));
result += texture(shadowMapCube, vec4(ml + vec3(-s, -s, s), compare));
result += texture(shadowMapCube, vec4(ml + vec3(s, -s, -s), compare));
result += texture(shadowMapCube, vec4(ml + vec3(-s, s, -s), compare));
result += texture(shadowMapCube, vec4(ml + vec3(-s, -s, -s), compare));
result /= 9.0;
return result;
}
#endif
#ifdef _ShadowMapAtlas
vec3 PCFCube(samplerCubeShadow shadowMapCube, samplerCube shadowMapCubeTransparent, const vec3 lp, vec3 ml, const float bias, const vec2 lightProj, const vec3 n, const bool transparent) {
const float s = shadowmapCubePcfSize; // TODO: incorrect...
float compare = lpToDepth(lp, lightProj) - bias * 1.5;
@ -115,7 +144,7 @@ vec3 PCFCube(samplerCubeShadow shadowMapCube, samplerCube shadowMapCubeTranspare
return result;
}
#ifdef _ShadowMapAtlas
// transform "out-of-bounds" coordinates to the correct face/coordinate system
// https://www.khronos.org/opengl/wiki/File:CubeMapAxes.png
vec2 transformOffsetedUV(const int faceIndex, out int newFaceIndex, vec2 uv) {