-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Examples: Introduce
OutputPass
. (#26102)
* Examples: Introduce `OutputPass`. * Examples: Simplify selective bloom demo. * Examples: Improve GUI in bloom demos.
- Loading branch information
Showing
6 changed files
with
179 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { | ||
ShaderMaterial, | ||
UniformsUtils, | ||
NoToneMapping, | ||
LinearToneMapping, | ||
ReinhardToneMapping, | ||
CineonToneMapping, | ||
ACESFilmicToneMapping | ||
} from 'three'; | ||
import { Pass, FullScreenQuad } from './Pass.js'; | ||
import { OutputShader } from '../shaders/OutputShader.js'; | ||
|
||
class OutputPass extends Pass { | ||
|
||
constructor( toneMapping = NoToneMapping, toneMappingExposure = 1 ) { | ||
|
||
super(); | ||
|
||
this.toneMapping = toneMapping; | ||
this.toneMappingExposure = toneMappingExposure; | ||
|
||
// | ||
|
||
const shader = OutputShader; | ||
|
||
this.uniforms = UniformsUtils.clone( shader.uniforms ); | ||
|
||
this.material = new ShaderMaterial( { | ||
uniforms: this.uniforms, | ||
vertexShader: shader.vertexShader, | ||
fragmentShader: shader.fragmentShader | ||
} ); | ||
|
||
if ( toneMapping === LinearToneMapping ) this.material.defines.LINEAR_TONE_MAPPING = ''; | ||
else if ( toneMapping === ReinhardToneMapping ) this.material.defines.REINHARD_TONE_MAPPING = ''; | ||
else if ( toneMapping === CineonToneMapping ) this.material.defines.CINEON_TONE_MAPPING = ''; | ||
else if ( toneMapping === ACESFilmicToneMapping ) this.material.defines.ACES_FILMIC_TONE_MAPPING = ''; | ||
|
||
this.fsQuad = new FullScreenQuad( this.material ); | ||
|
||
} | ||
|
||
render( renderer, writeBuffer, readBuffer/*, deltaTime, maskActive */ ) { | ||
|
||
this.uniforms[ 'tDiffuse' ].value = readBuffer.texture; | ||
this.uniforms[ 'toneMappingExposure' ].value = this.toneMappingExposure; | ||
|
||
if ( this.renderToScreen === true ) { | ||
|
||
renderer.setRenderTarget( null ); | ||
this.fsQuad.render( renderer ); | ||
|
||
} else { | ||
|
||
renderer.setRenderTarget( writeBuffer ); | ||
if ( this.clear ) renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil ); | ||
this.fsQuad.render( renderer ); | ||
|
||
} | ||
|
||
} | ||
|
||
dispose() { | ||
|
||
this.material.dispose(); | ||
this.fsQuad.dispose(); | ||
|
||
} | ||
|
||
} | ||
|
||
export { OutputPass }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
const OutputShader = { | ||
|
||
uniforms: { | ||
|
||
'tDiffuse': { value: null }, | ||
'toneMappingExposure': { value: 1 } | ||
|
||
}, | ||
|
||
vertexShader: /* glsl */` | ||
varying vec2 vUv; | ||
void main() { | ||
vUv = uv; | ||
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); | ||
}`, | ||
|
||
fragmentShader: /* glsl */` | ||
uniform sampler2D tDiffuse; | ||
#include <tonemapping_pars_fragment> | ||
varying vec2 vUv; | ||
void main() { | ||
gl_FragColor = texture2D( tDiffuse, vUv ); | ||
// tone mapping | ||
#ifdef LINEAR_TONE_MAPPING | ||
gl_FragColor.rgb = LinearToneMapping( gl_FragColor.rgb ); | ||
#elif defined( REINHARD_TONE_MAPPING ) | ||
gl_FragColor.rgb = ReinhardToneMapping( gl_FragColor.rgb ); | ||
#elif defined( CINEON_TONE_MAPPING ) | ||
gl_FragColor.rgb = OptimizedCineonToneMapping( gl_FragColor.rgb ); | ||
#elif defined( ACES_FILMIC_TONE_MAPPING ) | ||
gl_FragColor.rgb = ACESFilmicToneMapping( gl_FragColor.rgb ); | ||
#endif | ||
// color space | ||
gl_FragColor = LinearTosRGB( gl_FragColor ); | ||
}` | ||
|
||
}; | ||
|
||
export { OutputShader }; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-88 Bytes
(99%)
examples/screenshots/webgl_postprocessing_unreal_bloom_selective.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters