From 4d9e43bf039e27eaf55b8117f6573cd295e7883c Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sun, 3 Dec 2023 23:49:58 +0300 Subject: [PATCH] Fog fix --- res/shaders/skybox_gen.glslf | 12 ++++++++++-- src/frontend/graphics/Skybox.cpp | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/res/shaders/skybox_gen.glslf b/res/shaders/skybox_gen.glslf index dc5fed4f..36761cdb 100644 --- a/res/shaders/skybox_gen.glslf +++ b/res/shaders/skybox_gen.glslf @@ -243,20 +243,28 @@ uniform vec3 u_zaxis; uniform vec3 u_lightDir; uniform int u_quality; uniform float u_mie; +uniform float u_fog; #include void main() { + + vec3 camera_position = vec3(0.0f, PLANET_RADIUS+1.0f, 0.0f); vec3 camera_vector = normalize(u_xaxis * v_coord.x*1.005 + u_yaxis * -v_coord.y*1.005 - u_zaxis); + + camera_vector = mix(camera_vector, vec3(0, 1, 0), min(1.0, u_fog-1.0)); + float fog = 1.0f / u_fog; // hide darkness at horizon camera_vector.y = max(0.01, camera_vector.y)*(1.0-u_mie*0.08) + 0.08*u_mie; camera_vector = normalize(camera_vector); // the color of this pixel vec3 col = vec3(0.0);//scene.xyz; + + // get the atmosphere color col += calculate_scattering( @@ -265,7 +273,7 @@ void main() { 1e12f, // max dist, essentially the scene depth vec3(0.0f), // scene color, the color of the current pixel being rendered u_lightDir, // light direction - vec3(40.0), // light intensity, 40 looks nice + vec3(40.0*fog), // light intensity, 40 looks nice PLANET_POS, // position of the planet PLANET_RADIUS, // radius of the planet in meters ATMOS_RADIUS, // radius of the atmosphere in meters @@ -273,7 +281,7 @@ void main() { MIE_BETA, // Mie scattering coefficient ABSORPTION_BETA, // Absorbtion coefficient AMBIENT_BETA, // ambient scattering, turned off for now. This causes the air to glow a bit when no light reaches it - G, // Mie preferred scattering direction + G*fog, // Mie preferred scattering direction HEIGHT_RAY, // Rayleigh scale height HEIGHT_MIE*u_mie*u_mie, // Mie scale height HEIGHT_ABSORPTION, // the height at which the most absorption happens diff --git a/src/frontend/graphics/Skybox.cpp b/src/frontend/graphics/Skybox.cpp index 08e2fff0..9be557dc 100644 --- a/src/frontend/graphics/Skybox.cpp +++ b/src/frontend/graphics/Skybox.cpp @@ -86,6 +86,7 @@ void Skybox::refresh(float t, float mie, uint quality) { shader->uniform1i("u_quality", quality); shader->uniform1f("u_mie", mie); + shader->uniform1f("u_fog", mie); shader->uniform3f("u_lightDir", glm::normalize(vec3(sin(t), -cos(t), -0.7f))); for (uint face = 0; face < 6; face++) { glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, cubemap, 0);