Example #1
0
      /// <summary>
      /// Render
      /// </summary>
      /// <param name="shader">Shader</param>
      /// <param name="shaderTechnique">Shader technique</param>
      public void Render(ShaderEffect shader, //obs: string shaderTechnique,
	Matrix worldMatrix)
      {
          BaseGame.WorldMatrix = worldMatrix;
          BaseGame.Device.VertexDeclaration = TangentVertex.VertexDeclaration;
          shader.RenderSinglePassShader(
              material,
              //obs: shaderTechnique,
              new BaseGame.RenderDelegate(DrawPlaneVertices));
          BaseGame.WorldMatrix = Matrix.Identity;
      }
Example #2
0
 /// <summary>
 /// Render
 /// </summary>
 /// <param name="shader">Shader</param>
 /// <param name="shaderTechnique">Shader technique</param>
 public void Render(ShaderEffect shader)
 {
     Render(shader, Matrix.CreateTranslation(pos));
 }
Example #3
0
        /// <summary>
        /// Load a material from inside of a material node for loading collada
        /// models.
        /// </summary>
        /// <param name="materialNode">Material node</param>
        /// <param name="textures">Textures</param>
        /// <param name="effectsIds">Effects ids</param>
        internal Material(XmlNode materialNode,
			Dictionary<string, Texture> textures,
			Dictionary<string, string> effectIds)
        {
            name = XmlHelper.GetXmlAttribute(materialNode, "id");

            // Get all instance effects
            XmlNode instEffect =
                XmlHelper.GetChildNode(materialNode, "instance_effect");
            foreach (XmlNode setparam in instEffect)
            {
                float[] vec;
                switch (XmlHelper.GetXmlAttribute(setparam, "ref"))
                {
                    case "ambientColor":
                        vec = StringHelper.ConvertStringToFloatArray(
                            XmlHelper.GetChildNode(setparam, "float4").InnerText);
                        ambientColor = ColorHelper.ColorFromFloatArray(vec);
                        // Make sure ambientColor is at least DefaultAmbientColor.
                        // Modelers often save way to dark ambient colors.
                        if (ambientColor.R < DefaultAmbientColor.R)
                            ambientColor = DefaultAmbientColor;
                        break;
                    case "diffuseColor":
                        vec = StringHelper.ConvertStringToFloatArray(
                            XmlHelper.GetChildNode(setparam, "float4").InnerText);
                        diffuseColor = ColorHelper.ColorFromFloatArray(vec);
                        break;
                    case "specularColor":
                        vec = StringHelper.ConvertStringToFloatArray(
                            XmlHelper.GetChildNode(setparam, "float4").InnerText);
                        specularColor = ColorHelper.ColorFromFloatArray(vec);
                        break;
                    case "specularPower":
                        specularPower = Convert.ToSingle(
                            XmlHelper.GetChildNode(setparam, "float").InnerText,
                            NumberFormatInfo.InvariantInfo);
                        break;
                    case "diffuseTexture":
                        XmlNode initFromNode =
                            XmlHelper.GetChildNode(setparam, "init_from");
                        if (initFromNode != null)
                            diffuseTexture = textures[initFromNode.InnerText];
                        break;
                    case "normalTexture":
                        initFromNode = XmlHelper.GetChildNode(setparam, "init_from");
                        if (initFromNode != null)
                            normalTexture = textures[initFromNode.InnerText];
                        break;
                    default:
                        //silent ignore
                        break;
                } // switch
            } // foreach (setparam)

            string effectnodename =
                XmlHelper.GetXmlAttribute(instEffect, "url").Substring(1);
            if (effectnodename.Length > 0 &&
                effectIds.ContainsKey(effectnodename))
            {
                string shaderName =
                    StringHelper.ExtractFilename(effectIds[effectnodename], true);
                if (String.IsNullOrEmpty(shaderName) == false)
                {
                    shader = new ShaderEffect(shaderName);
                } // if (String.IsNullOrEmpty)
            } // if (effectnodename.Length)
        }