I’m going to give a presentation on how to draw 2D graphics efficiently in 2018 and it’ll just be one slide: “Use the Z-buffer”
-
-
Replying to @pcwalton
Sorry, but can you explain this a bit further? I know what a Z-buffer is, but why is it needed for 2D?
1 reply 0 retweets 1 like -
Basically vector graphics tend do be built upon many layers which means lots of overdraw and memory bandwidth. Using the z-buffer to draw opaque content front to back let's you save a ton of memory bandwidth.
1 reply 0 retweets 7 likes -
Replying to @nicalsilva @pcwalton
Why is drawing front to back any better then back to front? Aren't you drawing the same amount of stuff total?
1 reply 0 retweets 0 likes -
The z-buffer provides hardware level optimizations for quickly discarding occluded pixels and avoid the cost of writing to memory. Front to back maximizes the chance of discarding hidden operations on pixels.
2 replies 0 retweets 7 likes -
Replying to @nicalsilva
(Also the hardware avoids running the fragment shader for occluded pixels in some cases, which saves even more time.)
2 replies 0 retweets 2 likes -
Replying to @pcwalton @nicalsilva
For the opaque content pass, would you still do occlusion culling for rects using an r-tree, quadtree or some other acceleration structure? 3D engines do object level occlusion culling to reduce overdraw. i.e. using the camera transformed BVH AABB to avoid redundant draw calls.
1 reply 0 retweets 1 like
We tried that but it’s rarely worth it, because usually anything that increases CPU time loses.
-
-
Replying to @pcwalton
I'd say it can be worth splitting primitives on the CPU instead of using the z-buffer if there are few layers and mostly simple geometry (rectangles). E.g. compositor of a window manager would typically do that. For more complex stuff the z-buffer can really shine if used right.
0 replies 0 retweets 0 likesThanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.