Skip to content

Instantly share code, notes, and snippets.

@aras-p
Last active February 10, 2020 19:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aras-p/a3aeac5c84ce233f6787 to your computer and use it in GitHub Desktop.
Save aras-p/a3aeac5c84ce233f6787 to your computer and use it in GitHub Desktop.
Possible texture array syntax

Unity shader side:

UNITY_DECLARE_TEX2DARRAY(name)
UNITY_SAMPLE_TEX2DARRAY(name,coord) // coord is float3

On DX11-like systems (DX11, and I'd assume XB1/PS4) the macros expand to:

#define UNITY_DECLARE_TEX2DARRAY(name) Texture2DArray(name); SamplerState sampler##name
#define UNITY_SAMPLE_TEX2DARRAY(name,coord) name.Sample(coord)

On hlsl2glsl-like systems (GL+EXT_texture_array, GLES3, Metal) the macros expand to:

#define UNITY_DECLARE_TEX2DARRAY(name) sampler2DArray name
#define UNITY_SAMPLE_TEX2DARRAY(name,coord) tex2DArray(name,coord)

and hlsl2glslfork has to learn how to parse that & emit proper GLSL. glsl-optimizer might also need minor updates, but concept of "texture arrays" should already be there

Unity code side:

I'd assume that GfxDeviceTypes.h TextureDimension needs to get a new entry for kTexDim2DArray. Review all places that have any tables sized kTexDimCount.

Shader lexer/parser probably needs a keyword for 2D arrays, i.e. shader_lex.lpp.

Shader compiler side needs to emit reflection info for 2D arrays, CompilerHLSL11.cpp etc.

GraphicsCaps needs to get a bool for whether 2D arrays are supported.

Otherwise, probably basing implementation on Texture3D.cpp/h would be good - just like texture arrays, it needs to check for hardware support, has no asset pipeline just yet (only create/fill from code), etc. Expose it to scripts in TextureBindings.txt, similar to 3D textures.

Array uploading/update code added to GfxDevice.h interface, possibly with an empty base implementation (for platforms that can't have them), again probably similar to 3D textures.

@darkmavis
Copy link

Support for this would be a huge help for our project too. Thanks!

@bastienstefani
Copy link

Hello,
I'm a bit surprised there isn't more documentation about this.
So i'm leaving a reply if it can helps anymore one day: If i got it correctly from documentation and few tests, in lieene's example, the _Index passed in the float 3 is supposed to be something the index of the last texture to be considered in the array, so if its value is 1, only the first layer will be rendered. Putting it to a higher value allow the sample more textures.
Bastien

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment