/
index.html
53 lines (46 loc) · 1.29 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<title>GLSL Example No.017</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<script id="vs" type="x-shader/x-vertex">
attribute vec3 position;
attribute vec2 textureCoord;
varying vec2 vTextureCoord;
void main()
{
vTextureCoord = textureCoord;
gl_Position = vec4(position, 1.0);
}
</script>
<script id="fs" type="x-shader/x-fragment">
precision mediump float;
uniform sampler2D texture;
uniform float time;
uniform vec2 mouse;
uniform vec2 resolution;
varying vec4 vColor;
varying vec2 vTextureCoord;
const float redScale = 0.298912;
const float greenScale = 0.586611;
const float blueScale = 0.114478;
const vec3 monochromeScale = vec3(redScale, greenScale, blueScale);
void main( void ) {
vec2 p = (gl_FragCoord.xy * 2.0 - resolution) / min(resolution.x, resolution.y);
vec2 uv = vTextureCoord;
vec4 color = texture2D(texture, uv);
float mono = 0.0;
if ( p.x > 0.0 ) {
mono = dot(color.rgb, monochromeScale); // NTSC weighted average method
} else {
mono = (color.r + color.g + color.b) / 3.0; // Simple average method
}
gl_FragColor = vec4(mono, mono, mono, 1.0);
}
</script>
<canvas id="c" width="465" height="465"></canvas>
<script src="index.js"></script>
</body>
</html>