-
Notifications
You must be signed in to change notification settings - Fork 4
/
shaders.html
214 lines (165 loc) · 5.76 KB
/
shaders.html
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<!doctype html>
<html><head>
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-Equiv="Pragma" Content="no-cache">
<meta http-Equiv="Expires" Content="0">
</head>
<script id="phongVs" type="x-shader/x-vertex">
precision highp float;
attribute vec3 aVertexPosition;
attribute vec3 aVertexNormal;
// attribute vec2 aTextureCoord;
uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
//uniform mat4 uNMatrix;
// varying vec2 vTextureCoord;
varying vec3 vTransformedNormal;
varying vec3 vPosition;
void main(void) {
vec4 tpos = uMVMatrix * vec4(aVertexPosition, 1.0);
vPosition = tpos.xyz;
gl_Position = uPMatrix * tpos;
// vTextureCoord = aTextureCoord;
tpos = uMVMatrix * vec4(aVertexNormal, 0.0);
vTransformedNormal = tpos.xyz;
}
</script>
<script id="phongFs" type="x-shader/x-fragment">
precision highp float;
// varying vec2 vTextureCoord;
varying vec3 vTransformedNormal;
varying vec3 vPosition;
uniform bool uUseLighting;
uniform bool uTwoSided;
uniform vec3 uAmbientColor;
uniform vec3 uPointLightingLocation;
uniform vec3 uPointLightingDiffuseColor;
// uniform sampler2D uSampler;
uniform vec4 uGlobColor;
void main(void) {
vec3 lightWeighting;
if (!uUseLighting) {
lightWeighting = vec3(1.0, 1.0, 1.0);
}
else {
vec3 lightDirection = normalize(uPointLightingLocation - vPosition);
vec3 normal = normalize(vTransformedNormal);
float specularLightWeighting = 0.0;
float diffuseLightWeighting = dot(normal, lightDirection);
if (uTwoSided)
diffuseLightWeighting = abs(diffuseLightWeighting);
diffuseLightWeighting = max(diffuseLightWeighting, 0.0);
lightWeighting = uAmbientColor + uPointLightingDiffuseColor * diffuseLightWeighting;
}
gl_FragColor = vec4(uGlobColor.rgb * lightWeighting, uGlobColor.a);
}
</script>
<script id="bkgVs" type="x-shader/x-vertex">
precision highp float;
attribute vec3 aVertexPosition;
uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
varying vec3 pos;
void main(void) {
pos = aVertexPosition;
gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
}
</script>
<script id="bkgTDtexFs" type="x-shader/x-fragment">
precision highp float;
varying vec3 pos;
uniform float time;
uniform sampler2D noisef;
const vec3 colorA = vec3(0.00, 0.23, 0.32); //(0.10, 0.00, 0.40);
const vec3 colorB = vec3(0.00, 0.00, 0.10); //(0.49, 0.00, 0.43);
float mod(int x, float y){
return float(x) - y * floor(float(x) / y);
}
float fmod(float x, float y){
return x - y * floor(float(x) / y);
}
// 128x128 tiles are 8x16
// tiles are taken bottom to top
vec4 flat_texture3D(vec3 p)
{
vec2 inimg = p.xy;
inimg.x = fmod(inimg.x, 1.0);
inimg.y = fmod(inimg.y, 1.0);
inimg.y = max(inimg.y, 0.00390625);
inimg.y = min(inimg.y, 0.99609375);
inimg.x = max(inimg.x, 0.00390625);
inimg.x = min(inimg.x, 0.99609375);
float fpz = p.z*128.0;
fpz = min(fpz, 127.0);
int d1 = int(fpz);
float ix1 = mod(d1, 8.0);
float iy1 = float(d1 / 8);
vec2 oc1 = inimg + vec2(ix1, iy1);
oc1 *= vec2(0.125, 0.0625); // 1/8,1/16
int d2 = d1 + 1;
float ix2 = mod(d2, 8.0);
float iy2 = float(d2 / 8);
vec2 oc2 = inimg + vec2(ix2, iy2);
oc2 *= vec2(0.125, 0.0625);
vec4 t1 = texture2D(noisef, oc1);
vec4 t2 = texture2D(noisef, oc2);
vec4 t = mix(t1, t2, fract(fpz));
return t;
}
void main (void)
{
// normalize -6.2:6.2 to 0:1
vec3 p = pos;
p *= 0.08;
p += vec3(0.5, 0.5, 0.5) ;
vec4 noisevec1 = flat_texture3D(p + vec3(sin(time * 0.4),0.0 ,0.0));
vec4 noisevec2 = flat_texture3D(p.yzx + vec3(0.0, cos(time * 0.4), 0.0));
float a = abs(noisevec1[0] - 0.4) * 2.0;
float b = abs(noisevec2[0] - 0.6) * 2.0;
float c = a + b;
c = min(max(c, 0.0), 1.0);
//vec4 noisevec = flat_texture3D(p);
//float a = noisevec[0];
//vec3 color = vec3(a,a,a);// mix(colorA, colorB, a);
//color *= LightIntensity;
vec3 color = mix(colorA, colorB, c);
gl_FragColor = vec4(color, 1.0);
return;
}
</script>
<script id="bkgFs" type="x-shader/x-fragment">
precision highp float;
varying vec3 pos;
uniform float time;
#define L1 0.2,0.2,1.0, 1.0,3.0,+1.0,0.07, 5.0,+1.0,0.5, vec3(0.2,0.0,0.5)
#define L2 0.2,0.2,1.0, 0.0,2.1,+1.5,0.05, 7.0,-0.5,0.2, vec3(0.2,0.0,0.5)
#define L3 -0.2,-0.2,1.0, 0.0,2.5,+1.1,0.1, 6.0,-1.0,0.2, vec3(0.1,0.0,0.4)
#define L4 -0.2,-0.2,1.0, 1.0,3.5,-1.1,0.06, 8.0,1.0,0.3, vec3(0.1,0.0,0.4)
float mfmod(float x, float y) {
return x - y * floor(x/y);
}
vec3 makeLine(float ax, float ay, float az,
float hOffs, float hRep, float hTimeMult, float hSlit,
float dPiDiv, float dTimeMult, float dSlit,
vec3 color,
float t, float at)
{
bool p = true;
float a = az*pos.z + ay*pos.y + ax*pos.x;
p = p && (mfmod(abs(a + t*hTimeMult) + hOffs, hRep) < hSlit);
float deg = mfmod(abs(at + t*dTimeMult), 3.14126 / dPiDiv);
p = p && (deg < dSlit);
return float(p) * color;
}
void main() {
float t = time / 4.0;
vec3 c = vec3(0.0, 0.0, 0.0);
float at = atan(pos.x / pos.y);
c += makeLine(L1, t, at);
c += makeLine(L2, t, at);
c += makeLine(L3, t, at);
c += makeLine(L4, t, at);
gl_FragColor = vec4(c, 1.0);
}
</script>
<body></body></html>