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 46 - (download) (annotate)
Tue Apr 6 17:02:18 2010 UTC (9 years, 6 months ago) by glk
File size: 1626 byte(s)
added a plausible phong-lighting volume renderer
// vr.diderot
//
// volume rendering example in Diderot
//

input string dataFile;		// name of dataset
input real stepSz;		// size of steps
input vec<3> lightDir;
input vec<3> lightCol;
input vec<3> eye;               // location of eye point 
input vec<3> orig;              // location of pixel (0,0)
input vec<3> cVec;              // vector between pixels horizontally
input vec<3> 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);
 
actor RayCast (int row, int col)
{
    vec<3>	pos = orig + row*rVec + col*cVec;
    vec<3>	dir = pos - eye/|pos - eye|;
    real	t = 0.0;
    vec<3>      rayRGB = (0.0, 0.0, 0.0);
    real        rayTransp = 1.0;

    update
    {
        if (inside (pos,F)) {
           real val = F@pos;
           vec<3> grad = (D F)@pos;
           vec<3> norm = grad/|grad|;
           vec<3> half = lightDir - dir/|lightDir - dir|;
           vec<4> matRGBA = txf(val);
           vec<3> matRGB = (matRGBA[0],matRGBA[1],matRGBA[2]);
           real ldotn = dot(lightDir,norm);
           real hdotn = dot(halfDir,norm);
           // hey the per-component multiplication is in matRGB*lightRGB
           vec<3> pntRGB = (ka + kd*ldotn)*matRGB*lightRGB + ks*pow(hdotn,psh)*lightRGB;
           rayRGB = rayRGB + rayTranps*matRGBA[3]*matRGB;
           rayTransp = rayTranps*(1.0 - matRGBA[3]);
        }
	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