3DSelfie  Hansjoerg Hofer (1026632), Sebastian Metzler (0927550)
FaceTexture.shader
Go to the documentation of this file.
1 Shader "Custom/FaceTexture" {
2  Properties
3  {
4  _MainTex ("Front", 2D) = "white" {}
5  _Side ("Side", 2D) = "white" {}
6  }
7  SubShader
8  {
9  Pass
10  {
11  GLSLPROGRAM
12 
13  uniform sampler2D _MainTex;
14  uniform sampler2D _Side;
15  varying vec4 textureCoordinates;
16 
17  varying vec3 n;
18 
19  #ifdef VERTEX
20 
21  void main()
22  {
23  textureCoordinates = gl_MultiTexCoord0;
24  n = gl_Normal;
25 
26  gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
27  }
28  #endif
29 
30  #ifdef FRAGMENT
31 
32  void main()
33  {
34 
35  float yOffset = 0.03f;
36 
37  float frontX = textureCoordinates.x;
38 // float frontY = textureCoordinates.y - 0.06f;
39  float frontY = textureCoordinates.y;
40 
41  float siderX = textureCoordinates.x - 0.3f - 0.25f * textureCoordinates.y;
42  float sidelX = 1.0f - textureCoordinates.x - 0.3f - 0.25f * textureCoordinates.y;
43 // float siderX = textureCoordinates.x - 0.6f * textureCoordinates.y + 0.1f;
44 
45 
46 // float sidelX = 0.8f - textureCoordinates.x - 0.3 * textureCoordinates.y ;// + 0.39f * -textureCoordinates.y - 0.04f;
47 // float siderX = 0.65f + textureCoordinates.x;// - 0.6f * textureCoordinates.y + 0.1f;
48 
49 // float sideY = textureCoordinates.y - 0.062f;
50  float sideY = textureCoordinates.y - yOffset;
51 
52 
53  vec4 f = texture2D(_MainTex, vec2(frontX, frontY));
54 
55  vec4 sl = texture2D(_Side, vec2(sidelX, sideY));
56  vec4 sr = texture2D(_Side, vec2(siderX, sideY));
57 
58  float mixl, mixr, mixf;
59 
60  float gf = (f.r + f.g + f.b) / 3.0f;
61 
62  float Pi = 3.1415926535897932384626433832795f;
63  float sigma = 0.1f;
64  float m = 0.5f;
65  float x = textureCoordinates.x;
66  float prob = 1.0f / sqrt( 2.0f*Pi*pow(sigma,2.0f) ) * exp( -(pow(x-m,2.0f)/(2.0f*pow(sigma,2.0f) )));
67 
68  float p = 1.0f - prob * 0.2f;
69 
70  if(n.x < 0.0f) {
71  mixl = 0.0f;
72  mixr = abs(n.x) * p;
73 
74  mixf = 1.0f - mixr;
75  }
76  else {
77  mixl = abs(n.x) * p;
78  mixr = 0.0f;
79 
80  mixf = 1.0f - mixl;
81  }
82 
83  vec4 c = sl * mixl + sr * mixr + f * mixf;
84 
85  if(n.z < 0.0f)
86  gl_FragColor = vec4(0.0f,0.0f,0.0f,1.0f);
87  else
88  gl_FragColor = c;
89  }
90  #endif
91  ENDGLSL
92  }
93  }
94 }