BGE Graphics; using the new lamp data node for a different type of fade effect.

BGE_alphaExp.blend (627 KB)



NOTE: Might require a build newer than 2.69 to work as intended.

In recent months, not everyone may know it, but there’s been a new feature that was originally added for BI, but works in the BGE as well. This feature is called the lamp data node.

This feature can be quite useful in cases because you don’t actually have to have the lamp emitting light in the case you wanted to use it as a proxy object to hack around the fact that it has to be a lamp. In this file for example you will see that this is used to create an object fade out effect as the camera approaches the material (moving back and forth using ‘W’ and ‘S’).

The advantage of this is that now you can create a per-pixel fading effect for any material without having to resort to changing the object color and without having to write a custom GLSL shader.

Now you might wonder, why not the camera distance node, using the lamp data node means you get that nice round effect when approaching objects as well as the ability to reuse it for more than one camera (just teleport the lamp to the front of the other camera, providing that you did the lamp parenting in-game rather than in the viewport).

Also, as a bonus, this could be used for cases other than through use with the camera like X-ray vision.

Enjoy.

Excellent- thanks for the information! I wonder if there are any other hidden goodies lurking for us BGE users?

Awesome, I’ve been wanting something like this for a long time!
I also just noticed that at some point we got support for shadow maps and ObColor in custom shaders. Also, imageRender can now render a depth buffer to a texture, and you can use the native screen resolution instead of powers of two.

So in what release is that new node? I can’t find it anywhere.

@postmortem - Ace mentioned in his post that you’ll need a newer build than 2.69. Try a build from Graphicall, the Blender Buildbot, or building Blender yourself (if you have done so before).

@Ace - Really nice and cool-looking, but I see no such effect on my graphics card (AMD Radeon HD 7750 card). It’s just plain opaque. The other outputs seem to work, though. Looks like the distance output doesn’t work for AMD cards?

On the contrary, the screen was taken on a machine with an AMD card of the same generation as yours, so it might be a certain version of the drivers or something. (or maybe you didn’t clear the old drivers with the uninstall tool when you last upgraded).

Very nice!

How would one go about reversing the effect? Would it be able to make it fade in as you get closer?

You should just be able to add an invert node for that.

Either that or subtracting the value from 1 using an additional math node.

Also, as a bonus, this could be used for cases other than through use with the camera like X-ray vision.

I would like to use a similar setup in wrectified, in the ship exits tunnel scene,

Nice work ace.

Very nice!

How would one go about reversing the effect? Would it be able to make it fade in as you get closer?

has anyone used this with LOD levels?

Here’s a quick example of how fading out can work. Though it’s not really a lod as objects do exist, but are invisible, so you’d have to make a python script that checks if the whole object is faded out and then ends it or adds it if it’s not there and needs to appear at a certain distance.

edit: it looks better ingame than in viewport, you’ll need to add a camera with simple logic to see how it will actually look like.

Attachments

lodfadetest.blend (620 KB)

The Invert node worked! Thank you!