Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

There are white little dots between blocks at random places, mainly at very near blocks. They disappear when I move the mouse and change the view direction.

I use Vertex Arrays with glVertexAttributePointer to send the data directly to the shader. The shader only adds some fake light based on the face direction and draws the pixels.

What could be the reason for the small white artifacts?

Chunk render code:

public void renderChunk() {
    glPushMatrix();

    glTranslatef(pos.x*world.chunkSize.x, 0.0f, pos.z*world.chunkSize.z);

    glBindBuffer(GL_ARRAY_BUFFER, vao_id);

    glVertexAttribPointer(world.game.positionAtt, 3, GL_FLOAT, false, 32, 0);
    glVertexAttribPointer(world.game.normalAtt, 3, GL_FLOAT, false, 32, 12);
    glVertexAttribPointer(world.game.texCoordAtt, 2, GL_FLOAT, false, 32, 24);

    glDrawArrays(GL_TRIANGLES, 0, arraySize / 8);

    glBindBuffer(GL_ARRAY_BUFFER, 0);

    glPopMatrix();
}

Vertex Shader:

attribute vec3 in_position;
attribute vec3 in_normal;
attribute vec3 in_texcoord;
varying vec2 texture_coordinate;
varying vec3 normal;

void main()
{
    gl_Position = gl_ModelViewProjectionMatrix * vec4(in_position, 1.0);
    normal = in_normal;
    texture_coordinate = in_texcoord;
}

Fragment Shader:

varying vec2 texture_coordinate;
varying vec3 normal;
uniform sampler2D texture;

void main()
{
    float add;

    if (normal.x == 1.0 || normal.z == 1.0) {
        add = 0.65;
    } else if (normal.y != 1.0) {
        add = 0.8;
    } else {
     add = 1.0;
     }
         gl_FragColor = texture2D(texture, texture_coordinate) * add;
     }

Voxel Engine Artifacts (Dots)

Enlarge the image by click it to notice the artifacts.

share|improve this question
5  
Is there any particular reason that you're using the Minecraft default textures? It may be acceptable if it's just a placeholder whilst you do testing, but if you use those graphics anywhere outside of your computer there are copyright issues (as they aren't your graphics). –  Polar Mar 16 '13 at 16:09
    
If you are going to implement a deferred renderer, a post processing anti aliasing would blur these artifacts away. I am not sure what rendering technique you use, but I can't see any anti aliasing in your screenshot. –  danijar Mar 16 '13 at 16:28
    
Basaa, it would be very helpful if we had the code - at the minute all we can do is speculate. Help us help you, if you will. –  Polar Mar 16 '13 at 16:33
1  
Yes, those textures are ofcourse just a placeholder. I'm just experimenting with Voxel Engines, this isn't even going to be a complete game. –  Basaa Mar 16 '13 at 16:54
1  
Added the code. Thanks for the help! –  Basaa Mar 16 '13 at 17:00
show 9 more comments

3 Answers

up vote 5 down vote accepted

I had the same problem with a recent game I'm working on. I guess you are using one big texture with all the block textures in it (like Minecraft does it)?

If so these white pixels appear because of rounding errors in the shader that lead to "empty" texture spots. This occurs even if you do not use texture interpolation (which is the case with your game obviously).

You can circumvent the problem by modifying the texture coordinates to add a little margin. This way the rounding error won't lead to a lookup outside the texture. This may not be the best solution but when it comes to float values you always have to take care of possible rounding problems.

Another way to fix that would be to use one of the more recent GLSL versions that offer a integer based texture lookup method.

share|improve this answer
    
Thank you, this fixed my problem :) –  Basaa Mar 18 '13 at 13:56
add comment

If you build your meshes more carefully, ensuring you are reusing vertices wherever possible, you should be fine: That is, you must not duplicate vertices per face as then the GPU rasteriser will see them as two discrete objects and sometimes fail to rasterise the in-between space (thus defaulting to the GL's clear colour) due to floating point limitations; whereas had you shared the vertices between these same two faces, the rasteriser would have seen each fragment as either belonging to one face or to the other, but never to the space behind them (sky).

Polar rightly notes that Minecraft has these artifacts too. They are only noticeable when you are above a certain depth (y), because the sky(box) colour changes to grey/black once you hit the Deeps, so you won't notice fragments of blue sky shining through. That's one reason they're not as evident as they are in your engine.

The greater reason why your artifacts are more evident than Minecraft's is because the latter constructs RLE-based columnar meshes; that is, the stack of voxels (in y) at every (x,z) location is a single mesh rather than a mesh per block or per face (as you seem to have!), with the texture presumably procedurally generated for the the correct columnar sequence of voxel types. So in MC you won't experience noticeable sky pixels on the ground surface, or on the edges of columns, or vertically between cells; only between columns, and thus much less frequently than in your case, where you seem to have seams all over the place, including on cubes' upper edges.

(P.S. This should also greatly reduce your upload bandwidth and potentially number of draw calls.)

share|improve this answer
    
Very nice! Shared vertices, that's certainly the way to go. –  user1306322 Mar 17 '13 at 16:42
add comment

If you look closely at the dots, you'll see that they're all on the cube edges. The most likely explanation for this is that when you calculate the voxels positions in the viewport (screen), the rendering algorithm isn't seamless - that is, when they are converted from 3D to 2D, there are areas in the 2D which are never mapped to by the 3D world. If you're drawing the edges with a line, which is again quite likely, the line algorithm may miss out the odd pixel.

On the subject of Minecraft (see my comment about graphics and copyright on your post), Minecraft itself has these glitches from time to time - they aren't entirely unexpected. On the other hand, they can be quite annoying - I don't personally know a solution to this off the top of my head; if you really need to remove them, then you'll have to experiment, or ask someone else. Personally though, I wouldn't notice them if the game was any good - I'd be too absorbed in it to see such tiny graphical glitches.

share|improve this answer
2  
Instead I think the artifacts are caused by rounding error of floating point vertex data. –  danijar Mar 16 '13 at 16:29
    
@sharethis It's possible, I agree - it would probably be best to implement your suggestion above. On the other hand, my explanation matches it up with visual glitches I've seen before (without anti-aliasing) - who knows which one is right? Of course, it would help if we had the code. –  Polar Mar 16 '13 at 16:33
    
I agree with that. –  danijar Mar 16 '13 at 17:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.