Skip to content
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
45 changes: 37 additions & 8 deletions examples/jsm/postprocessing/SSRPass.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ class SSRPass extends Pass {

this._selects = selects;

this._resolutionScale = 1;

/**
* Whether the pass is selective or not.
*
Expand Down Expand Up @@ -457,6 +459,29 @@ class SSRPass extends Pass {

}


/**
* The resolution scale. Valid values are in the range
* `[0,1]`. `1` means best quality but also results in
* more computational overhead. Setting to `0.5` means
* the effect is computed in half-resolution.
*
* @type {number}
* @default 1
*/
get resolutionScale() {

return this._resolutionScale;

}

set resolutionScale( value ) {

this._resolutionScale = value;
this.setSize( this.width, this.height ); // force a resize when resolution scaling changes

}

/**
* Frees the GPU-related resources allocated by this instance. Call this
* method whenever the pass is no longer used in your app.
Expand Down Expand Up @@ -661,23 +686,27 @@ class SSRPass extends Pass {
this.width = width;
this.height = height;

this.ssrMaterial.defines.MAX_STEP = Math.sqrt( width * width + height * height );
const effectiveWidth = Math.round( this.resolutionScale * width );
const effectiveHeight = Math.round( this.resolutionScale * height );

this.ssrMaterial.defines.MAX_STEP = Math.sqrt( effectiveWidth * effectiveWidth + effectiveHeight * effectiveHeight );
this.ssrMaterial.needsUpdate = true;

this.beautyRenderTarget.setSize( width, height );
this.prevRenderTarget.setSize( width, height );
this.ssrRenderTarget.setSize( width, height );
this.normalRenderTarget.setSize( width, height );
this.metalnessRenderTarget.setSize( width, height );
this.blurRenderTarget.setSize( width, height );
this.blurRenderTarget2.setSize( width, height );
this.ssrRenderTarget.setSize( effectiveWidth, effectiveHeight );
this.prevRenderTarget.setSize( effectiveWidth, effectiveHeight );
this.blurRenderTarget.setSize( effectiveWidth, effectiveHeight );
this.blurRenderTarget2.setSize( effectiveWidth, effectiveHeight );
// this.blurRenderTarget3.setSize(width, height);

this.ssrMaterial.uniforms[ 'resolution' ].value.set( width, height );
this.ssrMaterial.uniforms[ 'resolution' ].value.set( effectiveWidth, effectiveHeight );
this.ssrMaterial.uniforms[ 'cameraProjectionMatrix' ].value.copy( this.camera.projectionMatrix );
this.ssrMaterial.uniforms[ 'cameraInverseProjectionMatrix' ].value.copy( this.camera.projectionMatrixInverse );

this.blurMaterial.uniforms[ 'resolution' ].value.set( width, height );
this.blurMaterial2.uniforms[ 'resolution' ].value.set( width, height );
this.blurMaterial.uniforms[ 'resolution' ].value.set( effectiveWidth, effectiveHeight );
this.blurMaterial2.uniforms[ 'resolution' ].value.set( effectiveWidth, effectiveHeight );

}

Expand Down
1 change: 1 addition & 0 deletions examples/webgl_postprocessing_ssr.html
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@

} );
ssrPass.thickness = 0.018;
gui.add( ssrPass, 'resolutionScale' ).min( 0 ).max( 1 );
gui.add( ssrPass, 'thickness' ).min( 0 ).max( .1 ).step( .0001 );
ssrPass.infiniteThick = false;
gui.add( ssrPass, 'infiniteThick' );
Expand Down
Loading