与SSAO着色器在场景上的奇怪广场

时间:2013-11-11 12:25:29

标签: three.js ssao

我正在运行以下代码(jsfiddle:http://jsfiddle.net/sx9p7/):

var scene, camera, renderer, composer;
var l1, l2, hemiLight;

var effectSSAO;

init();
animate();

function init() {
    renderer = new THREE.WebGLRenderer( { antialias: false, alpha: false } );

    renderer.shadowMapEnabled = true;

    renderer.setClearColor( 0xd8e7ff );
    renderer.setSize( 800,600);
    document.body.appendChild( renderer.domElement );

    scene = new THREE.Scene();

    camera = new THREE.PerspectiveCamera( 40, 800 / 600, 1, 10000 );
    camera.position.set(-200,100,-60);
    camera.lookAt(new THREE.Vector3(0,0,0));

    var container = document.createElement( 'div' );
    document.body.appendChild( container );

    composer = new THREE.EffectComposer( renderer );
  composer.addPass( new THREE.RenderPass( scene, camera ) );

    effectSSAO = new THREE.ShaderPass( THREE.SSAOShader );
    effectSSAO.renderToScreen = true;
    composer.addPass( effectSSAO ); 

    hemiLight = new THREE.HemisphereLight( 0xffffff, 0xffffff, 0.4 );
    hemiLight.position.set( 0, 300, 0 );
    scene.add( hemiLight );

    l1 = new THREE.DirectionalLight( 0xffffff, 0.3);
    l1.position.set( 100, 100, 0 );
    l1.castShadow = true;
    scene.add(l1);

    l2 = new THREE.DirectionalLight( 0xffffff, 0.3);
    l2.position.set( -100, 100, 0 );
    l2.castShadow = true;
    scene.add(l2);

    var plane = new THREE.Mesh( new THREE.PlaneGeometry( 200, 200), new THREE.MeshLambertMaterial({ }) );
    plane.receiveShadow = true;
    plane.castShadow = true;

    plane.rotation.x = - 90 * Math.PI / 180;
    plane.position.set(0,0,0);
    scene.add( plane );


    var cube = new THREE.Mesh(new THREE.CubeGeometry(50, 50, 50), new THREE.MeshPhongMaterial( { color: 0xaaaaaa, ambient: 0xbbbbbb, specular: 0xcccccc, perPixel: true,  vertexColors: THREE.FaceColors } ));
    cube.receiveShadow = true;
    cube.castShadow = true;
    scene.add(cube);
}

function animate() {
    requestAnimationFrame( animate );
    composer.render();
}

我的SSAO着色器有问题。我确实尝试了很多参数,代码,例子,但我仍然无法删除场景中间的那个方块(有时看起来像SSAO效果正确但位置错误???)

如果我将删除一个方向光片段已经消失 - 但仍然没有SSAO效果和阴影仍然超级非常低的分辨率。

1 个答案:

答案 0 :(得分:1)

嗯,无论如何,2个方向灯都很奇怪,暂时把它保持为1。

关于SSAO,请参阅着色器及其众多参数。你需要根据你的场景调整它们。例如:

effectSSAO .uniforms[ 'tDepth' ].value = depthTarget;
effectSSAO .uniforms[ 'size' ].value.set( width, height );
effectSSAO .uniforms[ 'cameraNear' ].value = 0.1;
effectSSAO .uniforms[ 'cameraFar' ].value = 1000;

如上所述,您还需要进行一些参数调整。 Three.SSAO着色器期望先前渲染的深度传递正常工作。 请点击此处获取更多帮助:

How to use the three.js SSAO shader?