3D texture problems

Started by
6 comments, last by gaurav khanduja 17 years, 6 months ago
Hi, I am having problems with the 3D textures. I have created the 3D texture of size 256 * 256 * 256 from some scalar data. It has RGBA values. The RGB values are assigned based on scalar values. The alpha value actually contains the scalar value itself clamped between 0 and 1. After clamping the values can be pretty small say 0.00002, this is just to indicate that the original scalar values have big range. When I am doing alpha test based on some reference value, I get something, but as I change the reference value I dont see continous change. For example refrence value = 0.5 initially and my alphafunc is GL_LEQUAL Now if I change the reference alpha value to 0.5001, I dont see anything And if say now I change it further down 0.5002 I may see something. This is just the example. This behaviour is actually happening for many values. I have no idea why this is happening. Any direction in this regard will be helpful Thanks Gaurav Khanduja
Advertisement
I am not sure, but are you using FP textures to store that data? If not you need to if you want to store FP values. Or else you need to use integer values 0-255 as OpenGL will convert them to 0-1 when it uses them internally.
I am just using the 3D textures from opengl. May be that is the reason. Anyway how does FP texture work, how do I store data in them and then access this value to do the alpha test.



You can use 32 bit floating point textures by specifying GL_RGBA32F_ARB instead of GL_RGBA for your internal texture format, when you create the texture via glTexImage3D(). (a complete call could look like this: glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA32F_ARB, width, height, depth, 0, GL_RGBA, GL_FLOAT, buffer); ) But you have to have in mind that these are real floats now, so you also have to provide real floats in your buffer. Also these float values are not normed to [0-1], but stay as they are. I am also not sure if the normal alpha test works on these kinda textures. You have to try that. Otherwise you can make the alpha test in a shader, there it will work fine.

Another thing: maybe you don't wanna hold your RGB values as 23 bit floats. Then it might make sense to keep a normal GL_RGB texture for the texture color and an additional GL_ALPHA32F_ARB texture only for the alpha values.
Hi

Thanks for the reply. Actually I tried it out GL_RGBA32F_ARB. and the code is giving error. It is not able to recognize this GL_RGBA32F_ARB. I would really appreciate if you could tell me how to initialize the extension so that it starts recognizing GL_ALPHA32F_ARB and GL_RGBA32F_ARB.

I also want to know that whether 3D texture will trilinear interpolate the values between the voxels. If yes do I have to enable it or it is by default. If no then I would like to know how to do it.

Third thing I would like to know is how to pass these textures to the fragment program. I am using CG and right now I am passing texture as Sampler3D ... will it be still be same if I use GL_RGBA32F_ARB and will I access the values in the same manner as I do with normal 3D texture.

Thanks
i dont know if this will help ..

but how are you allocating the array for storing the 3d texture data ?

Also GL_RGBA32F_ARB may mostly be an extension and you may have to include glext.h.

How about posting some images ?
Hi gaurav khanduja,

yes, you'll need to enable extensions. My favourite way to do that is using GLEW wich you can find here: http://glew.sourceforge.net/

You basicly just need to include the glew header and call an glewInit() and you can use OpenGL 2.0 finctionality and all extensions. Just read the infos on the page.

Yes, you can access a float texture in the same you access normal textures in a shader (via a sampler3D), so you don't have to change anything about that.

As far as I know trilinear interpolation doesn't work on 32 bit float textures up to now, so you have to set it up with GL_NEAREST. But I am not sure about what the latest cards can do, maybe somone else knows more. Also I think 16 bit float textures might be interpolated. Therefore you just use GL_RGBA16F_ARB
Hi,
Thanks ... I am not getting the problem with GL_RGBA16F_ARB.
But this is not solving my problem.

I am creating the 2 textures as follows

glGenTextures(1, &handle1);
glGenTextures(1, &handle0);

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glBindTexture(GL_TEXTURE_3D, handle1);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexEnvf(GL_TEXTURE_3D,GL_TEXTURE_ENV_MODE,GL_REPLACE);
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA16F_ARB, i_Width, i_Height, i_Depth, 0, GL_RGBA, GL_FLOAT, image1);
cgGLSetTextureParameter(cgGetNamedParameter(fragmentProgram, "diffuseMap1"), handle1);

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glBindTexture(GL_TEXTURE_3D, handle0);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexEnvf(GL_TEXTURE_3D,GL_TEXTURE_ENV_MODE,GL_REPLACE);
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, i_Width, i_Height, i_Depth, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
cgGLSetTextureParameter(cgGetNamedParameter(fragmentProgram, "diffuseMap0"), handle0);

****************
The value to the image1 are as follows
image1[t][r][0] = rho[t][r];;<br>image1[t][r][1] = 0.0;<br>image1[t][r][2] = 0.0;<br>image1[t][r][3] = alpha;<br><br>****************<br>float4 main(float3 uv : TEXCOORD0,<br> float3 uvz : TEXCOORD1, <br> uniform float3 testkey,<br> uniform sampler3D diffuseMap0,<br> uniform sampler3D diffuseMap1) : COLOR<br>{<br> float3 col = float3(tex3D(diffuseMap0, uv));<br> float4 color = tex3D(diffuseMap1, uv); <br> float val = testkey.x;<br> <br> float4 outcolor = (color.x &lt; (val + 0.001) && color.x &gt; (val - 0.001) ) ? float4(col, 1.0) : float4(1.0,0.0,0.0, 0.0);<br><br> return outcolor;<br> }<br><br>I am still having the same problem. As I increase the value of the val (testkey.x) by certain amount, I am loosing the structure. I am also not getting the structure as I am suppose to get. I am just seeing some points.<br><br>I dont know how to put the images. I will find it out today and definately do that.<br><br>Thanks<br><br>

This topic is closed to new replies.

Advertisement