如何从GLControl的底部和顶部切割/隐藏投影区域-openTK

时间:2019-06-18 07:30:06

标签: opengl glsl opentk coordinate-transformation

借助此link,我可以将图像投影为圆柱形状。是否可以如下图所示从图像的顶部和底部删除或隐藏投影区域? enter image description here

1 个答案:

答案 0 :(得分:1)

您必须根据 u .y)纹理坐标discard进行碎片整理。

根据原始问题How to project top and bottom area of openGL control的片段着色器:

precision highp float;
uniform sampler2D sTexture;
varying vec2 vTexCoord;

void main()
{
     vec2  pos     = vTexCoord.xy * 2.0 - 1.0;
     float b       = 0.3;
     float v_scale = (1.0 + b) / (1.0 + b * sqrt(1.0 - pos.x*pos.x));

     float u = asin( pos.x ) / 3.1415 + 0.5;
     float v = (pos.y * v_scale) * 0.5 + 0.5;
     if ( v < 0.0 || v > 1.0 )
          discard;

     vec3 texColor = texture2D( u_texture, vec2(u, v) ).rgb;
     gl_FragColor  = vec4( texColor.rgb, 1.0 );
}

大小必须由变量b限制:

if (abs(pos.y) * (1.0 + b) > 1.0)
    discard;