Browse Source

Shader parameters are no longer hardcoded.

Lasse Öörni 14 years ago
parent
commit
ced7b62889

+ 7 - 14
Engine/Engine/GraphicsAPI.cpp

@@ -239,14 +239,14 @@ static void RegisterTextures(asIScriptEngine* engine)
     engine->RegisterObjectMethod("TextureCube", "RenderSurface@+ get_renderSurface(CubeMapFace) const", asMETHOD(TextureCube, GetRenderSurface), asCALL_THISCALL);
 }
 
-static Vector4 MaterialGetShaderParameter(ShaderParameter parameter, Material* ptr)
+static Vector4 MaterialGetShaderParameter(const String& name, Material* ptr)
 {
-    const HashMap<ShaderParameter, Vector4>& parameters = ptr->GetShaderParameters();
-    HashMap<ShaderParameter, Vector4>::ConstIterator i = parameters.Find(parameter);
+    const HashMap<StringHash, MaterialShaderParameter>& parameters = ptr->GetShaderParameters();
+    HashMap<StringHash, MaterialShaderParameter>::ConstIterator i = parameters.Find(StringHash(name));
     if (i == parameters.End())
         return Vector4::ZERO;
     else
-        return i->second_;
+        return i->second_.value_;
 }
 
 static Material* MaterialClone(const String& cloneName, Material* ptr)
@@ -260,13 +260,6 @@ static Material* MaterialClone(const String& cloneName, Material* ptr)
 
 static void RegisterMaterial(asIScriptEngine* engine)
 {
-    engine->RegisterEnum("ShaderParameter");
-    engine->RegisterEnumValue("ShaderParameter", "VSP_UOFFSET", VSP_UOFFSET);
-    engine->RegisterEnumValue("ShaderParameter", "VSP_VOFFSET", VSP_VOFFSET);
-    engine->RegisterEnumValue("ShaderParameter", "PSP_MATDIFFCOLOR", PSP_MATDIFFCOLOR);
-    engine->RegisterEnumValue("ShaderParameter", "PSP_MATEMISSIVECOLOR", PSP_MATEMISSIVECOLOR);
-    engine->RegisterEnumValue("ShaderParameter", "PSP_MATSPECPROPERTIES", PSP_MATSPECPROPERTIES);
-    
     engine->RegisterEnum("TextureUnit");
     engine->RegisterEnumValue("TextureUnit", "TU_DIFFUSE", TU_DIFFUSE);
     engine->RegisterEnumValue("TextureUnit", "TU_NORMAL", TU_NORMAL);
@@ -336,13 +329,13 @@ static void RegisterMaterial(asIScriptEngine* engine)
     RegisterResource<Material>(engine, "Material");
     engine->RegisterObjectMethod("Material", "void SetUVTransform(const Vector2&in, float, const Vector2&in)", asMETHODPR(Material, SetUVTransform, (const Vector2&, float, const Vector2&), void), asCALL_THISCALL);
     engine->RegisterObjectMethod("Material", "void SetUVTransform(const Vector2&in, float, float)", asMETHODPR(Material, SetUVTransform, (const Vector2&, float, float), void), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Material", "void RemoveShaderParameter(ShaderParameter)", asMETHOD(Material, RemoveShaderParameter), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Material", "void RemoveShaderParameter(const String&in)", asMETHOD(Material, RemoveShaderParameter), asCALL_THISCALL);
     engine->RegisterObjectMethod("Material", "Material@ Clone(const String&in) const", asFUNCTION(MaterialClone), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod("Material", "void set_numTechniques(uint)", asMETHOD(Material, SetNumTechniques), asCALL_THISCALL);
     engine->RegisterObjectMethod("Material", "uint get_numTechniques() const", asMETHOD(Material, GetNumTechniques), asCALL_THISCALL);
     engine->RegisterObjectMethod("Material", "Technique@+ get_technique(uint)", asMETHOD(Material, GetTechnique), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Material", "void set_shaderParameter(ShaderParameter, const Vector4&in)", asMETHOD(Material, SetShaderParameter), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Material", "Vector4 get_shaderParameter(ShaderParameter) const", asFUNCTION(MaterialGetShaderParameter), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod("Material", "void set_shaderParameter(const String&in, const Vector4&in)", asMETHOD(Material, SetShaderParameter), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Material", "Vector4 get_shaderParameter(const String&in) const", asFUNCTION(MaterialGetShaderParameter), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod("Material", "void set_texture(TextureUnit, Texture@+)", asMETHOD(Material, SetTexture), asCALL_THISCALL);
     engine->RegisterObjectMethod("Material", "Texture@+ get_texture(TextureUnit) const", asMETHOD(Material, GetTexture), asCALL_THISCALL);
     engine->RegisterObjectMethod("Material", "bool get_occlusion()", asMETHOD(Material, GetOcclusion), asCALL_THISCALL);

+ 7 - 7
Engine/Graphics/Batch.cpp

@@ -71,7 +71,7 @@ void Batch::CalculateSortKey()
         (((unsigned long long)material) << 16) | geometry;
 }
 
-void Batch::Prepare(Graphics* graphics, const HashMap<ShaderParameter, Vector4>& shaderParameters, bool setModelTransform) const
+void Batch::Prepare(Graphics* graphics, const HashMap<StringHash, Vector4>& shaderParameters, bool setModelTransform) const
 {
     if (!vertexShader_ || !pixelShader_)
         return;
@@ -94,7 +94,7 @@ void Batch::Prepare(Graphics* graphics, const HashMap<ShaderParameter, Vector4>&
     graphics->SetShaders(vertexShader_, pixelShader_);
     
     // Set global shader parameters
-    for (HashMap<ShaderParameter, Vector4>::ConstIterator i = shaderParameters.Begin(); i != shaderParameters.End(); ++i)
+    for (HashMap<StringHash, Vector4>::ConstIterator i = shaderParameters.Begin(); i != shaderParameters.End(); ++i)
     {
         if (graphics->NeedParameterUpdate(i->first_, &shaderParameters))
             graphics->SetShaderParameter(i->first_, i->second_);
@@ -328,11 +328,11 @@ void Batch::Prepare(Graphics* graphics, const HashMap<ShaderParameter, Vector4>&
     // Set material-specific shader parameters and textures
     if (material_)
     {
-        const HashMap<ShaderParameter, Vector4>& parameters = material_->GetShaderParameters();
-        for (HashMap<ShaderParameter, Vector4>::ConstIterator i = parameters.Begin(); i != parameters.End(); ++i)
+        const HashMap<StringHash, MaterialShaderParameter>& parameters = material_->GetShaderParameters();
+        for (HashMap<StringHash, MaterialShaderParameter>::ConstIterator i = parameters.Begin(); i != parameters.End(); ++i)
         {
             if (graphics->NeedParameterUpdate(i->first_, material_))
-                graphics->SetShaderParameter(i->first_, i->second_);
+                graphics->SetShaderParameter(i->first_, i->second_.value_);
         }
         
         const Vector<SharedPtr<Texture> >& textures = material_->GetTextures();
@@ -365,7 +365,7 @@ void Batch::Prepare(Graphics* graphics, const HashMap<ShaderParameter, Vector4>&
     }
 }
 
-void Batch::Draw(Graphics* graphics, const HashMap<ShaderParameter, Vector4>& shaderParameters) const
+void Batch::Draw(Graphics* graphics, const HashMap<StringHash, Vector4>& shaderParameters) const
 {
     Prepare(graphics, shaderParameters);
     geometry_->Draw(graphics);
@@ -387,7 +387,7 @@ void BatchGroup::SetTransforms(void* lockedData, unsigned& freeIndex)
     freeIndex += instances_.Size();
 }
 
-void BatchGroup::Draw(Graphics* graphics, VertexBuffer* instanceBuffer, const HashMap<ShaderParameter, Vector4>& shaderParameters) const
+void BatchGroup::Draw(Graphics* graphics, VertexBuffer* instanceBuffer, const HashMap<StringHash, Vector4>& shaderParameters) const
 {
     if (!instances_.Size())
         return;

+ 3 - 3
Engine/Graphics/Batch.h

@@ -57,9 +57,9 @@ struct Batch
     /// Calculate sort key, which consists of priority flag, light, pass and geometry
     void CalculateSortKey();
     /// Prepare for rendering
-    void Prepare(Graphics* graphics, const HashMap<ShaderParameter, Vector4>& shaderParameters, bool setModelTransform = true) const;
+    void Prepare(Graphics* graphics, const HashMap<StringHash, Vector4>& shaderParameters, bool setModelTransform = true) const;
     /// Prepare and draw
-    void Draw(Graphics* graphics, const HashMap<ShaderParameter, Vector4>& shaderParameters) const;
+    void Draw(Graphics* graphics, const HashMap<StringHash, Vector4>& shaderParameters) const;
     
     /// Geometry
     Geometry* geometry_;
@@ -133,7 +133,7 @@ struct BatchGroup
     /// Pre-set the instance transforms. Buffer must be big enough to hold all transforms
     void SetTransforms(void* lockedData, unsigned& freeIndex);
     /// Prepare and draw
-    void Draw(Graphics* graphics, VertexBuffer* instanceBuffer, const HashMap<ShaderParameter, Vector4>& shaderParameters) const;
+    void Draw(Graphics* graphics, VertexBuffer* instanceBuffer, const HashMap<StringHash, Vector4>& shaderParameters) const;
     
     /// Geometry
     Geometry* geometry_;

+ 84 - 146
Engine/Graphics/Direct3D9/D3D9Graphics.cpp

@@ -145,7 +145,6 @@ static const D3DSTENCILOP d3dStencilOp[] =
     D3DSTENCILOP_DECR
 };
 
-static const String noParameter;
 static const DWORD windowStyle = WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME & ~WS_MAXIMIZEBOX;
 
 static LRESULT CALLBACK wndProc(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam);
@@ -179,7 +178,7 @@ Graphics::Graphics(Context* context) :
     defaultTextureFilterMode_(FILTER_BILINEAR)
 {
     ResetCachedState();
-    InitializeShaderParameters();
+    SetTextureUnitMappings();
     
     SubscribeToEvent(E_WINDOWMESSAGE, HANDLER(Graphics, HandleWindowMessage));
 }
@@ -942,46 +941,46 @@ void Graphics::SetShaders(ShaderVariation* vs, ShaderVariation* ps)
     }
 }
 
-void Graphics::SetShaderParameter(ShaderParameter param, const bool* data, unsigned count)
+void Graphics::SetShaderParameter(StringHash param, const bool* data, unsigned count)
 {
-    unsigned index = shaderRegisters_[param];
-    if (index >= MAX_CONSTANT_REGISTERS)
+    HashMap<StringHash, ShaderParameterInfo>::ConstIterator i = shaderParameters_.Find(param);
+    if (i == shaderParameters_.End())
         return;
     
-    if (param < PSP_AMBIENTCOLOR)
-       impl_->device_->SetVertexShaderConstantB(index, (const BOOL*)data, count);
+    if (i->second_.type_ == VS)
+       impl_->device_->SetVertexShaderConstantB(i->second_.register_, (const BOOL*)data, count);
     else
-       impl_->device_->SetPixelShaderConstantB(index, (const BOOL*)data, count);
+       impl_->device_->SetPixelShaderConstantB(i->second_.register_, (const BOOL*)data, count);
 }
 
-void Graphics::SetShaderParameter(ShaderParameter param, const float* data, unsigned count)
+void Graphics::SetShaderParameter(StringHash param, const float* data, unsigned count)
 {
-    unsigned index = shaderRegisters_[param];
-    if (index >= MAX_CONSTANT_REGISTERS)
+    HashMap<StringHash, ShaderParameterInfo>::ConstIterator i = shaderParameters_.Find(param);
+    if (i == shaderParameters_.End())
         return;
     
-    if (param < PSP_AMBIENTCOLOR)
-        impl_->device_->SetVertexShaderConstantF(index, data, count / 4);
+    if (i->second_.type_ == VS)
+        impl_->device_->SetVertexShaderConstantF(i->second_.register_, data, count / 4);
     else
-        impl_->device_->SetPixelShaderConstantF(index, data, count / 4);
+        impl_->device_->SetPixelShaderConstantF(i->second_.register_, data, count / 4);
 }
 
-void Graphics::SetShaderParameter(ShaderParameter param, const int* data, unsigned count)
+void Graphics::SetShaderParameter(StringHash param, const int* data, unsigned count)
 {
-    unsigned index = shaderRegisters_[param];
-    if (index >= MAX_CONSTANT_REGISTERS)
+    HashMap<StringHash, ShaderParameterInfo>::ConstIterator i = shaderParameters_.Find(param);
+    if (i == shaderParameters_.End())
         return;
     
-    if (param < PSP_AMBIENTCOLOR)
-        impl_->device_->SetVertexShaderConstantI(index, data, count / 4);
+    if (i->second_.type_ == VS)
+        impl_->device_->SetVertexShaderConstantI(i->second_.register_, data, count / 4);
     else
-        impl_->device_->SetPixelShaderConstantI(index, data, count / 4);
+        impl_->device_->SetPixelShaderConstantI(i->second_.register_, data, count / 4);
 }
 
-void Graphics::SetShaderParameter(ShaderParameter param, float value)
+void Graphics::SetShaderParameter(StringHash param, float value)
 {
-    unsigned index = shaderRegisters_[param];
-    if (index >= MAX_CONSTANT_REGISTERS)
+    HashMap<StringHash, ShaderParameterInfo>::ConstIterator i = shaderParameters_.Find(param);
+    if (i == shaderParameters_.End())
         return;
     
     float data[4];
@@ -991,28 +990,28 @@ void Graphics::SetShaderParameter(ShaderParameter param, float value)
     data[2] = 0.0f;
     data[3] = 0.0f;
     
-    if (param < PSP_AMBIENTCOLOR)
-        impl_->device_->SetVertexShaderConstantF(index, &data[0], 1);
+    if (i->second_.type_ == VS)
+        impl_->device_->SetVertexShaderConstantF(i->second_.register_, &data[0], 1);
     else
-        impl_->device_->SetPixelShaderConstantF(index, &data[0], 1);
+        impl_->device_->SetPixelShaderConstantF(i->second_.register_, &data[0], 1);
 }
 
-void Graphics::SetShaderParameter(ShaderParameter param, const Color& color)
+void Graphics::SetShaderParameter(StringHash param, const Color& color)
 {
-    unsigned index = shaderRegisters_[param];
-    if (index >= MAX_CONSTANT_REGISTERS)
+    HashMap<StringHash, ShaderParameterInfo>::ConstIterator i = shaderParameters_.Find(param);
+    if (i == shaderParameters_.End())
         return;
     
-    if (param < PSP_AMBIENTCOLOR)
-        impl_->device_->SetVertexShaderConstantF(index, color.GetData(), 1);
+    if (i->second_.type_ == VS)
+        impl_->device_->SetVertexShaderConstantF(i->second_.register_, color.GetData(), 1);
     else
-        impl_->device_->SetPixelShaderConstantF(index, color.GetData(), 1);
+        impl_->device_->SetPixelShaderConstantF(i->second_.register_, color.GetData(), 1);
 }
 
-void Graphics::SetShaderParameter(ShaderParameter param, const Matrix3& matrix)
+void Graphics::SetShaderParameter(StringHash param, const Matrix3& matrix)
 {
-    unsigned index = shaderRegisters_[param];
-    if (index >= MAX_CONSTANT_REGISTERS)
+    HashMap<StringHash, ShaderParameterInfo>::ConstIterator i = shaderParameters_.Find(param);
+    if (i == shaderParameters_.End())
         return;
     
     float data[12];
@@ -1030,16 +1029,16 @@ void Graphics::SetShaderParameter(ShaderParameter param, const Matrix3& matrix)
     data[10] = matrix.m22_;
     data[11] = 0.0f;
     
-    if (param < PSP_AMBIENTCOLOR)
-        impl_->device_->SetVertexShaderConstantF(index, &data[0], 3);
+    if (i->second_.type_ == VS)
+        impl_->device_->SetVertexShaderConstantF(i->second_.register_, &data[0], 3);
     else
-        impl_->device_->SetPixelShaderConstantF(index, &data[0], 3);
+        impl_->device_->SetPixelShaderConstantF(i->second_.register_, &data[0], 3);
 }
 
-void Graphics::SetShaderParameter(ShaderParameter param, const Vector3& vector)
+void Graphics::SetShaderParameter(StringHash param, const Vector3& vector)
 {
-    unsigned index = shaderRegisters_[param];
-    if (index >= MAX_CONSTANT_REGISTERS)
+    HashMap<StringHash, ShaderParameterInfo>::ConstIterator i = shaderParameters_.Find(param);
+    if (i == shaderParameters_.End())
         return;
     
     float data[4];
@@ -1049,63 +1048,73 @@ void Graphics::SetShaderParameter(ShaderParameter param, const Vector3& vector)
     data[2] = vector.z_;
     data[3] = 0.0f;
     
-    if (param < PSP_AMBIENTCOLOR)
-        impl_->device_->SetVertexShaderConstantF(index, &data[0], 1);
+    if (i->second_.type_ == VS)
+        impl_->device_->SetVertexShaderConstantF(i->second_.register_, &data[0], 1);
     else
-        impl_->device_->SetPixelShaderConstantF(index, &data[0], 1);
+        impl_->device_->SetPixelShaderConstantF(i->second_.register_, &data[0], 1);
 }
 
-void Graphics::SetShaderParameter(ShaderParameter param, const Matrix4& matrix)
+void Graphics::SetShaderParameter(StringHash param, const Matrix4& matrix)
 {
-    unsigned index = shaderRegisters_[param];
-    if (index >= MAX_CONSTANT_REGISTERS)
+    HashMap<StringHash, ShaderParameterInfo>::ConstIterator i = shaderParameters_.Find(param);
+    if (i == shaderParameters_.End())
         return;
     
-    if (param < PSP_AMBIENTCOLOR)
-        impl_->device_->SetVertexShaderConstantF(index, matrix.GetData(), 4);
+    if (i->second_.type_ == VS)
+        impl_->device_->SetVertexShaderConstantF(i->second_.register_, matrix.GetData(), 4);
     else
-        impl_->device_->SetPixelShaderConstantF(index, matrix.GetData(), 4);
+        impl_->device_->SetPixelShaderConstantF(i->second_.register_, matrix.GetData(), 4);
 }
 
-void Graphics::SetShaderParameter(ShaderParameter param, const Vector4& vector)
+void Graphics::SetShaderParameter(StringHash param, const Vector4& vector)
 {
-    unsigned index = shaderRegisters_[param];
-    if (index >= MAX_CONSTANT_REGISTERS)
+    HashMap<StringHash, ShaderParameterInfo>::ConstIterator i = shaderParameters_.Find(param);
+    if (i == shaderParameters_.End())
         return;
     
-    if (param < PSP_AMBIENTCOLOR)
-        impl_->device_->SetVertexShaderConstantF(index, vector.GetData(), 1);
+    if (i->second_.type_ == VS)
+        impl_->device_->SetVertexShaderConstantF(i->second_.register_, vector.GetData(), 1);
     else
-        impl_->device_->SetPixelShaderConstantF(index, vector.GetData(), 1);
+        impl_->device_->SetPixelShaderConstantF(i->second_.register_, vector.GetData(), 1);
 }
 
-void Graphics::SetShaderParameter(ShaderParameter param, const Matrix3x4& matrix)
+void Graphics::SetShaderParameter(StringHash param, const Matrix3x4& matrix)
 {
-    unsigned index = shaderRegisters_[param];
-    if (index >= MAX_CONSTANT_REGISTERS)
+    HashMap<StringHash, ShaderParameterInfo>::ConstIterator i = shaderParameters_.Find(param);
+    if (i == shaderParameters_.End())
         return;
     
-    if (param < PSP_AMBIENTCOLOR)
-        impl_->device_->SetVertexShaderConstantF(index, matrix.GetData(), 3);
+    if (i->second_.type_ == VS)
+        impl_->device_->SetVertexShaderConstantF(i->second_.register_, matrix.GetData(), 3);
     else
-        impl_->device_->SetPixelShaderConstantF(index, matrix.GetData(), 3);
+        impl_->device_->SetPixelShaderConstantF(i->second_.register_, matrix.GetData(), 3);
 }
 
-bool Graphics::NeedParameterUpdate(ShaderParameter param, const void* source)
+void Graphics::DefineShaderParameter(StringHash param, ShaderType type, unsigned hwReg)
 {
-    if (param < PSP_AMBIENTCOLOR)
+    shaderParameters_[param].type_ = type;
+    shaderParameters_[param].register_ = hwReg;
+}
+
+bool Graphics::NeedParameterUpdate(StringHash param, const void* source)
+{
+    HashMap<StringHash, ShaderParameterInfo>::Iterator i = shaderParameters_.Find(param);
+    if (i == shaderParameters_.End())
+        return false;
+        
+    if (i->second_.type_ == VS)
     {
-        if (vertexShader_ && vertexShader_->HasParameter(param) && lastShaderParameterSources_[param] != source)
+        if (vertexShader_ && vertexShader_->HasParameter(param) && i->second_.lastSource_ != source)
         {
-            lastShaderParameterSources_[param] = source;
+            i->second_.lastSource_ = source;
             return true;
         }
     }
     else
     {
-        if (pixelShader_ && pixelShader_->HasParameter(param) && lastShaderParameterSources_[param] != source)
+        if (pixelShader_ && pixelShader_->HasParameter(param) && i->second_.lastSource_ != source)
         {
-            lastShaderParameterSources_[param] = source;
+            i->second_.lastSource_ = source;
             return true;
         }
     }
@@ -1120,14 +1129,14 @@ bool Graphics::NeedTextureUnit(TextureUnit unit)
 
 void Graphics::ClearParameterSources()
 {
-    for (unsigned i = 0; i < MAX_SHADER_PARAMETERS; ++i)
-        lastShaderParameterSources_[i] = (const void*)M_MAX_UNSIGNED;
+    for (HashMap<StringHash, ShaderParameterInfo>::Iterator i = shaderParameters_.Begin(); i != shaderParameters_.End(); ++i)
+        i->second_.lastSource_ = (const void*)M_MAX_UNSIGNED;
 }
 
 void Graphics::ClearTransformSources()
 {
-    lastShaderParameterSources_[VSP_MODEL] = (const void*)M_MAX_UNSIGNED;
-    lastShaderParameterSources_[VSP_VIEWPROJ] = (const void*)M_MAX_UNSIGNED;
+    shaderParameters_[VSP_MODEL].lastSource_ = (const void*)M_MAX_UNSIGNED;
+    shaderParameters_[VSP_VIEWPROJ].lastSource_ = (const void*)M_MAX_UNSIGNED;
 }
 
 void Graphics::SetTexture(unsigned index, Texture* texture)
@@ -1883,44 +1892,15 @@ VertexBuffer* Graphics::GetVertexBuffer(unsigned index) const
     return index < MAX_VERTEX_STREAMS ? vertexBuffers_[index] : 0;
 }
 
-ShaderParameter Graphics::GetShaderParameter(const String& name)
-{
-    Map<String, ShaderParameter>::Iterator i = shaderParameters_.Find(name);
-    if (i != shaderParameters_.End())
-        return i->second_;
-    else
-        return MAX_SHADER_PARAMETERS;
-}
-
 TextureUnit Graphics::GetTextureUnit(const String& name)
 {
-    Map<String, TextureUnit>::Iterator i = textureUnits_.Find(name);
+    HashMap<String, TextureUnit>::Iterator i = textureUnits_.Find(name);
     if (i != textureUnits_.End())
         return i->second_;
     else
         return MAX_TEXTURE_UNITS;
 }
 
-const String& Graphics::GetShaderParameterName(ShaderParameter parameter)
-{
-    for (Map<String, ShaderParameter>::Iterator i = shaderParameters_.Begin(); i != shaderParameters_.End(); ++i)
-    {
-        if (i->second_ == parameter)
-            return i->first_;
-    }
-    return noParameter;
-}
-
-const String& Graphics::GetTextureUnitName(TextureUnit unit)
-{
-    for (Map<String, TextureUnit>::Iterator i = textureUnits_.Begin(); i != textureUnits_.End(); ++i)
-    {
-        if (i->second_ == unit)
-            return i->first_;
-    }
-    return noParameter;
-}
-
 Texture* Graphics::GetTexture(unsigned index) const
 {
     return index < MAX_TEXTURE_UNITS ? textures_[index] : 0;
@@ -2353,50 +2333,8 @@ void Graphics::ResetCachedState()
     queryIssued_ = false;
 }
 
-
-void Graphics::InitializeShaderParameters()
-{
-    // Initialize all parameters as unknown
-    for (unsigned i = 0; i < MAX_SHADER_PARAMETERS; ++i)
-        shaderRegisters_[i] = MAX_CONSTANT_REGISTERS;
-    
-    // Map parameter names
-    shaderParameters_["CameraPos"] = VSP_CAMERAPOS;
-    shaderParameters_["CameraRot"] = VSP_CAMERAROT;
-    shaderParameters_["DepthMode"] = VSP_DEPTHMODE;
-    shaderParameters_["ElapsedTime"] = VSP_ELAPSEDTIME;
-    shaderParameters_["FrustumSize"] = VSP_FRUSTUMSIZE;
-    shaderParameters_["GBufferOffsets"] = VSP_GBUFFEROFFSETS;
-    shaderParameters_["Model"] = VSP_MODEL;
-    shaderParameters_["ShadowProj"] = VSP_SHADOWPROJ;
-    shaderParameters_["SpotProj"] = VSP_SPOTPROJ;
-    shaderParameters_["ViewProj"] = VSP_VIEWPROJ;
-    shaderParameters_["UOffset"] = VSP_UOFFSET;
-    shaderParameters_["VOffset"] = VSP_VOFFSET;
-    shaderParameters_["ViewRightVector"] = VSP_VIEWRIGHTVECTOR;
-    shaderParameters_["ViewUpVector"] = VSP_VIEWUPVECTOR;
-    shaderParameters_["SkinMatrices"] = VSP_SKINMATRICES;
-    
-    shaderParameters_["AmbientColor"] = PSP_AMBIENTCOLOR;
-    shaderParameters_["EdgeFilterParams"] = PSP_EDGEFILTERPARAMS;
-    shaderParameters_["ElapsedTimePS"] = PSP_ELAPSEDTIME;
-    shaderParameters_["FogColor"] = PSP_FOGCOLOR;
-    shaderParameters_["FogParams"] = PSP_FOGPARAMS;
-    shaderParameters_["LightAtten"] = PSP_LIGHTATTEN;
-    shaderParameters_["LightColor"] = PSP_LIGHTCOLOR;
-    shaderParameters_["LightDir"] = PSP_LIGHTDIR;
-    shaderParameters_["LightPos"] = PSP_LIGHTPOS;
-    shaderParameters_["LightSplits"] = PSP_LIGHTSPLITS;
-    shaderParameters_["LightVecRot"] = PSP_LIGHTVECROT;
-    shaderParameters_["MatDiffColor"] = PSP_MATDIFFCOLOR;
-    shaderParameters_["MatEmissiveColor"] = PSP_MATEMISSIVECOLOR;
-    shaderParameters_["MatSpecProperties"] = PSP_MATSPECPROPERTIES;
-    shaderParameters_["SampleOffsets"] = PSP_SAMPLEOFFSETS;
-    shaderParameters_["ShadowIntensity"] = PSP_SHADOWINTENSITY;
-    shaderParameters_["ShadowProjPS"] = PSP_SHADOWPROJ;
-    shaderParameters_["SpotProjPS"] = PSP_SPOTPROJ;
-    
-    // Map texture units
+void Graphics::SetTextureUnitMappings()
+{
     textureUnits_["NormalMap"] = TU_NORMAL;
     textureUnits_["DiffMap"] = TU_DIFFUSE;
     textureUnits_["DiffCubeMap"] = TU_DIFFUSE;

+ 30 - 28
Engine/Graphics/Direct3D9/D3D9Graphics.h

@@ -24,6 +24,7 @@
 #pragma once
 
 #include "Color.h"
+#include "HashMap.h"
 #include "Object.h"
 #include "Rect.h"
 #include "GraphicsDefs.h"
@@ -47,6 +48,17 @@ class VertexDeclaration;
 
 static const int IMMEDIATE_BUFFER_DEFAULT_SIZE = 1024;
 
+/// Shader parameter information
+struct ShaderParameterInfo
+{
+    /// Shader type
+    ShaderType type_;
+    /// Hardware register
+    unsigned register_;
+    /// Last source
+    const void* lastSource_;
+};
+
 /// Graphics subsystem. Manages the Direct3D9 device, application window, rendering state and GPU resources
 class Graphics : public Object
 {
@@ -98,29 +110,29 @@ public:
     /// Set shaders
     void SetShaders(ShaderVariation* vs, ShaderVariation* ps);
     /// Set shader bool constants
-    void SetShaderParameter(ShaderParameter param, const bool* data, unsigned count);
+    void SetShaderParameter(StringHash param, const bool* data, unsigned count);
     /// Set shader float constants
-    void SetShaderParameter(ShaderParameter param, const float* data, unsigned count);
+    void SetShaderParameter(StringHash param, const float* data, unsigned count);
     /// Set shader int constants
-    void SetShaderParameter(ShaderParameter param, const int* data, unsigned count);
+    void SetShaderParameter(StringHash param, const int* data, unsigned count);
     /// Set shader float constant
-    void SetShaderParameter(ShaderParameter param, float value);
+    void SetShaderParameter(StringHash param, float value);
     /// Set shader color constant
-    void SetShaderParameter(ShaderParameter param, const Color& color);
+    void SetShaderParameter(StringHash param, const Color& color);
     /// Set shader 3x3 matrix constant
-    void SetShaderParameter(ShaderParameter param, const Matrix3& matrix);
+    void SetShaderParameter(StringHash param, const Matrix3& matrix);
     /// Set shader 3D vector constant
-    void SetShaderParameter(ShaderParameter param, const Vector3& vector);
+    void SetShaderParameter(StringHash param, const Vector3& vector);
     /// Set shader 4x4 matrix constant
-    void SetShaderParameter(ShaderParameter param, const Matrix4& matrix);
+    void SetShaderParameter(StringHash param, const Matrix4& matrix);
     /// Set shader 4D vector constant
-    void SetShaderParameter(ShaderParameter param, const Vector4& vector);
+    void SetShaderParameter(StringHash param, const Vector4& vector);
     /// Set shader 4x3 matrix constant
-    void SetShaderParameter(ShaderParameter param, const Matrix3x4& matrix);
-    /// Map shader parameter to a constant register. Called by Shader
-    void SetShaderRegister(ShaderParameter param, unsigned index) { shaderRegisters_[param] = index; }
+    void SetShaderParameter(StringHash param, const Matrix3x4& matrix);
+    /// Define a shader parameter. Called by Shader
+    void DefineShaderParameter(StringHash param, ShaderType type, unsigned hwReg);
     /// Check whether a shader parameter in the currently set shaders needs update
-    bool NeedParameterUpdate(ShaderParameter param, const void* source);
+    bool NeedParameterUpdate(StringHash param, const void* source);
     /// Check whether the current pixel shader uses a texture unit
     bool NeedTextureUnit(TextureUnit unit);
     /// Clear remembered shader parameter sources
@@ -256,14 +268,8 @@ public:
     ShaderVariation* GetVertexShader() const { return vertexShader_; }
     /// Return pixel shader
     ShaderVariation* GetPixelShader() const { return pixelShader_; }
-    /// Return shader parameter index by name
-    ShaderParameter GetShaderParameter(const String& name);
     /// Return texture unit index by name
     TextureUnit GetTextureUnit(const String& name);
-    /// Return shader parameter name by index
-    const String& GetShaderParameterName(ShaderParameter parameter);
-    /// Return texture unit name by index
-    const String& GetTextureUnitName(TextureUnit unit);
     /// Return texture by texture unit index
     Texture* GetTexture(unsigned index) const;
     /// Return the "view texture"
@@ -370,8 +376,8 @@ private:
     void OnDeviceReset();
     /// Reset cached rendering state
     void ResetCachedState();
-    /// Initialize shader parameter and texture unit mappings
-    void InitializeShaderParameters();
+    /// Initialize texture unit mappings
+    void SetTextureUnitMappings();
     /// Handle operating system window message
     void HandleWindowMessage(StringHash eventType, VariantMap& eventData);
     
@@ -467,18 +473,14 @@ private:
     ShaderVariation* vertexShader_;
     /// Pixel shader in use
     ShaderVariation* pixelShader_;
-    /// Shader parameter mappings
-    Map<String, ShaderParameter> shaderParameters_;
-    /// Shader constant register mappings
-    unsigned shaderRegisters_[MAX_SHADER_PARAMETERS];
-    /// Last shader parameter sources per parameter
-    const void* lastShaderParameterSources_[MAX_SHADER_PARAMETERS];
+    /// Shader parameters
+    HashMap<StringHash, ShaderParameterInfo> shaderParameters_;
     /// Textures in use
     Texture* textures_[MAX_TEXTURE_UNITS];
     /// "View texture" to prevent sampling the destination render target
     Texture* viewTexture_;
     /// Texture unit mappings
-    Map<String, TextureUnit> textureUnits_;
+    HashMap<String, TextureUnit> textureUnits_;
     /// Render targets in use
     RenderSurface* renderTargets_[MAX_RENDERTARGETS];
     /// Depth stencil buffer in use

+ 8 - 16
Engine/Graphics/Direct3D9/D3D9Shader.cpp

@@ -32,8 +32,8 @@
 #include "Shader.h"
 #include "ShaderVariation.h"
 
-/// Shader parameter structure for loading
-struct Parameter
+/// Shader constant (uniform or sampler) structure for loading
+struct Constant
 {
     /// Parameter name
     String name_;
@@ -81,29 +81,25 @@ bool Shader::Load(Deserializer& source)
     shaderType_ = (ShaderType)source.ReadShort();
     isSM3_ = (source.ReadShort() == 3);
     
-    Vector<Parameter> parameters;
-    Vector<Parameter> textureUnits;
+    Vector<Constant> parameters;
+    Vector<Constant> textureUnits;
     
     // Read the parameters and texture units used by this shader; use information is specified in terms of them
     unsigned numParameters = source.ReadUInt();
     for (unsigned i = 0; i < numParameters; ++i)
     {
-        Parameter newParameter;
+        Constant newParameter;
         newParameter.name_ = source.ReadString();
         newParameter.register_ = source.ReadUByte();
         parameters.Push(newParameter);
         
-        ShaderParameter paramIndex = graphics->GetShaderParameter(newParameter.name_);
-        if (paramIndex != MAX_SHADER_PARAMETERS)
-            graphics->SetShaderRegister(paramIndex, newParameter.register_);
-        else
-            LOGWARNING("Unknown shader parameter " + newParameter.name_);
+        graphics->DefineShaderParameter(StringHash(newParameter.name_), shaderType_, newParameter.register_);
     }
     
     unsigned numTextureUnits = source.ReadUInt();
     for (unsigned i = 0; i < numTextureUnits; ++i)
     {
-        Parameter newTextureUnit;
+        Constant newTextureUnit;
         newTextureUnit.name_ = source.ReadString();
         newTextureUnit.register_ = source.ReadUByte();
         textureUnits.Push(newTextureUnit);
@@ -129,11 +125,7 @@ bool Shader::Load(Deserializer& source)
         for (unsigned j = 0; j < numParameters; ++j)
         {
             if (source.ReadBool())
-            {
-                ShaderParameter paramIndex = graphics->GetShaderParameter(parameters[j].name_);
-                if (paramIndex != MAX_SHADER_PARAMETERS)
-                    variation->SetUseParameter(paramIndex, true);
-            }
+                variation->SetUseParameter(StringHash(parameters[j].name_), true);
         }
         
         for (unsigned j = 0; j < numTextureUnits; ++j)

+ 6 - 4
Engine/Graphics/Direct3D9/D3D9ShaderVariation.cpp

@@ -113,9 +113,12 @@ void ShaderVariation::SetByteCode(const SharedArrayPtr<unsigned char>& byteCode)
         Create();
 }
 
-void ShaderVariation::SetUseParameter(ShaderParameter param, bool enable)
+void ShaderVariation::SetUseParameter(StringHash param, bool enable)
 {
-    useParameter_[param] = enable;
+    if (enable)
+        useParameter_.Insert(param);
+    else
+        useParameter_.Erase(param);
 }
 
 void ShaderVariation::SetUseTextureUnit(TextureUnit unit, bool enable)
@@ -125,8 +128,7 @@ void ShaderVariation::SetUseTextureUnit(TextureUnit unit, bool enable)
 
 void ShaderVariation::ClearParameters()
 {
-    for (unsigned i = 0; i < MAX_SHADER_PARAMETERS; ++i)
-        useParameter_[i] = false;
+    useParameter_.Clear();
     for (unsigned i = 0; i < MAX_TEXTURE_UNITS; ++i)
         useTextureUnit_[i] = false;
 }

+ 4 - 3
Engine/Graphics/Direct3D9/D3D9ShaderVariation.h

@@ -25,6 +25,7 @@
 
 #include "GPUObject.h"
 #include "GraphicsDefs.h"
+#include "HashSet.h"
 #include "RefCounted.h"
 #include "SharedArrayPtr.h"
 
@@ -49,7 +50,7 @@ public:
     /// Set bytecode
     void SetByteCode(const SharedArrayPtr<unsigned char>& byteCode);
     /// Set to use a parameter
-    void SetUseParameter(ShaderParameter param, bool enable);
+    void SetUseParameter(StringHash param, bool enable);
     /// Set to use a texture unit
     void SetUseTextureUnit(TextureUnit unit, bool enable);
     /// Clear parameter and texture unit use flags
@@ -66,7 +67,7 @@ public:
     /// Return whether requires Shader Model 3
     bool IsSM3() const { return isSM3_; }
     /// Return whether uses a specific shader parameter
-    bool HasParameter(ShaderParameter parameter) const { return useParameter_[parameter]; }
+    bool HasParameter(StringHash param) const { return useParameter_.Contains(param); }
     /// Return whether uses a texture unit (only for pixel shaders)
     bool HasTextureUnit(TextureUnit unit) const { return useTextureUnit_[unit]; }
     
@@ -82,7 +83,7 @@ private:
     /// Compile failed flag
     bool failed_;
     /// Parameter use flags
-    bool useParameter_[MAX_SHADER_PARAMETERS];
+    HashSet<StringHash> useParameter_;
     /// Texture unit use flags
     bool useTextureUnit_[MAX_TEXTURE_UNITS];
 };

+ 34 - 44
Engine/Graphics/GraphicsDefs.h

@@ -24,6 +24,7 @@
 #pragma once
 
 #include "HashBase.h"
+#include "StringHash.h"
 
 /// Rendering mode
 enum RenderMode
@@ -199,50 +200,39 @@ enum ShaderType
     PS,
 };
 
-/// Shader parameters
-enum ShaderParameter
-{
-    VSP_CAMERAPOS,
-    VSP_CAMERAROT,
-    VSP_DEPTHMODE,
-    VSP_ELAPSEDTIME,
-    VSP_FRUSTUMSIZE,
-    VSP_GBUFFEROFFSETS,
-    VSP_MODEL,
-    VSP_SHADOWPROJ,
-    VSP_SPOTPROJ,
-    VSP_VIEWPROJ,
-    VSP_UOFFSET,
-    VSP_VOFFSET,
-    VSP_VIEWRIGHTVECTOR,
-    VSP_VIEWUPVECTOR,
-    VSP_SKINMATRICES,
-    PSP_AMBIENTCOLOR,
-    PSP_DEPTHRECONSTRUCT,
-    PSP_EDGEFILTERPARAMS,
-    PSP_ELAPSEDTIME,
-    PSP_FOGCOLOR,
-    PSP_FOGPARAMS,
-    PSP_LIGHTATTEN,
-    PSP_LIGHTCOLOR,
-    PSP_LIGHTDIR,
-    PSP_LIGHTPOS,
-    PSP_LIGHTSPLITS,
-    PSP_LIGHTVECROT,
-    PSP_MATDIFFCOLOR,
-    PSP_MATEMISSIVECOLOR,
-    PSP_MATSPECPROPERTIES,
-    PSP_SAMPLEOFFSETS,
-    PSP_SHADOWINTENSITY,
-    PSP_SHADOWPROJ,
-    PSP_SPOTPROJ,
-    MAX_SHADER_PARAMETERS
-};
-
-template<> inline unsigned MakeHash(const ShaderParameter& param)
-{
-    return (unsigned)param;
-}
+static const StringHash VSP_CAMERAPOS("CameraPos");
+static const StringHash VSP_CAMERAROT("CameraRot");
+static const StringHash VSP_DEPTHMODE("DepthMode");
+static const StringHash VSP_ELAPSEDTIME("ElapsedTime");
+static const StringHash VSP_FRUSTUMSIZE("FrustumSize");
+static const StringHash VSP_GBUFFEROFFSETS("GBufferOffsets");
+static const StringHash VSP_MODEL("Model");
+static const StringHash VSP_SHADOWPROJ("ShadowProj");
+static const StringHash VSP_SPOTPROJ("SpotProj");
+static const StringHash VSP_VIEWPROJ("ViewProj");
+static const StringHash VSP_UOFFSET("UOffset");
+static const StringHash VSP_VOFFSET("VOffset");
+static const StringHash VSP_VIEWRIGHTVECTOR("ViewRightVector");
+static const StringHash VSP_VIEWUPVECTOR("ViewUpVector");
+static const StringHash VSP_SKINMATRICES("SkinMatrices");
+static const StringHash PSP_AMBIENTCOLOR("AmbientColor");
+static const StringHash PSP_EDGEFILTERPARAMS("EdgeFilterParams");
+static const StringHash PSP_ELAPSEDTIME("ElapsedTimePS");
+static const StringHash PSP_FOGCOLOR("FogColor");
+static const StringHash PSP_FOGPARAMS("FogParams");
+static const StringHash PSP_LIGHTATTEN("LightAtten");
+static const StringHash PSP_LIGHTCOLOR("LightColor");
+static const StringHash PSP_LIGHTDIR("LightDir");
+static const StringHash PSP_LIGHTPOS("LightPos");
+static const StringHash PSP_LIGHTSPLITS("LightSplits");
+static const StringHash PSP_LIGHTVECROT("LightVecRot");
+static const StringHash PSP_MATDIFFCOLOR("MatDiffColor");
+static const StringHash PSP_MATEMISSIVECOLOR("MatEmissiveColor");
+static const StringHash PSP_MATSPECPROPERTIES("MatSpecProperties");
+static const StringHash PSP_SAMPLEOFFSETS("SampleOffsets");
+static const StringHash PSP_SHADOWINTENSITY("ShadowIntensity");
+static const StringHash PSP_SHADOWPROJ("ShadowProjPS");
+static const StringHash PSP_SPOTPROJ("SpotProjPS");
 
 /// Texture units
 enum TextureUnit

+ 19 - 27
Engine/Graphics/Material.cpp

@@ -89,11 +89,11 @@ Material::Material(Context* context) :
     textures_.Resize(MAX_MATERIAL_TEXTURE_UNITS);
     
     // Setup often used default parameters
-    shaderParameters_[VSP_UOFFSET] = Vector4(1.0f, 0.0f, 0.0f, 0.0f);
-    shaderParameters_[VSP_VOFFSET] = Vector4(0.0f, 1.0f, 0.0f, 0.0f);
-    shaderParameters_[PSP_MATDIFFCOLOR] = Vector4::UNITY;
-    shaderParameters_[PSP_MATEMISSIVECOLOR] = Vector4::ZERO;
-    shaderParameters_[PSP_MATSPECPROPERTIES] = Vector4::ZERO;
+    SetShaderParameter("UOffset", Vector4(1.0f, 0.0f, 0.0f, 0.0f));
+    SetShaderParameter("VOffset", Vector4(0.0f, 1.0f, 0.0f, 0.0f));
+    SetShaderParameter("MatDiffColor", Vector4::UNITY);
+    SetShaderParameter("MatEmissiveColor", Vector4::ZERO);
+    SetShaderParameter("MatSpecProperties", Vector4::ZERO);
 }
 
 Material::~Material()
@@ -174,12 +174,7 @@ bool Material::Load(Deserializer& source)
     {
         String name = parameterElem.GetString("name");
         Vector4 value = parameterElem.GetVector("value");
-        ShaderParameter param = graphics->GetShaderParameter(name);
-        // Check whether a VS or PS parameter
-        if (param < MAX_SHADER_PARAMETERS)
-            SetShaderParameter(param, value);
-        else
-            LOGERROR("Unknown shader parameter " + name);
+        SetShaderParameter(name, value);
         
         parameterElem = parameterElem.GetNextElement("parameter");
     }
@@ -197,7 +192,7 @@ bool Material::Load(Deserializer& source)
     memoryUse += sizeof(Material);
     memoryUse += techniques_.Size() * sizeof(TechniqueEntry);
     memoryUse += textures_.Size() * sizeof(SharedPtr<Texture>);
-    memoryUse += shaderParameters_.Size() * (sizeof(ShaderParameter) + sizeof(Vector4));
+    memoryUse += shaderParameters_.Size() * sizeof(MaterialShaderParameter);
     
     SetMemoryUse(memoryUse);
     Update();
@@ -239,11 +234,11 @@ bool Material::Save(Serializer& dest)
     }
     
     // Write shader parameters
-    for (HashMap<ShaderParameter, Vector4>::ConstIterator j = shaderParameters_.Begin(); j != shaderParameters_.End(); ++j)
+    for (HashMap<StringHash, MaterialShaderParameter>::ConstIterator j = shaderParameters_.Begin(); j != shaderParameters_.End(); ++j)
     {
         XMLElement parameterElem = materialElem.CreateChildElement("parameter");
-        parameterElem.SetString("name", graphics->GetShaderParameterName(j->first_));
-        parameterElem.SetVector4("value", j->second_);
+        parameterElem.SetString("name", j->second_.name_);
+        parameterElem.SetVector4("value", j->second_.value_);
     }
     
     return xml->Save(dest);
@@ -266,9 +261,12 @@ void Material::SetTechnique(unsigned index, Technique* technique, unsigned quali
     Update();
 }
 
-void Material::SetShaderParameter(ShaderParameter param, const Vector4& value)
+void Material::SetShaderParameter(const String& name, const Vector4& value)
 {
-    shaderParameters_[param] = value;
+    MaterialShaderParameter newParam;
+    newParam.name_ = name;
+    newParam.value_ = value;
+    shaderParameters_[StringHash(name)] = newParam;
 }
 
 void Material::SetTexture(TextureUnit unit, Texture* texture)
@@ -304,14 +302,8 @@ void Material::SetUVTransform(const Vector2& offset, float rotation, const Vecto
     
     transform = offsetMatrix * transform;
     
-    Vector4& uOffset = shaderParameters_[VSP_UOFFSET];
-    Vector4& vOffset = shaderParameters_[VSP_VOFFSET];
-    uOffset.x_ = transform.m00_;
-    uOffset.y_ = transform.m01_;
-    uOffset.w_ = transform.m03_;
-    vOffset.x_ = transform.m10_;
-    vOffset.y_ = transform.m11_;
-    vOffset.w_ = transform.m13_;
+    SetShaderParameter("UOffset", Vector4(transform.m00_, transform.m01_, transform.m02_, transform.m03_));
+    SetShaderParameter("VOffset", Vector4(transform.m10_, transform.m11_, transform.m12_, transform.m13_));
 }
 
 void Material::SetUVTransform(const Vector2& offset, float rotation, float repeat)
@@ -329,9 +321,9 @@ void Material::SetShadowCullMode(CullMode mode)
     shadowCullMode_ = mode;
 }
 
-void Material::RemoveShaderParameter(ShaderParameter param)
+void Material::RemoveShaderParameter(const String& name)
 {
-    shaderParameters_.Erase(param);
+    shaderParameters_.Erase(StringHash(name));
 }
 
 void Material::ReleaseShaders()

+ 13 - 4
Engine/Graphics/Material.h

@@ -34,6 +34,15 @@ class Texture;
 class Texture2D;
 class TextureCube;
 
+/// Material's shader parameter definition
+struct MaterialShaderParameter
+{
+    /// Name
+    String name_;
+    /// Value
+    Vector4 value_;
+};
+
 /// Material's technique list entry
 struct TechniqueEntry
 {
@@ -75,7 +84,7 @@ public:
     /// Set technique
     void SetTechnique(unsigned index, Technique* technique, unsigned qualityLevel = 0, float lodDistance = 0.0f);
     /// Set shader parameter
-    void SetShaderParameter(ShaderParameter param, const Vector4& value);
+    void SetShaderParameter(const String& name, const Vector4& value);
     /// Set texture
     void SetTexture(TextureUnit unit, Texture* texture);
     /// Set texture coordinate transform
@@ -87,7 +96,7 @@ public:
     /// Set culling mode for shadows
     void SetShadowCullMode(CullMode mode);
     /// Remove a shader parameter
-    void RemoveShaderParameter(ShaderParameter param);
+    void RemoveShaderParameter(const String& name);
     /// Reset all shader pointers
     void ReleaseShaders();
     /// Clone material
@@ -110,7 +119,7 @@ public:
     /// Return texture by unit
     Texture* GetTexture(TextureUnit unit) const;
     /// Return all shader parameters
-    const HashMap<ShaderParameter, Vector4>& GetShaderParameters() const { return shaderParameters_; }
+    const HashMap<StringHash, MaterialShaderParameter>& GetShaderParameters() const { return shaderParameters_; }
     /// Return normal culling mode
     CullMode GetCullMode() const { return cullMode_; }
     /// Return culling mode for shadows
@@ -132,7 +141,7 @@ private:
     /// Textures
     Vector<SharedPtr<Texture> > textures_;
     /// Shader parameters
-    HashMap<ShaderParameter, Vector4> shaderParameters_;
+    HashMap<StringHash, MaterialShaderParameter> shaderParameters_;
     /// Normal culling mode
     CullMode cullMode_;
     /// Culling mode for shadow rendering

+ 2 - 2
Engine/Graphics/Renderer.cpp

@@ -1466,7 +1466,7 @@ void Renderer::SetupLightBatch(Batch& batch)
     }
 }
 
-void Renderer::DrawFullScreenQuad(Camera& camera, ShaderVariation* vs, ShaderVariation* ps, bool nearQuad, const HashMap<ShaderParameter, Vector4>& shaderParameters)
+void Renderer::DrawFullScreenQuad(Camera& camera, ShaderVariation* vs, ShaderVariation* ps, bool nearQuad, const HashMap<StringHash, Vector4>& shaderParameters)
 {
     Light quadDirLight(context_);
     Matrix3x4 model(quadDirLight.GetDirLightTransform(camera, nearQuad));
@@ -1479,7 +1479,7 @@ void Renderer::DrawFullScreenQuad(Camera& camera, ShaderVariation* vs, ShaderVar
     graphics_->ClearTransformSources();
     
     // Set global shader parameters as needed
-    for (HashMap<ShaderParameter, Vector4>::ConstIterator i = shaderParameters.Begin(); i != shaderParameters.End(); ++i)
+    for (HashMap<StringHash, Vector4>::ConstIterator i = shaderParameters.Begin(); i != shaderParameters.End(); ++i)
     {
         if (graphics_->NeedParameterUpdate(i->first_, &shaderParameters))
             graphics_->SetShaderParameter(i->first_, i->second_);

+ 1 - 1
Engine/Graphics/Renderer.h

@@ -333,7 +333,7 @@ private:
     /// Set up a light volume rendering batch
     void SetupLightBatch(Batch& batch);
     /// Draw a full screen quad (either near or far)
-    void DrawFullScreenQuad(Camera& camera, ShaderVariation* vs, ShaderVariation* ps, bool nearQuad, const HashMap<ShaderParameter, Vector4>& shaderParameters);
+    void DrawFullScreenQuad(Camera& camera, ShaderVariation* vs, ShaderVariation* ps, bool nearQuad, const HashMap<StringHash, Vector4>& shaderParameters);
     /// Handle screen mode event
     void HandleScreenMode(StringHash eventType, VariantMap& eventData);
     /// Handle render update event

+ 1 - 1
Engine/Graphics/View.cpp

@@ -983,7 +983,7 @@ void View::RenderBatchesDeferred()
         ShaderVariation* vs = renderer_->GetVertexShader("EdgeFilter");
         ShaderVariation* ps = renderer_->GetPixelShader("EdgeFilter");
         
-        HashMap<ShaderParameter, Vector4> shaderParameters(shaderParameters_);
+        HashMap<StringHash, Vector4> shaderParameters(shaderParameters_);
         shaderParameters[PSP_EDGEFILTERPARAMS] = Vector4(parameters.radius_, parameters.threshold_, parameters.strength_, 0.0f);
         shaderParameters[PSP_SAMPLEOFFSETS] = Vector4(1.0f / gBufferWidth, 1.0f / gBufferHeight, 0.0f, 0.0f);
         

+ 1 - 1
Engine/Graphics/View.h

@@ -222,7 +222,7 @@ private:
     /// G-buffer size error displayed
     Set<RenderSurface*> gBufferErrorDisplayed_;
     /// View-global shader parameters
-    HashMap<ShaderParameter, Vector4> shaderParameters_;
+    HashMap<StringHash, Vector4> shaderParameters_;
     
     /// G-buffer batches
     BatchQueue gBufferQueue_;