Only enable shadowMap if an entity uses the shadow component and the shadow system is enabled #5399
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
The shadow system has logic for only enabling once an entity uses shadows. However, this logic is broken since #4040, resulting in
renderer.shadowMap.enabledto always default to true. This means that by default every A-Frame scene renders an empty shadowMap and compiles the materials withUSE_SHADOWMAPdefined.On top of that, while the system would update
renderer.shadowMap.enabledwhen changing the system's enabled property, this alone isn't enough to actually toggle the shadows in Three.js. It's needed for materials to be updated whenevershadowMap.enabledchanges (How to update things).This PR addresses both issues, restoring the original intended behaviour and ensuring enabling and disabling the shadow system on the fly works as well.
Changes proposed:
this.data.enabledfor if the shadow system is enabled andthis.shadowMapEnabledfor if a shadowMap is needed (e.g. an entity uses theshadowcomponent). As a resultrenderer.shadowMap.enabled = this.data.enabled && this.shadowMapEnabledneedsUpdatewhenever the actual value ofrenderer.shadowMap.enabledchanges