Polygon Clipping - Good or Bad

Hi all,

I have a question about 3D modelling, or more specifically about how Unity handles a certain aspect. For what it might be worth, I’m using 3DS Max 2010 to model my objects but I think this question applies whether modelling with a external application or using simple models built direct in Unity - hence why I’ve posted In this forum.

My question is whether there are significant (by which I mean just about ANY) performance gains by removing any polygons that intersect through another polygon and so have surface inside the main mesh of the model (and therefor would never be rendered).

For example, suppose you were making a (very) simple and stero-typical flying saucer. You create and squash a sphere to form the flat circular base then plonk a second sphere on top to form the dome (where the crafty aliens would sit). The second sphere on top could be be set so it is sunk half way into the bottom section create the dome effet on top. This of course leaves the bottom half of the sphere hidden inside bottom section of the ship.

There are several ways to get rid of the excess polygons (booleans, deleting the invisible polygons, manually creating the dome from a single object, etc) but, regardless f this, the question is is it worth taking the time to remove them for performance gains in Unity?

I’ve trawled through dozens of guides, tutorials and forums to try and get a solid answer but most of what I’ve fiound is in the context of rendering an animated movie (in which case it doesn’t really matter that much).

My train of thought is that, when considering this in a gaming environment, there probably would be gains as the engine would not have deal with the existance of these ‘invisible’ polygons on any level but I haven’t found anything as yet to support this.

Any thoughts?

1 Like

You should probably make your models as low poly as possible while still looking good. Considering that polygons that are being hidden from view have no functional purpose, they should be deleted to lower the poly count of your game in general. Although, for modern PC games, poly count is not that big of a concern anymore, if you were to texture that spaceship then the extra space in the texture map would be incredibly wasteful.

Yes, additional hidden polygons will have some performance impact as those polys are still sent to the video card. In many cases it will be negligible as Unity can push a ton of static polygons, but it really depends how many hidden polys you are talking about. If it’s animated it will have even more of an impact because even the hidden verts will have to be re-positioned on the CPU before being sent to the video card.

I’d take it on a case by case basis. If you’re talking an extra 20 tris and it’s going to take you an extra 20 minutes to clean up the model, just leave them in there, it’s not worth the time. If you’re talking about 20k tris, then it might very well be worth taking the time to remove them.

EDIT: If you’re planning on using transparent shaders on the object then you’ll definately want to clean them up. Since transparent (non-cutout) shaders don’t write to the depth buffer you can easily end up with sorting issues and things popping into and out of view.

Thanks Chaos, that’s really useful, I hadn’t considered the impact on other elements like the texture mapping.

The space ship was a just a simple concept to explain my question. Where this is really taxing my time is when modelling some Mech / Vertical Tank / Giant Crazy Robots (call them what you will) models. There’s lots of smaller mechanical parts that just wouldn’t be practical try and model from a single object. Much easier to model component parts separately and stick them together as appropriate. This of course leaves a lot of objects intersecting with other objects. If I take the time to cut out all the redundant plugins and merge all the vertices into a single mesh, it can the become incredibly painful to change or remodel one of those parts.

Cheers Niosop, definitely some wisdom there. I suppose, like most things, it’s about finding the happy medium.

Thanks again

worry about it later if there’s a performance issue during optimisation at the end of the project.

A little bit of clarification here. I was under the impression that Unity used GPU skinning, meaning that the CPU does not transform mesh vertices, but rather the GPU.

http://forum.unity3d.com/threads/27597-Is-edge-flow-so-important-It-can-raise-poly-counts.

it depends, sometimes connecting intersecting geometry to the main geometry actually creates more triangles especially if the geometry are of irregular shapes, I estimated I saved 500 triangles by not connecting geometry on my 9000 triangle gun model, but then again most of my intersections occur when a irregular shape intersect a flat surface and connecting the geometry will increase the vertex count for that surface significantly and also induce more irregular triangulation which affected surface normal.
so I would say to leave intersecting geometry in game unless connecting them takes no extra triangle.

That would depend on your modelling package though, and the tools you’re using. It simply doesn’t happen in max unless you tell it to using some form of boolean. That’s certainly the exception not the rule what you describe as I haven’t seen it in all the years I’ve done 3D development.

Clipping polygons is generally “poor practice” and should be used with great care or avoided. I say poor practice, because as a developer you should plan out things to avoid these situations and cut out polygons all-together if they will never be visible. Make sure that clipping doesn’t lead to visual degradation. One of the major issues is that part of the “hidden” triangles can “seep” through and be partially visible creating a grainy, ugly presentation. Attached is an example of clipping that can happen if the developer gets “lazy” and is not careful about clipping. It’s an image of a plane intersecting with the terrain at the same X/Z space.

I also heard a long time ago that older engines had a hard time dealing with intersecting geometry. I am not sure how true that is. What I heard about that is that the engine has to determine which polygon to draw for each pixel or something along those lines. That was a long time ago I and I am not sure how reliable the source was.

749790--27366--$clipping.jpg

That’s only applying to co planar polys. Clipping polys happens all the time in games, saving a lot of space just plunging a rock in the sand, for example, with no bottom or underside to the rock.

I do it happily all the time. It’s not a problem. I don’t think anyone is going to put 2 polys together like in the above picture.

I agree with you, I just want to warn those who are learning. Without proper care, new designers may not understand where visual artifacts can come from. I myself didn’t realize this right of the bat when I started learning 3D stuff 7 years ago. And depending on the graphics engine, the distance of separation needed between polygons to prevent “seeping” may vary, and may even vary by distance from the camera. So a box inside of a slightly larger box might seep though in Unity and not your modeling package or vice versa. At least that’s what I have seen from my experience.

Things like rocks, you don’t have to worry about this, but placing things like trees with roots that fan out might have similar issues with the ground. Also, if you are piecing objects together that almost converge, without proper care a similar situation might occur. I think it’s poor practice for beginners as they might miss some of these details. It’s really something to be taken on a case by case basis as to if it’s something to worry about.

I guess my point is: There is nothing wrong with clipping. Just make sure that you don’t have models set up where clipping may lead to overlap as seen above.

It’s not the engine, it’s the zbuffer precision. 16-bit zbuffers are pretty crap for intersecting geometry unless you severely limit the near/far clipping plane range.

–Eric

If you have a sphere intersecting something else and half of that sphere will never be seen, delete the polygons that will never be seen.

The only problem comes when you’ve got two polygons that intersect and their angle is identical or very close - you’ll get z-fighting then (as demonstrated in MakerOfGames’s post).

I have objects within other objects and you pull things apart to see the object inside the main object

Is there a away to increase the Zbuffers in unity to handle polygon that are close together ?
what option do i have beside hiding the inner object with out seen my user ?

I’m with Hippo. You can get a lot out of geometry re-use if you don’t worry overly much about this.

It’s a per-case thing anyway. Understand what your CPU, GPU and memory are doing to make your game work and you’ll be able to make informed decisions about this stuff.

Currently 24bits is the max for zbuffer and I think thats standard in most cases of Unity, perhaps on mobile devices you can still choose whether to use 16 or 24 bit. So you can’t make it any higher, though I have heard that 32bits has been supported in the past on gpu’s.

However what you can do is maximise the use of the zbuffer through minimising the range its applied to in your scene, through changes to both near and far planes, so that they are as close a fit to your scene as possible. To learn more and understand why check out Learning to Love your Zbuffer

As to the OP’s question, I believe that the modeller is responsible for minimising the number of hidden polygons.

Sure in your ufo saucer example it may only be a hundred or less polygons being hidden and needlessly rendered, but you also have to factor in that they are taking up memory and bandwidth too. The problem then occurs if you have 100 or 1000 or more of these objects on screen at once, now your 100 hidden plys have become 10,000 or 100,000 hidden polys, which can depending upon platform have much greater an impact on performance.

Things get even worse when you consider what shader might be applied, if you have a complex shader then there is a good chance (assuming you are not using deferred rendering) that those hidden polygons will be rendered first and thus fully rendered to the screen with the complex time consuming shader, before the outer polygons are rendered over the top. This overdraw combined with complex shaders can adversely affect performance.

Also as mentioned above, there are other considerations such as if the object gets lightmapped, or even if just badly uv unwrapped those hidden polygons will take up valuable space in your texture.

As ever in 3D graphics its a blancing act between performance and cost (where cost in this case is time taken to create the model). A few hidden or intersecting polygons wont make much of a difference either way, but careless modelling like your flying saucer example could be much worse.

Then again personally I wouldn’t really except models with either of those issues as I don’t believe they should ever happen and would be a sign of poor modelling. Sure you can have instances of whole models intersecting other models when placed in the scene (e.g. like Rocks), but that comes down to the balance trade off time vs cost where the rocks can easily be rotated 360 degrees and reused many times. Therefore the small cost of allowing them to intersect the ground is outweighed by the saving in time and memory of being able to re-use them easily.

from a modeling standpoint you should keep models as clean as possible

(ignoring issues in the game engine like z fighting or loss of performance)

when you are modeling more and more complex geometry, pointless polys will totally get in the way (imagine going into wireframe on a spaceship with millions of polygons and thousands of them muddling up the center, ugh)

The worse kind of clipping that I have had to deal with involved characters interacting with each other, and stuff like arms clipping into bodies, which is unfortunately not easy to avoid, especially if you have models that are wearng stuff like armour and other props are that supposed to be hard edged. This is the limitation of having no solvers to look for that kind of thing and being forced to sometimes use the same rig for all of the other characters in game. Tbh, model intersections during animations is sometimes a pain in the ass, but you have to let it slide unfortunately… even corrective blendshapes will not get you out situations like this… I am working with near 100k characters and it is very painful :frowning: