1 | /*
|
---|
2 | -----------------------------------------------------------------------------
|
---|
3 | This source file is part of OGRE
|
---|
4 | (Object-oriented Graphics Rendering Engine)
|
---|
5 | For the latest info, see http://www.ogre3d.org/
|
---|
6 |
|
---|
7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
8 | Also see acknowledgements in Readme.html
|
---|
9 |
|
---|
10 | You may use this sample code for anything you like, it is not covered by the
|
---|
11 | LGPL like the rest of the engine.
|
---|
12 | -----------------------------------------------------------------------------
|
---|
13 | */
|
---|
14 |
|
---|
15 | /**
|
---|
16 | \file
|
---|
17 | Lighting.h
|
---|
18 | \brief
|
---|
19 | Shows lighting support in OGRE. Also demonstrates the use of billboards
|
---|
20 | and controllers for automatic time-relative behaviour.
|
---|
21 | */
|
---|
22 |
|
---|
23 |
|
---|
24 | #include "ExampleApplication.h"
|
---|
25 | #include "OgreIlluminationManager.h"
|
---|
26 | #include "SceneSerializer.h"
|
---|
27 |
|
---|
28 |
|
---|
29 | // Listener class for frame updates
|
---|
30 | class PRMDemoFrameListener : public ExampleFrameListener
|
---|
31 | {
|
---|
32 | protected:
|
---|
33 |
|
---|
34 | unsigned long framecount;
|
---|
35 | SceneNode* mainLightNode;
|
---|
36 | Light* light;
|
---|
37 |
|
---|
38 | public:
|
---|
39 | PRMDemoFrameListener(RenderWindow* window, Camera* maincam, SceneNode* lightNode, Light* l)
|
---|
40 | :ExampleFrameListener(window, maincam)
|
---|
41 |
|
---|
42 | {
|
---|
43 | mainLightNode = lightNode;
|
---|
44 | light = l;
|
---|
45 | framecount = 0;
|
---|
46 | mMoveSpeed /= 50.0;
|
---|
47 | }
|
---|
48 |
|
---|
49 | bool frameStarted(const FrameEvent& evt)
|
---|
50 | {
|
---|
51 | /* light->setDirection(mCamera->getDirection());
|
---|
52 | light->setPosition(mCamera->getPosition());
|
---|
53 | mainLightNode->setPosition(mCamera->getPosition());*/
|
---|
54 | bool result = ExampleFrameListener::frameStarted(evt);
|
---|
55 | framecount++;
|
---|
56 |
|
---|
57 | return result;
|
---|
58 | }
|
---|
59 |
|
---|
60 |
|
---|
61 |
|
---|
62 | };
|
---|
63 |
|
---|
64 | /** Application class */
|
---|
65 | class PRMDemoApplication : public ExampleApplication
|
---|
66 | {
|
---|
67 |
|
---|
68 |
|
---|
69 |
|
---|
70 |
|
---|
71 | protected:
|
---|
72 | SceneNode* kupolaNode;
|
---|
73 | SceneNode* mainLightNode;
|
---|
74 | Light* mainLight;
|
---|
75 |
|
---|
76 | void loadResources(void)
|
---|
77 | {
|
---|
78 | // Initialise, parse scripts etc
|
---|
79 | ResourceGroupManager::getSingleton().initialiseResourceGroup("Bootstrap");
|
---|
80 | ResourceGroupManager::getSingleton().initialiseResourceGroup("General");
|
---|
81 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Basic");
|
---|
82 | ResourceGroupManager::getSingleton().initialiseResourceGroup("PostProc");
|
---|
83 | //ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Demo");
|
---|
84 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_PathMapDemo");
|
---|
85 | }
|
---|
86 |
|
---|
87 | void createPostproc()
|
---|
88 | {
|
---|
89 | CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
90 | "GTP/PostProc/Glow");
|
---|
91 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
92 | "GTP/PostProc/Glow", true);
|
---|
93 | /*
|
---|
94 | CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
95 | "GTP/PostProc/ToneMap");
|
---|
96 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
97 | "GTP/PostProc/ToneMap", true); */
|
---|
98 | }
|
---|
99 |
|
---|
100 | void chooseSceneManager()
|
---|
101 | {
|
---|
102 | mSceneMgr = mRoot->createSceneManager("OctreeSceneManager");
|
---|
103 | //mSceneMgr = mRoot->createSceneManager("OcclusionCullingSceneManager");
|
---|
104 | }
|
---|
105 |
|
---|
106 | /*
|
---|
107 | void createScene(void) /// SHADOWACCUM
|
---|
108 | {
|
---|
109 | //std::string occlusion_cfg("OcclusionCulling.cfg");
|
---|
110 | //mSceneMgr->setWorldGeometry(occlusion_cfg);
|
---|
111 | //createPostproc();
|
---|
112 |
|
---|
113 | OgreIlluminationManager::getSingleton().setMainCamera(mCamera);
|
---|
114 | OgreIlluminationManager::getSingleton().setMainViewport(mWindow->getViewport(0));
|
---|
115 | OgreIlluminationManager::getSingleton().setShadowMapMaterialName("GTP/Basic/CameraDepth");
|
---|
116 | OgreIlluminationManager::getSingleton().setFocusingSM(false);
|
---|
117 | OgreIlluminationManager::getSingleton().setShadowMapSize(1024);
|
---|
118 | OgreIlluminationManager::getSingleton().setBlurShadowMap(false);
|
---|
119 | OgreIlluminationManager::getSingleton().setUseLISPSM(false);
|
---|
120 | OgreIlluminationManager::getSingleton().setAreaLigtRadius(2);
|
---|
121 |
|
---|
122 | Root::getSingleton()._setCurrentSceneManager(mSceneMgr);
|
---|
123 | mCamera->setPosition(0,0,0);
|
---|
124 | //mCamera->setPosition(0,100,0);
|
---|
125 | //mCamera->lookAt(0,-1,0);
|
---|
126 | mCamera->setFOVy(Radian(Degree(80)));
|
---|
127 | mCamera->setNearClipDistance(0.01);
|
---|
128 | mCamera->setFarClipDistance(1000);
|
---|
129 | // Set ambient light
|
---|
130 | mSceneMgr->setAmbientLight(ColourValue(0,0, 0));
|
---|
131 | //mSceneMgr->setSkyBox(true, "Examples/EveningSkyBox", 500);
|
---|
132 |
|
---|
133 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
134 |
|
---|
135 | Entity* pillar = mSceneMgr->createEntity("pillar", "pillarShape.mesh");
|
---|
136 | SceneNode* pillarNode = rootNode->createChildSceneNode("pillarnode");
|
---|
137 | pillarNode->attachObject(pillar);
|
---|
138 |
|
---|
139 |
|
---|
140 | createPlane("p","GTP/Basic/ShadowReceiver/ShadowAccum",Vector3(0,-1.3,0),Vector2(20,20),Vector2(1,1));
|
---|
141 |
|
---|
142 | Light* mainLight = mSceneMgr->createLight("MainLight");
|
---|
143 | mainLight->setType(Light::LT_SPOTLIGHT);
|
---|
144 | mainLight->setCastShadows(true);
|
---|
145 | mainLight->setDiffuseColour(ColourValue::White);
|
---|
146 | mainLight->setSpecularColour(ColourValue::White);
|
---|
147 | mainLightNode = rootNode->createChildSceneNode();
|
---|
148 |
|
---|
149 | mainLightNode->setPosition(10,10,10);
|
---|
150 | mainLight->setPosition(10,10,10);
|
---|
151 | mainLight->setPowerScale(10);
|
---|
152 | mainLight->setDirection(-1,-1, -1);
|
---|
153 | mainLight->setSpotlightOuterAngle(Radian(Degree(90)));
|
---|
154 | mainLight->setAttenuation(20, 0, 0, 0);
|
---|
155 | mainLightNode->attachObject(mainLight);
|
---|
156 |
|
---|
157 | BillboardSet* bbs = mSceneMgr->createBillboardSet("bb", 1);
|
---|
158 | bbs->setDefaultDimensions(6,6);
|
---|
159 | bbs->createBillboard(Vector3::ZERO, ColourValue::White);
|
---|
160 | bbs->setMaterialName("Flare");
|
---|
161 | mainLightNode->attachObject(bbs);
|
---|
162 |
|
---|
163 | OgreIlluminationManager::getSingleton().initTechniques();
|
---|
164 | }*/
|
---|
165 | /*
|
---|
166 | void createScene(void) ///TOWERS
|
---|
167 | {
|
---|
168 | //std::string occlusion_cfg("OcclusionCulling.cfg");
|
---|
169 | //mSceneMgr->setWorldGeometry(occlusion_cfg);
|
---|
170 |
|
---|
171 | createPostproc();
|
---|
172 |
|
---|
173 | OgreIlluminationManager::getSingleton().setMainCamera(mCamera);
|
---|
174 | OgreIlluminationManager::getSingleton().setMainViewport(mWindow->getViewport(0));
|
---|
175 | OgreIlluminationManager::getSingleton().setShadowMapSize(700);
|
---|
176 | OgreIlluminationManager::getSingleton().setShadowMapMaterialName("GTP/Basic/Depth");
|
---|
177 | OgreIlluminationManager::getSingleton().setFocusingSM(true);
|
---|
178 | OgreIlluminationManager::getSingleton().setBlurShadowMap(false);
|
---|
179 | OgreIlluminationManager::getSingleton().setUseLISPSM(true);
|
---|
180 |
|
---|
181 | Root::getSingleton()._setCurrentSceneManager(mSceneMgr);
|
---|
182 | mCamera->setPosition(0,0,0);
|
---|
183 | //mCamera->setPosition(0,100,0);
|
---|
184 | //mCamera->lookAt(0,-1,0);
|
---|
185 | mCamera->setFOVy(Radian(Degree(80)));
|
---|
186 | mCamera->setNearClipDistance(0.01);
|
---|
187 | mCamera->setFarClipDistance(1000);
|
---|
188 | // Set ambient light
|
---|
189 | mSceneMgr->setAmbientLight(ColourValue(0.1, 0.1, 0.1));
|
---|
190 | mSceneMgr->setSkyBox(true, "Examples/EveningSkyBox", 500);
|
---|
191 |
|
---|
192 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
193 |
|
---|
194 |
|
---|
195 | SceneSerializer s(mSceneMgr);
|
---|
196 | DataStreamPtr inputStream;
|
---|
197 | inputStream = ResourceGroupManager::getSingleton().openResource("towers.level"); //towers2.level
|
---|
198 | s.parseScript(inputStream, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
199 |
|
---|
200 | //createPlane("p","groundmaterial",Vector3(0,-0.3,0),Vector2(150,150));
|
---|
201 |
|
---|
202 | Light* mainLight = mSceneMgr->createLight("MainLight");
|
---|
203 | mainLight->setType(Light::LT_DIRECTIONAL);
|
---|
204 | mainLight->setCastShadows(true);
|
---|
205 | mainLight->setDiffuseColour(ColourValue::White);
|
---|
206 | mainLight->setSpecularColour(ColourValue::White);
|
---|
207 | mainLightNode = rootNode->createChildSceneNode();
|
---|
208 |
|
---|
209 | mainLightNode->setPosition(1000,1000,1000);
|
---|
210 | mainLight->setPosition(1000,1000,1000);
|
---|
211 | mainLight->setPowerScale(5);
|
---|
212 | mainLight->setDirection(-1,-1, -1);
|
---|
213 | mainLightNode->attachObject(mainLight);
|
---|
214 |
|
---|
215 | OgreIlluminationManager::getSingleton().initTechniques();
|
---|
216 | }*/
|
---|
217 |
|
---|
218 | void createScene(void) ///PATHMAP Hangar
|
---|
219 | {
|
---|
220 | std::string occlusion_cfg("OcclusionCulling.cfg");
|
---|
221 | //mSceneMgr->setWorldGeometry(occlusion_cfg);
|
---|
222 |
|
---|
223 | //createPostproc();
|
---|
224 |
|
---|
225 | OgreIlluminationManager::getSingleton().setMainCamera(mCamera);
|
---|
226 | OgreIlluminationManager::getSingleton().setMainViewport(mWindow->getViewport(0));
|
---|
227 | OgreIlluminationManager::getSingleton().setShadowMapSize(512);
|
---|
228 | OgreIlluminationManager::getSingleton().setShadowMapMaterialName("GTP/Basic/Distance_Normalized");
|
---|
229 | OgreIlluminationManager::getSingleton().setFocusingSM(false);
|
---|
230 | OgreIlluminationManager::getSingleton().setShadowMapSize(512);
|
---|
231 | OgreIlluminationManager::getSingleton().setBlurShadowMap(false);
|
---|
232 | OgreIlluminationManager::getSingleton().setUseLISPSM(false);
|
---|
233 |
|
---|
234 | Root::getSingleton()._setCurrentSceneManager(mSceneMgr);
|
---|
235 | mCamera->setPosition(32,0,0);
|
---|
236 | //mCamera->setPosition(0,100,0);
|
---|
237 | //mCamera->lookAt(0,-1,0);
|
---|
238 | mCamera->setFOVy(Radian(Degree(80)));
|
---|
239 | mCamera->setNearClipDistance(0.01);
|
---|
240 | mCamera->setFarClipDistance(1000);
|
---|
241 | // Set ambient light
|
---|
242 | mSceneMgr->setAmbientLight(ColourValue(0.1, 0.1, 0.1));
|
---|
243 | mSceneMgr->setSkyBox(true, "Examples/EveningSkyBox", 500);
|
---|
244 |
|
---|
245 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
246 |
|
---|
247 |
|
---|
248 | SceneSerializer s(mSceneMgr);
|
---|
249 | DataStreamPtr inputStream;
|
---|
250 | inputStream = ResourceGroupManager::getSingleton().openResource("processed.level"); //towers2.level
|
---|
251 | s.parseScript(inputStream, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
252 | s.parseEntryPoints("prmEntryPoints.text");
|
---|
253 |
|
---|
254 | //createPlane("p","GTP/Basic/ShadowReceiver/Depth",Vector3(0,-0.3,0),Vector2(150,150));
|
---|
255 |
|
---|
256 | mainLight = mSceneMgr->createLight("MainLight");
|
---|
257 | mainLight->setType(Light::LT_SPOTLIGHT);
|
---|
258 | mainLight->setCastShadows(false);
|
---|
259 | mainLight->setDiffuseColour(ColourValue(0.5,0.8,1,1));
|
---|
260 | mainLight->setSpecularColour(ColourValue::White);
|
---|
261 | mainLightNode = rootNode->createChildSceneNode();
|
---|
262 |
|
---|
263 | mainLightNode->setPosition(30,1,0.0);
|
---|
264 | mainLight->setPosition(30,0,0);
|
---|
265 | mainLight->setPowerScale(300);
|
---|
266 | mainLight->setDirection(-1, 0, 0);
|
---|
267 | mainLight->setSpotlightOuterAngle(Radian(Degree(90)));
|
---|
268 | mainLight->setAttenuation(50, 0, 1, 0);
|
---|
269 | mainLightNode->attachObject(mainLight);
|
---|
270 |
|
---|
271 |
|
---|
272 |
|
---|
273 |
|
---|
274 | Light* blueLight = mSceneMgr->createLight("BlueLight");
|
---|
275 | blueLight->setType(Light::LT_SPOTLIGHT);
|
---|
276 | blueLight->setCastShadows(false);
|
---|
277 | blueLight->setDiffuseColour(ColourValue(0.0,0.1,1,1));
|
---|
278 | blueLight->setSpecularColour(ColourValue::White);
|
---|
279 | SceneNode* blueLightNode = rootNode->createChildSceneNode();
|
---|
280 |
|
---|
281 | blueLightNode->setPosition(-30,1,0.0);
|
---|
282 | blueLight->setPosition(-30,0,0);
|
---|
283 | blueLight->setPowerScale(300);
|
---|
284 | blueLight->setDirection(1, 0, 0);
|
---|
285 | blueLight->setSpotlightOuterAngle(Radian(Degree(90)));
|
---|
286 | blueLight->setAttenuation(50, 0, 1, 0);
|
---|
287 | blueLightNode->attachObject(blueLight);
|
---|
288 |
|
---|
289 |
|
---|
290 | OgreIlluminationManager::getSingleton().initTechniques();
|
---|
291 | }
|
---|
292 |
|
---|
293 | void createPlane(Ogre::String _name, Ogre::String _material, Ogre::Vector3 _pos, Ogre::Vector2 _size, Ogre::Vector2 _subdivisions = Ogre::Vector2(1,1))
|
---|
294 | {
|
---|
295 | Plane _plane;
|
---|
296 | _plane.normal = Vector3::UNIT_Y;
|
---|
297 | _plane.d = 0;
|
---|
298 |
|
---|
299 |
|
---|
300 | MeshManager::getSingleton().createPlane(_name + ".plane",
|
---|
301 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
302 | _plane,_size.x,_size.y,1,1,true,1,_subdivisions.x,_subdivisions.y,Vector3::UNIT_Z);
|
---|
303 |
|
---|
304 | Entity *_entity = mSceneMgr->createEntity(_name + ".entity", _name + ".plane");
|
---|
305 | _entity->setMaterialName(_material);
|
---|
306 |
|
---|
307 | SceneNode* _node = mSceneMgr->getRootSceneNode()->createChildSceneNode(_name + ".node");
|
---|
308 | _node->attachObject(_entity);
|
---|
309 | _node->setPosition(_pos);
|
---|
310 |
|
---|
311 | }
|
---|
312 |
|
---|
313 | void createFrameListener(void)
|
---|
314 | {
|
---|
315 | // This is where we instantiate our own frame listener
|
---|
316 | mFrameListener= new PRMDemoFrameListener(mWindow,
|
---|
317 | mCamera, mainLightNode, mainLight );
|
---|
318 | mFrameListener->setPriority(1);
|
---|
319 | mRoot->addFrameListener(mFrameListener);
|
---|
320 | OgreIlluminationManager::getSingleton().setPriority(2);
|
---|
321 | mRoot->addFrameListener(&OgreIlluminationManager::getSingleton());
|
---|
322 | }
|
---|
323 |
|
---|
324 | };
|
---|
325 |
|
---|