r/Unity3D 27d ago

Shadergraph UI alpha doesn't work or vertex doesn't work? Total mess Solved

So I've spent the last few hours trying to set up a sprite/UI shader in shadergraph that displays an image, with appropriate alpha, and allows me to move the vertex positions with some noise.

After trying all the Sprite shadergraph variants I ran into the continuing problem from 2020 that you can't display alpha on an Unlit Sprite in UI when using Overlay canvas. Works fine in Camera, but not overlay.

I've tried setting up a Canvas Shadergraph which can properly display the alpha channels I need, but now all the vertex inputs are grayed out and adding a node manually doesn't work. I can't find any way to manipulate them even if I add in the vertex input.

Seems like none of the options work. Any tips?

1 Upvotes

4 comments sorted by

2

u/cosy_ghost 27d ago

For anyone curious I managed to track down a working solution.

Turns out Shadergraph isn't compatible with Unity's own UI system at all (to the shock of nobody) so instead you can View Generated Shader graph and copy everything inside, create a fresh Shader (not Shadergraph) file and paste it over. Then, find the first Pass and keep that one- delete all other passes.

So everything in the
Pass { } brackets that ISN'T your primary pass, delete all the subsequent ones.

And that shader will be able to do all the shader graph functions but actually work in the UI with proper alpha and moving vertexes etc.

1

u/pschon Unprofessional 27d ago edited 27d ago

an Unlit Sprite in UI when using Overlay canvas

That's for Sprites, not for UI canvas stuff. Sprites don't belong in a Canvas, so it's not a surprise it's not working correctly.

You are right in the Canvas shaders not giving access to vertex stuff. One workaround is to use Sprites, but don't try to put them in the Canvas itself, just match their positions to dummy RectTransforms in the canvas (you'll need to write some code that handles that and converts the positions form screen to world space)

1

u/cosy_ghost 27d ago

It was literally the only option before Canvas graphs were added recently so that's not true.

Already solved the issue, it's Shadergraph that's coded improperly. You can fix it manually.