Esempio n. 1
0
        public ShadowMapResolver(GraphicsDevice graphicsDevice, LightsFX lightsFX, int resolverRadius)
        {
            this.graphicsDevice = graphicsDevice;

            this.lightsFX = lightsFX;

            this.resolverRadiusDesired = resolverRadius;

            int resolverRadiusModified = this.resolverRadiusDesired;

            bool reductionPlanCreated = false;
            List<ShadowMapReductionStep> listReductionSteps = new List<ShadowMapReductionStep>();
            int emergencyBreak = 10;
            while (reductionPlanCreated == false)
            {
                if (reductionPlanCreated)
                    break;

                this.effectiveResolverMapSize = resolverRadiusModified * 2;
                listReductionSteps.Clear();
                int resolverMapSizeToReduce = this.effectiveResolverMapSize;

                for (int i = 0; i < 10; i++)
                {
                    bool reductionStepFound = false;
                    for (int ii = ShadowMapResolver.ReductionPower; ii > 1; ii--)
                    {
                        if (this.CheckReductionStep(ref resolverMapSizeToReduce, ii, listReductionSteps))
                        {
                            reductionStepFound = true;
                            break;
                        }
                    }

                    if (reductionStepFound == false)
                        break;

                    if (resolverMapSizeToReduce == 2)
                    {
                        reductionPlanCreated = true;
                        break;
                    }
                }
                emergencyBreak--;
                resolverRadiusModified++;
                if (emergencyBreak == 0 && reductionPlanCreated == false)
                    throw new Exception("It has been impossible to create a shadow map resolver with radius " + resolverRadius);
            }
            this.reductionSteps = listReductionSteps.ToArray();
            this.lightRadiusEffective = resolverRadiusModified;
            this.shadowMapResolverSize = this.lightRadiusEffective * 2;

            shadowMapDistorted = new RenderTarget2D(graphicsDevice, this.shadowMapResolverSize, this.shadowMapResolverSize, false, ShadowMapResolver.SurfaceLight, DepthFormat.None);
            distancesRT = new RenderTarget2D(graphicsDevice, this.shadowMapResolverSize, this.shadowMapResolverSize, false, ShadowMapResolver.SurfaceLight, DepthFormat.None);
            shadowMapDigested = new RenderTarget2D(graphicsDevice, 2, this.shadowMapResolverSize, false, ShadowMapResolver.SurfaceLight, DepthFormat.None);
            shadowsRT = new RenderTarget2D(graphicsDevice, this.shadowMapResolverSize, this.shadowMapResolverSize, false, ShadowMapResolver.SurfaceLight, DepthFormat.None);
            processedShadowsRT = new RenderTarget2D(graphicsDevice, this.shadowMapResolverSize, this.shadowMapResolverSize, false, ShadowMapResolver.SurfaceLight, DepthFormat.None);
        }
Esempio n. 2
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,
            };
        }