Ogre 创建角色对象的边缘线效果
2015-08-11 13:07
190 查看
http://www.ogre3d.org/tikiwiki/Create+outline+around+a+character
Here is a script of user Telchar, which shows how to create an outline around a character, which works without shaders.
Screenshot of this effect, used in the game Torchlight:
Here is the c++ code to do the same:
Download of file rim.dds:
http://www.ogre3d.org/forums/download/file.php?id=2022
The code was published here:
http://www.ogre3d.org/forums/viewtopic.php?p=368918#p368918
Similar version:
http://www.ogre3d.org/forums/viewtopic.php?f=8&t=59079
For
questions and feedback, please use this forum topic:
http://www.ogre3d.org/forums/viewtopic.php?f=8&t=59079
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 screenshots of my current work.
Here is the exe (download and run): http://assaframan.googlepages.com/outline.zip
I did something similar to this article: http://www.codeproject.com/opengl/Outline_Mode.asp
This is only good for an outline and not for a glow effect.
Also – it only works in openGL and I had to add _setLineWidth function to the render system – and the Line Width only works with openGL. You can’t set the wireframe line thickness in DirectX.
If anyone wants the code – post a replay.
I will create a glow using a similer technique to the one in nebukadnezzar code.
The nice thing about the outlines technique in the screenshots is that the outlines stay with the same thickness no matter if you are far or near.
I didn't get nice results with the stencil+shaders.
Here is the best I have got until now:
Here is the exe (download and run):
http://assaframan.googlepages.com/glow.zip
Here is the source:
http://assaframan.googlepages.com/glow_code.zip
Not a nice glow - but a nice code sample of how to use the stencil with OGRE.
Watch out for my OGRE related tweets
here.
Assaf RamanOGRE Team Member
Posts: 3092Kudos:
79 Joined: 11 Apr 2006Location: TLV, Israel
Top
by
psquare » Tue Dec 26, 2006 5:28 am
I did something like this before:
1. Programmatically add a pass at the end of all passes of the technique you are using.
2. Render to texture the object(s)
3. Use this rendered texture as a projective texture in the pass that you added. In the pass you can have a
shader which scales the original color.
You can use something like a toon shader as your last pass
shader.
If dot(normal, viewVector) > treshold
color = glow color
else
color = original color
This will accurately do the edge detection for you.
Note that I add a pass, so that I do this non-invasively (do not modify the existing passes).
To do a glow around the edges, you can add a bloom
shader as Falagard mentions.You can accomplish this using compositor framework of Ogre.
There is a sample for bloom in the OgreSDK. There are also various scene shaders (compositor effects (.fx) ) in the Direct X SDK.
Here is a script of user Telchar, which shows how to create an outline around a character, which works without shaders.
Screenshot of this effect, used in the game Torchlight:
material some/random/material/with/rim/effect { technique { pass { texture_unit { texture yourtexturehere.png } //rim lighting texture_unit { cubic_texture rim.dds combinedUVW tex_address_mode clamp colour_op_ex add src_texture src_current colour_op_multipass_fallback one one env_map cubic_normal } } } }
Here is the c++ code to do the same:
/* rim lighting see: http://www.ogre3d.org/tikiwiki/Create+outline+around+a+character */ #pragma once #include <Ogre/OgreEntity.h> #include <Ogre/OgreSubEntity.h> #include <Ogre/OgreSubMesh.h> #include <Ogre/OgreString.h> #include <Ogre/OgreMaterial.h> /* add the rim lighting effect to an entity. */ void highlight (Ogre::Entity* entity) { unsigned short count = entity->getNumSubEntities(); const Ogre::String file_name = "rim.dds"; const Ogre::String rim_material_name = "_rim"; for (unsigned short i = 0; i < count; ++i) { Ogre::SubEntity* subentity = entity->getSubEntity (i); const Ogre::String& old_material_name = subentity->getMaterialName(); Ogre::String new_material_name = old_material_name + rim_material_name; Ogre::MaterialPtr new_material = MaterialManager::getSingleton().getByName (new_material_name); if (new_material.isNull()) { MaterialPtr old_material = MaterialManager::getSingleton().getByName (old_material_name); new_material = old_material->clone (new_material_name); Pass* pass = new_material->getTechnique(0)->getPass(0); Ogre::TextureUnitState* texture = pass->createTextureUnitState(); texture->setCubicTextureName (&file_name, true); texture->setTextureAddressingMode (TextureUnitState::TAM_CLAMP); texture->setColourOperationEx (Ogre::LBX_ADD, Ogre::LBS_TEXTURE, Ogre::LBS_CURRENT); texture->setColourOpMultipassFallback (Ogre::SBF_ONE, Ogre::SBF_ONE); texture->setEnvironmentMap (true, Ogre::TextureUnitState::ENV_NORMAL); } subentity->setMaterial (new_material); } } /* remove the rim lighting effect from an entity. */ void unhighlight (Ogre::Entity* entity) { unsigned short count = entity->getNumSubEntities(); for (unsigned short i = 0; i < count; ++i) { Ogre::SubEntity* subentity = entity->getSubEntity (i); Ogre::SubMesh* submesh = subentity->getSubMesh(); const Ogre::String& old_material_name = submesh->getMaterialName(); const Ogre::String& new_material_name = subentity->getMaterialName(); // if the entity is already using the original material then we're done. if (0 == stricmp (old_material_name.c_str(), new_material_name.c_str())) continue; // otherwise restore the original material name. subentity->setMaterialName (old_material_name); } }
Download of file rim.dds:
http://www.ogre3d.org/forums/download/file.php?id=2022
The code was published here:
http://www.ogre3d.org/forums/viewtopic.php?p=368918#p368918
Similar version:
http://www.ogre3d.org/forums/viewtopic.php?f=8&t=59079
For
questions and feedback, please use this forum topic:
http://www.ogre3d.org/forums/viewtopic.php?f=8&t=59079
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 screenshots of my current work.
Here is the exe (download and run): http://assaframan.googlepages.com/outline.zip
I did something similar to this article: http://www.codeproject.com/opengl/Outline_Mode.asp
This is only good for an outline and not for a glow effect.
Also – it only works in openGL and I had to add _setLineWidth function to the render system – and the Line Width only works with openGL. You can’t set the wireframe line thickness in DirectX.
If anyone wants the code – post a replay.
I will create a glow using a similer technique to the one in nebukadnezzar code.
The nice thing about the outlines technique in the screenshots is that the outlines stay with the same thickness no matter if you are far or near.
I didn't get nice results with the stencil+shaders.
Here is the best I have got until now:
Here is the exe (download and run):
http://assaframan.googlepages.com/glow.zip
Here is the source:
http://assaframan.googlepages.com/glow_code.zip
Not a nice glow - but a nice code sample of how to use the stencil with OGRE.
Watch out for my OGRE related tweets
here.
Assaf RamanOGRE Team Member
Posts: 3092Kudos:
79 Joined: 11 Apr 2006Location: TLV, Israel
Top
by
psquare » Tue Dec 26, 2006 5:28 am
I did something like this before:
1. Programmatically add a pass at the end of all passes of the technique you are using.
2. Render to texture the object(s)
3. Use this rendered texture as a projective texture in the pass that you added. In the pass you can have a
shader which scales the original color.
You can use something like a toon shader as your last pass
shader.
If dot(normal, viewVector) > treshold
color = glow color
else
color = original color
This will accurately do the edge detection for you.
Note that I add a pass, so that I do this non-invasively (do not modify the existing passes).
To do a glow around the edges, you can add a bloom
shader as Falagard mentions.You can accomplish this using compositor framework of Ogre.
There is a sample for bloom in the OgreSDK. There are also various scene shaders (compositor effects (.fx) ) in the Direct X SDK.
相关文章推荐
- 理解CSS中的BFC(块级可视化上下文)[译]
- GreenSQL(数据库安全)学习
- 互联网公司面试中经常被问的问题
- CountDownLatch与CyclicBarrier
- Class撑起了OOP世界的天。Class类是OO的基本单元,OO的世界都是通过一个一个的类协作完成的,提高软件的重用性、灵活性和扩展性(转)
- 8、SQL Server 表分区
- mongo设计(三)
- ios图片轮播
- char*和char[]的区别
- 左神牛课网讲座第一发之面试经验
- Linux PHP开发环境:CentOS下配置LAMP开发环境
- HDU 1686 Oulipo
- 《Python基础教程(第2版)》学习笔记(一):
- 如果他们在未来的几年内技术水平没有突破性的提升,或者缺乏一点灵性和品味,那么可能在未来很长一段时间内,他们都会保持这个薪资水平(转)
- 不再以讹传讹,GET和POST的真正区别
- android反编译-反编译工具和方法
- RPG2.0战斗框架学习3之技能镜头效果
- myeclipse中修改Web项目名称
- 浅析Java线程
- NSFileHandle操作文件内容