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.
Asked
Active
Viewed 781 times
3
-
[lightmapping](http://threejs.org/examples/webgl_materials_lightmap.html) – LJᛃ Jul 07 '15 at 23:05
-
@LJ_1102 yep i forgot to precise : for dynamically created scenes, so we can't use a pre-drawed lightmap – Mouloud85 Jul 08 '15 at 04:17
-
[Lightmapping](https://en.wikipedia.org/wiki/Lightmap) does not require a pre-drawn lightmap, after you created your scene you can simply *generate* the lightmap in a webworker. – LJᛃ Jul 08 '15 at 11:17
1 Answers
4
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

Mouloud85
- 3,826
- 5
- 22
- 42