NeHe OpenGL Lesson20 – Masking

本文介绍如何使用OpenGL的混合操作实现遮罩效果,而非传统的alpha测试。遮罩效果广泛应用于创建树叶、复杂窗口或栅栏等物体,使物体在光照下更加真实。文章详细讲解了绘制纹理、设置混合函数以及绘制遮罩扩散纹理的过程。

screen_shot2-300x237 This sample shows us how to implement masking effect with OpenGL using blend operation instead of alpha testing. Masking is an important effect, that could be used build tree leaves, some complicated windows or fence, those objects will be shined though them.

 

Main Idea

1) Draw the scene texture normally;
2) with glBlendFunc(GL_DST_COLOR,GL_ZERO) setup to draw the white and black texture, this texture will make those area that will be fully overlapped be totally black;
3) with glBlendFunc(GL_ONE, GL_ONE) setup, draw the mask diffuse texture. Those areas that fully black will be filled by the mask diffuse texture color.


The above workflow could be represented with following diagram:

combine

  

Of course, we could get the same masking effect with the alpha testing feature. I already wrote an alpha testing sample here, you could check them in the source code.
There is one thing that need to take special care is that when you use alpha testing for some mip-maps, you need to care about how those mip-maps are generated. Most of time, the masking texture alpha value should be 1 or 0. No middle valued such as 0.5, 0.6 created. But this situation will happen if you create mip-maps with linear sampling method.

 

A project named “AlphaRef” added, this project will load some TGA images with alpha channels. An OpenGL texture object will be created with alpha channel, that will be used for alpha testing.

 

The full source code could be downloaded from here.

转载于:https://www.cnblogs.com/open-coder/archive/2012/08/23/2653304.html

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值