[Feature] Gradients for Backgrounds#1846
Merged
hecrj merged 13 commits intoiced-rs:masterfrom May 19, 2023
Merged
Conversation
b409e2e to
7fef727
Compare
7fef727 to
6551a0b
Compare
The gradients feel a bit out of place currently.
fa61eb3 to
10a8c59
Compare
... since it's not really reused anywhere else.
8079b5a to
f557b81
Compare
hecrj
approved these changes
May 19, 2023
Member
hecrj
left a comment
There was a problem hiding this comment.
Awesomesauce! 🥳
Changed some minor details here and there, but overall the work here is excellent. Great job @bungoboingo!
Let's get this merged! 🎉
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Gradients are now usable as a
BackgroundvariantWhen creating a background with a gradient, the syntax is slightly different than when creating it on a
Canvas.Example of building a gradient for background:
Users can declare a
Gradientwith a specifiedAngle(rads or degrees), and add up to =8ColorStops along that angle. The bounds of the gradient will be calculated from the bounds of the quad that it is filling.Changes to
Canvasgradient syntaxUsers can no longer specify a
Position::Absoluteor aPosition::Relative; now users can only specify an absolutestart&endposition when using a gradient as aFillon aCanvas. This change was made to simplify the gradient API. Calculating bounds is possible with a mesh but would increase the cost of our tessellation phase which is not ideal.New syntax for creating a
Gradientfill on aCanvas(very similar to old one):Some API notes
Due to this differing requirement for both
CanvasandBackgroundgradient types, I've had to redeclareGradientsseparately incore&graphics. I messed about with keeping one builder for both, but it led to too many unexpected behaviors. Duping theGradientdeclaration between the two now has no unintended consequences of, for example, declaring aGradientwith an angle as a fill for a mesh, which is undefined behavior. Let me know what you think!Changes to Gradient rendering pipeline
Gradients are now stored as a vertex type,
GradientVertex2Dwhich takes a position & flattened gradient data. This change allows us to stay fast & reduce draw calls in quad instancing/triangle drawing. This will also make gradients more accessible for different platforms (eg for WASM target), as it removes the requirements of storage buffer support.Old gradients bench (rendering 5151 static gradients):

New gradients bench (same 5151 static gradients)!:

GPU is now much more happy!
This does have the tradeoff of forcing a lower maximum number of color stops, which is now 8 compared to.. like 186,000. If anyone has any issues with this please let me know in the comments below!
Support added
WASM should now be able to compile gradient shaders & use gradients as I've removed the need of storage buffers. Let me know if you see any issues!
Testing
Tested:
M1 mac (WGPU + metal, tiny-skia)
Linux (WGPU + Vulkan, tiny-skia)
Windows 10 (WGPU + DirectX, tiny-skia)
🌈 🌈 🌈
Welcoming all feedback on the API & other changes! 🎉
(reopened from 1597 which was auto closed due to
advanced-textmerge)