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 forward9fn depth_ndc_to_view_z(ndc_depth: f32, clip_from_view: mat4x4<f32>, view_from_clip: mat4x4<f32>) -> f32 {10// #ifdef VIEW_PROJECTION_PERSPECTIVE11 return -perspective_camera_near(clip_from_view) / ndc_depth;12// #else ifdef VIEW_PROJECTION_ORTHOGRAPHIC13// return -(clip_from_view[3][2] - ndc_depth) / clip_from_view[2][2];14// #else15// let view_pos = view_from_clip * vec4(0.0, 0.0, ndc_depth, 1.0);16// return view_pos.z / view_pos.w;17// #endif18}20fn perspective_camera_near(clip_from_view: mat4x4<f32>) -> f32 {21 return clip_from_view[3][2];22}24struct PrimitiveInput {25 @per_primitive @location(3) colorMask: vec4<f32>,26}28struct Output {29 @location(0) color: vec4<f32>,30 @builtin(frag_depth) frag_depth: f3231}33@fragment34fn 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;41}