【3D技术宅公社】XR数字艺术论坛  XR技术讨论 XR互动电影 定格动画

 找回密码
 立即注册

QQ登录

只需一步,快速开始

调查问卷
论坛即将给大家带来全新的技术服务,面向三围图形学、游戏、动画的全新服务论坛升级为UTF8版本后,中文用户名和用户密码中有中文的都无法登陆,请发邮件到324007255(at)QQ.com联系手动修改密码

3D技术论坛将以计算机图形学为核心,面向教育 推出国内的三维教育引擎该项目在持续研发当中,感谢大家的关注。

查看: 2327|回复: 1

深入分析D3DBLEND ,D3Dx环境下的半透明混合

[复制链接]
发表于 2013-10-22 16:26:43 | 显示全部楼层 |阅读模式
本帖最后由 夜行的猫仔 于 2013-10-23 15:34 编辑

首先要明白的是,半透明混合都来源于这个公式:

  Color = TexelColor x SourceBlend + CurrentPixelColor x DestBlend
也就是

                   Color=RGBs * As +RGBd * Ad
其中Color是最终显示的颜色,RGBs是渲染源的颜色,也就是模型的颜色,As是渲染源的半透明系数,RGBd是渲染目标的颜色,也就是背景色, Ad渲染目标(背景)的混合系数
Syntax
  1. typedef enum D3DBLEND {
  2.   D3DBLEND_ZERO             = 1,
  3.   D3DBLEND_ONE              = 2,
  4.   D3DBLEND_SRCCOLOR         = 3,
  5.   D3DBLEND_INVSRCCOLOR      = 4,
  6.   D3DBLEND_SRCALPHA         = 5,
  7.   D3DBLEND_INVSRCALPHA      = 6,
  8.   D3DBLEND_DESTALPHA        = 7,
  9.   D3DBLEND_INVDESTALPHA     = 8,
  10.   D3DBLEND_DESTCOLOR        = 9,
  11.   D3DBLEND_INVDESTCOLOR     = 10,
  12.   D3DBLEND_SRCALPHASAT      = 11,
  13.   D3DBLEND_BOTHSRCALPHA     = 12,
  14.   D3DBLEND_BOTHINVSRCALPHA  = 13,
  15.   D3DBLEND_BLENDFACTOR      = 14,
  16.   D3DBLEND_INVBLENDFACTOR   = 15,
  17.   D3DBLEND_SRCCOLOR2        = 16,
  18.   D3DBLEND_INVSRCCOLOR2     = 17,
  19.   D3DBLEND_FORCE_DWORD      = 0x7fffffff
  20. } D3DBLEND, *LPD3DBLEND;
复制代码
D3DBLEND_ZERO

Blend factor is (0, 0, 0, 0).

D3DBLEND_ONE

Blend factor is (1, 1, 1, 1).

D3DBLEND_SRCCOLOR

Blend factor is (Rs, Gs, Bs, As).

D3DBLEND_INVSRCCOLOR

Blend factor is (1 - Rs, 1 - Gs, 1 - Bs, 1 - As).

D3DBLEND_SRCALPHA

Blend factor is (As, As, As, As).

D3DBLEND_INVSRCALPHA

Blend factor is ( 1 - As, 1 - As, 1 - As, 1 - As).

D3DBLEND_DESTALPHA

Blend factor is (Ad Ad Ad Ad).

D3DBLEND_INVDESTALPHA

Blend factor is (1 - Ad 1 - Ad 1 - Ad 1 - Ad).

D3DBLEND_DESTCOLOR

Blend factor is (Rd, Gd, Bd, Ad).

D3DBLEND_INVDESTCOLOR

Blend factor is (1 - Rd, 1 - Gd, 1 - Bd, 1 - Ad).

D3DBLEND_SRCALPHASAT

Blend factor is (f, f, f, 1); where f = min(As, 1 - Ad).

D3DBLEND_BOTHSRCALPHA

Obsolete. Starting with DirectX 6, you can achieve the same effect by setting the source and destination blend factors to D3DBLEND_SRCALPHA and D3DBLEND_INVSRCALPHA in separate calls.

D3DBLEND_BOTHINVSRCALPHA

Source blend factor is (1 - As, 1 - As, 1 - As, 1 - As), and destination blend factor is (As, As, As, As); the destination blend selection is overridden. This blend mode is supported only for the D3DRS_SRCBLEND render state.

D3DBLEND_BLENDFACTOR

Constant color blending factor used by the frame-buffer blender. This blend mode is supported only if D3DPBLENDCAPS_BLENDFACTOR is set in the SrcBlendCaps or DestBlendCaps members ofD3DCAPS9.

D3DBLEND_INVBLENDFACTOR

Inverted constant color-blending factor used by the frame-buffer blender. This blend mode is supported only if the D3DPBLENDCAPS_BLENDFACTOR bit is set in the SrcBlendCaps or DestBlendCapsmembers of D3DCAPS9.

D3DBLEND_SRCCOLOR2

Blend factor is (PSOutColor[1]r, PSOutColor[1]g, PSOutColor[1]b, not used). See Render Target Blending.

Differences between Direct3D 9 and Direct3D 9Ex:

This flag is available in Direct3D 9Ex only.


D3DBLEND_INVSRCCOLOR2

Blend factor is (1 - PSOutColor[1]r, 1 - PSOutColor[1]g, 1 - PSOutColor[1]b, not used)). See Render Target Blending.

Differences between Direct3D 9 and Direct3D 9Ex:

This flag is available in Direct3D 9Ex only.


D3DBLEND_FORCE_DWORD

Forces this enumeration to compile to 32 bits in size. Without this value, some compilers would allow this enumeration to compile to a size other than 32 bits. This value is not used.

Remarks

In the preceding member descriptions, the RGBA values of the source and destination are indicated by the s and d subscripts.

The values in this enumerated type are used by the following render states:

  • D3DRS_DESTBLEND
  • D3DRS_SRCBLEND
  • D3DRS_DESTBLENDALPHA
  • D3DRS_SRCBLENDALPHA

See D3DRENDERSTATETYPE

Render Target Blending

Direct3D 9Ex has improved text rendering capabilities. Rendering clear-type fonts would normally require two passes. To eliminate the second pass, a pixel shader can be used to output two colors, which we can call PSOutColor[0] and PSOutColor[1]. The first color would contain the standard 3 color components (RGB). The second color would contain 3 alpha components (one for each component of the first color).

These new blending modes are only used for text rendering on the first render target.

-------------------------------------------------------------------------------------------------------------------------------------------------以上是微软的D3DBLEND文档,接下来通过程序来测试里面的混合效果。
此次使用例题的源代码下载:
游客,如果您要查看本帖隐藏内容请回复


该示例程序模拟了直升飞机螺旋桨的半透明效果。在程序的初始化阶段,载入Heli.x文件,它是一个包含直升飞机的三维模型文件,其中螺旋桨的材质漫反射属性为(R, G, B, A) = (0.183700; 0.183700; 0.183700; 0.500000; ),可以用文本方式打开Heli.x查看它的材质属性,Heli.x是一个文本格式的.x文件。

示例程序中没有设置alpha混合方法,所以应用程序将采用默认的alpha混合方法D3DBLEND_ADD,即将源计算结果与颜色缓冲区计算结果相加。由于直升机螺旋桨的材质的alpha值为0.5f,因此它的最终颜色就是50%的玻璃颜色加上50%的背景颜色。
以下分别对不同的参数做了渲染测试: 未标题-1.jpg

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|3D数字艺术论坛 ( 沪ICP备14023054号 )

GMT+8, 2024-5-24 05:59

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表