public TerrainVoxel()
 {
     Transformation.SetScale(Vector3.One * TerrainSize);
     Transformation.SetPosition(Vector3.Up * TerrainSize * 0.25f);
     GenerateFloatingIslands(128);
     terrainMaterial = ResourceManager.Inst.GetMaterial("TerrainMaterial");
     climate = ResourceManager.Inst.GetTerrainClimate("TestTerrain");
     PrepareTriangles();
 }
        public TerrainVoxel(string filename)
        {
            Transformation.SetScale(new Vector3(1, 0.25f, 1) * TerrainSize);
            Transformation.SetPosition(Vector3.Up * TerrainSize * 0.0725f);

            terrainMaterial = ResourceManager.Inst.GetMaterial("TerrainMaterial");
            climate = ResourceManager.Inst.GetTerrainClimate("TestTerrain");

            GenerateTerrainFromFile(filename);
        }
Esempio n. 3
0
 public TerrainVoxel()
 {
     Transformation.SetScale(new Vector3(1, 0.25f, 1) * TerrainSize);
     Transformation.SetPosition(Vector3.Up * TerrainSize * 0.22f);
     //GenerateFloatingIslands(128);
     GenerateTerrainProcedurally();
     terrainMaterial = ResourceManager.Inst.GetMaterial("TerrainMaterial");
     climate = ResourceManager.Inst.GetTerrainClimate("TestTerrain");
     PrepareTriangles();
     TransformLandmarks();
 }
 public ClutterPlacement(TerrainHeightmap terrain, RenderView renderView)
 {
     this.terrain = terrain;
     this.view = renderView;
     this.climate = terrain.GetClimate();
     BuildPlantSpots();
 }
        void BuildBlendMap(Texture2D heightmap)
        {
            climate = ResourceManager.Inst.GetTerrainClimate("TestTerrain");

            DepthStencilBuffer dsOld = GFX.Device.DepthStencilBuffer;
            GFX.Device.DepthStencilBuffer = GFX.Inst.dsBufferLarge;

            Shader gradientShader = ResourceManager.Inst.GetShader("GradientHeightmap");
            gradientShader.SetupShader();
            GFX.Device.SetVertexShaderConstant(GFXShaderConstants.VC_INVTEXRES, Vector2.One / new Vector2(heightmap.Width, heightmap.Height));
            GFX.Device.SetPixelShaderConstant(0, Vector2.One / new Vector2(heightmap.Width, heightmap.Height));
            GFX.Device.Textures[0] = heightmap;

            RenderTarget2D rtGradient = new RenderTarget2D(GFX.Device, heightmap.Width, heightmap.Height, 1, SurfaceFormat.Single);
            GFX.Device.SetRenderTarget(0, rtGradient);
            GFXPrimitives.Quad.Render();
            GFX.Device.SetRenderTarget(0, null);
            GFX.Device.Textures[0] = rtGradient.GetTexture();
            RenderTarget2D rtCurvature = new RenderTarget2D(GFX.Device, heightmap.Width, heightmap.Height, 1, SurfaceFormat.Single);
            GFX.Device.SetRenderTarget(0, rtCurvature);
            GFXPrimitives.Quad.Render();
            GFX.Device.SetRenderTarget(0, null);

            Shader blendShader = ResourceManager.Inst.GetShader("BlendHeightmap");
            blendShader.SetupShader();
            GFX.Device.Textures[0] = heightmap;
            GFX.Device.Textures[1] = rtGradient.GetTexture();
            GFX.Device.Textures[2] = rtCurvature.GetTexture();

            Vector4[] climateParams = new Vector4[4];
            Vector4[] climateParams2 = new Vector4[4];

            int numBlendMapsNeeded = climate.blendZones.Length / 4;
            blendMaps = new RenderTarget2D[numBlendMapsNeeded];

            for (int i = 0; i < numBlendMapsNeeded; i++)
            {
                int offset = i * 4;
                for (int j = 0; j < 4; j++)
                {
                    int climateIndex = j + offset;
                    climateParams[j] = new Vector4(climate.heightCoeffs[climateIndex], climate.gradientCoeffs[climateIndex], climate.curvatureCoeffs[climateIndex], climate.baseScores[climateIndex]);
                    climateParams2[j] = Vector4.One * climate.blendZones[climateIndex];
                }

                GFX.Device.SetPixelShaderConstant(0, climateParams);
                GFX.Device.SetPixelShaderConstant(4, climateParams2);

                blendMaps[i] = new RenderTarget2D(GFX.Device, heightmap.Width, heightmap.Height, 1, SurfaceFormat.Color);
                GFX.Device.SetRenderTarget(0, blendMaps[i]);
                GFXPrimitives.Quad.Render();
                GFX.Device.SetRenderTarget(0, null);
            }

            NormalizeBlendWeights();
            GFX.Device.DepthStencilBuffer = dsOld;
        }
 public override void AddElement(TerrainClimate climate, TerrainRenderElement element)
 {
     Elements.Enqueue(element);
 }
 public virtual void AddElement(TerrainClimate climate, TerrainRenderElement element)
 {
 }
        public override void AddElement(TerrainClimate climate, TerrainRenderElement element)
        {
            if (!Elements.ContainsKey(climate))
                Elements.Add(climate, new Queue<TerrainRenderElement>());

            Elements[climate].Enqueue(element);
        }