• If you have a mod, tool or prefab, please use the Resources section. Click Mods at the top of the forums.

Prefabs optimization (Unity)

franksouza183

New member
Why are my prefabs (unity) heavier than the vanilla prefabs? How to optimize them?

I'm developing a modlet with new 3D models of vegetation, like grass, trees, etc, however I was surprised that I can not make a prefab lighter than, for example, a vanilla grass (treeTallGrassDiagonal).

I did the following test: I created a biome where there's only the custom prefab, with only 1 triangle, without material, without collision, with 100% probability, filling the entire biome. I've got 20-30 fps.

BbCi7Oa.png


Then I replaced this custom prefab with a vanilla, and the result really surprised me: 80-85 fps.

UwNbnYs.png


So, what am I probably doing wrong when creating a new prefab?

 
Last edited by a moderator:
Hmmm....this drop, probably, it shouldn't be too much. Despite the fact that the grass shaders are written with optimization.

My plants are easy for performance, but i haven't tested for 100% filling.

1. I must warn that filling 100% of the terrain with grass can cause "Structural Integrity" recalculation errors /i checked before A17/. (code of 7dtd)

2. Besides for the best drawing, in materials there is a checkbox "enable GPU instancing". Pay attention to it for improve performance on multi-drawing. (materials)

3. I think it may depend on the settings of receiving of the shadows. (materials)

4. have complex colliders?

If you wish - you can share your prefab (source) or at least a screenshot of the prefab settings.

I am not a experienced in Unity, but i will look at your problem with interest and help if I can.

 
Last edited by a moderator:
9i4ljQN.png


from blocks.xml

<block name="bushtest">


<property name="Extends" value="treeGrassMaster" param1="CustomIcon"/>



<property name="CreativeMode" value="Player"/>



<property name="Shape" value="Grass"/>



<property name="Class" value="Tallgrass"/>



<property name="Model" value="#@modfolder:Resources/test.unity3d?bushtest"/>



</block>


As you can see, no materials, no colliders .. the mesh is just a simple triangle, with one face. Yes, I know the problem with the estructural errors, it's just for testing purposes. Some settings that you recommend don't work, since we have no material on it. I'm really lost here, looks like we can't even match the optimization :(

 
well...then...maybe:

- need to try with material+texture.... (can be without material - the Shader is confused in work ?)

- don't use class and shape of grass - let it be a simple block.

 
Last edited by a moderator:
Thanks for the help, boys!

Guppycur, no, there's already a "native" LOD that affects the grass diferently than trees, even with a LOD configuration where we can see little ahead, still remains at a very low perfomance. n2n1's suggestion make some difference, when I put some simple materials (like the nature->speedtrre8 or mobile->diffuse) with "gpu instance" enabled, the fps jumps to 55-65, obviously the material have a huge inffluence. But these materials are bad for what I want: real vegetation look. The hidden shader generated by creator leaves (wich I use in every vegetation prefab), for example, has a very very bad performance. Still missing something, and that "something" is probably have to learn how to make shaders lol

 
Last edited by a moderator:
Real vegetation in 7days uses speedtrees, have you looked into that, other than just using its shaders? They also lod, but for some reason "better".

To tell a speedtree from a non speedtree, if it sways, it's a speedtree. A good example would be dust2death's hq mod that has both speedtree and non speedtree versions of plants.

My only experience with vegetation is when I did medieval mod, I imported some wheat I made into the game and some peoples computers would drop fps to like 5 when they looked at it. Then I started poking around, learned about lod's which then showed me each wheat plant had like 750k tri's or something ridiculous. It was all a huge learning curve for me. =)

At any rate, in addition to using the cheaper shaders, I /believe/ the pimps use an lod program and move the sliders in such a way that you have to be right on top of them to see the full textures. So, when on top of grass, full texture. When even a little far away, veeeryyy low version.

I could be wrong, I often am, but you'll want to use speedtree's anyway (not blocks) for plants, otherwise they REALLY stand out against the other speedtree's (they'll be the only ones that don't sway, and especially in rain, they'll stand out like a beacon).

 
I use the speedtree included in the Unity 2018.3 version, and there are no options for LOD adjustments around of it, except for the default LOD component, I always have to do it manually. In the first layer of LOD, I use the speedtree prefabs, the next layer onwards are just static meshes optimized according to their layers with the same speedtree material. TFP clearly uses the full version of speedtree, which makes it possible to use the speedtree8 shader (which is only useful in static meshes or prefabs with own animation in personal editing). I'm not a pro at Unity, and I'm finding out more every day. In order to have a smooth transition between each layer of LOD, it would require an adjustment in the shader speedtree, which the version used by TFP clearly has.

As can be seen in the screenshots below, I'm looking to create a denser vegetation, and I got a better performance in the trees compared to the vanilla ones, but I realized that it could be a lot better after I started these tests.

7gawpED.png


Cz50hRB.png


 
I don't have unity installed on the PC I'm using atm, but if I recall when you're looking at the "block" you should see the 4 or 5 levels in a bar graph (each level has its own color) for the LOD; this was on 5.3.8p2 though for a16, so I'm not sure if that's changed in 2018... and, I used a separate program to generate LOD's (it would combine hidden vertices and had a lot of other nice little features that helped)... that was only around $5 if I recall.

...but it honestly sounds like you've already done what I did, if you're adjusting them manually. What kind of performance are you looking for btw?

Just curious at this point, I doubt I can help you. Screens look good btw.

 
Yes, of course Lod will be needed. But as long as you use a couple of polygons, it doesn't make sense. So I didn't say anything about it.

If you do the grass then of course you have to try different shaders from available. But, unfortunately, there's little to those who shows the polygons at once on two sides.

As to the question where to get fast shaders:

- perhaps a third-party program to create trees, if they can export directly to Unity (e.g. SpeedTree and other) - will invest its optimized/fast shaders when exporting.

By the way, still - the best way to make grass now - is to add texture to the unoccupied place of the native atlas (via UABE)..

 
Last edited by a moderator:
Back
Top