Light system test

Show off your games, demos and other (playable) creations.
Post Reply
User avatar
steVeRoll
Party member
Posts: 131
Joined: Sun Feb 14, 2016 1:13 pm

Light system test

Post 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!
Attachments
lights.love
(841 Bytes) Downloaded 161 times
User avatar
ivan
Party member
Posts: 1915
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Light system test

Post 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.
steven777
Prole
Posts: 35
Joined: Tue Jul 12, 2016 4:48 am

Re: Light system test

Post by steven777 »

i got 30 fps solid with it... thats decent.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 0 guests