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

Three.js r88 integration #160

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ module.exports = function(grunt)
//The same array excluding FORGE.js for jshint
var sourceFilesForJSHint = sourceFiles.slice(1);

var threeVersion = "86";
var threeVersion = "88";

var customThree =
[
Expand Down
34 changes: 30 additions & 4 deletions lib/three.js/postprocessing/AdaptiveToneMappingPass.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ THREE.AdaptiveToneMappingPass = function ( adaptive, resolution ) {
uniforms: {
"lastLum": { value: null },
"currentLum": { value: null },
"minLuminance": { value: 0.01 },
"delta": { value: 0.016 },
"tau": { value: 1.0 }
},
Expand All @@ -72,6 +73,7 @@ THREE.AdaptiveToneMappingPass = function ( adaptive, resolution ) {

"uniform sampler2D lastLum;",
"uniform sampler2D currentLum;",
"uniform float minLuminance;",
"uniform float delta;",
"uniform float tau;",

Expand All @@ -80,8 +82,8 @@ THREE.AdaptiveToneMappingPass = function ( adaptive, resolution ) {
"vec4 lastLum = texture2D( lastLum, vUv, MIP_LEVEL_1X1 );",
"vec4 currentLum = texture2D( currentLum, vUv, MIP_LEVEL_1X1 );",

"float fLastLum = lastLum.r;",
"float fCurrentLum = currentLum.r;",
"float fLastLum = max( minLuminance, lastLum.r );",
"float fCurrentLum = max( minLuminance, currentLum.r );",

//The adaption seems to work better in extreme lighting differences
//if the input luminance is squared.
Expand All @@ -90,7 +92,7 @@ THREE.AdaptiveToneMappingPass = function ( adaptive, resolution ) {
// Adapt the luminance using Pattanaik's technique
"float fAdaptedLum = fLastLum + (fCurrentLum - fLastLum) * (1.0 - exp(-delta * tau));",
// "fAdaptedLum = sqrt(fAdaptedLum);",
"gl_FragColor = vec4( vec3( fAdaptedLum ), 1.0 );",
"gl_FragColor.r = fAdaptedLum;",
"}"
].join( '\n' )
};
Expand Down Expand Up @@ -119,6 +121,7 @@ THREE.AdaptiveToneMappingPass = function ( adaptive, resolution ) {
this.scene = new THREE.Scene();

this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
this.quad.frustumCulled = false; // Avoid getting clipped
this.scene.add( this.quad );

};
Expand Down Expand Up @@ -164,7 +167,16 @@ THREE.AdaptiveToneMappingPass.prototype = Object.assign( Object.create( THREE.Pa

this.quad.material = this.materialToneMap;
this.materialToneMap.uniforms.tDiffuse.value = readBuffer.texture;
renderer.render( this.scene, this.camera, writeBuffer, this.clear );

if ( this.renderToScreen ) {

renderer.render( this.scene, this.camera );

} else {

renderer.render( this.scene, this.camera, writeBuffer, this.clear );

}

},

Expand All @@ -190,14 +202,17 @@ THREE.AdaptiveToneMappingPass.prototype = Object.assign( Object.create( THREE.Pa
var pars = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBAFormat }; // was RGB format. changed to RGBA format. see discussion in #8415 / #8450

this.luminanceRT = new THREE.WebGLRenderTarget( this.resolution, this.resolution, pars );
this.luminanceRT.texture.name = "AdaptiveToneMappingPass.l";
this.luminanceRT.texture.generateMipmaps = false;

this.previousLuminanceRT = new THREE.WebGLRenderTarget( this.resolution, this.resolution, pars );
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
pars.minFilter = THREE.LinearMipMapLinearFilter;
this.currentLuminanceRT = new THREE.WebGLRenderTarget( this.resolution, this.resolution, pars );
this.currentLuminanceRT.texture.name = "AdaptiveToneMappingPass.cl";

if ( this.adaptive ) {

Expand Down Expand Up @@ -245,6 +260,17 @@ THREE.AdaptiveToneMappingPass.prototype = Object.assign( Object.create( THREE.Pa

},

setMinLuminance: function( minLum ) {

if ( minLum ) {

this.materialToneMap.uniforms.minLuminance.value = minLum;
this.materialAdaptiveLum.uniforms.minLuminance.value = minLum;

}

},

setMaxLuminance: function( maxLum ) {

if ( maxLum ) {
Expand Down
3 changes: 3 additions & 0 deletions lib/three.js/postprocessing/BloomPass.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ THREE.BloomPass = function ( strength, kernelSize, sigma, resolution ) {
var pars = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBAFormat };

this.renderTargetX = new THREE.WebGLRenderTarget( resolution, resolution, pars );
this.renderTargetX.texture.name = "BloomPass.x";
this.renderTargetY = new THREE.WebGLRenderTarget( resolution, resolution, pars );
this.renderTargetY.texture.name = "BloomPass.y";

// copy material

Expand Down Expand Up @@ -69,6 +71,7 @@ THREE.BloomPass = function ( strength, kernelSize, sigma, resolution ) {
this.scene = new THREE.Scene();

this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
this.quad.frustumCulled = false; // Avoid getting clipped
this.scene.add( this.quad );

};
Expand Down
25 changes: 24 additions & 1 deletion lib/three.js/postprocessing/BokehPass.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ THREE.BokehPass = function ( scene, camera, params ) {
magFilter: THREE.LinearFilter,
format: THREE.RGBFormat
} );
this.renderTargetColor.texture.name = "BokehPass.color";

this.renderTargetDepth = this.renderTargetColor.clone();
this.renderTargetDepth.texture.name = "BokehPass.depth";

// depth material

this.materialDepth = new THREE.MeshDepthMaterial();
this.materialDepth.depthPacking = THREE.RGBADepthPacking;
this.materialDepth.blending = THREE.NoBlending;

// bokeh material

Expand All @@ -49,8 +53,11 @@ THREE.BokehPass = function ( scene, camera, params ) {
bokehUniforms[ "aspect" ].value = aspect;
bokehUniforms[ "aperture" ].value = aperture;
bokehUniforms[ "maxblur" ].value = maxblur;
bokehUniforms[ "nearClip" ].value = camera.near;
bokehUniforms[ "farClip" ].value = camera.far;

this.materialBokeh = new THREE.ShaderMaterial( {
defines: bokehShader.defines,
uniforms: bokehUniforms,
vertexShader: bokehShader.vertexShader,
fragmentShader: bokehShader.fragmentShader
Expand All @@ -63,8 +70,12 @@ THREE.BokehPass = function ( scene, camera, params ) {
this.scene2 = new THREE.Scene();

this.quad2 = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
this.quad2.frustumCulled = false; // Avoid getting clipped
this.scene2.add( this.quad2 );

this.oldClearColor = new THREE.Color();
this.oldClearAlpha = 1;

};

THREE.BokehPass.prototype = Object.assign( Object.create( THREE.Pass.prototype ), {
Expand All @@ -79,11 +90,20 @@ THREE.BokehPass.prototype = Object.assign( Object.create( THREE.Pass.prototype )

this.scene.overrideMaterial = this.materialDepth;

this.oldClearColor.copy( renderer.getClearColor() );
this.oldClearAlpha = renderer.getClearAlpha();
var oldAutoClear = renderer.autoClear;
renderer.autoClear = false;

renderer.setClearColor( 0xffffff );
renderer.setClearAlpha( 1.0 );
renderer.render( this.scene, this.camera, this.renderTargetDepth, true );

// Render bokeh composite

this.uniforms[ "tColor" ].value = readBuffer.texture;
this.uniforms[ "nearClip" ].value = this.camera.near;
this.uniforms[ "farClip" ].value = this.camera.far;

if ( this.renderToScreen ) {

Expand All @@ -96,7 +116,10 @@ THREE.BokehPass.prototype = Object.assign( Object.create( THREE.Pass.prototype )
}

this.scene.overrideMaterial = null;

renderer.setClearColor( this.oldClearColor );
renderer.setClearAlpha( this.oldClearAlpha );
renderer.autoClear = this.oldAutoClear;

}

} );
1 change: 1 addition & 0 deletions lib/three.js/postprocessing/DotScreenPass.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ THREE.DotScreenPass = function ( center, angle, scale ) {
this.scene = new THREE.Scene();

this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
this.quad.frustumCulled = false; // Avoid getting clipped
this.scene.add( this.quad );

};
Expand Down
26 changes: 20 additions & 6 deletions lib/three.js/postprocessing/EffectComposer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,35 @@ THREE.EffectComposer = function ( renderer, renderTarget ) {
format: THREE.RGBAFormat,
stencilBuffer: false
};
var size = renderer.getSize();

var size = renderer.getDrawingBufferSize();
renderTarget = new THREE.WebGLRenderTarget( size.width, size.height, parameters );
renderTarget.texture.name = 'EffectComposer.rt1';

}

this.renderTarget1 = renderTarget;
this.renderTarget2 = renderTarget.clone();
this.renderTarget2.texture.name = 'EffectComposer.rt2';

this.writeBuffer = this.renderTarget1;
this.readBuffer = this.renderTarget2;

this.passes = [];

if ( THREE.CopyShader === undefined )
console.error( "THREE.EffectComposer relies on THREE.CopyShader" );
// dependencies

if ( THREE.CopyShader === undefined ) {

console.error( 'THREE.EffectComposer relies on THREE.CopyShader' );

}

if ( THREE.ShaderPass === undefined ) {

console.error( 'THREE.EffectComposer relies on THREE.ShaderPass' );

}

this.copyPass = new THREE.ShaderPass( THREE.CopyShader );

Expand All @@ -48,7 +62,7 @@ Object.assign( THREE.EffectComposer.prototype, {

this.passes.push( pass );

var size = this.renderer.getSize();
var size = this.renderer.getDrawingBufferSize();
pass.setSize( size.width, size.height );

},
Expand Down Expand Up @@ -113,7 +127,7 @@ Object.assign( THREE.EffectComposer.prototype, {

if ( renderTarget === undefined ) {

var size = this.renderer.getSize();
var size = this.renderer.getDrawingBufferSize();

renderTarget = this.renderTarget1.clone();
renderTarget.setSize( size.width, size.height );
Expand Down Expand Up @@ -168,7 +182,7 @@ Object.assign( THREE.Pass.prototype, {

render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {

console.error( "THREE.Pass: .render() must be implemented in derived pass." );
console.error( 'THREE.Pass: .render() must be implemented in derived pass.' );

}

Expand Down
1 change: 1 addition & 0 deletions lib/three.js/postprocessing/FilmPass.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ THREE.FilmPass = function ( noiseIntensity, scanlinesIntensity, scanlinesCount,
this.scene = new THREE.Scene();

this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
this.quad.frustumCulled = false; // Avoid getting clipped
this.scene.add( this.quad );

};
Expand Down
1 change: 1 addition & 0 deletions lib/three.js/postprocessing/GlitchPass.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ THREE.GlitchPass = function ( dt_size ) {
this.scene = new THREE.Scene();

this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
this.quad.frustumCulled = false; // Avoid getting clipped
this.scene.add( this.quad );

this.goWild = false;
Expand Down
15 changes: 14 additions & 1 deletion lib/three.js/postprocessing/OutlinePass.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ THREE.OutlinePass = function ( resolution, scene, camera, selectedObjects ) {
this.maskBufferMaterial = new THREE.MeshBasicMaterial( { color: 0xffffff } );
this.maskBufferMaterial.side = THREE.DoubleSide;
this.renderTargetMaskBuffer = new THREE.WebGLRenderTarget( this.resolution.x, this.resolution.y, pars );
this.renderTargetMaskBuffer.texture.name = "OutlinePass.mask";
this.renderTargetMaskBuffer.texture.generateMipmaps = false;

this.depthMaterial = new THREE.MeshDepthMaterial();
Expand All @@ -39,20 +40,26 @@ THREE.OutlinePass = function ( resolution, scene, camera, selectedObjects ) {
this.prepareMaskMaterial.side = THREE.DoubleSide;

this.renderTargetDepthBuffer = new THREE.WebGLRenderTarget( this.resolution.x, this.resolution.y, pars );
this.renderTargetDepthBuffer.texture.name = "OutlinePass.depth";
this.renderTargetDepthBuffer.texture.generateMipmaps = false;

this.renderTargetMaskDownSampleBuffer = new THREE.WebGLRenderTarget( resx, resy, pars );
this.renderTargetMaskDownSampleBuffer.texture.name = "OutlinePass.depthDownSample";
this.renderTargetMaskDownSampleBuffer.texture.generateMipmaps = false;

this.renderTargetBlurBuffer1 = new THREE.WebGLRenderTarget( resx, resy, pars );
this.renderTargetBlurBuffer1.texture.name = "OutlinePass.blur1";
this.renderTargetBlurBuffer1.texture.generateMipmaps = false;
this.renderTargetBlurBuffer2 = new THREE.WebGLRenderTarget( Math.round( resx / 2 ), Math.round( resy / 2 ), pars );
this.renderTargetBlurBuffer2.texture.name = "OutlinePass.blur2";
this.renderTargetBlurBuffer2.texture.generateMipmaps = false;

this.edgeDetectionMaterial = this.getEdgeDetectionMaterial();
this.renderTargetEdgeBuffer1 = new THREE.WebGLRenderTarget( resx, resy, pars );
this.renderTargetEdgeBuffer1.texture.name = "OutlinePass.edge1";
this.renderTargetEdgeBuffer1.texture.generateMipmaps = false;
this.renderTargetEdgeBuffer2 = new THREE.WebGLRenderTarget( Math.round( resx / 2 ), Math.round( resy / 2 ), pars );
this.renderTargetEdgeBuffer2.texture.name = "OutlinePass.edge2";
this.renderTargetEdgeBuffer2.texture.generateMipmaps = false;

var MAX_EDGE_THICKNESS = 4;
Expand Down Expand Up @@ -97,6 +104,7 @@ THREE.OutlinePass = function ( resolution, scene, camera, selectedObjects ) {
this.scene = new THREE.Scene();

this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
this.quad.frustumCulled = false; // Avoid getting clipped
this.scene.add( this.quad );

this.tempPulseColor1 = new THREE.Color();
Expand Down Expand Up @@ -178,7 +186,7 @@ THREE.OutlinePass.prototype = Object.assign( Object.create( THREE.Pass.prototype

function VisibilityChangeCallBack( object ) {

if ( object instanceof THREE.Mesh ) {
if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Sprite ) {

var bFound = false;

Expand Down Expand Up @@ -241,6 +249,9 @@ THREE.OutlinePass.prototype = Object.assign( Object.create( THREE.Pass.prototype
// Make selected objects invisible
this.changeVisibilityOfSelectedObjects( false );

var currentBackground = this.renderScene.background;
this.renderScene.background = null;

// 1. Draw Non Selected objects in the depth buffer
this.renderScene.overrideMaterial = this.depthMaterial;
renderer.render( this.renderScene, this.renderCamera, this.renderTargetDepthBuffer, true );
Expand All @@ -261,6 +272,8 @@ THREE.OutlinePass.prototype = Object.assign( Object.create( THREE.Pass.prototype
this.renderScene.overrideMaterial = null;
this.changeVisibilityOfNonSelectedObjects( true );

this.renderScene.background = currentBackground;

// 2. Downsample to Half resolution
this.quad.material = this.materialCopy;
this.copyUniforms[ "tDiffuse" ].value = this.renderTargetMaskBuffer.texture;
Expand Down
Loading