Jump to content
  • Advertisement
Sign in to follow this  
CelticDaddio

Floating Point Texture Mapping

This topic is 3561 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

I am trying to use a float texture as a 1D lookup table. I had originally put my data in a 2D texture, but I did not get the results I thought I should, so instead of trying to determine if my 1D-to-2D conversion was messed up or the texture data was messed up I decided to back off and do a simple test with a 1D texture. That gave me the same results. So now, I am just trying to texture map a floating point texture to a quad. I see the same thing as when trying to do a 1D LUT. Every texel I retrieve from the texture is rgb = (0.0,0.0,0.0). I am using imdebug to look at the texture data before I stuff into the texture object, and it looks fine, but it doesn't look like the data is in the texture or something. In my current test app, I modified a texture mapping sample I found online. I modified it to create two different textures at runtime, rather than loading an image file. The float texture is created like this:
int texTarget			= GL_TEXTURE_2D;
int texInternalFormat	= GL_FLOAT_RGBA32_NV;
int texFormat			= GL_RGBA;

glGenTextures( 1, &g_FloatTextureID );
glBindTexture( texTarget, g_FloatTextureID );

int textureWidth   = 256;
int textureHeight  = 256;
int textureSize    = textureWidth * textureHeight;
int textureMemSize = textureWidth * textureHeight * 4 * format2components(texInternalFormat);

GLfloat *rgbaTextureData = new GLfloat[textureMemSize];

int index = 0;
int nRow  = 0;
int nCol  = 0;

unsigned long int nIndex = 0;
unsigned long int nTexelIndex = 0;

for(int nRow = 0; nRow < textureHeight; nRow++) {
	for(int nCol = 0; nCol < textureWidth; nCol++) {

		nIndex = textureWidth * nRow + nCol;
		nTexelIndex = 4*nIndex;

		rgbaTextureData[nTexelIndex + 0] = 2550.0;	
		rgbaTextureData[nTexelIndex + 1] = 2550.0;	
		rgbaTextureData[nTexelIndex + 2] = 2550.0;	
		rgbaTextureData[nTexelIndex + 3] = 2550.0;	
	}
}

glTexImage2D(texTarget, 
	 0, 
	 texInternalFormat,
	 textureWidth, 
	 textureHeight,
	 0, 
	 texFormat, 
	 GL_FLOAT, 
	 rgbaTextureData);

glTexParameteri(texTarget, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(texTarget, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(texTarget, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(texTarget, GL_TEXTURE_WRAP_T, GL_CLAMP);

delete [] rgbaTextureData;
rgbaTextureData = 0;

I set my texture locations like this:
glActiveTexture(GL_TEXTURE1);
glEnable(GL_TEXTURE_2D);
glBindTexture( GL_TEXTURE_2D, g_FloatTextureID );
if( g_FloatTexture_Location != -1 )
   glUniform1i(g_FloatTexture_Location, 1); 

And my frag shader looks like this:
uniform sampler2D floatTexture;

void main( void )
{   
   // When not comment out... this doesn't
   gl_FragColor = texture2D( floatTexture, gl_TexCoord[0].xy );
}

I don't see what I am doing wrong.... Any suggestions? CB

Share this post


Link to post
Share on other sites
Advertisement
int texInternalFormat = GL_FLOAT_RGBA32_NV;
int textureWidth = 256;
int textureHeight = 256;
int textureSize = textureWidth * textureHeight;
int textureMemSize = textureWidth * textureHeight * 4 * format2components(texInternalFormat);

GLfloat *rgbaTextureData = new GLfloat[textureMemSize];

What is format2components? Because GL_FLOAT_RGBA32_NV = 34955...
So, 256*256*4*34955? Is that what you are after? Because if I am reading that right, thats like 9GB's!

Share this post


Link to post
Share on other sites
format2components returns the number of components per texel... In the case of GL_FLOAT_RGBA32_NV it returns 4, since there are four components per texel... R,G,B, and A.


Quote:
Original post by MARS_999
int texInternalFormat = GL_FLOAT_RGBA32_NV;
int textureWidth = 256;
int textureHeight = 256;
int textureSize = textureWidth * textureHeight;
int textureMemSize = textureWidth * textureHeight * 4 * format2components(texInternalFormat);

GLfloat *rgbaTextureData = new GLfloat[textureMemSize];

What is format2components? Because GL_FLOAT_RGBA32_NV = 34955...
So, 256*256*4*34955? Is that what you are after? Because if I am reading that right, thats like 9GB's!


Share this post


Link to post
Share on other sites
Ok... I still can't see what is wrong here.... would anyone be willing to run this code and see what might be wrong? I know that is a lot to ask, but I am out of ideas....
Thanks,
CB

I placed the code in zip file here:

http://www.celticblues.com/code/glslTextureMapping.zip

Share this post


Link to post
Share on other sites
WEll if you are returning 4 then why do you do

int textureMemSize = textureWidth * textureHeight * 4 * format2components(texInternalFormat);

You already have 4 in that equation...

Share this post


Link to post
Share on other sites
width pixels * height pixels * 4 (bytes per float) * 4 components...

But looking at my code, that 4 bytes per float part isn't necessary since I am allocating the texture memory via new GLfloat[memsize]. It must have been a hold over from when I was using malloc....


CB

Quote:
Original post by MARS_999
WEll if you are returning 4 then why do you do

int textureMemSize = textureWidth * textureHeight * 4 * format2components(texInternalFormat);

You already have 4 in that equation...


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!