I am trying to add grass to my terrain. I create 3 differently sized circles around the player each filled with 400 grass nodes (each consisting of 3 cardmaker-cards in a triangular shape, flattened together). When the player is walking i want grass to be removed from where he is coming and created where he is going.
The problem is that i cannot render 1200 different grass nodes and thus have used flattenedStrong on them giving me a framerate of above 1000 (med to high end gpu and cpu). However then i am no longer able to remove separate grass nodes.
Any ideas on this? Was thinking about surrounding the player with hexagon shaped tiles, each with flattened grass on them and delete and create hexagons as the player is walking around, but perhaps you guys have a better idea.
At the start of the game, lay a grid over the entire terrain and fill it with squares containing grass (the density and type of grass are obtained from vegetation maps). Each square is a nodepath. Do this 3 times with different grid widths. Each different grid houses differently sized grass.
Detach all square-nodepaths from the render tree except the 25 squares surrounding the player. Do this for all three grids. In the update task, check if the player has moved from one cell in a grid to another. If so, detach all square-nodePaths except those 25 surrounding the player. This way only a fraction of the squares is active, greatly reducing computational costs.
Also in the shader, do not view any grass pieces that are further away than 2 cell width of the corresponding grid. This way it does not seem as if there is a large square with grass surrounding the player, but rather a circle. The point of the 3 grids is there not being a single barrier from which grass is generated, but 3 slightly overlapping eachother, this seems less crude.
The result, after setting “threading-model Cull/Draw” in the config file, is a framerate of 400 when looking into the distance, and 600 when looking more towards the ground (med-high end cpu, gpu). With 23500 active grass quads (not all visible due to the shader only showing the inner circle).
Yeah i had some issues regarding transparency. Since all the quads are crossing each other, the z-buffer no longer knows which part of the the quad is in front of another quad and visa versa.
The issue seemed sufficiently fixed by setting the transparancy attribute to MDual. Another, slightly less visually apealing but more easy on the GPU, was to disable the z-buffer all together.
Another problem that occured was with the water plane. Ofcourse this is a huge plane that also makes use of transparency and the z-buffer realy didnt know where to place it in its list. Now, when i look through the grass towards the water plane, it looks as if the water plane is in front of the grass, while it actually is 100m behind it. I found the same issue with the nature demo you supplied me with on the code-snippet section. For now im semi-fixing this problem by just not seeding any grass near my pond, but it is something i will have to look into later… Any thoughts on that would be helpfull
And thx for the tips on the trees, those are next up on my list.
i do get some transparency: i can see the terrain underneath the water. The problem with the see-through grass is also fixed. The only (major) remaining problem is that any other object beneath the waterplane doenst appear on screen.
So if the only thing required beneath the waterplane is the terrain than this could be the solution. If you also need, for instance, waterplants/your player/rocks ets beneath the water (which i happen to do) than this isnt optimal quite yet.