I am trying to voxelize my scene by rasterization using the dominant axis theory - which involves using the vertex normals to find the dominant axis of each triangle which would then determine the direction to apply an orthographic projection of the scene. This is done in the geometry shader and then passed to the fragment shader.

I manage to voxelize the scene, except for one major problem as shown below, adjacent to the non-voxelized scene:

[attachment=13606:givox0.jpg][attachment=13608:givox1.jpg]

Notice how there are artifacts above the Buddha and the Sphere?

Does anyone know what could be the cause of this and how this can be fixed?

Here is my geometry shader code:

#version 430 layout(triangles) in; layout(triangle_strip, max_vertices=3) out; in VSOutput { vec4 ndcPos; vec4 fNorm; vec2 fTexCoord; vec4 worldPos; } vsout[]; out GSOutput { vec4 ndcPos; vec4 fNorm; vec2 fTexCoord; vec4 worldPos; vec4 axisCol; mat4 oProj; } gsout; uniform mat4 voxSpace; void main() { gsout.oProj = mat4(0.0); for(int i = 0; i<gl_in.length(); i++) { vec4 n = vsout[i].fNorm; gsout.fNorm = n; gsout.fTexCoord = vsout[i].fTexCoord; gsout.worldPos = vsout[i].worldPos; float maxC = max(abs(n.x), max(abs(n.y), abs(n.z))); float x,y,z; x = abs(n.x) < maxC ? 0.0 : 1.0; y = abs(n.y) < maxC ? 0.0 : 1.0; z = abs(n.z) < maxC ? 0.0 : 1.0; vec4 axis = vec4(x,y,z,1); if(axis == vec4(1.0,0.0,0.0,1)) { gsout.oProj[0] = vec4(0,0,-1,0); gsout.oProj[1] = vec4(0,-1,0,0); gsout.oProj[2] = vec4(-1,0,0,0); gsout.oProj[3] = vec4(0,0,0,1); } else if(axis == vec4(0,1,0,1)) { gsout.oProj[0] = vec4(1,0,0,0); gsout.oProj[1] = vec4(0,0,1,0); gsout.oProj[2] = vec4(0,-1,0,0); gsout.oProj[3] = vec4(0,0,0,1); } else if(axis == vec4(0,0,1,1)) { gsout.oProj[0] = vec4(1,0,0,0); gsout.oProj[1] = vec4(0,-1,0,0); gsout.oProj[2] = vec4(0,0,-1,0); gsout.oProj[3] = vec4(0,0,0,1); } gsout.axisCol = axis; gl_Position = gsout.oProj*voxSpace*gl_in[i].gl_Position; gsout.ndcPos = gsout.oProj*voxSpace*vsout[i].ndcPos; EmitVertex(); } }