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: Use HalfFloatType as default. #26099

Merged
merged 3 commits into from May 21, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions examples/jsm/postprocessing/AdaptiveToneMappingPass.js
@@ -1,4 +1,5 @@
import {
HalfFloatType,
LinearMipmapLinearFilter,
MeshBasicMaterial,
NoBlending,
Expand Down Expand Up @@ -206,17 +207,17 @@ class AdaptiveToneMappingPass extends Pass {
}


this.luminanceRT = new WebGLRenderTarget( this.resolution, this.resolution );
this.luminanceRT = new WebGLRenderTarget( this.resolution, this.resolution, { type: HalfFloatType } );
this.luminanceRT.texture.name = 'AdaptiveToneMappingPass.l';
this.luminanceRT.texture.generateMipmaps = false;

this.previousLuminanceRT = new WebGLRenderTarget( this.resolution, this.resolution );
this.previousLuminanceRT = new WebGLRenderTarget( this.resolution, this.resolution, { type: HalfFloatType } );
this.previousLuminanceRT.texture.name = 'AdaptiveToneMappingPass.pl';
this.previousLuminanceRT.texture.generateMipmaps = false;

// We only need mipmapping for the current luminosity because we want a down-sampled version to sample in our adaptive shader

const pars = { minFilter: LinearMipmapLinearFilter, generateMipmaps: true };
const pars = { minFilter: LinearMipmapLinearFilter, generateMipmaps: true, type: HalfFloatType };

this.currentLuminanceRT = new WebGLRenderTarget( this.resolution, this.resolution, pars );
this.currentLuminanceRT.texture.name = 'AdaptiveToneMappingPass.cl';
Expand Down
3 changes: 3 additions & 0 deletions examples/jsm/postprocessing/AfterimagePass.js
@@ -1,4 +1,5 @@
import {
HalfFloatType,
MeshBasicMaterial,
NearestFilter,
ShaderMaterial,
Expand All @@ -22,10 +23,12 @@ class AfterimagePass extends Pass {

this.textureComp = new WebGLRenderTarget( window.innerWidth, window.innerHeight, {
magFilter: NearestFilter,
type: HalfFloatType
} );

this.textureOld = new WebGLRenderTarget( window.innerWidth, window.innerHeight, {
magFilter: NearestFilter,
type: HalfFloatType
} );

this.compFsMaterial = new ShaderMaterial( {
Expand Down
5 changes: 3 additions & 2 deletions examples/jsm/postprocessing/BloomPass.js
@@ -1,5 +1,6 @@
import {
AdditiveBlending,
HalfFloatType,
ShaderMaterial,
UniformsUtils,
Vector2,
Expand All @@ -16,9 +17,9 @@ class BloomPass extends Pass {

// render targets

this.renderTargetX = new WebGLRenderTarget(); // will be resized later
this.renderTargetX = new WebGLRenderTarget( 1, 1, { type: HalfFloatType } ); // will be resized later
this.renderTargetX.texture.name = 'BloomPass.x';
this.renderTargetY = new WebGLRenderTarget(); // will be resized later
this.renderTargetY = new WebGLRenderTarget( 1, 1, { type: HalfFloatType } ); // will be resized later
this.renderTargetY.texture.name = 'BloomPass.y';

// combine material
Expand Down
4 changes: 3 additions & 1 deletion examples/jsm/postprocessing/BokehPass.js
@@ -1,5 +1,6 @@
import {
Color,
HalfFloatType,
MeshDepthMaterial,
NearestFilter,
NoBlending,
Expand Down Expand Up @@ -33,7 +34,8 @@ class BokehPass extends Pass {

this.renderTargetDepth = new WebGLRenderTarget( 1, 1, { // will be resized later
minFilter: NearestFilter,
magFilter: NearestFilter
magFilter: NearestFilter,
type: HalfFloatType
Copy link
Collaborator

Choose a reason for hiding this comment

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

@Mugen87 Can you please explain why NearestFilter is used in many of the examples in this PR? Should it not be a fallback, instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did not want to touch filtering settings since they might be intended for specific passes.

However, I'm open for a review in this context and update to a higher setting when it's appropriate.

} );

this.renderTargetDepth.texture.name = 'BokehPass.depth';
Expand Down
3 changes: 2 additions & 1 deletion examples/jsm/postprocessing/EffectComposer.js
@@ -1,5 +1,6 @@
import {
Clock,
HalfFloatType,
Vector2,
WebGLRenderTarget
} from 'three';
Expand All @@ -22,7 +23,7 @@ class EffectComposer {
this._width = size.width;
this._height = size.height;

renderTarget = new WebGLRenderTarget( this._width * this._pixelRatio, this._height * this._pixelRatio );
renderTarget = new WebGLRenderTarget( this._width * this._pixelRatio, this._height * this._pixelRatio, { type: HalfFloatType } );
renderTarget.texture.name = 'EffectComposer.rt1';

} else {
Expand Down
13 changes: 7 additions & 6 deletions examples/jsm/postprocessing/OutlinePass.js
Expand Up @@ -2,6 +2,7 @@ import {
AdditiveBlending,
Color,
DoubleSide,
HalfFloatType,
Matrix4,
MeshDepthMaterial,
NoBlending,
Expand Down Expand Up @@ -54,26 +55,26 @@ class OutlinePass extends Pass {
this.prepareMaskMaterial.side = DoubleSide;
this.prepareMaskMaterial.fragmentShader = replaceDepthToViewZ( this.prepareMaskMaterial.fragmentShader, this.renderCamera );

this.renderTargetDepthBuffer = new WebGLRenderTarget( this.resolution.x, this.resolution.y );
this.renderTargetDepthBuffer = new WebGLRenderTarget( this.resolution.x, this.resolution.y, { type: HalfFloatType } );
this.renderTargetDepthBuffer.texture.name = 'OutlinePass.depth';
this.renderTargetDepthBuffer.texture.generateMipmaps = false;

this.renderTargetMaskDownSampleBuffer = new WebGLRenderTarget( resx, resy );
this.renderTargetMaskDownSampleBuffer = new WebGLRenderTarget( resx, resy, { type: HalfFloatType } );
this.renderTargetMaskDownSampleBuffer.texture.name = 'OutlinePass.depthDownSample';
this.renderTargetMaskDownSampleBuffer.texture.generateMipmaps = false;

this.renderTargetBlurBuffer1 = new WebGLRenderTarget( resx, resy );
this.renderTargetBlurBuffer1 = new WebGLRenderTarget( resx, resy, { type: HalfFloatType } );
this.renderTargetBlurBuffer1.texture.name = 'OutlinePass.blur1';
this.renderTargetBlurBuffer1.texture.generateMipmaps = false;
this.renderTargetBlurBuffer2 = new WebGLRenderTarget( Math.round( resx / 2 ), Math.round( resy / 2 ) );
this.renderTargetBlurBuffer2 = new WebGLRenderTarget( Math.round( resx / 2 ), Math.round( resy / 2 ), { type: HalfFloatType } );
this.renderTargetBlurBuffer2.texture.name = 'OutlinePass.blur2';
this.renderTargetBlurBuffer2.texture.generateMipmaps = false;

this.edgeDetectionMaterial = this.getEdgeDetectionMaterial();
this.renderTargetEdgeBuffer1 = new WebGLRenderTarget( resx, resy );
this.renderTargetEdgeBuffer1 = new WebGLRenderTarget( resx, resy, { type: HalfFloatType } );
this.renderTargetEdgeBuffer1.texture.name = 'OutlinePass.edge1';
this.renderTargetEdgeBuffer1.texture.generateMipmaps = false;
this.renderTargetEdgeBuffer2 = new WebGLRenderTarget( Math.round( resx / 2 ), Math.round( resy / 2 ) );
this.renderTargetEdgeBuffer2 = new WebGLRenderTarget( Math.round( resx / 2 ), Math.round( resy / 2 ), { type: HalfFloatType } );
this.renderTargetEdgeBuffer2.texture.name = 'OutlinePass.edge2';
this.renderTargetEdgeBuffer2.texture.generateMipmaps = false;

Expand Down
7 changes: 4 additions & 3 deletions examples/jsm/postprocessing/RenderPixelatedPass.js
Expand Up @@ -5,7 +5,8 @@ import {
Vector2,
Vector4,
DepthTexture,
NearestFilter
NearestFilter,
HalfFloatType
} from 'three';
import { Pass, FullScreenQuad } from './Pass.js';

Expand All @@ -32,13 +33,13 @@ class RenderPixelatedPass extends Pass {
this.beautyRenderTarget = new WebGLRenderTarget();
this.beautyRenderTarget.texture.minFilter = NearestFilter;
this.beautyRenderTarget.texture.magFilter = NearestFilter;
this.beautyRenderTarget.texture.type = HalfFloatType;
this.beautyRenderTarget.depthTexture = new DepthTexture();

this.normalRenderTarget = new WebGLRenderTarget();
this.normalRenderTarget.texture.minFilter = NearestFilter;
this.normalRenderTarget.texture.magFilter = NearestFilter;


this.normalRenderTarget.texture.type = HalfFloatType;

}

Expand Down
6 changes: 4 additions & 2 deletions examples/jsm/postprocessing/SAOPass.js
Expand Up @@ -5,6 +5,7 @@ import {
DepthTexture,
DstAlphaFactor,
DstColorFactor,
HalfFloatType,
MeshDepthMaterial,
MeshNormalMaterial,
NearestFilter,
Expand Down Expand Up @@ -62,13 +63,14 @@ class SAOPass extends Pass {

this.resolution = new Vector2( resolution.x, resolution.y );

this.saoRenderTarget = new WebGLRenderTarget( this.resolution.x, this.resolution.y );
this.saoRenderTarget = new WebGLRenderTarget( this.resolution.x, this.resolution.y, { type: HalfFloatType } );
this.blurIntermediateRenderTarget = this.saoRenderTarget.clone();
this.beautyRenderTarget = this.saoRenderTarget.clone();

this.normalRenderTarget = new WebGLRenderTarget( this.resolution.x, this.resolution.y, {
minFilter: NearestFilter,
magFilter: NearestFilter
magFilter: NearestFilter,
type: HalfFloatType
} );
this.depthRenderTarget = this.normalRenderTarget.clone();

Expand Down
7 changes: 5 additions & 2 deletions examples/jsm/postprocessing/SMAAPass.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion examples/jsm/postprocessing/SSAARenderPass.js
Expand Up @@ -4,6 +4,7 @@ import {
AddEquation,
SrcAlphaFactor,
Color,
HalfFloatType,
ShaderMaterial,
UniformsUtils,
WebGLRenderTarget
Expand Down Expand Up @@ -87,7 +88,7 @@ class SSAARenderPass extends Pass {

if ( ! this.sampleRenderTarget ) {

this.sampleRenderTarget = new WebGLRenderTarget( readBuffer.width, readBuffer.height );
this.sampleRenderTarget = new WebGLRenderTarget( readBuffer.width, readBuffer.height, { type: HalfFloatType } );
this.sampleRenderTarget.texture.name = 'SSAARenderPass.sample';

}
Expand Down
6 changes: 4 additions & 2 deletions examples/jsm/postprocessing/SSAOPass.js
Expand Up @@ -7,6 +7,7 @@ import {
DstAlphaFactor,
DstColorFactor,
FloatType,
HalfFloatType,
MathUtils,
MeshNormalMaterial,
NearestFilter,
Expand Down Expand Up @@ -65,19 +66,20 @@ class SSAOPass extends Pass {
depthTexture.format = DepthStencilFormat;
depthTexture.type = UnsignedInt248Type;

this.beautyRenderTarget = new WebGLRenderTarget( this.width, this.height );
this.beautyRenderTarget = new WebGLRenderTarget( this.width, this.height, { type: HalfFloatType } );

// normal render target with depth buffer

this.normalRenderTarget = new WebGLRenderTarget( this.width, this.height, {
minFilter: NearestFilter,
magFilter: NearestFilter,
type: HalfFloatType,
depthTexture: depthTexture
} );

// ssao render target

this.ssaoRenderTarget = new WebGLRenderTarget( this.width, this.height );
this.ssaoRenderTarget = new WebGLRenderTarget( this.width, this.height, { type: HalfFloatType } );

this.blurRenderTarget = this.ssaoRenderTarget.clone();

Expand Down
4 changes: 3 additions & 1 deletion examples/jsm/postprocessing/SSRPass.js
Expand Up @@ -162,6 +162,7 @@ class SSRPass extends Pass {
this.beautyRenderTarget = new WebGLRenderTarget( this.width, this.height, {
minFilter: NearestFilter,
magFilter: NearestFilter,
type: HalfFloatType,
depthTexture: depthTexture,
depthBuffer: true
} );
Expand All @@ -184,7 +185,8 @@ class SSRPass extends Pass {

this.metalnessRenderTarget = new WebGLRenderTarget( this.width, this.height, {
minFilter: NearestFilter,
magFilter: NearestFilter
magFilter: NearestFilter,
type: HalfFloatType,
} );


Expand Down
3 changes: 2 additions & 1 deletion examples/jsm/postprocessing/SavePass.js
@@ -1,4 +1,5 @@
import {
HalfFloatType,
ShaderMaterial,
UniformsUtils,
WebGLRenderTarget
Expand Down Expand Up @@ -30,7 +31,7 @@ class SavePass extends Pass {

if ( this.renderTarget === undefined ) {

this.renderTarget = new WebGLRenderTarget(); // will be resized later
this.renderTarget = new WebGLRenderTarget( 1, 1, { type: HalfFloatType } ); // will be resized later
this.renderTarget.texture.name = 'SavePass.rt';

}
Expand Down
5 changes: 3 additions & 2 deletions examples/jsm/postprocessing/TAARenderPass.js
@@ -1,4 +1,5 @@
import {
HalfFloatType,
WebGLRenderTarget
} from 'three';
import { SSAARenderPass } from './SSAARenderPass.js';
Expand Down Expand Up @@ -41,14 +42,14 @@ class TAARenderPass extends SSAARenderPass {

if ( this.sampleRenderTarget === undefined ) {

this.sampleRenderTarget = new WebGLRenderTarget( readBuffer.width, readBuffer.height, this.params );
this.sampleRenderTarget = new WebGLRenderTarget( readBuffer.width, readBuffer.height, { type: HalfFloatType } );
this.sampleRenderTarget.texture.name = 'TAARenderPass.sample';

}

if ( this.holdRenderTarget === undefined ) {

this.holdRenderTarget = new WebGLRenderTarget( readBuffer.width, readBuffer.height, this.params );
this.holdRenderTarget = new WebGLRenderTarget( readBuffer.width, readBuffer.height, { type: HalfFloatType } );
this.holdRenderTarget.texture.name = 'TAARenderPass.hold';

}
Expand Down
7 changes: 4 additions & 3 deletions examples/jsm/postprocessing/UnrealBloomPass.js
@@ -1,6 +1,7 @@
import {
AdditiveBlending,
Color,
HalfFloatType,
MeshBasicMaterial,
ShaderMaterial,
UniformsUtils,
Expand Down Expand Up @@ -42,20 +43,20 @@ class UnrealBloomPass extends Pass {
let resx = Math.round( this.resolution.x / 2 );
let resy = Math.round( this.resolution.y / 2 );

this.renderTargetBright = new WebGLRenderTarget( resx, resy );
this.renderTargetBright = new WebGLRenderTarget( resx, resy, { type: HalfFloatType } );
this.renderTargetBright.texture.name = 'UnrealBloomPass.bright';
this.renderTargetBright.texture.generateMipmaps = false;

for ( let i = 0; i < this.nMips; i ++ ) {

const renderTargetHorizonal = new WebGLRenderTarget( resx, resy );
const renderTargetHorizonal = new WebGLRenderTarget( resx, resy, { type: HalfFloatType } );

renderTargetHorizonal.texture.name = 'UnrealBloomPass.h' + i;
renderTargetHorizonal.texture.generateMipmaps = false;

this.renderTargetsHorizontal.push( renderTargetHorizonal );

const renderTargetVertical = new WebGLRenderTarget( resx, resy );
const renderTargetVertical = new WebGLRenderTarget( resx, resy, { type: HalfFloatType } );

renderTargetVertical.texture.name = 'UnrealBloomPass.v' + i;
renderTargetVertical.texture.generateMipmaps = false;
Expand Down
Binary file modified examples/screenshots/webgl_materials_video.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_points_dynamic.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_postprocessing.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_postprocessing_rgb_halftone.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_postprocessing_ssaa.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_postprocessing_unreal_bloom.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_shader_lava.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 8 additions & 7 deletions examples/webgl_materials_video.html
Expand Up @@ -44,7 +44,7 @@
import { RenderPass } from 'three/addons/postprocessing/RenderPass.js';
import { ShaderPass } from 'three/addons/postprocessing/ShaderPass.js';
import { BloomPass } from 'three/addons/postprocessing/BloomPass.js';
import { CopyShader } from 'three/addons/shaders/CopyShader.js';
import { GammaCorrectionShader } from 'three/addons/shaders/GammaCorrectionShader.js';

let container;

Expand Down Expand Up @@ -107,6 +107,7 @@
} );

texture = new THREE.VideoTexture( video );
texture.colorSpace = THREE.SRGBColorSpace;

//

Expand Down Expand Up @@ -169,15 +170,15 @@

// postprocessing

const renderModel = new RenderPass( scene, camera );
const effectBloom = new BloomPass( 1.3 );
const effectCopy = new ShaderPass( CopyShader );
const renderPass = new RenderPass( scene, camera );
const bloomPass = new BloomPass( 1.3 );
const outputPass = new ShaderPass( GammaCorrectionShader );

composer = new EffectComposer( renderer );

composer.addPass( renderModel );
composer.addPass( effectBloom );
composer.addPass( effectCopy );
composer.addPass( renderPass );
composer.addPass( bloomPass );
composer.addPass( outputPass );

//

Expand Down
2 changes: 1 addition & 1 deletion examples/webgl_postprocessing_crossfade.html
Expand Up @@ -186,7 +186,7 @@
const mesh = generateInstancedMesh( geometry, material, 500 );
scene.add( mesh );

this.fbo = new THREE.WebGLRenderTarget( window.innerWidth, window.innerHeight );
this.fbo = new THREE.WebGLRenderTarget( window.innerWidth, window.innerHeight, { type: THREE.HalfFloatType } );

this.render = function ( delta, rtt ) {

Expand Down