I have a Nvidia GeForce 6800 GS graphics card with 256 MB. My 3D application uses the following code to set up 3D texture units and uniform variables for use in the Cg fragment shader.
// texture setup in the application
gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
gl.glGenTextures(1, temp1, 0);
TextureID = temp1[0];
gl.glBindTexture(GL.GL_TEXTURE_3D, TextureID);
gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE);
gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE);
gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_R, GL.GL_CLAMP_TO_EDGE);
gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
// Generate normals
gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
gl.glGenTextures(1, temp16, 0);
normal_ID = temp16[0];
gl.glBindTexture(GL.GL_TEXTURE_3D, normal_ID);
// gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_MODULATE);
gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE);
gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE);
gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_R, GL.GL_CLAMP_TO_EDGE);
gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
// setup Cg parameters
Texture_Param = CgGL.cgGetNamedParameter(fProgram, “Texture”);
normal_Param = CgGL.cgGetNamedParameter(fProgram,“normals”);
CgGL.cgGLSetTextureParameter(Texture_Param, TextureID);
CgGL.cgGLSetTextureParameter(normal_Param, normal_ID);
CgGL.cgGLEnableTextureParameter(Texture_Param);
CgGL.cgGLEnableTextureParameter(normal_Param);
// in Display()
FloatBuffer volumeBuf = FloatBuffer.wrap(volumeBuffer);
volumeBuf.rewind();
gl.glActiveTexture(GL.GL_TEXTURE0);
gl.glEnable(GL.GL_TEXTURE_3D);
gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_OBJECT_LINEAR);
gl.glBindTexture(GL.GL_TEXTURE_3D, TextureID);
gl.glTexImage3D(GL.GL_TEXTURE_3D, 0, GL.GL_RGBA, iWidth, iHeight, iDepth,
0, GL.GL_RGBA, GL.GL_FLOAT, volumeBuf);
FloatBuffer normal_buf = FloatBuffer.wrap(normals);
normal_buf.rewind();
gl.glActiveTexture(GL.GL_TEXTURE1);
gl.glEnable(GL.GL_TEXTURE_3D);
gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_OBJECT_LINEAR);
gl.glBindTexture(GL.GL_TEXTURE_3D, normal_ID);
gl.glTexImage3D(GL.GL_TEXTURE_3D, 0, GL.GL_RGB, iWidth, iHeight, iDepth,
0, GL.GL_RGB, GL.GL_FLOAT, normal_buf);
void FragmentProgram(in float4 inTex : TEXCOORD0, out float4 oColor : COLOR0,
uniform sampler3D Texture,
uniform sampler3D normals) {
//get normal
float3 normal;
normal.rgb = tex3Dproj(normals, inTex).rgb;
// Color look up
float4 result;
result.rgba = tex3Dproj(USTexture, inTex).rgba;
… … // calculate the lighting.
oColor = result * light;
}
If I switch the order of normal and texture calculation in fragment program, i.e.
oid FragmentProgram(in float4 inTex : TEXCOORD0, out float4 oColor : COLOR0,
uniform sampler3D Texture,
uniform sampler3D normals) {
// Color look up
float4 result;
result.rgba = tex3Dproj(USTexture, inTex).rgba;
//get normal
float3 normal;
normal.rgb = tex3Dproj(normals, inTex).rgb;
… … // calculate th light.
oColor = result * light;
}
The final volume image color changed quite a lot. It turns to be an error. Does anyone have the slightest clue about what could be the reason for such behavior? Can Jogl correctly handle 3D texture sampler? Or this due to my card issue? Or my OpenGL code doesn’t setup 3D texture appropriately?
Thanks.