在这个简单的测试场景中,我需要将SSAO和FXAA效果组合在一起,但我无法让它工作。启用SSAO后,如果我也启用了FXAA,渲染将变为黑色。
在小提琴中,如果您取消注释composer.addPass(FXAA_effect);
,您将看到问题。我查看了如何一次添加这些效果的不同示例,它们单独工作,但我无法将它们组合在一起。
我错过了什么?
JSFiddle:http://jsfiddle.net/ur3tpwag/
这就是代码:
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000);
camera.position.z = 2;
var geometry = new THREE.BoxGeometry(1, 1, 1);
var material = new THREE.MeshPhongMaterial({ color: 0x1C4A8C });
var cube = new THREE.Mesh(geometry, material);
scene.add(cube);
var light = new THREE.DirectionalLight(0xffffff, 1.0);
light.position.set(0, 0, 1);
scene.add(light);
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// ----------------------------------
// POST PROCESSING
// ----------------------------------
// depth
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;
//
// FXAA
FXAA_effect = new THREE.ShaderPass( THREE.FXAAShader );
FXAA_effect.uniforms['resolution'].value.set(1 / window.innerWidth, 1 / window.innerHeight);
FXAA_effect.renderToScreen = true;
//
// composer
composer = new THREE.EffectComposer( renderer );
composer.addPass( new THREE.RenderPass( scene, camera ) );
//
depthTarget = new THREE.WebGLRenderTarget( window.innerWidth, window.innerHeight, { minFilter: THREE.NearestFilter, magFilter: THREE.NearestFilter, format: THREE.RGBAFormat } );
SSAO_effect = new THREE.ShaderPass( THREE.SSAOShader );
SSAO_effect.uniforms[ 'tDepth' ].value = depthTarget;
SSAO_effect.uniforms[ 'size' ].value.set( window.innerWidth, window.innerHeight );
SSAO_effect.uniforms[ 'cameraNear' ].value = 0.01;
SSAO_effect.uniforms[ 'cameraFar' ].value = 150;
SSAO_effect.uniforms[ 'onlyAO' ].value = false;
SSAO_effect.uniforms[ 'aoClamp' ].value = 0.5;
SSAO_effect.renderToScreen = true;
composer.setSize(window.innerWidth, window.innerHeight);
composer.addPass(FXAA_effect);
composer.addPass(SSAO_effect);
// ----------------------------------
var render = function () {
requestAnimationFrame( render );
cube.rotation.x += 0.01;
cube.rotation.y += 0.01;
scene.overrideMaterial = depthMaterial;
renderer.render( scene, camera, depthTarget, true );
scene.overrideMaterial = null;
composer.render();
};
render();
答案 0 :(得分:2)