I'm trying to add a SSAO shader pass to the an earlier fiddle which was the result of: EffectComposer second pass "overwrites" first pass
Unfortunately I get a black screen I created a new fiddle which I will update with my findings:
Creating the depthshader and the target for the depth shader to render onto:
var depthShader = THREE.ShaderLib[ "depthRGBA" ];
var depthUniforms = THREE.UniformsUtils.clone( depthShader.uniforms );
depthMaterial = new THREE.ShaderMaterial( { fragmentShader: depthShader.fragmentShader, vertexShader: depthShader.vertexShader, uniforms: depthUniforms } );
depthMaterial.blending = THREE.NoBlending;
depthTarget = new THREE.WebGLRenderTarget( window.innerWidth, window.innerHeight, { minFilter: THREE.NearestFilter, magFilter: THREE.NearestFilter, format: THREE.RGBAFormat } );
Creating the SSAO shader pas and adding it to the composer
var effect = new THREE.ShaderPass( THREE.SSAOShader );
effect.uniforms[ 'tDepth' ].value = depthTarget;
effect.uniforms[ 'size' ].value.set( window.innerWidth, window.innerHeight );
effect.uniforms[ 'cameraNear' ].value = camera.near;
effect.uniforms[ 'cameraFar' ].value = camera.far;
effect.renderToScreen = true;
composer.addPass( effect );
The render loop rendering the scene with the override material set first befor the composer is rendered
requestAnimationFrame( animate );
//renderer.clear(); // changed -------------
scene.overrideMaterial = depthMaterial;
renderer.render( scene, camera, depthTarget );
scene.overrideMaterial = null;
composer.render();
A side question which came up is would you be able to add the rendering of the scene with the depth target to the composer too?
Reason for this question is that the rendertarget is different and a override material is to be set. I couldnt find any way do do this, does it even sound reasonable to do this or am i miss using the effect composer here?
Found out that the SSAO is partially working if i set effect.uniforms[ 'onlyAO' ].value = 1;
then you can see it working but setting it to 0 results in a black screen. Looking at the code of the EffectComposer now to see what is happening.
Hopefully someone can help me out once again.
Like I said I'll update this post and the fiddle with my attempts
Interesting links on the subject:
- Pull request to add resize support to SSAO demo https://github.com/mrdoob/three.js/pull/6820
Edits:
- Added some relevant snippets of the code (posting all here would clutter the question)
- Added interesting links
- effect.uniforms[ 'onlyAO' ].value = 1;