Tuesday, June 26, 2012

How to count vertices in VideoGames

Ok this one is quite common, but still actual.

Let's say a vertex contains a position, a normal, an 2 UVs. It weights 40 bytes in video memory.
A triangle is just about indices, it weights 6 bytes (2 bytes * 3 indices)

Note that these numbers are here only for comparing examples. Positions, normals, UVs can be compressed (half values) to take less space in video memory. Also stripping of the faces can modify these numbers.

In this example, I have
9 vertices + 8 triangles = 408 bytes.
 

Here, ther eseems to be very few difference, but we do not share UVs (note if all the "1" were on the same side we could have used tiling and get the same count as previous example).

So vertices are split in our 3d engine. So we have a vertex for each red dot.
16 vertices + 8 triangles = 688 bytes (+70%)


In this case, I explain with normals. Here I have "soft edges" (smooth groups), so normals in the middle of the objet are the same for each side. You count 9 positions & 9 normals so there will be 9 vertices.
9 vertices + 8 triangles = 408 bytes.


If I put "hard edges", there are 2 normals for the points in the middle, so points will each one give 2 vertices. We'll have 12 vertices.
12 vertices + 8 triangles = 528 bytes (+30%)


Same for color-per-vertex, smooth color:
9 vertices + 8 triangles = 408 bytes.


Hard color change : 12 vertices.
12 vertices + 8 triangles = 528 bytes (+30%)


So what ?
Just keep this in mind.
- An "hard edge" model can be twice the weight of a "smooth" one.
- An "automatic layout" of UVs can be twice the weight of a "planar" UV mapping
- Most of the split in game models are due to UVs (UV1 or UV2)

Any advice ?
- Remove any unused UV layer (your vertices could be split because of an unused UV2 layer)
- If some of the Uvs of your model map to a single flat color, try to put all UVs in a single Uv position better than mapping it on a quad on the flat surface (and it's wasted place in the texture :)
- Smooth models. Only hard edge some small parts, if you really need to.
- You can simulate some hard edges with normal map

Well, lots of other things ! Just tell me in the comments if you have other ideas :)

Remarks:
- Same thing occurs with material change (with even more overhead due to other factors)

- Understand that if a point is already split by UVs for example (like in picture 2), having hard normals or hard colors won't split it again. In fact having 16 vertices for this mesh is the worst case.


- This leads to some optimizations like double edges, that I'll try to cover one day



References/Extra links
  • http://www.polycount.com/forum/showthread.php?t=50588
  • http://www.ericchadwick.com/examples/provost/byf1.html 

Saturday, June 16, 2012

Polygon repartition on an humanoid character

I was looking a thread about polygon count, and I wanted to check what it looked like in video-games productions.
Of course, the polygon count does not guarantee to have a good result. But if you start modeling a character, you should be aware of common constraints in videogames.
Once again, these numbers are examples, and can vary quite much depending on the technology and the needs. These numbers assume that we talk about
- An important character of a real-time game (not a enemy seen from very far)
- A character with a quite detailed face (seen on cinematic scenes or so)

On the picture below, you see values of  ModelA, a Lara Croft model taken from this site. The triangle count is a bit high for a game (30K) but this a good example.
The values in green are taken from a model from a recent game I was involved in, so it's real video-game data. The results are similar.
 

 To summarize, I would recommand:

- 30 % of triangles in the chest and arms
- 2x 5% of triangles in the hands (assuming the character has to handle things, and all fingers are skinned)
- 20 % of triangles on the legs and shoes (assuming no skinned toes : )
- 25 % of triangles in head (facial represents an important part, specially an important part of bones !)
- 15 % of triangles in the hairs (depends on character of course)




I would be happy to hear about other examples in your real-time video-game production (not for a CG offline-rendered character), so feel free to comment !

About body modeling

Wednesday, June 13, 2012

How to model a sphere


To start simple, I'll try to explain how simple things can be done.Model a sphere. It seems very simple, but there are many ways to do it. Specially if you care about triangle count, ease of future modeling, UVs, symmetry, etc.

The geosphere

Here is the default sphere created by Maya. It is well shaped, but we see two annoying things
- The triangle count is quite high : 760 triangles
- There is a huge difference between faces in the pole areas and the equatorial ones.
- The default mapping is quite strange, that makes textures very deformed especially in pole regions
- The sphere is not symmetric on all planes, so it won't look the same depending on the angle of view.


First of all, reduce the polycount.
You need to modulate the number of subdivisions in the height or the radius. Theoretically, to have square faces, we should have twice more divisions around radius than height. But on low values, this gives wreid angles when the sphere is seen from the size.
That's why a 3/2 factor is often a good choice. This makes your sphere profile look similar from the side of trom the top.
For instance, you can choose 15/10 or 12/8 values.



 The SoccerBall

This is the second option. It helps to have faces of a similar size. The basic soccer ball is 116 triangles, and there are 2 size of faces, the big and the medium ones. The drawback are
- The figure is not symmetric at all. No edge loop. No nice extrusions.
- No way to cut in half
- Default UV mapping is horrible, even if mapping by face is possible.
- If you triangulate it you get an horrible topology, and see that triangle size is not so even.


You can still use a smoothed version of it, if you don't need to edit the sphere (if you're a specialized sphere-only modeler for example : )

 

Smoothed box modeling

The third way is to use box modeling techniques. To do this, just create a box and smooth it. You've got a sphere for 48 triangles. It's not really detailed, but the shape is correct. Could be okay for an eyeball of some enemy.


The second version is a level 2 smooth (or double smooth). this time, it's really shaped like a sphere. It has multiple advantages
- 192 triangles, for a result much better than previous 168 tris' geosphere.
- Faces are approximately the same size
- The mapping if the one of a cube, that can be quite helpfull (this can be a problem, in this case make a spherical/cylindrical uv mapping)
- The sphere is symmetric on all planes. It will look the same from top as from any side.
- It is a good object to keep modeling. You can extrude easily from any side to make a tube for example.
- The only problem could be that all the points are not on a sphere (equal distance from center), even if the volume of the primitive is the same as a sphere.


If you have any comment or your own techniques, feel free to share it.