+ All Categories
Home > Documents > CHAPTER 10 Alpha Blending and Fog © 2008 Cengage Learning EMEA.

CHAPTER 10 Alpha Blending and Fog © 2008 Cengage Learning EMEA.

Date post: 17-Dec-2015
Category:
Upload: lambert-rice
View: 218 times
Download: 1 times
Share this document with a friend
Popular Tags:
17
CHAPTER 10 CHAPTER 10 Alpha Blending and Fog Alpha Blending and Fog © 2008 Cengage Learning EM
Transcript
Page 1: CHAPTER 10 Alpha Blending and Fog © 2008 Cengage Learning EMEA.

CHAPTER 10CHAPTER 10

Alpha Blending and FogAlpha Blending and Fog

© 2008 Cengage Learning EMEA

Page 2: CHAPTER 10 Alpha Blending and Fog © 2008 Cengage Learning EMEA.

LEARNING OBJECTIVESLEARNING OBJECTIVES In this chapter you will learn about:

– Alpha blending– Implementing blending– Implementing blending using shaders– Alpha testing– Fog– The physics of fog– Implementing fog

Page 3: CHAPTER 10 Alpha Blending and Fog © 2008 Cengage Learning EMEA.

ALPHA BLENDINGALPHA BLENDING Alpha blending is a technique used to render

the transparent and/or semi-transparent areas in textures.

An alpha channel can be considered a fourth An alpha channel can be considered a fourth color component, i.e. an add-on to our color component, i.e. an add-on to our current red–green–blue (RGB) color model current red–green–blue (RGB) color model controlling the transparency of a pixel. controlling the transparency of a pixel.

The alpha channel, just like the RGB color The alpha channel, just like the RGB color components, stores an 8-bit value ranging components, stores an 8-bit value ranging from ‘0’ to ‘255’ (‘0’ indicating full from ‘0’ to ‘255’ (‘0’ indicating full transparency and ‘255’ a solid area).transparency and ‘255’ a solid area).

Page 4: CHAPTER 10 Alpha Blending and Fog © 2008 Cengage Learning EMEA.

ALPHA BLENDINGALPHA BLENDING

Page 5: CHAPTER 10 Alpha Blending and Fog © 2008 Cengage Learning EMEA.

ALPHA BLENDINGALPHA BLENDING

Alpha blending works by merging the per-pixel color of one texture with that of another – specifically by combining the color of an alpha-enabled texture with a texture already present at the corresponding screen location.

Page 6: CHAPTER 10 Alpha Blending and Fog © 2008 Cengage Learning EMEA.

ALPHA BLENDINGALPHA BLENDING

The alpha blending equation calculates the final blended color by adding the overlaid pixel color, overlaidPixelColor (which has some specific alpha percentage, alphaPercentage) to the pixel color of the opaque surface, originalPixelColor, with the alpha percentage being subtracted from its opaque solid color:

Page 7: CHAPTER 10 Alpha Blending and Fog © 2008 Cengage Learning EMEA.

ALPHA BLENDINGALPHA BLENDING

The Truevision TGA (.tga) image format offers a solution to the bitmap file format’s lack of compression, transparency, and limited use. – It was one of the first formats to support

truecolor (millions of colors) and is a 32-bit image format with support for transparency and RLE (run-length encoding) compression.

Page 8: CHAPTER 10 Alpha Blending and Fog © 2008 Cengage Learning EMEA.

ALPHA BLENDINGALPHA BLENDING

Page 9: CHAPTER 10 Alpha Blending and Fog © 2008 Cengage Learning EMEA.

Implementing BlendingImplementing Blending

[see the textbook and online source code for a detailed example and discussion].

Page 10: CHAPTER 10 Alpha Blending and Fog © 2008 Cengage Learning EMEA.

Implementing Blending using Implementing Blending using ShadersShaders

Blending can also be performed using pixel and vertex shaders; specifically, textures are combined via fragment program operations and subsequently written to the frame buffer.

Shaders also allow significantly more control over the blending operation, leading to a vast array of advanced blending effects.

[see the textbook for a detailed example and discussion].

Page 11: CHAPTER 10 Alpha Blending and Fog © 2008 Cengage Learning EMEA.

Alpha TestingAlpha Testing

Alpha testing is a technique that controls whether pixels are written to the render-target.

Each pixel of a texture image is either rendered or discarded based on its alpha value. – Thus, the pixel is only written to the render-target if its

alpha value is more than 0.5, for example. Alpha testing is much simpler to implement than

blending as it doesn’t require the initialization of an alpha blend state.

[see the textbook and online source code for a detailed example and discussion].

Page 12: CHAPTER 10 Alpha Blending and Fog © 2008 Cengage Learning EMEA.

FOGFOG

Fog can be described as dense vapour of condensed particles reducing visibility to less than a kilometre.

Page 13: CHAPTER 10 Alpha Blending and Fog © 2008 Cengage Learning EMEA.

FOGFOG

Page 14: CHAPTER 10 Alpha Blending and Fog © 2008 Cengage Learning EMEA.

FogFog

Fog is used for countless environmental effects, its implementation specifically adding to the mood of outdoor environments while at the same time improving rendering performance when combined with the culling of fully obscured objects.

Page 15: CHAPTER 10 Alpha Blending and Fog © 2008 Cengage Learning EMEA.

FogFog Blending is controlled using a linear, exponential,

or Gaussian equation. – Varying these equations results in blending factor

changes. The blending factor is just a way for us to measure

exactly how much a certain color value will be blended with the fog color at a given time. For example, linear fog (as shown in Figure 10-8) will ‘dense up’ at a constant rate as an object’s distance from the viewer increases.

Exponential fog will, on the other hand, increase much more rapidly after a specific distance from the viewer.

Page 16: CHAPTER 10 Alpha Blending and Fog © 2008 Cengage Learning EMEA.

The Physics of FogThe Physics of Fog Fog particles, such as smoke and condensed vapor,

scatter and absorb light travelling from one point to another.

Scattered light can either be directed at or away from the viewer, resulting in a cloudy white color for water vapor and a greyish color for smog due to the higher light absorption rate of smoke particles (depending on its thickness).

The calculation of fog, as previously mentioned, is based on a distance function – specifically, either a linear (fog increases linearly from the point of view to an end point) or exponential function (fog intensifies exponentially from the point-of-view to an end point).

Page 17: CHAPTER 10 Alpha Blending and Fog © 2008 Cengage Learning EMEA.

Implementing FogImplementing Fog Implementing fog in a Direct3D 10 environment

requires emulation of Direct3D 9’s fixed function pipeline via use of an HLSL vertex and pixel shader.

The implementation is relatively simple with a pre-calculated fog factor determining the amount of fog obscuring a particular pixel.

Instead of calculating the fog distance using the planar eye distance (cameraPosition.z), we can also use the HLSL or Cg length function to return the floating-point Euclidean eye distance.

OpenGL offers support for Gaussian (GL_EXP2), exponential (GL_EXP) and linear fog (GL_LINEAR).

[see the textbook and online source code for a detailed example and discussion].


Recommended