Depth Buffers - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

Depth Buffers

Description:

Controls how color values in the fragment being processed (the ... Draw blue polygon in the back ... 4.OpenGL Red Book, http://www.opengl.org/documentation ... – PowerPoint PPT presentation

Number of Views:52
Avg rating:3.0/5.0
Slides: 14
Provided by: hirosh4
Category:
Tags: buffers | depth

less

Transcript and Presenter's Notes

Title: Depth Buffers


1
Depth Buffers Transparency
ECS175 Discussion Session 6
  • Hiroshi Akiba Feb 20, 2004

2
Outline
  • Depth Buffer
  • Overview
  • OpenGL depth buffer functions
  • Transparency Effect
  • overview
  • OpenGL transparency functions
  • example

3
Depth Buffer Overview
  • The most widely used visible surface detection
    method
  • Easy to implement
  • Compatible with pipeline architecture
  • Works in image space
  • It can be implemented with a small number of
    additional calculations at the scan conversion
    process
  • Worst case complexity is proportional to the
    number of polygons

4
Depth Buffer Overview






5
Depth Buffer Overview






6
Depth Buffer Overview






7
Depth Buffer Functions
  • glutInitDisplayMode(GLUT_SINGLEGLUT_RGBGLUT_DEPT
    H)
  • Declares to use depth buffer(z buffer)
  • The defaults are GLUT_SINGLE and GLUT_RGB
  • glClear(GL_DEPTH_BUFFER_BIT)
  • Sets all depth-buffer values to the maximum value
    (1.0 in default)
  • Need to call for every frame
  • glEnable(GL_DEPTH_TEST)
  • Activate visibility detection routines
  • glClearDepth(maxDepth)
  • Change maximum depth value in the range 0.0 to
    1.0
  • glDepthRange(nearDepth, farDepth)t
  • The defaults are 0.0 and 1.0
  • glDepthFunc(testCondition) --- GL_LESS(default),
    GL_GREATER,
  • glDepthMask(writeStatus) --- GL_TRUE or GL_FALSE

Necessary in hw4
8
OpenGL Transparency Overview
  • The transparency effect is simulated by color
    blending
  • Ignore the path shifts due to refraction

9
Transparency Functions
  • glutInitDisplayMode(GLUT_SINGLEGLUT_RGBAGLUT_DEP
    TH)
  • glColor4f(R,G,B,A)
  • glColor3f(R,G,B) glColor4f(R,G,B,1)
  • glEnable(GL_BLEND)
  • glBlendFunc(GLenum sfactor, GLenum dfactor)
  • Controls how color values in the fragment being
    processed (the source) are combined with those
    already stored in the framebuffer (the
    destination).
  • let the source and destination blending factors
    be (Sr, Sg, Sb, Sa) and (Dr, Dg, Db, Da) Final
    Color will be
  • (RsSrRdDr, GsSgGdDg, BsSbBdDb, AsSaAdDa)
  • GL_ONE_MINUS_SRC_ALPHA (1, 1, 1, 1)-(As, As, As,
    As)
  • GL_SRC_ALPHA (As, As, As, As)

10
Example
  • glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA)
  • (RsSrRdDr, GsSgGdDg, BsSbBdDb, AsSaAdDa)
  • GL_ONE_MINUS_SRC_ALPHA (1, 1, 1, 1)-(As, As, As,
    As)
  • GL_SRC_ALPHA (As, As, As, As)

glColor4f(0,0,1,1)
Draw blue polygon in the back fist
(Sr,Sg,Sb)(0.6, 0.6, 0.6) (Dr,Dg,Db)(0.4, 0.4,
0.4) Color (00.610.4, 00.600.4,
10.600.4) ( 0.4, 0, 0.6)
glColor4f(1,0,0,0.4)
11
Problem
  • What if there are an opaque object and two
    transparent objects intersect each other?

12
Solution
  • Render opaque objects first with the depth
    buffer, and render transparent objects without
    writing to the depth buffer.

glEnable(GL_DEPTH_TEST) DrawAllOpaqueObjects()
glEnable(GL_BLEND) glDepthMask(GL_FALSE) glBle
ndFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA)
DrawAllTransparentObjects() glDepthMask(GL_TRUE)
glDisable(GL_BLEND)
13
References
  • 1.Hearn baker, Computer Graphics width OpenGL,
    2004
  • 2.Edward Angel, Interactive Computer Graphics A
    Top-Down Approach with OpenGL, 2000
  • 3. Edward Angle, OpenGL A PRIMER, 2002
  • 4.OpenGL Red Book, http//www.opengl.org/documenta
    tion/red_book_1.0/
  • 5.Ken Joy, Online Graphics Note,
    http//graphics.cs.ucdavis.edu/GraphicsNotes/Z-Buf
    fer-Algorithm/Z-Buffer-Algorithm.html
Write a Comment
User Comments (0)
About PowerShow.com