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

SCM Repository

[diderot] View of /branches/opencl/test/vr-rgb.diderot
ViewVC logotype

View of /branches/opencl/test/vr-rgb.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1673 - (download) (annotate)
Fri Dec 9 19:56:10 2011 UTC (7 years, 6 months ago) by jhr
File size: 1715 byte(s)
  Creating a branch for hacking on the OpenCL target
// vr-rgb.diderot
//
// simple diffuse-only volume rendering with R, G, B
// lights at positive X, Y, Z
//

input string dataFile = "../data/txs-pad3.nrrd";
real stepSz = 0.05;
vec3 eye = [25.0, 15.0, 10.0];
vec3 orig = [8.83877,2.5911,7.65275];
vec3 cVec = [-0.0151831,0.0278357,0.0];
vec3 rVec = [0.0074887,0.00408474,-0.0305383];
real valOpacMin = 0.3;          // highest value with opacity 0.0
real valOpacMax = 0.4;          // lowest value with opacity 1.0 
vec3 Rdir = [1.0,0.0,0.0];
vec3 Gdir = [0.0,1.0,0.0];
vec3 Bdir = [0.0,0.0,1.0];

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

//field#2(3)[] F = img ⊛ bspln3;
//field#1(3)[] F = img ⊛ ctmr;
field#1(3)[] F = img ⊛ c1tent;

strand RayCast (int row, int col)
{
    vec3 pos = orig + real(row)*rVec + real(col)*cVec;
    vec3 dir = normalize(pos - eye);
    real t = 0.0;
    real transp = 1.0;
    real RR = 0.0;
    real GG = 0.0;
    real BB = 0.0;
    output vec4	rgba = [0.0, 0.0, 0.0, 0.0];

    update
    {
        pos = pos + stepSz*dir;
        if (inside (pos,F)) {
            real val = F@pos;
            vec3 norm = -normalize(∇F@pos);
            if (val > valOpacMin) {  // we have some opacity
                real opac = min(1.0, lerp(0.0, 1.0, valOpacMin, val, valOpacMax));
                RR = RR + transp*opac*max(0.0, Rdir • norm);
                GG = GG + transp*opac*max(0.0, Gdir • norm);
                BB = BB + transp*opac*max(0.0, Bdir • norm);
                transp = transp*(1.0 - opac);
            }
	}
        if (t > 20.0 || transp < 0.01) {
            rgba = [RR, GG, BB, 1.0-transp];
            stabilize;
        }
        t = t + stepSz;
    }
}

initially [ RayCast(r, c) | r in 0..199, c in 0..199 ];

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