Skip to content

Commit

Permalink
wgpu: Fix gradient shader on vulkan backend
Browse files Browse the repository at this point in the history
A regression in naga caused a mistranslation of the gradient shader
on the vulkan backend. This caused radial gradients to be rendered
as linear gradients on the vulkan backend. dx12 seems unaffected.

This seems to be cased by a switch statement starting with a default
case Re-order the case statements to avoid this. Looks like it's been
fixed in naga master.
  • Loading branch information
Herschel committed Jan 23, 2022
1 parent 48f8515 commit bfe0ee2
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions render/wgpu/shaders/gradient.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,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;
switch( gradient.gradient_type ){
// Linear gradient
default: {
t = in.uv.x;
break;
}

// Radial gradient
case 1: {
t = length(in.uv * 2.0 - 1.0);
Expand All @@ -56,16 +50,16 @@ fn main_fragment(in: VertexOutput) -> [[location(0)]] vec4<f32> {
t = l / (sqrt(1.0 - gradient.focal_point * gradient.focal_point * d.y * d.y) + gradient.focal_point * d.x);
break;
}
}

// Tweak out-of-bounds `t` based on the repeat mode.
switch( gradient.repeat_mode ){
// Clamp
// Linear gradient
default: {
t = clamp(t, 0.0, 1.0);
t = in.uv.x;
break;
}
}

// Tweak out-of-bounds `t` based on the repeat mode.
switch( gradient.repeat_mode ){
// Repeat
case 1: {
t = fract(t);
Expand All @@ -85,6 +79,12 @@ fn main_fragment(in: VertexOutput) -> [[location(0)]] vec4<f32> {
}
break;
}

// Clamp
default: {
t = clamp(t, 0.0, 1.0);
break;
}
}
t = clamp(t, gradient.ratios[0], gradient.ratios[last]);

Expand Down

0 comments on commit bfe0ee2

Please sign in to comment.