Skip to content

Commit

Permalink
Merge pull request #251 from gkjohnson/stable-tiles
Browse files Browse the repository at this point in the history
Add support for incrementing tiles on change
  • Loading branch information
gkjohnson committed Aug 10, 2022
2 parents a31feb5 + c81dc9e commit 1e57d6f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,14 @@ stableNoise = false : Boolean

Whether to reset the random seed to `0` when restarting the render. If true then a consistent random sample pattern will appear when moving the camera, for example.

### .stableTiles

```js
stableTiles = true : Boolean
```

Whether the initial tile is reset to the top left tile when moving the camera or if it should continue to shift every frame.

### .alpha

```js
Expand Down
33 changes: 24 additions & 9 deletions src/core/PathTracingRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ function* renderTask() {
material.resolution.set( w, h );
material.seed ++;

const tx = this.tiles.x || 1;
const ty = this.tiles.y || 1;
const totalTiles = tx * ty;
const tilesX = this.tiles.x || 1;
const tilesY = this.tiles.y || 1;
const totalTiles = tilesX * tilesY;
const dprInv = ( 1 / _renderer.getPixelRatio() );
for ( let y = 0; y < ty; y ++ ) {
for ( let y = 0; y < tilesY; y ++ ) {

for ( let x = 0; x < tx; x ++ ) {
for ( let x = 0; x < tilesX; x ++ ) {

material.cameraWorldMatrix.copy( camera.matrixWorld );
material.invProjectionMatrix.copy( camera.projectionMatrixInverse );
Expand Down Expand Up @@ -73,14 +73,26 @@ function* renderTask() {
const ogRenderTarget = _renderer.getRenderTarget();
const ogAutoClear = _renderer.autoClear;

let tx = x;
let ty = y;
if ( ! this.stableTiles ) {

const tileIndex = ( this._currentTile ) % ( tilesX * tilesY );
tx = tileIndex % tilesX;
ty = ~ ~ ( tileIndex / tilesY );

this._currentTile = tileIndex + 1;

}

// three.js renderer takes values relative to the current pixel ratio
_renderer.setRenderTarget( _primaryTarget );
_renderer.setScissorTest( true );
_renderer.setScissor(
dprInv * Math.ceil( x * w / tx ),
dprInv * Math.ceil( ( ty - y - 1 ) * h / ty ),
dprInv * Math.ceil( w / tx ),
dprInv * Math.ceil( h / ty ) );
dprInv * Math.ceil( tx * w / tilesX ),
dprInv * Math.ceil( ( tilesY - ty - 1 ) * h / tilesY ),
dprInv * Math.ceil( w / tilesX ),
dprInv * Math.ceil( h / tilesY ) );
_renderer.autoClear = false;
_fsQuad.render( _renderer );

Expand Down Expand Up @@ -163,11 +175,14 @@ export class PathTracingRenderer {

this.samples = 0;
this.stableNoise = false;
this.stableTiles = true;

this._renderer = renderer;
this._alpha = false;
this._fsQuad = new FullScreenQuad( null );
this._blendQuad = new FullScreenQuad( new BlendMaterial() );
this._task = null;
this._currentTile = 0;

this._primaryTarget = new WebGLRenderTarget( 1, 1, {
format: RGBAFormat,
Expand Down

0 comments on commit 1e57d6f

Please sign in to comment.