View Full Version : Texture understanding problem

11-17-2005, 12:23 AM
I am binding a 3d and a 1d texture and am passing them to the fragment shader.
in my 1d texture are values saying how strong the values out of the 3d texture are weighted.

ie: color = ValueFrom1D * ValueFrom3D

when i display the color without "valuefrom1d" a color apperas, whereas when i mulitply it wiht "valuefrom1d" my screen stays black. first idea, the texture only has 0 in it. but it hasen't.

in my main program i am setting up the texture coords to a quad.

glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0, 1.0);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0, 1.0);
glVertex3f(0.0, 0.0, 0.0);

glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0, 0.0);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0, 0.0);
glVertex3f(0.0, size*1.0, 0.0);

glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0, 0.0);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0, 0.0);
glVertex3f(size*1.0, size*1.0, 0.0);

glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0, 1.0);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0, 1.0);
glVertex3f(size*1.0, 0.0, 0.0);
for that i am not sure if im am setting the GL_TEXTURE1_ARB up correctly (this is the 1d texture, array actually)
also i pass the coord on throgh my vertex shader.

gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[1] = gl_MultiTexCoord1;
in my understanding i should be able now to access the values of my 1d texture appropriatly in the fragment shader.

uniform sampler3D Texel;
uniform sampler1D Eigen;

void main(void)
vec3 texval;
vec3 color;
float eigen;

for(float i=0.0; i < 1.0; i+=1.0/200.0)
texval = texture3D(Texel, vec3((gl_TexCoord[0]).st,i)).rgb;
eigen = texture1D(Eigen, i);
color += texval*eigen;

gl_FragColor = vec4(color, 1.0);
the step of 1.0/200.0 is because the 3d texture is 200 layers deep and the 1 d texture has 200 entries, for each layer one.
but when i run the app like this only a black screen appears.
when i set the color to:

color += texval;
my values out of the 3d texture are summed up and displayed properly (not black)
now i am not quite sure if i map my texture coords properly

11-17-2005, 04:49 AM
- Is the shader compiling correctly?
- Did you set the samplers to the correct texture units?
Default is, both point to 0 and that's not possible with different texture targets, which would fail to run with an INVALID_OPERATION error (I think).
- A 1D texture doesn't mean your texture data is only one component! So I guess you used a 1D luminance texture?
Check the OpenGL specs how luminance is mapped to RGBA when fetched from a texture.
More correct would be to use vec3 eigen or vec3(texture1D(Eigen, i).r);
- Optimization: Your multitexture coordinates are the same, no need to use both attributes if that remains this way.
- glTexCoord[1] is not used.
- color is not initialized to vec3(0.0).

11-17-2005, 05:31 AM
thanks a lot for your reply.
with your help i found the mistake. in my glTexImage1D i used GL_ALPHA as identifier and not GL_LUMINANCE
cheers mate