PDA

View Full Version : Texture Mapping - LUT does not work



djuiced
11-26-2010, 05:37 AM
Hello World,

since this is my first post I may introduce myself. I'm 27 years of age and studying Medical Informatics at the University of Heidelberg (germany). I began playing around with opengl half a year ago and did some smaller tutorials 1 1/2 year ago.

As part of my bachelorthesis I had to write a volume rendering program to display 3D medical data (with java and jogl). I realized it via texture mapping and 3D textures. The transferfunction was applied by glPixelTransfer to the color indices in the 3D tex and everything worked just fine. That was the final version for my thesis (see pictures).

A few weeks ago I started to enhance the program and tried to implement new features (2D TF, Phong Shading,...). I realizied that I needed to look into shaders in order to get those things working.

Lets start with the problem: I got a 3D-Alpha texture containing the volumetric data and a 1D-RGBA texture containing the corresponding color for each alpha value. The problem ist that the 1D-texture does not affect the output (see pictures).

I've checked the shader and if I type something like glFragColor = vec4(1.0,0.0,0.0,1.0) I'll get a red cube. Even if I try for example vec4 texel = texture3D(data, texcoord) and take the alpha value of texel and code a mini transferfunction in the glsl shader I get reasonable results (see pictures). But using the LUT with glFragColor = texture1D(tfunc, texel.a) does not change anything, even if I want to create an error with texture1D(<name of sampler texture that does not exist>, texel.a) the image does not change. Another fact is that without mipmapping I get to see nothing. The result seems to be a malfunctioned version of the 3D texture but not assigned colors by the 1d tex.

upload of 3d alpha texture:
<div class="ubbcode-block"><div class="ubbcode-header">Click to reveal.. <input type="button" class="form-button" value="Show me!" onclick="toggle_spoiler(this, 'Yikes, my eyes!', 'Show me!')" />]<div style="display: none;">
if (volren.getTextureID() == UNDEFINED_TEXTURE_ID) {
volren.setTextureID(this.generateTextureID(gl));
}
gl.glBindTexture(GL2.GL_TEXTURE_3D, volren.getTextureID());
gl.glTexParameteri(GL2.GL_TEXTURE_3D, GL2.GL_TEXTURE_WRAP_R, GL2.GL_CLAMP);
gl.glTexParameteri(GL2.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_S,
GL2.GL_CLAMP);
gl.glTexParameteri(GL2.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_T,
GL2.GL_CLAMP);
gl.glTexParameteri(GL2.GL_TEXTURE_3D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
gl.glTexParameteri(GL2.GL_TEXTURE_3D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR_MIPMAP_LINEAR);
gl.glTexParameteri(GL2.GL_TEXTURE_3D, GL2.GL_GENERATE_MIPMAP,
GL.GL_TRUE);
gl.glTexImage3D(GL2.GL_TEXTURE_3D, 0, GL2.GL_ALPHA, volren.getVolume().getMetaData().getDimx(), volren.getVolume().getMetaData().getDimy(), volren.getVolume().getMetaData().getDimz(), 0, GL2.GL_ALPHA, GL.GL_UNSIGNED_BYTE, volren.getTexel());
[/QUOTE]</div>

upload of 1d rgba transferfunction:
<div class="ubbcode-block"><div class="ubbcode-header">Click to reveal.. <input type="button" class="form-button" value="Show me!" onclick="toggle_spoiler(this, 'Yikes, my eyes!', 'Show me!')" />]<div style="display: none;">
if (this.textureID == AbstractVolumeRenderer.UNDEFINED_TEXTURE_ID) {
this.textureID = this.generateTextureID(gl);
}
gl.glBindTexture(GL2.GL_TEXTURE_1D, this.textureID);
gl.glTexParameteri(GL2.GL_TEXTURE_1D, GL.GL_TEXTURE_WRAP_S,
GL.GL_CLAMP_TO_EDGE);
gl.glTexParameteri(GL2.GL_TEXTURE_1D, GL.GL_TEXTURE_MAG_FILTER,GL.GL_LINEAR); gl.glTexParameteri(GL2.GL_TEXTURE_1D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR_MIPMAP_LINEAR);
gl.glTexParameteri(GL2.GL_TEXTURE_1D, GL2.GL_GENERATE_MIPMAP,
GL.GL_TRUE);
gl.glTexImage1D(GL2.GL_TEXTURE_1D, 0, GL.GL_RGBA, this.size, 0, GL2.GL_RGBA, GL.GL_UNSIGNED_BYTE, this.createTexel());
[/QUOTE]</div>

part of proxy geometry rendering code (binding textures and shaders):
<div class="ubbcode-block"><div class="ubbcode-header">Click to reveal.. <input type="button" class="form-button" value="Show me!" onclick="toggle_spoiler(this, 'Yikes, my eyes!', 'Show me!')" />]<div style="display: none;">
gl.glActiveTexture(GL.GL_TEXTURE0);
this.bindDataTexture(gl, volumeRenderable);
volShade.setDataTexID(0);
gl.glActiveTexture(GL.GL_TEXTURE1);
this.tfunction.bindTfuncTexture(gl);
volShade.setTfTexID(1);
enableClippingPlanes(gl, volumeRenderable);
volShade.start(gl);
gl.glActiveTexture(GL.GL_TEXTURE0);
//start drawing textured quads slicing through the bounding box of the 3d volume texture
gl.glBegin(GL2.GL_QUADS);
.
.
gl.glTexCoord3d(x * p.get(0), y * p.get(1), z * p.get(2));
gl.glVertex3dv(p);
.
[/QUOTE]</div>

I really hope that someone will look into this problem and that the detailed information will help and won't be too confusing. This problem is really killing me since weeks. If you need further informations just tell me.

Further informations about my system:
<div class="ubbcode-block"><div class="ubbcode-header">Click to reveal.. <input type="button" class="form-button" value="Show me!" onclick="toggle_spoiler(this, 'Yikes, my eyes!', 'Show me!')" />]<div style="display: none;">
OS: Windows 7 64bit
Java: Java 1.6.0_16
Jogl: 2.0
Gfx: Nvidia 9600GT (Driver 260.99_notebook_winvista_win7_64bit)
[/QUOTE]</div>

thanks and best regards

def
11-27-2010, 04:43 AM
Setting up the multiple samplers probably does not work. Are you binding to the correct texture targets, 1d and 3d?
Use glGetError() to check for errors after each gl call during setup or use some gl debug tool (glintercept).

djuiced
11-30-2010, 10:14 AM
I've found the mistake. I can't believe this took me so long to find, I did a mistake at the initializing stage of the shader which caused the malfunction. shame on me, but thx for the help