Skip to content

Instantly share code, notes, and snippets.

@Piratkopia13
Created January 26, 2020 12:46
Show Gist options
  • Save Piratkopia13/a11d1c26d3c8bab5e986e3b4b17dd161 to your computer and use it in GitHub Desktop.
Save Piratkopia13/a11d1c26d3c8bab5e986e3b4b17dd161 to your computer and use it in GitHub Desktop.
// Temporal filtering via an exponential moving average
float alpha = 0.3f; // Temporal fade, trading temporal stability for lag
// Reproject screenTexCoord to where it was last frame
float2 motionVector = gbuffer_motionVectors.SampleLevel(ss, screenTexCoord, 0);
motionVector.y = 1.f - motionVector.y;
motionVector = motionVector * 2.f - 1.0f;
float2 reprojectedTexCoord = screenTexCoord - motionVector;
// Sample the shadow texture from last frame
// Make sure to use a sampler with border color wrapping to avoid artifacts
// The first channel of the output contains shadows for the first/visibility bounce
// The second channel of the output contains shadows in reflections
float2 cLast = InputShadowsLastFrame.SampleLevel(motionSS, reprojectedTexCoord, 0).rg;
float2 shadow = float2(firstBounceShadowAmount, reflectionShadowAmount);
shadow = alpha * (1.0f - shadow) + (1.0f - alpha) * cLast;
// Write shadow to texture which will be denoised and used in shading the current frame
// as well as used as InputShadowsLastFrame the following frame
lOutputShadows[launchIndex] = shadow;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment