A hard-edged light without lights

I’m posting this less because I think that it’s impressive–although I am happy with it–than because I think that it might interest or amuse some here.

In a little side-game that I’m working on, I’ve decided to use only out-of-the-box features–in particular, I’m eschewing custom shaders. I’ve also settled upon a fairly simple, largely-unshaded art-style.

However, I have one area planned that I intend to have be dark.

Ideally, I’d like the player to be able to see only a little distance ahead of themselves. However, there is one exception: a particular part of the area that is illuminated, and thus visible at range.

And, again ideally, I’d like the light around the player to be somewhat hard-edged, both to fit with the art-style and to prevent pale objects from being too visible.

Now, I could use a standard point-light. But it seems to be very difficult indeed to make such a light hard-edged; I did come up with a possible solution, but was dubious of it.

I considered trickery with texture projection, or texture-stage blending, or spotlights–but none of these seemed like good solutions to me. (At least without significant additional work.)

Then a much simpler idea came to me: I could simply place a large, black, inverted sphere over the player to serve as the “darkness”–or better yet, two such spheres, one opaque and the other semi-transparent!

The illuminated area, then, could be handled by placing the illuminated area in a custom culling-bin ordered after that of the “darkness spheres” and disabling depth-writing on the latter. This would cause that area to render after the “darkness spheres”–and because the spheres wouldn’t be writing to the depth-buffer, it would render over them, giving the impression of light in the darkness! :slight_smile:

I tried it out–and it works, and indeed I’m quite satisfied with the result! :slight_smile:

Here’s the effect in action:

I was wondering if you were thinking about dark-colored fog on a cut-off plane.

If you set the slice on the far plane here, and select a color . Then, I think, the picture will be more pleasant.

I hadn’t thought of that! That’s not a bad idea! :slight_smile:

I’m not quite sure of what you mean by “a cut-off plane”, or to “set the slice on the far plane”–could you elaborate, please?

That said, would a distant, well-lit area show through the “fog”? (As seen in the second gif above.)

I was referring to the linear drawing range.

I think that I understand you: you’re simply talking about the distance at which the fog takes effect, yes?

Yes, but you need to experiment with the settings.

Fair enough.

But as I said, I’m dubious that the well-lit area would show through the fog. Am I mistaken in that?

[edit] Also, I quite like the two-stage nature of the lighting in my technique, which fog would presumably not replicate.

Hmm the Panda has a problem, the fog missing the back clip of the space. It should be like a camera.
At the moment, You can get something like this, but it’s not the way you wanted it to be.

Glad that you have found the soultion, but why not use a shader? Just use regular panda light inputs and if the light is in the range, mix in light colour. But maybe I am missing something, I am not good at shaders yet.

Looking at the API, it seems that it only respects the start- and end- distances if its mode is set to “M_linear”. The API seems to indicate that it should work with that mode, however…

It’s a decision that I took specific to this project: I intend to use only out-of-the-box rendering for it.

Creating this effect with a shader would indeed be quite easy, I do believe.