1 | #extension GL_OES_standard_derivatives : enable
|
2 |
|
3 | precision mediump float;
|
4 |
|
5 | #pragma glslify: cookTorrance = require(glsl-specular-cook-torrance)
|
6 |
|
7 |
|
8 | #pragma glslify: outOfRange = require(glsl-out-of-range)
|
9 |
|
10 | uniform vec3 clipBounds[2];
|
11 | uniform float roughness
|
12 | , fresnel
|
13 | , kambient
|
14 | , kdiffuse
|
15 | , kspecular
|
16 | , opacity;
|
17 | uniform sampler2D texture;
|
18 |
|
19 | varying vec3 f_normal
|
20 | , f_lightDirection
|
21 | , f_eyeDirection
|
22 | , f_data;
|
23 | varying vec4 f_color;
|
24 | varying vec2 f_uv;
|
25 |
|
26 | void main() {
|
27 | if (outOfRange(clipBounds[0], clipBounds[1], f_data)) discard;
|
28 |
|
29 | vec3 N = normalize(f_normal);
|
30 | vec3 L = normalize(f_lightDirection);
|
31 | vec3 V = normalize(f_eyeDirection);
|
32 |
|
33 | if(gl_FrontFacing) {
|
34 | N = -N;
|
35 | }
|
36 |
|
37 | float specular = max(cookTorrance(L, V, N, roughness, fresnel), 0.);
|
38 |
|
39 |
|
40 | float diffuse = min(kambient + kdiffuse * max(dot(N, L), 0.0), 1.0);
|
41 |
|
42 | vec4 surfaceColor = f_color * texture2D(texture, f_uv);
|
43 | vec4 litColor = surfaceColor.a * vec4(diffuse * surfaceColor.rgb + kspecular * vec3(1,1,1) * specular, 1.0);
|
44 |
|
45 | gl_FragColor = litColor * opacity;
|
46 | }
|