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