<?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>Unity Technologies Blog &#187; Aras Pranckevičius</title>
	<atom:link href="http://blogs.unity3d.com/author/aras/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.unity3d.com</link>
	<description>A glimpse inside Unity Technologies...</description>
	<lastBuildDate>Wed, 25 Jan 2012 11:59:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>&#8220;Fast Mobile Shaders&#8221; talk at SIGGRAPH</title>
		<link>http://blogs.unity3d.com/2011/08/18/fast-mobile-shaders-talk-at-siggraph/</link>
		<comments>http://blogs.unity3d.com/2011/08/18/fast-mobile-shaders-talk-at-siggraph/#comments</comments>
		<pubDate>Thu, 18 Aug 2011 07:08:07 +0000</pubDate>
		<dc:creator>Aras Pranckevičius</dc:creator>
				<category><![CDATA[Demos, Tutorials and Tips]]></category>
		<category><![CDATA[Events]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blogs.unity3d.com/?p=5245</guid>
		<description><![CDATA[Yes! I did a talk at SIGGRAPH! Ahem. So yeah, a bunch of us were at SIGGRAPH 2011 in lovely Vancouver, doing talks, meeting people and going to super interesting sessions. Me &#038; ReJ did a long technical session about optimizing graphics for mobile platforms. GPU architectures, shader optimization details, case studies from actual Unity...]]></description>
			<content:encoded><![CDATA[<p><a href="http://blogs.unity3d.com/wp-content/uploads/2011/08/siggraphshot.jpg"><img src="http://blogs.unity3d.com/wp-content/uploads/2011/08/siggraphshot-160x160.jpg" alt="" title="siggraphshot" width="160" height="160" class="alignright size-thumbnail wp-image-5276" /></a><em>Yes! I did a talk at <a href="http://www.siggraph.org/s2011/">SIGGRAPH</a>!</em></p>
<p>Ahem.</p>
<p>So yeah, a bunch of us were at SIGGRAPH 2011 in lovely Vancouver, <a href="http://blogs.unity3d.com/2011/08/08/unity-at-siggraph/">doing talks</a>, meeting people and going to super interesting sessions. <a href="http://twitter.com/#!/aras_p">Me</a> &#038; <a href="http://twitter.com/#!/__ReJ__">ReJ</a> did a long technical session about optimizing graphics for mobile platforms. GPU architectures, shader optimization details, case studies from actual Unity games and so on.</p>
<p>Here it is: <a href='http://blogs.unity3d.com/wp-content/uploads/2011/08/FastMobileShaders_siggraph2011.pdf'><strong>Fast Mobile Shaders</strong></a> (17MB pdf).</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.unity3d.com/2011/08/18/fast-mobile-shaders-talk-at-siggraph/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Notes on Native Client &amp; Pepper Plugin API</title>
		<link>http://blogs.unity3d.com/2011/06/02/notes-on-native-client-pepper-plugin-api/</link>
		<comments>http://blogs.unity3d.com/2011/06/02/notes-on-native-client-pepper-plugin-api/#comments</comments>
		<pubDate>Thu, 02 Jun 2011 10:42:14 +0000</pubDate>
		<dc:creator>Aras Pranckevičius</dc:creator>
				<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blogs.unity3d.com/?p=4837</guid>
		<description><![CDATA[Google&#8217;s Native Client (NaCl) is a brilliant idea. TL;DR: it allows native code to be run securely in the browser. Here&#8217;s a collection of developer-centric notes about it (it&#8217;s not very Unity specific). But is it secure? &#8220;Bububut, waitaminnit! Native code is not secure by definition&#8221; you say. Turns out, that isn&#8217;t necessarily true. With...]]></description>
			<content:encoded><![CDATA[<p>Google&#8217;s <a href="http://code.google.com/p/nativeclient/">Native Client</a> (NaCl) is a brilliant idea. <a href="http://en.wikipedia.org/wiki/Wikipedia:Too_long;_didn%27t_read">TL;DR</a>: it allows <em>native</em> code to be run <em>securely</em> in the browser. Here&#8217;s a collection of developer-centric notes about it (it&#8217;s not very Unity specific).</p>
<p><strong>But is it secure?</strong></p>
<p><em>&#8220;Bububut, waitaminnit! Native code is not secure by definition&#8221;</em> you say. Turns out, that isn&#8217;t necessarily true. With a specially massaged compiler, some runtime support and careful native code validation it is possible to ensure native code, when ran in the browser, can&#8217;t cause harm to user&#8217;s machine. I suggest taking a look at the original <a href="http://src.chromium.org/viewvc/native_client/data/docs_tarball/nacl/googleclient/native_client/documentation/nacl_paper.pdf">NaCl for x86 paper</a> and more recently, how similar techniques would apply to <a href="http://www.chromium.org/nativeclient/reference/arm-overview">ARM CPUs</a>.</p>
<p><strong>But what can you do with it?</strong></p>
<p><span id="more-4837"></span>So that&#8217;s great. It means it is possible to take C/C++ code, compile it with NaCl SDK (a gcc derived toolchain) and have it run in the browser. We can make a loop in C that multiplies a ton of floating point numbers, and it will run at native speed. That&#8217;s wonderful, except you can&#8217;t really do much interesting stuff with your own C code in isolation&#8230;</p>
<p>You need access to the hardware and/or OS. As game developers, we need pixels to appear on the screen. Preferably lots of them, with the help of something like a <a href="http://en.wikipedia.org/wiki/Graphics_processing_unit">GPU</a>. Audio waves to come out of the speakers. Mouse moves and keyboard presses to translate to some fancy actions. Post a high score to the internets. And so on.</p>
<p>NaCl surely can&#8217;t just allow my C code to call <a href="http://msdn.microsoft.com/en-us/library/bb219685(v=vs.85).aspx"><tt>Direct3DCreate9</tt></a> and run with it, while keeping the promise of &#8220;it&#8217;s secure&#8221;? Or a more extreme case, <tt>FILE* f = fopen("/etc/passwd", "rt");</tt>?!</p>
<p>And that&#8217;s true; NaCl does not allow you to use completely arbitrary APIs. It has it&#8217;s own set of APIs to interface with &#8220;the system&#8221;.</p>
<p><strong>Ok, how do I interface with the system?</strong></p>
<p>&#8230;and that&#8217;s where the current state of NaCl gets a bit confusing.</p>
<p>Initially Google developed an improved &#8220;browser plugin model&#8221; and called it Pepper. This Pepper thing would then take care of actually putting your code <em>into the browser</em>. Starting it up, tearing it down, controlling repaints, processing events and so on. But then apparently they realized that building on top of a decade-old Netscape plugin API (<a href="http://en.wikipedia.org/wiki/NPAPI">NPAPI</a>) isn&#8217;t going to really work, so they developed Pepper2 or PPAPI (Pepper Plugin API) which ditches NPAPI completely. To write a native client plugin, you only interface with PPAPI.</p>
<p>So some of the pages on the internets reference the &#8220;old API&#8221; (which is gone as far as I can see), and some others reference the new one. It does not help that Native Client&#8217;s own documentation are scattered around in <a href="http://www.chromium.org/nativeclient">Chromium</a>, <a href="http://code.google.com/p/nativeclient/">NaCl</a>, <a href="http://code.google.com/p/nativeclient-sdk/">NaCl SDK</a> and <a href="http://code.google.com/p/ppapi/">PPAPI</a> sites. Seriously, <em>it&#8217;s a mess</em>, with seemingly no high level, up to date &#8220;introduction&#8221; page that tells what exactly PPAPI can and can&#8217;t do. <em>Edit</em>: I&#8217;m told that the definitive entry point to NaCl right now is this page: <a href="http://code.google.com/chrome/nativeclient/"><strong>http://code.google.com/chrome/nativeclient/</strong></a> which clears up some mess.</p>
<p><strong>Here&#8217;s what I think it can do</strong></p>
<p><em>Note: we have an in-progress Unity NaCl port using this PPAPI. However, I am not working on it, so my knowledge may or may not be true. Take everything with a grain of NaCl <img src='http://blogs.unity3d.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </em></p>
<p>Most of things below found by poking around at <a href="http://src.chromium.org/viewvc/chrome/trunk/src/ppapi/">PPAPI source tree</a>, and by looking into Unity&#8217;s NaCl platform dependent bits.</p>
<p><em><strong>Graphics</strong></em></p>
<p>PPAPI provides an OpenGL ES 2.0 implementation for your 3D needs. You need to setup the context and initial surfaces via PPAPI (<tt><a href="http://src.chromium.org/viewvc/chrome/trunk/src/ppapi/cpp/dev/context_3d_dev.h?view=markup">ppapi/cpp/dev/context_3d_dev.h</a>, <a href="http://src.chromium.org/viewvc/chrome/trunk/src/ppapi/cpp/dev/surface_3d_dev.h?view=markup">ppapi/cpp/dev/surface_3d_dev.h</a></tt>) &#8211; similar to what you&#8217;d use EGL on other platforms for &#8211; and beyond that you just include <tt>GLES2/gl2.h, GLES2/gl2ext.h</tt> and call ye olde GLES2.0 functions.</p>
<p>Behind the scenes, all your GLES2.0 calls will be put into a <a href="http://src.chromium.org/viewvc/chrome/trunk/src/gpu/command_buffer/">command buffer</a> and transferred to actual &#8220;3D server&#8221; process for consuming them. Chrome splits up itself into various processes like that for security reasons &#8212; so that each process has the minimum set of privileges, and a crash or a security exploit in one of them can&#8217;t easily transfer over to other parts of the browser.</p>
<p><em><strong>Audio</strong></em></p>
<p>For audio needs, PPAPI provides a simple buffer based API in <tt><a href="http://src.chromium.org/viewvc/chrome/trunk/src/ppapi/cpp/audio_config.h?view=markup">ppapi/cpp/audio_config.h</a></tt> and <tt><a href="http://src.chromium.org/viewvc/chrome/trunk/src/ppapi/cpp/audio.h?view=markup">ppapi/cpp/audio.h</a></tt>. Your own callback will be called whenever audio buffer needs to be filled with new samples. That means you do all sound mixing yourself and just fill in the final buffer.</p>
<p><em><strong>Input</strong></em></p>
<p>Your plugin instance (subclass of <tt>pp::Instance</tt>) will get input events via HandleInputEvent virtual function override. Each event is a simple <a href="http://src.chromium.org/viewvc/chrome/trunk/src/ppapi/c/pp_input_event.h?view=markup"><tt>PPInputEvent</tt> struct</a> and can represent keyboard &#038; mouse. No support for gamepads or touch input so far, it seems.</p>
<p><em><strong>Other stuff</strong></em></p>
<p>Doing WWW requests is possible via <tt><a href="http://src.chromium.org/viewvc/chrome/trunk/src/ppapi/cpp/url_loader.h?view=markup">ppapi/cpp/url_loader.h</a></tt> and friends.</p>
<p>Timer &#038; time queries via <tt><a href="http://src.chromium.org/viewvc/chrome/trunk/src/ppapi/cpp/core.h?view=markup">ppapi/cpp/core.h</a></tt> (e.g. <tt>pp::Module::Get()->core()->CallOnMainThread(...)</tt>).</p>
<p>And, well, a bunch of other stuff is there, like ability to rasterize blocks of text into bitmaps, pop up file selection dialogs, use the browser to decode video streams and so on. Everything &#8211; or almost everything &#8211; is there to make it possible to do games on it.</p>
<p><strong>Summary</strong></p>
<p>Like <a href="http://chadaustin.me/2011/01/in-defense-of-language-democracy/">Chad says</a>, it would be good to end <em>&#8220;thou shalt only use Javascript&#8221;</em> on the web. Javascript is a very nice language &#8211; especially considering how it came into existence &#8211; but <em>forcing</em> it on everyone is quite silly. And no matter how hard V8/JägerMonkey/Nitro folks are trying, it is very, very hard to <a href="http://chadaustin.me/2011/01/digging-into-javascript-performance/">beat performance</a> of a simple, static, compiled language (like C) that has direct access to memory and the programmer is in almost full control of both the code flow and the memory layout. Steve rightly <a href="http://twitter.com/#!/stevestreeting/status/76216985888882688">points out</a> that even if for some tasks a super-optimized Javascript engine will approach the speed of C, it will burn much more energy to do so &#8212; a very important aspect in the increasingly mobile world.</p>
<p>Native Client does give some hope that there will be a way to run native code, at native speeds, in the browser, without compromising on security. Let it happen.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.unity3d.com/2011/06/02/notes-on-native-client-pepper-plugin-api/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Coming in 3.2: mobile graphics optimizations</title>
		<link>http://blogs.unity3d.com/2011/01/18/coming-in-3-2-mobile-graphics-optimizations/</link>
		<comments>http://blogs.unity3d.com/2011/01/18/coming-in-3-2-mobile-graphics-optimizations/#comments</comments>
		<pubDate>Tue, 18 Jan 2011 12:54:28 +0000</pubDate>
		<dc:creator>Aras Pranckevičius</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Unity Products and Services]]></category>

		<guid isPermaLink="false">http://blogs.unity3d.com/?p=3715</guid>
		<description><![CDATA[Last week, we started talking about Unity 3.2 by giving you a look at one of the updated Standard Assets. We&#8217;ll have more to show soon, but in the meantime we wanted to tell you about some of the optimizations that have been made to deliver great looking high-performance graphics on iOS and Android. Precision...]]></description>
			<content:encoded><![CDATA[<p><img src="http://blogs.unity3d.com/wp-content/uploads/2011/01/dualstick3.2.jpg" alt="3.2 Mobile Enhancements" title="3.2 Mobile Enhancements" width="300" height="275" class="alignright size-full wp-image-3723" style="border:0px" />Last week, we started talking about Unity 3.2 by giving you a look at one of the <a href="http://blogs.unity3d.com/2011/01/11/standard-assets-update-part-one/">updated Standard Assets</a>. We&#8217;ll have more to show soon, but in the meantime we wanted to tell you about some of the optimizations that have been made to deliver great looking high-performance graphics on iOS and Android. </p>
<p><strong>Precision of Shader Computations</strong><br />
Unity 3.2 makes much better use of different precision shader computations in OpenGL ES 2.0 shaders. This alone results in a 50%-150% speed increase on more complex shaders. Our <a href="http://blogs.unity3d.com/2010/10/20/shader-compilation-for-multiple-platforms/">GLSL Translator &#038; Optimizer</a> has been extended so that float/half/fixed types in Cg map to highp/mediump/lowp precision in GLSL, and we&#8217;ve updated all built-in shaders to use appropriate precision. </p>
<p><strong>Normal Mapping</strong><br />
We&#8217;ve made several tweaks to make normal mapping faster.  On desktops, we use &#8220;DXT5nm&#8221; compression for normal maps, where two normal components are stored and third is computed in the shader &#8211; this works great because it allows using DXT5 on the normalmaps. However, the extra computation is not very good for mobile platforms, so we&#8217;ve changed the normal map compression scheme there. We&#8217;ve also implement assembly optimized skinning for normal mapped meshes &#8212; this is now 4x faster than before. </p>
<p><strong>Built-In Shaders</strong><br />
Unity 3.2 will ship with new shaders that are optimized variants of existing built-in shaders. You&#8217;ll be able to find them under the &#8220;Mobile&#8221; category (but they work on other platforms  as well!). These new shaders have a few limitations, but the upside is increased performance &#8212; the Mobile/Bumped Specular, for example,  is 5.2x faster than the Bumped Specular currently shipping in Unity 3.1 (tested on iOS).</p>
<p><strong>Other Optimizations</strong><br />
There are a number of other improvements that make Unity-created mobile content run faster in 3.2. For example, we&#8217;ve optimized the internals of the OpenGL ES 2.0 renderer for lower CPU overhead. We&#8217;ve also changed how Unity handles alpha-testing so that those objects are rendered after all fully opaque ones. These and other tweaks and adjustments are all designed to help you get the most out of your mobile game.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.unity3d.com/2011/01/18/coming-in-3-2-mobile-graphics-optimizations/feed/</wfw:commentRss>
		<slash:comments>36</slash:comments>
		</item>
		<item>
		<title>Shader Compilation for Multiple Platforms</title>
		<link>http://blogs.unity3d.com/2010/10/20/shader-compilation-for-multiple-platforms/</link>
		<comments>http://blogs.unity3d.com/2010/10/20/shader-compilation-for-multiple-platforms/#comments</comments>
		<pubDate>Wed, 20 Oct 2010 12:58:52 +0000</pubDate>
		<dc:creator>Aras Pranckevičius</dc:creator>
				<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blogs.unity3d.com/?p=3466</guid>
		<description><![CDATA[Unity 3 launched recently, and with Surface Shaders we made it much easier to handle lighting, shadowing &#038; rendering paths pieces of shaders. But Unity can run on so many platforms (some having very different shader languages), yet you can write a shader once, and somehow it &#8220;just works&#8221; on all platforms. How do we...]]></description>
			<content:encoded><![CDATA[<p>Unity 3 launched recently, and with <a href="http://blogs.unity3d.com/2010/07/17/unity-3-technology-surface-shaders/">Surface Shaders</a> we made it much easier to handle lighting, shadowing &#038; rendering paths pieces of shaders. But Unity can run on so many platforms (some having very different shader languages), yet you can write a shader once, and somehow it &#8220;just works&#8221; on all platforms. How do we do that? I&#8217;m going to talk about some behind-the-scenes technology involved in compiling shaders.</p>
<p><span id="more-3466"></span><em>Warning: technical post ahead!</em></p>
<p><strong>Shading Languages</strong></p>
<p>There are two widely used shader languages out there: <a href="http://en.wikipedia.org/wiki/High_Level_Shader_Language">HLSL</a> (or Cg, which is the same for practical purposes) and <a href="http://en.wikipedia.org/wiki/GLSL">GLSL</a>. Cg/HLSL is used by Direct3D, Xbox 360 and PS3. GLSL is used by mobile platforms (OpenGL ES 2.0), Mac OS X (OpenGL) and upcoming WebGL.</p>
<p>Traditionally in Unity shaders are written in Cg/HLSL (there&#8217;s an option to write GLSL if you want to), so we had to find a way to take Cg shader and produce GLSL shader out of it. So you could write a shader like:</p>
<blockquote><pre>
// ...vertex shader omitted
sampler2D _MainTex;
half4 _Color;
half4 frag (float2 uv:TEXCOORD0) : COLOR {
    return tex2D (_MainTex, uv) * _Color;
}</pre>
</blockquote>
<p>&#8230;and somehow it would also work on mobile platforms on OpenGL ES 2.0. In short, you can do that in Unity 3. But if you want to know <em>how</em> that works, read on.</p>
<p><strong>HLSL to GLSL Translator</strong></p>
<p>The two shading languages are similar in principle, but there are lots of subtle differences that make a regexp-based converter not quite work (regular expression based parsers are <a href="http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454">rarely a good idea</a> by the way).</p>
<p>So we took <a href="http://sourceforge.net/projects/hlsl2glsl/">HLSL2GLSL</a>, an existing open source project that ATI has made 4 years ago and seemingly abandoned. Turns out it needed some massaging to get it work, as well as a ton of bug fixes, missing features and general code cleanup. But hey, it seems to work now!</p>
<p>Our fork of this translator, named &#8220;hlsl2glslfork&#8221;, is here: <a href="http://code.google.com/p/hlsl2glslfork/"><strong>http://code.google.com/p/hlsl2glslfork/</strong></a><br />
<em>(you can probably tell that I&#8217;m not too good at picking fancy names)</em></p>
<p>So now we can translate Cg/HLSL shaders into GLSL, and we&#8217;re done? Turns out, not quite so.</p>
<p><strong>GLSL Optimizer</strong></p>
<p>The shaders produced by the translator work on mobile platforms (iOS/Android). However, some of them were running <em>very</em> slow. The OpenGL ES 2.0 drivers in the mobile platforms aren&#8217;t very good at optimizing shaders! Or rather, some of them are seriously bad at optimizing.</p>
<p>Suffice to say, something extremely simple like a particle shader was running <em>6 times slower</em> than it should have. Six. Times. Ouch!</p>
<p>Almost by accident, I discovered that <a href="http://mesa3d.org/">Mesa 3D</a> guys are working on new GLSL compiler. I looked at the code and I liked it a lot; very hackable and “no bullshit” approach. So I took that Mesa&#8217;s GLSL compiler and made it output GLSL back after it has done all the optimizations (dead code removal, algebraic simplifications, constant propagation, constant folding, inlining and a bunch of other cryptic things that don&#8217;t mean anything to a normal person).</p>
<p>Here it is, named &#8220;GLSL Optimizer&#8221;: <a href="http://github.com/aras-p/glsl-optimizer"><strong>http://github.com/aras-p/glsl-optimizer</strong></a><br />
<em>(here&#8217;s my fancy-name-choosing in action again)</em></p>
<p>The good news is that it solves the performance problems on iOS/Android platforms. Yay!</p>
<p><strong>Further work</strong></p>
<p>For mobile platforms, using appropriate precision qualifiers is very important for performance. If some value has low range and does not need high precision, using &#8220;lowp&#8221; (low precision) qualifier can potentially make the shader work much faster. In Unity 3.0 we do some automagic to put the appropriate precision, but we could be better at it. I&#8217;m experimenting with proper precision support in HLSL to GLSL translator and the GLSL Optimizer, so that fixed/half/float types in Cg/HLSL would come out as lowp/mediump/highp in the resulting GLSL&#8230; we&#8217;ll see how that turns out.</p>
<p>Maybe at some point in the future it would make sense to have the opposite translation tool? So one could write GLSL shaders, and they would be converted into Cg/HLSL for the other platforms&#8230;</p>
<p><em>Oh, and next week Unity&#8217;s mobile tech. lead Renaldas &#8220;ReJ&#8221; Zioma is going to blog something technology related as well. Hear me ReJ? Now you have to do it!</em></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.unity3d.com/2010/10/20/shader-compilation-for-multiple-platforms/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Unity 3 technology &#8211; Surface Shaders</title>
		<link>http://blogs.unity3d.com/2010/07/17/unity-3-technology-surface-shaders/</link>
		<comments>http://blogs.unity3d.com/2010/07/17/unity-3-technology-surface-shaders/#comments</comments>
		<pubDate>Sat, 17 Jul 2010 12:40:16 +0000</pubDate>
		<dc:creator>Aras Pranckevičius</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Unity Products and Services]]></category>

		<guid isPermaLink="false">http://blogs.unity3d.com/?p=3236</guid>
		<description><![CDATA[In Unity you can write your own custom shaders, but it&#8217;s no secret that writing them is hard, especially when you need shaders that interact with per-pixel lights &#038; shadows. In Unity 3, that would be even harder because in addition to all the old stuff, your shaders would have to support the new Deferred...]]></description>
			<content:encoded><![CDATA[<p>In Unity you can write your own custom shaders, but it&#8217;s no secret that writing them is hard, especially when you need shaders that interact with per-pixel lights &#038; shadows. In Unity 3, that would be even harder  because in addition to all the old stuff, your shaders would have to support the new Deferred Lighting renderer. We decided it&#8217;s time to make shaders <em>somewhat easier</em> to write.</p>
<p><em>Warning: a technical post ahead with almost no pictures!</em></p>
<p>Over a year ago I had a thought that &#8220;Shaders must die&#8221; (<a href="http://aras-p.info/blog/2009/05/05/shaders-must-die/">part 1</a>, <a href="http://aras-p.info/blog/2009/05/07/shaders-must-die-part-2/">part 2</a>, <a href="http://aras-p.info/blog/2009/05/10/shaders-must-die-part-3/">part 3</a>). And what do you know &#8211; turns out we&#8217;re doing this in Unity 3. We call this <strong>Surface Shaders</strong> cause I&#8217;ve a suspicion &#8220;shaders must die&#8221; as a feature name wouldn&#8217;t have flied very far.</p>
<p><span id="more-3236"></span></p>
<p><strong>Idea</strong></p>
<p>The main idea is that 90% of the time I just want to declare surface properties. This is what I want to say:</p>
<blockquote><p>Hey, albedo comes from this texture mixed with this texture, and normal comes from this normal map. Use Blinn-Phong lighting model please, and don&#8217;t bother me again!</p></blockquote>
<p>With the above, I don&#8217;t have to care whether this will be used in a forward or deferred rendering, or how various light types will be handled, or how many lights per pass will be done in a forward renderer, or how some indirect illumination SH probes will come in, etc. I&#8217;m not interested in all that! These dirty bits are job of rendering programmers, <em>just make it work dammit</em>!</p>
<p>This is not a new idea. Most graphical shader editors <em>that make sense</em> do not have &#8220;pixel color&#8221; as the final output node; instead they have some node that basically describes surface parameters (diffuse, specularity, normal, &#8230;), and all the lighting code is usually not expressed in the shader graph itself. <a href="http://code.google.com/p/openshadinglanguage/">OpenShadingLanguage</a> is a similar idea as well (but because it&#8217;s targeted at offline rendering for movies, it&#8217;s much richer &#038; more complex).</p>
<p><strong>Example</strong></p>
<p>Here&#8217;s a simple &#8211; but full &#038; complete &#8211; Unity 3.0 shader that does diffuse lighting with a texture &#038; a normal map.</p>
<pre>
  <span style="color:gray">Shader "Example/Diffuse Bump" {
    Properties {
      _MainTex ("Texture", 2D) = "white" {}
      _BumpMap ("Bumpmap", 2D) = "bump" {}
    }
    SubShader {
      Tags { "RenderType" = "Opaque" }
      CGPROGRAM</span>
      #pragma surface surf Lambert
      struct Input {
        float2 uv_MainTex;
        float2 uv_BumpMap;
      };
      sampler2D _MainTex;
      sampler2D _BumpMap;
      void surf (Input IN, inout SurfaceOutput o) {
        o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
        o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
      }
      <span style="color:gray">ENDCG
    }
    Fallback "Diffuse"
  }</span></pre>
<p><a href="http://blogs.unity3d.com/wp-content/uploads/2010/07/SurfaceShaderDiffuseBump.png"><img src="http://blogs.unity3d.com/wp-content/uploads/2010/07/SurfaceShaderDiffuseBump-150x150.png" alt="Surface Shader: Diffuse Normalmapped" title="Surface Shader: Diffuse Normalmapped" width="150" height="150" class="alignright size-thumbnail wp-image-3239" /></a>Given pretty model &#038; textures, it can produce pretty pictures! How cool is that?</p>
<p>I grayed out bits that are not really interesting (declaration of serialized shader properties &#038; their UI names, shader fallback for older machines etc.). What&#8217;s left is Cg/HLSL code, which is then augmented by tons of auto-generated code that deals with lighting &#038; whatnot.</p>
<p>This surface shader dissected into pieces:</p>
<ul>
<li><tt>#pragma surface surf Lambert</tt>: this is a surface shader with main function &#8220;surf&#8221;, and a Lambert lighting model. Lambert is one of predefined lighting models, but you can write your own.</li>
<li><tt>struct Input</tt>: input data for the surface shader. This can have various predefined inputs that will be computed per-vertex &#038; passed into your surface function per-pixel. In this case, it&#8217;s two texture coordinates.</li>
<li><tt>surf</tt> function: actual surface shader code. It takes Input, and writes into <tt>SurfaceOutput</tt> (a predefined structure). It is possible to write into custom structures, provided you use lighting models that operate on those structures. The actual code just writes Albedo and Normal to the output.</li>
</ul>
<p><strong>What is generated</strong></p>
<p>Unity&#8217;s &#8220;surface shader code generator&#8221; would take this, generate <em>actual</em> vertex &#038; pixel shaders, and compile them to various target platforms. With default settings in Unity 3.0, it would make this shader support:</p>
<ul>
<li>Forward renderer and Deferred Lighting (Light Pre-Pass) renderer.</li>
<li>Objects with precomputed lightmaps and without.</li>
<li>Directional, Point and Spot lights; with projected light cookies or without; with shadowmaps or without. Well ok, this is only for forward renderer because in Deferred Lighting the lighting happens elsewhere.</li>
<li>For Forward renderer, it would compile in support for lights computed per-vertex and spherical harmonics lights computed per-object. It would also generate extra additive blended pass if needed for the case when additional per-pixel lights have to be rendered in separate passes.</li>
<li>For Deferred Lighting, it would generate base pass that outputs normals &#038; specular power; and a final pass that combines albedo with lighting, adds in any lightmaps or emissive lighting etc.</li>
<li>It can optionally generate a shadow caster rendering pass (needed if custom vertex position modifiers are used for vertex shader based animation; or some complex alpha-test effects are done).</li>
</ul>
<p>For example, here&#8217;s code that would be compiled for a forward-rendered base pass with one directional light, 4 per-vertex point lights, 3rd order SH lights; optional lightmaps <em>(I suggest just scrolling down)</em>: </p>
<pre style="font-size: 75%;">
#pragma vertex vert_surf
#pragma fragment frag_surf
#pragma fragmentoption ARB_fog_exp2
#pragma fragmentoption ARB_precision_hint_fastest
#pragma multi_compile_fwdbase
#include "HLSLSupport.cginc"
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "AutoLight.cginc"
struct Input {
	float2 uv_MainTex : TEXCOORD0;
};
sampler2D _MainTex;
sampler2D _BumpMap;
void surf (Input IN, inout SurfaceOutput o)
{
	o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
	o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_MainTex));
}
struct v2f_surf {
  V2F_POS_FOG;
  float2 hip_pack0 : TEXCOORD0;
  #ifndef LIGHTMAP_OFF
  float2 hip_lmap : TEXCOORD1;
  #else
  float3 lightDir : TEXCOORD1;
  float3 vlight : TEXCOORD2;
  #endif
  LIGHTING_COORDS(3,4)
};
#ifndef LIGHTMAP_OFF
float4 unity_LightmapST;
#endif
float4 _MainTex_ST;
v2f_surf vert_surf (appdata_full v) {
  v2f_surf o;
  PositionFog( v.vertex, o.pos, o.fog );
  o.hip_pack0.xy = TRANSFORM_TEX(v.texcoord, _MainTex);
  #ifndef LIGHTMAP_OFF
  o.hip_lmap.xy = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw;
  #endif
  float3 worldN = mul((float3x3)_Object2World, SCALED_NORMAL);
  TANGENT_SPACE_ROTATION;
  #ifdef LIGHTMAP_OFF
  o.lightDir = mul (rotation, ObjSpaceLightDir(v.vertex));
  #endif
  #ifdef LIGHTMAP_OFF
  float3 shlight = ShadeSH9 (float4(worldN,1.0));
  o.vlight = shlight;
  #ifdef VERTEXLIGHT_ON
  float3 worldPos = mul(_Object2World, v.vertex).xyz;
  o.vlight += Shade4PointLights (
    unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0,
    unity_LightColor0, unity_LightColor1, unity_LightColor2, unity_LightColor3,
    unity_4LightAtten0, worldPos, worldN );
  #endif // VERTEXLIGHT_ON
  #endif // LIGHTMAP_OFF
  TRANSFER_VERTEX_TO_FRAGMENT(o);
  return o;
}
#ifndef LIGHTMAP_OFF
sampler2D unity_Lightmap;
#endif
half4 frag_surf (v2f_surf IN) : COLOR {
  Input surfIN;
  surfIN.uv_MainTex = IN.hip_pack0.xy;
  SurfaceOutput o;
  o.Albedo = 0.0;
  o.Emission = 0.0;
  o.Specular = 0.0;
  o.Alpha = 0.0;
  o.Gloss = 0.0;
  surf (surfIN, o);
  half atten = LIGHT_ATTENUATION(IN);
  half4 c;
  #ifdef LIGHTMAP_OFF
  c = LightingLambert (o, IN.lightDir, atten);
  c.rgb += o.Albedo * IN.vlight;
  #else // LIGHTMAP_OFF
  half3 lmFull = DecodeLightmap (tex2D(unity_Lightmap, IN.hip_lmap.xy));
  #ifdef SHADOWS_SCREEN
  c.rgb = o.Albedo * min(lmFull, atten*2);
  #else
  c.rgb = o.Albedo * lmFull;
  #endif
  c.a = o.Alpha;
  #endif // LIGHTMAP_OFF
  return c;
}
</pre>
<p>Of those 90 lines of code, 10 are your original surface shader code; the remaining 80 would have to be pretty much written by hand in Unity 2.x days (well ok, less code would have to be written because 2.x had less rendering features). <em>But wait</em>, that was only base pass of the forward renderer! It also generates code for additive pass, for deferred base pass, deferred final pass, optionally for shadow caster pass and so on.</p>
<p>So this should be an easier to write lit shaders (it is for me at least). I hope this will also increase the number of Unity users who can write shaders at least 3 times <em>(i.e. to 30 up from 10!)</em>. It <em>should</em> be more future proof to accomodate changes to the lighting pipeline we&#8217;ll do in Unity next.</p>
<p><strong>Predefined Input values</strong></p>
<p>The Input structure can contain texture coordinates and some predefined values, for example view direction, world space position, world space reflection vector and so on. Code to compute them is only generated if they are <em>actually</em> used. For example, if you use world space reflection to do some cubemap reflections (as emissive term) in your surface shader, then in Deferred Lighting base pass the reflection vector will <em>not be computed</em> (since it does not output emission, so by extension does not need reflection vector).</p>
<p><a href="http://blogs.unity3d.com/wp-content/uploads/2010/07/SurfaceShaderRim.png"><img src="http://blogs.unity3d.com/wp-content/uploads/2010/07/SurfaceShaderRim-150x150.png" alt="Surface Shader: Rim Lighting" title="Surface Shader: Rim Lighting" width="150" height="150" class="alignright size-thumbnail wp-image-3240" /></a>As a small example, the shader above extended to do simple rim lighting:</p>
<pre>
  <span style="color:gray">#pragma surface surf Lambert
  struct Input {
      float2 uv_MainTex;
      float2 uv_BumpMap;</span>
      float3 viewDir;
  <span style="color:gray">};
  sampler2D _MainTex;
  sampler2D _BumpMap;</span>
  float4 _RimColor;
  float _RimPower;
  <span style="color:gray">void surf (Input IN, inout SurfaceOutput o) {
      o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
      o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));</span>
      half rim =
          1.0 - saturate(dot (normalize(IN.viewDir), o.Normal));
      o.Emission = _RimColor.rgb * pow (rim, _RimPower);
  <span style="color:gray">}</span>
</pre>
<p><strong>Vertex shader modifiers</strong></p>
<p><a href="http://blogs.unity3d.com/wp-content/uploads/2010/07/SurfaceShaderNormalExtrusion.png"><img src="http://blogs.unity3d.com/wp-content/uploads/2010/07/SurfaceShaderNormalExtrusion-150x150.png" alt="Surface Shader: Normal Extrusion" title="Surface Shader: Normal Extrusion" width="150" height="150" class="alignright size-thumbnail wp-image-3241" /></a>It is possible to specify custom &#8220;vertex modifier&#8221; function that will be called at start of the generated vertex shader, to modify (or generate) per-vertex data. You know, vertex shader based tree wind animation, grass billboard extrusion and so on. It can also fill in any non-predefined values in the Input structure.</p>
<p>My favorite vertex modifier? Moving vertices along their normals.</p>
<p><strong>Custom Lighting Models</strong></p>
<p>There are a couple simple lighting models built-in, but it&#8217;s possible to specify your own. A lighting model is nothing more than a function that will be called with the filled SurfaceOutput structure and per-light parameters (direction, attenuation and so on). Different functions would have to be called in forward &#038; deferred rendering cases; and naturally the deferred one has much less flexibility. So for any fancy effects, it is possible to say &#8220;do not compile this shader for deferred&#8221;, in which case it will be rendered via forward rendering.</p>
<p><a href="http://blogs.unity3d.com/wp-content/uploads/2010/07/SurfWrapLambert.png"><img src="http://blogs.unity3d.com/wp-content/uploads/2010/07/SurfWrapLambert-150x150.png" alt="Surface Shader: Wrapped Lambert lighting" title="Surface Shader: Wrapped Lambert lighting" width="150" height="150" class="alignright size-thumbnail wp-image-3242" /></a>Example of wrapped-Lambert lighting model:</p>
<pre>
  #pragma surface surf WrapLambert
  half4 LightingWrapLambert (SurfaceOutput s, half3 dir, half atten) {
      dir = normalize(dir);
      half NdotL = dot (s.Normal, dir);
      half diff = NdotL * 0.5 + 0.5;
      half4 c;
      c.rgb = s.Albedo * _LightColor0.rgb * (diff * atten * 2);
      c.a = s.Alpha;
      return c;
  }
  <span style="color:gray">struct Input {
      float2 uv_MainTex;
  };
  sampler2D _MainTex;
  void surf (Input IN, inout SurfaceOutput o) {
      o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
  }</span></pre>
<p><strong>Behind the scenes</strong></p>
<p>We&#8217;re using HLSL parser from Ryan Gordon&#8217;s <a href="http://hg.icculus.org/icculus/mojoshader/">mojoshader</a> to parse the original surface shader code and infer some things from the abstract syntax tree mojoshader produces. This way we can figure out what members are in what structures, go over function prototypes and so on. At this stage some error checking is done to tell the user his surface function is of wrong prototype, or his structures are missing required members &#8211; which is much better than failing with dozens of compile errors in the generated code later.</p>
<p>To figure out which surface shader inputs are <em>actually</em> used in the various lighting passes, we&#8217;re generating small dummy pixel shaders, compile them with Cg and use Cg&#8217;s API to query used inputs &#038; outputs. This way we can figure out, for example, that a normal map nor it&#8217;s texture coordinate is not actually used in Deferred Lighting final pass, and save some vertex shader instructions &#038; a texcoord interpolator.</p>
<p>The code that is ultimately generated is compiled with various shader compilers depending on the target platform (Cg for Windows/Mac, XDK HLSL for Xbox 360, PS3 Cg for PS3, and our own <a href="http://code.google.com/p/hlsl2glslfork/">fork of HLSL2GLSL</a> for iPhone, Android and upcoming <a href="http://blogs.unity3d.com/2010/05/19/google-android-and-the-future-of-games-on-the-web/">NativeClient port of Unity</a>).</p>
<p>So yeah, that&#8217;s it. We&#8217;ll see where this goes next, or what happens when Unity 3 will be released. I hope more folks will try to write shaders!</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.unity3d.com/2010/07/17/unity-3-technology-surface-shaders/feed/</wfw:commentRss>
		<slash:comments>40</slash:comments>
		</item>
		<item>
		<title>Summer of Code: Terrain Toolkit Released!</title>
		<link>http://blogs.unity3d.com/2010/02/23/summer-of-code-terrain-toolkit-released/</link>
		<comments>http://blogs.unity3d.com/2010/02/23/summer-of-code-terrain-toolkit-released/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 14:29:16 +0000</pubDate>
		<dc:creator>Aras Pranckevičius</dc:creator>
				<category><![CDATA[Community News and Info]]></category>
		<category><![CDATA[Company News and Info]]></category>
		<category><![CDATA[Events]]></category>

		<guid isPermaLink="false">http://blogs.unity3d.com/?p=2246</guid>
		<description><![CDATA[This blog post is written by Sándor Moldán (Nekharoth on forums) who has been working on Terrain Toolkit to help generate realistic terrains in Unity Editor. The project was one of the four selected projects that were selected for the Unity Summer of Code. Terrain Toolkit The Terrain Toolkit is an integrated set of tools...]]></description>
			<content:encoded><![CDATA[<p><em>This blog post is written by Sándor Moldán (Nekharoth on forums) who has been working on <a href="http://unity3d.com/support/resources/unity-extensions/terrain-toolkit">Terrain Toolkit</a> to help generate realistic terrains in Unity Editor. The project was one of the <a href="http://blogs.unity3d.com/2009/07/22/unity-summer-of-code-takes-off/">four selected projects</a> that were selected for the <a href="http://unity3d.com/usc/">Unity Summer of Code</a>.</em></p>
<p><strong>Terrain Toolkit</strong></p>
<p><a href="http://blogs.unity3d.com/wp-content/uploads/2010/01/TerrainToolkit.jpg"><img class="alignright size-full wp-image-2248" title="TerrainToolkit" src="http://blogs.unity3d.com/wp-content/uploads/2010/01/TerrainToolkit.jpg" alt="TerrainToolkit" width="640" height="240" /></a></p>
<p>The Terrain Toolkit is an integrated set of tools for the Unity Editor which is designed to streamline and improve the workflow involved in creating realistic terrains for games. The toolkit enables the creation of large scale, realistic and playable game worlds within a very short time span.</p>
<p><span id="more-2246"></span>Unity already has a powerful terrain engine as one of its core features. The Terrain Toolkit expands on this by providing the user with the ability to rapidly create a variety of different landscapes directly within Unity without needing to use third party software. An additional advantage is that landscapes can now be generated dynamically at runtime. This means a Unity game can have a potentially infinite number of levels or landscapes with a negligible impact on the file size.</p>
<p><strong>Integrated terrain creation tools</strong></p>
<p>The Terrain Toolkit provides an intuitive interface within the Unity Editor allowing a Unity artist to simply generate, erode and texture terrain objects. Quick and easy-to-use presets are provided for first time users, while advanced users can tweak low level settings such as rainfall and evaporation to get exactly the result they are after.</p>
<p>Watch the tutorial video to learn more about using the Terrain Toolkit:<br />
<!-- Smart Youtube --><span class="youtube"><object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/YnO9RtarzHE&amp;rel=1&amp;color1=d6d6d6&amp;color2=f0f0f0&amp;border=0&amp;fs=1&amp;hl=en&amp;autoplay=0&amp;showinfo=0&amp;iv_load_policy=3&amp;showsearch=0" /><param name="allowFullScreen" value="true" /><embed wmode="transparent" src="http://www.youtube.com/v/YnO9RtarzHE&amp;rel=1&amp;color1=d6d6d6&amp;color2=f0f0f0&amp;border=0&amp;fs=1&amp;hl=en&amp;autoplay=0&amp;showinfo=0&amp;iv_load_policy=3&amp;showsearch=0" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="355" ></embed><param name="wmode" value="transparent" /></object></span><a href="http://www.youtube.com/watch?v=YnO9RtarzHE"><img src="http://img.youtube.com/vi/YnO9RtarzHE/default.jpg" width="130" height="97" border=0></a></p>
<p><strong>A powerful runtime API</strong></p>
<p>The Terrain Toolkit comes with a powerful API that allows developers to call any of the terrain generation, erosion and texturing scripts at runtime.</p>
<p>This Unity web player shows the Terrain Toolkit API in action: <a href="http://www.sixtimesnothing.com/terraintoolkit/APIExample.html">http://www.sixtimesnothing.com/terraintoolkit/APIExample.html</a></p>
<p><strong>Where to next?</strong></p>
<p>I plan to continue work on the Terrain Toolkit by both making further improvements to existing features, as well as expanding on the feature set to allow even more flexibility in the creation of procedural terrain.</p>
<p>Here are some of the planned features for future versions of the Terrain Toolkit:</p>
<ul>
<li>Texture presets</li>
<li>User defined presets</li>
<li>The ability to apply pre-defined presets through the API</li>
<li>Realtime destructible terrain</li>
<li>The ability to create multiple, maskable terrain ‘layers’</li>
<li>An advanced hydraulic erosion filter based on a shallow water model</li>
<li>Glacial erosion</li>
</ul>
<p><strong>Documentation</strong></p>
<p>Comprehensive documentation for the Terrain Toolkit and the API is included in HTML format. The latest version of the documentation can also be viewed here: <a href="http://www.sixtimesnothing.com/terraintoolkit">http://www.sixtimesnothing.com/terraintoolkit</a></p>
<p><strong>Questions and support</strong></p>
<p>If you have any questions about the Terrain Toolkit, the API, or any suggestions for improvements or new features, please feel free to contact me on the Unity forums (Nekharoth) or through my developer blog: <a href="http://sixtimesnothing.wordpress.com">http://sixtimesnothing.wordpress.com</a></p>
<p><em>Get the <a href="http://unity3d.com/support/resources/unity-extensions/terrain-toolkit">Terrain Toolkit</a> from our Resources section.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.unity3d.com/2010/02/23/summer-of-code-terrain-toolkit-released/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Four years ago today&#8230;</title>
		<link>http://blogs.unity3d.com/2010/01/04/four-years-ago-today/</link>
		<comments>http://blogs.unity3d.com/2010/01/04/four-years-ago-today/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 17:36:54 +0000</pubDate>
		<dc:creator>Aras Pranckevičius</dc:creator>
				<category><![CDATA[Company News and Info]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blogs.unity3d.com/?p=2097</guid>
		<description><![CDATA[&#8230;I took a plane to Copenhagen. Well ok, it all started a bit before: I exchanged some emails with David and Joachim and they invited me for a gamejam in their office. Then one thing led to another, I was young and needed money (oops! wrong topic) and on January 2006 I started working on...]]></description>
			<content:encoded><![CDATA[<p>&#8230;I took a plane to Copenhagen.</p>
<p>Well ok, it all started a bit before: <span id="more-2097"></span><br />
<a href="http://blogs.unity3d.com/wp-content/uploads/2010/01/futureofmiddleware.png"><img class="alignnone size-full wp-image-2099" title="futureofmiddleware" src="http://blogs.unity3d.com/wp-content/uploads/2010/01/futureofmiddleware.png" alt="futureofmiddleware" width="548" height="19" /></a></p>
<p>I exchanged some emails with <a href="http://blogs.unity3d.com/author/david/">David</a> and <a href="http://blogs.unity3d.com/author/joe/">Joachim</a> and they invited me for a <a href="http://unity3d.com/pakimono/">gamejam</a> in their office. Then one thing led to another, I was young and needed money <em>(oops! wrong topic)</em> and on January 2006 I started working on this thing called &#8220;Unity&#8221;.</p>
<p>Unity was at version <a href="http://unity3d.com/unity/whats-new/unity-1.2">1.2.1</a> then. Since then we&#8217;ve released about a dozen new versions, added hundreds (or thousands?) of new features, a handful of new platforms and <a href="http://blogs.unity3d.com/2009/11/13/blast-from-the-past-pt-3-a-growing-company/">have grown a lot</a>.</p>
<p><a href="http://blogs.unity3d.com/wp-content/uploads/2010/01/insanesales.png"><img class="alignright size-full wp-image-2105" title="Insane Sales!" src="http://blogs.unity3d.com/wp-content/uploads/2010/01/insanesales.png" alt="Insane Sales!" width="333" height="72" /></a>Also, we stopped saying &#8220;Sales are INSANE!!!!11&#8243; whenever they exceeded a whopping ten thousand euros per week. <em><span style="color: #808080;">Seriously, that much money in 2006 was a big thing. Our Windows build machine was a single core Celeron with 512MB RAM because that&#8217;s what we could afford!</span></em> Well ok, we&#8217;re still saying &#8220;sales are insane!&#8221; from time to time, just the threshold has gone way up.</p>
<p style="clear: both;"><a href="http://blogs.unity3d.com/wp-content/uploads/2010/01/greatsuccess.png"><img class="alignright size-full wp-image-2119" title="SUCCESS!!!" src="http://blogs.unity3d.com/wp-content/uploads/2010/01/greatsuccess.png" alt="SUCCESS!!!" width="220" height="121" /></a>Occasionally we&#8217;d get excited about strangest things. I think this email is about some car model from ATI that was on front page of <a href="http://blogs.unity3d.com/wp-content/uploads/2010/01/website2006.png">our website in 2006</a>. It&#8217;s beyond me why we&#8217;d put a car on Unity website, but somehow it seemed to make sense at the time.</p>
<p style="clear: both;">It would take too much space to list all the awesome things that happened in those four years. I got to work on some things too, like <a href="http://blogs.unity3d.com/wp-content/uploads/2010/01/200603-firefox.jpg">Windows Web Player</a>, <a href="http://blogs.unity3d.com/wp-content/uploads/2010/01/200702-fastd3d1.png">Direct3D renderer</a>, <a href="http://blogs.unity3d.com/wp-content/uploads/2010/01/200706-lolshadows.png">shadows</a>, <a href="http://blogs.unity3d.com/2009/05/16/blast-from-the-recent-past-unity-25/">editor for Windows</a> and whatnot. But I mostly concentrate on creating trouble, which does not seem to hinder Unity that much. I need to get more efficient!</p>
<p>Seriously though, it has been an amazing ride so far, and I hope it will only become better. Thanks to everyone at Unity Technologies and the community!</p>
<p>Rock on!</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.unity3d.com/2010/01/04/four-years-ago-today/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Fridays Are For Fun!</title>
		<link>http://blogs.unity3d.com/2009/11/18/fridays-are-for-fun/</link>
		<comments>http://blogs.unity3d.com/2009/11/18/fridays-are-for-fun/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 09:42:15 +0000</pubDate>
		<dc:creator>Aras Pranckevičius</dc:creator>
				<category><![CDATA[Company News and Info]]></category>

		<guid isPermaLink="false">http://blogs.unity3d.com/?p=1852</guid>
		<description><![CDATA[At end of April 2009, Joachim sent this out to all developers at Unity: We want to try one more thing&#8230; On Friday work on something cool. I think there are a lot of low hanging fruits in Unity where somebody with drive can just do something cool that pushes us forward. Things that are...]]></description>
			<content:encoded><![CDATA[<p>At end of April 2009, Joachim sent this out to all developers at Unity:</p>
<blockquote><p>We want to try one more thing&#8230; On Friday work on something cool.</p>
<p>I think there are a lot of low hanging fruits in Unity where somebody with drive can just do something cool that pushes us forward. Things that are hard to put in words, but just make sense when you see it done.</p>
<p>So every Friday, developers can work on something cool, something they have been craving to do for a long time. A feature, a demo, a tutorial, a video tutorial, docs, cleaning the toilet, something on the website. Whatever. Be creative, push the envelope.</p></blockquote>
<p><span id="more-1852"></span>In other words, we started to work on &#8220;anything cool&#8221; on Fridays. This was dubbed as FAFF (Fridays Are For Fun).</p>
<p>Boy, what a positive effect on team morale that was!</p>
<p>It also resulted in some FAFF work being polished &amp; promoted into official releases already. Things like:</p>
<ul>
<li><a href="http://unity3d.com/support/documentation/Components/animeditor-AnimationEvents.html">Animation Events</a> in Unity 2.6 animation editor</li>
<li>Display <a href="http://feedback.unity3d.com/pages/15792-unity/suggestions/163534">realtime brush preview</a> in terrain editing tools</li>
<li>Timeline Charts for <a href="http://unity3d.com/support/documentation/Manual/Profiler.html">Unity 2.6 profiler</a></li>
<li><a href="http://feedback.unity3d.com/pages/15792-unity/suggestions/163793">Custom Icons</a> for standalone game builds</li>
<li><a href="http://unity3d.com/support/resources/unity-extensions/head-look-controller">Head Look Controller</a> sample project</li>
<li>Precise raycast-based snapping in Unity 2.6</li>
</ul>
<p>&#8230;all started out as Friday projects!</p>
<p>Developers have experimented with lots of other stuff on Fridays. Some of them were just playing around or learning Unity better. Some Fridays were for evaluating various middleware packages, implementing some features or doing some fancy R&amp;D. Some of the projects were an interesting kind of &#8220;fun&#8221;. Like improving internal build farm setup, a system for better tracking of crash reports, improving the website, or other similar things that often involve Perl scripts. Well, eveyone has his own kind of fun <img src='http://blogs.unity3d.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>So yeah. On Fridays, we just ignore the schedule and work on something cool. Something that pushes our own tech &#8211; something that we can&#8217;t defend from a business standpoint but that&#8217;s just too great to not get done.  If it rocks, we&#8217;ll ship it. Because, at the end of the day &#8211; who knows where the next killer idea will come from.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.unity3d.com/2009/11/18/fridays-are-for-fun/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Summer of Code: Progress of Terrain Erosion Tools</title>
		<link>http://blogs.unity3d.com/2009/08/23/summer-of-code-progress-of-terrain-erosion-tools/</link>
		<comments>http://blogs.unity3d.com/2009/08/23/summer-of-code-progress-of-terrain-erosion-tools/#comments</comments>
		<pubDate>Sun, 23 Aug 2009 14:51:37 +0000</pubDate>
		<dc:creator>Aras Pranckevičius</dc:creator>
				<category><![CDATA[Community News and Info]]></category>
		<category><![CDATA[Company News and Info]]></category>
		<category><![CDATA[Events]]></category>

		<guid isPermaLink="false">http://blogs.unity3d.com/?p=1263</guid>
		<description><![CDATA[This blog post is written by Sándor Moldán who is working on a set of Terrain Erosion tools for Unity. The project is one of four selected projects that were selected for the Unity Summer of Code. The objective of this Unity Summer of Code project was to develop a toolset for the Unity Editor...]]></description>
			<content:encoded><![CDATA[<p><em>This blog post is written by Sándor Moldán who is working on a set of Terrain Erosion tools for Unity. The project is one of <a href="http://blogs.unity3d.com/2009/07/22/unity-summer-of-code-takes-off/">four selected projects</a> that were selected for the <a href="http://unity3d.com/usc/">Unity Summer of Code</a>.</em></p>
<p>The objective of this Unity Summer of Code project was to develop a toolset for the Unity Editor which would streamline and improve the workflow involved in creating terrains for games.<br />
<a href="http://blogs.unity3d.com/wp-content/uploads/2009/08/Terrain_Screenshot.jpg"><img class="alignnone size-full wp-image-1264" title="Terrain Erosion Tools screenshot" src="http://blogs.unity3d.com/wp-content/uploads/2009/08/Terrain_Screenshot.jpg" alt="Terrain Erosion Tools screenshot" width="640" height="240" /></a></p>
<p><span id="more-1263"></span>While there are currently a number of third party tools that can already produce high quality terrains, I felt that they lacked two vital qualities. Besides the impact of the additional cost of these tools – particularly to indie developers, when using these tools it is left to the artist to develop an effective workflow for getting height and texture maps out of their proprietary software and into Unity. This can be a somewhat painful process. Secondly and more importantly, it is impossible to leverage the power of the tools to procedurally generate landscapes at runtime. My aim was to overcome these constraints by integrating terrain generation tools directly into the Unity engine and editor.</p>
<p>The toolset I am developing is divided into three areas – terrain generation, erosion and texturing. So far there are 5 different erosion filters – thermal, tidal, wind and two types of hydraulic erosion, 2 ‘generators’ that use Voronoi and cloud fractal algorithms to create base terrain, a couple of useful tools that allow the user to smooth or normalise the terrain and finally a procedural terrain texturing tool.</p>
<p>All ten of these features will be provided both as filters which can be applied in the Unity Editor and as fully documented API functions which will allow users to generate terrain and apply filters at runtime through their own scripts. Additionally, thermal, fast-hydraulic and tidal erosion filters can also be applied directly to the terrain object using brushes in the editor.<br />
<a href="http://blogs.unity3d.com/wp-content/uploads/2009/08/Terrain_UI_Screenshot.jpg"><img class="alignnone size-full wp-image-1265" title="Terrain Erosion Tools UI" src="http://blogs.unity3d.com/wp-content/uploads/2009/08/Terrain_UI_Screenshot.jpg" alt="Terrain Erosion Tools UI" width="640" height="320" /></a></p>
<p><strong>Where it’s up to, what still needs to be done</strong></p>
<p>I feel that the project has progressed well over the last five or so weeks. There have certainly been some obstacles and not everything has gone my way, but with just over a week remaining I am on track towards delivering at least 16 of the 19 features that I originally scoped for the project, plus two completely new ones. Given that my aim was to deliver a minimum of 12 of the scoped features within the Unity Summer of Code timeline, I’m quite happy with the result.</p>
<p>Over the next week my main aim is to tidy up the documentation for this project, which I believe is vital in allowing Unity artists and developers to get the most out of these tools. I will also focus on cleaning up my code and optimising it where possible and finally I will continue working away on the remaining features – namely a few UI tweaks, yet a third different approach to hydraulic erosion, and glacial erosion.</p>
<p><strong>What went well</strong></p>
<p>I started the project with a fairly limited knowledge about creating properly integrated custom tools for the Unity Editor and had only given the Editor GUI documentation a cursory glance. I found that despite a few minor hurdles, I was able to quite easily create a useful and intuitive interface for my tools. I was also pretty happy with some of the optimisations I was able made to my erosion code. Being able to run 50 thermal erosion iterations on a 512 x 512 terrain object in barely more than 6 seconds totally exceeded my wildest expectations.</p>
<p>Also, after many unsuccessful attempts to get Unity’s undo feature to work with my code, one of the Unity guys, Rune, was kind enough to explain it to us – and in typical Unity style, it turned out to be much simpler that I had thought it would be.</p>
<p>Even though I had originally considered undo as a ‘nice to have’ feature, I quickly realised that it was really an imperative. Getting the best results from these tools can require a bit of trial and error, and allowing users to run a filter, undo it, tweak a few settings and run it again without completely ruining their terrain object in the process is vital in making this project a practical solution for Unity artists and developers.</p>
<p><strong>What didn’t go so well</strong></p>
<p>While I consider my scripting skills in JavaScript and C# to be reasonably good, I have to admit that mathematics is not really my strong point. Some of the equations I used in my tools, such as Voronoi diagrams and the Diamond-Square algorithm were fairly easy to implement in code – but for the vast majority of my tools I initially approached the algorithms logically rather than algorithmically.</p>
<p>For the most part this worked well and produced good results. However, when I started looking for a more physically correct approach to erosion caused by fluid mediums – namely water and ice – I realised that the complexity of the mathematics involved in computational fluid dynamics, such as Shallow Water Models, Navier-Stokes equations and so on, was far beyond my level of understanding and well beyond my capacity to learn in such a short period. This was rather disappointing, as it has meant that I have not yet found an effective solution for glacial erosion.</p>
<p>That said, there is still a lot more that I want to achieve with this toolset. After I deliver my project at the end of the Unity Summer of Code, I fully intend to revisit some of these prohibitively complex features once I have the time to do all the learning and research that will be required to get them to work the way that I want them to.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.unity3d.com/2009/08/23/summer-of-code-progress-of-terrain-erosion-tools/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Presentations from Assembly 2009 demo party</title>
		<link>http://blogs.unity3d.com/2009/08/20/assembly-2009-presentations/</link>
		<comments>http://blogs.unity3d.com/2009/08/20/assembly-2009-presentations/#comments</comments>
		<pubDate>Thu, 20 Aug 2009 18:51:19 +0000</pubDate>
		<dc:creator>Aras Pranckevičius</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blogs.unity3d.com/?p=1225</guid>
		<description><![CDATA[We have a ton of people at Unity who have been or are involved in the demoscene. Assembly is one of the largest demoscene parties, and this year we were sponsoring the event, sent in some folks there and had a couple of seminar presentations. Our presentations were not directly Unity related, but still might...]]></description>
			<content:encoded><![CDATA[<p>We have <em>a ton</em> of people at Unity who have been or are involved in the <a href="http://en.wikipedia.org/wiki/Demoscene">demoscene</a>. <a href="http://en.wikipedia.org/wiki/Assembly_(demo_party)">Assembly</a> is one of the largest demoscene parties, and <a href="http://www.assembly.org/summer09/?set_language=en">this year</a> we were sponsoring the event, sent in some folks there and had a couple of seminar presentations. Our presentations were not directly Unity related, but still might be interesting for some of you.</p>
<p><span id="more-1225"></span><br />
I talked about developing graphics technology for small games (<a href='http://blogs.unity3d.com/wp-content/uploads/2009/08/Assembly09-Graphics-Tech-for-Small-Games.pdf'>PDF slides</a>). Mostly on hardware statistics, GPU features, testing and stability.<br />
<object width='504' height='284'><param name='allowfullscreen' value='true' /><param name='allowscriptaccess' value='always' /><param name='movie' value='http://vimeo.com/moogaloop.swf?clip_id=6128236&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1' /><embed src='http://vimeo.com/moogaloop.swf?clip_id=6128236&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1' type='application/x-shockwave-flash' allowfullscreen='true' allowscriptaccess='always' width='504' height='284'></embed></object></p>
<p>ReJ talked about low level iPhone (pre-3GS) rendering details (<a href='http://blogs.unity3d.com/wp-content/uploads/2009/08/Assembly09-iPhone-Learning-GPU-from-Driver-Code.pdf'>PDF slides</a>). On inner workings of iPhone&#8217;s GPU, OpenGL ES drivers, command buffers, VFP assembly and so on. Some awesome tech stuff in there!<br />
<object width='504' height='284'><param name='allowfullscreen' value='true' /><param name='allowscriptaccess' value='always' /><param name='movie' value='http://vimeo.com/moogaloop.swf?clip_id=6064955&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1' /><embed src='http://vimeo.com/moogaloop.swf?clip_id=6064955&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1' type='application/x-shockwave-flash' allowfullscreen='true' allowscriptaccess='always' width='504' height='284'></embed></object></p>
<p>If you&#8217;re going to watch some demos from Assembly 2009, make sure to see:</p>
<ul>
<li><a href="http://capped.tv/cncd_orange_fairlight-frameranger">Frameranger</a> (1st place demo). Imagine that on a big screen and a good sound system!</li>
<li><a href="http://capped.tv/united_force_digital_dynamite-the_golden_path">The Golden Path</a> (3rd place demo) &#8211; for something fresh.</li>
<li><a href="http://capped.tv/youth_uprising_mlat_design_out-muon_baryon">Muon Baryon</a> (1st place 4 kilobyte intro) &#8211; that&#8217;s what kids do with sphere marching on the GPU these days. Everything in 4 kilobytes!</li>
</ul>
<p>&#8230;see you at <a href="http://en.wikipedia.org/wiki/Breakpoint_(demo_party)">Breakpoint</a> next year? <img src='http://blogs.unity3d.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.unity3d.com/2009/08/20/assembly-2009-presentations/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Fixed function T&amp;L in vertex shaders: implemented</title>
		<link>http://blogs.unity3d.com/2009/06/10/fixed-function-tl-in-vertex-shaders-implemented/</link>
		<comments>http://blogs.unity3d.com/2009/06/10/fixed-function-tl-in-vertex-shaders-implemented/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 18:56:37 +0000</pubDate>
		<dc:creator>Aras Pranckevičius</dc:creator>
				<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blogs.unity3d.com/?p=826</guid>
		<description><![CDATA[Unity roadmap blog post said: Currently Unity mixes the fixed function pipeline for vertex lit objects and vertex shaders for pixel lit lights. On Direct3D this creates some rendering artifacts on very close or self intersecting surfaces. We want to end this by implementing a full fixed function emulator in vertex shaders. You won’t have...]]></description>
			<content:encoded><![CDATA[<p>Unity <a href="http://blogs.unity3d.com/2009/04/10/unity-roadmap/">roadmap blog post</a> said:</p>
<blockquote><p>Currently Unity mixes the fixed function pipeline for vertex lit objects and vertex shaders for pixel lit lights. On Direct3D this creates some rendering artifacts on very close or self intersecting surfaces. We want to end this by implementing a full fixed function emulator in vertex shaders. You won’t have to do anything, it will just work!
</p></blockquote>
<p>Well, the good news is that we have done it, and it is definitely coming in Unity 2.6!</p>
<p>It is funny, because the problem seems like a simple one: <em>&#8220;there are double-lighting artifacts on close surfaces&#8221;</em>. The solution, however, is <em>&#8220;we need to implement whole fixed function pipeline manually&#8221;</em>, which involves combining shader assembly fragments, doing register allocations, packing vertex pipeline state into bits and other low level hacking.</p>
<p>In other words, it required quite a bit of thinking and implementation effort, so I decided to write up a technical report on how we solved it. If you&#8217;re a graphics programmer or love programmer speak or just have nothing better to do: <a href="http://aras-p.info/texts/VertexShaderTnL.html"><strong>here&#8217;s the report</strong></a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.unity3d.com/2009/06/10/fixed-function-tl-in-vertex-shaders-implemented/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Blast from the recent past &#8211; Unity 2.5</title>
		<link>http://blogs.unity3d.com/2009/05/16/blast-from-the-recent-past-unity-25/</link>
		<comments>http://blogs.unity3d.com/2009/05/16/blast-from-the-recent-past-unity-25/#comments</comments>
		<pubDate>Sat, 16 May 2009 05:40:33 +0000</pubDate>
		<dc:creator>Aras Pranckevičius</dc:creator>
				<category><![CDATA[Unity Products and Services]]></category>

		<guid isPermaLink="false">http://blogs.unity3d.com/?p=753</guid>
		<description><![CDATA[For some reason I was browsing through old emails and found some old development screenshots of Unity 2.5. Unity 2.5 was the first version of the editor running on Windows and eventually was released in March 2009. Some development of it started at end of 2007, just after Unity 2.0 was released. First there was...]]></description>
			<content:encoded><![CDATA[<p>For some reason I was browsing through old emails and found some old development screenshots of Unity 2.5.</p>
<p>Unity 2.5 was the first version of the editor running on Windows and eventually was released in March 2009. Some development of it started at end of 2007, just after Unity 2.0 was released. First there was some serious code shuffling, converting from Objective C into C++, refactoring into platform independent interfaces and similar highly invisible stuff.</p>
<p>Here&#8217;s the first Unity running on Windows screenshot I could find (this is February 2008): <span id="more-753"></span><br />
<a href="http://blogs.unity3d.com/wp-content/uploads/2009/05/25blast-20080205.png"><img class="alignnone size-medium wp-image-754" title="Unity on Windows!" src="http://blogs.unity3d.com/wp-content/uploads/2009/05/25blast-20080205-300x211.png" alt="Unity on Windows!" width="300" height="211" /></a></p>
<p>This was the version dubbed &#8220;Can Haz Menus&#8221;. However, a couple of days later it was &#8220;CanHazGUI&#8221; already:<br />
<a href="http://blogs.unity3d.com/wp-content/uploads/2009/05/25blast-20080207.png"><img class="alignnone size-medium wp-image-755" title="Unity Windows GUI" src="http://blogs.unity3d.com/wp-content/uploads/2009/05/25blast-20080207-251x300.png" alt="Unity Windows GUI" width="251" height="300" /></a></p>
<p>That&#8217;s true, whole editor at that time only had a view into the Project, and you could not really do anything with it, except to use the scrollbar. Or maybe collapse and expand the folders &#8211; I forget. Things were progressing <em>really</em> fast though. About a week later I sent this status report mail:</p>
<blockquote><p>Working on Windows editor. Not much to say, so I&#8217;ll attach a cute picture instead. It&#8217;s getting there.</p></blockquote>
<p><a href="http://blogs.unity3d.com/wp-content/uploads/2009/05/25blast-20080213.png"><img class="alignnone size-medium wp-image-756" title="Cute Picture" src="http://blogs.unity3d.com/wp-content/uploads/2009/05/25blast-20080213-300x201.png" alt="Cute Picture" width="300" height="201" /></a><br />
<em>(Back then I was the only person with a working 2.5 for Windows build, and I did work separately from the main office. Occasionally I had to send screenshots as an argument for getting my salary!)</em></p>
<p>&#8230;and then came work for <a href="http://unity3d.com/unity/whats-new/unity-2.1">Unity 2.1</a>, <a href="http://unity3d.com/unity/features/iphone-publishing">Unity iPhone</a>, <a href="http://www.fusionfall.com/">Fusion Fall</a> and whatnot. Work on 2.5 was progressing, but at a bit slower pace. And of course, &#8220;getting something on screen&#8221; is <em>much</em> less work than &#8220;getting it to actually work&#8221;.</p>
<p>Here&#8217;s how the Windows editor looked in September 2008:<br />
<a href="http://blogs.unity3d.com/wp-content/uploads/2009/05/25blast-20080902.png"><img class="alignnone size-medium wp-image-758" title="Scene View" src="http://blogs.unity3d.com/wp-content/uploads/2009/05/25blast-20080902-300x234.png" alt="Scene View" width="300" height="234" /></a></p>
<p>This was approaching final look of 2.5 already. Of course, occasionally we&#8217;d run into funny situations where it did not quite work. For example, at that time if you dropped a refractive glass shader into scene, it would turn the editor into this:<br />
<a href="http://blogs.unity3d.com/wp-content/uploads/2009/05/25blast-20080918.png"><img class="alignnone size-medium wp-image-759" title="Funny Bug" src="http://blogs.unity3d.com/wp-content/uploads/2009/05/25blast-20080918-300x220.png" alt="Funny Bug" width="300" height="220" /></a></p>
<p>It took another half a year to add all new &amp; missing features, fix a ton of large &amp; small issues until it got to a real release:<br />
<a href="http://blogs.unity3d.com/wp-content/uploads/2009/05/25blast-20090318.jpg"><img class="alignnone size-medium wp-image-760" title="2.5" src="http://blogs.unity3d.com/wp-content/uploads/2009/05/25blast-20090318-300x222.jpg" alt="2.5" width="300" height="222" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.unity3d.com/2009/05/16/blast-from-the-recent-past-unity-25/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Hardware of the casual gamer, launched</title>
		<link>http://blogs.unity3d.com/2008/08/28/hardware-of-the-casual-gamer-launched/</link>
		<comments>http://blogs.unity3d.com/2008/08/28/hardware-of-the-casual-gamer-launched/#comments</comments>
		<pubDate>Thu, 28 Aug 2008 08:49:25 +0000</pubDate>
		<dc:creator>Aras Pranckevičius</dc:creator>
				<category><![CDATA[Demos, Tutorials and Tips]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blogs.unity3d.com/?p=91</guid>
		<description><![CDATA[Almost a month ago I said we&#8217;re preparing reports of Unity Web Player hardware statistics. Well, here they are: unity3d.com/webplayer/hwstats Operating system versions, desktop resolutions, graphics driver versions, shader models, memory sizes and some more. All broken down by quarter so some sort of &#8220;trends&#8221; can be seen (sure, changes can be caused by general...]]></description>
			<content:encoded><![CDATA[<p><a href="http://blogs.unity3d.com/2008/08/01/hardware-of-the-casual-gamer/">Almost a month ago I said</a> we&#8217;re preparing reports of Unity Web Player hardware statistics.</p>
<p>Well, here they are: <a href="http://unity3d.com/webplayer/hwstats/"><strong>unity3d.com/webplayer/hwstats</strong></a></p>
<p>Operating system versions, desktop resolutions, graphics driver versions, shader models, memory sizes and some more. All broken down by quarter so some sort of &#8220;trends&#8221; can be seen (sure, changes can be caused by general hardware change or simply different people groups playing different games).</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.unity3d.com/2008/08/28/hardware-of-the-casual-gamer-launched/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Hardware of the casual gamer</title>
		<link>http://blogs.unity3d.com/2008/08/01/hardware-of-the-casual-gamer/</link>
		<comments>http://blogs.unity3d.com/2008/08/01/hardware-of-the-casual-gamer/#comments</comments>
		<pubDate>Fri, 01 Aug 2008 08:35:20 +0000</pubDate>
		<dc:creator>Aras Pranckevičius</dc:creator>
				<category><![CDATA[Demos, Tutorials and Tips]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blogs.unity3d.com/?p=78</guid>
		<description><![CDATA[Pretty much everyone knows Valve&#8217;s hardware survey &#8211; it&#8217;s a very valuable resource that shows what hardware the typical &#8220;hardcore PC gamer&#8221; has (that is, gamers that play Valve&#8217;s games). However, the &#8220;casual gamer&#8221;, which is what Unity games are mostly targeted at, probably has slightly different hardware. &#8220;Slightly&#8221; being a very relative term of...]]></description>
			<content:encoded><![CDATA[<p>Pretty much everyone knows <a href="http://www.steampowered.com/status/survey.html">Valve&#8217;s hardware survey</a> &#8211; it&#8217;s a very valuable resource that shows what hardware the typical &#8220;hardcore PC gamer&#8221; has (that is, gamers that play Valve&#8217;s games).</p>
<p>However, the &#8220;casual gamer&#8221;, which is what Unity games are mostly targeted at, probably has <em>slightly</em> different hardware. &#8220;Slightly&#8221; being a very relative term of course.</p>
<p>Lo and behold &#8211; we have a glimpse into that data.<br />
<span id="more-78"></span><br />
How? First time the Unity Web Player is installed, it submits anonymous hardware details (details in the <a href="http://unity3d.com/unity/webplayer-end-user-license-2.x">EULA</a>). This happens only once, and contains no personally identifiable information. It&#8217;s much like visitor statistics trackers on the websites that gather your OS, browser information and whatnot.</p>
<p>We still haven&#8217;t prepared nicely laid out, colored and formatted reports into that data that we can share publicly like Valve, but we&#8217;re working on that. So in the meantime I&#8217;ll share some images without fancy graphs or colors, bear with me.</p>
<p>Remember, all this data is from people who installed Unity Web Player (most likely because they wanted to play some Unity content on the web). Hardware of standalone game players might be different, and hardware of <em>your game&#8217;s</em> players might be different as well. The data set is well over a million samples at the moment.</p>
<p>Enough talk, let&#8217;s show some pictures.</p>
<p><strong>What operating systems do we have?</strong></p>
<p><a href="http://blogs.unity3d.com/wp-content/uploads/2008/08/hwstats-os.png"><img class="alignnone size-full wp-image-86" title="Operating systems" src="http://blogs.unity3d.com/wp-content/uploads/2008/08/hwstats-os.png" alt="" width="271" height="70" /></a><br />
This one should be easy to understand.</p>
<p><a href="http://blogs.unity3d.com/wp-content/uploads/2008/08/hwstats-windows.png"><img class="alignnone size-full wp-image-89" title="Windows Versions" src="http://blogs.unity3d.com/wp-content/uploads/2008/08/hwstats-windows.png" alt="" width="311" height="99" /></a><br />
What Windows versions are out there?</p>
<p><a href="http://blogs.unity3d.com/wp-content/uploads/2008/08/hwstats-osx.png"><img class="alignnone size-full wp-image-87" title="OS X versions" src="http://blogs.unity3d.com/wp-content/uploads/2008/08/hwstats-osx.png" alt="" width="272" height="83" /></a><br />
We should know OS X versions as well, right? Hey, Leopard already took over Tiger!</p>
<p><a href="http://blogs.unity3d.com/wp-content/uploads/2008/08/hwstats-64bit.png"><img class="alignnone size-full wp-image-80" title="32 vs 64 bit Windows" src="http://blogs.unity3d.com/wp-content/uploads/2008/08/hwstats-64bit.png" alt="" width="370" height="71" /></a><br />
Hmm, looks like 64 bit Windows haven&#8217;t <em>really</em> taken off yet&#8230;</p>
<p><strong>Enough about OS, what about CPU?</strong></p>
<p><a href="http://blogs.unity3d.com/wp-content/uploads/2008/08/hwstats-cpu.png"><img class="alignnone size-full wp-image-82" title="CPU Vendors" src="http://blogs.unity3d.com/wp-content/uploads/2008/08/hwstats-cpu.png" alt="" width="289" height="128" /></a><br />
Poor Transmeta&#8230; <img src='http://blogs.unity3d.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  (for the record, that&#8217;s 43 Transmeta CPUs)</p>
<p><a href="http://blogs.unity3d.com/wp-content/uploads/2008/08/hwstats-cores1.png"><img class="alignnone size-full wp-image-90" title="CPU Cores" src="http://blogs.unity3d.com/wp-content/uploads/2008/08/hwstats-cores1.png" alt="" width="245" height="114" /></a><br />
Multicore CPUs are taking off (well, at least dual core ones).</p>
<p><strong>Graphics card?</strong></p>
<p><a href="http://blogs.unity3d.com/wp-content/uploads/2008/08/hwstats-shader.png"><img class="alignnone size-full wp-image-88" title="Shader versions" src="http://blogs.unity3d.com/wp-content/uploads/2008/08/hwstats-shader.png" alt="" width="233" height="235" /></a><br />
<em>Capabilities</em> of the graphics cards.</p>
<p>The capabilities are not as bad (certainly better than I expected).  I mean, about 70% of them support shader model 2.0 or higher!</p>
<p>What <em>is</em> is troubling is the 3.7% that run in OpenGL 1.1 software mode&#8230; That means they <em>don&#8217;t have</em> graphics drivers installed or have disabled hardware acceleration. This is just crazy, I mean, without the drivers, even dragging windows around is <em>horribly slow</em>&#8230; how people even <em>use</em> the computer this way?</p>
<p>Another interesting point is that DirectX 8.0 level hardware (GeForce 3/4Ti) is pretty much dead. I guess that&#8217;s because there never was an entry-level graphics card from that range (before there was GeForce 4MX, which is DX7 level, and it was followed by GeForce FX 5200, which is DX9 level).</p>
<p>However, the above was <em>technical capabilities</em> of the graphics cards. Let&#8217;s take a look at <em>which</em> cards are out there:</p>
<p><a href="http://blogs.unity3d.com/wp-content/uploads/2008/08/hwstats-gfx.png"><img class="alignnone size-full wp-image-84" title="Graphics cards" src="http://blogs.unity3d.com/wp-content/uploads/2008/08/hwstats-gfx.png" alt="" width="350" height="445" /></a></p>
<p>Uh-oh. Can you say &#8220;low end&#8221;? The first decent card here is GeForce 8600, <em>15th</em> on the list. Everything above &#8211; slow, slow, slow. Some <em>horribly slow</em>. Well, that&#8217;s casual gamer&#8230;</p>
<p>Here&#8217;s a rough performance indicator, graphics card fillrate in gigapixels/second:</p>
<p><a href="http://blogs.unity3d.com/wp-content/uploads/2008/08/hwstats-gfxfill.png"><img class="alignnone size-full wp-image-85" title="Graphics card fillrate" src="http://blogs.unity3d.com/wp-content/uploads/2008/08/hwstats-gfxfill.png" alt="" width="172" height="248" /></a></p>
<p>For the record, fillrate of GeForce 8600 is 4.3 GP/s, Radeon X1600 is 2 GP/s, Radeon HD 2600 is 2.8 GP/s, and Intel 945 (GMA 950) is 1.6 GP/s. The difference from high-end to low-end in video memory bandwidth is even larger.</p>
<p>On a somewhat unrelated note, here&#8217;s DirectX 10 card distribution:</p>
<p><a href="http://blogs.unity3d.com/wp-content/uploads/2008/08/hwstats-dx10.png"><img class="alignnone size-full wp-image-83" title="DX10 distribution" src="http://blogs.unity3d.com/wp-content/uploads/2008/08/hwstats-dx10.png" alt="" width="520" height="113" /></a></p>
<p>DirectX 10 can only be used starting with Windows Vista, <em>and</em> on DX10 capable graphics card. So that&#8217;s 2.6% of the Unity web game players &#8211; still not a <em>very</em> significant amount.</p>
<p><strong>In conclusion</strong></p>
<p>So here was the glimpse. We&#8217;ll prepare more and nicer reports into the hardware data sometime soon. Stay tuned!</p>
<p><strong>Edit</strong>: it&#8217;s live &#8211; <a href="http://unity3d.com/webplayer/hwstats/">unity3d.com/webplayer/hwstats</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.unity3d.com/2008/08/01/hardware-of-the-casual-gamer/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>Terrain lighting &amp; shadows, and the road towards it</title>
		<link>http://blogs.unity3d.com/2008/04/14/terrain-lighting-shadows-and-the-road-towards-it/</link>
		<comments>http://blogs.unity3d.com/2008/04/14/terrain-lighting-shadows-and-the-road-towards-it/#comments</comments>
		<pubDate>Mon, 14 Apr 2008 08:01:33 +0000</pubDate>
		<dc:creator>Aras Pranckevičius</dc:creator>
				<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blogs.unity3d.com/2008/04/14/terrain-lighting-shadows-and-the-road-towards-it/</guid>
		<description><![CDATA[People have been asking: why built-in shadows don&#8217;t work on Unity&#8217;s terrain? (here, here, &#8230;) Yes, right now (Unity 2.0.2) they don&#8217;t. Why &#8211; because we didn&#8217;t have time to make them work yet. Both terrain and built-in shadows are new features in Unity 2.0, and those two don&#8217;t happen to just work together. Here&#8217;s...]]></description>
			<content:encoded><![CDATA[<p>People have been asking: why built-in shadows don&#8217;t work on Unity&#8217;s terrain? (<a href="http://blogs.unity3d.com/2008/04/10/sliced-bread-is-overrated/#comment-113">here</a>, <a href="http://forum.unity3d.com/viewtopic.php?t=9507&#038;highlight=shadow+terrain">here</a>, &#8230;) Yes, <em>right now</em> (Unity 2.0.2) they don&#8217;t. Why &#8211; because we didn&#8217;t have time to make them work yet. Both terrain and built-in shadows are new features in Unity 2.0, and those two don&#8217;t happen to <em>just work</em> together.</p>
<p>Here&#8217;s a glimpse into what is needed to get it working.<span id="more-70"></span></p>
<p><em>The Plan</em>, straight from our internal planning wiki, with some explanations added:</p>
<p><strong>o)</strong> Convert all terrain code to use <a href="http://blogs.unity3d.com/2007/12/06/intermediate-rendering-or-what-goes-into-a-feature/">Intermediate Mode Render Calls</a>. This makes all the points below <em>possible</em>, and makes things like Projectors or wireframe terrain rendering in scene view <em>pretty much just work</em>.</p>
<p><strong>o)</strong> Update terrain shaders for proper rendering order and soft vegetation. Expand ShaderLab so that a shader pass can indicate it should only be executed when Soft Vegetation is on.</p>
<p><strong>o)</strong> Proper vertex lights on terrain, implemented in a vertex shader. Currently terrain handles up to four directional lights; we need to expand it to handle point lights as well. <em>I think</em> we&#8217;ll treat spot lights (when in vertex lit mode) as point lights; as calculating multiple spot lights in a vertex shader is next to impossible because of instruction count limits. Spotlights are not very useful in vertex lighting mode, right?</p>
<p><strong>o)</strong> Implemented pixel lit shaders for terrain. This will get light cookies, per-pixel lit terrain, and ability for terrain to receive shadows.</p>
<p><strong>o)</strong> Add option <em>somewhere</em> for pixel or vertex lit terrain (defaults to vertex lit).</p>
<p><strong>o)</strong> Proper vertex lights on trees. Very similar to &#8220;vertex lights on terrain&#8221; point above.</p>
<p><strong>o)</strong> Make tree shaders able to cast shadows. Because trees are scaled &#038; animated in a vertex shader, the shadow-casting shader needs to apply the same animation as well.</p>
<p><strong>o)</strong> Make Projectors not affect grass / trees. How? We&#8217;ll expand ShaderLab so a any shader can say &#8220;no Projectors on me, thanks&#8221;, and modify grass &#038; tree shaders to do that.</p>
<p><strong>o)</strong> Make projectors <em>not</em> affect terrain when game content is built with Unity 2.0. This is web player backwards compatibility &#8211; there <em>are</em> Unity games out there that use projectors and terrains, and they should continue functioning exactly like they did before. So Projectors <em>should not</em> affect terrain in this case.</p>
<p><strong>o)</strong> Make tree shadows not <del datetime="2008-04-14T07:55:16+00:00">s*ck</del><ins datetime="2008-04-14T07:55:16+00:00">look bad</ins> when they are squashed for billboarding. Trees are squashed into a planar shape when they approach billboards; this is to make the mesh-to-billboard transition less noticeable. However, this makes shadows from those trees look <em>very wrong</em>. Not sure how to handle this; <em>I think</em> we&#8217;ll just stop casting shadows when trees are starting to squash.</p>
<p><strong>o)</strong> Redo Lightmapped terrain shaders:
<ul>
<li>Use existing shaders for game content built with Unity 2.0. Again, existing web player games should work like they did before! For reference, in Unity 2.0.2 lightmapped terrain was not affected by <em>any lights at all</em>.</li>
<li>Make new set of terrain shaders that follows the convention of other <a href="http://unity3d.com/support/documentation/Components/shader-LightmapFamily.html">Lightmapped shaders</a>: lightmap, plus additional lights on top. Whoa, hey, we need <em>two new sets</em> of those shaders: for vertex-lit terrain and for pixel-lit terrain!</li>
</ul>
<p><strong>o)</strong> Optimize the bejesus out of rendering internals. Why &#8211; because the old terrain rendering code was like this:</p>
<ol>
<li>Figure out which parts of terrain and vegetation are visible.</li>
<li>Set terrain shader.</li>
<li>For each terrain chunk: draw it&#8217;s mesh!</li>
<li>Set tree shader.</li>
<li>For each tree: draw it&#8217;s mesh!</li>
<li>&#8230;similar for billboarded trees, grass, and so on.</li>
</ol>
<p>This is all simple &#038; nice. Of course this was <em>exactly</em> the problem why shadows, projectors and such didn&#8217;t work on terrain &#8211; everything was <em>just rendered</em> immediately. Now, the new terrain code just submits any visible parts of terrain as <a href="http://blogs.unity3d.com/2007/12/06/intermediate-rendering-or-what-goes-into-a-feature/">Intermediate Renderers</a>, and the rendering code <em>figures the rest out</em>&#8230; But that means it&#8217;s going through generic rendering &#8220;pipeline&#8221;, that has to figure out lighting, sort out objects, set shaders and their parameters, etc. The major overhead in switching to this &#8220;proper rendering&#8221; is the lost ability to do this:</p>
<ol>
<li>Set the shader.</li>
<li>Draw <em>lots and lots</em> of objects with it.</li>
</ol>
<p>The rendering code in Unity does sort objects by shader, and does <em>ultimately</em> figure out that they are using same shader, possibly same set of textures, even possibly same set of lights and same set of material parameters &#8211; but some time is spent <em>just figuring out that nothing actually changed between the objects</em>.</p>
<p>Well, the upside is that optimizing rendering internals makes <em>everything else</em> run somewhat faster as well!</p>
<p><em>(I am here right now&#8230; the points above are done, the points below are on the list)</em></p>
<p><strong>o)</strong> Make hills/trees outside of view be able to cast shadows <em>(how?)</em></p>
<p><strong>o)</strong> Expand shaders of detail meshes so they can cast shadows.</p>
<p><strong>o)</strong> Optimize terrain &#038; tree vertex lit shaders. Right now they process four vertex lights, where each can be directional or point light. This is noticeably slower than <em>old</em> shaders, that only supported directional lights (point lights need more calculations). We need to write multiple combinations of those shaders, specialized for specific situations (&#8220;one directional light&#8221;, &#8220;two direcitonal lights&#8221;, &#8220;two arbitrary lights&#8221;, and so on).</p>
<p><strong>o)</strong> Add option somewhere for terrain to <em>not</em> cast shadows.</p>
<p><strong>o)</strong> Add option somewhere for trees to <em>not</em> cast shadows.</p>
<p><strong>o)</strong> Add option somewhere for detail objects to <em>not</em> cast shadows.</p>
<p><strong>o)</strong> <em>(maybe, don&#8217;t know how to do)</em> Option for grass to receive shadows.</p>
<p><strong>o)</strong> Reduce memory allocations in terrain code. Because of intermediate rendering, some of temporary arrays are not actually needed anymore.</p>
<p>Whew, that was quite a list! I&#8217;m not sure I&#8217;m able to even <em>read</em> through all of that&#8230; well, back to work.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.unity3d.com/2008/04/14/terrain-lighting-shadows-and-the-road-towards-it/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Sliced bread is overrated</title>
		<link>http://blogs.unity3d.com/2008/04/10/sliced-bread-is-overrated/</link>
		<comments>http://blogs.unity3d.com/2008/04/10/sliced-bread-is-overrated/#comments</comments>
		<pubDate>Thu, 10 Apr 2008 07:10:30 +0000</pubDate>
		<dc:creator>Aras Pranckevičius</dc:creator>
				<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blogs.unity3d.com/2008/04/10/sliced-bread-is-overrated/</guid>
		<description><![CDATA[Just had this chat conversation: &#8230; Joachim: yeah it&#8217;s awesome Joachim: function Start () { /* super secret code snippet */ } Aras: whoa Joachim: it rocks Joachim: automatically instantiates material for you Joachim: the same way we do it for scripts Joachim: best thing since sliced bread i think Aras: Aras: hey, back in...]]></description>
			<content:encoded><![CDATA[<p>Just had this chat conversation:</p>
<blockquote><p>&#8230;<br />
<em>Joachim:</em> yeah it&#8217;s awesome<br />
<em>Joachim:</em> function Start () { <em>/* super secret code snippet */</em> }<br />
<em>Aras:</em> whoa<br />
<em>Joachim:</em> it rocks<br />
<em>Joachim:</em> automatically instantiates material for you<br />
<em>Joachim:</em> the same way we do it for scripts<br />
<em>Joachim:</em> best thing since sliced bread i think<br />
<em>Aras:</em> <img src='http://blogs.unity3d.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
<em>Aras:</em> hey, back in the day the terrain was best thing since sliced bread!<br />
<em>Joachim:</em> sliced bread appears to be always worse depending on what i work on.<br />
<em>Aras:</em> maybe sliced bread is just not so good in fact<br />
<em>Aras:</em> sliced bread is overrated</p></blockquote>
<p>And no, I won&#8217;t say <em>what</em> we were talking about <img src='http://blogs.unity3d.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.unity3d.com/2008/04/10/sliced-bread-is-overrated/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Holy FPU precision, Batman!</title>
		<link>http://blogs.unity3d.com/2008/01/22/holy-fpu-precision-batman/</link>
		<comments>http://blogs.unity3d.com/2008/01/22/holy-fpu-precision-batman/#comments</comments>
		<pubDate>Tue, 22 Jan 2008 09:41:25 +0000</pubDate>
		<dc:creator>Aras Pranckevičius</dc:creator>
				<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blogs.unity3d.com/2008/01/22/holy-fpu-precision-batman/</guid>
		<description><![CDATA[One of our customers found an interesting bug the other day: embedding Unity Web Player into a web page makes some javascript animation libraries not work correctly. For example, script.aculo.us or Dojo Toolkit would stop doing some of their tasks. But only on Windows, and only on some browsers (Firefox and Safari). Wait a moment&#8230;...]]></description>
			<content:encoded><![CDATA[<p>One of our customers found an interesting bug the other day: embedding Unity Web Player into a web page makes some javascript animation libraries not work correctly. For example, <a href="http://script.aculo.us/">script.aculo.us</a> or <a href="http://dojotoolkit.org/">Dojo Toolkit</a> would stop doing some of their tasks. But only on Windows, and only on some browsers (Firefox and Safari).</p>
<p>Wait a moment&#8230; Unity plugin makes nice wobbling web page elements not wobble anymore!? Sounds like an <em>interesting</em> issue&#8230;</p>
<p><span id="more-55"></span></p>
<p>So I prepared for a debug session and tried the usual &#8220;divide by two until you locate the problem&#8221; approach.</p>
<ul>
<li>Unity Web Player is composed of two parts: a small browser plugin, and the actual &#8220;engine&#8221; (let&#8217;s call it &#8220;runtime&#8221;). First I change the plugin so that it only loads the data, but never loads or starts the runtime. Everything works. So the problem is not in the plugin. <em>Good</em>.</li>
<li>Load the runtime and do basic initialization (create child window, load Mono, &#8230;), but never actually start playing the content &#8211; everything works.</li>
<li>Load the runtime and <em>fully</em> initialize everything, but never actually start playing the content &#8211; the bug appears! By now I know that the problem is <em>somewhere</em> in the initialization.</li>
</ul>
<p>Initialization reads some settings from the data file, creates some &#8220;manager objects&#8221; for the runtime,     initializes graphics device, loads first game &#8220;level&#8221; and then the game can play.</p>
<p>What of the above could cause <em>something</em> inside browser&#8217;s JavaScript engine stop working? And do that only on Windows, and only on some browsers? My first guess was the most platform-specific part: intialization of the graphics device, which on Windows usually happens to be Direct3D.</p>
<p>So I continued:</p>
<ul>
<li>Try using OpenGL instead of Direct3D &#8211; everything works. By now it&#8217;s confirmed that initializing Direct3D causes something else in the browser not work.</li>
<li>&#8220;A-ha!&#8221; moment: tell Direct3D to not change floating point precision (via a <a href="http://msdn2.microsoft.com/en-us/library/bb172527(VS.85).aspx">create flag</a>). Voilà, everything works!</li>
</ul>
<p>I don&#8217;t know how I <em>actually</em> came up with the idea of testing floating point precision flag. Maybe I remembered some related problems we had a while ago, where Direct3D would cause timing calculations be &#8220;off&#8221;, if the user&#8217;s machine was not rebooted for a couple of weeks or more. That time around we properly changed our timing code to use 64 bit integers, but left Direct3D precision setting intact.</p>
<blockquote><p>Side note: Intel x86 floating point unit (FPU) can operate in various <a href="http://www.stereopsis.com/FPU.html">precision modes</a>, usually 32, 64 or 80 bit. By default Direct3D 9 sets FPU precision to 32 bit (i.e. single precision). Telling D3D to not change FPU settings <em>could</em> lower performance somewhat, but in my tests it did not have any noticeable impact.</p></blockquote>
<p>So there it was. A debugging session, one line of change in the code, and fancy javascript webpage animations work on Windows in Firefox and Safari. This is coming out in Unity 2.0.2 update soon.</p>
<p>The moral? Something in one place can affect seemingly <em>completely</em> unrelated things in another place!</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.unity3d.com/2008/01/22/holy-fpu-precision-batman/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Intermediate rendering, or what goes into a feature</title>
		<link>http://blogs.unity3d.com/2007/12/06/intermediate-rendering-or-what-goes-into-a-feature/</link>
		<comments>http://blogs.unity3d.com/2007/12/06/intermediate-rendering-or-what-goes-into-a-feature/#comments</comments>
		<pubDate>Thu, 06 Dec 2007 20:30:40 +0000</pubDate>
		<dc:creator>Aras Pranckevičius</dc:creator>
				<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blogs.unity3d.com/2007/12/06/intermediate-rendering-or-what-goes-into-a-feature/</guid>
		<description><![CDATA[We&#8217;ve got a feature we want to do &#8212; it&#8217;s something we call &#8220;intermediate mode render calls&#8221;. The idea is that some script could say: Draw( position, rotation, mesh, material ); And that would make the mesh appear with the given material at the given position on the screen, and it would just work with...]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve got a feature we want to do &#8212; it&#8217;s something we call &#8220;intermediate mode render calls&#8221;. The idea is that some script could say:</p>
<p><code>Draw( position, rotation, mesh, material );</code></p>
<p>And that would make the mesh appear with the given material at the given position on the screen, <em>and</em> it would just work with pixel lights, shadows, projectors and whatnot.</p>
<p><span id="more-47"></span><br />
<blockquote> A step aside on why this is needed: in Unity 2.0 the terrain engine does not fully integrate with pixel lights or shadows; and Projectors don&#8217;t work with it either. The reason is that terrain is rendered immediately: at some point terrains gets it&#8217;s render call, draws the chunks of the terrain, the trees, the detail objects and all of this goes straight to the screen.</p>
<p>For shadows, pixel lights or projectors to work, however, <em>something</em> has to be remembered, so that the most important lights can be calculated for each object, so that shadow casters could be rendered, and so on.</p>
<p>With intermediate mode render calls the terrain engine could &#8220;submit&#8221; this lightweight rendering information: mesh, material, position; and the rendering system would figure out everything else at rendering time.</p></blockquote>
<p>Ok, the above sounds like a plan. What goes into developing such feature?</p>
<p>The basic functionality is obvious. <tt>Draw()</tt> above would not actually draw anything immediately, just merely record the information somewhere in the scene: &#8220;this mesh with this material will have to be drawn here&#8221;. At the end of the frame, all this information would be discarded, so Draw() persists for one frame only.</p>
<p>Some design issues immediately pop up:</p>
<ul>
<li>Will this mesh be rendered in all cameras, or just single one? (which one?)</li>
<li>Maybe it&#8217;s drawn in all cameras if called from inside <a href="http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.Update.html">Update()</a>, and drawn for current camera if called from inside <a href="http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.OnPreCull.html">OnPreCull()</a> or <a href="http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.OnPreRender.html">OnPreRender()</a>?</li>
<li>Or maybe we add an explicit &#8220;camera&#8221; parameter; and the mesh will be rendered in all cameras if no camera is indicated?</li>
<li>What to do if Draw() is called from inside of <a href="http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.Start.html">Start()</a>, <a href="http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.Awake.html">Awake()</a> and other functions that are not related to &#8220;frame&#8221; or &#8220;camera&#8221;?</li>
</ul>
<p>Some of the work required is also obvious: Right now all renderable things in Unity are <a href="http://unity3d.com/support/documentation/ScriptReference/Renderer.html">Renderer</a> components. That means they live in some game object, and so on. For intermediate mode calls, we need to put base rendering functionality somewhere &#8220;up&#8221; &#8211; so that a renderable thing can not necessarily be a Component in a game object.</p>
<ul>
<li>Make a leaner base renderer class that does not derive from Component (call it BaseRenderer). Move out base functionality from Renderer to BaseRenderer as needed. Make Renderer be both a Component and BaseRenderer.</li>
<li>Make the rendering code (that figures out lights, does shadows, &#8230;) operate on BaseRenderers, not Renderers.</li>
<li>Make IntermediateRenderer that would be used for intermediate mode. It has transformation matrix, pointers to mesh and material. Make it setup and update all related internal structures that describe Unity scene.
<ul>
<li>Possibly need distinction between scene-wide meshes and camera-specific meshes.</li>
<li>Clear all intermediate renderers at end of frame. And make this work in the editor with multiple views into the scene present.</li>
</ul>
</li>
</ul>
<p>With the above, we can go and write some code to implement the feature. Look ma, no game objects are here, just two lines of code drawing 100 meshes with random rotation in a loop! And it works with shadows!</p>
<p><a href="http://blogs.unity3d.com/wp-content/uploads/2007/12/intermediatemode.png" title="Look ma, no game objects here!"><img src="http://blogs.unity3d.com/wp-content/uploads/2007/12/intermediatemode.png" alt="Look ma, no game objects here!" /></a></p>
<p>So the proof that the base feature works is there already <em>(we say it&#8217;s a killer feature for making demoscene demos)</em>. We still have the design issues of the above, <em>and</em> some more that popped up while writing the code:</p>
<ul>
<li>Is culling performed on these meshes or not? It&#8217;s useful if the mesh will be rendered for all cameras, and potentially redundant if the mesh is drawn for single camera only.</li>
<li>Are layer masks indicated anywhere? Add a parameter to the function?</li>
<li>What if for each mesh rendered I want to change something in the material? (change some value for a shader, use a different texture, different tint color, &#8230;) Should I instantiate materials myself? Should the API instantiate materials internally? Should I supply variable number of arguments saying &#8220;and do these changes to the material before drawing&#8221;?</li>
</ul>
<p>It&#8217;s a long rocky road between thinking up a feature and shipping it. Surprisingly, actual development does not take up much time; the most difficult part is answering all the design questions.</p>
<p>Anyway, after all design issues are solved (or&#8230; ignored!), the feature usually is shipped. Yay!</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.unity3d.com/2007/12/06/intermediate-rendering-or-what-goes-into-a-feature/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

