Example #1
0
        public RenderSystem(GraphicsDevice device, ContentManager content, IScene scene)
        {
            this.Device            = device;
            this.ClearEffect       = content.Load <Effect>("Clear");
            this.CombineEffect     = content.Load <Effect>("Combine");
            this.PostProcessEffect = content.Load <Effect>("PostProcess");;

            this.Scene = scene;

            this.Quad = new Quad();

            var width  = device.PresentationParameters.BackBufferWidth;
            var height = device.PresentationParameters.BackBufferHeight;

            // Do not enable AA as we use FXAA during post processing
            const int aaSamples = 0;

            this.ColorTarget   = new RenderTarget2D(device, width, height, false, SurfaceFormat.Color, DepthFormat.Depth24, aaSamples, RenderTargetUsage.DiscardContents);
            this.NormalTarget  = new RenderTarget2D(device, width, height, false, SurfaceFormat.Color, DepthFormat.None, aaSamples, RenderTargetUsage.DiscardContents);
            this.DepthTarget   = new RenderTarget2D(device, width, height, false, SurfaceFormat.Single, DepthFormat.None, aaSamples, RenderTargetUsage.DiscardContents);
            this.LightTarget   = new RenderTarget2D(device, width, height, false, SurfaceFormat.Color, DepthFormat.None, aaSamples, RenderTargetUsage.DiscardContents);
            this.CombineTarget = new RenderTarget2D(device, width, height, false, SurfaceFormat.Color, DepthFormat.None, aaSamples, RenderTargetUsage.DiscardContents);

            this.DirectionalLightSystem   = new DirectionalLightSystem(device, content.Load <Effect>("DirectionalLight"));
            this.PointLightSystem         = new PointLightSystem(device, content.Load <Effect>("PointLight"), content.Load <Model>("Sphere"));
            this.ShadowCastingLightSystem = new ShadowCastingLightSystem(device, content.Load <Effect>("ShadowMap"), content.Load <Effect>("ShadowCastingLight"));
            this.SunlightSystem           = new SunlightSystem(device, content.Load <Effect>("ShadowMap"), content.Load <Effect>("Sunlight"));
        }
Example #2
0
        public DeferredRenderPipeline(
            GraphicsDevice device,
            ShadowMapSystem shadowMapSystem,
            ModelSystem modelSystem,
            AveragedParticleSystem particleSystem,
            AdditiveParticleSystem additiveParticleSystem,
            ProjectorSystem projectorSystem,
            EffectFactory effectFactory,
            AmbientLightSystem ambientLightSystem,
            DirectionalLightSystem directionalLightSystem,
            PointLightSystem pointLightSystem,
            CascadedShadowMapSystem cascadedShadowMapSystem,
            ShadowCastingLightSystem shadowCastingLightSystem,
            SunlightSystem sunlightSystem,
            BoundarySystem boundarySystem,
            DynamicTextureSystem dynamicTextureSystem,
            IconSystem iconSystem,
            CutsceneSystem cutsceneSystem,
            IMeterRegistry meterRegistry)
        {
            this.ShadowMapSystem           = shadowMapSystem;
            this.ModelSystem               = modelSystem;
            this.TransparentParticleSystem = particleSystem;
            this.AdditiveParticleSystem    = additiveParticleSystem;
            this.ProjectorSystem           = projectorSystem;
            this.CombineEffect             = effectFactory.Construct <CombineEffect>();
            this.FxaaEffect               = effectFactory.Construct <FxaaEffect>();
            this.AmbientLightSystem       = ambientLightSystem;
            this.DirectionalLightSystem   = directionalLightSystem;
            this.PointLightSystem         = pointLightSystem;
            this.CascadedShadowMapSystem  = cascadedShadowMapSystem;
            this.ShadowCastingLightSystem = shadowCastingLightSystem;
            this.SunlightSystem           = sunlightSystem;
            this.BoundarySystem           = boundarySystem;
            this.DynamicTextureSystem     = dynamicTextureSystem;
            this.CutsceneSystem           = cutsceneSystem;
            this.IconSystem               = iconSystem;

            var width  = device.PresentationParameters.BackBufferWidth;
            var height = device.PresentationParameters.BackBufferHeight;

            this.GBuffer = new GBuffer(device, width, height);

            this.Input = new RenderPipelineInput();

            this.Settings = new RenderPipelineSettings();

            this.ShadowPipeline    = ShadowPipeline.Create(device, meterRegistry);
            this.LightingPipeline  = LightingPipeline.Create(device, meterRegistry);
            this.ModelPipeline     = ModelPipeline.Create(device, meterRegistry);
            this.ParticlePipeline  = ParticlePipeline.Create(device, meterRegistry);
            this.ProjectorPipeline = ProjectorPipeline.Create(device, meterRegistry);

            this.Pipeline = RenderPipeline.Create(device, meterRegistry);
            this.RootPass = new Pass(PassType.Opaque, 0);

            this.Recreate();
        }
Example #3
0
        public static LightingPipeline RenderPointLights(
            this LightingPipeline pipeline,
            PointLightSystem pointLightSystem)
        {
            var stage = new PointLightStage(pipeline.Device, pointLightSystem);

            pipeline.Add(stage);
            return(pipeline);
        }
Example #4
0
        public PipelineBuilder(GraphicsDevice device, ShadowMapSystem shadowMapSystem, ModelSystem modelSystem, AveragedParticleSystem transparentParticleSystem, AdditiveParticleSystem additiveParticleSystem, ProjectorSystem projectorSystem, EffectFactory effectFactory, AmbientLightSystem ambientLightSystem, DirectionalLightSystem directionalLightSystem, PointLightSystem pointLightSystem, CascadedShadowMapSystem cascadedShadowMapSystem, ShadowCastingLightSystem shadowCastingLightSystem, SunlightSystem sunlightSystem, IconSystem iconSystem)
        {
            this.Device                    = device;
            this.ShadowMapSystem           = shadowMapSystem;
            this.ModelSystem               = modelSystem;
            this.TransparentParticleSystem = transparentParticleSystem;
            this.AdditiveParticleSystem    = additiveParticleSystem;
            this.ProjectorSystem           = projectorSystem;
            this.CombineEffect             = effectFactory.Construct <CombineEffect>();
            this.FxaaEffect                = effectFactory.Construct <FxaaEffect>();
            this.AmbientLightSystem        = ambientLightSystem;
            this.DirectionalLightSystem    = directionalLightSystem;
            this.PointLightSystem          = pointLightSystem;
            this.CascadedShadowMapSystem   = cascadedShadowMapSystem;
            this.ShadowCastingLightSystem  = shadowCastingLightSystem;
            this.SunlightSystem            = sunlightSystem;
            this.IconSystem                = iconSystem;

            this.MeterRegistry = new NullMeterRegistry();
        }
Example #5
0
        private void DefineScene()
        {
            var device = Services.GetService <IGraphicsDeviceService>().DirectXDevice;

            scene = new Scene(Services);

            var cube = CubeMesh.New(device, modelOperations: ModelAnalyzer.DetectModelRequirements(vsFlags));

            Content.Store(cube.Name, cube);

            var modelSystem     = new ContentLoadingSystem();
            var sInitialization = new InitializationSystem();
            var cameraSystem    = new PerspectiveCameraSystem();
            var lightSystem     = new PointLightSystem();
            var positionSystem  = new TransformSystem();
            var sOptimization   = new OptimizationSystem();
            var sRendering      = new RenderSystem();
            var sUI             = new UserInterfaceSystem();

            scene.BeginDesign();

            scene.AddSystem(modelSystem);
            scene.AddSystem(cameraSystem);
            scene.AddSystem(lightSystem);
            scene.AddSystem(sInitialization);
            scene.AddSystem(positionSystem);
            scene.AddSystem(sOptimization);
            scene.AddSystem(sRendering);
            scene.AddSystem(sUI);

            Entity root = scene.CreateEntity("Root");

            root.RegisterComponent(new TransformComponent());
            root.RegisterComponent(new PositionComponent());

            Entity camera = scene.CreateEntity("Camera");

            camera.RegisterComponent(new CameraComponent {
            });
            camera.RegisterComponent(new PositionComponent {
                Position = new Vector3(0, 0f, 3f)
            });
            camera.RegisterComponent(new UpdateComponent {
                UpdateFrequency = UpdateFrequency.RealTime
            });

            Entity pointLight = scene.CreateEntity("PointLight");

            pointLight.RegisterComponent(new PointLightComponent {
            });
            pointLight.RegisterComponent(new PositionComponent {
                Position = new Vector3(0, 0f, 3f)
            });
            pointLight.RegisterComponent(new UpdateComponent {
                UpdateFrequency = UpdateFrequency.RealTime
            });
            pointLight.RegisterComponent(new ParentComponent()
            {
                Parent = root
            });
            pointLight.RegisterComponent(new TransformComponent());

            previewModel = scene.CreateEntity("PreviewModel");
            previewModel.RegisterComponent(new PositionComponent());
            previewModel.RegisterComponent(new TransformComponent());
            previewModel.RegisterComponent(new ModelComponent()
            {
                AssetName = cube.Name
            });
            previewModel.RegisterComponent(new UpdateComponent()
            {
                UpdateFrequency = UpdateFrequency.RealTime
            });
            previewModel.RegisterComponent(new MaterialComponent()
            {
                Diffuse = Color.Blue
            });
            previewModel.RegisterComponent(cShader);

            Entity ui = scene.CreateEntity("UI");

            ui.RegisterComponent(new UserInterfaceComponent {
                Overlay = Viewer.CreateOverlay(Services, this)
            });
            ui.RegisterComponent(new UpdateComponent()
            {
                UpdateFrequency = UpdateFrequency.RealTime
            });

            scene.EndDesign();
        }
Example #6
0
 public PointLightStage(GraphicsDevice device, PointLightSystem pointLightSystem)
 {
     this.Device           = device;
     this.PointLightSystem = pointLightSystem;
 }