├── .gitignore ├── Assets ├── ComputeLatticeColors.meta ├── ComputeLatticeColors │ ├── ComputeLatticeColors.unity │ ├── ComputeLatticeColors.unity.meta │ ├── LatticeRenderInto3DCS.compute │ ├── LatticeRenderInto3DCS.compute.meta │ ├── LatticeRenderInto3DCS.cs │ ├── LatticeRenderInto3DCS.cs.meta │ ├── LatticeSample3DTex.mat │ ├── LatticeSample3DTex.mat.meta │ ├── LatticeSample3DTex.shader │ └── LatticeSample3DTex.shader.meta ├── ComputeParticles.meta ├── ComputeParticles │ ├── ComputeParticles.unity │ ├── ComputeParticles.unity.meta │ ├── ParticlesRenderInto3DCS.compute │ ├── ParticlesRenderInto3DCS.compute.meta │ ├── ParticlesRenderInto3DCS.cs │ ├── ParticlesRenderInto3DCS.cs.meta │ ├── ParticlesSample3DTex.mat │ ├── ParticlesSample3DTex.mat.meta │ ├── ParticlesSample3DTex.shader │ ├── ParticlesSample3DTex.shader.meta │ ├── ParticlesUpdateCS.compute │ └── ParticlesUpdateCS.compute.meta ├── ComputeShaders.meta ├── ComputeShaders │ ├── ParticleComputeShader.compute │ ├── ParticleComputeShader.compute.meta │ ├── ParticleController.cs │ ├── ParticleController.cs.meta │ ├── ParticleControllerShader.shader │ ├── ParticleControllerShader.shader.meta │ ├── RenderVolume.meta │ └── RenderVolume │ │ ├── _VolumeTextures.unity │ │ └── _VolumeTextures.unity.meta ├── Editor.meta ├── Editor │ ├── Create3DAssets.cs │ ├── Create3DAssets.cs.meta │ ├── Create3DTexture.cs │ ├── Create3DTexture.cs.meta │ ├── CreateLatticeMesh.cs │ ├── CreateLatticeMesh.cs.meta │ ├── CreateTexture.cs │ └── CreateTexture.cs.meta ├── MarchingCubesTest.meta ├── MarchingCubesTest │ ├── MarchingCubesTestScene.unity │ ├── MarchingCubesTestScene.unity.meta │ ├── PlayWithIsoLevels.cs │ └── PlayWithIsoLevels.cs.meta ├── Materials.meta ├── Materials │ ├── Particles.meta │ ├── Particles │ │ ├── GPUParticle.shader │ │ ├── GPUParticle.shader.meta │ │ ├── GPUParticleMaterial.mat │ │ └── GPUParticleMaterial.mat.meta │ ├── ReferenceMaterial.meta │ └── ReferenceMaterial │ │ ├── ExampleGeometryShader.shader │ │ ├── ExampleGeometryShader.shader.meta │ │ ├── MarchingCubes.meta │ │ ├── MarchingCubes │ │ ├── ExperimentalShader.shader │ │ ├── ExperimentalShader.shader.meta │ │ ├── MarchingCubesGPU.shader │ │ ├── MarchingCubesGPU.shader.meta │ │ ├── MarchingCubesGS.mat │ │ └── MarchingCubesGS.mat.meta │ │ ├── Reflection.meta │ │ └── Reflection │ │ ├── CGReflection.mat │ │ ├── CGReflection.mat.meta │ │ ├── CGReflectionShader.shader │ │ └── CGReflectionShader.shader.meta ├── Meshes.meta ├── Meshes │ ├── LatticeMesh.asset │ ├── LatticeMesh.asset.meta │ ├── LatticeMesh1x1x1.asset │ └── LatticeMesh1x1x1.asset.meta ├── Scenes.meta ├── Scenes │ ├── TestComputeShaders.unity │ └── TestComputeShaders.unity.meta ├── Scripts.meta ├── Scripts │ ├── Perlin.cs │ └── Perlin.cs.meta ├── Textures.meta ├── Textures │ ├── earth_texture2048x1024.png │ ├── earth_texture2048x1024.png.meta │ ├── edgeTableTexture.asset │ ├── edgeTableTexture.asset.meta │ ├── triTableTexture.asset │ └── triTableTexture.asset.meta ├── Textures3D.meta └── Textures3D │ ├── pyroclasticNoise.asset │ └── pyroclasticNoise.asset.meta ├── LICENSE ├── ProjectSettings ├── AudioManager.asset ├── DynamicsManager.asset ├── EditorBuildSettings.asset ├── EditorSettings.asset ├── InputManager.asset ├── NavMeshLayers.asset ├── NetworkManager.asset ├── ProjectSettings.asset ├── QualitySettings.asset ├── TagManager.asset └── TimeManager.asset ├── README.md └── UnityGPUMarchingCubes ├── .gitattributes └── .gitignore /.gitignore: -------------------------------------------------------------------------------- 1 | # Store this file at the root of your local repository. 2 | .DS_Store 3 | Library 4 | Temp 5 | Build 6 | Builds 7 | *.csproj 8 | *.pidb 9 | *.sln 10 | *.userprefs 11 | *.unityproj 12 | *.cache 13 | *.suo 14 | -------------------------------------------------------------------------------- /Assets/ComputeLatticeColors.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 581ea52c19ef19a488732de42afd1d82 3 | folderAsset: yes 4 | timeCreated: 1492919896 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/ComputeLatticeColors/ComputeLatticeColors.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kristofe/UnityGPUMarchingCubes/db1b234e7ae3343b48dfd942ed9ca2798735acde/Assets/ComputeLatticeColors/ComputeLatticeColors.unity -------------------------------------------------------------------------------- /Assets/ComputeLatticeColors/ComputeLatticeColors.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 920ad5a04577bc1408890e315cba6736 3 | timeCreated: 1492919896 4 | licenseType: Free 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/ComputeLatticeColors/LatticeRenderInto3DCS.compute: -------------------------------------------------------------------------------- 1 | #pragma kernel CSMain 2 | 3 | RWTexture3D Result; 4 | float4 g_Params; 5 | 6 | 7 | [numthreads(8,8,8)] 8 | void CSMain(uint3 id : SV_DispatchThreadID) 9 | { 10 | float4 c; 11 | c.r = (id.x & id.y & id.z) ? 1.0 : 0.0; 12 | //c.r = cos((id.x * g_Params.z + g_Params.x) * 4.0) * 0.5 + 0.5; 13 | c.g = sin((id.y * g_Params.z - g_Params.x) * 3.0) * 0.5 + 0.5; 14 | c.b = id.z * g_Params.z; 15 | c.a = 1.0; 16 | Result[id] = c; 17 | } 18 | -------------------------------------------------------------------------------- /Assets/ComputeLatticeColors/LatticeRenderInto3DCS.compute.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c3f334ca9565a384599b469ae57d9876 3 | timeCreated: 1492919899 4 | licenseType: Free 5 | ComputeShaderImporter: 6 | currentAPIMask: 131076 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/ComputeLatticeColors/LatticeRenderInto3DCS.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | public class LatticeRenderInto3DCS : MonoBehaviour 4 | { 5 | public ComputeShader cs; 6 | public int size = 16; 7 | private RenderTexture volume; 8 | 9 | void OnDisable () 10 | { 11 | if (volume != null) DestroyImmediate (volume); 12 | volume = null; 13 | } 14 | 15 | private void CreateResources () 16 | { 17 | if (!volume) 18 | { 19 | volume = new RenderTexture (size, size, 0, RenderTextureFormat.ARGB32); 20 | volume.volumeDepth = size; 21 | volume.isVolume = true; 22 | volume.enableRandomWrite = true; 23 | volume.Create(); 24 | Renderer Rend = GetComponent().GetComponent(); 25 | Rend.material.SetTexture ("_Volume", volume); 26 | } 27 | } 28 | 29 | void Update () 30 | { 31 | if (!SystemInfo.supportsComputeShaders) 32 | return; 33 | CreateResources (); 34 | cs.SetVector ("g_Params", new Vector4(Time.timeSinceLevelLoad, size, 1.0f/size, 1.0f)); 35 | 36 | cs.SetTexture (0, "Result", volume); 37 | cs.Dispatch (0, size,size,size); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Assets/ComputeLatticeColors/LatticeRenderInto3DCS.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 814fc7d0ce3553d4cb54a368416c9375 3 | timeCreated: 1492919897 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/ComputeLatticeColors/LatticeSample3DTex.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kristofe/UnityGPUMarchingCubes/db1b234e7ae3343b48dfd942ed9ca2798735acde/Assets/ComputeLatticeColors/LatticeSample3DTex.mat -------------------------------------------------------------------------------- /Assets/ComputeLatticeColors/LatticeSample3DTex.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d366b3c17b5792948bb096c3e3d41389 3 | timeCreated: 1492919898 4 | licenseType: Free 5 | NativeFormatImporter: 6 | mainObjectFileID: -1 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/ComputeLatticeColors/LatticeSample3DTex.shader: -------------------------------------------------------------------------------- 1 | Shader "DX11/Sample 3D Texture" { 2 | Properties { 3 | _Size ("Size", Range(0, 0.3)) = 0.1 4 | _Sprite ("", 2D) = "white" {} 5 | _Volume ("Texture", 3D) = "" {} 6 | } 7 | SubShader { 8 | Pass { 9 | //ZWrite Off ZTest Always Cull Off Fog { Mode Off } 10 | ZWrite Off Cull Off Fog { Mode Off } 11 | //Blend SrcAlpha OneMinusSrcAlpha 12 | Blend One One 13 | 14 | CGPROGRAM 15 | #pragma only_renderers d3d11 16 | #pragma target 5.0 17 | #pragma vertex vert 18 | #pragma geometry geom 19 | #pragma fragment frag 20 | 21 | #include "UnityCG.cginc" 22 | 23 | uniform float _Size; 24 | sampler3D _Volume; 25 | uniform sampler2D _Sprite; 26 | //For when the particles are simulated in a compute shader 27 | //StructuredBuffer particleBuffer; 28 | //StructuredBuffer particleColor; 29 | 30 | struct vs_in { 31 | float4 pos : POSITION; 32 | float4 uv : TEXCOORD0; 33 | float4 size : TEXCOORD1; 34 | float4 col : COLOR; 35 | }; 36 | 37 | struct vs_out { 38 | float4 pos : SV_POSITION; 39 | float4 uv : TEXCOORD0; 40 | float4 size : TEXCOORD1; 41 | float4 col : COLOR; 42 | }; 43 | 44 | //For when the particles are simulated in a compute shader 45 | //vs_out vert (uint id : SV_VertexID) 46 | //{ 47 | // // This runs through for each instance of the shader, id corrisponds to the particle in the list 48 | // vs_out o; 49 | // // Pull the location data and send it off to the geometry shader so it can be built into a particle 50 | // o.pos = float4(particleBuffer[id], 1.0f); 51 | // o.col = float4(particleColor[id], 1.0f); 52 | // return o; 53 | //} 54 | 55 | vs_out vert (vs_in v) 56 | { 57 | // This runs through for each instance of the shader, id corrisponds to the particle in the list 58 | vs_out o; 59 | // Pull the location data and send it off to the geometry shader so it can be built into a particle 60 | o.pos = v.pos; 61 | //o.uv = v.uv; 62 | o.col = v.pos.xyzw*0.5+0.5; 63 | o.size = v.size; 64 | //o.col = v.col; 65 | return o; 66 | } 67 | 68 | struct gs_out { 69 | float4 pos : SV_POSITION; 70 | float2 uv : TEXCOORD0; 71 | float4 col : COLOR; 72 | }; 73 | 74 | [maxvertexcount(4)] 75 | void geom (point vs_out input[1], inout TriangleStream outStream) 76 | { 77 | //float Size = 0.1f; 78 | 79 | float dx = _Size; 80 | float dy = _Size;// * _ScreenParams.x / _ScreenParams.y; 81 | gs_out output; 82 | 83 | // Run the given position through the View Proj matrix 84 | 85 | float4 corLoc = mul(UNITY_MATRIX_MVP, input[0].pos); 86 | //float4 corLoc = mul(UNITY_MATRIX_VP, input[0].pos); 87 | // Build the 4 points of the sprite and it's uv 88 | output.pos = corLoc + float4(-dx, dy,0,0); 89 | output.uv=float2(0,0); 90 | output.col = input[0].col; 91 | outStream.Append (output); 92 | 93 | output.pos = corLoc + float4( dx, dy,0,0); 94 | output.uv=float2(1,0); 95 | output.col = input[0].col; 96 | outStream.Append (output); 97 | 98 | output.pos = corLoc + float4(-dx,-dy,0,0); 99 | output.uv=float2(0,1); 100 | output.col = input[0].col; 101 | outStream.Append (output); 102 | 103 | output.pos = corLoc + float4( dx,-dy,0,0); 104 | output.uv=float2(1,1); 105 | output.col = input[0].col; 106 | outStream.Append (output); 107 | 108 | 109 | // Send it off as a particle to the pixel shader 110 | outStream.RestartStrip(); 111 | } 112 | 113 | // Pixel shader, straight forward just sample the sprite 114 | 115 | float4 frag (gs_out i ) : COLOR0 116 | { 117 | float4 c = tex3D (_Volume, i.col.xyz); 118 | float4 col = tex2D(_Sprite, i.uv) * c; 119 | //float4 col = tex2D(_Sprite, i.uv) * i.col; 120 | //col.w = 0.1f; 121 | //return i.col; 122 | return col; 123 | } 124 | 125 | ENDCG 126 | 127 | } 128 | } 129 | 130 | Fallback "VertexLit" 131 | } 132 | -------------------------------------------------------------------------------- /Assets/ComputeLatticeColors/LatticeSample3DTex.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f3a0cb00201a8654bbbd7db229525921 3 | timeCreated: 1492919898 4 | licenseType: Free 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/ComputeParticles.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a05b5dd7f2e915541816210a71600946 3 | folderAsset: yes 4 | timeCreated: 1492919896 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/ComputeParticles/ComputeParticles.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kristofe/UnityGPUMarchingCubes/db1b234e7ae3343b48dfd942ed9ca2798735acde/Assets/ComputeParticles/ComputeParticles.unity -------------------------------------------------------------------------------- /Assets/ComputeParticles/ComputeParticles.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 414f1953412a9bb469f4bc7c476993c3 3 | timeCreated: 1492919896 4 | licenseType: Free 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/ComputeParticles/ParticlesRenderInto3DCS.compute: -------------------------------------------------------------------------------- 1 | #pragma kernel CSMain 2 | 3 | //RWTexture3D pixels; 4 | RWStructuredBuffer pixels : register(u1); 5 | RWStructuredBuffer posBuffer : register(u0); 6 | 7 | float4 g_Params; 8 | int numParticles; 9 | 10 | 11 | 12 | float getPower(float3 testPos, float4 pos){ 13 | //This basically plots a nice curve that is 0.25 at r=0 and 0 at r=_power * 0.707 14 | float3 d = float3(pos.x - testPos.x, pos.y - testPos.y, pos.z - testPos.z); 15 | 16 | float mSqr = dot(d,d); 17 | mSqr /= pos.w * pos.w; 18 | if(mSqr >= 0.5f) 19 | return 0.0f; 20 | 21 | //mSqr /= _power * _power; 22 | 23 | if(mSqr < 0.5f ){ 24 | return (0.25 - mSqr + mSqr*mSqr); 25 | } 26 | return 0.0; 27 | } 28 | 29 | 30 | [numthreads(8,8,8)] 31 | void CSMain(uint3 id : SV_DispatchThreadID) 32 | { 33 | float p = 0.0; 34 | float textureSizeScale = g_Params.z; 35 | int idx = id.x + (id.y * g_Params.y) + (id.z * g_Params.y * g_Params.y); 36 | 37 | float3 testPos = float3(id.x*textureSizeScale,id.y*textureSizeScale,id.z*textureSizeScale); 38 | 39 | for(int i = 0; i < numParticles; ++i){ 40 | float4 particle = float4(posBuffer[i].x,posBuffer[i].y,posBuffer[i].z, posBuffer[i].w); 41 | p += getPower(testPos, particle); 42 | } 43 | 44 | //Result[id] = p; 45 | pixels[idx] = float4(p,p,p,1.0); 46 | } 47 | -------------------------------------------------------------------------------- /Assets/ComputeParticles/ParticlesRenderInto3DCS.compute.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 515f55454195cf6439fda1d7dabf7a63 3 | timeCreated: 1492919898 4 | licenseType: Free 5 | ComputeShaderImporter: 6 | currentAPIMask: 131076 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/ComputeParticles/ParticlesRenderInto3DCS.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | public class ParticlesRenderInto3DCS : MonoBehaviour 4 | { 5 | public Material marchingCubesMaterial; 6 | public ComputeShader updateTexture3DCS; 7 | public ComputeShader updateParticlePositionsCS; 8 | public int textureSize = 16; 9 | private RenderTexture volume; 10 | 11 | public int particleCount = 1000; 12 | public float particlePower = 0.2f; 13 | //public Transform rootLocation; 14 | 15 | private Vector4[] particleLocations; 16 | //private Vector4[] particleColors; 17 | private Vector4[] particleTargets; 18 | 19 | private Color[] pixels; 20 | private ComputeBuffer volumeBuffer; 21 | private Texture3D tex3D; // texture to pass to geometry shader 22 | 23 | private ComputeBuffer particleBuffer; 24 | //private ComputeBuffer particleColorBuffer; 25 | private ComputeBuffer targetBuffer; 26 | 27 | 28 | void OnDisable () 29 | { 30 | if (volume!= null) 31 | { 32 | volume.Release(); 33 | volume= null; 34 | } 35 | 36 | if (volumeBuffer != null) 37 | { 38 | volumeBuffer.Release(); 39 | volumeBuffer = null; 40 | } 41 | 42 | if (targetBuffer != null) 43 | { 44 | targetBuffer.Release(); 45 | targetBuffer = null; 46 | } 47 | /* 48 | if (particleColorBuffer != null) 49 | { 50 | particleColorBuffer.Release(); 51 | particleColorBuffer = null; 52 | } 53 | */ 54 | 55 | if (particleBuffer != null) 56 | { 57 | particleBuffer.Release(); 58 | particleBuffer = null; 59 | } 60 | } 61 | 62 | void Start () 63 | { 64 | // Setup the base args buffer 65 | particleLocations = new Vector4[particleCount]; 66 | //particleColors = new Vector4[particleCount]; 67 | particleTargets = new Vector4[particleCount]; 68 | 69 | for (int i = 0; i < particleCount; i++) 70 | { 71 | // Generate a random location 72 | Vector3 newLoc = Random.insideUnitSphere * 0.5f + new Vector3(0.5f,0.5f,0.5f); 73 | particleLocations[i] = new Vector4(newLoc.x, newLoc.y, newLoc.z, particlePower); 74 | particleTargets[i] = newLoc; 75 | //particleColors[i] = new Vector3(Random.value, Random.value, Random.value); 76 | } 77 | 78 | targetBuffer = new ComputeBuffer(particleCount, 16); 79 | targetBuffer.SetData(particleTargets); 80 | 81 | //particleColorBuffer = new ComputeBuffer(particleCount, 16); 82 | //particleColorBuffer.SetData(particleColors); 83 | 84 | particleBuffer = new ComputeBuffer(particleCount, 16); 85 | particleBuffer.SetData(particleLocations); 86 | 87 | int pixelCount = textureSize * textureSize * textureSize; 88 | 89 | tex3D = new Texture3D( textureSize, textureSize, textureSize, TextureFormat.ARGB32, false); 90 | tex3D.wrapMode = TextureWrapMode.Clamp; 91 | tex3D.anisoLevel = 0; 92 | 93 | pixels = new Color[pixelCount]; 94 | volumeBuffer = new ComputeBuffer(pixelCount, 16); 95 | volumeBuffer.SetData(pixels); 96 | 97 | /* 98 | volume = new RenderTexture(textureSize, textureSize, 0, RenderTextureFormat.ARGB32); 99 | volume.volumeDepth = textureSize; 100 | volume.isVolume = true; 101 | volume.enableRandomWrite = true; 102 | volume.Create(); 103 | */ 104 | 105 | //renderer.material.SetTexture ("_Volume", tex3D); 106 | //renderer.material.SetTexture ("_Volume", volume); 107 | //renderer.material.SetTexture("_dataFieldTex", tex3D); 108 | marchingCubesMaterial.SetTexture("_dataFieldTex", tex3D); 109 | 110 | 111 | } 112 | 113 | 114 | void Update () 115 | { 116 | if (!SystemInfo.supportsComputeShaders) 117 | return; 118 | 119 | float T = Time.timeSinceLevelLoad; 120 | 121 | 122 | updateParticlePositionsCS.SetFloat("Time", T); 123 | updateParticlePositionsCS.SetVector("CoreLoc", Vector3.zero); 124 | 125 | //cs.SetBuffer(cs.FindKernel("CSMain"), "colBuffer", particleColorBuffer); 126 | updateParticlePositionsCS.SetBuffer(updateTexture3DCS.FindKernel("CSMain"), "posBuffer", particleBuffer); 127 | updateParticlePositionsCS.SetBuffer(updateTexture3DCS.FindKernel("CSMain"), "tarBuffer", targetBuffer); 128 | updateParticlePositionsCS.Dispatch(updateParticlePositionsCS.FindKernel("CSMain"), particleCount/10, 1, 1); 129 | 130 | 131 | 132 | 133 | //Render Volume Texture 134 | updateTexture3DCS.SetVector("g_Params", new Vector4(Time.timeSinceLevelLoad, textureSize, 1.0f / textureSize, 1.0f)); 135 | updateTexture3DCS.SetInt("numParticles", particleCount); 136 | updateTexture3DCS.SetBuffer(updateTexture3DCS.FindKernel("CSMain"), "posBuffer", particleBuffer); 137 | updateTexture3DCS.SetBuffer(updateTexture3DCS.FindKernel("CSMain"), "pixels", volumeBuffer); 138 | //updateTexture3DCS.SetTexture(0, "pixels", volume); 139 | updateTexture3DCS.Dispatch(0, textureSize/8, textureSize/8, textureSize/8); 140 | 141 | //get pixels from render texture and copy to texture3D 142 | //Debug.Log("Before: " + pixels.Length); 143 | volumeBuffer.GetData(pixels); 144 | /*int count = 0; 145 | for (int i = 0; i < textureSize * textureSize * textureSize; ++i) 146 | { 147 | if (pixels[i].r > 0.0f || pixels[i].g > 0.0f || pixels[i].b > 0.0f) 148 | { 149 | count++; 150 | //Debug.Log("Success"); 151 | } 152 | } 153 | Debug.Log("After: " + pixels.Length + " count: " + count); 154 | */ 155 | tex3D.SetPixels(pixels); 156 | tex3D.Apply(); 157 | 158 | //renderer.material.SetTexture ("_Volume", tex3D); 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /Assets/ComputeParticles/ParticlesRenderInto3DCS.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bc5f3c2658f6c7843950131304e346dd 3 | timeCreated: 1492919897 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/ComputeParticles/ParticlesSample3DTex.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kristofe/UnityGPUMarchingCubes/db1b234e7ae3343b48dfd942ed9ca2798735acde/Assets/ComputeParticles/ParticlesSample3DTex.mat -------------------------------------------------------------------------------- /Assets/ComputeParticles/ParticlesSample3DTex.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 18c57a861a87e0f4aa5c53733730e1a8 3 | timeCreated: 1492919898 4 | licenseType: Free 5 | NativeFormatImporter: 6 | mainObjectFileID: -1 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/ComputeParticles/ParticlesSample3DTex.shader: -------------------------------------------------------------------------------- 1 | Shader "DX11/Particles Sample 3D Texture" { 2 | Properties { 3 | _Size ("Size", Range(0, 0.3)) = 0.1 4 | _Sprite ("", 2D) = "white" {} 5 | _Volume ("Texture", 3D) = "" {} 6 | } 7 | SubShader { 8 | Pass { 9 | //ZWrite Off ZTest Always Cull Off Fog { Mode Off } 10 | ZWrite Off Cull Off Fog { Mode Off } 11 | //Blend SrcAlpha OneMinusSrcAlpha 12 | Blend One One 13 | 14 | CGPROGRAM 15 | #pragma only_renderers d3d11 16 | #pragma target 5.0 17 | #pragma vertex vert 18 | #pragma geometry geom 19 | #pragma fragment frag 20 | 21 | #include "UnityCG.cginc" 22 | 23 | uniform float _Size; 24 | sampler3D _Volume; 25 | uniform sampler2D _Sprite; 26 | //For when the particles are simulated in a compute shader 27 | //StructuredBuffer particleBuffer; 28 | //StructuredBuffer particleColor; 29 | 30 | struct vs_in { 31 | float4 pos : POSITION; 32 | float4 uv : TEXCOORD0; 33 | float4 size : TEXCOORD1; 34 | float4 col : COLOR; 35 | }; 36 | 37 | struct vs_out { 38 | float4 pos : SV_POSITION; 39 | float4 uv : TEXCOORD0; 40 | float4 size : TEXCOORD1; 41 | float4 col : COLOR; 42 | }; 43 | 44 | //For when the particles are simulated in a compute shader 45 | //vs_out vert (uint id : SV_VertexID) 46 | //{ 47 | // // This runs through for each instance of the shader, id corrisponds to the particle in the list 48 | // vs_out o; 49 | // // Pull the location data and send it off to the geometry shader so it can be built into a particle 50 | // o.pos = float4(particleBuffer[id], 1.0f); 51 | // o.col = float4(particleColor[id], 1.0f); 52 | // return o; 53 | //} 54 | 55 | vs_out vert (vs_in v) 56 | { 57 | // This runs through for each instance of the shader, id corrisponds to the particle in the list 58 | vs_out o; 59 | // Pull the location data and send it off to the geometry shader so it can be built into a particle 60 | o.pos = v.pos; 61 | //o.uv = v.uv; 62 | o.col = v.pos.xyzw*0.5+0.5; 63 | o.size = v.size; 64 | //o.col = v.col; 65 | return o; 66 | } 67 | 68 | struct gs_out { 69 | float4 pos : SV_POSITION; 70 | float2 uv : TEXCOORD0; 71 | float4 col : COLOR; 72 | }; 73 | 74 | [maxvertexcount(4)] 75 | void geom (point vs_out input[1], inout TriangleStream outStream) 76 | { 77 | //float Size = 0.1f; 78 | 79 | float dx = _Size; 80 | float dy = _Size;// * _ScreenParams.x / _ScreenParams.y; 81 | gs_out output; 82 | 83 | // Run the given position through the View Proj matrix 84 | 85 | float4 corLoc = mul(UNITY_MATRIX_MVP, input[0].pos); 86 | //float4 corLoc = mul(UNITY_MATRIX_VP, input[0].pos); 87 | // Build the 4 points of the sprite and it's uv 88 | output.pos = corLoc + float4(-dx, dy,0,0); 89 | output.uv=float2(0,0); 90 | output.col = input[0].col; 91 | outStream.Append (output); 92 | 93 | output.pos = corLoc + float4( dx, dy,0,0); 94 | output.uv=float2(1,0); 95 | output.col = input[0].col; 96 | outStream.Append (output); 97 | 98 | output.pos = corLoc + float4(-dx,-dy,0,0); 99 | output.uv=float2(0,1); 100 | output.col = input[0].col; 101 | outStream.Append (output); 102 | 103 | output.pos = corLoc + float4( dx,-dy,0,0); 104 | output.uv=float2(1,1); 105 | output.col = input[0].col; 106 | outStream.Append (output); 107 | 108 | 109 | // Send it off as a particle to the pixel shader 110 | outStream.RestartStrip(); 111 | } 112 | 113 | // Pixel shader, straight forward just sample the sprite 114 | 115 | float4 frag (gs_out i ) : COLOR0 116 | { 117 | float4 c = tex3D (_Volume, i.col.xyz); 118 | float4 col = tex2D(_Sprite, i.uv) * c; 119 | //float4 col = tex2D(_Sprite, i.uv) * i.col; 120 | //col.w = 0.1f; 121 | //return i.col; 122 | return col; 123 | } 124 | 125 | ENDCG 126 | 127 | } 128 | } 129 | 130 | Fallback "VertexLit" 131 | } 132 | -------------------------------------------------------------------------------- /Assets/ComputeParticles/ParticlesSample3DTex.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1538c0b3569b2da4c86e930435e40875 3 | timeCreated: 1492919898 4 | licenseType: Free 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/ComputeParticles/ParticlesUpdateCS.compute: -------------------------------------------------------------------------------- 1 | 2 | // Each #kernel tells which function to compile; you can have many kernels 3 | #pragma kernel CSMain 4 | 5 | 6 | RWStructuredBuffer posBuffer : register(u0); 7 | //RWStructuredBuffer colBuffer : register(u2); 8 | RWStructuredBuffer tarBuffer : register(u1); 9 | 10 | float Time; 11 | float4 CoreLoc; 12 | 13 | float rand_1_05(in float2 uv) 14 | { 15 | float2 noise = (frac(sin(dot(uv ,float2(12.9898,78.233)*2.0)) * 43758.5453)); 16 | return abs(noise.x + noise.y) * 0.5; 17 | } 18 | 19 | float randomSpread(float2 seed) 20 | { 21 | float part1 = rand_1_05(seed); 22 | float part2 = 1; 23 | 24 | if (part1 < 0.5) 25 | { 26 | part2 = 1; 27 | } 28 | else{ 29 | part2 = -1; 30 | } 31 | 32 | return part2; 33 | } 34 | 35 | 36 | float3 ranWithinSphere(float2 seed) 37 | { 38 | float3 temp = float3(0,0,0); 39 | 40 | temp.x = randomSpread(seed); 41 | temp.y = randomSpread(seed); 42 | temp.z = randomSpread(seed); 43 | 44 | return temp; 45 | } 46 | 47 | float distance(float4 point1, float4 point2) 48 | { 49 | float x = (point1.x - point2.x) * (point1.x - point2.x); 50 | float y = (point1.y - point2.y) * (point1.x - point2.y); 51 | float z = (point1.z - point2.z) * (point1.x - point2.z); 52 | 53 | return sqrt(x + y + z); 54 | } 55 | 56 | [numthreads(10,1,1)] 57 | void CSMain (uint3 id : SV_DispatchThreadID) 58 | { 59 | float2 seed = float2(id.x * Time, Time); 60 | 61 | 62 | //colBuffer[id.x].x = cos(Time) * sin(Time); 63 | //colBuffer[id.x].y = sin(Time); 64 | 65 | float3 pos = tarBuffer[id.x]; 66 | pos.x = CoreLoc.x + ((cos(Time * id.x) * sin(Time))) * 4/12; 67 | pos.y = CoreLoc.y + ((sin(Time * id.x) * cos(Time))) * 7/12; 68 | pos.z = CoreLoc.z + ((cos(Time * id.x) * sin(Time))) * 12/12; 69 | 70 | pos = pos * 0.5 + 0.5; 71 | tarBuffer[id.x] = pos; 72 | 73 | 74 | // Work your way towards the target 75 | float changeX = tarBuffer[id.x].x - posBuffer[id.x].x; 76 | float changeY = tarBuffer[id.x].y - posBuffer[id.x].y; 77 | float changeZ = tarBuffer[id.x].z - posBuffer[id.x].z; 78 | 79 | 80 | posBuffer[id.x].x += (changeX / 40); 81 | posBuffer[id.x].y += (changeY / 40); 82 | posBuffer[id.x].z += (changeZ / 40); 83 | 84 | } -------------------------------------------------------------------------------- /Assets/ComputeParticles/ParticlesUpdateCS.compute.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fd272c44471cc704ca94c95faaee2dd9 3 | timeCreated: 1492919899 4 | licenseType: Free 5 | ComputeShaderImporter: 6 | currentAPIMask: 131076 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/ComputeShaders.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 02d2a9cc41dba1c47a059401c6a2f348 3 | folderAsset: yes 4 | timeCreated: 1492919896 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/ComputeShaders/ParticleComputeShader.compute: -------------------------------------------------------------------------------- 1 | 2 | // Each #kernel tells which function to compile; you can have many kernels 3 | #pragma kernel CSMain 4 | 5 | 6 | RWStructuredBuffer posBuffer : register(u0); 7 | RWStructuredBuffer colBuffer : register(u1); 8 | RWStructuredBuffer tarBuffer : register(u2); 9 | 10 | float Time; 11 | float4 CoreLoc; 12 | 13 | float rand_1_05(in float2 uv) 14 | { 15 | float2 noise = (frac(sin(dot(uv ,float2(12.9898,78.233)*2.0)) * 43758.5453)); 16 | return abs(noise.x + noise.y) * 0.5; 17 | } 18 | 19 | float randomSpread(float2 seed) 20 | { 21 | float part1 = rand_1_05(seed); 22 | float part2 = 1; 23 | 24 | if (part1 < 0.5) 25 | { 26 | part2 = 1; 27 | } 28 | else{ 29 | part2 = -1; 30 | } 31 | 32 | return part2; 33 | } 34 | 35 | 36 | float3 ranWithinSphere(float2 seed) 37 | { 38 | float3 temp = float3(0,0,0); 39 | 40 | temp.x = randomSpread(seed); 41 | temp.y = randomSpread(seed); 42 | temp.z = randomSpread(seed); 43 | 44 | return temp; 45 | } 46 | 47 | float distance(float3 point1, float3 point2) 48 | { 49 | float x = (point1.x - point2.x) * (point1.x - point2.x); 50 | float y = (point1.y - point2.y) * (point1.x - point2.y); 51 | float z = (point1.z - point2.z) * (point1.x - point2.z); 52 | 53 | return sqrt(x + y + z); 54 | } 55 | 56 | [numthreads(10,1,1)] 57 | void CSMain (uint3 id : SV_DispatchThreadID) 58 | { 59 | float2 seed = float2(id.x * Time, Time); 60 | 61 | 62 | colBuffer[id.x].x = cos(Time) * sin(Time); 63 | colBuffer[id.x].y = sin(Time); 64 | 65 | tarBuffer[id.x].x = CoreLoc.x + ((cos(Time * id.x) * sin(Time))) * 4; 66 | tarBuffer[id.x].y = CoreLoc.y + ((sin(Time * id.x) * cos(Time))) * 7; 67 | tarBuffer[id.x].z = CoreLoc.z + ((cos(Time * id.x) * sin(Time))) * 12; 68 | 69 | 70 | // Work your way towards the target 71 | float changeX = tarBuffer[id.x].x - posBuffer[id.x].x; 72 | float changeY = tarBuffer[id.x].y - posBuffer[id.x].y; 73 | float changeZ = tarBuffer[id.x].z - posBuffer[id.x].z; 74 | 75 | 76 | posBuffer[id.x].x += (changeX / 40); 77 | posBuffer[id.x].y += (changeY / 40); 78 | posBuffer[id.x].z += (changeZ / 40); 79 | 80 | } -------------------------------------------------------------------------------- /Assets/ComputeShaders/ParticleComputeShader.compute.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: efb588b73a75f9a42abfa1fefd5248d2 3 | timeCreated: 1492919899 4 | licenseType: Free 5 | ComputeShaderImporter: 6 | currentAPIMask: 131076 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/ComputeShaders/ParticleController.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Threading; 4 | 5 | public class ParticleController : MonoBehaviour 6 | { 7 | 8 | 9 | public Texture2D particleTexture; 10 | 11 | public Shader shader; 12 | 13 | private Material mat; 14 | 15 | //private ComputeBuffer cbDrawArgs; 16 | //private ComputeBuffer cbPoints; 17 | 18 | public ComputeShader cs; 19 | 20 | public int particleCount = 1000; 21 | public Transform rootLocation; 22 | 23 | private float[] x_p; 24 | private float[] y_p; 25 | private float[] z_p; 26 | 27 | private Vector3[] particleLocations; 28 | private Vector3[] particleColors; 29 | private Vector3[] particleTargets; 30 | 31 | private ComputeBuffer particleBuffer; 32 | private ComputeBuffer particleColorBuffer; 33 | private ComputeBuffer targetBuffer; 34 | 35 | private bool useCS = true; 36 | 37 | 38 | 39 | // Setup the shaders and such 40 | void Start() 41 | { 42 | // Setup the base args buffer 43 | particleLocations = new Vector3[particleCount]; 44 | particleColors = new Vector3[particleCount]; 45 | particleTargets = new Vector3[particleCount]; 46 | 47 | for (int i = 0; i < particleCount; i++) 48 | { 49 | // Generate a random location 50 | Vector3 newLoc = rootLocation.position + Random.insideUnitSphere; 51 | particleLocations[i] = newLoc; 52 | particleTargets[i] = newLoc; 53 | particleColors[i] = new Vector3(Random.value, Random.value, Random.value); 54 | } 55 | 56 | targetBuffer = new ComputeBuffer(particleCount, 12); 57 | targetBuffer.SetData(particleTargets); 58 | 59 | particleColorBuffer = new ComputeBuffer(particleCount, 12); 60 | particleColorBuffer.SetData(particleColors); 61 | 62 | particleBuffer = new ComputeBuffer(particleCount, 12); 63 | particleBuffer.SetData(particleLocations); 64 | 65 | // Setup the material based on the shader 66 | mat = new Material(shader); 67 | mat.hideFlags = HideFlags.HideAndDontSave; 68 | 69 | mat.SetTexture("_Sprite", particleTexture); 70 | Debug.Log("Finshed setting up"); 71 | } 72 | 73 | private void ReleaseResources() 74 | { 75 | 76 | if (targetBuffer != null) 77 | { 78 | targetBuffer.Release(); 79 | targetBuffer = null; 80 | } 81 | if (particleColorBuffer != null) 82 | { 83 | particleColorBuffer.Release(); 84 | particleColorBuffer = null; 85 | } 86 | if (particleBuffer != null) 87 | { 88 | particleBuffer.Release(); 89 | particleBuffer = null; 90 | } 91 | //Object.DestroyImmediate(mat); 92 | } 93 | 94 | void OnDisable() 95 | { 96 | ReleaseResources(); 97 | } 98 | 99 | 100 | void Update() 101 | { 102 | float T = Time.timeSinceLevelLoad; 103 | 104 | if (useCS) 105 | { 106 | if (useCS) 107 | { 108 | // Set time to the compute shader 109 | cs.SetFloat("Time", T); 110 | cs.SetVector("CoreLoc", rootLocation.position); 111 | 112 | // Have the compute shader process all the particle locations 113 | cs.SetBuffer(cs.FindKernel("CSMain"), "colBuffer", particleColorBuffer); 114 | cs.SetBuffer(cs.FindKernel("CSMain"), "posBuffer", particleBuffer); 115 | cs.SetBuffer(cs.FindKernel("CSMain"), "tarBuffer", targetBuffer); 116 | // Dispatch the compute shader 117 | cs.Dispatch(cs.FindKernel("CSMain"), particleCount, 1, 1); 118 | // Reconstruct the locations and colors 119 | } 120 | } 121 | else 122 | { 123 | // Do some modifications on the cpu 124 | 125 | for (int i = 0; i < particleCount; i++) 126 | { 127 | particleColors[i].x = Mathf.Cos(T); 128 | particleColors[i].y = Mathf.Sin(T); 129 | particleLocations[i] += Random.insideUnitSphere / 3; 130 | } 131 | 132 | 133 | // Set the buffers 134 | particleColorBuffer.SetData(particleColors); 135 | particleBuffer.SetData(particleLocations); 136 | } 137 | } 138 | 139 | void OnRenderImage(RenderTexture src, RenderTexture dst) 140 | { 141 | // The meat of the controller, this is where we can actually render our particles 142 | mat.SetTexture("_Sprite", particleTexture); 143 | 144 | // Blit the sceene without any interaction 145 | //Graphics.Blit(src, dst); 146 | 147 | 148 | // Set the buffers 149 | //particleBuffer.SetData(particleLocations); 150 | mat.SetBuffer("particleBuffer", particleBuffer); 151 | mat.SetBuffer("particleColor", particleColorBuffer); 152 | mat.SetPass(0); 153 | // Draw the particles into the scene 154 | Graphics.DrawProcedural(MeshTopology.LineStrip, particleCount); 155 | 156 | 157 | // Blit the sceene without any interaction 158 | Graphics.Blit(src, dst); 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /Assets/ComputeShaders/ParticleController.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9d67724f4cf045b47bfd86a329b3932c 3 | timeCreated: 1492919897 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/ComputeShaders/ParticleControllerShader.shader: -------------------------------------------------------------------------------- 1 | Shader "Custom/RenderParticles" { 2 | Properties { 3 | _Sprite ("", 2D) = "white" {} 4 | } 5 | 6 | SubShader { 7 | Pass{ 8 | //ZWrite Off ZTest Always Cull Off Fog { Mode Off } 9 | Cull Off Fog { Mode Off } 10 | Blend SrcAlpha One 11 | 12 | CGPROGRAM 13 | #pragma target 5.0 14 | 15 | #pragma vertex vert 16 | #pragma geometry geom 17 | #pragma fragment frag 18 | 19 | #include "UnityCG.cginc" 20 | 21 | StructuredBuffer particleBuffer; 22 | StructuredBuffer particleColor; 23 | 24 | struct vs_out { 25 | float4 pos : SV_POSITION; 26 | float4 col : COLOR; 27 | }; 28 | 29 | vs_out vert (uint id : SV_VertexID) 30 | { 31 | // This runs through for each instance of the shader, id corrisponds to the particle in the list 32 | vs_out o; 33 | // Pull the location data and send it off to the geometry shader so it can be built into a particle 34 | o.pos = float4(particleBuffer[id], 1.0f); 35 | o.col = float4(particleColor[id], 1.0f); 36 | return o; 37 | } 38 | 39 | struct gs_out { 40 | float4 pos : SV_POSITION; 41 | float2 uv : TEXCOORD0; 42 | float4 col : COLOR; 43 | }; 44 | 45 | [maxvertexcount(4)] 46 | void geom (point vs_out input[1], inout TriangleStream outStream) 47 | { 48 | float Size = 0.1f; 49 | 50 | float dx = Size; 51 | float dy = Size * _ScreenParams.x / _ScreenParams.y; 52 | gs_out output; 53 | 54 | // Run the given position through the View Proj matrix 55 | 56 | float4 corLoc = mul(UNITY_MATRIX_MVP, input[0].pos); 57 | // Build the 4 points of the sprite and it's uv 58 | output.pos = corLoc + float4(-dx, dy,0,0); output.uv=float2(0,0); output.col = input[0].col; outStream.Append (output); 59 | output.pos = corLoc + float4( dx, dy,0,0); output.uv=float2(1,0); output.col = input[0].col; outStream.Append (output); 60 | output.pos = corLoc + float4(-dx,-dy,0,0); output.uv=float2(0,1); output.col = input[0].col; outStream.Append (output); 61 | output.pos = corLoc + float4( dx,-dy,0,0); output.uv=float2(1,1); output.col = input[0].col; outStream.Append (output); 62 | // Send it off as a particle to the pixel shader 63 | outStream.RestartStrip(); 64 | } 65 | 66 | // Pixel shader, straight forward just sample the sprite 67 | sampler2D _Sprite; 68 | 69 | fixed4 frag (gs_out i ) : COLOR0 70 | { 71 | fixed4 col = tex2D(_Sprite, i.uv) * i.col; 72 | //col.w = 0.1f; 73 | //return i.col; 74 | return col; 75 | } 76 | 77 | ENDCG 78 | 79 | } 80 | } 81 | 82 | Fallback Off 83 | } -------------------------------------------------------------------------------- /Assets/ComputeShaders/ParticleControllerShader.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 30817d8a00459244db9941a9547530bd 3 | timeCreated: 1492919898 4 | licenseType: Free 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/ComputeShaders/RenderVolume.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 076effec73ffcd24bbcf0598f11e324a 3 | folderAsset: yes 4 | timeCreated: 1492919896 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/ComputeShaders/RenderVolume/_VolumeTextures.unity: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!29 &1 4 | Scene: 5 | m_ObjectHideFlags: 0 6 | m_PVSData: 7 | m_QueryMode: 1 8 | m_PVSObjectsArray: [] 9 | m_PVSPortalsArray: [] 10 | m_OcclusionBakeSettings: 11 | viewCellSize: 1 12 | bakeMode: 2 13 | memoryUsage: 10485760 14 | --- !u!104 &2 15 | RenderSettings: 16 | m_Fog: 0 17 | m_FogColor: {r: .5, g: .5, b: .5, a: 1} 18 | m_FogMode: 3 19 | m_FogDensity: .00999999978 20 | m_LinearFogStart: 0 21 | m_LinearFogEnd: 300 22 | m_AmbientLight: {r: .200000003, g: .200000003, b: .200000003, a: 1} 23 | m_SkyboxMaterial: {fileID: 0} 24 | m_HaloStrength: .5 25 | m_FlareStrength: 1 26 | m_HaloTexture: {fileID: 0} 27 | m_SpotCookie: {fileID: 0} 28 | m_ObjectHideFlags: 0 29 | --- !u!127 &3 30 | GameManager: 31 | m_ObjectHideFlags: 0 32 | --- !u!157 &4 33 | LightmapSettings: 34 | m_ObjectHideFlags: 0 35 | m_LightProbes: {fileID: 0} 36 | m_Lightmaps: [] 37 | m_LightmapsMode: 1 38 | m_BakedColorSpace: 0 39 | m_UseDualLightmapsInForward: 0 40 | m_LightmapEditorSettings: 41 | m_Resolution: 50 42 | m_LastUsedResolution: 0 43 | m_TextureWidth: 1024 44 | m_TextureHeight: 1024 45 | m_BounceBoost: 1 46 | m_BounceIntensity: 1 47 | m_SkyLightColor: {r: .860000014, g: .930000007, b: 1, a: 1} 48 | m_SkyLightIntensity: 0 49 | m_Quality: 0 50 | m_Bounces: 1 51 | m_FinalGatherRays: 1000 52 | m_FinalGatherContrastThreshold: .0500000007 53 | m_FinalGatherGradientThreshold: 0 54 | m_FinalGatherInterpolationPoints: 15 55 | m_AOAmount: 0 56 | m_AOMaxDistance: .100000001 57 | m_AOContrast: 1 58 | m_LODSurfaceMappingDistance: 1 59 | m_Padding: 0 60 | m_TextureCompression: 0 61 | m_LockAtlas: 0 62 | --- !u!196 &5 63 | NavMeshSettings: 64 | m_ObjectHideFlags: 0 65 | m_BuildSettings: 66 | agentRadius: .400000006 67 | agentHeight: 1.79999995 68 | agentSlope: 45 69 | agentClimb: .400000006 70 | ledgeDropHeight: 0 71 | maxJumpAcrossDistance: 0 72 | accuratePlacement: 0 73 | minRegionArea: 2 74 | widthInaccuracy: 16.666666 75 | heightInaccuracy: 10 76 | m_NavMesh: {fileID: 0} 77 | --- !u!1 &166027748 78 | GameObject: 79 | m_ObjectHideFlags: 0 80 | m_PrefabParentObject: {fileID: 0} 81 | m_PrefabInternal: {fileID: 0} 82 | serializedVersion: 4 83 | m_Component: 84 | - 4: {fileID: 166027749} 85 | - 33: {fileID: 166027751} 86 | - 135: {fileID: 166027752} 87 | - 23: {fileID: 166027750} 88 | - 114: {fileID: 166027753} 89 | m_Layer: 0 90 | m_Name: SphereScript3DTex 91 | m_TagString: Untagged 92 | m_Icon: {fileID: 0} 93 | m_NavMeshLayer: 0 94 | m_StaticEditorFlags: 0 95 | m_IsActive: 1 96 | --- !u!4 &166027749 97 | Transform: 98 | m_ObjectHideFlags: 0 99 | m_PrefabParentObject: {fileID: 0} 100 | m_PrefabInternal: {fileID: 0} 101 | m_GameObject: {fileID: 166027748} 102 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 103 | m_LocalPosition: {x: -2, y: 1, z: -1} 104 | m_LocalScale: {x: 1, y: 1, z: 1} 105 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 106 | m_Children: [] 107 | m_Father: {fileID: 0} 108 | --- !u!23 &166027750 109 | Renderer: 110 | m_ObjectHideFlags: 0 111 | m_PrefabParentObject: {fileID: 0} 112 | m_PrefabInternal: {fileID: 0} 113 | m_GameObject: {fileID: 166027748} 114 | m_Enabled: 1 115 | m_CastShadows: 1 116 | m_ReceiveShadows: 1 117 | m_LightmapIndex: 255 118 | m_LightmapTilingOffset: {x: 1, y: 1, z: 0, w: 0} 119 | m_Materials: 120 | - {fileID: 2100000, guid: 5b7fe7511c122c64e9ef0929ded86960, type: 2} 121 | m_SubsetIndices: 122 | m_StaticBatchRoot: {fileID: 0} 123 | m_UseLightProbes: 0 124 | m_LightProbeAnchor: {fileID: 0} 125 | m_ScaleInLightmap: 1 126 | --- !u!33 &166027751 127 | MeshFilter: 128 | m_ObjectHideFlags: 0 129 | m_PrefabParentObject: {fileID: 0} 130 | m_PrefabInternal: {fileID: 0} 131 | m_GameObject: {fileID: 166027748} 132 | m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0} 133 | --- !u!135 &166027752 134 | SphereCollider: 135 | m_ObjectHideFlags: 0 136 | m_PrefabParentObject: {fileID: 0} 137 | m_PrefabInternal: {fileID: 0} 138 | m_GameObject: {fileID: 166027748} 139 | m_Material: {fileID: 0} 140 | m_IsTrigger: 0 141 | m_Enabled: 1 142 | serializedVersion: 2 143 | m_Radius: .5 144 | m_Center: {x: 0, y: 0, z: -0} 145 | --- !u!114 &166027753 146 | MonoBehaviour: 147 | m_ObjectHideFlags: 0 148 | m_PrefabParentObject: {fileID: 0} 149 | m_PrefabInternal: {fileID: 0} 150 | m_GameObject: {fileID: 166027748} 151 | m_Enabled: 1 152 | m_EditorHideFlags: 0 153 | m_Script: {fileID: 11500000, guid: 65ebbfc93c9bd934397cf62c0b760f32, type: 3} 154 | m_Name: 155 | tex: {fileID: 0} 156 | size: 64 157 | --- !u!1 &922340770 158 | GameObject: 159 | m_ObjectHideFlags: 0 160 | m_PrefabParentObject: {fileID: 0} 161 | m_PrefabInternal: {fileID: 0} 162 | serializedVersion: 4 163 | m_Component: 164 | - 4: {fileID: 922340771} 165 | - 20: {fileID: 922340772} 166 | - 92: {fileID: 922340774} 167 | - 124: {fileID: 922340775} 168 | - 81: {fileID: 922340773} 169 | m_Layer: 0 170 | m_Name: Main Camera 171 | m_TagString: MainCamera 172 | m_Icon: {fileID: 0} 173 | m_NavMeshLayer: 0 174 | m_StaticEditorFlags: 0 175 | m_IsActive: 1 176 | --- !u!4 &922340771 177 | Transform: 178 | m_ObjectHideFlags: 0 179 | m_PrefabParentObject: {fileID: 0} 180 | m_PrefabInternal: {fileID: 0} 181 | m_GameObject: {fileID: 922340770} 182 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 183 | m_LocalPosition: {x: -1.5, y: .600000024, z: -3} 184 | m_LocalScale: {x: 1, y: 1, z: 1} 185 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 186 | m_Children: [] 187 | m_Father: {fileID: 0} 188 | --- !u!20 &922340772 189 | Camera: 190 | m_ObjectHideFlags: 0 191 | m_PrefabParentObject: {fileID: 0} 192 | m_PrefabInternal: {fileID: 0} 193 | m_GameObject: {fileID: 922340770} 194 | m_Enabled: 1 195 | serializedVersion: 2 196 | m_ClearFlags: 1 197 | m_BackGroundColor: {r: .0641568378, g: .0856414661, b: .119403005, a: .0196078438} 198 | m_NormalizedViewPortRect: 199 | serializedVersion: 2 200 | x: 0 201 | y: 0 202 | width: 1 203 | height: 1 204 | near clip plane: 1 205 | far clip plane: 100 206 | field of view: 60 207 | orthographic: 0 208 | orthographic size: 100 209 | m_Depth: -1 210 | m_CullingMask: 211 | serializedVersion: 2 212 | m_Bits: 4294967295 213 | m_RenderingPath: -1 214 | m_TargetTexture: {fileID: 0} 215 | m_HDR: 0 216 | --- !u!81 &922340773 217 | AudioListener: 218 | m_ObjectHideFlags: 0 219 | m_PrefabParentObject: {fileID: 0} 220 | m_PrefabInternal: {fileID: 0} 221 | m_GameObject: {fileID: 922340770} 222 | m_Enabled: 1 223 | --- !u!92 &922340774 224 | Behaviour: 225 | m_ObjectHideFlags: 0 226 | m_PrefabParentObject: {fileID: 0} 227 | m_PrefabInternal: {fileID: 0} 228 | m_GameObject: {fileID: 922340770} 229 | m_Enabled: 1 230 | --- !u!124 &922340775 231 | Behaviour: 232 | m_ObjectHideFlags: 0 233 | m_PrefabParentObject: {fileID: 0} 234 | m_PrefabInternal: {fileID: 0} 235 | m_GameObject: {fileID: 922340770} 236 | m_Enabled: 1 237 | --- !u!1 &1124085242 238 | GameObject: 239 | m_ObjectHideFlags: 0 240 | m_PrefabParentObject: {fileID: 0} 241 | m_PrefabInternal: {fileID: 0} 242 | serializedVersion: 4 243 | m_Component: 244 | - 4: {fileID: 1124085243} 245 | - 132: {fileID: 1124085244} 246 | m_Layer: 0 247 | m_Name: GUI Text 248 | m_TagString: Untagged 249 | m_Icon: {fileID: 0} 250 | m_NavMeshLayer: 0 251 | m_StaticEditorFlags: 0 252 | m_IsActive: 1 253 | --- !u!4 &1124085243 254 | Transform: 255 | m_ObjectHideFlags: 0 256 | m_PrefabParentObject: {fileID: 0} 257 | m_PrefabInternal: {fileID: 0} 258 | m_GameObject: {fileID: 1124085242} 259 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 260 | m_LocalPosition: {x: .5, y: 1, z: 0} 261 | m_LocalScale: {x: 1, y: 1, z: 1} 262 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 263 | m_Children: [] 264 | m_Father: {fileID: 0} 265 | --- !u!132 &1124085244 266 | GUIText: 267 | m_ObjectHideFlags: 0 268 | m_PrefabParentObject: {fileID: 0} 269 | m_PrefabInternal: {fileID: 0} 270 | m_GameObject: {fileID: 1124085242} 271 | m_Enabled: 1 272 | serializedVersion: 3 273 | m_Text: "3D texture filled from script (works anywhere)\r\nand one filled from Compute 274 | Shader (DX11 only).\r\n\r\nPress Play" 275 | m_Anchor: 1 276 | m_Alignment: 1 277 | m_PixelOffset: {x: 0, y: 0} 278 | m_LineSpacing: 1 279 | m_TabSize: 4 280 | m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0} 281 | m_Material: {fileID: 0} 282 | m_FontSize: 0 283 | m_FontStyle: 0 284 | m_PixelCorrect: 1 285 | m_EnableStyleMarkup: 1 286 | --- !u!1 &1500725512 287 | GameObject: 288 | m_ObjectHideFlags: 0 289 | m_PrefabParentObject: {fileID: 0} 290 | m_PrefabInternal: {fileID: 0} 291 | serializedVersion: 4 292 | m_Component: 293 | - 4: {fileID: 1500725513} 294 | - 33: {fileID: 1500725515} 295 | - 135: {fileID: 1500725516} 296 | - 23: {fileID: 1500725514} 297 | - 114: {fileID: 1500725517} 298 | m_Layer: 0 299 | m_Name: Sphere3DTexFromCompute 300 | m_TagString: Untagged 301 | m_Icon: {fileID: 0} 302 | m_NavMeshLayer: 0 303 | m_StaticEditorFlags: 0 304 | m_IsActive: 1 305 | --- !u!4 &1500725513 306 | Transform: 307 | m_ObjectHideFlags: 0 308 | m_PrefabParentObject: {fileID: 0} 309 | m_PrefabInternal: {fileID: 0} 310 | m_GameObject: {fileID: 1500725512} 311 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 312 | m_LocalPosition: {x: -1, y: 1, z: -1} 313 | m_LocalScale: {x: 1, y: 1, z: 1} 314 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 315 | m_Children: [] 316 | m_Father: {fileID: 0} 317 | --- !u!23 &1500725514 318 | Renderer: 319 | m_ObjectHideFlags: 0 320 | m_PrefabParentObject: {fileID: 0} 321 | m_PrefabInternal: {fileID: 0} 322 | m_GameObject: {fileID: 1500725512} 323 | m_Enabled: 1 324 | m_CastShadows: 1 325 | m_ReceiveShadows: 1 326 | m_LightmapIndex: 255 327 | m_LightmapTilingOffset: {x: 1, y: 1, z: 0, w: 0} 328 | m_Materials: 329 | - {fileID: 2100000, guid: 5b7fe7511c122c64e9ef0929ded86960, type: 2} 330 | m_SubsetIndices: 331 | m_StaticBatchRoot: {fileID: 0} 332 | m_UseLightProbes: 0 333 | m_LightProbeAnchor: {fileID: 0} 334 | m_ScaleInLightmap: 1 335 | --- !u!33 &1500725515 336 | MeshFilter: 337 | m_ObjectHideFlags: 0 338 | m_PrefabParentObject: {fileID: 0} 339 | m_PrefabInternal: {fileID: 0} 340 | m_GameObject: {fileID: 1500725512} 341 | m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0} 342 | --- !u!135 &1500725516 343 | SphereCollider: 344 | m_ObjectHideFlags: 0 345 | m_PrefabParentObject: {fileID: 0} 346 | m_PrefabInternal: {fileID: 0} 347 | m_GameObject: {fileID: 1500725512} 348 | m_Material: {fileID: 0} 349 | m_IsTrigger: 0 350 | m_Enabled: 1 351 | serializedVersion: 2 352 | m_Radius: .5 353 | m_Center: {x: 0, y: 0, z: -0} 354 | --- !u!114 &1500725517 355 | MonoBehaviour: 356 | m_ObjectHideFlags: 0 357 | m_PrefabParentObject: {fileID: 0} 358 | m_PrefabInternal: {fileID: 0} 359 | m_GameObject: {fileID: 1500725512} 360 | m_Enabled: 1 361 | m_EditorHideFlags: 0 362 | m_Script: {fileID: 11500000, guid: cb23fa3214495f341847a7ca9bb8f30a, type: 3} 363 | m_Name: 364 | cs: {fileID: 7200000, guid: c15c055ee6e1cba41a67624f2d7a7f8b, type: 3} 365 | size: 64 366 | -------------------------------------------------------------------------------- /Assets/ComputeShaders/RenderVolume/_VolumeTextures.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: eddbff871d1bc7d41845a5e627e47336 3 | timeCreated: 1492919896 4 | licenseType: Free 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f95b23053ceb78546885ccd7f2cecac3 3 | folderAsset: yes 4 | timeCreated: 1492919896 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Editor/Create3DAssets.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | 4 | public class Create3DAssets : MonoBehaviour { 5 | public Texture3D texture3D; 6 | public Texture2D texture2D; 7 | public int n; 8 | public Light _light; 9 | public float absorption; 10 | public float lightIntensityScale; 11 | //public bool onlyGenerateTexture3D; 12 | public string texture3DName = "pyroclasticNoise"; 13 | private Mesh m; 14 | 15 | // Use this for initialization 16 | public void Start () 17 | { 18 | /*if (onlyGenerateTexture3D) 19 | { 20 | Generate3DTexture(); 21 | save3DTexture(); 22 | } 23 | */ 24 | 25 | CreateMesh(); 26 | //Generate3DTexture(); 27 | 28 | Vector4 localEyePos = transform.worldToLocalMatrix.MultiplyPoint(Camera.main.transform.position); 29 | Vector4 localLightPos = transform.worldToLocalMatrix.MultiplyPoint(_light.transform.position); 30 | 31 | Renderer renderer = GetComponent().GetComponent(); 32 | renderer.material.SetVector("g_eyePos", localEyePos); 33 | renderer.material.SetVector("g_lightPos", localLightPos); 34 | renderer.material.SetFloat("g_lightIntensity", _light.intensity); 35 | renderer.material.SetFloat("g_absorption", absorption); 36 | } 37 | 38 | void LateUpdate() 39 | { 40 | //if (onlyGenerateTexture3D) 41 | //return; 42 | 43 | Renderer renderer = GetComponent().GetComponent(); 44 | 45 | Vector4 localEyePos = transform.worldToLocalMatrix.MultiplyPoint(Camera.main.transform.position); 46 | localEyePos += new Vector4(0.5f,0.5f,0.5f,0.0f); 47 | renderer.material.SetVector("g_eyePos", localEyePos); 48 | 49 | 50 | Vector4 localLightPos = transform.worldToLocalMatrix.MultiplyPoint( 51 | _light.transform.position); 52 | renderer.material.SetVector("g_lightPos", localLightPos); 53 | renderer.material.SetFloat("g_lightIntensity", _light.intensity * 54 | lightIntensityScale); 55 | } 56 | 57 | 58 | 59 | private Mesh CreateMesh() 60 | { 61 | m = new Mesh(); 62 | CreateCube(m); 63 | m.RecalculateBounds(); 64 | MeshFilter mf = (MeshFilter)transform.GetComponent(typeof(MeshFilter)); 65 | mf.mesh = m; 66 | return m; 67 | } 68 | 69 | void CreateCube(Mesh m) 70 | { 71 | Vector3[] vertices = new Vector3[24]; 72 | Vector2[] uv = new Vector2[24]; 73 | Color[] colors = new Color[24]; 74 | Vector3[] normals = new Vector3[24]; 75 | int[] triangles = new int[36]; 76 | 77 | int i = 0; 78 | int ti = 0; 79 | //Front 80 | vertices[i] = new Vector3(-0.5f,-0.5f,-0.5f); 81 | normals[i] = new Vector3(0,0,-1); 82 | colors[i] = new Color(0,0,0); 83 | 84 | i++; 85 | vertices[i] = new Vector3(0.5f,-0.5f,-0.5f); 86 | normals[i] = new Vector3(0,0,-1); 87 | colors[i] = new Color(1,0,0); 88 | 89 | i++; 90 | vertices[i] = new Vector3(0.5f,0.5f,-0.5f); 91 | normals[i] = new Vector3(0,0,-1); 92 | colors[i] = new Color(1,1,0); 93 | i++; 94 | 95 | vertices[i] = new Vector3(-0.5f,0.5f,-0.5f); 96 | normals[i] = new Vector3(0,0,-1); 97 | colors[i] = new Color(0,1,0); 98 | 99 | i++; 100 | 101 | triangles[ti++] = i-4; 102 | triangles[ti++] = i-2; 103 | triangles[ti++] = i-3; 104 | triangles[ti++] = i-4; 105 | triangles[ti++] = i-1; 106 | triangles[ti++] = i-2; 107 | 108 | //Back 109 | vertices[i] = new Vector3(-0.5f,-0.5f,0.5f); 110 | normals[i] = new Vector3(0,0,-1); 111 | colors[i] = new Color(0,0,1); 112 | 113 | i++; 114 | vertices[i] = new Vector3(0.5f,-0.5f,0.5f); 115 | normals[i] = new Vector3(0,0,-1); 116 | colors[i] = new Color(1,0,1); 117 | 118 | i++; 119 | vertices[i] = new Vector3(0.5f,0.5f,0.5f); 120 | normals[i] = new Vector3(0,0,-1); 121 | colors[i] = new Color(1,1,1); 122 | i++; 123 | 124 | vertices[i] = new Vector3(-0.5f,0.5f,0.5f); 125 | normals[i] = new Vector3(0,0,-1); 126 | colors[i] = new Color(0,1,1); 127 | 128 | i++; 129 | 130 | triangles[ti++] = i-4; 131 | triangles[ti++] = i-3; 132 | triangles[ti++] = i-2; 133 | triangles[ti++] = i-4; 134 | triangles[ti++] = i-2; 135 | triangles[ti++] = i-1; 136 | 137 | //Top 138 | vertices[i] = new Vector3(-0.5f,0.5f,-0.5f); 139 | normals[i] = new Vector3(0,1,0); 140 | colors[i] = new Color(0,1,0); 141 | 142 | i++; 143 | vertices[i] = new Vector3(0.5f,0.5f,-0.5f); 144 | normals[i] = new Vector3(0,1,0); 145 | colors[i] = new Color(1,1,0); 146 | 147 | i++; 148 | vertices[i] = new Vector3(0.5f,0.5f,0.5f); 149 | normals[i] = new Vector3(0,1,0); 150 | colors[i] = new Color(1,1,1); 151 | 152 | i++; 153 | 154 | vertices[i] = new Vector3(-0.5f,0.5f,0.5f); 155 | normals[i] = new Vector3(0,1,0); 156 | colors[i] = new Color(0,1,1); 157 | 158 | i++; 159 | 160 | triangles[ti++] = i-4; 161 | triangles[ti++] = i-2; 162 | triangles[ti++] = i-3; 163 | triangles[ti++] = i-4; 164 | triangles[ti++] = i-1; 165 | triangles[ti++] = i-2; 166 | 167 | //Bottom 168 | vertices[i] = new Vector3(-0.5f,-0.5f,-0.5f); 169 | normals[i] = new Vector3(0,1,0); 170 | colors[i] = new Color(0,0,0); 171 | 172 | i++; 173 | vertices[i] = new Vector3(0.5f,-0.5f,-0.5f); 174 | normals[i] = new Vector3(0,1,0); 175 | colors[i] = new Color(1,0,0); 176 | 177 | i++; 178 | vertices[i] = new Vector3(0.5f,-0.5f,0.5f); 179 | normals[i] = new Vector3(0,1,0); 180 | colors[i] = new Color(1,0,1); 181 | 182 | i++; 183 | 184 | vertices[i] = new Vector3(-0.5f,-0.5f,0.5f); 185 | normals[i] = new Vector3(0,1,0); 186 | colors[i] = new Color(0,0,1); 187 | 188 | i++; 189 | 190 | triangles[ti++] = i-4; 191 | triangles[ti++] = i-3; 192 | triangles[ti++] = i-2; 193 | triangles[ti++] = i-4; 194 | triangles[ti++] = i-2; 195 | triangles[ti++] = i-1; 196 | 197 | //Right 198 | vertices[i] = new Vector3(0.5f,-0.5f,-0.5f); 199 | normals[i] = new Vector3(0,1,0); 200 | colors[i] = new Color(1,0,0); 201 | 202 | i++; 203 | 204 | vertices[i] = new Vector3(0.5f,0.5f,-0.5f); 205 | normals[i] = new Vector3(0,1,0); 206 | colors[i] = new Color(1,1,0); 207 | 208 | i++; 209 | 210 | vertices[i] = new Vector3(0.5f,0.5f,0.5f); 211 | normals[i] = new Vector3(0,1,0); 212 | colors[i] = new Color(1,1,1); 213 | 214 | i++; 215 | 216 | vertices[i] = new Vector3(0.5f,-0.5f,0.5f); 217 | normals[i] = new Vector3(0,1,0); 218 | colors[i] = new Color(1,0,1); 219 | 220 | i++; 221 | 222 | triangles[ti++] = i-4; 223 | triangles[ti++] = i-3; 224 | triangles[ti++] = i-2; 225 | triangles[ti++] = i-4; 226 | triangles[ti++] = i-2; 227 | triangles[ti++] = i-1; 228 | 229 | //Left 230 | vertices[i] = new Vector3(-0.5f,-0.5f,-0.5f); 231 | normals[i] = new Vector3(0,1,0); 232 | colors[i] = new Color(0,0,0); 233 | 234 | i++; 235 | 236 | vertices[i] = new Vector3(-0.5f,0.5f,-0.5f); 237 | normals[i] = new Vector3(0,1,0); 238 | colors[i] = new Color(0,1,0); 239 | 240 | i++; 241 | 242 | vertices[i] = new Vector3(-0.5f,0.5f,0.5f); 243 | normals[i] = new Vector3(0,1,0); 244 | colors[i] = new Color(0,1,1); 245 | 246 | i++; 247 | 248 | vertices[i] = new Vector3(-0.5f,-0.5f,0.5f); 249 | normals[i] = new Vector3(0,1,0); 250 | colors[i] = new Color(0,0,1); 251 | 252 | i++; 253 | 254 | triangles[ti++] = i-4; 255 | triangles[ti++] = i-2; 256 | triangles[ti++] = i-3; 257 | triangles[ti++] = i-4; 258 | triangles[ti++] = i-1; 259 | triangles[ti++] = i-2; 260 | 261 | m.vertices = vertices; 262 | m.colors = colors; //Putting uv's into the normal channel to get the 263 | //Vector3 type 264 | m.uv = uv; 265 | m.normals = normals; 266 | m.triangles = triangles; 267 | } 268 | 269 | public void Generate2DTexture() 270 | { 271 | texture2D = new Texture2D(n,n,TextureFormat.ARGB32,true); 272 | int size = n*n; 273 | Color[] cols = new Color[size]; 274 | float u,v; 275 | int idx = 0; 276 | Color c = Color.white; 277 | for(int i = 0; i < n; i++) { 278 | u = i/(float)n; 279 | for(int j = 0; j < n; j++, ++idx) { 280 | v = j/(float)n; 281 | float noise = Mathf.PerlinNoise(u,v); 282 | c.r = c.g = c.b = noise; 283 | cols[idx] = c; 284 | 285 | } 286 | } 287 | 288 | texture2D.SetPixels(cols); 289 | texture2D.Apply(); 290 | 291 | Renderer renderer = GetComponent().GetComponent(); 292 | renderer.material.SetTexture("g_tex", texture2D); 293 | 294 | //Color[] cs = texture3D.GetPixels(); 295 | //for(int i = 0; i < 10; i++) 296 | // Debug.Log (cs[i]); 297 | 298 | 299 | } 300 | 301 | public void Generate3DTexture() 302 | { 303 | float r = 0.3f; 304 | texture3D = new Texture3D(n,n,n,TextureFormat.ARGB32,true); 305 | int size = n * n * n; 306 | Color[] cols = new Color[size]; 307 | int idx = 0; 308 | 309 | Color c = Color.white; 310 | float frequency = 0.01f / n; 311 | float center = n / 2.0f + 0.5f; 312 | 313 | for(int i = 0; i < n; i++) { 314 | for(int j = 0; j < n; j++) { 315 | for(int k = 0; k < n; k++, ++idx) { 316 | float dx = center-i; 317 | float dy = center-j; 318 | float dz = center-k; 319 | 320 | float off = Mathf.Abs(Perlin.Turbulence(i*frequency, 321 | j*frequency, 322 | k*frequency, 323 | 6)); 324 | 325 | float d = Mathf.Sqrt(dx*dx+dy*dy+dz*dz)/(n); 326 | //c.r = c.g = c.b = c.a = ((d-off) < r)?1.0f:0.0f; 327 | float p = d-off; 328 | c.r = c.g = c.b = c.a = Mathf.Clamp01(r - p); 329 | cols[idx] = c; 330 | } 331 | } 332 | } 333 | 334 | //for(int i = 0; i < size; i++) 335 | // Debug.Log (newC[i]); 336 | texture3D.SetPixels(cols); 337 | texture3D.Apply(); 338 | Renderer renderer = GetComponent().GetComponent(); 339 | renderer.material.SetTexture("g_densityTex", texture3D); 340 | texture3D.filterMode = FilterMode.Trilinear; 341 | texture3D.wrapMode = TextureWrapMode.Clamp; 342 | texture3D.anisoLevel = 1; 343 | 344 | //Color[] cs = texture3D.GetPixels(); 345 | //for(int i = 0; i < 10; i++) 346 | // Debug.Log (cs[i]); 347 | } 348 | 349 | private void save3DTexture() 350 | { 351 | string path = "Assets/Textures3D/" + texture3DName + ".asset"; 352 | Texture3D tmp = (Texture3D)AssetDatabase.LoadAssetAtPath(path, typeof(Texture3D)); 353 | if (tmp) 354 | { 355 | AssetDatabase.DeleteAsset(path); 356 | tmp = null; 357 | } 358 | 359 | AssetDatabase.CreateAsset(texture3D, path); 360 | AssetDatabase.SaveAssets(); 361 | } 362 | 363 | } 364 | -------------------------------------------------------------------------------- /Assets/Editor/Create3DAssets.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4bf2c199cf1fc31468c5cd1e3233ed67 3 | timeCreated: 1492919897 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/Editor/Create3DTexture.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.Collections; 4 | 5 | public class Create3DTexture : MonoBehaviour 6 | { 7 | 8 | [MenuItem ("Asset Creation/Create 3D Texture")] 9 | public static void CreateTexture() 10 | { 11 | int n = 64; 12 | string texName = "pyroclasticNoise"; 13 | Texture3D texture3D = new Texture3D(n, n, n, TextureFormat.ARGB32, true); 14 | 15 | Generate3DTexture(ref texture3D, n); 16 | save3DTexture(texture3D, texName); 17 | } 18 | 19 | public static void Generate3DTexture(ref Texture3D texture3D, int n) 20 | { 21 | float r = 0.3f; 22 | int size = n * n * n; 23 | Color[] cols = new Color[size]; 24 | int idx = 0; 25 | 26 | Color c = Color.white; 27 | float frequency = 0.01f / n; 28 | float center = n / 2.0f + 0.5f; 29 | 30 | for (int i = 0; i < n; i++) 31 | { 32 | for (int j = 0; j < n; j++) 33 | { 34 | for (int k = 0; k < n; k++, ++idx) 35 | { 36 | float dx = center - i; 37 | float dy = center - j; 38 | float dz = center - k; 39 | 40 | float off = Mathf.Abs(Perlin.Turbulence(i * frequency, 41 | j * frequency, 42 | k * frequency, 43 | 6)); 44 | 45 | float d = Mathf.Sqrt(dx * dx + dy * dy + dz * dz) / (n); 46 | //c.r = c.g = c.b = c.a = ((d-off) < r)?1.0f:0.0f; 47 | float p = d - off; 48 | c.r = c.g = c.b = c.a = Mathf.Clamp01(r - p); 49 | cols[idx] = c; 50 | } 51 | } 52 | } 53 | 54 | //for(int i = 0; i < size; i++) 55 | // Debug.Log (newC[i]); 56 | texture3D.SetPixels(cols); 57 | texture3D.Apply(); 58 | texture3D.filterMode = FilterMode.Trilinear; 59 | texture3D.wrapMode = TextureWrapMode.Clamp; 60 | texture3D.anisoLevel = 1; 61 | } 62 | 63 | private static void save3DTexture(Texture3D texture3D, string texture3DName) 64 | { 65 | string path = "Assets/Textures3D/" + texture3DName + ".asset"; 66 | Texture3D tmp = (Texture3D)AssetDatabase.LoadAssetAtPath(path, typeof(Texture3D)); 67 | if (tmp) 68 | { 69 | AssetDatabase.DeleteAsset(path); 70 | tmp = null; 71 | } 72 | 73 | AssetDatabase.CreateAsset(texture3D, path); 74 | AssetDatabase.SaveAssets(); 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /Assets/Editor/Create3DTexture.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 998a3e4b2cbb99641ab90b323cdc177f 3 | timeCreated: 1492919897 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/Editor/CreateLatticeMesh.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | 6 | public class CreateLatticeMesh : MonoBehaviour { 7 | // Use this for initialization 8 | [MenuItem ("Asset Creation/Create Point Lattice Mesh")] 9 | static void CreatePointLatticeMesh () { 10 | string meshName = "LatticeMesh1x1x1"; 11 | Mesh m = CreateLattice(32); 12 | saveMesh(m, meshName); 13 | 14 | } 15 | 16 | 17 | 18 | private static void saveMesh(Mesh m, string meshName){ 19 | string path = "Assets/Meshes/" + meshName + ".asset"; 20 | Mesh tmp = (Mesh)AssetDatabase.LoadAssetAtPath(path, typeof(Mesh)); 21 | if(tmp){ 22 | AssetDatabase.DeleteAsset(path); 23 | tmp = null; 24 | } 25 | 26 | AssetDatabase.CreateAsset(m, path); 27 | AssetDatabase.SaveAssets(); 28 | } 29 | 30 | 31 | private static Mesh CreateLattice(int meshDim) 32 | { 33 | Mesh m = new Mesh(); 34 | ConstructMesh(m, meshDim); 35 | m.RecalculateBounds(); 36 | return m; 37 | } 38 | 39 | private static void ConstructMesh(Mesh m, int meshDim) 40 | { 41 | int vertexCount = meshDim * meshDim * meshDim; 42 | Vector3[] vertices = new Vector3[vertexCount]; 43 | //Vector2[] uv = new Vector2[meshDim]; 44 | Vector3[] normals = new Vector3[vertexCount]; 45 | List triangles = new List(vertexCount * 3); 46 | float scale = 1.0f / meshDim; 47 | Vector3 offset = new Vector3(0.5f, 0.5f, 0.5f); 48 | for (int z = 0; z < meshDim; ++z) 49 | { 50 | for (int y = 0; y < meshDim; ++y) 51 | { 52 | for (int x = 0; x < meshDim; ++x) 53 | { 54 | int idx = z * meshDim * meshDim + y * meshDim + x; 55 | vertices[idx] = new Vector3(x * scale, y * scale, z * scale) - offset; 56 | normals[idx] = Vector3.right; 57 | triangles.Add(idx); 58 | triangles.Add(idx); 59 | triangles.Add(idx); 60 | } 61 | } 62 | } 63 | m.vertices = vertices; 64 | //m.uv = uv; 65 | m.normals = normals; 66 | m.triangles = triangles.ToArray(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Assets/Editor/CreateLatticeMesh.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 363762be1b9851541abc36fe9175d592 3 | timeCreated: 1492919897 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/Editor/CreateTexture.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.Collections; 4 | 5 | public class CreateTexture : MonoBehaviour { 6 | public string textureName; 7 | public int n; 8 | public Color color; 9 | 10 | private Texture2D texture2D; 11 | 12 | // Use this for initialization 13 | void Start () { 14 | Generate2DTexture(); 15 | save2DTexture(); 16 | 17 | } 18 | 19 | // Update is called once per frame 20 | void Update () { 21 | 22 | } 23 | 24 | 25 | public void Generate2DTexture() 26 | { 27 | texture2D = new Texture2D(n, n, TextureFormat.ARGB32, true); 28 | int size = n * n; 29 | Color[] cols = new Color[size]; 30 | //float u, v; 31 | int idx = 0; 32 | //Color c = Color.white; 33 | for (int i = 0; i < n; i++) 34 | { 35 | //u = i / (float)n; 36 | for (int j = 0; j < n; j++, ++idx) 37 | { 38 | cols[idx] = color; 39 | 40 | } 41 | } 42 | 43 | texture2D.SetPixels(cols); 44 | texture2D.Apply(); 45 | 46 | } 47 | 48 | private void save2DTexture() 49 | { 50 | string path = "Assets/Textures/" + textureName + ".asset"; 51 | Texture2D tmp = (Texture2D)AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D)); 52 | if (tmp) 53 | { 54 | AssetDatabase.DeleteAsset(path); 55 | tmp = null; 56 | } 57 | 58 | AssetDatabase.CreateAsset(texture2D, path); 59 | AssetDatabase.SaveAssets(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Assets/Editor/CreateTexture.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d41833330d4c41c4ba5a6d17f8e294b9 3 | timeCreated: 1492919897 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/MarchingCubesTest.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ea99b36aa4e6e6d43827364ea23d1116 3 | folderAsset: yes 4 | timeCreated: 1492919896 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/MarchingCubesTest/MarchingCubesTestScene.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kristofe/UnityGPUMarchingCubes/db1b234e7ae3343b48dfd942ed9ca2798735acde/Assets/MarchingCubesTest/MarchingCubesTestScene.unity -------------------------------------------------------------------------------- /Assets/MarchingCubesTest/MarchingCubesTestScene.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c8d2c43135ba0114ab91fee6f86f3ec3 3 | timeCreated: 1492919896 4 | licenseType: Free 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/MarchingCubesTest/PlayWithIsoLevels.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class PlayWithIsoLevels : MonoBehaviour { 5 | 6 | // Use this for initialization 7 | void Start () { 8 | 9 | } 10 | 11 | // Update is called once per frame 12 | void Update () 13 | { 14 | float level = Mathf.Sin(Time.time) * 0.5f + 0.5f; 15 | level = 0.05f + level * 0.25f; 16 | Renderer Rend = GetComponent().GetComponent(); 17 | Rend.material.SetFloat("_isoLevel", level); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Assets/MarchingCubesTest/PlayWithIsoLevels.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ba5c36664ca3ef649af2d04e2b489535 3 | timeCreated: 1492919897 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/Materials.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6e59a8abc62042447983d4dc2ba1feee 3 | folderAsset: yes 4 | timeCreated: 1492919896 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Materials/Particles.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d555fb1d24901c7499fa473bc1011c3a 3 | folderAsset: yes 4 | timeCreated: 1492919896 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Materials/Particles/GPUParticle.shader: -------------------------------------------------------------------------------- 1 | Shader "Custom/GPURenderParticles" { 2 | Properties { 3 | _Sprite ("", 2D) = "white" {} 4 | _Size ("Size", Range(0, 0.3)) = 0.1 5 | } 6 | 7 | SubShader { 8 | Pass{ 9 | //ZWrite Off ZTest Always Cull Off Fog { Mode Off } 10 | ZWrite Off Cull Off Fog { Mode Off } 11 | //Blend SrcAlpha OneMinusSrcAlpha 12 | Blend One One 13 | 14 | CGPROGRAM 15 | #pragma only_renderers d3d11 16 | #pragma target 5.0 17 | 18 | #pragma vertex vert 19 | #pragma geometry geom 20 | #pragma fragment frag 21 | 22 | #include "UnityCG.cginc" 23 | 24 | uniform float _Size; 25 | uniform sampler2D _Sprite; 26 | //For when the particles are simulated in a compute shader 27 | //StructuredBuffer particleBuffer; 28 | //StructuredBuffer particleColor; 29 | 30 | struct vs_in { 31 | float4 pos : POSITION; 32 | float4 uv : TEXCOORD0; 33 | float4 size : TEXCOORD1; 34 | float4 col : COLOR; 35 | }; 36 | 37 | struct vs_out { 38 | float4 pos : SV_POSITION; 39 | float4 uv : TEXCOORD0; 40 | float4 size : TEXCOORD1; 41 | float4 col : COLOR; 42 | }; 43 | 44 | //For when the particles are simulated in a compute shader 45 | //vs_out vert (uint id : SV_VertexID) 46 | //{ 47 | // // This runs through for each instance of the shader, id corrisponds to the particle in the list 48 | // vs_out o; 49 | // // Pull the location data and send it off to the geometry shader so it can be built into a particle 50 | // o.pos = float4(particleBuffer[id], 1.0f); 51 | // o.col = float4(particleColor[id], 1.0f); 52 | // return o; 53 | //} 54 | 55 | vs_out vert (vs_in v) 56 | { 57 | // This runs through for each instance of the shader, id corrisponds to the particle in the list 58 | vs_out o; 59 | // Pull the location data and send it off to the geometry shader so it can be built into a particle 60 | o.pos = v.pos; 61 | o.uv = v.uv; 62 | o.size = v.size; 63 | o.col = v.col; 64 | return o; 65 | } 66 | 67 | struct gs_out { 68 | float4 pos : SV_POSITION; 69 | float2 uv : TEXCOORD0; 70 | float4 col : COLOR; 71 | }; 72 | 73 | [maxvertexcount(4)] 74 | void geom (point vs_out input[1], inout TriangleStream outStream) 75 | { 76 | //float Size = 0.1f; 77 | 78 | float dx = _Size; 79 | float dy = _Size;// * _ScreenParams.x / _ScreenParams.y; 80 | gs_out output; 81 | 82 | // Run the given position through the View Proj matrix 83 | 84 | float4 corLoc = mul(UNITY_MATRIX_MVP, input[0].pos); 85 | //float4 corLoc = mul(UNITY_MATRIX_VP, input[0].pos); 86 | // Build the 4 points of the sprite and it's uv 87 | output.pos = corLoc + float4(-dx, dy,0,0); 88 | output.uv=float2(0,0); 89 | output.col = input[0].col; 90 | outStream.Append (output); 91 | 92 | output.pos = corLoc + float4( dx, dy,0,0); 93 | output.uv=float2(1,0); 94 | output.col = input[0].col; 95 | outStream.Append (output); 96 | 97 | output.pos = corLoc + float4(-dx,-dy,0,0); 98 | output.uv=float2(0,1); 99 | output.col = input[0].col; 100 | outStream.Append (output); 101 | 102 | output.pos = corLoc + float4( dx,-dy,0,0); 103 | output.uv=float2(1,1); 104 | output.col = input[0].col; 105 | outStream.Append (output); 106 | 107 | 108 | // Send it off as a particle to the pixel shader 109 | outStream.RestartStrip(); 110 | } 111 | 112 | // Pixel shader, straight forward just sample the sprite 113 | 114 | float4 frag (gs_out i ) : COLOR0 115 | { 116 | float4 col = tex2D(_Sprite, i.uv) * i.col; 117 | //col.w = 0.1f; 118 | //return i.col; 119 | return col; 120 | } 121 | 122 | ENDCG 123 | 124 | } 125 | } 126 | 127 | Fallback Off 128 | } -------------------------------------------------------------------------------- /Assets/Materials/Particles/GPUParticle.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b980bf1ad6a12b1459ec35dee1708878 3 | timeCreated: 1492919898 4 | licenseType: Free 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Materials/Particles/GPUParticleMaterial.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kristofe/UnityGPUMarchingCubes/db1b234e7ae3343b48dfd942ed9ca2798735acde/Assets/Materials/Particles/GPUParticleMaterial.mat -------------------------------------------------------------------------------- /Assets/Materials/Particles/GPUParticleMaterial.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 144f34431b7f89544aeec591b64daabd 3 | timeCreated: 1492919898 4 | licenseType: Free 5 | NativeFormatImporter: 6 | mainObjectFileID: -1 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Materials/ReferenceMaterial.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 77bbae528d15b6d4fb2147d3d7f12ba7 3 | folderAsset: yes 4 | timeCreated: 1492919896 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Materials/ReferenceMaterial/ExampleGeometryShader.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld' 2 | // Upgrade NOTE: replaced '_World2Object' with 'unity_WorldToObject' 3 | 4 | Shader "Custom/GeomShader-PassThrough" { 5 | Properties 6 | { 7 | _SpriteTex ("Base (RGB)", 2D) = "white" {} 8 | _Size ("Size", Range(0, 3)) = 0.5 9 | lightPos ("Light Position", Vector) = (1.0, 1.0, 1.0, 1.0) 10 | } 11 | 12 | SubShader 13 | { 14 | Pass 15 | { 16 | Tags { "RenderType"="Transparent" } 17 | LOD 200 18 | //ZWrite Off 19 | //Blend SrcAlpha One 20 | 21 | CGPROGRAM 22 | #pragma only_renderers d3d11 23 | #pragma target 4.0 24 | #pragma vertex VS_Main 25 | #pragma fragment FS_Main 26 | #pragma geometry GS_Main 27 | #include "UnityCG.cginc" 28 | 29 | // ************************************************************** 30 | // Data structures * 31 | // ************************************************************** 32 | struct GS_INPUT 33 | { 34 | float4 pos : POSITION; 35 | float3 normal : NORMAL; 36 | float2 tex0 : TEXCOORD0; 37 | }; 38 | 39 | struct FS_INPUT 40 | { 41 | float4 pos : POSITION; 42 | float3 normal : NORMAL; 43 | float2 tex0 : TEXCOORD0; 44 | }; 45 | 46 | 47 | // ************************************************************** 48 | // Vars * 49 | // ************************************************************** 50 | 51 | float _Size; 52 | float4 lightPos; 53 | float4x4 _VP; 54 | Texture2D _SpriteTex; 55 | SamplerState sampler_SpriteTex; 56 | 57 | // ************************************************************** 58 | // Shader Programs * 59 | // ************************************************************** 60 | 61 | // Vertex Shader ------------------------------------------------ 62 | GS_INPUT VS_Main(appdata_base v) 63 | { 64 | GS_INPUT output = (GS_INPUT)0; 65 | 66 | output.pos = mul(unity_ObjectToWorld, v.vertex); 67 | output.normal = v.normal; 68 | output.tex0 = v.texcoord; 69 | 70 | return output; 71 | } 72 | 73 | 74 | 75 | // Geometry Shader ----------------------------------------------------- 76 | [maxvertexcount(3)] 77 | void GS_Main(triangle GS_INPUT p[3], inout TriangleStream triStream) 78 | { 79 | float4x4 vp = mul(UNITY_MATRIX_MVP, unity_WorldToObject); 80 | FS_INPUT pIn; 81 | for(uint i= 0; i < 3; i++){ 82 | pIn.pos = mul(vp,p[i].pos); 83 | pIn.tex0 = p[i].tex0; 84 | pIn.normal = p[i].normal; 85 | triStream.Append(pIn); 86 | } 87 | triStream.RestartStrip(); 88 | } 89 | 90 | 91 | 92 | // Fragment Shader ----------------------------------------------- 93 | float4 FS_Main(FS_INPUT input) : COLOR 94 | { 95 | float3 N = input.normal; 96 | float3 L = normalize(lightPos - input.pos); 97 | float4 diffuseLight = max(dot(N,L),0); 98 | return _SpriteTex.Sample(sampler_SpriteTex, input.tex0) * diffuseLight; 99 | } 100 | 101 | ENDCG 102 | } 103 | } 104 | } 105 | 106 | -------------------------------------------------------------------------------- /Assets/Materials/ReferenceMaterial/ExampleGeometryShader.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d629ac2aeb6bdbe44832defcabef2615 3 | timeCreated: 1492919898 4 | licenseType: Free 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Materials/ReferenceMaterial/MarchingCubes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c744b946d37c50f48b2ba1a852b7ad9b 3 | folderAsset: yes 4 | timeCreated: 1492919896 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Materials/ReferenceMaterial/MarchingCubes/ExperimentalShader.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld' 2 | // Upgrade NOTE: replaced '_World2Object' with 'unity_WorldToObject' 3 | 4 | Shader "Custom/Experimental" { 5 | Properties { 6 | _Color("Color", Color) = (1,1,1,1) 7 | } 8 | SubShader { 9 | Tags { "RenderType"="Opaque" } 10 | LOD 200 11 | 12 | Pass { 13 | CGPROGRAM 14 | #pragma target 5.0 15 | #pragma only_renderers d3d11 16 | #pragma vertex vert 17 | #pragma fragment frag 18 | #include "UnityCG.cginc" 19 | #include "Lighting.cginc" 20 | 21 | float4 _Color; 22 | 23 | struct VS_INPUT { 24 | float4 pos : POSITION; 25 | float3 norm : NORMAL; 26 | }; 27 | 28 | struct VS_OUTPUT { 29 | float4 pos : POSITION; 30 | float4 posWorld : TEXCOORD0; 31 | float3 norm : TEXCOORD1; 32 | }; 33 | 34 | VS_OUTPUT vert(VS_INPUT v) { 35 | VS_OUTPUT o; 36 | 37 | float4x4 modelMatrix = unity_ObjectToWorld; 38 | float4x4 modelMatrixInverse = unity_WorldToObject; 39 | 40 | o.norm = normalize( mul( float4(v.norm,1.0), modelMatrixInverse).xyz); 41 | o.posWorld = mul(modelMatrix,v.pos); 42 | o.pos = mul(UNITY_MATRIX_MVP,v.pos); 43 | 44 | return o; 45 | } 46 | 47 | float4 frag(VS_OUTPUT i) : COLOR { 48 | //assuming directional light for now 49 | float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz); 50 | float d = saturate(dot(lightDirection, i.norm)); 51 | return float4(abs(i.norm),1);//_Color * d; 52 | } 53 | 54 | ENDCG 55 | } 56 | } 57 | FallBack "Diffuse" 58 | } 59 | -------------------------------------------------------------------------------- /Assets/Materials/ReferenceMaterial/MarchingCubes/ExperimentalShader.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 32b37f63b7edd9247a1310b76876af56 3 | timeCreated: 1492919898 4 | licenseType: Free 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Materials/ReferenceMaterial/MarchingCubes/MarchingCubesGPU.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld' 2 | 3 | Shader "Custom/GSMarchingCubes" 4 | { 5 | Properties 6 | { 7 | _SpriteTex ("Base (RGB)", 2D) = "white" {} 8 | _dataFieldTex ("Data Field Texture", 3D) = "white"{} 9 | _dataSize ("Data Field Texture Size", float) = 64 10 | _meshSize ("Mesh Cube Size", float) = 32 11 | _isoLevel ("isoLevel", Range(0.0, 0.5)) = 0.25 12 | } 13 | 14 | SubShader 15 | { 16 | Pass 17 | { 18 | Cull Off 19 | Tags { "RenderType"="Opaque" } 20 | LOD 200 21 | 22 | CGPROGRAM 23 | #pragma target 5.0 24 | #pragma debug 25 | #pragma vertex VS_Main 26 | #pragma fragment FS_Main 27 | #pragma geometry GS_Main 28 | #include "UnityCG.cginc" 29 | #include "Lighting.cginc" 30 | 31 | #define F3 1.0/3.0 32 | #define G3 1.0/6.0 33 | 34 | 35 | // ************************************************************** 36 | // Data structures * 37 | // ************************************************************** 38 | struct GS_INPUT 39 | { 40 | float4 pos : POSITION; 41 | float3 normal : NORMAL; 42 | float2 tex0 : TEXCOORD0; 43 | }; 44 | 45 | struct FS_INPUT 46 | { 47 | float4 pos : POSITION; 48 | float2 tex0 : TEXCOORD0; 49 | float3 normal : NORMAL; 50 | float3 tex3D : TEXCOORD1; 51 | }; 52 | 53 | 54 | // ************************************************************** 55 | // Vars * 56 | // ************************************************************** 57 | 58 | float _isoLevel; 59 | sampler3D _dataFieldTex; 60 | float4x4 _VP; 61 | Texture2D _SpriteTex; 62 | SamplerState sampler_SpriteTex; 63 | float _dataSize; 64 | float _meshSize; 65 | 66 | // ************************************************************** 67 | // Shader Programs * 68 | // ************************************************************** 69 | 70 | // Vertex Shader ------------------------------------------------ 71 | GS_INPUT VS_Main(appdata_base v) 72 | { 73 | GS_INPUT output = (GS_INPUT)0; 74 | 75 | output.pos = v.vertex; 76 | output.normal = v.normal; 77 | output.tex0 = float2(0, 0); 78 | 79 | return output; 80 | } 81 | 82 | 83 | float SampleData( float4 pPosition ){ 84 | //float3 sampleloc = pPosition.xyz - float3(0.5,0.5,0.5); 85 | //return sqrt(dot(sampleloc,sampleloc)); 86 | return tex3Dlod(_dataFieldTex,float4(pPosition.xyz,0)).x; 87 | } 88 | 89 | float SampleData3( float3 p){ 90 | //float3 sampleloc = p - float3(0.5,0.5,0.5); 91 | //return sqrt(dot(sampleloc,sampleloc)); 92 | return tex3Dlod(_dataFieldTex,float4(p.xyz,0)).x; 93 | } 94 | 95 | // Geometry Shader ----------------------------------------------------- 96 | [maxvertexcount(15)] 97 | void GS_Main(point GS_INPUT p[1], inout TriangleStream triStream) { 98 | /* 99 | const float size = 1.0/32.0; 100 | const float4 cubeVerts[8] = { 101 | //front face 102 | float4(0, 0, 0, 0) , //LB 0 103 | float4(0, size, 0, 0) , //LT 1 104 | float4( size, size, 0, 0) , //RT 2 105 | float4( size, 0, 0, 0) , //RB 3 106 | //bac0 107 | float4(0, 0, size, 0), // LB 4 108 | float4(0, size, size, 0), // LT 5 109 | float4( size, size, size, 0), // RT 6 110 | float4( size, 0, size, 0) // RB 7 111 | }; 112 | */ 113 | 114 | const float halfSize = 0.5/_meshSize; 115 | const float4 cubeVerts[8] = { 116 | //front face 117 | float4(-halfSize, -halfSize, -halfSize, 0) , //LB 0 118 | float4(-halfSize, halfSize, -halfSize, 0) , //LT 1 119 | float4( halfSize, halfSize, -halfSize, 0) , //RT 2 120 | float4( halfSize, -halfSize, -halfSize, 0) , //RB 3 121 | //bac0 122 | float4(-halfSize, -halfSize, halfSize, 0), // LB 4 123 | float4(-halfSize, halfSize, halfSize, 0), // LT 5 124 | float4( halfSize, halfSize, halfSize, 0), // RT 6 125 | float4( halfSize, -halfSize, halfSize, 0) // RB 7 126 | }; 127 | 128 | float4 offset = float4(0.5,0.5,0.5,0.0);//Move cube pos from 0-1 to -0.5-0.5 129 | //float4 offset = float4(0.0,0.0,0.0,0.0);//Move cube pos from 0-1 to -0.5-0.5 130 | const float weights[8] = { 131 | SampleData(p[0].pos + cubeVerts[0] + offset), 132 | SampleData(p[0].pos + cubeVerts[1] + offset), 133 | SampleData(p[0].pos + cubeVerts[2] + offset), 134 | SampleData(p[0].pos + cubeVerts[3] + offset), 135 | SampleData(p[0].pos + cubeVerts[4] + offset), 136 | SampleData(p[0].pos + cubeVerts[5] + offset), 137 | SampleData(p[0].pos + cubeVerts[6] + offset), 138 | SampleData(p[0].pos + cubeVerts[7] + offset) 139 | }; 140 | 141 | int cubeIndex = 142 | (weights[7] < _isoLevel) * 128 + 143 | (weights[6] < _isoLevel) * 64 + 144 | (weights[5] < _isoLevel) * 32 + 145 | (weights[4] < _isoLevel) * 16 + 146 | (weights[3] < _isoLevel) * 8 + 147 | (weights[2] < _isoLevel) * 4 + 148 | (weights[1] < _isoLevel) * 2 + 149 | (weights[0] < _isoLevel) * 1; 150 | 151 | const int2 edge_to_verts[12] = { 152 | int2(0,1), //0 153 | int2(1,2), //1 154 | int2(2,3), //2 155 | int2(3,0), //3 156 | int2(4,5), //4 157 | int2(5,6), //5 158 | int2(6,7), //6 159 | int2(7,4), //7 160 | int2(0,4), //8 161 | int2(1,5), //9 162 | int2(2,6), //10 163 | int2(3,7) //11 164 | }; 165 | /* 166 | const int case_to_numpolys[256] = { 167 | 0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,2,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,3, 168 | 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,3,2,3,3,2,3,4,4,3,3,4,4,3,4,5,5,2, 169 | 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,3,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,4, 170 | 2,3,3,4,3,4,2,3,3,4,4,5,4,5,3,2,3,4,4,3,4,5,3,2,4,5,5,4,5,2,4,1, 171 | 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,3,2,3,3,4,3,4,4,5,3,2,4,3,4,3,5,2, 172 | 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,4,3,4,4,3,4,5,5,4,4,3,5,2,5,4,2,1, 173 | 2,3,3,4,3,4,4,5,3,4,4,5,2,3,3,2,3,4,4,5,4,5,5,2,4,3,5,4,3,2,4,1, 174 | 3,4,4,5,4,5,3,4,4,5,5,2,3,4,2,1,2,3,3,2,3,4,2,1,3,2,4,1,2,1,1,0 175 | }; 176 | */ 177 | 178 | // 256*5 = 1280 entries 179 | const int4 edge_connect_list[1280] = { 180 | int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 181 | int4(0, 8, 3, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 182 | int4(0, 1, 9, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 183 | int4(1, 8, 3, -1), int4(9, 8, 1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 184 | int4(1, 2, 10, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 185 | int4(0, 8, 3, -1), int4(1, 2, 10, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 186 | int4(9, 2, 10, -1), int4(0, 2, 9, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 187 | int4(2, 8, 3, -1), int4(2, 10, 8, -1), int4(10, 9, 8, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 188 | int4(3, 11, 2, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 189 | int4(0, 11, 2, -1), int4(8, 11, 0, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 190 | int4(1, 9, 0, -1), int4(2, 3, 11, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 191 | int4(1, 11, 2, -1), int4(1, 9, 11, -1), int4(9, 8, 11, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 192 | int4(3, 10, 1, -1), int4(11, 10, 3, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 193 | int4(0, 10, 1, -1), int4(0, 8, 10, -1), int4(8, 11, 10, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 194 | int4(3, 9, 0, -1), int4(3, 11, 9, -1), int4(11, 10, 9, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 195 | int4(9, 8, 10, -1), int4(10, 8, 11, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 196 | int4(4, 7, 8, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 197 | int4(4, 3, 0, -1), int4(7, 3, 4, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 198 | int4(0, 1, 9, -1), int4(8, 4, 7, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 199 | int4(4, 1, 9, -1), int4(4, 7, 1, -1), int4(7, 3, 1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 200 | int4(1, 2, 10, -1), int4(8, 4, 7, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 201 | int4(3, 4, 7, -1), int4(3, 0, 4, -1), int4(1, 2, 10, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 202 | int4(9, 2, 10, -1), int4(9, 0, 2, -1), int4(8, 4, 7, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 203 | int4(2, 10, 9, -1), int4(2, 9, 7, -1), int4(2, 7, 3, -1), int4(7, 9, 4, -1), int4(-1, -1, -1, -1), 204 | int4(8, 4, 7, -1), int4(3, 11, 2, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 205 | int4(11, 4, 7, -1), int4(11, 2, 4, -1), int4(2, 0, 4, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 206 | int4(9, 0, 1, -1), int4(8, 4, 7, -1), int4(2, 3, 11, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 207 | int4(4, 7, 11, -1), int4(9, 4, 11, -1), int4(9, 11, 2, -1), int4(9, 2, 1, -1), int4(-1, -1, -1, -1), 208 | int4(3, 10, 1, -1), int4(3, 11, 10, -1), int4(7, 8, 4, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 209 | int4(1, 11, 10, -1), int4(1, 4, 11, -1), int4(1, 0, 4, -1), int4(7, 11, 4, -1), int4(-1, -1, -1, -1), 210 | int4(4, 7, 8, -1), int4(9, 0, 11, -1), int4(9, 11, 10, -1), int4(11, 0, 3, -1), int4(-1, -1, -1, -1), 211 | int4(4, 7, 11, -1), int4(4, 11, 9, -1), int4(9, 11, 10, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 212 | int4(9, 5, 4, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 213 | int4(9, 5, 4, -1), int4(0, 8, 3, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 214 | int4(0, 5, 4, -1), int4(1, 5, 0, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 215 | int4(8, 5, 4, -1), int4(8, 3, 5, -1), int4(3, 1, 5, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 216 | int4(1, 2, 10, -1), int4(9, 5, 4, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 217 | int4(3, 0, 8, -1), int4(1, 2, 10, -1), int4(4, 9, 5, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 218 | int4(5, 2, 10, -1), int4(5, 4, 2, -1), int4(4, 0, 2, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 219 | int4(2, 10, 5, -1), int4(3, 2, 5, -1), int4(3, 5, 4, -1), int4(3, 4, 8, -1), int4(-1, -1, -1, -1), 220 | int4(9, 5, 4, -1), int4(2, 3, 11, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 221 | int4(0, 11, 2, -1), int4(0, 8, 11, -1), int4(4, 9, 5, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 222 | int4(0, 5, 4, -1), int4(0, 1, 5, -1), int4(2, 3, 11, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 223 | int4(2, 1, 5, -1), int4(2, 5, 8, -1), int4(2, 8, 11, -1), int4(4, 8, 5, -1), int4(-1, -1, -1, -1), 224 | int4(10, 3, 11, -1), int4(10, 1, 3, -1), int4(9, 5, 4, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 225 | int4(4, 9, 5, -1), int4(0, 8, 1, -1), int4(8, 10, 1, -1), int4(8, 11, 10, -1), int4(-1, -1, -1, -1), 226 | int4(5, 4, 0, -1), int4(5, 0, 11, -1), int4(5, 11, 10, -1), int4(11, 0, 3, -1), int4(-1, -1, -1, -1), 227 | int4(5, 4, 8, -1), int4(5, 8, 10, -1), int4(10, 8, 11, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 228 | int4(9, 7, 8, -1), int4(5, 7, 9, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 229 | int4(9, 3, 0, -1), int4(9, 5, 3, -1), int4(5, 7, 3, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 230 | int4(0, 7, 8, -1), int4(0, 1, 7, -1), int4(1, 5, 7, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 231 | int4(1, 5, 3, -1), int4(3, 5, 7, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 232 | int4(9, 7, 8, -1), int4(9, 5, 7, -1), int4(10, 1, 2, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 233 | int4(10, 1, 2, -1), int4(9, 5, 0, -1), int4(5, 3, 0, -1), int4(5, 7, 3, -1), int4(-1, -1, -1, -1), 234 | int4(8, 0, 2, -1), int4(8, 2, 5, -1), int4(8, 5, 7, -1), int4(10, 5, 2, -1), int4(-1, -1, -1, -1), 235 | int4(2, 10, 5, -1), int4(2, 5, 3, -1), int4(3, 5, 7, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 236 | int4(7, 9, 5, -1), int4(7, 8, 9, -1), int4(3, 11, 2, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 237 | int4(9, 5, 7, -1), int4(9, 7, 2, -1), int4(9, 2, 0, -1), int4(2, 7, 11, -1), int4(-1, -1, -1, -1), 238 | int4(2, 3, 11, -1), int4(0, 1, 8, -1), int4(1, 7, 8, -1), int4(1, 5, 7, -1), int4(-1, -1, -1, -1), 239 | int4(11, 2, 1, -1), int4(11, 1, 7, -1), int4(7, 1, 5, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 240 | int4(9, 5, 8, -1), int4(8, 5, 7, -1), int4(10, 1, 3, -1), int4(10, 3, 11, -1), int4(-1, -1, -1, -1), 241 | int4(5, 7, 0, -1), int4(5, 0, 9, -1), int4(7, 11, 0, -1), int4(1, 0, 10, -1), int4(11, 10, 0, -1), 242 | int4(11, 10, 0, -1), int4(11, 0, 3, -1), int4(10, 5, 0, -1), int4(8, 0, 7, -1), int4(5, 7, 0, -1), 243 | int4(11, 10, 5, -1), int4(7, 11, 5, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 244 | int4(10, 6, 5, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 245 | int4(0, 8, 3, -1), int4(5, 10, 6, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 246 | int4(9, 0, 1, -1), int4(5, 10, 6, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 247 | int4(1, 8, 3, -1), int4(1, 9, 8, -1), int4(5, 10, 6, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 248 | int4(1, 6, 5, -1), int4(2, 6, 1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 249 | int4(1, 6, 5, -1), int4(1, 2, 6, -1), int4(3, 0, 8, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 250 | int4(9, 6, 5, -1), int4(9, 0, 6, -1), int4(0, 2, 6, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 251 | int4(5, 9, 8, -1), int4(5, 8, 2, -1), int4(5, 2, 6, -1), int4(3, 2, 8, -1), int4(-1, -1, -1, -1), 252 | int4(2, 3, 11, -1), int4(10, 6, 5, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 253 | int4(11, 0, 8, -1), int4(11, 2, 0, -1), int4(10, 6, 5, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 254 | int4(0, 1, 9, -1), int4(2, 3, 11, -1), int4(5, 10, 6, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 255 | int4(5, 10, 6, -1), int4(1, 9, 2, -1), int4(9, 11, 2, -1), int4(9, 8, 11, -1), int4(-1, -1, -1, -1), 256 | int4(6, 3, 11, -1), int4(6, 5, 3, -1), int4(5, 1, 3, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 257 | int4(0, 8, 11, -1), int4(0, 11, 5, -1), int4(0, 5, 1, -1), int4(5, 11, 6, -1), int4(-1, -1, -1, -1), 258 | int4(3, 11, 6, -1), int4(0, 3, 6, -1), int4(0, 6, 5, -1), int4(0, 5, 9, -1), int4(-1, -1, -1, -1), 259 | int4(6, 5, 9, -1), int4(6, 9, 11, -1), int4(11, 9, 8, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 260 | int4(5, 10, 6, -1), int4(4, 7, 8, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 261 | int4(4, 3, 0, -1), int4(4, 7, 3, -1), int4(6, 5, 10, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 262 | int4(1, 9, 0, -1), int4(5, 10, 6, -1), int4(8, 4, 7, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 263 | int4(10, 6, 5, -1), int4(1, 9, 7, -1), int4(1, 7, 3, -1), int4(7, 9, 4, -1), int4(-1, -1, -1, -1), 264 | int4(6, 1, 2, -1), int4(6, 5, 1, -1), int4(4, 7, 8, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 265 | int4(1, 2, 5, -1), int4(5, 2, 6, -1), int4(3, 0, 4, -1), int4(3, 4, 7, -1), int4(-1, -1, -1, -1), 266 | int4(8, 4, 7, -1), int4(9, 0, 5, -1), int4(0, 6, 5, -1), int4(0, 2, 6, -1), int4(-1, -1, -1, -1), 267 | int4(7, 3, 9, -1), int4(7, 9, 4, -1), int4(3, 2, 9, -1), int4(5, 9, 6, -1), int4(2, 6, 9, -1), 268 | int4(3, 11, 2, -1), int4(7, 8, 4, -1), int4(10, 6, 5, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 269 | int4(5, 10, 6, -1), int4(4, 7, 2, -1), int4(4, 2, 0, -1), int4(2, 7, 11, -1), int4(-1, -1, -1, -1), 270 | int4(0, 1, 9, -1), int4(4, 7, 8, -1), int4(2, 3, 11, -1), int4(5, 10, 6, -1), int4(-1, -1, -1, -1), 271 | int4(9, 2, 1, -1), int4(9, 11, 2, -1), int4(9, 4, 11, -1), int4(7, 11, 4, -1), int4(5, 10, 6, -1), 272 | int4(8, 4, 7, -1), int4(3, 11, 5, -1), int4(3, 5, 1, -1), int4(5, 11, 6, -1), int4(-1, -1, -1, -1), 273 | int4(5, 1, 11, -1), int4(5, 11, 6, -1), int4(1, 0, 11, -1), int4(7, 11, 4, -1), int4(0, 4, 11, -1), 274 | int4(0, 5, 9, -1), int4(0, 6, 5, -1), int4(0, 3, 6, -1), int4(11, 6, 3, -1), int4(8, 4, 7, -1), 275 | int4(6, 5, 9, -1), int4(6, 9, 11, -1), int4(4, 7, 9, -1), int4(7, 11, 9, -1), int4(-1, -1, -1, -1), 276 | int4(10, 4, 9, -1), int4(6, 4, 10, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 277 | int4(4, 10, 6, -1), int4(4, 9, 10, -1), int4(0, 8, 3, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 278 | int4(10, 0, 1, -1), int4(10, 6, 0, -1), int4(6, 4, 0, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 279 | int4(8, 3, 1, -1), int4(8, 1, 6, -1), int4(8, 6, 4, -1), int4(6, 1, 10, -1), int4(-1, -1, -1, -1), 280 | int4(1, 4, 9, -1), int4(1, 2, 4, -1), int4(2, 6, 4, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 281 | int4(3, 0, 8, -1), int4(1, 2, 9, -1), int4(2, 4, 9, -1), int4(2, 6, 4, -1), int4(-1, -1, -1, -1), 282 | int4(0, 2, 4, -1), int4(4, 2, 6, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 283 | int4(8, 3, 2, -1), int4(8, 2, 4, -1), int4(4, 2, 6, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 284 | int4(10, 4, 9, -1), int4(10, 6, 4, -1), int4(11, 2, 3, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 285 | int4(0, 8, 2, -1), int4(2, 8, 11, -1), int4(4, 9, 10, -1), int4(4, 10, 6, -1), int4(-1, -1, -1, -1), 286 | int4(3, 11, 2, -1), int4(0, 1, 6, -1), int4(0, 6, 4, -1), int4(6, 1, 10, -1), int4(-1, -1, -1, -1), 287 | int4(6, 4, 1, -1), int4(6, 1, 10, -1), int4(4, 8, 1, -1), int4(2, 1, 11, -1), int4(8, 11, 1, -1), 288 | int4(9, 6, 4, -1), int4(9, 3, 6, -1), int4(9, 1, 3, -1), int4(11, 6, 3, -1), int4(-1, -1, -1, -1), 289 | int4(8, 11, 1, -1), int4(8, 1, 0, -1), int4(11, 6, 1, -1), int4(9, 1, 4, -1), int4(6, 4, 1, -1), 290 | int4(3, 11, 6, -1), int4(3, 6, 0, -1), int4(0, 6, 4, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 291 | int4(6, 4, 8, -1), int4(11, 6, 8, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 292 | int4(7, 10, 6, -1), int4(7, 8, 10, -1), int4(8, 9, 10, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 293 | int4(0, 7, 3, -1), int4(0, 10, 7, -1), int4(0, 9, 10, -1), int4(6, 7, 10, -1), int4(-1, -1, -1, -1), 294 | int4(10, 6, 7, -1), int4(1, 10, 7, -1), int4(1, 7, 8, -1), int4(1, 8, 0, -1), int4(-1, -1, -1, -1), 295 | int4(10, 6, 7, -1), int4(10, 7, 1, -1), int4(1, 7, 3, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 296 | int4(1, 2, 6, -1), int4(1, 6, 8, -1), int4(1, 8, 9, -1), int4(8, 6, 7, -1), int4(-1, -1, -1, -1), 297 | int4(2, 6, 9, -1), int4(2, 9, 1, -1), int4(6, 7, 9, -1), int4(0, 9, 3, -1), int4(7, 3, 9, -1), 298 | int4(7, 8, 0, -1), int4(7, 0, 6, -1), int4(6, 0, 2, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 299 | int4(7, 3, 2, -1), int4(6, 7, 2, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 300 | int4(2, 3, 11, -1), int4(10, 6, 8, -1), int4(10, 8, 9, -1), int4(8, 6, 7, -1), int4(-1, -1, -1, -1), 301 | int4(2, 0, 7, -1), int4(2, 7, 11, -1), int4(0, 9, 7, -1), int4(6, 7, 10, -1), int4(9, 10, 7, -1), 302 | int4(1, 8, 0, -1), int4(1, 7, 8, -1), int4(1, 10, 7, -1), int4(6, 7, 10, -1), int4(2, 3, 11, -1), 303 | int4(11, 2, 1, -1), int4(11, 1, 7, -1), int4(10, 6, 1, -1), int4(6, 7, 1, -1), int4(-1, -1, -1, -1), 304 | int4(8, 9, 6, -1), int4(8, 6, 7, -1), int4(9, 1, 6, -1), int4(11, 6, 3, -1), int4(1, 3, 6, -1), 305 | int4(0, 9, 1, -1), int4(11, 6, 7, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 306 | int4(7, 8, 0, -1), int4(7, 0, 6, -1), int4(3, 11, 0, -1), int4(11, 6, 0, -1), int4(-1, -1, -1, -1), 307 | int4(7, 11, 6, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 308 | int4(7, 6, 11, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 309 | int4(3, 0, 8, -1), int4(11, 7, 6, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 310 | int4(0, 1, 9, -1), int4(11, 7, 6, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 311 | int4(8, 1, 9, -1), int4(8, 3, 1, -1), int4(11, 7, 6, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 312 | int4(10, 1, 2, -1), int4(6, 11, 7, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 313 | int4(1, 2, 10, -1), int4(3, 0, 8, -1), int4(6, 11, 7, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 314 | int4(2, 9, 0, -1), int4(2, 10, 9, -1), int4(6, 11, 7, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 315 | int4(6, 11, 7, -1), int4(2, 10, 3, -1), int4(10, 8, 3, -1), int4(10, 9, 8, -1), int4(-1, -1, -1, -1), 316 | int4(7, 2, 3, -1), int4(6, 2, 7, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 317 | int4(7, 0, 8, -1), int4(7, 6, 0, -1), int4(6, 2, 0, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 318 | int4(2, 7, 6, -1), int4(2, 3, 7, -1), int4(0, 1, 9, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 319 | int4(1, 6, 2, -1), int4(1, 8, 6, -1), int4(1, 9, 8, -1), int4(8, 7, 6, -1), int4(-1, -1, -1, -1), 320 | int4(10, 7, 6, -1), int4(10, 1, 7, -1), int4(1, 3, 7, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 321 | int4(10, 7, 6, -1), int4(1, 7, 10, -1), int4(1, 8, 7, -1), int4(1, 0, 8, -1), int4(-1, -1, -1, -1), 322 | int4(0, 3, 7, -1), int4(0, 7, 10, -1), int4(0, 10, 9, -1), int4(6, 10, 7, -1), int4(-1, -1, -1, -1), 323 | int4(7, 6, 10, -1), int4(7, 10, 8, -1), int4(8, 10, 9, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 324 | int4(6, 8, 4, -1), int4(11, 8, 6, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 325 | int4(3, 6, 11, -1), int4(3, 0, 6, -1), int4(0, 4, 6, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 326 | int4(8, 6, 11, -1), int4(8, 4, 6, -1), int4(9, 0, 1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 327 | int4(9, 4, 6, -1), int4(9, 6, 3, -1), int4(9, 3, 1, -1), int4(11, 3, 6, -1), int4(-1, -1, -1, -1), 328 | int4(6, 8, 4, -1), int4(6, 11, 8, -1), int4(2, 10, 1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 329 | int4(1, 2, 10, -1), int4(3, 0, 11, -1), int4(0, 6, 11, -1), int4(0, 4, 6, -1), int4(-1, -1, -1, -1), 330 | int4(4, 11, 8, -1), int4(4, 6, 11, -1), int4(0, 2, 9, -1), int4(2, 10, 9, -1), int4(-1, -1, -1, -1), 331 | int4(10, 9, 3, -1), int4(10, 3, 2, -1), int4(9, 4, 3, -1), int4(11, 3, 6, -1), int4(4, 6, 3, -1), 332 | int4(8, 2, 3, -1), int4(8, 4, 2, -1), int4(4, 6, 2, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 333 | int4(0, 4, 2, -1), int4(4, 6, 2, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 334 | int4(1, 9, 0, -1), int4(2, 3, 4, -1), int4(2, 4, 6, -1), int4(4, 3, 8, -1), int4(-1, -1, -1, -1), 335 | int4(1, 9, 4, -1), int4(1, 4, 2, -1), int4(2, 4, 6, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 336 | int4(8, 1, 3, -1), int4(8, 6, 1, -1), int4(8, 4, 6, -1), int4(6, 10, 1, -1), int4(-1, -1, -1, -1), 337 | int4(10, 1, 0, -1), int4(10, 0, 6, -1), int4(6, 0, 4, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 338 | int4(4, 6, 3, -1), int4(4, 3, 8, -1), int4(6, 10, 3, -1), int4(0, 3, 9, -1), int4(10, 9, 3, -1), 339 | int4(10, 9, 4, -1), int4(6, 10, 4, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 340 | int4(4, 9, 5, -1), int4(7, 6, 11, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 341 | int4(0, 8, 3, -1), int4(4, 9, 5, -1), int4(11, 7, 6, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 342 | int4(5, 0, 1, -1), int4(5, 4, 0, -1), int4(7, 6, 11, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 343 | int4(11, 7, 6, -1), int4(8, 3, 4, -1), int4(3, 5, 4, -1), int4(3, 1, 5, -1), int4(-1, -1, -1, -1), 344 | int4(9, 5, 4, -1), int4(10, 1, 2, -1), int4(7, 6, 11, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 345 | int4(6, 11, 7, -1), int4(1, 2, 10, -1), int4(0, 8, 3, -1), int4(4, 9, 5, -1), int4(-1, -1, -1, -1), 346 | int4(7, 6, 11, -1), int4(5, 4, 10, -1), int4(4, 2, 10, -1), int4(4, 0, 2, -1), int4(-1, -1, -1, -1), 347 | int4(3, 4, 8, -1), int4(3, 5, 4, -1), int4(3, 2, 5, -1), int4(10, 5, 2, -1), int4(11, 7, 6, -1), 348 | int4(7, 2, 3, -1), int4(7, 6, 2, -1), int4(5, 4, 9, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 349 | int4(9, 5, 4, -1), int4(0, 8, 6, -1), int4(0, 6, 2, -1), int4(6, 8, 7, -1), int4(-1, -1, -1, -1), 350 | int4(3, 6, 2, -1), int4(3, 7, 6, -1), int4(1, 5, 0, -1), int4(5, 4, 0, -1), int4(-1, -1, -1, -1), 351 | int4(6, 2, 8, -1), int4(6, 8, 7, -1), int4(2, 1, 8, -1), int4(4, 8, 5, -1), int4(1, 5, 8, -1), 352 | int4(9, 5, 4, -1), int4(10, 1, 6, -1), int4(1, 7, 6, -1), int4(1, 3, 7, -1), int4(-1, -1, -1, -1), 353 | int4(1, 6, 10, -1), int4(1, 7, 6, -1), int4(1, 0, 7, -1), int4(8, 7, 0, -1), int4(9, 5, 4, -1), 354 | int4(4, 0, 10, -1), int4(4, 10, 5, -1), int4(0, 3, 10, -1), int4(6, 10, 7, -1), int4(3, 7, 10, -1), 355 | int4(7, 6, 10, -1), int4(7, 10, 8, -1), int4(5, 4, 10, -1), int4(4, 8, 10, -1), int4(-1, -1, -1, -1), 356 | int4(6, 9, 5, -1), int4(6, 11, 9, -1), int4(11, 8, 9, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 357 | int4(3, 6, 11, -1), int4(0, 6, 3, -1), int4(0, 5, 6, -1), int4(0, 9, 5, -1), int4(-1, -1, -1, -1), 358 | int4(0, 11, 8, -1), int4(0, 5, 11, -1), int4(0, 1, 5, -1), int4(5, 6, 11, -1), int4(-1, -1, -1, -1), 359 | int4(6, 11, 3, -1), int4(6, 3, 5, -1), int4(5, 3, 1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 360 | int4(1, 2, 10, -1), int4(9, 5, 11, -1), int4(9, 11, 8, -1), int4(11, 5, 6, -1), int4(-1, -1, -1, -1), 361 | int4(0, 11, 3, -1), int4(0, 6, 11, -1), int4(0, 9, 6, -1), int4(5, 6, 9, -1), int4(1, 2, 10, -1), 362 | int4(11, 8, 5, -1), int4(11, 5, 6, -1), int4(8, 0, 5, -1), int4(10, 5, 2, -1), int4(0, 2, 5, -1), 363 | int4(6, 11, 3, -1), int4(6, 3, 5, -1), int4(2, 10, 3, -1), int4(10, 5, 3, -1), int4(-1, -1, -1, -1), 364 | int4(5, 8, 9, -1), int4(5, 2, 8, -1), int4(5, 6, 2, -1), int4(3, 8, 2, -1), int4(-1, -1, -1, -1), 365 | int4(9, 5, 6, -1), int4(9, 6, 0, -1), int4(0, 6, 2, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 366 | int4(1, 5, 8, -1), int4(1, 8, 0, -1), int4(5, 6, 8, -1), int4(3, 8, 2, -1), int4(6, 2, 8, -1), 367 | int4(1, 5, 6, -1), int4(2, 1, 6, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 368 | int4(1, 3, 6, -1), int4(1, 6, 10, -1), int4(3, 8, 6, -1), int4(5, 6, 9, -1), int4(8, 9, 6, -1), 369 | int4(10, 1, 0, -1), int4(10, 0, 6, -1), int4(9, 5, 0, -1), int4(5, 6, 0, -1), int4(-1, -1, -1, -1), 370 | int4(0, 3, 8, -1), int4(5, 6, 10, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 371 | int4(10, 5, 6, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 372 | int4(11, 5, 10, -1), int4(7, 5, 11, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 373 | int4(11, 5, 10, -1), int4(11, 7, 5, -1), int4(8, 3, 0, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 374 | int4(5, 11, 7, -1), int4(5, 10, 11, -1), int4(1, 9, 0, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 375 | int4(10, 7, 5, -1), int4(10, 11, 7, -1), int4(9, 8, 1, -1), int4(8, 3, 1, -1), int4(-1, -1, -1, -1), 376 | int4(11, 1, 2, -1), int4(11, 7, 1, -1), int4(7, 5, 1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 377 | int4(0, 8, 3, -1), int4(1, 2, 7, -1), int4(1, 7, 5, -1), int4(7, 2, 11, -1), int4(-1, -1, -1, -1), 378 | int4(9, 7, 5, -1), int4(9, 2, 7, -1), int4(9, 0, 2, -1), int4(2, 11, 7, -1), int4(-1, -1, -1, -1), 379 | int4(7, 5, 2, -1), int4(7, 2, 11, -1), int4(5, 9, 2, -1), int4(3, 2, 8, -1), int4(9, 8, 2, -1), 380 | int4(2, 5, 10, -1), int4(2, 3, 5, -1), int4(3, 7, 5, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 381 | int4(8, 2, 0, -1), int4(8, 5, 2, -1), int4(8, 7, 5, -1), int4(10, 2, 5, -1), int4(-1, -1, -1, -1), 382 | int4(9, 0, 1, -1), int4(5, 10, 3, -1), int4(5, 3, 7, -1), int4(3, 10, 2, -1), int4(-1, -1, -1, -1), 383 | int4(9, 8, 2, -1), int4(9, 2, 1, -1), int4(8, 7, 2, -1), int4(10, 2, 5, -1), int4(7, 5, 2, -1), 384 | int4(1, 3, 5, -1), int4(3, 7, 5, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 385 | int4(0, 8, 7, -1), int4(0, 7, 1, -1), int4(1, 7, 5, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 386 | int4(9, 0, 3, -1), int4(9, 3, 5, -1), int4(5, 3, 7, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 387 | int4(9, 8, 7, -1), int4(5, 9, 7, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 388 | int4(5, 8, 4, -1), int4(5, 10, 8, -1), int4(10, 11, 8, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 389 | int4(5, 0, 4, -1), int4(5, 11, 0, -1), int4(5, 10, 11, -1), int4(11, 3, 0, -1), int4(-1, -1, -1, -1), 390 | int4(0, 1, 9, -1), int4(8, 4, 10, -1), int4(8, 10, 11, -1), int4(10, 4, 5, -1), int4(-1, -1, -1, -1), 391 | int4(10, 11, 4, -1), int4(10, 4, 5, -1), int4(11, 3, 4, -1), int4(9, 4, 1, -1), int4(3, 1, 4, -1), 392 | int4(2, 5, 1, -1), int4(2, 8, 5, -1), int4(2, 11, 8, -1), int4(4, 5, 8, -1), int4(-1, -1, -1, -1), 393 | int4(0, 4, 11, -1), int4(0, 11, 3, -1), int4(4, 5, 11, -1), int4(2, 11, 1, -1), int4(5, 1, 11, -1), 394 | int4(0, 2, 5, -1), int4(0, 5, 9, -1), int4(2, 11, 5, -1), int4(4, 5, 8, -1), int4(11, 8, 5, -1), 395 | int4(9, 4, 5, -1), int4(2, 11, 3, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 396 | int4(2, 5, 10, -1), int4(3, 5, 2, -1), int4(3, 4, 5, -1), int4(3, 8, 4, -1), int4(-1, -1, -1, -1), 397 | int4(5, 10, 2, -1), int4(5, 2, 4, -1), int4(4, 2, 0, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 398 | int4(3, 10, 2, -1), int4(3, 5, 10, -1), int4(3, 8, 5, -1), int4(4, 5, 8, -1), int4(0, 1, 9, -1), 399 | int4(5, 10, 2, -1), int4(5, 2, 4, -1), int4(1, 9, 2, -1), int4(9, 4, 2, -1), int4(-1, -1, -1, -1), 400 | int4(8, 4, 5, -1), int4(8, 5, 3, -1), int4(3, 5, 1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 401 | int4(0, 4, 5, -1), int4(1, 0, 5, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 402 | int4(8, 4, 5, -1), int4(8, 5, 3, -1), int4(9, 0, 5, -1), int4(0, 3, 5, -1), int4(-1, -1, -1, -1), 403 | int4(9, 4, 5, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 404 | int4(4, 11, 7, -1), int4(4, 9, 11, -1), int4(9, 10, 11, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 405 | int4(0, 8, 3, -1), int4(4, 9, 7, -1), int4(9, 11, 7, -1), int4(9, 10, 11, -1), int4(-1, -1, -1, -1), 406 | int4(1, 10, 11, -1), int4(1, 11, 4, -1), int4(1, 4, 0, -1), int4(7, 4, 11, -1), int4(-1, -1, -1, -1), 407 | int4(3, 1, 4, -1), int4(3, 4, 8, -1), int4(1, 10, 4, -1), int4(7, 4, 11, -1), int4(10, 11, 4, -1), 408 | int4(4, 11, 7, -1), int4(9, 11, 4, -1), int4(9, 2, 11, -1), int4(9, 1, 2, -1), int4(-1, -1, -1, -1), 409 | int4(9, 7, 4, -1), int4(9, 11, 7, -1), int4(9, 1, 11, -1), int4(2, 11, 1, -1), int4(0, 8, 3, -1), 410 | int4(11, 7, 4, -1), int4(11, 4, 2, -1), int4(2, 4, 0, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 411 | int4(11, 7, 4, -1), int4(11, 4, 2, -1), int4(8, 3, 4, -1), int4(3, 2, 4, -1), int4(-1, -1, -1, -1), 412 | int4(2, 9, 10, -1), int4(2, 7, 9, -1), int4(2, 3, 7, -1), int4(7, 4, 9, -1), int4(-1, -1, -1, -1), 413 | int4(9, 10, 7, -1), int4(9, 7, 4, -1), int4(10, 2, 7, -1), int4(8, 7, 0, -1), int4(2, 0, 7, -1), 414 | int4(3, 7, 10, -1), int4(3, 10, 2, -1), int4(7, 4, 10, -1), int4(1, 10, 0, -1), int4(4, 0, 10, -1), 415 | int4(1, 10, 2, -1), int4(8, 7, 4, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 416 | int4(4, 9, 1, -1), int4(4, 1, 7, -1), int4(7, 1, 3, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 417 | int4(4, 9, 1, -1), int4(4, 1, 7, -1), int4(0, 8, 1, -1), int4(8, 7, 1, -1), int4(-1, -1, -1, -1), 418 | int4(4, 0, 3, -1), int4(7, 4, 3, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 419 | int4(4, 8, 7, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 420 | int4(9, 10, 8, -1), int4(10, 11, 8, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 421 | int4(3, 0, 9, -1), int4(3, 9, 11, -1), int4(11, 9, 10, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 422 | int4(0, 1, 10, -1), int4(0, 10, 8, -1), int4(8, 10, 11, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 423 | int4(3, 1, 10, -1), int4(11, 3, 10, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 424 | int4(1, 2, 11, -1), int4(1, 11, 9, -1), int4(9, 11, 8, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 425 | int4(3, 0, 9, -1), int4(3, 9, 11, -1), int4(1, 2, 9, -1), int4(2, 11, 9, -1), int4(-1, -1, -1, -1), 426 | int4(0, 2, 11, -1), int4(8, 0, 11, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 427 | int4(3, 2, 11, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 428 | int4(2, 3, 8, -1), int4(2, 8, 10, -1), int4(10, 8, 9, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 429 | int4(9, 10, 2, -1), int4(0, 9, 2, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 430 | int4(2, 3, 8, -1), int4(2, 8, 10, -1), int4(0, 1, 8, -1), int4(1, 10, 8, -1), int4(-1, -1, -1, -1), 431 | int4(1, 10, 2, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 432 | int4(1, 3, 8, -1), int4(9, 1, 8, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 433 | int4(0, 9, 1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 434 | int4(0, 3, 8, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), 435 | int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1), int4(-1, -1, -1, -1) 436 | }; 437 | 438 | //int numpolys = case_to_numpolys[cubeIndex]; 439 | 440 | float4x4 vp = UNITY_MATRIX_MVP;//mul(UNITY_MATRIX_MVP, _World2Object); 441 | FS_INPUT pIn; 442 | for( int i = 0; i < 5; i++ ){ 443 | int4 vertlistIndices = edge_connect_list[cubeIndex * 5 + i]; 444 | if(vertlistIndices.x != -1) { 445 | int va = edge_to_verts[vertlistIndices.x].x; 446 | int vb = edge_to_verts[vertlistIndices.x].y; 447 | float amount = (_isoLevel - weights[va]) / (weights[vb] - weights[va]); 448 | float4 worldPos = lerp( p[0].pos + cubeVerts[va], p[0].pos + cubeVerts[vb], amount); 449 | float4 texA = worldPos+offset; 450 | float4 pA = mul(vp, worldPos); 451 | 452 | va = edge_to_verts[vertlistIndices.y].x; 453 | vb = edge_to_verts[vertlistIndices.y].y; 454 | amount = (_isoLevel - weights[va]) / (weights[vb] - weights[va]); 455 | worldPos = lerp( p[0].pos + cubeVerts[va], p[0].pos + cubeVerts[vb], amount); 456 | float4 texB = worldPos+offset; 457 | float4 pB = mul(vp, worldPos); 458 | 459 | va = edge_to_verts[vertlistIndices.z].x; 460 | vb = edge_to_verts[vertlistIndices.z].y; 461 | amount = (_isoLevel - weights[va]) / (weights[vb] - weights[va]); 462 | worldPos = lerp( p[0].pos + cubeVerts[va], p[0].pos + cubeVerts[vb], amount); 463 | float4 texC = worldPos+offset; 464 | float4 pC = mul(vp, worldPos); 465 | 466 | float4 r = pA - pC; 467 | float4 f = pA - pB; 468 | float3 normal = normalize(cross(f,r)); 469 | 470 | pIn.pos = pA; 471 | pIn.tex3D = texA; 472 | pIn.tex0 = float2(1.0f, 0.0f); 473 | pIn.normal = normal; 474 | triStream.Append(pIn); 475 | 476 | pIn.normal = normal; 477 | pIn.pos = pC; 478 | pIn.tex3D = texC; 479 | pIn.tex0 = float2(1.0f, 0.0f); 480 | triStream.Append(pIn); 481 | 482 | pIn.pos = pB; 483 | pIn.tex3D = texB; 484 | pIn.tex0 = float2(1.0f, 0.0f); 485 | pIn.normal = normal; 486 | triStream.Append(pIn); 487 | 488 | triStream.RestartStrip(); 489 | }else{ 490 | pIn.pos = float4(0,0,0,0);// + p[0].pos; 491 | pIn.tex0 = float2(1.0f, 0.0f); 492 | pIn.normal = float3(0,1,0); 493 | triStream.Append(pIn); 494 | triStream.Append(pIn); 495 | triStream.Append(pIn); 496 | triStream.RestartStrip(); 497 | } 498 | } 499 | 500 | } 501 | 502 | // Fragment Shader ----------------------------------------------- 503 | float4 FS_Main(FS_INPUT input) : COLOR 504 | { 505 | float dataStepSize = _dataSize; 506 | float h2 = dataStepSize*2.0; 507 | float3 position = input.tex3D; 508 | float3 dataStep = float3(1.0/dataStepSize,1.0/dataStepSize,1.0/dataStepSize); 509 | 510 | float3 grad = float3( 511 | (SampleData3(position + float3(dataStep.x, 0, 0)).x - SampleData3(position+float3(-dataStep.x, 0, 0)).x)/h2, 512 | (SampleData3(position+float3(0, dataStep.y, 0)).x - SampleData3(position+float3(0, -dataStep.y, 0)).x)/h2, 513 | (SampleData3(position+float3(0,0,dataStep.z)).x - SampleData3(position+float3(0,0,-dataStep.z)).x)/h2 514 | ); 515 | float3 normal = normalize(grad); 516 | normal = mul(unity_ObjectToWorld,normal); 517 | normal = normalize(normal); 518 | 519 | float pi = 3.14159265; 520 | float3 dir = normalize(position - float3(0.5,0.5,0.5)); 521 | float u = (atan2(dir.z,dir.x)+pi)/(2.0 * pi); 522 | float v = 0.5 + 0.5* dot(float3(0,1,0),dir); 523 | 524 | float d = abs(dot(normalize(_WorldSpaceLightPos0.xyz),-normal)); 525 | return float4(d,d,d,1); 526 | //return float4(normal,1); 527 | //return _SpriteTex.Sample(sampler_SpriteTex, float2(u,v)) * saturate(0.5 + normal.y * 0.5) ; 528 | //return _SpriteTex.Sample(sampler_SpriteTex, float2(u,v)) * d; 529 | } 530 | 531 | ENDCG 532 | } 533 | } 534 | } -------------------------------------------------------------------------------- /Assets/Materials/ReferenceMaterial/MarchingCubes/MarchingCubesGPU.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 501b96ea624596f4a95570dff1508033 3 | timeCreated: 1492919898 4 | licenseType: Free 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Materials/ReferenceMaterial/MarchingCubes/MarchingCubesGS.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kristofe/UnityGPUMarchingCubes/db1b234e7ae3343b48dfd942ed9ca2798735acde/Assets/Materials/ReferenceMaterial/MarchingCubes/MarchingCubesGS.mat -------------------------------------------------------------------------------- /Assets/Materials/ReferenceMaterial/MarchingCubes/MarchingCubesGS.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9e3a2feb79bc28e4888b61d849cb1782 3 | timeCreated: 1492919898 4 | licenseType: Free 5 | NativeFormatImporter: 6 | mainObjectFileID: -1 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Materials/ReferenceMaterial/Reflection.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 34082fcd8e23ff543921bd6bda8272d9 3 | folderAsset: yes 4 | timeCreated: 1492919896 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Materials/ReferenceMaterial/Reflection/CGReflection.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kristofe/UnityGPUMarchingCubes/db1b234e7ae3343b48dfd942ed9ca2798735acde/Assets/Materials/ReferenceMaterial/Reflection/CGReflection.mat -------------------------------------------------------------------------------- /Assets/Materials/ReferenceMaterial/Reflection/CGReflection.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ec1483c7ace7d2a40a3606c5567f0c5d 3 | timeCreated: 1492919898 4 | licenseType: Free 5 | NativeFormatImporter: 6 | mainObjectFileID: -1 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Materials/ReferenceMaterial/Reflection/CGReflectionShader.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld' 2 | // Upgrade NOTE: replaced '_World2Object' with 'unity_WorldToObject' 3 | 4 | Shader "Custom/CG Reflection Map" { 5 | Properties { 6 | _Cube("Reflection Map", Cube) = "" {} 7 | _CubeAdd("Additive Reflection Map", Cube) = "" {} 8 | _MainColor ("Main Material Color", Color) = (1,1,1,1) 9 | _SpecularColor ("Specular Material Color", Color) = (1,1,1,1) 10 | _ReflectionColor("Reflection Color", Color) = (1.0,1.0,1.0,1.0) 11 | _ReflectionAddColor("Reflection Add Color", Color) = (1.0,1.0,1.0,1.0) 12 | _Shininess ("Shininess", Float) = 10 13 | } 14 | SubShader { 15 | Pass { 16 | CGPROGRAM 17 | #pragma target 3.0 18 | #pragma vertex vert 19 | #pragma fragment frag 20 | 21 | // User-specified uniforms 22 | uniform samplerCUBE _Cube; 23 | uniform samplerCUBE _CubeAdd; 24 | uniform float4 _MainColor; 25 | uniform float4 _SpecularColor; 26 | uniform float4 _ReflectionColor; 27 | uniform float4 _ReflectionAddColor; 28 | uniform float _Shininess; 29 | 30 | // The following built-in uniforms are also 31 | #include "UnityCG.cginc" 32 | #include "Lighting.cginc" 33 | 34 | struct vertexInput { 35 | float4 vertex : POSITION; 36 | float3 normal : NORMAL; 37 | }; 38 | struct vertexOutput { 39 | float4 pos : SV_POSITION; 40 | float4 posWorld : TEXCOORD0; 41 | float3 normalDir : TEXCOORD1; 42 | }; 43 | 44 | vertexOutput vert(vertexInput input) 45 | { 46 | vertexOutput output; 47 | 48 | float4x4 modelMatrix = unity_ObjectToWorld; 49 | float4x4 modelMatrixInverse = unity_WorldToObject; 50 | // multiplication with unity_Scale.w is unnecessary 51 | // because we normalize transformed vectors 52 | 53 | output.posWorld = mul(modelMatrix, input.vertex); 54 | output.normalDir = normalize( mul(float4(input.normal, 0.0), modelMatrixInverse).xyz); 55 | output.pos = mul(UNITY_MATRIX_MVP, input.vertex); 56 | return output; 57 | } 58 | 59 | float4 frag(vertexOutput input) : COLOR 60 | { 61 | float3 normalDirection = normalize(input.normalDir); 62 | 63 | float3 viewDirection = normalize( 64 | input.posWorld.xyz - _WorldSpaceCameraPos); 65 | float3 lightDirection; 66 | float attenuation; 67 | 68 | if (0.0 == _WorldSpaceLightPos0.w) // directional light? 69 | { 70 | attenuation = 1.0; // no attenuation 71 | lightDirection = 72 | normalize(_WorldSpaceLightPos0.xyz); 73 | } 74 | else // point or spot light 75 | { 76 | float3 vertexToLightSource = 77 | (_WorldSpaceLightPos0 - input.posWorld).xyz; 78 | float distance = length(vertexToLightSource); 79 | attenuation = 1.0 / distance; // linear attenuation 80 | lightDirection = normalize(vertexToLightSource); 81 | } 82 | 83 | float3 ambientLighting = 84 | UNITY_LIGHTMODEL_AMBIENT.xyz * _MainColor.xyz; 85 | 86 | float3 diffuseReflection = 87 | attenuation * _LightColor0.xyz * _MainColor.xyz 88 | * max(0.0, dot(normalDirection, lightDirection)); 89 | 90 | float3 specularReflection; 91 | if (dot(normalDirection, lightDirection) < 0.0) 92 | // light source on the wrong side? 93 | { 94 | specularReflection = float3(0.0, 0.0, 0.0); 95 | // no specular reflection 96 | } 97 | else // light source on the right side 98 | { 99 | specularReflection = attenuation * _LightColor0.xyz 100 | * _SpecColor.xyz * pow(max(0.0, dot( 101 | reflect(-lightDirection, normalDirection), 102 | viewDirection)), _Shininess); 103 | } 104 | 105 | float3 reflectedDir = 106 | reflect(viewDirection, normalDirection); 107 | float4 reflection = texCUBE(_Cube, reflectedDir) * _ReflectionColor; 108 | float4 reflection2 = texCUBE(_CubeAdd, reflectedDir) * _ReflectionAddColor; 109 | 110 | return float4(ambientLighting + diffuseReflection 111 | + specularReflection + reflection + reflection2, 1.0); 112 | } 113 | 114 | ENDCG 115 | } 116 | 117 | Pass { 118 | Tags { "LightMode" = "ForwardAdd" } 119 | // pass for additional light sources 120 | Blend One One // additive blending 121 | 122 | CGPROGRAM 123 | 124 | #pragma vertex vert 125 | #pragma fragment frag 126 | 127 | // User-specified uniforms 128 | uniform samplerCUBE _Cube; 129 | uniform float4 _MainColor; 130 | uniform float4 _SpecularColor; 131 | uniform float4 _ReflectionColor; 132 | uniform float _Shininess; 133 | 134 | // The following built-in uniforms are also 135 | #include "UnityCG.cginc" 136 | #include "Lighting.cginc" 137 | 138 | struct vertexInput { 139 | float4 vertex : POSITION; 140 | float3 normal : NORMAL; 141 | }; 142 | struct vertexOutput { 143 | float4 pos : SV_POSITION; 144 | float4 col : COLOR; 145 | }; 146 | 147 | vertexOutput vert(vertexInput input) 148 | { 149 | vertexOutput output; 150 | 151 | float4x4 modelMatrix = unity_ObjectToWorld; 152 | float4x4 modelMatrixInverse = unity_WorldToObject; 153 | // multiplication with unity_Scale.w is unnecessary 154 | // because we normalize transformed vectors 155 | 156 | float3 normalDirection = normalize( 157 | mul(float4(input.normal, 0.0), modelMatrixInverse).xyz 158 | ); 159 | float3 viewDirection = normalize( mul(modelMatrix, input.vertex).xyz 160 | - float4(_WorldSpaceCameraPos, 1.0) ); 161 | float3 lightDirection; 162 | float attenuation; 163 | 164 | if (0.0 == _WorldSpaceLightPos0.w) // directional light? 165 | { 166 | attenuation = 1.0; // no attenuation 167 | lightDirection = 168 | normalize(_WorldSpaceLightPos0.xyz); 169 | } 170 | else // point or spot light 171 | { 172 | float3 vertexToLightSource = (_WorldSpaceLightPos0 173 | - mul(modelMatrix, input.vertex)).xyz; 174 | float distance = length(vertexToLightSource); 175 | attenuation = 1.0 / distance; // linear attenuation 176 | lightDirection = normalize(vertexToLightSource); 177 | } 178 | 179 | float3 diffuseReflection = 180 | attenuation * _LightColor0.xyz * _MainColor.xyz 181 | * max(0.0, dot(normalDirection, lightDirection)); 182 | 183 | float3 specularReflection; 184 | if (dot(normalDirection, lightDirection) < 0.0) 185 | // light source on the wrong side? 186 | { 187 | specularReflection = float3(0.0, 0.0, 0.0); 188 | // no specular reflection 189 | } 190 | else // light source on the right side 191 | { 192 | specularReflection = attenuation * _LightColor0.xyz 193 | * _SpecularColor.xyz * pow(max(0.0, dot( 194 | reflect(-lightDirection, normalDirection), 195 | viewDirection)), _Shininess); 196 | } 197 | 198 | output.col = float4(diffuseReflection 199 | + specularReflection, 1.0); 200 | // no ambient contribution in this pass 201 | output.pos = mul(UNITY_MATRIX_MVP, input.vertex); 202 | return output; 203 | } 204 | 205 | float4 frag(vertexOutput input) : COLOR 206 | { 207 | return input.col; 208 | } 209 | 210 | ENDCG 211 | } 212 | } 213 | } -------------------------------------------------------------------------------- /Assets/Materials/ReferenceMaterial/Reflection/CGReflectionShader.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 08d8ccaca35a2084c964acb534d29f84 3 | timeCreated: 1492919898 4 | licenseType: Free 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Meshes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d071f0c36b609e5469f71f9afb9ca1f3 3 | folderAsset: yes 4 | timeCreated: 1492919896 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Meshes/LatticeMesh.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kristofe/UnityGPUMarchingCubes/db1b234e7ae3343b48dfd942ed9ca2798735acde/Assets/Meshes/LatticeMesh.asset -------------------------------------------------------------------------------- /Assets/Meshes/LatticeMesh.asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 23e652584f4a07c4cba1fdbfc9df5885 3 | timeCreated: 1492919899 4 | licenseType: Free 5 | NativeFormatImporter: 6 | mainObjectFileID: -1 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Meshes/LatticeMesh1x1x1.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kristofe/UnityGPUMarchingCubes/db1b234e7ae3343b48dfd942ed9ca2798735acde/Assets/Meshes/LatticeMesh1x1x1.asset -------------------------------------------------------------------------------- /Assets/Meshes/LatticeMesh1x1x1.asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e416f57d0f468b9459ac0e978cb0bb6a 3 | timeCreated: 1492919899 4 | licenseType: Free 5 | NativeFormatImporter: 6 | mainObjectFileID: -1 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Scenes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 97203cc31143a7b44be84bbd5b1963ad 3 | folderAsset: yes 4 | timeCreated: 1492919896 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Scenes/TestComputeShaders.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kristofe/UnityGPUMarchingCubes/db1b234e7ae3343b48dfd942ed9ca2798735acde/Assets/Scenes/TestComputeShaders.unity -------------------------------------------------------------------------------- /Assets/Scenes/TestComputeShaders.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 715c378414b93a648a8f321ea1e3cb42 3 | timeCreated: 1492919896 4 | licenseType: Free 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8cc25da9aecebc041b72a05e7ada1d5f 3 | folderAsset: yes 4 | timeCreated: 1492919896 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Scripts/Perlin.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System; 3 | using UnityEngine; 4 | 5 | public class Perlin 6 | { 7 | // Returns noise between 0 - 1 8 | static public float NoiseNormalized(float x, float y) 9 | { 10 | //-0.697 - 0.795 + 0.697 11 | float value = Noise(x, y); 12 | 13 | /* Replacing division with multipling by the inverse as a decimal 14 | 0.793+0.69 = 1.483 15 | 1/1.483 = 0.67430883345 16 | */ 17 | //value = (value + 0.69F) / (0.793F + 0.69F); 18 | value = (value + 0.69F) *0.67430883345F; 19 | return value; 20 | } 21 | 22 | static public float Noise(float x, float y) 23 | { 24 | int X = (int)Mathf.Floor(x) & 255, // FIND UNIT CUBE THAT 25 | Y = (int)Mathf.Floor(y) & 255; // CONTAINS POINT. 26 | x -= Mathf.Floor(x); // FIND RELATIVE X,Y,Z 27 | y -= Mathf.Floor(y); // OF POINT IN CUBE. 28 | float u = fade(x), // COMPUTE FADE CURVES 29 | v = fade(y); // FOR EACH OF X,Y,Z. 30 | int A = p[X ]+Y, AA = p[A], AB = p[A+1], // HASH COORDINATES OF 31 | B = p[X+1]+Y, BA = p[B], BB = p[B+1]; // THE 8 CUBE CORNERS, 32 | 33 | float res = lerp(v, lerp(u, grad2(p[AA ], x , y ), // AND ADD 34 | grad2(p[BA ], x-1, y )), // BLENDED 35 | lerp(u, grad2(p[AB ], x , y-1 ), // RESULTS 36 | grad2(p[BB ], x-1, y-1 )));// FROM 8 37 | return res; 38 | } 39 | 40 | static public float Noise(float x, float y, float z) { 41 | int X = (int)Mathf.Floor(x) & 255, // FIND UNIT CUBE THAT 42 | Y = (int)Mathf.Floor(y) & 255, // CONTAINS POINT. 43 | Z = (int)Mathf.Floor(z) & 255; 44 | x -= Mathf.Floor(x); // FIND RELATIVE X,Y,Z 45 | y -= Mathf.Floor(y); // OF POINT IN CUBE. 46 | z -= Mathf.Floor(z); 47 | float u = fade(x), // COMPUTE FADE CURVES 48 | v = fade(y), // FOR EACH OF X,Y,Z. 49 | w = fade(z); 50 | int A = p[X ]+Y, AA = p[A]+Z, AB = p[A+1]+Z, // HASH COORDINATES OF 51 | B = p[X+1]+Y, BA = p[B]+Z, BB = p[B+1]+Z; // THE 8 CUBE CORNERS, 52 | 53 | return lerp(w, lerp(v, lerp(u, grad(p[AA ], x , y , z ), // AND ADD 54 | grad(p[BA ], x-1, y , z )), // BLENDED 55 | lerp(u, grad(p[AB ], x , y-1, z ), // RESULTS 56 | grad(p[BB ], x-1, y-1, z ))),// FROM 8 57 | lerp(v, lerp(u, grad(p[AA+1], x , y , z-1 ), // CORNERS 58 | grad(p[BA+1], x-1, y , z-1 )), // OF CUBE 59 | lerp(u, grad(p[AB+1], x , y-1, z-1 ), 60 | grad(p[BB+1], x-1, y-1, z-1 )))); 61 | } 62 | 63 | static public float Turbulence(float posX, float posY, int octaves) { 64 | float x = 0; 65 | float scale = 1; 66 | int octave = 0; 67 | while (++octave <= octaves) { 68 | posX = posX/scale; 69 | posY = posY/scale; 70 | x = x + Math.Abs(Noise(posX, posY))*scale; 71 | scale = scale/2; 72 | } 73 | return x; 74 | } 75 | 76 | static public float Fractal(float posX, float posY, int octaves) 77 | { 78 | float x = 0; 79 | float scale = 1; 80 | int octave = 0; 81 | while (++octave <= octaves) 82 | { 83 | posX = posX / scale; 84 | posY = posY / scale; 85 | x = x + Noise(posX, posY) * scale; 86 | scale = scale / 2; 87 | } 88 | return x; 89 | } 90 | 91 | static public float Marble(float posX, float posY, int octaves) { 92 | //Vector3 rgb = new Vector3(); 93 | float x = Mathf.Sin((posY+3.0f*Turbulence(posX,posY,octaves))*Mathf.PI); 94 | x = Mathf.Sqrt(x+1)*.7071f; 95 | //rgb.z=.3+.8*x; 96 | //x = Mathf.sqrt(x); 97 | //rgb.x = .3 + .6*x; 98 | //rgb.z = .6 + .4*x; 99 | 100 | return x; 101 | } 102 | static public float Turbulence(float posX, float posY, float posZ, int octaves) { 103 | float x = 0; 104 | float scale = 1; 105 | int octave = 0; 106 | while (++octave <= octaves) { 107 | posX = posX/scale; 108 | posY = posY/scale; 109 | posZ = posZ/scale; 110 | x = x + Math.Abs(Noise(posX, posY, posZ))*scale; 111 | scale = scale/2; 112 | } 113 | return x; 114 | } 115 | 116 | static public float Marble(float posX, float posY, float posZ, int octaves) { 117 | //Vector3 rgb = new Vector3(); 118 | float x = Mathf.Sin((posY+3.0f*Turbulence(posX,posY,posZ,octaves))*Mathf.PI); 119 | x = Mathf.Sqrt(x+1)*.7071f; 120 | //rgb.z=.3+.8*x; 121 | //x = Mathf.sqrt(x); 122 | //rgb.x = .3 + .6*x; 123 | //rgb.z = .6 + .4*x; 124 | 125 | return x; 126 | } 127 | 128 | static float fade(float t) { return t * t * t * (t * (t * 6 - 15) + 10); } 129 | static float lerp(float t, float a, float b) { return a + t * (b - a); } 130 | static float grad(int hash, float x, float y, float z) { 131 | int h = hash & 15; // CONVERT LO 4 BITS OF HASH CODE 132 | float u = h<8 ? x : y, // INTO 12 GRADIENT DIRECTIONS. 133 | v = h<4 ? y : h==12||h==14 ? x : z; 134 | return ((h&1) == 0 ? u : -u) + ((h&2) == 0 ? v : -v); 135 | } 136 | 137 | static float grad2(int hash, float x, float y) { 138 | int h = hash & 15; // CONVERT LO 4 BITS OF HASH CODE 139 | float u = h < 8 ? x : y, // INTO 12 GRADIENT DIRECTIONS. 140 | v = h < 4 ? y : h==12 || h==14 ? x : 0; 141 | return ((h&1) == 0 ? u : -u) + ((h&2) == 0 ? v : -v); 142 | } 143 | 144 | static int[] p = { 151,160,137,91,90,15, 145 | 131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23, 146 | 190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33, 147 | 88,237,149,56,87,174,20,125,136,171,168, 68,175,74,165,71,134,139,48,27,166, 148 | 77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244, 149 | 102,143,54, 65,25,63,161, 1,216,80,73,209,76,132,187,208, 89,18,169,200,196, 150 | 135,130,116,188,159,86,164,100,109,198,173,186, 3,64,52,217,226,250,124,123, 151 | 5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42, 152 | 223,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167, 43,172,9, 153 | 129,22,39,253, 19,98,108,110,79,113,224,232,178,185, 112,104,218,246,97,228, 154 | 251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107, 155 | 49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254, 156 | 138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180, 157 | 151,160,137,91,90,15, 158 | 131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23, 159 | 190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33, 160 | 88,237,149,56,87,174,20,125,136,171,168, 68,175,74,165,71,134,139,48,27,166, 161 | 77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244, 162 | 102,143,54, 65,25,63,161, 1,216,80,73,209,76,132,187,208, 89,18,169,200,196, 163 | 135,130,116,188,159,86,164,100,109,198,173,186, 3,64,52,217,226,250,124,123, 164 | 5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42, 165 | 223,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167, 43,172,9, 166 | 129,22,39,253, 19,98,108,110,79,113,224,232,178,185, 112,104,218,246,97,228, 167 | 251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107, 168 | 49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254, 169 | 138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180 170 | }; 171 | } 172 | -------------------------------------------------------------------------------- /Assets/Scripts/Perlin.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 83a46f9d055b69b47a30e359ad95e779 3 | timeCreated: 1492919897 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/Textures.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 62d43b5fd25ddc34b83362f502673134 3 | folderAsset: yes 4 | timeCreated: 1492919896 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Textures/earth_texture2048x1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kristofe/UnityGPUMarchingCubes/db1b234e7ae3343b48dfd942ed9ca2798735acde/Assets/Textures/earth_texture2048x1024.png -------------------------------------------------------------------------------- /Assets/Textures/earth_texture2048x1024.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 69468af2b236ec1438f5cc9fdd8d7520 3 | timeCreated: 1492919898 4 | licenseType: Free 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 4 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 1 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: 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: 2048 55 | textureFormat: -1 56 | textureCompression: 1 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/Textures/edgeTableTexture.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kristofe/UnityGPUMarchingCubes/db1b234e7ae3343b48dfd942ed9ca2798735acde/Assets/Textures/edgeTableTexture.asset -------------------------------------------------------------------------------- /Assets/Textures/edgeTableTexture.asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 94e9443a5a9476446bbe02aa01a15ede 3 | timeCreated: 1492919899 4 | licenseType: Free 5 | NativeFormatImporter: 6 | mainObjectFileID: -1 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Textures/triTableTexture.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kristofe/UnityGPUMarchingCubes/db1b234e7ae3343b48dfd942ed9ca2798735acde/Assets/Textures/triTableTexture.asset -------------------------------------------------------------------------------- /Assets/Textures/triTableTexture.asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 93522c9d418adb34cad0aa3d557f2d52 3 | timeCreated: 1492919899 4 | licenseType: Free 5 | NativeFormatImporter: 6 | mainObjectFileID: -1 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Textures3D.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5281b3c38db477d41ace77a5140293fd 3 | folderAsset: yes 4 | timeCreated: 1492919896 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Textures3D/pyroclasticNoise.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kristofe/UnityGPUMarchingCubes/db1b234e7ae3343b48dfd942ed9ca2798735acde/Assets/Textures3D/pyroclasticNoise.asset -------------------------------------------------------------------------------- /Assets/Textures3D/pyroclasticNoise.asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9c2616fcd4d0ebd46a5a7f3e2c3a710f 3 | timeCreated: 1492919899 4 | licenseType: Free 5 | NativeFormatImporter: 6 | mainObjectFileID: -1 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Kristofer Schlachter 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/kristofe/UnityGPUMarchingCubes/db1b234e7ae3343b48dfd942ed9ca2798735acde/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kristofe/UnityGPUMarchingCubes/db1b234e7ae3343b48dfd942ed9ca2798735acde/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kristofe/UnityGPUMarchingCubes/db1b234e7ae3343b48dfd942ed9ca2798735acde/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kristofe/UnityGPUMarchingCubes/db1b234e7ae3343b48dfd942ed9ca2798735acde/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kristofe/UnityGPUMarchingCubes/db1b234e7ae3343b48dfd942ed9ca2798735acde/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshLayers.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kristofe/UnityGPUMarchingCubes/db1b234e7ae3343b48dfd942ed9ca2798735acde/ProjectSettings/NavMeshLayers.asset -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kristofe/UnityGPUMarchingCubes/db1b234e7ae3343b48dfd942ed9ca2798735acde/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kristofe/UnityGPUMarchingCubes/db1b234e7ae3343b48dfd942ed9ca2798735acde/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kristofe/UnityGPUMarchingCubes/db1b234e7ae3343b48dfd942ed9ca2798735acde/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kristofe/UnityGPUMarchingCubes/db1b234e7ae3343b48dfd942ed9ca2798735acde/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kristofe/UnityGPUMarchingCubes/db1b234e7ae3343b48dfd942ed9ca2798735acde/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | UnityGPUMarchingCubes 2 | ===================== 3 | 4 | Marching Cubes using DX11 geometry shaders in Unity 5.6. For previous versions checkout branch Unity4Compatible. 5 | ---------- 6 | 7 | Implementation is in ***Assets/Materials/ReferenceMaterial/MarchingCubes/*** 8 | -------------------------------------------------------------------------------- /UnityGPUMarchingCubes/.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /UnityGPUMarchingCubes/.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | [Dd]ebug/ 46 | [Rr]elease/ 47 | *_i.c 48 | *_p.c 49 | *.ilk 50 | *.meta 51 | *.obj 52 | *.pch 53 | *.pdb 54 | *.pgc 55 | *.pgd 56 | *.rsp 57 | *.sbr 58 | *.tlb 59 | *.tli 60 | *.tlh 61 | *.tmp 62 | *.vspscc 63 | .builds 64 | *.dotCover 65 | 66 | ## TODO: If you have NuGet Package Restore enabled, uncomment this 67 | #packages/ 68 | 69 | # Visual C++ cache files 70 | ipch/ 71 | *.aps 72 | *.ncb 73 | *.opensdf 74 | *.sdf 75 | 76 | # Visual Studio profiler 77 | *.psess 78 | *.vsp 79 | 80 | # ReSharper is a .NET coding add-in 81 | _ReSharper* 82 | 83 | # Installshield output folder 84 | [Ee]xpress 85 | 86 | # DocProject is a documentation generator add-in 87 | DocProject/buildhelp/ 88 | DocProject/Help/*.HxT 89 | DocProject/Help/*.HxC 90 | DocProject/Help/*.hhc 91 | DocProject/Help/*.hhk 92 | DocProject/Help/*.hhp 93 | DocProject/Help/Html2 94 | DocProject/Help/html 95 | 96 | # Click-Once directory 97 | publish 98 | 99 | # Others 100 | [Bb]in 101 | [Oo]bj 102 | sql 103 | TestResults 104 | *.Cache 105 | ClientBin 106 | stylecop.* 107 | ~$* 108 | *.dbmdl 109 | Generated_Code #added for RIA/Silverlight projects 110 | 111 | # Backup & report files from converting an old project file to a newer 112 | # Visual Studio version. Backup files are not needed, because we have git ;-) 113 | _UpgradeReport_Files/ 114 | Backup*/ 115 | UpgradeLog*.XML 116 | 117 | 118 | 119 | ############ 120 | ## Windows 121 | ############ 122 | 123 | # Windows image file caches 124 | Thumbs.db 125 | 126 | # Folder config file 127 | Desktop.ini 128 | 129 | 130 | ############# 131 | ## Python 132 | ############# 133 | 134 | *.py[co] 135 | 136 | # Packages 137 | *.egg 138 | *.egg-info 139 | dist 140 | build 141 | eggs 142 | parts 143 | bin 144 | var 145 | sdist 146 | develop-eggs 147 | .installed.cfg 148 | 149 | # Installer logs 150 | pip-log.txt 151 | 152 | # Unit test / coverage reports 153 | .coverage 154 | .tox 155 | 156 | #Translations 157 | *.mo 158 | 159 | #Mr Developer 160 | .mr.developer.cfg 161 | 162 | # Mac crap 163 | .DS_Store 164 | --------------------------------------------------------------------------------