Sign in to follow this  
sveinn

Store world positions in a texture

Recommended Posts

Does anyone know how to store world positions ( a 3d vector of integer values where each coordinate is in the range say [-300,300] ) in a texture instead of color values. Specifically, I would output the position of each fragment in the fragment shader instead of its color, then store that in a texture. It seems like the storage format of textures (according to glTexImage2D description) is always clamped to the range [0,1]. Do I perhaps need some fancy extension to implement this? Thanks for your time, -Sveinn

Share this post


Link to post
Share on other sites
I've been trying to use GL_RGBA32F_ARB (from the ARB_texture_float
extension) but unfortunately the results are still clamped to [0,1]. Specifically this is how I create my texture:


glTexImage2D ( GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, texture_width, texture_height, 0, GL_RGBA, GL_FLOAT, pixels)


Then I render everything using shaders, for testing I set the output color in my fragment shader to float4(0.1234, 2.0, 3.0, 4.0). When I look at the output in my texture using:


glGetTexImage( GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, pixels )


I get (0.1234, 1.0, 1.0, 1.0), which is a kick in the balls.

When searching for similar issues I found suggestions to use the following function calls, which are supposed to disable color clamping ( it's from the ARB_color_buffer_float extension ):

glClampColorARB(GL_CLAMP_VERTEX_COLOR_ARB, GL_FALSE);
glClampColorARB(GL_CLAMP_READ_COLOR_ARB, GL_FALSE);
glClampColorARB(GL_CLAMP_FRAGMENT_COLOR_ARB, GL_FALSE);

Tried those out, no luck, everything clamped tight..

I should mention that I'm on a Mac (9600M GT) and some Mac people (8600 by the looks of it) say that they couldn't use the glClampColorARB. However everything did compile and run without errors so I assume the extension is supported on my platform/hardware, not sure though..


Any ideas on how this can be solved?

Share this post


Link to post
Share on other sites
Haven't used this extension before so not really :) I would check for the extension string to make sure - just compiling doesn't guarantee anything, and it may be giving you a lower-grade texture at run-time if float is not available. Based on your description, I take it you are rendering to a texture attached to a FBO?

Share this post


Link to post
Share on other sites
Ok.

Actually, I am just copying from the back-buffer into a texture. I am gonna try out FBOs now ( total newbie here :)

Share this post


Link to post
Share on other sites
Quote:
Original post by sveinn
I've been trying to use GL_RGBA32F_ARB (from the ARB_texture_float
extension) but unfortunately the results are still clamped to [0,1]. Specifically this is how I create my texture:

glTexImage2D ( GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, texture_width, texture_height, 0, GL_RGBA, GL_FLOAT, pixels)

Then I render everything using shaders, for testing I set the output color in my fragment shader to float4(0.1234, 2.0, 3.0, 4.0). When I look at the output in my texture using:

glGetTexImage( GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, pixels )

I get (0.1234, 1.0, 1.0, 1.0), which is a kick in the balls.
Try checking that you do indeed receive a float texture (OpenGL is free to fall back to 8-bit textures if it can't support floating point textures):
nformat = GLint()
glGetTexLevelParameteriv(target, 0, GL_TEXTURE_INTERNAL_FORMAT, byref(nformat))

if nformat.value != internal_format:
print 'requested format not available, falling back to: %s' % (nformat.value)


Quote:
When searching for similar issues I found suggestions to use the following function calls, which are supposed to disable color clamping ( it's from the ARB_color_buffer_float extension ):

glClampColorARB(GL_CLAMP_VERTEX_COLOR_ARB, GL_FALSE);
glClampColorARB(GL_CLAMP_READ_COLOR_ARB, GL_FALSE);
glClampColorARB(GL_CLAMP_FRAGMENT_COLOR_ARB, GL_FALSE);

Tried those out, no luck, everything clamped tight..

I should mention that I'm on a Mac (9600M GT) and some Mac people (8600 by the looks of it) say that they couldn't use the glClampColorARB. However everything did compile and run without errors so I assume the extension is supported on my platform/hardware, not sure though.
glClampColorARB only affects vertex colours, not textures.
Quote:
Actually, I am just copying from the back-buffer into a texture. I am gonna try out FBOs now ( total newbie here :)
Ah, this will be your problem. The backbuffer is always clamped, no matter what format it is in. You need to render directly to your texture, using an FBO.

Share this post


Link to post
Share on other sites
Beautiful! That's exactly the problem. Render directly to texture using FBO works like a charm :D

Finally I can go to bed.. thanks for your help guys!


[EDIT:
Since I am a newbie this came in handy, FBO intro:
http://www.gamedev.net/reference/programming/features/fbo1/default.asp

As well as:
http://www.songho.ca/opengl/gl_fbo.html
]

Share this post


Link to post
Share on other sites

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