From 4ff18fec990fd4cabcc7e7eaf96453fb80dab88b Mon Sep 17 00:00:00 2001 From: MihailRis Date: Tue, 23 Sep 2025 00:51:21 +0300 Subject: [PATCH] fix sky shader --- res/shaders/lib/shadows.glsl | 2 +- res/shaders/lib/sky.glsl | 2 +- res/shaders/skybox_gen.glslf | 6 +++++- src/graphics/core/Shadows.cpp | 6 +++++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/res/shaders/lib/shadows.glsl b/res/shaders/lib/shadows.glsl index 71ef4776..658e9a69 100644 --- a/res/shaders/lib/shadows.glsl +++ b/res/shaders/lib/shadows.glsl @@ -43,7 +43,7 @@ float calc_shadow( // TODO: add array textures support float calc_shadow(vec4 modelPos, vec3 realnormal, float distance) { #ifdef ENABLE_SHADOWS - float s = pow(abs(cos(u_dayTime * PI2)), 0.25) * u_shadowsOpacity; + float s = u_shadowsOpacity; vec3 normalOffset = realnormal * (distance > 64.0 ? 0.2 : 0.04); // as slow as mix(...) diff --git a/res/shaders/lib/sky.glsl b/res/shaders/lib/sky.glsl index 028fb51a..ce3604f5 100644 --- a/res/shaders/lib/sky.glsl +++ b/res/shaders/lib/sky.glsl @@ -4,7 +4,7 @@ #include vec3 pick_sky_color(samplerCube cubemap) { - vec3 skyLightColor = texture(cubemap, vec3(0.8f, 0.01f, 0.4f)).rgb; + vec3 skyLightColor = texture(cubemap, vec3(0.4f, 0.05f, 0.4f)).rgb; skyLightColor *= SKY_LIGHT_TINT; skyLightColor = min(vec3(1.0f), skyLightColor * SKY_LIGHT_MUL); skyLightColor = max(MIN_SKY_LIGHT, skyLightColor); diff --git a/res/shaders/skybox_gen.glslf b/res/shaders/skybox_gen.glslf index 481203f3..583104eb 100644 --- a/res/shaders/skybox_gen.glslf +++ b/res/shaders/skybox_gen.glslf @@ -268,7 +268,11 @@ void main() { camera_vector, // the camera vector (ray direction of this pixel) 1e12f, // max dist, essentially the scene depth vec3(0.0f), // scene color, the color of the current pixel being rendered - vec3(u_lightDir.x, pow(u_lightDir.y, 3.0), u_lightDir.z), // light direction + vec3( + u_lightDir.x, + u_lightDir.y, + u_lightDir.z + ), // light direction vec3(40.0*fog), // light intensity, 40 looks nice PLANET_POS, // position of the planet PLANET_RADIUS, // radius of the planet in meters diff --git a/src/graphics/core/Shadows.cpp b/src/graphics/core/Shadows.cpp index d37dc557..c47b8a6a 100644 --- a/src/graphics/core/Shadows.cpp +++ b/src/graphics/core/Shadows.cpp @@ -96,12 +96,16 @@ void Shadows::setup(Shader& shader, const Weather& weather) { if (shadows) { const auto& worldInfo = level.getWorld()->getInfo(); float cloudsIntensity = glm::max(worldInfo.fog, weather.clouds()); + float shadowsOpacity = 1.0f - cloudsIntensity; + shadowsOpacity *= glm::sqrt(glm::abs( + glm::mod((worldInfo.daytime + 0.5f) * 2.0f, 1.0f) * 2.0f - 1.0f + )); shader.uniform1i("u_screen", 0); shader.uniformMatrix("u_shadowsMatrix[0]", shadowCamera.getProjView()); shader.uniformMatrix("u_shadowsMatrix[1]", wideShadowCamera.getProjView()); shader.uniform3f("u_sunDir", shadowCamera.front); shader.uniform1i("u_shadowsRes", shadowMap->getResolution()); - shader.uniform1f("u_shadowsOpacity", 1.0f - cloudsIntensity); // TODO: make it configurable + shader.uniform1f("u_shadowsOpacity", shadowsOpacity); // TODO: make it configurable shader.uniform1f("u_shadowsSoftness", 1.0f + cloudsIntensity * 4); // TODO: make it configurable glActiveTexture(GL_TEXTURE0 + TARGET_SHADOWS0);