basics of 3d rendering - github pages · cs 148: introduction to computer graphics and imaging...

77
CS 148: Summer 2016 Introduction of Graphics and Imaging Zahid Hossain Basics of 3D Rendering http://www.pling.org.uk/cs/cgv.html

Upload: others

Post on 28-Jun-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

CS 148: Summer 2016

Introduction of Graphics and Imaging

Zahid Hossain

Basics of 3D Rendering

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

Page 2: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

What We Have So Far

3D geometry 2D pipeline

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

Page 3: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

Handy Fact

Matrices preserve flat geometry

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

Page 4: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

Handy Fact

Matrices preserve flat geometry

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

Page 5: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

So What?

3D triangles look like 2D trianglesunder camera transformations.

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

Page 6: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

So What?

3D triangles look like 2D trianglesunder camera transformations.

Use 2D pipeline for 3D Rendering !

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

Page 7: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

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

Page 8: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

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

Page 9: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

Frame Buffering

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

Page 10: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

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

Page 11: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

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, or Swap Pointers (Usually in Fullscreen mode).

Vertical Retraces

Page 12: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

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, or Swap Pointers (Usually in Fullscreen mode).

Vertical Retraces

Page 13: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

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

Page 14: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

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

Page 15: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

Occulusion

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

Page 16: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

Painter’s Algorithm

Draw items one at a timeCS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 16

Page 17: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

Painter’s Algorithm

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

Draw items one at a time

Page 18: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

Painter’s Algorithm

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

Draw items one at a time

Page 19: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

Painter’s Algorithm

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

Draw items one at a time

Page 20: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

Painter’s Algorithm

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

Draw items one at a time

Page 21: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

What Order?

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

Page 22: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

What Order?

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

Page 23: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

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

Page 24: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

Observation

Each pixel can decide what is on top independently.

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

Page 25: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

Observation

Each pixel can decide what is on top independently.

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

Page 26: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

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)

Page 27: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

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

Page 28: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

Z-Buffer Issues: Resolution

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

Non linear !

Page 29: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

Z-Buffer Issues: Resolution

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

Depth

Page 30: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

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”

Page 31: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

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”

Page 32: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

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

Page 33: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

Basic Culling Strategies

• Backface culling: remove geometry facing away from the camera

• View volume culling: remove geometry outside frustum

• Occlusion culling: remove invisible geometry

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

Page 34: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

Backface Culling

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

None Backfaceculling

Hidden surfaceremoval

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

Page 35: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

Specifying Triangle Orientation

glFrontFace(GL_CCW)

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

glDisable/glEnable(GL_CULL_FACE)

Page 36: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

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

Page 37: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

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

Page 38: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

Occlusion Culling: Portal Rendering

Potentially Visible Sethttp://www.cs.virginia.edu/~luebke/publications/portals.html

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

Page 39: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

Occlusion Culling: Portal Rendering

Potentially Visible Sethttp://www.cs.virginia.edu/~luebke/publications/portals.html

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

Page 40: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

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 ?

Page 41: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

Summary of Culling Techniques

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

Page 42: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

Acceleration Structures

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

Page 43: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

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

Page 44: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

Spatial Hierarchies

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

Letters correspond to planes (A)

Page 45: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

Spatial Hierarchies

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

Letters correspond to planes (A,B)

Page 46: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

Spatial Hierarchies

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

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

Page 47: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

Spatial Hierarchies: Variations

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

Page 48: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

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

Page 49: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

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

Page 50: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

Shadows

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

Page 51: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

Shadows

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

Page 52: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

Shadows: Spatial Cue

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

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

Page 53: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

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

Page 54: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

Shadow

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

Page 55: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

Shadow

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

We will only concentrate on hard-shadows

Page 56: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

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

Page 57: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

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

Page 58: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

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

Page 59: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

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

Page 60: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

Shadow Mapping: Issues

• Limited field of view of depth map

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

Page 61: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

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

Page 62: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

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

Page 63: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

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

Page 64: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

Deferred Renderinga.k.a Deferred Shading

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

Page 65: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

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

Page 66: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

Deferred Rendering

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

Two Pass1. Geometry Pass2. Lighting Pass

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

Page 67: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

Deferred Rendering

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

Two Pass1. Geometry Pass2. Lighting Pass

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

Page 68: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

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

Page 69: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

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

Page 70: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

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

Page 71: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

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!

Page 72: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

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

Page 73: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

Challenges of Rasterizers

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

Page 74: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

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

Page 75: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

Transparencies

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

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

Page 76: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

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

Page 77: Basics of 3D Rendering - GitHub Pages · CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) –Zahid Hossain 49 • Begin with the global bounding box containing

CS 148: Summer 2016

Introduction of Graphics and Imaging

Zahid Hossain

Basics of 3D Rendering

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