Performance Optimizations
Every developer who creates real-time applications
that use three-dimensional (3-D) graphics is concerned about performance
optimization. This section provides you with guidelines about getting the best
performance from your scene.
- Keep the textures small.
- Only set needed textures in material
- D3D Effect (Shader Text) heavy debase
performance, especially work with multi-texture. Only use shader when really
needed (if possible, instead of it by checking object's styles like Alpha
Test, Alpha Blend, Color Add...); if a material include shader text, assign
it to objects as less as possible.
- Check material's No Receive Shadow option for unneeded object
like sky.
- Check Exclusive VB style for meshs. This feature
use more video memory but can speed up rendering, especially for massive
vertices objects.
- For scripting, keep the " .new() " invocation out of loop as possible,
because the ".new()" function is slow. If a function's return
value is a class (e.g. vec, color, rect, etc), it will call ".new()" inner.
See example code:
local starttime=os.clock()
for i=0,9999 do
local v1=vec.new(1,2,3)
local v2=vec.new(5,6,7)
local v=v1+v2 -- most operator function also has a inner .new() call
end
print(os.clock()-starttime) -- approximately 1
local starttime=os.clock()
local v1=vec.new(1,2,3)
local v2=vec.new(5,6,7)
local v=vec.new()
for i=0,9999 do
v.x=v1.x+v2.x
v.y=v1.y+v2.y
v.z=v1.z+v2.z
end
print(os.clock()-starttime) -- approximately 0.01