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!
I tried it out–and it works, and indeed I’m quite satisfied with the result!
Here’s the effect in action: