1// This shader computes the chromatic aberration effect3// Since post processing is a fullscreen effect, we use the fullscreen vertex shader provided by bevy.4// This will import a vertex shader that renders a single fullscreen triangle.5//6// A fullscreen triangle is a single triangle that covers the entire screen.7// The box in the top left in that diagram is the screen. The 4 x are the corner of the screen8//9// Y axis10// 1 | x-----x......11// 0 | | s | . ´12// -1 | x_____x´13// -2 | : .´14// -3 | :´15// +--------------- X axis16// -1 0 1 2 317//18// As you can see, the triangle ends up bigger than the screen.19//20// You don't need to worry about this too much since bevy will compute the correct UVs for you.21#import bevy_core_pipeline::fullscreen_vertex_shader::FullscreenVertexOutput23@group(0) @binding(0) var screen_texture: texture_2d<f32>;24@group(0) @binding(1) var texture_sampler: sampler;25struct PostProcessSettings {26 intensity: f32,27#ifdef SIXTEEN_BYTE_ALIGNMENT28 // WebGL2 structs must be 16 byte aligned.29 _webgl2_padding: vec3<f32>30#endif31}32@group(0) @binding(2) var<uniform> settings: PostProcessSettings;34@fragment35fn fragment(in: FullscreenVertexOutput) -> @location(0) vec4<f32> {36 // Chromatic aberration strength37 let offset_strength = settings.intensity;39 // Sample each color channel with an arbitrary shift40 return vec4<f32>(41 textureSample(screen_texture, texture_sampler, in.uv + vec2<f32>(offset_strength, -offset_strength)).r,42 textureSample(screen_texture, texture_sampler, in.uv + vec2<f32>(-offset_strength, 0.0)).g,43 textureSample(screen_texture, texture_sampler, in.uv + vec2<f32>(0.0, offset_strength)).b,44 1.045 );46}