├── .gitignore
├── GLSLRenderer
├── CmdOptions.cs
├── GLSLProg.cs
├── GLSLProgBase.cs
├── GLSLProgConstructor.cs
├── GLSLRenderer.csproj
├── MatN.cs
├── ObjectExtensions.cs
├── Program.cs
├── VectorBase.cs
├── VectorBaseSwizzles.cs
├── mat2.cs
├── mat3.cs
├── mat4.cs
├── vec2.cs
├── vec3.cs
└── vec4.cs
├── LICENSE
├── README.md
├── ShaderShrinker
├── InnoSetupProject
│ └── InstallScript.iss
├── Shrinker.Avalonia
│ ├── App.axaml
│ ├── App.axaml.cs
│ ├── Assets
│ │ ├── App.ico
│ │ └── Icon.icns
│ ├── Commands
│ │ ├── ClipboardCommand.cs
│ │ ├── CommandBase.cs
│ │ ├── FileOpenCommand.cs
│ │ ├── FileSaveCommand.cs
│ │ └── RelayCommand.cs
│ ├── Converters
│ │ ├── IsEqualConverter.cs
│ │ └── MarkdownToHtmlConverter.cs
│ ├── DiffCreator.cs
│ ├── Extensions
│ │ ├── ApplicationExtensions.cs
│ │ └── TextEditorExtensions.cs
│ ├── GLSL.xshd
│ ├── Models
│ │ ├── CombinedDiff.cs
│ │ ├── DiffCollection.cs
│ │ └── NameAndFileInfo.cs
│ ├── Presets
│ │ ├── Golf (Experimental)
│ │ ├── Maximum
│ │ ├── Reformat
│ │ └── Remove Dead Code
│ ├── Program.cs
│ ├── Properties
│ │ └── PublishProfiles
│ │ │ └── FolderProfile.pubxml
│ ├── Shadertoy
│ │ ├── ShadertoyApi.cs
│ │ └── ShadertoyImporter.cs
│ ├── Shrinker.Avalonia.csproj
│ ├── TempFile.cs
│ ├── UserSettings.cs
│ ├── ViewLocator.cs
│ ├── ViewModels
│ │ ├── AppViewModel.cs
│ │ ├── MainWindowViewModel.cs
│ │ └── PresetsViewModel.cs
│ ├── Views
│ │ ├── AboutDialog.axaml
│ │ ├── AboutDialog.axaml.cs
│ │ ├── CodeEditor.axaml
│ │ ├── CodeEditor.axaml.cs
│ │ ├── CodeLineControl.axaml
│ │ ├── CodeLineControl.axaml.cs
│ │ ├── HintDialog.axaml
│ │ ├── HintDialog.axaml.cs
│ │ ├── MainWindow.axaml
│ │ ├── MainWindow.axaml.cs
│ │ ├── OptionsDialog.axaml
│ │ └── OptionsDialog.axaml.cs
│ ├── app.manifest
│ └── packageMe.sh
├── Shrinker.Cmd
│ ├── Program.cs
│ └── Shrinker.Cmd.csproj
├── Shrinker.Lexer
│ ├── AlphaNumToken.cs
│ ├── AssignmentOperatorToken.cs
│ ├── BackslashToken.cs
│ ├── BracketToken.cs
│ ├── CommaToken.cs
│ ├── CommentTokenBase.cs
│ ├── ConstToken.cs
│ ├── DotToken.cs
│ ├── EqualityOperatorToken.cs
│ ├── FloatToken.cs
│ ├── INumberToken.cs
│ ├── IToken.cs
│ ├── IntToken.cs
│ ├── KeywordToken.cs
│ ├── Lexer.cs
│ ├── LineEndToken.cs
│ ├── MiscCharacterToken.cs
│ ├── MultiLineCommentToken.cs
│ ├── PrecisionToken.cs
│ ├── PreprocessorDefineToken.cs
│ ├── PreprocessorToken.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── QuoteToken.cs
│ ├── SemicolonToken.cs
│ ├── Shrinker.Lexer.csproj
│ ├── SingleLineCommentToken.cs
│ ├── StringExtensions.cs
│ ├── SymbolOperatorToken.cs
│ ├── SyntaxErrorException.cs
│ ├── Token.cs
│ ├── TokenExtensions.cs
│ ├── TypeToken.cs
│ ├── UniformToken.cs
│ ├── VerbatimToken.cs
│ └── WhitespaceToken.cs
├── Shrinker.Parser
│ ├── COutputFormatter.cs
│ ├── CodeHint.cs
│ ├── CustomOptions.cs
│ ├── GlslOutputFormatter.cs
│ ├── HintPriority.cs
│ ├── Hinter.cs
│ ├── Hints
│ │ ├── Hinter.AllCallsToFunctionMadeWithSameParamHint.cs
│ │ ├── Hinter.FunctionCalledWithAllConstParamsHint.cs
│ │ ├── Hinter.FunctionHasUnusedParamHint.cs
│ │ ├── Hinter.FunctionToInlineHint.cs
│ │ ├── Hinter.IntroduceDefineHint.cs
│ │ ├── Hinter.InvalidClampHint.cs
│ │ ├── Hinter.NegativePowHint.cs
│ │ ├── Hinter.NegativeSqrtHint.cs
│ │ └── Hinter.UnusedFunctionHint.cs
│ ├── Optimizations
│ │ ├── CombineAssignmentWithReturnExtension.cs
│ │ ├── CombineAssignmentWithSingleUseExtension.cs
│ │ ├── CombineConsecutiveAssignmentsExtension.cs
│ │ ├── DetectConstantsExtension.cs
│ │ ├── GolfExtensions.cs
│ │ ├── GroupVariableDeclarationsExtension.cs
│ │ ├── InlineConstantVariablesExtension.cs
│ │ ├── InlineDefinesExtension.cs
│ │ ├── IntroduceMathOperatorsExtension.cs
│ │ ├── JoinVariableDeclarationsWithAssignmentsExtension.cs
│ │ ├── MoveConstantParametersIntoCalledFunctionsExtension.cs
│ │ ├── PerformArithmeticExtension.cs
│ │ ├── RemoveCommentsExtension.cs
│ │ ├── RemoveDisabledCodeExtension.cs
│ │ ├── RemoveUnreachableCodeExtension.cs
│ │ ├── RemoveUnusedFunctionsExtension.cs
│ │ ├── RemoveUnusedVariablesExtension.cs
│ │ ├── ReplaceFunctionCallsWithResultExtension.cs
│ │ ├── SimplifyArithmeticExtension.cs
│ │ ├── SimplifyBranchingExtension.cs
│ │ ├── SimplifyFunctionDeclarationsExtension.cs
│ │ ├── SimplifyFunctionParamsExtension.cs
│ │ ├── SimplifyNumberFormat.cs
│ │ ├── SimplifyVectorConstructorsExtension.cs
│ │ ├── SimplifyVectorReferencesExtension.cs
│ │ └── TranspileToCSharpExtension.cs
│ ├── Parser.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── Shrinker.Parser.csproj
│ ├── Shrinker.cs
│ ├── StringBuilderExtensions.cs
│ └── SyntaxNodes
│ │ ├── BraceSyntaxNode.cs
│ │ ├── CommentSyntaxNodeBase.cs
│ │ ├── ExternalFunctionCallSyntaxNode.cs
│ │ ├── FileSyntaxNode.cs
│ │ ├── ForSyntaxNode.cs
│ │ ├── FunctionCallSyntaxNode.cs
│ │ ├── FunctionDeclarationSyntaxNode.cs
│ │ ├── FunctionDefinitionSyntaxNode.cs
│ │ ├── FunctionDefinitionSyntaxNodeExtensions.cs
│ │ ├── FunctionSyntaxNodeBase.cs
│ │ ├── GenericSyntaxNode.cs
│ │ ├── GlslFunctionCallSyntaxNode.cs
│ │ ├── GroupSyntaxNode.cs
│ │ ├── IRenamable.cs
│ │ ├── IStatementSyntaxNode.cs
│ │ ├── IfSyntaxNode.cs
│ │ ├── MultiLineCommentSyntaxNode.cs
│ │ ├── PragmaDefineSyntaxNode.cs
│ │ ├── PragmaIfSyntaxNode.cs
│ │ ├── ReturnSyntaxNode.cs
│ │ ├── RoundBracketSyntaxNode.cs
│ │ ├── SingleLineCommentSyntaxNode.cs
│ │ ├── SquareBracketSyntaxNode.cs
│ │ ├── StructDefinitionSyntaxNode.cs
│ │ ├── SwitchSyntaxNode.cs
│ │ ├── SyntaxNode.cs
│ │ ├── SyntaxNodeExtensions.cs
│ │ ├── VariableAssignmentSyntaxNode.cs
│ │ ├── VariableDeclarationSyntaxNode.cs
│ │ └── VerbatimLineSyntaxNode.cs
├── Shrinker.Transpile
│ ├── CmdOptions.cs
│ ├── Program.cs
│ ├── Shrinker.Transpile.csproj
│ └── Templates
│ │ └── GLSLProg.template
├── Shrinker.sln
├── Shrinker.sln.DotSettings
├── UnitTests
│ ├── Extensions
│ │ └── SyntaxNodeExtensions.cs
│ ├── FunctionDefinitionSyntaxNodeTests.cs
│ ├── GolfTests.cs
│ ├── HinterTests.cs
│ ├── LexerTests.cs
│ ├── OutputFormatterTests.cs
│ ├── ParserTests.cs
│ ├── PresetsUpdater.cs
│ ├── ProjectTests.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── ReadmeBuilder.cs
│ ├── RealFileTests.cs
│ ├── RoundBracketSyntaxNodeTests.cs
│ ├── ShrinkerTests.cs
│ ├── TestFiles
│ │ ├── Alien.glsl
│ │ ├── Bonzo.glsl
│ │ ├── ED209.glsl
│ │ ├── GolfedReference
│ │ │ ├── Alien.glsl
│ │ │ ├── Bonzo.glsl
│ │ │ ├── ED209.glsl
│ │ │ ├── Moonscape.glsl
│ │ │ ├── OceanTreasure.glsl
│ │ │ ├── OneSmallStep.glsl
│ │ │ ├── PowerStone.glsl
│ │ │ ├── Start.glsl
│ │ │ ├── Subway.glsl
│ │ │ └── Temple.glsl
│ │ ├── Moonscape.glsl
│ │ ├── OceanTreasure.glsl
│ │ ├── OneSmallStep.glsl
│ │ ├── PowerStone.glsl
│ │ ├── SimplifiedReference
│ │ │ ├── Alien.glsl
│ │ │ ├── Bonzo.glsl
│ │ │ ├── ED209.glsl
│ │ │ ├── Moonscape.glsl
│ │ │ ├── OceanTreasure.glsl
│ │ │ ├── OneSmallStep.glsl
│ │ │ ├── PowerStone.glsl
│ │ │ ├── Start.glsl
│ │ │ ├── Subway.glsl
│ │ │ └── Temple.glsl
│ │ ├── Start.glsl
│ │ ├── Subway.glsl
│ │ └── Temple.glsl
│ ├── Transpiler
│ │ ├── CastingTests.cs
│ │ ├── ConstTests.cs
│ │ ├── DeclarationTests.cs
│ │ ├── DefineTests.cs
│ │ ├── FunctionCallTests.cs
│ │ ├── FunctionDefinitionTests.cs
│ │ ├── GlslFunctionTests.cs
│ │ ├── MainVrTests.cs
│ │ ├── MatrixTests.cs
│ │ ├── StructTests.cs
│ │ ├── TranspiledOutputTests.cs
│ │ └── VectorTests.cs
│ ├── UnitTestBase.cs
│ ├── UnitTests.csproj
│ ├── VectorArithmeticTests.cs
│ └── VersionUpdater.cs
└── global.json
└── img
├── ED209.png
├── Export.png
├── Hints.png
├── Import.png
├── Shadertoy.png
└── Shrink.png
/GLSLRenderer/CmdOptions.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright (c) 2023 Dean Edis. All rights reserved.
4 | //
5 | //
6 | // This example is provided on an "as is" basis and without warranty of any kind.
7 | // Dean Edis. does not warrant or make any representations regarding the use or
8 | // results of use of this example.
9 | //
10 | // -----------------------------------------------------------------------
11 |
12 | using CommandLine;
13 | // ReSharper disable UnusedAutoPropertyAccessor.Global
14 | #pragma warning disable CS8618
15 |
16 | namespace GLSLRenderer;
17 |
18 | // ReSharper disable once ClassNeverInstantiated.Global
19 | public class CmdOptions
20 | {
21 | [Option('s', "start", Default = 10.0f, HelpText = "Start time.")]
22 | public float StartTime { get; set; }
23 |
24 | [Option('e', "end", Default = 10.0f, HelpText = "End time.")]
25 | public float EndTime { get; set; }
26 |
27 | [Option('f', "fps", Default = 1.0f, HelpText = "Frames per second.")]
28 | public float Fps { get; set; }
29 |
30 | [Option('w', "width", Default = 640, HelpText = "Output width.")]
31 | public int Width { get; set; }
32 |
33 | [Option('h', "height", Default = 320, HelpText = "Output height.")]
34 | public int Height { get; set; }
35 |
36 | [Option('o', "output", Required = true, HelpText = "Output file path.")]
37 | public string OutputPath { get; set; }
38 | }
--------------------------------------------------------------------------------
/GLSLRenderer/GLSLProgConstructor.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright (c) 2023 Dean Edis. All rights reserved.
4 | //
5 | //
6 | // This example is provided on an "as is" basis and without warranty of any kind.
7 | // Dean Edis. does not warrant or make any representations regarding the use or
8 | // results of use of this example.
9 | //
10 | // -----------------------------------------------------------------------
11 |
12 | namespace GLSLRenderer;
13 |
14 | public partial class GLSLProg
15 | {
16 | public GLSLProg(vec2 resolution, float time)
17 | : base(resolution, time)
18 | {
19 | }
20 | }
--------------------------------------------------------------------------------
/GLSLRenderer/GLSLRenderer.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net7.0
6 | enable
7 | enable
8 | false
9 | GLSL Renderer
10 | Dean Edis
11 | Dean Edis (DeanTheCoder)
12 | GLSL Renderer
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/GLSLRenderer/MatN.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright (c) 2023 Dean Edis. All rights reserved.
4 | //
5 | //
6 | // This example is provided on an "as is" basis and without warranty of any kind.
7 | // Dean Edis. does not warrant or make any representations regarding the use or
8 | // results of use of this example.
9 | //
10 | // -----------------------------------------------------------------------
11 |
12 | using System.Text;
13 |
14 | namespace GLSLRenderer;
15 |
16 | public class MatN where T : VectorBase, new()
17 | {
18 | protected readonly T[] m_columns;
19 |
20 | protected MatN(params T[] columns)
21 | {
22 | m_columns = columns.Select(o => new T { Components = o.Components.ToArray() }).ToArray();
23 | }
24 |
25 | public T this[in int i]
26 | {
27 | get => m_columns[i];
28 | set => m_columns[i] = new T { Components = value.Components.ToArray() };
29 | }
30 |
31 | // Overloads.
32 | public override string ToString()
33 | {
34 | var rowCount = m_columns.First().Components.Length;
35 | var colCount = m_columns.Length;
36 |
37 | var sb = new StringBuilder();
38 | for (var row = 0; row < rowCount; row++)
39 | {
40 | sb.Append('|');
41 |
42 | for (var col = 0; col < colCount; col++)
43 | sb.Append($" {m_columns[col][row],7:0.000}");
44 |
45 | sb.AppendLine(" |");
46 | }
47 |
48 | return sb.ToString().Trim('\n', '\r');
49 | }
50 |
51 | public override bool Equals(object? obj)
52 | {
53 | if (ReferenceEquals(null, obj))
54 | return false;
55 | if (ReferenceEquals(this, obj))
56 | return true;
57 | if (obj.GetType() != GetType())
58 | return false;
59 | return m_columns.SequenceEqual(((MatN)obj).m_columns);
60 | }
61 |
62 | public override int GetHashCode() => m_columns.GetHashCode();
63 | }
--------------------------------------------------------------------------------
/GLSLRenderer/ObjectExtensions.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright (c) 2023 Dean Edis. All rights reserved.
4 | //
5 | //
6 | // This example is provided on an "as is" basis and without warranty of any kind.
7 | // Dean Edis. does not warrant or make any representations regarding the use or
8 | // results of use of this example.
9 | //
10 | // -----------------------------------------------------------------------
11 |
12 | using System.Diagnostics.CodeAnalysis;
13 | using System.Reflection;
14 | #pragma warning disable CS8600
15 | #pragma warning disable CS8603
16 |
17 | namespace GLSLRenderer;
18 |
19 | public static class ObjectExtensions
20 | {
21 | public static T DeepClone(this T obj)
22 | {
23 | if (obj == null)
24 | throw new ArgumentNullException(nameof(obj));
25 |
26 | var type = obj.GetType();
27 |
28 | // Check for custom clone method
29 | var customCloneMethod = type.GetMethod("Clone");
30 | if (customCloneMethod != null)
31 | return (T)customCloneMethod.Invoke(obj, null);
32 |
33 | // If the type is a value type or a string, it's already deep cloned
34 | if (type.IsValueType || type == typeof(string))
35 | return obj;
36 |
37 | return DeepCloneFields(obj, type);
38 | }
39 |
40 | private static T DeepCloneFields([DisallowNull] T obj, Type type)
41 | {
42 | var clonedObject = (T)Activator.CreateInstance(type);
43 |
44 | foreach (var field in type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
45 | {
46 | var originalValue = field.GetValue(obj);
47 | var clonedValue = originalValue.DeepClone();
48 | field.SetValue(clonedObject, clonedValue);
49 | }
50 |
51 | return clonedObject;
52 | }
53 | }
--------------------------------------------------------------------------------
/GLSLRenderer/mat2.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright (c) 2023 Dean Edis. All rights reserved.
4 | //
5 | //
6 | // This example is provided on an "as is" basis and without warranty of any kind.
7 | // Dean Edis. does not warrant or make any representations regarding the use or
8 | // results of use of this example.
9 | //
10 | // -----------------------------------------------------------------------
11 |
12 | namespace GLSLRenderer;
13 |
14 | // ReSharper disable once InconsistentNaming
15 | public class mat2 : MatN
16 | {
17 | public mat2()
18 | : this(0, 0, 0, 0)
19 | {
20 | }
21 |
22 | public mat2(float a)
23 | : this(a, 0, 0, a)
24 | {
25 | }
26 |
27 | public mat2(params float[] a)
28 | : base(new vec2(a[0], a[1]), new vec2(a[2], a[3]))
29 | {
30 | }
31 |
32 | public mat2(vec2 c1, vec2 c2)
33 | : this(c1.x, c1.y, c2.x, c2.y)
34 | {
35 | }
36 |
37 | public mat2 Clone() => new(m_columns.SelectMany(o => o.Components).ToArray());
38 | }
--------------------------------------------------------------------------------
/GLSLRenderer/mat3.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright (c) 2023 Dean Edis. All rights reserved.
4 | //
5 | //
6 | // This example is provided on an "as is" basis and without warranty of any kind.
7 | // Dean Edis. does not warrant or make any representations regarding the use or
8 | // results of use of this example.
9 | //
10 | // -----------------------------------------------------------------------
11 |
12 | namespace GLSLRenderer;
13 |
14 | // ReSharper disable once InconsistentNaming
15 | public class mat3 : MatN
16 | {
17 | public mat3()
18 | : this(0, 0, 0, 0, 0, 0, 0, 0, 0)
19 | {
20 | }
21 |
22 | public mat3(float a)
23 | : this(a, 0, 0, 0, a, 0, 0, 0, a)
24 | {
25 | }
26 |
27 | public mat3(params float[] a)
28 | : base(new vec3(a[0], a[1], a[2]), new vec3(a[3], a[4], a[5]), new vec3(a[6], a[7], a[8]))
29 | {
30 | }
31 |
32 | public mat3(vec3 c1, vec3 c2, vec3 c3)
33 | : this(c1.x, c1.y, c1.z, c2.x, c2.y, c2.z, c3.x, c3.y, c3.z)
34 | {
35 | }
36 |
37 | public mat3 Clone() => new(m_columns.SelectMany(o => o.Components).ToArray());
38 | }
--------------------------------------------------------------------------------
/GLSLRenderer/mat4.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright (c) 2023 Dean Edis. All rights reserved.
4 | //
5 | //
6 | // This example is provided on an "as is" basis and without warranty of any kind.
7 | // Dean Edis. does not warrant or make any representations regarding the use or
8 | // results of use of this example.
9 | //
10 | // -----------------------------------------------------------------------
11 |
12 | namespace GLSLRenderer;
13 |
14 | // ReSharper disable once InconsistentNaming
15 | public class mat4 : MatN
16 | {
17 | public mat4()
18 | : this(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
19 | {
20 | }
21 |
22 | public mat4(float a)
23 | : this(a, 0, 0, 0, 0, a, 0, 0, 0, 0, a, 0, 0, 0, 0, a)
24 | {
25 | }
26 |
27 | public mat4(params float[] a)
28 | : base(new vec4(a[0], a[1], a[2], a[3]), new vec4(a[4], a[5], a[6], a[7]), new vec4(a[8], a[9], a[10], a[11]), new vec4(a[12], a[13], a[14], a[15]))
29 | {
30 | }
31 |
32 | public mat4(vec4 c1, vec4 c2, vec4 c3, vec4 c4)
33 | : this(c1.x, c1.y, c1.z, c1.w, c2.x, c2.y, c2.z, c2.w, c3.x, c3.y, c3.z, c3.w, c4.x, c4.y, c4.z, c4.w)
34 | {
35 | }
36 |
37 | public mat4 Clone() => new(m_columns.SelectMany(o => o.Components).ToArray());
38 | }
--------------------------------------------------------------------------------
/GLSLRenderer/vec2.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright (c) 2023 Dean Edis. All rights reserved.
4 | //
5 | //
6 | // This example is provided on an "as is" basis and without warranty of any kind.
7 | // Dean Edis. does not warrant or make any representations regarding the use or
8 | // results of use of this example.
9 | //
10 | // -----------------------------------------------------------------------
11 |
12 | namespace GLSLRenderer;
13 |
14 | // ReSharper disable once InconsistentNaming
15 | public class vec2 : VectorBase
16 | {
17 | public vec2(VectorBase v)
18 | : this(v.Components)
19 | {
20 | }
21 |
22 | public vec2(VectorBase v, params float[] f) : this(v.Components.Concat(f).ToArray())
23 | {
24 | }
25 |
26 | public vec2(params float[] f)
27 | : base(2, f)
28 | {
29 | }
30 |
31 | public vec2(float f)
32 | : this(f, f)
33 | {
34 | }
35 |
36 | public vec2()
37 | : this(0.0f)
38 | {
39 | }
40 |
41 | public static vec2 operator -(vec2 v) => new(-v.x, -v.y);
42 |
43 | public static vec2 operator -(vec2 v1, vec2 v2) => new(v1.Sub(v2));
44 | public static vec2 operator -(float v1, vec2 v2) => new(new vec2(v1).Sub(v2));
45 | public static vec2 operator -(vec2 v1, float v2) => new(v1.Sub(v2));
46 | public static vec2 operator +(vec2 v1, vec2 v2) => new(v1.x + v2.x, v1.y + v2.y);
47 | public static vec2 operator +(float v1, vec2 v2) => v2 + v1;
48 | public static vec2 operator +(vec2 v1, float v2) => new(v1.x + v2, v1.y + v2);
49 | public static vec2 operator /(vec2 v1, vec2 v2) => new(v1.Div(v2));
50 | public static vec2 operator /(float v1, vec2 v2) => new(new vec2(v1).Div(v2));
51 | public static vec2 operator /(vec2 v1, float v2) => new(v1.Div(v2));
52 | public static vec2 operator *(vec2 v1, vec2 v2) => new(v1.Mul(v2));
53 | public static vec2 operator *(float v1, vec2 v2) => new(new vec2(v1).Mul(v2));
54 | public static vec2 operator *(vec2 v1, float v2) => new(v1.Mul(v2));
55 | public static vec2 operator *(vec2 v, mat2 m) =>
56 | new(
57 | v.x * m[0].x + v.y * m[0].y,
58 | v.x * m[1].x + v.y * m[1].y
59 | );
60 |
61 | public vec2 Clone() => new(Components);
62 | }
--------------------------------------------------------------------------------
/GLSLRenderer/vec3.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright (c) 2023 Dean Edis. All rights reserved.
4 | //
5 | //
6 | // This example is provided on an "as is" basis and without warranty of any kind.
7 | // Dean Edis. does not warrant or make any representations regarding the use or
8 | // results of use of this example.
9 | //
10 | // -----------------------------------------------------------------------
11 |
12 | namespace GLSLRenderer;
13 |
14 | // ReSharper disable once InconsistentNaming
15 | public class vec3 : VectorBase
16 | {
17 | public vec3(VectorBase v)
18 | : this(v.Components)
19 | {
20 | }
21 |
22 | public vec3(VectorBase v, params float[] f) : this(v.Components.Concat(f).ToArray())
23 | {
24 | }
25 |
26 | public vec3(params float[] f)
27 | : base(3, f)
28 | {
29 | }
30 |
31 | public vec3(float f)
32 | : this(f, f, f)
33 | {
34 | }
35 |
36 | public vec3()
37 | : this(0)
38 | {
39 | }
40 |
41 | public static vec3 operator -(vec3 v) => new(-v.x, -v.y, -v.z);
42 |
43 | public static vec3 operator -(vec3 v1, vec3 v2) => new(v1.Sub(v2));
44 | public static vec3 operator -(float v1, vec3 v2) => new(new vec3(v1).Sub(v2));
45 | public static vec3 operator -(vec3 v1, float v2) => new(v1.Sub(v2));
46 | public static vec3 operator +(vec3 v1, vec3 v2) => new(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z);
47 | public static vec3 operator +(float v1, vec3 v2) => v2 + v1;
48 | public static vec3 operator +(vec3 v1, float v2) => new(v1.x + v2, v1.y + v2, v1.z + v2);
49 | public static vec3 operator /(vec3 v1, vec3 v2) => new(v1.Div(v2));
50 | public static vec3 operator /(float v1, vec3 v2) => new(new vec3(v1).Div(v2));
51 | public static vec3 operator /(vec3 v1, float v2) => new(v1.Div(v2));
52 | public static vec3 operator *(vec3 v1, vec3 v2) => new(v1.Mul(v2));
53 | public static vec3 operator *(float v1, vec3 v2) => new(new vec3(v1).Mul(v2));
54 | public static vec3 operator *(vec3 v1, float v2) => new(v1.Mul(v2));
55 |
56 | public vec3 Clone() => new(Components);
57 | }
--------------------------------------------------------------------------------
/GLSLRenderer/vec4.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright (c) 2023 Dean Edis. All rights reserved.
4 | //
5 | //
6 | // This example is provided on an "as is" basis and without warranty of any kind.
7 | // Dean Edis. does not warrant or make any representations regarding the use or
8 | // results of use of this example.
9 | //
10 | // -----------------------------------------------------------------------
11 |
12 | namespace GLSLRenderer;
13 |
14 | // ReSharper disable once InconsistentNaming
15 | public class vec4 : VectorBase
16 | {
17 | public vec4(VectorBase v)
18 | : this(v.Components)
19 | {
20 | }
21 |
22 | public vec4(VectorBase v, params float[] f) : this(v.Components.Concat(f).ToArray())
23 | {
24 | }
25 |
26 | public vec4(params float[] f)
27 | : base(4, f)
28 | {
29 | }
30 |
31 | public vec4(float f)
32 | : this(f, f, f, f)
33 | {
34 | }
35 |
36 | public vec4()
37 | : this(0.0f)
38 | {
39 | }
40 |
41 | public vec4(vec3 v, float w)
42 | : this(v[0], v[1], v[2], w)
43 | {
44 | }
45 |
46 | public static vec4 operator -(vec4 v) => new(-v.x, -v.y, -v.z, -v.w);
47 |
48 | public static vec4 operator -(vec4 v1, vec4 v2) => new(v1.Sub(v2));
49 | public static vec4 operator -(float v1, vec4 v2) => new(new vec4(v1).Sub(v2));
50 | public static vec4 operator -(vec4 v1, float v2) => new(v1.Sub(v2));
51 | public static vec4 operator +(vec4 v1, vec4 v2) => new(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z, v1.w + v2.w);
52 | public static vec4 operator +(float v1, vec4 v2) => v2 + v1;
53 | public static vec4 operator +(vec4 v1, float v2) => new(v1.x + v2, v1.y + v2, v1.z + v2, v1.w + v2);
54 | public static vec4 operator /(vec4 v1, vec4 v2) => new(v1.Div(v2));
55 | public static vec4 operator /(float v1, vec4 v2) => new(new vec4(v1).Div(v2));
56 | public static vec4 operator /(vec4 v1, float v2) => new(v1.Div(v2));
57 | public static vec4 operator *(vec4 v1, vec4 v2) => new(v1.Mul(v2));
58 | public static vec4 operator *(float v1, vec4 v2) => new(new vec4(v1).Mul(v2));
59 | public static vec4 operator *(vec4 v1, float v2) => new(v1.Mul(v2));
60 |
61 | public vec4 Clone() => new(Components);
62 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 deanthecoder
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/ShaderShrinker/InnoSetupProject/InstallScript.iss:
--------------------------------------------------------------------------------
1 | #define MyAppName "GLSL Shader Shrinker"
2 | #define MyAppExeName "Shrinker.Avalonia.exe"
3 |
4 | [Setup]
5 | AppId={{996B4B28-98DA-451F-ED15-8777E28DBDE4}
6 | AppName={#MyAppName}
7 | AppVersion=2.1
8 | AppPublisher=Dean Edis
9 | AppPublisherURL=https://github.com/deanthecoder/GLSLShaderShrinker
10 | DefaultDirName={commonpf}\ShaderShrinker
11 | DefaultGroupName={#MyAppName}
12 | UninstallDisplayIcon={app}\Inno_Setup_Project.exe
13 | Compression=lzma2
14 | SolidCompression=yes
15 | SourceDir=..\Shrinker.Avalonia\
16 | OutputDir=..\InnoSetupProject\
17 | OutputBaseFilename={#MyAppName} Installer
18 |
19 | [Tasks]
20 | Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
21 |
22 | [Files]
23 | Source: "bin\Release\net7.0\publish\win-x64\*.*"; DestDir: "{app}"; Excludes: "*.pdb"; Flags: ignoreversion
24 | Source: "bin\Release\net7.0\publish\win-x64\Presets\*.*"; DestDir: "{app}\Presets"; Flags: ignoreversion
25 |
26 | [Icons]
27 | Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
28 | Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
29 |
30 | [Run]
31 | Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent
32 |
--------------------------------------------------------------------------------
/ShaderShrinker/Shrinker.Avalonia/App.axaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Avalonia;
3 | using Avalonia.Controls.ApplicationLifetimes;
4 | using Avalonia.Markup.Xaml;
5 | using Shrinker.Avalonia.ViewModels;
6 | using Shrinker.Avalonia.Views;
7 |
8 | namespace Shrinker.Avalonia;
9 |
10 | public class App : Application
11 | {
12 | public App()
13 | {
14 | DataContext = new AppViewModel();
15 | }
16 |
17 | public override void Initialize() => AvaloniaXamlLoader.Load(this);
18 |
19 | public override void OnFrameworkInitializationCompleted()
20 | {
21 | if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
22 | {
23 | desktop.MainWindow = new MainWindow
24 | {
25 | DataContext = new MainWindowViewModel()
26 | };
27 |
28 | desktop.MainWindow.Closed += (_, _) =>
29 | {
30 | ((IDisposable)desktop.MainWindow.DataContext).Dispose();
31 | UserSettings.Instance.Dispose();
32 | };
33 | }
34 |
35 | base.OnFrameworkInitializationCompleted();
36 | }
37 | }
--------------------------------------------------------------------------------
/ShaderShrinker/Shrinker.Avalonia/Assets/App.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deanthecoder/GLSLShaderShrinker/1f1ff6f1de6112bc5ee62ce9abda02cdab79f2aa/ShaderShrinker/Shrinker.Avalonia/Assets/App.ico
--------------------------------------------------------------------------------
/ShaderShrinker/Shrinker.Avalonia/Assets/Icon.icns:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deanthecoder/GLSLShaderShrinker/1f1ff6f1de6112bc5ee62ce9abda02cdab79f2aa/ShaderShrinker/Shrinker.Avalonia/Assets/Icon.icns
--------------------------------------------------------------------------------
/ShaderShrinker/Shrinker.Avalonia/Commands/ClipboardCommand.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright (c) 2023 Dean Edis. All rights reserved.
4 | //
5 | //
6 | // This example is provided on an "as is" basis and without warranty of any kind.
7 | // Dean Edis. does not warrant or make any representations regarding the use or
8 | // results of use of this example.
9 | //
10 | // -----------------------------------------------------------------------
11 |
12 | using System;
13 | using Avalonia.Threading;
14 | using TextCopy;
15 |
16 | namespace Shrinker.Avalonia.Commands;
17 |
18 | ///
19 | /// Continuously monitors the clipboard, enabling the command if it contains non-empty content.
20 | ///
21 | public class ClipboardCommand : RelayCommand
22 | {
23 | public ClipboardCommand(Action