16 #define TACHYON_INTERNAL 1 34 memset(xvol, 0,
sizeof(
parvol));
36 xvol->normal = (void (*)(
void *,
void *,
void *,
void *))(
box_normal);
54 col.g = (scalar - 0.5) * 2.0;
58 col.b = 1.0 - (scalar / 2.0);
67 flt a, tx1, tx2, ty1, ty2, tz1, tz2;
69 flt t, tdist, dt, ddt, sum, tt;
70 vector pnt, bln, bln_1;
78 bx = (
box *) tex->obj;
79 xvol = (
parvol *) tex->obj;
89 if ((ry->o.x < bx->
min.x) || (ry->o.x > bx->
max.x))
return col;
91 tx1 = (bx->
min.x - ry->o.x) / ry->d.x;
92 tx2 = (bx->
max.x - ry->o.x) / ry->d.x;
93 if (tx1 > tx2) { a=tx1; tx1=tx2; tx2=a; }
94 if (tx1 > tnear) tnear=tx1;
95 if (tx2 < tfar) tfar=tx2;
97 if (tnear > tfar)
return col;
98 if (tfar < 0.0)
return col;
100 if (ry->d.y == 0.0) {
101 if ((ry->o.y < bx->
min.y) || (ry->o.y > bx->
max.y))
return col;
103 ty1 = (bx->
min.y - ry->o.y) / ry->d.y;
104 ty2 = (bx->
max.y - ry->o.y) / ry->d.y;
105 if (ty1 > ty2) { a=ty1; ty1=ty2; ty2=a; }
106 if (ty1 > tnear) tnear=ty1;
107 if (ty2 < tfar) tfar=ty2;
109 if (tnear > tfar)
return col;
110 if (tfar < 0.0)
return col;
112 if (ry->d.z == 0.0) {
113 if ((ry->o.z < bx->
min.z) || (ry->o.z > bx->
max.z))
return col;
115 tz1 = (bx->
min.z - ry->o.z) / ry->d.z;
116 tz2 = (bx->
max.z - ry->o.z) / ry->d.z;
117 if (tz1 > tz2) { a=tz1; tz1=tz2; tz2=a; }
118 if (tz1 > tnear) tnear=tz1;
119 if (tz2 < tfar) tfar=tz2;
121 if (tnear > tfar)
return col;
122 if (tfar < 0.0)
return col;
124 if (tnear < 0.0) tnear=0.0;
136 bln_1.x = 1.0 / bln.x;
137 bln_1.y = 1.0 / bln.y;
138 bln_1.z = 1.0 / bln.z;
141 for (t=tnear; t<=tfar; t+=dt) {
143 pnt.x=((ry->o.x + (ry->d.x * t)) - bx->
min.x) * bln_1.x;
144 pnt.y=((ry->o.y + (ry->d.y * t)) - bx->
min.y) * bln_1.y;
145 pnt.z=((ry->o.z + (ry->d.z * t)) - bx->
min.z) * bln_1.z;
148 scalar = xvol->
evaluator(pnt.x, pnt.y, pnt.z);
150 transval = tt * scalar;
155 col.r += transval * col2.r * xvol->
ambient;
156 col.g += transval * col2.g * xvol->
ambient;
157 col.b += transval * col2.b * xvol->
ambient;
165 N.x = (xvol->
evaluator(pnt.x - ddt, pnt.y, pnt.z) -
166 xvol->
evaluator(pnt.x + ddt, pnt.y, pnt.z)) * 8.0 * tt;
168 N.y = (xvol->
evaluator(pnt.x, pnt.y - ddt, pnt.z) -
169 xvol->
evaluator(pnt.x, pnt.y + ddt, pnt.z)) * 8.0 * tt;
171 N.z = (xvol->
evaluator(pnt.x, pnt.y, pnt.z - ddt) -
172 xvol->
evaluator(pnt.x, pnt.y, pnt.z + ddt)) * 8.0 * tt;
175 if ((N.x*N.x + N.y*N.y + N.z*N.z) > 0.0) {
181 for (i=0; i<numlights; i++) {
190 diffint.r += inten*li->tex->col.r;
191 diffint.g += inten*li->tex->col.g;
192 diffint.b += inten*li->tex->col.b;
195 col.r += col2.r * diffint.r * xvol->
diffuse;
196 col.g += col2.g * diffint.g * xvol->
diffuse;
197 col.b += col2.b * diffint.b * xvol->
diffuse;
color shade_transmission(ray *incident, const shadedata *shadevars, flt trans)
RT_OBJECT_HEAD vector min
minimum vertex coordinate
flt diffuse
diffuse lighting coefficient
color ParVoxelColor(flt scalar)
void box_intersect(const box *bx, ray *ry)
vector max
maximum vertex coordinate
double flt
generic floating point number, using double
vector ctr
point light position
#define VDOT(return, a, b)
Tachyon cross-platform timers, special math function wrappers, and RNGs.
flt opacity
transmissive surface factor
flt(* evaluator)(flt, flt, flt)
sample fctn pointer
flt ambient
ambient lighting coefficient
Tachyon public API function prototypes and declarations used to drive the ray tracing engine...
void box_normal(const box *bx, const vector *pnt, const ray *incident, vector *N)
color par_volume_texture(vector *hit, texture *tex, ray *ry)
int samples
number of volumetric samples to take
axis-aligned box definition