104 lines
2.6 KiB
WebGPU Shading Language
104 lines
2.6 KiB
WebGPU Shading Language
// This is a tool that merges the shader code with the shader code from the shader module.
|
|
|
|
struct UniformCommonTools {
|
|
model_matrix: mat4x4f,
|
|
view_matrix: mat4x4f,
|
|
proj_matrix: mat4x4f,
|
|
camera_x: f32,
|
|
camera_y: f32,
|
|
camera_z: f32,
|
|
camera_target_x: f32,
|
|
camera_target_y: f32,
|
|
camera_target_z: f32,
|
|
camera_up_x: f32,
|
|
camera_up_y: f32,
|
|
camera_up_z: f32,
|
|
|
|
// camera_position: vec3f,
|
|
// camera_front: vec3f,
|
|
// camera_up: vec3f,
|
|
}
|
|
|
|
@group(0) @binding(0) var<uniform> common_tools: UniformCommonTools;
|
|
const PI:f32 = 3.14159265358979323846264338327950288;
|
|
const TWO_PI:f32 = 6.28318530717958647692528676655900576;
|
|
const HALF_PI:f32 = 1.57079632679489661923132169163975144;
|
|
const LOG2:f32 = 0.693147180559945309417232121458176568;
|
|
const LOG10:f32 = 2.30258509299404568401799145468436421;
|
|
|
|
// 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<uniform> params: UniformParams;
|
|
// Data Buffer
|
|
@group(1) @binding(1) var<storage> data: array<f32>;
|
|
|
|
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;
|
|
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);
|
|
// var 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);
|
|
}
|
|
|