-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] Gradients for Backgrounds #1846
Merged
Merged
Conversation
This file contains 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
bungoboingo
force-pushed
the
feat/background-gradients
branch
from
May 11, 2023 17:53
b409e2e
to
7fef727
Compare
bungoboingo
force-pushed
the
feat/background-gradients
branch
from
May 11, 2023 18:13
7fef727
to
6551a0b
Compare
The gradients feel a bit out of place currently.
hecrj
force-pushed
the
feat/background-gradients
branch
from
May 19, 2023 01:48
fa61eb3
to
10a8c59
Compare
... since it's not really reused anywhere else.
hecrj
force-pushed
the
feat/background-gradients
branch
from
May 19, 2023 02:00
8079b5a
to
f557b81
Compare
hecrj
approved these changes
May 19, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesomesauce! 🥳
Changed some minor details here and there, but overall the work here is excellent. Great job @bungoboingo!
Let's get this merged! 🎉
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
Background
variantWhen 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
Gradient
with a specifiedAngle
(rads or degrees), and add up to =8ColorStop
s along that angle. The bounds of the gradient will be calculated from the bounds of the quad that it is filling.Changes to
Canvas
gradient syntaxUsers can no longer specify a
Position::Absolute
or aPosition::Relative
; now users can only specify an absolutestart
&end
position when using a gradient as aFill
on 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
Gradient
fill on aCanvas
(very similar to old one):Some API notes
Due to this differing requirement for both
Canvas
andBackground
gradient types, I've had to redeclareGradients
separately incore
&graphics
. I messed about with keeping one builder for both, but it led to too many unexpected behaviors. Duping theGradient
declaration between the two now has no unintended consequences of, for example, declaring aGradient
with 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,
GradientVertex2D
which 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-text
merge)