Slick Forums

Discuss the Slick 2D Library
It is currently Wed Jun 19, 2013 1:32 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Fri Aug 10, 2012 1:04 am 
Offline

Joined: Sun May 13, 2012 5:06 am
Posts: 18
I've read through the large lighting topic and a few other topics as well as gone through tutorials on lighting, and I'm wondering which implementation of lighting would work best for my situation.

The game I'm working on is a side screen platform game in 2.5D mostly with tiles. Each tile, rather than being squares, are 2D cubes that overlap each other. Besides the tiles, the trees and characters and background images and objects crafted and placed are not tiles. The best way to explain the look is probably a 2.5D version of LittleBigPlanet or a 2.5D Terraria.

-I tried alpha maps, but it messes up because each cube has transparent corners and they appear white rather than transparent. Plus making cubes transparent makes adjacent cubes shine through since they are overlapped. Would there be a method just like alpha maps but darkens each cube outside of the "alpha map" image rather than making them transparent and allowing black/what's behind to show through? Problem with this method though is that it would make every outside cube black on the map and overlapping multiple lights would be tougher.

-The average vertex lighting wouldn't look right because it would test for the corner of the images on a cube... for instance the top right corner is transparent space yet the bottom left corner is part of the front of the cube, the square face of the cube. If I do the lighting for the corners of the front facing square on the cube, the top and left side of the cubes would be left out of lighting and would need more complications to make work... it just makes it all complicated and I may have to break the cubes up into multiple images.

-Lastly and maybe the best way I thought of, is making a fog of war type of method or a reverse alpha map kind of thing. During the day, each cube tests if there is a cube adjacent to it and if there are cubes on all sides, a black image in front of it loses transparency and covers it. If there is no cube or less cubes adjacent to it and the sky shines through, the image in front stay transparent or is non-existent. During the night, all cubes are have the black image in front lose transparency. Any lighting I would do would work like an inverted alpha map- rather than an alpha map making only part of the image appear and the rest of it be transparent and be the black background image, it would make the black images in front of the cubes transparent if the "alpha map" image runs over them. What would be the easy way to do this method?


Last edited by Gheta on Sat Aug 11, 2012 6:11 pm, edited 1 time in total.

Top
 Profile  
 
PostPosted: Fri Aug 10, 2012 1:42 am 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1477
Show some pics of your 2.5D game so far, or how you expect it to look, and then how you expect the lighting to work. Hard to visualize with just text...


Top
 Profile  
 
PostPosted: Fri Aug 10, 2012 2:20 am 
Offline

Joined: Sun May 13, 2012 5:06 am
Posts: 18
Here is an idea (I just quickly drew a fake mock-up in Photoshop to give you the idea):
http://i49.tinypic.com/2jchvgg.png

Notice they are overlapping cube tiles and not flat squares.




I was thinking of making a fog of war that is a couple blocks in during the day, or completely covering the blocks and outside blocks at night, then make something similar to an alpha map but the opposite (except instead of making the outsides of the light transparent revealing black, the inside of the light is transparent, making the fog transparent) that makes the fog transparent when the light source is near it. I would also like to block parts of the light source if a walls obstructs it and combine multiple lights if the are near each other.

Would that be the best/easiest method you think?


Top
 Profile  
 
PostPosted: Fri Aug 10, 2012 11:59 pm 
Offline

Joined: Sun May 13, 2012 5:06 am
Posts: 18
Ok, I got the effect I want with only one issue.


-First I g.setDrawMode(Graphics.MODE_ALPHA_MAP);
-Then I draw all the black shaded in areas (without doing this, the outsides of my alpha map images become transparent too).
-Then I draw in my "reverse alpha map" images where ever I want the lights to be. They have transparency in the middle and black on the outsides rather than black in the center with transparency on the outsides. The transparency in the center removes any black shaded in areas.
-Then I draw the black shaded in areas again to blend in with the alpha map images.

It works good, except that you cannot combine multiple image next to each other or you end up seeing the black outer edges of the other lights in front:
http://i45.tinypic.com/2vilaoo.png


Any ideas on how to do a quick fix on this?



EDIT Aug 11, 1:25am: I thought of something that may work better. Is there an easy way in alpha maps to make it so two opaque images temporarily subtracts rather than adds? Meaning if I put a normal alpha map image that is 100% opaque black and put it over another opaque black image, they would subtract each other and make 100% transparent? That should solve all my blending issues with multiple transparent images I think.


Top
 Profile  
 
PostPosted: Sat Aug 11, 2012 6:10 pm 
Offline

Joined: Sun May 13, 2012 5:06 am
Posts: 18
I apologize for the triple post, but I solved my issue and believe this should be updated for those looking for different lighting systems they can implement in their game.

When using alpha maps to remove shaded in areas with light, instead of using:

Code:
g.clearAlphaMap();
g.setDrawMode(Graphics.MODE_ALPHA_MAP);
.........draw your alpha map images for lighted areas
g.setDrawMode(Graphics.MODE_ALPHA_BLEND);
.........draw your tiles
g.setDrawMode(Graphics.MODE_NORMAL);


Which is good for having a black background behind everything and making only lighted tiles appear we can do the reverse of it and use:

Code:
g.clearAlphaMap();
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
.........draw your alpha map images for lighted areas
GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_DST_ALPHA);
.........draw black foreground image(s)/shaded in areas that appear in front of tiles
g.setDrawMode(Graphics.MODE_NORMAL);


This worked better for me, because I had 2.5D blocks rather than flat square tiles and the first method makes the tiles become transparent. Making them transparent showed the sides of the blocks next to them since they overlapped (the overlapping cubes are seen in the first posts to get what I mean). Not to mention I had many layers behind the cubes and it just made things complicated.

Now I just have to make the light images clip or fade when they are cut off by block walls.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group