Enable depth sorting on Ogre 2.0

Discussion area about developing with Ogre2 branches (2.1, 2.2 and beyond)
Post Reply
white_waluigi
Goblin
Posts: 253
Joined: Sat Sep 28, 2013 3:46 pm
x 10

Enable depth sorting on Ogre 2.0

Post by white_waluigi »

I'm still working a Deferred Shading pipeline and got basic lighting to work:
http://i.imgur.com/uzFS6HS.jpg?1

But currently I have a Problem with transparency.
The Light-Geometries used are Alpha blended meshes which need to be alpha sorted in order to work correctly. But unfortunatly that doesn't seam to work for some reason (maybe becuase I put all Light Geometries into the 0x00008000 renderqueue),
So as you can see in the picture, the alpha blended abjects are overlapping.

So how can I enable them for alpha sorting?
Also is there a way to force the LightGeometry for the Dirtectional Light to always be rendered last?
Because It is a quad that is always rendered directly in front of the camera using the vertex shader.
Its world position is always 0,0,0.
So I need to manually change it.

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

Re: Enable depth sorting on Ogre 2.0

Post by dark_sylinc »

Well... you shouldn't need proper sorting because the light mode for the light geometries should be add, not alpha blend, which is order-independent.

But anyway:

I assume you're talking about 2.1 and not 2.0.
The render queue sorts by distance to camera back to front when a transparent material is used. I see two things that may go wrong though:

1. In OgreRenderQueue.cpp you'll see the line:
bool transparent = datablock->mBlendblock[casterPass]->mIsTransparent;
'transparent' should obviously be true. Otherwise the RenderQueue won't sort by distance first. If it's false, debug why it's not.

2. The AABB is faulty. The RenderQueue uses pMovableObject->getCachedDistanceToCamera(); to calculate the distance to camera and sort. The center of the world AABB and the radius (which are derived from mLocalAabb and mLocalRadius) are used for that. If any of them are faulty (e.g. you're using an infinite AABB or radius) the sorting will not go as planned.

3. 15 bits is not enough for sorting. RqBits::DepthBits is set to 15; and may not be enough for your needs. Increasing it is a little painful because you have to take away bits from others and make sure you don't break a few assumptions (e.g. do not change RqBits::ShaderBits, keep it at 10!)

white_waluigi
Goblin
Posts: 253
Joined: Sat Sep 28, 2013 3:46 pm
x 10

Re: Enable depth sorting on Ogre 2.0

Post by white_waluigi »

Ok; I'm gonna check that tomorrow, It probably is a faulty AABB.
Also I do indeed use ADD Alpha Blending, which makes me wonder why it doesn't work.

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

Re: Enable depth sorting on Ogre 2.0

Post by dark_sylinc »

My guess the blendblock is not set correctly.

I've seen the mistake once of setting the HlmsBlendblock::mBlendblock to a pointer that was not created via HlmsManager::getBlendblock and for some reason the app still worked without crashing but of course the look was wrong.

RenderDoc can help in determining what blend mode is actually being used.

white_waluigi
Goblin
Posts: 253
Joined: Sat Sep 28, 2013 3:46 pm
x 10

Re: Enable depth sorting on Ogre 2.0

Post by white_waluigi »

Heres the code responsible for setting the blendblock, I think its ok:

Code: Select all

	Ogre::HlmsBlendblock  templ;
		templ.setBlendType(Ogre::SBT_ADD);
		const Ogre::HlmsBlendblock * blendblock = this->hlmsman->mHlmsManager->getBlendblock(templ);
		Ogre::HlmsMacroblock mtempl;
		mtempl.mCullMode = Ogre::CULL_ANTICLOCKWISE;

		const Ogre::HlmsMacroblock* macro = this->hlmsman->mHlmsManager->getMacroblock(mtempl);



		lightmaterial =
				static_cast<Ogre::LightDatablock*>(this->hlmsman->createDatablock(
						Result + "Light_Material", "Light_Material", *macro,
						*blendblock, params));

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

Re: Enable depth sorting on Ogre 2.0

Post by dark_sylinc »

You're passing the macro and blendblocks by value and not by pointer.

That means you could do this:
Ogre::HlmsBlendblock templ;
templ.setBlendType(Ogre::SBT_ADD);
Ogre::HlmsMacroblock mtempl;
mtempl.mCullMode = Ogre::CULL_ANTICLOCKWISE;

lightmaterial =
static_cast<Ogre::LightDatablock*>(this->hlmsman->createDatablock(
Result + "Light_Material", "Light_Material", mtempl,
templ, params));
And what matters is that inside createDatablock getMacro-/Blend-block are called and the returned pointers reach safely to your constructor and passed to the HlmsDatablock constructor.

By calling getMacro/Blendblock then pass by value you're just slowing it down (by doing pointless lookups) and increasing the internal reference count without releasing it (object will leak until shutdown; unless you call destroyMacro/Blendblock to decrease the reference count, and destroy the object if the ref. count reaches 0).

white_waluigi
Goblin
Posts: 253
Joined: Sat Sep 28, 2013 3:46 pm
x 10

Re: Enable depth sorting on Ogre 2.0

Post by white_waluigi »

Yeah i just figured its the only way to egtBlendBlock
I'll check create Datablock

white_waluigi
Goblin
Posts: 253
Joined: Sat Sep 28, 2013 3:46 pm
x 10

Re: Enable depth sorting on Ogre 2.0

Post by white_waluigi »

I set the depth compare to always Pass, it seams to work fine for now, I hope it works.

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

Re: Enable depth sorting on Ogre 2.0

Post by dark_sylinc »

Oh that's right. When you're doing ADD blending, you still need to disable depth testing. I suggest setting mDepthCheck = false; instead of setting the compare to always pass, but it basically achieves the same result.
The difference is that always pass will write the depth to the depth buffer while disabling depth check will not (it basically disables all depth buffer operations).

white_waluigi
Goblin
Posts: 253
Joined: Sat Sep 28, 2013 3:46 pm
x 10

Re: Enable depth sorting on Ogre 2.0

Post by white_waluigi »

Did that works perfectly.
i forgot that depth checks are not needed with light Geometry.
I hope that doesn't mess with forwarded obejcts

Post Reply