Merge: gamnit: shadow mapping
authorJean Privat <jean@pryen.org>
Thu, 7 Sep 2017 14:48:53 +0000 (10:48 -0400)
committerJean Privat <jean@pryen.org>
Thu, 7 Sep 2017 14:48:53 +0000 (10:48 -0400)
Intro a basic API and the shaders for 3D actors to cast shadows. This feature is off by default, it can be activated by using a sun-like light with: `app.light = new ParallelLight`. This will require additional work to improve the performance, add more kind of lights (point, spotlight, ambient, etc.), support many lights and accept colored lights.

Many values can be tweaked to achieve the best performance tradeoff:

* `ParallelLight` is always centered on the `world_camera` to show shadows only around the player. Its attributes `width, height, depth` are in world coordinates and identify a prism where shadows are computed. Higher values show shadows further away and lower values show shadows in higher resolution.
* `App::shadow_resolution` sets the resolution of the depth texture. Higher is prettier but slower, there's also an upper limit depending on the hardware configuration. It is now hardcoded (but refinable) to 4096x4096 pixels, with is probably too high for some mobiles devices. More experimentation is needed to find a safe default value.
* For softer shadow edges, the shader applies a kind of antialiasing by tapping the depth texture many times for each fragment. It is currently hardcoded to 4 taps per fragment but it could be changed for better performances or smoother edges. I don't know where to expose this value in the API, it could be on the light, the material or even global. It can also be optimized by the hardware.

### Screenshots from Jump 'n' Gun

Looking down at the player's shadow:

![screenshot from 2017-08-29 10-31-48](https://user-images.githubusercontent.com/208057/29829419-62b27cfa-8cad-11e7-9d95-696e594f4490.png)

Complex shadows from a turret and a shield projector:

![screenshot from 2017-08-29 10-35-45](https://user-images.githubusercontent.com/208057/29829415-5f08d5c2-8cad-11e7-87ca-5e4566d2432b.png)

Pull-Request: #2543


Trivial merge