-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] Use varying interpolation to compute some linear gradients. #53166
Changes from all commits
e9e2ef4
29b4597
af7c7ee
b5f764a
9b35a37
765e00f
1aed825
7623919
61ed98a
a14f666
4cfd1cf
59ba1c4
f33c417
6c92f8e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| precision mediump float; | ||
|
|
||
| #include <impeller/color.glsl> | ||
| #include <impeller/dithering.glsl> | ||
| #include <impeller/types.glsl> | ||
|
|
||
| uniform FragInfo { | ||
| float alpha; | ||
| } | ||
| frag_info; | ||
|
|
||
| in vec4 v_color; | ||
|
|
||
| out vec4 frag_color; | ||
|
|
||
| void main() { | ||
| frag_color = IPPremultiply(v_color) * frag_info.alpha; | ||
| // mod operator is not supported in GLES 2.0 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whats with this comment? Also, even though the operator is not supported, you can use the function.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shader would fail to load on GLES because the ordered dither uses a bunch of bit manipulation logic?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh. Gotcha. That method has a mod in there somewhere. We should be able to fix it using the mod() function though. It's just the operator that's bad in ES.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nothing to do in this patch. Was just curious.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ahh TIL!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what an odd restriction |
||
| #ifndef IMPELLER_TARGET_OPENGLES | ||
| frag_color = IPOrderedDither8x8(frag_color, gl_FragCoord.xy); | ||
| #endif // IMPELLER_TARGET_OPENGLES | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #include <impeller/transform.glsl> | ||
| #include <impeller/types.glsl> | ||
|
|
||
| uniform FrameInfo { | ||
| mat4 mvp; | ||
| } | ||
| frame_info; | ||
|
|
||
| in vec2 position; | ||
| in vec4 color; | ||
|
|
||
| // The geometry of the fast gradient draws is designed so that the | ||
| // varying unit will perform the correct color interpolation. | ||
| out vec4 v_color; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a comment here saying, "We exploit the simplicity of this gradient and make the varying unit perform the interpolation instead of performing the calculations ourselves."
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
|
||
| void main() { | ||
| gl_Position = frame_info.mvp * vec4(position, 0.0, 1.0); | ||
| v_color = color; | ||
| } | ||
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.
Beautiful.