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
11struct Vertex {
12 @builtin(instance_index) instance_index: u32,
13#ifdef VERTEX_POSITIONS
14 @location(0) position: vec3<f32>,
15#endif
16#ifdef VERTEX_NORMALS
17 @location(1) normal: vec3<f32>,
18#endif
19#ifdef VERTEX_UVS
20 @location(2) uv: vec2<f32>,
21#endif
22#ifdef VERTEX_TANGENTS
23 @location(3) tangent: vec4<f32>,
24#endif
25#ifdef VERTEX_COLORS
26 @location(4) color: vec4<f32>,
27#endif
28};
30@vertex
31fn vertex(vertex: Vertex) -> VertexOutput {
32 var out: VertexOutput;
33#ifdef VERTEX_UVS
34 out.uv = vertex.uv;
35#endif
37#ifdef VERTEX_POSITIONS
38 var world_from_local = mesh_functions::get_world_from_local(vertex.instance_index);
39 out.world_position = mesh_functions::mesh2d_position_local_to_world(
40 world_from_local,
41 vec4<f32>(vertex.position, 1.0)
42 );
43 out.position = mesh_functions::mesh2d_position_world_to_clip(out.world_position);
44#endif
46#ifdef VERTEX_NORMALS
47 out.world_normal = mesh_functions::mesh2d_normal_local_to_world(vertex.normal, vertex.instance_index);
48#endif
50#ifdef VERTEX_TANGENTS
51 out.world_tangent = mesh_functions::mesh2d_tangent_local_to_world(
52 world_from_local,
53 vertex.tangent
54 );
55#endif
57#ifdef VERTEX_COLORS
58 out.color = vertex.color;
59#endif
60 return out;
63@fragment
64fn fragment(
65 in: VertexOutput,
66) -> @location(0) vec4<f32> {
67#ifdef VERTEX_COLORS
68 var color = in.color;
69#ifdef TONEMAP_IN_SHADER
70 color = tonemapping::tone_mapping(color, view.color_grading);
71#endif
72 return color;
73#else
74 return vec4<f32>(1.0, 0.0, 1.0, 1.0);
75#endif
Contents