1// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Adapted from the javascript implementation upon WebGL by kwaters@.
6
7#ifndef SHADERSRC_H_INCLUDED
8#define SHADERSRC_H_INCLUDED
9
10static const char *sFlatVertexSource =
11    "attribute highp vec3 pos;\n"
12    "attribute lowp vec4 colorIn;\n"
13    "uniform highp mat4 mvp;\n"
14    "varying lowp vec4 color;\n"
15    "void main() {\n"
16    "  color = colorIn;\n"
17    "  gl_Position = mvp * vec4(pos.xyz, 1.);\n"
18    "}\n";
19
20static const char *sFlatFragmentSource =
21    "varying lowp vec4 color;\n"
22    "void main() {\n"
23    "  gl_FragColor = vec4(color.rgb, 1.0);\n"
24    "}\n";
25
26static const char *sLitVertexSource =
27    "attribute highp vec3 pos;\n"
28    "attribute highp vec3 normal;\n"
29    "attribute lowp vec4 colorIn;\n"
30    "\n"
31    "varying lowp vec4 color;\n"
32    "\n"
33    "uniform highp mat4 mvp;\n"
34    "uniform highp mat3 normalMatrix;\n"
35    "uniform lowp vec4 ambient;\n"
36    "uniform lowp float shininess;\n"
37    "uniform lowp vec3 light_0_direction;\n"
38    "uniform lowp vec4 light_0_diffuse;\n"
39    "uniform lowp vec4 light_0_specular;\n"
40    "uniform lowp vec3 light_1_direction;\n"
41    "uniform lowp vec4 light_1_diffuse;\n"
42    "uniform lowp vec3 light_2_direction;\n"
43    "uniform lowp vec4 light_2_diffuse;\n"
44    "\n"
45    "highp vec3 worldNormal;\n"
46    "\n"
47    "lowp vec4 SpecularLight(highp vec3 direction,\n"
48    "                        lowp vec4 diffuseColor,\n"
49    "                        lowp vec4 specularColor) {\n"
50    "  lowp vec3 lightDir = normalize(direction);\n"
51    "  lowp float diffuse = max(0., dot(worldNormal, lightDir));\n"
52    "  lowp float specular = 0.;\n"
53    "  if (diffuse > 0.) {\n"
54    "    highp vec3 halfv = normalize(lightDir + vec3(0., 0., 1.));\n"
55    "    specular = pow(max(0., dot(halfv, worldNormal)), shininess);\n"
56    "  }\n"
57    "  return diffuse * diffuseColor * colorIn + specular * specularColor;\n"
58    "}\n"
59    "\n"
60    "lowp vec4 DiffuseLight(highp vec3 direction, lowp vec4 diffuseColor) {\n"
61    "  highp vec3 lightDir = normalize(direction);\n"
62    "  lowp float diffuse = max(0., dot(worldNormal, lightDir));\n"
63    "  return diffuse * diffuseColor * colorIn;\n"
64    "}\n"
65    "\n"
66    "void main() {\n"
67    "  worldNormal = normalize(normalMatrix * normal);\n"
68    "\n"
69    "  gl_Position = mvp * vec4(pos, 1.);\n"
70    "\n"
71    "  color = ambient * colorIn;\n"
72    "  color += SpecularLight(light_0_direction, light_0_diffuse,\n"
73    "                         light_0_specular);\n"
74    "  color += DiffuseLight(light_1_direction, light_1_diffuse);\n"
75    "  color += DiffuseLight(light_2_direction, light_2_diffuse);\n"
76    "}\n";
77
78static const char *sFadeVertexSource =
79    "attribute highp vec2 pos;\n"
80    "\n"
81    "varying lowp vec4 color;\n"
82    "\n"
83    "uniform lowp float minFade;\n"
84    "\n"
85    "void main() {\n"
86    "  color = vec4(minFade, minFade, minFade, 1.);\n"
87    "  gl_Position = vec4(pos, 0., 1.);\n"
88    "}\n";
89
90#endif  // SHADERSRC_H_INCLUDED
91
92