Sign in to follow this  
Daishim

Cg Texture Lookup

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

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