Lecture Cameras and lights 1Elias Holmlid
First part Cameras Lights ▪ Light types ▪ Light models ▪ How light is computed Second part We’ll implement an effect for phong shading & cel shading Elias Holmlid2
Fixed perspective First person Third person Elias Holmlid3
Example: Alone in the Dark (1992) Elias Holmlid4
Example: Bioshock (2007) Elias Holmlid5
Example: Tomb Raider something Elias Holmlid6
Problems with geometry hiding the players Might be solved with transparency Elias Holmlid7
Dizziness... Elias Holmlid8
Different follow behavior + giving the player some camera control Elias Holmlid9
10
A game might use several different cameras Use a manager for handling all the cameras Elias Holmlid11
Directional Sunlight (on Earth) Spotlight Point light (ominidirectional) Emitting light from one point in all directions Sunlight (on a deadly distance) Elias Holmlid12
Elias Holmlid13
Global illumination model Elias Holmlid14
Local illumination model Elias Holmlid15
Light may be precomputed and stored Global illumination models might be used (!) Elias Holmlid16
Elias Holmlid17 Gouraud: Per vertex Phong: Per pixel Color interpolated during rasterization Normal interpolated during rasterization
Can be accomplished in different ways; one technique is called hard shading Elias Holmlid18
Elias Holmlid19 LightMaterial (object) (Ambient) Diffuse: i d Diffuse: m d Specular: i s Specular: m s SpecularPower: s (Emissive)
In the real world, light bounces around: Therefore, all points are hit by light in some way Ambient light makes up for our non-global illumination model Ambient component might be just a global color (and not part of each light/object) Elias Holmlid20
Simulates how light bounces off a rough surface (it scatters in all directions) Elias Holmlid21
Elias Holmlid22 We want to find a scaling factor depending on how a point is hit by the light...
Elias Holmlid23 ...the dot product is ideal for this if clamped to the interval [0..1]. HLSL has a dot() function and [0..1] clamping can be done with s aturate()
Takes the viewpoint into consideration Light bounces off in a specific direction and might hit the eye (camera) Elias Holmlid24
If objects are only rotated and translated, normals can be transformed with the same matix If the above applies, but the object is also uniformely scaled, normals will have to be renormalized However, if non-uniform scaling or shearing is applied, normals will no longer be normal to the surface Then, the inverse-transpose of the transformation matrix does the job: B = (A 1 ) t In XNA: B = Matrix.Invert(A); B = Matrix.Transpose(B); This is done automatically for you if you use BasicEffect! Elias Holmlid25
BasicEffect supports a maximum of three directional lights If you want point/spot-lights, more lights, or do stuff like toon-shading you have to implement your own effects Elias Holmlid26
Stores all the lights Might contain methods for finding the closest light to a point etc Elias Holmlid27