laurentlb / shader-minifier

Minify and obfuscate GLSL or HLSL code

Home Page:https://ctrl-alt-test.fr/minifier/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

feature request: rename with prefix or suffix

fy0 opened this issue · comments

commented

Sometimes, we use include to insert shader fragments, and when processing these fragment files separately, duplicate naming may occur.
We hope to add a unified prefix or suffix to avoid this situation

I'm not sure how that would work. Do you have collisions with the function names, or with other symbols (e.g. uniforms)?

If it's with function names, how would you call the functions, if they are renamed?

I don't fully understand your use-case, but maybe:

  • you can run Shader Minifier after the processing
  • or you can run Shader Minifier and disable function renaming
commented

For example, there are two shader files for include:

// frag_1.glsl
float func1() { return 1.5; }
float calc1() { return func1() * 1.5; }
// frag_2.glsl
float func2() { return 2.0; }
float calc2() { return func2() * 1.5; }

In final fragment shader:

// frag_pbr.glsl
#include <frag_1>
#include <frag_2>

...

The #include can be understood as glsl's syntax, or just replace keyword in string.

When i use Shader Minifier on frag_1 and frag_2, function or vars names will be duplicated:

./shader_minifier.exe --format text --preserve-externals frag_1.glsl -o f1.glsl --no-remove-unused --no-inlining --no-renaming-list calc2,calc1
./shader_minifier.exe --format text --preserve-externals frag_2.glsl -o f2.glsl --no-remove-unused --no-inlining --no-renaming-list calc2,calc1

float c(){return 1.5;}float calc1(){return c()*1.5;}
float c(){return 2.;}float calc2(){return c()*1.5;}

It will be work if add a prefix:

float f1_c(){return 1.5;}float calc1(){return f1_c()*1.5;}
float f2_c(){return 2.;}float calc2(){return f2_c()*1.5;}

It's my case. If there's anything I said unclearly, please let me know.