Stencil Glow Demo

A place to show off your latest screenshots and for people to comment on them. Only start a new thread here if you have some nice images to show off!
User avatar
Falagard
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2060
Joined: Thu Feb 26, 2004 12:11 am
Location: Toronto, Canada
x 3
Contact:

Post by Falagard »

It's better in the shader. A simple vertex program like this is no problem on the GPU, and if you use setScale you can't scale from the bounding box center and instead it will scale from the origin.
Slicky
Bronze Sponsor
Bronze Sponsor
Posts: 614
Joined: Mon Apr 14, 2003 11:48 pm
Location: Was LA now France
x 25

Post by Slicky »

How do you change the color of the shader?

I am getting a pale yellow. I haven't messed with shaders before. I was trying param_name color and a value with no effect.
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Post by Assaf Raman »

Slicky wrote:How do you change the color of the shader?

I am getting a pale yellow. I haven't messed with shaders before. I was trying param_name color and a value with no effect.
Open the ps_glow.cg file in a text editor.

This is what you will see:

Code: Select all

float4 main(uniform float alpha_value, uniform float time) : COLOR
{
   float4 color;
   color.x = 1.0;
   color.y = 1.0;
   color.z = 0.0;
   color.w =  alpha_value * ((sin(time * 5.0) / 3.14 + 1.0) / 2.0 );
   return color;
}
Play with the x,y,z to change the color. the values are in the range of 0 to 1.
The x,y,z are r,g,b. The w is the alpha.

Post a replay if you need more help.
Watch out for my OGRE related tweets here.
Slicky
Bronze Sponsor
Bronze Sponsor
Posts: 614
Joined: Mon Apr 14, 2003 11:48 pm
Location: Was LA now France
x 25

Post by Slicky »

Thanks that was it. I hadn't noticed the reference to ps_glow.cg and I was messing with values in the material file.
User avatar
Virion
Halfling
Posts: 85
Joined: Mon Jul 24, 2006 11:06 am
Location: Malaysia
x 2

Post by Virion »

this could be pretty useful.
sdragou
Kobold
Posts: 28
Joined: Tue Nov 15, 2005 3:11 pm
Location: Greece
Contact:

Post by sdragou »

I use the code posted and don't get the outline glow. Just the full glow.

It looks like the StencilOpQueueListener doesn't exsist.
Actually even when i don;t attach the StencilOpQueueListener i get the same result.
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Post by Assaf Raman »

I downloaded the latest OGRE (1.4.0) source. Then I downloaded my sample. Fixed it so it will compile and link with OSI - and - it worked fine.

I will try to help you.

Did the EXE demo worked for you?
What kind of GPU do you use?
Does it act the same both in openGL and in DX?
Can you try it on a different computer with a new GPU?
Does anybody else see the problem?
Watch out for my OGRE related tweets here.
sdragou
Kobold
Posts: 28
Joined: Tue Nov 15, 2005 3:11 pm
Location: Greece
Contact:

Post by sdragou »

The glow demo worked fine. I have an ati radeon 9700 GPU.

Maybe i don;t understand the use of stencil buffer correctly.

I create the renderqueuelistener where entites of group 90 make their stencil value 1 and of group 91 0.

and i attach this listener to rendersystem (like the code u gave).

is there something else needed to tell the system to overwrite the pixels with stencil value 0?

I'll post pictures when i find access to some server where i can place them.

Thnx in advance
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Post by Assaf Raman »

sdragou wrote:is there something else needed to tell the system to overwrite the pixels with stencil value 0?
You also need to clear the stencil buffer - like I do in the sample.
Watch out for my OGRE related tweets here.
sdragou
Kobold
Posts: 28
Joined: Tue Nov 15, 2005 3:11 pm
Location: Greece
Contact:

Post by sdragou »

I do clear the stencil buffer.

I post the code and a screenshot to help u help me :)
(Even though it's a copy of your code)

1) The renderqueuelistener

Code: Select all

// stencil values
#define STENCIL_VALUE_FOR_OUTLINE_GLOW 1
#define STENCIL_FULL_MASK 0xFFFFFFFF


class StencilOpQueueListener : public Ogre::RenderQueueListener 
{ 
public: 
	void renderQueueStarted(Ogre::uint8 queueGroupId, const Ogre::String& invocation, bool& skipThisInvocation) 
	{ 
		if (queueGroupId == 90) // 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 == 91)  // 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_ZERO,false);       
		} 
		

	} 

	void renderQueueEnded(Ogre::uint8 queueGroupId, const Ogre::String& invocation, bool& repeatThisInvocation) 
	{ 
		if (( queueGroupId == 91 )

			) 
		{ 
			Ogre::RenderSystem * rendersys = Ogre::Root::getSingleton().getRenderSystem(); 
			rendersys->setStencilCheckEnabled(false); 
			rendersys->setStencilBufferParams(); 
		} 
	} 

}; 
2) The attachment to the rendersystem

Code: Select all

mStencilOpFrameListener = new StencilOpQueueListener();
		mSceneMgr->addRenderQueueListener(mStencilOpFrameListener);

		mFrameListener= new StateFrameListener(mWindow,mGUIRenderer,mCamera,m_World,0,ex,data);
		mRoot->addFrameListener(mFrameListener);


3) The screenshot

the material "red" is just a red material.

Image

I get the same result as this screenshot even if i delete the lines below

Code: Select all

mStencilOpFrameListener = new StencilOpQueueListener();
		mSceneMgr->addRenderQueueListener(mStencilOpFrameListener);
User avatar
RichTufty
Gnoblar
Posts: 22
Joined: Fri Feb 16, 2007 6:03 pm

Post by RichTufty »

This looks great!! Has anyone ported this to C#? With Mogre?
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Post by Assaf Raman »

sdragou wrote:I do clear the stencil buffer.

I post the code and a screenshot to help u help me
(Even though it's a copy of your code)

1) The renderqueuelistener
...
Sorry I didn't replay until now; it is hard for me to tell what your problem is.
Can you post a small sample or change my demo so I will be able to see the problem?
Can anyone else help?
RichTufty wrote:This looks great!! Has anyone ported this to C#? With Mogre?
I haven’t heard about a port yet. (Surprise me guys… :D ).
Last edited by Assaf Raman on Mon Mar 10, 2008 1:46 am, edited 1 time in total.
Watch out for my OGRE related tweets here.
alhobarata
Kobold
Posts: 26
Joined: Tue May 09, 2006 7:43 pm

Post by alhobarata »

In your demo, if i comment the lines of creation of the full glow entities, the outline glow don't work properly. Why?
[img=http://img259.imageshack.us/img259/9784/ogresz2.th.jpg]
User avatar
RichTufty
Gnoblar
Posts: 22
Joined: Fri Feb 16, 2007 6:03 pm

Post by RichTufty »

I have now converted this to Mogre and C# ... !! I shall upload the code very soon if anyone is interested?... prob at the weekend!
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Post by Assaf Raman »

I am thinking of converting also this demo:
http://www.mvps.org/directx/articles/wipe/index.htm
to ogre.
This sample illustrates how to transfer an image mask to the stencil buffer, and utilizes this technique to perform a dynamic wipe between two 3D scenes.
Image Image

Does anyone needs a shaderless dynamic wipe?
Watch out for my OGRE related tweets here.
User avatar
saladin
Halfling
Posts: 43
Joined: Sat Nov 05, 2005 12:49 pm

Post by saladin »

Hi,
Thanks for the great work. I've been using this stencil glow technique in my project.

Now I'm having a bit of a problem.
Image

As seen in the screen shot.

The snowy terrain is in the farthest background, then the bus, then the tree.

The terrain is in the render queue group RENDER_QUEUE_MAIN, and so is the tree.

The bus, since it's highlighted, is in the render queue group RENDER_QUEUE_MAIN + 1. Its outline glow is in render queue group RENDER_QUEUE_MAIN + 2.

The tree's leaves are using the following material with an alpha texture.

Code: Select all

material tree4
{
	receive_shadows on
	technique
	{
		pass
		{
			ambient 0.500000 0.500000 0.500000 1.000000
			diffuse 0.086275 0.403922 0.062745 1.000000
			specular 0.100000 0.100000 0.100000 1.000000 0.250000
			emissive 0.000000 0.000000 0.000000 1.000000
			scene_blend alpha_blend
			depth_write off
			texture_unit
			{
				texture tree4_leaves.png
				tex_address_mode wrap
				filtering trilinear
			}
		}
	}
}
The bus shows through the tree leaves because the tree is being rendered ealier than the bus. If I set the tree's render queue to the same as the bus, the tree itself will be displayed properly. But the paradox is if I do that, the tree will occlude the glow of the bus. And if I do that for every unhighlighted object including the snow terrain, I'll never be able to see the outline glow of the bus.

If there any technique that can let me see the glow of the bus through the leaves and at the same time has the bus covered by the non-transparent part of the tree?

Following is my render queue listener code in python:

Code: Select all

class CGStencilOpQueueListener(ogre.RenderQueueListener):
    def renderQueueStarted(self, queueGroupId, invocation, skipThisInvocation):
        if (queueGroupId == RENDER_QUEUE_OUTLINE_GLOW_OBJECTS):
            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_GLOW):
            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_KEEP, False)

    def renderQueueEnded(self, queueGroupId, invocation, repeatThis):
      if queueGroupId == RENDER_QUEUE_OUTLINE_GLOW_OBJECTS or queueGroupId == RENDER_QUEUE_OUTLINE_GLOW_GLOW:
          renderSys = ogre.Root.getSingleton().getRenderSystem()
          renderSys.setStencilCheckEnabled(False)
          renderSys.setStencilBufferParams()
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Post by Assaf Raman »

post a small demo + code and I will fix it for you.
Watch out for my OGRE related tweets here.
User avatar
nullsquared
Old One
Posts: 3245
Joined: Tue Apr 24, 2007 8:23 pm
Location: NY, NY, USA
x 11

Post by nullsquared »

Interesting, great job!

I love using the stencil buffer... so many awesome uses... (I use it for my portals) The best part, Ogre wraps it all up in two amazing functions. No low-level direct D3D or GL needed :D
User avatar
OgreZenist
Gnoblar
Posts: 18
Joined: Wed Jun 20, 2007 11:20 pm

Post by OgreZenist »

Assaf Raman wrote:post a small demo + code and I will fix it for you.
Hi,
Thanks for the quick reply.

I'm using python-ogre. So you'll need python2.5 installed to run the code. However there's really no need to change any code from the demo you provided. Just replace the outline glow object (ogre head) with any entity with an alpha texture and with 'depthWrite off' to skip writing to the depth buffer. Then this object will stop occluding the glowing object behind it.

This is a detailed introduction of my problem:
http://www.ogre3d.org/phpBB2/viewtopic. ... highlight=

If you can run python-ogre code please tell me I'll quickly make a demo.

Cheers.
Once a direction is chosen, all you need to do is keep walking.
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Post by Assaf Raman »

OgreZenist wrote:
Assaf Raman wrote:post a small demo + code and I will fix it for you.
Hi,
Thanks for the quick reply.

I'm using python-ogre. So you'll need python2.5 installed to run the code. However there's really no need to change any code from the demo you provided. Just replace the outline glow object (ogre head) with any entity with an alpha texture and with 'depthWrite off' to skip writing to the depth buffer. Then this object will stop occluding the glowing object behind it.

This is a detailed introduction of my problem:
http://www.ogre3d.org/phpBB2/viewtopic. ... highlight=

If you can run python-ogre code please tell me I'll quickly make a demo.

Cheers.
I see.

A possible solution for you will be to draw the object twice – once with depth write, stencil write, and no color write, and once without a depth write, a color write and a stencil check.
Watch out for my OGRE related tweets here.
User avatar
saladin
Halfling
Posts: 43
Joined: Sat Nov 05, 2005 12:49 pm

Post by saladin »

A possible solution for you will be to draw the object twice – once with depth write, stencil write, and no color write, and once without a depth write, a color write and a stencil check.
Thanks I'll try that.
Zero
Halfling
Posts: 50
Joined: Mon Mar 10, 2008 12:08 am
Location: Stuttgart|Germany
x 1
Contact:

Post by Zero »

Hi,
Thanks for your good work. I want to use it in my project but I have a problem.

Image

As you can see here I want to use it with CEGUI. But you can see it don`t want to work correctly with CEGUI.
In the boxes and at the buttons is normaly text but as you can see it won`t be shown with stencil.
I don`t know why it won`t work.
I use the same code like you in your example.
I hope you can help me.

Zero
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Post by Assaf Raman »

@Zero: Just to make things clear - you want the text glowing?
Sort of like this?:
Image
Watch out for my OGRE related tweets here.
Shion
Gnoblar
Posts: 18
Joined: Thu Jul 28, 2005 5:21 pm

Post by Shion »

I work on the same project.

We don't want the text glowing.
We want the ogrehead glowing and this works.
The problem is, if we let glow the ogrehead all text from the buttons and other widgets are not shown.
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Post by Assaf Raman »

I see.
Can you add a gui sample to my sample in this thread and post the code - I will be able to look at the problem and solve it for you.
Watch out for my OGRE related tweets here.
Post Reply