I just do instancing render meshes in the jobsystem, how to do cull?Is there any samples?
thx
Probably at this stage you will have to write this yourself from what i understand. I am curious if there are plans for such systems to get implemented by the engine team into ECS
We are working on some early prototypes of frustum culling and lod systems as part of the ecs rendering package, they should be part of the next release.
very happy to hear that:)
They are already available, you can just add MeshCullingComponent to and entity and it should be culled. I didn’t tested it myself, but those systems are avaliable already:
- MeshCullingComponent.cs
- MeshFrustumCullingSystem.cs
- MeshLODComponent.cs
- MeshLODSystem.cs
If you want to see the source, just read it on Unity cache folder. On windows 10 it’s located on:
_%LOCALAPPDATA%\Unity\cache\packages\packages.unity.com\com.unity.entities@0.0.12-preview.5\Unity.Rendering.Hybrid_
This is very cool news!
thx,i will give it a try
wow, added the MeshCullingComponent to our entities and got a nice performance boost.
I couldn’t find and example of setting up the MeshLODComponent. It’s unclear how to associate the 3 LOD with the component. Anyone have an example?
You create multiple Entities with MeshLODComponent each one having a different LOD level assigned. Then you create an entity with MeshLODGroupComponent (or attach that to eg the first entity). All MeshLODComponent’s must reference the entity of the MeshLODGroupComponent they belong to. The system will now calculate which LOD level should be used for a MeshLODGroup and attach MeshLODInactive to the ones that are currently not active. The MeshInstanceRendererSystem ignores all objects having a MeshLODInactive.
I didn’t use it yet, so no code to share.
Imo it would make more sense to implement culling BEFORE calling rendering methods.
Calling render everything and then culling not visible to camera seems like unnecessary work.
Edit: unless this culling component cooperates with unity’s internal renderInstanced method, then ignore my comment.
thanks, that’s enough to get started.
Maybe these got removed or changed to something else. I was unable to find them in my cache (Unity 2018.2.3f1, com.unity.entities@0.0.12-preview.12).
They did indeed get removed culling no longer attaches these components since that approach didn’t scale to millions of renderers in a scene.
What is the new approach?
Frustum culling is now taken care of in the MeshInstanceRendererSystem. If an entity has the MeshInstanceRenderer and LocalToWorld components, it will get rendered by the MeshInstanceRendererSystem (no culling). Additionally, if it also has a WorldMeshRenderBounds component, it should get culled by that same system.
You say “Millions of renderers in a scene”… With a simple green cube, I’m already running into 50ms of rendertime for about 10k cubes (with a shared meshinstancerenderer)… Is there something I’m missing?
You will not display all of them at once. Like in Megacity demo thy have to be culled and loaded and unloaded dynamicly.
How would I go about culling these with regards to my camera('s)?
In short: I’m trying to render stars around the user based on the user’s (and the star’s) actual location. This takes quite a bit of Sin/Cos/Tan-Math to do…
I’ve currently got it working for 100 Stars, where the Positioning is taking roughly .1ms, and the Rendering is taking about 1-2 ms… (On Unity 2018.2.13f1, with Entities 0.0.12-preview.19)… Increasing the # of stars leads to crashes & freezes though, with the Editor crashing once every 5 minutes atm…)
The total # of stars I want to use is +/- 10k. This amount is spaced out across all 3 dimensions around the user/camera
Edit: I’m currently at 4000 Entities, with the Positioning (the math) still only taking 0.1Ms, but the rendering already taking 12ms
What are you rendering on? Are you using the meshinstancerenderer with GPU instancing on your material? Are the models complex? You’ll want to LOD it, if there’s some kind of zoom functionality.
What are you rendering on?
How exactly do you mean? It’s running on my laptop (an HP Elitebook 8740w), with a single, shared MeshInstanceRenderer
Are you using the meshinstancerenderer with GPU instancing on your material?
Yes
Are the models complex?
They are the Unity-Cube-Primitives… I believe they have 24 Vertices per mesh.
You’ll want to LOD it, if there’s some kind of zoom functionality.
There isn’t. Only Frustum culling is what I’m looking for…
I’ve also since found out that if I add a “Frozen”-component to my instances, the render-times drop from 25-30 ms to around 3-5 ms…