-
Notifications
You must be signed in to change notification settings - Fork 1
/
example_with_controls.html
86 lines (66 loc) · 2.71 KB
/
example_with_controls.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
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jQuery-Knob/1.2.13/jquery.knob.min.js"></script>
</head>
<body>
<!-- Knobs to control uniform variables of the program -->
<input value="1" data-min="0" data-max="2" id="r_weight" title="R channel weight"/>
<input value="1" data-min="0" data-max="2" id="g_weight" title="G channel weight"/>
<input value="1" data-min="0" data-max="2" id="b_weight" title="B channel weight"/>
<br/>
<!-- Canvas element to display results and get a WebGL context from. -->
<canvas id="canvas"></canvas>
<!-- Source image content to use as textures.
To add new images put <img> entries with different "id" and "src" attributes.
Warning: WebGL cannot load local files to textures, a webserver is required. -->
<img id="carousel_1mpix" src="http://199.247.15.26/carousel_1mpix.jpg" crossorigin="anonymous"/>
<!-- Other images (uncomment the corresponding lines to load some of them):
<img id="carousel_4mpix" src="http://199.247.15.26/carousel_4mpix.jpg" crossorigin="anonymous"/>
<img id="carousel_11mpix" src="http://199.247.15.26/carousel_11mpix.jpg" crossorigin="anonymous"/>
<img id="boat_1mpix" src="http://199.247.15.26/boat_1mpix.jpg" crossorigin="anonymous"/>
<img id="boat_4mpix" src="http://199.247.15.26/boat_4mpix.jpg" crossorigin="anonymous"/>
-->
<!-- Fragment shader example. -->
<script id="colorChannelWeightingShader" type="x-shader/x-fragment">
precision highp float;
// input image texture
uniform sampler2D inputImage;
// per-channel weights
uniform vec3 weight;
// texture coordinates corresponding to the current output pixel position
varying vec2 texCoord;
void main() {
vec4 color = texture2D(inputImage, texCoord);
gl_FragColor = vec4(color.rgb * weight, 1.0);
}
</script>
<!-- Main script -->
<script>
function main() {
// Initialize WebGL
const canvas = document.getElementById("canvas")
initialize(canvas)
// Set image display resolution
canvas.width = 1024
canvas.height = 1024
// Setup a program
const program = buildProgram("colorChannelWeightingShader")
// Listen to knob changes using this function
document.onknobchange = function() {
// Fill inputs: an image and an array with knob values
const inputs = {
inputImage: makeTextureFromImage("carousel_1mpix"),
weight: [getKnobValue("r_weight"), getKnobValue("g_weight"), getKnobValue("b_weight")]
}
// Run the program
runProgram(program, inputs)
}
}
</script>
<!-- Framework script -->
<script src="script.js"></script>
</body>
</html>