Hello,
I need to insert transparent object in other transparent object and so on (something like information cube).
When I insert "EMT_SOLID" object in "EMT_TRANSPARENT_VERTEX_ALPHA" object, it looks good. But when both of objects have material EMT_TRANSPARENT_VERTEX_ALPHA, one of them is drawn over the second (depends on which of them has its position closer to camera). So sometimes, inner object is drawn out.
Playing with ALLOW_ZWRITE_ON_TRANSPARENT did not lead to any result. I am usign OpenGL. What am I doing wrong? How would you implement information cube in Irrlicht?
Thanks
2 objects with material EMT_TRANSPARENT_VERTEX_ALPHA
-
speculatius
- Posts: 15
- Joined: Wed Nov 28, 2007 12:49 pm
you have to render the inner cube first. The easiest way to do that is to hide the outer cube and call it's node->render() function manually after smgr->drawAll()
(You may need to call a couple of other things too, like node->updateAbsolutePosition())
If you want to understand what's going on: when you draw a semi-transparent object, it renders like normal - checking each pixel to see if it is nearer to the camera than any object drawn so far, and if so, rendering itself there. This works for single transparent objects, but when you get 2 and the nearer one is rendered first, the second will think that it can't be seen at all, even though it can be seen through the first. If it tried to render anyway (possible to do by controlling zwrite) then it would have an odd effect where the inner cube looks like it is on top of the outer. The only way to fix this (in any 3d engine) is to force further objects to render first then work towards the camera, which is what irrlicht tries to do, but since your cubes are in the same place but different sizes irrlicht can't work out which is closer.
(You may need to call a couple of other things too, like node->updateAbsolutePosition())
If you want to understand what's going on: when you draw a semi-transparent object, it renders like normal - checking each pixel to see if it is nearer to the camera than any object drawn so far, and if so, rendering itself there. This works for single transparent objects, but when you get 2 and the nearer one is rendered first, the second will think that it can't be seen at all, even though it can be seen through the first. If it tried to render anyway (possible to do by controlling zwrite) then it would have an odd effect where the inner cube looks like it is on top of the outer. The only way to fix this (in any 3d engine) is to force further objects to render first then work towards the camera, which is what irrlicht tries to do, but since your cubes are in the same place but different sizes irrlicht can't work out which is closer.
-
speculatius
- Posts: 15
- Joined: Wed Nov 28, 2007 12:49 pm
Thank you for reply.
I think it is acceptable solution for most cases. I tried something like this and it looks working:
So the main loop will stay clear and I can simulate unlimited number of inner-levels.
I think it is acceptable solution for most cases. I tried something like this and it looks working:
Code: Select all
InnerCube::OnRegisterSceneNode() {
// do not register for rendering
}
// ...
OuterCube::render() {
foreach innerCube in childs {
innerCube->render();
}
renderMyself();
}