Lighting

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Anickyan
Prole
Posts: 27
Joined: Sun Aug 05, 2012 8:42 am

Lighting

Post by Anickyan »

I have been thinking about something: an easy way to apply simple lighting to games. I was thinking about creating an emtpy ImageData, and filling it with a dark color, with a low alpha value. And loop through all of the tiles, and measure the distance from every light source, and then apply the correct shading.

Measuring distances is pretty easy:

d = sqrt( (x2 - x1) ^ 2 + (y2 - y1) ^ 2 )

And then I would use ImageData:setPixel() to apply appropriate shading to the tile/pixel.

I was wondering if this would be too slow, and if there were any alternatives. I do not really want to get into PixelEffects, as I only need very simple lighting.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Lighting

Post by kikito »

I've seen several ways of adding light to a game. Have you tried searching through the forums?
When I write def I mean function.
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Lighting

Post by Ref »

What's wrong to just use a simple shader?
Just an option depending on what you want to accomplish.
Attachments
spotlight.love
Pixel effect spotlight
(204.82 KiB) Downloaded 301 times
Anickyan
Prole
Posts: 27
Joined: Sun Aug 05, 2012 8:42 am

Re: Lighting

Post by Anickyan »

That is not the effect I wanted, but thanks anyways. I don't want it to be a perfect circle, but rather be "blocky", and only have one shade per tile.
User avatar
Inny
Party member
Posts: 652
Joined: Fri Jan 30, 2009 3:41 am
Location: New York

Re: Lighting

Post by Inny »

Sounds like you want a flood fill algorithm that traverses out a number of tiles from the light source, remembering distance traveled, and setting the lighting value to the larger of the various lighting sources that traveled the block. This would give you a kind of diamond lighting shape, but making it a circle would be easy enough if you took some considerations like if you travel to the same block from multiple directions, add a logarithmic value.
graham77
Prole
Posts: 1
Joined: Tue Oct 23, 2012 12:17 pm

Re: Lighting

Post by graham77 »

I've seen several ways of adding light to a game. Have you tried searching through the forums?
I second his opinion, off course there are many ways of doing it. Search through forums /blogs else I'll tell you ways.
User avatar
qaisjp
Party member
Posts: 490
Joined: Tue Sep 04, 2012 10:49 am
Location: United Kingdom
Contact:

Re: Lighting

Post by qaisjp »

I'd like to create SuperMeatBoy like lighting but there is no point using shaders (that my current pc cannot run) when SuperMeatBoy doesn't use much of them (which my current pc can run)
Lua is not an acronym.
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Lighting

Post by T-Bone »

It doesn't have to be slow, if you save your rendering to a Canvas, you only need to calculate the lighting once. But if you want stuff to react to movements of the light source for example, it might get very slow. It is also very resolution dependent. If you calculate the lighting in a low resolution and then scale it up, it can be much faster (and look more pixely which is awesome).
User avatar
substitute541
Party member
Posts: 484
Joined: Fri Aug 24, 2012 9:04 am
Location: Southern Leyte, Visayas, Philippines
Contact:

Re: Lighting

Post by substitute541 »

There are lots of ways. Probably the simplest isto find the distance from one tile, to a light source, divide it by something to create a ratio, multiply the ratio by its brightness (which is a percentage) and just use the new value to somehow darken the tile.
Currently designing themes for WordPress.

Sometimes lurks around the forum.
Post Reply

Who is online

Users browsing this forum: Amazon [Bot], Bing [Bot], Google [Bot], Semrush [Bot] and 5 guests