3dthree.jsrenderershadows

Render the shadows once for all


Given the cost of shadow casting, i was wondering if there is a feature or a possible/experimental way to render a shadowmap only once in three.js (even in webgl), for static objects positionned dynamically (ex: a procedural city). So the result can be used in next frames for static objects, at no cost. The shadow rendering would be done only when something moves.


Solution

  • EDIT

    mrdoobs approved :

    renderer.shadowMap.autoUpdate = false;
    renderer.shadowMap.needsUpdate = true; // when scene changes
    

    Original answer :

    I found my way : i copied the way verticesNeedUpdate works. I added a shadowMapNeedsUpdate = true parameter to the WebGLRenderer. In the render function of the ShadowMapPlugin i check if this paramater is true and set it to false after :

    if( _renderer.shadowMapEnabled===false || _renderer.shadowMapNeedsUpdate===false ) return;
    
    _renderer.shadowMapNeedsUpdate = false

    This way the shadowmap is rendered once at the first rendering, and if the scene requires the realtime shadowmap it has to be precised in the render loop. Otherwise computational power is freed