Skip to content

Instantly share code, notes, and snippets.

@tmpvar
Created March 19, 2014 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tmpvar/9647218 to your computer and use it in GitHub Desktop.
Save tmpvar/9647218 to your computer and use it in GitHub Desktop.
a few raymarching fx that I've found
uniform float aoIntensity; // {"label":"AO intensity", "min":0, "max":1, "step":0.01, "default":0.15, "group":"Shading", "group_label":"Ambient occlusion"}
uniform float aoSpread; // {"label":"AO spread", "min":0, "max":20, "step":0.01, "default":9, "group":"Shading"}
// Ambient occlusion approximation.
// Based upon boxplorer's implementation which is derived from:
// http://www.iquilezles.org/www/material/nvscene2008/rwwtt.pdf
float ambientOcclusion(vec3 p, vec3 n, float eps)
{
float o = 1.0; // Start at full output colour intensity
eps *= aoSpread; // Spread diffuses the effect
float k = aoIntensity / eps; // Set intensity factor
float d = 2.0 * eps; // Start ray a little off the surface
for (int i = 0; i < aoIterations; ++i) {
o -= (d - dE(p + n * d).x) * k;
d += eps;
k *= 0.5; // AO contribution drops as we move further from the surface
}
return clamp(o, 0.0, 1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment