- Home /
Make shader for UI
hey guys
just a little question
I'm making material using shadergraph and I want to attach it on mu UI element. how is it possible?
Answer by cnczcraft · Oct 01, 2018 at 06:26 AM
No make a sprite in a paint program shader graph is 3d only. Out of curiosity, why do you want to do this?
$$anonymous$$ake a sprite for the different colors of bar and move the bar with your health. Then either mask the end of the bar that sticks out or hide it at the edge of the screen.
the goal, I want to achieve is something different. I've already made shader. all I have to do is attach it on UI element. or maybe can I make 'fake' UI image?
Answer by ValakhP · Oct 03, 2018 at 10:47 AM
Hello giosto,
I don't use shader graph, but in general, there is no a lot of difference between shaders for UI and world objects.
If it's possible, take a look on built-in UI shaders and compare it with the shader that shader graph gives you.
Simple shaders should work both on UI elements and 3D objects. It it's not - find differences between your resulting shader and built-in one.
You can download build-in shaders from here: https://unity3d.com/ru/get-unity/download/archive
Answer by Dankey_Kang · Oct 03, 2018 at 01:24 PM
I havent used shadergraph so forgive my ignorance but I believe you can add a material to UI components, for example if you look at Image components you'll notice an object field named material. You set it there.
UI materials are handled a little differently then normal 3D materials and there are some special considerations.
An example of special considerations is how _MainTex is handled in shaders designed for the Text component, _MainTex is passed a texture by the Text component itself and it is an image of the relevant letter I think.
It will depend on the UI element you are using, sounds like this will be an Image component if it is a health bar.
Answer by metalouis · Oct 29, 2018 at 04:42 PM
You can make shaders for the UI, though mine only seem to work in editor and not play mode unless I set the canvas to use screen space-camera, otherwise its just black for me. FYI if you want to get the colour of the UI element add a vertex colour node.
Answer by leshemamit · May 24, 2019 at 07:16 AM
I've used shader graph for UI Image (also works for RawImage) and made a tutorial about it! hope you will find it useful:
https://www.youtube.com/watch?v=Nbvqi8cfnrc&list=PLhQGsXIRIGQ3Z99Z60tIGsK3kmpRRuvbj∈dex=2
Your answer
![](https://koobas.hobune.stream/wayback/20220612175536im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to add sprite or particles on shader 0 Answers
Shader Graph not showing when included in build? 0 Answers
Outline in shader graph 0 Answers
Intersection / Geometry blend shader graph problem 0 Answers
Shader Graph Positioned Vertex Normals 2 Answers