Search Unity

Resolved renderer.isVisible and void OnBecameVisible() are always true in Occlusion

Discussion in 'General Graphics' started by Volchok, Sep 10, 2021.

  1. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    Please tell me why renderer.isVisible and void OnBecameVisible() always true? I checked both in Unity Editor and in Build - always true, although Occlusion disables these portal planes.



    I need to somehow disable/enable OnPostRender() on cameras which retranslates the views to the portal planes, if the portal planes are not visible in Occlusion.

    But I can't do this and Unity consumes a lot of resources, constantly displaying the image of all cameras on all portal planes.







    Of course, I can use raycast from the Z axis of the character into the portals - but this is wrong way.
    How can I understand that Occlusion has disabled / enabled the Mesh Renderer of Portal Planes?
    And why renderer.isVisible and void OnBecameVisible() always true?

    Thanks!
     
  2. SugoiDev

    SugoiDev

    Joined:
    Mar 27, 2013
    Posts:
    395
    As far as I remember, the scene view camera counts as a camera, so if the scene view is seeing the objects, then they are considered isVisible will be true.

    Maybe try closing the scene view and looking only at the game view to see if it works.
     
    T-SaWer00, Kbozz and Volchok like this.
  3. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    I also had such thought and it looks like the truth, but then how can I disable the OnPostRender() of cameras if Occlusion does not see the portal planes?

    To use raycast from the character into all portals in Update()? But this is not normal!



    The most interesting thing is that I only need a flag - whether the object was hidden by Occlusion or not - and it turns out to be so difficult! It looks like some kind of cheat. Why then does the isVisible flag exist if the object is hidden on the scene, but it is shown somewhere inside?

     
    Last edited: Sep 10, 2021
  4. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    This is a very strange situation. Even if I turn off the cameras, Mesh Renderer.isVisible shows true. But still, sometimes, because of solar flares, isVisible = false appears, but extremely rarely and according to incomprehensible rules.

    I read this post:

    how to specify object for Renderer.isVisible?
    https://forum.unity.com/threads/how-to-specify-object-for-renderer-isvisible.472777

    ... I did absolutely the same - it does not help.

    :eek: It does not work in either the Unity Editor or the Build Version.
    :eek: Even if the cameras are turned off on the scene, OnPostRender() still works in them. A paradox!



    P.S. Scene Tab is closed.
     
    Last edited: Sep 12, 2021
  5. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    jhocking likes this.
  6. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    I suspect that the cameras (not MainCamera) see these portals, pointing to the places of resurrection - so renderer.isVisible is always true, even if MainCamera does not see them and they are hidden by the Occlusion system.
     
  7. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    No.
     
  8. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127

    This example helped me!

    I used:

    Code (CSharp):
    1. Plane[] planes = GeometryUtility.CalculateFrustumPlanes(Camera.main);
    2.  
    3. if (GeometryUtility.TestPlanesAABB(planes, _objectRender.bounds)) {
    4.      Debug.LogWarning("Object inside frustum!");
    5. } else {
    6.      Debug.LogWarning("Object not visible!");
    7. }
    But I don't know how much this solution will eat up resources in fps... :cool:
     
    jhocking likes this.
  9. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    The solution works and has increased the fps to 7-12 units. :)

    I do not recommend contacting renderer.isVisible and void OnBecameVisible() at all.
    According to the forums and comments and from my experience - there is some kind of mess going on.
     
    Last edited: Sep 12, 2021
    SugoiDev likes this.