BGE Development: Rasterizer and Scenegraph optimization (proposals, discussion)

I’m currently not able to find the problem. Seems like I missed something essential…

I uploaded the modified source files now to the ras-lod branch on gitorious. If someone has interest to look into it, maybe fixing this issue would be a little bit easier.

https://gitorious.org/~moerdn/blenderprojects/moerdn-bge-sandbox/commit/80705ad93ddd7e2ed8f5c36199cf8ad73168f341

writefile seems to work when saving is done, but restoring causes the problem. Sometimes loading works, but with garbage data. Closing blender then causes some further error:

Memoryblock free: pointer not in memlist
Error: Not freed memory blocks: -1

sorry for that ‘showstopper’, codebase of blender is quite huge and hard to look through for blender coding beginners.

EDIT:
I’ve looked into bb_dev stuff and there is also some work to do in readfile.c.

greetings,
moerdn

Looking good so far, will be very interesting to see how this effects performance in a proper game setup.
Great to see people like you moerdn who are popping up at the moment to help with the development of the BGE.

There area write data because bContoller can point to another struct if it is a python controller, so it need to be saved. Since your struct doesn’t point to another struct, it shouldn’t be needed :wink:

are you allocating with malloc? i think blender has his own memory manager, and you should use mem_alloc. Or maybe you are missing to free the memory(causing a memory leak, and blender warns you when this happens) This is the first things that came to my mind.

Yes, I only use:


lod= MEM_callocN(sizeof(LodLevel), "LodLevel");
MEM_freeN(lod);

from blender for allocation and de-allocation.

greetings,
moerdn

Well, it seems that fixing this problem requires a little bit more knowledge of the blender code base, than I can provide at the moment. :confused:

I decided to try another route to solve this issue. I’ve now ported the most parts from Benoit Bolsees bb_dev (thanks to Dalai and of course Benoit :slight_smile: ) branch to my 2.59 working copy. This was surprisingly easy to do. Wrapped at least the distance settings in proper rna functions and user interface works as before.

No crashes any more, saving, making copies of objects and loading seems stable now.

bb_dev branch doesn’t use names for the LOD settings, but links to objects. With this it should be possible to implement a nice drop down list for choosing the LOD levels. Need to read a bit about that. Any hints are welcome as always :slight_smile:

greetings, moerdn

You’re looking for an RNA pointer type. For examples, you can look at the collision/touch sensors, property sensor, etc.

Thank you Moguri, the pointer property do the trick.

http://img6.imageshack.us/img6/7207/lodsettings.png

greetings,
moerdn

I’m a bit curious about performance test on Your vs Benoits patch… If You going to switch because Your performance did look awesome. And if it use object pointers - do it still replace mesh or do it replace objects? The first ‘feels’ faster but the later feels more powerful (at least if we can use group instances).

Benoits patch was UI only, if I looked correctly and the object pointer is currently for user interface. A nice and clean method to pick the objects from scene list. At bge data conversion time I convert this to a string for mesh or object switching.

I’m not sure what is faster, mesh or object replacement. I would like to test them both (should not be that hard to implement) maybe user could decide what to replace. Replacement on object level gives more possibilities to tune the game, I think.

A problem has occurred now, as I save the object pointer in the LodLevel struct. Blender crashes again, because of wrong saving and loading of that object data. Anyway I made a workaround to solve this problem temporarily.

Next step is implementing the gameengine part. After that, I would made a tests builds for windows and linux. Source code is as always up-to-date on gitorious, if someone is interest to look at it.

thanks,
moerdn

Now GameEngine implementation part is almost done. I will try to upload the last changes to my repository this evening. Making builds for linux and windows would also be nice.

A quick test shows, that LOD also works for group instances and animations:

Models taken from Moguris animation stress test. Would be nice to see this in combination :slight_smile:

There was a nice script for blender 2.49: Polyreducer. If this would be available for blender 2.5 as operator, the lod levels could be generated half-automatic.

greetings, moerdn

Wow!

Am I jumping my conclusions or do this imply that we can replace a simple lowpoly house object with a more highpoly house with separate objects for doors and logic to open doors and ring doorbells etc?

All automatic depending on how close we are to the house… Not only lod:ing rendering but logic to?

Wow again, and thanks!

With replacement on mesh level I don’t think this is possible. You can simulate something like that:
http://dl.dropbox.com/u/2779060/complexe_object.ogv

Maybe replacement on object level would make it possible to replace complex groups of objects. (one big object --> many smaller object)

Maybe we could use a flag, that is set on distance, to stop logic from being executed.

greetings, moerdn

In Blender 2.5x you can use the decimate modifer.

Yes I know, but the polyreducer kept UV layouts intact.

greetings,
moerdn

maybe you can set a flag to let the user choose to switch on mesh or object level… But i think that the object switch can be more useful.

I interpreted “LOD also works for group instances” wrong… You mean it replace meshes for individual objects in groups?

That good on it’s own. But it would be nice to see how replace object would work - if we can replace one simple object with a group instance? I also think replace object would play well with both ordinary logic and components (the real one - my python fake one would need a callback - but callbacks don’t seams popular so I have kind of quit asking)… But I wonder if one can use a always sensor as ‘callback’ - It should be called with positive pulse when the object starts and a negative pulse when the object ends??? Dunno…

Thanks again anyway :slight_smile:

An switch seems ok for me, should be easy to implement. What is more useful depends on the situation, if you want to switch a mesh for animation, replace mesh is the only option.

@LaH: yes, sorry for unclear definition. Callbacks (callback always sensor? - callways sensor! ^^) for start and end object would also be nice, especially with LOD on object level.

For object/group-instance replacement my group-ref api for gameobjects would become useful here. If you replace an object with a group instance, you have to control all the objects inside (delete them if necessary, start/ stop logic…) I consider merging the two branches ras-lod and group-ref

  • I will target Mesh/Object replacement that could be set in UI for every object.
  • source code for LOD is now available on gitorious https://gitorious.org/~moerdn/blenderprojects/moerdn-bge-sandbox
  • I have made windows build now, need to bundle this with some testfiles (animation, benchmark…)
  • interest in linux builds? Than I need some resources on how to make an release build.
  • would be nice if someone could look into it, especially for solving this object pointer problem

greetings,
moerdn

Thank you a lot moerdn for all your great efforts on this. I’m amazed by your work. Two thumbs up!^^

Now another little video, that shows performance between:

  • 1000 highpoly trees (~10fps)
  • 2000 lowpoly trees (~25fps)
  • 2000 level of detail trees with 3 discrete levels (~25fps)

This video demonstrates LOD in a ‘real’ game environment from my BGE project ‘Romanic’

There are some problems still, but I think a first test can now be done.

Windows build:
http://dl.dropbox.com/u/2779060/LoD-Porject/win32-Level-of-Detail-vc.zip

Benchmark file:
http://dl.dropbox.com/u/2779060/LoD-Porject/Benchmark.blend

Usage if you load the Benchmark.blend

  • make some distance changes on the right side or leave the default values
  • click left on ‘random property placer’ operator
  • make some changes to object count, radius and seed
  • press P for play
  • move spectator cam with WSAD and mouse.

greetings,
moerdn

concerning the decimate modifier: i recommend “remove doubles” with a high limit (e.g. 0.400, changeable in the editing buttons in edit mode), because then the uv-layout is not changed.