Hello,
i am working on a physics driven game. Basically a tunnel racer. Drone is always centered third person like and shallow fly through tunnels. Tunnels are constructed by assembling template tunnel parts. There are straight, curve, up down and other templates (in unity prefabs).
Now it build ups to quite a lot parts, and I am having performance problems. Seems frustum related. If I disable frustum culling on the camera performance is very bad all the time. If its on I often reach 60FPS on a current MacBook Pro.
However, depending on were the camera looks at the game stalls for a second or more or stutters. The profiler doesn’t help me here.
So I tried to group tunnel entities into areas and then enable / disable them by flying though some trigger entities. This helps to keep the frame rate up during flights, but the game stalls again while doing so (means on enabling/disabling areas of entitys).
The tunnels are constructed of templates. usually they consist of a left side (and a mirrored rightside) and both sides have a mesh collider. Then every part has a light,but its area is so small, it can only lighten up its parent. Shadows are disabled on 90% of everything.
Every tunnel template has one point light, but it spreads out in small radius to only light up the single template.
Every tunnel template has two mesh colliders, low poly
very little amount of materials. Most templates share materials.
My solution was now to group tunnelentitys into areas and entering exiting doors will toggle them of or on, so there is only one area active at a time.
In this context I read about new lights in the latest release: clustered lights
I guess this might help, but it is not available in the editor. Or is it? Well it should be, since most fellows assemble there stuff with the editor. is there a toggle to switch this on or not? if not how can I try to use that? Iterate to every entity, find lights and exchange them to the new system?
Also I would take a look if there is a material being rendered for the first time. Spikes when enabling an entity/model can point to shader compilation, which can pause rendering for a while.
Edit: Similarly check if rigid bodies are being added to the hierarchy for the first time. Creating the Ammo shape can sometimes take a while for more complex models.
In current engine implementation, all enabled lights are used on all objects pretty much, it does not make a difference to make their range small.
Clustered lighting changes this, and only nearby lights are used. In Editor, you can create this script and add it on your root object to enable them. Note that that would mean no shadows for spot and point lights in the current preview implementation.
var Global = pc.createScript('global');
// initialize code called once per entity
Global.prototype.initialize = function() {
// enabled clustered lighting. This is a temporary API and will change in the future
pc.LayerComposition.clusteredLightingEnabled = true;
// adjust default clusterered lighting parameters to handle many lights:
// 1) subdivide space with lights into this many cells:
this.app.scene.layers.clusteredLightingCells = new pc.Vec3(12, 16, 12);
// 2) and allow this many lights per cell:
this.app.scene.layers.clusteredLightingMaxLights = 48;
};
It seems the massive slowdowns you get are related to shader compilation. It’s possibly due to lights … shaders need to recompile for different sets of lights. Try clustered lighting, that could be a good win here.