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
 private void parseTextures(XmlNode node, Material m)
 {
     m.TextureNames[0] = m.TextureNames[1] = m.TextureNames[2] = m.TextureNames[3] = "";
     foreach (XmlNode textureNode in node.ChildNodes)
     {
         if (textureNode.Name == "Texture")
         {
             int textureUnit = 0;
             String texName = "";
             foreach (XmlAttribute attrib in textureNode.Attributes)
             {
                 if (attrib.Name == "TextureUnit")
                 {
                     textureUnit = Int32.Parse(attrib.Value);
                 }
                 if (attrib.Name == "Texture")
                 {
                     texName = attrib.Value;
                 }
             }
             if (textureUnit >= 0 && textureUnit < 4)
             {
                 m.TextureNames[textureUnit] = texName;
             }
         }
     }
 }
Esempio n. 3
0
 private void parseEffect(XmlNode node, Material m)
 {
     foreach (XmlNode effectNode in node.ChildNodes)
     {
         if (effectNode.Name == "EffectName")
         {
             m.EffectName = effectNode.InnerText;
         }
         else if (effectNode.Name == "Technique")
         {
             m.Technique = effectNode.InnerText;
         }
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Set a shader parameter to some data provided by CBero
 /// </summary>
 /// <param name="effectParameter">the shader parameter</param>
 /// <param name="semantic">the type of data requested</param>
 public void setBuiltInShaderParameter(EffectParameter effectParameter, Material.ShaderParameterSemantic semantic)
 {
     if (effectParameter == null)
         return;
     switch (semantic)
     {
         case Material.ShaderParameterSemantic.MODEL_MATRIX:
             {
                 effectParameter.SetValue(RenderState.m_currentWorld.Peek());
                 break;
             }
         case Material.ShaderParameterSemantic.MODEL_INV_MATRIX:
             {
                 Matrix inv = Matrix.Invert(RenderState.m_currentWorld.Peek());
                 effectParameter.SetValue(inv);
                 break;
             }
         case Material.ShaderParameterSemantic.MODEL_INV_TRANS_MATRIX:
             {
                 Matrix invTrans = Matrix.Transpose(Matrix.Invert(RenderState.m_currentWorld.Peek()));
                 effectParameter.SetValue(invTrans);
                 break;
             }
         case Material.ShaderParameterSemantic.MODEL_TRANS_MATRIX:
             {
                 Matrix trans = Matrix.Transpose(RenderState.m_currentWorld.Peek());
                 effectParameter.SetValue(trans);
                 break;
             }
         case Material.ShaderParameterSemantic.VIEW_MATRIX:
             {
                 effectParameter.SetValue(RenderState.m_currentView.Peek());
                 break;
             }
         case Material.ShaderParameterSemantic.VIEW_INV_MATRIX:
             {
                 Matrix inv = Matrix.Invert(RenderState.m_currentView.Peek());
                 effectParameter.SetValue(inv);
                 break;
             }
         case Material.ShaderParameterSemantic.VIEW_TRANS_MATRIX:
             {
                 Matrix trans = Matrix.Transpose(RenderState.m_currentView.Peek());
                 effectParameter.SetValue(trans);
                 break;
             }
         case Material.ShaderParameterSemantic.VIEW_INV_TRANS_MATRIX:
             {
                 Matrix invTrans = Matrix.Transpose(Matrix.Invert(RenderState.m_currentView.Peek()));
                 effectParameter.SetValue(invTrans);
                 break;
             }
         case Material.ShaderParameterSemantic.PROJECTION_MATRIX:
             {
                 effectParameter.SetValue(RenderState.m_currentProj.Peek());
                 break;
             }
         case Material.ShaderParameterSemantic.VIEW_PROJECTION_MATRIX:
             {
                 Matrix viewProj = Matrix.Multiply(RenderState.m_currentView.Peek(), RenderState.m_currentProj.Peek());
                 effectParameter.SetValue(viewProj);
                 break;
             }
         case Material.ShaderParameterSemantic.MODEL_VIEW_PROJECTION_MATRIX:
             {
                 Matrix mvp = Matrix.Multiply(Matrix.Multiply(RenderState.m_currentWorld.Peek(), RenderState.m_currentView.Peek()), RenderState.m_currentProj.Peek());
                 effectParameter.SetValue(mvp);
                 break;
             }
         case Material.ShaderParameterSemantic.BONE_TRANSFORMS:
             {
                 Matrix[] bone;
                 IRenderable3D renderable = RenderState.m_currentRenderable.Peek();
                 if (renderable is SkinnedRenderable3D)
                 {
                     SkinnedRenderable3D skinned = renderable as SkinnedRenderable3D;
                     bone = skinned.GetSkinTransforms();
                 }
                 else
                 {
                     bone = new Matrix[1] { Matrix.Identity };
                 }
                 effectParameter.SetValue(bone);
                 break;
             }
         case Material.ShaderParameterSemantic.TEXTURE2D0:
             {
                 effectParameter.SetValue(RenderState.m_currentTexture[0].Peek());
                 break;
             }
         case Material.ShaderParameterSemantic.TEXTURE2D1:
             {
                 effectParameter.SetValue(RenderState.m_currentTexture[1].Peek());
                 break;
             }
         case Material.ShaderParameterSemantic.TEXTURE2D2:
             {
                 effectParameter.SetValue(RenderState.m_currentTexture[2].Peek());
                 break;
             }
         case Material.ShaderParameterSemantic.TEXTURE2D3:
             {
                 effectParameter.SetValue(RenderState.m_currentTexture[3].Peek());
                 break;
             }
         case Material.ShaderParameterSemantic.AMBIENTLIGHTING:
             {
                 effectParameter.SetValue(RenderState.GetAmbientLighting().ToVector3());
                 break;
             }
         case Material.ShaderParameterSemantic.BACKGROUNDCOLOR:
             {
                 effectParameter.SetValue(RenderState.GetClearColor().ToVector3());
                 break;
             }
         case Material.ShaderParameterSemantic.FOGCOLOR:
             {
                 effectParameter.SetValue(RenderState.GetFogColor().ToVector3());
                 break;
             }
         // TODO implement USER_DEFINED_*
     }
 }
Esempio n. 5
0
        private void ApplyMaterial(Material material)
        {
            m_currentEffect.Peek().CurrentTechnique = m_currentEffect.Peek().Techniques[material.Technique];
            m_currentEffectPass = m_currentEffect.Peek().CurrentTechnique.Passes.First();
            // apply textures
            for (int i = 0; i < RenderManager.MAX_TEXTURES; ++i)
            {
                setTexture(material.Textures[i], i);
            }

            // apply shader data
            ApplyEffectParameterPerFrame();
        }
Esempio n. 6
0
 public void PushMaterial(Material mat)
 {
     if (mat == null)
     {
         mat = RenderManager.BasicEffectMaterial;
     }
     m_currentMaterial.Push(mat);
     m_currentEffect.Push(mat.Effect);
     ApplyMaterial(mat);
 }
Esempio n. 7
0
        public override void doInitialize()
        {
            // get material
            m_material = new Material();
            setTexture(m_materialName);

            // add to rendermanager
            RenderManager renderMan = Owner.Game.Services.GetService(typeof(RenderManager)) as RenderManager;
            renderMan.addRenderable(this);

            // get position
            IPosition2D pos = Owner.getFirst(typeof(IPosition2D)) as IPosition2D;
            if (pos != null)
            {
                m_position = pos.Position;
                pos.Pos2DChanged += new XnaScrapCore.Core.Delegates.Position2DChangedEventHandler(PositionChanged);
            }

            // get orientation
            IOrientation2D orientation = Owner.getFirst(typeof(IOrientation2D)) as IOrientation2D;
            if (orientation != null)
            {
                m_orientation = orientation.Orientation;
                orientation.Orientation2DChanged += new XnaScrapCore.Core.Delegates.OrientationChangedEventHandler(OrientationChanged);
            }

            // get dimension
            IScale2D scale = Owner.getFirst(typeof(IScale2D)) as IScale2D;
            if (scale != null)
            {
                m_scale = scale.Scale;
                scale.Changed += new Scale2DChangedEventHandler(scale_Changed);
            }

            base.doInitialize();
        }
Esempio n. 8
0
 private void process(String xml, Material m)
 {
     XmlDocument doc = new XmlDocument();
     doc.LoadXml(xml);
     XmlNode n = doc.FirstChild;
     if (n.Name != "Material")
     {
         return;
     }
     foreach (XmlNode node in n.ChildNodes)
     {
         if (node.Name == "Textures")
         {
             parseTextures(node, m);
         }
         if (node.Name == "Effect")
         {
             parseEffect(node, m);
         }
         if (node.Name == "ParameterMap")
         {
             parseParameterMap(node, m);
         }
     }
 }
Esempio n. 9
0
 public Material Compile(MaterialUncompiled input)
 {
     Material ret = new Material();
     process(input.MaterialString,ret);
     return ret;
 }
Esempio n. 10
0
        public void process(String xml,Material.ParameterMapping mapping)
        {
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml);
            XmlNode n = doc.FirstChild;
            if (n.Name != "ParameterMapping")
            {
                return;
            }
            foreach (XmlNode node in n.ChildNodes)
            {
                if (node.Name == "Mapping")
                {
                    foreach (XmlAttribute attrib in node.Attributes)
                    {

                    }
                }
            }
        }
Esempio n. 11
0
        private void processMaterial(Material mat)
        {
            for (int i = 0; i < mat.TextureNames.Length; ++i)
            {
                if (!string.IsNullOrEmpty(mat.TextureNames[i]))
                {
                    if (!m_textures.TryGetValue(mat.TextureNames[i], out mat.Textures[i]))
                    {
                        // try to load the texture now
                        loadTexture2D(mat.TextureNames[i]);

                        m_textures.TryGetValue(mat.TextureNames[i], out mat.Textures[i]);
                    }
                }
                else
                {
                    break;
                }
            }

            Effect effect;
            if (m_effects.TryGetValue(mat.EffectName, out effect))
            {
                mat.Effect = effect;
                mat.Effect.CurrentTechnique = mat.Effect.Techniques[mat.Technique];
            }
        }
Esempio n. 12
0
 private void processMapping(Material.ParameterMapping mapping)
 {
 }