Esempio n. 1
0
 private void parseParameterMap(XmlNode node, Material m)
 {
     foreach (XmlNode parameter in node.ChildNodes)
     {
         if (parameter.Name == "Parameter")
         {
             Material.ParameterMapping mapping = new Material.ParameterMapping();
             foreach (XmlAttribute attrib in parameter.Attributes)
             {
                 if (attrib.Name == "Name")
                 {
                     mapping.name = attrib.Value;
                 }
                 else if (attrib.Name == "Value")
                 {
                     mapping.value = attrib.Value;
                 }
                 else if (attrib.Name == "perInstance")
                 {
                     mapping.perInstance = bool.Parse(attrib.Value);
                 }
                 else if (attrib.Name == "Semantic")
                 {
                     Enum.TryParse(attrib.Value, out mapping.semantic);
                 }
             }
             if (mapping.name.Length > 0)
             {
                 m.ParameterMappings.Add(mapping);
             }
         }
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // register elements
            IObjectBuilder objectBuilder = Game.Services.GetService(typeof(IObjectBuilder)) as IObjectBuilder;
            if (objectBuilder != null)
            {
                registerElements(objectBuilder);
            }

            // performance
            PerformanceMonitor perfMon = Game.Services.GetService(typeof(PerformanceMonitor)) as PerformanceMonitor;
            if (perfMon != null)
            {
                m_mainTimer = perfMon.addPerformanceMeter(new XnaScrapId("CBeroRenderManager"));
                m_sceneTimer = m_mainTimer.addSubTimer("Scene");
                m_overlayTimer = m_mainTimer.addSubTimer("Overlays");
            }

            #if WINDOWS
            // register REST stuff
            NetCtrlService netCtrlService = Game.Services.GetService(typeof(NetCtrlService)) as NetCtrlService;
            if (netCtrlService != null)
            {
                netCtrlService.AddServiceNode(new RenderManagerNode(this), this);
            }
            #endif
            base.Initialize();
            m_spriteBatch = new SpriteBatch(GraphicsDevice);
            GraphicsDevice.DepthStencilState = DepthStencilState.Default;

            #region materials
            BasicEffect basicEffect = new BasicEffect(GraphicsDevice);
            basicEffect.EnableDefaultLighting();
            basicEffect.PreferPerPixelLighting = true;
            m_basicEffectMaterial.Effect = basicEffect;
            m_basicEffectMaterial.Technique = basicEffect.Techniques.First().Name;
            Material.ParameterMapping worldviewprojection = new Material.ParameterMapping();
            worldviewprojection.name = "WorldViewProj";
            worldviewprojection.perInstance = true;
            worldviewprojection.semantic = Material.ShaderParameterSemantic.MODEL_VIEW_PROJECTION_MATRIX;
            m_basicEffectMaterial.ParameterMappings.Add(worldviewprojection);

            SkinnedEffect skinnedEffect = new SkinnedEffect(GraphicsDevice);
            skinnedEffect.EnableDefaultLighting();
            m_skinnedEffectMaterial.Effect = skinnedEffect;
            m_skinnedEffectMaterial.Technique = skinnedEffect.Techniques.First().Name;

            RenderState.PushMaterial(m_basicEffectMaterial);
            #endregion

            #region effects
            m_defaultEffect = new CBeroEffect(this);
            m_defaultCollection = new RenderTargetCollection(DefaultRenderTarget.GetInstance().Id, new IRenderTarget[] { DefaultRenderTarget.GetInstance() });
            m_defaultCollection.Effect = m_defaultEffect;
            m_defaultEffect.AddPass(new RenderSceneWithMaterialsPass(this, m_defaultCollection));
            m_defaultEffect.AddPass(new RenderOverlaysPass(this, m_defaultCollection));

            // add DefaultRenderTarget
            m_renderTargets.Add(DefaultRenderTarget.GetInstance().Id, m_defaultCollection);
            #endregion
        }
Esempio n. 3
0
 public Material.ParameterMapping Compile(ParameterMappingUncompiled input)
 {
     Material.ParameterMapping mapping = new Material.ParameterMapping();
     process(input.MappingString, mapping);
     return mapping;
 }