1[shaders]
2vertex =
3    uniform highp mat4 u_modelMatrix;
4    uniform highp mat4 u_viewMatrix;
5    uniform highp mat4 u_projectionMatrix;
6
7    uniform highp mat4 u_normalMatrix;
8
9    attribute highp vec4 a_vertex;
10    attribute highp vec4 a_normal;
11    attribute highp vec2 a_uvs;
12
13    varying highp vec3 v_vertex;
14    varying highp vec3 v_normal;
15
16    void main()
17    {
18        vec4 world_space_vert = u_modelMatrix * a_vertex;
19        gl_Position = u_projectionMatrix * u_viewMatrix * world_space_vert;
20
21        v_vertex = world_space_vert.xyz;
22        v_normal = (u_normalMatrix * normalize(a_normal)).xyz;
23    }
24
25fragment =
26    uniform mediump vec4 u_ambientColor;
27    uniform mediump vec4 u_diffuseColor;
28    uniform mediump vec4 u_specularColor;
29    uniform highp vec3 u_lightPosition;
30    uniform mediump float u_shininess;
31    uniform highp vec3 u_viewPosition;
32
33    varying highp vec3 v_vertex;
34    varying highp vec3 v_normal;
35
36    void main()
37    {
38        mediump vec4 finalColor = vec4(0.0);
39
40        /* Ambient Component */
41        finalColor += u_ambientColor;
42
43        highp vec3 normal = normalize(v_normal);
44        highp vec3 lightDir = normalize(u_lightPosition - v_vertex);
45
46        /* Diffuse Component */
47        highp float NdotL = clamp(abs(dot(normal, lightDir)), 0.0, 1.0);
48        finalColor += (NdotL * u_diffuseColor);
49
50        /* Specular Component */
51        /* TODO: We should not do specularity for fragments facing away from the light.*/
52        highp vec3 reflectedLight = reflect(-lightDir, normal);
53        highp vec3 viewVector = normalize(u_viewPosition - v_vertex);
54        highp float NdotR = clamp(dot(viewVector, reflectedLight), 0.0, 1.0);
55        finalColor += pow(NdotR, u_shininess) * u_specularColor;
56
57        gl_FragColor = finalColor;
58        gl_FragColor.a = 1.0;
59    }
60
61vertex41core =
62    #version 410
63    uniform highp mat4 u_modelMatrix;
64    uniform highp mat4 u_viewMatrix;
65    uniform highp mat4 u_projectionMatrix;
66
67    uniform highp mat4 u_normalMatrix;
68
69    attribute highp vec4 a_vertex;
70    attribute highp vec4 a_normal;
71    attribute highp vec2 a_uvs;
72
73    varying highp vec3 v_vertex;
74    varying highp vec3 v_normal;
75
76    void main()
77    {
78        vec4 world_space_vert = u_modelMatrix * a_vertex;
79        gl_Position = u_projectionMatrix * u_viewMatrix * world_space_vert;
80
81        v_vertex = world_space_vert.xyz;
82        v_normal = (u_normalMatrix * normalize(a_normal)).xyz;
83    }
84
85fragment41core =
86    #version 410
87    uniform mediump vec4 u_ambientColor;
88    uniform mediump vec4 u_diffuseColor;
89    uniform mediump vec4 u_specularColor;
90    uniform highp vec3 u_lightPosition;
91    uniform mediump float u_shininess;
92    uniform highp vec3 u_viewPosition;
93
94    varying highp vec3 v_vertex;
95    varying highp vec3 v_normal;
96
97    void main()
98    {
99        mediump vec4 finalColor = vec4(0.0);
100
101        /* Ambient Component */
102        finalColor += u_ambientColor;
103
104        highp vec3 normal = normalize(v_normal);
105        highp vec3 lightDir = normalize(u_lightPosition - v_vertex);
106
107        /* Diffuse Component */
108        highp float NdotL = clamp(abs(dot(normal, lightDir)), 0.0, 1.0);
109        finalColor += (NdotL * u_diffuseColor);
110
111        /* Specular Component */
112        /* TODO: We should not do specularity for fragments facing away from the light.*/
113        highp vec3 reflectedLight = reflect(-lightDir, normal);
114        highp vec3 viewVector = normalize(u_viewPosition - v_vertex);
115        highp float NdotR = clamp(dot(viewVector, reflectedLight), 0.0, 1.0);
116        finalColor += pow(NdotR, u_shininess) * u_specularColor;
117
118        gl_FragColor = finalColor;
119        gl_FragColor.a = 1.0;
120    }
121
122[defaults]
123u_ambientColor = [0.3, 0.3, 0.3, 1.0]
124u_diffuseColor = [0.5, 0.5, 0.5, 1.0]
125u_specularColor = [0.7, 0.7, 0.7, 1.0]
126u_shininess = 20.0
127
128[bindings]
129u_modelMatrix = model_matrix
130u_viewMatrix = view_matrix
131u_projectionMatrix = projection_matrix
132u_normalMatrix = normal_matrix
133u_viewPosition = view_position
134u_lightPosition = light_0_position
135
136[attributes]
137a_vertex = vertex
138a_normal = normal
139