-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Honor mesh-light interaction mediation for “low” render layers #15042
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good quality code, a nice example, and clearly explains the limitations in the docs. Just what I was looking for.
The generated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the absolutely fantastic pull request description. As mentioned before, the solution is a bit messy (or special-case-y, rather) but the actual implementation looks great. @alice-i-cecile I don't think this is actually controversial, but I'd like to get SME sign off as Mesh uniform space is at a premium, so there could be opportunity cost.
@@ -20,6 +20,36 @@ pub type Layer = usize; | |||
/// An entity with this component without any layers is invisible. | |||
/// | |||
/// Entities without this component belong to layer `0`. | |||
/// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this might almost be too much documentation relative to the feature but the quality here is really good, if anything we should just expand the docs just above this in another PR so it doesn't feel unbalanced.
@@ -770,7 +797,9 @@ pub fn prepare_lights( | |||
color: Vec4::from_slice(&light.color.to_f32_array()) * light.illuminance, | |||
// direction is negated to be ready for N.L | |||
dir_to_light: light.transform.back().into(), | |||
flags: flags.bits(), | |||
flags: flags.bits() | |||
| (light.render_layers.bits_compact_lossy() as u32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know the code is pretty self evidence but it might be nice to leave a breadcrumb here for future readers (e.g., something like "these aren't flags, but are using the extra space").
Based on this Discord conversation.
Objective
Allow mesh-light interactions to be mediated by (a subset of) render layers, with minimal changes to existing shaders and light/mesh extraction systems.
This addresses the limitation originally described on #10742:
Solution
0
toRenderLayers::MESH_LIGHT_INTERACTION_MAX
) are treated specially, in that they now mediate mesh-light interaction in addition to mesh-camera and light-camera interactionRenderLayers::MESH_LIGHT_INTERACTION_MAX + 1
onwards) retain the current behavior of mediating only light-camera and mesh-camera interactions.bits_compact_lossy()
method is introduced to lossily pack the unlimited render layers into a singleu16
u16
u16
This is a compromise solution that:
Testing
RenderLayers::MESH_LIGHT_INTERACTION_MAX
stays in sync with the return type ofbits_compact_lossy()
render_layers
example so that we can visually validate the effect. (See video below)first_person_view_model
example is unaffected by this changeShowcase
before.mov
after.mov
Migration Guide
RenderLayers
from0
toRenderLayers::MESH_LIGHT_INTERACTION_MAX
now also mediate mesh-light interactions. For many common scenarios, including first person view models, this should not produce any changes in existing behavior. If your scene is affected, and you'd like to retain the old behavior of all lights affecting all meshes, regardless of layers, you can add a layer value ofRenderLayers::MESH_LIGHT_INTERACTION_MAX + 1
or higher to all affected lights/meshes.