gkjohnson / three-gpu-pathtracer

Path tracing renderer and utilities for three.js built on top of three-mesh-bvh.
https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/index.html
MIT License
1.27k stars 125 forks source link

Add WebGLPathTracer convenience class #563

Closed gkjohnson closed 3 months ago

gkjohnson commented 3 months ago

Related to #498

Next PRs

gkjohnson commented 3 months ago

Looks like bounces are set to a lower value? Or color space?

Before

image

After

image
gkjohnson commented 3 months ago

The darkening is due to the "filterGlossyFactor" - should look into in a future PR.

gkjohnson commented 3 months ago

cc @donmccurdy - this PR adds a more simple way to access and render a path traced scene that mirrors the WebGLRenderer API design in some ways. I think this is something you'd wanted previously? Here's what it looks like to path trace a scene now:

const scene = new Scene();

// initialize scene ...

const texture = new GradientEquirectTexture();
texture.bottomColor.set( 0xffffff );
texture.bottomColor.set( 0x666666 );
texture.update();
scene.environment = texture;
scene.background = texture;

const renderer = new WebGLPathTracer();
document.body.appendChild( renderer.domElement );
renderer.toneMapping = ACESFilmicToneMapping;
renderer.tiles.set( 3 );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.updateScene( camera, scene );

animate();

function animate() {

    // if the camera position changes call "ptRenderer.reset()"
    requestAnimationFrame( animate );

    // update the camera and render one sample
    camera.updateMatrixWorld();

    // rasterizes the main scene if there are not enough path traced
    // samples and renders the path traced scene tiles on top. 
    renderer.renderSample();

}

There are some settings to disable rendering to canvas so you can just work with the Path Traced render target, as well. Let me know what you think.