Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for incrementing tiles on change #251

Merged
merged 1 commit into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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