Transparency?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Lorian
Posts: 20
Joined: Sat Feb 10, 2007 9:20 am
Location: United Kingdom
Contact:

Transparency?

Post by Lorian »

Hi folks,

How would I go about making a scene node transparent when the camera goes near it. I.e., it fades away to tranparent as I get near to it, and is completely transparent as I am about to intersect it.

Cheers.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

First, get the distance from the camera.

This is easily done by node->getPosition().getDistanceFrom(camera->getPosition());

Then use this scalar value to interpolate making the node transparent. There are two methods for making the node transparent and both are described here:
http://irrlicht.sourceforge.net/phpBB2/ ... ansparency

If you are familiar with shaders I recommend just writing one that takes the World position of both the camera and the object and uses this value to interpolate the alpha value of the pixels in the pixel shader. NOTE: In Irrlicht to use transparency in shaders you usually have to set the Base Material of the shader to EMT_ALPHA_TRANSPARENT_ALPHA_CHANNEL.

Cheers

- BlindSide

EDIT: Oh wait, it would probably just be faster to pass the actual distance to the shader.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Post Reply