Model Optimization

From DungeonHack

Jump to: navigation, search

We have particular standards for proper construction of models. This is based on deep knowledge of how models are actually processed by graphics hardware and what various techniques result in visually. The point is to create a shape, however complex, with only the polygons you need, to avoid shading artifacts, and to never have overdraw from hidden faces.


Contents

Optimizing Polycounts

Not optimizing your models is one of the most common beginner mistakes people make. They don't optimize their models and they end up spending polygons on nothing. Here are some examples of right vs. wrong. The examples are rather self- explanatory. Remember, every saved polygon means something.

Before: 48 triangles After: 32 triangles
Before: 48 triangles After: 32 triangles
Before: 112 triangles After: 72 triangles
Before: 112 triangles After: 72 triangles
Before: 36 triangles After: 34 triangles
Before: 36 triangles After: 34 triangles
Before: 64 triangles After: 32 triangles
Before: 64 triangles After: 32 triangles
Before: 412 triangles After: 304 triangles
Before: 412 triangles After: 304 triangles
Before: 194 triangles After: 178 triangles
Before: 194 triangles After: 178 triangles


Optimizing Vertices

2 or 3 saved polygons is nothing compared to a completely optimized model, both hardware-wise and visually. A 5,000 poly model can display faster than a 200 poly model, if you just know the right tips and tricks. If I may yet again mention my main project Vega Strike; we abandoned poly count saving when our graphics guru taught us model optimization. We went from a poly count limit of 1000 for small space ships to around 100,000 when he showed us an optimized model of the smallest ship with 70,000 polygons running at higher frame rates (the previous version of the same model had around 500 polygons, I believe).

Flatshading = Bad

Never make a model completely flat-shaded. A flat-shaded model gets three times the vertex count a smooth-shaded model gets. This is because of edge splitting happening at GPU level. Your model might say 1000 vertices in blender, but it's rendered as 3000 in-game. This gets ridiculous at higher poly levels. This is because: In order for a line to be rendered like it's hard, it has to be split into 2 lines, meaning that a fully flat shaded model gets 3 individual vertices - an individual smooth group - for each face. This is the worst case scenario.

Some of you might think "Oh no, smooth shaded models get ugly shading artifacts, like the houses in SilverTreeRPG!". This isn't necessarily true, and I'll show you an example. Here's a basic model with some shapes you might use; hard extrusion on a round surface - a barrel-ish cylinder (the barrel in the gallery is fully flat-shaded). This is with full flat-shading:

Image:Flatshade.png

This is the same model, with full smooth-shading, showing (although it's hard to see with blender's renderer) those ugly artifacts so many models get.

Image:Artifact.png

An artifact is a shading error, often resulting in dark lines on the model, shading differently than the rest of the model. These appear when an angle is too steep for the smooth shading to handle; smooth shading wants as round a model as it can get.

Edge-Splits

So the idea is to have a smooth-shaded model, and you do the edge splitting yourself so that the GPU doesn't have to. This is done with an object modifier in blender, called Edge-Split. First select all vertices on the model, then press W and click "set smooth". Then go into object mode, add the object modifier "Edge-Split" WITHOUT applying it. Deselect "From Edge Angle". Go back into edit mode, select all your lines you want hard (only where it's logically needed, and every logically needed line; a smooth steep angle can ruin an entire model) and press ctrl-E, then click "Mark As Sharp". Your model should look as awesome as this:

Image:Edgesplit.png

This requires practice, but you will learn after a while.

Also remember that the best place to put the seams in your textures is along edges on the mesh. Seams in the middle of a smooth group create an artificial, unnecessary edge that increases the index count without adding anything visually. The index count is:

all vertices post-export
all normals post-export
all texcoords (UV coords) post-export

Smooth-Bevels

OK, this is a great boost both for the eye and for the CPU, but it's not ideal. This is just the easy way of doing it.

The mother of all smooth shading optimization requires that ALL hard lines are smooth shaded. Welcome to the world of smooth-bevels. This requires a lot of explanation, and I'll let chuck_starchaser do the talking: Vega Strike wiki, HowTo:Bevel

Hidden faces = Worst

Make sure NO faces ever intersect. Overdraw causes massively slowed down frame rates.

If there are any inverted faces left, click Select -> Non-manifold to find all lines shared by too many faces. A line should never be shared by more than two faces. Simply delete the face that shouldn't be there.


To Review...

A general rule is that the actual, in-game vertex count has priority over triangle count. Blender will not always show the actual vertex count by itself so some knowledge from your side is required. Also know that actual in-game vertex counts may be different due to technical issues of how GPUs (graphical processing units) on modern video hardware handle data.

Cleaning up your model before exporting

  • If it's a static mesh, join all objects together by selecting them all and pressing Ctrl+J
  • Turn off the Double Sided in Blender's Mesh panel. If enabled, it makes the exported model render the inside and outside of the faces and it contributes horribly to rendering times in-game.
    px200
  • Remove doubled vertices. In mesh edit mode, select everything, got to specials menu with W-key and choose Remove Doubles
  • Recalculate vertex normals. In mesh edit mode, select everything and press Ctrl+N
  • Delete all hidden, also called "dead", polygons. These are the ones that will never be seen in-game no matter from which angle you try to look at them
  • An edge should always be shared between a maximum of only 2 faces. Edges that do not follow this rule will cause smoothing error and are generally not desired. They are commonly known as Non-manifold (or is it manifold?) . To find problematic areas on your mesh go to edit mode, edge selection, and then to Select -> Non-manifold. Edges that are problematic will not be highlighted and thus need to be inspected and impostor faces need to be deleted.