Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/mrdoob/three.js into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
aardgoose committed Jul 6, 2023
2 parents 318076a + 7fa8637 commit cf23772
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 44 deletions.
9 changes: 0 additions & 9 deletions examples/jsm/misc/GPUComputationRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import {
ClampToEdgeWrapping,
DataTexture,
FloatType,
LinearSRGBColorSpace,
Mesh,
NearestFilter,
NoToneMapping,
PlaneGeometry,
RGBAFormat,
Scene,
Expand Down Expand Up @@ -400,23 +398,16 @@ class GPUComputationRenderer {

const currentXrEnabled = renderer.xr.enabled;
const currentShadowAutoUpdate = renderer.shadowMap.autoUpdate;
const currentOutputColorSpace = renderer.outputColorSpace;
const currentToneMapping = renderer.toneMapping;

renderer.xr.enabled = false; // Avoid camera modification
renderer.shadowMap.autoUpdate = false; // Avoid re-computing shadows
renderer.outputColorSpace = LinearSRGBColorSpace;
renderer.toneMapping = NoToneMapping;

mesh.material = material;
renderer.setRenderTarget( output );
renderer.render( scene, camera );
mesh.material = passThruShader;

renderer.xr.enabled = currentXrEnabled;
renderer.shadowMap.autoUpdate = currentShadowAutoUpdate;
renderer.outputColorSpace = currentOutputColorSpace;
renderer.toneMapping = currentToneMapping;

renderer.setRenderTarget( currentRenderTarget );

Expand Down
10 changes: 1 addition & 9 deletions examples/jsm/objects/Reflector.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import {
Vector3,
Vector4,
WebGLRenderTarget,
HalfFloatType,
NoToneMapping,
LinearSRGBColorSpace
HalfFloatType
} from 'three';

class Reflector extends Mesh {
Expand Down Expand Up @@ -147,13 +145,9 @@ class Reflector extends Mesh {

const currentXrEnabled = renderer.xr.enabled;
const currentShadowAutoUpdate = renderer.shadowMap.autoUpdate;
const currentOutputColorSpace = renderer.outputColorSpace;
const currentToneMapping = renderer.toneMapping;

renderer.xr.enabled = false; // Avoid camera modification
renderer.shadowMap.autoUpdate = false; // Avoid re-computing shadows
renderer.outputColorSpace = LinearSRGBColorSpace;
renderer.toneMapping = NoToneMapping;

renderer.setRenderTarget( renderTarget );

Expand All @@ -164,8 +158,6 @@ class Reflector extends Mesh {

renderer.xr.enabled = currentXrEnabled;
renderer.shadowMap.autoUpdate = currentShadowAutoUpdate;
renderer.outputColorSpace = currentOutputColorSpace;
renderer.toneMapping = currentToneMapping;

renderer.setRenderTarget( currentRenderTarget );

Expand Down
8 changes: 0 additions & 8 deletions examples/jsm/objects/Refractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import {
Vector3,
Vector4,
WebGLRenderTarget,
LinearSRGBColorSpace,
NoToneMapping,
HalfFloatType
} from 'three';

Expand Down Expand Up @@ -194,22 +192,16 @@ class Refractor extends Mesh {
const currentRenderTarget = renderer.getRenderTarget();
const currentXrEnabled = renderer.xr.enabled;
const currentShadowAutoUpdate = renderer.shadowMap.autoUpdate;
const currentOutputColorSpace = renderer.outputColorSpace;
const currentToneMapping = renderer.toneMapping;

renderer.xr.enabled = false; // avoid camera modification
renderer.shadowMap.autoUpdate = false; // avoid re-computing shadows
renderer.outputColorSpace = LinearSRGBColorSpace;
renderer.toneMapping = NoToneMapping;

renderer.setRenderTarget( renderTarget );
if ( renderer.autoClear === false ) renderer.clear();
renderer.render( scene, virtualCamera );

renderer.xr.enabled = currentXrEnabled;
renderer.shadowMap.autoUpdate = currentShadowAutoUpdate;
renderer.outputColorSpace = currentOutputColorSpace;
renderer.toneMapping = currentToneMapping;
renderer.setRenderTarget( currentRenderTarget );

// restore viewport
Expand Down
43 changes: 31 additions & 12 deletions examples/jsm/postprocessing/OutputPass.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
import {
RawShaderMaterial,
UniformsUtils,
NoToneMapping,
LinearToneMapping,
ReinhardToneMapping,
CineonToneMapping,
ACESFilmicToneMapping
ACESFilmicToneMapping,
SRGBColorSpace
} from 'three';
import { Pass, FullScreenQuad } from './Pass.js';
import { OutputShader } from '../shaders/OutputShader.js';

class OutputPass extends Pass {

constructor( toneMapping = NoToneMapping, toneMappingExposure = 1 ) {
constructor() {

super();

this.toneMapping = toneMapping;
this.toneMappingExposure = toneMappingExposure;

//

const shader = OutputShader;
Expand All @@ -31,19 +28,41 @@ class OutputPass extends Pass {
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 );

// internal cache

this._outputColorSpace = null;
this._toneMapping = null;

}

render( renderer, writeBuffer, readBuffer/*, deltaTime, maskActive */ ) {

this.uniforms[ 'tDiffuse' ].value = readBuffer.texture;
this.uniforms[ 'toneMappingExposure' ].value = this.toneMappingExposure;
this.uniforms[ 'toneMappingExposure' ].value = renderer.toneMappingExposure;

// rebuild defines if required

if ( this._outputColorSpace !== renderer.outputColorSpace || this._toneMapping !== renderer.toneMapping ) {

this._outputColorSpace = renderer.outputColorSpace;
this._toneMapping = renderer.toneMapping;

this.material.defines = {};

if ( this._outputColorSpace == SRGBColorSpace ) this.material.defines.SRGB_COLOR_SPACE = '';

if ( this._toneMapping === LinearToneMapping ) this.material.defines.LINEAR_TONE_MAPPING = '';
else if ( this._toneMapping === ReinhardToneMapping ) this.material.defines.REINHARD_TONE_MAPPING = '';
else if ( this._toneMapping === CineonToneMapping ) this.material.defines.CINEON_TONE_MAPPING = '';
else if ( this._toneMapping === ACESFilmicToneMapping ) this.material.defines.ACES_FILMIC_TONE_MAPPING = '';

this.material.needsUpdate = true;

}

//

if ( this.renderToScreen === true ) {

Expand Down
6 changes: 5 additions & 1 deletion examples/jsm/shaders/OutputShader.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ const OutputShader = {
// color space
gl_FragColor = LinearTosRGB( gl_FragColor );
#ifdef SRGB_COLOR_SPACE
gl_FragColor = LinearTosRGB( gl_FragColor );
#endif
}`

Expand Down
3 changes: 2 additions & 1 deletion examples/webgl_postprocessing_3dlut.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,14 @@
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.useLegacyLights = false;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
container.appendChild( renderer.domElement );

composer = new EffectComposer( renderer );
composer.setPixelRatio( window.devicePixelRatio );
composer.setSize( window.innerWidth, window.innerHeight );
composer.addPass( new RenderPass( scene, camera ) );
composer.addPass( new OutputPass( THREE.ACESFilmicToneMapping ) );
composer.addPass( new OutputPass() );

lutPass = new LUTPass();
composer.addPass( lutPass );
Expand Down
5 changes: 3 additions & 2 deletions examples/webgl_postprocessing_unreal_bloom.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.toneMapping = THREE.ReinhardToneMapping;
renderer.useLegacyLights = false;
container.appendChild( renderer.domElement );

Expand All @@ -101,7 +102,7 @@
bloomPass.strength = params.strength;
bloomPass.radius = params.radius;

const outputPass = new OutputPass( THREE.ReinhardToneMapping );
const outputPass = new OutputPass();

composer = new EffectComposer( renderer );
composer.addPass( renderScene );
Expand Down Expand Up @@ -148,7 +149,7 @@

toneMappingFolder.add( params, 'exposure', 0.1, 2 ).onChange( function ( value ) {

outputPass.toneMappingExposure = Math.pow( value, 4.0 );
renderer.toneMappingExposure = Math.pow( value, 4.0 );

} );

Expand Down
5 changes: 3 additions & 2 deletions examples/webgl_postprocessing_unreal_bloom_selective.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.useLegacyLights = false;
renderer.toneMapping = THREE.ReinhardToneMapping;
document.body.appendChild( renderer.domElement );

const scene = new THREE.Scene();
Expand Down Expand Up @@ -125,7 +126,7 @@
);
mixPass.needsSwap = true;

const outputPass = new OutputPass( THREE.ReinhardToneMapping );
const outputPass = new OutputPass();

const finalComposer = new EffectComposer( renderer );
finalComposer.addPass( renderScene );
Expand Down Expand Up @@ -167,7 +168,7 @@

toneMappingFolder.add( params, 'exposure', 0.1, 2 ).onChange( function ( value ) {

outputPass.toneMappingExposure = Math.pow( value, 4.0 );
renderer.toneMappingExposure = Math.pow( value, 4.0 );
render();

} );
Expand Down

0 comments on commit cf23772

Please sign in to comment.