Skip to content

Commit

Permalink
Introduce WebGLFXManager.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 committed Jan 23, 2022
1 parent 6c89ee2 commit 88549cf
Show file tree
Hide file tree
Showing 38 changed files with 822 additions and 462 deletions.
432 changes: 255 additions & 177 deletions build/three.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/three.min.js

Large diffs are not rendered by default.

413 changes: 283 additions & 130 deletions build/three.module.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/helpers/ArrowHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ class ArrowHelper extends Object3D {

this.position.copy( origin );

this.line = new Line( _lineGeometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
this.line = new Line( _lineGeometry, new LineBasicMaterial( { color: color } ) );
this.line.matrixAutoUpdate = false;
this.add( this.line );

this.cone = new Mesh( _coneGeometry, new MeshBasicMaterial( { color: color, toneMapped: false } ) );
this.cone = new Mesh( _coneGeometry, new MeshBasicMaterial( { color: color } ) );
this.cone.matrixAutoUpdate = false;
this.add( this.cone );

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/AxesHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class AxesHelper extends LineSegments {
geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );

const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
const material = new LineBasicMaterial( { vertexColors: true } );

super( geometry, material );

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/Box3Helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Box3Helper extends LineSegments {

geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );

super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
super( geometry, new LineBasicMaterial( { color: color } ) );

this.box = box;

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/BoxHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class BoxHelper extends LineSegments {
geometry.setIndex( new BufferAttribute( indices, 1 ) );
geometry.setAttribute( 'position', new BufferAttribute( positions, 3 ) );

super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
super( geometry, new LineBasicMaterial( { color: color } ) );

this.object = object;
this.type = 'BoxHelper';
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/CameraHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CameraHelper extends LineSegments {
constructor( camera ) {

const geometry = new BufferGeometry();
const material = new LineBasicMaterial( { color: 0xffffff, vertexColors: true, toneMapped: false } );
const material = new LineBasicMaterial( { color: 0xffffff, vertexColors: true } );

const vertices = [];
const colors = [];
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/DirectionalLightHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class DirectionalLightHelper extends Object3D {
- size, size, 0
], 3 ) );

const material = new LineBasicMaterial( { fog: false, toneMapped: false } );
const material = new LineBasicMaterial( { fog: false } );

this.lightPlane = new Line( geometry, material );
this.add( this.lightPlane );
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/GridHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class GridHelper extends LineSegments {
geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );

const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
const material = new LineBasicMaterial( { vertexColors: true } );

super( geometry, material );

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/HemisphereLightHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class HemisphereLightHelper extends Object3D {
const geometry = new OctahedronGeometry( size );
geometry.rotateY( Math.PI * 0.5 );

this.material = new MeshBasicMaterial( { wireframe: true, fog: false, toneMapped: false } );
this.material = new MeshBasicMaterial( { wireframe: true, fog: false } );
if ( this.color === undefined ) this.material.vertexColors = true;

const position = geometry.getAttribute( 'position' );
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/PlaneHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class PlaneHelper extends Line {
geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
geometry.computeBoundingSphere();

super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
super( geometry, new LineBasicMaterial( { color: color } ) );

this.type = 'PlaneHelper';

Expand All @@ -32,7 +32,7 @@ class PlaneHelper extends Line {
geometry2.setAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
geometry2.computeBoundingSphere();

this.add( new Mesh( geometry2, new MeshBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false, toneMapped: false } ) ) );
this.add( new Mesh( geometry2, new MeshBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false } ) ) );

}

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/PointLightHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class PointLightHelper extends Mesh {
constructor( light, sphereSize, color ) {

const geometry = new SphereGeometry( sphereSize, 4, 2 );
const material = new MeshBasicMaterial( { wireframe: true, fog: false, toneMapped: false } );
const material = new MeshBasicMaterial( { wireframe: true, fog: false } );

super( geometry, material );

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/PolarGridHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class PolarGridHelper extends LineSegments {
geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );

const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
const material = new LineBasicMaterial( { vertexColors: true } );

super( geometry, material );

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/SkeletonHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class SkeletonHelper extends LineSegments {
geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );

const material = new LineBasicMaterial( { vertexColors: true, depthTest: false, depthWrite: false, toneMapped: false, transparent: true } );
const material = new LineBasicMaterial( { vertexColors: true, depthTest: false, depthWrite: false, transparent: true } );

super( geometry, material );

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/SpotLightHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class SpotLightHelper extends Object3D {

geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );

const material = new LineBasicMaterial( { fog: false, toneMapped: false } );
const material = new LineBasicMaterial( { fog: false } );

this.cone = new LineSegments( geometry, material );
this.add( this.cone );
Expand Down
2 changes: 0 additions & 2 deletions src/loaders/MaterialLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ class MaterialLoader extends Loader {

if ( json.visible !== undefined ) material.visible = json.visible;

if ( json.toneMapped !== undefined ) material.toneMapped = json.toneMapped;

if ( json.userData !== undefined ) material.userData = json.userData;

if ( json.vertexColors !== undefined ) {
Expand Down
6 changes: 0 additions & 6 deletions src/materials/Material.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ class Material extends EventDispatcher {

this.visible = true;

this.toneMapped = true;

this.userData = {};

this.version = 0;
Expand Down Expand Up @@ -350,8 +348,6 @@ class Material extends EventDispatcher {

if ( this.visible === false ) data.visible = false;

if ( this.toneMapped === false ) data.toneMapped = false;

if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;

// TODO: Copied from Object3D.toJSON
Expand Down Expand Up @@ -464,8 +460,6 @@ class Material extends EventDispatcher {

this.visible = source.visible;

this.toneMapped = source.toneMapped;

this.userData = JSON.parse( JSON.stringify( source.userData ) );

return this;
Expand Down
34 changes: 19 additions & 15 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { WebGLClipping } from './webgl/WebGLClipping.js';
import { WebGLCubeMaps } from './webgl/WebGLCubeMaps.js';
import { WebGLCubeUVMaps } from './webgl/WebGLCubeUVMaps.js';
import { WebGLExtensions } from './webgl/WebGLExtensions.js';
import { WebGLFXManager } from './webgl/WebGLFXManager.js';
import { WebGLGeometries } from './webgl/WebGLGeometries.js';
import { WebGLIndexedBufferRenderer } from './webgl/WebGLIndexedBufferRenderer.js';
import { WebGLInfo } from './webgl/WebGLInfo.js';
Expand Down Expand Up @@ -269,7 +270,7 @@ function WebGLRenderer( parameters = {} ) {
let properties, textures, cubemaps, cubeuvmaps, attributes, geometries, objects;
let programCache, materials, renderLists, renderStates, clipping, shadowMap;

let background, morphtargets, bufferRenderer, indexedBufferRenderer;
let background, morphtargets, bufferRenderer, indexedBufferRenderer, fxManager;

let utils, bindingStates;

Expand Down Expand Up @@ -306,6 +307,8 @@ function WebGLRenderer( parameters = {} ) {
bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info, capabilities );
indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, info, capabilities );

fxManager = new WebGLFXManager( _this, extensions, capabilities, _antialias );

info.programs = programCache.programs;

_this.capabilities = capabilities;
Expand Down Expand Up @@ -907,6 +910,15 @@ function WebGLRenderer( parameters = {} ) {

if ( _isContextLost === true ) return;

const renderToScreen = ( _currentRenderTarget === null || _currentRenderTarget.isXRRenderTarget === true );
const needsPostProcessing = ( this.outputEncoding !== LinearEncoding || this.toneMapping !== NoToneMapping );

if ( renderToScreen === true && needsPostProcessing === true ) {

fxManager.prepare();

}

// update scene graph

if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
Expand Down Expand Up @@ -1048,6 +1060,12 @@ function WebGLRenderer( parameters = {} ) {

}

if ( renderToScreen === true && needsPostProcessing === true ) {

fxManager.render();

}

};

function projectObject( object, camera, groupOrder, sortObjects ) {
Expand Down Expand Up @@ -1393,7 +1411,6 @@ function WebGLRenderer( parameters = {} ) {

const materialProperties = properties.get( material );

materialProperties.outputEncoding = parameters.outputEncoding;
materialProperties.instancing = parameters.instancing;
materialProperties.skinning = parameters.skinning;
materialProperties.morphTargets = parameters.morphTargets;
Expand All @@ -1403,7 +1420,6 @@ function WebGLRenderer( parameters = {} ) {
materialProperties.numIntersection = parameters.numClipIntersection;
materialProperties.vertexAlphas = parameters.vertexAlphas;
materialProperties.vertexTangents = parameters.vertexTangents;
materialProperties.toneMapping = parameters.toneMapping;

}

Expand All @@ -1415,14 +1431,12 @@ function WebGLRenderer( parameters = {} ) {

const fog = scene.fog;
const environment = material.isMeshStandardMaterial ? scene.environment : null;
const encoding = ( _currentRenderTarget === null ) ? _this.outputEncoding : ( _currentRenderTarget.isXRRenderTarget === true ? _currentRenderTarget.texture.encoding : LinearEncoding );
const envMap = ( material.isMeshStandardMaterial ? cubeuvmaps : cubemaps ).get( material.envMap || environment );
const vertexAlphas = material.vertexColors === true && !! geometry.attributes.color && geometry.attributes.color.itemSize === 4;
const vertexTangents = !! material.normalMap && !! geometry.attributes.tangent;
const morphTargets = !! geometry.morphAttributes.position;
const morphNormals = !! geometry.morphAttributes.normal;
const morphTargetsCount = !! geometry.morphAttributes.position ? geometry.morphAttributes.position.length : 0;
const toneMapping = material.toneMapped ? _this.toneMapping : NoToneMapping;

const materialProperties = properties.get( material );
const lights = currentRenderState.state.lights;
Expand Down Expand Up @@ -1454,10 +1468,6 @@ function WebGLRenderer( parameters = {} ) {

needsProgramChange = true;

} else if ( materialProperties.outputEncoding !== encoding ) {

needsProgramChange = true;

} else if ( object.isInstancedMesh && materialProperties.instancing === false ) {

needsProgramChange = true;
Expand Down Expand Up @@ -1504,10 +1514,6 @@ function WebGLRenderer( parameters = {} ) {

needsProgramChange = true;

} else if ( materialProperties.toneMapping !== toneMapping ) {

needsProgramChange = true;

} else if ( capabilities.isWebGL2 === true && materialProperties.morphTargetsCount !== morphTargetsCount ) {

needsProgramChange = true;
Expand Down Expand Up @@ -1670,8 +1676,6 @@ function WebGLRenderer( parameters = {} ) {

if ( refreshMaterial ) {

p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );

if ( materialProperties.needsLights ) {

// the current material requires lighting info
Expand Down
4 changes: 0 additions & 4 deletions src/renderers/shaders/ShaderChunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import displacementmap_pars_vertex from './ShaderChunk/displacementmap_pars_vert
import displacementmap_vertex from './ShaderChunk/displacementmap_vertex.glsl.js';
import emissivemap_fragment from './ShaderChunk/emissivemap_fragment.glsl.js';
import emissivemap_pars_fragment from './ShaderChunk/emissivemap_pars_fragment.glsl.js';
import encodings_fragment from './ShaderChunk/encodings_fragment.glsl.js';
import encodings_pars_fragment from './ShaderChunk/encodings_pars_fragment.glsl.js';
import envmap_fragment from './ShaderChunk/envmap_fragment.glsl.js';
import envmap_common_pars_fragment from './ShaderChunk/envmap_common_pars_fragment.glsl.js';
Expand Down Expand Up @@ -89,7 +88,6 @@ import skinning_vertex from './ShaderChunk/skinning_vertex.glsl.js';
import skinnormal_vertex from './ShaderChunk/skinnormal_vertex.glsl.js';
import specularmap_fragment from './ShaderChunk/specularmap_fragment.glsl.js';
import specularmap_pars_fragment from './ShaderChunk/specularmap_pars_fragment.glsl.js';
import tonemapping_fragment from './ShaderChunk/tonemapping_fragment.glsl.js';
import tonemapping_pars_fragment from './ShaderChunk/tonemapping_pars_fragment.glsl.js';
import transmission_fragment from './ShaderChunk/transmission_fragment.glsl.js';
import transmission_pars_fragment from './ShaderChunk/transmission_pars_fragment.glsl.js';
Expand Down Expand Up @@ -144,7 +142,6 @@ export const ShaderChunk = {
displacementmap_vertex: displacementmap_vertex,
emissivemap_fragment: emissivemap_fragment,
emissivemap_pars_fragment: emissivemap_pars_fragment,
encodings_fragment: encodings_fragment,
encodings_pars_fragment: encodings_pars_fragment,
envmap_fragment: envmap_fragment,
envmap_common_pars_fragment: envmap_common_pars_fragment,
Expand Down Expand Up @@ -210,7 +207,6 @@ export const ShaderChunk = {
skinnormal_vertex: skinnormal_vertex,
specularmap_fragment: specularmap_fragment,
specularmap_pars_fragment: specularmap_pars_fragment,
tonemapping_fragment: tonemapping_fragment,
tonemapping_pars_fragment: tonemapping_pars_fragment,
transmission_fragment: transmission_fragment,
transmission_pars_fragment: transmission_pars_fragment,
Expand Down
3 changes: 0 additions & 3 deletions src/renderers/shaders/ShaderChunk/encodings_fragment.glsl.js

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions src/renderers/shaders/ShaderLib/background.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,5 @@ void main() {
gl_FragColor = texture2D( t2D, vUv );
#include <tonemapping_fragment>
#include <encodings_fragment>
}
`;
3 changes: 0 additions & 3 deletions src/renderers/shaders/ShaderLib/cube.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,5 @@ void main() {
gl_FragColor = envColor;
gl_FragColor.a *= opacity;
#include <tonemapping_fragment>
#include <encodings_fragment>
}
`;
3 changes: 0 additions & 3 deletions src/renderers/shaders/ShaderLib/equirect.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,5 @@ void main() {
gl_FragColor = texture2D( tEquirect, sampleUV );
#include <tonemapping_fragment>
#include <encodings_fragment>
}
`;
2 changes: 0 additions & 2 deletions src/renderers/shaders/ShaderLib/linedashed.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ void main() {
outgoingLight = diffuseColor.rgb; // simple shader
#include <output_fragment>
#include <tonemapping_fragment>
#include <encodings_fragment>
#include <fog_fragment>
#include <premultiplied_alpha_fragment>
Expand Down
2 changes: 0 additions & 2 deletions src/renderers/shaders/ShaderLib/meshbasic.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ void main() {
#include <envmap_fragment>
#include <output_fragment>
#include <tonemapping_fragment>
#include <encodings_fragment>
#include <fog_fragment>
#include <premultiplied_alpha_fragment>
#include <dithering_fragment>
Expand Down
2 changes: 0 additions & 2 deletions src/renderers/shaders/ShaderLib/meshlambert.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ void main() {
#include <envmap_fragment>
#include <output_fragment>
#include <tonemapping_fragment>
#include <encodings_fragment>
#include <fog_fragment>
#include <premultiplied_alpha_fragment>
#include <dithering_fragment>
Expand Down
2 changes: 0 additions & 2 deletions src/renderers/shaders/ShaderLib/meshmatcap.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ void main() {
vec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;
#include <output_fragment>
#include <tonemapping_fragment>
#include <encodings_fragment>
#include <fog_fragment>
#include <premultiplied_alpha_fragment>
#include <dithering_fragment>
Expand Down
2 changes: 0 additions & 2 deletions src/renderers/shaders/ShaderLib/meshphong.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ void main() {
#include <envmap_fragment>
#include <output_fragment>
#include <tonemapping_fragment>
#include <encodings_fragment>
#include <fog_fragment>
#include <premultiplied_alpha_fragment>
#include <dithering_fragment>
Expand Down
Loading

0 comments on commit 88549cf

Please sign in to comment.