Unwanted Shimmering Effect with 1D Texture on Lines

Hi Everyone,
I am trying to apply 1D texture to lines. It works but lines shimmer. I don’t want this shimmering effect. Like on the picture.

[ATTACH=CONFIG]801[/ATTACH]

How can I solve this problem? I am adding the codes below.

Vertex Shader:

attribute vec4 vertexMC;
uniform mat4 MCVCMatrix;
uniform mat4 VCDCMatrix;
attribute float tcoordMC;
varying float tcoordVC;
void main()
{
    tcoordVC=(vertexMC.x+vertexMC.y+vertexMC.z)/3.0;
    gl_Position=VCDCMatrix*MCVCMatrix*vertexMC;
}

Fragment Shader:

varying float tcoordVC;
uniform sampler1D texture1;
uniform vec3 GridColor;
void main()
{
    gl_FragColor=vec4(GridColor, texture1D(texture1,tcoordVC).a);
    if (gl_FragColor.a <= 0.0) discard;
}

Texture:

glGenTextures(1, &texture);
glActiveTexture(GL_TEXTURE1);
glBindTexture( GL_TEXTURE_1D, texture );

glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

unsigned char buf[ 16 * 4 ];
for( size_t i=0; i < sizeof( buf ); i+=4 )
{
    buf[ i+0 ]=255;
    buf[ i+1 ]=0;
    buf[ i+2 ]=0;
}

buf[3]= 255;
buf[7]= 0;
buf[11]=255;
buf[15]=0;
buf[19]=255;
buf[23]=0;
buf[27]=255;
buf[31]=0;
buf[35]=255;
buf[39]=0;
buf[43]=255;
buf[47]=0;
buf[51]=255;
buf[55]=0;
buf[59]=255;
buf[63]=0;

glTexImage1D( GL_TEXTURE_1D, 0, 4, sizeof( buf ) / 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, buf );
InternalShader->Program.SetUniformi("texture1",1);

Draw Section:

glEnable( GL_TEXTURE_1D );
glBindTexture( GL_TEXTURE_1D, texture);

for(unsigned int i=0;i<GridsInternal.size();i++)
{        
    AGrid=GridsInternal[i];

    if(!AGrid->GetActivity())
        continue;

    ACellBO=CellBOs[i];
    AVBO=VBOs[i];
    ALayout=Layouts[i];

    AVBO->Bind();

    SetMapperShaderParameters(i);
    SetPropertyShaderParameters(i);
    ACellBO->ibo.Bind();

    glDrawRangeElements(GL_LINES, 0,
                        static_cast<GLuint>(ALayout->VertexCount-1),
                        static_cast<GLsizei>(ACellBO->indexCount),
                        GL_UNSIGNED_INT,
                        reinterpret_cast<const GLvoid *>(NULL));

    AVBO->Release();
    ACellBO->ibo.Release();
    ACellBO->vao.Release();
}

glDeleteTextures(1, &texture);
glDisable(GL_TEXTURE_1D);

[QUOTE=BrainPrism;1262625]Hi Everyone,
I am trying to apply 1D texture to lines. It works but lines shimmer. I don’t want this shimmering effect. Like on the picture.

[ATTACH=CONFIG]1508[/ATTACH]

How can I solve this problem?[/QUOTE]

Your lines are being undersampled. Read up on OpenGL line smoothing and glLineWidth.

Hi I just want to obtain dashed lines without shimmering. When the camera is middle of the lines and perpendicular it is ok but when I move the camera lines start to shimmering. Also when position of points smaller it is ok,too but positions are getting bigger it starts to shimmer again. I think problem isn’t about smoothing? I also added glEnable( GL_LINE_SMOOTH ); now it is shimmering and also there is a effect I dont want for dashed line like on picture.[ATTACH=CONFIG]803[/ATTACH]

when I added glLineWith it goes like that:

[ATTACH=CONFIG]804[/ATTACH]

might be problem about texture coordinates I calculate it simply

tcoordVC=(vertexMC.x+vertexMC.y+vertexMC.z)/3.0;

But I have just draw lines which is strech around X axes with :

tcoordVC=vertexMC.x;

this is shimmering, too.

It’s difficult to tell without seeing it move, but at a guess, using point sampling without mipmapping is also going to cause this kind of shimmering.

hi mhagain,

I’ve added a video about shimmiering problem:

https://drive.google.com/file/d/0ByJDypWl2oFiekxSUjAtSUM2U00/view

I looked at your video. It’s working perfectly. Your problem is you are oversampling and don’t seem to want perspective dashes. Right? You want dashed lines of a consistent length that do not get smaller with distance. To accomplish this you could sample texture in eye space after the perspective divide or you could compensate by specifying a W texture coordinate that undid the perspective transformation.

P.S. as has already been said, if you want dashed lines that get smaller in perspective without shimmering (they’ll fade to a % of dash coverage) then you should use 1D MIP map textures.