summaryrefslogtreecommitdiff
path: root/src/modules/evas/engines/gl_common/shader_3d/shadow_map_frag.shd
blob: bdb16e59bb5705013191b98937c27caa0522db42 (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
varying vec4 shadowmapposition;
#ifdef ALPHA_TEST_ENABLED
FRAGMENT_SHADER_USE_TEX_COORD
FRAGMENT_SHADER_USE_ALPHA_TEST_GLES

#ifdef DIFFUSE

#ifdef DIFFUSE_TEXTURE
uniform sampler2D  uTextureDiffuse0;
uniform mat3 uTextureMatrixTransformDiffuse0;
vec3 Tex0CoordDiffuse =
   vec3(vTexCoord, 1.0) * uTextureMatrixTransformDiffuse0;
#endif //DIFFUSE_TEXTURE

#ifdef DIFFUSE_TEXTURE_BLEND
uniform sampler2D  uTextureDiffuse1;
uniform float      uTextureDiffuseWeight;
uniform mat3 uTextureMatrixTransformDiffuse1;
vec3 Tex1CoordDiffuse =
   vec3(vTexCoord, 1.0) * uTextureMatrixTransformDiffuse1;
#endif //DIFFUSE_TEXTURE_BLEND

#endif //DIFFUSE

#endif //ALPHA_TEST_ENABLED

void main() {

   vec4 color;
#ifndef NEED_TEX_COORD
   gl_FragColor = vec4(1);
#endif

#ifdef ALPHA_TEST_ENABLED

#ifdef DIFFUSE_TEXTURE_BLEND
   color = (texture2D(uTextureDiffuse0, vec2(Tex0CoordDiffuse)) *
   uTextureDiffuseWeight + texture2D(uTextureDiffuse1, vec2(Tex1CoordDiffuse)) *
   (1.0 - uTextureDiffuseWeight));
#else

#ifdef DIFFUSE_TEXTURE
   color = texture2D(uTextureDiffuse0, vec2(Tex0CoordDiffuse));
#else
   color = vec4(1);
#endif //DIFFUSE_TEXTURE

#endif //DIFFUSE_TEXTURE_BLEND

   FRAGMENT_SHADER_ALPHA_TEST_GLES_APPLY(color)

#endif //ALPHA_TEST_ENABLED
#ifndef GL_ES
   gl_FragColor.r = gl_FragCoord.z;
#else
   const vec4 pack = vec4(256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0);
   const vec4 mask = vec4(0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);
   vec4 depthcolor;
   float normdist = shadowmapposition.z / shadowmapposition.w;
   normdist = ((normdist + 1.0) / 2.0);
   depthcolor = vec4(fract(pack * normdist));
   depthcolor -= depthcolor.xxyz * mask;
   gl_FragColor = depthcolor;
#endif
}