为什么我的质地不光滑?

时间:2016-05-10 00:11:39

标签: android shader opengl-es-2.0 texture2d

我想在视频预览中显示一些对象。让我们说它是一杯。 此项目的png图片是定性图片1024x1024。 我正在使用面具来获得结果。 (掩码是对象的二进制图像)

我以这种方式加载纹理:

public static int loadTexture(final Context context, final String name){
    final int[] textureHandle = new int[1];

    GLES20.glGenTextures(1, textureHandle, 0);

    if (textureHandle[0] != 0){

        // Read in the resource
        final Bitmap bitmap = getImageFromAssetsFile(context,name);

        // Bind to the texture in OpenGL
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);

        // Set filtering
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
        // Load the bitmap into the bound texture.
        GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);

        // Recycle the bitmap, since its data has been loaded into OpenGL.
        bitmap.recycle();                       
    }

    if (textureHandle[0] == 0){
        throw new RuntimeException("Error loading texture.");
    }

    return textureHandle[0];
}

这是我的片段着色器

precision mediump float;

 varying mediump vec2 textureCoordinate;

 uniform sampler2D inputImageTexture;
 uniform sampler2D inputImageTexture3;//glass shaped mask
 uniform sampler2D inputImageTexture4;//my glass


 void main()
 {
      vec2 tempCoordinate = textureCoordinate;

      vec2 shapePos = vec2(1.4*tempCoordinate.x, 1.2*tempCoordinate.y-0.1);

      vec4 originColor = texture2D(inputImageTexture, tempCoordinate);
      vec4 vMask = texture2D(inputImageTexture3, shapePos );
      vec4 butterfly = texture2D(inputImageTexture4, shapePos );
      if (vMask.r > 0.5)
          gl_FragColor = originColor*butterfly;
      else
          gl_FragColor = originColor;
 }

图片1(漂亮的光滑玻璃):

enter image description here

图像2(着色器结果):

enter image description here

我的问题是如何产生更少的锯齿?

0 个答案:

没有答案