SCM Repository
[diderot] / branches / charisee_dev / examples / canny / vr-ref.diderot |
View of /branches/charisee_dev/examples/canny/vr-ref.diderot
Parent Directory
|
Revision Log
Revision 3313 -
(download)
(annotate)
Sat Oct 17 00:33:40 2015 UTC (5 years, 3 months ago) by cchiw
File size: 2789 byte(s)
Sat Oct 17 00:33:40 2015 UTC (5 years, 3 months ago) by cchiw
File size: 2789 byte(s)
sync files
// 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("canny.nrrd"); 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("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) vec3 g = ∇V(x); // NOTISO NOTCANNY (ref) tensor[3,3] H = ∇⊗∇V(x); // NOTISO NOTCANNY (ref) tensor[3,3,3] J = ∇⊗∇⊗∇V(x); // NOTISO NOTCANNY (ref) real val = g•H•g/|g|; // NOTISO NOTCANNY (ref) vec3 grad = (2*H•H•g + g•J•g - (g•H•g)*(H•g)/(g•g))/|g|; // NOTISO NOTCANNY (ref) 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 |