Skip to content

Instantly share code, notes, and snippets.

@ShiftedClock
Created April 27, 2019 09:18
Show Gist options
  • Select an option

  • Save ShiftedClock/618dee31a85a2ea728e92dc5684dd68d to your computer and use it in GitHub Desktop.

Select an option

Save ShiftedClock/618dee31a85a2ea728e92dc5684dd68d to your computer and use it in GitHub Desktop.
An ambient occlusion routine for a raymarched shader
uniform float _AoStepsize, _AoIntensity;
uniform int _AoIterations;
float AmbientOcclusion(float3 ro, float3 p, float3 re, float3 n) {
float step = _AoStepsize;
float ao = 0.0;
float dist;
for (int i = 1; i <= _AoIterations; i++) {
dist = step * i;
ao += max(0.0,(dist - distanceField(ro, p + n * dist, re).w) / dist);
}
return (1.0 - ao * _AoIntensity);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment