UNPKG

1.3 kBPlain TextView Raw
1#extension GL_OES_standard_derivatives : enable
2
3precision mediump float;
4
5#pragma glslify: cookTorrance = require(glsl-specular-cook-torrance)
6//#pragma glslify: beckmann = require(glsl-specular-beckmann) // used in gl-surface3d
7
8#pragma glslify: outOfRange = require(glsl-out-of-range)
9
10uniform vec3 clipBounds[2];
11uniform float roughness
12 , fresnel
13 , kambient
14 , kdiffuse
15 , kspecular
16 , opacity;
17uniform sampler2D texture;
18
19varying vec3 f_normal
20 , f_lightDirection
21 , f_eyeDirection
22 , f_data;
23varying vec4 f_color;
24varying vec2 f_uv;
25
26void 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 //float specular = max(beckmann(L, V, N, roughness), 0.); // used in gl-surface3d
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}