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.
1import package::mesh2d::{
2 functions as mesh_functions,
3 vertex_output::VertexOutput,
4 view_bindings::view,
5 vertex_input::{Vertex, decompress_vertex}
6};
8@if(TONEMAP_IN_SHADER)
9import bevy_core_pipeline::tonemapping;
10@if(SRGB_OUTPUT)
11import bevy_render::color_operations::linear_to_srgb;
12@if(OKLAB_OUTPUT)
13import bevy_render::color_operations::linear_rgb_to_oklab;
15@vertex
16fn vertex(vertex: Vertex) -> VertexOutput {
17 var out: VertexOutput;
18 let uncompressed_vertex = decompress_vertex(vertex, vertex.instance_index);
19@if(VERTEX_UVS)
20 out.uv = uncompressed_vertex.uv;
22@if(VERTEX_POSITIONS)
23 var world_from_local = mesh_functions::get_world_from_local(vertex.instance_index);
24@if(VERTEX_POSITIONS)
25 out.world_position = mesh_functions::mesh2d_position_local_to_world(
26 world_from_local,
27 vec4<f32>(uncompressed_vertex.position, 1.0)
28 );
29@if(VERTEX_POSITIONS)
30 out.position = mesh_functions::mesh2d_position_world_to_clip(out.world_position);
32@if(VERTEX_NORMALS)
33 out.world_normal = mesh_functions::mesh2d_normal_local_to_world(uncompressed_vertex.normal, vertex.instance_index);
35@if(VERTEX_TANGENTS)
36 out.world_tangent = mesh_functions::mesh2d_tangent_local_to_world(
37 world_from_local,
38 uncompressed_vertex.tangent
39 );
41@if(VERTEX_COLORS)
42 out.color = uncompressed_vertex.color;
44 out.instance_index = vertex.instance_index;
46 return out;
49@fragment
50fn fragment(
51 in: VertexOutput,
52) -> @location(0) vec4<f32> {
53@if(VERTEX_COLORS) {
54 var color = in.color;
55@if(TONEMAP_IN_SHADER)
56 color = tonemapping::tone_mapping(color, view.color_grading);
57@if(SRGB_OUTPUT)
58 color = vec4(linear_to_srgb(color.rgb), color.a);
59@if(OKLAB_OUTPUT)
60 color = vec4(linear_rgb_to_oklab(color.rgb), color.a);
61 return color;
62} @else {
63 return vec4<f32>(1.0, 0.0, 1.0, 1.0);
Contents