Skip to content

Commit

Permalink
Improve circle layer performance by discarding empty pixels
Browse files Browse the repository at this point in the history
  • Loading branch information
kubapelc committed May 20, 2024
1 parent fe439a5 commit 266897d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/shaders/circle.fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ void main() {

fragColor = v_visibility * opacity_t * mix(color * opacity, stroke_color * stroke_opacity, color_t);

const float epsilon = 0.5 / 255.0;
if (fragColor.r < epsilon && fragColor.g < epsilon && fragColor.b < epsilon && fragColor.a < epsilon) {
// If this pixel wouldn't affect the framebuffer contents in any way, discard it for performance.
// This disables early-Z test, but that is likely irrelevant for circles, performance wise.
// But many circles might put a lot of load on the blending and framebuffer output hardware due to using a lot of pixels,
// and this discard will help in that case.
// Also, each circle will at most use ~3/4 of its rasterized pixels, due to being a circle approximated with a square,
// this will discard the unused 1/4.
// Also note that this discard happens even if overdraw inspection is enabled - because discarded pixels never contribute to overdraw.
discard;
}

#ifdef OVERDRAW_INSPECTOR
fragColor = vec4(1.0);
#endif
Expand Down

0 comments on commit 266897d

Please sign in to comment.