Skip to content

Commit 1e57d6f

Browse files
authored
Merge pull request #251 from gkjohnson/stable-tiles
Add support for incrementing tiles on change
2 parents a31feb5 + c81dc9e commit 1e57d6f

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,14 @@ stableNoise = false : Boolean
245245

246246
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.
247247

248+
### .stableTiles
249+
250+
```js
251+
stableTiles = true : Boolean
252+
```
253+
254+
Whether the initial tile is reset to the top left tile when moving the camera or if it should continue to shift every frame.
255+
248256
### .alpha
249257

250258
```js

src/core/PathTracingRenderer.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ function* renderTask() {
3838
material.resolution.set( w, h );
3939
material.seed ++;
4040

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

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

4949
material.cameraWorldMatrix.copy( camera.matrixWorld );
5050
material.invProjectionMatrix.copy( camera.projectionMatrixInverse );
@@ -73,14 +73,26 @@ function* renderTask() {
7373
const ogRenderTarget = _renderer.getRenderTarget();
7474
const ogAutoClear = _renderer.autoClear;
7575

76+
let tx = x;
77+
let ty = y;
78+
if ( ! this.stableTiles ) {
79+
80+
const tileIndex = ( this._currentTile ) % ( tilesX * tilesY );
81+
tx = tileIndex % tilesX;
82+
ty = ~ ~ ( tileIndex / tilesY );
83+
84+
this._currentTile = tileIndex + 1;
85+
86+
}
87+
7688
// three.js renderer takes values relative to the current pixel ratio
7789
_renderer.setRenderTarget( _primaryTarget );
7890
_renderer.setScissorTest( true );
7991
_renderer.setScissor(
80-
dprInv * Math.ceil( x * w / tx ),
81-
dprInv * Math.ceil( ( ty - y - 1 ) * h / ty ),
82-
dprInv * Math.ceil( w / tx ),
83-
dprInv * Math.ceil( h / ty ) );
92+
dprInv * Math.ceil( tx * w / tilesX ),
93+
dprInv * Math.ceil( ( tilesY - ty - 1 ) * h / tilesY ),
94+
dprInv * Math.ceil( w / tilesX ),
95+
dprInv * Math.ceil( h / tilesY ) );
8496
_renderer.autoClear = false;
8597
_fsQuad.render( _renderer );
8698

@@ -163,11 +175,14 @@ export class PathTracingRenderer {
163175

164176
this.samples = 0;
165177
this.stableNoise = false;
178+
this.stableTiles = true;
179+
166180
this._renderer = renderer;
167181
this._alpha = false;
168182
this._fsQuad = new FullScreenQuad( null );
169183
this._blendQuad = new FullScreenQuad( new BlendMaterial() );
170184
this._task = null;
185+
this._currentTile = 0;
171186

172187
this._primaryTarget = new WebGLRenderTarget( 1, 1, {
173188
format: RGBAFormat,

0 commit comments

Comments
 (0)