update shadows

This commit is contained in:
MihailRis
2025-07-04 18:20:41 +03:00
parent a9652327f1
commit 931f0180ef
2 changed files with 14 additions and 11 deletions
+10 -7
View File
@@ -15,23 +15,26 @@ float calc_shadow() {
float step = 1.0 / float(u_shadowsRes);
float s = pow(abs(cos(u_dayTime * PI2)), 0.25) * u_shadowsOpacity;
vec3 normalOffset = a_realnormal * (a_distance > 64.0 ? 0.2 : 0.04);
int shadowIdx = a_distance > 64.0 ? 1 : 0;
int shadowIdx = a_distance > 80.0 ? 1 : 0;
vec4 mpos = u_shadowsMatrix[shadowIdx] * vec4(a_modelpos.xyz + normalOffset, 1.0);
vec3 projCoords = mpos.xyz / mpos.w;
projCoords = projCoords * 0.5 + 0.5;
projCoords.z -= 0.00001;
projCoords.z -= 0.00001 / u_shadowsRes;
if (shadowIdx > 0) {
projCoords.z -= 0.001;
}
float shadow = 0.0;
if (dot(a_realnormal, u_sunDir) < 0.0) {
// 5x5 kernel
for (int y = -2; y <= 2; y++) {
for (int x = -2; x <= 2; x++) {
vec3 offset = vec3(x, y, -(abs(x) + abs(y)) * 0.1) * step * 2.0 * u_shadowsSoftness;
// 3x3 kernel
for (int y = -1; y <= 1; y++) {
for (int x = -1; x <= 1; x++) {
vec3 offset = vec3(x, y, -(abs(x) + abs(y)) * 0.8) * step * 1.0 * u_shadowsSoftness;
shadow += texture(u_shadows[shadowIdx], projCoords + offset);
}
}
shadow /= 25.0;
shadow /= 9.0;
} else {
shadow = 0.5;
}