1 / 39

Lighting

Lighting. SET09115 Intro Graphics Programming. Breakdown. Working with Colour Basics of Lighting Why Lighting? Ambient Light Surface Lighting Diffuse Light Specular Light Other Lighting Types. Recommended Reading. Real Time Rendering Chapter 5 – Visual Appearance Course Text

manton
Download Presentation

Lighting

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. Lighting SET09115 Intro Graphics Programming

  2. Breakdown • Working with Colour • Basics of Lighting • Why Lighting? • Ambient Light • Surface Lighting • Diffuse Light • Specular Light • Other Lighting Types

  3. Recommended Reading • Real Time Rendering • Chapter 5 – Visual Appearance • Course Text • Chapter 6 – Lighting and Shading

  4. Colours

  5. Colour Representation • Modern graphics work with 32 bit colour • Typically 4 values of 8 bits used • Red, green, blue, alpha (transparency) • Other formats exist • We could work with values 0..255 • Better to work with floats 0.0f ..1.0f • 0% to 100%

  6. Working with Colour • Treat colour as a value you can work with • Add colours together • Red + Green = Yellow • (1.0, 0.0, 0.0) + (0.0, 1.0, 0.0) = (1.0, 1.0, 0.0) • Multiply colours together • Magenta * Yellow = Red • (1.0, 0.0, 1.0) * (1.0, 1.0, 0.0) = (1.0, 0.0, 0.0)

  7. Vertex Colours • Attaching colours to vertices is what we have been doing up until this point • Blending occurs over surfaces between colour points • OpenGL follows the RGBA format • Image formats may not be in RGBA • DirectX can support other formats • These colours can be used in lighting calculations • Typically, we use textured objects to provide more detail

  8. Blending • The ability to blend colours in this way is useful • Multi-texturing • Terrain • We will revisit blending colours when working with textures and terrain

  9. Questions? Working with colour

  10. Basics of Lighting

  11. Why Lighting? • Lighting adds depth to a scene • Unlit objects are flat and lack detail • Lighting adds realism to objects • Specular detail • Light reflection

  12. How Lighting Works • Light works in rays from a graphics point of view • Light comes from a source • Light is reflected off of objects • Light eventually makes it into the eye

  13. Materials • Light rays are just one part of the equation • Light itself can have a colour • Objects also have a colour • The type of light they reflect into the eye rather than absorb • The light that an object reflects is commonly described in its material • Material may have other properties

  14. Main Lighting Types • Generally, an object has three lighting effects affecting it at any time • Ambient • Diffuse • Specular • The colour of an object are these three lighting effects combined • Plus any other effectx

  15. What is Ambient Light? • Ambient light is the light that affects everything equally in a scene • Has no direction • Has no distance • Doesn’t care about which part of the object is being calculated • Outside, daylight is an ambient light effect

  16. Ambient Light Equation • Ambient light calculation is the simplest • The ambient light of a particular vertex is just the ambient material colour of the object multiplied by the ambient light colour of the scene

  17. Example

  18. Questions? Why lighting? Materials Ambient light

  19. Lighting Surfaces

  20. Lighting a Surface • Ambient light is something affecting all geometry equally • Still gives a flat appearance to a scene • Objects reflect light based on how their surfaces are aligned with the light source • Occluded objects / surfaces get no light • Surfaces perpendicular to light source get full light

  21. Working with Normals • We use surface normals to determine how light should be reflected off a surface • Andrew will go into the mathematics of lighting next week • Normals are very important for lighting

  22. What is Diffuse Light? • Diffuse light is concerned with directionality of the light • Geometry facing a light source is lit • Geometry facing away from the light source unlit • Think sunlight outside

  23. How does Diffuse Light Work? • Diffuse light is concerned with the light direction against the surface normal of the piece of geometry in question • If angle = 90 then full light • If angle 0 to 90, or 90 to 180, then shaded • If angle < 0 or > 180 then not lit • Think about how this would work if you shone a light on a table

  24. Lambert’s Cosine Law • A simple way to calculate the diffuse light of an object is using Lambert’s Cosine Law • Cos(0) = 0 • Cos(90) = 1 • Cos(180) = 0 • The cosine graph shows how this works

  25. Diffuse Light Algorithm • Using Lambert’s Cosine Law, we can generate the diffuse lighting algorithm • Remember, dot product of two vectors is equal to the cosine of the angle between them • We would normally have to transform the surface normal if the model is transformed • Diffuse alpha should always be 1. We will have to set this

  26. Example

  27. What is Specular Light? • Specular light refers to the point on the object where the light strikes • Specular reflection • This provides a shiny look to objects • Also indicates where the light is coming from

  28. How does Specular Light Work? • Specular light requires three pieces of information • Light direction • Surface normal • Eye position • Specular intensity is based on eye position

  29. Specular Light Algorithm • Specular light is the most complicated algorithm

  30. Example

  31. Questions? Surface lighting Diffuse lighting Specular lighting

  32. Other Lighting Types

  33. Other Lighting Types • Ambient, Diffuse, and Specular are considered the main environmental lighting types • Object materials usually deal with these three types • There are of course other lighting types which affect a scene • Dynamic lighting • Point lights • Spot lights

  34. Point Lights • A point light is a light that emanates from a particular point in the scene • Use the same equations, but calculate light vector based on vertex position and light position • Distance to light affects the strength of the light

  35. Spot Lights • Spot lights also work using light position and distance • The direction of the light is also important • Objects behind the spot light aren’t lit • Light also has an angle associated with it • Beam width at distance

  36. Phong Shading • Phong Shading is a popular per-pixel approach to performing lighting calculations • Normals are interpolated across the surface of a polygon • Provides a smoother shading look • Vertex lighting as discussed in this lecture is sometimes referred to as Gourand shading

  37. Questions? Point Lights Spot Lights Phong Shading

  38. To do this week… • Investigate some of the different forms of light that can affect a scene • In particular, try and find their lighting values • Consider the type of lighting you may want in your coursework • OpenGL has light functionality built in without the use of shaders • Shaders provide more controllable lighting

  39. Summary • Lighting is an important concept to provide depth and realism to your scene • Lighting is about the colour of the light, and how an object reflects this light • Three main types of lighting • Ambient • Diffuse • Specular • You should make yourself familiar with how to work these out

More Related