Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update shadowMap size of light in THREE.js

I want to be able to update the size of the shadow map on a directional light in three.js.

When simply updating the the "shadowMapWidth" and "shadowMapHeight", nothing happens. When I update the "shadowMapSize" manually, the shadow sort of changes resolution but is not rendered properly since the shadowmap rendertarget is not set to the correct resolution. And finally, when I update the shadowmap rendertarget width and height, the shadow disappears completely (and or gets positioned incorrectly).

If anyone has any experience changing the shadowmap resolution of a shadow light in three.js I would love some help on getting this to work.


1 Answers

You have to dispose of the shadow map for it to update. Try this:

light.shadowMapWidth = 4096;
light.shadowMapHeight = 4096;
light.shadowMap.dispose();
light.shadowMap = null;
like image 136
Walter Schwarz Avatar answered Jan 06 '26 11:01

Walter Schwarz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!