How to cut/hide projected area from bottom and top of GLControl - openTK

荒凉一梦 提交于 2019-12-13 01:18:44

问题


With the help of this link, I can project an image in cylindrical shape. Can I able to remove or hide the projected area from top and bottom of image as shown in the image below?


回答1:


You have to discard fragmnts dependent on the u (.y) texture coordinate.

According to the fragment shader of the original question 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 );
}

The size has to be limited by the variable b:

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


来源:https://stackoverflow.com/questions/56643876/how-to-cut-hide-projected-area-from-bottom-and-top-of-glcontrol-opentk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!