410 likes | 801 Views
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
E N D
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 • Chapter 6 – Lighting and Shading
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%
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)
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
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
Questions? Working with colour
Why Lighting? • Lighting adds depth to a scene • Unlit objects are flat and lack detail • Lighting adds realism to objects • Specular detail • Light reflection
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
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
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
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
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
Questions? Why lighting? Materials Ambient light
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
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
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
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
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
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
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
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
Specular Light Algorithm • Specular light is the most complicated algorithm
Questions? Surface lighting Diffuse lighting Specular lighting
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
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
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
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
Questions? Point Lights Spot Lights Phong Shading
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
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