-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDecalProjector.h
84 lines (73 loc) · 3.34 KB
/
DecalProjector.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#pragma once
#include "Ogre.h"
//#include "global.h"
using namespace Ogre;
class DecalProjector
{
public:
DecalProjector();
~DecalProjector();
void createProjector(SceneNode* aNode)
{
// set up the main decal projection frustum
mWeaponNode=aNode;
mDecalFrustum = new Frustum();
mProjectorNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("DecalProjectorNode");
mProjectorNode->attachObject(mDecalFrustum);
mProjectorNode->setPosition(0,5,5000);
// include these two lines if you don't want perspective projection
mDecalFrustum->setProjectionType(PT_ORTHOGRAPHIC);
mDecalFrustum->setNearClipDistance(25);
// set up the perpendicular filter texture frustum
mFilterFrustum = new Frustum();
mFilterFrustum->setProjectionType(PT_ORTHOGRAPHIC);
filterNode = mProjectorNode->createChildSceneNode("DecalFilterNode");
filterNode->attachObject(mFilterFrustum);
filterNode->setOrientation(Quaternion(Degree(90),Vector3::UNIT_Y));
// load the images for the decal and the filter
//TextureManager::getSingleton().load("decal.png", "General", TEX_TYPE_2D, 1);
//TextureManager::getSingleton().load("decal_filter.png", "General", TEX_TYPE_1D, 1);
}
void makeMaterialReceiveDecal(const String &matName)
{
// get the material
mProjectorNode->setPosition(Ogre::Vector3(mWeaponNode->getParentSceneNode()->getParentSceneNode()->getPosition().x,mWeaponNode->getParentSceneNode()->getParentSceneNode()->getPosition().y,mWeaponNode->getParentSceneNode()->getParentSceneNode()->getPosition().z-20));
mProjectorNode->setOrientation(mWeaponNode->getOrientation());
filterNode->setPosition(mProjectorNode->getPosition()+Ogre::Vector3::NEGATIVE_UNIT_Z*100);
filterNode->setOrientation(mWeaponNode->getOrientation());
MaterialPtr mat = (MaterialPtr)MaterialManager::getSingleton().getByName(matName);
// create a new pass in the material to render the decal
Pass *pass;
if (!mat->getTechnique(0)->getPass("run3_decal_"))
{
pass = mat->getTechnique(0)->createPass();
pass->setName("run3_decal_");
}
else
{
pass = mat->getTechnique(0)->getPass("run3_decal_");
}
// set our pass to blend the decal over the model's regular texture
pass->setSceneBlending(SBT_TRANSPARENT_ALPHA);
pass->setDepthBias(1);
// set the decal to be self illuminated instead of lit by scene lighting
pass->setLightingEnabled(false);
// set up the decal's texture unit
TextureUnitState *texState = pass->createTextureUnitState("bullet_concrete_hit.png");
texState->setProjectiveTexturing(true, mDecalFrustum);
texState->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
texState->setTextureFiltering(FO_POINT, FO_LINEAR, FO_NONE);
// set up the filter texture's texture unit
texState = pass->createTextureUnitState("bullet_concrete_hit.png");
texState->setProjectiveTexturing(true, mFilterFrustum);
texState->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
texState->setTextureFiltering(TFO_NONE);
}
private:
Ogre::SceneManager* mSceneMgr;
Ogre::SceneNode *mProjectorNode;
Ogre::SceneNode *mWeaponNode;
Ogre::SceneNode *filterNode;
Ogre::Frustum *mDecalFrustum;
Ogre::Frustum *mFilterFrustum;
};