Problem of texture in distance

Hello,

I’m making a voxel game. So, i use my own algo for optimize and improve the fps. For information, I use shaders.
I have the rendering that i want, but in distance I have a freaky bug. See the http://www.noelshack.com/2015-12-1426533011-screenshot.png
As you can see, there are some brown lines between the chunks. But when I walk towards them, they retreat, I don’t understand why… Could you help me ?

Progy

A similiar result happens when you use a texture atlas and the magfilter picks some pixel from the next texture, but it can’t be your case unless you are using a single uvmap for the entire chunk.
Could you post the fragment shader?

This is my code :

    if(inNormal2.z >= 0.9f){
    //gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
    if(m_size.z < m_size.y){

        color = texture2D(m_data, vec2((inPosition2.x+(inPosition2.z-1)*m_size.x)/(m_size.x*m_size.z)/(m_size.y    /m_size.z), inPosition2.y/(m_size.y*4+m_size.z*2)));
    }
    else{
        
        color = texture2D(m_data, vec2((inPosition2.x+(inPosition2.z-1)*m_size.x)/(m_size.x*m_size.z),    inPosition2.y/(m_size.y*4+m_size.z*2)));
    }
    
    }
    else if(inNormal2.z <= -0.9f){
    //gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);

    if(m_size.z < m_size.y){
    
        color = texture2D(m_data, vec2((inPosition2.x+inPosition2.z*m_size.x)/(m_size.x*m_size.z)/(m_size.y/m_size.z), (inPosition2.y+m_size.y)/(m_size.y*4+m_size.z*2)));
    }
    else{

        color = texture2D(m_data, vec2((inPosition2.x+inPosition2.z*m_size.x)/(m_size.x*m_size.z), (inPosition2.y+m_size.y)/(m_size.y*4+m_size.z*2)));
    }
    }
    else if(inNormal2.x <= -0.9f){
    //gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0);

    if(m_size.z < m_size.y){

        color = texture2D(m_data, vec2((inPosition2.z+inPosition2.x*m_size.z)/(m_size.x*m_size.z)/(m_size.y/m_size.z), (inPosition2.y+2*m_size.y)/(m_size.y*4+m_size.z*2)));
    }
    else{

        color = texture2D(m_data, vec2((inPosition2.z+inPosition2.x*m_size.z)/(m_size.x*m_size.z),    (inPosition2.y+2*m_size.y)/(m_size.y*4+m_size.z*2)));
    }
     }
    else if(inNormal2.x >= 0.9f){

    if(m_size.z < m_size.y){

        color = texture2D(m_data, vec2((inPosition2.z+(inPosition2.x-1)*m_size.z)/(m_size.x*m_size.z)/(m_size.y    /m_size.z), (inPosition2.y+3*m_size.y)/(m_size.y*4+m_size.z*2)));
    }
    else{

        color = texture2D(m_data, vec2((inPosition2.z+(inPosition2.x-1)*m_size.z)/(m_size.x*m_size.z), (inPosition2.y+3*m_size.y)/(m_size.y*4+m_size.z*2)));
    }
    }
   else if(inNormal2.y >= 0.9f){
    //gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
    if(m_size.z < m_size.y){
      
        color = texture2D(m_data, vec2((inPosition2.x+(inPosition2.y-1)*m_size.x)/(m_size.x*m_size.y), (inPosition2.z+4*m_size.y)/(m_size.y*4+m_size.z*2)));
    }
    else{

        color = texture2D(m_data, vec2((inPosition2.x+(inPosition2.y-1)*m_size.x)/(m_size.x*m_size.y)/(m_size.z/m_size.y), (inPosition2.z+4*m_size.y)/(m_size.y*4+m_size.z*2)));
    }
    }
    else if(inNormal2.y <= -0.9f){
    //gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);

    if(m_size.z < m_size.y){
      
        color = texture2D(m_data, vec2((inPosition2.x+inPosition2.y*m_size.x)/(m_size.x*m_size.y), (inPosition2.z+4*m_size.y+m_size.z)/(m_size.y*4+m_size.z*2)));
    }
    else{

        color = texture2D(m_data, vec2((inPosition2.x+inPosition2.y*m_size.x)/(m_size.x*m_size.y)/(m_size.z/m_size.y), (inPosition2.z+4*m_size.y+m_size.z)/(m_size.y*4+m_size.z*2)));
    }
    }

    color.x *= 10;

    color.x = sign(color.x)*floor(abs(color.x)+0.5)-1;

    vector = texCoord;


    while(vector.x > color.x){

        vector.x -= 1;
    }

    while(vector.x < color.x){

        vector.x += 1;
    }

    gl_FragColor = texture2D(m_dataBlocs, vec2(vector.x/11, vector.y));

If you fill m_dataBlocs with a solid color the lines are still present? And if you set the MagFilter to MagFilter.Nearest and the MinFilter to MinFilter.NearestNoMipMaps?

The MagFilter and the MinFilter are still set to MagFilter.Nearest and to MinFilter.NearestNoMipMaps. But if I fill m_dataBlocs with a solid color the lines disappear ! Have you any idea to explain it ?

The min/max filtering isn’t fixing it on the texture… then it’s your coordinates that are bleeding outside of the atlas section.

Okay, but why this bug exists only between the chunks ?

Could you explain a bit what you are doing in your code? For example, what is m_data and why you divide vector.x for 11?
Also, this is quite OT but, for performance’s sake, you shouldn’t use two while cycles for make vector.x equals to color.x…

…because that’s at the edge of the ‘cell’ in the atlas… you are picking up the neighboring cell at the edges. I don’t know how else to explain it really as this is an extremely common problem with texture atlases. I mean, we’re assuming that you are using an atlas anyway.

Otherwise, I see lines even in the foreground perhaps the farground lines are just the grossly foreshortened version… but more likely it’s a texture atlas bleeding problem. You can probably google search “texture atlas bleeding” to get an overview of the issue in your code.

m_data is a texture where there are all my textures of block. I divide it by 11 because there are 11 textures. How can I replace the 2 while ?

I changed the texture of my blocks, and I saw that : http://www.noelshack.com/2015-12-1426677088-capture-d-ecran-16.png
As you can see, there are some white points in the background, but no lines, why ?

http://lmgtfy.com/?q=texture+atlas+bleed

I remplaced the two while by : vector.x += color.x - int(texCoord.x);
It’s better I think. But, I have still my bug.

I have already google it, but I didn’t find the solution.

Its a little hard to tell, but to me it seems your shader is selecting the brown texture at the edges of the blocks for some reason. Why its doing that, well, that’s a question for you, because you wrote the shader?

Yes it’s why i’m searching. My main trouble is why this bug exists only between the chunks ? I’m searching the solution…

Unless your chunks are cell-sized then it doesn’t exist only between the chunks as it’s clearly between every cell in some cases. So maybe you need to define the terms you are using.

My chunks have a surface of 16x16 blocks

These seem much closer than just “between chunks” then:

You probably say I’m crazy, but maybe there is two bugs : the lines between the chunks and the white points. Because on the first screenshot I sended we don’t see the white points…