summaryrefslogtreecommitdiff
path: root/src/modules/evas/engines/gl_common/shader_3d/include.shd
blob: 706def92c4e16919c7054aef331fdd0dd2b40bf9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
`#ifdef GL_ES
precision mediump float;
precision mediump int;
precision lowp sampler2D;
#endif'

define(`FRAGMENT_SHADER_USE_TEX_COORD',`
#ifdef NEED_TEX_COORD
varying vec2   vTexCoord;
#endif //TEX_COORD')

define(`FRAGMENT_SHADER_USE_TEXTURE', `
#ifdef $1_TEXTURE
uniform sampler2D  uTexture$2`0';
uniform mat3 uTextureMatrixTransform$2`0';
vec3 Tex0Coord$2 =
   vec3(vTexCoord, 1.0) * uTextureMatrixTransform$2`0';
#endif //$1_TEXTURE
#ifdef $1_TEXTURE_BLEND
uniform sampler2D  uTexture$2`1';
uniform float      uTexture$2Weight;
uniform mat3 uTextureMatrixTransform$2`1';
vec3 Tex1Coord$2 =
   vec3(vTexCoord, 1.0) * uTextureMatrixTransform$2`1';
#endif //$1_TEXTURE_BLEND')

define(`FRAGMENT_SHADER_USE_FOG', `
#ifdef FOG_ENABLED
uniform float uFogFactor;
uniform vec4  uFogColor;
#endif //FOG_ENABLED')

define(`FRAGMENT_SHADER_USE_ALPHA_TEST_GLES', `
#ifdef GL_ES
uniform int   uAlphaTestComparison;
uniform float uAlphaTestRefValue;
#endif //GL_ES')

define(`FRAGMENT_SHADER_USE_SHADOWS', `
#ifdef  SHADOWED
varying vec4 vLightPosition;
uniform sampler2D uShadowMap;
float shadow;
float pcf(vec4 lpos, float size)
  {
`#ifndef GL_ES'
     vec3 smcoord = lpos.xyz / lpos.w * 0.5 + 0.5;
     float i, j, randx, randy, shadow;
     shadow = 0.0;
     for (i = -4.0; i < 4.0; i++)
       for (j = -4.0; j < 4.0; j++)
         shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy + vec2(i / 8.0, j / 8.0) * size).x);
     return shadow / 64.0;
`#else'
   /*TODO Add algorithm generate shadow*/
   return 1.0;
`#endif //GL_ES'
}
#endif //SHADOWED')

define(`FRAGMENT_SHADER_FOG_APPLY', `
#ifdef FOG_ENABLED
   float z = gl_FragCoord.z / gl_FragCoord.w;
   float fogFactor = exp2(-uFogFactor * uFogFactor * z * z * 1.44);
   fogFactor = clamp(fogFactor, 0.0, 1.0);
   gl_FragColor = mix(uFogColor, gl_FragColor, fogFactor);
#endif //FOG_ENABLED')

define(`FRAGMENT_SHADER_USE_LIGHT', `
#ifdef LIGHT_SPOT
uniform   vec3  uLightSpotDir;
uniform   float uLightSpotExp;
uniform   float uLightSpotCutoffCos;
#endif //LIGHT_SPOT
#ifdef LIGHT_ATTENUATION
varying   float    vLightDist;
#endif //LIGHT_ATTENUATION')

define(`FRAGMENT_SHADER_TEXTURE_BLEND', `
#ifdef  $1_TEXTURE_BLEND
   color = mix(texture2D(uTexture$2`1', vec2(Tex1Coord$2)),
               texture2D(uTexture$2`0', vec2(Tex0Coord$2)), uTexture$2Weight);
   color *= uMaterial$2;
#else
#ifdef  $1_TEXTURE
   color = texture2D(uTexture$2`0', vec2(Tex0Coord$2)) * uMaterial$2;
#else
   color = uMaterial$2;
#endif //$1_TEXTURE
#endif //$1_TEXTURE_BLEND')

define(`FRAGMENT_SHADER_USE_EMISSION_TERM',
`#ifdef EMISSION'
uniform vec4       uMaterialEmission;
FRAGMENT_SHADER_USE_TEXTURE(EMISSION, Emission)
`#endif //EMISSION')

define(`FRAGMENT_SHADER_USE_SPECULAR_TERM',
`#ifdef SPECULAR'
uniform   vec4     uLightSpecular;
uniform   float    uMaterialShininess;
uniform   vec4     uMaterialSpecular;
FRAGMENT_SHADER_USE_TEXTURE(SPECULAR, Specular)
`#endif //SPECULAR')

define(`FRAGMENT_SHADER_USE_AMBIENT_TERM',
`#ifdef AMBIENT'
uniform  vec4       uMaterialAmbient;
uniform  vec4       uLightAmbient;
FRAGMENT_SHADER_USE_TEXTURE(AMBIENT, Ambient)
`#endif //AMBIENT')

define(`FRAGMENT_SHADER_USE_DIFFUSE_TERM',
`#ifdef DIFFUSE'
uniform   vec4        uMaterialDiffuse;
uniform   vec4        uLightDiffuse;
FRAGMENT_SHADER_USE_TEXTURE(DIFFUSE, Diffuse)
`#endif //DIFFUSE')

define(`FRAGMENT_SHADER_ALPHA_TEST_GLES_APPLY',
`#ifdef GL_ES'
/*uAlphaTestComparison is value of the Evas_3D_Comparison type*/
   const float p = 1000000.0;
   float acolor = floor($1.a * p);
   float refvalue = floor(uAlphaTestRefValue * p);
   if (uAlphaTestComparison == 0) discard;
   else if (uAlphaTestComparison == 1)
     {
        if (acolor < refvalue) gl_FragColor = $1;
        else discard;
     }
   else if (uAlphaTestComparison == 2)
     {
        if (acolor == refvalue) gl_FragColor = $1;
        else discard;
     }
   else if (uAlphaTestComparison == 3)
     {
        if (acolor <= refvalue) gl_FragColor = $1;
        else discard;
     }
   else if (uAlphaTestComparison == 4)
     {
        if (acolor > refvalue) gl_FragColor = $1;
        else discard;
     }
   else if (uAlphaTestComparison == 5)
     {
        if (acolor != refvalue) gl_FragColor = $1;
        else discard;
     }
   else if (uAlphaTestComparison == 6)
     {
        if (acolor >= refvalue) gl_FragColor = $1;
        else discard;
     }
   else if (uAlphaTestComparison == 7) ;
`#else'
   gl_FragColor = $1;
`#endif //GL_ES')


define(`VERTEX_SHADER_NEED_TEX_COORD',
`#ifdef NEED_TEX_COORD'
varying vec2 vTexCoord;
`#endif //NEED_TEX_COORD')

define(`VERTEX_SHADER_USE_LIGHT_ATTENUATION',
`#ifdef LIGHT_ATTENUATION'
varying  float vLightDist;
`#endif //LIGHT_ATTENUATION')

define(`VERTEX_SHADER_USE_SHADOWS',
`#ifdef SHADOWED'
uniform mat4 uMatrixLight;
varying vec4 vLightPosition;
`#endif //SHADOWED')

define(`VERTEX_SHADER_USE_POSITION',
`#ifdef VERTEX_POSITION'
attribute   vec4  aPosition0;
`#endif //VERTEX_POSITION'

`#ifdef VERTEX_POSITION_BLEND'
attribute   vec4  aPosition1;
uniform     float uPositionWeight;
`#endif //VERTEX_POSITION_BLEND')

define(`VERTEX_SHADER_USE_NORMALS',
`#ifdef VERTEX_NORMAL'
attribute   vec4  aNormal0;
`#endif //VERTEX_NORMAL'

`#ifdef VERTEX_NORMAL_BLEND'
attribute   vec4  aNormal1;
uniform     float uNormalWeight;
`#endif //VERTEX_NORMAL_BLEND'
)

define(`VERTEX_SHADER_USE_TEXCOORD',
`#ifdef VERTEX_TEXCOORD'
attribute   vec4  aTexCoord0;
`#endif //VERTEX_TEXCOORD'

`#ifdef VERTEX_TEXCOORD_BLEND'
attribute   vec4  aTexCoord1;
uniform     float uTexCoordWeight;
`#endif //VERTEX_TEXCOORD_BLEND'
)

define(`VERTEX_SHADER_USE_COLOR',
`#ifdef VERTEX_COLOR'
attribute   vec4  aColor0;
`#endif //VERTEX_COLOR'

`#ifdef VERTEX_COLOR_BLEND'
attribute   vec4  aColor1;
uniform     float uColorWeight;
`#endif //VERTEX_COLOR_BLEND')

define(`VERTEX_SHADER_POSITION',
`#ifdef VERTEX_POSITION_BLEND'
   vec4 position = mix(aPosition1, aPosition0, uPositionWeight);
   position = vec4(position.xyz, 1.0);
`#else'

`#ifdef VERTEX_POSITION'
   vec4 position = vec4(aPosition0.xyz, 1.0);
`#endif // VERTEX_POSITION'

`#endif //VERTEX_POSITION_BLEND')

define(`VERTEX_SHADER_NORMAL',
`#ifdef VERTEX_NORMAL_BLEND'
   vec3 normal = mix(aNormal1.xyz, aNormal0.xyz, uNormalWeight);
`#else'

`#ifdef VERTEX_NORMAL'
   vec3 normal = aNormal0.xyz;
`#endif //VERTEX_NORMAL'
`#endif //VERTEX_NORMAL_BLEND')

define(`VERTEX_SHADER_TEXCOORD',
`#ifdef VERTEX_TEXCOORD_BLEND'
   vTexCoord = mix(aTexCoord1.st, aTexCoord0.st, uTexCoordWeight);
`#else'

`#ifdef VERTEX_TEXCOORD'
   vTexCoord = aTexCoord0.st;
`#endif //VERTEX_TEXCOORD'

`#endif //VERTEX_TEXCOORD_BLEND')

define(`VERTEX_SHADER_SHADOWED',
`#ifdef SHADOWED'
   vLightPosition = uMatrixLight * position;
`#endif //SHADOWED')