Search across packages, versions, files, declarations, and comments. Use multiple terms to narrow results (AND), and add @vertex, @fragment, or @compute to filter by shader stage.
1import super::{
2 bindings::{globals, view, VertexOutput},
3};
4enable wgpu_mesh_shader;
6// TODO: import these functions in the future when doing so does not crash the shader.
7// Convert ndc depth to linear view z.
8// Note: Depth values in front of the camera will be negative as -z is forward
9fn depth_ndc_to_view_z(ndc_depth: f32, clip_from_view: mat4x4<f32>, view_from_clip: mat4x4<f32>) -> f32 {
10// #ifdef VIEW_PROJECTION_PERSPECTIVE
11 return -perspective_camera_near(clip_from_view) / ndc_depth;
12// #else ifdef VIEW_PROJECTION_ORTHOGRAPHIC
13// return -(clip_from_view[3][2] - ndc_depth) / clip_from_view[2][2];
14// #else
15// let view_pos = view_from_clip * vec4(0.0, 0.0, ndc_depth, 1.0);
16// return view_pos.z / view_pos.w;
17// #endif
20fn perspective_camera_near(clip_from_view: mat4x4<f32>) -> f32 {
21 return clip_from_view[3][2];
24struct PrimitiveInput {
25 @per_primitive @location(3) colorMask: vec4<f32>,
28struct Output {
29 @location(0) color: vec4<f32>,
30 @builtin(frag_depth) frag_depth: f32
33@fragment
34fn fragment(vertex: VertexOutput, primitive: PrimitiveInput) -> Output {
35 var output: Output;
36 // output.color = vec4(vertex.uv, 0.,1.);
37 // output.color = vec4(vertex.normal,1.);
38 output.color = primitive.colorMask;
39 output.frag_depth = vertex.position.z;
40 return output;
Contents