Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ var files = {
"webgl_points_sprites",
"webgl_postprocessing",
"webgl_postprocessing_advanced",
"webgl_postprocessing_backgrounds",
"webgl_postprocessing_crossfade",
"webgl_postprocessing_dof",
"webgl_postprocessing_dof2",
Expand Down
57 changes: 57 additions & 0 deletions examples/js/postprocessing/CubeTexturePass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* @author bhouston / http://clara.io/
*/

THREE.CubeTexturePass = function ( camera, envMap, opacity ) {

THREE.Pass.call( this );

this.camera = camera;

this.needsSwap = false;

this.cubeShader = THREE.ShaderLib[ 'cube' ];
this.cubeMesh = new THREE.Mesh(
new THREE.BoxBufferGeometry( 10, 10, 10 ),
new THREE.ShaderMaterial( {
uniforms: this.cubeShader.uniforms,
vertexShader: this.cubeShader.vertexShader,
fragmentShader: this.cubeShader.fragmentShader,
depthTest: false,
depthWrite: false,
side: THREE.BackSide
} )
);

this.envMap = envMap;
this.opacity = ( opacity !== undefined ) ? opacity : 1.0;

this.cubeScene = new THREE.Scene();
this.cubeCamera = new THREE.PerspectiveCamera();
this.cubeScene.add( this.cubeMesh );

};

THREE.CubeTexturePass.prototype = Object.assign( Object.create( THREE.Pass.prototype ), {

constructor: THREE.CubeTexturePass,

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

var oldAutoClear = renderer.autoClear;
renderer.autoClear = false;

this.cubeCamera.projectionMatrix.copy( this.camera.projectionMatrix );
this.cubeCamera.quaternion.setFromRotationMatrix( this.camera.matrixWorld );

this.cubeMesh.material.uniforms[ "tCube" ].value = this.envMap;
this.cubeMesh.material.uniforms[ "opacity" ].value = this.opacity;
this.cubeMesh.material.transparent = ( this.opacity < 1.0 );

renderer.render( this.cubeScene, this.cubeCamera, this.renderToScreen ? null : readBuffer, this.clear );

renderer.autoClear = oldAutoClear;

}

} );
5 changes: 4 additions & 1 deletion examples/js/postprocessing/RenderPass.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ THREE.RenderPass.prototype = Object.assign( Object.create( THREE.Pass.prototype

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

var oldAutoClear = renderer.autoClear;
renderer.autoClear = false;

this.scene.overrideMaterial = this.overrideMaterial;

var oldClearColor, oldClearAlpha;
Expand All @@ -47,7 +50,7 @@ THREE.RenderPass.prototype = Object.assign( Object.create( THREE.Pass.prototype
}

this.scene.overrideMaterial = null;

renderer.autoClear = oldAutoClear;
}

} );
22 changes: 16 additions & 6 deletions examples/js/postprocessing/TexturePass.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @author alteredq / http://alteredqualia.com/
*/

THREE.TexturePass = function ( texture, opacity ) {
THREE.TexturePass = function ( map, opacity ) {

THREE.Pass.call( this );

Expand All @@ -11,16 +11,18 @@ THREE.TexturePass = function ( texture, opacity ) {

var shader = THREE.CopyShader;

this.uniforms = THREE.UniformsUtils.clone( shader.uniforms );
this.map = map;
this.opacity = ( opacity !== undefined ) ? opacity : 1.0;

this.uniforms[ "opacity" ].value = ( opacity !== undefined ) ? opacity : 1.0;
this.uniforms[ "tDiffuse" ].value = texture;
this.uniforms = THREE.UniformsUtils.clone( shader.uniforms );

this.material = new THREE.ShaderMaterial( {

uniforms: this.uniforms,
vertexShader: shader.vertexShader,
fragmentShader: shader.fragmentShader
fragmentShader: shader.fragmentShader,
depthTest: false,
depthWrite: false

} );

Expand All @@ -40,10 +42,18 @@ THREE.TexturePass.prototype = Object.assign( Object.create( THREE.Pass.prototype

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

var oldAutoClear = renderer.autoClear;
renderer.autoClear = false;

this.quad.material = this.material;

renderer.render( this.scene, this.camera, readBuffer, this.clear );
this.uniforms[ "opacity" ].value = this.opacity;
this.uniforms[ "tDiffuse" ].value = this.map;
this.material.transparent = ( this.opacity < 1.0 );

renderer.render( this.scene, this.camera, this.renderToScreen ? null : readBuffer, this.clear );

renderer.autoClear = oldAutoClear;
}

} );
Loading