UGTK cat mascotUGTKengine within an engine Request access

UGTK / Toolkit / Ui Module / Gradient System Completed

Ui Module — UGTK

Gradient System

Summary

Two Unity UI components that paint a Gradient across a RectTransform: AdvancedGradientGraphic draws the gradient as its own mesh (no sprite needed), while AdvancedGradientImageOverlay tints the mesh of an existing Image. Both support angle, percent range, repeat/outside modes, invert and optional gamma compensation.


Content


Modules Dependencies

This module has no hard UGTK dependencies. It only uses Unity UI (MaskableGraphic, BaseMeshEffect).


Setup

Drop the GradientImage prefab under a Canvas — a UI object already painted by the gradient:


How To Use

Standalone gradient (no sprite) — add AdvancedGradientGraphic (menu UI/Advanced Gradient Graphic (No Sprite)) to a UI GameObject. It renders a quad filling the RectTransform, colored by the gradient.

Overlay on an Image — add AdvancedGradientImageOverlay (menu UI/Effects/Advanced Gradient Overlay (Image)) next to an Image (it RequireComponent(typeof(Image))); it recolors the Image mesh vertices via ModifyMesh.

Shared inspector fields on both: - gradient: the Gradient sampled per vertex (defaults to white→black). - angle (0–360): gradient direction. - repeatMode: Clamp, Repeat, Mirror for sampling outside 0–1. - fromPercent / toPercent (0–1): remap interval of the gradient. - outsideMode: Transparent (alpha 0 outside the interval) or ClampToEdge. - invert: swaps the from/to mapping. - gammaCompensation: applies a pow(1/2.2) correction for Gamma color space.

AdvancedGradientGraphic exposes runtime setters: SetGradient(Gradient), SetAngle(float), SetRange(float from01, float to01). Color is computed per vertex by projecting the normalized UV onto the angle direction, remapping into the from/to interval, applying the repeat/outside rules, then multiplying by the graphic tint. An Editor/AdvancedGradientEditor.cs custom inspector is provided.

Good to know:


Testing Scene

Open Debug/AdvanceGradientScene.unity: the two components sit side by side with different angles, ranges and repeat modes.


Technical Info


© 2026 Marcello De Bonis. All rights reserved

Real dependenciesOpen in the map →

Depends on 1

Used by 1

Measured from the repository: code references (asmdef) plus prefab and asset GUIDs. Importing this module alone brings in 1 module in total.