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

SCM Repository

[diderot] View of /branches/vis15/src/tests/glk-tests/new/illust-vr.diderot
ViewVC logotype

View of /branches/vis15/src/tests/glk-tests/new/illust-vr.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4497 - (download) (annotate)
Sat Sep 3 14:12:36 2016 UTC (2 years, 6 months ago) by jhr
File size: 4649 byte(s)
  working on merge: updating tests with new version 2 syntax
#version 2

// illust-vr
//
// Demonstration of "illustrative volume rendering"
//
// process output with:
// unu reshape -i illust-vr.txt -s 4 640 480 | overrgb -i - -b 0.1 0.15 0.2 -g 1.2 -o - | unu quantize -b 8 -min 0 -max 255  -o illust-vr.png

//field#2(3)[] F = bspln3 ⊛ load_image("../data/vfrhand-nohip.nhdr");
field#2(3)[] F = bspln3 ⊛ load_image("../data/vfrhand-nohip-smooth.nrrd");

field#0(1)[] silho = tent ⊛ load_image("../data/txf/silho.nrrd");
field#0(1)[] shade = tent ⊛ load_image("../data/txf/shade.nrrd");
field#0(2)[] rival = tent ⊛ load_image("../data/txf/ridgvall.nrrd");
field#0(2)[] alpha = tent ⊛ load_image("../data/txf/alpha-bone.nrrd"); // image("../data/txf/alpha-skin.nrrd");
field#0(1)[3] depth = tent ⊛ load_image("../data/txf/depth.nrrd");

bool useShade = true; // simple shading
bool useDepth = true; // depth-cue with warm-to-cool colormap
bool useSilho = true; // curvature-based silhouettes
bool useRival = true; // curvature-based ridge & valley emphasis

// set camera, image, and rendering parameters
vec3 camEye = [127.331, -1322.05, 272.53];
vec3 camAt = [63.0, 82.6536, 98.0];
vec3 camUp = [0.9987, 0.0459166, -0.0221267];
real camNear = -78.0;
real camFar = 78.0;
real camFOV = 5.0;
int imgResU = 640;
int imgResV = 480;
real rayStep = 0.15;

vec3 lightVspDir = [-2.0, -3.0, -2.0];
real sthick = 0.4;
real refStep = 1.5;

// (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);
          vec3 grad = -∇F(pos);
          real gmag = |grad|;
          real aa = alpha([max(0.0, min(2000.0, val)), max(0.0, min(900.0, gmag))]);
          if (aa > 0.0) {  // we have some opacity
              vec3 norm = grad/gmag;
              aa = 1.0 - pow(1.0-aa, rayStep/refStep);
              real gray = 1.0;
              if (useShade) {
                 gray = gray * shade(norm • lightDir);
              }
              tensor[3,3] Proj = identity[3];
              tensor[3,3] Gten = identity[3];
              if (useSilho || useRival) {
                 tensor[3,3] Hess = ∇⊗∇F(pos);
                 Proj = identity[3] - norm⊗norm;
                 Gten = -(Proj•Hess•Proj)/gmag;
              }
              if (useSilho) {
                 real kv = max(0.0, min(1.0/sthick, (vv•Gten•vv)/(vv•Proj•vv)));
                 real vdn = vv•norm;
                 vdn = vdn*(1.0 + 2.0*vdn*vdn); // limit silhouette on front-facing surfaces
                 gray = gray*silho(max(0.0, min(2.0,
                                   vdn^2 + (sthick*(kv - 1.0/sthick))^2  )));
              }
              if (useRival) {
                 real disc = max(0.0, sqrt(2.0*|Gten|^2 - trace(Gten)^2));
                 real k1 = (trace(Gten) + disc)/2.0;
                 real k2 = (trace(Gten) - disc)/2.0;
                 gray = gray*rival([min(0.55, |Gten|)/0.55, atan2(k2,k1)]);
              }
              vec3 matRGB = depth(lerp(0.0, 1.0, camVspNear, rayN, camVspFar))
                            if useDepth else [1.0,1.0,1.0];
              rayRGB = rayRGB + rayTransp*aa*gray*matRGB;
              rayTransp = rayTransp*(1.0 - aa);
          }
       }
       if (rayTransp < 0.01) {  // early ray termination
           rayTransp = 0.0;
           rayRGB = 0.9*rayRGB;
           outRGBA = [rayRGB[0], rayRGB[1], rayRGB[2], 1.0-rayTransp]; /* FIXME */
           stabilize;
       }
       if (rayN > camVspFar) {
           rayRGB = 0.9*rayRGB;
           outRGBA = [rayRGB[0], rayRGB[1], rayRGB[2], 1.0-rayTransp]; /* FIXME */
           stabilize;
       }
       rayN = rayN + rayStep;
    }
}

create_array { 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