Sign in to follow this  

3D texture problems

This topic is 4092 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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[s][t][r][0] = rho[s][t][r];;
image1[s][t][r][1] = 0.0;
image1[s][t][r][2] = 0.0;
image1[s][t][r][3] = alpha;

****************
float4 main(float3 uv : TEXCOORD0,
float3 uvz : TEXCOORD1,
uniform float3 testkey,
uniform sampler3D diffuseMap0,
uniform sampler3D diffuseMap1) : COLOR
{
float3 col = float3(tex3D(diffuseMap0, uv));
float4 color = tex3D(diffuseMap1, uv);
float val = testkey.x;

float4 outcolor = (color.x < (val + 0.001) && color.x > (val - 0.001) ) ? float4(col, 1.0) : float4(1.0,0.0,0.0, 0.0);

return outcolor;
}

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.

I dont know how to put the images. I will find it out today and definately do that.

Thanks

Share this post


Link to post
Share on other sites

This topic is 4092 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this