Пример #1
0
        public override bool Init()
        {
            if (!base.Init())
            {
                return(false);
            }

            Effects.InitAll(Device);
            InputLayouts.InitAll(Device);
            RenderStates.InitAll(Device);
            Patch.InitPatchData(Terrain.CellsPerPatch, Device);

            _sky = new Sky(Device, "Textures/grasscube1024.dds", 5000.0f);

            var tii = new InitInfo {
                HeightMapFilename = null,
                LayerMapFilename0 = "textures/grass.dds",
                LayerMapFilename1 = "textures/darkdirt.dds",
                LayerMapFilename2 = "textures/stone.dds",
                LayerMapFilename3 = "Textures/lightdirt.dds",
                LayerMapFilename4 = "textures/snow.dds",
                BlendMapFilename  = null,
                HeightScale       = 50.0f,
                HeightMapWidth    = 2049,
                HeightMapHeight   = 2049,
                CellSpacing       = 0.5f,

                Seed         = 0,
                NoiseSize1   = 3.0f,
                Persistence1 = 0.7f,
                Octaves1     = 7,
                NoiseSize2   = 2.5f,
                Persistence2 = 0.8f,
                Octaves2     = 3,
            };

            _terrain = new Terrain();
            _terrain.Init(Device, ImmediateContext, tii);

            _camera.Height = _terrain.Height;

            AddUIElements();

            _camera.SetLens(0.25f * MathF.PI, AspectRatio, 1.0f, 1000.0f);
            _ssao = new Ssao(Device, ImmediateContext, ClientWidth, ClientHeight, _camera.FovY, _camera.FarZ);

            _whiteTex = ShaderResourceView.FromFile(Device, "Textures/white.dds");


            _sMap = new ShadowMap(Device, SMapSize, SMapSize);

            _sceneBounds = new BoundingSphere(new Vector3(), MathF.Sqrt(_terrain.Width * _terrain.Width + _terrain.Depth * _terrain.Depth) / 2);

            _minimap = new Minimap(Device, ImmediateContext, MinimapSize, MinimapSize, _terrain, _camera);

            return(true);
        }
Пример #2
0
        public void ComputeSsao(DeviceContext dc, CameraBase cam, Ssao ssao, DepthStencilView depthStencilView)
        {
            ssao.SetNormalDepthRenderTarget(depthStencilView);

            Effects.SsaoFX.SetOcclusionRadius(0.1f);
            Effects.SsaoFX.SetOcclusionFadeEnd(0.75f);

            dc.InputAssembler.PrimitiveTopology = PrimitiveTopology.PatchListWith4ControlPoints;
            dc.InputAssembler.InputLayout       = InputLayouts.TerrainCP;

            var       stride = TerrainCP.Stride;
            const int offset = 0;

            dc.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_quadPatchVB, stride, offset));
            dc.InputAssembler.SetIndexBuffer(_quadPatchIB, Format.R16_UInt, 0);

            var viewProj = cam.ViewProj;
            var planes   = cam.FrustumPlanes;


            Effects.TerrainFX.SetViewProj(viewProj);
            Effects.TerrainFX.SetEyePosW(cam.Position);
            Effects.TerrainFX.SetMinDist(MinDist);
            Effects.TerrainFX.SetMaxDist(MaxDist);
            Effects.TerrainFX.SetMinTess(MinTess);
            Effects.TerrainFX.SetMaxTess(MaxTess);
            Effects.TerrainFX.SetTexelCellSpaceU(1.0f / _terrain.Info.HeightMapWidth);
            Effects.TerrainFX.SetTexelCellSpaceV(1.0f / _terrain.Info.HeightMapHeight);
            Effects.TerrainFX.SetWorldCellSpace(_terrain.Info.CellSpacing);
            Effects.TerrainFX.SetWorldFrustumPlanes(planes);
            Effects.TerrainFX.SetHeightMap(_heightMapSRV);
            Effects.TerrainFX.SetView(cam.View);

            var tech = Effects.TerrainFX.NormalDepthTech;

            for (var p = 0; p < tech.Description.PassCount; p++)
            {
                var pass = tech.GetPassByIndex(p);
                pass.Apply(dc);
                dc.DrawIndexed(_numPatchQuadFaces * 4, 0, 0);
            }
            dc.HullShader.Set(null);
            dc.DomainShader.Set(null);

            ssao.ComputeSsao(cam);
            ssao.BlurAmbientMap(4);
            Effects.SsaoFX.SetOcclusionRadius(0.5f);
        }
Пример #3
0
        public override bool Init()
        {
            if (!base.Init())
            {
                return(false);
            }
            Effects.InitAll(Device);
            InputLayouts.InitAll(Device);
            RenderStates.InitAll(Device);

            _sky = new Sky(Device, "Textures/desertcube1024.dds", 5000.0f);

            _ssao = new Ssao(Device, ImmediateContext, ClientWidth, ClientHeight, _camera.FovY, _camera.FarZ);

            BuildShapeGeometryBuffers();
            BuildSkullGeometryBuffers();
            BuildScreenQuadGeometryBuffers();

            return(true);
        }
Пример #4
0
        public void Initialize()
        {
            //----------------------------------------------------------------
            // グラフィックス設定

            GraphicsSettings = LoadAsset <GraphicsSettings>("title:Resources/GraphicsSettings.json");

            //----------------------------------------------------------------
            // シーン設定

            // TODO: ワールド設定としてどうするか再検討。
            // いずれにせよ、SceneSettings はワールド設定と一対一。

            SceneSettings = LoadAsset <SceneSettings>("title:Resources/SceneSettings.json");

            //----------------------------------------------------------------
            // シーン マネージャ設定

            // TODO: リソースから取得する。
            SceneManagerSettings = new SceneManager.Settings();

            //----------------------------------------------------------------
            // シーン マネージャ

            SceneManager = new SceneManager(SceneManagerSettings, GraphicsDevice);

            // 太陽と月をディレクショナル ライトとして登録。
            SceneManager.DirectionalLights.Add(SceneSettings.Sunlight);
            SceneManager.DirectionalLights.Add(SceneSettings.Moonlight);

            // シャドウ マップ
            if (GraphicsSettings.ShadowMapEnabled)
            {
                var shadowMapEffect = LoadAsset <Effect>("content:Effects/ShadowMap");
                var blurEffect      = LoadAsset <Effect>("content:Effects/GaussianBlur");

                ShadowMap = new ShadowMap(GraphicsDevice, GraphicsSettings.ShadowMap, spriteBatch, shadowMapEffect, blurEffect);

                SceneManager.ShadowMap = ShadowMap;
            }

            // レンズ フレア
            if (GraphicsSettings.LensFlareEnabled)
            {
                var         glowSpite    = LoadAsset <Texture2D>("content:Textures/LensFlare/Glow");
                Texture2D[] flareSprites =
                {
                    LoadAsset <Texture2D>("content:Textures/LensFlare/Flare1"),
                    LoadAsset <Texture2D>("content:Textures/LensFlare/Flare2"),
                    LoadAsset <Texture2D>("content:Textures/LensFlare/Flare3")
                };

                LensFlare = new LensFlare(GraphicsDevice, spriteBatch, glowSpite, flareSprites);

                SceneManager.LensFlare = LensFlare;
            }

            // スクリーン スペース シャドウ マッピング
            if (GraphicsSettings.SssmEnabled)
            {
                // スクリーン スペース シャドウ マッピング モジュール
                var shadowSceneEffect = LoadAsset <Effect>("content:Effects/ShadowScene");
                var sssmEffect        = LoadAsset <Effect>("content:Effects/Sssm");
                var blurEffect        = LoadAsset <Effect>("content:Effects/GaussianBlur");

                Sssm             = new Sssm(spriteBatch, GraphicsSettings.ShadowMap, GraphicsSettings.Sssm, shadowSceneEffect, sssmEffect, blurEffect);
                Sssm.ShadowColor = SceneSettings.ShadowColor;

                SceneManager.PostProcessors.Add(Sssm);

                // SSSM は直接的なシャドウ描画を回避しなければならないため明示。
                SceneManager.SssmEnabled = true;
            }

            // スクリーン スペース アンビエント オクルージョン
            if (GraphicsSettings.SsaoEnabled)
            {
                var normalDepthMapEffect = LoadAsset <Effect>("content:Effects/NormalDepthMap");
                var ssaoMapEffect        = LoadAsset <Effect>("content:Effects/SsaoMap");
                var blurEffect           = LoadAsset <Effect>("content:Effects/SsaoMapBlur");
                var ssaoEffect           = LoadAsset <Effect>("content:Effects/Ssao");
                var randomNormalMap      = LoadAsset <Texture2D>("content:Textures/RandomNormal");

                Ssao = new Ssao(spriteBatch, GraphicsSettings.Ssao,
                                normalDepthMapEffect, ssaoMapEffect, blurEffect, ssaoEffect, randomNormalMap);

                SceneManager.PostProcessors.Add(Ssao);
            }

            // エッジ強調
            if (GraphicsSettings.EdgeEnabled)
            {
                var normalDepthMapEffect = LoadAsset <Effect>("content:Effects/NormalDepthMap");
                var edgeEffect           = LoadAsset <Effect>("content:Effects/Edge");

                Edge = new Edge(spriteBatch, GraphicsSettings.Edge, normalDepthMapEffect, edgeEffect);

                SceneManager.PostProcessors.Add(Edge);
            }

            // ブルーム
            if (GraphicsSettings.BloomEnabled)
            {
                var bloomExtractEffect = LoadAsset <Effect>("content:Effects/BloomExtract");
                var bloomEffect        = LoadAsset <Effect>("content:Effects/Bloom");
                var blurEffect         = LoadAsset <Effect>("content:Effects/GaussianBlur");

                Bloom = new Bloom(spriteBatch, GraphicsSettings.Bloom, bloomExtractEffect, bloomEffect, blurEffect);

                SceneManager.PostProcessors.Add(Bloom);
            }

            // 被写界深度
            if (GraphicsSettings.DofEnabled)
            {
                var depthMapEffect = LoadAsset <Effect>("content:Effects/DepthMap");
                var dofEffect      = LoadAsset <Effect>("content:Effects/Dof");
                var blurEffect     = LoadAsset <Effect>("content:Effects/GaussianBlur");

                Dof = new Dof(spriteBatch, GraphicsSettings.Dof, depthMapEffect, dofEffect, blurEffect);

                SceneManager.PostProcessors.Add(Dof);
            }

            // カラー オーバラップ
            if (GraphicsSettings.ColorOverlapEnabled)
            {
                ColorOverlap = new ColorOverlap(spriteBatch);

                SceneManager.PostProcessors.Add(ColorOverlap);
            }

            // モノクローム
            if (GraphicsSettings.MonochromeEnabled)
            {
                var monochromeEffect = LoadAsset <Effect>("content:Effects/Monochrome");

                Monochrome = new Monochrome(spriteBatch, monochromeEffect);

                SceneManager.PostProcessors.Add(Monochrome);
            }

            // 走査線
            if (GraphicsSettings.ScanlineEnabled)
            {
                var effect = LoadAsset <Effect>("content:Effects/Scanline");

                Scanline = new Scanline(spriteBatch, effect);

                SceneManager.PostProcessors.Add(Scanline);
            }

            //----------------------------------------------------------------
            // リージョン マネージャ

            RegionManager = new RegionManager(serviceProvider, SceneManager);
            RegionManager.Initialize(SceneSettings);

            // イベント ハンドラ
            // シャドウ マップ更新にあわせて、リージョン マネージャで管理しているエフェクトを準備する。
            SceneManager.ShadowMapUpdated += RegionManager.OnShadowMapUpdated;

            //----------------------------------------------------------------
            // チャンク マネージャ

            var chunkSettings = LoadAsset <ChunkSettings>("title:Resources/ChunkSettings.json");

            ChunkManager = new ChunkManager(chunkSettings, GraphicsDevice, RegionManager, SceneManager);

            //----------------------------------------------------------------
            // デフォルト カメラ

            //camera.View.Position = new Vector3(0, 16 * 18, 0);
            defaultCamera.View.Position = new Vector3(0, 16 * 16, 0);
            //camera.View.Position = new Vector3(0, 16 * 3, 0);
            //camera.View.Position = new Vector3(0, 16 * 2, 0);
            //defaultCamera.Projection.Fov = MathHelper.ToRadians(90);
            defaultCamera.Projection.AspectRatio = GraphicsDevice.Viewport.AspectRatio;

            // 最大アクティブ範囲を超えない位置へ FarPlaneDistance を設定。
            // パーティション (チャンク) のサイズを掛けておく。

            var minChunkSize = Math.Min(chunkSettings.ChunkSize.X, chunkSettings.ChunkSize.Y);

            minChunkSize = Math.Min(minChunkSize, chunkSettings.ChunkSize.Z);
            defaultCamera.Projection.FarPlaneDistance = (chunkSettings.MaxActiveVolume - 1) * minChunkSize;

            // 念のためここで一度更新。
            defaultCamera.Update();

            // シーン マネージャへ登録してアクティブ化。
            SceneManager.Cameras.Add(defaultCamera);
            SceneManager.ActiveCameraName = defaultCamera.Name;
        }
Пример #5
0
        public void ComputeSsao(DeviceContext dc, CameraBase cam, Ssao ssao, DepthStencilView depthStencilView)
        {
            ssao.SetNormalDepthRenderTarget(depthStencilView);

            dc.InputAssembler.PrimitiveTopology = PrimitiveTopology.PatchListWith4ControlPoints;
            dc.InputAssembler.InputLayout = InputLayouts.TerrainCP;

            var stride = TerrainCP.Stride;
            const int offset = 0;

            dc.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_quadPatchVB, stride, offset));
            dc.InputAssembler.SetIndexBuffer(_quadPatchIB, Format.R16_UInt, 0);

            var viewProj = cam.ViewProj;
            var planes = cam.FrustumPlanes;

            Effects.TerrainFX.SetViewProj(viewProj);
            Effects.TerrainFX.SetEyePosW(cam.Position);
            Effects.TerrainFX.SetMinDist(MinDist);
            Effects.TerrainFX.SetMaxDist(MaxDist);
            Effects.TerrainFX.SetMinTess(MinTess);
            Effects.TerrainFX.SetMaxTess(MaxTess);
            Effects.TerrainFX.SetTexelCellSpaceU(1.0f / Info.HeightMapWidth);
            Effects.TerrainFX.SetTexelCellSpaceV(1.0f / Info.HeightMapHeight);
            Effects.TerrainFX.SetWorldCellSpace(Info.CellSpacing);
            Effects.TerrainFX.SetWorldFrustumPlanes(planes);
            Effects.TerrainFX.SetHeightMap(_heightMapSRV);
            Effects.TerrainFX.SetView(cam.View);

            var tech = Effects.TerrainFX.NormalDepthTech;
            for (int p = 0; p < tech.Description.PassCount; p++) {
                var pass = tech.GetPassByIndex(p);
                pass.Apply(dc);
                dc.DrawIndexed(_numPatchQuadFaces * 4, 0, 0);
            }
            dc.HullShader.Set(null);
            dc.DomainShader.Set(null);

            ssao.ComputeSsao(cam);
            ssao.BlurAmbientMap(4);
        }
Пример #6
0
        public override bool Init()
        {
            if (!base.Init())
            {
                return(false);
            }

            Effects.InitAll(Device);
            InputLayouts.InitAll(Device);
            RenderStates.InitAll(Device);
            Patch.InitPatchData(Terrain.CellsPerPatch, Device);

            _sky = new Sky(Device, "Textures/grasscube1024.dds", 5000.0f);

            var tii = new InitInfo {
                HeightMapFilename = null,
                LayerMapFilename0 = "textures/grass.dds",
                LayerMapFilename1 = "textures/darkdirt.dds",
                LayerMapFilename2 = "textures/stone.dds",
                LayerMapFilename3 = "Textures/lightdirt.dds",
                LayerMapFilename4 = "textures/snow.dds",
                BlendMapFilename  = null,
                HeightScale       = 50.0f,
                HeightMapWidth    = 2049,
                HeightMapHeight   = 2049,
                CellSpacing       = 0.5f,

                Seed         = 0,
                NoiseSize1   = 3.0f,
                Persistence1 = 0.7f,
                Octaves1     = 7,
                NoiseSize2   = 2.5f,
                Persistence2 = 0.8f,
                Octaves2     = 3,
            };

            _terrain = new Terrain();
            //_terrain.DebugQuadTree = true;
            _terrain.Init(Device, ImmediateContext, tii);

            _camera.Height = _terrain.Height;


            _camera.SetLens(0.25f * MathF.PI, AspectRatio, 1.0f, 1000.0f);
            _ssao = new Ssao(Device, ImmediateContext, ClientWidth, ClientHeight, _camera.FovY, _camera.FarZ);

            _whiteTex = ShaderResourceView.FromFile(Device, "Textures/white.dds");

            _sMap = new ShadowMap(Device, SMapSize, SMapSize);

            _sceneBounds = new BoundingSphere(new Vector3(), MathF.Sqrt(_terrain.Width * _terrain.Width + _terrain.Depth * _terrain.Depth) / 2);

            _minimap = new Minimap(Device, ImmediateContext, MinimapSize, MinimapSize, _terrain, _camera);

            _sphereModel = new BasicModel();
            _sphereModel.CreateSphere(Device, 0.25f, 10, 10);
            _sphereModel.Materials[0] = new Material {
                Ambient  = Color.Red,
                Diffuse  = Color.Red,
                Specular = new Color4(32, 1.0f, 1.0f, 1.0f)
            };
            _sphereModel.DiffuseMapSRV[0] = _whiteTex;

            _sphere    = new BasicModelInstance(_sphereModel);
            _spherePos = new Vector3(float.MaxValue);
            _path      = null;
            return(true);
        }