在废弃区域以外的地方投影

时间:2019-07-15 05:20:20

标签: c# opengl glsl fragment-shader opentk

借助this链接,我可以在OpenGL控件上应用投影。 但是当在着色器代码下面尝试这种投影时,我也在废弃区域上也得到了投影。我只想显示除废弃区域以外的投影。

precision highp float;

uniform sampler2D sTexture;
varying vec2 vTexCoordIn;

void main ()
{
    float rightsliderStartval = 0.7;
    float rightsliderEndval   = 0.9;

    if (vTexCoordIn.x < 0.7 || vTexCoordIn.x > 0.9)
        discard;

    //  vec4 color = texture2D(sTexture, vTexCoordIn.xy));
    //  gl_FragColor = color;

    vec2  pos     = vTexCoordIn.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 );
}

enter image description here

1 个答案:

答案 0 :(得分:1)

如果您不想使“废弃”区域变形,只需保留原始纹理坐标即可:

router.get('/:city', function(req, res) {
  var data = {teams: []};
  myService.teamsInCity(req.params.city, 1, [], function(err, teams) {
    if (err) {
      logger.error('Error while retrieving teams in ' + req.params.city);
    }
    data.teams = _.sortBy(teams, 'name');
    res.send(data);
  });
});