Search Unity

Questions about Game modelling and optimization

Discussion in 'Game Design' started by marti1599, Dec 2, 2022.

  1. marti1599

    marti1599

    Joined:
    Dec 2, 2022
    Posts:
    2
    Hi to all, i am always been insterested in videogame and as a developer i decided to learn how to create one. I decided to start during the 2020 pandemic but i started with a too big project that i gave up. Now i decided to retry with the main focus on learn instead of create my drem game.
    As a solo developer i write scripts and create 3d models. I learned to use Blender with my first game but some optimization questions pop up in my mind for optimize 3d models. I have searched online but i didn't find answer to my questions.

    My questions are:
    1.1 - What affects the performance of a 3d model?
    As i know the performace is better with low vertex count and low draw call (textures).
    1.2 - There are other things? For example one thing that pop in my mind is the texture size.
    1.3 - So If i need to make a list from the most important thing to optimize to the less which will be the order?

    As i know triangles and ngos are bad because they can cause problems on render, can cause errors on smooth and can create deformations.
    2.1 - Is better to add useless vertices (increase the vertex count) or a triangle/ngos?

    3.1 - If i wanna extrude a cube is better to add edge loops and extrude or cut and extrude? Because with edge loop i will increase a lot the vertex count.
    Using the attached images as an example starting from img1 is better img2 where i add 4 edge loops or img 3 where i cut the face?

    4.1 - For big mesh like an house is better to subdivide it in multiple meshes or to have 1 single big mesh?
    With multiple meshes i have more draw calls but the textures can have more details and are smaller. With 1 big mesh i have less details (i can create a big atlas like 8k image but it takes a lot of time to bake) but less draw calls.
    For example in when i developed my first game i made houses with objects inside for have 1 single mesh and reduce the draw call (i was dumb, i could make them separate and merge in a single object later)

    5.1 - When use atlas texture and when use single textures? For example for an house is better to use a big atlas like a 4k image, use more atlas like 1k images or use all different images for every material?

    Sometime the idea of buy a graphic tablet pop in my mind but i have never undestand how it could be useful as for use it you need to add a lot of vertex and after reduce it (using the decimate tool).
    6.1 - I think using it the model is not optimized right?
    6.2 - In which case a graphic tablet is useful?

    I put the numbers for let your answer better.
    Sorry if there are errors, i'm learning english and it's 3 AM.
    If you have a tutorial, a book, a guide or something that can help me answer those questions and learn how to optimize a 3d model feel free to link them.

    Thanks for your help and for your time
     

    Attached Files:

  2. DimitriX89

    DimitriX89

    Joined:
    Jun 3, 2015
    Posts:
    551
    1. It varies greatly depending on many factors. As a rule of thumb, adding a thousand more faces will affect performance less than, say, adding extra shader effect (like normal map), or increasing the texture resolution to a next power of 2 (like, 512 to 1024). Impact of a mesh compexity changes depending on what you do with the mesh. If the mesh is static, then it is negligible. SkinnedMeshRenderer is, of course, less performant; the cost of vertices will be multiplied by number of bone influences per vertex and number of blend shapes affecting it. The biggest impact vertex count will have on scripted mesh deformations: they are calculated by CPU and a script will have to iterate through each vertex in linear fashion. If you need some custom geometry deformer in your project, prioritize coding it in shader instead of C#. This way, the calculations will be performed by GPU, in more or less parallel fashion. And I think that the priority of optimization (from highest to lowest) should be 1)shader complexity (number of texture maps, performance in the shader itself (like, do not use Standard for self-illuminated object when Unlit is enough)); 2)texture resolution; 3)extra mesh data, such as number of bone influences and blend shapes; 4)vertex/face count of a mesh (general guideline is "the least number of faces that looks good").
    2. If those vertices are, as you say, useless, then better to add faces, I guess? They will at least contribute to the look.
    3.Generally, only the end triangle count matters. From the visual standpoint, picture 3 will look the worst if you use smooth shading (there is uneven triangulation). With flat shading, it will hardly matter
    4.If making a house as multiple objects is convenient for you, then look into Unity feature called "static batching". It can merge multiple static objects into single draw call if they share a material. You can also use a single big mesh, but in this case, better to utilize techniques such texture tiling, atlasing and decals instead of a huge individually unwrapped texture
    5. Atlas is preferable when multiple objects that share atlas material appear on screen at the same time. In this case, it will help reduce draw calls. A house or other interior (such as modular dungeon pack) will be a good use case for the atlas. If you mix and match assets from different creators, however, better to look for models with individual textures. Since if there would be an atlas, that would mean you are loading a huge texture to display only the fraction of it.
    6. Decimated sculpts are useful for prototyping (in case you replace them with good topology later), and, in some cases, for static objects (provided that the game is for powerful enough platform). (Photogrammetry, such as popular Megascans, utilizes similar triangle soup topology). Other remesh methods, such as Quad remesh or Zremesher, are marginally better, but still largely a self deception if you use them on deforming objects such as characters. Compared to hand crafted topology, remesh will need more triangles to look as good, and may introduce other problems, such as bad UV seams placement. The best practice is to retopologize by hand and bake normal maps (or displacement maps if you find out how to use them in Unity)
     
    Last edited: Dec 2, 2022
    marti1599 likes this.
  3. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,005
    I tried to answer as best as I can - I am not an artist but worked with a lot of them on several dozen projects for mobile, desktop, web, vr, ar, embedded and "special" platforms.

    Overall I have to say that most questions have no easy answer and require experience. So my advice is to keep those things in your mind but don't let them dictate how you work. Your early work will always be rough around the edges. It's more important to get more modeling workflow experience and if you notice anything starts falling apart, investigate and come up with a solution as the issues surface. Trying to preemptively avoid all possible pitfalls as a beginner will have you waste a lot of time and not actually learn that much compared to just going about your business and creating stuff. ;)

    Eventually you may work with a team and on a specific project and there will be guidelines (eg polycount limit, texture size limit, etc) and helpful mates pointing out that you're doing too much of this or could use that feature to speed up your work etc. You'll learn most from working with others!

    A lot of things. And depends heavily on the target platform. For example, on desktop vertex count is a low priority thing, whereas it is a high priority thing for mobile and low-end (integrated GPU ie notebook) desktop apps as well as WebGL. Also the app dictactes that - if you only ever have a single model (eg product showcase) it can be super detailed but if you want to build a city like GTA you need to be more careful and also come up with limits for each LOD mesh.
    Across the board the most important aspect is probably making use of a single or only few materials per model because that helps batching.

    Texture size is not (really) a performance issue, it can be a GPU memory usage issue though and on integrated desktop GPUs it can be a performance issue because for those, GPU memory is actually regular (slooooow) RAM. Again, this depends on target platform.

    Depends on target platform. ;)

    Depends on use case.

    I don't have the expertise on that. But I would expect Blender to be able to combine faces at a later time that don't add detail to the surface. So it may actually just affect the workflow.

    Depends on use case - size and complexity of the house, and how many of these you will have in the view port at most. Generally try to prefer whatever helps to reduce draw calls, but avoid doing so where it adds a lot of hard work and causes issues with programming.

    Prefer as few atlases of the largest size. Ideally just one. It may grow up to the max resolution recommended for a target platform but also keeping in mind how many unique models you'll have in a scene => monitor GPU memory usage.

    Some simply prefer it and try to avoid using the mouse. So it can simply be a matter of choice.
    Generally speaking, it's mostly used for drawing, sketching and sometimes interacting with static interfaces where every item remains on a fixed position so muscle memory can be trained to quickly find and hit specific buttons or whatever. For that reason some prefer tablets even for business simulations (Gear City and such) or turn-based / slow-paced strategy games (Civilization and such).

    For modeling I would say it's not that useful. There are specific modeling controllers though which help navigating in 3D space and such. If anything I'd look into those.
     
    Last edited: Dec 2, 2022
    marti1599 and DimitriX89 like this.
  4. DimitriX89

    DimitriX89

    Joined:
    Jun 3, 2015
    Posts:
    551
    I may be wrong, but won't it affect the number of calculations a pixel shader does?
     
    BrandyStarbrite and marti1599 like this.
  5. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,005
    Probably slightly depends on the view distance of the model but mostly it's not a performance issue. If the model is very close to the screen more texture pixels need to be processed, but at the same time that model will have more of the other geometry culled so it probably isn't going to negatively affect performance regardless.

    If you have a triangle on the screen that spans a certain area (say 10k pixels), then the number of pixels in that area determines performance, not the resolution of the texture of that triangle. The GPU and shader would need to process 10k pixels in both situations, and would look up in the triangle texture only the pixels needed. So bumping the resolution from 2k to 4k requires four times the computational power to get to the same fps. But bumping all 2k textures to 4k textures will hardly affect performance at all AS LONG AS all those textures still fit in GPU memory and don't need to be constantly swapped in/out as some game engines do these days (ie id Software's Megatexture system and I believe Unreal 5).
     
    marti1599 and DimitriX89 like this.
  6. DimitriX89

    DimitriX89

    Joined:
    Jun 3, 2015
    Posts:
    551
    Got it, thanks for explanation. So instead of keeping individual textures as low as possible as a no brainer, a dev should plan their sizes according to the potential display resolution?
     
    BrandyStarbrite and marti1599 like this.
  7. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,005
    Actually GPU specs is more important, and install size.

    For desktop apps you usually get the "(max) texture size" option in video settings to accomodate GPUs with wildly varying memory sizes and for built-in GPUs it's also a performance setting. You could offer gamers with high end GPUs the 8k texture resolution that way (ultra setting) but because these textures take up so much space, some games actually offer to download optional ultra-high-res texture packs that in itself can be somewhere between half to double the regular game's size!

    But of course it wouldn't make sense to have 8k textures on a mobile phone despite retina resolutions because the screens are relatively tiny and most models won't be close enough to the camera that it would make a difference. Some ultra texture resolutions in desktop games only swap in the ultra texture at in-game distances of (my gut feeling estimate) 2 meters or less.
     
    marti1599 and DimitriX89 like this.
  8. BrandyStarbrite

    BrandyStarbrite

    Joined:
    Aug 4, 2013
    Posts:
    2,076
    When you say cut, I think you are talking about the knife tool in blender. Am I correct?

    Using Cut is okay if it is not overused, but if used incorrectly, it sometimes does stuff to a 3d model, that causes some game engines, to have a hard time processing the geometry.

    I would highly recommend adding edge loops and extrude. This is the safer option.
     
    Last edited: Dec 3, 2022
  9. DimitriX89

    DimitriX89

    Joined:
    Jun 3, 2015
    Posts:
    551
    Any specifics on the "stuff" Knife tool does? All poly editing tools in Blender generate same triangles and vertices. The only way to create difficult to process geometry is to have absurd number of them
     
  10. BrandyStarbrite

    BrandyStarbrite

    Joined:
    Aug 4, 2013
    Posts:
    2,076
    It sometimes creates double vertices in the object that you are modifying, that are sometimes not noticeable. And that can sometimes cause odd rendering problems, and strange problems with textures, when the object is in unity.

    Also, last time I used it, the tool had a few weird bugs as well. I know the blender team has improved it a bit over the years, and it works alot better than before. But adding a few edge loops, and then extruding faces, is the safer option.
     
    Last edited: Dec 4, 2022
  11. DimitriX89

    DimitriX89

    Joined:
    Jun 3, 2015
    Posts:
    551
    Double vertices are noticeable (shading will be corru[pted) and trivial to fix. No reason not to use Knife
     
  12. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    IMHO a lot if these questions are YAGNI if you are trying to make a first game, one bottleneck when designing games from scratch for a first game is decision bottleneck, aka analysis paralysis. Don't try to make everything good on a first try. Especially if you are going to model, program and design everything yourself.

    For context on modeling. Most desktop gpu today are in the range of at least ps360 wii I switch level of power. Game in that range has millions of polygons on screen with character going as high as 50k poly. Character start looking good and fully articulated at 2000 poly, older generation fighting games like dead or alive 3 had 8000 poly and taken tag tournaments had 10 000 for reference. Past that point, extra poly goes to cinematic facial, hair, cloth sim, and extraneous details like modeling button.

    People stop counting poly there because pixel complexity (shader, post process and light effect like shadows and number of lights) aka fillrates, started taking over (also unified shader made vertex count less rekevant). Pixel quality, especially light influence, has a bigger effects now, so alpha coverage (think transparency, foliage, hair) are a bigger concern.

    Texture size are a problem for bandwidth and memory pressure, they don't affect pure rendering performance as much, every time you query a texture there is a bandwidth tax, so minimizing access (sampling) help a lot on low end. Ps360 game tend to use 256 - 512px Texture on average. Even hi quality modern game stay on that range because pixel complexity contribute more to looks, and we have more type of Texture layer to sample to achieve quality (like albedo, normal, metallic, etc), square Enix for example use 512 for character plus detail map at 256 to get a look that emulat 8k textures, in practice with all the needed layer it's equivalent to simple hirez color map as memory pressure, we just use more map now.

    The question is, are you making a last of us quality of game? Probably not as a first try I wouldn't recommend. I wouldn't recommend to focus too much on complex facial and hair, complex texture effects etc... a sweet spot is the ps2, gc, Xbox, wii Era, but with modern shader sugar, before that low poly is too low (500 per character) and is harder to do because you need constant optimization, it's the haiku of modeling.

    So given these data, I would recommend to start with something that's easy and comfortable to work with to gain progressive experience. The reason to go low poly is to have less decision pressure, such has not having to deal with optimization at the same time you are making the first game, that would be a distraction.

    So focus on making good visual within the range you know all gpu will operate with, good topology is great, but do things that makes comfortable first, you will pick up good practices by doing.

    For example it's okay to waste some uv space and use automated unwrapping with slightly bigger texture rez if that save you time and you don't have that much objects. If you don't fill the performance threshold, it's okay to be a bit wasteful to have a faster dev cycles. Finishing a game is more important that doing everything right.

    The common mistakes people do while going low poly is to over optimize the mesh and texture, but still use complex shader that tanks low end, because flat colored hirez textures with 50 lights and cast shadows on a pbr pipeline with heavy post process effects eats the performance while not adding to visual that much. It end up heavier than a last of us game with none of the impact. Because visual complexity does not equal pixel and performance complexity.
     
  13. marti99

    marti99

    Joined:
    Feb 25, 2018
    Posts:
    3
    Thank you for all the answers and the time.
    I know that focusing on performance and optimization for the first games is bad. My goal is not to create a triple A game but during my old modelling experiences those questions pop up in my mind and online i found only approximate answers. So mine is just curiosity for know how things are done in a working environment.
    Right now i don't have new questions so
    if I can think of any new one i will post it here.
    Thanks again for your time and help
     
    BrandyStarbrite likes this.