diff --git a/shaders/final_combine.frag b/shaders/final_combine.frag index 4fd4e2b32fd3f3f11dcb22fc9dcdc0995ea9b4c8..64fa77e5190be51e1a36e4258e14f31afbce58da 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 c97ea00327df46a75fbef7b877c438a98fb5dab7..8bca2dd5bd3d6512b891611af3bd03bf79fa483e 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 a1fb61e75f3c37518e81065a287371bc1cfce4a6..82475789a2a621d6a9d01d1908452760e09f4a9b 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 7d5bfdce29277f54c126d8efb8595a4b157d034e..d2571ddf981d14e9308ebfdfd9ab10b3aca359a1 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 0427c37663bc8660ddccb026cdd6a34faeb03e70..bd783f1a2b88e52644cb5862d48d100ecde0d571 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);