Realtime Rendering Introduction Graphics Pipeline Raster Graphics Lower

  • Slides: 31
Download presentation
Real-time Rendering - Introduction - Graphics Pipeline

Real-time Rendering - Introduction - Graphics Pipeline

Raster Graphics Lower costs enabled by mass production of Television General representations on addressable

Raster Graphics Lower costs enabled by mass production of Television General representations on addressable matrix: text, images, filled primitives Frame buffer Lots of memory; initially expensive Decouple refresh frequency from application update of display list Interlaced and Non-interlaced Need to convert continuous primitives for discrete raster 2 Scan conversion

Raster Graphics 3

Raster Graphics 3

Frame Buffer 4

Frame Buffer 4

Interactivity and Realism Time-faithful (interactivity) Space-faithful (visual realism) Interactivity is defined as 20 -30

Interactivity and Realism Time-faithful (interactivity) Space-faithful (visual realism) Interactivity is defined as 20 -30 frames per second Photo-realism is one touchstone for realism Realism and Interactivity are mutually conflicting goals The complexity of graphics datasets of interest keeps growing 5

The Graphics Rendering Pipeline 6

The Graphics Rendering Pipeline 6

The Graphics Rendering Pipeline The pipeline is the engine that creates images from 3

The Graphics Rendering Pipeline The pipeline is the engine that creates images from 3 D scenes Three conceptual stages of the pipeline: Application (executed on the CPU) Geometry Rasterizer Application Geometry Rasterizer Image output input 7 3 D scene Tomas Akenine-Mőller © 2002

Rendering Primitives Use graphics hardware for real time… These can render points, lines, triangles.

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. 8 Tomas Akenine-Mőller © 2002

Rendering a 3 D scene First, of all to take a picture, it takes

Rendering a 3 D scene First, of all to take a picture, it takes a camera – a virtual one. Decides what should end up in the final image A 3 D 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 9 A vertex is 3 D position, and may include normals and more. Tomas Akenine-Mőller © 2002

Virtual Camera Defined by position, direction vector, up vector, field of view, near and

Virtual Camera Defined by position, direction vector, up vector, field of view, near and far plane. point fov (angle) l l dir far near Create image of geometry inside gray region Used by Open. GL, Direct. X, ray tracing, etc 10

Back to the pipeline: The APPLICATION stage Rasterizer Means that the programmer decides what

Back to the pipeline: The APPLICATION stage Rasterizer Means that the programmer decides what happens here Examples: Geometry Executed on the CPU Application Collision detection Speed-up techniques Animation Most important task: send rendering primitives (e. g. triangles) to the graphics hardware 11

Application Geometry Rasterizer The GEOMETRY stage Task: ”geometrical” operations on the input data (e.

Application Geometry Rasterizer The GEOMETRY stage Task: ”geometrical” operations on the input data (e. g. triangles) Allows: 12 Move objects (matrix multiplication) Move the camera (matrix multiplication) Compute lighting at vertices of triangle Project onto screen (3 D to 2 D) Clipping (avoid triangles outside screen) Map to window

Application Geometry Rasterizer Animate objects and camera Can animate in many different ways with

Application Geometry Rasterizer Animate objects and camera Can animate in many different ways with 4 x 4 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) 13

Application Geometry Rasterizer The RASTERIZER stage Main task: take output from GEOMETRY and turn

Application Geometry Rasterizer 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 14

Rewind! Let’s take a closer look Application Geometry The programmer ”sends” down primtives to

Rewind! Let’s take a closer look Application Geometry 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 15 Rasterizer

The GEOMETRY stage in more detail Geometry Rasterizer The model transform Originally, an object

The GEOMETRY stage in more detail Geometry Rasterizer The model transform 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 Application Translate, rotate, scale to make it appear elsewhere Done per vertex with a 4 x 4 matrix multiplication! The user can apply different matrices over time to animate objects 16

GEOMETRY The view transform Application Geometry Rasterizer You can move the camera in the

GEOMETRY The view transform Application Geometry Rasterizer You can move the camera in the same manner But apply inverse transform to objects, so that camera looks down negative z-axis z 17 x

GEOMETRY Lighting Application Geometry Compute ”lighting” at vertices Rasterizer light blue Geometry red Rasterizer

GEOMETRY Lighting Application Geometry Compute ”lighting” at vertices Rasterizer light blue Geometry red Rasterizer green Try to mimic how light in nature behaves 18 Hard to uses empirical models, hacks, and some real theory

GEOMETRY Projection Application Geometry Two major ways to do it Orthogonal (useful in few

GEOMETRY Projection Application Geometry Two major ways to do it Orthogonal (useful in few applications) Perspective (most often used) 19 Mimics how humans perceive the world, i. e. , objects’ apparent size decreases with distance Rasterizer

GEOMETRY Projection Application Geometry Also done with a matrix multiplication! Pinhole camera (left), analog

GEOMETRY Projection Application Geometry Also done with a matrix multiplication! Pinhole camera (left), analog used in CG (right) 20 Rasterizer

GEOMETRY Clipping and Screen Mapping Application Geometry Rasterizer Square (cube) after projection Clip primitives

GEOMETRY Clipping and Screen Mapping Application Geometry Rasterizer Square (cube) after projection Clip primitives to square 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 21

GEOMETRY Summary model space compute lighting 22 Application world space projection image space world

GEOMETRY Summary model space compute lighting 22 Application world space projection image space world space clip Geometry Rasterizer camera space map to screen

The RASTERIZER in more detail Put images on triangles Interpolation over triangle Z-buffering Find

The RASTERIZER in more detail Put images on triangles Interpolation over triangle Z-buffering Find out which pixels are inside the primitive Texturing Geometry Scan-conversion Application Make sure that what is visible from the camera really is displayed Double buffering And more… 23 Rasterizer

The RASTERIZER Scan conversion Triangle vertices from GEOMETRY is input Find pixels inside the

The RASTERIZER Scan conversion Triangle vertices from GEOMETRY is input Find pixels inside the triangle Application Or on a line, or on a point Do per-pixel operations on these pixels: 24 Interpolation Texturing Z-buffering And more… Geometry Rasterizer

The RASTERIZER Interpolation Application Interpolate colors over the triangle Called Gouraud interpolation blue red

The RASTERIZER Interpolation Application Interpolate colors over the triangle Called Gouraud interpolation blue red 25 green Geometry Rasterizer

The RASTERIZER Texturing Geometry Rasterizer One application of texturing is to ”glue” images onto

The RASTERIZER Texturing Geometry Rasterizer One application of texturing is to ”glue” images onto geometrical object + Application = Uses and other applications 26 More realism Bump mapping Pseudo reflections Store lighting Almost infinitely many uses

The RASTERIZER Z-buffering Geometry Rasterizer The graphics hardware is pretty stupid Application It ”just”

The RASTERIZER Z-buffering Geometry Rasterizer The graphics hardware is pretty stupid Application 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 incorrect Triangle 1 27 Triangle 2 Draw 1 then 2 correct Draw 2 then 1

The RASTERIZER Z-buffering Geometry Rasterizer Would be nice to avoid sorting… The Z-buffer (aka

The RASTERIZER Z-buffering Geometry Rasterizer Would be nice to avoid sorting… The Z-buffer (aka depth buffer) solves this Idea: Application Store z (depth) at each pixel When scan-converting a triangle, compute z at each pixel on triangle Compare triangle’s z to Z-buffer z-value If triangle’s z is smaller, then replace Z-buffer and color buffer Else do nothing Can render in any order 28

The RASTERIZER Double buffering Application Geometry The monitor displays one image at a time

The RASTERIZER Double buffering Application Geometry 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” 29 Rasterizer

The RASTERIZER Double buffering Application Geometry Use two buffers: one front and one back

The RASTERIZER Double buffering Application Geometry 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 30 Rasterizer

And, lately… Programmable shading has become a hot topic Vertex shaders Pixel shaders Adds

And, lately… Programmable shading has become a hot topic Vertex shaders Pixel shaders Adds more control and much more possibilities for the programmer HARDWARE Application Geometry Vertex shader program 31 Rasterizer Pixel shader program