fix night shadows

This commit is contained in:
MihailRis 2025-06-11 00:51:42 +03:00
parent 11283f9a33
commit 1a3fb9f5b3
2 changed files with 11 additions and 3 deletions

View File

@ -3,6 +3,7 @@
uniform sampler2DShadow u_shadows[2];
uniform mat4 u_shadowsMatrix[2];
uniform float u_dayTime;
uniform int u_shadowsRes;
@ -22,7 +23,7 @@ float calc_shadow() {
shadow = 0.0;
// TODO: optimize
if (dot(a_realnormal, u_sunDir) < 0.0) {
if (dot(a_realnormal, u_sunDir) < 0.0 || true) {
if (a_distance > 128) {
for (int y = -1; y <= 1; y++) {
for (int x = -1; x <= 1; x++) {
@ -48,7 +49,9 @@ float calc_shadow() {
}
shadow /= 25;
}
shadow = shadow * 0.5 + 0.5;
float s = abs(cos(u_dayTime * 3.141592 * 2.0));
s = pow(s, 0.7);
shadow = mix(0.5, shadow * 0.5 + 0.5, s);
} else {
shadow = 0.5;
}

View File

@ -370,7 +370,12 @@ void WorldRenderer::generateShadowsMap(
shadowCamera.perspective = false;
shadowCamera.setAspectRatio(1.0f);
float sunAngle = glm::radians(fmod(90.0f - worldInfo.daytime * 360.0f, 180.0f));
float t = worldInfo.daytime - 0.25f;
if (t < 0.0f) {
t += 1.0f;
}
t = fmod(t, 0.5f);
float sunAngle = glm::radians(90.0f - (t + 0.25f) * 360.0f);
shadowCamera.rotate(
sunAngle,
glm::radians(-45.0f),