Basics of 3D Rendering CS 148: Summer 2016 Introduction of Graphics - - PowerPoint PPT Presentation

basics of 3d rendering
SMART_READER_LITE
LIVE PREVIEW

Basics of 3D Rendering CS 148: Summer 2016 Introduction of Graphics - - PowerPoint PPT Presentation

Basics of 3D Rendering CS 148: Summer 2016 Introduction of Graphics and Imaging Zahid Hossain http://www.pling.org.uk/cs/cgv.html What We Have So Far 3D geometry 2D pipeline CS 148: Introduction to Computer Graphics and Imaging (Summer 2016)


slide-1
SLIDE 1

CS 148: Summer 2016 Introduction of Graphics and Imaging Zahid Hossain

Basics of 3D Rendering

http://www.pling.org.uk/cs/cgv.html

slide-2
SLIDE 2

What We Have So Far

3D geometry 2D pipeline

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 2

slide-3
SLIDE 3

Handy Fact

Matrices preserve flat geometry

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 3

slide-4
SLIDE 4

Handy Fact

Matrices preserve flat geometry

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4

slide-5
SLIDE 5

So What?

3D triangles look like 2D triangles under camera transformations.

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 5

slide-6
SLIDE 6

So What?

3D triangles look like 2D triangles under camera transformations. Use 2D pipeline for 3D Rendering !

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 6

slide-7
SLIDE 7

Side Note

http://drawntothis.com/wp-content/uploads/2010/09/Random_Guy.jpg

Only true for flat shapes

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 7

slide-8
SLIDE 8

Side Note

http://drawntothis.com/wp-content/uploads/2010/09/Random_Guy.jpg

Only true for flat shapes

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 8

slide-9
SLIDE 9

Frame Buffering

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 9

slide-10
SLIDE 10

Double and Triple Buffering

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 10

Tearing : Data from multiple frames appear on the screen at the same time. This happens when GPU rendering rate and monitor refresh rate are not synced.

http://www.newcluster.com/wp-content/uploads/2015/01/g-sync_diagram_0.jpgitokgxy9kpos

slide-11
SLIDE 11

Double Buffering with V-Sync

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 11

Back Buffer Front Buffer (video memory) Front Buffer SwapBuffer: Either copy Back Buffer to Front Buffer,

  • r Swap Pointers (Usually in Fullscreen mode).

Vertical Retraces

slide-12
SLIDE 12

Double Buffering with V-Sync

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 12

Back Buffer Front Buffer (video memory) Front Buffer SwapBuffer: Either copy Back Buffer to Front Buffer,

  • r Swap Pointers (Usually in Fullscreen mode).

Vertical Retraces

slide-13
SLIDE 13

Triple Buffering with V-Sync

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 13

Front Buffer Front Buffer (Video Memory) Back Buffer 2 Vertical Retraces Back Buffer 1

slide-14
SLIDE 14

Triple Buffering with V-Sync

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 14

Front Buffer Front Buffer (Video Memory) Back Buffer 2 Vertical Retraces Back Buffer 1

slide-15
SLIDE 15

Occulusion

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 15

slide-16
SLIDE 16

Painter’s Algorithm

Draw items one at a time

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 16

slide-17
SLIDE 17

Painter’s Algorithm

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 17

Draw items one at a time

slide-18
SLIDE 18

Painter’s Algorithm

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 18

Draw items one at a time

slide-19
SLIDE 19

Painter’s Algorithm

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 19

Draw items one at a time

slide-20
SLIDE 20

Painter’s Algorithm

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 20

Draw items one at a time

slide-21
SLIDE 21

What Order?

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 21

slide-22
SLIDE 22

What Order?

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 22

slide-23
SLIDE 23

Early Hidden Surface Approaches

  • Pre-compute rendering order
  • Cut geometry as needed

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 23

slide-24
SLIDE 24

Observation

Each pixel can decide what is on top independently.

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 24

slide-25
SLIDE 25

Observation

Each pixel can decide what is on top independently.

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 25

slide-26
SLIDE 26

Z Buffer

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 26

Color Buffer (RGB each cell) Depth buffer (one number each cell)

slide-27
SLIDE 27

Z-Buffer

http://upload.wikimedia.org/wikipedia/commons/4/4e/Z_buffer.svg

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 27

slide-28
SLIDE 28

Z-Buffer Issues: Resolution

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 28

Non linear !

slide-29
SLIDE 29

Z-Buffer Issues: Resolution

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 29

Depth

slide-30
SLIDE 30

Z-Buffer Issues: Depth Fighting

http://ps-2.kev009.com/CATIA-B18/basug_C2/basugbt1510.htm

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 30

  • aka. “Stiching” or “bleeding”
slide-31
SLIDE 31

Z-Buffer Issues: Depth Fighting

http://ps-2.kev009.com/CATIA-B18/basug_C2/basugbt1510.htm

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 31

  • aka. “Stiching” or “bleeding”

Hack: Scale and add offset “glPolygonOffset”

slide-32
SLIDE 32

Cull [kuhl]:

To identify and throw away invisible geometry to save processing time.

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 32

slide-33
SLIDE 33

Basic Culling Strategies

  • Backface culling: remove geometry facing

away from the camera

  • View volume culling: remove geometry
  • utside frustum
  • Occlusion culling: remove invisible geometry

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 33

slide-34
SLIDE 34

Backface Culling

http://medialab.di.unipi.it/web/IUM/Waterloo/node70.html

None Backface culling Hidden surface removal

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 34

slide-35
SLIDE 35

Specifying Triangle Orientation

glFrontFace(GL_CCW)

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 35

glDisable/glEnable(GL_CULL_FACE)

slide-36
SLIDE 36

View Volume Culling

http://i.minus.com/i75qjiyFQzVCI.jpg

Potential strategies:

  • Store scene hierarchically
  • With bounding volumes
  • Compute viewing frustrum
  • Don’t render volumes that are clearly outside frustrum

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 36

slide-37
SLIDE 37

Occlusion Culling: Portal Rendering

http://www.aaid.ca/flash/media/hkmh/images/floor1/000a-geology-portal-cg-rendering.jpg CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 37

slide-38
SLIDE 38

Occlusion Culling: Portal Rendering Potentially Visible Set

http://www.cs.virginia.edu/~luebke/publications/portals.html

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 38

slide-39
SLIDE 39

Occlusion Culling: Portal Rendering Potentially Visible Set

http://www.cs.virginia.edu/~luebke/publications/portals.html

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 39

slide-40
SLIDE 40

Occlusion Culling: Portal Rendering Potentially Visible Set (PVS)

http://www.cs.virginia.edu/~luebke/publications/portals.html

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 40

Mirrors ?

slide-41
SLIDE 41

Summary of Culling Techniques

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 41

slide-42
SLIDE 42

Acceleration Structures

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 42

slide-43
SLIDE 43

Goal of Acceleration Structures

  • Quickly reject objects that are outside the

viewing volume

  • Query for intersections efficiently

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 43

slide-44
SLIDE 44

Spatial Hierarchies

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 44

Letters correspond to planes (A)

slide-45
SLIDE 45

Spatial Hierarchies

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 45

Letters correspond to planes (A,B)

slide-46
SLIDE 46

Spatial Hierarchies

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 46

Letters correspond to planes (A,B,C,D)

slide-47
SLIDE 47

Spatial Hierarchies: Variations

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 47

slide-48
SLIDE 48

Octree

  • Each node has 0 or 8 children
  • Each node can equally subdivide its space (an AABB) into eight

subboxes by 3 midplanes

  • Children of a node are contained within the box of the node itself
  • Stop subdividing when number of objects/primitives falls below a

threshold or maximum depth has reached.

  • Recursively render cells that intersects with the viewing volume

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 48

slide-49
SLIDE 49

K-d Tree

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 49

  • Begin with the global bounding box containing all primitives.
  • Choose an axis and a splitting plane perpendicular to that axis
  • Subdivide the primitives on both sides of the plane into two groups
  • Usually done in a balanced manner
  • Stop when the number of primitives in each single group is below a

threshold

slide-50
SLIDE 50

Shadows

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 50

slide-51
SLIDE 51

Shadows

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 51

slide-52
SLIDE 52

Shadows: Spatial Cue

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 52

http://mamassian.free.fr/papers/mamassian_tics98.pdf

slide-53
SLIDE 53

Shadows: Realism

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 53

http://ivl.calit2.net/wiki/images/5/55/17_ShadowMappingS15.pdf

slide-54
SLIDE 54

Shadow

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 54

slide-55
SLIDE 55

Shadow

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 55

We will only concentrate on hard-shadows

slide-56
SLIDE 56

Shadow Mapping

  • First Pass
  • Render the Scene from the light Source
  • Pretend the light is the “camera”
  • Store the depth buffer as a texture
  • Heightfield – tells us the “distance” of the nearest points from

the light source.

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 56

Light’s POV depth map

slide-57
SLIDE 57

Shadow Mapping

  • Second Pass
  • Project the depth buffer texture from the light’s P.O.V
  • Render the scene from the camera position

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 57

Recall Projective Texturing

slide-58
SLIDE 58

Projective Texturing (RECALL)

  • Map NDC (-1 , 1 ) to Texture Coordinate space (0-1)
  • Scale and add Bias

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 58

Final texture coordinates after perspective-correct interpolation of

Compare this with depth

slide-59
SLIDE 59

Shadow Mapping

  • Second Pass
  • Project the depth buffer texture from the light’s P.O.V
  • Render the scene from the camera position
  • Compare fragment’s depth (projected r texture

coordinate) to the depth stored in texture

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 59

slide-60
SLIDE 60

Shadow Mapping: Issues

  • Limited field of view of depth map

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 60

slide-61
SLIDE 61

Shadow Mapping: Issues

  • Limited field of view of depth map
  • Z-Fighting
  • Add scale and bias – similar to glPolygonOffset
  • Getting it right is complicated

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 61

slide-62
SLIDE 62

Shadow Mapping: Issues

  • Limited field of view of depth map
  • Z-Fighting
  • Add scale and bias – similar to glPolygonOffset
  • Getting it right is complicated
  • Sampling problem (aliasing)
  • Larger depth map may mitigate some of it

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 62

slide-63
SLIDE 63

Shadow Mapping: Issues

  • Limited field of view of depth map
  • Z-Fighting
  • Add scale and bias – similar to glPolygonOffset
  • Getting it right is complicated
  • Sampling problem (aliasing)
  • Larger depth map may mitigate some of it

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 63

slide-64
SLIDE 64

Deferred Rendering

a.k.a Deferred Shading

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 64

slide-65
SLIDE 65

Deferred Rendering

  • So far: we did Forward Rendering
  • Lots of fragments are wasted due to overdraw
  • Complex Lighting/Shading computation wasted
  • Solution: “Defer” lighting computation until we

have figured out all the pixels that end up on the screen

  • Deferred Rendering can handle lots of lights
  • Complexity:
  • Forward Rendering: Num_Objects * Num_Light
  • Deferred Rendering: Num_Object + Num_Light

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 65 http://learnopengl.com/#!Advanced-Lighting/Deferred-Shading

slide-66
SLIDE 66

Deferred Rendering

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 66

Two Pass

  • 1. Geometry Pass
  • 2. Lighting Pass

http://learnopengl.com/#!Advanced-Lighting/Deferred-Shading

slide-67
SLIDE 67

Deferred Rendering

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 67

Two Pass

  • 1. Geometry Pass
  • 2. Lighting Pass

http://learnopengl.com/#!Advanced-Lighting/Deferred-Shading

slide-68
SLIDE 68

Deferred Rendering

  • Transparency still done through Forward Rendering
  • Need to copy the Depth Buffer.

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 68 http://learnopengl.com/#!Advanced-Lighting/Deferred-Shading

slide-69
SLIDE 69

Deferred Rendering: Lots of Light

  • Can handle lots of light: key is Light Volume
  • Shade pixels that are close to a light
  • Why does not “if-else” branch work for this on the GPU?

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 69 http://learnopengl.com/#!Advanced-Lighting/Deferred-Shading

slide-70
SLIDE 70

Deferred Rendering: Lots of Light

  • Can handle lots of light: key is Light Volume
  • Shade pixels that are close to a light
  • Why does not “if-else” branch work for this on the GPU?
  • Draw one light volume at a time: accumulate colors

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 70 http://learnopengl.com/#!Advanced-Lighting/Deferred-Shading

slide-71
SLIDE 71

Deferred Rendering: Lots of Light

  • Can handle lots of light: key is Light Volume
  • Shade pixels that are close to a light
  • Why does not “if-else” branch work for this on the GPU?
  • Draw one light volume at a time: accumulate colors

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 71 http://learnopengl.com/#!Advanced-Lighting/Deferred-Shading

1847 Lights!

slide-72
SLIDE 72

Deferred Rendering: Challenges

  • Doesn’t support MSAA (Multiple Sample Anti-

Aliasing)

  • Extra frame buffer memory
  • Transparencies need to be done with Forward

Rendering

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 72 http://learnopengl.com/#!Advanced-Lighting/Deferred-Shading

slide-73
SLIDE 73

Challenges of Rasterizers

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 73

slide-74
SLIDE 74

Shadows and Reflections

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 74

http://artist- 3d.com/free_3d_models/uploads/mantalray.jpg

slide-75
SLIDE 75

Transparencies

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 75

http://www.archicadwiki.com/Bugs/TransparencyIn3dWindow

slide-76
SLIDE 76

Depth of Field

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 76

http://www.seemsartless.com/guides/camera-dof-cars-fast-360.jpg

slide-77
SLIDE 77

CS 148: Summer 2016 Introduction of Graphics and Imaging Zahid Hossain

Basics of 3D Rendering

http://www.pling.org.uk/cs/cgv.html