Exemplo n.º 1
0
        public DepthBufferPrecision()
        {
            _globeShape = Ellipsoid.Wgs84;
            _nearDistance = 1;
            _cubeRootFarDistance = 300;

            _window = Device.CreateWindow(800, 600, "Chapter 6:  Depth Buffer Precision");
            _window.Resize += OnResize;
            _window.RenderFrame += OnRenderFrame;
            _window.Keyboard.KeyUp += OnKeyUp;
            _window.Keyboard.KeyDown += OnKeyDown;
            _sceneState = new SceneState();
            _sceneState.DiffuseIntensity = 0.45f;
            _sceneState.SpecularIntensity = 0.05f;
            _sceneState.AmbientIntensity = 0.5f;

            _camera = new CameraLookAtPoint(_sceneState.Camera, _window, _globeShape);

            _sceneState.Camera.ZoomToTarget(_globeShape.MaximumRadius);

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

            _globe = new TessellatedGlobe();
            _globe.Shape = _globeShape;
            _globe.NumberOfSlicePartitions = 64;
            _globe.NumberOfStackPartitions = 32;
            _globe.Texture = Device.CreateTexture2D(new Bitmap("world_topo_bathy_200411_3x5400x2700.jpg"), TextureFormat.RedGreenBlue8, false);
            _globe.Textured = true;

            _plane = new Plane(_window.Context);
            _plane.XAxis = 0.6 * _globeShape.MaximumRadius * Vector3D.UnitX;
            _plane.YAxis = 0.6 * _globeShape.MinimumRadius * Vector3D.UnitZ;
            _plane.OutlineWidth = 3;
            _cubeRootPlaneHeight = 100.0;
            UpdatePlaneOrigin();

            _viewportQuad = new ViewportQuad(_window.Context, null);

            _framebuffer = _window.Context.CreateFramebuffer();
            _depthFormatIndex = 1;
            _depthTestLess = true;
            _logarithmicDepthConstant = 1;
            UpdatePlanesAndDepthTests();

            _clearState = new ClearState();

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

            _hudFont = new Font("Arial", 16);
            _hud = new HeadsUpDisplay();
            _hud.Color = Color.Blue;
            UpdateHUD();
        }
Exemplo n.º 2
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);
        }