为什么这个片段着色器在某些sumsung设备上运行有很多红热点

时间:2015-08-21 03:09:37

标签: android opengl-es shader

public static final String LOOKUP_FRAGMENT_SHADER = "varying highp vec2 textureCoordinate;\n" +
        " varying highp vec2 textureCoordinate2; // TODO: This is not used\n" +
        " \n" +
        " uniform sampler2D inputImageTexture;\n" +
        " uniform sampler2D inputImageTexture2; // lookup texture\n" +
        " \n" +
        " void main()\n" +
        " {\n" +
        "     lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" +
        "     \n" +
        "     mediump float blueColor = textureColor.b * 63.0;\n" +
        "     \n" +
        "     mediump vec2 quad1;\n" +
        "     quad1.y = floor(blueColor/ 8.0);\n" +
        "     //quad1.y = floor(floor(blueColor) / 8.0);\n" +
        "     quad1.x = floor(blueColor) - (quad1.y * 8.0);\n" +
        "     \n" +
        "     mediump vec2 quad2;\n" +
        "     quad2.y = floor(ceil(blueColor) / 7.999);\n" +
        "     quad2.x = ceil(blueColor) - (quad2.y * 8.0);\n" +
        "     \n" +
        "     highp vec2 texPos1;\n" +
        "     texPos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r);\n" +
        "     texPos1.y = (quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g);\n" +
        "     \n" +
        "     highp vec2 texPos2;\n" +
        "     texPos2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r);\n" +
        "     texPos2.y = (quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g);\n" +
        "     \n" +
        "     lowp vec4 newColor1 = texture2D(inputImageTexture2, texPos1);\n" +
        "     lowp vec4 newColor2 = texture2D(inputImageTexture2, texPos2);\n" +
        "     \n" +
        "     lowp float mixPercent=fract(blueColor);\n" +
        "     lowp vec4 newColor = mix(newColor1, newColor2, mixPercent);\n" +
        "     gl_FragColor = vec4(newColor.rgb, textureColor.w);\n" +
        " }";

当我使用" quad1.y = floor(blueColor / 8.0);"替换" quad1.y = floor(floor(blueColor)/ 8.0)",一切正常,没有红点。

我已经编写了一个使用java代码的演示,它们总是有相同的结果..我不知道为什么它们在片段着色器中有不同的效果。

1 个答案:

答案 0 :(得分:0)

尝试在inputImageTexture2纹理上禁用包装吗?

即。在绑定inputImageTexture2纹理时调用这些函数。

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);