Accessing gl_TexCoord[0].p

I need to check if i am on the first layer of my 3d texture.
In my vertex shader i simpy make the transforms for the fragment shader

void main(void)
    gl_TexCoord[0] = gl_MultiTexCoord0;

    gl_Position = ftransform();

in my fragment shader i only want to write the image of layer 0 of my 3d texture to the framebuffer

uniform sampler3D A;

void main(void)
     vec3 texval = texture3D(A, gl_TexCoord[0].stp).rgb;

     gl_FragColor = vec4 (texval.rgb, 1.0);   

to my astonishment the shader never enters the if loop, as if my p never would be 0.0
after my understanding p ought to be 0 for at least sxt pixels, hence i assume i am not accessing the right variable.
If anybody knows what i am doing wrong i’d appreciate an answer.

Two questions:
1)Are you sure you are setting the texture coordinate p somewhere when you are sourcing data from a vertex buffer.

  1. Comparing floats with equals is usually hit and miss. Use less-than-or-equal (small value)
  1. What are you expecting to happen when gl_TexCoord[0].p != 0.0? If you don’t want to write a value to the framebuffer you must kill the fragment. As it’s written right now the result is just undefined, but a value will certainly be written. It may just as well be the same value as if gl_TexCoord[0].p == 0.0. What you want is probably something closer to this:
if (gl_TexCoord[0].p != 0.0) discard;
gl_FragColor = vec4(texval.rgb, 1.0);

to 3) i assumed the fragcolor will be set to the clearcolor defined in my main.

to 2) i can’t figure out how “equal” works on floats.

to 1) i didn’t quite understand your answer.

to summarise: in my first layer of my 3d textures lay around 40000 texel information to an according vertex of a shape of a head. in every following layer come other 40000 texels belonging to other textures of heads. i can build linear combinations of the textures and add them to each other, this works beacause my data is in correlation. to boost performance i am trying to implement this on the gpu. since it is not possible to load 200 arrays of a size 1x40000 into texture memory, i am filling the information in a 3d texture (since max size is 512x512x512 on my system). in order to weight the different layers differently (linear combination) i need to know in what depths of the 3d texture i am so that i can multiply the texels with the according coefficient.
Moreover I think best solution is to use glTexSubImage3D(), to access the proper layer.

does any of you know if it is possible to load textures of different dimensions using multitexturing. ie binding a 3d texture to unit0 and a 1d texture to unit1?

Originally posted by cof

to 1) i didn’t quite understand your answer.

What he means is that you are using gl_MultiTexCoord0 (built in uniform) in your vertex shader. You will have to specify this value per-vertex from your application (like glTexCoord2f(…)), otherwise you’ll be getting junk values.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.