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#ifdef TONEMAP_IN_SHADER
2#import bevy_core_pipeline::tonemapping
3#endif
4#ifdef SRGB_OUTPUT
5#import bevy_render::color_operations::linear_to_srgb
6#endif
7#ifdef OKLAB_OUTPUT
8#import bevy_render::color_operations::linear_rgb_to_oklab
9#endif
11#import bevy_render::{
12 maths::affine3_to_square,
13 view::View,
16#import bevy_sprite::sprite_view_bindings::view
18struct VertexInput {
19 @builtin(vertex_index) index: u32,
20 // NOTE: Instance-rate vertex buffer members prefixed with i_
21 // NOTE: i_model_transpose_colN are the 3 columns of a 3x4 matrix that is the transpose of the
22 // affine 4x3 model matrix.
23 @location(0) i_model_transpose_col0: vec4<f32>,
24 @location(1) i_model_transpose_col1: vec4<f32>,
25 @location(2) i_model_transpose_col2: vec4<f32>,
26 @location(3) i_color: vec4<f32>,
27 @location(4) i_uv_offset_scale: vec4<f32>,
30struct VertexOutput {
31 @builtin(position) clip_position: vec4<f32>,
32 @location(0) uv: vec2<f32>,
33 @location(1) @interpolate(flat) color: vec4<f32>,
34};
36@vertex
37fn vertex(in: VertexInput) -> VertexOutput {
38 var out: VertexOutput;
40 let vertex_position = vec3<f32>(
41 f32(in.index & 0x1u),
42 f32((in.index & 0x2u) >> 1u),
43 0.0
44 );
46 out.clip_position = view.clip_from_world * affine3_to_square(mat3x4<f32>(
47 in.i_model_transpose_col0,
48 in.i_model_transpose_col1,
49 in.i_model_transpose_col2,
50 )) * vec4<f32>(vertex_position, 1.0);
51 out.uv = vec2<f32>(vertex_position.xy) * in.i_uv_offset_scale.zw + in.i_uv_offset_scale.xy;
52 out.color = in.i_color;
54 return out;
57@group(1) @binding(0) var sprite_texture: texture_2d<f32>;
58@group(1) @binding(1) var sprite_sampler: sampler;
60@fragment
61fn fragment(in: VertexOutput) -> @location(0) vec4<f32> {
62 var color = in.color * textureSample(sprite_texture, sprite_sampler, in.uv);
64#ifdef TONEMAP_IN_SHADER
65 color = tonemapping::tone_mapping(color, view.color_grading);
66#endif
68#ifdef SRGB_OUTPUT
69 color = vec4(linear_to_srgb(color.rgb), color.a);
70#endif
72#ifdef OKLAB_OUTPUT
73 color = vec4(linear_rgb_to_oklab(color.rgb), color.a);
74#endif
76 return color;
Contents