سؤال

I'm running following code (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();
}

and i have a problem with SSAO shader. I did try many parameters, codes, examples but still i can't remove that square which is in the middle of scene ( which sometime look like correct SSAO effect but in wrong position ??? )

If i will remove one directional light fragment is gone - but still no SSAO effect and shadows are still super very low resolution.

هل كانت مفيدة؟

المحلول

Well, 2 directional lights are strange anyway, just leave it at 1 for the moment.

Concerning the SSAO, see the shader and its numerous parameters. you would need to adjust those according to your scene. example:

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

As you see above, you also need more than just a few parameter tweaks. The Three.SSAO shader expects a previously rendered depth pass to work properly. See here for more help:

How to use the three.js SSAO shader?

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top