How to fill a plane with grass.(performance issue)

I know it’s a total noob’s question but I really don’t get it. And the code in instancing article is sssslloow when generating 100+ positions.

I use an almost-infinite plane(eg. floor.setScale(30000e2,30000e2,30000e2)).
My goal is to fill the visible “floor” with grass. I tried to do it with the code in the instancing article, but as I said: total performance loss.[drop to 1,1FPS]

Because I’ve deleted the original code, here a quick-rewrite just for try:

[Run with onscreenIDE by ynhj_jo for best experience]

clip.tar.ZiP.mod.zip

So what’s the right way to it?

-cheers Your Mešča

The GPU can’t render more than a few hundred different geoms before it starts slowing down terribly.
So, flatten down your grass to one node. Do that by reparenting all grass nodes to a dummy subnode of render, and then call clearModelNodes() and flattenStrong() on that subnode (in order). Note that this will wreck culling though, so it’s best to make max. 100 groups of grass or so and flatten those individually.

(Note that flatten operation on a lot of grass is very expensive, and if you really have an infinite blades of grass it will also be infinitely slow.)

Also I don’t recommend making the grass billboards, this will make it seem like it’s moving when you’re moving. This is a good read:
http.developer.nvidia.com/GPUGem … _ch07.html

I’ve seen this chapter millions of times, I just don’t understand it :slight_smile:

This is a new tree for the grass:

  1. grass_1…grass_100
  2. grass_1_x1_y1…grass_100_x10000e1_y10000e1

grass_1 to grass_100 are dummy nodes and grass_count_xX_yX is the node representing a model.

and every grass_count is flattened.

Is it right?


OK, I’ve deleted the billboardaxis and some kind of magic happened. The slow-down has gone away! So, from this I understood that Billboard effect is done completely on the CPU, so my GPU is not that slow! Uff…

No, the idea is to flatten them all together, into one node.

Will this flattening cause the issue as in:
discourse.panda3d.org/viewtopic … ight=grass

?

Yes. But there are smart ways around it - for example by keeping 4 copies of the grass, each ordered in a different way, and fading between them based on the player’s angle.

Alternatively you can just use multisample transparency (or MBinary).
Also see this thread:
discourse.panda3d.org/viewtopic.php?t=5829

Can you explain a bit more on this trick ? I read it several times and still don’t get it.

Say, all the grass is flattened into one mesh.
Grass planes are sent to the GPU the way they are ordered. So from one direction, the grass will look fine, without artifacts.

So, I thought maybe keep 4 copies of the grass, but with the polygons in a different order. (I think you can reorder by rotating 180 degrees, flattenLight, rotating back.)
You can then fade between those copies of the grass based on the angle. So it will look good at all angles.
Downside: there will probably be popping, and the rendering cost for the grass is also doubled.

I have another idea:

What about pre-generating the whole scene and saving it into one bam file? Then just load everything into the “scene” node.

Yes, that’s a good idea, but that will only solve the generation/flattening time issue.

And what is the issue that isn’t solved by this?
I can’t remember any other.