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

In pbr.wgsl screen_space_dither goes out of scope if TONEMAP_IN_SHADER is not defined #7965

Closed
Ababwa opened this issue Mar 8, 2023 · 2 comments · Fixed by #7977
Closed
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior
Milestone

Comments

@Ababwa
Copy link
Contributor

Ababwa commented Mar 8, 2023

Present in the latest version, which is 38a08d9 as of this writing.

In pbr.wgsl, a reference to screen_space_dither is made conditionally on #ifdef DEBAND_DITHER (line 113), but screen_space_dither is brought into scope in pbr_functions.wgsl, by importing bevy_core_pipeline::tonemapping conditionally on #ifdef TONEMAP_IN_SHADER (line 4).

If TONEMAP_IN_SHADER is not defined, but DEBAND_DITHER is, then the reference to screen_space_dither is present, but not defined, and the shader creation fails with this error:

ERROR bevy_render::render_resource::pipeline_cache: failed to create shader module: Validation Error

Caused by:
    In Device::create_shader_module

Shader '' parsing error: no definition in scope for identifier: 'screen_space_dither'
    ┌─ wgsl:830:34
    │
830 │     return vec4<f32>(color.rgb + screen_space_dither(pos.xy), color.a);
    │                                  ^^^^^^^^^^^^^^^^^^^ unknown identifier


    no definition in scope for identifier: 'screen_space_dither'

Either the reference to screen_space_dither in pbr.wgsl should be conditional on #ifdef TONEMAP_IN_SHADER, or the importing of bevy_core_pipeline::tonemapping in pbr_functions.wgsl should be conditional on (#ifdef TONEMAP_IN_SHADER OR #ifdef DEBAND_DITHER). I do not know if such a preprocessor operator exists to be able to do something like: #ifdef TONEMAP_IN_SHADER || DEBAND_DITHER, but such a change would seem to me to be the most correct fix for this issue.

I'm new to this interface and do not know how to add labels. My suggested labels are:
A-Rendering
C-Code-Quality

@Ababwa Ababwa added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Mar 8, 2023
@james7132 james7132 added A-Rendering Drawing game state to the screen and removed S-Needs-Triage This issue needs to be labelled labels Mar 8, 2023
@Ababwa
Copy link
Contributor Author

Ababwa commented Mar 8, 2023

The error shown actually comes from a reference to screen_space_dither in pbr_functions.wgsl on line 275. This reference is also conditional on #ifdef DEBAND_DITHER, and has the same issue as the reference in pbr.wgsl.

@Ababwa
Copy link
Contributor Author

Ababwa commented Mar 8, 2023

The dither function in pbr_functions.wgsl (line 274), which contains a reference to screen_space_dither is never actually called anywhere. This function could be deleted. This may be a separate issue.

@JMS55 JMS55 added this to the 0.10.1 milestone Mar 8, 2023
@Ababwa Ababwa mentioned this issue Mar 8, 2023
@cart cart closed this as completed in 846b748 Mar 27, 2023
mockersf pushed a commit that referenced this issue Mar 27, 2023
- Fixes #7965
- Code quality improvements.
- Removes the unreferenced function `dither` in pbr_functions.wgsl
introduced in 72fbcc7, but made obsolete in c069c54.
- Makes the reference to `screen_space_dither` in pbr.wgsl conditional
on `#ifdef TONEMAP_IN_SHADER`, as the required import is conditional on
the same, as deband dithering can only occur if tonemapping is also
occurring.

---------

Co-authored-by: Carter Anderson <mcanders1@gmail.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
Development

Successfully merging a pull request may close this issue.

3 participants