Page 1 of 1

Light system test

Posted: Mon Jul 11, 2016 7:51 am
by steVeRoll
Yeah, I know there's already a light library for love2d, but I created one by my own anyway.
It's VERY SLOW. VEEEEEERY SLOW. It can't be used in normal games, it's just a test I made.
If you have any suggestions on how to make the code better, or just have an opinion, reply!

Re: Light system test

Posted: Mon Jul 11, 2016 8:15 am
by ivan
Hello. It's ok, but the code needs a lot of work.
For starters you need to use locals for stuff like:

Code: Select all

          if light.x+(math.cos(ray.angle)*ray.len) >= box.x and light.x+(math.cos(ray.angle)*ray.len) <= box.x+box.w and
          light.y+(math.sin(ray.angle)*ray.len) >= box.y and light.y+(math.sin(ray.angle)*ray.len) <= box.y+box.h then
            keepdoing = false
          end
Generally I don't think it's a good idea to cast rays in every direction,
a cleverer approach would be to cast the rays to specific vertices in the scene.
As an optimization, you could ignore vertices that are too far away and edges that are "facing away".
It's possible to do a lot of fancy stuff using math alone, but I think a hardware accelerated solution
would be a better move at some point in the future.

Re: Light system test

Posted: Tue Jul 19, 2016 7:12 am
by steven777
i got 30 fps solid with it... thats decent.