Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] - 2D "lightmap"

Author
Message
noobnerd
13
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 3rd Apr 2013 16:00 Edited at: 3rd Apr 2013 23:35
Hi this is a pretty simple light/shadow program that can be used to make real time shadow/light effects in 2D top down games (or why not platformers or any other 2D game for the matter). Fairly simple to implement depending on how you have defined your world.

The code has some useless stuff that remained after i deleted most of the non relevant code. This was part of a larger thing.
if you run it you may notice low fps, the background boxes are very resource intensive and sloppily coded. On a solid background with some boxes the ldensity 4 makes about 90fps on my comp


Oh it needs Advanced2d plugin and Matrix plugin

THE setting "ldensity = 8" int the beginning of the code defines the detail of the lightmap. 8 is 64 times more detailed than the grid you see. (8x8 = 64 times more nodes). This can probably run slow on slower PCs. For mine 6-8 is fine but 2-4 would already look very crisp if a rough texture was used as the ground. ( is pretty much as high as there is any point of going with this.
the setting "density# = 10" defines the base grid detail. higher values make larger boxes -> better performance

Attachments

Login to view attachments
noobnerd
13
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 3rd Apr 2013 16:12 Edited at: 3rd Apr 2013 16:14
and a full HD image to show the detail @ ldensity 8

Attachments

Login to view attachments
chafari
Valued Member
17
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 4th Apr 2013 17:51
A clever way to make good lightmaps...no only for the ground, but as well for all walls...perhaps not for runtime, but good enough to save them and mix them with the final textures.

Long ago, I made the same for my lightmaps program, that render a complete room (6 sides) like all engines. Take a look to part of my initial project.



Cheers.

I'm not a grumpy grandpa
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 5th Apr 2013 09:42
Nice!

Never sure what the best way to implement this stuff is though.

What might be cool, is if it could be applied to a matrix of plains - like a 2D mesh, then use the lightmapping on the vertexes. Then someone could apply a tilemap texture, and have a lightmapped 2D map system to start a project with. It would mean a much lower resolution to lightmap as well, wouldn't look quite so nice - but it would be quick. Maybe even just cycle through every vertex and use the same technique to set the diffuse colour from an array of light sources.

Just a thought.

I got a fever, and the only prescription, is more memes.
noobnerd
13
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 5th Apr 2013 12:21
@ chafari: Thanks, as i understand your code you check the visibility to all coordinates in the field if they are visible from the lightsource? yeah thats pretty much what im doing except i start from the lightsource and go outwards. Yeah its not blazing fast but with ldensity 2 it can easily be used realtime in 2D.

@ Van B : thanks, not sure what you mean by that but as i see it you are refering to an irregular mesh to save vertexes? that is a mesh that isnt ordered in neat rows and columns? not sure how this code would work on such a system.
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 5th Apr 2013 13:12
Yeah, it's probably something I'd have to try out - when I have some free time I'll see if I can adapt one of these examples.

I got a fever, and the only prescription, is more memes.

Login to post a reply

Server time is: 2024-04-20 05:07:35
Your offset time is: 2024-04-20 05:07:35