├── .gitignore ├── LICENSE ├── LinesByDistance ├── Assets │ ├── LinesByDistance.meta │ ├── LinesByDistance │ │ ├── ComputeShaders.meta │ │ ├── ComputeShaders │ │ │ ├── Kernel.compute │ │ │ └── Kernel.compute.meta │ │ ├── Scenes.meta │ │ ├── Scenes │ │ │ ├── LinesByDistance.unity │ │ │ └── LinesByDistance.unity.meta │ │ ├── Scripts.meta │ │ ├── Scripts │ │ │ ├── LinesByDistance.cs │ │ │ └── LinesByDistance.cs.meta │ │ ├── Shaders.meta │ │ └── Shaders │ │ │ ├── LineRender.shader │ │ │ └── LineRender.shader.meta │ ├── ParticleOnSphere.meta │ └── ParticleOnSphere │ │ ├── Kernel.compute │ │ ├── Kernel.compute.meta │ │ ├── Particle.png │ │ ├── Particle.png.meta │ │ ├── ParticleOnSphere.cs │ │ ├── ParticleOnSphere.cs.meta │ │ ├── ParticleRender.shader │ │ └── ParticleRender.shader.meta └── ProjectSettings │ ├── AudioManager.asset │ ├── ClusterInputManager.asset │ ├── DynamicsManager.asset │ ├── EditorBuildSettings.asset │ ├── EditorSettings.asset │ ├── GraphicsSettings.asset │ ├── InputManager.asset │ ├── NavMeshAreas.asset │ ├── NetworkManager.asset │ ├── Physics2DSettings.asset │ ├── ProjectSettings.asset │ ├── ProjectVersion.txt │ ├── QualitySettings.asset │ ├── TagManager.asset │ ├── TimeManager.asset │ ├── UnityAdsSettings.asset │ └── UnityConnectSettings.asset ├── README.md └── img.jpg /.gitignore: -------------------------------------------------------------------------------- 1 | /LinesByDistance/[Ll]ibrary/ 2 | /LinesByDistance/[Tt]emp/ 3 | /LinesByDistance/[Oo]bj/ 4 | /LinesByDistance/[Bb]uild/ 5 | /LinesByDistance/[Bb]uilds/ 6 | /LinesByDistance/Assets/AssetStoreTools* 7 | 8 | # Autogenerated VS/MD solution and project files 9 | ExportedObj/ 10 | *.csproj 11 | *.unityproj 12 | *.sln 13 | *.suo 14 | *.tmp 15 | *.user 16 | *.userprefs 17 | *.pidb 18 | *.booproj 19 | *.svd 20 | 21 | 22 | # Unity3D generated meta files 23 | *.pidb.meta 24 | 25 | # Unity3D Generated File On Crash Reports 26 | sysinfo.txt 27 | 28 | # Builds 29 | *.apk 30 | *.unitypackage 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 OISHIHiroaki 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 | -------------------------------------------------------------------------------- /LinesByDistance/Assets/LinesByDistance.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: df5850d8812f8ac47bd3d7b9c843f780 3 | folderAsset: yes 4 | timeCreated: 1486176011 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /LinesByDistance/Assets/LinesByDistance/ComputeShaders.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a1d36a9aa19ee6a4e8e1beae8b41a8da 3 | folderAsset: yes 4 | timeCreated: 1486176016 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /LinesByDistance/Assets/LinesByDistance/ComputeShaders/Kernel.compute: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------- 2 | // kernels 3 | // ----------------------------------------------------------------- 4 | #pragma kernel CSUpdate 5 | #pragma kernel CSUpdate_Shared 6 | 7 | // ----------------------------------------------------------------- 8 | // Constants 9 | // ----------------------------------------------------------------- 10 | #define NUM_THREAD_X 256 11 | #define NUM_THREAD_Y 1 12 | #define NUM_THREAD_Z 1 13 | 14 | // ----------------------------------------------------------------- 15 | // Structures 16 | // ----------------------------------------------------------------- 17 | struct LineData 18 | { 19 | float3 position0; 20 | float alpha0; 21 | float3 position1; 22 | float alpha1; 23 | }; 24 | 25 | // ----------------------------------------------------------------- 26 | // Resources and Variables 27 | // ----------------------------------------------------------------- 28 | StructuredBuffer _VertexBufferRead; 29 | AppendStructuredBuffer _LineBufferWrite; 30 | RWStructuredBuffer _CounterBuffer; 31 | 32 | int _VertexNum; 33 | int _MaxLineNum; 34 | 35 | float _MinDist; 36 | float _MaxDist; 37 | 38 | // ----------------------------------------------------------------- 39 | // Kernel Functions 40 | // ----------------------------------------------------------------- 41 | // 更新 42 | [numthreads(NUM_THREAD_X, 1, 1)] 43 | void CSUpdate(uint3 DTid : SV_DispatchThreadID) 44 | { 45 | uint idx = DTid.x; 46 | 47 | float3 P_position = _VertexBufferRead[idx].xyz; 48 | 49 | int count = 0; 50 | int j; 51 | for (j = idx; j < _VertexNum; j++) 52 | { 53 | float3 N_position = _VertexBufferRead[j]; 54 | float3 diff = N_position - P_position; 55 | float dist = sqrt(dot(diff, diff)); 56 | if (dist > _MinDist && dist < _MaxDist) 57 | { 58 | count = _CounterBuffer.IncrementCounter(); 59 | if (count <= _MaxLineNum) 60 | { 61 | LineData ld; 62 | ld.position0 = P_position; 63 | ld.alpha0 = 1.0; 64 | ld.position1 = N_position; 65 | ld.alpha1 = 1.0; 66 | _LineBufferWrite.Append(ld); 67 | } 68 | } 69 | } 70 | } 71 | 72 | // 更新(シェアードメモリ使用) 73 | groupshared float3 shared_pos[NUM_THREAD_X]; 74 | 75 | [numthreads(NUM_THREAD_X, 1, 1)] 76 | void CSUpdate_Shared 77 | ( 78 | uint3 DTid : SV_DispatchThreadID, 79 | uint3 GTid : SV_GroupThreadID, 80 | uint3 Gid : SV_GroupID, 81 | uint GI : SV_GroupIndex 82 | ) 83 | { 84 | uint idx = DTid.x; 85 | 86 | float3 P_position = _VertexBufferRead[idx].xyz; 87 | 88 | [loop] 89 | for (uint N_block_ID = 0; N_block_ID < (uint)_VertexNum; N_block_ID += NUM_THREAD_X) 90 | { 91 | shared_pos[GI] = _VertexBufferRead[N_block_ID + GI]; 92 | 93 | GroupMemoryBarrierWithGroupSync(); 94 | for (int N_tile_ID = 0; N_tile_ID < NUM_THREAD_X; N_tile_ID++) 95 | { 96 | 97 | float3 N_position = shared_pos[N_tile_ID].xyz; 98 | 99 | float3 diff = P_position - N_position; 100 | float dist = sqrt(dot(diff, diff)); 101 | 102 | if (dist > _MinDist && dist < _MaxDist) 103 | { 104 | // ラインをカウント 105 | int count = _CounterBuffer.IncrementCounter(); 106 | // ラインが規定数を超えないように 107 | if (count <= _MaxLineNum) 108 | { 109 | LineData ld; 110 | float alpha = 1.0; 111 | ld.position0 = P_position; 112 | ld.alpha0 = alpha; 113 | ld.position1 = N_position; 114 | ld.alpha1 = alpha; 115 | _LineBufferWrite.Append(ld); 116 | } 117 | } 118 | } 119 | GroupMemoryBarrierWithGroupSync(); 120 | } 121 | } -------------------------------------------------------------------------------- /LinesByDistance/Assets/LinesByDistance/ComputeShaders/Kernel.compute.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a42a04afb03e69947817b5ef7397a358 3 | timeCreated: 1486179263 4 | licenseType: Pro 5 | ComputeShaderImporter: 6 | currentAPIMask: 4 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /LinesByDistance/Assets/LinesByDistance/Scenes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b7fcbc525713d90479e7ce6049e9b767 3 | folderAsset: yes 4 | timeCreated: 1486180012 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /LinesByDistance/Assets/LinesByDistance/Scenes/LinesByDistance.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiroakioishi/UnityLinesByDistance/0d84db0f9578622ab8f6d5d935b7fd1cf5fb159e/LinesByDistance/Assets/LinesByDistance/Scenes/LinesByDistance.unity -------------------------------------------------------------------------------- /LinesByDistance/Assets/LinesByDistance/Scenes/LinesByDistance.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6363f3105b8471048aca3b4383045961 3 | timeCreated: 1486180012 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /LinesByDistance/Assets/LinesByDistance/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1d4d09e6c9fd4c047b1f8283506e2207 3 | folderAsset: yes 4 | timeCreated: 1486176016 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /LinesByDistance/Assets/LinesByDistance/Scripts/LinesByDistance.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace irishoak.Sample 6 | { 7 | public class LinesByDistance : MonoBehaviour 8 | { 9 | 10 | #region Structs 11 | public struct LineData 12 | { 13 | public Vector3 Position0; // ラインの端点,点0の位置 14 | public float Alpha0; // ラインの端点,点0の不透明度 15 | public Vector3 Position1; // ラインの端点,点1の位置 16 | public float Alpha1; // ラインの端点,点1の不透明度 17 | }; 18 | #endregion 19 | 20 | #region Constants 21 | // ラインの最大数 22 | const int MAX_LINE_NUM = 524288; 23 | // 頂点の最大数 24 | const int MAX_VERTEX_NUM = 16384; 25 | // 生成されるラインを制限するためのカウンタの最大数 26 | const int MAX_LINE_COUNTER_NUM = 2097152; 27 | 28 | // スレッドグループ数(X) 29 | const int MUM_THREAD = 256; 30 | #endregion 31 | 32 | #region Public Resources 33 | [Tooltip("ラインの生成を行うComputeShader")] 34 | public ComputeShader KernelCS; 35 | [Tooltip("ラインを描画するShader")] 36 | public Shader LineRenderShader; 37 | #endregion 38 | 39 | #region Properties 40 | [Range(0.0f, 10.0f), Tooltip("ラインを結ぶ最小距離")] 41 | public float MinDist = 0.1f; 42 | [Range(0.0f, 10.0f), Tooltip("ラインを結ぶ最大距離")] 43 | public float MaxDist = 0.3f; 44 | [Tooltip("ラインの色")] 45 | public Color LineColor = Color.white; 46 | 47 | [Tooltip("頂点バッファの初期化を行うか(他のスクリプトから頂点バッファの代入を行う場合はfalseに)")] 48 | public bool IsEnableInitVertexBuffer = false; 49 | [Tooltip("GUIにデバッグ用テキストを表示するか")] 50 | public bool EnableDrawDebugTextOnGUI = false; 51 | #endregion 52 | 53 | #region Private Variables and Resources 54 | // 頂点を格納するバッファ 55 | ComputeBuffer _vertexBuffer; 56 | // ラインデータを格納するバッファ 57 | ComputeBuffer _lineDataBuffer; 58 | // 生成されたラインをカウントするバッファ 59 | ComputeBuffer _generatedLineCounterBuffer; 60 | // ラインのIndirect描画のための変数を扱うバッファ 61 | ComputeBuffer _drawLinesIndirectArgsBuffer; 62 | 63 | // ラインのIndirect描画のための変数 64 | int[] _drawLinesIndirectArgs; 65 | 66 | // 現在のラインの数 67 | int _currentLinesNum = 0; 68 | 69 | // ラインを描画するマテリアル 70 | Material _lineRenderMat; 71 | #endregion 72 | 73 | #region Accessor 74 | /// 75 | /// 頂点バッファをセット 76 | /// 77 | /// 78 | public void SetVertexBuffer(ref ComputeBuffer buffer) 79 | { 80 | this._vertexBuffer = buffer; 81 | } 82 | #endregion 83 | 84 | #region MonoBehaviour Functions 85 | void Start() 86 | { 87 | InitResources(); 88 | } 89 | 90 | void Update() 91 | { 92 | UpdateLines(); 93 | } 94 | 95 | void OnRenderObject() 96 | { 97 | DrawLines(); 98 | } 99 | 100 | void OnDestroy() 101 | { 102 | ReleaseResources(); 103 | } 104 | 105 | void OnGUI() 106 | { 107 | if (!EnableDrawDebugTextOnGUI) return; 108 | 109 | int restoreFontSize = GUI.skin.label.fontSize; 110 | GUI.skin.label.fontSize = 24; 111 | GUI.Label(new Rect(32, 32, 512, 64), "CurrentLineNum : " + _currentLinesNum.ToString()); 112 | GUI.skin.label.fontSize = restoreFontSize; 113 | 114 | } 115 | #endregion 116 | 117 | #region Private Functions 118 | /// 119 | /// リソースを初期化 120 | /// 121 | void InitResources() 122 | { 123 | _drawLinesIndirectArgs = new int[4] { 0, 1, 0, 0 }; 124 | 125 | // --- ComputeBuffer --- 126 | if (IsEnableInitVertexBuffer) 127 | { 128 | var vertexArr = new Vector3[MAX_VERTEX_NUM]; 129 | for (int i = 0; i < vertexArr.Length; i++) 130 | { 131 | vertexArr[i] = UnityEngine.Random.insideUnitSphere * 2.0f; 132 | } 133 | 134 | _vertexBuffer = new ComputeBuffer(MAX_VERTEX_NUM, Marshal.SizeOf(typeof(Vector3))); 135 | _vertexBuffer.SetData(vertexArr); 136 | 137 | vertexArr = null; 138 | } 139 | 140 | _lineDataBuffer = new ComputeBuffer(MAX_LINE_NUM, Marshal.SizeOf(typeof(LineData)), ComputeBufferType.Append); // AppendStructuredBufferとして初期化 141 | _lineDataBuffer.SetCounterValue(0); // カウンタリセット 142 | 143 | _generatedLineCounterBuffer = new ComputeBuffer(MAX_LINE_COUNTER_NUM, Marshal.SizeOf(typeof(int)), ComputeBufferType.Counter); // CounterBufferとして初期化 144 | _generatedLineCounterBuffer.SetCounterValue(0); // カウンタリセット 145 | 146 | _drawLinesIndirectArgsBuffer = new ComputeBuffer(4, Marshal.SizeOf(typeof(int)), ComputeBufferType.IndirectArguments); 147 | 148 | } 149 | 150 | /// 151 | /// リソースを解放 152 | /// 153 | void ReleaseResources() 154 | { 155 | if(_vertexBuffer != null) 156 | { 157 | _vertexBuffer.Release(); 158 | _vertexBuffer = null; 159 | } 160 | 161 | if(_lineDataBuffer != null) 162 | { 163 | _lineDataBuffer.Release(); 164 | _lineDataBuffer = null; 165 | } 166 | 167 | if(_generatedLineCounterBuffer != null) 168 | { 169 | _generatedLineCounterBuffer.Release(); 170 | _generatedLineCounterBuffer = null; 171 | } 172 | 173 | if (_drawLinesIndirectArgsBuffer != null) 174 | { 175 | _drawLinesIndirectArgsBuffer.Release(); 176 | _drawLinesIndirectArgsBuffer = null; 177 | } 178 | 179 | if (_lineRenderMat != null) 180 | { 181 | Material.DestroyImmediate(_lineRenderMat); 182 | _lineRenderMat = null; 183 | } 184 | 185 | } 186 | 187 | /// 188 | /// ラインのデータを更新 189 | /// 190 | void UpdateLines() 191 | { 192 | if (_vertexBuffer == null) return; 193 | 194 | _generatedLineCounterBuffer.SetCounterValue(0); 195 | _lineDataBuffer.SetCounterValue(0); 196 | 197 | ComputeShader cs = KernelCS; 198 | //int id = cs.FindKernel("CSUpdate"); 199 | int id = cs.FindKernel("CSUpdate_Shared"); 200 | 201 | cs.SetFloat("_MinDist", MinDist); 202 | cs.SetFloat("_MaxDist", MaxDist); 203 | cs.SetInt ("_VertexNum", MAX_VERTEX_NUM); 204 | cs.SetInt ("_MaxLineNum", MAX_LINE_NUM); 205 | cs.SetBuffer(id, "_VertexBufferRead", _vertexBuffer); 206 | cs.SetBuffer(id, "_LineBufferWrite", _lineDataBuffer); 207 | cs.SetBuffer(id, "_CounterBuffer", _generatedLineCounterBuffer); 208 | 209 | cs.Dispatch(id, MAX_VERTEX_NUM / MUM_THREAD, 1, 1); 210 | } 211 | 212 | /// 213 | /// ラインを描画 214 | /// 215 | void DrawLines() 216 | { 217 | if (_lineRenderMat == null) 218 | { 219 | _lineRenderMat = new Material(LineRenderShader); 220 | _lineRenderMat.hideFlags = HideFlags.HideAndDontSave; 221 | } 222 | 223 | // ラインの数を取得 224 | _currentLinesNum = GetCurrentLineNum(); 225 | 226 | _lineRenderMat.SetPass(0); 227 | _lineRenderMat.SetColor("_Color", LineColor); 228 | _lineRenderMat.SetBuffer("_LineDataBuffer", _lineDataBuffer); 229 | Graphics.DrawProceduralIndirect(MeshTopology.Points, _drawLinesIndirectArgsBuffer, 0); 230 | } 231 | 232 | /// 233 | /// ラインの数を取得 234 | /// 235 | /// ラインの数 236 | int GetCurrentLineNum() 237 | { 238 | // CPU->GPU 239 | _drawLinesIndirectArgsBuffer.SetData(_drawLinesIndirectArgs); 240 | // ライン数を取得 241 | ComputeBuffer.CopyCount(_lineDataBuffer, _drawLinesIndirectArgsBuffer, 0); 242 | // GPU->CPU 243 | _drawLinesIndirectArgsBuffer.GetData(_drawLinesIndirectArgs); 244 | return _drawLinesIndirectArgs[0]; 245 | } 246 | 247 | #endregion 248 | } 249 | } -------------------------------------------------------------------------------- /LinesByDistance/Assets/LinesByDistance/Scripts/LinesByDistance.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a66d53bfa1800a248b50f2a9de4fcecc 3 | timeCreated: 1486176103 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /LinesByDistance/Assets/LinesByDistance/Shaders.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7aaab8f32e1ae3e44a67fd588452cff1 3 | folderAsset: yes 4 | timeCreated: 1486176016 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /LinesByDistance/Assets/LinesByDistance/Shaders/LineRender.shader: -------------------------------------------------------------------------------- 1 | Shader "Hidden/irishoak/LinesByDistance/LineRender" 2 | { 3 | Properties 4 | { 5 | _MainTex("Texture", 2D) = "white" {} 6 | } 7 | 8 | CGINCLUDE 9 | #include "UnityCG.cginc" 10 | 11 | struct lineData 12 | { 13 | float3 position0; 14 | float alpha0; 15 | float3 position1; 16 | float alpha1; 17 | }; 18 | 19 | struct v2g 20 | { 21 | float4 vertex0 : POSITION; 22 | float4 vertex1 : TEXCOORD2; 23 | float alpha0 : TEXCOORD0; 24 | float alpha1 : TEXCOORD1; 25 | }; 26 | 27 | struct g2f 28 | { 29 | float4 position : SV_POSITION; 30 | float4 color : COLOR; 31 | }; 32 | 33 | sampler2D _MainTex; 34 | float4 _MainTex_ST; 35 | 36 | StructuredBuffer _LineDataBuffer; 37 | 38 | float4 _Color; 39 | 40 | // -------------------------------------------------------------------- 41 | // Vertex Shader 42 | // -------------------------------------------------------------------- 43 | v2g vert(uint id : SV_VertexID) 44 | { 45 | v2g o = (v2g)0; 46 | o.vertex0 = UnityObjectToClipPos(float4(_LineDataBuffer[id].position0, 1.0)); 47 | o.alpha0 = _LineDataBuffer[id].alpha0; 48 | o.vertex1 = UnityObjectToClipPos(float4(_LineDataBuffer[id].position1, 1.0)); 49 | o.alpha1 = _LineDataBuffer[id].alpha1; 50 | return o; 51 | } 52 | 53 | // -------------------------------------------------------------------- 54 | // Geometry Shader 55 | // -------------------------------------------------------------------- 56 | [maxvertexcount(2)] 57 | void geom(point v2g points[1], inout LineStream stream) 58 | { 59 | g2f o = (g2f)0; 60 | 61 | float4 pos0 = points[0].vertex0; 62 | float4 pos1 = points[0].vertex1; 63 | 64 | float a0 = points[0].alpha0; 65 | float a1 = points[0].alpha1; 66 | 67 | o.color = float4(1, 1, 1, 1) * a0; 68 | o.position = pos0; 69 | stream.Append(o); 70 | 71 | o.color = float4(1, 1, 1, 1) * a1; 72 | o.position = pos1; 73 | stream.Append(o); 74 | 75 | stream.RestartStrip(); 76 | } 77 | 78 | // -------------------------------------------------------------------- 79 | // Fragment Shader 80 | // -------------------------------------------------------------------- 81 | fixed4 frag(g2f i) : SV_Target 82 | { 83 | fixed4 col = i.color * _Color; 84 | return col; 85 | } 86 | ENDCG 87 | 88 | SubShader 89 | { 90 | Tags{ "RenderType" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" } 91 | LOD 100 92 | 93 | Blend One One 94 | ZWrite Off 95 | 96 | Pass 97 | { 98 | CGPROGRAM 99 | #pragma target 5.0 100 | #pragma vertex vert 101 | #pragma geometry geom 102 | #pragma fragment frag 103 | ENDCG 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /LinesByDistance/Assets/LinesByDistance/Shaders/LineRender.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 559fc35f342a72a42ad4b87aba62be3d 3 | timeCreated: 1486178806 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /LinesByDistance/Assets/ParticleOnSphere.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c4cfb368f63f5584ea275bf7f423a028 3 | folderAsset: yes 4 | timeCreated: 1486180197 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /LinesByDistance/Assets/ParticleOnSphere/Kernel.compute: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------- 2 | // kernels 3 | // ----------------------------------------------------------------- 4 | #pragma kernel CSUpdate 5 | #pragma kernel CSCopyVertex 6 | 7 | // ----------------------------------------------------------------- 8 | // Constants 9 | // ----------------------------------------------------------------- 10 | #define NUM_THREAD_X 256 11 | #define PI 3.14159265359 12 | 13 | // ----------------------------------------------------------------- 14 | // Structures 15 | // ----------------------------------------------------------------- 16 | struct ParticleData 17 | { 18 | float3 velocity; 19 | float3 position; 20 | float age; 21 | float pad0; 22 | }; 23 | 24 | // ----------------------------------------------------------------- 25 | // Resources and Variables 26 | // ----------------------------------------------------------------- 27 | RWStructuredBuffer _ParticleBuffer; 28 | RWStructuredBuffer _VertexBuffer; 29 | 30 | float4 _LifeParams; 31 | float _DeltaTime; 32 | float _Velocity; 33 | float _Radius; 34 | float _SurfaceLayerNum; 35 | float _Timer; 36 | float _Throttle; 37 | 38 | // ----------------------------------------------------------------- 39 | // Functions 40 | // ----------------------------------------------------------------- 41 | float rand(float2 co) { 42 | return frac(sin(dot(co.xy, float2(12.9898, 78.233))) * 43758.5453); 43 | } 44 | 45 | float3 RandomInsideUnitSphere(float idx) 46 | { 47 | float phi = 2.0 * PI * rand(float2(idx, 0.0)); 48 | float th = 0.05 + acos(1.0 - 2.0 * rand(float2(idx, 0.1))); 49 | float r = pow(rand(float2(idx, 0.2)), 0.333333333); 50 | 51 | float x = r * sin(th) * cos(phi); 52 | float z = r * sin(th) * sin(phi); 53 | float y = r * cos(th); 54 | 55 | return float3(x, y, z); 56 | } 57 | 58 | // ----------------------------------------------------------------- 59 | // Kernel Functions 60 | // ----------------------------------------------------------------- 61 | // パーティクルの更新 62 | [numthreads(NUM_THREAD_X, 1, 1)] 63 | void CSUpdate 64 | ( 65 | uint3 DTid : SV_DispatchThreadID, 66 | uint3 GTid : SV_GroupThreadID, 67 | uint3 Gid : SV_GroupID, 68 | uint GI : SV_GroupIndex 69 | ) 70 | { 71 | uint idx = DTid.x; 72 | 73 | float3 velocity = _ParticleBuffer[idx].velocity; 74 | float3 position = _ParticleBuffer[idx].position; 75 | float age = _ParticleBuffer[idx].age; 76 | 77 | // update 78 | position += velocity * _DeltaTime; 79 | age += lerp(_LifeParams.x, _LifeParams.y, rand(float2(idx, 0.0))) * _DeltaTime; 80 | 81 | if (age > 1.0) 82 | { 83 | // velcoity 84 | velocity = RandomInsideUnitSphere(idx + 0.0f + _Timer) * _Velocity; 85 | 86 | // position 87 | float4 offset = rand(float2(idx, 0.1)) < _Throttle ? float4(0, 0, 0, 1) : float4(1e6, 1e6, 1e6, 1e6); 88 | float3 newPos = RandomInsideUnitSphere(idx + 0.5f + _Timer); 89 | float radius = length(newPos); 90 | float layer = (ceil(radius / (1.0/_SurfaceLayerNum))) / _SurfaceLayerNum; 91 | position = normalize(newPos) * layer * _Radius * offset.w + offset.xyz; 92 | 93 | // age 94 | age = 0.0; 95 | } 96 | 97 | _ParticleBuffer[idx].velocity = velocity; 98 | _ParticleBuffer[idx].position = position; 99 | _ParticleBuffer[idx].age = age; 100 | } 101 | 102 | // パーティクルの位置データをコピー 103 | [numthreads(NUM_THREAD_X, 1, 1)] 104 | void CSCopyVertex 105 | ( 106 | uint3 DTid : SV_DispatchThreadID, 107 | uint3 GTid : SV_GroupThreadID, 108 | uint3 Gid : SV_GroupID, 109 | uint GI : SV_GroupIndex 110 | ) 111 | { 112 | uint idx = DTid.x; 113 | _VertexBuffer[DTid.x] = _ParticleBuffer[DTid.x].position; 114 | } 115 | -------------------------------------------------------------------------------- /LinesByDistance/Assets/ParticleOnSphere/Kernel.compute.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b70b1e55702a04747b3ff8531f149318 3 | timeCreated: 1486182369 4 | licenseType: Pro 5 | ComputeShaderImporter: 6 | currentAPIMask: 4 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /LinesByDistance/Assets/ParticleOnSphere/Particle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiroakioishi/UnityLinesByDistance/0d84db0f9578622ab8f6d5d935b7fd1cf5fb159e/LinesByDistance/Assets/ParticleOnSphere/Particle.png -------------------------------------------------------------------------------- /LinesByDistance/Assets/ParticleOnSphere/Particle.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 675ddbf0fb35bc448ab152533284ce43 3 | timeCreated: 1486191458 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 2 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 1 11 | linearTexture: 0 12 | correctGamma: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 0 25 | cubemapConvolution: 0 26 | cubemapConvolutionSteps: 7 27 | cubemapConvolutionExponent: 1.5 28 | seamlessCubemap: 0 29 | textureFormat: -1 30 | maxTextureSize: 2048 31 | textureSettings: 32 | filterMode: -1 33 | aniso: -1 34 | mipBias: -1 35 | wrapMode: -1 36 | nPOTScale: 1 37 | lightmap: 0 38 | rGBM: 0 39 | compressionQuality: 50 40 | allowsAlphaSplitting: 0 41 | spriteMode: 0 42 | spriteExtrude: 1 43 | spriteMeshType: 1 44 | alignment: 0 45 | spritePivot: {x: 0.5, y: 0.5} 46 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 47 | spritePixelsToUnits: 100 48 | alphaIsTransparency: 0 49 | spriteTessellationDetail: -1 50 | textureType: -1 51 | buildTargetSettings: [] 52 | spriteSheet: 53 | serializedVersion: 2 54 | sprites: [] 55 | outline: [] 56 | spritePackingTag: 57 | userData: 58 | assetBundleName: 59 | assetBundleVariant: 60 | -------------------------------------------------------------------------------- /LinesByDistance/Assets/ParticleOnSphere/ParticleOnSphere.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace irishoak.Sample 6 | { 7 | public class ParticleOnSphere : MonoBehaviour 8 | { 9 | #region Structures 10 | public struct ParticleData 11 | { 12 | public Vector3 Velocity; 13 | public Vector3 Position; 14 | public float Age; 15 | public float Pad0; 16 | }; 17 | #endregion 18 | 19 | #region Constants 20 | // パーティクルの最大数 21 | const int NUM_PARTICLES = 16384; 22 | // スレッドグループ数(X) 23 | const int NUM_THREAD = 256; 24 | #endregion 25 | 26 | #region Properties 27 | [Range(0.1f, 10.0f), Tooltip("パーティクルの寿命(最小値)")] 28 | public float LifeMin = 1.0f; 29 | [Range(0.1f, 10.0f), Tooltip("パーティクルの寿命(最大値)")] 30 | public float LifeMax = 2.0f; 31 | [Range(0.0f, 10.0f), Tooltip("速度")] 32 | public float Velocity = 0.1f; 33 | [Range(1.0f, 10.0f), Tooltip("パーティクルを生成するエリアの半径")] 34 | public float SphereRadius = 5.0f; 35 | [Range(1, 10), Tooltip("サーフェスの層の数")] 36 | public int SurfaceLayerNum = 10; 37 | 38 | [Range(0.0f, 1.0f), Tooltip("放出量")] 39 | public float Throttle = 1.0f; 40 | 41 | [Tooltip("パーティクルのテクスチャ")] 42 | public Texture2D ParticleTex = null; 43 | [Tooltip("パーティクルのサイズ")] 44 | public float ParticleSize = 0.025f; 45 | [Tooltip("パーティクルのカラー")] 46 | public Color ParticleColor = Color.white; 47 | #endregion 48 | 49 | #region Public Resources and References 50 | [Tooltip("パーティクル位置更新のためのComputeShader")] 51 | public ComputeShader KernelCS; 52 | [Tooltip("パーティクルの描画のためのシェーダ")] 53 | public Shader RenderShader = null; 54 | [Tooltip("レンダリングに使用するカメラの参照(ビルボードに使用)")] 55 | public Camera RenderCamera = null; 56 | [Tooltip("スクリプトの参照")] 57 | public LinesByDistance LinesByDistanceScript = null; 58 | #endregion 59 | 60 | #region Private Resources and Variables 61 | // パーティクルのデータのバッファ 62 | ComputeBuffer _particleBuffer; 63 | // パーティクルの頂点データのバッファ 64 | ComputeBuffer _vertexBuffer; 65 | // パーティクル描画のマテリアル 66 | Material _particleRenderMat = null; 67 | #endregion 68 | 69 | #region MonoBehaviour 70 | void Start() 71 | { 72 | InitResources(); 73 | } 74 | 75 | void Update() 76 | { 77 | if (LinesByDistanceScript != null) 78 | { 79 | // VertexBufferのパーティクルの位置データをコピー 80 | int id = KernelCS.FindKernel("CSCopyVertex"); 81 | KernelCS.SetBuffer(id, "_VertexBuffer", _vertexBuffer); 82 | KernelCS.SetBuffer(id, "_ParticleBuffer", _particleBuffer); 83 | KernelCS.Dispatch(id, NUM_THREAD, 1, 1); 84 | 85 | // Lineスクリプトに頂点バッファをセット 86 | LinesByDistanceScript.SetVertexBuffer(ref _vertexBuffer); 87 | } 88 | 89 | UpdateParticles(); 90 | } 91 | 92 | void OnRenderObject() 93 | { 94 | DrawParticles(); 95 | } 96 | 97 | void OnDestroy() 98 | { 99 | ReleaseResources(); 100 | } 101 | #endregion 102 | 103 | #region Private Functions 104 | /// 105 | /// リソースを初期化 106 | /// 107 | void InitResources() 108 | { 109 | _particleBuffer = new ComputeBuffer(NUM_PARTICLES, Marshal.SizeOf(typeof(ParticleData))); 110 | 111 | var particleDataArr = new ParticleData[NUM_PARTICLES]; 112 | for (var i = 0; i < particleDataArr.Length; i++) 113 | { 114 | particleDataArr[i].Velocity = UnityEngine.Random.insideUnitSphere * Velocity; 115 | particleDataArr[i].Position = UnityEngine.Random.insideUnitSphere * SphereRadius; 116 | particleDataArr[i].Age = 0.0f; 117 | particleDataArr[i].Pad0 = 0.0f; 118 | } 119 | _particleBuffer.SetData(particleDataArr); 120 | particleDataArr = null; 121 | 122 | _vertexBuffer = new ComputeBuffer(NUM_PARTICLES, Marshal.SizeOf(typeof(Vector3))); 123 | } 124 | 125 | /// 126 | /// リソースを解放 127 | /// 128 | void ReleaseResources() 129 | { 130 | if (_particleBuffer != null) 131 | { 132 | _particleBuffer.Release(); 133 | _particleBuffer = null; 134 | } 135 | 136 | if (_vertexBuffer != null) 137 | { 138 | _vertexBuffer.Release(); 139 | _vertexBuffer = null; 140 | } 141 | 142 | if (_particleRenderMat != null) 143 | { 144 | Material.DestroyImmediate(_particleRenderMat); 145 | _particleRenderMat = null; 146 | } 147 | } 148 | 149 | /// 150 | /// パーティクルを更新 151 | /// 152 | void UpdateParticles() 153 | { 154 | ComputeShader cs = KernelCS; 155 | int kernelId = cs.FindKernel("CSUpdate"); 156 | 157 | cs.SetBuffer(kernelId, "_ParticleBuffer", _particleBuffer); 158 | cs.SetVector("_LifeParams", new Vector4(1.0f/Mathf.Max(LifeMin, 0.0001f), 1.0f/Mathf.Max(LifeMax, 0.0001f), 0, 0)); 159 | cs.SetFloat ("_Velocity", Velocity); 160 | cs.SetFloat ("_Radius", SphereRadius); 161 | cs.SetFloat ("_SurfaceLayerNum", SurfaceLayerNum); 162 | cs.SetFloat ("_DeltaTime", Time.deltaTime); 163 | cs.SetFloat ("_Timer", Time.timeSinceLevelLoad); 164 | cs.SetFloat ("_Throttle", Throttle); 165 | 166 | cs.Dispatch(kernelId, NUM_THREAD, 1, 1); 167 | } 168 | 169 | /// 170 | /// パーティクルを描画 171 | /// 172 | void DrawParticles() 173 | { 174 | if (_particleRenderMat == null) 175 | { 176 | _particleRenderMat = new Material(RenderShader); 177 | _particleRenderMat.hideFlags = HideFlags.HideAndDontSave; 178 | } 179 | 180 | var invViewMatrix = RenderCamera.worldToCameraMatrix.inverse; 181 | 182 | _particleRenderMat.SetPass(0); 183 | _particleRenderMat.SetTexture("_MainTex", ParticleTex); 184 | _particleRenderMat.SetFloat ("_ParticleRad", ParticleSize); 185 | _particleRenderMat.SetColor ("_Color", ParticleColor); 186 | _particleRenderMat.SetMatrix ("_InvViewMatrix", invViewMatrix); 187 | _particleRenderMat.SetBuffer ("_ParticleBuffer", _particleBuffer); 188 | 189 | Graphics.DrawProcedural(MeshTopology.Points, NUM_PARTICLES); 190 | } 191 | 192 | #endregion 193 | } 194 | } -------------------------------------------------------------------------------- /LinesByDistance/Assets/ParticleOnSphere/ParticleOnSphere.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 526f4e62c5e5ca44684f13289be56a8a 3 | timeCreated: 1486180206 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /LinesByDistance/Assets/ParticleOnSphere/ParticleRender.shader: -------------------------------------------------------------------------------- 1 | Shader "Hidden/irishoak/ParticleOnSphere/ParticleRender" 2 | { 3 | Properties 4 | { 5 | _MainTex("Texture", 2D) = "white" {} 6 | _ParticleRad("ParticleRadius", Float) = 0.05 7 | _Color("Particle Color", Color) = (1,1,1,1) 8 | } 9 | 10 | CGINCLUDE 11 | #include "UnityCG.cginc" 12 | 13 | struct v2g 14 | { 15 | float3 pos : POSITION_SV; 16 | float4 color : COLOR; 17 | }; 18 | 19 | struct g2f 20 | { 21 | float4 pos : POSITION; 22 | float2 tex : TEXCOORD0; 23 | float4 color : COLOR; 24 | }; 25 | 26 | struct ParticleData 27 | { 28 | float3 velocity; 29 | float3 position; 30 | float age; 31 | float pad0; 32 | }; 33 | 34 | sampler2D _MainTex; 35 | float4 _MainTex_ST; 36 | 37 | StructuredBuffer _ParticleBuffer; 38 | 39 | float _ParticleRad; 40 | float4x4 _InvViewMatrix; 41 | fixed4 _Color; 42 | 43 | // -------------------------------------------------------------------- 44 | // Vertex Shader 45 | // -------------------------------------------------------------------- 46 | v2g vert(uint id : SV_VertexID) 47 | { 48 | v2g o = (v2g)0; 49 | o.pos = _ParticleBuffer[id].position; 50 | float age = _ParticleBuffer[id].age; 51 | o.color = saturate(min(1.0, 5.0 - abs(5.0 - age * 10))); 52 | return o; 53 | } 54 | 55 | static const float3 g_positions[4] = 56 | { 57 | float3(-1, 1, 0), 58 | float3( 1, 1, 0), 59 | float3(-1,-1, 0), 60 | float3( 1,-1, 0), 61 | }; 62 | 63 | static const float2 g_texcoords[4] = 64 | { 65 | float2(0, 0), 66 | float2(1, 0), 67 | float2(0, 1), 68 | float2(1, 1), 69 | }; 70 | 71 | // -------------------------------------------------------------------- 72 | // Geometry Shader 73 | // -------------------------------------------------------------------- 74 | [maxvertexcount(4)] 75 | void geom(point v2g In[1], inout TriangleStream SpriteStream) 76 | { 77 | g2f output = (g2f)0; 78 | [unroll] 79 | for (int i = 0; i < 4; i++) 80 | { 81 | float3 position = g_positions[i] * _ParticleRad; 82 | position = mul(_InvViewMatrix, position) + In[0].pos; 83 | output.pos = mul(UNITY_MATRIX_MVP, float4(position, 1.0)); 84 | 85 | output.color = In[0].color; 86 | output.tex = g_texcoords[i]; 87 | SpriteStream.Append(output); 88 | } 89 | SpriteStream.RestartStrip(); 90 | } 91 | 92 | // -------------------------------------------------------------------- 93 | // Fragment Shader 94 | // -------------------------------------------------------------------- 95 | fixed4 frag(g2f input) : SV_Target 96 | { 97 | return tex2D(_MainTex, input.tex) * input.color * _Color; 98 | } 99 | ENDCG 100 | 101 | SubShader 102 | { 103 | Tags{ "RenderType" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" } 104 | LOD 100 105 | 106 | ZWrite Off 107 | Blend One One 108 | 109 | Pass 110 | { 111 | CGPROGRAM 112 | #pragma target 5.0 113 | #pragma vertex vert 114 | #pragma geometry geom 115 | #pragma fragment frag 116 | ENDCG 117 | } 118 | } 119 | } -------------------------------------------------------------------------------- /LinesByDistance/Assets/ParticleOnSphere/ParticleRender.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: be894814c48674e4daef38b6bddd0640 3 | timeCreated: 1486182132 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /LinesByDistance/ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiroakioishi/UnityLinesByDistance/0d84db0f9578622ab8f6d5d935b7fd1cf5fb159e/LinesByDistance/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /LinesByDistance/ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiroakioishi/UnityLinesByDistance/0d84db0f9578622ab8f6d5d935b7fd1cf5fb159e/LinesByDistance/ProjectSettings/ClusterInputManager.asset -------------------------------------------------------------------------------- /LinesByDistance/ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiroakioishi/UnityLinesByDistance/0d84db0f9578622ab8f6d5d935b7fd1cf5fb159e/LinesByDistance/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /LinesByDistance/ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiroakioishi/UnityLinesByDistance/0d84db0f9578622ab8f6d5d935b7fd1cf5fb159e/LinesByDistance/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /LinesByDistance/ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiroakioishi/UnityLinesByDistance/0d84db0f9578622ab8f6d5d935b7fd1cf5fb159e/LinesByDistance/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /LinesByDistance/ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiroakioishi/UnityLinesByDistance/0d84db0f9578622ab8f6d5d935b7fd1cf5fb159e/LinesByDistance/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /LinesByDistance/ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiroakioishi/UnityLinesByDistance/0d84db0f9578622ab8f6d5d935b7fd1cf5fb159e/LinesByDistance/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /LinesByDistance/ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiroakioishi/UnityLinesByDistance/0d84db0f9578622ab8f6d5d935b7fd1cf5fb159e/LinesByDistance/ProjectSettings/NavMeshAreas.asset -------------------------------------------------------------------------------- /LinesByDistance/ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiroakioishi/UnityLinesByDistance/0d84db0f9578622ab8f6d5d935b7fd1cf5fb159e/LinesByDistance/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /LinesByDistance/ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiroakioishi/UnityLinesByDistance/0d84db0f9578622ab8f6d5d935b7fd1cf5fb159e/LinesByDistance/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /LinesByDistance/ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiroakioishi/UnityLinesByDistance/0d84db0f9578622ab8f6d5d935b7fd1cf5fb159e/LinesByDistance/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /LinesByDistance/ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 5.4.1f1 2 | m_StandardAssetsVersion: 0 3 | -------------------------------------------------------------------------------- /LinesByDistance/ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiroakioishi/UnityLinesByDistance/0d84db0f9578622ab8f6d5d935b7fd1cf5fb159e/LinesByDistance/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /LinesByDistance/ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiroakioishi/UnityLinesByDistance/0d84db0f9578622ab8f6d5d935b7fd1cf5fb159e/LinesByDistance/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /LinesByDistance/ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiroakioishi/UnityLinesByDistance/0d84db0f9578622ab8f6d5d935b7fd1cf5fb159e/LinesByDistance/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /LinesByDistance/ProjectSettings/UnityAdsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiroakioishi/UnityLinesByDistance/0d84db0f9578622ab8f6d5d935b7fd1cf5fb159e/LinesByDistance/ProjectSettings/UnityAdsSettings.asset -------------------------------------------------------------------------------- /LinesByDistance/ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiroakioishi/UnityLinesByDistance/0d84db0f9578622ab8f6d5d935b7fd1cf5fb159e/LinesByDistance/ProjectSettings/UnityConnectSettings.asset -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UnityLinesByDistance 2 | 3 | ## Description 4 | 頂点同士の距離によってラインを結ぶもののサンプルコード 5 | 6 | ComputeShader内で頂点同士の距離を計算し, AppendStructuredBufferにラインのデータをAppend, そのデータバッファをもとにGeometryShaderで頂点同士を結んでラインを描画しています. 生成されるラインの総数を制限する目的で, 総和計算にCounterBufferを使用していますが, 知識が足らず適切な実装とは言えないため, ご使用は自己責任でお願いします. 7 | 8 | ![image](https://github.com/hiroakioishi/UnityLinesByDistance/blob/master/img.jpg) 9 | 10 | ## Demo 11 | https://youtu.be/4tf1jCZ_ouE 12 | 13 | 14 | ## Requirement 15 | ComputeShader, GeometryShaderを使用しているため、DirectX11が動作する環境が必要です 16 | -------------------------------------------------------------------------------- /img.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiroakioishi/UnityLinesByDistance/0d84db0f9578622ab8f6d5d935b7fd1cf5fb159e/img.jpg --------------------------------------------------------------------------------