shading (introduction to rendering)

52
Graphics I Faramarz Samavati UNIVERSITY OF CALGARY Shading (introduction to rendering)

Upload: elisa

Post on 22-Feb-2016

41 views

Category:

Documents


1 download

DESCRIPTION

Shading (introduction to rendering). Rendering. We know how to specify the geometry but how is the color calculated. Rendering. We know how to specify the geometry but how is the color calculated. Rendering. We know how to specify the geometry but how is the color calculated. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Shading (introduction to rendering)

Shading(introduction to rendering)

Page 2: Shading (introduction to rendering)

Rendering We know how to specify the geometry but how

is the color calculated

Page 3: Shading (introduction to rendering)

Rendering We know how to specify the geometry but how

is the color calculated

Page 4: Shading (introduction to rendering)

Rendering We know how to specify the geometry but how

is the color calculated

Page 5: Shading (introduction to rendering)

Rendering: simulation of light transport

What makes up the final color of an object?

Page 6: Shading (introduction to rendering)

Rendering: simulation of light transport

Diffuse scattering o matt surfaces

Specular reflectiono shiny surfaceso highlight

Transparencyo glass, watero penetrate the surface

Page 7: Shading (introduction to rendering)

Rendering: simulation of light transport

How do we represent these observations in a mathematical framework

Page 8: Shading (introduction to rendering)

Rendering: simulation of light transport

Real time rendering is generally not concerned with using a "correct" lighting equation, just a series of hacks to make things look right with as little computational effort as possible

Page 9: Shading (introduction to rendering)

Illumination Models

Localo Direct illumination of surfaces by light sources

Global o all light/surface interactions for entire environment

Page 10: Shading (introduction to rendering)

Globalillumination

Page 11: Shading (introduction to rendering)

Globalillumination

Page 12: Shading (introduction to rendering)

Local illumination

Input:o a 3D objecto Material and color of the objecto Position and structure of the light sourceo “Intensity” of the light source

Output:o Color and intensity of points of the given object

A (modest) example of shading

Page 13: Shading (introduction to rendering)

Representing 3D Objects Collection of triangles or mesh

Page 14: Shading (introduction to rendering)

Dealing with color Three component intensity (red, green, blue) Luminance (intensity) of the source

o Red component of source red component of imageo Green component of source green component of

imageo Blue component of source blue component of image

Three similar but independent calculations We focus on one scalar value only

Page 15: Shading (introduction to rendering)

Diffuse reflection A perfect diffuse reflector (Lambertian

surface) scatters the light equally in all directions

Same appearance to all viewers

Depends ono Material of the surfaceo The position of the light

Page 16: Shading (introduction to rendering)

Normalso What direction is the surface facing?

Page 17: Shading (introduction to rendering)

CrossProduct

o n.x = a.y * b.z - a.z * b.yo n.y = a.z * b.x - a.x * b.zo n.z = a.x * b.y - a.y * b.x

Page 18: Shading (introduction to rendering)

Normalso A = V2 – V1o B = V0 – V1o N = A x B

Page 19: Shading (introduction to rendering)

Normalso For each triangle we can define a normal for the face

o For each vertex we an define a normal by interpolating normals of attached faces

Page 20: Shading (introduction to rendering)

Diffuse: Two important vectors To compute the intensity at P, we need

o The unit normal vector N,o The unit vector L, from P to the light

LN

P

θ

Page 21: Shading (introduction to rendering)

Diffuse: Two important vectors To compute the intensity at P, we need

o The unit normal vector N,o The unit vector L, from P to the light

LN

P

θ

What is the diffuse color at P?

Page 22: Shading (introduction to rendering)

Lambert’s cosine law

I : diffuse reflection at P

Id: intensity of the light from source coefficient of diffuse reflection

I = Id kd cos(r L ,

r N ) = Id kd

r L •

r N

10 dk

Page 23: Shading (introduction to rendering)

Coefficient of diffuse reflection kd is usually determined by a trial and error

approach Examples:Component Gold Black plastic SilverRed 0.75 0.01 0.5Green 0.6 0.01 0.5Blue 0.22 0.01 0.5

kd=0.05 kd=0.25 kd=0.5 kd=0.75 kd=1

Page 24: Shading (introduction to rendering)

Specular reflection

Diffusive reflection: no highlights, rough surface Specular reflection: highlights, shiny and smooth

surfaces View dependent reflection

Page 25: Shading (introduction to rendering)

Three important vectors To compute the intensity at P, we need

o The unit normal vector N,o The unit vector L, from P to the lighto The unit vector V, from P to the viewer

LN

VP

Page 26: Shading (introduction to rendering)

Three important vectors To compute the intensity at P, we need

o The unit normal vector N,o The unit vector L, from P to the lighto The unit vector V, from P to the viewer

LN

VP

What is the specular illumination at P?

Page 27: Shading (introduction to rendering)

The shininess coefficient

1n 2n 4n 6n

cos

0 90o-90o

increasing n

Page 28: Shading (introduction to rendering)

I : specular reflection at P

Id: intensity of the light from source coefficient of specular reflection n: controls shininess

The Phong model for specular reflection

P

NL R

P

NL R

V

I = Id ks cosn φ = Id ks(r R •

r V )n

10 sk

Page 29: Shading (introduction to rendering)

Ambient light

“Physical rules” are too simplified No indirect or global interaction of light

A hack to overcome the problem: use “ambient light”

Page 30: Shading (introduction to rendering)

Ambient light specification Not situated at any particular point Spreads uniformly in all directions Ia : intensity of ambient light in the environment I : ambient light at a given point : coefficient of ambient light reflection

ka=0 ka=0.5 ka=1

10 ak

aa IkI

Page 31: Shading (introduction to rendering)

A combined model(The Phong local illumination model)

The final model = diffuse + specular + ambient

Page 32: Shading (introduction to rendering)

How does it work in OpenGL

Page 33: Shading (introduction to rendering)

Flat Shading Individual faces are visualized Same color for any point in the face

Page 34: Shading (introduction to rendering)

Smooth Shading Visualize the underlying surface Each point on the face has its own color Two techniques Gouraud and Phong shading

Page 35: Shading (introduction to rendering)

ShadingGouraud Phong FlatNormal Per Vertex

Interpolated normal for each point across face

Normal per face

Color per vertex, interpolated across face

Color calculated per pixel

Color calculated per face

Faster then phongBad specular

Costly (not really any more)

Fast, good for distant objects

N

Page 36: Shading (introduction to rendering)

Clarification

Phong reflection model or phong lighting refers to

Phong Shading refers to filling a triangle by interpolating the normal and calculating the color at each point

Page 37: Shading (introduction to rendering)

Gouraud Shading Specular highlight quality tied to detail of mesh Specular highlights can even be missed

Page 38: Shading (introduction to rendering)

Incorporating a distance term

a,b,c are control parameters

I =1

a + bd + cd2 Id kd (r L •

r N ) + Id ks(

r R •

r V )n[ ] + Iaka

Empirical formula:

Page 39: Shading (introduction to rendering)
Page 40: Shading (introduction to rendering)
Page 41: Shading (introduction to rendering)
Page 42: Shading (introduction to rendering)

Multiple light sources The total reflection at p is the sum of all contributed intensities from all sources OpenGL allows us to define several light sources

Page 43: Shading (introduction to rendering)

OpenGL 2.0 (programmable) pipeline

Page 44: Shading (introduction to rendering)

More advanced rendering

Page 45: Shading (introduction to rendering)

More advanced rendering

Page 46: Shading (introduction to rendering)
Page 47: Shading (introduction to rendering)

More advanced rendering

Page 48: Shading (introduction to rendering)

More advanced rendering

Page 49: Shading (introduction to rendering)

More advanced rendering

Page 50: Shading (introduction to rendering)

More advanced rendering

Page 51: Shading (introduction to rendering)

Questions?

Page 52: Shading (introduction to rendering)

Questions?