Skip to content

Instantly share code, notes, and snippets.

@aras-p
Last active February 29, 2020 08:12
Show Gist options
  • Select an option

  • Save aras-p/6baae168ce6f941b8691 to your computer and use it in GitHub Desktop.

Select an option

Save aras-p/6baae168ce6f941b8691 to your computer and use it in GitHub Desktop.
Basic texture array usage in shaders in Unity 5.4

You generally want this compilation target:

// uses texture arrays, so needs DX10/ES3 which is 3.5 target
#pragma target 3.5

Inside Properties block: _MyArr ("Tex", 2DArray) = "" {}

Declare the texture array sampler inside CGPROGRAM: UNITY_DECLARE_TEX2DARRAY(_MyArr);

Sample it: half4 col = UNITY_SAMPLE_TEX2DARRAY(_MyArr, uv); // uv is float3, .z is the slice

@petersvp

petersvp commented Apr 5, 2016

Copy link
Copy Markdown

In case of surface shaders, you can use something like

#ifndef SHADER_TARGET_SURFACE_ANALYSIS
UNITY_DECLARE_TEX2DARRAY(_RGBS);
#endif 

@dkyeck

dkyeck commented Jul 12, 2016

Copy link
Copy Markdown

something like UNITY_SAMPLE_TEX2DARRAY_GRAD would be great as UNITY_SAMPLE_TEX2DARRAY_LOD unfortunately produces blurry and noisy results

@slipster216

Copy link
Copy Markdown

Seconded on a _GRAD variant; could really use that right now..

@slipster216

Copy link
Copy Markdown

@dkyeck: What I'm seeing is that the results of using UNITY_SAMPLE_TEX2DARRAY_LOD look decent on OSX, but on Windows machines shimmer like mad, as if it's always sampling the highest mip level.

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