From 22063750734cd2dca36fa6040839c66caeb422c8 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Wed, 16 Oct 2024 12:22:18 +0200 Subject: [PATCH] lint --- shader.wgsl | 86 ++++++++++++++++++++++++----------------------------- 1 file changed, 39 insertions(+), 47 deletions(-) diff --git a/shader.wgsl b/shader.wgsl index 64d5b6e..fe2dbd7 100644 --- a/shader.wgsl +++ b/shader.wgsl @@ -1,8 +1,8 @@ -struct Edge { v : vec2 }; +struct Edge { v: vec2 }; -struct Segment { v : vec2, index: i32 }; -struct Trig { v : vec3, index: i32 }; -struct Quad { v : vec4, index: i32 }; +struct Segment { v: vec2, index: i32 }; +struct Trig { v: vec3, index: i32 }; +struct Quad { v: vec4, index: i32 }; struct ClippingPlane { normal: vec3, @@ -20,7 +20,7 @@ struct Complex { }; struct Uniforms { - mat : mat4x4, + mat: mat4x4, clipping_plane: vec4, colormap: vec2, scaling: vec2, @@ -38,8 +38,7 @@ struct Uniforms { @group(0) @binding(4) var edges : array; @group(0) @binding(4) var trigs : array; -struct VertexOutput -{ +struct VertexOutput { @builtin(position) fragPosition: vec4, @location(0) p: vec3, @location(1) value: f32, @@ -47,63 +46,56 @@ struct VertexOutput }; fn calcPosition(p: vec3) -> vec4 { - return uniforms.mat * vec4(p, 1.0); + return uniforms.mat * vec4(p, 1.0); } fn checkClipping(p: vec3) { - if(uniforms.do_clipping != 0) { - if(dot(uniforms.clipping_plane, vec4(p, 1.0)) < 0) { + if uniforms.do_clipping != 0 { + if dot(uniforms.clipping_plane, vec4(p, 1.0)) < 0 { discard; - } - } + } + } } fn getColor(value: f32) -> vec4 { - return textureSample(colormap, colormap_sampler, value); + return textureSample(colormap, colormap_sampler, value); } @vertex -fn mainVertexTrig(@builtin(vertex_index) vertexId: u32) -> VertexOutput -{ - var trigId = vertexId / 3; - var trig = trigs[trigId]; - var vid = trig.v[vertexId % 3]; - var p = vertices[vid]; - var position = calcPosition(p); - position.z = 0.01; - var lam: vec3 = vec3(0.); - if(vertexId % 3 == 0) { lam[0] = 1.0; } - else if(vertexId % 3 == 1) { lam[1] = 1.0; } - else { lam[2] = 1.0; } - var value: f32 = p.x; - return VertexOutput(position, p, value, lam); +fn mainVertexTrig(@builtin(vertex_index) vertexId: u32) -> VertexOutput { + var trigId = vertexId / 3; + var trig = trigs[trigId]; + var vid = trig.v[vertexId % 3]; + var p = vertices[vid]; + var position = calcPosition(p); + position.z = 0.01; + var lam: vec3 = vec3(0.); + if vertexId % 3 == 0 { lam[0] = 1.0; } else if vertexId % 3 == 1 { lam[1] = 1.0; } else { lam[2] = 1.0; } + var value: f32 = p.x; + return VertexOutput(position, p, value, lam); } @vertex -fn mainVertexEdge(@builtin(vertex_index) vertexId: u32) -> VertexOutput -{ - var edgeId = vertexId / 2; - var edge = edges[edgeId]; - var vid = edge.v[vertexId % 2]; - var p = vertices[vid]; - var position = calcPosition(p); - var lam: vec3 = vec3(0.); - if(vertexId % 2 == 0) { lam[0] = 1.0; } - else { lam[1] = 1.0;} - var value: f32 = p.x; // todo: evaluate function here - return VertexOutput(position, p, value, lam); +fn mainVertexEdge(@builtin(vertex_index) vertexId: u32) -> VertexOutput { + var edgeId = vertexId / 2; + var edge = edges[edgeId]; + var vid = edge.v[vertexId % 2]; + var p = vertices[vid]; + var position = calcPosition(p); + var lam: vec3 = vec3(0.); + if vertexId % 2 == 0 { lam[0] = 1.0; } else { lam[1] = 1.0;} + var value: f32 = p.x; // todo: evaluate function here + return VertexOutput(position, p, value, lam); } @fragment -fn mainFragmentTrig(@location(0) p: vec3, @location(1) value: f32) -> @location(0) vec4 -{ - checkClipping(p); - return getColor(value); +fn mainFragmentTrig(@location(0) p: vec3, @location(1) value: f32) -> @location(0) vec4 { + checkClipping(p); + return getColor(value); } @fragment -fn mainFragmentEdge(@location(0) p: vec3, @location(1) value: f32) -> @location(0) vec4 -{ - checkClipping(p); - return vec4(0, 0, 0, 1.0); +fn mainFragmentEdge(@location(0) p: vec3, @location(1) value: f32) -> @location(0) vec4 { + checkClipping(p); + return vec4(0, 0, 0, 1.0); }