mirror of
https://github.com/bevyengine/bevy
synced 2024-12-01 08:59:11 +00:00
61bad4eb57
# Objective - bump naga_oil to 0.10 - update shader imports to use rusty syntax ## Migration Guide naga_oil 0.10 reworks the import mechanism to support more syntax to make it more rusty, and test for item use before importing to determine which imports are modules and which are items, which allows: - use rust-style imports ``` #import bevy_pbr::{ pbr_functions::{alpha_discard as discard, apply_pbr_lighting}, mesh_bindings, } ``` - import partial paths: ``` #import part::of::path ... path::remainder::function(); ``` which will call to `part::of::path::remainder::function` - use fully qualified paths without importing: ``` // #import bevy_pbr::pbr_functions bevy_pbr::pbr_functions::pbr() ``` - use imported items without qualifying ``` #import bevy_pbr::pbr_functions::pbr // for backwards compatibility the old style is still supported: // #import bevy_pbr::pbr_functions pbr ... pbr() ``` - allows most imported items to end with `_` and numbers (naga_oil#30). still doesn't allow struct members to end with `_` or numbers but it's progress. - the vast majority of existing shader code will work without changes, but will emit "deprecated" warnings for old-style imports. these can be suppressed with the `allow-deprecated` feature. - partly breaks overrides (as far as i'm aware nobody uses these yet) - now overrides will only be applied if the overriding module is added as an additional import in the arguments to `Composer::make_naga_module` or `Composer::add_composable_module`. this is necessary to support determining whether imports are modules or items.
47 lines
1.7 KiB
WebGPU Shading Language
47 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 PostProcessSettings {
|
||
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: PostProcessSettings;
|
||
|
||
@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
|
||
);
|
||
}
|
||
|