35 lines
787 B
GLSL
35 lines
787 B
GLSL
precision highp float;
|
|
|
|
varying highp vec2 vTextureCoord;
|
|
varying highp vec4 vNormal;
|
|
varying highp vec3 vPosition;
|
|
|
|
uniform sampler2D uSampler;
|
|
|
|
vec3 extremize(vec3 v, float n) {
|
|
if (v.x > n / 2.)
|
|
v.x = n;
|
|
else
|
|
v.x = 0.;
|
|
if (v.y > n / 2.)
|
|
v.y = n;
|
|
else
|
|
v.y = 0.;
|
|
if (v.z > n / 2.)
|
|
v.z = n;
|
|
else
|
|
v.z = 0.;
|
|
return v;
|
|
}
|
|
|
|
void main() {
|
|
vec3 n = normalize(vec3(-50., 100., 50.) - vPosition);
|
|
float diffuse = max(dot(normalize(vNormal.xyz), n), 0.);
|
|
float specular = pow(
|
|
max(dot(
|
|
reflect(n, normalize(vNormal.xyz)),
|
|
normalize(vec3(0., 0., -50.) - vPosition)),
|
|
0.), 10.);
|
|
vec3 texture = extremize(mod(vPosition.xyz + vec3(1000.), vec3(2.)), 2.) / vec3(2);
|
|
gl_FragColor = vec4((texture * diffuse * 0.8) + (texture * vec3(0.2)) + (specular * vec3(1.)), 1.0);
|
|
} |