-
Notifications
You must be signed in to change notification settings - Fork 0
/
shader.frag
30 lines (27 loc) · 903 Bytes
/
shader.frag
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
precision mediump float;
varying vec2 pos;
uniform sampler2D colorMap;
uniform sampler2D heightMap;
uniform float waterlvl;
uniform float width;
uniform vec3 lightDir;
void main() {
vec2 newPos = pos;
newPos.y = 1. - newPos.y;
vec4 col = texture2D(colorMap, newPos);
float d = 1./width;
vec2 posdx = newPos;
posdx.x = posdx.x+d;
vec2 posdy = newPos;
posdy.y = posdy.y+d;
float height = texture2D(heightMap, newPos).x*100.;
float heightdx = texture2D(heightMap, posdx).x*100.;
float heightdy = texture2D(heightMap, posdy).x*100.;
vec3 unnormal = vec3((heightdx-height),(heightdy-height),1);
vec3 normal = normalize(unnormal);
float brightness = dot(lightDir,normal);
brightness = clamp(brightness, 0.2, 1.);
col.rgb = col.rgb*brightness;
col = mix(col,vec4(0.,0.,1.,1.), clamp((waterlvl-height)/10.,0.,1.));
gl_FragColor = col;
}