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

SCM Repository

[diderot] View of /branches/charisee_dev/examples/mode/mode-vr-byhand.diderot
ViewVC logotype

View of /branches/charisee_dev/examples/mode/mode-vr-byhand.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3307 - (download) (annotate)
Fri Oct 16 19:41:04 2015 UTC (3 years, 9 months ago) by cchiw
File size: 3787 byte(s)
lifts det
input real isoval = 0.9;
input real thick = 0.8;

field#2(3)[3,3] V = c4hexic ⊛ image("slab-c4h-ten9-small.nrrd");
field#0(1)[3] cmap = tent ⊛ image("diverg-cmap.nrrd");

function vec3 color(vec3 x,real k) =cmap(clamp(-1,1,3*sqrt(6)*k/2));

input real refStep = 1;
input vec3 camEye = [-139.415, 396.62, 451.98];
input vec3 camAt = [128.432, 126.52, 219.103];
input vec3 camUp = [-0.0213419, -0.0581629, 0.998079];
input real camNearAtRel = -107.06;
input real camFarAtRel = 125.56;
input real camFOV = 17.16;
input int iresU = 650;
input int iresV = 330;
input real phongKa = 0.3;
input real phongKd = 0.7;
input real rayStep = 0.4;
input vec3 lightVsp = [-2.0, -3.5, -4.0];
real camDist = |camAt - camEye|;
real camNear = camNearAtRel + camDist;
real camFar = camFarAtRel + camDist;
vec3 camN = normalize(camAt - camEye);  // away from eye
vec3 camU = normalize(camN × camUp);    // right
vec3 camV = camN × camU;                // down
real camVmax = tan(camFOV*π/360)*camDist;
real camUmax = camVmax*iresU/iresV;
vec3 light = transpose([camU,camV,camN])•normalize(lightVsp);

function real alpha(real v, real g) = max(clamp(0, 1, 1.3*(1 - |v+isoval|/(g*thick))),
                                          clamp(0, 1, 1.3*(1 - |v-isoval|/(g*thick))));

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 = (camDist*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)) {
      real val = 0;
      vec3 grad = [0,0,0];

     tensor [3,3] e1=V (x)- trace(V(x))*identity[3]/3;
     real e2=sqrt(e1:e1);
     vec3 XXXX=(∇(trace(V)))(x);//<<< need to remove trace
     tensor [3,3,3] dele1=∇⊗V(x)- (XXXX⊗identity[3]/3);

     //∇|E|;
    tensor [3,3,3] t4=∇⊗V(x)- (XXXX⊗identity[3]/3);
    vec3 t3 =2*(t4:(e1));//product rule
    vec3 dele2=(1/2)*t3/sqrt(e1:e1);

    tensor[3,3] probeQ= e1/sqrt(e1:e1); //E/|E|;
    tensor[3,3,3] probedelQ=(e1⊗dele2-e2*dele1)/(e2*e2);

      real qa=probeQ[0,0];
      real qb=probeQ[0,1];
      real qc=probeQ[0,2];
      real qd=probeQ[1,0];
      real qe=probeQ[1,1];
      real qf=probeQ[1,2];
      real qg=probeQ[2,0];
      real qh=probeQ[2,1];
      real qi=probeQ[2,2];
      vec3 dqa=probedelQ[0,0,:];
      vec3 dqb=probedelQ[0,1,:];
      vec3 dqc=probedelQ[0,2,:];
      vec3 dqd=probedelQ[1,0,:];
      vec3 dqe=probedelQ[1,1,:];
      vec3 dqf=probedelQ[1,2,:];
      vec3 dqg=probedelQ[2,0,:];
      vec3 dqh=probedelQ[2,1,:];
      vec3 dqi=probedelQ[2,2,:];
    real t0=(qe*qi)-(qf*qh);
    real t1=(qd*qi) -(qf*qg);
    real t2=(qd*qh) -(qe*qg);
    real K=qa*t0 -qb*t1+qc*t2;//determinant of Q

val = 3*sqrt(6)*K/2; //F(x);

vec3 r0=(t0*dqa)+qa*((qe*dqi+dqe*qi)-(qf*dqh+dqf*qh));
vec3 r1=(t1*dqb)+qb*((qd*dqi+dqd*qi)-(qf*dqg+dqf*qg));
vec3 r2=(t2*dqc)+qc*((qd*dqh+dqh*qd)-(qe*dqg+dqe*qg));
vec3 del_K=r0-r1+r2; //derivative of determinant of Q

      grad =-(3*sqrt(6)*del_K);
      real a = alpha(val, |grad|);
      if (a > 0) {
        a = 1 - pow(1-a, rayStep*|rayVec|/refStep);
        real depth = lerp(1.1, 0.8, camNear, rayN, camFar);
        real shade = |normalize(grad)•light|;
        rgb += transp*a*depth*(phongKa + phongKd*shade)*color(x,K);
        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