OpenGL dumb mistakes: the mysterious Perfect Circular Hole

I’ve got a long-running project around rendering 3D Earth in interesting ways. It’s being used in a game project, and some non-game stuff too. Here’s a recent screenshot:

I added a particle system that uses Vector Fields to move the particles based on arbitrary incoming data, and then wraps it round a globe. Yay!:

…and then I increased the size of each particle, and something very strange happened. I wanted to splurge them out to be huge, but

The mysterious Holes Of Doom

… these weird holes appeared in the middle:

WTF? I must have done something stupid. I double checked everything. I removed the textures. I switched from quads to basic tris, with vertex colours … but still, this perfect circle cut out of the center! My vertex and fragment shaders by this point were exactly one line of code!

…I spent ages looking at this, trying to understand what could possibly create “holes” in my geometry. They were obviously holes – you can see through them!

Eventually, tired, and with lots of more important work to do, I gave up, shelved it, went off to do other things. Then today I suddenly realised the problem. I’m sure it’s obvious to most of you, but it’s taken me ages to figure it out.

When a hole is not a hole

And this is what makes it worth posting: the hole is not a hole.

My particles are on a 2D plane, so that I can calculate simple x/y coords from a vector-field. Great. My shader wraps the corners to a sphere. I’m rendering quads / tris like this:


Great. But GL doesn’t “bend” the edges – it draws straight lines between corners. So … when I made my tris larger … the corners were still slightly above the surface of the globe.

…and the EDGES were still slightly above

…but the centers … slightly interesected the globe. And so, of course, the depth-test cut them out. In the diagram below, it looks as if the quad moved closer to the center of the globe – but it hasn’t. The corners are all still the same height above the surface – only the middle has (implicitly) gone “inwards”.


Lesson to self: sometimes, it’s not a triangle-with-a-hole-that-I-can-see-through … instead, it’s a triangle-that-has-a-sphere-poking-through-the-middle


4 replies on “OpenGL dumb mistakes: the mysterious Perfect Circular Hole”

Yep, this is definitely familiar to me since I made a WebGL demo with PhiloGL for a job earlier this year showing simulated network traffic around the world. I used oriented quads around a sphere to draw the animations. Working with a unit sphere is handy. I suppose one can measure the centroid of the quad to make sure it remains entirely visible or a very handy trick is to turn depth testing off and do simple culling of the quads based on their position on the unit sphere. This depends on how rotation is handled because if the camera is stationary looking at the front positive side of the unit sphere it’s easy to calculate which quads are on the back side and cull them; IE if the quad centroid has a -Z then cull it though there may be a threshold value that is just below 0 that provides the best results depending on quad size, etc. By using this method one doesn’t need to be so precise in placing the quads by measuring the centroid. Also it’s necessary for proper alpha transparency between quads to turn off depth testing anyway unless you get into sorting which could be overkill in this case.

Hi Adam, first of all, sorry for off-topic, but could you please correct your article at #altdevblogaday

Because you’r breaking RSS feed, the problem is UTF-8 encoding.

Combine multi-threaded code with parallel-processors, and combine that with facade code that pretends to be on CPU but actually runs on GPU .. and you have a recipe for source-code disasters.
the real problem is on word “you”.

Thanks, sorry about the off topic and continue with good work :)

Thanks, David!

Someone else had the same problem with my blog (Also wirdpress), but Chrome gives the wrong line number, Nd we couldnt find it.
Its a wordpress bug, it seems. Rss works fine in firefox, but not others.

With your pinooint, ill edit asap and delete te errant char, thansk.

But im on iphkne right now, and wordpress edit fielda have a broken javascript that makes editing Most impossible.

Comments are closed.