Removing artifacts near the light is simply done by adding a bias to the depth test, it is good enough in our case
I’ve also added back unrealistic shadows on wall: walls on the right/left or down/top have an automatic different shadow applied, it makes gaps easier to see (you can see the small holes on the top-right of the image now, they were previously invisible).
It could be done using global illumination, but this method is a lot quicker (just testing the normal of a surface) and works nicely in Alien Blitz.
I will now make some assumptions, in order to get a good visual aspect over rendering speed ratio. It is very specific to Alien Blitz:
- Most lights have a small range, except sun lights that will probably have a specific code
- Bullets should not have a realistic shadow, the old one is best as it allows player to easily guess the height of a missile (I’ve tested both, unrealistic shadow is really better for gameplay)
- View is quite far away, no need for high quality shadows (a FPS view would require such shadows)
- There can be lots of lights on screen, so they should be computed quickly
These points explain some choices I will make from now on, if at some point I want to develop a first person view game I will have to change lots of code.
Testing different shadow map sizes
64px is obviously too small, 256px should be enough for most lights, and 1024px for high range lights (sun)
There are some artifacts above walls, I will have to correct them with PCF but maybe just as an option (3 quality options for shadows : low without PCF & 256px maps, medium with PCF & 512px maps, high with PCF & 1024px maps, or something like that)
Real level test
I’ve changed my code a bit so that light used for shadow mapping is the closest to the player, that allows me to quickly run some tests on actual levels.
It really feels good, currently shadows are very big, but when all lights will use shadow mapping it should feel better I think, otherwise I will have to make some changes on lights (higher and looking at the ground)
More complex test case
For next modifications I will need a more complex test case, with more lights, colors and such. Here it is (it also let me test that the old code was still working)
I should have used this king of effect (different light colors in the same room) in the game, it looks nice 🙂
Point lights / Omni-directional lights
Omni-directional lights require to use a cubemap, basically the scene is rendered 6 times : left/right/up/down/bottom/top
Of course in Alien Blitz top rendering is useless
The idea is just to render the scene 6 times, changing camera looking direction and viewport position/size each time.
Here is the resulting map
I will assume a light does not cast a shadow on itself, it will make things easier (hence the full black image in the bottom-right, the top-right is supposed to store the top view map, but it is unused here)
Time to render this new map now:
There are some artifacts on the edges of the 5 generated maps (it can be see on the left/down diagonal), other than that it seem quite fine.
I am now considering managing multiple lights, but I’m afraid I will come on some difficulties:
- Depending on the video card there can be some huge limitations (221 max uniforms vectors, 16 textures, on one of my video cards)
- I still get 60fps, but I think it is already beginning to be heavy on the gpu (my laptop is increasing fan speed, that’s a good indicator)
Most examples on the Internet are very simple: directional light, one light only,… so I will have to find some better sources on how to manage multiple lights and do lot of tests.
And of course I need to handle colors now.