Search Unity

Question Should I do Occlusion Culling manually through script?

Discussion in 'General Graphics' started by FOXAcemond, Dec 21, 2020.

?

Do you think I should do that?

  1. Yes, sounds good

    4 vote(s)
    100.0%
  2. Actually, there's better

    0 vote(s)
    0.0%
  3. Something seems wrong but since I don't know the specifics of your project I won't comment

    0 vote(s)
    0.0%
  4. No, activating and deactivating the renderer will murder framerate

    0 vote(s)
    0.0%
  5. What is a mesh?

    0 vote(s)
    0.0%
  1. FOXAcemond

    FOXAcemond

    Joined:
    Jan 23, 2015
    Posts:
    99
    Hello,

    In my project I have shaders such as sometimes a lot of objects are not visible, though are on camera.
    I've seen in the performance analyzer that the meshes were still rendered counting for a lot of additional useless vertices (almost double).

    Since I can accurately predict when they are visible and when they're not, I think I have to cull the meshes "manually" through script. Is that the right approach?

    Code (CSharp):
    1. meshRenderer.active = meshVisible
    Did I miss something?
     
  2. BattleAngelAlita

    BattleAngelAlita

    Joined:
    Nov 20, 2016
    Posts:
    400
    Yes, manual culling work nice.
    Code (CSharp):
    1. meshRenderer.forceRenderingOff = !meshVisible
     
  3. FOXAcemond

    FOXAcemond

    Joined:
    Jan 23, 2015
    Posts:
    99
    Are there other benefits in using
    forceRenderingOff
    appart from the separation of responsibility? (like not displaying renderers that were set to off in the inspector).

    I will use your property to avoid this kind of mistake but I'm wondering if there are other side effects.

    Given Unity documentation, it seems this property was designed specifically for this purpose so that is perfect!