DirectX Instancing Animation Meshes with LUT

48 Views Asked by At

I am currently learning directx11, new to stackoverflow, but not skilled enough. I am building a custum engine, but currently stuck with instancing animation meshes with LUT.

I've tried binding vs constant buffer, but this code was a bit dirty, so I just disabled the file from the project.
I was trying to find what I was missing, and now I think I fixed the texture sampling function, the lookuptable map unmapping code, but still I can't get the result.
So I tried to just use the original model mesh at vertex shader, and it was rendering correctly.
This made myself sure to believe there is a problem with the lut I made.

float4x4* bonearray = new float4x4[maxbones * numinstances];

    D3D11_TEXTURE2D_DESC tTexture2DDesc{};
    tTexture2DDesc.Width                = maxbones * 4;
    tTexture2DDesc.Height               = numinstances;
    tTexture2DDesc.MipLevels            = 1;
    tTexture2DDesc.ArraySize            = 1;
    tTexture2DDesc.Format               = DXGI_FORMAT_R32G32B32A32_FLOAT;
    tTexture2DDesc.SampleDesc.Count     = 1;
    tTexture2DDesc.SampleDesc.Quality   = 0;
    tTexture2DDesc.Usage                = D3D11_USAGE_DYNAMIC;
    tTexture2DDesc.BindFlags            = D3D11_BIND_SHADER_RESOURCE;
    tTexture2DDesc.CPUAccessFlags       = D3D11_CPU_ACCESS_WRITE;

    m_pDevice->CreateTexture2D(&tTexture2DDesc, nullptr, m_pTexture2D.GetAddressOf());
    m_pDevice->CreateShaderResourceView(m_pTexture2D.Get(), nullptr, m_pShaderResourceView.GetAddressOf());

    D3D11_MAPPED_SUBRESOURCE tSubResource{};
    _pContext->Map(m_pTexture2D.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &tSubResource);
    memcpy(tSubResource.pData, bonearray, sizeof(float4x4)*maxbones*numinstances);
    _pContext->Unmap(m_pTexture2D.Get(), 0);

// Bind SRV to Shader

    float4x4 BoneSample(int iBoneWeightIndex, int iInstanceIndex, int iNumInstance)
    {
    float4 vRight       = g_texBoneInstances.SampleLevel(TargetSampler,
                float2(float(iBoneWeightIndex* 4.f + 0.f) / float(MAX_BONE * 4.f),
                float(iInstanceIndex) / float(iNumInstance)), 0);
    float4 vUp      = g_texBoneInstances.SampleLevel(TargetSampler,
                float2(float(iBoneWeightIndex* 4.f + 1.f) / float(MAX_BONE * 4.f),
                float(iInstanceIndex) / float(iNumInstance)), 0);
    float4 vLook        = g_texBoneInstances.SampleLevel(TargetSampler,
                float2(float(iBoneWeightIndex * 4.f + 2.f) / float(MAX_BONE * 4.f),
                float(iInstanceIndex) / float(iNumInstance)), 0);
    float4 vTranslation = g_texBoneInstances.SampleLevel(TargetSampler,
                float2(float(iBoneWeightIndex* 4.f + 3.f) / float(MAX_BONE * 4.f),
                float(iInstanceIndex) / float(iNumInstance)), 0);

    return float4x4(vRight, vUp, vLook, vTranslation);
}

This is a short code showing the flow of my code. I can't find what I am missing. Is there anything left to try?

0

There are 0 best solutions below