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

SCM Repository

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

View of /trunk/test/vr-curv-quad.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1124 - (download) (annotate)
Thu May 5 10:59:35 2011 UTC (8 years, 3 months ago) by glk
File size: 3744 byte(s)
some tweaks
// vr-curv
//
// Demonstration of curvature-based transfer functions in volume rendering
//
// process output with:
// unu reshape -i mip.txt -s 4 480 345 | overrgb -i - -b 0.1 0.15 0.2 -g 1.2 -o - | unu quantize -b 8 -min 0 -max 255  -o vr-curv-quad.png

field#2(3)[] F = bspln3 ⊛ load("../data/quad-patches-pad.nrrd");
field#0(2)[3] RGB = tent ⊛ load("../data/txf/2d-bow.nrrd");

// set camera, image, and rendering parameters
vec3 camEye = [183.021, -411.857, 686.458];
vec3 camAt = [55.4037, 40.2407, 4.32732];
vec3 camUp = [0.0, 0.0, 1.0];
real camNear = -42.0;
real camFar = 42.0;
real camFOV = 7.15;
int imgResU = 480;
int imgResV = 345;
real rayStep = 0.2;
real valOpacMin = -0.25;
real valOpacMax = -0.10;
vec3 lightVspDir = [0.9, -2.5, -2.5];
vec3 lightRGB = [1.0, 1.0, 1.0];
real phongKa = 0.1;
real phongKd = 0.7;
real phongKs = 0.3;
real phongSp = 45.0;

// (boilerplate) computation of camera and light info
real camDist = |camAt - camEye|;
real camVspNear = camNear + camDist;
real camVspFar = camFar + camDist;
vec3 camN = normalize(camAt - camEye);
vec3 camU = normalize(camN × camUp);
vec3 camV = camN × camU;
real camVmax = tan(camFOV*π/360.0)*camDist;
real camUmax = camVmax*real(imgResU)/real(imgResV);
vec3 lightDir = normalize(lightVspDir[0]*camU + 
                          lightVspDir[1]*camV + 
                          lightVspDir[2]*camN);

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

    real rayN = camVspNear;
    real rayTransp = 1.0;
    vec3 rayRGB = [0.0, 0.0, 0.0];
    output vec4 outRGBA = [0.0, 0.0, 0.0, 0.0];

    update {
       vec3 pos = camEye + rayN*rayVec;
       if (inside (pos,F)) {
          real val = F(pos);
          if (val > valOpacMin) {  // we have some opacity 
              vec3 grad = -∇F(pos);
              vec3 norm = normalize(grad);
              // begin curvature computation
              tensor[3,3] H = ∇(∇F)(pos);
              tensor[3,3] P = identity[3] - norm⊗norm;
              tensor[3,3] G = -(P•H•P)/|grad|;
              real disc = max(0.0, sqrt(2.0*|G|^2 - trace(G)^2));
              real k1 = (trace(G) + disc)/2.0;
              real k2 = (trace(G) - disc)/2.0;
              // finished curvature computation; begin finding sample RGBA 
              k1 = max(-1.0, min(1.0, 6.0*k1));
              k2 = max(-1.0, min(1.0, 6.0*k2));
              vec3 matRGB = RGB([k1,k2]);
              real alpha = min(1.0, lerp(0.0, 1.0, 
                                         valOpacMin, val, valOpacMax));
              real ld = max(0.0, norm • lightDir);
              real hd = max(0.0, norm • normalize(lightDir + vv));
              // Phong shading
              vec3 pntRGB = (phongKa*matRGB 
                             + phongKd*ld*modulate(matRGB, lightRGB)
                             + phongKs*hd^phongSp*lightRGB);
              // composite with existing ray color and transparency 
              rayRGB = rayRGB + rayTransp*alpha*pntRGB;
              rayTransp = rayTransp*(1.0 - alpha);
          }
       }
       if (rayTransp < 0.01) {  // early ray termination
          rayTransp = 0.0;
          outRGBA = [rayRGB[0], rayRGB[1], rayRGB[2], 1.0 - rayTransp];
          stabilize;
       }
       if (rayN > camVspFar) {
          outRGBA = [rayRGB[0], rayRGB[1], rayRGB[2], 1.0 - rayTransp];
          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