<?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>Nodraw.net &#187; Tutorials</title>
	<atom:link href="http://www.nodraw.net/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nodraw.net</link>
	<description>Source Engine Level Design</description>
	<lastBuildDate>Mon, 14 Feb 2011 12:51:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Lighting Compile Options</title>
		<link>http://www.nodraw.net/2010/12/lighting-compile-options/</link>
		<comments>http://www.nodraw.net/2010/12/lighting-compile-options/#comments</comments>
		<pubDate>Thu, 02 Dec 2010 18:19:16 +0000</pubDate>
		<dc:creator>Timothy 'YM' Johnson</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[compile]]></category>
		<category><![CDATA[Hammer]]></category>
		<category><![CDATA[Lights]]></category>
		<category><![CDATA[Mapping]]></category>
		<category><![CDATA[prop_static]]></category>
		<category><![CDATA[staticproplighting]]></category>
		<category><![CDATA[staticproppolys]]></category>
		<category><![CDATA[textureshadows]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.nodraw.net/?p=324</guid>
		<description><![CDATA[Today I&#8217;m going to discuss the lighting conventions of source. Source has been evolving steadily since Half Life 2, with the introduction of HDR with Episode 1 and then per-vertex lighting for static props and shadowing textures with the Orange Box. These new methods for calculating lighting at compile time have become the standard for [...]]]></description>
			<content:encoded><![CDATA[<p>Today I&#8217;m going to discuss the lighting conventions of source. Source has been evolving steadily since Half Life 2, with the introduction of HDR with Episode 1 and then per-vertex lighting for static props and shadowing textures with the Orange Box. These new methods for calculating lighting at compile time have become the standard for source, everything produced since the Orange Box uses them.</p>
<p>Unfortunately the improved lighting introduced with the Orange Box was not added to hammer&#8217;s default compile settings, even as options, so we must add them ourselves. That means we need to know what they are and what they do. There are three options that we&#8217;re going to look at today, texture shadows, per vertex lighting for static props, and exact outline shadow casting for static props. So what exactly do they do?</p>
<p><span id="more-324"></span></p>
<h3>-staticproppolys</h3>
<p>-staticproppolys tells VRAD to use the exact outline of a static prop when it works out how light is cast. You might think it does this already as I once did but there are some props that cast odd shadows. VRAD uses collision meshes by default because, for many reasons, collision meshes have a lot simpler geometry which makes calculating lighting around them a lot quicker. For realistic lighting though, this is a problem as a lot of props have collision meshes that don&#8217;t precisely mimic the contours of the object itself.</p>
<h3>-textureshadows</h3>
<p>-textureshadows does what it says on the tin, it makes VRAD calculate shadows from textures with alpha channels that are applied to props. Chainlink fences and foliage are the most common props with alpha textures, to save having to model all the individual links in the fence a single sheet is used that has a transparent texture applied to it, but if VRAD is using the collision mesh or even the exact outline of the prop for shadowing then it thinks the links are as solid as a sheet of steel. -Texture shadows solves this. The prop must however be named in a lights.rad file in the root of the game you are compiling for otherwise it won&#8217;t bother with it. I&#8217;ll cover that in a bit.</p>
<h3>-staticproplighting</h3>
<p>-staticproplighting calculates per-vertex lighting for static props. Before all static props were lit by a single calculation at their origin or lighting origin. If that was inside a wall the prop was black, if it was in shade the entire prop was dark, if it was in light the entire prop was bright. Now though if half a model is in light and half is in shade, only the vertices that are in light are bright and if part of the prop is inside a wall then only the vertices that are actually inside the wall are black.</p>
<p>Unlike the previous two, this will increase the filesize of a map as well as the compile time. Since the previous two are lightmap based, the resulting filesize is the same with or without them but -staticproplighting forces VRAD to calculate hundreds if not thousands more bits of lighting information for each static prop used in the map.</p>
<h3>Lets look at some examples:</h3>
<p><img class="aligncenter size-large wp-image-330" title="lighting_case_ex1" src="http://www.nodraw.net/wp-content/uploads/2010/12/lighting_case_ex1-700x394.jpg" alt="" width="700" height="394" /></p>
<p>This one shows notable improvement for each compile parameter added. For -staticproppolys the shadow cast by the crane is turned from a dark blobby mass into an accurate network of dark and light as the light shines through gaps in the planks of wood. The dark blob around the rocks disappears as VRAD uses the outlines of the rocks instead of the collision mesh that the rocks don&#8217;t actually have. The razor wire top of the fence also cast a shadow before but with -staticproppolys the shadow from it is almost nonexistent.<br />
With -textureshadows the massive dark area caused by the fence disappears. If the sun spread angle was lower and the lightmap scale on the ground low enough you&#8217;d be able to see the chainlink pattern cast as a shadow here.<br />
Finally -staticproplighting has a subtle effect but if you look carefully at each prop you&#8217;ll see it working. The spigot is half shadowed and half lit now, the boulder is casting a shadow onto the smaller part of it that is hidden from the sun, the inside of the concrete tubes are dark now.</p>
<p><img class="aligncenter size-large wp-image-329" title="lighting_case_ex2" src="http://www.nodraw.net/wp-content/uploads/2010/12/lighting_case_ex2-700x394.jpg" alt="" width="700" height="394" /></p>
<p>This example shows most improvement with -staticproplighting. The corrugated metal sheets have some shadowing on them, the smallest one&#8217;s origin is either inside the plank of wood in front of it, or just behind it, in a dark shadow, but with -staticproplighting light falls on all the vertices except for a single strip through the middle. The oil drums have more natural lighting in the final shot, the one in the front casts a shadow on the one behind. You can also see the shadow cast by the fence disappear in the second two screenshots.</p>
<h3>How do we use these features?</h3>
<p>First you&#8217;ll need to enable expert mode on your compile options (click the &#8216;Expert&#8230;&#8217; button on the &#8216;Run Map&#8217; window) pick a configuration you wish to modify, generally these options are good for very final compiles, I only use them when doing a final build or for fine lighting tweaking, so &#8216;HDR Full compile -final (slow!)&#8217; is probably a good configuration to alter. Find the $light_exe one in the list of compile commands and select it. There is an image below, but yours won&#8217;t look exactly like this because I&#8217;ve added a few of my own which I can toggle on/off for different compiles. Add this to the Parameters of the $Light_exe one you just selected (without the quotes) &#8220;-lights mylights.rad -staticproppolys -textureshadows -staticproplighting&#8221;. Add them at the start of the list, NOT the end. The very final bit in the Parameters box should always be &#8220;-game $gamedir $path\$file&#8221; which should already be there, just make sure anything you add to $light_exe is in front of -game.</p>
<p><img class="aligncenter size-full wp-image-326" title="compile_options" src="http://www.nodraw.net/wp-content/uploads/2010/12/compile_options.jpg" alt="Expert mode compile options" width="558" height="346" /></p>
<p>There is one last thing that needs to be done, you need to create a mylights.rad file. This file is just a list of all the props you&#8217;re using that need -textureshadows enabling for them. You use &#8216;forcetextureshadow&#8217; followed by the filepath of the model, each model on a new line. &#8220;forcetextureshadow models/props_gameplay/security_fence512.mdl&#8221; for example.<br />
Once you have that file, and have added in your parameters in hammer, just hit &#8216;Go!&#8217; and wait for your compile.</p>
<h3>Wait, there&#8217;s more!</h3>
<p>Whilst these options are generally fantastic for improving visuals, there are a few cases where they make things worse and need to be turned off on a prop by prop basis. There are three options at the bottom of the keyvalues for any static prop which alter how these compile settings work. Well actually, just how -staticproppolys works. &#8216;Disable Vertex lighting&#8217; does what it says on the tin, stops all per-vertex calculations for the prop in question and uses the pre-2007 method of using just the prop&#8217;s origin. &#8216;Disable Self-Shadowing with vertex lighting&#8217; doesn&#8217;t turn off the per-vertex lighting calculations, but rather tells it to ignore other parts of the same prop when calculating lighting. I haven&#8217;t found a case where I&#8217;ve needed this, but the fact that it&#8217;s there means Valve did. Finally &#8216;Ignore surface normal for computing vertex lighting&#8217; makes each calculation unaware of which direction the face is facing.</p>
<p><img class="aligncenter size-large wp-image-327" title="lighting_case_ex5" src="http://www.nodraw.net/wp-content/uploads/2010/12/lighting_case_ex5-621x700.jpg" alt="" width="621" height="700" /></p>
<p>Here the top image shows the scene compiled with -textureshadows, -staticproppolys and &#8211; staticproplighting turned on but you can see there&#8217;s a bit of blotchy lighting on the concrete tube. This is caused by a single vertex on the tube being in exactly the wrong place, it&#8217;s in the shadow of one of the chain links. This isn&#8217;t a terrible example but if you wanted to remove this unrealistic blotchyness you might want to change the &#8216;Disable vertex lighting&#8217; option to &#8216;yes&#8217; which is shown below. You also lose the darkness on the inside of the tube, so you have to weigh the pros and cons in each case. The tube&#8217;s properties look like this:</p>
<p><img class="aligncenter size-large wp-image-331" title="properties_02" src="http://www.nodraw.net/wp-content/uploads/2010/12/properties_02-700x367.jpg" alt="" width="700" height="367" /></p>
<p>Below is another example that occurs frequently. Single sided models, that is models which are only a single sheet of polygons with a texture using $nocull so you can see the back of it, only receive light from their front. This means if a piece of corrugated metal, such as the centre piece below, is facing away from the main light source it will be unnaturally dark especially if it&#8217;s next to similar props facing the opposite direction.</p>
<p><img class="aligncenter size-large wp-image-328" title="lighting_case_ex4" src="http://www.nodraw.net/wp-content/uploads/2010/12/lighting_case_ex4-621x700.jpg" alt="" width="621" height="700" /></p>
<p>You can see with the ignore surface normals option changed to yes the middle sheet of metal now receives light like the others do. Again, this is what the properties of that prop look like:</p>
<p><img class="aligncenter size-large wp-image-332" title="properties_01" src="http://www.nodraw.net/wp-content/uploads/2010/12/properties_01-700x367.jpg" alt="" width="700" height="367" /></p>
<p>Enjoy. (No doubt I&#8217;ve made something unclear or have made a mistake, so&#8230; comments!)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nodraw.net/2010/12/lighting-compile-options/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Tweaking Hammer for Efficiency</title>
		<link>http://www.nodraw.net/2010/01/tweaking-hammer-for-efficiency/</link>
		<comments>http://www.nodraw.net/2010/01/tweaking-hammer-for-efficiency/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 14:49:29 +0000</pubDate>
		<dc:creator>Timothy 'YM' Johnson</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Hammer]]></category>
		<category><![CDATA[Shortcut]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.nodraw.net/?p=82</guid>
		<description><![CDATA[Like any engine, after a bit of love and attention it can run much better, spend some time setting hammer up how you like it, get something that you like and get it to work for you, it&#8217;s your workflow. Some things you might want to consider doing in that options menu you probably have [...]]]></description>
			<content:encoded><![CDATA[<p>Like any engine, after a bit of love and attention it can run much better, spend some time setting hammer up how you like it, get something that you like and get it to work for you, it&#8217;s your workflow.</p>
<p>Some things you might want to consider doing in that options menu you probably have ignored largely:</p>
<ul>
<li>Turn off verticies &#8211; Your 2D view now only draws the verticies of the brush you have selected, the 2D views are a lot less cluttered this way, especially when zoomed out a lot.</li>
<li>Default to 15 degree rotations &#8211; Using alt to rotate in .5 degree rotations, you can quickly rotate something exactly or roughly depending on what you want.</li>
<li>Arrow keys nudge selected object/vertex &#8211; Very useful for moving stuff by a few increments, even duplication as shift+arrow key will duplicate the object and put the new one one gridline in that direction.</li>
<li>Increase the distances &#8211; The Back clipping plane and model render distances both stop you seeing a vista as it was intended in your 3D view. I have mine well over 8000 units away.</li>
<li>Uncheck &#8216;Animate models&#8217; &#8211; particularly if you&#8217;re working with large animated models such as cinematic explosions the 3D and 2D views can become obstructed, not to mention its just another thing taking time to render.</li>
<li>Match the camera&#8217;s FoV with what you use in game &#8211; It goes without saying that a miss match will lead you to view the same area differently in game and in hammer, make sure they match!</li>
<li>Increase the camera speed &#8211; Mine is set to 6500. Holding space turns the left mouse into a freelook and using WASD keys to move around I can move around at great speed.</li>
</ul>
<p><span id="more-82"></span></p>
<p>Use Cordon wisely. See that little hazard stripe button? It isn&#8217;t just a compile tool, its far more powerful than that. Cordon can cut through all the mess in your 2D view to show you exactly the area you&#8217;re working on. You don&#8217;t want to look through your entire level just to see one staircase in detail, just drag a cordon area around it, enable it and you can see your staircase, free of clutter. Like this:</p>
<div id="attachment_83" class="wp-caption aligncenter" style="width: 710px"><img class="size-large wp-image-83" src="http://www.nodraw.net/wp-content/uploads/2009/12/cordonoffon-700x237.png" alt="" width="700" height="237" /><p class="wp-caption-text">Here the same staircase is viewed, without cordon enabled the staircase is almost invisible behind the rest of the level.</p></div>
<p>Got two screens? Wondered about hammer&#8217;s dual screen capabilities? Well its possible with another thing available in the options menu. &#8220;Use independent window configurations&#8221; and &#8220;Load default window positions with maps&#8221; in the general tab, check both. Drag hammer to the size you wan it (It won&#8217;t go fullscreen over two monitors unfortunately). Then use Window&gt;New window to add single windows, resize them and position them how you want. Then hit the Save window state button (looks like a stack of windows with an S next to it on the top toolbar). Now whenever you open a map in hammer it will load with this window configuration.</p>
<p>You can also undock and resize the side toolbars, I have mine floating between the two screens and I shifted my top toolbar to the middle too. Here is my display:</p>
<div id="attachment_85" class="wp-caption aligncenter" style="width: 710px"><img class="size-large wp-image-85" src="http://www.nodraw.net/wp-content/uploads/2009/12/Dualscreenhammer2-700x212.jpg" alt="" width="700" height="212" /><p class="wp-caption-text">I favour the topdown view out of the 2D views, so it got to be the biggest. The fullscreen 3D view accurately represents what I might see ingame after I changed the FoV to match my ingame settings. I added two black bars to the middle so you can see where my screen splits.</p></div>
<p>I&#8217;ve heard people rave about the VBCT&#8217;s options for compiles and how easy they are to use. I quite like hammer&#8217;s own compile options, if you press &#8216;Expert&#8230;&#8217; on the standard compile options you get to a much more in depth version, I&#8217;ve hijacked the HDR full compile configuration and added in a load of my own, I now have a checkbox system for fast/normal vis and normal/fancy lighting, as well as a -makedevshots checkbox option. Unchecking all but bsp is my leak-check compile.</p>
<div id="attachment_88" class="wp-caption aligncenter" style="width: 566px"><img class="size-full wp-image-88" src="http://www.nodraw.net/wp-content/uploads/2009/12/advanced-compile.png" alt="" width="556" height="342" /><p class="wp-caption-text">Checkbox options for all the types of compiles I run, easy to pick and choose.</p></div>
<p>Last but not least, a feature of Windows 7 that I&#8217;ve grown particularly fond of: Jump lists. Valve have been quick to take advantage of them and the steam jump list is one of my favourites. You can access jump lists by either right clicking or a click+drag upwards from a taskbar icon. Once opened, you can launch the SDK directly instead of opening the steam window and tools tab. It only saves a few clicks but I like it <img src='http://www.nodraw.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div id="attachment_119" class="wp-caption aligncenter" style="width: 305px"><img class="size-full wp-image-119" title="steam jumplist" src="http://www.nodraw.net/wp-content/uploads/2010/01/steam-jumplist.jpg" alt="" width="295" height="560" /><p class="wp-caption-text">Common tasks within steam.</p></div>
<p>And to round everything off: Learn the shortcuts for all the tools, they&#8217;re listed here: <a title="Here" href="http://www.nodraw.net/2009/12/speed-mapping/">Two posts ago.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nodraw.net/2010/01/tweaking-hammer-for-efficiency/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Dynamic Materials with Proxies</title>
		<link>http://www.nodraw.net/2010/01/dynamic-materials-with-proxies/</link>
		<comments>http://www.nodraw.net/2010/01/dynamic-materials-with-proxies/#comments</comments>
		<pubDate>Sun, 03 Jan 2010 11:08:22 +0000</pubDate>
		<dc:creator>Andy "Velvet Fist, Iron Glove" Durdin</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[materials]]></category>
		<category><![CDATA[proxies]]></category>

		<guid isPermaLink="false">http://www.nodraw.net/?p=93</guid>
		<description><![CDATA[Material proxies are a neat little feature of the Source engine that let you alter various properties of a material dynamically.  This can produce some neat effects, as the texture position, scale, rotation, transparency and much more can be changed continuously, or even in response to game events. Take Half-life 2, for example.  You know [...]]]></description>
			<content:encoded><![CDATA[<p>Material proxies are a neat little feature of the Source engine that let you alter various properties of a material dynamically.  This can produce some neat effects, as the texture position, scale, rotation, transparency and much more can be changed continuously, or even in response to game events.</p>
<p>Take Half-life 2, for example.  You know those combine force-fields, that ripple with energy, and fade out as you move away from it?  Or in Team Fortress 2, you&#8217;ll have seen the rotating radar screen in the 2fort basement.  Both those effects are done with material proxies.</p>
<div id="attachment_99" class="wp-caption aligncenter" style="width: 310px"><a rel="attachment wp-att-99" href="http://www.nodraw.net/2010/01/dynamic-materials-with-proxies/proxies/"><img class="size-medium wp-image-99 " src="http://www.nodraw.net/wp-content/uploads/2010/01/proxies-300x240.jpg" alt="Proxies" width="300" height="240" /></a><p class="wp-caption-text">Force fields and computer screens animated with material proxies</p></div>
<p><span id="more-93"></span></p>
<p>For this post, I&#8217;ve prepared four materials that provide a gradual introduction to several different ways of using proxies.  Since proxies are all about animated textures, screenshots alone won&#8217;t be very informative, so I&#8217;ve made a &#8220;Proxy Museum&#8221; HL2 map with these examples in. Download it and run HL2 in a window so you can follow along the article and see the results alongside.  The first example is in the first room, on the left-hand wall.</p>
<p style="text-align: center;"><strong><a href="http://www.nodraw.net/wp-content/uploads/2010/01/proxy_museum.zip">Download the proxy_museum example map</a></strong></p>
<p>Let&#8217;s start with a simple example. Here is the VMT for a basic texture, a section of carpet:</p>
<pre>    "LightmappedGeneric"
    {
    	"$basetexture" "overlays/redrunner001b"
    }</pre>
<p>One of the easiest things to do with proxies is to make a scrolling texture, with the &#8220;TextureScroll&#8221; proxy. Here&#8217;s the same texture, only now it is a moving piece of infinite carpet:</p>
<pre>    "LightmappedGeneric"
    {
    	"$basetexture" "overlays/redrunner001b"

        "Proxies"
        {
            "TextureScroll"
            {
                "textureScrollVar" "$basetexturetransform"
                "textureScrollRate" 0.25
                "textureScrollAngle" 90
            }
        }
    }</pre>
<div id="attachment_101" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.nodraw.net/wp-content/uploads/2010/01/the_infinite_carpet.jpg"><img class="size-medium wp-image-101" src="http://www.nodraw.net/wp-content/uploads/2010/01/the_infinite_carpet-300x240.jpg" alt="The Infinite Carpet" width="300" height="240" /></a><p class="wp-caption-text">This carpet scrolls endlessly.</p></div>
<p>The Valve developer wiki has a <a href="http://developer.valvesoftware.com/wiki/List_Of_Material_Proxies">good reference</a> for many of the proxies available; here&#8217;s what it says about TextureScroll:</p>
<p style="padding-left: 30px;"><strong>TextureScroll</strong></p>
<p style="padding-left: 30px;">Returns a transform matrix or vector that will translate a texture at a given angle at a given rate.</p>
<ul style="padding-left: 30px;">
<li>textureScrollVar — Destination for the resulting transformation.</li>
<li>textureScrollRate — Rate of scroll in units per second.</li>
<li>textureScrollAngle — Angle of rotation to move along. (90 = up, 180 = left, etc)</li>
</ul>
<p>So just by adding these few lines, we now have a texture that scrolls vertically, scrolling one full length in four seconds (0.25 units per second). The most important bit here is the value we give for textureScrollVar.  All proxies need to store their output somewhere; here we are telling it to store its output into the $basetexturetransform property.</p>
<p>If you&#8217;re familiar with material properties, you&#8217;ll know that <a href="http://developer.valvesoftware.com/wiki/$basetexturetransform">$basetexturetransform</a> allows you to scale, rotate, and offset the texture; for example, setting &#8220;$basetexturetransform&#8221; &#8220;center .5 .5 scale 1 1 rotate 0 translate 0 .5&#8243; directly in your VMT would cause the texture to appear shifter vertically by half its size. However by using a proxy, the basetexturetransform is updated for every frame that&#8217;s rendered, producing a very smooth scroll.</p>
<div id="attachment_103" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.nodraw.net/wp-content/uploads/2010/01/whirling_blur.jpg"><img class="size-medium wp-image-103" src="http://www.nodraw.net/wp-content/uploads/2010/01/whirling_blur-300x240.jpg" alt="Whirling Blur" width="300" height="240" /></a><p class="wp-caption-text">This picture constantly rotates.</p></div>
<p>Now turn around, and look at the picture opposite.  Here you have the classic impressionist portrait, which portrays the sitter as merely a tiny part of the endless circle of life.  I&#8217;m sorry, I mean it shows a constantly rotating material.</p>
<p>Here&#8217;s the VMT for this material:</p>
<pre>    "LightmappedGeneric"
    {
        "$basetexture" "models/props_c17/bladeblur"

        "$angle" 0.0
        "$translate" "[0.0 0.0]"
        "$center" "[-0.5 -0.5]"

        "Proxies"
        {
            "LinearRamp"
            {
                "rate" 45
                "initialValue" 0.0
                "resultVar" "$angle"
            }

            "TextureTransform"
            {
                "translateVar" "$translate"
                "rotateVar" "$angle"
                "centerVar" "$center"
                "resultVar" "$basetexturetransform"
            }
        }
    }</pre>
<p>Unlike the previous example, there&#8217;s no proxy specifically for continuously rotating textures, so instead we use the TextureTransform proxy:</p>
<p style="padding-left: 30px;"><strong>TextureTransform</strong></p>
<p style="padding-left: 30px;">Generates a texture transform matrix.</p>
<ul style="padding-left: 30px;">
<li>centerVar — Name of a variable holding the center of rotation and scaling. [Optional]</li>
<li>scaleVar — Name of scale variable (2D vector). [Optional]</li>
<li>rotateVar — Name of rotation angle variable (float). [Optional]</li>
<li>translateVar — Name of the translation variable (2D vector).</li>
<li>resultVar — Resulting value.</li>
</ul>
<p>This proxy lets you set the texture&#8217;s scale, rotation, and translation all at once, but instead of giving it values directly, now we need to create variables, and give the variable names to TextureTransform.  To create a variable, just give it a name (beginning with $) and a starting value, before the Proxies section:</p>
<pre>        "$angle" 0.0
        "$translate" "[0.0 0.0]"
        "$center" "[-0.5 -0.5]"</pre>
<p>The type of the variable depends on the value; $angle is just a number, while $translate and $center are 2-dimensional vectors.  $center will be the center of rotation, wile $translate is how much to offset the texture.  We don&#8217;t want to offset it at all actually, but TextureTransform insists that you give a value for &#8220;translateVar&#8221;.</p>
<p>If that was all we had, the texture would be nicely rotated by zero degrees; so we need to make the angle always increasing so the texture rotates continuously.</p>
<p style="padding-left: 30px;"><strong>LinearRamp</strong></p>
<p style="padding-left: 30px;">Produces an ever increasing value.</p>
<ul style="padding-left: 30px;">
<li>rate — Rate of increase of the value.</li>
<li>initialValue — Initial value to increase.</li>
<li>resultVar — Resulting value.</li>
</ul>
<p>LinearRamp to the rescue: by adding the LinearRamp proxy, we make $angle increase by 45 degrees every second.</p>
<div id="attachment_97" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.nodraw.net/wp-content/uploads/2010/01/look_at_me.jpg"><img class="size-medium wp-image-97" src="http://www.nodraw.net/wp-content/uploads/2010/01/look_at_me-300x240.jpg" alt="Look at Me" width="300" height="240" /></a><p class="wp-caption-text">The picture disappears as you look at it.</p></div>
<p>Around the other side of this central wall is an interesting picture, that you cannot easily see—it fades away when you look at it directly.  Can you guess how this was done?  That&#8217;s right, proxies!  Here&#8217;s the VMT for the material:</p>
<pre>    "LightmappedGeneric"
    {
        "$basetexture" "Metal/metalwall078a"
        "$surfaceprop" "metal"

        "$envmap" "env_cubemap"
        "$envmaptint" "[ .56 .56 .75 ]"

        "$bumpmap" "metal/metalwall078a_normal"
        "$nodiffusebumplighting" 1
        "$normalmapalphaenvmapmask" 1

        "$dpscale" 7.0
        "$dotproduct" 0.0
        "$alpha_unclamped" 0.0

        "Proxies"
        {
            "PlayerView"
            {
                "scale" 7.0
                "resultVar" "$dotproduct"
            }
            "Subtract"
            {
                "srcVar1" "$dpscale"
                "srcVar2" "$dotproduct"
                "resultVar" "$alpha_unclamped"
            }
            "Clamp"
            {
                "min" 0.0
                "max" 1.0
                "srcVar1" "$alpha_unclamped"
                "resultVar" "$alpha"
            }
        }
    }</pre>
<p>The Valve wiki describes the PlayerView proxy like this:</p>
<p style="padding-left: 30px;"><strong>PlayerView</strong></p>
<p style="padding-left: 30px;">Stores the dot product of the view direction + the direction from the camera to the entity the material is on.</p>
<ul style="padding-left: 30px;">
<li>scale — Amount to scale the dot product by.</li>
<li>resultVar — Resulting value.</li>
</ul>
<p>What all that actually means is that its result will be 1.0 if the player is looking directly at the center of the material, decreasing down to 0.0 if looking at right angles to it, and to -1 when the player is facing away.  Here we scale that by 7.0 to get a result from -7.0 to 7.0 in the $dotproduct variable.</p>
<p>There are a number of proxies for performing mathematical calculations: Add, Subtract, Multiply, Divide, and more.  Here we use two of them:</p>
<p style="padding-left: 30px;"><strong>Subtract</strong></p>
<p style="padding-left: 30px;">Subtracts the second variable from the first.</p>
<ul style="padding-left: 30px;">
<li>srcVar1</li>
<li>srcVar2</li>
<li>resultVar</li>
</ul>
<p style="padding-left: 30px;"><strong>Clamp</strong></p>
<p style="padding-left: 30px;">Keeps a variable within a specified range.</p>
<ul style="padding-left: 30px;">
<li>min,</li>
<li>max — The acceptable range of values</li>
<li>srcVar1</li>
<li>resultVar</li>
</ul>
<p>We subtract $dotproduct from seven so it will range from zero when looking directly at the material to fourteen when looking away, and store the result in $alpha_unclamped.</p>
<p>Finally, since the $alpha value is expected to be between zero and one.  Fourteen is obviously well out of that range, so we clamp $alpha_unclamped so that it&#8217;s never less than zero or more than one, and store the result in $alpha.  The end result is that the material is now fully transparent when looking at the center of it, becomes opaque as the player looks away.</p>
<div id="attachment_94" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.nodraw.net/wp-content/uploads/2010/01/breen_diptych.jpg"><img class="size-medium wp-image-94" src="http://www.nodraw.net/wp-content/uploads/2010/01/breen_diptych-300x240.jpg" alt="Breen Diptych" width="300" height="240" /></a><p class="wp-caption-text">The tint of the material is animated randomly.</p></div>
<p>The final picture in the gallery shows Dr. Breen in his true colours—all of them.  Taking inspiration from Andy Warhol, sixteen func_brushes with portraits of Dr. Breen are arranged in a mosaic.  The same material is applied to each of them, the variation is controlled by proxies:</p>
<pre>    "LightmappedGeneric"
    {
    	"$basetexture" "scripted/breen_fakemonitor_"

        // The base texture will be multiplied by this color
        "$color" "[1.0 1.0 1.0]"

        "$offset" "0"

    	"Proxies"
    	{
            "EntityRandom"
            {
                "scale" "12"
                "resultVar" "$offset"
            }
            "Sine"
            {
                "sineperiod" 4
                "timeoffset" "$offset"
                "resultVar" "$color[0]"
            }
            "Sine"
            {
                "sineperiod" 8
                "timeoffset" "$offset"
                "resultVar" "$color[1]"
            }
            "Sine"
            {
                "sineperiod" 12
                "timeoffset" "$offset"
                "resultVar" "$color[2]"
            }
    	}
    }</pre>
<p>Here we are manipulating $color, a standard material property which is a vector of red, green, and blue values that tints the texture.  This material modifies the red, green, and blue values independently to vary the tint, with three sine waves.</p>
<p style="padding-left: 30px;"><strong>Sine</strong></p>
<p style="padding-left: 30px;">Creates a sine wave.</p>
<ul style="padding-left: 30px;">
<li>sineperiod — Period of the sine wave in seconds.</li>
<li>sinemin — Minimum value of the sine wave.</li>
<li>sinemax — Maximum value of the sine wave.</li>
<li>timeoffset — Used to start the sine wave at a different point in time</li>
<li>resultVar — Resulting value.</li>
</ul>
<p>The Sine proxy does exactly what it says on the tin: creates a sine wave.  The sinemin and sinemax paramters default to 0 and 1 if not set.  So the three Sine proxies we use are creating 3 sine waves with periods of 4, 8, and 12 seconds respectively.</p>
<p>Another important point to note here: the $color material property is a three-element vector.  When outputting values from proxies, using square brackets with a number will set just a single element of a vector.  So the first Sine proxy in this material outputs to &#8220;$color[0]&#8220;, changing the red value only.</p>
<p>The other proxy in this material is quite important for the effect. If we just had the three Sine proxies, all the sixteen portraits would animate together.  So we want each of them to start its sine waves from a different point, for which we use the EntityRandom proxy:</p>
<p style="padding-left: 30px;"><strong>EntityRandom</strong></p>
<p style="padding-left: 30px;">A proxy that returns a random number associated with the entity the material is applied to. Can be helpful for making animated textures not all be in sync.</p>
<ul style="padding-left: 30px;">
<li>scale — Amount to scale the random number by.</li>
<li>resultVar — Resulting value.</li>
</ul>
<p>Using this, each brush will animate starting at a different point in the 12-second cycle, producing the final effect that you see.</p>
<p>Material proxies allow you to do some very cool effects.  This article has just scratched the surface of what you can do with them.  If you want to learn more, read <a href="http://developer.valvesoftware.com/wiki/Material_Proxies">the Valve developer wiki&#8217;s page on proxies</a> and its <a href="http://developer.valvesoftware.com/wiki/List_Of_Material_Proxies">list of proxies</a> for guidance, but to really learn you&#8217;ll need to study existing examples, and experiment for yourself.</p>
<div id="attachment_102" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.nodraw.net/wp-content/uploads/2010/01/the_showcase_room.jpg"><img class="size-medium wp-image-102" src="http://www.nodraw.net/wp-content/uploads/2010/01/the_showcase_room-300x240.jpg" alt="Three practical examples" width="300" height="240" /></a><p class="wp-caption-text">Three practical examples of material proxy use.</p></div>
<p>If you walk into the remaining room of the museum, you&#8217;ll find three more displays: each of these shows the use of material proxies to achieve a practical effect.</p>
<div id="attachment_98" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.nodraw.net/wp-content/uploads/2010/01/ocean_waves.jpg"><img class="size-medium wp-image-98" src="http://www.nodraw.net/wp-content/uploads/2010/01/ocean_waves-300x240.jpg" alt="Ocean Waves" width="300" height="240" /></a><p class="wp-caption-text">The waves are animated with proxies.</p></div>
<p>Ocean waves: Three sine waves and numerous calculations are used to animate simple waves breaking on the shore.  The wave moves into the shore at a slight angle, washes up, then washes away, fading quickly.</p>
<div id="attachment_96" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.nodraw.net/wp-content/uploads/2010/01/combine_tv.jpg"><img class="size-medium wp-image-96" src="http://www.nodraw.net/wp-content/uploads/2010/01/combine_tv-300x240.jpg" alt="Combine TV" width="300" height="240" /></a><p class="wp-caption-text">The TV screens flicker and jump.</p></div>
<p>Combine TV: A staticky TV screen image that constantly jumps as if reception is poor.  This uses two GuassianNoise proxies to generate random numbers to control the jumping of a base texture, and a UniformNoise proxy to randomly offset the second texture of the UnlitTwoTexture shader.</p>
<div id="attachment_95" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.nodraw.net/wp-content/uploads/2010/01/chess_with_lasers.jpg"><img class="size-medium wp-image-95" src="http://www.nodraw.net/wp-content/uploads/2010/01/chess_with_lasers-300x240.jpg" alt="Chess with Lasers" width="300" height="240" /></a><p class="wp-caption-text">The laser beams flicker and fade.</p></div>
<p>Chess, with Lasers: A UniformNoise proxy makes the lasers flicker constantly, while the PlayerProximity proxy is used with calculations to subtly fade the lasers when viewed from a distance or very near.</p>
<p>The VMF of the map, and VMTs of all the materials <a href="http://www.nodraw.net/wp-content/uploads/2010/01/proxy_museum_sources.zip">can be downloaded here</a>; hopefully these will inspire you to create your own amazing effects!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nodraw.net/2010/01/dynamic-materials-with-proxies/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Speed Mapping</title>
		<link>http://www.nodraw.net/2009/12/speed-mapping/</link>
		<comments>http://www.nodraw.net/2009/12/speed-mapping/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 21:42:44 +0000</pubDate>
		<dc:creator>MangyCarface</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Hammer]]></category>
		<category><![CDATA[Mapping]]></category>
		<category><![CDATA[shortcuts]]></category>
		<category><![CDATA[speed]]></category>

		<guid isPermaLink="false">http://www.nodraw.net/?p=80</guid>
		<description><![CDATA[There are a few things you can do to greatly improve the speed at which you map. I&#8217;ll be going through a few of these things, point by point, but you must use them in practice in order to get faster! Plan while not at hammer. Idle time spend at your keyboard adds up; know [...]]]></description>
			<content:encoded><![CDATA[<p>There are a few things you can do to greatly improve the speed at which you map. I&#8217;ll be going through a few of these things, point by point, but you must use them in practice in order to get faster!</p>
<ol>
<li>Plan while not at hammer. Idle time spend at your keyboard adds up; know what you want to do before you sit down. All your time in hammer should be spent at maximum speed.</li>
<li>Compile very infrequently. These take too much of your time that you could otherwise be spending working. Complete your daily task sheet and compile at the end of the day; take note of issues ingame and prepare to fix those tomorrow.</li>
<li>Cordon compiles: Don’t lazily seal your map; do it methodically and strongly according to optimization practices. Until then, use the cordon method to test your compiles.</li>
<li>Use your keyboard shortcuts wisely and swiftly! Proper hammer hand position is not on ASDF but on SHIFT Z X C V. Use your X finger to shift up to S. You should not be wasting time pressing buttons with the mouse, when you can do it in microseconds with shortcuts.</li>
</ol>
<blockquote>
<ul>
<li>Shift: When you grab a brush, hold shift and drag it to duplicate the brush. Don’t bother making a new brush, this wastes your time! Grab the nearest, closest shaped brush and duplicate it into place</li>
<li>Shift+S: In a tool mode, but want to go back to selection? Shift+S hops you into the selection mode. CTRL Q releases your current selection.</li>
<li>Shift+X: Have a brush you need to split? Shift+X brings up the cut tool. Press again to cycle through modes.</li>
<li>Shift+V: Vertex editing; this should be your #1 used tool. Press again to cycle through modes.</li>
<li>CTRL C: Copy, duh! But use it with right click -&gt; Paste Special to duplicate large selections onto the original’s position.</li>
<li>[ and ]: Use these to quickly alter grid size.</li>
<li>CTRL B: Snap to grid!</li>
<li>SHIFT A: Bring up the texture applicator.</li>
<li>ALT ENTER: Brings up entity window.</li>
<li>SHIFT O: Overlays</li>
<li>CTRL+T ties to entity, usually func_detail. CTRL W will bring it back to world.</li>
<li>Shift when rotating takes you off 15 degree increments for fine tuning.</li>
<li>CTRL+M allows you to scale selections, rotate and more.</li>
</ul>
</blockquote>
<p style="padding-left: 30px;">5. Set up your displacements properly. A little vertex manipulation here will save you time down the road.<br />
6. Paint displacements face normal. Face normal is by default on the Z axis; alt+right click on a face or displacement vertex to shift the plane of displacement alteration. This will vastly speed up your displacement painting.<br />
7. Use viewgroups wisely. Turn off tool textures whenever you’re not working with them; likewise brush ents can often get in the way. Remove everything but world brushes when optimizing and func_detailing.<br />
8. When working with symmetrical maps, center an enormous skip brush around the center of your map; you can then duplicate pieces of one side and select the brush to rotate them cleanly to the correspondent area on the other half of the map. CTRL L flips horizontally for bilaterally symmetric maps.<br />
9. Make use of your fellow mappers’ tools! These can eliminate painful processes that take too long but have to be often done. Examples:</p>
<blockquote>
<ul>
<li><a href="http://forums.tf2maps.net/downloads.php?do=file&amp;id=865">Boojum’s Prefab pack and Gametype gallery.</a> The prefabs within can help you set up doors, spawns, CPs and other entity arrangements that would normally take some time to put together.</li>
<li><a href="http://forums.tf2maps.net/showthread.php?t=4872">Acegikmo’s environment gallery</a>. Allows you to quickly experiment with exterior lighting arrangements.</li>
<li><a href="http://forums.tf2maps.net/downloads.php?do=file&amp;id=1518">Ravidge’s lighting gallery.</a> Allows swift implementation of manmade lighting.</li>
</ul>
</blockquote>
<blockquote><p><a href="http://www.n00bunlimited.net/fps-mapping/1603-full-list-keyboard-shortcuts-hammer.html">Full List of Hammer Shortcuts</a></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.nodraw.net/2009/12/speed-mapping/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Optimization in Source: A Practical Demonstration</title>
		<link>http://www.nodraw.net/2009/12/optimization-in-source-a-practical-demonstration/</link>
		<comments>http://www.nodraw.net/2009/12/optimization-in-source-a-practical-demonstration/#comments</comments>
		<pubDate>Sun, 13 Dec 2009 19:38:59 +0000</pubDate>
		<dc:creator>MangyCarface</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[hint]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[source]]></category>
		<category><![CDATA[tf2]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[visibility]]></category>

		<guid isPermaLink="false">http://www.nodraw.net/?p=39</guid>
		<description><![CDATA[Optimization is one of the least understood parts of mapping in source; there is a lot of hearsay on the matter and generally the topic can appear overwhelming to new mappers. Today we’re going to discuss how optimization in source works, not from a theoretical approach, but from an example-by-example method that will hopefully bring [...]]]></description>
			<content:encoded><![CDATA[<p><span style="color: #993366;">Optimization </span>is one of the least understood parts of mapping in source; there is a lot of hearsay on the matter and generally the topic can appear overwhelming to new mappers. Today we’re going to discuss how optimization in source works, not from a theoretical approach, but from an example-by-example method that will hopefully bring us around to understanding the <em>underlying</em> theory. When implemented correctly, good optimization can be more beautiful than the aesthetics of a map itself.</p>
<p><span style="text-decoration: underline;">This tutorial assumes you have an intermediate understanding of using hammer and the terminology used for its processes.</span></p>
<h3>Part I: Visibility in Source</h3>
<p>For this exercise we will be considering the source game TF2, though these techniques will apply to source in general. Our players will consist of a brick <span style="color: #000000;">wall, an engineer representing the player, and a sentry representing the high-polygon props that end up creating framerate loss on our players’ end. Our goal today will be to instruct the engine not to draw the sentry when</span> it is indeed hidden by the<span style="color: #800000;"> brick wall.</span></p>
<p style="text-align: center;"><img class="size-full wp-image-40 aligncenter" src="http://www.nodraw.net/wp-content/uploads/2009/12/1.png" alt="1" width="640" height="421" /></p>
<p><span id="more-39"></span>We would assume that, when looking at th<span style="color: #000000;">e wall, the engineer’s GPU would not be rendering </span>the sentry. In source, not necessarily so! On compile, when vbsp is run, the engine makes imaginary <span style="color: #99cc00;"><em>cuts</em> </span>out of any open space to determine what players should render. Confused? Well, let’s look at the scene from above.</p>
<p style="text-align: center;"><img class="size-full wp-image-41 aligncenter" src="http://www.nodraw.net/wp-content/uploads/2009/12/2.png" alt="2" width="578" height="508" /></p>
<p>All entities are ignored in this “<span style="color: #99cc00;">cutting</span>”, which we call a “binary space partition.” Sound familiar? The initials, bsp, are found in our maps’ file type. Binary space partition sounds like a complicated phrase, but is easily illustrated by this example taken from Wikipedia:</p>
<p><img class="aligncenter size-full wp-image-42" src="http://www.nodraw.net/wp-content/uploads/2009/12/3.png" alt="3" width="628" height="268" /></p>
<p>The BSP process <span style="color: #99cc00;">cuts </span>the interior of your map into pieces, one by one, until each separate piece is no longer concave. Then, the visibility calculator (vvis.exe) imagines itself as each of these created pieces, and attempts to draw lines outwards to every other piece. If, from any position in one piece it has a line of sight to another, it considers that piece visible. Let’s look at it in context. Remember that <span style="color: #ff0000;">world brushes</span>, here drawn in <span style="color: #ff0000;">red</span>, make our square concave, so the engine will cut around it, in <span style="color: #99cc00;">green</span>:</p>
<p><img class="aligncenter size-full wp-image-43" src="http://www.nodraw.net/wp-content/uploads/2009/12/4.png" alt="4" width="529" height="474" /></p>
<p>Now let’s attempt to draw <strong><span style="color: #ffcc00;">lines </span></strong>from th<span style="color: #000000;">e engineer’s partition to the sentry’s part</span>ition.</p>
<p><img class="aligncenter size-full wp-image-44" src="http://www.nodraw.net/wp-content/uploads/2009/12/5.png" alt="5" width="282" height="242" /></p>
<p>As you can see, even from the deepest angle, we can’t draw a <strong><span style="color: #ffcc00;">line </span></strong>from<span style="color: #000000;"> the engy’s space to the sentry’s. Therefore, the engy won’t render the sentry! Hoor</span>ah!</p>
<p>But what if the engine had instead, arbitrarily, partitioned the scene starting across the <span style="color: #ff0000;">wall</span>&#8216;s longer sides, like this?:</p>
<p><img class="aligncenter size-full wp-image-45" src="http://www.nodraw.net/wp-content/uploads/2009/12/6.png" alt="6" width="278" height="246" /></p>
<p>As you can see, the created partitions are all convex and therefore valid, but look at this:</p>
<p><img class="aligncenter size-full wp-image-46" src="http://www.nodraw.net/wp-content/uploads/2009/12/7.png" alt="7" width="273" height="241" /></p>
<p>We can easily draw a line from the engy’s partition to the sentry’s, and so he would render it while looking at the wall! This is clearly incorrect, so how do we tell the engine to partition it like our first example, rather than this inferior second one? The answer lies within the tool texture, <span style="color: #993366;">Hint</span>. We use <span style="color: #993366;">hint </span>brushes to tell the BSP system- or rather, to hint to it- where it should perform its partitions first. A<span style="color: #993366;"> hint brush</span> is constructed by texturing a world brush entirely with <span style="color: #00ccff;">skip</span>, and then applying the<span style="color: #993366;"> <a href="http://developer.valvesoftware.com/wiki/File:Toolshint.gif"><span style="color: #993366;">hint</span></a></span><a href="http://developer.valvesoftware.com/wiki/File:Toolshint.gif"><span style="color: #993366;"> tool material</span></a> along the face where we want a cut made. Let’s quickly add <span style="color: #993366;">hints </span>to our example so that it partitions correctly. We want to place them so that those cuts along the wall’s skinny edges are made first.</p>
<p><img class="aligncenter size-full wp-image-47" src="http://www.nodraw.net/wp-content/uploads/2009/12/8.png" alt="8" width="470" height="454" /></p>
<p>This is now correctly hinted, and presuming our scene had<span style="color: #ff0000;"> four walls and a ceiling<span style="color: #000000;"> in addition to the </span>brick wall,</span> would be cut as in our first partition example. So what can we take from this?</p>
<h3>Part II: Optimization Structures</h3>
<p><span style="color: #993366;"><em><strong>Hints</strong></em></span></p>
<p>We will now go into a discussion of practical uses of hints. From here on out, we will be using cordons, marked in red, to represent the walls and ceilings surrounding our scene; red lines will represent <span style="color: #ff0000;">world brushes</span>, and purple represent the<span style="color: #993366;"> hint faces</span>; yellow lines will denote possible<span style="color: #ffcc00;"> lines of sight</span> out of any one partition.</p>
<p>Our scene was actually one of the simpler uses of the most basic structure of optimization- the <strong>T structure</strong>. The <strong>T structure</strong> is formed by a wall perpendicular to another wall, along whose front a<span style="color: #993366;"> hint brush</span> is placed. In hammer, the structure would look like so:</p>
<p><img class="aligncenter size-full wp-image-48" src="http://www.nodraw.net/wp-content/uploads/2009/12/9.png" alt="9" width="490" height="414" /></p>
<p>This is the simplest of optimization situations, and one that can be combined into many other derivative forms. The first of these derivatives is the <strong>H structure</strong>, which we’ve studied: A solitary wall bracketed by two <span style="color: #993366;">hint brushes</span>.</p>
<p><img class="aligncenter size-full wp-image-49" src="http://www.nodraw.net/wp-content/uploads/2009/12/10.png" alt="10" width="460" height="441" /></p>
<p>In this situation we’ve replaced one wall with a hint brush, so that players on each side of the hints can see down the hall, but those within the width of the wall cannot see the sentry.</p>
<p>We can combine this with a few<strong> T</strong>-like walls to create something more feasible:</p>
<p><img class="aligncenter size-full wp-image-50" src="http://www.nodraw.net/wp-content/uploads/2009/12/11.png" alt="11" width="556" height="455" /></p>
<p>We now have 4 <strong>Ts</strong> jutting out from our cordon walls to touch the hint brushes. This means that players in the halls can see both areas, but any players in the partitions behind any of the 3 walls on the engineer’s side cannot see into the sentry’s partition. We’ll call this shape the <strong>]-[ configuration.</strong></p>
<p>The next shape, the <strong>S shape</strong>, is created out of 2 individual<strong> Ts.</strong> It is frequently used within tunnels to prevent line of sight issues and help optimize in this fashion:</p>
<p><img class="aligncenter size-full wp-image-51" src="http://www.nodraw.net/wp-content/uploads/2009/12/12.png" alt="12" width="569" height="471" /></p>
<p>We’ve added another pair of engie and sentry to demonstrate the dual quality of this simple arrangement. The bottom engie cannot see either sentry, and the top engie can see 1 but not both.</p>
<p>We can add in a third<strong> T</strong> to create a more solid optimization corridor, in the <strong>W shape:</strong></p>
<p><img class="aligncenter size-full wp-image-52" src="http://www.nodraw.net/wp-content/uploads/2009/12/13.png" alt="13" width="616" height="424" /></p>
<p>This should look familiar, as the <strong>W</strong> is basically half of our <strong>]-[ shape</strong>, but designed to work with only a single path instead of two paths of travel.</p>
<p>If we rotate the <strong>W</strong> to be on a diagonal and then snap it to the grid, we come upon another oft-used optimization shape, one that is used in many corners. We’ll call it the <strong>L shape.</strong> First, we rotate our W:</p>
<p><img class="aligncenter size-full wp-image-53" src="http://www.nodraw.net/wp-content/uploads/2009/12/14.png" alt="14" width="365" height="304" /></p>
<p>Now we vertex manipulate it to come out with a more familiar pathway:</p>
<p><img class="aligncenter size-full wp-image-54" src="http://www.nodraw.net/wp-content/uploads/2009/12/15.png" alt="15" width="387" height="338" /></p>
<p>As you can see, we now have a right angle corridor, but even though our walls have changed shape the<strong> W’s</strong> optimization is still at work. Only players inside of the green triangle can see both areas. We can use the <strong>L shape</strong> in a variety of places. An easy example is the right-most corridor on 2fort as you enter the enemy base from the outside second-floor; it leads to their spawn room area.</p>
<p>It is important to note in all of these cases that we have been assuming a solid world brush ceiling. This will usually not be the case in your maps! But luckily, the<strong> T structure </strong>can be used in horizontal situations as well, and combined with all of the other shapes to form their ceiling. Only players below the horizontal hint will benefit from the vertical optimization shapes, so make sure that if players will be above the horizontal hint, it will only be shortly. A simple use:</p>
<p><img class="aligncenter size-full wp-image-55" src="http://www.nodraw.net/wp-content/uploads/2009/12/16.png" alt="16" width="632" height="301" /></p>
<p>Our<strong> T</strong> is still intact, perpendicular to the floor; in fact, in this position you can see where it derives its name. Let’s see it in combination with the <strong>W:</strong></p>
<p><img class="aligncenter size-full wp-image-56" src="http://www.nodraw.net/wp-content/uploads/2009/12/17.png" alt="17" width="477" height="305" /></p>
<p>So while there is no ceiling abutting our shorter walls, the <strong>T function</strong> of the horizontal hint allows the <strong>W</strong> to still work correctly. It is important to note that without a ceiling or horizontal hint, there is no telling how vbsp and vvis will interpret your optimization structure! If any of the partitions extends above the walls involved with the particular optimization structure, VVIS will be able to see down from the top of the partition into other partitions, and players in that first partition will therefore render objects otherwise hidden by walls.</p>
<h3>Part III: Examples of Hint Structures in Use</h3>
<p>We have now covered all of the basic optimization shapes that involve hints. Experiment with combining Ts into other new structures to complement your map design. <strong>OPTIMIZATION MUST BE CONSIDERED WHEN CONSTRUCTING A LAYOUT</strong>. These structures are simple but need to be in mind when laying out a map! Remember that any of these structures can be scaled to any size, and we will demonstrate macro uses of these micro shapes in this next section: real examples. I’ll be using mostly my own work to point it out; you may download them if you wish to see these in game. Our actors will be represented by <span style="color: #3366ff;">two blue circles</span>; in each scenario the circles will not render one another.</p>
<p><strong>Basic T:</strong></p>
<p>Here’s an example from Yukon’s CP1 area of a Basic T in action. This demonstrates how large a scale you can use it on, and how you can vary the thickness of the T’s trunk:</p>
<p><img class="aligncenter size-full wp-image-57" src="http://www.nodraw.net/wp-content/uploads/2009/12/18.png" alt="18" width="450" height="336" /></p>
<p><strong>Basic H:</strong></p>
<p>Again from Yukon, this is the upper transition from CP2 to CP3:</p>
<p><img class="aligncenter size-full wp-image-58" src="http://www.nodraw.net/wp-content/uploads/2009/12/19.png" alt="19" width="534" height="354" /></p>
<p>You can see how large you can expand these structures to be without interrupting function.</p>
<p><strong>S Shape:</strong> Atrophy, near B and A, we have an example of a larger S-shape. <span style="color: #3366ff;">Blue </span>cannot see one another, and <span style="color: #ff0000;">red </span>cannot see one another; additionally, the top left <span style="color: #3366ff;">blue </span>cannot see the bottom right <span style="color: #ff0000;">red</span>:</p>
<p><img class="aligncenter size-full wp-image-59" src="http://www.nodraw.net/wp-content/uploads/2009/12/20.png" alt="20" width="539" height="354" /></p>
<p><strong>W Shape:</strong> The <strong>W</strong> is one of my favorite; it can be implemented on an enormous scale like here in cp_atrophy, between B and C:</p>
<p><img class="aligncenter size-full wp-image-60" src="http://www.nodraw.net/wp-content/uploads/2009/12/21.png" alt="21" width="542" height="357" /></p>
<p><strong>L Shape:</strong> This is easy to implement in simple fashion, but very cool to use in a different manner like here in Yukon, in the alternate path between CP3 and CP2 (cliffs removed for visibility):</p>
<p><img class="aligncenter size-full wp-image-61" src="http://www.nodraw.net/wp-content/uploads/2009/12/22.png" alt="22" width="327" height="327" /></p>
<p>Here’s another even larger example in Atrophy between A and C:</p>
<p><img class="aligncenter size-full wp-image-62" src="http://www.nodraw.net/wp-content/uploads/2009/12/23.png" alt="23" width="537" height="536" /></p>
<p><strong>Vertical T:</strong> These are everywhere, but a simple example is in ctf_aurora, where a horizontal hint covers the entirety of the map and guarantees that players in the backyards cannot see those in the middle:</p>
<p><img class="aligncenter size-full wp-image-63" src="http://www.nodraw.net/wp-content/uploads/2009/12/24.png" alt="24" width="533" height="359" /></p>
<p>There are unlimited examples of such structures being twisted and used in every imaginable fashion, so keep an eye out! I couldn’t possibly cover each instance.</p>
<h3>Part IV: Other Optimization Brushes, a Primer</h3>
<p><span style="color: #00ffff;"><em><strong>Area Portals</strong></em></span></p>
<p>Now we will cover, in short, areaportals in their door function. <span style="color: #00ffff;">Area portals</span> are brush entities, completely covered in the <a href="http://developer.valvesoftware.com/wiki/File:Toolsareaportal.gif"><span style="color: #00ffff;">areaportal material</span></a> and tied to a<a href="http://developer.valvesoftware.com/wiki/Func_areaportal"> func_areaportal</a>. <span style="color: #00ffff;">Area portals</span> act like <span style="color: #ff0000;">world brushes </span>when closed, and like open space (with some restrictions) when open. We use <span style="color: #00ffff;">area portals </span>within doors to prevent players from drawing anything inside the doored area. However, the area behind the <span style="color: #00ffff;">area portal</span> must be its own ‘area’ in the sense that, other than through another <span style="color: #00ffff;">area porta</span>l, no VVIS lines (our <span style="color: #ffcc00;">yellow arrows</span>) can be drawn into a partition on the outside of the area. A simple way to test this is to start from any visible face of your <span style="color: #00ffff;">area portals</span> and try to navigate through empty space to another face of the same <span style="color: #00ffff;">area portal</span>. If you’re able to do so without entering <em>another </em><span style="color: #00ffff;">area porta</span><span style="color: #00ffff;">l</span>, you need to seal the area better! But if you cannot, then your area is well-sealed and ready for compile. Area portals throw leaks if not sealed correctly, and can be a pain to sort out, but that&#8217;s too indepth for our brief overview here. Let’s look at a simple case of using an<span style="color: #00ffff;"> area portal:</span></p>
<p><img class="aligncenter size-full wp-image-64" src="http://www.nodraw.net/wp-content/uploads/2009/12/25.png" alt="25" width="407" height="307" /></p>
<p>Here we have our original scenario, but with the wall extended to fit against our cordon bounds and a<a href="http://developer.valvesoftware.com/wiki/Func_door"> func_door</a> added right between our two actors. Remember that a door is an entity and therefore is excluded from the vbsp process; it cannot by itself block visibility. This is where the<span style="color: #00ffff;"> area portal</span> comes in: we place it within the door such that it is entirely enclosed and touching all 4 faces (3 brick, 1 floor) around the door. We then set its properties so:</p>
<p><img class="aligncenter size-full wp-image-65" src="http://www.nodraw.net/wp-content/uploads/2009/12/26.png" alt="26" width="586" height="427" /></p>
<p>If your door starts closed, as would ours, we also start the <span style="color: #00ffff;">area portal </span>as closed. We then set its linked door to be the name of our door. Now, when the door’s position is toggled, the<span style="color: #00ffff;"> area portal</span> will toggle between open and close: once the door is fully closed, our <span style="color: #00ffff;">area portal</span> will shut and act like a world brush and the engineer will stop rendering the sentry. These are best used with spawn doors and other doors that will only be open momentarily; this gives you a higher budget (budget in optimization terms is the amount of detail you can use without impacting framerates negatively) to work with, without using one of our <span style="color: #993366;">hint</span> structures (which tend to complicate areas) instead.</p>
<p><span style="color: #333399;"><em><strong>Occluders</strong></em></span></p>
<p>There is one final brush entity we need to know when optimizing (in TF2; other games use area portal windows, which we can explain at a different time.) This entity is called a<span style="color: #333399;"><a href="http://developer.valvesoftware.com/wiki/Func_occluder"> func_occluder</a>. </span>It acts as a curtain between you and props on its opposite side; each side of an <span style="color: #333399;">occluder </span>entity textured with the<a href="http://developer.valvesoftware.com/wiki/File:Toolsoccluder.gif"><span style="color: #800080;"> <span style="color: #333399;">occluder tool material</span></span></a><span style="color: #333399;"> </span>will prevent you from rendering any objects completely covered by that face. Let’s take a situation where we have a func_detail wall instead of a world brush wall. It’s ignored in visibility calculations, but we still want our player not to render the sentry. Here is our scenario:</p>
<p><img class="aligncenter size-full wp-image-66" src="http://www.nodraw.net/wp-content/uploads/2009/12/27.png" alt="27" width="546" height="454" /></p>
<p>In this case we don’t want players at the sentry’s position to render the engy either, so we’ll make an <span style="color: #333399;">occluder </span>with two faces textured with <span style="color: #333399;">Occluder</span>. Like a hint brush, its other faces will be <span style="color: #33cccc;">skip</span>. We create this brush either within the <span style="color: #ff0000;">wall </span>or exactly as big as the <span style="color: #ff0000;">wall</span>:</p>
<p><img class="aligncenter size-full wp-image-67" src="http://www.nodraw.net/wp-content/uploads/2009/12/28.png" alt="28" width="591" height="474" /></p>
<p>We’ve toggled off details in our visgroups so that we can see the <span style="color: #333399;">Occluder </span>here. Now, neither the sentry nor the engy, were they both players, would be able to render one another. <span style="color: #333399;">Occluders </span>sound great, but they’re not at always a good idea! It costs the client to calculate which props should be ignored, so be sure that each <span style="color: #333399;">occluder </span>prevents a large number of high poly props from being drawn to balance out the initial cost of calculation. Look to Gravelpit’s vmf for correct usage.</p>
<h3>Part V: Other Ways to Optimize</h3>
<p>This concludes our overview of brush-based optimization, but there are a few other ways to optimize we need to keep in mind. These are kind of like cheating, and you’ll only squeeze scant frames out of each, so be sure to use hints and all before you go through and do these:</p>
<ol>
<li><strong>Draw distances</strong>. You can assign fading properties to any props that will prevent them from being drawn at a certain distance away. This works best on small detail props, but beware that it costs the client to fade the prop, so they will only experience benefits when the prop is completely invisible.</li>
<li><a href="http://developer.valvesoftware.com/wiki/Func_lod"><strong>Func_lod.</strong></a> This is an entity that is exactly like a func_detail except that it has fade distances like props. Use these sparingly.</li>
<li><a href="http://developer.valvesoftware.com/wiki/Lightmap"><strong>Lightmap optimization</strong>.</a> Look it up elsewhere <img src='http://www.nodraw.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  Doesn’t offer any huge gains, but shrinks file size.</li>
<li><a href="http://developer.valvesoftware.com/wiki/Func_detail"><strong>Func_detail</strong>.</a> The less partitions created by vbsp, the shorter vvis takes and the less calculations your players have to perform within each partition. Use func_detail to reduce the complexity of your vbsp structure. To view the structure of your map, compile it and then go to Map-&gt;Load Portal File and choose the associated file. The blue lines are the cuts that have been made around each partition!</li>
<li><strong>Advanced area portal usage.</strong> Area portals have small performance benefits when placed in doorways correctly; again, find a different tutorial for this particular piece.</li>
<li><strong><a href="http://developer.valvesoftware.com/wiki/Env_fog_controller">Fog</a>. </strong>At the limits of your map’s fog distance, decided by your env_fog_controller, nothing more is rendered; if you’re aggressive with this distance, you can slightly reduce framerate loss. Not advised.</li>
<li><strong>Water. </strong>You can use cheap water instead of expensive water (I presume you know what these are)</li>
<li><strong>Displacement power. </strong>If you can reduce the power of your displacements (working with power 2 is pro!) by even 1 degree, you will drastically reduce the energy needed to render that particular face. Remember that power 4 represents 8x the number of vertexes in power 2, 2x power 3. Even going from power 3 to 2 reduces the number of vertices considerably.</li>
<li><a href="http://developer.valvesoftware.com/wiki/File:Toolsnodraw.gif"><strong>Nodraw.</strong> </a>The engine automatically deletes brush faces facing the void or completely covered by other brush faces, but there are often faces that do not satisfy these conditions that will never be seen by your players- usually the back faces of detail behind player clips. Applying the <strong><span style="color: #ffcc00;">nodraw </span></strong>material to these faces will remove them from the cost of rendering.</li>
</ol>
<h3>Part VI: Closing, Extra Links, and Glossary</h3>
<p>We have looked at a variety of ways to optimize your maps, but there are more details to be learned! Now that you have a basic knowledge, search the VDC and elsewhere for specifics on theory and indepth explanations of any of the aforementioned knowledge areas. I hope you are able to come out with the next great work, and one that will perform well on all machines! Look for combinations of what we&#8217;ve examined, and be clever; the more you press yourself to be creative in optimizing, the less of a chore it&#8217;ll feel- imagine it a challenge <img src='http://www.nodraw.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>LINKS:</p>
<ol>
<li><a href="http://developer.valvesoftware.com/wiki/Main_Page">VDC</a></li>
<li><a href="http://www.optimization.interlopers.net/index.php?chapter=intro">Great guide with more theory</a></li>
<li>Maps used in discussion:</li>
</ol>
<ul>
<li><a href="http://forums.tf2maps.net/showthread.php?t=10031">Atrophy</a></li>
<li>Yukon is included within TF2 as cp_yukon_final</li>
<li><a href="http://forums.tf2maps.net/showthread.php?t=7264">Aurora</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.nodraw.net/2009/12/optimization-in-source-a-practical-demonstration/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

