aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/examples/11.PerPixelLighting/tutorial.html
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libraries/irrlicht-1.8/examples/11.PerPixelLighting/tutorial.html1004
1 files changed, 502 insertions, 502 deletions
diff --git a/libraries/irrlicht-1.8/examples/11.PerPixelLighting/tutorial.html b/libraries/irrlicht-1.8/examples/11.PerPixelLighting/tutorial.html
index 89e87bd..986d176 100644
--- a/libraries/irrlicht-1.8/examples/11.PerPixelLighting/tutorial.html
+++ b/libraries/irrlicht-1.8/examples/11.PerPixelLighting/tutorial.html
@@ -1,502 +1,502 @@
1<html> 1<html>
2<head> 2<head>
3<title>Irrlicht Engine Tutorial</title> 3<title>Irrlicht Engine Tutorial</title>
4<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 4<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
5</head> 5</head>
6 6
7<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> 7<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
8<br> 8<br>
9<table width="95%" border="0" cellspacing="0" cellpadding="2" align="center"> 9<table width="95%" border="0" cellspacing="0" cellpadding="2" align="center">
10 <tr> 10 <tr>
11 <td bgcolor="#666699" width="10"><b><a href="http://irrlicht.sourceforge.net" target="_blank"><img src="../../media/irrlichtlogo.jpg" width="88" height="31" border="0"></a></b></td> 11 <td bgcolor="#666699" width="10"><b><a href="http://irrlicht.sourceforge.net" target="_blank"><img src="../../media/irrlichtlogo.jpg" width="88" height="31" border="0"></a></b></td>
12 <td bgcolor="#666699" width="100%"> 12 <td bgcolor="#666699" width="100%">
13<div align="center"> 13<div align="center">
14 <div align="left"><b><font color="#FFFFFF">Tutorial 11. Per pixel lighting</font></b></div> 14 <div align="left"><b><font color="#FFFFFF">Tutorial 11. Per pixel lighting</font></b></div>
15 </div> 15 </div>
16 </td> 16 </td>
17 </tr> 17 </tr>
18 <tr bgcolor="#eeeeff"> 18 <tr bgcolor="#eeeeff">
19 <td height="90" colspan="2"> 19 <td height="90" colspan="2">
20 <div align="left"> 20 <div align="left">
21 <p> This tutorial shows how to use one of the built in more complex materials 21 <p> This tutorial shows how to use one of the built in more complex materials
22 in irrlicht: Per pixel lighted surfaces using normal maps and parallax 22 in irrlicht: Per pixel lighted surfaces using normal maps and parallax
23 mapping. It will also show how to use fog and moving particle systems. 23 mapping. It will also show how to use fog and moving particle systems.
24 And don't panic: You dont need any experience with shaders to use these 24 And don't panic: You dont need any experience with shaders to use these
25 materials in Irrlicht.</p> 25 materials in Irrlicht.</p>
26 <p>The program which is described here will look like this:</p> 26 <p>The program which is described here will look like this:</p>
27 <p align="center"><img src="../../media/011shot.jpg" width="258" height="202"><br> 27 <p align="center"><img src="../../media/011shot.jpg" width="258" height="202"><br>
28 </p> 28 </p>
29 </div> 29 </div>
30 </td> 30 </td>
31 </tr> 31 </tr>
32</table> 32</table>
33<br> 33<br>
34<table width="95%" border="0" cellspacing="0" cellpadding="2" align="center"> 34<table width="95%" border="0" cellspacing="0" cellpadding="2" align="center">
35 <tr> 35 <tr>
36 <td bgcolor="#666699"> <b><font color="#FFFFFF">Lets start!</font></b></td> 36 <td bgcolor="#666699"> <b><font color="#FFFFFF">Lets start!</font></b></td>
37 </tr> 37 </tr>
38 <tr> 38 <tr>
39 <td height="90" bgcolor="#eeeeff" valign="top"> <div align="left"> 39 <td height="90" bgcolor="#eeeeff" valign="top"> <div align="left">
40 <div align="left"> 40 <div align="left">
41 <p>At first, we need to include all headers and do the stuff we always 41 <p>At first, we need to include all headers and do the stuff we always
42 do, like in nearly all other tutorials.</p> 42 do, like in nearly all other tutorials.</p>
43 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> 43 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
44 <tr> 44 <tr>
45 <td> <pre>#include &lt;irrlicht.h&gt;<br>#include &lt;iostream&gt;<br><br>using namespace irr;<br><br>#pragma comment(lib, &quot;Irrlicht.lib&quot;)<br></pre></td> 45 <td> <pre>#include &lt;irrlicht.h&gt;<br>#include &lt;iostream&gt;<br><br>using namespace irr;<br><br>#pragma comment(lib, &quot;Irrlicht.lib&quot;)<br></pre></td>
46 </tr> 46 </tr>
47 </table> 47 </table>
48 <p>For this example, we need an event receiver, to make it possible 48 <p>For this example, we need an event receiver, to make it possible
49 for the user to switch between the three available material types. 49 for the user to switch between the three available material types.
50 In addition, the event receiver will create some small GUI window 50 In addition, the event receiver will create some small GUI window
51 which displays what material is currently being used. There is nothing 51 which displays what material is currently being used. There is nothing
52 special done in this class, so maybe you want to skip reading it.</p> 52 special done in this class, so maybe you want to skip reading it.</p>
53 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> 53 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
54 <tr> 54 <tr>
55 <td><pre>class MyEventReceiver : public IEventReceiver 55 <td><pre>class MyEventReceiver : public IEventReceiver
56{ 56{
57public: 57public:
58 58
59 MyEventReceiver(scene::ISceneNode* room, 59 MyEventReceiver(scene::ISceneNode* room,
60 gui::IGUIEnvironment* env, video::IVideoDriver* driver) 60 gui::IGUIEnvironment* env, video::IVideoDriver* driver)
61 { 61 {
62 // store pointer to room so we can change its drawing mode 62 // store pointer to room so we can change its drawing mode
63 Room = room; 63 Room = room;
64 Driver = driver; 64 Driver = driver;
65 65
66 // set a nicer font 66 // set a nicer font
67 gui::IGUISkin* skin = env->getSkin(); 67 gui::IGUISkin* skin = env->getSkin();
68 gui::IGUIFont* font = env->getFont("../../media/fonthaettenschweiler.bmp"); 68 gui::IGUIFont* font = env->getFont("../../media/fonthaettenschweiler.bmp");
69 if (font) 69 if (font)
70 skin->setFont(font); 70 skin->setFont(font);
71 71
72 // add window and listbox 72 // add window and listbox
73 gui::IGUIWindow* window = env->addWindow( 73 gui::IGUIWindow* window = env->addWindow(
74 core::rect<s32>(490,390,630,470), false, L"Use 'E' + 'R' to change"); 74 core::rect<s32>(490,390,630,470), false, L"Use 'E' + 'R' to change");
75 75
76 ListBox = env->addListBox( 76 ListBox = env->addListBox(
77 core::rect<s32>(2,22,135,78), window); 77 core::rect<s32>(2,22,135,78), window);
78 78
79 ListBox->addItem(L"Diffuse"); 79 ListBox->addItem(L"Diffuse");
80 ListBox->addItem(L"Bump mapping"); 80 ListBox->addItem(L"Bump mapping");
81 ListBox->addItem(L"Parallax mapping"); 81 ListBox->addItem(L"Parallax mapping");
82 ListBox->setSelected(1); 82 ListBox->setSelected(1);
83 83
84 // create problem text 84 // create problem text
85 ProblemText = env->addStaticText( 85 ProblemText = env->addStaticText(
86 L"Your hardware or this renderer is not able to use the "\ 86 L"Your hardware or this renderer is not able to use the "\
87 L"needed shaders for this material. Using fall back materials.", 87 L"needed shaders for this material. Using fall back materials.",
88 core::rect<s32>(150,20,470,60)); 88 core::rect<s32>(150,20,470,60));
89 89
90 ProblemText->setOverrideColor(video::SColor(100,255,255,255)); 90 ProblemText->setOverrideColor(video::SColor(100,255,255,255));
91 91
92 // set start material (prefer parallax mapping if available) 92 // set start material (prefer parallax mapping if available)
93 video::IMaterialRenderer* renderer = 93 video::IMaterialRenderer* renderer =
94 Driver->getMaterialRenderer(video::EMT_PARALLAX_MAP_SOLID); 94 Driver->getMaterialRenderer(video::EMT_PARALLAX_MAP_SOLID);
95 if (renderer && renderer->getRenderCapability() == 0) 95 if (renderer && renderer->getRenderCapability() == 0)
96 ListBox->setSelected(2); 96 ListBox->setSelected(2);
97 97
98 // set the material which is selected in the listbox 98 // set the material which is selected in the listbox
99 setMaterial(); 99 setMaterial();
100 } 100 }
101 101
102 bool OnEvent(const SEvent& event) 102 bool OnEvent(const SEvent& event)
103 { 103 {
104 // check if user presses the key 'E' or 'R' 104 // check if user presses the key 'E' or 'R'
105 if (event.EventType == irr::EET_KEY_INPUT_EVENT && 105 if (event.EventType == irr::EET_KEY_INPUT_EVENT &&
106 !event.KeyInput.PressedDown && Room && ListBox) 106 !event.KeyInput.PressedDown && Room && ListBox)
107 { 107 {
108 // change selected item in listbox 108 // change selected item in listbox
109 109
110 int sel = ListBox->getSelected(); 110 int sel = ListBox->getSelected();
111 if (event.KeyInput.Key == irr::KEY_KEY_R) 111 if (event.KeyInput.Key == irr::KEY_KEY_R)
112 ++sel; 112 ++sel;
113 else 113 else
114 if (event.KeyInput.Key == irr::KEY_KEY_E) 114 if (event.KeyInput.Key == irr::KEY_KEY_E)
115 --sel; 115 --sel;
116 else 116 else
117 return false; 117 return false;
118 118
119 if (sel > 2) sel = 0; 119 if (sel > 2) sel = 0;
120 if (sel < 0) sel = 2; 120 if (sel < 0) sel = 2;
121 ListBox->setSelected(sel); 121 ListBox->setSelected(sel);
122 122
123 // set the material which is selected in the listbox 123 // set the material which is selected in the listbox
124 setMaterial(); 124 setMaterial();
125 } 125 }
126 126
127 return false; 127 return false;
128 } 128 }
129 129
130private: 130private:
131 131
132 // sets the material of the room mesh the the one set in the 132 // sets the material of the room mesh the the one set in the
133 // list box. 133 // list box.
134 void setMaterial() 134 void setMaterial()
135 { 135 {
136 video::E_MATERIAL_TYPE type = video::EMT_SOLID; 136 video::E_MATERIAL_TYPE type = video::EMT_SOLID;
137 137
138 // change material setting 138 // change material setting
139 switch(ListBox->getSelected()) 139 switch(ListBox->getSelected())
140 { 140 {
141 case 0: type = video::EMT_SOLID; 141 case 0: type = video::EMT_SOLID;
142 break; 142 break;
143 case 1: type = video::EMT_NORMAL_MAP_SOLID; 143 case 1: type = video::EMT_NORMAL_MAP_SOLID;
144 break; 144 break;
145 case 2: type = video::EMT_PARALLAX_MAP_SOLID; 145 case 2: type = video::EMT_PARALLAX_MAP_SOLID;
146 break; 146 break;
147 } 147 }
148 148
149 Room->setMaterialType(type);</pre> 149 Room->setMaterialType(type);</pre>
150 </td> 150 </td>
151 </tr> 151 </tr>
152 </table> 152 </table>
153 <p>We need to add a warning if the materials will not be able to be 153 <p>We need to add a warning if the materials will not be able to be
154 displayed 100% correctly. This is no problem, they will be renderered 154 displayed 100% correctly. This is no problem, they will be renderered
155 using fall back materials, but at least the user should know that 155 using fall back materials, but at least the user should know that
156 it would look better on better hardware. We simply check if the material 156 it would look better on better hardware. We simply check if the material
157 renderer is able to draw at full quality on the current hardware. 157 renderer is able to draw at full quality on the current hardware.
158 The IMaterialRenderer::getRenderCapability() returns 0 if this is 158 The IMaterialRenderer::getRenderCapability() returns 0 if this is
159 the case.<br> 159 the case.<br>
160 </p> 160 </p>
161 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> 161 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
162 <tr> 162 <tr>
163 <td> <pre>video::IMaterialRenderer* renderer = Driver->getMaterialRenderer(type); 163 <td> <pre>video::IMaterialRenderer* renderer = Driver->getMaterialRenderer(type);
164 164
165 // display some problem text when problem 165 // display some problem text when problem
166 if (!renderer || renderer->getRenderCapability() != 0) 166 if (!renderer || renderer->getRenderCapability() != 0)
167 ProblemText->setVisible(true); 167 ProblemText->setVisible(true);
168 else 168 else
169 ProblemText->setVisible(false); 169 ProblemText->setVisible(false);
170 } 170 }
171 171
172private: 172private:
173 173
174 gui::IGUIStaticText* ProblemText; 174 gui::IGUIStaticText* ProblemText;
175 gui::IGUIListBox* ListBox; 175 gui::IGUIListBox* ListBox;
176 176
177 scene::ISceneNode* Room; 177 scene::ISceneNode* Room;
178 video::IVideoDriver* Driver; 178 video::IVideoDriver* Driver;
179};</pre></td> 179};</pre></td>
180 </tr> 180 </tr>
181 </table> 181 </table>
182 <p><br> 182 <p><br>
183 Now for the real fun. We create an Irrlicht Device and start to setup 183 Now for the real fun. We create an Irrlicht Device and start to setup
184 the scene.<br> 184 the scene.<br>
185 </p> 185 </p>
186 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> 186 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
187 <tr> 187 <tr>
188 <td> <pre>int main() 188 <td> <pre>int main()
189{ 189{
190 // let user select driver type 190 // let user select driver type
191 191
192 video::E_DRIVER_TYPE driverType = video::EDT_DIRECT3D9; 192 video::E_DRIVER_TYPE driverType = video::EDT_DIRECT3D9;
193<br> printf(&quot;Please select the driver you want for this example:\n&quot;\<br> &quot; (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.5\n&quot;\<br> &quot; (d) Software Renderer\n (e) Apfelbaum Software Renderer\n&quot;\<br> &quot; (f) NullDevice\n (otherKey) exit\n\n&quot;);<br> 193<br> printf(&quot;Please select the driver you want for this example:\n&quot;\<br> &quot; (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.5\n&quot;\<br> &quot; (d) Software Renderer\n (e) Apfelbaum Software Renderer\n&quot;\<br> &quot; (f) NullDevice\n (otherKey) exit\n\n&quot;);<br>
194 char i; 194 char i;
195 std::cin >> i; 195 std::cin >> i;
196 196
197 switch(i)<br> {<br> case 'a': driverType = video::EDT_DIRECT3D9;break;<br> case 'b': driverType = video::EDT_DIRECT3D8;break;<br> case 'c': driverType = video::EDT_OPENGL; break;<br> case 'd': driverType = video::EDT_SOFTWARE; break;<br> case 'e': driverType = video::EDT_BURNINGSVIDEO;break;<br> case 'f': driverType = video::EDT_NULL; break;<br> default: return 0;<br> } 197 switch(i)<br> {<br> case 'a': driverType = video::EDT_DIRECT3D9;break;<br> case 'b': driverType = video::EDT_DIRECT3D8;break;<br> case 'c': driverType = video::EDT_OPENGL; break;<br> case 'd': driverType = video::EDT_SOFTWARE; break;<br> case 'e': driverType = video::EDT_BURNINGSVIDEO;break;<br> case 'f': driverType = video::EDT_NULL; break;<br> default: return 0;<br> }
198 198
199 // create device 199 // create device
200 200
201 IrrlichtDevice* device = createDevice(driverType, core::dimension2d<s32>(640, 480)); 201 IrrlichtDevice* device = createDevice(driverType, core::dimension2d<s32>(640, 480));
202 202
203 if (device == 0) 203 if (device == 0)
204 return 1; // could not create selected driver. 204 return 1; // could not create selected driver.
205</pre></td> 205</pre></td>
206 </tr> 206 </tr>
207 </table> 207 </table>
208 <br> 208 <br>
209 Before we start with the interesting stuff, we do some simple things: 209 Before we start with the interesting stuff, we do some simple things:
210 Store pointers to the most important parts of the engine (video driver,<br> 210 Store pointers to the most important parts of the engine (video driver,<br>
211 scene manager, gui environment) to safe us from typing too much, add 211 scene manager, gui environment) to safe us from typing too much, add
212 an irrlicht engine logo to the window and a user controlled first person 212 an irrlicht engine logo to the window and a user controlled first person
213 shooter style camera. Also, we let the engine now that it should store 213 shooter style camera. Also, we let the engine now that it should store
214 all textures in 32 bit. This necessary because for parallax mapping, 214 all textures in 32 bit. This necessary because for parallax mapping,
215 we need 32 bit textures.<br> 215 we need 32 bit textures.<br>
216 <br> 216 <br>
217 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> 217 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
218 <tr> 218 <tr>
219 <td> <pre> 219 <td> <pre>
220 video::IVideoDriver* driver = device->getVideoDriver(); 220 video::IVideoDriver* driver = device->getVideoDriver();
221 scene::ISceneManager* smgr = device->getSceneManager(); 221 scene::ISceneManager* smgr = device->getSceneManager();
222 gui::IGUIEnvironment* env = device->getGUIEnvironment(); 222 gui::IGUIEnvironment* env = device->getGUIEnvironment();
223 223
224 driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true); 224 driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);
225 225
226 // add irrlicht logo 226 // add irrlicht logo
227 env->addImage(driver->getTexture("../../media/irrlichtlogoalpha.tga"), 227 env->addImage(driver->getTexture("../../media/irrlichtlogoalpha.tga"),
228 core::position2d<s32>(10,10)); 228 core::position2d<s32>(10,10));
229 229
230 // add camera 230 // add camera
231 scene::ICameraSceneNode* camera = 231 scene::ICameraSceneNode* camera =
232 smgr->addCameraSceneNodeFPS(0,100.0f,300.0f); 232 smgr->addCameraSceneNodeFPS(0,100.0f,300.0f);
233 camera->setPosition(core::vector3df(-200,200,-200)); 233 camera->setPosition(core::vector3df(-200,200,-200));
234 234
235 // disable mouse cursor 235 // disable mouse cursor
236 device->getCursorControl()->setVisible(false);</pre></td> 236 device->getCursorControl()->setVisible(false);</pre></td>
237 </tr> 237 </tr>
238 </table> 238 </table>
239 <br> 239 <br>
240 Because we want the whole scene to look a little bit scarier, we add 240 Because we want the whole scene to look a little bit scarier, we add
241 some fog to it. This is done by a call to IVideoDriver::setFog(). There 241 some fog to it. This is done by a call to IVideoDriver::setFog(). There
242 you can set<br> 242 you can set<br>
243 various fog settings. In this example, we use pixel fog, because it 243 various fog settings. In this example, we use pixel fog, because it
244 will work well with the materials we'll use in this example. Please 244 will work well with the materials we'll use in this example. Please
245 note that you will have to set the material flag EMF_FOG_ENABLE to 'true' 245 note that you will have to set the material flag EMF_FOG_ENABLE to 'true'
246 in every scene node which should be affected by this fog.<br> 246 in every scene node which should be affected by this fog.<br>
247 <br> 247 <br>
248 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> 248 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
249 <tr> 249 <tr>
250 <td> <pre>driver-&gt;setFog(video::SColor(0,138,125,81), true, 250, 1000, 0, true);<br></pre></td> 250 <td> <pre>driver-&gt;setFog(video::SColor(0,138,125,81), true, 250, 1000, 0, true);<br></pre></td>
251 </tr> 251 </tr>
252 </table> 252 </table>
253 <br> 253 <br>
254 To be able to display something interesting, we load a mesh from a .3ds 254 To be able to display something interesting, we load a mesh from a .3ds
255 file which is a room I modeled with anim8or. It is the same room as 255 file which is a room I modeled with anim8or. It is the same room as
256 <br> 256 <br>
257 from the specialFX example. Maybe you remember from that tutorial, I 257 from the specialFX example. Maybe you remember from that tutorial, I
258 am no good modeler at all and so I totally messed up the texture mapping 258 am no good modeler at all and so I totally messed up the texture mapping
259 in this model, but we can simply repair it with the IMeshManipulator::makePlanarTextureMapping() 259 in this model, but we can simply repair it with the IMeshManipulator::makePlanarTextureMapping()
260 method.<br> 260 method.<br>
261 <br> 261 <br>
262 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> 262 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
263 <tr> 263 <tr>
264 <td> <pre> scene::IAnimatedMesh* roomMesh = smgr->getMesh( 264 <td> <pre> scene::IAnimatedMesh* roomMesh = smgr->getMesh(
265 "../../media/room.3ds"); 265 "../../media/room.3ds");
266 scene::ISceneNode* room = 0; 266 scene::ISceneNode* room = 0;
267 267
268 if (roomMesh) 268 if (roomMesh)
269 { 269 {
270 smgr->getMeshManipulator()->makePlanarTextureMapping( 270 smgr->getMeshManipulator()->makePlanarTextureMapping(
271 roomMesh->getMesh(0), 0.003f);</pre></td> 271 roomMesh->getMesh(0), 0.003f);</pre></td>
272 </tr> 272 </tr>
273 </table> 273 </table>
274 <br> 274 <br>
275 Now for the first exciting thing: If we successfully loaded the mesh 275 Now for the first exciting thing: If we successfully loaded the mesh
276 we need to apply textures to it. Because we want this room to be displayed 276 we need to apply textures to it. Because we want this room to be displayed
277 with a very cool material, we have to do a little bit more than just 277 with a very cool material, we have to do a little bit more than just
278 set the textures. Instead of only loading a color map as usual, we also 278 set the textures. Instead of only loading a color map as usual, we also
279 load a height map which is simply a grayscale texture. From this height 279 load a height map which is simply a grayscale texture. From this height
280 map, we create a normal map which we will set as second texture of the 280 map, we create a normal map which we will set as second texture of the
281 room. If you already have a normal map, you could directly set it, but 281 room. If you already have a normal map, you could directly set it, but
282 I simply didn&acute;t find a nice normal map for this texture. The normal 282 I simply didn&acute;t find a nice normal map for this texture. The normal
283 map texture is being generated by the makeNormalMapTexture method<br> 283 map texture is being generated by the makeNormalMapTexture method<br>
284 of the VideoDriver. The second parameter specifies the height of the 284 of the VideoDriver. The second parameter specifies the height of the
285 heightmap. If you set it to a bigger value, the map will look more rocky.<br> 285 heightmap. If you set it to a bigger value, the map will look more rocky.<br>
286 <br> 286 <br>
287 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> 287 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
288 <tr> 288 <tr>
289 <td> <pre> video::ITexture* colorMap = driver->getTexture("../../media/rockwall.bmp"); 289 <td> <pre> video::ITexture* colorMap = driver->getTexture("../../media/rockwall.bmp");
290 video::ITexture* normalMap = driver->getTexture("../../media/rockwall_height.bmp"); 290 video::ITexture* normalMap = driver->getTexture("../../media/rockwall_height.bmp");
291 291
292 driver->makeNormalMapTexture(normalMap, 9.0f);</pre></td> 292 driver->makeNormalMapTexture(normalMap, 9.0f);</pre></td>
293 </tr> 293 </tr>
294 </table> 294 </table>
295 <br> 295 <br>
296 But just setting color and normal map is not everything. The material 296 But just setting color and normal map is not everything. The material
297 we want to use needs some additional informations per vertex like tangents 297 we want to use needs some additional informations per vertex like tangents
298 and binormals.<br> 298 and binormals.<br>
299 Because we are too lazy to calculate that information now, we let Irrlicht 299 Because we are too lazy to calculate that information now, we let Irrlicht
300 do this for us. That's why we call IMeshManipulator::createMeshWithTangents(). 300 do this for us. That's why we call IMeshManipulator::createMeshWithTangents().
301 It<br> 301 It<br>
302 creates a mesh copy with tangents and binormals from any other mesh. 302 creates a mesh copy with tangents and binormals from any other mesh.
303 After we've done that, we simply create a standard mesh scene node with 303 After we've done that, we simply create a standard mesh scene node with
304 this<br> 304 this<br>
305 mesh copy, set color and normal map and adjust some other material settings. 305 mesh copy, set color and normal map and adjust some other material settings.
306 Note that we set EMF_FOG_ENABLE to true to enable fog in the room.<br> 306 Note that we set EMF_FOG_ENABLE to true to enable fog in the room.<br>
307 <br> 307 <br>
308 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> 308 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
309 <tr> 309 <tr>
310 <td> <pre>scene::IMesh* tangentMesh = smgr-&gt;getMeshManipulator()-&gt;createMeshWithTangents(<br> roomMesh-&gt;getMesh(0));<br> <br> room = smgr-&gt;addMeshSceneNode(tangentMesh);<br> room-&gt;setMaterialTexture(0, colorMap);<br> room-&gt;setMaterialTexture(1, normalMap);<br> room-&gt;getMaterial(0).SpecularColor.set(0,0,0,0);<br> room-&gt;setMaterialFlag(video::EMF_FOG_ENABLE, true);<br> room-&gt;setMaterialType(video::EMT_PARALLAX_MAP_SOLID); <br> room-&gt;getMaterial(0).MaterialTypeParam = 0.02f; // adjust height for parallax effect<br> // drop mesh because we created it with a create.. call.<br> tangentMesh-&gt;drop();<br> }<br></pre></td> 310 <td> <pre>scene::IMesh* tangentMesh = smgr-&gt;getMeshManipulator()-&gt;createMeshWithTangents(<br> roomMesh-&gt;getMesh(0));<br> <br> room = smgr-&gt;addMeshSceneNode(tangentMesh);<br> room-&gt;setMaterialTexture(0, colorMap);<br> room-&gt;setMaterialTexture(1, normalMap);<br> room-&gt;getMaterial(0).SpecularColor.set(0,0,0,0);<br> room-&gt;setMaterialFlag(video::EMF_FOG_ENABLE, true);<br> room-&gt;setMaterialType(video::EMT_PARALLAX_MAP_SOLID); <br> room-&gt;getMaterial(0).MaterialTypeParam = 0.02f; // adjust height for parallax effect<br> // drop mesh because we created it with a create.. call.<br> tangentMesh-&gt;drop();<br> }<br></pre></td>
311 </tr> 311 </tr>
312 </table> 312 </table>
313 <br> 313 <br>
314 After we've created a room shaded by per pixel lighting, we add a sphere 314 After we've created a room shaded by per pixel lighting, we add a sphere
315 into it with the same material, but we'll make it transparent. In addition,<br> 315 into it with the same material, but we'll make it transparent. In addition,<br>
316 because the sphere looks somehow like a familiar planet, we make it 316 because the sphere looks somehow like a familiar planet, we make it
317 rotate. The procedure is similar as before. The difference is that we 317 rotate. The procedure is similar as before. The difference is that we
318 are loading <br> 318 are loading <br>
319 the mesh from an .x file which already contains a color map so we do 319 the mesh from an .x file which already contains a color map so we do
320 not need to load it manually. But the sphere is a little bit too small 320 not need to load it manually. But the sphere is a little bit too small
321 for our needs, so we scale it by the factor 50.<br> 321 for our needs, so we scale it by the factor 50.<br>
322 <br> 322 <br>
323 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> 323 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
324 <tr> 324 <tr>
325 <td> <pre>// add earth sphere 325 <td> <pre>// add earth sphere
326 326
327 scene::IAnimatedMesh* earthMesh = smgr->getMesh("../../media/earth.x"); 327 scene::IAnimatedMesh* earthMesh = smgr->getMesh("../../media/earth.x");
328 if (earthMesh) 328 if (earthMesh)
329 { 329 {
330 // create mesh copy with tangent informations from original earth.x mesh 330 // create mesh copy with tangent informations from original earth.x mesh
331 scene::IMesh* tangentSphereMesh = 331 scene::IMesh* tangentSphereMesh =
332 smgr->getMeshManipulator()->createMeshWithTangents(earthMesh->getMesh(0)); 332 smgr->getMeshManipulator()->createMeshWithTangents(earthMesh->getMesh(0));
333 333
334 // set the alpha value of all vertices to 200 334 // set the alpha value of all vertices to 200
335 smgr->getMeshManipulator()->setVertexColorAlpha(tangentSphereMesh, 200); 335 smgr->getMeshManipulator()->setVertexColorAlpha(tangentSphereMesh, 200);
336 336
337 // scale the mesh by factor 50 337 // scale the mesh by factor 50
338 smgr->getMeshManipulator()->scaleMesh( 338 smgr->getMeshManipulator()->scaleMesh(
339 tangentSphereMesh, core::vector3df(50,50,50)); 339 tangentSphereMesh, core::vector3df(50,50,50));
340 340
341 // create mesh scene node 341 // create mesh scene node
342 scene::ISceneNode* sphere = smgr->addMeshSceneNode(tangentSphereMesh); 342 scene::ISceneNode* sphere = smgr->addMeshSceneNode(tangentSphereMesh);
343 sphere->setPosition(core::vector3df(-70,130,45)); 343 sphere->setPosition(core::vector3df(-70,130,45));
344 344
345 // load heightmap, create normal map from it and set it 345 // load heightmap, create normal map from it and set it
346 video::ITexture* earthNormalMap = driver->getTexture("../../media/earthbump.bmp"); 346 video::ITexture* earthNormalMap = driver->getTexture("../../media/earthbump.bmp");
347 driver->makeNormalMapTexture(earthNormalMap, 20.0f); 347 driver->makeNormalMapTexture(earthNormalMap, 20.0f);
348 sphere->setMaterialTexture(1, earthNormalMap); 348 sphere->setMaterialTexture(1, earthNormalMap);
349 349
350 // adjust material settings 350 // adjust material settings
351 sphere->setMaterialFlag(video::EMF_FOG_ENABLE, true); 351 sphere->setMaterialFlag(video::EMF_FOG_ENABLE, true);
352 sphere->setMaterialType(video::EMT_NORMAL_MAP_TRANSPARENT_VERTEX_ALPHA); 352 sphere->setMaterialType(video::EMT_NORMAL_MAP_TRANSPARENT_VERTEX_ALPHA);
353 353
354 // add rotation animator 354 // add rotation animator
355 scene::ISceneNodeAnimator* anim = 355 scene::ISceneNodeAnimator* anim =
356 smgr->createRotationAnimator(core::vector3df(0,0.1f,0)); 356 smgr->createRotationAnimator(core::vector3df(0,0.1f,0));
357 sphere->addAnimator(anim); 357 sphere->addAnimator(anim);
358 anim->drop(); 358 anim->drop();
359 359
360 // drop mesh because we created it with a create.. call. 360 // drop mesh because we created it with a create.. call.
361 tangentSphereMesh->drop(); 361 tangentSphereMesh->drop();
362 }</pre></td> 362 }</pre></td>
363 </tr> 363 </tr>
364 </table> 364 </table>
365 <br> 365 <br>
366 Per pixel lighted materials only look cool when there are moving lights. 366 Per pixel lighted materials only look cool when there are moving lights.
367 So we add some. And because moving lights alone are so boring, we add 367 So we add some. And because moving lights alone are so boring, we add
368 billboards <br> 368 billboards <br>
369 to them, and a whole particle system to one of them. We start with the 369 to them, and a whole particle system to one of them. We start with the
370 first light which is red and has only the billboard attached.<br> 370 first light which is red and has only the billboard attached.<br>
371 <br> 371 <br>
372 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> 372 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
373 <tr> 373 <tr>
374 <td> <pre>// add light 1 (nearly red) 374 <td> <pre>// add light 1 (nearly red)
375 scene::ILightSceneNode* light1 = 375 scene::ILightSceneNode* light1 =
376 smgr->addLightSceneNode(0, core::vector3df(0,0,0), 376 smgr->addLightSceneNode(0, core::vector3df(0,0,0),
377 video::SColorf(0.5f, 1.0f, 0.5f, 0.0f), 200.0f); 377 video::SColorf(0.5f, 1.0f, 0.5f, 0.0f), 200.0f);
378 378
379 // add fly circle animator to light 1 379 // add fly circle animator to light 1
380 scene::ISceneNodeAnimator* anim = 380 scene::ISceneNodeAnimator* anim =
381 smgr->createFlyCircleAnimator (core::vector3df(50,300,0),190.0f, -0.003f); 381 smgr->createFlyCircleAnimator (core::vector3df(50,300,0),190.0f, -0.003f);
382 light1->addAnimator(anim); 382 light1->addAnimator(anim);
383 anim->drop(); 383 anim->drop();
384 384
385 // attach billboard to the light 385 // attach billboard to the light
386 scene::ISceneNode* bill = 386 scene::ISceneNode* bill =
387 smgr->addBillboardSceneNode(light1, core::dimension2d<f32>(60, 60)); 387 smgr->addBillboardSceneNode(light1, core::dimension2d<f32>(60, 60));
388 388
389 bill->setMaterialFlag(video::EMF_LIGHTING, false); 389 bill->setMaterialFlag(video::EMF_LIGHTING, false);
390 bill->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR); 390 bill->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
391 bill->setMaterialTexture(0, driver->getTexture("../../media/particlered.bmp"));</pre></td> 391 bill->setMaterialTexture(0, driver->getTexture("../../media/particlered.bmp"));</pre></td>
392 </tr> 392 </tr>
393 </table> 393 </table>
394 <br> 394 <br>
395 Now the same again, with the second light. The difference is that we 395 Now the same again, with the second light. The difference is that we
396 add a particle system to it too. And because the light moves, the particles 396 add a particle system to it too. And because the light moves, the particles
397 of the particlesystem will follow. If you want to know more about how 397 of the particlesystem will follow. If you want to know more about how
398 particle systems are created in Irrlicht, take a look at the specialFx 398 particle systems are created in Irrlicht, take a look at the specialFx
399 example.<br> 399 example.<br>
400 Maybe you will have noticed that we only add 2 lights, this has a simple 400 Maybe you will have noticed that we only add 2 lights, this has a simple
401 reason: The low end version of this material was written in ps1.1 and 401 reason: The low end version of this material was written in ps1.1 and
402 vs1.1, which doesn't allow more lights. You could add a third light 402 vs1.1, which doesn't allow more lights. You could add a third light
403 to the scene, but it won't be used to shade the walls. But of course, 403 to the scene, but it won't be used to shade the walls. But of course,
404 this will change in future versions of Irrlicht were higher versions 404 this will change in future versions of Irrlicht were higher versions
405 of pixel/vertex shaders will be implemented too.<br> 405 of pixel/vertex shaders will be implemented too.<br>
406 <br> 406 <br>
407 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> 407 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
408 <tr> 408 <tr>
409 <td> <pre>// add light 2 (gray) 409 <td> <pre>// add light 2 (gray)
410 scene::ISceneNode* light2 = 410 scene::ISceneNode* light2 =
411 smgr->addLightSceneNode(0, core::vector3df(0,0,0), 411 smgr->addLightSceneNode(0, core::vector3df(0,0,0),
412 video::SColorf(1.0f, 0.2f, 0.2f, 0.0f), 200.0f); 412 video::SColorf(1.0f, 0.2f, 0.2f, 0.0f), 200.0f);
413 413
414 // add fly circle animator to light 2 414 // add fly circle animator to light 2
415 anim = smgr->createFlyCircleAnimator (core::vector3df(0,150,0),200.0f); 415 anim = smgr->createFlyCircleAnimator (core::vector3df(0,150,0),200.0f);
416 light2->addAnimator(anim); 416 light2->addAnimator(anim);
417 anim->drop(); 417 anim->drop();
418 418
419 // attach billboard to light 419 // attach billboard to light
420 bill = smgr->addBillboardSceneNode(light2, core::dimension2d<f32>(120, 120)); 420 bill = smgr->addBillboardSceneNode(light2, core::dimension2d<f32>(120, 120));
421 bill->setMaterialFlag(video::EMF_LIGHTING, false); 421 bill->setMaterialFlag(video::EMF_LIGHTING, false);
422 bill->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR); 422 bill->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
423 bill->setMaterialTexture(0, driver->getTexture("../../media/particlewhite.bmp")); 423 bill->setMaterialTexture(0, driver->getTexture("../../media/particlewhite.bmp"));
424 424
425 // add particle system 425 // add particle system
426 scene::IParticleSystemSceneNode* ps = 426 scene::IParticleSystemSceneNode* ps =
427 smgr->addParticleSystemSceneNode(false, light2); 427 smgr->addParticleSystemSceneNode(false, light2);
428 428
429 ps->setParticleSize(core::dimension2d<f32>(30.0f, 40.0f)); 429 ps->setParticleSize(core::dimension2d<f32>(30.0f, 40.0f));
430 430
431 // create and set emitter 431 // create and set emitter
432 scene::IParticleEmitter* em = ps->createBoxEmitter( 432 scene::IParticleEmitter* em = ps->createBoxEmitter(
433 core::aabbox3d<f32>(-3,0,-3,3,1,3), 433 core::aabbox3d<f32>(-3,0,-3,3,1,3),
434 core::vector3df(0.0f,0.03f,0.0f), 434 core::vector3df(0.0f,0.03f,0.0f),
435 80,100, 435 80,100,
436 video::SColor(0,255,255,255), video::SColor(0,255,255,255), 436 video::SColor(0,255,255,255), video::SColor(0,255,255,255),
437 400,1100); 437 400,1100);
438 ps->setEmitter(em); 438 ps->setEmitter(em);
439 em->drop(); 439 em->drop();
440 440
441 // create and set affector 441 // create and set affector
442 scene::IParticleAffector* paf = ps->createFadeOutParticleAffector(); 442 scene::IParticleAffector* paf = ps->createFadeOutParticleAffector();
443 ps->addAffector(paf); 443 ps->addAffector(paf);
444 paf->drop(); 444 paf->drop();
445 445
446 // adjust some material settings 446 // adjust some material settings
447 ps->setMaterialFlag(video::EMF_LIGHTING, false); 447 ps->setMaterialFlag(video::EMF_LIGHTING, false);
448 ps->setMaterialTexture(0, driver->getTexture("../../media/fireball.bmp")); 448 ps->setMaterialTexture(0, driver->getTexture("../../media/fireball.bmp"));
449 ps->setMaterialType(video::EMT_TRANSPARENT_VERTEX_ALPHA); 449 ps->setMaterialType(video::EMT_TRANSPARENT_VERTEX_ALPHA);
450 450
451 451
452 MyEventReceiver receiver(room, env, driver); 452 MyEventReceiver receiver(room, env, driver);
453 device->setEventReceiver(&receiver);</pre></td> 453 device->setEventReceiver(&receiver);</pre></td>
454 </tr> 454 </tr>
455 </table> 455 </table>
456 <br> 456 <br>
457 Finally, draw everything. That's it.<br> 457 Finally, draw everything. That's it.<br>
458 <br> 458 <br>
459 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> 459 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
460 <tr> 460 <tr>
461 <td> <pre>int lastFPS = -1; 461 <td> <pre>int lastFPS = -1;
462 462
463 while(device->run()) 463 while(device->run())
464 if (device->isWindowActive()) 464 if (device->isWindowActive())
465 { 465 {
466 driver->beginScene(true, true, 0); 466 driver->beginScene(true, true, 0);
467 467
468 smgr->drawAll(); 468 smgr->drawAll();
469 env->drawAll(); 469 env->drawAll();
470 470
471 driver->endScene(); 471 driver->endScene();
472 472
473 int fps = driver->getFPS(); 473 int fps = driver->getFPS();
474 474
475 if (lastFPS != fps) 475 if (lastFPS != fps)
476 { 476 {
477 core::stringw str = L"Per pixel lighting example - Irrlicht Engine ["; 477 core::stringw str = L"Per pixel lighting example - Irrlicht Engine [";
478 str += driver->getName(); 478 str += driver->getName();
479 str += "] FPS:"; 479 str += "] FPS:";
480 str += fps; 480 str += fps;
481 481
482 device->setWindowCaption(str.c_str()); 482 device->setWindowCaption(str.c_str());
483 lastFPS = fps; 483 lastFPS = fps;
484 } 484 }
485 } 485 }
486 486
487 device->drop(); 487 device->drop();
488 488
489 return 0; 489 return 0;
490} 490}
491</pre></td> 491</pre></td>
492 </tr> 492 </tr>
493 </table> 493 </table>
494 <br> 494 <br>
495 </div> 495 </div>
496 </div> 496 </div>
497 </td> 497 </td>
498 </tr> 498 </tr>
499</table> 499</table>
500<p>&nbsp;</p> 500<p>&nbsp;</p>
501 </body> 501 </body>
502</html> 502</html>