directx - D3D11 纹理上的 Direct2D 绘制不混合
问题描述
我有一个与 Direct3D 互操作的 Direct2D。
我的 Direct2D 渲染到 Direct3d 纹理就好了。然后我试图在我的 Direct3D 场景之上渲染该纹理,但是当我渲染纹理时它显示得很好,但它用黑色覆盖了其余部分而不是混合
D2D1_BITMAP_PROPERTIES1 properties = D2D1::BitmapProperties1(
D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW,
D2D1::PixelFormat(
DXGI_FORMAT_B8G8R8A8_UNORM,
D2D1_ALPHA_MODE_PREMULTIPLIED
)
);
pd2dDeviceCtx->CreateBitmapFromDxgiSurface(surface.Get(), &properties, &p2dBitmap);
pd2dDeviceCtx->SetTarget(p2dBitmap.Get());
// BlendState
D3D11_BLEND_DESC blendStateDescription = {};
blendStateDescription.RenderTarget[0].BlendEnable = TRUE;
blendStateDescription.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
blendStateDescription.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
blendStateDescription.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
blendStateDescription.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
blendStateDescription.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
blendStateDescription.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
blendStateDescription.RenderTarget[0].RenderTargetWriteMask = 0x0f;
pDevice->CreateBlendState(&blendStateDescription, &blendState);
pContext->OMSetBlendState(blendState.Get(), NULL, sampleMask);
//D3D draws....
pd3dContext->DrawIndexed(6, 0, 0);
//D2D draws
pd2dDeviceCtx->BeginDraw();
pd2dDeviceCtx->Clear(D2D1::ColorF(0, 0, 0, 0));
// .. more D2D draws
pd2dDeviceCtx->EndDraw();
// ... Draw texture that d2d used to direct3d
pContext->VSSetShader(vertextShader.Get(), nullptr, 0);
pContext->PSSetShader(pixelShader.Get(), nullptr, 0);
pContext->PSSetShaderResources(0, 1, d2dTextShaderResource.GetAddressOf());
pContext->PSSetSamplers(0, 1, samplers.GetAddressOf());
pContext->DrawIndexed(6, 0, 0);
我的纹理渲染正确,但它应该是透明的,它的全黑隐藏了曾经在那里的东西。
解决方案
推荐阅读
- hadoop - 如何将 hdfs 中的现有文本数据转换为 Avro?
- reactjs - 获取 API 错误:无法读取未定义的属性“地图”
- vagrant - Vagrant: * 未知的配置部分 'disksize'
- php - 如何找到多个id不相等的mongodb数据?
- cassandra - 无法连接到任何服务器
- shell - 如何在 start.sh 脚本中获取 jar 名称
- python - 我如何提供再次运行程序或以 Python 结束程序的选择?
- vba - 启动 VBA 应用程序块使用和打开其他工作簿
- leaflet - 更改传单绘制中的顶点样式
- mongodb - mongodb异常连接失败