+ 2

DirectX texture arrays

I want to do batch-rendering with OpenGL and DirectX. I have this glsl code for the fragment(pixel) shader: #version 450 core out vec4 FSOutFragColor; in vec2 VSOutTexCoords; in flat uint VSOutTexIndex; uniform sampler2D[16] u_Textures; void main() { FSOutFragColor = texture(u_Textures[VSOutTexIndex], VSOutTexCoords); } But if I try to do the same thing with hlsl's Texture2D it gives me: X3512: sampler array index must be a literal expression. (I know what the error is saying) I searched the web and didn't find any clear answers, can someone help me with this ^_^

30th Jan 2020, 4:50 PM
Light
Light - avatar
1 Odpowiedź
+ 1
Alright, so I figured it out (I asked chili on discord). " You can't dynamically index into different texture resources. The array syntax is just a convenience, the compiler has to generate hard-coded lookups for each fetch. If you want full dynamic access you either need to use texture arrays as Nik02 suggests, use a texture atlas, or use some combination of the two. so you either have to generate those hard-coded lookups yourself or use something more dynamic like a kind of atlas ". So I need to use Texture2DArray in hlsl and sampler2DArray in glsl and all the textures have to be the same size ( so I'll need to use texture atlases ).
19th Feb 2020, 11:41 AM
Light
Light - avatar