Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Framebuffer 1 Lecture 37 Fri, Nov 30, 2007.

Similar presentations


Presentation on theme: "The Framebuffer 1 Lecture 37 Fri, Nov 30, 2007."— Presentation transcript:

1 The Framebuffer 1 Lecture 37 Fri, Nov 30, 2007

2 The Framebuffer The framebuffer consists of several separate buffers.
The color buffer(s) Front buffer, back buffer, right buffer, left buffer. The depth buffer The stencil buffer The accumulation buffer. The right and left buffers are used for stereoscopic viewing.

3 The Color Buffer A particular computer may not have the right buffer(s) and it may not have the back buffer(s). We will discuss the front left buffer. The others are similar.

4 The Color Buffer If the screen resolution is 1024  768, then there are pixels on the screen. The color buffer stores 24 bits per pixel – 8 for red, 8 for green, 8 for blue. That’s a total of bytes, or 2.25 Mb. Typically, the color buffer also stores 8 bits for the alpha value. Then the total is 3 Mb.

5 The Color Buffer If there is a back buffer, that’s another 3 Mb, for a total of 6 Mb. If there are stereo buffers (and a back buffer), then the total is 12 Mb.

6 The Framebuffer Read Run

7 Perspective Division The GPU divides the x-, y-, and z-coordinates by the w-coordinate, producing normalized device coordinates. In normalized device coordinates, we have -1  x  1 -1  y  1 -1  z  1 In the z-direction, the z-value becomes the depth of the point.

8 The Depth Buffer z is transformed one last time to the range 0 to 1, called the pseudo-depth. The depth of each point is stored in the depth buffer, also called the z-buffer. Collectively, all the information stored in the buffers for a point is called a fragment. A pixel is only the RGB values stored in the color buffer.

9 Hidden-Surface Removal
How do we determine when one object obstructs another object from view? For each point of each object, we could extend a line from the viewpoint through that point and see if it intersects any point of any other object. This would be extremely time consuming!

10 The Painter’s Algorithm
A simple algorithm is to sort the objects according to their distance from the viewpoint. Then draw them from furthest to nearest. There are some problems with this idea.

11 The Painter’s Algorithm
Which object is nearest? furthest? Eye

12 The Painter’s Algorithm
Which object is nearest? furthest? red green blue yellow Eye

13 The Painter’s Algorithm
Which object is nearest? furthest? yellow red blue green Eye

14 The Depth Buffer In the depth buffer, lower z-values are closer to the viewer. If two points have the same x- and y-coordinates, the one with the lower z-coordinate should be drawn (normally).

15 Hidden-Surface Removal
The objects to be drawn may be placed in the pipeline in any order. When a new fragment “arrives” at the framebuffer, its z-coordinate is compared to the z-coordinate of the fragment currently at that (x, y) location. If the new fragment is closer to the viewer, then it replaces the current fragment.

16 Hidden-Surface Removal
Once all the fragments have arrived, the ones left in the color buffer are the ones to be rendered on the screen.

17 Depth Testing Depth-buffer testing must be enabled using
glEnable(GL_DEPTH_TEST); Then the depth buffer must be cleared, or else the old values will interfere with the new calculations. glClearDepth(1.0); It is cleared to 1.0, which represents the furthest from the viewer; 0.0 represents the nearest.

18 Depth Testing Finally, the type of depth testing may be set using glDepthFunc(). The choices are GL_NEVER, GL_ALWAYS, GL_EQUAL, GL_NOTEQUAL, GL_LESS, GL_GREATER, GL_LEQUAL, GL_GEQUAL. We normally use GL_LESS or GL_LEQUAL.

19 Depth Testing Read Run


Download ppt "The Framebuffer 1 Lecture 37 Fri, Nov 30, 2007."

Similar presentations


Ads by Google