Ejemplo n.º 1
0
        private void UpsampleTileData(Context context, ClipmapLevel level, RasterDataDetails details, RasterTileRegion region)
        {
            ClipmapLevel coarserLevel = level.CoarserLevel;

            if (coarserLevel == null)
            {
                return;
            }

            Texture2D levelTexture;
            Texture2D coarserLevelTexture;
            Vector2I  originInTextures;
            Vector2I  coarserOriginInTextures;

            ClipmapLevel.Extent nextExtent;
            ClipmapLevel.Extent coarserNextExtent;

            if (details.Type == RasterType.Terrain)
            {
                levelTexture            = level.HeightTexture;
                coarserLevelTexture     = coarserLevel.HeightTexture;
                originInTextures        = level.OriginInTextures;
                coarserOriginInTextures = coarserLevel.OriginInTextures;
                nextExtent        = level.NextExtent;
                coarserNextExtent = coarserLevel.NextExtent;
            }
            else
            {
                levelTexture            = level.ImageryTexture;
                coarserLevelTexture     = coarserLevel.ImageryTexture;
                originInTextures        = level.OriginInImagery;
                coarserOriginInTextures = coarserLevel.OriginInImagery;
                nextExtent        = level.NextImageryExtent;
                coarserNextExtent = coarserLevel.NextImageryExtent;
            }

            context.TextureUnits[0].Texture        = coarserLevelTexture;
            context.TextureUnits[0].TextureSampler = Device.TextureSamplers.LinearRepeat;

            _framebuffer.ColorAttachments[_upsampleTexelOutput] = levelTexture;

            int fineClipmapSize = nextExtent.East - nextExtent.West + 1;
            int destWest        = (originInTextures.X + (region.Tile.West + region.West - nextExtent.West)) % fineClipmapSize;
            int destSouth       = (originInTextures.Y + (region.Tile.South + region.South - nextExtent.South)) % fineClipmapSize;

            int    coarseClipmapSize = coarserNextExtent.East - coarserNextExtent.West + 1;
            double sourceWest        = (coarserOriginInTextures.X + ((region.Tile.West + region.West) / 2.0 - coarserNextExtent.West)) % coarseClipmapSize;
            double sourceSouth       = (coarserOriginInTextures.Y + ((region.Tile.South + region.South) / 2.0 - coarserNextExtent.South)) % coarseClipmapSize;

            int width  = region.East - region.West + 1;
            int height = region.North - region.South + 1;

            _upsampleSourceOrigin.Value       = new Vector2F((float)sourceWest, (float)sourceSouth);
            _upsampleUpdateSize.Value         = new Vector2F(width, height);
            _upsampleDestinationOffset.Value  = new Vector2F(destWest, destSouth);
            _upsampleOneOverTextureSize.Value = new Vector2F(1.0f / coarserLevelTexture.Description.Width, 1.0f / coarserLevelTexture.Description.Height);

            // Save the current state of the context
            Rectangle   oldViewport    = context.Viewport;
            Framebuffer oldFramebuffer = context.Framebuffer;

            // Update the context and draw
            context.Viewport    = new Rectangle(0, 0, levelTexture.Description.Width, levelTexture.Description.Height);
            context.Framebuffer = _framebuffer;
            context.Draw(_unitQuadPrimitiveType, _upsampleDrawState, _sceneState);

            // Restore the context to its original state
            context.Framebuffer = oldFramebuffer;
            context.Viewport    = oldViewport;
        }
Ejemplo n.º 2
0
        private void RenderTileToLevelTexture(Context context, ClipmapLevel level, RasterDataDetails details, RasterTileRegion region, Texture2D tileTexture)
        {
            Texture2D levelTexture;
            Vector2I  originInTextures;

            ClipmapLevel.Extent nextExtent;

            if (details.Type == RasterType.Terrain)
            {
                levelTexture     = level.HeightTexture;
                originInTextures = level.OriginInTextures;
                nextExtent       = level.NextExtent;
            }
            else
            {
                levelTexture     = level.ImageryTexture;
                originInTextures = level.OriginInImagery;
                nextExtent       = level.NextImageryExtent;
            }

            context.TextureUnits[0].Texture        = tileTexture;
            context.TextureUnits[0].TextureSampler = Device.TextureSamplers.NearestClamp;

            _framebuffer.ColorAttachments[_updateTexelOutput] = levelTexture;

            int clipmapSize = nextExtent.East - nextExtent.West + 1;
            int destWest    = (originInTextures.X + (region.Tile.West + region.West - nextExtent.West)) % clipmapSize;
            int destSouth   = (originInTextures.Y + (region.Tile.South + region.South - nextExtent.South)) % clipmapSize;

            int width  = region.East - region.West + 1;
            int height = region.North - region.South + 1;

            _updateSourceOrigin.Value      = new Vector2F(region.West, region.South);
            _updateUpdateSize.Value        = new Vector2F(width, height);
            _updateDestinationOffset.Value = new Vector2F(destWest, destSouth);

            // Save the current state of the context
            Rectangle   oldViewport    = context.Viewport;
            Framebuffer oldFramebuffer = context.Framebuffer;

            // Update the context and draw
            context.Viewport    = new Rectangle(0, 0, levelTexture.Description.Width, levelTexture.Description.Height);
            context.Framebuffer = _framebuffer;
            context.Draw(_unitQuadPrimitiveType, _updateDrawState, _sceneState);

            // Restore the context to its original state
            context.Framebuffer = oldFramebuffer;
            context.Viewport    = oldViewport;
        }
Ejemplo n.º 3
0
        public RasterTileRegion[] GetTilesInExtent(int west, int south, int east, int north)
        {
            int tileXStart = west / LongitudePostsPerTile;
            int tileXStop  = east / LongitudePostsPerTile;

            if (west < 0)
            {
                --tileXStart;
            }
            if (east < 0)
            {
                --tileXStop;
            }

            int tileYStart = south / LatitudePostsPerTile;
            int tileYStop  = north / LatitudePostsPerTile;

            if (south < 0)
            {
                --tileYStart;
            }
            if (north < 0)
            {
                --tileYStop;
            }

            int tileWidth  = tileXStop - tileXStart + 1;
            int tileHeight = tileYStop - tileYStart + 1;

            RasterTileRegion[] result = new RasterTileRegion[tileWidth * tileHeight];
            int resultIndex           = 0;

            for (int tileY = tileYStart; tileY <= tileYStop; ++tileY)
            {
                int tileYOrigin = tileY * LatitudePostsPerTile;

                int currentSouth = south - tileYOrigin;
                if (currentSouth < 0)
                {
                    currentSouth = 0;
                }

                int currentNorth = north - tileYOrigin;
                if (currentNorth >= LatitudePostsPerTile)
                {
                    currentNorth = LatitudePostsPerTile - 1;
                }

                for (int tileX = tileXStart; tileX <= tileXStop; ++tileX)
                {
                    int tileXOrigin = tileX * LongitudePostsPerTile;

                    int currentWest = west - tileXOrigin;
                    if (currentWest < 0)
                    {
                        currentWest = 0;
                    }

                    int currentEast = east - tileXOrigin;
                    if (currentEast >= LongitudePostsPerTile)
                    {
                        currentEast = LongitudePostsPerTile - 1;
                    }

                    RasterTileIdentifier tileID = new RasterTileIdentifier(_level, tileX, tileY);
                    RasterTile           tile   = Source.GetTile(tileID);
                    result[resultIndex] = new RasterTileRegion(tile, currentWest, currentSouth, currentEast, currentNorth);
                    ++resultIndex;
                }
            }

            return(result);
        }
Ejemplo n.º 4
0
        private void UpsampleTileData(Context context, ClipmapLevel level, RasterDataDetails details, RasterTileRegion region)
        {
            ClipmapLevel coarserLevel = level.CoarserLevel;

            if (coarserLevel == null)
                return;

            Texture2D levelTexture;
            Texture2D coarserLevelTexture;
            Vector2I originInTextures;
            Vector2I coarserOriginInTextures;
            ClipmapLevel.Extent nextExtent;
            ClipmapLevel.Extent coarserNextExtent;

            if (details.Type == RasterType.Terrain)
            {
                levelTexture = level.HeightTexture;
                coarserLevelTexture = coarserLevel.HeightTexture;
                originInTextures = level.OriginInTextures;
                coarserOriginInTextures = coarserLevel.OriginInTextures;
                nextExtent = level.NextExtent;
                coarserNextExtent = coarserLevel.NextExtent;
            }
            else
            {
                levelTexture = level.ImageryTexture;
                coarserLevelTexture = coarserLevel.ImageryTexture;
                originInTextures = level.OriginInImagery;
                coarserOriginInTextures = coarserLevel.OriginInImagery;
                nextExtent = level.NextImageryExtent;
                coarserNextExtent = coarserLevel.NextImageryExtent;
            }

            context.TextureUnits[0].Texture = coarserLevelTexture;
            context.TextureUnits[0].TextureSampler = Device.TextureSamplers.LinearRepeat;

            _framebuffer.ColorAttachments[_upsampleTexelOutput] = levelTexture;

            int fineClipmapSize = nextExtent.East - nextExtent.West + 1;
            int destWest = (originInTextures.X + (region.Tile.West + region.West - nextExtent.West)) % fineClipmapSize;
            int destSouth = (originInTextures.Y + (region.Tile.South + region.South - nextExtent.South)) % fineClipmapSize;

            int coarseClipmapSize = coarserNextExtent.East - coarserNextExtent.West + 1;
            double sourceWest = (coarserOriginInTextures.X + ((region.Tile.West + region.West) / 2.0 - coarserNextExtent.West)) % coarseClipmapSize;
            double sourceSouth = (coarserOriginInTextures.Y + ((region.Tile.South + region.South) / 2.0 - coarserNextExtent.South)) % coarseClipmapSize;

            int width = region.East - region.West + 1;
            int height = region.North - region.South + 1;

            _upsampleSourceOrigin.Value = new Vector2F((float)sourceWest, (float)sourceSouth);
            _upsampleUpdateSize.Value = new Vector2F(width, height);
            _upsampleDestinationOffset.Value = new Vector2F(destWest, destSouth);
            _upsampleOneOverTextureSize.Value = new Vector2F(1.0f / coarserLevelTexture.Description.Width, 1.0f / coarserLevelTexture.Description.Height);

            // Save the current state of the context
            Rectangle oldViewport = context.Viewport;
            Framebuffer oldFramebuffer = context.Framebuffer;

            // Update the context and draw
            context.Viewport = new Rectangle(0, 0, levelTexture.Description.Width, levelTexture.Description.Height);
            context.Framebuffer = _framebuffer;
            context.Draw(_unitQuadPrimitiveType, _upsampleDrawState, _sceneState);

            // Restore the context to its original state
            context.Framebuffer = oldFramebuffer;
            context.Viewport = oldViewport;
        }
Ejemplo n.º 5
0
        private void RenderTileToLevelTexture(Context context, ClipmapLevel level, RasterDataDetails details, RasterTileRegion region, Texture2D tileTexture)
        {
            Texture2D levelTexture;
            Vector2I originInTextures;
            ClipmapLevel.Extent nextExtent;

            if (details.Type == RasterType.Terrain)
            {
                levelTexture = level.HeightTexture;
                originInTextures = level.OriginInTextures;
                nextExtent = level.NextExtent;
            }
            else
            {
                levelTexture = level.ImageryTexture;
                originInTextures = level.OriginInImagery;
                nextExtent = level.NextImageryExtent;
            }

            context.TextureUnits[0].Texture = tileTexture;
            context.TextureUnits[0].TextureSampler = Device.TextureSamplers.NearestClamp;

            _framebuffer.ColorAttachments[_updateTexelOutput] = levelTexture;

            int clipmapSize = nextExtent.East - nextExtent.West + 1;
            int destWest = (originInTextures.X + (region.Tile.West + region.West - nextExtent.West)) % clipmapSize;
            int destSouth = (originInTextures.Y + (region.Tile.South + region.South - nextExtent.South)) % clipmapSize;

            int width = region.East - region.West + 1;
            int height = region.North - region.South + 1;

            _updateSourceOrigin.Value = new Vector2F(region.West, region.South);
            _updateUpdateSize.Value = new Vector2F(width, height);
            _updateDestinationOffset.Value = new Vector2F(destWest, destSouth);

            // Save the current state of the context
            Rectangle oldViewport = context.Viewport;
            Framebuffer oldFramebuffer = context.Framebuffer;

            // Update the context and draw
            context.Viewport = new Rectangle(0, 0, levelTexture.Description.Width, levelTexture.Description.Height);
            context.Framebuffer = _framebuffer;
            context.Draw(_unitQuadPrimitiveType, _updateDrawState, _sceneState);

            // Restore the context to its original state
            context.Framebuffer = oldFramebuffer;
            context.Viewport = oldViewport;
        }
Ejemplo n.º 6
0
        public RasterTileRegion[] GetTilesInExtent(int west, int south, int east, int north)
        {
            int tileXStart = west / LongitudePostsPerTile;
            int tileXStop = east / LongitudePostsPerTile;

            if (west < 0)
            {
                --tileXStart;
            }
            if (east < 0)
            {
                --tileXStop;
            }

            int tileYStart = south / LatitudePostsPerTile;
            int tileYStop = north / LatitudePostsPerTile;

            if (south < 0)
            {
                --tileYStart;
            }
            if (north < 0)
            {
                --tileYStop;
            }

            int tileWidth = tileXStop - tileXStart + 1;
            int tileHeight = tileYStop - tileYStart + 1;

            RasterTileRegion[] result = new RasterTileRegion[tileWidth * tileHeight];
            int resultIndex = 0;

            for (int tileY = tileYStart; tileY <= tileYStop; ++tileY)
            {
                int tileYOrigin = tileY * LatitudePostsPerTile;

                int currentSouth = south - tileYOrigin;
                if (currentSouth < 0)
                    currentSouth = 0;

                int currentNorth = north - tileYOrigin;
                if (currentNorth >= LatitudePostsPerTile)
                    currentNorth = LatitudePostsPerTile - 1;

                for (int tileX = tileXStart; tileX <= tileXStop; ++tileX)
                {
                    int tileXOrigin = tileX * LongitudePostsPerTile;

                    int currentWest = west - tileXOrigin;
                    if (currentWest < 0)
                        currentWest = 0;

                    int currentEast = east - tileXOrigin;
                    if (currentEast >= LongitudePostsPerTile)
                        currentEast = LongitudePostsPerTile - 1;

                    RasterTileIdentifier tileID = new RasterTileIdentifier(_level, tileX, tileY);
                    RasterTile tile = Source.GetTile(tileID);
                    result[resultIndex] = new RasterTileRegion(tile, currentWest, currentSouth, currentEast, currentNorth);
                    ++resultIndex;
                }
            }

            return result;
        }