Accessing a secondary texture normal map in shader graph?

3k Views Asked by At

I'm using Unity 2020.1.3f1's URP, with the new 2D renderer system. As of right now, I have objects that change between the built in "Sprite-Lit-Default" material, and a material with the custom built pixel outline shader detailed here: https://danielilett.com/2020-04-27-tut5-6-urp-2d-outlines/

This worked well and good, but I recently added lights, and a normal map to my sprites as a secondary texture in the import settings. The default lit texture has no problems displaying the normal map, but when I attempted to modify my shader graph to include the normal map, it doesn't import like the sprite texture does when _MainTex is set as the reference.

I've tried _NormalMap (which is the name of the secondary texture in the importer!) as well as _NormalTex, but it always ends up not importing the normal map. I even attempted changing _MainTex to a Texture2D, but given that kept sparking an error, I didn't think it was the right way to go about it. (This one to be specific.)

Error assigning 2D texture to 2DArray texture property '_MainTex': Dimensions must match
UnityEditor.EditorApplication:Internal_CallUpdateFunctions()

Am I missing something here? All the tutorials I can find online only show people dragging the normal map in through the inspector, but this material is going to be used by many different sprites, so that seems...counterintuitive.

On top of this, the default material/shader has no issues with this, so I feel like I'm either missing something, or I'm going to end up having to code my sprites to change material through code instead of the animator, just for this small, annoying quirk..

Blackboard Properties, and nodes. This just goes into the normals input.

Inspector panel showing the missing normal map slot.

And the Secondary Textures in case I somehow misnamed it, why not?

(EDIT) So, an update on this, for anyone else who runs into this same issue. I managed to find a section of the shadergraph documentation that seems to be the only part talking about this:

It is required to name the reference for MainTex as _MainTex to render Sprites. It is also recommended to name the references for Mask as _MaskTex and Normal as _NormalMap to match the Shader inputs used in this package.

So from what I gather from that, _MainTex is the only one that's automatic in ShaderGraph. After a full day of looking up tutorials, I've noticed that every single one of them simply set the normal map and extra textures as the default textures so they'll show up without being assigned manually.

I think this is possible with hand-written shaders, but I've decided to just go with a simple unlit shadergraph on a hand-drawn sprite outline, displayed on a separate gameobject parented to the main object. I'm not posting this as an answer in case someone else finds a solution to it in the future, and since this isn't...really a solution in my eyes.

1

There are 1 best solutions below

0
On

I don't know if you have figured this out yet but I'll try to answer since I had the same problem. Create a new Texture2D node, convert it to a property, and have the reference as _NormalMap, connect that to the sample texture 2D node as normal, and plug that into the sprite lit master. Now go into the sprite editor, assign the normal maps as a secondary texture, and make sure the name is the same as in your shader, _NormalMap (or something else, as long as it's the same). This currently has worked for me, shader graph detects the normal map texture by reference automatically. Attached below are some images to help and the finished result on the character sprite, which uses a custom shader I picked up from a tutorial and added the normal map to. Shader Graph Sprite EditorSprite Editor 2 Normal Map result