forked from cobbpg/webstunts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstunts.frag
More file actions
70 lines (58 loc) · 2.03 KB
/
stunts.frag
File metadata and controls
70 lines (58 loc) · 2.03 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// -*- c -*-
#ifdef GL_ES
precision highp float;
#ifdef ANTI_MOIRE_ENABLED
#extension GL_OES_standard_derivatives : enable
#endif
#endif
uniform vec3 lightPosition;
varying vec3 fragmentPosition;
varying vec3 fragmentNormal;
varying vec3 fragmentColour;
varying vec3 fragmentMaterialInfo;
varying vec3 eyePosition;
#ifdef ANTI_MOIRE_ENABLED
float perturb(float x, float r) {
float w = fwidth(x);
return x + r * w * w * 2.0;
}
#endif
bool is_solid() {
#ifdef ANTI_MOIRE_ENABLED
//float rand = texture2D(noiseSampler, gl_FragCoord.xy);
float rand1 = fract(sin(dot(gl_FragCoord.xy, vec2(12.9898, 78.233))) * 43758.5453) - 0.5;
float rand2 = fract(sin(dot(gl_FragCoord.zx, vec2(15.9898, 74.233))) * 53758.5453) - 0.5;
float rand3 = fract(sin(dot(gl_FragCoord.yz, vec2(18.9898, 71.233))) * 73758.5453) - 0.5;
float prod1 = dot(fragmentPosition, vec3(2.0, 2.0, -2.0));
float prod2 = dot(fragmentPosition, vec3(2.0, -2.0, 2.0));
float prod3 = dot(fragmentPosition, vec3(-2.0, 2.0, 2.0));
return
fract(perturb(prod1, rand1)) < 0.2 ||
fract(perturb(prod2, rand2)) < 0.2 ||
fract(perturb(prod3, rand3)) < 0.2;
#else
return
fract(dot(fragmentPosition, vec3(2.0, 2.0, -2.0))) < 0.2 ||
fract(dot(fragmentPosition, vec3(2.0, -2.0, 2.0))) < 0.2 ||
fract(dot(fragmentPosition, vec3(-2.0, 2.0, 2.0))) < 0.2;
#endif
}
void main(void) {
float surf = fragmentMaterialInfo.b;
if (surf > 0.25 && (surf > 0.75 || is_solid())) {
vec3 l = normalize(lightPosition - eyePosition);
vec3 e = normalize(-eyePosition);
vec3 n = fragmentNormal;
vec3 r = normalize(reflect(-l, n));
float lambert = max(dot(l, n), 0.0);
float phong = max(dot(r, e), 0.0);
float shininess = fragmentMaterialInfo.g;
float intensity = 0.2 + lambert * 0.5 + pow(phong, shininess) * 0.3;
float highlight = pow(phong, shininess) * min(1.0, shininess * 0.04);
vec3 rgb = intensity * fragmentColour + highlight * vec3(1.0, 1.0, 1.0);
//rgb = vec3(gl_FragCoord.z * 50.0);
gl_FragColor = vec4(rgb, 1.0);
} else {
discard;
}
}