Render a plane mesh on top of a mesh that is clipped into it

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


knn217
Halfling
Posts: 78
Joined: Wed Jan 25, 2023 9:04 am
x 5

Render a plane mesh on top of a mesh that is clipped into it

Post by knn217 »

Hello, I have a main mesh and a plane mesh (the mesh's hurtbox) clipping into each other but I want the plane mesh to be rendered on top.

I've tried setting the main mesh's item 's renderqueue :

Code: Select all

Ogre::Item* mainItem = mSceneMgr->createItem(v2Mesh, Ogre::SCENE_DYNAMIC);  // Create an Item (v2mesh)
mainItem->setRenderQueueGroup(3);

mSceneMgr->getRenderQueue()->setRenderQueueMode(3, Ogre::RenderQueue::FAST);
mSceneMgr->getRenderQueue()->setSortRenderQueue(3, Ogre::RenderQueue::StableSort);

And the plane mesh's item's renderqueue:

Code: Select all

Ogre::Item* boxItem = mSceneMgr->createItem(v2boxMesh, Ogre::SCENE_DYNAMIC);
boxItem->setRenderQueueGroup(4);

mSceneMgr->getRenderQueue()->setRenderQueueMode(4, Ogre::RenderQueue::FAST);
mSceneMgr->getRenderQueue()->setSortRenderQueue(4, Ogre::RenderQueue::StableSort);

But the main mesh is still on top of the plane wherever the main mesh is sticking out. Did I miss a step? or does the renderqueue only work if there is no mesh clipping?

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5477
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1359

Re: Render a plane mesh on top of a mesh that is clipped into it

Post by dark_sylinc »

Hi!

I believe you mean you have two objects and one of them is always Z fighting with the other? (may be a picture would help, or diagram).

Anyway, while there are different interpretations of what you described, I suspect they all boil down to depth buffer: If Items A and B are rendered in any order, the depth buffer will try to guarantee they are rendered in the right order.

If B is supposed to always be on top of A, solutions are:

  • Render A first (you can control this with render queue IDs and sub group IDs). Turn off depth writes on A. Then render B.

    • The issue if that is A is a complex object, turning off depth writes may make A to not render correctly.

    • If an object C is rendered after A & B, then it may occlude A even if C is supposed to be behind it.

  • Render A first, then render B. B has depth checks off.

    • If B is a complex object, B may not render correctly.

    • If an object C is rendered after B, then it may occlude B even if C is supposed to be behind it.

  • Divide the pass in 2:

    1. Pass Scene rendering A

    2. Pass Scene rendering B; set load action to clear depth_stencil (only depth_stencil).

    • A bit overkill

    • If an object C is rendered after A & B, then it may occlude A even if C is supposed to be behind it.

  • Render A first. Then render a clone of B with a special material. Then render B again.

    • You'll need a custom shader piece

    • There are no rendering downsides.

Regarding that special material:

Code: Select all

hlms SpecialBDepthClear pbs
{
	depth_write     on
	depth_func      always_pass
	channel_mask    force_disabled
}

And you will need a custom VS piece :

PlayerOnTop_piece_vs.any:

Code: Select all

@property( player_depth_clear )
	@piece( custom_vs_posExecution )
		@property( hlms_no_reverse_depth )
			outVs_Position.z = outVs_Position.w - 1e-6f;
		@else
			outVs_Position.z = 0.0f;
		@end
	@end
@end

See the very recent Tutorial_Hlms02_CustomizationPerObj sample on how to add a custom shader piece to just one Item.

knn217
Halfling
Posts: 78
Joined: Wed Jan 25, 2023 9:04 am
x 5

Re: Render a plane mesh on top of a mesh that is clipped into it

Post by knn217 »

dark_sylinc wrote: Thu Dec 07, 2023 3:29 pm

Render A first, then render B. B has depth checks off.

  • If B is a complex object, B may not render correctly.

  • If an object C is rendered after B, then it may occlude B even if C is supposed to be behind it.

Thanks for the reply! This method worked for me! I only needed to add a macroblock with these options into my material.json file. The rendering not correctly doesn't bother me that much, since the hurtbox was supposed to be render over everything (even the terrain) anyway.

One thing is that I couldn't pull the Tutorial in your link, is it from another branch?

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5477
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1359

Re: Render a plane mesh on top of a mesh that is clipped into it

Post by dark_sylinc »

Yeah, it's in the ParticleFX branch. For various misc. reasons it's not on the main ones.

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5477
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1359

Re: Render a plane mesh on top of a mesh that is clipped into it

Post by dark_sylinc »

In case you're interested, I added two new tutorials (Tutorial_Hlms03_AlwaysOnTopA & Tutorial_Hlms04_AlwaysOnTopB) to the ParticleFX branch to show two of these techniques I described on how to render an object on top without being clipped.