1 / 19

CSC345: Advanced Graphics & Virtual Environments

CSC345: Advanced Graphics & Virtual Environments. Lecture 4: Visual Appearance Patrick Olivier p.l.olivier@ncl.ac.uk 2 nd floor in the Devonshire Building. Objectives. Refresher on simple lighting models Blending for translucent surfaces Compositing images Fog Gamma correction.

odina
Télécharger la présentation

CSC345: Advanced Graphics & Virtual Environments

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSC345: Advanced Graphics &Virtual Environments Lecture 4: Visual Appearance Patrick Olivier p.l.olivier@ncl.ac.uk 2nd floor in the Devonshire Building 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 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 Rasterizer light blue Geometry red green 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 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) Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)

  6. n r l -l Specular component: Phong 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! 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 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) Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)

  10. Opacity and Transparency • Surfaces: • Opaque: permit no light to pass through • Transparent: permit all light to pass • Translucent: pass some light translucency = 1 – opacity(a) • Translucency in physically correct manner is difficult: • complexity of interactions of light & matter • using a pipeline renderer Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)

  11. Writing model • Use “A” component RGBA (or RGBa) to store opacity • Can expand our model to use RGBA values blend source component source blending factor destination component color buffer Destination blending factor 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, sa] d = [dr, dg, db, da] • Suppose source & destination colours are: b = [br, bg, bb, ba] c = [cr, cg, cb, ca] • Blend as: c’ = [br sr+ cr dr, bg sg+ cg dg, bb sb+ cb db , basa+ cada] 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… 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,a1) • Select GL_SRC_ALPHA and GL_ONE_MINUS_SRC_ALPHA as the source and destination blending factors R’1 = a1 R1 +(1- a1) R0, …… • Note this formula is correct if polygon is either opaque or transparent 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 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 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 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: Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)

  19. Fog example GLfloat fcolor[4] = {……}: glEnable(GL_FOG); glFogf(GL_FOG_MODE, GL_EXP); glFogf(GL_FOG_DENSITY, 0.5); glFOgv(GL_FOG, fcolor); • Often just a matter of: • Choosing fog color • Choosing fog model • Turning it on Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)

More Related