Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Feature Request Texture 2D Array Sample with LOD

Discussion in 'Shader Graph' started by meanmonkey, Mar 4, 2020.

  1. meanmonkey

    meanmonkey

    Joined:
    Nov 13, 2014
    Posts:
    148
    As it seems the lod version of texture2DArray sample is not available in the shader graph.

    Will it be added in the future ?

    Many thanks

    EDIT: I just realized I can inject custom HLSL code into the shader graph. I will give it a go as a workaround.

    EDIT 2: I was able to use the texture2DArrayLOD sample variant via a custom HLSL function. So I guess the missing option in shader graph is a "bug" as the method is available in HLSL.

    Input values:
    Texture2DArray myTextureArray
    Vector1 myIndex
    Vector2 myUV
    Sampler mySampler
    Vector1 myLOD

    Output values:
    Vector4 rgbaOut

    Function (string variant in my case):

    rgbaOut = SAMPLE_TEXTURE2D_ARRAY_LOD(myTextureArray, mySampler, myUV, myIndex, myLOD);
     
    Last edited: Mar 5, 2020
    Ruchir likes this.
  2. IndieMarkus

    IndieMarkus

    Joined:
    Apr 17, 2014
    Posts:
    1
    I was at a similar roadblock. I'm not interested in the LOD functionality, but need to sample a texture array, which contains heightmaps, which are used for vertex displacement. I've read that the LOD sample method *is* compatible with the vertex shader stage, while the non-LOD is *not*. I have tried out your code with a custom node and it works with the vertex shader stage as well. For convenience, here's the complete content of a compatible hlsl file that worked for me (the variable names, types and order were taken from you above). FYI: If any novice user tries to use the node, you don't necessarily need to specify a SamplerState or lod, but just the array, index and uvs.

    Code (CSharp):
    1. //UNITY_SHADER_NO_UPGRADE
    2. #ifndef SAMPLE_TEXTURE_ARRAY_SHADER_INCLUDED
    3. #define SAMPLE_TEXTURE_ARRAY_SHADER_INCLUDED
    4.  
    5. void SampleTexture2DArray_float(Texture2DArray myTextureArray, float1 myIndex, float2 myUV, SamplerState mySampler, float1 myLOD, out float4 rgbaOut)
    6. {
    7.     rgbaOut = SAMPLE_TEXTURE2D_ARRAY_LOD(myTextureArray, mySampler, myUV, myIndex, myLOD);
    8. }
    9.  
    10. #endif //SAMPLE_TEXTURE_ARRAY_SHADER_INCLUDED
     
    Ne0mega, mangax, vertexcolor and 2 others like this.
  3. DekkerC

    DekkerC

    Joined:
    Oct 7, 2017
    Posts:
    17
    Yes it's an essential feature for me too. For Unity only support HDRP with shadergraph.
     
  4. DekkerC

    DekkerC

    Joined:
    Oct 7, 2017
    Posts:
    17
  5. meanmonkey

    meanmonkey

    Joined:
    Nov 13, 2014
    Posts:
    148
    Ok now with 2021.1.5f1 I'm at the point where the custom hlsl (SAMPLE_TEXTURE2D_ARRAY_LOD) version won't work in the dots build, it seems it won't get executed at vertex stage time for some reason. It works in the editor tho.

    Please Unity, give us the (hdrp) shadergraph version so we can use it in the vertex stage!

    Cheers
     
  6. meanmonkey

    meanmonkey

    Joined:
    Nov 13, 2014
    Posts:
    148
    I'm still waiting for this to happen
     
  7. AustinMclEctro

    AustinMclEctro

    Joined:
    May 3, 2017
    Posts:
    16
    Trying this in a custom function in Unity 2020.3.17f1 + HDRP 10.6.0 breaks with the exception:
    'SampleTexture2DArray_float': cannot convert from 'const struct UnityTexture2DArray' to 'Texture2DArray<float4>'
    .

    Any tips? I bet it's something obvious. Have been trying to figure out how to make my own Texture2DArrayLOD function, so I can sample from a Texture2DArray in a shader graph for use on mesh vertices.

    Edit: I just tried this in string form (instead of file form) and it seems to work, as in:
    rgbaOut = SAMPLE_TEXTURE2D_ARRAY_LOD(myTextureArray, mySampler, myUV, myIndex, myLOD);

    I'm not familiar with hlsl in general, so I wonder if something needs to be changed in order for this to work in an hlsl file.
     
    Last edited: Dec 7, 2021
  8. tylo

    tylo

    Joined:
    Dec 7, 2009
    Posts:
    154
    +1 for SAMPLE_TEXTURE2D_ARRAY_LOD support please. I want to access a TEXTURE2D ARRAY in the Vertex pass.

    But, in the meantime, this does work (ShaderGraph version 10.5.1, Unity Version 2020.3.4f1)

     
    Last edited: Dec 27, 2021
    TheSky, Reanimate_L and ToxicTree like this.