View Full Version : Simple Multitexturing Question
03-18-2005, 09:21 AM
Okay, I store 2 textures, 512*512 containing pixel values ranging from -1.0 to 1.0. I am using GL_ADD.
The results are not as expected. Multitexturing code is fine.
I was under the impression that the pixel values were not capped to [0,1] until they were interpolated.
03-18-2005, 11:43 AM
Could you be a little more specific?
for example: how are they not as expected?
03-18-2005, 12:07 PM
I am rendering the representation of two cosine functions, in each texture. Simplest version, 2nd tecture contains Cos + phase angle => Pi.
Basically generating strips of black and white with transitions. If I combine(add these two textures), I do not get all black. As I should.
Now I know the values get clamped to 0,1, which means this might not work, but I assume values were clamped after texture operations, so my textures could contain negative values, and adding them would produce the right result.
03-19-2005, 06:23 AM
Colors values are indeed clamped to [0,1] when stored to textures.
ex, typical RGBA texture : each component is an unsigned byte going through 0 to 255, for intensities in the |0.0, 1.0] range.
The common trick is shifting values from [-1,1] to [0,1] before creating texture.
Then to add 2 textures :
res = tex1 /2 + tex2 /2
and res will be in the [0,1] range, for your case always 0.5, as expected.
EDIT : with textures in floating point, you are only clamped to classic fp representations. If your card is listed here (http://www.delphi3d.net/hardware/extsupport.php?extension=GL_ATI_texture_float) it support the GL_ATI_texture_float extension (http://oss.sgi.com/projects/ogl-sample/registry/ATI/texture_float.txt) .
03-19-2005, 08:10 AM
But, I used GL_ADD_SIGNED_EXT(spelling), and shifted by bias
If I assigned, simple example, cos(t) for x1, and cos(t+Pi) to x2, do the above, combine using add signed, it will not work. In fact, the math does not work, unless the negative values are retained. I need to work with wave interference and construction.
Thanks for the help.
03-19-2005, 09:03 AM
Math should work, providing you shift/scale properly (but I am not very good with multitexturing) :
done on CPU :
original range [-1,1]-> scaled/shifted to texture allowed range [O,1]-> scaled to avoid sum overflow [0,0.5] ->
done on GPU :
sum 2 tex [0,1] ->
done on CPU : read result and scale back to [-1,1]
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.