Sophie

Sophie

distrib > Mandriva > 2010.1 > x86_64 > by-pkgid > 58828b263d8f56d90ac336dea07a4586 > files > 742

irrlicht-doc-1.6.1-1mdv2010.1.x86_64.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>Irrlicht Engine: Tutorial 11: Per-Pixel Lighting</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<table class="irrlicht" >
  <tr valign="middle"> 
    <td><font size="2"><a class="qindex" href="index.html"><font color="#FFFFFF">Home</font></a> 
      | <a class="qindex" href="namespaces.html"><font color="#FFFFFF">Namespaces</font></a> 
      | <a class="qindex" href="hierarchy.html"><font color="#FFFFFF">Hierarchy</font></a> 
      | <a class="qindex" href="classes.html"><font color="#FFFFFF">Alphabetical 
      List</font></a> | <a class="qindex" href="annotated.html"><font color="#FFFFFF"> 
      Class list</font></a> | <a class="qindex" href="files.html"><font color="#FFFFFF">Files</font></a> 
      | <a class="qindex" href="namespacemembers.html"><font color="#FFFFFF"> 
      Namespace&nbsp;Members</font></a> | <a class="qindex" href="functions.html"><font color="#FFFFFF">Class 
      members</font></a> | <a class="qindex" href="globals.html"><font color="#FFFFFF">File 
      members</font></a> | <a class="qindex" href="pages.html"><font color="#FFFFFF">Tutorials</font></a></font> </td>
  </tr>
</table>
<!-- Generated by Doxygen 1.5.6 -->
<div class="contents">
<h1><a class="anchor" name="example011">Tutorial 11: Per-Pixel Lighting </a></h1><div align="center">
<img src="011shot.jpg" alt="011shot.jpg">
</div>
 <p>
This tutorial shows how to use one of the built in more complex materials in irrlicht: Per pixel lighted surfaces using normal maps and parallax mapping. It will also show how to use fog and moving particle systems. And don't panic: You dont need any experience with shaders to use these materials in Irrlicht.<p>
At first, we need to include all headers and do the stuff we always do, like in nearly all other tutorials. <div class="fragment"><pre class="fragment"><span class="preprocessor">#include &lt;<a class="code" href="irrlicht_8h.html" title="Main header file of the irrlicht, the only file needed to include.">irrlicht.h</a>&gt;</span>
<span class="preprocessor">#include &lt;iostream&gt;</span>

<span class="keyword">using namespace </span>irr;

<span class="preprocessor">#ifdef _MSC_VER</span>
<span class="preprocessor"></span><span class="preprocessor">#pragma comment(lib, "Irrlicht.lib")</span>
<span class="preprocessor">#endif</span>
</pre></div><p>
For this example, we need an event receiver, to make it possible for the user to switch between the three available material types. In addition, the event receiver will create some small GUI window which displays what material is currently being used. There is nothing special done in this class, so maybe you want to skip reading it. <div class="fragment"><pre class="fragment"><span class="keyword">class </span>MyEventReceiver : <span class="keyword">public</span> IEventReceiver
{
<span class="keyword">public</span>:

        MyEventReceiver(scene::ISceneNode* room,
                gui::IGUIEnvironment* env, video::IVideoDriver* driver)
        {
                <span class="comment">// store pointer to room so we can change its drawing mode</span>
                Room = room;
                Driver = driver;

                <span class="comment">// set a nicer font</span>
                gui::IGUISkin* skin = env-&gt;getSkin();
                gui::IGUIFont* font = env-&gt;getFont(<span class="stringliteral">"../../media/fonthaettenschweiler.bmp"</span>);
                <span class="keywordflow">if</span> (font)
                        skin-&gt;setFont(font);

                <span class="comment">// add window and listbox</span>
                gui::IGUIWindow* window = env-&gt;addWindow(
                        core::rect&lt;s32&gt;(460,375,630,470), <span class="keyword">false</span>, L<span class="stringliteral">"Use 'E' + 'R' to change"</span>);

                ListBox = env-&gt;addListBox(
                        core::rect&lt;s32&gt;(2,22,165,88), window);

                ListBox-&gt;addItem(L<span class="stringliteral">"Diffuse"</span>);
                ListBox-&gt;addItem(L<span class="stringliteral">"Bump mapping"</span>);
                ListBox-&gt;addItem(L<span class="stringliteral">"Parallax mapping"</span>);
                ListBox-&gt;setSelected(1);

                <span class="comment">// create problem text</span>
                ProblemText = env-&gt;addStaticText(
                        L<span class="stringliteral">"Your hardware or this renderer is not able to use the "</span>\
                        L<span class="stringliteral">"needed shaders for this material. Using fall back materials."</span>,
                        core::rect&lt;s32&gt;(150,20,470,80));

                ProblemText-&gt;setOverrideColor(video::SColor(100,255,255,255));

                <span class="comment">// set start material (prefer parallax mapping if available)</span>
                video::IMaterialRenderer* renderer =
                        Driver-&gt;getMaterialRenderer(<a class="code" href="namespaceirr_1_1video.html#c8e9b6c66f7cebabd1a6d30cbc5430f1833aaad409476c3c4baf59e2d1096f4a" title="Just like EMT_NORMAL_MAP_SOLID, but uses parallax mapping.">video::EMT_PARALLAX_MAP_SOLID</a>);
                <span class="keywordflow">if</span> (renderer &amp;&amp; renderer-&gt;getRenderCapability() == 0)
                        ListBox-&gt;setSelected(2);

                <span class="comment">// set the material which is selected in the listbox</span>
                setMaterial();
        }

        <span class="keywordtype">bool</span> OnEvent(<span class="keyword">const</span> SEvent&amp; event)
        {
                <span class="comment">// check if user presses the key 'E' or 'R'</span>
                <span class="keywordflow">if</span> (event.EventType == <a class="code" href="namespaceirr.html#c9eed96e06e85ce3c86fcbbbe9e48a0c6f90390f3147a1693e5e2e3422d6ca09" title="A key input event.">irr::EET_KEY_INPUT_EVENT</a> &amp;&amp;
                        !event.KeyInput.PressedDown &amp;&amp; Room &amp;&amp; ListBox)
                {
                        <span class="comment">// change selected item in listbox</span>

                        <span class="keywordtype">int</span> sel = ListBox-&gt;getSelected();
                        <span class="keywordflow">if</span> (event.KeyInput.Key == <a class="code" href="namespaceirr.html#54da2a0e231901735e3da1b0edf72eb369dba8cbd4fc6825c6ac18ebe13c6eba">irr::KEY_KEY_R</a>)
                                ++sel;
                        <span class="keywordflow">else</span>
                        <span class="keywordflow">if</span> (event.KeyInput.Key == <a class="code" href="namespaceirr.html#54da2a0e231901735e3da1b0edf72eb3f378ce3d6f5cbd09a1ae4ec8f44a0079">irr::KEY_KEY_E</a>)
                                --sel;
                        <span class="keywordflow">else</span>
                                <span class="keywordflow">return</span> <span class="keyword">false</span>;

                        <span class="keywordflow">if</span> (sel &gt; 2) sel = 0;
                        <span class="keywordflow">if</span> (sel &lt; 0) sel = 2;
                        ListBox-&gt;setSelected(sel);

                        <span class="comment">// set the material which is selected in the listbox</span>
                        setMaterial();
                }

                <span class="keywordflow">return</span> <span class="keyword">false</span>;
        }

<span class="keyword">private</span>:

        <span class="comment">// sets the material of the room mesh the the one set in the</span>
        <span class="comment">// list box.</span>
        <span class="keywordtype">void</span> setMaterial()
        {
                <a class="code" href="namespaceirr_1_1video.html#c8e9b6c66f7cebabd1a6d30cbc5430f1" title="Abstracted and easy to use fixed function/programmable pipeline material modes.">video::E_MATERIAL_TYPE</a> type = <a class="code" href="namespaceirr_1_1video.html#c8e9b6c66f7cebabd1a6d30cbc5430f19bc471b9c18c9e2d20496004d2a2e803" title="Standard solid material.">video::EMT_SOLID</a>;

                <span class="comment">// change material setting</span>
                <span class="keywordflow">switch</span>(ListBox-&gt;getSelected())
                {
                <span class="keywordflow">case</span> 0: type = <a class="code" href="namespaceirr_1_1video.html#c8e9b6c66f7cebabd1a6d30cbc5430f19bc471b9c18c9e2d20496004d2a2e803" title="Standard solid material.">video::EMT_SOLID</a>;
                        <span class="keywordflow">break</span>;
                <span class="keywordflow">case</span> 1: type = <a class="code" href="namespaceirr_1_1video.html#c8e9b6c66f7cebabd1a6d30cbc5430f189220ece17ea7d54a530de9756734c70" title="A solid normal map renderer.">video::EMT_NORMAL_MAP_SOLID</a>;
                        <span class="keywordflow">break</span>;
                <span class="keywordflow">case</span> 2: type = <a class="code" href="namespaceirr_1_1video.html#c8e9b6c66f7cebabd1a6d30cbc5430f1833aaad409476c3c4baf59e2d1096f4a" title="Just like EMT_NORMAL_MAP_SOLID, but uses parallax mapping.">video::EMT_PARALLAX_MAP_SOLID</a>;
                        <span class="keywordflow">break</span>;
                }

                Room-&gt;setMaterialType(type);
</pre></div><p>
We need to add a warning if the materials will not be able to be displayed 100% correctly. This is no problem, they will be renderered using fall back materials, but at least the user should know that it would look better on better hardware. We simply check if the material renderer is able to draw at full quality on the current hardware. The IMaterialRenderer::getRenderCapability() returns 0 if this is the case. <div class="fragment"><pre class="fragment">                video::IMaterialRenderer* renderer = Driver-&gt;getMaterialRenderer(type);

                <span class="comment">// display some problem text when problem</span>
                <span class="keywordflow">if</span> (!renderer || renderer-&gt;getRenderCapability() != 0)
                        ProblemText-&gt;setVisible(<span class="keyword">true</span>);
                <span class="keywordflow">else</span>
                        ProblemText-&gt;setVisible(<span class="keyword">false</span>);
        }

<span class="keyword">private</span>:

        gui::IGUIStaticText* ProblemText;
        gui::IGUIListBox* ListBox;

        scene::ISceneNode* Room;
        video::IVideoDriver* Driver;
};
</pre></div><p>
Now for the real fun. We create an Irrlicht Device and start to setup the scene. <div class="fragment"><pre class="fragment"><span class="keywordtype">int</span> main()
{
        <span class="comment">// let user select driver type</span>

        <a class="code" href="namespaceirr_1_1video.html#e35a6de6d436c76107ad157fe42356d0" title="An enum for all types of drivers the Irrlicht Engine supports.">video::E_DRIVER_TYPE</a> driverType = <a class="code" href="namespaceirr_1_1video.html#e35a6de6d436c76107ad157fe42356d04691ca314f9018f508dcf2c57dcaacec" title="Direct3D 9 device, only available on Win32 platforms.">video::EDT_DIRECT3D9</a>;

        printf(<span class="stringliteral">"Please select the driver you want for this example:\n"</span>\
                <span class="stringliteral">" (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.5\n"</span>\
                <span class="stringliteral">" (d) Software Renderer\n (e) Burning's Software Renderer\n"</span>\
                <span class="stringliteral">" (f) NullDevice\n (otherKey) exit\n\n"</span>);

        <span class="keywordtype">char</span> i;
        std::cin &gt;&gt; i;

        <span class="keywordflow">switch</span>(i)
        {
                <span class="keywordflow">case</span> <span class="charliteral">'a'</span>: driverType = <a class="code" href="namespaceirr_1_1video.html#e35a6de6d436c76107ad157fe42356d04691ca314f9018f508dcf2c57dcaacec" title="Direct3D 9 device, only available on Win32 platforms.">video::EDT_DIRECT3D9</a>;<span class="keywordflow">break</span>;
                <span class="keywordflow">case</span> <span class="charliteral">'b'</span>: driverType = <a class="code" href="namespaceirr_1_1video.html#e35a6de6d436c76107ad157fe42356d08cc3807f6f28404f3424ad7e31b3142f" title="Direct3D8 device, only available on Win32 platforms.">video::EDT_DIRECT3D8</a>;<span class="keywordflow">break</span>;
                <span class="keywordflow">case</span> <span class="charliteral">'c'</span>: driverType = <a class="code" href="namespaceirr_1_1video.html#e35a6de6d436c76107ad157fe42356d02715182a79f1cb8e2826fd68a8150a53" title="OpenGL device, available on most platforms.">video::EDT_OPENGL</a>;   <span class="keywordflow">break</span>;
                <span class="keywordflow">case</span> <span class="charliteral">'d'</span>: driverType = <a class="code" href="namespaceirr_1_1video.html#e35a6de6d436c76107ad157fe42356d01598cd235a1a6bd052e2011b559e8995" title="The Irrlicht Engine Software renderer.">video::EDT_SOFTWARE</a>; <span class="keywordflow">break</span>;
                <span class="keywordflow">case</span> <span class="charliteral">'e'</span>: driverType = <a class="code" href="namespaceirr_1_1video.html#e35a6de6d436c76107ad157fe42356d0e85481da26159b967191ccc6de1e4a05" title="The Burning&amp;#39;s Software Renderer, an alternative software renderer.">video::EDT_BURNINGSVIDEO</a>;<span class="keywordflow">break</span>;
                <span class="keywordflow">case</span> <span class="charliteral">'f'</span>: driverType = <a class="code" href="namespaceirr_1_1video.html#e35a6de6d436c76107ad157fe42356d0cfdbd476cbfd4d05e72f9adffcc42210" title="Null driver, useful for applications to run the engine without visualisation.">video::EDT_NULL</a>;     <span class="keywordflow">break</span>;
                <span class="keywordflow">default</span>: <span class="keywordflow">return</span> 0;
        }

        <span class="comment">// create device</span>

        IrrlichtDevice* device = <a class="code" href="namespaceirr.html#baf4d8719cc26b0d30813abf85e47c76" title="Creates an Irrlicht device. The Irrlicht device is the root object for using the...">createDevice</a>(driverType,
                        core::dimension2d&lt;u32&gt;(640, 480));

        <span class="keywordflow">if</span> (device == 0)
                <span class="keywordflow">return</span> 1; <span class="comment">// could not create selected driver.</span>
</pre></div><p>
Before we start with the interesting stuff, we do some simple things: Store pointers to the most important parts of the engine (video driver, scene manager, gui environment) to safe us from typing too much, add an irrlicht engine logo to the window and a user controlled first person shooter style camera. Also, we let the engine know that it should store all textures in 32 bit. This necessary because for parallax mapping, we need 32 bit textures. <div class="fragment"><pre class="fragment">        video::IVideoDriver* driver = device-&gt;getVideoDriver();
        scene::ISceneManager* smgr = device-&gt;getSceneManager();
        gui::IGUIEnvironment* env = device-&gt;getGUIEnvironment();

        driver-&gt;setTextureCreationFlag(<a class="code" href="namespaceirr_1_1video.html#caf6f7414534f7d62bff18c5bf11876f20881e307a778c4a4fbb5327a60a93bb">video::ETCF_ALWAYS_32_BIT</a>, <span class="keyword">true</span>);

        <span class="comment">// add irrlicht logo</span>
        env-&gt;addImage(driver-&gt;getTexture(<span class="stringliteral">"../../media/irrlichtlogo2.png"</span>),
                core::position2d&lt;s32&gt;(10,10));

        <span class="comment">// add camera</span>
        scene::ICameraSceneNode* camera = smgr-&gt;addCameraSceneNodeFPS();
        camera-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(-200,200,-200));

        <span class="comment">// disable mouse cursor</span>
        device-&gt;getCursorControl()-&gt;setVisible(<span class="keyword">false</span>);
</pre></div><p>
Because we want the whole scene to look a little bit scarier, we add some fog to it. This is done by a call to IVideoDriver::setFog(). There you can set various fog settings. In this example, we use pixel fog, because it will work well with the materials we'll use in this example. Please note that you will have to set the material flag EMF_FOG_ENABLE to 'true' in every scene node which should be affected by this fog. <div class="fragment"><pre class="fragment">        driver-&gt;setFog(video::SColor(0,138,125,81), <a class="code" href="namespaceirr_1_1video.html#df41b1a85e067f5988ba1eb8bb50f44e998abcfd4824aaf15a95678bb444ef65">video::EFT_FOG_LINEAR</a>, 250, 1000, .003f, <span class="keyword">true</span>, <span class="keyword">false</span>);
</pre></div><p>
To be able to display something interesting, we load a mesh from a .3ds file which is a room I modeled with anim8or. It is the same room as from the specialFX example. Maybe you remember from that tutorial, I am no good modeler at all and so I totally messed up the texture mapping in this model, but we can simply repair it with the IMeshManipulator::makePlanarTextureMapping() method. <div class="fragment"><pre class="fragment">        scene::IAnimatedMesh* roomMesh = smgr-&gt;getMesh(
                <span class="stringliteral">"../../media/room.3ds"</span>);
        scene::ISceneNode* room = 0;

        <span class="keywordflow">if</span> (roomMesh)
        {
                smgr-&gt;getMeshManipulator()-&gt;makePlanarTextureMapping(
                                roomMesh-&gt;getMesh(0), 0.003f);
</pre></div><p>
Now for the first exciting thing: If we successfully loaded the mesh we need to apply textures to it. Because we want this room to be displayed with a very cool material, we have to do a little bit more than just set the textures. Instead of only loading a color map as usual, we also load a height map which is simply a grayscale texture. From this height map, we create a normal map which we will set as second texture of the room. If you already have a normal map, you could directly set it, but I simply didn't find a nice normal map for this texture. The normal map texture is being generated by the makeNormalMapTexture method of the VideoDriver. The second parameter specifies the height of the heightmap. If you set it to a bigger value, the map will look more rocky. <div class="fragment"><pre class="fragment">                video::ITexture* normalMap =
                        driver-&gt;getTexture(<span class="stringliteral">"../../media/rockwall_height.bmp"</span>);

                <span class="keywordflow">if</span> (normalMap)
                        driver-&gt;makeNormalMapTexture(normalMap, 9.0f);
</pre></div><p>
But just setting color and normal map is not everything. The material we want to use needs some additional informations per vertex like tangents and binormals. Because we are too lazy to calculate that information now, we let Irrlicht do this for us. That's why we call IMeshManipulator::createMeshWithTangents(). It creates a mesh copy with tangents and binormals from another mesh. After we've done that, we simply create a standard mesh scene node with this mesh copy, set color and normal map and adjust some other material settings. Note that we set EMF_FOG_ENABLE to true to enable fog in the room. <div class="fragment"><pre class="fragment">                scene::IMesh* tangentMesh = smgr-&gt;getMeshManipulator()-&gt;createMeshWithTangents(
                        roomMesh-&gt;getMesh(0));

                room = smgr-&gt;addMeshSceneNode(tangentMesh);
                room-&gt;setMaterialTexture(0,
                                driver-&gt;getTexture(<span class="stringliteral">"../../media/rockwall.jpg"</span>));
                room-&gt;setMaterialTexture(1, normalMap);

                room-&gt;getMaterial(0).SpecularColor.set(0,0,0,0);

                room-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#8a3bc00ae8137535b9fbc5f40add70d35b898e76a9f5e5cfb9c27bee1fbc38be" title="Is fog enabled? Default: false.">video::EMF_FOG_ENABLE</a>, <span class="keyword">true</span>);
                room-&gt;setMaterialType(<a class="code" href="namespaceirr_1_1video.html#c8e9b6c66f7cebabd1a6d30cbc5430f1833aaad409476c3c4baf59e2d1096f4a" title="Just like EMT_NORMAL_MAP_SOLID, but uses parallax mapping.">video::EMT_PARALLAX_MAP_SOLID</a>);
                <span class="comment">// adjust height for parallax effect</span>
                room-&gt;getMaterial(0).MaterialTypeParam = 0.035f;

                <span class="comment">// drop mesh because we created it with a create.. call.</span>
                tangentMesh-&gt;drop();
        }
</pre></div><p>
After we've created a room shaded by per pixel lighting, we add a sphere into it with the same material, but we'll make it transparent. In addition, because the sphere looks somehow like a familiar planet, we make it rotate. The procedure is similar as before. The difference is that we are loading the mesh from an .x file which already contains a color map so we do not need to load it manually. But the sphere is a little bit too small for our needs, so we scale it by the factor 50. <div class="fragment"><pre class="fragment">        <span class="comment">// add earth sphere</span>

        scene::IAnimatedMesh* earthMesh = smgr-&gt;getMesh(<span class="stringliteral">"../../media/earth.x"</span>);
        <span class="keywordflow">if</span> (earthMesh)
        {
                <span class="comment">//perform various task with the mesh manipulator</span>
                scene::IMeshManipulator *manipulator = smgr-&gt;getMeshManipulator();

                <span class="comment">// create mesh copy with tangent informations from original earth.x mesh</span>
                scene::IMesh* tangentSphereMesh =
                        manipulator-&gt;createMeshWithTangents(earthMesh-&gt;getMesh(0));

                <span class="comment">// set the alpha value of all vertices to 200</span>
                manipulator-&gt;setVertexColorAlpha(tangentSphereMesh, 200);

                <span class="comment">// scale the mesh by factor 50</span>
                <a class="code" href="namespaceirr_1_1core.html#73fa92e638c5ca97efd72da307cc9b65" title="Typedef for f32 matrix.">core::matrix4</a> m;
                m.setScale ( <a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(50,50,50) );
                manipulator-&gt;transformMesh( tangentSphereMesh, m );

                scene::ISceneNode *sphere = smgr-&gt;addMeshSceneNode(tangentSphereMesh);

                sphere-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(-70,130,45));

                <span class="comment">// load heightmap, create normal map from it and set it</span>
                video::ITexture* earthNormalMap = driver-&gt;getTexture(<span class="stringliteral">"../../media/earthbump.jpg"</span>);
                <span class="keywordflow">if</span> (earthNormalMap)
                {
                        driver-&gt;makeNormalMapTexture(earthNormalMap, 20.0f);
                        sphere-&gt;setMaterialTexture(1, earthNormalMap);
                        sphere-&gt;setMaterialType(<a class="code" href="namespaceirr_1_1video.html#c8e9b6c66f7cebabd1a6d30cbc5430f10d6f6973795d52d137955699537565db" title="A transparent (based on the vertex alpha value) normal map renderer.">video::EMT_NORMAL_MAP_TRANSPARENT_VERTEX_ALPHA</a>);
                }

                <span class="comment">// adjust material settings</span>
                sphere-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#8a3bc00ae8137535b9fbc5f40add70d35b898e76a9f5e5cfb9c27bee1fbc38be" title="Is fog enabled? Default: false.">video::EMF_FOG_ENABLE</a>, <span class="keyword">true</span>);

                <span class="comment">// add rotation animator</span>
                scene::ISceneNodeAnimator* anim =
                        smgr-&gt;createRotationAnimator(<a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0,0.1f,0));
                sphere-&gt;addAnimator(anim);
                anim-&gt;drop();

                <span class="comment">// drop mesh because we created it with a create.. call.</span>
                tangentSphereMesh-&gt;drop();
        }
</pre></div><p>
Per pixel lighted materials only look cool when there are moving lights. So we add some. And because moving lights alone are so boring, we add billboards to them, and a whole particle system to one of them. We start with the first light which is red and has only the billboard attached. <div class="fragment"><pre class="fragment">        <span class="comment">// add light 1 (nearly red)</span>
        scene::ILightSceneNode* light1 =
                smgr-&gt;addLightSceneNode(0, <a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0,0,0),
                video::SColorf(0.5f, 1.0f, 0.5f, 0.0f), 800.0f);

        light1-&gt;setDebugDataVisible ( <a class="code" href="namespaceirr_1_1scene.html#52b664c4c988113735042b168fc32dbe19e56bb3d3b18134fa63e0529629b427" title="Show Bounding Boxes of SceneNode.">scene::EDS_BBOX</a> );


        <span class="comment">// add fly circle animator to light 1</span>
        scene::ISceneNodeAnimator* anim =
                smgr-&gt;createFlyCircleAnimator (<a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(50,300,0),190.0f, -0.003f);
        light1-&gt;addAnimator(anim);
        anim-&gt;drop();

        <span class="comment">// attach billboard to the light</span>
        scene::ISceneNode* bill =
                smgr-&gt;addBillboardSceneNode(light1, core::dimension2d&lt;f32&gt;(60, 60));

        bill-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#8a3bc00ae8137535b9fbc5f40add70d3cea597a2692b8415486a464a7f954d34" title="Will this material be lighted? Default: true.">video::EMF_LIGHTING</a>, <span class="keyword">false</span>);
        bill-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#8a3bc00ae8137535b9fbc5f40add70d34bc03b7b9dd19e577bf909313ea62510" title="May be written to the zbuffer or is it readonly. Default: true.">video::EMF_ZWRITE_ENABLE</a>, <span class="keyword">false</span>);
        bill-&gt;setMaterialType(<a class="code" href="namespaceirr_1_1video.html#c8e9b6c66f7cebabd1a6d30cbc5430f11b5a814c4466aca2943ff056003a50d1" title="A transparent material.">video::EMT_TRANSPARENT_ADD_COLOR</a>);
        bill-&gt;setMaterialTexture(0, driver-&gt;getTexture(<span class="stringliteral">"../../media/particlered.bmp"</span>));
</pre></div><p>
Now the same again, with the second light. The difference is that we add a particle system to it too. And because the light moves, the particles of the particlesystem will follow. If you want to know more about how particle systems are created in Irrlicht, take a look at the specialFx example. Maybe you will have noticed that we only add 2 lights, this has a simple reason: The low end version of this material was written in ps1.1 and vs1.1, which doesn't allow more lights. You could add a third light to the scene, but it won't be used to shade the walls. But of course, this will change in future versions of Irrlicht where higher versions of pixel/vertex shaders will be implemented too. <div class="fragment"><pre class="fragment">        <span class="comment">// add light 2 (gray)</span>
        scene::ISceneNode* light2 =
                smgr-&gt;addLightSceneNode(0, <a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0,0,0),
                video::SColorf(1.0f, 0.2f, 0.2f, 0.0f), 800.0f);

        <span class="comment">// add fly circle animator to light 2</span>
        anim = smgr-&gt;createFlyCircleAnimator(<a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0,150,0), 200.0f,
                        0.001f, <a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0.2f, 0.9f, 0.f));
        light2-&gt;addAnimator(anim);
        anim-&gt;drop();

        <span class="comment">// attach billboard to light</span>
        bill = smgr-&gt;addBillboardSceneNode(light2, core::dimension2d&lt;f32&gt;(120, 120));
        bill-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#8a3bc00ae8137535b9fbc5f40add70d3cea597a2692b8415486a464a7f954d34" title="Will this material be lighted? Default: true.">video::EMF_LIGHTING</a>, <span class="keyword">false</span>);
        bill-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#8a3bc00ae8137535b9fbc5f40add70d34bc03b7b9dd19e577bf909313ea62510" title="May be written to the zbuffer or is it readonly. Default: true.">video::EMF_ZWRITE_ENABLE</a>, <span class="keyword">false</span>);
        bill-&gt;setMaterialType(<a class="code" href="namespaceirr_1_1video.html#c8e9b6c66f7cebabd1a6d30cbc5430f11b5a814c4466aca2943ff056003a50d1" title="A transparent material.">video::EMT_TRANSPARENT_ADD_COLOR</a>);
        bill-&gt;setMaterialTexture(0, driver-&gt;getTexture(<span class="stringliteral">"../../media/particlewhite.bmp"</span>));

        <span class="comment">// add particle system</span>
        scene::IParticleSystemSceneNode* ps =
                smgr-&gt;addParticleSystemSceneNode(<span class="keyword">false</span>, light2);

        <span class="comment">// create and set emitter</span>
        scene::IParticleEmitter* em = ps-&gt;createBoxEmitter(
                core::aabbox3d&lt;f32&gt;(-3,0,-3,3,1,3),
                <a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0.0f,0.03f,0.0f),
                80,100,
                video::SColor(0,255,255,255), video::SColor(0,255,255,255),
                400,1100);
        em-&gt;setMinStartSize(core::dimension2d&lt;f32&gt;(30.0f, 40.0f));
        em-&gt;setMaxStartSize(core::dimension2d&lt;f32&gt;(30.0f, 40.0f));

        ps-&gt;setEmitter(em);
        em-&gt;drop();

        <span class="comment">// create and set affector</span>
        scene::IParticleAffector* paf = ps-&gt;createFadeOutParticleAffector();
        ps-&gt;addAffector(paf);
        paf-&gt;drop();

        <span class="comment">// adjust some material settings</span>
        ps-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#8a3bc00ae8137535b9fbc5f40add70d3cea597a2692b8415486a464a7f954d34" title="Will this material be lighted? Default: true.">video::EMF_LIGHTING</a>, <span class="keyword">false</span>);
        ps-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#8a3bc00ae8137535b9fbc5f40add70d34bc03b7b9dd19e577bf909313ea62510" title="May be written to the zbuffer or is it readonly. Default: true.">video::EMF_ZWRITE_ENABLE</a>, <span class="keyword">false</span>);
        ps-&gt;setMaterialTexture(0, driver-&gt;getTexture(<span class="stringliteral">"../../media/fireball.bmp"</span>));
        ps-&gt;setMaterialType(<a class="code" href="namespaceirr_1_1video.html#c8e9b6c66f7cebabd1a6d30cbc5430f126529b1cf18ec4d8073809f6bd15ebbb" title="Makes the material transparent based on the vertex alpha value.">video::EMT_TRANSPARENT_VERTEX_ALPHA</a>);


        MyEventReceiver receiver(room, env, driver);
        device-&gt;setEventReceiver(&amp;receiver);
</pre></div><p>
Finally, draw everything. That's it. <div class="fragment"><pre class="fragment">        <span class="keywordtype">int</span> lastFPS = -1;

        <span class="keywordflow">while</span>(device-&gt;run())
        <span class="keywordflow">if</span> (device-&gt;isWindowActive())
        {
                driver-&gt;beginScene(<span class="keyword">true</span>, <span class="keyword">true</span>, 0);

                smgr-&gt;drawAll();
                env-&gt;drawAll();

                driver-&gt;endScene();

                <span class="keywordtype">int</span> fps = driver-&gt;getFPS();

                <span class="keywordflow">if</span> (lastFPS != fps)
                {
                        <a class="code" href="namespaceirr_1_1core.html#ef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a> str = L<span class="stringliteral">"Per pixel lighting example - Irrlicht Engine ["</span>;
                        str += driver-&gt;getName();
                        str += <span class="stringliteral">"] FPS:"</span>;
                        str += fps;

                        device-&gt;setWindowCaption(str.c_str());
                        lastFPS = fps;
                }
        }

        device-&gt;drop();

        <span class="keywordflow">return</span> 0;
}
</pre></div> </div>
<hr size="1">
<address style="align: right;">
<small> </small>
</address>
<table width="100%" border="0" cellspacing="0" cellpadding="2">
  <tr> 
    <td width="0"> <div align="left"><small><a href="http://irrlicht.sourceforge.net" target="_blank"><img src="irrlicht.png" alt="The Irrlicht Engine" align="middle" border=0 width=88 height=31></a></small></div></td>
    <td> <div align="left"><small><em><font size="2">The <a href="http://irrlicht.sourceforge.net" target="_blank">Irrlicht 
        Engine</a> Documentation &copy; 2003-2009 by Nikolaus Gebhardt. Generated 
        on Sun Jan 10 09:24:07 2010 by <a href="http://www.doxygen.org" target="_blank">Doxygen</a> 
        (1.5.6)</font></em></small></div></td>
  </tr>
</table>
<address style="align: right;">
</address>
</body>
</html>