views:

98

answers:

1

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?


Edit: This is for Shader Model 3

+1  A: 

If you are targeting SM 4.0-SM 5.0 you can use Binary Casts and Bitwise operations:

uint4 myUInt4 = asuint(myFloat4);

uint x0 = myUInt4.x & 0x000000FF; //extract two xy-coordinates (x0,y0), (x1,y1)
uint y0 = (myUInt4.x & 0x0000FF00) >> 8;
uint x1 = (myUInt4.x & 0x00FF0000) >> 16;
uint y1 = (myUInt4.x & 0xFF000000) >> 24;

//repeat operation for .y .z and .w coordinates

For previous Shader Models, I think it could be more complicated since it depends on FP precision.

Stringer Bell
I guess I am stuck with SM3 since I am constrained to DX9. To be honest I don't know a great deal about shader models, but I know the pixel shader is currently version 3.
Statement