[Solved: I am a Moron] Lighting, Shadows, Illumination. But not raycasting.

9 posts

Flag Post

I want to do this in a simple-to-create way. My A* maps generate themselves based on the map layout I have (so array painter kind of functionality, built into the game itself; the generation time is pretty insignificant 2-4 ms per level).

What I’d like to add is a lighting layer. Or rather, a shadows layer that is overlayed on top of the level and then masked out by the torches.

I can add a movieclip above everything that is black easily enough, but I don’t want to go in and manually apply mask objects above every torch. Which…even that is very difficult, as you can’t mask an object being used as a mask (Flash just says “f&ck you” and ignores it).

I don’t need raycast light here, just really basic halos that don’t care about walls, ah la retro RPGs:

That game was a stealth area (stay out of the light) whereas the effect I want is similar, except that the areas of shadow are effectively invisible (covered in darkness). I just don’t want to hand-build 30+ shadow layers!

 
Flag Post

And then I says to myself, “Me, did you think about BlendMode.ERASE?”

“I,” I reply, “I had not. Shall we try it?”

And it was glorious.

 
Flag Post

You could use multiply for an even more organic and flexible effect.

 
Flag Post
Originally posted by qwerberberber:

You could use multiply for an even more organic and flexible effect.

Fiddles

Good call. Good call.

Have to use SCREEN on the halos if they’re going to have a blended edge, but the parent clip as multiply works vunderbar.

Not that the shadows are going to start off that dark, but it makes a good test. And I see I need to move some torches around!

 
Flag Post

And then I says to myself, “Me, did you think about BlendMode.ERASE?”

BlendModes are ungodly slow. You’d seriously better be caching this lightmap.

 
Flag Post
Originally posted by truefire:

And then I says to myself, “Me, did you think about BlendMode.ERASE?”

BlendModes are ungodly slow. You’d seriously better be caching this lightmap.

Depending lights he might not need to, plus I’m guessing that most of the lights are dynamic too :P

 
Flag Post

Caching as bitmap will happen. This stuff is remarkably static. I just didn’t want to hand-craft them all! XD

 
Flag Post

Alright what gives? I want to have increasing alpha on some levels so that the transition from “well lit” to “not” isn’t harsh.

Here’s what it looks like when I set things up manually:

Here’s what it looks like when I do the same exact thing through code:

I can’t even get that result manually no matter what I try!

Manual setup:
Add shadow movieclip, set blend mode to Multiply and alpha to 50%.
Add torch illumination pieces into shadow MC, set each ones blend mode to screen.

Code:

shadows = new Shadows();
shadows.blendMode = BlendMode.MULTIPLY;
shadows.alpha = .5;
shadows.cacheAsBitmap = true;
addChild(shadows);
var t:TorchIllum;
var m:DisplayObject;
i = 0;
do {
	m = this.getChildAt(i);
	if(m is Torch) { //screw giving them instance names :|
		t = new TorchIllum();
		shadows.addChild(t);
		t.blendMode = BlendMode.SCREEN;
		t.x = m.x;
		t.y = m.y;
	}
	++i;
} while(i < this.numChildren);

Left out the chunk where it adds another “light” for the up and down stairs, just because it’s effectively duplicate code.

 
Flag Post

Slight increase in acceptability. Apparently “cache as bitmap” on parent objects of things that have not-blendmode-layer ends poorly.

So I removed the chacheAsBitmap = true.

Now the lighting is rendering correctly…but not brightly:

The upper left corner is an illumination circle that is hand-placed and appears to have all the same settings as the code-placed ones: not cached as bitmaps, blendmode-screen, alpha 100%.

OMFG, I’m such a dumbass. I had a second copy hand placed into that floor. Jesus Christ, that cost me like two hours.

I was all “what the hell is going on?” because everything I did did Weird Shit (the halo in the upper left worked correctly because there were two copies of it, when I moved one around, it made two “faint” versions and I was beginning to think Flash was caching layering results and somehow duplicating the original state and layering it under the new state).

Wasn’t until I went “Fuck it, don’t add the shadow mc to the stage” that I figured out what was going on.