mirror of
https://github.com/bevyengine/bevy
synced 2025-01-10 20:29:01 +00:00
82 lines
1.9 KiB
WebGPU Shading Language
82 lines
1.9 KiB
WebGPU Shading Language
|
#import bevy_pbr::prepass_bindings
|
||
|
#import bevy_pbr::mesh_functions
|
||
|
|
||
|
// 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 {
|
||
|
@location(0) position: vec3<f32>,
|
||
|
|
||
|
#ifdef VERTEX_UVS
|
||
|
@location(1) uv: vec2<f32>,
|
||
|
#endif // VERTEX_UVS
|
||
|
|
||
|
#ifdef NORMAL_PREPASS
|
||
|
@location(2) normal: vec3<f32>,
|
||
|
#ifdef VERTEX_TANGENTS
|
||
|
@location(3) tangent: vec4<f32>,
|
||
|
#endif // VERTEX_TANGENTS
|
||
|
#endif // NORMAL_PREPASS
|
||
|
|
||
|
#ifdef SKINNED
|
||
|
@location(4) joint_indices: vec4<u32>,
|
||
|
@location(5) joint_weights: vec4<f32>,
|
||
|
#endif // SKINNED
|
||
|
}
|
||
|
|
||
|
struct VertexOutput {
|
||
|
@builtin(position) clip_position: vec4<f32>,
|
||
|
|
||
|
#ifdef VERTEX_UVS
|
||
|
@location(0) uv: vec2<f32>,
|
||
|
#endif // VERTEX_UVS
|
||
|
|
||
|
#ifdef NORMAL_PREPASS
|
||
|
@location(1) world_normal: vec3<f32>,
|
||
|
#ifdef VERTEX_TANGENTS
|
||
|
@location(2) world_tangent: vec4<f32>,
|
||
|
#endif // VERTEX_TANGENTS
|
||
|
#endif // NORMAL_PREPASS
|
||
|
}
|
||
|
|
||
|
@vertex
|
||
|
fn vertex(vertex: Vertex) -> VertexOutput {
|
||
|
var out: VertexOutput;
|
||
|
|
||
|
#ifdef SKINNED
|
||
|
var model = skin_model(vertex.joint_indices, vertex.joint_weights);
|
||
|
#else // SKINNED
|
||
|
var model = mesh.model;
|
||
|
#endif // SKINNED
|
||
|
|
||
|
out.clip_position = mesh_position_local_to_clip(model, vec4(vertex.position, 1.0));
|
||
|
|
||
|
#ifdef VERTEX_UVS
|
||
|
out.uv = vertex.uv;
|
||
|
#endif // VERTEX_UVS
|
||
|
|
||
|
#ifdef NORMAL_PREPASS
|
||
|
#ifdef SKINNED
|
||
|
out.world_normal = skin_normals(model, vertex.normal);
|
||
|
#else // SKINNED
|
||
|
out.world_normal = mesh_normal_local_to_world(vertex.normal);
|
||
|
#endif // SKINNED
|
||
|
|
||
|
#ifdef VERTEX_TANGENTS
|
||
|
out.world_tangent = mesh_tangent_local_to_world(model, vertex.tangent);
|
||
|
#endif // VERTEX_TANGENTS
|
||
|
#endif // NORMAL_PREPASS
|
||
|
|
||
|
return out;
|
||
|
}
|
||
|
|
||
|
#ifdef NORMAL_PREPASS
|
||
|
struct FragmentInput {
|
||
|
@location(1) world_normal: vec3<f32>,
|
||
|
}
|
||
|
|
||
|
@fragment
|
||
|
fn fragment(in: FragmentInput) -> @location(0) vec4<f32> {
|
||
|
return vec4(in.world_normal * 0.5 + vec3(0.5), 1.0);
|
||
|
}
|
||
|
#endif // NORMAL_PREPASS
|