mirror of
https://github.com/bevyengine/bevy
synced 2025-01-03 08:48:57 +00:00
3f5a090b1b
# Objective - The StandardMaterial always uses ATTRIBUTE_UV_0 for each texture except lightmap. This is not flexible enough for a lot of gltf Files. - Fixes #12496 - Fixes #13086 - Fixes #13122 - Closes #13153 ## Solution - The StandardMaterial gets extended for each texture by an UvChannel enum. It defaults to Uv0 but can also be set to Uv1. - The gltf loader now handles the texcoord information. If the texcoord is not supported it creates a warning. - It uses StandardMaterial shader defs to define which attribute to use. ## Testing This fixes #12496 for example: ![wall_fixed](https://github.com/bevyengine/bevy/assets/688816/bc37c9e1-72ba-4e59-b092-5ee10dade603) For testing of all kind of textures I used the TextureTransformMultiTest from https://github.com/KhronosGroup/glTF-Sample-Assets/tree/main/Models/TextureTransformMultiTest Its purpose is to test multiple texture transfroms but it is also a good test for different texcoords. It also shows the issue with emission #13133. Before: ![TextureTransformMultiTest_main](https://github.com/bevyengine/bevy/assets/688816/aa701d04-5a3f-4df1-a65f-fc770ab6f4ab) After: ![TextureTransformMultiTest_texcoord](https://github.com/bevyengine/bevy/assets/688816/c3f91943-b830-4068-990f-e4f2c97771ee)
94 lines
2.2 KiB
WebGPU Shading Language
94 lines
2.2 KiB
WebGPU Shading Language
#define_import_path bevy_pbr::prepass_io
|
|
|
|
// Most of these attributes are not used in the default prepass fragment shader, but they are still needed so we can
|
|
// pass them to custom prepass shaders like pbr_prepass.wgsl.
|
|
struct Vertex {
|
|
@builtin(instance_index) instance_index: u32,
|
|
@location(0) position: vec3<f32>,
|
|
|
|
#ifdef VERTEX_UVS_A
|
|
@location(1) uv: vec2<f32>,
|
|
#endif
|
|
|
|
#ifdef VERTEX_UVS_B
|
|
@location(2) uv_b: vec2<f32>,
|
|
#endif
|
|
|
|
#ifdef NORMAL_PREPASS_OR_DEFERRED_PREPASS
|
|
@location(3) normal: vec3<f32>,
|
|
#ifdef VERTEX_TANGENTS
|
|
@location(4) tangent: vec4<f32>,
|
|
#endif
|
|
#endif // NORMAL_PREPASS_OR_DEFERRED_PREPASS
|
|
|
|
#ifdef SKINNED
|
|
@location(5) joint_indices: vec4<u32>,
|
|
@location(6) joint_weights: vec4<f32>,
|
|
#endif
|
|
|
|
#ifdef VERTEX_COLORS
|
|
@location(7) color: vec4<f32>,
|
|
#endif
|
|
|
|
#ifdef MORPH_TARGETS
|
|
@builtin(vertex_index) index: u32,
|
|
#endif // MORPH_TARGETS
|
|
}
|
|
|
|
struct VertexOutput {
|
|
// This is `clip position` when the struct is used as a vertex stage output
|
|
// and `frag coord` when used as a fragment stage input
|
|
@builtin(position) position: vec4<f32>,
|
|
|
|
#ifdef VERTEX_UVS_A
|
|
@location(0) uv: vec2<f32>,
|
|
#endif
|
|
|
|
#ifdef VERTEX_UVS_B
|
|
@location(1) uv_b: vec2<f32>,
|
|
#endif
|
|
|
|
#ifdef NORMAL_PREPASS_OR_DEFERRED_PREPASS
|
|
@location(2) world_normal: vec3<f32>,
|
|
#ifdef VERTEX_TANGENTS
|
|
@location(3) world_tangent: vec4<f32>,
|
|
#endif
|
|
#endif // NORMAL_PREPASS_OR_DEFERRED_PREPASS
|
|
|
|
@location(4) world_position: vec4<f32>,
|
|
#ifdef MOTION_VECTOR_PREPASS
|
|
@location(5) previous_world_position: vec4<f32>,
|
|
#endif
|
|
|
|
#ifdef DEPTH_CLAMP_ORTHO
|
|
@location(6) clip_position_unclamped: vec4<f32>,
|
|
#endif // DEPTH_CLAMP_ORTHO
|
|
#ifdef VERTEX_OUTPUT_INSTANCE_INDEX
|
|
@location(7) instance_index: u32,
|
|
#endif
|
|
|
|
#ifdef VERTEX_COLORS
|
|
@location(8) color: vec4<f32>,
|
|
#endif
|
|
}
|
|
|
|
#ifdef PREPASS_FRAGMENT
|
|
struct FragmentOutput {
|
|
#ifdef NORMAL_PREPASS
|
|
@location(0) normal: vec4<f32>,
|
|
#endif
|
|
|
|
#ifdef MOTION_VECTOR_PREPASS
|
|
@location(1) motion_vector: vec2<f32>,
|
|
#endif
|
|
|
|
#ifdef DEFERRED_PREPASS
|
|
@location(2) deferred: vec4<u32>,
|
|
@location(3) deferred_lighting_pass_id: u32,
|
|
#endif
|
|
|
|
#ifdef DEPTH_CLAMP_ORTHO
|
|
@builtin(frag_depth) frag_depth: f32,
|
|
#endif // DEPTH_CLAMP_ORTHO
|
|
}
|
|
#endif //PREPASS_FRAGMENT
|