Skip to content

Instantly share code, notes, and snippets.

@Shell64
Created April 8, 2017 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shell64/48cfe3740308fc715541328f017085eb to your computer and use it in GitHub Desktop.
Save Shell64/48cfe3740308fc715541328f017085eb to your computer and use it in GitHub Desktop.
SSR Render Loop
for(int Count = 0; Count < 160; Count++)
{
if(CurrentPosition.x < 0.0 || CurrentPosition.x > 1.0 ||
CurrentPosition.y < 0.0 || CurrentPosition.y > 1.0 ||
CurrentPosition.z < 0.0 || CurrentPosition.z > 1.0)
{
return vec4(0.0, 0.0, 0.0, 1.0);
}
//intersections
float SampleDepth = texture2DLod(tex_depth, CurrentPosition.xy, 0).x;
/*
if(SampleDepth == 1.0)
{
return vec4(0.0, 0.0, 0.0, 1.0);
}
*/
float CurrentDepth = CurrentPosition.z;
float Difference = CurrentDepth - SampleDepth;
if(Difference >= 0.0 && Difference < length(ScreenSpaceVector))
{
ScreenSpaceVector *= StepRefinementAmount;
CurrentPosition = OLD_Position;
NumRefinements++;
if(NumRefinements >= MaxRefinements)
{
SSR = CurrentPosition.xy;
break;
}
}
OLD_Position = CurrentPosition;
CurrentPosition = OLD_Position + ScreenSpaceVector;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment