This shows you the differences between two versions of the page.

Link to this comparison view

performance [2017/05/24 14:27] (current)
Line 1: Line 1:
 +====== Performance Tutorial ======  ​
 +Game Version: ​ FS13 and later\\
 +GE Version: ​ ? and later
 +[[modding_tutorials|Modding Index]] | [[general_modding|General Modding Tutorials]]
 +===== Intro =====
 +Hey guys,
 +since I hear from people having problems with "Bad Allocation"​ or other performance problems again and again, I decided to create this performance tutorial.
 +===== Prep Work =====
 +In order to use this tutorial, you'll need some software (see below). I don't expand on the operation of each program as long as it's not needed explicitly for this tutorial. That would go beyond the constraints of this tutorial. So you should have at least basic knowledge, if you don't have it, get it first. The programs are al available for free, except Photoshop, but since there are people out there who are using Photoshops and that als works, it's also mentioned here. Paint.NET, GIMP and Photoshop are alternatives to eachother, means you need only one of these.
 +[color=#​0000FF]GE (Giants Editor)[/​color] -> Version 4.1.7 can be found in the "​sdk"​ folder in the installation directory (usually C:/Program Files/​Farming Simulator 2011). The current version 4.1.9 is available for download here (after free registration):​ [url=http://​gdn.giants-software.com/​index.php]Download Page[/url]
 +[color=#​0000FF]WTV (Windows Texture Viewer)[/​color] -> [url=http://​www.nvidia.de/​object/​windows_texture_viewer.html]Download Page[/url]
 +[color=#​0000FF]Paint.NET[/​color] -> [url=http://​www.getpaint.net/​]Download Page[/url]
 +[color=#​0000FF]GIMP[/​color] -> [url=http://​www.gimp.org/​]Download Page[/url]
 +[color=#​0000FF]DDS-Plugin für GIMP[/​color] (wwithout the Plugin GIMP can't handle DDS files) -> [url=http://​code.google.com/​p/​gimp-dds/​]Download Page[/url]
 +[color=#​0000FF]Photoshop-Plugin[/​color] -> [url=http://​www.nvidia.com/​content/​devzone/​index.html]Download Page[/url]
 +[color=#​0000FF]Notepad++[/​color] -> [url=http://​notepad-plus-plus.org/​]Download Page[/url]
 +===== Full Details =====
 +[size=14pt]The contents of this tutorial:​[/​size]
 +-What is DDS and why should you use DDS textures?
 +-With wich settings should DDS textures be saved?
 +-GE: saving lots of work converting textures
 +-WTV: how to check DDS textures
 +-Paint.NET, GIMP, Photoshop: The settings to save textures as DDS
 +-What Polys?
 +-What are ClipDistances and why should they be set properly
 +-ClipDistances:​ how to set them properly
 +-Tipps & Tricks: setting many ClipDistances in short time with Notepad++
 +-Other: what else is important for performance
 +I'll create this tutorial in several steps, because I also have a real life and I still want to share my knowledge as soon as possible. That also gives me the possibility to react to your feedback. I got all my knowledge by learning-by-doing and from Stefan Geiger, lead programmer from Giants. At this point a special thanks to Stefan Geiger for all the informations,​ without these I probably wouldn'​t know about this stuff till today.
 +When the tutorial is finnishd and I concidered your feedback I'll release also a PDF version which you can/​may/​should distribute wherever and whenever possible to share this, in my opinion, very important knowledge. Untill then you can link to this tutorial.
 +[size=14pt]-What is DDS and why should you use DDS textures?​[/​size]
 +DDS is the abbreviation for Direct Draw Surface and was created by Microsoft especially to optimize textures.
 +The main advantage if DDS ist the low memory usage on the graphics card (hereinafter called VRAM). Compared to PNG and JPG a DDS texture only needs 1/8 VRAM for the same resolution. Since memory is limited, it shouldn'​t be hard to imagine, how good these savings are. Especially because the quality is the same.
 +Another advantage is the much higher loading speed of DDS textures. PNG and JPG are highly compressed formats. These need to be decompressed,​ before the graphics card can use them. DDS textures can also be compressed, bit they don't need to be decompressed,​ thus these are loaded about 8-10 times faster. Primarily for maps it's distinctly noticeable.
 +Additionally,​ because of the much lower VRAM usage the commonly know Bad Allocation crash prevented as far as possible. Bad Allocation appears when the usable memory of the game is full (2GB default, after using CFF-Explorer it's 3GB for a 32bit OS and 4GB for a 64bit OS). With a much lower memory usage it lasts logically much longer, before the usable memory is full and the game crashes.
 +[size=14pt]-With wich settings should DDS textures be saved?​[/​size]
 +Let's go on with the settings. DDS isn't equal DDS, there are big differences in settings.
 +Programs like Paint.NET and GIMP provides much different settings. Most of them are irrelevant, so here just the relevant settings (texture examples given in the WTV part):
 +[color=#​0000FF]DXT1[/​color]:​ This compression should be used when the texture has no transparent pixels. For converting JPG textures you always have to use DXT1, since JPG doesn'​t support transparency. For converting PNG or resaving DDS you have to check the texture for transparency first. DXT1 uses fewest memory of all, so you should use DXT1 whenever possible.
 +[color=#​0000FF]DXT3[/​color]:​ This is used for textures with binary transparency. That means, the pixels of a texture are either completely transparent or not. For saving the alpha channel (alpha is the transparency in a picture) extra memory is needed. Hence DXT3 needs twice of the memory DXT1 needs.
 +[color=#​0000FF]DXT5[/​color]:​ This compression is used for textures with multilevel transparency. That means, when the pixels of a texture are partly transparent. That's often used for window- and particle-textures. DXT5 needs just as much memory as DXT3.
 +[color=#​0000FF]the resolution[/​color]:​ The resolution for textures is very important. Only edge lengths with 2^n (power of 2) are allowed. To be more specific, all values from 2^2 to 2^11, in numbers that are 4, 8, 16, 32, 64, 128, 256, 512, 1024 and 2048. A texture doesn'​t have to be square, it can also be rectangular. E.g. not only 256*256, but also 256*64, or 256*1024, or 2048*512, just to name a few examples. Reason is the divisibility by 2. Furthermore some AMD/ATI graphics cards have problems with textures, that doesn'​t match there resolutions.
 +As well textures shouldn'​t be unnecessary big. E.g. unicolored textures should have 4*4pixel resolution. May sound natural, but it seems not to be. I've seen unicolored PNG textures with 2048*2048 resolution more then once. That's 16MB unnecessary VRAM usage instead of just a few bytes. As a general rule: the more details a texture have, the bigger may the resolution be. If the whole texture of a vehicle/​machine is in one texture (btw: that's called UV-map) in most cases you can use edge lengths of 2048 without bothering about it. For wheels 512 or 1024 is enough. Just go a little by touch which resolution is reasonable.
 +[color=#​0000FF]Mipmaps[/​color]:​ You can generate them automatically when saving textures. All textures should have mipmaps, except HUD textures. HUD textures are the ones, that are only shouwn on the screen and not rendered on 3D objects. Examples for HUD textures are the shop pictures, map preview pictures and PDA maps. A little disadvantage of mipmaps is the by 1/3 higher memory usage (compared to without mipmaps). But this disadvantage is just that small that you can ignore it, especially because compared to a PNG/JPG texture a DDS texture with DXT1 and mipmaps just uses 1/6 of VRAM and DXT3/DXT5 still just 1/3. The advantage of mipmaps is that they increase the quality and the performance. That's because of the different resolutions of the texture which are saved in the texture file. Here the divisibility by 2 is important, from 4 pixels (2*2) one pixel for the next smaller mipmap is generated. The graphics card is looking for the mipmap which resolution fits best to the resolution with which an object is rendered on the screen. E.g. you have a texture of 1024*1024 resolution with mipmaps, the object it's rendered on uses 256*256pixels on the screen, so the graphics card only needs the 256*256 mipmap. That's just 1/16 of the memory bandwith which is used compared to the whole resolution. That results in a much better performance,​ because for each frame that's rendered much less of the (limited) bandwith  is needed.
 +Another advantage of the mipmaps is located in the hardware profiles of FS. On low and medium the highest mipmap is left out. So if you have a texture with 1024*1024 resolution, only the mipmpas with 512*512 and lower are used. That results in 75% less VRAM usage for the textures. Especially for old graphic cards with not that much VRAM it's a real advantage, also good for the performance on low-end grpahic cards with a low memory bandwith. Of course, that results in less details, but I thing a good performance is much better/ more important then many details and a completely stuttering game.
 +At this point I want to point out towards FS13 or which the textures needs to be in correct resolution and correct DDS format. If these are not correct you'll get compatibility- or performance-warnings. Some of you already may have seen these while using the new GE 5.0.1.
 +[size=14pt]-GE:​ saving lots of work converting textures[/​size]
 +Now you know what DDS is, why you should save textures as DDS and which settings you should use. But before converting all the textures you should clean up the map. At an average map there are lots of files/​textures which aren't used and I guess nobody want's to spend much time to convert textures which aren't used anyway. It also works for regular mods, but since these don't have that many unnecessary files it isn't that important to clean them up first and it's also costlier as for maps.
 +Don't worry, you don't have to check all files manually. The GE has a very usefull function for cleaning up. It's in the "​File"​-menu and called "​Export All with Files"​. But befor using this function you should prepare two little things:
 +1. You have to check the paths in the i3d file. Sounds more difficult as it is. Background: the export function can't handle backslashes (\), which are often used for Sketchup models. Therefore you have to open the i3d file with Notepad++, click in the menu on "​search"​ and then on "​replace"​. Or just use the shortcut CTRL + H. At "​search for" you type in the backslash and at "​replace with" the normal slash (/). Now a click on "​replace all" and you're done. If the appearing message says that there is nothing replaced, this step wasn't necessary, but when there are some backslashes replaced you can be very happy, because it saves you a lot of trouble. If you forgot it and there were some backslashes you would have to check some or maybe many files and copy them manually.
 +2. You have to create a new, empty folder, because the export function needs one to export the map to. Where this folder is located doesn'​t really matters, but it's recommended to create this folder at the same location where the source map is. Name for that folder also doesn'​t matter, but it's recommended to use a resonable name to find it back/know what it is for. I always use the same name as the source map and add an underscore (_) at the end. Thereby it's easy to diffenretiate both and you still know which map it is.
 +Now you can use the "​Export All with Files" function. Open the map with the GE and apply the function. As destination you choose the new created folder, as name the same name as the source i3d which is in very most cases "​map01"​. Depending on the amount of files and their sizes it takes a while. As soon as everything is exported the status at the lower left changes to "​ready"​.
 +If you don't have the Scripting Window open, you should open it now (located at "​Window -> Scripting"​). Sometimes some copying errors are shown here, but in most cases these are of no importance. Just do a short check if the file exists in the destination folder, if yes, you can ignore these error. If the file doesn'​t exist you have to copy that one manually. If the file already doesn'​t exist in the source folder you should write the modder a message and ask him for a fixed version. Or just let the map go, if there are already files missing, there will be probably other errors.
 +Now the map01.i3d and all needed textures/​files are in the new created folder. In order to get the map working you need to copy a few files manually, which are not listed in the i3d file, but still needed for the map. That are following files:
 +SampleModMap.lua (could have another name, e.g. the name of the map)
 +SampleModMap.xml (could have another name, e.g. the name of the map)
 +defaultVehicles.xml (could have another name, e.g. Vehicles.xml)
 +sampleModMap_briefing3.dds (all three could have another name, e.g. <​mapname>​_briefingX.dds,​ could also be JPG/PNG files, then you have to convert them. These are btw the three preview pictures shown while loading the map)
 +Now you should do a short test, therefor you have to copy the map to your mods folder. For this test it doesn'​t matter if you put it there as a ZIP or just the folder. You should do this test, because in some cases there are still some files missing. If the map normally loads, you're ready. If not you should check the LOG file and compare it with the LOG file from the source version. With this comparison you can find the missing files, because each i3d file which is loaded makes an entry in the LOG file. Just check which file isn't loaded in the clean version and copy it with all textures needed from the source to the clean version. In most cases some particleSystems are missing.
 +[size=14pt]-WTV:​ how to check DDS textures[/​size]
 +Now you have a clean map without unnecessary files. Before I come to the converting part I want to explain the WTV. Since DDS isn't equal DDS, like I already told, you need a tool to check existing DDS files for their settings. Therefor only one tool exists: the WTV. This is a very fast software and you don't even have to install it. You also don't have to open every texture by yourself, just use the scrollwheel from your mouse to scroll trough all DDS textures in that folder. I use the WTV as default viewer for DDS textures and I can only recommend it to anyone. This is what the WTV looks like:
 +The first marker shows the format/​compression. If this shows anything else as DXT1, DXT3 or DXT5, you definitely have to convert/​resave the texture.
 +The second marker shows the resolution. If any other resolution is shown as the allowed ones, you have ro resize the texture.
 +The third marker shows the mipmaps. If this value is "​1/​1"​ and it's not a HUD texture, you have to resave the texture, if it is "​1/​x"​ and it's a HUD texture, you have to resave it.
 +Here some DXT1 examples:
 +Here some DXT3 examples:
 +As you can see, there is a bright pink color in the background. This is the default background color. You can change it, but it's not recommended,​ since pink normally isn't used for textures. So with this bright pink color you can easily detect transparency in a texture, because pink indicates transparency. Btw the third picture shows an example for a HUD texture. As you can see, the value for mipmaps is "​1/​1"​ which means that no mipmaps are created/​generated.
 +Note: If a texture has a wrong resolution, in some cases some transparent stripes are shown, which are not really present. In this case you should check when resizing whether there really exist transparent pixels or not. As already mentioned, use DXT1 whenever possible. Here an example for such a texture with wrong resolution:
 +Then there are some textures which have some transparent pixels, but nevertheless should be saved as DXT1. In that case the modder didn't work completely proper and used a transparent background while creating the texture, or forgot to make the background black when he finished the texture. Here an example for such a texture: ​
 +Here some DXT5 examples:
 +As you can see, the pink color is not as bright as at the DXT3 examples. These are pixels which are just partly transparent,​ also called multilevel transparency. In some cases it's hard to recognise this multilevel transparency. In these cases it's easier to use Paint.NET or GIMP to check these textures. If you're not sure, you should use DXT5 instead of DXT3. For memory usage it doesn'​t make a difference and you play it safe.
 +At his point an [color=#​ff0000][size=14pt]important note[/​size][/​color]:​ The PNG files in the folder "​map01"​ which has "​weight"​ in their filename has to be PNG files. Otherwise you'll get errors and the map won't work anymore. The same for the "​textures"​ folder, all textures with "​distance"​ in their filename has to be PNG files, all others should be DDS files.
 +Sequel in this post: [url=http://​www.fs-uk.com/​forum/​index.php?​topic=123400.msg807787#​msg807787]http://​www.fs-uk.com/​forum/​index.php?​topic=123400.msg807787#​msg807787[/​url]
 +Original Author: ​ bassaddict | Date:  November 02, 2012
 +        ​
 +[[modding_tutorials|Modding Index]] | [[general_modding|General Modding Tutorials]]