Пример #1
0
 public void AddRenderSystem(IRenderSystem system)
 {
     if (system == null)
     {
         throw new ArgumentNullException("system");
     }
 }
Пример #2
0
        public void Draw(GameTime gameTime)
        {
            if (!_initialized)
            {
                if (Services.HasInstance <ILogger>())
                {
                    Services.GetInstance <ILogger>().WriteLine(LogEntryType.Warning, string.Format("Draw call skipped. {0} has not yet been initialized.", GetType().Name));
                }
                return;
            }

            IRenderSystem renderer = Services.GetInstance <IRenderSystem>();

            if (renderer == null)
            {
                if (Services.HasInstance <ILogger>())
                {
                    Services.GetInstance <ILogger>().WriteLine(LogEntryType.Warning, "No rendering service has been registered.");
                }
            }

            renderer.PreProcess();
            renderer.Render();
            renderer.PostProcess();
        }
Пример #3
0
        private void RegisterSystemTo(List <RenderSystemHolder> list, IRenderSystem system, System.Type systemType, System.Type updateBefore, System.Type updateAfter)
        {
            if (list == null)
            {
                Console.WriteLine("List was null while registering a system.");
                return;
            }

            if (systems.ContainsKey(systemType))
            {
                Console.WriteLine($"System {systemType.Name} is already registered!");
                return;
            }

            systems.Add(systemType, system);

            list.Add(new RenderSystemHolder()
            {
                system       = system,
                systemType   = systemType,
                renderBefore = updateBefore,
                renderAfter  = updateAfter
            });

            SortSystemList(list);
        }
Пример #4
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            wandererWorld = Matrix.Identity;

            wanderer = new WandererBody(this);
            heightMapTransformSystem_Wanderer = new HeightMapTransformSystem_Wanderer();

            heightMapComponent       = new HeightMapComponent();
            heightMapCameraComponent = new HeightMapCameraComponent();

            robotComponent = new RobotComponent();

            heightMapSystem         = new HeightmapSystem();
            heightMapTranformSystem = new HeightMapTranformSystem();
            heightMapRenderSystem   = new HeightMapRenderSystem(graphics.GraphicsDevice);

            robotSystem         = new RobotSystem();
            robotTranformSystem = new RobotTranformSystem();
            robotRenderSystem   = new RobotRenderSystem();

            collisionSystem = new CollisionSystem();
            houseSystem     = new HouseSystem(this);

            systemRenderer = new Renderer();

            base.Initialize();
        }
Пример #5
0
 public TurtlePen(IRenderSystem renderSystem)
 {
     _positionStack       = new Stack <Vector3>();
     _rotationStack       = new Stack <Quaternion>();
     _branchDiameterStack = new Stack <float>();
     _colorStack          = new Stack <Color>();
     _renderSystem        = renderSystem;
     _randomGenerator     = new Random();
 }
Пример #6
0
        public override void Play(ISkillAttacker attacker, SkillEffect se)
        {
            if (attacker == null)
            {
                return;
            }
            IEntity en = attacker.GetGameObject();

            if (en == null)
            {
                return;
            }
            if (!SkillSystem.GetClientGlobal().IsMainPlayer(en))
            {//不是主角不震屏
                return;
            }
            ShakeCameraNodeProp prop = m_NodeProp as ShakeCameraNodeProp;

            if (prop == null)
            {
                return;
            }
            IRenderSystem renderSys = RareEngine.Instance().GetRenderSystem();

            if (renderSys == null)
            {
                Log.Error("RenderSystem is null!");
                return;
            }
            string  camName = "MainCamera";
            ICamera cam     = renderSys.GetCamera(ref camName);

            if (cam != null)
            {
                ICameraCtrl cc = cam.GetCameraCtrl();
                if (cc != null)
                {
                    //   public float duration = 0.2f;//持续时间
                    //   public float strength = 0.5f;//振幅
                    //   public int vibrato = 10;//频率
                    //@brief 开始振动
                    //@param fAmplitude 振幅
                    //@param fFrequency 频率
                    //@param fCycle 周期
                    //@param fTime 持续时间

                    cc.StartShake(prop.strength, prop.vibrato, 1, prop.duration);
                }
            }
            else
            {
                //编辑器代码实现
                Camera.main.DOShakePosition(prop.duration, prop.strength, prop.vibrato, 0);
            }
        }
Пример #7
0
    private void LoadRenderObj(string strObj)
    {
        //人物资源预先加载
        IRenderObj    obj = null;
        IRenderSystem rs  = RareEngine.Instance().GetRenderSystem();

        rs.CreateRenderObj(ref strObj, ref obj, null, Vector3.zero, TaskPriority.TaskPriority_Immediate, true);
        if (obj != null)
        {
            rs.RemoveRenderObj(obj);
        }
    }
Пример #8
0
        /// <summary>
        /// 仅仅创建一个模型
        /// </summary>
        /// <param name="body"></param>
        /// <param name="weapon"></param>
        /// <param name="wing"></param>
        /// <returns></returns>
        public bool CreateAvatar(GameObject parent, List <SuitInfo> lstSuit, int nLayer = 0, Action <object> callback = null, object param = null)
        {
            m_CallBack = callback;
            m_Param    = param;

            IRenderSystem rs = RareEngine.Instance().GetRenderSystem();

            if (rs == null)
            {
                return(false);
            }

            for (int i = 0; i < lstSuit.Count; ++i)
            {
                m_lstSuitData.Add(new SuitData
                {
                    info = lstSuit[i],
                    obj  = null,
                });
            }


            m_nLayer = nLayer;
            for (int i = 0; i < m_lstSuitData.Count; ++i)
            {
                if (m_lstSuitData[i] == null)
                {
                    continue;
                }

                if (m_lstSuitData[i].info.pos == SuitPos.Cloth)
                {
                    //Engine.Utility.Log.Error("Create Body");
                    //先创建身体
                    rs.CreateRenderObj(ref m_lstSuitData[i].info.modelPath, ref m_obj, OnCreateBodyEvent, m_lstSuitData[i].info.pos, TaskPriority.TaskPriority_Normal, true);
                    if (m_obj != null)
                    {
                        // 挂接父节点
                        Vector3 rot = m_obj.GetNode().GetTransForm().localEulerAngles;
                        m_obj.GetNode().GetTransForm().parent           = parent.transform;
                        m_obj.GetNode().GetTransForm().localPosition    = Vector3.zero;
                        m_obj.GetNode().GetTransForm().localEulerAngles = rot;
                        m_obj.GetNode().GetTransForm().localScale       = Vector3.one;
                    }
                    else
                    {
                        Engine.Utility.Log.Error("obj is null path is " + m_lstSuitData[i].info.modelPath);
                    }
                }
            }

            return(true);
        }
Пример #9
0
    private void LoadRenderObj(string strObj, string strMaterial)
    {
        //人物资源预先加载
        IRenderObj    obj = null;
        IRenderSystem rs  = RareEngine.Instance().GetRenderSystem();

        rs.CreateRenderObj(ref strObj, ref obj, null, Vector3.zero, TaskPriority.TaskPriority_Normal, true);
        if (obj != null)
        {
            obj.ApplyMaterial(strMaterial);
            rs.RemoveRenderObj(obj);
        }
    }
Пример #10
0
        protected override void OnSystemAdd()
        {
            this.effectSystemOld  = Services.GetSafeServiceAs <IEffectSystemOld>();
            renderSystem          = Services.GetSafeServiceAs <IRenderSystem>();
            graphicsDeviceService = Services.GetSafeServiceAs <IGraphicsDeviceService>();
            assetManager          = Services.GetSafeServiceAs <IAssetManager>();

            renderSystem.RenderPassEnumerators.Add(renderPassEnumerator);

            if (enableIcons)
            {
                InitializeIconsRenderer();
            }
        }
Пример #11
0
        public void OnCreateSystem(ECSWorld world)
        {
            //camera = new Camera() {
            //	aspect = (float)Window.window.Width / (float)Window.window.Height,
            //	farPlane = 10000,
            //	fow = 60,
            //	nearPlane = 0.1f
            //};

            //cameraPosition = new Vector3(4 , 10, 20);
            //cameraRotation = MathHelper.LookAt(cameraPosition, Vector3.Zero, Vector3.UnitY);
            cameraQuery = new ComponentQuery();
            cameraQuery.IncludeShared <Camera>();
            cameraQuery.IncludeReadonly <Position>();
            cameraQuery.IncludeReadonly <Rotation>();

            foreach (var assembly in AssemblyHelper.GetAllUserAssemblies())
            {
                foreach (Type type in AssemblyHelper.GetTypesWithAttribute(assembly, typeof(RenderSystemAttribute)))
                {
                    try
                    {
                        if (!type.GetInterfaces().Contains(typeof(IRenderSystem)))
                        {
                            continue;
                        }

                        RenderSystemAttribute attribute =
                            type.GetCustomAttribute(typeof(RenderSystemAttribute)) as RenderSystemAttribute;
                        IRenderSystem instance = Activator.CreateInstance(type) as IRenderSystem;

                        RegisterRenderSystem(instance, type, attribute.renderStage, attribute.renderBefore,
                                             attribute.renderAfter);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"could not create an instance of type {type.Name}. Does it have an empty constructor? \n{ex.StackTrace}");
                    }
                }
            }

            foreach (var renderSystem in systems)
            {
                renderSystem.Value.OnCreate(world);
            }
        }
Пример #12
0
    public void CreateMainCamera(bool active)
    {
        // 逻辑层初始化
        IRenderSystem renderSys = RareEngine.Instance().GetRenderSystem();

        if (renderSys == null)
        {
            Log.Error("RenderSystem is null!");
            // return;
        }

        // 设置主Camera
        string  strCameraName = "MainCamera";
        ICamera cam           = renderSys.GetCamera(ref strCameraName);

        if (cam != null)
        {
            cam.Enable(active);
            return;
        }

        cam = renderSys.CreateCamera(ref strCameraName, 0.3f, 140f, 45f, -1, CameraClearFlags.Skybox);
        if (cam != null)
        {
            Camera        camera   = cam.GetNode().GetTransForm().gameObject.GetComponent <Camera>();
            AudioListener listener = camera.transform.GetComponent <AudioListener>();
            if (listener != null)
            {
                GameObject.Destroy(listener);
            }
            CameraFollow.Instance.camera = cam;
            Engine.IAudio audio = Engine.RareEngine.Instance().GetAudio();
            if (audio != null)
            {
                audio.SetListener(CameraFollow.Instance.CreateAudioListener());
            }

            camera.cullingMask = -1 - (1 << LayerMask.NameToLayer("UI")) - (1 << LayerMask.NameToLayer("ShowModel")) - (1 << LayerMask.NameToLayer("UIHide"));
            camera.tag         = strCameraName;
            cam.SetDepth((float)Engine.CameraDepth.Scene);
            cam.LookAt(new Vector3(0, 3, 5), new Vector3(0, 0, 0), new Vector3(0, 1, 0));
            UnityEngine.MonoBehaviour.DontDestroyOnLoad(camera.gameObject);
            cam.Enable(active);
        }
    }
Пример #13
0
        public override void Stop()
        {
            IRenderSystem renderSys = RareEngine.Instance().GetRenderSystem();

            if (renderSys == null)
            {
                Log.Error("RenderSystem is null!");
                return;
            }
            string  camName = "Main Camera";
            ICamera cam     = renderSys.GetCamera(ref camName);

            if (cam != null)
            {
                ICameraCtrl cc = cam.GetCameraCtrl();
                if (cc != null)
                {
                    cc.StopShake();
                }
            }
        }
Пример #14
0
        /**
         * @brief 对象销毁
         */
        public void Destroy()
        {
            if (m_obj != null)
            {
                IRenderSystem rs = RareEngine.Instance().GetRenderSystem();
                if (rs == null)
                {
                    return;
                }

                if (m_obj.GetNode() == null)
                {
                    return;
                }

                if (m_obj.GetNode().GetTransForm() == null)
                {
                    return;
                }


                if (m_obj.GetNode().GetTransForm().parent != null)
                {
                    m_obj.GetNode().GetTransForm().parent = null;
                }

                rs.RemoveRenderObj(m_obj);
                m_obj = null;

                for (int i = 0; i < m_lstSuitData.Count; ++i)
                {
                    if (m_lstSuitData[i].obj != null)
                    {
                        rs.RemoveRenderObj(m_lstSuitData[i].obj);
                    }
                }

                //Engine.Utility.Log.Error("Destroy Avater");
            }
        }
Пример #15
0
        //-------------------------------------------------------------------------------------------------------
        private void OnCreateBodyEvent(Engine.IRenderObj obj, object param)
        {
            if (obj == null)
            {
                return;
            }

            m_obj = obj;

            IRenderSystem rs = RareEngine.Instance().GetRenderSystem();

            if (rs == null)
            {
                return;
            }

            //Engine.Utility.Log.Error("OnCreateBodyEvent {0}", m_obj.GetName());

            for (int i = 0; i < m_lstSuitData.Count; ++i)
            {
                if (m_lstSuitData[i] == null)
                {
                    continue;
                }

                if (m_lstSuitData[i].info.pos != SuitPos.Cloth)
                {
                    //Engine.Utility.Log.Error("Create {0}", m_lstSuitData[i].info.pos.ToString());
                    rs.CreateRenderObj(ref m_lstSuitData[i].info.modelPath, ref m_lstSuitData[i].obj, OnCreateRenderObj, m_lstSuitData[i].info.pos, TaskPriority.TaskPriority_Normal, false);
                }
            }

            if (m_lstSuitData.Count == 1 && m_lstSuitData[0].info.pos == SuitPos.Cloth)
            {
                OnCreateRenderObj(obj, SuitPos.None);
            }

            m_obj.SetLayer(m_nLayer);
        }
 public void AddRenderSystem(IRenderSystem system)
 {
     if (system == null)
         throw new ArgumentNullException("system");
 }
Пример #17
0
        public void Initialize(IServiceRegistry registry, string effectFilename = null, string[] optionalFeatures = null)
        {
            // Missing features compared to before: ZInverse support, Picking/Wireframe, Heat Shimmering and light shafts bounding boxes.
            // Other stuff to implement: Enable features by RenderPipeline, reloading, access of plugins through a flexible interface, yebis config.
            renderSystem          = registry.GetSafeServiceAs <IRenderSystem>();
            graphicsDeviceService = registry.GetSafeServiceAs <IGraphicsDeviceService>();
            this.effectSystemOld  = registry.GetSafeServiceAs <IEffectSystemOld>();
            entitySystem          = registry.GetSafeServiceAs <IEntitySystem>();

            var rootRenderPass = renderSystem.RootRenderPass;
            var dataContext    = RenderConfigContext = renderSystem.ConfigContext;
            var graphicsDevice = graphicsDeviceService.GraphicsDevice;

            if (effectFilename == null)
            {
                effectFilename = Path.Combine("/shaders/effects.xml");
            }

            var context          = new XenkoXamlSchemaContext(dataContext);
            var xamlObjectWriter = new XamlObjectWriter(context);

            using (var fileStream = VirtualFileSystem.OpenStream(effectFilename, VirtualFileMode.Open, VirtualFileAccess.Read))
                XamlServices.Transform(new XamlXmlReader(fileStream, context), xamlObjectWriter);

            var effectConfig = (RenderConfig)xamlObjectWriter.Result;

            foreach (var renderPass in effectConfig.Content.OfType <RenderPass>())
            {
                dataContext.RenderPasses.Add(renderPass.Name, renderPass);
                rootRenderPass.AddPass(renderPass);
            }

            foreach (var item in effectConfig.Content)
            {
                var plugin = item as RenderPassPlugin;
                if (plugin != null)
                {
                    dataContext.RenderPassPlugins.Add(plugin.Name, plugin);
                }

                var setter = item as Setter;
                if (setter != null)
                {
                    PropertyPath.SetNextValue(setter.Target, setter.Property, setter.Value);
                }
            }

            MainPlugin       = dataContext.RenderPassPlugins.Select(x => x.Value).OfType <MainPlugin>().First();
            MainTargetPlugin = dataContext.RenderPassPlugins.Select(x => x.Value).OfType <RenderTargetsPlugin>().FirstOrDefault(x => x.Name == "MainTargetPlugin");

            var mainBackBuffer = graphicsDevice.BackBuffer;

            MainPlugin.RenderTarget = graphicsDevice.BackBuffer;

            // Depth Stencil target needs to be shader resource only if Yebis or GBuffer is active (need more robust way to decide)
            var depthStencilTexture = Texture.New2D(graphicsDevice, mainBackBuffer.Width, mainBackBuffer.Height, PixelFormat.D32_Float,
                                                    (RenderConfigContext.RenderPassPlugins.Any(x => x.Value is YebisPlugin || x.Value is GBufferPlugin) ? TextureFlags.ShaderResource : 0) | TextureFlags.DepthStencil);

            MainPlugin.DepthStencil = depthStencilTexture.ToDepthStencilBuffer(false);

            if (DepthStencilBuffer.IsReadOnlySupported(graphicsDevice))
            {
                MainPlugin.DepthStencilReadOnly = depthStencilTexture.ToDepthStencilBuffer(true);
            }

            // TODO: Temporary setup (should be done through an Entity and its Manager)
            HeatShimmerPlugin heatShimmerPlugin;

            if (RenderConfigContext.RenderPassPlugins.TryGetValueCast("HeatShimmerPlugin", out heatShimmerPlugin))
            {
                throw new NotImplementedException();
                //heatShimmerPlugin.BoundingBoxes.Add(new MeshData { MeshData = MeshDataHelper.CreateBox(1, 1, 1, Color.White, true), Parameters = new ParameterCollectionData { { TransformationKeys.World, Matrix.Scaling(8200, 3000, 1500) * Matrix.Translation(2700, 0, 300) } } });
                //heatShimmerPlugin.BoundingBoxes.Add(new MeshData { MeshData = MeshDataHelper.CreateBox(1, 1, 1, Color.White, true), Parameters = new ParameterCollectionData { { TransformationKeys.World, Matrix.Scaling(2000, 2000, 3500) * Matrix.RotationZ(0.5f) * Matrix.Translation(-7000, -4000, 1500) } } });
                //heatShimmerPlugin.BoundingBoxes.Add(new MeshData { MeshData = MeshDataHelper.CreateBox(1, 1, 1, Color.White, true), Parameters = new ParameterCollectionData { { TransformationKeys.World, Matrix.Scaling(2000, 3000, 3500) * Matrix.Translation(-7800, 900, 1500) } } });
            }

            // Generates intermediate render targets
            var plugins = dataContext.RenderPassPlugins
                          .OrderBy(x => rootRenderPass.Passes.IndexOf(x.Value.RenderPass)).ToArray();

            // Weave render targets from last to first plugin.
            // TODO: Instead of guessing through interface and non-null/null values, it would be better if plugin had flags to inform of its intentions.
            var currentTarget = mainBackBuffer;

            for (int i = plugins.Length - 1; i >= 0; --i)
            {
                var plugin = plugins[i];

                var targetPlugin = plugin.Value as IRenderPassPluginTarget;
                if (targetPlugin != null)
                {
                    if (targetPlugin.RenderTarget == null)
                    {
                        targetPlugin.RenderTarget = currentTarget;
                    }

                    currentTarget = targetPlugin.RenderTarget;
                }

                var sourcePlugin = plugin.Value as IRenderPassPluginSource;
                if (sourcePlugin != null)
                {
                    if (sourcePlugin.RenderSource == null)
                    {
                        sourcePlugin.RenderSource = Texture.New2D(graphicsDevice, mainBackBuffer.Width, mainBackBuffer.Height, PixelFormat.R16G16B16A16_Float, TextureFlags.ShaderResource | TextureFlags.RenderTarget);
                    }

                    currentTarget = sourcePlugin.RenderSource.ToRenderTarget();
                }
            }

            foreach (var plugin in dataContext.RenderPassPlugins)
            {
                renderSystem.RenderPassPlugins.Add(plugin.Value);
            }

            foreach (var effectBuilder in effectConfig.Content.OfType <EffectBuilder>())
            {
                foreach (var plugin in effectBuilder.Plugins)
                {
                    plugin.Services = registry;
                }
                this.effectSystemOld.Effects.Add(effectBuilder);
            }

#if XENKO_YEBIS
            YebisPlugin yebisPlugin;
            if (RenderConfigContext.RenderPassPlugins.TryGetValueCast("YebisPlugin", out yebisPlugin))
            {
                yebisPlugin.AntiAlias = true;

                yebisPlugin.ToneMap.Gamma = 2.2f;
                yebisPlugin.ToneMap.Type  = ToneMapType.SensiToMetric;
                yebisPlugin.ToneMap.AutoExposure.Enable                    = true;
                yebisPlugin.ToneMap.AutoExposure.MiddleGray                = 0.25f;
                yebisPlugin.ToneMap.AutoExposure.AdaptationSensitivity     = 0.5f;
                yebisPlugin.ToneMap.AutoExposure.AdaptationScale           = 0.8f;
                yebisPlugin.ToneMap.AutoExposure.AdaptationSpeedLimit      = 4.0f;
                yebisPlugin.ToneMap.AutoExposure.DarkAdaptationSensitivity = 0.9f;
                yebisPlugin.ToneMap.AutoExposure.DarkAdaptationScale       = 0.6f;
                yebisPlugin.ToneMap.AutoExposure.DarkAdaptationSpeedLimit  = 4.0f;
                yebisPlugin.ToneMap.AutoExposure.LightDarkExposureBorder   = 1.0f;

                yebisPlugin.Glare.Enable = true;
                //yebisPlugin.Glare.RemapFactor = 1.0f;
                //yebisPlugin.Glare.Threshold = 0.0f;

                yebisPlugin.Lens.Vignette.Enable = true;

                yebisPlugin.Lens.Distortion.Enable         = false;
                yebisPlugin.Lens.Distortion.Power          = 0.2f;
                yebisPlugin.Lens.Distortion.EdgeSmoothness = 0.2f;

                yebisPlugin.DepthOfField.Enable            = true;
                yebisPlugin.DepthOfField.AutoFocus         = true;
                yebisPlugin.DepthOfField.Aperture          = 2.0f;
                yebisPlugin.DepthOfField.ImageSensorHeight = 40.0f;

                //yebisPlugin.ColorCorrection.ColorTemperature = 4500;

                yebisPlugin.HeatShimmer.Enable = false;
                //YebisPlugin.LightShaft.Enable = true;
                //YebisPlugin.LightShaft.ScreenPosition = new Vector2(0.5f, 0.1f);
            }
#endif

            // Adds the particle system if the ParticlePlugin is used in the config
            ParticlePlugin particlePlugin;
            if (RenderConfigContext.RenderPassPlugins.TryGetValueCast("ParticlePlugin", out particlePlugin))
            {
                var particleSystem = new ParticleProcessor(particlePlugin);
                entitySystem.Processors.Add(particleSystem);
            }
        }
Пример #18
0
        public void Initialize(IServiceRegistry registry, string effectFilename = null, string[] optionalFeatures = null)
        {
            // Missing features compared to before: ZInverse support, Picking/Wireframe, Heat Shimmering and light shafts bounding boxes.
            // Other stuff to implement: Enable features by RenderPipeline, reloading, access of plugins through a flexible interface, yebis config.
            renderSystem = registry.GetSafeServiceAs<IRenderSystem>();
            graphicsDeviceService = registry.GetSafeServiceAs<IGraphicsDeviceService>();
            this.effectSystemOld = registry.GetSafeServiceAs<IEffectSystemOld>();
            entitySystem = registry.GetSafeServiceAs<IEntitySystem>();
            
            var rootRenderPass = renderSystem.RootRenderPass;
            var dataContext = RenderConfigContext = renderSystem.ConfigContext;
            var graphicsDevice = graphicsDeviceService.GraphicsDevice;

            if (effectFilename == null)
                effectFilename = Path.Combine("/shaders/effects.xml");

            var context = new XenkoXamlSchemaContext(dataContext);
            var xamlObjectWriter = new XamlObjectWriter(context);

            using (var fileStream = VirtualFileSystem.OpenStream(effectFilename, VirtualFileMode.Open, VirtualFileAccess.Read))
                XamlServices.Transform(new XamlXmlReader(fileStream, context), xamlObjectWriter);

            var effectConfig = (RenderConfig)xamlObjectWriter.Result;

            foreach (var renderPass in effectConfig.Content.OfType<RenderPass>())
            {
                dataContext.RenderPasses.Add(renderPass.Name, renderPass);
                rootRenderPass.AddPass(renderPass);
            }

            foreach (var item in effectConfig.Content)
            {
                var plugin = item as RenderPassPlugin;
                if (plugin != null)
                {
                    dataContext.RenderPassPlugins.Add(plugin.Name, plugin);
                }

                var setter = item as Setter;
                if (setter != null)
                {
                    PropertyPath.SetNextValue(setter.Target, setter.Property, setter.Value);
                }
            }

            MainPlugin = dataContext.RenderPassPlugins.Select(x => x.Value).OfType<MainPlugin>().First();
            MainTargetPlugin = dataContext.RenderPassPlugins.Select(x => x.Value).OfType<RenderTargetsPlugin>().FirstOrDefault(x => x.Name == "MainTargetPlugin");

            var mainBackBuffer = graphicsDevice.BackBuffer;
            MainPlugin.RenderTarget = graphicsDevice.BackBuffer;
            
            // Depth Stencil target needs to be shader resource only if Yebis or GBuffer is active (need more robust way to decide)
            var depthStencilTexture = Texture.New2D(graphicsDevice, mainBackBuffer.Width, mainBackBuffer.Height, PixelFormat.D32_Float,
                (RenderConfigContext.RenderPassPlugins.Any(x => x.Value is YebisPlugin || x.Value is GBufferPlugin) ? TextureFlags.ShaderResource : 0) | TextureFlags.DepthStencil);
            MainPlugin.DepthStencil = depthStencilTexture.ToDepthStencilBuffer(false);

            if (DepthStencilBuffer.IsReadOnlySupported(graphicsDevice))
                MainPlugin.DepthStencilReadOnly = depthStencilTexture.ToDepthStencilBuffer(true);

            // TODO: Temporary setup (should be done through an Entity and its Manager)
            HeatShimmerPlugin heatShimmerPlugin;
            if (RenderConfigContext.RenderPassPlugins.TryGetValueCast("HeatShimmerPlugin", out heatShimmerPlugin))
            {
                throw new NotImplementedException();
                //heatShimmerPlugin.BoundingBoxes.Add(new MeshData { MeshData = MeshDataHelper.CreateBox(1, 1, 1, Color.White, true), Parameters = new ParameterCollectionData { { TransformationKeys.World, Matrix.Scaling(8200, 3000, 1500) * Matrix.Translation(2700, 0, 300) } } });
                //heatShimmerPlugin.BoundingBoxes.Add(new MeshData { MeshData = MeshDataHelper.CreateBox(1, 1, 1, Color.White, true), Parameters = new ParameterCollectionData { { TransformationKeys.World, Matrix.Scaling(2000, 2000, 3500) * Matrix.RotationZ(0.5f) * Matrix.Translation(-7000, -4000, 1500) } } });
                //heatShimmerPlugin.BoundingBoxes.Add(new MeshData { MeshData = MeshDataHelper.CreateBox(1, 1, 1, Color.White, true), Parameters = new ParameterCollectionData { { TransformationKeys.World, Matrix.Scaling(2000, 3000, 3500) * Matrix.Translation(-7800, 900, 1500) } } });
            }
            
            // Generates intermediate render targets
            var plugins = dataContext.RenderPassPlugins
                .OrderBy(x => rootRenderPass.Passes.IndexOf(x.Value.RenderPass)).ToArray();

            // Weave render targets from last to first plugin.
            // TODO: Instead of guessing through interface and non-null/null values, it would be better if plugin had flags to inform of its intentions.
            var currentTarget = mainBackBuffer;
            for (int i = plugins.Length - 1; i >= 0; --i)
            {
                var plugin = plugins[i];

                var targetPlugin = plugin.Value as IRenderPassPluginTarget;
                if (targetPlugin != null)
                {
                    if (targetPlugin.RenderTarget == null)
                        targetPlugin.RenderTarget = currentTarget;

                    currentTarget = targetPlugin.RenderTarget;
                }

                var sourcePlugin = plugin.Value as IRenderPassPluginSource;
                if (sourcePlugin != null)
                {
                    if (sourcePlugin.RenderSource == null)
                    {
                        sourcePlugin.RenderSource = Texture.New2D(graphicsDevice, mainBackBuffer.Width, mainBackBuffer.Height, PixelFormat.R16G16B16A16_Float, TextureFlags.ShaderResource | TextureFlags.RenderTarget);
                    }

                    currentTarget = sourcePlugin.RenderSource.ToRenderTarget();
                }
            }

            foreach (var plugin in dataContext.RenderPassPlugins)
            {
                renderSystem.RenderPassPlugins.Add(plugin.Value);
            }

            foreach (var effectBuilder in effectConfig.Content.OfType<EffectBuilder>())
            {
                foreach (var plugin in effectBuilder.Plugins)
                {
                    plugin.Services = registry;
                }
                this.effectSystemOld.Effects.Add(effectBuilder);
            }

#if XENKO_YEBIS
            YebisPlugin yebisPlugin;
            if (RenderConfigContext.RenderPassPlugins.TryGetValueCast("YebisPlugin", out yebisPlugin))
            {
                yebisPlugin.AntiAlias = true;

                yebisPlugin.ToneMap.Gamma = 2.2f;
                yebisPlugin.ToneMap.Type = ToneMapType.SensiToMetric;
                yebisPlugin.ToneMap.AutoExposure.Enable = true;
                yebisPlugin.ToneMap.AutoExposure.MiddleGray = 0.25f;
                yebisPlugin.ToneMap.AutoExposure.AdaptationSensitivity = 0.5f;
                yebisPlugin.ToneMap.AutoExposure.AdaptationScale = 0.8f;
                yebisPlugin.ToneMap.AutoExposure.AdaptationSpeedLimit = 4.0f;
                yebisPlugin.ToneMap.AutoExposure.DarkAdaptationSensitivity = 0.9f;
                yebisPlugin.ToneMap.AutoExposure.DarkAdaptationScale = 0.6f;
                yebisPlugin.ToneMap.AutoExposure.DarkAdaptationSpeedLimit = 4.0f;
                yebisPlugin.ToneMap.AutoExposure.LightDarkExposureBorder = 1.0f;

                yebisPlugin.Glare.Enable = true;
                //yebisPlugin.Glare.RemapFactor = 1.0f;
                //yebisPlugin.Glare.Threshold = 0.0f;

                yebisPlugin.Lens.Vignette.Enable = true;

                yebisPlugin.Lens.Distortion.Enable = false;
                yebisPlugin.Lens.Distortion.Power = 0.2f;
                yebisPlugin.Lens.Distortion.EdgeSmoothness = 0.2f;

                yebisPlugin.DepthOfField.Enable = true;
                yebisPlugin.DepthOfField.AutoFocus = true;
                yebisPlugin.DepthOfField.Aperture = 2.0f;
                yebisPlugin.DepthOfField.ImageSensorHeight = 40.0f;

                //yebisPlugin.ColorCorrection.ColorTemperature = 4500;

                yebisPlugin.HeatShimmer.Enable = false;
                //YebisPlugin.LightShaft.Enable = true;
                //YebisPlugin.LightShaft.ScreenPosition = new Vector2(0.5f, 0.1f);
            }
#endif

            // Adds the particle system if the ParticlePlugin is used in the config
            ParticlePlugin particlePlugin;
            if (RenderConfigContext.RenderPassPlugins.TryGetValueCast("ParticlePlugin", out particlePlugin))
            {
                var particleSystem = new ParticleProcessor(particlePlugin);
                entitySystem.Processors.Add(particleSystem);
            }
        }
Пример #19
0
        public void RegisterRenderSystem(IRenderSystem system, System.Type type, RenderStage renderStage, System.Type renderBefore = null,
                                         System.Type renderAfter = null)
        {
            switch (renderStage)
            {
            case RenderStage.BeforeRender:
                RegisterSystemTo(beforeRenderSystems, system, type, renderBefore, renderAfter);
                break;

            case RenderStage.RenderShadows:
                RegisterSystemTo(renderShadowsSystems, system, type, renderBefore, renderAfter);
                break;

            case RenderStage.AfterRenderShadows:
                RegisterSystemTo(afterRenderShadowsSystems, system, type, renderBefore, renderAfter);
                break;

            case RenderStage.RenderOpaques:
                RegisterSystemTo(renderOpaquesSystems, system, type, renderBefore, renderAfter);
                break;

            case RenderStage.AfterRenderOpaques:
                RegisterSystemTo(afterRenderOpaquesSystems, system, type, renderBefore, renderAfter);
                break;

            case RenderStage.RenderSkybox:
                RegisterSystemTo(renderSkyboxSystems, system, type, renderBefore, renderAfter);
                break;

            case RenderStage.AfterRenderSkybox:
                RegisterSystemTo(afterRenderSkyboxSystems, system, type, renderBefore, renderAfter);
                break;

            case RenderStage.RenderTransparents:
                RegisterSystemTo(renderTransparentsSystems, system, type, renderBefore, renderAfter);
                break;

            case RenderStage.AfterRenderTransparents:
                RegisterSystemTo(afterRenderTransparentsSystems, system, type, renderBefore, renderAfter);
                break;

            case RenderStage.RenderPostProcessing:
                RegisterSystemTo(renderPostProcessingSystems, system, type, renderBefore, renderAfter);
                break;

            case RenderStage.AfterRenderPostProcessing:
                RegisterSystemTo(afterRenderPostProcessingSystems, system, type, renderBefore, renderAfter);
                break;

            case RenderStage.RenderUi:
                RegisterSystemTo(renderUiSystems, system, type, renderBefore, renderAfter);
                break;

            case RenderStage.AfterRenderUi:
                RegisterSystemTo(afterRenderUiSystems, system, type, renderBefore, renderAfter);
                break;

            case RenderStage.AfterRender:
                RegisterSystemTo(afterRenderSystems, system, type, renderBefore, renderAfter);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(renderStage), renderStage, null);
            }
        }
Пример #20
0
 public void AddRenderSystem(IRenderSystem system)
 {
     _renderSystems.Add(system);
 }
Пример #21
0
 public void RemoveRenderSystem(IRenderSystem system)
 {
     _renderSystems.Remove(system);
 }
 protected override void OnSystemAdd()
 {
     renderSystem = Services.GetSafeServiceAs <IRenderSystem>();
 }
Пример #23
0
 public void AddRenderSystem(IRenderSystem system)
 {
     system.Window = this.window;
     renderSystems.Add(system);
 }