Sample_CelShading源码简析
来源:互联网 发布:淘宝会员名霸气的名字 编辑:程序博客网 时间:2024/05/19 16:05
#ifndef __CelShading_H__
#define __CelShading_H__
#include "SdkSample.h"
using namespace Ogre;
using namespace OgreBites;
class _OgreSampleClassExport Sample_CelShading : public SdkSample
{
public:
Sample_CelShading()
{
mInfo["Title"] = "Cel-shading";
mInfo["Description"] = "A demo of cel-shaded graphics using vertex & fragment programs.";
mInfo["Thumbnail"] = "thumb_cel.png";
mInfo["Category"] = "Lighting";
}
StringVector getRequiredPlugins()
{
StringVector names;
names.push_back("Cg Program Manager");
return names;
}
void testCapabilities(const RenderSystemCapabilities* caps)
{
if (!caps->hasCapability(RSC_VERTEX_PROGRAM) || !caps->hasCapability(RSC_FRAGMENT_PROGRAM))
{
OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "Your graphics card does not support vertex and fragment"
" programs, so you cannot run this sample. Sorry!", "CelShadingSample::testCapabilities");
}
}
如果图形卡不支持顶点和段处理,那就会报错。反正我的电脑是用不起。
bool frameRenderingQueued(const FrameEvent& evt)
{
// make the light revolve around our model if and only if the check box is checked
if (mMoveLight->isChecked()) mLightPivot->yaw(Degree(evt.timeSinceLastFrame * 30));
return SdkSample::frameRenderingQueued(evt); // don't forget the parent class updates!
}
protected:
void setupContent()
{
mViewport->setBackgroundColour(ColourValue::White);
// set our camera to orbit around the origin and show cursor
mCameraMan->setStyle(CS_ORBIT);
mTrayMgr->showCursor();
// create a basic point light with an offset
Light* light = mSceneMgr->createLight();
light->setPosition(20, 40, 50);
// attach the light to a pivot node
mLightPivot = mSceneMgr->getRootSceneNode()->createChildSceneNode();
mLightPivot->attachObject(light);
// create our model, give it the shader material, and place it at the origin
Entity *ent = mSceneMgr->createEntity("Head", "ogrehead.mesh");
ent->setMaterialName("Examples/CelShading");
其实这个demo中最主要的就是这一句话,这里关系到Ogre材质脚本的知识,请看链接
http://blog.csdn.net/a523330620/article/details/7270252
mSceneMgr->getRootSceneNode()->attachObject(ent);
/* We set the same material for all parts of the head, but use custom shader parameters to set the
colours for each part. See Examples-Advanced.material for how these are bound to GPU parameters. */
SubEntity* sub;
sub = ent->getSubEntity(0); // eyes
sub->setCustomParameter(SP_SHININESS, Vector4(35, 0, 0, 0));
sub->setCustomParameter(SP_DIFFUSE, Vector4(1, 0.3, 0.3, 1));
sub->setCustomParameter(SP_SPECULAR, Vector4(1, 0.6, 0.6, 1));
这里的SP_SHININESS难道就是材质脚本中使用shininess(脚本中是没有大小写之分的)?我想应该是吧,不然还真理解不了。不过脚本中已经有对shininess这些参数的设置了,这里可能是用来自定义的吧。
sub = ent->getSubEntity(1); // skin
sub->setCustomParameter(SP_SHININESS, Vector4(10, 0, 0, 0));
sub->setCustomParameter(SP_DIFFUSE, Vector4(0, 0.5, 0, 1));
sub->setCustomParameter(SP_SPECULAR, Vector4(0.3, 0.5, 0.3, 1));
sub = ent->getSubEntity(2); // earring
sub->setCustomParameter(SP_SHININESS, Vector4(25, 0, 0, 0));
sub->setCustomParameter(SP_DIFFUSE, Vector4(1, 1, 0, 1));
sub->setCustomParameter(SP_SPECULAR, Vector4(1, 1, 0.7, 1));
sub = ent->getSubEntity(3); // teeth
sub->setCustomParameter(SP_SHININESS, Vector4(20, 0, 0, 0));
sub->setCustomParameter(SP_DIFFUSE, Vector4(1, 1, 0.7, 1));
sub->setCustomParameter(SP_SPECULAR, Vector4(1, 1, 1, 1));
// create a check box to toggle light movement
mMoveLight = mTrayMgr->createCheckBox(TL_TOPLEFT, "MoveLight", "Move Light");
mMoveLight->setChecked(true);
}
// custom shader parameter bindings
enum ShaderParam { SP_SHININESS = 1, SP_DIFFUSE, SP_SPECULAR };
SceneNode* mLightPivot;
CheckBox* mMoveLight;
};
#endif
- Sample_CelShading源码简析
- Sample_CelShading源码简析
- Sample_BezierPatch源码简析
- Sample_BSP源码简析
- Sample_CameraTrack源码简析
- Sample_Character源码简析
- Sample_BezierPatch源码简析
- Sample_BSP源码简析
- Sample_CameraTrack源码简析
- Sample_Character源码简析
- IoCancelIrp源码简析
- cordova源码简析
- EasyDialog 源码简析
- fork源码简析
- ThreadLocal源码简析
- AFNetworking源码简析
- String 源码简析
- ArrayList源码简析
- ubuntu1104 apache + php + mysql + phpmyadmin
- 心目中的编程高手
- 静态构造函数
- MYSQL时间比较及时间差计算PHP
- What is Facebook's architecture?
- Sample_CelShading源码简析
- MySQL日期时间函数大全
- Linux(Ubuntu)环境MYSQL->master/slave主从同步设置以及注意事项
- Ubuntu Mysql 主从设置
- POJ3267 The Cow Lexicon, DP
- Android学习笔记06——handler的使用
- 正则习点 --- 11
- MySQl备份恢复策略(完全+增量备份策略)
- MySQL 给数据减肥 让MySQL数据库跑的更快