-
access floating point values from texture?
Hi,
I want to use one big texture as data container for 3D-vertices, so I can access all the values I need inside a fragment shader (I'm writing some sort of raytracer, that's why I'm doing some per-vertex calculations in the frag shader).
Does anyone know if the values of the texture will be automatically normalized to 0..1 when accessed from the frag shader? Since I don't have colors, but vertices, I need common float values!
I know this question probably sounds somewhat stupid and must have been answered somewere, but I googled and used forum search, but haven't found anything on this topic so far.
Help, please!
Michael
-
Advanced Member
Frequent Contributor
Re: access floating point values from texture?
If you use a float texture then it's not normalized to 0..1, the normalization is only for non float textures and colors.
-
Re: access floating point values from texture?
Hi zeoverlord,
thanks for your reply! Great, that means my approch will actually work? :-)
Just to be sure, with the following code I shoud be able to pass 2 vec3 with full floating point range to a fragment shader via the texture?
[CODE]
float *texData = new float[2*3];
texData[0] = 10.0f; texData[1] = 20.0f; texData[2] = 30.0f;
texData[3] = -10.0f; texData[4] = -20.0f; texData[5] = -30.0f;
glBindTexture( GL_TEXTURE_2D, texture[1]);
glTexImage2D( GL_TEXTURE_2D, 0, 3, 2, 1, 0, GL_RGB, GL_FLOAT, texData);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
[\code]
best regards, Michael
-
Advanced Member
Frequent Contributor
Re: access floating point values from texture?
No, in glTexImage2D the parameter currently set to GL_RGB determines the internal format, to get full size floats you need to use GL_RGBA32F_ARB, alternatively GL_RGBA16F_ARB if the former is not available somehow.
The "GL_FLOAT" parameter only determines in what format you are putting into the texture, not what it will end up as.
However if you only need two vec3, might i suggest using texture coords instead, they are really vec4 when you think about it.
-
Re: access floating point values from texture?
Oh, I didn't realize that I have to use GL_RGBA16F_ARB (I think the precision will be sufficient for my cause), thanks again!
I know I could simply pass the values as tex coords in theory, but I'm already using 8 vec4-varyings in my shader, so I think I don't have enough varyings left for the additional vertices I need.
-
Senior Member
OpenGL Pro
Re: access floating point values from texture?
A little correction. glTexImage2D takes two format parameters. First one is the internal format. Second is the format of data, that you pass in (texData).
glTexImage2D will perform conversion from your data to internal texture storage.
In many tutorials you'll find internal format set to 1,2,3 or 4 meaning 1-4 components.
In some tutorials you'll find GL_RGB, GL_RGBA instead.
The most accurate way is to pass GL_RGB8, GL_RGBA8, GL_RGB32F here, because otherwise, RGB8 texture may be stored internally as RGB4 by the graphics driver - they do that if you're running in 16bpp desktop mode.
Check out glTexImage2D documentation for more specific information.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules