[3D Programming] GLSL Minifier: Pack Your GLSL Code Into a C Header

OpenGL logo

GLSL Minifier is a tool made by a french demogroup (yeah!) to pack GLSL shader code into a C header file. It generates a code as small as possible that is equivalent to the input code. GLSL Minifier has been optimized for the compression tool Crinkler.

See this post for some tips to create very small code and help compression tools like Crinkler.

I tested GLSL Minifier with the following pixel shader saved in a file called ps.glsl:

#version 120
uniform sampler2D blurTex;
uniform float rt_w;
uniform float rt_h;
// Kernel weight vector
float samples[5];

uniform float kernel[5];

vec4 BlurV(vec2 Tex)
  vec4 Color = vec4(0.0);
  for (int i = 0; i<5; i++)
    Color += texture2D(blurTex, 
                       vec2(Tex.x, Tex.y +  samples[i])
                       ) * kernel[i];
  return Color;
void main()
  vec2 uv = gl_TexCoord[0].xy;
  samples[0] = -4.0/rt_w;
	samples[1] = -2.0/rt_w;
  samples[2] = 0.0;
  samples[3] = 2.0/rt_w;
  samples[4] = 4.0/rt_w;
  gl_FragColor = BlurV(uv);

I ran GLSL_Minifier in command line:

glsl_minifier ps.glsl

and here is the C file generated by GLSL_Minifier:

/* File generated with GLSL Minifier 0.4.1
 * http://www.ctrl-alt-test.fr
#ifndef SHADER_CODE_H_
#define SHADER_CODE_H_
#define U_KERNEL "t"
#define U_RT_H "e"
#define U_RT_W "o"
#define U_BLURTEX "r"
const char *shader_ps = ""
 "#version 120\n"
 "uniform sampler2D r;"
 "uniform float o,e;"
 "float v[5];"
 "uniform float t[5];"
 "vec4 n(vec2 o)"
   "vec4 e=vec4(0.);"
   "for(int n=0;n<5;n++)"
   "return e;"
 "void main()"
   "vec2 r=gl_TexCoord[0].rg;"
#endif // SHADER_CODE_H_

GLSL Minifier has an option called --make-elevated2. Here is the output :D

GLSL Minifier



↑ Grab this Headline Animator