我正在尝试将1D纹理应用于线条。它工作但线条闪烁。我不想要这种闪光效果。就像在图片上。
我还添加了一个关于闪烁问题的视频:
我该如何解决这个问题?我正在添加以下代码。
顶点着色器:
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;
}
片段着色器:
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;
}
纹理:
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);
绘制部分:
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);