原始图像
处理后
核心源码
1 #version 330 core 2 out vec4 FragColor; 3
4 in vec2 TexCoords; 5 6 uniform sampler2D texture1; 7 uniform float gauss[21]; 8 9 const vec2 texSize = vec2(1000, 800); 10 11 void main() 12 { 13 float xStep, yStep; 14 xStep = 1.0 / 1000.0; 15 vec4 color = vec4(0.0); 16 //X方向 17 for(int i = 1; i < 21; i++) 18 { 19 if(TexCoords.x - xStep * i > 0.0) 20 { 21 color += (texture(texture1, vec2(TexCoords.x - xStep * i, TexCoords.y)) * gauss[i]) ; 22 } 23 24 if(TexCoords.x + xStep * i < 1.0) 25 { 26 color += (texture(texture1, vec2(TexCoords.x + xStep * i, TexCoords.y)) * gauss[i]); 27 } 28 } 29 FragColor = color; 30 }
1 float g_GaussNum[21]; 2 float gauss(int x) 3 { 4 float pi = 3.1415927f; 5 float e = 2.71828f; 6 float theta = 0.1f; 7 float theta2 = theta * theta; 8 float temp1 = 1.0f / (theta * sqrt(2 * pi)); 9 float temp2 = pow(e, -(x * x) / 2 * theta2); 10 return temp1 * temp2; 11 } 12 13 void calculateGauss() 14 { 15 g_GaussNum[0] = 1.0f; 16 17 for (int i = 1; i < sizeof(g_GaussNum) / sizeof(g_GaussNum[0]); i++) { 18 g_GaussNum[i] = gauss(i); 19 } 20 21 float total = 0.0f; 22 for (int i = 0; i < sizeof(g_GaussNum) / sizeof(g_GaussNum[0]); i++) { 23 total += g_GaussNum[i]; 24 } 25 26 for (int i = 0; i < sizeof(g_GaussNum) / sizeof(g_GaussNum[0]); i++) { 27 g_GaussNum[i] = g_GaussNum[i] / total; 28 } 29 }