Global Illumination-Esque Test

Hey. So, I was thinking about how to do a global illumination-styled feature in the BGE. Global Illumination is where objects are lit by surrounding textures or objects. It’s a nice, subtle feature - you can see it in effect in this image.


You see, the left wall is red, and the right is blue. The right sides of the spheres gets blue, and the left sides get red. My implementation is far worse, but still could be useful.

Now, it’s not possible to do this in the BGE by default, but I’m working on a very simplified version with node object that changes objects’ colors depending on how close each object is to the nodes. The results aren’t too bad.


Here’s a shot with the ‘light’ nodes not adding their color to objects.


The colors can mix between GI nodes, which is a nice feature. I still need to add a raycast to change the color of an object based on whether it can ‘see’ the node. While it doesn’t look nearly as good, it still has a little bit of an effect, and should be especially interesting in a more developed scene. It also runs very quickly - each of those shapes in the screenshots are getting illumination dynamically, and the script is running every frame.

EDIT: So, this would be most useful in an environment with dynamic objects, where you can’t spare lamps (like an indoor scene, for example), and with baked lighting. With this, you can make baked lighting seem like it’s giving off a little light.

Oh, and you can tweak some settings via game properties - the strength of the GI effect for each node, the color of the node, whether it’s additive or not, and the minimum and maximum distances for the GI effect to appear.

Wow! Very nice ideia.
Still needs work, but it is an excellent feature to add to the BGE.
With some SSAO thrown in it could look really good. (I can already see some proximity shadows near the corners)

I notice the blue backside of the cube in image 2.

I suggest to take the face normal into account. With that you might get a better backward facing.

Go Go!! Nice screens!

Thanks, guys.

You’re talking about the cube in the green area in my first image? The color’s not being adopted by the color of the texture or map - it’s coming from 3D objects in the area, so that cube’s most likely on the outskirts of the blue area, and in the green one (at least, that’s my guess). I already implemented a debug feature to show the limits of the nodes.


The yellow line is the outer limits of the node, and the orange is the inner limits. If objects exceed the yellow line in distance, they get no GI, and if they’re closer than the orange line, they get 100% GI. Of course, since it’s measuring the distance to the node, the shape of the node’s influence is circular, not a diamond.

I meant the blue box at the left. Leaves the impression it is blue-illuminated from the back. But the blue color is at the other side.
I think that is because of the object color.

Anyway, it is a cool idea.

Nice! I could see myself using something like this in a game.

But as Monster, said, it would be nice if you could get it to take face normals into account. Unfortunately, I think this is impossible to do right now(if we were able to pass unlimited per-object variables into custom shaders, then it would be possible).

Well, if you were really determined, I think there actually might be way to do it(without changing any of Blender’s source code), but it would be really complex and hackish. Probably not worth it.

I don’t think face normals would matter given that I’m altering the object.color variable, so the whole object gets tinted by the same color. I could use vertex colors, maybe, but I don’t think that would be fast enough for complex objects.

One thing that I really admire about the majority of your projects is the approach of “make do and adapt” that seems to pierce any attitudes of laziness or complaint. In this instance, you’ve taken what is easily acheivable, and implemented it within a much more complex concept. Well done SolarLune! It would be interesting to see how easy true Global Illumination would be after the rasterizer refactoring.

Yeah, you would need to make major changes to get it to account for face normals. Unfortunately, there isn’t a practical way to do it, as far as I can tell.

Still, it’s a neat idea. It could also be used to alter the ambient lighting of objects, like in a cave or building.

how is the frame rate with the script running?

Thanks, everyone.

@mrn - You can see that in the screenshots - 60 FPS with 18 or so objects being globally illuminated at the same time. The logic percentage is at around 4.9%. In truth, it would be faster if I implemented it to only influence objects’ colors if they actually appear onscreen.

Awsome! looks awsome to