Foliage Performance and Popping in.

Hey,

recently i have dabbled into foliage and despite of cutting my grass to cut quad overdraw, i still get alot of fps drops almost half from 120 fps to 70 on a 1080ti. I have tried doing custom lods but nothing was really satisfactory.I just have a hard time figuring out how people do grass over long landscapes and still get good performance. But the most annyoing problem is how obvious the foliage is popping in. I cant even see the quad overdraw as its all blue and even unticking z-pass in the project settings but it didnt help. Then I tried to use a distance fade in the material but the performance dropped heavy there and even had frame drops when the grass wasnt even rendered.

  1. Fps drop is normal. You are rendering a lot of stuff. check your draw-calls. (a 1080ti at 4k can barely manage 60FPS at epic settings on a finished and optimized game).

  2. exact poly, light tris count, small number of meshes. Using the Grass Node (ei, not the foliage tool).

  3. If it’s NOT all blue, you are doing it wrong.
    This is the light-map density view - useful to tell if the meshes are being randomly scaled by the grass settings (why the colors are different).

    ](filedata/fetch?id=1770676&d=1591206373)

What eats up most FPS is your landscape. Make sure the material you are using is in the green

](filedata/fetch?id=1770677&d=1591206519)
In .25 mesh HLOD coloration crashes the editor. consider using .24 to visualize the LOD ranges?

The most important thing to worry about is the composition of your grass mesh.
I’m using a clump of 1m x 1m.
A clump of taller stems of .5m x .5m
and variations of the same with different colors.

100 density on 1mx1m and 50 density on .5mx.5m (instances per 10m x 10m) is more then enough to give enough “body” to the grass.

Then you have variations. 10 density each, for “dead” grass versions in which the colors change.

Perhaps, the most important setting is that Dynamic Shadows must be disabled on the grass meshes - the shadowing is faked within the material.
It doesn’t necessarily need to be, but at high resolutions it eats processing power.

Another important optimization for the grass is texture packing. The least amount of samples = the best performance. AO, Roughness, and Specularity should be packed within the same image - and you still have the Alpha channel free for something else if you wanted to.
Personally I pack the alpha of the grass inside the diffuse. You may choose to set it inside the packed image instead for consistency…

The real fight is to create something that allows for the grass to disappear but you not notice that it is gone.
This is mostly done by matching the landscape color to the grass color, and using the PerInstanceFade amount in the grass material.


You pipe this in into the Opacity mask - under no circumstance should your grass be set to “Transparent” that really would eat up performance.
The value of B is the alpha mask of the grass mesh - or transparency.

To match the material to the grass, the best way I have found is to de saturate the materials, and lerp in the replacement color (or you could avoid de-saturate and use the green pin since usually grass is green…)
Hooking that value up to a MPC also allows you to create a change of season which is also nice to have for no extra cost.

You can also make two landscape grass types for one grass mesh. One is looks good up close, but fades out pretty quickly, the other is only for distance ( so much more sparse ) and fades out further away. That will stop the popping.

Another solution presented in the video From Ants to Outer Space is to sinking the grass into the ground following a distance gradient
ttps://youtu.be/xz-XBPjd2OY?t=2688

thank you, i will try this asap. But I am just confused. I look at youtube videos and old engine versions would fade the foliage in by default without any shader tricks. What changed?

examplehttps://youtube.com/watch?v=SNDfopeyek4
here is my quad overdraw viewport which cannot be correct as I do have cut the meshes to avoid overdraw but its not perfect. Still its showing blue and I have no way to optimize my grass:

and here is the mesh:

If the mesh is set to transparency then quad overdraw will show you the cost of the transparent area. But when you have it as masked there should be no overdraw. I guess? Its true that the view in .24 was slightly different for my own grass.

As far as the other vid, the fade is not very nice. Could have been done with foliage tool settings instead. But for the grass node to fade it the shader needs to know about it.

BTW, its hard to tell if your mesh is just planes or cut up parts. Can you share without a material?

hey thank you so much for your help. However I was wondering if theres some way to get the behaviour of fading in before 4.24? Screenshot - 9c792f9e23bec64de5b4d9e121e55325 - Gyazo heres the mesh only. It definitely has area that is transparent but like mentioned, cut up for performance. I get performance drops so I dont know why masked is showing me all green in quad overdraw, its almost there are no grass meshes? I think knowing how performant my foliage is is very vital for optimizing so I am very confused why it is not working :frowning:

Blue is the best result in quad overdraw view. It doesn’t use the same color scale as shader complexity.

This also looks like you’re staring at an empty scene. Normally there is always some quad overdraw at the edges of polygons, this is completely blank (meaning no quad overdraw at all) as if there is absolutely nothing in your scene.

The same fading code was working fine in .22.
Did you setup the Grass Instance fade distance inside of the Grass node?
​​They have a start fade and end fade parameter that allows you to control where they fade.

sorry yes, it shows all blue but I have a alpha masked grass but I still dont get any areas in quad overdraw: Screenshot - fd910e32c85d3ea0e37a315339264afe - Gyazo

EDIT: yes for some reason I dont get any information from my quad overdraw…
[USER=“3140864”]MostHost LA[/USER]

Inside grass node?

Has anyone tried hooking up foliage to the runtime virtual texturing system? That way the foliage can get baked down into the landscape material and the culling transition should appear seamless at far distances.

I have tried this out and it works, except that my foliage material does not accept masked materials when the Material Domain is set to “Virtual Texture”. Is this by design?

It’s way too complicated with a working version of a tiled landscape - at least until they fix it.
I have done it for a couple of tiles, but you have to take them away from the shared landscape, create a separate material and rtvt, assign it and compile. Duplicate the instance and change it… and just no. Not on 100+ tiles.

What I do is bake a grass texture made with the same or very similar mesh directly in Blender - as a render, so I have full transparency on the results.
Then I use Quixel Mixer to make the texture to use.

The material is created to match the colors based on a MPC anyway.

The masked material issue, could just be its not yet fully implemented…