wgpu: Fix repeat & reflect gradients

This commit is contained in:
Nathan Adams 2023-01-29 00:09:08 +01:00
parent 85dc100ee9
commit 7b1c101c81
14 changed files with 67 additions and 31 deletions

View File

@ -92,26 +92,6 @@ fn main_fragment(in: VertexOutput) -> @location(0) vec4<f32> {
// Calculate normalized `t` position in gradient, [0.0, 1.0] being the bounds of the ratios.
var t: f32 = find_t(gradient.focal_point, in.uv);
#if gradient_repeat_mode == 1
// Mirror
if( t < 0.0 ) {
t = -t;
}
if ( (i32(t) & 1) == 0 ) {
t = fract(t);
} else {
t = 1.0 - fract(t);
}
#endif
#if gradient_repeat_mode == 2
// Repeat
t = fract(t);
#endif
#if gradient_repeat_mode == 3
// Clamp
t = clamp(t, 0.0, 1.0);
#endif
t = clamp(t, ratio(0u), ratio(last));
// Find the two gradient colors bordering our position.

View File

@ -5,7 +5,27 @@ override fn gradient::find_t(focal_point: f32, uv: vec2<f32>) -> f32 {
var d: vec2<f32> = vec2<f32>(focal_point, 0.0) - uv;
let l = length(d);
d = d / l;
return l / (sqrt(1.0 - focal_point * focal_point * d.y * d.y) + focal_point * d.x);
var t = l / (sqrt(1.0 - focal_point * focal_point * d.y * d.y) + focal_point * d.x);
#if gradient_repeat_mode == 1
// Mirror
if( t < 0.0 ) {
t = -t;
}
if ( (i32(t) & 1) == 0 ) {
t = fract(t);
} else {
t = 1.0 - fract(t);
}
#endif
#if gradient_repeat_mode == 2
// Repeat
t = fract(t);
#endif
#if gradient_repeat_mode == 3
// Clamp
t = clamp(t, 0.0, 1.0);
#endif
return t;
}
@vertex

View File

@ -1,7 +1,27 @@
#import gradient
override fn gradient::find_t(focal_point: f32, uv: vec2<f32>) -> f32 {
return uv.x;
var t = uv.x;
#if gradient_repeat_mode == 1
// Mirror
if( t < 0.0 ) {
t = -t;
}
if ( (i32(t) & 1) == 0 ) {
t = fract(t);
} else {
t = 1.0 - fract(t);
}
#endif
#if gradient_repeat_mode == 2
// Repeat
t = fract(t);
#endif
#if gradient_repeat_mode == 3
// Clamp
t = clamp(t, 0.0, 1.0);
#endif
return t;
}
@vertex

View File

@ -1,7 +1,27 @@
#import gradient
override fn gradient::find_t(focal_point: f32, uv: vec2<f32>) -> f32 {
return length(uv * 2.0 - 1.0);
var t = length(uv * 2.0 - 1.0);
#if gradient_repeat_mode == 1
// Mirror
if( t < 0.0 ) {
t = -t;
}
if ( (i32(t) & 1) == 0 ) {
t = fract(t);
} else {
t = 1.0 - fract(t);
}
#endif
#if gradient_repeat_mode == 2
// Repeat
t = fract(t);
#endif
#if gradient_repeat_mode == 3
// Clamp
t = clamp(t, 0.0, 1.0);
#endif
return t;
}
@vertex

Binary file not shown.

Before

Width:  |  Height:  |  Size: 61 KiB

After

Width:  |  Height:  |  Size: 76 KiB

View File

@ -1,8 +1,7 @@
num_frames = 1
ignore = true
[image_comparison]
tolerance = 0
tolerance = 2
[player_options]
with_renderer = { optional = true, sample_count = 1 }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

After

Width:  |  Height:  |  Size: 39 KiB

View File

@ -1,8 +1,7 @@
num_frames = 1
ignore = true
[image_comparison]
tolerance = 0
tolerance = 1
[player_options]
with_renderer = { optional = true, sample_count = 1 }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.0 KiB

View File

@ -1,8 +1,7 @@
num_frames = 1
ignore = true
[image_comparison]
tolerance = 0
tolerance = 1
[player_options]
with_renderer = { optional = true, sample_count = 1 }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.0 KiB

View File

@ -1,8 +1,7 @@
num_frames = 1
ignore = true
[image_comparison]
tolerance = 0
tolerance = 1
[player_options]
with_renderer = { optional = true, sample_count = 1 }