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
5#import bevy_render::{
6 maths::affine3_to_square,
7 view::View,
8}
10#import bevy_sprite::sprite_view_bindings::view
12struct VertexInput {
13 @builtin(vertex_index) index: u32,
14 // NOTE: Instance-rate vertex buffer members prefixed with i_
15 // NOTE: i_model_transpose_colN are the 3 columns of a 3x4 matrix that is the transpose of the
16 // affine 4x3 model matrix.
17 @location(0) i_model_transpose_col0: vec4<f32>,
18 @location(1) i_model_transpose_col1: vec4<f32>,
19 @location(2) i_model_transpose_col2: vec4<f32>,
20 @location(3) i_color: vec4<f32>,
21 @location(4) i_uv_offset_scale: vec4<f32>,
24struct VertexOutput {
25 @builtin(position) clip_position: vec4<f32>,
26 @location(0) uv: vec2<f32>,
27 @location(1) @interpolate(flat) color: vec4<f32>,
28};
30@vertex
31fn vertex(in: VertexInput) -> VertexOutput {
32 var out: VertexOutput;
34 let vertex_position = vec3<f32>(
35 f32(in.index & 0x1u),
36 f32((in.index & 0x2u) >> 1u),
37 0.0
38 );
40 out.clip_position = view.clip_from_world * affine3_to_square(mat3x4<f32>(
41 in.i_model_transpose_col0,
42 in.i_model_transpose_col1,
43 in.i_model_transpose_col2,
44 )) * vec4<f32>(vertex_position, 1.0);
45 out.uv = vec2<f32>(vertex_position.xy) * in.i_uv_offset_scale.zw + in.i_uv_offset_scale.xy;
46 out.color = in.i_color;
48 return out;
51@group(1) @binding(0) var sprite_texture: texture_2d<f32>;
52@group(1) @binding(1) var sprite_sampler: sampler;
54@fragment
55fn fragment(in: VertexOutput) -> @location(0) vec4<f32> {
56 var color = in.color * textureSample(sprite_texture, sprite_sampler, in.uv);
58#ifdef TONEMAP_IN_SHADER
59 color = tonemapping::tone_mapping(color, view.color_grading);
60#endif
62 return color;
Contents