Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / [SOLVED] AddObjectMeshFromMemblock() performance issues? Guidance?

Author
Message
Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 3rd Sep 2018 22:45 Edited at: 3rd Sep 2018 22:48
I seem to be have some terrible performance from this.

I am attempting to add 10,000 meshes to a grass object. I can load 10,000 objects in less than 30 seconds. However, when I go to create one object, and add the meshes to it. My memory used shoots up to 1GB and its takes close to 20 minutes to load.

Making this one object has really increased my FPS. But I am struggling on how to get these meshes merged in a timely manner. I believe its the addobjectmeshfrommemblock that is causing these issues.

Should I be instead creating a new memblock via the SetMemblock byte commands? Would I still have meshes? I thought meshes off-screen were automatically culled, and that was why they increased performance?

In my screenshot I have 12908 grass meshses and 1 object. That many objects would normally bring me to about 50-55 fps, but I am still at 60. You can also see I am only using 16MB in images, and task manager says 23MB total. It jumps to 1GB during loading.

I also thought about saving all 13,000 memblocks, but surely there is a better way.

I appreciate any guidance!


Attachments

Login to view attachments

The author of this post has marked a post as an answer.

Go to answer

Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 4th Sep 2018 00:51 Edited at: 4th Sep 2018 01:13
I split it up into objects with 1000 meshes. This has decreased the loading time to about 2.0-2.5 minutes from 25 minutes.

edit: I also tried 100 meshes. It cut it to about 1.5 minutes. I still get a stupid amount of memory usage during loading.

edit2: 30 meshes was 1 minute and 20 second load time. A slight fractional hit to fps. Still crazy memory usage.


Unless, someone tells me not to waste my time I am going to try without using AddObjectMeshfromMemblock. This really seems to be bottlenecking things. Of course, I could be missing something very simple, as usual.


new code to split into multiple objects: I changed the mesh to 60 since 30 was not worth the fps loss.

puzzler2018
User Banned
Posted: 4th Sep 2018 07:21
Your forever creating *new* Big_Grass in a for loop with a SetObjectMeshImage and SetObjectMeshShader in the for loop too. - This will be doing the slow down



Let me have a think
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 4th Sep 2018 09:28 Edited at: 4th Sep 2018 09:32
Should numvert be recalculated for the grass too rather than the just the big grass?
Or are they all the same model? In which case you don't really need the get vertex position in the second part at all.

Not sure you can do much about the memory usage, me blocks require much more memory than models.
life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 4th Sep 2018 12:19
Ouch......that's gonna be incredibly slow. You need to build it in a memblock, build the mesh one time. There's now a TON of threads covering this.
Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 4th Sep 2018 13:05 Edited at: 4th Sep 2018 13:16
Quote: "
Your forever creating *new* Big_Grass in a for loop with a SetObjectMeshImage and SetObjectMeshShader in the for loop too. - This will be doing the slow down"


This is just a startup function. It doesn't run forever. I took out the image and shader from the for loop, and performance was still crap. Pretty sure the bottleneck is adding the mesh via addmesh command.

smallg wrote: "
Or are they all the same model? In which case you don't really need the get vertex position in the second part at all."

Ah.. good point.

I will have a look around Santman. I don't really read those threads, since they make my brain hurt.
puzzler2018
User Banned
Posted: 4th Sep 2018 13:10
here is my bundle of mesh memblock work that I do - updated frequently

https://forum.thegamecreators.com/thread/222071?page=1

Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 4th Sep 2018 13:16
Thanks, Puzzler. I will study it.
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 4th Sep 2018 16:43 Edited at: 4th Sep 2018 18:56
This post has been marked by the post author as the answer.
As santman says, why not just move all the grass into a single mesh? Theres no need for multiple meshes and 10,000 draw calls just to draw grass.

This code creates 10,000 grass tufts (each is 4 triangles, like yours) and it builds the object from scratch in under a second in AGK

Its also pretty quick to draw on my colleagues 'work' pc which doesnt even have a graphics card. Using a single mesh is quick to draw.



There are very few reasons to use multiple meshes in an object unless
1) You want it to have a different texture on that mesh (even so you should be texture atlasing)
2) You want to use a different shader on it
3) You are doing it for culling reasons or plan to change one section of a very large mesh and dont want to eat bus bandwidth.

Attachments

Login to view attachments
Icerion
5
Years of Service
User Offline
Joined: 3rd Aug 2018
Location:
Posted: 4th Sep 2018 17:08
Is there a way you can make visible, only the grass within the sight of the camera to save even more FPS?

Thanks!
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 4th Sep 2018 19:00
Any mesh that isnt at least partly on the screen wont be drawn by AGK. So the easiest way to allow culling to be efficient is to break large objects up into manageable smaller meshes.

A good example is the CreateObjectHeightmap() which allows you to split up the heightmap into a number of smaller meshes. In the case of grass I would break up the grass onto chunks which are the same size as the landscape chunks.
Icerion
5
Years of Service
User Offline
Joined: 3rd Aug 2018
Location:
Posted: 4th Sep 2018 22:53
Can you show a demonstration?

Thanks!
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 4th Sep 2018 23:09
Same example as above but with a copy of the Ground offset to the right. As the camera rotates the copy will be on the screen then not on the screen when the camera rotates to face away from it.

When it is in screen space 80,000 polygons are drawn (2 objects worth)
When its not in screen space, just 40,000 are drawn as AppGameKit does a bounding box check then doesnt draw it if its not in the viewing frustrum. So we just saved draing 40,000 polygons by doing nothing at all.

puzzler2018
User Banned
Posted: 4th Sep 2018 23:12 Edited at: 4th Sep 2018 23:13
Cant get any better than that - Thanks Bengismo
Icerion
5
Years of Service
User Offline
Joined: 3rd Aug 2018
Location:
Posted: 5th Sep 2018 00:04 Edited at: 5th Sep 2018 00:14
Thanks @Bengismo!

I think that even more FPS can be added by shooting a raycast directly from the entity ( camera OR object ), then within the field of view, it shows you what's within the field of view of the camera & hide everything else outside that view.
Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 5th Sep 2018 00:17
Thanks, Beng. I wasn't entirely sure what method would be fastest. I really appreciate your in-depth answer.

My next challenge was going to be what you have provided. Although, I will still have to study it to learn what its doing.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 5th Sep 2018 00:22
Icerion, agk already does that, its the built in fulstrum culling.

The only thing that may make it faster would be low level occlusion culling, but that's largely useless on transparent objects anyway.
Icerion
5
Years of Service
User Offline
Joined: 3rd Aug 2018
Location:
Posted: 5th Sep 2018 00:24
I agree, @Santman. I think that could work.

Can you add that @Bengismo?

Thanks!
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 5th Sep 2018 00:33
????????

Yeah Ben.....just add occlusion culling in please. Lol
puzzler2018
User Banned
Posted: 5th Sep 2018 00:38 Edited at: 5th Sep 2018 00:41
Like I said - cant get any much better than what Bengismo has provided already. We all have to learn the hard way

Search on the forum for memblock works, you maybe learners, so was I. Do some research to learn yourselves

If no one learns and someone posts an example, then you be stuck at the next hurdle..

If you wanna be programmers then be wiling to learn the langauge instead of asking for snippets to only find your struggling again next week cause done have a clue what the snippets mean

Login to post a reply

Server time is: 2024-04-20 09:15:27
Your offset time is: 2024-04-20 09:15:27