Prof. Crawfis
12-28-2005, 06:05 PM
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:
1) Is this in the official spec, or just a safety issue with current compilers?
2) Does assembly language have the same constraints?
3) 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.
1) Is this in the official spec, or just a safety issue with current compilers?
2) Does assembly language have the same constraints?
3) 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.