3DSelfie  Hansjoerg Hofer (1026632), Sebastian Metzler (0927550)
cornerCustom.shader
Go to the documentation of this file.
1 Shader "Custom/cornerCustom" {
2  Properties
3  {
4  _MainTex ("Texture Image", 2D) = "white" {}
5  _TexSizeX ("Texture Width", Float) = 0.0
6  _TexSizeY ("Texture Height", Float) = 0.0
7  }
8  SubShader
9  {
10  Pass
11  {
12  GLSLPROGRAM
13 
14  uniform sampler2D _MainTex;
15  varying vec4 textureCoordinates;
16  uniform float _TexSizeX;
17  uniform float _TexSizeY;
18 
19  #ifdef VERTEX
20 
21  void main()
22  {
23  textureCoordinates = gl_MultiTexCoord0;
24  gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
25  }
26  #endif
27 
28  #ifdef FRAGMENT
29 
30  void main()
31  {
32  vec4 x0 = texture2D(_MainTex, vec2(textureCoordinates) + vec2(-1.0/_TexSizeX, 0.0));
33  vec4 x1 = texture2D(_MainTex, vec2(textureCoordinates) + vec2( 1.0/_TexSizeX, 0.0));
34 
35  vec4 gx = (x1 - x0) / 2.0;
36  float gradX = (gx.r + gx.g + gx.b) / 3.0;
37 
38  vec4 y0 = texture2D(_MainTex, vec2(textureCoordinates) + vec2(0.0, -1.0/_TexSizeY));
39  vec4 y1 = texture2D(_MainTex, vec2(textureCoordinates) + vec2(0.0, 1.0/_TexSizeY));
40 
41  vec4 gy = (y1 - y0) / 2.0;
42  float gradY = (gy.r + gy.g + gy.b) / 3.0;
43 
44  float magnitude = (length(vec2(gradX,gradY)) / sqrt(2.0));
45 
46  gl_FragColor = vec4(magnitude,magnitude,magnitude, 1.0);
47  }
48  #endif
49  ENDGLSL
50  }
51  }
52 }