I was working on a project using 2020.3, recently moved to 2022.3.0 (I also tried this in the latest LTS 2022.3.4 and the latest 2023.1.3f1 ).
The shader is an Unlit Sprite Shader for use as a material for a UI element
I’m using the Alpha to shape the UI Image
Here is a simplified example of what I’m doing, easy to replicate Just:
- Create a Universal / Sprite Unlit Shader
- Assign whatever Black/White mask to the Alpha (could be an Ellipse node)
- Assign the material to an UI Image
It seems to work in the scene viewport, but not in the game.
Am I missing something, Should I enable some setting elsewhere? Or is this a bug?
In case someone is following this, More info that could help:
- I also recreated the same shader with Amplify Shader and it works. It only doesn’t work if created with Shader Graph.
- The Shader created with Shader Graph, that doesn’t display correctly in Game view, works when you build the game.
This could be because Unity mostly uses rpe-multiplied alpha blending (One OneMinusSrcAlpha) instead of traditional alpha blending (SrcAlpha OneMinusSrcAlpha)? If that’s the case, you need to multiply the color.rgb with color.a at the end.
fixed4 SpriteFrag(v2f IN) : SV_Target
{
fixed4 c = SampleSpriteTexture (IN.texcoord) * IN.color;
c.rgb *= c.a;
return c;
}
I think it’s still not working in latest 2022.3.16f1, I have to change the render mode of my canvas to screen space-camera to cope.