3d texture sampling as black

Started by sephjfox, October 10, 2023, 01:14:28

Previous topic - Next topic

sephjfox

hello friends  8)

i am attempting to display a simple 3d texture in my scene, but the 3d texture always samples black. any idea what i could be doing wrong?

please note the line in the glsl section that sets the output pixel to green, that is used to test color placement.

// Create array
int t3dim = 32;
int[] tex3d_r = new int[t3dim*t3dim*t3dim*4];
for(int i=0;i<(t3dim*t3dim*t3dim);i++) {
	tex3d_r[i*4+0] = 0;
	tex3d_r[i*4+1] = 255;
	tex3d_r[i*4+2] = 0;
	tex3d_r[i*4+3] = 255;
}

// Create texture
int id = glGenTextures();
glActiveTexture(GL_TEXTURE0);
ARBMultitexture.glActiveTextureARB(ARBMultitexture.GL_TEXTURE0_ARB);
glClientActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_3D,id);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
glTexImage3D(GL_TEXTURE_3D, 0, GL30.GL_RGBA8, t3dim, t3dim, t3dim, 0, GL30.GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, tex3d_r);
glGenerateMipmap(GL_TEXTURE_3D);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_LOD_BIAS, 0.4f);

// Render
glUniform1i(vIndex("volumeMode"),1);
glUniform1i(vIndex("volumeMap"),6);
glActiveTexture(GL_TEXTURE0+6);
ARBMultitexture.glActiveTextureARB(ARBMultitexture.GL_TEXTURE0_ARB+6);
glClientActiveTexture(GL_TEXTURE0+6);
glBindTexture(GL_TEXTURE_3D,id);

// GLSL
uniform int volumeMode;
uniform sampler3D volumeMap;
if(volumeMode==1) {
	float xd = gl_FragCoord.x/resolution.x; // 0..1
	vec4 sc = texture(volumeMap, vec3(xd));
	//sc = vec4(0,255,0,255); // makes circle green
	sc /= 255;
	pixel = vec4(sc.xyz,1f);
}