Android GPUImage

编程入门 行业动态 更新时间:2024-10-07 09:26:23

<a href=https://www.elefans.com/category/jswz/34/1771384.html style=Android GPUImage"/>

Android GPUImage

1.效果图

2.shader

"attribute vec4 position;\n" +"attribute vec4 inputTextureCoordinate;\n" +"\n" +"uniform float imageWidthFactor; \n" +"uniform float imageHeightFactor; \n" +"uniform float sharpness;\n" +"\n" +"varying vec2 textureCoordinate;\n" +"varying vec2 leftTextureCoordinate;\n" +"varying vec2 rightTextureCoordinate; \n" +"varying vec2 topTextureCoordinate;\n" +"varying vec2 bottomTextureCoordinate;\n" +"\n" +"varying float centerMultiplier;\n" +"varying float edgeMultiplier;\n" +"\n" +"void main()\n" +"{\n" +"    gl_Position = position;\n" +"    \n" +"    mediump vec2 widthStep = vec2(imageWidthFactor, 0.0);\n" +"    mediump vec2 heightStep = vec2(0.0, imageHeightFactor);\n" +"    \n" +"    textureCoordinate = inputTextureCoordinate.xy;\n" +"    leftTextureCoordinate = inputTextureCoordinate.xy - widthStep;\n" +"    rightTextureCoordinate = inputTextureCoordinate.xy + widthStep;\n" +"    topTextureCoordinate = inputTextureCoordinate.xy + heightStep;     \n" +"    bottomTextureCoordinate = inputTextureCoordinate.xy - heightStep;\n" +"    \n" +"    centerMultiplier = 1.0 + 4.0 * sharpness;\n" +"    edgeMultiplier = sharpness;\n" +"}";

 

static final String SHARPEN_FRAGMENT_SHADER = "" +"precision highp float;\n" +"\n" +"varying highp vec2 textureCoordinate;\n" +"varying highp vec2 leftTextureCoordinate;\n" +"varying highp vec2 rightTextureCoordinate; \n" +"varying highp vec2 topTextureCoordinate;\n" +"varying highp vec2 bottomTextureCoordinate;\n" +"\n" +"varying highp float centerMultiplier;\n" +"varying highp float edgeMultiplier;\n" +"\n" +"uniform sampler2D inputImageTexture;\n" +"\n" +"void main()\n" +"{\n" +"    mediump vec3 textureColor = texture2D(inputImageTexture, textureCoordinate).rgb;\n" +"    mediump vec3 leftTextureColor = texture2D(inputImageTexture, leftTextureCoordinate).rgb;\n" +"    mediump vec3 rightTextureColor = texture2D(inputImageTexture, rightTextureCoordinate).rgb;\n" +"    mediump vec3 topTextureColor = texture2D(inputImageTexture, topTextureCoordinate).rgb;\n" +"    mediump vec3 bottomTextureColor = texture2D(inputImageTexture, bottomTextureCoordinate).rgb;\n" +"\n" +"    gl_FragColor = vec4((textureColor * centerMultiplier - (leftTextureColor * edgeMultiplier + rightTextureColor * edgeMultiplier + topTextureColor * edgeMultiplier + bottomTextureColor * edgeMultiplier)), texture2D(inputImageTexture, bottomTextureCoordinate).w);\n" +"}";

3.原理

取上下左右四个点,把中心点的像素按照一定的sharpness来改变,临近的像素是比较相似的。

更多推荐

Android GPUImage

本文发布于:2024-03-23 20:47:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1742645.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Android   GPUImage

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!