mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 15:14:50 +00:00
765bd46c2e
# Objective - Add an example showing a custom post processing effect, done after the first rendering pass. ## Solution - A simple post processing "chromatic aberration" effect. I mixed together examples `3d/render_to_texture`, and `shader/shader_material_screenspace_texture` - Reading a bit how https://github.com/bevyengine/bevy/pull/3430 was done gave me pointers to apply the main pass to the 2d render rather than using a 3d quad. This work might be or not be relevant to https://github.com/bevyengine/bevy/issues/2724 <details> <summary> ⚠️ Click for a video of the render ⚠️ I’ve been told it might hurt the eyes 👀 , maybe we should choose another effect just in case ?</summary> https://user-images.githubusercontent.com/2290685/169138830-a6dc8a9f-8798-44b9-8d9e-449e60614916.mp4 </details> # Request for feedbacks - [ ] Is chromatic aberration effect ok ? (Correct term, not a danger for the eyes ?) I'm open to suggestion to make something different. - [ ] Is the code idiomatic ? I preferred a "main camera -> **new camera with post processing applied to a quad**" approach to emulate minimum modification to existing code wanting to add global post processing. --- ## Changelog - Add a full screen post processing shader example
25 lines
816 B
WebGPU Shading Language
25 lines
816 B
WebGPU Shading Language
#import bevy_pbr::mesh_view_bindings
|
|
|
|
[[group(1), binding(0)]]
|
|
var texture: texture_2d<f32>;
|
|
|
|
[[group(1), binding(1)]]
|
|
var our_sampler: sampler;
|
|
|
|
|
|
[[stage(fragment)]]
|
|
fn fragment([[builtin(position)]] position: vec4<f32>) -> [[location(0)]] vec4<f32> {
|
|
// Get screen position with coordinates from 0 to 1
|
|
let uv = position.xy / vec2<f32>(view.width, view.height);
|
|
let offset_strength = 0.02;
|
|
|
|
// Sample each color channel with an arbitrary shift
|
|
var output_color = vec4<f32>(
|
|
textureSample(texture, our_sampler, uv + vec2<f32>(offset_strength, -offset_strength)).r,
|
|
textureSample(texture, our_sampler, uv + vec2<f32>(-offset_strength, 0.0)).g,
|
|
textureSample(texture, our_sampler, uv + vec2<f32>(0.0, offset_strength)).b,
|
|
1.0
|
|
);
|
|
|
|
return output_color;
|
|
}
|