Search Unity

Performance tips for low-poly style

Discussion in 'General Graphics' started by Pagi, Oct 29, 2017.

Thread Status:
Not open for further replies.
  1. Pagi

    Pagi

    Joined:
    Dec 18, 2015
    Posts:
    132
    Hi,
    We're making a dungeoncrawler with generated maps made of tiles.
    We are going for a flat shaded low-poly style. On first try I made a mesh with kinda high polygon count(3000), and meshes like this one will be used in dozens to hundreds in the scene. A little test on my integrated GPU immediately jumped to 20fps.
    Bez názvu.png
    I tried using deffered lighting and a simple diffuse material, but it didn't help much.
    Any tips on getting playable framerates, or will I have to make less detailed meshes?
     
  2. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    28,156
    You are underlining useless information in the screenshot. Your real damage dealer here is the setpass count. It's way too high and you should look at getting that and batches a bit lower.

    You've provided far too little information about how you're setting things up. There is no magic bullet if there's no target. So I am guessing, but I don't think the GPU is working especially hard. The CPU is working very hard. This means you have major inefficiencies with materials and nothing is being batched and you didn't really use deferred under ideal conditions.
     
    theANMATOR2b likes this.
  3. Pagi

    Pagi

    Joined:
    Dec 18, 2015
    Posts:
    132
    Thank you for the fast reply!
    I saw the setpass calls and I agree it's horrendous. The models are just dragged and dropped into the scene, all have the same material - Legacy diffuse. I think the problem is either that the material isn't shared between the models, or the lights drive setpass calls so high. Because of that I tried setting rendering to deferred, but it didn't seem to help much.
    Also all gameobjects are marked as static, but they will be spawned at runtime, so I don't know whether it applies. All models use the same palette texture too.
     
  4. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    28,156
    It doesn't really apply but you can manually batch things at runtime. In any case setpass would be low and batches high if it wasn't switching materials. So I think you need to look closely - are you modifying materials at all at runtime? if so you are probably instructing Unity to create a clone of the material. When game is running in editor, pause it and look at the scene properly. Are the walls using (clone) materials? Can they be moved (ignoring static batching) etc. Lots of info for you to look at.

    You want to first sort out material inefficiencies. This is what is contributing to large setpass calls. Batches isn't a bad thing if setpass is low. Because a gpu can easily plough through similar batches, but it has to stop and set things up with a setpass.

    In any case, the CPU is the one being stressed here, not the GPU.
     
    theANMATOR2b likes this.
  5. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    28,156
    Once you sort it out so your setpass is much lower, you need to look at using a shader to give you the faceted look, not splitting everything when everything is high poly. This is suicide for performance. A shader, or even great crisp normal maps will give you back the sharp edged polygonal look you're looking for without a performance-draining hack.

    (The normal maps approach can even let you lower your poly count and you would probably want to split no verts at all with this approach, dramatically lowering gpu cost).
     
    theANMATOR2b likes this.
  6. Pagi

    Pagi

    Joined:
    Dec 18, 2015
    Posts:
    132
    Bez názvu.png

    I noticed leftover cages from blender, they may have caused the setpass calls even though they had no triangles, only edges. So setpass calls are down, but 30ms cpu is still pretty high. The materials aren't clones and there are no scripts at all, even post processing is disabled. Meshes are batched fine too. Atleast on forward i get almost 60fps.

    With the second post, you mean I should make the meshes share vertices and then use some geometry shader to fix it? Isn't the shader heavy for older PCs?
     
  7. nat42

    nat42

    Joined:
    Jun 10, 2017
    Posts:
    353
    The batching limitations seem a bit rough: https://docs.unity3d.com/Manual/DrawCallBatching.html (his polygon counts are too high for dynamic batching according to that?) if a small number pallette of objects will be repeated many times would instancing be better https://docs.unity3d.com/Manual/GPUInstancing.html

    I like the idea of forward rendering with this art style you can prob do per vertex lighting and get away with it looking good even. Somewhat odd you can get almost 60fps with 30ms of CPU per frame, or does that change with forward?
     
  8. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    28,156
    No, no geometry shader is needed. Looks like the stats window is all within reason for a mobile title, let alone laptop. So that's all fine.

    At this point the bottleneck is something else so you would probably want to use profiler. If deferred is slower and forward is 60, you probably should stick with forward :) most of the CPU time at this point will probably be something else, or even vsync (which you don't need to be fixing).

    It could be the device is truly pants. What are you running it on?

    I'd say stick it on forward and be done with it. Test it once or twice with vsync off, to check how much it's really flying.

    Only thing to watch out for in forward is not to use lights that are too big in radius, that would cause to many things to be overdrawn at once (in forward each object is drawn multiplied by the number of however many lights touching it).

    TLDR: if profiler isnt immediately telling you what highest ms is being spent on at this point, it's probably just your laptop
     
  9. Pagi

    Pagi

    Joined:
    Dec 18, 2015
    Posts:
    132
    I will stick with forward, it runs fine now.
    Thank you for your time, have a great day.
     
  10. Ironmax

    Ironmax

    Joined:
    May 12, 2015
    Posts:
    890
    Normal maps with really high ress does stress the GPU pretty much since it will generate polygones up in tangent space even so your model is low poly. Also shader has a very important role for your FPS performance, since this are the instructions for the GPU. What type of GPU you have also matter (you said you use integrated GPU, on laptops does aren't the best. Yeah forward is by standard with Unity and performance best, but not the solution to your current issue. Lower texture size on the normal maps / displace map. and see what FPS you get. Also make sure your GPU it sett to maximum power in the windows power management so it doesn't trikel down.
     
  11. nat42

    nat42

    Joined:
    Jun 10, 2017
    Posts:
    353
    They aren't using normal or displacement maps, it's all polygons.
     
  12. nat42

    nat42

    Joined:
    Jun 10, 2017
    Posts:
    353
    It's several 3000-ish poly mesh tiles reused, they have spelled that out in the thread. The screenshot has post processing effects - looks like a chromatic aberration effect?
     
  13. Ironmax

    Ironmax

    Joined:
    May 12, 2015
    Posts:
    890
    postprosessing does not generate tangentspace.
     
  14. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    28,156
    But you are the only person in the thread talking about tangents.
     
  15. Ironmax

    Ironmax

    Joined:
    May 12, 2015
    Posts:
    890
    I am sure Pagi can explain what was done in that screenshot him self, when he say flat low poly and post a screenshot
    with stones extruded that can only mean normal mapping or displacement. Else its not flat low poly.. its only logic..

    If he did use mesh , he should consider normal mapping instead, since the GPU has
    optimization for this in pixelshader,.

    I hope his performance will be better with some texture handling. Looking good so far.
     
  16. Ironmax

    Ironmax

    Joined:
    May 12, 2015
    Posts:
    890
    I want to point out, that on low GPU hardware its better to simulate things with texture than geometry. Programs like 3D coat can render gemotry in to normal maps and trippel the performance with low poly objects with normal map based from a high polygone object.

    This is pretty much standard now days ..
     
  17. Pagi

    Pagi

    Joined:
    Dec 18, 2015
    Posts:
    132
    Yes these are basic models sculpted and decimated in blender. Colors by UVs from color palette, no normal maps. I know I could bake details into normal map, but it just isn't the same, I want real 3D details if it is possible.
     
    Suddoha and hippocoder like this.
  18. Ironmax

    Ironmax

    Joined:
    May 12, 2015
    Posts:
    890
    Hi Pagi, i understand, then the performance is pretty much self explanatory and very little you can do in Unity (other than turn off shadow and use forward render) Texturet/materials will not change things to the better. The GPU renders every geometry that is in the frustum range, you can also try to cull objects by distance if your whole scene is based on high polygone objects. Try also on another computer, maybe its just the GPU you currently using.

    That said, i think you be surprised how well/real normal map can simulate geometry (try displace map) , since you acutely get increase poly by texture in tangent space. Its just allot faster :)

    You can also bake geometry objects, to increase performance,
     
    Last edited: Oct 29, 2017
  19. Ironmax

    Ironmax

    Joined:
    May 12, 2015
    Posts:
    890


    Here you see an object that is low poly to the left, and same model to the the right with normal map based of the high polygone object.(they pretty much look exactly the same).
    http://wiki.polycount.com/wiki/Texture_Baking
     
    Last edited: Oct 29, 2017
  20. Ironmax

    Ironmax

    Joined:
    May 12, 2015
    Posts:
    890
    higher polycount = lower framerate. take any GPU.. Theres more than 3000 in that scene, if you look closely he have copied objects around. so i guess 3000 on each object. multiplied with each.

    It was 1.6m trio so yeah...

    Culling is also pretty much important.
     
    Last edited: Oct 29, 2017
  21. Ironmax

    Ironmax

    Joined:
    May 12, 2015
    Posts:
    890


    Here is another. Just a hint.. Blizzard texture bake all there models.
     
  22. nat42

    nat42

    Joined:
    Jun 10, 2017
    Posts:
    353
    I've deleted my posts as offtopic, I don't want to play any part in derailing the OP's thread
     
    hippocoder and Ironmax like this.
  23. Ironmax

    Ironmax

    Joined:
    May 12, 2015
    Posts:
    890
    Anyways.. god luck with your dungeon crawler Pagi, atmosphere looks good, i gave you all the tips i know in the book.
     
    Pagi likes this.
  24. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,825
    They want a flat-shaded style. What you're showing is a fundamentally different style of shading, as it involves other lighting models and therefore different shaders.
     
    theANMATOR2b likes this.
  25. Ironmax

    Ironmax

    Joined:
    May 12, 2015
    Posts:
    890
    Defuse map have nothing to do with normal maps. Its just doing the subdivision in GPU for you instead of doing it in geometry. There is then no problem to make a flatt shader with simple surface without defuse texture but with normal mapping. "I hope your not hijacking the thread, i think Pagi have received the tips he needed, unless you have something to contribute with.."

    Normal mapping passed 2.0 pixel shader is more than just a bump simualtion, its acutely additive geometry based on the normal texture. This is handled very differently in GPU memory than normal texture
     
    Last edited: Oct 29, 2017
  26. Ironmax

    Ironmax

    Joined:
    May 12, 2015
    Posts:
    890
  27. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,825
    You're posting things he's oviously aware about, but not much interested in.

    Flat-shading is an established term in computer graphics and refers to a technique and style that does not rely on faked information such as normal maps, instead its lighting is based on the actual existing mesh-data, so clearly not a faked one that's baked into a texture.

    If you add normal maps, you no longer have pure flat-shading.
    This thread is neither about 'what is a normal map' nor 'how to apply normal maps' nor 'how to fake the details'. The OP apparently knows about all of this and they've decided they want to have flat-shaded low-poly style.

    I'm going to stop at this point, as I know that this is going nowhere.

    @Pagi I'd also consider LODs. You can keep the flat-shading approach for near objects and take a way cheaper alternative for tiles that are not as close to the camera.
     
  28. LogicVision

    LogicVision

    Joined:
    Oct 28, 2017
    Posts:
    4
    I don't know what is your purpose of entering this thread (and others) other than causing nausea. You can make flatt texture surface with normal map tangent space subdivision just fine. Texture actually means surface, normal map has to do with geometry and subdivision, what you do with the surface render is up to the shader. So you can make a plane flat surface that comes from a normal map just fine. The examples Ironmax here posted clearly proves this.

    Saying normal mapping is a fake information just proves how little knowledge you have on the subject. The light simulation is fake, the geometry is not. Trying to teach Ironmax that has over 15 years of computer graphics experience is just pointless.

    Here is a picture taken from Nvidia explaining geometry mechanics.

    What your saying is just not true..

    In the way you talk i have the feeling you been gooling Normal map on wiki, that does not cover GPU related normal mapping..

    Here is more correct documentation for you:
    A normal map is a texture that stores normals. These normals are usually stored as unit-length vectors with three components: X, Y and Z. Normal mapping has significant performance benefits over bump mapping, in that far fewer operations are required to calculate the surface lighting.

    http://www.nvidia.com/object/real-time-normal-map-dxt-compression.html
     
    Last edited: Oct 29, 2017
  29. Ironmax

    Ironmax

    Joined:
    May 12, 2015
    Posts:
    890
    To clean up the misinformed, a polygon is flat, a normal map actually stores the normal data, there is no fake data here.
    The normals extends the geometry up in tangent space making it receive the same light as the rest of the geometry.
    Its not like when you include a normal map the surface becomes bumpy or smooth, it can be completely flat, its vector data not light model limitation. If you want to make a unlit shader that's fine, you can still access the normal data, the same you can do with normal geometry data.
    Code (CSharp):
    1. fixed3 norm = mul((fixed3x3)UNITY_MATRIX_IT_MV, v.normal);
    2.   fixed2 offset = normalize(TransformViewToProjection(norm.xy));
    Just some simpe shader explaning use of normals (not normal map, and its a vertex shader not even surface with light).
     
    Last edited: Oct 29, 2017
  30. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,825
    Hello IronMax (or colleague).
    Do you (or both of you) ever read what you're actually posting? Stop spreading information out of context or just completely wrong information.

    Flat shading has nothing to do with normal maps. It's purely based on mesh-data. That's a fact. Every beginner in a modelling program does know that.

    The image in your post says "Flat shading using generated normals". Do you know what it means?
    It's exactly what flat-shading is about. It takes mesh-data and calculates the normals for it in order to render it flat-shaded, it does NOT use any normal map nor any other texture for it.

    I don't know why you always try to re-define every single term that you come across just a day before, it's just wrong and unprofessional.

    Unbelievable he's been (or you've been) doing this for 15 years, given that you get so many things wrong in its fundamental basics and yet think you're an expert on this topic.

    Again we're hijacking a thread, but seriously. It is so annoying when you post wrong facts in a community where a lot of people are trying to sharpen their knowledge and ask for help. Get your facts straight.

    It is faked, because it only does exist on the reference object it's been created from.
    These information do not exist on the low-poly model, thus they are "faked" (or if you want so, simulated) to give the visual illusion of greater detail.
     
    theANMATOR2b likes this.
  31. Ironmax

    Ironmax

    Joined:
    May 12, 2015
    Posts:
    890
    Looks like this thread have been hijacked.. i end the ignorance here ..
     
  32. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    28,156
    LogicVision and Ironmax have identical ip addresses, so I am locking this thread. Sorry for any inconvenience @Pagi and please do post if you are having further questions or just for fun.
     
    theANMATOR2b likes this.
Thread Status:
Not open for further replies.
unityunity