-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathMaterial.frag
32 lines (24 loc) · 901 Bytes
/
Material.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
31
32
#ifdef GL_ES
precision highp float;
#endif
//require the lambert diffuse formula from a module via glslify
#pragma glslify: lambert = require(glsl-diffuse-lambert)
//glsl-gamma module exports two functions that we can import separately
#pragma glslify: toLinear = require(glsl-gamma/in)
#pragma glslify: toGamma = require(glsl-gamma/out)
//vertex position, normal and light position in the eye/view space
varying vec3 ecPosition;
varying vec3 ecNormal;
varying vec3 ecLightPos;
float PI = 3.14159265;
void main() {
vec3 N = normalize(ecNormal);
vec3 L = normalize(ecLightPos - ecPosition);
//diffuse intensity
float Id = lambert(L, N);
//surface and light color, full white
vec4 baseColor = toLinear(vec4(1.0));
vec4 lightColor = toLinear(vec4(1.0));
vec4 finalColor = vec4(baseColor.rgb * lightColor.rgb * Id, 1.0);
gl_FragColor = toGamma(finalColor);
}