Low Cost Lighting?

mako

Member
Hi, guys!

I'm still working on my MORTS space exploration game and I've run into a small problem: in 2d, the lack of back-lighting from stars makes the ships look like they're just stickered on over the scene (which, yeah, they are). I've seen a lot of methods for doing dynamic lighting with layers, but given the number of ships I'm running in-game, it seems like this might be really hard/expensive on the processing power for the machine the client is on.

Any thoughts on this, or alternatives I might be able to use to create dynamic lighting on my spaceships?

Edit: I have used shaders before (not remotely proficient with them, but comfortable trying). The main question here is whether it'll be more processor-friendly to use shaders or different method, when we're talking about 100+ ships needing dynamic lighting.
 
Last edited:

woods

Member
granted everything has a cost ;o) we just have to find the acceptable trade-off for performance/functionality that we can live with ;o)

with my scrubby noob programing skills, the first thing that comes to mind is maybe..
static objects with gradient alpha layers scattered about the level?
//as you get closer to center of one of these "holes in the alpha layer" your ship would get brighter.. giving the illusion of dynamic light? (would be better than just a ship sticker at least)
 

mako

Member
//as you get closer to center of one of these "holes in the alpha layer" your ship would get brighter.. giving the illusion of dynamic light? (would be better than just a ship sticker at least)
Interesting.... I'm not sure how that would work with the "level" design I'm using (it's a single map 64,000x64000, with dynamically placed objects based on distance to player) but it's DEFINITELY an interesting idea.....
 

woods

Member
dynamically placed objects based on distance to player
every so often drop one of these alpha holes into play.. when the player gets so far away, or after x amount of time passes, remove it

but the concept is there.. ;o)
 

mako

Member
I'm looking for something that will give sort of an "edge" lighting effect, to mimic the effect of the sun being only on one side of an object/ship/station, etc, based on the location of whatever sun is closest to the ships.

That's what I was hoping to hear, but I'm not shader-competent, yet. :) Any suggestions on where I should look for info on how to about doing it?
 
Expensive is relative to the hardware target and unless someone is trying to run it 10 year old integrated graphics nothing you do with the lighting and particle engine within reason should cause performance issues on a 2D game
 
I'm not really great at recommending a place to start learning from scratch.

I could help you accomplish a specific goal though.

If you want to go with normal maps, then you'll need a way to make your normal maps. I find them tedious to make by hand. So I'll either find a way to make them from a bump map, or else, I'll make a 3d model, and then create a normal map from that.

If you're going to use normal maps, you'll likely need a way to get certain pieces of data into your shader. Such as the "rotation" of your individual ship instances. What you don't want to do is set a uniform variable in between drawing every ship. One thing I've been doing that works pretty well is to encode data into the image_blend attribute. For example, I can map a 360 degree rotation to the range 0 to 255, and put the result in the red channel.
 

mako

Member
One thing I've been doing that works pretty well is to encode data into the image_blend attribute. For example, I can map a 360 degree rotation to the range 0 to 255, and put the result in the red channel.
So, if I understand this right, instead of passing the rotational information for every ship to the shader, you trick it by using the color as rotation? But the color of what?

Pardon my utter ignorance here; shaders blow my mind.
 
When you're drawing sprites normally they've got a property called "image_blend". Or when you draw a sprite using certain functions, there's a color argument. Inside of a shader, you can access those colors through the "in_Colour" vertex attribute. You don't actually have to use in_Colour for actual coloring. You can use it for any kind of data that you can fit inside of the four bytes allowed to in_Colour through the default vertex format. Each channel, rgba, is 1 byte. When you make a color in gml, you supply a value for each channel from 0 to 255. Inside the shader, that value is remapped to a range 0 to 1 (1=255).
 
Top