<h1>Danger - Status</h1>
<p>Works for me, but might wipe your harddisk.</p>
<h1>What?</h1>
<p>Takes a glsl shader, removes white space, comments, etc, and replaces symbols/identifiers/type names by shorter ones that compress better.</p>
<h1>Why?</h1>
<p>I got tired of installing mono to get shader-minifier working,
and needed something that I could embedd into my tools.</p>
<h1>Why rust?</h1>
<p>Because.
And I want to learn rust.</p>
<p>And it's portable, and fast, and future proof.</p>
<h1>Usage</h1>
<h2>Commandline</h2>
<p>```
cargo run --help</p>
<p>cargo run -- --input shader.glsl --output shader_crushed.glsl
```</p>
<p>Use <code>--blacklist "dont,crush,these"</code>
or
```glsl</p>
<p>// code</p>
<p>#pragma SHADER_CRUSHER_OFF</p>
<p>// code</p>
<p>#pragma SHADER_CRUSHER_ON</p>
<p>// code
```
to keep certain identifiers untouched, e.g. uniforms that you need to resolve externaly.
Keywords, built-in functions, and 'main' are automatically blacklisted.</p>
<h2>Embedded/Linked</h2>
<p>From C/C++</p>
<p><code>c++
shader_crusher::ShaderCrusher* pShaderCrusher = shader_crusher::shadercrusher_new();
shader_crusher::shadercrusher_set_input( pShaderCrusher, fragmentString.c_str() );
shader_crusher::shadercrusher_crush( pShaderCrusher );
char* pOutput = shader_crusher::shadercrusher_get_ouput( pShaderCrusher );
fragmentString = std::string( pOutput );
shader_crusher::shadercrusher_free_ouput( pShaderCrusher, pOutput );
shader_crusher::shadercrusher_free( pShaderCrusher );</code>
Don't forget do include the cbindgen generated header file, and link against the lib.</p>
<h1>Stats</h1>
<p>I only used it on my shaders so far, but on average the crushed size is 60%, or 40% if you further compress (e.g. with UPX/Crinkler/kkrunchy).</p>
<h1>Soon</h1>
<p>(because I want it)</p>
<ul>
<li> Allow blacklist via c-api.</li>
<li> Add revalidation of output.</li>
<li> Run against piglet suite.</li>
<li> CI system with testing</li>
</ul>
<h1>Future</h1>
<p>(aka not going to happen anytime soon)</p>
<ul>
<li> Dead code removal</li>
<li> Smart replacement of repeated blocks</li>
<li> Multishader passes for smart extraction of shared code</li>
</ul>
<h1>Help</h1>
<ul>
<li>Run this against your shader, and see if it breaks anything, and what compression ratio you get.</li>
<li>Fix <a href="https://github.com/phaazon/glsl/issues/52">#52</a> in the glsl crate (too many braces).</li>
<li>Fix <a href="https://github.com/phaazon/glsl/issues/110">#110</a> in the glsl crate (whitespace in defines).</li>
<li>The swizzling blacklist is totally wrong, but gets the job done for now.</li>
<li>'#define's could be fixed, but I was lazy.</li>
</ul>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta charset="utf-8"/>
</head>
<body>
</body>
</html>