Depth buffer pass, not using camera near/far clip planes

Problems building or running the engine, queries about how to use features etc.
las3rlars
Bronze Sponsor
Bronze Sponsor
Posts: 5
Joined: Tue Nov 11, 2025 10:07 pm
x 1

Depth buffer pass, not using camera near/far clip planes

Post by las3rlars »

Ogre Version: :14.4.1:
Operating System: :Linux:
Render System: :GL3:

I'm having difficulties understanding what I need to do, do get a depth pre-pass to use the cameras near and far plane settings.

Code: Select all

	auto depthText = Ogre::TextureManager::getSingleton().createManual(
		"DepthRTT",
		Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
		Ogre::TEX_TYPE_2D, getRenderWindow()->getWidth(), getRenderWindow()->getHeight(),
		0, Ogre::PF_DEPTH, Ogre::TU_RENDERTARGET);

Code: Select all

	scnMgr->setShadowTechnique(Ogre::ShadowTechnique::SHADOWTYPE_STENCIL_MODULATIVE);
	scnMgr->setShadowFarDistance(200.0f);
	scnMgr->setFog(Ogre::FOG_EXP, Ogre::ColourValue::Blue, 0.002f);
	scnMgr->setAmbientLight(Ogre::ColourValue(0.1f, 0.1f, 0.1f));
	scnMgr->setShadowColour(Ogre::ColourValue(0.7f, 0.7f, 0.7f));
	scnMgr->setShadowUseInfiniteFarPlane(false);

Code: Select all

	auto depthText = Ogre::TextureManager::getSingleton().getByName("DepthRTT");

auto* depthRT = depthText->getBuffer()->getRenderTarget();

auto depthCam = scnMgr->createCamera("depthCam");
depthCam->setNearClipDistance(10.0f);
depthCam->setFarClipDistance(200.0f);
depthCam->setAutoAspectRatio(true);
depthCam->setFOVy(cam->getFOVy());


camNode->attachObject(depthCam);

auto vp = depthRT->addViewport(depthCam);
vp->setClearEveryFrame(true, Ogre::FBT_DEPTH);
vp->setOverlaysEnabled(false);
vp->setShadowsEnabled(false);
vp->setSkiesEnabled(false);
vp->setBackgroundColour(Ogre::ColourValue::Black);
vp->setVisibilityMask(1u << 23);

I attached a image to the post showing the depth texture in render dock. The far plane when looking rgba output seems work as it should, it clips at 200 units. But in the depth buffer the whole scene is in 1.0 to 0.9680 range.

Any idea what could be wrong?

Image

hedphelym
Gremlin
Posts: 189
Joined: Tue Nov 25, 2008 10:58 am
Location: Kristiansand, Norway
x 23

Re: Depth buffer pass, not using camera near/far clip planes

Post by hedphelym »

I have the same on my end.
This also makes it tricky to use the depth buffer to make fog and other effects, since the values are as you say.
I have not figured out if it can be adjusted any better yet, I was hoping that I do not have to implement my own texture\shader for it - but that might be the way to solve it if you expect other values then what you have now.

paroj
OGRE Team Member
OGRE Team Member
Posts: 2274
Joined: Sun Mar 30, 2014 2:51 pm
x 1239

Re: Depth buffer pass, not using camera near/far clip planes

Post by paroj »

the depth buffer values are normalised. If you want to have world units, you have reverse this transformation:
https://paroj.github.io/gltut/Positioni ... ml#idp2563

las3rlars
Bronze Sponsor
Bronze Sponsor
Posts: 5
Joined: Tue Nov 11, 2025 10:07 pm
x 1

Re: Depth buffer pass, not using camera near/far clip planes

Post by las3rlars »

Thank you all for your time giving input! Yes, I expect them to be normalized. But the far end should be around 0 and near should be 1. But the distribution between 0 and 1 does not reflect what I think should be correct. If I check a value that is far away it should be closer to 0 and the near should be close to 1. I know it's not linear but it seems the far plane is extremely far away so all my geometry is in the 1.0 - 0.9680 range.

I will try later to see what values goes in when setting up the perspective matrix. Any hints on where I should set the breakpoint?

las3rlars
Bronze Sponsor
Bronze Sponsor
Posts: 5
Joined: Tue Nov 11, 2025 10:07 pm
x 1

Re: Depth buffer pass, not using camera near/far clip planes

Post by las3rlars »

I think I got it to work, not entirely sure but now my values are more what I would expect;

I switched to setting the depth-cam to use the values from usual cam using;

Camera::synchroniseBaseSettingsWith(const Camera* cam)

Now things are working more as expect.

Cheers