示例#1
0
        public TerrainShading()
        {
            _window                   = Device.CreateWindow(800, 600, "Chapter 11:  Terrain Shading");
            _window.Resize           += OnResize;
            _window.RenderFrame      += OnRenderFrame;
            _window.Keyboard.KeyDown += OnKeyDown;
            _window.Keyboard.KeyUp   += OnKeyUp;
            _sceneState               = new SceneState();
            _sceneState.Camera.PerspectiveFarPlaneDistance = 4096;
            _sceneState.DiffuseIntensity  = 0.9f;
            _sceneState.SpecularIntensity = 0.05f;
            _sceneState.AmbientIntensity  = 0.05f;
            _clearState = new ClearState();

            ///////////////////////////////////////////////////////////////////

            TerrainTile terrainTile = TerrainTile.FromBitmap(new Bitmap("ps-e.lg.png"));

            _tile = new VertexDisplacementMapTerrainTile(_window.Context, terrainTile);
            _tile.HeightExaggeration     = 30;
            _tile.ColorMapTexture        = Device.CreateTexture2D(new Bitmap("ps_texture_1k.png"), TextureFormat.RedGreenBlue8, false);
            _tile.ColorRampHeightTexture = Device.CreateTexture2D(new Bitmap("ColorRamp.jpg"), TextureFormat.RedGreenBlue8, false);
            _tile.ColorRampSlopeTexture  = Device.CreateTexture2D(new Bitmap("ColorRampSlope.jpg"), TextureFormat.RedGreenBlue8, false);
            _tile.BlendRampTexture       = Device.CreateTexture2D(new Bitmap("BlendRamp.jpg"), TextureFormat.Red8, false);
            _tile.GrassTexture           = Device.CreateTexture2D(new Bitmap("Grass.jpg"), TextureFormat.RedGreenBlue8, false);
            _tile.StoneTexture           = Device.CreateTexture2D(new Bitmap("Stone.jpg"), TextureFormat.RedGreenBlue8, false);
            _tile.BlendMaskTexture       = Device.CreateTexture2D(new Bitmap("BlendMask.jpg"), TextureFormat.Red8, false);

            ///////////////////////////////////////////////////////////////////

            double tileRadius = Math.Max(terrainTile.Resolution.X, terrainTile.Resolution.Y) * 0.5;

            _camera                           = new CameraLookAtPoint(_sceneState.Camera, _window, Ellipsoid.UnitSphere);
            _camera.CenterPoint               = new Vector3D(terrainTile.Resolution.X * 0.5, terrainTile.Resolution.Y * 0.5, 0.0);
            _camera.MinimumRotateRate         = 1.0;
            _camera.MaximumRotateRate         = 1.0;
            _camera.RotateRateRangeAdjustment = 0.0;
            _camera.RotateFactor              = 0.0;
            _sceneState.Camera.ZoomToTarget(tileRadius);

            ///////////////////////////////////////////////////////////////////

            _hudFont   = new Font("Arial", 16);
            _hud       = new HeadsUpDisplay();
            _hud.Color = Color.Black;
            UpdateHUD();
        }
        public TerrainRayCasting()
        {
            _window                   = Device.CreateWindow(800, 600, "Chapter 11:  Terrain Ray Casting");
            _window.Resize           += OnResize;
            _window.RenderFrame      += OnRenderFrame;
            _window.Keyboard.KeyDown += OnKeyDown;
            _sceneState               = new SceneState();
            _sceneState.Camera.PerspectiveFarPlaneDistance = 4096;
            _clearState = new ClearState();

            ///////////////////////////////////////////////////////////////////

            // 创建地形高程对象
            TerrainTile terrainTile = TerrainTile.FromBitmap(new Bitmap(@"ps-e.lg.png"));

            // 创建地形图形可渲染对象
            _tile = new RayCastedTerrainTile(terrainTile);
            // 地形高度缩放因子(可以使高山更高)
            _tile.HeightExaggeration = 30;

            ///////////////////////////////////////////////////////////////////

            // 根据地形设置相机位置
            double tileRadius = Math.Max(terrainTile.Resolution.X, terrainTile.Resolution.Y) * 0.5;

            _camera                           = new CameraLookAtPoint(_sceneState.Camera, _window, Ellipsoid.UnitSphere);
            _camera.CenterPoint               = new Vector3D(terrainTile.Resolution.X * 0.5, terrainTile.Resolution.Y * 0.5, 0.0);
            _camera.MinimumRotateRate         = 1.0;
            _camera.MaximumRotateRate         = 1.0;
            _camera.RotateRateRangeAdjustment = 0.0;
            _camera.RotateFactor              = 0.0;
            _sceneState.Camera.ZoomToTarget(tileRadius);

            ///////////////////////////////////////////////////////////////////

            _hudFont   = new Font("Arial", 16);
            _hud       = new HeadsUpDisplay();
            _hud.Color = Color.Black;
            UpdateHUD();
        }
示例#3
0
        public LinesOnTerrain()
        {
            _window                   = Device.CreateWindow(800, 600, "Research:  Lines on Terrain");
            _window.Resize           += OnResize;
            _window.RenderFrame      += OnRenderFrame;
            _window.Keyboard.KeyDown += OnKeyDown;
            _sceneState               = new SceneState();
            _sceneState.Camera.PerspectiveFarPlaneDistance  = 4096;
            _sceneState.Camera.PerspectiveNearPlaneDistance = 10;

            _instructions         = new HeadsUpDisplay();
            _instructions.Texture = Device.CreateTexture2D(
                Device.CreateBitmapFromText(
                    "u - Use silhouette\ns - Show silhouette\n",
                    new Font("Arial", 24)),
                TextureFormat.RedGreenBlueAlpha8, false);
            _instructions.Color = Color.LightBlue;

            ///////////////////////////////////////////////////////////////////

            TerrainTile terrainTile = TerrainTile.FromBitmap(new Bitmap(@"ps-e.lg.png"));

            _tile = new TriangleMeshTerrainTile(_window.Context, terrainTile);
            _tile.HeightExaggeration = 30.0f;

            ///////////////////////////////////////////////////////////////////

            double tileRadius = Math.Max(terrainTile.Resolution.X, terrainTile.Resolution.Y) * 0.5;

            _camera             = new CameraLookAtPoint(_sceneState.Camera, _window, Ellipsoid.UnitSphere);
            _camera.CenterPoint = new Vector3D(terrainTile.Resolution.X * 0.5, terrainTile.Resolution.Y * 0.5, 0.0);
            _sceneState.Camera.ZoomToTarget(tileRadius);
            _sceneState.Camera.Eye = new Vector3D(_xPos, 256, 0);

            //
            // Positions
            //
            IList <Vector3D> positions = new List <Vector3D>();
            double           temp      = 1.2 * _tile.HeightExaggeration;

            positions.Add(new Vector3D(0.0, 0.0, -temp));
            positions.Add(new Vector3D(0.0, 0.0, temp));
            positions.Add(new Vector3D(100.0, 100.0, -temp));
            positions.Add(new Vector3D(100.0, 100.0, temp));
            positions.Add(new Vector3D(200.0, 100.0, -temp));
            positions.Add(new Vector3D(200.0, 100.0, temp));
            positions.Add(new Vector3D(256.0, 256.0, -temp));
            positions.Add(new Vector3D(256.0, 256.0, temp));
            positions.Add(new Vector3D(512.0, 512.0, -temp));
            positions.Add(new Vector3D(512.0, 512.0, temp));

            //
            // junk
            _polylineOnTerrain = new PolylineOnTerrain();
            _polylineOnTerrain.Set(_window.Context, positions);


            _clearState = new ClearState();

            // junk
            string fs =
                @"#version 330

                uniform sampler2D og_texture0;
                in vec2 fsTextureCoordinates;
                out vec4 fragmentColor;

                void main()
                {
                    if (texture(og_texture0, fsTextureCoordinates).r == 0.0)
                    {
                        fragmentColor = vec4(0.0, 0.0, 0.0, 1.0);
                    }
                    else
                    {
                        discard;
                    }
                }";

            _viewportQuad = new ViewportQuad(_window.Context, fs);
        }