mirror of
https://github.com/bevyengine/bevy.git
synced 2026-07-06 02:23:17 -04:00
681751647a
# Objective - Users often want to run a fullscreen shader but the current solution involves copying the custom_post_processing example which is a 350 line file with a lot of low level wgpu complexity. Users shouldn't have to deal with that just to make a fullscreen shader ## Solution - Introduce a new FullscreenMaterial trait and FullscsreenMaterialPlugin - This new material will run a fullscreen triangle with the specified shader. It builds on top of the existing FullscreenShader infrastructure - It lets user customize the node ordering. There's no defaults right now becausae it's intended as a bit of a primitive plugin. Eventually we could have some kind of default for custom post processing ## Testing Made a new fullscreen_material example and made sure it works ## Follow up Once this is merged there are various things that should be done to improve it. Add the option to bind the depth texture, offer defaults for post processing, use a full AsBindGroup, add a way to bind the gbuffer. --------- Co-authored-by: JMS55 <47158642+JMS55@users.noreply.github.com> Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
51 lines
1.7 KiB
WebGPU Shading Language
51 lines
1.7 KiB
WebGPU Shading Language
// This shader computes the chromatic aberration effect
|
||
|
||
// Since post processing is a fullscreen effect, we use the fullscreen vertex shader provided by bevy.
|
||
// This will import a vertex shader that renders a single fullscreen triangle.
|
||
//
|
||
// A fullscreen triangle is a single triangle that covers the entire screen.
|
||
// The box in the top left in that diagram is the screen. The 4 x are the corner of the screen
|
||
//
|
||
// Y axis
|
||
// 1 | x-----x......
|
||
// 0 | | s | . ´
|
||
// -1 | x_____x´
|
||
// -2 | : .´
|
||
// -3 | :´
|
||
// +--------------- X axis
|
||
// -1 0 1 2 3
|
||
//
|
||
// As you can see, the triangle ends up bigger than the screen.
|
||
//
|
||
// You don't need to worry about this too much since bevy will compute the correct UVs for you.
|
||
#import bevy_core_pipeline::fullscreen_vertex_shader::FullscreenVertexOutput
|
||
|
||
@group(0) @binding(0) var screen_texture: texture_2d<f32>;
|
||
@group(0) @binding(1) var texture_sampler: sampler;
|
||
|
||
struct FullScreenEffect {
|
||
intensity: f32,
|
||
#ifdef SIXTEEN_BYTE_ALIGNMENT
|
||
// WebGL2 structs must be 16 byte aligned.
|
||
_webgl2_padding: vec3<f32>
|
||
#endif
|
||
}
|
||
|
||
@group(0) @binding(2) var<uniform> settings: FullScreenEffect;
|
||
|
||
@fragment
|
||
fn fragment(in: FullscreenVertexOutput) -> @location(0) vec4<f32> {
|
||
// Chromatic aberration strength
|
||
let offset_strength = settings.intensity;
|
||
|
||
// Sample each color channel with an arbitrary shift
|
||
return vec4<f32>(
|
||
textureSample(screen_texture, texture_sampler, in.uv + vec2<f32>(offset_strength, -offset_strength)).r,
|
||
textureSample(screen_texture, texture_sampler, in.uv + vec2<f32>(-offset_strength, 0.0)).g,
|
||
textureSample(screen_texture, texture_sampler, in.uv + vec2<f32>(0.0, offset_strength)).b,
|
||
1.0
|
||
);
|
||
}
|
||
|
||
|