An account is required to edit the wiki.

Avatar Optimization Tutorial

From VRWiki
Jump to navigation Jump to search

Introduction

This is the sister page to Avatar Optimization which teaches you mostly how and why to optimize. This one should actually lead you through the process in an easier to follow way. There's also Booth Optimization example which may be fixed one day if I find the images. It's hard to follow though.

Goals are to make a set of digestible tutorials on how to perform optimization tasks. Read the other page first for a background.

This page will also cover any optimization tools I've tested or am aware of.

Where do I even start?

Optimize down to what you need. For smaller instances, just throw a few auto tools at it. For larger instances or dance/etc events, pare it down to run fast. The performance tiers aren't that bad of a guide (see below), and a quick rule of thumb is 'stay out of very poor in every category except polygons'.

Try the quick list below if you're new to all this. Read the other page first, if you want to develop a greater understanding, and get some basic blender usage in, which is also shown in Avatar Hypertutorial, although I do plan on adding some generic blender basic guidance.

Keep in mind that even if you're still in very poor your avatar can still get worse. It's all too easy to be stuck in very poor due to something hard to fix (like polygons, thanks booth) and 'give up' on the rest. This is the worst thing you can do because bad stats all compound on each other to make it even worse.

(below) Statistically. If you take 1000 random avatars and hit them with the ranking tiers, they won't be THAT bad at sorting them. For the very poor rant, check the other article.

Quick Wins (all unity only)

tl;dr checklist in roughly the order of priority of what helps the most with the least effort:

  • Run the AAO's optimizer tool. (or just D4rks if your polygon count is fine) It should always be used, especially on MA/unity only setups.
  • Having less things on that upload of the avatar here
  • Go through your Textures with Thyr's Tool and reduce the resolution of your textures. here
  • Reduce animator controller stuff to an absolute minimum - IE toggles and stuff. Use VRCFury when you can since it optimizes toggles for you. here
  • Use Prefabulous tool or AAO's blend-shape remove on unused mesh (IE blendshapes that hide body mesh) here
  • Meshia Mesh Simplification can be used to decimate mesh (say, shoes) to bap down the polygon count without touching blender. here
  • Adding extra root bones in unity to merge physbone components
  • Removing fancy shader effects like fur, transparent grab passes, etc

More In depth

Don't forget to also do the quick win stuff where relevant. Effort is going to be reasonably high for all of these:

  • Merge physbones by adding a root bone in blender and moving components.
  • Edge Loop Dissolve needed mesh to reduce polygon count.
  • Removing/merging/decimating mesh in blender
  • Merging bones together (blender)
  • Merging materials manually (I don't recommend most auto tools for merging materials/textures together since they aren't context aware.)
  • Pulling FBXes out of your modular avatar stack, optimizing them, then pushing them back together in MA.
  • Not using Modular Avatar. Building the avatar together in blender gives you far more power over trimming and optimizing.

How important is X?

Different stats of the avatar affect different compute resources. Read Avatar Optimization to get a better understanding overall; but the take-away message is that just each bad stat makes the others worse too. They work with each other to make rendering harder, and just one bad stat is better than 2, 3, 4 or even more bad stats all at the same time. Some stats are worse than others, too.

Overall though, Draw calls, CPU Usage and VRAM Usage are the primary targets. Get those meshes and materials down, get those animator controllers trimmed, and lower the resolution of your textures/trim unused blendshapes. Reducing polygons is good but should be done as a lower priority, since the other stats are more painful overall.

Starting

Tool or not to tool? Use tools if you can. I will link to tools and their tutorials and what they do here, but expect stuff here to be mostly manual.

Tool:

  • Usually non destructive (Everything applied on testing/upload.. over and over again..)
  • Usually quicker
  • Can't do a lot of important things.
  • If it doesn't work you're fucked.
  • If it doesn't support your setup you're fucked.
  • If you need to do something they don't do, you're fucked.

Manual:

  • Often destructive (Quicker in unity, but will need to work on versioning/duplicates more.)
  • Kinda slow usually
  • Works on everything.
  • Will always work.
  • Can do everything.

Overall I recommend a pragmatic approach - Use tools where you can but don't be locked into them. (Insert tangent on Modular Avatar here). Tools that can be slotted into any workflow are the best ones. (EG D4rk's, VRCFury, etc.)

Blender.

If you are COMPLETELY new to blender, you'll want to check out the Avatar Hypertutorial for 'load stuff into blender'. The basics of how to set up a model for editing will be needed. I recorded some footage of me loading up a militina that may make it here to establish a baseline, but getting that done is time and effort.

Removing stuff you don't need for that avatar

Greatest win will be simply removing stuff you don't need. If you NEVER need it, just remove it straight up. If you just want it removed for that avatar like it's an event avatar, make a duplicate. We're talking stuff like the clothing came with two pairs of shoes and you just want one. Simple removals at first. Something to keep in mind for things like D4rk's (or AAO) is that if there is a toggle for it, it won't get pruned.

In Unity - Quick

Give yourself about an hour to do this.

When to use:

When there are unused parts of your avatar that you NEVER use. Also if you need a streamlined optimized version where you make a copy with a little as possible on it, say for big events like new years.

What:

It's just removing things from the avatar. With the idea of 'optimizing to what you need', consider if you really need more than one outfit for a streamlined event/avatar. Or boob sliders, or multiple hair options, etc. The idea is to bake the avatar down (in less than an hour!) to something much cleaner.

How:

  • Duplicate your avatar and menu and animator controller
  • Delete mesh, toggles, animator controller layers, and such to greatly reduce the fluff on the avatar.
  • Upload under a separate ID and use it when performance is needed.

Note that if it's just game objects you want to remove, AAO has components that remove game objects on build time. I do not believe that it also trims or optimizes animator controllers, but if it does and I find out I'll update this section.

Guide:

  • Duplicate

Avatar_Optimization_Tutorial#Duplicate

  • Remove unused Mesh items

Avatar_Optimization_Tutorial#Destructive_-_Manual_-_Unity

  • Remove/remake animator controller toggle stuff

Avatar_Optimization_Tutorial#Animator_Controller_Layers

  • Upload under a different pipeline ID

Before uploading remember to make sure the pipeline ID is different/removed. You'll overwrite the original on VRC's servers elsewise - not a big issue if you have the local copy... but...

In Blender

Same as above but in blender, then moving it to unity. The pipeline is more work but you will get much better results.

Everything

Stuff here is 'all in one' optimizers, or tools. D4rks is not here because it is NOT an all in one optimizer.

Probinas' "Avatar Weight Reduction Prefab"

tl;dr: If you have one of the following Avatars you can slap on this prefab to skip a load of work:

  • "Shinano" Ver1.02
  • -Chocolat- Ver1.02
  • Sio / Shio / ver.2.01
  • -Rinasciita- Ver1.01
  • Lumina – LUMINA Ver1.07
  • "vio Stellar" Ver 1.04
  • Lurie- Ver1.02
  • Saffy-Sappy- Ver2.0.5
  • "Manuka" Ver1.02
  • Kipfel Ver1.2.0

If you don't - You're shit out of luck. Open blender.

Polygon Count

VRC's performance ranks are not very good. However, booths nowadays are way too polygon heavy and can be trimmed down with little cost to looks. Keep in mind this is most usually not the most cost-benefit optimization. However, getting a booth that is OUT OF THE BOX like 170k polygons down to 70k is not going to be possible without removing polygons.

Tools like D4rks and AAO and other unity only tools are very blunt-force rough tools that work fine for bulk removal of mesh, but for carefully tuning polygon counts down they aren't enough. Mesh manipulation is the core strength of blender, and the core weakness of unity.

Manual - Edge Loop Dissolve

The most powerful, if the most tedious technique. The idea here is to dissolve extra edges in your mesh.

--->

When to use: Use when the mesh cannot be removed (You want it, it's not under anything else, it's actually used, etc) but it needs to be lower polygon without damaging the topology (much). Much better results than decimation. Absolutely needed to get modern booths down below 70k. You will want to use this on your base that you build outfits and other things on top of.

Downside is that it's time intensive. Is it worth the effort? Well if the outfit you want is 150k tris by itself out the box then yes. Or there's some easy stuff to dissolve like inside the head. Or you look at the topology in blender and you're just stunned by the tri density.

What: An edge loop is a loop of edges. There's a function in blender called edge dissolve that removes the edges without ruining the topology (much) or UVs, or weighting, or blendshapes (in Blender 3.6 and above). It is technically destructive but it's a gentle kind where the underlying structure is preserved.

How:

  1. In edit mode, select an edge with alt-click to select the entire line of edges.
  2. Go along the mesh and select alternate loops or chains of edges. (Don't forget about select mirror on mirrored meshes)
  3. Press x -> Edge Dissolve.
  4. Inspect to see if you broke anything (Like UVs)
  5. Repeat. Over and over.

Video(s):

The video below shows me doing it to the Militina tail. It goes from 1700 to 802 polygons.

https://files.catbox.moe/e1aa1b.mp4

Tools

These tools help remove polygons from avatars at the end of your workflow. They do not replace edge loop dissolving, but they do replace deleting mesh in blender. Deleting at the end of a workflow is objectively superior since it is far less work.

When to use:

Almost every single upload. If there's ever mesh hidden under clothing, you will want to remove those polygons on upload.

What:

  • AAO (https://vpm.anatawa12.com/avatar-optimizer/en/docs/tutorial/basic-usage/)
    • AAO Can remove polygons by blendshape, by 3d box, and also by bone and mesh object, it's probably the most powerful in-unity polygon removal tool at the moment. Note: may not work with d4rks. (Some combinations of versions have problems together, if you have any, try just AAO)
  • Meshia Mesh Simplification (decimation in Unity)
  • Prefabulous Avatar (remove tris affected by X blendshape)

How:

Removing by Blendshape, 3d Box, bone or Mesh Object (Unity)

AAO:

  1. Go to the mesh object you wish to remove polygons from.
  2. Add a new component, and search for AAO. Find the one that is the method you want. Usually, blendshape delete is the first to try.
  3. Tick the 'preview' button, and then start ticking blendshapes that would usually just hide mesh under the clothing (for example, elbows under sleeves, feet under shoes, etc.), or shapes that hide features you don't use (like extra ears). Or for box select, move the box, for bone, select the bone, for mesh object, select the mesh object.
  4. Tick them until you've got all the ones that hide your mesh.
  5. AAO on upload will remove these polygons. This does mean the 'performance preview' in the SDK is complete nonsense now so you have to go to VRC to check it. And again, it does not work with D4rks. You will have to use AAO's general optimizer instead.

For more Guidance, check the Avatar_Optimization_Tutorial#References section and read the creator's usage guides.


Removal with Meshia

I haven't used this one, but this is 'decimation in unity'. Only recommended for low importance high polygon objects such as shoes, jewellery, etc, stuff that is out of the way of the head area but kinda too high poly.

See tool section (Avatar_Optimization_Tutorial#References below) for guidance

Mesh Objects

Mesh objects cause extra drawcalls. GPUs render mesh packaged up as mesh objects. Each mesh object is entire cycle of read mesh, texture mesh, add effects, then output render. This is a drawcall, more or less. By reducing the number of mesh objects, and therefore draw calls, GPUs spend much less time rendering.

Non Destructive - Tools - D4rks, AAO

When to use: When it's better than nothing. Ideally never, but if you do have lots of unused objects on your avatar, tools can trim/merge them automatically. In case you forgot what you weren't using, or have some unholy unity abomination crafted by the most satanic of japanese unitysmiths.

What: For unused mesh objects, both D4rks and AAO remove unused mesh objects. For the blender -> unity pipeline, the very concept of having unused mesh objects to delete is weird. Note that a mesh object is a logical entity within a 3d model that should be considered 'a collection of mesh' rather than being mesh itself.

How both these tools do it is they check animations in animator controllers (VRCFury compatibility unknown) possibly at runtime and then for any mesh not in an animation or referenced anywhere else, remove it or merge it.

How:

  • Install and run. For more detail read their documentation. Both AAO and d4rks do the same thing and you only need one - I recommend trying d4rk's first.

Non Destructive - Manual - Blender

When to use: As a mandatory part of any avatar creation. When you know you don't want the object. Or you only want part of the object. Or you want to mix and match parts of different objects. Or you know you want the object. Basically when you make an avatar.

What: Blender has the ultimate mesh modification tools. You can merge everything into one mesh if you really wanted. Or mix and match, or anything. A mesh object in blender is the separate 'mesh' things in the hierarchy. The 'mesh objects' image on this page shows the blender layout. The Armature is the bone structure, and each orange triangle is a different mesh object. Most booths come with them all separate for use in unity toggles. The example here is a lot of objects and is like loading a lag bomb if everything is on at once.

Mesh objects - Anything more than 4 is a lot.

How:

(Under development)

  • Object Merging - Select two (or more) mesh objects at once in the scene collection (ctrl or shift click), then press ctrl-j. (Note: Where your mouse cursor is changes what hotkeys do.)
    • (Unmerging: Select the mesh (not object, the actual mesh in the edit mode window) and press p.)
  • Object deletion - Select a mesh object in the scene collection, and press delete.

Destructive - Manual - Unity

When to use:

As part of removing stuff you don't use. More performance you want the more stuff you remove. You do this whenever there are things you don't want. You also do this when you want to pare down an avatar down to a more performant state, quickly.

What:

It is deleting things. Usually on a duplicate to create a nicer version, but you could consider modifying the prefab for day-to-day removals.

How:

  • Work on an unpacked duplicate - this will break prefabs elsewise.
  • Select items in the hierarchy and delete them.
  • For mesh you delete, also delete the bones and physbones for them.
  • Also delete the toggles for them (in the duplicate), and bake the state you want by setting it. More guidance is in the other section (TODO OTHER SECTION)
  • Make sure to look at your avatar on each step of deletion. Worst case is you'll have to make another duplicate and start again in case you delete something you wanted.

Guide:

The guidance starts with a modular avatar avatar that was duplicated and unpacked. It is basically just a stock militina with some booth slop slapped on with MA. Note I am using Gesture Manager (linked in tools section) to test the avatar.

VRAM / Download Size - Textures

VRAM and Download size are consumed by your entire avatar. Most of it will be textures and blendshape data. In short; reduce the resolution of the textures, merge materials, and remove unneeded blendshapes. Merging materials is covered elsewhere.

Textures

When to use: Always, and especially when your VRAM usage is high. A reasonable upper limit is 102MB per Avatar. Go under if you can, since it prevents hitching when your avatar loads in.

If there's some detail you really want, you should consider modifying UVs to grant that detail more 'space' in the texture.

What: Unity loads images and then encodes them to preset-sizes that are loaded into VRAM. You can change this pre-set size to GREATLY reduce VRAM usage.

Crunch compression adds a compression layer that reduces download size but keeps the size in VRAM the same. In other words: Crunch compression reduces the quality of your textures for zero reduction in VRAM usage. Never enable it.

How:

Thry's Avatar Performance tools (below in Tools) can show you high-usage Textures and components. Go through them and lower the resolution until acceptable.

  • Change resolution downwards. 4k is usually way too high, 2k usually looks fine, so long as:
  • As for type; DXT1 looks the worst but performs the best, DXT5 looks a bit better and performs a tiny bit worse, and BC7 looks nearly lossless but there's a performance tradeoff. In general, try DXT5 first, and if you notice color banding or whatnot, switch to BC7. BC7 is pretty low in performance costs but if there's many gigabytes of bx7 in a scene (like a VRC instance) this turns into lots of lag spikes. tl;dr don't BC7 everything, and avoid it on 4k textures.
  • Turn crunch compression OFF.

Guide:

There's also https://github.com/limitex/avatar-compressor but it's a one-click machine that will 'automatically' determine if your textures still look acceptable. I don't trust it but it may work for you.

VRAM / Download Size - Blendshapes

Blendshapes are stored in the mesh data, which is loaded by the GPU. More polygons and more blendshapes = more space needed.

Remove Unused Blendshapes

When to use: Always.

What: If a blendshape is not affected by an animation on your avatar, it means you never activate it and can just remove it on upload (non destructive). Note this doesn't remove the mesh that the blendshape moves, just the 'positional data' that tells a vertex to move to one location relative to others to be the blendshape. Apply prefabulous to get rid of mesh according to blendshape.

How:

Run d4rk's optimizer on (at least) basic. That's it.

Material Count

Every different material causes a new draw call as if it was an entirely new mesh. These should be merged as much as possible. See twitter link sorry (tl;dr: 1 million polygons and 1 MaterialSlot = 800fps, 1,000 polygons and 1,000 MaterialSlots = 200 FPS). The example is an extreme but it shows that you should be reducing material counts more than polygon. (Same reason to merge mesh objects, although d4rks and AAO just do this automagically so it's near zero effort)

TODO: Actually finish this section since it's important

When to use:

Every time. Prioritize this even above pushing polygon counts down.

What:

I'm still researching tools to use, but for now look up how to do:

  • Atlasing (manual or automatic)
  • Any kind of material combining

How:

Some (MISSING IMAGES: TODO) manual guidance is in Booth_Optimization_example#Considering_Materials, and d4rks works on poiyomi, but combining materials tends to be difficult to do automatically because materials tend to have a lot of separate settings and a tool can't figure out which of them are important and can't be merged and which are not important and can be merged.

It's a todo to get some better guidance here, sorry.

Bone Count

Useful for removing the transforms in physbones too.

When to use:

When you see a lot of bones in a model. Long chains of lots of small bones cause more physbones transforms and more render processing when calculating movement.

What:

Blender (With CATS plugin) can help you merge the weights and make a smaller number of larger bones. Motion will be less fluid but only by a bit. Often it's crazy overkill to have that much fluidity.

How:

  1. Open blender.
  2. Find the chains of bones that you'd like to reduce the count on. They tend to be hair bones that have lots of tiny little bones rather than just a few larger ones.
  3. Start with the bone on the very tip - Select the bone then use CATS - merge with parent. This merges the bone with the parent of that bone. The bone's visual size will appear small, but if you wiggle it you'll see it works.
  4. Find the bone ABOVE the bone you just merged to, and repeat the process for every other bone.
  5. (TODO: Validate what things are supposed to look like when you do this, and ways to make it look nicer.)

Blendshape Stuff

Physbones

Animator Controller Layers

Animator controllers control your 3.0 avatar junk. They can be made bad, and they can be made less bad. Bad is: Lots of separate layers, lots of any-states transitions. These things use CPU power, which is always at a premium.

When to use: Always reduce this. VRChat has a hidden feature where auto-culled avatars will still have their animator controllers running so the avatar doesn't go out of sync. Avatars with poor controllers (IE many layers, lots of any states, etc) when auto-culled don't actually stop running and so still act as performance bombs. Animator controllers are always important.

Especially important if you've removed bits from your avatar for the goal of performance, you should also remove the toggles, so the game logic controlling them isn't still running!

What: Check your animator controller and look at the layers. If you've never looked, it might be bad. If anything is on a toggle, d4rks cannot optimize it, so removing toggles you don't use allows d4rks to do a LOT more work.

Also do not use "infinite parameters and toggles" basically ever. I know facetracking eats a lot of parameters, but this addon turns avatars into lag bombs.

How:

  • Look at the animator controller. If it has many layers, that's a problem.
  • Duplicate the animator controller so you work on a copy.
    • Find your animator controller by clicking the root of your avatar (same place as the VRC avatar descriptor) and in the inspector scrolling down and looking for the controller. Click on it, and then find the animator pane and look at it there. A layer is each seperate 'workspace' with the game-logic flowchart looking things
  • Ideally delete things there and replace with VRCFury or MA toggles.

Guide:

In the example below I start with a mega-MA'd default militina. The default FX layer is kinda awful. I went through the mesh deletion stuff above so many of the things in the old controller can get yeeted. Since lots of stuff is baked down now there's not much to add back.

Important note: I didn't have time to figure out how blendshape matching worked in MA which is a system which automatically moves clothing blendshapes along with the toggles that move the default ones. You'll have to recreate it (which takes a few seconds per toggle)

Other

Techniques

Duplicate

  • Duplicate with ctrl-d in the hierachy to duplicate the game object
  • ALSO duplicate the animator controller (FX Layer only usually). Ensure you only remove stuff from the duplicate.
  • Also duplicate the VRC menu and Parameter list (In the avatar descriptor)
  • Unpack the prefabs if you don't want to be deleting stuff from the master copy too!

References

Tools

Installation

For ones which have packages (all of the above), follow the instruction guides on their main pages. If you don't quite get it, use the JSONs, linked above. In VCC, go to Settings -> Packages -> Add Repository, and in that box add the JSON. Then go to your project by Projects -> Manage Project -> Make sure "Selected Repos" includes the thing you just added, then scroll down and hit the + next to the pancake you actually want. This should add it to your project.

  • PREFABULOUS: Apparently if you install this via Hai's package it wants to downgrade the VRC SDK down to 2.7. If ANYTHING asks you to downgrade the VRCSDK, do not install it. VRC depreciates old SDKs pretty hard nowadays and so you'll just be unable to upload avatars which sucks.