How can I encode four unsigned bytes (0-255) to a float and back again using HLSL?

Posted by Statement on Stack Overflow See other posts from Stack Overflow or by Statement
Published on 2010-05-22T20:50:57Z Indexed on 2010/05/22 22:30 UTC
Read the original article Hit count: 383

Hello!

I am facing a task where one of my hlsl shaders require multiple texture lookups per pixel. My 2d textures are fixed to 256*256, so two bytes should be sufficient to address any given texel given this constraint. My idea is then to put two xy-coordinates in each float, giving me eight xy-coordinates in pixel space when packed in a Vector4 format image. These eight coordinates are then used to sample another texture(s).

The reason for doing this is to save graphics memory and an attempt to optimize processing time, since then I don't require multiple texture lookups.

By the way: Does anyone know if encoding/decoding 16 bytes from/to 4 floats using 1 sampling is slower than 4 samplings with unencoded data?

© Stack Overflow or respective owner

Related posts about optimization

Related posts about data