Search across packages, versions, files, declarations, and comments. Use multiple terms to narrow results (AND), and add @vertex, @fragment, or @compute to filter by shader stage.
1#import bevy_sprite::{
2 mesh2d_functions as mesh_functions,
3 mesh2d_vertex_output::VertexOutput,
4 mesh2d_view_bindings::view,
5}
7#ifdef TONEMAP_IN_SHADER
8#import bevy_core_pipeline::tonemapping
9#endif
10#ifdef SRGB_OUTPUT
11#import bevy_render::color_operations::linear_to_srgb
12#endif
13#ifdef OKLAB_OUTPUT
14#import bevy_render::color_operations::linear_rgb_to_oklab
15#endif
17struct Vertex {
18 @builtin(instance_index) instance_index: u32,
19#ifdef VERTEX_POSITIONS
20 @location(0) position: vec3<f32>,
21#endif
22#ifdef VERTEX_NORMALS
23 @location(1) normal: vec3<f32>,
24#endif
25#ifdef VERTEX_UVS
26 @location(2) uv: vec2<f32>,
27#endif
28#ifdef VERTEX_TANGENTS
29 @location(3) tangent: vec4<f32>,
30#endif
31#ifdef VERTEX_COLORS
32 @location(4) color: vec4<f32>,
33#endif
34};
36@vertex
37fn vertex(vertex: Vertex) -> VertexOutput {
38 var out: VertexOutput;
39#ifdef VERTEX_UVS
40 out.uv = vertex.uv;
41#endif
43#ifdef VERTEX_POSITIONS
44 var world_from_local = mesh_functions::get_world_from_local(vertex.instance_index);
45 out.world_position = mesh_functions::mesh2d_position_local_to_world(
46 world_from_local,
47 vec4<f32>(vertex.position, 1.0)
48 );
49 out.position = mesh_functions::mesh2d_position_world_to_clip(out.world_position);
50#endif
52#ifdef VERTEX_NORMALS
53 out.world_normal = mesh_functions::mesh2d_normal_local_to_world(vertex.normal, vertex.instance_index);
54#endif
56#ifdef VERTEX_TANGENTS
57 out.world_tangent = mesh_functions::mesh2d_tangent_local_to_world(
58 world_from_local,
59 vertex.tangent
60 );
61#endif
63#ifdef VERTEX_COLORS
64 out.color = vertex.color;
65#endif
66 return out;
69@fragment
70fn fragment(
71 in: VertexOutput,
72) -> @location(0) vec4<f32> {
73#ifdef VERTEX_COLORS
74 var color = in.color;
75#ifdef TONEMAP_IN_SHADER
76 color = tonemapping::tone_mapping(color, view.color_grading);
77#endif
78#ifdef SRGB_OUTPUT
79 color = vec4(linear_to_srgb(color.rgb), color.a);
80#endif
81#ifdef OKLAB_OUTPUT
82 color = vec4(linear_rgb_to_oklab(color.rgb), color.a);
83#endif
84 return color;
85#else
86 return vec4<f32>(1.0, 0.0, 1.0, 1.0);
87#endif
Contents