Sohail Si
Sohail Si

Reputation: 2976

How to dynamically update the resolution of the Shadow Map in THREE.js when changing resolution?

I want to dynamically change the resolution of the shadows of a spotlight in THREE.js. This question first seems relevant but it is not about my issue. I change the parameters of shadowmap dynamically but this is not affecting the scene. Even when I add more mesh objects after this, it does not affect the shadows in the scene/light. When I use an initial value (256,256), it is applied but not after showing the scene.

light.shadowMapWidth = 2048; 
light.shadowMapHeight = 2048;

I tries the following but it didn't work:

light.shadowMap.setSize(100,100)

When I change the light.position, the shadow is updated but the resultion is not updated. It seems to use the .shadowMapWidth property in the beginning during the initialisation only.

Upvotes: 2

Views: 1964

Answers (1)

WestLangley
WestLangley

Reputation: 104833

If you want to dynamically update the resolution of a shadow map, you can use this pattern:

light.shadow.mapSize.width = 1024;
light.shadow.mapSize.height = 1024;
light.shadow.map.dispose(); // important
light.shadow.map = null;

three.js r.74

Upvotes: 3

Related Questions