Accessing a secondary texture normal map in shader graph? - unity3d

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.

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

Related

Point light in Unity (3D) only shines in one direction when I add a normal map to a material

I've been looking around for answers and I haven't found any.
Whenever I add a .jpg as a normal map in a material, and use that material on objects, point lighting breaks and only shines in one direction
https://i.stack.imgur.com/zoeT9.jpg
(With the .jpg added as a normal map)
https://i.stack.imgur.com/fZy5w.png
(Without any normal maps added, how it should look)
What am I doing wrong?
https://i.stack.imgur.com/3IWLV.png
This is the settings for the texture I'm trying to use

when importing a model to unity from blender, i get odd material results

i imported my blender backrooms model to unity, and i got a wierd mess, this is the model in unity , when its in blender it looks exactly as intended, and even when i render a image of the model in blender all the textures look like they should,this is the model in blender, not a rendered image, ive browsed countless "solutions" and i cant find one that applies to mine, i have tried changing unity import settings, extracting both materials and images, and so on, nothing makes the materials look proper, my guess is that its not accounting for UV mapping junk so its stretching the image so far that it becomes blurred beyond recognitiion, if anybody can help me out it would be much appreciated, also just a side note but i dont think the displacement maps work in unity like they do in blender
edit: the model has multiple objects, the floor ceiling and walls are all 3 seperate objects
edit again: here is the node layout for the floor, every other node layout for the walls and ceiling is just the floors layout but without a displacement map on it
It's been a minute since I've used Unity. But without looking at the blender file, I would suspect that it could maybe be that there's two UVs on your model, and Unity is using the wrong one. I believe Unity uses the first UV Map for texture info, while the others are used for lightmap info. If that's the case, just delete the wrong one in your model. Hopefully that helps!
Edit (more info): I created a basic model with walls, ceiling, and floor. The walls, and ceiling only have a UV Map called UVMap. However, the floor has two UV Maps: UVMap and UVMap.001. Like so:
Now, if I click on that little camera icon next to the UVMap/UVMap.001 you will possibly see the overall size of the bricks change. If so, delete the wrongly scaled UV Map so you only have one UV Map in that window. After that, I would just ensure all your UV Maps are called the same on your other meshes, which is typically UVMap as default. You will also want to be sure all of your images are being mapped by UV, not Object or Generated as Unity cannot use that information. From there you should be good to go!

Global Tiling in HDRP Combined with Parallax Occlusion Makes Messed up UVS

I'm trying to make a custom shader with Shader Graph on HDRP. The intention is to automatically tile textures based on global position so I don't have to worry about remaking materials when I resize things etc. (I'm sure you can imagine the usefuleness of this). But when I do that, combined with the Parallax Occlusion Mapping node (built into HDRP) for height mapping the UVs get all messed up, and the height mapping doesn't even seem to work for some reason.
I thought that if I fed any source UVs into the Parallax Occlusion Mapping node that it would work just fine, but for some reason it doesn't in this case (it's especially obvious when zoomed far in that something is wrong with the UVs). I'm fairly new to shader graph so I'm not exactly sure how to resolve this issue. Let me know if you need anything else from me.
Here is the relevant shader graph nodes (not pictured is pretty much just mapping textures directly into the output node, if you think it might be relevant I can post those too)
Here is the zoomed out version of the scene (with some sample textures) without my global tiling activated (top) and with (bottom). As you can see the tiling works but the height disappears:
And it gets worse if you zoom in (no tiling top, with tiling bottom):
You are missing to connect PixelDepthOffset to the corresponding entry in the Master node. It looks like it's shifting correctly the UV, but the rendering pipeline is not aware it should also change the depth pass accordingly.
You can enable the depth offset in the options of your master node, as follows:

Unity 3D - Render hole in place of object B, which is placed onto object A

I have a primary object which I'd like to make a hole of any shape in, depending on the overlaying gameobject's shape. I thought this could be done with stencil buffer tricks(https://docs.unity3d.com/Manual/SL-Stencil.html), but as my project is for the HDRP, it doesn't seem to work.
Gameobject A has a shader and material set, so I don't want to change its shader as it's inherited.
Gameobject B, which is the overlaid shape, is free for any approach.
I would be happy if anyone knew what I should be reading up on in order to do this for the HD render pipeline (which makes certain shader code invalid).
Written shader, or made with the shader graph, any is fine.
I believe this shader i used to create a "hole" in the water for a boat. Might be what you seek.
unity3d trouble with ship floating on water
You could then use the intermediary object, as a zone for when the player (or anything else) should be able to drop through the area.

Texture doesn't look the same

I am new to Unity and having problems with the textures. Whenever I import a texture and apply it to the terrain it doesn't look the same, sometimes it's for example way too dark and sometimes it's way too shiny. Here is an example:
I have been googling for a while without finding much about it, does someone know what is causing this and how I can fix it?
The reason for this, I expect, is because you are just dropping a texture image onto an object without changing anything. By default, this will create a new material asset, which is what is actually added to the object.
Look up Materials if you don't already understand how they work. The default settings are the Metallic slider at 0 and the Shininess slider at 0.5. Obviously these settings need to be changed depending on the texture, as not every texture is going be a non-metallic, kind of shiny substance.
It is also in these settings that you can add things like Normal Maps, Bump Maps, etc, to make them look more realistic.
Reasons for it being too dark might simply be that the your lighting isn't reaching that particular surface. In order to have a global light source, add a Directional Light to your scene.