战魂小筑

讨论群:309800774 知乎关注:http://zhihu.com/people/sunicdavy 开源项目:https://github.com/davyxu

   :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  257 随笔 :: 0 文章 :: 506 评论 :: 0 Trackbacks

前段时间曾经碰到过RT纹理绘制出来时需要透明的问题。当时也Google了一下,但是很少有人提起过这个问题。昨天看剑孤寒的空间的Galaxy2D引擎中使用RT的透明绘制,文章在这里。发现这个特性居然需要显卡支持,马上查过DX9SDK文档,发现这样一篇文章,已经告诉我们怎么做了:

Render Target Alpha (Direct3D 9)

The frame buffer blender can now blend alpha channels independent from color-channel blending on render targets. This control is enabled with a new render state, D3DRS_SEPARATEALPHABLENDENABLE.

When D3DRS_SEPARATEALPHABLENDENABLE is set to FALSE (which is the default condition), the render-target blending factors and operations applied to alpha are the same as those defined for blending color channels. A driver needs to set the D3DPMISCCAPS_SEPARATEALPHABLEND cap to indicate that it can support render-target alpha blending. Be sure to enable D3DRS_ALPHABLEND to tell the pipeline that alpha blending is needed.

To control the factors in the alpha channel of the render-target blenders, two new render states are defined as follows:

D3DRS_SRCBLENDALPHA 
D3DRS_DESTBLENDALPHA 

Like the D3DRS_SRCBLEND and D3DRS_DESTBLEND, these can be set to one of the values in the D3DBLEND enumeration. The source and destination blend settings can be combined in several ways, depending on the settings in the SrcBlendCaps and DestBlendCaps members of D3DCAPS9.

The alpha blending is done as follows:

renderTargetAlpha = (alphain* srcBlendOp) BlendOp (alphart* destBlendOp) 

Where:

  • alphain is the input alpha value.
  • srcBlendOp is one of the blend factors in D3DBLEND.
  • BlendOp is one of the blend factors in D3DBLENDOP.
  • alphart is the render-target alpha value.
  • destBlendOp is one of the blend factors in D3DBLEND.
  • renderTargetAlpha is the final blended alpha value.

 

翻译如下:

   使用 D3DRS_SEPARATEALPHABLENDENABLE渲染状态可以让Frame Buffer 混合器将RT中的Alpha通道与颜色通道分开混合。

当D3DRS_SEPARATEALPHABLENDENABLE 设置为 FALSE(默认),RT渲染参数和操作会跟颜色通道一样被应用到Alpha通道。 这项特性需要显卡支持D3DPMISCCAPS_SEPARATEALPHABLEND 特性。记住,在之前设置D3DRS_ALPHABLEND以便打开Alpha混合。

   RT混合器的Alpha通道混合因子渲染状态如下:

D3DRS_SRCBLENDALPHA

D3DRS_DESTBLENDALPHA

其被定义在D3DBLEND枚举中,D3DRS_SRCBLEND 和D3DRS_DESTBLEND也是这样定义的。来源色与目标颜色将会有很多组合方式,主要依赖于D3DCAPS9中的SrcBlendCaps 和DestBlendCaps

Alpha混合公式如下:

renderTargetAlpha = (alphain* srcBlendOp) BlendOp (alphart* destBlendOp)

其中:

    alphain为输入alpha值

    srcBlendOp是D3DBLEND中的一个混合因子

    BlendOp是 D3DBLENDOP中的一个混合因子

    alphart是RT的alpha值

    destBlendOp是D3DBLEND中的一个混合因子

    renderTargetAlpha是最后混合后的alpha值

posted on 2010-01-20 16:56 战魂小筑 阅读(2769) 评论(1)  编辑 收藏 引用 所属分类: 游戏开发技术C++/ 编程语言

评论

# re: 解决Render Target中的Alpha通道绘制问题 2010-01-21 18:27 yoya
这篇文章是不是只是说alpha和color的混合可以分开进行?如果不按照文中设置,只是alpha和color用的D3DRS_SRCBLEND和D3DRS_DESTBLEND的参数
那么render target里面还是可以设置alpha啊?

  回复  更多评论
  


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理