-
-
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 #1597
[Feature] Gradients for Backgrounds #1597
Conversation
a9a80bb
to
c31a421
Compare
389c6df
to
e2ee8e4
Compare
fba463d
to
d662a2d
Compare
d662a2d
to
5bc240f
Compare
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.
Looking awesome!
No specific showstoppers for me 🎉 Just a bunch of suggestions here and there. Let me know what you think!
d253f95
to
54576b3
Compare
7c16569
to
9987bf4
Compare
Added ooooonnnneeee last commit d33e3e6 to add dithering to the gradient shaders to smooth out banding |
@@ -38,6 +42,8 @@ vec4 gradient( | |||
//if a gradient has a start/end stop that is identical, the mesh will have a transparent fill | |||
vec4 color; | |||
|
|||
float noise_granularity = 0.3/255.0; |
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.
this seemed like a good amount to me, but I'm also pretty blind IRL so if it still looks band-y or too grainy, let me know.
I would love to see this get merged, as it also seems to fix #1625! |
- Adjusted default instances/triangles to be more consistent.
d33e3e6
to
2adaf3f
Compare
a756bf0
to
dc82fb0
Compare
dc82fb0
to
f60c065
Compare
Re-targeted this to
|
Updated gradient builder to not use a If stops are added after the 8th, they will be silently ignored. |
8b6be3d
to
dc36423
Compare
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!
Addition of several new
benches
cratesI've added four new static benchmarks toexamples/benches
. Not sure this is the best place for them, I could see them perhaps being added to theprofiling
crate in my profiling PR, or to a separate repo entirely. Let me know what you think!I've moved these to https://github.com/bungoboingo/iced_benches for the time being until we can figure out how we want to integrate the benches into our CI.
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! 🎉