1 : |
glk |
46 |
// vr.diderot
|
2 : |
|
|
//
|
3 : |
|
|
// volume rendering example in Diderot
|
4 : |
|
|
//
|
5 : |
|
|
|
6 : |
|
|
input string dataFile; // name of dataset
|
7 : |
|
|
input real stepSz; // size of steps
|
8 : |
|
|
input vec<3> lightDir;
|
9 : |
|
|
input vec<3> lightCol;
|
10 : |
|
|
input vec<3> eye; // location of eye point
|
11 : |
|
|
input vec<3> orig; // location of pixel (0,0)
|
12 : |
|
|
input vec<3> cVec; // vector between pixels horizontally
|
13 : |
|
|
input vec<3> rVec; // vector between pixels vertically
|
14 : |
|
|
input real pka;
|
15 : |
|
|
input real pkd;
|
16 : |
|
|
input real pks;
|
17 : |
|
|
input real psh;
|
18 : |
|
|
|
19 : |
|
|
image[3] img = load (dataFile);
|
20 : |
|
|
|
21 : |
|
|
field#1[3] F = convolve (bspln3, img);
|
22 : |
glk |
49 |
|
23 : |
|
|
field#0<4>[1] txf = convolve (tent, load("txf-rgba.nrrd"));
|
24 : |
glk |
46 |
|
25 : |
|
|
actor RayCast (int row, int col)
|
26 : |
|
|
{
|
27 : |
|
|
vec<3> pos = orig + row*rVec + col*cVec;
|
28 : |
|
|
vec<3> dir = pos - eye/|pos - eye|;
|
29 : |
|
|
real t = 0.0;
|
30 : |
|
|
vec<3> rayRGB = (0.0, 0.0, 0.0);
|
31 : |
|
|
real rayTransp = 1.0;
|
32 : |
|
|
|
33 : |
|
|
update
|
34 : |
|
|
{
|
35 : |
|
|
if (inside (pos,F)) {
|
36 : |
|
|
real val = F@pos;
|
37 : |
|
|
vec<3> grad = (D F)@pos;
|
38 : |
|
|
vec<3> norm = grad/|grad|;
|
39 : |
|
|
vec<3> half = lightDir - dir/|lightDir - dir|;
|
40 : |
glk |
49 |
vec<4> matRGBA = txf@val;
|
41 : |
glk |
46 |
vec<3> matRGB = (matRGBA[0],matRGBA[1],matRGBA[2]);
|
42 : |
|
|
real ldotn = dot(lightDir,norm);
|
43 : |
|
|
real hdotn = dot(halfDir,norm);
|
44 : |
|
|
// hey the per-component multiplication is in matRGB*lightRGB
|
45 : |
|
|
vec<3> pntRGB = (ka + kd*ldotn)*matRGB*lightRGB + ks*pow(hdotn,psh)*lightRGB;
|
46 : |
|
|
rayRGB = rayRGB + rayTranps*matRGBA[3]*matRGB;
|
47 : |
|
|
rayTransp = rayTranps*(1.0 - matRGBA[3]);
|
48 : |
|
|
}
|
49 : |
|
|
if (t > 1.0 || rayTransp < 0.01) // a little odd; ray terminates at length=1
|
50 : |
|
|
stabilize;
|
51 : |
|
|
pos = pos + stepSz*dir;
|
52 : |
|
|
t = t + stepSz;
|
53 : |
|
|
}
|
54 : |
|
|
|
55 : |
|
|
|
56 : |
|
|
}
|