Skip to content

Commit

Permalink
Canvas: fix arc rendering on AMD GPUs
Browse files Browse the repository at this point in the history
for some reason only using one discard statement makes the glitching go
away
  • Loading branch information
carrotIndustries committed Feb 18, 2024
1 parent 79704c7 commit f197474
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
9 changes: 5 additions & 4 deletions src/canvas/shaders/triangle-arc-fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ vec2 p2r(float phi, float l) {
}

void main() {
bool disc = false;

if(length(round_pos_to_fragment)>1)
discard;
disc = true;

float my_alpha = alpha;
if(layer_mode == LAYER_MODE_FILL_ONLY) { //force alpha for fill only mode
Expand All @@ -30,7 +32,6 @@ void main() {
if(my_a0 < 0)
my_a0 += 2*PI;

bool disc = false;

float len = length(round_pos_to_fragment);
if(((len < (1-line_width+border_width)) || (len > (1-border_width))) && layer_mode != LAYER_MODE_FILL_ONLY) {
Expand All @@ -43,7 +44,7 @@ void main() {
}

if(len < (1-line_width)) {
discard;
disc = true;
}

if(my_a0 > a1) { //outside of arc
Expand All @@ -66,7 +67,7 @@ void main() {
}
}
else if (!e0 && !e1){
discard;
disc = true;
}
}

Expand Down
8 changes: 1 addition & 7 deletions src/canvas/shaders/triangle-arc0-fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ flat in float a0;
flat in float a1;

void main() {
if(length(round_pos_to_fragment)>1)
discard;

float my_alpha = 1;
if(layer_mode == LAYER_MODE_FILL_ONLY) { //force alpha for stencil mode
my_alpha = alpha;
Expand All @@ -25,11 +22,8 @@ void main() {
if(my_a0 < 0)
my_a0 += 2*PI;

if(my_a0 > a1)
if(my_a0 > a1 || length(round_pos_to_fragment)>1 || length(round_pos_to_fragment) < border_threshold)
discard;

if(length(round_pos_to_fragment) < border_threshold) {
discard;
}
outputColor = vec4(color_to_fragment, my_alpha);
}
7 changes: 4 additions & 3 deletions src/canvas/shaders/triangle-arc0-geometry.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,18 @@ void main() {

color_to_fragment = get_color(color_to_geom[0], color2_to_geom[0]);

a0 = p1.x;
a1 = p1.y;


float border_width = min_line_width;
float r = p2.x + border_width/scale/2;
float h = r*2;
float z = 2;

border_threshold = 1-border_width/(r*scale);

for(int i = 0; i<3; i++) {
a0 = p1.x;
a1 = p1.y;
border_threshold = 1-border_width/(r*scale);
float phi = PI*(2./3)*i;
gl_Position = t(p0+p2r(phi, h));
round_pos_to_fragment = p2r(phi,z);
Expand Down

0 comments on commit f197474

Please sign in to comment.