Skip to content

Conversation

@mrxz
Copy link
Contributor

@mrxz mrxz commented Nov 29, 2023

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.enabled to always default to true. This means that by default every A-Frame scene renders an empty shadowMap and compiles the materials with USE_SHADOWMAP defined.

On top of that, while the system would update renderer.shadowMap.enabled when 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 whenever shadowMap.enabled changes (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:

  • Use this.data.enabled for if the shadow system is enabled and this.shadowMapEnabled for if a shadowMap is needed (e.g. an entity uses the shadow component). As a result renderer.shadowMap.enabled = this.data.enabled && this.shadowMapEnabled
  • Mark all materials as needsUpdate whenever the actual value of renderer.shadowMap.enabled changes
  • Update unit tests to reflect the above changes

if (renderer && newEnabledState !== renderer.shadowMap.enabled) {
renderer.shadowMap.enabled = newEnabledState;

// If scene has already rendered, materials must be updated.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this can be factored out to an independent function (example) at the bottom of the file. updateAllMaterials(sceneEl)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@dmarcos
Copy link
Member

dmarcos commented Dec 1, 2023

Thanks so much. You rock 🎸

@dmarcos dmarcos merged commit 78ca91e into aframevr:master Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants