I had the idea to remove terrain from shadow calculation, sadly it can not work as terrain needs to be rendered in order to stop shadow from propagating through walls. So now terrain is rendered in depth map calculations, but terrain itself won’t cast shadows.
So visually the result is as expected, but it takes a lot longer to render lights (terrain has a very high voxel/vertices count, and is quite hard to optimize without a lot of work on the engine).
Old shadows (circle on the ground) are back, but will be displayed only when jumping (if shadow mapping is activated). It helps player guess where his mecha is when mid-air.
Sun won’t cast shadow, it is too costly (sun is a bit tricky in Alien Blitz, it’s a lot of lights that have an almost infinite far, so a very big scene needs to be rendered for each “sun” on the map, they were not created with 3d in mind, hence this trick…). Thankfully there aren’t that many suns in maps, so it doesn’t really matter.
Edge on terrain has been removed, it doesn’t suit very well the graphical style of the game. But borders on sprites have been improved, only pickable items, player & monsters have a border now. I tried giving them different colors but it wasn’t looking nice.
The good thing is that these borders are visible when behind a wall, I like that.
Adding cache means whenever a sprite moves it must check the surrounding lights and force them to update. Same happen when the terrain is modified (door open or wall destroyed)
Problem is that lights still need lots of updates, there are always things moving around (monsters, turning sprites, player,…) and the game was never build with shadow mapping in mind, so there are LOTS of lights in the levels, way too much for forward rendering in my opinion. Combine that with the high vertex count and you have a hell of a problem.
So now time for some optimizations, first thing that can easily be done is to decrease vertex count (not faces, just vertex) by removing useless/duplicate ones. I didn’t think it would boost performance as the face count is the same, but it does increase shadow mapping speed by ~20% which is nice. It might also slightly improve performance on mobile, but not that much.
Another thing that can be optimized is the terrain mesh sent for shadow mapping, basically terrain is currently a big mesh containing lighting information, texture positions, normals,…. With shadow mapping we don’t care about all these stuffs, we just need to know the global shape of the terrain… and so we can send a really simplified version of the terrain to the rendering passes.
Given this terrain:
If we apply some sort of wireframe (it’s not real wireframe, just some basic render I used to check voxels) we can see the voxels on the terrain:
The idea is to optimize the terrain in order to get that:
Of course all texture/lighting/… information are lost in the process, so this can only be used for internal rendering (depth maps,…), but it works fine (what you can still see now are the chunks, the biggest partition of the terrain).
Problem is that it increases loading time, it’s still acceptable though (5 seconds in worst case)
Cache and performance
Some performance tests (map with lots of lights, min-max FPS while playing):
- Laptop, Intel integrated graphics: 30-120 FPS
- Laptop, Nvidia card (GTX 660M): 50-120 FPS
- Computer, Nvidia card (GTX 280): 100-200 FPS
- EeePC, Nvidia card (ION): 5-30 FPS
Again, it’s crazy how my 6 years old computer is better than my 2 years old “gaming” laptop… but the GTX 280 was an high end graphical card if I remember correctly. I have included the EeePC in the test for fun, the game can run on it without shadows, but with shadows it’s just impossible.
In conclusion results are not too bad, problem is that when there are lots of light updates we can sense that the game slows down on my laptop (because FPS is averaged, it’s the number of frames in one second, so there could be for example 49 frames in 0.5 seconds, and 1 frame in the next 0.5 second, the average in one second is 50FPS, but there have been too many frame lost), especially when vsync is turned on.
I will continue trying to optimize that, depending on results I will decide whether or not shadow mapping will be enabled by default. Given current results it should be disabled by default, but selectable in the options.
I will release a PC demo soon, for testing and to send to some websites that might be interested. It will just include a few levels (I don’t know, 4 or 5), enough to have an idea of what the game is (not the starting levels as they don’t have enough content, it will start with a fixed mid-game save that will be reverted every time the game is restarted)
I will also work on this **** press release that I keep reporting, and send it to some websites.
I will maybe also release a new mobile version soon, I think it will include sprite borders. Depending on performances it might be disabled by default though.