Spellcaster Studios

Make it happen…

Culling problems

I spent a lot of time looking at a bug all wrong…

I noticed that the voxels that had transparency were rendering wrong:

screen556

Check out the front window of the ship…

Anyway, my first thought was that I was adding to the vertex buffers the faces between two adjacent objects with the same material, but after looking and looking at the code, I couldn’t see where that would happen… Nothing I changed lately would break that code, so it felt weird…

Out of inspiration, I tried running the game in DirectX instead of OpenGL (been running the game in OpenGL since I made the port, so I can see if something is wrong)… And in DirectX the problem didn’t appear…

Then I tried isolating a single voxel to see if it had any problems, and I couldn’t see anything as well… Only when I added multiple voxels the problem would be apparent…

In this process, I figured that the backface culling wasn’t working properly, because I was seeing faces that I shouldn’t (the backfaces)… Thinking about it a bit, and considering that alpha objects don’t render to the depth buffer, I finally figured out that what I was seeing wasn’t the face between the voxels, but consequence of the parallel nature of the GPU (multiple triangles are drawn at the same time, not one after the other), allied to bad backface culling (backfaces and frontfaces were rendering) and the fact I wasn’t writing to the depth buffer (so it wasn’t resolved properly)!

Investigating a bit more, I figured out that the problem was that the backface culling wasn’t setup only with glCullFace, but I also had to do glEnable(GL_CULL_FACE) or glDisable(GL_CULL_FACE), depending on the cull mode…

Then, the result was this:

screen558

It looks cool, but it’s all wrong.. Smile Culling was reversed, and not only that, it was doubly wrong, which resulted in the ambient occlusion being wrongly computed, which creates that negative aura effect!).

After inverting some flags, I finally got this:

screen559

So basically I lost 3 hours because I don’t read documentation properly… Disappointed smile

Now listening to “The X Factor” by “Iron Maiden”

Link of the Day: Another game with great aesthetics… Indies are really raising the bar nowadays: http://triple-eh.tumblr.com/

Comment