Просмотр исходного кода

C# versions of Shader and Material resources
Some fixes for non 2d texture, plain text and script code C# resources

Marko Pintera 10 лет назад
Родитель
Сommit
b74cf06aa0

+ 1 - 0
BansheeMono/Include/BsMonoArray.h

@@ -2,6 +2,7 @@
 
 #include "BsMonoPrerequisites.h"
 #include "BsScriptMeta.h"
+#include "BsMonoManager.h"
 #include <mono/jit/jit.h>
 
 namespace BansheeEngine

+ 33 - 0
BansheeMono/Source/BsMonoArray.cpp

@@ -1,6 +1,7 @@
 #include "BsMonoArray.h"
 #include "BsMonoManager.h"
 #include "BsMonoClass.h"
+#include "BsMonoUtil.h"
 
 namespace BansheeEngine
 {
@@ -22,8 +23,40 @@ namespace BansheeEngine
 		mInternal = mono_array_new(MonoManager::instance().getDomain(), klass, size);
 	}
 
+	template<>
+	String ScriptArray::get<String>(UINT32 idx)
+	{
+		return MonoUtil::monoToString(mono_array_get(mInternal, MonoString*, idx));
+	}
+
+	template<>
+	WString ScriptArray::get<WString>(UINT32 idx)
+	{
+		return MonoUtil::monoToWString(mono_array_get(mInternal, MonoString*, idx));
+	}
+
+	template<>
+	void ScriptArray::set<String>(UINT32 idx, const String& value)
+	{
+		MonoString* monoString = MonoUtil::stringToMono(MonoManager::instance().getDomain(), value);
+		mono_array_set(mInternal, MonoString*, idx, monoString);
+	}
+
+	template<>
+	void ScriptArray::set<WString>(UINT32 idx, const WString& value)
+	{
+		MonoString* monoString = MonoUtil::wstringToMono(MonoManager::instance().getDomain(), value);
+		mono_array_set(mInternal, MonoString*, idx, monoString);
+	}
+
 	UINT32 ScriptArray::size() const
 	{
 		return (UINT32)mono_array_length(mInternal);
 	}
+
+	template BS_MONO_EXPORT String ScriptArray::get(UINT32 idx);
+	template BS_MONO_EXPORT WString ScriptArray::get(UINT32 idx);
+
+	template BS_MONO_EXPORT void ScriptArray::set(UINT32 idx, const String& value);
+	template BS_MONO_EXPORT void ScriptArray::set(UINT32 idx, const WString& value);
 }

+ 2 - 0
MBansheeEngine/MBansheeEngine.csproj

@@ -85,6 +85,7 @@
     <Compile Include="InputConfiguration.cs" />
     <Compile Include="LocString.cs" />
     <Compile Include="ManagedResource.cs" />
+    <Compile Include="Material.cs" />
     <Compile Include="Math\AABox.cs" />
     <Compile Include="Math\BsRect3.cs" />
     <Compile Include="Math\Degree.cs" />
@@ -118,6 +119,7 @@
     <Compile Include="SerializableProperty.cs" />
     <Compile Include="SerializeObject.cs" />
     <Compile Include="SerializeField.cs" />
+    <Compile Include="Shader.cs" />
     <Compile Include="SpriteTexture.cs" />
     <Compile Include="StringTable.cs" />
     <Compile Include="Texture.cs" />

+ 219 - 0
MBansheeEngine/Material.cs

@@ -0,0 +1,219 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Text;
+
+namespace BansheeEngine
+{
+    public class Material : Resource
+    {
+        public Material()
+        {
+            Internal_CreateInstance(this, IntPtr.Zero);
+        }
+
+        public Material(Shader shader)
+        {
+            IntPtr nativeShader = IntPtr.Zero;
+            if (shader != null)
+                nativeShader = shader.GetCachedPtr();
+
+            Internal_CreateInstance(this, nativeShader);
+        }
+
+        public Shader Shader
+        {
+            get { return Internal_GetShader(mCachedPtr); }
+            set
+            {
+                IntPtr nativeShader = IntPtr.Zero;
+                if (value != null)
+                    nativeShader = value.GetCachedPtr();
+
+                Internal_SetShader(mCachedPtr, nativeShader); 
+            }
+        }
+
+        public void SetFloat(string name, float value)
+        {
+            Internal_SetFloat(mCachedPtr, name, value);
+        }
+
+        public void SetVector2(string name, Vector2 value)
+        {
+            Internal_SetVector2(mCachedPtr, name, value);
+        }
+
+        public void SetVector3(string name, Vector3 value)
+        {
+            Internal_SetVector3(mCachedPtr, name, value);
+        }
+
+        public void SetVector4(string name, Vector4 value)
+        {
+            Internal_SetVector4(mCachedPtr, name, value);
+        }
+
+        public void SetMatrix3(string name, Matrix3 value)
+        {
+            Internal_SetMatrix3(mCachedPtr, name, value);
+        }
+
+        public void SetMatrix4(string name, Matrix4 value)
+        {
+            Internal_SetMatrix4(mCachedPtr, name, value);
+        }
+
+        public void SetColor(string name, Color value)
+        {
+            Internal_SetColor(mCachedPtr, name, value);
+        }
+
+        public void SetTexture2D(string name, Texture2D value)
+        {
+            IntPtr texturePtr = IntPtr.Zero;
+            if (value != null)
+                texturePtr = value.GetCachedPtr();
+
+            Internal_SetTexture2D(mCachedPtr, name, texturePtr);
+        }
+
+        public void SetTexture3D(string name, Texture3D value)
+        {
+            IntPtr texturePtr = IntPtr.Zero;
+            if (value != null)
+                texturePtr = value.GetCachedPtr();
+
+            Internal_SetTexture3D(mCachedPtr, name, texturePtr);
+        }
+
+        public void SetTextureCube(string name, TextureCube value)
+        {
+            IntPtr texturePtr = IntPtr.Zero;
+            if (value != null)
+                texturePtr = value.GetCachedPtr();
+
+            Internal_SetTextureCube(mCachedPtr, name, texturePtr);
+        }
+
+        public float GetFloat(string name)
+        {
+            return Internal_GetFloat(mCachedPtr, name);
+        }
+
+        public Vector2 GetVector2(string name)
+        {
+            return Internal_GetVector2(mCachedPtr, name);
+        }
+
+        public Vector3 GetVector3(string name)
+        {
+            return Internal_GetVector3(mCachedPtr, name);
+        }
+
+        public Vector4 GetVector4(string name)
+        {
+            return Internal_GetVector4(mCachedPtr, name);
+        }
+
+        public Matrix3 GetMatrix3(string name)
+        {
+            return Internal_GetMatrix3(mCachedPtr, name);
+        }
+
+        public Matrix4 GetMatrix4(string name)
+        {
+            return Internal_GetMatrix4(mCachedPtr, name);
+        }
+
+        public Color GetColor(string name)
+        {
+            return Internal_GetColor(mCachedPtr, name);
+        }
+
+        public Texture2D GetTexture2D(string name)
+        {
+            return Internal_GetTexture2D(mCachedPtr, name);
+        }
+
+        public Texture3D GetTexture3D(string name)
+        {
+            return Internal_GetTexture3D(mCachedPtr, name);
+        }
+
+        public TextureCube GetTextureCube(string name)
+        {
+            return Internal_GetTextureCube(mCachedPtr, name);
+        }
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_CreateInstance(Material instance, IntPtr shader);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern Shader Internal_GetShader(IntPtr nativeInstance);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetShader(IntPtr nativeInstance, IntPtr shader);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetFloat(IntPtr nativeInstance, string name, float value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetVector2(IntPtr nativeInstance, string name, Vector2 value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetVector3(IntPtr nativeInstance, string name, Vector3 value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetVector4(IntPtr nativeInstance, string name, Vector4 value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetMatrix3(IntPtr nativeInstance, string name, Matrix3 value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetMatrix4(IntPtr nativeInstance, string name, Matrix4 value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetColor(IntPtr nativeInstance, string name, Color value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetTexture2D(IntPtr nativeInstance, string name, IntPtr value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetTexture3D(IntPtr nativeInstance, string name, IntPtr value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetTextureCube(IntPtr nativeInstance, string name, IntPtr value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern float Internal_GetFloat(IntPtr nativeInstance, string name);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern Vector2 Internal_GetVector2(IntPtr nativeInstance, string name);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern Vector3 Internal_GetVector3(IntPtr nativeInstance, string name);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern Vector4 Internal_GetVector4(IntPtr nativeInstance, string name);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern Matrix3 Internal_GetMatrix3(IntPtr nativeInstance, string name);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern Matrix4 Internal_GetMatrix4(IntPtr nativeInstance, string name);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern Color Internal_GetColor(IntPtr nativeInstance, string name);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern Texture2D Internal_GetTexture2D(IntPtr nativeInstance, string name);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern Texture3D Internal_GetTexture3D(IntPtr nativeInstance, string name);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern TextureCube Internal_GetTextureCube(IntPtr nativeInstance, string name);
+    }
+}

+ 54 - 0
MBansheeEngine/Shader.cs

@@ -0,0 +1,54 @@
+using System;
+using System.Runtime.CompilerServices;
+
+namespace BansheeEngine
+{
+    // Note: This must match C++ ShaderParameterType enum
+    public enum ShaderParameterType
+    {
+        Float, Vector2, Vector3, Vector4, Color,
+        Matrix3, Matrix4, Texture2D, 
+        Texture3D, TextureCube, Sampler
+    }
+
+    public struct ShaderParameter
+    {
+        public ShaderParameter(string name, ShaderParameterType type)
+        {
+            this.name = name;
+            this.type = type;
+        }
+
+        public string name;
+        public ShaderParameterType type;
+    }
+
+    public class Shader : Resource
+    {
+        // For internal use by the runtime
+        private Shader()
+        { }
+
+        public ShaderParameter[] Parameters
+        {
+            get
+            {
+                string[] names;
+                ShaderParameterType[] types;
+
+                Internal_GetShaderParameters(mCachedPtr, out names, out types);
+
+                ShaderParameter[] parameters = new ShaderParameter[names.Length];
+                for (int i = 0; i < names.Length; i++)
+                {
+                    parameters[i] = new ShaderParameter(names[i], types[i]);
+                }
+
+                return parameters;
+            }
+        }
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_GetShaderParameters(IntPtr nativeInstance, out string[] names, out ShaderParameterType[] types);
+    }
+}

+ 49 - 1
SBansheeEditor/Source/BsGUIResourceField.cpp

@@ -238,7 +238,10 @@ namespace BansheeEngine
 			{
 			case TID_Texture:
 			{
-				if (ScriptAssemblyManager::instance().getTextureClass()->isSubClassOf(acceptedClass))
+				// TODO - Need to distinguish from 2D/3D/Cube
+				if (ScriptAssemblyManager::instance().getTexture2DClass()->isSubClassOf(acceptedClass) ||
+					ScriptAssemblyManager::instance().getTexture3DClass()->isSubClassOf(acceptedClass) ||
+					ScriptAssemblyManager::instance().getTextureCubeClass()->isSubClassOf(acceptedClass))
 				{
 					setUUID(uuid);
 					found = true;
@@ -254,6 +257,51 @@ namespace BansheeEngine
 				}
 			}
 				break;
+			case TID_Font:
+			{
+				if (ScriptAssemblyManager::instance().getFontClass()->isSubClassOf(acceptedClass))
+				{
+					setUUID(uuid);
+					found = true;
+				}
+			}
+				break;
+			case TID_PlainText:
+			{
+				if (ScriptAssemblyManager::instance().getPlainTextClass()->isSubClassOf(acceptedClass))
+				{
+					setUUID(uuid);
+					found = true;
+				}
+			}
+				break;
+			case TID_ScriptCode:
+			{
+				if (ScriptAssemblyManager::instance().getScriptCodeClass()->isSubClassOf(acceptedClass))
+				{
+					setUUID(uuid);
+					found = true;
+				}
+			}
+				break;
+			case TID_Shader:
+			{
+				if (ScriptAssemblyManager::instance().getShaderClass()->isSubClassOf(acceptedClass))
+				{
+					setUUID(uuid);
+					found = true;
+				}
+			}
+				break;
+			case TID_Material:
+			{
+				if (ScriptAssemblyManager::instance().getMaterialClass()->isSubClassOf(acceptedClass))
+				{
+					setUUID(uuid);
+					found = true;
+				}
+			}
+				break;
 			case TID_ManagedResource:
 			{
 				ManagedResourceMetaDataPtr managedResMetaData = std::static_pointer_cast<ManagedResourceMetaData>(meta->getResourceMetaData());

+ 3 - 3
SBansheeEditor/Source/BsScriptDropTarget.cpp

@@ -50,10 +50,10 @@ namespace BansheeEngine
 		metaData.scriptClass->addInternalCall("Internal_SetBounds", &ScriptDropTarget::internal_SetBounds);
 		metaData.scriptClass->addInternalCall("Internal_GetFilePaths", &ScriptDropTarget::internal_GetFilePaths);
 
-		onEnterThunk = (OnEnterThunkDef)metaData.scriptClass->getMethod("InternalDoOnEnter")->getThunk();
-		onMoveThunk = (OnMoveDef)metaData.scriptClass->getMethod("InternalDoOnDrag")->getThunk();
+		onEnterThunk = (OnEnterThunkDef)metaData.scriptClass->getMethod("InternalDoOnEnter", 2)->getThunk();
+		onMoveThunk = (OnMoveDef)metaData.scriptClass->getMethod("InternalDoOnDrag", 2)->getThunk();
 		onLeaveThunk = (OnLeaveDef)metaData.scriptClass->getMethod("InternalDoOnLeave")->getThunk();
-		onDropThunk = (OnDropThunkDef)metaData.scriptClass->getMethod("InternalDoOnDrop")->getThunk();
+		onDropThunk = (OnDropThunkDef)metaData.scriptClass->getMethod("InternalDoOnDrop", 2)->getThunk();
 	}
 
 	void ScriptDropTarget::internal_CreateInstance(MonoObject* instance, ScriptEditorWindow* editorWindow)

+ 5 - 1
SBansheeEngine/Include/BsManagedSerializableObjectInfo.h

@@ -21,11 +21,15 @@ namespace BansheeEngine
 		Float,
 		Double,
 		String,
-		TextureRef,
+		Texture2DRef,
+		Texture3DRef,
+		TextureCubeRef,
 		SpriteTextureRef,
 		ManagedResourceRef,
 		PlainTextRef,
 		ScriptCodeRef,
+		ShaderRef,
+		MaterialRef,
 		SceneObjectRef,
 		ComponentRef
 	};

+ 10 - 2
SBansheeEngine/Include/BsScriptAssemblyManager.h

@@ -27,8 +27,12 @@ namespace BansheeEngine
 		MonoClass* getMissingComponentClass() const { return mMissingComponentClass; }
 		MonoClass* getSceneObjectClass() const { return mSceneObjectClass; }
 		MonoClass* getManagedResourceClass() const { return mManagedResourceClass; }
-		MonoClass* getTextureClass() const { return mTextureClass; }
+		MonoClass* getTexture2DClass() const { return mTexture2DClass; }
+		MonoClass* getTexture3DClass() const { return mTexture3DClass; }
+		MonoClass* getTextureCubeClass() const { return mTextureCubeClass; }
 		MonoClass* getSpriteTextureClass() const { return mSpriteTextureClass; }
+		MonoClass* getShaderClass() const { return mShaderClass; }
+		MonoClass* getMaterialClass() const { return mMaterialClass; }
 		MonoClass* getFontClass() const { return mFontClass; }
 		MonoClass* getPlainTextClass() const { return mPlainTextClass; }
 		MonoClass* getScriptCodeClass() const { return mScriptCodeClass; }
@@ -46,8 +50,12 @@ namespace BansheeEngine
 		MonoClass* mSceneObjectClass;
 		MonoClass* mMissingComponentClass;
 
-		MonoClass* mTextureClass;
+		MonoClass* mTexture2DClass;
+		MonoClass* mTexture3DClass;
+		MonoClass* mTextureCubeClass;
 		MonoClass* mSpriteTextureClass;
+		MonoClass* mShaderClass;
+		MonoClass* mMaterialClass;
 		MonoClass* mManagedResourceClass;
 		MonoClass* mFontClass;
 		MonoClass* mPlainTextClass;

+ 2 - 0
SBansheeEngine/Include/BsScriptEnginePrerequisites.h

@@ -30,6 +30,8 @@ namespace BansheeEngine
 	class ScriptTextureCube;
 	class ScriptPlainText;
 	class ScriptScriptCode;
+	class ScriptShader;
+	class ScriptMaterial;
 	class ScriptGUIElementStyle;
 	class ScriptGUIElementStateStyle;
 	class ScriptGUILayout;

+ 60 - 0
SBansheeEngine/Include/BsScriptMaterial.h

@@ -0,0 +1,60 @@
+#pragma once
+
+#include "BsScriptEnginePrerequisites.h"
+#include "BsScriptResource.h"
+#include "BsMaterial.h"
+#include "BsVector2.h"
+#include "BsVector3.h"
+#include "BsVector4.h"
+#include "BsMatrix3.h"
+#include "BsMatrix4.h"
+#include "BsColor.h"
+
+namespace BansheeEngine
+{
+	class BS_SCR_BE_EXPORT ScriptMaterial : public ScriptObject <ScriptMaterial, ScriptResourceBase>
+	{
+	public:
+		SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "Material")
+
+		HResource getNativeHandle() const { return mMaterial; }
+		void setNativeHandle(const HResource& resource);
+
+		HMaterial getMaterialHandle() const { return mMaterial; }
+	private:
+		friend class ScriptResourceManager;
+
+		static void internal_CreateInstance(MonoObject* instance, ScriptShader* shader);
+
+		static MonoObject* internal_GetShader(ScriptMaterial* nativeInstance);
+		static void internal_SetShader(ScriptMaterial* nativeInstance, ScriptShader* shader);
+
+		static void internal_SetFloat(ScriptMaterial* nativeInstance, MonoString* name, float value);
+		static void internal_SetVector2(ScriptMaterial* nativeInstance, MonoString* name, Vector2 value);
+		static void internal_SetVector3(ScriptMaterial* nativeInstance, MonoString* name, Vector3 value);
+		static void internal_SetVector4(ScriptMaterial* nativeInstance, MonoString* name, Vector4 value);
+		static void internal_SetMatrix3(ScriptMaterial* nativeInstance, MonoString* name, Matrix3 value);
+		static void internal_SetMatrix4(ScriptMaterial* nativeInstance, MonoString* name, Matrix4 value);
+		static void internal_SetColor(ScriptMaterial* nativeInstance, MonoString* name, Color value);
+		static void internal_SetTexture2D(ScriptMaterial* nativeInstance, MonoString* name, ScriptTexture2D* value);
+		static void internal_SetTexture3D(ScriptMaterial* nativeInstance, MonoString* name, ScriptTexture3D* value);
+		static void internal_SetTextureCube(ScriptMaterial* nativeInstance, MonoString* name, ScriptTextureCube* value);
+
+		static float internal_GetFloat(ScriptMaterial* nativeInstance, MonoString* name);
+		static Vector2 internal_GetVector2(ScriptMaterial* nativeInstance, MonoString* name);
+		static Vector3 internal_GetVector3(ScriptMaterial* nativeInstance, MonoString* name);
+		static Vector4 internal_GetVector4(ScriptMaterial* nativeInstance, MonoString* name);
+		static Matrix3 internal_GetMatrix3(ScriptMaterial* nativeInstance, MonoString* name);
+		static Matrix4 internal_GetMatrix4(ScriptMaterial* nativeInstance, MonoString* name);
+		static Color internal_GetColor(ScriptMaterial* nativeInstance, MonoString* name);
+		static MonoObject* internal_GetTexture2D(ScriptMaterial* nativeInstance, MonoString* name);
+		static MonoObject* internal_GetTexture3D(ScriptMaterial* nativeInstance, MonoString* name);
+		static MonoObject* internal_GetTextureCube(ScriptMaterial* nativeInstance, MonoString* name);
+
+		ScriptMaterial(MonoObject* instance, const HMaterial& material);
+
+		void _onManagedInstanceDeleted();
+
+		HMaterial mMaterial;
+	};
+}

+ 45 - 1
SBansheeEngine/Include/BsScriptResourceManager.h

@@ -47,6 +47,30 @@ namespace BansheeEngine
 		 */
 		ScriptTextureCube* createScriptTextureCube(MonoObject* existingInstance, const HTexture& resourceHandle);
 
+		/**
+		 * @note Throws an exception if resource for the handle already exists.
+		 * 		 Initializes the ScriptResource with an existing managed instance.
+		 */
+		ScriptShader* createScriptShader(const HShader& resourceHandle);
+
+		/**
+		 * @note Throws an exception if resource for the handle already exists.
+		 * 		 Initializes the ScriptResource with an existing managed instance.
+		 */
+		ScriptShader* createScriptShader(MonoObject* existingInstance, const HShader& resourceHandle);
+
+		/**
+		 * @note Throws an exception if resource for the handle already exists.
+		 * 		 Initializes the ScriptResource with an existing managed instance.
+		 */
+		ScriptMaterial* createScriptMaterial(const HMaterial& resourceHandle);
+
+		/**
+		 * @note Throws an exception if resource for the handle already exists.
+		 * 		 Initializes the ScriptResource with an existing managed instance.
+		 */
+		ScriptMaterial* createScriptMaterial(MonoObject* existingInstance, const HMaterial& resourceHandle);
+
 		/**
 		 * @note Throws an exception if resource for the handle already exists.
 		 * 		 Initializes the ScriptResource with an existing managed instance.
@@ -104,7 +128,27 @@ namespace BansheeEngine
 		/**
 		 * @note Returns nullptr if script resource doesn't exist.
 		 */
-		ScriptTexture2D* getScriptTexture(const HTexture& resourceHandle);
+		ScriptTexture2D* getScriptTexture2D(const HTexture& resourceHandle);
+
+		/**
+		 * @note Returns nullptr if script resource doesn't exist.
+		 */
+		ScriptTexture3D* getScriptTexture3D(const HTexture& resourceHandle);
+
+		/**
+		 * @note Returns nullptr if script resource doesn't exist.
+		 */
+		ScriptTextureCube* getScriptTextureCube(const HTexture& resourceHandle);
+
+		/**
+		 * @note Returns nullptr if script resource doesn't exist.
+		 */
+		ScriptShader* getScriptShader(const HShader& resourceHandle);
+
+		/**
+		 * @note Returns nullptr if script resource doesn't exist.
+		 */
+		ScriptMaterial* getScriptMaterial(const HMaterial& resourceHandle);
 
 		/**
 		 * @note Returns nullptr if script resource doesn't exist.

+ 29 - 0
SBansheeEngine/Include/BsScriptShader.h

@@ -0,0 +1,29 @@
+#pragma once
+
+#include "BsScriptEnginePrerequisites.h"
+#include "BsScriptResource.h"
+#include "BsShader.h"
+
+namespace BansheeEngine
+{
+	class BS_SCR_BE_EXPORT ScriptShader : public ScriptObject <ScriptShader, ScriptResourceBase>
+	{
+	public:
+		SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "Shader")
+
+		HResource getNativeHandle() const { return mShader; }
+		void setNativeHandle(const HResource& resource);
+
+		HShader getShaderHandle() const { return mShader; }
+	private:
+		friend class ScriptResourceManager;
+
+		static void internal_GetShaderParameters(ScriptShader* nativeInstance, MonoArray** outNames, MonoArray** outTypes);
+
+		ScriptShader(MonoObject* instance, const HShader& shader);
+
+		void _onManagedInstanceDeleted();
+
+		HShader mShader;
+	};
+}

+ 2 - 0
SBansheeEngine/Include/BsScriptTexture3D.h

@@ -16,6 +16,8 @@ namespace BansheeEngine
 
 		HResource getNativeHandle() const { return mTexture; }
 		void setNativeHandle(const HResource& resource);
+
+		HTexture getTextureHandle() const { return mTexture; }
 	private:
 		friend class ScriptResourceManager;
 

+ 2 - 0
SBansheeEngine/Include/BsScriptTextureCube.h

@@ -16,6 +16,8 @@ namespace BansheeEngine
 
 		HResource getNativeHandle() const { return mTexture; }
 		void setNativeHandle(const HResource& resource);
+
+		HTexture getTextureHandle() const { return mTexture; }
 	private:
 		friend class ScriptResourceManager;
 

+ 4 - 0
SBansheeEngine/SBansheeEngine.vcxproj

@@ -285,6 +285,7 @@
     <ClInclude Include="Include\BsScriptInputConfiguration.h" />
     <ClInclude Include="Include\BsScriptMacros.h" />
     <ClInclude Include="Include\BsScriptManagedResource.h" />
+    <ClInclude Include="Include\BsScriptMaterial.h" />
     <ClInclude Include="Include\BsScriptObject.h" />
     <ClInclude Include="Include\BsScriptObjectImpl.h" />
     <ClInclude Include="Include\BsScriptObjectManager.h" />
@@ -306,6 +307,7 @@
     <ClInclude Include="Include\BsScriptSerializableList.h" />
     <ClInclude Include="Include\BsScriptSerializableObject.h" />
     <ClInclude Include="Include\BsScriptSerializableProperty.h" />
+    <ClInclude Include="Include\BsScriptShader.h" />
     <ClInclude Include="Include\BsScriptSpriteTexture.h" />
     <ClInclude Include="Include\BsScriptStringTable.h" />
     <ClInclude Include="Include\BsScriptTexture.h" />
@@ -359,6 +361,7 @@
     <ClCompile Include="Source\BsScriptInput.cpp" />
     <ClCompile Include="Source\BsScriptInputConfiguration.cpp" />
     <ClCompile Include="Source\BsScriptManagedResource.cpp" />
+    <ClCompile Include="Source\BsScriptMaterial.cpp" />
     <ClCompile Include="Source\BsScriptObject.cpp" />
     <ClCompile Include="Source\BsScriptObjectImpl.cpp" />
     <ClCompile Include="Source\BsScriptObjectManager.cpp" />
@@ -384,6 +387,7 @@
     <ClCompile Include="Source\BsScriptSerializableList.cpp" />
     <ClCompile Include="Source\BsScriptSerializableObject.cpp" />
     <ClCompile Include="Source\BsScriptSerializableProperty.cpp" />
+    <ClCompile Include="Source\BsScriptShader.cpp" />
     <ClCompile Include="Source\BsScriptSpriteTexture.cpp" />
     <ClCompile Include="Source\BsScriptStringTable.cpp" />
     <ClCompile Include="Source\BsScriptTexture.cpp" />

+ 12 - 0
SBansheeEngine/SBansheeEngine.vcxproj.filters

@@ -291,6 +291,12 @@
     <ClInclude Include="Include\BsScriptBuiltin.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="Include\BsScriptShader.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\BsScriptMaterial.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\BsScriptTexture2D.cpp">
@@ -518,5 +524,11 @@
     <ClCompile Include="Source\BsScriptBuiltin.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="Source\BsScriptShader.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="Source\BsScriptMaterial.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 113 - 3
SBansheeEngine/Source/BsManagedSerializableField.cpp

@@ -6,10 +6,14 @@
 #include "BsScriptResourceManager.h"
 #include "BsScriptGameObjectManager.h"
 #include "BsScriptTexture2D.h"
+#include "BsScriptTexture3D.h"
+#include "BsScriptTextureCube.h"
 #include "BsScriptSpriteTexture.h"
 #include "BsScriptManagedResource.h"
 #include "BsScriptPlainText.h"
 #include "BsScriptScriptCode.h"
+#include "BsScriptShader.h"
+#include "BsScriptMaterial.h"
 #include "BsScriptSceneObject.h"
 #include "BsScriptComponent.h"
 #include "BsManagedSerializableObject.h"
@@ -138,7 +142,7 @@ namespace BansheeEngine
 						fieldData->value = MonoUtil::monoToWString(strVal);
 					return fieldData;
 				}
-			case ScriptPrimitiveType::TextureRef:
+			case ScriptPrimitiveType::Texture2DRef:
 				{
 					auto fieldData = bs_shared_ptr<ManagedSerializableFieldDataResourceRef>();
 
@@ -150,6 +154,30 @@ namespace BansheeEngine
 
 					return fieldData;
 				}
+			case ScriptPrimitiveType::Texture3DRef:
+			{
+				auto fieldData = bs_shared_ptr<ManagedSerializableFieldDataResourceRef>();
+
+				if (value != nullptr)
+				{
+					ScriptTexture3D* scriptTexture3D = ScriptTexture3D::toNative(value);
+					fieldData->value = static_resource_cast<ScriptTexture3D>(scriptTexture3D->getNativeHandle());
+				}
+
+				return fieldData;
+			}
+			case ScriptPrimitiveType::TextureCubeRef:
+			{
+				auto fieldData = bs_shared_ptr<ManagedSerializableFieldDataResourceRef>();
+
+				if (value != nullptr)
+				{
+					ScriptTextureCube* scriptTextureCube = ScriptTextureCube::toNative(value);
+					fieldData->value = static_resource_cast<ScriptTextureCube>(scriptTextureCube->getNativeHandle());
+				}
+
+				return fieldData;
+			}
 			case ScriptPrimitiveType::SpriteTextureRef:
 				{
 					auto fieldData = bs_shared_ptr<ManagedSerializableFieldDataResourceRef>();
@@ -162,6 +190,30 @@ namespace BansheeEngine
 
 					return fieldData;
 				}
+			case ScriptPrimitiveType::ShaderRef:
+			{
+				auto fieldData = bs_shared_ptr<ManagedSerializableFieldDataResourceRef>();
+
+				if (value != nullptr)
+				{
+					ScriptShader* scriptShader = ScriptShader::toNative(value);
+					fieldData->value = static_resource_cast<ScriptShader>(scriptShader->getNativeHandle());
+				}
+
+				return fieldData;
+			}
+			case ScriptPrimitiveType::MaterialRef:
+			{
+				auto fieldData = bs_shared_ptr<ManagedSerializableFieldDataResourceRef>();
+
+				if (value != nullptr)
+				{
+					ScriptMaterial* scriptMaterial = ScriptMaterial::toNative(value);
+					fieldData->value = static_resource_cast<ScriptMaterial>(scriptMaterial->getNativeHandle());
+				}
+
+				return fieldData;
+			}
 			case ScriptPrimitiveType::ManagedResourceRef:
 				{
 					auto fieldData = bs_shared_ptr<ManagedSerializableFieldDataResourceRef>();
@@ -432,12 +484,12 @@ namespace BansheeEngine
 		{
 			auto primitiveTypeInfo = std::static_pointer_cast<ManagedSerializableTypeInfoPrimitive>(typeInfo);
 
-			if(primitiveTypeInfo->mType == ScriptPrimitiveType::TextureRef)
+			if(primitiveTypeInfo->mType == ScriptPrimitiveType::Texture2DRef)
 			{
 				if(value)
 				{
 					HTexture texture = static_resource_cast<Texture>(value);
-					ScriptTexture2D* scriptResource = ScriptResourceManager::instance().getScriptTexture(texture);
+					ScriptTexture2D* scriptResource = ScriptResourceManager::instance().getScriptTexture2D(texture);
 					if(scriptResource == nullptr)
 						scriptResource = ScriptResourceManager::instance().createScriptTexture2D(texture);
 
@@ -446,6 +498,34 @@ namespace BansheeEngine
 				else
 					return nullptr;
 			}
+			else if (primitiveTypeInfo->mType == ScriptPrimitiveType::Texture3DRef)
+			{
+				if (value)
+				{
+					HTexture texture = static_resource_cast<Texture>(value);
+					ScriptTexture3D* scriptResource = ScriptResourceManager::instance().getScriptTexture3D(texture);
+					if (scriptResource == nullptr)
+						scriptResource = ScriptResourceManager::instance().createScriptTexture3D(texture);
+
+					return scriptResource->getManagedInstance();
+				}
+				else
+					return nullptr;
+			}
+			else if (primitiveTypeInfo->mType == ScriptPrimitiveType::TextureCubeRef)
+			{
+				if (value)
+				{
+					HTexture texture = static_resource_cast<Texture>(value);
+					ScriptTextureCube* scriptResource = ScriptResourceManager::instance().getScriptTextureCube(texture);
+					if (scriptResource == nullptr)
+						scriptResource = ScriptResourceManager::instance().createScriptTextureCube(texture);
+
+					return scriptResource->getManagedInstance();
+				}
+				else
+					return nullptr;
+			}
 			else if(primitiveTypeInfo->mType == ScriptPrimitiveType::SpriteTextureRef)
 			{
 				if(value)
@@ -461,6 +541,36 @@ namespace BansheeEngine
 				else
 					return nullptr;
 			}
+			else if (primitiveTypeInfo->mType == ScriptPrimitiveType::ShaderRef)
+			{
+				if (value)
+				{
+					HShader shader = static_resource_cast<Shader>(value);
+					ScriptShader* scriptResource = ScriptResourceManager::instance().getScriptShader(shader);
+					if (scriptResource == nullptr)
+						scriptResource = ScriptResourceManager::instance().createScriptShader(shader);
+
+					if (scriptResource != nullptr)
+						return scriptResource->getManagedInstance();
+				}
+				else
+					return nullptr;
+			}
+			else if (primitiveTypeInfo->mType == ScriptPrimitiveType::MaterialRef)
+			{
+				if (value)
+				{
+					HMaterial material = static_resource_cast<Material>(value);
+					ScriptMaterial* scriptResource = ScriptResourceManager::instance().getScriptMaterial(material);
+					if (scriptResource == nullptr)
+						scriptResource = ScriptResourceManager::instance().createScriptMaterial(material);
+
+					if (scriptResource != nullptr)
+						return scriptResource->getManagedInstance();
+				}
+				else
+					return nullptr;
+			}
 			else if (primitiveTypeInfo->mType == ScriptPrimitiveType::PlainTextRef)
 			{
 				if (value)

+ 10 - 2
SBansheeEngine/Source/BsManagedSerializableObjectInfo.cpp

@@ -129,10 +129,18 @@ namespace BansheeEngine
 			return mono_get_double_class();
 		case ScriptPrimitiveType::String:
 			return mono_get_string_class();
-		case ScriptPrimitiveType::TextureRef:
-			return ScriptAssemblyManager::instance().getTextureClass()->_getInternalClass();
+		case ScriptPrimitiveType::Texture2DRef:
+			return ScriptAssemblyManager::instance().getTexture2DClass()->_getInternalClass();
+		case ScriptPrimitiveType::Texture3DRef:
+			return ScriptAssemblyManager::instance().getTexture3DClass()->_getInternalClass();
+		case ScriptPrimitiveType::TextureCubeRef:
+			return ScriptAssemblyManager::instance().getTextureCubeClass()->_getInternalClass();
 		case ScriptPrimitiveType::SpriteTextureRef:
 			return ScriptAssemblyManager::instance().getSpriteTextureClass()->_getInternalClass();
+		case ScriptPrimitiveType::ShaderRef:
+			return ScriptAssemblyManager::instance().getShaderClass()->_getInternalClass();
+		case ScriptPrimitiveType::MaterialRef:
+			return ScriptAssemblyManager::instance().getMaterialClass()->_getInternalClass();
 		case ScriptPrimitiveType::ManagedResourceRef:
 			return ScriptAssemblyManager::instance().getManagedResourceClass()->_getInternalClass();
 		case ScriptPrimitiveType::PlainTextRef:

+ 52 - 7
SBansheeEngine/Source/BsScriptAssemblyManager.cpp

@@ -15,10 +15,11 @@ namespace BansheeEngine
 {
 	ScriptAssemblyManager::ScriptAssemblyManager()
 		:mBaseTypesInitialized(false), mSerializeObjectAttribute(nullptr), mDontSerializeFieldAttribute(nullptr), 
-		mComponentClass(nullptr), mSceneObjectClass(nullptr), mTextureClass(nullptr), mSpriteTextureClass(nullptr),
+		mComponentClass(nullptr), mSceneObjectClass(nullptr), mTexture2DClass(nullptr), mSpriteTextureClass(nullptr),
 		mSerializeFieldAttribute(nullptr), mHideInInspectorAttribute(nullptr), mSystemArrayClass(nullptr), mSystemGenericListClass(nullptr),
 		mSystemGenericDictionaryClass(nullptr), mManagedResourceClass(nullptr), mFontClass(nullptr), mMissingComponentClass(nullptr),
-		mPlainTextClass(nullptr), mScriptCodeClass(nullptr)
+		mPlainTextClass(nullptr), mScriptCodeClass(nullptr), mShaderClass(nullptr), mMaterialClass(nullptr), mTexture3DClass(nullptr),
+		mTextureCubeClass(nullptr)
 	{
 
 	}
@@ -265,10 +266,22 @@ namespace BansheeEngine
 				return typeInfo;
 			}
 		case MONO_TYPE_CLASS:
-			if(monoClass->isSubClassOf(mTextureClass))
+			if(monoClass->isSubClassOf(mTexture2DClass))
 			{
 				std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr<ManagedSerializableTypeInfoPrimitive>();
-				typeInfo->mType = ScriptPrimitiveType::TextureRef;
+				typeInfo->mType = ScriptPrimitiveType::Texture2DRef;
+				return typeInfo;
+			}
+			if (monoClass->isSubClassOf(mTexture3DClass))
+			{
+				std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr<ManagedSerializableTypeInfoPrimitive>();
+				typeInfo->mType = ScriptPrimitiveType::Texture3DRef;
+				return typeInfo;
+			}
+			if (monoClass->isSubClassOf(mTextureCubeClass))
+			{
+				std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr<ManagedSerializableTypeInfoPrimitive>();
+				typeInfo->mType = ScriptPrimitiveType::TextureCubeRef;
 				return typeInfo;
 			}
 			else if(monoClass->isSubClassOf(mSpriteTextureClass))
@@ -283,6 +296,18 @@ namespace BansheeEngine
 				typeInfo->mType = ScriptPrimitiveType::ManagedResourceRef;
 				return typeInfo;
 			}
+			else if (monoClass->isSubClassOf(mShaderClass))
+			{
+				std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr<ManagedSerializableTypeInfoPrimitive>();
+				typeInfo->mType = ScriptPrimitiveType::ShaderRef;
+				return typeInfo;
+			}
+			else if (monoClass->isSubClassOf(mMaterialClass))
+			{
+				std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr<ManagedSerializableTypeInfoPrimitive>();
+				typeInfo->mType = ScriptPrimitiveType::MaterialRef;
+				return typeInfo;
+			}
 			else if (monoClass->isSubClassOf(mPlainTextClass))
 			{
 				std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr<ManagedSerializableTypeInfoPrimitive>();
@@ -398,8 +423,12 @@ namespace BansheeEngine
 		mMissingComponentClass = nullptr;
 
 		mManagedResourceClass = nullptr;
-		mTextureClass = nullptr;
+		mTexture2DClass = nullptr;
+		mTexture3DClass = nullptr;
+		mTextureCubeClass = nullptr;
 		mSpriteTextureClass = nullptr;
+		mShaderClass = nullptr;
+		mMaterialClass = nullptr;
 		mFontClass = nullptr;
 		mPlainTextClass = nullptr;
 		mScriptCodeClass = nullptr;
@@ -455,14 +484,30 @@ namespace BansheeEngine
 		if (mManagedResourceClass == nullptr)
 			BS_EXCEPT(InvalidStateException, "Cannot find ManagedResource managed class.");
 
-		mTextureClass = bansheeEngineAssembly->getClass("BansheeEngine", "Texture2D");
-		if(mTextureClass == nullptr)
+		mTexture2DClass = bansheeEngineAssembly->getClass("BansheeEngine", "Texture2D");
+		if(mTexture2DClass == nullptr)
 			BS_EXCEPT(InvalidStateException, "Cannot find Texture2D managed class.");
 
+		mTexture3DClass = bansheeEngineAssembly->getClass("BansheeEngine", "Texture3D");
+		if (mTexture3DClass == nullptr)
+			BS_EXCEPT(InvalidStateException, "Cannot find Texture3D managed class.");
+
+		mTextureCubeClass = bansheeEngineAssembly->getClass("BansheeEngine", "TextureCube");
+		if (mTextureCubeClass == nullptr)
+			BS_EXCEPT(InvalidStateException, "Cannot find TextureCube managed class.");
+
 		mSpriteTextureClass = bansheeEngineAssembly->getClass("BansheeEngine", "SpriteTexture");
 		if(mSpriteTextureClass == nullptr)
 			BS_EXCEPT(InvalidStateException, "Cannot find SpriteTexture managed class.");
 
+		mShaderClass = bansheeEngineAssembly->getClass("BansheeEngine", "Shader");
+		if (mShaderClass == nullptr)
+			BS_EXCEPT(InvalidStateException, "Cannot find Shader managed class.");
+
+		mMaterialClass = bansheeEngineAssembly->getClass("BansheeEngine", "Material");
+		if (mMaterialClass == nullptr)
+			BS_EXCEPT(InvalidStateException, "Cannot find Material managed class.");
+
 		mFontClass = bansheeEngineAssembly->getClass("BansheeEngine", "Font");
 		if (mFontClass == nullptr)
 			BS_EXCEPT(InvalidStateException, "Cannot find Font managed class.");

+ 275 - 0
SBansheeEngine/Source/BsScriptMaterial.cpp

@@ -0,0 +1,275 @@
+#include "BsScriptMaterial.h"
+#include "BsScriptResourceManager.h"
+#include "BsScriptMeta.h"
+#include "BsMonoField.h"
+#include "BsMonoClass.h"
+#include "BsMonoManager.h"
+#include "BsMonoUtil.h"
+#include "BsScriptShader.h"
+#include "BsScriptTexture2D.h"
+#include "BsScriptTexture3D.h"
+#include "BsScriptTextureCube.h"
+
+namespace BansheeEngine
+{
+	ScriptMaterial::ScriptMaterial(MonoObject* instance, const HMaterial& material)
+		:ScriptObject(instance), mMaterial(material)
+	{
+
+	}
+
+	void ScriptMaterial::initRuntimeData()
+	{
+		metaData.scriptClass->addInternalCall("Internal_CreateInstance", &ScriptMaterial::internal_CreateInstance);
+
+		metaData.scriptClass->addInternalCall("Internal_GetShader", &ScriptMaterial::internal_GetShader);
+		metaData.scriptClass->addInternalCall("Internal_SetShader", &ScriptMaterial::internal_SetShader);
+
+		metaData.scriptClass->addInternalCall("Internal_SetFloat", &ScriptMaterial::internal_SetFloat);
+		metaData.scriptClass->addInternalCall("Internal_SetVector2", &ScriptMaterial::internal_SetVector2);
+		metaData.scriptClass->addInternalCall("Internal_SetVector3", &ScriptMaterial::internal_SetVector3);
+		metaData.scriptClass->addInternalCall("Internal_SetVector4", &ScriptMaterial::internal_SetVector4);
+		metaData.scriptClass->addInternalCall("Internal_SetMatrix3", &ScriptMaterial::internal_SetMatrix3);
+		metaData.scriptClass->addInternalCall("Internal_SetMatrix4", &ScriptMaterial::internal_SetMatrix4);
+		metaData.scriptClass->addInternalCall("Internal_SetColor", &ScriptMaterial::internal_SetColor);
+		metaData.scriptClass->addInternalCall("Internal_SetTexture2D", &ScriptMaterial::internal_SetTexture2D);
+		metaData.scriptClass->addInternalCall("Internal_SetTexture3D", &ScriptMaterial::internal_SetTexture3D);
+		metaData.scriptClass->addInternalCall("Internal_SetTextureCube", &ScriptMaterial::internal_SetTextureCube);
+
+		metaData.scriptClass->addInternalCall("Internal_GetFloat", &ScriptMaterial::internal_GetFloat);
+		metaData.scriptClass->addInternalCall("Internal_GetVector2", &ScriptMaterial::internal_GetVector2);
+		metaData.scriptClass->addInternalCall("Internal_GetVector3", &ScriptMaterial::internal_GetVector3);
+		metaData.scriptClass->addInternalCall("Internal_GetVector4", &ScriptMaterial::internal_GetVector4);
+		metaData.scriptClass->addInternalCall("Internal_GetMatrix3", &ScriptMaterial::internal_GetMatrix3);
+		metaData.scriptClass->addInternalCall("Internal_GetMatrix4", &ScriptMaterial::internal_GetMatrix4);
+		metaData.scriptClass->addInternalCall("Internal_GetColor", &ScriptMaterial::internal_GetColor);
+		metaData.scriptClass->addInternalCall("Internal_GetTexture2D", &ScriptMaterial::internal_GetTexture2D);
+		metaData.scriptClass->addInternalCall("Internal_GetTexture3D", &ScriptMaterial::internal_GetTexture3D);
+		metaData.scriptClass->addInternalCall("Internal_GetTextureCube", &ScriptMaterial::internal_GetTextureCube);
+	}
+
+	void ScriptMaterial::internal_CreateInstance(MonoObject* instance, ScriptShader* shader)
+	{
+		HShader nativeShader;
+		if (shader != nullptr)
+			nativeShader = shader->getShaderHandle();
+
+		HMaterial material = Material::create(nativeShader);
+		ScriptResourceManager::instance().createScriptMaterial(instance, material);
+	}
+
+	MonoObject* ScriptMaterial::internal_GetShader(ScriptMaterial* nativeInstance)
+	{
+		HShader shader = nativeInstance->getMaterialHandle()->getShader();
+
+		if (shader == nullptr)
+			return nullptr;
+
+		ScriptShader* scriptShader = ScriptResourceManager::instance().getScriptShader(shader);
+		if (scriptShader == nullptr)
+			scriptShader = ScriptResourceManager::instance().createScriptShader(shader);
+
+		return scriptShader->getManagedInstance();
+	}
+
+	void ScriptMaterial::internal_SetShader(ScriptMaterial* nativeInstance, ScriptShader* shader)
+	{
+		HShader nativeShader;
+		if (shader != nullptr)
+			nativeShader = shader->getShaderHandle();
+
+		nativeInstance->getMaterialHandle()->setShader(nativeShader);
+	}
+
+	void ScriptMaterial::internal_SetFloat(ScriptMaterial* nativeInstance, MonoString* name, float value)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		nativeInstance->mMaterial->setFloat(paramName, value);
+	}
+
+	void ScriptMaterial::internal_SetVector2(ScriptMaterial* nativeInstance, MonoString* name, Vector2 value)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		nativeInstance->mMaterial->setVec2(paramName, value);
+	}
+
+	void ScriptMaterial::internal_SetVector3(ScriptMaterial* nativeInstance, MonoString* name, Vector3 value)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		nativeInstance->mMaterial->setVec3(paramName, value);
+	}
+
+	void ScriptMaterial::internal_SetVector4(ScriptMaterial* nativeInstance, MonoString* name, Vector4 value)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		nativeInstance->mMaterial->setVec4(paramName, value);
+	}
+
+	void ScriptMaterial::internal_SetMatrix3(ScriptMaterial* nativeInstance, MonoString* name, Matrix3 value)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		nativeInstance->mMaterial->setMat3(paramName, value);
+	}
+
+	void ScriptMaterial::internal_SetMatrix4(ScriptMaterial* nativeInstance, MonoString* name, Matrix4 value)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		nativeInstance->mMaterial->setMat4(paramName, value);
+	}
+
+	void ScriptMaterial::internal_SetColor(ScriptMaterial* nativeInstance, MonoString* name, Color value)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		nativeInstance->mMaterial->setColor(paramName, value);
+	}
+
+	void ScriptMaterial::internal_SetTexture2D(ScriptMaterial* nativeInstance, MonoString* name, ScriptTexture2D* value)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		HTexture texture;
+
+		if (value != nullptr)
+			texture = value->getTextureHandle();
+
+		nativeInstance->mMaterial->setTexture(paramName, texture);
+	}
+
+	void ScriptMaterial::internal_SetTexture3D(ScriptMaterial* nativeInstance, MonoString* name, ScriptTexture3D* value)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		HTexture texture;
+
+		if (value != nullptr)
+			texture = value->getTextureHandle();
+
+		nativeInstance->mMaterial->setTexture(paramName, texture);
+	}
+
+	void ScriptMaterial::internal_SetTextureCube(ScriptMaterial* nativeInstance, MonoString* name, ScriptTextureCube* value)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		HTexture texture;
+
+		if (value != nullptr)
+			texture = value->getTextureHandle();
+
+		nativeInstance->mMaterial->setTexture(paramName, texture);
+	}
+
+	float ScriptMaterial::internal_GetFloat(ScriptMaterial* nativeInstance, MonoString* name)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		return nativeInstance->mMaterial->getFloat(paramName);
+	}
+
+	Vector2 ScriptMaterial::internal_GetVector2(ScriptMaterial* nativeInstance, MonoString* name)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		return nativeInstance->mMaterial->getVec2(paramName);
+	}
+
+	Vector3 ScriptMaterial::internal_GetVector3(ScriptMaterial* nativeInstance, MonoString* name)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		return nativeInstance->mMaterial->getVec3(paramName);
+	}
+
+	Vector4 ScriptMaterial::internal_GetVector4(ScriptMaterial* nativeInstance, MonoString* name)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		return nativeInstance->mMaterial->getVec4(paramName);
+	}
+
+	Matrix3 ScriptMaterial::internal_GetMatrix3(ScriptMaterial* nativeInstance, MonoString* name)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		return nativeInstance->mMaterial->getMat3(paramName);
+	}
+
+	Matrix4 ScriptMaterial::internal_GetMatrix4(ScriptMaterial* nativeInstance, MonoString* name)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		return nativeInstance->mMaterial->getMat4(paramName);
+	}
+
+	Color ScriptMaterial::internal_GetColor(ScriptMaterial* nativeInstance, MonoString* name)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		return nativeInstance->mMaterial->getColor(paramName);
+	}
+
+	MonoObject* ScriptMaterial::internal_GetTexture2D(ScriptMaterial* nativeInstance, MonoString* name)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		HTexture texture = nativeInstance->mMaterial->getTexture(paramName);
+		if (texture == nullptr)
+			return nullptr;
+
+		ScriptTexture2D* scriptTexture = ScriptResourceManager::instance().getScriptTexture2D(texture);
+		if (scriptTexture == nullptr)
+			scriptTexture = ScriptResourceManager::instance().createScriptTexture2D(texture);
+
+		return scriptTexture->getManagedInstance();
+	}
+
+	MonoObject* ScriptMaterial::internal_GetTexture3D(ScriptMaterial* nativeInstance, MonoString* name)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		HTexture texture = nativeInstance->mMaterial->getTexture(paramName);
+		if (texture == nullptr)
+			return nullptr;
+
+		ScriptTexture3D* scriptTexture = ScriptResourceManager::instance().getScriptTexture3D(texture);
+		if (scriptTexture == nullptr)
+			scriptTexture = ScriptResourceManager::instance().createScriptTexture3D(texture);
+
+		return scriptTexture->getManagedInstance();
+	}
+
+	MonoObject* ScriptMaterial::internal_GetTextureCube(ScriptMaterial* nativeInstance, MonoString* name)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		HTexture texture = nativeInstance->mMaterial->getTexture(paramName);
+		if (texture == nullptr)
+			return nullptr;
+
+		ScriptTextureCube* scriptTexture = ScriptResourceManager::instance().getScriptTextureCube(texture);
+		if (scriptTexture == nullptr)
+			scriptTexture = ScriptResourceManager::instance().createScriptTextureCube(texture);
+
+		return scriptTexture->getManagedInstance();
+	}
+
+	void ScriptMaterial::_onManagedInstanceDeleted()
+	{
+		mManagedInstance = nullptr;
+
+		if (!mRefreshInProgress)
+			ScriptResourceManager::instance().destroyScriptResource(this);
+	}
+
+	void ScriptMaterial::setNativeHandle(const HResource& resource)
+	{
+		mMaterial = static_resource_cast<Material>(resource);
+	}
+}

+ 3 - 3
SBansheeEngine/Source/BsScriptRenderTexture2D.cpp

@@ -149,7 +149,7 @@ namespace BansheeEngine
 			{
 				HTexture colorTex = tex->getBindableColorTexture(i);
 
-				ScriptTexture2D* scriptSurface = ScriptResourceManager::instance().getScriptTexture(colorTex);
+				ScriptTexture2D* scriptSurface = ScriptResourceManager::instance().getScriptTexture2D(colorTex);
 				if (scriptSurface == nullptr)
 					scriptSurface = ScriptResourceManager::instance().createScriptTexture2D(colorTex);
 
@@ -164,7 +164,7 @@ namespace BansheeEngine
 
 			HTexture colorTex = tex->getBindableColorTexture();
 
-			ScriptTexture2D* scriptSurface = ScriptResourceManager::instance().getScriptTexture(colorTex);
+			ScriptTexture2D* scriptSurface = ScriptResourceManager::instance().getScriptTexture2D(colorTex);
 			if (scriptSurface == nullptr)
 				scriptSurface = ScriptResourceManager::instance().createScriptTexture2D(colorTex);
 
@@ -187,7 +187,7 @@ namespace BansheeEngine
 			colorTex = tex->getBindableDepthStencilTexture();
 		}
 
-		ScriptTexture2D* scriptSurface = ScriptResourceManager::instance().getScriptTexture(colorTex);
+		ScriptTexture2D* scriptSurface = ScriptResourceManager::instance().getScriptTexture2D(colorTex);
 		if (scriptSurface == nullptr)
 			scriptSurface = ScriptResourceManager::instance().createScriptTexture2D(colorTex);
 

+ 87 - 5
SBansheeEngine/Source/BsScriptResourceManager.cpp

@@ -8,6 +8,8 @@
 #include "BsScriptSpriteTexture.h"
 #include "BsScriptPlainText.h"
 #include "BsScriptScriptCode.h"
+#include "BsScriptShader.h"
+#include "BsScriptMaterial.h"
 #include "BsScriptFont.h"
 #include "BsScriptManagedResource.h"
 #include "BsScriptAssemblyManager.h"
@@ -20,7 +22,7 @@ namespace BansheeEngine
 
 	ScriptTexture2D* ScriptResourceManager::createScriptTexture2D(const HTexture& resourceHandle)
 	{
-		MonoClass* textureClass = ScriptAssemblyManager::instance().getTextureClass();
+		MonoClass* textureClass = ScriptAssemblyManager::instance().getTexture2DClass();
 		MonoObject* monoInstance = textureClass->createInstance();
 
 		return createScriptTexture2D(monoInstance, resourceHandle);
@@ -28,7 +30,7 @@ namespace BansheeEngine
 
 	ScriptTexture3D* ScriptResourceManager::createScriptTexture3D(const HTexture& resourceHandle)
 	{
-		MonoClass* textureClass = ScriptAssemblyManager::instance().getTextureClass();
+		MonoClass* textureClass = ScriptAssemblyManager::instance().getTexture3DClass();
 		MonoObject* monoInstance = textureClass->createInstance();
 
 		return createScriptTexture3D(monoInstance, resourceHandle);
@@ -36,7 +38,7 @@ namespace BansheeEngine
 
 	ScriptTextureCube* ScriptResourceManager::createScriptTextureCube(const HTexture& resourceHandle)
 	{
-		MonoClass* textureClass = ScriptAssemblyManager::instance().getTextureClass();
+		MonoClass* textureClass = ScriptAssemblyManager::instance().getTextureCubeClass();
 		MonoObject* monoInstance = textureClass->createInstance();
 
 		return createScriptTextureCube(monoInstance, resourceHandle);
@@ -81,6 +83,48 @@ namespace BansheeEngine
 		return scriptResource;
 	}
 
+	ScriptShader* ScriptResourceManager::createScriptShader(const HShader& resourceHandle)
+	{
+		MonoClass* shaderClass = ScriptAssemblyManager::instance().getShaderClass();
+		MonoObject* monoInstance = shaderClass->createInstance();
+
+		return createScriptShader(monoInstance, resourceHandle);
+	}
+
+	ScriptShader* ScriptResourceManager::createScriptShader(MonoObject* instance, const HShader& resourceHandle)
+	{
+		const String& uuid = resourceHandle.getUUID();
+#if BS_DEBUG_MODE
+		throwExceptionIfInvalidOrDuplicate(uuid);
+#endif
+
+		ScriptShader* scriptResource = new (bs_alloc<ScriptShader>()) ScriptShader(instance, resourceHandle);
+		mScriptResources[uuid] = scriptResource;
+
+		return scriptResource;
+	}
+
+	ScriptMaterial* ScriptResourceManager::createScriptMaterial(const HMaterial& resourceHandle)
+	{
+		MonoClass* materialClass = ScriptAssemblyManager::instance().getMaterialClass();
+		MonoObject* monoInstance = materialClass->createInstance();
+
+		return createScriptMaterial(monoInstance, resourceHandle);
+	}
+
+	ScriptMaterial* ScriptResourceManager::createScriptMaterial(MonoObject* instance, const HMaterial& resourceHandle)
+	{
+		const String& uuid = resourceHandle.getUUID();
+#if BS_DEBUG_MODE
+		throwExceptionIfInvalidOrDuplicate(uuid);
+#endif
+
+		ScriptMaterial* scriptResource = new (bs_alloc<ScriptMaterial>()) ScriptMaterial(instance, resourceHandle);
+		mScriptResources[uuid] = scriptResource;
+
+		return scriptResource;
+	}
+
 	ScriptPlainText* ScriptResourceManager::createScriptPlainText(const HPlainText& resourceHandle)
 	{
 		MonoClass* plainTextClass = ScriptAssemblyManager::instance().getPlainTextClass();
@@ -176,16 +220,36 @@ namespace BansheeEngine
 		return scriptResource;
 	}
 
-	ScriptTexture2D* ScriptResourceManager::getScriptTexture(const HTexture& resourceHandle)
+	ScriptTexture2D* ScriptResourceManager::getScriptTexture2D(const HTexture& resourceHandle)
 	{
 		return static_cast<ScriptTexture2D*>(getScriptResource(resourceHandle.getUUID()));
 	}
 
+	ScriptTexture3D* ScriptResourceManager::getScriptTexture3D(const HTexture& resourceHandle)
+	{
+		return static_cast<ScriptTexture3D*>(getScriptResource(resourceHandle.getUUID()));
+	}
+
+	ScriptTextureCube* ScriptResourceManager::getScriptTextureCube(const HTexture& resourceHandle)
+	{
+		return static_cast<ScriptTextureCube*>(getScriptResource(resourceHandle.getUUID()));
+	}
+
 	ScriptSpriteTexture* ScriptResourceManager::getScriptSpriteTexture(const HSpriteTexture& resourceHandle)
 	{
 		return static_cast<ScriptSpriteTexture*>(getScriptResource(resourceHandle.getUUID()));
 	}
 
+	ScriptShader* ScriptResourceManager::getScriptShader(const HShader& resourceHandle)
+	{
+		return static_cast<ScriptShader*>(getScriptResource(resourceHandle.getUUID()));
+	}
+
+	ScriptMaterial* ScriptResourceManager::getScriptMaterial(const HMaterial& resourceHandle)
+	{
+		return static_cast<ScriptMaterial*>(getScriptResource(resourceHandle.getUUID()));
+	}
+
 	ScriptPlainText* ScriptResourceManager::getScriptPlainText(const HPlainText& resourceHandle)
 	{
 		return static_cast<ScriptPlainText*>(getScriptResource(resourceHandle.getUUID()));
@@ -224,11 +288,29 @@ namespace BansheeEngine
 		switch (resTypeID)
 		{
 		case TID_Texture:
-			return createScriptTexture2D(static_resource_cast<Texture>(resource));
+		{
+			HTexture texture = static_resource_cast<Texture>(resource);
+			TextureType type = texture->getProperties().getTextureType();
+
+			if (type == TEX_TYPE_3D)
+				return createScriptTexture3D(texture);
+			else if (type == TEX_TYPE_CUBE_MAP)
+				return createScriptTextureCube(texture);
+			else
+				return createScriptTexture2D(texture);
+		}
 		case TID_SpriteTexture:
 			return createScriptSpriteTexture(static_resource_cast<SpriteTexture>(resource));
 		case TID_Font:
 			return createScriptFont(static_resource_cast<Font>(resource));
+		case TID_PlainText:
+			return createScriptPlainText(static_resource_cast<PlainText>(resource));
+		case TID_ScriptCode:
+			return createScriptScriptCode(static_resource_cast<ScriptCode>(resource));
+		case TID_Shader:
+			return createScriptShader(static_resource_cast<Shader>(resource));
+		case TID_Material:
+			return createScriptMaterial(static_resource_cast<Material>(resource));
 		case TID_ManagedResource:
 			BS_EXCEPT(InternalErrorException, "Managed resources must have a managed instance by default, this call is invalid.")
 				break;

+ 150 - 0
SBansheeEngine/Source/BsScriptShader.cpp

@@ -0,0 +1,150 @@
+#include "BsScriptShader.h"
+#include "BsScriptResourceManager.h"
+#include "BsScriptMeta.h"
+#include "BsMonoField.h"
+#include "BsMonoClass.h"
+#include "BsMonoArray.h"
+#include "BsMonoManager.h"
+
+namespace BansheeEngine
+{
+	// Note: This must match C# ShaderParameterType enum
+	enum class ShaderParameterType
+	{
+		Float, Vector2, Vector3, Vector4, Color,
+		Matrix3, Matrix4, Texture2D,
+		Texture3D, TextureCube, Sampler
+	};
+
+	ScriptShader::ScriptShader(MonoObject* instance, const HShader& shader)
+		:ScriptObject(instance), mShader(shader)
+	{
+
+	}
+
+	void ScriptShader::initRuntimeData()
+	{
+		metaData.scriptClass->addInternalCall("Internal_GetShaderParameters", &ScriptShader::internal_GetShaderParameters);
+	}
+
+	void ScriptShader::internal_GetShaderParameters(ScriptShader* nativeInstance, MonoArray** outNames, MonoArray** outTypes)
+	{
+		HShader shader = nativeInstance->getShaderHandle();
+		if (!shader.isLoaded())
+			return;
+
+		const Map<String, SHADER_DATA_PARAM_DESC>& dataParams = shader->getDataParams();
+		const Map<String, SHADER_OBJECT_PARAM_DESC>& textureParams = shader->getTextureParams();
+		const Map<String, SHADER_OBJECT_PARAM_DESC>& samplerParams = shader->getSamplerParams();
+
+		struct ParamInfo
+		{
+			String name;
+			ShaderParameterType type;
+		};
+
+		Vector<ParamInfo> paramInfos;
+
+		// TODO - Ignoring int, bool, struct and non-square matrices
+		// TODO - Ignoring buffers and load/store textures
+		for (auto& param : dataParams)
+		{
+			// TODO - No way to identify color types
+
+			ShaderParameterType type;
+			bool isValidType = false;
+			switch (param.second.type) 
+			{
+			case GPDT_FLOAT1:
+				type = ShaderParameterType::Float;
+				isValidType = true;
+				break;
+			case GPDT_FLOAT2:
+				type = ShaderParameterType::Vector2;
+				isValidType = true;
+				break;
+			case GPDT_FLOAT3:
+				type = ShaderParameterType::Vector3;
+				isValidType = true;
+				break;
+			case GPDT_FLOAT4:
+				type = ShaderParameterType::Vector4;
+				isValidType = true;
+				break;
+			case GPDT_MATRIX_3X3:
+				type = ShaderParameterType::Matrix3;
+				isValidType = true;
+				break;
+			case GPDT_MATRIX_4X4:
+				type = ShaderParameterType::Matrix4;
+				isValidType = true;
+				break;
+			}
+
+			if (isValidType)
+				paramInfos.push_back({ param.first, type });
+		}
+
+		for (auto& param : textureParams)
+		{
+			ShaderParameterType type;
+			bool isValidType = false;
+			switch (param.second.type)
+			{
+			case GPOT_TEXTURE2D:
+			case GPOT_TEXTURE2DMS:
+				type = ShaderParameterType::Texture2D;
+				isValidType = true;
+				break;
+			case GPOT_TEXTURE3D:
+				type = ShaderParameterType::Texture3D;
+				isValidType = true;
+				break;
+			case GPOT_TEXTURECUBE:
+				type = ShaderParameterType::TextureCube;
+				isValidType = true;
+				break;
+			}
+
+			if (isValidType)
+				paramInfos.push_back({ param.first, type });
+		}
+
+		for (auto& param : samplerParams)
+		{
+			ShaderParameterType type = ShaderParameterType::Sampler;
+			paramInfos.push_back({ param.first, type });
+		}
+
+
+		UINT32 totalNumParams = (UINT32)paramInfos.size();
+
+		ScriptArray names = ScriptArray::create<String>(totalNumParams);
+		ScriptArray types = ScriptArray::create<UINT32>(totalNumParams);
+
+		UINT32 idx = 0;
+		for (auto& param : paramInfos)
+		{
+			names.set(idx, param.name);
+			types.set(idx, param.type);
+
+			idx++;
+		}
+
+		*outNames = names.getInternal();
+		*outTypes = types.getInternal();
+	}
+	
+	void ScriptShader::_onManagedInstanceDeleted()
+	{
+		mManagedInstance = nullptr;
+
+		if (!mRefreshInProgress)
+			ScriptResourceManager::instance().destroyScriptResource(this);
+	}
+
+	void ScriptShader::setNativeHandle(const HResource& resource)
+	{
+		mShader = static_resource_cast<Shader>(resource);
+	}
+}

+ 22 - 7
TODO.txt

@@ -13,14 +13,15 @@ My GUID generation is screwed up. If multiple GUIDs are generated in succession
 the same and the only variable will be the 4byte random number, which can sometimes end up identical to the previous number.
 
 ----------------------------------------------------------------------
-Project window
+C# Material/Shader:
+
+TODO - Material/Shader has no color type so I cannot know when to display normal vector and when color in inspector
+TODO - Implement param block and sampler support
+TODO - When creating a Material without a shader, a default one should be used, at least in editor
+TODO - Setting Material array parameters isn't possible from C#
 
-C# DropTarget
- - Requires an EditorWindow parent (so I can retrieve its coordinates)
- - Bounds - settable area relative to the parent window
- - Callbacks for OnEnter, OnLeave, OnDrag, OnDrop
- - C# version only works for file drop types, others are ignored
- - GetDroppedFiles() returns a list of paths
+----------------------------------------------------------------------
+Project window
 
 Need faster GUILayoutUtility::calcBounds:
  - WAY too much recursion and repetition
@@ -32,6 +33,19 @@ Need faster GUILayoutUtility::calcBounds:
  - Extend _calculateLayoutSizeRange so it can accept a precalculated array of child size ranges
   - Then I can hopefully avoid repetition and also merge two code paths for layout size range calculation
  - CONSIDER actually performing the layout update, and just caching the results
+   - How to check if element is dirty?
+    - Iterating over all of its children (and parents?) every time seems slow
+	- Perhaps I could move dirty flags from the element and to the first non-dependant parent
+	  - Then when any of its children are updated I mark it as dirty. 
+
+Make sure that making a single GUI element dirty doesn't cause an update over the entire GUIWidget
+ - Make sure that _updateLayoutInternal determines whether an element is dependant on children
+   - GUILayout and GUIPanel would need to store bounds
+   - This would also require removal of actual width/height from layout as that makes it dependant on children 100% of the time
+   - It's not dependant of children if it has fixed width and height
+   - When calculating bounds or updating layout make sure to stop at non-dependant layout or panel
+
+GUIResourceField doesn't distinguish between tex2d, tex3d and texcube.
 
 Simple tasks:
  - Add C# Renderable & Material interface
@@ -88,6 +102,7 @@ Other simple stuff:
  - Get rid of event callback from HString and figure out a better way
  - GUI TextureField similar to ResourceField but it displays the texture it has assigned
  - Better handle and gizmo shaders
+ - Fix FBX indexes and while at it also find out how to extract animation data, bone weights and tangent frames
 
 ----------------------------------------------------------------------
 Handles