summaryrefslogtreecommitdiff
path: root/src/modules/evas/engines/gl_common/shader_3d/parallax_occlusion_vert.shd
blob: dff4ff75d46022cbff02785ed3e8dcf3a4c9c5d4 (plain)
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
uniform  mat4  uMatrixMvp;
uniform  mat3  uMatrixNormal;
uniform  mat4  uMatrixModelview;
uniform  vec4  uLightPosition;
varying  vec3  vLightVector;
varying  vec3  vLightHalfVector;
varying  vec3  vEyeVector;

VERTEX_SHADER_USE_SHADOWS
VERTEX_SHADER_USE_POSITION
VERTEX_SHADER_USE_NORMALS

#ifdef VERTEX_TANGENT
attribute   vec4  aTangent0;
#endif //VERTEX_TANGENT

#ifdef VERTEX_TANGENT_BLEND
attribute   vec4  aTangent1;
uniform     float uTangentWeight;
#endif //VERTEX_TANGENT_BLEND

VERTEX_SHADER_USE_TEXCOORD
VERTEX_SHADER_NEED_TEX_COORD
VERTEX_SHADER_USE_LIGHT_ATTENUATION

void vertexParallaxOcclusion(vec4 position, vec3 normal, vec3 tangent)
{
   vec3 n = normalize(uMatrixNormal * normal);
   vec3 t = normalize(uMatrixNormal * tangent);
   vec3 b = cross(n, t);
   vec3 tmp;

   position = uMatrixModelview * position;

#ifdef LIGHT_DIRECTIONAL
   vec3 lightDir = uLightPosition.xyz;
#else
   vec3 lightDir = uLightPosition.xyz - position.xyz;

#ifdef LIGHT_ATTENUATION
   vLightDist = length(lightDir);
#endif //LIGHT_ATTENUATION

   lightDir = normalize(lightDir);
#endif //LIGHT_DIRECTIONAL

   tmp.x = dot(lightDir, t);
   tmp.y = dot(lightDir, b);
   tmp.z = dot(lightDir, n);
   vLightVector = tmp;

   tmp.x = dot(position.xyz, t);
   tmp.y = dot(position.xyz, b);
   tmp.z = dot(position.xyz, n);
   vEyeVector = normalize(tmp);

   vec3 hv = normalize(normalize(-position.xyz) + lightDir);
   tmp.x = dot(hv, t);
   tmp.y = dot(hv, b);
   tmp.z = dot(hv, n);
   vLightHalfVector = tmp;
}

void main()
{

   VERTEX_SHADER_POSITION
   VERTEX_SHADER_NORMAL

#ifdef VERTEX_TANGENT_BLEND
   vec3 tangent = aTangent0.xyz * uTangentWeight +
   aTangent1.xyz * (1.0 - uTangentWeight);
#else

#ifdef VERTEX_TANGENT
   vec3 tangent = aTangent0.xyz;
#endif //VERTEX_TANGENT

#endif //VERTEX_TANGENT_BLEND

   VERTEX_SHADER_TEXCOORD

   gl_Position = uMatrixMvp * position;

   vertexParallaxOcclusion(position, normal, tangent);

   VERTEX_SHADER_SHADOWED
}