How to show a glow around characters?
- fassihi
- Goblin
- Posts: 215
- Joined: Sat Sep 16, 2006 6:51 am
- x 8
- Contact:
How to show a glow around characters?
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?
What would be a good approach for creating such effect around the characters?
- Falagard
- OGRE Retired Moderator
- Posts: 2060
- Joined: Thu Feb 26, 2004 12:11 am
- Location: Toronto, Canada
- x 3
- Contact:
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.
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.
- zap
- Greenskin
- Posts: 135
- Joined: Mon Jul 04, 2005 12:14 am
- Location: St. Petersburg, Russia
- x 1
- Contact:
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.
Andrew
- Falagard
- OGRE Retired Moderator
- Posts: 2060
- Joined: Thu Feb 26, 2004 12:11 am
- Location: Toronto, Canada
- x 3
- Contact:
- zap
- Greenskin
- Posts: 135
- Joined: Mon Jul 04, 2005 12:14 am
- Location: St. Petersburg, Russia
- x 1
- Contact:
It will look as if you would enclose the object into a glass container... or into a lump of ice. All depends of your imaginationFalagard wrote:Yup, can do that too but it kinda looks like crap
Well, that's the simplest option and since the guy is quite new with Ogre that would be easy for him to do...
Andrew
-
- Hobgoblin
- Posts: 540
- Joined: Wed Nov 17, 2004 4:36 pm
- Location: Middlesbrough, England
Couldn't he assign it a lower render queue so it is rendered before the full textured version...?
Regards,
Sticky.
Web: http://sourceforge.net/projects/ogreoggsound/
SVN: https://ogreoggsound.svn.sourceforge.ne ... ound/trunk
Sticky.
Web: http://sourceforge.net/projects/ogreoggsound/
SVN: https://ogreoggsound.svn.sourceforge.ne ... ound/trunk
- jacmoe
- OGRE Retired Moderator
- Posts: 20570
- Joined: Thu Jan 22, 2004 10:13 am
- Location: Denmark
- x 179
- Contact:
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
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
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
- Falagard
- OGRE Retired Moderator
- Posts: 2060
- Joined: Thu Feb 26, 2004 12:11 am
- Location: Toronto, Canada
- x 3
- Contact:
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.
- nebukadnezzar
- Halfling
- Posts: 93
- Joined: Sun Jun 11, 2006 4:40 pm
- Location: Germany
- x 1
- Contact:
- nebukadnezzar
- Halfling
- Posts: 93
- Joined: Sun Jun 11, 2006 4:40 pm
- Location: Germany
- x 1
- Contact:
yes this first come to my mind,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
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.
- Falagard
- OGRE Retired Moderator
- Posts: 2060
- Joined: Thu Feb 26, 2004 12:11 am
- Location: Toronto, Canada
- x 3
- Contact:
- dfacchin
- Greenskin
- Posts: 105
- Joined: Fri May 13, 2005 10:11 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.
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.
- jacmoe
- OGRE Retired Moderator
- Posts: 20570
- Joined: Thu Jan 22, 2004 10:13 am
- Location: Denmark
- x 179
- Contact:
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.
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.
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
- Falagard
- OGRE Retired Moderator
- Posts: 2060
- Joined: Thu Feb 26, 2004 12:11 am
- Location: Toronto, Canada
- x 3
- Contact:
- jacmoe
- OGRE Retired Moderator
- Posts: 20570
- Joined: Thu Jan 22, 2004 10:13 am
- Location: Denmark
- x 179
- Contact:
Looks great!
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.
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.
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
- Falagard
- OGRE Retired Moderator
- Posts: 2060
- Joined: Thu Feb 26, 2004 12:11 am
- Location: Toronto, Canada
- x 3
- Contact:
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.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?
- nebukadnezzar
- Halfling
- Posts: 93
- Joined: Sun Jun 11, 2006 4:40 pm
- Location: Germany
- x 1
- Contact:
I've done it to get an effect as Falagard described above.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.
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: 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);
- Assaf Raman
- OGRE Team Member
- Posts: 3092
- Joined: Tue Apr 11, 2006 3:58 pm
- Location: TLV, Israel
- x 76
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.
Watch out for my OGRE related tweets here.
- nebukadnezzar
- Halfling
- Posts: 93
- Joined: Sun Jun 11, 2006 4:40 pm
- Location: Germany
- x 1
- Contact:
- Assaf Raman
- OGRE Team Member
- Posts: 3092
- Joined: Tue Apr 11, 2006 3:58 pm
- Location: TLV, Israel
- x 76
- nebukadnezzar
- Halfling
- Posts: 93
- Joined: Sun Jun 11, 2006 4:40 pm
- Location: Germany
- x 1
- Contact:
-
- Kobold
- Posts: 31
- Joined: Mon Nov 27, 2006 1:29 am
- x 1