Skip to content

Commit d97679b

Browse files
committed
Merge commit '25670374031ca9f16177eb6bbd2ac1b6ff941c17'
2 parents cb747f9 + 2567037 commit d97679b

File tree

13 files changed

+739
-61
lines changed

13 files changed

+739
-61
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7-
## [0.0.7] = 2022-10-15
7+
## Unreleased
8+
### Fixed
9+
- Three.js semver package version.
10+
11+
## [0.0.7] - 2022-10-15
812
### Added
913
- DenoiseMaterial based on "glslSmartDenoise" to smooth the final render.
1014
- Support for vertex colors.

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ _More features and capabilities in progress!_
1515

1616
# Examples
1717

18+
**Setup**
19+
20+
[Basic Setup Example](https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/basic.html)
21+
1822
**Beauty Demos**
1923

2024
[Physically Based Materials](https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/index.html)
@@ -41,13 +45,14 @@ _More features and capabilities in progress!_
4145

4246
[Transmission Preset Orb](https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/materialBall.html#transmission)
4347

44-
[Model Viewer Fidelity Scene Comparisons](https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/viewerTest.html#khronos-DragonAttenuation)
48+
[Model Viewer Fidelity Scene Comparisons](https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/viewerTest.html)
49+
50+
[Physical Material Database](https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/materialDatabase.html)
4551

4652
**Light Baking**
4753

4854
[Ambient Occlusion Material](https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/aoRender.html)
4955

50-
5156
## Running examples locally
5257

5358
To run and modify the examples locally, make sure you have Node and NPM installed. Check the supported versions in [the test configuration](./.github/workflows/node.js.yml).

example/basic.html

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<html>
2+
<head>
3+
<title>Basic Path Tracing Example</title>
4+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
5+
6+
<style>
7+
html, body {
8+
margin: 0;
9+
padding: 0;
10+
background-color: #111;
11+
}
12+
13+
#info {
14+
position: absolute;
15+
bottom: 0;
16+
left: 0;
17+
font-family: 'Courier New', Courier, monospace;
18+
color: white;
19+
pointer-events: none;
20+
}
21+
22+
#samples, #credits {
23+
24+
opacity: 0.5;
25+
background-color: rgba( 0.0, 0.0, 0.0, 0.5 );
26+
padding: 5px;
27+
display: inline-block;
28+
29+
}
30+
31+
#loading {
32+
position: absolute;
33+
left: 50%;
34+
top: 50%;
35+
transform: translate(-50%, -50%);
36+
color: white;
37+
font-family: 'Courier New', Courier, monospace;
38+
}
39+
</style>
40+
41+
</head>
42+
<body>
43+
<div id="loading">LOADING</div>
44+
<div id="info">
45+
<div>
46+
<div id="samples">--</div>
47+
</div>
48+
<div>
49+
<div id="credits">Model by "nyancube" on Sketchfab.</div>
50+
</div>
51+
</div>
52+
<script src="./basic.js" type="module"></script>
53+
</body>
54+
</html>

example/basic.js

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
import * as THREE from 'three';
2+
import { FullScreenQuad } from 'three/examples/jsm/postprocessing/Pass.js';
3+
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
4+
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
5+
import { PathTracingRenderer, PhysicalPathTracingMaterial, PhysicalCamera } from '../src/index.js';
6+
import { PathTracingSceneWorker } from '../src/workers/PathTracingSceneWorker.js';
7+
import { RGBELoader } from 'three/examples/jsm/loaders/RGBELoader.js';
8+
9+
let renderer, controls, pathTracer, blitQuad, camera, scene, samplesEl;
10+
11+
let tiles = 1;
12+
let resolutionScale = 1;
13+
14+
// adjust performance parameters for mobile
15+
const aspectRatio = window.innerWidth / window.innerHeight;
16+
if ( aspectRatio < 0.65 ) {
17+
18+
resolutionScale *= 0.5;
19+
tiles = 2;
20+
21+
}
22+
23+
init();
24+
25+
async function init() {
26+
27+
samplesEl = document.getElementById( 'samples' );
28+
29+
// init renderer, camera, controls, scene
30+
renderer = new THREE.WebGLRenderer( { antialias: true } );
31+
renderer.toneMapping = THREE.ACESFilmicToneMapping;
32+
renderer.outputEncoding = THREE.sRGBEncoding;
33+
renderer.setClearColor( 0, 0 );
34+
document.body.appendChild( renderer.domElement );
35+
36+
camera = new PhysicalCamera( 75, 1, 0.025, 500 );
37+
camera.position.set( 8, 9, 24 );
38+
39+
controls = new OrbitControls( camera, renderer.domElement );
40+
controls.target.y = 10;
41+
controls.update();
42+
43+
scene = new THREE.Scene();
44+
45+
// init path tracer
46+
pathTracer = new PathTracingRenderer( renderer );
47+
pathTracer.material = new PhysicalPathTracingMaterial();
48+
pathTracer.material.filterGlossyFactor = 0.5;
49+
pathTracer.material.backgroundBlur = 0.05;
50+
pathTracer.tiles.set( tiles, tiles );
51+
pathTracer.camera = camera;
52+
53+
blitQuad = new FullScreenQuad( new THREE.MeshBasicMaterial( {
54+
map: pathTracer.target.texture,
55+
blending: THREE.CustomBlending,
56+
} ) );
57+
58+
controls.addEventListener( 'change', () => {
59+
60+
pathTracer.reset();
61+
62+
} );
63+
64+
// load the envmap and model
65+
const envMapPromise = new RGBELoader()
66+
.loadAsync( 'https://raw.githubusercontent.com/gkjohnson/3d-demo-data/master/hdri/chinese_garden_1k.hdr' )
67+
.then( texture => {
68+
69+
texture.mapping = THREE.EquirectangularReflectionMapping;
70+
scene.background = texture;
71+
scene.environment = texture;
72+
pathTracer.material.envMapInfo.updateFrom( texture );
73+
74+
} );
75+
76+
const generator = new PathTracingSceneWorker();
77+
const gltfPromise = new GLTFLoader()
78+
.loadAsync( 'https://raw.githubusercontent.com/gkjohnson/3d-demo-data/main/models/terrarium-robots/scene.gltf' )
79+
.then( gltf => {
80+
81+
return generator.generate( gltf.scene );
82+
83+
} )
84+
.then( result => {
85+
86+
scene.add( result.scene );
87+
88+
const { bvh, textures, materials } = result;
89+
const geometry = bvh.geometry;
90+
const material = pathTracer.material;
91+
92+
material.bvh.updateFrom( bvh );
93+
material.normalAttribute.updateFrom( geometry.attributes.normal );
94+
material.tangentAttribute.updateFrom( geometry.attributes.tangent );
95+
material.uvAttribute.updateFrom( geometry.attributes.uv );
96+
material.materialIndexAttribute.updateFrom( geometry.attributes.materialIndex );
97+
material.textures.setTextures( renderer, 2048, 2048, textures );
98+
material.materials.updateFrom( materials, textures );
99+
100+
generator.dispose();
101+
102+
} );
103+
104+
// wait for the scene to be rady
105+
await Promise.all( [ gltfPromise, envMapPromise ] );
106+
107+
document.getElementById( 'loading' ).remove();
108+
window.addEventListener( 'resize', onResize );
109+
110+
onResize();
111+
animate();
112+
113+
}
114+
115+
function onResize() {
116+
117+
// update rendering resolution
118+
const w = window.innerWidth;
119+
const h = window.innerHeight;
120+
const scale = resolutionScale;
121+
const dpr = window.devicePixelRatio;
122+
123+
pathTracer.setSize( w * scale * dpr, h * scale * dpr );
124+
pathTracer.reset();
125+
126+
renderer.setSize( w, h );
127+
renderer.setPixelRatio( window.devicePixelRatio * scale );
128+
129+
const aspect = w / h;
130+
camera.aspect = aspect;
131+
camera.updateProjectionMatrix();
132+
133+
}
134+
135+
function animate() {
136+
137+
requestAnimationFrame( animate );
138+
139+
camera.updateMatrixWorld();
140+
pathTracer.update();
141+
142+
if ( pathTracer.samples < 1 ) {
143+
144+
renderer.render( scene, camera );
145+
146+
}
147+
148+
renderer.autoClear = false;
149+
blitQuad.material.map = pathTracer.target.texture;
150+
blitQuad.render( renderer );
151+
renderer.autoClear = true;
152+
153+
samplesEl.innerText = `Samples: ${ Math.floor( pathTracer.samples ) }`;
154+
155+
}

example/depthOfField.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const mouse = new THREE.Vector2();
1414
const focusPoint = new THREE.Vector3();
1515
const params = {
1616

17-
environmentIntensity: 1,
17+
environmentIntensity: 0.5,
1818
environmentRotation: 0,
1919
bounces: 3,
2020
samplesPerFrame: 1,
@@ -78,24 +78,20 @@ async function init() {
7878

7979
samplesEl = document.getElementById( 'samples' );
8080

81-
const envMapPromise = new Promise( resolve => {
81+
const envMapPromise = new RGBELoader()
82+
.loadAsync( 'https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/textures/equirectangular/royal_esplanade_1k.hdr' )
83+
.then( texture => {
8284

83-
new RGBELoader()
84-
.load( 'https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/textures/equirectangular/royal_esplanade_1k.hdr', texture => {
85-
86-
const generator = new BlurredEnvMapGenerator( renderer );
87-
const blurredTex = generator.generate( texture, 0.35 );
88-
ptRenderer.material.envMapInfo.updateFrom( blurredTex );
89-
generator.dispose();
90-
texture.dispose();
91-
92-
scene.environment = blurredTex;
85+
const generator = new BlurredEnvMapGenerator( renderer );
86+
const blurredTex = generator.generate( texture, 0.35 );
87+
ptRenderer.material.envMapInfo.updateFrom( blurredTex );
88+
generator.dispose();
89+
texture.dispose();
9390

94-
resolve();
91+
scene.environment = blurredTex;
9592

96-
} );
93+
} );
9794

98-
} );
9995

10096
const generator = new PathTracingSceneWorker();
10197
const gltfPromise = new GLTFLoader()
@@ -105,7 +101,7 @@ async function init() {
105101

106102
const group = new THREE.Group();
107103

108-
const geometry = new THREE.SphereBufferGeometry( 1, 10, 10 );
104+
const geometry = new THREE.SphereGeometry( 1, 10, 10 );
109105
const mat = new THREE.MeshStandardMaterial( {
110106
emissiveIntensity: 10,
111107
emissive: 0xffffff

example/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@
297297

298298
let mat = new MeshPhysicalMaterial( {
299299
color: 0xcc8888,
300-
roughness: 0.15,
300+
roughness: 0.25,
301301
transmission: 1,
302302
ior: 1.5,
303303
} ) ;

example/interior.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,13 @@ async function init() {
9898

9999
samplesEl = document.getElementById( 'samples' );
100100

101-
const envMapPromise = new Promise( resolve => {
101+
const envMapPromise = new RGBELoader()
102+
.loadAsync( 'https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/textures/equirectangular/royal_esplanade_1k.hdr' )
103+
.then( texture => {
102104

103-
new RGBELoader()
104-
.load( 'https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/textures/equirectangular/royal_esplanade_1k.hdr', texture => {
105+
ptRenderer.material.envMapInfo.updateFrom( texture );
105106

106-
ptRenderer.material.envMapInfo.updateFrom( texture );
107-
resolve();
108-
109-
} );
110-
111-
} );
107+
} );
112108

113109
const generator = new PathTracingSceneWorker();
114110
const gltfPromise = new GLTFLoader()
@@ -166,8 +162,6 @@ async function init() {
166162

167163
await Promise.all( [ gltfPromise, envMapPromise ] );
168164

169-
window.CONTROLS = controls;
170-
171165
document.getElementById( 'loading' ).remove();
172166

173167
onResize();

example/materialBall.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -198,19 +198,15 @@ async function init() {
198198

199199
envMapGenerator = new BlurredEnvMapGenerator( renderer );
200200

201-
const envMapPromise = new Promise( resolve => {
201+
const envMapPromise = new RGBELoader()
202+
.loadAsync( 'https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/textures/equirectangular/royal_esplanade_1k.hdr' )
203+
.then( texture => {
202204

203-
new RGBELoader()
204-
.load( 'https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/textures/equirectangular/royal_esplanade_1k.hdr', texture => {
205+
envMap = texture;
205206

206-
envMap = texture;
207+
updateEnvBlur();
207208

208-
updateEnvBlur();
209-
resolve();
210-
211-
} );
212-
213-
} );
209+
} );
214210

215211
const generator = new PathTracingSceneWorker();
216212
const gltfPromise = new GLTFLoader()
@@ -228,7 +224,7 @@ async function init() {
228224
box.setFromObject( gltf.scene );
229225

230226
const floor = new THREE.Mesh(
231-
new THREE.CylinderBufferGeometry( 3, 3, 0.05, 200 ),
227+
new THREE.CylinderGeometry( 3, 3, 0.05, 200 ),
232228
new THREE.MeshPhysicalMaterial( { color: 0xffffff, roughness: 0, metalness: 0.25 } ),
233229
);
234230
floor.geometry = floor.geometry.toNonIndexed();

0 commit comments

Comments
 (0)