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]
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.)
I’ve seen this chapter millions of times, I just don’t understand it
This is a new tree for the grass:
grass_1…grass_100
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…
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.
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.