I have a fragment shader where I select one of several texture units to sample. Unfortunately, using a non-constant to index the sampler array results in a compile time error (nVidia, but also I believe on ATI). Three questions:
Is this in the official spec, or just a safety issue with current compilers?
Does assembly language have the same constraints?
Any chance this is going to change?
Currently, I have a massive if-else statement to test for which texture unit. What I would like is something like this (which 3DLabs GLSL Validator indicates is fine):
uniform sampler2D myTextures[4];
uniform float myValue;
void main( void ){
float fUnit = log2(myValue);
int unit = int( min(max(myValue,3),0) );
gl_FragColor = tex2D( myTextures[unit], gl_TexCoord[0].st );
}
Roger
p.s. How do you get extra white space in these posts? I lost the indenting above.
Is this in the official spec, or just a safety issue with current compilers?
I can’t see it in the spec. The hardware probably just can’t support it. FYI: last time I even tried to use uniform sampler arrays on ATI (about a month ago) it crashed the driver. (even with a constant offset)
Does assembly language have the same constraints?
Reasonably sure that no ASM version supports runtime determination of texture lookups.
Originally posted by sqrt[-1]:
[b]1) Is this in the official spec, or just a safety issue with current compilers?
I can’t see it in the spec. The hardware probably just can’t support it.
[/b]
I was surprised by this at first, indexing an array is pretty common. However the generated assembly language for nVidia looks like:
TEX R1, fragment.texcoord[2], texture[2], 2D;
which isn’t very assembly-language looking, so something very special with samplers is going on.