如何解决快速径向模糊着色器-GLSL
我尝试使用GLSL着色器进行快速无线电模糊处理,这是我的实现:
- 第1遍,以单位步长为单位,计算模糊方向上16个样本的平均颜色。
- 第2遍,计算16个步长沿模糊方向的3个样本的平均颜色。
通过这个,我想得到48的模糊长度的结果,但是我在这里得到了一些伪像
我还测试了均匀方向上的模糊,该模糊还显示了一些伪像,但更少。这是我的着色器代码,您可以在shadertoy上对其进行测试:
// bruteforce mathod
#iChannel0 "file://E:/workspace/data/color_test.png"
const float u_sample_step = 1.0;
const int u_nsample = 48;
const vec2 u_center = vec2(0.5); // center in origional image,normalized to [0,1]
void main() {
vec2 coord = gl_FragCoord.xy / iResolution.xy;
//vec2 cstep = u_sample_step/iResolution.xy * normalize(u_center - coord);
vec2 cstep = u_sample_step/iResolution.xy * normalize(u_center - coord);
vec4 color = vec4(0.0);
for(int i=0; i<u_nsample; ++i) {
color += texture2D(iChannel0,coord);
coord += cstep;
}
gl_FragColor = color/float(u_nsample);
}
改进方法的第1遍:
#iChannel0 "test.png"
const float u_sample_step = 1.0;
const int u_nsample = 16;
const vec2 u_center = vec2(0.5); // center in origional image,coord);
coord += cstep;
}
gl_FragColor = color/float(u_nsample);
}
改进方法的第二遍:
#iChannel0 "pass1.frag"
const float u_sample_step = 16.0;
const int u_nsample = 3;
const vec2 u_center = vec2(0.5); // center in origional image,coord);
coord += cstep;
}
gl_FragColor = color/float(u_nsample);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。