2

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:

http://jsfiddle.net/mqt1ng2r/

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:

Edits:

  • Added some relevant snippets of the code (posting all here would clutter the question)
  • Added interesting links
  • effect.uniforms[ 'onlyAO' ].value = 1;
Community
  • 1
  • 1
Raymond
  • 93
  • 7
  • 1
    I nearly tackled this issue please see the next fiddle i had to remove the copy shader pass as the SSAO shader pass does that for you. i added some rotation to the mesh so you can see the effect. but there is still a small issue there a trail is still left over. hard to explain looking at the fiddle run will make it clear http://jsfiddle.net/mqt1ng2r/1/ – Raymond Jul 10 '15 at 13:26

0 Answers0