[SOLVED]Make node transp using other transp node|xray effect

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
user-r3
Posts: 70
Joined: Tue Dec 07, 2010 4:09 pm

[SOLVED]Make node transp using other transp node|xray effect

Post by user-r3 »

Hello,

first off: this may sound really dumb - it may be anyway...

Ok, I did achieve this previously, but later testing it (I don't know what I changed there..., from my Backups, it seems like I changed nothing, so I am probably observing the wrong properties...) it does no longer work.

What I want is the following: Let's say we have object A: a cube and object B a smaller (in diameter) circle (or even sphere, if you prefer)
B is given a texture with Alpha channel and it is in front of A (between the camera and A)
Obviously you can look through the transparent parts of B. Usually you would see A through it (this is happening now) - but earlier I somehow managed to see through A too, where B is transparent (this is what I want...)

As I have no idea, how it worked, not even how it is called, if it has a name, I am asking for help on how to achieve this (again), respectively, how I could have achieved it earlier.

thanks a lot in advance

user-r3
Last edited by user-r3 on Tue Feb 12, 2013 6:15 pm, edited 2 times in total.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Make node transparent using transp. node on top

Post by hendu »

Do you mean the X-ray glasses effect?

Image

(most SFW picture I could find ;))
user-r3
Posts: 70
Joined: Tue Dec 07, 2010 4:09 pm

Re: Make node transparent using transp. node on top

Post by user-r3 »

Haha, did not really think of that :mrgreen: , but yes something like that...

Is that possible or are you making fun of me... Well.. it must be possible because I achieved it earlier... (Maybe it was a bug in Irrlicht?)

Anyway, I am not trying to create x-ray glasses, but I want to use it for an optical sight on my gun, in my game. The perspective really looks bad with a correctly modelled sight (they are long tubes...) so this effect really worked like a charm^^ (RTT would work too, but consumes too much processing power.)

Thanks anyway for your reply :)

But this did not help me find, how to achieve this in irrlicht... I can only tell you, that it must have been done using vanilla methods, no shaders or anything like that...

Thanks in advance for any further help
STTrife
Posts: 33
Joined: Sun Jan 13, 2013 3:43 pm

Re: Make node transparent using node alpha on top (x-ray eff

Post by STTrife »

I guess something like that could happen when the rendering order is wrong. It should first draw the opaque object, and then the transparant one. If not then the z-test will make the part of the opaque object not drawn at all, which could indeed look like a hole. Problem with that is: it is not guaranteed that the rest of your scene IS drawn behind the transparant object.

I think to make x-ray you have to take control of the drawing order. First draw the scene, then draw the transparant object, then draw the opaque object. It will then not draw any parts of the opaque object which is behind the transparant object...

but I'm not expert at this... and I don't know HOW to exactly achieve this in irrlicht.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Make node transparent using node alpha on top (x-ray eff

Post by hendu »

You can do that by removing the node from the scene manager, and then calling render on it after smgr->drawall.

ie

node->grab
node->setparent(NULL)
...
loop {
smgr->drawall
specialsolidnode->render
}
user-r3
Posts: 70
Joined: Tue Dec 07, 2010 4:09 pm

Re: Make node transparent using node alpha on top (x-ray eff

Post by user-r3 »

Thank you very much for your interest!

@hendu

this really is a nice method, but is it possible to keep the parent of the node and still not render it in drawAll(), but via render()?


Thanks again and also thanks again in advance

user-r3
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Make node transparent using node alpha on top (x-ray eff

Post by hendu »

Only if the parent is also not in the scene manager. Otherwise the manager will render it in drawall.

edit: Or by making it invisible before drawall and visible before render.
user-r3
Posts: 70
Joined: Tue Dec 07, 2010 4:09 pm

Re: Make node transparent using node alpha on top (x-ray eff

Post by user-r3 »

hmm. ok, I tried your "edit", making the node invisible immediately bevore drawall, setting it to visible afterwards, before calling "render", but it is not showing at all... can you reproduce this error?

Thanks for your help anyway :)
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Make node transparent using node alpha on top (x-ray eff

Post by hendu »

Works for me. Maybe post your code.
user-r3
Posts: 70
Joined: Tue Dec 07, 2010 4:09 pm

Re: Make node transparent using node alpha on top (x-ray eff

Post by user-r3 »

After creating my weaponry I call:

Code: Select all

for (int i=0; i<weapons.size(); i++)
{
    // here are other methods with weapons[i]->
 
    weapons[i]->node->grab();
}
in my loop function I call:

Code: Select all

weapon->node->setVisible(false);
smgr->drawAll();
weapon->node->setVisible(true);
weapon->node->render();
where weapon is a pointer to the currently selected weapon in weapons[]

the weapon is not drawn at all... (but the lens of the sight, which is a seperate scenenode, and should cause the x-ray effect, is drawn... looks strange^^)
user-r3
Posts: 70
Joined: Tue Dec 07, 2010 4:09 pm

Re: Make node transparent using node alpha on top (x-ray eff

Post by user-r3 »

I'm sorry for bumping, but can nobody say why my code doesn't work?

Could you, hendu, post your working code, so that I may find a fatal difference?

Greeetz
user-r3

EDIT Nevermind, I finally found this thread:

http://irrlicht.sourceforge.net/forum/v ... hp?t=32045

which showed me how to do it, instead of my:

Code: Select all

weapon->node->setVisible(false);
smgr->drawAll();
weapon->node->setVisible(true);
weapon->node->render();
I have to replace the render and do the following:

Code: Select all

weapon->node->updateAbsolutePosition();
IMesh* mesh = weapon->node->getMesh();
driver->setTransform(video::ETS_WORLD, weapon->node->getAbsoluteTransformation());
for (unsigned int i=0; i<mesh->getMeshBufferCount(); ++i)
{
    scene::IMeshBuffer* mb = mesh->getMeshBuffer(i);
    if (mb)
    {
           const video::SMaterial& material = weapon->node->isReadOnlyMaterials() ? mb->getMaterial() : weapon->node->getMaterial(i);
           driver->setMaterial(material);
           driver->drawMeshBuffer(mb);
    }
}
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: [SOLVED]Make node transp using other transp node|xray ef

Post by hendu »

I suppose it was since I had nothing transparent in my simple test app, so the pass never changed to transparent. But yeah, taking more control works well too, like you found.
Post Reply