ecere/gfx/drivers/OpenGL/Default Shader: Fixed mistakes in lights 3,4,7
[sdk] / ecere / src / gfx / drivers / gl3 / default.vert
1 attribute vec3 vertex;
2 uniform mat4 projection_matrix;
3
4 #if MODELVIEW
5    uniform mat4 modelview_matrix;
6 #endif
7
8 #if PER_VERTEX_COLOR
9    attribute vec4 color;
10 #endif
11
12 #if ENVIRONMENT_MAPPING || LIGHTING_ON
13    varying vec3 nnEyeToSurface;
14 #endif
15
16 #if LIGHTING_ON
17    attribute vec3 normal;
18    attribute vec3 tangent1;
19    attribute vec3 tangent2;
20
21    uniform float nearPlane;
22    uniform mat3 normals_matrix;
23
24    #if PER_VERTEX_COLOR
25       varying vec4 diffuseColor; // w: opacity
26       varying vec3 ambientColor;
27    #endif
28
29    varying vec3 tNormal;
30    #if NORMALS_MAPPING
31       varying vec3 tTangent1;
32       varying vec3 tTangent2;
33    #endif
34
35 #elif PER_VERTEX_COLOR
36    uniform vec4 matDiffuse;
37    varying vec4 fColor;
38 #endif
39
40 #if FOG_ON
41    uniform float fogDensity;
42    varying float fogZ;
43 #endif
44
45 #if CUBEMAP_ON
46    varying vec3 fTexCoord;
47 #endif
48
49 #if TEXTURE_ON || NORMALS_MAPPING || SPECULAR_MAPPING || REFLECTION_MAP
50    attribute vec2 texCoord;
51    varying vec2 fTexCoord;
52 #endif
53
54 void main(void)
55 {
56 #if MODELVIEW
57    vec4 pos = modelview_matrix * vec4(vertex, 1.0);
58 #else
59    vec4 pos = vec4(vertex, 1.0);
60 #endif
61
62 #if ENVIRONMENT_MAPPING || LIGHTING_ON
63    nnEyeToSurface = vec3(pos.x, -pos.y, pos.z) * nearPlane;
64 #endif
65
66 #if LIGHTING_ON
67    #if PER_VERTEX_COLOR
68       diffuseColor = color;
69       ambientColor = color.xyz;
70    #endif
71
72    tNormal = normals_matrix * normal;
73 #if NORMALS_MAPPING
74    tTangent1 = normals_matrix * tangent1;
75    tTangent2 = normals_matrix * tangent2;
76 #endif
77 #elif PER_VERTEX_COLOR
78    fColor = matDiffuse * color;
79 #endif
80
81    gl_Position = projection_matrix * pos;
82
83 #if TEXTURE_ON || NORMALS_MAPPING || SPECULAR_MAPPING || REFLECTION_MAP
84    fTexCoord = texCoord;
85 #endif
86
87 #if CUBEMAP_ON
88    fTexCoord = vec3(vertex.x, -vertex.y, -vertex.z);
89 #endif
90
91 #if FOG_ON
92    fogZ = pos.z * fogDensity;
93 #endif
94 }