This is what I got so far, but there’s something still not working properly.
Edited because I solved some problems.
- I create a scene with the space cubic-texture.
- I let the renderer render that texture normally into the screen.
- I create a renderTarget and rtScene containing the stars (just some random points).
- I create a transparent black plane (fadeMesh) to put in front of the camera in the rtScene.
- I create copyPass like this:
var copyPass = new THREE.ShaderPass( THREE.CopyShader );
using the standard CopyShader and a simplified ShaderPass wich I use (so far) without the EffectComposer:
THREE.ShaderPass = function ( shader ) {
THREE.Pass.call( this );
this.textureID = "tDiffuse";
this.uniforms = THREE.UniformsUtils.clone( shader.uniforms );
this.material = new THREE.ShaderMaterial( {
defines: shader.defines || {},
uniforms: this.uniforms,
vertexShader: shader.vertexShader,
fragmentShader: shader.fragmentShader ,
transparent: true
} );
this.material.blending = THREE.CustomBlending;
this.material.blendEquation = THREE.AddEquation;
this.material.blendSrc = THREE.SrcAlphaFactor;
this.material.blendDst = THREE.SrcAlphaFactor;
this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
this.scene = new THREE.Scene();
this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
this.scene.add( this.quad );
};
THREE.ShaderPass.prototype.render = function( renderer, writeBuffer ) {
this.uniforms[ this.textureID ].value = writeBuffer.texture;
this.quad.material = this.material;
renderer.setRenderTarget ( null ) ;
renderer.autoClearColor = false ;
renderer.render( this.scene, this.camera );
};
And the render cycle:
function render() {
// render background to screen
renderer.setRenderTarget(null);
renderer.render(scene, camera);
// fade plane in rtScene
var worldDir = new THREE.Vector3 ( ) ;
camera.getWorldDirection ( worldDir ) ;
worldDir.multiplyScalar ( 0.1 );
fadeMesh.position.addVectors ( camera.position , worldDir ) ;
fadeMesh.rotation.copy ( camera.rotation ) ;
// rendere Stars to renderTarget (with accumulation), same camera
renderer.autoClearColor = false ;
renderer.setRenderTarget ( renderTarget );
renderer.render( rtScene, camera );
// shader Pass copies stars into screen from renderTarget
copyPass.render ( renderer , renderTarget ) ;
// controls
controls.update ( ) ;
requestAnimationFrame(render);
};
Demo 3
I’m not sure if I have to manage the blending operations in the ShaderPass material (that’s what I did) or if I have to manage the blending operations in the CopyShader with GLSL (don’t know how).
More over for some reason half of the stars disappear after a while if the camera doesn’t move … any ideas why ?.
[Edit: solved, I was using renderer.autoClear = false instead of autoClearColor = false].
EDIT: I read your answer again and you said to use two render targets … in order to then blend the two textures in the target buffers … Now I understand that step … [see next update]