├── .gitattributes ├── Runtime ├── Props │ ├── Default │ │ ├── Tree5.fbx │ │ ├── noise.png │ │ ├── normal.png │ │ ├── Dynamic Edit.prefab.meta │ │ ├── TestPropPrefab 1.prefab.meta │ │ ├── TestPropPrefab 2.prefab.meta │ │ ├── TestPropPrefab.prefab.meta │ │ ├── BarkMat.mat.meta │ │ ├── Pine1Mat.mat.meta │ │ ├── Pine2Mat.mat.meta │ │ ├── Pine3Mat.mat.meta │ │ ├── TestProp.asset.meta │ │ ├── TestProp 1.asset.meta │ │ ├── TestProp 2.asset.meta │ │ ├── Instanced Material.mat.meta │ │ ├── DefaultSerializableProp.cs.meta │ │ ├── DefaultSerializableProp.cs │ │ ├── TestProp 1.asset │ │ ├── TestProp 2.asset │ │ ├── TestProp.asset │ │ ├── noise.png.meta │ │ ├── normal.png.meta │ │ └── Tree5.fbx.meta │ ├── Compute.meta │ ├── Default.meta │ ├── PropGeneratorEnd.cginc.meta │ ├── PropGeneratorStart.cginc.meta │ ├── Compute │ │ ├── FreeBlockCopy.compute.meta │ │ ├── RemoveSegments.compute.meta │ │ ├── FreeBlockSearch.compute.meta │ │ ├── PropCullingApply.compute.meta │ │ ├── PropCullingCopy.compute.meta │ │ ├── SpawnManualProps.compute.meta │ │ ├── SpawnManualProps.compute │ │ ├── FreeBlockSearch.compute │ │ ├── RemoveSegments.compute │ │ ├── PropCullingApply.compute │ │ ├── FreeBlockCopy.compute │ │ └── PropCullingCopy.compute │ ├── PropGeneratorTemplate.compute.meta │ ├── Billboard Capture.meta │ ├── Billboard Capture │ │ ├── BillBoardBaseShader.mat.meta │ │ ├── PropCaptureFullScreenMaterial.mat.meta │ │ ├── PropCaptureFullScreen.shader.meta │ │ ├── PropCaptureFullScreenMaterial.mat │ │ └── PropCaptureFullScreen.shader │ ├── PropGeneratorEnd.cginc │ ├── PropType.cs.meta │ ├── VoxelProps.cs.meta │ ├── SerializableProp.cs.meta │ ├── VoxelPropsGpuUtil.cs.meta │ ├── VoxelPropSerializeUtil.cs.meta │ ├── VoxelPropsRendering.cs.meta │ ├── PropGeneratorTemplate.compute │ └── SerializableProp.cs ├── Utils │ ├── noises │ │ ├── voronoise.cginc │ │ ├── README.meta │ │ ├── common.cginc.meta │ │ ├── fbm.cginc.meta │ │ ├── psrdnoise2D.glsl.meta │ │ ├── voronoise.cginc.meta │ │ ├── cellular2D.cginc.meta │ │ ├── cellular3D.cginc.meta │ │ ├── erosion.cginc.meta │ │ ├── noise2D.cginc.meta │ │ ├── noise3D.cginc.meta │ │ ├── README │ │ ├── fbm.cginc │ │ ├── cellular2D.cginc │ │ ├── noise2D.cginc │ │ └── noise3D.cginc │ ├── sdf.cginc.meta │ ├── PropUtils.cginc.meta │ ├── morton.cginc.meta │ ├── noises.cginc.meta │ ├── PropPackUtils.cginc.meta │ ├── noises.meta │ ├── Morton.cs.meta │ ├── Voxel.cs.meta │ ├── VoxelUtils.cs.meta │ ├── NativeCounter.cs.meta │ ├── NativeExtensions.cs.meta │ ├── RleCompressionJob.cs.meta │ ├── TestTerrainEdit.cs.meta │ ├── TestTerrainPlayer.cs.meta │ ├── VoxelBehaviour.cs.meta │ ├── NativeMultiCounter.cs.meta │ ├── RleDecompressionJob.cs.meta │ ├── SerializableRegistry.cs.meta │ ├── VoxelCompressionJob.cs.meta │ ├── VoxelDecompressionJob.cs.meta │ ├── VoxelSerialization.cs.meta │ ├── VoxelBehaviour.cs │ ├── noises.cginc │ ├── NativeExtensions.cs │ ├── RleCompressionJob.cs │ ├── RleDecompressionJob.cs │ ├── PropUtils.cginc │ ├── morton.cginc │ ├── PropPackUtils.cginc │ ├── Voxel.cs │ ├── VoxelCompressionJob.cs │ ├── sdf.cginc │ ├── VoxelDecompressionJob.cs │ └── SerializableRegistry.cs ├── Shader Graph │ ├── Shadows.cginc │ ├── Shadows.cginc.meta │ ├── EulerAngles.cginc.meta │ ├── InstancedFetch.cginc.meta │ ├── Shader Graphs_BillBoardShaderGraph.mat.meta │ ├── LowPoly Shader.shadergraph.meta │ ├── LowPoly Normals.shadersubgraph.meta │ ├── Ambient Occlusion Test.shadergraph.meta │ ├── BillBoardShaderGraph.shadergraph.meta │ ├── FetchBlittableProp.shadersubgraph.meta │ ├── InstancedPropShaderGraph.shadergraph.meta │ ├── InstancedPropSubGraph.shadersubgraph.meta │ ├── LowPoly Shader Slope.shadergraph.meta │ ├── FetchInstancedPropShader.shadersubgraph.meta │ ├── LowPoly Chunk Checker Shader.shadergraph.meta │ ├── LowPoly Shader Slope Textured.shadergraph.meta │ ├── EulerAngles.cginc │ └── InstancedFetch.cginc ├── Scenes │ ├── Demo.unity.meta │ └── Sample.unity.meta ├── Mesher.meta ├── Octree.meta ├── Prefabs │ ├── Voxel Chunk.prefab.meta │ ├── Voxel Terrain.prefab.meta │ ├── Prop Billboard Capture Camera.prefab.meta │ └── Voxel Chunk.prefab ├── Props.meta ├── Scenes.meta ├── Utils.meta ├── Editing.meta ├── Materials.meta ├── Prefabs.meta ├── Segments.meta ├── Voxelizer.meta ├── Editing │ ├── Default.meta │ ├── IVoxelEdit.cs.meta │ ├── VoxelEdits.cs.meta │ ├── DynamicEditJob.cs.meta │ ├── IDynamicEdit.cs.meta │ ├── VoxelEditJob.cs.meta │ ├── Default │ │ ├── AddVoxelEdit.cs.meta │ │ ├── CuboidDynamicEdit.cs.meta │ │ ├── CuboidVoxelEdit.cs.meta │ │ ├── FlattenVoxelEdit.cs.meta │ │ ├── SphereDynamicEdit.cs.meta │ │ ├── SphereVoxelEdit.cs.meta │ │ ├── SphereVoxelEdit.cs │ │ ├── AddVoxelEdit.cs │ │ ├── CuboidVoxelEdit.cs │ │ ├── FlattenVoxelEdit.cs │ │ ├── SphereDynamicEdit.cs │ │ └── CuboidDynamicEdit.cs │ ├── VoxelEditApplyJob.cs.meta │ ├── VoxelEditOctreeNode.cs.meta │ ├── VoxelEditSubdivisionJob.cs.meta │ ├── DynamicEditJob.cs │ ├── VoxelEditApplyJob.cs │ ├── IVoxelEdit.cs │ ├── IDynamicEdit.cs │ ├── VoxelEditJob.cs │ ├── VoxelEditSubdivisionJob.cs │ └── VoxelEditOctreeNode.cs ├── Shader Graph.meta ├── Voxelizer │ ├── VoxelGeneratorEnd.cginc.meta │ ├── VoxelGeneratorStart.cginc.meta │ ├── VoxelGeneratorTemplate.compute.meta │ ├── VoxelGenerator.cs.meta │ ├── VoxelReadbackRequest.cs.meta │ ├── VoxelReadbackRequest.cs │ ├── VoxelGeneratorStart.cginc │ ├── VoxelGeneratorEnd.cginc │ └── VoxelGeneratorTemplate.compute ├── Materials │ ├── Grass.mat.meta │ ├── Checkers.mat.meta │ ├── Green Metal.mat.meta │ ├── Red Metal.mat.meta │ ├── Low Poly Textured 2.mat.meta │ ├── Low Poly Textured.mat.meta │ ├── Ambient Occlusion Test.mat.meta │ ├── Low Poly Textured Slope.mat.meta │ └── Checkers.mat ├── jedjoud.voxelterraingenerator.runtime.asmdef.meta ├── Mesher │ ├── SumJob.cs.meta │ ├── BakeJob.cs.meta │ ├── CopyJob.cs.meta │ ├── CornerJob.cs.meta │ ├── MaterialJob.cs.meta │ ├── QuadJob.cs.meta │ ├── VertexJob.cs.meta │ ├── VoxelMesh.cs.meta │ ├── VoxelMesher.cs.meta │ ├── MeshJobHandler.cs.meta │ ├── PendingMeshJob.cs.meta │ ├── VoxelCollisions.cs.meta │ ├── BakeJob.cs │ ├── PendingMeshJob.cs │ ├── SumJob.cs │ ├── MaterialJob.cs │ ├── VoxelMesh.cs │ ├── CopyJob.cs │ ├── VoxelCollisions.cs │ └── CornerJob.cs ├── TerrainLoader.cs.meta ├── VoxelChunk.cs.meta ├── VoxelTerrain.cs.meta ├── Octree │ ├── DiffJob.cs.meta │ ├── NeigbourJob.cs.meta │ ├── OctreeNode.cs.meta │ ├── VoxelOctree.cs.meta │ ├── IntersectJob.cs.meta │ ├── SubdivideJob.cs.meta │ ├── ToHashSetJob.cs.meta │ ├── IOctreeSubdivider.cs.meta │ ├── DefaultOctreeSubdivider.cs.meta │ ├── DiffJob.cs │ ├── ToHashSetJob.cs │ ├── DefaultOctreeSubdivider.cs │ ├── IOctreeSubdivider.cs │ ├── IntersectJob.cs │ ├── SubdivideJob.cs │ ├── NeigbourJob.cs │ └── OctreeNode.cs ├── Segments │ ├── Segment.cs.meta │ ├── VoxelSegments.cs.meta │ ├── SegmentSpawnJob.cs.meta │ ├── Segment.cs │ └── SegmentSpawnJob.cs ├── jedjoud.voxelterraingenerator.runtime.asmdef ├── VoxelChunk.cs └── TerrainLoader.cs ├── README.md.meta ├── package.json.meta ├── Editor.meta ├── Runtime.meta ├── Editor ├── jedjoud.voxelterraingenerator.editor.asmdef.meta ├── CustomEditorProp.cs.meta ├── CustomEditorVoxelOctree.cs.meta ├── CustomEditorVoxelPreview.cs.meta ├── CustomEditorVoxelRegions.cs.meta ├── CustomEditorVoxelTerrain.cs.meta ├── jedjoud.voxelterraingenerator.editor.asmdef ├── CustomEditorVoxelRegions.cs ├── CustomEditorVoxelOctree.cs ├── CustomEditorVoxelTerrain.cs ├── CustomEditorProp.cs └── CustomEditorVoxelPreview.cs ├── package.json └── .gitignore /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /Runtime/Props/Default/Tree5.fbx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jedjoud10/VoxelTerrain/HEAD/Runtime/Props/Default/Tree5.fbx -------------------------------------------------------------------------------- /Runtime/Props/Default/noise.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jedjoud10/VoxelTerrain/HEAD/Runtime/Props/Default/noise.png -------------------------------------------------------------------------------- /Runtime/Props/Default/normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jedjoud10/VoxelTerrain/HEAD/Runtime/Props/Default/normal.png -------------------------------------------------------------------------------- /Runtime/Utils/noises/voronoise.cginc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jedjoud10/VoxelTerrain/HEAD/Runtime/Utils/noises/voronoise.cginc -------------------------------------------------------------------------------- /Runtime/Shader Graph/Shadows.cginc: -------------------------------------------------------------------------------- 1 | void shadowcaster_float(out bool _out) { 2 | #ifdef UNITY_PASS_SHADOWCASTER 3 | _out = true; 4 | #else 5 | _out = false; 6 | #endif 7 | } -------------------------------------------------------------------------------- /README.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 94e6df6cc1928cd49b8595c459928e99 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /package.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c5a30d77ab891804b8e827b8d2905950 3 | PackageManifestImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Scenes/Demo.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: addfdd812d310e34da776e1506c06fac 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a104355699f02584a8edac985c6e6a77 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 35d14cad66c9be042837fcf16d81ab19 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Scenes/Sample.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 812248f89f59d5249a3c2c84c1aa7a08 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Utils/noises/README.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 76ebee02d62db574483880a01b0555b3 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Utils/sdf.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c283925b9423e5449bdeb57950b34c13 3 | ShaderIncludeImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Mesher.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: dfb4f6aee3909a744a6d820644386b57 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Octree.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0998b2360d83aed4a956046920db725d 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Prefabs/Voxel Chunk.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4d388002189c96345901f85821f1a600 3 | PrefabImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Prefabs/Voxel Terrain.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0e6936411dbff8245ae15ba99cdb64b9 3 | PrefabImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Props.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 747297c67f5507840945f13f65a2b43c 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Scenes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 930c35170a457284e81618a70517f637 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Utils.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1602f297dee2fce41ac66d4e3b5eb783 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Utils/PropUtils.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 14ea883968a7551488a20ce7f1eb0b7c 3 | ShaderIncludeImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Utils/morton.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 93a81becc68522442ab9136f0e54b30b 3 | ShaderIncludeImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Utils/noises.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 949e667c8a3210d449ee95f43889d550 3 | ShaderIncludeImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Editing.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4343222859578e44299d22732e343cf0 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Materials.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 95aeccc786021104ba53333d84e5572e 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Prefabs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1c34c262c2821cb44add12f357d9323d 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Props/Default/Dynamic Edit.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 796109a54e11c9341bd352fdc03d56ba 3 | PrefabImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Segments.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fe1233ddd01e148419a08408a35dbdc7 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Shader Graph/Shadows.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 67e25f0b2f575094c8aaf060622c4e10 3 | ShaderIncludeImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Utils/PropPackUtils.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b409caa6c484fa6439755e344993b23d 3 | ShaderIncludeImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Utils/noises/common.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b21e1bfeb3f4c714ebc469226c458402 3 | ShaderIncludeImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Utils/noises/fbm.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1e0f5688de5fbfd46a2b055cbf16ca8c 3 | ShaderIncludeImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Utils/noises/psrdnoise2D.glsl.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d1332eb3e4f739e42ba49158e9f6f16b 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Voxelizer.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e94b835efd84e7845af59a87d99d7af9 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Editing/Default.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 977a8876d16beb34eb5ba11936934221 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Props/Compute.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 94db4e9ba9291e94db9a8f879ac800ba 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Props/Default.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9a62cc7e17d581f48b98feea5eb0472f 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Props/Default/TestPropPrefab 1.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: df96a2d6604800b40af714ed6b3cfdf0 3 | PrefabImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Props/Default/TestPropPrefab 2.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5e86418390f91554db10ad733d9e7c22 3 | PrefabImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Props/Default/TestPropPrefab.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7b5625836e801c04fbb54c9225ac4663 3 | PrefabImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Props/PropGeneratorEnd.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9bef47c97f8c0b44b8991adbff0f859f 3 | ShaderIncludeImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Props/PropGeneratorStart.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c65ace0f9601a58469006e809396020d 3 | ShaderIncludeImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Shader Graph.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ff5619e29e24f454288e42c0e34f9d7c 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Shader Graph/EulerAngles.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 243d7fb43cbd5ad4c9d6e5dc1cd9cfc1 3 | ShaderIncludeImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Utils/noises.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2fa7fd29f0e0f9345bcb981c89bfa569 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Utils/noises/voronoise.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4f76aefaa37dacb4fa654112bc3b3a8f 3 | ShaderIncludeImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Props/Compute/FreeBlockCopy.compute.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 328bf8d3e8bc49d4588683eb391693fe 3 | ComputeShaderImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Props/Compute/RemoveSegments.compute.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 62d1ba42545233149af3b0666c4246c9 3 | ComputeShaderImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Props/PropGeneratorTemplate.compute.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a564b702928195d4a8a3350466841cf5 3 | ComputeShaderImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Shader Graph/InstancedFetch.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 206d6a2e44f7c8b47873137f2015171b 3 | ShaderIncludeImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Voxelizer/VoxelGeneratorEnd.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 53af72d07ec9bad4a8f2386823cc2b1a 3 | ShaderIncludeImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Voxelizer/VoxelGeneratorStart.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f42c57e335b873b45978d8f711e67e72 3 | ShaderIncludeImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Prefabs/Prop Billboard Capture Camera.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b5f593c8c122c934ca1aef0d4969cb43 3 | PrefabImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Props/Billboard Capture.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8fae631610d391241a3f84a3d6a31604 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Props/Compute/FreeBlockSearch.compute.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fa5b04c4e2be05c4683ba659eb1c2bf5 3 | ComputeShaderImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Props/Compute/PropCullingApply.compute.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b37299e5f05f5004b9698816461e0df3 3 | ComputeShaderImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Props/Compute/PropCullingCopy.compute.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0fc248ebd7631a242afffc4ccdbe1b5e 3 | ComputeShaderImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Props/Compute/SpawnManualProps.compute.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 992c850ac58270149b6f249dd7b07ed1 3 | ShaderIncludeImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Voxelizer/VoxelGeneratorTemplate.compute.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e462ac5da1eeb174ca7f61e9b72917b9 3 | ComputeShaderImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Editor/jedjoud.voxelterraingenerator.editor.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4e180f60acf24804da4ba8c073599d80 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Materials/Grass.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d42681a54f383bb468b6aacca20850bd 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 2100000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/jedjoud.voxelterraingenerator.runtime.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f0062f368b8ff49498c534259edcfc97 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Materials/Checkers.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 62cb0288a0a6372468fe6da7d4a84aa1 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 2100000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Materials/Green Metal.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 40d4a243869c25a48ab2f2de89d94dcd 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 2100000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Materials/Red Metal.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ca1ae838cf2e7d645b7e97efe6deb252 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 2100000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Props/Default/BarkMat.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 466c25623343bb04eb8c6e97d1f198bd 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 2100000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Props/Default/Pine1Mat.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f3c32e94e039f554e93780039b92c785 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 2100000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Props/Default/Pine2Mat.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5430ebc2f560b144981e67f73169d8fc 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 2100000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Props/Default/Pine3Mat.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c39be52b8fcf42b45bfe71795e231d39 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 2100000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Props/Default/TestProp.asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3ab5956d7784dc341b5dcb3cb8b0c70c 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 11400000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Materials/Low Poly Textured 2.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 57308a0e7c9a01549a5120e2775cff75 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 2100000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Materials/Low Poly Textured.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 046aef91378297847971989e13254949 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 2100000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Props/Default/TestProp 1.asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9e91c229f071f1c4e9bdcc0ae525b3d4 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 11400000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Props/Default/TestProp 2.asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6c9186bb4b2e46a418456cc52782e3fd 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 11400000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Materials/Ambient Occlusion Test.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 84a6e112257e25349992cb747d24539e 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 2100000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Materials/Low Poly Textured Slope.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 44ba4b072f5232546b8e3481243824f3 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 2100000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Props/Default/Instanced Material.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f0fed9d70ae7f3146b651b5f23365ea0 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 2100000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Props/Billboard Capture/BillBoardBaseShader.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 646a06c2b757afa4d89f8ee6901875ec 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 2100000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Shader Graph/Shader Graphs_BillBoardShaderGraph.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 90a1024c46a050349b2471586a81e543 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 2100000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Props/Billboard Capture/PropCaptureFullScreenMaterial.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6a57ba25d9097ae498538688f424599b 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 2100000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Props/PropGeneratorEnd.cginc: -------------------------------------------------------------------------------- 1 | // Generates the prop data on the GPU (executed for all prop type available) 2 | [numthreads(4, 4, 4)] 3 | void CSPropenator(uint3 id : SV_DispatchThreadID) 4 | { 5 | float3 position = PropSegmentToWorld(id); 6 | position *= voxelSize; 7 | PropsAt(id, position); 8 | } -------------------------------------------------------------------------------- /Runtime/Props/Billboard Capture/PropCaptureFullScreen.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: eafa6170b9550d94e9b649d2d66ff2c4 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Runtime/Utils/noises/cellular2D.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 35a9997500e7855428f7bb4a848cd40c 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | preprocessorOverride: 0 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Runtime/Utils/noises/cellular3D.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f53d6a3f3e3af4a46ab4a6a78a567ed6 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | preprocessorOverride: 0 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Runtime/Utils/noises/erosion.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8a78fe51fdce5ae469ce7d9fad166540 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | preprocessorOverride: 0 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Runtime/Utils/noises/noise2D.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9249b6a60c50b9b4aa99260338276edc 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | preprocessorOverride: 0 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Runtime/Utils/noises/noise3D.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 24d59ba45794e6a41a4ff1733be35aaf 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | preprocessorOverride: 0 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Runtime/Mesher/SumJob.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3faf6046dd412ab4a8dad96e70dba657 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/TerrainLoader.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 267a861500977894bb1a9f9aa51b5e7d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Utils/Morton.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 60cbeca10691d094d86a3c9a14a62e76 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Utils/Voxel.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a220e2c457c3fa542b2a8967bf3d5bbe 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/VoxelChunk.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6c05b53cee660b74a8787c1bcfe31e4c 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/VoxelTerrain.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 00e1ff5fc0a7fe64db46a425293b5b1f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/CustomEditorProp.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6861ed3d28b7dee4481f3726cd0cb733 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Editing/IVoxelEdit.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 79d72663cc5ae5e4a8d5b75d93a720c2 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Editing/VoxelEdits.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a218ca44eaa006d4a8992f3d71327c68 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Mesher/BakeJob.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4ecc79bc46c3b4746be4bb0b113c0893 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Mesher/CopyJob.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1ce67c44fd8e279428bbe5cffbc47b58 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Mesher/CornerJob.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 67ef58c90fa8c644095adcfc2c65be24 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Mesher/MaterialJob.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 973c7264b158f4347838d383ac61d210 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Mesher/QuadJob.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 125a81e5195ff9840843b99c16e900a6 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Mesher/VertexJob.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 71ca91726f8f1374e8166f23ddc0ed3e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Mesher/VoxelMesh.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6f4c56023ebc9234ba79307e8ecc0fd9 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Mesher/VoxelMesher.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 998d14371a252d844953b5096474c997 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Octree/DiffJob.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3689269e0392a7642a201d9597929134 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Octree/NeigbourJob.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 97a6079d3961d8c43b4bc1961ed807dc 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Octree/OctreeNode.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 18167a2b881368f4c8c58ddf7d94ca75 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Octree/VoxelOctree.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6e787133040bb3d45acfc35df2b68f88 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Props/PropType.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ca249502b12e6574a82400f18da30c2f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Props/VoxelProps.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: efb0edf5fd1e01a4283d253eaa649b4e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Segments/Segment.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fefe7ea7f29b31d4c825ec578a0efce5 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Utils/VoxelUtils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5f9bccd0cbbe4f44491d75a8a1ba2e01 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/CustomEditorVoxelOctree.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2e29144915d50da48b71950ff4ff138b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/CustomEditorVoxelPreview.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d45dc3cfd199cf94d8889e66f1113dd6 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/CustomEditorVoxelRegions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5e6d8a191c4feb84bbffd422342cd023 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/CustomEditorVoxelTerrain.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 93b2c014972aaef4b882042cf36373df 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Editing/DynamicEditJob.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cb119f300874fa74f8711d6ccbbe1fe8 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Editing/IDynamicEdit.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 687f6c6468207d048b57dc44c6a49a62 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Editing/VoxelEditJob.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9cce87902f011c7439e933c20c506c9d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Mesher/MeshJobHandler.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ecb8161a95cd1104daeb3fa88b933284 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Mesher/PendingMeshJob.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 60b27b379f8b8f445bfbb4f7f1672e36 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Mesher/VoxelCollisions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d5bef0f1433829e458439ecec3acd6bc 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Octree/IntersectJob.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9cd25e3036a2ca748b765003550dce41 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Octree/SubdivideJob.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1a78c01d0cd127f4ca5d1e28b28bdb3d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Octree/ToHashSetJob.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8c2d0ded8a90b864d88d8b52a21a1da6 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Props/SerializableProp.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3a011e1492d7819408a5ceb7a9d519ce 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Props/VoxelPropsGpuUtil.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 50e7446635f3ef14183e7dadba5acd21 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Segments/VoxelSegments.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: db5166f307879fe4a8a29401cee62383 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Utils/NativeCounter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f4403b86e4f7d364b92a2659db9549fd 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Utils/NativeExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6693ce0df33825441a3e32b8eabaee25 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Utils/RleCompressionJob.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3a85520fd217f024ea12a17797ca10be 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Utils/TestTerrainEdit.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b15549390a6d38b43a9b80cd914e28a8 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Utils/TestTerrainPlayer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c99f745608ad9684aa21a1a5d06660ec 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Utils/VoxelBehaviour.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 55c9f6f69f070e64fabbb05871e3c2a7 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Editing/Default/AddVoxelEdit.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bf7c27a1f26451646ba06f5898896e82 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Editing/VoxelEditApplyJob.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 84be643ce5bca8141b4c922475d58500 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Editing/VoxelEditOctreeNode.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d660360c9801b494090ee8e3ee5716c3 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Octree/IOctreeSubdivider.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9e71fbfa28c9a5947a9d0c3be650cdd6 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Props/VoxelPropSerializeUtil.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 59f72ae9049ff1b4499feb0b0ba6d506 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Props/VoxelPropsRendering.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 13e34b4a33dfc2d4493e2965e296f288 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Segments/SegmentSpawnJob.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1e1d5827653af36498fce331da2e59e3 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Utils/NativeMultiCounter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d90c6cc6f25b53d4a8cea0de30d3f16a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Utils/RleDecompressionJob.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9e593e441d41be74e8c87d49b840aeff 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Utils/SerializableRegistry.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d2b3d3ddce594a148b8f1d1f7d550a04 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Utils/VoxelCompressionJob.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8fa4057811ac52f458cf4bea92a3f4e6 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Utils/VoxelDecompressionJob.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e3c361fb5439e584ea982c72aac9454e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Utils/VoxelSerialization.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a06ee7f25df53d240bd1d2d33ed794d3 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Voxelizer/VoxelGenerator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 67c1f2da8151ece498d87984ae6dbd90 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Editing/Default/CuboidDynamicEdit.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 499eab92eebf99c4fb054b6e998c043d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Editing/Default/CuboidVoxelEdit.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b60b037daa14e7245ab56f637eb2955b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Editing/Default/FlattenVoxelEdit.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0f1ceb403d836e948b4855448536edcc 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Editing/Default/SphereDynamicEdit.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 42efcb336ad98ca48bdd56a8b749b3cd 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Editing/Default/SphereVoxelEdit.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 76d799d2098462846a060e7afad4efde 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Editing/VoxelEditSubdivisionJob.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5e1b76c46d62da546b40319cdbda45a7 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Octree/DefaultOctreeSubdivider.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3adee1fb8dbbaac43867288c09ae678d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Voxelizer/VoxelReadbackRequest.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3d69202ca82ae23428bdbc333e81d593 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Props/Default/DefaultSerializableProp.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: df4cd5e81118b7548a938181bb880d04 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Mesher/BakeJob.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using Unity.Jobs; 3 | using Unity.Burst; 4 | 5 | 6 | // Bakes the collision mesh for the given voxel meshes 7 | [BurstCompile(CompileSynchronously = true)] 8 | public struct BakeJob : IJob { 9 | public int meshId; 10 | public void Execute() { 11 | Physics.BakeMesh(meshId, false); 12 | } 13 | } -------------------------------------------------------------------------------- /Runtime/Props/Default/DefaultSerializableProp.cs: -------------------------------------------------------------------------------- 1 | using Unity.Netcode; 2 | 3 | public class DefaultSerializableProp : SerializableProp { 4 | public override int Stride => sizeof(int); 5 | public int data; 6 | 7 | public override void NetworkSerialize(BufferSerializer serializer) { 8 | serializer.SerializeValue(ref data); 9 | } 10 | } -------------------------------------------------------------------------------- /Runtime/Shader Graph/LowPoly Shader.shadergraph.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d0ef69fe5c20f614d9be3e3a23295316 3 | ScriptedImporter: 4 | internalIDToNameTable: [] 5 | externalObjects: {} 6 | serializedVersion: 2 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3} 11 | -------------------------------------------------------------------------------- /Runtime/Shader Graph/LowPoly Normals.shadersubgraph.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7dc1736a15179de438693b96f8c4643e 3 | ScriptedImporter: 4 | internalIDToNameTable: [] 5 | externalObjects: {} 6 | serializedVersion: 2 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | script: {fileID: 11500000, guid: 60072b568d64c40a485e0fc55012dc9f, type: 3} 11 | -------------------------------------------------------------------------------- /Runtime/Mesher/PendingMeshJob.cs: -------------------------------------------------------------------------------- 1 | // Queued up mesh job that we are waiting to begin 2 | internal struct PendingMeshJob { 3 | public VoxelChunk chunk; 4 | public bool collisions; 5 | public int maxFrames; 6 | 7 | public static PendingMeshJob Empty = new PendingMeshJob { 8 | chunk = null, 9 | collisions = false, 10 | maxFrames = 0 11 | }; 12 | } -------------------------------------------------------------------------------- /Runtime/Shader Graph/Ambient Occlusion Test.shadergraph.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a499934f25864dd4cadfe64eab78cd6a 3 | ScriptedImporter: 4 | internalIDToNameTable: [] 5 | externalObjects: {} 6 | serializedVersion: 2 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3} 11 | -------------------------------------------------------------------------------- /Runtime/Shader Graph/BillBoardShaderGraph.shadergraph.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c9a17ef61883e5545a843c5b782f2d46 3 | ScriptedImporter: 4 | internalIDToNameTable: [] 5 | externalObjects: {} 6 | serializedVersion: 2 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3} 11 | -------------------------------------------------------------------------------- /Runtime/Shader Graph/FetchBlittableProp.shadersubgraph.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ff679f3f6968327469e7207d772ba606 3 | ScriptedImporter: 4 | internalIDToNameTable: [] 5 | externalObjects: {} 6 | serializedVersion: 2 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | script: {fileID: 11500000, guid: 60072b568d64c40a485e0fc55012dc9f, type: 3} 11 | -------------------------------------------------------------------------------- /Runtime/Shader Graph/InstancedPropShaderGraph.shadergraph.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9e7e9849952d1f14fbe6ae5aa2ce6706 3 | ScriptedImporter: 4 | internalIDToNameTable: [] 5 | externalObjects: {} 6 | serializedVersion: 2 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3} 11 | -------------------------------------------------------------------------------- /Runtime/Shader Graph/InstancedPropSubGraph.shadersubgraph.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a0b50341572110543ab5f325b4bb077e 3 | ScriptedImporter: 4 | internalIDToNameTable: [] 5 | externalObjects: {} 6 | serializedVersion: 2 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | script: {fileID: 11500000, guid: 60072b568d64c40a485e0fc55012dc9f, type: 3} 11 | -------------------------------------------------------------------------------- /Runtime/Shader Graph/LowPoly Shader Slope.shadergraph.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 889e36322ddbaeb469d76930c31e6c18 3 | ScriptedImporter: 4 | internalIDToNameTable: [] 5 | externalObjects: {} 6 | serializedVersion: 2 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3} 11 | -------------------------------------------------------------------------------- /Runtime/Shader Graph/FetchInstancedPropShader.shadersubgraph.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6574c0e01a7844c4fa7f61623bea1946 3 | ScriptedImporter: 4 | internalIDToNameTable: [] 5 | externalObjects: {} 6 | serializedVersion: 2 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | script: {fileID: 11500000, guid: 60072b568d64c40a485e0fc55012dc9f, type: 3} 11 | -------------------------------------------------------------------------------- /Runtime/Shader Graph/LowPoly Chunk Checker Shader.shadergraph.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2f935650640c47841bfe11ff5ce9b6da 3 | ScriptedImporter: 4 | internalIDToNameTable: [] 5 | externalObjects: {} 6 | serializedVersion: 2 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3} 11 | -------------------------------------------------------------------------------- /Runtime/Shader Graph/LowPoly Shader Slope Textured.shadergraph.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1b72af06099531b448b6b9c4f31025d5 3 | ScriptedImporter: 4 | internalIDToNameTable: [] 5 | externalObjects: {} 6 | serializedVersion: 2 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3} 11 | -------------------------------------------------------------------------------- /Runtime/Props/Compute/SpawnManualProps.compute: -------------------------------------------------------------------------------- 1 | struct BlittableProp { 2 | uint2 packed_position_and_scale; 3 | uint2 packed_rotation_dispatch_index_prop_variant_padding; 4 | }; 5 | 6 | int propCount; 7 | RWStructuredBuffer tempProps; 8 | RWStructuredBuffer tempCounters; 9 | StructuredBuffer propSectionOffsets; 10 | 11 | [numthreads(4, 4, 4)] 12 | void CSSpawnManualProp(uint3 id : SV_DispatchThreadID) 13 | { 14 | } -------------------------------------------------------------------------------- /Editor/jedjoud.voxelterraingenerator.editor.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jedjoud.voxelterraingenerator.editor", 3 | "rootNamespace": "", 4 | "references": [ 5 | "GUID:f0062f368b8ff49498c534259edcfc97" 6 | ], 7 | "includePlatforms": [ 8 | "Editor" 9 | ], 10 | "excludePlatforms": [], 11 | "allowUnsafeCode": false, 12 | "overrideReferences": false, 13 | "precompiledReferences": [], 14 | "autoReferenced": true, 15 | "defineConstraints": [], 16 | "versionDefines": [], 17 | "noEngineReferences": false 18 | } -------------------------------------------------------------------------------- /Editor/CustomEditorVoxelRegions.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | 4 | [CustomEditor(typeof(VoxelSegments))] 5 | public class CustomEditorVoxelRegions : Editor 6 | { 7 | public override void OnInspectorGUI() 8 | { 9 | base.OnInspectorGUI(); 10 | 11 | VoxelSegments regions = (VoxelSegments)target; 12 | EditorGUILayout.Space(); 13 | EditorGUILayout.LabelField("Global Prop Segment Count: " + VoxelUtils.PropSegmentsCount); 14 | EditorGUILayout.LabelField("Prop Segment Size: " + VoxelUtils.PropSegmentSize); 15 | } 16 | } -------------------------------------------------------------------------------- /Runtime/Shader Graph/EulerAngles.cginc: -------------------------------------------------------------------------------- 1 | #ifndef EULER_TO_MAT_INCLUDED 2 | #define EULER_TO_MAT_INCLUDED 3 | 4 | void MyFunctionB_float(float3 v, out float3x3 output) 5 | { 6 | float sx, cx; 7 | float sy, cy; 8 | float sz, cz; 9 | 10 | sincos(v.x, sx, cx); 11 | sincos(v.y, sy, cy); 12 | sincos(v.z, sz, cz); 13 | 14 | float3 row1 = float3(sx*sy*sz + cy*cz, sx*sy*cz - cy*sz, cx*sy); 15 | float3 row3 = float3(sx*cy*sz - sy*cz, sx*cy*cz + sy*sz, cx*cy); 16 | float3 row2 = float3(cx*sz, cx*cz, -sx); 17 | 18 | output = float3x3(row1, row2, row3); 19 | } 20 | 21 | #endif -------------------------------------------------------------------------------- /Runtime/Utils/noises/README: -------------------------------------------------------------------------------- 1 | These files contain noise functions that are compatible with all 2 | current versions of GLSL (1.20 and up), and all you need to use them 3 | is provided in the source file. There is no external data, and no 4 | setup procedure. Just cut and paste and call the function. 5 | 6 | GLSL has a very rudimentary linker, so some helper functions are 7 | included in several of the files with the same name. If you want to 8 | use more than one of these functions in the same shader, you may run 9 | into problems with redefinition of the functions mod289() and permute(). 10 | If that happens, just delete any superfluous definitions. 11 | -------------------------------------------------------------------------------- /Editor/CustomEditorVoxelOctree.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | 4 | [CustomEditor(typeof(VoxelOctree))] 5 | public class CustomEditorVoxelOctree : Editor 6 | { 7 | public override void OnInspectorGUI() 8 | { 9 | base.OnInspectorGUI(); 10 | 11 | VoxelOctree octree = (VoxelOctree)target; 12 | float maxSize = Mathf.Pow(2F, (float)octree.maxDepth) * VoxelUtils.VoxelSizeFactor * VoxelUtils.Size; 13 | EditorGUILayout.Space(); 14 | EditorGUILayout.LabelField("Global World Size: " + maxSize + "m"); 15 | EditorGUILayout.LabelField("Global World Volume: " + maxSize * maxSize * maxSize + "m³"); 16 | } 17 | } -------------------------------------------------------------------------------- /Runtime/Utils/VoxelBehaviour.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | // Used internally by the classes that handle terrain 4 | public abstract class VoxelBehaviour : MonoBehaviour 5 | { 6 | // Fetch the parent terrain heheheha 7 | internal protected VoxelTerrain terrain; 8 | 9 | // Initialize the voxel behavior with the given terrain 10 | internal void InitWith(VoxelTerrain terrain) 11 | { 12 | this.terrain = terrain; 13 | Init(); 14 | } 15 | 16 | // Initialize the voxel behaviour (called from the voxel terrain) 17 | internal abstract void Init(); 18 | 19 | // Dispose of any internally stored memory 20 | internal abstract void Dispose(); 21 | } 22 | -------------------------------------------------------------------------------- /Runtime/Voxelizer/VoxelReadbackRequest.cs: -------------------------------------------------------------------------------- 1 | // Generated voxel data from the GPU 2 | // Allows us to check if the readback has finished and if we can use the NativeArray 3 | // Also allows us to Free the native array to give it back to the Voxel Generator for generation 4 | 5 | public class VoxelReadbackRequest : VoxelTempContainer { 6 | public int Index { get; internal set; } 7 | public VoxelGenerator generator; 8 | 9 | // Dispose of the request's memory, giving it back to the VoxelGenerator 10 | public override void TempDispose() { 11 | generator.freeVoxelNativeArrays[Index] = true; 12 | generator.voxelNativeArrays[Index] = voxels; 13 | chunk = null; 14 | } 15 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "displayName": "Voxel Terrain Generator", 3 | "name": "com.jedjoud.voxelterraingenerator", 4 | "version": "1.0.8", 5 | "unity": "2022.3", 6 | "unityRelease": "16f1", 7 | "author": { 8 | "name": "Jed Jribi", 9 | "email": "jribijed6@gmail.com", 10 | "url": "https://github.com/jedjoud10" 11 | }, 12 | "description": "GPU based voxel terrain generator", 13 | "dependencies": { 14 | "com.unity.mathematics": "1.3.1", 15 | "com.unity.burst": "1.8.11", 16 | "com.unity.collections": "2.2.1", 17 | "com.unity.netcode.gameobjects": "1.7.1", 18 | "com.unity.render-pipelines.high-definition": "14.0.9", 19 | "com.unity.render-pipelines.core": "14.0.9" 20 | } 21 | } -------------------------------------------------------------------------------- /Runtime/Utils/noises.cginc: -------------------------------------------------------------------------------- 1 | #include "Packages/com.jedjoud.voxelterraingenerator/Runtime/Utils/noises/common.cginc" 2 | #include "Packages/com.jedjoud.voxelterraingenerator/Runtime/Utils/noises/cellular2D.cginc" 3 | #include "Packages/com.jedjoud.voxelterraingenerator/Runtime/Utils/noises/cellular3D.cginc" 4 | #include "Packages/com.jedjoud.voxelterraingenerator/Runtime/Utils/noises/erosion.cginc" 5 | #include "Packages/com.jedjoud.voxelterraingenerator/Runtime/Utils/noises/noise2D.cginc" 6 | #include "Packages/com.jedjoud.voxelterraingenerator/Runtime/Utils/noises/noise3D.cginc" 7 | #include "Packages/com.jedjoud.voxelterraingenerator/Runtime/Utils/noises/fbm.cginc" 8 | #include "Packages/com.jedjoud.voxelterraingenerator/Runtime/Utils/noises/voronoise.cginc" -------------------------------------------------------------------------------- /Runtime/Octree/DiffJob.cs: -------------------------------------------------------------------------------- 1 | using Unity.Collections; 2 | using Unity.Jobs; 3 | using Unity.Burst; 4 | 5 | // Two of these jobs put out in parallel to handle diffing 6 | [BurstCompile(CompileSynchronously = true)] 7 | public struct DiffJob : IJob { 8 | [ReadOnly] 9 | public NativeHashSet oldNodesHashSet; 10 | 11 | [ReadOnly] 12 | public NativeHashSet newNodesHashSet; 13 | 14 | [WriteOnly] 15 | public NativeList diffedNodes; 16 | 17 | public void Execute() { 18 | diffedNodes.Clear(); 19 | 20 | foreach (var node in oldNodesHashSet) { 21 | if (!newNodesHashSet.Contains(node)) { 22 | diffedNodes.Add(node); 23 | } 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /Runtime/jedjoud.voxelterraingenerator.runtime.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jedjoud.voxelterraingenerator.runtime", 3 | "rootNamespace": "", 4 | "references": [ 5 | "GUID:d8b63aba1907145bea998dd612889d6b", 6 | "GUID:2665a8d13d1b3f18800f46e256720795", 7 | "GUID:e0cd26848372d4e5c891c569017e11f1", 8 | "GUID:1491147abca9d7d4bb7105af628b223e", 9 | "GUID:457756d89b35d2941b3e7b37b4ece6f1", 10 | "GUID:df380645f10b7bc4b97d4f5eb6303d95" 11 | ], 12 | "includePlatforms": [], 13 | "excludePlatforms": [], 14 | "allowUnsafeCode": true, 15 | "overrideReferences": false, 16 | "precompiledReferences": [], 17 | "autoReferenced": true, 18 | "defineConstraints": [], 19 | "versionDefines": [], 20 | "noEngineReferences": false 21 | } -------------------------------------------------------------------------------- /Runtime/Utils/NativeExtensions.cs: -------------------------------------------------------------------------------- 1 | using Unity.Collections.LowLevel.Unsafe; 2 | using Unity.Collections; 3 | 4 | public static class NativeExtensions { 5 | // FOR FUCKS SAKE UNITY WHY ARE YOU SO FUCKING ANNOYING 6 | // Why on GOD's GREEN FUCKING EARTH DO I NEED TO TO DO THIS SHIT I FUCKING HATE YOU GO KILL YOURSELF 7 | // (all love no hate) 8 | // TODO: Submit bug report 9 | public static NativeArray AsNativeArrayExt(this NativeBitArray self) where T : unmanaged { 10 | #if ENABLE_UNITY_COLLECTIONS_CHECKS 11 | AtomicSafetyHandle handle = NativeBitArrayUnsafeUtility.GetAtomicSafetyHandle(self); 12 | #endif 13 | var arr = self.AsNativeArray(); 14 | #if ENABLE_UNITY_COLLECTIONS_CHECKS 15 | NativeBitArrayUnsafeUtility.SetAtomicSafetyHandle(ref self, handle); 16 | #endif 17 | return arr; 18 | } 19 | } -------------------------------------------------------------------------------- /Runtime/Utils/RleCompressionJob.cs: -------------------------------------------------------------------------------- 1 | using Unity.Burst; 2 | using Unity.Collections; 3 | using Unity.Jobs; 4 | 5 | [BurstCompile(CompileSynchronously = true)] 6 | internal struct RleCompressionJob : IJob { 7 | [ReadOnly] 8 | public NativeArray bytesIn; 9 | [WriteOnly] 10 | public NativeList uintsOut; 11 | 12 | // 1 BYTES FOR DATA, 3 BYTES FOR COUNT 13 | // MAX COUNT: 16 MIL 14 | public void Execute() { 15 | byte lastByte = bytesIn[0]; 16 | int byteCount = 0; 17 | for (int i = 0; i < bytesIn.Length; i++) { 18 | byte cur = bytesIn[i]; 19 | if (cur == lastByte) { 20 | byteCount++; 21 | } else { 22 | uintsOut.Add((uint)byteCount << 8 | (uint)lastByte); 23 | lastByte = cur; 24 | byteCount = 1; 25 | } 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /Runtime/Octree/ToHashSetJob.cs: -------------------------------------------------------------------------------- 1 | using Unity.Collections; 2 | using Unity.Jobs; 3 | using Unity.Burst; 4 | 5 | // Two of these jobs put out in parallel to handle diffing 6 | [BurstCompile(CompileSynchronously = true)] 7 | public struct ToHashSetJob : IJob 8 | { 9 | [ReadOnly] 10 | public NativeList oldNodesList; 11 | [WriteOnly] 12 | public NativeHashSet oldNodesHashSet; 13 | 14 | [ReadOnly] 15 | public NativeList newNodesList; 16 | [WriteOnly] 17 | public NativeHashSet newNodesHashSet; 18 | 19 | public void Execute() 20 | { 21 | oldNodesHashSet.Clear(); 22 | newNodesHashSet.Clear(); 23 | 24 | foreach (var node in oldNodesList) 25 | { 26 | oldNodesHashSet.Add(node); 27 | } 28 | 29 | foreach (var node in newNodesList) 30 | { 31 | newNodesHashSet.Add(node); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /Runtime/Props/Billboard Capture/PropCaptureFullScreenMaterial.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 8 6 | m_ObjectHideFlags: 0 7 | m_CorrespondingSourceObject: {fileID: 0} 8 | m_PrefabInstance: {fileID: 0} 9 | m_PrefabAsset: {fileID: 0} 10 | m_Name: PropCaptureFullScreenMaterial 11 | m_Shader: {fileID: 4800000, guid: eafa6170b9550d94e9b649d2d66ff2c4, type: 3} 12 | m_Parent: {fileID: 0} 13 | m_ModifiedSerializedProperties: 0 14 | m_ValidKeywords: [] 15 | m_InvalidKeywords: [] 16 | m_LightmapFlags: 4 17 | m_EnableInstancingVariants: 0 18 | m_DoubleSidedGI: 0 19 | m_CustomRenderQueue: -1 20 | stringTagMap: {} 21 | disabledShaderPasses: [] 22 | m_LockedProperties: 23 | m_SavedProperties: 24 | serializedVersion: 3 25 | m_TexEnvs: [] 26 | m_Ints: 27 | - _RenderAlbedo: 0 28 | m_Floats: [] 29 | m_Colors: [] 30 | m_BuildTextureStacks: [] 31 | -------------------------------------------------------------------------------- /Runtime/Props/Compute/FreeBlockSearch.compute: -------------------------------------------------------------------------------- 1 | #pragma kernel CSFreeBlockSearch 2 | 3 | StructuredBuffer tempCounters; 4 | RWStructuredBuffer tempIndices; 5 | StructuredBuffer usedBitmask; 6 | StructuredBuffer propSectionOffsets; 7 | uint enabledProps; 8 | 9 | // Finds a free index we can use to copy the temp memory to perm memory 10 | [numthreads(32, 1, 1)] 11 | void CSFreeBlockSearch(uint3 id : SV_DispatchThreadID) 12 | { 13 | uint baseIndex = id.x + propSectionOffsets[id.y].y; 14 | uint count = tempCounters[id.y]; 15 | 16 | if (count == 0 || ((enabledProps >> id.y) & 1) == 0) { 17 | return; 18 | } 19 | 20 | // TODO: Eventually fix this by checking whole blocks at once 21 | for (uint i = baseIndex; i < (baseIndex + count); i++) 22 | { 23 | uint block = i / 32; 24 | uint local = i % 32; 25 | if (((usedBitmask[block] >> local) & 1) == 1) { 26 | return; 27 | } 28 | } 29 | 30 | InterlockedMin(tempIndices[id.y], baseIndex); 31 | } -------------------------------------------------------------------------------- /Runtime/Mesher/SumJob.cs: -------------------------------------------------------------------------------- 1 | using Unity.Collections; 2 | using Unity.Jobs; 3 | using Unity.Burst; 4 | 5 | // Sum job that will add the offset of each material onto the last one to have a sequential native array 6 | [BurstCompile(CompileSynchronously = true)] 7 | public struct SumJob : IJobParallelFor { 8 | // Offsets for each material type 9 | [WriteOnly] 10 | public NativeArray materialSegmentOffsets; 11 | 12 | // Multiple counters for each material type 13 | [ReadOnly] 14 | public NativeMultiCounter countersQuad; 15 | 16 | // Global material counter 17 | [ReadOnly] 18 | public NativeCounter materialCounter; 19 | 20 | public void Execute(int index) { 21 | if (index > materialCounter.Count) 22 | return; 23 | 24 | 25 | int sum = 0; 26 | 27 | for (int i = 0; i < index; i++) { 28 | sum += countersQuad[i]; 29 | } 30 | 31 | materialSegmentOffsets[index] = sum * 6; 32 | } 33 | } -------------------------------------------------------------------------------- /Runtime/Mesher/MaterialJob.cs: -------------------------------------------------------------------------------- 1 | using Unity.Collections; 2 | using Unity.Jobs; 3 | using Unity.Burst; 4 | 5 | 6 | // Material job that will count the number of unique materials for the mesh 7 | [BurstCompile(CompileSynchronously = true)] 8 | public struct MaterialJob : IJobParallelFor { 9 | [ReadOnly] 10 | public NativeArray voxels; 11 | 12 | public NativeParallelHashSet.ParallelWriter materialHashSet; 13 | public NativeParallelHashMap.ParallelWriter materialHashMap; 14 | 15 | 16 | // Global material counter 17 | public NativeCounter.Concurrent materialCounter; 18 | 19 | public void Execute(int index) { 20 | Voxel voxel = voxels[index]; 21 | 22 | // Don't care about the material for non-solid terrain 23 | if (voxel.density < 0.0) { 24 | if (materialHashSet.Add(voxel.material)) { 25 | materialHashMap.TryAdd(voxel.material, materialCounter.Increment()); 26 | } 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /Runtime/Shader Graph/InstancedFetch.cginc: -------------------------------------------------------------------------------- 1 | #ifndef INSTANCED_FETCH_INCLUDED 2 | #define INSTANCED_FETCH_INCLUDED 3 | 4 | #include "Packages/com.jedjoud.voxelterraingenerator/Runtime/Utils/PropPackUtils.cginc" 5 | 6 | struct BlittableProp { 7 | uint2 packed_position_and_scale; 8 | uint2 packed_euler_angles_id; 9 | }; 10 | 11 | StructuredBuffer _BlittablePropBuffer; 12 | 13 | StructuredBuffer _PropSectionOffsets; 14 | float _PropType; 15 | 16 | void MyFunctionA_float(float i, out float variant, out float3 position, out float scale, out float3 rotation) 17 | { 18 | BlittableProp prop = _BlittablePropBuffer[(int)i + _PropSectionOffsets[(int)_PropType].z]; 19 | 20 | float4 unpackedPosScale = UnpackPositionAndScale(prop.packed_position_and_scale); 21 | variant = UnpackVariant(prop.packed_euler_angles_id); 22 | position = unpackedPosScale.xyz; 23 | scale = unpackedPosScale.w; 24 | rotation = UnpackRotation(prop.packed_euler_angles_id); 25 | } 26 | 27 | #endif -------------------------------------------------------------------------------- /Runtime/Mesher/VoxelMesh.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | // The generated voxel mesh that we can render to the player 4 | public struct VoxelMesh 5 | { 6 | // Actual mesh reference (which is stored inside the chunk anyways) 7 | public Mesh SharedMesh { get; internal set; } 8 | 9 | // Lookup for converting sub-mesh index to voxel material index 10 | public int[] VoxelMaterialsLookup { get; internal set; } 11 | 12 | // Should we compute collisions for this voxel mesh? 13 | public bool ComputeCollisions { get; internal set; } 14 | 15 | // Total number of vertices used by this mesh 16 | public int VertexCount { get; internal set; } 17 | 18 | // Total number of triangles used by this mesh 19 | public int TriangleCount { get; internal set; } 20 | 21 | public static VoxelMesh Empty = new VoxelMesh 22 | { 23 | SharedMesh = null, 24 | VoxelMaterialsLookup = null, 25 | VertexCount = 0, 26 | TriangleCount = 0, 27 | ComputeCollisions = false, 28 | }; 29 | } -------------------------------------------------------------------------------- /Runtime/Utils/RleDecompressionJob.cs: -------------------------------------------------------------------------------- 1 | using Unity.Burst; 2 | using Unity.Collections; 3 | using Unity.Jobs; 4 | 5 | [BurstCompile(CompileSynchronously = true)] 6 | internal struct RleDecompressionJob : IJob { 7 | public byte defaultValue; 8 | [WriteOnly] 9 | public NativeArray bytesOut; 10 | [ReadOnly] 11 | public NativeArray uintsIn; 12 | 13 | // 1 BYTES FOR DATA, 3 BYTES FOR COUNT 14 | // MAX COUNT: 16 MIL 15 | public void Execute() { 16 | int byteOffset = 0; 17 | for (int j = 0; j < uintsIn.Length; j++) { 18 | uint compressed = uintsIn[j]; 19 | int count = (int)(compressed & ~0xFF) >> 8; 20 | byte value = (byte)(compressed & 0xFF); 21 | 22 | for (int k = 0; k < count; k++) { 23 | bytesOut[k + byteOffset] = value; 24 | } 25 | 26 | byteOffset += count; 27 | } 28 | 29 | for (int i = byteOffset; i < bytesOut.Length; i++) { 30 | bytesOut[i] = defaultValue; 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /Editor/CustomEditorVoxelTerrain.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | 4 | [CustomEditor(typeof(VoxelTerrain))] 5 | public class CustomEditorVoxelTerrain : Editor { 6 | public override bool RequiresConstantRepaint() { 7 | return true; 8 | } 9 | 10 | public override void OnInspectorGUI() { 11 | base.OnInspectorGUI(); 12 | 13 | float voxelSize = VoxelUtils.VoxelSizeFactor; 14 | EditorGUILayout.Space(); 15 | EditorGUILayout.LabelField("Voxel Size: " + voxelSize + "m"); 16 | 17 | VoxelTerrain terrain = ((VoxelTerrain)target); 18 | GUI.enabled = terrain.Free; 19 | if (GUILayout.Button("Regenerate")) { 20 | terrain.VoxelGenerator.UpdateStaticComputeFields(); 21 | terrain.VoxelProps.UpdateStaticComputeFields(); 22 | terrain.VoxelSegments.RegenerateRegions(); 23 | terrain.RequestAll(true); 24 | } 25 | if (GUILayout.Button("Remesh")) { 26 | terrain.RequestAll(false); 27 | } 28 | GUI.enabled = true; 29 | } 30 | } -------------------------------------------------------------------------------- /Runtime/Props/Compute/RemoveSegments.compute: -------------------------------------------------------------------------------- 1 | #pragma kernel CSRemoveSegments 2 | 3 | int propCount; 4 | int segmentsToRemoveCount; 5 | StructuredBuffer segmentIndices; 6 | RWStructuredBuffer segmentIndexCount; 7 | RWStructuredBuffer usedBitmask; 8 | 9 | // Delete the bits set inside the bitmask for multiple segments at once 10 | [numthreads(32, 1, 1)] 11 | void CSRemoveSegments(uint3 id : SV_DispatchThreadID) 12 | { 13 | if (id.x >= (uint)segmentsToRemoveCount) { 14 | return; 15 | } 16 | 17 | int index = segmentIndices[id.x]; 18 | 19 | if (index == -1) { 20 | return; 21 | } 22 | 23 | int tahiniIndex = index * propCount + id.y; 24 | uint2 vals = segmentIndexCount[tahiniIndex]; 25 | 26 | 27 | // last hope to avoid dx11 driver crash 28 | if (vals.y > 1000000 || vals.x > 1000000) { 29 | return; 30 | } 31 | 32 | for (uint i = vals.x; i < (vals.x + vals.y); i++) 33 | { 34 | uint block = i / 32; 35 | uint local = i % 32; 36 | InterlockedAnd(usedBitmask[block], !(1 << local)); 37 | } 38 | 39 | segmentIndexCount[tahiniIndex] = uint2(0, 0); 40 | } -------------------------------------------------------------------------------- /Runtime/Segments/Segment.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Unity.Mathematics; 3 | using UnityEngine; 4 | 5 | // A voxel region is used to generate props and structures 6 | // Voxel regions are stored in the main voxel regions terrain component 7 | // We must split the world in equal "regions" so that prop spawn density and 8 | // structure spawn density stay the same across LODs, otherwise density would not be consistent 9 | public class Segment { 10 | // Internal position 11 | public int3 regionPosition; 12 | 13 | // World space position 14 | public Vector3 worldPosition; 15 | 16 | // Basically denotes how close the user is to the prop region 17 | public bool spawnPrefabs; 18 | 19 | // Props that are handled by this prop region 20 | // Assumes that there is a maximum of 1 variant per type per dispatch group 21 | public Dictionary, List)> props; 22 | 23 | // Lookup index we use when destroying this prop region and need to get rid of the billboards or instanced props 24 | public int indexRangeLookup; 25 | } -------------------------------------------------------------------------------- /Runtime/Utils/PropUtils.cginc: -------------------------------------------------------------------------------- 1 | #include "Packages/com.jedjoud.voxelterraingenerator/Runtime/Utils/PropPackUtils.cginc" 2 | 3 | float3 PropSegmentToWorld(float3 id) { 4 | // Calculate the main world position 5 | float3 position = id.xzy; 6 | 7 | position *= (propSegmentResolution + 1) / propSegmentResolution; 8 | position *= propSegmentWorldSize / propSegmentResolution; 9 | position += propChunkOffset; 10 | 11 | // World offset and scale 12 | position *= (1 / voxelSize); 13 | position = (position * worldScale) + worldOffset; 14 | return position; 15 | } 16 | 17 | float3 WorldToPropSegment(float3 world) { 18 | // World offset and scale 19 | float3 gridPos = world - worldOffset; 20 | gridPos /= worldScale; 21 | 22 | // Inverse of PropSegmentToWorld 23 | gridPos -= propChunkOffset; 24 | gridPos /= propSegmentWorldSize / propSegmentResolution; 25 | gridPos /= (propSegmentResolution + 1) / propSegmentResolution; 26 | return float3(gridPos.xzy / propSegmentResolution); 27 | } 28 | 29 | float invLerp(float from, float to, float value) { 30 | return (value - from) / (to - from); 31 | } -------------------------------------------------------------------------------- /Runtime/Voxelizer/VoxelGeneratorStart.cginc: -------------------------------------------------------------------------------- 1 | // Chunk offset + scale 2 | float3 chunkOffset; 3 | float chunkScale; 4 | 5 | // World parameters 6 | float3 worldOffset; 7 | float3 worldScale; 8 | float densityOffset; 9 | 10 | // Seeding parameters 11 | int3 permuationSeed; 12 | int3 moduloSeed; 13 | 14 | // Voxel resolution 15 | int size; 16 | float vertexScaling; 17 | float voxelSize; 18 | 19 | // Used for async readback 20 | RWTexture3D voxels; 21 | 22 | // PREVIEW MODE 23 | RWTexture3D previewVoxels; 24 | float previewDensityFactor; 25 | float previewDensityOffset; 26 | 27 | float propSegmentWorldSize; 28 | float propSegmentResolution; 29 | float3 propChunkOffset; 30 | RWTexture3D cachedPropDensities; 31 | 32 | RWTexture2DArray positionIntersections; 33 | 34 | #include "Packages/com.jedjoud.voxelterraingenerator/Runtime/Utils/Noises.cginc" 35 | #include "Packages/com.jedjoud.voxelterraingenerator/Runtime/Utils/SDF.cginc" 36 | #include "Packages/com.jedjoud.voxelterraingenerator/Runtime/Utils/Morton.cginc" 37 | #include "Packages/com.jedjoud.voxelterraingenerator/Runtime/Utils/PropUtils.cginc" 38 | 39 | -------------------------------------------------------------------------------- /Runtime/Props/Default/TestProp 1.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!114 &11400000 4 | MonoBehaviour: 5 | m_ObjectHideFlags: 0 6 | m_CorrespondingSourceObject: {fileID: 0} 7 | m_PrefabInstance: {fileID: 0} 8 | m_PrefabAsset: {fileID: 0} 9 | m_GameObject: {fileID: 0} 10 | m_Enabled: 1 11 | m_EditorHideFlags: 0 12 | m_Script: {fileID: 11500000, guid: ca249502b12e6574a82400f18da30c2f, type: 3} 13 | m_Name: TestProp 1 14 | m_EditorClassIdentifier: 15 | variants: [] 16 | propSpawnBehavior: 9 17 | maxPropsPerSegment: 8192 18 | maxPropsInTotal: 524288 19 | maxVisibleProps: 524288 20 | maxInstancingDistance: 1000 21 | instancedMeshMaterial: {fileID: 2100000, guid: f0fed9d70ae7f3146b651b5f23365ea0, 22 | type: 2} 23 | instancedMesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} 24 | billboardTextureWidth: 64 25 | billboardTextureHeight: 64 26 | billboardMipMaps: 1 27 | billboardTextureFilterMode: 1 28 | billboardSize: {x: 1, y: 1} 29 | billboardOffset: {x: 0, y: 3, z: 0} 30 | billboardSizeOrigin: {x: 0, y: 0, z: 0} 31 | instancesRestrictRotationY: 0 32 | instancesCastShadows: 0 33 | -------------------------------------------------------------------------------- /Runtime/Props/Compute/PropCullingApply.compute: -------------------------------------------------------------------------------- 1 | #pragma kernel CSPropCullingApply 2 | #define UNITY_INDIRECT_DRAW_ARGS IndirectDrawIndexedArgs 3 | #include "UnityIndirect.cginc" 4 | 5 | int propCount; 6 | RWStructuredBuffer culledCount; 7 | RWStructuredBuffer drawArgs; 8 | StructuredBuffer meshIndexCountPerInstance; 9 | 10 | // Do some culling on the props and save them to the culled props buffer 11 | [numthreads(32, 1, 1)] 12 | void CSPropCullingApply(uint3 id : SV_DispatchThreadID) 13 | { 14 | if (id.x < (uint)propCount) { 15 | IndirectDrawIndexedArgs args; 16 | args.indexCountPerInstance = meshIndexCountPerInstance[id.x]; 17 | args.instanceCount = culledCount[id.x]; 18 | 19 | if (id.x == 1) { 20 | //args.instanceCount = 0; 21 | } 22 | 23 | args.startIndex = 0; 24 | args.baseVertexIndex = 0; 25 | 26 | // normally I'd have the visibility offset applied here but it seems to not work 27 | // so I'm manually adding it in the fucking shader graph custom func 28 | // Unity why do you have to be so FUCKING annoying sometimes? 29 | // Can't have shit mate 30 | args.startInstance = 0; 31 | drawArgs[id.x] = args; 32 | } 33 | } -------------------------------------------------------------------------------- /Runtime/Utils/morton.cginc: -------------------------------------------------------------------------------- 1 | // Morton encoding from 2 | // Stolen from https://github.com/johnsietsma/InfPoints/blob/master/com.infpoints/Runtime/Morton.cs 3 | uint part1By2_32(uint x) 4 | { 5 | x &= 0x3FF; // x = ---- ---- ---- ---- ---- --98 7654 3210 6 | x = (x ^ (x << 16)) & 0xFF0000FF; // x = ---- --98 ---- ---- ---- ---- 7654 3210 7 | x = (x ^ (x << 8)) & 0x300F00F; // x = ---- --98 ---- ---- 7654 ---- ---- 3210 8 | x = (x ^ (x << 4)) & 0x30C30C3; // x = ---- --98 ---- 76-- --54 ---- 32-- --10 9 | x = (x ^ (x << 2)) & 0x9249249; // x = ---- 9--8 --7- -6-- 5--4 --3- -2-- 1--0 10 | return x; 11 | } 12 | 13 | uint encodeMorton32(uint3 coordinate) 14 | { 15 | return (part1By2_32(coordinate.z) << 2) + (part1By2_32(coordinate.y) << 1) + part1By2_32(coordinate.x); 16 | } 17 | 18 | 19 | // taken from the voxels utils class 20 | uint3 indexToPos(uint index) 21 | { 22 | // N(ABC) -> N(A) x N(BC) 23 | uint y = index / (size * size); // x in N(A) 24 | uint w = index % (size * size); // w in N(BC) 25 | 26 | // N(BC) -> N(B) x N(C) 27 | uint z = w / size;// y in N(B) 28 | uint x = w % size; // z in N(C) 29 | return uint3(x, y, z); 30 | } -------------------------------------------------------------------------------- /Runtime/Editing/Default/SphereVoxelEdit.cs: -------------------------------------------------------------------------------- 1 | using Unity.Collections; 2 | using Unity.Jobs; 3 | using Unity.Mathematics; 4 | using UnityEngine; 5 | 6 | [assembly: RegisterGenericJobType(typeof(VoxelEditJob))] 7 | public struct SphereVoxelEdit : IVoxelEdit { 8 | [ReadOnly] public float3 center; 9 | [ReadOnly] public float radius; 10 | [ReadOnly] public float strength; 11 | [ReadOnly] public byte material; 12 | [ReadOnly] public bool writeMaterial; 13 | 14 | public JobHandle Apply(SparseVoxelDeltaData data) { 15 | return IVoxelEdit.ApplyGeneric(data, this); 16 | } 17 | 18 | public Bounds GetBounds() { 19 | return new Bounds { 20 | center = center, 21 | extents = new Vector3(radius, radius, radius), 22 | }; 23 | } 24 | 25 | public Voxel Modify(float3 position, Voxel lastDelta) { 26 | Voxel voxel = lastDelta; 27 | float density = math.length(position - center) - radius; 28 | voxel.material = (density < 1.0F && writeMaterial) ? material : voxel.material; 29 | voxel.density = (density < 0.0F) ? (half)(density * strength) : lastDelta.density; 30 | return voxel; 31 | } 32 | } -------------------------------------------------------------------------------- /Runtime/Octree/DefaultOctreeSubdivider.cs: -------------------------------------------------------------------------------- 1 | using Unity.Collections; 2 | using Unity.Jobs; 3 | using Unity.Mathematics; 4 | 5 | // Default implementation of the octree subdivider 6 | [assembly: RegisterGenericJobType(typeof(SubdivideJob))] 7 | public struct DefaultOctreeSubdivider : IOctreeSubdivider { 8 | public float propSegmentWorldSize; 9 | public float2 yPositionBounds; 10 | 11 | public JobHandle Apply(TerrainLoader.Target target, NativeList nodes, NativeQueue pending) { 12 | return IOctreeSubdivider.ApplyGeneric(target, nodes, pending, this); 13 | } 14 | 15 | public bool ShouldSubdivide(ref OctreeNode node, ref TerrainLoader.Target target) { 16 | float3 minBounds = math.float3(node.position); 17 | float3 maxBounds = math.float3(node.position) + math.float3(node.size); 18 | bool intersects = maxBounds.y > yPositionBounds.x && minBounds.y < yPositionBounds.y; 19 | 20 | float3 clamped = math.clamp(target.center, minBounds, maxBounds); 21 | bool subdivide = math.distance(clamped, target.center) < target.radius * node.scalingFactor; 22 | 23 | return subdivide && intersects; 24 | } 25 | } -------------------------------------------------------------------------------- /Runtime/Editing/DynamicEditJob.cs: -------------------------------------------------------------------------------- 1 | using Unity.Burst; 2 | using Unity.Collections; 3 | using Unity.Jobs; 4 | using Unity.Mathematics; 5 | 6 | // Edit job for dynamic edits 7 | [BurstCompile(CompileSynchronously = true)] 8 | struct DynamicEditJob : IJobParallelFor 9 | where T : struct, IDynamicEdit { 10 | [ReadOnly] public float3 chunkOffset; 11 | [ReadOnly] public float voxelScale; 12 | [ReadOnly] public int size; 13 | [ReadOnly] public float vertexScaling; 14 | [ReadOnly] public float scalingFactor; 15 | 16 | public T dynamicEdit; 17 | public NativeArray voxels; 18 | 19 | public void Execute(int index) { 20 | uint3 id = VoxelUtils.IndexToPos(index); 21 | float3 position = (math.float3(id)); 22 | 23 | // Needed for voxel size reduction 24 | position *= voxelScale; 25 | position -= 1.5f * voxelScale; 26 | 27 | //position -= math.float3(1); 28 | position *= vertexScaling; 29 | position *= scalingFactor; 30 | position += chunkOffset; 31 | 32 | // Read, modify, write 33 | voxels[index] = dynamicEdit.Modify(position, voxels[index]); 34 | //voxels[index] = Voxel.Empty; 35 | } 36 | } -------------------------------------------------------------------------------- /Runtime/Editing/VoxelEditApplyJob.cs: -------------------------------------------------------------------------------- 1 | using Unity.Burst; 2 | using Unity.Collections; 3 | using Unity.Collections.LowLevel.Unsafe; 4 | using Unity.Jobs; 5 | using Unity.Mathematics; 6 | 7 | [BurstCompile(CompileSynchronously = true)] 8 | public struct VoxelEditApplyJob : IJobParallelFor { 9 | public NativeArray voxels; 10 | [ReadOnly] public SparseVoxelDeltaData data; 11 | 12 | public NativeMultiCounter.Concurrent counters; 13 | 14 | public void Execute(int index) { 15 | half deltaDensity = data.densities[index]; 16 | byte deltaMaterial = data.materials[index]; 17 | Voxel cur = voxels[index]; 18 | 19 | if (deltaMaterial != byte.MaxValue) { 20 | cur.material = deltaMaterial; 21 | } 22 | 23 | half oldDensity = cur.density; 24 | cur.density += VoxelUtils.NormalizeHalf(deltaDensity); 25 | half newDensity = cur.density; 26 | 27 | if (newDensity > 0.0f && oldDensity < 0.0f) { 28 | counters.Increment(cur.material); 29 | } else if (newDensity < 0.0f && oldDensity > 0.0f) { 30 | counters.Decrement(cur.material); 31 | } 32 | 33 | voxels[index] = cur; 34 | } 35 | } -------------------------------------------------------------------------------- /Runtime/Octree/IOctreeSubdivider.cs: -------------------------------------------------------------------------------- 1 | using Unity.Collections; 2 | using Unity.Jobs; 3 | using System.Runtime.CompilerServices; 4 | 5 | // Custom octree subdivier to allow end users to handle custom octree subdivision logic 6 | public interface IOctreeSubdivider { 7 | // Should we subdivide the given node? 8 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 9 | public bool ShouldSubdivide(ref OctreeNode node, ref TerrainLoader.Target target); 10 | 11 | // MUST CALL THE "ApplyGeneric" function because we can't hide away generics 12 | public JobHandle Apply(TerrainLoader.Target target, NativeList nodes, NativeQueue pending); 13 | 14 | // Apply any generic octree subdivider edit onto the octree 15 | internal static JobHandle ApplyGeneric(TerrainLoader.Target target, NativeList nodes, NativeQueue pending, T subdivider) where T : struct, IOctreeSubdivider { 16 | SubdivideJob job = new SubdivideJob { 17 | target = target, 18 | nodes = nodes, 19 | pending = pending, 20 | maxDepth = VoxelUtils.MaxDepth, 21 | subdivider = subdivider, 22 | }; 23 | return job.Schedule(); 24 | } 25 | } -------------------------------------------------------------------------------- /Runtime/Editing/Default/AddVoxelEdit.cs: -------------------------------------------------------------------------------- 1 | using Unity.Collections; 2 | using Unity.Jobs; 3 | using Unity.Mathematics; 4 | using UnityEngine; 5 | 6 | [assembly: RegisterGenericJobType(typeof(VoxelEditJob))] 7 | 8 | // Will either add / remove matter from the terrain 9 | public struct AddVoxelEdit : IVoxelEdit { 10 | [ReadOnly] public float3 center; 11 | [ReadOnly] public float strength; 12 | [ReadOnly] public float radius; 13 | [ReadOnly] public byte material; 14 | [ReadOnly] public bool writeMaterial; 15 | 16 | public JobHandle Apply(SparseVoxelDeltaData data) { 17 | return IVoxelEdit.ApplyGeneric(data, this); 18 | } 19 | 20 | public Bounds GetBounds() { 21 | return new Bounds { 22 | center = center, 23 | extents = new Vector3(radius, radius, radius) 24 | }; 25 | } 26 | 27 | public Voxel Modify(float3 position, Voxel lastDelta) { 28 | Voxel voxel = lastDelta; 29 | float density = math.length(position - center) - radius; 30 | voxel.material = (density < 1.0F && writeMaterial && strength < 0) ? material : voxel.material; 31 | voxel.density = (density < 0.0F) ? (half)(lastDelta.density + strength) : lastDelta.density; 32 | return voxel; 33 | } 34 | } -------------------------------------------------------------------------------- /Runtime/Editing/Default/CuboidVoxelEdit.cs: -------------------------------------------------------------------------------- 1 | using Unity.Collections; 2 | using Unity.Jobs; 3 | using Unity.Mathematics; 4 | using UnityEngine; 5 | 6 | [assembly: RegisterGenericJobType(typeof(VoxelEditJob))] 7 | public struct CuboidVoxelEdit : IVoxelEdit { 8 | [ReadOnly] public float3 center; 9 | [ReadOnly] public float3 halfExtents; 10 | [ReadOnly] public float strength; 11 | [ReadOnly] public byte material; 12 | [ReadOnly] public bool writeMaterial; 13 | 14 | public JobHandle Apply(SparseVoxelDeltaData data) { 15 | return IVoxelEdit.ApplyGeneric(data, this); 16 | } 17 | 18 | public Bounds GetBounds() { 19 | return new Bounds { 20 | center = center, 21 | extents = halfExtents 22 | }; 23 | } 24 | 25 | public Voxel Modify(float3 position, Voxel lastDelta) { 26 | float3 q = math.abs(position - center) - halfExtents; 27 | float density = math.length(math.max(q, 0.0F)) + math.min(math.max(q.x, math.max(q.y, q.z)), 0.0F); 28 | 29 | Voxel voxel = lastDelta; 30 | voxel.material = (density < 1.0F && writeMaterial) ? material : voxel.material; 31 | voxel.density = (density < 0.0F) ? (half)(strength) : lastDelta.density; 32 | return voxel; 33 | } 34 | } -------------------------------------------------------------------------------- /Runtime/Props/Default/TestProp 2.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!114 &11400000 4 | MonoBehaviour: 5 | m_ObjectHideFlags: 0 6 | m_CorrespondingSourceObject: {fileID: 0} 7 | m_PrefabInstance: {fileID: 0} 8 | m_PrefabAsset: {fileID: 0} 9 | m_GameObject: {fileID: 0} 10 | m_Enabled: 1 11 | m_EditorHideFlags: 0 12 | m_Script: {fileID: 11500000, guid: ca249502b12e6574a82400f18da30c2f, type: 3} 13 | m_Name: TestProp 2 14 | m_EditorClassIdentifier: 15 | variants: 16 | - prefab: {fileID: 5706152555069415400, guid: 796109a54e11c9341bd352fdc03d56ba, 17 | type: 3} 18 | billboardCaptureCameraScale: 0 19 | billboardCaptureRotation: {x: 0, y: 0, z: 0} 20 | billboardCapturePosition: {x: 0, y: 0, z: 0} 21 | propSpawnBehavior: 0 22 | maxPropsPerSegment: 8192 23 | maxPropsInTotal: 524288 24 | maxVisibleProps: 524288 25 | maxInstancingDistance: 100 26 | instancedMeshMaterial: {fileID: 0} 27 | instancedMesh: {fileID: 0} 28 | billboardTextureWidth: 64 29 | billboardTextureHeight: 64 30 | billboardMipMaps: 1 31 | billboardTextureFilterMode: 1 32 | billboardSize: {x: 1, y: 1} 33 | billboardOffset: {x: 0, y: 3, z: 0} 34 | billboardSizeOrigin: {x: 0, y: 0, z: 0} 35 | instancesRestrictRotationY: 0 36 | instancesCastShadows: 0 37 | -------------------------------------------------------------------------------- /Runtime/Editing/Default/FlattenVoxelEdit.cs: -------------------------------------------------------------------------------- 1 | using Unity.Collections; 2 | using Unity.Jobs; 3 | using Unity.Mathematics; 4 | using UnityEngine; 5 | 6 | [assembly: RegisterGenericJobType(typeof(VoxelEditJob))] 7 | 8 | // Flatten the terrain using the current normal and position 9 | // Kinda like the flatten thing in astroneer 10 | public struct FlattenVoxelEdit : IVoxelEdit { 11 | [ReadOnly] public float3 center; 12 | [ReadOnly] public float3 normal; 13 | [ReadOnly] public float strength; 14 | [ReadOnly] public float radius; 15 | 16 | public JobHandle Apply(SparseVoxelDeltaData data) { 17 | return IVoxelEdit.ApplyGeneric(data, this); 18 | } 19 | 20 | public Bounds GetBounds() { 21 | return new Bounds { 22 | center = center, 23 | extents = new Vector3(radius, radius, radius) 24 | }; 25 | } 26 | 27 | public Voxel Modify(float3 position, Voxel lastDelta) { 28 | Voxel voxel = lastDelta; 29 | float density = math.length(position - center) - radius; 30 | float mask = math.saturate(density); 31 | float oldDensity = lastDelta.density; 32 | float planeDensity = math.dot(normal, position - center); 33 | float newDensity = (half)(lastDelta.density + strength * planeDensity); 34 | voxel.density = (half)math.lerp(newDensity, oldDensity, mask); 35 | 36 | 37 | return voxel; 38 | } 39 | } -------------------------------------------------------------------------------- /Runtime/Editing/IVoxelEdit.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.CompilerServices; 2 | using Unity.Jobs; 3 | using Unity.Mathematics; 4 | using UnityEngine; 5 | 6 | // Interface for voxel edits that has a unique job for creating the delta voxel diffs that we will serialize 7 | public interface IVoxelEdit { 8 | // Create the delta voxel modifications (without having to read the inner voxel data) 9 | // The given input Voxel is the last delta value (for continuous edits) 10 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 11 | public Voxel Modify(float3 position, Voxel lastDelta); 12 | 13 | // Get the AABB bounds of this voxel edit 14 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 15 | public Bounds GetBounds(); 16 | 17 | // MUST CALL THE "ApplyGeneric" function because we can't hide away generics 18 | public JobHandle Apply(SparseVoxelDeltaData data); 19 | 20 | // Apply any generic voxel edit onto oncoming data 21 | internal static JobHandle ApplyGeneric(SparseVoxelDeltaData data, T edit) where T : struct, IVoxelEdit { 22 | VoxelEditJob job = new VoxelEditJob { 23 | chunkOffset = data.position, 24 | scalingFactor = data.scalingFactor, 25 | voxelScale = VoxelUtils.VoxelSizeFactor, 26 | size = VoxelUtils.Size, 27 | vertexScaling = VoxelUtils.VertexScaling, 28 | edit = edit, 29 | densities = data.densities, 30 | materials = data.materials, 31 | }; 32 | return job.Schedule(VoxelUtils.Volume, 2048 * 16); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Runtime/Props/Compute/FreeBlockCopy.compute: -------------------------------------------------------------------------------- 1 | #pragma kernel CSFreeBlockCopy 2 | 3 | // Input and output buffers 4 | int segmentLookup; 5 | int propCount; 6 | RWStructuredBuffer segmentIndexCount; 7 | 8 | StructuredBuffer tempCounters; 9 | RWStructuredBuffer tempIndices; 10 | 11 | StructuredBuffer tempProps; 12 | RWStructuredBuffer permProps; 13 | RWStructuredBuffer usedBitmask; 14 | 15 | StructuredBuffer propSectionOffsets; 16 | 17 | // Copy the temporary prop buffer to the permanent prop buffer 18 | [numthreads(32, 1, 1)] 19 | void CSFreeBlockCopy(uint3 id : SV_DispatchThreadID) 20 | { 21 | int counter = tempCounters[id.y]; 22 | 23 | // already comes with the perm offset applied 24 | uint baseFreeIndex = tempIndices[id.y]; 25 | 26 | // nothing to spawn 27 | if (counter == 0 || baseFreeIndex == 0xffffffff) { 28 | segmentIndexCount[segmentLookup * propCount + id.y] = uint2(0, 0); 29 | return; 30 | } 31 | 32 | // set the index count uint2 only by one dispatch group 33 | if (id.x == 0) { 34 | segmentIndexCount[segmentLookup * propCount + id.y] = uint2(baseFreeIndex, counter); 35 | } 36 | 37 | // quite if 2 much 4 us 38 | if ((id.x) >= (uint)counter) { 39 | return; 40 | } 41 | 42 | // copy data to perm spot 43 | permProps[id.x + baseFreeIndex] = tempProps[id.x + propSectionOffsets[id.y].x]; 44 | 45 | // also update the bitmask whilst we're at it 46 | uint bitmaskIndex = id.x + baseFreeIndex; 47 | uint block = bitmaskIndex / 32; 48 | uint local = bitmaskIndex % 32; 49 | InterlockedOr(usedBitmask[block], 1 << local); 50 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # This .gitignore file should be placed at the root of your Unity project directory 2 | # 3 | # Get latest from https://github.com/github/gitignore/blob/main/Unity.gitignore 4 | # 5 | /[Ll]ibrary/ 6 | /[Tt]emp/ 7 | /[Oo]bj/ 8 | /[Bb]uild/ 9 | /[Bb]uilds/ 10 | /[Ll]ogs/ 11 | /[Uu]ser[Ss]ettings/ 12 | 13 | # MemoryCaptures can get excessive in size. 14 | # They also could contain extremely sensitive data 15 | /[Mm]emoryCaptures/ 16 | 17 | # Recordings can get excessive in size 18 | /[Rr]ecordings/ 19 | 20 | # Uncomment this line if you wish to ignore the asset store tools plugin 21 | # /[Aa]ssets/AssetStoreTools* 22 | 23 | # Autogenerated Jetbrains Rider plugin 24 | /[Aa]ssets/Plugins/Editor/JetBrains* 25 | 26 | # Visual Studio cache directory 27 | .vs/ 28 | 29 | # Gradle cache directory 30 | .gradle/ 31 | 32 | # Autogenerated VS/MD/Consulo solution and project files 33 | ExportedObj/ 34 | .consulo/ 35 | *.csproj 36 | *.unityproj 37 | *.sln 38 | *.suo 39 | *.tmp 40 | *.user 41 | *.userprefs 42 | *.pidb 43 | *.booproj 44 | *.svd 45 | *.pdb 46 | *.mdb 47 | *.opendb 48 | *.VC.db 49 | 50 | # Unity3D generated meta files 51 | *.pidb.meta 52 | *.pdb.meta 53 | *.mdb.meta 54 | 55 | # Unity3D generated file on crash reports 56 | sysinfo.txt 57 | 58 | # Builds 59 | *.apk 60 | *.aab 61 | *.unitypackage 62 | *.app 63 | 64 | # Crashlytics generated file 65 | crashlytics-build.properties 66 | 67 | # Packed Addressables 68 | /[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin* 69 | 70 | # Temporary auto-generated Android Assets 71 | /[Aa]ssets/[Ss]treamingAssets/aa.meta 72 | /[Aa]ssets/[Ss]treamingAssets/aa/* 73 | -------------------------------------------------------------------------------- /Runtime/Octree/IntersectJob.cs: -------------------------------------------------------------------------------- 1 | using Unity.Collections; 2 | using Unity.Jobs; 3 | using Unity.Burst; 4 | using UnityEngine; 5 | 6 | // Job that's going to detect what intersected the octree using an AABB 7 | [BurstCompile(CompileSynchronously = true)] 8 | public struct IntersectJob : IJob { 9 | // The input AABBs 10 | [ReadOnly] 11 | public NativeArray bounds; 12 | 13 | // Nodes currently stored in the octree 14 | [ReadOnly] 15 | public NativeList nodes; 16 | 17 | // Leaf nodes that intersected the AABB 18 | [WriteOnly] 19 | public NativeList intersectLeafs; 20 | 21 | // Currently pending nodes for generation 22 | public NativeQueue pending; 23 | 24 | public void Execute() { 25 | // Most optimized jed code (jed try to make optimized code challenge (IMPOSSIBLE)) 26 | while (pending.TryDequeue(out int index)) { 27 | var node = nodes[index]; 28 | 29 | bool any = false; 30 | for (int i = 0; i < bounds.Length; i++) { 31 | if (node.IntersectsAABB(bounds[i].min, bounds[i].max)) { 32 | any = true; 33 | break; 34 | } 35 | } 36 | 37 | if (any) { 38 | if (node.childBaseIndex != -1) { 39 | for (int i = 0; i < 8; i++) { 40 | pending.Enqueue(node.childBaseIndex + i); 41 | } 42 | } else { 43 | intersectLeafs.Add(node); 44 | } 45 | } 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /Runtime/Props/PropGeneratorTemplate.compute: -------------------------------------------------------------------------------- 1 | #pragma kernel CSPropenator 2 | #include "Packages/com.jedjoud.voxelterraingenerator/Runtime/Props/PropGeneratorStart.cginc" 3 | 4 | // Called at each prop segment voxel inside the segment to check what props to spawn 5 | // Remember that you can only spawn ONE prop type (including variants) per unique ID 6 | void PropsAt(uint3 id, float3 position) { 7 | //return; 8 | // Mixer between biome 1 and biome 2 9 | float mixer = snoise(position.xz * 0.0003) * 0.5 + 0.5; 10 | mixer = smoothstep(0, 1, mixer) * 1; 11 | 12 | 13 | 14 | 15 | for (int i = 0; i < 2; i++) { 16 | float3 randomOffset2 = (2 * hash33(position * 2 + 0.588456 + i) - 1) * 30; 17 | float3 rockPos = position + randomOffset2; 18 | 19 | float3 randomOffset = (2 * hash33(position) - 1) * float3(5, 0, 5); 20 | float3 treePos = position + randomOffset; 21 | treePos = rockPos; 22 | ClosestSurface hit1 = CheckClosestSurface(treePos, 0, 3.0); 23 | float caveMixer = saturate(-(position.y - 100) / 20); 24 | 25 | if (hit1.hit && dot(float3(0, 1, 0), hit1.normals) > 0.80 + snoise(position.xz * 0.01) * 0.12) 26 | { 27 | Spawn(hit1.position, hash13(treePos * 12.321) * 0.5 + 1.5, float3(0, 0, 0), 0, round(hash13(treePos * 3.123 - 15.694) * 2), id); 28 | } 29 | 30 | /* 31 | ClosestSurface hit2 = CheckClosestSurface(rockPos, 0, 3.0); 32 | if (hit2.hit && hit2.normals.y < 0.8) { 33 | Spawn(hit2.position, 0.6 + snoise(position * 0.01) * 0.5, hash33(position) * 180, 1, 0, id); 34 | } 35 | */ 36 | } 37 | 38 | } 39 | 40 | #include "Packages/com.jedjoud.voxelterraingenerator/Runtime/Props/PropGeneratorEnd.cginc" -------------------------------------------------------------------------------- /Runtime/Props/SerializableProp.cs: -------------------------------------------------------------------------------- 1 | using Unity.Netcode; 2 | using UnityEngine; 3 | 4 | // Custom prop interface that we can extend to implement custom prop saving/loading logic 5 | // All data that must be persistently saved should be saved with the prop system 6 | // The prop system will *not* make use of the serializable registry system 7 | // because it would force us to create another layer of indirection (to uphold the struct contraint) 8 | // So I'm just keeping the prop data saved as raw bytes and decompressing it only when needed 9 | public abstract class SerializableProp : MonoBehaviour, INetworkSerializable { 10 | // Set the prop as modified, forcing us to serialize it 11 | public bool wasModified = false; 12 | 13 | // Dispatch group ID bitmask index used for loading and saving 14 | public int ElementIndex { internal set; get; } = -1; 15 | 16 | // Stride of the byte data we will be writing 17 | public abstract int Stride { get; } 18 | 19 | // Variant of the prop type 20 | public int Variant { get; internal set; } 21 | 22 | // Called when the fake gameobject for capturing gets spawned 23 | public virtual void OnSpawnCaptureFake(Camera camnera, Texture2DArray[] renderedTextures, int variant) { } 24 | 25 | // Called when the fake gameobject for capturing gets destroyed 26 | public virtual void OnDestroyCaptureFake() { } 27 | 28 | // When a new prop spawns :3 29 | public virtual void OnPropSpawn(BlittableProp prop) { } 30 | 31 | // Serialization / deserialization on a per prop basis 32 | public abstract void NetworkSerialize(BufferSerializer serializer) where T : IReaderWriter; 33 | } -------------------------------------------------------------------------------- /Runtime/Props/Compute/PropCullingCopy.compute: -------------------------------------------------------------------------------- 1 | #pragma kernel CSPropCullingCopy 2 | #define UNITY_INDIRECT_DRAW_ARGS IndirectDrawIndexedArgs 3 | #include "UnityIndirect.cginc" 4 | #include "Packages/com.jedjoud.voxelterraingenerator/Runtime/Utils/PropPackUtils.cginc" 5 | 6 | RWStructuredBuffer totalTemp; 7 | 8 | RWStructuredBuffer culledCount; 9 | StructuredBuffer permProps; 10 | 11 | RWStructuredBuffer culledProps; 12 | StructuredBuffer usedBitmask; 13 | 14 | StructuredBuffer propSectionOffsets; 15 | StructuredBuffer maxDistances; 16 | 17 | float3 cameraForward; 18 | float3 cameraPosition; 19 | 20 | // Do some culling on the props and save them to the culled props buffer 21 | [numthreads(32, 1, 1)] 22 | void CSPropCullingCopy(uint3 id : SV_DispatchThreadID) 23 | { 24 | uint permOffset = propSectionOffsets[id.y].y; 25 | uint visibleOffset = propSectionOffsets[id.y].z; 26 | float maxDistance = maxDistances[id.y]; 27 | uint inputIndex = id.x + permOffset; 28 | 29 | float4 positionScale = UnpackPositionAndScale(permProps[inputIndex].xy); 30 | 31 | uint block = inputIndex / 32; 32 | uint local = inputIndex % 32; 33 | bool valid = ((usedBitmask[block] >> local) & 1) == 1; 34 | //valid = true; 35 | 36 | float3 diff = cameraPosition - positionScale.xyz; 37 | float mag = length(diff); 38 | diff = normalize(diff); 39 | 40 | bool visible = dot(diff, cameraForward) < -0.2 && mag < maxDistance; 41 | //visible = true; 42 | 43 | if (valid) 44 | { 45 | InterlockedAdd(totalTemp[0], 1); 46 | } 47 | 48 | if (visible && valid) { 49 | int index; 50 | InterlockedAdd(culledCount[id.y], 1, index); 51 | culledProps[index + visibleOffset] = permProps[inputIndex]; 52 | } 53 | } -------------------------------------------------------------------------------- /Runtime/Editing/IDynamicEdit.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.CompilerServices; 2 | using Unity.Collections; 3 | using Unity.Jobs; 4 | using Unity.Mathematics; 5 | using Unity.Netcode; 6 | using UnityEngine; 7 | 8 | // Interface for dynamic edits that we can disable / toggle / move around 9 | public interface IDynamicEdit : INetworkSerializable { 10 | // Is the dynamic edit even enabled 11 | public bool Enabled { get; } 12 | 13 | // Create the delta voxel modifications (without having to read the inner voxel data) 14 | // The given input Voxel is the last delta value (for continuous edits) 15 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 16 | public Voxel Modify(float3 position, Voxel voxel); 17 | 18 | // Get the AABB bounds of this voxel edit 19 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 20 | public Bounds GetBounds(); 21 | 22 | // MUST CALL THE "ApplyGeneric" function because we can't hide away generics 23 | public JobHandle Apply(VoxelChunk chunk, ref NativeArray voxels, JobHandle dep); 24 | 25 | // Apply any generic dynamic edit onto oncoming data 26 | internal static JobHandle ApplyGeneric(VoxelChunk chunk, ref NativeArray voxels, JobHandle dep, T edit) where T : struct, IDynamicEdit { 27 | DynamicEditJob job = new DynamicEditJob { 28 | chunkOffset = math.float3(chunk.node.position), 29 | voxelScale = VoxelUtils.VoxelSizeFactor, 30 | size = VoxelUtils.Size, 31 | vertexScaling = VoxelUtils.VertexScaling, 32 | scalingFactor = chunk.node.scalingFactor, 33 | dynamicEdit = edit, 34 | voxels = voxels, 35 | }; 36 | return job.Schedule(VoxelUtils.Volume, 2048, dep); 37 | } 38 | } -------------------------------------------------------------------------------- /Runtime/Utils/PropPackUtils.cginc: -------------------------------------------------------------------------------- 1 | // NOTE: For some fucking reason whenever we read the data on the CPU 2 | // endianess / byte order is fucked and the lowest byte is actually the highest idk 3 | // Will need to figure out why this happens later on but for now it works ok 4 | 5 | uint2 PackPositionAndScale(float3 position, float scale) { 6 | uint x = f32tof16(position.x); 7 | uint y = f32tof16(position.y); 8 | uint z = f32tof16(position.z); 9 | uint w = f32tof16(scale); 10 | 11 | uint first = x | (y << 16); 12 | uint second = z | (w << 16); 13 | return uint2(first, second); 14 | } 15 | 16 | uint NormalizeAndPackAngle(float angle) { 17 | if (angle < 0) { 18 | angle = fmod(360 + angle, 360.0); 19 | } 20 | 21 | angle = fmod(angle, 360.0); 22 | return (uint)((angle / 360.0) * 255.0); 23 | } 24 | 25 | float UnpackRotation(uint rot) { 26 | return (rot / 255.0) * 360.0; 27 | } 28 | 29 | uint2 PackRotationAndVariantAndId(float3 rotation, uint propVariant, uint id) { 30 | uint x = NormalizeAndPackAngle(rotation.x); 31 | uint y = NormalizeAndPackAngle(rotation.y); 32 | uint z = NormalizeAndPackAngle(rotation.z); 33 | uint rots = x | (y << 8) | (z << 16); 34 | uint rest = id | (propVariant << 16); 35 | 36 | return uint2(rots, rest); 37 | } 38 | 39 | float3 UnpackRotation(uint2 packed) { 40 | return float3(UnpackRotation(packed.x >> 16), UnpackRotation(packed.x >> 8), UnpackRotation(packed.x & 0xFF)); 41 | } 42 | 43 | float4 UnpackPositionAndScale(uint2 packed) { 44 | float x = f16tof32(packed.x & 0xFFFF); 45 | float y = f16tof32(packed.x >> 16); 46 | float z = f16tof32(packed.y & 0xFFFF); 47 | float w = f16tof32(packed.y >> 16); 48 | return float4(x, y, z, w); 49 | } 50 | 51 | uint UnpackVariant(uint2 packed) { 52 | return packed.y >> 16; 53 | } -------------------------------------------------------------------------------- /Runtime/Props/Default/TestProp.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!114 &11400000 4 | MonoBehaviour: 5 | m_ObjectHideFlags: 0 6 | m_CorrespondingSourceObject: {fileID: 0} 7 | m_PrefabInstance: {fileID: 0} 8 | m_PrefabAsset: {fileID: 0} 9 | m_GameObject: {fileID: 0} 10 | m_Enabled: 1 11 | m_EditorHideFlags: 0 12 | m_Script: {fileID: 11500000, guid: ca249502b12e6574a82400f18da30c2f, type: 3} 13 | m_Name: TestProp 14 | m_EditorClassIdentifier: 15 | variants: 16 | - prefab: {fileID: 900193227329173065, guid: 7b5625836e801c04fbb54c9225ac4663, type: 3} 17 | billboardCaptureCameraScale: 7 18 | billboardCaptureRotation: {x: 0, y: 0, z: 0} 19 | billboardCapturePosition: {x: 0, y: -7, z: 5} 20 | - prefab: {fileID: 900193227329173065, guid: df96a2d6604800b40af714ed6b3cfdf0, type: 3} 21 | billboardCaptureCameraScale: 7 22 | billboardCaptureRotation: {x: 0, y: 0, z: 0} 23 | billboardCapturePosition: {x: 0, y: -7, z: 5} 24 | - prefab: {fileID: 900193227329173065, guid: 5e86418390f91554db10ad733d9e7c22, type: 3} 25 | billboardCaptureCameraScale: 7 26 | billboardCaptureRotation: {x: 0, y: 0, z: 0} 27 | billboardCapturePosition: {x: 0, y: -7, z: 5} 28 | propSpawnBehavior: 3 29 | maxPropsPerSegment: 8192 30 | maxPropsInTotal: 1048576 31 | maxVisibleProps: 1048576 32 | maxInstancingDistance: 100000 33 | instancedMeshMaterial: {fileID: 0} 34 | instancedMesh: {fileID: 0} 35 | billboardTextureWidth: 256 36 | billboardTextureHeight: 1024 37 | billboardMipMaps: 0 38 | billboardTextureFilterMode: 1 39 | billboardSize: {x: 4.2, y: 14} 40 | billboardOffset: {x: 0, y: 0, z: 0} 41 | billboardSizeOrigin: {x: 0, y: -0.5, z: 0} 42 | instancesRestrictRotationY: 1 43 | instancesCastShadows: 1 44 | -------------------------------------------------------------------------------- /Runtime/Mesher/CopyJob.cs: -------------------------------------------------------------------------------- 1 | using Unity.Collections; 2 | using Unity.Jobs; 3 | using Unity.Burst; 4 | 5 | // Copies the temp triangulation data to the permanent location where we store the offsets too 6 | [BurstCompile(CompileSynchronously = true)] 7 | public struct CopyJob : IJobParallelFor 8 | { 9 | // Offsets for each material type 10 | [ReadOnly] 11 | public NativeArray materialSegmentOffsets; 12 | 13 | // Sparse triangles based on the material segment offsets 14 | [ReadOnly] 15 | public NativeArray tempTriangles; 16 | 17 | // Packed triangles based on material segment offsets 18 | [WriteOnly] 19 | [NativeDisableParallelForRestriction] 20 | public NativeArray permTriangles; 21 | 22 | // Quad Counter for each material 23 | [ReadOnly] 24 | public NativeMultiCounter counters; 25 | 26 | // Global material counter 27 | [ReadOnly] 28 | public NativeCounter materialCounter; 29 | 30 | public void Execute(int index) 31 | { 32 | if (materialCounter.Count == 0 || index >= materialCounter.Count) 33 | return; 34 | 35 | int segmentOffset = tempTriangles.Length / materialCounter.Count; 36 | 37 | // Segment offset for the temp index buffer, not the perm one 38 | // Segment offset in the temp buffer is constant, so each sub-mesh contains the same amount of indices 39 | // (not goodo, which is why we have the perm one in the first hand) 40 | int material = index; 41 | int readOffset = segmentOffset * material; 42 | int offset = materialSegmentOffsets[material]; 43 | 44 | for (int i = 0; i < counters[material] * 6; i++) 45 | { 46 | int val = tempTriangles[i + readOffset]; 47 | permTriangles[offset + i] = val; 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /Runtime/Editing/VoxelEditJob.cs: -------------------------------------------------------------------------------- 1 | using Unity.Burst; 2 | using Unity.Collections; 3 | using Unity.Collections.LowLevel.Unsafe; 4 | using Unity.Jobs; 5 | using Unity.Mathematics; 6 | 7 | // Edit job that will create the delta voxel data for each chunk 8 | // This executes for VoxelUtils.DeltaVolume size instead of VoxelUtils.Volume 9 | // Because we must also affect the higher LOD chunk values as well 10 | [BurstCompile(CompileSynchronously = true)] 11 | struct VoxelEditJob : IJobParallelFor 12 | where T : struct, IVoxelEdit { 13 | [ReadOnly] public float3 chunkOffset; 14 | [ReadOnly] public float scalingFactor; 15 | [ReadOnly] public float voxelScale; 16 | [ReadOnly] public int size; 17 | [ReadOnly] public float vertexScaling; 18 | 19 | public T edit; 20 | public NativeArray densities; 21 | public NativeArray materials; 22 | 23 | public void Execute(int index) { 24 | uint3 id = VoxelUtils.IndexToPos(index); 25 | float3 position = (math.float3(id)); 26 | 27 | // Needed for voxel size reduction 28 | position *= voxelScale; 29 | position -= 1.5f * voxelScale; 30 | 31 | //position -= math.float3(1); 32 | position *= vertexScaling; 33 | position *= scalingFactor; 34 | position += chunkOffset; 35 | 36 | // Chunk offsets + vertex scaling 37 | //position += math.float3((chunkOffset - (scalingFactor * size / (size - 3.0f)) * 0.5f)); 38 | 39 | // Read, modify, write 40 | byte material = materials[index]; 41 | half density = VoxelUtils.NormalizeHalf(densities[index]); 42 | Voxel output = edit.Modify(position, new Voxel { material = material, density = density }); 43 | materials[index] = output.material; 44 | densities[index] = VoxelUtils.NormalizeHalf(output.density); 45 | } 46 | } -------------------------------------------------------------------------------- /Runtime/Editing/Default/SphereDynamicEdit.cs: -------------------------------------------------------------------------------- 1 | using Unity.Collections; 2 | using Unity.Jobs; 3 | using Unity.Mathematics; 4 | using Unity.Netcode; 5 | using UnityEngine; 6 | 7 | [assembly: RegisterGenericJobType(typeof(DynamicEditJob))] 8 | 9 | public struct SphereDynamicEdit : IDynamicEdit { 10 | [ReadOnly] public float3 center; 11 | [ReadOnly] public float radius; 12 | [ReadOnly] public bool inverse; 13 | [ReadOnly] public byte material; 14 | [ReadOnly] public bool writeMaterial; 15 | public bool Enabled => true; 16 | 17 | public JobHandle Apply(VoxelChunk chunk, ref NativeArray voxels, JobHandle dep) { 18 | return IDynamicEdit.ApplyGeneric(chunk, ref voxels, dep, this); 19 | } 20 | 21 | public Bounds GetBounds() { 22 | return new Bounds { 23 | center = center, 24 | extents = new Vector3(radius, radius, radius) * 2.0F, 25 | }; 26 | } 27 | 28 | public Voxel Modify(float3 position, Voxel voxel) { 29 | float density = math.length(position - center) - radius; 30 | 31 | if (density < 1.0 && writeMaterial) { 32 | voxel.material = material; 33 | } 34 | 35 | if (inverse) { 36 | voxel.density = (half)(math.max(voxel.density, -density)); 37 | } else { 38 | voxel.density = (half)math.min(voxel.density, density); 39 | } 40 | return voxel; 41 | } 42 | 43 | public void NetworkSerialize(BufferSerializer serializer) where T : IReaderWriter { 44 | serializer.SerializeValue(ref center.x); 45 | serializer.SerializeValue(ref center.y); 46 | serializer.SerializeValue(ref center.z); 47 | serializer.SerializeValue(ref radius); 48 | serializer.SerializeValue(ref material); 49 | serializer.SerializeValue(ref writeMaterial); 50 | } 51 | } -------------------------------------------------------------------------------- /Runtime/Octree/SubdivideJob.cs: -------------------------------------------------------------------------------- 1 | using Unity.Collections; 2 | using Unity.Jobs; 3 | using Unity.Mathematics; 4 | using Unity.Burst; 5 | 6 | // This will handle generating the nodes for one of the starting nodes 7 | [BurstCompile(CompileSynchronously = true)] 8 | public struct SubdivideJob : IJob where T: struct, IOctreeSubdivider { 9 | // The total nodes that where generated 10 | public NativeList nodes; 11 | 12 | // Currently pending nodes for generation 13 | public NativeQueue pending; 14 | 15 | [ReadOnly] 16 | public TerrainLoader.Target target; 17 | 18 | [ReadOnly] public int maxDepth; 19 | public T subdivider; 20 | 21 | public void Execute() { 22 | while (pending.TryDequeue(out OctreeNode node)) { 23 | TrySubdivide(ref node); 24 | } 25 | } 26 | 27 | // Try to subdivide the current node into 8 octants 28 | public void TrySubdivide(ref OctreeNode node) { 29 | if (subdivider.ShouldSubdivide(ref node, ref target) && node.depth < maxDepth) { 30 | node.childBaseIndex = nodes.Length; 31 | 32 | for (int i = 0; i < 8; i++) { 33 | float3 offset = math.float3(VoxelUtils.OctreeChildOffset[i]); 34 | OctreeNode child = new OctreeNode { 35 | position = offset * (node.size / 2.0F) + node.position, 36 | depth = node.depth + 1, 37 | size = node.size / 2, 38 | parentIndex = node.index, 39 | index = node.childBaseIndex + i, 40 | childBaseIndex = -1, 41 | skirts = 0, 42 | scalingFactor = node.scalingFactor / 2.0F, 43 | }; 44 | 45 | pending.Enqueue(child); 46 | nodes.Add(child); 47 | } 48 | 49 | nodes[node.index] = node; 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /Runtime/Utils/noises/fbm.cginc: -------------------------------------------------------------------------------- 1 | 2 | // fBM noise, uses 2D simplex noise 3 | float fbm(float2 pos, uint octaves, float persistence, float lacunarity) { 4 | float final = 0.0; 5 | float scale = 1.0; 6 | float amplitude = 1.0; 7 | 8 | [unroll] 9 | for(uint i = 0; i < octaves; i++) { 10 | final += snoise(pos * scale + hash21(float(i))) * amplitude; 11 | scale *= lacunarity; 12 | amplitude *= persistence; 13 | } 14 | 15 | return final; 16 | } 17 | 18 | // fBM noise, uses 3D simplex noise 19 | float fbm(float3 pos, uint octaves, float persistence, float lacunarity) { 20 | float final = 0.0; 21 | float scale = 1.0; 22 | float amplitude = 1.0; 23 | 24 | [unroll] 25 | for(uint i = 0; i < octaves; i++) { 26 | final += snoise(pos * scale + hash31(float(i))) * amplitude; 27 | scale *= lacunarity; 28 | amplitude *= persistence; 29 | } 30 | 31 | return final; 32 | } 33 | 34 | // fBM noise, uses 2D worley noise 35 | float2 fbmCellular(float2 pos, uint octaves, float persistence, float lacunarity) { 36 | float2 final = float2(0.0, 0.0); 37 | float scale = 1.0; 38 | float amplitude = 1.0; 39 | 40 | [unroll] 41 | for(uint i = 0; i < octaves; i++) { 42 | final += (cellular(pos * scale + hash21(float(i)))-float2(0.5, 0.5)) * amplitude; 43 | scale *= lacunarity; 44 | amplitude *= persistence; 45 | } 46 | 47 | return final; 48 | } 49 | 50 | // fBM noise, uses 3D worley noise 51 | float2 fbmCellular(float3 pos, uint octaves, float persistence, float lacunarity) { 52 | float2 final = float2(0.0, 0.0); 53 | float scale = 1.0; 54 | float amplitude = 1.0; 55 | 56 | [unroll] 57 | for(uint i = 0; i < octaves; i++) { 58 | final += (cellular(pos * scale + hash31(float(i)))-float2(0.5, 0.5)) * amplitude; 59 | scale *= lacunarity; 60 | amplitude *= persistence; 61 | } 62 | 63 | return final; 64 | } -------------------------------------------------------------------------------- /Editor/CustomEditorProp.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | 3 | [CustomEditor(typeof(PropType))] 4 | public class CustomEditorProp : Editor 5 | { 6 | public override void OnInspectorGUI() 7 | { 8 | base.OnInspectorGUI(); 9 | 10 | /* 11 | var script = (Prop)target; 12 | 13 | if (script.propSpawnBehavior.HasFlag(PropSpawnBehavior.RenderBillboards)) { 14 | EditorGUILayout.Separator(); 15 | EditorGUILayout.LabelField("Billboard Capture", EditorStyles.boldLabel); 16 | EditorGUI.indentLevel++; 17 | script.billboardCaptureCameraScale = EditorGUILayout.FloatField("Capture Camera Scale", script.billboardCaptureCameraScale); 18 | script.billboardTextureWidth = EditorGUILayout.IntField("Texture Width", script.billboardTextureWidth); 19 | script.billboardTextureHeight = EditorGUILayout.IntField("Texture Height", script.billboardTextureHeight); 20 | script.billboardCaptureRotation = EditorGUILayout.Vector3Field("Capture Rotation", script.billboardCaptureRotation); 21 | script.billboardCapturePosition = EditorGUILayout.Vector3Field("Capture Position", script.billboardCapturePosition); 22 | EditorGUI.indentLevel--; 23 | 24 | EditorGUILayout.Separator(); 25 | EditorGUILayout.LabelField("Billboard Rendering", EditorStyles.boldLabel); 26 | EditorGUI.indentLevel++; 27 | script.billboardSize = EditorGUILayout.Vector2Field("World Size", script.billboardSize); 28 | script.billboardOffset = EditorGUILayout.Vector2Field("World Offset", script.billboardOffset); 29 | script.billboardRestrictRotationY = EditorGUILayout.Toggle("Restrict Rotation Y?", script.billboardRestrictRotationY); 30 | script.billboardCastShadows = EditorGUILayout.Toggle("Cast Shadows?", script.billboardCastShadows); 31 | script.billboardAlphaClipThreshold = EditorGUILayout.FloatField("Alpha Clip Threshold", script.billboardAlphaClipThreshold); 32 | EditorGUILayout.Separator(); 33 | } 34 | */ 35 | } 36 | } -------------------------------------------------------------------------------- /Runtime/Utils/noises/cellular2D.cginc: -------------------------------------------------------------------------------- 1 | 2 | 3 | // Cellular noise ("Worley noise") in 2D in GLSL. 4 | // Copyright (c) Stefan Gustavson 2011-04-19. All rights reserved. 5 | // This code is released under the conditions of the MIT license. 6 | // See LICENSE file for props. 7 | // https://github.com/stegu/webgl-noise 8 | 9 | // Cellular noise, returning F1 and F2 in a float2. 10 | // Standard 3x3 search window for good F1 and F2 values 11 | float2 cellular(float2 P) { 12 | #define K 0.142857142857 // 1/7 13 | #define Ko 0.428571428571 // 3/7 14 | #define jitter 1.0 // Less gives more regular pattern 15 | float2 Pi = mod289(floor(P)); 16 | float2 Pf = frac(P); 17 | float3 oi = float3(-1.0, 0.0, 1.0); 18 | float3 of = float3(-0.5, 0.5, 1.5); 19 | float3 px = permute(Pi.x + oi); 20 | float3 p = permute(px.x + Pi.y + oi); // p11, p12, p13 21 | float3 ox = frac(p*K) - Ko; 22 | float3 oy = mod7(floor(p*K))*K - Ko; 23 | float3 dx = Pf.x + 0.5 + jitter*ox; 24 | float3 dy = Pf.y - of + jitter*oy; 25 | float3 d1 = dx * dx + dy * dy; // d11, d12 and d13, squared 26 | p = permute(px.y + Pi.y + oi); // p21, p22, p23 27 | ox = frac(p*K) - Ko; 28 | oy = mod7(floor(p*K))*K - Ko; 29 | dx = Pf.x - 0.5 + jitter*ox; 30 | dy = Pf.y - of + jitter*oy; 31 | float3 d2 = dx * dx + dy * dy; // d21, d22 and d23, squared 32 | p = permute(px.z + Pi.y + oi); // p31, p32, p33 33 | ox = frac(p*K) - Ko; 34 | oy = mod7(floor(p*K))*K - Ko; 35 | dx = Pf.x - 1.5 + jitter*ox; 36 | dy = Pf.y - of + jitter*oy; 37 | float3 d3 = dx * dx + dy * dy; // d31, d32 and d33, squared 38 | // Sort out the two smallest distances (F1, F2) 39 | float3 d1a = min(d1, d2); 40 | d2 = max(d1, d2); // Swap to keep candidates for F2 41 | d2 = min(d2, d3); // neither F1 nor F2 are now in d3 42 | d1 = min(d1a, d2); // F1 is now in d1 43 | d2 = max(d1a, d2); // Swap to keep candidates for F2 44 | d1.xy = (d1.x < d1.y) ? d1.xy : d1.yx; // Swap if smaller 45 | d1.xz = (d1.x < d1.z) ? d1.xz : d1.zx; // F1 is in d1.x 46 | d1.yz = min(d1.yz, d2.yz); // F2 is now not in d2.yz 47 | d1.y = min(d1.y, d1.z); // nor in d1.z 48 | d1.y = min(d1.y, d2.x); // F2 is in d1.y, we're done. 49 | return sqrt(d1.xy); 50 | } 51 | -------------------------------------------------------------------------------- /Runtime/Editing/Default/CuboidDynamicEdit.cs: -------------------------------------------------------------------------------- 1 | using Unity.Collections; 2 | using Unity.Jobs; 3 | using Unity.Mathematics; 4 | using Unity.Netcode; 5 | using UnityEngine; 6 | 7 | [assembly: RegisterGenericJobType(typeof(DynamicEditJob))] 8 | public struct CuboidDynamicEdit : IDynamicEdit { 9 | [ReadOnly] public float3x3 rotation; 10 | [ReadOnly] public float3 center; 11 | [ReadOnly] public float3 halfExtents; 12 | [ReadOnly] public bool inverse; 13 | [ReadOnly] public byte material; 14 | [ReadOnly] public bool writeMaterial; 15 | public bool Enabled => true; 16 | 17 | public JobHandle Apply(VoxelChunk chunk, ref NativeArray voxels, JobHandle dep) { 18 | return IDynamicEdit.ApplyGeneric(chunk, ref voxels, dep, this); 19 | } 20 | 21 | public Bounds GetBounds() { 22 | return new Bounds { 23 | center = center, 24 | extents = halfExtents * 2 25 | }.RotatedBy(rotation); 26 | } 27 | 28 | public Voxel Modify(float3 position, Voxel voxel) { 29 | position = math.mul(math.inverse(rotation), position - center); 30 | float3 q = math.abs(position) - halfExtents; 31 | float density = math.length(math.max(q, 0.0F)) + math.min(math.max(q.x, math.max(q.y, q.z)), 0.0F); 32 | 33 | if (density < 1.0 && writeMaterial) { 34 | voxel.material = material; 35 | } 36 | 37 | if (inverse) { 38 | voxel.density = (half)(math.max(voxel.density, -density)); 39 | } else { 40 | voxel.density = (half)math.min(voxel.density, density); 41 | } 42 | 43 | return voxel; 44 | } 45 | 46 | public void NetworkSerialize(BufferSerializer serializer) where T : IReaderWriter { 47 | serializer.SerializeValue(ref center.x); 48 | serializer.SerializeValue(ref center.y); 49 | serializer.SerializeValue(ref center.z); 50 | serializer.SerializeValue(ref halfExtents.x); 51 | serializer.SerializeValue(ref halfExtents.y); 52 | serializer.SerializeValue(ref halfExtents.z); 53 | serializer.SerializeValue(ref material); 54 | serializer.SerializeValue(ref writeMaterial); 55 | } 56 | } -------------------------------------------------------------------------------- /Runtime/Mesher/VoxelCollisions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Unity.Jobs; 3 | 4 | 5 | // Responsible for creating and executing the mesh baking jobs 6 | // Can also be used to check for collisions based on the stored voxel data (needed for props) 7 | public class VoxelCollisions : VoxelBehaviour { 8 | public bool generateCollisions = false; 9 | 10 | // Called when a chunk's mesh gets its collision data 11 | public delegate void OnCollisionBakingComplete(VoxelChunk chunk, VoxelMesh stats); 12 | public event OnCollisionBakingComplete onCollisionBakingComplete; 13 | 14 | // Used for collision 15 | internal List<(JobHandle, VoxelChunk, VoxelMesh)> ongoingBakeJobs; 16 | 17 | // Checks if the voxel collision baker has completed all the baking work 18 | public bool Free { 19 | get { 20 | bool bakeJobs = ongoingBakeJobs.Count == 0; 21 | return bakeJobs; 22 | } 23 | } 24 | 25 | // Initialize the voxel mesher 26 | internal override void Init() { 27 | ongoingBakeJobs = new List<(JobHandle, VoxelChunk, VoxelMesh)>(); 28 | terrain.VoxelMesher.onVoxelMeshingComplete += HandleVoxelMeshCollision; 29 | } 30 | 31 | private void HandleVoxelMeshCollision(VoxelChunk chunk, VoxelMesh voxelMesh) { 32 | if (voxelMesh.VertexCount > 0 && voxelMesh.TriangleCount > 0 && voxelMesh.ComputeCollisions && generateCollisions) { 33 | BakeJob bakeJob = new BakeJob { 34 | meshId = chunk.sharedMesh.GetInstanceID(), 35 | }; 36 | 37 | var handle = bakeJob.Schedule(); 38 | ongoingBakeJobs.Add((handle, chunk, voxelMesh)); 39 | } else { 40 | onCollisionBakingComplete?.Invoke(chunk, VoxelMesh.Empty); 41 | } 42 | } 43 | 44 | void Update() { 45 | foreach (var (handle, chunk, mesh) in ongoingBakeJobs) { 46 | if (handle.IsCompleted) { 47 | handle.Complete(); 48 | onCollisionBakingComplete?.Invoke(chunk, mesh); 49 | } 50 | } 51 | ongoingBakeJobs.RemoveAll(item => item.Item1.IsCompleted); 52 | } 53 | 54 | internal override void Dispose() { 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Runtime/Utils/noises/noise2D.cginc: -------------------------------------------------------------------------------- 1 | // 2 | // Description : Array and textureless GLSL 2D simplex noise function. 3 | // Author : Ian McEwan, Ashima Arts. 4 | // Maintainer : stegu 5 | // Lastmod : 20110822 (ijm) 6 | // License : Copyright (C) 2011 Ashima Arts. All rights reserved. 7 | // Distributed under the MIT License. See LICENSE file. 8 | // https://github.com/ashima/webgl-noise 9 | // https://github.com/stegu/webgl-noise 10 | // 11 | 12 | 13 | 14 | 15 | 16 | float snoise(float2 v) 17 | { 18 | const float4 C = float4(0.211324865405187, // (3.0-sqrt(3.0))/6.0 19 | 0.366025403784439, // 0.5*(sqrt(3.0)-1.0) 20 | -0.577350269189626, // -1.0 + 2.0 * C.x 21 | 0.024390243902439); // 1.0 / 41.0 22 | // First corner 23 | float2 i = floor(v + dot(v, C.yy) ); 24 | float2 x0 = v - i + dot(i, C.xx); 25 | 26 | // Other corners 27 | float2 i1; 28 | //i1.x = step( x0.y, x0.x ); // x0.x > x0.y ? 1.0 : 0.0 29 | //i1.y = 1.0 - i1.x; 30 | i1 = (x0.x > x0.y) ? float2(1.0, 0.0) : float2(0.0, 1.0); 31 | // x0 = x0 - 0.0 + 0.0 * C.xx ; 32 | // x1 = x0 - i1 + 1.0 * C.xx ; 33 | // x2 = x0 - 1.0 + 2.0 * C.xx ; 34 | float4 x12 = x0.xyxy + C.xxzz; 35 | x12.xy -= i1; 36 | 37 | // Permutations 38 | i = mod289(i); // Avoid truncation effects in permutation 39 | float3 p = permute( permute( i.y + float3(0.0, i1.y, 1.0 )) + permuationSeed.y 40 | + i.x + float3(0.0, i1.x, 1.0 ) + permuationSeed.z); 41 | 42 | float3 m = max(0.5 - float3(dot(x0,x0), dot(x12.xy,x12.xy), dot(x12.zw,x12.zw)), 0.0); 43 | m = m*m ; 44 | m = m*m ; 45 | 46 | // Gradients: 41 points uniformly over a line, mapped onto a diamond. 47 | // The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287) 48 | 49 | float3 x = 2.0 * frac(p * C.www) - 1.0; 50 | float3 h = abs(x) - 0.5; 51 | float3 ox = floor(x + 0.5); 52 | float3 a0 = x - ox; 53 | 54 | // Normalise gradients implicitly by scaling m 55 | // Approximation of: m *= inversesqrt( a0*a0 + h*h ); 56 | m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h ); 57 | 58 | // Compute final noise value at P 59 | float3 g; 60 | g.x = a0.x * x0.x + h.x * x0.y; 61 | g.yz = a0.yz * x12.xz + h.yz * x12.yw; 62 | return 130.0 * dot(m, g); 63 | } 64 | -------------------------------------------------------------------------------- /Runtime/Utils/Voxel.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | using Unity.Collections; 3 | using Unity.Jobs; 4 | using Unity.Mathematics; 5 | 6 | // CPU representation of what a voxel is. The most important value here is the density value 7 | [StructLayout(LayoutKind.Sequential)] 8 | public struct Voxel { 9 | public const int size = sizeof(int); 10 | 11 | // Density of the voxel as a half to save some memory 12 | public half density; 13 | 14 | // Material of the voxel that depicts its color and other parameters 15 | public byte material; 16 | 17 | // Used for extra color data on a per vertex basis 18 | public byte _padding; 19 | 20 | // Empty voxel with the empty material 21 | public readonly static Voxel Empty = new Voxel { 22 | density = half.zero, 23 | material = byte.MaxValue, 24 | _padding = 0, 25 | }; 26 | } 27 | 28 | // Delta data that contains the voxel values for any arbitrarily sized chunk 29 | public struct SparseVoxelDeltaData { 30 | public float3 position; 31 | public float scalingFactor; 32 | 33 | // Densities that we will compress using a lossless compression algorithm 34 | public NativeArray densities; 35 | 36 | // Byte that we will compress using RLE 37 | // byte.max represents a value that the user has not modified yet 38 | public NativeArray materials; 39 | 40 | // Job handle for the "apply" task for this sparse voxel data 41 | public JobHandle applyJobHandle; 42 | 43 | // Last counters for the chunk for this delta node 44 | // Used to calculate delta counter values 45 | public NativeArray lastCounters; 46 | 47 | // Create sparse voxel data for an unnaffected delta chunk 48 | public static SparseVoxelDeltaData Empty = new SparseVoxelDeltaData { 49 | densities = default, 50 | materials = default, 51 | applyJobHandle = new JobHandle(), 52 | position = new float3(0, 0, 0), 53 | scalingFactor = -1, 54 | lastCounters = default, 55 | }; 56 | } 57 | 58 | // Voxel container with custom dispose methods 59 | // (implemented for voxel readback request and voxel edit request) 60 | public abstract class VoxelTempContainer { 61 | public NativeArray voxels; 62 | public VoxelChunk chunk; 63 | 64 | // Dispose of the voxel container 65 | public abstract void TempDispose(); 66 | } -------------------------------------------------------------------------------- /Runtime/Utils/VoxelCompressionJob.cs: -------------------------------------------------------------------------------- 1 | using Unity.Burst; 2 | using Unity.Collections; 3 | using Unity.Jobs; 4 | using Unity.Mathematics; 5 | 6 | // Compression job that we will apply over each voxel chunk to compress its data for serialization 7 | [BurstCompile(CompileSynchronously = true)] 8 | internal struct VoxelCompressionJob : IJob { 9 | [ReadOnly] 10 | public NativeArray densitiesIn; 11 | [WriteOnly] 12 | public NativeList densitiesOut; 13 | 14 | public void Execute() { 15 | ushort lastDensity = VoxelUtils.AsUshort(densitiesIn[0]); 16 | int densityCount = 0; 17 | bool rlePerfect = true; 18 | 19 | AddUshort(0); 20 | AddUshort(lastDensity); 21 | 22 | for (int i = 0; i < densitiesIn.Length; i++) { 23 | ushort newDensity = VoxelUtils.AsUshort(densitiesIn[i]); 24 | 25 | if (newDensity == lastDensity) { 26 | densityCount++; 27 | } else if (VoxelUtils.CouldDelta(lastDensity, newDensity)) { 28 | if (rlePerfect) { 29 | AddUshort((ushort)densityCount); 30 | AddUshort(newDensity); 31 | lastDensity = newDensity; 32 | densityCount = 0; 33 | rlePerfect = false; 34 | } 35 | 36 | densitiesOut.Add(VoxelUtils.EncodeDelta(newDensity)); 37 | densityCount++; 38 | } else { 39 | rlePerfect = true; 40 | AddUshort((ushort)densityCount); 41 | AddUshort(newDensity); 42 | lastDensity = newDensity; 43 | densityCount = 1; 44 | } 45 | 46 | if (densityCount == 32767) { 47 | rlePerfect = true; 48 | AddUshort((ushort)densityCount); 49 | AddUshort(newDensity); 50 | lastDensity = newDensity; 51 | densityCount = 0; 52 | } 53 | } 54 | } 55 | 56 | private void AddInt(int packed) { 57 | densitiesOut.Add((byte)(packed >> 24)); 58 | densitiesOut.Add((byte)(packed >> 16)); 59 | densitiesOut.Add((byte)(packed >> 8)); 60 | densitiesOut.Add((byte)packed); 61 | } 62 | 63 | private void AddUshort(ushort packed) { 64 | densitiesOut.Add((byte)(packed >> 8)); 65 | densitiesOut.Add((byte)packed); 66 | } 67 | } -------------------------------------------------------------------------------- /Runtime/VoxelChunk.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | // Script added to all game objects that represent a chunk 4 | public class VoxelChunk : MonoBehaviour { 5 | // Voxel chunk node 6 | public OctreeNode node; 7 | 8 | // Either the chunk's own voxel data (in case collisions are enabled) 9 | // OR the voxel request data (temp) 10 | // If null it means the chunk cannot be generated (no voxel data!!) 11 | public VoxelTempContainer container; 12 | 13 | // Callback that we must invoke when we finish meshing this voxel chunk 14 | internal VoxelEdits.VoxelEditCountersHandle voxelCountersHandle; 15 | 16 | // Shared generated mesh 17 | public Mesh sharedMesh; 18 | internal int[] voxelMaterialsLookup; 19 | 20 | // Get the AABB world bounds of this chunk 21 | public Bounds GetBounds() { 22 | return new Bounds { 23 | min = node.position, 24 | max = node.position + node.size, 25 | }; 26 | } 27 | 28 | // Remesh the chunk given the parent terrain 29 | public void Remesh(VoxelTerrain terrain, int maxFrames = 5) { 30 | if (container is UniqueVoxelChunkContainer) { 31 | // Regenerate the mesh based on the unique voxel container 32 | terrain.VoxelMesher.GenerateMesh(this, node.depth == VoxelUtils.MaxDepth, maxFrames); 33 | } else { 34 | // If not, simply regenerate the chunk 35 | // This is pretty inefficient but it's a matter of memory vs performance 36 | terrain.VoxelGenerator.GenerateVoxels(this); 37 | } 38 | } 39 | 40 | // Regenerate the chunk given the parent terrain 41 | public void Regenerate(VoxelTerrain terrain) { 42 | terrain.VoxelGenerator.GenerateVoxels(this); 43 | } 44 | 45 | // Convert a specific sub-mesh index (from physics collision for example) to voxel material index 46 | public bool TryGetVoxelMaterialFromSubmesh(int submeshIndex, out int voxelMaterialIndex) { 47 | if (voxelMaterialsLookup != null && submeshIndex < voxelMaterialsLookup.Length) { 48 | voxelMaterialIndex = voxelMaterialsLookup[submeshIndex]; 49 | return true; 50 | } 51 | 52 | voxelMaterialIndex = -1; 53 | return false; 54 | } 55 | } 56 | 57 | // Cached voxel chunk container for chunks with their own temp voxels (for modifs) 58 | public class UniqueVoxelChunkContainer : VoxelTempContainer { 59 | public override void TempDispose() { 60 | } 61 | } -------------------------------------------------------------------------------- /Runtime/Utils/sdf.cginc: -------------------------------------------------------------------------------- 1 | // Common primitive SDF functions taken from https://iquilezles.org/articles/distfunctions/ 2 | // Author: Inigo Quilez 3 | 4 | float sdSphere(float3 p, float s) 5 | { 6 | return length(p) - s; 7 | } 8 | 9 | float sdBox(float3 p, float3 b) 10 | { 11 | float3 q = abs(p) - b; 12 | return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0); 13 | } 14 | 15 | float3 repeat(float3 p, float3 b) { 16 | return float3(fmod(p.x, b.x), fmod(p.y, b.y), fmod(p.z, b.z)); 17 | } 18 | 19 | float sdOctahedron(float3 p, float s) 20 | { 21 | p = abs(p); 22 | float m = p.x + p.y + p.z - s; 23 | float3 q; 24 | if (3.0 * p.x < m) q = p.xyz; 25 | else if (3.0 * p.y < m) q = p.yzx; 26 | else if (3.0 * p.z < m) q = p.zxy; 27 | else return m * 0.57735027; 28 | 29 | float k = clamp(0.5 * (q.z - q.y + s), 0.0, s); 30 | return length(float3(q.x, q.y - s + k, q.z - k)); 31 | } 32 | 33 | float sdPlane(float3 p, float3 n, float h) 34 | { 35 | // n must be normalized 36 | return dot(p, n) + h; 37 | } 38 | 39 | float sdPyramid(float3 p, float h) 40 | { 41 | float m2 = h * h + 0.25; 42 | 43 | p.xz = abs(p.xz); 44 | p.xz = (p.z > p.x) ? p.zx : p.xz; 45 | p.xz -= 0.5; 46 | 47 | float3 q = float3(p.z, h * p.y - 0.5 * p.x, h * p.x + 0.5 * p.y); 48 | 49 | float s = max(-q.x, 0.0); 50 | float t = clamp((q.y - 0.5 * p.z) / (m2 + 0.25), 0.0, 1.0); 51 | 52 | float a = m2 * (q.x + s) * (q.x + s) + q.y * q.y; 53 | float b = m2 * (q.x + 0.5 * t) * (q.x + 0.5 * t) + (q.y - m2 * t) * (q.y - m2 * t); 54 | 55 | float d2 = min(q.y, -q.x * m2 - q.y * 0.5) > 0.0 ? 0.0 : min(a, b); 56 | 57 | return sqrt((d2 + q.z * q.z) / m2) * sign(max(q.z, -p.y)); 58 | } 59 | 60 | float sdRoundBox(float3 p, float3 b, float r) 61 | { 62 | float3 q = abs(p) - b; 63 | return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0) - r; 64 | } 65 | 66 | float opUnion(float d1, float d2) { return min(d1, d2); } 67 | float opSubtraction(float d1, float d2) { return max(-d1, d2); } 68 | float opIntersection(float d1, float d2) { return max(d1, d2); } 69 | 70 | 71 | float opSmoothUnion(float d1, float d2, float k) { 72 | float h = clamp(0.5 + 0.5 * (d2 - d1) / k, 0.0, 1.0); 73 | return lerp(d2, d1, h) - k * h * (1.0 - h); 74 | } 75 | 76 | float opSmoothSubtraction(float d1, float d2, float k) { 77 | float h = clamp(0.5 - 0.5 * (d2 + d1) / k, 0.0, 1.0); 78 | return lerp(d2, -d1, h) + k * h * (1.0 - h); 79 | } 80 | 81 | float opSmoothIntersection(float d1, float d2, float k) { 82 | float h = clamp(0.5 - 0.5 * (d2 - d1) / k, 0.0, 1.0); 83 | return lerp(d2, d1, h) + k * h * (1.0 - h); 84 | } -------------------------------------------------------------------------------- /Runtime/Segments/SegmentSpawnJob.cs: -------------------------------------------------------------------------------- 1 | using Unity.Collections; 2 | using Unity.Jobs; 3 | using Unity.Mathematics; 4 | using Unity.Burst; 5 | 6 | // This will handle spawning the prop segments from scratch and to be diffed later 7 | [BurstCompile(CompileSynchronously = true)] 8 | public struct SegmentSpawnJob : IJob { 9 | public NativeHashSet oldPropSegments; 10 | public NativeHashSet propSegments; 11 | public TerrainLoader.Target target; 12 | 13 | [WriteOnly] 14 | public NativeList addedSegments; 15 | 16 | [WriteOnly] 17 | public NativeList removedSegments; 18 | 19 | public int maxSegmentsInWorld; 20 | 21 | public float propSegmentSize; 22 | 23 | public void Execute() { 24 | propSegments.Clear(); 25 | 26 | int3 c = (int3)target.propSegmentExtent; 27 | int3 min = new int3(-maxSegmentsInWorld, -maxSegmentsInWorld, -maxSegmentsInWorld); 28 | int3 max = new int3(maxSegmentsInWorld, maxSegmentsInWorld, maxSegmentsInWorld); 29 | 30 | int3 offset = (int3)math.round(target.center / propSegmentSize); 31 | 32 | for (int x = -c.x; x < c.x; x++) { 33 | for (int y = -c.y; y < c.y; y++) { 34 | for (int z = -c.z; z < c.z; z++) { 35 | int3 segment = new int3(x, y, z) + offset; 36 | 37 | float3 segmentPos = new float3(segment.x, segment.y, segment.z) * propSegmentSize + new float3(1, 1, 1) * (propSegmentSize / 2.0f); 38 | float distance = math.distance(target.center, segmentPos) / propSegmentSize; 39 | 40 | int lod = (int)math.round(distance / math.max(target.propSegmentLodMultiplier, 0.01)); 41 | lod = math.clamp(lod, 0, 1); 42 | 43 | if (math.all(segment >= min) && math.all(segment < max)) { 44 | propSegments.Add(new int4(segment, lod)); 45 | } 46 | } 47 | } 48 | } 49 | 50 | addedSegments.Clear(); 51 | removedSegments.Clear(); 52 | 53 | foreach (var item in propSegments) { 54 | if (!oldPropSegments.Contains(item)) { 55 | addedSegments.Add(item); 56 | } 57 | } 58 | 59 | foreach (var item in oldPropSegments) { 60 | if (!propSegments.Contains(item)) { 61 | removedSegments.Add(item); 62 | } 63 | } 64 | 65 | oldPropSegments.Clear(); 66 | 67 | foreach (var item in propSegments) { 68 | oldPropSegments.Add(item); 69 | } 70 | } 71 | } -------------------------------------------------------------------------------- /Runtime/Utils/VoxelDecompressionJob.cs: -------------------------------------------------------------------------------- 1 | using Unity.Burst; 2 | using Unity.Collections; 3 | using Unity.Jobs; 4 | using Unity.Mathematics; 5 | using UnityEngine; 6 | 7 | // Decompression job that we will apply over each voxel chunk to decompress its data for loading 8 | [BurstCompile(CompileSynchronously = true)] 9 | internal struct VoxelDecompressionJob : IJob { 10 | [WriteOnly] 11 | public NativeArray densitiesOut; 12 | [ReadOnly] 13 | public NativeArray densitiesIn; 14 | 15 | public void Execute() { 16 | int densityOffset = 0; 17 | int i = 0; 18 | ushort newDensity = ushort.MaxValue; 19 | bool wasDeltaCompressed = false; 20 | int startOfDeltaPart = 0; 21 | 22 | while (i < densitiesIn.Length) { 23 | int currentByte = densitiesIn[i]; 24 | if ((currentByte & (1 << 7)) == 0) { 25 | ushort lastDensity = newDensity; 26 | ushort lastDensityCount = VoxelUtils.BytesToUshort(densitiesIn[i], densitiesIn[i + 1]); 27 | newDensity = VoxelUtils.BytesToUshort(densitiesIn[i+2], densitiesIn[i + 3]); 28 | 29 | /* 30 | Debug.Log("Byte1: " + byte1); 31 | Debug.Log("Byte2: " + byte2); 32 | Debug.Log("Byte3: " + byte3); 33 | Debug.Log("Byte4: " + byte4); 34 | */ 35 | 36 | //Debug.Log("Dens: " + newDensity); 37 | //Debug.Log("Cnt: " + lastDensityCount); 38 | 39 | if (wasDeltaCompressed) { 40 | for (int k = 0; k < lastDensityCount; k++) { 41 | ushort lsb = VoxelUtils.DecodeDelta(densitiesIn[k + startOfDeltaPart]); 42 | ushort packedDensity = (ushort)((lastDensity & 0xFF80) | lsb); 43 | densitiesOut[k + densityOffset] = VoxelUtils.AsHalf(packedDensity); 44 | } 45 | } else { 46 | for (int k = 0; k < lastDensityCount; k++) { 47 | densitiesOut[k + densityOffset] = VoxelUtils.AsHalf(lastDensity); 48 | } 49 | } 50 | 51 | if (densityOffset + lastDensityCount >= 262144) { 52 | Debug.LogWarning("VERY BAD"); 53 | } 54 | 55 | wasDeltaCompressed = false; 56 | startOfDeltaPart = -1; 57 | densityOffset += lastDensityCount; 58 | i += 4; 59 | } else { 60 | if (!wasDeltaCompressed) { 61 | //wasDeltaCompressed = true; 62 | //startOfDeltaPart = i; 63 | } 64 | 65 | i++; 66 | } 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /Runtime/Mesher/CornerJob.cs: -------------------------------------------------------------------------------- 1 | using Unity.Burst; 2 | using Unity.Collections; 3 | using Unity.Jobs; 4 | using Unity.Mathematics; 5 | 6 | 7 | // Corner job that will store the locations of completely empty / filled cells in the mesh to speed up meshing 8 | [BurstCompile(CompileSynchronously = true, FloatMode = FloatMode.Fast, FloatPrecision = FloatPrecision.Low, OptimizeFor = OptimizeFor.Performance)] 9 | public struct CornerJob : IJobParallelFor { 10 | // List of enabled corners like in MC 11 | [WriteOnly] 12 | public NativeArray enabled; 13 | 14 | // Voxel native array 15 | [ReadOnly] 16 | public NativeArray voxels; 17 | 18 | [ReadOnly] 19 | static readonly uint4x3[] offsets = { 20 | new uint4x3( 21 | new uint4(0, 1, 0, 1), 22 | new uint4(0, 0, 1, 1), 23 | new uint4(0, 0, 0, 0) 24 | ), 25 | 26 | new uint4x3( 27 | new uint4(0, 1, 0, 1), 28 | new uint4(0, 0, 1, 1), 29 | new uint4(1, 1, 1, 1) 30 | ) 31 | }; 32 | 33 | // Used for checking for culling ig 34 | public NativeMultiCounter.Concurrent intersectingCases; 35 | 36 | // Static settings 37 | [ReadOnly] public int size; 38 | 39 | public void Execute(int index) { 40 | uint3 position = VoxelUtils.IndexToPos(index); 41 | 42 | if (math.any(position > math.uint3(size - 2))) 43 | return; 44 | 45 | 46 | int4 indices = math.int4(Morton.EncodeMorton32(offsets[0].c0 + position.x, offsets[0].c1 + position.y, offsets[0].c2 + position.z)); 47 | float4 test = math.float4(0.0F); 48 | 49 | for (int i = 0; i < 4; i++) { 50 | test[i] = voxels[indices[i]].density; 51 | } 52 | 53 | int4 indices2 = math.int4(Morton.EncodeMorton32(offsets[1].c0 + position.x, offsets[1].c1 + position.y, offsets[1].c2 + position.z)); 54 | float4 test2 = math.float4(0.0F); 55 | 56 | for (int i = 0; i < 4; i++) { 57 | test2[i] = voxels[indices2[i]].density; 58 | } 59 | 60 | bool4 check1 = test < math.float4(0.0); 61 | bool4 check2 = test2 < math.float4(0.0); 62 | 63 | int value = math.bitmask(check1) | (math.bitmask(check2) << 4); 64 | 65 | /* 66 | bool3 firstTest = position == math.uint3(0); 67 | bool3 secondTest = position == math.uint3(size - 2); 68 | if ((math.any(firstTest) ^ math.any(secondTest)) && (value != 0 || value != 255)) { 69 | int firstTahini = math.bitmask(new bool4(firstTest, false)); 70 | int secondTahini = math.bitmask(new bool4(secondTest, false)); 71 | int combinedTahinis = firstTahini << 3 | secondTahini; 72 | int face = math.lzcnt(combinedTahinis); 73 | face = math.clamp(face, 0, 5); 74 | intersectingCases.Increment(face); 75 | } 76 | */ 77 | 78 | enabled[index] = (byte)value; 79 | } 80 | } -------------------------------------------------------------------------------- /Runtime/Editing/VoxelEditSubdivisionJob.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using Unity.Collections; 3 | using Unity.Jobs; 4 | using Unity.Mathematics; 5 | using Unity.Burst; 6 | 7 | [BurstCompile(CompileSynchronously = true)] 8 | internal struct VoxelEditSubdivisionJob : IJob { 9 | public NativeHashMap chunkLookup; 10 | public NativeList nodes; 11 | public NativeHashMap lookup; 12 | public int sparseVoxelCountOffset; 13 | public NativeList addedNodes; 14 | public NativeList chunksToUpdate; 15 | public Bounds voxelEditBounds; 16 | 17 | public NativeQueue pending; 18 | [ReadOnly] public int maxDepth; 19 | 20 | public void Execute() { 21 | while (pending.TryDequeue(out VoxelEditOctreeNode node)) { 22 | TrySubdivide(ref node); 23 | } 24 | } 25 | 26 | public void TrySubdivide(ref VoxelEditOctreeNode node) { 27 | if (node.Bounds.Intersects(voxelEditBounds) && node.depth <= maxDepth) { 28 | 29 | if (!lookup.ContainsKey(node.index)) { 30 | int lookupIndex = sparseVoxelCountOffset + addedNodes.Length; 31 | node.lookup = lookupIndex; 32 | addedNodes.Add(node.index); 33 | chunkLookup.Add(new VoxelEditOctreeNode.RawNode { 34 | position = node.position, 35 | depth = node.depth, 36 | size = node.size, 37 | }, lookupIndex); 38 | lookup.Add(node.index, lookupIndex); 39 | nodes[node.index] = node; 40 | } 41 | 42 | if (node.lookup != -1) { 43 | chunksToUpdate.Add(node.lookup); 44 | } 45 | 46 | if (node.childBaseIndex == -1 && node.depth < maxDepth) { 47 | node.childBaseIndex = nodes.Length; 48 | nodes[node.index] = node; 49 | 50 | for (int i = 0; i < 8; i++) { 51 | float3 offset = math.float3(VoxelUtils.OctreeChildOffset[i]); 52 | VoxelEditOctreeNode child = new VoxelEditOctreeNode { 53 | position = offset * (node.size / 2.0F) + node.position, 54 | depth = node.depth + 1, 55 | lookup = -1, 56 | size = node.size / 2, 57 | index = node.childBaseIndex + i, 58 | childBaseIndex = -1, 59 | scalingFactor = node.scalingFactor / 2.0F, 60 | }; 61 | 62 | pending.Enqueue(child); 63 | nodes.Add(child); 64 | } 65 | } else if (node.depth < maxDepth) { 66 | for (int i = 0; i < 8; i++) { 67 | pending.Enqueue(nodes[node.childBaseIndex + i]); 68 | } 69 | } 70 | } 71 | } 72 | } -------------------------------------------------------------------------------- /Runtime/Editing/VoxelEditOctreeNode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Unity.Mathematics; 3 | using Unity.Netcode; 4 | using UnityEngine; 5 | 6 | // Heavily simplified octree node for voxel edits 7 | internal struct VoxelEditOctreeNode : IEquatable, IEquatable, INetworkSerializeByMemcpy { 8 | internal struct RawNode : IEquatable, INetworkSerializeByMemcpy { 9 | public float3 position; 10 | public int depth; 11 | public float size; 12 | 13 | public bool Equals(RawNode other) { 14 | return math.all(this.position == other.position) && 15 | this.depth == other.depth && 16 | this.size == other.size; 17 | } 18 | 19 | public override int GetHashCode() { 20 | unchecked { 21 | int hash = 17; 22 | hash = hash * 23 + position.GetHashCode(); 23 | hash = hash * 23 + depth.GetHashCode(); 24 | hash = hash * 23 + size.GetHashCode(); 25 | return hash; 26 | } 27 | } 28 | } 29 | 30 | public float3 position; 31 | public int depth; 32 | public float size; 33 | public int index; 34 | public int childBaseIndex; 35 | public int lookup; 36 | public float scalingFactor; 37 | public float3 Center => math.float3(position) + math.float3(size) / 2.0F; 38 | public Bounds Bounds { get => new Bounds { min = position, max = position + size }; } 39 | public static VoxelEditOctreeNode RootNode(int maxDepth) { 40 | float size = (int)(math.pow(2.0F, (float)(maxDepth))) * VoxelUtils.Size * VoxelUtils.VoxelSizeFactor; 41 | VoxelEditOctreeNode node = new VoxelEditOctreeNode(); 42 | node.position = -math.int3(size / 2); 43 | node.depth = 0; 44 | node.size = size; 45 | node.childBaseIndex = -1; 46 | node.lookup = -1; 47 | node.scalingFactor = math.pow(2.0f, (float)(maxDepth)); 48 | return node; 49 | } 50 | 51 | public bool Equals(VoxelEditOctreeNode other) { 52 | return math.all(this.position == other.position) && 53 | this.depth == other.depth && 54 | this.size == other.size; 55 | } 56 | 57 | public bool Equals(OctreeNode other) { 58 | return math.all(this.position == other.position) && 59 | this.depth == other.depth && 60 | this.size == other.size && 61 | (this.childBaseIndex == -1) == (other.childBaseIndex == -1); 62 | } 63 | 64 | // https://forum.unity.com/threads/burst-error-bc1091-external-and-internal-calls-are-not-allowed-inside-static-constructors.1347293/ 65 | public override int GetHashCode() { 66 | unchecked { 67 | int hash = 17; 68 | hash = hash * 23 + position.GetHashCode(); 69 | hash = hash * 23 + depth.GetHashCode(); 70 | hash = hash * 23 + size.GetHashCode(); 71 | return hash; 72 | } 73 | } 74 | } 75 | 76 | -------------------------------------------------------------------------------- /Editor/CustomEditorVoxelPreview.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using UnityEngine.Experimental.Rendering; 4 | 5 | [CustomEditor(typeof(VoxelGenerator))] 6 | public class CustomEditorVoxelGenerator : Editor { 7 | RenderTexture previewTexture = null; 8 | 9 | public override void OnInspectorGUI() { 10 | base.OnInspectorGUI(); 11 | 12 | VoxelGenerator generator = (VoxelGenerator)target; 13 | 14 | if (GUI.changed && generator.previewMode != VoxelGenerator.Preview3DMode.None) { 15 | Dispatch(generator); 16 | } 17 | } 18 | 19 | private void Dispatch(VoxelGenerator generator) { 20 | generator.UpdateStaticComputeFields(); 21 | 22 | ComputeShader shader = generator.voxelShader; 23 | shader.SetVector("worldOffset", generator.previewWorldOffset); 24 | shader.SetVector("worldScale", generator.previewWorldScale * VoxelUtils.VoxelSizeFactor); 25 | shader.SetTexture(4, "previewVoxels", previewTexture); 26 | shader.SetVector("chunkOffset", Vector3.zero); 27 | shader.SetFloat("previewDensityFactor", generator.previewDensityFactor / generator.previewWorldScale.magnitude); 28 | shader.SetFloat("previewDensityOffset", generator.previewDensityOffset); 29 | shader.SetFloat("chunkScale", 1.0f); 30 | 31 | // Generate the voxel data for the chunk 32 | int count = VoxelUtils.Size / 4; 33 | count *= 2; 34 | shader.Dispatch(4, count, count, count); 35 | } 36 | 37 | private void OnSceneViewGUI(SceneView sv) { 38 | if (Application.isPlaying) return; 39 | 40 | VoxelGenerator generator = (VoxelGenerator)target; 41 | if (generator.previewMode == VoxelGenerator.Preview3DMode.None) return; 42 | 43 | Handles.matrix = Matrix4x4.Scale(Vector3.one * (float)VoxelUtils.Size); 44 | 45 | switch (generator.previewMode) { 46 | case VoxelGenerator.Preview3DMode.Volume: 47 | Handles.DrawTexture3DVolume(previewTexture, generator.previewOpacity, generator.previewQuality, useColorRamp: true, customColorRamp: generator.previewColorRampGradient); 48 | break; 49 | case VoxelGenerator.Preview3DMode.Slice: 50 | Handles.DrawTexture3DSlice(previewTexture, Vector3.zero); 51 | break; 52 | case VoxelGenerator.Preview3DMode.SDF: 53 | Handles.DrawTexture3DSDF(previewTexture, 0.1f); 54 | break; 55 | } 56 | 57 | } 58 | 59 | void OnEnable() { 60 | if (VoxelUtils.Size == 0) 61 | return; 62 | 63 | previewTexture = VoxelUtils.Create3DRenderTexture(VoxelUtils.Size * 2, GraphicsFormat.R32_SFloat); 64 | VoxelGenerator generator = (VoxelGenerator)target; 65 | Dispatch(generator); 66 | SceneView.duringSceneGui += OnSceneViewGUI; 67 | } 68 | 69 | void OnDisable() { 70 | SceneView.duringSceneGui -= OnSceneViewGUI; 71 | } 72 | } -------------------------------------------------------------------------------- /Runtime/TerrainLoader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Unity.Mathematics; 3 | using UnityEngine; 4 | 5 | // Will be used by the prop system to load prop segments and spawn props 6 | public class TerrainLoader : MonoBehaviour { 7 | [Serializable] 8 | public struct Target { 9 | // Should we generate collisions for chunks generated around this target? 10 | public bool generateCollisions; 11 | 12 | // Position of the target in world space (very small coordinates) 13 | [HideInInspector] 14 | public float3 center; 15 | 16 | // Radius in world space 17 | [Min(0.001F)] 18 | public float radius; 19 | 20 | // Should the terrain loader force the voxel props to generated prop segments 21 | public bool affectsVoxelProps; 22 | 23 | // Extents around the terrain loader where we must spawn prop segments 24 | public uint3 propSegmentExtent; 25 | 26 | // Multiplier for the prop segment lod system 27 | public float propSegmentLodMultiplier; 28 | 29 | // Max distance we can move before we must regenerate the octree around us 30 | [Min(0.001F)] 31 | public float maxDistanceThreshold; 32 | } 33 | 34 | public Target data = new Target { 35 | generateCollisions = false, 36 | center = float3.zero, 37 | radius = 16f, 38 | affectsVoxelProps = true, 39 | propSegmentExtent = new uint3(5, 1, 5), 40 | maxDistanceThreshold = 1F, 41 | }; 42 | private Vector3 last; 43 | private VoxelOctree octree; 44 | private VoxelSegments segments; 45 | public Camera viewCamera; 46 | 47 | void Start() { 48 | last = transform.position; 49 | } 50 | 51 | // NOTE: How do we do this in a multiplayer setting? 52 | // will we force the host to load all terrain around all players 53 | // or will it only trust the player inputs and the fact that the players themselves will generate terrain? 54 | 55 | void Update() { 56 | if (VoxelTerrain.Instance != null) { 57 | // Initialize both octree and props 58 | bool bruhtonium = false; 59 | if (octree == null) { 60 | octree = VoxelTerrain.Instance.VoxelOctree; 61 | segments = VoxelTerrain.Instance.VoxelSegments; 62 | 63 | if (VoxelTerrain.Instance.VoxelOctree.target == null) { 64 | octree.target = this; 65 | bruhtonium = true; 66 | octree.mustUpdate = true; 67 | segments.mustUpdate = true; 68 | } else { 69 | Debug.LogWarning("Already have a target. Multi-target support has been removed already!!"); 70 | } 71 | } 72 | 73 | // Update octree variables (pass in required prop segment mul) 74 | if (Vector3.Distance(transform.position, last) > data.maxDistanceThreshold || bruhtonium) { 75 | data.center = transform.position; 76 | octree.mustUpdate = true; 77 | segments.mustUpdate = true; 78 | last = transform.position; 79 | } 80 | } 81 | } 82 | } -------------------------------------------------------------------------------- /Runtime/Utils/noises/noise3D.cginc: -------------------------------------------------------------------------------- 1 | // 2 | // Description : Array and textureless GLSL 2D/3D/4D simplex 3 | // noise functions. 4 | // Author : Ian McEwan, Ashima Arts. 5 | // Maintainer : stegu 6 | // Lastmod : 20201014 (stegu) 7 | // License : Copyright (C) 2011 Ashima Arts. All rights reserved. 8 | // Distributed under the MIT License. See LICENSE file. 9 | // https://github.com/ashima/webgl-noise 10 | // https://github.com/stegu/webgl-noise 11 | // 12 | 13 | float4 taylorInvSqrt(float4 r) 14 | { 15 | return 1.79284291400159 - 0.85373472095314 * r; 16 | } 17 | 18 | float snoise(float3 v) 19 | { 20 | const float2 C = float2(1.0/6.0, 1.0/3.0) ; 21 | const float4 D = float4(0.0, 0.5, 1.0, 2.0); 22 | 23 | // First corner 24 | float3 i = floor(v + dot(v, C.yyy) ); 25 | float3 x0 = v - i + dot(i, C.xxx) ; 26 | 27 | // Other corners 28 | float3 g = step(x0.yzx, x0.xyz); 29 | float3 l = 1.0 - g; 30 | float3 i1 = min( g.xyz, l.zxy ); 31 | float3 i2 = max( g.xyz, l.zxy ); 32 | 33 | // x0 = x0 - 0.0 + 0.0 * C.xxx; 34 | // x1 = x0 - i1 + 1.0 * C.xxx; 35 | // x2 = x0 - i2 + 2.0 * C.xxx; 36 | // x3 = x0 - 1.0 + 3.0 * C.xxx; 37 | float3 x1 = x0 - i1 + C.xxx; 38 | float3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y 39 | float3 x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y 40 | 41 | // Permutations 42 | i = mod289(i); 43 | float4 p = permute( permute( permute( 44 | i.z + float4(0.0, i1.z, i2.z, 1.0 ) + permuationSeed.x) 45 | + i.y + float4(0.0, i1.y, i2.y, 1.0 ) + permuationSeed.y) 46 | + i.x + float4(0.0, i1.x, i2.x, 1.0 ) + permuationSeed.z); 47 | 48 | // Gradients: 7x7 points over a square, mapped onto an octahedron. 49 | // The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294) 50 | float n_ = 0.142857142857; // 1.0/7.0 51 | float3 ns = n_ * D.wyz - D.xzx; 52 | 53 | float4 j = p - 49.0 * floor(p * ns.z * ns.z); // mod(p,7*7) 54 | 55 | float4 x_ = floor(j * ns.z); 56 | float4 y_ = floor(j - 7.0 * x_ ); // mod(j,N) 57 | 58 | float4 x = x_ *ns.x + ns.yyyy; 59 | float4 y = y_ *ns.x + ns.yyyy; 60 | float4 h = 1.0 - abs(x) - abs(y); 61 | 62 | float4 b0 = float4( x.xy, y.xy ); 63 | float4 b1 = float4( x.zw, y.zw ); 64 | 65 | //float4 s0 = float4(lessThan(b0,0.0))*2.0 - 1.0; 66 | //float4 s1 = float4(lessThan(b1,0.0))*2.0 - 1.0; 67 | float4 s0 = floor(b0)*2.0 + 1.0; 68 | float4 s1 = floor(b1)*2.0 + 1.0; 69 | float4 sh = -step(h, 0.0); 70 | 71 | float4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ; 72 | float4 a1 = b1.xzyw + s1.xzyw*sh.zzww ; 73 | 74 | float3 p0 = float3(a0.xy,h.x); 75 | float3 p1 = float3(a0.zw,h.y); 76 | float3 p2 = float3(a1.xy,h.z); 77 | float3 p3 = float3(a1.zw,h.w); 78 | 79 | //Normalise gradients 80 | float4 norm = taylorInvSqrt(float4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3))); 81 | p0 *= norm.x; 82 | p1 *= norm.y; 83 | p2 *= norm.z; 84 | p3 *= norm.w; 85 | 86 | // Mix final noise value 87 | float4 m = max(0.5 - float4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0); 88 | m = m * m; 89 | return 105.0 * dot( m*m, float4( dot(p0,x0), dot(p1,x1), 90 | dot(p2,x2), dot(p3,x3) ) ); 91 | } 92 | -------------------------------------------------------------------------------- /Runtime/Octree/NeigbourJob.cs: -------------------------------------------------------------------------------- 1 | using Unity.Collections; 2 | using Unity.Jobs; 3 | using Unity.Mathematics; 4 | using Unity.Burst; 5 | 6 | // Checks if the node has neighbours of different sizes or not 7 | // Used for creating the appropriate skirts 8 | [BurstCompile(CompileSynchronously = true)] 9 | public struct NeighbourJob : IJobParallelFor { 10 | // Copy of input data so we can execute this in parallel 11 | // This contains the nodes for the whole tree 12 | [ReadOnly] 13 | public NativeArray inputNodes; 14 | 15 | // Output nodees that we will set the update data for 16 | // These are the added diffed nodes 17 | public NativeArray outputNodes; 18 | 19 | // Direction data 20 | static readonly float3[] directions = new float3[] 21 | { 22 | new float3(-1.0F, 0, 0), 23 | new float3(0, -1.0F, 0), 24 | new float3(0, 0, -1.0F), 25 | new float3(1.0F, 0, 0), 26 | new float3(0, 1.0F, 0), 27 | new float3(0, 0, 1.0F), 28 | }; 29 | 30 | // Main octree loader position 31 | public float3 octreeLoaderPosition; 32 | 33 | public void Execute(int index) { 34 | // Find node (current) 35 | OctreeNode node = outputNodes[index]; 36 | 37 | // Skip if it's not a leaf 38 | if (node.childBaseIndex != -1) 39 | return; 40 | 41 | // Skirts that we must apply to the nodes 42 | int skirts = 0x3F; 43 | 44 | for (int i = 0; i < 6; i++) { 45 | float3 dir = directions[i]; 46 | float3 estimatedNeighbouringNodeCenter = math.float3(node.position) + math.float3(node.size) / 2.0F + math.float3(node.size * dir); 47 | int nextChildIndex = 0; 48 | bool breakOuter = false; 49 | int iter = 0; 50 | 51 | // Recursively pick the child that intersects the "neigbouring node" estimated center 52 | while (!breakOuter) { 53 | if (iter > 10000) 54 | break; 55 | 56 | for (int k = 0; k < 8; k++) { 57 | OctreeNode cur = inputNodes[nextChildIndex + k]; 58 | 59 | if (cur.ContainsPoint(estimatedNeighbouringNodeCenter)) { 60 | nextChildIndex = cur.childBaseIndex; 61 | 62 | // We reached a node with the same depth as ours 63 | if (cur.depth == node.depth) { 64 | breakOuter = true; 65 | 66 | 67 | // Enable skirts if said node goes deeper 68 | if (cur.childBaseIndex != -1) 69 | skirts |= 1 << i; 70 | else 71 | skirts &= ~(1 << i); 72 | 73 | 74 | break; 75 | } 76 | 77 | // We reached the bottom of the tree (or too deep), break out 78 | if (nextChildIndex == -1 || cur.depth > node.depth) { 79 | breakOuter = true; 80 | break; 81 | } 82 | 83 | break; 84 | } 85 | } 86 | 87 | iter++; 88 | } 89 | } 90 | 91 | node.skirts = skirts; 92 | outputNodes[index] = node; 93 | } 94 | } -------------------------------------------------------------------------------- /Runtime/Voxelizer/VoxelGeneratorEnd.cginc: -------------------------------------------------------------------------------- 1 | // Seems to work without this janky thing below 2 | //position += (chunkOffset - ((chunkScale * size) / (size - 3.0)) * 0.5); 3 | 4 | 5 | [numthreads(4, 4, 4)] 6 | void CSVoxelizer(uint3 id : SV_DispatchThreadID) 7 | { 8 | // Calculate the main world position 9 | float3 position = float3(id.xzy); 10 | position *= voxelSize; 11 | position -= (1.5 * voxelSize); 12 | 13 | // Chunk offsets + vertex scaling 14 | position *= vertexScaling; 15 | position *= chunkScale; 16 | position += chunkOffset; 17 | 18 | // World offset and scale 19 | position = ((position * worldScale) / voxelSize) + worldOffset; 20 | float density = 0.0; 21 | uint material = 0; 22 | 23 | VoxelAt(position, density, material); 24 | 25 | // Morton encode the texture data 26 | uint packedDensity = f32tof16(density + densityOffset); 27 | uint packedData = packedDensity | (material << 16); 28 | uint mortonIndex = encodeMorton32(id.xzy); 29 | uint3 mortonPos = indexToPos(mortonIndex); 30 | voxels[mortonPos.xzy] = packedData; 31 | } 32 | 33 | // USED FOR PREVIEW ONLY 34 | [numthreads(4, 4, 4)] 35 | void CSPreview(uint3 id : SV_DispatchThreadID) 36 | { 37 | // Calculate the main world position 38 | float3 position = float3(id.xzy); 39 | position *= voxelSize; 40 | position -= (1.5 * voxelSize); 41 | 42 | // Chunk offsets + vertex scaling 43 | position *= vertexScaling; 44 | 45 | // World offset and scale 46 | position = ((position * worldScale) / voxelSize) + worldOffset; 47 | float density = 0.0; 48 | uint material = 0; 49 | 50 | VoxelAt(position, density, material); 51 | 52 | previewVoxels[id.xzy] = density * previewDensityFactor + previewDensityOffset; 53 | } 54 | 55 | // Generates the prop cached voxel data 56 | [numthreads(4, 4, 4)] 57 | void CSPropVoxelizer(uint3 id : SV_DispatchThreadID) 58 | { 59 | float3 position = PropSegmentToWorld(id); 60 | 61 | // TODO: Understand why we need this 62 | // Props are constant size so why would voxel size affect them? 63 | //position *= (1 / voxelSize); 64 | float density = 0.0; 65 | uint material = 0; 66 | VoxelAt(position, density, material); 67 | cachedPropDensities[id.xyz] = density; 68 | } 69 | 70 | // Raycasts to get the position of the surface in a specific axis 71 | // xy 72 | // xz 73 | // yx 74 | [numthreads(4, 4, 4)] 75 | void CSPropRaycaster(uint3 id : SV_DispatchThreadID) 76 | { 77 | float d0 = cachedPropDensities[id]; 78 | float3 p0 = PropSegmentToWorld(id); 79 | 80 | float d1 = cachedPropDensities[id + uint3(1, 0, 0)]; 81 | float3 p1 = PropSegmentToWorld(id + uint3(1, 0, 0)); 82 | 83 | float d2 = cachedPropDensities[id + uint3(0, 1, 0)]; 84 | float3 p2 = PropSegmentToWorld(id + uint3(0, 1, 0)); 85 | 86 | float d3 = cachedPropDensities[id + uint3(0, 0, 1)]; 87 | float3 p3 = PropSegmentToWorld(id + uint3(0, 0, 1)); 88 | 89 | if (d0 < 0 && d3 > 0) { 90 | float inv = invLerp(d0, d3, 0); 91 | float3 finalPosition = lerp(p0, p3, inv); 92 | positionIntersections[uint3(id.xy, 0)] = finalPosition.y; 93 | } 94 | } 95 | 96 | #pragma warning( disable: 4008 ) 97 | 98 | // Clears the textures 99 | [numthreads(4, 4, 1)] 100 | void CSClearRayCastData(uint3 id : SV_DispatchThreadID) 101 | { 102 | float maxValue = 0.0f / 0.0f; 103 | positionIntersections[id] = float4(maxValue, maxValue, maxValue, maxValue); 104 | } -------------------------------------------------------------------------------- /Runtime/Props/Default/noise.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 125de8a4cbd436a4da433e72c1fd73df 3 | TextureImporter: 4 | internalIDToNameTable: [] 5 | externalObjects: {} 6 | serializedVersion: 12 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | flipGreenChannel: 0 24 | isReadable: 0 25 | streamingMipmaps: 0 26 | streamingMipmapsPriority: 0 27 | vTOnly: 0 28 | ignoreMipmapLimit: 0 29 | grayScaleToAlpha: 0 30 | generateCubemap: 6 31 | cubemapConvolution: 0 32 | seamlessCubemap: 0 33 | textureFormat: 1 34 | maxTextureSize: 2048 35 | textureSettings: 36 | serializedVersion: 2 37 | filterMode: 0 38 | aniso: 1 39 | mipBias: 0 40 | wrapU: 0 41 | wrapV: 0 42 | wrapW: 0 43 | nPOTScale: 1 44 | lightmap: 0 45 | compressionQuality: 50 46 | spriteMode: 0 47 | spriteExtrude: 1 48 | spriteMeshType: 1 49 | alignment: 0 50 | spritePivot: {x: 0.5, y: 0.5} 51 | spritePixelsToUnits: 100 52 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 53 | spriteGenerateFallbackPhysicsShape: 1 54 | alphaUsage: 1 55 | alphaIsTransparency: 0 56 | spriteTessellationDetail: -1 57 | textureType: 0 58 | textureShape: 1 59 | singleChannelComponent: 0 60 | flipbookRows: 1 61 | flipbookColumns: 1 62 | maxTextureSizeSet: 0 63 | compressionQualitySet: 0 64 | textureFormatSet: 0 65 | ignorePngGamma: 0 66 | applyGammaDecoding: 0 67 | swizzle: 50462976 68 | cookieLightType: 0 69 | platformSettings: 70 | - serializedVersion: 3 71 | buildTarget: DefaultTexturePlatform 72 | maxTextureSize: 32 73 | resizeAlgorithm: 0 74 | textureFormat: -1 75 | textureCompression: 1 76 | compressionQuality: 50 77 | crunchedCompression: 0 78 | allowsAlphaSplitting: 0 79 | overridden: 0 80 | ignorePlatformSupport: 0 81 | androidETC2FallbackOverride: 0 82 | forceMaximumCompressionQuality_BC6H_BC7: 0 83 | - serializedVersion: 3 84 | buildTarget: Standalone 85 | maxTextureSize: 2048 86 | resizeAlgorithm: 0 87 | textureFormat: -1 88 | textureCompression: 1 89 | compressionQuality: 50 90 | crunchedCompression: 0 91 | allowsAlphaSplitting: 0 92 | overridden: 0 93 | ignorePlatformSupport: 0 94 | androidETC2FallbackOverride: 0 95 | forceMaximumCompressionQuality_BC6H_BC7: 0 96 | - serializedVersion: 3 97 | buildTarget: Server 98 | maxTextureSize: 2048 99 | resizeAlgorithm: 0 100 | textureFormat: -1 101 | textureCompression: 1 102 | compressionQuality: 50 103 | crunchedCompression: 0 104 | allowsAlphaSplitting: 0 105 | overridden: 0 106 | ignorePlatformSupport: 0 107 | androidETC2FallbackOverride: 0 108 | forceMaximumCompressionQuality_BC6H_BC7: 0 109 | spriteSheet: 110 | serializedVersion: 2 111 | sprites: [] 112 | outline: [] 113 | physicsShape: [] 114 | bones: [] 115 | spriteID: 116 | internalID: 0 117 | vertices: [] 118 | indices: 119 | edges: [] 120 | weights: [] 121 | secondaryTextures: [] 122 | nameFileIdTable: {} 123 | mipmapLimitGroupName: 124 | pSDRemoveMatte: 0 125 | userData: 126 | assetBundleName: 127 | assetBundleVariant: 128 | -------------------------------------------------------------------------------- /Runtime/Props/Default/normal.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f32fcc028760d52499735f1b1ebce5c9 3 | TextureImporter: 4 | internalIDToNameTable: [] 5 | externalObjects: {} 6 | serializedVersion: 12 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 0 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | flipGreenChannel: 0 24 | isReadable: 0 25 | streamingMipmaps: 0 26 | streamingMipmapsPriority: 0 27 | vTOnly: 0 28 | ignoreMipmapLimit: 0 29 | grayScaleToAlpha: 0 30 | generateCubemap: 6 31 | cubemapConvolution: 0 32 | seamlessCubemap: 0 33 | textureFormat: 1 34 | maxTextureSize: 2048 35 | textureSettings: 36 | serializedVersion: 2 37 | filterMode: 0 38 | aniso: 1 39 | mipBias: 0 40 | wrapU: 0 41 | wrapV: 0 42 | wrapW: 0 43 | nPOTScale: 1 44 | lightmap: 0 45 | compressionQuality: 50 46 | spriteMode: 0 47 | spriteExtrude: 1 48 | spriteMeshType: 1 49 | alignment: 0 50 | spritePivot: {x: 0.5, y: 0.5} 51 | spritePixelsToUnits: 100 52 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 53 | spriteGenerateFallbackPhysicsShape: 1 54 | alphaUsage: 1 55 | alphaIsTransparency: 0 56 | spriteTessellationDetail: -1 57 | textureType: 1 58 | textureShape: 1 59 | singleChannelComponent: 0 60 | flipbookRows: 1 61 | flipbookColumns: 1 62 | maxTextureSizeSet: 0 63 | compressionQualitySet: 0 64 | textureFormatSet: 0 65 | ignorePngGamma: 0 66 | applyGammaDecoding: 0 67 | swizzle: 50462976 68 | cookieLightType: 0 69 | platformSettings: 70 | - serializedVersion: 3 71 | buildTarget: DefaultTexturePlatform 72 | maxTextureSize: 32 73 | resizeAlgorithm: 0 74 | textureFormat: -1 75 | textureCompression: 1 76 | compressionQuality: 50 77 | crunchedCompression: 0 78 | allowsAlphaSplitting: 0 79 | overridden: 0 80 | ignorePlatformSupport: 0 81 | androidETC2FallbackOverride: 0 82 | forceMaximumCompressionQuality_BC6H_BC7: 0 83 | - serializedVersion: 3 84 | buildTarget: Standalone 85 | maxTextureSize: 2048 86 | resizeAlgorithm: 0 87 | textureFormat: -1 88 | textureCompression: 1 89 | compressionQuality: 50 90 | crunchedCompression: 0 91 | allowsAlphaSplitting: 0 92 | overridden: 0 93 | ignorePlatformSupport: 0 94 | androidETC2FallbackOverride: 0 95 | forceMaximumCompressionQuality_BC6H_BC7: 0 96 | - serializedVersion: 3 97 | buildTarget: Server 98 | maxTextureSize: 2048 99 | resizeAlgorithm: 0 100 | textureFormat: -1 101 | textureCompression: 1 102 | compressionQuality: 50 103 | crunchedCompression: 0 104 | allowsAlphaSplitting: 0 105 | overridden: 0 106 | ignorePlatformSupport: 0 107 | androidETC2FallbackOverride: 0 108 | forceMaximumCompressionQuality_BC6H_BC7: 0 109 | spriteSheet: 110 | serializedVersion: 2 111 | sprites: [] 112 | outline: [] 113 | physicsShape: [] 114 | bones: [] 115 | spriteID: 116 | internalID: 0 117 | vertices: [] 118 | indices: 119 | edges: [] 120 | weights: [] 121 | secondaryTextures: [] 122 | nameFileIdTable: {} 123 | mipmapLimitGroupName: 124 | pSDRemoveMatte: 0 125 | userData: 126 | assetBundleName: 127 | assetBundleVariant: 128 | -------------------------------------------------------------------------------- /Runtime/Octree/OctreeNode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Unity.Mathematics; 3 | 4 | // A singular octree node stored within the octree 5 | // Stored as a struct for performance reasons and to be able to use it within jobs 6 | public struct OctreeNode : IEquatable { 7 | // Invalid type octree node 8 | public static OctreeNode Invalid = new OctreeNode { 9 | parentIndex = -1, 10 | index = -1, 11 | depth = -1, 12 | position = float3.zero, 13 | size = 0, 14 | childBaseIndex = -1, 15 | skirts = -1, 16 | }; 17 | 18 | // Start position (0, 0, 0) of the octree node 19 | public float3 position; 20 | 21 | // Inverse Depth of the node starting from maxDepth 22 | public int depth; 23 | 24 | // The full size of the node 25 | public float size; 26 | 27 | // Index of the current node inside the array 28 | public int index; 29 | 30 | // Index of the parent node (-1 if root) 31 | public int parentIndex; 32 | 33 | // Index of the children nodes 34 | public int childBaseIndex; 35 | 36 | // Center of the node 37 | public float3 Center => math.float3(position) + math.float3(size) / 2.0F; 38 | 39 | // Scaling factor applied to chunks 40 | public float scalingFactor; 41 | 42 | // Directions in which skirts should be enabled 43 | // First 3 bits depict the "base" skirts (x = 0, etc...) 44 | // Next 3 bits depict the "end" skirts (x = size - 2, etc...) 45 | public int skirts; 46 | 47 | // Create the root node 48 | public static OctreeNode RootNode(int maxDepth) { 49 | float size = (int)(math.pow(2.0F, (float)(maxDepth))) * VoxelUtils.Size * VoxelUtils.VoxelSizeFactor; 50 | OctreeNode node = new OctreeNode(); 51 | node.position = -math.int3(size / 2); 52 | node.depth = 0; 53 | node.size = size; 54 | node.index = 0; 55 | node.parentIndex = -1; 56 | node.skirts = 0; 57 | node.childBaseIndex = 1; 58 | node.scalingFactor = math.pow(2.0f, (float)(maxDepth)); 59 | return node; 60 | } 61 | 62 | public bool Equals(OctreeNode other) { 63 | return math.all(this.position == other.position) && 64 | this.depth == other.depth && 65 | this.size == other.size && 66 | this.skirts == other.skirts && 67 | (this.childBaseIndex == -1) == (other.childBaseIndex == -1); 68 | } 69 | 70 | // https://forum.unity.com/threads/burst-error-bc1091-external-and-internal-calls-are-not-allowed-inside-static-constructors.1347293/ 71 | public override int GetHashCode() { 72 | unchecked { 73 | int hash = 17; 74 | hash = hash * 23 + position.GetHashCode(); 75 | hash = hash * 23 + depth.GetHashCode(); 76 | hash = hash * 23 + childBaseIndex.GetHashCode(); 77 | hash = hash * 23 + size.GetHashCode(); 78 | hash = hash * 23 + skirts.GetHashCode(); 79 | return hash; 80 | } 81 | } 82 | 83 | // Check if this node intersects the given AABB 84 | public bool IntersectsAABB(float3 min, float3 max) { 85 | float3 nodeMin = math.float3(position); 86 | float3 nodeMax = math.float3(position) + math.float3(size); 87 | return math.all(min <= nodeMax) && math.all(nodeMin <= max); 88 | } 89 | 90 | // Check if this node contains a point 91 | internal bool ContainsPoint(float3 point) { 92 | float3 nodeMin = math.float3(position); 93 | float3 nodeMax = math.float3(position) + math.float3(size); 94 | return math.all(nodeMin <= point) && math.all(point <= nodeMax); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /Runtime/Props/Default/Tree5.fbx.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1951ddca4eff0e043963e0f307ed0f50 3 | ModelImporter: 4 | serializedVersion: 22200 5 | internalIDToNameTable: [] 6 | externalObjects: 7 | - first: 8 | type: UnityEngine:Material 9 | assembly: UnityEngine.CoreModule 10 | name: LogMat 11 | second: {fileID: 2100000, guid: 466c25623343bb04eb8c6e97d1f198bd, type: 2} 12 | - first: 13 | type: UnityEngine:Material 14 | assembly: UnityEngine.CoreModule 15 | name: PineMat 16 | second: {fileID: 2100000, guid: f3c32e94e039f554e93780039b92c785, type: 2} 17 | materials: 18 | materialImportMode: 2 19 | materialName: 0 20 | materialSearch: 1 21 | materialLocation: 1 22 | animations: 23 | legacyGenerateAnimations: 4 24 | bakeSimulation: 0 25 | resampleCurves: 1 26 | optimizeGameObjects: 0 27 | removeConstantScaleCurves: 0 28 | motionNodeName: 29 | rigImportErrors: 30 | rigImportWarnings: 31 | animationImportErrors: 32 | animationImportWarnings: 33 | animationRetargetingWarnings: 34 | animationDoRetargetingWarnings: 0 35 | importAnimatedCustomProperties: 0 36 | importConstraints: 0 37 | animationCompression: 1 38 | animationRotationError: 0.5 39 | animationPositionError: 0.5 40 | animationScaleError: 0.5 41 | animationWrapMode: 0 42 | extraExposedTransformPaths: [] 43 | extraUserProperties: [] 44 | clipAnimations: [] 45 | isReadable: 0 46 | meshes: 47 | lODScreenPercentages: [] 48 | globalScale: 1 49 | meshCompression: 0 50 | addColliders: 0 51 | useSRGBMaterialColor: 1 52 | sortHierarchyByName: 1 53 | importPhysicalCameras: 1 54 | importVisibility: 1 55 | importBlendShapes: 1 56 | importCameras: 1 57 | importLights: 1 58 | nodeNameCollisionStrategy: 1 59 | fileIdsGeneration: 2 60 | swapUVChannels: 0 61 | generateSecondaryUV: 0 62 | useFileUnits: 1 63 | keepQuads: 0 64 | weldVertices: 1 65 | bakeAxisConversion: 0 66 | preserveHierarchy: 0 67 | skinWeightsMode: 0 68 | maxBonesPerVertex: 4 69 | minBoneWeight: 0.001 70 | optimizeBones: 1 71 | meshOptimizationFlags: -1 72 | indexFormat: 0 73 | secondaryUVAngleDistortion: 8 74 | secondaryUVAreaDistortion: 15.000001 75 | secondaryUVHardAngle: 88 76 | secondaryUVMarginMethod: 1 77 | secondaryUVMinLightmapResolution: 40 78 | secondaryUVMinObjectScale: 1 79 | secondaryUVPackMargin: 4 80 | useFileScale: 0 81 | strictVertexDataChecks: 0 82 | tangentSpace: 83 | normalSmoothAngle: 60 84 | normalImportMode: 0 85 | tangentImportMode: 3 86 | normalCalculationMode: 4 87 | legacyComputeAllNormalsFromSmoothingGroupsWhenMeshHasBlendShapes: 0 88 | blendShapeNormalImportMode: 1 89 | normalSmoothingSource: 0 90 | referencedClips: [] 91 | importAnimation: 1 92 | humanDescription: 93 | serializedVersion: 3 94 | human: [] 95 | skeleton: [] 96 | armTwist: 0.5 97 | foreArmTwist: 0.5 98 | upperLegTwist: 0.5 99 | legTwist: 0.5 100 | armStretch: 0.05 101 | legStretch: 0.05 102 | feetSpacing: 0 103 | globalScale: 1 104 | rootMotionBoneName: 105 | hasTranslationDoF: 0 106 | hasExtraRoot: 0 107 | skeletonHasParents: 1 108 | lastHumanDescriptionAvatarSource: {instanceID: 0} 109 | autoGenerateAvatarMappingIfUnspecified: 1 110 | animationType: 2 111 | humanoidOversampling: 1 112 | avatarSetup: 0 113 | addHumanoidExtraRootOnlyWhenUsingAvatar: 1 114 | importBlendShapeDeformPercent: 1 115 | remapMaterialsIfMaterialImportModeIsNone: 0 116 | additionalBone: 0 117 | userData: 118 | assetBundleName: 119 | assetBundleVariant: 120 | -------------------------------------------------------------------------------- /Runtime/Voxelizer/VoxelGeneratorTemplate.compute: -------------------------------------------------------------------------------- 1 | #pragma kernel CSVoxelizer 2 | #pragma kernel CSPropVoxelizer 3 | #pragma kernel CSPropRaycaster 4 | #pragma kernel CSClearRayCastData 5 | #pragma kernel CSPreview 6 | 7 | #include "Packages/com.jedjoud.voxelterraingenerator/Runtime/Voxelizer/VoxelGeneratorStart.cginc" 8 | 9 | // Called for each voxel in the chunk to check the density and material at a specific position 10 | void VoxelAt(float3 position, out float density, out uint material) { 11 | /* 12 | float height = cellular(position.xz * 0.01).x; 13 | height = exp(-4 * height) * sin(0.5 + 2 * 3.1415 * height); 14 | density = position.y + height * 20; 15 | material = 0; 16 | return; 17 | */ 18 | 19 | 20 | /* 21 | float2 slope2 = float2(position.y * snoise(position.xz * 0.001), position.y * snoise(position.xz * 0.001 + 123)) * 0.04; 22 | float h = voronoise(position.xz * 0.03 + slope2 + snoise(position * 0.04) * 0.1, 1.0, 0.3); 23 | h = max(h, 0.5) * 80; 24 | density = position.y - h; 25 | material = 1; 26 | density *= 0.4; 27 | return; 28 | 29 | 30 | density = -fbmCellular(position.xz * 0.006, 4, 0.5, 2.0).y * 30 + position.y; 31 | float test2 = clamp(fbmCellular(position * 0.01 * float3(1, 2.8, 1), 3, 0.66, 1.3).y - 0.2, 0, 1); 32 | float test1 = (fbmCellular(position.xz * 0.006, 3, 0.66, 1.8).y - 0.2).x * -10; 33 | density += clamp(test1,-2,0) * 10; 34 | density += (clamp(test1,-3,-2)) * 10 + 40; 35 | material = density < -100 ? 1 : 0; 36 | return; 37 | */ 38 | 39 | // Density value for biome 1 40 | material = 0; 41 | float density1 = -fbm(position.xz * 0.001, 5, 0.50, 2.1) * 90 - 50; 42 | density1 += opSmoothUnion(-fbmCellular(position.xz * 0.003, 5, 0.53, 2.1) + 0.6, 0, 1.0) * 260; 43 | 44 | // Density value for biome 2 45 | float density2 = fbmCellular(position.xz * 0.0008, 8, 0.4, 2.2).y * 7; 46 | density2 = -pow(opSmoothIntersection(density2, 4, 5), 3) + 100; 47 | 48 | // Density value for biome 3 49 | float density3 = -fbm(position.xz * 0.005, 4, 0.60, 2.2) * 10 - 50; 50 | float rngSlope = snoise(position.xz * 0.003) * 0.00325; 51 | float2 sloped = position.xz * 0.008 + position.y * (0.008 + rngSlope); 52 | float shortPillars = -fbmCellular(sloped, 4, 0.45, 2.1).x * (snoise(position.xz * 0.002) + 1); 53 | shortPillars = max(shortPillars, -0.7); 54 | density3 += min(shortPillars - 0.05, 0) * 225; 55 | density3 += cellular(sloped * 3).y * 20.0; 56 | 57 | // Mixer between biome 1 and biome 2 58 | float mixer = snoise(position.xz * 0.0003) * 0.5 + 0.5; 59 | float mixer2 = snoise(position.xz * 0.0003 + 12541) * 0.5 + 0.5; 60 | mixer = smoothstep(0, 1, saturate(2 * (mixer - 0.5) + 0.5)); 61 | 62 | density = lerp(density1, density3, mixer); 63 | density = lerp(density2, density, mixer2); 64 | density += position.y; 65 | 66 | /* 67 | // Cave mixer? 68 | float caveMixer = saturate((-(position.y + 30) / 60)) * saturate(((position.y + 600) / 60)); 69 | caveMixer = smoothstep(0, 1, caveMixer); 70 | 71 | float caveDensity = -fbmCellular(position * 0.001 * float3(1, 1.5, 1), 4, 0.4, 2.2).x * 620 + 100; 72 | caveDensity += snoise(float2(position.y, 0) * 0.001) * 300; 73 | float pillars = fbmCellular(position.xz * 0.004, 5, 0.4, 2.0).y; 74 | pillars = smoothstep(0, 1.0, saturate(pillars - 0.3)); 75 | caveDensity -= pillars * 800; 76 | float shortPillars2 = -fbmCellular(position.xz * 0.01, 3, 0.45, 2.1).x; 77 | caveDensity += min(shortPillars2 + 0.25, 0) * 200; 78 | caveDensity -= cellular(position * 0.1 * float3(1, 3, 1)).y * 2; 79 | //density = lerp(density, caveDensity, caveMixer); 80 | material = caveMixer > 0.2 ? 1 : 0; 81 | */ 82 | //material = (shortPillars < 0.2 && (mixer + fbm(position * 0.008, 3, 0.5, 2.2) * 0.1) > 0.4 || (mixer2 < 0.5 && position.y > 200)) ? 1 : 0; 83 | //materail 84 | } 85 | 86 | #include "Packages/com.jedjoud.voxelterraingenerator/Runtime/Voxelizer/VoxelGeneratorEnd.cginc" -------------------------------------------------------------------------------- /Runtime/Materials/Checkers.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!114 &-8766605702265288927 4 | MonoBehaviour: 5 | m_ObjectHideFlags: 11 6 | m_CorrespondingSourceObject: {fileID: 0} 7 | m_PrefabInstance: {fileID: 0} 8 | m_PrefabAsset: {fileID: 0} 9 | m_GameObject: {fileID: 0} 10 | m_Enabled: 1 11 | m_EditorHideFlags: 0 12 | m_Script: {fileID: 11500000, guid: da692e001514ec24dbc4cca1949ff7e8, type: 3} 13 | m_Name: 14 | m_EditorClassIdentifier: 15 | version: 13 16 | hdPluginSubTargetMaterialVersions: 17 | m_Keys: [] 18 | m_Values: 19 | --- !u!21 &2100000 20 | Material: 21 | serializedVersion: 8 22 | m_ObjectHideFlags: 0 23 | m_CorrespondingSourceObject: {fileID: 0} 24 | m_PrefabInstance: {fileID: 0} 25 | m_PrefabAsset: {fileID: 0} 26 | m_Name: Checkers 27 | m_Shader: {fileID: -6465566751694194690, guid: 2f935650640c47841bfe11ff5ce9b6da, 28 | type: 3} 29 | m_Parent: {fileID: 0} 30 | m_ModifiedSerializedProperties: 0 31 | m_ValidKeywords: 32 | - _ALPHATEST_ON 33 | - _DISABLE_SSR_TRANSPARENT 34 | m_InvalidKeywords: [] 35 | m_LightmapFlags: 4 36 | m_EnableInstancingVariants: 0 37 | m_DoubleSidedGI: 0 38 | m_CustomRenderQueue: 2475 39 | stringTagMap: 40 | MotionVector: User 41 | RenderType: TransparentCutout 42 | disabledShaderPasses: 43 | - TransparentDepthPrepass 44 | - TransparentDepthPostpass 45 | - TransparentBackface 46 | - RayTracingPrepass 47 | - MOTIONVECTORS 48 | m_LockedProperties: 49 | m_SavedProperties: 50 | serializedVersion: 3 51 | m_TexEnvs: 52 | - unity_Lightmaps: 53 | m_Texture: {fileID: 0} 54 | m_Scale: {x: 1, y: 1} 55 | m_Offset: {x: 0, y: 0} 56 | - unity_LightmapsInd: 57 | m_Texture: {fileID: 0} 58 | m_Scale: {x: 1, y: 1} 59 | m_Offset: {x: 0, y: 0} 60 | - unity_ShadowMasks: 61 | m_Texture: {fileID: 0} 62 | m_Scale: {x: 1, y: 1} 63 | m_Offset: {x: 0, y: 0} 64 | m_Ints: [] 65 | m_Floats: 66 | - _AddPrecomputedVelocity: 0 67 | - _AlphaCutoffEnable: 1 68 | - _AlphaDstBlend: 0 69 | - _AlphaSrcBlend: 1 70 | - _BlendMode: 0 71 | - _ConservativeDepthOffsetEnable: 0 72 | - _CullMode: 2 73 | - _CullModeForward: 2 74 | - _DepthOffsetEnable: 0 75 | - _DoubleSidedEnable: 0 76 | - _DoubleSidedGIMode: 0 77 | - _DoubleSidedNormalMode: 2 78 | - _DstBlend: 0 79 | - _EnableBlendModePreserveSpecularLighting: 1 80 | - _EnableFogOnTransparent: 1 81 | - _Metallic: 0 82 | - _OpaqueCullMode: 2 83 | - _RayTracing: 0 84 | - _ReceivesSSR: 1 85 | - _ReceivesSSRTransparent: 0 86 | - _RefractionModel: 0 87 | - _RenderQueueType: 1 88 | - _RequireSplitLighting: 0 89 | - _Smoothness: 0 90 | - _SrcBlend: 1 91 | - _StencilRef: 0 92 | - _StencilRefDepth: 8 93 | - _StencilRefDistortionVec: 4 94 | - _StencilRefGBuffer: 10 95 | - _StencilRefMV: 40 96 | - _StencilWriteMask: 6 97 | - _StencilWriteMaskDepth: 9 98 | - _StencilWriteMaskDistortionVec: 4 99 | - _StencilWriteMaskGBuffer: 15 100 | - _StencilWriteMaskMV: 41 101 | - _SupportDecals: 1 102 | - _SurfaceType: 0 103 | - _TransparentBackfaceEnable: 0 104 | - _TransparentCullMode: 2 105 | - _TransparentDepthPostpassEnable: 0 106 | - _TransparentDepthPrepassEnable: 0 107 | - _TransparentSortPriority: 0 108 | - _TransparentWritingMotionVec: 0 109 | - _TransparentZWrite: 0 110 | - _UseShadowThreshold: 0 111 | - _ZTestDepthEqualForOpaque: 3 112 | - _ZTestGBuffer: 3 113 | - _ZTestTransparent: 4 114 | - _ZWrite: 1 115 | m_Colors: 116 | - _Color: {r: 1, g: 1, b: 1, a: 0} 117 | - _DoubleSidedConstants: {r: 1, g: 1, b: -1, a: 0} 118 | - _EmissionColor: {r: 1, g: 1, b: 1, a: 1} 119 | m_BuildTextureStacks: [] 120 | -------------------------------------------------------------------------------- /Runtime/Utils/SerializableRegistry.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using Unity.Netcode; 6 | using UnityEngine; 7 | 8 | public class SerializableRegistry { 9 | internal Dictionary lookup; 10 | internal List types; 11 | 12 | public SerializableRegistry() { 13 | lookup = new Dictionary(); 14 | types = new List(); 15 | } 16 | 17 | // Register a new type that we can use going forward 18 | public void Register() where T : struct, INetworkSerializable { 19 | lookup.Add(typeof(T), (byte)types.Count); 20 | types.Add(new TypedThingy2 { 21 | list = new List() 22 | }); 23 | } 24 | 25 | // Add a new object to the registry 26 | public int Add(T val) where T : struct, INetworkSerializable { 27 | byte type = lookup[typeof(T)]; 28 | List list = (List)types[type].List; 29 | list.Add(val); 30 | return list.Count - 1; 31 | } 32 | 33 | // Retrieve the edit at the specific index and specific type 34 | public T Get(int index) where T : struct, INetworkSerializable { 35 | byte type = lookup[typeof(T)]; 36 | List list = (List)types[type].List; 37 | return list[index]; 38 | } 39 | 40 | public void Serialize(FastBufferWriter writer) { 41 | Debug.Log($"Serializing {types.Count} registry types"); 42 | writer.WriteByteSafe((byte)types.Count); 43 | 44 | foreach (var item in types) { 45 | item.Serialize(writer); 46 | } 47 | } 48 | 49 | public void Deserialize(FastBufferReader reader) { 50 | reader.ReadByteSafe(out byte count); 51 | Debug.Log($"Deserializing {count} registry types"); 52 | 53 | for (int i = 0; i < count; i++) { 54 | types[i].Deserialize(reader); 55 | } 56 | } 57 | 58 | // Tries to get the inner registry values of values of a specific type 59 | // Casts each IList object to T internally 60 | // TODO: Optimize 61 | public List TryGetAll() { 62 | List total = new List(); 63 | foreach (var reg in types) { 64 | if (typeof(T).IsAssignableFrom(reg.Inner)) { 65 | total.AddRange(reg.Enumerable.Select(x => (T)x)); 66 | } 67 | } 68 | return total; 69 | } 70 | } 71 | 72 | internal interface IRegistryType { 73 | public IList List { get; } 74 | public byte Index { get; } 75 | public Type Inner { get; } 76 | public IEnumerable Enumerable { get; } 77 | public void Serialize(FastBufferWriter writer); 78 | public void Deserialize(FastBufferReader reader); 79 | } 80 | 81 | struct TypedThingy2 : IRegistryType where T : struct, INetworkSerializable { 82 | internal List list; 83 | internal byte index; 84 | public Type Inner => typeof(T); 85 | public byte Index => index; 86 | public IList List => list; 87 | public IEnumerable Enumerable => ((IEnumerable)list).Select(x => (object)x); 88 | 89 | public void Serialize(FastBufferWriter writer) { 90 | Debug.Log($"Serializing list of type {typeof(T).Name}"); 91 | writer.WriteByteSafe(index); 92 | writer.WriteValueSafe(list.ToArray()); 93 | } 94 | 95 | public void Deserialize(FastBufferReader reader) { 96 | Debug.Log($"Deserializing list of type {typeof(T).Name}"); 97 | reader.ReadByteSafe(out byte tempIndex); 98 | 99 | if (tempIndex != index) { 100 | Debug.LogError("Mismatch in type! Backwards compat isn't implemented yet. Bruhtonium?"); 101 | } 102 | 103 | reader.ReadValueSafe(out T[] temp); 104 | list.Clear(); 105 | list.AddRange(temp); 106 | } 107 | } -------------------------------------------------------------------------------- /Runtime/Prefabs/Voxel Chunk.prefab: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!1 &6177338312385691531 4 | GameObject: 5 | m_ObjectHideFlags: 0 6 | m_CorrespondingSourceObject: {fileID: 0} 7 | m_PrefabInstance: {fileID: 0} 8 | m_PrefabAsset: {fileID: 0} 9 | serializedVersion: 6 10 | m_Component: 11 | - component: {fileID: 7997404549458471372} 12 | - component: {fileID: 6432250165502823860} 13 | - component: {fileID: 6339310753692409675} 14 | - component: {fileID: 7278345948793822433} 15 | - component: {fileID: 7448608749173672578} 16 | m_Layer: 0 17 | m_Name: Voxel Chunk 18 | m_TagString: Untagged 19 | m_Icon: {fileID: 0} 20 | m_NavMeshLayer: 0 21 | m_StaticEditorFlags: 0 22 | m_IsActive: 1 23 | --- !u!4 &7997404549458471372 24 | Transform: 25 | m_ObjectHideFlags: 0 26 | m_CorrespondingSourceObject: {fileID: 0} 27 | m_PrefabInstance: {fileID: 0} 28 | m_PrefabAsset: {fileID: 0} 29 | m_GameObject: {fileID: 6177338312385691531} 30 | serializedVersion: 2 31 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 32 | m_LocalPosition: {x: 0, y: 0, z: 0} 33 | m_LocalScale: {x: 1, y: 1, z: 1} 34 | m_ConstrainProportionsScale: 0 35 | m_Children: [] 36 | m_Father: {fileID: 0} 37 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 38 | --- !u!33 &6432250165502823860 39 | MeshFilter: 40 | m_ObjectHideFlags: 0 41 | m_CorrespondingSourceObject: {fileID: 0} 42 | m_PrefabInstance: {fileID: 0} 43 | m_PrefabAsset: {fileID: 0} 44 | m_GameObject: {fileID: 6177338312385691531} 45 | m_Mesh: {fileID: 0} 46 | --- !u!23 &6339310753692409675 47 | MeshRenderer: 48 | m_ObjectHideFlags: 0 49 | m_CorrespondingSourceObject: {fileID: 0} 50 | m_PrefabInstance: {fileID: 0} 51 | m_PrefabAsset: {fileID: 0} 52 | m_GameObject: {fileID: 6177338312385691531} 53 | m_Enabled: 1 54 | m_CastShadows: 2 55 | m_ReceiveShadows: 1 56 | m_DynamicOccludee: 1 57 | m_StaticShadowCaster: 1 58 | m_MotionVectors: 1 59 | m_LightProbeUsage: 1 60 | m_ReflectionProbeUsage: 1 61 | m_RayTracingMode: 2 62 | m_RayTraceProcedural: 0 63 | m_RenderingLayerMask: 257 64 | m_RendererPriority: 0 65 | m_Materials: 66 | - {fileID: 0} 67 | m_StaticBatchInfo: 68 | firstSubMesh: 0 69 | subMeshCount: 0 70 | m_StaticBatchRoot: {fileID: 0} 71 | m_ProbeAnchor: {fileID: 0} 72 | m_LightProbeVolumeOverride: {fileID: 0} 73 | m_ScaleInLightmap: 1 74 | m_ReceiveGI: 1 75 | m_PreserveUVs: 0 76 | m_IgnoreNormalsForChartDetection: 0 77 | m_ImportantGI: 0 78 | m_StitchLightmapSeams: 1 79 | m_SelectedEditorRenderState: 3 80 | m_MinimumChartSize: 4 81 | m_AutoUVMaxDistance: 0.5 82 | m_AutoUVMaxAngle: 89 83 | m_LightmapParameters: {fileID: 0} 84 | m_SortingLayerID: 0 85 | m_SortingLayer: 0 86 | m_SortingOrder: 0 87 | m_AdditionalVertexStreams: {fileID: 0} 88 | --- !u!114 &7278345948793822433 89 | MonoBehaviour: 90 | m_ObjectHideFlags: 0 91 | m_CorrespondingSourceObject: {fileID: 0} 92 | m_PrefabInstance: {fileID: 0} 93 | m_PrefabAsset: {fileID: 0} 94 | m_GameObject: {fileID: 6177338312385691531} 95 | m_Enabled: 1 96 | m_EditorHideFlags: 0 97 | m_Script: {fileID: 11500000, guid: 6c05b53cee660b74a8787c1bcfe31e4c, type: 3} 98 | m_Name: 99 | m_EditorClassIdentifier: 100 | --- !u!64 &7448608749173672578 101 | MeshCollider: 102 | m_ObjectHideFlags: 0 103 | m_CorrespondingSourceObject: {fileID: 0} 104 | m_PrefabInstance: {fileID: 0} 105 | m_PrefabAsset: {fileID: 0} 106 | m_GameObject: {fileID: 6177338312385691531} 107 | m_Material: {fileID: 0} 108 | m_IncludeLayers: 109 | serializedVersion: 2 110 | m_Bits: 0 111 | m_ExcludeLayers: 112 | serializedVersion: 2 113 | m_Bits: 0 114 | m_LayerOverridePriority: 0 115 | m_IsTrigger: 0 116 | m_ProvidesContacts: 0 117 | m_Enabled: 1 118 | serializedVersion: 5 119 | m_Convex: 0 120 | m_CookingOptions: 30 121 | m_Mesh: {fileID: 0} 122 | -------------------------------------------------------------------------------- /Runtime/Props/Billboard Capture/PropCaptureFullScreen.shader: -------------------------------------------------------------------------------- 1 | Shader "FullScreen/NewFullScreenCustomPass" 2 | { 3 | Properties 4 | { 5 | _RenderAlbedo("Render Albedo", Integer) = 0 6 | } 7 | 8 | 9 | HLSLINCLUDE 10 | 11 | #pragma vertex Vert 12 | 13 | #pragma target 4.5 14 | #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch 15 | 16 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/CustomPass/CustomPassCommon.hlsl" 17 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl" 18 | 19 | TEXTURE2D_X(_GBufferTexture0); 20 | TEXTURE2D_X(_GBufferTexture1); 21 | TEXTURE2D_X(_GBufferTexture2); 22 | TEXTURE2D_X(_GBufferTexture3); 23 | 24 | // The PositionInputs struct allow you to retrieve a lot of useful information for your fullScreenShader: 25 | // struct PositionInputs 26 | // { 27 | // float3 positionWS; // World space position (could be camera-relative) 28 | // float2 positionNDC; // Normalized screen coordinates within the viewport : [0, 1) (with the half-pixel offset) 29 | // uint2 positionSS; // Screen space pixel coordinates : [0, NumPixels) 30 | // uint2 tileCoord; // Screen tile coordinates : [0, NumTiles) 31 | // float deviceDepth; // Depth from the depth buffer : [0, 1] (typically reversed) 32 | // float linearDepth; // View space Z coordinate : [Near, Far] 33 | // }; 34 | 35 | // To sample custom buffers, you have access to these functions: 36 | // But be careful, on most platforms you can't sample to the bound color buffer. It means that you 37 | // can't use the SampleCustomColor when the pass color buffer is set to custom (and same for camera the buffer). 38 | // float4 CustomPassSampleCustomColor(float2 uv); 39 | // float4 CustomPassLoadCustomColor(uint2 pixelCoords); 40 | // float LoadCustomDepth(uint2 pixelCoords); 41 | // float SampleCustomDepth(float2 uv); 42 | 43 | // There are also a lot of utility function you can use inside Common.hlsl and Color.hlsl, 44 | // you can check them out in the source code of the core SRP package. 45 | 46 | int _TextureType; 47 | 48 | float4 FullScreenPass(Varyings varyings) : SV_Target 49 | { 50 | UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(varyings); 51 | float depth = LoadCameraDepth(varyings.positionCS.xy); 52 | PositionInputs posInput = GetPositionInput(varyings.positionCS.xy, _ScreenSize.zw, depth, UNITY_MATRIX_I_VP, UNITY_MATRIX_V); 53 | 54 | float3 color = float3(0, 0, 0); 55 | 56 | NormalData normalData; 57 | DecodeFromNormalBuffer(posInput.positionSS.xy, normalData); 58 | 59 | if (_TextureType == 0) { 60 | color = LOAD_TEXTURE2D_X(_GBufferTexture0, posInput.positionSS).rgb; 61 | } 62 | else if (_TextureType == 1) { 63 | color = normalData.normalWS.xyz; 64 | color = (color + 1) / 2.0; 65 | } else { 66 | // contains roughness, metallic (HOW), maybe occlusion? 67 | color = float3(1 - normalData.perceptualRoughness, 0, 0); 68 | } 69 | 70 | float alpha = LOAD_TEXTURE2D_X(_GBufferTexture0, posInput.positionSS).a; 71 | 72 | return float4(color, alpha); 73 | } 74 | 75 | ENDHLSL 76 | 77 | SubShader 78 | { 79 | Tags{ "RenderPipeline" = "HDRenderPipeline" } 80 | Pass 81 | { 82 | Name "Custom Pass 0" 83 | 84 | ZWrite Off 85 | ZTest Always 86 | Blend SrcAlpha OneMinusSrcAlpha 87 | Cull Off 88 | 89 | HLSLPROGRAM 90 | #pragma fragment FullScreenPass 91 | ENDHLSL 92 | } 93 | } 94 | Fallback Off 95 | } 96 | --------------------------------------------------------------------------------