Ejemplo n.º 1
0
        public ParticipatingMediaSystem(GraphicsDevice device, ContentManager content, ShadowMapEffect shadowMapEffect, ParticipatingMediaEffect mediaEffect, ParticipatingMediaPostProcessEffect postProcessEffect, PostProcessTriangle postProcessTriangle, FrameService frameService)
        {
            this.Device = device;
            this.Albedo = new Texture2D(device, 1, 1);
            this.Albedo.SetData(new Color[] { Color.White });
            this.MediaEffect         = mediaEffect;
            this.ShadowMapEffect     = shadowMapEffect;
            this.PostProcessEffect   = postProcessEffect;
            this.PostProcessTriangle = postProcessTriangle;
            this.FrameService        = frameService;

            this.Noise         = content.Load <Texture2D>("Textures/BlueNoise");
            this.DitherPattern = content.Load <Texture2D>("Textures/DitherPattern");

            this.FrontRasterizerState = new RasterizerState
            {
                CullMode        = CullMode.CullCounterClockwiseFace,
                DepthClipEnable = false
            };

            this.BackRasterizerState = new RasterizerState
            {
                CullMode        = CullMode.CullClockwiseFace,
                DepthClipEnable = false
            };
        }
Ejemplo n.º 2
0
        public ShadowMap(GraphicsDevice graphicsDevice, Settings settings,
            SpriteBatch spriteBatch, Effect shadowMapEffect, Effect blurEffect)
        {
            if (graphicsDevice == null) throw new ArgumentNullException("graphicsDevice");
            if (settings == null) throw new ArgumentNullException("settings");
            if (spriteBatch == null) throw new ArgumentNullException("spriteBatch");
            if (shadowMapEffect == null) throw new ArgumentNullException("shadowMapEffect");
            if (blurEffect == null) throw new ArgumentNullException("blurEffect");

            GraphicsDevice = graphicsDevice;
            this.settings = settings;
            this.spriteBatch = spriteBatch;
            this.shadowMapEffect = new ShadowMapEffect(shadowMapEffect);
            this.shadowMapEffect.ShadowMapTechnique = settings.Technique;

            Technique = settings.Technique;
            Size = settings.Size;
            DepthBias = settings.DepthBias;
            SplitCount = settings.SplitCount;
            inverseSplitCount = 1 / (float) SplitCount;

            splitDistances = new float[SplitCount + 1];
            safeSplitDistances = new float[SplitCount + 1];
            safeSplitLightViewProjections = new Matrix[SplitCount];
            safeSplitShadowMaps = new Texture2D[SplitCount];

            splitCameras = new BasicCamera[SplitCount];
            for (int i = 0; i < splitCameras.Length; i++)
                splitCameras[i] = new BasicCamera("PssmLight" + i);

            splitLightCameras = new LightCamera[SplitCount];
            for (int i = 0; i < splitLightCameras.Length; i++)
                splitLightCameras[i] = new LightCamera(settings.Size);

            // TODO: パラメータ見直し or 外部設定化。
            var pp = GraphicsDevice.PresentationParameters;
            // メモ: ブラーをかける場合があるので RenderTargetUsage.PreserveContents で作成。
            splitRenderTargets = new RenderTarget2D[SplitCount];
            for (int i = 0; i < splitRenderTargets.Length; i++)
            {
                splitRenderTargets[i] = new RenderTarget2D(GraphicsDevice, settings.Size, settings.Size,
                    false, settings.Format, DepthFormat.Depth24, 0, RenderTargetUsage.PreserveContents);
                splitRenderTargets[i].Name = "ShadowMap" + i;
            }

            // TODO: 初期容量。
            splitShadowCasters = new Queue<ShadowCaster>[SplitCount];
            for (int i = 0; i < splitShadowCasters.Length; i++)
                splitShadowCasters[i] = new Queue<ShadowCaster>();

            if (settings.Technique == Techniques.Vsm)
            {
                blur = new GaussianBlur(blurEffect, spriteBatch, settings.Size, settings.Size, SurfaceFormat.Vector2,
                    settings.VsmBlur.Radius, settings.VsmBlur.Amount);
            }

            Monitor = new ShadowMapMonitor(SplitCount);
        }
        public CascadedShadowMapper(GraphicsDevice graphicsDevice,
                                    ShadowSettings settings,
                                    ContentManager contentManager)
        {
            _graphicsDevice = graphicsDevice;
            _settings       = settings;

            _cascadeSplits  = new float[4];
            _frustumCorners = new Vector3[8];

            _shadowMapEffect = new ShadowMapEffect(contentManager.Load <Effect>("CascadeShadowMap"));

            _boundingFrustum = new BoundingFrustum(Matrix.Identity);

            CreateShadowMaps();
        }
Ejemplo n.º 4
0
        public GeometryRenderService(
            IComponentContainer <InstancingComponent> instances,
            IComponentContainer <GeometryComponent> geometry,
            IComponentContainer <TransformComponent> transforms,
            GeometryEffect effect,
            ShadowMapEffect shadowMapEffect,
            GraphicsDevice device)
        {
            this.Instances       = instances;
            this.Geometry        = geometry;
            this.Transforms      = transforms;
            this.GBufferEffect   = effect;
            this.ShadowMapEffect = shadowMapEffect;
            this.Device          = device;

            this.InstanceBuffer = new VertexBuffer(device, InstancingVertex.Declaration, MaxInstances, BufferUsage.WriteOnly);
        }
Ejemplo n.º 5
0
        public MeshRenderer(
            GraphicsDevice graphicsDevice, GameSettingsComponent settings,
            ContentManager contentManager, Model scene)
        {
            _graphicsDevice = graphicsDevice;
            _settings       = settings;

            _scene           = scene;
            _sceneTransforms = new Matrix[_scene.Bones.Count];
            _scene.CopyAbsoluteBoneTransformsTo(_sceneTransforms);

            _cascadeSplits  = new float[4];
            _frustumCorners = new Vector3[8];

            _shadowMapEffect = new ShadowMapEffect(graphicsDevice, contentManager.Load <Effect>("effects/ShadowMap"));
            _meshEffect      = new MeshEffect(graphicsDevice, contentManager.Load <Effect>("effects/Mesh"));

            _boundingFrustum = new BoundingFrustum(Matrix.Identity);

            CreateShadowMaps();
        }
Ejemplo n.º 6
0
        public ShadowMap(GraphicsDevice graphicsDevice, Settings settings,
                         SpriteBatch spriteBatch, Effect shadowMapEffect, Effect blurEffect)
        {
            if (graphicsDevice == null)
            {
                throw new ArgumentNullException("graphicsDevice");
            }
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }
            if (spriteBatch == null)
            {
                throw new ArgumentNullException("spriteBatch");
            }
            if (shadowMapEffect == null)
            {
                throw new ArgumentNullException("shadowMapEffect");
            }
            if (blurEffect == null)
            {
                throw new ArgumentNullException("blurEffect");
            }

            GraphicsDevice       = graphicsDevice;
            this.settings        = settings;
            this.spriteBatch     = spriteBatch;
            this.shadowMapEffect = new ShadowMapEffect(shadowMapEffect);
            this.shadowMapEffect.ShadowMapTechnique = settings.Technique;

            Technique         = settings.Technique;
            Size              = settings.Size;
            DepthBias         = settings.DepthBias;
            SplitCount        = settings.SplitCount;
            inverseSplitCount = 1 / (float)SplitCount;

            splitDistances                = new float[SplitCount + 1];
            safeSplitDistances            = new float[SplitCount + 1];
            safeSplitLightViewProjections = new Matrix[SplitCount];
            safeSplitShadowMaps           = new Texture2D[SplitCount];

            splitCameras = new BasicCamera[SplitCount];
            for (int i = 0; i < splitCameras.Length; i++)
            {
                splitCameras[i] = new BasicCamera("PssmLight" + i);
            }

            splitLightCameras = new LightCamera[SplitCount];
            for (int i = 0; i < splitLightCameras.Length; i++)
            {
                splitLightCameras[i] = new LightCamera(settings.Size);
            }

            // TODO: パラメータ見直し or 外部設定化。
            var pp = GraphicsDevice.PresentationParameters;

            // メモ: ブラーをかける場合があるので RenderTargetUsage.PreserveContents で作成。
            splitRenderTargets = new RenderTarget2D[SplitCount];
            for (int i = 0; i < splitRenderTargets.Length; i++)
            {
                splitRenderTargets[i] = new RenderTarget2D(GraphicsDevice, settings.Size, settings.Size,
                                                           false, settings.Format, DepthFormat.Depth24, 0, RenderTargetUsage.PreserveContents);
                splitRenderTargets[i].Name = "ShadowMap" + i;
            }

            // TODO: 初期容量。
            splitShadowCasters = new Queue <ShadowCaster> [SplitCount];
            for (int i = 0; i < splitShadowCasters.Length; i++)
            {
                splitShadowCasters[i] = new Queue <ShadowCaster>();
            }

            if (settings.Technique == Techniques.Vsm)
            {
                blur = new GaussianBlur(blurEffect, spriteBatch, settings.Size, settings.Size, SurfaceFormat.Vector2,
                                        settings.VsmBlur.Radius, settings.VsmBlur.Amount);
            }

            Monitor = new ShadowMapMonitor(SplitCount);
        }