如何 cut/hide 从 GLControl 的底部和顶部投影区域 - openTK
How to cut/hide projected area from bottom and top of GLControl - openTK
借助这个,我可以投影出圆柱形的图像。我能否移除或隐藏图像顶部和底部的投影区域,如下图所示?
您必须 discard
依赖于 u (.y
) 纹理坐标的片段。
根据原题的fragment shader:
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;
借助这个
您必须 discard
依赖于 u (.y
) 纹理坐标的片段。
根据原题
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;