PDA

View Full Version : problem with shader



AdrianPi
11-25-2009, 10:38 AM
Hi there. I have the following fragment shader:


uniform sampler2D maskMap;
uniform sampler2DArray splats;

void main()
{
vec4 tc = gl_TexCoord[0];
vec4 masks = texture2D(maskMap, tc);
tc.z = 0;
vec4 base = texture2DArray(splats, tc);
tc.z = 1;
vec4 color1 = texture2DArray(splats, tc);
vec4 color = mix(base, color1, masks.r);
gl_FragColor = color;
}

That is supposed to mix base and color1 from two textures in the texture array according to a mask in the red channel of the first texture. But it does not produce the expected mix, instead a uniform mix as if a constant value is passed is produced.

However if I change the texture array lookups by a constant color, the correct output is produced:


uniform sampler2D maskMap;
uniform sampler2DArray splats;

void main()
{
vec4 tc = gl_TexCoord[0];
vec4 masks = texture2D(maskMap, tc);
tc.z = 0;
vec4 base = vec4(1,0,0,1);
tc.z = 1;
vec4 color1 = vec4(0,0,1,1);
vec4 color = mix(base, color1, masks.r);
gl_FragColor = color;
}

Any idea of what I'm doing wrong?

AdrianPi
11-25-2009, 10:57 AM
Fixed, it was bug when setting sampler uniforms.