Skip to content
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

Importing bevy_pbr::mesh_view_types imples defining MAX_DIRECTIONAL_LIGHTS #6799

Closed
torsteingrindvik opened this issue Nov 29, 2022 · 2 comments
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior

Comments

@torsteingrindvik
Copy link
Contributor

Bevy version

Main @ e954b8573

What you did

I did this in a shader:

#import bevy_pbr::mesh_view_types

Because I wanted the definition of the Globals struct to re-use in my own shader.

What went wrong

error: expected constant, found '#'
   ┌─ wgsl:59:49
   │
59 │     directional_lights: array<DirectionalLight, #{MAX_DIRECTIONAL_LIGHTS}u>,
   │                                                 ^ expected constant

Additional information

theories about what might be going wrong

Importing bevy_pbr::mesh_view_types implies that this value is defined.

workarounds that you used

  1. I could redefine the Globals struct, but I would like to not repeat that.
  2. I currently add
shader_defs: vec![ShaderDefVal::Int("MAX_DIRECTIONAL_LIGHTS".to_string(), 1)],

to my code and that works. But this feels like something I should not have to do.

@torsteingrindvik torsteingrindvik added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Nov 29, 2022
@JMS55
Copy link
Contributor

JMS55 commented Dec 1, 2022

This happens because of the Lights struct in mesh_view_types.wgsl. Almost all importers of this file are not actually using the Lights struct. For now, I think we should hard-code MAX_DIRECTIONAL_LIGHTS to always be added to all shader defines. Eventually, this will be fixed by #5703.

@james7132 james7132 added A-Rendering Drawing game state to the screen and removed S-Needs-Triage This issue needs to be labelled labels Dec 4, 2022
bors bot pushed a commit that referenced this issue Jan 30, 2023
# Objective

- Fix `post_processing` and `shader_prepass` examples as they fail when compiling shaders due to missing shader defs
- Fixes #6799
- Fixes #6996
- Fixes #7375 
- Supercedes #6997
- Supercedes #7380 

## Solution

- The prepass was broken due to a missing `MAX_CASCADES_PER_LIGHT` shader def. Add it.
- The shader used in the `post_processing` example is applied to a 2D mesh, so use the correct mesh2d_view_bindings shader import.
bors bot pushed a commit that referenced this issue Jan 30, 2023
# Objective

- Fix `post_processing` and `shader_prepass` examples as they fail when compiling shaders due to missing shader defs
- Fixes #6799
- Fixes #6996
- Fixes #7375 
- Supercedes #6997
- Supercedes #7380 

## Solution

- The prepass was broken due to a missing `MAX_CASCADES_PER_LIGHT` shader def. Add it.
- The shader used in the `post_processing` example is applied to a 2D mesh, so use the correct mesh2d_view_bindings shader import.
bors bot pushed a commit that referenced this issue Jan 30, 2023
# Objective

- Fix `post_processing` and `shader_prepass` examples as they fail when compiling shaders due to missing shader defs
- Fixes #6799
- Fixes #6996
- Fixes #7375 
- Supercedes #6997
- Supercedes #7380 

## Solution

- The prepass was broken due to a missing `MAX_CASCADES_PER_LIGHT` shader def. Add it.
- The shader used in the `post_processing` example is applied to a 2D mesh, so use the correct mesh2d_view_bindings shader import.
bors bot pushed a commit that referenced this issue Jan 30, 2023
# Objective

- Fix `post_processing` and `shader_prepass` examples as they fail when compiling shaders due to missing shader defs
- Fixes #6799
- Fixes #6996
- Fixes #7375 
- Supercedes #6997
- Supercedes #7380 

## Solution

- The prepass was broken due to a missing `MAX_CASCADES_PER_LIGHT` shader def. Add it.
- The shader used in the `post_processing` example is applied to a 2D mesh, so use the correct mesh2d_view_bindings shader import.
bors bot pushed a commit that referenced this issue Jan 30, 2023
# Objective

- Fix `post_processing` and `shader_prepass` examples as they fail when compiling shaders due to missing shader defs
- Fixes #6799
- Fixes #6996
- Fixes #7375 
- Supercedes #6997
- Supercedes #7380 

## Solution

- The prepass was broken due to a missing `MAX_CASCADES_PER_LIGHT` shader def. Add it.
- The shader used in the `post_processing` example is applied to a 2D mesh, so use the correct mesh2d_view_bindings shader import.
@bors bors bot closed this as completed in 8b7ebe1 Jan 30, 2023
ItsDoot pushed a commit to ItsDoot/bevy that referenced this issue Feb 1, 2023
# Objective

- Fix `post_processing` and `shader_prepass` examples as they fail when compiling shaders due to missing shader defs
- Fixes bevyengine#6799
- Fixes bevyengine#6996
- Fixes bevyengine#7375 
- Supercedes bevyengine#6997
- Supercedes bevyengine#7380 

## Solution

- The prepass was broken due to a missing `MAX_CASCADES_PER_LIGHT` shader def. Add it.
- The shader used in the `post_processing` example is applied to a 2D mesh, so use the correct mesh2d_view_bindings shader import.
@torsteingrindvik
Copy link
Contributor Author

As far as I can tell this is still not fixed.
In my custom shader I still want to have struct Globals { ... } defined, so I import mesh_view_types.
That shader expects #{MAX_CASCADES_PER_LIGHT} and #{MAX_DIRECTIONAL_LIGHTS}.

@bors bors bot closed this as completed in 38766fa Feb 11, 2023
myreprise1 pushed a commit to myreprise1/bevy that referenced this issue Feb 14, 2023
)

fixes bevyengine#6799

We should be able to reuse the `Globals` or `View` shader struct definitions from anywhere (including third party plugins) without needing to worry about defining unrelated shader defs.
Also we'd like to refactor these structs to not be repeatedly defined.

Refactor both `Globals` and `View` into separate importable shaders.
Use the imports throughout.

Co-Authored-By: Torstein Grindvik <52322338+torsteingrindvik@users.noreply.github.com>
myreprise1 pushed a commit to myreprise1/bevy that referenced this issue Feb 15, 2023
)

fixes bevyengine#6799

We should be able to reuse the `Globals` or `View` shader struct definitions from anywhere (including third party plugins) without needing to worry about defining unrelated shader defs.
Also we'd like to refactor these structs to not be repeatedly defined.

Refactor both `Globals` and `View` into separate importable shaders.
Use the imports throughout.

Co-Authored-By: Torstein Grindvik <52322338+torsteingrindvik@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior
Projects
None yet
3 participants