From 5fa849d883e6c6483db1183f047f0c8f2a84612f Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 13 Oct 2022 12:05:10 +0200 Subject: [PATCH] Consolidate duplicate return values --- crates/fj-viewer/src/graphics/shader.wgsl | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/crates/fj-viewer/src/graphics/shader.wgsl b/crates/fj-viewer/src/graphics/shader.wgsl index bb0011c5c..035900538 100644 --- a/crates/fj-viewer/src/graphics/shader.wgsl +++ b/crates/fj-viewer/src/graphics/shader.wgsl @@ -18,6 +18,10 @@ struct VertexOutput { @location(1) color: vec4, }; +struct FragmentOutput { + @location(0) color: vec4, +} + @vertex fn vertex(in: VertexInput) -> VertexOutput { var out: VertexOutput; @@ -32,7 +36,7 @@ fn vertex(in: VertexInput) -> VertexOutput { let pi: f32 = 3.14159265359; @fragment -fn frag_model(in: VertexOutput) -> @location(0) vec4 { +fn frag_model(in: VertexOutput) -> FragmentOutput { let light = vec3(0.0, 0.0, -1.0); let angle = acos(dot(light, -in.normal)); @@ -40,17 +44,22 @@ fn frag_model(in: VertexOutput) -> @location(0) vec4 { let f_normal = max(1.0 - f_angle, 0.0); - let color = vec4(in.color.rgb * f_normal, in.color.a); + var out: FragmentOutput; + out.color = vec4(in.color.rgb * f_normal, in.color.a); - return color; + return out; } @fragment -fn frag_mesh(in: VertexOutput) -> @location(0) vec4 { - return vec4(1.0 - in.color.rgb, in.color.a); +fn frag_mesh(in: VertexOutput) -> FragmentOutput { + var out: FragmentOutput; + out.color = vec4(1.0 - in.color.rgb, in.color.a); + return out; } @fragment -fn frag_lines(in: VertexOutput) -> @location(0) vec4 { - return vec4(in.color.rgb, in.color.a); +fn frag_lines(in: VertexOutput) -> FragmentOutput { + var out: FragmentOutput; + out.color = vec4(in.color.rgb, in.color.a); + return out; }