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

SCM Repository

[diderot] View of /tests/vis12-bugs/src/bug046.diderot
ViewVC logotype

View of /tests/vis12-bugs/src/bug046.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4640 - (download) (annotate)
Tue Sep 27 20:54:47 2016 UTC (2 years, 10 months ago) by glk
File size: 3638 byte(s)
initial result of svn export --username anonsvn --password=anonsvn https://svn.smlnj-gforge.cs.uchicago.edu/svn/diderot/branches/vis15/src/tests/
/* This is not a bug; better error messages require improvements in the
 * error correction technology (or a hand-written parser). [JHR]
 */

/*
** can't assign to single elements of vectors
** compiling with: ../../bin/diderotc --exec bug046.diderot
** produces:

[bug046.diderot:77.21] Error: syntax error; try substituting ":" for "+="
[bug046.diderot:77.15] Error: syntax error; try inserting "%="
[bug046.diderot:69.18] Error: syntax error; try substituting ":" for "+="
[bug046.diderot:69.14] Error: syntax error; try inserting "%="

** These are good examples of confusing and unhelpful syntax error
** messages; the suggested "try" changes don't actually make any
** sense, regardless of how justified is the algorithm for generating
** the suggestion.
*/

// set camera, image, and rendering parameters
input vec3 camEye = [0.09, 0, 10];
input vec3 camAt = [0.09, 0, 0];
input vec3 camUp = [-1, 0, 0];
input real camNearAtRel = -0;
input real camFarAtRel =  0.45;
input real camFOV = 4.85;
input int iresU = 450;
input int iresV = 200;
input real refStep = 0.005;
input real rayStep = 0.005;
input vec3 lightVsp = [-2, -3, -4];
input real phongKa = 0.3;
input real phongKd = 0.7;
input real thickness = 0.03;

input real isoval = -0.1;

field#2(3)[] F = bspln3 ⊛ image("../data/wee-torus.nrrd");

function real alpha(real v, real g) = max(0, 1 - |v/g|/thickness);

// (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,F)) {
      vec3 grad = ∇F(x);
      vec3 norm = -normalize(grad);
      tensor[3,3] hess = ∇⊗∇F(x);
      real a = 0;
      real val = F(x) - isoval;
      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, norm•light);
        if (grad•camUp > 0) {
          /* BUG: can't write this: */
          rgb[0] += 0.02;
          /* or this: */
          //rgb[0] = rgb[0] + 0.02;
          /* instead have to: */
          //rgb = [rgb[0] - 0.02, rgb[1], rgb[2]];
        }
        if (grad•camU > 0) {
          /* BUG: can't write this: */
          hess[0,0] += 0.02;
          /* or this: */
          //hess[0,0] = hess[0,0] + 0.02;
          /* instead have to: */
          //hess = [[hess[0,0]+80,hess[0,1],hess[0,2]],[hess[1,0],hess[1,1],hess[1,2]],[hess[2,0],hess[2,1],hess[2,2]]];
        }
        rgb += transp*depth*a*(phongKa + phongKd*shade)*[1,1,0.6-0.04*(norm•hess•norm)];
        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