[MERGED] GrassLoader Modifications

stealth977

24-02-2010 07:33:20

From my OGITOR POST


I modified GrassLoader of PagedGeometry and committed changes to our repository, the changes are:

1 - Creation of Pages are much much faster now since we use a pre-calculated random_table instead of rand()
2 - The grass locations are persistent now, this means, if you add more grass, old grass positions/rotations are kept, but new ones are added, if you remove grass, some of the current grass is removed, the remaining grass keeps its old position/rotation
3 - GrassLoader had a strange page creation, it was creating an entity out of the mesh, then clones this entity and adds to its internal list, then deletes the original entity. Now, we removed the clone and delete process and we directly add the created entity to internal list, THIS ALSO FIXED THE MEMORY (GPU) LEAK CRASH BUG i mentioned in my last post.

Overall, I expect at least 2x speedup at creation/modification of grass pages....


[attachment=0]GrassLoader.rar[/attachment]


NOTE: There are RANDOM_TABLE_SIZE and RANDOM_TABLE_MASK defines at the beginning of the source file, the optimum size is:

PAGESIZE * PAGESIZE * OVERALL_DENSITY_VALUE * 4 rounded up to the next 2^N and the mask value is RANDOM_TABLE_SIZE - 1

for example a page of 100 units x 100 units with overall density of 6 = 100*100*6*4 = 240000, TABLE_SIZE should be 262144 (2^18)(0x40000) and mask should be 262143 (0x3FFFF), the total size of your random_table would be 1MB and its nothing important nowadays, compared to persistence and speed it supplies.

Fish

24-02-2010 13:52:26

Hiya Stealth,

Thanks for the patch.

Is there a specific reason you made RANDOM_TABLE_SIZE and RANDOM_TABLE_MASK #defines instead of variables that can be specified at runtime?

-Fish

stealth977

24-02-2010 15:22:24

yes, actually it was easier that way and just a fraction faster than variables. Although I am thinking of making them variables for easy editor integration, the problem is:

Will you change the values during your programs execution. If so at which point?

And i couldnt find an answer for those questions. Usually a table size of 2^18 is enough to create 65536 grass blades per page, which means 262000 polygons per page for CROSSQUADS and is an insane number of polygons for a realtime-app, just for the grass... And since it only consumes 1MB at that setting, no need to make it adjustable.

Still it could be a variable, to use the same code in different applications and to gain memory by using smaller tables, but, its up to you guys :)

tdev

27-03-2010 15:32:22

thank you very much for the great idea about the random tables, simple and fast :)
also, thanks for spotting the entity clone thing.

i have converted your random table into a random table class (RandomTable.{cpp,h}) and merged your patches into the SVN trunk as revision 2860.

would be awesome if you could test it with that version :)