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

Question Texture2D Arrays, get textures count

Discussion in 'Shader Graph' started by Alesk, Apr 12, 2020.

  1. Alesk

    Alesk

    Joined:
    Jul 15, 2010
    Posts:
    339
    Hi !

    I'm wondering how I could get the number of textures stored in a Texture2D Array ... It seems there is no node to get this information :/
     
  2. andywatts

    andywatts

    Joined:
    Sep 19, 2015
    Posts:
    110
    I use an array of bools to keep track of used tex2darray elements.
     
  3. Alesk

    Alesk

    Joined:
    Jul 15, 2010
    Posts:
    339
    Sorry, I don't understand what you mean ;p

    Here I'm talking about a node in the Shader Graph.
    I've created a Texture2DArray asset with 30 textures in it.
    When I assign this asset to a Texture2DArray node in the shader graph, I would like to get this 30 value from a node, and not using any script outside.
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    There is no node, or any built in functionality for this even outside of Shader Graph that I'm aware of.

    If you only need this for Direct3D 11 you could use a custom function node to get this information in the shader.
    upload_2020-4-13_0-29-42.png
    Code (csharp):
    1. Tex2DArray.GetDimensions(Width, Height, Elements);
     
    andywatts and Alesk like this.
  5. Alesk

    Alesk

    Joined:
    Jul 15, 2010
    Posts:
    339
    Thank you so much ! :)
     
  6. Alesk

    Alesk

    Joined:
    Jul 15, 2010
    Posts:
    339
    HA ! No !
    This is not working for me ... The "Elements" output gives 0 :(
    I'm under Linux, could this be the cause ? (some kind of incompatibility with a DX11 function)
     
    Last edited: Apr 13, 2020
  7. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    Yep, that’s why I said “only for Direct3D 11”. Linux means OpenGL or Vulkan.
     
  8. Alesk

    Alesk

    Joined:
    Jul 15, 2010
    Posts:
    339
    Ok ! Thanks !
    I suppose there is no workaround for that ?
     
  9. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    The usually work around is to write a c# script to set the value on the material when you assign the texture array. But there’s not really a good way to do that with texture arrays assigned not via script.
     
  10. Alesk

    Alesk

    Joined:
    Jul 15, 2010
    Posts:
    339
    Ok thanks !
    I'll do that ;)