1 Shader "Custom/gaussY" {
4 //_webcamTex ("Base (RGB)", 2D) = "" {}
5 _MainTex ("Texture Image", 2D) = "white" {}
6 _EdgeTex ("_EdgeTex", 2D) = "white" {}
8 _TexSizeX ("Texture Width", Float) = 0.0
9 _TexSizeY ("Texture Height", Float) = 0.0
10 _Sigma ("_Sigma", Float) = 0.0
11 _KernelSize ("_KernelSize", Float) = 0.0
17 //Tags { "Queue" = "Geometry" }
21 // #pragma only_renderers gles
22 #define M_PI 3.1415926535897932384626433832795
24 uniform sampler2D _MainTex;
25 uniform sampler2D _EdgeTex;
27 uniform float _TexSizeX;
28 uniform float _TexSizeY;
30 varying vec4 textureCoordinates;
34 uniform float _KernelSize;
35 // float kernel[5] = float[](0.00296901674395065, 0.013306209891014005, 0.02193823127971504, 0.013306209891014005, 0.00296901674395065);
36 // const float kernel1[kernelSize] = float[kernelSize](0.013306209891014005, 0.05963429543618023, 0.09832033134884507, 0.05963429543618023, 0.013306209891014005);
37 // const float kernel2[kernelSize] = float[kernelSize](0.02193823127971504, 0.09832033134884507, 0.16210282163712417, 0.09832033134884507, 0.02193823127971504);
38 // const float kernel3[kernelSize] = float[kernelSize](0.013306209891014005, 0.05963429543618023, 0.09832033134884507, 0.05963429543618023, 0.013306209891014005);
39 // const float kernel4[kernelSize] = float[kernelSize](0.00296901674395065, 0.013306209891014005, 0.02193823127971504, 0.013306209891014005, 0.00296901674395065);
47 gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
52 // textureCoordinates = vec4(gl_Position.x * -1.0, gl_Position.y, gl_Position.z, gl_Position.w);
53 textureCoordinates = (gl_Position + 1.0) * 0.5;
58 // textureCoordinates = (gl_Position + 1.0) * 0.5;
59 // textureCoordinates = textureCoordinates.yxzw;
69 float getGaussValue(int x, float sigma){
72 return exp(-float(x*x)/(2.0 * sigma * sigma))/(sqrt(2.0 * M_PI) * sigma);
80 vec4 c = vec4(0.0, 0.0, 0.0, 0.0);
82 highp int halfKernelSize = int((_KernelSize-1.0)/2.0);
85 // float sigma = clamp(1.0 - texture2D(_EdgeTex, vec2(textureCoordinates)).r, 0.001, 1.0) * _Sigma;
88 for(int y = -halfKernelSize; y<=halfKernelSize; y++){
91 // c += getGaussValue(x, y, sigma) * texture2D(_MainTex, vec2(textureCoordinates) + vec2(x/_TexSizeX, y/_TexSizeY));
92 // c += (exp(-float(x*x+y*y)/(2.0 * _Sigma * _Sigma))/(2.0 * 3.1415926535897932384626433832795 * _Sigma * _Sigma)) * texture2D(_MainTex, vec2(textureCoordinates) + vec2(float(x)/_TexSizeX, float(y)/_TexSizeY));
94 c += getGaussValue(y, _Sigma) * texture2D(_MainTex, vec2(textureCoordinates) + vec2(0.0, float(y)/_TexSizeY));
98 gl_FragColor = vec4(c.x, c.y, c.z, 1.0);