gam0022 / resimulated

1st place at Revision 2020 (PC 64K Intro)
MIT License
18 stars 1 forks source link

GLSLをminifyしたい #6

Closed gam0022 closed 4 years ago

gam0022 commented 4 years ago

laurentlb/Shader_Minifier

https://github.com/laurentlb/Shader_Minifier

mono shader_minifier.exe                                                                                                              13:06:42
Shader Minifier 1.1.6 - https://github.com/laurentlb/Shader_Minifier
Please give the shader files to compress on the command line.
    -o <string>: Set the output filename (default is shader_code.h)
    -v: Verbose, display additional information
    --hlsl: Use HLSL (default is GLSL)
    --format <string>: Can be: c-variables (default), c-array, js, nasm, or none
    --field-names <string>: Choose the field names for vectors: 'rgba', 'xyzw', or 'stpq'
    --preserve-externals: Do not rename external values (e.g. uniform)
    --preserve-all-globals: Do not rename functions and global variables
    --no-renaming: Do not rename anything
    --no-renaming-list <string>: Comma-separated list of functions to preserve
    --no-sequence: Do not use the comma operator trick
    --smoothstep: Use IQ's smoothstep trick
    -- ...: Stop parsing command line
    --help: display this list of options
    -help: display this list of options

./glslopt ~/Dropbox/TDF2020/webpack-tdf2020/src/fragment.glsl output.glsl -3

precision highp float;precision highp int;precision mediump sampler3D; をインジェクトすればコンパイル通る。

#version 300 es
precision highp float;precision highp int;precision mediump sampler3D;uniform vec3 iResolution;uniform float iTime,iChannelTime[4];uniform vec4 iMouse,iDate;uniform float iSampleRate;uniform vec3 iChannelResolution[4];uniform int iFrame;uniform float iTimeDelta,iFrameRate;struct Channel{vec3 resolution;float time;};uniform Channel iChannel[4];uniform sampler2D iChannel0,iChannel1,iChannel2,iChannel3;out vec4 outColor;void i(out vec4 i,in vec2 v){vec2 f=v/iResolution.xy;vec3 e=.5+.5*cos(iTime+f.xyx+vec3(0,2,4));i=vec4(e,1.);}void main(){vec4 e=vec4(0.,0.,0.,1.);i(e,gl_FragCoord.xy);e.w=1.;outColor=e;}

1116 byte -> 623 byte

gam0022 commented 4 years ago

glsl-optimizer

./glslopt                                                                                                  14:26:25
Usage: glslopt <-f|-v> <input shader> [<output shader>]
    -f : fragment shader (default)
    -v : vertex shader
    -1 : target OpenGL (default)
    -2 : target OpenGL ES 2.0
    -3 : target OpenGL ES 3.0

    If no output specified, output is to [input].out.

./glslopt ~/Dropbox/TDF2020/webpack-tdf2020/src/fragment.glsl output.glsl -3

#version 300 es
precision mediump sampler3D;
precision highp int;
precision highp float;
uniform vec3 iResolution;
uniform float iTime;
out highp vec4 outColor;
void main ()
{
  highp vec4 color_1;
  highp vec4 tmpvar_2;
  tmpvar_2.w = 1.0;
  tmpvar_2.xyz = (0.5 + (0.5 * cos(
    ((iTime + (gl_FragCoord.xy / iResolution.xy).xyx) + vec3(0.0, 2.0, 4.0))
  )));
  color_1.xyz = tmpvar_2.xyz;
  color_1.w = 1.0;
  outColor = color_1;
}

435 byte

gam0022 commented 4 years ago

https://qiita.com/gam0022/items/364c7f76f2787e385161 にまとめた