Skip to main content
GameDev.net gamedev.net
🔒 Locked

GLSL float texture

Started by Runt8888 Feb 26, 2009 at 2:36 PM 4 replies 5.4k views
Original Post
Runt8888
Runt8888
Hello, I an attempting to draw pre-rendered color and depth data to the framebuffer so that it interacts correctly with geometry. To simplify the problem, lets say I have a single RGBA buffer with color data, and a single float buffer with depth data (and by buffers, I mean a standard C++ style buffer). All I want to do is quickly draw this data to the framebuffer, then draw some geometry and have it intersect correctly. I started out using a textured quad to draw the color data, and glDrawPixels to fill the depth buffer. This worked correctly, however when zoom factors less than 1.0 are used, all nVidia cards that I tested slowed down to a crawl (obviously they were dropping down to software rendering when scaling down float data). After a ton of research, the only other method I was able to find to fill the depth buffer was to use shaders. So I started experimenting with GLSL and float textures. So far I've tried the following: 1. Using a GL_DEPTH_COMPONENT texture and the shadow functions to access the depth values in the shader. This works perfectly on nVidia cards, but not at all on ATI cards. It's very possibly that I was just doing something incorrectly and that was why the ATI cards weren't working, so if you think this should work then a small sample would be very appreciated! 2. Using a GL_LUMINANCE32F_ARB/GL_LUMINANCE_FLOAT32_ATI texture and the standard texture accessors in the shader. This worked perfectly for cards that supported the necessary extensions, however we have several older Quadro cards that we need to support that don't have any floating point texture extensions (other than the ARB_depth_texture extension). Now I'm attempting to encode the float depth values in a standard RGBA texture, but I'm having difficulties getting the float values correct in the shader without any bitwise operators. I've seen code floating around that uses GLSL to encode and decode a float value to 4 int8 values, but I am trying to avoid having to manipulate the float buffer that I have (the depth values change fairly frequently, so it would be a time consuming process to have to encode the entire float buffer into a different int8 buffer before passing it to the texture). So finally my question - is it possible to pass a C++ float buffer to a RGBA texture, and get back the float values in a fragment shader? I realize that with what I already have working, it would be possible to have separate render paths that would work based on what the hardware supports, but I would prefer to keep the rendering code as simple as possible. If there is a way to use a standard RGBA texture for float values, then I figure that would be the most supported solution. Sorry for the long post! I would appreciate any suggestions or examples! Kelly
BionicBytes
BionicBytes
Sorry to say this, but to me at least, it not really very clear what you are trying to do. Still, I shall try to read-between the lines.

By C++ buffer - do you just mean an array of data of some sort?
Anyway - I think you really want to look at OpenGL FrameBufferObjects (FBO) objects. Using a FBO allows you to attach a texture as a drawable surface. So you could simply create a texture -from a RGBA filled C++ array. Then attach this texture as a COLOR texture to the FBO. You can also do this with the DEPTH texture as well. Once the FBO is attached with the COLOR and DEPTH - it becomes the current receiver of all rendering operations until the FBO unbound.

Best of all these buffers can be specified as floats.

Runt8888
Runt8888
Sorry I wasn't more clear.

Basically, in the end I just want a fast way to fill the depth buffer with floating point data that I have in a C++ array.

A little more specifically, I want to know how to access the floating point data in a GLSL shader.

I looked into using FBOs, but at first glance they didn't seem to be able to accomplish what I needed, and I don't think all of the cards we need to support will have them.
V-man
V-man
Just make a floating point texture
http://www.opengl.org/wiki/Floating_point_and_mipmapping_and_filtering
Runt8888
Runt8888
Thanks for the reply. I tried that (see #2 in my first post) and it worked fine for machines that support the extension.

However, we need this to work on an older series of Quadro cards that don't support the ARB_float_texture extension.

Kelly
V-man
V-man
In that case just convert the float values to integer and call
glTexImage(...., GL_RGBA8, .....)
or perhaps you can try one of the other formats like GL_RGBA16

The ref pages list the formats
http://opengl.org/sdk/docs/man/

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.