How can to handle RGBA(4) output from Texture2DArray when node requires a Texture2D input?

Hello,

I have a triplanar node for my procedural map that works great. The problem is that this triplanar node only take an input of a Texture2D.

In my map, I store Texture2D index in UV map for vertices and I change Texture2DArray using this index cells.

The problem is that I can’t output a RGBA into Triplanar node.

What solution I can see :

  • (blue) Export the UV map from triplanar and input it to Texture2D array (this need to edit triplanar node).
  • (red) Convert RGBA to Texture2D
  • (green) Change input of Triplanar node to Texture2D array
  • Use a if/else expression from my TextureIndex and output the corresponding texture2D (I know if/else on shader is bad practice, iI need to do it for like 20 textures).

Do you think it’s possible ? If yes how ?

What you’re asking for is pretty specialized. You need an Array version of the Triplanar node. What I’d recommend is that you use the source code for the Triplanar node that’s available in the documentation here: Triplanar Node | Shader Graph | 16.0.6 Put that into a custom code node and make your own new version of the Triplanar node that samples array textures instead of standard 2d textures. That can be done by replacing the instances of SAMPLE_TEXTURE2D in the code with SAMPLE_TEXTURE2DARRAY instead. If you don’t know how to do that, ask and engineer on your team for help. If you don’t have an available engineer, let me know here and I’ll do it.

Thanks you !
I didn’t know that this code on the documentation was the .HSLS code. First I tried to edit TiplanarNode.cs on the package but it was protected of course…

So I made a custom node function taking Texture2Darray and index as input and it’s working !

9189785--1280759--upload_2023-8-2_21-1-26.png

The looks perfect from what I can see in your screen shot - except you’ll want to create a Normal Vector node and plug that into the Normal input port instead of the Position node as it is now. Nice work with that!

Also, if you make a new Subgraph and put your Custom Function node in that, you’ll be able to save it out and reuse it in other graphs if needed.

Hi, could you post the code to your hlsl that takes in index and texture2DArray and outputs a texture2D?

// Your existing setup
float3 Node_UV = Position * Tile;
float3 Node_Blend = pow(abs(Normal), Blend);
Node_Blend /= dot(Node_Blend, 1.0);

// Individual UV for each axis
float2 UV_X = Node_UV.zy;
float2 UV_Y = Node_UV.xz;
float2 UV_Z = Node_UV.xy;

// Blend the UVs
float2 Blended_UV = UV_X * Node_Blend.x + UV_Y * Node_Blend.y + UV_Z * Node_Blend.z;

// Output the blended UV
Out_UV = Blended_UV;

what I did is go there :
https://docs.unity3d.com/Packages/com.unity.shadergraph@6.9/manual/Triplanar-Node.html

Then take the code at the bottom of the map and add what I want. This is my final version based also on a “infinite” hex