- Home /
[5.1.2f1] Unnecessarily agressive culling - how to tweak it?
Hi there!
I'm experiencing some trouble with some effects and graphics in the game we are currently developing. Some objects (particles and 2D sprites) cease to be rendered when they reach the border of the screen, even if they should still be visible. Since the camera barely zooms, we do not have any kind of LOD or custom culling zones in the game (and those objects are non-static, which should avoid culling calculations for them). I'll give you some visual examples:
In the first screenshot, you can see how a fog particle effect is perfectly rendered but disappears when the camera is a few pixels ahead. In the second one, the medallion sprite is rendered but, as the camera moves a little bit, vanishes.
We have a Perspective camera because we do make use of the Z axis for a lot of things (and we have some Z movement in some specific areas of the game), maybe that's part of the problem? I haven't configured anything related to culling, so this is Unity working automatically. How can I deal with this issue? It gets very annoying when you are walking and see sprites and particles pop in suddenly. And we are working really hard on our game's art, so we really want to solve any erratic behaviour concerning visuals.
I've double-checked the scene setup and every gameObject's renderer has a unique sortingLayer value, so it's not a rendering issue. I've also tried setting mainCamera.TransparencySortMode to Ortographic, unchecking the Occlusion Culling flag in my camera and narrowing the Near and Far clipping plane values, but none of that worked either.
Thanks for your time.
If you switch the camera to orthographic are they still being culled away?
A hacky fix might be to ensure some significant scene depth is present for those elements in the background prone to order incorrectly (though I can see that being unworkable too). It's probably an optimisation in Unity's perpective camera code which is screwing up the render order at distance. Possibly worth submitting a bug report on it, and hopefully they don't just say they expect 2D sprites to use orthographic cameras.
I wonder if there are any settings to increase the z ordering fidelity, someone else might know of such a thing.
Oh, perhaps try playing about with this too: http://docs.unity3d.com/ScriptReference/Camera-transparencySort$$anonymous$$ode.html?from=TransparencySort$$anonymous$$ode
Thanks a lot @l3fty, I'll submit a bug report and take a look at the docs. And yeah, transparency sorting might be the thing (we are using Transparent sprites with 2DToolkit after all).
I'll let you know what I find out.
Hi, the frame debugger may help to see if it's a Z order problem or if the object is culled (it allows to see each object rendered). It may also help to use a simple script in the Update that check the Renderer.IsVisible flag of a problematic object. If it's some Z order problem, make sure your camera Near & far clipping plane are as narrow as possible = $$anonymous$$imize (Far - Near) as it will increase precision (EDIT: it increases precision of the Z buffer but not of transparent object sorting).
Answer by Teku-Studios · Aug 31, 2015 at 06:03 PM
Okay, found it! Although I do not know exactly why this happens.
The issue vanished when I changed those object's Zscale value. Some objects needed a smaller Z and others needed a bigger Z. I'm glad to see this solved, although I still don't know why scale in Z affects 2D sprites' rendering.
Your answer
Follow this Question
Related Questions
Culling part of a sprite in Sprite Manager 2 1 Answer
Problem with flipping ! 0 Answers
Greyscale shading 0 Answers
Make 2D sprites glow? 4 Answers
Unity drawing particles incorrectly 0 Answers