♻️ Use a single GLSL files for each effect

This commit is contained in:
Simon Schneegans
2022-05-13 09:17:26 +02:00
parent 84d5ad9caf
commit 7b8d6e18b2
34 changed files with 1006 additions and 915 deletions
+8 -3
View File
@@ -164,11 +164,16 @@ if (utils.isInShellProcess()) {
// This is called by the constructor. This means, it's only called when the effect
// is used for the first time.
vfunc_build_pipeline() {
const decl =
utils.loadGLSLResource(`/shaders/${Apparition.getNick()}-declarations.glsl`);
const code = utils.loadGLSLResource(`/shaders/${Apparition.getNick()}.glsl`);
this.add_glsl_snippet(Shell.SnippetHook.FRAGMENT, decl, code, true);
// Match anything between the curly brackets of "void main() {...}".
const regex = RegExp('void main *\\(\\) *\\{([\\S\\s]+)\\}', 'd');
const match = regex.exec(code);
const declarations = code.substr(0, match.index);
const main = match[1];
this.add_glsl_snippet(Shell.SnippetHook.FRAGMENT, declarations, main, true);
}
});
}
+8 -3
View File
@@ -201,11 +201,16 @@ if (utils.isInShellProcess()) {
// This is called by the constructor. This means, it's only called when the effect
// is used for the first time.
vfunc_build_pipeline() {
const decl =
utils.loadGLSLResource(`/shaders/${BrokenGlass.getNick()}-declarations.glsl`);
const code = utils.loadGLSLResource(`/shaders/${BrokenGlass.getNick()}.glsl`);
this.add_glsl_snippet(Shell.SnippetHook.FRAGMENT, decl, code, true);
// Match anything between the curly brackets of "void main() {...}".
const regex = RegExp('void main *\\(\\) *\\{([\\S\\s]+)\\}', 'd');
const match = regex.exec(code);
const declarations = code.substr(0, match.index);
const main = match[1];
this.add_glsl_snippet(Shell.SnippetHook.FRAGMENT, declarations, main, true);
}
// This is overridden to bind the shard texture for drawing. Sadly, this seems to be
+8 -3
View File
@@ -152,11 +152,16 @@ if (utils.isInShellProcess()) {
// This is called by the constructor. This means, it's only called when the effect
// is used for the first time.
vfunc_build_pipeline() {
const decl =
utils.loadGLSLResource(`/shaders/${EnergizeA.getNick()}-declarations.glsl`);
const code = utils.loadGLSLResource(`/shaders/${EnergizeA.getNick()}.glsl`);
this.add_glsl_snippet(Shell.SnippetHook.FRAGMENT, decl, code, true);
// Match anything between the curly brackets of "void main() {...}".
const regex = RegExp('void main *\\(\\) *\\{([\\S\\s]+)\\}', 'd');
const match = regex.exec(code);
const declarations = code.substr(0, match.index);
const main = match[1];
this.add_glsl_snippet(Shell.SnippetHook.FRAGMENT, declarations, main, true);
}
});
}
+8 -3
View File
@@ -152,11 +152,16 @@ if (utils.isInShellProcess()) {
// This is called by the constructor. This means, it's only called when the effect
// is used for the first time.
vfunc_build_pipeline() {
const decl =
utils.loadGLSLResource(`/shaders/${EnergizeB.getNick()}-declarations.glsl`);
const code = utils.loadGLSLResource(`/shaders/${EnergizeB.getNick()}.glsl`);
this.add_glsl_snippet(Shell.SnippetHook.FRAGMENT, decl, code, true);
// Match anything between the curly brackets of "void main() {...}".
const regex = RegExp('void main *\\(\\) *\\{([\\S\\s]+)\\}', 'd');
const match = regex.exec(code);
const declarations = code.substr(0, match.index);
const main = match[1];
this.add_glsl_snippet(Shell.SnippetHook.FRAGMENT, declarations, main, true);
}
});
}
+8 -2
View File
@@ -279,10 +279,16 @@ if (utils.isInShellProcess()) {
// This is called by the constructor. This means, it's only called when the effect
// is used for the first time.
vfunc_build_pipeline() {
const decl = utils.loadGLSLResource(`/shaders/${Fire.getNick()}-declarations.glsl`);
const code = utils.loadGLSLResource(`/shaders/${Fire.getNick()}.glsl`);
this.add_glsl_snippet(Shell.SnippetHook.FRAGMENT, decl, code, true);
// Match anything between the curly brackets of "void main() {...}".
const regex = RegExp('void main *\\(\\) *\\{([\\S\\s]+)\\}', 'd');
const match = regex.exec(code);
const declarations = code.substr(0, match.index);
const main = match[1];
this.add_glsl_snippet(Shell.SnippetHook.FRAGMENT, declarations, main, true);
}
});
}
+8 -3
View File
@@ -171,11 +171,16 @@ if (utils.isInShellProcess()) {
// This is called by the constructor. This means, it's only called when the effect
// is used for the first time.
vfunc_build_pipeline() {
const decl =
utils.loadGLSLResource(`/shaders/${Hexagon.getNick()}-declarations.glsl`);
const code = utils.loadGLSLResource(`/shaders/${Hexagon.getNick()}.glsl`);
this.add_glsl_snippet(Shell.SnippetHook.FRAGMENT, decl, code, true);
// Match anything between the curly brackets of "void main() {...}".
const regex = RegExp('void main *\\(\\) *\\{([\\S\\s]+)\\}', 'd');
const match = regex.exec(code);
const declarations = code.substr(0, match.index);
const main = match[1];
this.add_glsl_snippet(Shell.SnippetHook.FRAGMENT, declarations, main, true);
}
});
}
+8 -3
View File
@@ -183,11 +183,16 @@ if (utils.isInShellProcess()) {
// https://www.shadertoy.com/view/ldccW4, however the implementation is quite
// different as the letters drop only once and there is no need for a noise texture.
vfunc_build_pipeline() {
const decl =
utils.loadGLSLResource(`/shaders/${Matrix.getNick()}-declarations.glsl`);
const code = utils.loadGLSLResource(`/shaders/${Matrix.getNick()}.glsl`);
this.add_glsl_snippet(Shell.SnippetHook.FRAGMENT, decl, code, true);
// Match anything between the curly brackets of "void main() {...}".
const regex = RegExp('void main *\\(\\) *\\{([\\S\\s]+)\\}', 'd');
const match = regex.exec(code);
const declarations = code.substr(0, match.index);
const main = match[1];
this.add_glsl_snippet(Shell.SnippetHook.FRAGMENT, declarations, main, true);
}
// This is overridden to bind the font texture for drawing. Sadly, this seems to be
+8 -3
View File
@@ -177,12 +177,17 @@ if (utils.isInShellProcess()) {
// This is called by the constructor. This means, it's only called when the effect
// is used for the first time.
vfunc_build_pipeline() {
const decl = utils.loadGLSLResource(
`/shaders/${SnapOfDisintegration.getNick()}-declarations.glsl`);
const code =
utils.loadGLSLResource(`/shaders/${SnapOfDisintegration.getNick()}.glsl`);
this.add_glsl_snippet(Shell.SnippetHook.FRAGMENT, decl, code, true);
// Match anything between the curly brackets of "void main() {...}".
const regex = RegExp('void main *\\(\\) *\\{([\\S\\s]+)\\}', 'd');
const match = regex.exec(code);
const declarations = code.substr(0, match.index);
const main = match[1];
this.add_glsl_snippet(Shell.SnippetHook.FRAGMENT, declarations, main, true);
}
// This is overridden to bind the dust texture for drawing. Sadly, this seems to be
+8 -3
View File
@@ -179,11 +179,16 @@ if (utils.isInShellProcess()) {
// This is called by the constructor. This means, it's only called when the effect
// is used for the first time.
vfunc_build_pipeline() {
const decl =
utils.loadGLSLResource(`/shaders/${TRexAttack.getNick()}-declarations.glsl`);
const code = utils.loadGLSLResource(`/shaders/${TRexAttack.getNick()}.glsl`);
this.add_glsl_snippet(Shell.SnippetHook.FRAGMENT, decl, code, true);
// Match anything between the curly brackets of "void main() {...}".
const regex = RegExp('void main *\\(\\) *\\{([\\S\\s]+)\\}', 'd');
const match = regex.exec(code);
const declarations = code.substr(0, match.index);
const main = match[1];
this.add_glsl_snippet(Shell.SnippetHook.FRAGMENT, declarations, main, true);
}
// This is overridden to bind the claw texture for drawing. Sadly, this seems to be
+8 -3
View File
@@ -148,11 +148,16 @@ if (utils.isInShellProcess()) {
// This is called by the constructor. This means, it's only called when the effect
// is used for the first time.
vfunc_build_pipeline() {
const decl =
utils.loadGLSLResource(`/shaders/${TVEffect.getNick()}-declarations.glsl`);
const code = utils.loadGLSLResource(`/shaders/${TVEffect.getNick()}.glsl`);
this.add_glsl_snippet(Shell.SnippetHook.FRAGMENT, decl, code, true);
// Match anything between the curly brackets of "void main() {...}".
const regex = RegExp('void main *\\(\\) *\\{([\\S\\s]+)\\}', 'd');
const match = regex.exec(code);
const declarations = code.substr(0, match.index);
const main = match[1];
this.add_glsl_snippet(Shell.SnippetHook.FRAGMENT, declarations, main, true);
}
});
}
+8 -3
View File
@@ -158,11 +158,16 @@ if (utils.isInShellProcess()) {
// This is called by the constructor. This means, it's only called when the effect
// is used for the first time.
vfunc_build_pipeline() {
const decl =
utils.loadGLSLResource(`/shaders/${Wisps.getNick()}-declarations.glsl`);
const code = utils.loadGLSLResource(`/shaders/${Wisps.getNick()}.glsl`);
this.add_glsl_snippet(Shell.SnippetHook.FRAGMENT, decl, code, true);
// Match anything between the curly brackets of "void main() {...}".
const regex = RegExp('void main *\\(\\) *\\{([\\S\\s]+)\\}', 'd');
const match = regex.exec(code);
const declarations = code.substr(0, match.index);
const main = match[1];
this.add_glsl_snippet(Shell.SnippetHook.FRAGMENT, declarations, main, true);
}
});
}
+3 -1
View File
@@ -106,7 +106,9 @@ function loadGLSLResource(path) {
// This regex matches either #include "..." or #include <...>. The part between the
// brackets is captured in the named "file" capture group.
code = code.replaceAll(/#include ["<](?<file>.+)[">]/g, (m, p1, p2, str, groups) => {
const regex = RegExp('#include ["<](?<file>.+)[">]', 'g');
code = code.replaceAll(regex, (m, p1, p2, str, groups) => {
return loadStringResource('/shaders/' + groups.file);
});