mirror of
https://github.com/bevyengine/bevy
synced 2024-11-14 00:47:32 +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.
39 lines
1.2 KiB
WebGPU Shading Language
39 lines
1.2 KiB
WebGPU Shading Language
#import bevy_sprite::{
|
|
mesh2d_view_bindings::globals,
|
|
mesh2d_functions::{get_model_matrix, mesh2d_position_local_to_clip},
|
|
}
|
|
|
|
struct Vertex {
|
|
@builtin(instance_index) instance_index: u32,
|
|
@location(0) position: vec3<f32>,
|
|
@location(1) color: vec4<f32>,
|
|
@location(2) barycentric: vec3<f32>,
|
|
};
|
|
|
|
struct VertexOutput {
|
|
@builtin(position) clip_position: vec4<f32>,
|
|
@location(0) color: vec4<f32>,
|
|
@location(1) barycentric: vec3<f32>,
|
|
};
|
|
|
|
@vertex
|
|
fn vertex(vertex: Vertex) -> VertexOutput {
|
|
var out: VertexOutput;
|
|
let model = get_model_matrix(vertex.instance_index);
|
|
out.clip_position = mesh2d_position_local_to_clip(model, vec4<f32>(vertex.position, 1.0));
|
|
out.color = vertex.color;
|
|
out.barycentric = vertex.barycentric;
|
|
return out;
|
|
}
|
|
|
|
struct FragmentInput {
|
|
@location(0) color: vec4<f32>,
|
|
@location(1) barycentric: vec3<f32>,
|
|
};
|
|
|
|
@fragment
|
|
fn fragment(input: FragmentInput) -> @location(0) vec4<f32> {
|
|
let d = min(input.barycentric.x, min(input.barycentric.y, input.barycentric.z));
|
|
let t = 0.05 * (0.85 + sin(5.0 * globals.time));
|
|
return mix(vec4(1.0,1.0,1.0,1.0), input.color, smoothstep(t, t+0.01, d));
|
|
}
|