|
|
@ -6,7 +6,8 @@ uniform vec3 iMouse;
|
|
6
|
6
|
|
|
7
|
7
|
`;
|
|
8
|
8
|
|
|
9
|
|
function transformShader(shader) {
|
|
|
9
|
function transformShader(shader, noPrelude, visited) {
|
|
|
10
|
var visited = visited || {};
|
|
10
|
11
|
var lines = shader.split("\n");
|
|
11
|
12
|
lines = lines.map(function(line) {
|
|
12
|
13
|
var match = line.match(/\/\/#include "(.*)"/);
|
|
|
@ -15,14 +16,18 @@ function transformShader(shader) {
|
|
15
|
16
|
if (!file.content) {
|
|
16
|
17
|
throw new Error(`No such file: '${match[1]}'`);
|
|
17
|
18
|
}
|
|
|
19
|
if (file.name in visited) {
|
|
|
20
|
throw new Error(`Include loop: '${match[1]}'`);
|
|
|
21
|
}
|
|
|
22
|
visited[file.name] = true;
|
|
|
23
|
var expanded = transformShader(file.content, true, visited);
|
|
18
|
24
|
return `//#includestart "${match[1]}" (start)
|
|
19
|
|
${file.content}
|
|
20
|
|
//#includeend "${match[1]}"
|
|
21
|
|
`
|
|
|
25
|
${expanded}
|
|
|
26
|
//#includeend "${match[1]}"`
|
|
22
|
27
|
} else {
|
|
23
|
28
|
return line;
|
|
24
|
29
|
}
|
|
25
|
30
|
});
|
|
26
|
31
|
|
|
27
|
|
return prelude + lines.join("\n");
|
|
|
32
|
return (noPrelude ? "" : prelude) + lines.join("\n");
|
|
28
|
33
|
}
|