The problem I had previously on the far was because of the pack/unpack functions I was using to store depth data on all the rgba values, now I will just use an alpha texture for lights depth map. So I will loose precision, but in a third person view it doesn’t really matter.
All far values work now
Correcting multiple lights
My problem with multiple lights was just a small bug in my multi render pass, no idea why it was working on my nvidia card and not on my intel card.
The shadow map :
The render :
Of course as there are lots of lights there’s not so much shadows.
Adding basic colors is pretty straight forward from here, the shadows & render :
Comparing to the current render :
There’s still some work to do to get a similar result, mainly because in the current solution I do a lot of smoothing. But the advantage of shadow mapping is that even sprites have a shadow…
After just a few modifications, and trying to smooth a bit (2nd image)
It doesn’t change that much
Tests on PC
I ran 2 tests on different configurations and checked the FPS, using the sample level (7 lights)
- Render everything every frame
- Cache depth map, render shadow map, blend shadow map
Results (first number is test 1, second is test 2) :
- Recent laptop, Integrated Intel card : 26/60
- Recent laptop, Nvidia card : 53/60
- Old computer (6 years old), Nvidia card : 60/60
I’m surprised my old computer has such a good result, but even in some recent games it performs better than my laptop (Borderlands Pre Sequel for example), but it can’t render all the effects on these games (old graphical card)
In the first test the depth map is computed each frame, I didn’t try to optimize anything (my shaders are certainly full of bottlenecks), in a final version it should cache the depth map and re-render it only if something is moving in its range. So it would save A LOT of time, I think it will always render at 60fps on these configurations with proper optimizations and caching.
Sadly my netbook is broken, it needs a new memory kit, so I can’t test on it.
I prefer the old rendering, maybe I could do a mix between old and new, to get dynamic shadows but keep the light colors.
I don’t know yet if it will be included on PC version, I will continue working on it for now, and we will see.
I think I’ll try to do a clean tutorial with all I learned, basically it will cover
- Point lights and directional lights
- Cubemap frame buffers
- Multiple lights
- Multi pass rendering (forward rendering)
- Everything using Libgdx, and Android/iOs/PC compatible
It will not cover caching of lights, everything will be rendered each frame. Because this is a very specific work that depends on your game engine.
The problem I have is I’m pretty sure there are better ways to do it, but at least it works 😉