Stencil Glow Demo
-
- OGRE Team Member
- Posts: 3092
- Joined: Tue Apr 11, 2006 3:58 pm
- Location: TLV, Israel
- x 76
Stencil Glow Demo
Stencil Glow Demo
The work described in this post is partially based on code by nebukadnezzar that was posted on this thread: http://www.ogre3d.org/phpBB2/viewtopic.php?t=25321
Thanks nebukadnezzar!
I have created a simple demo to show how to use the stencil to create two types of glow effects.
The main advantage of my glows is that you can apply them to a single object and not the whole scene.
Outline glow effect round a specific entity:
A full body wrap glow effect round a specific entity:
I did not find any other good demo of how to use the stencil in OGRE.
I recommend to add this demo (or similar) to the OGRE demos that come with the OGRE source download.
Here is the exe ready to run:
http://assaframan.googlepages.com/StencilGlow_exe.zip
Here is the code:
http://assaframan.googlepages.com/StencilGlow_src.zip
Here are some more screenshots:
This is my Xmas present to the OGRE community.
[EDIT]I updated the downloads with broli's normal fix.[/EDIT]
The work described in this post is partially based on code by nebukadnezzar that was posted on this thread: http://www.ogre3d.org/phpBB2/viewtopic.php?t=25321
Thanks nebukadnezzar!
I have created a simple demo to show how to use the stencil to create two types of glow effects.
The main advantage of my glows is that you can apply them to a single object and not the whole scene.
Outline glow effect round a specific entity:
A full body wrap glow effect round a specific entity:
I did not find any other good demo of how to use the stencil in OGRE.
I recommend to add this demo (or similar) to the OGRE demos that come with the OGRE source download.
Here is the exe ready to run:
http://assaframan.googlepages.com/StencilGlow_exe.zip
Here is the code:
http://assaframan.googlepages.com/StencilGlow_src.zip
Here are some more screenshots:
This is my Xmas present to the OGRE community.
[EDIT]I updated the downloads with broli's normal fix.[/EDIT]
Last edited by Assaf Raman on Fri Dec 29, 2006 10:40 am, edited 2 times in total.
Watch out for my OGRE related tweets here.
-
- Halfling
- Posts: 48
- Joined: Fri Mar 31, 2006 5:08 pm
In your cg or hlsl file try using the normal and multiply it with the rest. And don't multyply your vertex position, something like this...
It would clear up that offset issue you currently have since the vertices arn't shifted trough their normals.
Code: Select all
cg:
mypos.xyz += size_value * (1.0 + (sin(time * 5.0) + 1.0) / 5.0 ) * normal;
hlsl:
vec3 Pos = gl_Vertex.xyz + ( (size_value * (1.0 + (sin(time * 5.0) + 1.0) / 15.0 ) * normal );
-
- Minaton
- Posts: 980
- Joined: Sat Aug 07, 2004 12:08 am
- Location: Dallas, TX
-
- OGRE Team Member
- Posts: 3092
- Joined: Tue Apr 11, 2006 3:58 pm
- Location: TLV, Israel
- x 76
broli: You are right - it is much better with the normal.
I updated the downloads in the first post.
Redownload if you want it.
Here is how it looks now:
Thanks broli!
I updated the downloads in the first post.
Redownload if you want it.
Here is how it looks now:
Thanks broli!
Watch out for my OGRE related tweets here.
-
- Minaton
- Posts: 980
- Joined: Sat Aug 07, 2004 12:08 am
- Location: Dallas, TX
-
- Goblin
- Posts: 282
- Joined: Sat May 14, 2005 9:20 pm
- x 1
I'm getting a problem with this when I try to turn the effect 'off'. I have a 'select object' function as follows:
However, when de-highlighted, the original entity (mEntity) is now being rendered with no depth-checking.
Code: Select all
void ActorRepresentation::setHighlighted (bool active)
{
if (active)
{
mEntity->setRenderQueueGroup
(RENDER_QUEUE_OUTLINE_GLOW_OBJECTS);
mHiliteEntity = mEntity->clone (mEntity->getName () + "Hilite");
mHiliteEntity->setRenderQueueGroup (RENDER_QUEUE_OUTLINE_GLOW_GLOWS);
mHiliteEntity->setMaterialName ("Editor/Glow_CG");
mNode->attachObject (mHiliteEntity);
}
else
{
Ogre::SceneManager *scm = Ogre::Root::getSingleton ().getSceneManager ("SceneManager");
mEntity->setRenderQueueGroup (mDefaultRenderQueueGroup);
scm->destroyEntity (mHiliteEntity);
mHiliteEntity = 0;
}
}
-
- Gold Sponsor
- Posts: 446
- Joined: Fri May 02, 2003 10:05 am
- Location: UK
-
- Halfling
- Posts: 48
- Joined: Fri Mar 31, 2006 5:08 pm
-
- OGRE Retired Moderator
- Posts: 2060
- Joined: Thu Feb 26, 2004 12:11 am
- Location: Toronto, Canada
- x 3
-
- OGRE Team Member
- Posts: 3092
- Joined: Tue Apr 11, 2006 3:58 pm
- Location: TLV, Israel
- x 76
This effect can be done without any shaders.
You can use scale (a modified scale that scales in the direction of the normal) and color change.
I guess it can be modified so it will work on any hardware that supports the stencil buffer.
You can use scale (a modified scale that scales in the direction of the normal) and color change.
I guess it can be modified so it will work on any hardware that supports the stencil buffer.
Watch out for my OGRE related tweets here.
-
- OGRE Team Member
- Posts: 3092
- Joined: Tue Apr 11, 2006 3:58 pm
- Location: TLV, Israel
- x 76
Ajare: To disable the effect - just detach the glow entity from the node.
For outline glow:
For full glow:
To enable the effect re-attach the glow entity.
For outline glow:
Code: Select all
actualOutlineGlowNode->detachObject(actualOutlineGlowEntity);
Code: Select all
alphaFullGlowNode->detachObject(alphaFullGlowEntity);
glowFullGlowNode->detachObject(glowFullGlowEntity);
Watch out for my OGRE related tweets here.
-
- OGRE Retired Moderator
- Posts: 20570
- Joined: Thu Jan 22, 2004 10:13 am
- Location: Denmark
- x 179
What a great present!
This looks awesome and seems to be efficient and easy to use. Useful in many situations! Thanks!
This looks awesome and seems to be efficient and easy to use. Useful in many situations! Thanks!
/* 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.
-
- Halfling
- Posts: 48
- Joined: Fri Mar 31, 2006 5:08 pm
Why would you use the CPU and extra code with some nasty work arounds instead of a simple Ogre material+GPU method that everybody can use out of the box. This goes for alot of things that are made here on these forums.Assaf Raman wrote:This effect can be done without any shaders.
You can use scale (a modified scale that scales in the direction of the normal) and color change.
-
- Greenskin
- Posts: 120
- Joined: Wed May 18, 2005 6:40 pm
-
- OGRE Team Member
- Posts: 3092
- Joined: Tue Apr 11, 2006 3:58 pm
- Location: TLV, Israel
- x 76
You can very easily – just change it in the shaders. The shaders are very basic shaders and I think you can change them without any knowledge in shaders.
Watch out for my OGRE related tweets here.
-
- Goblin
- Posts: 282
- Joined: Tue Jan 04, 2005 6:56 pm
- Location: The Netherlands
I agree, I have no knowledge of shaders and was able to change the workings of these 2 I ran up to a problem though, which your demo doesn't seem to suffer from. Perhaps that's because the Ogre model is more complex, but if I use a simple box model and this shader there's an obvious seam between the vertices of the glow. It looks a bit odd, so I'm going to try using a scaled scenenode instead.Assaf Raman wrote:You can very easily – just change it in the shaders. The shaders are very basic shaders and I think you can change them without any knowledge in shaders.
Proud member of the OpenFRAG Game Development community
-
- Goblin
- Posts: 279
- Joined: Sun Feb 19, 2006 1:08 am
-
- Gnoblar
- Posts: 4
- Joined: Fri Nov 24, 2006 10:37 am
this problem also occurs with the robot.mesh. seems that the faces are translated a bit outward according to their normals only. so a right angle or close to one would have gaps in the glow.BRAINLESS wrote:I agree, I have no knowledge of shaders and was able to change the workings of these 2 I ran up to a problem though, which your demo doesn't seem to suffer from. Perhaps that's because the Ogre model is more complex, but if I use a simple box model and this shader there's an obvious seam between the vertices of the glow. It looks a bit odd, so I'm going to try using a scaled scenenode instead.Assaf Raman wrote:You can very easily – just change it in the shaders. The shaders are very basic shaders and I think you can change them without any knowledge in shaders.
i dont know how to do cg, anyone care to fix this?
-
- Goblin
- Posts: 282
- Joined: Tue Jan 04, 2005 6:56 pm
- Location: The Netherlands
I've asked around and apparently that's not possible with vertex shaders. I'm no expert though (this is my first experience with shaders ) so I may be wrong
Proud member of the OpenFRAG Game Development community
-
- OGRE Retired Moderator
- Posts: 2060
- Joined: Thu Feb 26, 2004 12:11 am
- Location: Toronto, Canada
- x 3
It's not possible to fix without modifying the original mesh normals. The problem is that at angular seams in the mesh, normals usually point in different directions. This is because when you generate normals for a mesh in a 3d modeller you usually define an angular threshold for "smoothing" the normals - if the threshold is exceeded the normals will point in different directions at seams (otherwise your sharp corners would appear smooth-ish when you render them in Ogre). You could fix this by making an actual copy of the geometry and then smoothing all normals without this threshold, but it probably isn't worth it.
You can't do anything about this in a vertex shader because per vertex the shader doesn't know anything about the surrounding vertices, so you can't change the normal direction in the shader.
If you want to avoid this, you have to use the scale approach, instead of moving the verts out along their normals. You can do the scale inside a shader as well instead of calling setScale on the mesh. Also, you should get the center of the bounding box and pass it to the shader, then get the direction from this position to the vertex position and move the verts out along this vector. If you just pass a scale matrix and use the origin of the mesh, unless the origin is directly in the center of the mesh it will scale out in a less friendly manner.
You can't do anything about this in a vertex shader because per vertex the shader doesn't know anything about the surrounding vertices, so you can't change the normal direction in the shader.
If you want to avoid this, you have to use the scale approach, instead of moving the verts out along their normals. You can do the scale inside a shader as well instead of calling setScale on the mesh. Also, you should get the center of the bounding box and pass it to the shader, then get the direction from this position to the vertex position and move the verts out along this vector. If you just pass a scale matrix and use the origin of the mesh, unless the origin is directly in the center of the mesh it will scale out in a less friendly manner.
-
- Goblin
- Posts: 282
- Joined: Tue Jan 04, 2005 6:56 pm
- Location: The Netherlands
So which one is better? Either way we'll have to move the vertices out from the center and multiply them by a scale matrix. Using a shader this would have to be done every frame, but that may not be a problem as it's done on the GPU. I don't know if setScale() is done on the GPU, but I expect it isn't... it would be a one-time-only job though.
With my limited experience I'd say option 2 (using setScale rather then a shader) would be more efficient...
With my limited experience I'd say option 2 (using setScale rather then a shader) would be more efficient...
Proud member of the OpenFRAG Game Development community