-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathThreeShaderFormatter.html
More file actions
69 lines (55 loc) · 1.47 KB
/
ThreeShaderFormatter.html
File metadata and controls
69 lines (55 loc) · 1.47 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Three Shader Formatter</title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
article, aside, figure, footer, header, hgroup,
menu, nav, section { display: block; }
</style>
</head>
<body>
<div>
<label>Shader code:<br/>
<textarea id="shadercode" style="width:600px; height:480px" onkeydown="convert()"> #ifdef USE_FOG
uniform vec3 fogColor;
#ifdef FOG_EXP2
uniform float fogDensity;
#else
uniform float fogNear;
uniform float fogFar;
#endif
#endif"</textarea>
</label>
</div>
<div>
<label>Three Shader code:<br/>
<textarea id="threeshadercode" style="width:600px; height:480px" onkeydown="">Hello World</textarea>
</label>
</div>
<script>
function process(code) {
var threeshader = [ '[','' ];
var lines = code.split('\n');
for (var i=0;i<lines.length;i++) {
var line = lines[i];
if (line.trim()!="")
line = line.replace('"', '\\"').replace(/(\s*)(.*)(\s*)/, '$1"$2"$3,');
threeshader.push(line);
}
threeshader.push('');
threeshader.push('].join("\\n");');
return threeshader.join('\n');
}
function convert() {
document.getElementById('threeshadercode').value = process(
document.getElementById('shadercode').value
);
}
convert();
</script>
</body>
</html>