Ejemplo n.º 1
0
        public void BlurTextureToTarget(Texture2D texture, LightMapSize mapSize, BlurTechnique blurTechnique, float bluriness)
        {
            // Get the pass to use
            string passName = "";

            switch (blurTechnique) {
                case (BlurTechnique.Horizontal):
                    effect.Parameters["BlurFactorU"].SetValue(1f / GraphicsDevice.PresentationParameters.BackBufferWidth);
                    passName = "HorizontalBlur";
                    break;

                case (BlurTechnique.Vertical):
                    effect.Parameters["BlurFactorV"].SetValue(1f / graphicsDevice.PresentationParameters.BackBufferHeight);
                    passName = "VerticalBlur";
                    break;
            }

            float biasFactor = BiasFactorFromLightMapSize(mapSize);

            // Calculate the texel bias
            var texelBias = new Vector2 {
                X = biasFactor / graphicsDevice.Viewport.Width,
                Y = biasFactor / graphicsDevice.Viewport.Height,
            };

            effect.Parameters["Texture0"].SetValue(texture);
            effect.Parameters["TexelBias"].SetValue(texelBias);
            effect.Parameters["Bluriness"].SetValue(bluriness);
            effect.CurrentTechnique = effect.Techniques["Blur"];

            effect.CurrentTechnique.Passes[passName].Apply();
            graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, Unit.Quad, 0, 2);
        }
Ejemplo n.º 2
0
        public LightingComponent(LightingMode lightingMode = LightingMode.Knockout, LightMapSize mLightMapSize = LightMapSize.Full, int mBluriness = 0)
        {
            mLight = new KryptonEngine(MilkShake.Game, "KryptonEffect");
            mLight.Initialize();

            // [Settings]
            mLight.LightMapSize = mLightMapSize;
            mLight.Bluriness = mBluriness;
            mLightingMode = lightingMode;

            mRenderTarget = new RenderTarget2D(MilkShake.Graphics, Globals.ScreenWidth, Globals.ScreenHeight);
        }
Ejemplo n.º 3
0
        public void BlurTextureToTarget(Texture2D texture, LightMapSize mapSize, BlurTechnique blurTechnique,
                                        float bluriness)
        {
            // Get the pass to use
            var passName = "";

            switch (blurTechnique)
            {
            case BlurTechnique.Horizontal:
                Effect.Parameters["BlurFactorU"]
                .SetValue(1f / GraphicsDevice.PresentationParameters.BackBufferWidth);

                passName = "HorizontalBlur";

                break;

            case BlurTechnique.Vertical:
                Effect.Parameters["BlurFactorV"]
                .SetValue(1f / GraphicsDevice.PresentationParameters.BackBufferHeight);

                passName = "VerticalBlur";

                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(blurTechnique), blurTechnique, null);
            }

            var biasFactor = BiasFactorFromLightMapSize(mapSize);

            var texelBias = new Vector2
            {
                X = biasFactor / GraphicsDevice.Viewport.Width,
                Y = biasFactor / GraphicsDevice.Viewport.Height,
            };


            Effect.Parameters["Texture0"].SetValue(texture);
            Effect.Parameters["TexelBias"].SetValue(texelBias);
            Effect.Parameters["Bluriness"].SetValue(bluriness);
            Effect.CurrentTechnique = Effect.Techniques["Blur"];

            Effect.CurrentTechnique.Passes[passName].Apply();

            GraphicsDevice.DrawUserPrimitives(
                primitiveType: PrimitiveType.TriangleStrip,
                vertexData: UnitQuad,
                vertexOffset: 0,
                primitiveCount: 2);
        }
Ejemplo n.º 4
0
        public LightingComponent(Scene mScene, LightMapSize mLightMapSize = LightMapSize.Full, int mBluriness = 0)
            : base(mScene)
        {
            mLight = new KryptonEngine(MilkShake.Game, "KryptonEffect");
            mLight.Initialize();

            // [Settings]
            mLight.LightMapSize = mLightMapSize;
            mLight.Bluriness = mBluriness;

            // [Events]
            Scene.Listener.PreDraw[DrawLayer.First] += new DrawEvent(PreDraw);
            Scene.Listener.PostDraw[DrawLayer.Fourth] += new DrawEvent(PostDraw);
        }
Ejemplo n.º 5
0
        private static float BiasFactorFromLightMapSize(LightMapSize mapSize)
        {
            switch (mapSize)
            {
            case (LightMapSize.Full):
                return(0.5f);

            case (LightMapSize.Fourth):
                return(0.6f);

            case (LightMapSize.Eighth):
                return(0.7f);

            default:
                return(0.0f);
            }
        }
Ejemplo n.º 6
0
        public void DrawTextureToTarget(
            Texture2D texture,
            LightMapSize mapSize,
            BlendTechnique blend)
        {
            var techniqueName = "";

            switch (blend)
            {
            case BlendTechnique.Add:
                techniqueName = "TextureToTarget_Add";
                break;

            case BlendTechnique.Multiply:
                techniqueName = "TextureToTarget_Multiply";
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(blend), blend, null);
            }

            var biasFactor = BiasFactorFromLightMapSize(mapSize);

            var texelBias = new Vector2
            {
                X = biasFactor / GraphicsDevice.ScissorRectangle.Width,
                Y = biasFactor / GraphicsDevice.ScissorRectangle.Height,
            };

            Effect.Parameters["Texture0"].SetValue(texture);
            Effect.Parameters["TexelBias"].SetValue(texelBias);
            Effect.CurrentTechnique = Effect.Techniques[techniqueName];

            foreach (var effectPass in Effect.CurrentTechnique.Passes)
            {
                effectPass.Apply();
                GraphicsDevice.DrawUserPrimitives(
                    primitiveType: PrimitiveType.TriangleStrip,
                    vertexData: UnitQuad,
                    vertexOffset: 0,
                    primitiveCount: 2);
            }
        }
Ejemplo n.º 7
0
        public void DrawTextureToTarget(Texture2D texture, LightMapSize mapSize, BlendTechnique blend)
        {
            // Get the technique to use
            string techniqueName = "";

            switch (blend)
            {
            case (BlendTechnique.Add):
                techniqueName = "TextureToTarget_Add";
                break;

            case (BlendTechnique.Multiply):
                techniqueName = "TextureToTarget_Multiply";
                break;
            }

            var biasFactor = KryptonRenderHelper.BiasFactorFromLightMapSize(mapSize);

            // Calculate the texel bias
            Vector2 texelBias = new Vector2()
            {
                X = biasFactor / this.mGraphicsDevice.ScissorRectangle.Width,
                Y = biasFactor / this.mGraphicsDevice.ScissorRectangle.Height,
            };

            this.mEffect.Parameters["Texture0"].SetValue(texture);
            this.mEffect.Parameters["TexelBias"].SetValue(texelBias);
            this.mEffect.CurrentTechnique = this.mEffect.Techniques[techniqueName];

            // Draw the quad
            foreach (var effectPass in this.mEffect.CurrentTechnique.Passes)
            {
                effectPass.Apply();
                this.mGraphicsDevice.DrawUserPrimitives <VertexPositionTexture>(PrimitiveType.TriangleStrip, KryptonRenderHelper.UnitQuad, 0, 2);
            }
        }
Ejemplo n.º 8
0
        public void BlurTextureToTarget(Texture2D texture, LightMapSize mapSize, BlurTechnique blurTechnique, float bluriness)
        {
            // Get the pass to use
            string passName = "";

            switch (blurTechnique)
            {
            case (BlurTechnique.Horizontal):
                this.mEffect.Parameters["BlurFactorU"].SetValue(1f / this.GraphicsDevice.PresentationParameters.BackBufferWidth);
                passName = "HorizontalBlur";
                break;

            case (BlurTechnique.Vertical):
                this.mEffect.Parameters["BlurFactorV"].SetValue(1f / this.mGraphicsDevice.PresentationParameters.BackBufferHeight);
                passName = "VerticalBlur";
                break;
            }

            var biasFactor = KryptonRenderHelper.BiasFactorFromLightMapSize(mapSize);

            // Calculate the texel bias
            Vector2 texelBias = new Vector2()
            {
                X = biasFactor / this.mGraphicsDevice.Viewport.Width,
                Y = biasFactor / this.mGraphicsDevice.Viewport.Height,
            };


            this.mEffect.Parameters["Texture0"].SetValue(texture);
            this.mEffect.Parameters["TexelBias"].SetValue(texelBias);
            this.mEffect.Parameters["Bluriness"].SetValue(bluriness);
            this.mEffect.CurrentTechnique = this.mEffect.Techniques["Blur"];

            mEffect.CurrentTechnique.Passes[passName].Apply();
            this.mGraphicsDevice.DrawUserPrimitives <VertexPositionTexture>(PrimitiveType.TriangleStrip, KryptonRenderHelper.UnitQuad, 0, 2);
        }
        private static float BiasFactorFromLightMapSize(LightMapSize mapSize)
        {
            switch (mapSize)
            {
                case (LightMapSize.Full):
                    return 0.5f;

                case (LightMapSize.Fourth):
                    return 0.6f;

                case (LightMapSize.Eighth):
                    return 0.7f;

                default:
                    return 0.0f;
            }
        }
        public void DrawTextureToTarget(Texture2D texture, LightMapSize mapSize, BlendTechnique blend)
        {
            // Get the technique to use
            string techniqueName = "";

            switch (blend)
            {
                case(BlendTechnique.Add):
                    techniqueName = "TextureToTarget_Add";
                    break;

                case(BlendTechnique.Multiply):
                    techniqueName = "TextureToTarget_Multiply";
                    break;
            }

            var biasFactor = KryptonRenderHelper.BiasFactorFromLightMapSize(mapSize);

            // Calculate the texel bias
            Vector2 texelBias = new Vector2()
            {
                X = biasFactor / this.mGraphicsDevice.ScissorRectangle.Width,
                Y = biasFactor / this.mGraphicsDevice.ScissorRectangle.Height,
            };

            this.mEffect.Parameters["Texture0"].SetValue(texture);
            this.mEffect.Parameters["TexelBias"].SetValue(texelBias);
            this.mEffect.CurrentTechnique = this.mEffect.Techniques[techniqueName];

            // Draw the quad
            foreach (var effectPass in this.mEffect.CurrentTechnique.Passes)
            {
                effectPass.Apply();
                this.mGraphicsDevice.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleStrip, KryptonRenderHelper.UnitQuad, 0, 2);
            }
        }
        public void BlurTextureToTarget(Texture2D texture, LightMapSize mapSize, BlurTechnique blurTechnique, float bluriness)
        {
            // Get the pass to use
            string passName = "";

            switch (blurTechnique)
            {
                case (BlurTechnique.Horizontal):
                    this.mEffect.Parameters["BlurFactorU"].SetValue(1f / this.GraphicsDevice.PresentationParameters.BackBufferWidth);
                    passName = "HorizontalBlur";
                    break;

                case (BlurTechnique.Vertical):
                    this.mEffect.Parameters["BlurFactorV"].SetValue(1f / this.mGraphicsDevice.PresentationParameters.BackBufferHeight);
                    passName = "VerticalBlur";
                    break;
            }

            var biasFactor = KryptonRenderHelper.BiasFactorFromLightMapSize(mapSize);

            // Calculate the texel bias
            Vector2 texelBias = new Vector2()
            {
                X = biasFactor / this.mGraphicsDevice.Viewport.Width,
                Y = biasFactor / this.mGraphicsDevice.Viewport.Height,
            };


            this.mEffect.Parameters["Texture0"].SetValue(texture);
            this.mEffect.Parameters["TexelBias"].SetValue(texelBias);
            this.mEffect.Parameters["Bluriness"].SetValue(bluriness);
            this.mEffect.CurrentTechnique = this.mEffect.Techniques["Blur"];

            mEffect.CurrentTechnique.Passes[passName].Apply();
            this.mGraphicsDevice.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleStrip, KryptonRenderHelper.UnitQuad, 0, 2);
        }
Ejemplo n.º 12
0
        public void DrawTextureToTarget(Texture2D texture, LightMapSize mapSize)
        {
            float biasFactor = BiasFactorFromLightMapSize(mapSize);

            // Calculate the texel bias
            var texelBias = new Vector2 {
                X = biasFactor / graphicsDevice.ScissorRectangle.Width,
                Y = biasFactor / graphicsDevice.ScissorRectangle.Height,
            };

            effect.Parameters["Texture0"].SetValue(texture);
            effect.Parameters["TexelBias"].SetValue(texelBias);
            effect.CurrentTechnique = effect.Techniques["TextureToTarget_Multiply"];

            // Draw the quad
            foreach (var effectPass in effect.CurrentTechnique.Passes) {
                effectPass.Apply();
                graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, Unit.Quad, 0, 2);
            }
        }
Ejemplo n.º 13
0
 public void SetLightMapSize(LightMapSize value)
 {
     if (lightMapSize == value) return;
     lightMapSize = value;
     DisposeRenderTargets();
     CreateRenderTargets();
 }