コード例 #1
0
        public void LoadContent(IContentManager manager, Engine.GraphicInfo ginfo, Engine.GraphicFactory factory, bool cullPointLight, bool useFloatingBufferForLightning)
        {
            _lightAddBlendState = new BlendState()
            {
                AlphaSourceBlend      = Blend.One,
                ColorSourceBlend      = Blend.One,
                AlphaDestinationBlend = Blend.One,
                ColorDestinationBlend = Blend.One,
            };
            this.ginfo = ginfo;
            shadow     = new DirectionalShadowRenderer();
            shadow.ShadowFilteringType = filteringType;
            shadow.ShadowMapSize       = shadowMapSize;
            shadow.SplitConstant       = splitConstant;

            shadownBufferSize = ginfo.BackBufferWidth;
            shadowRT          = factory.CreateRenderTarget(shadownBufferSize, shadownBufferSize, SurfaceFormat.Single, ginfo.UseMipMap, DepthFormat.Depth24Stencil8, ginfo.MultiSample);

            if (useFloatingBufferForLightning)
            {
                lightRT = factory.CreateRenderTarget(ginfo.BackBufferWidth, ginfo.BackBufferHeight, SurfaceFormat.HdrBlendable, ginfo.UseMipMap, DepthFormat.None, ginfo.MultiSample, RenderTargetUsage.PreserveContents);
            }
            else
            {
                lightRT = factory.CreateRenderTarget(ginfo.BackBufferWidth, ginfo.BackBufferHeight, SurfaceFormat.Color, ginfo.UseMipMap, DepthFormat.None, ginfo.MultiSample, RenderTargetUsage.PreserveContents);
            }

            pointLightEffect       = factory.GetEffect("PointLight", false, true);
            directionalLightEffect = factory.GetEffect("ShadowDirectionalCascade", false, true);
            spotLightEffect        = factory.GetEffect("ShadowSpot", false, true);
            sphereModel            = new SimpleModel(factory, "Dsphere", true);
            blank = factory.CreateTexture2DColor(1, 1, Color.White);

            rt         = factory.CreateRenderTarget(ginfo.BackBufferWidth, ginfo.BackBufferHeight, SurfaceFormat.Color, ginfo.UseMipMap, DepthFormat.Depth24Stencil8, ginfo.MultiSample);
            deferredRT = factory.CreateRenderTarget(shadownBufferSize, shadownBufferSize, SurfaceFormat.Single, ginfo.UseMipMap, DepthFormat.Depth24Stencil8, ginfo.MultiSample);
            shadow.Load(factory, ginfo);

            switch (shadowFilterSpot)
            {
            case ShadowFilter.NONE:
                spotLightEffect.CurrentTechnique = spotLightEffect.Techniques["Technique1"];
                break;

            case ShadowFilter.PCF3x3:
                spotLightEffect.CurrentTechnique = spotLightEffect.Techniques["Technique2"];
                break;

            case ShadowFilter.PCF7x7SOFT:
                spotLightEffect.CurrentTechnique = spotLightEffect.Techniques["Technique3"];
                break;

            default:
                break;
            }
        }
コード例 #2
0
        public void LoadContent(IContentManager manager, Engine.GraphicInfo ginfo, Engine.GraphicFactory factory, bool cullPointLight, bool useFloatingBufferForLightning)
        {
            _lightAddBlendState = new BlendState()
            {
                AlphaSourceBlend = Blend.One,
                ColorSourceBlend = Blend.One,
                AlphaDestinationBlend = Blend.One,
                ColorDestinationBlend = Blend.One,
            };
            this.ginfo = ginfo;
            shadow = new DirectionalShadowRenderer();
            shadow.ShadowFilteringType = filteringType;
            shadow.ShadowMapSize = shadowMapSize;
            shadow.SplitConstant = splitConstant;
            
            shadownBufferSize = ginfo.BackBufferWidth;
            shadowRT = factory.CreateRenderTarget(shadownBufferSize, shadownBufferSize, SurfaceFormat.Single, ginfo.UseMipMap,DepthFormat.Depth24Stencil8,ginfo.MultiSample);

            if (useFloatingBufferForLightning)
                lightRT = factory.CreateRenderTarget(ginfo.BackBufferWidth, ginfo.BackBufferHeight, SurfaceFormat.HdrBlendable, ginfo.UseMipMap, DepthFormat.None, ginfo.MultiSample, RenderTargetUsage.PreserveContents);
            else
                lightRT = factory.CreateRenderTarget(ginfo.BackBufferWidth, ginfo.BackBufferHeight, SurfaceFormat.Color, ginfo.UseMipMap, DepthFormat.None, ginfo.MultiSample, RenderTargetUsage.PreserveContents);

            pointLightEffect = factory.GetEffect("PointLight",false,true);
            directionalLightEffect = factory.GetEffect("ShadowDirectionalCascade",false,true);
            spotLightEffect = factory.GetEffect("ShadowSpot",false,true);
            sphereModel = new SimpleModel(factory, "Dsphere", true);
            blank = factory.CreateTexture2DColor(1, 1, Color.White);

            rt = factory.CreateRenderTarget(ginfo.BackBufferWidth, ginfo.BackBufferHeight,SurfaceFormat.Color,ginfo.UseMipMap,DepthFormat.Depth24Stencil8,ginfo.MultiSample);
            deferredRT = factory.CreateRenderTarget(shadownBufferSize, shadownBufferSize, SurfaceFormat.Single,ginfo.UseMipMap, DepthFormat.Depth24Stencil8, ginfo.MultiSample);
            shadow.Load(factory,ginfo);

            switch (shadowFilterSpot)
            {
                case ShadowFilter.NONE:
                    spotLightEffect.CurrentTechnique = spotLightEffect.Techniques["Technique1"];
                    break;                
                case ShadowFilter.PCF3x3:
                    spotLightEffect.CurrentTechnique = spotLightEffect.Techniques["Technique2"];
                    break;             
                case ShadowFilter.PCF7x7SOFT:
                    spotLightEffect.CurrentTechnique = spotLightEffect.Techniques["Technique3"];
                    break;
                default:
                    break;
            }

        }