Presentation is loading. Please wait.

Presentation is loading. Please wait.

7/2/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 4: Visual Appearance.

Similar presentations


Presentation on theme: "7/2/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 4: Visual Appearance."— Presentation transcript:

1 7/2/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 4: Visual Appearance Patrick Olivier p.l.olivier@ncl.ac.uk 2 nd floor in the Devonshire Building

2 6/2/2006Based 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

3 6/2/2006Based 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 light blue red green Rasterizer Geometry

4 6/2/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)4 Diffuse component: i diff  i = i amb + i diff + i spec  Diffuse is Lambert’s law  Photons cattered equally in all directions

5 6/2/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)5 Specular component: i spec  Diffuse is dull (left)  Specular: simulates a highlight  Models: Phong specular highlight model Blinn’s highlight formula (variation on Phong)

6 6/2/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)6 Specular component: Phong n l r -l-l

7 6/2/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)7 Ambient component: i amb  Ad-hoc – tries to account for light coming from other surfaces  Just add a constant color:  Sum all components: i = i amb + i diff + i spec  This is just a hack!  It has almost nothing to do with reality! ++=

8 6/2/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)8 Additions to the lighting equation  Depends on distance: 1/(a+bt+ct 2 )  Can have more lights: just sum their respective contributions  Different light types: directional point spot

9 6/2/2006Based 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)

10 6/2/2006Based 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

11 6/2/2006Based 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 destination component blend Destination blending factor source blending factor source component

12 6/2/2006Based 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 = [s r, s g, s b, s  ] d = [d r, d g, d b, d  ]  Suppose source & destination colours are: b = [b r, b g, b b, b  ] c = [c r, c g, c b, c  ]  Blend as: c’ = [b r s r + c r d r, b g s g + c g d g, b b s b + c b d b, b  s  + c  d  ]

13 6/2/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)13 OpenGL Blending and Compositing  Must enable blending and pick source and destination factors: g lEnable(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…

14 6/2/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)14 Example…  Suppose that we start with the opaque background colour (R 0,G 0,B 0,1) This color becomes the initial destination color  We now want to blend in a translucent polygon with colour (R 1,G 1,B 1,  1 )  Select GL_SRC_ALPHA and GL_ONE_MINUS_SRC_ALPHA as the source and destination blending factors R ’ 1 =  1 R 1 +(1-  1 ) R 0, ……  Note this formula is correct if polygon is either opaque or transparent

15 6/2/2006Based 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

16 6/2/2006Based 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

17 6/2/2006Based 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

18 6/2/2006Based 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:

19 6/2/2006Based 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);


Download ppt "7/2/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 4: Visual Appearance."

Similar presentations


Ads by Google