The Mystic Z Values CS 6500 Adv Computer

  • Slides: 11
Download presentation
The Mystic Z Values CS 6500 Adv. Computer Graphics © Chun-Fa Chang, Spring 2003

The Mystic Z Values CS 6500 Adv. Computer Graphics © Chun-Fa Chang, Spring 2003

Today’s Short Film Special Effects in A. I. CS 6500 Adv. Computer Graphics ©

Today’s Short Film Special Effects in A. I. CS 6500 Adv. Computer Graphics © Chun-Fa Chang, Spring 2003

Announcement • Assignment 1 still due on March 5. • Volunteers wanted for paper

Announcement • Assignment 1 still due on March 5. • Volunteers wanted for paper presentations on March 18 & 25: – 2 presentations each date. – +5 bonus for presentation grades. – Paper list to be posted next week. CS 6500 Adv. Computer Graphics © Chun-Fa Chang, Spring 2003

Z Buffer • THE choice of hidden surface removal algorithms in computer graphics. •

Z Buffer • THE choice of hidden surface removal algorithms in computer graphics. • Also called “Depth Buffer. ” • Note that Z distance. CS 6500 Adv. Computer Graphics © Chun-Fa Chang, Spring 2003

“So, Where are the problem? ” • The Z values in Open. GL depth

“So, Where are the problem? ” • The Z values in Open. GL depth buffer are not exactly the Z in world space (or eye space). • For example, glu. Perspective in the next slide: CS 6500 Adv. Computer Graphics © Chun-Fa Chang, Spring 2003

Projection Matrix • glu. Perspective(fov. Y, aspect, Zn, Zf) produces projection matrix of: [

Projection Matrix • glu. Perspective(fov. Y, aspect, Zn, Zf) produces projection matrix of: [ A 0 0 0 ] [ 0 f 0 0 ] [ 0 0 B C ] [ 0 0 -1 0 ] Where B = (Zf+Zn)/(Zn-Zf), C=2*Zf*Zn/(Zn-Zf) So Z buffer will get B*Z + C CS 6500 Adv. Computer Graphics © Chun-Fa Chang, Spring 2003

Why Not Just Use Z? • We want Z to be within 0 and

Why Not Just Use Z? • We want Z to be within 0 and 1. • So it may be represented in fewer bits (such as 16 -bit or 24 -bit Z values). CS 6500 Adv. Computer Graphics © Chun-Fa Chang, Spring 2003

A Derivation: Step (0) • Ys/D=Y/(Z+D), If we let Ws=(Z+D)/D, then Ys=Y/Ws and Zs=Z/Ws.

A Derivation: Step (0) • Ys/D=Y/(Z+D), If we let Ws=(Z+D)/D, then Ys=Y/Ws and Zs=Z/Ws. • Exercise: What is the projection matrix? Y Ys Z D CS 6500 Adv. Computer Graphics © Chun-Fa Chang, Spring 2003

Step (1): Move the eye to Z=0 • Ys=Y/(Z/D), Ws=Z/D, so Zs=(Z-D)/Ws • Exercise:

Step (1): Move the eye to Z=0 • Ys=Y/(Z/D), Ws=Z/D, so Zs=(Z-D)/Ws • Exercise: What is the projection matrix? Y Ys Z D CS 6500 Adv. Computer Graphics © Chun-Fa Chang, Spring 2003

A Derivation: Step (2) • Now, we want to map Zn 0 and Zf

A Derivation: Step (2) • Now, we want to map Zn 0 and Zf 1. • If the matrix is: [ [ 1 0 0 0 0 A 1/D 0 0 B 0 ] ] Then: A*Zn+B=0, A*Zf+B=Zf/D. • Exercise: What are A and B? CS 6500 Adv. Computer Graphics © Chun-Fa Chang, Spring 2003

References • Chapter 18 of “Jim Blinn's Corner: A Trip Down the Graphics Pipeline”

References • Chapter 18 of “Jim Blinn's Corner: A Trip Down the Graphics Pipeline” • Kenny Hoff’s Note on “Deriving the Open. GL Perspective Depth Transformmation” http: //www. cs. unc. edu/~hoff/techrep • Steve Baker, “Learning to Love your Z-buffer” http: //sjbaker. org/steve/omniv/love_your_z_buffer. html CS 6500 Adv. Computer Graphics © Chun-Fa Chang, Spring 2003