From BlenderWiki

Jump to: navigation, search
Note: This is an archived version of the Blender Developer Wiki. The current and active wiki is available on wiki.blender.org.

From Sdfgeoff:

Here's quite a useful component for UPBGE:

import bge
import logging
from collections import OrderedDict
 
LOCAL = True
 
class DistFromObj(bge.types.KX_PythonComponent):
    args = OrderedDict([
        ("ObjName", "Player"),
        ("Distance", 5.0),
    ])
    def start(self, args):
        self.target = args['ObjName']
        self.distance = args['Distance']
        self.object.staticShadow = True
 
    def update(self):
        player_obj = self.object.scene.objects[self.target]
        dist = self.object.getDistanceTo(player_obj)
        self.object.staticShadow = dist > self.distance

Apply it to a light, and it will make it so the shadow only updates when the specified object is within the specified distance. What this means is that you can have lots of shadow lights and not have as much of a performance hit (bear in mind you will still have the texture samples and VRAM use though)


From Sdfgeoff:

Thing I learned a few days ago: Heightmaps are really really slow. They have 3 texture samples per pixel. Normal maps have only a single texture sample per pixel. One scene that had two heightmaps on objects taking up most of the screen ran at ~5fps on my laptop. I changed it to normal maps, and performance has increased to over 60 (for some reason I can't turn vsync off on my laptop, so I don't know what it's uncapped performance is).

If you didn't already know, the thing that makes a material slow is pretty much always the same thing: the number of texture samples. A madern GPU can add numbers together at a blindingly fast rate but to access a texture, it has to access vram, which is quite a bit slower. I haven't done any profiling, but I expect that you could do 20 or so math operations in the time it takes to sample a pixel.

Likewise, textures occupy vram. If the vram get's full, then the computer has to swap textures from system memory into GPU memory. This is extremely slow. So if you notice that adding a single texture takes your scene from 200fps down to 10fps, you've probably run out of VRAM and need to consider reducing the resolution of your textures.


Other tricks https://wiki.blender.org/index.php/User:Lordloki/other_tricks