public MyRectangle ComputeAlignedTerrainArea(MyRectangle queryArea,
                                                     TerrainCardinalResolution cardinalResolution)
        {
            var newTerrainArea = TerrainShapeUtils.GetAlignedTerrainArea(queryArea, cardinalResolution,
                                                                         _terrainDetailImageSideDisjointResolution);

            return(newTerrainArea);
        }
예제 #2
0
        private TerrainDetailElementOutput GenerateOutput(TokenizedTerrainDetailElement element,
            MyRectangle queryArea)
        {
            var elementArea = element.DetailElement.DetailArea;
            var uvBase = TerrainShapeUtils.ComputeUvOfSubElement(queryArea, elementArea);

            return new TerrainDetailElementOutput()
            {
                UvBase = uvBase,
                TokenizedElement = element
            };
        }
예제 #3
0
        public async Task <TextureWithSize> GenerateNormalDetailElementAsync(MyRectangle requestedArea,
                                                                             TerrainCardinalResolution resolution, RequiredCornersMergeStatus cornersMergeStatus)
        {
            var baseHeightTextureOutput =
                await _baseTerrainDetailProvider.RetriveTerrainDetailAsync(
                    TerrainDescriptionElementTypeEnum.HEIGHT_ARRAY, requestedArea, resolution, cornersMergeStatus);

            var baseHeightTexture = baseHeightTextureOutput.TokenizedElement.DetailElement;

            IntVector2   outTextureSize = TerrainShapeUtils.RetriveTextureSize(requestedArea, resolution);
            UniformsPack pack           = new UniformsPack();

            float heightMultiplier = 0;

            if (resolution == TerrainCardinalResolution.MIN_RESOLUTION)
            {
                heightMultiplier = 1.25f;
            }
            else if (resolution == TerrainCardinalResolution.MID_RESOLUTION)
            {
                heightMultiplier = 10f;
            }
            else
            {
                heightMultiplier = 80f;
            }

            pack.SetTexture("_HeightmapTex", baseHeightTexture.Texture.Texture);
            //pack.SetUniform("_HeightMultiplier", heightMultiplier);
            pack.SetUniform("_HeightMultiplier", 1);
            pack.SetUniform("_GlobalCoords", requestedArea.ToVector4());
            ConventionalTextureInfo outTextureInfo =
                new ConventionalTextureInfo(outTextureSize.X, outTextureSize.Y, TextureFormat.ARGB32, true);

            var renderCoords =
                TerrainShapeUtils.ComputeUvOfSubElement(requestedArea, baseHeightTexture.DetailArea);

            TextureRenderingTemplate template = new TextureRenderingTemplate()
            {
                CanMultistep        = false,
                Coords              = renderCoords,
                OutTextureInfo      = outTextureInfo,
                RenderTextureFormat = RenderTextureFormat.ARGB32,
                ShaderName          = "Custom/Terrain/NormalmapGenerator",
                UniformPack         = pack,
                CreateTexture2D     = false
            };
            var outTex = await _rendererProxy.AddOrder(template);

            await _commonExecutor.AddAction(() => outTex.filterMode = FilterMode.Trilinear);

            await _baseTerrainDetailProvider.RemoveTerrainDetailAsync(baseHeightTextureOutput.TokenizedElement.Token);

            //SavingFileManager.SaveTextureToPngFile(@"C:\temp\norm1.png", outTex as Texture2D);

            return(new TextureWithSize()
            {
                Size = new IntVector2(outTextureSize.X, outTextureSize.Y),
                Texture = outTex
            });
        }
예제 #4
0
        private async Task <TextureWithSize> RetriveFoundationTextureAsync(MyRectangle requestedArea,
                                                                           TerrainCardinalResolution resolution, RequiredCornersMergeStatus cornersMergeStatus)
        {
            Texture     fundationTexture = null;
            MyRectangle renderCoords     = null;

            TerrainDetailElementToken retrivedElementToken = null;

            if (resolution == TerrainCardinalResolution.MIN_RESOLUTION)
            {
                fundationTexture = _fullFundationTextureData.Texture;
                renderCoords     =
                    TerrainShapeUtils.ComputeUvOfSubElement(requestedArea, _fullFundationTextureData.Coords);
            }
            else
            {
                var lowerResolution    = resolution.LowerResolution;
                var fundationQueryArea = TerrainShapeUtils.GetAlignedTerrainArea(requestedArea, lowerResolution,
                                                                                 _configuration.TerrainDetailImageSideDisjointResolution);

                var foundationOutput = await _baseTerrainDetailProvider.RetriveTerrainDetailAsync(
                    TerrainDescriptionElementTypeEnum.HEIGHT_ARRAY, fundationQueryArea, lowerResolution, cornersMergeStatus);

                retrivedElementToken = foundationOutput.TokenizedElement.Token;
                var fundationDetailElement = foundationOutput.TokenizedElement.DetailElement;

                renderCoords =
                    TerrainShapeUtils.ComputeUvOfSubElement(requestedArea, fundationDetailElement.DetailArea);
                fundationTexture = fundationDetailElement.Texture.Texture;
                await _commonExecutor.AddAction(() => fundationTexture.filterMode = FilterMode.Bilinear);
            }

            IntVector2   outTextureSize = TerrainShapeUtils.RetriveTextureSize(requestedArea, resolution);
            UniformsPack pack           = new UniformsPack();

            pack.SetTexture("_SourceTexture", fundationTexture);
            ConventionalTextureInfo outTextureInfo =
                new ConventionalTextureInfo(outTextureSize.X, outTextureSize.Y, TextureFormat.ARGB32, true);
            TextureRenderingTemplate template = new TextureRenderingTemplate()
            {
                CanMultistep        = false,
                Coords              = renderCoords,
                OutTextureInfo      = outTextureInfo,
                RenderTextureFormat = RenderTextureFormat.RFloat,
                ShaderName          = "Custom/TerGen/Cutting",
                UniformPack         = pack,
                CreateTexture2D     = false
            };
            var outTex = await _rendererProxy.AddOrder(template);

            await _commonExecutor.AddAction(() => outTex.wrapMode = TextureWrapMode.Clamp);

            if (retrivedElementToken != null)
            {
                await _baseTerrainDetailProvider.RemoveTerrainDetailAsync(retrivedElementToken);
            }

            return(new TextureWithSize()
            {
                Size = outTextureSize,
                Texture = outTex
            });
        }
 public MyRectangle GetAlignedTerrainArea(IntVector2 griddedArea, TerrainCardinalResolution cardinalResolution)
 {
     return(TerrainShapeUtils.GetAlignedTerrainArea(griddedArea, cardinalResolution,
                                                    _terrainDetailImageSideDisjointResolution));
 }
 public MyRectangle GetAlignedTerrainArea(MyRectangle queryArea, TerrainCardinalResolution cardinalResolution)
 {
     return(TerrainShapeUtils.GetAlignedTerrainArea(queryArea, cardinalResolution,
                                                    _terrainDetailImageSideDisjointResolution));
 }