bevy icon indicating copy to clipboard operation
bevy copied to clipboard

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

Open jakeswenson opened this issue 1 year ago • 2 comments

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

jakeswenson avatar Oct 12 '24 01:10 jakeswenson

Welcome, new contributor!

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

github-actions[bot] avatar Oct 12 '24 01:10 github-actions[bot]

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;

BorisBoutillier avatar Oct 15 '24 08:10 BorisBoutillier