Source Filmmaker

Source Filmmaker

26 avaliações
How to Reduce Memory Usage
Por Anyar
How you can avoid hitting SFM's memory limit and crashing.
   
Premiar
+ favoritos
Nos favoritos
- favoritos
Intro
In the bottom right of the corner, you'll see the text "Mem: 800 MB" or some other number. When you hit around 2600 MB, it turns red, and when it reaches somewhere around 3200 MB, the program crashes. Why?

Due to its 32-bit architecture, SFM can only use 4 GB of RAM, regardless of how much you have installed. In practice, SFM crashes immediately after reaching somewhere around 3200 MB.
Technical Details
SFM's memory usage increases when you load textures into a session/project.

To see this happen in real time, open the model viewer and start scrolling through models. You'll see the memory usage go up and up and up.

Textures are used by maps, models and their skins, particles, light gobos, etc. Loading these will all increase your memory usage.

Once you've loaded a texture, you don't have to load it again. Meaning that copying the same model a dozen times will not increase memory usage (but it will increase filesize!).
Remove Assets
This is the most obvious solution. Remove unused models, particles, and gobo lights from your session.

This does not immediately update the memory usage number, but trust that it will help.
Reuse Assets
If possible, prefer to reuse existing assets in the project, since this doesn't affect memory usage.

For example, instead of using player\soldier.mdl, hwm\soldier.mdl, and workshop\enhanced_soldier.mdl in the same session, just choose one and use it everywhere.
Console Commands
There's a couple commands I know which may help reduce current memory usage.

mat_reloadallmaterials will reload all the materials (wow), including removing unused materials from memory.

mat_bumpmap 0 also reduces memory, though I don't know how it works.

Some people may suggest flush, but others say it crashes SFM. I've never tried it.
Note on Texture Filesize
Texture files come in different sizes. Many workshop assets are unoptimized, and you generally do not want to load, say, 4k textures in your S1FM session. The texture files that I have range from a few KB to nearly 90 MB in filesize, and that adds up.

Of course, prioritize the big texture files. It's a waste of time to remove 4 KB textures from your project; that pixelated soda can model probably isn't the cause of your issues. But stuff like terrain models and skydomes can be pretty influential.

To find out which textures are used by a model, right click -> Add Override Materials. In Element Viewer, expand materials and check the mtlname for each material listed. That'll point you to the .VMT files, which are usually named the same as the .VTF files, but if not you can just open the .VMT file and check the $basetexture value.

The $basetexture is what tells you the .VTF file being used. Those files are the actual textures you care about. You'll need VTFEdit (or VTFEdit Reloaded) to view them.
Maps
You can see how much memory a map uses by creating a new session and loading a map, and seeing the difference.

For reference, scenebuild_hugevoid increases my memory usage by about 700 MB.

Some workshop maps are badly optimized. You can reach out to the map creators to see if they can help, or you can use Hammer and do some fancy stuff that I sadly don't know anything about. At least it helps you narrow down your problem though.
Shrink Textures
If a texture file is too big, the obvious solution is to reduce its filesize by making it lower resolution.

Make sure you have VTFEdit or its unofficial successor, VTFEdit Reloaded.

Open the file. Export it in some other image format (I usually use TGA) and open that image in your image editor of choice, like GIMP or Photoshop.

Reduce the image resolution. You could just scale it down some.

Export the image from your image editor, then import that image into VTFEdit.

Save it as a VTF file. You probably don't want to overwrite your original VTF file.

Go to SFM again. Find your model, right click -> Add Override Materials. Go to Element Viewer, expand materials, expand again, and do right click -> Add Attribute -> string -> $basetexture.

This will turn the material into pink and black checkerboards; don't worry! You'll input the relative filepath to your VTF file here, excluding the file extension and everything up to the materials folder, and the new material should show immediately.

For example, if my VTF file is called cape_white.vtf located in C:\Program Files (x86)\Steam\steamapps\common\SourceFilmmaker\game\workshop\materials\models\batman\cape, then $basetexture = models\batman\cape\cape_white.

If you change your material file and want to reload it, use mat_reloadallmaterials.
Remove Skins
Remember, when you load a model, you also load the textures for all of its skins. And some models have a lot of skins.

For example, the Dishonored skydomes recommended in the Ultimate Scenebuilding Course have 21 skins, each at least 21 MB. In total it increases your memory usage by over 600 MB! This is frankly unacceptable for a program that crashes around 3200 MB.

So, I'll teach you how to remove a model's skins.

Download Crowbar.

Open it, go to the Decompile tab and find your model, the .MDL file. You may want to make a backup since the following steps will overwrite it.

(To find the model name, add override materials and check the modelName property.)

Decompile it with default settings.

Open the .QC file in any text editor. Remove the $texturegroup property completely.

Compile it again. This will replace the model with one that doesn't have skins, which means it will use less memory.

To change the texture now that the skins are gone, use $basetexture.
Edit Search Paths
I'm not 100% sure if this helps with memory usage, but it's here just in case it does. It helps prevent certain crashes anyways. The goal here is to just have SFM ignore or remove files that you aren't planning to use anymore.

Launch SFM as SDK (you'll have this option when you launch from within the Steam client).

Under Mod, click Edit Search Paths For Selected Mod. Uncheck everything that you aren't using. Similarly, uninstall any DLC that you aren't using. It's just good practice.

You can also do this by editing your gameinfo.txt.
Start a new session
Inevitably, at some point in your project's life, it will become too big. Your memory usage will be red as soon as you load the project, and you're already moments away from crashing.

This is natural, and people deal with this by simply creating a new session to continue their project. For example, I believe some of The Winglet's biggest projects were split into three or four parts. The more you work on one session, the more bloated it becomes, and you will need to create a new one eventually.
Upgrade
Move to S2FM. No more memory limit!
Myths
A certain Steam discussion from 2014 recommends installing the program LargeAddressAware to increase the RAM that SFM can use. I've been told that this does not work; if it did, everyone would be using it already.

Also, if you're experiencing low FPS, this guide probably isn't that helpful. Explore other options, such as turning off ambient occlusion and reducing the duration of your project.
What else?
Have I missed anything? Leave a comment; I'll read it and update the guide if necessary.

Thanks to people in the SFM Discord for helping me figure this stuff out.
1 comentário(s)
cerulean 7 de dez. às 2:31 
"VideoConfig"
{
"setting.cpu_level" "1"
"setting.gpu_level" "1"
"setting.mat_antialias" "0"
"setting.mat_aaquality" "1"
"setting.mat_forceaniso" "16"
"setting.mat_vsync" "1"
"setting.mat_triplebuffered" "1"
"setting.mat_grain_scale_override" "-1.0"
"setting.mat_monitorgamma" "2.200000"
"setting.gpu_mem_level" "3"
"setting.mem_level" "3"
"setting.mat_queue_mode" "0"
"setting.r_screen_size_expansion" "0"
"setting.r_ssao" "0"
"setting.defaultres" "1920"
"setting.defaultresheight" "1080"
"setting.aspectratiomode" "1"
"setting.fullscreen" "0"
"setting.nowindowborder" "0"
}