Efficient way to check which lights belong to which meshes?

Started by
13 comments, last by Avilius 9 years ago

But those 6frustum culling passes per light should be very fast bebecause they should only operate for subset of data. Assuming that you do range check before.

Ah, correct.

I did another test with the release version and I got an average of 0.1ms :s! I don't know why it's so low now (I guess I had a game running in the background or some debugging file idk). Still a bit high though. I'm gonna take some time to look into what I am doing wrong.

Quicky algorithm that I would try.

1. Frustum cull visible lights.

2. Sort lights by radius.

3. Frustum cull objects but add biggest radius of visible lights for every object.

4. For each visible light loop over object list from pass 3 and do range check. For each face frustum cull objects that are inside the range.

Hmm, that seems like a good idea. I will try that actually. I may have to do two frustum culls though. One with the radius and one without. So that way objects outside of players view don't get rendered. I may also need to make some dynamic lights smaller for this to be more efficient.

View my game dev blog here!

Advertisement

Also you could cache list of lights affecting each mesh and update only if given mesh moves or light moves.

You could use a Forward+ renderer and cull lights in a compute shader to get a list of lights for each screen-space tile.

Aether3D Game Engine: https://github.com/bioglaze/aether3d

Blog: http://twiren.kapsi.fi/blog.html

Control

You could use a Forward+ renderer and cull lights in a compute shader to get a list of lights for each screen-space tile.

Sounds good, but i'm planning to support openGL 3.3, which doesn't support compute shaders.

Either way, I found the reason it is acting so slow. I'm iterating over an std::vector<boost::weak_ptr<RenderingComponent>>, and locking each one for every light for checking for collision detection. I'm gonna have to move away from shared ptrs since they are too slow, however I am having difficulty finding a way to iterate through all rendering components without knowing if they are dead or not.

I may try using a memory pool of rendering component ptrs and update every frame, checking each game object to see if it has a rendering component in it's component map, but idk, probs won't be as slow as locking weak ptrs, but still sounds slow.. I didn't think this issue would pop up again.

View my game dev blog here!

...Don't do that. If you're going to make a memory pool, store the actual structures themselves in the pool, not pointers to them. If not, you won't see much of an improvement (or any, really). Smart pointer's aren't really faster or slower than normal pointers. The problem is that you're thrashing your cache, which really kills performance especially in portions of code that are performance-critical. Checks like this do not belong in any low level subsystem, much less a renderer. This belongs in a scene manager. The renderer has no idea what a game object is. It should just take in a structure similar to this:


struct render_item_t
{
    uint16_t vertex_buffer_id;
    uint16_t index_buffer_id;
    uint16_t material_id;
    uint16_t offset; // Offset in vertex buffer
    uint16_t size;   // Size
};

And spit out pixel values to be sent to the monitor.

The scene manager decides what is drawn and how, then constructs the appropriate command buffer for the renderer to consume.

This topic is closed to new replies.

Advertisement