├── .gitignore ├── LICENSE ├── README.md ├── Unity CJ Lib ├── Assets │ ├── CjLib.meta │ ├── CjLib │ │ ├── Script.meta │ │ ├── Script │ │ │ ├── Collection.meta │ │ │ ├── Collection │ │ │ │ ├── CollectionUtil.cs │ │ │ │ └── CollectionUtil.cs.meta │ │ │ ├── Debug.meta │ │ │ ├── Debug │ │ │ │ ├── Components.meta │ │ │ │ ├── Components │ │ │ │ │ ├── DrawArc.cs │ │ │ │ │ ├── DrawArc.cs.meta │ │ │ │ │ ├── DrawArrow.cs │ │ │ │ │ ├── DrawArrow.cs.meta │ │ │ │ │ ├── DrawArrowEditor.cs │ │ │ │ │ ├── DrawArrowEditor.cs.meta │ │ │ │ │ ├── DrawBase.cs │ │ │ │ │ ├── DrawBase.cs.meta │ │ │ │ │ ├── DrawBox.cs │ │ │ │ │ ├── DrawBox.cs.meta │ │ │ │ │ ├── DrawCircle.cs │ │ │ │ │ ├── DrawCircle.cs.meta │ │ │ │ │ ├── DrawLine.cs │ │ │ │ │ ├── DrawLine.cs.meta │ │ │ │ │ ├── DrawLineEditor.cs │ │ │ │ │ ├── DrawLineEditor.cs.meta │ │ │ │ │ ├── DrawSphere.cs │ │ │ │ │ └── DrawSphere.cs.meta │ │ │ │ ├── DebugUtil.cs │ │ │ │ ├── DebugUtil.cs.meta │ │ │ │ ├── GizmosUtil.cs │ │ │ │ ├── GizmosUtil.cs.meta │ │ │ │ ├── PrimitiveMeshFactory.cs │ │ │ │ └── PrimitiveMeshFactory.cs.meta │ │ │ ├── Math.meta │ │ │ ├── Math │ │ │ │ ├── LatexFormula.cs │ │ │ │ ├── LatexFormula.cs.meta │ │ │ │ ├── MathUtil.cs │ │ │ │ ├── MathUtil.cs.meta │ │ │ │ ├── NumericSpring.cs │ │ │ │ ├── NumericSpring.cs.meta │ │ │ │ ├── QuaternionUtil.cs │ │ │ │ ├── QuaternionUtil.cs.meta │ │ │ │ ├── VectorUtil.cs │ │ │ │ └── VectorUtil.cs.meta │ │ │ ├── Noise.meta │ │ │ ├── Noise │ │ │ │ ├── ClassicNoise.cs │ │ │ │ ├── ClassicNoise.cs.meta │ │ │ │ ├── ClassicNoisePeriodic.cs │ │ │ │ ├── ClassicNoisePeriodic.cs.meta │ │ │ │ ├── NoiseCommon.cs │ │ │ │ ├── NoiseCommon.cs.meta │ │ │ │ ├── RandomNoise.cs │ │ │ │ ├── RandomNoise.cs.meta │ │ │ │ ├── RandomNoiseVector.cs │ │ │ │ ├── RandomNoiseVector.cs.meta │ │ │ │ ├── SimplexNoise.cs │ │ │ │ ├── SimplexNoise.cs.meta │ │ │ │ ├── SimplexNoiseGradient.cs │ │ │ │ └── SimplexNoiseGradient.cs.meta │ │ │ ├── Physics.meta │ │ │ ├── Physics │ │ │ │ ├── Collision.cs │ │ │ │ └── Collision.cs.meta │ │ │ ├── Util.meta │ │ │ └── Util │ │ │ │ ├── ConditionalFieldAttribute.cs │ │ │ │ ├── ConditionalFieldAttribute.cs.meta │ │ │ │ ├── ConditionalFieldAttributeDrawer.cs │ │ │ │ └── ConditionalFieldAttributeDrawer.cs.meta │ │ ├── Shader.meta │ │ └── Shader │ │ │ ├── Debug.meta │ │ │ ├── Debug │ │ │ ├── Primitive.shader │ │ │ ├── Primitive.shader.meta │ │ │ ├── PrimitiveCore.cginc │ │ │ ├── PrimitiveCore.cginc.meta │ │ │ ├── PrimitiveNoZTest.shader │ │ │ └── PrimitiveNoZTest.shader.meta │ │ │ ├── Math.meta │ │ │ ├── Math │ │ │ ├── CatmullRom.cginc │ │ │ ├── CatmullRom.cginc.meta │ │ │ ├── Color.cginc │ │ │ ├── Color.cginc.meta │ │ │ ├── Math.cginc │ │ │ ├── Math.cginc.meta │ │ │ ├── Quaternion.cginc │ │ │ ├── Quaternion.cginc.meta │ │ │ ├── Vector.cginc │ │ │ └── Vector.cginc.meta │ │ │ ├── Noise.meta │ │ │ ├── Noise │ │ │ ├── ClassicNoise2D.cginc │ │ │ ├── ClassicNoise2D.cginc.meta │ │ │ ├── ClassicNoise3D.cginc │ │ │ ├── ClassicNoise3D.cginc.meta │ │ │ ├── Noise.cginc │ │ │ ├── Noise.cginc.meta │ │ │ ├── NoiseCommon.cginc │ │ │ ├── NoiseCommon.cginc.meta │ │ │ ├── RandomNoise.cginc │ │ │ ├── RandomNoise.cginc.meta │ │ │ ├── Resources.meta │ │ │ ├── Resources │ │ │ │ ├── ClassicNoiseCs.compute │ │ │ │ ├── ClassicNoiseCs.compute.meta │ │ │ │ ├── ClassicNoisePeriodicCs.compute │ │ │ │ ├── ClassicNoisePeriodicCs.compute.meta │ │ │ │ ├── RandomNoiseCs.compute │ │ │ │ ├── RandomNoiseCs.compute.meta │ │ │ │ ├── RandomNoiseVectorCs.compute │ │ │ │ ├── RandomNoiseVectorCs.compute.meta │ │ │ │ ├── SimplexNoiseCs.compute │ │ │ │ ├── SimplexNoiseCs.compute.meta │ │ │ │ ├── SimplexNoiseGradientCs.compute │ │ │ │ └── SimplexNoiseGradientCs.compute.meta │ │ │ ├── SimplexNoise2D.cginc │ │ │ ├── SimplexNoise2D.cginc.meta │ │ │ ├── SimplexNoise3D.cginc │ │ │ └── SimplexNoise3D.cginc.meta │ │ │ ├── Physics.meta │ │ │ ├── Physics │ │ │ ├── Physics.cginc │ │ │ └── Physics.cginc.meta │ │ │ ├── Render.meta │ │ │ └── Render │ │ │ ├── Forward.cginc │ │ │ └── Forward.cginc.meta │ ├── Example.meta │ └── Example │ │ ├── Debug Draw Components.meta │ │ ├── Debug Draw Components │ │ ├── Debug Draw Components.unity │ │ └── Debug Draw Components.unity.meta │ │ ├── Debug Draw Meshes.meta │ │ ├── Debug Draw Meshes │ │ ├── CjLibDebugUtilDemo.cs │ │ ├── CjLibDebugUtilDemo.cs.meta │ │ ├── Debug Draw Meshes.unity │ │ ├── Debug Draw Meshes.unity.meta │ │ ├── GizmosUtilDemoComponent.cs │ │ └── GizmosUtilDemoComponent.cs.meta │ │ ├── GPU Particles with Colliders.meta │ │ ├── GPU Particles with Colliders │ │ ├── GPU Particles with Colliders.unity │ │ ├── GPU Particles with Colliders.unity.meta │ │ ├── Main.cs │ │ ├── Main.cs.meta │ │ ├── Particle.mat │ │ ├── Particle.mat.meta │ │ ├── Particle.shader │ │ ├── Particle.shader.meta │ │ ├── ParticleCore.cginc │ │ ├── ParticleCore.cginc.meta │ │ ├── ParticleLogic.compute │ │ ├── ParticleLogic.compute.meta │ │ ├── ParticleStruct.cginc │ │ ├── ParticleStruct.cginc.meta │ │ ├── Plane.prefab │ │ ├── Plane.prefab.meta │ │ ├── Sphere.mat │ │ ├── Sphere.mat.meta │ │ ├── Sphere.prefab │ │ └── Sphere.prefab.meta │ │ ├── Noise Fragment Shader.meta │ │ ├── Noise Fragment Shader │ │ ├── NoiseFragmentShaderTest.cs │ │ ├── NoiseFragmentShaderTest.cs.meta │ │ ├── NoiseFragmentShaderTest.shader │ │ ├── NoiseFragmentShaderTest.shader.meta │ │ ├── NoiseFragmentShaderTest.unity │ │ └── NoiseFragmentShaderTest.unity.meta │ │ ├── Noise GPU Compute And CPU.meta │ │ ├── Noise GPU Compute And CPU │ │ ├── Noise Gpu Compute And Cpu.unity │ │ ├── Noise Gpu Compute And Cpu.unity.meta │ │ ├── NoiseGpuComputeAndCpuTest.cs │ │ └── NoiseGpuComputeAndCpuTest.cs.meta │ │ ├── Quaternion Integration Comparison.meta │ │ ├── Quaternion Integration Comparison │ │ ├── Main.cs │ │ ├── Main.cs.meta │ │ ├── Quaternion Integration Comparison.unity │ │ └── Quaternion Integration Comparison.unity.meta │ │ ├── Quaternion Swing Twist Decomposition.meta │ │ ├── Quaternion Swing Twist Decomposition │ │ ├── Quaternion Swing Twist Decomposition.unity │ │ ├── Quaternion Swing Twist Decomposition.unity.meta │ │ ├── QuaternionSwingTwistDecompositionDemo.cs │ │ └── QuaternionSwingTwistDecompositionDemo.cs.meta │ │ ├── Turbulent Rainbow GPU Particles.meta │ │ └── Turbulent Rainbow GPU Particles │ │ ├── Main.cs │ │ ├── Main.cs.meta │ │ ├── Particle.shader │ │ ├── Particle.shader.meta │ │ ├── ParticleCore.cginc │ │ ├── ParticleCore.cginc.meta │ │ ├── ParticleCoreWithForwardPass.cginc │ │ ├── ParticleCoreWithForwardPass.cginc.meta │ │ ├── ParticleLogic.compute │ │ ├── ParticleLogic.compute.meta │ │ ├── ParticleStruct.cginc │ │ ├── ParticleStruct.cginc.meta │ │ ├── ParticleWithForwardPass.shader │ │ ├── ParticleWithForwardPass.shader.meta │ │ ├── Turbulent Rainbow GPU Particles.unity │ │ └── Turbulent Rainbow GPU Particles.unity.meta ├── Packages │ └── manifest.json └── ProjectSettings │ ├── AudioManager.asset │ ├── ClusterInputManager.asset │ ├── DynamicsManager.asset │ ├── EditorBuildSettings.asset │ ├── EditorSettings.asset │ ├── GraphicsSettings.asset │ ├── InputManager.asset │ ├── NavMeshAreas.asset │ ├── NetworkManager.asset │ ├── Physics2DSettings.asset │ ├── PresetManager.asset │ ├── ProjectSettings.asset │ ├── ProjectVersion.txt │ ├── QualitySettings.asset │ ├── TagManager.asset │ ├── TimeManager.asset │ └── UnityConnectSettings.asset └── img ├── gpu-particles-with-primitive-collider-physics.gif └── turbulent-rainbow-cubes.gif /.gitignore: -------------------------------------------------------------------------------- 1 | Unity CJ Lib/[Ll]ibrary/ 2 | Unity CJ Lib/[Dd]ebug/ 3 | Unity CJ Lib/[Tt]emp/ 4 | Unity CJ Lib/[Oo]bj/ 5 | Unity CJ Lib/[Bb]uild/ 6 | Unity CJ Lib/[Bb]uilds/ 7 | Unity CJ Lib/Assets/FrameCapturer 8 | Unity CJ Lib/Assets/AssetStoreTools* 9 | Unity CJ Lib/Logs/ 10 | Unity CJ Lib/ProjectSettings 11 | Unity CJ Lib/.vs/ 12 | bin/ 13 | 14 | # Autogenerated VS/MD/Consulo solution and project files 15 | ExportedObj/ 16 | .consulo/ 17 | *.csproj 18 | *.unityproj 19 | *.sln 20 | *.suo 21 | *.tmp 22 | *.user 23 | *.userprefs 24 | *.pidb 25 | *.booproj 26 | *.svd 27 | *.pdb 28 | 29 | # Unity3D generated meta files 30 | *.pidb.meta 31 | 32 | # Unity3D Generated File On Crash Reports 33 | sysinfo.txt 34 | 35 | # Builds 36 | *.unitypackage 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Allen Chou 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## CJ Lib - Utility Library for Unity 2 | by **Ming-Lun "Allen" Chou** / [AllenChou.net](http://AllenChou.net) / [@TheAllenChou](http://twitter.com/TheAllenChou) / [Patreon](https://www.patreon.com/TheAllenChou) 3 | 4 | ![turbulent-rainbow-cubes](/img/turbulent-rainbow-cubes.gif) ![gpu-particles-with-primitive-collider-physics](/img/gpu-particles-with-primitive-collider-physics.gif) 5 | 6 | CJ Lib is a constant work in progress. 7 | 8 | This library is meant to provide various script utilities to aid in Unity development. 9 | 10 | If you use CJ Lib in your work, directly or via modification, credits and link-backs are highly appreciated. 11 | 12 | ---- 13 | ### Math 14 | 15 | Utilities and extensions to Unity's existing math library, including vectors, quaternions, etc. 16 | 17 | 18 | ---- 19 | ### Physics 20 | 21 | Shader functions for primitive collider physics. 22 | 23 | 24 | ---- 25 | ### Noise 26 | 27 | Shader functions for noise generation, including: 28 | * Classic Perlin noise 29 | * Periodic classic Perlin noise 30 | * Random noise 31 | * Random vector noise 32 | * Simplex noise 33 | * Simplex noise gradient 34 | 35 | CPU variant coming soon. 36 | Classic Perlin & simplex noise based on [webgl-noise](https://github.com/ashima/webgl-noise). 37 | 38 | ---- 39 | ### Debug 40 | 41 | Utilities to draw various primitives: 42 | * Line 43 | * Arrow 44 | * Rectangle 45 | * Box 46 | * Circle 47 | * Sphere 48 | * Cylinder 49 | * Capsule 50 | * Cone 51 | 52 | Available styles include: 53 | * Wireframe 54 | * Solid color 55 | * Flat shaded 56 | * Smooth shaded 57 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a79f06bfc8e3b4a4b8c5ecc35901e08c 3 | folderAsset: yes 4 | timeCreated: 1505627213 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e3ef1ad5044532742919696ed4e7aa23 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Collection.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 36b970fb8601b214f89bbd3f89dcc03f 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Collection/CollectionUtil.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | using System.Collections; 13 | using System.Collections.Generic; 14 | 15 | namespace CjLib 16 | { 17 | public class CollectionUtil 18 | { 19 | public struct Pair 20 | { 21 | public T Prev; 22 | public T Curr; 23 | public Pair(T prev, T curr) 24 | { 25 | Prev = prev; 26 | Curr = curr; 27 | } 28 | } 29 | 30 | public static IEnumerable> Pairs(IEnumerable enumerable) 31 | { 32 | return new PairEnumerable(enumerable); 33 | } 34 | 35 | private class PairEnumerable : IEnumerable> 36 | { 37 | public IEnumerable m_enumerable; 38 | public PairEnumerable(IEnumerable enumerable) 39 | { 40 | m_enumerable = enumerable; 41 | } 42 | 43 | public IEnumerator> GetEnumerator() 44 | { 45 | IEnumerator itPrev = m_enumerable.GetEnumerator(); 46 | IEnumerator itCurr = m_enumerable.GetEnumerator(); 47 | itPrev.MoveNext(); 48 | itCurr.MoveNext(); 49 | while (itCurr.MoveNext()) 50 | { 51 | yield return new Pair(itPrev.Current, itCurr.Current); 52 | itPrev.MoveNext(); 53 | } 54 | } 55 | 56 | IEnumerator IEnumerable.GetEnumerator() 57 | { 58 | return GetEnumerator(); 59 | } 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Collection/CollectionUtil.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2ef8b4c7c95d0314582c0094306c9ec5 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Debug.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 27f07aa86dbcfde46ae8de5e73de0fc7 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Debug/Components.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: efd0a739fe209304aa81c05ec99b018f 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Debug/Components/DrawArc.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | using UnityEngine; 13 | 14 | namespace CjLib 15 | { 16 | [ExecuteInEditMode] 17 | public class DrawArc : DrawBase 18 | { 19 | public float Radius = 1.0f; 20 | public int NumSegments = 64; 21 | 22 | public float StartAngle = 0.0f; 23 | public float ArcAngle = 60.0f; 24 | 25 | private void OnValidate() 26 | { 27 | Wireframe = true; 28 | Style = DebugUtil.Style.Wireframe; 29 | 30 | Radius = Mathf.Max(0.0f, Radius); 31 | NumSegments = Mathf.Max(0, NumSegments); 32 | } 33 | 34 | protected override void Draw(Color color, DebugUtil.Style style, bool depthTest) 35 | { 36 | Quaternion startRot = QuaternionUtil.AxisAngle(Vector3.forward, StartAngle * MathUtil.Deg2Rad); 37 | DebugUtil.DrawArc 38 | ( 39 | transform.position, 40 | transform.rotation * startRot * Vector3.right, 41 | transform.rotation * Vector3.forward, 42 | ArcAngle * MathUtil.Deg2Rad, Radius, NumSegments, 43 | color, depthTest 44 | ); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Debug/Components/DrawArc.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b83df268a65a4ae45b606ef7cf326a72 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Debug/Components/DrawArrow.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | using UnityEngine; 13 | 14 | namespace CjLib 15 | { 16 | [ExecuteInEditMode] 17 | public class DrawArrow : DrawBase 18 | { 19 | public Vector3 LocalEndVector = Vector3.right; 20 | 21 | public float ConeRadius = 0.05f; 22 | public float ConeHeight = 0.1f; 23 | public float StemThickness = 0.05f; 24 | public int NumSegments = 8; 25 | 26 | private void OnValidate() 27 | { 28 | ConeRadius = Mathf.Max(0.0f, ConeRadius); 29 | ConeHeight = Mathf.Max(0.0f, ConeHeight); 30 | StemThickness = Mathf.Max(0.0f, StemThickness); 31 | NumSegments = Mathf.Max(4, NumSegments); 32 | } 33 | 34 | protected override void Draw(Color color, DebugUtil.Style style, bool depthTest) 35 | { 36 | DebugUtil.DrawArrow 37 | ( 38 | transform.position, 39 | transform.position + transform.TransformVector(LocalEndVector), 40 | ConeRadius, ConeHeight, NumSegments, StemThickness, 41 | color, depthTest, style 42 | ); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Debug/Components/DrawArrow.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f14b51060c9846b4e893bef665a462cd 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Debug/Components/DrawArrowEditor.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | #if UNITY_EDITOR 13 | using UnityEditor; 14 | using UnityEngine; 15 | 16 | namespace CjLib 17 | { 18 | [CustomEditor(typeof(DrawArrow)), CanEditMultipleObjects] 19 | public class DrawArrowEditor : Editor 20 | { 21 | private void OnSceneGUI() 22 | { 23 | var drawLine = (DrawArrow) target; 24 | 25 | Vector3 oldLineEnd = drawLine.transform.position + drawLine.transform.TransformVector(drawLine.LocalEndVector); 26 | 27 | Vector3 newLineEnd = 28 | Handles.PositionHandle 29 | ( 30 | oldLineEnd, 31 | Tools.pivotRotation == PivotRotation.Global 32 | ? Quaternion.identity 33 | : drawLine.transform.rotation 34 | ) ; 35 | 36 | Vector3 delta = newLineEnd - oldLineEnd; 37 | 38 | if (delta.sqrMagnitude <= 0.0f) 39 | return; 40 | 41 | drawLine.LocalEndVector += drawLine.transform.InverseTransformVector(delta); 42 | 43 | EditorApplication.QueuePlayerLoopUpdate(); 44 | } 45 | } 46 | } 47 | #endif 48 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Debug/Components/DrawArrowEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c1bc679e63c970549819aafeb740033a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Debug/Components/DrawBase.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | using UnityEngine; 13 | 14 | namespace CjLib 15 | { 16 | public abstract class DrawBase : MonoBehaviour 17 | { 18 | public Color WireframeColor = Color.white; 19 | public Color ShadededColor = Color.gray; 20 | 21 | public bool Wireframe = false; 22 | public DebugUtil.Style Style = DebugUtil.Style.FlatShaded; 23 | 24 | public bool DepthTest = true; 25 | 26 | private void Update() 27 | { 28 | if (Style != DebugUtil.Style.Wireframe) 29 | Draw(ShadededColor, Style, DepthTest); 30 | 31 | if (Style == DebugUtil.Style.Wireframe || Wireframe) 32 | Draw(WireframeColor, DebugUtil.Style.Wireframe, DepthTest); 33 | } 34 | 35 | protected abstract void Draw(Color color, DebugUtil.Style style, bool depthTest); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Debug/Components/DrawBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7a2903a055739d24a906186039dc7550 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Debug/Components/DrawBox.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | using UnityEngine; 13 | 14 | namespace CjLib 15 | { 16 | [ExecuteInEditMode] 17 | public class DrawBox : DrawBase 18 | { 19 | public float Radius = 1.0f; 20 | public int NumSegments = 64; 21 | 22 | public float StartAngle = 0.0f; 23 | public float ArcAngle = 60.0f; 24 | 25 | private void OnValidate() 26 | { 27 | Radius = Mathf.Max(0.0f, Radius); 28 | NumSegments = Mathf.Max(0, NumSegments); 29 | } 30 | 31 | protected override void Draw(Color color, DebugUtil.Style style, bool depthTest) 32 | { 33 | Quaternion startRot = QuaternionUtil.AxisAngle(Vector3.forward, StartAngle * MathUtil.Deg2Rad); 34 | DebugUtil.DrawArc 35 | ( 36 | transform.position, 37 | transform.rotation * startRot * Vector3.right, 38 | transform.rotation * Vector3.forward, 39 | ArcAngle * MathUtil.Deg2Rad, Radius, NumSegments, 40 | color, depthTest 41 | ); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Debug/Components/DrawBox.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b9c471870a8d6d94d8ced3169854ab80 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Debug/Components/DrawCircle.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | using UnityEngine; 13 | 14 | namespace CjLib 15 | { 16 | [ExecuteInEditMode] 17 | public class DrawCircle : DrawBase 18 | { 19 | public float Radius = 1.0f; 20 | public int NumSegments = 64; 21 | 22 | private void OnValidate() 23 | { 24 | Radius = Mathf.Max(0.0f, Radius); 25 | NumSegments = Mathf.Max(0, NumSegments); 26 | } 27 | 28 | protected override void Draw(Color color, DebugUtil.Style style, bool depthTest) 29 | { 30 | DebugUtil.DrawCircle(transform.position, transform.rotation * Vector3.back, Radius, NumSegments, color, depthTest, style); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Debug/Components/DrawCircle.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ab47c729609ea7e4ca91a53a1b648aa0 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Debug/Components/DrawLine.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | using UnityEngine; 13 | 14 | namespace CjLib 15 | { 16 | [ExecuteInEditMode] 17 | public class DrawLine : DrawBase 18 | { 19 | public Vector3 LocalEndVector = Vector3.right; 20 | 21 | private void OnValidate() 22 | { 23 | Wireframe = true; 24 | Style = DebugUtil.Style.Wireframe; 25 | } 26 | 27 | protected override void Draw(Color color, DebugUtil.Style style, bool depthTest) 28 | { 29 | DebugUtil.DrawLine 30 | ( 31 | transform.position, 32 | transform.position + transform.TransformVector(LocalEndVector), 33 | color, depthTest 34 | ); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Debug/Components/DrawLine.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 38a130bb4d340a345b48f57fb67035ff 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Debug/Components/DrawLineEditor.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | #if UNITY_EDITOR 13 | using UnityEditor; 14 | using UnityEngine; 15 | 16 | namespace CjLib 17 | { 18 | [CustomEditor(typeof(DrawLine)), CanEditMultipleObjects] 19 | public class DrawLineEditor : Editor 20 | { 21 | private void OnSceneGUI() 22 | { 23 | var drawLine = (DrawLine) target; 24 | 25 | Vector3 oldLineEnd = drawLine.transform.position + drawLine.transform.TransformVector(drawLine.LocalEndVector); 26 | 27 | Vector3 newLineEnd = 28 | Handles.PositionHandle 29 | ( 30 | oldLineEnd, 31 | Tools.pivotRotation == PivotRotation.Global 32 | ? Quaternion.identity 33 | : drawLine.transform.rotation 34 | ) ; 35 | 36 | Vector3 delta = newLineEnd - oldLineEnd; 37 | 38 | if (delta.sqrMagnitude <= 0.0f) 39 | return; 40 | 41 | drawLine.LocalEndVector += drawLine.transform.InverseTransformVector(delta); 42 | 43 | EditorApplication.QueuePlayerLoopUpdate(); 44 | } 45 | } 46 | } 47 | #endif 48 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Debug/Components/DrawLineEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0acc817dd8164f74b83641278885cb4a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Debug/Components/DrawSphere.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | using UnityEngine; 13 | 14 | namespace CjLib 15 | { 16 | [ExecuteInEditMode] 17 | public class DrawSphere : DrawBase 18 | { 19 | public float Radius = 1.0f; 20 | public int NumSegments = 64; 21 | 22 | public float StartAngle = 0.0f; 23 | public float ArcAngle = 60.0f; 24 | 25 | private void OnValidate() 26 | { 27 | Radius = Mathf.Max(0.0f, Radius); 28 | NumSegments = Mathf.Max(0, NumSegments); 29 | } 30 | 31 | protected override void Draw(Color color, DebugUtil.Style style, bool depthTest) 32 | { 33 | Quaternion startRot = QuaternionUtil.AxisAngle(Vector3.forward, StartAngle * MathUtil.Deg2Rad); 34 | DebugUtil.DrawArc 35 | ( 36 | transform.position, 37 | transform.rotation * startRot * Vector3.right, 38 | transform.rotation * Vector3.forward, 39 | ArcAngle * MathUtil.Deg2Rad, Radius, NumSegments, 40 | color, depthTest 41 | ); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Debug/Components/DrawSphere.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3c92e38eec6d399438276095697c66c2 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Debug/DebugUtil.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bcd12943196f1194c8243f1153874ca9 3 | timeCreated: 1505627213 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Debug/GizmosUtil.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c8d8fc51a789c3f40bcd3e88a9b20031 3 | timeCreated: 1509865761 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Debug/PrimitiveMeshFactory.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 63fe9a59410702a4d9db5da90b504001 3 | timeCreated: 1506843182 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Math.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f5d22176eeb35cf4f83e1cc7acd4d954 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Math/LatexFormula.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | using UnityEngine; 13 | using UnityEngine.Networking; 14 | 15 | using System.Collections; 16 | using System.IO; 17 | using UnityEngine.SceneManagement; 18 | using System; 19 | 20 | #if UNITY_EDITOR 21 | using UnityEditor; 22 | #endif 23 | 24 | namespace CjLib 25 | { 26 | [ExecuteInEditMode] 27 | public class LatexFormula : MonoBehaviour 28 | { 29 | public static readonly string BaseUrl = "http://tex.s2cms.ru/svg/f(x) "; 30 | 31 | private int m_hash = BaseUrl.GetHashCode(); 32 | 33 | [SerializeField] 34 | private string m_formula = ""; 35 | 36 | private Texture m_texture; 37 | 38 | #if UNITY_EDITOR 39 | private double m_nextRefreshTime; 40 | private bool m_refreshing; 41 | 42 | public void OnEnable() 43 | { 44 | m_nextRefreshTime = Time.time; 45 | m_refreshing = false; 46 | EditorApplication.update += OnEditorUpdate; 47 | } 48 | 49 | public void OnDisable() 50 | { 51 | EditorApplication.update -= OnEditorUpdate; 52 | } 53 | 54 | private void OnEditorUpdate() 55 | { 56 | if (m_refreshing) 57 | return; 58 | 59 | if (EditorApplication.timeSinceStartup < m_nextRefreshTime) 60 | return; 61 | 62 | if (m_formula.GetHashCode() != m_hash) 63 | { 64 | m_refreshing = true; 65 | StartCoroutine(RefreshTexture()); 66 | } 67 | } 68 | 69 | private IEnumerator RefreshTexture() 70 | { 71 | UnityWebRequest req = UnityWebRequest.Get(BaseUrl + m_formula); 72 | yield return req.SendWebRequest(); 73 | 74 | m_hash = m_formula.GetHashCode(); 75 | 76 | if (req.error != null) 77 | { 78 | Debug.LogWarning("Error loading from \"" + req.url + "\":" + req.error); 79 | } 80 | else 81 | { 82 | Debug.Log("Finished loading from \"" + req.url); 83 | 84 | string filePath = Application.dataPath + "/LaTex Textures/" + m_hash + ".svg"; 85 | try 86 | { 87 | using (var fs = new FileStream(filePath, FileMode.Create, FileAccess.Write)) 88 | { 89 | fs.Write(req.downloadHandler.data, 0, req.downloadHandler.data.Length); 90 | } 91 | 92 | Debug.Log("Finished writing file from \"" + filePath); 93 | } 94 | catch (Exception ex) 95 | { 96 | Debug.LogWarning("Error writing file \"" + filePath + "\":" + ex.Message); 97 | } 98 | } 99 | 100 | m_refreshing = false; 101 | m_nextRefreshTime = EditorApplication.timeSinceStartup + 2.0; 102 | } 103 | 104 | public void OnValidate() 105 | { 106 | int newHash = m_formula.GetHashCode(); 107 | if (newHash != m_hash) 108 | { 109 | m_nextRefreshTime = EditorApplication.timeSinceStartup + 2.0; 110 | } 111 | } 112 | #endif 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Math/LatexFormula.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 664cb85748a961445bc3e3747c028f1d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Math/MathUtil.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | using UnityEngine; 13 | 14 | namespace CjLib 15 | { 16 | public class MathUtil 17 | { 18 | 19 | public static readonly float Pi = Mathf.PI; 20 | public static readonly float TwoPi = 2.0f * Mathf.PI; 21 | public static readonly float HalfPi = Mathf.PI / 2.0f; 22 | public static readonly float ThirdPi = Mathf.PI / 3.0f; 23 | public static readonly float QuarterPi = Mathf.PI / 4.0f; 24 | public static readonly float FifthPi = Mathf.PI / 5.0f; 25 | public static readonly float SixthPi = Mathf.PI / 6.0f; 26 | 27 | public static readonly float Sqrt2 = Mathf.Sqrt(2.0f); 28 | public static readonly float Sqrt2Inv = 1.0f / Mathf.Sqrt(2.0f); 29 | public static readonly float Sqrt3 = Mathf.Sqrt(3.0f); 30 | public static readonly float Sqrt3Inv = 1.0f / Mathf.Sqrt(3.0f); 31 | 32 | 33 | public static readonly float Epsilon = 1.0e-9f; 34 | public static readonly float EpsilonComp = 1.0f - Epsilon; 35 | public static readonly float Rad2Deg = 180.0f / Mathf.PI; 36 | public static readonly float Deg2Rad = Mathf.PI / 180.0f; 37 | 38 | public static float AsinSafe(float x) 39 | { 40 | return Mathf.Asin(Mathf.Clamp(x, -1.0f, 1.0f)); 41 | } 42 | 43 | public static float AcosSafe(float x) 44 | { 45 | return Mathf.Acos(Mathf.Clamp(x, -1.0f, 1.0f)); 46 | } 47 | 48 | public static float CatmullRom(float p0, float p1, float p2, float p3, float t) 49 | { 50 | float tt = t * t; 51 | return 52 | 0.5f 53 | * ((2.0f * p1) 54 | + (-p0 + p2) * t 55 | + (2.0f * p0 - 5.0f * p1 + 4.0f * p2 - p3) * tt 56 | + (-p0 + 3.0f * p1 - 3.0f * p2 + p3) * tt * t 57 | ); 58 | } 59 | 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Math/MathUtil.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 293ef8804f152764c9b62fead2675ab0 3 | timeCreated: 1505630917 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Math/NumericSpring.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fd0d307d689a8ac4580a4a4c56bf0742 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Math/QuaternionUtil.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3e3573306d728414c851bf9fc2fbc23f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Math/VectorUtil.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | using UnityEngine; 13 | 14 | namespace CjLib 15 | { 16 | public class VectorUtil 17 | { 18 | 19 | public static Vector3 Rotate2D(Vector3 v, float deg) 20 | { 21 | Vector3 results = v; 22 | float cos = Mathf.Cos(MathUtil.Deg2Rad * deg); 23 | float sin = Mathf.Sin(MathUtil.Deg2Rad * deg); 24 | results.x = cos * v.x - sin * v.y; 25 | results.y = sin * v.x + cos * v.y; 26 | return results; 27 | } 28 | 29 | public static Vector3 NormalizeSafe(Vector3 v, Vector3 fallback) 30 | { 31 | return 32 | v.sqrMagnitude > MathUtil.Epsilon 33 | ? v.normalized 34 | : fallback; 35 | } 36 | 37 | // Returns a vector orthogonal to given vector. 38 | // If the given vector is a unit vector, the returned vector will also be a unit vector. 39 | public static Vector3 FindOrthogonal(Vector3 v) 40 | { 41 | if (Mathf.Abs(v.x) >= MathUtil.Sqrt3Inv) 42 | return Vector3.Normalize(new Vector3(v.y, -v.x, 0.0f)); 43 | else 44 | return Vector3.Normalize(new Vector3(0.0f, v.z, -v.y)); 45 | } 46 | 47 | // Yields two extra vectors that form an orthogonal basis with the given vector. 48 | // If the given vector is a unit vector, the returned vectors will also be unit vectors. 49 | public static void FormOrthogonalBasis(Vector3 v, out Vector3 a, out Vector3 b) 50 | { 51 | a = FindOrthogonal(v); 52 | b = Vector3.Cross(a, v); 53 | } 54 | 55 | public static Vector3 Integrate(Vector3 x, Vector3 v, float dt) 56 | { 57 | return x + v * dt; 58 | } 59 | 60 | // Both vectors must be unit vectors. 61 | public static Vector3 Slerp(Vector3 a, Vector3 b, float t) 62 | { 63 | float dot = Vector3.Dot(a, b); 64 | 65 | if (dot > 0.99999f) 66 | { 67 | // singularity: two vectors point in the same direction 68 | return Vector3.Lerp(a, b, t); 69 | } 70 | else if (dot < -0.99999f) 71 | { 72 | // singularity: two vectors point in the opposite direction 73 | Vector3 axis = FindOrthogonal(a); 74 | return Quaternion.AngleAxis(180.0f * t, axis) * a; 75 | } 76 | 77 | float rad = MathUtil.AcosSafe(dot); 78 | return (Mathf.Sin((1.0f - t) * rad) * a + Mathf.Sin(t * rad) * b) / Mathf.Sin(rad); 79 | } 80 | 81 | public static Vector3 CatmullRom(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t) 82 | { 83 | float tt = t * t; 84 | return 85 | 0.5f 86 | * ((2.0f * p1) 87 | + (-p0 + p2) * t 88 | + (2.0f * p0 - 5.0f * p1 + 4.0f * p2 - p3) * tt 89 | + (-p0 + 3.0f * p1 - 3.0f * p2 + p3) * tt * t 90 | ); 91 | } 92 | 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Math/VectorUtil.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a0c20a61328a4bb4ba0334465ca09061 3 | timeCreated: 1505973953 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Noise.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d2fdee2e45961c242a6ecced78a385e4 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Noise/ClassicNoise.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | using UnityEngine; 13 | 14 | namespace CjLib 15 | { 16 | public class ClassicNoise 17 | { 18 | // common 19 | //------------------------------------------------------------------------- 20 | 21 | private static bool s_classicInit = false; 22 | private static ComputeShader s_classic; 23 | private static int s_classicGrid2KernelId; 24 | private static int s_classicGrid3KernelId; 25 | private static int s_classicCustom2KernelId; 26 | private static int s_classicCustom3KernelId; 27 | private static void InitClassic() 28 | { 29 | if (s_classicInit) 30 | return; 31 | 32 | s_classic = (ComputeShader) Resources.Load("ClassicNoiseCs"); 33 | s_classicGrid2KernelId = s_classic.FindKernel("ClassicGrid2"); 34 | s_classicGrid3KernelId = s_classic.FindKernel("ClassicGrid3"); 35 | s_classicCustom2KernelId = s_classic.FindKernel("ClassicCustom2"); 36 | s_classicCustom3KernelId = s_classic.FindKernel("ClassicCustom3"); 37 | } 38 | 39 | private static void GetClassicGrid2(out ComputeShader shader, out int kernelId) 40 | { 41 | InitClassic(); 42 | shader = s_classic; 43 | kernelId = s_classicGrid2KernelId; 44 | } 45 | 46 | private static void GetClassicGrid3(out ComputeShader shader, out int kernelId) 47 | { 48 | InitClassic(); 49 | shader = s_classic; 50 | kernelId = s_classicGrid3KernelId; 51 | } 52 | 53 | private static void GetClassicCustom2(out ComputeShader shader, out int kernelId) 54 | { 55 | InitClassic(); 56 | shader = s_classic; 57 | kernelId = s_classicCustom2KernelId; 58 | } 59 | 60 | private static void GetClassicCustom3(out ComputeShader shader, out int kernelId) 61 | { 62 | InitClassic(); 63 | shader = s_classic; 64 | kernelId = s_classicCustom3KernelId; 65 | } 66 | 67 | //------------------------------------------------------------------------- 68 | // end: common 69 | 70 | 71 | // GPU compute / grid samples 72 | //------------------------------------------------------------------------- 73 | 74 | public static void Compute(FloatArray output, NoiseScale scale, NoiseOffset offset, int numOctaves, float octaveOffsetFactor) 75 | { 76 | ComputeShader shader; 77 | int kernelId; 78 | GetClassicGrid2(out shader, out kernelId); 79 | NoiseCommon.Compute(output, shader, kernelId, scale.GetArray(), offset, numOctaves, octaveOffsetFactor); 80 | } 81 | 82 | //------------------------------------------------------------------------- 83 | // end: GPU compute / grid samples 84 | 85 | 86 | // GPU compute / custom samples 87 | //------------------------------------------------------------------------- 88 | 89 | public static void Compute(Vector2Array input, FloatArray output, NoiseScale scale, NoiseOffset offset, int numOctaves, float octaveOffsetFactor) 90 | { 91 | ComputeShader shader; 92 | int kernelId; 93 | GetClassicCustom2(out shader, out kernelId); 94 | NoiseCommon.Compute(input, output, shader, kernelId, scale, offset, numOctaves, octaveOffsetFactor); 95 | } 96 | 97 | public static void Compute(Vector3Array input, FloatArray output, NoiseScale scale, NoiseOffset offset, int numOctaves, float octaveOffsetFactor) 98 | { 99 | ComputeShader shader; 100 | int kernelId; 101 | GetClassicCustom3(out shader, out kernelId); 102 | NoiseCommon.Compute(input, output, shader, kernelId, scale, offset, numOctaves, octaveOffsetFactor); 103 | } 104 | 105 | //------------------------------------------------------------------------- 106 | // end: GPU compute / custom samples 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Noise/ClassicNoise.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b3bb9ab06bd7c784e8a7e8b5b8001170 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Noise/ClassicNoisePeriodic.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | using UnityEngine; 13 | 14 | namespace CjLib 15 | { 16 | public class ClassicNoisePeriodic 17 | { 18 | // common 19 | //------------------------------------------------------------------------- 20 | 21 | private static bool s_classicPeriodicInit = false; 22 | private static ComputeShader s_classicPeriodic; 23 | private static int s_classicPeriodicGrid2KernelId; 24 | private static int s_classicPeriodicGrid3KernelId; 25 | private static int s_classicPeriodicCustom2KernelId; 26 | private static int s_classicPeriodicCustom3KernelId; 27 | private static void InitClassicPeriodic() 28 | { 29 | if (s_classicPeriodicInit) 30 | return; 31 | 32 | s_classicPeriodic = (ComputeShader) Resources.Load("ClassicNoisePeriodicCs"); 33 | s_classicPeriodicGrid2KernelId = s_classicPeriodic.FindKernel("ClassicPeriodicGrid2"); 34 | s_classicPeriodicGrid3KernelId = s_classicPeriodic.FindKernel("ClassicPeriodicGrid3"); 35 | s_classicPeriodicCustom2KernelId = s_classicPeriodic.FindKernel("ClassicPeriodicGrid2"); 36 | s_classicPeriodicCustom3KernelId = s_classicPeriodic.FindKernel("ClassicPeriodicGrid3"); 37 | } 38 | 39 | private static void GetClassicPeriodicGrid2(out ComputeShader shader, out int kernelId) 40 | { 41 | InitClassicPeriodic(); 42 | shader = s_classicPeriodic; 43 | kernelId = s_classicPeriodicGrid2KernelId; 44 | } 45 | 46 | private static void GetClassicPeriodicGrid3(out ComputeShader shader, out int kernelId) 47 | { 48 | InitClassicPeriodic(); 49 | shader = s_classicPeriodic; 50 | kernelId = s_classicPeriodicGrid3KernelId; 51 | } 52 | 53 | private static void GetClassicPeriodicCustom2(out ComputeShader shader, out int kernelId) 54 | { 55 | InitClassicPeriodic(); 56 | shader = s_classicPeriodic; 57 | kernelId = s_classicPeriodicCustom2KernelId; 58 | } 59 | 60 | private static void GetClassicPeriodicCustom3(out ComputeShader shader, out int kernelId) 61 | { 62 | InitClassicPeriodic(); 63 | shader = s_classicPeriodic; 64 | kernelId = s_classicPeriodicCustom3KernelId; 65 | } 66 | 67 | //------------------------------------------------------------------------- 68 | // end: common 69 | 70 | 71 | // GPU compute / grid samples 72 | //------------------------------------------------------------------------- 73 | 74 | public static void Compute(FloatArray output, NoiseScale scale, NoiseOffset offset, NoisePeriod period, int numOctaves, float octaveOffsetFactor) 75 | { 76 | ComputeShader shader; 77 | int kernelId; 78 | GetClassicPeriodicGrid2(out shader, out kernelId); 79 | NoiseCommon.Compute(output, shader, kernelId, scale, offset, period, numOctaves, octaveOffsetFactor); 80 | } 81 | 82 | //------------------------------------------------------------------------- 83 | // end: GPU compute / grid samples 84 | 85 | 86 | // GPU compute / custom samples 87 | //------------------------------------------------------------------------- 88 | 89 | public static void Compute(Vector2Array input, FloatArray output, NoiseScale scale, NoiseOffset offset, NoisePeriod period, int numOctaves, float octaveOffsetFactor) 90 | { 91 | ComputeShader shader; 92 | int kernelId; 93 | GetClassicPeriodicCustom2(out shader, out kernelId); 94 | NoiseCommon.Compute(input, output, shader, kernelId, scale, offset, period, numOctaves, octaveOffsetFactor); 95 | } 96 | 97 | public static void Compute(Vector3Array input, FloatArray output, NoiseScale scale, NoiseOffset offset, NoisePeriod period, int numOctaves, float octaveOffsetFactor) 98 | { 99 | ComputeShader shader; 100 | int kernelId; 101 | GetClassicPeriodicCustom3(out shader, out kernelId); 102 | NoiseCommon.Compute(input, output, shader, kernelId, scale, offset, period, numOctaves, octaveOffsetFactor); 103 | } 104 | 105 | //------------------------------------------------------------------------- 106 | // end: GPU compute / custom samples 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Noise/ClassicNoisePeriodic.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0cff445fac36ff743af64c8e420e935a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Noise/NoiseCommon.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4e25413c92d3b2d4499e6af30623b523 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Noise/RandomNoise.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | using UnityEngine; 13 | 14 | namespace CjLib 15 | { 16 | public class RandomNoise 17 | { 18 | // common 19 | //------------------------------------------------------------------------- 20 | 21 | private static bool s_randomInit = false; 22 | private static ComputeShader s_random; 23 | private static int s_random1KernelId; 24 | private static int s_random2KernelId; 25 | private static int s_random3KernelId; 26 | private static void InitRandom() 27 | { 28 | if (s_randomInit) 29 | return; 30 | 31 | s_random = (ComputeShader) Resources.Load("RandomNoiseCs"); 32 | s_random1KernelId = s_random.FindKernel("RandomGrid1"); 33 | s_random2KernelId = s_random.FindKernel("RandomGrid2"); 34 | s_random3KernelId = s_random.FindKernel("RandomGrid3"); 35 | } 36 | 37 | private static void GetRandom1(out ComputeShader shader, out int kernelId) 38 | { 39 | InitRandom(); 40 | shader = s_random; 41 | kernelId = s_random1KernelId; 42 | } 43 | 44 | private static void GetRandom2(out ComputeShader shader, out int kernelId) 45 | { 46 | InitRandom(); 47 | shader = s_random; 48 | kernelId = s_random2KernelId; 49 | } 50 | 51 | private static void GetRandom3(out ComputeShader shader, out int kernelId) 52 | { 53 | InitRandom(); 54 | shader = s_random; 55 | kernelId = s_random3KernelId; 56 | } 57 | 58 | //------------------------------------------------------------------------- 59 | // end: common 60 | 61 | 62 | // GPU compute / grid samples 63 | //------------------------------------------------------------------------- 64 | 65 | public static void Compute(FloatArray output, int seed = 0) 66 | { 67 | ComputeShader shader; 68 | int kernelId; 69 | GetRandom1(out shader, out kernelId); 70 | NoiseCommon.Compute(output, shader, kernelId, seed); 71 | } 72 | 73 | //------------------------------------------------------------------------- 74 | // end: GPU compute / grid samples 75 | 76 | 77 | // CPU 78 | //------------------------------------------------------------------------- 79 | 80 | public static float Get(float v, int seed = 0) 81 | { 82 | // return frac(sin(mod(s, 6.2831853)) * 43758.5453123); 83 | float s = NoiseCommon.JumbleSeed(seed); 84 | float r = Mathf.Sin(Mathf.Repeat(s + v, 6.2831853f)) * 43758.5453123f; 85 | r = (r >= 0.0f) ? r : -r; 86 | r -= Mathf.Floor(r); 87 | return r; 88 | } 89 | 90 | public static float Get(Vector2 v, int seed = 0) 91 | { 92 | // float d = dot(s + 0.1234567, float2(1111112.9819837, 78.237173)); 93 | float s = NoiseCommon.JumbleSeed(seed); 94 | float d = 95 | (s + v.x + 0.1234567f) * 1111112.9819837f 96 | + (s + v.y + 0.1234567f) * 78.237173f; 97 | 98 | // return frac(sin(m) * 43758.5453123); 99 | float r = Mathf.Sin(d) * 43758.5453123f; 100 | r = (r >= 0.0f) ? r : -r; 101 | r -= Mathf.Floor(r); 102 | return r; 103 | } 104 | 105 | public static float Get(Vector3 v, int seed = 0) 106 | { 107 | // float d = dot(s + 0.1234567, float3(11112.9819837, 378.237173, 3971977.9173179)); 108 | float s = NoiseCommon.JumbleSeed(seed); 109 | float d = 110 | (s + v.x + 0.1234567f) * 1111112.9819837f 111 | + (s + v.y + 0.1234567f) * 378.237173f 112 | + (s + v.z + 0.1234567f) * 3971977.9173179f; 113 | 114 | // return frac(sin(m) * 43758.5453123); 115 | float r = Mathf.Sin(d) * 43758.5453123f; 116 | r = (r >= 0.0f) ? r : -r; 117 | r -= Mathf.Floor(r); 118 | return r; 119 | } 120 | 121 | //------------------------------------------------------------------------- 122 | // end: CPU 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Noise/RandomNoise.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 28b2d82f214efb541b5eaf2403235d8e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Noise/RandomNoiseVector.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | using UnityEngine; 13 | 14 | namespace CjLib 15 | { 16 | // GPU compute 17 | //------------------------------------------------------------------------- 18 | 19 | public class RandomNoiseVector 20 | { 21 | private static bool s_randomVecInit = false; 22 | private static ComputeShader s_randomVec; 23 | private static int s_randomVec2KernelId; 24 | private static int s_randomVec3KernelId; 25 | private static void InitRandomVec() 26 | { 27 | if (s_randomVecInit) 28 | return; 29 | 30 | s_randomVec = (ComputeShader) Resources.Load("RandomNoiseVectorCs"); 31 | s_randomVec2KernelId = s_randomVec.FindKernel("RandomVec2"); 32 | s_randomVec3KernelId = s_randomVec.FindKernel("RandomVec3"); 33 | } 34 | 35 | private static void GetRandomVec2(out ComputeShader shader, out int kernelId) 36 | { 37 | InitRandomVec(); 38 | shader = s_randomVec; 39 | kernelId = s_randomVec2KernelId; 40 | } 41 | 42 | private static void GetRandomVec3(out ComputeShader shader, out int kernelId) 43 | { 44 | InitRandomVec(); 45 | shader = s_randomVec; 46 | kernelId = s_randomVec3KernelId; 47 | } 48 | 49 | public static void Compute(Vector2Array output, int seed = 0) 50 | { 51 | ComputeShader shader; 52 | int kernelId; 53 | GetRandomVec2(out shader, out kernelId); 54 | NoiseCommon.Compute(output, shader, kernelId, seed); 55 | } 56 | 57 | public static void Compute(Vector3Array output, int seed = 0) 58 | { 59 | ComputeShader shader; 60 | int kernelId; 61 | GetRandomVec3(out shader, out kernelId); 62 | NoiseCommon.Compute(output, shader, kernelId, seed); 63 | } 64 | 65 | //------------------------------------------------------------------------- 66 | // end: GPU compute 67 | 68 | 69 | // CPU 70 | //------------------------------------------------------------------------- 71 | 72 | public static Vector2 GetVector2(float v, int seed = 0) 73 | { 74 | // TODO 75 | return new Vector2(); 76 | } 77 | 78 | public static Vector2 GetVector2(Vector2 v, int seed = 0) 79 | { 80 | // TODO 81 | return new Vector2(); 82 | } 83 | 84 | public static Vector3 GetVector3(float v, int seed = 0) 85 | { 86 | // TODO 87 | return new Vector3(); 88 | } 89 | 90 | public static Vector3 GetVector3(Vector2 v, int seed = 0) 91 | { 92 | // TODO 93 | return new Vector3(); 94 | } 95 | 96 | public static Vector3 GetVector3(Vector3 v, int seed = 0) 97 | { 98 | // TODO 99 | return new Vector3(); 100 | } 101 | 102 | //------------------------------------------------------------------------- 103 | // end: CPU 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Noise/RandomNoiseVector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cffd641eedd68b344ae1955908e45ea2 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Noise/SimplexNoise.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | using UnityEngine; 13 | 14 | namespace CjLib 15 | { 16 | public class SimplexNoise 17 | { 18 | // common 19 | //------------------------------------------------------------------------- 20 | 21 | private static bool s_simplexInit = false; 22 | private static ComputeShader s_simplex; 23 | private static int s_simplexGrid2KernelId; 24 | private static int s_simplexGrid3KernelId; 25 | private static int s_simplexCustom2KernelId; 26 | private static int s_simplexCustom3KernelId; 27 | private static void InitSimplex() 28 | { 29 | if (s_simplexInit) 30 | return; 31 | 32 | s_simplex = (ComputeShader) Resources.Load("SimplexNoiseCs"); 33 | s_simplexGrid2KernelId = s_simplex.FindKernel("SimplexGrid2"); 34 | s_simplexGrid3KernelId = s_simplex.FindKernel("SimplexGrid3"); 35 | s_simplexCustom2KernelId = s_simplex.FindKernel("SimplexCustom2"); 36 | s_simplexCustom3KernelId = s_simplex.FindKernel("SimplexCustom3"); 37 | } 38 | 39 | private static void GetSimplexGrid2(out ComputeShader shader, out int kernelId) 40 | { 41 | InitSimplex(); 42 | shader = s_simplex; 43 | kernelId = s_simplexGrid2KernelId; 44 | } 45 | 46 | private static void GetSimplexGrid3(out ComputeShader shader, out int kernelId) 47 | { 48 | InitSimplex(); 49 | shader = s_simplex; 50 | kernelId = s_simplexGrid3KernelId; 51 | } 52 | 53 | private static void GetSimplexCustom2(out ComputeShader shader, out int kernelId) 54 | { 55 | InitSimplex(); 56 | shader = s_simplex; 57 | kernelId = s_simplexCustom2KernelId; 58 | } 59 | 60 | private static void GetSimplexCustom3(out ComputeShader shader, out int kernelId) 61 | { 62 | InitSimplex(); 63 | shader = s_simplex; 64 | kernelId = s_simplexCustom3KernelId; 65 | } 66 | 67 | //------------------------------------------------------------------------- 68 | // end: common 69 | 70 | 71 | // GPU compute / grid samples 72 | //------------------------------------------------------------------------- 73 | 74 | public static void Compute(FloatArray output, NoiseScale scale, NoiseOffset offset, int numOctaves, float octaveOffsetFactor) 75 | { 76 | ComputeShader shader; 77 | int kernelId; 78 | GetSimplexGrid2(out shader, out kernelId); 79 | NoiseCommon.Compute(output, shader, kernelId, scale, offset, numOctaves, octaveOffsetFactor); 80 | } 81 | 82 | //------------------------------------------------------------------------- 83 | // end: GPU compute / grid samples 84 | 85 | 86 | // GPU compute / custom samples 87 | //------------------------------------------------------------------------- 88 | 89 | public static void Compute(Vector2Array input, FloatArray output, NoiseScale scale, NoiseOffset offset, int numOctaves, float octaveOffsetFactor) 90 | { 91 | ComputeShader shader; 92 | int kernelId; 93 | GetSimplexCustom2(out shader, out kernelId); 94 | NoiseCommon.Compute(input, output, shader, kernelId, scale, offset, numOctaves, octaveOffsetFactor); 95 | } 96 | 97 | public static void Compute(Vector3Array input, FloatArray output, NoiseScale scale, NoiseOffset offset, int numOctaves, float octaveOffsetFactor) 98 | { 99 | ComputeShader shader; 100 | int kernelId; 101 | GetSimplexCustom3(out shader, out kernelId); 102 | NoiseCommon.Compute(input, output, shader, kernelId, scale, offset, numOctaves, octaveOffsetFactor); 103 | } 104 | 105 | //------------------------------------------------------------------------- 106 | // end: GPU compute / custom samples 107 | 108 | 109 | // CPU 110 | //------------------------------------------------------------------------- 111 | 112 | 113 | 114 | //------------------------------------------------------------------------- 115 | // end: CPU 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Noise/SimplexNoise.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 41dbc06144f95e84a90d192821544cf7 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Noise/SimplexNoiseGradient.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | using UnityEngine; 13 | 14 | namespace CjLib 15 | { 16 | public class SimplexNoiseGradient 17 | { 18 | // common 19 | //------------------------------------------------------------------------- 20 | 21 | private static bool s_simplexGradientInit = false; 22 | private static ComputeShader s_simplexGradient; 23 | private static int s_simplexGradientGrid2KernelId; 24 | private static int s_simplexGradientGrid3KernelId; 25 | private static int s_simplexGradientCustom2KernelId; 26 | private static int s_simplexGradientCustum3KernelId; 27 | private static void InitSimplex() 28 | { 29 | if (s_simplexGradientInit) 30 | return; 31 | 32 | s_simplexGradient = (ComputeShader) Resources.Load("SimplexNoiseGradientCs"); 33 | s_simplexGradientGrid2KernelId = s_simplexGradient.FindKernel("SimplexGradientGrid2"); 34 | s_simplexGradientGrid3KernelId = s_simplexGradient.FindKernel("SimplexGradientGrid3"); 35 | s_simplexGradientCustom2KernelId = s_simplexGradient.FindKernel("SimplexGradientCustom2"); 36 | s_simplexGradientCustum3KernelId = s_simplexGradient.FindKernel("SimplexGradientCustom3"); 37 | } 38 | 39 | private static void GetSimplexGradientGrid2(out ComputeShader shader, out int kernelId) 40 | { 41 | InitSimplex(); 42 | shader = s_simplexGradient; 43 | kernelId = s_simplexGradientGrid2KernelId; 44 | } 45 | 46 | private static void GetSimplexGradientGrid3(out ComputeShader shader, out int kernelId) 47 | { 48 | InitSimplex(); 49 | shader = s_simplexGradient; 50 | kernelId = s_simplexGradientGrid3KernelId; 51 | } 52 | 53 | private static void GetSimplexGradientCustom2(out ComputeShader shader, out int kernelId) 54 | { 55 | InitSimplex(); 56 | shader = s_simplexGradient; 57 | kernelId = s_simplexGradientCustom2KernelId; 58 | } 59 | 60 | private static void GetSimplexGradientCustom3(out ComputeShader shader, out int kernelId) 61 | { 62 | InitSimplex(); 63 | shader = s_simplexGradient; 64 | kernelId = s_simplexGradientCustum3KernelId; 65 | } 66 | 67 | //------------------------------------------------------------------------- 68 | // end: common 69 | 70 | 71 | // GPU compute / grid samples 72 | //------------------------------------------------------------------------- 73 | 74 | public static void Compute(Vector2Array output, NoiseScale scale, NoiseOffset offset, int numOctaves, float octaveOffsetFactor) 75 | { 76 | ComputeShader shader; 77 | int kernelId; 78 | GetSimplexGradientGrid2(out shader, out kernelId); 79 | NoiseCommon.Compute(output, shader, kernelId, scale, offset, numOctaves, octaveOffsetFactor); 80 | } 81 | 82 | public static void Compute(Vector3Array output, NoiseScale scale, NoiseOffset offset, int numOctaves, float octaveOffsetFactor) 83 | { 84 | ComputeShader shader; 85 | int kernelId; 86 | GetSimplexGradientGrid3(out shader, out kernelId); 87 | NoiseCommon.Compute(output, shader, kernelId, scale, offset, numOctaves, octaveOffsetFactor); 88 | } 89 | 90 | //------------------------------------------------------------------------- 91 | // end: GPU compute / grid samples 92 | 93 | 94 | // GPU compute / custom samples 95 | //------------------------------------------------------------------------- 96 | 97 | public static void Compute(Vector2Array input, Vector2Array output, NoiseScale scale, NoiseOffset offset, int numOctaves, float octaveOffsetFactor) 98 | { 99 | ComputeShader shader; 100 | int kernelId; 101 | GetSimplexGradientCustom2(out shader, out kernelId); 102 | NoiseCommon.Compute(input, output, shader, kernelId, scale, offset, numOctaves, octaveOffsetFactor); 103 | } 104 | 105 | public static void Compute(Vector3Array input, Vector3Array output, NoiseScale scale, NoiseOffset offset, int numOctaves, float octaveOffsetFactor) 106 | { 107 | ComputeShader shader; 108 | int kernelId; 109 | GetSimplexGradientCustom3(out shader, out kernelId); 110 | NoiseCommon.Compute(input, output, shader, kernelId, scale, offset, numOctaves, octaveOffsetFactor); 111 | } 112 | 113 | //------------------------------------------------------------------------- 114 | // end: GPU compute / custom samples 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Noise/SimplexNoiseGradient.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 83a5e45027611394794e3fdd86c74020 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Physics.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1ec10a4b4edb34b47bc708be75e4183d 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Physics/Collision.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | using UnityEngine; 13 | 14 | namespace CjLib 15 | { 16 | // push vector separates A from B 17 | public class Collision 18 | { 19 | public static bool SphereSphere(Vector3 centerA, float radiusA, Vector3 centerB, float radiusB) 20 | { 21 | Vector3 vec = centerA - centerB; 22 | float dd = vec.sqrMagnitude; 23 | float r = radiusA + radiusB; 24 | 25 | return dd <= r * r; 26 | } 27 | 28 | public static bool SphereSphere(Vector3 centerA, float radiusA, Vector3 centerB, float radiusB, out Vector3 push) 29 | { 30 | push = Vector3.zero; 31 | 32 | Vector3 vec = centerA - centerB; 33 | float dd = vec.sqrMagnitude; 34 | float r = radiusA + radiusB; 35 | 36 | if (dd > r * r) 37 | { 38 | return false; 39 | } 40 | 41 | float d = Mathf.Sqrt(dd); 42 | 43 | push = VectorUtil.NormalizeSafe(vec, Vector3.zero) * (r - d); 44 | return true; 45 | } 46 | 47 | public static bool SphereCapsule(Vector3 centerA, float radiusA, Vector3 headB, Vector3 tailB, float radiusB) 48 | { 49 | Vector3 segVec = tailB - headB; 50 | float segLenSqr = segVec.sqrMagnitude; 51 | if (segLenSqr < MathUtil.Epsilon) 52 | return SphereSphere(centerA, radiusA, 0.5f * (headB + tailB), radiusB); 53 | 54 | float segLenInv = 1.0f / Mathf.Sqrt(segLenSqr); 55 | Vector3 segDir = segVec * segLenInv; 56 | Vector3 headToA = centerA - headB; 57 | float t = Mathf.Clamp01(Vector3.Dot(headToA, segDir) * segLenInv); 58 | Vector3 closestB = Vector3.Lerp(headB, tailB, t); 59 | 60 | return SphereSphere(centerA, radiusA, closestB, radiusB); 61 | } 62 | 63 | public static bool SphereCapsule(Vector3 centerA, float radiusA, Vector3 headB, Vector3 tailB, float radiusB, out Vector3 push) 64 | { 65 | push = Vector3.zero; 66 | 67 | Vector3 segVec = tailB - headB; 68 | float segLenSqr = segVec.sqrMagnitude; 69 | if (segLenSqr < MathUtil.Epsilon) 70 | return SphereSphere(centerA, radiusA, 0.5f * (headB + tailB), radiusB, out push); 71 | 72 | float segLenInv = 1.0f / Mathf.Sqrt(segLenSqr); 73 | Vector3 segDir = segVec * segLenInv; 74 | Vector3 headToA = centerA - headB; 75 | float t = Mathf.Clamp01(Vector3.Dot(headToA, segDir) * segLenInv); 76 | Vector3 closestB = Vector3.Lerp(headB, tailB, t); 77 | 78 | return SphereSphere(centerA, radiusA, closestB, radiusB, out push); 79 | } 80 | 81 | public static bool SphereBox(Vector3 centerOffsetA, float radiusA, Vector3 halfExtentB) 82 | { 83 | Vector3 closestOnB = 84 | new Vector3 85 | ( 86 | Mathf.Clamp(centerOffsetA.x, -halfExtentB.x, halfExtentB.x), 87 | Mathf.Clamp(centerOffsetA.y, -halfExtentB.y, halfExtentB.y), 88 | Mathf.Clamp(centerOffsetA.z, -halfExtentB.z, halfExtentB.z) 89 | ); 90 | 91 | Vector3 vec = centerOffsetA - closestOnB; 92 | float dd = vec.sqrMagnitude; 93 | 94 | return dd <= radiusA * radiusA; 95 | } 96 | 97 | public static bool SphereBox(Vector3 centerOffsetA, float radiusA, Vector3 halfExtentB, out Vector3 push) 98 | { 99 | push = Vector3.zero; 100 | 101 | Vector3 closestOnB = 102 | new Vector3 103 | ( 104 | Mathf.Clamp(centerOffsetA.x, -halfExtentB.x, halfExtentB.x), 105 | Mathf.Clamp(centerOffsetA.y, -halfExtentB.y, halfExtentB.y), 106 | Mathf.Clamp(centerOffsetA.z, -halfExtentB.z, halfExtentB.z) 107 | ); 108 | 109 | Vector3 vec = centerOffsetA - closestOnB; 110 | float dd = vec.sqrMagnitude; 111 | 112 | if (dd > radiusA * radiusA) 113 | { 114 | return false; 115 | } 116 | 117 | int numInBoxAxes = 118 | ((centerOffsetA.x < -halfExtentB.x || centerOffsetA.x > halfExtentB.x) ? 0 : 1) 119 | + ((centerOffsetA.y < -halfExtentB.y || centerOffsetA.y > halfExtentB.y) ? 0 : 1) 120 | + ((centerOffsetA.z < -halfExtentB.z || centerOffsetA.z > halfExtentB.z) ? 0 : 1); 121 | 122 | switch (numInBoxAxes) 123 | { 124 | case 0: // hit corner 125 | case 1: // hit edge 126 | case 2: // hit face 127 | { 128 | push = VectorUtil.NormalizeSafe(vec, Vector3.right) * (radiusA - Mathf.Sqrt(dd)); 129 | } 130 | break; 131 | case 3: // inside 132 | { 133 | Vector3 penetration = 134 | new Vector3 135 | ( 136 | halfExtentB.x - Mathf.Abs(centerOffsetA.x) + radiusA, 137 | halfExtentB.y - Mathf.Abs(centerOffsetA.y) + radiusA, 138 | halfExtentB.z - Mathf.Abs(centerOffsetA.z) + radiusA 139 | ); 140 | 141 | if (penetration.x < penetration.y) 142 | { 143 | if (penetration.x < penetration.z) 144 | push = new Vector3(Mathf.Sign(centerOffsetA.x) * penetration.x, 0.0f, 0.0f); 145 | else 146 | push = new Vector3(0.0f, 0.0f, Mathf.Sign(centerOffsetA.z) * penetration.z); 147 | } 148 | else 149 | { 150 | if (penetration.y < penetration.z) 151 | push = new Vector3(0.0f, Mathf.Sign(centerOffsetA.y) * penetration.y, 0.0f); 152 | else 153 | push = new Vector3(0.0f, 0.0f, Mathf.Sign(centerOffsetA.z) * penetration.z); 154 | } 155 | } 156 | break; 157 | } 158 | 159 | return true; 160 | } 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Physics/Collision.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 17c0889bf211a0149aa94f299bd9d883 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Util.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e7698136ae2fbd64bb4704bbf12beb3b 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Util/ConditionalFieldAttribute.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Physics Constraints 4 | https://github.com/TheAllenChou/unity-physics-constraints 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | http://AllenChou.net 8 | 9 | Modified from project "MyBox" by Andrew Rumak. 10 | License : Copyright (C) 2018 Andrew Rumak. 11 | Distributed under the MIT License. See LICENSE file. 12 | https://github.com/Deadcows/MyBox 13 | */ 14 | /******************************************************************************/ 15 | 16 | using System; 17 | using UnityEngine; 18 | 19 | namespace CjLib 20 | { 21 | [AttributeUsage(AttributeTargets.Field)] 22 | public class ConditionalFieldAttribute : PropertyAttribute 23 | { 24 | public bool ShowRange { get { return Min != Max; } } 25 | 26 | public string PropertyToCheck; 27 | public object CompareValue; 28 | public object CompareValue2; 29 | public object CompareValue3; 30 | public object CompareValue4; 31 | public object CompareValue5; 32 | public object CompareValue6; 33 | public string Label; 34 | public string Tooltip; 35 | public float Min; 36 | public float Max; 37 | 38 | public ConditionalFieldAttribute 39 | ( 40 | string propertyToCheck = null, 41 | object compareValue = null, 42 | object compareValue2 = null, 43 | object compareValue3 = null, 44 | object compareValue4 = null, 45 | object compareValue5 = null, 46 | object compareValue6 = null 47 | ) 48 | { 49 | PropertyToCheck = propertyToCheck; 50 | CompareValue = compareValue; 51 | CompareValue2 = compareValue2; 52 | CompareValue3 = compareValue3; 53 | CompareValue4 = compareValue4; 54 | CompareValue5 = compareValue5; 55 | CompareValue6 = compareValue6; 56 | Label = ""; 57 | Tooltip = ""; 58 | Min = 0.0f; 59 | Max = 0.0f; 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Util/ConditionalFieldAttribute.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9bb73dc1b0f1a044cb1deb9a88cfc67d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Script/Util/ConditionalFieldAttributeDrawer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b9e53b729e687884fb1ec3241468ad3e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: af1136683704bda4aad9ba53863f5cd8 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Debug.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 700846c65cb10354eba710117d2cd8eb 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Debug/Primitive.shader: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | Shader "CjLib/Primitive" 13 | { 14 | SubShader 15 | { 16 | Tags { "Queue"="Transparent" "RenderType"="Transparent" "DisableBatching"="true" } 17 | LOD 100 18 | 19 | Pass 20 | { 21 | Blend SrcAlpha OneMinusSrcAlpha 22 | 23 | CGPROGRAM 24 | #pragma shader_feature NORMAL_ON 25 | #pragma shader_feature CAP_SHIFT_SCALE 26 | #pragma vertex vert 27 | #pragma fragment frag 28 | #include "PrimitiveCore.cginc" 29 | ENDCG 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Debug/Primitive.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 034880ed17763504c8c134022d45077a 3 | timeCreated: 1506841290 4 | licenseType: Free 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Debug/PrimitiveCore.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | 10 | Author - Ming-Lun "Allen" Chou 11 | Web - http://AllenChou.net 12 | Twitter - @TheAllenChou 13 | */ 14 | /******************************************************************************/ 15 | 16 | #ifndef CJ_LIB_PRIMITIVE_CORE 17 | #define CJ_LIB_PRIMITIVE_CORE 18 | 19 | #include "UnityCG.cginc" 20 | 21 | struct appdata 22 | { 23 | float4 vertex : POSITION; 24 | 25 | #ifdef NORMAL_ON 26 | float3 normal : NORMAL; 27 | #endif 28 | }; 29 | 30 | struct v2f 31 | { 32 | float4 vertex : SV_POSITION; 33 | 34 | #ifdef NORMAL_ON 35 | float3 normal : NORMAL; 36 | #endif 37 | }; 38 | 39 | float4 _Color; 40 | 41 | // (x, y, z) == (dimensionX, dimensionY, dimensionZ) 42 | // w == capShiftScale (shift 0.5 towards X-Z plane, scale by dimensions, and then shoft back 0.5 * capShiftScale) 43 | float4 _Dimensions; 44 | 45 | float _ZBias; 46 | 47 | sampler2D _MainTex; 48 | float4 _MainTex_ST; 49 | 50 | v2f vert (appdata v) 51 | { 52 | v2f o; 53 | 54 | #ifdef CAP_SHIFT_SCALE 55 | const float ySign = sign(v.vertex.y); 56 | v.vertex.y -= ySign * 0.5f; 57 | #endif 58 | 59 | v.vertex.xyz *= _Dimensions.xyz; 60 | 61 | #ifdef CAP_SHIFT_SCALE 62 | v.vertex.y += ySign * 0.5f * _Dimensions.w; 63 | #endif 64 | 65 | o.vertex = UnityObjectToClipPos(v.vertex); 66 | o.vertex.z += _ZBias; 67 | 68 | #ifdef NORMAL_ON 69 | float4x4 scaleInverseTranspose = float4x4 70 | ( 71 | 1.0f / _Dimensions.x, 0.0f, 0.0f, 0.0f, 72 | 0.0f, 1.0f / _Dimensions.y, 0.0f, 0.0f, 73 | 0.0f, 0.0f, 1.0f / _Dimensions.z, 0.0f, 74 | 0.0f, 0.0f, 0.0f, 1.0f 75 | ); 76 | o.normal = mul(mul(UNITY_MATRIX_IT_MV, scaleInverseTranspose), float4(v.normal, 0.0f)).xyz; 77 | #endif 78 | 79 | return o; 80 | } 81 | 82 | fixed4 frag (v2f i) : SV_Target 83 | { 84 | fixed4 color = _Color; 85 | 86 | #ifdef NORMAL_ON 87 | i.normal = normalize(i.normal); 88 | color.rgb *= 0.7f * i.normal.z + 0.3f; // darkest at 0.3f 89 | #endif 90 | 91 | return color; 92 | } 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Debug/PrimitiveCore.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5addce54e9089824fb95ae41f409cfcf 3 | timeCreated: 1506925965 4 | licenseType: Free 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Debug/PrimitiveNoZTest.shader: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | Shader "CjLib/PrimitiveNoZTest" 13 | { 14 | SubShader 15 | { 16 | Tags { "Queue"="Overlay" "RenderType"="Transparent" "DisableBatching"="true" } 17 | LOD 100 18 | 19 | Pass 20 | { 21 | Blend SrcAlpha OneMinusSrcAlpha 22 | ZWrite Off ZTest Always 23 | 24 | CGPROGRAM 25 | #pragma shader_feature NORMAL_ON 26 | #pragma shader_feature CAP_SHIFT_SCALE 27 | #pragma vertex vert 28 | #pragma fragment frag 29 | #include "PrimitiveCore.cginc" 30 | ENDCG 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Debug/PrimitiveNoZTest.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: aa5e61c16eee1db4e85f6ef4483fea6d 3 | timeCreated: 1506845184 4 | licenseType: Free 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Math.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9254b444dab1c474ea0ef5b3c7932238 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Math/CatmullRom.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | #ifndef CJ_LIB_CATMULL_ROM 13 | #define CJ_LIB_CATMULL_ROM 14 | 15 | inline float catmullRom(float p0, float p1, float p2, float p3, float t) 16 | { 17 | float tt = t * t; 18 | return 19 | 0.5f 20 | * ((2.0f * p1) 21 | + (-p0 + p2) * t 22 | + (2.0f * p0 - 5.0f * p1 + 4.0f * p2 - p3) * tt 23 | + (-p0 + 3.0f * p1 - 3.0f * p2 + p3) * tt * t 24 | ); 25 | } 26 | 27 | inline float2 catmullRom(float2 p0, float2 p1, float2 p2, float2 p3, float t) 28 | { 29 | float tt = t * t; 30 | return 31 | 0.5f 32 | * ((2.0f * p1) 33 | + (-p0 + p2) * t 34 | + (2.0f * p0 - 5.0f * p1 + 4.0f * p2 - p3) * tt 35 | + (-p0 + 3.0f * p1 - 3.0f * p2 + p3) * tt * t 36 | ); 37 | } 38 | 39 | inline float3 catmullRom(float3 p0, float3 p1, float3 p2, float3 p3, float t) 40 | { 41 | float tt = t * t; 42 | return 43 | 0.5f 44 | * ((2.0f * p1) 45 | + (-p0 + p2) * t 46 | + (2.0f * p0 - 5.0f * p1 + 4.0f * p2 - p3) * tt 47 | + (-p0 + 3.0f * p1 - 3.0f * p2 + p3) * tt * t 48 | ); 49 | } 50 | 51 | inline float4 catmullRom(float4 p0, float4 p1, float4 p2, float4 p3, float t) 52 | { 53 | float tt = t * t; 54 | return 55 | 0.5f 56 | * ((2.0f * p1) 57 | + (-p0 + p2) * t 58 | + (2.0f * p0 - 5.0f * p1 + 4.0f * p2 - p3) * tt 59 | + (-p0 + 3.0f * p1 - 3.0f * p2 + p3) * tt * t 60 | ); 61 | } 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Math/CatmullRom.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8faf7cc0acb5fcb4f8f2344c07918c16 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Math/Color.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | #ifndef CJ_LIB_COLOR 13 | #define CJ_LIB_COLOR 14 | 15 | float3 hsv2rgb(float3 hsv) 16 | { 17 | hsv.x = hsv.x - floor(hsv.x); 18 | int h = ((int) (hsv.x * 6)); 19 | float f = hsv.x * 6.0 - h; 20 | float p = hsv.z * (1.0 - hsv.y); 21 | float q = hsv.z * (1.0 - f * hsv.y); 22 | float t = hsv.z * (1.0 - (1.0 - f) * hsv.y); 23 | 24 | switch (h) 25 | { 26 | default: 27 | case 0: return float3(hsv.z, t, p); 28 | case 1: return float3(q, hsv.z, p); 29 | case 2: return float3(p, hsv.z, t); 30 | case 3: return float3(p, q, hsv.z); 31 | case 4: return float3(t, p, hsv.z); 32 | case 5: return float3(hsv.z, p, q); 33 | } 34 | } 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Math/Color.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d29168bdf7611fb43ae31c32f099264e 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Math/Math.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | #ifndef CJ_LIB_MATH 13 | #define CJ_LIB_MATH 14 | 15 | #define kPi (3.1415926535) 16 | #define kTwoPi (6.2831853071) 17 | #define kHalfPi (1.5707963267) 18 | #define kThirdPi (1.0471975511) 19 | #define kQuaterPi (0.7853981633) 20 | #define kFifthPi (0.6283185307) 21 | #define kSixthPi (0.5235987755) 22 | 23 | #define kSqrt2 (1.4142135623) 24 | #define kSqrt3 (1.7320508075) 25 | #define kSqrt2Inv (0.7071067811) 26 | #define kSqrt3Inv (0.5773502691) 27 | 28 | #define kEpsilon (0.0000000001) 29 | #define kEpsilonComp (0.9999999999) 30 | 31 | #define kRad2Deg (57.295779513) 32 | #define kDeg2Rad (0.0174532925) 33 | 34 | #include "Color.cginc" 35 | #include "Quaternion.cginc" 36 | #include "Vector.cginc" 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Math/Math.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cbc2d2d27ca839e4a9a2e5662fd714ad 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Math/Quaternion.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | #ifndef CJ_LIB_QUATERNION 13 | #define CJ_LIB_QUATERNION 14 | 15 | #include "Math.cginc" 16 | #include "Vector.cginc" 17 | 18 | inline float4 quat_identity() 19 | { 20 | return float4(0.0f, 0.0f, 0.0f, 1.0f); 21 | } 22 | 23 | inline float4 quat_conj(float4 q) 24 | { 25 | return float4(-q.xyz, q.w); 26 | } 27 | 28 | // q must be unit quaternion 29 | inline float4 quat_pow(float4 q, float p) 30 | { 31 | float r = length(q.xyz); 32 | if (r < kEpsilon) 33 | return quat_identity(); 34 | 35 | float t = p * atan2(q.w, r); 36 | 37 | return float4(sin(t) * q.xyz / r, cos(t)); 38 | } 39 | 40 | inline float3 quat_rot(float4 q, float3 v) 41 | { 42 | return 43 | dot(q.xyz, v) * q.xyz 44 | + q.w * q.w * v 45 | + 2.0 * q.w * cross(q.xyz, v) 46 | - cross(cross(q.xyz, v), q.xyz); 47 | } 48 | 49 | inline float4 quat_axis_angle(float3 v, float a) 50 | { 51 | float h = 0.5 * a; 52 | return float4(sin(h) * normalize(v), cos(h)); 53 | } 54 | 55 | inline float4 quat_from_to(float3 from, float3 to) 56 | { 57 | float3 c = cross(from, to); 58 | float cc = dot(c, c); 59 | 60 | if (cc < kEpsilon) 61 | return quat_identity(); 62 | 63 | float3 axis = c / sqrt(cc); 64 | float angle = acos(clamp(dot(from, to), -1.0f, 1.0f)); 65 | return quat_axis_angle(axis, angle); 66 | } 67 | 68 | inline float3 quat_get_axis(float4 q) 69 | { 70 | float d = dot(q.xyz, q.xyz); 71 | return 72 | d > kEpsilon 73 | ? q.xyz / sqrt(d) 74 | : float3(0.0f, 0.0f, 1.0f); 75 | } 76 | 77 | inline float3 quat_get_angle(float4 q) 78 | { 79 | return 2.0f * acos(clamp(q.w, -1.0f, 1.0f)); 80 | } 81 | 82 | inline float4 quat_concat(float4 q1, float4 q2) 83 | { 84 | return 85 | float4 86 | ( 87 | q1.w * q2.xyz + q2.w * q1.xyz + cross(q1.xyz, q2.xyz), 88 | q1.w * q2.w - dot(q1.xyz, q2.xyz) 89 | ); 90 | } 91 | 92 | inline float4 quat_mat(float3x3 m) 93 | { 94 | float tr = m._m00 + m._m11 + m._m22; 95 | if (tr > 0.0f) { 96 | float s = sqrt(tr + 1.0f) * 2.0f; 97 | float sInv = 1.0f / s; 98 | return 99 | float4 100 | ( 101 | (m._m21 - m._m12) * sInv, 102 | (m._m02 - m._m20) * sInv, 103 | (m._m10 - m._m01) * sInv, 104 | 0.25 * s 105 | ); 106 | } 107 | else if ((m._m00 > m._m11) && (m._m00 > m._m22)) 108 | { 109 | float s = sqrt(1.0f + m._m00 - m._m11 - m._m22) * 2.0f; 110 | float sInv = 1.0f / s; 111 | return 112 | float4 113 | ( 114 | 0.25f * s, 115 | (m._m01 + m._m10) * sInv, 116 | (m._m02 + m._m20) * sInv, 117 | (m._m21 - m._m12) * sInv 118 | ); 119 | } 120 | else if (m._m11 > m._m22) 121 | { 122 | float s = sqrt(1.0f + m._m11 - m._m00 - m._m22) * 2.0f; 123 | float sInv = 1.0f / s; 124 | return 125 | float4 126 | ( 127 | (m._m01 + m._m10) * sInv, 128 | 0.25 * s, 129 | (m._m12 + m._m21) * sInv, 130 | (m._m02 - m._m20) * sInv 131 | ); 132 | } 133 | else { 134 | float s = sqrt(1.0f + m._m22 - m._m00 - m._m11) * 2.0f; 135 | float sInv = 1.0f / s; 136 | return 137 | float4 138 | ( 139 | (m._m02 + m._m20) * sInv, 140 | (m._m12 + m._m21) * sInv, 141 | 0.25 * s, 142 | (m._m10 - m._m01) * sInv 143 | ); 144 | } 145 | } 146 | 147 | inline float4 quat_look_at(float3 dir, float3 up) 148 | { 149 | return quat_mat(mat_look_at(dir, up)); 150 | } 151 | 152 | inline float4 slerp(float4 a, float4 b, float t) 153 | { 154 | float d = dot(normalize(a), normalize(b)); 155 | if (d > kEpsilonComp) 156 | { 157 | return lerp(a, b, t); 158 | } 159 | 160 | float r = acos(clamp(d, -1.0f, 1.0f)); 161 | return (sin((1.0 - t) * r) * a + sin(t * r) * b) / sin(r); 162 | } 163 | 164 | inline float4 nlerp(float4 a, float b, float t) 165 | { 166 | return normalize(lerp(a, b, t)); 167 | } 168 | 169 | #endif 170 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Math/Quaternion.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e4acf9f8acb3a9b408dcca8bc0f064ff 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Math/Vector.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | #ifndef CJ_LIB_VECTOR 13 | #define CJ_LIB_VECTOR 14 | 15 | #include "Math.cginc" 16 | 17 | inline float3 unit_x() { return float3(1.0f, 0.0f, 0.0f); } 18 | inline float3 unit_y() { return float3(0.0f, 1.0f, 0.0f); } 19 | inline float3 unit_z() { return float3(0.0f, 0.0f, 1.0f); } 20 | 21 | inline float3 normalize_safe(float3 v, float3 fallback) 22 | { 23 | float vv = dot(v, v); 24 | return vv > kEpsilon ? v / sqrt(vv) : fallback; 25 | } 26 | 27 | inline float3 normalize_safe(float3 v) 28 | { 29 | return normalize_safe(v, unit_z()); 30 | } 31 | 32 | inline float3 project_vec(float3 v, float3 onto) 33 | { 34 | onto = normalize(onto); 35 | return dot(v, onto) * onto; 36 | } 37 | 38 | inline float3 project_plane(float3 v, float3 n) 39 | { 40 | return v - project_vec(v, n); 41 | } 42 | 43 | inline float3 find_ortho(float3 v) 44 | { 45 | if (v.x >= kSqrt3Inv) 46 | return float3(v.y, -v.x, 0.0); 47 | else 48 | return float3(0.0, v.z, -v.y); 49 | } 50 | 51 | inline float3 slerp(float3 a, float3 b, float t) 52 | { 53 | float d = dot(normalize(a), normalize(b)); 54 | if (d > kEpsilonComp) 55 | { 56 | return lerp(a, b, t); 57 | } 58 | 59 | float r = acos(clamp(d, -1.0f, 1.0f)); 60 | return (sin((1.0 - t) * r) * a + sin(t * r) * b) / sin(r); 61 | } 62 | 63 | inline float3 nlerp(float3 a, float b, float t) 64 | { 65 | return normalize(lerp(a, b, t)); 66 | } 67 | 68 | inline float3x3 mat_basis(float3 xAxis, float3 yAxis, float3 zAxis) 69 | { 70 | return transpose(float3x3(xAxis, yAxis, zAxis)); 71 | } 72 | 73 | inline float3x3 mat_look_at(float3 dir, float3 up) 74 | { 75 | float3 zAxis = normalize_safe(dir, unit_z()); 76 | float3 xAxis = normalize_safe(cross(up, zAxis), unit_x()); 77 | float3 yAxis = cross(zAxis, xAxis); 78 | return mat_basis(xAxis, yAxis, zAxis); 79 | } 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Math/Vector.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fa89081643259a543bf0f9f2dc1300cc 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Noise.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 29d5af0e6172a384bb50c6831f2dbd1d 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Noise/ClassicNoise2D.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | 10 | Based on project "webgl-noise" by Ashima Arts. 11 | Description : Array and textureless GLSL 2D simplex noise function. 12 | Author : Ian McEwan, Ashima Arts. 13 | Maintainer : ijm 14 | Lastmod : 20110822 (ijm) 15 | License : Copyright (C) 2011 Ashima Arts. All rights reserved. 16 | Distributed under the MIT License. See LICENSE file. 17 | https://github.com/ashima/webgl-noise 18 | */ 19 | /******************************************************************************/ 20 | 21 | 22 | #ifndef CJ_LIB_CLASSIC_NOISE_2D 23 | #define CJ_LIB_CLASSIC_NOISE_2D 24 | 25 | #include "NoiseCommon.cginc" 26 | 27 | // classic Perlin noise 28 | // single octave 29 | float cnoise(float2 P) 30 | { 31 | float4 Pi = floor(P.xyxy) + float4(0.0, 0.0, 1.0, 1.0); 32 | float4 Pf = frac (P.xyxy) - float4(0.0, 0.0, 1.0, 1.0); 33 | Pi = mod289(Pi); // To avoid truncation effects in permutation 34 | float4 ix = Pi.xzxz; 35 | float4 iy = Pi.yyww; 36 | float4 fx = Pf.xzxz; 37 | float4 fy = Pf.yyww; 38 | 39 | float4 i = permute(permute(ix) + iy); 40 | 41 | float4 gx = frac(i / 41.0) * 2.0 - 1.0 ; 42 | float4 gy = abs(gx) - 0.5 ; 43 | float4 tx = floor(gx + 0.5); 44 | gx = gx - tx; 45 | 46 | float2 g00 = float2(gx.x,gy.x); 47 | float2 g10 = float2(gx.y,gy.y); 48 | float2 g01 = float2(gx.z,gy.z); 49 | float2 g11 = float2(gx.w,gy.w); 50 | 51 | float4 norm = taylorInvSqrt(float4(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11))); 52 | g00 *= norm.x; 53 | g01 *= norm.y; 54 | g10 *= norm.z; 55 | g11 *= norm.w; 56 | 57 | float n00 = dot(g00, float2(fx.x, fy.x)); 58 | float n10 = dot(g10, float2(fx.y, fy.y)); 59 | float n01 = dot(g01, float2(fx.z, fy.z)); 60 | float n11 = dot(g11, float2(fx.w, fy.w)); 61 | 62 | float2 fade_xy = fade(Pf.xy); 63 | float2 n_x = lerp(float2(n00, n01), float2(n10, n11), fade_xy.x); 64 | float n_xy = lerp(n_x.x, n_x.y, fade_xy.y); 65 | return 2.3 * n_xy; 66 | } 67 | 68 | // multiple octaves 69 | DEFINE_NOISE_FUNC_MULTIPLE_OCTAVES(cnoise, float, float2, 0.5); 70 | 71 | // classic Perlin noise, periodic variant 72 | // single octave 73 | float pnoise(float2 P, float2 rep) 74 | { 75 | float4 Pi = floor(P.xyxy) + float4(0.0, 0.0, 1.0, 1.0); 76 | float4 Pf = frac (P.xyxy) - float4(0.0, 0.0, 1.0, 1.0); 77 | Pi = mod(Pi, rep.xyxy); // To create noise with explicit period 78 | Pi = mod289(Pi); // To avoid truncation effects in permutation 79 | float4 ix = Pi.xzxz; 80 | float4 iy = Pi.yyww; 81 | float4 fx = Pf.xzxz; 82 | float4 fy = Pf.yyww; 83 | 84 | float4 i = permute(permute(ix) + iy); 85 | 86 | float4 gx = frac(i / 41.0) * 2.0 - 1.0 ; 87 | float4 gy = abs(gx) - 0.5 ; 88 | float4 tx = floor(gx + 0.5); 89 | gx = gx - tx; 90 | 91 | float2 g00 = float2(gx.x,gy.x); 92 | float2 g10 = float2(gx.y,gy.y); 93 | float2 g01 = float2(gx.z,gy.z); 94 | float2 g11 = float2(gx.w,gy.w); 95 | 96 | float4 norm = taylorInvSqrt(float4(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11))); 97 | g00 *= norm.x; 98 | g01 *= norm.y; 99 | g10 *= norm.z; 100 | g11 *= norm.w; 101 | 102 | float n00 = dot(g00, float2(fx.x, fy.x)); 103 | float n10 = dot(g10, float2(fx.y, fy.y)); 104 | float n01 = dot(g01, float2(fx.z, fy.z)); 105 | float n11 = dot(g11, float2(fx.w, fy.w)); 106 | 107 | float2 fade_xy = fade(Pf.xy); 108 | float2 n_x = lerp(float2(n00, n01), float2(n10, n11), fade_xy.x); 109 | float n_xy = lerp(n_x.x, n_x.y, fade_xy.y); 110 | return 2.3 * n_xy; 111 | } 112 | 113 | // multiple octave 114 | DEFINE_PERIODIC_NOISE_FUNC_MULTIPLE_OCTAVES(pnoise, float, float2); 115 | 116 | #endif 117 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Noise/ClassicNoise2D.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8a0a039eee7b0d048a94b088878a737a 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Noise/ClassicNoise3D.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3bb8e11abde62a34e9b3c23f1b163708 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Noise/Noise.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | 10 | */ 11 | /******************************************************************************/ 12 | 13 | #ifndef NOISE 14 | #define NOISE 15 | 16 | #include "ClassicNoise2D.cginc" 17 | #include "ClassicNoise3D.cginc" 18 | #include "SimplexNoise2D.cginc" 19 | #include "SimplexNoise3D.cginc" 20 | 21 | #include "RandomNoise.cginc" 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Noise/Noise.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5428bc95309813640956652494e668d1 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Noise/NoiseCommon.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d888eae3bfbc1b44dadb3c139a77443a 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Noise/RandomNoise.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | 10 | Based on an Andy Gryc's version of the common one-line shader random noise 11 | http://byteblacksmith.com/improvements-to-the-canonical-one-liner-glsl-rand/ 12 | 13 | */ 14 | /******************************************************************************/ 15 | 16 | 17 | #ifndef CJ_LIB_RANDOM_NOISE 18 | #define CJ_LIB_RANDOM_NOISE 19 | 20 | #include "NoiseCommon.cginc" 21 | 22 | float rand(float s) 23 | { 24 | return frac(sin(mod(s, 6.2831853)) * 43758.5453123); 25 | } 26 | 27 | 28 | float rand(float2 s) 29 | { 30 | float d = dot(s + 0.1234567, float2(1111112.9819837, 78.237173)); 31 | float m = mod(d, 6.2831853); 32 | return frac(sin(m) * 43758.5453123); 33 | } 34 | 35 | float rand(float3 s) 36 | { 37 | float d = dot(s + 0.1234567, float3(11112.9819837, 378.237173, 3971977.9173179)); 38 | float m = mod(d, 6.2831853); 39 | return frac(sin(m) * 43758.5453123); 40 | } 41 | 42 | float rand_range(float s, float a, float b) 43 | { 44 | return a + (b - a) * rand(s); 45 | } 46 | 47 | float2 rand_range(float2 s, float2 a, float2 b) 48 | { 49 | return a + (b - a) * rand(s); 50 | } 51 | 52 | float3 rand_range(float3 s, float3 a, float3 b) 53 | { 54 | return a + (b - a) * rand(s); 55 | } 56 | 57 | float2 rand_uvec(float2 s) 58 | { 59 | return normalize(float2(rand(s), rand(s * 1.23456789)) - 0.5); 60 | } 61 | 62 | float3 rand_uvec(float3 s) 63 | { 64 | return normalize(float3(rand(s), rand(s * 1.23456789), rand(s * 9876.54321)) - 0.5); 65 | } 66 | 67 | float2 rand_vec(float2 s) 68 | { 69 | return rand_uvec(s) * rand(s * 9876.54321); 70 | } 71 | 72 | float3 rand_vec(float3 s) 73 | { 74 | return rand_uvec(s) * rand(s * 1357975.31313); 75 | } 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Noise/RandomNoise.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d6d41152c5085d749b5d5d890fa0dc81 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Noise/Resources.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1fd5ac2c904801a478dcc3481cdc9ce4 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Noise/Resources/ClassicNoiseCs.compute: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | #pragma kernel ClassicGrid2 13 | #pragma kernel ClassicGrid3 14 | #pragma kernel ClassicCustom2 15 | #pragma kernel ClassicCustom3 16 | 17 | #include "../ClassicNoise2D.cginc" 18 | #include "../ClassicNoise3D.cginc" 19 | #include "../RandomNoise.cginc" 20 | 21 | RWStructuredBuffer input2; 22 | RWStructuredBuffer input3; 23 | RWStructuredBuffer output; 24 | 25 | int3 dimension; 26 | float3 scale; 27 | float3 offset; 28 | int numOctaves; 29 | float octaveOffsetFactor; 30 | 31 | [numthreads(1, 1, 1)] 32 | void ClassicGrid2(uint3 id : SV_DispatchThreadID) 33 | { 34 | float2 s = id.xy / scale.xy; 35 | output[index(id, dimension)] = 36 | cnoise(s, offset.xy, numOctaves, octaveOffsetFactor); 37 | } 38 | 39 | [numthreads(1, 1, 1)] 40 | void ClassicGrid3(uint3 id : SV_DispatchThreadID) 41 | { 42 | float3 s = id / scale; 43 | output[index(id, dimension)] = 44 | cnoise(s, offset, numOctaves, octaveOffsetFactor); 45 | } 46 | 47 | [numthreads(1, 1, 1)] 48 | void ClassicCustom2(uint3 id : SV_DispatchThreadID) 49 | { 50 | float2 s = input2[id.x] / scale.xy; 51 | output[id.x] = 52 | cnoise(s, offset.xy, numOctaves, octaveOffsetFactor); 53 | } 54 | 55 | [numthreads(1, 1, 1)] 56 | void ClassicCustom3(uint3 id : SV_DispatchThreadID) 57 | { 58 | float3 s = input3[id.x] / scale; 59 | output[id.x] = 60 | cnoise(s, offset, numOctaves, octaveOffsetFactor); 61 | } 62 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Noise/Resources/ClassicNoiseCs.compute.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2d47a6b2a48ecf647875c4bedbc8d0c2 3 | ComputeShaderImporter: 4 | externalObjects: {} 5 | currentAPIMask: 4 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Noise/Resources/ClassicNoisePeriodicCs.compute: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | #pragma kernel ClassicPeriodicGrid2 13 | #pragma kernel ClassicPeriodicGrid3 14 | #pragma kernel ClassicPeriodicCustom2 15 | #pragma kernel ClassicPeriodicCustom3 16 | 17 | #include "../ClassicNoise2D.cginc" 18 | #include "../ClassicNoise3D.cginc" 19 | 20 | RWStructuredBuffer input2; 21 | RWStructuredBuffer input3; 22 | RWStructuredBuffer output; 23 | 24 | int3 dimension; 25 | float3 scale; 26 | float3 offset; 27 | float3 period; 28 | int numOctaves; 29 | float octaveOffsetFactor; 30 | 31 | [numthreads(1, 1, 1)] 32 | void ClassicPeriodicGrid2(uint3 id : SV_DispatchThreadID) 33 | { 34 | float2 s = id.xy / scale.xy; 35 | output[index(id, dimension)] = 36 | pnoise(s, offset.xy, period.xy, numOctaves, octaveOffsetFactor); 37 | } 38 | 39 | [numthreads(1, 1, 1)] 40 | void ClassicPeriodicGrid3(uint3 id : SV_DispatchThreadID) 41 | { 42 | float3 s = id / scale; 43 | output[index(id, dimension)] = 44 | pnoise(s, offset, period, numOctaves, octaveOffsetFactor); 45 | } 46 | 47 | [numthreads(1, 1, 1)] 48 | void ClassicPeriodicCustom2(uint3 id : SV_DispatchThreadID) 49 | { 50 | float2 s = input2[id.x] / scale.xy; 51 | output[id.x] = 52 | pnoise(s, offset.xy, period.xy, numOctaves, octaveOffsetFactor); 53 | } 54 | 55 | [numthreads(1, 1, 1)] 56 | void ClassicPeriodicCustom3(uint3 id : SV_DispatchThreadID) 57 | { 58 | float3 s = input3[id.x] / scale; 59 | output[id.x] = 60 | pnoise(s, offset, period, numOctaves, octaveOffsetFactor); 61 | } 62 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Noise/Resources/ClassicNoisePeriodicCs.compute.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: afe6add88b0b89d448b26e6e3dc5f59b 3 | ComputeShaderImporter: 4 | externalObjects: {} 5 | currentAPIMask: 4 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Noise/Resources/RandomNoiseCs.compute: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | #pragma kernel RandomGrid1 13 | #pragma kernel RandomGrid2 14 | #pragma kernel RandomGrid3 15 | 16 | #include "../RandomNoise.cginc" 17 | 18 | RWStructuredBuffer output; 19 | 20 | float seed; 21 | int3 dimension; 22 | 23 | [numthreads(1, 1, 1)] 24 | void RandomGrid1(uint3 id : SV_DispatchThreadID) 25 | { 26 | output[index(id, dimension)] = rand(seed + id.x); 27 | } 28 | 29 | [numthreads(1, 1, 1)] 30 | void RandomGrid2(uint3 id : SV_DispatchThreadID) 31 | { 32 | output[index(id, dimension)] = rand(seed + id.xy); 33 | } 34 | 35 | [numthreads(1, 1, 1)] 36 | void RandomGrid3(uint3 id : SV_DispatchThreadID) 37 | { 38 | output[index(id, dimension)] = rand(seed + id.xyz); 39 | } 40 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Noise/Resources/RandomNoiseCs.compute.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 17f67342dcf81694fbd8e72def0acced 3 | ComputeShaderImporter: 4 | externalObjects: {} 5 | currentAPIMask: 4 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Noise/Resources/RandomNoiseVectorCs.compute: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | #pragma kernel RandomVec2 13 | #pragma kernel RandomVec3 14 | 15 | #include "../RandomNoise.cginc" 16 | 17 | RWStructuredBuffer output2; 18 | RWStructuredBuffer output3; 19 | 20 | float seed; 21 | int3 dimension; 22 | 23 | [numthreads(1, 1, 1)] 24 | void RandomVec2(uint3 id : SV_DispatchThreadID) 25 | { 26 | output2[index(id, dimension)] = rand_vec(seed + id.xy); 27 | } 28 | 29 | [numthreads(1, 1, 1)] 30 | void RandomVec3(uint3 id : SV_DispatchThreadID) 31 | { 32 | output3[index(id, dimension)] = rand_vec(seed + id.xyz); 33 | } -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Noise/Resources/RandomNoiseVectorCs.compute.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: db6578c993355594ba41b3c1335a9adf 3 | ComputeShaderImporter: 4 | externalObjects: {} 5 | currentAPIMask: 4 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Noise/Resources/SimplexNoiseCs.compute: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | #pragma kernel SimplexGrid2 13 | #pragma kernel SimplexGrid3 14 | #pragma kernel SimplexCustom2 15 | #pragma kernel SimplexCustom3 16 | 17 | #include "../SimplexNoise2D.cginc" 18 | #include "../SimplexNoise3D.cginc" 19 | #include "../RandomNoise.cginc" 20 | 21 | RWStructuredBuffer input2; 22 | RWStructuredBuffer input3; 23 | RWStructuredBuffer output; 24 | 25 | int3 dimension; 26 | float3 scale; 27 | float3 offset; 28 | int numOctaves; 29 | float octaveOffsetFactor; 30 | 31 | [numthreads(1, 1, 1)] 32 | void SimplexGrid2(uint3 id : SV_DispatchThreadID) 33 | { 34 | float2 s = id.xy / scale.xy; 35 | output[index(id, dimension)] = 36 | snoise(s, offset.xy, numOctaves, octaveOffsetFactor); 37 | } 38 | 39 | [numthreads(1, 1, 1)] 40 | void SimplexGrid3(uint3 id : SV_DispatchThreadID) 41 | { 42 | float3 s = id / scale; 43 | output[index(id, dimension)] = 44 | snoise(s, offset, numOctaves, octaveOffsetFactor); 45 | } 46 | 47 | [numthreads(1, 1, 1)] 48 | void SimplexCustom2(uint3 id : SV_DispatchThreadID) 49 | { 50 | float2 s = input2[id.x] / scale.xy; 51 | output[id.x] = 52 | snoise(s, offset.xy, numOctaves, octaveOffsetFactor); 53 | } 54 | 55 | [numthreads(1, 1, 1)] 56 | void SimplexCustom3(uint3 id : SV_DispatchThreadID) 57 | { 58 | float3 s = input3[id.x] / scale; 59 | output[id.x] = 60 | snoise(s, offset, numOctaves, octaveOffsetFactor); 61 | } 62 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Noise/Resources/SimplexNoiseCs.compute.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4eb8152e697df05409038674dbc8bb4b 3 | ComputeShaderImporter: 4 | externalObjects: {} 5 | currentAPIMask: 4 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Noise/Resources/SimplexNoiseGradientCs.compute: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | 13 | #pragma kernel SimplexGradientGrid2 14 | #pragma kernel SimplexGradientGrid3 15 | #pragma kernel SimplexGradientCustom2 16 | #pragma kernel SimplexGradientCustom3 17 | 18 | #include "../SimplexNoise2D.cginc" 19 | #include "../SimplexNoise3D.cginc" 20 | 21 | RWStructuredBuffer input2; 22 | RWStructuredBuffer input3; 23 | RWStructuredBuffer output2; 24 | RWStructuredBuffer output3; 25 | 26 | int3 dimension; 27 | float3 scale; 28 | float3 offset; 29 | int numOctaves; 30 | float octaveOffsetFactor; 31 | 32 | // grid sample points 33 | [numthreads(1, 1, 1)] 34 | void SimplexGradientGrid2(uint3 id : SV_DispatchThreadID) 35 | { 36 | float2 s = id.xy / scale.xy; 37 | output2[index(id, dimension)] = 38 | snoise_grad(s, offset.xy, numOctaves, octaveOffsetFactor).xy; 39 | } 40 | 41 | // grid sample points 42 | [numthreads(1, 1, 1)] 43 | void SimplexGradientGrid3(uint3 id : SV_DispatchThreadID) 44 | { 45 | float3 s = id / scale; 46 | output3[index(id, dimension)] = 47 | snoise_grad(s, offset, numOctaves, octaveOffsetFactor).xyz; 48 | } 49 | 50 | // custom sample points 51 | [numthreads(1, 1, 1)] 52 | void SimplexGradientCustom2(uint3 id : SV_DispatchThreadID) 53 | { 54 | float2 s = input2[id.x] / scale.xy; 55 | output2[id.x] = 56 | snoise_grad(s, offset.xy, numOctaves, octaveOffsetFactor).xy; 57 | } 58 | 59 | // custom sample points 60 | [numthreads(1, 1, 1)] 61 | void SimplexGradientCustom3(uint3 id : SV_DispatchThreadID) 62 | { 63 | float3 s = input3[id.x] / scale; 64 | output3[id.x] = 65 | snoise_grad(s, offset, numOctaves, octaveOffsetFactor).xyz; 66 | } 67 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Noise/Resources/SimplexNoiseGradientCs.compute.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7957dd6eaa0f4074383bdba2b668fe69 3 | ComputeShaderImporter: 4 | externalObjects: {} 5 | currentAPIMask: 4 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Noise/SimplexNoise2D.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | 10 | Based on project "webgl-noise" by Ashima Arts. 11 | Description : Array and textureless GLSL 2D simplex noise function. 12 | Author : Ian McEwan, Ashima Arts. 13 | Maintainer : ijm 14 | Lastmod : 20110822 (ijm) 15 | License : Copyright (C) 2011 Ashima Arts. All rights reserved. 16 | Distributed under the MIT License. See LICENSE file. 17 | https://github.com/ashima/webgl-noise 18 | */ 19 | /******************************************************************************/ 20 | 21 | #ifndef CJ_LIB_SIMPLEX_NOISE_2D 22 | #define CJ_LIB_SIMPLEX_NOISE_2D 23 | 24 | #include "NoiseCommon.cginc" 25 | 26 | // single octave 27 | float snoise(float2 v) 28 | { 29 | const float4 C = float4( 0.211324865405187, // (3.0-sqrt(3.0))/6.0 30 | 0.366025403784439, // 0.5*(sqrt(3.0)-1.0) 31 | -0.577350269189626, // -1.0 + 2.0 * C.x 32 | 0.024390243902439); // 1.0 / 41.0 33 | // First corner 34 | float2 i = floor(v + dot(v, C.yy)); 35 | float2 x0 = v - i + dot(i, C.xx); 36 | 37 | // Other corners 38 | float2 i1; 39 | i1.x = step(x0.y, x0.x); 40 | i1.y = 1.0 - i1.x; 41 | 42 | // x1 = x0 - i1 + 1.0 * C.xx; 43 | // x2 = x0 - 1.0 + 2.0 * C.xx; 44 | float2 x1 = x0 + C.xx - i1; 45 | float2 x2 = x0 + C.zz; 46 | 47 | // Permutations 48 | i = mod289(i); // Avoid truncation effects in permutation 49 | float3 p = 50 | permute(permute(i.y + float3(0.0, i1.y, 1.0)) 51 | + i.x + float3(0.0, i1.x, 1.0)); 52 | 53 | float3 m = max(0.5 - float3(dot(x0, x0), dot(x1, x1), dot(x2, x2)), 0.0); 54 | m = m * m; 55 | m = m * m; 56 | 57 | // Gradients: 41 points uniformly over a line, mapped onto a diamond. 58 | // The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287) 59 | float3 x = 2.0 * frac(p * C.www) - 1.0; 60 | float3 h = abs(x) - 0.5; 61 | float3 ox = floor(x + 0.5); 62 | float3 a0 = x - ox; 63 | 64 | // Normalise gradients implicitly by scaling m 65 | m *= taylorInvSqrt(a0 * a0 + h * h); 66 | 67 | // Compute final noise value at P 68 | float3 g; 69 | g.x = a0.x * x0.x + h.x * x0.y; 70 | g.y = a0.y * x1.x + h.y * x1.y; 71 | g.z = a0.z * x2.x + h.z * x2.y; 72 | return 130.0 * dot(m, g); 73 | } 74 | 75 | // multiple octaves 76 | DEFINE_NOISE_FUNC_MULTIPLE_OCTAVES(snoise, float, float2, 0.5); 77 | 78 | // single octave 79 | float3 snoise_grad(float2 v) 80 | { 81 | const float4 C = float4( 0.211324865405187, // (3.0-sqrt(3.0))/6.0 82 | 0.366025403784439, // 0.5*(sqrt(3.0)-1.0) 83 | -0.577350269189626, // -1.0 + 2.0 * C.x 84 | 0.024390243902439); // 1.0 / 41.0 85 | // First corner 86 | float2 i = floor(v + dot(v, C.yy)); 87 | float2 x0 = v - i + dot(i, C.xx); 88 | 89 | // Other corners 90 | float2 i1; 91 | i1.x = step(x0.y, x0.x); 92 | i1.y = 1.0 - i1.x; 93 | 94 | // x1 = x0 - i1 + 1.0 * C.xx; 95 | // x2 = x0 - 1.0 + 2.0 * C.xx; 96 | float2 x1 = x0 + C.xx - i1; 97 | float2 x2 = x0 + C.zz; 98 | 99 | // Permutations 100 | i = mod289(i); // Avoid truncation effects in permutation 101 | float3 p = 102 | permute(permute(i.y + float3(0.0, i1.y, 1.0)) 103 | + i.x + float3(0.0, i1.x, 1.0)); 104 | 105 | float3 m = max(0.5 - float3(dot(x0, x0), dot(x1, x1), dot(x2, x2)), 0.0); 106 | float3 m2 = m * m; 107 | float3 m3 = m2 * m; 108 | float3 m4 = m2 * m2; 109 | 110 | // Gradients: 41 points uniformly over a line, mapped onto a diamond. 111 | // The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287) 112 | float3 x = 2.0 * frac(p * C.www) - 1.0; 113 | float3 h = abs(x) - 0.5; 114 | float3 ox = floor(x + 0.5); 115 | float3 a0 = x - ox; 116 | 117 | // Normalise gradients 118 | float3 norm = taylorInvSqrt(a0 * a0 + h * h); 119 | float2 g0 = float2(a0.x, h.x) * norm.x; 120 | float2 g1 = float2(a0.y, h.y) * norm.y; 121 | float2 g2 = float2(a0.z, h.z) * norm.z; 122 | 123 | // Compute noise and gradient at P 124 | float2 grad = 125 | -6.0 * m3.x * x0 * dot(x0, g0) + m4.x * g0 + 126 | -6.0 * m3.y * x1 * dot(x1, g1) + m4.y * g1 + 127 | -6.0 * m3.z * x2 * dot(x2, g2) + m4.z * g2; 128 | float3 px = float3(dot(x0, g0), dot(x1, g1), dot(x2, g2)); 129 | return 130.0 * float3(grad, dot(m4, px)); 130 | } 131 | 132 | // multiple octaves 133 | DEFINE_NOISE_FUNC_MULTIPLE_OCTAVES(snoise_grad, float3, float2, 0.0); 134 | 135 | #endif 136 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Noise/SimplexNoise2D.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c05b16f88a1d0ba419095712496e35e6 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Noise/SimplexNoise3D.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c474d07a7f2949a45b86bf61f6a3fa29 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Physics.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3eaa3e9ee906aa0498047407a76af341 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Physics/Physics.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | #ifndef CJ_LIB_PHYSICS 13 | #define CJ_LIB_PHYSICS 14 | 15 | 16 | #include "../Math/Math.cginc" 17 | 18 | 19 | // common 20 | //----------------------------------------------------------------------------- 21 | 22 | struct CollisionResult 23 | { 24 | float3 position; 25 | float3 velocity; 26 | }; 27 | 28 | inline CollisionResult resolveCollision(float3 pos, float3 norm, float3 vel, float penetration, float restitution, float friction) 29 | { 30 | float d = dot(vel, norm); // projected relative speed onto contact normal 31 | float f = -d / length(vel); // ratio of relative speed along contact normal 32 | float3 velN = d * norm; // normal relative velocity 33 | float3 velT = vel - velN; // tangential relative velocity 34 | float3 velResolution = -(1.0 + restitution) * velN - friction * f * velT; 35 | 36 | CollisionResult res; 37 | res.position = pos + penetration * norm; 38 | res.velocity = vel + step(kEpsilon, penetration) * velResolution; 39 | return res; 40 | } 41 | 42 | //----------------------------------------------------------------------------- 43 | // end: common 44 | 45 | 46 | // VS plane 47 | //----------------------------------------------------------------------------- 48 | 49 | inline CollisionResult pointVsPlane(float3 p, float4 plane, float3 vel, float restitution, float friction) 50 | { 51 | float penetration = max(0.0, -dot(float4(p, 1.0), plane)); 52 | float3 norm = plane.xyz; 53 | return resolveCollision(p, norm, vel, penetration, restitution, friction); 54 | } 55 | 56 | inline CollisionResult sphereVsPlane(float4 s, float4 plane, float3 vel, float restitution, float friction) 57 | { 58 | float penetration = max(0.0, s.w - dot(float4(s.xyz, 1.0), plane)); 59 | float3 norm = plane.xyz; 60 | return resolveCollision(s.xyz, norm, vel, penetration, restitution, friction); 61 | } 62 | 63 | //----------------------------------------------------------------------------- 64 | // end: VS plane 65 | 66 | 67 | // VS sphere 68 | //----------------------------------------------------------------------------- 69 | 70 | inline CollisionResult pointVsSphere(float3 p, float4 sphere, float3 vel, float restitution, float friction) 71 | { 72 | float3 centerDiff = p - sphere.xyz; 73 | float centerDiffLen = length(centerDiff); 74 | float penetration = max(0.0, sphere.w - centerDiffLen); 75 | float3 norm = centerDiff / centerDiffLen; 76 | return resolveCollision(p, norm, vel, penetration, restitution, friction); 77 | } 78 | 79 | inline CollisionResult sphereVsSphere(float4 s, float4 sphere, float3 vel, float restitution, float friction) 80 | { 81 | float3 centerDiff = s.xyz - sphere.xyz; 82 | float centerDiffLen = length(centerDiff); 83 | float penetration = max(0.0, s.w + sphere.w - centerDiffLen); 84 | float3 norm = centerDiff / centerDiffLen; 85 | return resolveCollision(s.xyz, norm, vel, penetration, restitution, friction); 86 | } 87 | 88 | //----------------------------------------------------------------------------- 89 | // end: VS sphere 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Physics/Physics.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7a57aa193bee1d6498620b4468cf25d7 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Render.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0fd18b40526c4584bb9bcebda9c06062 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Render/Forward.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | #ifndef CJ_LIB_FORWARD 13 | #define CJ_LIB_FORWARD 14 | 15 | #include "UnityStandardCore.cginc" 16 | 17 | #define CJ_LIB_SHADE_MAIN_LIGHT(v, posWs, normWs) \ 18 | ( \ 19 | dot(normWs, normalize(WorldSpaceLightDir(float4(posWs.xyz, 1.0)))) \ 20 | * LIGHT_ATTENUATION(v) \ 21 | ) 22 | 23 | #define CJ_LIB_SHADE_POINT_LIGHTS(posWs, normWs) \ 24 | ( \ 25 | Shade4PointLights \ 26 | ( \ 27 | unity_4LightPosX0, \ 28 | unity_4LightPosY0, \ 29 | unity_4LightPosZ0, \ 30 | unity_LightColor[0].rgb, \ 31 | unity_LightColor[1].rgb, \ 32 | unity_LightColor[2].rgb, \ 33 | unity_LightColor[3].rgb, \ 34 | unity_4LightAtten0, \ 35 | posWs.xyz, \ 36 | normWs.xyz \ 37 | ) \ 38 | ) 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/CjLib/Shader/Render/Forward.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 79c286afcc217ff498d2659c8c5d82b1 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b96b0cf5a1ffddd4cbc250d2335d90e2 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Debug Draw Components.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d2ab0f89e46a4624cb9c5601dcbc0d18 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Debug Draw Components/Debug Draw Components.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a095076f6ea43af4ca2878a103420ffe 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Debug Draw Meshes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9cb260535a09a58418a879279a230c51 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Debug Draw Meshes/CjLibDebugUtilDemo.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7fae6f74a7cd3c64c85a14add7b2e90c 3 | timeCreated: 1506321043 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Debug Draw Meshes/Debug Draw Meshes.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fcd4b8593bb25da419ab92a78d72a40d 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Debug Draw Meshes/GizmosUtilDemoComponent.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using CjLib; 5 | 6 | public class GizmosUtilDemoComponent : MonoBehaviour 7 | { 8 | public enum Primitive 9 | { 10 | Arrow, 11 | Box, 12 | Capsule, 13 | Cone, 14 | Cylinder, 15 | Sphere, 16 | }; 17 | 18 | public Primitive m_primitive = Primitive.Box; 19 | public GizmosUtil.Style m_style = GizmosUtil.Style.FlatShaded; 20 | public Color m_color = Color.white; 21 | 22 | [Range(0.1f, 10.0f)] 23 | public float m_width = 1.0f; 24 | 25 | [Range(0.1f, 10.0f)] 26 | public float m_depth = 1.0f; 27 | 28 | [Range(0.1f, 10.0f)] 29 | public float m_height = 1.0f; 30 | 31 | [Range(0.1f, 10.0f)] 32 | public float m_radius = 0.5f; 33 | 34 | [Range(0.05f, 0.2f)] 35 | public float m_arrowTipSize = 0.1f; 36 | 37 | [Range(2, 32)] 38 | public int m_latSegments = 8; 39 | 40 | [Range(2, 32)] 41 | public int m_longSegments = 16; 42 | 43 | void OnDrawGizmos() 44 | { 45 | float width = m_width * Mathf.Abs(transform.localScale.x); 46 | float height = m_height * Mathf.Abs(transform.localScale.y); 47 | float depth = m_depth * Mathf.Abs(transform.localScale.z); 48 | float radius = m_radius * 0.5f * Mathf.Abs(transform.localScale.x + transform.localScale.z); 49 | 50 | switch (m_primitive) 51 | { 52 | case Primitive.Arrow: 53 | Vector3 axisY = transform.rotation * Vector3.up; 54 | Vector3 endOffset = 0.5f * height * axisY; 55 | GizmosUtil.DrawArrow(transform.position - endOffset, transform.position + endOffset, m_arrowTipSize, 2.0f * m_arrowTipSize, m_latSegments, 0.0f, m_color, m_style); 56 | break; 57 | case Primitive.Box: 58 | GizmosUtil.DrawBox(transform.position, transform.rotation, new Vector3(width, height, depth), m_color, m_style); 59 | break; 60 | case Primitive.Capsule: 61 | GizmosUtil.DrawCapsule(transform.position, transform.rotation, height, radius, m_latSegments, m_longSegments, m_color, m_style); 62 | break; 63 | case Primitive.Cone: 64 | GizmosUtil.DrawCone(transform.position, transform.rotation, height, radius, m_longSegments, m_color, m_style); 65 | break; 66 | case Primitive.Cylinder: 67 | GizmosUtil.DrawCylinder(transform.position, transform.rotation, height, radius, m_longSegments, m_color, m_style); 68 | break; 69 | case Primitive.Sphere: 70 | GizmosUtil.DrawSphere(transform.position, transform.rotation, radius, m_latSegments, m_longSegments, m_color, m_style); 71 | break; 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Debug Draw Meshes/GizmosUtilDemoComponent.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a9e5b4fed39c0134b9602241ce09d11f 3 | timeCreated: 1509866656 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/GPU Particles with Colliders.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9fe21ef1b59e7614d91d8a43a50dcd88 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/GPU Particles with Colliders/GPU Particles with Colliders.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 88094152c1599b549bbcd9e10cca3451 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/GPU Particles with Colliders/Main.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bd8c70e0c90dcc34b9377f55c9250be8 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: 7 | - m_shader: {fileID: 7200000, guid: 230a25ffd14974e4da0aceca97604204, type: 3} 8 | - m_material: {fileID: 2100000, guid: 0695fc9db65d4d544a7abaf0e6bec756, type: 2} 9 | - m_spherePrefab: {fileID: 1904052554886110, guid: 808c6ede839820a4180c79912af3e1a2, 10 | type: 2} 11 | - m_floorPrefab: {fileID: 1113924760286158, guid: 2b1a709b1fe816e4a8dd3f429ecbff09, 12 | type: 2} 13 | executionOrder: 0 14 | icon: {instanceID: 0} 15 | userData: 16 | assetBundleName: 17 | assetBundleVariant: 18 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/GPU Particles with Colliders/Particle.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 6 6 | m_ObjectHideFlags: 0 7 | m_CorrespondingSourceObject: {fileID: 0} 8 | m_PrefabInternal: {fileID: 0} 9 | m_Name: Particle 10 | m_Shader: {fileID: 4800000, guid: c459bb87522bdc743b25e3180ee9990a, type: 3} 11 | m_ShaderKeywords: 12 | m_LightmapFlags: 4 13 | m_EnableInstancingVariants: 1 14 | m_DoubleSidedGI: 0 15 | m_CustomRenderQueue: -1 16 | stringTagMap: {} 17 | disabledShaderPasses: [] 18 | m_SavedProperties: 19 | serializedVersion: 3 20 | m_TexEnvs: 21 | - _BumpMap: 22 | m_Texture: {fileID: 0} 23 | m_Scale: {x: 1, y: 1} 24 | m_Offset: {x: 0, y: 0} 25 | - _DetailAlbedoMap: 26 | m_Texture: {fileID: 0} 27 | m_Scale: {x: 1, y: 1} 28 | m_Offset: {x: 0, y: 0} 29 | - _DetailMask: 30 | m_Texture: {fileID: 0} 31 | m_Scale: {x: 1, y: 1} 32 | m_Offset: {x: 0, y: 0} 33 | - _DetailNormalMap: 34 | m_Texture: {fileID: 0} 35 | m_Scale: {x: 1, y: 1} 36 | m_Offset: {x: 0, y: 0} 37 | - _EmissionMap: 38 | m_Texture: {fileID: 0} 39 | m_Scale: {x: 1, y: 1} 40 | m_Offset: {x: 0, y: 0} 41 | - _MainTex: 42 | m_Texture: {fileID: 0} 43 | m_Scale: {x: 1, y: 1} 44 | m_Offset: {x: 0, y: 0} 45 | - _MetallicGlossMap: 46 | m_Texture: {fileID: 0} 47 | m_Scale: {x: 1, y: 1} 48 | m_Offset: {x: 0, y: 0} 49 | - _OcclusionMap: 50 | m_Texture: {fileID: 0} 51 | m_Scale: {x: 1, y: 1} 52 | m_Offset: {x: 0, y: 0} 53 | - _ParallaxMap: 54 | m_Texture: {fileID: 0} 55 | m_Scale: {x: 1, y: 1} 56 | m_Offset: {x: 0, y: 0} 57 | m_Floats: 58 | - _BumpScale: 1 59 | - _Cutoff: 0.5 60 | - _DetailNormalMapScale: 1 61 | - _DstBlend: 0 62 | - _GlossMapScale: 1 63 | - _Glossiness: 0.5 64 | - _GlossyReflections: 1 65 | - _Metallic: 0 66 | - _Mode: 0 67 | - _OcclusionStrength: 1 68 | - _Parallax: 0.02 69 | - _SmoothnessTextureChannel: 0 70 | - _SpecularHighlights: 1 71 | - _SrcBlend: 1 72 | - _UVSec: 0 73 | - _ZWrite: 1 74 | m_Colors: 75 | - _Color: {r: 1, g: 1, b: 1, a: 1} 76 | - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} 77 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/GPU Particles with Colliders/Particle.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0695fc9db65d4d544a7abaf0e6bec756 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 2100000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/GPU Particles with Colliders/Particle.shader: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | Shader "CjLib/Example/GpuParticlesWithColliders" 13 | { 14 | SubShader 15 | { 16 | Tags { "RenderType" = "Opaque" } 17 | 18 | Pass 19 | { 20 | Name "Deferred" 21 | Tags { "LightMode" = "Deferred" } 22 | CGPROGRAM 23 | #pragma target 5.0 24 | #pragma vertex vert 25 | #pragma fragment frag 26 | #pragma multi_compile_instancing 27 | #define PASS_DEFERRED 28 | #include "ParticleCore.cginc" 29 | ENDCG 30 | } 31 | 32 | Pass 33 | { 34 | Name "Shadow Caster" 35 | Tags { "LightMode" = "ShadowCaster" } 36 | CGPROGRAM 37 | #pragma target 5.0 38 | #pragma vertex vert 39 | #pragma fragment frag 40 | #pragma multi_compile_instancing 41 | #define PASS_SHADOW_CASTER 42 | #include "ParticleCore.cginc" 43 | ENDCG 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/GPU Particles with Colliders/Particle.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c459bb87522bdc743b25e3180ee9990a 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/GPU Particles with Colliders/ParticleCore.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | #include "AutoLight.cginc" 13 | #include "UnityCG.cginc" 14 | 15 | #include "../../CjLib/Shader/Math/Math.cginc" 16 | 17 | #include "ParticleStruct.cginc" 18 | 19 | struct appdata 20 | { 21 | float4 posOs : POSITION; 22 | float3 normOs : NORMAL; 23 | uint id : SV_InstanceId; 24 | }; 25 | 26 | struct v2f 27 | { 28 | float4 posCs : SV_POSITION; 29 | float3 normWs : NORMAL; 30 | float4 color : COLOR0; 31 | }; 32 | 33 | struct fout 34 | { 35 | fixed4 c0 : COLOR0; // diffuse (rgb), occlusion (a) 36 | fixed4 c1 : COLOR1; // spec (rgb), smoothness (a) 37 | fixed4 c2 : COLOR2; // normalWs (rgb), 38 | fixed4 c3 : COLOR3; // emission 39 | }; 40 | 41 | StructuredBuffer particleBuffer; 42 | float4x4 viewMatrix; 43 | float4x4 projMatrix; 44 | 45 | v2f vert(appdata i) 46 | { 47 | v2f o; 48 | 49 | Particle p = particleBuffer[i.id]; 50 | 51 | float scale = 52 | lerp 53 | ( 54 | 0.0, 55 | lerp(0.0, p.scale, saturate(p.lifetime.w / p.lifetime.x)), 56 | saturate(dot(p.lifetime, float4(1.0, 1.0, 1.0, -1.0)) / p.lifetime.z) 57 | ); 58 | 59 | float3 posWs = 60 | p.position 61 | + scale * quat_rot(p.rotation, i.posOs.xyz); 62 | 63 | o.posCs = UnityObjectToClipPos(posWs); 64 | o.normWs = quat_rot(p.rotation, i.normOs); 65 | o.color = p.color; 66 | 67 | return o; 68 | } 69 | 70 | fout frag(v2f i) 71 | { 72 | fout o; 73 | 74 | o.c0 = i.color; 75 | o.c1.rgb = 0.0; 76 | o.c1.a = 1.0; 77 | o.c2.rgb = i.normWs; 78 | o.c2.a = 0.0; 79 | o.c3 = 0.3 * i.color; 80 | 81 | return o; 82 | } 83 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/GPU Particles with Colliders/ParticleCore.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 51b1d8b6d7c31ae43b6ecf3bf70c07f7 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/GPU Particles with Colliders/ParticleLogic.compute: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | #pragma kernel Init 13 | #pragma kernel Step 14 | 15 | #include "../../CjLib/Shader/Math/Math.cginc" 16 | #include "../../CjLib/Shader/Noise/Noise.cginc" 17 | #include "../../CjLib/Shader/Physics/Physics.cginc" 18 | 19 | #include "ParticleStruct.cginc" 20 | 21 | RWStructuredBuffer particleBuffer; 22 | 23 | float2 scale; // (min, max) 24 | float damping; 25 | float4 speed; // (min linear, max linear, min angular, max angular) 26 | float4 lifetime; // (head, min body, max body, tail) 27 | 28 | int numParticles; 29 | 30 | [numthreads(1, 1, 1)] 31 | void Init(uint3 id : SV_DispatchThreadID) 32 | { 33 | float t = float(id.x) / float(numParticles); 34 | float3 seed = id.x; 35 | 36 | particleBuffer[id.x].position = float3(0.0, 3.0, 0.0); 37 | 38 | float3 rotationAxis = rand_uvec(seed); 39 | seed = rand_vec(seed); 40 | float rotationAngle = rand(seed.x) * kPi; 41 | seed = rand_vec(seed); 42 | particleBuffer[id.x].rotation = quat_axis_angle(rotationAxis, rotationAngle); 43 | 44 | particleBuffer[id.x].scale = rand_range(seed.x, scale.x, scale.y); 45 | seed = rand_vec(seed); 46 | 47 | particleBuffer[id.x].damping = damping; 48 | 49 | float3 linearDirection = normalize(rand_vec(seed)); 50 | seed = rand_vec(seed); 51 | float linearSpeed = rand_range(seed.x, speed.x, speed.y); 52 | seed = rand_vec(seed); 53 | particleBuffer[id.x].linearVelocity = linearSpeed * linearDirection; 54 | 55 | float3 angularDirection = rand_uvec(seed); 56 | seed = rand_vec(seed); 57 | float angularSpeed = rand_range(seed.x, speed.z, speed.w); 58 | seed = rand_vec(seed); 59 | particleBuffer[id.x].angularVelocity = quat_axis_angle(angularDirection, angularSpeed); 60 | 61 | float lifetimeBody = rand_range(seed.x, lifetime.y, lifetime.z); 62 | seed = rand_vec(seed); 63 | float lifetimeCurrent = -t * (lifetime.x + lifetime.z + lifetime.w); 64 | particleBuffer[id.x].lifetime = float4(lifetime.x, lifetimeBody, lifetime.w, lifetimeCurrent); 65 | 66 | particleBuffer[id.x].color = float4(hsv2rgb(float3(t, 1.0, 1.0)), 1.0); 67 | } 68 | 69 | float2 time; // (current, delta) 70 | float3 dynamics; // (gravity, restitution, friction) 71 | float4 aSphere[3]; 72 | float4 aSphereVel[3]; 73 | float4 plane; 74 | 75 | [numthreads(1, 1, 1)] 76 | void Step(uint3 id : SV_DispatchThreadID) 77 | { 78 | // respawn particle 79 | float prevLife = particleBuffer[id.x].lifetime.w; 80 | particleBuffer[id.x].lifetime.w += time.y; 81 | float4 lifetime = particleBuffer[id.x].lifetime; 82 | float totalLife = dot(lifetime.xyz, float3(1.0, 1.0, 1.0)); 83 | if (lifetime.w > totalLife) 84 | { 85 | // easy way to achieve sub-frame interpolation 86 | lifetime.w -= totalLife; 87 | time.x += lifetime.w; 88 | 89 | float3 seed = id.x + time.x; 90 | 91 | float3 emitterPos = float3(0.0, 3.0, 0.0); 92 | particleBuffer[id.x].position = emitterPos; 93 | particleBuffer[id.x].lifetime.w = 0.0; 94 | 95 | float3 linearDirection = normalize(rand_vec(seed)); 96 | seed = rand_vec(seed); 97 | float linearSpeed = rand_range(seed.x, speed.x, speed.y); 98 | seed = rand_vec(seed); 99 | particleBuffer[id.x].linearVelocity = linearSpeed * linearDirection; 100 | 101 | float3 angularDirection = rand_uvec(seed); 102 | seed = rand_vec(seed); 103 | float angularSpeed = rand_range(seed.x, speed.z, speed.w); 104 | seed = rand_vec(seed); 105 | particleBuffer[id.x].angularVelocity = quat_axis_angle(angularDirection, angularSpeed); 106 | } 107 | 108 | if (lifetime.w < 0.0) 109 | return; 110 | 111 | // read out 112 | float r = 0.5f * particleBuffer[id.x].scale; 113 | float3 pos = particleBuffer[id.x].position; 114 | float3 vel = particleBuffer[id.x].linearVelocity; 115 | 116 | // gravity 117 | vel.y -= dynamics.x * time.y; 118 | 119 | CollisionResult res; 120 | 121 | // spheres 122 | for (int i = 0; i < 3; ++i) 123 | { 124 | float3 velRel = vel - aSphereVel[i].xyz; 125 | res = sphereVsSphere(float4(pos, r), aSphere[i], velRel, dynamics.y, dynamics.z); 126 | pos = res.position; 127 | vel = res.velocity + aSphereVel[i].xyz; 128 | } 129 | 130 | // plane 131 | res = sphereVsPlane(float4(pos, r), plane, vel, dynamics.y, dynamics.z); 132 | pos = res.position; 133 | vel = res.velocity; 134 | 135 | // integrate 136 | pos += vel * time.y; 137 | float4 q = quat_pow(particleBuffer[id.x].angularVelocity, time.y); 138 | particleBuffer[id.x].rotation = quat_concat(q, particleBuffer[id.x].rotation); 139 | 140 | // write back 141 | particleBuffer[id.x].position = pos; 142 | particleBuffer[id.x].linearVelocity = vel; 143 | } 144 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/GPU Particles with Colliders/ParticleLogic.compute.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 230a25ffd14974e4da0aceca97604204 3 | ComputeShaderImporter: 4 | externalObjects: {} 5 | currentAPIMask: 4 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/GPU Particles with Colliders/ParticleStruct.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | #ifndef PARTICLE_STRUCT 13 | #define PARTICLE_STRUCT 14 | 15 | struct Particle 16 | { 17 | float3 position; 18 | float damping; 19 | 20 | float4 rotation; 21 | 22 | float3 linearVelocity; 23 | float scale; 24 | 25 | float4 angularVelocity; 26 | 27 | float4 lifetime; // (head, body, tail, current) 28 | 29 | float4 color; 30 | }; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/GPU Particles with Colliders/ParticleStruct.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: eeaca592cee3bde498f3d650846e0efd 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/GPU Particles with Colliders/Plane.prefab: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!1001 &100100000 4 | Prefab: 5 | m_ObjectHideFlags: 1 6 | serializedVersion: 2 7 | m_Modification: 8 | m_TransformParent: {fileID: 0} 9 | m_Modifications: [] 10 | m_RemovedComponents: [] 11 | m_ParentPrefab: {fileID: 0} 12 | m_RootGameObject: {fileID: 1113924760286158} 13 | m_IsPrefabParent: 1 14 | --- !u!1 &1113924760286158 15 | GameObject: 16 | m_ObjectHideFlags: 0 17 | m_PrefabParentObject: {fileID: 0} 18 | m_PrefabInternal: {fileID: 100100000} 19 | serializedVersion: 5 20 | m_Component: 21 | - component: {fileID: 4889533220450216} 22 | - component: {fileID: 33231903784293998} 23 | - component: {fileID: 23107254070747086} 24 | - component: {fileID: 64479188876994914} 25 | m_Layer: 0 26 | m_Name: Plane 27 | m_TagString: Untagged 28 | m_Icon: {fileID: 0} 29 | m_NavMeshLayer: 0 30 | m_StaticEditorFlags: 0 31 | m_IsActive: 1 32 | --- !u!4 &4889533220450216 33 | Transform: 34 | m_ObjectHideFlags: 1 35 | m_PrefabParentObject: {fileID: 0} 36 | m_PrefabInternal: {fileID: 100100000} 37 | m_GameObject: {fileID: 1113924760286158} 38 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 39 | m_LocalPosition: {x: 1.7532644, y: 1.2589529, z: 0.945655} 40 | m_LocalScale: {x: 10, y: 10, z: 10} 41 | m_Children: [] 42 | m_Father: {fileID: 0} 43 | m_RootOrder: 0 44 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 45 | --- !u!23 &23107254070747086 46 | MeshRenderer: 47 | m_ObjectHideFlags: 1 48 | m_PrefabParentObject: {fileID: 0} 49 | m_PrefabInternal: {fileID: 100100000} 50 | m_GameObject: {fileID: 1113924760286158} 51 | m_Enabled: 1 52 | m_CastShadows: 1 53 | m_ReceiveShadows: 1 54 | m_DynamicOccludee: 1 55 | m_MotionVectors: 1 56 | m_LightProbeUsage: 1 57 | m_ReflectionProbeUsage: 1 58 | m_RenderingLayerMask: 4294967295 59 | m_Materials: 60 | - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} 61 | m_StaticBatchInfo: 62 | firstSubMesh: 0 63 | subMeshCount: 0 64 | m_StaticBatchRoot: {fileID: 0} 65 | m_ProbeAnchor: {fileID: 0} 66 | m_LightProbeVolumeOverride: {fileID: 0} 67 | m_ScaleInLightmap: 1 68 | m_PreserveUVs: 0 69 | m_IgnoreNormalsForChartDetection: 0 70 | m_ImportantGI: 0 71 | m_StitchLightmapSeams: 0 72 | m_SelectedEditorRenderState: 3 73 | m_MinimumChartSize: 4 74 | m_AutoUVMaxDistance: 0.5 75 | m_AutoUVMaxAngle: 89 76 | m_LightmapParameters: {fileID: 0} 77 | m_SortingLayerID: 0 78 | m_SortingLayer: 0 79 | m_SortingOrder: 0 80 | --- !u!33 &33231903784293998 81 | MeshFilter: 82 | m_ObjectHideFlags: 1 83 | m_PrefabParentObject: {fileID: 0} 84 | m_PrefabInternal: {fileID: 100100000} 85 | m_GameObject: {fileID: 1113924760286158} 86 | m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0} 87 | --- !u!64 &64479188876994914 88 | MeshCollider: 89 | m_ObjectHideFlags: 1 90 | m_PrefabParentObject: {fileID: 0} 91 | m_PrefabInternal: {fileID: 100100000} 92 | m_GameObject: {fileID: 1113924760286158} 93 | m_Material: {fileID: 0} 94 | m_IsTrigger: 0 95 | m_Enabled: 1 96 | serializedVersion: 3 97 | m_Convex: 0 98 | m_CookingOptions: 14 99 | m_SkinWidth: 0.01 100 | m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0} 101 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/GPU Particles with Colliders/Plane.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2b1a709b1fe816e4a8dd3f429ecbff09 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 100100000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/GPU Particles with Colliders/Sphere.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 6 6 | m_ObjectHideFlags: 0 7 | m_PrefabParentObject: {fileID: 0} 8 | m_PrefabInternal: {fileID: 0} 9 | m_Name: Sphere 10 | m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} 11 | m_ShaderKeywords: 12 | m_LightmapFlags: 4 13 | m_EnableInstancingVariants: 0 14 | m_DoubleSidedGI: 0 15 | m_CustomRenderQueue: -1 16 | stringTagMap: {} 17 | disabledShaderPasses: [] 18 | m_SavedProperties: 19 | serializedVersion: 3 20 | m_TexEnvs: 21 | - _BumpMap: 22 | m_Texture: {fileID: 0} 23 | m_Scale: {x: 1, y: 1} 24 | m_Offset: {x: 0, y: 0} 25 | - _DetailAlbedoMap: 26 | m_Texture: {fileID: 0} 27 | m_Scale: {x: 1, y: 1} 28 | m_Offset: {x: 0, y: 0} 29 | - _DetailMask: 30 | m_Texture: {fileID: 0} 31 | m_Scale: {x: 1, y: 1} 32 | m_Offset: {x: 0, y: 0} 33 | - _DetailNormalMap: 34 | m_Texture: {fileID: 0} 35 | m_Scale: {x: 1, y: 1} 36 | m_Offset: {x: 0, y: 0} 37 | - _EmissionMap: 38 | m_Texture: {fileID: 0} 39 | m_Scale: {x: 1, y: 1} 40 | m_Offset: {x: 0, y: 0} 41 | - _MainTex: 42 | m_Texture: {fileID: 0} 43 | m_Scale: {x: 1, y: 1} 44 | m_Offset: {x: 0, y: 0} 45 | - _MetallicGlossMap: 46 | m_Texture: {fileID: 0} 47 | m_Scale: {x: 1, y: 1} 48 | m_Offset: {x: 0, y: 0} 49 | - _OcclusionMap: 50 | m_Texture: {fileID: 0} 51 | m_Scale: {x: 1, y: 1} 52 | m_Offset: {x: 0, y: 0} 53 | - _ParallaxMap: 54 | m_Texture: {fileID: 0} 55 | m_Scale: {x: 1, y: 1} 56 | m_Offset: {x: 0, y: 0} 57 | m_Floats: 58 | - _BumpScale: 1 59 | - _Cutoff: 0.5 60 | - _DetailNormalMapScale: 1 61 | - _DstBlend: 0 62 | - _GlossMapScale: 1 63 | - _Glossiness: 0 64 | - _GlossyReflections: 1 65 | - _Metallic: 0 66 | - _Mode: 0 67 | - _OcclusionStrength: 1 68 | - _Parallax: 0.02 69 | - _SmoothnessTextureChannel: 0 70 | - _SpecularHighlights: 1 71 | - _SrcBlend: 1 72 | - _UVSec: 0 73 | - _ZWrite: 1 74 | m_Colors: 75 | - _Color: {r: 0.6037736, g: 0.581431, b: 0.49270204, a: 1} 76 | - _EmissionColor: {r: 0.103773594, g: 0.09251514, b: 0.09251514, a: 1} 77 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/GPU Particles with Colliders/Sphere.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e6ee4a6ba87209d4b82ed0bcafd2e43e 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 2100000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/GPU Particles with Colliders/Sphere.prefab: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!1001 &100100000 4 | Prefab: 5 | m_ObjectHideFlags: 1 6 | serializedVersion: 2 7 | m_Modification: 8 | m_TransformParent: {fileID: 0} 9 | m_Modifications: [] 10 | m_RemovedComponents: [] 11 | m_ParentPrefab: {fileID: 0} 12 | m_RootGameObject: {fileID: 1904052554886110} 13 | m_IsPrefabParent: 1 14 | --- !u!1 &1904052554886110 15 | GameObject: 16 | m_ObjectHideFlags: 0 17 | m_PrefabParentObject: {fileID: 0} 18 | m_PrefabInternal: {fileID: 100100000} 19 | serializedVersion: 5 20 | m_Component: 21 | - component: {fileID: 4337084622871386} 22 | - component: {fileID: 33679405207982478} 23 | - component: {fileID: 23660809238315912} 24 | - component: {fileID: 135202814895602136} 25 | m_Layer: 0 26 | m_Name: Sphere 27 | m_TagString: Untagged 28 | m_Icon: {fileID: 0} 29 | m_NavMeshLayer: 0 30 | m_StaticEditorFlags: 0 31 | m_IsActive: 1 32 | --- !u!4 &4337084622871386 33 | Transform: 34 | m_ObjectHideFlags: 1 35 | m_PrefabParentObject: {fileID: 0} 36 | m_PrefabInternal: {fileID: 100100000} 37 | m_GameObject: {fileID: 1904052554886110} 38 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 39 | m_LocalPosition: {x: 0, y: 0, z: 0} 40 | m_LocalScale: {x: 1, y: 1, z: 1} 41 | m_Children: [] 42 | m_Father: {fileID: 0} 43 | m_RootOrder: 0 44 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 45 | --- !u!23 &23660809238315912 46 | MeshRenderer: 47 | m_ObjectHideFlags: 1 48 | m_PrefabParentObject: {fileID: 0} 49 | m_PrefabInternal: {fileID: 100100000} 50 | m_GameObject: {fileID: 1904052554886110} 51 | m_Enabled: 1 52 | m_CastShadows: 1 53 | m_ReceiveShadows: 1 54 | m_DynamicOccludee: 1 55 | m_MotionVectors: 1 56 | m_LightProbeUsage: 1 57 | m_ReflectionProbeUsage: 1 58 | m_RenderingLayerMask: 4294967295 59 | m_Materials: 60 | - {fileID: 2100000, guid: e6ee4a6ba87209d4b82ed0bcafd2e43e, type: 2} 61 | m_StaticBatchInfo: 62 | firstSubMesh: 0 63 | subMeshCount: 0 64 | m_StaticBatchRoot: {fileID: 0} 65 | m_ProbeAnchor: {fileID: 0} 66 | m_LightProbeVolumeOverride: {fileID: 0} 67 | m_ScaleInLightmap: 1 68 | m_PreserveUVs: 0 69 | m_IgnoreNormalsForChartDetection: 0 70 | m_ImportantGI: 0 71 | m_StitchLightmapSeams: 0 72 | m_SelectedEditorRenderState: 3 73 | m_MinimumChartSize: 4 74 | m_AutoUVMaxDistance: 0.5 75 | m_AutoUVMaxAngle: 89 76 | m_LightmapParameters: {fileID: 0} 77 | m_SortingLayerID: 0 78 | m_SortingLayer: 0 79 | m_SortingOrder: 0 80 | --- !u!33 &33679405207982478 81 | MeshFilter: 82 | m_ObjectHideFlags: 1 83 | m_PrefabParentObject: {fileID: 0} 84 | m_PrefabInternal: {fileID: 100100000} 85 | m_GameObject: {fileID: 1904052554886110} 86 | m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0} 87 | --- !u!135 &135202814895602136 88 | SphereCollider: 89 | m_ObjectHideFlags: 1 90 | m_PrefabParentObject: {fileID: 0} 91 | m_PrefabInternal: {fileID: 100100000} 92 | m_GameObject: {fileID: 1904052554886110} 93 | m_Material: {fileID: 0} 94 | m_IsTrigger: 0 95 | m_Enabled: 1 96 | serializedVersion: 2 97 | m_Radius: 0.5 98 | m_Center: {x: 0, y: 0, z: 0} 99 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/GPU Particles with Colliders/Sphere.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 808c6ede839820a4180c79912af3e1a2 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 100100000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Noise Fragment Shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 50c184abe6a2b314b97efef0a50dea0e 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Noise Fragment Shader/NoiseFragmentShaderTest.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | 10 | This example is based on Noise Shader Library for Unity 11 | https://github.com/keijiro/NoiseShader 12 | 13 | Original work (webgl-noise) Copyright (C) 2011 Ashima Arts. 14 | Translation and modification was made by Keijiro Takahashi. 15 | 16 | Description : Array and textureless GLSL 2D simplex noise function. 17 | Author : Ian McEwan, Ashima Arts. 18 | Maintainer : ijm 19 | Lastmod : 20110822 (ijm) 20 | License : Copyright (C) 2011 Ashima Arts. All rights reserved. 21 | Distributed under the MIT License. See LICENSE file. 22 | https://github.com/ashima/webgl-noise 23 | */ 24 | /******************************************************************************/ 25 | 26 | using UnityEngine; 27 | 28 | public class NoiseFragmentShaderTest : MonoBehaviour 29 | { 30 | public enum NoiseType 31 | { 32 | Classic, 33 | ClassicPeriodic, 34 | Random, 35 | RandomVector, 36 | Simplex, 37 | SimplexGradient, 38 | } 39 | 40 | public NoiseType m_noiseType = NoiseType.Simplex; 41 | public bool m_is3D; 42 | public int m_numOctaves = 6; 43 | public float m_octaveOffsetFactor = 1.2f; 44 | 45 | Material m_material; 46 | 47 | void Update() 48 | { 49 | if (m_material == null) 50 | { 51 | Shader shader = Shader.Find("CjLib/Example/NoiseTest"); 52 | m_material = new Material(shader); 53 | m_material.hideFlags = HideFlags.DontSave; 54 | GetComponent().material = m_material; 55 | } 56 | 57 | m_material.shaderKeywords = null; 58 | 59 | if (m_noiseType == NoiseType.Classic) 60 | m_material.EnableKeyword("CNOISE"); 61 | else if (m_noiseType == NoiseType.ClassicPeriodic) 62 | m_material.EnableKeyword("PNOISE"); 63 | else if (m_noiseType == NoiseType.Simplex) 64 | m_material.EnableKeyword("SNOISE"); 65 | else if (m_noiseType == NoiseType.SimplexGradient) 66 | m_material.EnableKeyword("SNOISE_GRAD"); 67 | else if (m_noiseType == NoiseType.Random) 68 | m_material.EnableKeyword("RAND"); 69 | else // RandomVector 70 | m_material.EnableKeyword("RAND_VEC"); 71 | 72 | if (m_is3D) 73 | m_material.EnableKeyword("THREED"); 74 | 75 | m_material.SetVector("_Offset", new Vector4(0.0f, -0.5f * Time.time, 0.0f, 0.0f)); 76 | m_material.SetInt("_NumOctaves", m_numOctaves); 77 | m_material.SetFloat("_OctaveOffsetFactor", m_octaveOffsetFactor); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Noise Fragment Shader/NoiseFragmentShaderTest.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a43c654f6c08ae647addf3d11f401abe 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: 7 | - m_shader: {fileID: 4800000, guid: 6011c4b5e94a5564bbe431059b89b700, type: 3} 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Noise Fragment Shader/NoiseFragmentShaderTest.shader: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | 10 | Based on Noise Shader Library for Unity 11 | https://github.com/keijiro/NoiseShader 12 | 13 | Original work (webgl-noise) Copyright (C) 2011 Ashima Arts. 14 | Translation and modification was made by Keijiro Takahashi. 15 | 16 | Description : Array and textureless GLSL 2D simplex noise function. 17 | Author : Ian McEwan, Ashima Arts. 18 | Maintainer : ijm 19 | Lastmod : 20110822 (ijm) 20 | License : Copyright (C) 2011 Ashima Arts. All rights reserved. 21 | Distributed under the MIT License. See LICENSE file. 22 | https://github.com/ashima/webgl-noise 23 | */ 24 | /******************************************************************************/ 25 | 26 | Shader "CjLib/Example/NoiseTest" 27 | { 28 | Properties 29 | { 30 | _Offset("Offset", Vector) = (0.0, 0.0, 0.0, 0.0) 31 | _NumOctaves("Num Octaves", Int) = 6 32 | _OctaveOffsetFactor("Octave Offset Factor", Float) = 1.2 33 | } 34 | 35 | CGINCLUDE 36 | #pragma multi_compile CNOISE PNOISE SNOISE SNOISE_GRAD RAND RAND_VEC 37 | #pragma multi_compile _ MULTIPLE_OCTAVES 38 | #pragma multi_compile _ THREED 39 | 40 | #include "UnityCG.cginc" 41 | 42 | #include "../../CjLib/Shader/Noise/Noise.cginc" 43 | 44 | float4 _Offset; 45 | uint _NumOctaves; 46 | float _OctaveOffsetFactor; 47 | 48 | struct v2f 49 | { 50 | float4 posSs : SV_POSITION; 51 | float3 posWs : TEXCOORD0; 52 | }; 53 | 54 | v2f vert(appdata_base v) 55 | { 56 | v2f o; 57 | o.posSs = UnityObjectToClipPos(v.vertex); 58 | o.posWs = mul(unity_ObjectToWorld, v.vertex).xyz; 59 | return o; 60 | } 61 | 62 | float4 frag(v2f i) : SV_Target 63 | { 64 | #if defined(THREED) 65 | float3 s = i.posWs * 4.0; 66 | float3 offset = _Offset.xyz; 67 | #else 68 | float2 s = i.posWs.xy * 4.0; 69 | float2 offset = _Offset.xy; 70 | #endif 71 | 72 | #if defined(CNOISE) 73 | #define NOISE_FUNC cnoise 74 | #elif defined(PNOISE) 75 | #define NOISE_FUNC pnoise 76 | #if defined(THREED) 77 | float3 period = 1.0; 78 | #else 79 | float2 period = 1.0; 80 | #endif 81 | #elif defined(SNOISE) 82 | #define NOISE_FUNC snoise 83 | #elif defined(SNOISE_GRAD) 84 | #define NOISE_FUNC snoise_grad 85 | #elif defined(RAND) 86 | #define NOISE_FUNC rand 87 | #else // RAND_VEC 88 | #define NOISE_FUNC rand_vec 89 | #endif 90 | 91 | float4 o = 0.0; 92 | #if defined(PNOISE) 93 | o = NOISE_FUNC(s, offset, period, _NumOctaves, _OctaveOffsetFactor); 94 | #elif defined(SNOISE_GRAD) 95 | #if defined(THREED) 96 | o.rgb = NOISE_FUNC(s, offset, _NumOctaves, _OctaveOffsetFactor); 97 | #else 98 | o.rg = NOISE_FUNC(s, offset, _NumOctaves, _OctaveOffsetFactor); 99 | o.b = 0.0; 100 | #endif 101 | #else 102 | #if defined(RAND) 103 | o = NOISE_FUNC(s + offset); 104 | #elif defined(RAND_VEC) 105 | #if defined(THREED) 106 | o.rgb = NOISE_FUNC(s + offset); 107 | #else 108 | o.rg = NOISE_FUNC(s + offset); 109 | o.b = 0.0; 110 | #endif 111 | #else 112 | o = NOISE_FUNC(s, offset, _NumOctaves, _OctaveOffsetFactor); 113 | #endif 114 | #endif 115 | 116 | o.a = 1.0; 117 | return o; 118 | } 119 | ENDCG 120 | 121 | SubShader 122 | { 123 | Pass 124 | { 125 | CGPROGRAM 126 | #pragma target 3.0 127 | #pragma vertex vert 128 | #pragma fragment frag 129 | ENDCG 130 | } 131 | } 132 | } -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Noise Fragment Shader/NoiseFragmentShaderTest.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6011c4b5e94a5564bbe431059b89b700 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Noise Fragment Shader/NoiseFragmentShaderTest.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 14d60e72115ddaf4aa344843e54a402d 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Noise GPU Compute And CPU.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2803723a30af0f64aa7459a6df4cec3e 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Noise GPU Compute And CPU/Noise Gpu Compute And Cpu.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6dc3b0c9d1927c94b998ec8b1c8bb558 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Noise GPU Compute And CPU/NoiseGpuComputeAndCpuTest.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 71ffc15b407c2ae47be0c5a6cefd5f2e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Quaternion Integration Comparison.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cc3fffbe1f7ddf24faa4772b5a487a96 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Quaternion Integration Comparison/Main.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | 13 | using UnityEngine; 14 | 15 | using CjLib; 16 | 17 | namespace QuaternionIntegrationComparison 18 | { 19 | public class Main : MonoBehaviour 20 | { 21 | [Range(0.0f, 10.0f)] 22 | public float m_timeScale = 1.0f; 23 | 24 | public Color m_closedColor; 25 | public Color m_powerColor; 26 | public Color m_derivativeColor; 27 | 28 | private float m_angle; 29 | 30 | private Quaternion m_quatClosedForm; 31 | private Quaternion m_quatPower; 32 | private Quaternion m_quatDerivative; 33 | 34 | private void Reset() 35 | { 36 | m_angle = 0.0f; 37 | m_quatClosedForm = Quaternion.identity; 38 | m_quatPower = Quaternion.identity; 39 | m_quatDerivative = Quaternion.identity; 40 | } 41 | 42 | void Start() 43 | { 44 | Reset(); 45 | } 46 | 47 | void Update() 48 | { 49 | Vector3 axis = Vector3.down; 50 | float angularSpeed = 1.0f; 51 | float dt = m_timeScale * Time.fixedDeltaTime; 52 | 53 | // render 54 | Quaternion baseRot = Quaternion.FromToRotation(Vector3.one, Vector3.up); 55 | DebugUtil.DrawBox(Vector3.zero, m_quatClosedForm * baseRot, Vector3.one, m_closedColor, true, DebugUtil.Style.FlatShaded); 56 | DebugUtil.DrawBox(Vector3.zero, m_quatPower * baseRot, 1.05f * Vector3.one, m_powerColor, true, DebugUtil.Style.Wireframe); 57 | DebugUtil.DrawBox(Vector3.zero, m_quatDerivative * baseRot, 1.1f * Vector3.one, m_derivativeColor, true, DebugUtil.Style.Wireframe); 58 | 59 | // integrate 60 | Quaternion v = QuaternionUtil.AxisAngle(axis, angularSpeed); 61 | Vector3 o = angularSpeed * axis; 62 | m_quatClosedForm = QuaternionUtil.Normalize(QuaternionUtil.AxisAngle(axis, (m_angle += angularSpeed * dt))); 63 | m_quatPower = QuaternionUtil.Normalize(QuaternionUtil.Integrate(m_quatPower, v, dt)); 64 | m_quatDerivative = QuaternionUtil.Normalize(QuaternionUtil.Integrate(m_quatDerivative, o, dt)); 65 | 66 | if (Input.GetKey(KeyCode.Space)) 67 | Reset(); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Quaternion Integration Comparison/Main.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 512c8c0aa5f226d42b00e3215e1299dc 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Quaternion Integration Comparison/Quaternion Integration Comparison.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d0b64ec500d3ca041968d55f30a1e9cc 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Quaternion Swing Twist Decomposition.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: eaa10598b9b0ec64389859bca200b13d 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Quaternion Swing Twist Decomposition/Quaternion Swing Twist Decomposition.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ce16c09fb631ad247ac7cc980c7bce30 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Quaternion Swing Twist Decomposition/QuaternionSwingTwistDecompositionDemo.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a071a59154559394ebece10498963d6f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Turbulent Rainbow GPU Particles.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 64ac044314cf7674da8609bb673faba6 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Turbulent Rainbow GPU Particles/Main.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | 13 | using UnityEngine; 14 | 15 | using CjLib; 16 | 17 | namespace TurbulentRainbowGpuParticles 18 | { 19 | public class Main : MonoBehaviour 20 | { 21 | public ComputeShader m_shader; 22 | 23 | private const int kNumParticles = 10000; 24 | 25 | /* 26 | private struct Particle 27 | { 28 | // 4 floats 29 | Vector3 m_position; 30 | float m_damping; 31 | 32 | // 4 floats 33 | Quaternion m_rotation; 34 | 35 | // 4 floats 36 | Vector3 m_linearVelocity; 37 | float m_scale; 38 | 39 | // 4 floats 40 | Quaternion m_angularVelocity; 41 | 42 | // 4 floats 43 | Vector4 m_lifetime; 44 | 45 | // 4 floats 46 | Color m_color; 47 | }; 48 | */ 49 | 50 | private ComputeBuffer m_computeBuffer; 51 | private ComputeBuffer m_instanceArgsBuffer; 52 | //private Particle[] m_debugBuffer; 53 | 54 | private Mesh m_mesh; 55 | private Material m_material; 56 | private MaterialPropertyBlock m_materialProperties; 57 | 58 | private int m_csInitKernelId; 59 | private int m_csStepKernelId; 60 | 61 | private int m_csParticleBufferId; 62 | private int m_csScaleId; 63 | private int m_csDampingId; 64 | private int m_csSpeedId; 65 | private int m_csLifetimeId; 66 | private int m_csNumParticlesId; 67 | private int m_csTimeId; 68 | 69 | void OnEnable() 70 | { 71 | m_mesh = new Mesh(); 72 | m_mesh = PrimitiveMeshFactory.BoxFlatShaded(); 73 | 74 | int particleStride = sizeof(float) * 24; 75 | m_computeBuffer = new ComputeBuffer(kNumParticles, particleStride); 76 | 77 | uint[] instanceArgs = new uint[] { 0, 0, 0, 0, 0 }; 78 | m_instanceArgsBuffer = new ComputeBuffer(1, instanceArgs.Length * sizeof(uint), ComputeBufferType.IndirectArguments); 79 | instanceArgs[0] = (uint) m_mesh.GetIndexCount(0); 80 | instanceArgs[1] = (uint) kNumParticles; 81 | instanceArgs[2] = (uint) m_mesh.GetIndexStart(0); 82 | instanceArgs[3] = (uint) m_mesh.GetBaseVertex(0); 83 | m_instanceArgsBuffer.SetData(instanceArgs); 84 | 85 | //m_debugBuffer = new Particle[kNumParticles]; 86 | 87 | m_csInitKernelId = m_shader.FindKernel("Init"); 88 | m_csStepKernelId = m_shader.FindKernel("Step"); 89 | 90 | m_csParticleBufferId = Shader.PropertyToID("particleBuffer"); 91 | m_csScaleId = Shader.PropertyToID("scale"); 92 | m_csDampingId = Shader.PropertyToID("damping"); 93 | m_csSpeedId = Shader.PropertyToID("speed"); 94 | m_csLifetimeId = Shader.PropertyToID("lifetime"); 95 | m_csNumParticlesId = Shader.PropertyToID("numParticles"); 96 | m_csTimeId = Shader.PropertyToID("time"); 97 | 98 | m_material = new Material(Shader.Find("CjLib/Example/TurbulentRainbowGpuParticles")); 99 | m_material.enableInstancing = true; 100 | m_material.SetBuffer(m_csParticleBufferId, m_computeBuffer); 101 | m_materialProperties = new MaterialPropertyBlock(); 102 | 103 | m_shader.SetFloats(m_csScaleId, new float[] { 0.15f, 0.3f }); 104 | m_shader.SetFloat(m_csDampingId, 6.0f); 105 | m_shader.SetFloats(m_csSpeedId, new float[] { 3.0f, 4.0f, 1.0f, 6.0f }); 106 | m_shader.SetFloats(m_csLifetimeId, new float[] { 0.1f, 0.5f, 0.5f, 0.1f }); 107 | m_shader.SetInt(m_csNumParticlesId, kNumParticles); 108 | 109 | m_shader.SetBuffer(m_csInitKernelId, m_csParticleBufferId, m_computeBuffer); 110 | m_shader.SetBuffer(m_csStepKernelId, m_csParticleBufferId, m_computeBuffer); 111 | 112 | m_shader.Dispatch(m_csInitKernelId, kNumParticles, 1, 1); 113 | 114 | //m_computeBuffer.GetData(m_debugBuffer); 115 | } 116 | 117 | void Update() 118 | { 119 | m_shader.SetFloats(m_csTimeId, new float[] { Time.time, Time.fixedDeltaTime }); 120 | m_shader.Dispatch(m_csStepKernelId, kNumParticles, 1, 1); 121 | 122 | //m_computeBuffer.GetData(m_debugBuffer); 123 | 124 | Graphics.DrawMeshInstancedIndirect(m_mesh, 0, m_material, new Bounds(Vector3.zero, 20.0f * Vector3.one), m_instanceArgsBuffer, 0, m_materialProperties, UnityEngine.Rendering.ShadowCastingMode.On); 125 | } 126 | 127 | void OnDisable() 128 | { 129 | if (m_computeBuffer != null) 130 | { 131 | m_computeBuffer.Dispose(); 132 | m_computeBuffer = null; 133 | } 134 | 135 | if (m_instanceArgsBuffer != null) 136 | { 137 | m_instanceArgsBuffer.Dispose(); 138 | m_instanceArgsBuffer = null; 139 | } 140 | } 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Turbulent Rainbow GPU Particles/Main.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3dc2777853a3ea346b8d4ff4f88a943a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: 7 | - m_shader: {fileID: 7200000, guid: c6689aa98202bc2429cce4ed01db01df, type: 3} 8 | - m_material: {instanceID: 0} 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Turbulent Rainbow GPU Particles/Particle.shader: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | Shader "CjLib/Example/TurbulentRainbowParticle" 13 | { 14 | SubShader 15 | { 16 | Tags { "RenderType" = "Opaque" } 17 | 18 | Pass 19 | { 20 | Name "Deferred" 21 | Tags { "LightMode" = "Deferred" } 22 | CGPROGRAM 23 | #pragma target 5.0 24 | #pragma vertex vert 25 | #pragma fragment frag 26 | #pragma multi_compile_instancing 27 | #define PASS_DEFERRED 28 | #include "ParticleCore.cginc" 29 | ENDCG 30 | } 31 | 32 | Pass 33 | { 34 | Name "Shadow Caster" 35 | Tags { "LightMode" = "ShadowCaster" } 36 | CGPROGRAM 37 | #pragma target 5.0 38 | #pragma vertex vert 39 | #pragma fragment frag 40 | #pragma multi_compile_instancing 41 | #define PASS_SHADOW_CASTER 42 | #include "ParticleCore.cginc" 43 | ENDCG 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Turbulent Rainbow GPU Particles/Particle.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 40341118263ba934d8034deec1d0dbc1 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Turbulent Rainbow GPU Particles/ParticleCore.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | #include "AutoLight.cginc" 13 | #include "UnityCG.cginc" 14 | 15 | #include "../../CjLib/Shader/Math/Math.cginc" 16 | 17 | #include "ParticleStruct.cginc" 18 | 19 | struct appdata 20 | { 21 | float4 posOs : POSITION; 22 | float3 normOs : NORMAL; 23 | uint id : SV_InstanceId; 24 | }; 25 | 26 | struct v2f 27 | { 28 | float4 posCs : SV_POSITION; 29 | float3 normWs : NORMAL; 30 | float4 color : COLOR0; 31 | }; 32 | 33 | struct fout 34 | { 35 | fixed4 c0 : COLOR0; // diffuse (rgb), occlusion (a) 36 | fixed4 c1 : COLOR1; // spec (rgb), smoothness (a) 37 | fixed4 c2 : COLOR2; // normalWs (rgb), 38 | fixed4 c3 : COLOR3; // emission 39 | }; 40 | 41 | StructuredBuffer particleBuffer; 42 | float4x4 viewMatrix; 43 | float4x4 projMatrix; 44 | 45 | v2f vert(appdata i) 46 | { 47 | v2f o; 48 | 49 | Particle p = particleBuffer[i.id]; 50 | 51 | float scale = 52 | lerp 53 | ( 54 | 0.0, 55 | lerp(0.0, p.scale, saturate(p.lifetime.w / p.lifetime.x)), 56 | saturate(dot(p.lifetime, float4(1.0, 1.0, 1.0, -1.0)) / p.lifetime.z) 57 | ); 58 | 59 | float3 posWs = 60 | p.position 61 | + scale * quat_rot(p.rotation, i.posOs.xyz); 62 | 63 | o.posCs = UnityObjectToClipPos(posWs); 64 | o.normWs = quat_rot(p.rotation, i.normOs); 65 | o.color = p.color; 66 | 67 | return o; 68 | } 69 | 70 | fout frag(v2f i) 71 | { 72 | fout o; 73 | 74 | o.c0 = i.color; 75 | o.c1.rgb = 0.0; 76 | o.c1.a = 1.0; 77 | o.c2.rgb = i.normWs; 78 | o.c2.a = 0.0; 79 | o.c3 = 0.3 * i.color; 80 | 81 | return o; 82 | } 83 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Turbulent Rainbow GPU Particles/ParticleCore.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0bfd80d146b8ef14d90fe3da9e1869c5 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Turbulent Rainbow GPU Particles/ParticleCoreWithForwardPass.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | #include "AutoLight.cginc" 13 | #include "UnityCG.cginc" 14 | 15 | #include "../../CjLib/Shader/Math/Math.cginc" 16 | #include "../../CjLib/Shader/Render/Forward.cginc" 17 | 18 | #include "ParticleStruct.cginc" 19 | 20 | 21 | struct appdata 22 | { 23 | float4 vertex : POSITION; 24 | 25 | #if defined(PASS_FORWARD) || defined(PASS_DEFERRED) 26 | float3 normal : NORMAL; 27 | UNITY_VERTEX_INPUT_INSTANCE_ID 28 | #endif 29 | }; 30 | 31 | struct v2f 32 | { 33 | float4 pos : SV_POSITION; 34 | 35 | #if defined(PASS_FORWARD) || defined(PASS_DEFERRED) 36 | float3 normWs : NORMAL; 37 | float4 color : COLOR0; 38 | #endif 39 | 40 | #if defined (PASS_FORWARD) 41 | float3 posWs : COLOR1; 42 | #endif 43 | 44 | #if defined(PASS_FORWARD_BASE) 45 | float3 vertLight : COLOR2; 46 | #endif 47 | 48 | #if defined(PASS_FORWARD) 49 | LIGHTING_COORDS(0, 1) 50 | #endif 51 | }; 52 | 53 | struct fout 54 | { 55 | fixed4 c0 : COLOR0; // diffuse (rgb), occlusion (a) 56 | 57 | #if defined(PASS_DEFERRED) 58 | fixed4 c1 : COLOR1; // spec (rgb), smoothness (a) 59 | fixed4 c2 : COLOR2; 60 | fixed4 c3 : COLOR3; 61 | #endif 62 | }; 63 | 64 | // particle data 65 | StructuredBuffer particleBuffer; 66 | 67 | v2f vert(appdata v, uint instance_id : SV_InstanceID) 68 | { 69 | v2f o; 70 | 71 | float3 posOs = v.vertex; 72 | float4 rotOs = particleBuffer[instance_id].rotation; 73 | posOs = quat_rot(rotOs, posOs); 74 | 75 | float scale = particleBuffer[instance_id].scale; 76 | float4 lifetime = particleBuffer[instance_id].lifetime; 77 | scale = 78 | lerp 79 | ( 80 | 0.0, 81 | lerp(0.0, scale, saturate(lifetime.w / lifetime.x)), 82 | saturate(dot(lifetime, float4(1.0, 1.0, 1.0, -1.0)) / lifetime.z) 83 | ); 84 | 85 | float3 posWs = scale * posOs + particleBuffer[instance_id].position; 86 | 87 | o.pos = UnityObjectToClipPos(posWs); 88 | 89 | #if defined(PASS_FORWARD) || defined(PASS_DEFERRED) 90 | float3 normWs = quat_rot(rotOs, v.normal); 91 | o.normWs = normWs; 92 | o.color = particleBuffer[instance_id].color; 93 | 94 | v.vertex = float4(posWs, 1.0); 95 | 96 | UNITY_SETUP_INSTANCE_ID(v); 97 | #endif 98 | 99 | #if defined(PASS_FORWARD_BASE) 100 | o.vertLight = o.color * CJ_LIB_SHADE_POINT_LIGHTS(posWs, normWs); 101 | #endif 102 | 103 | #if defined(PASS_FORWARD) 104 | o.posWs = posWs; 105 | TRANSFER_VERTEX_TO_FRAGMENT(o); 106 | #endif 107 | 108 | return o; 109 | } 110 | 111 | fout frag(v2f i) 112 | { 113 | fout o; 114 | 115 | #if defined(PASS_SHADOW_CASTER) 116 | o.c0.rgba = float4(0.0, 0.0, 0.0, 1.0); 117 | #elif defined(PASS_FORWARD) 118 | o.c0.rgb = i.color.rgb * CJ_LIB_SHADE_MAIN_LIGHT(i, i.posWs, i.normWs); 119 | o.c0.a = i.color.a; 120 | #elif defined(PASS_DEFERRED) 121 | o.c0.rgb = i.color; 122 | o.c0.a = 0.0; 123 | o.c1.rgb = 0.0; 124 | o.c1.a = 0.0; 125 | o.c2.rgb = i.normWs; 126 | o.c2.a = 0.0; 127 | o.c3 = 0.0; 128 | #endif 129 | 130 | #if defined(PASS_FORWARD_BASE) 131 | o.c0.rgb += i.color.rgb * i.vertLight; 132 | #endif 133 | 134 | return o; 135 | } 136 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Turbulent Rainbow GPU Particles/ParticleCoreWithForwardPass.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 28c3e88459533894f9c366d777413759 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Turbulent Rainbow GPU Particles/ParticleLogic.compute: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | #pragma kernel Init 13 | #pragma kernel Step 14 | 15 | #include "../../CjLib/Shader/Math/Color.cginc" 16 | #include "../../CjLib/Shader/Math/Math.cginc" 17 | #include "../../CjLib/Shader/Noise/Noise.cginc" 18 | 19 | #include "ParticleStruct.cginc" 20 | 21 | RWStructuredBuffer particleBuffer; 22 | 23 | float2 scale; // (min, max) 24 | float damping; 25 | float4 speed; // (min linear, max linear, min angular, max angular) 26 | float4 lifetime; // (head, min body, max body, tail) 27 | 28 | int numParticles; 29 | 30 | [numthreads(1, 1, 1)] 31 | void Init(uint3 id : SV_DispatchThreadID) 32 | { 33 | float t = float(id.x) / float(numParticles); 34 | float3 seed = id.x; 35 | 36 | particleBuffer[id.x].position = float3(0.0, 0.0, 0.0); 37 | 38 | float3 rotationAxis = rand_uvec(seed); 39 | seed = rand_vec(seed); 40 | float rotationAngle = rand(seed.x) * kPi; 41 | seed = rand_vec(seed); 42 | particleBuffer[id.x].rotation = quat_axis_angle(rotationAxis, rotationAngle); 43 | 44 | particleBuffer[id.x].scale = rand_range(seed.x, scale.x, scale.y); 45 | seed = rand_vec(seed); 46 | 47 | particleBuffer[id.x].damping = damping; 48 | 49 | float3 linearDirection = normalize(rand_vec(seed)); 50 | seed = rand_vec(seed); 51 | float linearSpeed = rand_range(seed.x, speed.x, speed.y); 52 | seed = rand_vec(seed); 53 | particleBuffer[id.x].linearVelocity = linearSpeed * linearDirection; 54 | 55 | float3 angularDirection = rand_uvec(seed); 56 | seed = rand_vec(seed); 57 | float angularSpeed = rand_range(seed.x, speed.z, speed.w); 58 | seed = rand_vec(seed); 59 | particleBuffer[id.x].angularVelocity = quat_axis_angle(angularDirection, angularSpeed); 60 | 61 | float lifetimeBody = rand_range(seed.x, lifetime.y, lifetime.z); 62 | seed = rand_vec(seed); 63 | float lifetimeCurrent = -t * (lifetime.x + lifetime.z + lifetime.w); 64 | particleBuffer[id.x].lifetime = float4(lifetime.x, lifetimeBody, lifetime.w, lifetimeCurrent); 65 | 66 | particleBuffer[id.x].color = float4(hsv2rgb(float3(t, 1.0, 1.0)), 1.0); 67 | } 68 | 69 | float2 time; // (current, delta) 70 | 71 | [numthreads(1, 1, 1)] 72 | void Step(uint3 id : SV_DispatchThreadID) 73 | { 74 | // respawn particle 75 | float prevLife = particleBuffer[id.x].lifetime.w; 76 | particleBuffer[id.x].lifetime.w += time.y; 77 | float4 lifetime = particleBuffer[id.x].lifetime; 78 | float totalLife = dot(lifetime.xyz, float3(1.0, 1.0, 1.0)); 79 | if (lifetime.w > totalLife) 80 | { 81 | // easy way to achieve sub-frame interpolation 82 | lifetime.w -= totalLife; 83 | time.x += lifetime.w; 84 | 85 | float3 seed = id.x + time.x; 86 | 87 | float3 emitterPos = float3(6.0 * sin(3.0 * time.x), 1.0 * sin(6.0 * time.x), 1.0 * sin(6.0 * time.x)); 88 | particleBuffer[id.x].position = emitterPos; 89 | particleBuffer[id.x].lifetime.w = 0.0; 90 | 91 | float3 linearDirection = normalize(rand_vec(seed)); 92 | seed = rand_vec(seed); 93 | float linearSpeed = rand_range(seed.x, speed.x, speed.y); 94 | seed = rand_vec(seed); 95 | particleBuffer[id.x].linearVelocity = linearSpeed * linearDirection; 96 | 97 | float3 angularDirection = rand_uvec(seed); 98 | seed = rand_vec(seed); 99 | float angularSpeed = rand_range(seed.x, speed.z, speed.w); 100 | seed = rand_vec(seed); 101 | particleBuffer[id.x].angularVelocity = quat_axis_angle(angularDirection, angularSpeed); 102 | } 103 | 104 | if (lifetime.w < 0.0) 105 | return; 106 | 107 | // turbulence 108 | float3 turbulence = snoise_grad(0.4 * particleBuffer[id.x].position, float3(0.0, time.x, 0.0), 2, 1.2).xyz; 109 | particleBuffer[id.x].linearVelocity += 0.3f * turbulence; 110 | 111 | // integrate 112 | particleBuffer[id.x].position += particleBuffer[id.x].linearVelocity * time.y; 113 | float4 q = quat_pow(particleBuffer[id.x].angularVelocity, time.y); 114 | particleBuffer[id.x].rotation = quat_concat(q, particleBuffer[id.x].rotation); 115 | 116 | // damping 117 | float d = 1.0 - particleBuffer[id.x].damping * time.y; 118 | particleBuffer[id.x].linearVelocity *= d; 119 | } 120 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Turbulent Rainbow GPU Particles/ParticleLogic.compute.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c6689aa98202bc2429cce4ed01db01df 3 | ComputeShaderImporter: 4 | externalObjects: {} 5 | currentAPIMask: 0 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Turbulent Rainbow GPU Particles/ParticleStruct.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | 13 | #ifndef PARTICLE_STRUCT 14 | #define PARTICLE_STRUCT 15 | 16 | struct Particle 17 | { 18 | float3 position; 19 | float damping; 20 | 21 | float4 rotation; 22 | 23 | float3 linearVelocity; 24 | float scale; 25 | 26 | float4 angularVelocity; 27 | 28 | float4 lifetime; // (head, body, tail, current) 29 | 30 | float4 color; 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Turbulent Rainbow GPU Particles/ParticleStruct.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1715bcb7f11a0de4ab297bcb1bc6d5a7 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Turbulent Rainbow GPU Particles/ParticleWithForwardPass.shader: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity CJ Lib 4 | https://github.com/TheAllenChou/unity-cj-lib 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | Shader "CjLib/Example/TurbulentRainbowParticle" 13 | { 14 | SubShader 15 | { 16 | Tags { "RenderType" = "Opaque" } 17 | 18 | Pass 19 | { 20 | Name "ForwardBase" 21 | Tags { "LightMode" = "ForwardBase" } 22 | CGPROGRAM 23 | #pragma target 5.0 24 | #pragma vertex vert 25 | #pragma fragment frag 26 | #pragma multi_compile_instancing 27 | #pragma multi_compile_fwdbase 28 | #pragma multi_compile_prepassfinal noshadowmask nodynlightmap nodirlightmap nolightmap 29 | #define PASS_FORWARD 30 | #define PASS_FORWARD_BASE 31 | #include "ParticleCoreWithForwardPass.cginc" 32 | ENDCG 33 | } 34 | 35 | Pass 36 | { 37 | Name "ForwardAdd" 38 | Tags { "LightMode" = "ForwardAdd" } 39 | Blend One One 40 | CGPROGRAM 41 | #pragma target 5.0 42 | #pragma vertex vert 43 | #pragma fragment frag 44 | #pragma multi_compile_instancing 45 | #pragma multi_compile_fwdbase 46 | #pragma multi_compile_prepassfinal noshadowmask nodynlightmap nodirlightmap nolightmap 47 | #define PASS_FORWARD 48 | #define PASS_FORWARD_ADD 49 | #include "ParticleCoreWithForwardPass.cginc" 50 | ENDCG 51 | } 52 | 53 | Pass 54 | { 55 | Name "Deferred" 56 | Tags { "LightMode" = "Deferred" } 57 | CGPROGRAM 58 | #pragma target 5.0 59 | #pragma vertex vert 60 | #pragma fragment frag 61 | #pragma multi_compile_instancing 62 | #pragma multi_compile_prepassfinal noshadowmask nodynlightmap nodirlightmap nolightmap 63 | #define PASS_DEFERRED 64 | #include "ParticleCoreWithForwardPass.cginc" 65 | ENDCG 66 | } 67 | 68 | Pass 69 | { 70 | Name "ShadowCaster" 71 | Tags { "LightMode" = "ShadowCaster" } 72 | CGPROGRAM 73 | #pragma target 5.0 74 | #pragma vertex vert 75 | #pragma fragment frag 76 | #pragma multi_compile_instancing 77 | #pragma multi_compile_prepassfinal noshadowmask nodynlightmap nodirlightmap nolightmap 78 | #define PASS_SHADOW_CASTER 79 | #include "ParticleCoreWithForwardPass.cginc" 80 | ENDCG 81 | } 82 | } 83 | } -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Turbulent Rainbow GPU Particles/ParticleWithForwardPass.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 60ab2dfd0fb963148892ee711b9ef1a0 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Unity CJ Lib/Assets/Example/Turbulent Rainbow GPU Particles/Turbulent Rainbow GPU Particles.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4bed08ef6c35fff428fd98bd7420aaf4 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Unity CJ Lib/Packages/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "com.unity.2d.sprite": "1.0.0", 4 | "com.unity.2d.tilemap": "1.0.0", 5 | "com.unity.ads": "2.3.1", 6 | "com.unity.analytics": "3.3.4", 7 | "com.unity.collab-proxy": "1.2.16", 8 | "com.unity.ide.rider": "1.1.4", 9 | "com.unity.ide.vscode": "1.1.3", 10 | "com.unity.multiplayer-hlapi": "1.0.4", 11 | "com.unity.purchasing": "2.0.6", 12 | "com.unity.test-framework": "1.1.9", 13 | "com.unity.timeline": "1.2.9", 14 | "com.unity.ugui": "1.0.0", 15 | "com.unity.vectorgraphics": "2.0.0-preview.11", 16 | "com.unity.xr.legacyinputhelpers": "2.0.2", 17 | "com.unity.modules.ai": "1.0.0", 18 | "com.unity.modules.androidjni": "1.0.0", 19 | "com.unity.modules.animation": "1.0.0", 20 | "com.unity.modules.assetbundle": "1.0.0", 21 | "com.unity.modules.audio": "1.0.0", 22 | "com.unity.modules.cloth": "1.0.0", 23 | "com.unity.modules.director": "1.0.0", 24 | "com.unity.modules.imageconversion": "1.0.0", 25 | "com.unity.modules.imgui": "1.0.0", 26 | "com.unity.modules.jsonserialize": "1.0.0", 27 | "com.unity.modules.particlesystem": "1.0.0", 28 | "com.unity.modules.physics": "1.0.0", 29 | "com.unity.modules.physics2d": "1.0.0", 30 | "com.unity.modules.screencapture": "1.0.0", 31 | "com.unity.modules.terrain": "1.0.0", 32 | "com.unity.modules.terrainphysics": "1.0.0", 33 | "com.unity.modules.tilemap": "1.0.0", 34 | "com.unity.modules.ui": "1.0.0", 35 | "com.unity.modules.uielements": "1.0.0", 36 | "com.unity.modules.umbra": "1.0.0", 37 | "com.unity.modules.unityanalytics": "1.0.0", 38 | "com.unity.modules.unitywebrequest": "1.0.0", 39 | "com.unity.modules.unitywebrequestassetbundle": "1.0.0", 40 | "com.unity.modules.unitywebrequestaudio": "1.0.0", 41 | "com.unity.modules.unitywebrequesttexture": "1.0.0", 42 | "com.unity.modules.unitywebrequestwww": "1.0.0", 43 | "com.unity.modules.vehicles": "1.0.0", 44 | "com.unity.modules.video": "1.0.0", 45 | "com.unity.modules.vr": "1.0.0", 46 | "com.unity.modules.wind": "1.0.0", 47 | "com.unity.modules.xr": "1.0.0" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Unity CJ Lib/ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!11 &1 4 | AudioManager: 5 | m_ObjectHideFlags: 0 6 | m_Volume: 1 7 | Rolloff Scale: 1 8 | Doppler Factor: 1 9 | Default Speaker Mode: 2 10 | m_SampleRate: 0 11 | m_DSPBufferSize: 0 12 | m_VirtualVoiceCount: 512 13 | m_RealVoiceCount: 32 14 | m_SpatializerPlugin: 15 | m_AmbisonicDecoderPlugin: 16 | m_DisableAudio: 0 17 | m_VirtualizeEffects: 1 18 | -------------------------------------------------------------------------------- /Unity CJ Lib/ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!236 &1 4 | ClusterInputManager: 5 | m_ObjectHideFlags: 0 6 | m_Inputs: [] 7 | -------------------------------------------------------------------------------- /Unity CJ Lib/ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!55 &1 4 | PhysicsManager: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 3 7 | m_Gravity: {x: 0, y: -9.81, z: 0} 8 | m_DefaultMaterial: {fileID: 0} 9 | m_BounceThreshold: 2 10 | m_SleepThreshold: 0.005 11 | m_DefaultContactOffset: 0.01 12 | m_DefaultSolverIterations: 6 13 | m_DefaultSolverVelocityIterations: 1 14 | m_QueriesHitBackfaces: 0 15 | m_QueriesHitTriggers: 1 16 | m_EnableAdaptiveForce: 0 17 | m_EnablePCM: 1 18 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 19 | m_AutoSimulation: 1 20 | -------------------------------------------------------------------------------- /Unity CJ Lib/ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!1045 &1 4 | EditorBuildSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_Scenes: [] 8 | -------------------------------------------------------------------------------- /Unity CJ Lib/ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!159 &1 4 | EditorSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 9 7 | m_ExternalVersionControlSupport: Visible Meta Files 8 | m_SerializationMode: 2 9 | m_LineEndingsForNewScripts: 1 10 | m_DefaultBehaviorMode: 0 11 | m_PrefabRegularEnvironment: {fileID: 0} 12 | m_PrefabUIEnvironment: {fileID: 0} 13 | m_SpritePackerMode: 0 14 | m_SpritePackerPaddingPower: 1 15 | m_EtcTextureCompressorBehavior: 0 16 | m_EtcTextureFastCompressor: 2 17 | m_EtcTextureNormalCompressor: 2 18 | m_EtcTextureBestCompressor: 5 19 | m_ProjectGenerationIncludedExtensions: txt;xml;fnt;cd;asmref 20 | m_ProjectGenerationRootNamespace: 21 | m_CollabEditorSettings: 22 | inProgressEnabled: 1 23 | m_EnableTextureStreamingInEditMode: 1 24 | m_EnableTextureStreamingInPlayMode: 1 25 | m_AsyncShaderCompilation: 1 26 | m_EnterPlayModeOptionsEnabled: 0 27 | m_EnterPlayModeOptions: 3 28 | m_ShowLightmapResolutionOverlay: 1 29 | m_UseLegacyProbeSampleCount: 1 30 | m_AssetPipelineMode: 1 31 | m_CacheServerMode: 0 32 | m_CacheServerEndpoint: 33 | m_CacheServerNamespacePrefix: default 34 | m_CacheServerEnableDownload: 1 35 | m_CacheServerEnableUpload: 1 36 | -------------------------------------------------------------------------------- /Unity CJ Lib/ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!30 &1 4 | GraphicsSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 12 7 | m_Deferred: 8 | m_Mode: 1 9 | m_Shader: {fileID: 69, guid: 0000000000000000f000000000000000, type: 0} 10 | m_DeferredReflections: 11 | m_Mode: 1 12 | m_Shader: {fileID: 74, guid: 0000000000000000f000000000000000, type: 0} 13 | m_ScreenSpaceShadows: 14 | m_Mode: 1 15 | m_Shader: {fileID: 64, guid: 0000000000000000f000000000000000, type: 0} 16 | m_LegacyDeferred: 17 | m_Mode: 1 18 | m_Shader: {fileID: 63, guid: 0000000000000000f000000000000000, type: 0} 19 | m_DepthNormals: 20 | m_Mode: 1 21 | m_Shader: {fileID: 62, guid: 0000000000000000f000000000000000, type: 0} 22 | m_MotionVectors: 23 | m_Mode: 1 24 | m_Shader: {fileID: 75, guid: 0000000000000000f000000000000000, type: 0} 25 | m_LightHalo: 26 | m_Mode: 1 27 | m_Shader: {fileID: 105, guid: 0000000000000000f000000000000000, type: 0} 28 | m_LensFlare: 29 | m_Mode: 1 30 | m_Shader: {fileID: 102, guid: 0000000000000000f000000000000000, type: 0} 31 | m_AlwaysIncludedShaders: 32 | - {fileID: 7, guid: 0000000000000000f000000000000000, type: 0} 33 | - {fileID: 15104, guid: 0000000000000000f000000000000000, type: 0} 34 | - {fileID: 15105, guid: 0000000000000000f000000000000000, type: 0} 35 | - {fileID: 15106, guid: 0000000000000000f000000000000000, type: 0} 36 | - {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0} 37 | - {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0} 38 | - {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0} 39 | - {fileID: 4800000, guid: 034880ed17763504c8c134022d45077a, type: 3} 40 | - {fileID: 4800000, guid: aa5e61c16eee1db4e85f6ef4483fea6d, type: 3} 41 | m_PreloadedShaders: [] 42 | m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000, 43 | type: 0} 44 | m_CustomRenderPipeline: {fileID: 0} 45 | m_TransparencySortMode: 0 46 | m_TransparencySortAxis: {x: 0, y: 0, z: 1} 47 | m_DefaultRenderingPath: 1 48 | m_DefaultMobileRenderingPath: 1 49 | m_TierSettings: [] 50 | m_LightmapStripping: 0 51 | m_FogStripping: 0 52 | m_InstancingStripping: 0 53 | m_LightmapKeepPlain: 1 54 | m_LightmapKeepDirCombined: 1 55 | m_LightmapKeepDynamicPlain: 1 56 | m_LightmapKeepDynamicDirCombined: 1 57 | m_LightmapKeepShadowMask: 1 58 | m_LightmapKeepSubtractive: 1 59 | m_FogKeepLinear: 1 60 | m_FogKeepExp: 1 61 | m_FogKeepExp2: 1 62 | m_AlbedoSwatchInfos: [] 63 | m_LightsUseLinearIntensity: 0 64 | m_LightsUseColorTemperature: 0 65 | -------------------------------------------------------------------------------- /Unity CJ Lib/ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!126 &1 4 | NavMeshProjectSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | areas: 8 | - name: Walkable 9 | cost: 1 10 | - name: Not Walkable 11 | cost: 1 12 | - name: Jump 13 | cost: 2 14 | - name: 15 | cost: 1 16 | - name: 17 | cost: 1 18 | - name: 19 | cost: 1 20 | - name: 21 | cost: 1 22 | - name: 23 | cost: 1 24 | - name: 25 | cost: 1 26 | - name: 27 | cost: 1 28 | - name: 29 | cost: 1 30 | - name: 31 | cost: 1 32 | - name: 33 | cost: 1 34 | - name: 35 | cost: 1 36 | - name: 37 | cost: 1 38 | - name: 39 | cost: 1 40 | - name: 41 | cost: 1 42 | - name: 43 | cost: 1 44 | - name: 45 | cost: 1 46 | - name: 47 | cost: 1 48 | - name: 49 | cost: 1 50 | - name: 51 | cost: 1 52 | - name: 53 | cost: 1 54 | - name: 55 | cost: 1 56 | - name: 57 | cost: 1 58 | - name: 59 | cost: 1 60 | - name: 61 | cost: 1 62 | - name: 63 | cost: 1 64 | - name: 65 | cost: 1 66 | - name: 67 | cost: 1 68 | - name: 69 | cost: 1 70 | - name: 71 | cost: 1 72 | m_LastAgentTypeID: -887442657 73 | m_Settings: 74 | - serializedVersion: 2 75 | agentTypeID: 0 76 | agentRadius: 0.5 77 | agentHeight: 2 78 | agentSlope: 45 79 | agentClimb: 0.75 80 | ledgeDropHeight: 0 81 | maxJumpAcrossDistance: 0 82 | minRegionArea: 2 83 | manualCellSize: 0 84 | cellSize: 0.16666667 85 | manualTileSize: 0 86 | tileSize: 256 87 | accuratePlacement: 0 88 | m_SettingNames: 89 | - Humanoid 90 | -------------------------------------------------------------------------------- /Unity CJ Lib/ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!149 &1 4 | NetworkManager: 5 | m_ObjectHideFlags: 0 6 | m_DebugLevel: 0 7 | m_Sendrate: 15 8 | m_AssetToPrefab: {} 9 | -------------------------------------------------------------------------------- /Unity CJ Lib/ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!19 &1 4 | Physics2DSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 3 7 | m_Gravity: {x: 0, y: -9.81} 8 | m_DefaultMaterial: {fileID: 0} 9 | m_VelocityIterations: 8 10 | m_PositionIterations: 3 11 | m_VelocityThreshold: 1 12 | m_MaxLinearCorrection: 0.2 13 | m_MaxAngularCorrection: 8 14 | m_MaxTranslationSpeed: 100 15 | m_MaxRotationSpeed: 360 16 | m_BaumgarteScale: 0.2 17 | m_BaumgarteTimeOfImpactScale: 0.75 18 | m_TimeToSleep: 0.5 19 | m_LinearSleepTolerance: 0.01 20 | m_AngularSleepTolerance: 2 21 | m_DefaultContactOffset: 0.01 22 | m_AutoSimulation: 1 23 | m_QueriesHitTriggers: 1 24 | m_QueriesStartInColliders: 1 25 | m_ChangeStopsCallbacks: 0 26 | m_CallbacksOnDisable: 1 27 | m_AlwaysShowColliders: 0 28 | m_ShowColliderSleep: 1 29 | m_ShowColliderContacts: 0 30 | m_ShowColliderAABB: 0 31 | m_ContactArrowScale: 0.2 32 | m_ColliderAwakeColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.7529412} 33 | m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432} 34 | m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745} 35 | m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804} 36 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 37 | -------------------------------------------------------------------------------- /Unity CJ Lib/ProjectSettings/PresetManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!1386491679 &1 4 | PresetManager: 5 | m_ObjectHideFlags: 0 6 | m_DefaultList: [] 7 | -------------------------------------------------------------------------------- /Unity CJ Lib/ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 2019.3.0f5 2 | m_EditorVersionWithRevision: 2019.3.0f5 (44796c9d3c2c) 3 | -------------------------------------------------------------------------------- /Unity CJ Lib/ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!47 &1 4 | QualitySettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 5 7 | m_CurrentQuality: 5 8 | m_QualitySettings: 9 | - serializedVersion: 2 10 | name: Very Low 11 | pixelLightCount: 0 12 | shadows: 0 13 | shadowResolution: 0 14 | shadowProjection: 1 15 | shadowCascades: 1 16 | shadowDistance: 15 17 | shadowNearPlaneOffset: 3 18 | shadowCascade2Split: 0.33333334 19 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 20 | shadowmaskMode: 0 21 | blendWeights: 1 22 | textureQuality: 1 23 | anisotropicTextures: 0 24 | antiAliasing: 0 25 | softParticles: 0 26 | softVegetation: 0 27 | realtimeReflectionProbes: 0 28 | billboardsFaceCameraPosition: 0 29 | vSyncCount: 0 30 | lodBias: 0.3 31 | maximumLODLevel: 0 32 | particleRaycastBudget: 4 33 | asyncUploadTimeSlice: 2 34 | asyncUploadBufferSize: 4 35 | resolutionScalingFixedDPIFactor: 1 36 | excludedTargetPlatforms: [] 37 | - serializedVersion: 2 38 | name: Low 39 | pixelLightCount: 0 40 | shadows: 0 41 | shadowResolution: 0 42 | shadowProjection: 1 43 | shadowCascades: 1 44 | shadowDistance: 20 45 | shadowNearPlaneOffset: 3 46 | shadowCascade2Split: 0.33333334 47 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 48 | shadowmaskMode: 0 49 | blendWeights: 2 50 | textureQuality: 0 51 | anisotropicTextures: 0 52 | antiAliasing: 0 53 | softParticles: 0 54 | softVegetation: 0 55 | realtimeReflectionProbes: 0 56 | billboardsFaceCameraPosition: 0 57 | vSyncCount: 0 58 | lodBias: 0.4 59 | maximumLODLevel: 0 60 | particleRaycastBudget: 16 61 | asyncUploadTimeSlice: 2 62 | asyncUploadBufferSize: 4 63 | resolutionScalingFixedDPIFactor: 1 64 | excludedTargetPlatforms: [] 65 | - serializedVersion: 2 66 | name: Medium 67 | pixelLightCount: 1 68 | shadows: 1 69 | shadowResolution: 0 70 | shadowProjection: 1 71 | shadowCascades: 1 72 | shadowDistance: 20 73 | shadowNearPlaneOffset: 3 74 | shadowCascade2Split: 0.33333334 75 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 76 | shadowmaskMode: 0 77 | blendWeights: 2 78 | textureQuality: 0 79 | anisotropicTextures: 1 80 | antiAliasing: 0 81 | softParticles: 0 82 | softVegetation: 0 83 | realtimeReflectionProbes: 0 84 | billboardsFaceCameraPosition: 0 85 | vSyncCount: 1 86 | lodBias: 0.7 87 | maximumLODLevel: 0 88 | particleRaycastBudget: 64 89 | asyncUploadTimeSlice: 2 90 | asyncUploadBufferSize: 4 91 | resolutionScalingFixedDPIFactor: 1 92 | excludedTargetPlatforms: [] 93 | - serializedVersion: 2 94 | name: High 95 | pixelLightCount: 2 96 | shadows: 2 97 | shadowResolution: 1 98 | shadowProjection: 1 99 | shadowCascades: 2 100 | shadowDistance: 40 101 | shadowNearPlaneOffset: 3 102 | shadowCascade2Split: 0.33333334 103 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 104 | shadowmaskMode: 1 105 | blendWeights: 2 106 | textureQuality: 0 107 | anisotropicTextures: 1 108 | antiAliasing: 0 109 | softParticles: 0 110 | softVegetation: 1 111 | realtimeReflectionProbes: 1 112 | billboardsFaceCameraPosition: 1 113 | vSyncCount: 1 114 | lodBias: 1 115 | maximumLODLevel: 0 116 | particleRaycastBudget: 256 117 | asyncUploadTimeSlice: 2 118 | asyncUploadBufferSize: 4 119 | resolutionScalingFixedDPIFactor: 1 120 | excludedTargetPlatforms: [] 121 | - serializedVersion: 2 122 | name: Very High 123 | pixelLightCount: 3 124 | shadows: 2 125 | shadowResolution: 2 126 | shadowProjection: 1 127 | shadowCascades: 2 128 | shadowDistance: 70 129 | shadowNearPlaneOffset: 3 130 | shadowCascade2Split: 0.33333334 131 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 132 | shadowmaskMode: 1 133 | blendWeights: 4 134 | textureQuality: 0 135 | anisotropicTextures: 2 136 | antiAliasing: 2 137 | softParticles: 1 138 | softVegetation: 1 139 | realtimeReflectionProbes: 1 140 | billboardsFaceCameraPosition: 1 141 | vSyncCount: 1 142 | lodBias: 1.5 143 | maximumLODLevel: 0 144 | particleRaycastBudget: 1024 145 | asyncUploadTimeSlice: 2 146 | asyncUploadBufferSize: 4 147 | resolutionScalingFixedDPIFactor: 1 148 | excludedTargetPlatforms: [] 149 | - serializedVersion: 2 150 | name: Ultra 151 | pixelLightCount: 4 152 | shadows: 2 153 | shadowResolution: 2 154 | shadowProjection: 1 155 | shadowCascades: 4 156 | shadowDistance: 150 157 | shadowNearPlaneOffset: 3 158 | shadowCascade2Split: 0.33333334 159 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 160 | shadowmaskMode: 1 161 | blendWeights: 4 162 | textureQuality: 0 163 | anisotropicTextures: 2 164 | antiAliasing: 2 165 | softParticles: 1 166 | softVegetation: 1 167 | realtimeReflectionProbes: 1 168 | billboardsFaceCameraPosition: 1 169 | vSyncCount: 1 170 | lodBias: 2 171 | maximumLODLevel: 0 172 | particleRaycastBudget: 4096 173 | asyncUploadTimeSlice: 2 174 | asyncUploadBufferSize: 4 175 | resolutionScalingFixedDPIFactor: 1 176 | excludedTargetPlatforms: [] 177 | m_PerPlatformDefaultQuality: {} 178 | -------------------------------------------------------------------------------- /Unity CJ Lib/ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!78 &1 4 | TagManager: 5 | serializedVersion: 2 6 | tags: [] 7 | layers: 8 | - Default 9 | - TransparentFX 10 | - Ignore Raycast 11 | - 12 | - Water 13 | - UI 14 | - 15 | - 16 | - 17 | - 18 | - 19 | - 20 | - 21 | - 22 | - 23 | - 24 | - 25 | - 26 | - 27 | - 28 | - 29 | - 30 | - 31 | - 32 | - 33 | - 34 | - 35 | - 36 | - 37 | - 38 | - 39 | - 40 | m_SortingLayers: 41 | - name: Default 42 | uniqueID: 0 43 | locked: 0 44 | -------------------------------------------------------------------------------- /Unity CJ Lib/ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!5 &1 4 | TimeManager: 5 | m_ObjectHideFlags: 0 6 | Fixed Timestep: 0.02 7 | Maximum Allowed Timestep: 0.33333334 8 | m_TimeScale: 1 9 | Maximum Particle Timestep: 0.03 10 | -------------------------------------------------------------------------------- /Unity CJ Lib/ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!310 &1 4 | UnityConnectSettings: 5 | m_ObjectHideFlags: 0 6 | m_Enabled: 0 7 | m_TestMode: 0 8 | m_TestEventUrl: 9 | m_TestConfigUrl: 10 | m_TestInitMode: 0 11 | CrashReportingSettings: 12 | m_EventUrl: https://perf-events.cloud.unity3d.com/api/events/crashes 13 | m_Enabled: 0 14 | m_CaptureEditorExceptions: 1 15 | UnityPurchasingSettings: 16 | m_Enabled: 0 17 | m_TestMode: 0 18 | UnityAnalyticsSettings: 19 | m_Enabled: 1 20 | m_InitializeOnStartup: 1 21 | m_TestMode: 0 22 | m_TestEventUrl: 23 | m_TestConfigUrl: 24 | UnityAdsSettings: 25 | m_Enabled: 0 26 | m_InitializeOnStartup: 1 27 | m_TestMode: 0 28 | m_EnabledPlatforms: 4294967295 29 | m_IosGameId: 30 | m_AndroidGameId: 31 | m_GameIds: {} 32 | m_GameId: 33 | PerformanceReportingSettings: 34 | m_Enabled: 0 35 | -------------------------------------------------------------------------------- /img/gpu-particles-with-primitive-collider-physics.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheAllenChou/unity-cj-lib/90b3c739475f5a0e20dc8825ff7525027e488b9a/img/gpu-particles-with-primitive-collider-physics.gif -------------------------------------------------------------------------------- /img/turbulent-rainbow-cubes.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheAllenChou/unity-cj-lib/90b3c739475f5a0e20dc8825ff7525027e488b9a/img/turbulent-rainbow-cubes.gif --------------------------------------------------------------------------------