hello,
im trying to use a lookup table to remap the values of a 3d texture to some function… However i seem to be getting some errors even with the simplest of functions ie: (linear)…
here is the 3d texture loading code:
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glextensions.glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, volobj->texwidth, volobj->texheight, volobj->texdepth, 0, GL_RGBA, GL_UNSIGNED_BYTE, volobj->texture3d);
Note volobj->texture3d is of type unsigned char.
Next i upload my lookup table;
glBindTexture(GL_TEXTURE_2D, 1);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, &rgb_tfunc[0]);
Again rgb_tfunc is of type unsigned and is linear ie: 0 → 255.
Then in my shader i do the following:
//get the texture rgb data
vec4 texValue = texture3D(volumeTexture, gl_TexCoord[0].stp);
//get lookup table values for the texValue
RGBlookupValue.x = (texture2D(RGBlookupTexture, vec2(texValue.x, 0.0))).x;
RGBlookupValue.y = (texture2D(RGBlookupTexture, vec2(texValue.y, 0.0))).y;
RGBlookupValue.z = (texture2D(RGBlookupTexture, vec2(texValue.z, 0.0))).z;
//check if values are the same.
if(texValue.x!=RGBlookupValue.x)
{
finalColour.x = 1.0;
finalColour.y = 1.0;
finalColour.z = 0.0;
finalColour.w = 1.0;
}
And what i seem to get is that it works fine unless my 3d texture value is equal or above 240. If the later is true then my if statement is true. Thought it could be some clamping issue, but tried repeat & mirrored with no luck, also tried to set the 3d texture filter to nearest too, but appart from making everything look horrible still have the problem.
Im out of ideas, any help would be greatful.
Thanks,
ut.