Three.js usage with stencil buffer

前端 未结 2 582
后悔当初
后悔当初 2021-01-07 14:48

I can\'t get the following to draw the scene into the shape created as a stencil mask. Instead the code just seems to render the stencil itself as a black object.

ht

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-07 15:30

    Accepted answer don't work on latest threejs. If anyone interested, here's an up-to-date version that works (using r111):

    
            gl.enable(gl.STENCIL_TEST);
            gl.stencilOp(gl.KEEP, gl.KEEP, gl.REPLACE);
    
            //renderer.clear(); <-- works without this too
    
            gl.stencilFunc(gl.ALWAYS, 1, 0xFF);
            gl.stencilMask(0xFF);
            renderer.render(maskScene, camera);
    
            gl.stencilFunc(gl.EQUAL, 1, 0xFF);
            gl.stencilMask(0x00);
    
            renderer.render(scene, camera);
            gl.stencilMask(0xFF);
            gl.disable(gl.STENCIL_TEST);
    

    Also in my case I didn't disable auto-clear and it still works.

提交回复
热议问题