混合 blending

一,默认的混合方程。

outpixelcolor=sourcepixelcolor⊕sourceblendfactor+destpixelcolor⊕destblendfactor;

其中,⊕代表对应元素分别相乘。source代表正在渲染的片元,dest代表后台缓存中的片元。

sourceblendfactor越大,物体透明度越小。

二,使用混合时必须遵守的规则。

先画不透明物体,再画透明物体。多个透明物体按照离视点由远及近的顺序渲染。可通过视空间中的z值排列顺序。

三,默认情况下混合是关闭的,因为其计算开销比较大。因此,当渲染某物体需要使用混合时,开启混合,方法如下:

Device->SetRenderState(D3DRS_ALPHABLENDENABLE,true);

而当前渲染的物体不需要使用混合时,随即关闭混合,将true改为false即可。

应尽量避免重复的开关混合功能,需使用混合的物体尽量绑定在一起。

四,混合因子的设置具有相当大的灵活性,不同的设置可以组合出多种不同的混合方式。

注意两种重要的特殊状态,在SetRenderState中定义:D3DRS_SAPARATEALPHABLENDENABLE和D3DRS_COLORWRITEENABLE.

前者的作用是单独对alpha值进行混合操作,后者的作用是决定哪些颜色元素被混合,例如可以封住rgb值,而只对alpha值进行混合。

五,所有的renderstate状态设置均可在shader中进行,以便在不同的pass间进行切换。

六,总结混合的过程:

第一步,启用混合功能;

第二步,对混合方程和源及目标混合因子进行设置;

第三步,关闭混合功能。

七,Alpha Channel

一般情况下透明值是顶点级的,that is to say we can only dedide whether a triangle or a set of trianles are transparent,but we can not decide the transparency inside the triangle ,so it is not detailed to some degree.Alpha Channle can solve the problem.We do not need to specify the alpha componet by diffuseMtrl.a,We can specify it by color.a,which is the alpha component of texel color.But in many cases,its hard for us to specify the alpha component by hand ,so we can use image editing tools like Adobe Photoshop to add the alpha component to a texure image provided the format of it is 32_bit color(rgba).if not ,we should convert it to right format.Here is a useful tool:D3DTEXTool.we open a image file,and choose Change Surface Format(if the format does not support rgba),and choose Open Onto Alpha Channel of this Texture,and choose a alpha image ,then the alpha component of the alpha image is added to the texture image.

八,Alpha Test.

We might often draw objects like fences and gates and nets,modeling these objects is a chore and it is expensive to compute,so we can use Alpha TEST .

We can set comparison equation and the reference alpha.if the alpha of the texel that are being rendered pass the comparison,it is renderd to the back buffer.so the solid part of the fence is drawed ,and other parts are not drawed.

We just open the alpha test by call the SetRenderState with the parameter of D3DRS_ALPAHTESTENABLE.to true.and set D3DRS_ALPHAFUNC and D3DRS_ALPHAREF to choose comparison equation and reference alpha value.

Remember to set D3DRS_ALPHATESTENABLE to false when finished.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值