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.
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.
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.
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.
If I understand you correct, I have to set the internal format specifier to the intended value. So the following statement should specify a 2D texture with three channels and full floating point range, which would allow me to pass unclamped vec3 to the fragment shader?
I read through the OGL 2.1 reference page for glTexImage2D here at opengl.org, but I didn’t find anything about the appropriate ARB-formats, so I did a forum search and found the statement given above.
[edit]
I hope I’m not completely on the wrong track now, but if I understood the threads I read correctly, the following should also be correct and working:
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB32F_ARB, <w>, <h>, 0, GL_RGB32F_ARB, GL_FLOAT, <data>);
Is there any difference to my former solution? Does it make any difference how I specify the format of the pixel data?
As you can see, id doesn’t matter if you put GL_RGB_FLOAT32_ATI or GL_RGB32F_ARB in your code - it’s the same and your code will work, no matter which one driver supports
So, you should actually be looking at these extension specifications. You should find confirmation to whenever floats are clamped by glTexImage2D in these documents.
[EDIT]
I use the specific tokens for internal format only. For data I pass in, I only use tokens like GL_RGB, GL_RGBA etc., because there’s one more parameter there, where I pass GL_FLOAT, GL_UNSIGNED_BYTE, GL_HALF_FLOAT and others.
It works!
And the best thing is: Fetching the values from the texture is exactly as fast as using attribute/varying variables (althoug I used only 4 vec3-varyings and now I fetch up to 12 vec3 from the texture).
Thank you all,
Michael
(There is no way I can set this query as resolved, isn’t it?)