public void GeneratePreviewMap() { CurrentChunkX = 0; CurrentChunkY = 0; //Voronoi map TargetedScript.VoronoiGenerator.Result(TargetedScript.MapSeed, PreviewSize, Regions); //Normal map TargetedScript.RandomizeMapRegions(Regions); //GPU GPURegions = GPURegion.CreateGPURegions(Regions); //Create texture PreviewVoronoiGrayscaleTexture = new Texture2D(PreviewSize.x, PreviewSize.y); PreviewRegionMatchTexture = new Texture2D(PreviewSize.x, PreviewSize.y); PreviewVoronoiGrayscaleTexture.wrapMode = TextureWrapMode.Clamp; PreviewVoronoiGrayscaleTexture.filterMode = FilterMode.Point; PreviewVoronoiGrayscaleTexture.Apply(); PreviewRegionMatchTexture.wrapMode = TextureWrapMode.Clamp; PreviewRegionMatchTexture.filterMode = FilterMode.Point; PreviewRegionMatchTexture.Apply(); //for (int x = 0; x < Mathf.CeilToInt(PreviewSize.x / 8.0f); x++) //{ // for (int y = 0; y < Mathf.CeilToInt(PreviewSize.y / 8.0f); y++) // { // GeneratePreviewMapChunk(x, y); // } //} }
public static GPURegion[] CreateGPURegions(List <Region> regions) { GPURegion[] gpuRegions = new GPURegion[regions.Count]; for (int i = 0; i < regions.Count; i++) { gpuRegions[i] = new GPURegion(regions[i]); } return(gpuRegions); }
public void Init(string mapSeed, int cubesPerAxis, float chunkSize, SurfaceBiomeDatabase.SurfaceBiomeList surfaceBiomes, CaveBiomeDatabase.CaveBiomeList caveBiomes, List <Region> regions) { //GPU Vector3[] SurfaceOctaveOffsets = GenerateMapOctaveOffsets(mapSeed, false); Vector3[] CaveOctaveOffsets = GenerateMapOctaveOffsets(mapSeed, true); GPUSurfaceBiome[] GPUSurfaceBiomes = GPUSurfaceBiome.CreateGPUSurfaceBiomes(surfaceBiomes); GPUCaveBiome[] GPUCaveBiomes = GPUCaveBiome.CreateGPUCaveBiomes(caveBiomes); GPURegion[] GPURegions = GPURegion.CreateGPURegions(regions); //Kernal Kernel = NoiseShader.FindKernel("NoiseGenerator"); //Sets NoiseShader.SetInts("ThreadDimensions", new int[3] { cubesPerAxis, cubesPerAxis, cubesPerAxis }); NoiseShader.SetFloat("ChunkSize", chunkSize); NoiseShader.SetFloat("CubesPerAxis", cubesPerAxis); NoiseShader.SetInt("SurfaceOctaves", SurfaceOctaves); NoiseShader.SetFloat("SurfaceLacunarity", SurfaceLacunarity); NoiseShader.SetFloat("SurfaceScale", SurfaceScale); NoiseShader.SetInt("CaveOctaves", CaveOctaves); NoiseShader.SetFloat("CaveLacunarity", CaveLacunarity); NoiseShader.SetFloat("CaveScale", CaveScale); NoiseShader.SetInt("SurfaceBiomesCount", GPUSurfaceBiomes.Length); NoiseShader.SetInt("CaveBiomesCount", GPUCaveBiomes.Length); NoiseShader.SetInt("RegionsCount", GPURegions.Length); //StructuredBuffer sets SurfaceOctaveOffsetsBuffer = new ComputeBuffer(SurfaceOctaves, Stride.Vector3Stride); CaveOctaveOffsetsBuffer = new ComputeBuffer(CaveOctaves, Stride.Vector3Stride); GPUSurfaceBiomesBuffer = new ComputeBuffer(GPUSurfaceBiomes.Length, GPUSurfaceBiome.Stride); GPUCaveBiomesBuffer = new ComputeBuffer(GPUCaveBiomes.Length, GPUCaveBiome.Stride); GPURegionsBuffer = new ComputeBuffer(GPURegions.Length, GPURegion.Stride); SurfaceOctaveOffsetsBuffer.SetData(SurfaceOctaveOffsets); CaveOctaveOffsetsBuffer.SetData(CaveOctaveOffsets); GPUSurfaceBiomesBuffer.SetData(GPUSurfaceBiomes); GPUCaveBiomesBuffer.SetData(GPUCaveBiomes); GPURegionsBuffer.SetData(GPURegions); NoiseShader.SetBuffer(Kernel, "SurfaceOctaveOffsets", SurfaceOctaveOffsetsBuffer); NoiseShader.SetBuffer(Kernel, "CaveOctaveOffsets", CaveOctaveOffsetsBuffer); NoiseShader.SetBuffer(Kernel, "SurfaceBiomes", GPUSurfaceBiomesBuffer); NoiseShader.SetBuffer(Kernel, "CaveBiomes", GPUCaveBiomesBuffer); NoiseShader.SetBuffer(Kernel, "Regions", GPURegionsBuffer); }