【问题标题】:How can I adjust the transparency with DirectX 11?如何使用 DirectX 11 调整透明度?
【发布时间】:2019-11-03 08:48:33
【问题描述】:

我正在尝试制作像彩色玻璃或水一样的透明物体,我成功地制作了它。 但我不知道如何调整它的透明度。我在尝试做不可能的事吗?

通过简单的颜色和光照计算来渲染场景。 并且没有在这个程序中使用纹理映射

我尝试更改混合状态描述、混合因子、样本蒙版

但我不确定它是否正确。

这是我的 Blendstate 描述

BlendStateDesc.AlphaToCoverageEnable = false;
BlendStateDesc.IndependentBlendEnable = false;
BlendStateDesc.RenderTarget[0].BlendEnable = true;
BlendStateDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_DEST_COLOR;
BlendStateDesc.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO;
BlendStateDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
BlendStateDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
BlendStateDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
BlendStateDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
BlendStateDesc.RenderTarget[0].RenderTargetWriteMask 
=D3D11_COLOR_WRITE_ENABLE_ALL;

和设置

float bf[] = { 0.f,0.f,0.f,0.f };

pDeviceContext->OMSetBlendState(m_pd3dBlendState, bf, 0xffffffff);

【问题讨论】:

    标签: directx transparency directx-11 alphablending color-blending


    【解决方案1】:

    我会假设这是 DX11,并且您缺少的部分实际上是在您的着色器中。

    在您的像素着色器中,您将返回一个 float4 rgba。 “a”值将控制应用于计算的值。该值介于 0 和 1 之间。如果您可以发布像素着色器代码,这将有助于确认/拒绝解决方案。

    【讨论】:

    • 抱歉回复晚了。我错过了一些非常简单的东西!
    猜你喜欢
    • 1970-01-01
    • 2019-01-24
    • 2011-09-16
    • 2021-12-20
    • 1970-01-01
    • 1970-01-01
    • 2018-04-22
    • 2015-08-18
    • 1970-01-01
    相关资源
    最近更新 更多