2010©. introduction graphics rendering pipeline architecture application stages geometry stages...

44
Real-Time Rendering 靜靜靜靜靜靜靜靜靜 靜靜靜靜靜靜 2010©

Upload: jamison-swanick

Post on 29-Mar-2015

323 views

Category:

Documents


0 download

TRANSCRIPT

  • Slide 1

2010 Slide 2 Introduction Graphics Rendering Pipeline Architecture Application Stages Geometry Stages Rasterizer Stages Slide 3 Tomas Akenine-Mller 2002 What are the results that are achievable with Computer Graphics? Slide 4 Tomas Akenine-Mller 2002 State-of-the-Art Real-Time Rendering 2001 Slide 5 Tomas Akenine-Mller 2002 State-of-the-Art Real-Time Rendering 2001 Slide 6 Tomas Akenine-Mller 2002 Which one is a real photo, and which one is CG? Slide 7 Tomas Akenine-Mller 2002 Complexity: 8 million triangles Slide 8 Tomas Akenine-Mller 2002 Photo-realistic Rendering Slide 9 Introduction Real-time rendering is concerned with making images rapidly on the computer. The rate at which images are displayed is measured in frames per second (fps) or Hertz (Hz). Usually between 15 fps and 72 fps. Interactivity, 3D rendering, graphics acceleration hardware. Include applications such as computer games, CAD, 3D animation software (3D Max or Maya), , etc. Slide 10 Graphics Rendering Pipeline The main function of the pipeline is to generate, or render, a two-dimensional image, given a virtual camera, 3D objects, light sources, shading equations, textures, and more. Slide 11 Pipeline Architecture conceptual stages functional stages pipeline stages A pipeline consists of several stages. The speed of the pipeline is determined by the slowest stage, no matter how fast the other stages may be. Slide 12 Conceptual Stages 1. Application 2. Geomrtry 3. Rasterizer Slide 13 Tomas Akenine-Mller 2002 The APPLICATION stage Executed on the CPU Means that the programmer decides what happens here Examples: Collision detection Speed-up techniques Animation Most important task: send rendering primitives (e.g. triangles) to the graphics hardware ApplicationGeometryRasterizer Slide 14 Tomas Akenine-Mller 2002 Rendering Primitives Use graphics hardware for real time These can render points, lines, triangles. A surface is thus an approximation by a number of such primitives. Slide 15 Tomas Akenine-Mller 2002 You say that you render a 3D scene, but what is it? First, of all to take a picture, it takes a camera a virtual one. Decides what should end up in the final image A 3D scene is: Geometry (triangles, lines, points, and more) Light sources Material properties of geometry Textures (images to glue onto the geometry) A triangle consists of 3 vertices A vertex is 3D position, and may include normals and more. Slide 16 Tomas Akenine-Mller 2002 Virtual Camera Defined by position, direction vector, up vector, field of view, near and far plane. point dir near far fov (angle) Create image of geometry inside gray region Used by OpenGL, DirectX, ray tracing, etc. Slide 17 Tomas Akenine-Mller 2002 The GEOMETRY stage Task: geometrical operations on the input data (e.g. triangles) Allows: Move objects (matrix multiplication) Move the camera (matrix multiplication) Compute lighting at vertices of triangle Project onto screen (3D to 2D) Clipping (avoid triangles outside screen) Map to window ApplicationGeometryRasterizer Slide 18 Tomas Akenine-Mller 2002 Animate objects and camera Can animate in many different ways with 4x4 matrices Example: Before displaying a torus on screen, a matrix that represents a rotation can be applied. The result is that the torus is rotated. Same thing with camera (this is possible since motion is relative) ApplicationGeometryRasterizer Slide 19 Tomas Akenine-Mller 2002 The RASTERIZER stage Main task: take output from GEOMETRY and turn into visible pixels on screen Also, add textures and various other per-pixel operations And visibility is resolved here: sorts the primitives in the z-direction ApplicationGeometryRasterizer Slide 20 Tomas Akenine-Mller 2002 In Summery The programmer sends down primtives to be rendered through the pipeline (using API calls) The geometry stage does per-vertex operations The rasterizer stage does per-pixel operations Next, scrutinize geometry and rasterizer ApplicationGeometryRasterizer Slide 21 The GEOMETRY stages Tomas Akenine-Mller 2002 ApplicationGeometryRasterizer Slide 22 Tomas Akenine-Mller 2002 GEOMETRY Model Transformation Originally, an object is in model space Move, orient, and transform geometrical objects into world space Example, a sphere is defined with origin at (0,0,0) with radius 1 Translate, rotate, scale to make it appear elsewhere Done per vertex with a 4x4 matrix multiplication! The user can apply different matrices over time to animate objects ApplicationGeometryRasterizer Slide 23 Tomas Akenine-Mller 2002 GEOMETRY View Transform You can move the camera in the same manner But apply inverse transform to objects, so that camera looks down negative z-axis ApplicationGeometryRasterizer Slide 24 GEOMETRY Vertex Shading light Geometry blue red green Rasterizer Materials + Lighting Shading Compute color at vertices Try to mimic how light in nature behaves Hard to uses empirical models, hacks, and some real theory ApplicationGeometryRasterizer shading equation Slide 25 Tomas Akenine-Mller 2002 GEOMETRY Projection Two major ways to do it Orthogonal Perspective Mimics how humans perceive the world, i.e., objects apparent size decreases with distance ApplicationGeometryRasterizer Slide 26 Tomas Akenine-Mller 2002 GEOMETRY Projection Also done with a matrix multiplication! Pinhole camera (left), analog used in CG (right) ApplicationGeometryRasterizer Slide 27 GEOMETRY Clipping Square (cube) after projection Clip primitives to square ApplicationGeometryRasterizer Slide 28 GEOMETRY Screen Mapping Screen mapping, scales and translates square so that it ends up in a rendering window These screen space coordinates together with Z (depth) are sent to the rasterizer stage ApplicationGeometryRasterizer Slide 29 Tomas Akenine-Mller 2002 GEOMETRY Summary model spaceworld space compute lightingcamera space projection image space clip map to screen ApplicationGeometryRasterizer Slide 30 The RASTERIZER stages Tomas Akenine-Mller 2002 ApplicationGeometryRasterizer Slide 31 The RASTERIZER Triangle Setup Tomas Akenine-Mller 2002 ApplicationGeometryRasterizer In this stage the differentials and other data for the triangle's surface are computed. This data is used for scan conversion, as well as for interpolation of the various shading data produced by the geometry stage. This process is performed by fixed-operation hardware dedicated to this task. Slide 32 Tomas Akenine-Mller 2002 The RASTERIZER Triangle Traversal (Scan Conversion) Find pixels inside the triangle Or on a line, or on a point Do per-pixel operations on these pixels: Interpolation Texturing Z-buffering And more ApplicationGeometryRasterizer Slide 33 Tomas Akenine-Mller 2002 The RASTERIZER Interpolation Interpolate colors over the triangle Called Gouraud interpolation blue red green ApplicationGeometryRasterizer Slide 34 The RASTERIZER Pixel Shading ApplicationGeometryRasterizer Using the interpolated shading data as input The end result is one or more colors to be passed on to the next stage is executed by programmable GPU cores Texturing is one of the most important techniquies Slide 35 The RASTERIZER Texturing += One application of texturing is to glue images onto geometrical object Uses and other applications More realism Bump mapping Pseudo reflections Store lighting Almost infinitely many uses ApplicationGeometryRasterizer Slide 36 Example of texturing Slide 37 The RASTERIZER Merging ApplicationGeometryRasterizer Pixels are stored in color buffer Combine the fragment color with the pixel color Highly configurable Resolving visibility (done with Z-buffer) alpha channel for transparency stencil buffer for masking accumulation buffer for motion blur, depth of field, soft shadows, or antialiasing Slide 38 The RASTERIZER Z-buffering The graphics hardware is pretty stupid It just draws triangles However, a triangle that is covered by a more closely located triangle should not be visible Assume two equally large tris at different depths Triangle 1Triangle 2Draw 1 then 2 incorrect Draw 2 then 1 correct ApplicationGeometryRasterizer Slide 39 Tomas Akenine-Mller 2002 Would be nice to avoid sorting The Z-buffer (aka depth buffer) solves this Idea: Store z (depth) at each pixel When scan-converting a triangle, compute z at each pixel on triangle Compare triangles z to Z-buffer z-value If triangles z is smaller, then replace Z-buffer and color buffer Else do nothing Can render in any order Have difficulty to handle transparancy The RASTERIZER Z-buffering ApplicationGeometryRasterizer Slide 40 Tomas Akenine-Mller 2002 The RASTERIZER Double Buffering The monitor displays one image at a time So if we render the next image to screen, then rendered primitives pop up And even worse, we often clear the screen before generating a new image A better solution is double buffering ApplicationGeometryRasterizer Slide 41 Tomas Akenine-Mller 2002 Use two buffers: one front and one back The front buffer is displayed The back buffer is rendered to When new image has been created in back buffer, swap front and back The RASTERIZER Double Buffering ApplicationGeometryRasterizer Slide 42 Double Buffering Front Buffer Back Buffer Copy Back Buffer Front Buffer backfront backfront backfront (vertical retrace) Slide 43 Flipping Front Buffer Back Buffer back front register A B front back register A B Slide 44 And, lately Programmable shading has become a hot topic Vertex shaders Pixel shaders Adds more control and much more possibilities for the programmer Application Geometry Rasterizer HARDWARE Vertex shader program Pixel shader program