SCM Repository
View of /examples/vr-demo/vr-lite-cam.diderot
Parent Directory
|
Revision Log
Revision 2058 -
(download)
(annotate)
Tue Oct 30 10:38:25 2012 UTC (9 years, 7 months ago) by jhr
File size: 2863 byte(s)
Tue Oct 30 10:38:25 2012 UTC (9 years, 7 months ago) by jhr
File size: 2863 byte(s)
Working on vr-lite demo
// vr-lite-cam // // simple volume renderer, now with a single directional light, // Phong shading, and the new camera. // // image parameters input int imgResU = 480; input int imgResV = 345; input real rayStep = 0.1; // camera controls input vec3 camEye = [127.331, -1322.05, 272.53]; input vec3 camAt = [63.0, 82.6536, 98.0]; input vec3 camUp = [0.9987, 0.0459166, -0.0221267]; input real camNear = -78.0; input real camFar = 78.0; input real camFOV = 5.0; /* we control the opacity by its center value and the +/- keys */ input real valOpacMid = 550.0; // 550 for skin, 1300.0 for bone real valOpacMin = valOpacMid - 150.0; real valOpacMax = valOpacMid + 150.0; real camDist = |camAt - camEye|; real camVspNear = camDist + camNear; real camVspFar = camDist + camFar; vec3 camN = normalize(camAt - camEye); vec3 camU = normalize(camN × camUp); vec3 camV = camN × camU; real camVmax = tan(camFOV*π/360.0)*camDist; real camUmax = camVmax*real(imgResU)/real(imgResV); vec3 lightVspDir = [0.9, -1.0, -2.5]; vec3 lightDir = normalize(lightVspDir[0]*camU + lightVspDir[1]*camV + lightVspDir[2]*camN); //vec3 lightRGB = [1.0, 1.0, 1.0]; real phongKa = 0.05; real phongKd = 0.65; real phongKs = 0.45; real phongSp = 50.0; field#2(3)[] F = bspln3 ⊛ image("data/vfrhand-nohip.nhdr"); strand RayCast (int ui, int vi) { real rayU = lerp(-camUmax, camUmax, -0.5, real(ui), real(imgResU)-0.5); real rayV = lerp(-camVmax, camVmax, -0.5, real(vi), real(imgResV)-0.5); vec3 rayVec = (camDist*camN + rayU*camU + rayV*camV)/camDist; vec3 toEye = normalize(-rayVec); real rayN = camVspNear; // ########## BEGIN per-ray initialization real rayTransp = 1.0; // vec3 rayRGB = [0.0, 0.0, 0.0]; real rayGrey = 0.0; output vec4 outRGBA = [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); if (val > valOpacMin) { // we have some opacity vec3 grad = ∇F(rayPos); vec3 norm = normalize(-∇F(rayPos)); real alpha = min(1.0, lerp(0.0, 1.0, valOpacMin, val, valOpacMax)); real ld = max(0.0, norm • lightDir); real hd = max(0.0, norm • normalize(lightDir + toEye)); real pnt = phongKa + phongKd * ld + phongKs * hd^phongSp; rayGrey += rayTransp*alpha*pnt; rayTransp = rayTransp*(1.0 - alpha); } // ########## END per-sample code } if (rayTransp < 0.01) { // early ray termination rayTransp = 0.0; stabilize; } if (rayN > camVspFar) { stabilize; } rayN += rayStep; } stabilize { outRGBA = [rayGrey, rayGrey, rayGrey, 1.0-rayTransp]; } } 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 |