19
7/2/2006 Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition) 1 CSC345: Advanced Graphics & Virtual Environments Lecture 4: Visual Appearance Patrick Olivier [email protected] 2 nd floor in the Devonshire Building

CSC345: Advanced Graphics & Virtual Environments

  • Upload
    odina

  • View
    18

  • Download
    0

Embed Size (px)

DESCRIPTION

CSC345: Advanced Graphics & Virtual Environments. Lecture 4: Visual Appearance Patrick Olivier [email protected] 2 nd floor in the Devonshire Building. Objectives. Refresher on simple lighting models Blending for translucent surfaces Compositing images Fog Gamma correction. - PowerPoint PPT Presentation

Citation preview

Page 1: CSC345: Advanced Graphics & Virtual Environments

7/2/2006 Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition) 1

CSC345: Advanced Graphics &

Virtual Environments

Lecture 4: Visual Appearance

Patrick [email protected]

2nd floor in the Devonshire Building

Page 2: CSC345: Advanced Graphics & Virtual Environments

6/2/2006 Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition) 2

Objectives Refresher on simple lighting models Blending for translucent surfaces Compositing images Fog Gamma correction

Page 3: CSC345: Advanced Graphics & Virtual Environments

6/2/2006 Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition) 3

Lighting model (1)

How compute lighting? We could set colors per vertex manually For a little more realism, compute lighting from:

Light sources Material properties Geometrical relationships

lightblue

red green

Rasterizer

Geometry

Page 4: CSC345: Advanced Graphics & Virtual Environments

6/2/2006 Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition) 4

Diffuse component: idiff

i = iamb + idiff + ispec

Diffuse is Lambert’s law

Photons cattered equally in all directions

cos lndiffi

diffdiffdiff smlni )(

Page 5: CSC345: Advanced Graphics & Virtual Environments

6/2/2006 Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition) 5

Specular component: ispec

Diffuse is dull (left) Specular: simulates a highlight Models:

Phong specular highlight model Blinn’s highlight formula (variation on Phong)

Page 6: CSC345: Advanced Graphics & Virtual Environments

6/2/2006 Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition) 6

Specular component: Phong

l)n2(nlr

n

lr

-lnln )(

lnshishi mm

speci )(cos)( vr

Page 7: CSC345: Advanced Graphics & Virtual Environments

6/2/2006 Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition) 7

Ambient component: iamb

Ad-hoc – tries to account for light coming from other surfaces

Just add a constant color: Sum all components: i = iamb + idiff + ispec

This is just a hack! It has almost nothing to do with reality!

ambambamb smi

++ =

Page 8: CSC345: Advanced Graphics & Virtual Environments

6/2/2006 Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition) 8

Additions to the lighting equation Depends on distance: 1/(a+bt+ct2) Can have more lights: just sum their

respective contributions Different light types:

directional point spot

Page 9: CSC345: Advanced Graphics & Virtual Environments

6/2/2006 Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition) 9

What’s lighting and what’s shading?

Lighting: interaction between light & matter Shading: determine pixel colors from vertex

lighting Three types of shading:

Flat (per polygon) Gouraud (per vertex) Phong (per pixel)

Page 10: CSC345: Advanced Graphics & Virtual Environments

6/2/2006 Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition) 10

Surfaces: Opaque: permit no light to pass through Transparent: permit all light to pass Translucent: pass some light

translucency = 1 – opacity() Translucency in physically correct manner

is difficult: complexity of interactions of light &

matter using a pipeline renderer

Opacity and Transparency

Page 11: CSC345: Advanced Graphics & Virtual Environments

6/2/2006 Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition) 11

Writing model Use “A” component RGBA (or RGB) to store opacity Can expand our model to use RGBA values

color buffer

destinationcomponent

blend

Destination blending factor

source blending factor sourcecomponent

Page 12: CSC345: Advanced Graphics & Virtual Environments

6/2/2006 Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition) 12

Blending Equation We can define source and destination

blending factors for each RGBA component: s = [sr, sg, sb, s]

d = [dr, dg, db, d] Suppose source & destination colours are: b = [br, bg, bb, b]

c = [cr, cg, cb, c] Blend as:c’ = [br sr+ cr dr, bg sg+ cg dg, bb sb+ cb db , b s+ c d ]

Page 13: CSC345: Advanced Graphics & Virtual Environments

6/2/2006 Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition) 13

OpenGL Blending and Compositing Must enable blending and pick source

and destination factors: glEnable(GL_BLEND) glBlendFunc(source_factor, destination_factor) Only certain factors supported:

GL_ZERO, GL_ONE GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA See Redbook for complete list…

Page 14: CSC345: Advanced Graphics & Virtual Environments

6/2/2006 Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition) 14

Example… Suppose that we start with the opaque

background colour (R0,G0,B0,1) This color becomes the initial destination color

We now want to blend in a translucent polygon with colour (R1,G1,B1,1)

Select GL_SRC_ALPHA and GL_ONE_MINUS_SRC_ALPHA as the source and destination blending factors

R’1 = 1 R1 +(1- 1) R0, ……

Note this formula is correct if polygon is either opaque or transparent

Page 15: CSC345: Advanced Graphics & Virtual Environments

6/2/2006 Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition) 15

Clamping All the components (RGBA) are clamped

and stay in the range (0,1) However, in a typical (old) system, RGBA

values are only stored to 8 bits Can easily loose accuracy if we add many

components together Example: add together n images

Divide all color components by n to avoid clamping Blend with source factor = 1, destination factor = 1 But division by n loses bits

Page 16: CSC345: Advanced Graphics & Virtual Environments

6/2/2006 Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition) 16

Order Dependency Is this image correct?

Probably not… Polygons are rendered

in the order they pass down the pipeline

Blending functions are order dependent

Page 17: CSC345: Advanced Graphics & Virtual Environments

6/2/2006 Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition) 17

Opaque and Translucent Polygons Suppose that we have a group of polygons

some of which are opaque and some translucent

How do we use hidden-surface removal? Opaque polygons block all polygons behind

them and affect the depth buffer Translucent polygons should not affect depth

buffer Render with glDepthMask(GL_FALSE) which makes

depth buffer read-only Sort polygons first to remove order

dependency

Page 18: CSC345: Advanced Graphics & Virtual Environments

6/2/2006 Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition) 18

Fog Simple atmospheric effect

A little better realism Help in determining distances

Color of fog: color of surface:

How to compute f ? 3 ways: linear, exponential, exponential-

squared Linear:

fc sc

]1,0[ )1( fff ssp ccc

startend

pend

zz

zzf

Page 19: CSC345: Advanced Graphics & Virtual Environments

6/2/2006 Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition) 19

Fog example Often just a matter

of: Choosing fog color Choosing fog model Turning it on

GLfloat fcolor[4] = {……}:

glEnable(GL_FOG);glFogf(GL_FOG_MODE, GL_EXP);glFogf(GL_FOG_DENSITY, 0.5);glFOgv(GL_FOG, fcolor);