提问人:testora 提问时间:11/8/2023 最后编辑:testora 更新时间:11/8/2023 访问量:34
DirectX 实例化动画网格与 LUT
DirectX Instancing Animation Meshes with LUT
问:
我目前正在学习 directx11,这是 stackoverflow 的新手,但不够熟练。 我正在构建一个 custum 引擎,但目前坚持使用 LUT 实例化动画网格。
我尝试过绑定与常量缓冲区,但是这段代码有点脏,所以我只是从项目中禁用了该文件。
我试图找到我缺少的东西,现在我想我修复了纹理采样函数,可查找的地图取消映射代码,但我仍然无法得到结果。
因此,我尝试在顶点着色器中使用原始模型网格,并且它正在正确渲染。
这让我确信我制作的 lut 有问题。
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);
}
这是一个简短的代码,显示了我的代码流。 我找不到我缺少的东西。 还有什么可以尝试的吗?
答: 暂无答案
评论