Cg Texture Lookup

Started by
2 comments, last by Kalidor 18 years, 5 months ago
I have a scenario, in my Cg program, where I am trying to get a pixel value out of a texture as a whole 32bit value, instead of being dissected into individual color values. So... I what I'm after is a single float value for the pixel, instead of a Float4 color value, like the tex2D() function returns. Am I just overlooking something? ... or is this not even possible?

I know only that which I know, but I do not know what I know.
Advertisement
why not use a float32 texture? AFAIK, nv cards support that
Why would your texture have floats? RGBA texture data is generally in the form of 4 8-bit unsigned chars. Each represents the intensity of each color component (A is for the alpha component). Light colors as generated by electronic displays and intpreted by the human eye (why is what our electronic displays were modelled to stimulate) is the product of the 3 light components red, green, and blue combining at varying intensities. If you want a single value for overall intensity you can have that by averaging the three, of course you would lose the color information in the process. This means you'll have the brightness value or gray scale value. Now, if what are looking for is a normalized brightness vectors in 32-bit float form you could take the red, green, and blue values in integer form, add them together, and divide by the max possible value ( (2^8bits - 1)*3 = 765). If your color components are already normalized brightness vectors then averaging them should work as well.
Programming since 1995.
Phantom posted some GLSL code for packing/unpacking a float to/from an rgba texture here (I seem to be posting this a lot lately [grin]). It's easy enough to convert to Cg.

EDIT: Actually, I think Cg has it's on packing and unpacking functions defined for one of NVidia's shader profiles. Check the Cg User's Manual. They obviously won't work on ATI cards though.

This topic is closed to new replies.

Advertisement