Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opengl的shader的写法存在机型兼容性问题 #14

Closed
liuhongda opened this issue Sep 18, 2019 · 1 comment
Closed

opengl的shader的写法存在机型兼容性问题 #14

liuhongda opened this issue Sep 18, 2019 · 1 comment

Comments

@liuhongda
Copy link

private static String getGaussianSampleCode() {

    StringBuilder sb = new StringBuilder();

    sb.append("   int diameter = 2 * uRadius + 1;  \n")
            .append("   vec4 sampleTex;\n")
            .append("   vec3 col;  \n")
            .append("   float weightSum = 0.0; \n")
            .append("   for(int i = 0; i < diameter; i++) {\n")
            .append("       vec2 offset = vec2(float(i - uRadius) * uWidthOffset, float(i - uRadius) * uHeightOffset);  \n")
            .append("       sampleTex = vec4(texture2D(uTexture, vTexCoord.st+offset));\n")
            .append("       float index = float(i); \n")
            .append("       float gaussWeight = getGaussWeight(index - float(diameter - 1)/2.0,")
            .append("           (float(diameter - 1)/2.0 + 1.0) / 2.0); \n")
            .append("       col += sampleTex.rgb * gaussWeight; \n")
            .append("       weightSum += gaussWeight;\n")
            .append("   }   \n")
            .append("   gl_FragColor = vec4(col / weightSum, sampleTex.a);   \n");

    return sb.toString();
}

如上:vec3 col的写法最好写成vec3 col = vec3(0.0,0.0,0.0);主动进行初始化,否则在一些机型上会有问题,导致最终渲染效果不正确

HokoFly added a commit that referenced this issue Oct 3, 2019
@HokoFly
Copy link
Owner

HokoFly commented Oct 3, 2019

已修复,感谢提醒

@HokoFly HokoFly closed this as completed Oct 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants