How to show a glow around characters?

Problems building or running the engine, queries about how to use features etc.
User avatar
fassihi
Goblin
Posts: 215
Joined: Sat Sep 16, 2006 6:51 am
Contact:

How to show a glow around characters?

Post by fassihi » Fri Oct 20, 2006 4:08 pm

I have some characters in a scene and I will select these characters using the mouse, now what I need is for the selected characters to look different from the un-selected ones. Some kind of glow around them would be nice.. most of the games to this I guess..

What would be a good approach for creating such effect around the characters?
0 x

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 » Fri Oct 20, 2006 4:37 pm

Depends on the exact effect you want.

What I've done in the past render the scene, then enable the stencil buffer and render the selected object into the buffer, then render the selected object again but scaled slightly (be sure to scale from the center of the bounding box, not necessarily the object's origin) with a different material (such as a translucent color) and use the stencil to only make it render where the stencil doesn't exist. This will create a glow outline.

I've also tried by using a vertex shader to "grow" the object by moving its vertices outwards along the lines of the normals but this doesn't work when you have multiple materials for an entity since it breaks apart where the geometry is different and has problems with sharp edges where the normals point in opposite directions.

There are lots of other ways to do the same thing as well though, probably techniques involving render to texture. For example, I can imagine clearing the render texture to black, scaling the object as above, render scaled version a color (into render target), blur the render texture using technique similar to how bloom is done in compositor, then render the original object black with depth testing disabled. This will give you a texture with the glow outline, then render this texture into the scene at the exact position of the original. Tricky to get them to line up, you might want to look at Tuan Kurane's impostor code available on his site for how to set this up.

In fact, the compositor itself might have techniques you could do this if you're willing to render full screen texture. Lots of options available.
0 x

User avatar
zap
Greenskin
Posts: 135
Joined: Mon Jul 04, 2005 12:14 am
Location: St. Petersburg, Russia
Contact:

Post by zap » Fri Oct 20, 2006 10:55 pm

You can just clone the entity, assign it a translucent material, scale it a little larger and attach to the same scene node. When you don't need selection anymore, you destroy it. This will paint over the selected object as well, but this looks ok since it makes the object "look different" too.
0 x
Andrew

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 » Fri Oct 20, 2006 11:04 pm

Yup, can do that too but it kinda looks like crap :-)
0 x

User avatar
fassihi
Goblin
Posts: 215
Joined: Sat Sep 16, 2006 6:51 am
Contact:

Code

Post by fassihi » Sat Oct 21, 2006 6:27 am

Thanks for the detailed information Falagard... however since I am new to Ogre programming, are there some code examples that would do similar things.. for example how do you render and object into the stencil buffer?
0 x

User avatar
zap
Greenskin
Posts: 135
Joined: Mon Jul 04, 2005 12:14 am
Location: St. Petersburg, Russia
Contact:

Post by zap » Sat Oct 21, 2006 3:28 pm

Falagard wrote:Yup, can do that too but it kinda looks like crap :-)
It will look as if you would enclose the object into a glass container... or into a lump of ice. All depends of your imagination :-)

Well, that's the simplest option and since the guy is quite new with Ogre that would be easy for him to do...
0 x
Andrew

Stickymango
Hobgoblin
Posts: 540
Joined: Wed Nov 17, 2004 4:36 pm
Location: Middlesbrough, England

Post by Stickymango » Mon Oct 23, 2006 12:45 pm

Couldn't he assign it a lower render queue so it is rendered before the full textured version...?
0 x

User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
Contact:

Post by jacmoe » Mon Oct 23, 2006 3:58 pm

This doesn't have to be complex at all.
Just assign a different material to the entity while it's selected. Then revert back to the old one when it's not selected anymore:
http://www.ogre3d.org/phpBB2/viewtopic. ... ahs#179516 :wink:
0 x
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.

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 » Mon Oct 23, 2006 4:43 pm

True, doesn't have to be complex if he's willing to go with a simple solution. Easiest is to just switch the material as Jacmoe said. He asked about a glow around the character which I interpretted to mean... well a glow around the character. Glows are a lot more complex than just changing the material, so I'd suggest if you're a new Ogre user to go with the simple approach until you're more familiar with Ogre.
0 x

User avatar
nebukadnezzar
Halfling
Posts: 93
Joined: Sun Jun 11, 2006 4:40 pm
Location: Germany
Contact:

Post by nebukadnezzar » Mon Oct 23, 2006 8:07 pm

Falagard, can you give a hint how you would apply a glow/aura to a mesh?
0 x

User avatar
dfacchin
Greenskin
Posts: 105
Joined: Fri May 13, 2005 10:11 am

Post by dfacchin » Mon Oct 23, 2006 10:52 pm

If u don't want a glow on the char but just a way to show that it's selected, u can use billboards, like a circle attached to at the feets point

maybe this image is better than words

Image

look at the priest

hope it can be useful
0 x

User avatar
nebukadnezzar
Halfling
Posts: 93
Joined: Sun Jun 11, 2006 4:40 pm
Location: Germany
Contact:

Post by nebukadnezzar » Tue Oct 24, 2006 7:38 am

dfacchin wrote:If u don't want a glow on the char but just a way to show that it's selected, u can use billboards, like a circle attached to at the feets point

maybe this image is better than words

look at the priest

hope it can be useful
yes this first come to my mind,
but how can i show an voluminous glow around an object?
(not in the "real" shape of the object - so not resizing the object )
Last edited by nebukadnezzar on Tue Oct 24, 2006 7:40 am, edited 1 time in total.
0 x

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 » Tue Oct 24, 2006 7:40 am

Falagard, can you give a hint how you would apply a glow/aura to a mesh?
See my first post on this thread with fairly detailed instructions?
0 x

User avatar
dfacchin
Greenskin
Posts: 105
Joined: Fri May 13, 2005 10:11 am

Post by dfacchin » Tue Oct 24, 2006 8:22 am

I think u recived some good hint, but if u need a step by step tutorial here I try:
Let's try to make a cylinder appear around the selected object

Suppose u have the chara, u take it's scenenode and make a child out of it
Now that u have the scenenode u need to attach an object to it:
this object can be:
the billiboard (like I posted in the figure) so the scenenode has to be attached to it's parent at the bottom of the figure
a mesh with the right material to make it glow, so a cylinder or a resized mesh of the player with a different material, the material has to be "trasparent" to let u see trought it, if u use the cylinder it would be fun to use a texture (with alpha blending.. I'm right guys???) made with a noise generator(so perlin noise I guess) and make it rotate/move, so it would look like some kind of fog is around ur player....

and of course there still the easiest way that is just to change the character material.
0 x

User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
Contact:

Post by jacmoe » Tue Oct 24, 2006 4:43 pm

Keep in mind that a material script can contain shaders, which should make it possible to add a glow effect to whatever you submit your material to.
Shaders can (and do) modify both pixels and vertices.
The only problem would be to find that (or rather: those) shader scripts - or even write them yourself. :)

So, I still stand by my suggestion: use a simple material switch.
The material doesn't have to be simple though the switch is. :wink:
0 x
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.

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 » Tue Oct 24, 2006 5:38 pm

Here's a screenshot of the glow we implemented in MyVirtualHome using the stencil buffer technique I described above.

Image

Again, this particular glow implementation is complicated and not for newbies ;-)

Sorry about the advertising at the bottom of the screenshot, it is embedded in the img.
0 x

User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
Contact:

Post by jacmoe » Tue Oct 24, 2006 8:42 pm

Looks great! :D

Wouldn't it be possible to create a similar looking effect by running a silhuette shader, and use the resulting texture as a mask for some kind of bloom shader?
If only I knew how to write shaders, otherwise I would have had a go at it. :)
0 x
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.

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 » Tue Oct 24, 2006 9:10 pm

Wouldn't it be possible to create a similar looking effect by running a silhuette shader, and use the resulting texture as a mask for some kind of bloom shader?
Kinda sorta not really. If you're talking about a "resulting texture" then that requires a render to texture. You could possibly use a compositor in some way to do this - clear the background render just the object with a special sillouette shader that renders anything inside the sillouette border as black and the sillouette as pure white (or the glow colour I guess) - render that to a texture used for the compositor, then perform blurring operations on it.
0 x

User avatar
nebukadnezzar
Halfling
Posts: 93
Joined: Sun Jun 11, 2006 4:40 pm
Location: Germany
Contact:

Post by nebukadnezzar » Mon Oct 30, 2006 5:36 pm

What I've done in the past render the scene, then enable the stencil buffer and render the selected object into the buffer, then render the selected object again but scaled slightly (be sure to scale from the center of the bounding box, not necessarily the object's origin) with a different material (such as a translucent color) and use the stencil to only make it render where the stencil doesn't exist. This will create a glow outline.
I've done it to get an effect as Falagard described above.

The most time I've spend searching information about rendering to the stencil buffer. Since there is no clear proceeding described.

Here is the code (it's a first try, i think there is space to optmize):

Code: Select all

#pragma once

#include <OgreRenderQueueListener.h>

class HighlightQueueListener : public Ogre::RenderQueueListener
{
public:
	virtual void renderQueueStarted(Ogre::uint8 queueGroupId, const Ogre::String& invocation, bool& skipThisInvocation)
	{
		//RenderQueue containing the object to be highlighted
		if (queueGroupId == 90)
		{
			Ogre::RenderSystem * rendersys = Ogre::Root::getSingleton().getRenderSystem();

			rendersys->clearFrameBuffer(Ogre::FBT_STENCIL);
			rendersys->setStencilCheckEnabled(true);
			rendersys->setStencilBufferParams(Ogre::CMPF_ALWAYS_PASS,1,0xFFFFFFFF,
									Ogre::SOP_KEEP,Ogre::SOP_KEEP,Ogre::SOP_REPLACE,false);		
		}

		//RenderQueue containing the outline
		if (queueGroupId == 91)
		{
			Ogre::RenderSystem * rendersys = Ogre::Root::getSingleton().getRenderSystem();

			rendersys->setStencilCheckEnabled(true);
			rendersys->setStencilBufferParams(Ogre::CMPF_NOT_EQUAL,1,0xFFFFFFFF,
						Ogre::SOP_KEEP,Ogre::SOP_KEEP,Ogre::SOP_KEEP,false);		
		}
	}

	virtual void renderQueueEnded(Ogre::uint8 queueGroupId, const Ogre::String& invocation, bool& repeatThisInvocation)
	{
		if (( queueGroupId == 90 ) || ( queueGroupId == 91 ))
		{
			Ogre::RenderSystem * rendersys = Ogre::Root::getSingleton().getRenderSystem();
			rendersys->setStencilCheckEnabled(false);
			rendersys->setStencilBufferParams();
		}
	}

};
Code for setting an Ogre::Entitiy* entity to be highlighted

Code: Select all

	entity->setRenderQueueGroup(90);
	Ogre::Entity* clone = entity->clone(entity->getName() + "Outline");
	clone->setRenderQueueGroup(91);
	clone->setMaterialName("Outline");

	Ogre::SceneNode* high = entity->getParentSceneNode()->createChildSceneNode(parent->getName() + "Outline");
	high->setScale(Ogre::Vector3(1.1,1.1,1.1));
	high->attachObject(clone);
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 Dec 25, 2006 8:48 am

This code should become one of the samples that come with Ogre. There it will be good for demonstrate using the stencil in the scene for special effects like the glow.
0 x
Watch out for my OGRE related tweets here.

User avatar
BRAINLESS
Goblin
Posts: 282
Joined: Tue Jan 04, 2005 6:56 pm
Location: The Netherlands

Post by BRAINLESS » Mon Dec 25, 2006 1:31 pm

Thanks! This looks really good :)
0 x
Proud member of the OpenFRAG Game Development community

User avatar
nebukadnezzar
Halfling
Posts: 93
Joined: Sun Jun 11, 2006 4:40 pm
Location: Germany
Contact:

Post by nebukadnezzar » Mon Dec 25, 2006 1:35 pm

BRAINLESS wrote:Thanks! This looks really good :)
hmm maybe someone can provide a nice matrial (or shader) for the glow-outline...
something with a gradient or so...
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 Dec 25, 2006 1:36 pm

I am working on a clean demo...
0 x
Watch out for my OGRE related tweets here.

User avatar
nebukadnezzar
Halfling
Posts: 93
Joined: Sun Jun 11, 2006 4:40 pm
Location: Germany
Contact:

Post by nebukadnezzar » Mon Dec 25, 2006 1:43 pm

Assaf Raman wrote:I am working on a clean demo...
nice to know that someone picks up the code... and can use it...

since i've only done a simple POC to determine how diffcult and expensive this technique is....

can't wait for more ogre-experienced users to pimp it ;-)
0 x

billrobertson42
Kobold
Posts: 31
Joined: Mon Nov 27, 2006 1:29 am

Post by billrobertson42 » Mon Dec 25, 2006 7:01 pm

Would the compositor be a way to achieve this effect?
0 x

Post Reply