void GenerateHeightMap() { // pass 0 if (chunkConfig.rescaleToMinMax) { var heightRough = new RenderTexture(16, 16, 0, RenderTextureFormat.RInt, RenderTextureReadWrite.Linear); heightRough.wrapMode = TextureWrapMode.Clamp; heightRough.filterMode = FilterMode.Bilinear; heightRough.enableRandomWrite = true; heightRough.Create(); var c = chunkConfig.generateChunkHeightMapPass1; c.SetTexture(0, "_planetHeightMap", planetConfig.planetHeightMap); rangeUnitCubePosToGenerateInto.SetParams(c, "_rangeUnitCubePos"); c.SetFloat("_heightMin", 0); c.SetFloat("_heightMax", 1); c.SetTexture(0, "_chunkHeightMap", heightRough); c.Dispatch(0, heightRough.width / 16, heightRough.height / 16, 1); MyProfiler.BeginSample("find texture min max"); var result = FindTextureMinMax.Find(heightRough); MyProfiler.EndSample(); heightMax = result.max.x; heightMin = result.min.x; var r = 0.1f; //HeightRange / 10.0f; heightMax += r; heightMin -= r; //DEBUG //heightMax = 1; heightMin = 0; heightRough.Release(); } // pass 1 RenderTexture height1; { height1 = new RenderTexture(HeightMapResolution, HeightMapResolution, 0, RenderTextureFormat.RInt, RenderTextureReadWrite.Linear); height1.wrapMode = TextureWrapMode.Clamp; height1.filterMode = FilterMode.Bilinear; height1.enableRandomWrite = true; height1.Create(); var c = chunkConfig.generateChunkHeightMapPass1; c.SetTexture(0, "_planetHeightMap", planetConfig.planetHeightMap); rangeUnitCubePosToGenerateInto.SetParams(c, "_rangeUnitCubePos"); c.SetFloat("_heightMin", heightMin); c.SetFloat("_heightMax", heightMax); c.SetTexture(0, "_chunkHeightMap", height1); c.Dispatch(0, height1.width / 16, height1.height / 16, 1); GenerateSlopeAndCurvatureMap(height1); } // pass 2 { if (chunkHeightMap == null) { chunkHeightMap = new RenderTexture(HeightMapResolution, HeightMapResolution, 0, RenderTextureFormat.RInt, RenderTextureReadWrite.Linear); chunkHeightMap.wrapMode = TextureWrapMode.Clamp; chunkHeightMap.filterMode = FilterMode.Bilinear; chunkHeightMap.enableRandomWrite = true; chunkHeightMap.Create(); } var c = chunkConfig.generateChunkHeightMapPass2; SetAll(c, 0); c.SetTexture(0, "_chunkHeightMap", height1); c.SetTexture(0, "_chunkHeightMapNew", chunkHeightMap); c.Dispatch(0, chunkHeightMap.width / 16, chunkHeightMap.height / 16, 1); if (chunkHeightMap.useMipMap) { chunkHeightMap.GenerateMips(); } //GenerateSlopeAndCurvatureMap(chunkHeightMap); } height1.Release(); }
void GenerateHeightMap() { if (chunkConfig.rescaleToMinMax) { var heightRough = new RenderTexture(HeightMapResolution / 2, HeightMapResolution / 2, 0, RenderTextureFormat.RInt, RenderTextureReadWrite.Linear); heightRough.wrapMode = TextureWrapMode.Clamp; heightRough.filterMode = FilterMode.Bilinear; heightRough.enableRandomWrite = true; heightRough.Create(); var c = chunkConfig.generateChunkHeightMap; SetAll(c, 0); c.SetTexture(0, "_planetHeightMap", planetConfig.planetHeightMap); rangeUnitCubePosToGenerateInto.SetParams(c, "_rangeUnitCubePos"); c.SetFloat("_heightMin", 0); c.SetFloat("_heightMax", 1); c.SetTexture(0, "_chunkHeightMap", heightRough); c.Dispatch(0, heightRough.width / 16, heightRough.height / 16, 1); MyProfiler.BeginSample("find texture min max"); var result = FindTextureMinMax.Find(heightRough, RenderTextureFormat.RInt); MyProfiler.EndSample(); heightMax = result.max.x; heightMin = result.min.x; var r = 0.1f; if (parent != null) { r = parent.HeightRange / 5.0f; } heightMax += r; heightMin -= r; //DEBUG //heightMax = 1; heightMin = 0; heightRough.Release(); } { if (generatingData.chunkHeightMap == null) { generatingData.chunkHeightMap = new RenderTexture(HeightMapResolution, HeightMapResolution, 0, RenderTextureFormat.RInt, RenderTextureReadWrite.Linear); generatingData.chunkHeightMap.wrapMode = TextureWrapMode.Clamp; generatingData.chunkHeightMap.filterMode = FilterMode.Bilinear; generatingData.chunkHeightMap.enableRandomWrite = true; generatingData.chunkHeightMap.Create(); } var c = chunkConfig.generateChunkHeightMap; SetAll(c, 0); c.SetTexture(0, "_planetHeightMap", planetConfig.planetHeightMap); rangeUnitCubePosToGenerateInto.SetParams(c, "_rangeUnitCubePos"); c.SetFloat("_heightMin", heightMin); c.SetFloat("_heightMax", heightMax); c.SetBool("_hasParent", parent != null); if (parent != null && parent.HasFullyGeneratedData && parent.FullyGeneratedData.chunkHeightMap) { c.SetTexture(0, "_parentChunkHeightMap", parent.FullyGeneratedData.chunkHeightMap); } c.SetTexture(0, "_chunkHeightMap", generatingData.chunkHeightMap); c.Dispatch(0, generatingData.chunkHeightMap.width / 16, generatingData.chunkHeightMap.height / 16, 1); } }