From ce2c5f66b106dc392670b56a74d2a7a3395e29f4 Mon Sep 17 00:00:00 2001 From: Connor Slade Date: Sun, 16 Feb 2025 11:37:44 -0500 Subject: [PATCH] Cleanup model shader --- mslicer/src/shaders/model.wgsl | 35 ++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/mslicer/src/shaders/model.wgsl b/mslicer/src/shaders/model.wgsl index df0233b..d0abc9c 100644 --- a/mslicer/src/shaders/model.wgsl +++ b/mslicer/src/shaders/model.wgsl @@ -1,5 +1,9 @@ @group(0) @binding(0) var context: Context; +const STYLE_NORMAL: u32 = 0; +const STYLE_RANDOM: u32 = 1; +const STYLE_RENDERD: u32 = 2; + struct Context { transform: mat4x4, model_transform: mat4x4, @@ -40,21 +44,28 @@ fn frag(in: VertexOutput) -> @location(0) vec4 { return vec4(1.0, 0.0, 0.0, 1.0); } - if context.render_style == 0 { - return vec4(normal, 1.0); - } else if context.render_style == 1 { - seed = in.vertex_index; - return vec4f(rand(), rand(), rand(), 1.0); - } else { - let camera_direction = normalize(context.camera_position + context.camera_target); + switch context.render_style { + case STYLE_NORMAL: { + return vec4(normal, 1.0); + } + case STYLE_RANDOM: { + seed = in.vertex_index; + return vec4f(rand(), rand(), rand(), 1.0); + } + case STYLE_RENDERD: { + let camera_direction = normalize(context.camera_position + context.camera_target); - let diffuse = max(dot(normal, camera_direction), 0.0); + let diffuse = max(dot(normal, camera_direction), 0.0); - let reflect_dir = reflect(-camera_direction, normal); - let specular = pow(max(dot(camera_direction, reflect_dir), 0.0), 32.0); + let reflect_dir = reflect(-camera_direction, normal); + let specular = pow(max(dot(camera_direction, reflect_dir), 0.0), 32.0); - let intensity = (diffuse + specular + 0.1) * context.model_color.rgb; - return vec4(intensity, context.model_color.a); + let intensity = (diffuse + specular + 0.1) * context.model_color.rgb; + return vec4(intensity, context.model_color.a); + } + default: { + return vec4(0.0); + } } }