Jelajahi Sumber

Added RemoveShaderParameter to Material.

Lasse Öörni 14 tahun lalu
induk
melakukan
c3d68e849c

+ 1 - 1
Engine/Container/HashMap.h

@@ -365,7 +365,7 @@ private:
         Node* node = ptrs[hashKey];
         while (node)
         {
-            if (node->pair_.key_ == key)
+            if (node->pair_.first_ == key)
                 return node;
             previous = node;
             node = node->Down();

+ 1 - 0
Engine/Engine/GraphicsAPI.cpp

@@ -338,6 +338,7 @@ 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", "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);

+ 9 - 14
Engine/Graphics/Batch.cpp

@@ -100,17 +100,6 @@ void Batch::Prepare(Graphics* graphics, const HashMap<ShaderParameter, Vector4>&
             graphics->SetShaderParameter(i->first_, i->second_);
     }
     
-    // Set material's shader parameters
-    if (material_)
-    {
-        const HashMap<ShaderParameter, Vector4>& parameters = material_->GetShaderParameters();
-        for (HashMap<ShaderParameter, Vector4>::ConstIterator i = parameters.Begin(); i != parameters.End(); ++i)
-        {
-            if (graphics->NeedParameterUpdate(i->first_, material_))
-                graphics->SetShaderParameter(i->first_, i->second_);
-        }
-    }
-    
     // Set viewport and camera shader parameters
     if (graphics->NeedParameterUpdate(VSP_CAMERAPOS, camera_))
         graphics->SetShaderParameter(VSP_CAMERAPOS, camera_->GetWorldPosition());
@@ -157,7 +146,7 @@ void Batch::Prepare(Graphics* graphics, const HashMap<ShaderParameter, Vector4>&
     if ((shaderData_) && (shaderDataSize_))
     {
         if (graphics->NeedParameterUpdate(VSP_SKINMATRICES, shaderData_))
-            graphics->SetShaderParameter(VSP_SKINMATRICES, (const float*)shaderData_, shaderDataSize_);
+            graphics->SetShaderParameter(VSP_SKINMATRICES, shaderData_, shaderDataSize_);
     }
     
     // Set light-related shader parameters
@@ -315,11 +304,17 @@ void Batch::Prepare(Graphics* graphics, const HashMap<ShaderParameter, Vector4>&
         }
     }
     
-    // Set material-specific textures
+    // Set material-specific shader parameters and textures
     if (material_)
     {
-        const Vector<SharedPtr<Texture> >& textures = material_->GetTextures();
+        const HashMap<ShaderParameter, Vector4>& parameters = material_->GetShaderParameters();
+        for (HashMap<ShaderParameter, Vector4>::ConstIterator i = parameters.Begin(); i != parameters.End(); ++i)
+        {
+            if (graphics->NeedParameterUpdate(i->first_, material_))
+                graphics->SetShaderParameter(i->first_, i->second_);
+        }
         
+        const Vector<SharedPtr<Texture> >& textures = material_->GetTextures();
         if (graphics->NeedTextureUnit(TU_DIFFUSE))
             graphics->SetTexture(TU_DIFFUSE, textures[TU_DIFFUSE]);
         if (graphics->NeedTextureUnit(TU_NORMAL))

+ 9 - 9
Engine/Graphics/Batch.h

@@ -65,6 +65,10 @@ struct Batch
     Geometry* geometry_;
     /// Model world transform
     const Matrix3x4* worldTransform_;
+    /// Camera
+    Camera* camera_;
+    /// Light that affects the geometry, if any
+    Light* light_;
     /// Material
     Material* material_;
     /// Material pass
@@ -73,12 +77,8 @@ struct Batch
     ShaderVariation* vertexShader_;
     /// Pixel shader
     ShaderVariation* pixelShader_;
-    /// Camera
-    Camera* camera_;
-    /// Light that affects the geometry, if any
-    Light* light_;
     /// Vertex shader data
-    const void* shaderData_;
+    const float* shaderData_;
     /// Vertex shader data size in floats
     unsigned shaderDataSize_;
     /// Distance from camera
@@ -139,6 +139,10 @@ struct BatchGroup
     Geometry* geometry_;
     /// Instance data
     PODVector<InstanceData> instances_;
+    /// Camera
+    Camera* camera_;
+    /// Light that affects the geometry, if any
+    Light* light_;
     /// Material
     Material* material_;
     /// Material pass
@@ -147,10 +151,6 @@ struct BatchGroup
     ShaderVariation* vertexShader_;
     /// Pixel shader
     ShaderVariation* pixelShader_;
-    /// Camera
-    Camera* camera_;
-    /// Light that affects the geometry, if any
-    Light* light_;
     /// Vertex shader index
     unsigned char vertexShaderIndex_;
     /// Instance stream start index, or M_MAX_UNSIGNED if transforms not pre-set

+ 7 - 2
Engine/Graphics/Material.cpp

@@ -266,9 +266,9 @@ void Material::SetTechnique(unsigned index, Technique* technique, unsigned quali
     Update();
 }
 
-void Material::SetShaderParameter(ShaderParameter parameter, const Vector4& value)
+void Material::SetShaderParameter(ShaderParameter param, const Vector4& value)
 {
-    shaderParameters_[parameter] = value;
+    shaderParameters_[param] = value;
 }
 
 void Material::SetTexture(TextureUnit unit, Texture* texture)
@@ -329,6 +329,11 @@ void Material::SetShadowCullMode(CullMode mode)
     shadowCullMode_ = mode;
 }
 
+void Material::RemoveShaderParameter(ShaderParameter param)
+{
+    shaderParameters_.Erase(param);
+}
+
 void Material::ReleaseShaders()
 {
     for (unsigned i = 0; i < techniques_.Size(); ++i)

+ 3 - 1
Engine/Graphics/Material.h

@@ -75,7 +75,7 @@ public:
     /// Set technique
     void SetTechnique(unsigned index, Technique* technique, unsigned qualityLevel = 0, float lodDistance = 0.0f);
     /// Set shader parameter
-    void SetShaderParameter(ShaderParameter parameter, const Vector4& value);
+    void SetShaderParameter(ShaderParameter param, const Vector4& value);
     /// Set texture
     void SetTexture(TextureUnit unit, Texture* texture);
     /// Set texture coordinate transform
@@ -86,6 +86,8 @@ public:
     void SetCullMode(CullMode mode);
     /// Set culling mode for shadows
     void SetShadowCullMode(CullMode mode);
+    /// Remove a shader parameter
+    void RemoveShaderParameter(ShaderParameter param);
     /// Reset all shader pointers
     void ReleaseShaders();
     /// Clone material

+ 1 - 1
Engine/Graphics/Renderer.h

@@ -48,7 +48,7 @@ class Zone;
 
 static const int SHADOW_MIN_PIXELS = 64;
 static const int NUM_SHADOWMAP_RESOLUTIONS = 3;
-static const int MIN_INSTANCES = 3;
+static const int MIN_INSTANCES = 4;
 static const int INSTANCING_BUFFER_DEFAULT_SIZE = 1024;
 
 /// Light vertex shader variations