Real-Time Rendering——5.5 Transparency, Alpha, and Compositing 透明度、Alpha和合成

There are many different ways in which semitransparent objects can allow light to pass through them. For rendering algorithms, these can be roughly divided into light-based and view-based effects. Light-based effects are those in which the object causes light to be attenuated or diverted, causing other objects in the scene to be lit and rendered differently. View-based effects are those in which the semitransparent object itself is being rendered.

半透明物体可以通过许多不同的方式让光线穿过。对于渲染算法来说,这些大致可以分为基于光线的效果和基于视图的效果。基于灯光的效果是指对象导致灯光衰减或转移,从而导致场景中的其他对象被照亮并以不同方式渲染。基于视图的效果是半透明对象本身被渲染的效果。

In this section we will deal with the simplest form of view-based transparency, in which the semitransparent object acts as an attenuator of the colors of the objects behind it. More elaborate view- and light-based effects such as frosted glass, the bending of light (refraction), attenuation of light due to the thickness of the transparent object,and reflectivity and transmission changes due to the viewing angle are discussed in later chapters.

在本节中,我们将讨论最简单的基于视图的透明度,其中半透明对象充当其背后对象颜色的衰减器。更精细的基于视图和灯光的效果,如磨砂玻璃、光的弯曲(折射)、由于透明对象的厚度而导致的光衰减,以及由于视角而导致的反射率和透射率变化,将在后面的章节中讨论。

One method for giving the illusion of transparency is called screen-door transparency. The idea is to render the transparent triangle with a pixel-aligned checkerboard fill pattern. That is, every other pixel of the triangle is rendered, thereby leaving the object behind it partially visible. Usually the pixels on the screen are close enough together that the checkerboard pattern itself is not visible. A major drawback of this method is that often only one transparent object can be convincingly rendered on one area of the screen. For example, if a transparent red object and transparent green object are rendered atop a blue object, only two of the three colors can appear on the checkerboard pattern. Also, the 50% checkerboard is limiting. Other larger pixel masks could be used to give other percentages, but these tend to create detectable patterns.

一种产生透明错觉的方法叫做纱门透明。这个想法是用像素对齐的棋盘填充图案来渲染透明三角形。也就是说,三角形的每隔一个像素进行渲染,从而使其后面的对象部分可见。通常屏幕上的像素足够接近,棋盘图案本身是不可见的。这种方法的一个主要缺点是,通常只有一个透明物体可以令人信服地呈现在屏幕的一个区域上。例如,如果一个透明的红色对象和一个透明的绿色对象被渲染到一个蓝色对象的顶部,那么棋盘图案上只能出现三种颜色中的两种。此外,50%的棋盘是有限制的。可以使用其他更大的像素掩模来给出其他百分比,但是这些容易产生可检测的图案。

That said, one advantage of this technique is its simplicity. Transparent objects can be rendered at any time, in any order, and no special hardware is needed. The transparency problem goes away by making all objects opaque at the pixels they cover.This same idea is used for antialiasing edges of cutout textures, but at a subpixel level,using a feature called alpha to coverage (Section 6.6).

也就是说,这种技术的一个优点是简单。透明对象可以在任何时间以任何顺序渲染,不需要特殊的硬件。透明度问题通过使所有对象在其覆盖的像素处不透明而消失。同样的想法也用于剪切纹理边缘的反走样,但是是在子像素级别,使用一个称为alpha to coverage的特性(6.6节)。

Introduced by Enderton et al., stochastic transparency uses subpixel screendoor masks combined with stochastic sampling. A reasonable, though noisy, image is created by using random stipple patterns to represent the alpha coverage of the fragment. See Figure 5.31. A large number of samples per pixel is needed for the result to look reasonable, as well as a sizable amount of memory for all the subpixel samples.What is appealing is that no blending is needed, and antialiasing, transparency, and any other phenomena that creates partially covered pixels are covered by a single mechanism.

由Enderton等人介绍,随机透明使用子像素屏门掩模结合随机采样。通过使用随机点画模式来表示片段的alpha覆盖,创建了一个合理但有噪声的图像。参见图5.31。为了使结果看起来合理,每个像素需要大量的样本,以及用于所有子像素样本的相当大数量的存储器。吸引人的是,不需要混合,抗锯齿、透明度和任何其他产生部分覆盖像素的现象都由单个机制覆盖。

Figure 5.31. Stochastic transparency. The noise produced is displayed in the magnified area. (Images from NVIDIA SDK 11 samples, courtesy of NVIDIA Corporation.) 

图5.31。随机透明。产生的噪音显示在放大区域。(图片来自英伟达SDK 11样本,由英伟达公司提供。)

Most transparency algorithms blend the transparent object’s color with the color of the object behind it. For this, the concept of alpha blending is needed.When an object is rendered on the screen, an RGB color and a z-buffer depth are associated with each pixel. Another component, called alpha (α), can also be defined for each pixel the object covers. Alpha is a value describing the degree of opacity and coverage of an object fragment for a given pixel. An alpha of 1.0 means the object is opaque and entirely covers the pixel’s area of interest; 0.0 means the pixel is not obscured at all, i.e., the fragment is entirely transparent.

大多数透明度算法将透明对象的颜色与其后面对象的颜色混合。为此,需要阿尔法混合的概念。当对象呈现在屏幕上时,RGB颜色和z缓冲区深度与每个像素相关联。另一个称为alpha (α)的分量也可以为对象覆盖的每个像素定义。Alpha是描述给定像素的对象片段的不透明度和覆盖度的值。alpha为1.0表示对象不透明,并且完全覆盖了像素的感兴趣区域;0.0表示像素完全不模糊,即片段完全透明。

A pixel’s alpha can represent either opacity, coverage, or both, depending on the circumstances. For example, the edge of a soap bubble may cover three-quarters of the pixel, 0.75, and may be nearly transparent, letting nine-tenths of the light through to the eye, so it is one-tenth opaque, 0.1. Its alpha would then be 0.75 × 0.1 = 0.075.However, if we were using MSAA or similar antialiasing schemes, the coverage would be taken into account by the samples themselves. Three-quarters of the samples would be affected by the soap bubble. At each of these samples we would then use the 0.1 opacity value as the alpha.

根据具体情况,像素的alpha可以表示不透明度、覆盖率或都表示。例如,肥皂泡的边缘可能覆盖四分之三的像素,即0.75,并且可能几乎透明,让十分之九的光透过到达眼睛,因此它是十分之一的不透明,即0.1。那么它的alpha就是0.75 × 0.1 = 0.075。然而,如果我们使用MSAA或类似的抗混叠方案,覆盖范围将由样本本身来考虑。四分之三的样本会受到肥皂泡的影响。在每个样本中,我们将使用0.1的不透明度值作为alpha值。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

椰子糖莫莫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值