|
@@ -58,6 +58,7 @@ layout(location = 0) out vec3 out_color;
|
|
|
|
|
|
|
|
const uint MAX_SAMPLES_PER_CLUSTER = 4u;
|
|
const uint MAX_SAMPLES_PER_CLUSTER = 4u;
|
|
|
const float DIST_BETWEEN_SAMPLES = 0.25;
|
|
const float DIST_BETWEEN_SAMPLES = 0.25;
|
|
|
|
|
+const float HISTORY_FEEDBACK = 1.0 / 16.0;
|
|
|
|
|
|
|
|
// Return the diffuse color without taking into account the diffuse term of the particles.
|
|
// Return the diffuse color without taking into account the diffuse term of the particles.
|
|
|
vec3 computeLightColor(vec3 fragPos, uint plightCount, uint plightIdx, uint slightCount, uint slightIdx)
|
|
vec3 computeLightColor(vec3 fragPos, uint plightCount, uint plightIdx, uint slightCount, uint slightIdx)
|
|
@@ -108,16 +109,30 @@ vec3 computeLightColor(vec3 fragPos, uint plightCount, uint plightIdx, uint slig
|
|
|
return outColor;
|
|
return outColor;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+vec3 readHistory(vec3 ndc, out float historyFeedback)
|
|
|
|
|
+{
|
|
|
|
|
+ vec4 v4 = u_prevViewProjMatMulInvViewProjMat * vec4(ndc, 1.0);
|
|
|
|
|
+ v4.xy /= v4.w;
|
|
|
|
|
+
|
|
|
|
|
+ vec2 oldUv = NDC_TO_UV(v4.xy);
|
|
|
|
|
+ vec3 history = textureLod(u_historyRt, oldUv, 0.0).rgb;
|
|
|
|
|
+
|
|
|
|
|
+ // Compute the history blend. If clip falls outside NDC then it's 1.0 (use only current fog term) and if it's
|
|
|
|
|
+ // inside NDC then use the HISTORY_FEEDBACK value
|
|
|
|
|
+ vec2 posNdc = abs(v4.xy);
|
|
|
|
|
+ historyFeedback = max(posNdc.x, posNdc.y);
|
|
|
|
|
+ historyFeedback = min(floor(historyFeedback), 1.0 - HISTORY_FEEDBACK);
|
|
|
|
|
+ historyFeedback += HISTORY_FEEDBACK;
|
|
|
|
|
+
|
|
|
|
|
+ return history;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
void main()
|
|
void main()
|
|
|
{
|
|
{
|
|
|
float depth = textureLod(u_msDepthRt, in_uv, 0.0).r;
|
|
float depth = textureLod(u_msDepthRt, in_uv, 0.0).r;
|
|
|
|
|
|
|
|
vec3 ndc = UV_TO_NDC(vec3(in_uv, depth));
|
|
vec3 ndc = UV_TO_NDC(vec3(in_uv, depth));
|
|
|
|
|
|
|
|
- vec4 v4 = u_prevViewProjMatMulInvViewProjMat * vec4(ndc, 1.0);
|
|
|
|
|
- vec2 oldUv = NDC_TO_UV(v4.xy / v4.w);
|
|
|
|
|
- vec3 history = textureLod(u_historyRt, oldUv, 0.0).rgb;
|
|
|
|
|
-
|
|
|
|
|
vec3 farPos;
|
|
vec3 farPos;
|
|
|
farPos.z = u_unprojectionParams.z / (u_unprojectionParams.w + depth);
|
|
farPos.z = u_unprojectionParams.z / (u_unprojectionParams.w + depth);
|
|
|
farPos.xy = ndc.xy * u_unprojectionParams.xy * farPos.z;
|
|
farPos.xy = ndc.xy * u_unprojectionParams.xy * farPos.z;
|
|
@@ -181,8 +196,15 @@ void main()
|
|
|
|
|
|
|
|
newCol *= u_fogParticleColor;
|
|
newCol *= u_fogParticleColor;
|
|
|
|
|
|
|
|
|
|
+ // Read history
|
|
|
|
|
+ float historyFeedback;
|
|
|
|
|
+ vec3 history = readHistory(ndc, historyFeedback);
|
|
|
|
|
+
|
|
|
|
|
+ // Fix ghosting
|
|
|
history = max(history, newCol);
|
|
history = max(history, newCol);
|
|
|
- out_color = mix(history, newCol, 1.0 / 16.0);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // Blend
|
|
|
|
|
+ out_color = mix(history, newCol, historyFeedback);
|
|
|
}
|
|
}
|
|
|
]]></source>
|
|
]]></source>
|
|
|
</shader>
|
|
</shader>
|