Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Question Is it possible to make a shader and hide specific parts of a mesh sequentialy?

Discussion in 'Shader Graph' started by PaoloAm, Jun 9, 2022.

  1. PaoloAm

    PaoloAm

    Joined:
    Jul 15, 2019
    Posts:
    28
    Hello there,

    I hope someone can help us out.

    Some contest:
    It's a farming game where you place multiple machines down and you grow fruits and vegetables.

    Currently we are trying to optimize performances by doing the following:
    1. One single skinned mesh composed of multiple small plants grows with a blend shape
    2. Once the grow is completed the skinned mesh get disabled and we enable each plant mesh (not skinned) so that the harvesting looks more real and it's one plant at the time (like the image below)


    roboplant-seedling-harvesting.png

    We have two issues:
    - having all those small mesh renderers is still not the most performant solutions
    - if the plants dies when the plant is still growing then we don't have a way to let the worker clean it one at the time. Unless we change it the full grown version but it would look ugly.

    So, I was thinking, is there any shader graph we can make that given a fixed map (each machine have specific spots where the plants can grow) hide entirely one single plant based on a value passed?

    Thanks and have a great day,
    Paolo
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,582
    That is game design issue. Nothing to do with shader.

    Try DrawMeshInstanced
    https://docs.unity3d.com/ScriptReference/Graphics.DrawMeshInstanced.html
    Or
    DrawMeshInstancedIndirect
    https://docs.unity3d.com/ScriptReference/Graphics.DrawMeshInstancedIndirect.html

    You should gain significant performance this way.

    Is this for a mobile hardware?
     
    PutridEx likes this.
  3. PaoloAm

    PaoloAm

    Joined:
    Jul 15, 2019
    Posts:
    28
    You are totally right, we are trying to think a possible workaround for this.

    Wonderful thanks, I'll look into this, maybe there is a way to combine it with a plant growing as well.

    Desktop but imagine when you have 40 of those tables, each one with multiple plants. Just by using one single skinned mesh with all the plants growing instead for a skinned mesh for each plant improved massively the fps.

    It's also true that it's our first commercial game so we are learning performance optimization techniques while we move forward :)
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,582
    Maybe if you consider handling 100s and 1000s of plants, perhaps it is worth look deeper into optimization as next level. That is providing CPU is a bottleneck.

    You could try to investigate DOTS.
    Multithreading using Jobs, and Burst, could improve performance tremendously for you.
    But the downside is, you would need to switch into Data Oriented Design. If your team is not familiar with that, it may imply additional dev cost and time. So need be discussed carefully within your team members. DOTS may have a quite steep learning curve, if never worked with it.

    You could even dive into DOTS ECS, but is not required for your need. It is extra level of optimization. Something to be considered in future maybe. ECS could help you handle with rendering. But you potentially loose some of tools. I.e animation Unity API, as DOTS animation is not ready. ECS is also in preview and works only with 2020 atm.

    Either way, you don't need go full DOTS. You could use it to help optimize certain systems and mechanics.
    For example grab plant growing mechanics and try optimize it, using jobs parallelization and burst. And operate on NativeArrays, or other native collections.
     
  5. PaoloAm

    PaoloAm

    Joined:
    Jul 15, 2019
    Posts:
    28
    Thanks for the tip, I looked into DOTS before starting this project but due of my inexperience with it I decided to stick with the old system, but for the next game I will want to use it. It's our first commercial game and we need to go live in the next 8 months so hopefully your previous suggestions should be enough.

    I didn't know you could partially use DOTS, I'll look into that if we can't optimize enough.
     
    Antypodish likes this.
  6. PaoloAm

    PaoloAm

    Joined:
    Jul 15, 2019
    Posts:
    28
    I just did a quick test on the game using the API you suggested and with 20 machines and 10k instances of plants we went from 35fps to 55fps, wonderful tip!

    It will take a lot of refactoring work but it also solve the first problem since I implemented a way to remove one plant at the time based on the percentage of progress.
     
    Last edited: Jun 9, 2022
    Antypodish likes this.