clearZBuffer () after each render pass?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
agamemnus
Posts: 283
Joined: Sun Jan 31, 2010 6:06 pm

clearZBuffer () after each render pass?

Post by agamemnus »

I'm on 1.7.2, official. Is the z buffer cleared after each render pass? :?

(ie: skybox, to solid, to transparent, etc.)

Doesn't seem like it's cleared after the skybox render pass.
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Post by Radikalizm »

No, it isn't cleared after each render pass, why would it be?

Why do you need to clear your depth buffer after you rendered a skybox?
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

no the zBuffer is not cleared after each renderpass. Wouldn't make sense to clear the buffer after the solid pass and then render transparent stuff. it would be rendered ontop of everything(seeing stuff through walls). The skybox is rendered with zWrite disabled.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
agamemnus
Posts: 283
Joined: Sun Jan 31, 2010 6:06 pm

Post by agamemnus »

Sudi wrote:no the zBuffer is not cleared after each renderpass. Wouldn't make sense to clear the buffer after the solid pass and then render transparent stuff. it would be rendered ontop of everything(seeing stuff through walls). The skybox is rendered with zWrite disabled.
I am not sure that the skybox is rendered with zWrite disabled.

Assuming it isn't disabled, if your skybox is a plane or a sphere around the camera then it doesn't matter since there's no depth issue. My skybox is a table with a hint of ocean, though, and the zWrite does seem to be enabled. I use the code above to add a table model and a plane (the ocean) for my game. I can set the zbuffer or zwrite to on or off for either node.

I thought that the depth buffer was cleared because doing what is described above partially fixed my clipping problem. However, when I temporarily set zWrite to ON for some of the solid items, I noticed that I had z-fighting between the skybox and the solids.

Code: Select all

class CCustomPassNode : public scene::ISceneNode {
 irr::scene::IAnimatedMesh *mesh;
	E_SCENE_NODE_RENDER_PASS renderPass;

public:
       CCustomPassNode(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id, IAnimatedMesh *m, E_SCENE_NODE_RENDER_PASS pass)
                : scene::ISceneNode(parent, mgr, id), mesh(m), renderPass(pass) { 
	}
	virtual void OnRegisterSceneNode() {

  if (IsVisible) SceneManager->registerNodeForRendering (this, renderPass);
		ISceneNode::OnRegisterSceneNode();
	}

	virtual void render()	{
 	video::IVideoDriver* driver = SceneManager->getVideoDriver();
 	driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);

	 // Render original meshes.
  u32 meshBufferCount = mesh->getMeshBufferCount();
		for (u32 i=0; i < meshBufferCount; ++i) {
			scene::IMeshBuffer* mb = mesh->getMeshBuffer(i);
			if (mb)
			{
				const video::SMaterial& material = mb->getMaterial();
				video::IMaterialRenderer* rnd = driver->getMaterialRenderer(material.MaterialType);
				driver->setMaterial(material);
				driver->drawMeshBuffer(mb);
			}
		}
 }

	virtual const core::aabbox3d<f32>& getBoundingBox() const {
		return mesh->getBoundingBox();
	}

	virtual u32 getMaterialCount() const {
		return mesh->getMeshBufferCount();
	}

	virtual video::SMaterial& getMaterial(u32 i) {
		return mesh->getMesh(0)->getMeshBuffer(i)->getMaterial();
	}	
};

....

void * DLL_EXPORT IrrAddCustomPassMeshToScene (IAnimatedMesh* mesh, u32 passEnum, s32 id = 0) {
 return (new CCustomPassNode(smgr->getRootSceneNode(), smgr, id, mesh, (irr::scene::E_SCENE_NODE_RENDER_PASS)passEnum));
}

void DLL_EXPORT IrrRemoveCustomPassMeshFromScene (u32* node) {
 ((CCustomPassNode*)node)->drop();
}
Post Reply