Alpha trees and stencil glow.

Problems building or running the engine, queries about how to use features etc.
Post Reply
User avatar
OgreZenist
Gnoblar
Posts: 18
Joined: Wed Jun 20, 2007 11:20 pm

Alpha trees and stencil glow.

Post by OgreZenist » Tue Nov 20, 2007 1:27 pm

Hi,

I'm implementing a level editor for my game and I am using the stencil glow technique described in this thread to highlight selection. http://www.ogre3d.org/phpBB2/viewtopic. ... encil+glow

For those who's not familiar with it and doesn't wanna read through the source code, to put a long story short: This technique puts unselected objects in one render queue group (in the demo's case, the main render queue group), then the highlighted object is put in a render queue group after it , and then the actual stencil glow after the highlighted object.

During rendering the highlighted object render queue group, the stencil buffer is created. All the pixels of the highlighted object which passed the depth check are set to 1.
Image
By gigidigooz at 2007-11-20

And then when the actual outline glow object is rendered, it looks at the stencil buffer to exclude all the pixels with value 1. This creates the hollow inside the outline glow.
Image
By gigidigooz at 2007-11-20

The bit of code that does the above is as follows:

Code: Select all

		if (queueGroupId == RENDER_QUEUE_OUTLINE_GLOW_OBJECTS) // outline glow object 
		{ 
			Ogre::RenderSystem * rendersys = Ogre::Root::getSingleton().getRenderSystem(); 

			rendersys->clearFrameBuffer(Ogre::FBT_STENCIL); 
			rendersys->setStencilCheckEnabled(true); 
			rendersys->setStencilBufferParams(Ogre::CMPF_ALWAYS_PASS,
				STENCIL_VALUE_FOR_OUTLINE_GLOW, STENCIL_FULL_MASK, 
				Ogre::SOP_KEEP,Ogre::SOP_KEEP,Ogre::SOP_REPLACE,false);       
		} 
if (queueGroupId == RENDER_QUEUE_OUTLINE_GLOW_GLOWS)  // outline glow
		{ 
			Ogre::RenderSystem * rendersys = Ogre::Root::getSingleton().getRenderSystem(); 
			rendersys->setStencilCheckEnabled(true); 
			rendersys->setStencilBufferParams(Ogre::CMPF_NOT_EQUAL,
				STENCIL_VALUE_FOR_OUTLINE_GLOW, STENCIL_FULL_MASK, 
				Ogre::SOP_KEEP,Ogre::SOP_KEEP,Ogre::SOP_REPLACE,false);       
		} 

Now, if an unselected object is in front of the selected object. And if this unselected object happens to be set to 'depthWrite off', in the case of a billboard tree or glasses, then the selected object will not be correctly occluded from the depth check. It appears to jump to the front.
Image
By gigidigooz at 2007-11-19

I'm wondering if there's anyway to work around this problem so that the part of the bus behind the tree is occluded properly.

Cheers.
0 x
Once a direction is chosen, all you need to do is keep walking.

Post Reply