/usr/share/k3d/shaders/k3d_raysphere.h is in k3d-data 0.8.0.3-3build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | /************************************************************************
* raysphere.h - intersect a ray with a sphere (this is a useful
* solution to subproblems that crop up frequently)
*
* Author: Larry Gritz (gritzl@acm.org).
*
* Reference:
* _Advanced RenderMan: Creating CGI for Motion Picture_,
* by Anthony A. Apodaca and Larry Gritz, Morgan Kaufmann, 1999.
*
* $Revision: 1.1 $ $Date: 2004/05/19 18:15:20 $
*
************************************************************************/
#ifndef RAYSPHERE_H
#define RAYSPHERE_H 1
/* raysphere - calculate the intersection of ray (E,I) with a sphere
* centered at the origin and with radius r. We return the number of
* intersections found (0, 1, or 2), and place the distances to the
* intersections in t0, t1 (always with t0 <= t1). Ignore any hits
* closer than eps.
*/
float
raysphere (point E; vector I; /* Origin and unit direction of the ray */
float r; /* radius of sphere */
float eps; /* epsilon - ignore closer hits */
output float t0, t1; /* distances to intersection */
)
{
/* Set up a quadratic equation -- note that a==1 if I is normalized */
float b = 2 * ((vector E) . I);
float c = ((vector E) . (vector E)) - r*r;
float discrim = b*b - 4*c;
float solutions;
if (discrim > 0) { /* Two solutions */
discrim = sqrt(discrim);
t0 = (-discrim - b) / 2;
if (t0 > eps) {
t1 = (discrim - b) / 2;
solutions = 2;
} else {
t0 = (discrim - b) / 2;
solutions = (t0 > eps) ? 1 : 0;
}
} else if (discrim == 0) { /* One solution on the edge! */
t0 = -b/2;
solutions = (t0 > eps) ? 1 : 0;
} else { /* Imaginary solution -> no intersection */
solutions = 0;
}
return solutions;
}
#endif
|