3 uniform vec4 uColor; // DALi
4 uniform sampler2D uNormalMap; // DALi
6 uniform vec3 uInvLightDir;
7 uniform vec3 uLightColorSqr;
8 uniform vec3 uAmbientColor;
10 uniform float uNormalMapWeight;
11 uniform float uSpecularity;
15 varying vec3 vViewPos;
16 varying float vHeight;
20 return fract(sin(dot(co.xy, vec2(12.98981, 78.2331))) * 43758.5453);
25 return v.x + v.y + v.z;
30 vec3 viewPos = normalize(vViewPos);
31 vec2 uv2 = vUv + vViewPos.xy / vViewPos.z * vHeight + vec2(.5, 0.);
33 vec3 perturbNormal = texture2D(uNormalMap, vUv).rgb * 2. - 1.;
34 vec3 perturbNormal2 = texture2D(uNormalMap, uv2).rgb * 2. - 1.;
35 vec3 normal = normalize(vNormal + perturbNormal * uNormalMapWeight);
36 vec3 normal2 = normalize(vNormal + perturbNormal2 * uNormalMapWeight);
38 vec3 color = uAmbientColor;
39 float d = max(0., dot(normal, -uInvLightDir));
40 color += uColor.rgb * d;
42 vec3 reflected = reflect(uInvLightDir, normal);
43 d = max(0., dot(reflected, viewPos));
44 color += pow(d, uSpecularity) * uLightColorSqr;
46 reflected = reflect(uInvLightDir, normal2);
47 d = max(0., dot(reflected, viewPos));
48 color += pow(d, uSpecularity) * uLightColorSqr;
50 gl_FragColor = vec4(color, 1.);