hello, I am trying to learn Shaders in Unity in general.
I am trying to texture the extruded faces in a different texture but I don’t know how to get the UV coords right. In my attempt, I am using the Triplanar node because it gives me the closest results, which is still incorrect, i.e. the texture is not aligned to the cliff face axis. I do not believe Triplanar node is required in this situation, I think I just do not understand the concepts of converting between different cartesian coordinate spaces.
I read various shader code and found a common line in the vert() TRANSFORM_TEXT(v.texcoord, _MainTex_ST) that seems to be my answer, but I do not understand fully what this does and how to test this in the Shader Graph equivalent.
In this example, I exported the model from Blender. The Blender’s Cliff UVs are squished into a line (intentional), however, in below example, the cliff texture (grey) is not squished, which suggests to me that the Blender UVs are not used in Unity. So my question is, what is the default TEXTCOORD0 (UV0) used? How can I map this default UV0 using position data to the texture?
My end goal is to generate this procedurally. In that case, do I also need to procedurally supply the UV0 coords, or can the Shader calculate it on the fly?
If you are using triplanar, then it will not use UV as triplanar node uses world space coords to “stick” the texture from all axes.
To be honest I am not sure I get what you want, how does blender uv looks like? Do you want to use UV from blender or generate UV from code? How it supposed to look like in the end?
By the way I think TRANSFORM_TEX is macro for tiling and offset.
@Qriva If you look at the rock texture (grey), I expect them to align to the face axis, i.e. it should look right-side-up the same as in the shader graph Triplanar node preview, but actually it is not. I don’t know what it is currently aligned to, it is slanted in various direction.
I don’t want to use triplanar. I believe this can be achieved by simple mapping.
If I am importing from Blender, I will just texture everything in Blender and will not have this problem. But I want to generate the model in Unity and procedurally texture it.
Are you saying that I need to generate the UV in C# first, as it is not possible to map the texture in Shader alone?
Well, triplanar takes world space axes by default (the red arrows), this is why the rock is aligned to top.
I think you have two options, first one is to calculate new coords in shader. Never tried to spherize coords like this, so I can’t tell you how exactly to do this, but you would probably need to find the light green tangent arrow and the blue one, but to do that you need both normal and tangent to be correctly set in mesh, then you could try polarize them. You could use sphere origin to calculate distance on blue arrow and autotile texture like that.
The thing is if you generate this mesh anyway, then you can assign UV values directly during generation and this is the second option you have.