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

EffectComposer: Introduce .setPixelRatio() and harmonize resizing. #16404

Merged
merged 1 commit into from
May 8, 2019
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
41 changes: 34 additions & 7 deletions examples/js/postprocessing/EffectComposer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,20 @@ THREE.EffectComposer = function ( renderer, renderTarget ) {
stencilBuffer: false
};

var size = renderer.getDrawingBufferSize( new THREE.Vector2() );
renderTarget = new THREE.WebGLRenderTarget( size.width, size.height, parameters );
var size = renderer.getSize( new THREE.Vector2() );
this._pixelRatio = renderer.getPixelRatio();
this._width = size.width;
this._height = size.height;

renderTarget = new THREE.WebGLRenderTarget( this._width * this._pixelRatio, this._height * this._pixelRatio, parameters );
renderTarget.texture.name = 'EffectComposer.rt1';

} else {

this._pixelRatio = 1;
this._width = renderTarget.width;
this._height = renderTarget.height;

}

this.renderTarget1 = renderTarget;
Expand Down Expand Up @@ -162,10 +172,13 @@ Object.assign( THREE.EffectComposer.prototype, {

if ( renderTarget === undefined ) {

var size = this.renderer.getDrawingBufferSize( new THREE.Vector2() );
var size = this.renderer.getSize( new THREE.Vector2() );
this._pixelRatio = this.renderer.getPixelRatio();
this._width = size.width;
this._height = size.height;

renderTarget = this.renderTarget1.clone();
renderTarget.setSize( size.width, size.height );
renderTarget.setSize( this._width * this._pixelRatio, this._height * this._pixelRatio );

}

Expand All @@ -181,15 +194,29 @@ Object.assign( THREE.EffectComposer.prototype, {

setSize: function ( width, height ) {

this.renderTarget1.setSize( width, height );
this.renderTarget2.setSize( width, height );
this._width = width;
this._height = height;

var effectiveWidth = this._width * this._pixelRatio;
var effectiveHeight = this._height * this._pixelRatio;

this.renderTarget1.setSize( effectiveWidth, effectiveHeight );
this.renderTarget2.setSize( effectiveWidth, effectiveHeight );

for ( var i = 0; i < this.passes.length; i ++ ) {

this.passes[ i ].setSize( width, height );
this.passes[ i ].setSize( effectiveWidth, effectiveHeight );

}

},

setPixelRatio: function ( pixelRatio ) {

this._pixelRatio = pixelRatio;

this.setSize( this._width, this._height );

}

} );
Expand Down
5 changes: 2 additions & 3 deletions examples/misc_controls_fly.html
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,11 @@
SCREEN_HEIGHT = window.innerHeight;
SCREEN_WIDTH = window.innerWidth;

renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );

camera.aspect = SCREEN_WIDTH / SCREEN_HEIGHT;
camera.updateProjectionMatrix();

composer.reset();
renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
composer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );

}

Expand Down
2 changes: 1 addition & 1 deletion examples/webgl_materials_video.html
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@
camera.updateProjectionMatrix();

renderer.setSize( window.innerWidth, window.innerHeight );
composer.reset();
composer.setSize( window.innerWidth, window.innerHeight );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As is was before.

composer.reset() should auto-size the composer based on the renderer's drawing buffer size.


}

Expand Down
13 changes: 6 additions & 7 deletions examples/webgl_points_dynamic.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@

effectFocus = new THREE.ShaderPass( THREE.FocusShader );

effectFocus.uniforms[ "screenWidth" ].value = window.innerWidth;
effectFocus.uniforms[ "screenHeight" ].value = window.innerHeight;
effectFocus.uniforms[ "screenWidth" ].value = window.innerWidth * window.devicePixelRatio;
effectFocus.uniforms[ "screenHeight" ].value = window.innerHeight * window.devicePixelRatio;

composer = new THREE.EffectComposer( renderer );

Expand All @@ -156,17 +156,16 @@

function onWindowResize() {

renderer.setSize( window.innerWidth, window.innerHeight );

camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();

camera.lookAt( scene.position );

composer.reset();
renderer.setSize( window.innerWidth, window.innerHeight );
composer.setSize( window.innerWidth, window.innerHeight );

effectFocus.uniforms[ "screenWidth" ].value = window.innerWidth;
effectFocus.uniforms[ "screenHeight" ].value = window.innerHeight;
effectFocus.uniforms[ "screenWidth" ].value = window.innerWidth * window.devicePixelRatio;
effectFocus.uniforms[ "screenHeight" ].value = window.innerHeight * window.devicePixelRatio;

}

Expand Down
6 changes: 1 addition & 5 deletions examples/webgl_postprocessing_backgrounds.html
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,7 @@
cameraO.updateProjectionMatrix();*/

renderer.setSize( width, height );

var pixelRatio = renderer.getPixelRatio();
var newWidth = Math.floor( width * pixelRatio ) || 1;
var newHeight = Math.floor( height * pixelRatio ) || 1;
composer.setSize( newWidth, newHeight );
composer.setSize( width, height );

}

Expand Down
6 changes: 1 addition & 5 deletions examples/webgl_postprocessing_smaa.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,7 @@
camera.updateProjectionMatrix();

renderer.setSize( width, height );

var pixelRatio = renderer.getPixelRatio();
var newWidth = Math.floor( width * pixelRatio ) || 1;
var newHeight = Math.floor( height * pixelRatio ) || 1;
composer.setSize( newWidth, newHeight );
composer.setSize( width, height );

}

Expand Down
8 changes: 4 additions & 4 deletions examples/webgl_postprocessing_sobel.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@
// Sobel operator

effectSobel = new THREE.ShaderPass( THREE.SobelOperatorShader );
effectSobel.uniforms[ "resolution" ].value.x = window.innerWidth;
effectSobel.uniforms[ "resolution" ].value.y = window.innerHeight;
effectSobel.uniforms[ 'resolution' ].value.x = window.innerWidth * window.devicePixelRatio;
effectSobel.uniforms[ 'resolution' ].value.y = window.innerHeight * window.devicePixelRatio;
composer.addPass( effectSobel );

var controls = new THREE.OrbitControls( camera, renderer.domElement );
Expand All @@ -145,8 +145,8 @@
renderer.setSize( window.innerWidth, window.innerHeight );
composer.setSize( window.innerWidth, window.innerHeight );

effectSobel.uniforms[ "resolution" ].value.x = window.innerWidth;
effectSobel.uniforms[ "resolution" ].value.y = window.innerHeight;
effectSobel.uniforms[ 'resolution' ].value.x = window.innerWidth * window.devicePixelRatio;
effectSobel.uniforms[ 'resolution' ].value.y = window.innerHeight * window.devicePixelRatio;

}

Expand Down
6 changes: 1 addition & 5 deletions examples/webgl_postprocessing_ssaa.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,7 @@
camera.updateProjectionMatrix();

renderer.setSize( width, height );

var pixelRatio = renderer.getPixelRatio();
var newWidth = Math.floor( width * pixelRatio ) || 1;
var newHeight = Math.floor( height * pixelRatio ) || 1;
composer.setSize( newWidth, newHeight );
composer.setSize( width, height );

}

Expand Down
7 changes: 2 additions & 5 deletions examples/webgl_postprocessing_ssaa_unbiased.html
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
// postprocessing

composer = new THREE.EffectComposer( renderer );
composer.setPixelRatio( 1 ); // ensure pixel ratio is always 1 for performance reasons
ssaaRenderPassP = new THREE.SSAARenderPass( scene, cameraP );
composer.addPass( ssaaRenderPassP );
ssaaRenderPassO = new THREE.SSAARenderPass( scene, cameraO );
Expand Down Expand Up @@ -204,11 +205,7 @@
cameraO.updateProjectionMatrix();

renderer.setSize( width, height );

var pixelRatio = renderer.getPixelRatio();
var newWidth = Math.floor( width * pixelRatio ) || 1;
var newHeight = Math.floor( height * pixelRatio ) || 1;
composer.setSize( newWidth, newHeight );
composer.setSize( width, height );

}

Expand Down
6 changes: 1 addition & 5 deletions examples/webgl_postprocessing_taa.html
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,7 @@
camera.updateProjectionMatrix();

renderer.setSize( width, height );

var pixelRatio = renderer.getPixelRatio();
var newWidth = Math.floor( width * pixelRatio ) || 1;
var newHeight = Math.floor( height * pixelRatio ) || 1;
composer.setSize( newWidth, newHeight );
composer.setSize( width, height );

}

Expand Down
1 change: 0 additions & 1 deletion examples/webgl_postprocessing_unreal_bloom.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@
bloomPass.radius = params.bloomRadius;

composer = new THREE.EffectComposer( renderer );
composer.setSize( window.innerWidth, window.innerHeight );
composer.addPass( renderScene );
composer.addPass( bloomPass );

Expand Down
6 changes: 2 additions & 4 deletions examples/webgl_postprocessing_unreal_bloom_selective.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@

var bloomComposer = new THREE.EffectComposer( renderer );
bloomComposer.renderToScreen = false;
bloomComposer.setSize( window.innerWidth * window.devicePixelRatio, window.innerHeight * window.devicePixelRatio );
bloomComposer.addPass( renderScene );
bloomComposer.addPass( bloomPass );

Expand All @@ -158,7 +157,6 @@
finalPass.needsSwap = true;

var finalComposer = new THREE.EffectComposer( renderer );
finalComposer.setSize( window.innerWidth * window.devicePixelRatio, window.innerHeight * window.devicePixelRatio );
finalComposer.addPass( renderScene );
finalComposer.addPass( finalPass );

Expand Down Expand Up @@ -251,8 +249,8 @@

renderer.setSize( width, height );

bloomComposer.setSize( width * window.devicePixelRatio, height * window.devicePixelRatio );
finalComposer.setSize( width * window.devicePixelRatio, height * window.devicePixelRatio );
bloomComposer.setSize( width, height );
finalComposer.setSize( width, height );

render();

Expand Down
5 changes: 2 additions & 3 deletions examples/webgl_shader_lava.html
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,11 @@

function onWindowResize() {

renderer.setSize( window.innerWidth, window.innerHeight );

camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();

composer.reset();
renderer.setSize( window.innerWidth, window.innerHeight );
composer.setSize( window.innerWidth, window.innerHeight );

}

Expand Down