3

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

4

1 回答 1

1

如果您的目标是SM 4.0-SM 5.0您可以使用Binary Castsand 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

对于以前的着色器模型,我认为它可能会更复杂,因为它取决于 FP 精度。

于 2010-05-22T22:28:33.143 回答