Trying out an idea.
Well, I stand corrected. If you only process the necessary parts of the screen and fake the rest, you can get the effect to take up much less CPU.
I was reading the Dank Tombs articles by Krajzeg and decided to see how far I could get with what I know. I cheated and used a smaller screenspace at 30fps, but not even that could save me from CPU overload...I want to get this effect running well enough that a game could be played using it, but I think at some point to go any farther I'll need to delve into more complicated things than what I'm doing.
Hum...looks like you did not get the core ideas of Krajzeg:
(you get the shading right ;) )
- don’t work on pixel (use peek/poke to work on pairs)
- precompute shading pairs (for 16x16 color combinations)
- compute shading area per row (eg don’t do dist(...) for each pixel ), eg find x where xx+yy=radius for a given y (can even be precomputed).
Alternative: look at circle rasterization to find boundaries.
Known caveat: your version is pixel perfect, the fast version is not (unless you get the extra mile and got per pixel for the outer boundary)
Edit: realized my code is a bit too complex for demo/tuto purposes. Simplified version below (requires mouse):
You can have a look at Nuklear Klone level 2 - I used that very technique @60 fps:
(I have 3 precomputed lights with different radius to simulate flicker and avoid costly sqrt(...) )
[Please log in to post a comment]