Shader_Minifier icon indicating copy to clipboard operation
Shader_Minifier copied to clipboard

feature request: rename with prefix or suffix

Open fy0 opened this issue 2 years ago • 2 comments

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

fy0 avatar Jul 25 '23 19:07 fy0

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

laurentlb avatar Jul 25 '23 19:07 laurentlb

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.

fy0 avatar Jul 26 '23 16:07 fy0