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

SCM Repository

[diderot] View of /branches/ein16/ertest/visprog/vr-can.diderot
ViewVC logotype

View of /branches/ein16/ertest/visprog/vr-can.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4537 - (download) (annotate)
Thu Sep 8 15:39:49 2016 UTC (3 years ago) by cchiw
File size: 2716 byte(s)
:central location of vis programs
// set camera, image, and rendering parameters
input vec3 camEye = [-1.5015, -3.6392, 5.27097];
input vec3 camAt = [0, 0, 0]; // [-0.0455194, 0.0129536, -0.0035959];
input vec3 camUp = [0.00940017, 0.298005, 0.954518];
input real camNearAtRel = -1.9;
input real camFarAtRel = 1.9;
input real camFOV = 20;
input int iresU = 600;
input int iresV = 600;
input real refStep = 0.1;
input real rayStep = 0.06;
input vec3 lightVsp = [-2, -3, -4];
input real phongKa = 0.3;
input real phongKd = 0.7;
input real thickness = 0.1;

input real isoval = 1800;

field#4(3)[] V = bspln5 ⊛ image("../data/canny.nrrd");
field#3(3)[3] D = ∇V/|∇V|; // NOTISO (canny) NOTREF
field#3(3)[] M = ∇V•∇V;    // NOTISO (canny) NOTREF
field#2(3)[] F = -∇M • D;  // NOTISO (canny) NOTREF

input real gmin = 1;       // NOTISO (canny & ref)

function real alpha(real v, real g) = clamp(0, 1, 1.2*(1 - |v|/(g*thickness)));
field#0(1)[3] cmap = tent ⊛ image("../data/isobow.nrrd");
function vec3 color(vec3 x) = cmap(clamp(-3,1,V(x)));

// (boilerplate) computation of camera and light info
real camDist = |camAt - camEye|;
real camNear = camNearAtRel + camDist;
real camFar = camFarAtRel + camDist;
vec3 camN = normalize(camAt - camEye);  // away
vec3 camU = normalize(camN × camUp);    // right
vec3 camV = camU × camN;                // up
real camVmax = tan(camFOV*π/360)*camDist;
real camUmax = camVmax*iresU/iresV;
vec3 light = transpose([camU,camV,camN])•normalize(lightVsp);

strand raycast(int ui, int vi) {
  real rayU = lerp(-camUmax, camUmax, -0.5, ui, iresU-0.5);
  real rayV = lerp(camVmax, -camVmax, -0.5, vi, iresV-0.5);
  real rayN = camNear;
  vec3 rayVec = camN + (rayU*camU + rayV*camV)/camDist;
  real transp = 1;
  vec3 rgb = [0,0,0];
  output vec4 rgba = [0,0,0,0];

  update {
    vec3 x = camEye + rayN*rayVec;
    if (inside(x,V) && |∇V(x)| > gmin) { // NOTISO (canny & ref)
      real val = F(x);                   // (iso & canny) NOTREF
      vec3 grad = -∇F(x);                // (iso & canny) NOTREF
      real a = alpha(val, |grad|);
      if (a > 0) {  // we have some opacity
        a = 1 - pow(1-a, rayStep*|rayVec|/refStep);
        real depth = lerp(1.3, 0.6, camNear, rayN, camFar);
        real shade = max(0, normalize(grad)•light);
        rgb += transp*depth*a*(phongKa + phongKd*shade)*color(x);
        transp *= 1 - a;
      }
    }
    if (transp < 0.01) {  // early ray termination
      transp = 0;
      stabilize;
    }
    if (rayN > camFar) {
      stabilize;
    }
    rayN = rayN + rayStep;
  }
  stabilize {
    real a = 1-transp;
    if (a > 0) rgba = [rgb[0]/a, rgb[1]/a, rgb[2]/a, a];
  }
}
initially [ raycast(ui, vi) | vi in 0..iresV-1, ui in 0..iresU-1 ];

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