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
Contact:

Post by Falagard » Wed Jan 03, 2007 5:42 pm

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.
0 x

Slicky
Bronze Sponsor
Bronze Sponsor
Posts: 429
Joined: Mon Apr 14, 2003 11:48 pm
Location: Los Angeles, CA
x 1

Post by Slicky » Sat Mar 31, 2007 11:18 pm

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.
0 x

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

Post by Assaf Raman » Sat Mar 31, 2007 11:53 pm

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.
0 x
Watch out for my OGRE related tweets here.

Slicky
Bronze Sponsor
Bronze Sponsor
Posts: 429
Joined: Mon Apr 14, 2003 11:48 pm
Location: Los Angeles, CA
x 1

Post by Slicky » Sun Apr 01, 2007 12:26 am

Thanks that was it. I hadn't noticed the reference to ps_glow.cg and I was messing with values in the material file.
0 x

User avatar
Virion
Halfling
Posts: 84
Joined: Mon Jul 24, 2006 11:06 am
Location: Malaysia

Post by Virion » Sun Apr 01, 2007 6:40 am

this could be pretty useful.
0 x

sdragou
Kobold
Posts: 28
Joined: Tue Nov 15, 2005 3:11 pm
Location: Greece
Contact:

Post by sdragou » Tue Apr 03, 2007 3:25 pm

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.
0 x

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

Post by Assaf Raman » Tue Apr 03, 2007 7:51 pm

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?
0 x
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 » Tue Apr 03, 2007 11:08 pm

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
0 x

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

Post by Assaf Raman » Wed Apr 04, 2007 3:15 am

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.
0 x
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 » Wed Apr 04, 2007 8:21 am

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);
0 x

User avatar
RichTufty
Gnoblar
Posts: 22
Joined: Fri Feb 16, 2007 6:03 pm

Post by RichTufty » Thu Apr 05, 2007 1:46 pm

This looks great!! Has anyone ported this to C#? With Mogre?
0 x

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

Post by Assaf Raman » Thu Apr 05, 2007 9:09 pm

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.
0 x
Watch out for my OGRE related tweets here.

alhobarata
Kobold
Posts: 26
Joined: Tue May 09, 2006 7:43 pm

Post by alhobarata » Sun Apr 15, 2007 4:13 pm

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]
0 x

User avatar
RichTufty
Gnoblar
Posts: 22
Joined: Fri Feb 16, 2007 6:03 pm

Post by RichTufty » Wed Apr 18, 2007 4:53 pm

I have now converted this to Mogre and C# ... !! I shall upload the code very soon if anyone is interested?... prob at the weekend!
0 x

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

Post by Assaf Raman » Wed Apr 18, 2007 5:00 pm

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?
0 x
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 » Tue Nov 20, 2007 7:08 am

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()
0 x

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

Post by Assaf Raman » Fri Nov 23, 2007 1:53 am

post a small demo + code and I will fix it for you.
0 x
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

Post by nullsquared » Fri Nov 23, 2007 2:46 am

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
0 x

User avatar
OgreZenist
Gnoblar
Posts: 18
Joined: Wed Jun 20, 2007 11:20 pm

Post by OgreZenist » Sat Nov 24, 2007 12:44 pm

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.
0 x
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

Post by Assaf Raman » Sat Nov 24, 2007 3:47 pm

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.
0 x
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 » Tue Nov 27, 2007 1:21 am

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.
0 x

Zero
Halfling
Posts: 50
Joined: Mon Mar 10, 2008 12:08 am
Location: Stuttgart|Germany
Contact:

Post by Zero » Mon Mar 10, 2008 12:27 am

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
0 x

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

Post by Assaf Raman » Mon Mar 10, 2008 1:41 am

@Zero: Just to make things clear - you want the text glowing?
Sort of like this?:
Image
0 x
Watch out for my OGRE related tweets here.

Shion
Gnoblar
Posts: 18
Joined: Thu Jul 28, 2005 5:21 pm

Post by Shion » Mon Mar 10, 2008 7:46 am

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.
0 x

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

Post by Assaf Raman » Mon Mar 10, 2008 8:24 am

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.
0 x
Watch out for my OGRE related tweets here.

Post Reply