Skip to content

Instantly share code, notes, and snippets.

@hughsk
Created March 19, 2015 19:30
Show Gist options
  • Save hughsk/568527653ef52f13c7cf to your computer and use it in GitHub Desktop.
Save hughsk/568527653ef52f13c7cf to your computer and use it in GitHub Desktop.
float sSphere(vec3 p, float time) {
return length(p) - 1.0 - noise(p, time) * 0.05;
}
vec3 calcNormal(vec3 p, float time) {
const float eps = 0.002;
const vec2 offset = vec2(1.0, -1.0);
return normalize(
offset.xyy * sSphere(p + offset.xyy * eps, time) +
offset.yyx * sSphere(p + offset.yyx * eps, time) +
offset.yxy * sSphere(p + offset.yxy * eps, time) +
offset.xxx * sSphere(p + offset.xxx * eps, time)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment