{"id":440,"date":"2009-12-01T23:59:46","date_gmt":"2009-12-01T14:59:46","guid":{"rendered":"http:\/\/www.codedojo.com\/?p=440"},"modified":"2011-08-06T11:56:30","modified_gmt":"2011-08-06T02:56:30","slug":"development-diary-more-irrlicht-on-the-iphone-pvrtc-mipmaps-lightmaps","status":"publish","type":"post","link":"https:\/\/www.codedojo.com\/?p=440","title":{"rendered":"Development Diary &#8211; More Irrlicht on the iPhone (pvrtc, mipmaps, lightmaps)"},"content":{"rendered":"<p>Some more iPhone benchmarks and tests with everybody&#8217;s favorite <a href=\"http:\/\/irrlicht.sourceforge.net\/download\/irrlichtengine.wav\">difficult to pronounce<\/a> 3d rendering framework!<\/p>\n<h2><strong>Thumb mode and floating point:\u00a0 Just don&#8217;t<\/strong><\/h2>\n<p><a href=\"http:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/iphone_irrlicht_md2_again.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-441 alignnone\" title=\"iphone_irrlicht_md2_again\" src=\"https:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/iphone_irrlicht_md2_again.jpg\" alt=\"iphone_irrlicht_md2_again\" width=\"480\" height=\"320\" srcset=\"https:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/iphone_irrlicht_md2_again.jpg 480w, https:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/iphone_irrlicht_md2_again-300x200.jpg 300w\" sizes=\"auto, (max-width: 480px) 100vw, 480px\" \/><\/a><\/p>\n<p>Ok, first, I was an idiot before and somehow was still compiling in thumb mode. I know not to do that!<\/p>\n<p>Somehow the setting was removed but I guess the default is ON even with it missing or something.\u00a0 After adding it by hand it the math-heavy md2 anim rendering test went from 31 fps to 60+ fps.<\/p>\n<p>I think the mistake came from editing the build configuration by clicking on the project settings instead of the &#8220;build target&#8221; settings, so I&#8217;m going to check both from now on to be safe.<\/p>\n<h2><strong>Irrlicht and Quake 3 style .bsp demo<\/strong><\/h2>\n<div id=\"attachment_442\" style=\"width: 490px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/iphone_irrlicht_quake.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-442\" class=\"size-full wp-image-442\" title=\"iphone_irrlicht_quake\" src=\"https:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/iphone_irrlicht_quake.jpg\" alt=\"Irrlicht's .bsp map demo on iPhone using pvrtc4 textures with collision\" width=\"480\" height=\"320\" srcset=\"https:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/iphone_irrlicht_quake.jpg 480w, https:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/iphone_irrlicht_quake-300x200.jpg 300w\" sizes=\"auto, (max-width: 480px) 100vw, 480px\" \/><\/a><p id=\"caption-attachment-442\" class=\"wp-caption-text\">Irrlicht&#39;s .bsp map demo on iPhone using pvrtc4 textures with mipmaps and player collision enabled<\/p><\/div>\n<p>I was expecting Irrlicht to do some kind of wicked optimizations when rendering a .bsp map.\u00a0 Nope, it does nothing special.\u00a0 You CAN load it into an octree but if OCTTREE_USE_HARDWARE is defined it renders the whole mesh anyway. (?!!?) \u00a0 If that flag isn&#8217;t defined, it does render less primitives but without using VBOs so it&#8217;s way slower anyway.<\/p>\n<p>This <a href=\"http:\/\/irrlicht.sourceforge.net\/phpBB2\/viewtopic.php?t=32681\">forum thread<\/a> may be of interest about that.<\/p>\n<p>Collision detection would be a better candidate for a software octree but after playing with createOctTreeTriangleSelector with different settings I never saw even one fps of difference.\u00a0 Strange, I would have expected it to noticeably help.<\/p>\n<p>(this section was updated Dec 2nd after Tonic pointed out that you can use VBO&#8217;s with Octrees&#8230;)<\/p>\n<h2><strong>Adding iPhone controls<\/strong><\/h2>\n<p>As you can see in the screenshot above I&#8217;ve added a basic wolf3d control scheme to get around.<\/p>\n<p>I use my own engine to handle the GUI overlay\/handling (it draws after Irrlicht is done)\u00a0 and just have it controlling Irrlicht&#8217;s FPSControlComponent.<\/p>\n<p>I use camera-&gt;setTarget() to look up and down, and I fake UP\/DOWN\/LEFT\/RIGHT key movement by sending pDevice-&gt;postEventFromUser() messages.\u00a0 This works ok but bites because it&#8217;s not proportional or 360 degree so I&#8217;ll need to modify FPSControlComponent or just do my own movement stuff if I want to do it right.<\/p>\n<h2><strong>Do using compressed textures help the FPS on the iPhone?<\/strong><strong><br \/>\n<\/strong><\/h2>\n<p>Short answer, a little.<\/p>\n<p>I added CImageLoaderRTTEX to Irrlicht so it could load my own texture format.\u00a0 It&#8217;s sort of a container that houses multiple formats including pvrct4, pvrct2, 4444 rgba, 565 rgb, etc.\u00a0 It does extra stuff that normal .pvr&#8217;s don&#8217;t, like remember the original image size before padding or stretching.<\/p>\n<p>I also modified the b3d and .bsp loader to look for textures with my .rttex file extension first.<\/p>\n<p>Some rough numbers with the quake style .bsp map collision disabled:<\/p>\n<ul>\n<li>Map test with raw 32 bit textures with mipmap chain: 26 fps<\/li>\n<li>Map test with pvrtc4 format textures with mipmap chain: 28 fps<\/li>\n<\/ul>\n<p>So yeah, tiny difference.<\/p>\n<p>However, keep in mind there are also other good reasons to use pvrtc:<\/p>\n<ul>\n<li>Fast loading even when zlib&#8217;ed.\u00a0 Especially compared to decompressing a .jpg<\/li>\n<li>Use a hell of a lot less texture memory<\/li>\n<\/ul>\n<p>On the down side, the visual artifacts can look pretty bad so you still need some raw formats in your toolbox for specific images like GUI.<\/p>\n<h2><strong><strong>Do using mipmaps help speed on the iPhone?<\/strong><\/strong><\/h2>\n<p>I didn&#8217;t notice a difference.\u00a0 Using mipmaps look better though, although I need to adjust the lod bias a bit so it doesn&#8217;t pop up so bad&#8230;<\/p>\n<p><strong>Tip:<\/strong> The iPhone requires a full mipmap chain to work, so don&#8217;t try to get tricky and only include a few of them.<\/p>\n<p><a href=\"http:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/irrlicht_broken_mipmaps.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-446\" title=\"irrlicht_broken_mipmaps\" src=\"https:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/irrlicht_broken_mipmaps.jpg\" alt=\"irrlicht_broken_mipmaps\" width=\"486\" height=\"346\" srcset=\"https:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/irrlicht_broken_mipmaps.jpg 486w, https:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/irrlicht_broken_mipmaps-300x213.jpg 300w\" sizes=\"auto, (max-width: 486px) 100vw, 486px\" \/><\/a><\/p>\n<p>For your enjoyment here is what\u00a0 happens when your texture processing utility has a bug in its mipmap generation.\u00a0 (The festive blue, pink, and green colors shouldn&#8217;t be there&#8230;)<\/p>\n<h2><strong><strong><strong><strong>Putting it all together, our own level<\/strong><\/strong><\/strong><\/strong><\/h2>\n<p>I&#8217;ve got to say, the king of the 3dsmax exporters for Irrlicht is <a href=\"http:\/\/www.onigirl.com\/pipeline\/\">B3D Pipeline<\/a>.<\/p>\n<p>I know, you&#8217;re thinking <em>&#8220;Uh&#8230; b3d, that Blitz3d format?\u00a0 Why not use collada or .x or something?&#8221; <\/em> All I can say is this is the exporter that actually worked right for me when trying to get the lightmaps working.<\/p>\n<p><a href=\"http:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/max_house_scene_render.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-445\" title=\"max_house_scene_render\" src=\"https:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/max_house_scene_render-300x255.jpg\" alt=\"max_house_scene_render\" width=\"300\" height=\"255\" srcset=\"https:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/max_house_scene_render-300x255.jpg 300w, https:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/max_house_scene_render.jpg 882w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>So here is a low poly house in 3dsmax.\u00a0 I&#8217;ve applied a light source and got it looking how I want.\u00a0 Then I use max&#8217;s render to texture feature to make a single alpha lightmap.<\/p>\n<p>The (old) iPhone has two texture units and this will be the second one, controlling where shadows appear, the same way the .bsp map example works.<\/p>\n<p>After exporting it pops into the game engine fully lightmapped and ready to go with a single line of code.<\/p>\n<p><a href=\"http:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/iphone_irrlicht_shadowmapping.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-443\" title=\"iphone_irrlicht_shadowmapping\" src=\"https:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/iphone_irrlicht_shadowmapping.jpg\" alt=\"iphone_irrlicht_shadowmapping\" width=\"480\" height=\"320\" srcset=\"https:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/iphone_irrlicht_shadowmapping.jpg 480w, https:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/iphone_irrlicht_shadowmapping-300x200.jpg 300w\" sizes=\"auto, (max-width: 480px) 100vw, 480px\" \/><\/a><\/p>\n<p>After adding a skybox and a simplified collision mesh it still gets nearly 60 fps, not bad.\u00a0 Too bad a game needs more than one house.\u00a0 Hmm, my fov looks a bit extreme.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Some more iPhone benchmarks and tests with everybody&#8217;s favorite difficult to pronounce 3d rendering framework! Thumb mode and floating point:\u00a0 Just don&#8217;t Ok, first, I was an idiot before and somehow was still compiling in thumb mode. I know not to do that! Somehow the setting was removed but I guess the default is ON [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,6],"tags":[],"class_list":["post-440","post","type-post","status-publish","format-standard","hentry","category-development","category-tech-tips"],"_links":{"self":[{"href":"https:\/\/www.codedojo.com\/index.php?rest_route=\/wp\/v2\/posts\/440","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codedojo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codedojo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codedojo.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codedojo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=440"}],"version-history":[{"count":18,"href":"https:\/\/www.codedojo.com\/index.php?rest_route=\/wp\/v2\/posts\/440\/revisions"}],"predecessor-version":[{"id":461,"href":"https:\/\/www.codedojo.com\/index.php?rest_route=\/wp\/v2\/posts\/440\/revisions\/461"}],"wp:attachment":[{"href":"https:\/\/www.codedojo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=440"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codedojo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=440"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codedojo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=440"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}