(Programming Tool) Shader Minifier 1.0: GLSL Minifier with HLSL Obfuscation

Shader Minifier 1.0: GLSL Minifier with HLSL Obfuscation

The french demogroup Ctrl-Alft-Test has released a new version of their shader minifier. The previous version was called GLSL Minifier because only GLSL shaders were supported. Now, with the support of HLSL shaders, GLSL Minifier has been renamed in Shader Minifier.

Shader Minifier is tool to pack GLSL / HLSL shader code into a C header file. It generates a code as small as possible that is equivalent to the input code. Shader Minifier has been optimized for the compression tool Crinkler. More information about Shader Minifier can be found HERE.

Size-optimizing a shader code by hand is tedious and inefficient. No matter how good your are, this GLSL/HLSL packer will probably be able to improve your hand-optimized code. It doesn’t mean you can do stupid things and rely only on the tool. Basically, you should do the optimizations the tool cannot do. Keep all the spaces, comments and useful variables names you need to have a readable and maintainable piece of code. You should focus on clever optimizations.

Most intros, even among the best ones, would benefit from this tool. Hand-written shaders can often be reduced by dozens of bytes (after compression) by using Shader Minifier.

Now a quick test. Here is the readable source of a GLSL toon shader:

uniform float specIntensity;
uniform vec4 specColor;
uniform float t[2];
uniform vec4 colors[3];
varying vec3 normal, lightDir;
void main()
	float intensity;
	vec3 n;
	vec4 color;
	n = normalize(normal);
	intensity = max(dot(lightDir,n),0.0); 
	if (intensity > specIntensity)
		color = specColor;
	else if (intensity > t[0])
		color = colors[0];	
	else if (intensity > t[1])
		color = colors[1];
		color = colors[2];		
	gl_FragColor = color;

The command line:

shader_minifier.exe toon.ps

and here is the C header file generated:

/* File generated with Shader Minifier 1.0
 * http://www.ctrl-alt-test.fr
#ifndef SHADER_CODE_H_
# define SHADER_CODE_H_
# define U_COLORS "m"
# define U_SPECCOLOR "i"
# define U_SPECINTENSITY "v"
# define U_T "f"
# define V_LIGHTDIR "o"
# define V_NORMAL "d"

const char *toon_ps = ""
 "uniform float v;"
 "uniform vec4 i;"
 "uniform float f[2];"
 "uniform vec4 m[3];"
 "varying vec3 d,o;"
 "void main()"
   "float e;"
   "vec3 u;"
   "vec4 r;"
     " if(f[0]<e)"
       " if(f[1]<e)"
         " r=m[2];"

#endif // SHADER_CODE_H_


2 thoughts on “(Programming Tool) Shader Minifier 1.0: GLSL Minifier with HLSL Obfuscation”

Comments are closed.