<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Development Journal</title>
	<atom:link href="http://lugtug.com/dev/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://lugtug.com/dev</link>
	<description>Programming</description>
	<lastBuildDate>Sat, 13 Nov 2010 10:36:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Terrain Collision</title>
		<link>http://lugtug.com/dev/2010/11/05/terrain-collision/</link>
		<comments>http://lugtug.com/dev/2010/11/05/terrain-collision/#comments</comments>
		<pubDate>Fri, 05 Nov 2010 21:31:44 +0000</pubDate>
		<dc:creator>Foxtox</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[terrain]]></category>

		<guid isPermaLink="false">http://lugtug.com/dev/?p=161</guid>
		<description><![CDATA[Added terrain collision last week, but as I&#8217;m not using heightfields I had to use something slightly different from the norm. First I tried a pure triangle mesh based approach, I knew this would be slow as hell and use a ton of memory but I wanted to have a working baseline to compare against. [...]]]></description>
			<content:encoded><![CDATA[<p>
Added terrain collision last week, but as I&#8217;m not using heightfields I had to use<br />
something slightly different from the norm.</p>
<p>  First I tried a pure triangle mesh based approach, I knew this would be slow as<br />
hell and use a ton of memory but I wanted to have a working baseline to compare<br />
against.</p>
<p>  Initially for physics I used Havok, but as I don&#8217;t have $100,000 laying around to waste on a<br />
physics engine I only had access to the binary version&#8211;and Havok only supplies<br />
libs for VS2008, not VS2010 which I what I am using, although I was able to get<br />
the 2008 libs working.  After getting the basic triangle mesh collision up and running<br />
in Havok I decided I didn&#8217;t much care for not having access to the source so I switched<br />
to Bullet.  </p>
<p>  I&#8217;d used Bullet before so it was easy to get it switched over, and once I had the triangle<br />
mesh collision set up I gave it a trial run.  </p>
<p>  The triangle mesh collision used approximatly one gig of memory, although generation speed<br />
for the <strong>btBvhTriangleMeshShape</strong> was fairly quick.  I created a task<br />
to generate collision and spread the work across the cores which made generation faster.  </p>
<p>  I added spheres and boxes that I could drop onto the terrain to test the accuracy and<br />
performance of the collision detection.  </p>
<p> A gig of memory for terrain collision was obviously out of the question so I began testing<br />
convex hulls.  </p>
<p>      Bullet has a <strong>btConvexHullShape</strong> which takes an array of<br />
vertices in floating point format.  This worked and reduced memory usage by more than<br />
half.  Still wasn&#8217;t good enough though. </p>
<p>      I wrote my own convex hull shape which I called <strong>btCompressedConvexHullShape</strong>,<br />
 as the name implies it uses compressed verts(about 1/4th the memory per vert).  </p>
<p>      I also started using Bullets utility class <strong>btShapeHull</strong>.  This class takes in<br />
an array of vertices and produces a convex tri mesh with a greatly reduced number of<br />
vertices.  Feed it 2000 verts and get back a 14 vert convex mesh, that type of thing.</p>
<p>    I feed the results of the btShapeHull back into <strong>btCompressedConvexHullShape </strong>or<br />
a <strong>btConvexTriangleMeshShape</strong>(favoring btCompressedConvexHullShape as they<br />
both seem to produce the same results and it uses less memory).  </p>
<p>   Memory usage for the physics simulation was greatly reduced at this point, down to<br />
about 100 megs.  There are still a few optimizations I&#8217;d like to do, mostly to reduce the allocations<br />
taking place in the btShapeHull step, but overall the performance and<br />
memory usage is fairly good at this point.</p>
<p>  I&#8217;ve also got the physics simulation running as it&#8217;s own task, with adding and<br />
removing of objects done asynchronously.  This helps because as you move through<br />
the world a great many terrain chunks(each as a convex hull) are being added and removed.</p>
<p> Collision seems to be fairly accurate as long as I don&#8217;t have it too far off<br />
from the visual representation.   </p>
<p>   My gravity is currently just set using Bullets built in system, which is directional.<br />
This means if I navigate to the side of the planet I can start dropping objects<br />
and watch them bounce along through mountains and valleys for miles as they<br />
travel along the edge of the planet.  </p>
<p>  Need to add a character control system soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://lugtug.com/dev/2010/11/05/terrain-collision/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Compile time string hashing</title>
		<link>http://lugtug.com/dev/2010/08/13/compile-time-string-hashing/</link>
		<comments>http://lugtug.com/dev/2010/08/13/compile-time-string-hashing/#comments</comments>
		<pubDate>Sat, 14 Aug 2010 06:52:59 +0000</pubDate>
		<dc:creator>Foxtox</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://lugtug.com/dev/?p=132</guid>
		<description><![CDATA[Here is a working version of compile time string hashing in C++, pretty tedious to make this so perhaps I&#8217;ll save someone some time. You cannot currently do this with templates, at least not without resorting to specifying one character at a time or using multi-byte for 4 at a time, so it massages the [...]]]></description>
			<content:encoded><![CDATA[<p>   Here is a working version of <a href="http://lugtug.com/dev/wp-content/uploads/2010/08/string_id.h">compile time string hashing</a> in C++,<br />
pretty tedious to make this so perhaps I&#8217;ll save someone some time.</p>
<p>   You cannot currently do this with templates, at least not without<br />
resorting to specifying one character at a time or using multi-byte for<br />
4 at a time,  so it massages the compiler into optimizing the string hash<br />
 out of existence.  </p>
<p> Another way of doing it is with pure <a href="http://chrissavoie.com/index.php?option=com_content&#038;task=view&#038;id=65&#038;Itemid=1">macros</a>.</p>
<p>   It was written with VS2010, so results may not be the same on other compilers<br />
(though I&#8217;d expect GCC and Intel should be able to pull it off).  In debug(without<br />
optimizations on), it will not be optimized out so you may want to force it to use<br />
the const char* path in debug.</p>
<p>  Also the __forceinline calls are necessary, without them once the compiler starts<br />
seeing more than one string literal of the same length it switches to calling a function.</p>
<p>    Tested it with string literals up to 64 characters in length, and the resulting<br />
assembly is just a single assignment.  </p>
<p>   Usage is like this:</p>
<p>            size_t id = ptl::string_id(&#8220;hello what is my hash?&#8221;);</p>
<p>  You can also pass a const char* or a std::string, but this will result in a run<br />
time hash(using same hash function so results should be the same).</p>
<p>   Additionally you can use it with std::unordered_map/set like so </p>
<p>             <code> std::unordered_map &lt; ptl::string_id, int, ptl::string_id::hash &gt; PreHashed; </code></p>
<p>  And a lookup like this:</p>
<p>            auto it = PreHashed.find(&#8220;hello&#8221;); </p>
<p>  Won&#8217;t actually hash anything, it will just use the compile-time calculated hash value.</p>
<p>   The hash function used is called One-at-a-Time, see here for <a href="http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx">description</a>.</p>
<p> Of course&#8211; it probably isn&#8217;t a good idea to actually use something like this without throughly testing<br />
to verify that the compiler generates the correct code in all situations, which is pretty difficult<br />
to do <img src='http://lugtug.com/dev/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://lugtug.com/dev/2010/08/13/compile-time-string-hashing/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>progress</title>
		<link>http://lugtug.com/dev/2010/08/01/progress/</link>
		<comments>http://lugtug.com/dev/2010/08/01/progress/#comments</comments>
		<pubDate>Mon, 02 Aug 2010 01:30:23 +0000</pubDate>
		<dc:creator>Foxtox</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[terrain]]></category>

		<guid isPermaLink="false">http://lugtug.com/dev/?p=116</guid>
		<description><![CDATA[I&#8217;ve been porting my old terrain system to my new code base, and from OpenGL to D3D11. As of today it is rendering at more or less visual parity with the OpenGL version. It still lacks any form of culling and has no shadows, but overall a major upgrade from a few days ago when [...]]]></description>
			<content:encoded><![CDATA[<p> I&#8217;ve been porting my old terrain system to my new code base, and<br />
from OpenGL to D3D11. As of today it is rendering at more<br />
or less visual parity with the OpenGL version.  It still lacks any form<br />
of culling and has no shadows, but overall a major upgrade from a few<br />
days ago when it looked like a couple of broken triangles.</p>
<p>  While porting it, one system I ditched was my old threaded job<br />
system&#8211;which was used heavily during terrain generation. </p>
<p>  Instead I&#8217;ve decided to use Intel&#8217;s thread building blocks.  Initially I<br />
was using Microsoft&#8217;s concurrency runtime, but a few problems compared to<br />
TBB drove me away.  One major annoyance is that MCRT won&#8217;t compile<br />
in C++/cli(while TBB will); amusing considering C++/cli is<br />
a MS product.</p>
<p>  It took abit but eventually I had TBB performing on par with my<br />
old job system, and TBB should be a win in the end since it is<br />
much more flexible. </p>
<p><strong>Files </strong></p>
<p>  One useful feature I added recently was a file monitoring system&#8211;<br />
mostly intended to make development easier&#8211;it notes any files that<br />
my program opens, and if and when any of them change while the program<br />
is running it sends out a message so that any interested system can<br />
reload the file.  </p>
<p>  So far just using this with lua files and shader files, but it is very nice<br />
to be able to modify a shader, hit save, and have it immediately reflected<br />
in the game.</p>
<p> To make this work generically for all D3D resources I had to add an<br />
extra level of indirection, I did wrap it up in a way that just changing<br />
a typedef will allow me to toggle between the two&#8211; though on a modern<br />
PC it probably makes little to no difference.</p>
]]></content:encoded>
			<wfw:commentRss>http://lugtug.com/dev/2010/08/01/progress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tool windows</title>
		<link>http://lugtug.com/dev/2010/07/22/tool-windows/</link>
		<comments>http://lugtug.com/dev/2010/07/22/tool-windows/#comments</comments>
		<pubDate>Fri, 23 Jul 2010 04:36:24 +0000</pubDate>
		<dc:creator>Foxtox</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://lugtug.com/dev/?p=93</guid>
		<description><![CDATA[I have been trying to come to come up with a good way to handle editors/tools and I think I&#8217;ve finally found a method that satisfies me. Some projects use external tools, while others build them directly into the application. The external tool method bothers me for a few reasons 1) potential problems with tool [...]]]></description>
			<content:encoded><![CDATA[<p> I have been trying to come to come up with a good way to handle editors/tools and<br />
I think I&#8217;ve finally found a method that satisfies me.  </p>
<p>Some projects use external tools, while others build them directly into the application.  </p>
<p>  The external tool method bothers me for a few reasons</p>
<p>1) potential problems with tool not being in sync with engine/game<br />
2) some tools will need access to engine code<br />
3) end up duplicating functionality already found in the engine/game<br />
4) won&#8217;t be able to really see what it looks like in the game(not easily)</p>
<p>  The method of directly embedding(preferably as DLL) it into the game is somewhat<br />
more appealing to me, but this method has one big issue at least&#8230;</p>
<p>1) Since your game is likely using DirectX/OpenGL, there really aren&#8217;t any great UI<br />
   solutions readily available, so you will likely use whatever method your game uses<br />
   for in-game UI (scaleform for in game editor? Ugh.. no thanks)<br />
2) Also if the game is slow to load and has no methods to reduce what is loaded,<br />
    lots of time can be wasted </p>
<p> Then I heard about methods such as this <a href="http://jmorrill.hjtcentral.com/Home/tabid/428/EntryId/437/Direct3D-10-11-Direct2D-in-WPF.aspx">D3D10 and WPF</a><br />
and was interested because I thought I might be able to use this to somehow display<br />
WPF with my D3D11 app.<br />
  Unfortunately it seems to work the other way, you can display D3D in the WPF app,<br />
but not vice versa(at least not that I&#8217;ve been able to discover).<br />
  Dropping the D3D into WPF means you are at the mercy of WPF for updating the window,<br />
and if you have multiple tools each one must have the D3D interop code added. BLEH.</p>
<p> My codebase is primary native C++, but supports dynamic loading of .Net assemblies,<br />
and I&#8217;ve written a fair amount of interop code to allow these assemblies to communicate<br />
with the rest of the game.   </p>
<p>I began to wonder if it was possible to make a WPF assembly, dynamically load it like any<br />
other .net assembly and have it pop up a separate window.  Perhaps this isn&#8217;t surprising<br />
to people more familiar with managed code/WPF, but for me it as somewhat surprising that<br />
this did indeed work&#8211; although I had to overcome a few odd problems.</p>
<p>Steps:<br />
1) Create the WPF project<br />
2) Go to project properies and change output type to class library<br />
3) the project defaults to application, to change this click on app.xaml, go to properties,<br />
    and change &#8220;Build Action&#8221; to &#8220;Page&#8221;</p>
<p>  (may be other/better ways of handling some of this next part)<br />
4) I way I do it is; create an instance of the window(called MainWindow by default )<br />
   within my startup class, but I have to do it a special way to avoid .net tossing<br />
   exceptions such as this lovely one</p>
<p>     “The calling thread must be STA, because many UI components require this.” </p>
<p><code>  _Thread = new Thread(LaunchWindow);<br />
            _Thread.SetApartmentState(ApartmentState.STA);  //Many WPF UI elements need to be created inside STA<br />
            _Thread.Start();</code></p>
<p>This calls the &#8220;LaunchWindow&#8221; function on a STA approved thread, the function<br />
just does this currently</p>
<p><code>     _Window = new MainWindow();<br />
               _Window.ShowDialog();</p>
<p>              </code></p>
<p>This causes a 2nd window to popup, it acts independently of the apps<br />
primary window.   </p>
<p><img src="http://lugtug.com/dev/wp-content/uploads/2010/07/ToolWindow.jpg" alt="ToolWindow" title="ToolWindow" width="500" height="400" class="alignnone size-full wp-image-97" /></p>
<p> I&#8217;ve heard of other methods where the game acts as a server and each tool a<br />
client, and communication is done via networking. Sounds good, but I don&#8217;t feel<br />
like spending time to implement that( and I already have a generic event system which<br />
allows for communication between unrelated modules in lua, C++, or .net), also that method<br />
does prevent directly access(which could be seen as good.. or bad&#8230;).</p>
]]></content:encoded>
			<wfw:commentRss>http://lugtug.com/dev/2010/07/22/tool-windows/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Functional</title>
		<link>http://lugtug.com/dev/2010/05/02/functional/</link>
		<comments>http://lugtug.com/dev/2010/05/02/functional/#comments</comments>
		<pubDate>Mon, 03 May 2010 03:21:42 +0000</pubDate>
		<dc:creator>Foxtox</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://lugtug.com/dev/?p=71</guid>
		<description><![CDATA[Sometimes I find that I need to use delegates in C++, in the past I almost always used the fast delegate library available on codeproject, but over the last year or so I&#8217;ve been using std::tr1::functional often enough instead&#8211;functional is somewhat more powerful as you can bind functors containing state. I was curious if the [...]]]></description>
			<content:encoded><![CDATA[<p>   Sometimes I find that I need to use delegates in C++, in the past I almost always used the <a href="http://www.codeproject.com/kb/cpp/FastDelegate.aspx">fast delegate </a>library available on codeproject, but over the last year or so I&#8217;ve been using std::tr1::functional often enough instead&#8211;functional is somewhat more powerful as you can<br />
 bind functors containing state.</p>
<p>   I was curious if the std::tr1::functional that ships with VS2010 has any sort of SBO.</p>
<p>(small buffer optimization- this allows it to avoid any dynamic memory allocation if the bound object is small enough).  </p>
<p>Turns out it does, although it isn&#8217;t terribly large, in the header xxxfunction I found this union&#8230;</p>
<p>	union _Space_union<br />
		{	// storage for small wrappers<br />
		_Pfnty _Pfn[3];<br />
		void *_Pobj[3];<br />
		long double _Ldbl;	// for maximum alignment<br />
		char _Alias[3 * sizeof (void *)];	// to permit aliasing<br />
		} _Space;</p>
<p> Only 12 bytes for storage(in 32 bit mode).</p>
<p><em> //member fxn takes up 16 bytes and thus causes dynamic allocation</em><br />
 auto memfxn =  std::tr1::bind(&#038;RenderModule::UpdateDisplay, this);  </p>
<p><em>//free fxn is only 4 bytes</em><br />
 auto freeFxn =  std::tr1::bind(Hello);      </p>
<p><em>//lambda capturing this, is only 4 bytes also</em><br />
 auto lambda =  [this](){this->UpdateDisplay();};                             </p>
<p> Functional also seems to tack on an extra 4 bytes when you pass the bind to the functional,<br />
so the mem fxn ends up requiring a 20 byte SBO to avoid dynamic allocation.</p>
<p>  So to avoid dynamic allocation on member functions you can either go into xxxfunction and<br />
simply change the size of the SBO(changing the 3 to a 5 works for mem fxn),<br />
or use a lambda which in turn calls the desired mem fxn, the disadvantage being it involves an extra function call.</p>
<p>  The fast delegate library uses less static memory(sizeof shows only 8 bytes)<br />
and does not dynamically allocate, also as the name implies&#8211; it is quite fast.</p>
<p> So I&#8217;ll continue using fast delegate wherever speed is paramount. </p>
]]></content:encoded>
			<wfw:commentRss>http://lugtug.com/dev/2010/05/02/functional/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Visual Studio 2010</title>
		<link>http://lugtug.com/dev/2010/04/11/visual-studio-2010/</link>
		<comments>http://lugtug.com/dev/2010/04/11/visual-studio-2010/#comments</comments>
		<pubDate>Sun, 11 Apr 2010 23:20:02 +0000</pubDate>
		<dc:creator>Foxtox</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://lugtug.com/dev/?p=59</guid>
		<description><![CDATA[VS2010 is supposedly coming out tomorrow&#8211; I&#8217;ve been using the release candidate for the last few months and have found it to be a great improvement over VS2008. VS2010 supports 6 new language level features from C++0x, which is not alot, but they did add some of the important ones at least. New Language Features: [...]]]></description>
			<content:encoded><![CDATA[<p> VS2010 is supposedly coming out tomorrow&#8211; I&#8217;ve been using the release candidate for the last few months and have found it to be a great improvement over VS2008.</p>
<p> VS2010 supports 6 new language level features from C++0x, which is not alot, but they did add some of the important ones at least.</p>
<p><strong>New Language Features:</strong></p>
<p><strong>Lambda&#8217;s: </strong>Instead of writing incredibly verbose functors/function objects(and often enough not in the location where they are actually used)&#8211; you can now use the very succinct lambda syntax to declare an anonymous function that behaviors like a functor. While this doesn&#8217;t allow you do anything you couldn&#8217;t already do in C++, the resulting code is much shorter and you no longer have to write tedious functor constructors to accept external state.  I&#8217;ve found lambda support in C++ to be quite awesome.</p>
<p><strong>R-Value reference</strong>s: A new reference type which will bind to temporary&#8217;s, this allowed for the introduction of move constructors and move assignment operators&#8211; which steal their resources from R-value references.  This features allows for faster performing code by the removal of needless copying.<br />
 One of the remaining issues with C++ STL is that it often results in a good amount of data copying going on&#8211; the addition of R-Value references allows for any STL implementation that takes advantage of them to reduce the amount of copying that occurs(which the VS2010  Dinkumware STL does).</p>
<p><strong>decltype</strong>: can deduce the type of an expression&#8211; for example this can be used to get the return type of a function.  Another useful tool for generic programming.</p>
<p><strong>static_assert</strong>: compile time asserts that will print whatever message you specified, this is nice because you can add a useful description of the problem, better then using C++ hackery to get a description with lots of underscores.</p>
<p><strong>nullptr</strong>: so you can say float* ptr = nullptr instead of 0. One problem with this is that it uses the same keyword as the C++/cli version, but has a different meaning, so MS has added a non-standard __nullptr which will always act as the native nullptr, even in C++/cli.   I like this addition, but the conflict with C++/cli is annoying.</p>
<p><strong>auto</strong>: you can now declare an objects type to be auto and the compiler will attempt to deduce which type it is, this allows for more concise code(especially when it comes to iterators) and is useful for generic programming. Nice feature.</p>
<p>   C++0x features that didn&#8217;t make it include variadic templates, strongly typed enums(so tired of wrapping enums in classes/namespaces), initializer lists, template typedefs, and foreach.</p>
<p>New stuff in the standard library </p>
<p><em>forward_list</em>   &#8211; singly-linked list&#8211; cool, but I rarely use list so I doubt I&#8217;ll use this much either<br />
<em>unique_ptr </em>    &#8211; now this is I find very very useful, it takes advantage of R-Value references to allow it to be stored in STL containers(unlike auto_ptr), and includes support for a custom deleter similar to shared_ptr</p>
<p><strong>The IDE</strong></p>
<p> The new UI allows you to break off parts of the UI and then drag them outside of the primary window, I&#8217;m using a multi-monitor setup at home, so I can drag my output window &#038; search window to the 2nd monitor.  Very nice..</p>
<p><em>Intellisense</em>: from the brief period I attempted to use VS2010 without Visual Assist it did appear to be improved</p>
<p><em>Concurrency Runtime</em>: Microsoft has been busy working on two C++ systems for handling concurrency&#8211; the Asynchronous Agents Library and the Parallel Patterns Library, so far I&#8217;ve only dabbled around with the PPL, but I do like what I&#8217;ve seen.  It does pretty much stick you with windows though, so perhaps forking over $300 for intel&#8217;s TBB might be a better route.</p>
<p><em>F#</em>: I don&#8217;t know this language yet, but it was added as a first class language with full intellisense support etc.  I&#8217;m gonna spend some time learning the language as I&#8217;d like to know a functional language. </p>
<p>And boo to <strong>Perforce</strong>, I&#8217;d have expected perforce would have a working plugin for VS2010 by now, but alas they have nothing.</p>
]]></content:encoded>
			<wfw:commentRss>http://lugtug.com/dev/2010/04/11/visual-studio-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Few Experiments</title>
		<link>http://lugtug.com/dev/2009/06/13/few-experiments/</link>
		<comments>http://lugtug.com/dev/2009/06/13/few-experiments/#comments</comments>
		<pubDate>Sat, 13 Jun 2009 08:09:21 +0000</pubDate>
		<dc:creator>Foxtox</dc:creator>
				<category><![CDATA[noise]]></category>

		<guid isPermaLink="false">http://lugtug.com/dev/2009/06/13/few-experiments/</guid>
		<description><![CDATA[Played around with a few methods for modifying the terrain, so far just doing simple modifications to the fractional part of the noise input. The input is from 0.0-1.0, so to keep the terrain continuous it helps if the output also is (more or less); but at first I was getting terrain with boxy shapes [...]]]></description>
			<content:encoded><![CDATA[<p> Played around with a few methods for modifying the terrain, so far just doing simple<br />
modifications to the fractional part of the noise input.  </p>
<p> The input is from 0.0-1.0, so to keep the terrain continuous it helps if the output also is<br />
(more or less); but at first I was getting terrain with boxy shapes because I wasn&#8217;t doing this<br />
correctly.</p>
<p>One very interesting result was this: A world composed out the outline of boxes.</p>
<p>Modification:<br />
                        _mu = _mu*2.0*1.33134 -1.33134;<br />
		        _mu = cos(_mu*_mu*_mu*_mu);<br />
 <a href='http://lugtug.com/dev/wp-content/uploads/2009/05/tinker.jpg' title='tinker.jpg'><img src='http://lugtug.com/dev/wp-content/uploads/2009/05/tinker.jpg' alt='tinker.jpg' /></a></p>
<p>Where they grow..<br />
<a href='http://lugtug.com/dev/wp-content/uploads/2009/06/crazyland.jpg' title='Tinker toys'><img src='http://lugtug.com/dev/wp-content/uploads/2009/06/crazyland.jpg' alt='Tinker toys' /></a></p>
<p>Another example where the signal is not smooth&#8230;<br />
<a href='http://lugtug.com/dev/wp-content/uploads/2009/06/brokeridge.jpg' title='Cool but pattern can be seen'><img src='http://lugtug.com/dev/wp-content/uploads/2009/06/brokeridge.jpg' alt='Cool but pattern can be seen' /></a></p>
<p>Realized what I was doing wrong, fixed it, and implemented a sin filter; it only looks<br />
subtly different from the standard appearance so I won&#8217;t bother posting a picture.</p>
<p>More interesting was a sin(x^2) filter:</p>
<p>		_mu *= 1.2533141373155002512078826424054;<br />
		_mu = sin(_mu*_mu)</p>
<p>Lots of poker type things appeared&#8230;<br />
<a href='http://lugtug.com/dev/wp-content/uploads/2009/05/poker.jpg' title='Poke'><img src='http://lugtug.com/dev/wp-content/uploads/2009/05/poker.jpg' alt='Poke' /></a></p>
<p>And some odd looking rounded shapes occasionally..</p>
<p><a href='http://lugtug.com/dev/wp-content/uploads/2009/05/thing.jpg' title='Smooth'><img src='http://lugtug.com/dev/wp-content/uploads/2009/05/thing.jpg' alt='Smooth' /></a></p>
<p>Dark twisted area I&#8217;m posting for no particular reason.<br />
<a href='http://lugtug.com/dev/wp-content/uploads/2009/05/darkland.jpg' title='darks'><img src='http://lugtug.com/dev/wp-content/uploads/2009/05/darkland.jpg' alt='darks' /></a></p>
<p><em><br />
 Super Shape?</em><br />
 I saw this about <a href="http://diaryofagraphicsprogrammer.blogspot.com/2009/04/3d-supershape.html">Super Shapes</a> and thought I might see if they could be made to<br />
work within my generation process&#8211; but the results aren&#8217;t so great, and it is also rather<br />
slow since it involves a great many calls to sin/cos.<br />
<a href='http://lugtug.com/dev/wp-content/uploads/2009/06/notsosupershape.jpg' title='Not so Super'><img src='http://lugtug.com/dev/wp-content/uploads/2009/06/notsosupershape.jpg' alt='Not so Super' /></a><br />
-Problem being the super shape function expects as input angles, and returns positions;<br />
but I already have a position &#038; just want to modify the density.  What I did was calculate an<br />
angle based on an arbitrary center point, and then use the returned position to modify<br />
the existing density dependent upon how far it was from the real position&#8230; but<br />
it tended to blob together and stretch/tear in ways that the proper super shapes don&#8217;t.</p>
<p><strong>Point Rendering</strong>:</p>
<p>Awhile back I was reading the <a href="http://www.farrarfocus.com/atom/090110.htm">Atom </a>journal and began wondering if points might<br />
be a nice solution for my terrain. </p>
<p>Good:<br />
    + Would greatly reduce memory usage since index buffers wouldn&#8217;t be necessary.<br />
    + The poor triangulation MC generates could be avoided and likely point interpolation<br />
       would look superior.<br />
    + Could skip most of the MC steps altogether for faster generation<br />
Bad:<br />
    &#8211; Could be issues if points aren&#8217;t dense enough<br />
    &#8211; The hole filling step doesn&#8217;t sound particularly fast, and I would have to do this<br />
       multiple times(shadow maps too).<br />
    &#8211; Might not work so great with occlusion culling </p>
<p>Here is the terrain rendered using points(looks kinda crap from jpg compression)<br />
<a href='http://lugtug.com/dev/wp-content/uploads/2009/06/pointcloud.jpg' title='point cloud'><img src='http://lugtug.com/dev/wp-content/uploads/2009/06/pointcloud.jpg' alt='point cloud' /></a></p>
<p><strong>Visual Studio 2010</strong><br />
 Also download the VS2010 beta 1, it supports lamba functions and<br />
various other new C++ features, but mainly what I noticed was:</p>
<p>1) Unresponsive UI &#8212; often around a 1 second delay<br />
2) It crashed within the first 5 minutes<br />
3) Intellisense can&#8217;t compete with visual assist, though it does have some new<br />
   abilities I have not seen before(red squiggle lines under things it doesn&#8217;t understand;<br />
   hover over said items and it actually says in English why).</p>
<p> I look forward to the new C++ language features, but MS really needs to improving<br />
the UI responsiveness; considering I&#8217;m running an i7 there is no reason<br />
for it to be so slow.</p>
<p><strong>Bindless Graphics</strong><br />
  Also tested out NVidia&#8217;s new <a href="http://developer.nvidia.com/object/bindless_graphics.html">bindless graphics</a> extensions, but for whatever reason<br />
this resulted in crashes once enough terrain chunks had been generated.<br />
An Nvidia guy told me it was a driver bug, so hopefully I can re-enable this down the road.<br />
Using occlusion culling also seemed to anger it greatly as any attempt to run with OC<br />
enabled would result in a crash within seconds of startup. </p>
<p>I&#8217;d like to start using dx11(or 10) more, OGL is just getting old.</p>
]]></content:encoded>
			<wfw:commentRss>http://lugtug.com/dev/2009/06/13/few-experiments/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Links</title>
		<link>http://lugtug.com/dev/2009/05/05/links/</link>
		<comments>http://lugtug.com/dev/2009/05/05/links/#comments</comments>
		<pubDate>Wed, 06 May 2009 05:23:28 +0000</pubDate>
		<dc:creator>Foxtox</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://lugtug.com/dev/links/</guid>
		<description><![CDATA[Game Dev Blogs: Atom Engine Old: Interesting tech journal, has some pretty cool ideas Atom Engine New: New location for above Real Time Rendering: Lots of good links can be found here C0DE517E: Another cool programming blog Ignacio Castaño: Has a very useful website, lots of knowledge about procedural/noise/demo scene related topics. Wolfgang: Light pre-pass [...]]]></description>
			<content:encoded><![CDATA[<p>Game Dev Blogs:</p>
<p><a href="http://www.farrarfocus.com/atom/index.htm">Atom Engine Old</a>: Interesting tech journal, has some pretty cool ideas<br />
<a href="http://farrarfocus.blogspot.com/">Atom Engine New</a>: New location for above<br />
<a href="http://www.realtimerendering.com/blog/">Real Time Rendering</a>: Lots of good links can be found here<br />
<a href="http://c0de517e.blogspot.com/">C0DE517E</a>: Another cool programming blog<br />
<a href="http://castano.ludicon.com/blog/">Ignacio Castaño</a>: Has a very useful website, lots of knowledge about procedural/noise/demo scene related topics.<br />
<a href="http://diaryofagraphicsprogrammer.blogspot.com/">Wolfgang</a>: Light pre-pass<br />
<a href="http://www.gamedev.net/community/forums/mod/journal/journal.asp?jn=263350">Infinity</a>: Ysaneya&#8217;s procedural universe game<br />
<a href="http://www.jshopf.com/blog/">Level of Detail</a>: Graphics talk<br />
<a href="http://repi.blogspot.com/">frostbite</a>: dx10 and graphics<br />
<a href="http://anteru.net/2008/07/25/242/">Anteru</a>: Another graphics  blog(voxels/points)</p>
<p>API/Code Links:</p>
<p><a href="http://icculus.org/physfs/">physfs</a>: multi-platform fileIO &#038; file packing<br />
<a href="http://squirrel-lang.org/default.aspx">Squirrel</a>: scripting language<br />
<a href="http://www.sfml-dev.org/index.php">Simple-fast media layer</a>: Input, other basic stuff</p>
]]></content:encoded>
			<wfw:commentRss>http://lugtug.com/dev/2009/05/05/links/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Occlusion</title>
		<link>http://lugtug.com/dev/2009/03/24/occlusion/</link>
		<comments>http://lugtug.com/dev/2009/03/24/occlusion/#comments</comments>
		<pubDate>Wed, 25 Mar 2009 05:06:18 +0000</pubDate>
		<dc:creator>Foxtox</dc:creator>
				<category><![CDATA[terrain]]></category>

		<guid isPermaLink="false">http://lugtug.com/dev/2009/03/24/occlusion/</guid>
		<description><![CDATA[Haven&#8217;t updated this website in far too long, took a break from this project(moved/new job). Back on track now; purchased a new computer, primarily intended for development purposes, it has an i7 920 quad core so I can really stress test my threading. i7 Results: Chunk generation on this processor makes my old Pentium D [...]]]></description>
			<content:encoded><![CDATA[<p>   Haven&#8217;t updated this website in far too long, took a break from this project(moved/new job).<br />
Back on track now; purchased a new computer, primarily intended for development purposes,<br />
it has an i7 920 quad core so I can really stress test my threading.</p>
<p><strong>i7 Results</strong>:<br />
   Chunk generation on this processor makes my old Pentium D look like a slug,<br />
I have hyper threading enabled, which currently results in 7 job threads being created.<br />
Didn&#8217;t measure it scientifically or anything, but eye balling the printout(prints out every<br />
512 chunks), it appears to creating 1k-1.5k chunks per second(old Pentium-D gave<br />
 100-200/sec).</p>
<p> Also have a new monitor which supports up to 1920&#215;1200 so I can finally run this at<br />
something higher then 1280&#215;1024. I was surprised to find that maxing the settings for<br />
the terrain(uses horizontal screen width) actually ran relatively smoothly.</p>
<p><strong>Occlusion Culling</strong>:<br />
  Last weekend I implemented occlusion culling for the terrain system, this has given a<br />
really nice boost to rendering speed, and has also helped out the generation process,<br />
as I can use occlusion information when assigning a priority to chunks that need to be<br />
generated(as in, if parent is occluded, reduce score, if grandparent is also occluded,<br />
 reduce it even more etc).</p>
<p> My implementation works like this(using a 3 frame delay):<br />
-Initially we have no OC&#8217;ing info, so render terrain front to back, issuing an occlusion<br />
query for each chunk.<br />
-If a chunk fails OC, switch to rendering its bounding box(AABB are rendered after all<br />
actual terrain chunks, and with depth/color writes disabled).<br />
-Newly created chunks take OC&#8217;ing state of parent.<br />
-If all children of a parent have failed OC test, fall back to parent(this will result in a<br />
chain reaction of fall backs in portions of scene that are deeply occluded &#8211; and more<br />
importantly, less objects to render), once parent becomes visible again, fall forward to<br />
children. This results in an interesting deblurring effect; when you pop your head<br />
around a corner, the world very rapidly comes into focus.</p>
<p><em>Few issues I ran into with occlusion culling</em>:</p>
<p>-Fast movement over the ledge of a cliff will result in the sudden appearance of new<br />
chunks, but since they occlusion results are delayed three frames, they still think they<br />
are occluded and don&#8217;t show up immediately.  </p>
<p> -Another problem was with chunks whose AABB test indicated they were the frustum,<br />
but upon rendering, none of the actual triangles are truly within the frustum, resulting in<br />
a failed query.  These chunks then promptly disappear(switch to invisible AABB test).<br />
The result of this, is that as the screen pans around, small holes appear on the side of<br />
the screen nearest the direction of movement.</p>
<p> Turns out there is a really simple solution, <a href="http://www.opengl.org/registry/specs/NV/conditional_render.txt">NV_conditional_render</a>.  Just issue the<br />
occlusion queries like normal, then in a later stage attempt to render those<br />
objects you think are occluded with a conditional render and the GPU handles<br />
the rest.  I still read back the occlusion results a few frames later, since it<br />
is useful for LOD and chunk generation.</p>
<p> Overall I&#8217;m very satisfied with the speedup(not exactly sure what it was, I&#8217;ll measure<br />
it at some point, but it was quite noticeable).</p>
<p><strong>Noise code to SSE:</strong><br />
    Awhile back(couple months ago) I also rewrote the majority of the noise code<br />
in SSE2.  Used AMD CodeAnalyst to find the hotspots and focused on reducing<br />
whichever part it indicated as being the slowest. Another nice performance boost<br />
was noticed.  At some point I think I will go back and add 64 bit double support<br />
to the entire pipeline since I would really like to be able to use more then 20 octaves<br />
before running into the damn stair step affect from precision loss, so I&#8217;ll<br />
have to write another SSE version using doubles, eventually.</p>
<p><a href='http://lugtug.com/dev/wp-content/uploads/2009/05/planetview2.jpg' title='Planet View'><img src='http://lugtug.com/dev/wp-content/uploads/2009/05/planetview2.jpg' alt='Planet View' /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://lugtug.com/dev/2009/03/24/occlusion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shadows</title>
		<link>http://lugtug.com/dev/2008/11/18/shadows/</link>
		<comments>http://lugtug.com/dev/2008/11/18/shadows/#comments</comments>
		<pubDate>Wed, 19 Nov 2008 03:31:28 +0000</pubDate>
		<dc:creator>Foxtox</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[shadows]]></category>
		<category><![CDATA[terrain]]></category>

		<guid isPermaLink="false">http://lugtug.com/dev/2008/11/18/shadows/</guid>
		<description><![CDATA[I&#8217;ve added PSSM(Parallel-Split shadow maps) based shadows, this technique uses multiple shadow maps each one progressively closer to the viewer. I went with PSSM because of the size of my terrain, even so, using 4 splits I have to limit how far away objects can be and still receive shadows. Having the render the scene [...]]]></description>
			<content:encoded><![CDATA[<p> I&#8217;ve added PSSM(Parallel-Split shadow maps) based shadows, this technique uses<br />
 multiple shadow maps each one progressively closer to the viewer.  I went with PSSM<br />
because of  the size of my terrain, even so, using 4 splits I have to limit how far away<br />
objects can be and still receive shadows.  </p>
<p>  Having the render the scene an extra four times is pretty unpleasant, hopefully<br />
once I add some more optimizations things will won&#8217;t be so slow.</p>
<p>  It still has some kinks, I need to eventually take into account the visible<br />
objects when constructing the matrices for the shadow map, and add<br />
some much better filtering.  There is also some perspective aliasing that<br />
needs fixing.  ShaderX6 apparently has an article covering some of these<br />
things but I don&#8217;t have a copy of the book.</p>
<p> Eventually I would like to use some sort of deferred rendering technique since<br />
it would allow for a cleaner shadow system, but not until I can get AA with deferred..<br />
though the light pre-pass method might work. </p>
<p>  Some screens with shadows: this made my 6800 cry</p>
<p><a href='http://lugtug.com/dev/wp-content/uploads/2008/11/shademe.jpg' title='In the Shade'><img src='http://lugtug.com/dev/wp-content/uploads/2008/11/shademe.jpg' alt='In the Shade' /></a></p>
<p><a href='http://lugtug.com/dev/wp-content/uploads/2008/11/longshade.jpg' title='A big rock says hi'><img src='http://lugtug.com/dev/wp-content/uploads/2008/11/longshade.jpg' alt='A big rock says hi' /></a></p>
<p><a href='http://lugtug.com/dev/wp-content/uploads/2008/11/moon.jpg' title='a moon'><img src='http://lugtug.com/dev/wp-content/uploads/2008/11/moon.jpg' alt='a moon' /></a></p>
<p><a href='http://lugtug.com/dev/wp-content/uploads/2008/11/hanger.jpg' title='A lonely hanger'><img src='http://lugtug.com/dev/wp-content/uploads/2008/11/hanger.jpg' alt='A lonely hanger' /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://lugtug.com/dev/2008/11/18/shadows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 1.573 seconds -->

