Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /trunk/test/vr-phong.diderot
ViewVC logotype

View of /trunk/test/vr-phong.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 58 - (download) (annotate)
Mon May 3 03:46:16 2010 UTC (9 years, 4 months ago) by glk
File size: 2329 byte(s)
added annotations about types of operations
// vr.diderot
//
// volume rendering example in Diderot
//

input string dataFile;		// name of dataset
input real stepSz;		// size of steps
input vec3 lightDir;
input vec3 lightCol;
input vec3 eye;               // location of eye point 
input vec3 orig;              // location of pixel (0,0)
input vec3 cVec;              // vector between pixels horizontally
input vec3 rVec;              // vector between pixels vertically
input real pka;
input real pkd;
input real pks;
input real psh;

image(3)[] img = load (dataFile);

field#1(3)[] F = convolve (bspln3, img);

field#0(1)[4] txf = convolve (tent, load("txf-rgba.nrrd"));
 
actor RayCast (int row, int col)
{
    //// * : int x vec3 -> vec3
    //// + : vec3 x vec3 -> vec3
    vec3	pos = orig + row*rVec + col*cVec;
    //// |()| : vec -> real
    //// - : vec3 x vec3 -> vec3
    //// / : vec3 x real -> vec3
    vec3	dir = (pos - eye)/|pos - eye|;
    real	t = 0.0;
    vec3	rayRGB = (0.0, 0.0, 0.0);
    real        rayTransp = 1.0;

    update
    {
        if (inside (pos,F)) {
           //// @ : field x vec3 -> real
           real val = F@pos;
           //// D : field -> field
           vec3 grad = (D F)@pos;
           vec3 norm = grad/|grad|;
           vec3 half = (lightDir - dir)/|lightDir - dir|;
           vec4 matRGBA = txf@val;
           vec3 matRGB = (matRGBA[0],matRGBA[1],matRGBA[2]);
           //// dot : vec3 x vec3 -> real
           real ldotn = dot(lightDir,norm);
           real hdotn = dot(halfDir,norm);
           // hey the per-component multiplication is in matRGB*lightRGB
           //// * : real x vec3 -> vec3
           //// * : vec3 x vec3 -> vec3      this notation may be reconsidered
           //// + : vec3 x vec3 -> vec3
           //// pow : real x real -> real
           vec3 pntRGB = (ka + kd*ldotn)*matRGB*lightRGB + ks*pow(hdotn,psh)*lightRGB;
           rayRGB = rayRGB + rayTranps*matRGBA[3]*pntRGB;
           //// * : real x real -> real
           //// - : real x real -> real
           rayTransp = rayTranps*(1.0 - matRGBA[3]);
        }
        //// > : real x real -> bool
        //// < : real x real -> bool
        //// || : bool x bool -> bool
	if (t > 1.0 || rayTransp < 0.01) // a little odd; ray terminates at length=1
	    stabilize;
	pos = pos + stepSz*dir;
        t = t + stepSz;
    }


}

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0