|
|
@@ -12,6 +12,7 @@
|
|
|
#pragma anki start comp
|
|
|
|
|
|
#include <shaders/glsl_cpp_common/ClusteredShading.h>
|
|
|
+#include <shaders/Common.glsl>
|
|
|
|
|
|
layout(local_size_x = WORKGROUP_SIZE.x, local_size_y = WORKGROUP_SIZE.y, local_size_z = 1) in;
|
|
|
|
|
|
@@ -29,7 +30,7 @@ ANKI_PUSH_CONSTANTS(PushConsts, u_regs);
|
|
|
#define u_fogAbsorptionCoeff u_regs.m_fogScatteringCoeffFogAbsorptionCoeffDensityPad1.y
|
|
|
#define u_density u_regs.m_fogScatteringCoeffFogAbsorptionCoeffDensityPad1.z
|
|
|
#define u_fogDiffuse u_regs.m_fogDiffusePad1.xyz
|
|
|
-#define u_clustererMagic m_regs.m_clustererMagic
|
|
|
+#define u_clustererMagic u_regs.m_clustererMagic
|
|
|
|
|
|
void main()
|
|
|
{
|
|
|
@@ -41,7 +42,7 @@ void main()
|
|
|
Vec2 uv = (Vec2(gl_GlobalInvocationID.xy) + 0.5) / Vec2(VOLUME_SIZE.xy);
|
|
|
|
|
|
Vec4 colorAndDensityFront = Vec4(0.0);
|
|
|
- ANKI_LOOP for(U32 i = 0u; i <= VOLUME_SIZE.z; ++i)
|
|
|
+ ANKI_LOOP for(U32 i = 0u; i < VOLUME_SIZE.z; ++i)
|
|
|
{
|
|
|
// Compute the cluster K limits of this cluster fragment
|
|
|
F32 clusterKNear = F32(i) * (F32(FINAL_CLUSTER_Z + 1u) / F32(VOLUME_SIZE.z));
|
|
|
@@ -59,18 +60,19 @@ void main()
|
|
|
F32 absorption = u_density * u_fogAbsorptionCoeff * layerThinkness;
|
|
|
|
|
|
// Read the light value
|
|
|
- F32 k = mix(clusterKFar, clusterKNear, 0.5);
|
|
|
- Vec3 light = textureLod(u_lightVolume, Vec3(uv, k / F32(FINAL_CLUSTER_Z + 1u)), 0.0).rgb;
|
|
|
+ Vec3 light = textureLod(u_lightVolume, Vec3(uv, clusterKFar / F32(FINAL_CLUSTER_Z + 1u)), 0.0).rgb;
|
|
|
light *= u_fogDiffuse;
|
|
|
|
|
|
// Integrate
|
|
|
- Vec4 colorAndDensityBack = Vec4(light * scattering, scattering * absoption);
|
|
|
+ Vec4 colorAndDensityBack = Vec4(light * scattering, scattering + absorption);
|
|
|
|
|
|
Vec3 l = colorAndDensityFront.rgb + saturate(exp(-colorAndDensityFront.a)) * colorAndDensityBack.rgb;
|
|
|
colorAndDensityFront = Vec4(l.rgb, colorAndDensityFront.a + colorAndDensityBack.a);
|
|
|
|
|
|
// Write the value
|
|
|
- Vec4 valToWrite = Vec4(colorAndDensityFront.rgb, exp(-colorAndDensityFront.a));
|
|
|
+ Vec4 valToWrite = Vec4(colorAndDensityFront.rgb, saturate(exp(-colorAndDensityFront.a)));
|
|
|
imageStore(u_fogVolume, IVec3(UVec3(gl_GlobalInvocationID.xy, i)), valToWrite);
|
|
|
}
|
|
|
-}
|
|
|
+}
|
|
|
+
|
|
|
+#pragma anki end
|