#include "constants.wgsl"; // Common Uniforms // common_tools // model_matrix: mat4, // view_matrix: mat4, // proj_matrix: mat4, // camera_position: vec3, // camera_front: vec3, // camera_up: vec3, // light_position: vec3, // light_color: vec3, // light_intensity: float, // Uniforms @group(1) @binding(0) var params: UniformParams; // Data Buffer @group(1) @binding(1) var data: array; struct UniformParams { origin: vec4f } struct VertexOutput { @builtin(position) position: vec4f, @location(0) r_range: vec4f, @location(1) idx: u32 } @vertex fn vertex( @location(0) position: vec4f, @location(1) r_range: vec4f, // @location(2) idx: u32 ) -> VertexOutput { var out: VertexOutput; // Transform position // out.position = common_tools.proj_matrix * common_tools.view_matrix * common_tools.model_matrix * vec4f(position, 1.0); out.position = vec4(position.xyz, 1.0); out.r_range = r_range; out.idx = 0u; return out; } fn polar_forward(cartesian: vec3f) -> vec3f { let r = length(cartesian.xy - params.origin.xy); let theta = atan2(cartesian.y, cartesian.x); let z = cartesian.z; return vec3f(r, theta, z); } @fragment fn fragment(input: VertexOutput) -> @location(0) vec4f { // Sample data texture let value = data[input.idx]; let ear = polar_forward(input.position.xyz); // var color = linear_colormap(value); var color = vec4(1.0, 1.0, 1.0, 1.0); let r = ear.z; // Valid range // let r_range = input.r_range; // let outside_lower_bound = step(r, r_range.x); // let outside_upper_bound = step(r_range.y, r); // let is_outside = outside_lower_bound + outside_upper_bound; // color.a *= 1.0 - is_outside; return vec4(r,r,r,r); }