You are on page 1of 17

Course Introduction

Gustavo Patow
GGG - UdG
Those slides are based on the
Advanced
Advanced Computer Graphics
Graphics
course by Tomas Akenine-Mller
1

Three major parts of this


course:

Real-Time Rendering

Performance is extremely important.


Really, real-time is soft
Try to increase the level of realism

Shadows
Reflections/refractions
Trees, clouds, water, crowds...

What are the results that are


achievable with
Computer Graphics?
3

State-of-the-Art
Real-Time Rendering
2001

Which one is a real photo,


and which one is CG?

Complexity: 8 million
triangles

Photo-realistic Rendering

The Graphics Rendering Pipeline

The pipeline is the engine that creates


images from 3D scenes
Three conceptual stages of the pipeline:

Application (executed on the CPU)


Geometry
Rasterizer

Application
input

3D
scene

Geometry

Rasterizer

Image

output
8

Application

Geometry

Rasterizer

Lets take a closer look

The programmer sends down


primitives to be rendered through the
pipeline (using API calls)
The geometry stage does per-primitive
and per-vertex operations
The rasterizer stage does per-pixel
operations
9

Application

Geometry

Back to the pipeline:


The APPLICATION stage

Executed on the CPU

Means that the programmer decides what


happens here

Examples:

Rasterizer

Collision detection
Speed-up techniques
Animation

Most important task: send rendering


primitives (e.g. triangles) to the graphics
hardware
10

Application

Geometry

Rasterizer

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.

11

Application

Geometry

Rasterizer

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.
12

Application

Geometry

Rasterizer

The GEOMETRY stage


Task: geometrical operations on the input
data (e.g. triangles)
Allows:

Modify object geometry


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

13

Application

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

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
14

Application

GEOMETRY
The view transform

GEOMETRY
Virtual Camera

Application

Geometry

15

Rasterizer

Defined by position, direction vector, up


vector, field of view, near and far plane.

point

Rasterizer

You can move the camera in the same


manner
But apply inverse transform to objects,
so that camera looks down negative zaxis

Geometry

dir
fov near
(angle)

far

Create image of geometry inside gray region


Used by OpenGL, DirectX, ray tracing, etc.

16

GEOMETRY
Projection

Application

Geometry

Rasterizer

Two major ways to do it

Orthogonal (useful in few applications)


Perspective (most often used)

Mimics how humans perceive the world, i.e.,


objects apparent size decreases with distance

17

GEOMETRY
Projection

Application

Geometry

Rasterizer

Also done with a matrix multiplication!


Pinhole camera (left), analog used in
CG (right)

18

Application

GEOMETRY
Lighting

Geometry

Rasterizer

Compute lighting at vertices


Rasterizer

light
blue
Geometry

red

Try to mimic how light in nature behaves

green

Hardware uses empirical models, hacks, and some


real theory

Much more about this in later lecture


19

Application

Geometry

Rasterizer

GEOMETRY
Clipping and Screen Mapping

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 20

10

GEOMETRY
Summary

model space

compute lighting

world space

projection
image space

Application

world space

clip

Geometry

Rasterizer

camera space

map to screen
21

Application

Geometry

Rasterizer

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)
22

11

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

The RASTERIZER
in more detail

Find out which pixels are inside the primitive


Put images on triangles

Interpolation over triangle


Z-buffering

Rasterizer

Texturing

Geometry

Scan-conversion

Application

23

Make sure that what is visible from the camera


really is displayed

Double buffering
And more
24

12

The RASTERIZER
Scan conversion

Geometry

Rasterizer

Triangle vertices from GEOMETRY is input


Find pixels/fragments inside the triangle

Application

Or on a line, or on a point

Do per-pixel operations on these


fragments:

Interpolation
Texturing
Z-buffering
And more

The RASTERIZER
Interpolation

25

Application

Geometry

Rasterizer

Interpolate colors over the triangle

Called Gouraud interpolation


blue

red

green

26

13

Application

The RASTERIZER
Interpolation

Rasterizer

Gouraud Shading

f(u1)

We know:

Geometry

f(u)~ (f(u1)+f(u2)+f(u3))/3

u1
f(u)??
f(u3)
u3

f(u2)

u2

Phong Shading

u1

f(u)~ f((u1+u2+u3)/3)

We want to evaluate f(u)

u3

u2

The RASTERIZER
Texturing

Geometry

Rasterizer

One application of texturing is to glue images


onto geometrical object
+

Application

27

Uses and other applications

More realism
Bump mapping
Pseudo reflections
Store lighting
Almost infinitely many uses

28

14

The RASTERIZER
Z-buffering

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 1

Triangle 2

Draw 1 then 2

The RASTERIZER
Z-buffering

Application

correct

Draw 2 then 1

Geometry

29

Rasterizer

Would be nice to avoid sorting


The Z-buffer (aka depth buffer) solves this
Idea:

Rasterizer

It just draws triangles

incorrect

Geometry

The graphics hardware is pretty stupid

Application

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


30

15

The RASTERIZER
Double buffering

Application

Geometry

Rasterizer

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
31

The RASTERIZER
Double buffering

Application

Geometry

Rasterizer

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

32

16

And, lately

Programmable shading has become a hot topic

Geometry & Vertex shaders


Pixel shaders
Point & Hull shaders
Adds more control and much more possibilities for the
programmer

HARDWARE
Application

Geometry

Tessellation
programs

Vertex
Shader
programs

Rasterizer

Geometry
Shader
programs

Pixel Shader
program

33

17

You might also like