[英]Display three textures equally on openGL control - OpenTK C#
我有3个纹理应该以相同的方式显示在opengl控件上。 表示texture1应该在glcontrol的0到0.33之间。 并且texture2应该在0.33到0.66之间,而texture3保留在原处。 我已经做了如下。 但是中间图像的右侧部分出现模糊区域。 请帮助纠正
private void CreateShaders()
{
/***********Vert Shader********************/
vertShader = GL.CreateShader(ShaderType.VertexShader);
GL.ShaderSource(vertShader, @"attribute vec3 a_position;
varying vec2 vTexCoordIn;
void main() {
vTexCoordIn=( a_position.xy+1)/2 ;
gl_Position = vec4(a_position,1);
}");
GL.CompileShader(vertShader);
/***********Frag Shader ****************/
fragShader = GL.CreateShader(ShaderType.FragmentShader);
GL.ShaderSource(fragShader, @"
uniform sampler2D sTexture1;
uniform sampler2D sTexture2;
uniform sampler2D sTexture3;
varying vec2 vTexCoordIn;
void main ()
{
vec2 vTexCoord=vec2(vTexCoordIn.x,vTexCoordIn.y);
if ( vTexCoord.x<0.3 )
gl_FragColor = texture2D (sTexture1, vec2(vTexCoord.x*2.0, vTexCoord.y));
else if ( vTexCoord.x>=0.3 && vTexCoord.x<=0.6 )
gl_FragColor = texture2D (sTexture2, vec2(vTexCoord.x*2.0, vTexCoord.y));
else
gl_FragColor = texture2D (sTexture3, vec2(vTexCoord.x*2.0, vTexCoord.y));
}");
GL.CompileShader(fragShader);
}
gl_FragColor = texture2D (sTexture3, vec2(vTexCoord.x*2.0, vTexCoord.y));
^^^^
如果x> = 0.5,则将x坐标乘以2.0会导致值超过1.0。 如果将采样器设置为CLAMP_TO_EDGE(似乎是这种情况),则会导致在纹理的边缘重复采样相同的纹理像素(如您提到的那样出现拖尾/模糊)。
表示texture1应该在glcontrol的0到0.33之间。 并且texture2应该在0.33到0.66之间,而texture3保留在原处。
如果纹理坐标在[ sTexture1
]范围内,则必须绘制sTexture1
并且必须将纹理坐标从[ sTexture1
]映射到[0,1]:
if ( vTexCoord.x < 1.0/3.0 )
gl_FragColor = texture2D(sTexture1, vec2(vTexCoord.x * 3.0, vTexCoord.y));
如果纹理坐标在[ sTexture2
]范围内,则必须绘制sTexture2
并且必须将纹理坐标从[ sTexture2
]映射到[0,1]:
else if ( vTexCoord.x >= 1.0/3.0 && vTexCoord.x < 2.0/3.0 )
gl_FragColor = texture2D(sTexture2, vec2(vTexCoord.x * 3.0 - 1.0, vTexCoord.y));
如果纹理坐标在[ sTexture3
]范围内,则必须绘制sTexture3
并且必须将纹理坐标从[ sTexture3
]映射到[0,1]:
else if ( vTexCoord.x >= 2.0/3.0 )
gl_FragColor = texture2D(sTexture2, vec2(vTexCoord.x * 3.0 - 2.0, vTexCoord.y));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.