3DSelfie  Hansjoerg Hofer (1026632), Sebastian Metzler (0927550)
gaussY.shader
Go to the documentation of this file.
1 Shader "Custom/gaussY" {
2  Properties
3  {
4  //_webcamTex ("Base (RGB)", 2D) = "" {}
5  _MainTex ("Texture Image", 2D) = "white" {}
6  _EdgeTex ("_EdgeTex", 2D) = "white" {}
7 
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
12 
13 
14  }
15  SubShader
16  {
17  //Tags { "Queue" = "Geometry" }
18  Pass
19  {
20  GLSLPROGRAM
21 // #pragma only_renderers gles
22  #define M_PI 3.1415926535897932384626433832795
23 
24  uniform sampler2D _MainTex;
25  uniform sampler2D _EdgeTex;
26 
27  uniform float _TexSizeX;
28  uniform float _TexSizeY;
29 
30  varying vec4 textureCoordinates;
31 
32 
33  uniform float _Sigma;
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);
40 
41  #ifdef VERTEX
42 
43  void main()
44  {
45 
46 
47  gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
48 
49 
50  //desktop
51 
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;
54 
55 
56  //mobile
57 
58 // textureCoordinates = (gl_Position + 1.0) * 0.5;
59 // textureCoordinates = textureCoordinates.yxzw;
60  }
61  #endif
62 
63 
64 
65 
66  #ifdef FRAGMENT
67 
68 
69  float getGaussValue(int x, float sigma){
70 
71 
72  return exp(-float(x*x)/(2.0 * sigma * sigma))/(sqrt(2.0 * M_PI) * sigma);
73  }
74 
75 
76 
77  void main()
78  {
79 
80  vec4 c = vec4(0.0, 0.0, 0.0, 0.0);
81 
82  highp int halfKernelSize = int((_KernelSize-1.0)/2.0);
83 //
84 
85 // float sigma = clamp(1.0 - texture2D(_EdgeTex, vec2(textureCoordinates)).r, 0.001, 1.0) * _Sigma;
86 
87 
88  for(int y = -halfKernelSize; y<=halfKernelSize; y++){
89 
90 
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));
93 //
94  c += getGaussValue(y, _Sigma) * texture2D(_MainTex, vec2(textureCoordinates) + vec2(0.0, float(y)/_TexSizeY));
95 //
96  }
97 //
98  gl_FragColor = vec4(c.x, c.y, c.z, 1.0);
99 
100 
101  }
102 //
103 
104 
105  #endif
106  ENDGLSL
107  }
108  }
109 
110 }