SCM Repository
[diderot] / branches / pure-cfg / test / vr-lite-cam.diderot |
View of /branches/pure-cfg/test/vr-lite-cam.diderot
Parent Directory
|
Revision Log
Revision 696 -
(download)
(annotate)
Fri Mar 25 18:29:12 2011 UTC (9 years, 9 months ago) by glk
File size: 4278 byte(s)
Fri Mar 25 18:29:12 2011 UTC (9 years, 9 months ago) by glk
File size: 4278 byte(s)
did I never commit this?
// vr-lite-cam // // simple volume renderer, now with a single directional light, // Phong shading, and the new camera. // // The main thing missing from this is a more general // transfer function //string dataFile = "../data/txs-pad3.nrrd"; //vec3 camEye = [25.0, 15.0, 10.0]; //vec3 camAt = [3.0, 3.0, 3.0]; //vec3 camUp = [0.0, 0.0, 1.0]; //real camNear = -5.0; //real camFar = 5.0; //real camFOV = 18.0; //int imgResU = 320; //int imgResV = 240; //real rayStep = 0.1; //real valOpacMin = 0.20; // highest value with opacity 0.0 //real valOpacMax = 0.25; // lowest value with opacity 1.0 string dataFile = "../data/vfrhand-nohip.nhdr"; vec3 camEye = [127.331, -1322.05, 272.53]; vec3 camAt = [63.0, 82.6536, 98.0]; vec3 camUp = [0.9987, 0.0459166, -0.0221267]; real camNear = -78.0; real camFar = 78.0; real camFOV = 5.0; //int imgResU = 640; //int imgResV = 480; int imgResU = 480; int imgResV = 345; //int imgResU = 320; //int imgResV = 240; // HEY (BUG?) do we intend to allow inconsistent redefinitions of things? real rayStep = 0.1; real rayStep = 0.5; real valOpacMin = 400.0; // 400.0 for skin, 1150.0 for bone real valOpacMax = 700.0; // 700.0 for skin, 1450.0 for bone // HEY: update this camera code when possible, based on eventual // improvements to mip-cam.diderot real camDist = |camAt - camEye|; real camVspNear = camDist + camNear; real camVspFar = camDist + camFar; vec3 camN = (camAt - camEye)/camDist; vec3 tmp0 = cross(camN,camUp); vec3 camU = tmp0/|tmp0|; vec3 camV = cross(camN,camU); real camVmax = tan(camFOV*3.1415926536/360.0)*camDist; real camUmax = camVmax*real(imgResU)/real(imgResV); vec3 lightVspDir = [0.9, -1.0, -2.5]; // HEY (want) ability to access components of a vector (e.g. "vec[0]") // would make this transform to world-space less awkward; would be // lightVspDir[0]*camU + lightVspDir[1]*camV + lightVspDir[2]*camN // OR, we could create and apply a view-to-world matrix transform vec3 tmp2 = ( dot(lightVspDir,[1.0,0.0,0.0])*camU + dot(lightVspDir,[0.0,1.0,0.0])*camV + dot(lightVspDir,[0.0,0.0,1.0])*camN); vec3 lightDir = tmp2/|tmp2|; real phongKa = 0.05; real phongKd = 0.80; real phongKs = 0.20; real phongSp = 30.0; image(3)[] img = load (dataFile); //field#2(3)[] F = img ⊛ bspln3; field#2(3)[] F = img ⊛ bspln3; // HEY (BUG): ctmr Catmull-Rom is C1 but not C2 continuous //field#2(3)[] F = img ⊛ ctmr; //field#0(3)[] F = img ⊛ tent; strand RayCast (int ui, int vi) { real rayU = 2.0*camUmax*(real(ui) + 0.5)/real(imgResU) - camUmax; real rayV = 2.0*camVmax*(real(vi) + 0.5)/real(imgResV) - camVmax; vec3 rayVec = (camDist*camN + rayU*camU + rayV*camV)/camDist; vec3 rayDir = rayVec/|rayVec|; real rayN = camVspNear; // ########## BEGIN per-ray initialization real transp = 1.0; real gray = 0.0; output vec4 rgba = [0.0, 0.0, 0.0, 0.0]; // ########## END per-ray initialization update { vec3 rayPos = camEye + rayN*rayVec; if (inside (rayPos,F)) { // ########## BEGIN per-sample code real val = F@rayPos; vec3 grad = ∇F@rayPos; vec3 norm = -grad/|grad|; // HEY (BUG) will get an "uncaught exception" if code is instead // vec3 norm = -∇F@rayPos/|∇F@rayPos|; if (val > valOpacMin) { // we have some opacity real opac = 1.0 if (val > valOpacMax) else (val - valOpacMin)/(valOpacMax - valOpacMin); real ld = dot(lightDir,norm); real mat = ( phongKa + phongKd*(ld if ld > 0.0 else 0.0) + phongKs*(pow(ld, phongSp) if ld > 0.0 else 0.0)); gray = gray + transp*opac*mat; transp = transp*(1.0 - opac); } // ########## END per-sample code } if (transp < 0.01) { // early ray termination rgba = [gray, gray, gray, 1.0]; stabilize; } if (rayN > camVspFar) { rgba = [gray, gray, gray, 1.0-transp]; stabilize; } rayN = rayN + rayStep; } /* render: output maxval */ } 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 |