最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Three.js - antialiasing, rendering, fxaa - Stack Overflow

programmeradmin2浏览0评论

I have a three.js project with 3d-models, a ground and a grid in it. The 3d-models getting outlined with outlinePass (/?q=outl#webgl_postprocessing_outline).

I am able to move the objects with Transformcontrol (/?q=transf#misc_controls_transform) and i can change my camera position with Orbitcontrols (/?q=orbit#misc_controls_orbit)

The problem: The graphics seem kind of badly rendered, here some screenshots: .jpg

I don't really know which settings i should use here:

    renderer = new THREE.WebGLRenderer();//{ antialias: true } ); With antialiasing or without?
                                 //antialiasing is only needed when not using fxaa, right??
            renderer.setPixelRatio( window.devicePixelRatio );
            renderer.setSize( window.innerWidth, window.innerHeight );
            renderer.gammaOutput = true;
            renderer.physicallyCorrectLights = true;

    camera = new THREE.PerspectiveCamera( 45, container.offsetWidth / container.offsetHeight, 0.001, 1000 );
    camera.addEventListener( 'change', render ); //Is this necessary? Seems like it has no use

FXAA is probably necessary for outlinePass (also in the outlinePass-example linked above).

    poser = new EffectComposer( renderer );

            var renderPass = new RenderPass( scene, camera );
            poser.addPass( renderPass );

            effectFXAA = new ShaderPass( FXAAShader );
            effectFXAA.uniforms[ 'resolution' ].value.set( 1 / window.innerWidth, 1 / window.innerHeight );
            effectFXAA.renderToScreen = true;
            poser.addPass( effectFXAA );   

            orbitControls = new OrbitControls( camera, renderer.domElement );
            orbitControls.update();
            orbitControls.addEventListener( 'change', render );

    function render(){
    renderer.render(scene, camera);
    //poser.render(); // don't know if needed
    }

So i have to say, i have not really a clue how i can solve the rendering issue and which settings i have to set to make the most out of my project. I'm happy for every hint and answers and maybe i can put these answers together and solve the issue.

I have a three.js project with 3d-models, a ground and a grid in it. The 3d-models getting outlined with outlinePass (https://threejs/examples/?q=outl#webgl_postprocessing_outline).

I am able to move the objects with Transformcontrol (https://threejs/examples/?q=transf#misc_controls_transform) and i can change my camera position with Orbitcontrols (https://threejs/examples/?q=orbit#misc_controls_orbit)

The problem: The graphics seem kind of badly rendered, here some screenshots: https://i.sstatic/QxjrZ.jpg

I don't really know which settings i should use here:

    renderer = new THREE.WebGLRenderer();//{ antialias: true } ); With antialiasing or without?
                                 //antialiasing is only needed when not using fxaa, right??
            renderer.setPixelRatio( window.devicePixelRatio );
            renderer.setSize( window.innerWidth, window.innerHeight );
            renderer.gammaOutput = true;
            renderer.physicallyCorrectLights = true;

    camera = new THREE.PerspectiveCamera( 45, container.offsetWidth / container.offsetHeight, 0.001, 1000 );
    camera.addEventListener( 'change', render ); //Is this necessary? Seems like it has no use

FXAA is probably necessary for outlinePass (also in the outlinePass-example linked above).

    poser = new EffectComposer( renderer );

            var renderPass = new RenderPass( scene, camera );
            poser.addPass( renderPass );

            effectFXAA = new ShaderPass( FXAAShader );
            effectFXAA.uniforms[ 'resolution' ].value.set( 1 / window.innerWidth, 1 / window.innerHeight );
            effectFXAA.renderToScreen = true;
            poser.addPass( effectFXAA );   

            orbitControls = new OrbitControls( camera, renderer.domElement );
            orbitControls.update();
            orbitControls.addEventListener( 'change', render );

    function render(){
    renderer.render(scene, camera);
    //poser.render(); // don't know if needed
    }

So i have to say, i have not really a clue how i can solve the rendering issue and which settings i have to set to make the most out of my project. I'm happy for every hint and answers and maybe i can put these answers together and solve the issue.

Share Improve this question asked Oct 17, 2019 at 10:19 derseitzerderseitzer 1591 silver badge9 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

When using post-processing with WebGL 1, you have to use FXAA for antialiasing. Passing { antialias: true } to true when creating WebGLRenderer activates MSAA but only if you render to the default framebuffer (directly to screen).

In any event, you configure the FXAA pass like so:

effectFXAA = new ShaderPass( FXAAShader );
effectFXAA.uniforms[ 'resolution' ].value.x = 1 / ( window.innerWidth * pixelRatio );
effectFXAA.uniforms[ 'resolution' ].value.y = 1 / ( window.innerHeight * pixelRatio );
poser.addPass( effectFXAA );   

You have to honor the pixelRatio. Besides, setting renderToScreen to true is not necessary anymore. The last pass in the post-processing chain is automatically rendered to screen now.

When using EffectComposer, you do not call renderer.render(scene, camera);. You have to use poser.render(); instead.

camera.addEventListener( 'change', render ); can also be deleted. I'm not sure where you seen this but it has no effect.

three.js R109

发布评论

评论列表(0)

  1. 暂无评论