WIREFRAME_WGSL

Constant WIREFRAME_WGSL 

Source
pub const WIREFRAME_WGSL: &str = "// Wireframe Material Shader\n// For debug visualization of mesh geometry\n\n// --- Vertex Shader ---\n\nstruct CameraUniforms {\n    view_projection: mat4x4<f32>,\n    camera_position: vec4<f32>,\n};\n\n@group(0) @binding(0)\nvar<uniform> camera: CameraUniforms;\n\nstruct VertexInput {\n    @location(0) position: vec3<f32>,\n    @location(1) normal: vec3<f32>,\n};\n\nstruct VertexOutput {\n    @builtin(position) clip_position: vec4<f32>,\n    @location(0) barycentric: vec3<f32>,  // For wireframe rendering\n};\n\nstruct ModelUniforms {\n    model_matrix: mat4x4<f32>,\n};\n\n@group(1) @binding(0)\nvar<uniform> model: ModelUniforms;\n\n@vertex\nfn vs_main(input: VertexInput, @builtin(vertex_index) vertex_index: u32) -> VertexOutput {\n    var out: VertexOutput;\n    \n    let world_pos = model.model_matrix * vec4<f32>(input.position, 1.0);\n    out.clip_position = camera.view_projection * world_pos;\n    \n    // Assign barycentric coordinates based on vertex index in triangle\n    // This is a simple approach - each vertex gets one coordinate as 1.0\n    let tri_index = vertex_index % 3u;\n    if (tri_index == 0u) {\n        out.barycentric = vec3<f32>(1.0, 0.0, 0.0);\n    } else if (tri_index == 1u) {\n        out.barycentric = vec3<f32>(0.0, 1.0, 0.0);\n    } else {\n        out.barycentric = vec3<f32>(0.0, 0.0, 1.0);\n    }\n    \n    return out;\n}\n\n\n// --- Fragment Shader ---\n\nstruct WireframeMaterialUniforms {\n    color: vec4<f32>,           // Wireframe line color\n    line_width: f32,            // Line width in pixels\n    _padding: vec3<f32>,\n};\n\n@group(2) @binding(0)\nvar<uniform> material: WireframeMaterialUniforms;\n\n@fragment\nfn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {\n    // Use barycentric coordinates to determine distance from edges\n    // The minimum barycentric coordinate tells us how far we are from an edge\n    let min_bary = min(min(in.barycentric.x, in.barycentric.y), in.barycentric.z);\n    \n    // Convert to screen space distance (approximation)\n    let edge_distance = min_bary;\n    \n    // Threshold for line width (this is a simplified approach)\n    let threshold = material.line_width * 0.01;  // Scale down for barycentric space\n    \n    // Discard fragments far from edges\n    if (edge_distance > threshold) {\n        discard;\n    }\n    \n    // Anti-aliasing: smooth the edge\n    let alpha = 1.0 - smoothstep(threshold * 0.5, threshold, edge_distance);\n    \n    return vec4<f32>(material.color.rgb, material.color.a * alpha);\n}\n";
Expand description

Wireframe debug visualization shader.

Renders mesh edges using barycentric coordinates to calculate edge distances. Useful for debugging mesh topology.