GetMatrix() public method

Get a named matrix value from the shader.

public GetMatrix ( int nameID ) : Matrix4x4
nameID int The name ID of the property retrieved by Shader.PropertyToID.
return Matrix4x4
Esempio n. 1
0
 static public int GetMatrix(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (matchType(l, argc, 2, typeof(int)))
         {
             UnityEngine.Material self = (UnityEngine.Material)checkSelf(l);
             System.Int32         a1;
             checkType(l, 2, out a1);
             var ret = self.GetMatrix(a1);
             pushValue(l, true);
             pushValue(l, ret);
             return(2);
         }
         else if (matchType(l, argc, 2, typeof(string)))
         {
             UnityEngine.Material self = (UnityEngine.Material)checkSelf(l);
             System.String        a1;
             checkType(l, 2, out a1);
             var ret = self.GetMatrix(a1);
             pushValue(l, true);
             pushValue(l, ret);
             return(2);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
    static int GetMatrix(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Material), typeof(int)))
            {
                UnityEngine.Material obj = (UnityEngine.Material)ToLua.ToObject(L, 1);
                int arg0 = (int)LuaDLL.lua_tonumber(L, 2);
                UnityEngine.Matrix4x4 o = obj.GetMatrix(arg0);
                ToLua.PushValue(L, o);
                return(1);
            }
            else if (count == 2 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Material), typeof(string)))
            {
                UnityEngine.Material obj = (UnityEngine.Material)ToLua.ToObject(L, 1);
                string arg0             = ToLua.ToString(L, 2);
                UnityEngine.Matrix4x4 o = obj.GetMatrix(arg0);
                ToLua.PushValue(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.Material.GetMatrix"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
	public List<StoredValue> GetValues(Material m)
	{
		var list = GetShaderProperties(m);
		var output = new List<StoredValue>();
		foreach(var p in list)
		{
			var o = new StoredValue { Property = p };
			output.Add(o);
			switch(p.type)
			{
			case MaterialProperty.PropertyType.color:
				o.Value = m.GetColor(p.name);
				break;
			case MaterialProperty.PropertyType.real:
				o.Value = m.GetFloat(p.name);
				break;
			case MaterialProperty.PropertyType.texture:
				o.Value = m.GetTexture(p.name);
				break;
			case MaterialProperty.PropertyType.vector:
				o.Value = m.GetVector(p.name);
				break;
			case MaterialProperty.PropertyType.textureOffset:
				o.Value = m.GetTextureOffset(p.name);
				break;
			case MaterialProperty.PropertyType.textureScale:
				o.Value = m.GetTextureScale(p.name);
				break;
			case MaterialProperty.PropertyType.matrix:
				o.Value = m.GetMatrix(p.name);
				break;
			}
		}
		return output;
	}
Esempio n. 4
0
 static public int GetMatrix(IntPtr l)
 {
     try{
         if (matchType(l, 2, typeof(System.String)))
         {
             UnityEngine.Material self = (UnityEngine.Material)checkSelf(l);
             System.String        a1;
             checkType(l, 2, out a1);
             UnityEngine.Matrix4x4 ret = self.GetMatrix(a1);
             pushValue(l, ret);
             return(1);
         }
         else if (matchType(l, 2, typeof(System.Int32)))
         {
             UnityEngine.Material self = (UnityEngine.Material)checkSelf(l);
             System.Int32         a1;
             checkType(l, 2, out a1);
             UnityEngine.Matrix4x4 ret = self.GetMatrix(a1);
             pushValue(l, ret);
             return(1);
         }
         LuaDLL.luaL_error(l, "No matched override function to call");
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
	public List<MaterialProperty> GetShaderProperties(Material material)
	{
		if(cache.ContainsKey(material.shader.name))
			return cache[material.shader.name];
		
		var list = new List<MaterialProperty>();
		foreach(var m in MaterialProperties)
		{
			if(material.HasProperty(m.name))
			{
				if(m.type == MaterialProperty.PropertyType.unknown)
				{
					try
					{
						var p = material.GetColor(m.name);
						if(p != transparent)
						    list.Add( new MaterialProperty { name = m.name, type = MaterialProperty.PropertyType.color });
					}
					catch
					{
					}
					try
					{
						var p = material.GetFloat(m.name);
						if(p != 0)
						    list.Add( new MaterialProperty { name = m.name, type = MaterialProperty.PropertyType.real });
					}
					catch
					{
					}
					try
					{
						var p = material.GetTexture(m.name);
						if(p!=null)
						    list.Add( new MaterialProperty { name = m.name, type = MaterialProperty.PropertyType.texture });
					}
					catch
					{
					}
					try
					{
						var p = material.GetVector(m.name);
						if(p != Vector4.zero)
						    list.Add( new MaterialProperty { name = m.name, type = MaterialProperty.PropertyType.vector });
					}
					catch
					{
						
					}
					try
					{
						var p = material.GetMatrix(m.name);
						if(p != Matrix4x4.identity)
						     list.Add( new MaterialProperty { name = m.name, type = MaterialProperty.PropertyType.matrix });
					}
					catch
					{
					}
					try
					{
						var p = material.GetTextureOffset(m.name);
						if(p != Vector2.zero)
						     list.Add( new MaterialProperty { name = m.name, type = MaterialProperty.PropertyType.textureOffset });
					}
					catch
					{
					}
					try
					{
						var p = material.GetTextureScale(m.name);
						if(p != Vector2.zero)
						     list.Add( new MaterialProperty { name = m.name, type = MaterialProperty.PropertyType.textureScale });
					}
					catch
					{
					}
				}
				else
				{
					list.Add(m);
				}

					
			}
			
		}
		cache[material.shader.name] = list;
		return list;
	}
        private void CloneToBuffer(Material mat, CommandBuffer buf)
        {
            foreach (KeyValuePair<object, object> field in cache)
            {
                object obj = field.Value;
                //float
                int id = (int)field.Key;
                if (obj.GetType() == typeof(float))
                {
                    float value = mat.GetFloat(id);
                    buf.SetGlobalFloat(id, value);
                }
                //Color
                else if (obj.GetType() == typeof(Color))
                {
                    Color value = mat.GetColor(id);
                    buf.SetGlobalColor(id, value);
                }
                //Color32
                else if (obj.GetType() == typeof(Color32))
                {
                    Color value = mat.GetColor(id);
                    buf.SetGlobalColor(id, value);
                }//Vector2
                else if (obj.GetType() == typeof(Vector2))
                {
                    Vector4 value = mat.GetVector(id);
                    buf.SetGlobalVector(id, value);
                }
                //Vector3
                else if (obj.GetType() == typeof(Vector3))
                {
                    Vector4 value = mat.GetVector(id);
                    buf.SetGlobalVector(id, value);
                }
                //Vector4
                else if (obj.GetType() == typeof(Vector4))
                {
                    Vector4 value = mat.GetVector(id);
                    buf.SetGlobalVector(id, value);
                }
                //Matrix
                else if (obj.GetType() == typeof(Matrix4x4))
                {
                    Matrix4x4 value = mat.GetMatrix(id);
                    buf.SetGlobalMatrix(id, value);
                }

            }
        }