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

SCM Repository

[diderot] View of /branches/vis12/test/vr-kcomp-torus.diderot
ViewVC logotype

View of /branches/vis12/test/vr-kcomp-torus.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3242 - (download) (annotate)
Thu Aug 20 05:46:22 2015 UTC (4 years, 2 months ago) by glk
File size: 2922 byte(s)
shaded rendering of torus with two different kernels
// process output with:
// unu reshape -i mip.txt -s 4 200 200 | overrgb -i - -b 0.1 0.15 0.2 -o - | unu quantize -b 8 -min 0 -max 255  -o vr-kcomp.png

vec3 camEye = [4, 6, 5];
vec3 camAt = [0, 0, -0.12];
vec3 camUp = [0, 0, 1];
real camNear = -1.9;
real camFar = 1.9;
real camFOV = 16;
int imgResU = 640;
int imgResV = 480;
real rayStep = 0.002;
real isoVal = 0.77;
real isoThick = 0.01;

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);

// convert a view-space light direction to world-space
vec3 lightDir = transpose([camU,camV,camN])•normalize([0, -1, -2]);

real phongKa = 0.10;
real phongKd = 0.50;
real phongKs = 0.40;
real phongSp = 120.0;

image(3)[] img = image("../data/torus-scl.nrrd");
field#1(3)[] Fc1 = img ⊛ ctmr - isoVal;
//field#1(3)[] Fc1 = img ⊛ c4hexic - isoVal;
field#1(3)[] Fc0 = img ⊛ c1tent - isoVal;

function real txf(real v, real g) = 1.0 if v > 0 else clamp(0, 1, 1 - |v|/(g*isoThick));

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 transp = 1;
    vec3 rgb = [0, 0, 0];
    output vec4 rgba = [0, 0, 0, 0];

    update {
       vec3 rayPos = camEye + rayN*rayVec;
       if (inside (rayPos,Fc1)) {
          real val = 0;
          vec3 norm = [0, 0, 0];
          if (ui > imgResU/2) {
             val = Fc0(rayPos);
             norm = normalize(-∇Fc0(rayPos));
          } else {
             val = Fc1(rayPos);
             norm = normalize(-∇Fc1(rayPos));
          }
          real opac = txf(val, |norm|);
          if (opac > 0) {  // we have some opacity
              real ld = norm • lightDir;
              real hd = norm • normalize(lightDir + vv);
              real lit = (  phongKa
                          + phongKd*(ld if ld > 0.0 else 0.0)
                          + phongKs*(hd^phongSp if hd > 0.0 else 0.0));
              vec3 mat = [1, 1, 1];
              rgb += transp*opac*lit*mat;
              transp *= 1 - opac;
          }
       }
       if (transp < 0.01) {  // early ray termination
          transp = 0.0;
          stabilize;
       }
       if (rayN > camVspFar) {
          stabilize;
       }
       rayN = rayN + rayStep;
    }

    stabilize {
       if (transp < 1) {
         real aa = 1 - transp;
         rgba = [rgb[0]/aa, rgb[1]/aa, rgb[2]/aa, aa];
       } else {
         rgba = [0, 0, 0, 0];
       }
    }
}

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