尝试在SurfaceView上添加模糊效果和膨胀效果的问题

时间:2019-05-28 14:28:56

标签: android opengl-es glsl

我正在尝试使用高斯模糊来进行实时视频预览,而不是为其添加膨胀效果。

我尝试将代码合并,但似乎无法正常工作。

它只是在做膨胀效果,但我看不到模糊效果。

// Gaussian Blur code
+"   vec2 singleStepOffset = vec2("+UNIFORM_TEXELWIDTH+", "+UNIFORM_TEXELHEIGHT+");\n"
+"   int multiplier = 0;\n"
+"   vec2 blurStep = vec2(0,0);\n"
+"   vec2 blurCoordinates[9];"
+"   for(int i = 0; i < 9; i++) {\n"
+"     multiplier = (i - 4);\n"
+"     blurStep = float(multiplier) * singleStepOffset;\n"
+"     blurCoordinates[i] = "+VARYING_TEXCOORD+".xy + blurStep;\n"
+"   }\n"
+"   vec3 sum = vec3(0,0,0);\n"
+"   vec4 color = texture2D("+UNIFORM_TEXTURE0+", blurCoordinates[4]);\n"
+"   sum += texture2D("+UNIFORM_TEXTURE0+", blurCoordinates[0]).rgb * 0.05;\n"
+"   sum += texture2D("+UNIFORM_TEXTURE0+", blurCoordinates[1]).rgb * 0.09;\n"
+"   sum += texture2D("+UNIFORM_TEXTURE0+", blurCoordinates[2]).rgb * 0.12;\n"
+"   sum += texture2D("+UNIFORM_TEXTURE0+", blurCoordinates[3]).rgb * 0.15;\n"
+"   sum += color.rgb * 0.18;\n"
+"   sum += texture2D("+UNIFORM_TEXTURE0+", blurCoordinates[5]).rgb * 0.15;\n"
+"   sum += texture2D("+UNIFORM_TEXTURE0+", blurCoordinates[6]).rgb * 0.12;\n"
+"   sum += texture2D("+UNIFORM_TEXTURE0+", blurCoordinates[7]).rgb * 0.09;\n"
+"   sum += texture2D("+UNIFORM_TEXTURE0+", blurCoordinates[8]).rgb * 0.05;\n"
+"   gl_FragColor = vec4(sum, color.a);\n"

// Dilation Effect
+"   vec2 step = vec2("+UNIFORM_TEXELWIDTH+", "+UNIFORM_TEXELHEIGHT+");\n"
+"   vec4 stepIntensity[dilationSize];\n"
+"   for(int i = 0; i < dilationSize; i++) {\n"
+"     stepIntensity[i] = texture2D("+UNIFORM_TEXTURE0+", "+VARYING_TEXCOORD+" + step * float(i - dilationRadius));\n"
+"   }\n"

+"   vec4 minValue = vec4(1.0);\n"
+"   for(int i = 0; i < dilationSize; i++) {\n"
+"     minValue = min(minValue, stepIntensity[i]);\n"
+"   }\n"
+"gl_FragColor = minValue;\n"

我希望它会模糊而不是扩张,但它只会扩张图像。

0 个答案:

没有答案