Skip to content

Commit

Permalink
Editor: Update realistic viewport packages (#27780)
Browse files Browse the repository at this point in the history
* Use a larger texture for env map, background

* Only display after 1 sample

* update versions

* Bump package versions again

* Remove need for dummy geometry
  • Loading branch information
gkjohnson committed Feb 20, 2024
1 parent af2b894 commit 54127d1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
4 changes: 2 additions & 2 deletions editor/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
"three/addons/": "../examples/jsm/",

"three/examples/": "../examples/",
"three-gpu-pathtracer": "https://unpkg.com/three-gpu-pathtracer@0.0.17/build/index.module.js",
"three-mesh-bvh": "https://unpkg.com/three-mesh-bvh@0.7.0/build/index.module.js"
"three-gpu-pathtracer": "https://unpkg.com/three-gpu-pathtracer@0.0.19/build/index.module.js",
"three-mesh-bvh": "https://unpkg.com/three-mesh-bvh@0.7.3/build/index.module.js"
}
}
</script>
Expand Down
39 changes: 21 additions & 18 deletions editor/js/Viewport.Pathtracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ import { FullScreenQuad } from 'three/examples/jsm/postprocessing/Pass.js';
import {
PathTracingSceneGenerator,
PathTracingRenderer,
PhysicalPathTracingMaterial
PhysicalPathTracingMaterial,
ProceduralEquirectTexture,
} from 'three-gpu-pathtracer';

function buildColorTexture( color ) {

const data = new Uint8Array( [ color.r * 255, color.g * 255, color.b * 255, 255 ] );
const texture = new THREE.DataTexture( data, 1, 1, THREE.RGBAFormat );
texture.needsUpdate = true;
const texture = new ProceduralEquirectTexture( 4, 4 );
texture.generationCallback = ( polar, uv, coord, target ) => {

target.copy( color );

};

texture.update();

return texture;

Expand Down Expand Up @@ -46,14 +52,6 @@ function ViewportPathtracer( renderer ) {
pathtracer.material.backgroundBlur = scene.backgroundBlurriness;
pathtracer.reset();

// TOFIX: If the scene is empty the generator crashes so we render a tiny cube (:

if ( scene.children.length === 0 ) {

scene = new THREE.Mesh( new THREE.BoxGeometry( 0.0001, 0.0001, 0.0001 ) );

}

const { bvh, textures, materials, lights } = generator.generate( scene );

const ptGeometry = bvh.geometry;
Expand All @@ -70,6 +68,7 @@ function ViewportPathtracer( renderer ) {
ptMaterial.textures.setTextures( renderer, 2048, 2048, textures );
ptMaterial.materials.updateFrom( materials, textures );
ptMaterial.lights.updateFrom( lights );
ptMaterial.filterGlossyFactor = 0.5;

//

Expand All @@ -89,15 +88,15 @@ function ViewportPathtracer( renderer ) {

} else {

ptMaterial.backgroundMap = buildColorTexture( new THREE.Color( 0x000000 ) );
ptMaterial.backgroundMap = buildColorTexture( new THREE.Color( 0 ) );

}

//

const environment = scene.environment;

if ( environment && environment.isTexture === true ) {
if ( environment && environment.isDataTexture === true ) {

// Avoid calling envMapInfo() with the same hdr

Expand All @@ -110,7 +109,7 @@ function ViewportPathtracer( renderer ) {

} else {

ptMaterial.envMapInfo.updateFrom( buildColorTexture( new THREE.Color( 0xffffff ) ) );
ptMaterial.envMapInfo.updateFrom( buildColorTexture( new THREE.Color( 0 ) ) );

}

Expand All @@ -131,9 +130,13 @@ function ViewportPathtracer( renderer ) {

pathtracer.update();

renderer.autoClear = false;
quad.render( renderer );
renderer.autoClear = true;
if ( pathtracer.samples >= 1 ) {

renderer.autoClear = false;
quad.render( renderer );
renderer.autoClear = true;

}

}

Expand Down

0 comments on commit 54127d1

Please sign in to comment.