From 5621b194682b89ad920e6c0fdb98cfdc88b5aa42 Mon Sep 17 00:00:00 2001 From: adany292 <adany292@student.liu.se> Date: Wed, 25 Dec 2024 14:40:22 +0100 Subject: [PATCH] Discared smoothing thicknes fro backrgound piels, fluid now looks better --- shaders/final_combine.frag | 11 ++++++++++- shaders/thickness.frag | 2 +- shaders/thickness_attenuation.frag | 12 +++++++++++- shaders/thickness_filter.frag | 4 ++++ src/FluidRenderer.cpp | 2 +- 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/shaders/final_combine.frag b/shaders/final_combine.frag index 4fd4e2b..64fa77e 100644 --- a/shaders/final_combine.frag +++ b/shaders/final_combine.frag @@ -100,8 +100,17 @@ void main() vec3 finalColor = fluidColor * lighting; finalColor += fluidColor * fresnel; + //--------------------------------------- + // Attenuation + //--------------------------------------- + float attenuation = texture(uLightAttenTex, TexCoords).r; + finalColor *= attenuation; + + float alpha = texture(uLightAttenTex, TexCoords).a; + // float alpha = clamp(1.0 - attenuation, 0.0, 1.0); + //--------------------------------------- // 5) Output //--------------------------------------- - FragColor = vec4(finalColor, 1.0); + FragColor = vec4(finalColor, alpha); } diff --git a/shaders/thickness.frag b/shaders/thickness.frag index c97ea00..8bca2dd 100644 --- a/shaders/thickness.frag +++ b/shaders/thickness.frag @@ -19,7 +19,7 @@ void main() discard; // For thickness: each particle in this pixel adds some amount. - float thicknessIncrement = 0.04; + float thicknessIncrement = 0.08; // Output that in the red channel. Using GL32F only reed chanele sotred FragColor = vec4(thicknessIncrement, 0.0, 0.0, 1.0); diff --git a/shaders/thickness_attenuation.frag b/shaders/thickness_attenuation.frag index a1fb61e..8247578 100644 --- a/shaders/thickness_attenuation.frag +++ b/shaders/thickness_attenuation.frag @@ -24,5 +24,15 @@ void main() // to be fully absorbing, you do: finalColor = fluidColor * (1 - attenuation), etc.) //vec3 color = fluidColor * (1 - attenuation); //FragColor = vec4(color, 1.0); - FragColor = vec4(attenuation, 0.0, 0.0, 1.0); + float alpha = 0; + + if(thicknessVal < 0.001) { + // Background + alpha = 0; + } else + { + alpha = clamp((1.0 - attenuation)*4, 0.0, 1.0); + } + + FragColor = vec4(attenuation, 0.0, 0.0, alpha); } diff --git a/shaders/thickness_filter.frag b/shaders/thickness_filter.frag index 7d5bfdc..d2571dd 100644 --- a/shaders/thickness_filter.frag +++ b/shaders/thickness_filter.frag @@ -16,6 +16,8 @@ void main() // Sample center float centerVal = texture(uThicknessTex, TexCoords).r; + if (centerVal < 0.01) discard; + // Accumulate for a 1D Gaussian blur float sum = 0.0; float wSum = 0.0; @@ -28,6 +30,8 @@ void main() float sampleVal = texture(uThicknessTex, sampleUV).r; + //if (sampleVal < 0.01) continue; + // Spatial weight from precomputed array float w = gaussWeights[abs(i)]; diff --git a/src/FluidRenderer.cpp b/src/FluidRenderer.cpp index 0427c37..bd783f1 100644 --- a/src/FluidRenderer.cpp +++ b/src/FluidRenderer.cpp @@ -989,7 +989,7 @@ void FluidRenderer::renderThicknessAttenFrame() glUniform1i(glGetUniformLocation(m_thicknessAttenProgram.programID, "uThicknessTex"), 0); // 3) Set uniform: absorption, fluidColor, etc. - float absorption = 0.8f; // tweak to taste + float absorption = 0.2f; // tweak to taste GLuint absorpLoc = glGetUniformLocation(m_thicknessAttenProgram.programID, "absorption"); glUniform1f(absorpLoc, absorption); -- GitLab