three.jsdepth-bufferzbuffer

How to write to zbuffer only with three.js


I'm trying to use thee.js to only update the zbuffer (I'm using preserveDrawingBuffer to create a trace effect). However I can't find any way to only write to the zbuffer with the standard materials, so far I've tried:

Is there a 'standard' way of doing this, or do I need to use a custom fragment shader?


Solution

  • You can render to the depth buffer only using the following pattern.

    renderer.context.colorMask( false, false, false, false ); // don't update color buffer
    renderer.render( scene1, camera ); // first scene
    
    renderer.context.colorMask( true, true, true, true );
    renderer.render( scene2, camera ); // second scene
    

    three.js r.71