-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathshaders.coffee
138 lines (120 loc) · 2.85 KB
/
shaders.coffee
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
semantics =
VERTEXID : 0
POSITION : 0
NORMAL : 1
TEXCOORD : 2
shaders = source: {}
shaders.solidmesh =
keys: ["VS-Scene", "FS-Scene"]
attribs:
Position: semantics.POSITION
Normal: semantics.NORMAL
shaders.wireframe =
keys: ["VS-Wireframe", "FS-Wireframe"]
attribs:
Position: semantics.POSITION
shaders.vignette =
keys: ["VS-Vignette", "FS-Vignette"]
attribs:
VertexID: semantics.VERTEXID
shaders.source["VS-Scene"] =
"""
attribute vec4 Position;
attribute vec3 Normal;
uniform mat4 modelview;
uniform mat4 projection;
uniform mat3 normalmatrix;
uniform vec3 worldOffset;
varying vec3 vPosition;
varying vec3 vNormal;
void main(void)
{
vPosition = Position.xyz + worldOffset;
vNormal = normalmatrix * Normal;
vec4 p = vec4(vPosition, 1);
gl_Position = projection * modelview * p;
}
"""
shaders.source["VS-Wireframe"] =
"""
attribute vec4 Position;
uniform mat4 modelview;
uniform mat4 projection;
uniform float depthOffset;
uniform float scale;
uniform vec2 screenOffset;
uniform vec3 worldOffset;
void main(void)
{
vec4 p = Position;
p.xyz *= scale;
p.xyz += worldOffset;
gl_Position = projection * modelview * p;
gl_Position.z += depthOffset;
gl_Position.xy += screenOffset * 0.15;
}
"""
shaders.source["FS-Wireframe"] =
"""
precision highp float;
uniform vec4 color;
void main()
{
gl_FragColor = color;
}
"""
shaders.source["FS-Scene"] =
"""
precision highp float;
varying vec3 vNormal;
varying vec3 vPosition;
vec3 LightPosition = vec3(0.25, 0.5, 1.0);
vec3 AmbientMaterial = vec3(0.04, 0.04, 0.04);
vec3 SpecularMaterial = vec3(0.25, 0.25, 0.25);
vec3 FrontMaterial = vec3(0.25, 0.5, 0.75);
vec3 BackMaterial = vec3(0.75, 0.75, 0.7);
float Shininess = 50.0;
uniform vec4 color;
void main()
{
vec3 N = normalize(vNormal);
vec3 L = normalize(LightPosition);
vec3 Eye = vec3(0, 0, 1);
vec3 H = normalize(L + Eye);
float df = max(0.0, dot(N, L));
float sf = max(0.0, dot(N, H));
sf = pow(sf, Shininess);
vec3 P = vPosition;
vec3 I = normalize(P);
float cosTheta = abs(dot(I, N));
float fresnel = 1.0 - clamp(pow(1.0 - cosTheta, 0.125), 0.0, 1.0);
vec3 mat = !gl_FrontFacing ? FrontMaterial : BackMaterial;
mat *= color.rgb;
vec3 lighting = AmbientMaterial + df * mat;
if (gl_FrontFacing)
lighting += sf * SpecularMaterial;
lighting += fresnel;
gl_FragColor = vec4(lighting,1);
}
"""
shaders.source["VS-Vignette"] =
"""
attribute vec2 VertexID;
void main(void)
{
vec2 p = 3.0 - 4.0 * VertexID;
gl_Position = vec4(p, 0, 1);
}
"""
shaders.source["FS-Vignette"] =
"""
precision highp float;
uniform vec2 viewport;
void main()
{
vec2 c = gl_FragCoord.xy / viewport;
float f = 1.0 - 0.5 * pow(distance(c, vec2(0.5)), 1.5);
gl_FragColor = vec4(f, f, f, 1);
gl_FragColor.rgb *= vec3(0.867, 0.18, 0.447); // Hot Pink!
}
"""