Giezi
Giezi

Reputation: 140

Unity: access sprite secondary texture in shader for UI canvas image

In Unity, I have a sprite with the usual _MainTex and an additional _inner texture defined as secondary texture in the sprite editor. In shaderGraph, when I want to access this secondary texture for a material meant for the sprite renderer, I can just enter the "ref" as _inner in the Texture2D property, works like a charm.

But when I try to do the same with the same sprite with a shader meant for a UI canvas image (in-game UI), the shader does not appear to find the secondary texture (so the same shader works on my SpriteRenderer, but doesn't on my UI image renderer).

Am I doing something wrong? Any idea what?

Upvotes: 0

Views: 2999

Answers (1)

Nicolas Dai
Nicolas Dai

Reputation: 296

I have encountered a similar problem, the difference is I was making an unlit shader from shader graph. As far as I know, the problem is caused by the master node. Change the master node to sprite lit or sprite unlit, then it can specify the secondary shader, otherwise it won't. So if your UI shader can work fine with a sprite lit or sprite unlit node, you can give it a try.

Sprite Lit and Sprite Unlit works fine

Sprite Lit and Sprite Unlit works fine

EDIT:

As I commented below, flip the secondary texture back.

enter image description here

I can't explain the principle behind the problem, but it worked for me anyhow.

Upvotes: 0

Related Questions