Blending and Fog - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

Blending and Fog

Description:

turn up the specular material property. enable lighting ... when fog is turned on, objects in the distance have less color. To turn fog on. glEnable ( GL_FOG ) ... – PowerPoint PPT presentation

Number of Views:42
Avg rating:3.0/5.0
Slides: 12
Provided by: StephenD3
Category:
Tags: blending | fog | turn

less

Transcript and Presenter's Notes

Title: Blending and Fog


1
Blending and Fog
2
Creating Translucent Surfaces
  • alpha value of 1 solid
  • alpha value of 0 clear

3
  • glEnable ( GL_BLEND )
  • glBlendFunc ( source pixel, destination pixel )
  • source incoming pixel, destination existing
    pixel
  • GL_ONE
  • GL_ZERO
  • GL_SRC_ALPHA
  • GL_DST_ALPHA
  • GL_ONE_MINUS_SRC_ALPHA
  • etc
  • Default is to not blend
  • glBlendFunc (GL_ONE, GL_ZERO)
  • Most Common
  • glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

4
Example Blend
  • Using glBlendFunc ( GL_SRC_ALPHA,
    GL_ONE_MINUS_SRC_ALPHA )
  • first draw the color 1.0, 1.0, 0.0, .75
  • followed by 0.0, 1.0, 1.0, .75
  • yields color .25, 1.0, .75,
    0.9375
  • 25 of dest (existing), plus 75 of src
    (incoming)
  • reversing the order of the drawing colors yields
    .75, 1.0, .25, 0.9375

5
Example cont
6
Blending in 3D
  • Suppose we have solid green and red boxes and
    clear blue and orange boxes. Where blue overlaps
    green we should blend. Where green overlaps
    orange, we should replace.

Z axis
view from above
projection plane
7
How to Blend in 3D
  • turn on Depth Test
  • draw all opaque objects
  • make depth buffer read-only
  • glDepthMask(GL_FALSE)
  • draw all translucent objects
  • all the opaque objects are depth sorted as usual
  • since the depth test is on, any translucent
    object that is behind a solid will not be drawn
  • translucent pixels drawn in front of a solid will
    have the source blended into the destination

8
Cool Blending EffectsShiny Glass
  • render all opaque objects
  • disable lighting
  • enable blending
  • render glass polygon in very light grey to create
    a faint appearance
  • set ambient and diffuse material properties to
    zero
  • turn up the specular material property
  • enable lighting
  • glDepthFunc (GL_EQUAL)
  • render glass again

9
Cool Blending EffectsTrees
  • apply a texture that looks like leaves, and has
    lots of different alpha values
  • so some light goes through, other parts are solid
  • draw several of the polygons at different angles

10
Fog
  • when fog is turned on, objects in the distance
    have less color
  • To turn fog on
  • glEnable ( GL_FOG )
  • glFogfv (GL_FOG_COLOR, color)
  • probably dark gray

11
Amount of Fog Effect
  • glFogi ( GL_FOG_MODE, mode)
  • GL_LINEAR
  • GL_EXP (default)
  • GL_EXP2
  • Linear fog amount
  • exponent fog amount e -(density z)
  • glFogf ( GL_FOG_START, frontz)
  • glFogf ( GL_FOG_END, backz)
  • glFogf ( GL_FOG_DENSISTY, 0.3)
Write a Comment
User Comments (0)
About PowerShow.com