Code Monkey home page Code Monkey logo

shader-crusher's Introduction

Danger - Status

Works for me, but might wipe your harddisk.

Windows Status MacOS Status Linux Status

What?

Takes a glsl shader, removes white space, comments, etc, and replaces symbols/identifiers/type names by shorter ones that compress better.

Why?

I got tired of installing mono to get shader-minifier working, and needed something that I could embedd into my tools.

Why rust?

Because. And I want to learn rust.

And it's portable, and fast, and future proof.

Usage

Commandline

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.

Embedded/Linked

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.

Stats

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).

Soon

(because I want it)

  • Allow blacklist via c-api.
  • Add revalidation of output.
  • Run against piglet suite.
  • CI system with testing

Future

(aka not going to happen anytime soon)

  • Dead code removal
  • Smart replacement of repeated blocks
  • Multishader passes for smart extraction of shared code

Help

  • Run this against your shader, and see if it breaks anything, and what compression ratio you get.
  • Fix #52 in the glsl crate (too many braces).
  • Fix #110 in the glsl crate (whitespace in defines).
  • The swizzling blacklist is totally wrong, but gets the job done for now.
  • '#define's could be fixed, but I was lazy.

shader-crusher's People

Contributors

andreasom avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.