summaryrefslogtreecommitdiff
path: root/rust/crates/gpu/src/shaders
diff options
context:
space:
mode:
Diffstat (limited to 'rust/crates/gpu/src/shaders')
-rw-r--r--rust/crates/gpu/src/shaders/gaussian_blur.wgsl34
-rw-r--r--rust/crates/gpu/src/shaders/jfa_distance.wgsl50
-rw-r--r--rust/crates/gpu/src/shaders/jfa_init.wgsl35
-rw-r--r--rust/crates/gpu/src/shaders/jfa_step.wgsl75
4 files changed, 0 insertions, 194 deletions
diff --git a/rust/crates/gpu/src/shaders/gaussian_blur.wgsl b/rust/crates/gpu/src/shaders/gaussian_blur.wgsl
deleted file mode 100644
index 6c8d311d..00000000
--- a/rust/crates/gpu/src/shaders/gaussian_blur.wgsl
+++ /dev/null
@@ -1,34 +0,0 @@
-struct VertexOutput {
- @builtin(position) position: vec4f,
- @location(0) tex_coord: vec2f,
-}
-
-struct EffectUniforms {
- resolution: vec2f,
- direction: vec2f,
- scalars: vec4f,
-}
-
-@group(0) @binding(0) var input_texture: texture_2d<f32>;
-@group(0) @binding(1) var input_sampler: sampler;
-@group(1) @binding(0) var<uniform> uniforms: EffectUniforms;
-
-@fragment
-fn fragment_main(input: VertexOutput) -> @location(0) vec4f {
- let texel_size = vec2f(1.0, 1.0) / uniforms.resolution;
- let sigma = uniforms.scalars.x;
- let step_size = uniforms.scalars.y;
-
- var color = vec4f(0.0, 0.0, 0.0, 0.0);
- var total_weight = 0.0;
-
- for (var index = -30; index <= 30; index = index + 1) {
- let position = f32(index) * step_size;
- let weight = exp(-(position * position) / (2.0 * sigma * sigma));
- let sample_uv = input.tex_coord + (texel_size * uniforms.direction * position);
- color = color + textureSample(input_texture, input_sampler, sample_uv) * weight;
- total_weight = total_weight + weight;
- }
-
- return color / total_weight;
-}
diff --git a/rust/crates/gpu/src/shaders/jfa_distance.wgsl b/rust/crates/gpu/src/shaders/jfa_distance.wgsl
deleted file mode 100644
index e65a7023..00000000
--- a/rust/crates/gpu/src/shaders/jfa_distance.wgsl
+++ /dev/null
@@ -1,50 +0,0 @@
-struct VertexOutput {
- @builtin(position) position: vec4f,
- @location(0) tex_coord: vec2f,
-}
-
-struct DistanceUniforms {
- resolution: vec2f,
- feather_half: f32,
- _padding: f32,
-}
-
-@group(0) @binding(0) var inside_texture: texture_2d<f32>;
-@group(0) @binding(1) var inside_sampler: sampler;
-@group(1) @binding(0) var outside_texture: texture_2d<f32>;
-@group(1) @binding(1) var outside_sampler: sampler;
-@group(2) @binding(0) var<uniform> uniforms: DistanceUniforms;
-
-fn decode_seed(encoded: vec4f) -> vec2f {
- let x = floor(encoded.r * 255.0 + 0.5) * 256.0 + floor(encoded.g * 255.0 + 0.5);
- let y = floor(encoded.b * 255.0 + 0.5) * 256.0 + floor(encoded.a * 255.0 + 0.5);
- return vec2f(x, y);
-}
-
-fn is_no_seed(encoded: vec4f) -> bool {
- return encoded.r > 0.99 && encoded.g > 0.99 && encoded.b > 0.99 && encoded.a > 0.99;
-}
-
-@fragment
-fn fragment_main(input: VertexOutput) -> @location(0) vec4f {
- let pixel_coord = floor(input.tex_coord * uniforms.resolution);
- let inside_encoded = textureSample(inside_texture, inside_sampler, input.tex_coord);
- let outside_encoded = textureSample(outside_texture, outside_sampler, input.tex_coord);
-
- let has_inside = !is_no_seed(inside_encoded);
- let has_outside = !is_no_seed(outside_encoded);
- let distance_to_inside = select(
- 100000.0,
- distance(pixel_coord, decode_seed(inside_encoded)),
- has_inside,
- );
- let distance_to_outside = select(
- 100000.0,
- distance(pixel_coord, decode_seed(outside_encoded)),
- has_outside,
- );
- let signed_distance = distance_to_outside - distance_to_inside;
- let alpha = smoothstep(-uniforms.feather_half, uniforms.feather_half, signed_distance);
-
- return vec4f(alpha, alpha, alpha, alpha);
-}
diff --git a/rust/crates/gpu/src/shaders/jfa_init.wgsl b/rust/crates/gpu/src/shaders/jfa_init.wgsl
deleted file mode 100644
index 29aa38c7..00000000
--- a/rust/crates/gpu/src/shaders/jfa_init.wgsl
+++ /dev/null
@@ -1,35 +0,0 @@
-struct VertexOutput {
- @builtin(position) position: vec4f,
- @location(0) tex_coord: vec2f,
-}
-
-struct JfaInitUniforms {
- resolution: vec2f,
- invert: f32,
- _padding: f32,
-}
-
-@group(0) @binding(0) var input_texture: texture_2d<f32>;
-@group(0) @binding(1) var input_sampler: sampler;
-@group(1) @binding(0) var<uniform> uniforms: JfaInitUniforms;
-
-fn encode_seed(seed: vec2f) -> vec4f {
- let x_hi = floor(seed.x / 256.0);
- let x_lo = seed.x - (x_hi * 256.0);
- let y_hi = floor(seed.y / 256.0);
- let y_lo = seed.y - (y_hi * 256.0);
- return vec4f(x_hi / 255.0, x_lo / 255.0, y_hi / 255.0, y_lo / 255.0);
-}
-
-@fragment
-fn fragment_main(input: VertexOutput) -> @location(0) vec4f {
- let mask = textureSample(input_texture, input_sampler, input.tex_coord).r;
- let is_seed = select(mask > 0.5, mask < 0.5, uniforms.invert > 0.5);
-
- if (is_seed) {
- let pixel_coord = floor(input.tex_coord * uniforms.resolution);
- return encode_seed(pixel_coord);
- }
-
- return vec4f(1.0, 1.0, 1.0, 1.0);
-}
diff --git a/rust/crates/gpu/src/shaders/jfa_step.wgsl b/rust/crates/gpu/src/shaders/jfa_step.wgsl
deleted file mode 100644
index e20d7fb0..00000000
--- a/rust/crates/gpu/src/shaders/jfa_step.wgsl
+++ /dev/null
@@ -1,75 +0,0 @@
-struct VertexOutput {
- @builtin(position) position: vec4f,
- @location(0) tex_coord: vec2f,
-}
-
-struct JfaStepUniforms {
- resolution: vec2f,
- step_size: f32,
- _padding: f32,
-}
-
-@group(0) @binding(0) var input_texture: texture_2d<f32>;
-@group(0) @binding(1) var input_sampler: sampler;
-@group(1) @binding(0) var<uniform> uniforms: JfaStepUniforms;
-
-fn decode_seed(encoded: vec4f) -> vec2f {
- let x = floor(encoded.r * 255.0 + 0.5) * 256.0 + floor(encoded.g * 255.0 + 0.5);
- let y = floor(encoded.b * 255.0 + 0.5) * 256.0 + floor(encoded.a * 255.0 + 0.5);
- return vec2f(x, y);
-}
-
-fn encode_seed(seed: vec2f) -> vec4f {
- let x_hi = floor(seed.x / 256.0);
- let x_lo = seed.x - (x_hi * 256.0);
- let y_hi = floor(seed.y / 256.0);
- let y_lo = seed.y - (y_hi * 256.0);
- return vec4f(x_hi / 255.0, x_lo / 255.0, y_hi / 255.0, y_lo / 255.0);
-}
-
-fn is_no_seed(encoded: vec4f) -> bool {
- return encoded.r > 0.99 && encoded.g > 0.99 && encoded.b > 0.99 && encoded.a > 0.99;
-}
-
-@fragment
-fn fragment_main(input: VertexOutput) -> @location(0) vec4f {
- let pixel_coord = floor(input.tex_coord * uniforms.resolution);
- let texel_size = vec2f(1.0, 1.0) / uniforms.resolution;
-
- var best_distance = 10000000000.0;
- var best_seed = vec2f(65535.0, 65535.0);
-
- for (var y = -1; y <= 1; y = y + 1) {
- for (var x = -1; x <= 1; x = x + 1) {
- let offset = vec2f(f32(x), f32(y)) * uniforms.step_size;
- let sample_uv = input.tex_coord + (offset * texel_size);
-
- if (
- sample_uv.x < 0.0 ||
- sample_uv.x > 1.0 ||
- sample_uv.y < 0.0 ||
- sample_uv.y > 1.0
- ) {
- continue;
- }
-
- let encoded = textureSample(input_texture, input_sampler, sample_uv);
- if (is_no_seed(encoded)) {
- continue;
- }
-
- let seed = decode_seed(encoded);
- let distance_to_seed = distance(pixel_coord, seed);
- if (distance_to_seed < best_distance) {
- best_distance = distance_to_seed;
- best_seed = seed;
- }
- }
- }
-
- if (best_distance < 1000000000.0) {
- return encode_seed(best_seed);
- }
-
- return vec4f(1.0, 1.0, 1.0, 1.0);
-}