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@if(TONEMAP_IN_SHADER)
2import bevy_core_pipeline::tonemapping;
3@if(SRGB_OUTPUT)
4import bevy_render::color_operations::linear_to_srgb;
5@if(OKLAB_OUTPUT)
6import bevy_render::color_operations::linear_rgb_to_oklab;
8import bevy_render::{
9 maths::affine3_to_square,
10 view::View,
11};
13import package::render::sprite_view_bindings::view;
15struct VertexInput {
16 @builtin(vertex_index) index: u32,
17 // NOTE: Instance-rate vertex buffer members prefixed with i_
18 /// the first column of a 3x4 matrix that is the transpose of the affine 4x3 model matrix.
19 @location(0) i_model_transpose_col0: vec4<f32>,
20 /// the second column of a 3x4 matrix that is the transpose of the affine 4x3 model matrix.
21 @location(1) i_model_transpose_col1: vec4<f32>,
22 /// the third column of a 3x4 matrix that is the transpose of the affine 4x3 model matrix.
23 @location(2) i_model_transpose_col2: vec4<f32>,
24 @location(3) i_color: vec4<f32>,
25 @location(4) i_uv_offset_scale: vec4<f32>,
28struct VertexOutput {
29 @builtin(position) clip_position: vec4<f32>,
30 @location(0) uv: vec2<f32>,
31 @location(1) @interpolate(flat) color: vec4<f32>,
32};
34@vertex
35fn vertex(in: VertexInput) -> VertexOutput {
36 var out: VertexOutput;
38 let vertex_position = vec3<f32>(
39 f32(in.index & 0x1u),
40 f32((in.index & 0x2u) >> 1u),
41 0.0
42 );
44 out.clip_position = view.clip_from_world * affine3_to_square(mat3x4<f32>(
45 in.i_model_transpose_col0,
46 in.i_model_transpose_col1,
47 in.i_model_transpose_col2,
48 )) * vec4<f32>(vertex_position, 1.0);
49 out.uv = vec2<f32>(vertex_position.xy) * in.i_uv_offset_scale.zw + in.i_uv_offset_scale.xy;
50 out.color = in.i_color;
52 return out;
55@group(1) @binding(0) var sprite_texture: texture_2d<f32>;
56@group(1) @binding(1) var sprite_sampler: sampler;
58@fragment
59fn fragment(in: VertexOutput) -> @location(0) vec4<f32> {
60 var color = in.color * textureSample(sprite_texture, sprite_sampler, in.uv);
62@if(TONEMAP_IN_SHADER)
63 color = tonemapping::tone_mapping(color, view.color_grading);
65@if(SRGB_OUTPUT)
66 color = vec4(linear_to_srgb(color.rgb), color.a);
68@if(OKLAB_OUTPUT)
69 color = vec4(linear_rgb_to_oklab(color.rgb), color.a);
71 return color;
Contents