Sign in to follow this  

Early Z - How to?

This topic is 4343 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there, I've managed to push my geforce 5600 to draw a 20k scene mesh, with 5 materials, all using GLSL shaders, at 300 fps. I want to get it faster. I think I understand the concept of early z... 1. disable color writes / enable depth writes 2. render geometry 3. enable color writes / disable depth writes 3. render geometry by shader/material using the following code isn't working though...

	if(_cam!=NULL){
		_octree.DrawOcclusion(&_octree, &_world, _cam, 0);
		if(bShaders){
			//	render only z
			glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
			glDepthMask(GL_TRUE);
			_octree.DrawOctreeMesh( &_octree, &_world,_cam );

			//	now render scene by material
			int num		=	_world.pMaterials.size();
			int count;
			for(count=0;count<num;++count){
				//	render only color
				glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
				glDepthMask(GL_FALSE);
				_octree.DrawOctreeByMaterial(&_octree, &_world,_cam, count, 0);
				glDepthMask(GL_TRUE);
			}
		}
		else{
			_octree.DrawOctree_NoShaders(&_octree, &_world, _cam);
		}
	}
	else{
		int num		=	_world.pMaterials.size();
		int count;
		for(count=0;count<num;++count){
			_octree.DrawOctreeByMaterial(&_octree, &_world, NULL, count, 0);
		}
	}




Do I have to alter my shaders in some way to accomodate the early-z? Or am I doing the rendering routine incorrectly?

Share this post


Link to post
Share on other sites
that should work but its not the ideal method speedwise
u wanna lay down the depth pass first (of all solid geometry) for the whole scene in one go ie not continually changing states
also for extra speed (if theres a lot of occlusion eg a terrain with hills viewwed from FirstPerson) u will want to do occlusion tests whilst laying down the first depth pass (though on the nv3x this is broken but if u have >15% occlusion its still a win, on other cards eg nv4x> or ati its a win always)

Share this post


Link to post
Share on other sites
You should make sure that the second pass uses a depth comparison with less or equal. Otherwise your geometry will not be rendered as the depth buffer has already that Z value.

EDIT:
You should also move the glColorMask and glDepthMask calls out of the loop.

Share this post


Link to post
Share on other sites

This topic is 4343 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this