bevy/crates/bevy_pbr/src/render
Charles 8073362039 add globals to mesh view bind group (#5409)
# Objective

- It's often really useful to have access to the time when writing shaders.

## Solution

- Add a UnifformBuffer in the mesh view bind group
- This buffer contains the time, delta time and a wrapping frame count

https://user-images.githubusercontent.com/8348954/180130314-97948c2a-2d11-423d-a9c4-fb5c9d1892c7.mp4

---

## Changelog

- Added a `GlobalsUniform` at position 9 of the mesh view bind group

## Notes

The implementation is currently split between bevy_render and bevy_pbr because I was basing my implementation on the `ViewPlugin`. I'm not sure if that's the right way to structure it.

I named this `globals` instead of just time because we could potentially add more things to it.

## References in other engines

- Godot: <https://docs.godotengine.org/en/stable/tutorials/shaders/shader_reference/canvas_item_shader.html#global-built-ins>
    - Global time since startup, in seconds, by default resets to 0 after 3600 seconds
    - Doesn't seem to have anything else
- Unreal: <https://docs.unrealengine.com/4.26/en-US/RenderingAndGraphics/Materials/ExpressionReference/Constant/>
    - Generic time value that updates every frame. Can be paused or scaled.
    - Frame count node, doesn't seem to be an equivalent for shaders: <https://docs.unrealengine.com/4.26/en-US/BlueprintAPI/Utilities/GetFrameCount/>
- Unity: <https://docs.unity3d.com/Manual/SL-UnityShaderVariables.html>
    - time since startup in seconds. No mention of time wrapping. Stored as a `vec4(t/20, t, t*2, t*3)` where `t` is the value in seconds
    - Also has delta time, sin time and cos time
- ShaderToy: <https://www.shadertoy.com/howto>
    - iTime is the time since startup in seconds.
    - iFrameRate
    - iTimeDelta
    - iFrame frame counter

Co-authored-by: Charles <IceSentry@users.noreply.github.com>
2022-09-28 04:20:27 +00:00
..
clustered_forward.wgsl adjust cluster index for viewport origin (#5947) 2022-09-15 21:58:14 +00:00
depth.wgsl update wgpu to 0.13 (#5168) 2022-07-14 21:17:16 +00:00
light.rs Fix some outdated file reference comments in bevy_pbr (#6111) 2022-09-27 17:51:12 +00:00
mesh.rs add globals to mesh view bind group (#5409) 2022-09-28 04:20:27 +00:00
mesh.wgsl update wgpu to 0.13 (#5168) 2022-07-14 21:17:16 +00:00
mesh_bindings.wgsl update wgpu to 0.13 (#5168) 2022-07-14 21:17:16 +00:00
mesh_functions.wgsl bevy_pbr: Fix tangent and normal normalization (#5666) 2022-08-18 21:54:40 +00:00
mesh_types.wgsl bevy_pbr: Fix tangent and normal normalization (#5666) 2022-08-18 21:54:40 +00:00
mesh_vertex_output.wgsl update wgpu to 0.13 (#5168) 2022-07-14 21:17:16 +00:00
mesh_view_bindings.wgsl add globals to mesh view bind group (#5409) 2022-09-28 04:20:27 +00:00
mesh_view_types.wgsl add globals to mesh view bind group (#5409) 2022-09-28 04:20:27 +00:00
mod.rs Materials and MaterialPlugin (#3428) 2021-12-25 21:45:43 +00:00
pbr.wgsl update wgpu to 0.13 (#5168) 2022-07-14 21:17:16 +00:00
pbr_bindings.wgsl update wgpu to 0.13 (#5168) 2022-07-14 21:17:16 +00:00
pbr_functions.wgsl bevy_pbr: Fix tangent and normal normalization (#5666) 2022-08-18 21:54:40 +00:00
pbr_lighting.wgsl update wgpu to 0.13 (#5168) 2022-07-14 21:17:16 +00:00
pbr_types.wgsl update wgpu to 0.13 (#5168) 2022-07-14 21:17:16 +00:00
shadows.wgsl Spotlights (#4715) 2022-07-08 19:57:43 +00:00
skinning.wgsl update wgpu to 0.13 (#5168) 2022-07-14 21:17:16 +00:00
utils.wgsl adjust cluster index for viewport origin (#5947) 2022-09-15 21:58:14 +00:00
wireframe.wgsl update wgpu to 0.13 (#5168) 2022-07-14 21:17:16 +00:00