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.

RT Occlusion Culling

Discussion in 'Assets and Asset Store' started by KSI777, Oct 17, 2019.

  1. KSI777

    KSI777

    Joined:
    Aug 8, 2019
    Posts:
    9
    Hi, everyone. It is a dynamic-occlusion-culling system for Unity.



    ASSETSTORE : https://assetstore.unity.com/packag...sion-culling-dynamic-occlusion-culling-138442


    • Very easy to set up, no programming required.
    • Easy interface to edit convex hull
    • [1.2] Stereoscopic rendering support (VR)
    • [1.3] Baking LOD Mesh (Integrated UnityMeshSimplifier )
    • Geometric approach (NO GPU, NO Rasterization)
      * Available for any platform, including iOS and Android
    • Managing large-scale occludees by spatial partitioning algorithm
    • Runtime combine mesh for batching optimization
    Compare with PVS (Unity Occlusion Culling)
    • Smaller memory usage (ignore, almost zero)
    • No pre-computing time, no pre-computing data
    • Dynamic Occluder (any translation, rotation, scaling)
    • Dynamic Environment (show and hide)
    • Cons. Setting occluders manually like unity-colliders for collision detection
     
  2. Leniaal

    Leniaal

    Joined:
    Nov 7, 2012
    Posts:
    119
    Hi there, I'm looking for a decent occlusion culling tool. It looks promising, though I have to honest I'm not a fan of having to set all the occludees up like that. However if it gives a proper performance boost it's probably worth the hassle.

    But, I notice you barely mention the performance gains anywhere. I know this is very situation dependent, but could you at least show a video with a bit of a complex scene where you compare the scene with and without your tool?
     
    Gekigengar likes this.
  3. KSI777

    KSI777

    Joined:
    Aug 8, 2019
    Posts:
    9
    We made a comparison video with an old test device (NVidia shield tablet 2015) for you.
    (We played the scene included in the asset.)

     
  4. GCatz

    GCatz

    Joined:
    Jul 31, 2012
    Posts:
    272
    does it works with terrains ? webgl ?
     
  5. Bzuco

    Bzuco

    Joined:
    Sep 6, 2015
    Posts:
    56
    @GCat webgl yes, unity terrains no...you can hide just whole terrain game object, but not its submeshes
     
  6. Bzuco

    Bzuco

    Joined:
    Sep 6, 2015
    Posts:
    56
    @KSI777
    I am trying to use custom object as convex occluder using script but as you can see in video I am getting weird looking yellow lines from camera...it seems that just feed "SetConvexVolume" function with Vector3 array of vertices from mesh filter component is not enough. What is the correct workflow? Thanks for help.
    video: https://www54.zippyshare.com/v/lBm4NgxP/file.html

    ...I am using mesh based terrain objects


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class SetOccluderConvex : MonoBehaviour
    6. {
    7.     RT.Occluder m_Occluder;
    8.  
    9.     void Awake()
    10.     {
    11.         m_Occluder = new RT.Occluder();
    12.         m_Occluder.SetConvexVolume(GetComponent<MeshFilter>().mesh.vertices, transform.localToWorldMatrix);
    13.         m_Occluder.SetTransform(transform);
    14.     }
    15.     void OnEnable()
    16.     {
    17.         if (m_Occluder != null)
    18.             m_Occluder.Enable();
    19.     }
    20.     private void OnDisable()
    21.     {
    22.         if (m_Occluder != null)
    23.            m_Occluder.Disable();
    24.     }
    25. }
     
  7. KSI777

    KSI777

    Joined:
    Aug 8, 2019
    Posts:
    9
    @GCat
    WebGL has no problem because it works with the CPU.
    But there is no support for terrain rendering.
    It is impossible to apply the terrain as a occludee.
    I think it might be able to use it with terrain partially.
    I have captured a sample video for you. (Of course I think that is quite limited.)

     
  8. KSI777

    KSI777

    Joined:
    Aug 8, 2019
    Posts:
    9
    @Bzuco
    We checked and found some issues in SetConvexVolume.
    (The limit for the number of planes is 64, and there were some errors in the calculation of the convex.)
    We have fixed it and upload it to the asset store now, and it will be updated soon. (1.4 version)
    If the update is delayed, request by email, and I will send changes to you.

    The vertex count of convex affects performance.
    So we added a function to limit the vertex to the convex calculation function.
    And it would be helpful for the performance to pre-calculate it.

    We added it to your code as below.
    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. #if UNITY_EDITOR
    6. using UnityEditor;
    7. #endif
    8.  
    9. public class SetConvexOccluder : MonoBehaviour
    10. {
    11.     RT.Occluder m_Occluder;
    12.     [HideInInspector] public Vector3[] m_BakedConvex;
    13.     [HideInInspector] public int[] m_BakedHullTriangle;
    14.     [HideInInspector] public int[] m_BakedEdge;
    15.  
    16.     void Awake()
    17.     {
    18.         m_Occluder = new RT.Occluder();
    19.         if (m_BakedConvex != null && m_BakedConvex.Length >= 4)
    20.             m_Occluder.SetVolume(m_BakedConvex, m_BakedHullTriangle, m_BakedEdge, transform.localToWorldMatrix);
    21.         else
    22.             m_Occluder.SetConvexVolume(GetComponent<MeshFilter>().mesh.vertices, transform.localToWorldMatrix);
    23.         m_Occluder.SetTransform(transform);
    24.     }
    25.     void OnEnable()
    26.     {
    27.         if (m_Occluder != null)
    28.             m_Occluder.Enable();
    29.     }
    30.     private void OnDisable()
    31.     {
    32.         if (m_Occluder != null)
    33.             m_Occluder.Disable();
    34.     }
    35.  
    36. #if UNITY_EDITOR
    37.     [CustomEditor(typeof(SetConvexOccluder))]
    38.     public class SetConvexOccluderEditor : Editor
    39.     {
    40.         Vector3[] m_ConvexVertex;
    41.         int[] m_ConvexPolygons;
    42.         int m_TargetCount;
    43.  
    44.         public void OnEnable()
    45.         {
    46.             SetConvexOccluder _target = (SetConvexOccluder)target;
    47.             m_TargetCount = _target.m_BakedConvex != null && _target.m_BakedConvex.Length > 0 ? _target.m_BakedConvex.Length : 32;
    48.  
    49.             if (_target.m_BakedConvex != null && _target.m_BakedConvex.Length >= 4)
    50.                 RT.Occluder.ConvexHull3d(_target.m_BakedConvex, out m_ConvexVertex, out m_ConvexPolygons, 0);
    51.         }
    52.  
    53.         public override void OnInspectorGUI()
    54.         {
    55.             base.OnInspectorGUI();
    56.  
    57.             GUILayout.Space(8);
    58.  
    59.             EditorGUILayout.BeginHorizontal();
    60.             m_TargetCount = EditorGUILayout.IntSlider("", m_TargetCount, 8, 64);
    61.             if (GUILayout.Button("Bake"))
    62.             {
    63.                 SetConvexOccluder _target = (SetConvexOccluder)target;
    64.                 Undo.RecordObject(target, "Bake");
    65.  
    66.                 Vector3[] vertices = _target.GetComponent<MeshFilter>().sharedMesh.vertices;
    67.                 int[] hull;
    68.                 int[] edge;
    69.  
    70.                 RT.Occluder.ConvexHull3d(vertices, out m_ConvexVertex, out m_ConvexPolygons, m_TargetCount);
    71.                 RT.Occluder.GetVolumeEdgeAndHull(m_ConvexPolygons, out hull, out edge);
    72.  
    73.                 SceneView.RepaintAll();
    74.                 _target.m_BakedConvex = m_ConvexVertex;
    75.                 _target.m_BakedHullTriangle = hull;
    76.                 _target.m_BakedEdge = edge;
    77.             }
    78.             if (GUILayout.Button("Reset"))
    79.             {
    80.                 SetConvexOccluder _target = (SetConvexOccluder)target;
    81.                 Undo.RecordObject(target, "Reset");
    82.                 _target.m_BakedConvex = null;
    83.                 _target.m_BakedHullTriangle = null;
    84.                 _target.m_BakedEdge = null;
    85.                 m_ConvexVertex = null;
    86.                 SceneView.RepaintAll();
    87.             }
    88.             EditorGUILayout.EndHorizontal();
    89.         }
    90.  
    91.         private void OnSceneGUI()
    92.         {
    93.             if (m_ConvexVertex != null && m_ConvexVertex.Length > 0 && m_ConvexPolygons != null)
    94.             {
    95.                 SetConvexOccluder _target = (SetConvexOccluder)target;
    96.                 Vector3[] vertex = new Vector3[m_ConvexVertex.Length];
    97.                 List<Vector3> back_lines = new List<Vector3>();
    98.                 List<Vector3> front_lines = new List<Vector3>();
    99.                 for (int i = 0; i < vertex.Length; i++)
    100.                 {
    101.                     vertex[i] = _target.transform.TransformPoint(m_ConvexVertex[i]);
    102.                 }
    103.                 for (int i = 0; i < m_ConvexPolygons.Length;)
    104.                 {
    105.                     Vector3 nrm = Vector3.Cross(vertex[m_ConvexPolygons[i + 2]] - vertex[m_ConvexPolygons[i]], vertex[m_ConvexPolygons[i + 1]] - vertex[m_ConvexPolygons[i]]);
    106.                     Plane p = new Plane(Vector3.Normalize(nrm), vertex[m_ConvexPolygons[i]]);
    107.                     SceneView sceneview = SceneView.currentDrawingSceneView;
    108.                     bool front = p.GetDistanceToPoint(sceneview.camera.transform.position) > 0;
    109.  
    110.                     List<Vector3> list = front ? front_lines : back_lines;
    111.                     int v0, v1;
    112.                     for (v0 = v1 = m_ConvexPolygons[i++]; i < m_ConvexPolygons.Length; i++)
    113.                     {
    114.                         int v2 = m_ConvexPolygons[i];
    115.                         if (v2 == -1)
    116.                         {
    117.                             list.Add(vertex[v1]);
    118.                             list.Add(vertex[v0]);
    119.                             i++;
    120.                             break;
    121.                         }
    122.                         else
    123.                         {
    124.                             list.Add(vertex[v1]);
    125.                             list.Add(vertex[v2]);
    126.                             v1 = v2;
    127.                         }
    128.                     }
    129.                     Handles.color = Color.gray;
    130.                     Handles.DrawLines(back_lines.ToArray());
    131.                     Handles.color = Color.white;
    132.                     Handles.DrawLines(front_lines.ToArray());
    133.                 }
    134.             }
    135.         }
    136.     }
    137. #endif
    138. }
     
    Bzuco likes this.
  9. Bzuco

    Bzuco

    Joined:
    Sep 6, 2015
    Posts:
    56
    OK, thanks, I will check the code and wait for the store update, or request you by email if it will be takes too long ;)
     
  10. ohbado

    ohbado

    Joined:
    Aug 13, 2014
    Posts:
    37
    Hello.
    I am looking for a working Dynamic Occlusion Culling system. Can you answer two questions?
    1.Does this asset work on the Console platform?
    2.This asset is described as not using GPU, but does it support multi-threaded CPU processing? Is CPU main thread usage minimal?
    Thank you.
     
  11. KSI777

    KSI777

    Joined:
    Aug 8, 2019
    Posts:
    9
    @ohbado
    1. There is no platform limit.
    2. It is currently not operating in parallel like a general unity script. We plan to review the relevant issues.
    The calculated load depends on the number of objects. There is a variable that controls the calculation.
     
  12. KSI777

    KSI777

    Joined:
    Aug 8, 2019
    Posts:
    9


    1.5 Updated.
    It can add a window to the side of the occluder. (like a wall with door.)
     
  13. joshuacwilde

    joshuacwilde

    Joined:
    Feb 4, 2018
    Posts:
    643
    Does this support concave shapes? Also does it support runtime manipulation, addition, and deletion of the occluder shapes?
     
    Last edited: Apr 4, 2020
  14. KSI777

    KSI777

    Joined:
    Aug 8, 2019
    Posts:
    9
    Concave is not supported, only Convex is supported.
    (However, it supports that the occluder is overlapped by multiple occluders. Hole on surface like a door are restrictively supported.)
    It is not possible flexibly change the shape, it is just possible to add and remove occluders runtime.
     
  15. MyCatEatNoFish

    MyCatEatNoFish

    Joined:
    Oct 20, 2020
    Posts:
    19
    Does this plug-in support Webgl?
     
  16. Bzuco

    Bzuco

    Joined:
    Sep 6, 2015
    Posts:
    56
    check post #7
     
  17. KSI777

    KSI777

    Joined:
    Aug 8, 2019
    Posts:
    9
  18. nitoh

    nitoh

    Joined:
    Mar 20, 2014
    Posts:
    30
    Hi I bought your asset, Im quite satisfied with it, though I have a future feature request, i thought already inculed: frustum culling. Right now only the occluded objects get culled, that are inside the camera frustum, all of the objects that are behind the player are still active.

    With that feature implemented this asset is easily 5 stars.
     
    Last edited: Mar 18, 2021
  19. KSI777

    KSI777

    Joined:
    Aug 8, 2019
    Posts:
    9
    Do you mean something like this? (I tried to modify the code as below.)
    code
    I'll try to be able to selectively apply it to the next update.
    Currently we are preparing for optimization using compute shaders.
     
    nitoh likes this.
  20. nitoh

    nitoh

    Joined:
    Mar 20, 2014
    Posts:
    30
    Well, yes. This is what i meant, wonderful job. I think that you should update your example videos too, because this is much more impressive this way. Thank you for your update. I rated the asset 5*
     
  21. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,617
    Unity alread does frustum culling (although you won't see it in Scene view). Are there any performance benefits of doing a manual frustum culling on top of the built-in frustum culling?
     
  22. nitoh

    nitoh

    Joined:
    Mar 20, 2014
    Posts:
    30
    In my case yes, beacause i use object pooling on environment objects. So I can release the frustum culled objects back to the pool.
     
    yasirkula likes this.
  23. mason_unity134

    mason_unity134

    Joined:
    Feb 18, 2021
    Posts:
    1
    I got this package, but when looking at all of the example scenes I don't see any culling happening, nor do I see any of the visuals in the scene view that are seen in the readme and the asset's store page. Does anybody have any insights as to why that'd be the case?
     
  24. Marcel399

    Marcel399

    Joined:
    Jan 1, 2021
    Posts:
    1
    Hi, I got a pretty weird case here so please hear me out:
    I am part of a modding community for a VR game and I make custom maps for that game. Due to the way we load the modded scenes we sadly do not get acess to any of unitys default occlusion culling. However the main problem is the CPU load as the game is very extensively physics based. Will your culling script reduce the load on the CPU?
     
  25. yoship

    yoship

    Joined:
    Aug 21, 2012
    Posts:
    1
    @KSI777
    It is translated at DeepL.
    Hello, I have a question.

    The wall in the foreground is made up of 4 separate objects, each with an RTSimpleOccluder set on it. The back wall has two and both are set to RTOccludee. One of the walls is culled because it is hidden by the Occluder, but the other wall is not culled, probably because it crosses two Occluders. Is this the way it works?
    Thank you.
     

    Attached Files:

  26. satolas

    satolas

    Joined:
    Feb 13, 2017
    Posts:
    21
    Hello
    I tried to send an email to the support email written in the Readme.pdf but it seems this email is not reachable.

    Just a little question :
    Is there a way to get the actual Status of an Occludee from Script ?
    Let say for example I have a box behind an Occluder wall.

    When the box is Occluded : Debug.Log("RT_OccludeeStatus : " + occludee.isOccluded);
    // Could display RT_OccludeeStatus : True;

    When the box is Visible it display : Debug.Log("RT_OccludeeStatus : " + occludee.isOccluded);

    // Could display RT_OccludeeStatus : False;

    I just want to extend a FrustumCullingVisualization script so when the object is occluded by RT_Occlusion it is not displayed by the FrustrumCulling,

    Thanks
     
  27. linaibin

    linaibin

    Joined:
    Sep 28, 2017
    Posts:
    1
    Does it support transparents?
     
  28. TheSheyper

    TheSheyper

    Joined:
    Jul 3, 2013
    Posts:
    19
    Hi @KSI777
    I'm interested in buying it but is it still supported? Because zero updates since March 2021 makes it feel like it's been abandoned...
    Thanks for your answer ;)
     
    ImreT01 likes this.
  29. JediNizar

    JediNizar

    Joined:
    Nov 13, 2016
    Posts:
    110
    same question, and any comparison between build in Occulison and this one regarding performance
     
    ImreT01 likes this.
  30. krakentanz

    krakentanz

    Joined:
    Aug 13, 2020
    Posts:
    31
    Same question here. What's the development status of this tool?
    Also: I can't manually build these green boxes for all objects (too many different ones in the game). I could however provide one or more matching concave meshes. Is it possible to use these meshes as RT convex occluders instead ob building them by hand?
     
    JediNizar likes this.
  31. melanke

    melanke

    Joined:
    Jan 27, 2018
    Posts:
    3
    Hello, I am considering buying your asset. My scene is generated at runtime, instantiating all game objects as tiles. Does this solution support this usecase?