├── .gitignore ├── Assets ├── MeshVertexTexture.meta ├── MeshVertexTexture │ ├── Editor.meta │ ├── Editor │ │ ├── MeshVertexTextureCreator.cs │ │ ├── MeshVertexTextureCreator.cs.meta │ │ ├── MeshVertexTextureCreatorWindow.cs │ │ └── MeshVertexTextureCreatorWindow.cs.meta │ ├── Sample.meta │ ├── Sample │ │ ├── GPUParticle.meta │ │ ├── GPUParticle │ │ │ ├── Scripts.meta │ │ │ ├── Scripts │ │ │ │ ├── GPUParticle.cs │ │ │ │ └── GPUParticle.cs.meta │ │ │ ├── Shaders.meta │ │ │ └── Shaders │ │ │ │ ├── GPUParticle.compute │ │ │ │ ├── GPUParticle.compute.meta │ │ │ │ ├── GPUParticleData.cginc │ │ │ │ ├── GPUParticleData.cginc.meta │ │ │ │ ├── GPUParticleRender.shader │ │ │ │ └── GPUParticleRender.shader.meta │ │ ├── Materials.meta │ │ ├── Materials │ │ │ ├── MeshVertexTextureParticleSample.mat │ │ │ └── MeshVertexTextureParticleSample.mat.meta │ │ ├── Models.meta │ │ ├── Models │ │ │ ├── IcoSphere4.asset │ │ │ └── IcoSphere4.asset.meta │ │ ├── Scenes.meta │ │ ├── Scenes │ │ │ ├── MeshVertexTextureParticleSample.unity │ │ │ └── MeshVertexTextureParticleSample.unity.meta │ │ ├── Scripts.meta │ │ ├── Scripts │ │ │ ├── RotateCamera.cs │ │ │ └── RotateCamera.cs.meta │ │ ├── Textures.meta │ │ └── Textures │ │ │ ├── particle.png │ │ │ └── particle.png.meta │ ├── Scripts.meta │ ├── Scripts │ │ ├── MeshVertexTextureUtil.cs │ │ └── MeshVertexTextureUtil.cs.meta │ ├── Shaders.meta │ └── Shaders │ │ ├── MeshVertexTexture.cginc │ │ └── MeshVertexTexture.cginc.meta ├── MeshVertexTextures.meta └── MeshVertexTextures │ ├── Capsule.png │ ├── Capsule.png.meta │ ├── Cube.png │ ├── Cube.png.meta │ ├── IcoSphere4.png │ ├── IcoSphere4.png.meta │ ├── Sphere.png │ └── Sphere.png.meta ├── LICENSE ├── 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 └── UnityConnectSettings.asset ├── README.md └── ReadMeData ├── IcoSphereMesh.PNG ├── IcoSphereTexture.png ├── VertexTextureParticle.gif └── Window.png /.gitignore: -------------------------------------------------------------------------------- 1 | /[Ll]ibrary/ 2 | /[Tt]emp/ 3 | /[Oo]bj/ 4 | /[Bb]uild/ 5 | /[Bb]uilds/ 6 | /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 | -------------------------------------------------------------------------------- /Assets/MeshVertexTexture.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 335503098876cea4285d677b346c91c3 3 | folderAsset: yes 4 | timeCreated: 1489850214 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a46247bb329950a48b31a82a598fde4a 3 | folderAsset: yes 4 | timeCreated: 1489850982 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Editor/MeshVertexTextureCreator.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEditor; 5 | using System.IO; 6 | using System.Runtime.InteropServices; 7 | 8 | 9 | public static class MeshVertexTextureCreator { 10 | 11 | const int texWidthMax = 8192; 12 | const int texHeightMax = 8192; 13 | 14 | static string directoryName = "MeshVertexTextures"; 15 | 16 | public static void Create(Mesh mesh) 17 | { 18 | 19 | Vector3[] vertices = mesh.vertices; 20 | int[] indices = mesh.GetIndices(0); 21 | List vertexList = new List(); 22 | Bounds bounds = mesh.bounds; 23 | Vector3 boundsMax = bounds.max; 24 | Vector3 boundsCenter = bounds.center; 25 | 26 | Debug.Log("Bounds max " + bounds.max + " extents " + bounds.extents + " center " + bounds.center); 27 | 28 | // Index順にVertex格納(正規化) 29 | for (int i = 0; i < indices.Length; i++) 30 | { 31 | int idx = indices[i]; 32 | Vector3 v = vertices[idx]; 33 | 34 | v.x = (v.x / boundsMax.x) * 0.5f + 0.5f; 35 | v.y = (v.y / boundsMax.y) * 0.5f + 0.5f; 36 | v.z = (v.z / boundsMax.z) * 0.5f + 0.5f; 37 | 38 | vertexList.Add(v); 39 | } 40 | 41 | int texWidthCount = vertexList.Count; 42 | int texHeight = 4; // 1行目はBoundsなどの定義データ部、2行目から頂点データ部 43 | int positionLines = 1; 44 | 45 | // 最低8ピクセル必要らしい 46 | if (texWidthCount < 8) 47 | { 48 | texWidthCount = 8; 49 | } 50 | 51 | if (texWidthCount > texWidthMax) 52 | { 53 | // 8K以上は折り返す 54 | int remain = texWidthCount; 55 | while (positionLines < texHeightMax) 56 | { 57 | positionLines++; 58 | remain -= texWidthMax-1; 59 | if (remain < texWidthMax) 60 | break; 61 | } 62 | texWidthCount = texWidthMax; 63 | } 64 | 65 | texHeight = RoundUpPowerOf2(Mathf.Max(positionLines, texHeight)); 66 | 67 | if (texHeight >= texHeightMax) 68 | { 69 | Debug.LogError("Texture Maximum Size Over 8K"); 70 | return; 71 | } 72 | 73 | int texWidth = RoundUpPowerOf2(texWidthCount); 74 | 75 | Debug.Log("vertexList " + vertexList.Count + " texWidth " + texWidth); 76 | Debug.Log("texWidth " + texWidth + " texHeight " + texHeight + " positionLines " + positionLines); 77 | 78 | // テクスチャ作成 79 | Texture2D tex = new Texture2D(texWidth, texHeight, TextureFormat.RGBA32, false); 80 | 81 | Color vertexCount = MeshVertexTextureUtil.GetIntToColor(vertexList.Count); 82 | 83 | // メッシュの情報をColorに変換 84 | Color maxX = MeshVertexTextureUtil.GetFloatToColor(boundsMax.x); 85 | Color maxY = MeshVertexTextureUtil.GetFloatToColor(boundsMax.y); 86 | Color maxZ = MeshVertexTextureUtil.GetFloatToColor(boundsMax.z); 87 | 88 | Color centerX = MeshVertexTextureUtil.GetFloatToColor(boundsCenter.x); 89 | Color centerY = MeshVertexTextureUtil.GetFloatToColor(boundsCenter.y); 90 | Color centerZ = MeshVertexTextureUtil.GetFloatToColor(boundsCenter.z); 91 | 92 | int meshTopologyNum = MeshVertexTextureUtil.GetMeshTopologyNum(mesh); 93 | Color meshTopology = MeshVertexTextureUtil.GetIntToColor(meshTopologyNum); 94 | 95 | Debug.Log("vertexCount: " + vertexList.Count + " " + vertexCount + " MeshTopologyNum " + meshTopologyNum); 96 | Debug.Log("Max X: " + boundsMax.x + " : " + maxX + " Y: " + boundsMax.y + " : " + maxY + " Z: " + boundsMax.z + " : " + maxZ); 97 | Debug.Log("Center X: " + boundsCenter.x + " : " + centerX + " Y: " + boundsCenter.y + " : " + centerY + " Z: " + boundsCenter.z + " : " + centerZ); 98 | 99 | // テクスチャに書き込む 100 | int index = 0; 101 | 102 | // [0] VertexCount 103 | tex.SetPixel(index++, 0, vertexCount); 104 | 105 | // [1..3] Bounds.Max(x,y,z) 106 | tex.SetPixel(index++, 0, maxX); 107 | tex.SetPixel(index++, 0, maxY); 108 | tex.SetPixel(index++, 0, maxZ); 109 | 110 | // [4..6] Bounds.Center(x,y,z) 111 | tex.SetPixel(index++, 0, centerX); 112 | tex.SetPixel(index++, 0, centerX); 113 | tex.SetPixel(index++, 0, centerX); 114 | 115 | // [7] meshTopologyNum 116 | tex.SetPixel(index++, 0, meshTopology); 117 | 118 | for (int y = 0; y < positionLines; y++) 119 | { 120 | for(int x = 0; x < texWidth; x++) 121 | { 122 | int idx = y * texWidth + x; 123 | if (idx >= vertexList.Count) 124 | break; 125 | Color pos = MeshVertexTextureUtil.GetNormalizedVector3ToColor(vertexList[idx]); 126 | //Debug.Log("[" + x + "," + y + "] " + idx + " pos " + vertexList[idx] + " : " + pos); 127 | 128 | tex.SetPixel(x, y + 1, pos); 129 | } 130 | } 131 | tex.Apply(); 132 | 133 | // 保存 134 | string path = Application.dataPath; 135 | path += "/" + directoryName; 136 | if (!File.Exists(path)) 137 | { 138 | Directory.CreateDirectory(path); 139 | } 140 | 141 | path += "/" + mesh.name + ".png"; 142 | string relativePath = "Assets/" + directoryName + "/" + mesh.name + ".png"; 143 | 144 | byte[] bytes = tex.EncodeToPNG(); 145 | File.WriteAllBytes(path, bytes); 146 | AssetDatabase.ImportAsset(relativePath); 147 | Object.DestroyImmediate(tex); 148 | 149 | TextureImporter texImporter = AssetImporter.GetAtPath(relativePath) as TextureImporter; 150 | 151 | if(texImporter != null) 152 | { 153 | texImporter.wrapMode = TextureWrapMode.Clamp; 154 | texImporter.filterMode = FilterMode.Point; 155 | texImporter.anisoLevel = 0; 156 | texImporter.mipmapEnabled = false; 157 | texImporter.textureCompression = TextureImporterCompression.Uncompressed; 158 | texImporter.maxTextureSize = Mathf.Max(texWidth, texHeight); 159 | texImporter.isReadable = true; 160 | texImporter.SaveAndReimport(); 161 | } 162 | 163 | Debug.Log("Create Mesh Vertex Texture " + path); 164 | } 165 | 166 | /// 167 | /// 指定数X以上で最も近い2の乗数を返す 168 | /// 169 | /// 170 | /// 171 | static int RoundUpPowerOf2(int x) 172 | { 173 | x--; 174 | x |= x >> 1; 175 | x |= x >> 2; 176 | x |= x >> 4; 177 | x |= x >> 8; 178 | x |= x >> 16; 179 | 180 | return (x + 1); 181 | } 182 | } 183 | -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Editor/MeshVertexTextureCreator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9676232131fbb7c4face57aa5cefad5b 3 | timeCreated: 1489851062 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Editor/MeshVertexTextureCreatorWindow.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | 4 | public class MeshVertexTextureCreatorWindow : ScriptableWizard { 5 | 6 | public Mesh mesh; 7 | 8 | [MenuItem("Window/MeshVertexTexture Creator")] 9 | static void Open() 10 | { 11 | DisplayWizard("Create MeshVertexTexture"); 12 | } 13 | 14 | private void OnWizardCreate() 15 | { 16 | // todo: Meshの頂点座標をテクスチャに書き込む 17 | if (mesh != null) 18 | { 19 | MeshVertexTextureCreator.Create(mesh); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Editor/MeshVertexTextureCreatorWindow.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 076be341325189740ae0e4ada8b59a2a 3 | timeCreated: 1489850238 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Sample.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4bd363508b08a834d9f5f25a7c9b1d88 3 | folderAsset: yes 4 | timeCreated: 1489863265 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Sample/GPUParticle.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c84190378408ee24d976068831f2c9ff 3 | folderAsset: yes 4 | timeCreated: 1489860789 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Sample/GPUParticle/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2264510a2d8b7a14db5b176738941baa 3 | folderAsset: yes 4 | timeCreated: 1489936535 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Sample/GPUParticle/Scripts/GPUParticle.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using System.Runtime.InteropServices; 5 | 6 | struct ParticleData 7 | { 8 | public Vector3 position; 9 | public Vector3 orgPosition; 10 | public float vertexIndex; // 参照する頂点の番号 11 | public Color color; 12 | 13 | public ParticleData(Vector3 pos, Vector3 org, float vidx, Color col) 14 | { 15 | position = pos; 16 | orgPosition = org; 17 | vertexIndex = vidx; 18 | color = col; 19 | } 20 | } 21 | 22 | public class GPUParticle : MonoBehaviour { 23 | #region define 24 | const int THREAD_GROUP_X = 8; 25 | #endregion 26 | 27 | #region public 28 | public Material material; 29 | public ComputeShader cs; 30 | public Texture2D vertexTex; 31 | 32 | public int particleNum = 10000; 33 | public float vertexSpeed = 10f; 34 | public float vertexScale = 1; 35 | public float particleScale = 0.05f; 36 | 37 | [Range(0, 1)] 38 | public float positionRatio = 0; 39 | #endregion 40 | 41 | #region private 42 | ComputeBuffer particleBuffer; 43 | //Texture2D vertexTex; 44 | int vertexNum; 45 | Vector3 meshSize; 46 | Vector3 meshCenter; 47 | int meshTopologyNum; 48 | Vector4 texelSize; 49 | #endregion 50 | 51 | void InitializeParticle() 52 | { 53 | //vertexTex = material.GetTexture("_VertexTex") as Texture2D; 54 | material.SetTexture("_VertexTex", vertexTex); 55 | particleNum = Mathf.CeilToInt((float)particleNum / THREAD_GROUP_X) * THREAD_GROUP_X; 56 | particleBuffer = new ComputeBuffer(particleNum, Marshal.SizeOf(typeof(ParticleData))); 57 | 58 | vertexNum = MeshVertexTextureUtil.GetVertexNum(vertexTex); 59 | meshSize = MeshVertexTextureUtil.GetMeshSize(vertexTex); 60 | meshCenter = MeshVertexTextureUtil.GetMeshCenter(vertexTex); 61 | meshTopologyNum = MeshVertexTextureUtil.GetMeshTopologyNum(vertexTex); 62 | 63 | texelSize.x = 1f / vertexTex.width; 64 | texelSize.y = 1f / vertexTex.height; 65 | texelSize.z = vertexTex.width; 66 | texelSize.w = vertexTex.height; 67 | 68 | Debug.Log("Vertex Num " + vertexNum + " meshSize " + meshSize + " meshCenter " + meshCenter + " meshTopologyNum " + meshTopologyNum); 69 | ParticleData[] particles = new ParticleData[particleNum]; 70 | float indexStep = (float)vertexNum / particleNum; 71 | for (int i = 0; i < particleNum; i++) 72 | { 73 | particles[i] = new ParticleData(Vector3.zero, Random.insideUnitSphere * 5, indexStep * i, Color.HSVToRGB((float)i / particleNum, 0.75f, 1)); 74 | //particles[i] = new ParticleData(Random.onUnitSphere * 100f, indexStep * i, Color.red); 75 | } 76 | 77 | particleBuffer.SetData(particles); 78 | } 79 | 80 | //int GetColorToInt(Color col) 81 | //{ 82 | // const int xx = 255; 83 | // const int yy = 256; 84 | // int a = Mathf.CeilToInt(col.a * xx); 85 | // int b = Mathf.CeilToInt(col.b * xx) * yy; 86 | // int g = Mathf.CeilToInt(col.g * xx) * yy * yy; 87 | // int r = Mathf.CeilToInt(col.r * xx) * yy * yy * yy; 88 | 89 | // return a + b + g + r; 90 | //} 91 | 92 | //UnionFloatToRGBA frgba; 93 | //float GetColorToFloat(Color col) 94 | //{ 95 | // int bai = 255; 96 | // byte a = (byte)Mathf.CeilToInt(col.a * bai); 97 | // byte b = (byte)Mathf.CeilToInt(col.b * bai); 98 | // byte g = (byte)Mathf.CeilToInt(col.g * bai); 99 | // byte r = (byte)Mathf.CeilToInt(col.r * bai); 100 | // //int xx = x1 + x2 + x3 + x4; 101 | // frgba.a = a; 102 | // frgba.b = b; 103 | // frgba.g = g; 104 | // frgba.r = r; 105 | // float f = frgba.f; 106 | // //Debug.Log("Color " + col + " a " + r + " b " + b + " g " + g + " r " + r); 107 | // return f; 108 | //} 109 | 110 | //int GetVertexNum(Texture2D vertexTex) 111 | //{ 112 | // Color col = vertexTex.GetPixel(0, 0); 113 | // return GetColorToInt(col); 114 | //} 115 | 116 | //Vector3 GetMeshSize(Texture2D vertexTex) 117 | //{ 118 | // float x = GetColorToFloat(vertexTex.GetPixel(1, 0)); 119 | // float y = GetColorToFloat(vertexTex.GetPixel(2, 0)); 120 | // float z = GetColorToFloat(vertexTex.GetPixel(3, 0)); 121 | 122 | // return new Vector3(x, y, z); 123 | //} 124 | 125 | //Vector3 GetMeshCenter(Texture2D vertexTex) 126 | //{ 127 | // float x = GetColorToFloat(vertexTex.GetPixel(4, 0)); 128 | // float y = GetColorToFloat(vertexTex.GetPixel(5, 0)); 129 | // float z = GetColorToFloat(vertexTex.GetPixel(6, 0)); 130 | 131 | // return new Vector3(x, y, z); 132 | //} 133 | 134 | //int GetMeshTopologyNum(Texture2D vertexTex) 135 | //{ 136 | // Color col = vertexTex.GetPixel(7, 0); 137 | // return GetColorToInt(col); 138 | //} 139 | 140 | void UpdateParticle() 141 | { 142 | int kernel = cs.FindKernel("CSMain"); 143 | cs.SetFloat("_DT", Time.deltaTime); 144 | cs.SetFloat("_VertexSpeed", vertexSpeed); 145 | cs.SetInt("_VertexCount", vertexNum); 146 | cs.SetVector("_MeshSize", meshSize * vertexScale); 147 | cs.SetVector("_MeshCenter", meshCenter); 148 | cs.SetInt("_MeshTopologyNum", meshTopologyNum); 149 | cs.SetVector("_VertexTex_TexelSize", texelSize); 150 | cs.SetTexture(kernel, "_VertexTex", vertexTex); 151 | cs.SetBuffer(kernel, "_ParticleBuffer", particleBuffer); 152 | 153 | cs.Dispatch(kernel, particleNum / THREAD_GROUP_X, 1, 1); 154 | } 155 | 156 | // Use this for initialization 157 | void Start () { 158 | InitializeParticle(); 159 | } 160 | 161 | // Update is called once per frame 162 | void Update () { 163 | UpdateParticle(); 164 | } 165 | 166 | void OnRenderObject() 167 | { 168 | 169 | //material.SetTexture("_MainTex", bulletsTexture); 170 | material.SetBuffer("_ParticleBuffer", particleBuffer); 171 | material.SetInt("_VertexCount", vertexNum); 172 | material.SetVector("_MeshSize", meshSize * vertexScale); 173 | material.SetVector("_MeshCenter", meshCenter); 174 | material.SetInt("_MeshTopologyNum", meshTopologyNum); 175 | material.SetFloat("_ParticleScale", particleScale); 176 | material.SetFloat("_PositionRatio", positionRatio); 177 | material.SetPass(0); 178 | 179 | Graphics.DrawProcedural(MeshTopology.Points, particleNum); 180 | } 181 | 182 | private void OnDestroy() 183 | { 184 | particleBuffer.Release(); 185 | particleBuffer = null; 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Sample/GPUParticle/Scripts/GPUParticle.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f2595e54fcac7bc46944021089289a9a 3 | timeCreated: 1489860806 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Sample/GPUParticle/Shaders.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e0e219fe6e8a9714680e6646b9dfd9ab 3 | folderAsset: yes 4 | timeCreated: 1489936519 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Sample/GPUParticle/Shaders/GPUParticle.compute: -------------------------------------------------------------------------------- 1 | // Each #kernel tells which function to compile; you can have many kernels 2 | #pragma kernel CSMain 3 | 4 | #include "Assets/MeshVertexTexture/Shaders/MeshVertexTexture.cginc" 5 | #include "GPUParticleData.cginc" 6 | 7 | float _DT; 8 | float _VertexSpeed; 9 | //int _VertexCount; 10 | RWStructuredBuffer _ParticleBuffer; 11 | 12 | [numthreads(8,1,1)] 13 | void CSMain (uint3 id : SV_DispatchThreadID) 14 | { 15 | uint idx = id.x; 16 | _ParticleBuffer[idx].vertexIndex = fmod(_ParticleBuffer[idx].vertexIndex + _DT * _VertexSpeed, _VertexCount); 17 | //_ParticleBuffer[id.xy] = float4(id.x & id.y, (id.x & 15)/15.0, (id.y & 15)/15.0, 0.0); 18 | 19 | //float vidx = CheckVertexIndex(_ParticleBuffer[idx].vertexIndex); 20 | //float3 pos = GetVertexPosition(vidx); 21 | 22 | // 頂点テクスチャーから頂点座標を取り出す 23 | float vidx = CheckVertexIndex(_ParticleBuffer[idx].vertexIndex); 24 | float vidx2 = vidx + 1; // 次の座標 25 | 26 | float3 pos = GetVertexPosition(vidx); 27 | float3 pos2 = GetVertexPosition(vidx2); 28 | 29 | //pos = lerp(pos, pos2, frac(vidx)); 30 | 31 | //_ParticleBuffer[idx].position = _MeshCenter + (pos - 0.5) * 2.0 * _MeshSize; 32 | _ParticleBuffer[idx].position = lerp(pos, pos2, frac(vidx)); 33 | } 34 | -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Sample/GPUParticle/Shaders/GPUParticle.compute.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0c94357e1bbbf40459e53ec824e69057 3 | timeCreated: 1489862723 4 | licenseType: Free 5 | ComputeShaderImporter: 6 | currentAPIMask: 4 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Sample/GPUParticle/Shaders/GPUParticleData.cginc: -------------------------------------------------------------------------------- 1 | struct ParticleData 2 | { 3 | float3 position; 4 | float3 orgPosition; // 元の位置 5 | float vertexIndex; // 参照する頂点の番号 6 | float4 color; 7 | }; -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Sample/GPUParticle/Shaders/GPUParticleData.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b1453e70732469b4b8e57c65cf1faa65 3 | timeCreated: 1489930947 4 | licenseType: Free 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Sample/GPUParticle/Shaders/GPUParticleRender.shader: -------------------------------------------------------------------------------- 1 | Shader "Custom/GPUParticleRender" { 2 | Properties 3 | { 4 | _MainTex("Texture", 2D) = "white" {} 5 | } 6 | SubShader{ 7 | ZWrite Off 8 | Cull Off 9 | Blend SrcAlpha One 10 | 11 | Pass{ 12 | CGPROGRAM 13 | 14 | #pragma target 5.0 15 | 16 | #pragma vertex vert 17 | #pragma geometry geom 18 | #pragma fragment frag 19 | 20 | #include "UnityCG.cginc" 21 | #include "Assets/MeshVertexTexture/Shaders/MeshVertexTexture.cginc" 22 | #include "GPUParticleData.cginc" 23 | 24 | sampler2D _MainTex; 25 | 26 | float _ParticleScale; 27 | float _PositionRatio; 28 | 29 | StructuredBuffer _ParticleBuffer; 30 | 31 | struct VSOut { 32 | float4 pos : SV_POSITION; 33 | float2 tex : TEXCOORD0; 34 | float4 col : COLOR; 35 | }; 36 | 37 | VSOut vert(uint id : SV_VertexID) 38 | { 39 | VSOut output; 40 | output.pos = float4(lerp(_ParticleBuffer[id].orgPosition, _ParticleBuffer[id].position, _PositionRatio), 1); 41 | output.tex = float2(0, 0); 42 | output.col = _ParticleBuffer[id].color; 43 | 44 | return output; 45 | } 46 | 47 | [maxvertexcount(4)] 48 | void geom(point VSOut input[1], inout TriangleStream outStream) 49 | { 50 | VSOut output; 51 | 52 | float4 pos = input[0].pos; 53 | float4 col = input[0].col; 54 | 55 | float4x4 billboardMatrix = UNITY_MATRIX_V; 56 | billboardMatrix._m03 = 57 | billboardMatrix._m13 = 58 | billboardMatrix._m23 = 59 | billboardMatrix._m33 = 0; 60 | 61 | for (int x = 0; x < 2; x++) 62 | { 63 | for (int y = 0; y < 2; y++) 64 | { 65 | float2 tex = float2(x, y); 66 | output.tex = tex; 67 | 68 | output.pos = pos + mul(float4((tex * 2 - float2(1, 1)) * _ParticleScale, 0, 1), billboardMatrix); 69 | output.pos = mul(UNITY_MATRIX_VP, output.pos); 70 | 71 | output.col = col; 72 | 73 | outStream.Append(output); 74 | } 75 | } 76 | 77 | outStream.RestartStrip(); 78 | } 79 | 80 | fixed4 frag(VSOut i) : COLOR 81 | { 82 | return tex2D(_MainTex, i.tex) * i.col; 83 | } 84 | 85 | ENDCG 86 | } 87 | } 88 | } -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Sample/GPUParticle/Shaders/GPUParticleRender.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5bf311d6f4d05814396463ba98d4ae55 3 | timeCreated: 1489862776 4 | licenseType: Free 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Sample/Materials.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4661caad22840e14d934aeeee0a9567e 3 | folderAsset: yes 4 | timeCreated: 1489863165 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Sample/Materials/MeshVertexTextureParticleSample.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaiware007/UnityMeshVertexTexture/3749b17de04c22017960a896c72864c75de3d213/Assets/MeshVertexTexture/Sample/Materials/MeshVertexTextureParticleSample.mat -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Sample/Materials/MeshVertexTextureParticleSample.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 62095196ab75628498aa64891e9f511d 3 | timeCreated: 1489863186 4 | licenseType: Free 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Sample/Models.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 98321dda9288c244e9462300a39c6dd7 3 | folderAsset: yes 4 | timeCreated: 1489873381 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Sample/Models/IcoSphere4.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaiware007/UnityMeshVertexTexture/3749b17de04c22017960a896c72864c75de3d213/Assets/MeshVertexTexture/Sample/Models/IcoSphere4.asset -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Sample/Models/IcoSphere4.asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a839ad815eb747b4da9b73fce2e571dc 3 | timeCreated: 1489919464 4 | licenseType: Free 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Sample/Scenes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8c800d35524f08640a916224e34db061 3 | folderAsset: yes 4 | timeCreated: 1489863281 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Sample/Scenes/MeshVertexTextureParticleSample.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaiware007/UnityMeshVertexTexture/3749b17de04c22017960a896c72864c75de3d213/Assets/MeshVertexTexture/Sample/Scenes/MeshVertexTextureParticleSample.unity -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Sample/Scenes/MeshVertexTextureParticleSample.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6a709611fe5ecd24cb0b63aeeb1382ad 3 | timeCreated: 1489863305 4 | licenseType: Free 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Sample/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 65b724d6c9257a943b1a39a74f2b6587 3 | folderAsset: yes 4 | timeCreated: 1489934257 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Sample/Scripts/RotateCamera.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class RotateCamera : MonoBehaviour { 6 | 7 | public Vector3 center = Vector3.zero; 8 | public Vector3 axis = Vector3.up; 9 | public float speed = 1; 10 | 11 | //private float angle = 0; 12 | 13 | // Update is called once per frame 14 | void Update () { 15 | //angle += Time.deltaTime * speed; 16 | transform.RotateAround(center, axis, Time.deltaTime * speed); 17 | transform.LookAt(center); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Sample/Scripts/RotateCamera.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b1a6fcf31cbd71644b25a53e9c79c287 3 | timeCreated: 1489933501 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Sample/Textures.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 305e2745992fea94b82ec42ecbe21dfd 3 | folderAsset: yes 4 | timeCreated: 1489934276 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Sample/Textures/particle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaiware007/UnityMeshVertexTexture/3749b17de04c22017960a896c72864c75de3d213/Assets/MeshVertexTexture/Sample/Textures/particle.png -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Sample/Textures/particle.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 71ddd63a92666d04b9bc56f8180a5a9e 3 | timeCreated: 1489934246 4 | licenseType: Free 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 4 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 0 11 | sRGBTexture: 1 12 | linearTexture: 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: 6 25 | cubemapConvolution: 0 26 | seamlessCubemap: 0 27 | textureFormat: 1 28 | maxTextureSize: 2048 29 | textureSettings: 30 | filterMode: -1 31 | aniso: -1 32 | mipBias: -1 33 | wrapMode: 1 34 | nPOTScale: 0 35 | lightmap: 0 36 | compressionQuality: 50 37 | spriteMode: 1 38 | spriteExtrude: 1 39 | spriteMeshType: 1 40 | alignment: 0 41 | spritePivot: {x: 0.5, y: 0.5} 42 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 43 | spritePixelsToUnits: 100 44 | alphaUsage: 1 45 | alphaIsTransparency: 1 46 | spriteTessellationDetail: -1 47 | textureType: 0 48 | textureShape: 1 49 | maxTextureSizeSet: 0 50 | compressionQualitySet: 0 51 | textureFormatSet: 0 52 | platformSettings: 53 | - buildTarget: DefaultTexturePlatform 54 | maxTextureSize: 2048 55 | textureFormat: -1 56 | textureCompression: 1 57 | compressionQuality: 50 58 | crunchedCompression: 0 59 | allowsAlphaSplitting: 0 60 | overridden: 0 61 | - buildTarget: Standalone 62 | maxTextureSize: 64 63 | textureFormat: 4 64 | textureCompression: 1 65 | compressionQuality: 50 66 | crunchedCompression: 0 67 | allowsAlphaSplitting: 0 68 | overridden: 1 69 | spriteSheet: 70 | serializedVersion: 2 71 | sprites: [] 72 | outline: [] 73 | spritePackingTag: 74 | userData: 75 | assetBundleName: 76 | assetBundleVariant: 77 | -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 36cdc87756b29ce4c8a1ee1f6d008e82 3 | folderAsset: yes 4 | timeCreated: 1489935743 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Scripts/MeshVertexTextureUtil.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using System.Runtime.InteropServices; 5 | 6 | 7 | /// 8 | /// float型/int型をRGBAに変換するための共用体もどき 9 | /// 10 | [StructLayout(LayoutKind.Explicit)] 11 | public struct UnionFloatToRGBA 12 | { 13 | [FieldOffset(0)] 14 | public float f; 15 | 16 | [FieldOffset(0)] 17 | public int i; 18 | 19 | [FieldOffset(0)] 20 | public byte a; 21 | 22 | [FieldOffset(1)] 23 | public byte b; 24 | 25 | [FieldOffset(2)] 26 | public byte g; 27 | 28 | [FieldOffset(3)] 29 | public byte r; 30 | } 31 | 32 | public static class MeshVertexTextureUtil { 33 | 34 | #region decode_function 35 | /// 36 | /// Color To Int 37 | /// 38 | /// 39 | /// 40 | public static int GetColorToInt(Color col) 41 | { 42 | const int xx = 255; 43 | const int yy = 256; 44 | int a = Mathf.CeilToInt(col.a * xx); 45 | int b = Mathf.CeilToInt(col.b * xx) * yy; 46 | int g = Mathf.CeilToInt(col.g * xx) * yy * yy; 47 | int r = Mathf.CeilToInt(col.r * xx) * yy * yy * yy; 48 | 49 | return a + b + g + r; 50 | } 51 | 52 | static UnionFloatToRGBA frgba; 53 | 54 | /// 55 | /// Colot To Float 56 | /// 57 | /// 58 | /// 59 | public static float GetColorToFloat(Color col) 60 | { 61 | int bai = 255; 62 | byte a = (byte)Mathf.CeilToInt(col.a * bai); 63 | byte b = (byte)Mathf.CeilToInt(col.b * bai); 64 | byte g = (byte)Mathf.CeilToInt(col.g * bai); 65 | byte r = (byte)Mathf.CeilToInt(col.r * bai); 66 | 67 | frgba.a = a; 68 | frgba.b = b; 69 | frgba.g = g; 70 | frgba.r = r; 71 | float f = frgba.f; 72 | 73 | return f; 74 | } 75 | 76 | public static int GetMeshTopologyNum(Mesh mesh) 77 | { 78 | MeshTopology topology = mesh.GetTopology(0); 79 | 80 | int num = 0; 81 | switch (topology) 82 | { 83 | case MeshTopology.Points: 84 | num = 1; 85 | break; 86 | case MeshTopology.Lines: 87 | case MeshTopology.LineStrip: 88 | num = 2; 89 | break; 90 | case MeshTopology.Triangles: 91 | num = 3; 92 | break; 93 | case MeshTopology.Quads: 94 | num = 4; 95 | break; 96 | } 97 | return num; 98 | } 99 | #endregion 100 | 101 | #region encode_function 102 | /// 103 | /// Float to Color 104 | /// 105 | /// 106 | /// 107 | public static Color GetFloatToColor(float f) 108 | { 109 | UnionFloatToRGBA data = new UnionFloatToRGBA(); 110 | data.f = f; 111 | //Debug.Log("f " + f + " r " + data.r + " g " + data.g + " b " + data.b + " a " + data.a); 112 | return new Color32(data.r, data.g, data.b, data.a); 113 | } 114 | 115 | /// 116 | /// Int to Color 117 | /// 118 | /// 119 | /// 120 | public static Color GetIntToColor(int i) 121 | { 122 | UnionFloatToRGBA data = new UnionFloatToRGBA(); 123 | data.i = i; 124 | //Debug.Log("i " + i + " r " + data.r + " g " + data.g + " b " + data.b + " a " + data.a); 125 | return new Color32(data.r, data.g, data.b, data.a); 126 | } 127 | 128 | /// 129 | /// 正規化済みVector3をRGBAに変換 130 | /// 131 | /// 132 | /// 133 | public static Color GetNormalizedVector3ToColor(Vector3 v) 134 | { 135 | return new Color(v.x, v.y, v.z, 1); 136 | } 137 | 138 | /// 139 | /// Get Vertex Num from MeshVertexTexture 140 | /// 141 | /// 142 | /// 143 | public static int GetVertexNum(Texture2D vertexTex) 144 | { 145 | Color col = vertexTex.GetPixel(0, 0); 146 | return GetColorToInt(col); 147 | } 148 | 149 | /// 150 | /// Get Mesh Size from MeshVertexTexture 151 | /// 152 | /// 153 | /// 154 | public static Vector3 GetMeshSize(Texture2D vertexTex) 155 | { 156 | float x = GetColorToFloat(vertexTex.GetPixel(1, 0)); 157 | float y = GetColorToFloat(vertexTex.GetPixel(2, 0)); 158 | float z = GetColorToFloat(vertexTex.GetPixel(3, 0)); 159 | 160 | return new Vector3(x, y, z); 161 | } 162 | 163 | /// 164 | /// Get Mesh Center Positin from MeshVertexTexture 165 | /// 166 | /// 167 | /// 168 | public static Vector3 GetMeshCenter(Texture2D vertexTex) 169 | { 170 | float x = GetColorToFloat(vertexTex.GetPixel(4, 0)); 171 | float y = GetColorToFloat(vertexTex.GetPixel(5, 0)); 172 | float z = GetColorToFloat(vertexTex.GetPixel(6, 0)); 173 | 174 | return new Vector3(x, y, z); 175 | } 176 | 177 | /// 178 | /// Get MeshTopologyNum from MeshVertexTexture 179 | /// 180 | /// 181 | /// 182 | public static int GetMeshTopologyNum(Texture2D vertexTex) 183 | { 184 | Color col = vertexTex.GetPixel(7, 0); 185 | return GetColorToInt(col); 186 | } 187 | #endregion 188 | } 189 | -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Scripts/MeshVertexTextureUtil.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e5299e39593ef9d4987caef3497af145 3 | timeCreated: 1489936012 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Shaders.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 40da3202ceada084e9573f4e38b31b9e 3 | folderAsset: yes 4 | timeCreated: 1489862694 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Shaders/MeshVertexTexture.cginc: -------------------------------------------------------------------------------- 1 | sampler2D _VertexTex; 2 | float4 _VertexTex_TexelSize; 3 | 4 | int _VertexCount; // 頂点数 5 | float3 _MeshSize; // メッシュのサイズ 6 | float3 _MeshCenter; // メッシュの中心座標 7 | int _MeshTopologyNum; 8 | 9 | // 頂点番号のはみ出しチェック 10 | float CheckVertexIndex(float idx) { 11 | idx = idx % _VertexCount; 12 | idx = (idx < 0) ? idx + _VertexCount : idx; // 始点はみ出しチェック 13 | idx = (idx % _MeshTopologyNum) >= (_MeshTopologyNum - 1) ? idx + 1 : idx; // MeshTopologyチェック 14 | idx = (idx > ((float)_VertexCount)) ? idx - _VertexCount : idx; // 終点はみ出しチェック 15 | return idx; 16 | } 17 | 18 | // 頂点番号からVertexTexture上のUV座標取得 19 | float2 GetVertexPositionUV(int idx) { 20 | float idxX = (idx) % (_VertexTex_TexelSize.z); 21 | float idxY = 1.0 + (int)(idx / _VertexTex_TexelSize.z); 22 | 23 | return float2(idxX, idxY) * _VertexTex_TexelSize.xy; 24 | } 25 | 26 | // 頂点番号から頂点座標取得 27 | float3 GetVertexPosition(int idx) { 28 | float2 uv = GetVertexPositionUV(idx); 29 | float3 pos = tex2Dlod(_VertexTex, float4(uv, 0, 0)).rgb; 30 | 31 | return _MeshCenter + (pos - 0.5) * 2.0 * _MeshSize; 32 | } -------------------------------------------------------------------------------- /Assets/MeshVertexTexture/Shaders/MeshVertexTexture.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ec61a0129c08de743af9c1c0617e47b9 3 | timeCreated: 1489930947 4 | licenseType: Free 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/MeshVertexTextures.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0ad7aa56bfc69404e91b79fc3dcd5feb 3 | folderAsset: yes 4 | timeCreated: 1489857067 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/MeshVertexTextures/Capsule.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaiware007/UnityMeshVertexTexture/3749b17de04c22017960a896c72864c75de3d213/Assets/MeshVertexTextures/Capsule.png -------------------------------------------------------------------------------- /Assets/MeshVertexTextures/Capsule.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b8a5154990a26a54eb92adc3a14b0866 3 | timeCreated: 1489930115 4 | licenseType: Free 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 4 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 0 11 | sRGBTexture: 1 12 | linearTexture: 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: 1 23 | grayScaleToAlpha: 0 24 | generateCubemap: 6 25 | cubemapConvolution: 0 26 | seamlessCubemap: 0 27 | textureFormat: 1 28 | maxTextureSize: 2048 29 | textureSettings: 30 | filterMode: 0 31 | aniso: 0 32 | mipBias: -1 33 | wrapMode: 1 34 | nPOTScale: 1 35 | lightmap: 0 36 | compressionQuality: 50 37 | spriteMode: 0 38 | spriteExtrude: 1 39 | spriteMeshType: 1 40 | alignment: 0 41 | spritePivot: {x: 0.5, y: 0.5} 42 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 43 | spritePixelsToUnits: 100 44 | alphaUsage: 1 45 | alphaIsTransparency: 0 46 | spriteTessellationDetail: -1 47 | textureType: 0 48 | textureShape: 1 49 | maxTextureSizeSet: 0 50 | compressionQualitySet: 0 51 | textureFormatSet: 0 52 | platformSettings: 53 | - buildTarget: DefaultTexturePlatform 54 | maxTextureSize: 4096 55 | textureFormat: -1 56 | textureCompression: 0 57 | compressionQuality: 50 58 | crunchedCompression: 0 59 | allowsAlphaSplitting: 0 60 | overridden: 0 61 | - buildTarget: Standalone 62 | maxTextureSize: 512 63 | textureFormat: -1 64 | textureCompression: 0 65 | compressionQuality: 50 66 | crunchedCompression: 0 67 | allowsAlphaSplitting: 0 68 | overridden: 0 69 | spriteSheet: 70 | serializedVersion: 2 71 | sprites: [] 72 | outline: [] 73 | spritePackingTag: 74 | userData: 75 | assetBundleName: 76 | assetBundleVariant: 77 | -------------------------------------------------------------------------------- /Assets/MeshVertexTextures/Cube.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaiware007/UnityMeshVertexTexture/3749b17de04c22017960a896c72864c75de3d213/Assets/MeshVertexTextures/Cube.png -------------------------------------------------------------------------------- /Assets/MeshVertexTextures/Cube.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 12b7ae1e749a92641a19c928299730d7 3 | timeCreated: 1489929626 4 | licenseType: Free 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 4 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 0 11 | sRGBTexture: 1 12 | linearTexture: 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: 1 23 | grayScaleToAlpha: 0 24 | generateCubemap: 6 25 | cubemapConvolution: 0 26 | seamlessCubemap: 0 27 | textureFormat: 1 28 | maxTextureSize: 2048 29 | textureSettings: 30 | filterMode: 0 31 | aniso: 0 32 | mipBias: -1 33 | wrapMode: 1 34 | nPOTScale: 1 35 | lightmap: 0 36 | compressionQuality: 50 37 | spriteMode: 0 38 | spriteExtrude: 1 39 | spriteMeshType: 1 40 | alignment: 0 41 | spritePivot: {x: 0.5, y: 0.5} 42 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 43 | spritePixelsToUnits: 100 44 | alphaUsage: 1 45 | alphaIsTransparency: 0 46 | spriteTessellationDetail: -1 47 | textureType: 0 48 | textureShape: 1 49 | maxTextureSizeSet: 0 50 | compressionQualitySet: 0 51 | textureFormatSet: 0 52 | platformSettings: 53 | - buildTarget: DefaultTexturePlatform 54 | maxTextureSize: 64 55 | textureFormat: -1 56 | textureCompression: 0 57 | compressionQuality: 50 58 | crunchedCompression: 0 59 | allowsAlphaSplitting: 0 60 | overridden: 0 61 | - buildTarget: Standalone 62 | maxTextureSize: 64 63 | textureFormat: -1 64 | textureCompression: 0 65 | compressionQuality: 50 66 | crunchedCompression: 0 67 | allowsAlphaSplitting: 0 68 | overridden: 0 69 | spriteSheet: 70 | serializedVersion: 2 71 | sprites: [] 72 | outline: [] 73 | spritePackingTag: 74 | userData: 75 | assetBundleName: 76 | assetBundleVariant: 77 | -------------------------------------------------------------------------------- /Assets/MeshVertexTextures/IcoSphere4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaiware007/UnityMeshVertexTexture/3749b17de04c22017960a896c72864c75de3d213/Assets/MeshVertexTextures/IcoSphere4.png -------------------------------------------------------------------------------- /Assets/MeshVertexTextures/IcoSphere4.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9ef172f158a11074295282e8f74c8864 3 | timeCreated: 1489930105 4 | licenseType: Free 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 4 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 0 11 | sRGBTexture: 1 12 | linearTexture: 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: 1 23 | grayScaleToAlpha: 0 24 | generateCubemap: 6 25 | cubemapConvolution: 0 26 | seamlessCubemap: 0 27 | textureFormat: 1 28 | maxTextureSize: 2048 29 | textureSettings: 30 | filterMode: 0 31 | aniso: 0 32 | mipBias: -1 33 | wrapMode: 1 34 | nPOTScale: 1 35 | lightmap: 0 36 | compressionQuality: 50 37 | spriteMode: 0 38 | spriteExtrude: 1 39 | spriteMeshType: 1 40 | alignment: 0 41 | spritePivot: {x: 0.5, y: 0.5} 42 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 43 | spritePixelsToUnits: 100 44 | alphaUsage: 1 45 | alphaIsTransparency: 0 46 | spriteTessellationDetail: -1 47 | textureType: 0 48 | textureShape: 1 49 | maxTextureSizeSet: 0 50 | compressionQualitySet: 0 51 | textureFormatSet: 0 52 | platformSettings: 53 | - buildTarget: DefaultTexturePlatform 54 | maxTextureSize: 512 55 | textureFormat: -1 56 | textureCompression: 0 57 | compressionQuality: 50 58 | crunchedCompression: 0 59 | allowsAlphaSplitting: 0 60 | overridden: 0 61 | spriteSheet: 62 | serializedVersion: 2 63 | sprites: [] 64 | outline: [] 65 | spritePackingTag: 66 | userData: 67 | assetBundleName: 68 | assetBundleVariant: 69 | -------------------------------------------------------------------------------- /Assets/MeshVertexTextures/Sphere.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaiware007/UnityMeshVertexTexture/3749b17de04c22017960a896c72864c75de3d213/Assets/MeshVertexTextures/Sphere.png -------------------------------------------------------------------------------- /Assets/MeshVertexTextures/Sphere.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9ca168ab0bc0b364aa557c6499e551af 3 | timeCreated: 1489930122 4 | licenseType: Free 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 4 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 0 11 | sRGBTexture: 1 12 | linearTexture: 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: 1 23 | grayScaleToAlpha: 0 24 | generateCubemap: 6 25 | cubemapConvolution: 0 26 | seamlessCubemap: 0 27 | textureFormat: 1 28 | maxTextureSize: 2048 29 | textureSettings: 30 | filterMode: 0 31 | aniso: 0 32 | mipBias: -1 33 | wrapMode: 1 34 | nPOTScale: 1 35 | lightmap: 0 36 | compressionQuality: 50 37 | spriteMode: 0 38 | spriteExtrude: 1 39 | spriteMeshType: 1 40 | alignment: 0 41 | spritePivot: {x: 0.5, y: 0.5} 42 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 43 | spritePixelsToUnits: 100 44 | alphaUsage: 1 45 | alphaIsTransparency: 0 46 | spriteTessellationDetail: -1 47 | textureType: 0 48 | textureShape: 1 49 | maxTextureSizeSet: 0 50 | compressionQualitySet: 0 51 | textureFormatSet: 0 52 | platformSettings: 53 | - buildTarget: DefaultTexturePlatform 54 | maxTextureSize: 4096 55 | textureFormat: -1 56 | textureCompression: 0 57 | compressionQuality: 50 58 | crunchedCompression: 0 59 | allowsAlphaSplitting: 0 60 | overridden: 0 61 | spriteSheet: 62 | serializedVersion: 2 63 | sprites: [] 64 | outline: [] 65 | spritePackingTag: 66 | userData: 67 | assetBundleName: 68 | assetBundleVariant: 69 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 kaiware007 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 | -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaiware007/UnityMeshVertexTexture/3749b17de04c22017960a896c72864c75de3d213/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaiware007/UnityMeshVertexTexture/3749b17de04c22017960a896c72864c75de3d213/ProjectSettings/ClusterInputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaiware007/UnityMeshVertexTexture/3749b17de04c22017960a896c72864c75de3d213/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaiware007/UnityMeshVertexTexture/3749b17de04c22017960a896c72864c75de3d213/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaiware007/UnityMeshVertexTexture/3749b17de04c22017960a896c72864c75de3d213/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaiware007/UnityMeshVertexTexture/3749b17de04c22017960a896c72864c75de3d213/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaiware007/UnityMeshVertexTexture/3749b17de04c22017960a896c72864c75de3d213/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaiware007/UnityMeshVertexTexture/3749b17de04c22017960a896c72864c75de3d213/ProjectSettings/NavMeshAreas.asset -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaiware007/UnityMeshVertexTexture/3749b17de04c22017960a896c72864c75de3d213/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaiware007/UnityMeshVertexTexture/3749b17de04c22017960a896c72864c75de3d213/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaiware007/UnityMeshVertexTexture/3749b17de04c22017960a896c72864c75de3d213/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 5.5.2f1 2 | -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaiware007/UnityMeshVertexTexture/3749b17de04c22017960a896c72864c75de3d213/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaiware007/UnityMeshVertexTexture/3749b17de04c22017960a896c72864c75de3d213/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaiware007/UnityMeshVertexTexture/3749b17de04c22017960a896c72864c75de3d213/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaiware007/UnityMeshVertexTexture/3749b17de04c22017960a896c72864c75de3d213/ProjectSettings/UnityConnectSettings.asset -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MeshVertexTexture 2 | 3 | ![VertexTextureParticle](ReadMeData/VertexTextureParticle.gif) 4 | 5 | Create Mesh's Vertex Texture. 6 | Writing Mesh vertex position data to Texture2D. 7 | Vertex / fragment shader or compute shader can reference vertex coordinates of the mesh. 8 | 9 | ![IcoSphereMesh](ReadMeData/IcoSphereMesh.PNG) 10 | **↓** 11 | ![IcoSphereTexture](ReadMeData/IcoSphereTexture.png) 12 | 13 | ## How to create 14 | 15 | 1. Menu [Window]->[MeshVertexTexture Creator] 16 | 2. Select Mesh 17 | ![MeshVertexTexture Creator window](ReadMeData/Window.png) 18 | 3. Click [Create] Button 19 | 4. Create VertexTexture in Assets/MeshVertexTextures/ 20 | 21 | ## How to use 22 | 23 | Please see Sample scene. 24 | Assets/MeshVertexTexture/Sample/Scenes/MeshVertexTextureParticleSample.unity 25 | -------------------------------------------------------------------------------- /ReadMeData/IcoSphereMesh.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaiware007/UnityMeshVertexTexture/3749b17de04c22017960a896c72864c75de3d213/ReadMeData/IcoSphereMesh.PNG -------------------------------------------------------------------------------- /ReadMeData/IcoSphereTexture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaiware007/UnityMeshVertexTexture/3749b17de04c22017960a896c72864c75de3d213/ReadMeData/IcoSphereTexture.png -------------------------------------------------------------------------------- /ReadMeData/VertexTextureParticle.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaiware007/UnityMeshVertexTexture/3749b17de04c22017960a896c72864c75de3d213/ReadMeData/VertexTextureParticle.gif -------------------------------------------------------------------------------- /ReadMeData/Window.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaiware007/UnityMeshVertexTexture/3749b17de04c22017960a896c72864c75de3d213/ReadMeData/Window.png --------------------------------------------------------------------------------