470 likes | 667 Views
Lighting a 3D Scene. Guilford County Sci Vis V204.01 part 1. The 4 Elements of CG Lighting. Where in the Scene the light is located Intensity or brightness Color Angle of Incidence-the more a surface is angled away from a light the darker it appears. The Type of Lights. Point Spot
E N D
Lighting a 3D Scene Guilford County Sci Vis V204.01 part 1
The 4 Elements of CG Lighting • Where in the Scene the light is located • Intensity or brightness • Color • Angle of Incidence-the more a surface is angled away from a light the darker it appears.
The Type of Lights • Point • Spot • Ambient • Directional
Point Lights • Shines light in all directions (much like the sun). • Good for acting as a light from a light bulb or a candle.
Point Lights • Also known as omni or local lights. • Have location but no direction.
Spot Lights • Behaves just like a real-world spotlight. • Good for imitating beams of headlights and focused lamps (lamps with shades).
Spot Lights • Spotlights produce a circular pattern of light known as the hotspotthat grows elliptical in shape as the angle of the light’s centerline decreases. Falloff Hotspot
Spot Lights • The intensity of the light fades with an increase in its distance from the centerline of the cone to its edge. This fading is known as dropoff. • The width or spread of the cone can be controlled in most programs
Ambient Lights • Can shine light everywhere uniformly. • Good for filling the scene with overall light. • Does not cast shadows.
Directional or Infinite Lights • Shines light in the direction of the arrow. Placement not important. Acts like ray from the sun. • Good for directional fill lights in an outdoor scene. • Not very effective with indoor lighting with shadows turned on.
Light Icons • Lights do not have size or shape. • Only see their effects in a rendered scene.
Classic lighting • Classic lighting in 3D needs three types of lights. • Key Light • Fill Light • Back Light
Setting Lights in 3D Scenes • Start in Darkness. • Add a Key Light. • Creates the subject's main illumination, and defines the most visible lighting and shadows. • Represents the dominant light source, such as the sun, a window, or ceiling light - does not have to be positioned exactly at this source.
Adding the Key Light • Create a spot as the Key. • In the top view, offset the Key Light 15 - 45 degrees to the side • From a side view, raise the Key Light above the camera, so that it hits your subject from about 15 - 45 degrees
Adding the Key Light • The key light is brighter than any other light and is the main shadow-caster. Specular highlights are triggered by the Key Light. • Do a test-renders. The scene should have a balance and contrast between light and dark, and shading that uses all of the grays. • The "one light" looks almost like the final rendering, except that the shadows are pitch black and it has a very harsh contrast .
Adding the Key Light • Side view: The Key light is generally placed at a 45 degree angle from the subject.The angle of the Key light is determined by what kind of mood the scene needs.
Adding the Key Light • Top view: The Key light is placed next to the camera. Generally, place the Key Light at an approximately 35-45 degree angle to the subject
Add The Fill Light • The Fill Light softens and extends the illumination provided by the key light, and makes more of the subject visible. • Fill Light can simulate light from the sky (other than the sun), secondary light sources such as table lamps, or reflected and bounced light in your scene. • With several functions for Fill Lights, several of them can be added to a scene. • Spot lights are the most useful, but point lights may be used.
Add The Fill Light • From the top view, a Fill Light should come from a generally opposite angle than the Key - if the Key is on the left, the Fill should be on the right - but don't make all of the lighting 100% symmetrical! • The Fill can be raised to the subject's height, but should be lower than the Key.
Add The Fill Light • At most, Fill Lights can be about half as bright as the Key (a Key-to-Fill ratio of 2:1). For shadowy environments, use only 1/8th the Key's brightness (a Key-to-Fill ratio of 8:1). • If multiple Fills overlap, their sum still shouldn't compete with the Key.
Add The Fill Light • Shadows from a Fill Light are optional, and often skipped. To simulate reflected light, tint the Fill color to match colors from the environment. Fill Lights are sometimes set to be Diffuse-only (set not to cast specular highlights.)
Add The Fill Light • Front View: The Fill Light is generally placed slightly higher or lower then the Key Light. Here it is on the same elevation as the Key Light
Add The Fill Light • Top View: Place the Fill Light at a 90 degree angle from the Key Light
Add Back Light • The Back Light (also called Rim Light) creates a "defining edge" to help visually separate the subject from the background. • From the top view, add a spot light, and position it behind the subject, opposite from the camera. From the right view, position the Back Light above the subject
Add Back Light. • Adjust the Back Light until it gives a nice "rim" of light, that highlights the top or side edge for the subject. (Some people call a light that highlights the side edge a rim light.) • Back Lights can be as bright as necessary to achieve the glints needed around the hair or sides of the subject. Unless one can avoid the need for shadows with careful aiming, a bright Back Light often needs to cast shadows.
Add Back Light. • A Back Light is not a background light - it creates a rim of light around the top or side of the subject No Back Light (left), Back Light added (right).
Add Back Light • Side View: The Back Light is pointed at a sharp angle towards the subject. Be careful here, If the light is placed too low or if the angle is set too close to 90 degrees the light will spill over onto the face or frontal areas of the subject.
Add Back Light • Top View: The Back Light is placed directly opposite the camera and behind the subject
Using Light to Convey Time • The color and angle of a light place a scene in time and space. For morning or evening scenes, make the sun a warm color such as yellow, orange, or red. Then place the light source at a low angle
Using Light for Noon • Cooler white lights placed at a high angle suggest the sun shining at midday. To make a midday scene more interesting, add clouds to the sky and project shadows from them • Fill lights above the ground should be blue or gray to match the sky. Fill lights below the ground should be green or brown to match the earth
Using Light for Night • For night scenes, use a cool blue-white tint to suggest the light of the moon and stars. • If there is fog, streetlights create warm, hazy cones of illumination. If there is a large or brightly colored object in the scene, match a nearby light to that color to create the effect of light radiating off of its surface.
Spotlights, Pointlights, Directional Lights, etc. • There are different kinds of lights and different types of lighting properties inherant to objects. The simplest light is a directional light, or infinite light. This is where the light rays are, to all intents and purposes, parallel (eg. light from the Sun). The computations required for directional lights are considerably less than other types of light source because the angle at which any ray is approaching an object is always the same, thus the angle at which the light strikes any vertex is the same (initial lighting values are always calculated at object vertices first). Thus, one can save time if two different vertices happen to be the same. For other types of light source, light rays will always strike different vertices at different angles, so lighting calculations have to be done separately for every vertex. Also, for flat surfaces affected by a directional light, the degree of shading will be the same right across the surface - an effect that does not happen with other types of light source. In the image above, a single white directional light, placed toward the lower left of the scene, lights up the landscape, producing shadows to the right of hillsides. • A pointlight is defined to be a light source which emanates from a single point in space equally in all directions; for example an arc lamp, or an emergency signal flare fired into the sky from a ship in distress. In the image shown here on the right, a single white point light has been placed in the middle of the scene, producing shadows wherever the point light cannot directly illuminate. • Several N64 games use point lights, eg. Forsaken uses point lights to illuminate one's surroundings whenever a projectile weapon is fired. An example PC game that uses point lights is Quake2 (firing the simple blaster gun into a dark corner shows the effect quite well), so I expect N64 Quake2 (when it is released) will use the same effect. • Note that if a point light is modeled properly, moving it further and further away from a scene should slowly decrease the amount of light falling on the scene (this is because the light rays are not parallel). • A spotlight is a light source which has a cone of effect, eg. a desk lamp or a torch. Like a directional light, it has a basic direction, but it also has a defined conic volume in which its light can fall. The angle of the cone determines how much of the scene is illuminated. Spotlights can also have a drop-off rate; this is the degree to which light nearer the edge of the cone becomes less and less bright compared to light at the center. eg. for a torch beam, directly ahead is the brightest point while to either side the light becomes dimmer usually until there is very little illumination (high drop off rate). Compare this to a stage light, where the cone of illumination is usually fairly constant from the centre to its edge (low drop off rate). • In the image shown above-left, the landscape is illuminated by a single white spotlight, positioned to the left of the scene and pointing downwards to the right. The light has a moderately wide cone of effect (around 60 degrees), but there is no drop-off rate defined, so the edges of the light cone are just as bright as the center of the light cone. The left-hand edge of the cone appears jagged because of the low number of polygons used to construct the landscape (the entire triangle mesh is only 100 by 100). Examine the two main hills in the scene: the shadows on the right faces of the two hills are falling at different angles. • Pointlights and spotlights are local light sources, ie. they are usually close to the observer (as opposed to a directional light which is assumed to be infinitely far away). As a result, the angle between the light source and the normals of the various affected surfaces can change dramatically from one surface to the next, which also means that identical normals in space from different objects will have different angles between them and the light source. • In practical terms, this means that having more than one local light source in a scene incurs many more calculations since each vertex must have lighting calculations performed upon it for each local light in the scene. This becomes especially complex when the colour nature of the light and/or the object is defined to vary across the scene, eg. imagine three spotlights (red, green and blue) all illuminating a pool of water that has been coloured to look like spilled gasoline (which as you know resembles rainbow colours). • The image to the right shows the effect of multiple lights in a scene. The landscape now includes: • a red spotlight, positioned as above but only emitting red light (thus, it does not affect the mainly blue and green low-lying aspects of the scene), • a green point light, positioned as above, • a blue directional light, aimed towards the far left of the scene. • The combined effect looks distinctly strange... • Whenever possible, game designers will use directional lights. Sometimes, one might think that a local light must be used (eg. car head lamp) but in practice one can often get away with using clever texture effects, eg. a bright, partially transparent white cone texture, such as is used in the Library level of Goldeneye, or in Top Gear Rally (TGR) for all the car headlights. Actually, TGR uses several such textures to produce a more believable effect. • Some types of real-world light can be hard to model, eg. flourescent lights. This is because the light is not being emitted from a simple single point, or as a conveniently defined cone. Rather, the light is being diffusely emitted from all parts of what is usually a large object, eg. a long rectangular smoke-glass light box. Such lights never produce shadows with sharp edges and so are hard to model in computer graphics. In a computer game, one could probably cheat by having an object with emissive colour and two spotlights, one at each end of the object - this would produce the appropriate shadows, but would not be as complex as modeling a real flourescent light. • Note: one can simulate a spotlight source using a projected texture. This is where a texture that looks like a spotlight cone is projected into a scene and mapped onto any surface it hits. Obviously, genuine lighting calculations are not being performed in this case, but the results can be surprisingly effective. • Here is some information on specular lights which I typed up as part of an email response to a question I received: • The following is an extract from: • Computer Graphics: Principles and Practice (2nd Edition) Foley, van Dam, Feiner and Hughes Addison Wesley, 1990, ISBN: 0-201-12110-7 • Section 16.1.4. Specular Reflection (pp. 728) • Specular reflection can be observed on any shiny surface. Illuminate an apple with a bright white light: the highlight is caused by specular reflection, whereas the light reflected from the rest of the apple is the result of diffuse reflection. Also note that, at the highlight, the apple appears to be not red, but white, the colour of the incident light. Objects such as waxed apples or shiny plastics have a transparent surface; plastics, for example, are typically composed of pigment particles embedded in a transparent material. Light specularly reflected from the colorless surface has much the same color as that of the light source. • _ _ _ L N R \ | / \ | / _ Fig. 16.8 \ | / V Specular Relfection \ b | b / _.' \ | / a _.' \ | / _.' \|/.-' _...-----..._ • Now move your head and notice how the highlight also moves. It does so because shiny surfaces reflect light unequally in different directions; on a perfectly shiny surface, such as a perfect mirror, light is reflected only in the direction of reflection R, which is L mirrored about N. Thus the viewer can see specularly reflected light from a mirror only when the angle a in Fig. 16.8 is zero; a is the angle between R and the direction to the viewpoint V. • (end of extract) • The book then goes on to discuss the Phong illumination model, created by Phong Bui-Tuong, "... for nonperfect reflectors, such as the apple." • The various equations are given, a key point being that, "... the color of the specular component in Phong's illumination model is not dependent on any material property; thus, this model does a good job of modeling specular reflections from plastic surfaces." • Phong shading is discussed on pp. 738 (section 16.2.5) as part of the chapter on 'Shading Models for Polygons' (pp. 734). This chapter is already available for reading. • An important point about specular reflection as used in computer games is that Phong calculations are complex. In essence, Phong modeling involves calculating many different lighting values across the surface of each polygon, usually by extrapolating normals and repeating a lighting calculation for each new normal. This is very time consuming. Some consoles, like the Nintendo64, probably support Phong lighting directly, but the extra detail it gives is normally not worth the extra effort (is one going to notice the difference in a fast moving game?). A much more common approach is to use the Phong lighting model to calculate colour values at polygon vertices and then use Gouraud shading to extrapolate those colour values across the surface between vertices. This is better than Gouraud shading on its own and is used extensively by graphics cards manufacturers as an easy benchmarking marketing con trick: '1 million Phong-lighted polygons/sec' is very different and alot easier to do than '1 million Phong-shaded polygons/sec' (the former is using Gouraud shading with Phong-lit vertices, the latter is using the much more complex Phong shading). • An important point is that, if one is using Phong lighting with Gouraud shading, the results are greatly improved with more polygons (because there are more vertices). However, since texturing is common and easy to do, it makes sense to use texture wherever possible since this can reduce the required number of polygons by a factor of as much as 200 (compared to flat shading). Even so, some surfaces, like plastics, are not easily represented by textures and in these cases specular lighting is important (sometimes, one uses both, eg. a plastic coated patterned beach ball). To cut down on the calculations required, Phong lighting combined with Gouraud shading is often chosen instead of Phong shading.
Sometimes, textures can be a very effective way of removing the need for a light source altogether, or at least greatly simplifying the situation. Consider a corridor, with a lamp on the ceiling: in the real world, such a light would be a spot light or emissive/diffuse light such as a flourescent lamp, or perhaps a point light for a simple bare light bulb, etc., but not a directional light. For a game, one could use a spot light (or whatever) as normal, but this is computationally expensive, especially if, for example, a character enters the area carrying a torch (two light sources, double the calculations for every affected vertex). • A different approach uses textures instead. The textures for the walls, ceiling and floor are created with the appropriate lighting from the ceiling lamp already included (ie. the lit walls, ceiling and floor are part of the texture and not the result of any lighting calculations going on when the game is in motion). When playing the game, the corridor will look very nice indeed; when one moves though the corridor, the lamp can be made to affect, say, the gun one is carrying by defining the lamp to be a simple downward directional light that has a fade cut-off value (fades away when one moves away from the area). The scene database can be organised so that such a 'fake' light only affects the gun and not the rest of the scene which has already been 'lit' by using textures. The scenery looks great, the lamp affects carried objects, the calculations are much simpler (identical lighting normals for every vertex) and the player won't notice the difference (the image shown above-left, from Goldeneye, is a perfect example of where a texture is used to show lighting). • Even better, if one then decided to shoot the lamp, the missing light can be modeled very easily just by using a different set of textures for the walls, ceiling and floor, and deactivating the directional light from above. Similarly, a partially damaged 'flickering' light can be achieved simply by switching repeatedly between texture sets. Games such as Quake and Goldeneye use these techniques extensively, although it's noticeable that Goldeneye does not often have separate textures available for walls, etc. after a lamp has been destroyed which sometimes spoils the effect of being able to shoot a light in the first place - an example of this is shown in the above-right image where I have destroyed the wall lamp, but the lit-texture effect has not changed. Perhaps the extra textures are not included because of space considerations. It will be interesting to see whether Perfect Dark employs this lit-texture technique properly. • However, one disadvantage of the texturing method described above is that the player may notice inconsistencies between the fake lamp light and the resultant lighting on a carried object such as a gun when the player is close to a wall. In the heat of the action though, it's unlikely the player will notice. • In time, as compute power becomes greater, the need for such careful programming techniques to increase game speed will lessen and designers will be able to offer full texuring, Gouraud, Phong, etc. lighting all round, whatever gives the best realism. On the other hand, whatever compute power is available, it's likely that designers will always try and push the game hardware to the limits, so perhaps these space-saving, speed-increasing techniques will always be used to some degree.