Search Unity

Can I disable culling

Discussion in 'Editor & General Support' started by Paulius-Liekis, Mar 18, 2010.

  1. Paulius-Liekis

    Paulius-Liekis

    Joined:
    Aug 31, 2009
    Posts:
    672
    Hi,

    I ran into a problem: Unity decides to cull one of my objects event if part of that object is still in camera view (I can see it clearly in scene view). It's a skinned mesh and one of the bones and part of the mesh is still in view. I'm not doing any custom shader stuff.

    Is there a way to force Unity to render my object? Disable culling or expand bounding box or something like that?
     
  2. muplor

    muplor

    Joined:
    Nov 2, 2009
    Posts:
    75
    set your near clipping plane on the camera in question to a low value like 0.01 and it might solve this problem

    or increase it's field of view
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Turn on "Update when offscreen" on the skinned mesh renderer.

    --Eric
     
    ryansizemore likes this.
  4. Paulius-Liekis

    Paulius-Liekis

    Joined:
    Aug 31, 2009
    Posts:
    672
    Thanks! That solved my problem!
     
  5. ASteer

    ASteer

    Joined:
    May 13, 2016
    Posts:
    14
    @Eric5h5 Sorry for bumping a very old thread, but your answer was very on spot for what I need and thus I might not mess the forum with an uncessary new thread. So, is there an equivalent to that option for a simple mesh, that can be activated via script? Thanks!
     
  6. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,292
    Is this a procedural mesh? If its being culled then you probably need to update the Bounds.
    http://docs.unity3d.com/ScriptReference/Mesh-bounds.html
     
    forestrf, booferei, dkaloger and 2 others like this.
  7. ASteer

    ASteer

    Joined:
    May 13, 2016
    Posts:
    14
    Many thanks for your reply! That is the exact problem: it is procedural. But the issue is that vertices change frequently and I keep having to update Bounds all the time, incurring in unnecessary costs. Also, think of meshes that are only used to convey shader code: they can be culled out even if a shader is set to overlay. There should be a simple option to mark objects to be rendered anyways, just like there is this option to update animations of skinned meshes no matter if they are offscreen.

    Or even better, there should be a simple flag in the GameObjects or in the MeshFilter components to set them to either not be culled or even to not be tested for culling, in the case we already know they are visible.
     
  8. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,292
    You don't need to calculate the bounds, just set it to a really high value.
    By default no bounds are calculated when its only vertices so assign a value to it once and you should be fine.
     
  9. ASteer

    ASteer

    Joined:
    May 13, 2016
    Posts:
    14
    The problem is: in one of my procedural meshes that are giving me culling issues, vertices are updated all the time. Sometimes vertices are added or removed. When that happens, one needs to redefine the indices of the vertices. And that requires a new recalculation of the bounds. While the mesh has low number of vertices, it's fine. But if the number of vertices is high, redefining bounds gives an unnecessary burden on the processing of the procedural mesh
     
  10. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,292
    You dont need to calculate the bounds. Just assign a large value that will encompass all the verts. This will give you a mesh that is always rendered.

    Code (csharp):
    1. mesh.bounds = new Bounds(transform.position, new Vector3(float.MaxValue, float.MaxValue, float.MaxValue));
     
    ASteer likes this.
  11. ASteer

    ASteer

    Joined:
    May 13, 2016
    Posts:
    14
    Ah, I see what you mean. Great idea, makes sense. So it's all about performing that every time a mesh.SetIndices(indices, MeshTopology.Points, 0) is called again to update the vertices. Much faster, since it's no more than an assignment of a new Vector3.

    Problem solved! In any case, here you have my plea that in the future objects could have an option to disable frustum culling checks on them. Would be cleaner and even improve performance in some cases. Anyways, thanks for the tips!
     
    karl_jones likes this.
  12. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,292
    Give it a vote https://feedback.unity3d.com/sugges...disable-automatic-culling-on-particle-systems or maybe create a new one that is not particle specific.

    Aha maybe this one https://feedback.unity3d.com/sugges...-view-frustum-culling-for-chosen-game-objects
     
    ASteer likes this.
  13. ASteer

    ASteer

    Joined:
    May 13, 2016
    Posts:
    14
    Excellent that someone has already put that there! And I completely agree with the arguments presented by both. Now, the question becomes: is it better to vote for the one with 42 votes but which was raised in the particles context, or to the very recent one that is more general but pretty much does not have votes?
     
  14. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,292
    I don't know :confused:
    I investigated allowing custom culling to the particle system earlier in the year and we deiced at the time that it was not worth it. The performance gain was minute and the space for mistakes was huge. So maybe add it to the more generic one :)
     
    ASteer likes this.
  15. ASteer

    ASteer

    Joined:
    May 13, 2016
    Posts:
    14
    @karl.jones Thanks for all the info! Voted on the second link. Hope that at some point you guys reconsider it for the more general non-particle cases. Having a flag to determine which objects are view frustum tested would be awesome..
     
  16. Roiw

    Roiw

    Joined:
    Jan 15, 2013
    Posts:
    23
    Hey everyone, sorry for reviving old thread :D

    I tried doing that to one of my meshes, and it worked, no frustum culling anymore! But I'm getting a lot of "Expanding invalid MinMaxAABB" errors.

    Why does that happen (did I break my mesh internally?)? Should I look for a sweetspot of size for the bound box that will solve the issue and don't give me the error?

    Thanks for the replies so far guys.

    Have a wonderful day :)
     
  17. Roiw

    Roiw

    Joined:
    Jan 15, 2013
    Posts:
    23
    Another question on the same matter.

    I have Sprites and World Canvas on the scene, those don't have Mesh Filters how can I fix for those cases ?
     
  18. captain_canuck

    captain_canuck

    Joined:
    Mar 9, 2018
    Posts:
    2
    Did you ever figure this out, Roiw? I'm running into the same problem with 3D text.
     
  19. Roiw

    Roiw

    Joined:
    Jan 15, 2013
    Posts:
    23
    It's been so long ago I can't quiet remember what I did.. Your problem is that your Sprite is disappearing from your world space canvas?
     
  20. captain_canuck

    captain_canuck

    Joined:
    Mar 9, 2018
    Posts:
    2
    Yes. A few different things in my scene are being moved by a vertex shader and they disappear at certain camera angles. For the objects that have mesh filters, I can easily fix the problem by setting the mesh bounds to something large. However, I can't figure out a way to solve to problem for text since it has no mesh filter for me to adjust mesh bounds with. Any help would be greatly appreciated!
     
  21. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,292
    Could you file a bug report, please? Provide a simple example project and explanation. If we can see no solution then this can be a justification for providing better control of culling in the future and we can add it to our roadmap.
     
    Ignacii, Peter77 and hippocoder like this.
  22. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I recall an issue about this very recently actually - something to do with clipping or such with 2D, and the origin, on these forums... devil if I remember where, so there is something going on.
     
  23. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,933
    Culling via bounds consistently crashes when using large values (As described above).

    1. Setting mesh.bounds to ( (float.max, max, max), one ) crashes Unity internally and you get spammed with error messages
    2. (any large bounds has similar effect)
    UPDATE: previous comment re: "doesn't cull with zero-size bounds" was my mistake - the culling works in 2019, so long as you avoid the internal crashes above
     
    Last edited: Dec 27, 2019
  24. tim12332000

    tim12332000

    Joined:
    Jun 15, 2017
    Posts:
    20
    I'm using
    Graphics.DrawMesh(mesh, _matrix, material, 0, cam);
    this API , And I set mesh bounds to max , It's still culling. How can I do?
     
  25. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,292
    How do you know its culling and not something else?
    Try enabling the show renderer bounds option in the diagnostic switches(requires 2021.2)
     
  26. tim12332000

    tim12332000

    Joined:
    Jun 15, 2017
    Posts:
    20
    Thanks I think I found issue , it's my bad , my code wirte own culling. I forgot it.
     
    karl_jones likes this.
  27. RadTad2

    RadTad2

    Joined:
    May 26, 2019
    Posts:
    2
    Cheers from 2021 for solving this issue
     
  28. marcospgp

    marcospgp

    Joined:
    Jun 11, 2018
    Posts:
    194
    2023 and still no way to disable frustum culling per material/object/shader outside of a whole custom scriptable render pipeline?