forked from aras-p/glsl-optimizer
-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.html
159 lines (133 loc) · 5.07 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
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
<!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>GLSL Optimizer Emscripten</title>
<style>
body {
font-family: sans-serif;
margin: 0;
padding: 10px;
}
textarea {
width: 600px;
height: 400px;
font-family: monospace;
font-size: 13px;
padding: 10px;
}
</style>
</head>
<body>
<h1>GLSL Optimizer</h1>
<p>
This is the emscripten/asm.js version of GLSL optimizer. Check out the <a href="https://github.com/zz85/glsl-optimizer/">repo on github</a>.
</p>
<p>
<div id="statusLabel"></div>
<div id="errorLabel"></div>
</p>
<p>
<select id="shaderType">
<option value="fs">Fragment shader</option>
<option value="vs">Vertex shader</option>
</select>
<select id="target">
<option value="1">OpenGL</option>
<option value="2" selected>OpenGL ES 2.0</option>
<option value="3">OpenGL ES 3.0</option>
</select>
<button onclick="optimize();">Optimize!</button>
</p>
<p>
<textarea id="source">
#define SPREAD 8.00
#define MAX_DIR_LIGHTS 0
#define MAX_POINT_LIGHTS 0
#define MAX_SPOT_LIGHTS 0
#define MAX_HEMI_LIGHTS 0
#define MAX_SHADOWS 0
#define GAMMA_FACTOR 2
uniform mat4 viewMatrix;
uniform vec3 cameraPosition;
uniform vec2 resolution;
uniform float time;
uniform sampler2D texture;
void main() {
vec2 uv = gl_FragCoord.xy / resolution.xy;
float v = texture2D( texture, uv ).x;
if (v == 1000.) discard;
v = sqrt(v);
gl_FragColor = vec4( vec3( 1. - v / SPREAD ), 1.0 );;
}
</textarea>
</p>
<script type='text/javascript'>
var statusLabel = document.getElementById('statusLabel');
var GLSLOptimizer = {
onError: function(reason) {
// console.error(e);
statusLabel.textContent = reason;
},
onSuccess: function(code) {
errorLabel.textContent = statusLabel.textContent = '';
source.value = code;
},
}
var optimize_glsl = function() {
alert('not loaded yet!');
}
function postRun() {
optimize_glsl = Module.cwrap('optimize_glsl', 'string', ['string', 'number', 'number']);
}
function optimize() {
var results = optimize_glsl( source.value, +target.value, shaderType.value === "vs");
console.log('results', results)
if (results.indexOf('Error:') > -1) {
GLSLOptimizer.onError(results);
} else {
GLSLOptimizer.onSuccess(results);
}
}
var Module = {
preRun: [],
postRun: [ postRun ],
print: function(text) {
console.log('::print::', text);
errorLabel.textContent = text;
},
printErr: function(text) {
text = Array.prototype.slice.call(arguments).join(' ');
if (0) { // XXX disabled for safety typeof dump == 'function') {
dump(text + '\n'); // fast, straight to the real console
} else {
console.error(text);
}
},
setStatus: function(text) {
// console.log('::status::', text)
statusLabel.textContent = text;
},
totalDependencies: 0,
monitorRunDependencies: function(left) {
// console.error('monitorRunDependencies', left);
this.totalDependencies = Math.max(this.totalDependencies, left);
Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.');
},
locateFile: function(hoho) {
return 'glsl-optimizer.js.mem';
}
};
Module.setStatus('Downloading...');
window.onerror = function(event) {
Module.setStatus('Exception thrown, see JavaScript console');
Module.setStatus = function(text) {
if (text) Module.printErr('[post-exception status] ' + text);
};
};
</script>
<script async type="text/javascript" src="glsl-optimizer.js"></script>
<style>#forkongithub a{background:#000;color:#fff;text-decoration:none;font-family:arial,sans-serif;text-align:center;font-weight:bold;padding:5px 40px;font-size:1rem;line-height:2rem;position:relative;transition:0.5s;}#forkongithub a:hover{background:#c11;color:#fff;}#forkongithub a::before,#forkongithub a::after{content:"";width:100%;display:block;position:absolute;top:1px;left:0;height:1px;background:#fff;}#forkongithub a::after{bottom:1px;top:auto;}@media screen and (min-width:800px){#forkongithub{position:absolute;display:block;top:0;right:0;width:200px;overflow:hidden;height:200px;z-index:9999;}#forkongithub a{width:200px;position:absolute;top:60px;right:-60px;transform:rotate(45deg);-webkit-transform:rotate(45deg);-ms-transform:rotate(45deg);-moz-transform:rotate(45deg);-o-transform:rotate(45deg);box-shadow:4px 4px 10px rgba(0,0,0,0.8);}}</style><span id="forkongithub"><a href="https://github.com/zz85/glsl-optimizer/">Fork me on GitHub</a></span>
</body>
</html>