Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL...

52
Rendering Overview

Transcript of Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL...

Page 1: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Rendering Overview

Page 2: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

RenderingRendering

• Algorithmically generating a 2D image from 3D models

• Raster graphics

Page 3: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

CSE OSU rendering coursesCSE OSU rendering courses

• CSE 5542 Real Time Rendering– Comprehensive list of topics in real‐time rendering p p gusing OpenGL and GLSL, including coordinate systems, transformations, viewing, illumination, y , , g, ,texture mapping, and shader‐based algorithms. 

• CSE 5545 Advanced Computer Graphics• CSE 5545 Advanced Computer Graphics– Advanced topics in computer graphics; image 

h i li h i d d i li dsynthesis, lighting and rendering, sampling and material properties, volume rendering. 

Page 4: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

TopicsTopics

• Lighting models and shadingLighting models and shading

• Viewing transformation

• Raytracing overview

Page 5: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Lighting and Shading

Page 6: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Physics of lighty g

Red lines – single bounce ; local illuminationGreen lines – multiple bounce ; global illumination

Page 7: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Vectors for light modelingVectors for light modeling

Page 8: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Point lightPoint light

Emit light in all directions Vector from point to light

Light Source

Object

Page 9: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Directional lightDirectional light

Light vector always the same

Light Source

Object

Page 10: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

SpotlightSpotlight

Page 11: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Area light (only in Unity Pro)g y y

Any point within an area is a point light source.

Page 12: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Shadows

H lf h dHalf shadow(Penumbra)

Shadow Not in shadow Shadow

Area light source can produce more realistic shadow effects. It is typically approximated by a number of point light sources So it is more computationally expensivelight sources. So it is more computationally expensive.

Page 13: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Shadows

Point Light Source Area Light Source(or multiple point light)

Page 14: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Light scattering on a surface

Figure from http://en.wikipedia.org/wiki/Bidirectional_scattering_distribution_function

Page 15: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Illumination modelIllumination model

Page 16: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Ambient illuminationAmbient illumination

• Approximation for global illumination• Often set as a constant value, resulting inOften set as a constant value, resulting in object having one, flat colorL I * K• Lambient = Iambient * Kambient

• [Light = Intensity * Material][ g y ]

Page 17: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Diffuse illuminationDiffuse illumination

iff fl i h h li h i• Diffuse reflection assumes that the light is equally reflected in every direction.

• In other words, if the light source and the object has fixed positions in the world space, j p p ,the camera motion doesn’t affect the appearance of the object.pp j

• The reflection only depends on the incoming direction It is independent of the outgoingdirection. It is independent of the outgoing (viewing) direction.

Page 18: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Diffuse illuminationDiffuse illumination

• Ldiffuse = Idiffuse * Kdiffuse* cosθi

Page 19: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Ambient and Diffuse illumination example

Page 20: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Specular illuminationSpecular illumination

i l h• Some materials, such as plastic and metal, can have shiny highlight spots.

• This is due to a glossy mirror‐like reflection.

• Materials have differentdifferent shininess/glossiness.

Page 21: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Specular reflectionSpecular reflection

( ) L• R = 2(L N)N‐ L L

• Lspecular=I * K * cosnφIspecular * Kspecular * cosnφ

• n is shininess coefficient• φ is the angle betweenφ is the angle between EYE and R

Page 22: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Specular illumination exampleSpecular illumination example

Page 23: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Normal of polygon(s)Normal of polygon(s)

Page 24: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Normal of vertexNormal of vertex

Average the normals of the polygons it is used inAverage the normals of the polygons it is used in

Page 25: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Shading model comparisonShading model comparison

Flat shading – one normal per polygon

Gouraud shading – one normal per vertex ; compute color of a point on the polygon by:computing color at each vertex and linearly interpolate colors inside the polygon

Phong shading – one normal per vertex ; compute color of a point on the polygon by:linearly interpolate the normal vector, then perform lighting calculation

Page 26: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Bump Map• A simple way to enrich surface details is to use bump mapmap.

• The basic idea is to modify the normal using a texture.

• Red and blue colors stand for normal change in two directions.

Page 27: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Viewing and ProjectionViewing and Projection Transformations

Page 28: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Graphics pipeline reminderp p p

Page 29: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

ProjectionProjection

• Transform a point from a high dimensionalspace to a low‐dimensional space.p p

• In 3D, the projection means mapping a 3D point onto a 2D projection plane (or calledpoint onto a 2D projection plane (or called image plane).

• There are two basic projection types:– Parallel (orthographic)Parallel (orthographic)– Perspective

Page 30: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Orthographic projectionOrthographic projection

Page 31: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Orthographic projectionOrthographic projection

Page 32: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Properties of orthographic projectionProperties of orthographic projection

• Not realistic looking• Can preserve parallel linesCan preserve parallel lines• Can preserve ratios• Does not preserve angles between lines• Mostly used in computer aided design andMostly used in computer aided design and architectural drawing software

Page 33: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Foreshortening – PietroPeruginofresco example

Page 34: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Orthographic projectionno foreshortening

Page 35: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Perspective projectionhas foreshortening

Page 36: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Perspective projectionviewing volume frustumviewing volume – frustum

Can you find near, far and field of view in Unity?

Field of View Angle

Page 37: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Properties of perspective projectionProperties of perspective projection 

• Realistic looking• Lines are mapped to linesLines are mapped to lines• Parallel lines may not remain parallel• Ratios are not preserved• Distances cannot be directly measured as inDistances cannot be directly measured, as in parallel projection

Page 38: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Raytracing

Page 39: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Ray TracingRay Tracing• Algorithm:Algorithm:

Shoot a ray through each pixelFind first object intersected by ray

Image plane

Eye

• Computation:• Computation:Compute ray (orthographic or perspective?)Compute ray object intersections (parametric line equation)Compute ray‐object intersections (parametric line equation)Compute shading (use light and normal vectors)

Page 40: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

ExampleExample

Page 41: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Shade of Object at PointShade of Object at Point

• Ambient

• Diffuse• Diffuse

• Specular

• Texture

• Shadows

• Reflections• Reflections

• Transparency (refraction)

Page 42: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

ShadowsShadows

• Determine when light ray is blocked from reaching object.• Ray‐object intersection calculation

For each pixelf h bjfor each objectfor each light sourcefor each object

Page 43: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

ReflectionReflection

Image plane

Eye

Page 44: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

TransparencyTransparency

Page 45: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Transparency & RefractionTransparency & Refraction

• Ray changes direction in transition between materials• Material properties give ratio of in/out angles

Page 46: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Transparency & RefractionTransparency & Refraction

Page 47: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Recursive Ray TracingRecursive Ray Tracing

Image plane

Eye

Page 48: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Sampling and AliasingSampling and Aliasing

Problem: Representing pixel by a single ray.

Page 49: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

EfficiencyEfficiency1280 1024 1 310 720 106 i l• 1280 x 1024 = 1,310,720  106 pixels.

• 106 initial rays.• 106 reflection rays.• Potentially 106 refraction rays.• 3 x 106 shadow rays (3 lights.)

Next level:• Potentially 4 x 106 refraction/reflection rays.

1,000,000 polygons.107 x 106 = 1013 ray‐polygon intersection calculations10 x 10 = 10 ray‐polygon intersection calculations.

Page 50: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Intersection Data StructuresIntersection Data Structures

if ld * ibl *Coarse test to see if a ray could *possibly* intersect object

OROR

Divide space up– sort objects into spatial bucketsj p– trace ray from bucket to bucket

Page 51: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Bounding BoxesBounding Boxes

Page 52: Rendering Overviewweb.cse.ohio-state.edu/~wang.3602/courses/cse3541-2017-fall/10... · using OpenGL and GLSL, including coordinate syy ... – Advanced topics in computer graphics;

Spatial SubdivisionSpatial Subdivision