Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Texture arrays in URP

Discussion in 'Universal Render Pipeline' started by Hakazaba, Sep 16, 2020.

  1. Hakazaba

    Hakazaba

    Joined:
    Jul 1, 2015
    Posts:
    119
    Hi, in unityCG you can initialize a texture array in a shader using UNITY_DECLARE_TEX2DARRAY however in URP this is unrecognized and unityCG has its own errors if you try to use it. How do i use a 2D texture array in URP shaders?
     
  2. Simon_E_Sorensen

    Simon_E_Sorensen

    Unity Technologies

    Joined:
    Feb 4, 2020
    Posts:
    10
    Hi Hakazaba,
    Great question - with URP you use:
    TEXTURE2D_ARRAY(_ArrayName); and
    SAMPLER(sampler_ArrayName);

    And to sample the array you use:
    SAMPLE_TEXTURE_2D_ARRAY(_ArrayName, sampler_ArrayName, uv-coords(IN.uv), index(0,1,2...));

    If you are interested to look at the shader API, you can look at the definitions(per platform) here: https://github.com/Unity-Technologi...unity.render-pipelines.core/ShaderLibrary/API

    Hope this helps, and if not, feel free to ask any further questions.
     
  3. Loofou

    Loofou

    Joined:
    Aug 22, 2012
    Posts:
    25
    Sorry to hijack the thread, but I have a related question:
    Do texture arrays need to be part of the cbuffer for the srp batcher to work? If so, how do we declare them properly?
     
  4. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,850
    Textures cannot be part of cbuffers.
     
  5. quizcanners

    quizcanners

    Joined:
    Feb 6, 2015
    Posts:
    108
    It should be
    SAMPLE_TEXTURE2D_ARRAY
    not
    SAMPLE_TEXTURE_2D_ARRAY
    (no underscore)

    Just to save people some time)