From 13d33719f39976838d87d5beeb3cae3d52d2b003 Mon Sep 17 00:00:00 2001 From: past-due <30942300+past-due@users.noreply.github.com> Date: Sun, 17 Mar 2024 20:25:37 -0400 Subject: [PATCH] Fix: Normal terrain quality water + fog, adjust blending --- data/base/shaders/vk/water.frag | 11 ++++++++--- data/base/shaders/water.frag | 11 ++++++++--- lib/ivis_opengl/gfx_api_gl.cpp | 2 +- lib/ivis_opengl/gfx_api_vk.cpp | 6 +++--- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/data/base/shaders/vk/water.frag b/data/base/shaders/vk/water.frag index 063b23afc30..49523adfdb1 100644 --- a/data/base/shaders/vk/water.frag +++ b/data/base/shaders/vk/water.frag @@ -56,10 +56,15 @@ void main() { // Calculate linear fog float fogFactor = (fogEnd - vertexDistance) / (fogEnd - fogStart); - fogFactor = clamp(fogFactor, 0.0, 1.0); - // Return fragment color - fragColor = mix(fragColor, fogColor, fogFactor); + if (fogFactor >= 1.f) + { + discard; + } + + fogFactor = 1.0 - clamp(fogFactor, 0.0, 1.0); + fragColor.rgb *= fogFactor; // premultiply by fogFactor as alpha + fragColor.a = fogFactor; } FragColor = fragColor; diff --git a/data/base/shaders/water.frag b/data/base/shaders/water.frag index b15c64b8f34..0c045ed8812 100644 --- a/data/base/shaders/water.frag +++ b/data/base/shaders/water.frag @@ -65,10 +65,15 @@ void main() { // Calculate linear fog float fogFactor = (fogEnd - vertexDistance) / (fogEnd - fogStart); - fogFactor = clamp(fogFactor, 0.0, 1.0); - // Return fragment color - fragColor = mix(fragColor, fogColor, fogFactor); + if (fogFactor >= 1.f) + { + discard; + } + + fogFactor = 1.0 - clamp(fogFactor, 0.0, 1.0); + fragColor.rgb *= fogFactor; // premultiply by fogFactor as alpha + fragColor.a = fogFactor; } FragColor = fragColor; diff --git a/lib/ivis_opengl/gfx_api_gl.cpp b/lib/ivis_opengl/gfx_api_gl.cpp index 1d88ea09e84..25ba3b2df02 100644 --- a/lib/ivis_opengl/gfx_api_gl.cpp +++ b/lib/ivis_opengl/gfx_api_gl.cpp @@ -1269,7 +1269,7 @@ void gl_pipeline_state_object::bind() case REND_MULTIPLICATIVE: glEnable(GL_BLEND); - glBlendFunc(GL_ZERO, GL_SRC_COLOR); + glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA); break; case REND_PREMULTIPLIED: diff --git a/lib/ivis_opengl/gfx_api_vk.cpp b/lib/ivis_opengl/gfx_api_vk.cpp index bdcaadb16b9..72d5fd40aa8 100644 --- a/lib/ivis_opengl/gfx_api_vk.cpp +++ b/lib/ivis_opengl/gfx_api_vk.cpp @@ -1279,9 +1279,9 @@ std::array VkPSO::to_vk(const REND_MOD .setBlendEnable(true) .setColorBlendOp(vk::BlendOp::eAdd) .setAlphaBlendOp(vk::BlendOp::eAdd) - .setSrcColorBlendFactor(vk::BlendFactor::eZero) - .setSrcAlphaBlendFactor(vk::BlendFactor::eZero) - .setDstColorBlendFactor(vk::BlendFactor::eSrcColor) + .setSrcColorBlendFactor(vk::BlendFactor::eDstColor) + .setSrcAlphaBlendFactor(vk::BlendFactor::eDstAlpha) + .setDstColorBlendFactor(vk::BlendFactor::eOneMinusSrcAlpha) .setDstAlphaBlendFactor(vk::BlendFactor::eOneMinusSrcAlpha) .setColorWriteMask(vk_color_mask) };