[2.1] Trouble with transparent objects. Topic is solved

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Post Reply
Jay721
Halfling
Posts: 62
Joined: Mon Jan 29, 2018 8:19 am

[2.1] Trouble with transparent objects.

Post by Jay721 »

Silly issue. I'm trying to make something semi-transparent but having some trouble... I get the object's HlmsPbsDatablock and do this

Code: Select all

block->setTransparency(0.1);
Instead of seeing the things behind the object, I am simply seeing the scene's clear colour. This line of code worked as expected in a previous project with Ogre so I'm a little confused.

thanks.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: [2.1] Trouble with transparent objects.

Post by dark_sylinc »

Picture?
Jay721
Halfling
Posts: 62
Joined: Mon Jan 29, 2018 8:19 am

Re: [2.1] Trouble with transparent objects.

Post by Jay721 »

dark_sylinc wrote: Wed Feb 06, 2019 4:34 amPicture?
Hi, here's an example. I've discovered that the issue only occurs when the big red cube is scaled above 42x42x42.

42x42x42 cube in background:
Image

42x42x43 cube in background:
Image
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: [2.1] Trouble with transparent objects.

Post by dark_sylinc »

Ahhhh. Now it makes sense.

Ogre uses the AABB size and distance to camera to determine which object is in front of which; as transparents must be drawn back to front for correct alpha blending.

However when one big object acts as "the room" like in your example, these approximations can easily break; because it think the room is closer to the camera and should be rendered last (and that's wrong, it should be rendered first).

The solution is to place the big object enclosing everything into a lower render queue; so that you're controlling the order manually. ie. for "the room" call setRenderQueueGroup( 0 ); and for the rest of the items call setRenderQueueGroup( 2 ); (we skip 1 because that's where usually v1 Entity go by default, but you can use 1 if you have no v1 entities)

Make sure you call sceneManager->getRenderQueue()->setRenderQueueMode( 2, RenderQueue::FAST ); before doing any of this, to set render queue group #2 to accept v2 objects.

Cheers
Matias
Jay721
Halfling
Posts: 62
Joined: Mon Jan 29, 2018 8:19 am

Re: [2.1] Trouble with transparent objects.

Post by Jay721 »

dark_sylinc wrote: Sun Mar 03, 2019 11:56 pm Ahhhh. Now it makes sense.

Ogre uses the AABB size and distance to camera to determine which object is in front of which; as transparents must be drawn back to front for correct alpha blending.

However when one big object acts as "the room" like in your example, these approximations can easily break; because it think the room is closer to the camera and should be rendered last (and that's wrong, it should be rendered first).

The solution is to place the big object enclosing everything into a lower render queue; so that you're controlling the order manually. ie. for "the room" call setRenderQueueGroup( 0 ); and for the rest of the items call setRenderQueueGroup( 2 ); (we skip 1 because that's where usually v1 Entity go by default, but you can use 1 if you have no v1 entities)

Make sure you call sceneManager->getRenderQueue()->setRenderQueueMode( 2, RenderQueue::FAST ); before doing any of this, to set render queue group #2 to accept v2 objects.

Cheers
Matias
The smaller cubes shown in my example aren’t actually inside of the bigger object, so it isn’t really acting as a room.

The big cube is definetly behind the smaller objects, with no intersection and room to spare, so why does Ogre struggle to determine what’s in front of what?

Thanks for your solution though, it worked but I’m not sure if it’s gonna be fine for multiple “big” objects that have transparency?
hyyou
Gremlin
Posts: 173
Joined: Wed Feb 03, 2016 2:24 am
x 17
Contact:

Re: [2.1] Trouble with transparent objects.

Post by hyyou »

Roughly speaking, for a certain Ogre::Item, Ogre approximately uses its vertex position that is nearest to the camera - to do dept sort.
Ogre doesn't use the center of Ogre::Item to sort. This can cause glitch in some scenes (including my scene).

Are you sure that such vertex of the big cube is far from camera more than such point of a smaller one?
Depth bias may help, but I have never tried it.
Post Reply