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

SCM Repository

[diderot] Annotation of /trunk/rtest/tests/sum-grad/sum-grad.diderot
ViewVC logotype

Annotation of /trunk/rtest/tests/sum-grad/sum-grad.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3349 - (view) (download)

1 : jhr 2636 /*! \file sum-grad.diderot
2 :     *
3 :     * \author Gordon Kindlmann
4 :     *
5 :     * does summation of view-space components gradient
6 :     */
7 : glk 1189
8 : jhr 2636 /*
9 : jhr 3349 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
10 :     *
11 :     * COPYRIGHT (c) 2015 The University of Chicago
12 : jhr 2636 * All rights reserved.
13 :     */
14 : glk 1194
15 : glk 1189 vec3 camEye = [6.65584, 13.2759, 8.55225];
16 :     vec3 camAt = [0.0, 0.0, 0.0];
17 :     vec3 camUp = [0.0, 0.0, 1.0];
18 :     real camNear = -1.0;
19 :     real camFar = 1.0;
20 :     real camFOV = 6.0;
21 :     int imgResU = 320;
22 :     int imgResV = 240;
23 : glk 1193 real rayStep = 0.03;
24 : glk 1189
25 :     real camDist = |camAt - camEye|;
26 :     real camVspNear = camNear + camDist;
27 :     real camVspFar = camFar + camDist;
28 :     vec3 camN = normalize(camAt - camEye);
29 :     vec3 camU = normalize(camN × camUp);
30 :     vec3 camV = camN × camU;
31 :     real camVmax = tan(camFOV*π/360.0)*camDist;
32 :     real camUmax = camVmax*real(imgResU)/real(imgResV);
33 :    
34 : jhr 2636 field#1(3)[] F = ctmr ⊛ image("../../data/ring.nrrd");
35 : glk 1189
36 :     strand RayCast (int ui, int vi) {
37 :     real rayU = lerp(-camUmax, camUmax, -0.5, real(ui), real(imgResU)-0.5);
38 :     real rayV = lerp(-camVmax, camVmax, -0.5, real(vi), real(imgResV)-0.5);
39 :     vec3 rayVec = (camDist*camN + rayU*camU + rayV*camV)/camDist;
40 :    
41 :     real rayN = camVspNear;
42 : jhr 2636 output vec3 sum = [0, 0, 0];
43 : glk 1189
44 :     update {
45 :     vec3 rayPos = camEye + rayN*rayVec;
46 :     if (inside (rayPos,F)) {
47 :     vec3 grad = ∇F(rayPos);
48 :     // we're summing the view-space components of the gradient
49 :     sum = sum + [grad•camU, grad•camV, grad•camN];
50 :     }
51 :     if (rayN > camVspFar)
52 :     stabilize;
53 :     rayN = rayN + rayStep;
54 :     }
55 :     }
56 :    
57 :     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