mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 04:33:37 +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.
36 lines
1.1 KiB
WebGPU Shading Language
36 lines
1.1 KiB
WebGPU Shading Language
#import bevy_pbr::mesh_functions::{get_model_matrix, mesh_position_local_to_clip}
|
|
|
|
struct Vertex {
|
|
@location(0) position: vec3<f32>,
|
|
@location(1) normal: vec3<f32>,
|
|
@location(2) uv: vec2<f32>,
|
|
|
|
@location(3) i_pos_scale: vec4<f32>,
|
|
@location(4) i_color: vec4<f32>,
|
|
};
|
|
|
|
struct VertexOutput {
|
|
@builtin(position) clip_position: vec4<f32>,
|
|
@location(0) color: vec4<f32>,
|
|
};
|
|
|
|
@vertex
|
|
fn vertex(vertex: Vertex) -> VertexOutput {
|
|
let position = vertex.position * vertex.i_pos_scale.w + vertex.i_pos_scale.xyz;
|
|
var out: VertexOutput;
|
|
// NOTE: Passing 0 as the instance_index to get_model_matrix() is a hack
|
|
// for this example as the instance_index builtin would map to the wrong
|
|
// index in the Mesh array. This index could be passed in via another
|
|
// uniform instead but it's unnecessary for the example.
|
|
out.clip_position = mesh_position_local_to_clip(
|
|
get_model_matrix(0u),
|
|
vec4<f32>(position, 1.0)
|
|
);
|
|
out.color = vertex.i_color;
|
|
return out;
|
|
}
|
|
|
|
@fragment
|
|
fn fragment(in: VertexOutput) -> @location(0) vec4<f32> {
|
|
return in.color;
|
|
}
|