OpenTK上的圆柱投影-C#

时间:2019-05-23 07:20:44

标签: c# opengl fragment-shader opentk cylindrical

使用以下着色器代码,我可以在openGL窗口上平均显示三个纹理。在整个轮廓上的投影也是可能的。 我可以将此投影应用于每种纹理吗?意味着在单个opengl窗口中,每个纹理都应该具有圆柱投影。

   private void CreateShaders()
    {
        /***********Vert Shader********************/
        vertShader = GL.CreateShader(ShaderType.VertexShader);
        GL.ShaderSource(vertShader, @"attribute vec3 a_position;
                                varying vec2 vTexCoordIn; 
     void main() {
       vTexCoordIn=( a_position.xy+1)/2;
      gl_Position = vec4(a_position,1);
      }");
        GL.CompileShader(vertShader);

        /***********Frag Shader ****************/
        fragShader = GL.CreateShader(ShaderType.FragmentShader);
        GL.ShaderSource(fragShader, @"
uniform sampler2D sTexture;
uniform sampler2D sTexture1;
uniform sampler2D sTexture2; 

varying vec2 vTexCoordIn;
 uniform int ShowProjection;

void main ()
{                                               
vec2 vTexCoord=vec2(vTexCoordIn.x,vTexCoordIn.y);
if ( vTexCoord.x < 1.0/3.0 )///Left
{
    vec2 uv = vec2(vTexCoord.x * 3.0, vTexCoord.y);
    gl_FragColor = texture2D(sTexture, uv);
}
else if ( vTexCoord.x >= 1.0/3.0 && vTexCoord.x < 2.0/3.0 )//center
{    vec2 uv = vec2(vTexCoord.x * 3.0 - 1.0, vTexCoord.y);
     gl_FragColor = texture2D(sTexture1, uv);
}
else if ( vTexCoord.x >= 2.0/3.0 )//right
{
    vec2 uv = vec2(vTexCoord.x * 3.0 - 2.0, vTexCoord.y);
    gl_FragColor = texture2D(sTexture2, uv);
}
//Apply Projection  
if(ShowProjection==1)
{
vec2  pos     = vTexCoord.xy* 2.0 - 1.0;
float b       = 0.2;
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;
 gl_FragColor= vec4(1.0, 1.0, 1.0, 1.0);
}
 }");
     GL.CompileShader(fragShader);}

0 个答案:

没有答案