Static Lighting Generator 2

by DarkCampainger
Static Lighting Generator 2
Generate advanced soft-edge static lighting. Now using an EXE!
Adding them together should be correct. Maybe it's because the attenuation of the light's intensity is quadratic. Maybe it would look better if it was linear.
Yes, additive blending does seem to be the problem here. It almost makes it seem like the light sources cast shadows on other light sources while they fade out.
SuperAntx wrote:
Yes, additive blending does seem to be the problem here. It almost makes it seem like the light sources cast shadows on other light sources while they fade out.

That's the problem I'm trying to figure out. It seems like it's a problem with the attenuation. It looks like this is how the light's intensity drops as the distance from the light increases.

Because of how that curve is shaped, where the ranges of two lights overlap the darkest part is not halfway between them.
Here's linear attenuation and additive blending:

http://files.byondhome.com/DarkCampainger/LinearAdditive.png

The problem is still there, but it's definitely not as bad.
How exactly are you calculating the intensity at a given point? The fade should get more gradual as you get further from the light source but it appears to fade faster the further away you get.

I think I was wrong before. Quadratic attenuation would lessen this problem. But it appears as though attenuation is only part of it.
Here's the calculation used in the current release: (run for each light that reaches the point)
darkness -= (light->intensity - dist) * options->falloff * filter;

Where darkness is a value from 0-255, and filter is a value from 0-1 that provides the soft-shadows. falloff is set by the user, but defaults to 0.4, I think.
You should be dividing by the distance, not subtracting it.

You might also want to add some concept of vertical positioning of light sources. Attenuation is just the light's intensity fading over a distance. Even without that, the light's intensity will lessen as distance increases because the light is hitting the ground at a steeper and steeper angle (when you get further away from the light, fewer light rays are hitting the same pixel-sized area). You need a sense of vertical positioning to compute that angle.
Forum_account wrote:
You should be dividing by the distance, not subtracting it.

I tried that. It blends much nicer, but requires very high light intensity values to light even the smallest of areas, and creates star-like dots at the source:

http://files.byondhome.com/DarkCampainger/InverseBlended.png

It also takes a much longer time to generate, because of the high intensities increasing the light's range. I should probably separate light-casting range and brightness, at some point.

You might also want to add some concept of vertical positioning of light sources.

I was afraid it would come to that. I have to write a ray-tracer this quarter for classes anyway, so I can reuse some of that code. I think it's just a dot-product between the surface normal and the vector from the point to the light, though. As an added bonus, I could potentially add attenuation across walls, too.

Of course, I'll have to do all this after finals, so don't expect any updates for about 3 weeks...

You shouldn't need to change much. You only need the vertical position so you can compute the vector to the light source and the dot product. You can completely ignore it for visibility checks.

It might take longer to generate, but it'll look right :-)
Did you make these changes? The last image looks better.

You should consider adding some method to capture reflected light. If you look at the middle-right part of the first screenshot, there are crisp shadows at all different angles. The shadows are mathematically correct, but that's not how it would actually look. In reality, the amount of light that bounces off the walls, floor, and ceiling would illuminate the darker parts and soften things out.

Here are some links that might inspire you:
http://en.m.wikipedia.org/wiki/ Radiosity_(3D_computer_graphics)
http://en.m.wikipedia.org/wiki/Ambient_occlusion

Edit:
I was goofing around with these kinds of techniques and here are some images I came up with:

Basic Shadows (Plain Icons)
Ambient Reflections (Plain Icons)

You can see how areas with lots of overlapping shadows don't look oddly geometric, things get smoothed out. Areas that should be dark still are dark, but without the harsh contrast.
Forum_account wrote:
Did you make these changes? The last image looks better.

No, I haven't had any free time yet.

...

Edit:
I was goofing around with these kinds of techniques and here are some images I came up with:

Ambient Reflections (Plain Icons)

You can see how areas with lots of overlapping shadows don't look oddly geometric, things get smoothed out. Areas that should be dark still are dark, but without the harsh contrast.

Wow, that looks infinitely better. Can I ask how you generated those images? Are you just drawing them out, writing your own generator, or using an existing one?

It would be a shame to lose the ability to reuse tiles because of the increased complexity and uniqueness, but I would imagine most would prefer the smoother shadows to smaller file sizes. I guess I could always let the user specify the rendering scheme they want.
It generates shadows similar to what you're doing now (see the "Basic Shadows" image) and then uses that to generate another image. To compute the light's intensity at a point in the second image, you find all pixels that are visible from that point, then add up all the light values (from the first image) at all of those points.

Actually, it approximates this by just casting some random rays from each point. If I had more time to optimize it, I'd make it adaptively cast rays. It could check every 4th pixel in the center of the room, interpolate to get values at the pixels in between, and look fine because the center of the room is bright, there are no edges of shadows. It only needs to check every pixel where there's a lot of contrast.
Well damn; If you've already got it written up, you should release it. No point in me reinventing the wheel.

I'll go work on something else. Maybe a game, for once.
It's not exactly ready for release, and without some optimizing its a bit too slow. But if it'll make you go work on a game, maybe I'll release it.
Any idea how this would work versus non-Square dense objects?
Latoma wrote:
Any idea how this would work versus non-Square dense objects?

Poorly.
SuperAntx wrote:
Latoma wrote:
Any idea how this would work versus non-Square dense objects?

Poorly.

Yep. The current version doesn't have the "light shapes" needed to cast non-tile-sized shadows.

I'll see how FA goes about making his generator, and if I feel there's room for both of them, I'll add the last couple of features I have on my To-Do list.
I'm not sure how polished mine will be. I'll post the code for it at least, it's written in Java.

It works per-pixel. You give it a black and white image that tells it which pixels are opaque and it does the rest. I don't know how quickly your program runs but I'm sure mine will be slower. It has some options so you can play with the speed vs. quality tradeoff.
I posted the code for my lighting generator: http://files.byondhome.com/Forumaccount/shadow.zip

If you have any questions about it, just post on my forum: http://www.byond.com/members/Forumaccount/forum
Page: 1 2 3