Esempio n. 1
0
        private void ExecuteTechniqueDistortAndComputeDistance(ShadowCasterMap shadowCasterMap, LightSource light, RenderTarget2D destination, string techniqueName, Camera gameCamera)
        {
            graphicsDevice.SetRenderTarget(destination);
            graphicsDevice.Clear(Color.White);

            this.lightsFX.ResolveShadowsEffect.Parameters["lightRelativeZero"].SetValue(light.RelativeZeroHLSL(shadowCasterMap, gameCamera));

            Vector2 shadowCasterMapPortion = (light.Size * shadowCasterMap.PrecisionRatio) / shadowCasterMap.Size;
            this.lightsFX.ResolveShadowsEffect.Parameters["shadowCasterMapPortion"].SetValue(shadowCasterMapPortion);

            this.lightsFX.ResolveShadowsEffect.Parameters["InputTexture"].SetValue(shadowCasterMap.Map);

            this.lightsFX.ResolveShadowsEffect.CurrentTechnique = this.lightsFX.ResolveShadowsEffect.Techniques[techniqueName];

            this.lightsFX.ResolveShadowsEffect.CurrentTechnique.Passes[0].Apply();
            ShadowMapResolver.QuadRender.Render(this.graphicsDevice, Vector2.One * -1, Vector2.One);

            graphicsDevice.SetRenderTarget(null);
        }
Esempio n. 2
0
        public void ResolveShadows(ShadowCasterMap shadowCasterMap, LightSource resultLight, RenderTarget2D printRT, PostEffect postEffect, float distanceMod, Camera gameCamera)
        {
            BlendState backupBlendState = graphicsDevice.BlendState;
            graphicsDevice.BlendState = BlendState.Opaque;

            this.ExecuteTechniqueDistortAndComputeDistance(shadowCasterMap, resultLight, shadowMapDistorted, "DistortAndComputeDistances", gameCamera);

            // Horizontal reduction
            this.ApplyHorizontalReduction(shadowMapDistorted, this.shadowMapDigested);

            this.distanceMod = distanceMod;

            switch (postEffect)
            {
                case PostEffect.LinearAttenuation:
                    {
                        this.ExecuteTechniqueDrawShadows(printRT, "DrawShadowsLinearAttenuation", this.shadowMapDigested);
                    }
                    break;

                case PostEffect.LinearAttenuation_BlurLow:
                    {
                        this.ExecuteTechniqueDrawShadows(shadowsRT, "DrawShadowsNoAttenuationPreBlur", this.shadowMapDigested);
                        this.ExecuteTechniqueBlurH(shadowsRT, processedShadowsRT, "BlurHorizontallyLow");
                        this.ExecuteTechniqueBlurV(processedShadowsRT, printRT, "BlurVerticallyLowLinearAttenuation");
                    }
                    break;

                case PostEffect.LinearAttenuation_BlurMid:
                    {
                        this.ExecuteTechniqueDrawShadows(shadowsRT, "DrawShadowsNoAttenuationPreBlur", this.shadowMapDigested);
                        this.ExecuteTechniqueBlurH(shadowsRT, processedShadowsRT, "BlurHorizontallyMid");
                        this.ExecuteTechniqueBlurV(processedShadowsRT, printRT, "BlurVerticallyMidLinearAttenuation");
                    }
                    break;

                case PostEffect.LinearAttenuation_BlurHigh:
                    {
                        this.ExecuteTechniqueDrawShadows(shadowsRT, "DrawShadowsNoAttenuationPreBlur", this.shadowMapDigested);
                        this.ExecuteTechniqueBlurH(shadowsRT, processedShadowsRT, "BlurHorizontallyHigh");
                        this.ExecuteTechniqueBlurV(processedShadowsRT, printRT, "BlurVerticallyHighLinearAttenuation");
                    }
                    break;

                case PostEffect.CurveAttenuation:
                    {
                        this.ExecuteTechniqueDrawShadows(printRT, "DrawShadowsCurveAttenuation", this.shadowMapDigested);
                    }
                    break;

                case PostEffect.CurveAttenuation_BlurLow:
                    {
                        this.ExecuteTechniqueDrawShadows(shadowsRT, "DrawShadowsNoAttenuationPreBlur", this.shadowMapDigested);
                        this.ExecuteTechniqueBlurH(shadowsRT, processedShadowsRT, "BlurHorizontallyLow");
                        this.ExecuteTechniqueBlurV(processedShadowsRT, printRT, "BlurVerticallyLowCurveAttenuation");
                    }
                    break;

                case PostEffect.CurveAttenuation_BlurMid:
                    {
                        this.ExecuteTechniqueDrawShadows(shadowsRT, "DrawShadowsNoAttenuationPreBlur", this.shadowMapDigested);
                        this.ExecuteTechniqueBlurH(shadowsRT, processedShadowsRT, "BlurHorizontallyMid");
                        this.ExecuteTechniqueBlurV(processedShadowsRT, printRT, "BlurVerticallyMidCurveAttenuation");
                    }
                    break;

                case PostEffect.CurveAttenuation_BlurHigh:
                    {
                        this.ExecuteTechniqueDrawShadows(shadowsRT, "DrawShadowsNoAttenuationPreBlur", this.shadowMapDigested);
                        this.ExecuteTechniqueBlurH(shadowsRT, processedShadowsRT, "BlurHorizontallyHigh");
                        this.ExecuteTechniqueBlurV(processedShadowsRT, printRT, "BlurVerticallyHighCurveAttenuation");
                    }
                    break;

                case PostEffect.Only_BlurLow:
                    {
                        this.ExecuteTechniqueDrawShadows(shadowsRT, "DrawShadowsNoAttenuationPreBlur", this.shadowMapDigested);
                        this.ExecuteTechniqueBlurH(shadowsRT, processedShadowsRT, "BlurHorizontallyLow");
                        this.ExecuteTechniqueBlurV(processedShadowsRT, printRT, "BlurVerticallyLowNoAttenuation");
                    }
                    break;

                case PostEffect.Only_BlurMid:
                    {
                        this.ExecuteTechniqueDrawShadows(shadowsRT, "DrawShadowsNoAttenuationPreBlur", this.shadowMapDigested);
                        this.ExecuteTechniqueBlurH(shadowsRT, processedShadowsRT, "BlurHorizontallyMid");
                        this.ExecuteTechniqueBlurV(processedShadowsRT, printRT, "BlurVerticallyMidNoAttenuation");
                    }
                    break;

                case PostEffect.Only_BlurHigh:
                    {
                        this.ExecuteTechniqueDrawShadows(shadowsRT, "DrawShadowsNoAttenuationPreBlur", this.shadowMapDigested);
                        this.ExecuteTechniqueBlurH(shadowsRT, processedShadowsRT, "BlurHorizontallyHigh");
                        this.ExecuteTechniqueBlurV(processedShadowsRT, printRT, "BlurVerticallyHighNoAttenuation");
                    }
                    break;

                default: //NOFX
                    {
                        this.ExecuteTechniqueDrawShadows(printRT, "DrawShadowsNoAttenuation", this.shadowMapDigested);
                    }
                    break;
            }
            graphicsDevice.BlendState = backupBlendState;
        }
Esempio n. 3
0
 public void ResolveShadows(ShadowCasterMap shadowCasterMap, LightSource resultLight, RenderTarget2D printRT, PostEffect postEffect, Camera gameCamera)
 {
     this.ResolveShadows(shadowCasterMap, resultLight, printRT, postEffect, 1f, gameCamera);
 }
Esempio n. 4
0
 public void ResolveShadows(ShadowCasterMap shadowCasterMap, LightSource resultLight, RenderTarget2D printRT, PostEffect postEffect, float distanceMod, Vector2 newPosition, Camera gameCamera)
 {
     resultLight.Position = newPosition;
     this.ResolveShadows(shadowCasterMap, resultLight, printRT, postEffect, distanceMod, gameCamera);
 }
Esempio n. 5
0
 public Vector2 RelativeZeroHLSL(ShadowCasterMap shadowMap, Camera gameCamera)
 {
     Vector2 sizedRelativeZero = ((this.RelativeZero - (gameCamera.Position)) + new Vector2(gameCamera.Width / 2, gameCamera.Height / 2)) * shadowMap.PrecisionRatio;
     float shadowmapRelativeZeroX = sizedRelativeZero.X / shadowMap.Size.X;
     shadowmapRelativeZeroX -= (shadowmapRelativeZeroX % shadowMap.PixelSizeHLSL.X) * shadowMap.PrecisionRatio;
     float shadowmapRelativeZeroY = sizedRelativeZero.Y / shadowMap.Size.Y;
     shadowmapRelativeZeroY -= (shadowmapRelativeZeroY % shadowMap.PixelSizeHLSL.Y) * shadowMap.PrecisionRatio;
     return new Vector2(shadowmapRelativeZeroX, shadowmapRelativeZeroY);
 }
Esempio n. 6
0
        public void LoadContent(ContentManager content, GraphicsDevice gd, SpriteBatch sb)
        {
            for (int i = 0; i < PrintedLight.Length; i++)
            {
                PrintedLight[i] = new RenderTarget2D(gd, 750, 750);
                BeamLight[i] = new RenderTarget2D(gd, 750, 750);
            }
            #if OPENGL
            LFX = new LightsFX(
                content.Load<Effect>("resolveShadowsEffect.mgfxo"),
                content.Load<Effect>("reductionEffect.mgfxo"),
                content.Load<Effect>("2xMultiBlend.mgfxo"));
            #else
            LFX = new LightsFX(
                content.Load<Effect>("resolveShadowsEffect"),
                content.Load<Effect>("reductionEffect"),
                content.Load<Effect>("2xMultiBlend"));
            #endif
            ShadowmapResolver = new ShadowMapResolver(gd, LFX, 128);

            ShadowMap = new ShadowCasterMap(PrecisionSettings.VeryHigh, gd, sb);
            ScreenLights = new RenderTarget2D(gd, gd.Viewport.Width, gd.Viewport.Height);
            ScreenGround = new RenderTarget2D(gd, gd.Viewport.Width, gd.Viewport.Height);

            BeamStencils.Add(BeamStencilType.Wide, content.Load<Texture2D>("lights/beamwide"));
            BeamStencils.Add(BeamStencilType.Narrow, content.Load<Texture2D>("lights/beamnarrow"));

            SpotStencils.Add(SpotStencilType.Full, Tuple.Create<Texture2D, Texture2D, RenderTarget2D>(content.Load<Texture2D>("lights/spotbg"), content.Load<Texture2D>("lights/spotfg"), new RenderTarget2D(gd, content.Load<Texture2D>("lights/spotbg").Width, content.Load<Texture2D>("lights/spotbg").Height)));
            SpotStencils.Add(SpotStencilType.Half, Tuple.Create<Texture2D, Texture2D, RenderTarget2D>(content.Load<Texture2D>("lights/spotbg"), content.Load<Texture2D>("lights/spothalf"), new RenderTarget2D(gd, content.Load<Texture2D>("lights/spotbg").Width, content.Load<Texture2D>("lights/spotbg").Height)));

            spotBS = new BlendState()
            {
                ColorSourceBlend = Blend.DestinationColor,
                ColorDestinationBlend = Blend.SourceColor,
                ColorBlendFunction = BlendFunction.Add,
            };
        }