#include "constants.wgsl"; #include "colormap.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(2) @binding(0) var params: UniformParams; // Data Buffer @group(2) @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 = vec4(position.xyz, 1.0); out.r_range = r_range; let idx = u32(position.w); out.idx = idx; 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); // let color = linear_colormap(value); var color = clamp(value / 75.0, 0.0, 1.0); // let r = ear.x; // 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(color,color,color, 1.0); }