SCM Repository
Annotation of /examples/vr-demo/vr-lite-cam.diderot
Parent Directory
|
Revision Log
Revision 2058 - (view) (download)
1 : | jhr | 2058 | // vr-lite-cam |
2 : | // | ||
3 : | // simple volume renderer, now with a single directional light, | ||
4 : | // Phong shading, and the new camera. | ||
5 : | // | ||
6 : | |||
7 : | // image parameters | ||
8 : | input int imgResU = 480; | ||
9 : | input int imgResV = 345; | ||
10 : | input real rayStep = 0.1; | ||
11 : | |||
12 : | // camera controls | ||
13 : | input vec3 camEye = [127.331, -1322.05, 272.53]; | ||
14 : | input vec3 camAt = [63.0, 82.6536, 98.0]; | ||
15 : | input vec3 camUp = [0.9987, 0.0459166, -0.0221267]; | ||
16 : | input real camNear = -78.0; | ||
17 : | input real camFar = 78.0; | ||
18 : | input real camFOV = 5.0; | ||
19 : | |||
20 : | /* we control the opacity by its center value and the +/- keys */ | ||
21 : | input real valOpacMid = 550.0; // 550 for skin, 1300.0 for bone | ||
22 : | real valOpacMin = valOpacMid - 150.0; | ||
23 : | real valOpacMax = valOpacMid + 150.0; | ||
24 : | |||
25 : | real camDist = |camAt - camEye|; | ||
26 : | real camVspNear = camDist + camNear; | ||
27 : | real camVspFar = camDist + camFar; | ||
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 : | vec3 lightVspDir = [0.9, -1.0, -2.5]; | ||
35 : | vec3 lightDir = normalize(lightVspDir[0]*camU + lightVspDir[1]*camV + lightVspDir[2]*camN); | ||
36 : | //vec3 lightRGB = [1.0, 1.0, 1.0]; | ||
37 : | |||
38 : | real phongKa = 0.05; | ||
39 : | real phongKd = 0.65; | ||
40 : | real phongKs = 0.45; | ||
41 : | real phongSp = 50.0; | ||
42 : | |||
43 : | field#2(3)[] F = bspln3 ⊛ image("data/vfrhand-nohip.nhdr"); | ||
44 : | |||
45 : | strand RayCast (int ui, int vi) | ||
46 : | { | ||
47 : | real rayU = lerp(-camUmax, camUmax, -0.5, real(ui), real(imgResU)-0.5); | ||
48 : | real rayV = lerp(-camVmax, camVmax, -0.5, real(vi), real(imgResV)-0.5); | ||
49 : | vec3 rayVec = (camDist*camN + rayU*camU + rayV*camV)/camDist; | ||
50 : | vec3 toEye = normalize(-rayVec); | ||
51 : | |||
52 : | real rayN = camVspNear; | ||
53 : | // ########## BEGIN per-ray initialization | ||
54 : | real rayTransp = 1.0; | ||
55 : | // vec3 rayRGB = [0.0, 0.0, 0.0]; | ||
56 : | real rayGrey = 0.0; | ||
57 : | output vec4 outRGBA = [0.0, 0.0, 0.0, 0.0]; | ||
58 : | // ########## END per-ray initialization | ||
59 : | |||
60 : | update | ||
61 : | { | ||
62 : | vec3 rayPos = camEye + rayN*rayVec; | ||
63 : | if (inside (rayPos,F)) { | ||
64 : | // ########## BEGIN per-sample code | ||
65 : | real val = F(rayPos); | ||
66 : | if (val > valOpacMin) { // we have some opacity | ||
67 : | vec3 grad = ∇F(rayPos); | ||
68 : | vec3 norm = normalize(-∇F(rayPos)); | ||
69 : | real alpha = min(1.0, lerp(0.0, 1.0, valOpacMin, val, valOpacMax)); | ||
70 : | real ld = max(0.0, norm • lightDir); | ||
71 : | real hd = max(0.0, norm • normalize(lightDir + toEye)); | ||
72 : | real pnt = phongKa | ||
73 : | + phongKd * ld | ||
74 : | + phongKs * hd^phongSp; | ||
75 : | rayGrey += rayTransp*alpha*pnt; | ||
76 : | rayTransp = rayTransp*(1.0 - alpha); | ||
77 : | } | ||
78 : | // ########## END per-sample code | ||
79 : | } | ||
80 : | if (rayTransp < 0.01) { // early ray termination | ||
81 : | rayTransp = 0.0; | ||
82 : | stabilize; | ||
83 : | } | ||
84 : | if (rayN > camVspFar) { | ||
85 : | stabilize; | ||
86 : | } | ||
87 : | rayN += rayStep; | ||
88 : | } | ||
89 : | |||
90 : | stabilize { | ||
91 : | outRGBA = [rayGrey, rayGrey, rayGrey, 1.0-rayTransp]; | ||
92 : | } | ||
93 : | |||
94 : | } | ||
95 : | |||
96 : | 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 |