1/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 * or implied. See the License for the specific language governing permissions and limitations under
12 * the License.
13 */
14precision mediump float;
15uniform vec3 u_LightPos;
16uniform sampler2D u_Texture1;
17uniform sampler2D u_Texture2;
18uniform int u_Time;
19varying vec3 v_Position;
20varying vec2 v_TexCoordinate;
21void main() {
22  float weight = abs(mod(float(u_Time), 101.0) - 50.0) / 50.0;// loop between 0.0 and 1.0
23  float offset = abs(float(u_Time) / 1000.0);
24  // Get normal from bump map.
25  vec3 map1 = texture2D(u_Texture1, v_TexCoordinate + offset).xyz * 2.0 - 1.0;
26  vec3 map2 = texture2D(u_Texture2, v_TexCoordinate + offset).xyz * 2.0 - 1.0;
27  vec3 normal = normalize((map1 * weight) + (map2 * (1.0 - weight)));
28  // Get a lighting direction vector from the light to the vertex.
29  vec3 lightVector = normalize(u_LightPos - v_Position);
30  // Calculate the dot product of the light vector and vertex normal.
31  float diffuse = max(dot(lightVector, normal), 0.0);
32  // Add ambient lighting
33  diffuse = diffuse + 0.025;
34  // Use the diffuse illumination to get final output color.
35  gl_FragColor = vec4(1.0 - diffuse, 1.0 - diffuse, 1.0, 1.0 - (diffuse * 0.9));// Semi transparent blue.
36}