Render the shadows once for all

孤街醉人 提交于 2019-12-11 02:19:26

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/31275839/render-the-shadows-once-for-all

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!