Skip to content

Instantly share code, notes, and snippets.

View PiMaker's full-sized avatar
🕴️

pi PiMaker

🕴️
View GitHub Profile
@wwwtyro
wwwtyro / gist:beecc31d65d1004f5a9d
Created March 16, 2015 05:54
GLSL ray-sphere intersection
float raySphereIntersect(vec3 r0, vec3 rd, vec3 s0, float sr) {
// - r0: ray origin
// - rd: normalized ray direction
// - s0: sphere center
// - sr: sphere radius
// - Returns distance from r0 to first intersecion with sphere,
// or -1.0 if no intersection.
float a = dot(rd, rd);
vec3 s0_r0 = r0 - s0;
float b = 2.0 * dot(rd, s0_r0);