Skip to content

Latest commit

 

History

History
162 lines (127 loc) · 6.27 KB

lecture06_shadows.asciidoc

File metadata and controls

162 lines (127 loc) · 6.27 KB

Shadows

What are shadows?

  • absence of light on a surface due to occlusion from other objects

    • not necessarily complete absence

    • could be other light sources

    • light sources are usually unfocused - give soft edges to shadows

Shadows - examples

shadow mapping with without

Shadows in OpenGL/DirectX

  • Both OpenGL and DirectX only resolve the generic rendering equation in a quite limited way

    • light only in straight lines

    • light transfer only one step from surface to camera

    • light transfer only one step from a light to surface (local lighting)

      • discounting any occlusion

  • In other words, our normal lighting is extremely incomplete

Local lighting

  • The pipeline nature of OpenGL and DirectX mean that each vertex/triangle only has information about itself

    • they don’t know where any other triangles are

  • This makes things fast

    • but limited

Global lighting

  • There are a variety of global lighting models/techniques.

  • Some you could look into include:

    • ray-tracing

    • path-tracing

    • radiosity

    • photon mapping

    • metropolis light transport

Global lighting 2

  • These take into account how light is transported between (and within) surfaces

    • but require information about the whole scene at all stages

  • They tend to be extremely expensive relative to local-lighting models

    • except that for good local-lighting models we have to hack in some global-lighting effects

    • shadows are one such effect

      • and are important sense of depth

      • and for for visual quality

Radiosity   RRV, step 79

Light maps

  • As global lighting is expensive we could pre-calculate some/all of the lighting/shadows effects

  • This technique is called light mapping

    • on offline process (usually in a 3D modelling package) "bakes" the light in to the scene

    • "bakes" = makes a fixed/static version of something (can also do with physics)

    • gives an static output that we can use in our rendering

  • Usually the brightness of a surface is calculated offline and stored in an image to use as a texture

  • The lighting for lighting mapping can be arbitrarily good

    • it’s offline, so depends only on how much offline time we want to throw at it

  • Doesn’t (easily) account for dynamic scenes - where things change move

    • Can combine with dynamic lighting models

Shadow maps

  • Modern method for dynamic shadows (2016)

  • Requires rendering to off-screen buffers

    • AKA render-to-texture

    • Frame-Buffer Objects

Shadow maps - outline

  1. Render from each light - depth-only

    • store in a texture/FBO

    • everything the light can’t "see" is in shadow

    • this gives us the closest point on a ray, to the light

      • i.e. the nearest occluder of the light in a specific direction

  2. Render as usual

    • with extra test to determine shadow status

    • using the FBO

    • for each fragment calculate the distance to each light

    • compare with the distance stored in the shadow map for that direction

      • we have to sample the texture/FBO appropriately

      • we have to be able to calculate where in the texture/FBO to lookup

    • if shadow map is nearer then this fragment is in shadow

shadow mapping theory spaces

Shadow maps - hints

  • The resolution of the shadow map is up to you

    • higher resolution gives better results

    • costs more render time

  • Simulate the viewpoint of a directional light (one with parallel rays) with an orthographic projection matrix

  • Your shadow map rendering stages should use separate shaders

    • they need to do much less, so only do what you need to

    • you could use if conditions in your shaders

      • but generally (in other situation) DON’T

  • The matrix used to transform vertices for the shadow map is exactly what we need for calculating the lookup into the shadow map

    • when rendering the player-viewpoint, we have to pass extra information (about the lookup into the shadow map) from the vertex shader to the fragment shader

IF conditions in shaders

Shadow map - artifacts

  • Shadow maps are theoretically reasonable straightforwards

  • Practically, lots of issues to get right

    • lots of artifacts if we aren’t careful

      1. Shadow acne

    • depth map has limited precision and resolution

    • similar to z-fighting

      1. Peter panning

    • solving shadow acne may detach shadows from their objects

    • objects visually appear to float on surfaces

      1. Over sampling

      2. Aliased edges

    • depth map has limited resolution

shadow mapping zoom

Shadow maps - costs

  • Good shadow maps are pretty expensive

  • Good shadow maps are pretty complex

    • in theory

    • in practice

  • Perhaps at some point, real-time light transport methods will be used instead

    • i.e. no more local lighting.

Workshop Activities