Pack 2 16 bits floats into a 32 bits float in hlsl
Hi! How can i pack 2 16 bits floats into a 32 bits float and unpack them in hlsl ? I would like to use a rf32 texture to store them...
Tnks in advance
Hi! I can't help you directly here, but is there any reason you can't just use a G16R16F-texure?
edit: IIRC, NVIDIA support this kind of packing natively via FK2H/UP2H, but I don't know if there's any way to access that functionality in HLSL. (Or how many NV-cards do actually support it)
In Cg it would just be
[Edited by - Phobon on January 9, 2008 6:10:42 AM]
edit: IIRC, NVIDIA support this kind of packing natively via FK2H/UP2H, but I don't know if there's any way to access that functionality in HLSL. (Or how many NV-cards do actually support it)
In Cg it would just be
(un)pack_2half().
[Edited by - Phobon on January 9, 2008 6:10:42 AM]
There isn't any functionality built into HLSL for this. Search the GP&T forum archives for tricks about storing this sort of thing in integer ARGB textures, but I don't think I've seen it done for 2xFP16->FP32 unfortunately.
Integers are a nice target format as they can be treated as just a block of binary data; FP formats have more encoding (sign, exponent and mantissa) that can get a little more tricky.
As has been suggested, why not use G16R16F?
hth
Jack
Integers are a nice target format as they can be treated as just a block of binary data; FP formats have more encoding (sign, exponent and mantissa) that can get a little more tricky.
As has been suggested, why not use G16R16F?
hth
Jack
Quote:Original post by jollyjeffers
There isn't any functionality built into HLSL for this. Search the GP&T forum archives for tricks about storing this sort of thing in integer ARGB textures, but I don't think I've seen it done for 2xFP16->FP32 unfortunately.
Integers are a nice target format as they can be treated as just a block of binary data; FP formats have more encoding (sign, exponent and mantissa) that can get a little more tricky.
As has been suggested, why not use G16R16F?
hth
Jack
First of all thank you for answers.
Concerning the G16R16F I'm not using it because this is for a tex2Dlod instruction. I'm fetching a elevation value for a terrain engine in the vertex shader with the tex2dLod instruction, and from what i have read for this kind of functionality we can only use D3DFMT_R32F and D3DFMT_A32B32G32R32F.
But my question arises from some piece of shader code that i have seen in the GPU Geometric Clipmapping article they have something like this:
// sample the vertex texture
float zf_zd = tex2Dlod(ElevationSampler, float4(uv, 0, 1));
// unpack to obtain zf and zd = (zc - zf)
// zf is elevation value in current (fine) level
// zc is elevation value in coarser level
float zf = floor(zf_zd);
float zd = frac(zf_zd) * 512 - 256; // (zd = zc - zf)
What's happening here ? It's because they know the domain of the values ?
Quote:Original post by Ivo Leitao
But my question arises from some piece of shader code that i have seen in the GPU Geometric Clipmapping article they have something like this:
// sample the vertex texture
float zf_zd = tex2Dlod(ElevationSampler, float4(uv, 0, 1));
// unpack to obtain zf and zd = (zc - zf)
// zf is elevation value in current (fine) level
// zc is elevation value in coarser level
float zf = floor(zf_zd);
float zd = frac(zf_zd) * 512 - 256; // (zd = zc - zf)
What's happening here ? It's because they know the domain of the values ?
They're using the integer part of the floating-point to store one value, and the fractional part to the store the other other. So yes, it does require you know the range of the values (for the second value in particular). However, since this is a floating-point, the larger the first value in the integer part, the less precision you have available for the second value. You only have 24 "effective" mantissa bits (23 physical plus 1 normalized) in a 32-bit FP, meaning that you can only pack up to two 12-bit values before information is lost (or any two values with combined precision less than 24-bits).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement