最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

directx - half data in structured buffer directx11 - Stack Overflow

programmeradmin2浏览0评论

I am trying to use 16 bit floating point data in my directx 11 buffer but the data always comes back wrong are there special options i need to set on the data to pack it and read it correctly?

this is my buffer:

typedef struct VertexSplat1
{
    float           x, y, z;
    uint16_t                    fOpacity;
    uint16_t                    qImRot[4]; //imaginary parts of rotation
    uint16_t                    vScale[3];
    uint16_t                    vHarmonicColors[3];
    uint16_t                    fPad;
} VertexSplat1;

and in hlsl

struct VertexSplat1
{
    float3 vPos;   //float4
    half  fAlpha; 
    half  fQx;

    half  fQy; //float4
    half  fQz;

    half  fQw;
    half  fSx;

    half  fSy;
    half  fSz;

    half  fSH0_0;
    half  fSH0_1;

    half  fSH0_2; //float4
    half  fPad;
};
StructuredBuffer<VertexSplat1> g_SplatData  : register(t0);

...

float4 clr = float4(g_SplatData[dwVert].fSH0_0,
                    g_SplatData[dwVert].fSH0_1,
                    g_SplatData[dwVert].fSH0_2,
                    g_SplatData[dwVert].fAlpha);

am I accessing my data wrong? it comes back incorrectly (differently as if it came from an R16_Float texture)

I am trying to use 16 bit floating point data in my directx 11 buffer but the data always comes back wrong are there special options i need to set on the data to pack it and read it correctly?

this is my buffer:

typedef struct VertexSplat1
{
    float           x, y, z;
    uint16_t                    fOpacity;
    uint16_t                    qImRot[4]; //imaginary parts of rotation
    uint16_t                    vScale[3];
    uint16_t                    vHarmonicColors[3];
    uint16_t                    fPad;
} VertexSplat1;

and in hlsl

struct VertexSplat1
{
    float3 vPos;   //float4
    half  fAlpha; 
    half  fQx;

    half  fQy; //float4
    half  fQz;

    half  fQw;
    half  fSx;

    half  fSy;
    half  fSz;

    half  fSH0_0;
    half  fSH0_1;

    half  fSH0_2; //float4
    half  fPad;
};
StructuredBuffer<VertexSplat1> g_SplatData  : register(t0);

...

float4 clr = float4(g_SplatData[dwVert].fSH0_0,
                    g_SplatData[dwVert].fSH0_1,
                    g_SplatData[dwVert].fSH0_2,
                    g_SplatData[dwVert].fAlpha);

am I accessing my data wrong? it comes back incorrectly (differently as if it came from an R16_Float texture)

Share Improve this question asked Mar 14 at 19:22 yo76yoyo76yo 1561 silver badge7 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0
  1. why dont use half2/half3/half4 for vector, it will be a better thing to do

  2. if alpha is color value related to color put it close (the best option half4 color and alpha)

  3. HLSL usualy maps half to 32bits with no flags, check out this: https://github/microsoft/DirectXShaderCompiler/wiki/Buffer-Packing

    hope this will help:)

发布评论

评论列表(0)

  1. 暂无评论