问题
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