Skip to content

examples(shaders/glsl): Update GLSL Shader Example Camera View uniform#15865

Merged
cart merged 2 commits intobevyengine:mainfrom
jakeswenson:docs/shaders/fix-example-glsl-shader-view-uniform
Oct 19, 2024
Merged

examples(shaders/glsl): Update GLSL Shader Example Camera View uniform#15865
cart merged 2 commits intobevyengine:mainfrom
jakeswenson:docs/shaders/fix-example-glsl-shader-view-uniform

Conversation

@jakeswenson
Copy link
Copy Markdown
Contributor

@jakeswenson jakeswenson commented Oct 12, 2024

Objective

The Custom Material GLSL shader example has an old version of the camera view uniform structure.
This PR updates the example GLSL custom material shader to have the latest structure.

Solution

I was running into issues using the camera world position (it wasn't changing) and someone in discord pointed me to the source of truth.
crates/bevy_render/src/view/view.wgsl

After using this latest uniform structure in my project I'm now able to work with the camera position in my shader.

Testing

I tested this change by running the example with:

cargo run --features shader_format_glsl --example shader_material_glsl
image

@github-actions
Copy link
Copy Markdown
Contributor

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

@alice-i-cecile alice-i-cecile added this to the 0.15 milestone Oct 12, 2024
@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen C-Examples An addition or correction to our examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Oct 12, 2024
Copy link
Copy Markdown
Member

@tychedelia tychedelia left a comment

Choose a reason for hiding this comment

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

Thanks!

@jakeswenson jakeswenson force-pushed the docs/shaders/fix-example-glsl-shader-view-uniform branch from e83ebc1 to e4f2393 Compare October 13, 2024 17:03
The Custom Material GLSL shader example had what seemed to be an old
version of the camera view uniform.

I was running into issues using camera world position
and someone in discord pointed me to the source of truth.
  crates/bevy_render/src/view/view.wgsl

Since this was helpful to me I've updated the shader example
to have the latest view uniform structure converted to GLSL.

I tested it with:
```bash
cargo run --features shader_format_glsl --example shader_material_glsl
```
@jakeswenson jakeswenson force-pushed the docs/shaders/fix-example-glsl-shader-view-uniform branch from e4f2393 to 3fa4092 Compare October 15, 2024 00:09
@BorisBoutillier
Copy link
Copy Markdown
Contributor

I wonder if it would be better to just have the clip_from_world first attribute described and after a comment like // Other attributes exist and can be described here, see full definition in: crates/bevy_render/src/view/view.wgsl
Because here you describe 11 of the 13 attributes, so it could feel like everything is here, while it is not.
I agree we don't want to also describe the full ColorGrading, so I think by only going down to the attribute needed in the example clip_from_world with a comment pointing to other attributes and where is the source of truth, will be both be more helpful and easier to maintain.

layout(set = 0, binding = 0) uniform CameraViewProj {
    mat4 clip_from_world;
    // Other attributes exist that can be described here.
    // See full definition in: crates/bevy_render/src/view/view.wgsl
} camera_view;

Copy link
Copy Markdown
Member

@cart cart left a comment

Choose a reason for hiding this comment

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

I made the change specified by @BorisBoutillier and expanded the comment to describe the constraints.

@cart cart enabled auto-merge October 19, 2024 01:00
@cart cart added this pull request to the merge queue Oct 19, 2024
Merged via the queue into bevyengine:main with commit 16b39c2 Oct 19, 2024
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-Examples An addition or correction to our examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants