Exemplo n.º 1
0
        public void Bind(ShaderParam param, PluginBase.GameObjects.Material mat)
        {
            _mat = mat;
            bsParameter.DataSource = param;

            var textures = _mat.Root.FindChildrenWithInterface<ITexture>();
            var names = new List<string>();
            foreach (var texture in textures)
            {
                names.Add(texture.Name);
            }
            bsTextures.DataSource = names;
        }
Exemplo n.º 2
0
 public void AddParameter(ShaderParam param)
 {
     _parameters.Add(param);
 }
Exemplo n.º 3
0
 public void Bind(ShaderParam param, PluginBase.GameObjects.Material mat)
 {
     _mat = mat;
     bsParameter.DataSource = param;
 }
Exemplo n.º 4
0
 public void CopyFrom(ShaderParam param)
 {
     Type = param.Type;
     Name = param.Name;
     LongName = param.LongName;
     IntValue = param.IntValue;
     FloatValue = param.FloatValue;
     Vec2Value = param.Vec2Value;
     Vec3Value = param.Vec3Value;
     Vec4Value = param.Vec4Value;
     MatrixValue = param.MatrixValue;
     TexUnit = param.TexUnit;
     TextureName = param.TextureName;
 }
Exemplo n.º 5
0
 public ShaderParam Clone()
 {
     var result = new ShaderParam();
     result.CopyFrom(this);
     return result;
 }
Exemplo n.º 6
0
 private void ApplyParameter(ShaderParam param)
 {
     switch (param.Type)
     {
         case ShaderParamType.Int: GL.Uniform1(param.Location, param.IntValue); break;
         case ShaderParamType.Float: GL.Uniform1(param.Location, param.FloatValue); break;
         case ShaderParamType.Texture: GL.Uniform1(param.Location, (int)(param.TexUnit) - (int)(TextureUnit.Texture0)); break;
         case ShaderParamType.Vec2: GL.Uniform2(param.Location, ref param.Vec2Value); break;
         case ShaderParamType.Vec3: GL.Uniform3(param.Location, ref param.Vec3Value); break;
         case ShaderParamType.Vec4:
         case ShaderParamType.Color: GL.Uniform4(param.Location, ref param.Vec4Value); break;
         case ShaderParamType.Model: GL.UniformMatrix4(param.Location, 1, false, ref param.MatrixValue.Row0.X); break;
         case ShaderParamType.Camera: GL.UniformMatrix4(param.Location, 1, false, ref param.MatrixValue.Row0.X); break;
         case ShaderParamType.Time: GL.Uniform1(param.Location, param.FloatValue); break;
     }
 }
Exemplo n.º 7
0
 public void CopyParameter(ShaderParam param)
 {
     _parameters[param.Name].CopyFrom(param);
     ApplyParameter(_parameters[param.Name]);
 }
Exemplo n.º 8
0
 public override void ReadXml(XmlReader reader)
 {
     base.ReadXml(reader);
     _shader = reader.GetAttribute("Shader");
     _parameterShader = _shader;
     if (reader.GetAttribute("DepthTest") != null) _depthTest = reader.GetAttribute("DepthTest").ToUpper() == "TRUE";
     if (reader.GetAttribute("AlphaBlend") != null) _alphaBlend = reader.GetAttribute("AlphaBlend").ToUpper() == "TRUE";
     if (reader.GetAttribute("SmoothLines") != null) _smoothLines = reader.GetAttribute("SmoothLines").ToUpper() == "TRUE";
     if (reader.GetAttribute("MinFilter") != null) _minFilter = (TextureMinFilter)Enum.Parse(typeof(TextureMinFilter), reader.GetAttribute("MinFilter"));
     if (reader.GetAttribute("MagFilter") != null) _magFilter = (TextureMagFilter)Enum.Parse(typeof(TextureMagFilter), reader.GetAttribute("MagFilter"));
     while (reader.Name != "Parameters") reader.Read();
     _parameters.Clear();
     if (!reader.IsEmptyElement)
     {
         while (reader.Read() && (reader.NodeType != XmlNodeType.EndElement))
         {
             if (reader.NodeType == XmlNodeType.Element)
             {
                 var p = new ShaderParam();
                 p.Type = (ShaderParamType)Enum.Parse(typeof(ShaderParamType), reader.Name); ;
                 p.Name = reader.GetAttribute("Name");
                 p.LongName = reader.GetAttribute("Desc");
                 switch (p.Type)
                 {
                     case ShaderParamType.Int:
                         p.IntValue = Convert.ToInt32(reader.GetAttribute("Value"));
                         break;
                     case ShaderParamType.Float:
                         p.FloatValue = Convert.ToSingle(reader.GetAttribute("Value"));
                         break;
                     case ShaderParamType.Vec2:
                         p.Vec2Value = new Vector2(
                             Convert.ToSingle(reader.GetAttribute("X")),
                             Convert.ToSingle(reader.GetAttribute("Y"))
                         );
                         break;
                     case ShaderParamType.Vec3:
                         p.Vec3Value = new Vector3(
                             Convert.ToSingle(reader.GetAttribute("X")),
                             Convert.ToSingle(reader.GetAttribute("Y")),
                             Convert.ToSingle(reader.GetAttribute("Z"))
                         );
                         break;
                     case ShaderParamType.Vec4:
                         p.Vec4Value = new Vector4(
                             Convert.ToSingle(reader.GetAttribute("X")),
                             Convert.ToSingle(reader.GetAttribute("Y")),
                             Convert.ToSingle(reader.GetAttribute("Z")),
                             Convert.ToSingle(reader.GetAttribute("W"))
                         );
                         break;
                     case ShaderParamType.Texture:
                         p.TextureName = reader.GetAttribute("Texture");
                         p.TexUnit = (TextureUnit)Enum.Parse(typeof(TextureUnit), reader.GetAttribute("TextureUnit"));
                         break;
                     case ShaderParamType.Color:
                         p.Vec4Value = new Vector4(
                             Convert.ToSingle(reader.GetAttribute("R")),
                             Convert.ToSingle(reader.GetAttribute("G")),
                             Convert.ToSingle(reader.GetAttribute("B")),
                             Convert.ToSingle(reader.GetAttribute("A"))
                         );
                         break;
                 }
                 _parameters.Add(p);
             }
         }
     }
 }