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.

DarkBASIC Professional Discussion / Quasi 2d Light Map Questions

Author
Message
Alaror
15
Years of Service
User Offline
Joined: 9th May 2011
Location:
Posted: 8th Sep 2011 23:28 Edited at: 8th Sep 2011 23:40
EDIT: I realize now that it may be more accurate to describe what I'm trying to achieve as "Illumination Mapping," since I'm trying to illuminate only specific parts of the map.


I'm working on a side-view 2d game made of randomly generated terrain which is displayed as blocks. All terrain data is saved into a single array, and is (currently) then partially loaded into a matrix. Recently I've began playing around with some of the lighting commands in DarkBasic, which was something I had wanted to use from the get-go. I've attached a screenshot of how things look right now; a single point of light illuminates the matrix, and is supposed to illuminate the player but for some reason isn't right now.

I like the visual effect it provides, but I can already foresee some problems. My problem stems from the fact that while the visual style appears to be 2d, there are in fact more than two dimensions. Besides the world height and width there is a depth value, which is made up of four layers: foreground (non-obstructing, appears in front of the player and all objects), ground (the layer of the player and obstructing terrain the they can not move around but can edit), background (non-obstructing terrain the player can move in front of and edit), and finally the base (non-obstructing terrain the player can move in front of but not edit).

This in itself isn't much of a problem; I can very easily display these layers using matrix commands. Things get tricky when you move onto a global illumination system, such as a day/night cycle. A light source at the top of the screen has to stop once it reaches a solid block in the "ground" section. I've thought about using another 2d array to store light map values for every block in the game, but there doesn't appear to be a DarkBasic lighting system that could take these values and display a specific strength of light for the block.

Any thoughts on how something like this might be implemented? I do have access to the commands included in the Dark Lights addon.
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 9th Sep 2011 00:28 Edited at: 9th Sep 2011 00:32
You could set the light range, and if it isn't accurate enough move the blocks further apart, and then scale them up to make them look the same size, then tweak their speeds so that they move at the same speed. So an object twice as far away, but twice the scale moves at twice the speed (maybe something like that???)

Or.. you could change the light emissive colour of the blocks based on their heights.

Alaror
15
Years of Service
User Offline
Joined: 9th May 2011
Location:
Posted: 9th Sep 2011 09:34
@Pincho Paxton

The problem is that I'm not using actual object cubes since creating or even just moving/re-texturing them in the amount I need (768 minimum in a single step) causes a small but noticeable pause in the game. Also note that with my earlier tests I was using object planes, which are less processor intensive than full 3d objects such as cubes. Right now I have a single matrix with each tile being unique to what type of material is in that location (you can see an ore node among the dirt in the screenshot from my previous post). This is great for speed but not lighting.

That said, after reading your suggestions I did come up with one idea today which is worth trying, but it hinges on whether or not the DarkLIGHTS command "LM ADD TRANSPARENT COLLISION OBJECT" will allow me to reuse a single object (there's a note in the description of "LM ADD COLLISION OBJECT" which says the data is stored, so the object itself isn't needed any more). My idea is that I create a single cubed object with its texture being slightly transparent. Instead of creating a new object for every single tile, I would reposition the object at each tile and then add it to the lightmap. Once all tiles have been added, the actual lightmap would be calculated and displayed. The world would be displayed with the following layers (the lower the number the further away from the camera/screen):

1. Matrix: Base/Background/Ground
2. Semi-transparent cube to reduce how far light goes
3. Lights
4. Matrix: Foreground


It's extremely late right now so I'll have to test it out tomorrow if I get time. If anyone has other suggestions/possible ways to tackle this problem I'd be very interested in hearing them.
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 9th Sep 2011 10:30
I did some 2D lighting maps on my Bruce game a while ago. All my platforms and stuff were 3D objects, so what I did was make 2 plains, one in front of the players/enemies, and one behind. Then for each screen there was a seperate pair of shadow textures, these were calculated with Sparky's, doing line collision checks between each pixel and each light source. I also did a height check on each pixel, to decide which shadow layer to use.

These shadow maps took a while to render, so it's not something you can do in realtime, but it did give a cool effect. Having 2 shadow layers means that players can be hidden in shadow as well as being in front of shaded areas. I went for an Abe's Odyssey effect. Anyway, theres a video of Bruce here: http://www.youtube.com/watch?v=BK3ESzz_d_A

Health, Ammo, and bacon and eggs!
Alaror
15
Years of Service
User Offline
Joined: 9th May 2011
Location:
Posted: 9th Sep 2011 19:29
Well I read up on DarkLIGHTS a bit more and found that it's for pre-rendered lightmaps in scenes, rather than dynamic lighting. In another topic someone mentioned that it can be used in real time as long as you're not moving the lights around too much (which I would be). Another person said that DarkLIGHTS can't be used to illuminate a matrix anyways so that would put an end to it as well. Anyone have experience with DarkLIGHTS who could confirm if all this is true?


@Pincho Paxton

Would you mind elaborating a bit more on this:

Quote: "Or.. you could change the light emissive colour of the blocks based on their heights."



@Van B

That's pretty neat, but sadly I would need to do it all in real time. Do you think it would be technically feasible with a game that has dynamic terrain such as mine?
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 9th Sep 2011 19:49 Edited at: 9th Sep 2011 19:54
Set Object Emissive 1,Rgb(10,10,255)

Will give you control over the glow of an object if you lower the ambience. So you could create a fake light effect from it. It'll make an effect a bit like TRON.

If you fast forward my video to 6:11 you can see what I mean...
http://www.youtube.com/watch?v=zBtt-iVqvFE&feature=related

Login to post a reply

Server time is: 2026-07-11 06:25:57
Your offset time is: 2026-07-11 06:25:57