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

SCM Repository

[diderot] View of /branches/pure-cfg/test/vr-kcomp.diderot
ViewVC logotype

View of /branches/pure-cfg/test/vr-kcomp.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 746 - (download) (annotate)
Wed Apr 6 18:19:21 2011 UTC (8 years, 7 months ago) by glk
File size: 3117 byte(s)
bug
vec3 camEye = [25.0, 10.0, 8.0];
vec3 camAt = [0.0, 0.0, 0.0];
vec3 camUp = [0.0, 0.0, 1.0];
real camNear = -1.0;
real camFar = 1.0;
real camFOV = 4.0;
int imgResU = 200;
int imgResV = 200;
real rayStep = 0.01;
real valOpacMin = 0.15;          // highest value with opacity 0.0
real valOpacMax = 0.16;          // lowest value with opacity 1.0 

 // HEY: update this camera code when possible, based on eventual
// improvements to mip-cam.diderot
real camDist = |camAt - camEye|;
real camVspNear = camDist + camNear;
real camVspFar = camDist + camFar;
vec3 camN = (camAt - camEye)/camDist;
vec3 tmp0 = cross(camN,camUp); 
vec3 camU = tmp0/|tmp0|;
vec3 camV = cross(camN,camU);
real camVmax = tan(camFOV*3.1415926536/360.0)*camDist;
real camUmax = camVmax*real(imgResU)/real(imgResV);

vec3 lightVspDir = [0.9, -1.0, -2.5];
vec3 tmp2 = lightVspDir[0]*camU + lightVspDir[1]*camV + lightVspDir[2]*camN;
vec3 lightDir = tmp2/|tmp2|;

real phongKa = 0.05;
real phongKd = 0.80;
real phongKs = 0.20;
real phongSp = 30.0;

image(3)[] img = load ("../data/vox1-9.nrrd");
field#1(3)[] Fc1 = img ⊛ ctmr;
field#1(3)[] Fc0 = img ⊛ c1tent;

strand RayCast (int ui, int vi)
{
    real rayU = 2.0*camUmax*(real(ui) + 0.5)/real(imgResU) - camUmax;
    real rayV = 2.0*camVmax*(real(vi) + 0.5)/real(imgResV) - camVmax;
    vec3 rayVec = (camDist*camN + rayU*camU + rayV*camV)/camDist;
    vec3 rayDir = rayVec/|rayVec|;

    real rayN = camVspNear;
    // ########## BEGIN per-ray initialization
    real transp = 1.0;
    real gray = 0.0;
    output vec4 rgba = [0.0, 0.0, 0.0, 0.0];
    // ##########  END  per-ray initialization

    update
    {
       vec3 rayPos = camEye + rayN*rayVec;
       if (inside (rayPos,Fc1)) {
          // ########## BEGIN per-sample code
          real val = 0.0;
          vec3 grad = [0.0,0.0,0.0];
          // HEY (BUG): looks like the strand parameters (e.g. ui, vi) can't
          // appear in conditionals
          if (ui < 100) {
             val = Fc0@rayPos;
             grad = ∇Fc0@rayPos;
          } else {
             val = Fc1@rayPos;
             grad = ∇Fc1@rayPos;
          }
          vec3 norm = -grad/|grad|;
          if (val > valOpacMin) {  // we have some opacity 
              real opac =
                 1.0 if (val > valOpacMax)
                 else (val - valOpacMin)/(valOpacMax - valOpacMin);
              real ld = dot(lightDir,norm);
              real mat = (  phongKa
                          + phongKd*(ld if ld > 0.0 else 0.0)
                          + phongKs*(pow(ld, phongSp) if ld > 0.0 else 0.0));
              gray = gray + transp*opac*mat;
              transp = transp*(1.0 - opac);
          }
          // ##########  END  per-sample code
       }
       if (transp < 0.01) {  // early ray termination
          rgba = [gray, gray, gray, 1.0];
          stabilize;
       }
       if (rayN > camVspFar) {
          rgba = [gray, gray, gray, 1.0-transp];
          stabilize;
       }
       rayN = rayN + rayStep;
    }

    /* render: output maxval */
}

initially [ RayCast(ui, vi) | vi in 0..(imgResV-1), ui in 0..(imgResU-1) ];

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