- Home /
Question by
TehFisharmahn · Jan 23, 2018 at 09:53 AM ·
shaderstexture2d
Sample Texture2dArray in vertex shader
Hello,
I'd like to ask if there is a possibility to sample a Texture2DArray in vertex shader? Normally, to sample a regular texture in vertex shader, I'd use
tex2Dlod
But since sampling Texture2DArray requires a macro (UNITY_SAMPLE_TEX2DARRAY), which encapsulates the regular tex2D used in fragment shaders, I can't use it there.
Unity documentation does not seem to hold this information - or I just can't find it.
Thanks in advance for any help!
Comment
Answer by Namey5 · Mar 06, 2020 at 01:01 AM
Most texture sampling macros Unity provides have all possible overloads as well, and if they didn't, you can just use the sampling function directly if you know what API you are building for;
//To sample a specific mip on a tex2Darray using macros (defined in "HLSLSupport.cginc");
UNITY_SAMPLE_TEX2DARRAY_LOD (_ArrayTex, float3 (uv, index), mip);
//To sample a specific mip directly with DX10+ HLSL-style syntax;
_ArrayTex.SampleLevel (sampler_ArrayTex, float3 (uv, index), mip);