コード例 #1
0
        public override async Task <TerrainDetailElementOutput> RetriveTerrainDetailAsync(
            TerrainDescriptionElementTypeEnum type, MyRectangle queryArea,
            TerrainCardinalResolution resolution, RequiredCornersMergeStatus cornersMergeStatus)
        {
            TerrainDetailElement detailElement = null;
            CornersMergeStatus   status        = CornersMergeStatus.MERGED;

            if (cornersMergeStatus == RequiredCornersMergeStatus.NOT_MERGED)
            {
                status = CornersMergeStatus.NOT_MERGED;
            }
            if (type == TerrainDescriptionElementTypeEnum.HEIGHT_ARRAY)
            {
                detailElement = await _provider.GenerateHeightDetailElementAsync(queryArea, resolution, status);
            }
            else if (type == TerrainDescriptionElementTypeEnum.NORMAL_ARRAY)
            {
                detailElement = await _provider.GenerateNormalDetailElementAsync(queryArea, resolution, status);
            }
            else
            {
                Preconditions.Fail("Not supported type: " + type);
            }

            return(new TerrainDetailElementOutput()
            {
                TokenizedElement = new TokenizedTerrainDetailElement()
                {
                    DetailElement = detailElement,
                    Token = null
                },
                UvBase = null
            });
        }
コード例 #2
0
        public override async Task <TerrainDetailElementOutput> RetriveTerrainDetailAsync(
            TerrainDescriptionElementTypeEnum type, MyRectangle queryArea,
            TerrainCardinalResolution resolution, RequiredCornersMergeStatus cornersMergeStatus)
        {
            var queryOutput = await _db.QueryAsync(new TerrainDescriptionQuery()
            {
                QueryArea = queryArea,
                RequestedElementDetails = new List <TerrainDescriptionQueryElementDetail>()
                {
                    new TerrainDescriptionQueryElementDetail()
                    {
                        Resolution          = resolution,
                        Type                = type,
                        RequiredMergeStatus = cornersMergeStatus
                    }
                }
            });

            return(queryOutput.GetElementOfType(type));
        }
コード例 #3
0
 public override Task <TerrainDetailElementOutput> RetriveTerrainDetailAsync(
     TerrainDescriptionElementTypeEnum type, MyRectangle queryArea, TerrainCardinalResolution resolution, RequiredCornersMergeStatus cornersMergeStatus)
 {
     return(TaskUtils.MyFromResult(_mockProvidingFunction(type, queryArea, resolution, cornersMergeStatus)));
 }
コード例 #4
0
        private async Task <TokenizedTerrainDetailElement> GenerateElementAsync(
            MyRectangle alignedArea, TerrainCardinalResolution resolution,
            RequiredCornersMergeStatus requiredMerge,
            TerrainDescriptionElementTypeEnum elementType,
            Func <MyRectangle, TerrainCardinalResolution, CornersMergeStatus, Task <TerrainDetailElement> > detailElementGenerator
            )
        {
            CornersMergeStatus statusWeTarget;

            if (requiredMerge == RequiredCornersMergeStatus.NOT_IMPORTANT)
            {
                if (_memoryTerrainCaches[CornersMergeStatus.MERGED][elementType].IsInCache(GenerateInternalToken(alignedArea, resolution, elementType, CornersMergeStatus.MERGED)))
                {
                    statusWeTarget = CornersMergeStatus.MERGED;
                }
                else
                {
                    statusWeTarget = CornersMergeStatus.NOT_MERGED;
                }
            }
            else if (requiredMerge == RequiredCornersMergeStatus.NOT_MERGED)
            {
                statusWeTarget = CornersMergeStatus.NOT_MERGED;
            }
            else
            {
                statusWeTarget = CornersMergeStatus.MERGED;
            }

            if (!_mergingEnabled)
            {
                statusWeTarget = CornersMergeStatus.NOT_MERGED;
            }

            var internalToken = GenerateInternalToken(alignedArea, resolution, elementType, statusWeTarget);
            var queryOutput   = await _memoryTerrainCaches[statusWeTarget][elementType].TryRetriveAsync(internalToken);

            if (queryOutput.Asset != null)
            {
                return(new TokenizedTerrainDetailElement()
                {
                    DetailElement = new TerrainDetailElement()
                    {
                        Texture = queryOutput.Asset,
                        Resolution = resolution,
                        DetailArea = alignedArea,
                        CornersMergeStatus = statusWeTarget
                    },
                    Token = new TerrainDetailElementToken(alignedArea, resolution, elementType, statusWeTarget)
                });
            }
            else
            {
                var detailElement = await detailElementGenerator(alignedArea, resolution, statusWeTarget);

                var   queryOutputCreationObligationToken = queryOutput.CreationObligationToken.Value;
                await _memoryTerrainCaches[statusWeTarget][elementType].AddAssetAsync(
                    queryOutputCreationObligationToken, internalToken, detailElement.Texture);
                return(new TokenizedTerrainDetailElement()
                {
                    DetailElement = new TerrainDetailElement()
                    {
                        Texture = detailElement.Texture,
                        Resolution = resolution,
                        DetailArea = alignedArea,
                        CornersMergeStatus = statusWeTarget
                    },
                    Token = new TerrainDetailElementToken(alignedArea, resolution, elementType, detailElement.CornersMergeStatus)
                });
            }
        }
コード例 #5
0
 public async Task <TokenizedTerrainDetailElement> GenerateHeightDetailElementAsync(MyRectangle alignedArea,
                                                                                    TerrainCardinalResolution resolution, RequiredCornersMergeStatus requiredMerge)
 {
     return(await GenerateElementAsync(alignedArea, resolution, requiredMerge, TerrainDescriptionElementTypeEnum.HEIGHT_ARRAY, _terrainDetailProvider.GenerateHeightDetailElementAsync));
 }
コード例 #6
0
 private async Task<TerrainDetailElementOutput> RetriveNormalArrayAsync(MyRectangle queryArea, TerrainCardinalResolution resolution, RequiredCornersMergeStatus requiredMerge) //todo
 {
     var alignedArea = _alignmentCalculator.ComputeAlignedTerrainArea(queryArea, resolution);
     return GenerateOutput( await _cachedTerrainDetailProvider.GenerateNormalDetailElementAsync(alignedArea, resolution, requiredMerge), queryArea);
 }
コード例 #7
0
        public async Task <TextureWithSize> GenerateHeightDetailElementAsync(MyRectangle requestedArea,
                                                                             TerrainCardinalResolution resolution, RequiredCornersMergeStatus cornersMergeStatus)
        {
            var textureWithSize = await RetriveFoundationTextureAsync(requestedArea, resolution, cornersMergeStatus);

            var workTexture = new TextureWithCoords(sizedTexture: textureWithSize, coords: requestedArea);

            foreach (var applier in _featureAppliers.Where(c => c.AvalibleResolutions.Contains(resolution))
                     .OrderBy(c => c.Rank))
            {
                workTexture = await applier.Applier.ApplyFeatureAsync(workTexture, resolution, false); //todo

                var localTexture = workTexture;
                await _commonExecutor.AddAction(() => localTexture.Texture.wrapMode = TextureWrapMode.Clamp);
            }

            var textureWithMipMaps = await GenerateTextureWithMipMapsAsync(new TextureWithSize()
            {
                Size    = textureWithSize.Size,
                Texture = workTexture.Texture
            });

            return(new TextureWithSize()
            {
                Size = textureWithSize.Size,
                Texture = textureWithMipMaps
            });
        }
コード例 #8
0
 public abstract Task <TerrainDetailElementOutput> RetriveTerrainDetailAsync(
     TerrainDescriptionElementTypeEnum type, MyRectangle queryArea, TerrainCardinalResolution resolution, RequiredCornersMergeStatus cornersMergeStatus);
コード例 #9
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
            });
        }
コード例 #10
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
            });
        }