User Tools

Site Tools


Sidebar

hpl3:engine:optimizations

Optimizations

Below are various important adivice on how to get the most out of the engine. Most of these have to do with getting it to run as fast as possible, but some have to to with visual quality aswell.

Transparency

Avoid overlap
Translucent materials are quite costly perfomance-wise to render and because they both have to read and write for each pixel. At the same time many effects that use translucent materials, like billboards and particle systems, have effects that depend on overlap. For example in a fire the movement of overlapping particles create create a nice effect. For, on screen, small particle systems this is not that much of a problem. But for larger things like smoke it can be very costly. What one needs to be is to try and mimick this sort of overlap effect in a single particle in order to reduce overlap. For example b haing animated textures (using sub textures for particle system) it might be possible to do this very nicely! So beware before just pushing tons of overlapping particles or billboards to do an effect!

Alpha in all trans materials
As mentioned above, a costly aspect is of translucency is that it both read and writes. This can be reduced quite bit by skipping pixels that are not needed. Normally particles and similar and round in shape and are on a square textures. This makes the corners of of the image have pixels that are never drawn. This can be fixed to some extent by having an alpha channel and set alpha to zero in these areas. The important part is that this works even more additive, mul and mulx2 blend modes! So where ever your material is invisible (add=(0,0,0), mul=(1,1,1), mulx2=(0.5, 0.5, 0.5)) have alpha value of zero and for the rest of the pixels 1 (gradient is not needed). This reduce the perfomance it by a particle system by almost 50%!!

Premultiplied alpha
Premultiplied alpha is not something that can increase performance, but is used to remove glitches. When using normal alpha blending it is common for some sort of images that the background (what is in the transperant area) seeps in on the more opaque areas. The reason for this is because of how the hardware works and remultiplied alpha totally removes the artifact. This video (wich features cats!) shows the issue:
http://www.youtube.com/watch?v=dU9AXzCabiM
In order to use premultiplied alpha simply copy the alpha layer in photoshop and paste it as a multiply layer on top of the rgb. Then just set the materail to use pre-multiplied alpha. Note: In order for fading to work in particles, you also need to set multiply alpha with color!

Objects

The fewer the objects, the better
One of the major performance hogs in 3D rendering is the number of object rendered at the same time. The reason is because it can take plenty of CPU power to handle each object and all modern GPUs work much better with a small number of objects.
So how many are too many? Well it depends. Depending on how many lights are rendered, particles on screen (and overlapping), world reflections present etc you will have more or less time to render out objects. But to give sort of pointer, having 150 objects visible at a time is a good goal. Important note: if u have only made a single room so far, do not celebrate, if u have many connecting rooms later on, all objects will not be culled or slightly visible, adding to the total number of visible objects. A maximum figure would be 300 objects, but do not get up to this until really needed!

In order to reduce the number of objects there are three main ways to go about.

  • First thing you need to know is that the game's engine will try and combine static objects ad efficiently as possible. This means that even though you place, say 100 static objects, this might end up being less than 10 in the final version. The way this can be done is if many of the objects share the same material (making it possible for the engine to combine). This means that static objects that are close by to one another should try and save the same material as much as possible. But do not go overboard on this. Do not rely on huge 4096×4096 textures for all static, and have illum textures, etc that are mostly black.
  • While the engine can combine pretty good on its own, it does not work very well with smaller objects. Because of this you should have smaller objects as groups of objects instead, for example a group of 6 mushrooms in various configurations. It is okay to have single objects, but use the groups to place the bulk of them.
  • If you have a really large room where the engine will not properly combine objects. I giant wall might become made up of 100s of smaller objects, when all it needs is one object really. To solve this you can force combine them in the editor by using the combine edit move. Simply add the sides of the wall into four different groups and they will each become a single object in the game.

- Use small number of objects. Same texture for same things + combine (force if needed in editor).

- IsOccluder only on important stuff.

- Static object: Low poly count!

Lights

- Only use spec when really needed.

- Do not use too many shadows (link to jens's article)

Physics

- Turn off or simplify collisions of static objects.

hpl3/engine/optimizations.1314644962.txt.gz · Last modified: 2011/08/29 19:09 by thomas