Announcing the Shader Graph UGUI Shaders Sample

The Shader Graph team is excited to announce the release of our newest set of samples - UGUI Shaders - available to import now in Unity 6. This set of samples contains over a dozen user interface widgets, buttons, and backgrounds - all generated procedurally using Shader Graph. It also contains a library of more than 50 UI-specific subgraphs that you can use to build user interface elements. The sample shaders work in both HDRP and URP.

We have two main objectives with this sample set:

  1. Demonstrate Shader Graph’s ability to create dynamic, resolution-independent user interface elements in a wide variety of shapes and styles.
  2. Make it easier and faster to create UI elements by providing a large set of UI-specific subgraph nodes that can be used as building blocks to speed up the creation process.

Using Shader Graph and UGUI, you can create user interface elements that are resolution independent, require zero texture memory, can be authored and edited directly in Shader Graph inside of Unity, automatically adapt to aspect ratio, and contain all visual states and behaviors. That’s a lot, so let’s unpack it!

  • Resolution Independent - These UI elements are procedurally-generated, so they look perfectly crisp whether displayed on a small smartphone screen or a 100 inch 8k TV. You can zoom in on them as close as you want and they’ll always be tack sharp.
  • Zero Texture Memory - The visuals for these UI elements are created using math, so they don’t rely on textures at all. That means they require zero texture memory.
  • Authored In Shader Graph - If you’re frustrated by the back and forth workflow of editing your UI images outside of Unity, chopping them up into textures, importing them, and then going back to make adjustments, you’ll be glad to hear that these UI elements are created entirely in Shader Graph, so there’s no export/import loop. Adjustments require simply changing shader parameters or re-wiring a few nodes.
  • Automatically Adapt To Aspect Ratio - By passing the width and height values of the assigned UI element into the shader, the shader can automatically adapt the visuals to fit that ratio. No more making different button shapes to fit different size buttons or fiddling with 9 slicing.
  • Contain all visual states and behaviors - One shader can contain all the information needed for a hover state, and active/inactive state, a pressed down state, etc, so you don’t need to manage multiple image assets for each button or widget.

This set of samples demonstrates how to use all of these advanced techniques for generating UI, and provides tools to make the process easier.

The Samples

The collection of samples includes examples of how to create backgrounds, buttons, indicators, and progress bars using Shader Graph. You can use them as they are, or modify them easily in Shader Graph. The samples are built using nodes from the Subgraph Library, so they serve as examples for how the Subgraph Library nodes can be used together.

Backgrounds - These shaders generally use Screen Space as coordinates. Most of them manipulate the appearance of the scene in some way - such as blurring it or pixelating it - so that the elements of the user interface can be added on top.

RectTransform Size - Many of the UI elements such as rounded rectangles need to adapt to changing aspect ratios. These samples show how you can use the included RectTransform Size node to pass in the width and height of the UI element so that the shader can adapt to fit.

Meters - These shaders create meters that display specific information to the player - including health level, shield strength, mana, etc. Each of them has an exposed parameter that controls the level indicator and can be driven by game values through scripting.

Interactables - These shaders create buttons and other UI elements that the player can interact with. The buttons include exposed parameters for changing the state of the button including active, selected, and pressed. These parameters control the appearance of the button, so connecting these shader parameters to the button events allows the buttons to switch appearance states when the button events are triggered.

Indicators - Indicators are UI elements that ask the user to wait temporarily while the game is saving or loading. They’re usually animated, but don’t require any connection to game logic, and are completely self-contained. These illustrate how these example elements can be made in Shader Graph with zero texture memory.

The Subgraph Library

This sample set contains a library of over 50 subgraphs that you can use to construct UI shaders. To create the subgraph library, we’ve taken a large set of commonly used functionality and encapsulated them as subgraphs. You can build UI shaders easily by connecting these subgraphs together as building blocks instead of creating the functionality from scratch.

After importing the sample, these new nodes show up directly in the Shader Graph Add Node menu, so they’re easy to find and add in your shader projects.

Here’s a description of each of the categories of subgraphs:

Gradients - Shader Graph already ships with a very nice Gradient node, but these subgraphs extend the existing functionality by providing commonly used gradients including Linear Gradient, Sphere Gradient, and Square Gradient.

Helpers - This is a set of commonly used tools like random value generators, posterization, and ease curves. The most useful one - AntiAliasing - creates a perfectly sharp and anti-aliased shape that’s resolution independent when given a gradient or SDF.

Patterns - This set of subgraphs generates commonly used patterns that can be used directly or used as masks to create other shapes and effects. Patterns include Square Tiles, Hexagon Tiles, Circle Segments, Checkers, Bars, Animated Sheen, Ring Segments, etc.

SDFs - This is a collection of signed distance fields - procedurally generated shapes and tools for combining them. These are the foundation for creating buttons and meters that are resolution-independent.

Time - These nodes provide time in various forms - Looping, Switching, Sine Wave, and offset using a mask.

UV - These nodes manipulate UV coordinates - tiling, mirroring, posterizing, shaking, tilting, etc.

How to Install

In the latest version of Unity 6, install the new sample assets using the Package Manager.

  1. In the Editor, open Package Manager.

  1. In the Package Manager window, select the Shader Graph package.

  1. Select the Samples tab.

  2. Finally, select the UGUI Shaders Import button to bring the new UGUI Shaders sample set into your project.

With these steps completed, the UGUI Shaders sample will show up in your project under

Assets/Samples/Shader Graph/-your version-/UGUI Shaders

After importing the samples, get started by opening the sample scene:

Assets/Samples/Shader Graph/-your version-/UGUI Shaders/Scenes/UISampleScene

We’d love to hear what you think! Share your thoughts and comments here in the forum.

22 Likes

Thank you for this, the samples feel very useful!

So is this for UI elements (as per the video description), or for UGUI?

It’s for UGUI. UI element was intended to be a generic term for a “thing” in the user interface, not a proper noun for a specific system.

2 Likes

why my unity 6 dont have that: Sample, Step 4, only says Production Ready Shaders, No UGUI Shader.

what to do

1 Like

wow, it’s so refreshing to see you guys working on augmenting UGUI. I am an UGUI extremist, I think it should be the 1st/default choice for UI, haven’t disappointed me in 1 decade I’ve been using it, complex and simple games.
that said, I’m long overdue learning shader graph, but wow, thanks again for continuing to support the real G in terms of UI. looks amazing too :ok_hand:

1 Like

This new sample set is available in the following versions: 6000.0.39f1, 6000.1.b8

2 Likes

I tried to import but UGUI didn’t show on the


package manager

Shows and imported fine on u6 40f1

Anyway I checked the example scene, seems like Blur doesn’t work on the background… ie no effect, the hex tiles settings can be changed but the blur not working… what is missing for that to work?

In order for the blur to work in URP, you need to enable the Opaque Texture setting on the Render Pipeline Asset:

1 Like

Also be sure that you’re looking at the Game window and not the Scene window.

1 Like

ah nice it works now, thanks for quick response.

2 Likes

This looks awesome, thank you Ben! I noticed on the sample scene that the canvas throws a warning re Screen Space - Overlay (attached). Is this simply an oversight in the demo and I would be safe to remove Normal and Tangent from the Additional Shader Channels or is this setup correct?

The normal and tangent data is not needed. You can remove it.

1 Like

Is there no way to have blur/transparency working in editor view?

It can yes, but not in this particular demo scene. The problem is one of scale. The Canvas that we’re using is quite large in relation to the size of the scene, but it’s set up to always render as a camera overlay. The scene itself is just an image mapped to the inside of a sphere with a camera pointing at it. When you view the scene in Game view, you see the Canvas properly overlaid on the camera with the environment behind it, but when you’re in Scene view, the scene is very small compared to the size of the Canvas - which is not overlaid on the camera - so you’re not actually seeing the scene behind the Canvas anymore. If you were to add another object to the scene, scale it up, and position it behind the Canvas in Scene view, you would see that the Canvas would blur that object. Hope that all makes sense.

I was playing around with this new UGUI Shaders Samples and I have several questions.

  1. How do I achieve consistent outline thickness and corner roundness for rectangles? I’m using rectangle subgraph. Here you can see that depending on the aspect ratio (or something else idk) we have dramatically different results with the same material. I understand that it happening probably because of streched/scaled uvs but for now I don’t know how to fix it.

  2. Suggestion - add an option for outlines to be outside/inside/center.

  3. Is “RectTransform size” component from this sample pack production ready? There is a problem with it when you try to input size values into the rect transform.

1 Like

Hey Ben, the blur shader doesnt respect the masking, is there a way to fix this?

This sample is cool, but why UI Blur doesn’t work when the tint color is black?

Is there a UI Blur sample available somewhere that simply blurs what’s behind an image?

For example I just want to blur a rectangle or an image without any hexagon stuff - how can I do that?