diff --git a/README.md b/README.md index 935bb49c..604ff5b7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Shader Minifier -[![Build status](https://ci.appveyor.com/api/projects/status/chwlpnssgd5kdl4x/branch/master?svg=true)](https://ci.appveyor.com/project/laurentlb/shader-minifier/branch/master) +[![Build status](https://ci.appveyor.com/api/projects/status/9sekrxuiway58su3?svg=true)](https://ci.appveyor.com/project/laurentlb/shader-minifier-r5gmt) Shader Minifier is a tool that minifies and obfuscates shader code (GLSL and HLSL) without affecting its behaviour. It is also suitable for reducing the size @@ -100,7 +100,7 @@ USAGE: Shader Minifier [--help] [-o ] [-v] [--hlsl] [--preserve-all-globals] [--no-inlining] [--aggressive-inlining] [--no-renaming] [--no-renaming-list ] [--no-sequence] - [--smoothstep] [--no-remove-unused] + [--no-remove-unused] [--move-declarations] [...] FILENAMES: @@ -134,7 +134,6 @@ OPTIONS: --no-renaming-list Comma-separated list of functions to preserve --no-sequence Do not use the comma operator trick - --smoothstep Use IQ's smoothstep trick --no-remove-unused Do not remove unused code --move-declarations Move declarations to group them --preprocess Evaluate some of the file preprocessor directives @@ -318,7 +317,6 @@ them all at the same time by listing them all on the command-line. - [Unused local variables](TRANSFORMATIONS.md#Unused-local-variables) - [Dead code removal](TRANSFORMATIONS.md#Dead-code-removal) - [Unused function removal](TRANSFORMATIONS.md#Unused-function-removal) -- [Smoothstep transformation](TRANSFORMATIONS.md#Smoothstep-transformation) - [Renaming](TRANSFORMATIONS.md#Renaming) diff --git a/TRANSFORMATIONS.md b/TRANSFORMATIONS.md index 22fcc4e8..afd41ec3 100644 --- a/TRANSFORMATIONS.md +++ b/TRANSFORMATIONS.md @@ -468,17 +468,6 @@ default, this is the case for `main` and `mainImage`. **Note**: Use `--no-remove-unused` to disable this transformation. -## Smoothstep transformation - -`smoothstep(a,b,x)` calls can be replaced with -`smoothstep(0.0,1.0,(x-a)/(b-a))`. When `a` and `b` are constant, the expression -will be simplified. In some cases, this might make the code more compressible, -and this technique was [used in -Elevated](https://www.pouet.net/topic.php?which=6751&page=1#c295695). - -However, in many cases this trick doesn't give good results. As a result, this -is not enabled by default; use `--smoothstep` if you want to try it. - ## Renaming There are two renaming strategies: diff --git a/src/options.fs b/src/options.fs index dd0352bb..03eafd2e 100644 --- a/src/options.fs +++ b/src/options.fs @@ -35,7 +35,6 @@ type CliArguments = | [] NoRenaming | [] NoRenamingList of string | [] NoSequence - | [] Smoothstep | [] NoRemoveUnused | [] MoveDeclarations | [] Preprocess @@ -58,7 +57,6 @@ type CliArguments = | NoRenaming -> "Do not rename anything" | NoRenamingList _ -> "Comma-separated list of functions to preserve" | NoSequence -> "Do not use the comma operator trick" - | Smoothstep -> "Use IQ's smoothstep trick" | NoRemoveUnused -> "Do not remove unused code" | MoveDeclarations -> "Move declarations to group them" | Preprocess -> "Evaluate some of the file preprocessor directives" @@ -70,7 +68,6 @@ type Options() = member val outputFormat = CVariables with get, set member val verbose = false with get, set member val debug = false with get, set - member val smoothstepTrick = false with get, set member val canonicalFieldNames = "xyzw" with get, set member val preserveExternals = false with get, set member val preserveAllGlobals = false with get, set @@ -119,7 +116,6 @@ let private initPrivate argv needFiles = options.outputFormat <- args.GetResult(FormatArg, defaultValue = CVariables) options.verbose <- args.Contains(Verbose) options.debug <- args.Contains(Debug) - options.smoothstepTrick <- args.Contains(Smoothstep) options.canonicalFieldNames <- (sprintf "%A" (args.GetResult(FieldNames, defaultValue = XYZW))).ToLower() options.preserveExternals <- args.Contains(PreserveExternals) || args.Contains(PreserveAllGlobals) options.preserveAllGlobals <- args.Contains(PreserveAllGlobals) diff --git a/src/rewriter.fs b/src/rewriter.fs index d244282e..644c872e 100644 --- a/src/rewriter.fs +++ b/src/rewriter.fs @@ -117,8 +117,8 @@ module private RewriterImpl = // Expression that is equivalent to an assignment. let (|Assignment|_|) = function - | (FunCall (Op "=", [Var v; e])) -> Some (v, e) - | (FunCall (Op op, [Var name; e])) when Builtin.assignOps.Contains op -> + | FunCall (Op "=", [Var v; e]) -> Some (v, e) + | FunCall (Op op, [Var name; e]) when Builtin.assignOps.Contains op -> let baseOp = op.TrimEnd('=') if not (Builtin.augmentableOperators.Contains baseOp) then None @@ -336,14 +336,6 @@ module private RewriterImpl = | FunCall(Var constr, args) when constr.Name = "vec2" || constr.Name = "vec3" || constr.Name = "vec4" -> simplifyVec constr args - // iq's smoothstep trick: http://www.pouet.net/topic.php?which=6751&page=1#c295695 - | FunCall(Var var, [Float (0.M,_); Float (1.M,_); _]) as e when var.Name = "smoothstep" -> e - | FunCall(Var var, [a; b; x]) when var.Name = "smoothstep" && options.smoothstepTrick -> - let sub1 = FunCall(Op "-", [x; a]) - let sub2 = FunCall(Op "-", [b; a]) - let div = FunCall(Op "/", [sub1; sub2]) |> mapExpr env - FunCall(Var (Ident "smoothstep"), [Float (0.M,""); Float (1.M,""); div]) - | Dot(e, field) when options.canonicalFieldNames <> "" -> Dot(e, renameField field) | Var s as e ->