UIGradient has been a great gift to us developers ever since its introduction as it’s simple to use and can be quite powerful when combined with other features to create nice effects. The only drawback to it is that it’s quite limited, only offering a Linear Gradient style. The effectiveness and power of UIGradients would increase EXPONENTIALLY if they had the ability to render using different gradient styles.
Mockup
Proposed new properties of UIGradient:
-
Style: A new enum with a selection of gradient styles
-
GradientStyle.Linear
- What we currently have and are used to. -
GradientStyle.Radial
- Gradient begins from a central point and spreads outwards in a circular shape. -
GradientStyle.Conic
(or Angle as in PS) - Gradient revolves around a central point. -
GradientStyle.Square
(or Diamond as in PS) - Similar to Radial, except it forms a square/diamond shape. -
GradientStyle.CustomImage
- Gradient forms using an inputted Texture map. Texture map should be greyscale (black/white only).
-
-
StyleTextureId: The image asset for which the gradient is based off if the style is set to ‘Custom Image’
- Used only when GradientStyle is set to Custom Image.
- Image should be a greyscale opaque bitmap.
- Color from the gradient ColorSequence is interpolated from how dark/light each pixel on the texture is.
- Black pixels = ColorSequence [0%] (The leftmost ColorSequenceKeypoint)
- 50% grey pixels = ColorSequence [50%] (The central ColorSequenceKeypoint)
- White pixels = ColorSequence [100%] (The rightmost ColorSequenceKeypoint)
- This is something I commonly used in Unreal Engine using their material setup and UMG to create custom progress/health bar shapes and transition effects.
-
Scale: The scale offset of the gradient, similar to how Photoshop handles it
-
Low scale example
-
High scale example
-
Low scale example
Use case example
I like to create radial progress bars, however the best way to achieve them currently is as follows (for a clockwise-depleting radial bar):
- Have two ImageLabels centralised on the same point with half of a hollow circle image on either side.
- The left half must have a UIGradient with the Transparency suddenly jumping to 1 at 50%.
- Use scripting to animate the wheel
- When progress is 50-100%, rotate the right half into the left half
- When progress is 0-50%, hide the right half and set the Rotation of the left half’s UIGradient so that it depletes the semi-circle into nothingness.
As you can see, it surely works, but it’s a little convoluted (takes a little trial and error to get the maths set up correctly), has a mild rendering artefact (the right half bulges out of the left half by 1 pixel when it is rotated into the left half) and could certainly be made 100x more convenient and easy to set up with one single UIGradient set to Conic and a little basic scripting setting the Transparency numbersequence.
Further potential use cases for enhanced GradientStyles:
The following images are taken from some of my projects at university in Unreal Engine.
—Inventory opening transition—
—Custom progress bars—
This example also uses a texture input to distort the image. Texture distortion on UI plz Roblox ?
The XP bar is a painted horseshoe shape with a distorted Conic gradient.
Images used to set up the health bar:
(1. Gradient mask) (2. Foreground to be masked) (3. Background)
More hypothetical use cases:
- Loading screen animations
- Transition effects
- Something more complex than a simple fade or swipe. Such as a custom shape filling & unfilling on the screen, such as a star.
- Visual & particle effects
- These new gradients could be used to mimic particles or on-screen particles with enhanced shape animation capability.
- Ripple effects using circular gradients that grow & shrink.