lighting & shading - eth zlighting & shading 12 real-world vs. opengl •r wdlaleor –...

40
Lighting & Shading

Upload: others

Post on 20-Jul-2020

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

Lighting & Shading

Page 2: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

2

Light Transport

• Goal: Model the interaction of light with matter in a way that appears realistic (and is fast)

Page 3: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

3

Light Transport

• Assumptions:– Geometrical optics:

• No diffraction, no polarization, no interference– Light travels in a straight line in a vacuum

• No atmospheric scattering or refraction• No gravity effects

– Discrete-wavelength approximation of color• Quantized approximation of dispersion and fluorescence

– Superposition• No non-linear reflecting materials

Page 4: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

4

Bidirectional Reflectance

• Radiance L [W/(sr m2)]

– radiant flux / (unit solid angle * unit area)

Page 5: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

5

Bidirectional Reflectance

• Single incoming direction and single outgoing direction

rφiφ

iθrθ

iiiirirrir LfL ωθωωωωω dcos)(),(),( =

rωiω

bidirectional reflectance distribution function

Page 6: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

6

Bidirectional Reflectance

• Integral over all incoming directions

rφiφ

iθrθ

∫Ω

=i

iiiirirrr LfL ωθωωωω dcos)(),()(

rωiω

incident hemisphere

Page 7: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

7

Bidirectional Reflectance

• Bidirectional Reflectance Distribution Function (BRDF)– anisotropic (4 DOFs)– isotropic (3DOFs)

),,,( rriirf θφθφ

),,( ririrf θθφφ −

Page 8: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

8

Bidirectional Reflectance

• Generalizations – anisotropic BRDF: 4 DOFs– spatially varying: +2– spectrally varying: +1– Fluorescence: +1– Phosphorescence: +1– Subsurface Scattering: +2

→ General BRDF is 11 dimensional function!!

Page 9: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

9

Subsurface Scattering

© Henrik Wann Jensen

Page 10: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

10

Global Illumination

© Henrik Wann Jensen

Page 11: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

11

Complex Materials and Lighting

© Henrik Wann Jensen

Page 12: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

12

Real-World vs. OpenGL

• Real world– complex computations– see optics textbooks, photorealistic rendering

• OpenGL– simplified model– ambient, diffuse and specular

light sources and reflections– easy to tune– fast to compute

Page 13: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

13

Lighting

• Light sources

• Light reflection

Page 14: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

14

Ambient Light

• Scattered by environment• Coming from all directions• Reflection independent of

– Camera position– Light position (no light position)– Surface orientation

• Reflected intensity:light

sourcematerial

parameter

I = Ia ka

Page 15: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

15

Diffuse Reflection

• Directed light Ip

• Reflection dependent on – orientation of surface– light source position

• Independent of– camera position

(reflected equally in all directions)• Reflected intensity: I = Ip kd cosθ

L

N

θ

I = Ip kd (N ⋅L)

Page 16: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

16

Two Radiant Surface Patches

• Illumination B [lux]

2dAdFB =

Page 17: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

17

Diffuse Reflection

• Diffuse reflection scales with angle

Surface 1 Surface 2

dA dA / cosθ

N

θ

90-θ

N

illumination

B =dF

dA/ cosθ= cosθ dF

dA

Page 18: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

18

A Simple Model

• Sum up ambient light and diffuse reflection:

I = Ia ka + Ip kd (N ⋅L)

Page 19: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

19

Attenuation

• Quadratic attenuation due to spatial radiation

2

1

Latt d

f =

),dcdcc

(fLL

att 11min 2321 ++

=

glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, c1);glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, c2);glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, c3);

)(kIfkII dpattaa LN ⋅+=

• A model often used in Graphics (OpenGL)

• Include attenuation

Page 20: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

20

• Colored light and reflection as functions of wavelength λ

Wavelength Dependency

Iλ = Ia λka Odλ

+ fatt Ipλkd Odλ

(N ⋅L)

Restriction of spectral sampling to RGB canlead to substantial color artifacts

)(kIfkII

)(kIfkII

)(kIfkII

BBRB

GGRG

RRRR

dpattaaB

dpattaaG

dpattaaR

LN

LN

LN

⋅+=

⋅+=

⋅+=

• Restriction to RGB (OpenGL)

Page 21: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

21

Depth Cueing (Fog)

• Linear depth cue by blending with the color of the participating medium

Iλ = sIλ + (1− s) Idcλ

fb

bf

bfbb

zzz

zz)s(s)z(z

ss

≤≤

−−+=

for

1sf

Scalefactor

sb

zb Depth zf 1z

• s is scaling factor

Page 22: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

22

Specular Reflection

• Depends on angle between reflection and viewing ray

L

N

θ θ α

R

V

Page 23: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

23

Reflected Ray

• Computed using simple vector algebra

R =Ncosθ + SR = 2Ncosθ −L = 2N(N ⋅L) −Lcosα =R ⋅ V = (2N(N ⋅L) −L) ⋅ V

L

N

θ θ

R

Ncosθ

SS

Page 24: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

24

Phong Illumination Model

• Approximates specular reflection by cosine powers

Iλ = Ia?ka Odλ

+ fatt Ipλ[kd Odλ

(N ⋅L)+ ks(R ⋅ V)n ]

Page 25: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

25

Ambient + Diffuse + Specular

Ambient Diffuse Specular

Page 26: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

26

Extensions

• Specular colors

• Halfway-Vector (faster)

• Multiple Light Sources

L

N

θ θ α

R

V

H

β

Iλ = Iaλka Odλ

+ fatt Ipλ[kd Odλ

(N ⋅L)+ ks Osλ(R ⋅ V)n]

cosn β = (N ⋅H)n

VLVLH

++

=

Iλ = Iaλka Odλ

+ fattiIpλi

[kd Odλ(N ⋅Li) + ks Osλ

(Ri ⋅ V)n]1≤ i≤m∑

Page 27: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

27

Highlights

• ks/kd determines highlighted surface regions

Page 28: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

28

OpenGLGLfloat light_pos[] = x,y,z, 1;GLfloat light_Ia[] = IaR, IaG, IaB, IaA;GLfloat light_Id[] = IdR, IdG, IdB, IdA;GLfloat light_Is[] = IsR, IsG, IsB, IsA;glLightfv(GL_LIGHT0, GL_POSITION, light_pos);glLightfv(GL_LIGHT0, GL_AMBIENT, light_Ia);glLightfv(GL_LIGHT0, GL_DIFFUSE, light_Id);glLightfv(GL_LIGHT0, GL_SPECULAR, light_Is);

GLfloat material_Ka[] = kaR, kaG, kaB, kaA;GLfloat material_Kd[] = kdR, kdG, kdB, kdA;GLfloat material_Ks[] = ksR, ksG, ksB, ksA;glMaterialfv(GL_FRONT, GL_AMBIENT, material_Ka);glMaterialfv(GL_FRONT, GL_DIFFUSE, material_Kd);glMaterialfv(GL_FRONT, GL_SPECULAR, material_Ks);glMaterialfv(GL_FRONT, GL_SHININESS, Se);

• Light source:

• Reflection(material):

Page 29: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

29

Light Position• Position in world-coordinates• Light stationary

gluLookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ,upX, upY, upZ);

glLightfv(GL_LIGHT0, GL_POSITION, pos);

• Position in camera-coordinates• Light moving with camera (headlight)

glLightfv(GL_LIGHT0, GL_POSITION, pos);gluLookAt(eyeX, eyeY, eyeZ,

centerX, centerY, centerZ,upX, upY, upZ);

Page 30: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

30

Light Sources

• Directed Spotlights

IL'λcosp λ

IL'λ( − L ⋅ L')p

glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, L’);glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, p);

L

NL’

γ

Spot position

Spot direction

Page 31: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

31

Intensity Diagrams

• Implemented in most modern graphics APIs

Page 32: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

32

Shading

• Shading requires many evaluations of alighting model

• Questions: – where to evaluate ?– when to evaluate ?

Page 33: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

33

Shading Models

• Flat shading (constant shading)– one color per primitive

• Gouraud shading– linear interpolation of vertex intensities

• Phong shading– linear interpolation of vertex normals

• Gouraud & Phong shading need vertex normals

Page 34: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

34

Gouraud Shading – Procedure

1. Calculate face normals2. Calculate vertex normals

3. Evaluate lighting model for each vertex4. Interpolate vertex intensities across

primitive (bilinear interpolation)

N1

Nv

N4

N3

N2

Nv =Ni

i=1

n

Nii=1

n

Page 35: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

35

Gouraud Shading –Interpolation

• Linear interpolation on current scan line

• Done during scan conversion• Hardware acceleration possible

Scan line

I1

Ia

I3

I2

IbIp

y1

ys

y2

y3

y

x

Ia = I1-(I1-I2)(y1-ys)(y1-y2)

Ib = I1-(I1-I3)(y1-ys)(y1-y3)

Ip = Ib-(Ib-Ia)(xb-xp)(xb-xa)

Page 36: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

36

Gouraud Shading – Quality

• Shading quality depends on size of projected primitives (relative to pixel size)

Page 37: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

37

Phong Shading

• Linear interpolation of normals (not intensities) on current scan line

• Evaluation of lighting model at each pixel• More accurate but slower than Gouraud

P0 Pa Pb Pc P1

N0 Na Nb Nc N1

Page 38: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

38

Shading Methods – Overview

• Shading in image space:– Flat shading (Constant shading)– Gouraud shading

• Shading in object / screen space:– Phong shading

• Impact on graphics hardware...

Page 39: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

39

Transparency

• Transparency done with α-blending…• Linearizing exponential attenuation of

intensity in media

P1 P2

Iλ2

Iλ1

∆tthickness

view

α1 α2 = 1 (opaque)

α: absorption

Page 40: Lighting & Shading - ETH ZLighting & Shading 12 Real-World vs. OpenGL •R wdlaleor – complex computations – see optics textbooks, photorealistic rendering •OpenGL – simplified

5. Lighting & Shading

40

Transparency – Basic Laws

• P1 filters intensity according to

• Linearization yields

• Emission of P1

• Summing up (for unit length)

• For N polygons (α-blending )

I'λ2= Iλ2

e−α1∆t

I'λ2= Iλ2

(1−α1∆t)

I'λ1= Iλ1

α1∆t

Iλ = I'λ1+ I'λ2

= Iλ1α1 + Iλ2

(1−α1)

Iλ = α i Iλi⋅ (1−αb)

b=1

i−1

∏i=1

N