Skip to content

Commit

Permalink
Updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
flowtsohg committed Dec 10, 2013
1 parent b88dd7c commit f1a1dd5
Showing 1 changed file with 60 additions and 23 deletions.
83 changes: 60 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,63 @@ glsl-minifier

A GLSL minifier.


---------------------------------------

Features:
* Removes unneeded whitespace.
* Renames struct/function/function argument/function local variables/varying variable names.
* Optionally renames uniform variables, attribute variables, and struct members (read on to see how to access them).
* Removes useless zeroes from numbers, converts hexadecimal numbers to decimal numbers, and changes decimal numbers to exponent representation if it's shorter.
`0.1 => .1`
`0.10 => .1`
`1.0 => 1.`
`0x1 => 1`
`1000 => 1e3`

* Inlines #defines
* Merges uniform/attribute/varying declarations to list declarations where possible.
`uniform vec3 a;`
`uniform vec3 b;` => `uniform vec3 a,b,c;`
`uniform vec3 c;`
* Inlines #defines.

```
#define FIRST 5
#define SECOND FIRST*2 => 5;10;
FIRST;SECOND;
```
* Merges uniform/attribute/varying/const declarations to list declarations where possible.

```
uniform vec3 a;
uniform vec3 b; => uniform vec3 a,b,c;
uniform vec3 c;
```
* Removes dead functions.

```c
// Will be removed
void Dead() {

}

void Alive2() {

}

It works on a list of files in order to make the same changes on all of them and keep them working.
That is, the same new names will be given across all inputs.
void Alive1() {
Alive2();
}

void main() {
Alive1();
}
```


---------------------------------------

All the features work on a list of files in order to make the same changes on all of them and keep them working.
That is, the same new names will be given across all inputs, dead functions will only be functions that can't be reach from a main() function from any of the inputs, and so on.
This is useful for when there is shared code between shaders that is kept separately.

---------------------------------------

Usage:
`minify(["file1", "file2", ...], rewriteall)`

Expand All @@ -34,29 +71,29 @@ Index 0 is another array - the new shader sources for all inputs.
Index 1 is a hash object that maps between uniform/attribute old/new names.
Index 2 is a hash object that maps between struct member's old/new names.

If rewriteall is false, the two hashes returned are identity, meaning every name points to itself `"name"=>"name"`.
If rewriteall is false, the two hashes returned are identity, meaning every name points to itself: `"name"=>"name"`.

All member name changes are synchronized across all structs.
That is, if struct Foo has a member called "member", and struct Bar has a member called "member", then both of them will be renamed to "a".
This allows to use the struct member old/new name map easily when setting uniforms.
For example, let's assume we have the following code:

struct Foo {
float something;
};
uniform Foo foo;

```
struct Foo {
float something;
};
uniform Foo foo;
```

Now let's assume it got renamed to this:

struct A {
float a;
};
uniform A B;
```
struct A {
float a;
};
uniform A B;
```
The array returned by this minify call will be the following:
`minified = ["struct A{float a;};uniform A B;", {"Foo"=>"A", "foo"=>"B"}, {"something"=>"a"}]`

Expand Down

0 comments on commit f1a1dd5

Please sign in to comment.