Windows 7 Ult 64-bit SP1
TD 088 build 62160
GLSL version 4.00
This is what I expect to work in the GLSL MAT pixel shader, with my sampler array starting at index of 0. There is no compilation error or TD error doing this, but the sampler I assign to index 0 is just invisible as if i don’t have a sampler at all, RGBA = 0000. While Indexes 1-3 sample and render just fine.
[code]// Init instanced normal map array
const int numInstances = 4;
uniform sampler2D sNormalMap[numInstances];
sampler2D sNormalIndex;
void main(){
// omitted unrelated code //
// Assign normal map with instance texture index
for (int i = 0; i < numInstances; i++ )
{
if ( vVert.texIndex == i)
{
sNormalIndex = sNormalMap[i];
}
}
vec4 normalMap = texture(sampler2D(sNormalIndex), texCoord0.st);
[/code]
This is the workaround I’m using to avoid the issue --increasing the array size by 1, with no sampler assigned to index 0, offsetting the for loop, so I am able to use indexes 1-4.
[code]// Init instanced normal map array
const int numInstances = 5;
uniform sampler2D sNormalMap[numInstances];
sampler2D sNormalIndex;
void main(){
// omitted unrelated code //
// Assign normal map with instance texture index
for (int i = 0; i < numInstances-1; i++ )
{
if ( vVert.texIndex == i)
{
sNormalIndex = sNormalMap[i+1];
}
}
vec4 normalMap = texture(sampler2D(sNormalIndex), texCoord0.st);
[/code]
Seems like a bug… but maybe there is some reason for this behaviour or some GLSL limitation with Sampler arrays.
P.S. The reason I am instancing Normal map textures this way is because am I already instancing Color map textures with TDInstanceTexture2D().
I am also unable to stack both Color and Normal maps into one texture split out in the shader by UV for instancing because I need nearest neighbour for the Color map (alpha channel is a vertex displacement map) but linear filtering for the Normal map.
Thanks