James Peret vor 2 Jahren
Commit
c88a3d0585

+ 71 - 0
.gitignore

@@ -0,0 +1,71 @@
+# This .gitignore file should be placed at the root of your Unity project directory
+#
+# Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore
+#
+/[Ll]ibrary/
+/[Tt]emp/
+/[Oo]bj/
+/[Bb]uild/
+/[Bb]uilds/
+/[Ll]ogs/
+/[Uu]ser[Ss]ettings/
+
+# MemoryCaptures can get excessive in size.
+# They also could contain extremely sensitive data
+/[Mm]emoryCaptures/
+
+# Asset meta data should only be ignored when the corresponding asset is also ignored
+!/[Aa]ssets/**/*.meta
+
+# Uncomment this line if you wish to ignore the asset store tools plugin
+# /[Aa]ssets/AssetStoreTools*
+
+# Autogenerated Jetbrains Rider plugin
+/[Aa]ssets/Plugins/Editor/JetBrains*
+
+# Visual Studio cache directory
+.vs/
+
+# Gradle cache directory
+.gradle/
+
+# Autogenerated VS/MD/Consulo solution and project files
+ExportedObj/
+.consulo/
+*.csproj
+*.unityproj
+*.sln
+*.suo
+*.tmp
+*.user
+*.userprefs
+*.pidb
+*.booproj
+*.svd
+*.pdb
+*.mdb
+*.opendb
+*.VC.db
+
+# Unity3D generated meta files
+*.pidb.meta
+*.pdb.meta
+*.mdb.meta
+
+# Unity3D generated file on crash reports
+sysinfo.txt
+
+# Builds
+*.apk
+*.aab
+*.unitypackage
+
+# Crashlytics generated file
+crashlytics-build.properties
+
+# Packed Addressables
+/[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin*
+
+# Temporary auto-generated Android Assets
+/[Aa]ssets/[Ss]treamingAssets/aa.meta
+/[Aa]ssets/[Ss]treamingAssets/aa/*

+ 8 - 0
Runtime.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 9463b8e2b4d6d3247b27a720c242d678
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 17 - 0
Runtime/KairoEngine.NoiseUtilities.asmdef

@@ -0,0 +1,17 @@
+{
+    "name": "KairoEngine.NoiseUtilities",
+    "rootNamespace": "",
+    "references": [
+        "GUID:7e5ae6a38d1532248b4c890eca668b06",
+        "GUID:e048eeec9bdb9d30448017b829deb3f6"
+    ],
+    "includePlatforms": [],
+    "excludePlatforms": [],
+    "allowUnsafeCode": false,
+    "overrideReferences": false,
+    "precompiledReferences": [],
+    "autoReferenced": true,
+    "defineConstraints": [],
+    "versionDefines": [],
+    "noEngineReferences": false
+}

+ 7 - 0
Runtime/KairoEngine.NoiseUtilities.asmdef.meta

@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: d09ad6089c871be4581e7b220db144be
+AssemblyDefinitionImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 69 - 0
Runtime/NoiseCombinator.cs

@@ -0,0 +1,69 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using Sirenix.OdinInspector;
+
+namespace KairoEngine.NoiseUtilities
+{
+    [System.Serializable]
+    public class NoiseCombinator
+    {
+        [PreviewField(256, ObjectFieldAlignment.Center), HideLabel, PropertyOrder(0)]
+        public Texture2D texture;
+        [PropertyOrder(2), OnCollectionChanged("Before", "After"), OnInspectorInit("After")] public List<NoiseGenerator> generators = new List<NoiseGenerator>();
+        [PropertyOrder(3), HideInInspector] public Vector2Int size = new Vector2Int(128, 128);
+
+        public float SamplePoint(float x, float y)
+        {
+            float value = 0;
+            for (int i = 0; i < generators.Count; i++)
+            {
+                switch (generators[i].blending)
+                {
+                    case NoiseBlendingModes.Blend:
+                        value = BlendSubpixel(value, generators[i].SamplePoint(x, y), 1, 1f - generators[i].opacity);
+                        break;
+                    case NoiseBlendingModes.Addictive:
+                        value += generators[i].SamplePoint(x, y) * generators[i].opacity;
+                        break;
+                    case NoiseBlendingModes.Subtractive:
+                        value -= generators[i].SamplePoint(x, y) * generators[i].opacity;
+                        break;
+                }
+                value = Mathf.Clamp(value, 0, 1f);
+                
+            }
+            return value;
+        }
+
+        //[Button("Preview"), PropertyOrder(1)]
+        public void GenerateTexture()
+        {
+            texture = new Texture2D(size.x, size.y);
+            for (int x = 0; x < size.x; x++)
+            {
+                for (int y = 0; y < size.y; y++)
+                {
+                    float xCoord = (((float)x / size.x));
+                    float yCoord = (((float)y / size.y));
+                    float sample = SamplePoint(xCoord, yCoord);
+                    Color color = new Color(sample, sample, sample);
+                    texture.SetPixel(x, y, color);
+                }
+            }
+            texture.Apply();
+        }
+
+        static float BlendSubpixel(float top, float bottom, float alphaTop, float alphaBottom){
+            return (top * alphaTop) + ( (bottom-1f) * (alphaBottom-alphaTop) );
+        }
+
+        public void Before() { }
+
+        public void After() 
+        {
+            for (int i = 0; i < generators.Count; i++) generators[i].OnChangeDelegate = GenerateTexture;
+            GenerateTexture();
+        }
+    }
+}

+ 11 - 0
Runtime/NoiseCombinator.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: f7fe172f7d19f6041a1615bc1d68ed73
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 73 - 0
Runtime/NoiseGenerator.cs

@@ -0,0 +1,73 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using Sirenix.OdinInspector;
+
+namespace KairoEngine.NoiseUtilities
+{
+    public enum NoiseBlendingModes
+    {
+        Blend,
+        Addictive,
+        Subtractive
+    }
+
+    [System.Serializable]
+    public class NoiseGenerator
+    {
+        [HorizontalGroup("Slpit", 80, MarginRight = 15), VerticalGroup("Slpit/Preview"), PreviewField(80, ObjectFieldAlignment.Left), HideLabel]
+        public Texture2D texture;
+        [HorizontalGroup("Slpit"), VerticalGroup("Slpit/Config"), LabelWidth(80), OnValueChanged("OnChange")] public float scale = 1f;
+        [HorizontalGroup("Slpit"), VerticalGroup("Slpit/Config"), LabelWidth(80), OnValueChanged("OnChange")] public Vector2 offset = new Vector2();
+        [HorizontalGroup("Slpit"), VerticalGroup("Slpit/Config"), LabelWidth(80), Range(0, 1f), OnValueChanged("OnChange")] public float opacity = 1f;
+        [HorizontalGroup("Slpit"), VerticalGroup("Slpit/Config"), LabelWidth(80), OnValueChanged("OnChange")] public NoiseBlendingModes blending = NoiseBlendingModes.Blend;
+        [HorizontalGroup("Slpit"), VerticalGroup("Slpit/Config"), LabelWidth(80), HideInInspector] public Vector2Int size = new Vector2Int(128, 128);
+
+        [HideInInspector] public System.Action OnChangeDelegate;
+
+        public NoiseGenerator()
+        {
+            this.size = new Vector2Int(128, 128);;
+            this.scale = 1f;
+            this.offset = new Vector2();
+            this.opacity = 1f;
+            GenerateTexture();
+        }
+
+        public float SamplePoint(float x, float y)
+        {
+            float xCoord = (x * scale) + offset.x;
+            float yCoord = (y * scale) + offset.y;
+            return Mathf.PerlinNoise(xCoord, yCoord);
+        }
+
+        public float SamplePixel(int x, int y)
+        {
+            float xCoord = (((float)x / size.x) * scale) + offset.x;
+            float yCoord = (((float)y / size.y) * scale) + offset.y;
+            return Mathf.PerlinNoise(xCoord, yCoord);
+        }
+
+        //[HorizontalGroup("Slpit"), VerticalGroup("Slpit/Preview"), Button("Preview")]
+        public void GenerateTexture()
+        {
+            texture = new Texture2D(size.x, size.y);
+            for (int x = 0; x < size.x; x++)
+            {
+                for (int y = 0; y < size.y; y++)
+                {
+                    float sample = SamplePixel(x, y);
+                    Color color = new Color(sample, sample, sample);
+                    texture.SetPixel(x, y, color);
+                }
+            }
+            texture.Apply();
+        }
+
+        private void OnChange()
+        {
+            GenerateTexture();
+            if(OnChangeDelegate != null) OnChangeDelegate();
+        }
+    }
+}

+ 11 - 0
Runtime/NoiseGenerator.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 2efc598233bed6d4c87745d1e8d2b9ad
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: