Procházet zdrojové kódy

Fixed the terrain sample.

seanpaultaylor před 12 roky
rodič
revize
f03a476ab5

+ 0 - 1
gameplay/res/shaders/terrain.frag

@@ -108,7 +108,6 @@ void main()
     #endif
 
     #if defined(DEBUG_PATCHES)
-    // If patch debug drawing is enabled, tint patches alternate colors
     float tint = mod(u_row + mod(u_column, 2.0), 2.0);
     _baseColor.rgb = _baseColor.rgb * 0.75 + vec3(1.0-tint, tint, 0) * 0.25;
     #endif

+ 17 - 1
gameplay/src/RenderState.cpp

@@ -85,7 +85,23 @@ MaterialParameter* RenderState::getParameter(const char* name) const
     return param;
 }
 
-void RenderState::clearParameter(const char* name)
+unsigned int RenderState::getParameterCount() const
+{
+    return _parameters.size();
+}
+
+MaterialParameter* RenderState::getParameterByIndex(unsigned int index)
+{
+    return _parameters[index];
+}
+
+void RenderState::addParameter(MaterialParameter* param)
+{
+    _parameters.push_back(param);
+    param->addRef();
+}
+
+void RenderState::removeParameter(const char* name)
 {
     for (size_t i = 0, count = _parameters.size(); i < count; ++i)
     {

+ 24 - 3
gameplay/src/RenderState.h

@@ -418,7 +418,7 @@ public:
     };
 
     /**
-     * Returns a MaterialParameter for the specified name.
+     * Gets a MaterialParameter for the specified name.
      * 
      * The returned MaterialParameter can be used to set values for the specified
      * parameter name.
@@ -433,14 +433,35 @@ public:
     MaterialParameter* getParameter(const char* name) const;
 
     /**
-     * Clears the MaterialParameter with the given name.
+     * Gets the number of material parameters.
+     *
+     * @return The number of material parameters.
+     */
+    unsigned int getParameterCount() const;
+
+    /**
+     * Gets a MaterialParameter for the specified index.
+     *
+     * @return A MaterialParameter for the specified index.
+     */
+    MaterialParameter* getParameterByIndex(unsigned int index);
+
+    /**
+     * Adds a MaterialParameter to the render state.
+     *
+     * @param param The parameters to to added.
+     */
+    void addParameter(MaterialParameter* param);
+
+    /**
+     * Removes(clears) the MaterialParameter with the given name.
      *
      * If a material parameter exists for the given name, it is destroyed and
      * removed from this RenderState.
      *
      * @param name Material parameter (uniform) name.
      */
-    void clearParameter(const char* name);
+    void removeParameter(const char* name);
 
     /**
      * Sets a material parameter auto-binding.

+ 20 - 0
gameplay/src/TerrainPatch.cpp

@@ -538,6 +538,26 @@ bool TerrainPatch::updateMaterial()
                 material->getParameter("u_normalMatrix")->bindValue(_terrain, &Terrain::getNormalMatrix);
         }
 
+        // Add all the parameters from the old material to the new ones render state
+        Material* prevMaterial = _levels[i]->model->getMaterial();
+        if (prevMaterial)
+        {
+            RenderState* prevStates[3] = { prevMaterial, prevMaterial->getTechnique(), prevMaterial->getTechnique()->getPassByIndex(0) };
+            RenderState* newStates[3] = { material, material->getTechnique(), material->getTechnique()->getPassByIndex(0) };
+            for (unsigned int i = 0; i < 3; ++i)
+            {
+                for (unsigned int j = 0; j < prevStates[i]->getParameterCount(); ++j)
+                {
+                    newStates[i]->addParameter(prevStates[i]->getParameterByIndex(j));
+                    if (!_terrain->isFlagSet(Terrain::DEBUG_PATCHES))
+                    {
+                        newStates[i]->removeParameter("u_row");
+                        newStates[i]->removeParameter("u_column");
+                    }
+                }
+            }
+        }
+
         // Set material on this lod level
         _levels[i]->model->setMaterial(material);
 

+ 139 - 11
gameplay/src/lua/lua_Material.cpp

@@ -28,15 +28,18 @@ void luaRegister_Material()
 {
     const luaL_Reg lua_members[] = 
     {
+        {"addParameter", lua_Material_addParameter},
         {"addRef", lua_Material_addRef},
-        {"clearParameter", lua_Material_clearParameter},
         {"getParameter", lua_Material_getParameter},
+        {"getParameterByIndex", lua_Material_getParameterByIndex},
+        {"getParameterCount", lua_Material_getParameterCount},
         {"getRefCount", lua_Material_getRefCount},
         {"getStateBlock", lua_Material_getStateBlock},
         {"getTechnique", lua_Material_getTechnique},
         {"getTechniqueByIndex", lua_Material_getTechniqueByIndex},
         {"getTechniqueCount", lua_Material_getTechniqueCount},
         {"release", lua_Material_release},
+        {"removeParameter", lua_Material_removeParameter},
         {"setParameterAutoBinding", lua_Material_setParameterAutoBinding},
         {"setStateBlock", lua_Material_setStateBlock},
         {"setTechnique", lua_Material_setTechnique},
@@ -97,6 +100,48 @@ int lua_Material__gc(lua_State* state)
     return 0;
 }
 
+int lua_Material_addParameter(lua_State* state)
+{
+    // Get the number of parameters.
+    int paramCount = lua_gettop(state);
+
+    // Attempt to match the parameters to a valid binding.
+    switch (paramCount)
+    {
+        case 2:
+        {
+            if ((lua_type(state, 1) == LUA_TUSERDATA) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
+            {
+                // Get parameter 1 off the stack.
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<MaterialParameter> param1 = gameplay::ScriptUtil::getObjectPointer<MaterialParameter>(2, "MaterialParameter", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'MaterialParameter'.");
+                    lua_error(state);
+                }
+
+                Material* instance = getInstance(state);
+                instance->addParameter(param1);
+                
+                return 0;
+            }
+
+            lua_pushstring(state, "lua_Material_addParameter - Failed to match the given parameters to a valid function signature.");
+            lua_error(state);
+            break;
+        }
+        default:
+        {
+            lua_pushstring(state, "Invalid number of parameters (expected 2).");
+            lua_error(state);
+            break;
+        }
+    }
+    return 0;
+}
+
 int lua_Material_addRef(lua_State* state)
 {
     // Get the number of parameters.
@@ -129,7 +174,7 @@ int lua_Material_addRef(lua_State* state)
     return 0;
 }
 
-int lua_Material_clearParameter(lua_State* state)
+int lua_Material_getParameter(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -146,12 +191,24 @@ int lua_Material_clearParameter(lua_State* state)
                 const char* param1 = gameplay::ScriptUtil::getString(2, false);
 
                 Material* instance = getInstance(state);
-                instance->clearParameter(param1);
-                
-                return 0;
+                void* returnPtr = (void*)instance->getParameter(param1);
+                if (returnPtr)
+                {
+                    gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "MaterialParameter");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
+
+                return 1;
             }
 
-            lua_pushstring(state, "lua_Material_clearParameter - Failed to match the given parameters to a valid function signature.");
+            lua_pushstring(state, "lua_Material_getParameter - Failed to match the given parameters to a valid function signature.");
             lua_error(state);
             break;
         }
@@ -165,7 +222,7 @@ int lua_Material_clearParameter(lua_State* state)
     return 0;
 }
 
-int lua_Material_getParameter(lua_State* state)
+int lua_Material_getParameterByIndex(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -176,13 +233,13 @@ int lua_Material_getParameter(lua_State* state)
         case 2:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
+                lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
 
                 Material* instance = getInstance(state);
-                void* returnPtr = (void*)instance->getParameter(param1);
+                void* returnPtr = (void*)instance->getParameterByIndex(param1);
                 if (returnPtr)
                 {
                     gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
@@ -199,7 +256,7 @@ int lua_Material_getParameter(lua_State* state)
                 return 1;
             }
 
-            lua_pushstring(state, "lua_Material_getParameter - Failed to match the given parameters to a valid function signature.");
+            lua_pushstring(state, "lua_Material_getParameterByIndex - Failed to match the given parameters to a valid function signature.");
             lua_error(state);
             break;
         }
@@ -213,6 +270,41 @@ int lua_Material_getParameter(lua_State* state)
     return 0;
 }
 
+int lua_Material_getParameterCount(lua_State* state)
+{
+    // Get the number of parameters.
+    int paramCount = lua_gettop(state);
+
+    // Attempt to match the parameters to a valid binding.
+    switch (paramCount)
+    {
+        case 1:
+        {
+            if ((lua_type(state, 1) == LUA_TUSERDATA))
+            {
+                Material* instance = getInstance(state);
+                unsigned int result = instance->getParameterCount();
+
+                // Push the return value onto the stack.
+                lua_pushunsigned(state, result);
+
+                return 1;
+            }
+
+            lua_pushstring(state, "lua_Material_getParameterCount - Failed to match the given parameters to a valid function signature.");
+            lua_error(state);
+            break;
+        }
+        default:
+        {
+            lua_pushstring(state, "Invalid number of parameters (expected 1).");
+            lua_error(state);
+            break;
+        }
+    }
+    return 0;
+}
+
 int lua_Material_getRefCount(lua_State* state)
 {
     // Get the number of parameters.
@@ -487,6 +579,42 @@ int lua_Material_release(lua_State* state)
     return 0;
 }
 
+int lua_Material_removeParameter(lua_State* state)
+{
+    // Get the number of parameters.
+    int paramCount = lua_gettop(state);
+
+    // Attempt to match the parameters to a valid binding.
+    switch (paramCount)
+    {
+        case 2:
+        {
+            if ((lua_type(state, 1) == LUA_TUSERDATA) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
+            {
+                // Get parameter 1 off the stack.
+                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+
+                Material* instance = getInstance(state);
+                instance->removeParameter(param1);
+                
+                return 0;
+            }
+
+            lua_pushstring(state, "lua_Material_removeParameter - Failed to match the given parameters to a valid function signature.");
+            lua_error(state);
+            break;
+        }
+        default:
+        {
+            lua_pushstring(state, "Invalid number of parameters (expected 2).");
+            lua_error(state);
+            break;
+        }
+    }
+    return 0;
+}
+
 int lua_Material_setParameterAutoBinding(lua_State* state)
 {
     // Get the number of parameters.

+ 4 - 1
gameplay/src/lua/lua_Material.h

@@ -6,15 +6,18 @@ namespace gameplay
 
 // Lua bindings for Material.
 int lua_Material__gc(lua_State* state);
+int lua_Material_addParameter(lua_State* state);
 int lua_Material_addRef(lua_State* state);
-int lua_Material_clearParameter(lua_State* state);
 int lua_Material_getParameter(lua_State* state);
+int lua_Material_getParameterByIndex(lua_State* state);
+int lua_Material_getParameterCount(lua_State* state);
 int lua_Material_getRefCount(lua_State* state);
 int lua_Material_getStateBlock(lua_State* state);
 int lua_Material_getTechnique(lua_State* state);
 int lua_Material_getTechniqueByIndex(lua_State* state);
 int lua_Material_getTechniqueCount(lua_State* state);
 int lua_Material_release(lua_State* state);
+int lua_Material_removeParameter(lua_State* state);
 int lua_Material_setParameterAutoBinding(lua_State* state);
 int lua_Material_setStateBlock(lua_State* state);
 int lua_Material_setTechnique(lua_State* state);

+ 148 - 20
gameplay/src/lua/lua_Pass.cpp

@@ -25,16 +25,19 @@ void luaRegister_Pass()
 {
     const luaL_Reg lua_members[] = 
     {
+        {"addParameter", lua_Pass_addParameter},
         {"addRef", lua_Pass_addRef},
         {"bind", lua_Pass_bind},
-        {"clearParameter", lua_Pass_clearParameter},
         {"getEffect", lua_Pass_getEffect},
         {"getId", lua_Pass_getId},
         {"getParameter", lua_Pass_getParameter},
+        {"getParameterByIndex", lua_Pass_getParameterByIndex},
+        {"getParameterCount", lua_Pass_getParameterCount},
         {"getRefCount", lua_Pass_getRefCount},
         {"getStateBlock", lua_Pass_getStateBlock},
         {"getVertexAttributeBinding", lua_Pass_getVertexAttributeBinding},
         {"release", lua_Pass_release},
+        {"removeParameter", lua_Pass_removeParameter},
         {"setParameterAutoBinding", lua_Pass_setParameterAutoBinding},
         {"setStateBlock", lua_Pass_setStateBlock},
         {"setVertexAttributeBinding", lua_Pass_setVertexAttributeBinding},
@@ -92,7 +95,7 @@ int lua_Pass__gc(lua_State* state)
     return 0;
 }
 
-int lua_Pass_addRef(lua_State* state)
+int lua_Pass_addParameter(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -100,23 +103,33 @@ int lua_Pass_addRef(lua_State* state)
     // Attempt to match the parameters to a valid binding.
     switch (paramCount)
     {
-        case 1:
+        case 2:
         {
-            if ((lua_type(state, 1) == LUA_TUSERDATA))
+            if ((lua_type(state, 1) == LUA_TUSERDATA) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
             {
+                // Get parameter 1 off the stack.
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<MaterialParameter> param1 = gameplay::ScriptUtil::getObjectPointer<MaterialParameter>(2, "MaterialParameter", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'MaterialParameter'.");
+                    lua_error(state);
+                }
+
                 Pass* instance = getInstance(state);
-                instance->addRef();
+                instance->addParameter(param1);
                 
                 return 0;
             }
 
-            lua_pushstring(state, "lua_Pass_addRef - Failed to match the given parameters to a valid function signature.");
+            lua_pushstring(state, "lua_Pass_addParameter - Failed to match the given parameters to a valid function signature.");
             lua_error(state);
             break;
         }
         default:
         {
-            lua_pushstring(state, "Invalid number of parameters (expected 1).");
+            lua_pushstring(state, "Invalid number of parameters (expected 2).");
             lua_error(state);
             break;
         }
@@ -124,7 +137,7 @@ int lua_Pass_addRef(lua_State* state)
     return 0;
 }
 
-int lua_Pass_bind(lua_State* state)
+int lua_Pass_addRef(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -137,12 +150,12 @@ int lua_Pass_bind(lua_State* state)
             if ((lua_type(state, 1) == LUA_TUSERDATA))
             {
                 Pass* instance = getInstance(state);
-                instance->bind();
+                instance->addRef();
                 
                 return 0;
             }
 
-            lua_pushstring(state, "lua_Pass_bind - Failed to match the given parameters to a valid function signature.");
+            lua_pushstring(state, "lua_Pass_addRef - Failed to match the given parameters to a valid function signature.");
             lua_error(state);
             break;
         }
@@ -156,7 +169,7 @@ int lua_Pass_bind(lua_State* state)
     return 0;
 }
 
-int lua_Pass_clearParameter(lua_State* state)
+int lua_Pass_bind(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -164,27 +177,23 @@ int lua_Pass_clearParameter(lua_State* state)
     // Attempt to match the parameters to a valid binding.
     switch (paramCount)
     {
-        case 2:
+        case 1:
         {
-            if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
+            if ((lua_type(state, 1) == LUA_TUSERDATA))
             {
-                // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
-
                 Pass* instance = getInstance(state);
-                instance->clearParameter(param1);
+                instance->bind();
                 
                 return 0;
             }
 
-            lua_pushstring(state, "lua_Pass_clearParameter - Failed to match the given parameters to a valid function signature.");
+            lua_pushstring(state, "lua_Pass_bind - Failed to match the given parameters to a valid function signature.");
             lua_error(state);
             break;
         }
         default:
         {
-            lua_pushstring(state, "Invalid number of parameters (expected 2).");
+            lua_pushstring(state, "Invalid number of parameters (expected 1).");
             lua_error(state);
             break;
         }
@@ -319,6 +328,89 @@ int lua_Pass_getParameter(lua_State* state)
     return 0;
 }
 
+int lua_Pass_getParameterByIndex(lua_State* state)
+{
+    // Get the number of parameters.
+    int paramCount = lua_gettop(state);
+
+    // Attempt to match the parameters to a valid binding.
+    switch (paramCount)
+    {
+        case 2:
+        {
+            if ((lua_type(state, 1) == LUA_TUSERDATA) &&
+                lua_type(state, 2) == LUA_TNUMBER)
+            {
+                // Get parameter 1 off the stack.
+                unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
+
+                Pass* instance = getInstance(state);
+                void* returnPtr = (void*)instance->getParameterByIndex(param1);
+                if (returnPtr)
+                {
+                    gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "MaterialParameter");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
+
+                return 1;
+            }
+
+            lua_pushstring(state, "lua_Pass_getParameterByIndex - Failed to match the given parameters to a valid function signature.");
+            lua_error(state);
+            break;
+        }
+        default:
+        {
+            lua_pushstring(state, "Invalid number of parameters (expected 2).");
+            lua_error(state);
+            break;
+        }
+    }
+    return 0;
+}
+
+int lua_Pass_getParameterCount(lua_State* state)
+{
+    // Get the number of parameters.
+    int paramCount = lua_gettop(state);
+
+    // Attempt to match the parameters to a valid binding.
+    switch (paramCount)
+    {
+        case 1:
+        {
+            if ((lua_type(state, 1) == LUA_TUSERDATA))
+            {
+                Pass* instance = getInstance(state);
+                unsigned int result = instance->getParameterCount();
+
+                // Push the return value onto the stack.
+                lua_pushunsigned(state, result);
+
+                return 1;
+            }
+
+            lua_pushstring(state, "lua_Pass_getParameterCount - Failed to match the given parameters to a valid function signature.");
+            lua_error(state);
+            break;
+        }
+        default:
+        {
+            lua_pushstring(state, "Invalid number of parameters (expected 1).");
+            lua_error(state);
+            break;
+        }
+    }
+    return 0;
+}
+
 int lua_Pass_getRefCount(lua_State* state)
 {
     // Get the number of parameters.
@@ -474,6 +566,42 @@ int lua_Pass_release(lua_State* state)
     return 0;
 }
 
+int lua_Pass_removeParameter(lua_State* state)
+{
+    // Get the number of parameters.
+    int paramCount = lua_gettop(state);
+
+    // Attempt to match the parameters to a valid binding.
+    switch (paramCount)
+    {
+        case 2:
+        {
+            if ((lua_type(state, 1) == LUA_TUSERDATA) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
+            {
+                // Get parameter 1 off the stack.
+                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+
+                Pass* instance = getInstance(state);
+                instance->removeParameter(param1);
+                
+                return 0;
+            }
+
+            lua_pushstring(state, "lua_Pass_removeParameter - Failed to match the given parameters to a valid function signature.");
+            lua_error(state);
+            break;
+        }
+        default:
+        {
+            lua_pushstring(state, "Invalid number of parameters (expected 2).");
+            lua_error(state);
+            break;
+        }
+    }
+    return 0;
+}
+
 int lua_Pass_setParameterAutoBinding(lua_State* state)
 {
     // Get the number of parameters.

+ 4 - 1
gameplay/src/lua/lua_Pass.h

@@ -6,16 +6,19 @@ namespace gameplay
 
 // Lua bindings for Pass.
 int lua_Pass__gc(lua_State* state);
+int lua_Pass_addParameter(lua_State* state);
 int lua_Pass_addRef(lua_State* state);
 int lua_Pass_bind(lua_State* state);
-int lua_Pass_clearParameter(lua_State* state);
 int lua_Pass_getEffect(lua_State* state);
 int lua_Pass_getId(lua_State* state);
 int lua_Pass_getParameter(lua_State* state);
+int lua_Pass_getParameterByIndex(lua_State* state);
+int lua_Pass_getParameterCount(lua_State* state);
 int lua_Pass_getRefCount(lua_State* state);
 int lua_Pass_getStateBlock(lua_State* state);
 int lua_Pass_getVertexAttributeBinding(lua_State* state);
 int lua_Pass_release(lua_State* state);
+int lua_Pass_removeParameter(lua_State* state);
 int lua_Pass_setParameterAutoBinding(lua_State* state);
 int lua_Pass_setStateBlock(lua_State* state);
 int lua_Pass_setVertexAttributeBinding(lua_State* state);

+ 139 - 11
gameplay/src/lua/lua_RenderState.cpp

@@ -24,12 +24,15 @@ void luaRegister_RenderState()
 {
     const luaL_Reg lua_members[] = 
     {
+        {"addParameter", lua_RenderState_addParameter},
         {"addRef", lua_RenderState_addRef},
-        {"clearParameter", lua_RenderState_clearParameter},
         {"getParameter", lua_RenderState_getParameter},
+        {"getParameterByIndex", lua_RenderState_getParameterByIndex},
+        {"getParameterCount", lua_RenderState_getParameterCount},
         {"getRefCount", lua_RenderState_getRefCount},
         {"getStateBlock", lua_RenderState_getStateBlock},
         {"release", lua_RenderState_release},
+        {"removeParameter", lua_RenderState_removeParameter},
         {"setParameterAutoBinding", lua_RenderState_setParameterAutoBinding},
         {"setStateBlock", lua_RenderState_setStateBlock},
         {NULL, NULL}
@@ -85,6 +88,48 @@ int lua_RenderState__gc(lua_State* state)
     return 0;
 }
 
+int lua_RenderState_addParameter(lua_State* state)
+{
+    // Get the number of parameters.
+    int paramCount = lua_gettop(state);
+
+    // Attempt to match the parameters to a valid binding.
+    switch (paramCount)
+    {
+        case 2:
+        {
+            if ((lua_type(state, 1) == LUA_TUSERDATA) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
+            {
+                // Get parameter 1 off the stack.
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<MaterialParameter> param1 = gameplay::ScriptUtil::getObjectPointer<MaterialParameter>(2, "MaterialParameter", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'MaterialParameter'.");
+                    lua_error(state);
+                }
+
+                RenderState* instance = getInstance(state);
+                instance->addParameter(param1);
+                
+                return 0;
+            }
+
+            lua_pushstring(state, "lua_RenderState_addParameter - Failed to match the given parameters to a valid function signature.");
+            lua_error(state);
+            break;
+        }
+        default:
+        {
+            lua_pushstring(state, "Invalid number of parameters (expected 2).");
+            lua_error(state);
+            break;
+        }
+    }
+    return 0;
+}
+
 int lua_RenderState_addRef(lua_State* state)
 {
     // Get the number of parameters.
@@ -117,7 +162,7 @@ int lua_RenderState_addRef(lua_State* state)
     return 0;
 }
 
-int lua_RenderState_clearParameter(lua_State* state)
+int lua_RenderState_getParameter(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -134,12 +179,24 @@ int lua_RenderState_clearParameter(lua_State* state)
                 const char* param1 = gameplay::ScriptUtil::getString(2, false);
 
                 RenderState* instance = getInstance(state);
-                instance->clearParameter(param1);
-                
-                return 0;
+                void* returnPtr = (void*)instance->getParameter(param1);
+                if (returnPtr)
+                {
+                    gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "MaterialParameter");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
+
+                return 1;
             }
 
-            lua_pushstring(state, "lua_RenderState_clearParameter - Failed to match the given parameters to a valid function signature.");
+            lua_pushstring(state, "lua_RenderState_getParameter - Failed to match the given parameters to a valid function signature.");
             lua_error(state);
             break;
         }
@@ -153,7 +210,7 @@ int lua_RenderState_clearParameter(lua_State* state)
     return 0;
 }
 
-int lua_RenderState_getParameter(lua_State* state)
+int lua_RenderState_getParameterByIndex(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -164,13 +221,13 @@ int lua_RenderState_getParameter(lua_State* state)
         case 2:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
+                lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+                unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
 
                 RenderState* instance = getInstance(state);
-                void* returnPtr = (void*)instance->getParameter(param1);
+                void* returnPtr = (void*)instance->getParameterByIndex(param1);
                 if (returnPtr)
                 {
                     gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
@@ -187,7 +244,7 @@ int lua_RenderState_getParameter(lua_State* state)
                 return 1;
             }
 
-            lua_pushstring(state, "lua_RenderState_getParameter - Failed to match the given parameters to a valid function signature.");
+            lua_pushstring(state, "lua_RenderState_getParameterByIndex - Failed to match the given parameters to a valid function signature.");
             lua_error(state);
             break;
         }
@@ -201,6 +258,41 @@ int lua_RenderState_getParameter(lua_State* state)
     return 0;
 }
 
+int lua_RenderState_getParameterCount(lua_State* state)
+{
+    // Get the number of parameters.
+    int paramCount = lua_gettop(state);
+
+    // Attempt to match the parameters to a valid binding.
+    switch (paramCount)
+    {
+        case 1:
+        {
+            if ((lua_type(state, 1) == LUA_TUSERDATA))
+            {
+                RenderState* instance = getInstance(state);
+                unsigned int result = instance->getParameterCount();
+
+                // Push the return value onto the stack.
+                lua_pushunsigned(state, result);
+
+                return 1;
+            }
+
+            lua_pushstring(state, "lua_RenderState_getParameterCount - Failed to match the given parameters to a valid function signature.");
+            lua_error(state);
+            break;
+        }
+        default:
+        {
+            lua_pushstring(state, "Invalid number of parameters (expected 1).");
+            lua_error(state);
+            break;
+        }
+    }
+    return 0;
+}
+
 int lua_RenderState_getRefCount(lua_State* state)
 {
     // Get the number of parameters.
@@ -312,6 +404,42 @@ int lua_RenderState_release(lua_State* state)
     return 0;
 }
 
+int lua_RenderState_removeParameter(lua_State* state)
+{
+    // Get the number of parameters.
+    int paramCount = lua_gettop(state);
+
+    // Attempt to match the parameters to a valid binding.
+    switch (paramCount)
+    {
+        case 2:
+        {
+            if ((lua_type(state, 1) == LUA_TUSERDATA) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
+            {
+                // Get parameter 1 off the stack.
+                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+
+                RenderState* instance = getInstance(state);
+                instance->removeParameter(param1);
+                
+                return 0;
+            }
+
+            lua_pushstring(state, "lua_RenderState_removeParameter - Failed to match the given parameters to a valid function signature.");
+            lua_error(state);
+            break;
+        }
+        default:
+        {
+            lua_pushstring(state, "Invalid number of parameters (expected 2).");
+            lua_error(state);
+            break;
+        }
+    }
+    return 0;
+}
+
 int lua_RenderState_setParameterAutoBinding(lua_State* state)
 {
     // Get the number of parameters.

+ 4 - 1
gameplay/src/lua/lua_RenderState.h

@@ -6,12 +6,15 @@ namespace gameplay
 
 // Lua bindings for RenderState.
 int lua_RenderState__gc(lua_State* state);
+int lua_RenderState_addParameter(lua_State* state);
 int lua_RenderState_addRef(lua_State* state);
-int lua_RenderState_clearParameter(lua_State* state);
 int lua_RenderState_getParameter(lua_State* state);
+int lua_RenderState_getParameterByIndex(lua_State* state);
+int lua_RenderState_getParameterCount(lua_State* state);
 int lua_RenderState_getRefCount(lua_State* state);
 int lua_RenderState_getStateBlock(lua_State* state);
 int lua_RenderState_release(lua_State* state);
+int lua_RenderState_removeParameter(lua_State* state);
 int lua_RenderState_setParameterAutoBinding(lua_State* state);
 int lua_RenderState_setStateBlock(lua_State* state);
 

+ 145 - 17
gameplay/src/lua/lua_Technique.cpp

@@ -25,16 +25,19 @@ void luaRegister_Technique()
 {
     const luaL_Reg lua_members[] = 
     {
+        {"addParameter", lua_Technique_addParameter},
         {"addRef", lua_Technique_addRef},
-        {"clearParameter", lua_Technique_clearParameter},
         {"getId", lua_Technique_getId},
         {"getParameter", lua_Technique_getParameter},
+        {"getParameterByIndex", lua_Technique_getParameterByIndex},
+        {"getParameterCount", lua_Technique_getParameterCount},
         {"getPass", lua_Technique_getPass},
         {"getPassByIndex", lua_Technique_getPassByIndex},
         {"getPassCount", lua_Technique_getPassCount},
         {"getRefCount", lua_Technique_getRefCount},
         {"getStateBlock", lua_Technique_getStateBlock},
         {"release", lua_Technique_release},
+        {"removeParameter", lua_Technique_removeParameter},
         {"setParameterAutoBinding", lua_Technique_setParameterAutoBinding},
         {"setStateBlock", lua_Technique_setStateBlock},
         {NULL, NULL}
@@ -90,7 +93,7 @@ int lua_Technique__gc(lua_State* state)
     return 0;
 }
 
-int lua_Technique_addRef(lua_State* state)
+int lua_Technique_addParameter(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -98,23 +101,33 @@ int lua_Technique_addRef(lua_State* state)
     // Attempt to match the parameters to a valid binding.
     switch (paramCount)
     {
-        case 1:
+        case 2:
         {
-            if ((lua_type(state, 1) == LUA_TUSERDATA))
+            if ((lua_type(state, 1) == LUA_TUSERDATA) &&
+                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
             {
+                // Get parameter 1 off the stack.
+                bool param1Valid;
+                gameplay::ScriptUtil::LuaArray<MaterialParameter> param1 = gameplay::ScriptUtil::getObjectPointer<MaterialParameter>(2, "MaterialParameter", false, &param1Valid);
+                if (!param1Valid)
+                {
+                    lua_pushstring(state, "Failed to convert parameter 1 to type 'MaterialParameter'.");
+                    lua_error(state);
+                }
+
                 Technique* instance = getInstance(state);
-                instance->addRef();
+                instance->addParameter(param1);
                 
                 return 0;
             }
 
-            lua_pushstring(state, "lua_Technique_addRef - Failed to match the given parameters to a valid function signature.");
+            lua_pushstring(state, "lua_Technique_addParameter - Failed to match the given parameters to a valid function signature.");
             lua_error(state);
             break;
         }
         default:
         {
-            lua_pushstring(state, "Invalid number of parameters (expected 1).");
+            lua_pushstring(state, "Invalid number of parameters (expected 2).");
             lua_error(state);
             break;
         }
@@ -122,7 +135,7 @@ int lua_Technique_addRef(lua_State* state)
     return 0;
 }
 
-int lua_Technique_clearParameter(lua_State* state)
+int lua_Technique_addRef(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -130,27 +143,23 @@ int lua_Technique_clearParameter(lua_State* state)
     // Attempt to match the parameters to a valid binding.
     switch (paramCount)
     {
-        case 2:
+        case 1:
         {
-            if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
+            if ((lua_type(state, 1) == LUA_TUSERDATA))
             {
-                // Get parameter 1 off the stack.
-                const char* param1 = gameplay::ScriptUtil::getString(2, false);
-
                 Technique* instance = getInstance(state);
-                instance->clearParameter(param1);
+                instance->addRef();
                 
                 return 0;
             }
 
-            lua_pushstring(state, "lua_Technique_clearParameter - Failed to match the given parameters to a valid function signature.");
+            lua_pushstring(state, "lua_Technique_addRef - Failed to match the given parameters to a valid function signature.");
             lua_error(state);
             break;
         }
         default:
         {
-            lua_pushstring(state, "Invalid number of parameters (expected 2).");
+            lua_pushstring(state, "Invalid number of parameters (expected 1).");
             lua_error(state);
             break;
         }
@@ -241,6 +250,89 @@ int lua_Technique_getParameter(lua_State* state)
     return 0;
 }
 
+int lua_Technique_getParameterByIndex(lua_State* state)
+{
+    // Get the number of parameters.
+    int paramCount = lua_gettop(state);
+
+    // Attempt to match the parameters to a valid binding.
+    switch (paramCount)
+    {
+        case 2:
+        {
+            if ((lua_type(state, 1) == LUA_TUSERDATA) &&
+                lua_type(state, 2) == LUA_TNUMBER)
+            {
+                // Get parameter 1 off the stack.
+                unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
+
+                Technique* instance = getInstance(state);
+                void* returnPtr = (void*)instance->getParameterByIndex(param1);
+                if (returnPtr)
+                {
+                    gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "MaterialParameter");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
+
+                return 1;
+            }
+
+            lua_pushstring(state, "lua_Technique_getParameterByIndex - Failed to match the given parameters to a valid function signature.");
+            lua_error(state);
+            break;
+        }
+        default:
+        {
+            lua_pushstring(state, "Invalid number of parameters (expected 2).");
+            lua_error(state);
+            break;
+        }
+    }
+    return 0;
+}
+
+int lua_Technique_getParameterCount(lua_State* state)
+{
+    // Get the number of parameters.
+    int paramCount = lua_gettop(state);
+
+    // Attempt to match the parameters to a valid binding.
+    switch (paramCount)
+    {
+        case 1:
+        {
+            if ((lua_type(state, 1) == LUA_TUSERDATA))
+            {
+                Technique* instance = getInstance(state);
+                unsigned int result = instance->getParameterCount();
+
+                // Push the return value onto the stack.
+                lua_pushunsigned(state, result);
+
+                return 1;
+            }
+
+            lua_pushstring(state, "lua_Technique_getParameterCount - Failed to match the given parameters to a valid function signature.");
+            lua_error(state);
+            break;
+        }
+        default:
+        {
+            lua_pushstring(state, "Invalid number of parameters (expected 1).");
+            lua_error(state);
+            break;
+        }
+    }
+    return 0;
+}
+
 int lua_Technique_getPass(lua_State* state)
 {
     // Get the number of parameters.
@@ -483,6 +575,42 @@ int lua_Technique_release(lua_State* state)
     return 0;
 }
 
+int lua_Technique_removeParameter(lua_State* state)
+{
+    // Get the number of parameters.
+    int paramCount = lua_gettop(state);
+
+    // Attempt to match the parameters to a valid binding.
+    switch (paramCount)
+    {
+        case 2:
+        {
+            if ((lua_type(state, 1) == LUA_TUSERDATA) &&
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
+            {
+                // Get parameter 1 off the stack.
+                const char* param1 = gameplay::ScriptUtil::getString(2, false);
+
+                Technique* instance = getInstance(state);
+                instance->removeParameter(param1);
+                
+                return 0;
+            }
+
+            lua_pushstring(state, "lua_Technique_removeParameter - Failed to match the given parameters to a valid function signature.");
+            lua_error(state);
+            break;
+        }
+        default:
+        {
+            lua_pushstring(state, "Invalid number of parameters (expected 2).");
+            lua_error(state);
+            break;
+        }
+    }
+    return 0;
+}
+
 int lua_Technique_setParameterAutoBinding(lua_State* state)
 {
     // Get the number of parameters.

+ 4 - 1
gameplay/src/lua/lua_Technique.h

@@ -6,16 +6,19 @@ namespace gameplay
 
 // Lua bindings for Technique.
 int lua_Technique__gc(lua_State* state);
+int lua_Technique_addParameter(lua_State* state);
 int lua_Technique_addRef(lua_State* state);
-int lua_Technique_clearParameter(lua_State* state);
 int lua_Technique_getId(lua_State* state);
 int lua_Technique_getParameter(lua_State* state);
+int lua_Technique_getParameterByIndex(lua_State* state);
+int lua_Technique_getParameterCount(lua_State* state);
 int lua_Technique_getPass(lua_State* state);
 int lua_Technique_getPassByIndex(lua_State* state);
 int lua_Technique_getPassCount(lua_State* state);
 int lua_Technique_getRefCount(lua_State* state);
 int lua_Technique_getStateBlock(lua_State* state);
 int lua_Technique_release(lua_State* state);
+int lua_Technique_removeParameter(lua_State* state);
 int lua_Technique_setParameterAutoBinding(lua_State* state);
 int lua_Technique_setStateBlock(lua_State* state);
 

+ 11 - 6
samples/browser/src/TerrainSample.cpp

@@ -43,6 +43,7 @@ void TerrainSample::initialize()
 	_scene = Scene::load("res/common/terrain/sample.scene");
 	_terrain = _scene->findNode("terrain")->getTerrain();
     _sky = _scene->findNode("sky");
+    _sky->setTag("lighting", "none");
 
     // Load shapes
     Bundle* bundle;
@@ -81,18 +82,22 @@ void TerrainSample::initialize()
     Node* lightNode = Node::create("directionalLight");
     _scene->addNode(lightNode);
     lightNode->setLight(_directionalLight);
-    lightNode->setRotation(Vector3(1, 0, 0), -MATH_DEG_TO_RAD(90));
+    lightNode->setRotation(Vector3(1, 0, 0), -MATH_DEG_TO_RAD(45));
     
     _scene->visit(this, &TerrainSample::intializeLights);
 }
 
 void initializeLight(Material* material, Light* light)
 {
-    // For this sample we will only bind a single light to each object in the scene.
-    MaterialParameter* colorParam = material->getParameter("u_directionalLightColor[0]");
-    colorParam->setValue(light->getColor());
-    MaterialParameter* directionParam = material->getParameter("u_directionalLightDirection[0]");
-    directionParam->bindValue(light->getNode(), &Node::getForwardVectorWorld);
+    if (material->getTechnique()->getPassByIndex(0)->getEffect()->getUniform("u_directionalLightDirection[0]"))
+    {
+        // For this sample we will only bind a single light to each object in the scene.
+        MaterialParameter* colorParam = material->getParameter("u_directionalLightColor[0]");
+        colorParam->setValue(light->getColor());
+
+        MaterialParameter* directionParam = material->getParameter("u_directionalLightDirection[0]");
+        directionParam->bindValue(light->getNode(), &Node::getForwardVectorWorld);
+    }
 }
 
 bool TerrainSample::intializeLights(Node* node)