/
sc_waves.fsh
37 lines (33 loc) · 958 Bytes
/
sc_waves.fsh
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
31
32
33
34
35
36
37
#version 150
///
// Geometry wave fragment shader.
///
// u,v texture coordinates in bump map
in vec2 v_tex_coord;
// Color mod of reflected env map
in vec4 v_mod_color;
// Base color (tint)
in vec4 v_add_color;
// binormal, tangent, normal matrix
in mat3 v_btn;
// eye-to-vertex in world space
in vec3 v_eye_ray;
// Environment map
uniform samplerCube u_tex0;
// Elevation sampler
uniform sampler2D u_tex1;
// Bump map
uniform sampler2D u_tex2;
out vec4 o_color;
void main()
{
// Texture coordinates are used to sample bump map
vec3 bump_sample = normalize(2.0 * texture(u_tex2, v_tex_coord).xyz - 1.0);
// Convert normal from tangent to world space
vec3 normal = normalize(v_btn * bump_sample);
// Compute reflection and sample environment map
vec3 refl = reflect(v_eye_ray, normal);
vec4 env_sample = texture(u_tex0, refl);
// tint + environment * mod_color
o_color = vec4(env_sample.rgb * v_mod_color.rgb + v_add_color.rgb, v_mod_color.a);
}