16 #define TACHYON_INTERNAL 1 42 (
void (*)(
const void *,
const void *,
const void *,
void *))(
box_normal),
50 standard_texture * tex, * xvoltex;
52 tex = (standard_texture *) voidtex;
55 memset(xvol, 0,
sizeof(
extvol));
67 xvoltex = malloc(
sizeof(standard_texture));
68 memset(xvoltex, 0,
sizeof(standard_texture));
73 xvoltex->rot = xvoltex->ctr;
74 xvoltex->scale = xvoltex->ctr;
75 xvoltex->uaxs = xvoltex->ctr;
76 xvoltex->vaxs = xvoltex->ctr;
77 xvoltex->flags = RT_TEXTURE_NOFLAGS;
79 xvoltex->col=tex->col;
82 xvoltex->specular=0.0;
86 xvoltex->obj = (
void *) xvol;
88 xvol->tex = (texture *) xvoltex;
106 col.g = (scalar - 0.5) * 2.0;
110 col.b = 1.0 - (scalar / 2.0);
119 flt a, tx1, tx2, ty1, ty2, tz1, tz2;
121 flt t, tdist, dt, ddt, sum, tt;
122 vector pnt, bln, bln_1;
123 flt scalar, transval;
128 standard_texture * tex = (standard_texture *) tx;
130 bx = (
box *) tex->obj;
131 xvol = (
extvol *) tex->obj;
140 if (ry->d.x == 0.0) {
141 if ((ry->o.x < bx->
min.x) || (ry->o.x > bx->
max.x))
return col;
143 tx1 = (bx->
min.x - ry->o.x) / ry->d.x;
144 tx2 = (bx->
max.x - ry->o.x) / ry->d.x;
145 if (tx1 > tx2) { a=tx1; tx1=tx2; tx2=a; }
146 if (tx1 > tnear) tnear=tx1;
147 if (tx2 < tfar) tfar=tx2;
149 if (tnear > tfar)
return col;
150 if (tfar < 0.0)
return col;
152 if (ry->d.y == 0.0) {
153 if ((ry->o.y < bx->
min.y) || (ry->o.y > bx->
max.y))
return col;
155 ty1 = (bx->
min.y - ry->o.y) / ry->d.y;
156 ty2 = (bx->
max.y - ry->o.y) / ry->d.y;
157 if (ty1 > ty2) { a=ty1; ty1=ty2; ty2=a; }
158 if (ty1 > tnear) tnear=ty1;
159 if (ty2 < tfar) tfar=ty2;
161 if (tnear > tfar)
return col;
162 if (tfar < 0.0)
return col;
164 if (ry->d.z == 0.0) {
165 if ((ry->o.z < bx->
min.z) || (ry->o.z > bx->
max.z))
return col;
167 tz1 = (bx->
min.z - ry->o.z) / ry->d.z;
168 tz2 = (bx->
max.z - ry->o.z) / ry->d.z;
169 if (tz1 > tz2) { a=tz1; tz1=tz2; tz2=a; }
170 if (tz1 > tnear) tnear=tz1;
171 if (tz2 < tfar) tfar=tz2;
173 if (tnear > tfar)
return col;
174 if (tfar < 0.0)
return col;
176 if (tnear < 0.0) tnear=0.0;
188 bln_1.x = 1.0 / bln.x;
189 bln_1.y = 1.0 / bln.y;
190 bln_1.z = 1.0 / bln.z;
193 for (t=tnear; t<=tfar; t+=dt) {
195 pnt.x=((ry->o.x + (ry->d.x * t)) - bx->
min.x) * bln_1.x;
196 pnt.y=((ry->o.y + (ry->d.y * t)) - bx->
min.y) * bln_1.y;
197 pnt.z=((ry->o.z + (ry->d.z * t)) - bx->
min.z) * bln_1.z;
200 scalar = xvol->
evaluator(pnt.x, pnt.y, pnt.z);
202 transval = tt * scalar;
207 col.r += transval * col2.r * xvol->
ambient;
208 col.g += transval * col2.g * xvol->
ambient;
209 col.b += transval * col2.b * xvol->
ambient;
217 N.x = (xvol->
evaluator(pnt.x - ddt, pnt.y, pnt.z) -
218 xvol->
evaluator(pnt.x + ddt, pnt.y, pnt.z)) * 8.0 * tt;
220 N.y = (xvol->
evaluator(pnt.x, pnt.y - ddt, pnt.z) -
221 xvol->
evaluator(pnt.x, pnt.y + ddt, pnt.z)) * 8.0 * tt;
223 N.z = (xvol->
evaluator(pnt.x, pnt.y, pnt.z - ddt) -
224 xvol->
evaluator(pnt.x, pnt.y, pnt.z + ddt)) * 8.0 * tt;
227 if ((N.x*N.x + N.y*N.y + N.z*N.z) > 0.0) {
235 cur = ry->scene->lightlist;
236 while (cur != NULL) {
245 standard_texture * litex = (standard_texture *) li->tex;
247 diffint.r += inten * litex->col.r;
248 diffint.g += inten * litex->col.g;
249 diffint.b += inten * litex->col.b;
255 col.r += col2.r * diffint.r * xvol->
diffuse;
256 col.g += col2.g * diffint.g * xvol->
diffuse;
257 col.b += col2.b * diffint.b * xvol->
diffuse;
color shade_transmission(ray *incident, const shadedata *shadevars, flt trans)
flt opacity
surface transmission factor
int samples
number of samples to take through volume
RT_OBJECT_HEAD vector min
minimum vertex coordinate
flt(* evaluator)(flt, flt, flt)
user-defined sample fctn ptr
void box_intersect(const box *bx, ray *ry)
flt ambient
ambient lighting coefficient
color ext_volume_texture(const vector *hit, const texture *tx, ray *ry)
extvol * newextvol(void *voidtex, vector min, vector max, int samples, flt(*evaluator)(flt, flt, flt))
RT_OBJECT_HEAD vector min
minimum box vertex coordinate
vector max
maximum vertex coordinate
Tachyon cross-platform thread creation and management, atomic operations, and CPU feature query APIs...
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.
vector max
maximum box vertex coordinate
flt diffuse
diffuse lighting coefficient
static object_methods extvol_methods
color ExtVoxelColor(flt scalar)
Tachyon public API function prototypes and declarations used to drive the ray tracing engine...
int extvol_bbox(void *obj, vector *min, vector *max)
void box_normal(const box *bx, const vector *pnt, const ray *incident, vector *N)
axis-aligned box definition