For every light
For every block
Iterate over edges of block, calculating the shadow for each edge
Draw the shadows to the inverted stencil
Turn on shader and additive blending
Draw a fullscreen rectangle (shader renders the light with some simple math)
Change blending mode to multiply
Render every block with color
It's all runs smoothly, even with many lights and many Box2D bodies.
I just wanted to share and see what you guys think
Ranguna259 wrote:Really nice, what fps do you get ?
Hmm I just tested it. I get a solid 60 w/ 10 lights and 100 bodies, and also with 25 lights and 8o bodies
All of the code is currently optimized for readability so there's likely performance loss there. Also most of this is computed on the CPU. I might try moving all of it over to a shader to make it more robust.
Would you normally do math (like calculating the position of shadows) inside a shader? Or should that stay on the CPU?
Edit:
Well I just saw this: viewtopic.php?f=5&t=77418
Disable vsync and check the FPS, lights on the CPU are very resource intensive so I want to know how much is shader based lightning better than CPU lightning.
Last edited by Ranguna259 on Wed Jul 16, 2014 12:02 am, edited 1 time in total.
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping