Crates.io | shader-crusher |
lib.rs | shader-crusher |
version | 0.4.1-alpha |
source | src |
created_at | 2021-04-05 09:57:15.497725 |
updated_at | 2022-08-27 17:32:08.014013 |
description | A little helper to optimize glsl shaders for size. |
homepage | https://github.com/AndreasOM/shader-crusher |
repository | https://github.com/AndreasOM/shader-crusher |
max_upload_size | |
id | 379261 |
size | 43,449 |
Works for me, but might wipe your harddisk.
Takes a glsl shader, removes white space, comments, etc, and replaces symbols/identifiers/type names by shorter ones that compress better.
I got tired of installing mono to get shader-minifier working, and needed something that I could embedd into my tools.
Because. And I want to learn rust.
And it's portable, and fast, and future proof.
cargo run --help
cargo run -- --input shader.glsl --output shader_crushed.glsl
Use --blacklist "dont,crush,these"
or
// code
#pragma SHADER_CRUSHER_OFF
// code
#pragma SHADER_CRUSHER_ON
// code
to keep certain identifiers untouched, e.g. uniforms that you need to resolve externaly. Keywords, built-in functions, and 'main' are automatically blacklisted.
From C/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 );
Don't forget do include the cbindgen generated header file, and link against the lib.
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).
(because I want it)
(aka not going to happen anytime soon)
Dead code removal
Smart replacement of repeated blocks
Multishader passes for smart extraction of shared code