-
Notifications
You must be signed in to change notification settings - Fork 182
/
Copy pathCompare_Bi-Directional_Approach.js
89 lines (63 loc) · 3.23 KB
/
Compare_Bi-Directional_Approach.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// scene/demo-specific variables go here
let tallBoxGeometry, tallBoxMaterial, tallBoxMesh;
let shortBoxGeometry, shortBoxMaterial, shortBoxMesh;
// called automatically from within initTHREEjs() function (located in InitCommon.js file)
function initSceneData()
{
demoFragmentShaderFileName = 'Compare_Bi-Directional_Approach_Fragment.glsl';
// scene/demo-specific three.js objects setup goes here
sceneIsDynamic = false;
edgeSharpenSpeed = 0.001;//0.0002;
cameraFlightSpeed = 300;
// pixelRatio is resolution - range: 0.5(half resolution) to 1.0(full resolution)
pixelRatio = mouseControl ? 1.0 : 1.0; // mobile devices can also handle full resolution for this demo
EPS_intersect = 0.01;
// Boxes
tallBoxGeometry = new THREE.BoxGeometry(1, 1, 1);
tallBoxMaterial = new THREE.MeshPhysicalMaterial({
color: new THREE.Color(0.95, 0.95, 0.95), //RGB, ranging from 0.0 - 1.0
roughness: 1.0 // ideal Diffuse material
});
tallBoxMesh = new THREE.Mesh(tallBoxGeometry, tallBoxMaterial);
pathTracingScene.add(tallBoxMesh);
tallBoxMesh.visible = false; // disable normal Three.js rendering updates of this object:
// it is just a data placeholder as well as an Object3D that can be transformed/manipulated by
// using familiar Three.js library commands. It is then fed into the GPU path tracing renderer
// through its 'matrixWorld' matrix. See below:
tallBoxMesh.rotation.set(0, Math.PI * 0.1, 0);
tallBoxMesh.position.set(180, 170, -350);
tallBoxMesh.updateMatrixWorld(true); // 'true' forces immediate matrix update
shortBoxGeometry = new THREE.BoxGeometry(1, 1, 1);
shortBoxMaterial = new THREE.MeshPhysicalMaterial({
color: new THREE.Color(0.95, 0.95, 0.95), //RGB, ranging from 0.0 - 1.0
roughness: 1.0 // ideal Diffuse material
});
shortBoxMesh = new THREE.Mesh(shortBoxGeometry, shortBoxMaterial);
pathTracingScene.add(shortBoxMesh);
shortBoxMesh.visible = false;
shortBoxMesh.rotation.set(0, -Math.PI * 0.09, 0);
shortBoxMesh.position.set(370, 85, -170);
shortBoxMesh.updateMatrixWorld(true); // 'true' forces immediate matrix update
// set camera's field of view
worldCamera.fov = 31;
focusDistance = 1180.0;
apertureChangeSpeed = 200;
// position and orient camera
cameraControlsObject.position.set(278, 270, 1050);
///cameraControlsYawObject.rotation.y = 0.0;
// look slightly upward
cameraControlsPitchObject.rotation.x = 0.005;
// scene/demo-specific uniforms go here
pathTracingUniforms.uTallBoxInvMatrix = { value: new THREE.Matrix4() };
pathTracingUniforms.uShortBoxInvMatrix = { value: new THREE.Matrix4() };
} // end function initSceneData()
// called automatically from within the animate() function (located in InitCommon.js file)
function updateVariablesAndUniforms()
{
// BOXES
pathTracingUniforms.uTallBoxInvMatrix.value.copy(tallBoxMesh.matrixWorld).invert();
pathTracingUniforms.uShortBoxInvMatrix.value.copy(shortBoxMesh.matrixWorld).invert();
// INFO
cameraInfoElement.innerHTML = "FOV: " + worldCamera.fov + " / Aperture: " + apertureSize.toFixed(2) + " / FocusDistance: " + focusDistance + "<br>" + "Samples: " + sampleCounter;
} // end function updateVariablesAndUniforms()
init(); // init app and start animating