intro to gràfics en temps real
TRANSCRIPT
8/18/2019 intro to Gràfics en Temps Real
http://slidepdf.com/reader/full/intro-to-grafics-en-temps-real 1/17
1
1
Course Introduction
Gustavo Patow
GGG - UdG
Those slides are based on the” Advanced Computer Graphics Advanced Computer Graphics” course by Tomas Akenine-Möller
2
Three major parts of thiscourse:
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...
8/18/2019 intro to Gràfics en Temps Real
http://slidepdf.com/reader/full/intro-to-grafics-en-temps-real 2/17
2
3
What are the results that are
achievable with
Computer Graphics?
4
State-of-the-ArtReal-Time Rendering2001
8/18/2019 intro to Gràfics en Temps Real
http://slidepdf.com/reader/full/intro-to-grafics-en-temps-real 3/17
3
5
Which one is a real photo,and which one is CG?
6
Complexity: 8 milliontriangles…
8/18/2019 intro to Gràfics en Temps Real
http://slidepdf.com/reader/full/intro-to-grafics-en-temps-real 4/17
4
7
Photo-realistic Rendering…
8
The Graphics Rendering Pipeline
The pipeline is the ”engine” that createsimages from 3D scenes
Three conceptual stages of the pipeline:
Application (executed on the CPU)
Geometry
Rasterizer
Application Geometry Rasterizer
3D
sceneinput
Image
output
8/18/2019 intro to Gràfics en Temps Real
http://slidepdf.com/reader/full/intro-to-grafics-en-temps-real 5/17
5
9
Let’s take a closer look
The programmer ”sends” downprimitives to be rendered through thepipeline (using API calls)
The geometry stage does per-primitiveand per-vertex operations
The rasterizer stage does per-pixeloperations
Application Geometry Rasterizer
10
Back to the pipeline: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 renderingprimitives (e.g. triangles) to the graphicshardware
Application Geometry Rasterizer
8/18/2019 intro to Gràfics en Temps Real
http://slidepdf.com/reader/full/intro-to-grafics-en-temps-real 6/17
6
11
Rendering Primitives
Use graphics hardware for real time…
These can render points, lines, triangles.
A surface is thus an approximation by anumber of such primitives.
Application Geometry Rasterizer
12
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 mayinclude normals and more.
Application Geometry Rasterizer
8/18/2019 intro to Gràfics en Temps Real
http://slidepdf.com/reader/full/intro-to-grafics-en-temps-real 7/17
7
13
The GEOMETRY stage
Task: ”geometrical” operations on the inputdata (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
Application Geometry Rasterizer
14
The GEOMETRYstage in more detail
TheThe modelmodel transformtransform
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 toanimate objects
Application Geometry Rasterizer
8/18/2019 intro to Gràfics en Temps Real
http://slidepdf.com/reader/full/intro-to-grafics-en-temps-real 8/17
8
15
GEOMETRYThe view transform
You can move the camera in the samemanner
But apply inverse transform to objects,so that camera looks down negative z-axis
z x
Application Geometry Rasterizer
16
GEOMETRY Virtual Camera
Defined by position, direction vector, upvector, field of view, near and far plane.
pointdir
near far
fov
(angle)
Create image of geometry inside gray region
Used by OpenGL, DirectX, ray tracing, etc.
Application Geometry Rasterizer
8/18/2019 intro to Gràfics en Temps Real
http://slidepdf.com/reader/full/intro-to-grafics-en-temps-real 9/17
9
17
GEOMETRYProjection
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
Application Geometry Rasterizer
18
GEOMETRYProjection
Also done with a matrix multiplication!
Pinhole camera (left), analog used in
CG (right)
Application Geometry Rasterizer
8/18/2019 intro to Gràfics en Temps Real
http://slidepdf.com/reader/full/intro-to-grafics-en-temps-real 10/17
10
19
GEOMETRYLighting
Compute ”lighting” at vertices
Try to mimic how light in nature behaves Hardware uses empirical models, hacks, and some
real theory
Much more about this in later lecture
Application Geometry Rasterizer
light
Geometry
blue
red green
Rasterizer
20
GEOMETRYClipping and Screen Mapping
Square (cube) after projection
Clip primitives to square
Application Geometry Rasterizer
Screen mapping, scales and translates squareso that it ends up in a rendering window
These ”screen space coordinates” together with Z (depth) are sent to the rasterizer stage
8/18/2019 intro to Gràfics en Temps Real
http://slidepdf.com/reader/full/intro-to-grafics-en-temps-real 11/17
11
21
GEOMETRYSummary
Application Geometry Rasterizer
model space world space world space
compute lighting
camera space
projection
image space
clip map to screen
22
Animate objects and camera
Can animate in many different ways with 4x4matrices
Example:
Before displaying a torus on screen, a matrix thatrepresents a rotation can be applied
The result is that the torus is rotated
Same thing with camera (this is possible sincemotion is relative)
Application Geometry Rasterizer
8/18/2019 intro to Gràfics en Temps Real
http://slidepdf.com/reader/full/intro-to-grafics-en-temps-real 12/17
12
23
The RASTERIZER stage
Main task: take output from GEOMETRYand turn into visible pixels on screen
Application Geometry Rasterizer
Also, add textures and various other per-pixeloperations
And visibility is resolved here: sorts theprimitives in the z-direction
24
The RASTERIZERin more detail
Scan-conversion Find out which pixels are inside the primitive
Texturing Put images on triangles
Interpolation over triangle
Z-buffering Make sure that what is visible from the camera
really is displayed
Double buffering
And more…
Application Geometry Rasterizer
8/18/2019 intro to Gràfics en Temps Real
http://slidepdf.com/reader/full/intro-to-grafics-en-temps-real 13/17
13
25
The RASTERIZERScan conversion
Triangle vertices from GEOMETRY is input
Find pixels/fragments inside the triangle
Or on a line, or on a point
Do per-pixel operations on thesefragments:
Interpolation
Texturing
Z-buffering
And more…
Application Geometry Rasterizer
26
The RASTERIZERInterpolation
Interpolate colors over the triangle
Called Gouraud interpolation
Application Geometry Rasterizer
blue
red green
8/18/2019 intro to Gràfics en Temps Real
http://slidepdf.com/reader/full/intro-to-grafics-en-temps-real 14/17
14
27
The RASTERIZER Interpolation
Application Geometry Rasterizer
u1
u2
u3
We want to evaluate f(u)
f(u)??
f(u1)
u1
u2
u3
f(u3) f(u2)
f(u)~ (f(u1)+f(u2)+f(u3))/3
f(u)~ f((u1+u2+u3)/3)
Gouraud Shading
Phong Shading
We know:
28
The RASTERIZERTexturing
One application of texturing is to ”glue” imagesonto geometrical object
Uses and other applications More realism
Bump mapping
Pseudo reflections
Store lighting
Almost infinitely many uses
Application Geometry Rasterizer
+ =
8/18/2019 intro to Gràfics en Temps Real
http://slidepdf.com/reader/full/intro-to-grafics-en-temps-real 15/17
15
29
The RASTERIZERZ-buffering
The graphics hardware is pretty stupid It ”just” draws triangles
However, a triangle that is covered by a moreclosely located triangle should not be visible
Assume two equally large tris at differentdepths
Application Geometry Rasterizer
Triangle 1 Triangle 2 Draw 1 then 2
incorrect
Draw 2 then 1
correct
30
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 triangle’s z to Z-buffer z-value
If triangle’s z is smaller, then replace Z-buffer andcolor buffer
Else do nothing
Can render in any order
The RASTERIZERZ-buffering
Application Geometry Rasterizer
8/18/2019 intro to Gràfics en Temps Real
http://slidepdf.com/reader/full/intro-to-grafics-en-temps-real 16/17
16
31
The RASTERIZERDouble buffering
The monitor displays one image at atime
So if we render the next image toscreen, then rendered primitives pop up
And even worse, we often clear thescreen before generating a new image
A better solution is ”double buffering”
Application Geometry Rasterizer
32
Use two buffers: one front and oneback
The front buffer is displayed The back buffer is rendered to
When new image has been created inback buffer, swap front and back
The RASTERIZERDouble buffering
Application Geometry Rasterizer
8/18/2019 intro to Gràfics en Temps Real
http://slidepdf.com/reader/full/intro-to-grafics-en-temps-real 17/17
17
33
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 theprogrammer
Application Geometry Rasterizer
HARDWARE
Vertex
Shader
programs
Pixel Shader
program
Geometry
Shader
programs
Tessellation
programs