mirror of
https://github.com/bevyengine/bevy
synced 2025-02-16 22:18:33 +00:00
# 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.
52 lines
1.7 KiB
WebGPU Shading Language
52 lines
1.7 KiB
WebGPU Shading Language
#import bevy_pbr::{
|
|
forward_io::VertexOutput,
|
|
mesh_view_bindings::view,
|
|
pbr_types::{STANDARD_MATERIAL_FLAGS_DOUBLE_SIDED_BIT, PbrInput, pbr_input_new},
|
|
pbr_functions as fns,
|
|
}
|
|
#import bevy_core_pipeline::tonemapping::tone_mapping
|
|
|
|
@group(1) @binding(0) var my_array_texture: texture_2d_array<f32>;
|
|
@group(1) @binding(1) var my_array_texture_sampler: sampler;
|
|
|
|
@fragment
|
|
fn fragment(
|
|
@builtin(front_facing) is_front: bool,
|
|
mesh: VertexOutput,
|
|
) -> @location(0) vec4<f32> {
|
|
let layer = i32(mesh.world_position.x) & 0x3;
|
|
|
|
// Prepare a 'processed' StandardMaterial by sampling all textures to resolve
|
|
// the material members
|
|
var pbr_input: PbrInput = pbr_input_new();
|
|
|
|
pbr_input.material.base_color = textureSample(my_array_texture, my_array_texture_sampler, mesh.uv, layer);
|
|
#ifdef VERTEX_COLORS
|
|
pbr_input.material.base_color = pbr_input.material.base_color * mesh.color;
|
|
#endif
|
|
|
|
pbr_input.frag_coord = mesh.position;
|
|
pbr_input.world_position = mesh.world_position;
|
|
pbr_input.world_normal = fns::prepare_world_normal(
|
|
mesh.world_normal,
|
|
(pbr_input.material.flags & STANDARD_MATERIAL_FLAGS_DOUBLE_SIDED_BIT) != 0u,
|
|
is_front,
|
|
);
|
|
|
|
pbr_input.is_orthographic = view.projection[3].w == 1.0;
|
|
|
|
pbr_input.N = fns::apply_normal_mapping(
|
|
pbr_input.material.flags,
|
|
mesh.world_normal,
|
|
#ifdef VERTEX_TANGENTS
|
|
#ifdef STANDARDMATERIAL_NORMAL_MAP
|
|
mesh.world_tangent,
|
|
#endif
|
|
#endif
|
|
mesh.uv,
|
|
view.mip_bias,
|
|
);
|
|
pbr_input.V = fns::calculate_view(mesh.world_position, pbr_input.is_orthographic);
|
|
|
|
return tone_mapping(fns::apply_pbr_lighting(pbr_input), view.color_grading);
|
|
}
|