コード例 #1
0
        public DemoPartitionContext(
            GraphicsDevice graphicsDevice, ContentManager content, CDLODSettings settings,
            ICDLODVisibleRanges visibleRanges)
        {
            GraphicsDevice = graphicsDevice;
            Content = content;
            this.settings = settings;

            TerrainRenderer = new DemoTerrainRenderer(GraphicsDevice, Content, settings);
            TerrainRenderer.InitializeMorphConsts(visibleRanges);

            var heightColors = new HeightColorCollection();
            // default settings.
            heightColors.AddColor(-1.0000f, new Color(  0,   0, 128, 255));
            heightColors.AddColor(-0.2500f, new Color(  0,   0, 255, 255));
            heightColors.AddColor( 0.0000f, new Color(  0, 128, 255, 255));
            heightColors.AddColor( 0.0625f, new Color(240, 240,  64, 255));
            heightColors.AddColor( 0.1250f, new Color( 32, 160,   0, 255));
            heightColors.AddColor( 0.3750f, new Color(224, 224,   0, 255));
            heightColors.AddColor( 0.7500f, new Color(128, 128, 128, 255));
            heightColors.AddColor( 1.0000f, new Color(255, 255, 255, 255));

            TerrainRenderer.InitializeHeightColors(heightColors);

            Selection = new CDLODSelection(settings, visibleRanges);
        }
コード例 #2
0
ファイル: Node.cs プロジェクト: willcraftia/TestXna
        public Node(int x, int y, int size, ref CDLODSettings settings)
        {
            this.x = x;
            this.y = y;
            this.size = size;

            if (settings.LeafNodeSize < size)
            {
                // if not a leaf node, then create child nodes.

                int childSize = size / 2;
                childTopLeft = new Node(x, y, childSize, ref settings);
                level = childTopLeft.level + 1;

                if (x + childSize < settings.HeightMapWidth - 1)
                {
                    childTopRight = new Node(x + childSize, y, childSize, ref settings);
                }

                if (y + childSize < settings.HeightMapHeight - 1)
                {
                    childBottomLeft = new Node(x, y + childSize, childSize, ref settings);
                }

                if (x + childSize < settings.HeightMapWidth - 1 &&
                    y + childSize < settings.HeightMapHeight - 1)
                {
                    childBottomRight = new Node(x + childSize, y + childSize, childSize, ref settings);
                }
            }
        }
コード例 #3
0
        public DemoTerrainRenderer(GraphicsDevice graphicsDevice, ContentManager content, CDLODSettings settings)
        {
            GraphicsDevice = graphicsDevice;
            Content = content;
            this.settings = settings;

            renderer = new CDLODTerrainRenderer(graphicsDevice, settings);

            sourceEffect = Content.Load<Effect>("TerrainEffect");
            effect = new TerrainEffect(sourceEffect);
            effect.LevelCount = settings.LevelCount;
            effect.TerrainScale = settings.TerrainScale;
            effect.PatchGridSize = renderer.PatchGridSize;
            effect.SetHeightMapInfo(settings.HeightMapWidth, settings.HeightMapHeight);

            lightDirection = new Vector3(0, -1, -1);
            lightDirection.Normalize();

            boundingBoxDrawer = new BoundingBoxDrawer(GraphicsDevice);
            debugEffect = new BasicEffect(GraphicsDevice);
            debugEffect.AmbientLightColor = Vector3.One;
            debugEffect.VertexColorEnabled = true;

            HeightColorVisible = true;
            LightEnabled = true;
        }
コード例 #4
0
        public DemoTerrainRenderer(GraphicsDevice graphicsDevice, ContentManager content, CDLODSettings settings)
        {
            GraphicsDevice = graphicsDevice;
            Content = content;
            this.settings = settings;

            renderer = new CDLODTerrainRenderer(graphicsDevice, settings);

            sourceEffect = Content.Load<Effect>("TerrainEffect");
            effect = new TerrainEffect(sourceEffect);
            effect.LevelCount = settings.LevelCount;
            effect.TerrainScale = settings.TerrainScale;
            effect.PatchGridSize = renderer.PatchGridSize;
            effect.HeightMapSize = new Vector2(settings.HeightMapWidth, settings.HeightMapHeight);
            effect.DiffuseMap0 = Content.Load<Texture2D>("Textures/DiffuseMap0");
            effect.DiffuseMap1 = Content.Load<Texture2D>("Textures/DiffuseMap1");
            effect.DiffuseMap2 = Content.Load<Texture2D>("Textures/DiffuseMap2");
            effect.DiffuseMap3 = Content.Load<Texture2D>("Textures/DiffuseMap3");
            effect.SetDiffuseRange0(-settings.HeightScale * 1.5f, -settings.HeightScale * 0.5f);
            effect.SetDiffuseRange1(-settings.HeightScale * 0.5f, 0);
            effect.SetDiffuseRange2(0, settings.HeightScale * 0.5f);
            effect.SetDiffuseRange3(settings.HeightScale * 0.5f, settings.HeightScale * 1.5f);
            effect.DiffuseMapScale = settings.MapScale;

            lightDirection = new Vector3(0, -1, -1);
            lightDirection.Normalize();

            boundingBoxDrawer = new BoundingBoxDrawer(GraphicsDevice);
            debugEffect = new BasicEffect(GraphicsDevice);
            debugEffect.AmbientLightColor = Vector3.One;
            debugEffect.VertexColorEnabled = true;

            RenderMode = TerrainRenderMode.HeightColor;
            LightEnabled = true;
        }
コード例 #5
0
        public DemoPartitionContext(
            GraphicsDevice graphicsDevice, ContentManager content, CDLODSettings settings,
            ICDLODVisibleRanges visibleRanges, SampleSourceDelegate noiseSource,
            float noiseMinX, float noiseMinY, float noiseWidth, float noiseHeight)
        {
            GraphicsDevice = graphicsDevice;
            Content = content;
            this.settings = settings;
            NoiseSource = noiseSource;
            NoiseMinX = noiseMinX;
            NoiseMinY = noiseMinY;
            NoiseWidth = noiseWidth;
            NoiseHeight = noiseHeight;

            TerrainRenderer = new DemoTerrainRenderer(GraphicsDevice, Content, settings);
            TerrainRenderer.InitializeMorphConsts(visibleRanges);

            var heightColors = new HeightColorCollection();
            // default settings.
            heightColors.AddColor(-1.0000f, Color.Navy);
            heightColors.AddColor(-0.2500f, Color.Blue);
            heightColors.AddColor( 0.0000f, Color.LightSeaGreen);
            heightColors.AddColor( 0.0625f, Color.Khaki);
            heightColors.AddColor( 0.1250f, Color.DarkGreen);
            heightColors.AddColor( 0.3750f, Color.DarkGoldenrod);
            heightColors.AddColor( 0.7500f, Color.Gray);
            heightColors.AddColor( 1.0000f, Color.White);

            TerrainRenderer.InitializeHeightColors(heightColors);

            Selection = new CDLODSelection(settings, visibleRanges);
        }
コード例 #6
0
        public CDLODDefaultVisibleRanges(CDLODSettings settings)
        {
            this.settings = settings;

            FinestNodeSize = DefaultFinestNodeSize;
            DetailBalance = DefaultDetailBalance;
            ranges = new float[settings.LevelCount];
        }
コード例 #7
0
ファイル: CDLODSelection.cs プロジェクト: hwixlab/TestXna
        public CDLODSelection(CDLODSettings settings, ICDLODVisibleRanges visibleRanges)
        {
            Settings = settings;
            VisibleRanges = visibleRanges;

            Frustum = new BoundingFrustum(Matrix.Identity);
            selectedNodes = new CDLODSelectedNode[MaxSelectedNodeCount];
        }
コード例 #8
0
ファイル: QuadTree.cs プロジェクト: hwixlab/TestXna
        public QuadTree(CDLODSettings settings)
        {
            topNodeSize = settings.TopNodeSize;

            topNodeCountX = (int) Math.Ceiling((settings.HeightMapWidth - 1) / (float) topNodeSize);
            topNodeCountY = (int) Math.Ceiling((settings.HeightMapHeight - 1) / (float) topNodeSize);

            topNodes = new Node[topNodeCountX, topNodeCountY];
            for (int y = 0; y < topNodeCountY; y++)
                for (int x = 0; x < topNodeCountX; x++)
                    topNodes[x, y] = new Node(x * topNodeSize, y * topNodeSize, topNodeSize, ref settings);
        }
コード例 #9
0
        public CDLODTerrainRenderer(GraphicsDevice graphicsDevice, CDLODSettings settings)
        {
            if (graphicsDevice == null) throw new ArgumentNullException("graphicsDevice");

            GraphicsDevice = graphicsDevice;
            this.settings = settings;

            instanceVertexBuffer = new WritableVertexBuffer<PatchInstanceVertex>(GraphicsDevice, CDLODSelection.MaxSelectedNodeCount * 2);

            // TODO: I want to change a patch resolution at runtime.
            // patchGridSize = leafNodeSize * patchResolution;
            patchMesh = new PatchMesh(GraphicsDevice, settings.PatchGridSize);
        }
コード例 #10
0
ファイル: DemoPartition.cs プロジェクト: hwixlab/TestXna
        public DemoPartition(DemoPartitionContext context)
        {
            if (context == null) throw new ArgumentNullException("context");

            this.context = context;

            settings = context.Settings;

            heightMap = new NoiseHeightMap(context.GraphicsDevice, settings.HeightMapWidth, settings.HeightMapHeight);
            heightMap.NoiseSource = context.Noise;

            normalMap = new NormalMap(context.GraphicsDevice, settings.HeightMapWidth, settings.HeightMapHeight);
            normalMap.HeightMap = heightMap;
            normalMap.Amplitude = settings.HeightScale;

            noiseRainMap = new NoiseRainMap(settings.HeightMapWidth, settings.HeightMapHeight);
            noiseRainMap.NoiseSource = rainNoise.Sample;
            noiseRainMap.RainAmount = 0.5f;

            uniformRainMap = new Map<float>(settings.HeightMapWidth, settings.HeightMapHeight);
            uniformRainMap.Fill(0.8f);

            terrainRainMap = new Map<float>(settings.HeightMapWidth, settings.HeightMapHeight);

            hydraulicErosion.HeightMap = heightMap;
            //hydraulicErosion.RainMap = noiseRainMap;
            //hydraulicErosion.RainMap = uniformRainMap;
            hydraulicErosion.RainMap = terrainRainMap;

            fastHydraulicErosion.HeightMap = heightMap;
            //fastHydraulicErosion.RainMap = noiseRainMap;
            //fastHydraulicErosion.RainMap = uniformRainMap;
            fastHydraulicErosion.RainMap = terrainRainMap;

            musgraveHydraulicErosion.HeightMap = heightMap;
            //musgraveHydraulicErosion.RainMap = noiseRainMap;
            //musgraveHydraulicErosion.RainMap = uniformRainMap;
            musgraveHydraulicErosion.RainMap = terrainRainMap;

            thermalErosion.HeightMap = heightMap;

            fastThermalErosion.HeightMap = heightMap;

            terrain = new CDLODTerrain(context.Settings);
            terrain.HeightMap = heightMap;
        }
コード例 #11
0
ファイル: DemoPartition.cs プロジェクト: hwixlab/TestXna
        public DemoPartition(DemoPartitionContext context)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            this.context = context;

            settings = context.Settings;

            heightMap = new Map<float>(settings.HeightMapWidth, settings.HeightMapHeight);

            terrain = new CDLODTerrain(context.Settings);
            terrain.HeightMap = heightMap;

            texture = new Texture2D(context.GraphicsDevice, settings.HeightMapWidth, settings.HeightMapWidth, false, SurfaceFormat.Single);

            md.Destination = heightMap;
            md.Seed = context.MDSeed;

            fastThermalErosion.HeightMap = heightMap;
            fastThermalErosion.Talus = 0.5f;
        }
コード例 #12
0
ファイル: CDLODTerrain.cs プロジェクト: hwixlab/TestXna
        public CDLODTerrain(CDLODSettings settings)
        {
            this.settings = settings;

            quadTree = new QuadTree(settings);
        }