Browse Source

Unified the shader parameter setting API.

Lasse Öörni 14 years ago
parent
commit
dca33c3b34

+ 4 - 16
Engine/Engine/GraphicsAPI.cpp

@@ -239,19 +239,9 @@ static void RegisterTextures(asIScriptEngine* engine)
     engine->RegisterObjectMethod("TextureCube", "RenderSurface@+ get_renderSurface(CubeMapFace) const", asMETHOD(TextureCube, GetRenderSurface), asCALL_THISCALL);
     engine->RegisterObjectMethod("TextureCube", "RenderSurface@+ get_renderSurface(CubeMapFace) const", asMETHOD(TextureCube, GetRenderSurface), asCALL_THISCALL);
 }
 }
 
 
-static Vector4 MaterialGetVertexShaderParameter(ShaderParameter parameter, Material* ptr)
+static Vector4 MaterialGetShaderParameter(ShaderParameter parameter, Material* ptr)
 {
 {
-    const Map<ShaderParameter, Vector4>& parameters = ptr->GetVertexShaderParameters();
-    Map<ShaderParameter, Vector4>::ConstIterator i = parameters.Find(parameter);
-    if (i == parameters.End())
-        return Vector4::ZERO;
-    else
-        return i->second_;
-}
-
-static Vector4 MaterialGetPixelShaderParameter(ShaderParameter parameter, Material* ptr)
-{
-    const Map<ShaderParameter, Vector4>& parameters = ptr->GetPixelShaderParameters();
+    const Map<ShaderParameter, Vector4>& parameters = ptr->GetShaderParameters();
     Map<ShaderParameter, Vector4>::ConstIterator i = parameters.Find(parameter);
     Map<ShaderParameter, Vector4>::ConstIterator i = parameters.Find(parameter);
     if (i == parameters.End())
     if (i == parameters.End())
         return Vector4::ZERO;
         return Vector4::ZERO;
@@ -352,10 +342,8 @@ static void RegisterMaterial(asIScriptEngine* engine)
     engine->RegisterObjectMethod("Material", "void set_numTechniques(uint)", asMETHOD(Material, SetNumTechniques), asCALL_THISCALL);
     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", "uint get_numTechniques() const", asMETHOD(Material, GetNumTechniques), asCALL_THISCALL);
     engine->RegisterObjectMethod("Material", "Technique@+ get_technique(uint)", asMETHOD(Material, GetTechnique), asCALL_THISCALL);
     engine->RegisterObjectMethod("Material", "Technique@+ get_technique(uint)", asMETHOD(Material, GetTechnique), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Material", "void set_vertexShaderParameter(ShaderParameter, const Vector4&in)", asMETHOD(Material, SetVertexShaderParameter), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Material", "Vector4 get_vertexShaderParameter(ShaderParameter) const", asFUNCTION(MaterialGetVertexShaderParameter), asCALL_CDECL_OBJLAST);
-    engine->RegisterObjectMethod("Material", "void set_pixelShaderParameter(ShaderParameter, const Vector4&in)", asMETHOD(Material, SetPixelShaderParameter), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Material", "Vector4 get_pixelShaderParameter(ShaderParameter) const", asFUNCTION(MaterialGetPixelShaderParameter), asCALL_CDECL_OBJLAST);
+    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_texture(TextureUnit, Texture@+)", asMETHOD(Material, SetTexture), asCALL_THISCALL);
     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", "Texture@+ get_texture(TextureUnit) const", asMETHOD(Material, GetTexture), asCALL_THISCALL);
     engine->RegisterObjectMethod("Material", "bool get_occlusion()", asMETHOD(Material, GetOcclusion), asCALL_THISCALL);
     engine->RegisterObjectMethod("Material", "bool get_occlusion()", asMETHOD(Material, GetOcclusion), asCALL_THISCALL);

+ 33 - 44
Engine/Graphics/Batch.cpp

@@ -127,10 +127,10 @@ void Batch::Prepare(Graphics* graphics, bool SetModelTransform) const
     
     
     // Set viewport parameters
     // Set viewport parameters
     if (graphics->NeedParameterUpdate(VSP_CAMERAPOS, camera_))
     if (graphics->NeedParameterUpdate(VSP_CAMERAPOS, camera_))
-        graphics->SetVertexShaderParameter(VSP_CAMERAPOS, camera_->GetWorldPosition());
+        graphics->SetShaderParameter(VSP_CAMERAPOS, camera_->GetWorldPosition());
     
     
     if (graphics->NeedParameterUpdate(VSP_CAMERAROT, camera_))
     if (graphics->NeedParameterUpdate(VSP_CAMERAROT, camera_))
-        graphics->SetVertexShaderParameter(VSP_CAMERAROT, camera_->GetWorldTransform().RotationMatrix());
+        graphics->SetShaderParameter(VSP_CAMERAROT, camera_->GetWorldTransform().RotationMatrix());
     
     
     if (graphics->NeedParameterUpdate(VSP_DEPTHMODE, camera_))
     if (graphics->NeedParameterUpdate(VSP_DEPTHMODE, camera_))
     {
     {
@@ -140,12 +140,12 @@ void Batch::Prepare(Graphics* graphics, bool SetModelTransform) const
         else
         else
             depthMode.w_ = 1.0f / camera_->GetFarClip();
             depthMode.w_ = 1.0f / camera_->GetFarClip();
         
         
-        graphics->SetVertexShaderParameter(VSP_DEPTHMODE, depthMode);
+        graphics->SetShaderParameter(VSP_DEPTHMODE, depthMode);
     }
     }
     
     
     // Set transforms
     // Set transforms
     if ((SetModelTransform) && (graphics->NeedParameterUpdate(VSP_MODEL, worldTransform_)))
     if ((SetModelTransform) && (graphics->NeedParameterUpdate(VSP_MODEL, worldTransform_)))
-        graphics->SetVertexShaderParameter(VSP_MODEL, *worldTransform_);
+        graphics->SetShaderParameter(VSP_MODEL, *worldTransform_);
     
     
     if ((shadowMap) && (graphics->NeedParameterUpdate(VSP_SHADOWPROJ, light_)))
     if ((shadowMap) && (graphics->NeedParameterUpdate(VSP_SHADOWPROJ, light_)))
     {
     {
@@ -158,7 +158,7 @@ void Batch::Prepare(Graphics* graphics, bool SetModelTransform) const
         texAdjust.SetTranslation(Vector3(offset, offset, 0.0f));
         texAdjust.SetTranslation(Vector3(offset, offset, 0.0f));
         texAdjust.SetScale(Vector3(0.5f, -0.5f, 1.0f));
         texAdjust.SetScale(Vector3(0.5f, -0.5f, 1.0f));
         
         
-        graphics->SetVertexShaderParameter(VSP_SHADOWPROJ, texAdjust * shadowProj * shadowView);
+        graphics->SetShaderParameter(VSP_SHADOWPROJ, texAdjust * shadowProj * shadowView);
     }
     }
     
     
     if ((light_) && (graphics->NeedParameterUpdate(VSP_SPOTPROJ, light_)))
     if ((light_) && (graphics->NeedParameterUpdate(VSP_SPOTPROJ, light_)))
@@ -179,7 +179,7 @@ void Batch::Prepare(Graphics* graphics, bool SetModelTransform) const
         texAdjust.SetTranslation(Vector3(0.5f, 0.5f, 0.0f));
         texAdjust.SetTranslation(Vector3(0.5f, 0.5f, 0.0f));
         texAdjust.SetScale(Vector3(0.5f, -0.5f, 1.0f));
         texAdjust.SetScale(Vector3(0.5f, -0.5f, 1.0f));
         
         
-        graphics->SetVertexShaderParameter(VSP_SPOTPROJ, texAdjust * spotProj * spotView.Inverse());
+        graphics->SetShaderParameter(VSP_SPOTPROJ, texAdjust * spotProj * spotView.Inverse());
     }
     }
     
     
     if (overrideView_)
     if (overrideView_)
@@ -187,37 +187,26 @@ void Batch::Prepare(Graphics* graphics, bool SetModelTransform) const
         // If we override the view matrix, also disable any projection jittering
         // If we override the view matrix, also disable any projection jittering
         /// \todo This may not be correct in all cases (skybox rendering?)
         /// \todo This may not be correct in all cases (skybox rendering?)
         if (graphics->NeedParameterUpdate(VSP_VIEWPROJ, &Matrix3x4::IDENTITY))
         if (graphics->NeedParameterUpdate(VSP_VIEWPROJ, &Matrix3x4::IDENTITY))
-            graphics->SetVertexShaderParameter(VSP_VIEWPROJ, camera_->GetProjection(false));
+            graphics->SetShaderParameter(VSP_VIEWPROJ, camera_->GetProjection(false));
     }
     }
     else
     else
     {
     {
         if (graphics->NeedParameterUpdate(VSP_VIEWPROJ, camera_))
         if (graphics->NeedParameterUpdate(VSP_VIEWPROJ, camera_))
-            graphics->SetVertexShaderParameter(VSP_VIEWPROJ, camera_->GetProjection() *
+            graphics->SetShaderParameter(VSP_VIEWPROJ, camera_->GetProjection() *
                 camera_->InverseWorldTransform());
                 camera_->InverseWorldTransform());
     }
     }
     
     
-    // Set material's vertex shader parameters
-    if (material_)
-    {
-        const Map<ShaderParameter, Vector4>& parameters = material_->GetVertexShaderParameters();
-        for (Map<ShaderParameter, Vector4>::ConstIterator i = parameters.Begin(); i != parameters.End(); ++i)
-        {
-            if (graphics->NeedParameterUpdate(i->first_, material_))
-                graphics->SetVertexShaderParameter(i->first_, i->second_);
-        }
-    }
-    
     if (graphics->NeedParameterUpdate(VSP_VIEWRIGHTVECTOR, camera_))
     if (graphics->NeedParameterUpdate(VSP_VIEWRIGHTVECTOR, camera_))
-        graphics->SetVertexShaderParameter(VSP_VIEWRIGHTVECTOR, camera_->GetRightVector());
+        graphics->SetShaderParameter(VSP_VIEWRIGHTVECTOR, camera_->GetRightVector());
     
     
     if (graphics->NeedParameterUpdate(VSP_VIEWUPVECTOR, camera_))
     if (graphics->NeedParameterUpdate(VSP_VIEWUPVECTOR, camera_))
-        graphics->SetVertexShaderParameter(VSP_VIEWUPVECTOR, camera_->GetUpVector());
+        graphics->SetShaderParameter(VSP_VIEWUPVECTOR, camera_->GetUpVector());
     
     
     // Set skinning transforms
     // Set skinning transforms
     if ((shaderData_) && (shaderDataSize_))
     if ((shaderData_) && (shaderDataSize_))
     {
     {
         if (graphics->NeedParameterUpdate(VSP_SKINMATRICES, shaderData_))
         if (graphics->NeedParameterUpdate(VSP_SKINMATRICES, shaderData_))
-            graphics->SetVertexShaderParameter(VSP_SKINMATRICES, (const float*)shaderData_, shaderDataSize_);
+            graphics->SetShaderParameter(VSP_SKINMATRICES, (const float*)shaderData_, shaderDataSize_);
     }
     }
     
     
     // Set light-related parameters
     // Set light-related parameters
@@ -226,7 +215,7 @@ void Batch::Prepare(Graphics* graphics, bool SetModelTransform) const
         if (graphics->NeedParameterUpdate(PSP_LIGHTATTEN, light_))
         if (graphics->NeedParameterUpdate(PSP_LIGHTATTEN, light_))
         {
         {
             Vector4 light_Atten(1.0f / Max(light_->GetRange(), M_EPSILON), 0.0f, 0.0f, 0.0f);
             Vector4 light_Atten(1.0f / Max(light_->GetRange(), M_EPSILON), 0.0f, 0.0f, 0.0f);
-            graphics->SetPixelShaderParameter(PSP_LIGHTATTEN, light_Atten);
+            graphics->SetShaderParameter(PSP_LIGHTATTEN, light_Atten);
         }
         }
         
         
         if (graphics->NeedParameterUpdate(PSP_LIGHTCOLOR, light_))
         if (graphics->NeedParameterUpdate(PSP_LIGHTCOLOR, light_))
@@ -239,15 +228,15 @@ void Batch::Prepare(Graphics* graphics, bool SetModelTransform) const
             if ((light_->GetLightType() != LIGHT_DIRECTIONAL) && (fadeEnd > 0.0f) && (fadeStart > 0.0f) && (fadeStart < fadeEnd))
             if ((light_->GetLightType() != LIGHT_DIRECTIONAL) && (fadeEnd > 0.0f) && (fadeStart > 0.0f) && (fadeStart < fadeEnd))
                 fade = Min(1.0f - (light_->GetDistance() - fadeStart) / (fadeEnd - fadeStart), 1.0f);
                 fade = Min(1.0f - (light_->GetDistance() - fadeStart) / (fadeEnd - fadeStart), 1.0f);
             
             
-            graphics->SetPixelShaderParameter(PSP_LIGHTCOLOR, Vector4(light_->GetColor().RGBValues(),
+            graphics->SetShaderParameter(PSP_LIGHTCOLOR, Vector4(light_->GetColor().RGBValues(),
                 light_->GetSpecularIntensity()) * fade);
                 light_->GetSpecularIntensity()) * fade);
         }
         }
         
         
         if (graphics->NeedParameterUpdate(PSP_LIGHTDIR, light_))
         if (graphics->NeedParameterUpdate(PSP_LIGHTDIR, light_))
-            graphics->SetPixelShaderParameter(PSP_LIGHTDIR, light_->GetWorldRotation() * Vector3::BACK);
+            graphics->SetShaderParameter(PSP_LIGHTDIR, light_->GetWorldRotation() * Vector3::BACK);
         
         
         if (graphics->NeedParameterUpdate(PSP_LIGHTPOS, light_))
         if (graphics->NeedParameterUpdate(PSP_LIGHTPOS, light_))
-            graphics->SetPixelShaderParameter(PSP_LIGHTPOS, light_->GetWorldPosition() - camera_->GetWorldPosition());
+            graphics->SetShaderParameter(PSP_LIGHTPOS, light_->GetWorldPosition() - camera_->GetWorldPosition());
         
         
         if (graphics->NeedParameterUpdate(PSP_LIGHTSPLITS, light_))
         if (graphics->NeedParameterUpdate(PSP_LIGHTSPLITS, light_))
         {
         {
@@ -257,7 +246,7 @@ void Batch::Prepare(Graphics* graphics, bool SetModelTransform) const
             float farFadeStart = light_->GetFarSplit() - farFadeRange;
             float farFadeStart = light_->GetFarSplit() - farFadeRange;
             float depthRange = camera_->GetFarClip();
             float depthRange = camera_->GetFarClip();
             
             
-            graphics->SetPixelShaderParameter(PSP_LIGHTSPLITS, Vector4(nearFadeStart / depthRange, 1.0f / (nearFadeRange / depthRange),
+            graphics->SetShaderParameter(PSP_LIGHTSPLITS, Vector4(nearFadeStart / depthRange, 1.0f / (nearFadeRange / depthRange),
                 farFadeStart / depthRange, 1.0f / (farFadeRange / depthRange)));
                 farFadeStart / depthRange, 1.0f / (farFadeRange / depthRange)));
         }
         }
         
         
@@ -271,18 +260,7 @@ void Batch::Prepare(Graphics* graphics, bool SetModelTransform) const
             else
             else
                 light_VecRot = Matrix3x4(Vector3::ZERO, original->GetWorldRotation(), Vector3::UNITY);
                 light_VecRot = Matrix3x4(Vector3::ZERO, original->GetWorldRotation(), Vector3::UNITY);
             
             
-            graphics->SetPixelShaderParameter(PSP_LIGHTVECROT, light_VecRot);
-        }
-    }
-    
-    // Set material's pixel shader parameters
-    if (material_)
-    {
-        const Map<ShaderParameter, Vector4>& parameters = material_->GetPixelShaderParameters();
-        for (Map<ShaderParameter, Vector4>::ConstIterator i = parameters.Begin(); i != parameters.End(); ++i)
-        {
-            if (graphics->NeedParameterUpdate(i->first_, material_))
-                graphics->SetPixelShaderParameter(i->first_, i->second_);
+            graphics->SetShaderParameter(PSP_LIGHTVECROT, light_VecRot);
         }
         }
     }
     }
     
     
@@ -292,7 +270,7 @@ void Batch::Prepare(Graphics* graphics, bool SetModelTransform) const
         if (graphics->NeedParameterUpdate(PSP_SAMPLEOFFSETS, shadowMap))
         if (graphics->NeedParameterUpdate(PSP_SAMPLEOFFSETS, shadowMap))
         {
         {
             float invWidth = 1.0f / (float)shadowMap->GetWidth();
             float invWidth = 1.0f / (float)shadowMap->GetWidth();
-            graphics->SetPixelShaderParameter(PSP_SAMPLEOFFSETS, Vector4(0.5f * invWidth, -0.5f * invWidth, 0.0f, 0.0f));
+            graphics->SetShaderParameter(PSP_SAMPLEOFFSETS, Vector4(0.5f * invWidth, -0.5f * invWidth, 0.0f, 0.0f));
         }
         }
         
         
         if (graphics->NeedParameterUpdate(PSP_SHADOWINTENSITY, light_))
         if (graphics->NeedParameterUpdate(PSP_SHADOWINTENSITY, light_))
@@ -303,7 +281,7 @@ void Batch::Prepare(Graphics* graphics, bool SetModelTransform) const
             if ((fadeStart > 0.0f) && (fadeEnd > 0.0f) && (fadeEnd > fadeStart))
             if ((fadeStart > 0.0f) && (fadeEnd > 0.0f) && (fadeEnd > fadeStart))
                 intensity = Lerp(intensity, 1.0f, Clamp((light_->GetDistance() - fadeStart) / (fadeEnd - fadeStart), 0.0f, 1.0f));
                 intensity = Lerp(intensity, 1.0f, Clamp((light_->GetDistance() - fadeStart) / (fadeEnd - fadeStart), 0.0f, 1.0f));
             float pcfValues = (1.0f - intensity) * 0.25f;
             float pcfValues = (1.0f - intensity) * 0.25f;
-            graphics->SetPixelShaderParameter(PSP_SHADOWINTENSITY, Vector4(pcfValues, intensity, 0.0f, 0.0f));
+            graphics->SetShaderParameter(PSP_SHADOWINTENSITY, Vector4(pcfValues, intensity, 0.0f, 0.0f));
         }
         }
         
         
         if (graphics->NeedParameterUpdate(PSP_SHADOWPROJ, light_))
         if (graphics->NeedParameterUpdate(PSP_SHADOWPROJ, light_))
@@ -320,7 +298,7 @@ void Batch::Prepare(Graphics* graphics, bool SetModelTransform) const
             texAdjust.SetTranslation(Vector3(offset, offset, 0.0f));
             texAdjust.SetTranslation(Vector3(offset, offset, 0.0f));
             texAdjust.SetScale(Vector3(0.5f, -0.5f, 1.0f));
             texAdjust.SetScale(Vector3(0.5f, -0.5f, 1.0f));
             
             
-            graphics->SetPixelShaderParameter(PSP_SHADOWPROJ, texAdjust * shadowProj * shadowView * viewPos);
+            graphics->SetShaderParameter(PSP_SHADOWPROJ, texAdjust * shadowProj * shadowView * viewPos);
         }
         }
     }
     }
     
     
@@ -344,7 +322,18 @@ void Batch::Prepare(Graphics* graphics, bool SetModelTransform) const
         texAdjust.SetTranslation(Vector3(0.5f, 0.5f, 0.0f));
         texAdjust.SetTranslation(Vector3(0.5f, 0.5f, 0.0f));
         texAdjust.SetScale(Vector3(0.5f, -0.5f, 1.0f));
         texAdjust.SetScale(Vector3(0.5f, -0.5f, 1.0f));
         
         
-        graphics->SetPixelShaderParameter(PSP_SPOTPROJ, texAdjust * spotProj * spotView.Inverse() * viewPos);
+        graphics->SetShaderParameter(PSP_SPOTPROJ, texAdjust * spotProj * spotView.Inverse() * viewPos);
+    }
+    
+    // Set material's shader parameters
+    if (material_)
+    {
+        const Map<ShaderParameter, Vector4>& parameters = material_->GetShaderParameters();
+        for (Map<ShaderParameter, Vector4>::ConstIterator i = parameters.Begin(); i != parameters.End(); ++i)
+        {
+            if (graphics->NeedParameterUpdate(i->first_, material_))
+                graphics->SetShaderParameter(i->first_, i->second_);
+        }
     }
     }
 }
 }
 
 
@@ -397,7 +386,7 @@ void BatchGroup::Draw(Graphics* graphics, VertexBuffer* buffer) const
         for (unsigned i = 0; i < instances_.Size(); ++i)
         for (unsigned i = 0; i < instances_.Size(); ++i)
         {
         {
             if (graphics->NeedParameterUpdate(VSP_MODEL, instances_[i].worldTransform_))
             if (graphics->NeedParameterUpdate(VSP_MODEL, instances_[i].worldTransform_))
-                graphics->SetVertexShaderParameter(VSP_MODEL, *instances_[i].worldTransform_);
+                graphics->SetShaderParameter(VSP_MODEL, *instances_[i].worldTransform_);
             
             
             graphics->Draw(geometry_->GetPrimitiveType(), geometry_->GetIndexStart(), geometry_->GetIndexCount(),
             graphics->Draw(geometry_->GetPrimitiveType(), geometry_->GetIndexStart(), geometry_->GetIndexCount(),
                 geometry_->GetVertexStart(), geometry_->GetVertexCount());
                 geometry_->GetVertexStart(), geometry_->GetVertexCount());

+ 3 - 3
Engine/Graphics/DebugRenderer.cpp

@@ -213,9 +213,9 @@ void DebugRenderer::Render()
     graphics->SetScissorTest(false);
     graphics->SetScissorTest(false);
     graphics->SetStencilTest(false);
     graphics->SetStencilTest(false);
     graphics->SetShaders(renderer->GetVertexShader("Basic_VCol"), renderer->GetPixelShader("Basic_VCol"));
     graphics->SetShaders(renderer->GetVertexShader("Basic_VCol"), renderer->GetPixelShader("Basic_VCol"));
-    graphics->SetVertexShaderParameter(VSP_MODEL, Matrix3x4::IDENTITY);
-    graphics->SetVertexShaderParameter(VSP_VIEWPROJ, projection_ * view_);
-    graphics->SetPixelShaderParameter(PSP_MATDIFFCOLOR, Color(1.0f, 1.0f, 1.0f, 1.0f));
+    graphics->SetShaderParameter(VSP_MODEL, Matrix3x4::IDENTITY);
+    graphics->SetShaderParameter(VSP_VIEWPROJ, projection_ * view_);
+    graphics->SetShaderParameter(PSP_MATDIFFCOLOR, Color(1.0f, 1.0f, 1.0f, 1.0f));
     
     
     // Draw all line geometry with depth testing
     // Draw all line geometry with depth testing
     if (lines_.Size())
     if (lines_.Size())

+ 50 - 139
Engine/Graphics/Graphics.cpp

@@ -930,153 +930,43 @@ void Graphics::SetShaders(ShaderVariation* vs, ShaderVariation* ps)
     }
     }
 }
 }
 
 
-void Graphics::SetVertexShaderParameter(ShaderParameter param, const bool* data, unsigned count)
+void Graphics::SetShaderParameter(ShaderParameter param, const bool* data, unsigned count)
 {
 {
     unsigned index = shaderRegisters_[param];
     unsigned index = shaderRegisters_[param];
     if (index >= MAX_CONSTANT_REGISTERS)
     if (index >= MAX_CONSTANT_REGISTERS)
         return;
         return;
     
     
-    impl_->device_->SetVertexShaderConstantB(index, (const BOOL*)data, count);
-}
-
-void Graphics::SetVertexShaderParameter(ShaderParameter param, const float* data, unsigned count)
-{
-    unsigned index = shaderRegisters_[param];
-    if (index >= MAX_CONSTANT_REGISTERS)
-        return;
-    
-    impl_->device_->SetVertexShaderConstantF(index, data, count / 4);
-}
-
-void Graphics::SetVertexShaderParameter(ShaderParameter param, const int* data, unsigned count)
-{
-    unsigned index = shaderRegisters_[param];
-    if (index >= MAX_CONSTANT_REGISTERS)
-        return;
-    
-    impl_->device_->SetVertexShaderConstantI(index, data, count / 4);
-}
-
-void Graphics::SetVertexShaderParameter(ShaderParameter param, float value)
-{
-    unsigned index = shaderRegisters_[param];
-    if (index >= MAX_CONSTANT_REGISTERS)
-        return;
-    
-    float data[4];
-    
-    data[0] = value;
-    data[1] = 0.0f;
-    data[2] = 0.0f;
-    data[3] = 0.0f;
-    
-    impl_->device_->SetVertexShaderConstantF(index, &data[0], 1);
-}
-
-void Graphics::SetVertexShaderParameter(ShaderParameter param, const Color& color)
-{
-    unsigned index = shaderRegisters_[param];
-    if (index >= MAX_CONSTANT_REGISTERS)
-        return;
-    
-    impl_->device_->SetVertexShaderConstantF(index, color.GetData(), 1);
-}
-
-void Graphics::SetVertexShaderParameter(ShaderParameter param, const Matrix3& matrix)
-{
-    unsigned index = shaderRegisters_[param];
-    if (index >= MAX_CONSTANT_REGISTERS)
-        return;
-    
-    float data[12];
-    
-    data[0] = matrix.m00_;
-    data[1] = matrix.m01_;
-    data[2] = matrix.m02_;
-    data[3] = 0.0f;
-    data[4] = matrix.m10_;
-    data[5] = matrix.m11_;
-    data[6] = matrix.m12_;
-    data[7] = 0.0f;
-    data[8] = matrix.m20_;
-    data[9] = matrix.m21_;
-    data[10] = matrix.m22_;
-    data[11] = 0.0f;
-    
-    impl_->device_->SetVertexShaderConstantF(index, &data[0], 3);
-}
-
-void Graphics::SetVertexShaderParameter(ShaderParameter param, const Vector3& vector)
-{
-    unsigned index = shaderRegisters_[param];
-    if (index >= MAX_CONSTANT_REGISTERS)
-        return;
-    
-    float data[4];
-    
-    data[0] = vector.x_;
-    data[1] = vector.y_;
-    data[2] = vector.z_;
-    data[3] = 0.0f;
-    
-    impl_->device_->SetVertexShaderConstantF(index, &data[0], 1);
-}
-
-void Graphics::SetVertexShaderParameter(ShaderParameter param, const Matrix4& matrix)
-{
-    unsigned index = shaderRegisters_[param];
-    if (index >= MAX_CONSTANT_REGISTERS)
-        return;
-    
-    impl_->device_->SetVertexShaderConstantF(index, matrix.GetData(), 4);
-}
-
-void Graphics::SetVertexShaderParameter(ShaderParameter param, const Vector4& vector)
-{
-    unsigned index = shaderRegisters_[param];
-    if (index >= MAX_CONSTANT_REGISTERS)
-        return;
-    
-    impl_->device_->SetVertexShaderConstantF(index, vector.GetData(), 1);
-}
-
-void Graphics::SetVertexShaderParameter(ShaderParameter param, const Matrix3x4& matrix)
-{
-    unsigned index = shaderRegisters_[param];
-    if (index >= MAX_CONSTANT_REGISTERS)
-        return;
-    
-    impl_->device_->SetVertexShaderConstantF(index, matrix.GetData(), 3);
-}
-
-void Graphics::SetPixelShaderParameter(ShaderParameter param, const bool* data, unsigned count)
-{
-    unsigned index = shaderRegisters_[param];
-    if (index >= MAX_CONSTANT_REGISTERS)
-        return;
-    
-    impl_->device_->SetPixelShaderConstantB(index, (const BOOL*)data, count);
+    if (param < PSP_AMBIENTCOLOR)
+       impl_->device_->SetVertexShaderConstantB(index, (const BOOL*)data, count);
+    else
+       impl_->device_->SetPixelShaderConstantB(index, (const BOOL*)data, count);
 }
 }
 
 
-void Graphics::SetPixelShaderParameter(ShaderParameter param, const float* data, unsigned count)
+void Graphics::SetShaderParameter(ShaderParameter param, const float* data, unsigned count)
 {
 {
     unsigned index = shaderRegisters_[param];
     unsigned index = shaderRegisters_[param];
     if (index >= MAX_CONSTANT_REGISTERS)
     if (index >= MAX_CONSTANT_REGISTERS)
         return;
         return;
     
     
-    impl_->device_->SetPixelShaderConstantF(index, data, count / 4);
+    if (param < PSP_AMBIENTCOLOR)
+        impl_->device_->SetVertexShaderConstantF(index, data, count / 4);
+    else
+        impl_->device_->SetPixelShaderConstantF(index, data, count / 4);
 }
 }
 
 
-void Graphics::SetPixelShaderParameter(ShaderParameter param, const int* data, unsigned count)
+void Graphics::SetShaderParameter(ShaderParameter param, const int* data, unsigned count)
 {
 {
     unsigned index = shaderRegisters_[param];
     unsigned index = shaderRegisters_[param];
     if (index >= MAX_CONSTANT_REGISTERS)
     if (index >= MAX_CONSTANT_REGISTERS)
         return;
         return;
     
     
-    impl_->device_->SetPixelShaderConstantI(index, data, count / 4);
+    if (param < PSP_AMBIENTCOLOR)
+        impl_->device_->SetVertexShaderConstantI(index, data, count / 4);
+    else
+        impl_->device_->SetPixelShaderConstantI(index, data, count / 4);
 }
 }
 
 
-void Graphics::SetPixelShaderParameter(ShaderParameter param, float value)
+void Graphics::SetShaderParameter(ShaderParameter param, float value)
 {
 {
     unsigned index = shaderRegisters_[param];
     unsigned index = shaderRegisters_[param];
     if (index >= MAX_CONSTANT_REGISTERS)
     if (index >= MAX_CONSTANT_REGISTERS)
@@ -1089,19 +979,25 @@ void Graphics::SetPixelShaderParameter(ShaderParameter param, float value)
     data[2] = 0.0f;
     data[2] = 0.0f;
     data[3] = 0.0f;
     data[3] = 0.0f;
     
     
-    impl_->device_->SetPixelShaderConstantF(index, &data[0], 1);
+    if (param < PSP_AMBIENTCOLOR)
+        impl_->device_->SetVertexShaderConstantF(index, &data[0], 1);
+    else
+        impl_->device_->SetPixelShaderConstantF(index, &data[0], 1);
 }
 }
 
 
-void Graphics::SetPixelShaderParameter(ShaderParameter param, const Color& color)
+void Graphics::SetShaderParameter(ShaderParameter param, const Color& color)
 {
 {
     unsigned index = shaderRegisters_[param];
     unsigned index = shaderRegisters_[param];
     if (index >= MAX_CONSTANT_REGISTERS)
     if (index >= MAX_CONSTANT_REGISTERS)
         return;
         return;
     
     
-    impl_->device_->SetPixelShaderConstantF(index, color.GetData(), 1);
+    if (param < PSP_AMBIENTCOLOR)
+        impl_->device_->SetVertexShaderConstantF(index, color.GetData(), 1);
+    else
+        impl_->device_->SetPixelShaderConstantF(index, color.GetData(), 1);
 }
 }
 
 
-void Graphics::SetPixelShaderParameter(ShaderParameter param, const Matrix3& matrix)
+void Graphics::SetShaderParameter(ShaderParameter param, const Matrix3& matrix)
 {
 {
     unsigned index = shaderRegisters_[param];
     unsigned index = shaderRegisters_[param];
     if (index >= MAX_CONSTANT_REGISTERS)
     if (index >= MAX_CONSTANT_REGISTERS)
@@ -1122,10 +1018,13 @@ void Graphics::SetPixelShaderParameter(ShaderParameter param, const Matrix3& mat
     data[10] = matrix.m22_;
     data[10] = matrix.m22_;
     data[11] = 0.0f;
     data[11] = 0.0f;
     
     
-    impl_->device_->SetPixelShaderConstantF(index, &data[0], 3);
+    if (param < PSP_AMBIENTCOLOR)
+        impl_->device_->SetVertexShaderConstantF(index, &data[0], 3);
+    else
+        impl_->device_->SetPixelShaderConstantF(index, &data[0], 3);
 }
 }
 
 
-void Graphics::SetPixelShaderParameter(ShaderParameter param, const Vector3& vector)
+void Graphics::SetShaderParameter(ShaderParameter param, const Vector3& vector)
 {
 {
     unsigned index = shaderRegisters_[param];
     unsigned index = shaderRegisters_[param];
     if (index >= MAX_CONSTANT_REGISTERS)
     if (index >= MAX_CONSTANT_REGISTERS)
@@ -1138,34 +1037,46 @@ void Graphics::SetPixelShaderParameter(ShaderParameter param, const Vector3& vec
     data[2] = vector.z_;
     data[2] = vector.z_;
     data[3] = 0.0f;
     data[3] = 0.0f;
     
     
-    impl_->device_->SetPixelShaderConstantF(index, &data[0], 1);
+    if (param < PSP_AMBIENTCOLOR)
+        impl_->device_->SetVertexShaderConstantF(index, &data[0], 1);
+    else
+        impl_->device_->SetPixelShaderConstantF(index, &data[0], 1);
 }
 }
 
 
-void Graphics::SetPixelShaderParameter(ShaderParameter param, const Matrix4& matrix)
+void Graphics::SetShaderParameter(ShaderParameter param, const Matrix4& matrix)
 {
 {
     unsigned index = shaderRegisters_[param];
     unsigned index = shaderRegisters_[param];
     if (index >= MAX_CONSTANT_REGISTERS)
     if (index >= MAX_CONSTANT_REGISTERS)
         return;
         return;
     
     
-    impl_->device_->SetPixelShaderConstantF(index, matrix.GetData(), 4);
+    if (param < PSP_AMBIENTCOLOR)
+        impl_->device_->SetVertexShaderConstantF(index, matrix.GetData(), 4);
+    else
+        impl_->device_->SetPixelShaderConstantF(index, matrix.GetData(), 4);
 }
 }
 
 
-void Graphics::SetPixelShaderParameter(ShaderParameter param, const Vector4& vector)
+void Graphics::SetShaderParameter(ShaderParameter param, const Vector4& vector)
 {
 {
     unsigned index = shaderRegisters_[param];
     unsigned index = shaderRegisters_[param];
     if (index >= MAX_CONSTANT_REGISTERS)
     if (index >= MAX_CONSTANT_REGISTERS)
         return;
         return;
     
     
-    impl_->device_->SetPixelShaderConstantF(index, vector.GetData(), 1);
+    if (param < PSP_AMBIENTCOLOR)
+        impl_->device_->SetVertexShaderConstantF(index, vector.GetData(), 1);
+    else
+        impl_->device_->SetPixelShaderConstantF(index, vector.GetData(), 1);
 }
 }
 
 
-void Graphics::SetPixelShaderParameter(ShaderParameter param, const Matrix3x4& matrix)
+void Graphics::SetShaderParameter(ShaderParameter param, const Matrix3x4& matrix)
 {
 {
     unsigned index = shaderRegisters_[param];
     unsigned index = shaderRegisters_[param];
     if (index >= MAX_CONSTANT_REGISTERS)
     if (index >= MAX_CONSTANT_REGISTERS)
         return;
         return;
     
     
-    impl_->device_->SetPixelShaderConstantF(index, matrix.GetData(), 3);
+    if (param < PSP_AMBIENTCOLOR)
+        impl_->device_->SetVertexShaderConstantF(index, matrix.GetData(), 3);
+    else
+        impl_->device_->SetPixelShaderConstantF(index, matrix.GetData(), 3);
 }
 }
 
 
 bool Graphics::NeedParameterUpdate(ShaderParameter parameter, const void* source)
 bool Graphics::NeedParameterUpdate(ShaderParameter parameter, const void* source)

+ 20 - 40
Engine/Graphics/Graphics.h

@@ -100,46 +100,26 @@ public:
     void SetIndexBuffer(IndexBuffer* buffer);
     void SetIndexBuffer(IndexBuffer* buffer);
     /// Set shaders
     /// Set shaders
     void SetShaders(ShaderVariation* vs, ShaderVariation* ps);
     void SetShaders(ShaderVariation* vs, ShaderVariation* ps);
-    /// Set vertex shader bool parameter
-    void SetVertexShaderParameter(ShaderParameter param, const bool* data, unsigned count);
-    /// Set vertex shader float constants
-    void SetVertexShaderParameter(ShaderParameter param, const float* data, unsigned count);
-    /// Set vertex shader int constants
-    void SetVertexShaderParameter(ShaderParameter param, const int* data, unsigned count);
-    /// Set vertex shader float constant
-    void SetVertexShaderParameter(ShaderParameter param, float value);
-    /// Set vertex shader color constant
-    void SetVertexShaderParameter(ShaderParameter param, const Color& color);
-    /// Set vertex shader 3x3 matrix constant
-    void SetVertexShaderParameter(ShaderParameter param, const Matrix3& matrix);
-    /// Set vertex shader 3D vector constant
-    void SetVertexShaderParameter(ShaderParameter param, const Vector3& vector);
-    /// Set vertex shader 4x4 matrix constant
-    void SetVertexShaderParameter(ShaderParameter param, const Matrix4& matrix);
-    /// Set vertex shader 4D vector constant
-    void SetVertexShaderParameter(ShaderParameter param, const Vector4& vector);
-    /// Set vertex shader 4x3 matrix constant
-    void SetVertexShaderParameter(ShaderParameter param, const Matrix3x4& matrix);
-    /// Set pixel shader bool constants
-    void SetPixelShaderParameter(ShaderParameter param, const bool* data, unsigned count);
-    /// Set pixel shader float constants
-    void SetPixelShaderParameter(ShaderParameter param, const float* data, unsigned count);
-    /// Set pixel shader int constants
-    void SetPixelShaderParameter(ShaderParameter param, const int* data, unsigned count);
-    /// Set pixel shader float constant
-    void SetPixelShaderParameter(ShaderParameter param, float value);
-    /// Set pixel shader color constant
-    void SetPixelShaderParameter(ShaderParameter param, const Color& color);
-    /// Set pixel shader 3x3 matrix constant
-    void SetPixelShaderParameter(ShaderParameter param, const Matrix3& matrix);
-    /// Set pixel shader 3D vector constant
-    void SetPixelShaderParameter(ShaderParameter param, const Vector3& vector);
-     /// Set pixel shader 4x4 matrix constant
-    void SetPixelShaderParameter(ShaderParameter param, const Matrix4& matrix);
-    /// Set pixel shader 3D vector constant
-    void SetPixelShaderParameter(ShaderParameter param, const Vector4& vector);
-    /// Set pixel shader 4x3 matrix constant
-    void SetPixelShaderParameter(ShaderParameter param, const Matrix3x4& matrix);
+    /// Set shader bool parameter
+    void SetShaderParameter(ShaderParameter param, const bool* data, unsigned count);
+    /// Set shader float constants
+    void SetShaderParameter(ShaderParameter param, const float* data, unsigned count);
+    /// Set shader int constants
+    void SetShaderParameter(ShaderParameter param, const int* data, unsigned count);
+    /// Set shader float constant
+    void SetShaderParameter(ShaderParameter param, float value);
+    /// Set shader color constant
+    void SetShaderParameter(ShaderParameter param, const Color& color);
+    /// Set shader 3x3 matrix constant
+    void SetShaderParameter(ShaderParameter param, const Matrix3& matrix);
+    /// Set shader 3D vector constant
+    void SetShaderParameter(ShaderParameter param, const Vector3& vector);
+    /// Set shader 4x4 matrix constant
+    void SetShaderParameter(ShaderParameter param, const Matrix4& matrix);
+    /// Set shader 4D vector constant
+    void SetShaderParameter(ShaderParameter 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
     /// Map shader parameter to a constant register. Called by Shader
     void SetShaderRegister(ShaderParameter param, unsigned index) { shaderRegisters_[param] = index; }
     void SetShaderRegister(ShaderParameter param, unsigned index) { shaderRegisters_[param] = index; }
     /// Check whether a shader parameter in the currently set shaders needs update
     /// Check whether a shader parameter in the currently set shaders needs update

+ 14 - 29
Engine/Graphics/Material.cpp

@@ -89,11 +89,11 @@ Material::Material(Context* context) :
     textures_.Resize(MAX_MATERIAL_TEXTURE_UNITS);
     textures_.Resize(MAX_MATERIAL_TEXTURE_UNITS);
     
     
     // Setup often used default parameters
     // Setup often used default parameters
-    vsParameters_[VSP_UOFFSET] = Vector4(1.0f, 0.0f, 0.0f, 0.0f);
-    vsParameters_[VSP_VOFFSET] = Vector4(0.0f, 1.0f, 0.0f, 0.0f);
-    psParameters_[PSP_MATDIFFCOLOR] = Vector4::UNITY;
-    psParameters_[PSP_MATEMISSIVECOLOR] = Vector4::ZERO;
-    psParameters_[PSP_MATSPECPROPERTIES] = Vector4::ZERO;
+    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;
 }
 }
 
 
 Material::~Material()
 Material::~Material()
@@ -176,10 +176,8 @@ bool Material::Load(Deserializer& source)
         Vector4 value = parameterElem.GetVector("value");
         Vector4 value = parameterElem.GetVector("value");
         ShaderParameter param = graphics->GetShaderParameter(name);
         ShaderParameter param = graphics->GetShaderParameter(name);
         // Check whether a VS or PS parameter
         // Check whether a VS or PS parameter
-        if (param < PSP_AMBIENTCOLOR)
-            SetVertexShaderParameter(param, value);
-        else if (param != MAX_SHADER_PARAMETERS)
-            SetPixelShaderParameter(param, value);
+        if (param < MAX_SHADER_PARAMETERS)
+            SetShaderParameter(param, value);
         else
         else
             LOGERROR("Unknown shader parameter " + name);
             LOGERROR("Unknown shader parameter " + name);
         
         
@@ -199,8 +197,7 @@ bool Material::Load(Deserializer& source)
     memoryUse += sizeof(Material);
     memoryUse += sizeof(Material);
     memoryUse += techniques_.Size() * sizeof(TechniqueEntry);
     memoryUse += techniques_.Size() * sizeof(TechniqueEntry);
     memoryUse += textures_.Size() * sizeof(SharedPtr<Texture>);
     memoryUse += textures_.Size() * sizeof(SharedPtr<Texture>);
-    memoryUse += vsParameters_.Size() * (sizeof(ShaderParameter) + sizeof(Vector4));
-    memoryUse += psParameters_.Size() * (sizeof(ShaderParameter) + sizeof(Vector4));
+    memoryUse += shaderParameters_.Size() * (sizeof(ShaderParameter) + sizeof(Vector4));
     
     
     SetMemoryUse(memoryUse);
     SetMemoryUse(memoryUse);
     Update();
     Update();
@@ -242,13 +239,7 @@ bool Material::Save(Serializer& dest)
     }
     }
     
     
     // Write shader parameters
     // Write shader parameters
-    for (Map<ShaderParameter, Vector4>::ConstIterator j = vsParameters_.Begin(); j != vsParameters_.End(); ++j)
-    {
-        XMLElement parameterElem = materialElem.CreateChildElement("parameter");
-        parameterElem.SetString("name", graphics->GetShaderParameterName(j->first_));
-        parameterElem.SetVector4("value", j->second_);
-    }
-    for (Map<ShaderParameter, Vector4>::ConstIterator j = psParameters_.Begin(); j != psParameters_.End(); ++j)
+    for (Map<ShaderParameter, Vector4>::ConstIterator j = shaderParameters_.Begin(); j != shaderParameters_.End(); ++j)
     {
     {
         XMLElement parameterElem = materialElem.CreateChildElement("parameter");
         XMLElement parameterElem = materialElem.CreateChildElement("parameter");
         parameterElem.SetString("name", graphics->GetShaderParameterName(j->first_));
         parameterElem.SetString("name", graphics->GetShaderParameterName(j->first_));
@@ -275,14 +266,9 @@ void Material::SetTechnique(unsigned index, Technique* technique, unsigned quali
     Update();
     Update();
 }
 }
 
 
-void Material::SetVertexShaderParameter(ShaderParameter parameter, const Vector4& value)
-{
-    vsParameters_[parameter] = value;
-}
-
-void Material::SetPixelShaderParameter(ShaderParameter parameter, const Vector4& value)
+void Material::SetShaderParameter(ShaderParameter parameter, const Vector4& value)
 {
 {
-    psParameters_[parameter] = value;
+    shaderParameters_[parameter] = value;
 }
 }
 
 
 void Material::SetTexture(TextureUnit unit, Texture* texture)
 void Material::SetTexture(TextureUnit unit, Texture* texture)
@@ -318,8 +304,8 @@ void Material::SetUVTransform(const Vector2& offset, float rotation, const Vecto
     
     
     transform = offsetMatrix * transform;
     transform = offsetMatrix * transform;
     
     
-    Vector4& uOffset = vsParameters_[VSP_UOFFSET];
-    Vector4& vOffset = vsParameters_[VSP_VOFFSET];
+    Vector4& uOffset = shaderParameters_[VSP_UOFFSET];
+    Vector4& vOffset = shaderParameters_[VSP_VOFFSET];
     uOffset.x_ = transform.m00_;
     uOffset.x_ = transform.m00_;
     uOffset.y_ = transform.m01_;
     uOffset.y_ = transform.m01_;
     uOffset.w_ = transform.m03_;
     uOffset.w_ = transform.m03_;
@@ -359,8 +345,7 @@ SharedPtr<Material> Material::Clone(const String& cloneName) const
     
     
     ret->SetName(cloneName);
     ret->SetName(cloneName);
     ret->techniques_ = techniques_;
     ret->techniques_ = techniques_;
-    ret->vsParameters_ = vsParameters_;
-    ret->psParameters_ = psParameters_;
+    ret->shaderParameters_ = shaderParameters_;
     ret->textures_ = textures_;
     ret->textures_ = textures_;
     ret->occlusion_ = occlusion_;
     ret->occlusion_ = occlusion_;
     ret->cullMode_ = cullMode_;
     ret->cullMode_ = cullMode_;

+ 6 - 12
Engine/Graphics/Material.h

@@ -73,10 +73,8 @@ public:
     void SetNumTechniques(unsigned num);
     void SetNumTechniques(unsigned num);
     /// Set technique
     /// Set technique
     void SetTechnique(unsigned index, Technique* technique, unsigned qualityLevel = 0, float lodDistance = 0.0f);
     void SetTechnique(unsigned index, Technique* technique, unsigned qualityLevel = 0, float lodDistance = 0.0f);
-    /// Set vertex shader parameter
-    void SetVertexShaderParameter(ShaderParameter parameter, const Vector4& value);
-    /// Set pixel shader parameter
-    void SetPixelShaderParameter(ShaderParameter parameter, const Vector4& value);
+    /// Set shader parameter
+    void SetShaderParameter(ShaderParameter parameter, const Vector4& value);
     /// Set texture
     /// Set texture
     void SetTexture(TextureUnit unit, Texture* texture);
     void SetTexture(TextureUnit unit, Texture* texture);
     /// Set texture coordinate transform
     /// Set texture coordinate transform
@@ -108,10 +106,8 @@ public:
     const Vector<SharedPtr<Texture> >& GetTextures() const { return textures_; }
     const Vector<SharedPtr<Texture> >& GetTextures() const { return textures_; }
     /// Return texture by unit
     /// Return texture by unit
     Texture* GetTexture(TextureUnit unit) const;
     Texture* GetTexture(TextureUnit unit) const;
-    /// Return all vertex shader parameters
-    const Map<ShaderParameter, Vector4>& GetVertexShaderParameters() const { return vsParameters_; }
-    /// Return all pixel shader parameters
-    const Map<ShaderParameter, Vector4>& GetPixelShaderParameters() const { return psParameters_; }
+    /// Return all shader parameters
+    const Map<ShaderParameter, Vector4>& GetShaderParameters() const { return shaderParameters_; }
     /// Return normal culling mode
     /// Return normal culling mode
     CullMode GetCullMode() const { return cullMode_; }
     CullMode GetCullMode() const { return cullMode_; }
     /// Return culling mode for shadows
     /// Return culling mode for shadows
@@ -132,10 +128,8 @@ private:
     Vector<TechniqueEntry> techniques_;
     Vector<TechniqueEntry> techniques_;
     /// Textures
     /// Textures
     Vector<SharedPtr<Texture> > textures_;
     Vector<SharedPtr<Texture> > textures_;
-    /// Vertex shader parameters
-    Map<ShaderParameter, Vector4> vsParameters_;
-    /// Pixel shader parameters
-    Map<ShaderParameter, Vector4> psParameters_;
+    /// Shader parameters
+    Map<ShaderParameter, Vector4> shaderParameters_;
     /// Normal culling mode
     /// Normal culling mode
     CullMode cullMode_;
     CullMode cullMode_;
     /// Culling mode for shadow rendering
     /// Culling mode for shadow rendering

+ 8 - 8
Engine/Graphics/Renderer.cpp

@@ -1364,8 +1364,8 @@ void Renderer::SetupLightBatch(Batch& batch)
             graphics_->SetDepthTest(CMP_LESSEQUAL);
             graphics_->SetDepthTest(CMP_LESSEQUAL);
             graphics_->SetStencilTest(true, CMP_ALWAYS, OP_INCR, OP_KEEP, OP_KEEP, 1);
             graphics_->SetStencilTest(true, CMP_ALWAYS, OP_INCR, OP_KEEP, OP_KEEP, 1);
             graphics_->SetShaders(stencilVS_, stencilPS_);
             graphics_->SetShaders(stencilVS_, stencilPS_);
-            graphics_->SetVertexShaderParameter(VSP_VIEWPROJ, projection);
-            graphics_->SetVertexShaderParameter(VSP_MODEL, nearTransform);
+            graphics_->SetShaderParameter(VSP_VIEWPROJ, projection);
+            graphics_->SetShaderParameter(VSP_MODEL, nearTransform);
             
             
             // Draw to stencil
             // Draw to stencil
             batch.geometry_->Draw(graphics_);
             batch.geometry_->Draw(graphics_);
@@ -1391,8 +1391,8 @@ void Renderer::SetupLightBatch(Batch& batch)
             graphics_->SetDepthTest(drawBackFaces ? CMP_GREATER : CMP_LESS);
             graphics_->SetDepthTest(drawBackFaces ? CMP_GREATER : CMP_LESS);
             graphics_->SetStencilTest(true, CMP_EQUAL, OP_INCR, OP_KEEP, OP_KEEP, 0);
             graphics_->SetStencilTest(true, CMP_EQUAL, OP_INCR, OP_KEEP, OP_KEEP, 0);
             graphics_->SetShaders(stencilVS_, stencilPS_);
             graphics_->SetShaders(stencilVS_, stencilPS_);
-            graphics_->SetVertexShaderParameter(VSP_VIEWPROJ, projection * view);
-            graphics_->SetVertexShaderParameter(VSP_MODEL, model);
+            graphics_->SetShaderParameter(VSP_VIEWPROJ, projection * view);
+            graphics_->SetShaderParameter(VSP_MODEL, model);
             
             
             // Draw the other faces to stencil to mark where we should not draw
             // Draw the other faces to stencil to mark where we should not draw
             batch.geometry_->Draw(graphics_);
             batch.geometry_->Draw(graphics_);
@@ -1423,8 +1423,8 @@ void Renderer::SetupLightBatch(Batch& batch)
                     graphics_->SetDepthTest(CMP_GREATEREQUAL);
                     graphics_->SetDepthTest(CMP_GREATEREQUAL);
                     graphics_->SetStencilTest(true, CMP_ALWAYS, OP_INCR, OP_KEEP, OP_KEEP, 1);
                     graphics_->SetStencilTest(true, CMP_ALWAYS, OP_INCR, OP_KEEP, OP_KEEP, 1);
                     graphics_->SetShaders(stencilVS_, stencilPS_);
                     graphics_->SetShaders(stencilVS_, stencilPS_);
-                    graphics_->SetVertexShaderParameter(VSP_VIEWPROJ, projection * view);
-                    graphics_->SetVertexShaderParameter(VSP_MODEL, model);
+                    graphics_->SetShaderParameter(VSP_VIEWPROJ, projection * view);
+                    graphics_->SetShaderParameter(VSP_MODEL, model);
                     
                     
                     // Draw to stencil
                     // Draw to stencil
                     batch.geometry_->Draw(graphics_);
                     batch.geometry_->Draw(graphics_);
@@ -1455,9 +1455,9 @@ void Renderer::DrawFullScreenQuad(Camera& camera, ShaderVariation* vs, ShaderVar
     
     
     graphics_->SetCullMode(CULL_NONE);
     graphics_->SetCullMode(CULL_NONE);
     graphics_->SetShaders(vs, ps);
     graphics_->SetShaders(vs, ps);
-    graphics_->SetVertexShaderParameter(VSP_MODEL, model);
+    graphics_->SetShaderParameter(VSP_MODEL, model);
     // Get projection without jitter offset to ensure the whole screen is filled
     // Get projection without jitter offset to ensure the whole screen is filled
-    graphics_->SetVertexShaderParameter(VSP_VIEWPROJ, camera.GetProjection(false));
+    graphics_->SetShaderParameter(VSP_VIEWPROJ, camera.GetProjection(false));
     
     
     dirLightGeometry_->Draw(graphics_);
     dirLightGeometry_->Draw(graphics_);
 }
 }

+ 21 - 21
Engine/Graphics/View.cpp

@@ -827,10 +827,10 @@ void View::RenderBatchesDeferred()
     Vector4 viewportSize((float)screenRect_.left_ / gBufferWidth, (float)screenRect_.top_ / gBufferHeight,
     Vector4 viewportSize((float)screenRect_.left_ / gBufferWidth, (float)screenRect_.top_ / gBufferHeight,
         (float)screenRect_.right_ / gBufferWidth, (float)screenRect_.bottom_ / gBufferHeight);
         (float)screenRect_.right_ / gBufferWidth, (float)screenRect_.bottom_ / gBufferHeight);
     
     
-    graphics_->SetVertexShaderParameter(VSP_FRUSTUMSIZE, viewportParams);
-    graphics_->SetVertexShaderParameter(VSP_GBUFFEROFFSETS, bufferUVOffset);
-    graphics_->SetPixelShaderParameter(PSP_GBUFFEROFFSETS, bufferUVOffset);
-    graphics_->SetPixelShaderParameter(PSP_GBUFFERVIEWPORT, viewportSize);
+    graphics_->SetShaderParameter(VSP_FRUSTUMSIZE, viewportParams);
+    graphics_->SetShaderParameter(VSP_GBUFFEROFFSETS, bufferUVOffset);
+    graphics_->SetShaderParameter(PSP_GBUFFEROFFSETS, bufferUVOffset);
+    graphics_->SetShaderParameter(PSP_GBUFFERVIEWPORT, viewportSize);
     
     
     {
     {
         // Render G-buffer
         // Render G-buffer
@@ -1037,12 +1037,12 @@ void View::RenderBatchesDeferred()
         graphics_->SetTexture(TU_DIFFBUFFER, graphics_->GetScreenBuffer(jitterCounter_ & 1));
         graphics_->SetTexture(TU_DIFFBUFFER, graphics_->GetScreenBuffer(jitterCounter_ & 1));
         graphics_->SetTexture(TU_NORMALBUFFER, graphics_->GetScreenBuffer((jitterCounter_ + 1) & 1));
         graphics_->SetTexture(TU_NORMALBUFFER, graphics_->GetScreenBuffer((jitterCounter_ + 1) & 1));
         graphics_->SetTexture(TU_DEPTHBUFFER, graphics_->GetDepthBuffer());
         graphics_->SetTexture(TU_DEPTHBUFFER, graphics_->GetDepthBuffer());
-        graphics_->SetVertexShaderParameter(VSP_CAMERAROT, camera_->GetWorldTransform().RotationMatrix());
-        graphics_->SetVertexShaderParameter(VSP_DEPTHMODE, depthMode);
-        graphics_->SetPixelShaderParameter(PSP_CAMERAPOS, camera_->GetWorldPosition());
-        graphics_->SetPixelShaderParameter(PSP_ANTIALIASWEIGHTS, Vector4(thisFrameWeight, 1.0f - thisFrameWeight, 0.0f, 0.0f));
-        graphics_->SetPixelShaderParameter(PSP_SAMPLEOFFSETS, Vector4(1.0f / gBufferWidth, 1.0f / gBufferHeight, 0.0f, 0.0f));
-        graphics_->SetPixelShaderParameter(PSP_VIEWPROJ, camera_->GetProjection(false) * lastCameraView_);
+        graphics_->SetShaderParameter(VSP_CAMERAROT, camera_->GetWorldTransform().RotationMatrix());
+        graphics_->SetShaderParameter(VSP_DEPTHMODE, depthMode);
+        graphics_->SetShaderParameter(PSP_CAMERAPOS, camera_->GetWorldPosition());
+        graphics_->SetShaderParameter(PSP_ANTIALIASWEIGHTS, Vector4(thisFrameWeight, 1.0f - thisFrameWeight, 0.0f, 0.0f));
+        graphics_->SetShaderParameter(PSP_SAMPLEOFFSETS, Vector4(1.0f / gBufferWidth, 1.0f / gBufferHeight, 0.0f, 0.0f));
+        graphics_->SetShaderParameter(PSP_VIEWPROJ, camera_->GetProjection(false) * lastCameraView_);
         
         
         unsigned index = camera_->IsOrthographic() ? 1 : 0;
         unsigned index = camera_->IsOrthographic() ? 1 : 0;
         String shaderName = "TemporalAA_" + aaVariation[index];
         String shaderName = "TemporalAA_" + aaVariation[index];
@@ -2004,11 +2004,11 @@ void View::SetShaderParameters()
     Vector4 fogParams(fogStart / farClip, fogEnd / farClip, 1.0f / (fogRange / farClip), 0.0f);
     Vector4 fogParams(fogStart / farClip, fogEnd / farClip, 1.0f / (fogRange / farClip), 0.0f);
     Vector4 elapsedTime((time->GetTotalMSec() & 0x3fffff) / 1000.0f, 0.0f, 0.0f, 0.0f);
     Vector4 elapsedTime((time->GetTotalMSec() & 0x3fffff) / 1000.0f, 0.0f, 0.0f, 0.0f);
     
     
-    graphics_->SetVertexShaderParameter(VSP_ELAPSEDTIME, elapsedTime);
-    graphics_->SetPixelShaderParameter(PSP_AMBIENTCOLOR, zone_->GetAmbientColor());
-    graphics_->SetPixelShaderParameter(PSP_ELAPSEDTIME, elapsedTime);
-    graphics_->SetPixelShaderParameter(PSP_FOGCOLOR, zone_->GetFogColor());
-    graphics_->SetPixelShaderParameter(PSP_FOGPARAMS, fogParams);
+    graphics_->SetShaderParameter(VSP_ELAPSEDTIME, elapsedTime);
+    graphics_->SetShaderParameter(PSP_AMBIENTCOLOR, zone_->GetAmbientColor());
+    graphics_->SetShaderParameter(PSP_ELAPSEDTIME, elapsedTime);
+    graphics_->SetShaderParameter(PSP_FOGCOLOR, zone_->GetFogColor());
+    graphics_->SetShaderParameter(PSP_FOGPARAMS, fogParams);
 }
 }
 
 
 void View::DrawSplitLightToStencil(Camera& camera, Light* light, bool clear)
 void View::DrawSplitLightToStencil(Camera& camera, Light* light, bool clear)
@@ -2033,8 +2033,8 @@ void View::DrawSplitLightToStencil(Camera& camera, Light* light, bool clear)
             graphics_->SetCullMode(drawBackFaces ? CULL_CW : CULL_CCW);
             graphics_->SetCullMode(drawBackFaces ? CULL_CW : CULL_CCW);
             graphics_->SetDepthTest(drawBackFaces ? CMP_GREATER : CMP_LESS);
             graphics_->SetDepthTest(drawBackFaces ? CMP_GREATER : CMP_LESS);
             graphics_->SetShaders(renderer_->stencilVS_, renderer_->stencilPS_);
             graphics_->SetShaders(renderer_->stencilVS_, renderer_->stencilPS_);
-            graphics_->SetVertexShaderParameter(VSP_MODEL, model);
-            graphics_->SetVertexShaderParameter(VSP_VIEWPROJ, projection * view);
+            graphics_->SetShaderParameter(VSP_MODEL, model);
+            graphics_->SetShaderParameter(VSP_VIEWPROJ, projection * view);
             
             
             // Draw the faces to stencil which we should draw (where no light has not been rendered yet)
             // Draw the faces to stencil which we should draw (where no light has not been rendered yet)
             graphics_->SetStencilTest(true, CMP_EQUAL, OP_INCR, OP_KEEP, OP_KEEP, 0);
             graphics_->SetStencilTest(true, CMP_EQUAL, OP_INCR, OP_KEEP, OP_KEEP, 0);
@@ -2082,8 +2082,8 @@ void View::DrawSplitLightToStencil(Camera& camera, Light* light, bool clear)
                 {
                 {
                     graphics_->SetDepthTest(CMP_GREATEREQUAL);
                     graphics_->SetDepthTest(CMP_GREATEREQUAL);
                     graphics_->SetShaders(renderer_->stencilVS_, renderer_->stencilPS_);
                     graphics_->SetShaders(renderer_->stencilVS_, renderer_->stencilPS_);
-                    graphics_->SetVertexShaderParameter(VSP_MODEL, farTransform);
-                    graphics_->SetVertexShaderParameter(VSP_VIEWPROJ, projection);
+                    graphics_->SetShaderParameter(VSP_MODEL, farTransform);
+                    graphics_->SetShaderParameter(VSP_VIEWPROJ, projection);
                     graphics_->SetStencilTest(true, CMP_ALWAYS, OP_REF, OP_ZERO, OP_ZERO, 1);
                     graphics_->SetStencilTest(true, CMP_ALWAYS, OP_REF, OP_ZERO, OP_ZERO, 1);
                 }
                 }
                 // Otherwise draw at split near plane
                 // Otherwise draw at split near plane
@@ -2091,8 +2091,8 @@ void View::DrawSplitLightToStencil(Camera& camera, Light* light, bool clear)
                 {
                 {
                     graphics_->SetDepthTest(CMP_LESSEQUAL);
                     graphics_->SetDepthTest(CMP_LESSEQUAL);
                     graphics_->SetShaders(renderer_->stencilVS_, renderer_->stencilPS_);
                     graphics_->SetShaders(renderer_->stencilVS_, renderer_->stencilPS_);
-                    graphics_->SetVertexShaderParameter(VSP_MODEL, nearTransform);
-                    graphics_->SetVertexShaderParameter(VSP_VIEWPROJ, projection);
+                    graphics_->SetShaderParameter(VSP_MODEL, nearTransform);
+                    graphics_->SetShaderParameter(VSP_VIEWPROJ, projection);
                     graphics_->SetStencilTest(true, CMP_ALWAYS, OP_REF, OP_ZERO, OP_ZERO, 1);
                     graphics_->SetStencilTest(true, CMP_ALWAYS, OP_REF, OP_ZERO, OP_ZERO, 1);
                 }
                 }
                 
                 

+ 3 - 3
Engine/UI/UI.cpp

@@ -250,9 +250,9 @@ void UI::Render()
     graphics_->SetDepthWrite(false);
     graphics_->SetDepthWrite(false);
     graphics_->SetFillMode(FILL_SOLID);
     graphics_->SetFillMode(FILL_SOLID);
     graphics_->SetStencilTest(false);
     graphics_->SetStencilTest(false);
-    graphics_->SetVertexShaderParameter(VSP_MODEL, Matrix3x4::IDENTITY);
-    graphics_->SetVertexShaderParameter(VSP_VIEWPROJ, projection);
-    graphics_->SetPixelShaderParameter(PSP_MATDIFFCOLOR, Color(1.0f, 1.0f, 1.0f, 1.0f));
+    graphics_->SetShaderParameter(VSP_MODEL, Matrix3x4::IDENTITY);
+    graphics_->SetShaderParameter(VSP_VIEWPROJ, projection);
+    graphics_->SetShaderParameter(PSP_MATDIFFCOLOR, Color(1.0f, 1.0f, 1.0f, 1.0f));
     
     
     ShaderVariation* ps = 0;
     ShaderVariation* ps = 0;
     ShaderVariation* vs = 0;
     ShaderVariation* vs = 0;