From 047e71a4e15001ca028b6f7ce60ae4da4d26b57d Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Thu, 4 Feb 2016 16:18:54 +0100 Subject: [PATCH 001/130] Added BoostAssault,BoostDefender components. Added their effects in HealthSystem,PlayerMovementSystem --- resources/Schema/Components.xsd | 2 + resources/Schema/Components/BoostAssault.xml | 16 ++ resources/Schema/Components/BoostAssault.xsd | 18 ++ resources/Schema/Components/BoostDefender.xml | 16 ++ resources/Schema/Components/BoostDefender.xsd | 18 ++ .../Schema/Entities/BoostAssaultTest.xml | 243 ++++++++++++++++++ src/Game/Systems/HealthSystem.cpp | 3 + src/Game/Systems/PlayerMovementSystem.cpp | 9 +- 8 files changed, 322 insertions(+), 3 deletions(-) create mode 100644 resources/Schema/Components/BoostAssault.xml create mode 100644 resources/Schema/Components/BoostAssault.xsd create mode 100644 resources/Schema/Components/BoostDefender.xml create mode 100644 resources/Schema/Components/BoostDefender.xsd create mode 100644 resources/Schema/Entities/BoostAssaultTest.xml diff --git a/resources/Schema/Components.xsd b/resources/Schema/Components.xsd index ab46b0ea..36060753 100644 --- a/resources/Schema/Components.xsd +++ b/resources/Schema/Components.xsd @@ -29,4 +29,6 @@ + + \ No newline at end of file diff --git a/resources/Schema/Components/BoostAssault.xml b/resources/Schema/Components/BoostAssault.xml new file mode 100644 index 00000000..099d3b0c --- /dev/null +++ b/resources/Schema/Components/BoostAssault.xml @@ -0,0 +1,16 @@ + + + + + + 5 + + + 5 + + + + + + + diff --git a/resources/Schema/Components/BoostAssault.xsd b/resources/Schema/Components/BoostAssault.xsd new file mode 100644 index 00000000..f7d348b7 --- /dev/null +++ b/resources/Schema/Components/BoostAssault.xsd @@ -0,0 +1,18 @@ + + + + + + + + This is the assault's class boost component + + + + + This is the strength of the boost effect + + + + + diff --git a/resources/Schema/Components/BoostDefender.xml b/resources/Schema/Components/BoostDefender.xml new file mode 100644 index 00000000..489d30cd --- /dev/null +++ b/resources/Schema/Components/BoostDefender.xml @@ -0,0 +1,16 @@ + + + + + + 10 + + + 5 + + + + + + + diff --git a/resources/Schema/Components/BoostDefender.xsd b/resources/Schema/Components/BoostDefender.xsd new file mode 100644 index 00000000..167b41dd --- /dev/null +++ b/resources/Schema/Components/BoostDefender.xsd @@ -0,0 +1,18 @@ + + + + + + + + This is the defender's class boost component + + + + + This is the strength of the boost effect + + + + + diff --git a/resources/Schema/Entities/BoostAssaultTest.xml b/resources/Schema/Entities/BoostAssaultTest.xml new file mode 100644 index 00000000..97fd3f4d --- /dev/null +++ b/resources/Schema/Entities/BoostAssaultTest.xml @@ -0,0 +1,243 @@ + + + + + + + + + + + + Models\MapVersion1.mesh + + + + + + + + + 2 + + + Models/DirectionalLightWidget.mesh + false + + + + + + + + + + + + + 8 + 2.7999999523162842 + + + + + + + + + + + 8 + 2.7999999523162842 + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + Models/Core/UnitCube.mesh + false + + + Schema/Entities/Player.xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Models/Core/UnitCube.mesh + false + + + Schema/Entities/Player.xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Game/Systems/HealthSystem.cpp b/src/Game/Systems/HealthSystem.cpp index 9e118070..3f64d7b9 100644 --- a/src/Game/Systems/HealthSystem.cpp +++ b/src/Game/Systems/HealthSystem.cpp @@ -49,6 +49,9 @@ bool HealthSystem::OnPlayerDamaged(Events::PlayerDamage& e) { ComponentWrapper cHealth = e.Player["Health"]; double& health = cHealth["Health"]; + if (e.Player.HasComponent("BoostDefender")) { + e.Damage -= (double)e.Player["BoostDefender"]["StrengthOfEffect"]; + } health -= e.Damage; if (health <= 0.0) { diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index 72900d7a..bb50942d 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -1,6 +1,6 @@ #include "Systems/PlayerMovementSystem.h" -PlayerMovementSystem::PlayerMovementSystem(World* world, EventBroker* eventBroker) +PlayerMovementSystem::PlayerMovementSystem(World* world, EventBroker* eventBroker) : System(world, eventBroker) , PureSystem("Player") { @@ -72,6 +72,10 @@ void PlayerMovementSystem::Update(double dt) ImGui::InputFloat("surfaceFriction", &surfaceFriction); float accelerationSpeed = actualAccel * (float)dt * wishSpeed * surfaceFriction; accelerationSpeed = glm::min(accelerationSpeed, addSpeed); + //if player has Boost from an Assault class, accelerate the player faster + if (player.HasComponent("BoostAssault")) { + accelerationSpeed *= (double) player["BoostAssault"]["StrengthOfEffect"]; + } velocity += accelerationSpeed * wishDirection; ImGui::Text("velocity: (%f, %f, %f) |%f|", velocity.x, velocity.y, velocity.z, glm::length(velocity)); } @@ -79,8 +83,7 @@ void PlayerMovementSystem::Update(double dt) if (controller->Jumping() && !controller->Crouching() && (velocity.y == 0.f || !controller->DoubleJumping())) { if (velocity.y == 0.f) { controller->SetDoubleJumping(false); - } - else { + } else { controller->SetDoubleJumping(true); } velocity.y += 4.f; From 7f1016476b80878d0374da7e79d948a787fa636c Mon Sep 17 00:00:00 2001 From: Ayumiwii Date: Fri, 5 Feb 2016 15:08:56 +0100 Subject: [PATCH 002/130] Shadows WIP - create 2D texture (depthmap) --- .../Engine/Rendering/DirectionalLightJob.h | 5 +- include/Engine/Rendering/Renderer.h | 2 + include/Engine/Rendering/ShadowPass.cpp | 124 ++ include/Engine/Rendering/ShadowPass.h | 50 + include/Engine/Rendering/ShadowPassState.h | 15 + resources/Schema/Entities/OliviaTestWorld.xml | 1558 +++++++++++++++++ resources/Shaders/Shadow.frag.glsl | 18 + resources/Shaders/Shadow.vert.glsl | 17 + src/Engine/Rendering/FrameBuffer.cpp | 2 +- src/Engine/Rendering/Renderer.cpp | 9 +- src/Engine/Rendering/ShadowPassState.cpp | 16 + 11 files changed, 1812 insertions(+), 4 deletions(-) create mode 100644 include/Engine/Rendering/ShadowPass.cpp create mode 100644 include/Engine/Rendering/ShadowPass.h create mode 100644 include/Engine/Rendering/ShadowPassState.h create mode 100644 resources/Schema/Entities/OliviaTestWorld.xml create mode 100644 resources/Shaders/Shadow.frag.glsl create mode 100644 resources/Shaders/Shadow.vert.glsl create mode 100644 src/Engine/Rendering/ShadowPassState.cpp diff --git a/include/Engine/Rendering/DirectionalLightJob.h b/include/Engine/Rendering/DirectionalLightJob.h index 5f104ca5..0fcfaf84 100644 --- a/include/Engine/Rendering/DirectionalLightJob.h +++ b/include/Engine/Rendering/DirectionalLightJob.h @@ -15,13 +15,14 @@ struct DirectionalLightJob : RenderJob DirectionalLightJob(ComponentWrapper transformComponent, ComponentWrapper directionalLightComponent, World* m_World) : RenderJob() { - - Direction = glm::vec4(0,0,-1,0) * glm::inverse(Transform::AbsoluteOrientation(m_World, transformComponent.EntityID)); + Orientation = Transform::AbsoluteOrientation(m_World, transformComponent.EntityID); + Direction = glm::vec4(0,0,-1,0) * glm::inverse(Orientation); //Direction = glm::vec4((glm::vec3)directionalLightComponent["Direction"], 0.f); Color = (glm::vec4)directionalLightComponent["Color"]; Intensity = (double)directionalLightComponent["Intensity"]; }; + glm::quat Orientation; glm::vec4 Direction; glm::vec4 Color; float Intensity; diff --git a/include/Engine/Rendering/Renderer.h b/include/Engine/Rendering/Renderer.h index 33a61edf..74338e40 100644 --- a/include/Engine/Rendering/Renderer.h +++ b/include/Engine/Rendering/Renderer.h @@ -22,6 +22,7 @@ #include "../Core/Transform.h" #include "imgui/imgui.h" #include "TextPass.h" +#include "ShadowPass.h" class Renderer : public IRenderer { @@ -57,6 +58,7 @@ private: DrawScreenQuadPass* m_DrawScreenQuadPass; DrawBloomPass* m_DrawBloomPass; DrawColorCorrectionPass* m_DrawColorCorrectionPass; + ShadowPass* m_ShadowPass; //----------------------Functions----------------------// void InitializeWindow(); diff --git a/include/Engine/Rendering/ShadowPass.cpp b/include/Engine/Rendering/ShadowPass.cpp new file mode 100644 index 00000000..94844d1f --- /dev/null +++ b/include/Engine/Rendering/ShadowPass.cpp @@ -0,0 +1,124 @@ +#include "ShadowPass.h" + +ShadowPass::ShadowPass(IRenderer * renderer) +{ + m_Renderer = renderer; + + //InitializeTextures(); + InitializeFrameBuffers(); + InitializeShaderPrograms(); +} + +ShadowPass::~ShadowPass() +{ + +} + + +void ShadowPass::InitializeFrameBuffers() +{ + +// glGenRenderbuffers(1, &m_DepthFBO); +// glBindRenderbuffer(GL_RENDERBUFFER, m_DepthFBO); +// glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height); + + // Depth texture + glGenTextures(1, &m_DepthMap); + glBindTexture(GL_TEXTURE_2D, m_DepthMap); + //glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 1024, 1024, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr); + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 1024, 1024, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr); + //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, 1024, 1024, 0, GL_RGB, GL_FLOAT, 0); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + m_DepthBuffer.AddResource(std::shared_ptr(new Texture2D(&m_DepthMap, GL_DEPTH_ATTACHMENT))); + //m_DepthBuffer.AddResource(std::shared_ptr(new Texture2D(&m_DepthMap, GL_COLOR_ATTACHMENT0))); + m_DepthBuffer.Generate(); + + GLERROR("depthMap failed"); + +} + +void ShadowPass::InitializeShaderPrograms() +{ + m_ShadowProgram = ResourceManager::Load("#ShadowProgram"); + m_ShadowProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/Shadow.vert.glsl"))); + m_ShadowProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/Shadow.frag.glsl"))); + m_ShadowProgram->Compile(); + m_ShadowProgram->BindFragDataLocation(0, "ShadowMap"); + m_ShadowProgram->Link(); +} + +void ShadowPass::ClearBuffer() +{ + m_DepthBuffer.Bind(); + glClearColor(0.f, 0.f, 0.f, 0.f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + m_DepthBuffer.Unbind(); +} + +void ShadowPass::Draw(RenderScene & scene) +{ + ShadowPassState* state = new ShadowPassState(m_DepthBuffer.GetHandle()); + + GLuint shaderHandle = m_ShadowProgram->GetHandle(); + glDrawBuffer(GL_NONE); + glReadBuffer(GL_NONE); + m_ShadowProgram->Bind(); + + //if (scene.ClearDepth) { + // glClear(GL_COLOR_BUFFER_BIT); + //} + + for (auto &job : scene.DirectionalLightJobs) { + auto directionalLightJob = std::dynamic_pointer_cast(job); + + if(directionalLightJob) { + + GLfloat near_plane = 1.0f, far_plane = 200.5f; + glm::mat4 lightProjection = glm::ortho(-10.0f, 10.0f, -10.0f, 10.0f, near_plane, far_plane); + + // broken? + //glm::mat4 lightView = glm::lookAt(-glm::normalize(glm::vec3(directionalLightJob->Direction)), glm::vec3(0,0,0), glm::vec3(0,1,0)); + glm::mat4 lightView = glm::lookAt(glm::vec3(50.f, 50.f, 50.f), glm::vec3(0.f, 0.f, 0.f), glm::vec3(0.f, 1.f, 0.f)); + //glm::mat4 lightSpaceMatrix = lightProjection * lightView; + + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix())); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix())); + + GLERROR("ShadowLight ERROR"); + + for (auto &objectJob : scene.OpaqueObjects) { + auto modelJob = std::dynamic_pointer_cast(objectJob); + + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); + + glBindVertexArray(modelJob->Model->VAO); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); + glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int))); + + GLERROR("Shadow Draw ERROR"); + + } + + } + + m_DepthBuffer.Unbind(); + + delete state; + + + } + + + + + //m_ShadowProgram->Unbind(); + + + + + +} diff --git a/include/Engine/Rendering/ShadowPass.h b/include/Engine/Rendering/ShadowPass.h new file mode 100644 index 00000000..c578339e --- /dev/null +++ b/include/Engine/Rendering/ShadowPass.h @@ -0,0 +1,50 @@ +#ifndef ShadowPass_h_ +#define ShadowPass_h_ + +#include "IRenderer.h" +#include "FrameBuffer.h" +#include "ShaderProgram.h" +#include "../Core/EventBroker.h" +#include "../Core/World.h" +#include "ShadowPassState.h" + +//#include "ShadowPassState.h" // not created yet + + + +class ShadowPass +{ +public: + + ShadowPass(IRenderer* renderer); + ~ShadowPass(); + + void InitializeFrameBuffers(); + void InitializeShaderPrograms(); + void ClearBuffer(); + void Draw(RenderScene& scene); + + + + GLuint DepthMap() const { return m_DepthMap; } + + +private: + + + + EventBroker* m_EventBroker; + + const IRenderer* m_Renderer; + + GLuint m_DepthMap; + + FrameBuffer m_DepthBuffer; + + ShaderProgram* m_ShadowProgram; + + GLuint m_DepthFBO; + +}; + +#endif \ No newline at end of file diff --git a/include/Engine/Rendering/ShadowPassState.h b/include/Engine/Rendering/ShadowPassState.h new file mode 100644 index 00000000..ec08a77c --- /dev/null +++ b/include/Engine/Rendering/ShadowPassState.h @@ -0,0 +1,15 @@ +#ifndef ShadowPassState_h_ +#define ShadowPassState_h_ + +#include "Rendering/RenderState.h" + +class ShadowPassState : public RenderState +{ +public: + ShadowPassState(GLuint frameBuffer); + ~ShadowPassState(); + +private: +}; + +#endif \ No newline at end of file diff --git a/resources/Schema/Entities/OliviaTestWorld.xml b/resources/Schema/Entities/OliviaTestWorld.xml new file mode 100644 index 00000000..23c2b283 --- /dev/null +++ b/resources/Schema/Entities/OliviaTestWorld.xml @@ -0,0 +1,1558 @@ + + + + + + + + + + + + + + + + Models/Core/UnitPlane.mesh + + + + + + + + + + + 90 + + + + + + + + + + + + 1 + + + + + + + + + + + Audio/crosscounter.wav + true + + + + + + + + + + SoundEmitter + Fonts/DroidSans.ttf,64 + + + + + + + + + + + + + + + + + + + + + Sound Test + Fonts/DroidSans.ttf,64 + + + + + + + + + + + + + 0.80000001192092896 + + + Models/DirectionalLightWidget.mesh + + + 1 + + + + + + + + + + + + + + + + + + + + + Run + + 1 + + + models/AssaultAnimated.mesh + + + + + + + + + + + Walk + + 1 + + + models/AssaultAnimated.mesh + + + + + + + + + Animation test + Fonts/DroidSans.ttf,64 + + + + + + + + + + + + Models/Core/UnitCylinder.mesh + + + + + + + + + + + + + + + + + + + + 0.5 + + + + + + + + + + + Run + + 1 + + + Models/AssaultAnimated.mesh + + + + + + + + + + + + + + + + + + + + + + + + models/NormSpecIncdMapSphere.mesh + + + + + + + + + 1 + + + + + + + + + + + Models/Core/UnitSphere.mesh + + + + 3 + 1.1399998664855957 + + + + + + + + + + + + Models/Core/UnitSphere.mesh + + + + 5.0100002288818359 + 0.69999998807907104 + + + + + + + + + + + + Models/Core/UnitSphere.mesh + + + + 4 + 0.80000001192092896 + + + + + + + + + + + + + + 1 + + + + + + + + + + + Models/NormalMapSphere.mesh + + + + + + + + + + + Models/SpecularMapSphere.mesh + + + + + + + + + + 1 + + + + + + + + + + + Models/Core/UnitSphere.mesh + + + + 3 + 1.1399998664855957 + + + + + + + + + + + + + + + + Models/IncandescenceMapSphere.mesh + + + + + + + + + + + + + TextureMap's Test + Fonts/DroidSans.ttf,64 + + + + + + + + + + + + + + 1.3999999761581421 + + + + + + + + + + + + + + + + + Schema/Entities/Player.xml + + + + + + + + + + + + + + + + Models/Assault.mesh + + + + + + + + + + + + + Models/Assault.mesh + + + + + + + + + + + + + Models/Assault.mesh + + + + + + + + + + + + + Models/Assault.mesh + + + + + + + + + + + + + + + Schema/Entities/Player.xml + + + + + + + + + + + + + + + + + Models/Assault.mesh + + + + + + + + + + + + + Models/Assault.mesh + + + + + + + + + + + + + Models/Assault.mesh + + + + + + + + + + + + + Models/Assault.mesh + + + + + + + + + + + + + + Spawn Test + Fonts/DroidSans.ttf,64 + + + + + + + + + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + true + + + + + + + + + + + Models/Core/UnitCylinder.mesh + + true + + + + + + + + + + + + Models/Core/UnitRaptor.mesh + + true + + + + + + + + + + + Models/Assault.mesh + + true + + + + + + + + + + + + Models/Core/UnitCube.mesh + + true + + + + + + + + + + + + + Transparency Test + Fonts/DroidSans.ttf,64 + + + + + + + + + + + + + + + + + + + + + Models/Core/UnitCylinder.mesh + + + + + + + + + + + + + + + + + + + + 0.5 + + + + + + + + + + + Models/AssaultBlueWeapon.mesh + + + + + + + + + + + + + + + + Models/Core/UnitCylinder.mesh + + + + + + + + + + + + + + + + + + + + 0.5 + + + + + + + + + + + Models/AssaultRedWeapon.mesh + + + + + + + + + + + + + + + + Asset Test + Fonts/DroidSans.ttf,64 + + + + + + + + + + + + Models/Core/UnitCylinder.mesh + + + + + + + + + + + + + + + + + + + + 0.5 + + + + + + + + + + + Models/SecondaryWeapon.mesh + + + + + + + + + + + + + + + + Models/Core/UnitCylinder.mesh + + + + + + + + + + + + + + + + + + + + 0.5 + + + + + + + + + + + Models/AssualtSoft.mesh + + + + + + + + + + + + + + + Models/Core/UnitCylinder.mesh + + + + + + + + + + + + + + + + + + + + 0.5 + + + + + + + + + + + Models/DefenderGunBlue.mesh + + + + + + + + + + + + + + + + Models/Core/UnitCylinder.mesh + + + + + + + + + + + + + + + + + + + + 0.5 + + + + + + + + + + + Models/DefenderGunRed.mesh + + + + + + + + + + + + + + + + Models/Core/UnitCylinder.mesh + + + + + + + + + + + + + + + + + + + + 0.5 + + + + + + + + + + + Models/Assualt.mesh + + + + + + + + + + + + + + + + + + + + + + + + CapturePoint Test + Fonts/DroidSans.ttf,64 + + + + + + + + + + + + Models/CapturePoint.mesh + + + + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + true + + + + + + + + + + + + + + + + + + Red team home point + Fonts/DroidSans.ttf,64 + + + + + + + + + + + + + + + Models/CapturePoint.mesh + + + + + + + + + + + 1 + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + + RedMiddle Point + Fonts/DroidSans.ttf + + + + + + + + + + + + + + + Models/CapturePoint.mesh + + + + + + + + + 2 + + + Models/Core/UnitCube.mesh + true + + + + + + + + + + + + + + Middle Point + Fonts/DroidSans.ttf,64 + + + + + + + + + + + + + + + Models/CapturePoint.mesh + + + + + + + + + + + -12.033302729641917 + 3 + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + + BlueMiddle Point + Fonts/DroidSans.ttf + + + + + + + + + + + + + + + Models/CapturePoint.mesh + + + + + + + + + + + + + + 4 + + + Models/Core/UnitCube.mesh + + true + + + + + + + + + + + + + + + + + + Blue team home point + Fonts/DroidSans.ttf,64 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Models/Test/ObstacleCourse.mesh + + + + + + + + + + + Collision Test + Fonts/DroidSans.ttf,64 + + + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + + + + + + + + Models/Core/UnitCylinder.mesh + + + + + + + + + + + + + + + + + + + + 0.5 + + + + + + + + + + + true + + 2.3331127968986038 + 3.7999999523162842 + + true + + + Models/AssaultWeaponBlue.mesh + true + + + + + + + + + + + + + + + + Models/Core/UnitCylinder.mesh + + + + + + + + + + + + + + + + + + + + 0.5 + + + + + + + + + + + + + 0.28322599621543532 + + + Models/Assault.mesh + true + + + + + + + + + + + + + + + Models/Core/UnitCylinder.mesh + + + + + + + + + + + + + + + + + + + + 0.5 + + + + + + + + + + + Walk + + 1 + + + true + + + 1.8831113377486872 + + true + + + Models/AssaultAnimated.mesh + true + + + + + + + + + + + + + + + ExplosionEffect Test + Fonts/DroidSans.ttf,64 + + + + + + + + + + + + + + + + + + + + + Remember to pick random entities. + Fonts/DroidSans.ttf,64 + + + + + + + + + + + + + + diff --git a/resources/Shaders/Shadow.frag.glsl b/resources/Shaders/Shadow.frag.glsl new file mode 100644 index 00000000..04cc05df --- /dev/null +++ b/resources/Shaders/Shadow.frag.glsl @@ -0,0 +1,18 @@ +#version 430 + + + +in VertexData{ + vec3 Position; +}Input; + +//layout(location = 0 ) out vec4 ShadowMap; +layout(location = 0 ) out float ShadowMap; + +void main() +{ + //ShadowMap = vec4(vec3(gl_FragCoord.z), 1.0); + //ShadowMap = gl_FragCoord.z; +} + + diff --git a/resources/Shaders/Shadow.vert.glsl b/resources/Shaders/Shadow.vert.glsl new file mode 100644 index 00000000..cc1ee0a9 --- /dev/null +++ b/resources/Shaders/Shadow.vert.glsl @@ -0,0 +1,17 @@ +#version 430 + +uniform mat4 M; +uniform mat4 V; +uniform mat4 P; + +layout(location = 0) in vec3 Position; + +out VertexData{ + vec3 Position; +}Output; + +void main() +{ + Output.Position = Position; + gl_Position = P * V * M * vec4(Position, 1.0); +} \ No newline at end of file diff --git a/src/Engine/Rendering/FrameBuffer.cpp b/src/Engine/Rendering/FrameBuffer.cpp index 9677f50e..4f83122e 100644 --- a/src/Engine/Rendering/FrameBuffer.cpp +++ b/src/Engine/Rendering/FrameBuffer.cpp @@ -58,7 +58,7 @@ void FrameBuffer::Generate() } - if ((*it)->m_Attachment != GL_DEPTH_ATTACHMENT) { + if ((*it)->m_ResourceType == GL_TEXTURE_2D) { attachments.push_back((*it)->m_Attachment); } } diff --git a/src/Engine/Rendering/Renderer.cpp b/src/Engine/Rendering/Renderer.cpp index a63e02a0..147fed65 100644 --- a/src/Engine/Rendering/Renderer.cpp +++ b/src/Engine/Rendering/Renderer.cpp @@ -93,7 +93,7 @@ void Renderer::Update(double dt) void Renderer::Draw(RenderFrame& frame) { - ImGui::Combo("Draw textures", &m_DebugTextureToDraw, "Final\0Scene\0Bloom\0Gaussian\0Picking"); + ImGui::Combo("Draw textures", &m_DebugTextureToDraw, "Final\0Scene\0Bloom\0Gaussian\0Picking\0Shadow"); //clear buffer 0 glClearColor(0.f, 0.f, 0.f, 0.f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -102,11 +102,13 @@ void Renderer::Draw(RenderFrame& frame) m_PickingPass->ClearPicking(); m_DrawFinalPass->ClearBuffer(); m_DrawBloomPass->ClearBuffer(); + m_ShadowPass->ClearBuffer(); for (auto scene : frame.RenderScenes){ SortRenderJobsByDepth(*scene); m_PickingPass->Draw(*scene); + m_ShadowPass->Draw(*scene); m_LightCullingPass->GenerateNewFrustum(*scene); m_LightCullingPass->FillLightList(*scene); m_LightCullingPass->CullLights(*scene); @@ -133,6 +135,10 @@ void Renderer::Draw(RenderFrame& frame) } if (m_DebugTextureToDraw == 4) { m_DrawScreenQuadPass->Draw(m_PickingPass->PickingTexture()); + } + if (m_DebugTextureToDraw == 5) { + m_DrawScreenQuadPass->Draw(m_ShadowPass->DepthMap()); + // m_DrawScreenQuadPass->Draw(); } m_ImGuiRenderPass->Draw(); @@ -177,4 +183,5 @@ void Renderer::InitializeRenderPasses() m_DrawScreenQuadPass = new DrawScreenQuadPass(this); m_DrawBloomPass = new DrawBloomPass(this); m_DrawColorCorrectionPass = new DrawColorCorrectionPass(this); + m_ShadowPass = new ShadowPass(this); } diff --git a/src/Engine/Rendering/ShadowPassState.cpp b/src/Engine/Rendering/ShadowPassState.cpp new file mode 100644 index 00000000..caa09b9f --- /dev/null +++ b/src/Engine/Rendering/ShadowPassState.cpp @@ -0,0 +1,16 @@ +#include "Rendering/ShadowPassState.h" + +ShadowPassState::ShadowPassState(GLuint frameBuffer) +{ + GLERROR("---2"); + BindFramebuffer(frameBuffer); + GLERROR("---3"); + Enable(GL_DEPTH_TEST); + Enable(GL_CULL_FACE); + Disable(GL_BLEND); +} + +ShadowPassState::~ShadowPassState() +{ + +} \ No newline at end of file From c912cd7a428492c0b659a88a1611a3adb8c1490e Mon Sep 17 00:00:00 2001 From: Ayumiwii Date: Fri, 5 Feb 2016 15:12:17 +0100 Subject: [PATCH 003/130] Shadows wip --- include/Engine/Rendering/ShadowPass.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/Engine/Rendering/ShadowPass.cpp b/include/Engine/Rendering/ShadowPass.cpp index 94844d1f..2fe14238 100644 --- a/include/Engine/Rendering/ShadowPass.cpp +++ b/include/Engine/Rendering/ShadowPass.cpp @@ -62,10 +62,10 @@ void ShadowPass::ClearBuffer() void ShadowPass::Draw(RenderScene & scene) { ShadowPassState* state = new ShadowPassState(m_DepthBuffer.GetHandle()); - - GLuint shaderHandle = m_ShadowProgram->GetHandle(); glDrawBuffer(GL_NONE); glReadBuffer(GL_NONE); + + GLuint shaderHandle = m_ShadowProgram->GetHandle(); m_ShadowProgram->Bind(); //if (scene.ClearDepth) { From 0e51ae7dc91e6cb8a85d369a550cff6ba811166d Mon Sep 17 00:00:00 2001 From: Ayumiwii Date: Fri, 5 Feb 2016 15:31:20 +0100 Subject: [PATCH 004/130] shadow wip --- assets | 2 +- include/Engine/Rendering/ShadowPass.cpp | 2 -- resources/Shaders/Shadow.frag.glsl | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/assets b/assets index c4898d82..091ad5c0 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit c4898d8281b5584d89b1caf14dab8e5fac120321 +Subproject commit 091ad5c01bf7b6ef5501fc907fc610576a4a45ea diff --git a/include/Engine/Rendering/ShadowPass.cpp b/include/Engine/Rendering/ShadowPass.cpp index 2fe14238..33549d03 100644 --- a/include/Engine/Rendering/ShadowPass.cpp +++ b/include/Engine/Rendering/ShadowPass.cpp @@ -62,8 +62,6 @@ void ShadowPass::ClearBuffer() void ShadowPass::Draw(RenderScene & scene) { ShadowPassState* state = new ShadowPassState(m_DepthBuffer.GetHandle()); - glDrawBuffer(GL_NONE); - glReadBuffer(GL_NONE); GLuint shaderHandle = m_ShadowProgram->GetHandle(); m_ShadowProgram->Bind(); diff --git a/resources/Shaders/Shadow.frag.glsl b/resources/Shaders/Shadow.frag.glsl index 04cc05df..b2f7115b 100644 --- a/resources/Shaders/Shadow.frag.glsl +++ b/resources/Shaders/Shadow.frag.glsl @@ -12,7 +12,7 @@ layout(location = 0 ) out float ShadowMap; void main() { //ShadowMap = vec4(vec3(gl_FragCoord.z), 1.0); - //ShadowMap = gl_FragCoord.z; + ShadowMap = (glgl_FragCoord.x, glgl_FragCoord.y, glgl_FragCoord.z); } From bbf6058c17d904873710c41e53bd1b6c1a2c49fb Mon Sep 17 00:00:00 2001 From: Ayumiwii Date: Fri, 5 Feb 2016 16:13:46 +0100 Subject: [PATCH 005/130] Shadow WIP - fixed file placing of ShadowPass.cpp --- resources/Shaders/Shadow.frag.glsl | 2 +- .../Engine/Rendering/ShadowPass.cpp | 23 +++++++++++-------- 2 files changed, 14 insertions(+), 11 deletions(-) rename {include => src}/Engine/Rendering/ShadowPass.cpp (78%) diff --git a/resources/Shaders/Shadow.frag.glsl b/resources/Shaders/Shadow.frag.glsl index b2f7115b..983cc828 100644 --- a/resources/Shaders/Shadow.frag.glsl +++ b/resources/Shaders/Shadow.frag.glsl @@ -12,7 +12,7 @@ layout(location = 0 ) out float ShadowMap; void main() { //ShadowMap = vec4(vec3(gl_FragCoord.z), 1.0); - ShadowMap = (glgl_FragCoord.x, glgl_FragCoord.y, glgl_FragCoord.z); + ShadowMap = (gl_FragCoord.z); } diff --git a/include/Engine/Rendering/ShadowPass.cpp b/src/Engine/Rendering/ShadowPass.cpp similarity index 78% rename from include/Engine/Rendering/ShadowPass.cpp rename to src/Engine/Rendering/ShadowPass.cpp index 33549d03..56fcbe7a 100644 --- a/include/Engine/Rendering/ShadowPass.cpp +++ b/src/Engine/Rendering/ShadowPass.cpp @@ -1,4 +1,4 @@ -#include "ShadowPass.h" +#include "Rendering/ShadowPass.h" ShadowPass::ShadowPass(IRenderer * renderer) { @@ -26,15 +26,15 @@ void ShadowPass::InitializeFrameBuffers() glGenTextures(1, &m_DepthMap); glBindTexture(GL_TEXTURE_2D, m_DepthMap); //glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 1024, 1024, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr); - glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 1024, 1024, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr); - //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, 1024, 1024, 0, GL_RGB, GL_FLOAT, 0); + //glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 1024, 1024, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, 1024, 1024, 0, GL_RGB, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - m_DepthBuffer.AddResource(std::shared_ptr(new Texture2D(&m_DepthMap, GL_DEPTH_ATTACHMENT))); - //m_DepthBuffer.AddResource(std::shared_ptr(new Texture2D(&m_DepthMap, GL_COLOR_ATTACHMENT0))); + //m_DepthBuffer.AddResource(std::shared_ptr(new Texture2D(&m_DepthMap, GL_DEPTH_ATTACHMENT))); + m_DepthBuffer.AddResource(std::shared_ptr(new Texture2D(&m_DepthMap, GL_COLOR_ATTACHMENT0))); m_DepthBuffer.Generate(); GLERROR("depthMap failed"); @@ -75,16 +75,19 @@ void ShadowPass::Draw(RenderScene & scene) if(directionalLightJob) { - GLfloat near_plane = 1.0f, far_plane = 200.5f; + GLfloat near_plane = 1.0f, far_plane = 75.5f; glm::mat4 lightProjection = glm::ortho(-10.0f, 10.0f, -10.0f, 10.0f, near_plane, far_plane); // broken? - //glm::mat4 lightView = glm::lookAt(-glm::normalize(glm::vec3(directionalLightJob->Direction)), glm::vec3(0,0,0), glm::vec3(0,1,0)); - glm::mat4 lightView = glm::lookAt(glm::vec3(50.f, 50.f, 50.f), glm::vec3(0.f, 0.f, 0.f), glm::vec3(0.f, 1.f, 0.f)); + glm::mat4 lightView = glm::lookAt(-glm::normalize(glm::vec3(directionalLightJob->Direction)) * (float)50.0 , glm::vec3(0,0,0), glm::vec3(0,1,0)); + //glm::mat4 lightView = glm::lookAt(glm::vec3(10.f, 10.f, 50.f), glm::vec3(0.f, 0.f, 0.f), glm::vec3(0.f, 1.f, 0.f)); //glm::mat4 lightSpaceMatrix = lightProjection * lightView; - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix())); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix())); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(lightProjection)); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(lightView)); + + /* glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix())); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));*/ GLERROR("ShadowLight ERROR"); From 6542d1b44445458651cb9f96dbc9b1458eca29c9 Mon Sep 17 00:00:00 2001 From: Ayumiwii Date: Fri, 5 Feb 2016 17:29:53 +0100 Subject: [PATCH 006/130] Shadow WIP - DepthTexture working --- include/Engine/Rendering/ShadowPass.h | 9 +++++++++ resources/Shaders/Shadow.frag.glsl | 8 ++++---- resources/Shaders/Shadow.vert.glsl | 8 ++++---- src/Engine/Rendering/ShadowPass.cpp | 16 ++++++++-------- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/include/Engine/Rendering/ShadowPass.h b/include/Engine/Rendering/ShadowPass.h index c578339e..6a00dacd 100644 --- a/include/Engine/Rendering/ShadowPass.h +++ b/include/Engine/Rendering/ShadowPass.h @@ -7,6 +7,7 @@ #include "../Core/EventBroker.h" #include "../Core/World.h" #include "ShadowPassState.h" +#include "imgui/imgui.h" //#include "ShadowPassState.h" // not created yet @@ -45,6 +46,14 @@ private: GLuint m_DepthFBO; + GLfloat m_NearPlane = -40.f; + GLfloat m_FarPlane = 80.f; + //GLfloat m_Left = -10.f; + //GLfloat m_Right = 10.f; + //GLfloat m_Bottom = -10.f; + //GLfloat m_Top = 10.f; + GLfloat m_LRBT[4] = { -40.f, 100.f, -50.f, 50.f }; + }; #endif \ No newline at end of file diff --git a/resources/Shaders/Shadow.frag.glsl b/resources/Shaders/Shadow.frag.glsl index 983cc828..798d1cda 100644 --- a/resources/Shaders/Shadow.frag.glsl +++ b/resources/Shaders/Shadow.frag.glsl @@ -2,9 +2,9 @@ -in VertexData{ - vec3 Position; -}Input; +//in VertexData{ +// vec3 Position; +//}Input; //layout(location = 0 ) out vec4 ShadowMap; layout(location = 0 ) out float ShadowMap; @@ -12,7 +12,7 @@ layout(location = 0 ) out float ShadowMap; void main() { //ShadowMap = vec4(vec3(gl_FragCoord.z), 1.0); - ShadowMap = (gl_FragCoord.z); + //ShadowMap = (gl_FragCoord.z); } diff --git a/resources/Shaders/Shadow.vert.glsl b/resources/Shaders/Shadow.vert.glsl index cc1ee0a9..16c0b26e 100644 --- a/resources/Shaders/Shadow.vert.glsl +++ b/resources/Shaders/Shadow.vert.glsl @@ -6,12 +6,12 @@ uniform mat4 P; layout(location = 0) in vec3 Position; -out VertexData{ - vec3 Position; -}Output; +//out VertexData{ +// vec3 Position; +//}Output; void main() { - Output.Position = Position; +// Output.Position = Position; gl_Position = P * V * M * vec4(Position, 1.0); } \ No newline at end of file diff --git a/src/Engine/Rendering/ShadowPass.cpp b/src/Engine/Rendering/ShadowPass.cpp index 56fcbe7a..84c0de87 100644 --- a/src/Engine/Rendering/ShadowPass.cpp +++ b/src/Engine/Rendering/ShadowPass.cpp @@ -26,15 +26,15 @@ void ShadowPass::InitializeFrameBuffers() glGenTextures(1, &m_DepthMap); glBindTexture(GL_TEXTURE_2D, m_DepthMap); //glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 1024, 1024, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr); - //glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 1024, 1024, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, 1024, 1024, 0, GL_RGB, GL_FLOAT, 0); + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 1024, 1024, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr); + //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, 1024, 1024, 0, GL_RGB, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - //m_DepthBuffer.AddResource(std::shared_ptr(new Texture2D(&m_DepthMap, GL_DEPTH_ATTACHMENT))); - m_DepthBuffer.AddResource(std::shared_ptr(new Texture2D(&m_DepthMap, GL_COLOR_ATTACHMENT0))); + m_DepthBuffer.AddResource(std::shared_ptr(new Texture2D(&m_DepthMap, GL_DEPTH_ATTACHMENT))); + //m_DepthBuffer.AddResource(std::shared_ptr(new Texture2D(&m_DepthMap, GL_COLOR_ATTACHMENT0))); m_DepthBuffer.Generate(); GLERROR("depthMap failed"); @@ -70,16 +70,16 @@ void ShadowPass::Draw(RenderScene & scene) // glClear(GL_COLOR_BUFFER_BIT); //} + ImGui::DragFloat4("ShadowMapCam", m_LRBT, 1.f, -1000.f, 1000.f); + for (auto &job : scene.DirectionalLightJobs) { auto directionalLightJob = std::dynamic_pointer_cast(job); if(directionalLightJob) { - - GLfloat near_plane = 1.0f, far_plane = 75.5f; - glm::mat4 lightProjection = glm::ortho(-10.0f, 10.0f, -10.0f, 10.0f, near_plane, far_plane); + glm::mat4 lightProjection = glm::ortho(m_LRBT[0], m_LRBT[1], m_LRBT[2], m_LRBT[3], m_NearPlane, m_FarPlane); // broken? - glm::mat4 lightView = glm::lookAt(-glm::normalize(glm::vec3(directionalLightJob->Direction)) * (float)50.0 , glm::vec3(0,0,0), glm::vec3(0,1,0)); + glm::mat4 lightView = glm::lookAt(-glm::normalize(glm::vec3(directionalLightJob->Direction)) * (float)20.0 , glm::vec3(0,0,0), glm::vec3(0,1,0)); //glm::mat4 lightView = glm::lookAt(glm::vec3(10.f, 10.f, 50.f), glm::vec3(0.f, 0.f, 0.f), glm::vec3(0.f, 1.f, 0.f)); //glm::mat4 lightSpaceMatrix = lightProjection * lightView; From cb7f06573fbea083af3c666f4185a5cadabc14a3 Mon Sep 17 00:00:00 2001 From: Ayumiwii Date: Tue, 9 Feb 2016 14:08:57 +0100 Subject: [PATCH 007/130] Shadows stage 2 WIP --- include/Engine/Rendering/DrawFinalPass.h | 4 +- include/Engine/Rendering/ShadowPass.h | 19 ++++--- resources/Shaders/ExplosionEffect.geom.glsl | 4 ++ resources/Shaders/ForwardPlus.frag.glsl | 63 ++++++++++++++++++++- resources/Shaders/ForwardPlus.vert.glsl | 22 ++++++- src/Engine/Rendering/DrawFinalPass.cpp | 20 ++++++- src/Engine/Rendering/FrameBuffer.cpp | 1 - src/Engine/Rendering/Renderer.cpp | 5 +- src/Engine/Rendering/ShadowPass.cpp | 19 +++---- 9 files changed, 128 insertions(+), 29 deletions(-) diff --git a/include/Engine/Rendering/DrawFinalPass.h b/include/Engine/Rendering/DrawFinalPass.h index 74f505fe..ba65d6e7 100644 --- a/include/Engine/Rendering/DrawFinalPass.h +++ b/include/Engine/Rendering/DrawFinalPass.h @@ -8,11 +8,12 @@ #include "ShaderProgram.h" #include "Util/UnorderedMapVec2.h" #include "Texture.h" +#include "ShadowPass.h" class DrawFinalPass { public: - DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass); + DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass, ShadowPass* shadowPass); ~DrawFinalPass() { } void InitializeTextures(); void InitializeFrameBuffers(); @@ -50,6 +51,7 @@ private: const IRenderer* m_Renderer; const LightCullingPass* m_LightCullingPass; + const ShadowPass* m_ShadowPass; ShaderProgram* m_ForwardPlusProgram; ShaderProgram* m_ExplosionEffectProgram; diff --git a/include/Engine/Rendering/ShadowPass.h b/include/Engine/Rendering/ShadowPass.h index 6a00dacd..a8f41502 100644 --- a/include/Engine/Rendering/ShadowPass.h +++ b/include/Engine/Rendering/ShadowPass.h @@ -11,7 +11,8 @@ //#include "ShadowPassState.h" // not created yet - +enum NearFar { Near = 0, Far = 1 }; +enum LRBT { Left = 0, Right = 1, Bottom = 2, Top = 3 }; class ShadowPass { @@ -28,7 +29,11 @@ public: GLuint DepthMap() const { return m_DepthMap; } - + glm::mat4 lightSpaceMatrix() const { return m_LightSpaceMatrix; } + glm::mat4 lightP() const { return m_LightProjection; } + glm::mat4 lightV() const { return m_LightView; } + //glm::mat4 lightV() const { return m_LightProjection; } //swapped m_P -> m_V + //glm::mat4 lightP() const { return m_LightView; } // swapped m_V -> m_P private: @@ -46,14 +51,12 @@ private: GLuint m_DepthFBO; - GLfloat m_NearPlane = -40.f; - GLfloat m_FarPlane = 80.f; - //GLfloat m_Left = -10.f; - //GLfloat m_Right = 10.f; - //GLfloat m_Bottom = -10.f; - //GLfloat m_Top = 10.f; + GLfloat m_NearFarPlane[2] = { -40.f, 30.f }; GLfloat m_LRBT[4] = { -40.f, 100.f, -50.f, 50.f }; + glm::mat4 m_LightProjection; + glm::mat4 m_LightView; + glm::mat4 m_LightSpaceMatrix; }; #endif \ No newline at end of file diff --git a/resources/Shaders/ExplosionEffect.geom.glsl b/resources/Shaders/ExplosionEffect.geom.glsl index 44b44aa6..3471e4f2 100644 --- a/resources/Shaders/ExplosionEffect.geom.glsl +++ b/resources/Shaders/ExplosionEffect.geom.glsl @@ -22,6 +22,7 @@ in VertexData{ vec2 TextureCoordinate; vec4 ExplosionColor; float ExplosionPercentageElapsed; + vec4 PositionLightSpace; }Input[]; out VertexData{ @@ -32,6 +33,7 @@ out VertexData{ vec2 TextureCoordinate; vec4 ExplosionColor; float ExplosionPercentageElapsed; + vec4 PositionLightSpace; }Output; layout(triangles) in; @@ -145,6 +147,7 @@ void main() Output.TextureCoordinate = Input[i].TextureCoordinate; Output.Tangent = Input[i].Tangent; Output.BiTangent = Input[i].BiTangent; + Output.PositionLightSpace = Input[i].PositionLightSpace; // convert to model space for the gravity to always be in -y vec4 ExplodedPositionInModelSpace = M * vec4(ExplodedPosition, 1.0); @@ -186,6 +189,7 @@ void main() Output.TextureCoordinate = Input[i].TextureCoordinate; Output.Tangent = Input[i].Tangent; Output.BiTangent = Input[i].BiTangent; + Output.PositionLightSpace = Input[i].PositionLightSpace; // no change in position, pass through vertex gl_Position = gl_in[i].gl_Position; diff --git a/resources/Shaders/ForwardPlus.frag.glsl b/resources/Shaders/ForwardPlus.frag.glsl index c09e0438..d54de713 100644 --- a/resources/Shaders/ForwardPlus.frag.glsl +++ b/resources/Shaders/ForwardPlus.frag.glsl @@ -13,6 +13,7 @@ layout (binding = 0) uniform sampler2D DiffuseTexture; layout (binding = 1) uniform sampler2D NormalMapTexture; layout (binding = 2) uniform sampler2D SpecularMapTexture; layout (binding = 3) uniform sampler2D GlowMapTexture; +layout (binding = 4) uniform sampler2D DepthMap; #define TILE_SIZE 16 @@ -56,6 +57,7 @@ in VertexData{ vec2 TextureCoordinate; vec4 ExplosionColor; float ExplosionPercentageElapsed; + vec4 PositionLightSpace; }Input; out vec4 sceneColor; @@ -112,6 +114,45 @@ vec4 CalcNormalMappedValue(vec3 normal, vec3 tangent, vec3 bitangent, vec2 textu return vec4(TBN * normalize(NormalMap), 0.0); } +//float CalcShadowValue(vec4 positionLightSpace, vec4 normal, vec4 lightDir, sampler2D depthTexture) +//{ +// // perform perspective divide +// //vec3 projCoords = positionLightSpace.xyz / positionLightSpace.w; +// // Transform to [0,1] range +// //projCoords = projCoords * 0.5 + 0.5; +// // Get closest depth value from light's perspective (using [0,1] range fragPosLight as coords) +// float closestDepth = texture(depthTexture, positionLightSpace.xy).r; +// // Get depth of current fragment from light's perspective +// float currentDepth = positionLightSpace.z; +// // Check whether current frag pos is in shadow +// float shadow = currentDepth > closestDepth ? 1.0 : 0.0; +// +// return shadow; +// +//} + +float CalcShadowValue(vec4 positionLightSpace, vec4 normal, vec4 lightDir, sampler2D depthTexture) +{ + + //float bias = max(0.05 * (1.0 - dot(normal, -lightDir)), 0.005); + // perform perspective divide + vec3 projCoords = positionLightSpace.xyz / positionLightSpace.w; + // Transform to [0,1] range + projCoords = projCoords * 0.5 + 0.5; + // Get closest depth value from light's perspective (using [0,1] range fragPosLight as coords) + //float lightDepth = texture(depthTexture, positionLightSpace.xy).r; + float closestDepth = texture(depthTexture, projCoords.xy).r; + // Get depth of current fragment from light's perspective + //float currentDepth = positionLightSpace.z; + float currentDepth = projCoords.z; + // Check whether current frag pos is in shadow + float shadow = currentDepth /*- bias*/ > closestDepth ? 1.0 : 0.0; + // float shadow = currentDepth > closestDepth ? 1.0 : 0.0; + + return shadow; + +} + void main() { vec4 diffuseTexel = texture2D(DiffuseTexture, Input.TextureCoordinate); @@ -134,24 +175,42 @@ void main() int start = int(LightGrids.Data[currentTile].Start); int amount = int(LightGrids.Data[currentTile].Amount); + float shadowFactor = 1.0; + for(int i = start; i < start + amount; i++) { int l = int(LightIndex[i]); LightSource light = LightSources.List[l]; - + LightResult light_result; //These if statements should be removed. if(light.Type == 1) { // point light_result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, position, normal, light.Falloff); } else if (light.Type == 2) { //Directional light_result = CalcDirectionalLightSource(V * light.Direction, light.Color, light.Intensity, viewVec, normal); + shadowFactor = CalcShadowValue(Input.PositionLightSpace, normal, light.Direction, DepthMap); } + totalLighting.Diffuse += light_result.Diffuse; - totalLighting.Specular += light_result.Specular; + totalLighting.Specular += light_result.Specular; } + totalLighting.Diffuse += (1.0 - shadowFactor); + totalLighting.Specular += (1.0 - shadowFactor); + //LightResult getInformation; + vec4 color_result = mix((Color * diffuseTexel * DiffuseColor), Input.ExplosionColor, Input.ExplosionPercentageElapsed); color_result = color_result * (totalLighting.Diffuse + (totalLighting.Specular * specularTexel)); + + //color_result = (totalLighting.Diffuse + (1.0 - shadowFactor) * (getInformation.Diffuse + (getInformation.Specular * specularTexel))) * color_result; + + + + + + + + //vec4 color_result = (DiffuseColor + Input.ExplosionColor) * (totalLighting.Diffuse + (totalLighting.Specular * specularTexel)) * diffuseTexel * Color; diff --git a/resources/Shaders/ForwardPlus.vert.glsl b/resources/Shaders/ForwardPlus.vert.glsl index 3b3e931c..21f3f370 100644 --- a/resources/Shaders/ForwardPlus.vert.glsl +++ b/resources/Shaders/ForwardPlus.vert.glsl @@ -3,6 +3,9 @@ uniform mat4 M; uniform mat4 V; uniform mat4 P; +uniform mat4 lightSpaceMatrix; // Shadow map PV +uniform mat4 LightV; +uniform mat4 LightP; uniform mat4 Bones[100]; layout(location = 0) in vec3 Position; @@ -21,8 +24,17 @@ out VertexData{ vec2 TextureCoordinate; vec4 ExplosionColor; float ExplosionPercentageElapsed; + vec4 PositionLightSpace; }Output; +// N +mat4 biasMatrix = mat4( +vec4(0.5, 0.0, 0.0, 0.0), +vec4(0.0, 0.5, 0.0, 0.0), +vec4(0.0, 0.0, 0.5, 0.0), +vec4(0.5, 0.5, 0.5, 1.0) +); + void main() { @@ -34,9 +46,12 @@ void main() + BoneWeights[2] * Bones[int(BoneIndices[2])] + BoneWeights[3] * Bones[int(BoneIndices[3])]; } - - gl_Position = P*V*M*boneTransform * vec4(Position, 1.0); + //vec4 lightPos = biasMatrix * LightP * LightV * M * vec4(Position, 1.0); // N + + gl_Position = P*V*M*boneTransform * vec4(Position, 1.0); + //gl_Position = lightPos; // N + Output.Position = (boneTransform * vec4(Position, 1.0)).xyz; Output.TextureCoordinate = TextureCoords; Output.Normal = vec3(M * vec4(Normal, 0.0)); @@ -44,4 +59,7 @@ void main() Output.BiTangent = vec3(M * vec4(BiTangent, 0.0)); Output.ExplosionColor = vec4(1.0); Output.ExplosionPercentageElapsed = 0.0; + + //Output.PositionLightSpace = lightPos; // N + Output.PositionLightSpace = lightSpaceMatrix * (M * vec4(Position, 1.0)); } \ No newline at end of file diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index 8247797e..3e74cd1a 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -1,9 +1,10 @@ #include "Rendering/DrawFinalPass.h" -DrawFinalPass::DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass) +DrawFinalPass::DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass, ShadowPass* shadowPass) { m_Renderer = renderer; m_LightCullingPass = lightCullingPass; + m_ShadowPass = shadowPass; InitializeTextures(); InitializeShaderPrograms(); InitializeFrameBuffers(); @@ -242,6 +243,16 @@ void DrawFinalPass::BindModelUniforms(GLuint shaderHandle, std::shared_ptrFillPercentage); glUniform4fv(glGetUniformLocation(shaderHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor)); + //Shadow + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "lightSpaceMatrix"), 1, GL_FALSE, glm::value_ptr(m_ShadowPass->lightSpaceMatrix())); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "LightP"), 1, GL_FALSE, glm::value_ptr(m_ShadowPass->lightP())); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "LightV"), 1, GL_FALSE, glm::value_ptr(m_ShadowPass->lightV())); + //GLfloat m_NearFarPlane[2] = { -40.f, 30.f }; + //GLfloat m_LRBT[4] = { -40.f, 100.f, -50.f, 50.f }; + //glm::mat4 m_LightProjection = glm::ortho(m_LRBT[Left], m_LRBT[Right], m_LRBT[Bottom], m_LRBT[Top], m_NearFarPlane[Near], m_NearFarPlane[Far]); + //glm::mat4 m_LightView = glm::lookAt(glm::vec3(-20.0f, 20.0f, -20.0f), glm::vec3(0.0f), glm::vec3(1.0)); + //glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "LightP"), 1, GL_FALSE, glm::value_ptr(m_LightProjection)); + //glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "LightV"), 1, GL_FALSE, glm::value_ptr(m_LightView)); GLERROR("END"); } @@ -306,5 +317,12 @@ void DrawFinalPass::BindModelTextures(std::shared_ptr& job) } else { glBindTexture(GL_TEXTURE_2D, m_BlackTexture->m_Texture); } + + glActiveTexture(GL_TEXTURE4); + if (m_ShadowPass->DepthMap() != NULL) { + glBindTexture(GL_TEXTURE_2D, m_ShadowPass->DepthMap()); + } else { + glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture); + } } diff --git a/src/Engine/Rendering/FrameBuffer.cpp b/src/Engine/Rendering/FrameBuffer.cpp index 4f83122e..44ffb20e 100644 --- a/src/Engine/Rendering/FrameBuffer.cpp +++ b/src/Engine/Rendering/FrameBuffer.cpp @@ -49,7 +49,6 @@ void FrameBuffer::Generate() case GL_TEXTURE_2D: glFramebufferTexture2D(GL_FRAMEBUFFER, (*it)->m_Attachment, (*it)->m_ResourceType, *(*it)->m_ResourceHandle, 0); GLERROR("FrameBuffer generate: glFramebufferTexture2D"); - break; case GL_RENDERBUFFER: glFramebufferRenderbuffer(GL_FRAMEBUFFER, (*it)->m_Attachment, (*it)->m_ResourceType, *(*it)->m_ResourceHandle); diff --git a/src/Engine/Rendering/Renderer.cpp b/src/Engine/Rendering/Renderer.cpp index 147fed65..f8e1cd6b 100644 --- a/src/Engine/Rendering/Renderer.cpp +++ b/src/Engine/Rendering/Renderer.cpp @@ -138,7 +138,6 @@ void Renderer::Draw(RenderFrame& frame) } if (m_DebugTextureToDraw == 5) { m_DrawScreenQuadPass->Draw(m_ShadowPass->DepthMap()); - // m_DrawScreenQuadPass->Draw(); } m_ImGuiRenderPass->Draw(); @@ -179,9 +178,9 @@ void Renderer::InitializeRenderPasses() { m_PickingPass = new PickingPass(this, m_EventBroker); m_LightCullingPass = new LightCullingPass(this); - m_DrawFinalPass = new DrawFinalPass(this, m_LightCullingPass); + m_ShadowPass = new ShadowPass(this); + m_DrawFinalPass = new DrawFinalPass(this, m_LightCullingPass, m_ShadowPass); m_DrawScreenQuadPass = new DrawScreenQuadPass(this); m_DrawBloomPass = new DrawBloomPass(this); m_DrawColorCorrectionPass = new DrawColorCorrectionPass(this); - m_ShadowPass = new ShadowPass(this); } diff --git a/src/Engine/Rendering/ShadowPass.cpp b/src/Engine/Rendering/ShadowPass.cpp index 84c0de87..9855917c 100644 --- a/src/Engine/Rendering/ShadowPass.cpp +++ b/src/Engine/Rendering/ShadowPass.cpp @@ -71,23 +71,20 @@ void ShadowPass::Draw(RenderScene & scene) //} ImGui::DragFloat4("ShadowMapCam", m_LRBT, 1.f, -1000.f, 1000.f); + ImGui::DragFloat2("ShadowMapNearFar", m_NearFarPlane, 1.f, -1000.f, 1000.f); for (auto &job : scene.DirectionalLightJobs) { auto directionalLightJob = std::dynamic_pointer_cast(job); if(directionalLightJob) { - glm::mat4 lightProjection = glm::ortho(m_LRBT[0], m_LRBT[1], m_LRBT[2], m_LRBT[3], m_NearPlane, m_FarPlane); + //m_LightProjection = glm::ortho(m_LRBT[Left], m_LRBT[Right], m_LRBT[Bottom], m_LRBT[Top], m_NearFarPlane[Near], m_NearFarPlane[Far]); + m_LightProjection = glm::ortho(m_LRBT[Left], m_LRBT[Right], m_LRBT[Bottom], m_LRBT[Top], m_NearFarPlane[Near], m_NearFarPlane[Far]); + m_LightView = glm::lookAt(-glm::normalize(glm::vec3(directionalLightJob->Direction)), glm::vec3(0.f,0.f,0.f), glm::vec3(0.f,1.f,0.f)); + //m_LightView = glm::lookAt(glm::vec3(-20.0f, 20.0f, -20.0f), glm::vec3(0.0f), glm::vec3(1.0)); + m_LightSpaceMatrix = m_LightProjection * m_LightView; - // broken? - glm::mat4 lightView = glm::lookAt(-glm::normalize(glm::vec3(directionalLightJob->Direction)) * (float)20.0 , glm::vec3(0,0,0), glm::vec3(0,1,0)); - //glm::mat4 lightView = glm::lookAt(glm::vec3(10.f, 10.f, 50.f), glm::vec3(0.f, 0.f, 0.f), glm::vec3(0.f, 1.f, 0.f)); - //glm::mat4 lightSpaceMatrix = lightProjection * lightView; - - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(lightProjection)); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(lightView)); - - /* glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix())); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));*/ + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_LightProjection)); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_LightView)); GLERROR("ShadowLight ERROR"); From 847c539373ba58548bf010a96e60ac66a56b44dc Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Tue, 9 Feb 2016 14:44:12 +0100 Subject: [PATCH 008/130] Fix viewport --- resources/Shaders/ForwardPlus.frag.glsl | 21 ++------------------- resources/Shaders/ForwardPlus.vert.glsl | 4 ++-- src/Engine/Rendering/ShadowPass.cpp | 5 ++--- 3 files changed, 6 insertions(+), 24 deletions(-) diff --git a/resources/Shaders/ForwardPlus.frag.glsl b/resources/Shaders/ForwardPlus.frag.glsl index d54de713..56809878 100644 --- a/resources/Shaders/ForwardPlus.frag.glsl +++ b/resources/Shaders/ForwardPlus.frag.glsl @@ -114,27 +114,10 @@ vec4 CalcNormalMappedValue(vec3 normal, vec3 tangent, vec3 bitangent, vec2 textu return vec4(TBN * normalize(NormalMap), 0.0); } -//float CalcShadowValue(vec4 positionLightSpace, vec4 normal, vec4 lightDir, sampler2D depthTexture) -//{ -// // perform perspective divide -// //vec3 projCoords = positionLightSpace.xyz / positionLightSpace.w; -// // Transform to [0,1] range -// //projCoords = projCoords * 0.5 + 0.5; -// // Get closest depth value from light's perspective (using [0,1] range fragPosLight as coords) -// float closestDepth = texture(depthTexture, positionLightSpace.xy).r; -// // Get depth of current fragment from light's perspective -// float currentDepth = positionLightSpace.z; -// // Check whether current frag pos is in shadow -// float shadow = currentDepth > closestDepth ? 1.0 : 0.0; -// -// return shadow; -// -//} - float CalcShadowValue(vec4 positionLightSpace, vec4 normal, vec4 lightDir, sampler2D depthTexture) { - //float bias = max(0.05 * (1.0 - dot(normal, -lightDir)), 0.005); + float bias = max(0.05 * (1.0 - dot(normal, -lightDir)), 0.005); // perform perspective divide vec3 projCoords = positionLightSpace.xyz / positionLightSpace.w; // Transform to [0,1] range @@ -188,7 +171,7 @@ void main() light_result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, position, normal, light.Falloff); } else if (light.Type == 2) { //Directional light_result = CalcDirectionalLightSource(V * light.Direction, light.Color, light.Intensity, viewVec, normal); - shadowFactor = CalcShadowValue(Input.PositionLightSpace, normal, light.Direction, DepthMap); + shadowFactor = CalcShadowValue(Input.PositionLightSpace, vec4(Input.Normal, 0.0), light.Direction, DepthMap); } totalLighting.Diffuse += light_result.Diffuse; diff --git a/resources/Shaders/ForwardPlus.vert.glsl b/resources/Shaders/ForwardPlus.vert.glsl index 21f3f370..bde356e9 100644 --- a/resources/Shaders/ForwardPlus.vert.glsl +++ b/resources/Shaders/ForwardPlus.vert.glsl @@ -47,7 +47,7 @@ void main() + BoneWeights[3] * Bones[int(BoneIndices[3])]; } - //vec4 lightPos = biasMatrix * LightP * LightV * M * vec4(Position, 1.0); // N + //vec4 lightPos = LightP * LightV * M * vec4(Position, 1.0); // N gl_Position = P*V*M*boneTransform * vec4(Position, 1.0); //gl_Position = lightPos; // N @@ -61,5 +61,5 @@ void main() Output.ExplosionPercentageElapsed = 0.0; //Output.PositionLightSpace = lightPos; // N - Output.PositionLightSpace = lightSpaceMatrix * (M * vec4(Position, 1.0)); + Output.PositionLightSpace = lightSpaceMatrix * M * vec4(Position, 1.0); } \ No newline at end of file diff --git a/src/Engine/Rendering/ShadowPass.cpp b/src/Engine/Rendering/ShadowPass.cpp index 9855917c..3ae83773 100644 --- a/src/Engine/Rendering/ShadowPass.cpp +++ b/src/Engine/Rendering/ShadowPass.cpp @@ -25,9 +25,8 @@ void ShadowPass::InitializeFrameBuffers() // Depth texture glGenTextures(1, &m_DepthMap); glBindTexture(GL_TEXTURE_2D, m_DepthMap); - //glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 1024, 1024, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr); - glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 1024, 1024, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr); - //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, 1024, 1024, 0, GL_RGB, GL_FLOAT, 0); + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr); + //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height, 0, GL_RGB, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); From ecd823cb9f59843a2d67be0711a18f3daef4d166 Mon Sep 17 00:00:00 2001 From: Ayumiwii Date: Tue, 9 Feb 2016 16:15:11 +0100 Subject: [PATCH 009/130] Shadow WIP stage 2 - Soft shadow --- include/Engine/Rendering/ShadowPass.h | 8 ++++++-- resources/Shaders/ForwardPlus.frag.glsl | 22 +++++++++++++++++++++- src/Engine/Rendering/ShadowPass.cpp | 13 +++++++------ 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/include/Engine/Rendering/ShadowPass.h b/include/Engine/Rendering/ShadowPass.h index a8f41502..301af9a5 100644 --- a/include/Engine/Rendering/ShadowPass.h +++ b/include/Engine/Rendering/ShadowPass.h @@ -32,8 +32,8 @@ public: glm::mat4 lightSpaceMatrix() const { return m_LightSpaceMatrix; } glm::mat4 lightP() const { return m_LightProjection; } glm::mat4 lightV() const { return m_LightView; } - //glm::mat4 lightV() const { return m_LightProjection; } //swapped m_P -> m_V - //glm::mat4 lightP() const { return m_LightView; } // swapped m_V -> m_P + + void setResolution(GLuint width, GLuint height) { resolutionSizeWidth = width; resolutionSizeHeigth = height; } private: @@ -57,6 +57,10 @@ private: glm::mat4 m_LightProjection; glm::mat4 m_LightView; glm::mat4 m_LightSpaceMatrix; + + GLuint resolutionSizeWidth = 2048; + GLuint resolutionSizeHeigth = 2048; + }; #endif \ No newline at end of file diff --git a/resources/Shaders/ForwardPlus.frag.glsl b/resources/Shaders/ForwardPlus.frag.glsl index 56809878..cf3b3ed0 100644 --- a/resources/Shaders/ForwardPlus.frag.glsl +++ b/resources/Shaders/ForwardPlus.frag.glsl @@ -114,6 +114,13 @@ vec4 CalcNormalMappedValue(vec3 normal, vec3 tangent, vec3 bitangent, vec2 textu return vec4(TBN * normalize(NormalMap), 0.0); } +vec2 poissonDisk[4] = vec2[]( + vec2( -0.94201624, -0.39906216 ), + vec2( 0.94558609, -0.76890725 ), + vec2( -0.094184101, -0.92938870 ), + vec2( 0.34495938, 0.29387760 ) + ); + float CalcShadowValue(vec4 positionLightSpace, vec4 normal, vec4 lightDir, sampler2D depthTexture) { @@ -129,8 +136,21 @@ float CalcShadowValue(vec4 positionLightSpace, vec4 normal, vec4 lightDir, sampl //float currentDepth = positionLightSpace.z; float currentDepth = projCoords.z; // Check whether current frag pos is in shadow - float shadow = currentDepth /*- bias*/ > closestDepth ? 1.0 : 0.0; + //float shadow = currentDepth - bias > closestDepth ? 1.0 : 0.0; // float shadow = currentDepth > closestDepth ? 1.0 : 0.0; + + float shadow = 0.0; + //soft shadow - using percentage-closer filtering (PCF) is to simply sample the surrounding texels of the depth map and average the results: + vec2 texelSize = 1.0 / textureSize(depthTexture, 0); + for(int x = -1; x <= 1; ++x) + { + for(int y = -1; y <= 1; ++y) + { + float pcfDepth = texture(depthTexture, projCoords.xy + vec2(x, y) * texelSize).r; + shadow += currentDepth - bias > pcfDepth ? 1.0 : 0.0; + } + } + shadow /= 9.0; return shadow; diff --git a/src/Engine/Rendering/ShadowPass.cpp b/src/Engine/Rendering/ShadowPass.cpp index 3ae83773..c6bb4313 100644 --- a/src/Engine/Rendering/ShadowPass.cpp +++ b/src/Engine/Rendering/ShadowPass.cpp @@ -25,7 +25,7 @@ void ShadowPass::InitializeFrameBuffers() // Depth texture glGenTextures(1, &m_DepthMap); glBindTexture(GL_TEXTURE_2D, m_DepthMap); - glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr); + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, resolutionSizeWidth, resolutionSizeHeigth, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr); //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height, 0, GL_RGB, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); @@ -65,9 +65,9 @@ void ShadowPass::Draw(RenderScene & scene) GLuint shaderHandle = m_ShadowProgram->GetHandle(); m_ShadowProgram->Bind(); - //if (scene.ClearDepth) { - // glClear(GL_COLOR_BUFFER_BIT); - //} + glViewport(0, 0, resolutionSizeWidth, resolutionSizeHeigth); + glCullFace(GL_FRONT); + ImGui::DragFloat4("ShadowMapCam", m_LRBT, 1.f, -1000.f, 1000.f); ImGui::DragFloat2("ShadowMapNearFar", m_NearFarPlane, 1.f, -1000.f, 1000.f); @@ -111,8 +111,9 @@ void ShadowPass::Draw(RenderScene & scene) - - //m_ShadowProgram->Unbind(); + glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height); + glCullFace(GL_BACK); + m_ShadowProgram->Unbind(); From 6af167675d102f02a40df9291371b51768707d86 Mon Sep 17 00:00:00 2001 From: Ayumiwii Date: Wed, 10 Feb 2016 11:48:44 +0100 Subject: [PATCH 010/130] Shadow WIP stage 2 - fix cel-shading --- include/Engine/Rendering/ShadowPass.h | 9 ++-- resources/Shaders/ForwardPlus.frag.glsl | 32 +++++++------ src/Engine/Rendering/ShadowPass.cpp | 61 +++++++++++++------------ 3 files changed, 57 insertions(+), 45 deletions(-) diff --git a/include/Engine/Rendering/ShadowPass.h b/include/Engine/Rendering/ShadowPass.h index 301af9a5..e26045db 100644 --- a/include/Engine/Rendering/ShadowPass.h +++ b/include/Engine/Rendering/ShadowPass.h @@ -51,16 +51,17 @@ private: GLuint m_DepthFBO; - GLfloat m_NearFarPlane[2] = { -40.f, 30.f }; - GLfloat m_LRBT[4] = { -40.f, 100.f, -50.f, 50.f }; + GLfloat m_NearFarPlane[2] = { -84.f, 28.f }; + GLfloat m_LRBT[4] = { -77.f, 75.f, -89.f, 89.f }; glm::mat4 m_LightProjection; glm::mat4 m_LightView; glm::mat4 m_LightSpaceMatrix; - GLuint resolutionSizeWidth = 2048; - GLuint resolutionSizeHeigth = 2048; + GLuint resolutionSizeWidth = 2048 * 4; + GLuint resolutionSizeHeigth = 2048 * 4; + bool m_ShadowOn = true; }; #endif \ No newline at end of file diff --git a/resources/Shaders/ForwardPlus.frag.glsl b/resources/Shaders/ForwardPlus.frag.glsl index cf3b3ed0..a82555c8 100644 --- a/resources/Shaders/ForwardPlus.frag.glsl +++ b/resources/Shaders/ForwardPlus.frag.glsl @@ -124,7 +124,8 @@ vec2 poissonDisk[4] = vec2[]( float CalcShadowValue(vec4 positionLightSpace, vec4 normal, vec4 lightDir, sampler2D depthTexture) { - float bias = max(0.05 * (1.0 - dot(normal, -lightDir)), 0.005); + float bias = 0.005; + //float bias = max(0.05 * (1.0 - dot(normal, -lightDir)), 0.005); // perform perspective divide vec3 projCoords = positionLightSpace.xyz / positionLightSpace.w; // Transform to [0,1] range @@ -136,21 +137,26 @@ float CalcShadowValue(vec4 positionLightSpace, vec4 normal, vec4 lightDir, sampl //float currentDepth = positionLightSpace.z; float currentDepth = projCoords.z; // Check whether current frag pos is in shadow - //float shadow = currentDepth - bias > closestDepth ? 1.0 : 0.0; - // float shadow = currentDepth > closestDepth ? 1.0 : 0.0; + float shadow = currentDepth - bias > closestDepth ? 1.0 : 0.0; + //float shadow = currentDepth > closestDepth ? 1.0 : 0.0; - float shadow = 0.0; - //soft shadow - using percentage-closer filtering (PCF) is to simply sample the surrounding texels of the depth map and average the results: - vec2 texelSize = 1.0 / textureSize(depthTexture, 0); - for(int x = -1; x <= 1; ++x) + //float shadow = 0.0; + ////soft shadow - using percentage-closer filtering (PCF) is to simply sample the surrounding texels of the depth map and average the results: + //vec2 texelSize = 1.0 / textureSize(depthTexture, 0); + //for(int x = -1; x <= 1; ++x) + //{ + // for(int y = -1; y <= 1; ++y) + // { + // float pcfDepth = texture(depthTexture, projCoords.xy + vec2(x, y) * texelSize).r; + // shadow += currentDepth - bias > pcfDepth ? 1.0 : 0.0; + // } + //} + //shadow /= 9.0; + // + if(projCoords.z > 0.9) { - for(int y = -1; y <= 1; ++y) - { - float pcfDepth = texture(depthTexture, projCoords.xy + vec2(x, y) * texelSize).r; - shadow += currentDepth - bias > pcfDepth ? 1.0 : 0.0; - } + shadow = 1.0; } - shadow /= 9.0; return shadow; diff --git a/src/Engine/Rendering/ShadowPass.cpp b/src/Engine/Rendering/ShadowPass.cpp index c6bb4313..61e37da3 100644 --- a/src/Engine/Rendering/ShadowPass.cpp +++ b/src/Engine/Rendering/ShadowPass.cpp @@ -25,13 +25,14 @@ void ShadowPass::InitializeFrameBuffers() // Depth texture glGenTextures(1, &m_DepthMap); glBindTexture(GL_TEXTURE_2D, m_DepthMap); - glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, resolutionSizeWidth, resolutionSizeHeigth, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr); + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, resolutionSizeWidth, resolutionSizeHeigth, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr); //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height, 0, GL_RGB, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + m_DepthBuffer.AddResource(std::shared_ptr(new Texture2D(&m_DepthMap, GL_DEPTH_ATTACHMENT))); //m_DepthBuffer.AddResource(std::shared_ptr(new Texture2D(&m_DepthMap, GL_COLOR_ATTACHMENT0))); m_DepthBuffer.Generate(); @@ -66,47 +67,51 @@ void ShadowPass::Draw(RenderScene & scene) m_ShadowProgram->Bind(); glViewport(0, 0, resolutionSizeWidth, resolutionSizeHeigth); - glCullFace(GL_FRONT); - + glCullFace(GL_BACK); + //state->Disable(GL_CULL_FACE); ImGui::DragFloat4("ShadowMapCam", m_LRBT, 1.f, -1000.f, 1000.f); ImGui::DragFloat2("ShadowMapNearFar", m_NearFarPlane, 1.f, -1000.f, 1000.f); + ImGui::Checkbox("EnableShadow", &m_ShadowOn); - for (auto &job : scene.DirectionalLightJobs) { - auto directionalLightJob = std::dynamic_pointer_cast(job); + if (m_ShadowOn == true) + { + for (auto &job : scene.DirectionalLightJobs) { + auto directionalLightJob = std::dynamic_pointer_cast(job); - if(directionalLightJob) { - //m_LightProjection = glm::ortho(m_LRBT[Left], m_LRBT[Right], m_LRBT[Bottom], m_LRBT[Top], m_NearFarPlane[Near], m_NearFarPlane[Far]); - m_LightProjection = glm::ortho(m_LRBT[Left], m_LRBT[Right], m_LRBT[Bottom], m_LRBT[Top], m_NearFarPlane[Near], m_NearFarPlane[Far]); - m_LightView = glm::lookAt(-glm::normalize(glm::vec3(directionalLightJob->Direction)), glm::vec3(0.f,0.f,0.f), glm::vec3(0.f,1.f,0.f)); - //m_LightView = glm::lookAt(glm::vec3(-20.0f, 20.0f, -20.0f), glm::vec3(0.0f), glm::vec3(1.0)); - m_LightSpaceMatrix = m_LightProjection * m_LightView; + if(directionalLightJob) { + //m_LightProjection = glm::ortho(m_LRBT[Left], m_LRBT[Right], m_LRBT[Bottom], m_LRBT[Top], m_NearFarPlane[Near], m_NearFarPlane[Far]); + m_LightProjection = glm::ortho(m_LRBT[Left], m_LRBT[Right], m_LRBT[Bottom], m_LRBT[Top], m_NearFarPlane[Near], m_NearFarPlane[Far]); + m_LightView = glm::lookAt(-glm::normalize(glm::vec3(directionalLightJob->Direction)), glm::vec3(0.f,0.f,0.f), glm::vec3(0.f,1.f,0.f)); + //m_LightView = glm::lookAt(glm::vec3(-20.0f, 20.0f, -20.0f), glm::vec3(0.0f), glm::vec3(1.0)); + m_LightSpaceMatrix = m_LightProjection * m_LightView; - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_LightProjection)); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_LightView)); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_LightProjection)); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_LightView)); - GLERROR("ShadowLight ERROR"); + GLERROR("ShadowLight ERROR"); - for (auto &objectJob : scene.OpaqueObjects) { - auto modelJob = std::dynamic_pointer_cast(objectJob); + for (auto &objectJob : scene.OpaqueObjects) { + auto modelJob = std::dynamic_pointer_cast(objectJob); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); - glBindVertexArray(modelJob->Model->VAO); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); - glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int))); + glBindVertexArray(modelJob->Model->VAO); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); + glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int))); - GLERROR("Shadow Draw ERROR"); + GLERROR("Shadow Draw ERROR"); - } + } + } + + m_DepthBuffer.Unbind(); + + delete state; + + } - - m_DepthBuffer.Unbind(); - - delete state; - - } From 69db32337ddb04557e8e60187782076249a5d253 Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Wed, 10 Feb 2016 15:16:58 +0100 Subject: [PATCH 011/130] Shado wip --- include/Engine/Rendering/ShadowPass.h | 2 +- resources/Schema/Entities/GameMap.xml | 7 +++ resources/Shaders/ForwardPlus.frag.glsl | 63 +++++++++++-------------- src/Engine/Rendering/ShadowPass.cpp | 14 ++++-- 4 files changed, 44 insertions(+), 42 deletions(-) diff --git a/include/Engine/Rendering/ShadowPass.h b/include/Engine/Rendering/ShadowPass.h index e26045db..5acc376e 100644 --- a/include/Engine/Rendering/ShadowPass.h +++ b/include/Engine/Rendering/ShadowPass.h @@ -51,7 +51,7 @@ private: GLuint m_DepthFBO; - GLfloat m_NearFarPlane[2] = { -84.f, 28.f }; + GLfloat m_NearFarPlane[2] = { -34.f, 27.f }; GLfloat m_LRBT[4] = { -77.f, 75.f, -89.f, 89.f }; glm::mat4 m_LightProjection; diff --git a/resources/Schema/Entities/GameMap.xml b/resources/Schema/Entities/GameMap.xml index 97fd3f4d..7b62b5d8 100644 --- a/resources/Schema/Entities/GameMap.xml +++ b/resources/Schema/Entities/GameMap.xml @@ -238,6 +238,13 @@ + + + + + + + diff --git a/resources/Shaders/ForwardPlus.frag.glsl b/resources/Shaders/ForwardPlus.frag.glsl index a82555c8..170a9d5a 100644 --- a/resources/Shaders/ForwardPlus.frag.glsl +++ b/resources/Shaders/ForwardPlus.frag.glsl @@ -13,7 +13,7 @@ layout (binding = 0) uniform sampler2D DiffuseTexture; layout (binding = 1) uniform sampler2D NormalMapTexture; layout (binding = 2) uniform sampler2D SpecularMapTexture; layout (binding = 3) uniform sampler2D GlowMapTexture; -layout (binding = 4) uniform sampler2D DepthMap; +layout (binding = 4) uniform sampler2DShadow DepthMap; #define TILE_SIZE 16 @@ -114,49 +114,39 @@ vec4 CalcNormalMappedValue(vec3 normal, vec3 tangent, vec3 bitangent, vec2 textu return vec4(TBN * normalize(NormalMap), 0.0); } -vec2 poissonDisk[4] = vec2[]( - vec2( -0.94201624, -0.39906216 ), - vec2( 0.94558609, -0.76890725 ), - vec2( -0.094184101, -0.92938870 ), - vec2( 0.34495938, 0.29387760 ) - ); - -float CalcShadowValue(vec4 positionLightSpace, vec4 normal, vec4 lightDir, sampler2D depthTexture) +float CalcShadowValue(vec4 positionLightSpace, vec3 normal, vec3 lightDir, sampler2DShadow depthTexture) { float bias = 0.005; - //float bias = max(0.05 * (1.0 - dot(normal, -lightDir)), 0.005); - // perform perspective divide + //float bias = max(0.05 * (1.0 - dot(normal, lightDir)), 0.005); + //float bias = 0.005 * tan(acos(clamp(dot(normal, lightDir), 0,1))); bias = clamp(bias, 0,0.01); + vec3 projCoords = positionLightSpace.xyz / positionLightSpace.w; - // Transform to [0,1] range projCoords = projCoords * 0.5 + 0.5; - // Get closest depth value from light's perspective (using [0,1] range fragPosLight as coords) - //float lightDepth = texture(depthTexture, positionLightSpace.xy).r; - float closestDepth = texture(depthTexture, projCoords.xy).r; - // Get depth of current fragment from light's perspective - //float currentDepth = positionLightSpace.z; - float currentDepth = projCoords.z; - // Check whether current frag pos is in shadow - float shadow = currentDepth - bias > closestDepth ? 1.0 : 0.0; - //float shadow = currentDepth > closestDepth ? 1.0 : 0.0; - + //float shadowMapDepth = texture(depthTexture, projCoords.xy).r; + float shadowMapDepth = 1.0 - texture(depthTexture, projCoords); + float geometryDepth = projCoords.z; + //float shadow = geometryDepth - bias > shadowMapDepth ? 1.0 : 0.0; + //float shadow = geometryDepth - bias > shadowMapDepth ? 0.0 : 1.0; + float shadow = shadowMapDepth; + //float shadow = 0.0; - ////soft shadow - using percentage-closer filtering (PCF) is to simply sample the surrounding texels of the depth map and average the results: + //vec2 texelSize = 1.0 / textureSize(depthTexture, 0); - //for(int x = -1; x <= 1; ++x) + //for(int x = -1; x <= 1; x++) //{ - // for(int y = -1; y <= 1; ++y) + // for(int y = -1; y <= 1; y++) // { - // float pcfDepth = texture(depthTexture, projCoords.xy + vec2(x, y) * texelSize).r; - // shadow += currentDepth - bias > pcfDepth ? 1.0 : 0.0; + // float pcfDepth = texture(depthTexture, projCoords.xy + vec2(x, y) * texelSize).r; + // shadow += geometryDepth - bias > pcfDepth ? 1.0 : 0.0; // } //} //shadow /= 9.0; - // - if(projCoords.z > 0.9) - { - shadow = 1.0; - } + + //if(projCoords.z > 1.0) + //{ + // shadow = 0.0; + //} return shadow; @@ -184,7 +174,7 @@ void main() int start = int(LightGrids.Data[currentTile].Start); int amount = int(LightGrids.Data[currentTile].Amount); - float shadowFactor = 1.0; + float shadowFactor = 0.0; for(int i = start; i < start + amount; i++) { @@ -197,15 +187,16 @@ void main() light_result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, position, normal, light.Falloff); } else if (light.Type == 2) { //Directional light_result = CalcDirectionalLightSource(V * light.Direction, light.Color, light.Intensity, viewVec, normal); - shadowFactor = CalcShadowValue(Input.PositionLightSpace, vec4(Input.Normal, 0.0), light.Direction, DepthMap); + shadowFactor = CalcShadowValue(Input.PositionLightSpace, Input.Normal, vec3(light.Direction), DepthMap); } totalLighting.Diffuse += light_result.Diffuse; totalLighting.Specular += light_result.Specular; } - totalLighting.Diffuse += (1.0 - shadowFactor); - totalLighting.Specular += (1.0 - shadowFactor); + totalLighting.Diffuse *= (1.0 + vec4(AmbientColor.rgb, 1.0)) - vec4(vec3(shadowFactor), 0.0); + totalLighting.Specular *= (1.0 + vec4(AmbientColor.rgb, 1.0)) - vec4(vec3(shadowFactor), 0.0); + //LightResult getInformation; vec4 color_result = mix((Color * diffuseTexel * DiffuseColor), Input.ExplosionColor, Input.ExplosionPercentageElapsed); diff --git a/src/Engine/Rendering/ShadowPass.cpp b/src/Engine/Rendering/ShadowPass.cpp index 61e37da3..5ffd553f 100644 --- a/src/Engine/Rendering/ShadowPass.cpp +++ b/src/Engine/Rendering/ShadowPass.cpp @@ -25,12 +25,15 @@ void ShadowPass::InitializeFrameBuffers() // Depth texture glGenTextures(1, &m_DepthMap); glBindTexture(GL_TEXTURE_2D, m_DepthMap); - glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, resolutionSizeWidth, resolutionSizeHeigth, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr); + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, resolutionSizeWidth, resolutionSizeHeigth, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr); //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height, 0, GL_RGB, GL_FLOAT, 0); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); + glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY); m_DepthBuffer.AddResource(std::shared_ptr(new Texture2D(&m_DepthMap, GL_DEPTH_ATTACHMENT))); @@ -67,7 +70,8 @@ void ShadowPass::Draw(RenderScene & scene) m_ShadowProgram->Bind(); glViewport(0, 0, resolutionSizeWidth, resolutionSizeHeigth); - glCullFace(GL_BACK); + + //glCullFace(GL_FRONT); //state->Disable(GL_CULL_FACE); ImGui::DragFloat4("ShadowMapCam", m_LRBT, 1.f, -1000.f, 1000.f); @@ -117,7 +121,7 @@ void ShadowPass::Draw(RenderScene & scene) glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height); - glCullFace(GL_BACK); + //glCullFace(GL_BACK); m_ShadowProgram->Unbind(); From cb77c1ff974fcb1f031f9fc3a6d1e12714533917 Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Wed, 10 Feb 2016 16:16:41 +0100 Subject: [PATCH 012/130] Working pcf, not optimized --- include/Engine/Rendering/ShadowPass.h | 4 ++-- resources/Shaders/ForwardPlus.frag.glsl | 9 ++++----- src/Engine/Rendering/ShadowPass.cpp | 6 +++--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/include/Engine/Rendering/ShadowPass.h b/include/Engine/Rendering/ShadowPass.h index 5acc376e..7c93fcd8 100644 --- a/include/Engine/Rendering/ShadowPass.h +++ b/include/Engine/Rendering/ShadowPass.h @@ -58,8 +58,8 @@ private: glm::mat4 m_LightView; glm::mat4 m_LightSpaceMatrix; - GLuint resolutionSizeWidth = 2048 * 4; - GLuint resolutionSizeHeigth = 2048 * 4; + GLuint resolutionSizeWidth = 2048 * 2; + GLuint resolutionSizeHeigth = 2048 * 2; bool m_ShadowOn = true; }; diff --git a/resources/Shaders/ForwardPlus.frag.glsl b/resources/Shaders/ForwardPlus.frag.glsl index 170a9d5a..ce71be28 100644 --- a/resources/Shaders/ForwardPlus.frag.glsl +++ b/resources/Shaders/ForwardPlus.frag.glsl @@ -121,16 +121,15 @@ float CalcShadowValue(vec4 positionLightSpace, vec3 normal, vec3 lightDir, sampl //float bias = max(0.05 * (1.0 - dot(normal, lightDir)), 0.005); //float bias = 0.005 * tan(acos(clamp(dot(normal, lightDir), 0,1))); bias = clamp(bias, 0,0.01); - vec3 projCoords = positionLightSpace.xyz / positionLightSpace.w; + vec3 projCoords = vec3(positionLightSpace.xy, positionLightSpace.z + bias) / positionLightSpace.w; projCoords = projCoords * 0.5 + 0.5; //float shadowMapDepth = texture(depthTexture, projCoords.xy).r; - float shadowMapDepth = 1.0 - texture(depthTexture, projCoords); + float shadowMapDepth = texture(depthTexture, projCoords); float geometryDepth = projCoords.z; //float shadow = geometryDepth - bias > shadowMapDepth ? 1.0 : 0.0; - //float shadow = geometryDepth - bias > shadowMapDepth ? 0.0 : 1.0; - float shadow = shadowMapDepth; + //float shadow = 1.0 - bias > shadowMapDepth ? 0.0 : 1.0; - //float shadow = 0.0; + float shadow = 1.0 - shadowMapDepth; //vec2 texelSize = 1.0 / textureSize(depthTexture, 0); //for(int x = -1; x <= 1; x++) diff --git a/src/Engine/Rendering/ShadowPass.cpp b/src/Engine/Rendering/ShadowPass.cpp index 5ffd553f..fbf25219 100644 --- a/src/Engine/Rendering/ShadowPass.cpp +++ b/src/Engine/Rendering/ShadowPass.cpp @@ -33,7 +33,7 @@ void ShadowPass::InitializeFrameBuffers() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); - glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY); + //glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY); m_DepthBuffer.AddResource(std::shared_ptr(new Texture2D(&m_DepthMap, GL_DEPTH_ATTACHMENT))); @@ -71,7 +71,7 @@ void ShadowPass::Draw(RenderScene & scene) glViewport(0, 0, resolutionSizeWidth, resolutionSizeHeigth); - //glCullFace(GL_FRONT); + glCullFace(GL_FRONT); //state->Disable(GL_CULL_FACE); ImGui::DragFloat4("ShadowMapCam", m_LRBT, 1.f, -1000.f, 1000.f); @@ -121,7 +121,7 @@ void ShadowPass::Draw(RenderScene & scene) glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height); - //glCullFace(GL_BACK); + glCullFace(GL_BACK); m_ShadowProgram->Unbind(); From 36043010af52d4d346f6cd4423d0ac32513af655 Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Wed, 10 Feb 2016 20:51:33 +0100 Subject: [PATCH 013/130] wip for shadows they work, but will be shit until we get cascaded. --- include/Engine/Rendering/ShadowPass.h | 4 +-- resources/Shaders/ForwardPlus.frag.glsl | 45 ++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/include/Engine/Rendering/ShadowPass.h b/include/Engine/Rendering/ShadowPass.h index 7c93fcd8..c5bf038e 100644 --- a/include/Engine/Rendering/ShadowPass.h +++ b/include/Engine/Rendering/ShadowPass.h @@ -58,8 +58,8 @@ private: glm::mat4 m_LightView; glm::mat4 m_LightSpaceMatrix; - GLuint resolutionSizeWidth = 2048 * 2; - GLuint resolutionSizeHeigth = 2048 * 2; + GLuint resolutionSizeWidth = 1024 * 8; + GLuint resolutionSizeHeigth = 1024 * 8; bool m_ShadowOn = true; }; diff --git a/resources/Shaders/ForwardPlus.frag.glsl b/resources/Shaders/ForwardPlus.frag.glsl index ce71be28..1157a019 100644 --- a/resources/Shaders/ForwardPlus.frag.glsl +++ b/resources/Shaders/ForwardPlus.frag.glsl @@ -114,18 +114,53 @@ vec4 CalcNormalMappedValue(vec3 normal, vec3 tangent, vec3 bitangent, vec2 textu return vec4(TBN * normalize(NormalMap), 0.0); } +vec2 poissonDisk[16] = vec2[]( + vec2( -0.94201624, -0.39906216 ), + vec2( 0.94558609, -0.76890725 ), + vec2( -0.094184101, -0.92938870 ), + vec2( 0.34495938, 0.29387760 ), + vec2( -0.91588581, 0.45771432 ), + vec2( -0.81544232, -0.87912464 ), + vec2( -0.38277543, 0.27676845 ), + vec2( 0.97484398, 0.75648379 ), + vec2( 0.44323325, -0.97511554 ), + vec2( 0.53742981, -0.47373420 ), + vec2( -0.26496911, -0.41893023 ), + vec2( 0.79197514, 0.19090188 ), + vec2( -0.24188840, 0.99706507 ), + vec2( -0.81409955, 0.91437590 ), + vec2( 0.19984126, 0.78641367 ), + vec2( 0.14383161, -0.14100790 ) +); + +float random(vec3 seed, int i) +{ + vec4 seed4 = vec4(seed, i); + float dot_product = dot(seed4, vec4(12.9898, 78.233, 45.164, 94.673)); + return fract(sin(dot_product) * 43758.5453); +} + float CalcShadowValue(vec4 positionLightSpace, vec3 normal, vec3 lightDir, sampler2DShadow depthTexture) { float bias = 0.005; //float bias = max(0.05 * (1.0 - dot(normal, lightDir)), 0.005); - //float bias = 0.005 * tan(acos(clamp(dot(normal, lightDir), 0,1))); bias = clamp(bias, 0,0.01); + //float bias = 0.005 * tan(acos(clamp(dot(normal, -lightDir), 0.0, 1.0))); vec3 projCoords = vec3(positionLightSpace.xy, positionLightSpace.z + bias) / positionLightSpace.w; projCoords = projCoords * 0.5 + 0.5; //float shadowMapDepth = texture(depthTexture, projCoords.xy).r; - float shadowMapDepth = texture(depthTexture, projCoords); - float geometryDepth = projCoords.z; + float shadowMapDepth; + //for (int i = 0; i < 4; i++) + //{ + // int index = i; + // //int index = int(16.0 * random(gl_FragCoord.xyy, i)) % 16; + // shadowMapDepth += 0.25 * texture(depthTexture, projCoords + vec3(poissonDisk[index], 0.0) / 700.0); + //} + + shadowMapDepth = texture(depthTexture, projCoords); + + //float geometryDepth = projCoords.z; //float shadow = geometryDepth - bias > shadowMapDepth ? 1.0 : 0.0; //float shadow = 1.0 - bias > shadowMapDepth ? 0.0 : 1.0; @@ -193,8 +228,8 @@ void main() totalLighting.Specular += light_result.Specular; } - totalLighting.Diffuse *= (1.0 + vec4(AmbientColor.rgb, 1.0)) - vec4(vec3(shadowFactor), 0.0); - totalLighting.Specular *= (1.0 + vec4(AmbientColor.rgb, 1.0)) - vec4(vec3(shadowFactor), 0.0); + totalLighting.Diffuse *= (1.5 + vec4(AmbientColor.rgb, 1.0)) - vec4(vec3(shadowFactor), 0.0); + totalLighting.Specular *= (1.5 + vec4(AmbientColor.rgb, 1.0)) - vec4(vec3(shadowFactor), 0.0); //LightResult getInformation; From e7118ce8e5eecefffd7f70587ed48a0a98561706 Mon Sep 17 00:00:00 2001 From: viktorljung Date: Wed, 17 Feb 2016 10:52:50 +0100 Subject: [PATCH 014/130] WIP --- include/Engine/Rendering/Skeleton.h | 5 +- resources/Schema/Entities/AnimationTests2.xml | 64 ++++++++++++------ src/Engine/Rendering/Skeleton.cpp | 66 +++++++++++-------- 3 files changed, 84 insertions(+), 51 deletions(-) diff --git a/include/Engine/Rendering/Skeleton.h b/include/Engine/Rendering/Skeleton.h index 28a5ef6a..3a7231d6 100644 --- a/include/Engine/Rendering/Skeleton.h +++ b/include/Engine/Rendering/Skeleton.h @@ -108,6 +108,8 @@ public: void AccumulateBoneTransforms(bool noRootMotion, std::vector animations, std::map& frameBones, const Bone* bone, glm::mat4 parentMatrix); void AccumulateBoneTransforms(bool noRootMotion, std::vector animations, AnimationOffset animationOffset, std::map& frameBones, const Bone* bone, glm::mat4 parentMatrix); + glm::mat4 AdditiveBlend(JointFrameTransform addTransform, JointFrameTransform transform); + void PrintSkeleton(); void PrintSkeleton(const Bone* parent, int depthCount); std::map Animations; @@ -118,8 +120,7 @@ public: int GetKeyframe(const Animation& animation, double time); private: - - glm::mat4 GetOffsetTransform(const Bone* bone, AnimationOffset animationOffset); + JointFrameTransform GetOffsetTransform(const Bone* bone, AnimationOffset animationOffset); std::map m_BonesByName; diff --git a/resources/Schema/Entities/AnimationTests2.xml b/resources/Schema/Entities/AnimationTests2.xml index 413c7e67..7ce357f4 100644 --- a/resources/Schema/Entities/AnimationTests2.xml +++ b/resources/Schema/Entities/AnimationTests2.xml @@ -29,25 +29,19 @@ - Run - 0.5 - 0.60188997954429357 - -1 + AimRifle + 0.94417153407339605 1 - 0.5 - 0.96957233017255007 + + 0.032904333143131348 0.093923612201312068 1 - - AimRifle - - Models/Characters/Assault/AssaultAnimations.mesh - + @@ -61,8 +55,8 @@ Models/Weapons/Red/AssaultWeaponRed.mesh - - + + @@ -108,23 +102,52 @@ - ShootFastRifle - 0.056234247235838808 + Idle + 0.17120540274882234 1 - 1 - Idl + 0.10000000149011612 + StrafeRigh 0.5 - 1.8308673495784191 - StrafeRigh + 0.518960175468406 0.5 0.32167823998061529 1 + + AimRifle + Models/Characters/Assault/AssaultAnimations.mesh + + + + + R_Arm_Weapon_Joint + + + Models/Weapons/Red/AssaultWeaponRed.mesh + + + + + + + + + + + AimRifle + + + Models/Characters/Assault/AssaultAnimations.mesh + + + + + @@ -135,7 +158,8 @@ Models/Weapons/Red/AssaultWeaponRed.mesh - + + diff --git a/src/Engine/Rendering/Skeleton.cpp b/src/Engine/Rendering/Skeleton.cpp index e390d694..bd994a08 100644 --- a/src/Engine/Rendering/Skeleton.cpp +++ b/src/Engine/Rendering/Skeleton.cpp @@ -274,26 +274,18 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, std::vectorParent) { - if (offset != glm::mat4(1)) { - boneMatrix = parentMatrix * offset;// *((glm::inverse(bone->OffsetMatrix) * bone->Parent->OffsetMatrix)); - } else { - boneMatrix = parentMatrix *((glm::inverse(bone->OffsetMatrix) * bone->Parent->OffsetMatrix)); - - } + boneMatrix = parentMatrix * (glm::inverse(bone->OffsetMatrix) * bone->Parent->OffsetMatrix); boneMatrices[bone->ID] = boneMatrix * bone->OffsetMatrix; } else { - boneMatrix = offset * glm::inverse(bone->OffsetMatrix); + boneMatrix = glm::inverse(bone->OffsetMatrix); boneMatrices[bone->ID] = parentMatrix; } } else { - glm::vec3 finalPosInterp; - glm::quat finalRotInterp; - glm::vec3 finalScaleInterp; + JointFrameTransform jointFinalTransform; + float totalWeight = 0; for (JointFrameTransform jointTransform : JointTransforms) { @@ -303,26 +295,23 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, std::vectorID] = boneMatrix * bone->OffsetMatrix; } @@ -331,7 +320,20 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, std::vector animations, AnimationOffset animationOffset, glm::mat4 childMatrix) { glm::mat4 boneMatrix; - + /* std::vector JointTransforms; for (const AnimationData animationData : animations) { @@ -569,9 +577,9 @@ glm::mat4 Skeleton::GetBoneTransform(bool noRootMotion, const Bone* bone, std::v if (bone->Parent != nullptr) { return GetBoneTransform(noRootMotion, bone->Parent, animations, animationOffset, boneMatrix); - } else { + } else {*/ return boneMatrix; - } + // } } From db8bc612bd61c1de7f7543fca13ff2abc8f7b4ec Mon Sep 17 00:00:00 2001 From: viktorljung Date: Wed, 17 Feb 2016 14:55:02 +0100 Subject: [PATCH 015/130] AdditiveBlend now working, needs cleanup --- include/Engine/Rendering/Skeleton.h | 8 +- resources/Schema/Entities/AnimationTests2.xml | 64 ++------- src/Engine/Rendering/Skeleton.cpp | 122 ++++++++++-------- 3 files changed, 79 insertions(+), 115 deletions(-) diff --git a/include/Engine/Rendering/Skeleton.h b/include/Engine/Rendering/Skeleton.h index 3a7231d6..3f9331ca 100644 --- a/include/Engine/Rendering/Skeleton.h +++ b/include/Engine/Rendering/Skeleton.h @@ -76,9 +76,9 @@ public: }; struct JointFrameTransform { - glm::vec3 PositionInterp = glm::vec3(0); - glm::quat RotationInterp = glm::quat(); - glm::vec3 ScaleInterp = glm::vec3(0); + glm::vec3 Position = glm::vec3(0); + glm::quat Rotation = glm::quat(); + glm::vec3 Scale = glm::vec3(0); float Weight; }; @@ -108,7 +108,7 @@ public: void AccumulateBoneTransforms(bool noRootMotion, std::vector animations, std::map& frameBones, const Bone* bone, glm::mat4 parentMatrix); void AccumulateBoneTransforms(bool noRootMotion, std::vector animations, AnimationOffset animationOffset, std::map& frameBones, const Bone* bone, glm::mat4 parentMatrix); - glm::mat4 AdditiveBlend(JointFrameTransform addTransform, JointFrameTransform transform); + glm::mat4 AdditiveBlend(glm::mat4 differencePose, glm::mat4 targetPose); void PrintSkeleton(); void PrintSkeleton(const Bone* parent, int depthCount); diff --git a/resources/Schema/Entities/AnimationTests2.xml b/resources/Schema/Entities/AnimationTests2.xml index 7ce357f4..c36c5c02 100644 --- a/resources/Schema/Entities/AnimationTests2.xml +++ b/resources/Schema/Entities/AnimationTests2.xml @@ -29,10 +29,10 @@ - AimRifle - 0.94417153407339605 + Idle + 1.1429797894322036 + 1 1 - 0.032904333143131348 0.093923612201312068 1 @@ -44,24 +44,7 @@ - - - - - R_Arm_Weapon_Joint - - - - Models/Weapons/Red/AssaultWeaponRed.mesh - - - - - - - - - + @@ -103,43 +86,32 @@ Idle - 0.17120540274882234 + 1.1429797894322036 1 0.10000000149011612 StrafeRigh 0.5 - 0.518960175468406 + 0.67154243305829331 0.5 0.32167823998061529 1 AimRifle + Models/Characters/Assault/AssaultAnimations.mesh - - - - - R_Arm_Weapon_Joint - - - Models/Weapons/Red/AssaultWeaponRed.mesh - - - - - - + AimRifle + 0.5 Models/Characters/Assault/AssaultAnimations.mesh @@ -148,23 +120,7 @@ - - - - - R_Arm_Weapon_Joint - - - Models/Weapons/Red/AssaultWeaponRed.mesh - - - - - - - - - + diff --git a/src/Engine/Rendering/Skeleton.cpp b/src/Engine/Rendering/Skeleton.cpp index bd994a08..0e9483d6 100644 --- a/src/Engine/Rendering/Skeleton.cpp +++ b/src/Engine/Rendering/Skeleton.cpp @@ -127,23 +127,23 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, std::vectorID] = parentMatrix; } } else if (JointTransforms.size() == 1) { - boneMatrix = parentMatrix *(glm::translate(JointTransforms.at(0).PositionInterp) * glm::toMat4(JointTransforms.at(0).RotationInterp) * glm::scale(JointTransforms.at(0).ScaleInterp)); + boneMatrix = parentMatrix *(glm::translate(JointTransforms.at(0).Position) * glm::toMat4(JointTransforms.at(0).Rotation) * glm::scale(JointTransforms.at(0).Scale)); boneMatrices[bone->ID] = boneMatrix * bone->OffsetMatrix; } else { @@ -178,14 +178,14 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, std::vectorID] = boneMatrix * bone->OffsetMatrix; @@ -321,16 +335,10 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, std::vectorOffsetMatrix) * childMatrix; } } else if (JointTransforms.size() == 1) { - boneMatrix = (glm::translate(JointTransforms.at(0).PositionInterp) * glm::toMat4(JointTransforms.at(0).RotationInterp) * glm::scale(JointTransforms.at(0).ScaleInterp)) * childMatrix; + boneMatrix = (glm::translate(JointTransforms.at(0).Position) * glm::toMat4(JointTransforms.at(0).Rotation) * glm::scale(JointTransforms.at(0).Scale)) * childMatrix; } else { glm::vec3 finalPosInterp; @@ -676,14 +684,14 @@ glm::mat4 Skeleton::GetBoneTransform(bool noRootMotion, const Bone* bone, std::v for (JointFrameTransform jointTransform : JointTransforms) { if (jointTransform.Weight == 1.0f) { - finalPosInterp = jointTransform.PositionInterp; - finalRotInterp = jointTransform.RotationInterp; - finalScaleInterp = jointTransform.ScaleInterp; + finalPosInterp = jointTransform.Position; + finalRotInterp = jointTransform.Rotation; + finalScaleInterp = jointTransform.Scale; break; } else { - finalPosInterp += jointTransform.PositionInterp * (jointTransform.Weight/totalWeight); - finalRotInterp *= glm::slerp(glm::quat(), jointTransform.RotationInterp, (jointTransform.Weight/totalWeight)); - finalScaleInterp += jointTransform.ScaleInterp * (jointTransform.Weight/totalWeight); + finalPosInterp += jointTransform.Position * (jointTransform.Weight/totalWeight); + finalRotInterp *= glm::slerp(glm::quat(), jointTransform.Rotation, (jointTransform.Weight/totalWeight)); + finalScaleInterp += jointTransform.Scale * (jointTransform.Weight/totalWeight); } } From debb1881bf70ee2de8d5bd91a4ad564cd1d9fd47 Mon Sep 17 00:00:00 2001 From: viktorljung Date: Wed, 17 Feb 2016 15:48:45 +0100 Subject: [PATCH 016/130] BoneAttachment working --- include/Engine/Rendering/Skeleton.h | 2 +- resources/Schema/Entities/BlueRifle | 19 ++++++ src/Engine/Rendering/Skeleton.cpp | 101 +++++++++++++--------------- 3 files changed, 68 insertions(+), 54 deletions(-) create mode 100644 resources/Schema/Entities/BlueRifle diff --git a/include/Engine/Rendering/Skeleton.h b/include/Engine/Rendering/Skeleton.h index 3f9331ca..93f62a37 100644 --- a/include/Engine/Rendering/Skeleton.h +++ b/include/Engine/Rendering/Skeleton.h @@ -108,7 +108,7 @@ public: void AccumulateBoneTransforms(bool noRootMotion, std::vector animations, std::map& frameBones, const Bone* bone, glm::mat4 parentMatrix); void AccumulateBoneTransforms(bool noRootMotion, std::vector animations, AnimationOffset animationOffset, std::map& frameBones, const Bone* bone, glm::mat4 parentMatrix); - glm::mat4 AdditiveBlend(glm::mat4 differencePose, glm::mat4 targetPose); + glm::mat4 AdditiveBlend(const Bone* bone, AnimationOffset animationOffset, glm::mat4 targetPose); void PrintSkeleton(); void PrintSkeleton(const Bone* parent, int depthCount); diff --git a/resources/Schema/Entities/BlueRifle b/resources/Schema/Entities/BlueRifle new file mode 100644 index 00000000..194c7739 --- /dev/null +++ b/resources/Schema/Entities/BlueRifle @@ -0,0 +1,19 @@ + + + + + + R_Arm_Weapon_Joint + + + Models/Weapons/Blue/AssaultWeaponBlue.mesh + + + + + + + + + + diff --git a/src/Engine/Rendering/Skeleton.cpp b/src/Engine/Rendering/Skeleton.cpp index 0e9483d6..4e961a36 100644 --- a/src/Engine/Rendering/Skeleton.cpp +++ b/src/Engine/Rendering/Skeleton.cpp @@ -276,7 +276,11 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, std::vectorParent) { - boneMatrix = parentMatrix * (glm::inverse(bone->OffsetMatrix) * bone->Parent->OffsetMatrix); + + glm::mat4 jointPose = (glm::inverse(bone->OffsetMatrix) * bone->Parent->OffsetMatrix); + glm::mat4 boneTransform = AdditiveBlend(bone, animationOffset, jointPose); + + boneMatrix = parentMatrix * boneTransform; boneMatrices[bone->ID] = boneMatrix * bone->OffsetMatrix; } else { boneMatrix = glm::inverse(bone->OffsetMatrix); @@ -308,22 +312,8 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, std::vectorID] = boneMatrix * bone->OffsetMatrix; @@ -335,10 +325,19 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, std::vector animations, AnimationOffset animationOffset, glm::mat4 childMatrix) { glm::mat4 boneMatrix; - /* + std::vector JointTransforms; for (const AnimationData animationData : animations) { @@ -511,23 +509,23 @@ glm::mat4 Skeleton::GetBoneTransform(bool noRootMotion, const Bone* bone, std::v Animation::Keyframe::BoneProperty currentBoneProperty = currentFrame.BoneProperties; Animation::Keyframe::BoneProperty nextBoneProperty = nextFrame.BoneProperties; - jointTransform.PositionInterp = currentBoneProperty.Position * (1.f - progress) + nextBoneProperty.Position * progress; - jointTransform.RotationInterp = glm::slerp(currentBoneProperty.Rotation, nextBoneProperty.Rotation, progress); - jointTransform.ScaleInterp = currentBoneProperty.Scale * (1.f - progress) + nextBoneProperty.Scale * progress; + jointTransform.Position = currentBoneProperty.Position * (1.f - progress) + nextBoneProperty.Position * progress; + jointTransform.Rotation = glm::slerp(currentBoneProperty.Rotation, nextBoneProperty.Rotation, progress); + jointTransform.Scale = currentBoneProperty.Scale * (1.f - progress) + nextBoneProperty.Scale * progress; // Flag for no root motion if (bone == RootBone && noRootMotion) { - jointTransform.PositionInterp.x = 0; - jointTransform.PositionInterp.z = 0; + jointTransform.Position.x = 0; + jointTransform.Position.z = 0; } JointTransforms.push_back(jointTransform); } else { // 1 keyframes for the current bone currentFrame = boneKeyFrames.at(0); - jointTransform.PositionInterp = currentFrame.BoneProperties.Position; - jointTransform.RotationInterp = currentFrame.BoneProperties.Rotation; - jointTransform.ScaleInterp = currentFrame.BoneProperties.Scale; + jointTransform.Position = currentFrame.BoneProperties.Position; + jointTransform.Rotation = currentFrame.BoneProperties.Rotation; + jointTransform.Scale = currentFrame.BoneProperties.Scale; JointTransforms.push_back(jointTransform); } @@ -538,23 +536,20 @@ glm::mat4 Skeleton::GetBoneTransform(bool noRootMotion, const Bone* bone, std::v } - glm::mat4 offset = GetOffsetTransform(bone, animationOffset); - if (JointTransforms.size() == 0) { if (bone->Parent) { - if (offset != glm::mat4(1)) { - boneMatrix = offset * childMatrix;// *((glm::inverse(bone->OffsetMatrix) * bone->Parent->OffsetMatrix)); - } else { - boneMatrix = ((glm::inverse(bone->OffsetMatrix) * bone->Parent->OffsetMatrix)) * childMatrix; - } + + glm::mat4 jointPose = (glm::inverse(bone->OffsetMatrix) * bone->Parent->OffsetMatrix); + glm::mat4 boneTransform = AdditiveBlend(bone, animationOffset, jointPose); + + boneMatrix = boneTransform * childMatrix; } else { - boneMatrix = offset * glm::inverse(bone->OffsetMatrix); + boneMatrix = glm::inverse(bone->OffsetMatrix) * childMatrix; } } else { - glm::vec3 finalPosInterp; - glm::quat finalRotInterp; - glm::vec3 finalScaleInterp; + JointFrameTransform jointFinalTransform; + float totalWeight = 0; for (JointFrameTransform jointTransform : JointTransforms) { @@ -564,30 +559,30 @@ glm::mat4 Skeleton::GetBoneTransform(bool noRootMotion, const Bone* bone, std::v for (JointFrameTransform jointTransform : JointTransforms) { if (jointTransform.Weight == 1.0f) { - finalPosInterp = jointTransform.PositionInterp; - finalRotInterp = jointTransform.RotationInterp; - finalScaleInterp = jointTransform.ScaleInterp; + jointFinalTransform.Position = jointTransform.Position; + jointFinalTransform.Rotation = jointTransform.Rotation; + jointFinalTransform.Scale = jointTransform.Scale; break; } else { - finalPosInterp += jointTransform.PositionInterp * (jointTransform.Weight/totalWeight); - finalRotInterp *= glm::slerp(glm::quat(), jointTransform.RotationInterp, (jointTransform.Weight/totalWeight)); - finalScaleInterp += jointTransform.ScaleInterp * (jointTransform.Weight/totalWeight); + jointFinalTransform.Position += jointTransform.Position * (jointTransform.Weight/totalWeight); + jointFinalTransform.Rotation *= glm::slerp(glm::quat(), jointTransform.Rotation, (jointTransform.Weight/totalWeight)); + jointFinalTransform.Scale += jointTransform.Scale * (jointTransform.Weight/totalWeight); } } - if (offset != glm::mat4(1)) { - boneMatrix = ((glm::translate(finalPosInterp) * glm::toMat4(finalRotInterp) * glm::scale(finalScaleInterp)) + offset) * childMatrix; - } else { - boneMatrix = (glm::translate(finalPosInterp) * glm::toMat4(finalRotInterp) * glm::scale(finalScaleInterp)) * childMatrix; - } + + glm::mat4 jointPose = (glm::translate(jointFinalTransform.Position) * glm::toMat4(jointFinalTransform.Rotation) * glm::scale(jointFinalTransform.Scale)); + glm::mat4 boneTransform = AdditiveBlend(bone, animationOffset, jointPose); + + boneMatrix = boneTransform * childMatrix; } if (bone->Parent != nullptr) { return GetBoneTransform(noRootMotion, bone->Parent, animations, animationOffset, boneMatrix); - } else {*/ + } else { return boneMatrix; - // } + } } From 1c9a1a99044b3825bdbcd3aeb73028873bb6ef25 Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Wed, 17 Feb 2016 16:04:44 +0100 Subject: [PATCH 017/130] playerMovementSpeed,playerCrouchSpeed in the player component now also gets AssaultBoosted. --- resources/Schema/Entities/NewMap.xml | 20 ++++++++++---------- src/Game/Systems/HealthSystem.cpp | 4 ++-- src/Game/Systems/PlayerMovementSystem.cpp | 8 +++++++- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/resources/Schema/Entities/NewMap.xml b/resources/Schema/Entities/NewMap.xml index 00dc476f..8fb8d9f4 100644 --- a/resources/Schema/Entities/NewMap.xml +++ b/resources/Schema/Entities/NewMap.xml @@ -5019,7 +5019,7 @@ - + @@ -5089,7 +5089,7 @@ - + @@ -5165,7 +5165,7 @@ - + @@ -5184,7 +5184,7 @@ - + @@ -5203,7 +5203,7 @@ - + @@ -5222,7 +5222,7 @@ - + @@ -5241,7 +5241,7 @@ - + @@ -5260,7 +5260,7 @@ - + @@ -5279,7 +5279,7 @@ - + @@ -5298,7 +5298,7 @@ - + diff --git a/src/Game/Systems/HealthSystem.cpp b/src/Game/Systems/HealthSystem.cpp index 201e4760..b4ea210c 100644 --- a/src/Game/Systems/HealthSystem.cpp +++ b/src/Game/Systems/HealthSystem.cpp @@ -30,8 +30,8 @@ bool HealthSystem::OnPlayerDamaged(Events::PlayerDamage& e) ComponentWrapper cHealth = e.Victim["Health"]; double& health = cHealth["Health"]; - if (e.Player.HasComponent("BoostDefender")) { - e.Damage -= (double)e.Player["BoostDefender"]["StrengthOfEffect"]; + if (e.Victim.HasComponent("BoostDefender")) { + e.Damage -= (double)e.Victim["BoostDefender"]["StrengthOfEffect"]; } health -= e.Damage; diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index 64216e58..e754252d 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -53,6 +53,11 @@ void PlayerMovementSystem::updateMovementControllers(double dt) float playerMovementSpeed = player["Player"]["MovementSpeed"]; float playerCrouchSpeed = player["Player"]["CrouchSpeed"]; glm::vec3& wishDirection = player["Player"]["CurrentWishDirection"]; + if (player.HasComponent("BoostAssault")) { + playerMovementSpeed *= (double)player["BoostAssault"]["StrengthOfEffect"]; + playerCrouchSpeed *= (double)player["BoostAssault"]["StrengthOfEffect"]; + } + if (player.HasComponent("Physics")) { ComponentWrapper cPhysics = player["Physics"]; @@ -104,9 +109,10 @@ void PlayerMovementSystem::updateMovementControllers(double dt) //if doubleTapped do Assault Dash - but only boost maximum 50.0f float doubleTapDashBoost = controller->AssaultDashDoubleTapped() ? 40.0f : 1.0f; accelerationSpeed = glm::min(doubleTapDashBoost*glm::min(accelerationSpeed, addSpeed), 50.0f); + accelerationSpeed = doubleTapDashBoost*glm::min(accelerationSpeed, addSpeed); //if player has Boost from an Assault class, accelerate the player faster if (player.HasComponent("BoostAssault")) { - accelerationSpeed *= (double) player["BoostAssault"]["StrengthOfEffect"]; + accelerationSpeed *= (double)player["BoostAssault"]["StrengthOfEffect"]; } velocity += accelerationSpeed * wishDirection; ImGui::Text("velocity: (%f, %f, %f) |%f|", velocity.x, velocity.y, velocity.z, glm::length(velocity)); From 56bc1fee3ddf5767bc5af135652fe519894f9df0 Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Wed, 17 Feb 2016 16:43:38 +0100 Subject: [PATCH 018/130] Added LifeTimeOfEffect in BoostAssault,BoostDefender components. --- resources/Schema/Components/BoostAssault.xml | 15 ++------------- resources/Schema/Components/BoostAssault.xsd | 3 +++ resources/Schema/Components/BoostDefender.xml | 15 ++------------- resources/Schema/Components/BoostDefender.xsd | 3 +++ src/Game/Systems/PlayerMovementSystem.cpp | 1 - 5 files changed, 10 insertions(+), 27 deletions(-) diff --git a/resources/Schema/Components/BoostAssault.xml b/resources/Schema/Components/BoostAssault.xml index 099d3b0c..20ec953c 100644 --- a/resources/Schema/Components/BoostAssault.xml +++ b/resources/Schema/Components/BoostAssault.xml @@ -1,16 +1,5 @@ - - - - 5 - - - 5 - - - - - - + 2 + 5 diff --git a/resources/Schema/Components/BoostAssault.xsd b/resources/Schema/Components/BoostAssault.xsd index f7d348b7..b965b1fa 100644 --- a/resources/Schema/Components/BoostAssault.xsd +++ b/resources/Schema/Components/BoostAssault.xsd @@ -12,6 +12,9 @@ This is the strength of the boost effect + + How long the effect lasts + diff --git a/resources/Schema/Components/BoostDefender.xml b/resources/Schema/Components/BoostDefender.xml index 489d30cd..c1810544 100644 --- a/resources/Schema/Components/BoostDefender.xml +++ b/resources/Schema/Components/BoostDefender.xml @@ -1,16 +1,5 @@ - - - - 10 - - - 5 - - - - - - + 10 + 5 diff --git a/resources/Schema/Components/BoostDefender.xsd b/resources/Schema/Components/BoostDefender.xsd index 167b41dd..ed59f89c 100644 --- a/resources/Schema/Components/BoostDefender.xsd +++ b/resources/Schema/Components/BoostDefender.xsd @@ -12,6 +12,9 @@ This is the strength of the boost effect + + How long the effect lasts + diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index e754252d..a0289f3d 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -109,7 +109,6 @@ void PlayerMovementSystem::updateMovementControllers(double dt) //if doubleTapped do Assault Dash - but only boost maximum 50.0f float doubleTapDashBoost = controller->AssaultDashDoubleTapped() ? 40.0f : 1.0f; accelerationSpeed = glm::min(doubleTapDashBoost*glm::min(accelerationSpeed, addSpeed), 50.0f); - accelerationSpeed = doubleTapDashBoost*glm::min(accelerationSpeed, addSpeed); //if player has Boost from an Assault class, accelerate the player faster if (player.HasComponent("BoostAssault")) { accelerationSpeed *= (double)player["BoostAssault"]["StrengthOfEffect"]; From c3ed429377210709d4ab2664dc26ce6ff7343e5d Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Wed, 17 Feb 2016 18:11:36 +0100 Subject: [PATCH 019/130] Added BoostSystem, Added BoostAssault entity XML --- include/Game/Systems/BoostSystem.h | 25 + resources/Schema/Entities/BoostAssault.xml | 14 + .../Schema/Entities/BoostAssaultTest.xml | 5370 ++++++++++++++++- src/Game/Game.cpp | 2 + src/Game/Systems/BoostSystem.cpp | 60 + .../Systems/Weapon/AssaultWeaponBehaviour.cpp | 10 +- 6 files changed, 5326 insertions(+), 155 deletions(-) create mode 100644 include/Game/Systems/BoostSystem.h create mode 100644 resources/Schema/Entities/BoostAssault.xml create mode 100644 src/Game/Systems/BoostSystem.cpp diff --git a/include/Game/Systems/BoostSystem.h b/include/Game/Systems/BoostSystem.h new file mode 100644 index 00000000..8d87f065 --- /dev/null +++ b/include/Game/Systems/BoostSystem.h @@ -0,0 +1,25 @@ +#ifndef BoostSystem_h__ +#define BoostSystem_h__ + +#include "Core/System.h" +#include "Core/Transform.h" +#include "Core/ResourceManager.h" +#include "Core/EntityFileParser.h" +#include "Core/EPlayerDamage.h" +#include "Common.h" +#include + +#include "Rendering/Util/CommonFunctions.h" + +class BoostSystem : public System +{ +public: + BoostSystem(SystemParams params); + +private: + EventRelay m_EPlayerDamage; + bool OnPlayerDamage(Events::PlayerDamage& e); + + std::string determineClass(EntityWrapper player); +}; +#endif \ No newline at end of file diff --git a/resources/Schema/Entities/BoostAssault.xml b/resources/Schema/Entities/BoostAssault.xml new file mode 100644 index 00000000..727e5363 --- /dev/null +++ b/resources/Schema/Entities/BoostAssault.xml @@ -0,0 +1,14 @@ + + + + + + + 55 + + + + + + + diff --git a/resources/Schema/Entities/BoostAssaultTest.xml b/resources/Schema/Entities/BoostAssaultTest.xml index 97fd3f4d..89dcd0d7 100644 --- a/resources/Schema/Entities/BoostAssaultTest.xml +++ b/resources/Schema/Entities/BoostAssaultTest.xml @@ -6,130 +6,5080 @@ - + - - Models\MapVersion1.mesh - - + + + + + + Models/Props/Ground.mesh + + + + + + + + + Models/Props/Highground1.mesh + + + + + + + + + + Models/Props/Highground2.mesh + + + + + + + + + + Models/Props/Highground1.mesh + + + + + + + + + + + + Models/Props/Highground2.mesh + + + + + + + + + + + + Models/Props/Highground3.mesh + + + + + + + + + + Models/Props/Highground4.mesh + + + + + + + + + + Models/Props/Highground5.mesh + + + + + + + + + + + Models/Props/Highground6.mesh + + + + + + + + + + Models/Props/Walls/SciFiWallTop.mesh + + + + + + + + + Models/Props/Walls/SciFiWallBig.mesh + + + + + + + + + + Models/Props/Walls/SciFiWallMedium.mesh + + + + + + + + + + Models/Props/Walls/SciFiWallSmall1.mesh + + + + + + + + + + Models/Props/Walls/SciFiWallSmall2.mesh + + + + + + + + + + Models/Props/Walls/SciFiWallBig.mesh + + + + + + + + + + + + Models/Props/Walls/SciFiWallMedium.mesh + + + + + + + + + + + + Models/Props/Walls/SciFiWallSmall3.mesh + + + + + + + + + + Models/Props/Walls/SciFiWallSmall4.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar1Blue.mesh + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar1Red.mesh + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar3Blue.mesh + + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar1Blue.mesh + + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar1Red.mesh + + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar3Red.mesh + + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + + + + Models/Props/Walls/MediumWall3.mesh + + + + + + + + + + + + Models/Props/Walls/MediumWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall4.mesh + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + Models/Props/Walls/SmallWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall2.mesh + + + + + + + + + + + + Models/Props/Walls/MediumWall2.mesh + + + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall4.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall4.mesh + + + + + + + + + + + + Models/Props/Walls/SmallWall2.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + + + + Models/Props/Walls/SmallWall2.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall2.mesh + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + + + + Models/Props/Walls/MediumWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + Models/Props/Walls/SmallWall2.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + Models/Props/Walls/SpecialWall1.mesh + + + + + + + + + + + + + + Models/Props/Flora/SpecialRoot.mesh + + + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + Models/Props/Walls/MediumWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall2.mesh + + + + + + + + + + + + Models/Props/Walls/SmallWall2.mesh + + + + + + + + + + + + Models/Props/Walls/MediumWall3.mesh + + + + + + + + + + + + Models/Props/Walls/MediumWall2.mesh + + + + + + + + + + + Models/Props/Walls/MediumWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + Models/Props/Walls/SmallWall4.mesh + + + + + + + + + + + + + + + + Models/Props/Walls/MediumWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/SpecialWall1.mesh + + + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + + Models/Props/Walls/SpecialWall1.mesh + + + + + + + + + + + + Models/Props/Walls/SpecialWall1.mesh + + + + + + + + + + + + + Models/Props/Walls/SpecialWall1.mesh + + + + + + + + + + + + + Models/Props/Walls/SpecialWall1.mesh + + + + + + + + + + + + + Models/Props/Walls/SpecialWall1.mesh + + + + + + + + + + + + + + Models/Props/Walls/SpecialWall1.mesh + + + + + + + + + + + + + + + + + + + + + Models/Props/Bridges/WoodenBridge.mesh + + + + + + + + + + + + + + Models/Props/Bridges/WoodenBridge.mesh + + + + + + + + + + + + + + Models/Props/Bridges/WoodenBridge.mesh + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridge1Red.mesh + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridge1Blue.mesh + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/Pillars/SciFiBridgePillar1.mesh + + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridge1Blue.mesh + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridge1Blue.mesh + + + + + + + + + + + + + Models/Props/Pillars/SciFiBridgePillar1.mesh + + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridge1Red.mesh + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridge1Red.mesh + + + + + + + + + + + + + Models/Props/Bridges/WoodenBridge.mesh + + + + + + + + + + + + + + + + + + + + + Models/Props/Pillars/SciFiBridgePillar1.mesh + + + + + + + + + + + + + + Models/Props/Pillars/SciFiBridgePillar1.mesh + + + + + + + + + + + + + + Models/Props/Walls/MediumWall2.mesh + + + + + + + + + + + Models/Props/Walls/MediumWall2.mesh + + + + + + + + + + + + + + + Models/Props/Walls/MediumWall3.mesh + + + + + + + + + + + Models/Props/Walls/MediumWall3.mesh + + + + + + + + + + + + + + Models/Props/Pillars/SciFiBridgePillar1.mesh + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + Models/Core/UnitPlane.mesh + + true + + + + + + + + + + + + + Models/Core/UnitPlane.mesh + + true + + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + + + Models/Props/Pillars/SciFiBridgePillar1.mesh + + + + + + + + + + + + + + Models/Props/Pillars/SciFiBridgePillar1.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + + + + Models/Props/Flora/TreeLog.mesh + + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + + + Models/Props/Flora/SpecialRoot.mesh + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + + + Models/Props/Flora/SpecialRoot.mesh + + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + + + Models/Props/Flora/SpecialRoot.mesh + + + + + + + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + + + + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + - + - - 2 - - - Models/DirectionalLightWidget.mesh - false - - - - - - + - + + + + + + Models/Props/CapturePoint/CapturePointBlue.mesh + + + + + + + + + + + + + 4 + + + Models/Core/UnitCylinder.mesh + + true + + + + + + + + + + + + + + + + + + + + + Models/Props/CapturePoint/CapturePointNeutral.mesh + + + + + + + + + + 3 + + + Models/Core/UnitCylinder.mesh + + true + + + + + + + + + + + + + + + + + Models/Props/CapturePoint/CapturePointNeutral.mesh + + + + + + + + + + 2 + + + Models/Core/UnitCylinder.mesh + + true + + + + + + + + + + + + + + + + + Models/Props/CapturePoint/CapturePointNeutral.mesh + + + + + + + + + + 1.5498908015879351 + 1 + + + Models/Core/UnitCylinder.mesh + + true + + + + + + + + + + + + + + + + + Models/Props/CapturePoint/CapturePointRed.mesh + + + + + + + + + + + + + + + Models/Core/UnitCylinder.mesh + + true + + + + + + + + + + + + + + + + + - + - - 8 - 2.7999999523162842 - - - - + - + + + + + 1 + + + + + + + + + 10 + + + + + + + + + + 10 + + + + + + + + + + + + + 10 + + + + + + + + + + + 10 + + + + + + + + + + + 10 + + + + + + + + + + + 1 + + + + + + + + - - - - 8 - 2.7999999523162842 - - - - - - - - - - - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - Models/Core/UnitCube.mesh - - - - - - - - - + + + + + Schema/Entities/PlayerRed.xml + + + + + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + - - Models/Core/UnitCube.mesh - false - Schema/Entities/Player.xml @@ -139,100 +5089,218 @@ - + - + - + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + - + + + Models/Characters/Assault/AssaultTPose.mesh + false + - + - + + + + Models/Characters/Assault/AssaultTPose.mesh + false + - + - + + + + Models/Characters/Assault/AssaultTPose.mesh + false + - - - - - - - - - + - + - - - Models/Core/UnitCube.mesh - false - - - Schema/Entities/Player.xml - - - - - - - - - + - - + + + Models/Props/PickUps/HealthPickUp.mesh + + + 0.10000000149011612 + + + + + + + + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + 0.10000000149011612 + + - + + + + + + + Models/Props/PickUps/HealthPickUp.mesh + + + 0.10000000149011612 + + - + + + + + + + Models/Props/PickUps/HealthPickUp.mesh + + + 0.10000000149011612 + + - + + + + + + + + + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + 0.10000000149011612 + + + + + + + + + + + + + + + + Models/Props/PickUps/HealthPickUp.mesh + + + 0.10000000149011612 + + + + + + + + + + + + + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + 0.10000000149011612 + + + + + + + + + + + + + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + 0.10000000149011612 + + + + + + + + diff --git a/src/Game/Game.cpp b/src/Game/Game.cpp index 49b1a963..2cc5d715 100644 --- a/src/Game/Game.cpp +++ b/src/Game/Game.cpp @@ -26,6 +26,7 @@ #include "Network/MultiplayerSnapshotFilter.h" #include "Game/Systems/AmmunitionHUDSystem.h" #include "Game/Systems/KillFeedSystem.h" +#include "Game/Systems/BoostSystem.h" Game::Game(int argc, char* argv[]) @@ -132,6 +133,7 @@ Game::Game(int argc, char* argv[]) m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); + m_SystemPipeline->AddSystem(updateOrderLevel); // Populate Octree with collidables ++updateOrderLevel; m_SystemPipeline->AddSystem(updateOrderLevel, m_OctreeCollision, "Collidable"); diff --git a/src/Game/Systems/BoostSystem.cpp b/src/Game/Systems/BoostSystem.cpp new file mode 100644 index 00000000..bdd36d6a --- /dev/null +++ b/src/Game/Systems/BoostSystem.cpp @@ -0,0 +1,60 @@ +#include "Systems/BoostSystem.h" + +BoostSystem::BoostSystem(SystemParams params) + : System(params) +{ + EVENT_SUBSCRIBE_MEMBER(m_EPlayerDamage, &BoostSystem::OnPlayerDamage); +} + +bool BoostSystem::OnPlayerDamage(Events::PlayerDamage& e) +{ + if (e.Victim.ID == e.Inflictor.ID) { + return false; + } + if (!e.Victim.Valid() && e.Victim != LocalPlayer && !e.Victim.IsChildOf(LocalPlayer)) { + return false; + } + + if (!e.Inflictor.Valid() || !e.Victim.Valid()) { + return false; + } + + auto teamInflictor = m_World->GetComponent(e.Inflictor.ID, "Team"); + auto teamVictim = m_World->GetComponent(e.Victim.ID, "Team"); + if ((int)teamInflictor["Team"] != (int)teamVictim["Team"]) { + return false; + } + + //friendly fire + + auto className = determineClass(e.Inflictor); + if (className == "") { + return false; + } + //"Schema/Entities/BoostAssault.xml" + std::string classXML = "Schema/Entities/" + className + ".xml"; + + //class + + //load & set the BoostAssault Component + auto entityFile = ResourceManager::Load(classXML); + EntityFileParser parser(entityFile); + EntityID boostAssaultEntity = parser.MergeEntities(m_World); + m_World->SetParent(boostAssaultEntity, e.Victim.ID); + + return true; +} + +std::string BoostSystem::determineClass(EntityWrapper player) +{ + if (m_World->HasComponent(player.ID, "DashAbility")) { + return "BoostAssault"; + } + if (m_World->HasComponent(player.ID, "DefenderShield")) { + return "BoostDefender"; + } + if (m_World->HasComponent(player.ID, "SniperSprint")) { + return "BoostSniper"; + } + return ""; +} diff --git a/src/Game/Systems/Weapon/AssaultWeaponBehaviour.cpp b/src/Game/Systems/Weapon/AssaultWeaponBehaviour.cpp index 84d3ccd4..4a56ec8c 100644 --- a/src/Game/Systems/Weapon/AssaultWeaponBehaviour.cpp +++ b/src/Game/Systems/Weapon/AssaultWeaponBehaviour.cpp @@ -384,10 +384,12 @@ bool AssaultWeaponBehaviour::shoot(double damage) return false; } - // Check for friendly fire - if ((ComponentInfo::EnumType)victim["Team"]["Team"] == (ComponentInfo::EnumType)m_Player["Team"]["Team"]) { - return false; - } + + // Do Not Check for friendly fire + //// Check for friendly fire + //if ((ComponentInfo::EnumType)victim["Team"]["Team"] == (ComponentInfo::EnumType)m_Player["Team"]["Team"]) { + // return false; + //} // Deal damage! Events::PlayerDamage ePlayerDamage; From 178402e9646b11e3b0a61e189ba082161a228ac1 Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Thu, 18 Feb 2016 10:08:29 +0100 Subject: [PATCH 020/130] cascade shadow wip --- include/Engine/Rendering/ShadowPass.h | 20 +++++- resources/Shaders/ForwardPlus.frag.glsl | 6 +- src/Engine/Editor/EditorRenderSystem.cpp | 2 +- src/Engine/Rendering/RenderSystem.cpp | 2 +- src/Engine/Rendering/ShadowPass.cpp | 91 ++++++++++++++++++++++-- 5 files changed, 108 insertions(+), 13 deletions(-) diff --git a/include/Engine/Rendering/ShadowPass.h b/include/Engine/Rendering/ShadowPass.h index c5bf038e..685432c8 100644 --- a/include/Engine/Rendering/ShadowPass.h +++ b/include/Engine/Rendering/ShadowPass.h @@ -9,11 +9,18 @@ #include "ShadowPassState.h" #include "imgui/imgui.h" +#define MAX_SPLITS 5 + //#include "ShadowPassState.h" // not created yet enum NearFar { Near = 0, Far = 1 }; enum LRBT { Left = 0, Right = 1, Bottom = 2, Top = 3 }; +struct ShadowCamera{ + Camera* camera; + std::array frustumCorners; +}; + class ShadowPass { public: @@ -37,7 +44,10 @@ public: private: - + void CalculateFrustum(RenderScene & scene, std::shared_ptr directionalLightJob); + glm::vec3 LightDirectionToPoint(glm::vec4 direction); + std::array UpdateFrustumPoints(Camera* cam, glm::vec3 center, glm::vec3 view_dir); + void UpdateSplitDist(std::array shadow_cams, float far_distance, float near_distance); EventBroker* m_EventBroker; @@ -52,7 +62,8 @@ private: GLuint m_DepthFBO; GLfloat m_NearFarPlane[2] = { -34.f, 27.f }; - GLfloat m_LRBT[4] = { -77.f, 75.f, -89.f, 89.f }; + //GLfloat m_LRBT[4] = { -77.f, 75.f, -89.f, 89.f }; + GLfloat m_LRBT[4] = { -10.f, 10.f, -10.f, 10.f }; glm::mat4 m_LightProjection; glm::mat4 m_LightView; @@ -62,6 +73,11 @@ private: GLuint resolutionSizeHeigth = 1024 * 8; bool m_ShadowOn = true; + + int m_CurrentNrOfSplits = 3; + float m_SplitWeight = 0.75f; + + std::array shadCams; }; #endif \ No newline at end of file diff --git a/resources/Shaders/ForwardPlus.frag.glsl b/resources/Shaders/ForwardPlus.frag.glsl index 1157a019..205f1c5d 100644 --- a/resources/Shaders/ForwardPlus.frag.glsl +++ b/resources/Shaders/ForwardPlus.frag.glsl @@ -228,8 +228,10 @@ void main() totalLighting.Specular += light_result.Specular; } - totalLighting.Diffuse *= (1.5 + vec4(AmbientColor.rgb, 1.0)) - vec4(vec3(shadowFactor), 0.0); - totalLighting.Specular *= (1.5 + vec4(AmbientColor.rgb, 1.0)) - vec4(vec3(shadowFactor), 0.0); + //totalLighting.Diffuse *= (1.5 + vec4(AmbientColor.rgb, 1.0)) - vec4(vec3(shadowFactor), 0.0); + //totalLighting.Specular *= (1.5 + vec4(AmbientColor.rgb, 1.0)) - vec4(vec3(shadowFactor), 0.0); + totalLighting.Diffuse *= (1.0 + vec4(AmbientColor.rgb, 1.0)) + vec4(vec3(shadowFactor, shadowFactor, 0.0), 0.0); + totalLighting.Specular *= (1.0 + vec4(AmbientColor.rgb, 1.0)) + vec4(vec3(shadowFactor, shadowFactor, 0.0), 0.0); //LightResult getInformation; diff --git a/src/Engine/Editor/EditorRenderSystem.cpp b/src/Engine/Editor/EditorRenderSystem.cpp index 4d65e9d3..1a521b88 100644 --- a/src/Engine/Editor/EditorRenderSystem.cpp +++ b/src/Engine/Editor/EditorRenderSystem.cpp @@ -7,7 +7,7 @@ EditorRenderSystem::EditorRenderSystem(World* m_World, EventBroker* eventBroker, { EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &EditorRenderSystem::OnSetCamera); auto resolution = Rectangle::Rectangle(1280, 720); - m_EditorCamera = new Camera((float)resolution.Width / resolution.Height, glm::radians(45.f), 0.01f, 5000.f); + m_EditorCamera = new Camera((float)resolution.Width / resolution.Height, glm::radians(45.f), 0.01f, 500.f); } void EditorRenderSystem::Update(double dt) diff --git a/src/Engine/Rendering/RenderSystem.cpp b/src/Engine/Rendering/RenderSystem.cpp index eaecf99e..03613842 100644 --- a/src/Engine/Rendering/RenderSystem.cpp +++ b/src/Engine/Rendering/RenderSystem.cpp @@ -10,7 +10,7 @@ RenderSystem::RenderSystem(World* world, EventBroker* eventBroker, const IRender EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &RenderSystem::OnInputCommand); EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &RenderSystem::OnPlayerSpawned); - m_Camera = new Camera((float)m_Renderer->Resolution().Width / m_Renderer->Resolution().Height, glm::radians(45.f), 0.01f, 5000.f); + m_Camera = new Camera((float)m_Renderer->Resolution().Width / m_Renderer->Resolution().Height, glm::radians(45.f), 0.01f, 300.f); } RenderSystem::~RenderSystem() diff --git a/src/Engine/Rendering/ShadowPass.cpp b/src/Engine/Rendering/ShadowPass.cpp index fbf25219..ca7b59f0 100644 --- a/src/Engine/Rendering/ShadowPass.cpp +++ b/src/Engine/Rendering/ShadowPass.cpp @@ -14,6 +14,86 @@ ShadowPass::~ShadowPass() } +// Compute the 8 corner points of the current view frustum +std::array ShadowPass::UpdateFrustumPoints(Camera* cam, glm::vec3 center, glm::vec3 view_dir) +{ + glm::vec3 up = glm::vec3(0.f, 1.f, 0.f); + glm::vec3 right = glm::normalize(glm::cross(view_dir, up)); + + glm::vec3 farCenter = center + view_dir * cam->FarClip(); + glm::vec3 nearCenter = center + view_dir * cam->NearClip(); + + up = glm::normalize(glm::cross(right, view_dir)); + + float near_height = tan(cam->FOV() / 2.0f) * cam->NearClip(); + float near_width = near_height * cam->AspectRatio(); + float far_height = tan(cam->FOV() / 2.0f) * cam->FarClip(); + float far_width = far_height * cam->AspectRatio(); + + std::array frustumPoints; + frustumPoints[0] = nearCenter - up*near_height - right*near_width; + frustumPoints[1] = nearCenter + up*near_height - right*near_width; + frustumPoints[2] = nearCenter + up*near_height + right*near_width; + frustumPoints[3] = nearCenter - up*near_height + right*near_width; + + frustumPoints[4] = farCenter - up*far_height - right*far_width; + frustumPoints[5] = farCenter + up*far_height - right*far_width; + frustumPoints[6] = farCenter + up*far_height + right*far_width; + frustumPoints[7] = farCenter - up*far_height + right*far_width; + + return frustumPoints; +} + +// UpdateSplitDist computes the near and far distances for every frustum slice +// in camera eye space - that is, at what distance does a slice start and end +void ShadowPass::UpdateSplitDist(std::array shadow_cams, float far_distance, float near_distance) +{ + float lambda = m_SplitWeight; + float ratio = far_distance / near_distance; + + shadow_cams[0].camera->SetNearClip(near_distance); + + for (int i = 1; i < m_CurrentNrOfSplits; i++) { + float si = i / static_cast(m_CurrentNrOfSplits); + + shadow_cams[i].camera->SetNearClip(lambda * (near_distance * powf(ratio, si)) + (1 - lambda) * (near_distance + (far_distance - near_distance) * si)); + shadow_cams[i - 1].camera->SetFarClip(shadow_cams[i].camera->NearClip() * 1.005f); + } + + shadow_cams[m_CurrentNrOfSplits - 1].camera->SetFarClip(far_distance); +} + +float applyCropMatrix() +{ + +} + +// GLM wants a point for glm::lookAt, brute out a point that is on the light direction's tangent. +glm::vec3 ShadowPass::LightDirectionToPoint(glm::vec4 direction) +{ + return -glm::normalize(glm::vec3(direction)); +} + +void ShadowPass::CalculateFrustum(RenderScene & scene, std::shared_ptr directionalLightJob) +{ + //m_LightView = glm::lookAt(LightDirectionToPoint(directionalLightJob->Direction), glm::vec3(0.f, 0.f, 0.f), glm::vec3(0.f, 1.f, 0.f)); + + m_LightProjection = glm::ortho(m_LRBT[Left], m_LRBT[Right], m_LRBT[Bottom], m_LRBT[Top], m_NearFarPlane[Near], m_NearFarPlane[Far]); + + glm::vec3 LightPoint = LightDirectionToPoint(directionalLightJob->Direction); + + float CameraDistance = scene.Camera->FarClip() - scene.Camera->NearClip(); + float CameraPercentiles[3] = { 0.f, CameraDistance * 0.2f, CameraDistance * 0.65f }; + + + glm::vec3 point = scene.Camera->Position() + (scene.Camera->Forward() * 30.f); + + m_LightView = glm::lookAt(LightPoint + point, point, glm::vec3(0.f, 1.f, 0.f)); + + m_LightSpaceMatrix = m_LightProjection * m_LightView; + + //scene.Camera-> +} void ShadowPass::InitializeFrameBuffers() { @@ -29,9 +109,10 @@ void ShadowPass::InitializeFrameBuffers() //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height, 0, GL_RGB, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE); + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, glm::vec4(1.f).data); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); //glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY); @@ -84,11 +165,7 @@ void ShadowPass::Draw(RenderScene & scene) auto directionalLightJob = std::dynamic_pointer_cast(job); if(directionalLightJob) { - //m_LightProjection = glm::ortho(m_LRBT[Left], m_LRBT[Right], m_LRBT[Bottom], m_LRBT[Top], m_NearFarPlane[Near], m_NearFarPlane[Far]); - m_LightProjection = glm::ortho(m_LRBT[Left], m_LRBT[Right], m_LRBT[Bottom], m_LRBT[Top], m_NearFarPlane[Near], m_NearFarPlane[Far]); - m_LightView = glm::lookAt(-glm::normalize(glm::vec3(directionalLightJob->Direction)), glm::vec3(0.f,0.f,0.f), glm::vec3(0.f,1.f,0.f)); - //m_LightView = glm::lookAt(glm::vec3(-20.0f, 20.0f, -20.0f), glm::vec3(0.0f), glm::vec3(1.0)); - m_LightSpaceMatrix = m_LightProjection * m_LightView; + CalculateFrustum(scene, directionalLightJob); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_LightProjection)); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_LightView)); From 7f489b3569996ff5c6c369bce6ffb387dd900107 Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Thu, 18 Feb 2016 10:40:09 +0100 Subject: [PATCH 021/130] Added Assault,Defender,Sniper Components,Entities. Added ShieldAbility,Sprintability-Component (not implemented). Changed BoostSystem to use a childed Boost to the player. All friendly fire is 0 damage. --- include/Game/Systems/BoostSystem.h | 2 +- resources/Schema/Components.xsd | 3 +++ resources/Schema/Components/BoostAssault.xml | 1 - resources/Schema/Components/BoostAssault.xsd | 3 --- resources/Schema/Components/BoostDefender.xml | 1 - resources/Schema/Components/BoostDefender.xsd | 3 --- resources/Schema/Components/BoostSniper.xml | 4 ++++ resources/Schema/Components/BoostSniper.xsd | 18 +++++++++++++++ resources/Schema/Components/ShieldAbility.xml | 4 ++++ resources/Schema/Components/ShieldAbility.xsd | 18 +++++++++++++++ resources/Schema/Components/SprintAbility.xml | 4 ++++ resources/Schema/Components/SprintAbility.xsd | 18 +++++++++++++++ resources/Schema/Entities/BoostAssault.xml | 2 +- resources/Schema/Entities/BoostDefender.xml | 14 +++++++++++ resources/Schema/Entities/BoostSniper.xml | 14 +++++++++++ src/Game/Systems/BoostSystem.cpp | 23 +++++++++++-------- src/Game/Systems/HealthSystem.cpp | 5 ++-- src/Game/Systems/PlayerMovementSystem.cpp | 11 +++++---- .../Systems/Weapon/AssaultWeaponBehaviour.cpp | 9 ++++---- 19 files changed, 125 insertions(+), 32 deletions(-) create mode 100644 resources/Schema/Components/BoostSniper.xml create mode 100644 resources/Schema/Components/BoostSniper.xsd create mode 100644 resources/Schema/Components/ShieldAbility.xml create mode 100644 resources/Schema/Components/ShieldAbility.xsd create mode 100644 resources/Schema/Components/SprintAbility.xml create mode 100644 resources/Schema/Components/SprintAbility.xsd create mode 100644 resources/Schema/Entities/BoostDefender.xml create mode 100644 resources/Schema/Entities/BoostSniper.xml diff --git a/include/Game/Systems/BoostSystem.h b/include/Game/Systems/BoostSystem.h index 8d87f065..5e9c47da 100644 --- a/include/Game/Systems/BoostSystem.h +++ b/include/Game/Systems/BoostSystem.h @@ -20,6 +20,6 @@ private: EventRelay m_EPlayerDamage; bool OnPlayerDamage(Events::PlayerDamage& e); - std::string determineClass(EntityWrapper player); + std::string DetermineClass(EntityWrapper player); }; #endif \ No newline at end of file diff --git a/resources/Schema/Components.xsd b/resources/Schema/Components.xsd index f5c65719..c9d8a70e 100644 --- a/resources/Schema/Components.xsd +++ b/resources/Schema/Components.xsd @@ -35,9 +35,12 @@ + + + diff --git a/resources/Schema/Components/BoostAssault.xml b/resources/Schema/Components/BoostAssault.xml index 20ec953c..c76fe21e 100644 --- a/resources/Schema/Components/BoostAssault.xml +++ b/resources/Schema/Components/BoostAssault.xml @@ -1,5 +1,4 @@ 2 - 5 diff --git a/resources/Schema/Components/BoostAssault.xsd b/resources/Schema/Components/BoostAssault.xsd index b965b1fa..f7d348b7 100644 --- a/resources/Schema/Components/BoostAssault.xsd +++ b/resources/Schema/Components/BoostAssault.xsd @@ -12,9 +12,6 @@ This is the strength of the boost effect - - How long the effect lasts - diff --git a/resources/Schema/Components/BoostDefender.xml b/resources/Schema/Components/BoostDefender.xml index c1810544..fad0d2b7 100644 --- a/resources/Schema/Components/BoostDefender.xml +++ b/resources/Schema/Components/BoostDefender.xml @@ -1,5 +1,4 @@ 10 - 5 diff --git a/resources/Schema/Components/BoostDefender.xsd b/resources/Schema/Components/BoostDefender.xsd index ed59f89c..167b41dd 100644 --- a/resources/Schema/Components/BoostDefender.xsd +++ b/resources/Schema/Components/BoostDefender.xsd @@ -12,9 +12,6 @@ This is the strength of the boost effect - - How long the effect lasts - diff --git a/resources/Schema/Components/BoostSniper.xml b/resources/Schema/Components/BoostSniper.xml new file mode 100644 index 00000000..844b7c59 --- /dev/null +++ b/resources/Schema/Components/BoostSniper.xml @@ -0,0 +1,4 @@ + + + 10 + diff --git a/resources/Schema/Components/BoostSniper.xsd b/resources/Schema/Components/BoostSniper.xsd new file mode 100644 index 00000000..89778482 --- /dev/null +++ b/resources/Schema/Components/BoostSniper.xsd @@ -0,0 +1,18 @@ + + + + + + + + This is the defender's class boost component + + + + + This is the strength of the boost effect + + + + + diff --git a/resources/Schema/Components/ShieldAbility.xml b/resources/Schema/Components/ShieldAbility.xml new file mode 100644 index 00000000..49fcf0c0 --- /dev/null +++ b/resources/Schema/Components/ShieldAbility.xml @@ -0,0 +1,4 @@ + + + 2.0 + \ No newline at end of file diff --git a/resources/Schema/Components/ShieldAbility.xsd b/resources/Schema/Components/ShieldAbility.xsd new file mode 100644 index 00000000..49c0bae3 --- /dev/null +++ b/resources/Schema/Components/ShieldAbility.xsd @@ -0,0 +1,18 @@ + + + + + + + + A dash component for one of the classes + + + + + This is the cooldown on dash + + + + + \ No newline at end of file diff --git a/resources/Schema/Components/SprintAbility.xml b/resources/Schema/Components/SprintAbility.xml new file mode 100644 index 00000000..2aac99d6 --- /dev/null +++ b/resources/Schema/Components/SprintAbility.xml @@ -0,0 +1,4 @@ + + + 2.0 + \ No newline at end of file diff --git a/resources/Schema/Components/SprintAbility.xsd b/resources/Schema/Components/SprintAbility.xsd new file mode 100644 index 00000000..d8dc5383 --- /dev/null +++ b/resources/Schema/Components/SprintAbility.xsd @@ -0,0 +1,18 @@ + + + + + + + + A dash component for one of the classes + + + + + This is the cooldown on dash + + + + + \ No newline at end of file diff --git a/resources/Schema/Entities/BoostAssault.xml b/resources/Schema/Entities/BoostAssault.xml index 727e5363..9c8e54fd 100644 --- a/resources/Schema/Entities/BoostAssault.xml +++ b/resources/Schema/Entities/BoostAssault.xml @@ -4,7 +4,7 @@ - 55 + 10 diff --git a/resources/Schema/Entities/BoostDefender.xml b/resources/Schema/Entities/BoostDefender.xml new file mode 100644 index 00000000..f22b404e --- /dev/null +++ b/resources/Schema/Entities/BoostDefender.xml @@ -0,0 +1,14 @@ + + + + + + + 10 + + + + + + + diff --git a/resources/Schema/Entities/BoostSniper.xml b/resources/Schema/Entities/BoostSniper.xml new file mode 100644 index 00000000..a82a7a5d --- /dev/null +++ b/resources/Schema/Entities/BoostSniper.xml @@ -0,0 +1,14 @@ + + + + + + + 10 + + + + + + + diff --git a/src/Game/Systems/BoostSystem.cpp b/src/Game/Systems/BoostSystem.cpp index bdd36d6a..fdd5b6dc 100644 --- a/src/Game/Systems/BoostSystem.cpp +++ b/src/Game/Systems/BoostSystem.cpp @@ -25,35 +25,38 @@ bool BoostSystem::OnPlayerDamage(Events::PlayerDamage& e) return false; } - //friendly fire - - auto className = determineClass(e.Inflictor); + auto className = DetermineClass(e.Inflictor); if (className == "") { return false; } - //"Schema/Entities/BoostAssault.xml" + //"Schema/Entities/Boost-.xml" std::string classXML = "Schema/Entities/" + className + ".xml"; - //class - + //check if player already has the component + auto playerBoostAssaultEntity = e.Victim.FirstChildByName(className); + if (playerBoostAssaultEntity.Valid()) { + m_World->DeleteEntity(playerBoostAssaultEntity.ID); + } //load & set the BoostAssault Component auto entityFile = ResourceManager::Load(classXML); EntityFileParser parser(entityFile); EntityID boostAssaultEntity = parser.MergeEntities(m_World); + m_World->SetName(boostAssaultEntity, className); m_World->SetParent(boostAssaultEntity, e.Victim.ID); return true; } -std::string BoostSystem::determineClass(EntityWrapper player) +std::string BoostSystem::DetermineClass(EntityWrapper inflictorPlayer) { - if (m_World->HasComponent(player.ID, "DashAbility")) { + //determine the class based on what component the inflictor-player has + if (m_World->HasComponent(inflictorPlayer.ID, "DashAbility")) { return "BoostAssault"; } - if (m_World->HasComponent(player.ID, "DefenderShield")) { + if (m_World->HasComponent(inflictorPlayer.ID, "ShieldAbility")) { return "BoostDefender"; } - if (m_World->HasComponent(player.ID, "SniperSprint")) { + if (m_World->HasComponent(inflictorPlayer.ID, "SprintAbility")) { return "BoostSniper"; } return ""; diff --git a/src/Game/Systems/HealthSystem.cpp b/src/Game/Systems/HealthSystem.cpp index b4ea210c..82836d2c 100644 --- a/src/Game/Systems/HealthSystem.cpp +++ b/src/Game/Systems/HealthSystem.cpp @@ -30,8 +30,9 @@ bool HealthSystem::OnPlayerDamaged(Events::PlayerDamage& e) ComponentWrapper cHealth = e.Victim["Health"]; double& health = cHealth["Health"]; - if (e.Victim.HasComponent("BoostDefender")) { - e.Damage -= (double)e.Victim["BoostDefender"]["StrengthOfEffect"]; + auto playerBoostDefenderEntity = e.Victim.FirstChildByName("BoostDefender"); + if (playerBoostDefenderEntity.Valid()) { + e.Damage -= (double)playerBoostDefenderEntity["BoostDefender"]["StrengthOfEffect"]; } health -= e.Damage; diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index a0289f3d..cb28c7e6 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -53,9 +53,10 @@ void PlayerMovementSystem::updateMovementControllers(double dt) float playerMovementSpeed = player["Player"]["MovementSpeed"]; float playerCrouchSpeed = player["Player"]["CrouchSpeed"]; glm::vec3& wishDirection = player["Player"]["CurrentWishDirection"]; - if (player.HasComponent("BoostAssault")) { - playerMovementSpeed *= (double)player["BoostAssault"]["StrengthOfEffect"]; - playerCrouchSpeed *= (double)player["BoostAssault"]["StrengthOfEffect"]; + auto playerBoostAssaultEntity = player.FirstChildByName("BoostAssault"); + if (playerBoostAssaultEntity.Valid()) { + playerMovementSpeed *= (double)playerBoostAssaultEntity["BoostAssault"]["StrengthOfEffect"]; + playerCrouchSpeed *= (double)playerBoostAssaultEntity["BoostAssault"]["StrengthOfEffect"]; } @@ -110,8 +111,8 @@ void PlayerMovementSystem::updateMovementControllers(double dt) float doubleTapDashBoost = controller->AssaultDashDoubleTapped() ? 40.0f : 1.0f; accelerationSpeed = glm::min(doubleTapDashBoost*glm::min(accelerationSpeed, addSpeed), 50.0f); //if player has Boost from an Assault class, accelerate the player faster - if (player.HasComponent("BoostAssault")) { - accelerationSpeed *= (double)player["BoostAssault"]["StrengthOfEffect"]; + if (playerBoostAssaultEntity.Valid()) { + accelerationSpeed *= (double)playerBoostAssaultEntity["BoostAssault"]["StrengthOfEffect"]; } velocity += accelerationSpeed * wishDirection; ImGui::Text("velocity: (%f, %f, %f) |%f|", velocity.x, velocity.y, velocity.z, glm::length(velocity)); diff --git a/src/Game/Systems/Weapon/AssaultWeaponBehaviour.cpp b/src/Game/Systems/Weapon/AssaultWeaponBehaviour.cpp index 4a56ec8c..0b981169 100644 --- a/src/Game/Systems/Weapon/AssaultWeaponBehaviour.cpp +++ b/src/Game/Systems/Weapon/AssaultWeaponBehaviour.cpp @@ -385,11 +385,10 @@ bool AssaultWeaponBehaviour::shoot(double damage) } - // Do Not Check for friendly fire - //// Check for friendly fire - //if ((ComponentInfo::EnumType)victim["Team"]["Team"] == (ComponentInfo::EnumType)m_Player["Team"]["Team"]) { - // return false; - //} + // BoostUpdate: If friendly fire - reduce damage to 0 + if ((ComponentInfo::EnumType)victim["Team"]["Team"] == (ComponentInfo::EnumType)m_Player["Team"]["Team"]) { + damage = 0; + } // Deal damage! Events::PlayerDamage ePlayerDamage; From 8c92b7ceb6c389456260f9b6e0767149d10d8a71 Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Thu, 18 Feb 2016 13:40:17 +0100 Subject: [PATCH 022/130] Small cleanup. Clarified a few comments --- include/Game/Systems/BoostSystem.h | 4 ---- src/Game/Systems/BoostSystem.cpp | 14 +++++++------- src/Game/Systems/HealthSystem.cpp | 1 + 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/include/Game/Systems/BoostSystem.h b/include/Game/Systems/BoostSystem.h index 5e9c47da..f82707ab 100644 --- a/include/Game/Systems/BoostSystem.h +++ b/include/Game/Systems/BoostSystem.h @@ -2,14 +2,10 @@ #define BoostSystem_h__ #include "Core/System.h" -#include "Core/Transform.h" #include "Core/ResourceManager.h" #include "Core/EntityFileParser.h" #include "Core/EPlayerDamage.h" #include "Common.h" -#include - -#include "Rendering/Util/CommonFunctions.h" class BoostSystem : public System { diff --git a/src/Game/Systems/BoostSystem.cpp b/src/Game/Systems/BoostSystem.cpp index fdd5b6dc..9e4d6968 100644 --- a/src/Game/Systems/BoostSystem.cpp +++ b/src/Game/Systems/BoostSystem.cpp @@ -14,30 +14,30 @@ bool BoostSystem::OnPlayerDamage(Events::PlayerDamage& e) if (!e.Victim.Valid() && e.Victim != LocalPlayer && !e.Victim.IsChildOf(LocalPlayer)) { return false; } - if (!e.Inflictor.Valid() || !e.Victim.Valid()) { return false; } - auto teamInflictor = m_World->GetComponent(e.Inflictor.ID, "Team"); - auto teamVictim = m_World->GetComponent(e.Victim.ID, "Team"); - if ((int)teamInflictor["Team"] != (int)teamVictim["Team"]) { + //if its not friendly fire, return + if ((int)m_World->GetComponent(e.Inflictor.ID, "Team")["Team"] != (int)m_World->GetComponent(e.Victim.ID, "Team")["Team"]) { return false; } + //determine the inflictors class auto className = DetermineClass(e.Inflictor); if (className == "") { return false; } - //"Schema/Entities/Boost-.xml" + + //get the XML file, example: "Schema/Entities/BoostclassName.xml" std::string classXML = "Schema/Entities/" + className + ".xml"; - //check if player already has the component + //check if player already has a child with the component, if so delete that child auto playerBoostAssaultEntity = e.Victim.FirstChildByName(className); if (playerBoostAssaultEntity.Valid()) { m_World->DeleteEntity(playerBoostAssaultEntity.ID); } - //load & set the BoostAssault Component + //load boost XML file, set it entity parented with the victim player auto entityFile = ResourceManager::Load(classXML); EntityFileParser parser(entityFile); EntityID boostAssaultEntity = parser.MergeEntities(m_World); diff --git a/src/Game/Systems/HealthSystem.cpp b/src/Game/Systems/HealthSystem.cpp index 82836d2c..6e1e276f 100644 --- a/src/Game/Systems/HealthSystem.cpp +++ b/src/Game/Systems/HealthSystem.cpp @@ -30,6 +30,7 @@ bool HealthSystem::OnPlayerDamaged(Events::PlayerDamage& e) ComponentWrapper cHealth = e.Victim["Health"]; double& health = cHealth["Health"]; + //if player has the boost from a defender, subtract the damage taken by StrengthOfEffect amount auto playerBoostDefenderEntity = e.Victim.FirstChildByName("BoostDefender"); if (playerBoostDefenderEntity.Valid()) { e.Damage -= (double)playerBoostDefenderEntity["BoostDefender"]["StrengthOfEffect"]; From b2304a95f8e9146feb666629e605039973071a48 Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Thu, 18 Feb 2016 13:49:22 +0100 Subject: [PATCH 023/130] Fixed some XML documentation --- resources/Schema/Components/BoostSniper.xsd | 2 +- resources/Schema/Components/ShieldAbility.xsd | 4 ++-- resources/Schema/Components/SprintAbility.xsd | 4 ++-- src/Game/Systems/Weapon/AssaultWeaponBehaviour.cpp | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/resources/Schema/Components/BoostSniper.xsd b/resources/Schema/Components/BoostSniper.xsd index 89778482..2d62a9da 100644 --- a/resources/Schema/Components/BoostSniper.xsd +++ b/resources/Schema/Components/BoostSniper.xsd @@ -5,7 +5,7 @@ - This is the defender's class boost component + This is the sniper's class boost component diff --git a/resources/Schema/Components/ShieldAbility.xsd b/resources/Schema/Components/ShieldAbility.xsd index 49c0bae3..5cf2145c 100644 --- a/resources/Schema/Components/ShieldAbility.xsd +++ b/resources/Schema/Components/ShieldAbility.xsd @@ -5,12 +5,12 @@ - A dash component for one of the classes + A shield component for one of the classes - This is the cooldown on dash + This is the cooldown on shield diff --git a/resources/Schema/Components/SprintAbility.xsd b/resources/Schema/Components/SprintAbility.xsd index d8dc5383..4207dee2 100644 --- a/resources/Schema/Components/SprintAbility.xsd +++ b/resources/Schema/Components/SprintAbility.xsd @@ -5,12 +5,12 @@ - A dash component for one of the classes + A sprint component for one of the classes - This is the cooldown on dash + This is the cooldown on sprint diff --git a/src/Game/Systems/Weapon/AssaultWeaponBehaviour.cpp b/src/Game/Systems/Weapon/AssaultWeaponBehaviour.cpp index 0b981169..7ea6f4f1 100644 --- a/src/Game/Systems/Weapon/AssaultWeaponBehaviour.cpp +++ b/src/Game/Systems/Weapon/AssaultWeaponBehaviour.cpp @@ -385,7 +385,7 @@ bool AssaultWeaponBehaviour::shoot(double damage) } - // BoostUpdate: If friendly fire - reduce damage to 0 + // If friendly fire - reduce damage to 0 (needed to make Boosts, Ammosharing work) if ((ComponentInfo::EnumType)victim["Team"]["Team"] == (ComponentInfo::EnumType)m_Player["Team"]["Team"]) { damage = 0; } From b81bb9eeead495e600517d9ec5b54d806512a398 Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Thu, 18 Feb 2016 15:17:19 +0100 Subject: [PATCH 024/130] Changed SprintAbility to take StrengthOfEffect. PlayerMovementSystem: if Sniper is sprinting he will now move faster. --- include/Engine/Input/FirstPersonInputController.h | 9 +++++++++ resources/Schema/Components/SprintAbility.xml | 2 +- resources/Schema/Components/SprintAbility.xsd | 4 ++-- src/Game/Systems/PlayerMovementSystem.cpp | 12 +++++++++++- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/include/Engine/Input/FirstPersonInputController.h b/include/Engine/Input/FirstPersonInputController.h index 7dc24a2c..21833864 100644 --- a/include/Engine/Input/FirstPersonInputController.h +++ b/include/Engine/Input/FirstPersonInputController.h @@ -28,6 +28,7 @@ public: virtual void Reset(); void AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer); + bool SniperSprintingCheck(); virtual bool AssaultDashDoubleTapped() const { return m_AssaultDashDoubleTapped; } virtual bool PlayerIsDashing() const { return m_PlayerIsDashing; } @@ -241,4 +242,12 @@ void FirstPersonInputController::AssaultDashCheck(double dt, bool m_EventBroker->Publish(e); } +template +bool FirstPersonInputController::SniperSprintingCheck() { + if (m_SpecialAbilityKeyDown) { + return true; + } else { + return false; + } +} #endif \ No newline at end of file diff --git a/resources/Schema/Components/SprintAbility.xml b/resources/Schema/Components/SprintAbility.xml index 2aac99d6..5cc59a3a 100644 --- a/resources/Schema/Components/SprintAbility.xml +++ b/resources/Schema/Components/SprintAbility.xml @@ -1,4 +1,4 @@ - 2.0 + 2.0 \ No newline at end of file diff --git a/resources/Schema/Components/SprintAbility.xsd b/resources/Schema/Components/SprintAbility.xsd index 4207dee2..9eabb450 100644 --- a/resources/Schema/Components/SprintAbility.xsd +++ b/resources/Schema/Components/SprintAbility.xsd @@ -9,8 +9,8 @@ - - This is the cooldown on sprint + + This is the strength of the sprint effect diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index cb28c7e6..ee2f9ca3 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -58,7 +58,14 @@ void PlayerMovementSystem::updateMovementControllers(double dt) playerMovementSpeed *= (double)playerBoostAssaultEntity["BoostAssault"]["StrengthOfEffect"]; playerCrouchSpeed *= (double)playerBoostAssaultEntity["BoostAssault"]["StrengthOfEffect"]; } - + bool sniperSprinting = false; + if (player.HasComponent("SprintAbility")) { + if (controller->SniperSprintingCheck()) { + playerMovementSpeed *= (double)player["SprintAbility"]["StrengthOfEffect"]; + playerCrouchSpeed *= (double)player["SprintAbility"]["StrengthOfEffect"]; + sniperSprinting = true; + } + } if (player.HasComponent("Physics")) { ComponentWrapper cPhysics = player["Physics"]; @@ -114,6 +121,9 @@ void PlayerMovementSystem::updateMovementControllers(double dt) if (playerBoostAssaultEntity.Valid()) { accelerationSpeed *= (double)playerBoostAssaultEntity["BoostAssault"]["StrengthOfEffect"]; } + if (sniperSprinting) { + accelerationSpeed *= (double)player["SprintAbility"]["StrengthOfEffect"]; + } velocity += accelerationSpeed * wishDirection; ImGui::Text("velocity: (%f, %f, %f) |%f|", velocity.x, velocity.y, velocity.z, glm::length(velocity)); } From 3c9c95cff4d132ef43e23886b3455c4f0745bb95 Mon Sep 17 00:00:00 2001 From: viktorljung Date: Thu, 18 Feb 2016 16:34:18 +0100 Subject: [PATCH 025/130] Animation blending improved and Animation Override added --- assets | 2 +- include/Engine/Rendering/ModelJob.h | 9 + include/Engine/Rendering/Skeleton.h | 22 +- resources/Schema/Components/Animation.xml | 6 + resources/Schema/Components/Animation.xsd | 21 ++ resources/Schema/Entities/AnimationTests2.xml | 85 ++++- src/Engine/Rendering/AnimationSystem.cpp | 10 +- src/Engine/Rendering/Renderer.cpp | 1 + src/Engine/Rendering/Skeleton.cpp | 323 ++++++++---------- 9 files changed, 279 insertions(+), 200 deletions(-) diff --git a/assets b/assets index 4d36fdce..1e7adc74 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 4d36fdced7007a594a56b7371bb26861876889aa +Subproject commit 1e7adc749e02144615a20a82c847d3c8df46ee3d diff --git a/include/Engine/Rendering/ModelJob.h b/include/Engine/Rendering/ModelJob.h index ba801f60..773e002e 100644 --- a/include/Engine/Rendering/ModelJob.h +++ b/include/Engine/Rendering/ModelJob.h @@ -133,7 +133,16 @@ struct ModelJob : RenderJob } animationData.time = (double)animationComponent["Time" + std::to_string(i)]; animationData.weight = (double)animationComponent["Weight" + std::to_string(i)]; + + if((int)animationComponent["BlendType" + std::to_string(i)].Enum("Additive") == (int)animationComponent["BlendType" + std::to_string(i)]) { + animationData.blendType = Skeleton::BlendType::Additive; + } else if ((int)animationComponent["BlendType" + std::to_string(i)].Enum("Blend") == (int)animationComponent["BlendType" + std::to_string(i)]) { + animationData.blendType = Skeleton::BlendType::Blend; + } else if ((int)animationComponent["BlendType" + std::to_string(i)].Enum("Override") == (int)animationComponent["BlendType" + std::to_string(i)]) { + animationData.blendType = Skeleton::BlendType::Override; + } + animationData.level = (int)animationComponent["Level" + std::to_string(i)]; Animations.push_back(animationData); } } diff --git a/include/Engine/Rendering/Skeleton.h b/include/Engine/Rendering/Skeleton.h index 93f62a37..f064cc3c 100644 --- a/include/Engine/Rendering/Skeleton.h +++ b/include/Engine/Rendering/Skeleton.h @@ -68,18 +68,26 @@ public: std::map> JointAnimations; }; + enum class BlendType + { + Additive, + Blend, + Override, + }; struct AnimationData { const Animation* animation; + BlendType blendType; float time; + int level; float weight; }; - struct JointFrameTransform { - glm::vec3 Position = glm::vec3(0); - glm::quat Rotation = glm::quat(); - glm::vec3 Scale = glm::vec3(0); - float Weight; + struct JointFramePose { + BlendType Type; + int Level = 0; + glm::mat4 Pose = glm::mat4(0); + float Weight = 0.0f; }; struct AnimationOffset { @@ -119,8 +127,10 @@ public: glm::mat4 GetBoneTransform(bool noRootMotion, const Bone* bone, std::vector animations, glm::mat4 childMatrix); int GetKeyframe(const Animation& animation, double time); + private: - JointFrameTransform GetOffsetTransform(const Bone* bone, AnimationOffset animationOffset); + glm::mat4 GetOffsetTransform(const Bone* bone, AnimationOffset animationOffset); + glm::mat4 GetBonePose(const Bone* bone, const Animation* animation, double time, bool noRootMotion); std::map m_BonesByName; diff --git a/resources/Schema/Components/Animation.xml b/resources/Schema/Components/Animation.xml index ae42009d..6f49edb4 100644 --- a/resources/Schema/Components/Animation.xml +++ b/resources/Schema/Components/Animation.xml @@ -1,16 +1,22 @@ + + 0 1.0 0 0 true + + 0 1.0 0 0 true + + 0 1.0 0 0 diff --git a/resources/Schema/Components/Animation.xsd b/resources/Schema/Components/Animation.xsd index f39aac18..e765f8e8 100644 --- a/resources/Schema/Components/Animation.xsd +++ b/resources/Schema/Components/Animation.xsd @@ -3,20 +3,41 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/Schema/Entities/AnimationTests2.xml b/resources/Schema/Entities/AnimationTests2.xml index c36c5c02..8cc3f812 100644 --- a/resources/Schema/Entities/AnimationTests2.xml +++ b/resources/Schema/Entities/AnimationTests2.xml @@ -29,11 +29,14 @@ - Idle - 1.1429797894322036 + Run 1 + StrafeRight + 0.5 + 0.98334510030765165 + 0.5 + 0.97153983043137671 1 - 0.032904333143131348 0.093923612201312068 1 @@ -44,7 +47,20 @@ - + + + + + R_Arm_Weapon_Joint + + + Models/Weapons/Blue/AssaultWeaponBlue.mesh + + + + + + @@ -75,6 +91,7 @@ Models/Core/UnitPlane.mesh + @@ -85,42 +102,80 @@ - Idle - 1.1429797894322036 + Run 1 - 0.10000000149011612 - StrafeRigh + StrafeRight + 0.5 + 0.98334510030765165 0.5 - 0.67154243305829331 - 0.5 - 0.32167823998061529 + 0.89665639003541542 + 1 + ShootFastRifle + + + + 0.099759525382621339 1 AimRifle - + Models/Characters/Assault/AssaultAnimations.mesh - + + + + + R_Arm_Weapon_Joint + + + Models/Weapons/Blue/AssaultWeaponBlue.mesh + + + + + + + + + + AimRifle - 0.5 + 0.5 + Ru + 0.57926159055711501 Models/Characters/Assault/AssaultAnimations.mesh + true - + + + + + R_Arm_Weapon_Joint + + + Models/Weapons/Red/AssaultWeaponRed.mesh + true + + + + + + diff --git a/src/Engine/Rendering/AnimationSystem.cpp b/src/Engine/Rendering/AnimationSystem.cpp index 02d72409..e70c4f36 100644 --- a/src/Engine/Rendering/AnimationSystem.cpp +++ b/src/Engine/Rendering/AnimationSystem.cpp @@ -54,13 +54,19 @@ void AnimationSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& a e.Entity = entity; e.Name = (std::string)animationComponent["AnimationName" + std::to_string(i)]; m_EventBroker->Publish(e); - nextTime -= animation->Duration; + + while(nextTime > animation->Duration) { + nextTime -= animation->Duration; + } } else if (nextTime < 0) { Events::AnimationComplete e; e.Entity = entity; e.Name = (std::string)animationComponent["AnimationName" + std::to_string(i)]; m_EventBroker->Publish(e); - nextTime += animation->Duration; + + while (nextTime < 0) { + nextTime += animation->Duration; + } } } diff --git a/src/Engine/Rendering/Renderer.cpp b/src/Engine/Rendering/Renderer.cpp index 173ddb2b..85741be4 100644 --- a/src/Engine/Rendering/Renderer.cpp +++ b/src/Engine/Rendering/Renderer.cpp @@ -124,6 +124,7 @@ void Renderer::Draw(RenderFrame& frame) } m_DrawBloomPass->Draw(m_DrawFinalPass->BloomTexture()); + if (m_DebugTextureToDraw == 0) { m_DrawColorCorrectionPass->Draw(m_DrawFinalPass->SceneTexture(), m_DrawBloomPass->GaussianTexture(), m_DrawFinalPass->SceneTextureLowRes(), m_DrawFinalPass->BloomTextureLowRes(), frame.Gamma, frame.Exposure); } diff --git a/src/Engine/Rendering/Skeleton.cpp b/src/Engine/Rendering/Skeleton.cpp index 4e961a36..94656848 100644 --- a/src/Engine/Rendering/Skeleton.cpp +++ b/src/Engine/Rendering/Skeleton.cpp @@ -66,7 +66,7 @@ std::vector Skeleton::GetFrameBones(std::vector animat if (animations.size() <= 0 || animationOffset.animation == nullptr) { std::vector finalMatrices; for (auto& b : Bones) { - finalMatrices.push_back(glm::mat4(1));//b.second->OffsetMatrix); + finalMatrices.push_back(glm::mat4(1)); } return finalMatrices; } @@ -85,14 +85,15 @@ std::vector Skeleton::GetFrameBones(std::vector animat void Skeleton::AccumulateBoneTransforms(bool noRootMotion, std::vector animations, std::map& boneMatrices, const Bone* bone, glm::mat4 parentMatrix) { glm::mat4 boneMatrix; - std::vector JointTransforms; + + std::vector JointPoses; for (const AnimationData animationData : animations) { const Animation* animation = animationData.animation; const float time = animationData.time; - JointFrameTransform jointTransform; - jointTransform.Weight = animationData.weight;; + JointFramePose jointPose; + jointPose.Weight = animationData.weight;; if (animation->JointAnimations.find(bone->ID) != animation->JointAnimations.end()) { std::vector boneKeyFrames = animation->JointAnimations.at(bone->ID); @@ -121,31 +122,28 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, std::vector 1.0f || progress < 0.0f) { - LOG_INFO("Progress: %f", progress); progress = glm::clamp(progress, 0.0f, 1.0f); } Animation::Keyframe::BoneProperty currentBoneProperty = currentFrame.BoneProperties; Animation::Keyframe::BoneProperty nextBoneProperty = nextFrame.BoneProperties; - jointTransform.Position = currentBoneProperty.Position * (1.f - progress) + nextBoneProperty.Position * progress; - jointTransform.Rotation = glm::slerp(currentBoneProperty.Rotation, nextBoneProperty.Rotation, progress); - jointTransform.Scale = currentBoneProperty.Scale * (1.f - progress) + nextBoneProperty.Scale * progress; + glm::vec3 position = currentBoneProperty.Position * (1.f - progress) + nextBoneProperty.Position * progress; + glm::quat rotation = glm::slerp(currentBoneProperty.Rotation, nextBoneProperty.Rotation, progress); + glm::vec3 scale = currentBoneProperty.Scale * (1.f - progress) + nextBoneProperty.Scale * progress; // Flag for no root motion if (bone == RootBone && noRootMotion) { - jointTransform.Position.x = 0; - jointTransform.Position.z = 0; + position.x = 0; + position.z = 0; } - JointTransforms.push_back(jointTransform); + jointPose.Pose = (glm::translate(position) * glm::toMat4(rotation) * glm::scale(scale)); + JointPoses.push_back(jointPose); } else { // 1 keyframes for the current bone currentFrame = boneKeyFrames.at(0); - jointTransform.Position = currentFrame.BoneProperties.Position; - jointTransform.Rotation = currentFrame.BoneProperties.Rotation; - jointTransform.Scale = currentFrame.BoneProperties.Scale; - JointTransforms.push_back(jointTransform); - + jointPose.Pose = (glm::translate(currentFrame.BoneProperties.Position) * glm::toMat4(currentFrame.BoneProperties.Rotation) * glm::scale(currentFrame.BoneProperties.Scale)); + JointPoses.push_back(jointPose); } } else { // 0 keyframes for the current bone @@ -153,49 +151,41 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, std::vectorParent) { - boneMatrix = parentMatrix * glm::inverse(bone->OffsetMatrix) * bone->Parent->OffsetMatrix; + + glm::mat4 jointPose = (glm::inverse(bone->OffsetMatrix) * bone->Parent->OffsetMatrix); + + boneMatrix = parentMatrix * jointPose; boneMatrices[bone->ID] = boneMatrix * bone->OffsetMatrix; } else { boneMatrix = glm::inverse(bone->OffsetMatrix); boneMatrices[bone->ID] = parentMatrix; } - } else if (JointTransforms.size() == 1) { - boneMatrix = parentMatrix *(glm::translate(JointTransforms.at(0).Position) * glm::toMat4(JointTransforms.at(0).Rotation) * glm::scale(JointTransforms.at(0).Scale)); - boneMatrices[bone->ID] = boneMatrix * bone->OffsetMatrix; } else { - glm::vec3 finalPosInterp; - glm::quat finalRotInterp; - glm::vec3 finalScaleInterp; float totalWeight = 0; - for (JointFrameTransform jointTransform : JointTransforms) { - totalWeight += jointTransform.Weight; + for (JointFramePose jointFramePose : JointPoses) { + totalWeight += jointFramePose.Weight; } + glm::mat4 finalBlend = glm::mat4(0); - for (JointFrameTransform jointTransform : JointTransforms) { - if (jointTransform.Weight == 1.0f) { - finalPosInterp = jointTransform.Position; - finalRotInterp = jointTransform.Rotation; - finalScaleInterp = jointTransform.Scale; - break; + for (JointFramePose jointFramePose : JointPoses) { + if (jointFramePose.Weight == 1.0f) { + finalBlend = jointFramePose.Pose; } else { - finalPosInterp += jointTransform.Position * (jointTransform.Weight/totalWeight); - finalRotInterp *= glm::slerp(glm::quat(), jointTransform.Rotation, (jointTransform.Weight/totalWeight)); - finalScaleInterp += jointTransform.Scale * (jointTransform.Weight/totalWeight); + finalBlend += jointFramePose.Pose * (jointFramePose.Weight / totalWeight); } - } - boneMatrix = parentMatrix *(glm::translate(finalPosInterp) * glm::toMat4(finalRotInterp) * glm::scale(finalScaleInterp)); + + boneMatrix = parentMatrix * finalBlend; boneMatrices[bone->ID] = boneMatrix * bone->OffsetMatrix; } - - for (auto &child : bone->Children) { AccumulateBoneTransforms(noRootMotion, animations, boneMatrices, child, boneMatrix); } @@ -204,83 +194,25 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, std::vector animations, AnimationOffset animationOffset, std::map& boneMatrices, const Bone* bone, glm::mat4 parentMatrix) { glm::mat4 boneMatrix; - - std::vector JointTransforms; + std::vector JointPoses; for (const AnimationData animationData : animations) { - const Animation* animation = animationData.animation; - const float time = animationData.time; - - JointFrameTransform jointTransform; - jointTransform.Weight = animationData.weight;; - - if (animation->JointAnimations.find(bone->ID) != animation->JointAnimations.end()) { - std::vector boneKeyFrames = animation->JointAnimations.at(bone->ID); - - Animation::Keyframe currentFrame; - Animation::Keyframe nextFrame; - - if (boneKeyFrames.size() > 1) { // 2+ keyframes for the current bone - for (int index = boneKeyFrames.size()-1; index >= 0; index--) { // find the bone keyframes that surrounds the current frame - if (time >= boneKeyFrames.at(index).Time) { - currentFrame = boneKeyFrames.at(index); - nextFrame = boneKeyFrames.at((index + 1) % boneKeyFrames.size()); - break; - } - } - - float progress; - - if (nextFrame.Index == 0) { - nextFrame = currentFrame; - progress = (time - currentFrame.Time) / (animation->Duration - currentFrame.Time); - } else { - progress = (time - currentFrame.Time) / (nextFrame.Time - currentFrame.Time); - - } - - - if (progress > 1.0f || progress < 0.0f) { - LOG_INFO("Progress: %f", progress); - progress = glm::clamp(progress, 0.0f, 1.0f); - } - Animation::Keyframe::BoneProperty currentBoneProperty = currentFrame.BoneProperties; - Animation::Keyframe::BoneProperty nextBoneProperty = nextFrame.BoneProperties; - - jointTransform.Position = currentBoneProperty.Position * (1.f - progress) + nextBoneProperty.Position * progress; - jointTransform.Rotation = glm::slerp(currentBoneProperty.Rotation, nextBoneProperty.Rotation, progress); - jointTransform.Scale = currentBoneProperty.Scale * (1.f - progress) + nextBoneProperty.Scale * progress; - - // Flag for no root motion - if (bone == RootBone && noRootMotion) { - jointTransform.Position.x = 0; - jointTransform.Position.z = 0; - } - - JointTransforms.push_back(jointTransform); - - } else { // 1 keyframes for the current bone - currentFrame = boneKeyFrames.at(0); - jointTransform.Position = currentFrame.BoneProperties.Position; - jointTransform.Rotation = currentFrame.BoneProperties.Rotation; - jointTransform.Scale = currentFrame.BoneProperties.Scale; - JointTransforms.push_back(jointTransform); - - } - } else { // 0 keyframes for the current bone - - } - + if (animationData.animation->JointAnimations.find(bone->ID) != animationData.animation->JointAnimations.end()) { // Does the bone have any keyframes in this animation? + JointFramePose jointPose; + jointPose.Weight = animationData.weight; + jointPose.Type = animationData.blendType; + jointPose.Level = animationData.level; + jointPose.Pose = GetBonePose(bone, animationData.animation, animationData.time, noRootMotion); + JointPoses.push_back(jointPose); + } } - if (JointTransforms.size() == 0) { + if (JointPoses.size() == 0) { // No keyframes for the current bone if (bone->Parent) { - glm::mat4 jointPose = (glm::inverse(bone->OffsetMatrix) * bone->Parent->OffsetMatrix); glm::mat4 boneTransform = AdditiveBlend(bone, animationOffset, jointPose); - - boneMatrix = parentMatrix * boneTransform; + boneMatrix = parentMatrix * boneTransform; boneMatrices[bone->ID] = boneMatrix * bone->OffsetMatrix; } else { boneMatrix = glm::inverse(bone->OffsetMatrix); @@ -288,33 +220,31 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, std::vector maxLevel ? jointPose.Level : maxLevel; } - for (JointFrameTransform jointTransform : JointTransforms) { - if (jointTransform.Weight == 1.0f) { - jointFinalTransform.Position = jointTransform.Position; - jointFinalTransform.Rotation = jointTransform.Rotation; - jointFinalTransform.Scale = jointTransform.Scale; - break; - } else { - jointFinalTransform.Position += jointTransform.Position * (jointTransform.Weight/totalWeight); - jointFinalTransform.Rotation *= glm::slerp(glm::quat(), jointTransform.Rotation, (jointTransform.Weight/totalWeight)); - jointFinalTransform.Scale += jointTransform.Scale * (jointTransform.Weight/totalWeight); + for (JointFramePose jointPose : JointPoses) { + if (jointPose.Type == BlendType::Override) { + finalOverride += jointPose.Pose * jointPose.Weight; //Blend Overrides then apply to final blend + } else if(jointPose.Type == BlendType::Blend) { + finalBlend += jointPose.Pose * jointPose.Weight; + } else if (jointPose.Type == BlendType::Additive) { + //Soon } - } + if(finalOverride != glm::mat4(0)) { + finalBlend = finalOverride; + } - glm::mat4 jointPose = (glm::translate(jointFinalTransform.Position) * glm::toMat4(jointFinalTransform.Rotation) * glm::scale(jointFinalTransform.Scale)); - glm::mat4 boneTransform = AdditiveBlend(bone, animationOffset, jointPose); - + glm::mat4 boneTransform = AdditiveBlend(bone, animationOffset, finalBlend); boneMatrix = parentMatrix * boneTransform; boneMatrices[bone->ID] = boneMatrix * bone->OffsetMatrix; } @@ -329,18 +259,14 @@ glm::mat4 Skeleton::AdditiveBlend(const Bone* bone, AnimationOffset animationOff { AnimationOffset refOffset = animationOffset; refOffset.time = 0.5f; // reference pose is at 0.5s for now - JointFrameTransform refOffsetTransform = GetOffsetTransform(bone, refOffset); - JointFrameTransform srcOffsetTransform = GetOffsetTransform(bone, animationOffset); - - glm::mat4 srcPose = (glm::translate(srcOffsetTransform.Position) * glm::toMat4(srcOffsetTransform.Rotation) * glm::scale(srcOffsetTransform.Scale)); - glm::mat4 refPose = (glm::translate(refOffsetTransform.Position) * glm::toMat4(refOffsetTransform.Rotation) * glm::scale(refOffsetTransform.Scale)); - + glm::mat4 refPose = GetOffsetTransform(bone, refOffset); + glm::mat4 srcPose = GetOffsetTransform(bone, animationOffset); glm::mat4 differencePose = srcPose * glm::inverse(refPose); glm::mat4 finalPose = differencePose * targetPose; return finalPose; } -Skeleton::JointFrameTransform Skeleton::GetOffsetTransform(const Bone* bone, AnimationOffset animationOffset) +glm::mat4 Skeleton::GetOffsetTransform(const Bone* bone, AnimationOffset animationOffset) { const Animation* animation = animationOffset.animation; float time = animationOffset.time; @@ -371,7 +297,6 @@ Skeleton::JointFrameTransform Skeleton::GetOffsetTransform(const Bone* bone, Ani progress = (time - currentFrame.Time) / (animation->Duration - currentFrame.Time); } else { progress = (time - currentFrame.Time) / (nextFrame.Time - currentFrame.Time); - } progress = glm::clamp(progress, 0.0f, 1.0f); @@ -392,13 +317,70 @@ Skeleton::JointFrameTransform Skeleton::GetOffsetTransform(const Bone* bone, Ani } } + return (glm::translate(position) * glm::toMat4(rotation) * glm::scale(scale));; +} - JointFrameTransform jointTransform; - jointTransform.Position = position; - jointTransform.Rotation = rotation; - jointTransform.Scale = scale; - return jointTransform; +glm::mat4 Skeleton::GetBonePose(const Bone* bone, const Animation* animation, double time, bool noRootMotion) +{ + glm::mat4 boneMatrix; + + std::vector JointPoses; + + + if (animation->JointAnimations.find(bone->ID) != animation->JointAnimations.end()) { + std::vector boneKeyFrames = animation->JointAnimations.at(bone->ID); + + Animation::Keyframe currentFrame; + Animation::Keyframe nextFrame; + + if (boneKeyFrames.size() > 1) { // 2+ keyframes for the current bone + for (int index = boneKeyFrames.size()-1; index >= 0; index--) { // find the bone keyframes that surrounds the current frame + if (time >= boneKeyFrames.at(index).Time) { + currentFrame = boneKeyFrames.at(index); + nextFrame = boneKeyFrames.at((index + 1) % boneKeyFrames.size()); + break; + } + } + + float progress; + + if (nextFrame.Index == 0) { + nextFrame = currentFrame; + progress = (time - currentFrame.Time) / (animation->Duration - currentFrame.Time); + } else { + progress = (time - currentFrame.Time) / (nextFrame.Time - currentFrame.Time); + + } + + + if (progress > 1.0f || progress < 0.0f) { + progress = glm::clamp(progress, 0.0f, 1.0f); + } + Animation::Keyframe::BoneProperty currentBoneProperty = currentFrame.BoneProperties; + Animation::Keyframe::BoneProperty nextBoneProperty = nextFrame.BoneProperties; + + glm::vec3 position = currentBoneProperty.Position * (1.f - progress) + nextBoneProperty.Position * progress; + glm::quat rotation = glm::slerp(currentBoneProperty.Rotation, nextBoneProperty.Rotation, progress); + glm::vec3 scale = currentBoneProperty.Scale * (1.f - progress) + nextBoneProperty.Scale * progress; + + // Flag for no root motion + if (bone == RootBone && noRootMotion) { + position.x = 0; + position.z = 0; + } + + boneMatrix = (glm::translate(position) * glm::toMat4(rotation) * glm::scale(scale)); + + } else { // 1 keyframes for the current bone + currentFrame = boneKeyFrames.at(0); + boneMatrix = (glm::translate(currentFrame.BoneProperties.Position) * glm::toMat4(currentFrame.BoneProperties.Rotation) * glm::scale(currentFrame.BoneProperties.Scale)); + } + } //else { // 0 keyframes for the current bone + + // } + + return boneMatrix; } glm::mat4 Skeleton::GetBoneTransform(const Bone* bone, const Animation* animation, float time, glm::mat4 childMatrix) @@ -467,14 +449,14 @@ glm::mat4 Skeleton::GetBoneTransform(bool noRootMotion, const Bone* bone, std::v { glm::mat4 boneMatrix; - std::vector JointTransforms; + std::vector JointPoses; for (const AnimationData animationData : animations) { const Animation* animation = animationData.animation; const float time = animationData.time; - JointFrameTransform jointTransform; - jointTransform.Weight = animationData.weight;; + JointFramePose jointPose; + jointPose.Weight = animationData.weight;; if (animation->JointAnimations.find(bone->ID) != animation->JointAnimations.end()) { std::vector boneKeyFrames = animation->JointAnimations.at(bone->ID); @@ -503,31 +485,28 @@ glm::mat4 Skeleton::GetBoneTransform(bool noRootMotion, const Bone* bone, std::v if (progress > 1.0f || progress < 0.0f) { - LOG_INFO("Progress: %f", progress); progress = glm::clamp(progress, 0.0f, 1.0f); } Animation::Keyframe::BoneProperty currentBoneProperty = currentFrame.BoneProperties; Animation::Keyframe::BoneProperty nextBoneProperty = nextFrame.BoneProperties; - jointTransform.Position = currentBoneProperty.Position * (1.f - progress) + nextBoneProperty.Position * progress; - jointTransform.Rotation = glm::slerp(currentBoneProperty.Rotation, nextBoneProperty.Rotation, progress); - jointTransform.Scale = currentBoneProperty.Scale * (1.f - progress) + nextBoneProperty.Scale * progress; + glm::vec3 position = currentBoneProperty.Position * (1.f - progress) + nextBoneProperty.Position * progress; + glm::quat rotation = glm::slerp(currentBoneProperty.Rotation, nextBoneProperty.Rotation, progress); + glm::vec3 scale = currentBoneProperty.Scale * (1.f - progress) + nextBoneProperty.Scale * progress; // Flag for no root motion if (bone == RootBone && noRootMotion) { - jointTransform.Position.x = 0; - jointTransform.Position.z = 0; + position.x = 0; + position.z = 0; } - JointTransforms.push_back(jointTransform); + jointPose.Pose = (glm::translate(position) * glm::toMat4(rotation) * glm::scale(scale)); + JointPoses.push_back(jointPose); } else { // 1 keyframes for the current bone currentFrame = boneKeyFrames.at(0); - jointTransform.Position = currentFrame.BoneProperties.Position; - jointTransform.Rotation = currentFrame.BoneProperties.Rotation; - jointTransform.Scale = currentFrame.BoneProperties.Scale; - JointTransforms.push_back(jointTransform); - + jointPose.Pose = (glm::translate(currentFrame.BoneProperties.Position) * glm::toMat4(currentFrame.BoneProperties.Rotation) * glm::scale(currentFrame.BoneProperties.Scale)); + JointPoses.push_back(jointPose); } } else { // 0 keyframes for the current bone @@ -536,7 +515,7 @@ glm::mat4 Skeleton::GetBoneTransform(bool noRootMotion, const Bone* bone, std::v } - if (JointTransforms.size() == 0) { + if (JointPoses.size() == 0) { if (bone->Parent) { glm::mat4 jointPose = (glm::inverse(bone->OffsetMatrix) * bone->Parent->OffsetMatrix); @@ -548,33 +527,24 @@ glm::mat4 Skeleton::GetBoneTransform(bool noRootMotion, const Bone* bone, std::v } } else { - JointFrameTransform jointFinalTransform; - float totalWeight = 0; - for (JointFrameTransform jointTransform : JointTransforms) { - totalWeight += jointTransform.Weight; + for (JointFramePose jointFramePose : JointPoses) { + totalWeight += jointFramePose.Weight; } + glm::mat4 finalBlend = glm::mat4(0); - for (JointFrameTransform jointTransform : JointTransforms) { - if (jointTransform.Weight == 1.0f) { - jointFinalTransform.Position = jointTransform.Position; - jointFinalTransform.Rotation = jointTransform.Rotation; - jointFinalTransform.Scale = jointTransform.Scale; - break; + for (JointFramePose jointFramePose : JointPoses) { + if (jointFramePose.Weight == 1.0f) { + finalBlend = jointFramePose.Pose; } else { - jointFinalTransform.Position += jointTransform.Position * (jointTransform.Weight/totalWeight); - jointFinalTransform.Rotation *= glm::slerp(glm::quat(), jointTransform.Rotation, (jointTransform.Weight/totalWeight)); - jointFinalTransform.Scale += jointTransform.Scale * (jointTransform.Weight/totalWeight); + finalBlend += jointFramePose.Pose * (jointFramePose.Weight / totalWeight); } - } - glm::mat4 jointPose = (glm::translate(jointFinalTransform.Position) * glm::toMat4(jointFinalTransform.Rotation) * glm::scale(jointFinalTransform.Scale)); - glm::mat4 boneTransform = AdditiveBlend(bone, animationOffset, jointPose); - + glm::mat4 boneTransform = AdditiveBlend(bone, animationOffset, finalBlend); boneMatrix = boneTransform * childMatrix; } @@ -589,7 +559,7 @@ glm::mat4 Skeleton::GetBoneTransform(bool noRootMotion, const Bone* bone, std::v glm::mat4 Skeleton::GetBoneTransform(bool noRootMotion, const Bone* bone, std::vector animations, glm::mat4 childMatrix) { glm::mat4 boneMatrix; - std::vector JointTransforms; + /* std::vector JointTransforms; for (const AnimationData animationData : animations) { const Animation* animation = animationData.animation; @@ -625,7 +595,6 @@ glm::mat4 Skeleton::GetBoneTransform(bool noRootMotion, const Bone* bone, std::v if (progress > 1.0f || progress < 0.0f) { - LOG_INFO("Progress: %f", progress); progress = glm::clamp(progress, 0.0f, 1.0f); } Animation::Keyframe::BoneProperty currentBoneProperty = currentFrame.BoneProperties; @@ -688,18 +657,20 @@ glm::mat4 Skeleton::GetBoneTransform(bool noRootMotion, const Bone* bone, std::v finalRotInterp *= glm::slerp(glm::quat(), jointTransform.Rotation, (jointTransform.Weight/totalWeight)); finalScaleInterp += jointTransform.Scale * (jointTransform.Weight/totalWeight); } + } boneMatrix = (glm::translate(finalPosInterp) * glm::toMat4(finalRotInterp) * glm::scale(finalScaleInterp)) * childMatrix; } - if (bone->Parent != nullptr) { return GetBoneTransform(noRootMotion, bone->Parent, animations, boneMatrix); } else { return boneMatrix; - } + }*/ + +return boneMatrix; } int Skeleton::GetBoneID(std::string name) From bf376f54b627973f7950ae968336ce43273fc34b Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Thu, 18 Feb 2016 20:48:39 +0100 Subject: [PATCH 026/130] WIP I think this is now finding the different segments of the cascade --- include/Engine/Rendering/ShadowPass.h | 21 +- resources/Shaders/ForwardPlus.frag.glsl | 4 +- src/Engine/Editor/EditorSystem.cpp | 4 +- src/Engine/Rendering/ShadowPass.cpp | 311 ++++++++++++++++-------- 4 files changed, 230 insertions(+), 110 deletions(-) diff --git a/include/Engine/Rendering/ShadowPass.h b/include/Engine/Rendering/ShadowPass.h index 685432c8..306ae8e0 100644 --- a/include/Engine/Rendering/ShadowPass.h +++ b/include/Engine/Rendering/ShadowPass.h @@ -33,9 +33,7 @@ public: void ClearBuffer(); void Draw(RenderScene& scene); - - - GLuint DepthMap() const { return m_DepthMap; } + GLuint DepthMap() const { return m_DepthMap[m_ShadowLevel]; } glm::mat4 lightSpaceMatrix() const { return m_LightSpaceMatrix; } glm::mat4 lightP() const { return m_LightProjection; } glm::mat4 lightV() const { return m_LightView; } @@ -44,18 +42,20 @@ public: private: - void CalculateFrustum(RenderScene & scene, std::shared_ptr directionalLightJob); + glm::mat4 CalculateFrustum(RenderScene & scene, std::shared_ptr directionalLightJob, glm::mat4& p, glm::mat4& v, ShadowCamera shad_cam); glm::vec3 LightDirectionToPoint(glm::vec4 direction); std::array UpdateFrustumPoints(Camera* cam, glm::vec3 center, glm::vec3 view_dir); void UpdateSplitDist(std::array shadow_cams, float far_distance, float near_distance); + void InitializeLightCameras(); + glm::mat4 ApplyCropMatrix(ShadowCamera& shadow_cam, glm::mat4 m, glm::mat4 v); + glm::mat4 FindNewFrustum(ShadowCamera shadow_cam); EventBroker* m_EventBroker; const IRenderer* m_Renderer; - GLuint m_DepthMap; - - FrameBuffer m_DepthBuffer; + std::array m_DepthMap; + std::array m_DepthBuffer; ShaderProgram* m_ShadowProgram; @@ -69,15 +69,16 @@ private: glm::mat4 m_LightView; glm::mat4 m_LightSpaceMatrix; - GLuint resolutionSizeWidth = 1024 * 8; - GLuint resolutionSizeHeigth = 1024 * 8; + GLuint resolutionSizeWidth = 1024 * 2; + GLuint resolutionSizeHeigth = 1024 * 2; bool m_ShadowOn = true; + int m_ShadowLevel = 0; int m_CurrentNrOfSplits = 3; float m_SplitWeight = 0.75f; - std::array shadCams; + std::array m_shadCams; }; #endif \ No newline at end of file diff --git a/resources/Shaders/ForwardPlus.frag.glsl b/resources/Shaders/ForwardPlus.frag.glsl index 205f1c5d..1f3ba711 100644 --- a/resources/Shaders/ForwardPlus.frag.glsl +++ b/resources/Shaders/ForwardPlus.frag.glsl @@ -143,9 +143,9 @@ float random(vec3 seed, int i) float CalcShadowValue(vec4 positionLightSpace, vec3 normal, vec3 lightDir, sampler2DShadow depthTexture) { - float bias = 0.005; + //float bias = 0.005; //float bias = max(0.05 * (1.0 - dot(normal, lightDir)), 0.005); - //float bias = 0.005 * tan(acos(clamp(dot(normal, -lightDir), 0.0, 1.0))); + float bias = 0.005 * tan(acos(clamp(dot(normal, -lightDir), 0.0, 1.0))); vec3 projCoords = vec3(positionLightSpace.xy, positionLightSpace.z + bias) / positionLightSpace.w; projCoords = projCoords * 0.5 + 0.5; diff --git a/src/Engine/Editor/EditorSystem.cpp b/src/Engine/Editor/EditorSystem.cpp index ccbc1b48..96b48874 100644 --- a/src/Engine/Editor/EditorSystem.cpp +++ b/src/Engine/Editor/EditorSystem.cpp @@ -17,7 +17,9 @@ EditorSystem::EditorSystem(World* world, EventBroker* eventBroker, IRenderer* re m_EditorCamera = importEntity(EntityWrapper(m_EditorWorld, EntityID_Invalid), "Schema/Entities/Empty.xml"); m_ActualCamera = m_EditorCamera; m_EditorWorld->AttachComponent(m_EditorCamera.ID, "Transform"); - m_EditorWorld->AttachComponent(m_EditorCamera.ID, "Camera"); + auto cCamera = m_EditorWorld->AttachComponent(m_EditorCamera.ID, "Camera"); + (double&)cCamera["FarClip"] = 30.0; + m_EditorCameraInputController = new EditorCameraInputController(m_EventBroker, -1); m_EditorGUI = new EditorGUI(m_World, m_EventBroker); diff --git a/src/Engine/Rendering/ShadowPass.cpp b/src/Engine/Rendering/ShadowPass.cpp index ca7b59f0..7be01b5b 100644 --- a/src/Engine/Rendering/ShadowPass.cpp +++ b/src/Engine/Rendering/ShadowPass.cpp @@ -11,7 +11,7 @@ ShadowPass::ShadowPass(IRenderer * renderer) ShadowPass::~ShadowPass() { - + // m_shadCams } // Compute the 8 corner points of the current view frustum @@ -25,28 +25,28 @@ std::array ShadowPass::UpdateFrustumPoints(Camera* cam, glm::vec3 up = glm::normalize(glm::cross(right, view_dir)); - float near_height = tan(cam->FOV() / 2.0f) * cam->NearClip(); + float near_height = tan(cam->FOV() / 2.f) * cam->NearClip(); float near_width = near_height * cam->AspectRatio(); - float far_height = tan(cam->FOV() / 2.0f) * cam->FarClip(); + float far_height = tan(cam->FOV() / 2.f) * cam->FarClip(); float far_width = far_height * cam->AspectRatio(); std::array frustumPoints; - frustumPoints[0] = nearCenter - up*near_height - right*near_width; - frustumPoints[1] = nearCenter + up*near_height - right*near_width; - frustumPoints[2] = nearCenter + up*near_height + right*near_width; - frustumPoints[3] = nearCenter - up*near_height + right*near_width; - - frustumPoints[4] = farCenter - up*far_height - right*far_width; - frustumPoints[5] = farCenter + up*far_height - right*far_width; - frustumPoints[6] = farCenter + up*far_height + right*far_width; - frustumPoints[7] = farCenter - up*far_height + right*far_width; + frustumPoints[0] = nearCenter - up * near_height - right * near_width; + frustumPoints[1] = nearCenter + up * near_height - right * near_width; + frustumPoints[2] = nearCenter + up * near_height + right * near_width; + frustumPoints[3] = nearCenter - up * near_height + right * near_width; + + frustumPoints[4] = farCenter - up * far_height - right * far_width; + frustumPoints[5] = farCenter + up * far_height - right * far_width; + frustumPoints[6] = farCenter + up * far_height + right * far_width; + frustumPoints[7] = farCenter - up * far_height + right * far_width; return frustumPoints; } // UpdateSplitDist computes the near and far distances for every frustum slice // in camera eye space - that is, at what distance does a slice start and end -void ShadowPass::UpdateSplitDist(std::array shadow_cams, float far_distance, float near_distance) +void ShadowPass::UpdateSplitDist(std::array shadow_cams, float near_distance, float far_distance) { float lambda = m_SplitWeight; float ratio = far_distance / near_distance; @@ -63,66 +63,165 @@ void ShadowPass::UpdateSplitDist(std::array shadow_cam shadow_cams[m_CurrentNrOfSplits - 1].camera->SetFarClip(far_distance); } -float applyCropMatrix() +glm::mat4 ShadowPass::FindNewFrustum(ShadowCamera shadow_cam) { + float maxX = -1000.0f; + float maxY = -1000.0f; + float maxZ; + float minX = 1000.0f; + float minY = 1000.0f; + float minZ; + glm::vec4 transf = glm::vec4(shadow_cam.frustumCorners[0], 1.f); + + //if (transf.x > maxX) maxX = transf.x; + //if (transf.x < minX) minX = transf.x; + //if (transf.y > maxY) maxY = transf.y; + //if (transf.y < minY) minY = transf.y; + + for (int i = 0; i < 8; i++) + { + transf = glm::vec4(shadow_cam.frustumCorners[i], 1.f); + + transf.x /= transf.w; + transf.y /= transf.w; + + if (transf.x > maxX) maxX = transf.x; + if (transf.x < minX) minX = transf.x; + if (transf.y > maxY) maxY = transf.y; + if (transf.y < minY) minY = transf.y; + } + + glm::mat4 p = glm::ortho(minX, maxX, minY, maxY, m_NearFarPlane[Near], m_NearFarPlane[Far]); + + return p; } -// GLM wants a point for glm::lookAt, brute out a point that is on the light direction's tangent. -glm::vec3 ShadowPass::LightDirectionToPoint(glm::vec4 direction) +glm::mat4 ShadowPass::ApplyCropMatrix(ShadowCamera& shadow_cam, glm::mat4 m, glm::mat4 v) { - return -glm::normalize(glm::vec3(direction)); + glm::mat4 shad_modelview; + glm::mat4 shad_proj; + glm::mat4 shad_crop; + glm::mat4 shad_mvp; + float maxX = -1000.0f; + float maxY = -1000.0f; + float maxZ; + float minX = 1000.0f; + float minY = 1000.0f; + float minZ; + + glm::mat4 nv_mvp; + glm::vec4 transf; + + shad_modelview = m * v; + nv_mvp = shad_modelview; + + transf = nv_mvp * glm::vec4(shadow_cam.frustumCorners[0], 1.f); + minZ = transf.z; + maxZ = transf.z; + + for (int i = 1; i < 8; i++) { + transf = nv_mvp * glm::vec4(shadow_cam.frustumCorners[i], 1.f); + if (transf.z > maxZ) { + maxZ = transf.z; + } + if (transf.z < minZ) { + minZ = transf.z; + } + } + + // make sure all relevant shadow casters are included here + + shad_proj = glm::ortho(-1.f, 1.f, -1.f, 1.f, m_NearFarPlane[0], m_NearFarPlane[1]); + + //return shad_proj; + + shad_mvp = shad_proj * shad_modelview; + + nv_mvp = shad_mvp; + + for (int i = 0; i < 8; i++) + { + transf = nv_mvp * glm::vec4(shadow_cam.frustumCorners[i], 1.0f); + + transf.x /= transf.w; + transf.y /= transf.w; + + if (transf.x > maxX) maxX = transf.x; + if (transf.x < minX) minX = transf.x; + if (transf.y > maxY) maxY = transf.y; + if (transf.y < minY) minY = transf.y; + } + + float scaleX = 2.0f / (maxX - minX); + float scaleY = 2.0f / (maxY - minY); + float offsetX = -0.5f*(maxX + minX)*scaleX; + float offsetY = -0.5f*(maxY + minY)*scaleY; + + nv_mvp = glm::mat4(); + nv_mvp[0][0] = scaleX; + nv_mvp[1][1] = scaleY; + nv_mvp[0][3] = offsetX; + nv_mvp[1][3] = offsetY; + glm::transpose(nv_mvp); + + shad_crop = nv_mvp; + shad_crop *= shad_proj; + + //return nv_mvp; + //return shad_crop; + return glm::mat4(); } -void ShadowPass::CalculateFrustum(RenderScene & scene, std::shared_ptr directionalLightJob) +void MakeShadowMap(glm::mat4 m, glm::mat4 v, glm::mat4 p, glm::vec3 light_dir) { - //m_LightView = glm::lookAt(LightDirectionToPoint(directionalLightJob->Direction), glm::vec3(0.f, 0.f, 0.f), glm::vec3(0.f, 1.f, 0.f)); + //float shad_modelview[16]; - m_LightProjection = glm::ortho(m_LRBT[Left], m_LRBT[Right], m_LRBT[Bottom], m_LRBT[Top], m_NearFarPlane[Near], m_NearFarPlane[Far]); - - glm::vec3 LightPoint = LightDirectionToPoint(directionalLightJob->Direction); + glDisable(GL_TEXTURE_2D); - float CameraDistance = scene.Camera->FarClip() - scene.Camera->NearClip(); - float CameraPercentiles[3] = { 0.f, CameraDistance * 0.2f, CameraDistance * 0.65f }; + glm::mat4 viewMatrix = glm::lookAt(glm::vec3(0.f), light_dir, glm::vec3(-1.f, 0.f, 0.f)); - - glm::vec3 point = scene.Camera->Position() + (scene.Camera->Forward() * 30.f); - - m_LightView = glm::lookAt(LightPoint + point, point, glm::vec3(0.f, 1.f, 0.f)); - m_LightSpaceMatrix = m_LightProjection * m_LightView; - //scene.Camera-> + + + + + + + glEnable(GL_TEXTURE_2D); +} + +glm::mat4 ShadowPass::CalculateFrustum(RenderScene & scene, std::shared_ptr directionalLightJob, glm::mat4& p, glm::mat4& v, ShadowCamera shad_cam) +{ + p = glm::ortho(m_LRBT[Left], m_LRBT[Right], m_LRBT[Bottom], m_LRBT[Top], m_NearFarPlane[Near], m_NearFarPlane[Far]); + v = glm::lookAt(glm::vec3(0.f) + shad_cam.camera->Position(), glm::vec3(directionalLightJob->Direction) + shad_cam.camera->Position(), glm::vec3(-1.f, 0.f, 0.f)); + + return p * v; } void ShadowPass::InitializeFrameBuffers() { - -// glGenRenderbuffers(1, &m_DepthFBO); -// glBindRenderbuffer(GL_RENDERBUFFER, m_DepthFBO); -// glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height); - // Depth texture - glGenTextures(1, &m_DepthMap); - glBindTexture(GL_TEXTURE_2D, m_DepthMap); - glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, resolutionSizeWidth, resolutionSizeHeigth, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr); - //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height, 0, GL_RGB, GL_FLOAT, 0); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE); - glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, glm::vec4(1.f).data); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); - //glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY); + glGenTextures(m_CurrentNrOfSplits, m_DepthMap.data()); + for (int i = 0; i < m_CurrentNrOfSplits; i++) { + glBindTexture(GL_TEXTURE_2D, m_DepthMap[i]); + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, resolutionSizeWidth / (1 + i), resolutionSizeHeigth + (1 + i), 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE); + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, glm::vec4(1.f).data); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); + //glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY); - m_DepthBuffer.AddResource(std::shared_ptr(new Texture2D(&m_DepthMap, GL_DEPTH_ATTACHMENT))); - //m_DepthBuffer.AddResource(std::shared_ptr(new Texture2D(&m_DepthMap, GL_COLOR_ATTACHMENT0))); - m_DepthBuffer.Generate(); + m_DepthBuffer[i].AddResource(std::shared_ptr(new Texture2D(&m_DepthMap[i], GL_DEPTH_ATTACHMENT))); + m_DepthBuffer[i].Generate(); + } GLERROR("depthMap failed"); - } void ShadowPass::InitializeShaderPrograms() @@ -135,74 +234,92 @@ void ShadowPass::InitializeShaderPrograms() m_ShadowProgram->Link(); } +void ShadowPass::InitializeLightCameras() +{ + //for (int i = 0; i < MAX_SPLITS; i++) { + // m_shadCams[i].camera = new Camera(1.f, ); + // Camera. + //} +} + void ShadowPass::ClearBuffer() { - m_DepthBuffer.Bind(); - glClearColor(0.f, 0.f, 0.f, 0.f); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - m_DepthBuffer.Unbind(); + for (int i = 0; i < m_CurrentNrOfSplits; i++) { + m_DepthBuffer[i].Bind(); + glClearColor(0.f, 0.f, 0.f, 0.f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + m_DepthBuffer[i].Unbind(); + } } void ShadowPass::Draw(RenderScene & scene) { - ShadowPassState* state = new ShadowPassState(m_DepthBuffer.GetHandle()); + ImGui::DragFloat4("ShadowMapCam", m_LRBT, 1.f, -1000.f, 1000.f); + ImGui::DragFloat2("ShadowMapNearFar", m_NearFarPlane, 1.f, -1000.f, 1000.f); + ImGui::Checkbox("EnableShadow", &m_ShadowOn); + ImGui::DragInt("ShadowLevel", &m_ShadowLevel, 0.05f, 0, m_CurrentNrOfSplits - 1); - GLuint shaderHandle = m_ShadowProgram->GetHandle(); - m_ShadowProgram->Bind(); + for (int i = 0; i < m_CurrentNrOfSplits; i++) { + m_shadCams[i].camera = new Camera(*scene.Camera); + //m_shadCams[i].frustumCorners = tempPoints; + } - glViewport(0, 0, resolutionSizeWidth, resolutionSizeHeigth); + UpdateSplitDist(m_shadCams, scene.Camera->NearClip(), scene.Camera->FarClip()); + + for (int i = 0; i < m_CurrentNrOfSplits; i++) { + m_shadCams[i].frustumCorners = UpdateFrustumPoints(m_shadCams[i].camera, m_shadCams[i].camera->Position(), m_shadCams[i].camera->Forward()); - glCullFace(GL_FRONT); - //state->Disable(GL_CULL_FACE); + ShadowPassState* state = new ShadowPassState(m_DepthBuffer[i].GetHandle()); - ImGui::DragFloat4("ShadowMapCam", m_LRBT, 1.f, -1000.f, 1000.f); - ImGui::DragFloat2("ShadowMapNearFar", m_NearFarPlane, 1.f, -1000.f, 1000.f); - ImGui::Checkbox("EnableShadow", &m_ShadowOn); + GLuint shaderHandle = m_ShadowProgram->GetHandle(); + m_ShadowProgram->Bind(); - if (m_ShadowOn == true) - { - for (auto &job : scene.DirectionalLightJobs) { - auto directionalLightJob = std::dynamic_pointer_cast(job); - - if(directionalLightJob) { - CalculateFrustum(scene, directionalLightJob); + glViewport(0, 0, resolutionSizeWidth / (1 + i), resolutionSizeHeigth); + glDisable(GL_TEXTURE_2D); + glCullFace(GL_FRONT); + //state->Disable(GL_CULL_FACE); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_LightProjection)); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_LightView)); + //m_LightProjection = FindNewFrustum(m_shadCams[0], m_LightProjection, m_LightProjection); - GLERROR("ShadowLight ERROR"); + if (m_ShadowOn == true) + { + for (auto &job : scene.DirectionalLightJobs) { + auto directionalLightJob = std::dynamic_pointer_cast(job); - for (auto &objectJob : scene.OpaqueObjects) { - auto modelJob = std::dynamic_pointer_cast(objectJob); - - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); + if (directionalLightJob) { + m_LightSpaceMatrix = CalculateFrustum(scene, directionalLightJob, m_LightProjection, m_LightView, m_shadCams[i]); + m_LightProjection = FindNewFrustum(m_shadCams[i]); - glBindVertexArray(modelJob->Model->VAO); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); - glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int))); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_LightProjection)); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_LightView)); - GLERROR("Shadow Draw ERROR"); + GLERROR("ShadowLight ERROR"); - } - - } + for (auto &objectJob : scene.OpaqueObjects) { + auto modelJob = std::dynamic_pointer_cast(objectJob); - m_DepthBuffer.Unbind(); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); - delete state; - - - } - } - - - - glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height); - glCullFace(GL_BACK); - m_ShadowProgram->Unbind(); + //glm::mat4 proj_mat = ApplyCropMatrix(m_shadCams[0], modelJob->Matrix, m_LightView); + //glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(proj_mat)); + glBindVertexArray(modelJob->Model->VAO); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); + glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int))); + GLERROR("Shadow Draw ERROR"); + } + } + m_DepthBuffer[i].Unbind(); + delete state; + } + } + glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height); + glEnable(GL_TEXTURE_2D); + glCullFace(GL_BACK); + m_ShadowProgram->Unbind(); + } } From f2ab02d860bf33e58460129dbd3054313afbb55b Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Thu, 18 Feb 2016 22:38:50 +0100 Subject: [PATCH 027/130] More WIP Switching between levels seem to work, but I borked all matrices --- include/Engine/Rendering/ShadowPass.h | 29 ++--- resources/Shaders/ForwardPlus.vert.glsl | 3 +- src/Engine/Editor/EditorSystem.cpp | 2 +- src/Engine/Rendering/DrawFinalPass.cpp | 1 - src/Engine/Rendering/ShadowPass.cpp | 136 ++++-------------------- 5 files changed, 29 insertions(+), 142 deletions(-) diff --git a/include/Engine/Rendering/ShadowPass.h b/include/Engine/Rendering/ShadowPass.h index 306ae8e0..7df1bbe9 100644 --- a/include/Engine/Rendering/ShadowPass.h +++ b/include/Engine/Rendering/ShadowPass.h @@ -11,8 +11,6 @@ #define MAX_SPLITS 5 -//#include "ShadowPassState.h" // not created yet - enum NearFar { Near = 0, Far = 1 }; enum LRBT { Left = 0, Right = 1, Bottom = 2, Top = 3 }; @@ -34,41 +32,30 @@ public: void Draw(RenderScene& scene); GLuint DepthMap() const { return m_DepthMap[m_ShadowLevel]; } - glm::mat4 lightSpaceMatrix() const { return m_LightSpaceMatrix; } - glm::mat4 lightP() const { return m_LightProjection; } - glm::mat4 lightV() const { return m_LightView; } - - void setResolution(GLuint width, GLuint height) { resolutionSizeWidth = width; resolutionSizeHeigth = height; } - + glm::mat4 lightP() const { return m_LightProjection[m_ShadowLevel]; } + glm::mat4 lightV() const { return m_LightView[m_ShadowLevel]; } private: glm::mat4 CalculateFrustum(RenderScene & scene, std::shared_ptr directionalLightJob, glm::mat4& p, glm::mat4& v, ShadowCamera shad_cam); - glm::vec3 LightDirectionToPoint(glm::vec4 direction); std::array UpdateFrustumPoints(Camera* cam, glm::vec3 center, glm::vec3 view_dir); void UpdateSplitDist(std::array shadow_cams, float far_distance, float near_distance); - void InitializeLightCameras(); - glm::mat4 ApplyCropMatrix(ShadowCamera& shadow_cam, glm::mat4 m, glm::mat4 v); glm::mat4 FindNewFrustum(ShadowCamera shadow_cam); EventBroker* m_EventBroker; - - const IRenderer* m_Renderer; + const IRenderer* m_Renderer; std::array m_DepthMap; std::array m_DepthBuffer; - ShaderProgram* m_ShadowProgram; + std::array m_LightProjection; + std::array m_LightView; - GLuint m_DepthFBO; + ShaderProgram* m_ShadowProgram; + GLuint m_DepthFBO; GLfloat m_NearFarPlane[2] = { -34.f, 27.f }; - //GLfloat m_LRBT[4] = { -77.f, 75.f, -89.f, 89.f }; GLfloat m_LRBT[4] = { -10.f, 10.f, -10.f, 10.f }; - glm::mat4 m_LightProjection; - glm::mat4 m_LightView; - glm::mat4 m_LightSpaceMatrix; - GLuint resolutionSizeWidth = 1024 * 2; GLuint resolutionSizeHeigth = 1024 * 2; @@ -76,7 +63,7 @@ private: int m_ShadowLevel = 0; int m_CurrentNrOfSplits = 3; - float m_SplitWeight = 0.75f; + float m_SplitWeight = 0.5f; std::array m_shadCams; }; diff --git a/resources/Shaders/ForwardPlus.vert.glsl b/resources/Shaders/ForwardPlus.vert.glsl index bde356e9..be7fa273 100644 --- a/resources/Shaders/ForwardPlus.vert.glsl +++ b/resources/Shaders/ForwardPlus.vert.glsl @@ -3,7 +3,6 @@ uniform mat4 M; uniform mat4 V; uniform mat4 P; -uniform mat4 lightSpaceMatrix; // Shadow map PV uniform mat4 LightV; uniform mat4 LightP; uniform mat4 Bones[100]; @@ -61,5 +60,5 @@ void main() Output.ExplosionPercentageElapsed = 0.0; //Output.PositionLightSpace = lightPos; // N - Output.PositionLightSpace = lightSpaceMatrix * M * vec4(Position, 1.0); + Output.PositionLightSpace = LightP * LightV * M * vec4(Position, 1.0); } \ No newline at end of file diff --git a/src/Engine/Editor/EditorSystem.cpp b/src/Engine/Editor/EditorSystem.cpp index 96b48874..a13bac0b 100644 --- a/src/Engine/Editor/EditorSystem.cpp +++ b/src/Engine/Editor/EditorSystem.cpp @@ -18,7 +18,7 @@ EditorSystem::EditorSystem(World* world, EventBroker* eventBroker, IRenderer* re m_ActualCamera = m_EditorCamera; m_EditorWorld->AttachComponent(m_EditorCamera.ID, "Transform"); auto cCamera = m_EditorWorld->AttachComponent(m_EditorCamera.ID, "Camera"); - (double&)cCamera["FarClip"] = 30.0; + (double&)cCamera["FarClip"] = 60.0; m_EditorCameraInputController = new EditorCameraInputController(m_EventBroker, -1); diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index 3e74cd1a..776bb1b3 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -244,7 +244,6 @@ void DrawFinalPass::BindModelUniforms(GLuint shaderHandle, std::shared_ptrlightSpaceMatrix())); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "LightP"), 1, GL_FALSE, glm::value_ptr(m_ShadowPass->lightP())); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "LightV"), 1, GL_FALSE, glm::value_ptr(m_ShadowPass->lightV())); //GLfloat m_NearFarPlane[2] = { -40.f, 30.f }; diff --git a/src/Engine/Rendering/ShadowPass.cpp b/src/Engine/Rendering/ShadowPass.cpp index 7be01b5b..ce9ac0c4 100644 --- a/src/Engine/Rendering/ShadowPass.cpp +++ b/src/Engine/Rendering/ShadowPass.cpp @@ -4,7 +4,6 @@ ShadowPass::ShadowPass(IRenderer * renderer) { m_Renderer = renderer; - //InitializeTextures(); InitializeFrameBuffers(); InitializeShaderPrograms(); } @@ -63,6 +62,7 @@ void ShadowPass::UpdateSplitDist(std::array shadow_cam shadow_cams[m_CurrentNrOfSplits - 1].camera->SetFarClip(far_distance); } +// Create a new light frustum based on the 8 corner points of a view frustum segment glm::mat4 ShadowPass::FindNewFrustum(ShadowCamera shadow_cam) { float maxX = -1000.0f; @@ -72,126 +72,35 @@ glm::mat4 ShadowPass::FindNewFrustum(ShadowCamera shadow_cam) float minY = 1000.0f; float minZ; - glm::vec4 transf = glm::vec4(shadow_cam.frustumCorners[0], 1.f); - - //if (transf.x > maxX) maxX = transf.x; - //if (transf.x < minX) minX = transf.x; - //if (transf.y > maxY) maxY = transf.y; - //if (transf.y < minY) minY = transf.y; + glm::vec4 transf; for (int i = 0; i < 8; i++) { transf = glm::vec4(shadow_cam.frustumCorners[i], 1.f); - transf.x /= transf.w; - transf.y /= transf.w; - if (transf.x > maxX) maxX = transf.x; if (transf.x < minX) minX = transf.x; if (transf.y > maxY) maxY = transf.y; if (transf.y < minY) minY = transf.y; } + //float scaleX = 2.0f / (maxX - minX); + //float scaleY = 2.0f / (maxY - minY); + //float offsetX = -0.5f * (maxX + minX) * scaleX; + //float offsetY = -0.5f * (maxY + minY) * scaleY; + // + //glm::mat4 nv_mvp = glm::mat4(); + //nv_mvp[0][0] = scaleX; + //nv_mvp[1][1] = scaleY; + //nv_mvp[0][3] = offsetX; + //nv_mvp[1][3] = offsetY; + //glm::transpose(nv_mvp); + glm::mat4 p = glm::ortho(minX, maxX, minY, maxY, m_NearFarPlane[Near], m_NearFarPlane[Far]); return p; } -glm::mat4 ShadowPass::ApplyCropMatrix(ShadowCamera& shadow_cam, glm::mat4 m, glm::mat4 v) -{ - glm::mat4 shad_modelview; - glm::mat4 shad_proj; - glm::mat4 shad_crop; - glm::mat4 shad_mvp; - float maxX = -1000.0f; - float maxY = -1000.0f; - float maxZ; - float minX = 1000.0f; - float minY = 1000.0f; - float minZ; - - glm::mat4 nv_mvp; - glm::vec4 transf; - - shad_modelview = m * v; - nv_mvp = shad_modelview; - - transf = nv_mvp * glm::vec4(shadow_cam.frustumCorners[0], 1.f); - minZ = transf.z; - maxZ = transf.z; - - for (int i = 1; i < 8; i++) { - transf = nv_mvp * glm::vec4(shadow_cam.frustumCorners[i], 1.f); - if (transf.z > maxZ) { - maxZ = transf.z; - } - if (transf.z < minZ) { - minZ = transf.z; - } - } - - // make sure all relevant shadow casters are included here - - shad_proj = glm::ortho(-1.f, 1.f, -1.f, 1.f, m_NearFarPlane[0], m_NearFarPlane[1]); - - //return shad_proj; - - shad_mvp = shad_proj * shad_modelview; - - nv_mvp = shad_mvp; - - for (int i = 0; i < 8; i++) - { - transf = nv_mvp * glm::vec4(shadow_cam.frustumCorners[i], 1.0f); - - transf.x /= transf.w; - transf.y /= transf.w; - - if (transf.x > maxX) maxX = transf.x; - if (transf.x < minX) minX = transf.x; - if (transf.y > maxY) maxY = transf.y; - if (transf.y < minY) minY = transf.y; - } - - float scaleX = 2.0f / (maxX - minX); - float scaleY = 2.0f / (maxY - minY); - float offsetX = -0.5f*(maxX + minX)*scaleX; - float offsetY = -0.5f*(maxY + minY)*scaleY; - - nv_mvp = glm::mat4(); - nv_mvp[0][0] = scaleX; - nv_mvp[1][1] = scaleY; - nv_mvp[0][3] = offsetX; - nv_mvp[1][3] = offsetY; - glm::transpose(nv_mvp); - - shad_crop = nv_mvp; - shad_crop *= shad_proj; - - //return nv_mvp; - //return shad_crop; - return glm::mat4(); -} - -void MakeShadowMap(glm::mat4 m, glm::mat4 v, glm::mat4 p, glm::vec3 light_dir) -{ - //float shad_modelview[16]; - - glDisable(GL_TEXTURE_2D); - - glm::mat4 viewMatrix = glm::lookAt(glm::vec3(0.f), light_dir, glm::vec3(-1.f, 0.f, 0.f)); - - - - - - - - - - glEnable(GL_TEXTURE_2D); -} - glm::mat4 ShadowPass::CalculateFrustum(RenderScene & scene, std::shared_ptr directionalLightJob, glm::mat4& p, glm::mat4& v, ShadowCamera shad_cam) { p = glm::ortho(m_LRBT[Left], m_LRBT[Right], m_LRBT[Bottom], m_LRBT[Top], m_NearFarPlane[Near], m_NearFarPlane[Far]); @@ -234,14 +143,6 @@ void ShadowPass::InitializeShaderPrograms() m_ShadowProgram->Link(); } -void ShadowPass::InitializeLightCameras() -{ - //for (int i = 0; i < MAX_SPLITS; i++) { - // m_shadCams[i].camera = new Camera(1.f, ); - // Camera. - //} -} - void ShadowPass::ClearBuffer() { for (int i = 0; i < m_CurrentNrOfSplits; i++) { @@ -287,11 +188,11 @@ void ShadowPass::Draw(RenderScene & scene) auto directionalLightJob = std::dynamic_pointer_cast(job); if (directionalLightJob) { - m_LightSpaceMatrix = CalculateFrustum(scene, directionalLightJob, m_LightProjection, m_LightView, m_shadCams[i]); - m_LightProjection = FindNewFrustum(m_shadCams[i]); + CalculateFrustum(scene, directionalLightJob, m_LightProjection[i], m_LightView[i], m_shadCams[i]); + m_LightProjection[i] = FindNewFrustum(m_shadCams[i]); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_LightProjection)); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_LightView)); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_LightProjection[i])); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_LightView[i])); GLERROR("ShadowLight ERROR"); @@ -321,5 +222,6 @@ void ShadowPass::Draw(RenderScene & scene) glCullFace(GL_BACK); m_ShadowProgram->Unbind(); + } } From 73a4336206df535b13f2087048bc6d7f4ff8491d Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Thu, 18 Feb 2016 23:33:10 +0100 Subject: [PATCH 028/130] Try some stuff --- include/Engine/Rendering/ShadowPass.h | 2 +- src/Engine/Rendering/ShadowPass.cpp | 20 ++++++++------------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/include/Engine/Rendering/ShadowPass.h b/include/Engine/Rendering/ShadowPass.h index 7df1bbe9..2022a5ab 100644 --- a/include/Engine/Rendering/ShadowPass.h +++ b/include/Engine/Rendering/ShadowPass.h @@ -36,7 +36,7 @@ public: glm::mat4 lightV() const { return m_LightView[m_ShadowLevel]; } private: - glm::mat4 CalculateFrustum(RenderScene & scene, std::shared_ptr directionalLightJob, glm::mat4& p, glm::mat4& v, ShadowCamera shad_cam); + glm::mat4 CalculateFrustum(RenderScene & scene, std::shared_ptr directionalLightJob, ShadowCamera shad_cam); std::array UpdateFrustumPoints(Camera* cam, glm::vec3 center, glm::vec3 view_dir); void UpdateSplitDist(std::array shadow_cams, float far_distance, float near_distance); glm::mat4 FindNewFrustum(ShadowCamera shadow_cam); diff --git a/src/Engine/Rendering/ShadowPass.cpp b/src/Engine/Rendering/ShadowPass.cpp index ce9ac0c4..412a1fc7 100644 --- a/src/Engine/Rendering/ShadowPass.cpp +++ b/src/Engine/Rendering/ShadowPass.cpp @@ -19,8 +19,10 @@ std::array ShadowPass::UpdateFrustumPoints(Camera* cam, glm::vec3 glm::vec3 up = glm::vec3(0.f, 1.f, 0.f); glm::vec3 right = glm::normalize(glm::cross(view_dir, up)); - glm::vec3 farCenter = center + view_dir * cam->FarClip(); - glm::vec3 nearCenter = center + view_dir * cam->NearClip(); + //glm::vec3 farCenter = center + view_dir * cam->FarClip(); + //glm::vec3 nearCenter = center + view_dir * cam->NearClip(); + glm::vec3 farCenter = view_dir * cam->FarClip(); + glm::vec3 nearCenter = view_dir * cam->NearClip(); up = glm::normalize(glm::cross(right, view_dir)); @@ -101,12 +103,11 @@ glm::mat4 ShadowPass::FindNewFrustum(ShadowCamera shadow_cam) return p; } -glm::mat4 ShadowPass::CalculateFrustum(RenderScene & scene, std::shared_ptr directionalLightJob, glm::mat4& p, glm::mat4& v, ShadowCamera shad_cam) +glm::mat4 ShadowPass::CalculateFrustum(RenderScene & scene, std::shared_ptr directionalLightJob, ShadowCamera shad_cam) { - p = glm::ortho(m_LRBT[Left], m_LRBT[Right], m_LRBT[Bottom], m_LRBT[Top], m_NearFarPlane[Near], m_NearFarPlane[Far]); - v = glm::lookAt(glm::vec3(0.f) + shad_cam.camera->Position(), glm::vec3(directionalLightJob->Direction) + shad_cam.camera->Position(), glm::vec3(-1.f, 0.f, 0.f)); + glm::vec3 middle = shad_cam.camera->Position() + (shad_cam.camera->Forward() * shad_cam.camera->FarClip() * 0.5f); - return p * v; + return glm::lookAt(glm::vec3(0.f) + middle, glm::vec3(directionalLightJob->Direction) + middle, glm::vec3(-1.f, 0.f, 0.f)); } void ShadowPass::InitializeFrameBuffers() @@ -180,15 +181,13 @@ void ShadowPass::Draw(RenderScene & scene) glCullFace(GL_FRONT); //state->Disable(GL_CULL_FACE); - //m_LightProjection = FindNewFrustum(m_shadCams[0], m_LightProjection, m_LightProjection); - if (m_ShadowOn == true) { for (auto &job : scene.DirectionalLightJobs) { auto directionalLightJob = std::dynamic_pointer_cast(job); if (directionalLightJob) { - CalculateFrustum(scene, directionalLightJob, m_LightProjection[i], m_LightView[i], m_shadCams[i]); + m_LightView[i] = CalculateFrustum(scene, directionalLightJob, m_shadCams[i]); m_LightProjection[i] = FindNewFrustum(m_shadCams[i]); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_LightProjection[i])); @@ -201,9 +200,6 @@ void ShadowPass::Draw(RenderScene & scene) glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); - //glm::mat4 proj_mat = ApplyCropMatrix(m_shadCams[0], modelJob->Matrix, m_LightView); - //glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(proj_mat)); - glBindVertexArray(modelJob->Model->VAO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int))); From abd36c81f8d6182a75c118bed855d935e9ec968b Mon Sep 17 00:00:00 2001 From: viktorljung Date: Mon, 22 Feb 2016 15:58:38 +0100 Subject: [PATCH 029/130] Added BlendTree that stores and blends multiple animations --- include/Engine/Rendering/BlendTree.h | 75 +++++ include/Engine/Rendering/ModelJob.h | 39 +-- include/Engine/Rendering/Skeleton.h | 17 +- resources/Schema/Components.xsd | 3 + resources/Schema/Components/Animation.xml | 26 +- resources/Schema/Components/Animation.xsd | 43 +-- resources/Schema/Components/Blend.xml | 6 + resources/Schema/Components/Blend.xsd | 14 + resources/Schema/Components/BlendAdditive.xml | 5 + resources/Schema/Components/BlendAdditive.xsd | 13 + resources/Schema/Components/BlendOverride.xml | 6 + resources/Schema/Components/BlendOverride.xsd | 14 + resources/Schema/Entities/AnimationTests2.xml | 156 ++++----- resources/Schema/Types/Entity.xsd | 3 + src/Engine/Rendering/AnimationSystem.cpp | 33 +- src/Engine/Rendering/BlendTree.cpp | 255 ++++++++++++++ src/Engine/Rendering/BoneAttachmentSystem.cpp | 13 +- src/Engine/Rendering/DrawFinalPass.cpp | 40 ++- src/Engine/Rendering/PickingPass.cpp | 20 +- src/Engine/Rendering/Skeleton.cpp | 313 ++++++------------ 20 files changed, 641 insertions(+), 453 deletions(-) create mode 100644 include/Engine/Rendering/BlendTree.h create mode 100644 resources/Schema/Components/Blend.xml create mode 100644 resources/Schema/Components/Blend.xsd create mode 100644 resources/Schema/Components/BlendAdditive.xml create mode 100644 resources/Schema/Components/BlendAdditive.xsd create mode 100644 resources/Schema/Components/BlendOverride.xml create mode 100644 resources/Schema/Components/BlendOverride.xsd create mode 100644 src/Engine/Rendering/BlendTree.cpp diff --git a/include/Engine/Rendering/BlendTree.h b/include/Engine/Rendering/BlendTree.h new file mode 100644 index 00000000..431cb8b2 --- /dev/null +++ b/include/Engine/Rendering/BlendTree.h @@ -0,0 +1,75 @@ +#ifndef BlendTree_h__ +#define BlendTree_h__ + +#include "Common.h" +#include "../GLM.h" +#include "Skeleton.h" +#include "../Core/EntityWrapper.h" +#include "../Core/World.h" +#include + +class BlendTree +{ +public: + enum class NodeType + { + Additive, + Blend, + Override, + Animation, + }; + + + struct Node + { + std::string Name; + Node* Parent = nullptr; + Node* Child[2] = { nullptr, nullptr }; + NodeType Type; + std::vector Pose; + float Weight = 0.f; + + Node* Next() { + Node* next = this; + + if (next->Child[1] == nullptr) { + // Node has no right child + next = this; + while (next->Parent != nullptr && next == next->Parent->Child[1]) { + next = next->Parent; + } + next = next->Parent; + } else { + // Find the leftmost node in the right subtree + next = next->Child[1]; + while (next->Child[0] != nullptr) { + next = next->Child[0]; + } + } + + return next; + + } + }; + + + + + + BlendTree(EntityWrapper ModelEntity, Skeleton* skeleton); + ~BlendTree(); + + std::vector GetBoneTransforms(Skeleton* skeleton); + + void PrintTree(); + +private: + Node* m_Root = nullptr; + + void FillTree(Node* parentNode, EntityWrapper parentEntity, Skeleton* skeleton); + BlendTree::Node* FillTreeByName(Node* parentNode, std::string name, EntityWrapper parentEntity, Skeleton* skeleton); + + void Blend(Skeleton* skeleton, std::vector& pose); +}; + +#endif diff --git a/include/Engine/Rendering/ModelJob.h b/include/Engine/Rendering/ModelJob.h index 773e002e..212a3888 100644 --- a/include/Engine/Rendering/ModelJob.h +++ b/include/Engine/Rendering/ModelJob.h @@ -15,6 +15,7 @@ #include "../Core/Transform.h" #include "Skeleton.h" #include "ShaderProgram.h" +#include "BlendTree.h" struct ModelJob : RenderJob { @@ -122,41 +123,11 @@ struct ModelJob : RenderJob Skeleton = Model->m_RawModel->m_Skeleton; if (Skeleton != nullptr) { - if (world->HasComponent(Entity, "Animation")) { - auto animationComponent = world->GetComponent(Entity, "Animation"); - - for (int i = 1; i <= 3; i++) { - ::Skeleton::AnimationData animationData; - animationData.animation = model->m_RawModel->m_Skeleton->GetAnimation(animationComponent["AnimationName" + std::to_string(i)]); - if (animationData.animation == nullptr) { - continue; - } - animationData.time = (double)animationComponent["Time" + std::to_string(i)]; - animationData.weight = (double)animationComponent["Weight" + std::to_string(i)]; - - if((int)animationComponent["BlendType" + std::to_string(i)].Enum("Additive") == (int)animationComponent["BlendType" + std::to_string(i)]) { - animationData.blendType = Skeleton::BlendType::Additive; - } else if ((int)animationComponent["BlendType" + std::to_string(i)].Enum("Blend") == (int)animationComponent["BlendType" + std::to_string(i)]) { - animationData.blendType = Skeleton::BlendType::Blend; - } else if ((int)animationComponent["BlendType" + std::to_string(i)].Enum("Override") == (int)animationComponent["BlendType" + std::to_string(i)]) { - animationData.blendType = Skeleton::BlendType::Override; - } - - animationData.level = (int)animationComponent["Level" + std::to_string(i)]; - Animations.push_back(animationData); - } - } - - if (world->HasComponent(Entity, "AnimationOffset")) { - auto animationOffsetComponent = world->GetComponent(Entity, "AnimationOffset"); - AnimationOffset.animation = model->m_RawModel->m_Skeleton->GetAnimation(animationOffsetComponent["AnimationName"]); - AnimationOffset.time = (double)animationOffsetComponent["Time"]; - } else { - AnimationOffset.animation = nullptr; - } + + EntityWrapper entityWrapper = EntityWrapper(world, modelComponent.EntityID); + BlendTree = new ::BlendTree(entityWrapper, Skeleton); } } - }; unsigned int TextureID; @@ -178,7 +149,7 @@ struct ModelJob : RenderJob std::vector<::Skeleton::AnimationData> Animations; ::Skeleton::AnimationOffset AnimationOffset; - + ::BlendTree* BlendTree = nullptr; glm::vec4 DiffuseColor; glm::vec4 SpecularColor; diff --git a/include/Engine/Rendering/Skeleton.h b/include/Engine/Rendering/Skeleton.h index f064cc3c..58021416 100644 --- a/include/Engine/Rendering/Skeleton.h +++ b/include/Engine/Rendering/Skeleton.h @@ -74,6 +74,7 @@ public: Blend, Override, }; + struct AnimationData { const Animation* animation; @@ -108,26 +109,24 @@ public: int GetBoneID(std::string name); - std::vector GetFrameBones(std::vector animations, AnimationOffset animationOffset, bool noRootMotion = false); - std::vector GetFrameBones(std::vector animations, bool noRootMotion = false); + std::vector GetFrameBones(); + + std::vector GetFrameBones(const Animation* animation, double time, bool additive, bool noRootMotion = false); + void AccumulateBoneTransforms(bool noRootMotion, const Animation* animation, double time, std::map& boneMatrices, bool additive, const Bone* bone, glm::mat4 parentMatrix); const Animation* GetAnimation(std::string name); - - void AccumulateBoneTransforms(bool noRootMotion, std::vector animations, std::map& frameBones, const Bone* bone, glm::mat4 parentMatrix); - void AccumulateBoneTransforms(bool noRootMotion, std::vector animations, AnimationOffset animationOffset, std::map& frameBones, const Bone* bone, glm::mat4 parentMatrix); - glm::mat4 AdditiveBlend(const Bone* bone, AnimationOffset animationOffset, glm::mat4 targetPose); - void PrintSkeleton(); - void PrintSkeleton(const Bone* parent, int depthCount); std::map Animations; glm::mat4 GetBoneTransform(const Bone* bone, const Animation* animation, float time, glm::mat4 childMatrix); glm::mat4 GetBoneTransform(bool noRootMotion, const Bone* bone, std::vector animations, AnimationOffset animationOffset, glm::mat4 childMatrix); glm::mat4 GetBoneTransform(bool noRootMotion, const Bone* bone, std::vector animations, glm::mat4 childMatrix); - int GetKeyframe(const Animation& animation, double time); + std::vector BlendPoses(std::vector pose1, std::vector pose2, float weight); + std::vector OverridePose(std::vector overridePose, std::vector targetPose); + private: glm::mat4 GetOffsetTransform(const Bone* bone, AnimationOffset animationOffset); glm::mat4 GetBonePose(const Bone* bone, const Animation* animation, double time, bool noRootMotion); diff --git a/resources/Schema/Components.xsd b/resources/Schema/Components.xsd index f950e8c8..d81c3852 100644 --- a/resources/Schema/Components.xsd +++ b/resources/Schema/Components.xsd @@ -39,4 +39,7 @@ + + + \ No newline at end of file diff --git a/resources/Schema/Components/Animation.xml b/resources/Schema/Components/Animation.xml index 6f49edb4..45ee8428 100644 --- a/resources/Schema/Components/Animation.xml +++ b/resources/Schema/Components/Animation.xml @@ -1,24 +1,8 @@ - - - 0 - 1.0 - 0 - 0 - true - - - 0 - 1.0 - 0 - 0 - true - - - 0 - 1.0 - 0 - 0 - true + + + 0 + true + false \ No newline at end of file diff --git a/resources/Schema/Components/Animation.xsd b/resources/Schema/Components/Animation.xsd index e765f8e8..5e82c333 100644 --- a/resources/Schema/Components/Animation.xsd +++ b/resources/Schema/Components/Animation.xsd @@ -2,48 +2,15 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + - \ No newline at end of file diff --git a/resources/Schema/Components/Blend.xml b/resources/Schema/Components/Blend.xml new file mode 100644 index 00000000..f949a102 --- /dev/null +++ b/resources/Schema/Components/Blend.xml @@ -0,0 +1,6 @@ + + + + + 0.5 + \ No newline at end of file diff --git a/resources/Schema/Components/Blend.xsd b/resources/Schema/Components/Blend.xsd new file mode 100644 index 00000000..95fc8f49 --- /dev/null +++ b/resources/Schema/Components/Blend.xsd @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/resources/Schema/Components/BlendAdditive.xml b/resources/Schema/Components/BlendAdditive.xml new file mode 100644 index 00000000..758917f9 --- /dev/null +++ b/resources/Schema/Components/BlendAdditive.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/resources/Schema/Components/BlendAdditive.xsd b/resources/Schema/Components/BlendAdditive.xsd new file mode 100644 index 00000000..ab931d52 --- /dev/null +++ b/resources/Schema/Components/BlendAdditive.xsd @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/resources/Schema/Components/BlendOverride.xml b/resources/Schema/Components/BlendOverride.xml new file mode 100644 index 00000000..a9f2095a --- /dev/null +++ b/resources/Schema/Components/BlendOverride.xml @@ -0,0 +1,6 @@ + + + + + 1.0 + \ No newline at end of file diff --git a/resources/Schema/Components/BlendOverride.xsd b/resources/Schema/Components/BlendOverride.xsd new file mode 100644 index 00000000..27fc01ed --- /dev/null +++ b/resources/Schema/Components/BlendOverride.xsd @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/resources/Schema/Entities/AnimationTests2.xml b/resources/Schema/Entities/AnimationTests2.xml index 8cc3f812..ace71800 100644 --- a/resources/Schema/Entities/AnimationTests2.xml +++ b/resources/Schema/Entities/AnimationTests2.xml @@ -26,42 +26,6 @@ - - - - Run - 1 - StrafeRight - 0.5 - 0.98334510030765165 - 0.5 - 0.97153983043137671 - 1 - 0.093923612201312068 - 1 - - - Models/Characters/Assault/AssaultAnimations.mesh - - - - - - - - - - R_Arm_Weapon_Joint - - - Models/Weapons/Blue/AssaultWeaponBlue.mesh - - - - - - - @@ -99,35 +63,19 @@ - + - - Run - 1 - StrafeRight - 0.5 - 0.98334510030765165 - 0.5 - 0.89665639003541542 - 1 - ShootFastRifle - - - - 0.099759525382621339 - 1 - - - AimRifle - - + + BlendOverride + AimAdditive + Models/Characters/Assault/AssaultAnimations.mesh - + R_Arm_Weapon_Joint @@ -136,45 +84,79 @@ Models/Weapons/Blue/AssaultWeaponBlue.mesh - - - - - - - - AimRifle - 0.5 - Ru - 0.57926159055711501 - - - Models/Characters/Assault/AssaultAnimations.mesh - true - - - - - - - + - - R_Arm_Weapon_Joint - - - Models/Weapons/Red/AssaultWeaponRed.mesh - true - + + AimRifle + + 0.5 + true + + + + + ShootRifleAnimation + BlendWalkRun + + + + + + + + RunAnimtaion + WalkAnimation + 1 + + + + + + + + Run + + 1 + + + + + + + + + Walk + + 1 + + + + + + + + + + + ShootFastRifle + + 1 + + + + + + + diff --git a/resources/Schema/Types/Entity.xsd b/resources/Schema/Types/Entity.xsd index ffe3421a..19eded09 100644 --- a/resources/Schema/Types/Entity.xsd +++ b/resources/Schema/Types/Entity.xsd @@ -43,6 +43,9 @@ + + + diff --git a/src/Engine/Rendering/AnimationSystem.cpp b/src/Engine/Rendering/AnimationSystem.cpp index e70c4f36..1b260b08 100644 --- a/src/Engine/Rendering/AnimationSystem.cpp +++ b/src/Engine/Rendering/AnimationSystem.cpp @@ -2,57 +2,56 @@ void AnimationSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& animationComponent, double dt) { - if(!entity.HasComponent("Model")) { - return; - } + + EntityWrapper parent = entity.FirstParentWithComponent("Model"); Model* model; try { - model = ResourceManager::Load<::Model, true>(entity["Model"]["Resource"]); + model = ResourceManager::Load<::Model, true>(parent["Model"]["Resource"]); } catch (const std::exception&) { return; } - + Skeleton* skeleton = model->m_RawModel->m_Skeleton; - if(skeleton == nullptr) { + if (skeleton == nullptr) { return; } - for (int i = 1; i <= 3; i++) { - const Skeleton::Animation* animation = skeleton->GetAnimation(animationComponent["AnimationName" + std::to_string(i)]); + for (int i = 1; i <= 1; i++) { + const Skeleton::Animation* animation = skeleton->GetAnimation(animationComponent["AnimationName"]); if (animation == nullptr) { continue;; } - double animationSpeed = (double)animationComponent["Speed" + std::to_string(i)]; + double animationSpeed = (double)animationComponent["Speed"]; if (animationSpeed != 0.0) { - double nextTime = (double)animationComponent["Time" + std::to_string(i)] + animationSpeed * dt; + double nextTime = (double)animationComponent["Time"] + animationSpeed * dt; - if (!(bool)animationComponent["Loop" + std::to_string(i)]) { + if (!(bool)animationComponent["Loop"]) { if (nextTime > animation->Duration) { nextTime = animation->Duration; Events::AnimationComplete e; e.Entity = entity; - e.Name = (std::string)animationComponent["AnimationName" + std::to_string(i)]; + e.Name = (std::string)animationComponent["AnimationName"]; m_EventBroker->Publish(e); } else if (nextTime < 0) { Events::AnimationComplete e; e.Entity = entity; - e.Name = (std::string)animationComponent["AnimationName" + std::to_string(i)]; + e.Name = (std::string)animationComponent["AnimationName"]; m_EventBroker->Publish(e); nextTime = 0; } - (double&)animationComponent["Speed" + std::to_string(i)] = 0.0; + (double&)animationComponent["Speed"] = 0.0; } else { if (nextTime > animation->Duration) { Events::AnimationComplete e; e.Entity = entity; - e.Name = (std::string)animationComponent["AnimationName" + std::to_string(i)]; + e.Name = (std::string)animationComponent["AnimationName"]; m_EventBroker->Publish(e); while(nextTime > animation->Duration) { @@ -61,7 +60,7 @@ void AnimationSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& a } else if (nextTime < 0) { Events::AnimationComplete e; e.Entity = entity; - e.Name = (std::string)animationComponent["AnimationName" + std::to_string(i)]; + e.Name = (std::string)animationComponent["AnimationName"]; m_EventBroker->Publish(e); while (nextTime < 0) { @@ -70,7 +69,7 @@ void AnimationSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& a } } - (double&)animationComponent["Time" + std::to_string(i)] = nextTime; + (double&)animationComponent["Time"] = nextTime; } } } diff --git a/src/Engine/Rendering/BlendTree.cpp b/src/Engine/Rendering/BlendTree.cpp new file mode 100644 index 00000000..43d1d5fd --- /dev/null +++ b/src/Engine/Rendering/BlendTree.cpp @@ -0,0 +1,255 @@ +#include "Rendering/BlendTree.h" + +BlendTree::BlendTree(EntityWrapper ModelEntity, Skeleton* skeleton) +{ + auto itPair = ModelEntity.World->GetChildren(ModelEntity.ID); + if (itPair.first == itPair.second) { + return; + } + + + if (ModelEntity.HasComponent("Animation")) { + const Skeleton::Animation* animation = skeleton->GetAnimation(ModelEntity["Animation"]["AnimationName"]); + if (animation == nullptr) { + return; + } + + m_Root = new Node(); + m_Root->Name = ModelEntity.Name(); + m_Root->Pose = skeleton->GetFrameBones(animation, (double)ModelEntity["Animation"]["Time"], (bool)ModelEntity["Animation"]["Additive"]); + m_Root->Parent = nullptr; + m_Root->Type = NodeType::Animation; + + } else if (ModelEntity.HasComponent("Blend")) { + m_Root = new Node(); + m_Root->Name = ModelEntity.Name(); + m_Root->Parent = nullptr; + m_Root->Type = NodeType::Blend; + m_Root->Weight = (double)ModelEntity["Blend"]["Weight"]; + m_Root->Child[0] = FillTreeByName(m_Root, (std::string)ModelEntity["Blend"]["Pose1"], ModelEntity, skeleton); + m_Root->Child[1] = FillTreeByName(m_Root, (std::string)ModelEntity["Blend"]["Pose2"], ModelEntity, skeleton); + + } else if (ModelEntity.HasComponent("BlendOverride")) { + m_Root = new Node(); + m_Root->Name = ModelEntity.Name(); + m_Root->Parent = nullptr; + m_Root->Type = NodeType::Override; + m_Root->Child[0] = FillTreeByName(m_Root, (std::string)ModelEntity["BlendOverride"]["Master"], ModelEntity, skeleton); + m_Root->Child[1] = FillTreeByName(m_Root, (std::string)ModelEntity["BlendOverride"]["Slave"], ModelEntity, skeleton); + + } else if (ModelEntity.HasComponent("BlendAdditive")) { + m_Root = new Node(); + m_Root->Name = ModelEntity.Name(); + m_Root->Parent = nullptr; + m_Root->Type = NodeType::Additive; + m_Root->Child[0] = FillTreeByName(m_Root, (std::string)ModelEntity["BlendAdditive"]["Adder"], ModelEntity, skeleton); + m_Root->Child[1] = FillTreeByName(m_Root, (std::string)ModelEntity["BlendAdditive"]["Receiver"], ModelEntity, skeleton); + } + + + + // PrintTree(); +} + +BlendTree::~BlendTree() +{ + +} + +void BlendTree::PrintTree() +{ + Node* currentNode = m_Root; + LOG_INFO("\n\n"); + + while(currentNode->Child[0] != nullptr) { + currentNode = currentNode->Child[0]; + } + + while (currentNode != nullptr) + { + LOG_INFO("%s", currentNode->Name.c_str()); + currentNode = currentNode->Next(); + } + + +} + + + +void BlendTree::FillTree(Node* parentNode, EntityWrapper parentEntity, Skeleton* skeleton) +{ + auto itPair = parentEntity.World->GetChildren(parentEntity.ID); + if (itPair.first == itPair.second) { + return; // no children + } + + unsigned int childIndex = 0; + for (auto it = itPair.first; it != itPair.second; ++it) { + + EntityWrapper childEntity = EntityWrapper(parentEntity.World, it->second); + + if(!childEntity.Valid()) { + continue; + } + + if (childEntity.HasComponent("Animation")) { + const Skeleton::Animation* animation = skeleton->GetAnimation(childEntity["Animation"]["AnimationName"]); + if(animation == nullptr) { + continue; + } + + Node* node = new Node(); + node->Name = childEntity.Name(); + node->Pose = skeleton->GetFrameBones(animation, (double)childEntity["Animation"]["Time"], (bool)childEntity["Animation"]["Additive"]); + node->Parent = parentNode; + node->Type = NodeType::Animation; + parentNode->Child[childIndex] = node; + childIndex++; + FillTree(node, childEntity, skeleton); + + } else if (childEntity.HasComponent("Blend")) { + Node* node = new Node(); + node->Name = childEntity.Name(); + node->Parent = parentNode; + node->Type = NodeType::Blend; + node->Weight = (double)childEntity["Blend"]["Weight"]; + parentNode->Child[childIndex] = node; + childIndex++; + FillTree(node, childEntity, skeleton); + + } else if (childEntity.HasComponent("BlendOverride")) { + Node* node = new Node(); + node->Name = childEntity.Name(); + node->Parent = parentNode; + node->Type = NodeType::Override; + parentNode->Child[childIndex] = node; + childIndex++; + FillTree(node, childEntity, skeleton); + + } else if (childEntity.HasComponent("BlendAdditive")) { + Node* node = new Node(); + node->Name = childEntity.Name(); + node->Parent = parentNode; + node->Type = NodeType::Additive; + parentNode->Child[childIndex] = node; + childIndex++; + FillTree(node, childEntity, skeleton); + } + } +} + + +BlendTree::Node* BlendTree::FillTreeByName(Node* parentNode, std::string name, EntityWrapper parentEntity, Skeleton* skeleton) +{ + EntityWrapper childEntity = parentEntity.FirstChildByName(name); + + if (!childEntity.Valid()) { + return nullptr; + } + + if (childEntity.HasComponent("Animation")) { + const Skeleton::Animation* animation = skeleton->GetAnimation(childEntity["Animation"]["AnimationName"]); + if (animation == nullptr) { + return nullptr; + } + + Node* node = new Node(); + node->Name = childEntity.Name(); + node->Pose = skeleton->GetFrameBones(animation, (double)childEntity["Animation"]["Time"], (bool)childEntity["Animation"]["Additive"]); + node->Parent = parentNode; + node->Type = NodeType::Animation; + return node; + + } else if (childEntity.HasComponent("Blend")) { + Node* node = new Node(); + node->Name = childEntity.Name(); + node->Parent = parentNode; + node->Type = NodeType::Blend; + node->Weight = (double)childEntity["Blend"]["Weight"]; + node->Child[0] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose1"], childEntity, skeleton); + node->Child[1] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose2"], childEntity, skeleton); + return node; + } else if (childEntity.HasComponent("BlendOverride")) { + Node* node = new Node(); + node->Name = childEntity.Name(); + node->Parent = parentNode; + node->Type = NodeType::Override; + node->Child[0] = FillTreeByName(node, (std::string)childEntity["BlendOverride"]["Master"], childEntity, skeleton); + node->Child[1] = FillTreeByName(node, (std::string)childEntity["BlendOverride"]["Slave"], childEntity, skeleton); + return node; + } else if (childEntity.HasComponent("BlendAdditive")) { + Node* node = new Node(); + node->Name = childEntity.Name(); + node->Parent = parentNode; + node->Type = NodeType::Additive; + node->Child[0] = FillTreeByName(node, (std::string)childEntity["BlendAdditive"]["Adder"], childEntity, skeleton); + node->Child[1] = FillTreeByName(node, (std::string)childEntity["BlendAdditive"]["Receiver"], childEntity, skeleton); + return node; + } + + return nullptr; +} + +void BlendTree::Blend(Skeleton* skeleton, std::vector& pose) +{ + Node* currentNode; + Node* start = m_Root; + while (start->Child[0] != nullptr) { + start = start->Child[0]; + } + + currentNode = start; + LOG_INFO("\n\n"); + while (m_Root->Pose.size() == 0) { + if(currentNode->Pose.size() == 0) { + if(currentNode->Child[0]->Pose.size() != 0 && currentNode->Child[1]->Pose.size() != 0) { + + switch (currentNode->Type) { + case BlendTree::NodeType::Additive: + currentNode->Pose = skeleton->BlendPoses(currentNode->Child[0]->Pose, currentNode->Child[1]->Pose, currentNode->Weight); + break; + case BlendTree::NodeType::Blend: + currentNode->Pose = skeleton->BlendPoses(currentNode->Child[0]->Pose, currentNode->Child[1]->Pose, currentNode->Weight); + break; + case BlendTree::NodeType::Override: + currentNode->Pose = skeleton->OverridePose(currentNode->Child[0]->Pose, currentNode->Child[1]->Pose); + break; + case BlendTree::NodeType::Animation: + // do nothing + break; + } + + + LOG_INFO("Blending %s and %s", currentNode->Child[0]->Name.c_str(), currentNode->Child[1]->Name.c_str()); + } + } + + + + currentNode = currentNode->Next(); + + if (currentNode == nullptr) { + currentNode = start; + } + + } + + pose = m_Root->Pose; +} + +std::vector BlendTree::GetBoneTransforms(Skeleton* skeleton) +{ + if (skeleton == nullptr || m_Root == nullptr) { + std::vector pose; + for (auto& b : skeleton->Bones) { + pose.push_back(glm::mat4(1)); + } + return pose; + } + + std::vector pose; + Blend(skeleton, pose); + + return pose; +} + diff --git a/src/Engine/Rendering/BoneAttachmentSystem.cpp b/src/Engine/Rendering/BoneAttachmentSystem.cpp index 3effaf2c..a4d381d1 100644 --- a/src/Engine/Rendering/BoneAttachmentSystem.cpp +++ b/src/Engine/Rendering/BoneAttachmentSystem.cpp @@ -40,15 +40,10 @@ void BoneAttachmentSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapp glm::mat4 boneTransform; if (parent.HasComponent("Animation")) { - for (int i = 1; i <= 3; i++) { - ::Skeleton::AnimationData animationData; - animationData.animation = model->m_RawModel->m_Skeleton->GetAnimation(parent["Animation"]["AnimationName" + std::to_string(i)]); - if (animationData.animation == nullptr) { - continue; - } - animationData.time = (double)parent["Animation"]["Time" + std::to_string(i)]; - animationData.weight = (double)parent["Animation"]["Weight" + std::to_string(i)]; - + ::Skeleton::AnimationData animationData; + animationData.animation = model->m_RawModel->m_Skeleton->GetAnimation(parent["Animation"]["AnimationName"]); + if (animationData.animation != nullptr) { + animationData.time = (double)parent["Animation"]["Time"]; Animations.push_back(animationData); } } diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index 11db71f0..43722a61 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -338,11 +338,12 @@ void DrawFinalPass::DrawModelRenderQueues(std::list>& //bind textures BindExplosionTextures(explosionSkinnedHandle, explosionEffectJob); std::vector frameBones; - if (explosionEffectJob->AnimationOffset.animation != nullptr) { + /*if (explosionEffectJob->AnimationOffset.animation != nullptr) { frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations, explosionEffectJob->AnimationOffset); } else { frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations); - } + }*/ + frameBones = explosionEffectJob->Skeleton->GetFrameBones(); glUniformMatrix4fv(glGetUniformLocation(explosionSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); } else { m_ExplosionEffectProgram->Bind(); @@ -365,11 +366,12 @@ void DrawFinalPass::DrawModelRenderQueues(std::list>& BindExplosionTextures(explosionSplatMapSkinnedHandle, explosionEffectJob); GLERROR("asdasd"); std::vector frameBones; - if (explosionEffectJob->AnimationOffset.animation != nullptr) { + /*if (explosionEffectJob->AnimationOffset.animation != nullptr) { frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations, explosionEffectJob->AnimationOffset); } else { frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations); - } + }*/ + frameBones = explosionEffectJob->Skeleton->GetFrameBones(); glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); } else { @@ -410,11 +412,12 @@ void DrawFinalPass::DrawModelRenderQueues(std::list>& //bind textures BindModelTextures(forwardSkinnedHandle, modelJob); std::vector frameBones; - if (modelJob->AnimationOffset.animation != nullptr) { + /* if (modelJob->AnimationOffset.animation != nullptr) { frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset); } else { frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations); - } + }*/ + frameBones = modelJob->BlendTree->GetBoneTransforms(modelJob->Skeleton); glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); } else { @@ -438,11 +441,12 @@ void DrawFinalPass::DrawModelRenderQueues(std::list>& BindModelTextures(forwardSplatMapSkinnedHandle, modelJob); GLERROR("asdasd"); std::vector frameBones; - if (modelJob->AnimationOffset.animation != nullptr) { + /* if (modelJob->AnimationOffset.animation != nullptr) { frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset); } else { frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations); - } + }*/ + frameBones = modelJob->BlendTree->GetBoneTransforms(modelJob->Skeleton); glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); } else { @@ -486,11 +490,12 @@ void DrawFinalPass::DrawShieldToStencilBuffer(std::listViewMatrix())); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix())); std::vector frameBones; - if (modelJob->AnimationOffset.animation != nullptr) { + /*if (modelJob->AnimationOffset.animation != nullptr) { frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset); } else { frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations); - } + }*/ + frameBones = modelJob->Skeleton->GetFrameBones(); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); } else { m_ShieldToStencilProgram->Bind(); @@ -544,11 +549,12 @@ void DrawFinalPass::DrawShieldedModelRenderQueue(std::list frameBones; - if (explosionEffectJob->AnimationOffset.animation != nullptr) { + /* if (explosionEffectJob->AnimationOffset.animation != nullptr) { frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations, explosionEffectJob->AnimationOffset); } else { frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations); - } + }*/ + frameBones = explosionEffectJob->Skeleton->GetFrameBones(); glUniformMatrix4fv(glGetUniformLocation(explosionHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); if (GLERROR("Animation")) { @@ -583,11 +589,12 @@ void DrawFinalPass::DrawShieldedModelRenderQueue(std::list frameBones; - if (modelJob->AnimationOffset.animation != nullptr) { + /* if (modelJob->AnimationOffset.animation != nullptr) { frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset); } else { frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations); - } + }*/ + frameBones = modelJob->Skeleton->GetFrameBones(); glUniformMatrix4fv(glGetUniformLocation(forwardHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); @@ -619,11 +626,12 @@ void DrawFinalPass::DrawToDepthBuffer(std::list>& job glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); std::vector frameBones; - if (modelJob->AnimationOffset.animation != nullptr) { + /*if (modelJob->AnimationOffset.animation != nullptr) { frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset); } else { frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations); - } + }*/ + frameBones = modelJob->Skeleton->GetFrameBones(); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); } else { diff --git a/src/Engine/Rendering/PickingPass.cpp b/src/Engine/Rendering/PickingPass.cpp index fa1b3ca3..479cb762 100644 --- a/src/Engine/Rendering/PickingPass.cpp +++ b/src/Engine/Rendering/PickingPass.cpp @@ -103,11 +103,12 @@ void PickingPass::Draw(RenderScene& scene) if (modelJob->Model->m_RawModel->m_Skeleton != nullptr) { std::vector frameBones; - if (modelJob->AnimationOffset.animation != nullptr) { + /*if (modelJob->AnimationOffset.animation != nullptr) { frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset); } else { frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations); - } + }*/ + frameBones = modelJob->Skeleton->GetFrameBones(); glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); } @@ -160,11 +161,12 @@ void PickingPass::Draw(RenderScene& scene) glUniform2fv(glGetUniformLocation(shaderSkinnedHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1]))); std::vector frameBones; - if (modelJob->AnimationOffset.animation != nullptr) { + /* if (modelJob->AnimationOffset.animation != nullptr) { frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset); } else { frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations); - } + }*/ + frameBones = modelJob->Skeleton->GetFrameBones(); glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); } else { m_PickingProgram->Bind(); @@ -215,11 +217,12 @@ void PickingPass::Draw(RenderScene& scene) glUniform2fv(glGetUniformLocation(shaderSkinnedHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1]))); std::vector frameBones; - if (modelJob->AnimationOffset.animation != nullptr) { + /* if (modelJob->AnimationOffset.animation != nullptr) { frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset); } else { frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations); - } + }*/ + frameBones = modelJob->Skeleton->GetFrameBones(); glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); } else { @@ -276,11 +279,12 @@ void PickingPass::Draw(RenderScene& scene) if (modelJob->Model->m_RawModel->m_Skeleton != nullptr) { std::vector frameBones; - if (modelJob->AnimationOffset.animation != nullptr) { + /*if (modelJob->AnimationOffset.animation != nullptr) { frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset); } else { frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations); - } + }*/ + frameBones = modelJob->Skeleton->GetFrameBones(); glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); } diff --git a/src/Engine/Rendering/Skeleton.cpp b/src/Engine/Rendering/Skeleton.cpp index 94656848..4745b36d 100644 --- a/src/Engine/Rendering/Skeleton.cpp +++ b/src/Engine/Rendering/Skeleton.cpp @@ -41,29 +41,17 @@ const Skeleton::Animation* Skeleton::GetAnimation(std::string name) } } -std::vector Skeleton::GetFrameBones(std::vector animations, bool noRootMotion /*= false*/) +std::vector Skeleton::GetFrameBones() { - if (animations.size() <= 0) { - std::vector finalMatrices; - for (auto& b : Bones) { - finalMatrices.push_back(glm::mat4(1));//b.second->OffsetMatrix); - } - return finalMatrices; - } - - std::map frameBones; - AccumulateBoneTransforms(true, animations, frameBones, RootBone, glm::mat4(1)); - std::vector finalMatrices; - for (auto &kv : frameBones) { - finalMatrices.push_back(kv.second); + for (auto& b : Bones) { + finalMatrices.push_back(glm::mat4(1)); } return finalMatrices; } - -std::vector Skeleton::GetFrameBones(std::vector animations, AnimationOffset animationOffset, bool noRootMotion /*= false*/) +std::vector Skeleton::GetFrameBones(const Animation* animation, const double time, bool additive, bool noRootMotion /*= false*/) { - if (animations.size() <= 0 || animationOffset.animation == nullptr) { + if (animation == nullptr) { std::vector finalMatrices; for (auto& b : Bones) { finalMatrices.push_back(glm::mat4(1)); @@ -71,9 +59,9 @@ std::vector Skeleton::GetFrameBones(std::vector animat return finalMatrices; } - + std::map frameBones; - AccumulateBoneTransforms(true, animations, animationOffset, frameBones, RootBone, glm::mat4(1)); + AccumulateBoneTransforms(true, animation, time, frameBones, additive, RootBone, glm::mat4(1)); std::vector finalMatrices; for (auto &kv : frameBones) { @@ -82,175 +70,74 @@ std::vector Skeleton::GetFrameBones(std::vector animat return finalMatrices; } -void Skeleton::AccumulateBoneTransforms(bool noRootMotion, std::vector animations, std::map& boneMatrices, const Bone* bone, glm::mat4 parentMatrix) +void Skeleton::AccumulateBoneTransforms(bool noRootMotion, const Animation* animation, double time, std::map& boneMatrices, bool additive, const Bone* bone, glm::mat4 parentMatrix) { - glm::mat4 boneMatrix; - - std::vector JointPoses; - - for (const AnimationData animationData : animations) { - const Animation* animation = animationData.animation; - const float time = animationData.time; - - JointFramePose jointPose; - jointPose.Weight = animationData.weight;; - - if (animation->JointAnimations.find(bone->ID) != animation->JointAnimations.end()) { - std::vector boneKeyFrames = animation->JointAnimations.at(bone->ID); - - Animation::Keyframe currentFrame; - Animation::Keyframe nextFrame; - - if (boneKeyFrames.size() > 1) { // 2+ keyframes for the current bone - for (int index = boneKeyFrames.size()-1; index >= 0; index--) { // find the bone keyframes that surrounds the current frame - if (time >= boneKeyFrames.at(index).Time) { - currentFrame = boneKeyFrames.at(index); - nextFrame = boneKeyFrames.at((index + 1) % boneKeyFrames.size()); - break; - } - } - - float progress; - - if (nextFrame.Index == 0) { - nextFrame = currentFrame; - progress = (time - currentFrame.Time) / (animation->Duration - currentFrame.Time); - } else { - progress = (time - currentFrame.Time) / (nextFrame.Time - currentFrame.Time); - - } - - - if (progress > 1.0f || progress < 0.0f) { - progress = glm::clamp(progress, 0.0f, 1.0f); - } - Animation::Keyframe::BoneProperty currentBoneProperty = currentFrame.BoneProperties; - Animation::Keyframe::BoneProperty nextBoneProperty = nextFrame.BoneProperties; - - glm::vec3 position = currentBoneProperty.Position * (1.f - progress) + nextBoneProperty.Position * progress; - glm::quat rotation = glm::slerp(currentBoneProperty.Rotation, nextBoneProperty.Rotation, progress); - glm::vec3 scale = currentBoneProperty.Scale * (1.f - progress) + nextBoneProperty.Scale * progress; - - // Flag for no root motion - if (bone == RootBone && noRootMotion) { - position.x = 0; - position.z = 0; - } - - jointPose.Pose = (glm::translate(position) * glm::toMat4(rotation) * glm::scale(scale)); - JointPoses.push_back(jointPose); - - } else { // 1 keyframes for the current bone - currentFrame = boneKeyFrames.at(0); - jointPose.Pose = (glm::translate(currentFrame.BoneProperties.Position) * glm::toMat4(currentFrame.BoneProperties.Rotation) * glm::scale(currentFrame.BoneProperties.Scale)); - JointPoses.push_back(jointPose); - } - } else { // 0 keyframes for the current bone - - } - + if (additive) { + time += 1.0/60.0; // first frame is a reference frame } + glm::mat4 boneMatrix; - if (JointPoses.size() == 0) { - if (bone->Parent) { - glm::mat4 jointPose = (glm::inverse(bone->OffsetMatrix) * bone->Parent->OffsetMatrix); + if (animation->JointAnimations.find(bone->ID) != animation->JointAnimations.end()) { + std::vector boneKeyFrames = animation->JointAnimations.at(bone->ID); - boneMatrix = parentMatrix * jointPose; - boneMatrices[bone->ID] = boneMatrix * bone->OffsetMatrix; - } else { - boneMatrix = glm::inverse(bone->OffsetMatrix); - boneMatrices[bone->ID] = parentMatrix; - } - } else { + Animation::Keyframe currentFrame; + Animation::Keyframe nextFrame; - float totalWeight = 0; + if (boneKeyFrames.size() > 1) { // 2+ keyframes for the current bone + for (int index = boneKeyFrames.size()-1; index >= 0; index--) { // find the bone keyframes that surrounds the current frame + if (time >= boneKeyFrames.at(index).Time) { + currentFrame = boneKeyFrames.at(index); + nextFrame = boneKeyFrames.at((index + 1) % boneKeyFrames.size()); + break; + } + } - for (JointFramePose jointFramePose : JointPoses) { - totalWeight += jointFramePose.Weight; - } + float progress; - glm::mat4 finalBlend = glm::mat4(0); - - for (JointFramePose jointFramePose : JointPoses) { - if (jointFramePose.Weight == 1.0f) { - finalBlend = jointFramePose.Pose; + if (nextFrame.Index == 0) { + nextFrame = currentFrame; + progress = (time - currentFrame.Time) / (animation->Duration - currentFrame.Time); } else { - finalBlend += jointFramePose.Pose * (jointFramePose.Weight / totalWeight); + progress = (time - currentFrame.Time) / (nextFrame.Time - currentFrame.Time); + } + + progress = glm::clamp(progress, 0.0f, 1.0f); + Animation::Keyframe::BoneProperty currentBoneProperty = currentFrame.BoneProperties; + Animation::Keyframe::BoneProperty nextBoneProperty = nextFrame.BoneProperties; + + glm::vec3 position = currentBoneProperty.Position * (1.f - progress) + nextBoneProperty.Position * progress; + glm::quat rotation = glm::slerp(currentBoneProperty.Rotation, nextBoneProperty.Rotation, progress); + glm::vec3 scale = currentBoneProperty.Scale * (1.f - progress) + nextBoneProperty.Scale * progress; + + // Flag for no root motion + if (bone == RootBone && noRootMotion) { + position.x = 0; + position.z = 0; + } + + boneMatrix = parentMatrix * (glm::translate(position) * glm::toMat4(rotation) * glm::scale(scale)); + boneMatrices[bone->ID] = boneMatrix *bone->OffsetMatrix; + + } else { // 1 keyframes for the current bone + currentFrame = boneKeyFrames.at(0); + boneMatrix = parentMatrix * (glm::translate(currentFrame.BoneProperties.Position) * glm::toMat4(currentFrame.BoneProperties.Rotation) * glm::scale(currentFrame.BoneProperties.Scale)); + boneMatrices[bone->ID] = boneMatrix *bone->OffsetMatrix; } - - - boneMatrix = parentMatrix * finalBlend; - boneMatrices[bone->ID] = boneMatrix * bone->OffsetMatrix; - } - - for (auto &child : bone->Children) { - AccumulateBoneTransforms(noRootMotion, animations, boneMatrices, child, boneMatrix); - } -} - -void Skeleton::AccumulateBoneTransforms(bool noRootMotion, std::vector animations, AnimationOffset animationOffset, std::map& boneMatrices, const Bone* bone, glm::mat4 parentMatrix) -{ - glm::mat4 boneMatrix; - std::vector JointPoses; - - for (const AnimationData animationData : animations) { - if (animationData.animation->JointAnimations.find(bone->ID) != animationData.animation->JointAnimations.end()) { // Does the bone have any keyframes in this animation? - JointFramePose jointPose; - jointPose.Weight = animationData.weight; - jointPose.Type = animationData.blendType; - jointPose.Level = animationData.level; - jointPose.Pose = GetBonePose(bone, animationData.animation, animationData.time, noRootMotion); - JointPoses.push_back(jointPose); - } - } - - - if (JointPoses.size() == 0) { // No keyframes for the current bone + } else { // 0 keyframes for the current bone if (bone->Parent) { - glm::mat4 jointPose = (glm::inverse(bone->OffsetMatrix) * bone->Parent->OffsetMatrix); - glm::mat4 boneTransform = AdditiveBlend(bone, animationOffset, jointPose); - boneMatrix = parentMatrix * boneTransform; - boneMatrices[bone->ID] = boneMatrix * bone->OffsetMatrix; + boneMatrix = parentMatrix * (glm::inverse(bone->OffsetMatrix) * bone->Parent->OffsetMatrix); + boneMatrices[bone->ID] = boneMatrix *bone->OffsetMatrix; } else { boneMatrix = glm::inverse(bone->OffsetMatrix); boneMatrices[bone->ID] = parentMatrix; } - } else { - - - glm::mat4 finalBlend = glm::mat4(0); - glm::mat4 finalOverride = glm::mat4(0); - - int maxLevel = 0; - for (JointFramePose jointPose : JointPoses) { - maxLevel = jointPose.Level > maxLevel ? jointPose.Level : maxLevel; - } - - - for (JointFramePose jointPose : JointPoses) { - if (jointPose.Type == BlendType::Override) { - finalOverride += jointPose.Pose * jointPose.Weight; //Blend Overrides then apply to final blend - } else if(jointPose.Type == BlendType::Blend) { - finalBlend += jointPose.Pose * jointPose.Weight; - } else if (jointPose.Type == BlendType::Additive) { - //Soon - } - } - - if(finalOverride != glm::mat4(0)) { - finalBlend = finalOverride; - } - - glm::mat4 boneTransform = AdditiveBlend(bone, animationOffset, finalBlend); - boneMatrix = parentMatrix * boneTransform; - boneMatrices[bone->ID] = boneMatrix * bone->OffsetMatrix; } for (auto &child : bone->Children) { - AccumulateBoneTransforms(noRootMotion, animations, animationOffset, boneMatrices, child, boneMatrix); + AccumulateBoneTransforms(noRootMotion, animation, time, boneMatrices, additive, child, boneMatrix); } } @@ -444,7 +331,6 @@ glm::mat4 Skeleton::GetBoneTransform(const Bone* bone, const Animation* animatio } } - glm::mat4 Skeleton::GetBoneTransform(bool noRootMotion, const Bone* bone, std::vector animations, AnimationOffset animationOffset, glm::mat4 childMatrix) { glm::mat4 boneMatrix; @@ -555,7 +441,6 @@ glm::mat4 Skeleton::GetBoneTransform(bool noRootMotion, const Bone* bone, std::v } } - glm::mat4 Skeleton::GetBoneTransform(bool noRootMotion, const Bone* bone, std::vector animations, glm::mat4 childMatrix) { glm::mat4 boneMatrix; @@ -673,6 +558,50 @@ glm::mat4 Skeleton::GetBoneTransform(bool noRootMotion, const Bone* bone, std::v return boneMatrix; } + +std::vector Skeleton::BlendPoses(std::vector pose1, std::vector pose2, float weight) +{ + std::vector finalPose; + + if(pose1.size() != pose2.size()) { + LOG_ERROR("Number of bones does not match"); + return finalPose; + } + + for (int i = 0; i < pose1.size(); i++) { + glm::mat4 blendedPose = glm::mat4(0); + + blendedPose += pose1[i] * weight; + + blendedPose += pose2[i] * (1.f - weight); + + finalPose.push_back(blendedPose); + } + + return finalPose; +} + + +std::vector Skeleton::OverridePose(std::vector overridePose, std::vector targetPose) +{ + std::vector finalPose; + + if (overridePose.size() != targetPose.size()) { + LOG_ERROR("Number of bones does not match"); + return finalPose; + } + + for (int i = 0; i < overridePose.size(); i++) { + if(overridePose[i] != glm::mat4(1)) { + finalPose.push_back(overridePose[i]); + } else { + finalPose.push_back(targetPose[i]); + } + } + + return finalPose; +} + int Skeleton::GetBoneID(std::string name) { if (m_BonesByName.find(name) == m_BonesByName.end()) { @@ -681,47 +610,3 @@ int Skeleton::GetBoneID(std::string name) return m_BonesByName.at(name)->ID; } } - -void Skeleton::PrintSkeleton() -{ - if (LOG_LEVEL < LOG_LEVEL_DEBUG) { - return; - } - PrintSkeleton(RootBone, 0); -} - -void Skeleton::PrintSkeleton(const Bone* bone, int depthCount) -{ - std::stringstream ss; - ss << std::string(depthCount, ' '); - ss << bone->ID << ": " << bone->Name; - std::cout << ss.str() << std::endl; - - depthCount++; - - for (auto &child : bone->Children) { - PrintSkeleton(child, depthCount); - } -} - -int Skeleton::GetKeyframe(const Animation& animation, double time) -{ - -/* - if (time < 0) { - time = 0; - } - if (time >= animation.Duration) { - return animation..size() - 1; - } - - for (int keyframe = 0; keyframe < animation.Keyframes.size(); ++keyframe) { - if (animation.Keyframes[keyframe].Time > time) { - return (keyframe - 1) % animation.Keyframes.size(); - } - } -*/ - - - return 0; -} From 127edb4e604605610418ff4a6d33f06b6f9d0d8c Mon Sep 17 00:00:00 2001 From: viktorljung Date: Mon, 22 Feb 2016 17:47:30 +0100 Subject: [PATCH 030/130] Fixed some memory leaks --- include/Engine/Rendering/ModelJob.h | 4 ++-- resources/Schema/Entities/AnimationTests2.xml | 10 ++++++---- src/Engine/Rendering/BlendTree.cpp | 18 ++++++++++++++++++ src/Engine/Rendering/Skeleton.cpp | 4 +++- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/include/Engine/Rendering/ModelJob.h b/include/Engine/Rendering/ModelJob.h index 212a3888..c10d6389 100644 --- a/include/Engine/Rendering/ModelJob.h +++ b/include/Engine/Rendering/ModelJob.h @@ -125,7 +125,7 @@ struct ModelJob : RenderJob if (Skeleton != nullptr) { EntityWrapper entityWrapper = EntityWrapper(world, modelComponent.EntityID); - BlendTree = new ::BlendTree(entityWrapper, Skeleton); + BlendTree = std::shared_ptr<::BlendTree>(new ::BlendTree(entityWrapper, Skeleton)); } } }; @@ -149,7 +149,7 @@ struct ModelJob : RenderJob std::vector<::Skeleton::AnimationData> Animations; ::Skeleton::AnimationOffset AnimationOffset; - ::BlendTree* BlendTree = nullptr; + std::shared_ptr<::BlendTree> BlendTree = nullptr; glm::vec4 DiffuseColor; glm::vec4 SpecularColor; diff --git a/resources/Schema/Entities/AnimationTests2.xml b/resources/Schema/Entities/AnimationTests2.xml index ace71800..659ece9a 100644 --- a/resources/Schema/Entities/AnimationTests2.xml +++ b/resources/Schema/Entities/AnimationTests2.xml @@ -68,6 +68,7 @@ BlendOverride AimAdditive + 1 Models/Characters/Assault/AssaultAnimations.mesh @@ -93,7 +94,7 @@ AimRifle - + 0.5 true @@ -106,6 +107,7 @@ ShootRifleAnimation BlendWalkRun + 0 @@ -124,7 +126,7 @@ Run - + 1 @@ -135,7 +137,7 @@ Walk - + 1 @@ -148,7 +150,7 @@ ShootFastRifle - + 1 diff --git a/src/Engine/Rendering/BlendTree.cpp b/src/Engine/Rendering/BlendTree.cpp index 43d1d5fd..e5fb21a4 100644 --- a/src/Engine/Rendering/BlendTree.cpp +++ b/src/Engine/Rendering/BlendTree.cpp @@ -53,7 +53,25 @@ BlendTree::BlendTree(EntityWrapper ModelEntity, Skeleton* skeleton) BlendTree::~BlendTree() { + Node* currentNode = m_Root; + while (currentNode->Child[0] != nullptr) { + currentNode = currentNode->Child[0]; + } + + std::list m_NodesToRemove; + + while (currentNode != nullptr) { + currentNode = currentNode->Next(); + m_NodesToRemove.push_back(currentNode); + } + + for (auto it = m_NodesToRemove.begin(); it != m_NodesToRemove.end(); it++) { + if ((*it) != nullptr) { + delete (*it); + (*it) = nullptr; + } + } } void BlendTree::PrintTree() diff --git a/src/Engine/Rendering/Skeleton.cpp b/src/Engine/Rendering/Skeleton.cpp index 4745b36d..6a409d3c 100644 --- a/src/Engine/Rendering/Skeleton.cpp +++ b/src/Engine/Rendering/Skeleton.cpp @@ -591,12 +591,14 @@ std::vector Skeleton::OverridePose(std::vector overridePos return finalPose; } - for (int i = 0; i < overridePose.size(); i++) { + for (int i = 0; i < targetPose.size(); i++) { if(overridePose[i] != glm::mat4(1)) { finalPose.push_back(overridePose[i]); } else { finalPose.push_back(targetPose[i]); } + + //finalPose.push_back(overridePose[i]); } return finalPose; From 606a9bf94f25cf3c2bd4fa93b7a4c7a7c3ac4964 Mon Sep 17 00:00:00 2001 From: viktorljung Date: Tue, 23 Feb 2016 17:06:41 +0100 Subject: [PATCH 031/130] BlendTree now working but has some memory leaks --- include/Engine/Rendering/BlendTree.h | 5 +- include/Engine/Rendering/Skeleton.h | 14 +- resources/Schema/Components/BlendOverride.xml | 1 - resources/Schema/Components/BlendOverride.xsd | 1 - resources/Schema/Entities/AnimationTests2.xml | 112 ++++++----- src/Engine/Rendering/BlendTree.cpp | 64 ++++--- src/Engine/Rendering/Skeleton.cpp | 181 ++++++++++++------ 7 files changed, 243 insertions(+), 135 deletions(-) diff --git a/include/Engine/Rendering/BlendTree.h b/include/Engine/Rendering/BlendTree.h index 431cb8b2..694776a1 100644 --- a/include/Engine/Rendering/BlendTree.h +++ b/include/Engine/Rendering/BlendTree.h @@ -26,7 +26,8 @@ public: Node* Parent = nullptr; Node* Child[2] = { nullptr, nullptr }; NodeType Type; - std::vector Pose; + std::map Pose; + //std::vector Pose; float Weight = 0.f; Node* Next() { @@ -69,7 +70,7 @@ private: void FillTree(Node* parentNode, EntityWrapper parentEntity, Skeleton* skeleton); BlendTree::Node* FillTreeByName(Node* parentNode, std::string name, EntityWrapper parentEntity, Skeleton* skeleton); - void Blend(Skeleton* skeleton, std::vector& pose); + void Blend(Skeleton* skeleton, std::map& pose); }; #endif diff --git a/include/Engine/Rendering/Skeleton.h b/include/Engine/Rendering/Skeleton.h index 58021416..e380b6f2 100644 --- a/include/Engine/Rendering/Skeleton.h +++ b/include/Engine/Rendering/Skeleton.h @@ -111,7 +111,7 @@ public: std::vector GetFrameBones(); - std::vector GetFrameBones(const Animation* animation, double time, bool additive, bool noRootMotion = false); + std::map GetFrameBones(const Animation* animation, double time, bool additive, bool noRootMotion = false); void AccumulateBoneTransforms(bool noRootMotion, const Animation* animation, double time, std::map& boneMatrices, bool additive, const Bone* bone, glm::mat4 parentMatrix); const Animation* GetAnimation(std::string name); @@ -124,11 +124,17 @@ public: glm::mat4 GetBoneTransform(bool noRootMotion, const Bone* bone, std::vector animations, glm::mat4 childMatrix); - std::vector BlendPoses(std::vector pose1, std::vector pose2, float weight); - std::vector OverridePose(std::vector overridePose, std::vector targetPose); + std::map BlendPoses(std::map pose1, std::map pose2, float weight); + std::map OverridePose(std::map overridePose, std::map targetPose); + std::map BlendPoseAdditive(std::map additivePose, std::map targetPose); + + std::vector GetFinalPose(std::map& boneMatrices); + void AccumulateFinalPose(std::map& boneMatrices, const Bone* bone, glm::mat4 parentMatrix); + + void AdditiveBoneTransforms(const Animation* animation, double time, std::map& boneMatrices, const Bone* bone); private: - glm::mat4 GetOffsetTransform(const Bone* bone, AnimationOffset animationOffset); + glm::mat4 GetAdditiveBonePose(const Bone* bone, const Animation* animation, double time); glm::mat4 GetBonePose(const Bone* bone, const Animation* animation, double time, bool noRootMotion); std::map m_BonesByName; diff --git a/resources/Schema/Components/BlendOverride.xml b/resources/Schema/Components/BlendOverride.xml index a9f2095a..c44a2d22 100644 --- a/resources/Schema/Components/BlendOverride.xml +++ b/resources/Schema/Components/BlendOverride.xml @@ -2,5 +2,4 @@ - 1.0 \ No newline at end of file diff --git a/resources/Schema/Components/BlendOverride.xsd b/resources/Schema/Components/BlendOverride.xsd index 27fc01ed..8cf6dbd6 100644 --- a/resources/Schema/Components/BlendOverride.xsd +++ b/resources/Schema/Components/BlendOverride.xsd @@ -7,7 +7,6 @@ - diff --git a/resources/Schema/Entities/AnimationTests2.xml b/resources/Schema/Entities/AnimationTests2.xml index 659ece9a..40761b13 100644 --- a/resources/Schema/Entities/AnimationTests2.xml +++ b/resources/Schema/Entities/AnimationTests2.xml @@ -65,11 +65,10 @@ - - BlendOverride - AimAdditive - 1 - + + AimAdditive + BlendOverride + Models/Characters/Assault/AssaultAnimations.mesh @@ -93,9 +92,8 @@ - AimRifle - - 0.5 + AimRifleA + true @@ -106,57 +104,79 @@ ShootRifleAnimation - BlendWalkRun - 0 + MovementBlend - - - - RunAnimtaion - WalkAnimation - 1 - - - - - - - - Run - - 1 - - - - - - - - - Walk - - 1 - - - - - - - - ShootFastRifle - + ShootFastRifleU + 1 + + + + BlendWalkRun + StrafeAnimation + 1 + + + + + + + + StrafeRightF + + 1 + + + + + + + + + RunAnimtaion + WalkAnimation + 0.43000054359436035 + + + + + + + + RunF + + 1 + + + + + + + + + WalkF + + 1 + + + + + + + + + diff --git a/src/Engine/Rendering/BlendTree.cpp b/src/Engine/Rendering/BlendTree.cpp index e5fb21a4..a5f10188 100644 --- a/src/Engine/Rendering/BlendTree.cpp +++ b/src/Engine/Rendering/BlendTree.cpp @@ -130,6 +130,7 @@ void BlendTree::FillTree(Node* parentNode, EntityWrapper parentEntity, Skeleton* node->Name = childEntity.Name(); node->Parent = parentNode; node->Type = NodeType::Blend; + (double&)childEntity["Blend"]["Weight"] = glm::clamp((float)(double)childEntity["Blend"]["Weight"], 0.f, 1.f); node->Weight = (double)childEntity["Blend"]["Weight"]; parentNode->Child[childIndex] = node; childIndex++; @@ -183,6 +184,7 @@ BlendTree::Node* BlendTree::FillTreeByName(Node* parentNode, std::string name, E node->Name = childEntity.Name(); node->Parent = parentNode; node->Type = NodeType::Blend; + (double&)childEntity["Blend"]["Weight"] = glm::clamp((float)(double)childEntity["Blend"]["Weight"], 0.f, 1.f); node->Weight = (double)childEntity["Blend"]["Weight"]; node->Child[0] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose1"], childEntity, skeleton); node->Child[1] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose2"], childEntity, skeleton); @@ -208,7 +210,7 @@ BlendTree::Node* BlendTree::FillTreeByName(Node* parentNode, std::string name, E return nullptr; } -void BlendTree::Blend(Skeleton* skeleton, std::vector& pose) +void BlendTree::Blend(Skeleton* skeleton, std::map& pose) { Node* currentNode; Node* start = m_Root; @@ -220,30 +222,37 @@ void BlendTree::Blend(Skeleton* skeleton, std::vector& pose) LOG_INFO("\n\n"); while (m_Root->Pose.size() == 0) { if(currentNode->Pose.size() == 0) { - if(currentNode->Child[0]->Pose.size() != 0 && currentNode->Child[1]->Pose.size() != 0) { + if (currentNode->Child[0] != nullptr && currentNode->Child[1] != nullptr) { + if (currentNode->Child[0]->Pose.size() != 0 && currentNode->Child[1]->Pose.size() != 0) { - switch (currentNode->Type) { - case BlendTree::NodeType::Additive: - currentNode->Pose = skeleton->BlendPoses(currentNode->Child[0]->Pose, currentNode->Child[1]->Pose, currentNode->Weight); - break; - case BlendTree::NodeType::Blend: - currentNode->Pose = skeleton->BlendPoses(currentNode->Child[0]->Pose, currentNode->Child[1]->Pose, currentNode->Weight); - break; - case BlendTree::NodeType::Override: - currentNode->Pose = skeleton->OverridePose(currentNode->Child[0]->Pose, currentNode->Child[1]->Pose); - break; - case BlendTree::NodeType::Animation: - // do nothing - break; + switch (currentNode->Type) { + case BlendTree::NodeType::Additive: + currentNode->Pose = skeleton->BlendPoseAdditive(currentNode->Child[0]->Pose, currentNode->Child[1]->Pose); + break; + case BlendTree::NodeType::Blend: + currentNode->Pose = skeleton->BlendPoses(currentNode->Child[0]->Pose, currentNode->Child[1]->Pose, currentNode->Weight); + break; + case BlendTree::NodeType::Override: + currentNode->Pose = skeleton->OverridePose(currentNode->Child[0]->Pose, currentNode->Child[1]->Pose); + break; + case BlendTree::NodeType::Animation: + // do nothing + break; + } + + LOG_INFO("Blending %s and %s", currentNode->Child[0]->Name.c_str(), currentNode->Child[1]->Name.c_str()); + } + } else if (currentNode->Child[0] != nullptr) { + if (currentNode->Child[0]->Pose.size() != 0) { + currentNode->Pose = currentNode->Child[0]->Pose; + } + } else if (currentNode->Child[1] != nullptr) { + if (currentNode->Child[1]->Pose.size() != 0) { + currentNode->Pose = currentNode->Child[1]->Pose; } - - - LOG_INFO("Blending %s and %s", currentNode->Child[0]->Name.c_str(), currentNode->Child[1]->Name.c_str()); } } - - currentNode = currentNode->Next(); if (currentNode == nullptr) { @@ -257,17 +266,20 @@ void BlendTree::Blend(Skeleton* skeleton, std::vector& pose) std::vector BlendTree::GetBoneTransforms(Skeleton* skeleton) { + std::vector finalPose; if (skeleton == nullptr || m_Root == nullptr) { - std::vector pose; - for (auto& b : skeleton->Bones) { - pose.push_back(glm::mat4(1)); + + for (int i = 0; i < skeleton->Bones.size(); i++) { + finalPose.push_back(glm::mat4(1)); } - return pose; + return finalPose; } - std::vector pose; + std::map pose; Blend(skeleton, pose); - return pose; + finalPose = skeleton->GetFinalPose(pose); + + return finalPose; } diff --git a/src/Engine/Rendering/Skeleton.cpp b/src/Engine/Rendering/Skeleton.cpp index 6a409d3c..e951b3c5 100644 --- a/src/Engine/Rendering/Skeleton.cpp +++ b/src/Engine/Rendering/Skeleton.cpp @@ -49,25 +49,26 @@ std::vector Skeleton::GetFrameBones() } return finalMatrices; } -std::vector Skeleton::GetFrameBones(const Animation* animation, const double time, bool additive, bool noRootMotion /*= false*/) +std::map Skeleton::GetFrameBones(const Animation* animation, const double time, bool additive, bool noRootMotion /*= false*/) { if (animation == nullptr) { - std::vector finalMatrices; + std::map finalMatrices; for (auto& b : Bones) { - finalMatrices.push_back(glm::mat4(1)); + finalMatrices[b.second->ID] = glm::mat4(1); } return finalMatrices; } std::map frameBones; - AccumulateBoneTransforms(true, animation, time, frameBones, additive, RootBone, glm::mat4(1)); - std::vector finalMatrices; - for (auto &kv : frameBones) { - finalMatrices.push_back(kv.second); + if(!additive) { + AccumulateBoneTransforms(true, animation, time, frameBones, additive, RootBone, glm::mat4(1)); + } else { + AdditiveBoneTransforms(animation, time, frameBones, RootBone); } - return finalMatrices; + + return frameBones; } void Skeleton::AccumulateBoneTransforms(bool noRootMotion, const Animation* animation, double time, std::map& boneMatrices, bool additive, const Bone* bone, glm::mat4 parentMatrix) @@ -77,7 +78,7 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, const Animation* anim } glm::mat4 boneMatrix; - + if (animation->JointAnimations.find(bone->ID) != animation->JointAnimations.end()) { std::vector boneKeyFrames = animation->JointAnimations.at(bone->ID); @@ -118,21 +119,21 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, const Animation* anim position.z = 0; } - boneMatrix = parentMatrix * (glm::translate(position) * glm::toMat4(rotation) * glm::scale(scale)); - boneMatrices[bone->ID] = boneMatrix *bone->OffsetMatrix; + boneMatrix = (glm::translate(position) * glm::toMat4(rotation) * glm::scale(scale)); + boneMatrices[bone->ID] = boneMatrix;// *bone->OffsetMatrix; } else { // 1 keyframes for the current bone currentFrame = boneKeyFrames.at(0); - boneMatrix = parentMatrix * (glm::translate(currentFrame.BoneProperties.Position) * glm::toMat4(currentFrame.BoneProperties.Rotation) * glm::scale(currentFrame.BoneProperties.Scale)); - boneMatrices[bone->ID] = boneMatrix *bone->OffsetMatrix; + boneMatrix = (glm::translate(currentFrame.BoneProperties.Position) * glm::toMat4(currentFrame.BoneProperties.Rotation) * glm::scale(currentFrame.BoneProperties.Scale)); + boneMatrices[bone->ID] = boneMatrix;// *bone->OffsetMatrix; } } else { // 0 keyframes for the current bone if (bone->Parent) { - boneMatrix = parentMatrix * (glm::inverse(bone->OffsetMatrix) * bone->Parent->OffsetMatrix); - boneMatrices[bone->ID] = boneMatrix *bone->OffsetMatrix; + //boneMatrix = parentMatrix * (glm::inverse(bone->OffsetMatrix) * bone->Parent->OffsetMatrix); + //boneMatrices[bone->ID] = boneMatrix *bone->OffsetMatrix; } else { - boneMatrix = glm::inverse(bone->OffsetMatrix); - boneMatrices[bone->ID] = parentMatrix; + //boneMatrix = glm::inverse(bone->OffsetMatrix); + //boneMatrices[bone->ID] = parentMatrix; } } @@ -142,22 +143,36 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, const Animation* anim } -glm::mat4 Skeleton::AdditiveBlend(const Bone* bone, AnimationOffset animationOffset, glm::mat4 targetPose) +void Skeleton::AdditiveBoneTransforms(const Animation* animation, double time, std::map& boneMatrices, const Bone* bone) { - AnimationOffset refOffset = animationOffset; - refOffset.time = 0.5f; // reference pose is at 0.5s for now - glm::mat4 refPose = GetOffsetTransform(bone, refOffset); - glm::mat4 srcPose = GetOffsetTransform(bone, animationOffset); - glm::mat4 differencePose = srcPose * glm::inverse(refPose); - glm::mat4 finalPose = differencePose * targetPose; - return finalPose; + if (animation->JointAnimations.find(bone->ID) != animation->JointAnimations.end()) { + glm::mat4 refPose = GetAdditiveBonePose(bone, animation, 0.0); + glm::mat4 srcPose = GetAdditiveBonePose(bone, animation, time); + glm::mat4 boneMatrix = srcPose * glm::inverse(refPose); + boneMatrices[bone->ID] = boneMatrix; + } + + for (auto &child : bone->Children) { + AdditiveBoneTransforms(animation, time, boneMatrices, child); + } } -glm::mat4 Skeleton::GetOffsetTransform(const Bone* bone, AnimationOffset animationOffset) -{ - const Animation* animation = animationOffset.animation; - float time = animationOffset.time; + +glm::mat4 Skeleton::AdditiveBlend(const Bone* bone, AnimationOffset animationOffset, glm::mat4 targetPose) +{ +/* + AnimationOffset refOffset = animationOffset; + refOffset.time = 0.5f; // reference pose is at 0.5s for now + glm::mat4 refPose = GetAdditiveBonePose(bone, refOffset); + glm::mat4 srcPose = GetAdditiveBonePose(bone, animationOffset); + glm::mat4 differencePose = srcPose * glm::inverse(refPose); + glm::mat4 finalPose = differencePose * targetPose;*/ + return glm::mat4(); +} + +glm::mat4 Skeleton::GetAdditiveBonePose(const Bone* bone, const Animation* animation, double time) +{ glm::vec3 position = glm::vec3(0); glm::quat rotation = glm::quat(); glm::vec3 scale = glm::vec3(1); @@ -559,51 +574,107 @@ return boneMatrix; } -std::vector Skeleton::BlendPoses(std::vector pose1, std::vector pose2, float weight) +std::map Skeleton::BlendPoses(std::map pose1, std::map pose2, float weight) { - std::vector finalPose; + std::map finalPose; - if(pose1.size() != pose2.size()) { - LOG_ERROR("Number of bones does not match"); - return finalPose; - } - - for (int i = 0; i < pose1.size(); i++) { + for (auto& b : Bones) { + int boneID = b.second->ID; glm::mat4 blendedPose = glm::mat4(0); - blendedPose += pose1[i] * weight; - - blendedPose += pose2[i] * (1.f - weight); - - finalPose.push_back(blendedPose); + if(pose1.find(boneID) != pose1.end() && pose2.find(boneID) != pose2.end()) { + blendedPose += pose1.at(boneID) * weight; + blendedPose += pose2.at(boneID) * (1.f - weight); + finalPose[boneID] = blendedPose; + } else if(pose1.find(boneID) != pose1.end()) { + finalPose[boneID] = pose1.at(boneID); + } else if (pose2.find(boneID) != pose2.end()) { + finalPose[boneID] = pose2.at(boneID); + } } return finalPose; } -std::vector Skeleton::OverridePose(std::vector overridePose, std::vector targetPose) +std::map Skeleton::OverridePose(std::map overridePose, std::map targetPose) { - std::vector finalPose; + std::map finalPose; - if (overridePose.size() != targetPose.size()) { - LOG_ERROR("Number of bones does not match"); - return finalPose; - } - - for (int i = 0; i < targetPose.size(); i++) { - if(overridePose[i] != glm::mat4(1)) { - finalPose.push_back(overridePose[i]); - } else { - finalPose.push_back(targetPose[i]); + for (auto& b : Bones) { + int boneID = b.second->ID; + if (overridePose.find(boneID) != overridePose.end()) { + finalPose[boneID] = overridePose.at(boneID); + } else if (targetPose.find(boneID) != targetPose.end()) { + finalPose[boneID] = targetPose.at(boneID); } + } + return finalPose; +} - //finalPose.push_back(overridePose[i]); + +std::map Skeleton::BlendPoseAdditive(std::map additivePose, std::map targetPose) +{ + std::map finalPose; + + for (auto& b : Bones) { + int boneID = b.second->ID; + glm::mat4 blendedPose = glm::mat4(1); + + if (additivePose.find(boneID) != additivePose.end() && targetPose.find(boneID) != targetPose.end()) { + blendedPose = additivePose.at(boneID) * targetPose.at(boneID); + finalPose[boneID] = blendedPose; + + } else if (additivePose.find(boneID) != additivePose.end()) { + finalPose[boneID] = additivePose.at(boneID); + } else if (targetPose.find(boneID) != targetPose.end()) { + finalPose[boneID] = targetPose.at(boneID); + } } return finalPose; } +std::vector Skeleton::GetFinalPose(std::map& boneMatrices) +{ + std::vector finalPose; + + AccumulateFinalPose(boneMatrices, RootBone, glm::mat4(1)); + + + for(auto& b : boneMatrices) { + finalPose.push_back(b.second); + } + + return finalPose; +} + +void Skeleton::AccumulateFinalPose(std::map& boneMatrices, const Bone* bone, glm::mat4 parentMatrix) +{ + + glm::mat4 boneMatrix; + + + if (boneMatrices.find(bone->ID) != boneMatrices.end()) { + + boneMatrix = parentMatrix * boneMatrices.at(bone->ID); + boneMatrices[bone->ID] = boneMatrix * bone->OffsetMatrix; + + } else { + if (bone->Parent) { + boneMatrix = parentMatrix * (glm::inverse(bone->OffsetMatrix) * bone->Parent->OffsetMatrix); + boneMatrices[bone->ID] = boneMatrix * bone->OffsetMatrix; + } else { + boneMatrix = glm::inverse(bone->OffsetMatrix); + boneMatrices[bone->ID] = parentMatrix; + } + } + + for (auto &child : bone->Children) { + AccumulateFinalPose(boneMatrices, child, boneMatrix); + } +} + int Skeleton::GetBoneID(std::string name) { if (m_BonesByName.find(name) == m_BonesByName.end()) { From c97d0d938138886e8d0fc4d41abd950b6bcf304f Mon Sep 17 00:00:00 2001 From: viktorljung Date: Thu, 25 Feb 2016 11:30:09 +0100 Subject: [PATCH 032/130] Fixed memory leaks and cleaned up Skeleton and BlendTree --- include/Engine/Rendering/BlendTree.h | 13 +- include/Engine/Rendering/ModelJob.h | 3 - include/Engine/Rendering/Skeleton.h | 59 +-- resources/Schema/Entities/AnimationTests2.xml | 372 +++++++++++++++++- resources/Schema/Entities/yeeee.xml | 122 ++++++ src/Engine/Rendering/BlendTree.cpp | 137 ++----- src/Engine/Rendering/BoneAttachmentSystem.cpp | 8 +- src/Engine/Rendering/DrawFinalPass.cpp | 56 +-- src/Engine/Rendering/PickingPass.cpp | 28 +- src/Engine/Rendering/Skeleton.cpp | 353 +++-------------- 10 files changed, 606 insertions(+), 545 deletions(-) create mode 100644 resources/Schema/Entities/yeeee.xml diff --git a/include/Engine/Rendering/BlendTree.h b/include/Engine/Rendering/BlendTree.h index 694776a1..8d192cfe 100644 --- a/include/Engine/Rendering/BlendTree.h +++ b/include/Engine/Rendering/BlendTree.h @@ -60,17 +60,22 @@ public: BlendTree(EntityWrapper ModelEntity, Skeleton* skeleton); ~BlendTree(); - std::vector GetBoneTransforms(Skeleton* skeleton); + + std::vector GetFinalPose() { return m_FinalPose; } + + void PrintTree(); private: + Skeleton* m_Skeleton = nullptr; Node* m_Root = nullptr; - void FillTree(Node* parentNode, EntityWrapper parentEntity, Skeleton* skeleton); - BlendTree::Node* FillTreeByName(Node* parentNode, std::string name, EntityWrapper parentEntity, Skeleton* skeleton); + std::vector m_FinalPose; + std::vector AccumulateFinalPose(); + BlendTree::Node* FillTreeByName(Node* parentNode, std::string name, EntityWrapper parentEntity); - void Blend(Skeleton* skeleton, std::map& pose); + void Blend(std::map& pose); }; #endif diff --git a/include/Engine/Rendering/ModelJob.h b/include/Engine/Rendering/ModelJob.h index c10d6389..4ea7a1f6 100644 --- a/include/Engine/Rendering/ModelJob.h +++ b/include/Engine/Rendering/ModelJob.h @@ -146,9 +146,6 @@ struct ModelJob : RenderJob glm::vec4 Color; const ::Model* Model = nullptr; ::Skeleton* Skeleton = nullptr; - std::vector<::Skeleton::AnimationData> Animations; - ::Skeleton::AnimationOffset AnimationOffset; - std::shared_ptr<::BlendTree> BlendTree = nullptr; glm::vec4 DiffuseColor; diff --git a/include/Engine/Rendering/Skeleton.h b/include/Engine/Rendering/Skeleton.h index e380b6f2..fa5a329d 100644 --- a/include/Engine/Rendering/Skeleton.h +++ b/include/Engine/Rendering/Skeleton.h @@ -68,34 +68,6 @@ public: std::map> JointAnimations; }; - enum class BlendType - { - Additive, - Blend, - Override, - }; - - struct AnimationData - { - const Animation* animation; - BlendType blendType; - float time; - int level; - float weight; - }; - - struct JointFramePose { - BlendType Type; - int Level = 0; - glm::mat4 Pose = glm::mat4(0); - float Weight = 0.0f; - }; - - struct AnimationOffset { - const Animation* animation; - float time; - }; - Skeleton() { } ~Skeleton(); @@ -106,36 +78,23 @@ public: // Attach a new bone to the skeleton // Returns: New bone index int CreateBone(int ID, int parentID, std::string name, glm::mat4 offsetMatrix); - int GetBoneID(std::string name); - - std::vector GetFrameBones(); + const Animation* GetAnimation(std::string name); std::map GetFrameBones(const Animation* animation, double time, bool additive, bool noRootMotion = false); - void AccumulateBoneTransforms(bool noRootMotion, const Animation* animation, double time, std::map& boneMatrices, bool additive, const Bone* bone, glm::mat4 parentMatrix); - - const Animation* GetAnimation(std::string name); - glm::mat4 AdditiveBlend(const Bone* bone, AnimationOffset animationOffset, glm::mat4 targetPose); - - std::map Animations; - glm::mat4 GetBoneTransform(const Bone* bone, const Animation* animation, float time, glm::mat4 childMatrix); - glm::mat4 GetBoneTransform(bool noRootMotion, const Bone* bone, std::vector animations, AnimationOffset animationOffset, glm::mat4 childMatrix); - glm::mat4 GetBoneTransform(bool noRootMotion, const Bone* bone, std::vector animations, glm::mat4 childMatrix); - - - std::map BlendPoses(std::map pose1, std::map pose2, float weight); - std::map OverridePose(std::map overridePose, std::map targetPose); - std::map BlendPoseAdditive(std::map additivePose, std::map targetPose); - + std::map BlendPoses(const std::map& pose1, const std::map& pose2, float weight); + std::map OverridePose(const std::map& overridePose, const std::map& targetPose); + std::map BlendPoseAdditive(const std::map& additivePose, const std::map& targetPose); std::vector GetFinalPose(std::map& boneMatrices); - void AccumulateFinalPose(std::map& boneMatrices, const Bone* bone, glm::mat4 parentMatrix); - - void AdditiveBoneTransforms(const Animation* animation, double time, std::map& boneMatrices, const Bone* bone); - + + std::map Animations; private: glm::mat4 GetAdditiveBonePose(const Bone* bone, const Animation* animation, double time); glm::mat4 GetBonePose(const Bone* bone, const Animation* animation, double time, bool noRootMotion); + void AccumulateFinalPose(std::map& boneMatrices, const Bone* bone, glm::mat4 parentMatrix); + void AdditiveBoneTransforms(const Animation* animation, double time, std::map& boneMatrices, const Bone* bone); + void AccumulateBoneTransforms(bool noRootMotion, const Animation* animation, double time, std::map& boneMatrices, const Bone* bone, glm::mat4 parentMatrix); std::map m_BonesByName; diff --git a/resources/Schema/Entities/AnimationTests2.xml b/resources/Schema/Entities/AnimationTests2.xml index 40761b13..4779bbaf 100644 --- a/resources/Schema/Entities/AnimationTests2.xml +++ b/resources/Schema/Entities/AnimationTests2.xml @@ -58,6 +58,7 @@ + @@ -113,7 +114,7 @@ ShootFastRifleU - + 1 @@ -134,7 +135,7 @@ StrafeRightF - + 1 @@ -155,7 +156,7 @@ RunF - + 1 @@ -166,7 +167,370 @@ WalkF - + + 1 + + + + + + + + + + + + + + + + + AimAdditive + BlendOverride + + + Models/Characters/Assault/AssaultAnimations.mesh + + + + + + + + + + + R_Arm_Weapon_Joint + + + Models/Weapons/Blue/AssaultWeaponBlue.mesh + + + + + + + + + + + AimRifleA + + true + + + + + + + + + ShootRifleAnimation + MovementBlend + + + + + + + + ShootFastRifleU + + 1 + + + + + + + + + BlendWalkRun + StrafeAnimation + 1 + + + + + + + + StrafeRightF + + 1 + + + + + + + + + RunAnimtaion + WalkAnimation + 0.43000054359436035 + + + + + + + + RunF + + 1 + + + + + + + + + WalkF + + 1 + + + + + + + + + + + + + + + + + AimAdditive + BlendOverride + + + Models/Characters/Assault/AssaultAnimations.mesh + + + + + + + + + + + R_Arm_Weapon_Joint + + + Models/Weapons/Blue/AssaultWeaponBlue.mesh + + + + + + + + + + + AimRifleA + + true + + + + + + + + + ShootRifleAnimation + MovementBlend + + + + + + + + ShootFastRifleU + + 1 + + + + + + + + + BlendWalkRun + StrafeAnimation + 1 + + + + + + + + StrafeRightF + + 1 + + + + + + + + + RunAnimtaion + WalkAnimation + 0.43000054359436035 + + + + + + + + RunF + + 1 + + + + + + + + + WalkF + + 1 + + + + + + + + + + + + + + + + + AimAdditive + BlendOverride + + + Models/Characters/Assault/AssaultAnimations.mesh + + + + + + + + + + + R_Arm_Weapon_Joint + + + Models/Weapons/Blue/AssaultWeaponBlue.mesh + + + + + + + + + + + AimRifleA + + true + + + + + + + + + ShootRifleAnimation + MovementBlend + + + + + + + + ShootFastRifleU + + 1 + + + + + + + + + BlendWalkRun + StrafeAnimation + 1 + + + + + + + + StrafeRightF + + 1 + + + + + + + + + RunAnimtaion + WalkAnimation + 0.43000054359436035 + + + + + + + + RunF + + 1 + + + + + + + + + WalkF + 1 diff --git a/resources/Schema/Entities/yeeee.xml b/resources/Schema/Entities/yeeee.xml new file mode 100644 index 00000000..d3853b8f --- /dev/null +++ b/resources/Schema/Entities/yeeee.xml @@ -0,0 +1,122 @@ + + + + + + AimAdditive + BlendOverride + + + Models/Characters/Assault/AssaultAnimations.mesh + + + + + + + + + R_Arm_Weapon_Joint + + + Models/Weapons/Blue/AssaultWeaponBlue.mesh + + + + + + + + + + + AimRifleA + + true + + + + + + + + + ShootRifleAnimation + MovementBlend + + + + + + + + ShootFastRifleU + + 1 + + + + + + + + + BlendWalkRun + StrafeAnimation + 1 + + + + + + + + StrafeRightF + + 1 + + + + + + + + + RunAnimtaion + WalkAnimation + 0.43000054359436035 + + + + + + + + RunF + + 1 + + + + + + + + + WalkF + + 1 + + + + + + + + + + + + + + diff --git a/src/Engine/Rendering/BlendTree.cpp b/src/Engine/Rendering/BlendTree.cpp index a5f10188..1d628a06 100644 --- a/src/Engine/Rendering/BlendTree.cpp +++ b/src/Engine/Rendering/BlendTree.cpp @@ -2,6 +2,10 @@ BlendTree::BlendTree(EntityWrapper ModelEntity, Skeleton* skeleton) { + + m_Skeleton = skeleton; + + auto itPair = ModelEntity.World->GetChildren(ModelEntity.ID); if (itPair.first == itPair.second) { return; @@ -16,7 +20,7 @@ BlendTree::BlendTree(EntityWrapper ModelEntity, Skeleton* skeleton) m_Root = new Node(); m_Root->Name = ModelEntity.Name(); - m_Root->Pose = skeleton->GetFrameBones(animation, (double)ModelEntity["Animation"]["Time"], (bool)ModelEntity["Animation"]["Additive"]); + m_Root->Pose = m_Skeleton->GetFrameBones(animation, (double)ModelEntity["Animation"]["Time"], (bool)ModelEntity["Animation"]["Additive"]); m_Root->Parent = nullptr; m_Root->Type = NodeType::Animation; @@ -26,26 +30,27 @@ BlendTree::BlendTree(EntityWrapper ModelEntity, Skeleton* skeleton) m_Root->Parent = nullptr; m_Root->Type = NodeType::Blend; m_Root->Weight = (double)ModelEntity["Blend"]["Weight"]; - m_Root->Child[0] = FillTreeByName(m_Root, (std::string)ModelEntity["Blend"]["Pose1"], ModelEntity, skeleton); - m_Root->Child[1] = FillTreeByName(m_Root, (std::string)ModelEntity["Blend"]["Pose2"], ModelEntity, skeleton); + m_Root->Child[0] = FillTreeByName(m_Root, (std::string)ModelEntity["Blend"]["Pose1"], ModelEntity); + m_Root->Child[1] = FillTreeByName(m_Root, (std::string)ModelEntity["Blend"]["Pose2"], ModelEntity); } else if (ModelEntity.HasComponent("BlendOverride")) { m_Root = new Node(); m_Root->Name = ModelEntity.Name(); m_Root->Parent = nullptr; m_Root->Type = NodeType::Override; - m_Root->Child[0] = FillTreeByName(m_Root, (std::string)ModelEntity["BlendOverride"]["Master"], ModelEntity, skeleton); - m_Root->Child[1] = FillTreeByName(m_Root, (std::string)ModelEntity["BlendOverride"]["Slave"], ModelEntity, skeleton); + m_Root->Child[0] = FillTreeByName(m_Root, (std::string)ModelEntity["BlendOverride"]["Master"], ModelEntity); + m_Root->Child[1] = FillTreeByName(m_Root, (std::string)ModelEntity["BlendOverride"]["Slave"], ModelEntity); } else if (ModelEntity.HasComponent("BlendAdditive")) { m_Root = new Node(); m_Root->Name = ModelEntity.Name(); m_Root->Parent = nullptr; m_Root->Type = NodeType::Additive; - m_Root->Child[0] = FillTreeByName(m_Root, (std::string)ModelEntity["BlendAdditive"]["Adder"], ModelEntity, skeleton); - m_Root->Child[1] = FillTreeByName(m_Root, (std::string)ModelEntity["BlendAdditive"]["Receiver"], ModelEntity, skeleton); + m_Root->Child[0] = FillTreeByName(m_Root, (std::string)ModelEntity["BlendAdditive"]["Adder"], ModelEntity); + m_Root->Child[1] = FillTreeByName(m_Root, (std::string)ModelEntity["BlendAdditive"]["Receiver"], ModelEntity); } + m_FinalPose = AccumulateFinalPose(); // PrintTree(); @@ -62,15 +67,12 @@ BlendTree::~BlendTree() std::list m_NodesToRemove; while (currentNode != nullptr) { - currentNode = currentNode->Next(); m_NodesToRemove.push_back(currentNode); + currentNode = currentNode->Next(); } for (auto it = m_NodesToRemove.begin(); it != m_NodesToRemove.end(); it++) { - if ((*it) != nullptr) { - delete (*it); - (*it) = nullptr; - } + delete (*it); } } @@ -89,92 +91,26 @@ void BlendTree::PrintTree() currentNode = currentNode->Next(); } - + } - - -void BlendTree::FillTree(Node* parentNode, EntityWrapper parentEntity, Skeleton* skeleton) +BlendTree::Node* BlendTree::FillTreeByName(Node* parentNode, std::string name, EntityWrapper parentEntity) { - auto itPair = parentEntity.World->GetChildren(parentEntity.ID); - if (itPair.first == itPair.second) { - return; // no children - } - - unsigned int childIndex = 0; - for (auto it = itPair.first; it != itPair.second; ++it) { - - EntityWrapper childEntity = EntityWrapper(parentEntity.World, it->second); - - if(!childEntity.Valid()) { - continue; - } - - if (childEntity.HasComponent("Animation")) { - const Skeleton::Animation* animation = skeleton->GetAnimation(childEntity["Animation"]["AnimationName"]); - if(animation == nullptr) { - continue; - } - - Node* node = new Node(); - node->Name = childEntity.Name(); - node->Pose = skeleton->GetFrameBones(animation, (double)childEntity["Animation"]["Time"], (bool)childEntity["Animation"]["Additive"]); - node->Parent = parentNode; - node->Type = NodeType::Animation; - parentNode->Child[childIndex] = node; - childIndex++; - FillTree(node, childEntity, skeleton); - - } else if (childEntity.HasComponent("Blend")) { - Node* node = new Node(); - node->Name = childEntity.Name(); - node->Parent = parentNode; - node->Type = NodeType::Blend; - (double&)childEntity["Blend"]["Weight"] = glm::clamp((float)(double)childEntity["Blend"]["Weight"], 0.f, 1.f); - node->Weight = (double)childEntity["Blend"]["Weight"]; - parentNode->Child[childIndex] = node; - childIndex++; - FillTree(node, childEntity, skeleton); - - } else if (childEntity.HasComponent("BlendOverride")) { - Node* node = new Node(); - node->Name = childEntity.Name(); - node->Parent = parentNode; - node->Type = NodeType::Override; - parentNode->Child[childIndex] = node; - childIndex++; - FillTree(node, childEntity, skeleton); - - } else if (childEntity.HasComponent("BlendAdditive")) { - Node* node = new Node(); - node->Name = childEntity.Name(); - node->Parent = parentNode; - node->Type = NodeType::Additive; - parentNode->Child[childIndex] = node; - childIndex++; - FillTree(node, childEntity, skeleton); - } - } -} - - -BlendTree::Node* BlendTree::FillTreeByName(Node* parentNode, std::string name, EntityWrapper parentEntity, Skeleton* skeleton) -{ - EntityWrapper childEntity = parentEntity.FirstChildByName(name); + EntityWrapper childEntity = parentEntity.FirstChildByName(name); // Make first level child by name if (!childEntity.Valid()) { return nullptr; } if (childEntity.HasComponent("Animation")) { - const Skeleton::Animation* animation = skeleton->GetAnimation(childEntity["Animation"]["AnimationName"]); + const Skeleton::Animation* animation = m_Skeleton->GetAnimation(childEntity["Animation"]["AnimationName"]); if (animation == nullptr) { return nullptr; } Node* node = new Node(); node->Name = childEntity.Name(); - node->Pose = skeleton->GetFrameBones(animation, (double)childEntity["Animation"]["Time"], (bool)childEntity["Animation"]["Additive"]); + node->Pose = m_Skeleton->GetFrameBones(animation, (double)childEntity["Animation"]["Time"], (bool)childEntity["Animation"]["Additive"]); node->Parent = parentNode; node->Type = NodeType::Animation; return node; @@ -186,31 +122,32 @@ BlendTree::Node* BlendTree::FillTreeByName(Node* parentNode, std::string name, E node->Type = NodeType::Blend; (double&)childEntity["Blend"]["Weight"] = glm::clamp((float)(double)childEntity["Blend"]["Weight"], 0.f, 1.f); node->Weight = (double)childEntity["Blend"]["Weight"]; - node->Child[0] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose1"], childEntity, skeleton); - node->Child[1] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose2"], childEntity, skeleton); + node->Child[0] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose1"], childEntity); + node->Child[1] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose2"], childEntity); return node; } else if (childEntity.HasComponent("BlendOverride")) { Node* node = new Node(); node->Name = childEntity.Name(); node->Parent = parentNode; node->Type = NodeType::Override; - node->Child[0] = FillTreeByName(node, (std::string)childEntity["BlendOverride"]["Master"], childEntity, skeleton); - node->Child[1] = FillTreeByName(node, (std::string)childEntity["BlendOverride"]["Slave"], childEntity, skeleton); + node->Child[0] = FillTreeByName(node, (std::string)childEntity["BlendOverride"]["Master"], childEntity); + node->Child[1] = FillTreeByName(node, (std::string)childEntity["BlendOverride"]["Slave"], childEntity); return node; } else if (childEntity.HasComponent("BlendAdditive")) { Node* node = new Node(); node->Name = childEntity.Name(); node->Parent = parentNode; node->Type = NodeType::Additive; - node->Child[0] = FillTreeByName(node, (std::string)childEntity["BlendAdditive"]["Adder"], childEntity, skeleton); - node->Child[1] = FillTreeByName(node, (std::string)childEntity["BlendAdditive"]["Receiver"], childEntity, skeleton); + node->Child[0] = FillTreeByName(node, (std::string)childEntity["BlendAdditive"]["Adder"], childEntity); + node->Child[1] = FillTreeByName(node, (std::string)childEntity["BlendAdditive"]["Receiver"], childEntity); return node; } + return nullptr; } -void BlendTree::Blend(Skeleton* skeleton, std::map& pose) +void BlendTree::Blend(std::map& pose) { Node* currentNode; Node* start = m_Root; @@ -219,7 +156,7 @@ void BlendTree::Blend(Skeleton* skeleton, std::map& pose) } currentNode = start; - LOG_INFO("\n\n"); + while (m_Root->Pose.size() == 0) { if(currentNode->Pose.size() == 0) { if (currentNode->Child[0] != nullptr && currentNode->Child[1] != nullptr) { @@ -227,20 +164,18 @@ void BlendTree::Blend(Skeleton* skeleton, std::map& pose) switch (currentNode->Type) { case BlendTree::NodeType::Additive: - currentNode->Pose = skeleton->BlendPoseAdditive(currentNode->Child[0]->Pose, currentNode->Child[1]->Pose); + currentNode->Pose = m_Skeleton->BlendPoseAdditive(currentNode->Child[0]->Pose, currentNode->Child[1]->Pose); break; case BlendTree::NodeType::Blend: - currentNode->Pose = skeleton->BlendPoses(currentNode->Child[0]->Pose, currentNode->Child[1]->Pose, currentNode->Weight); + currentNode->Pose = m_Skeleton->BlendPoses(currentNode->Child[0]->Pose, currentNode->Child[1]->Pose, currentNode->Weight); break; case BlendTree::NodeType::Override: - currentNode->Pose = skeleton->OverridePose(currentNode->Child[0]->Pose, currentNode->Child[1]->Pose); + currentNode->Pose = m_Skeleton->OverridePose(currentNode->Child[0]->Pose, currentNode->Child[1]->Pose); break; case BlendTree::NodeType::Animation: // do nothing break; } - - LOG_INFO("Blending %s and %s", currentNode->Child[0]->Name.c_str(), currentNode->Child[1]->Name.c_str()); } } else if (currentNode->Child[0] != nullptr) { if (currentNode->Child[0]->Pose.size() != 0) { @@ -264,21 +199,21 @@ void BlendTree::Blend(Skeleton* skeleton, std::map& pose) pose = m_Root->Pose; } -std::vector BlendTree::GetBoneTransforms(Skeleton* skeleton) +std::vector BlendTree::AccumulateFinalPose() { std::vector finalPose; - if (skeleton == nullptr || m_Root == nullptr) { + if (m_Skeleton == nullptr || m_Root == nullptr) { - for (int i = 0; i < skeleton->Bones.size(); i++) { + for (int i = 0; i < m_Skeleton->Bones.size(); i++) { finalPose.push_back(glm::mat4(1)); } return finalPose; } std::map pose; - Blend(skeleton, pose); + Blend(pose); - finalPose = skeleton->GetFinalPose(pose); + finalPose = m_Skeleton->GetFinalPose(pose); return finalPose; } diff --git a/src/Engine/Rendering/BoneAttachmentSystem.cpp b/src/Engine/Rendering/BoneAttachmentSystem.cpp index a4d381d1..0e259f4b 100644 --- a/src/Engine/Rendering/BoneAttachmentSystem.cpp +++ b/src/Engine/Rendering/BoneAttachmentSystem.cpp @@ -35,7 +35,7 @@ void BoneAttachmentSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapp return; } - std::vector<::Skeleton::AnimationData> Animations; + /* std::vector<::Skeleton::AnimationData> Animations; ::Skeleton::AnimationOffset AnimationOffset; glm::mat4 boneTransform; @@ -72,7 +72,7 @@ void BoneAttachmentSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapp glm::decompose(boneTransform, scale, rotation, translation, skew, perspective); glm::vec3 angles = glm::vec3(-glm::pitch(rotation), -glm::yaw(rotation), -glm::roll(rotation)); -/* +/ * angles.y = asin(-boneTransform[0][2]); if (cos(angles.y) != 0) { @@ -81,7 +81,7 @@ void BoneAttachmentSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapp } else { angles.x = atan2(-boneTransform[2][0], boneTransform[1][1]); angles.z = 0; - }*/ + }* / if ((bool)entity["BoneAttachment"]["InheritPosition"]) { (glm::vec3&)entity["Transform"]["Position"] = translation + (glm::vec3)entity["BoneAttachment"]["PositionOffset"]; @@ -91,5 +91,5 @@ void BoneAttachmentSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapp } if ((bool)entity["BoneAttachment"]["InheritScale"]) { (glm::vec3&)entity["Transform"]["Scale"] = scale * (glm::vec3)entity["BoneAttachment"]["ScaleOffset"]; - } + }*/ } diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index 43722a61..b139f2ba 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -338,12 +338,7 @@ void DrawFinalPass::DrawModelRenderQueues(std::list>& //bind textures BindExplosionTextures(explosionSkinnedHandle, explosionEffectJob); std::vector frameBones; - /*if (explosionEffectJob->AnimationOffset.animation != nullptr) { - frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations, explosionEffectJob->AnimationOffset); - } else { - frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations); - }*/ - frameBones = explosionEffectJob->Skeleton->GetFrameBones(); + frameBones = explosionEffectJob->BlendTree->GetFinalPose(); glUniformMatrix4fv(glGetUniformLocation(explosionSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); } else { m_ExplosionEffectProgram->Bind(); @@ -366,12 +361,7 @@ void DrawFinalPass::DrawModelRenderQueues(std::list>& BindExplosionTextures(explosionSplatMapSkinnedHandle, explosionEffectJob); GLERROR("asdasd"); std::vector frameBones; - /*if (explosionEffectJob->AnimationOffset.animation != nullptr) { - frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations, explosionEffectJob->AnimationOffset); - } else { - frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations); - }*/ - frameBones = explosionEffectJob->Skeleton->GetFrameBones(); + frameBones = explosionEffectJob->BlendTree->GetFinalPose(); glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); } else { @@ -412,12 +402,7 @@ void DrawFinalPass::DrawModelRenderQueues(std::list>& //bind textures BindModelTextures(forwardSkinnedHandle, modelJob); std::vector frameBones; - /* if (modelJob->AnimationOffset.animation != nullptr) { - frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset); - } else { - frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations); - }*/ - frameBones = modelJob->BlendTree->GetBoneTransforms(modelJob->Skeleton); + frameBones = modelJob->BlendTree->GetFinalPose(); glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); } else { @@ -441,12 +426,7 @@ void DrawFinalPass::DrawModelRenderQueues(std::list>& BindModelTextures(forwardSplatMapSkinnedHandle, modelJob); GLERROR("asdasd"); std::vector frameBones; - /* if (modelJob->AnimationOffset.animation != nullptr) { - frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset); - } else { - frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations); - }*/ - frameBones = modelJob->BlendTree->GetBoneTransforms(modelJob->Skeleton); + frameBones = modelJob->BlendTree->GetFinalPose(); glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); } else { @@ -490,12 +470,7 @@ void DrawFinalPass::DrawShieldToStencilBuffer(std::listViewMatrix())); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix())); std::vector frameBones; - /*if (modelJob->AnimationOffset.animation != nullptr) { - frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset); - } else { - frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations); - }*/ - frameBones = modelJob->Skeleton->GetFrameBones(); + frameBones = modelJob->BlendTree->GetFinalPose(); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); } else { m_ShieldToStencilProgram->Bind(); @@ -549,12 +524,7 @@ void DrawFinalPass::DrawShieldedModelRenderQueue(std::list frameBones; - /* if (explosionEffectJob->AnimationOffset.animation != nullptr) { - frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations, explosionEffectJob->AnimationOffset); - } else { - frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations); - }*/ - frameBones = explosionEffectJob->Skeleton->GetFrameBones(); + frameBones = explosionEffectJob->BlendTree->GetFinalPose(); glUniformMatrix4fv(glGetUniformLocation(explosionHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); if (GLERROR("Animation")) { @@ -589,12 +559,7 @@ void DrawFinalPass::DrawShieldedModelRenderQueue(std::list frameBones; - /* if (modelJob->AnimationOffset.animation != nullptr) { - frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset); - } else { - frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations); - }*/ - frameBones = modelJob->Skeleton->GetFrameBones(); + frameBones = modelJob->BlendTree->GetFinalPose(); glUniformMatrix4fv(glGetUniformLocation(forwardHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); @@ -626,12 +591,7 @@ void DrawFinalPass::DrawToDepthBuffer(std::list>& job glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); std::vector frameBones; - /*if (modelJob->AnimationOffset.animation != nullptr) { - frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset); - } else { - frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations); - }*/ - frameBones = modelJob->Skeleton->GetFrameBones(); + frameBones = modelJob->BlendTree->GetFinalPose(); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); } else { diff --git a/src/Engine/Rendering/PickingPass.cpp b/src/Engine/Rendering/PickingPass.cpp index 479cb762..64483755 100644 --- a/src/Engine/Rendering/PickingPass.cpp +++ b/src/Engine/Rendering/PickingPass.cpp @@ -103,12 +103,7 @@ void PickingPass::Draw(RenderScene& scene) if (modelJob->Model->m_RawModel->m_Skeleton != nullptr) { std::vector frameBones; - /*if (modelJob->AnimationOffset.animation != nullptr) { - frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset); - } else { - frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations); - }*/ - frameBones = modelJob->Skeleton->GetFrameBones(); + frameBones = modelJob->BlendTree->GetFinalPose(); glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); } @@ -161,12 +156,7 @@ void PickingPass::Draw(RenderScene& scene) glUniform2fv(glGetUniformLocation(shaderSkinnedHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1]))); std::vector frameBones; - /* if (modelJob->AnimationOffset.animation != nullptr) { - frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset); - } else { - frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations); - }*/ - frameBones = modelJob->Skeleton->GetFrameBones(); + frameBones = modelJob->BlendTree->GetFinalPose(); glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); } else { m_PickingProgram->Bind(); @@ -217,12 +207,7 @@ void PickingPass::Draw(RenderScene& scene) glUniform2fv(glGetUniformLocation(shaderSkinnedHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1]))); std::vector frameBones; - /* if (modelJob->AnimationOffset.animation != nullptr) { - frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset); - } else { - frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations); - }*/ - frameBones = modelJob->Skeleton->GetFrameBones(); + frameBones = modelJob->BlendTree->GetFinalPose(); glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); } else { @@ -279,12 +264,7 @@ void PickingPass::Draw(RenderScene& scene) if (modelJob->Model->m_RawModel->m_Skeleton != nullptr) { std::vector frameBones; - /*if (modelJob->AnimationOffset.animation != nullptr) { - frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset); - } else { - frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations); - }*/ - frameBones = modelJob->Skeleton->GetFrameBones(); + frameBones = modelJob->BlendTree->GetFinalPose(); glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); } diff --git a/src/Engine/Rendering/Skeleton.cpp b/src/Engine/Rendering/Skeleton.cpp index e951b3c5..077e9d02 100644 --- a/src/Engine/Rendering/Skeleton.cpp +++ b/src/Engine/Rendering/Skeleton.cpp @@ -1,55 +1,6 @@ #include "Rendering/Skeleton.h" -int Skeleton::CreateBone(int ID, int parentID, std::string name, glm::mat4 offsetMatrix) -{ - if (m_BonesByName.find(name) != m_BonesByName.end()) { - return m_BonesByName.at(name)->ID; - } else { - Bone* bone; - - if (parentID == -1) { - bone = new Bone(ID, nullptr, name, offsetMatrix); - RootBone = bone; - } else { - Bone* parent = Bones[parentID]; - bone = new Bone(ID, parent, name, offsetMatrix); - parent->Children.push_back(bone); - } - - Bones[ID] = bone; - m_BonesByName[name] = bone; - return ID; - } -} - -Skeleton::~Skeleton() -{ - for (auto &kv : Bones) { - delete kv.second; - } -} - - - -const Skeleton::Animation* Skeleton::GetAnimation(std::string name) -{ - auto it = Animations.find(name); - if (it != Animations.end()) { - return const_cast(&it->second); - } else { - return nullptr; - } -} - -std::vector Skeleton::GetFrameBones() -{ - std::vector finalMatrices; - for (auto& b : Bones) { - finalMatrices.push_back(glm::mat4(1)); - } - return finalMatrices; -} -std::map Skeleton::GetFrameBones(const Animation* animation, const double time, bool additive, bool noRootMotion /*= false*/) +std::map Skeleton::GetFrameBones(const Animation* animation, double time, bool additive, bool noRootMotion /*= false*/) { if (animation == nullptr) { std::map finalMatrices; @@ -63,7 +14,7 @@ std::map Skeleton::GetFrameBones(const Animation* animation, con std::map frameBones; if(!additive) { - AccumulateBoneTransforms(true, animation, time, frameBones, additive, RootBone, glm::mat4(1)); + AccumulateBoneTransforms(true, animation, time, frameBones, RootBone, glm::mat4(1)); } else { AdditiveBoneTransforms(animation, time, frameBones, RootBone); } @@ -71,12 +22,8 @@ std::map Skeleton::GetFrameBones(const Animation* animation, con return frameBones; } -void Skeleton::AccumulateBoneTransforms(bool noRootMotion, const Animation* animation, double time, std::map& boneMatrices, bool additive, const Bone* bone, glm::mat4 parentMatrix) +void Skeleton::AccumulateBoneTransforms(bool noRootMotion, const Animation* animation, double time, std::map& boneMatrices, const Bone* bone, glm::mat4 parentMatrix) { - if (additive) { - time += 1.0/60.0; // first frame is a reference frame - } - glm::mat4 boneMatrix; @@ -138,7 +85,7 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, const Animation* anim } for (auto &child : bone->Children) { - AccumulateBoneTransforms(noRootMotion, animation, time, boneMatrices, additive, child, boneMatrix); + AccumulateBoneTransforms(noRootMotion, animation, time, boneMatrices, child, boneMatrix); } } @@ -157,20 +104,6 @@ void Skeleton::AdditiveBoneTransforms(const Animation* animation, double time, s } } - - -glm::mat4 Skeleton::AdditiveBlend(const Bone* bone, AnimationOffset animationOffset, glm::mat4 targetPose) -{ -/* - AnimationOffset refOffset = animationOffset; - refOffset.time = 0.5f; // reference pose is at 0.5s for now - glm::mat4 refPose = GetAdditiveBonePose(bone, refOffset); - glm::mat4 srcPose = GetAdditiveBonePose(bone, animationOffset); - glm::mat4 differencePose = srcPose * glm::inverse(refPose); - glm::mat4 finalPose = differencePose * targetPose;*/ - return glm::mat4(); -} - glm::mat4 Skeleton::GetAdditiveBonePose(const Bone* bone, const Animation* animation, double time) { glm::vec3 position = glm::vec3(0); @@ -227,9 +160,6 @@ glm::mat4 Skeleton::GetBonePose(const Bone* bone, const Animation* animation, do { glm::mat4 boneMatrix; - std::vector JointPoses; - - if (animation->JointAnimations.find(bone->ID) != animation->JointAnimations.end()) { std::vector boneKeyFrames = animation->JointAnimations.at(bone->ID); @@ -346,235 +276,7 @@ glm::mat4 Skeleton::GetBoneTransform(const Bone* bone, const Animation* animatio } } -glm::mat4 Skeleton::GetBoneTransform(bool noRootMotion, const Bone* bone, std::vector animations, AnimationOffset animationOffset, glm::mat4 childMatrix) -{ - glm::mat4 boneMatrix; - - std::vector JointPoses; - - for (const AnimationData animationData : animations) { - const Animation* animation = animationData.animation; - const float time = animationData.time; - - JointFramePose jointPose; - jointPose.Weight = animationData.weight;; - - if (animation->JointAnimations.find(bone->ID) != animation->JointAnimations.end()) { - std::vector boneKeyFrames = animation->JointAnimations.at(bone->ID); - - Animation::Keyframe currentFrame; - Animation::Keyframe nextFrame; - - if (boneKeyFrames.size() > 1) { // 2+ keyframes for the current bone - for (int index = boneKeyFrames.size()-1; index >= 0; index--) { // find the bone keyframes that surrounds the current frame - if (time >= boneKeyFrames.at(index).Time) { - currentFrame = boneKeyFrames.at(index); - nextFrame = boneKeyFrames.at((index + 1) % boneKeyFrames.size()); - break; - } - } - - float progress; - - if (nextFrame.Index == 0) { - nextFrame = currentFrame; - progress = (time - currentFrame.Time) / (animation->Duration - currentFrame.Time); - } else { - progress = (time - currentFrame.Time) / (nextFrame.Time - currentFrame.Time); - - } - - - if (progress > 1.0f || progress < 0.0f) { - progress = glm::clamp(progress, 0.0f, 1.0f); - } - Animation::Keyframe::BoneProperty currentBoneProperty = currentFrame.BoneProperties; - Animation::Keyframe::BoneProperty nextBoneProperty = nextFrame.BoneProperties; - - glm::vec3 position = currentBoneProperty.Position * (1.f - progress) + nextBoneProperty.Position * progress; - glm::quat rotation = glm::slerp(currentBoneProperty.Rotation, nextBoneProperty.Rotation, progress); - glm::vec3 scale = currentBoneProperty.Scale * (1.f - progress) + nextBoneProperty.Scale * progress; - - // Flag for no root motion - if (bone == RootBone && noRootMotion) { - position.x = 0; - position.z = 0; - } - - jointPose.Pose = (glm::translate(position) * glm::toMat4(rotation) * glm::scale(scale)); - JointPoses.push_back(jointPose); - - } else { // 1 keyframes for the current bone - currentFrame = boneKeyFrames.at(0); - jointPose.Pose = (glm::translate(currentFrame.BoneProperties.Position) * glm::toMat4(currentFrame.BoneProperties.Rotation) * glm::scale(currentFrame.BoneProperties.Scale)); - JointPoses.push_back(jointPose); - } - } else { // 0 keyframes for the current bone - - } - - } - - - if (JointPoses.size() == 0) { - if (bone->Parent) { - - glm::mat4 jointPose = (glm::inverse(bone->OffsetMatrix) * bone->Parent->OffsetMatrix); - glm::mat4 boneTransform = AdditiveBlend(bone, animationOffset, jointPose); - - boneMatrix = boneTransform * childMatrix; - } else { - boneMatrix = glm::inverse(bone->OffsetMatrix) * childMatrix; - } - } else { - - float totalWeight = 0; - - for (JointFramePose jointFramePose : JointPoses) { - totalWeight += jointFramePose.Weight; - } - - glm::mat4 finalBlend = glm::mat4(0); - - for (JointFramePose jointFramePose : JointPoses) { - if (jointFramePose.Weight == 1.0f) { - finalBlend = jointFramePose.Pose; - } else { - finalBlend += jointFramePose.Pose * (jointFramePose.Weight / totalWeight); - } - } - - - glm::mat4 boneTransform = AdditiveBlend(bone, animationOffset, finalBlend); - boneMatrix = boneTransform * childMatrix; - } - - if (bone->Parent != nullptr) { - return GetBoneTransform(noRootMotion, bone->Parent, animations, animationOffset, boneMatrix); - } else { - return boneMatrix; - } -} - -glm::mat4 Skeleton::GetBoneTransform(bool noRootMotion, const Bone* bone, std::vector animations, glm::mat4 childMatrix) -{ - glm::mat4 boneMatrix; - /* std::vector JointTransforms; - - for (const AnimationData animationData : animations) { - const Animation* animation = animationData.animation; - const float time = animationData.time; - - JointFrameTransform jointTransform; - jointTransform.Weight = animationData.weight;; - - if (animation->JointAnimations.find(bone->ID) != animation->JointAnimations.end()) { - std::vector boneKeyFrames = animation->JointAnimations.at(bone->ID); - - Animation::Keyframe currentFrame; - Animation::Keyframe nextFrame; - - if (boneKeyFrames.size() > 1) { // 2+ keyframes for the current bone - for (int index = boneKeyFrames.size()-1; index >= 0; index--) { // find the bone keyframes that surrounds the current frame - if (time >= boneKeyFrames.at(index).Time) { - currentFrame = boneKeyFrames.at(index); - nextFrame = boneKeyFrames.at((index + 1) % boneKeyFrames.size()); - break; - } - } - - float progress; - - if (nextFrame.Index == 0) { - nextFrame = currentFrame; - progress = (time - currentFrame.Time) / (animation->Duration - currentFrame.Time); - } else { - progress = (time - currentFrame.Time) / (nextFrame.Time - currentFrame.Time); - - } - - - if (progress > 1.0f || progress < 0.0f) { - progress = glm::clamp(progress, 0.0f, 1.0f); - } - Animation::Keyframe::BoneProperty currentBoneProperty = currentFrame.BoneProperties; - Animation::Keyframe::BoneProperty nextBoneProperty = nextFrame.BoneProperties; - - jointTransform.Position = currentBoneProperty.Position * (1.f - progress) + nextBoneProperty.Position * progress; - jointTransform.Rotation = glm::slerp(currentBoneProperty.Rotation, nextBoneProperty.Rotation, progress); - jointTransform.Scale = currentBoneProperty.Scale * (1.f - progress) + nextBoneProperty.Scale * progress; - - // Flag for no root motion - if (bone == RootBone && noRootMotion) { - jointTransform.Position.x = 0; - jointTransform.Position.z = 0; - } - - JointTransforms.push_back(jointTransform); - - } else { // 1 keyframes for the current bone - currentFrame = boneKeyFrames.at(0); - jointTransform.Position = currentFrame.BoneProperties.Position; - jointTransform.Rotation = currentFrame.BoneProperties.Rotation; - jointTransform.Scale = currentFrame.BoneProperties.Scale; - JointTransforms.push_back(jointTransform); - - } - } else { // 0 keyframes for the current bone - - } - - } - - if (JointTransforms.size() <= 0) { - if (bone->Parent) { - boneMatrix = glm::inverse(bone->OffsetMatrix) * bone->Parent->OffsetMatrix * childMatrix; - } else { - boneMatrix = glm::inverse(bone->OffsetMatrix) * childMatrix; - } - } else if (JointTransforms.size() == 1) { - boneMatrix = (glm::translate(JointTransforms.at(0).Position) * glm::toMat4(JointTransforms.at(0).Rotation) * glm::scale(JointTransforms.at(0).Scale)) * childMatrix; - } else { - - glm::vec3 finalPosInterp; - glm::quat finalRotInterp; - glm::vec3 finalScaleInterp; - float totalWeight = 0; - - for (JointFrameTransform jointTransform : JointTransforms) { - totalWeight += jointTransform.Weight; - } - - - for (JointFrameTransform jointTransform : JointTransforms) { - if (jointTransform.Weight == 1.0f) { - finalPosInterp = jointTransform.Position; - finalRotInterp = jointTransform.Rotation; - finalScaleInterp = jointTransform.Scale; - break; - } else { - finalPosInterp += jointTransform.Position * (jointTransform.Weight/totalWeight); - finalRotInterp *= glm::slerp(glm::quat(), jointTransform.Rotation, (jointTransform.Weight/totalWeight)); - finalScaleInterp += jointTransform.Scale * (jointTransform.Weight/totalWeight); - } - - } - - boneMatrix = (glm::translate(finalPosInterp) * glm::toMat4(finalRotInterp) * glm::scale(finalScaleInterp)) * childMatrix; - } - - - if (bone->Parent != nullptr) { - return GetBoneTransform(noRootMotion, bone->Parent, animations, boneMatrix); - } else { - return boneMatrix; - }*/ - -return boneMatrix; -} - - -std::map Skeleton::BlendPoses(std::map pose1, std::map pose2, float weight) +std::map Skeleton::BlendPoses(const std::map& pose1, const std::map& pose2, float weight) { std::map finalPose; @@ -596,8 +298,7 @@ std::map Skeleton::BlendPoses(std::map pose1, st return finalPose; } - -std::map Skeleton::OverridePose(std::map overridePose, std::map targetPose) +std::map Skeleton::OverridePose(const std::map& overridePose, const std::map& targetPose) { std::map finalPose; @@ -612,8 +313,7 @@ std::map Skeleton::OverridePose(std::map overrid return finalPose; } - -std::map Skeleton::BlendPoseAdditive(std::map additivePose, std::map targetPose) +std::map Skeleton::BlendPoseAdditive(const std::map& additivePose, const std::map& targetPose) { std::map finalPose; @@ -683,3 +383,42 @@ int Skeleton::GetBoneID(std::string name) return m_BonesByName.at(name)->ID; } } + +int Skeleton::CreateBone(int ID, int parentID, std::string name, glm::mat4 offsetMatrix) +{ + if (m_BonesByName.find(name) != m_BonesByName.end()) { + return m_BonesByName.at(name)->ID; + } else { + Bone* bone; + + if (parentID == -1) { + bone = new Bone(ID, nullptr, name, offsetMatrix); + RootBone = bone; + } else { + Bone* parent = Bones[parentID]; + bone = new Bone(ID, parent, name, offsetMatrix); + parent->Children.push_back(bone); + } + + Bones[ID] = bone; + m_BonesByName[name] = bone; + return ID; + } +} + +Skeleton::~Skeleton() +{ + for (auto &kv : Bones) { + delete kv.second; + } +} + +const Skeleton::Animation* Skeleton::GetAnimation(std::string name) +{ + auto it = Animations.find(name); + if (it != Animations.end()) { + return const_cast(&it->second); + } else { + return nullptr; + } +} \ No newline at end of file From 8867e7ac3c0ea9c34eee4a32227d09a75bc5c910 Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Thu, 25 Feb 2016 20:29:41 +0100 Subject: [PATCH 033/130] Working shadows, no cascade blend yet --- include/Engine/Rendering/ShadowPass.h | 41 ++++- resources/Shaders/ExplosionEffect.geom.glsl | 6 +- resources/Shaders/ForwardPlus.frag.glsl | 80 +++++++- resources/Shaders/ForwardPlus.vert.glsl | 13 +- src/Engine/Rendering/DrawFinalPass.cpp | 24 ++- src/Engine/Rendering/Renderer.cpp | 2 +- src/Engine/Rendering/ShadowPass.cpp | 194 +++++++++++--------- 7 files changed, 243 insertions(+), 117 deletions(-) diff --git a/include/Engine/Rendering/ShadowPass.h b/include/Engine/Rendering/ShadowPass.h index 2022a5ab..b7c37b31 100644 --- a/include/Engine/Rendering/ShadowPass.h +++ b/include/Engine/Rendering/ShadowPass.h @@ -9,7 +9,8 @@ #include "ShadowPassState.h" #include "imgui/imgui.h" -#define MAX_SPLITS 5 +#define MAX_SPLITS 3 +#define MAP_SIZE 216.f enum NearFar { Near = 0, Far = 1 }; enum LRBT { Left = 0, Right = 1, Bottom = 2, Top = 3 }; @@ -19,6 +20,18 @@ struct ShadowCamera{ std::array frustumCorners; }; +struct Frustum +{ + float NearClip; + float FarClip; + float FOV; + float AspectRatio; + glm::vec3 MiddlePoint; + float Radius; + std::array LRTB; + std::array CornerPoint; +}; + class ShadowPass { public: @@ -31,15 +44,23 @@ public: void ClearBuffer(); void Draw(RenderScene& scene); - GLuint DepthMap() const { return m_DepthMap[m_ShadowLevel]; } - glm::mat4 lightP() const { return m_LightProjection[m_ShadowLevel]; } - glm::mat4 lightV() const { return m_LightView[m_ShadowLevel]; } + GLuint DepthMap(int level) const { return m_DepthMap[level]; } + std::array lightP() const { return m_LightProjection; } + std::array lightV() const { return m_LightView; } + std::array farDistance() const { return { m_shadFrusta[0].FarClip, m_shadFrusta[1].FarClip, m_shadFrusta[2].FarClip }; } + int CurrentNrOfSplits() const { return m_CurrentNrOfSplits; } private: + void UpdateFrustumPoints(Frustum& frustum, glm::vec3 camera_position, glm::vec3 view_dir, glm::mat4 p, glm::mat4 v); + void UpdateSplitDist(std::array& frusta, float near_distance, float far_distance); + glm::mat4 ApplyCropMatrix(Frustum& frustum, glm::mat4 m, glm::mat4 v); glm::mat4 CalculateFrustum(RenderScene & scene, std::shared_ptr directionalLightJob, ShadowCamera shad_cam); - std::array UpdateFrustumPoints(Camera* cam, glm::vec3 center, glm::vec3 view_dir); - void UpdateSplitDist(std::array shadow_cams, float far_distance, float near_distance); - glm::mat4 FindNewFrustum(ShadowCamera shadow_cam); + glm::mat4 FindNewFrustum(Frustum frustum, glm::mat4 v, glm::mat4 p); + void InitializeCameras(RenderScene & scene); + float FindRadius(Frustum& frustum); + void PointsToLightspace(Frustum& frustum, glm::mat4 v); + void RadiusToLightspace(Frustum& frustum, glm::mat4 v); + EventBroker* m_EventBroker; const IRenderer* m_Renderer; @@ -63,9 +84,11 @@ private: int m_ShadowLevel = 0; int m_CurrentNrOfSplits = 3; - float m_SplitWeight = 0.5f; + float m_SplitWeight = 0.75f; - std::array m_shadCams; + //std::array m_shadCams; + Frustum m_MainCamera; + std::array m_shadFrusta; }; #endif \ No newline at end of file diff --git a/resources/Shaders/ExplosionEffect.geom.glsl b/resources/Shaders/ExplosionEffect.geom.glsl index 3471e4f2..b4a90e3b 100644 --- a/resources/Shaders/ExplosionEffect.geom.glsl +++ b/resources/Shaders/ExplosionEffect.geom.glsl @@ -1,5 +1,7 @@ #version 430 +#define MAX_SPLITS 3 + uniform mat4 M; uniform mat4 V; uniform mat4 P; @@ -22,7 +24,7 @@ in VertexData{ vec2 TextureCoordinate; vec4 ExplosionColor; float ExplosionPercentageElapsed; - vec4 PositionLightSpace; + vec4 PositionLightSpace[MAX_SPLITS]; }Input[]; out VertexData{ @@ -33,7 +35,7 @@ out VertexData{ vec2 TextureCoordinate; vec4 ExplosionColor; float ExplosionPercentageElapsed; - vec4 PositionLightSpace; + vec4 PositionLightSpace[MAX_SPLITS]; }Output; layout(triangles) in; diff --git a/resources/Shaders/ForwardPlus.frag.glsl b/resources/Shaders/ForwardPlus.frag.glsl index 1f3ba711..76169707 100644 --- a/resources/Shaders/ForwardPlus.frag.glsl +++ b/resources/Shaders/ForwardPlus.frag.glsl @@ -1,5 +1,7 @@ #version 430 +#define MAX_SPLITS 3 + uniform mat4 M; uniform mat4 V; uniform mat4 P; @@ -9,11 +11,15 @@ uniform vec2 ScreenDimensions; uniform vec4 FillColor; uniform vec4 AmbientColor; uniform float FillPercentage; +uniform float FarDistance[MAX_SPLITS]; + layout (binding = 0) uniform sampler2D DiffuseTexture; layout (binding = 1) uniform sampler2D NormalMapTexture; layout (binding = 2) uniform sampler2D SpecularMapTexture; layout (binding = 3) uniform sampler2D GlowMapTexture; -layout (binding = 4) uniform sampler2DShadow DepthMap; +layout (binding = 4) uniform sampler2DShadow DepthMap0; +layout (binding = 5) uniform sampler2DShadow DepthMap1; +layout (binding = 6) uniform sampler2DShadow DepthMap2; #define TILE_SIZE 16 @@ -57,7 +63,7 @@ in VertexData{ vec2 TextureCoordinate; vec4 ExplosionColor; float ExplosionPercentageElapsed; - vec4 PositionLightSpace; + vec4 PositionLightSpace[MAX_SPLITS]; }Input; out vec4 sceneColor; @@ -186,8 +192,52 @@ float CalcShadowValue(vec4 positionLightSpace, vec3 normal, vec3 lightDir, sampl } +int getShadowIndex(float far_distance[MAX_SPLITS]) +{ + int index = 2; + if( gl_FragCoord.z < far_distance[0] ) + { + index = 0; + } + else if( gl_FragCoord.z < far_distance[1] && gl_FragCoord.z > far_distance[0] ) + { + index = 1; + } + + return index; +} + +//sampler2DShadow whichDepthMap( int DepthMapIndex ) +//{ +// if( DepthMapIndex == 0 ) +// { +// return DepthMap0; +// } +// else if( DepthMapIndex == 1 ) +// { +// return DepthMap1; +// } +// else +// { +// return DepthMap2; +// } +// +//} + void main() { + //sampler2DShadow DepthMaps[3] = { sampler2DShadow(DepthMap0), sampler2DShadow(DepthMap1), sampler2DShadow(DepthMap2) }; + //sampler2DShadow DepthMaps[3] = { DepthMap0, DepthMap1, DepthMap2 }; + //sampler2DShadow DepthMaps[3] = sampler2DShadow[]( DepthMap0, DepthMap1, DepthMap2 ); + //sampler2DShadow DepthMaps[3] = sampler2DShadow[3]( DepthMap0, DepthMap1, DepthMap2 ); + //sampler2DShadow DepthMaps[3]; + + //sampler2DShadow DepthMapOne = DepthMap0; + + //DepthMaps[0] = DepthMap0; + //DepthMaps[1] = DepthMap1; + //DepthMaps[2] = DepthMap2; + vec4 diffuseTexel = texture2D(DiffuseTexture, Input.TextureCoordinate); vec4 glowTexel = texture2D(GlowMapTexture, Input.TextureCoordinate); vec4 specularTexel = texture2D(SpecularMapTexture, Input.TextureCoordinate); @@ -220,18 +270,32 @@ void main() if(light.Type == 1) { // point light_result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, position, normal, light.Falloff); } else if (light.Type == 2) { //Directional + int DepthMapIndex = getShadowIndex(FarDistance); + //sampler2DShadow WhichDepthMap = whichDepthMap(DepthMapIndex); + light_result = CalcDirectionalLightSource(V * light.Direction, light.Color, light.Intensity, viewVec, normal); - shadowFactor = CalcShadowValue(Input.PositionLightSpace, Input.Normal, vec3(light.Direction), DepthMap); + + shadowFactor = CalcShadowValue(Input.PositionLightSpace[0], Input.Normal, vec3(light.Direction), DepthMap0); + //if( DepthMapIndex == 0 ) + //{ + // shadowFactor = CalcShadowValue(Input.PositionLightSpace[DepthMapIndex], Input.Normal, vec3(light.Direction), DepthMap0); + //} + //else if( DepthMapIndex == 1 ) + //{ + // shadowFactor = CalcShadowValue(Input.PositionLightSpace[DepthMapIndex], Input.Normal, vec3(light.Direction), DepthMap1); + //} + //else + //{ + // shadowFactor = CalcShadowValue(Input.PositionLightSpace[DepthMapIndex], Input.Normal, vec3(light.Direction), DepthMap2); + //} } totalLighting.Diffuse += light_result.Diffuse; - totalLighting.Specular += light_result.Specular; + totalLighting.Specular += light_result.Specular; } - //totalLighting.Diffuse *= (1.5 + vec4(AmbientColor.rgb, 1.0)) - vec4(vec3(shadowFactor), 0.0); - //totalLighting.Specular *= (1.5 + vec4(AmbientColor.rgb, 1.0)) - vec4(vec3(shadowFactor), 0.0); - totalLighting.Diffuse *= (1.0 + vec4(AmbientColor.rgb, 1.0)) + vec4(vec3(shadowFactor, shadowFactor, 0.0), 0.0); - totalLighting.Specular *= (1.0 + vec4(AmbientColor.rgb, 1.0)) + vec4(vec3(shadowFactor, shadowFactor, 0.0), 0.0); + totalLighting.Diffuse *= (1.5 + vec4(AmbientColor.rgb, 1.0)) - vec4(vec3(shadowFactor), 0.0); + totalLighting.Specular *= (1.5 + vec4(AmbientColor.rgb, 1.0)) - vec4(vec3(shadowFactor), 0.0); //LightResult getInformation; diff --git a/resources/Shaders/ForwardPlus.vert.glsl b/resources/Shaders/ForwardPlus.vert.glsl index be7fa273..fb280e3a 100644 --- a/resources/Shaders/ForwardPlus.vert.glsl +++ b/resources/Shaders/ForwardPlus.vert.glsl @@ -1,10 +1,12 @@ #version 430 +#define MAX_SPLITS 3 + uniform mat4 M; uniform mat4 V; uniform mat4 P; -uniform mat4 LightV; -uniform mat4 LightP; +uniform mat4 LightV[MAX_SPLITS]; +uniform mat4 LightP[MAX_SPLITS]; uniform mat4 Bones[100]; layout(location = 0) in vec3 Position; @@ -23,7 +25,7 @@ out VertexData{ vec2 TextureCoordinate; vec4 ExplosionColor; float ExplosionPercentageElapsed; - vec4 PositionLightSpace; + vec4 PositionLightSpace[MAX_SPLITS]; }Output; // N @@ -60,5 +62,8 @@ void main() Output.ExplosionPercentageElapsed = 0.0; //Output.PositionLightSpace = lightPos; // N - Output.PositionLightSpace = LightP * LightV * M * vec4(Position, 1.0); + for(int i = 0; i < MAX_SPLITS; i++) + { + Output.PositionLightSpace[i] = LightP[i] * LightV[i] * M * vec4(Position, 1.0); + } } \ No newline at end of file diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index 776bb1b3..8770adb4 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -244,8 +244,11 @@ void DrawFinalPass::BindModelUniforms(GLuint shaderHandle, std::shared_ptrlightP())); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "LightV"), 1, GL_FALSE, glm::value_ptr(m_ShadowPass->lightV())); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "LightP"), MAX_SPLITS, GL_FALSE, glm::value_ptr(*m_ShadowPass->lightP().data())); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "LightV"), MAX_SPLITS, GL_FALSE, glm::value_ptr(*m_ShadowPass->lightV().data())); + glUniform1fv(glGetUniformLocation(shaderHandle, "FarDistance"), MAX_SPLITS, m_ShadowPass->farDistance().data()); + + //GLfloat m_NearFarPlane[2] = { -40.f, 30.f }; //GLfloat m_LRBT[4] = { -40.f, 100.f, -50.f, 50.f }; //glm::mat4 m_LightProjection = glm::ortho(m_LRBT[Left], m_LRBT[Right], m_LRBT[Bottom], m_LRBT[Top], m_NearFarPlane[Near], m_NearFarPlane[Far]); @@ -317,11 +320,16 @@ void DrawFinalPass::BindModelTextures(std::shared_ptr& job) glBindTexture(GL_TEXTURE_2D, m_BlackTexture->m_Texture); } - glActiveTexture(GL_TEXTURE4); - if (m_ShadowPass->DepthMap() != NULL) { - glBindTexture(GL_TEXTURE_2D, m_ShadowPass->DepthMap()); - } else { - glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture); - } + for (int i = 0; i < m_ShadowPass->CurrentNrOfSplits(); i++) + { + glActiveTexture(GL_TEXTURE4 + i); + if (m_ShadowPass->DepthMap(i) != NULL) { + glBindTexture(GL_TEXTURE_2D, m_ShadowPass->DepthMap(i)); + } else { + glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture); + } + } + + } diff --git a/src/Engine/Rendering/Renderer.cpp b/src/Engine/Rendering/Renderer.cpp index f8e1cd6b..5aa411fc 100644 --- a/src/Engine/Rendering/Renderer.cpp +++ b/src/Engine/Rendering/Renderer.cpp @@ -137,7 +137,7 @@ void Renderer::Draw(RenderFrame& frame) m_DrawScreenQuadPass->Draw(m_PickingPass->PickingTexture()); } if (m_DebugTextureToDraw == 5) { - m_DrawScreenQuadPass->Draw(m_ShadowPass->DepthMap()); + m_DrawScreenQuadPass->Draw(m_ShadowPass->DepthMap(0)); } m_ImGuiRenderPass->Draw(); diff --git a/src/Engine/Rendering/ShadowPass.cpp b/src/Engine/Rendering/ShadowPass.cpp index 412a1fc7..1c31f91e 100644 --- a/src/Engine/Rendering/ShadowPass.cpp +++ b/src/Engine/Rendering/ShadowPass.cpp @@ -1,11 +1,12 @@ #include "Rendering/ShadowPass.h" + ShadowPass::ShadowPass(IRenderer * renderer) { - m_Renderer = renderer; + m_Renderer = renderer; - InitializeFrameBuffers(); - InitializeShaderPrograms(); + InitializeFrameBuffers(); + InitializeShaderPrograms(); } ShadowPass::~ShadowPass() @@ -13,101 +14,94 @@ ShadowPass::~ShadowPass() // m_shadCams } -// Compute the 8 corner points of the current view frustum -std::array ShadowPass::UpdateFrustumPoints(Camera* cam, glm::vec3 center, glm::vec3 view_dir) +void ShadowPass::InitializeCameras(RenderScene & scene) { - glm::vec3 up = glm::vec3(0.f, 1.f, 0.f); - glm::vec3 right = glm::normalize(glm::cross(view_dir, up)); - - //glm::vec3 farCenter = center + view_dir * cam->FarClip(); - //glm::vec3 nearCenter = center + view_dir * cam->NearClip(); - glm::vec3 farCenter = view_dir * cam->FarClip(); - glm::vec3 nearCenter = view_dir * cam->NearClip(); - - up = glm::normalize(glm::cross(right, view_dir)); - - float near_height = tan(cam->FOV() / 2.f) * cam->NearClip(); - float near_width = near_height * cam->AspectRatio(); - float far_height = tan(cam->FOV() / 2.f) * cam->FarClip(); - float far_width = far_height * cam->AspectRatio(); - - std::array frustumPoints; - frustumPoints[0] = nearCenter - up * near_height - right * near_width; - frustumPoints[1] = nearCenter + up * near_height - right * near_width; - frustumPoints[2] = nearCenter + up * near_height + right * near_width; - frustumPoints[3] = nearCenter - up * near_height + right * near_width; - - frustumPoints[4] = farCenter - up * far_height - right * far_width; - frustumPoints[5] = farCenter + up * far_height - right * far_width; - frustumPoints[6] = farCenter + up * far_height + right * far_width; - frustumPoints[7] = farCenter - up * far_height + right * far_width; - - return frustumPoints; + for (int i = 0; i < m_CurrentNrOfSplits; i++) { + m_shadFrusta[i].AspectRatio = scene.Camera->AspectRatio(); + m_shadFrusta[i].FOV = scene.Camera->FOV(); + } } // UpdateSplitDist computes the near and far distances for every frustum slice // in camera eye space - that is, at what distance does a slice start and end -void ShadowPass::UpdateSplitDist(std::array shadow_cams, float near_distance, float far_distance) +void ShadowPass::UpdateSplitDist(std::array& frusta, float near_distance, float far_distance) { float lambda = m_SplitWeight; float ratio = far_distance / near_distance; - shadow_cams[0].camera->SetNearClip(near_distance); + frusta[0].NearClip = near_distance; for (int i = 1; i < m_CurrentNrOfSplits; i++) { float si = i / static_cast(m_CurrentNrOfSplits); - shadow_cams[i].camera->SetNearClip(lambda * (near_distance * powf(ratio, si)) + (1 - lambda) * (near_distance + (far_distance - near_distance) * si)); - shadow_cams[i - 1].camera->SetFarClip(shadow_cams[i].camera->NearClip() * 1.005f); + frusta[i].NearClip = lambda * (near_distance * powf(ratio, si)) + (1 - lambda) * (near_distance + (far_distance - near_distance) * si); + frusta[i - 1].FarClip = frusta[i].NearClip * 1.005f; } - shadow_cams[m_CurrentNrOfSplits - 1].camera->SetFarClip(far_distance); + frusta[m_CurrentNrOfSplits - 1].FarClip = far_distance; } -// Create a new light frustum based on the 8 corner points of a view frustum segment -glm::mat4 ShadowPass::FindNewFrustum(ShadowCamera shadow_cam) +// Compute the 8 corner points of the current view frustum in world space +void ShadowPass::UpdateFrustumPoints(Frustum& frustum, glm::vec3 camera_position, glm::vec3 view_dir, glm::mat4 p, glm::mat4 v) { - float maxX = -1000.0f; - float maxY = -1000.0f; - float maxZ; - float minX = 1000.0f; - float minY = 1000.0f; - float minZ; + glm::vec3 up = glm::vec3(0.f, 1.f, 0.f); + glm::vec3 right = glm::normalize(glm::cross(view_dir, up)); - glm::vec4 transf; + glm::vec3 far_center = camera_position + glm::normalize(view_dir) * frustum.FarClip; + glm::vec3 near_center = camera_position + glm::normalize(view_dir) * frustum.NearClip; + frustum.MiddlePoint = near_center + (far_center - near_center) * 0.5f; - for (int i = 0; i < 8; i++) - { - transf = glm::vec4(shadow_cam.frustumCorners[i], 1.f); + up = glm::normalize(glm::cross(right, view_dir)); - if (transf.x > maxX) maxX = transf.x; - if (transf.x < minX) minX = transf.x; - if (transf.y > maxY) maxY = transf.y; - if (transf.y < minY) minY = transf.y; + // these heights and widths are half the heights and widths of the near and far plane rectangles. + float near_height = tan(frustum.FOV / 2.f) * frustum.NearClip; + float near_width = near_height * frustum.AspectRatio; + float far_height = tan(frustum.FOV / 2.f) * frustum.FarClip; + float far_width = far_height * frustum.AspectRatio; + + frustum.CornerPoint[0] = near_center - up * near_height - right * near_width; + frustum.CornerPoint[1] = near_center + up * near_height - right * near_width; + frustum.CornerPoint[2] = near_center + up * near_height + right * near_width; + frustum.CornerPoint[3] = near_center - up * near_height + right * near_width; + + frustum.CornerPoint[4] = far_center - up * far_height - right * far_width; + frustum.CornerPoint[5] = far_center + up * far_height - right * far_width; + frustum.CornerPoint[6] = far_center + up * far_height + right * far_width; + frustum.CornerPoint[7] = far_center - up * far_height + right * far_width; + + // Alternative way + //std::array CornerPoint = { + // glm::vec4(-1.f, -1.f, -1.f, 1.f), + // glm::vec4(-1.f, 1.f, -1.f, 1.f), + // glm::vec4(1.f, 1.f, -1.f, 1.f), + // glm::vec4(1.f, -1.f, -1.f, 1.f), + // glm::vec4(-1.f, -1.f, 1.f, 1.f), + // glm::vec4(-1.f, 1.f, 1.f, 1.f), + // glm::vec4(1.f, 1.f, 1.f, 1.f), + // glm::vec4(1.f, -1.f, 1.f, 1.f) }; + + //std::array final; + + //for (int i = 0; i < 8; i++) { + // glm::vec4 anus = glm::inverse(p) * CornerPoint[i]; + // anus = anus / anus.w; + // final[i] = glm::vec3(glm::inverse(v) * anus); + //} +} + +float ShadowPass::FindRadius(Frustum& frustum) +{ + float radius = 0.f; + + for (int i = 0; i < 8; i++) { + float distance = glm::distance(frustum.MiddlePoint, frustum.CornerPoint[i]); + if (distance > radius) { + radius = distance; + } } - //float scaleX = 2.0f / (maxX - minX); - //float scaleY = 2.0f / (maxY - minY); - //float offsetX = -0.5f * (maxX + minX) * scaleX; - //float offsetY = -0.5f * (maxY + minY) * scaleY; - // - //glm::mat4 nv_mvp = glm::mat4(); - //nv_mvp[0][0] = scaleX; - //nv_mvp[1][1] = scaleY; - //nv_mvp[0][3] = offsetX; - //nv_mvp[1][3] = offsetY; - //glm::transpose(nv_mvp); - - glm::mat4 p = glm::ortho(minX, maxX, minY, maxY, m_NearFarPlane[Near], m_NearFarPlane[Far]); - - return p; -} - -glm::mat4 ShadowPass::CalculateFrustum(RenderScene & scene, std::shared_ptr directionalLightJob, ShadowCamera shad_cam) -{ - glm::vec3 middle = shad_cam.camera->Position() + (shad_cam.camera->Forward() * shad_cam.camera->FarClip() * 0.5f); - - return glm::lookAt(glm::vec3(0.f) + middle, glm::vec3(directionalLightJob->Direction) + middle, glm::vec3(-1.f, 0.f, 0.f)); + frustum.Radius = radius; + return radius; } void ShadowPass::InitializeFrameBuffers() @@ -154,6 +148,36 @@ void ShadowPass::ClearBuffer() } } +void ShadowPass::PointsToLightspace(Frustum& frustum, glm::mat4 v) +{ + float left = INFINITY; + float right = -INFINITY; + float bottom = INFINITY; + float top = -INFINITY; + + for (int i = 0; i < 8; i++) + { + glm::vec3 tempPoint = glm::vec3(v * glm::vec4(frustum.CornerPoint[i], 1.f)); + + if (tempPoint.x < left) { left = tempPoint.x; } + if (tempPoint.x > right) { right = tempPoint.x; } + if (tempPoint.y < bottom) { bottom = tempPoint.y; } + if (tempPoint.y > top) { top = tempPoint.y; } + } + + frustum.LRTB = { left, right, bottom, top }; +} + +void ShadowPass::RadiusToLightspace(Frustum& frustum, glm::mat4 v) +{ + float left = -frustum.Radius; + float right = frustum.Radius; + float bottom = -frustum.Radius; + float top =frustum.Radius; + + frustum.LRTB = { left, right, bottom, top }; +} + void ShadowPass::Draw(RenderScene & scene) { ImGui::DragFloat4("ShadowMapCam", m_LRBT, 1.f, -1000.f, 1000.f); @@ -161,15 +185,12 @@ void ShadowPass::Draw(RenderScene & scene) ImGui::Checkbox("EnableShadow", &m_ShadowOn); ImGui::DragInt("ShadowLevel", &m_ShadowLevel, 0.05f, 0, m_CurrentNrOfSplits - 1); - for (int i = 0; i < m_CurrentNrOfSplits; i++) { - m_shadCams[i].camera = new Camera(*scene.Camera); - //m_shadCams[i].frustumCorners = tempPoints; - } - - UpdateSplitDist(m_shadCams, scene.Camera->NearClip(), scene.Camera->FarClip()); + InitializeCameras(scene); + UpdateSplitDist(m_shadFrusta, scene.Camera->NearClip(), scene.Camera->FarClip()); for (int i = 0; i < m_CurrentNrOfSplits; i++) { - m_shadCams[i].frustumCorners = UpdateFrustumPoints(m_shadCams[i].camera, m_shadCams[i].camera->Position(), m_shadCams[i].camera->Forward()); + UpdateFrustumPoints(m_shadFrusta[i], scene.Camera->Position(), scene.Camera->Forward(), scene.Camera->ProjectionMatrix(), scene.Camera->ViewMatrix()); + //float test = FindRadius(m_shadFrusta[i]); ShadowPassState* state = new ShadowPassState(m_DepthBuffer[i].GetHandle()); @@ -187,8 +208,11 @@ void ShadowPass::Draw(RenderScene & scene) auto directionalLightJob = std::dynamic_pointer_cast(job); if (directionalLightJob) { - m_LightView[i] = CalculateFrustum(scene, directionalLightJob, m_shadCams[i]); - m_LightProjection[i] = FindNewFrustum(m_shadCams[i]); + m_LightView[i] = glm::lookAt(glm::vec3(-directionalLightJob->Direction) + m_shadFrusta[i].MiddlePoint, m_shadFrusta[i].MiddlePoint, glm::vec3(0.f, 1.f, 0.f)); + + PointsToLightspace(m_shadFrusta[i], m_LightView[i]); + m_LightProjection[i] = glm::ortho(m_shadFrusta[i].LRTB[Left], m_shadFrusta[i].LRTB[Right], m_shadFrusta[i].LRTB[Bottom], m_shadFrusta[i].LRTB[Top], -30.f, 30.f); + //m_LightProjection[i] = glm::ortho(m_shadFrusta[i].LRTB[Left], m_shadFrusta[i].LRTB[Right], m_shadFrusta[i].LRTB[Bottom], m_shadFrusta[i].LRTB[Top], -0.f, 300.f); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_LightProjection[i])); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_LightView[i])); @@ -197,7 +221,7 @@ void ShadowPass::Draw(RenderScene & scene) for (auto &objectJob : scene.OpaqueObjects) { auto modelJob = std::dynamic_pointer_cast(objectJob); - + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); glBindVertexArray(modelJob->Model->VAO); From df2e4abb527938bcaf4689b8e392f835456ff1f7 Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Thu, 25 Feb 2016 21:21:38 +0100 Subject: [PATCH 034/130] WE HAVE WORKING CASCADE SHADOWS --- resources/Shaders/ForwardPlus.frag.glsl | 35 +++++++++++++------------ src/Engine/Rendering/ShadowPass.cpp | 4 +-- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/resources/Shaders/ForwardPlus.frag.glsl b/resources/Shaders/ForwardPlus.frag.glsl index 76169707..f4fd0dd1 100644 --- a/resources/Shaders/ForwardPlus.frag.glsl +++ b/resources/Shaders/ForwardPlus.frag.glsl @@ -194,12 +194,14 @@ float CalcShadowValue(vec4 positionLightSpace, vec3 normal, vec3 lightDir, sampl int getShadowIndex(float far_distance[MAX_SPLITS]) { + float depth = gl_FragCoord.z / gl_FragCoord.w; + int index = 2; - if( gl_FragCoord.z < far_distance[0] ) + if( depth < far_distance[0] ) { index = 0; } - else if( gl_FragCoord.z < far_distance[1] && gl_FragCoord.z > far_distance[0] ) + else if( depth < far_distance[1] && depth > far_distance[0] ) { index = 1; } @@ -207,7 +209,7 @@ int getShadowIndex(float far_distance[MAX_SPLITS]) return index; } -//sampler2DShadow whichDepthMap( int DepthMapIndex ) +//sampler2DShadow whichDepthMap(int DepthMapIndex) //{ // if( DepthMapIndex == 0 ) // { @@ -221,7 +223,6 @@ int getShadowIndex(float far_distance[MAX_SPLITS]) // { // return DepthMap2; // } -// //} void main() @@ -275,19 +276,19 @@ void main() light_result = CalcDirectionalLightSource(V * light.Direction, light.Color, light.Intensity, viewVec, normal); - shadowFactor = CalcShadowValue(Input.PositionLightSpace[0], Input.Normal, vec3(light.Direction), DepthMap0); - //if( DepthMapIndex == 0 ) - //{ - // shadowFactor = CalcShadowValue(Input.PositionLightSpace[DepthMapIndex], Input.Normal, vec3(light.Direction), DepthMap0); - //} - //else if( DepthMapIndex == 1 ) - //{ - // shadowFactor = CalcShadowValue(Input.PositionLightSpace[DepthMapIndex], Input.Normal, vec3(light.Direction), DepthMap1); - //} - //else - //{ - // shadowFactor = CalcShadowValue(Input.PositionLightSpace[DepthMapIndex], Input.Normal, vec3(light.Direction), DepthMap2); - //} + //shadowFactor = CalcShadowValue(Input.PositionLightSpace[0], Input.Normal, vec3(light.Direction), DepthMap0); + if( DepthMapIndex == 0 ) + { + shadowFactor = CalcShadowValue(Input.PositionLightSpace[DepthMapIndex], Input.Normal, vec3(light.Direction), DepthMap0); + } + else if( DepthMapIndex == 1 ) + { + shadowFactor = CalcShadowValue(Input.PositionLightSpace[DepthMapIndex], Input.Normal, vec3(light.Direction), DepthMap1); + } + else + { + shadowFactor = CalcShadowValue(Input.PositionLightSpace[DepthMapIndex], Input.Normal, vec3(light.Direction), DepthMap2); + } } totalLighting.Diffuse += light_result.Diffuse; diff --git a/src/Engine/Rendering/ShadowPass.cpp b/src/Engine/Rendering/ShadowPass.cpp index 1c31f91e..a5ef4663 100644 --- a/src/Engine/Rendering/ShadowPass.cpp +++ b/src/Engine/Rendering/ShadowPass.cpp @@ -111,7 +111,7 @@ void ShadowPass::InitializeFrameBuffers() for (int i = 0; i < m_CurrentNrOfSplits; i++) { glBindTexture(GL_TEXTURE_2D, m_DepthMap[i]); - glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, resolutionSizeWidth / (1 + i), resolutionSizeHeigth + (1 + i), 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr); + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, resolutionSizeWidth / (1 /*+ i*/), resolutionSizeHeigth + (1 /*+ i*/), 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, nullptr); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); @@ -197,7 +197,7 @@ void ShadowPass::Draw(RenderScene & scene) GLuint shaderHandle = m_ShadowProgram->GetHandle(); m_ShadowProgram->Bind(); - glViewport(0, 0, resolutionSizeWidth / (1 + i), resolutionSizeHeigth); + glViewport(0, 0, resolutionSizeWidth / (1/* + i*/), resolutionSizeHeigth); glDisable(GL_TEXTURE_2D); glCullFace(GL_FRONT); //state->Disable(GL_CULL_FACE); From af034673f6244002820bf459556ad43c0e65a4c5 Mon Sep 17 00:00:00 2001 From: viktorljung Date: Fri, 26 Feb 2016 10:17:47 +0100 Subject: [PATCH 035/130] BoneAttachments now working and BlendTrees are created in the AnimationSystem --- include/Engine/Rendering/AnimationSystem.h | 15 +- include/Engine/Rendering/BlendTree.h | 4 +- .../Engine/Rendering/BoneAttachmentSystem.h | 1 + include/Engine/Rendering/ModelJob.h | 5 +- include/Engine/Rendering/Skeleton.h | 28 +-- include/Game/Systems/LifetimeSystem.h | 2 +- resources/Schema/Entities/AnimationTests2.xml | 234 ++++++++++-------- src/Engine/Rendering/AnimationSystem.cpp | 89 +++++-- src/Engine/Rendering/BlendTree.cpp | 13 +- src/Engine/Rendering/BoneAttachmentSystem.cpp | 77 ++---- src/Engine/Rendering/DrawFinalPass.cpp | 69 +++--- src/Engine/Rendering/PickingPass.cpp | 24 +- src/Engine/Rendering/Skeleton.cpp | 16 +- 13 files changed, 308 insertions(+), 269 deletions(-) diff --git a/include/Engine/Rendering/AnimationSystem.h b/include/Engine/Rendering/AnimationSystem.h index dbe4b3fc..d05dc765 100644 --- a/include/Engine/Rendering/AnimationSystem.h +++ b/include/Engine/Rendering/AnimationSystem.h @@ -9,20 +9,17 @@ #include "Rendering/Model.h" #include "Rendering/EAnimationComplete.h" #include "Rendering/Skeleton.h" -#include +#include "Rendering/BlendTree.h" -class AnimationSystem : public PureSystem +class AnimationSystem : public ImpureSystem { public: - AnimationSystem(SystemParams params) - : System(params) - , PureSystem("Animation") - { - - } + AnimationSystem(SystemParams params); ~AnimationSystem() { } - virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& animationComponent, double dt) override; + virtual void Update(double dt) override; private: + void CreateBlendTrees(); + void UpdateAnimations(double dt); }; diff --git a/include/Engine/Rendering/BlendTree.h b/include/Engine/Rendering/BlendTree.h index 8d192cfe..a472465b 100644 --- a/include/Engine/Rendering/BlendTree.h +++ b/include/Engine/Rendering/BlendTree.h @@ -62,7 +62,7 @@ public: std::vector GetFinalPose() { return m_FinalPose; } - + glm::mat4 GetBoneTransform(int boneID); void PrintTree(); @@ -72,6 +72,8 @@ private: Node* m_Root = nullptr; std::vector m_FinalPose; + std::map m_FinalBoneTransforms; + std::vector AccumulateFinalPose(); BlendTree::Node* FillTreeByName(Node* parentNode, std::string name, EntityWrapper parentEntity); diff --git a/include/Engine/Rendering/BoneAttachmentSystem.h b/include/Engine/Rendering/BoneAttachmentSystem.h index 55c2a1c8..2791d877 100644 --- a/include/Engine/Rendering/BoneAttachmentSystem.h +++ b/include/Engine/Rendering/BoneAttachmentSystem.h @@ -8,6 +8,7 @@ #include "Core/ResourceManager.h" #include "Rendering/Model.h" #include "Rendering/Skeleton.h" +#include "Rendering/BlendTree.h" //Needs to be a higher orderlevel than AnimationSystem class BoneAttachmentSystem : public PureSystem diff --git a/include/Engine/Rendering/ModelJob.h b/include/Engine/Rendering/ModelJob.h index 4ea7a1f6..adc21c6f 100644 --- a/include/Engine/Rendering/ModelJob.h +++ b/include/Engine/Rendering/ModelJob.h @@ -125,7 +125,10 @@ struct ModelJob : RenderJob if (Skeleton != nullptr) { EntityWrapper entityWrapper = EntityWrapper(world, modelComponent.EntityID); - BlendTree = std::shared_ptr<::BlendTree>(new ::BlendTree(entityWrapper, Skeleton)); + + if(Skeleton->BlendTrees.find(entityWrapper) != Skeleton->BlendTrees.end()) { + BlendTree = Skeleton->BlendTrees.at(entityWrapper); + } } } }; diff --git a/include/Engine/Rendering/Skeleton.h b/include/Engine/Rendering/Skeleton.h index fa5a329d..ffa08452 100644 --- a/include/Engine/Rendering/Skeleton.h +++ b/include/Engine/Rendering/Skeleton.h @@ -6,27 +6,9 @@ #include "../GLM.h" #include #include +#include "../Core/EntityWrapper.h" -//struct Bone -//{ -// Bone(std::string name, glm::mat4 offsetMatrix) -// : Name(name) -// , OffsetMatrix(offsetMatrix) -// { } -// -// ~Bone() -// { -// for (auto kv : Children) { -// delete kv.second; -// } -// } -// -// std::string Name; -// glm::mat4 OffsetMatrix; -// glm::mat4 LocalMatrix; -// -// std::map Children; -//}; +class BlendTree; class Skeleton { @@ -75,6 +57,8 @@ public: std::map Bones; + std::unordered_map> BlendTrees; + // Attach a new bone to the skeleton // Returns: New bone index int CreateBone(int ID, int parentID, std::string name, glm::mat4 offsetMatrix); @@ -86,13 +70,13 @@ public: std::map BlendPoses(const std::map& pose1, const std::map& pose2, float weight); std::map OverridePose(const std::map& overridePose, const std::map& targetPose); std::map BlendPoseAdditive(const std::map& additivePose, const std::map& targetPose); - std::vector GetFinalPose(std::map& boneMatrices); + void GetFinalPose(std::map& boneMatrices, std::vector& finalPose, std::map& boneTransforms); std::map Animations; private: glm::mat4 GetAdditiveBonePose(const Bone* bone, const Animation* animation, double time); glm::mat4 GetBonePose(const Bone* bone, const Animation* animation, double time, bool noRootMotion); - void AccumulateFinalPose(std::map& boneMatrices, const Bone* bone, glm::mat4 parentMatrix); + void AccumulateFinalPose(std::map& boneMatrices, std::map& boneTransforms, const Bone* bone, glm::mat4 parentMatrix); void AdditiveBoneTransforms(const Animation* animation, double time, std::map& boneMatrices, const Bone* bone); void AccumulateBoneTransforms(bool noRootMotion, const Animation* animation, double time, std::map& boneMatrices, const Bone* bone, glm::mat4 parentMatrix); diff --git a/include/Game/Systems/LifetimeSystem.h b/include/Game/Systems/LifetimeSystem.h index 6dee644d..d19308d5 100644 --- a/include/Game/Systems/LifetimeSystem.h +++ b/include/Game/Systems/LifetimeSystem.h @@ -10,7 +10,7 @@ public: : System(params) , PureSystem("Lifetime") { - LOG_INFO("ASDASDASSA"); + } virtual void Update(double dt) override; diff --git a/resources/Schema/Entities/AnimationTests2.xml b/resources/Schema/Entities/AnimationTests2.xml index 4779bbaf..ca7c705d 100644 --- a/resources/Schema/Entities/AnimationTests2.xml +++ b/resources/Schema/Entities/AnimationTests2.xml @@ -9,19 +9,22 @@ - + + - + + 0.10000047832727432 + Models/Widgets/Lights/DirectionalLightWidget.mesh - + @@ -30,36 +33,22 @@ - 10 + 8 + 0.20000000298023224 - + - - - - - - 10 - - - - - - - - + Models/Core/UnitPlane.mesh - - - + @@ -85,7 +74,9 @@ Models/Weapons/Blue/AssaultWeaponBlue.mesh + + @@ -94,7 +85,6 @@ AimRifleA - true @@ -114,7 +104,7 @@ ShootFastRifleU - + 1 @@ -123,63 +113,28 @@ - - BlendWalkRun - StrafeAnimation - 1 - + + RunF + + 1 + - - - - - StrafeRightF - - 1 - - - - - - - - - RunAnimtaion - WalkAnimation - 0.43000054359436035 - - - - - - - - RunF - - 1 - - - - - - - - - WalkF - - 1 - - - - - - - - + + + + + 3 + + + + + + + @@ -206,7 +161,9 @@ Models/Weapons/Blue/AssaultWeaponBlue.mesh + + @@ -215,7 +172,8 @@ AimRifleA - + + 0.5 true @@ -235,7 +193,7 @@ ShootFastRifleU - + 1 @@ -247,7 +205,7 @@ BlendWalkRun StrafeAnimation - 1 + 0 @@ -255,8 +213,8 @@ - StrafeRightF - + StrafeLeftF + 1 @@ -268,7 +226,7 @@ RunAnimtaion WalkAnimation - 0.43000054359436035 + 1 @@ -277,7 +235,7 @@ RunF - + 1 @@ -288,7 +246,7 @@ WalkF - + 1 @@ -301,6 +259,20 @@ + + + + + 3 + 0.80000001192092896 + 0.30000001192092896 + + + + + + + @@ -327,7 +299,9 @@ Models/Weapons/Blue/AssaultWeaponBlue.mesh + + @@ -336,7 +310,7 @@ AimRifleA - + true @@ -355,8 +329,8 @@ - ShootFastRifleU - + ShootRifleU + 1 @@ -368,7 +342,7 @@ BlendWalkRun StrafeAnimation - 1 + 0 @@ -377,7 +351,7 @@ StrafeRightF - + 1 @@ -398,7 +372,7 @@ RunF - + 1 @@ -409,7 +383,7 @@ WalkF - + 1 @@ -422,6 +396,19 @@ + + + + + 3 + 0.30000001192092896 + + + + + + + @@ -448,7 +435,9 @@ Models/Weapons/Blue/AssaultWeaponBlue.mesh + + @@ -457,7 +446,7 @@ AimRifleA - + true @@ -473,17 +462,6 @@ - - - - ShootFastRifleU - - 1 - - - - - @@ -498,7 +476,7 @@ StrafeRightF - + 1 @@ -510,7 +488,7 @@ RunAnimtaion WalkAnimation - 0.43000054359436035 + 1 @@ -518,8 +496,8 @@ - RunF - + CrouchWalkF + 1 @@ -530,7 +508,7 @@ WalkF - + 1 @@ -541,10 +519,50 @@ + + + + ReloadSwitchU + + 1 + + + + + + + + + + 3 + + + + + + + + + + + Models/Core/UnitSphere.mesh + + + + + 3 + + + + + + + + diff --git a/src/Engine/Rendering/AnimationSystem.cpp b/src/Engine/Rendering/AnimationSystem.cpp index 1b260b08..9a74da29 100644 --- a/src/Engine/Rendering/AnimationSystem.cpp +++ b/src/Engine/Rendering/AnimationSystem.cpp @@ -1,66 +1,109 @@ #include "Rendering/AnimationSystem.h" -void AnimationSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& animationComponent, double dt) +AnimationSystem::AnimationSystem(SystemParams params) + : System(params) { - - EntityWrapper parent = entity.FirstParentWithComponent("Model"); - Model* model; - try { - model = ResourceManager::Load<::Model, true>(parent["Model"]["Resource"]); - } catch (const std::exception&) { +} + +void AnimationSystem::Update(double dt) +{ + UpdateAnimations(dt); + CreateBlendTrees(); +} + +void AnimationSystem::CreateBlendTrees() +{ + auto modelComponents = m_World->GetComponents("Model"); + if (modelComponents == nullptr) { return; } - Skeleton* skeleton = model->m_RawModel->m_Skeleton; - if (skeleton == nullptr) { + for (auto& modelC : *modelComponents) { + EntityWrapper entity = EntityWrapper(m_World, modelC.EntityID); + + Model* model; + try { + model = ResourceManager::Load<::Model, true>(entity["Model"]["Resource"]); + } catch (const std::exception&) { + continue;; + } + + Skeleton* skeleton = model->m_RawModel->m_Skeleton; + if (skeleton == nullptr) { + continue; + } + + skeleton->BlendTrees[entity] = std::shared_ptr(new BlendTree(entity, skeleton)); + } +} + +void AnimationSystem::UpdateAnimations(double dt) +{ + auto animationComponents = m_World->GetComponents("Animation"); + if(animationComponents == nullptr) { return; } - for (int i = 1; i <= 1; i++) { - const Skeleton::Animation* animation = skeleton->GetAnimation(animationComponent["AnimationName"]); + for (auto& animationC : *animationComponents) { + EntityWrapper entity = EntityWrapper(m_World, animationC.EntityID); + EntityWrapper parent = entity.FirstParentWithComponent("Model"); + + Model* model; + try { + model = ResourceManager::Load<::Model, true>(parent["Model"]["Resource"]); + } catch (const std::exception&) { + return; + } + + Skeleton* skeleton = model->m_RawModel->m_Skeleton; + if (skeleton == nullptr) { + return; + } + + const Skeleton::Animation* animation = skeleton->GetAnimation(animationC["AnimationName"]); if (animation == nullptr) { continue;; } - double animationSpeed = (double)animationComponent["Speed"]; + double animationSpeed = (double)animationC["Speed"]; if (animationSpeed != 0.0) { - double nextTime = (double)animationComponent["Time"] + animationSpeed * dt; + double nextTime = (double)animationC["Time"] + animationSpeed * dt; - if (!(bool)animationComponent["Loop"]) { + if (!(bool)animationC["Loop"]) { if (nextTime > animation->Duration) { nextTime = animation->Duration; Events::AnimationComplete e; e.Entity = entity; - e.Name = (std::string)animationComponent["AnimationName"]; + e.Name = (std::string)animationC["AnimationName"]; m_EventBroker->Publish(e); } else if (nextTime < 0) { Events::AnimationComplete e; e.Entity = entity; - e.Name = (std::string)animationComponent["AnimationName"]; + e.Name = (std::string)animationC["AnimationName"]; m_EventBroker->Publish(e); nextTime = 0; } - (double&)animationComponent["Speed"] = 0.0; - + (double&)animationC["Speed"] = 0.0; + } else { if (nextTime > animation->Duration) { Events::AnimationComplete e; e.Entity = entity; - e.Name = (std::string)animationComponent["AnimationName"]; + e.Name = (std::string)animationC["AnimationName"]; m_EventBroker->Publish(e); - while(nextTime > animation->Duration) { + while (nextTime > animation->Duration) { nextTime -= animation->Duration; } } else if (nextTime < 0) { Events::AnimationComplete e; e.Entity = entity; - e.Name = (std::string)animationComponent["AnimationName"]; + e.Name = (std::string)animationC["AnimationName"]; m_EventBroker->Publish(e); while (nextTime < 0) { @@ -69,8 +112,8 @@ void AnimationSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& a } } - (double&)animationComponent["Time"] = nextTime; + (double&)animationC["Time"] = nextTime; } - } + } } diff --git a/src/Engine/Rendering/BlendTree.cpp b/src/Engine/Rendering/BlendTree.cpp index 1d628a06..0d87665f 100644 --- a/src/Engine/Rendering/BlendTree.cpp +++ b/src/Engine/Rendering/BlendTree.cpp @@ -76,6 +76,17 @@ BlendTree::~BlendTree() } } + +glm::mat4 BlendTree::GetBoneTransform(int boneID) +{ + if(m_FinalBoneTransforms.find(boneID) != m_FinalBoneTransforms.end()) { + return m_FinalBoneTransforms.at(boneID); + } else { + return glm::mat4(1); + } + +} + void BlendTree::PrintTree() { Node* currentNode = m_Root; @@ -213,7 +224,7 @@ std::vector BlendTree::AccumulateFinalPose() std::map pose; Blend(pose); - finalPose = m_Skeleton->GetFinalPose(pose); + m_Skeleton->GetFinalPose(pose, finalPose, m_FinalBoneTransforms); return finalPose; } diff --git a/src/Engine/Rendering/BoneAttachmentSystem.cpp b/src/Engine/Rendering/BoneAttachmentSystem.cpp index 0e259f4b..43dc8634 100644 --- a/src/Engine/Rendering/BoneAttachmentSystem.cpp +++ b/src/Engine/Rendering/BoneAttachmentSystem.cpp @@ -8,10 +8,13 @@ void BoneAttachmentSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapp return; } - auto parent = entity.FirstParentWithComponent("Animation"); - if (!parent.HasComponent("Model")) { + auto parent = entity.FirstParentWithComponent("Model"); + + if(!parent.Valid()) { return; } + + Model* model; try { model = ResourceManager::Load<::Model, true>(parent["Model"]["Resource"]); @@ -35,61 +38,29 @@ void BoneAttachmentSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapp return; } - /* std::vector<::Skeleton::AnimationData> Animations; - ::Skeleton::AnimationOffset AnimationOffset; - glm::mat4 boneTransform; + if (skeleton->BlendTrees.find(parent) != skeleton->BlendTrees.end()) { - if (parent.HasComponent("Animation")) { - ::Skeleton::AnimationData animationData; - animationData.animation = model->m_RawModel->m_Skeleton->GetAnimation(parent["Animation"]["AnimationName"]); - if (animationData.animation != nullptr) { - animationData.time = (double)parent["Animation"]["Time"]; - Animations.push_back(animationData); - } - } - if (parent.HasComponent("AnimationOffset")) { - AnimationOffset.animation = model->m_RawModel->m_Skeleton->GetAnimation(parent["AnimationOffset"]["AnimationName"]); - AnimationOffset.time = (double)parent["AnimationOffset"]["Time"]; + glm::mat4 boneTransform = skeleton->BlendTrees.at(parent)->GetBoneTransform(id); - if(AnimationOffset.animation != nullptr) { - boneTransform = skeleton->GetBoneTransform(false, skeleton->Bones.at(id), Animations, AnimationOffset, glm::mat4(1)); - } else { - boneTransform = skeleton->GetBoneTransform(false, skeleton->Bones.at(id), Animations, glm::mat4(1)); - } + glm::vec3 scale; + glm::quat rotation; + glm::vec3 translation; + glm::vec3 skew; + glm::vec4 perspective; + glm::decompose(boneTransform, scale, rotation, translation, skew, perspective); + + glm::vec3 angles = glm::vec3(-glm::pitch(rotation), -glm::yaw(rotation), -glm::roll(rotation)); - } else { - boneTransform = skeleton->GetBoneTransform(false, skeleton->Bones.at(id), Animations, glm::mat4(1)); + if ((bool)entity["BoneAttachment"]["InheritPosition"]) { + (glm::vec3&)entity["Transform"]["Position"] = translation + (glm::vec3)entity["BoneAttachment"]["PositionOffset"]; + } + if ((bool)entity["BoneAttachment"]["InheritOrientation"]) { + (glm::vec3&)entity["Transform"]["Orientation"] = angles + (glm::vec3)entity["BoneAttachment"]["OrientationOffset"]; + } + if ((bool)entity["BoneAttachment"]["InheritScale"]) { + (glm::vec3&)entity["Transform"]["Scale"] = scale * (glm::vec3)entity["BoneAttachment"]["ScaleOffset"]; + } } - - - glm::vec3 scale; - glm::quat rotation; - glm::vec3 translation; - glm::vec3 skew; - glm::vec4 perspective; - glm::decompose(boneTransform, scale, rotation, translation, skew, perspective); - - glm::vec3 angles = glm::vec3(-glm::pitch(rotation), -glm::yaw(rotation), -glm::roll(rotation)); -/ * - - angles.y = asin(-boneTransform[0][2]); - if (cos(angles.y) != 0) { - angles.x = atan2(boneTransform[1][2], boneTransform[2][2]); - angles.z = atan2(boneTransform[0][1], boneTransform[0][0]); - } else { - angles.x = atan2(-boneTransform[2][0], boneTransform[1][1]); - angles.z = 0; - }* / - - if ((bool)entity["BoneAttachment"]["InheritPosition"]) { - (glm::vec3&)entity["Transform"]["Position"] = translation + (glm::vec3)entity["BoneAttachment"]["PositionOffset"]; - } - if ((bool)entity["BoneAttachment"]["InheritOrientation"]) { - (glm::vec3&)entity["Transform"]["Orientation"] = angles + (glm::vec3)entity["BoneAttachment"]["OrientationOffset"]; - } - if ((bool)entity["BoneAttachment"]["InheritScale"]) { - (glm::vec3&)entity["Transform"]["Scale"] = scale * (glm::vec3)entity["BoneAttachment"]["ScaleOffset"]; - }*/ } diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index b139f2ba..7360d064 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -337,9 +337,11 @@ void DrawFinalPass::DrawModelRenderQueues(std::list>& BindExplosionUniforms(explosionSkinnedHandle, explosionEffectJob, scene); //bind textures BindExplosionTextures(explosionSkinnedHandle, explosionEffectJob); - std::vector frameBones; - frameBones = explosionEffectJob->BlendTree->GetFinalPose(); - glUniformMatrix4fv(glGetUniformLocation(explosionSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); + if (explosionEffectJob->BlendTree != nullptr) { + std::vector frameBones; + frameBones = explosionEffectJob->BlendTree->GetFinalPose(); + glUniformMatrix4fv(glGetUniformLocation(explosionSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); + } } else { m_ExplosionEffectProgram->Bind(); GLERROR("Bind ExplosionEffect program"); @@ -360,10 +362,11 @@ void DrawFinalPass::DrawModelRenderQueues(std::list>& //bind textures BindExplosionTextures(explosionSplatMapSkinnedHandle, explosionEffectJob); GLERROR("asdasd"); - std::vector frameBones; - frameBones = explosionEffectJob->BlendTree->GetFinalPose(); - glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); - + if (explosionEffectJob->BlendTree != nullptr) { + std::vector frameBones; + frameBones = explosionEffectJob->BlendTree->GetFinalPose(); + glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); + } } else { m_ExplosionEffectSplatMapProgram->Bind(); GLERROR("Bind ExplosionEffectSplatMap program"); @@ -401,10 +404,12 @@ void DrawFinalPass::DrawModelRenderQueues(std::list>& BindModelUniforms(forwardSkinnedHandle, modelJob, scene); //bind textures BindModelTextures(forwardSkinnedHandle, modelJob); - std::vector frameBones; - frameBones = modelJob->BlendTree->GetFinalPose(); - glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); + if (modelJob->BlendTree != nullptr) { + std::vector frameBones; + frameBones = modelJob->BlendTree->GetFinalPose(); + glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); + } } else { m_ForwardPlusProgram->Bind(); GLERROR("Bind ForwardPlusProgram"); @@ -425,10 +430,11 @@ void DrawFinalPass::DrawModelRenderQueues(std::list>& //bind textures BindModelTextures(forwardSplatMapSkinnedHandle, modelJob); GLERROR("asdasd"); - std::vector frameBones; - frameBones = modelJob->BlendTree->GetFinalPose(); - glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); - + if (modelJob->BlendTree != nullptr) { + std::vector frameBones; + frameBones = modelJob->BlendTree->GetFinalPose(); + glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); + } } else { m_ForwardPlusSplatMapProgram->Bind(); GLERROR("Bind SplatMap program"); @@ -469,9 +475,11 @@ void DrawFinalPass::DrawShieldToStencilBuffer(std::listMatrix)); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix())); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix())); - std::vector frameBones; - frameBones = modelJob->BlendTree->GetFinalPose(); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); + if (modelJob->BlendTree != nullptr) { + std::vector frameBones; + frameBones = modelJob->BlendTree->GetFinalPose(); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); + } } else { m_ShieldToStencilProgram->Bind(); GLuint shaderHandle = m_ShieldToStencilProgram->GetHandle(); @@ -523,10 +531,11 @@ void DrawFinalPass::DrawShieldedModelRenderQueue(std::list frameBones; - frameBones = explosionEffectJob->BlendTree->GetFinalPose(); - glUniformMatrix4fv(glGetUniformLocation(explosionHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); - + if (explosionEffectJob->BlendTree != nullptr) { + std::vector frameBones; + frameBones = explosionEffectJob->BlendTree->GetFinalPose(); + glUniformMatrix4fv(glGetUniformLocation(explosionHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); + } if (GLERROR("Animation")) { continue; } @@ -558,10 +567,11 @@ void DrawFinalPass::DrawShieldedModelRenderQueue(std::list frameBones; - frameBones = modelJob->BlendTree->GetFinalPose(); - glUniformMatrix4fv(glGetUniformLocation(forwardHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); - + if (modelJob->BlendTree != nullptr) { + std::vector frameBones; + frameBones = modelJob->BlendTree->GetFinalPose(); + glUniformMatrix4fv(glGetUniformLocation(forwardHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); + } //draw glBindVertexArray(modelJob->Model->VAO); @@ -590,10 +600,11 @@ void DrawFinalPass::DrawToDepthBuffer(std::list>& job glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix())); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); - std::vector frameBones; - frameBones = modelJob->BlendTree->GetFinalPose(); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); - + if (modelJob->BlendTree != nullptr) { + std::vector frameBones; + frameBones = modelJob->BlendTree->GetFinalPose(); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); + } } else { m_FillDepthBufferProgram->Bind(); GLuint shaderHandle = m_FillDepthBufferProgram->GetHandle(); diff --git a/src/Engine/Rendering/PickingPass.cpp b/src/Engine/Rendering/PickingPass.cpp index 64483755..4d156e46 100644 --- a/src/Engine/Rendering/PickingPass.cpp +++ b/src/Engine/Rendering/PickingPass.cpp @@ -100,12 +100,10 @@ void PickingPass::Draw(RenderScene& scene) glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix())); glUniform2fv(glGetUniformLocation(shaderSkinnedHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1]))); - if (modelJob->Model->m_RawModel->m_Skeleton != nullptr) { - + if (modelJob->BlendTree != nullptr) { std::vector frameBones; frameBones = modelJob->BlendTree->GetFinalPose(); glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); - } } else { m_PickingProgram->Bind(); @@ -155,9 +153,11 @@ void PickingPass::Draw(RenderScene& scene) glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix())); glUniform2fv(glGetUniformLocation(shaderSkinnedHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1]))); - std::vector frameBones; - frameBones = modelJob->BlendTree->GetFinalPose(); - glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); + if (modelJob->BlendTree != nullptr) { + std::vector frameBones; + frameBones = modelJob->BlendTree->GetFinalPose(); + glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); + } } else { m_PickingProgram->Bind(); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); @@ -206,9 +206,11 @@ void PickingPass::Draw(RenderScene& scene) glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix())); glUniform2fv(glGetUniformLocation(shaderSkinnedHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1]))); - std::vector frameBones; - frameBones = modelJob->BlendTree->GetFinalPose(); - glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); + if (modelJob->BlendTree != nullptr) { + std::vector frameBones; + frameBones = modelJob->BlendTree->GetFinalPose(); + glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); + } } else { m_PickingProgram->Bind(); @@ -261,12 +263,10 @@ void PickingPass::Draw(RenderScene& scene) glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix())); glUniform2fv(glGetUniformLocation(shaderSkinnedHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1]))); - if (modelJob->Model->m_RawModel->m_Skeleton != nullptr) { - + if (modelJob->BlendTree != nullptr) { std::vector frameBones; frameBones = modelJob->BlendTree->GetFinalPose(); glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); - } } else { m_PickingProgram->Bind(); diff --git a/src/Engine/Rendering/Skeleton.cpp b/src/Engine/Rendering/Skeleton.cpp index 077e9d02..4583de92 100644 --- a/src/Engine/Rendering/Skeleton.cpp +++ b/src/Engine/Rendering/Skeleton.cpp @@ -94,7 +94,7 @@ void Skeleton::AdditiveBoneTransforms(const Animation* animation, double time, s { if (animation->JointAnimations.find(bone->ID) != animation->JointAnimations.end()) { glm::mat4 refPose = GetAdditiveBonePose(bone, animation, 0.0); - glm::mat4 srcPose = GetAdditiveBonePose(bone, animation, time); + glm::mat4 srcPose = GetAdditiveBonePose(bone, animation, time + 1.0/60.0); glm::mat4 boneMatrix = srcPose * glm::inverse(refPose); boneMatrices[bone->ID] = boneMatrix; } @@ -335,21 +335,17 @@ std::map Skeleton::BlendPoseAdditive(const std::map Skeleton::GetFinalPose(std::map& boneMatrices) +void Skeleton::GetFinalPose(std::map& boneMatrices, std::vector& finalPose, std::map& boneTransforms) { - std::vector finalPose; - - AccumulateFinalPose(boneMatrices, RootBone, glm::mat4(1)); - + AccumulateFinalPose(boneMatrices, boneTransforms, RootBone, glm::mat4(1)); for(auto& b : boneMatrices) { finalPose.push_back(b.second); } - return finalPose; } -void Skeleton::AccumulateFinalPose(std::map& boneMatrices, const Bone* bone, glm::mat4 parentMatrix) +void Skeleton::AccumulateFinalPose(std::map& boneMatrices, std::map& boneTransforms, const Bone* bone, glm::mat4 parentMatrix) { glm::mat4 boneMatrix; @@ -370,8 +366,10 @@ void Skeleton::AccumulateFinalPose(std::map& boneMatrices, const } } + boneTransforms[bone->ID] = boneMatrix; + for (auto &child : bone->Children) { - AccumulateFinalPose(boneMatrices, child, boneMatrix); + AccumulateFinalPose(boneMatrices, boneTransforms, child, boneMatrix); } } From f220d8088c13285239625b86f6519dc93fb3a6ee Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Fri, 26 Feb 2016 10:53:16 +0100 Subject: [PATCH 036/130] Begin clean-up --- include/Engine/Rendering/ShadowPass.h | 30 +++++++--------------- src/Engine/Rendering/DrawFinalPass.cpp | 6 ++--- src/Engine/Rendering/ShadowPass.cpp | 35 +++++++++++++------------- 3 files changed, 29 insertions(+), 42 deletions(-) diff --git a/include/Engine/Rendering/ShadowPass.h b/include/Engine/Rendering/ShadowPass.h index b7c37b31..373bc21b 100644 --- a/include/Engine/Rendering/ShadowPass.h +++ b/include/Engine/Rendering/ShadowPass.h @@ -9,17 +9,12 @@ #include "ShadowPassState.h" #include "imgui/imgui.h" -#define MAX_SPLITS 3 +#define MAX_SPLITS 4 #define MAP_SIZE 216.f enum NearFar { Near = 0, Far = 1 }; enum LRBT { Left = 0, Right = 1, Bottom = 2, Top = 3 }; -struct ShadowCamera{ - Camera* camera; - std::array frustumCorners; -}; - struct Frustum { float NearClip; @@ -28,7 +23,7 @@ struct Frustum float AspectRatio; glm::vec3 MiddlePoint; float Radius; - std::array LRTB; + std::array LRBT; std::array CornerPoint; }; @@ -45,24 +40,19 @@ public: void Draw(RenderScene& scene); GLuint DepthMap(int level) const { return m_DepthMap[level]; } - std::array lightP() const { return m_LightProjection; } - std::array lightV() const { return m_LightView; } - std::array farDistance() const { return { m_shadFrusta[0].FarClip, m_shadFrusta[1].FarClip, m_shadFrusta[2].FarClip }; } + std::array LightP() const { return m_LightProjection; } + std::array LightV() const { return m_LightView; } + std::array FarDistance() const { return { m_shadowFrusta[0].FarClip, m_shadowFrusta[1].FarClip, m_shadowFrusta[2].FarClip, m_shadowFrusta[3].FarClip }; } int CurrentNrOfSplits() const { return m_CurrentNrOfSplits; } private: void UpdateFrustumPoints(Frustum& frustum, glm::vec3 camera_position, glm::vec3 view_dir, glm::mat4 p, glm::mat4 v); void UpdateSplitDist(std::array& frusta, float near_distance, float far_distance); - glm::mat4 ApplyCropMatrix(Frustum& frustum, glm::mat4 m, glm::mat4 v); - - glm::mat4 CalculateFrustum(RenderScene & scene, std::shared_ptr directionalLightJob, ShadowCamera shad_cam); - glm::mat4 FindNewFrustum(Frustum frustum, glm::mat4 v, glm::mat4 p); void InitializeCameras(RenderScene & scene); float FindRadius(Frustum& frustum); void PointsToLightspace(Frustum& frustum, glm::mat4 v); void RadiusToLightspace(Frustum& frustum, glm::mat4 v); - - EventBroker* m_EventBroker; + EventBroker* m_EventBroker; const IRenderer* m_Renderer; std::array m_DepthMap; @@ -77,8 +67,8 @@ private: GLfloat m_NearFarPlane[2] = { -34.f, 27.f }; GLfloat m_LRBT[4] = { -10.f, 10.f, -10.f, 10.f }; - GLuint resolutionSizeWidth = 1024 * 2; - GLuint resolutionSizeHeigth = 1024 * 2; + GLuint m_ResolutionSizeWidth = 1024 * 2; + GLuint m_ResolutionSizeHeigth = 1024 * 2; bool m_ShadowOn = true; int m_ShadowLevel = 0; @@ -86,9 +76,7 @@ private: int m_CurrentNrOfSplits = 3; float m_SplitWeight = 0.75f; - //std::array m_shadCams; - Frustum m_MainCamera; - std::array m_shadFrusta; + std::array m_shadowFrusta; }; #endif \ No newline at end of file diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index 8770adb4..537bc3dc 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -244,9 +244,9 @@ void DrawFinalPass::BindModelUniforms(GLuint shaderHandle, std::shared_ptrlightP().data())); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "LightV"), MAX_SPLITS, GL_FALSE, glm::value_ptr(*m_ShadowPass->lightV().data())); - glUniform1fv(glGetUniformLocation(shaderHandle, "FarDistance"), MAX_SPLITS, m_ShadowPass->farDistance().data()); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "LightP"), MAX_SPLITS, GL_FALSE, glm::value_ptr(*m_ShadowPass->LightP().data())); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "LightV"), MAX_SPLITS, GL_FALSE, glm::value_ptr(*m_ShadowPass->LightV().data())); + glUniform1fv(glGetUniformLocation(shaderHandle, "FarDistance"), MAX_SPLITS, m_ShadowPass->FarDistance().data()); //GLfloat m_NearFarPlane[2] = { -40.f, 30.f }; diff --git a/src/Engine/Rendering/ShadowPass.cpp b/src/Engine/Rendering/ShadowPass.cpp index a5ef4663..c3eb8c73 100644 --- a/src/Engine/Rendering/ShadowPass.cpp +++ b/src/Engine/Rendering/ShadowPass.cpp @@ -11,14 +11,14 @@ ShadowPass::ShadowPass(IRenderer * renderer) ShadowPass::~ShadowPass() { - // m_shadCams + } void ShadowPass::InitializeCameras(RenderScene & scene) { for (int i = 0; i < m_CurrentNrOfSplits; i++) { - m_shadFrusta[i].AspectRatio = scene.Camera->AspectRatio(); - m_shadFrusta[i].FOV = scene.Camera->FOV(); + m_shadowFrusta[i].AspectRatio = scene.Camera->AspectRatio(); + m_shadowFrusta[i].FOV = scene.Camera->FOV(); } } @@ -69,7 +69,7 @@ void ShadowPass::UpdateFrustumPoints(Frustum& frustum, glm::vec3 camera_position frustum.CornerPoint[6] = far_center + up * far_height + right * far_width; frustum.CornerPoint[7] = far_center - up * far_height + right * far_width; - // Alternative way + // Alternative way. //std::array CornerPoint = { // glm::vec4(-1.f, -1.f, -1.f, 1.f), // glm::vec4(-1.f, 1.f, -1.f, 1.f), @@ -80,12 +80,12 @@ void ShadowPass::UpdateFrustumPoints(Frustum& frustum, glm::vec3 camera_position // glm::vec4(1.f, 1.f, 1.f, 1.f), // glm::vec4(1.f, -1.f, 1.f, 1.f) }; - //std::array final; + //std::array FinalPoints; //for (int i = 0; i < 8; i++) { - // glm::vec4 anus = glm::inverse(p) * CornerPoint[i]; - // anus = anus / anus.w; - // final[i] = glm::vec3(glm::inverse(v) * anus); + // glm::vec4 NDC = glm::inverse(p) * CornerPoint[i]; + // NDC = NDC / NDC.w; + // FinalPoints[i] = glm::vec3(glm::inverse(v) * NDC); //} } @@ -111,7 +111,7 @@ void ShadowPass::InitializeFrameBuffers() for (int i = 0; i < m_CurrentNrOfSplits; i++) { glBindTexture(GL_TEXTURE_2D, m_DepthMap[i]); - glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, resolutionSizeWidth / (1 /*+ i*/), resolutionSizeHeigth + (1 /*+ i*/), 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, nullptr); + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, m_ResolutionSizeWidth / (1 /*+ i*/), m_ResolutionSizeHeigth + (1 /*+ i*/), 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, nullptr); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); @@ -165,7 +165,7 @@ void ShadowPass::PointsToLightspace(Frustum& frustum, glm::mat4 v) if (tempPoint.y > top) { top = tempPoint.y; } } - frustum.LRTB = { left, right, bottom, top }; + frustum.LRBT = { left, right, bottom, top }; } void ShadowPass::RadiusToLightspace(Frustum& frustum, glm::mat4 v) @@ -175,7 +175,7 @@ void ShadowPass::RadiusToLightspace(Frustum& frustum, glm::mat4 v) float bottom = -frustum.Radius; float top =frustum.Radius; - frustum.LRTB = { left, right, bottom, top }; + frustum.LRBT = { left, right, bottom, top }; } void ShadowPass::Draw(RenderScene & scene) @@ -186,10 +186,10 @@ void ShadowPass::Draw(RenderScene & scene) ImGui::DragInt("ShadowLevel", &m_ShadowLevel, 0.05f, 0, m_CurrentNrOfSplits - 1); InitializeCameras(scene); - UpdateSplitDist(m_shadFrusta, scene.Camera->NearClip(), scene.Camera->FarClip()); + UpdateSplitDist(m_shadowFrusta, scene.Camera->NearClip(), scene.Camera->FarClip()); for (int i = 0; i < m_CurrentNrOfSplits; i++) { - UpdateFrustumPoints(m_shadFrusta[i], scene.Camera->Position(), scene.Camera->Forward(), scene.Camera->ProjectionMatrix(), scene.Camera->ViewMatrix()); + UpdateFrustumPoints(m_shadowFrusta[i], scene.Camera->Position(), scene.Camera->Forward(), scene.Camera->ProjectionMatrix(), scene.Camera->ViewMatrix()); //float test = FindRadius(m_shadFrusta[i]); ShadowPassState* state = new ShadowPassState(m_DepthBuffer[i].GetHandle()); @@ -197,7 +197,7 @@ void ShadowPass::Draw(RenderScene & scene) GLuint shaderHandle = m_ShadowProgram->GetHandle(); m_ShadowProgram->Bind(); - glViewport(0, 0, resolutionSizeWidth / (1/* + i*/), resolutionSizeHeigth); + glViewport(0, 0, m_ResolutionSizeWidth / (1/* + i*/), m_ResolutionSizeHeigth); glDisable(GL_TEXTURE_2D); glCullFace(GL_FRONT); //state->Disable(GL_CULL_FACE); @@ -208,11 +208,10 @@ void ShadowPass::Draw(RenderScene & scene) auto directionalLightJob = std::dynamic_pointer_cast(job); if (directionalLightJob) { - m_LightView[i] = glm::lookAt(glm::vec3(-directionalLightJob->Direction) + m_shadFrusta[i].MiddlePoint, m_shadFrusta[i].MiddlePoint, glm::vec3(0.f, 1.f, 0.f)); + m_LightView[i] = glm::lookAt(glm::vec3(-directionalLightJob->Direction) + m_shadowFrusta[i].MiddlePoint, m_shadowFrusta[i].MiddlePoint, glm::vec3(0.f, 1.f, 0.f)); - PointsToLightspace(m_shadFrusta[i], m_LightView[i]); - m_LightProjection[i] = glm::ortho(m_shadFrusta[i].LRTB[Left], m_shadFrusta[i].LRTB[Right], m_shadFrusta[i].LRTB[Bottom], m_shadFrusta[i].LRTB[Top], -30.f, 30.f); - //m_LightProjection[i] = glm::ortho(m_shadFrusta[i].LRTB[Left], m_shadFrusta[i].LRTB[Right], m_shadFrusta[i].LRTB[Bottom], m_shadFrusta[i].LRTB[Top], -0.f, 300.f); + PointsToLightspace(m_shadowFrusta[i], m_LightView[i]); + m_LightProjection[i] = glm::ortho(m_shadowFrusta[i].LRBT[Left], m_shadowFrusta[i].LRBT[Right], m_shadowFrusta[i].LRBT[Bottom], m_shadowFrusta[i].LRBT[Top], -30.f, 30.f); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_LightProjection[i])); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_LightView[i])); From 22c391df54c3aa5479339c6e26dd7dbdedde5537 Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Fri, 26 Feb 2016 17:40:35 +0100 Subject: [PATCH 037/130] Initial work on texture arrays --- include/Engine/Rendering/FrameBuffer.h | 14 +++++ include/Engine/Rendering/ShadowPass.h | 9 ++- resources/Shaders/ExplosionEffect.geom.glsl | 2 +- resources/Shaders/ForwardPlus.frag.glsl | 63 ++++++--------------- resources/Shaders/ForwardPlus.vert.glsl | 2 +- src/Engine/Rendering/DrawFinalPass.cpp | 14 ++--- src/Engine/Rendering/FrameBuffer.cpp | 24 +++++++- src/Engine/Rendering/Renderer.cpp | 6 +- src/Engine/Rendering/ShadowPass.cpp | 53 ++++++++++------- 9 files changed, 101 insertions(+), 86 deletions(-) diff --git a/include/Engine/Rendering/FrameBuffer.h b/include/Engine/Rendering/FrameBuffer.h index cf63b6c6..325fbe3b 100644 --- a/include/Engine/Rendering/FrameBuffer.h +++ b/include/Engine/Rendering/FrameBuffer.h @@ -8,10 +8,12 @@ class BufferResource { public: BufferResource(GLuint* resourceHandle, GLenum resourceType, GLenum attachment); + BufferResource(GLuint* resourceHandle, GLenum resourceType, GLenum attachment, GLuint layers); GLuint* m_ResourceHandle; GLenum m_ResourceType; GLenum m_Attachment; + GLuint m_Layers; private: }; @@ -22,6 +24,9 @@ class ResourceType : public BufferResource public: ResourceType(GLuint* resourceHandle, GLenum attachment) : BufferResource(resourceHandle, RESOURCETYPE, attachment) { } + + ResourceType(GLuint* resourceHandle, GLenum attachment, GLuint layers) + : BufferResource(resourceHandle, RESOURCETYPE, attachment, layers) { } }; class Texture2D : public ResourceType @@ -43,6 +48,15 @@ public: ~RenderBuffer(); }; +class Texture2DArray : public ResourceType +{ +public: + Texture2DArray(GLuint* resourceHandle, GLenum attachment, GLuint layers) + : ResourceType(resourceHandle, attachment, layers) { }; + + ~Texture2DArray(); +}; + class FrameBuffer { public: diff --git a/include/Engine/Rendering/ShadowPass.h b/include/Engine/Rendering/ShadowPass.h index 373bc21b..192d54c7 100644 --- a/include/Engine/Rendering/ShadowPass.h +++ b/include/Engine/Rendering/ShadowPass.h @@ -39,7 +39,8 @@ public: void ClearBuffer(); void Draw(RenderScene& scene); - GLuint DepthMap(int level) const { return m_DepthMap[level]; } + //GLuint DepthMap(int level) const { return m_DepthMap[level]; } + GLuint DepthMap() const { return m_DepthMap; } std::array LightP() const { return m_LightProjection; } std::array LightV() const { return m_LightView; } std::array FarDistance() const { return { m_shadowFrusta[0].FarClip, m_shadowFrusta[1].FarClip, m_shadowFrusta[2].FarClip, m_shadowFrusta[3].FarClip }; } @@ -55,8 +56,10 @@ private: EventBroker* m_EventBroker; const IRenderer* m_Renderer; - std::array m_DepthMap; - std::array m_DepthBuffer; + //std::array m_DepthMap; + //std::array m_DepthBuffer; + GLuint m_DepthMap; + FrameBuffer m_DepthBuffer; std::array m_LightProjection; std::array m_LightView; diff --git a/resources/Shaders/ExplosionEffect.geom.glsl b/resources/Shaders/ExplosionEffect.geom.glsl index b4a90e3b..ffc78900 100644 --- a/resources/Shaders/ExplosionEffect.geom.glsl +++ b/resources/Shaders/ExplosionEffect.geom.glsl @@ -1,6 +1,6 @@ #version 430 -#define MAX_SPLITS 3 +#define MAX_SPLITS 4 uniform mat4 M; uniform mat4 V; diff --git a/resources/Shaders/ForwardPlus.frag.glsl b/resources/Shaders/ForwardPlus.frag.glsl index f4fd0dd1..7f80826a 100644 --- a/resources/Shaders/ForwardPlus.frag.glsl +++ b/resources/Shaders/ForwardPlus.frag.glsl @@ -1,6 +1,6 @@ #version 430 -#define MAX_SPLITS 3 +#define MAX_SPLITS 4 uniform mat4 M; uniform mat4 V; @@ -17,9 +17,8 @@ layout (binding = 0) uniform sampler2D DiffuseTexture; layout (binding = 1) uniform sampler2D NormalMapTexture; layout (binding = 2) uniform sampler2D SpecularMapTexture; layout (binding = 3) uniform sampler2D GlowMapTexture; -layout (binding = 4) uniform sampler2DShadow DepthMap0; -layout (binding = 5) uniform sampler2DShadow DepthMap1; -layout (binding = 6) uniform sampler2DShadow DepthMap2; +layout (binding = 4) uniform sampler2DShadow DepthMap[MAX_SPLITS]; + #define TILE_SIZE 16 @@ -209,36 +208,8 @@ int getShadowIndex(float far_distance[MAX_SPLITS]) return index; } -//sampler2DShadow whichDepthMap(int DepthMapIndex) -//{ -// if( DepthMapIndex == 0 ) -// { -// return DepthMap0; -// } -// else if( DepthMapIndex == 1 ) -// { -// return DepthMap1; -// } -// else -// { -// return DepthMap2; -// } -//} - void main() { - //sampler2DShadow DepthMaps[3] = { sampler2DShadow(DepthMap0), sampler2DShadow(DepthMap1), sampler2DShadow(DepthMap2) }; - //sampler2DShadow DepthMaps[3] = { DepthMap0, DepthMap1, DepthMap2 }; - //sampler2DShadow DepthMaps[3] = sampler2DShadow[]( DepthMap0, DepthMap1, DepthMap2 ); - //sampler2DShadow DepthMaps[3] = sampler2DShadow[3]( DepthMap0, DepthMap1, DepthMap2 ); - //sampler2DShadow DepthMaps[3]; - - //sampler2DShadow DepthMapOne = DepthMap0; - - //DepthMaps[0] = DepthMap0; - //DepthMaps[1] = DepthMap1; - //DepthMaps[2] = DepthMap2; - vec4 diffuseTexel = texture2D(DiffuseTexture, Input.TextureCoordinate); vec4 glowTexel = texture2D(GlowMapTexture, Input.TextureCoordinate); vec4 specularTexel = texture2D(SpecularMapTexture, Input.TextureCoordinate); @@ -271,24 +242,22 @@ void main() if(light.Type == 1) { // point light_result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, position, normal, light.Falloff); } else if (light.Type == 2) { //Directional - int DepthMapIndex = getShadowIndex(FarDistance); - //sampler2DShadow WhichDepthMap = whichDepthMap(DepthMapIndex); + //int DepthMapIndex = getShadowIndex(FarDistance); light_result = CalcDirectionalLightSource(V * light.Direction, light.Color, light.Intensity, viewVec, normal); - //shadowFactor = CalcShadowValue(Input.PositionLightSpace[0], Input.Normal, vec3(light.Direction), DepthMap0); - if( DepthMapIndex == 0 ) - { - shadowFactor = CalcShadowValue(Input.PositionLightSpace[DepthMapIndex], Input.Normal, vec3(light.Direction), DepthMap0); - } - else if( DepthMapIndex == 1 ) - { - shadowFactor = CalcShadowValue(Input.PositionLightSpace[DepthMapIndex], Input.Normal, vec3(light.Direction), DepthMap1); - } - else - { - shadowFactor = CalcShadowValue(Input.PositionLightSpace[DepthMapIndex], Input.Normal, vec3(light.Direction), DepthMap2); - } + //if( DepthMapIndex == 0 ) + //{ + shadowFactor = CalcShadowValue(Input.PositionLightSpace[0], Input.Normal, vec3(light.Direction), DepthMap[0]); + //} + //else if( DepthMapIndex == 1 ) + //{ + // shadowFactor = CalcShadowValue(Input.PositionLightSpace[DepthMapIndex], Input.Normal, vec3(light.Direction), DepthMap1); + //} + //else + //{ + // shadowFactor = CalcShadowValue(Input.PositionLightSpace[DepthMapIndex], Input.Normal, vec3(light.Direction), DepthMap2); + //} } totalLighting.Diffuse += light_result.Diffuse; diff --git a/resources/Shaders/ForwardPlus.vert.glsl b/resources/Shaders/ForwardPlus.vert.glsl index fb280e3a..0d9661cc 100644 --- a/resources/Shaders/ForwardPlus.vert.glsl +++ b/resources/Shaders/ForwardPlus.vert.glsl @@ -1,6 +1,6 @@ #version 430 -#define MAX_SPLITS 3 +#define MAX_SPLITS 4 uniform mat4 M; uniform mat4 V; diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index 537bc3dc..72bd8711 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -320,15 +320,15 @@ void DrawFinalPass::BindModelTextures(std::shared_ptr& job) glBindTexture(GL_TEXTURE_2D, m_BlackTexture->m_Texture); } - for (int i = 0; i < m_ShadowPass->CurrentNrOfSplits(); i++) - { - glActiveTexture(GL_TEXTURE4 + i); - if (m_ShadowPass->DepthMap(i) != NULL) { - glBindTexture(GL_TEXTURE_2D, m_ShadowPass->DepthMap(i)); + //for (int i = 0; i < m_ShadowPass->CurrentNrOfSplits(); i++) + //{ + glActiveTexture(GL_TEXTURE4); + if (m_ShadowPass->DepthMap() != NULL) { + glBindTexture(GL_TEXTURE_2D_ARRAY, m_ShadowPass->DepthMap()); } else { - glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture); + glBindTexture(GL_TEXTURE_2D_ARRAY, m_WhiteTexture->m_Texture); } - } + //} } diff --git a/src/Engine/Rendering/FrameBuffer.cpp b/src/Engine/Rendering/FrameBuffer.cpp index 44ffb20e..b5dad961 100644 --- a/src/Engine/Rendering/FrameBuffer.cpp +++ b/src/Engine/Rendering/FrameBuffer.cpp @@ -9,6 +9,14 @@ BufferResource::BufferResource(GLuint* resourceHandle, GLenum resourceType, GLen m_Attachment = attachment; } +BufferResource::BufferResource(GLuint* resourceHandle, GLenum resourceType, GLenum attachment, GLuint layers) +{ + m_ResourceHandle = resourceHandle; + m_ResourceType = resourceType; + m_Attachment = attachment; + m_Layers = layers; +} + Texture2D::~Texture2D() { if (m_ResourceHandle != 0) { @@ -16,6 +24,12 @@ Texture2D::~Texture2D() } } +Texture2DArray::~Texture2DArray() +{ + if (m_ResourceHandle != 0) { + glDeleteTextures(1, m_ResourceHandle); + } +} RenderBuffer::~RenderBuffer() { @@ -48,18 +62,22 @@ void FrameBuffer::Generate() switch ((*it)->m_ResourceType) { case GL_TEXTURE_2D: glFramebufferTexture2D(GL_FRAMEBUFFER, (*it)->m_Attachment, (*it)->m_ResourceType, *(*it)->m_ResourceHandle, 0); + attachments.push_back((*it)->m_Attachment); GLERROR("FrameBuffer generate: glFramebufferTexture2D"); break; case GL_RENDERBUFFER: glFramebufferRenderbuffer(GL_FRAMEBUFFER, (*it)->m_Attachment, (*it)->m_ResourceType, *(*it)->m_ResourceHandle); GLERROR("FrameBuffer generate: glFramebufferRenderbuffer"); break; + case GL_TEXTURE_2D_ARRAY: + glFramebufferTexture(GL_FRAMEBUFFER, (*it)->m_Attachment, *(*it)->m_ResourceHandle, 0); + attachments.push_back((*it)->m_Attachment); + GLERROR("FrameBuffer generate: GL_TEXTURE_2D_ARRAY"); + + break; } - if ((*it)->m_ResourceType == GL_TEXTURE_2D) { - attachments.push_back((*it)->m_Attachment); - } } GLenum* bufferTextures = &attachments[0]; diff --git a/src/Engine/Rendering/Renderer.cpp b/src/Engine/Rendering/Renderer.cpp index 5aa411fc..1341ac15 100644 --- a/src/Engine/Rendering/Renderer.cpp +++ b/src/Engine/Rendering/Renderer.cpp @@ -136,9 +136,9 @@ void Renderer::Draw(RenderFrame& frame) if (m_DebugTextureToDraw == 4) { m_DrawScreenQuadPass->Draw(m_PickingPass->PickingTexture()); } - if (m_DebugTextureToDraw == 5) { - m_DrawScreenQuadPass->Draw(m_ShadowPass->DepthMap(0)); - } + //if (m_DebugTextureToDraw == 5) { + // m_DrawScreenQuadPass->Draw(m_ShadowPass->DepthMap()); + //} m_ImGuiRenderPass->Draw(); glfwSwapBuffers(m_Window); diff --git a/src/Engine/Rendering/ShadowPass.cpp b/src/Engine/Rendering/ShadowPass.cpp index c3eb8c73..c734f695 100644 --- a/src/Engine/Rendering/ShadowPass.cpp +++ b/src/Engine/Rendering/ShadowPass.cpp @@ -106,26 +106,37 @@ float ShadowPass::FindRadius(Frustum& frustum) void ShadowPass::InitializeFrameBuffers() { - // Depth texture - glGenTextures(m_CurrentNrOfSplits, m_DepthMap.data()); + GLERROR("depthMap failed PRE"); + // Depth texture + glGenTextures(1, &m_DepthMap); - for (int i = 0; i < m_CurrentNrOfSplits; i++) { - glBindTexture(GL_TEXTURE_2D, m_DepthMap[i]); - glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, m_ResolutionSizeWidth / (1 /*+ i*/), m_ResolutionSizeHeigth + (1 /*+ i*/), 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, nullptr); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE); - glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, glm::vec4(1.f).data); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); - //glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY); + GLERROR("depthMap failed1"); + glBindTexture(GL_TEXTURE_2D_ARRAY, m_DepthMap); + GLERROR("depthMap failed2"); + glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_DEPTH_COMPONENT16, m_ResolutionSizeWidth, m_ResolutionSizeHeigth, m_CurrentNrOfSplits); + GLERROR("depthMap failed3"); - m_DepthBuffer[i].AddResource(std::shared_ptr(new Texture2D(&m_DepthMap[i], GL_DEPTH_ATTACHMENT))); - m_DepthBuffer[i].Generate(); - } + glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, m_ResolutionSizeWidth, m_ResolutionSizeHeigth, m_CurrentNrOfSplits, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, nullptr); + GLERROR("depthMap failed4"); - GLERROR("depthMap failed"); + //for (int i = 0; i < m_CurrentNrOfSplits; i++) { + // glBindTexture(GL_TEXTURE_2D, m_DepthMap[i]); + // glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, m_ResolutionSizeWidth / (1 /*+ i*/), m_ResolutionSizeHeigth + (1 /*+ i*/), 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, nullptr); + glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); + glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); + glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE); + glTexParameterfv(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BORDER_COLOR, glm::vec4(1.f).data); + glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); + //glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY); + GLERROR("depthMap failed5"); + + m_DepthBuffer.AddResource(std::shared_ptr(new Texture2DArray(&m_DepthMap, GL_DEPTH_ATTACHMENT, m_CurrentNrOfSplits))); + m_DepthBuffer.Generate(); + //} + + GLERROR("depthMap failed END"); } void ShadowPass::InitializeShaderPrograms() @@ -141,10 +152,10 @@ void ShadowPass::InitializeShaderPrograms() void ShadowPass::ClearBuffer() { for (int i = 0; i < m_CurrentNrOfSplits; i++) { - m_DepthBuffer[i].Bind(); + m_DepthBuffer.Bind(); glClearColor(0.f, 0.f, 0.f, 0.f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - m_DepthBuffer[i].Unbind(); + m_DepthBuffer.Unbind(); } } @@ -192,7 +203,7 @@ void ShadowPass::Draw(RenderScene & scene) UpdateFrustumPoints(m_shadowFrusta[i], scene.Camera->Position(), scene.Camera->Forward(), scene.Camera->ProjectionMatrix(), scene.Camera->ViewMatrix()); //float test = FindRadius(m_shadFrusta[i]); - ShadowPassState* state = new ShadowPassState(m_DepthBuffer[i].GetHandle()); + ShadowPassState* state = new ShadowPassState(m_DepthBuffer.GetHandle()); GLuint shaderHandle = m_ShadowProgram->GetHandle(); m_ShadowProgram->Bind(); @@ -230,7 +241,7 @@ void ShadowPass::Draw(RenderScene & scene) GLERROR("Shadow Draw ERROR"); } } - m_DepthBuffer[i].Unbind(); + m_DepthBuffer.Unbind(); delete state; } From 38d8cdded221dd9a82535ea99024b142ed8b9be0 Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Sat, 27 Feb 2016 15:53:28 +0100 Subject: [PATCH 038/130] Texture Array is now working. Enjoy your single Bind(). --- include/Engine/Rendering/ShadowPass.h | 4 +- resources/Shaders/ForwardPlus.frag.glsl | 74 +++++++++++++--------- src/Engine/Rendering/FrameBuffer.cpp | 1 - src/Engine/Rendering/Renderer.cpp | 6 +- src/Engine/Rendering/ShadowPass.cpp | 78 +++++++++++------------- src/Engine/Rendering/ShadowPassState.cpp | 4 ++ 6 files changed, 91 insertions(+), 76 deletions(-) diff --git a/include/Engine/Rendering/ShadowPass.h b/include/Engine/Rendering/ShadowPass.h index 192d54c7..6fab8a3a 100644 --- a/include/Engine/Rendering/ShadowPass.h +++ b/include/Engine/Rendering/ShadowPass.h @@ -68,7 +68,7 @@ private: GLuint m_DepthFBO; GLfloat m_NearFarPlane[2] = { -34.f, 27.f }; - GLfloat m_LRBT[4] = { -10.f, 10.f, -10.f, 10.f }; + //GLfloat m_LRBT[4] = { -10.f, 10.f, -10.f, 10.f }; GLuint m_ResolutionSizeWidth = 1024 * 2; GLuint m_ResolutionSizeHeigth = 1024 * 2; @@ -77,7 +77,7 @@ private: int m_ShadowLevel = 0; int m_CurrentNrOfSplits = 3; - float m_SplitWeight = 0.75f; + float m_SplitWeight = 0.7f; std::array m_shadowFrusta; }; diff --git a/resources/Shaders/ForwardPlus.frag.glsl b/resources/Shaders/ForwardPlus.frag.glsl index 7f80826a..7659f3b0 100644 --- a/resources/Shaders/ForwardPlus.frag.glsl +++ b/resources/Shaders/ForwardPlus.frag.glsl @@ -17,7 +17,7 @@ layout (binding = 0) uniform sampler2D DiffuseTexture; layout (binding = 1) uniform sampler2D NormalMapTexture; layout (binding = 2) uniform sampler2D SpecularMapTexture; layout (binding = 3) uniform sampler2D GlowMapTexture; -layout (binding = 4) uniform sampler2DShadow DepthMap[MAX_SPLITS]; +layout (binding = 4) uniform sampler2DArrayShadow DepthMap; #define TILE_SIZE 16 @@ -138,32 +138,59 @@ vec2 poissonDisk[16] = vec2[]( vec2( 0.14383161, -0.14100790 ) ); -float random(vec3 seed, int i) +float Random(vec3 seed, int i) { vec4 seed4 = vec4(seed, i); float dot_product = dot(seed4, vec4(12.9898, 78.233, 45.164, 94.673)); return fract(sin(dot_product) * 43758.5453); } -float CalcShadowValue(vec4 positionLightSpace, vec3 normal, vec3 lightDir, sampler2DShadow depthTexture) +// Standard hardware-calculated PCF method +float PCFShadow(sampler2DArrayShadow depth_texture_array, vec3 projection_coords, int layer_index) +{ + return texture(depth_texture_array, vec4(projection_coords.xy, layer_index, projection_coords.z)); +} + +float CalcShadowValue(vec4 light_space_pos, vec3 normal, vec3 light_dir, sampler2DArrayShadow depth_texture_array, int layer_index) { - - //float bias = 0.005; - //float bias = max(0.05 * (1.0 - dot(normal, lightDir)), 0.005); - float bias = 0.005 * tan(acos(clamp(dot(normal, -lightDir), 0.0, 1.0))); - - vec3 projCoords = vec3(positionLightSpace.xy, positionLightSpace.z + bias) / positionLightSpace.w; - projCoords = projCoords * 0.5 + 0.5; - //float shadowMapDepth = texture(depthTexture, projCoords.xy).r; float shadowMapDepth; + float bias; + + // Various bias methods. + + //bias = 0.005; + //bias = max(0.05 * (1.0 - dot(normal, light_dir)), 0.005); + bias = 0.005 * tan(acos(clamp(dot(normal, -light_dir), 0.0, 1.0))); + + // Calculate coordinates in projection space + vec3 projCoords = vec3(light_space_pos.xy, light_space_pos.z + bias) / light_space_pos.w; + projCoords = projCoords * 0.5 + 0.5; + + // Various methods for shadow calculation in fastest to slowest order. + + shadowMapDepth = PCFShadow(depth_texture_array, projCoords, layer_index); + + // PCF + Four-tap Poisson model method + //float SplitWeight = 0.7; //for (int i = 0; i < 4; i++) //{ - // int index = i; - // //int index = int(16.0 * random(gl_FragCoord.xyy, i)) % 16; - // shadowMapDepth += 0.25 * texture(depthTexture, projCoords + vec3(poissonDisk[index], 0.0) / 700.0); + // int loop = i; + // vec3 newProjCoords = projCoords + vec3(poissonDisk[loop], 0.0) / (1500.0 * SplitWeight * (1.0 + layer_index)); + // shadowMapDepth += 0.25 * texture(depthTexture, vec4(newProjCoords.xy, layer_index, newProjCoords.z)); //} - - shadowMapDepth = texture(depthTexture, projCoords); + // + //// PCF + Four-tap Poisson model method + //float SplitWeight = 0.7; + //for (int i = 0; i < 4; i++) + //{ + // int loop = i; + // vec3 newProjCoords = projCoords + vec3(poissonDisk[loop], 0.0) / (1500.0 * SplitWeight * (1.0 + layer_index)); + // //int loop = int(16.0 * Random(gl_FragCoord.xyy, i)) % 16; + // shadowMapDepth += 0.25 * texture(depthTexture, vec4(newProjCoords.xy, layer_index, newProjCoords.z)); + //} + + + //float geometryDepth = projCoords.z; //float shadow = geometryDepth - bias > shadowMapDepth ? 1.0 : 0.0; @@ -242,22 +269,11 @@ void main() if(light.Type == 1) { // point light_result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, position, normal, light.Falloff); } else if (light.Type == 2) { //Directional - //int DepthMapIndex = getShadowIndex(FarDistance); + int DepthMapIndex = getShadowIndex(FarDistance); light_result = CalcDirectionalLightSource(V * light.Direction, light.Color, light.Intensity, viewVec, normal); - //if( DepthMapIndex == 0 ) - //{ - shadowFactor = CalcShadowValue(Input.PositionLightSpace[0], Input.Normal, vec3(light.Direction), DepthMap[0]); - //} - //else if( DepthMapIndex == 1 ) - //{ - // shadowFactor = CalcShadowValue(Input.PositionLightSpace[DepthMapIndex], Input.Normal, vec3(light.Direction), DepthMap1); - //} - //else - //{ - // shadowFactor = CalcShadowValue(Input.PositionLightSpace[DepthMapIndex], Input.Normal, vec3(light.Direction), DepthMap2); - //} + shadowFactor = CalcShadowValue(Input.PositionLightSpace[DepthMapIndex], Input.Normal, vec3(light.Direction), DepthMap, DepthMapIndex); } totalLighting.Diffuse += light_result.Diffuse; diff --git a/src/Engine/Rendering/FrameBuffer.cpp b/src/Engine/Rendering/FrameBuffer.cpp index b5dad961..cc563600 100644 --- a/src/Engine/Rendering/FrameBuffer.cpp +++ b/src/Engine/Rendering/FrameBuffer.cpp @@ -73,7 +73,6 @@ void FrameBuffer::Generate() glFramebufferTexture(GL_FRAMEBUFFER, (*it)->m_Attachment, *(*it)->m_ResourceHandle, 0); attachments.push_back((*it)->m_Attachment); GLERROR("FrameBuffer generate: GL_TEXTURE_2D_ARRAY"); - break; } diff --git a/src/Engine/Rendering/Renderer.cpp b/src/Engine/Rendering/Renderer.cpp index 1341ac15..a26a7f09 100644 --- a/src/Engine/Rendering/Renderer.cpp +++ b/src/Engine/Rendering/Renderer.cpp @@ -136,9 +136,9 @@ void Renderer::Draw(RenderFrame& frame) if (m_DebugTextureToDraw == 4) { m_DrawScreenQuadPass->Draw(m_PickingPass->PickingTexture()); } - //if (m_DebugTextureToDraw == 5) { - // m_DrawScreenQuadPass->Draw(m_ShadowPass->DepthMap()); - //} + if (m_DebugTextureToDraw == 5) { + m_DrawScreenQuadPass->Draw(m_ShadowPass->DepthMap()); + } m_ImGuiRenderPass->Draw(); glfwSwapBuffers(m_Window); diff --git a/src/Engine/Rendering/ShadowPass.cpp b/src/Engine/Rendering/ShadowPass.cpp index c734f695..dd423f25 100644 --- a/src/Engine/Rendering/ShadowPass.cpp +++ b/src/Engine/Rendering/ShadowPass.cpp @@ -119,9 +119,6 @@ void ShadowPass::InitializeFrameBuffers() glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, m_ResolutionSizeWidth, m_ResolutionSizeHeigth, m_CurrentNrOfSplits, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, nullptr); GLERROR("depthMap failed4"); - //for (int i = 0; i < m_CurrentNrOfSplits; i++) { - // glBindTexture(GL_TEXTURE_2D, m_DepthMap[i]); - // glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, m_ResolutionSizeWidth / (1 /*+ i*/), m_ResolutionSizeHeigth + (1 /*+ i*/), 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, nullptr); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); @@ -129,7 +126,6 @@ void ShadowPass::InitializeFrameBuffers() glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE); glTexParameterfv(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BORDER_COLOR, glm::vec4(1.f).data); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); - //glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY); GLERROR("depthMap failed5"); m_DepthBuffer.AddResource(std::shared_ptr(new Texture2DArray(&m_DepthMap, GL_DEPTH_ATTACHMENT, m_CurrentNrOfSplits))); @@ -151,12 +147,15 @@ void ShadowPass::InitializeShaderPrograms() void ShadowPass::ClearBuffer() { + m_DepthBuffer.Bind(); + for (int i = 0; i < m_CurrentNrOfSplits; i++) { - m_DepthBuffer.Bind(); - glClearColor(0.f, 0.f, 0.f, 0.f); + glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_DepthMap, 0, i); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - m_DepthBuffer.Unbind(); } + + m_DepthBuffer.Unbind(); } void ShadowPass::PointsToLightspace(Frustum& frustum, glm::mat4 v) @@ -191,67 +190,64 @@ void ShadowPass::RadiusToLightspace(Frustum& frustum, glm::mat4 v) void ShadowPass::Draw(RenderScene & scene) { - ImGui::DragFloat4("ShadowMapCam", m_LRBT, 1.f, -1000.f, 1000.f); +// ImGui::DragFloat4("ShadowMapCam", m_LRBT, 1.f, -1000.f, 1000.f); ImGui::DragFloat2("ShadowMapNearFar", m_NearFarPlane, 1.f, -1000.f, 1000.f); ImGui::Checkbox("EnableShadow", &m_ShadowOn); - ImGui::DragInt("ShadowLevel", &m_ShadowLevel, 0.05f, 0, m_CurrentNrOfSplits - 1); + //ImGui::DragInt("ShadowLevel", &m_ShadowLevel, 0.05f, 0, m_CurrentNrOfSplits - 1); InitializeCameras(scene); UpdateSplitDist(m_shadowFrusta, scene.Camera->NearClip(), scene.Camera->FarClip()); + ShadowPassState* state = new ShadowPassState(m_DepthBuffer.GetHandle()); + + m_ShadowProgram->Bind(); + for (int i = 0; i < m_CurrentNrOfSplits; i++) { UpdateFrustumPoints(m_shadowFrusta[i], scene.Camera->Position(), scene.Camera->Forward(), scene.Camera->ProjectionMatrix(), scene.Camera->ViewMatrix()); //float test = FindRadius(m_shadFrusta[i]); - ShadowPassState* state = new ShadowPassState(m_DepthBuffer.GetHandle()); - GLuint shaderHandle = m_ShadowProgram->GetHandle(); - m_ShadowProgram->Bind(); + + glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_DepthMap, 0, i); - glViewport(0, 0, m_ResolutionSizeWidth / (1/* + i*/), m_ResolutionSizeHeigth); - glDisable(GL_TEXTURE_2D); - glCullFace(GL_FRONT); + glViewport(0, 0, m_ResolutionSizeWidth, m_ResolutionSizeHeigth); + //state->Disable(GL_CULL_FACE); - if (m_ShadowOn == true) - { - for (auto &job : scene.DirectionalLightJobs) { - auto directionalLightJob = std::dynamic_pointer_cast(job); + for (auto &job : scene.DirectionalLightJobs) { + auto directionalLightJob = std::dynamic_pointer_cast(job); - if (directionalLightJob) { - m_LightView[i] = glm::lookAt(glm::vec3(-directionalLightJob->Direction) + m_shadowFrusta[i].MiddlePoint, m_shadowFrusta[i].MiddlePoint, glm::vec3(0.f, 1.f, 0.f)); - - PointsToLightspace(m_shadowFrusta[i], m_LightView[i]); - m_LightProjection[i] = glm::ortho(m_shadowFrusta[i].LRBT[Left], m_shadowFrusta[i].LRBT[Right], m_shadowFrusta[i].LRBT[Bottom], m_shadowFrusta[i].LRBT[Top], -30.f, 30.f); + if (directionalLightJob) { + m_LightView[i] = glm::lookAt(glm::vec3(-directionalLightJob->Direction) + m_shadowFrusta[i].MiddlePoint, m_shadowFrusta[i].MiddlePoint, glm::vec3(0.f, 1.f, 0.f)); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_LightProjection[i])); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_LightView[i])); + PointsToLightspace(m_shadowFrusta[i], m_LightView[i]); + m_LightProjection[i] = glm::ortho(m_shadowFrusta[i].LRBT[Left], m_shadowFrusta[i].LRBT[Right], m_shadowFrusta[i].LRBT[Bottom], m_shadowFrusta[i].LRBT[Top], m_NearFarPlane[Near], m_NearFarPlane[Far]); - GLERROR("ShadowLight ERROR"); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_LightProjection[i])); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_LightView[i])); - for (auto &objectJob : scene.OpaqueObjects) { - auto modelJob = std::dynamic_pointer_cast(objectJob); - - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); + GLERROR("ShadowLight ERROR"); - glBindVertexArray(modelJob->Model->VAO); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); - glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int))); + for (auto &objectJob : scene.OpaqueObjects) { + auto modelJob = std::dynamic_pointer_cast(objectJob); - GLERROR("Shadow Draw ERROR"); - } + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); + + glBindVertexArray(modelJob->Model->VAO); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); + glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int))); + + GLERROR("Shadow Draw ERROR"); } - m_DepthBuffer.Unbind(); - - delete state; } + } glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height); - glEnable(GL_TEXTURE_2D); - glCullFace(GL_BACK); m_ShadowProgram->Unbind(); } + m_DepthBuffer.Unbind(); + delete state; } diff --git a/src/Engine/Rendering/ShadowPassState.cpp b/src/Engine/Rendering/ShadowPassState.cpp index caa09b9f..f84b6436 100644 --- a/src/Engine/Rendering/ShadowPassState.cpp +++ b/src/Engine/Rendering/ShadowPassState.cpp @@ -8,6 +8,10 @@ ShadowPassState::ShadowPassState(GLuint frameBuffer) Enable(GL_DEPTH_TEST); Enable(GL_CULL_FACE); Disable(GL_BLEND); + Disable(GL_TEXTURE_2D); + CullFace(GL_FRONT); + ClearColor(glm::vec4(255.f, 128.f, 128.f, 128.f)); + GLERROR("---4"); } ShadowPassState::~ShadowPassState() From ecab5de0567f1b6dffd237da40d3ea5f88b2de2c Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Sat, 27 Feb 2016 16:35:15 +0100 Subject: [PATCH 039/130] Various shadow calculation methods implemented and ready for use. --- resources/Shaders/ForwardPlus.frag.glsl | 136 +++++++++++++----------- resources/Shaders/Shadow.frag.glsl | 10 +- resources/Shaders/Shadow.vert.glsl | 5 - src/Engine/Rendering/DrawFinalPass.cpp | 16 ++- 4 files changed, 82 insertions(+), 85 deletions(-) diff --git a/resources/Shaders/ForwardPlus.frag.glsl b/resources/Shaders/ForwardPlus.frag.glsl index 7659f3b0..b3240911 100644 --- a/resources/Shaders/ForwardPlus.frag.glsl +++ b/resources/Shaders/ForwardPlus.frag.glsl @@ -1,6 +1,7 @@ #version 430 #define MAX_SPLITS 4 +#define SPLIT_WEIGHT 0.7 uniform mat4 M; uniform mat4 V; @@ -73,6 +74,25 @@ struct LightResult { vec4 Specular; }; +vec2 poissonDisk[16] = vec2[]( + vec2( -0.94201624, -0.39906216 ), + vec2( 0.94558609, -0.76890725 ), + vec2( -0.094184101, -0.92938870 ), + vec2( 0.34495938, 0.29387760 ), + vec2( -0.91588581, 0.45771432 ), + vec2( -0.81544232, -0.87912464 ), + vec2( -0.38277543, 0.27676845 ), + vec2( 0.97484398, 0.75648379 ), + vec2( 0.44323325, -0.97511554 ), + vec2( 0.53742981, -0.47373420 ), + vec2( -0.26496911, -0.41893023 ), + vec2( 0.79197514, 0.19090188 ), + vec2( -0.24188840, 0.99706507 ), + vec2( -0.81409955, 0.91437590 ), + vec2( 0.19984126, 0.78641367 ), + vec2( 0.14383161, -0.14100790 ) + ); + float CalcAttenuation(float radius, float dist, float falloff) { return 1.0 - smoothstep(radius * 0.3, radius, dist); } @@ -119,25 +139,6 @@ vec4 CalcNormalMappedValue(vec3 normal, vec3 tangent, vec3 bitangent, vec2 textu return vec4(TBN * normalize(NormalMap), 0.0); } -vec2 poissonDisk[16] = vec2[]( - vec2( -0.94201624, -0.39906216 ), - vec2( 0.94558609, -0.76890725 ), - vec2( -0.094184101, -0.92938870 ), - vec2( 0.34495938, 0.29387760 ), - vec2( -0.91588581, 0.45771432 ), - vec2( -0.81544232, -0.87912464 ), - vec2( -0.38277543, 0.27676845 ), - vec2( 0.97484398, 0.75648379 ), - vec2( 0.44323325, -0.97511554 ), - vec2( 0.53742981, -0.47373420 ), - vec2( -0.26496911, -0.41893023 ), - vec2( 0.79197514, 0.19090188 ), - vec2( -0.24188840, 0.99706507 ), - vec2( -0.81409955, 0.91437590 ), - vec2( 0.19984126, 0.78641367 ), - vec2( 0.14383161, -0.14100790 ) -); - float Random(vec3 seed, int i) { vec4 seed4 = vec4(seed, i); @@ -151,6 +152,57 @@ float PCFShadow(sampler2DArrayShadow depth_texture_array, vec3 projection_coords return texture(depth_texture_array, vec4(projection_coords.xy, layer_index, projection_coords.z)); } +// PCF + Poisson model method +float PoissonShadow(sampler2DArrayShadow depth_texture_array, vec3 projection_coords, int layer_index, int taps, float spread) +{ + int loop; + float multiplier = 1.0 / float(taps); + float shadowMapDepth; + + for (int i = 0; i < taps; i++) + { + loop = i; + vec3 newProjCoords = projection_coords + vec3(poissonDisk[loop], 0.0) / (spread * SPLIT_WEIGHT * (1.0 + layer_index)); + shadowMapDepth += multiplier * texture(depth_texture_array, vec4(newProjCoords.xy, layer_index, newProjCoords.z)); + } + + return shadowMapDepth; +} + +// PCF + Poisson + RandomSample model method +float PoissonDotShadow(sampler2DArrayShadow depth_texture_array, vec3 projection_coords, int layer_index, int taps, float spread) +{ + int loop; + float multiplier = 1.0 / float(taps); + float shadowMapDepth; + + for (int i = 0; i < taps; i++) + { + loop = int(16.0 * Random(gl_FragCoord.xyy, i)) % 16; + vec3 newProjCoords = projection_coords + vec3(poissonDisk[loop], 0.0) / (spread * SPLIT_WEIGHT * (1.0 + layer_index)); + shadowMapDepth += multiplier * texture(depth_texture_array, vec4(newProjCoords.xy, layer_index, newProjCoords.z)); + } + + return shadowMapDepth; +} + +// Hardware PCF + Additional software PCF method +float SoftwarePCF(sampler2DArrayShadow depth_texture_array, vec3 projection_coords, int layer_index, float bias) +{ + float shadow = 0.0; + + vec3 texelSize = 1.0 / textureSize(depth_texture_array, 0); + for(int x = -1; x <= 1; x++) + { + for(int y = -1; y <= 1; y++) + { + shadow += texture(depth_texture_array, vec4(projection_coords.xy + vec2(x, y) * texelSize.xy, layer_index, projection_coords.z)); + } + } + + return shadow / 9.0; +} + float CalcShadowValue(vec4 light_space_pos, vec3 normal, vec3 light_dir, sampler2DArrayShadow depth_texture_array, int layer_index) { float shadowMapDepth; @@ -169,53 +221,13 @@ float CalcShadowValue(vec4 light_space_pos, vec3 normal, vec3 light_dir, sampler // Various methods for shadow calculation in fastest to slowest order. shadowMapDepth = PCFShadow(depth_texture_array, projCoords, layer_index); - - // PCF + Four-tap Poisson model method - //float SplitWeight = 0.7; - //for (int i = 0; i < 4; i++) - //{ - // int loop = i; - // vec3 newProjCoords = projCoords + vec3(poissonDisk[loop], 0.0) / (1500.0 * SplitWeight * (1.0 + layer_index)); - // shadowMapDepth += 0.25 * texture(depthTexture, vec4(newProjCoords.xy, layer_index, newProjCoords.z)); - //} - // - //// PCF + Four-tap Poisson model method - //float SplitWeight = 0.7; - //for (int i = 0; i < 4; i++) - //{ - // int loop = i; - // vec3 newProjCoords = projCoords + vec3(poissonDisk[loop], 0.0) / (1500.0 * SplitWeight * (1.0 + layer_index)); - // //int loop = int(16.0 * Random(gl_FragCoord.xyy, i)) % 16; - // shadowMapDepth += 0.25 * texture(depthTexture, vec4(newProjCoords.xy, layer_index, newProjCoords.z)); - //} - - - - - //float geometryDepth = projCoords.z; - //float shadow = geometryDepth - bias > shadowMapDepth ? 1.0 : 0.0; - //float shadow = 1.0 - bias > shadowMapDepth ? 0.0 : 1.0; + //shadowMapDepth = PoissonShadow(depth_texture_array, projCoords, layer_index, 4, 1500.0); + //shadowMapDepth = PoissonDotShadow(depth_texture_array, projCoords, layer_index, 4, 1500.0); + //shadowMapDepth = SoftwarePCF(depth_texture_array, projCoords, layer_index, bias); float shadow = 1.0 - shadowMapDepth; - - //vec2 texelSize = 1.0 / textureSize(depthTexture, 0); - //for(int x = -1; x <= 1; x++) - //{ - // for(int y = -1; y <= 1; y++) - // { - // float pcfDepth = texture(depthTexture, projCoords.xy + vec2(x, y) * texelSize).r; - // shadow += geometryDepth - bias > pcfDepth ? 1.0 : 0.0; - // } - //} - //shadow /= 9.0; - - //if(projCoords.z > 1.0) - //{ - // shadow = 0.0; - //} return shadow; - } int getShadowIndex(float far_distance[MAX_SPLITS]) diff --git a/resources/Shaders/Shadow.frag.glsl b/resources/Shaders/Shadow.frag.glsl index 798d1cda..58290b59 100644 --- a/resources/Shaders/Shadow.frag.glsl +++ b/resources/Shaders/Shadow.frag.glsl @@ -1,18 +1,10 @@ #version 430 - - -//in VertexData{ -// vec3 Position; -//}Input; - -//layout(location = 0 ) out vec4 ShadowMap; layout(location = 0 ) out float ShadowMap; void main() { - //ShadowMap = vec4(vec3(gl_FragCoord.z), 1.0); - //ShadowMap = (gl_FragCoord.z); + } diff --git a/resources/Shaders/Shadow.vert.glsl b/resources/Shaders/Shadow.vert.glsl index 16c0b26e..8a0dc8f4 100644 --- a/resources/Shaders/Shadow.vert.glsl +++ b/resources/Shaders/Shadow.vert.glsl @@ -6,12 +6,7 @@ uniform mat4 P; layout(location = 0) in vec3 Position; -//out VertexData{ -// vec3 Position; -//}Output; - void main() { -// Output.Position = Position; gl_Position = P * V * M * vec4(Position, 1.0); } \ No newline at end of file diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index 72bd8711..98a56f6b 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -320,15 +320,13 @@ void DrawFinalPass::BindModelTextures(std::shared_ptr& job) glBindTexture(GL_TEXTURE_2D, m_BlackTexture->m_Texture); } - //for (int i = 0; i < m_ShadowPass->CurrentNrOfSplits(); i++) - //{ - glActiveTexture(GL_TEXTURE4); - if (m_ShadowPass->DepthMap() != NULL) { - glBindTexture(GL_TEXTURE_2D_ARRAY, m_ShadowPass->DepthMap()); - } else { - glBindTexture(GL_TEXTURE_2D_ARRAY, m_WhiteTexture->m_Texture); - } - //} + glActiveTexture(GL_TEXTURE4); + if (m_ShadowPass->DepthMap() != NULL) { + glBindTexture(GL_TEXTURE_2D_ARRAY, m_ShadowPass->DepthMap()); + } + else { + glBindTexture(GL_TEXTURE_2D_ARRAY, m_WhiteTexture->m_Texture); + } } From 8647267cad3dcd549c131229e1a2554410c8ba0c Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Sat, 27 Feb 2016 18:04:33 +0100 Subject: [PATCH 040/130] Make code less dumb, save 7 fps --- include/Engine/Rendering/ShadowPass.h | 38 +++++------ resources/Shaders/ForwardPlus.frag.glsl | 87 +++++++++++++++--------- resources/Shaders/ForwardPlus.vert.glsl | 6 +- src/Engine/Editor/EditorSystem.cpp | 2 +- src/Engine/Rendering/ShadowPass.cpp | 88 +++++++++++-------------- 5 files changed, 113 insertions(+), 108 deletions(-) diff --git a/include/Engine/Rendering/ShadowPass.h b/include/Engine/Rendering/ShadowPass.h index 6fab8a3a..1ff09338 100644 --- a/include/Engine/Rendering/ShadowPass.h +++ b/include/Engine/Rendering/ShadowPass.h @@ -10,10 +10,9 @@ #include "imgui/imgui.h" #define MAX_SPLITS 4 -#define MAP_SIZE 216.f -enum NearFar { Near = 0, Far = 1 }; -enum LRBT { Left = 0, Right = 1, Bottom = 2, Top = 3 }; +enum NearFar { NEAR = 0, FAR = 1 }; +enum LRBT { LEFT = 0, RIGHT = 1, BOTTOM = 2, TOP = 3 }; struct Frustum { @@ -30,8 +29,8 @@ struct Frustum class ShadowPass { public: - ShadowPass(IRenderer* renderer); + ShadowPass(IRenderer * renderer, int ShadowResX, int ShadowResY); ~ShadowPass(); void InitializeFrameBuffers(); @@ -39,45 +38,40 @@ public: void ClearBuffer(); void Draw(RenderScene& scene); - //GLuint DepthMap(int level) const { return m_DepthMap[level]; } GLuint DepthMap() const { return m_DepthMap; } std::array LightP() const { return m_LightProjection; } std::array LightV() const { return m_LightView; } std::array FarDistance() const { return { m_shadowFrusta[0].FarClip, m_shadowFrusta[1].FarClip, m_shadowFrusta[2].FarClip, m_shadowFrusta[3].FarClip }; } int CurrentNrOfSplits() const { return m_CurrentNrOfSplits; } + + void SetSplitWeight(float split_weight) { m_SplitWeight = split_weight; }; private: - void UpdateFrustumPoints(Frustum& frustum, glm::vec3 camera_position, glm::vec3 view_dir, glm::mat4 p, glm::mat4 v); - void UpdateSplitDist(std::array& frusta, float near_distance, float far_distance); void InitializeCameras(RenderScene & scene); - float FindRadius(Frustum& frustum); + void UpdateSplitDist(std::array& frusta, float near_distance, float far_distance); + void UpdateFrustumPoints(Frustum& frustum, glm::vec3 camera_position, glm::vec3 view_dir); + void UpdateFrustumPoints(Frustum& frustum, glm::mat4 p, glm::mat4 v); + void PointsToLightspace(Frustum& frustum, glm::mat4 v); - void RadiusToLightspace(Frustum& frustum, glm::mat4 v); + + float FindRadius(Frustum& frustum); + void RadiusToLightspace(Frustum& frustum); EventBroker* m_EventBroker; const IRenderer* m_Renderer; - //std::array m_DepthMap; - //std::array m_DepthBuffer; GLuint m_DepthMap; FrameBuffer m_DepthBuffer; + ShaderProgram* m_ShadowProgram; std::array m_LightProjection; std::array m_LightView; - ShaderProgram* m_ShadowProgram; - GLuint m_DepthFBO; - GLfloat m_NearFarPlane[2] = { -34.f, 27.f }; - //GLfloat m_LRBT[4] = { -10.f, 10.f, -10.f, 10.f }; - GLuint m_ResolutionSizeWidth = 1024 * 2; - GLuint m_ResolutionSizeHeigth = 1024 * 2; + GLuint m_ResolutionSizeHeight = 1024 * 2; - bool m_ShadowOn = true; - int m_ShadowLevel = 0; - - int m_CurrentNrOfSplits = 3; - float m_SplitWeight = 0.7f; + int m_CurrentNrOfSplits = 4; + float m_SplitWeight = 0.91f; std::array m_shadowFrusta; }; diff --git a/resources/Shaders/ForwardPlus.frag.glsl b/resources/Shaders/ForwardPlus.frag.glsl index b3240911..d29abfdc 100644 --- a/resources/Shaders/ForwardPlus.frag.glsl +++ b/resources/Shaders/ForwardPlus.frag.glsl @@ -1,7 +1,6 @@ #version 430 #define MAX_SPLITS 4 -#define SPLIT_WEIGHT 0.7 uniform mat4 M; uniform mat4 V; @@ -139,6 +138,7 @@ vec4 CalcNormalMappedValue(vec3 normal, vec3 tangent, vec3 bitangent, vec2 textu return vec4(TBN * normalize(NormalMap), 0.0); } +// Returns a "random" value. float Random(vec3 seed, int i) { vec4 seed4 = vec4(seed, i); @@ -162,7 +162,7 @@ float PoissonShadow(sampler2DArrayShadow depth_texture_array, vec3 projection_co for (int i = 0; i < taps; i++) { loop = i; - vec3 newProjCoords = projection_coords + vec3(poissonDisk[loop], 0.0) / (spread * SPLIT_WEIGHT * (1.0 + layer_index)); + vec3 newProjCoords = projection_coords + vec3(poissonDisk[loop], 0.0) / (spread * (1.0 + layer_index)); shadowMapDepth += multiplier * texture(depth_texture_array, vec4(newProjCoords.xy, layer_index, newProjCoords.z)); } @@ -179,7 +179,7 @@ float PoissonDotShadow(sampler2DArrayShadow depth_texture_array, vec3 projection for (int i = 0; i < taps; i++) { loop = int(16.0 * Random(gl_FragCoord.xyy, i)) % 16; - vec3 newProjCoords = projection_coords + vec3(poissonDisk[loop], 0.0) / (spread * SPLIT_WEIGHT * (1.0 + layer_index)); + vec3 newProjCoords = projection_coords + vec3(poissonDisk[loop], 0.0) / (spread * (1.0 + layer_index)); shadowMapDepth += multiplier * texture(depth_texture_array, vec4(newProjCoords.xy, layer_index, newProjCoords.z)); } @@ -196,7 +196,7 @@ float SoftwarePCF(sampler2DArrayShadow depth_texture_array, vec3 projection_coor { for(int y = -1; y <= 1; y++) { - shadow += texture(depth_texture_array, vec4(projection_coords.xy + vec2(x, y) * texelSize.xy, layer_index, projection_coords.z)); + shadow += texture(depth_texture_array, vec4(projection_coords.xy + vec2(x, y) * texelSize.xy / (1.0 + layer_index), layer_index, projection_coords.z)); } } @@ -206,40 +206,56 @@ float SoftwarePCF(sampler2DArrayShadow depth_texture_array, vec3 projection_coor float CalcShadowValue(vec4 light_space_pos, vec3 normal, vec3 light_dir, sampler2DArrayShadow depth_texture_array, int layer_index) { float shadowMapDepth; - float bias; + float bias = 0.005; // Various bias methods. - //bias = 0.005; - //bias = max(0.05 * (1.0 - dot(normal, light_dir)), 0.005); - bias = 0.005 * tan(acos(clamp(dot(normal, -light_dir), 0.0, 1.0))); + bias = max(0.05 * (1.0 - dot(normal, light_dir)), bias); + //bias = bias * tan(acos(clamp(dot(normal, -light_dir), 0.0, 1.0))); + + // Calculate coordinates in projection space. - // Calculate coordinates in projection space vec3 projCoords = vec3(light_space_pos.xy, light_space_pos.z + bias) / light_space_pos.w; projCoords = projCoords * 0.5 + 0.5; // Various methods for shadow calculation in fastest to slowest order. shadowMapDepth = PCFShadow(depth_texture_array, projCoords, layer_index); - //shadowMapDepth = PoissonShadow(depth_texture_array, projCoords, layer_index, 4, 1500.0); - //shadowMapDepth = PoissonDotShadow(depth_texture_array, projCoords, layer_index, 4, 1500.0); + //shadowMapDepth = PoissonShadow(depth_texture_array, projCoords, layer_index, 4, 25.0 * FarDistance[MAX_SPLITS - 1]); + //shadowMapDepth = PoissonDotShadow(depth_texture_array, projCoords, layer_index, 4, 25.0 * FarDistance[MAX_SPLITS]); //shadowMapDepth = SoftwarePCF(depth_texture_array, projCoords, layer_index, bias); - - float shadow = 1.0 - shadowMapDepth; - return shadow; + return 1.0 - shadowMapDepth; } -int getShadowIndex(float far_distance[MAX_SPLITS]) +int getShadowIndex(float far_distance[1]) +{ + return 0; +} + +int getShadowIndex(float far_distance[2]) +{ + float depth = gl_FragCoord.z / gl_FragCoord.w; + + int index = 1; + if ( depth < far_distance[0] ) + { + index = 0; + } + + return index; +} + +int getShadowIndex(float far_distance[3]) { float depth = gl_FragCoord.z / gl_FragCoord.w; int index = 2; - if( depth < far_distance[0] ) + if ( depth < far_distance[0] ) { index = 0; } - else if( depth < far_distance[1] && depth > far_distance[0] ) + else if ( depth < far_distance[1] && depth > far_distance[0] ) { index = 1; } @@ -247,6 +263,27 @@ int getShadowIndex(float far_distance[MAX_SPLITS]) return index; } +int getShadowIndex(float far_distance[4]) +{ + float depth = gl_FragCoord.z / gl_FragCoord.w; + + int index = 3; + if ( depth < far_distance[0] ) + { + index = 0; + } + else if ( depth < far_distance[1] && depth > far_distance[0] ) + { + index = 1; + } + else if ( depth < far_distance[2] && depth > far_distance[1] ) + { + index = 2; + } + + return index; +} + void main() { vec4 diffuseTexel = texture2D(DiffuseTexture, Input.TextureCoordinate); @@ -282,9 +319,7 @@ void main() light_result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, position, normal, light.Falloff); } else if (light.Type == 2) { //Directional int DepthMapIndex = getShadowIndex(FarDistance); - light_result = CalcDirectionalLightSource(V * light.Direction, light.Color, light.Intensity, viewVec, normal); - shadowFactor = CalcShadowValue(Input.PositionLightSpace[DepthMapIndex], Input.Normal, vec3(light.Direction), DepthMap, DepthMapIndex); } @@ -298,19 +333,7 @@ void main() //LightResult getInformation; vec4 color_result = mix((Color * diffuseTexel * DiffuseColor), Input.ExplosionColor, Input.ExplosionPercentageElapsed); - color_result = color_result * (totalLighting.Diffuse + (totalLighting.Specular * specularTexel)); - - //color_result = (totalLighting.Diffuse + (1.0 - shadowFactor) * (getInformation.Diffuse + (getInformation.Specular * specularTexel))) * color_result; - - - - - - - - - //vec4 color_result = (DiffuseColor + Input.ExplosionColor) * (totalLighting.Diffuse + (totalLighting.Specular * specularTexel)) * diffuseTexel * Color; - + color_result = color_result * (totalLighting.Diffuse + (totalLighting.Specular * specularTexel)); float pos = ((P * vec4(Input.Position, 1)).y + 1.0)/2.0; diff --git a/resources/Shaders/ForwardPlus.vert.glsl b/resources/Shaders/ForwardPlus.vert.glsl index 0d9661cc..d77ee20a 100644 --- a/resources/Shaders/ForwardPlus.vert.glsl +++ b/resources/Shaders/ForwardPlus.vert.glsl @@ -47,11 +47,8 @@ void main() + BoneWeights[2] * Bones[int(BoneIndices[2])] + BoneWeights[3] * Bones[int(BoneIndices[3])]; } - - //vec4 lightPos = LightP * LightV * M * vec4(Position, 1.0); // N - + gl_Position = P*V*M*boneTransform * vec4(Position, 1.0); - //gl_Position = lightPos; // N Output.Position = (boneTransform * vec4(Position, 1.0)).xyz; Output.TextureCoordinate = TextureCoords; @@ -61,7 +58,6 @@ void main() Output.ExplosionColor = vec4(1.0); Output.ExplosionPercentageElapsed = 0.0; - //Output.PositionLightSpace = lightPos; // N for(int i = 0; i < MAX_SPLITS; i++) { Output.PositionLightSpace[i] = LightP[i] * LightV[i] * M * vec4(Position, 1.0); diff --git a/src/Engine/Editor/EditorSystem.cpp b/src/Engine/Editor/EditorSystem.cpp index a13bac0b..6128c1f9 100644 --- a/src/Engine/Editor/EditorSystem.cpp +++ b/src/Engine/Editor/EditorSystem.cpp @@ -18,7 +18,7 @@ EditorSystem::EditorSystem(World* world, EventBroker* eventBroker, IRenderer* re m_ActualCamera = m_EditorCamera; m_EditorWorld->AttachComponent(m_EditorCamera.ID, "Transform"); auto cCamera = m_EditorWorld->AttachComponent(m_EditorCamera.ID, "Camera"); - (double&)cCamera["FarClip"] = 60.0; + (double&)cCamera["FarClip"] = 300.0; m_EditorCameraInputController = new EditorCameraInputController(m_EventBroker, -1); diff --git a/src/Engine/Rendering/ShadowPass.cpp b/src/Engine/Rendering/ShadowPass.cpp index dd423f25..33a42e3b 100644 --- a/src/Engine/Rendering/ShadowPass.cpp +++ b/src/Engine/Rendering/ShadowPass.cpp @@ -1,6 +1,16 @@ #include "Rendering/ShadowPass.h" +ShadowPass::ShadowPass(IRenderer * renderer, int shadow_res_x, int shadow_res_y) +{ + m_Renderer = renderer; + m_ResolutionSizeWidth = shadow_res_x; + m_ResolutionSizeHeight = shadow_res_y; + + InitializeFrameBuffers(); + InitializeShaderPrograms(); +} + ShadowPass::ShadowPass(IRenderer * renderer) { m_Renderer = renderer; @@ -41,8 +51,28 @@ void ShadowPass::UpdateSplitDist(std::array& frusta, float frusta[m_CurrentNrOfSplits - 1].FarClip = far_distance; } +void ShadowPass::UpdateFrustumPoints(Frustum& frustum, glm::mat4 p, glm::mat4 v) +{ + std::array CornerPoint = { + glm::vec4(-1.f, -1.f, -1.f, 1.f), + glm::vec4(-1.f, 1.f, -1.f, 1.f), + glm::vec4(1.f, 1.f, -1.f, 1.f), + glm::vec4(1.f, -1.f, -1.f, 1.f), + glm::vec4(-1.f, -1.f, 1.f, 1.f), + glm::vec4(-1.f, 1.f, 1.f, 1.f), + glm::vec4(1.f, 1.f, 1.f, 1.f), + glm::vec4(1.f, -1.f, 1.f, 1.f) + }; + + for (int i = 0; i < 8; i++) { + glm::vec4 NDC = glm::inverse(p) * CornerPoint[i]; + NDC = NDC / NDC.w; + frustum.CornerPoint[i] = glm::vec3(glm::inverse(v) * NDC); + } +} + // Compute the 8 corner points of the current view frustum in world space -void ShadowPass::UpdateFrustumPoints(Frustum& frustum, glm::vec3 camera_position, glm::vec3 view_dir, glm::mat4 p, glm::mat4 v) +void ShadowPass::UpdateFrustumPoints(Frustum& frustum, glm::vec3 camera_position, glm::vec3 view_dir) { glm::vec3 up = glm::vec3(0.f, 1.f, 0.f); glm::vec3 right = glm::normalize(glm::cross(view_dir, up)); @@ -68,25 +98,6 @@ void ShadowPass::UpdateFrustumPoints(Frustum& frustum, glm::vec3 camera_position frustum.CornerPoint[5] = far_center + up * far_height - right * far_width; frustum.CornerPoint[6] = far_center + up * far_height + right * far_width; frustum.CornerPoint[7] = far_center - up * far_height + right * far_width; - - // Alternative way. - //std::array CornerPoint = { - // glm::vec4(-1.f, -1.f, -1.f, 1.f), - // glm::vec4(-1.f, 1.f, -1.f, 1.f), - // glm::vec4(1.f, 1.f, -1.f, 1.f), - // glm::vec4(1.f, -1.f, -1.f, 1.f), - // glm::vec4(-1.f, -1.f, 1.f, 1.f), - // glm::vec4(-1.f, 1.f, 1.f, 1.f), - // glm::vec4(1.f, 1.f, 1.f, 1.f), - // glm::vec4(1.f, -1.f, 1.f, 1.f) }; - - //std::array FinalPoints; - - //for (int i = 0; i < 8; i++) { - // glm::vec4 NDC = glm::inverse(p) * CornerPoint[i]; - // NDC = NDC / NDC.w; - // FinalPoints[i] = glm::vec3(glm::inverse(v) * NDC); - //} } float ShadowPass::FindRadius(Frustum& frustum) @@ -106,18 +117,13 @@ float ShadowPass::FindRadius(Frustum& frustum) void ShadowPass::InitializeFrameBuffers() { - GLERROR("depthMap failed PRE"); // Depth texture glGenTextures(1, &m_DepthMap); - GLERROR("depthMap failed1"); glBindTexture(GL_TEXTURE_2D_ARRAY, m_DepthMap); - GLERROR("depthMap failed2"); - glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_DEPTH_COMPONENT16, m_ResolutionSizeWidth, m_ResolutionSizeHeigth, m_CurrentNrOfSplits); - GLERROR("depthMap failed3"); + glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_DEPTH_COMPONENT16, m_ResolutionSizeWidth, m_ResolutionSizeHeight, m_CurrentNrOfSplits); - glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, m_ResolutionSizeWidth, m_ResolutionSizeHeigth, m_CurrentNrOfSplits, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, nullptr); - GLERROR("depthMap failed4"); + glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, m_ResolutionSizeWidth, m_ResolutionSizeHeight, m_CurrentNrOfSplits, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, nullptr); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR); @@ -126,11 +132,9 @@ void ShadowPass::InitializeFrameBuffers() glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE); glTexParameterfv(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BORDER_COLOR, glm::vec4(1.f).data); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); - GLERROR("depthMap failed5"); m_DepthBuffer.AddResource(std::shared_ptr(new Texture2DArray(&m_DepthMap, GL_DEPTH_ATTACHMENT, m_CurrentNrOfSplits))); m_DepthBuffer.Generate(); - //} GLERROR("depthMap failed END"); } @@ -178,7 +182,7 @@ void ShadowPass::PointsToLightspace(Frustum& frustum, glm::mat4 v) frustum.LRBT = { left, right, bottom, top }; } -void ShadowPass::RadiusToLightspace(Frustum& frustum, glm::mat4 v) +void ShadowPass::RadiusToLightspace(Frustum& frustum) { float left = -frustum.Radius; float right = frustum.Radius; @@ -190,10 +194,7 @@ void ShadowPass::RadiusToLightspace(Frustum& frustum, glm::mat4 v) void ShadowPass::Draw(RenderScene & scene) { -// ImGui::DragFloat4("ShadowMapCam", m_LRBT, 1.f, -1000.f, 1000.f); ImGui::DragFloat2("ShadowMapNearFar", m_NearFarPlane, 1.f, -1000.f, 1000.f); - ImGui::Checkbox("EnableShadow", &m_ShadowOn); - //ImGui::DragInt("ShadowLevel", &m_ShadowLevel, 0.05f, 0, m_CurrentNrOfSplits - 1); InitializeCameras(scene); UpdateSplitDist(m_shadowFrusta, scene.Camera->NearClip(), scene.Camera->FarClip()); @@ -201,19 +202,14 @@ void ShadowPass::Draw(RenderScene & scene) ShadowPassState* state = new ShadowPassState(m_DepthBuffer.GetHandle()); m_ShadowProgram->Bind(); + GLuint shaderHandle = m_ShadowProgram->GetHandle(); + glViewport(0, 0, m_ResolutionSizeWidth, m_ResolutionSizeHeight); for (int i = 0; i < m_CurrentNrOfSplits; i++) { - UpdateFrustumPoints(m_shadowFrusta[i], scene.Camera->Position(), scene.Camera->Forward(), scene.Camera->ProjectionMatrix(), scene.Camera->ViewMatrix()); - //float test = FindRadius(m_shadFrusta[i]); - - GLuint shaderHandle = m_ShadowProgram->GetHandle(); + UpdateFrustumPoints(m_shadowFrusta[i], scene.Camera->Position(), scene.Camera->Forward()); glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_DepthMap, 0, i); - - glViewport(0, 0, m_ResolutionSizeWidth, m_ResolutionSizeHeigth); - //state->Disable(GL_CULL_FACE); - for (auto &job : scene.DirectionalLightJobs) { auto directionalLightJob = std::dynamic_pointer_cast(job); @@ -221,7 +217,7 @@ void ShadowPass::Draw(RenderScene & scene) m_LightView[i] = glm::lookAt(glm::vec3(-directionalLightJob->Direction) + m_shadowFrusta[i].MiddlePoint, m_shadowFrusta[i].MiddlePoint, glm::vec3(0.f, 1.f, 0.f)); PointsToLightspace(m_shadowFrusta[i], m_LightView[i]); - m_LightProjection[i] = glm::ortho(m_shadowFrusta[i].LRBT[Left], m_shadowFrusta[i].LRBT[Right], m_shadowFrusta[i].LRBT[Bottom], m_shadowFrusta[i].LRBT[Top], m_NearFarPlane[Near], m_NearFarPlane[Far]); + m_LightProjection[i] = glm::ortho(m_shadowFrusta[i].LRBT[LEFT], m_shadowFrusta[i].LRBT[RIGHT], m_shadowFrusta[i].LRBT[BOTTOM], m_shadowFrusta[i].LRBT[TOP], m_NearFarPlane[NEAR], m_NearFarPlane[FAR]); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_LightProjection[i])); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_LightView[i])); @@ -240,14 +236,10 @@ void ShadowPass::Draw(RenderScene & scene) GLERROR("Shadow Draw ERROR"); } } - } - - glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height); - - m_ShadowProgram->Unbind(); - } + m_ShadowProgram->Unbind(); + glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height); m_DepthBuffer.Unbind(); delete state; } From 14b0a64720cead73c7c3ed124cd126f6f6ef8a32 Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Sat, 27 Feb 2016 18:42:51 +0100 Subject: [PATCH 041/130] begin fixing transparent object's shadows --- include/Engine/Rendering/ShadowPass.h | 24 +++++----- .../Schema/Entities/QualityAssurance.xml | 2 +- resources/Shaders/ForwardPlus.frag.glsl | 4 +- src/Engine/Rendering/DrawFinalPass.cpp | 13 +++--- src/Engine/Rendering/Renderer.cpp | 3 -- src/Engine/Rendering/ShadowPass.cpp | 44 ++++++++++++------- src/Engine/Rendering/ShadowPassState.cpp | 5 +-- 7 files changed, 51 insertions(+), 44 deletions(-) diff --git a/include/Engine/Rendering/ShadowPass.h b/include/Engine/Rendering/ShadowPass.h index 1ff09338..a26ddf97 100644 --- a/include/Engine/Rendering/ShadowPass.h +++ b/include/Engine/Rendering/ShadowPass.h @@ -29,19 +29,19 @@ struct Frustum class ShadowPass { public: - ShadowPass(IRenderer* renderer); + ShadowPass(IRenderer* renderer); ShadowPass(IRenderer * renderer, int ShadowResX, int ShadowResY); - ~ShadowPass(); - - void InitializeFrameBuffers(); - void InitializeShaderPrograms(); - void ClearBuffer(); - void Draw(RenderScene& scene); + ~ShadowPass(); + + void InitializeFrameBuffers(); + void InitializeShaderPrograms(); + void ClearBuffer(); + void Draw(RenderScene& scene); GLuint DepthMap() const { return m_DepthMap; } std::array LightP() const { return m_LightProjection; } std::array LightV() const { return m_LightView; } - std::array FarDistance() const { return { m_shadowFrusta[0].FarClip, m_shadowFrusta[1].FarClip, m_shadowFrusta[2].FarClip, m_shadowFrusta[3].FarClip }; } + std::array FarDistance() const { return{ m_shadowFrusta[0].FarClip, m_shadowFrusta[1].FarClip, m_shadowFrusta[2].FarClip, m_shadowFrusta[3].FarClip }; } int CurrentNrOfSplits() const { return m_CurrentNrOfSplits; } void SetSplitWeight(float split_weight) { m_SplitWeight = split_weight; }; @@ -55,7 +55,7 @@ private: float FindRadius(Frustum& frustum); void RadiusToLightspace(Frustum& frustum); - + EventBroker* m_EventBroker; const IRenderer* m_Renderer; @@ -66,9 +66,9 @@ private: std::array m_LightProjection; std::array m_LightView; - GLfloat m_NearFarPlane[2] = { -34.f, 27.f }; - GLuint m_ResolutionSizeWidth = 1024 * 2; - GLuint m_ResolutionSizeHeight = 1024 * 2; + GLfloat m_NearFarPlane[2] = { -34.f, 27.f }; + GLuint m_ResolutionSizeWidth = 1024 * 2; + GLuint m_ResolutionSizeHeight = 1024 * 2; int m_CurrentNrOfSplits = 4; float m_SplitWeight = 0.91f; diff --git a/resources/Schema/Entities/QualityAssurance.xml b/resources/Schema/Entities/QualityAssurance.xml index e057cf38..04dfc6aa 100644 --- a/resources/Schema/Entities/QualityAssurance.xml +++ b/resources/Schema/Entities/QualityAssurance.xml @@ -569,7 +569,7 @@ Models/Core/UnitCube.mesh - + true diff --git a/resources/Shaders/ForwardPlus.frag.glsl b/resources/Shaders/ForwardPlus.frag.glsl index d29abfdc..8250d96d 100644 --- a/resources/Shaders/ForwardPlus.frag.glsl +++ b/resources/Shaders/ForwardPlus.frag.glsl @@ -210,8 +210,8 @@ float CalcShadowValue(vec4 light_space_pos, vec3 normal, vec3 light_dir, sampler // Various bias methods. - bias = max(0.05 * (1.0 - dot(normal, light_dir)), bias); - //bias = bias * tan(acos(clamp(dot(normal, -light_dir), 0.0, 1.0))); + //bias = max(0.05 * (1.0 - dot(normal, light_dir)), bias); + bias = bias * tan(acos(clamp(dot(normal, -light_dir), 0.0, 1.0))); // Calculate coordinates in projection space. diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index 98a56f6b..a1139902 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -226,6 +226,12 @@ void DrawFinalPass::BindExplosionUniforms(GLuint shaderHandle, std::shared_ptrFillColor)); glUniform1f(glGetUniformLocation(shaderHandle, "FillPercentage"), job->FillPercentage); glUniform4fv(glGetUniformLocation(shaderHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor)); + + //Shadow + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "LightP"), MAX_SPLITS, GL_FALSE, glm::value_ptr(*m_ShadowPass->LightP().data())); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "LightV"), MAX_SPLITS, GL_FALSE, glm::value_ptr(*m_ShadowPass->LightV().data())); + glUniform1fv(glGetUniformLocation(shaderHandle, "FarDistance"), MAX_SPLITS, m_ShadowPass->FarDistance().data()); + GLERROR("END"); } @@ -248,13 +254,6 @@ void DrawFinalPass::BindModelUniforms(GLuint shaderHandle, std::shared_ptrLightV().data())); glUniform1fv(glGetUniformLocation(shaderHandle, "FarDistance"), MAX_SPLITS, m_ShadowPass->FarDistance().data()); - - //GLfloat m_NearFarPlane[2] = { -40.f, 30.f }; - //GLfloat m_LRBT[4] = { -40.f, 100.f, -50.f, 50.f }; - //glm::mat4 m_LightProjection = glm::ortho(m_LRBT[Left], m_LRBT[Right], m_LRBT[Bottom], m_LRBT[Top], m_NearFarPlane[Near], m_NearFarPlane[Far]); - //glm::mat4 m_LightView = glm::lookAt(glm::vec3(-20.0f, 20.0f, -20.0f), glm::vec3(0.0f), glm::vec3(1.0)); - //glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "LightP"), 1, GL_FALSE, glm::value_ptr(m_LightProjection)); - //glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "LightV"), 1, GL_FALSE, glm::value_ptr(m_LightView)); GLERROR("END"); } diff --git a/src/Engine/Rendering/Renderer.cpp b/src/Engine/Rendering/Renderer.cpp index a26a7f09..cc6ab11b 100644 --- a/src/Engine/Rendering/Renderer.cpp +++ b/src/Engine/Rendering/Renderer.cpp @@ -136,9 +136,6 @@ void Renderer::Draw(RenderFrame& frame) if (m_DebugTextureToDraw == 4) { m_DrawScreenQuadPass->Draw(m_PickingPass->PickingTexture()); } - if (m_DebugTextureToDraw == 5) { - m_DrawScreenQuadPass->Draw(m_ShadowPass->DepthMap()); - } m_ImGuiRenderPass->Draw(); glfwSwapBuffers(m_Window); diff --git a/src/Engine/Rendering/ShadowPass.cpp b/src/Engine/Rendering/ShadowPass.cpp index 33a42e3b..be09626d 100644 --- a/src/Engine/Rendering/ShadowPass.cpp +++ b/src/Engine/Rendering/ShadowPass.cpp @@ -53,7 +53,7 @@ void ShadowPass::UpdateSplitDist(std::array& frusta, float void ShadowPass::UpdateFrustumPoints(Frustum& frustum, glm::mat4 p, glm::mat4 v) { - std::array CornerPoint = { + std::array CornerPoint = { glm::vec4(-1.f, -1.f, -1.f, 1.f), glm::vec4(-1.f, 1.f, -1.f, 1.f), glm::vec4(1.f, 1.f, -1.f, 1.f), @@ -81,7 +81,7 @@ void ShadowPass::UpdateFrustumPoints(Frustum& frustum, glm::vec3 camera_position glm::vec3 near_center = camera_position + glm::normalize(view_dir) * frustum.NearClip; frustum.MiddlePoint = near_center + (far_center - near_center) * 0.5f; - up = glm::normalize(glm::cross(right, view_dir)); + up = glm::normalize(glm::cross(right, view_dir)); // these heights and widths are half the heights and widths of the near and far plane rectangles. float near_height = tan(frustum.FOV / 2.f) * frustum.NearClip; @@ -118,7 +118,7 @@ float ShadowPass::FindRadius(Frustum& frustum) void ShadowPass::InitializeFrameBuffers() { // Depth texture - glGenTextures(1, &m_DepthMap); + glGenTextures(1, &m_DepthMap); glBindTexture(GL_TEXTURE_2D_ARRAY, m_DepthMap); glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_DEPTH_COMPONENT16, m_ResolutionSizeWidth, m_ResolutionSizeHeight, m_CurrentNrOfSplits); @@ -136,17 +136,17 @@ void ShadowPass::InitializeFrameBuffers() m_DepthBuffer.AddResource(std::shared_ptr(new Texture2DArray(&m_DepthMap, GL_DEPTH_ATTACHMENT, m_CurrentNrOfSplits))); m_DepthBuffer.Generate(); - GLERROR("depthMap failed END"); + GLERROR("depthMap failed END"); } void ShadowPass::InitializeShaderPrograms() { - m_ShadowProgram = ResourceManager::Load("#ShadowProgram"); - m_ShadowProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/Shadow.vert.glsl"))); - m_ShadowProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/Shadow.frag.glsl"))); - m_ShadowProgram->Compile(); - m_ShadowProgram->BindFragDataLocation(0, "ShadowMap"); - m_ShadowProgram->Link(); + m_ShadowProgram = ResourceManager::Load("#ShadowProgram"); + m_ShadowProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/Shadow.vert.glsl"))); + m_ShadowProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/Shadow.frag.glsl"))); + m_ShadowProgram->Compile(); + m_ShadowProgram->BindFragDataLocation(0, "ShadowMap"); + m_ShadowProgram->Link(); } void ShadowPass::ClearBuffer() @@ -155,7 +155,7 @@ void ShadowPass::ClearBuffer() for (int i = 0; i < m_CurrentNrOfSplits; i++) { glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_DepthMap, 0, i); - + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } @@ -187,7 +187,7 @@ void ShadowPass::RadiusToLightspace(Frustum& frustum) float left = -frustum.Radius; float right = frustum.Radius; float bottom = -frustum.Radius; - float top =frustum.Radius; + float top = frustum.Radius; frustum.LRBT = { left, right, bottom, top }; } @@ -198,7 +198,7 @@ void ShadowPass::Draw(RenderScene & scene) InitializeCameras(scene); UpdateSplitDist(m_shadowFrusta, scene.Camera->NearClip(), scene.Camera->FarClip()); - + ShadowPassState* state = new ShadowPassState(m_DepthBuffer.GetHandle()); m_ShadowProgram->Bind(); @@ -207,9 +207,9 @@ void ShadowPass::Draw(RenderScene & scene) for (int i = 0; i < m_CurrentNrOfSplits; i++) { UpdateFrustumPoints(m_shadowFrusta[i], scene.Camera->Position(), scene.Camera->Forward()); - + glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_DepthMap, 0, i); - + for (auto &job : scene.DirectionalLightJobs) { auto directionalLightJob = std::dynamic_pointer_cast(job); @@ -235,6 +235,20 @@ void ShadowPass::Draw(RenderScene & scene) GLERROR("Shadow Draw ERROR"); } + + state->CullFace(GL_BACK); + for (auto &objectJob : scene.TransparentObjects) { + auto modelJob = std::dynamic_pointer_cast(objectJob); + + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); + + glBindVertexArray(modelJob->Model->VAO); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); + glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int))); + + GLERROR("Shadow Draw ERROR"); + } + state->CullFace(GL_FRONT); } } } diff --git a/src/Engine/Rendering/ShadowPassState.cpp b/src/Engine/Rendering/ShadowPassState.cpp index f84b6436..67e0dd1f 100644 --- a/src/Engine/Rendering/ShadowPassState.cpp +++ b/src/Engine/Rendering/ShadowPassState.cpp @@ -2,16 +2,13 @@ ShadowPassState::ShadowPassState(GLuint frameBuffer) { - GLERROR("---2"); BindFramebuffer(frameBuffer); - GLERROR("---3"); Enable(GL_DEPTH_TEST); Enable(GL_CULL_FACE); Disable(GL_BLEND); Disable(GL_TEXTURE_2D); CullFace(GL_FRONT); - ClearColor(glm::vec4(255.f, 128.f, 128.f, 128.f)); - GLERROR("---4"); + ClearColor(glm::vec4(0.f, 0.f, 0.f, 0.f)); } ShadowPassState::~ShadowPassState() From 144e548b7a660ff1e58d2f881692efbc3fe6b91f Mon Sep 17 00:00:00 2001 From: Tleety Date: Sun, 28 Feb 2016 17:17:24 +0100 Subject: [PATCH 042/130] Added AbilityCooldownHUD component and system to track the cooldown on the dashability, this needs to be extended for other abilities when they are implemented. However current dash time needs to be included into the component, since we can currently just see the max cooldown time. --- .../Game/Systems/AbilityCooldownHUDSystem.h | 17 + resources/Schema/Components.xsd | 1 + .../Schema/Components/AbilityCooldownHUD.xml | 3 + .../Schema/Components/AbilityCooldownHUD.xsd | 9 + resources/Schema/Entities/PlayerRed.xml | 91 ++- .../Schema/Entities/QualityAssurance.xml | 730 +++++++++++++++++- resources/Schema/Types/Entity.xsd | 1 + src/Game/Game.cpp | 2 + src/Game/Systems/AbilityCooldownHUDSystem.cpp | 28 + 9 files changed, 835 insertions(+), 47 deletions(-) create mode 100644 include/Game/Systems/AbilityCooldownHUDSystem.h create mode 100644 resources/Schema/Components/AbilityCooldownHUD.xml create mode 100644 resources/Schema/Components/AbilityCooldownHUD.xsd create mode 100644 src/Game/Systems/AbilityCooldownHUDSystem.cpp diff --git a/include/Game/Systems/AbilityCooldownHUDSystem.h b/include/Game/Systems/AbilityCooldownHUDSystem.h new file mode 100644 index 00000000..610b4dc2 --- /dev/null +++ b/include/Game/Systems/AbilityCooldownHUDSystem.h @@ -0,0 +1,17 @@ +#ifndef AbilityCooldownHUDSystem_h__ +#define AbilityCooldownHUDSystem_h__ + +#include "../../Engine/Core/System.h" +#include "../../Engine/GLM.h" + +class AbilityCooldownHUDSystem : public ImpureSystem +{ +public: + AbilityCooldownHUDSystem(SystemParams params) + : System(params) + { } + + virtual void Update(double dt) override; +}; + +#endif \ No newline at end of file diff --git a/resources/Schema/Components.xsd b/resources/Schema/Components.xsd index 42abed82..b90a445d 100644 --- a/resources/Schema/Components.xsd +++ b/resources/Schema/Components.xsd @@ -46,4 +46,5 @@ + \ No newline at end of file diff --git a/resources/Schema/Components/AbilityCooldownHUD.xml b/resources/Schema/Components/AbilityCooldownHUD.xml new file mode 100644 index 00000000..8f91bbc3 --- /dev/null +++ b/resources/Schema/Components/AbilityCooldownHUD.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/resources/Schema/Components/AbilityCooldownHUD.xsd b/resources/Schema/Components/AbilityCooldownHUD.xsd new file mode 100644 index 00000000..066a9442 --- /dev/null +++ b/resources/Schema/Components/AbilityCooldownHUD.xsd @@ -0,0 +1,9 @@ + + + + + + HUD element for tracking ability cooldown + + + \ No newline at end of file diff --git a/resources/Schema/Entities/PlayerRed.xml b/resources/Schema/Entities/PlayerRed.xml index d56fa3c1..1e419b4d 100644 --- a/resources/Schema/Entities/PlayerRed.xml +++ b/resources/Schema/Entities/PlayerRed.xml @@ -23,7 +23,9 @@ - + + + @@ -111,6 +113,7 @@ Textures/HealthHUD3.png + false @@ -121,7 +124,55 @@ - + + + + + + 1 + + + + Textures/Core/White.png + false + + + + + + + + + + + + + + 2.0 + Fonts/DroidSans.ttf,64 + + + + + + + + + + + + + Textures/Props/FoliageDiff.png + false + + + + + + + + + @@ -137,6 +188,7 @@ Textures/Core/UnitHexagon.png + false @@ -155,6 +207,7 @@ Textures/Core/UnitHexagon_Rotated.png + false @@ -171,6 +224,7 @@ Textures/Core/UnitHexagon.png + false @@ -185,11 +239,11 @@ 3 - 0.80222018197612788 Textures/Core/UnitHexagon_Rotated.png + false @@ -206,6 +260,7 @@ Textures/Core/UnitHexagon.png + false @@ -220,10 +275,12 @@ 4 + 1 Textures/Core/UnitHexagon_Rotated.png + false @@ -240,6 +297,7 @@ Textures/Core/UnitHexagon.png + false @@ -258,6 +316,7 @@ Textures/Core/UnitHexagon_Rotated.png + false @@ -274,8 +333,9 @@ Textures/Core/UnitHexagon.png + false - + @@ -286,16 +346,18 @@ - + 1 + Textures/Core/UnitHexagon_Rotated.png + false - + @@ -364,7 +426,7 @@ Idle - 1.2667383999985162 + 1.2417589624457968 1 @@ -385,8 +447,8 @@ Models/Weapons/Red/AssaultWeaponRed.mesh - - + + @@ -492,10 +554,13 @@ - Idle - 0.26532318661337229 + Run + 0.012377234178668317 1 + 1 + 0.5 + 1.8342275085993549 @@ -519,8 +584,8 @@ Models/Weapons/Red/AssaultWeaponRed.mesh - - + + diff --git a/resources/Schema/Entities/QualityAssurance.xml b/resources/Schema/Entities/QualityAssurance.xml index 0aa2fbe7..3f880c91 100644 --- a/resources/Schema/Entities/QualityAssurance.xml +++ b/resources/Schema/Entities/QualityAssurance.xml @@ -40,7 +40,7 @@ - + @@ -93,7 +93,7 @@ - + @@ -108,7 +108,11 @@ - + + + + + Models/Characters/Assault/AssaultAnimated.mesh @@ -120,7 +124,11 @@ - + + + + + Models/Characters/Assault/AssaultAnimated.mesh @@ -168,21 +176,643 @@ - + - + - - - Models/Characters/Assault/AssaultAnimated.mesh - + + + + + + 600 + + + + + + + + + 5 + + + + + + - + + + + + + + + + + + + + Models/Widgets/Camera.mesh + false + + + + + + + + + + + + + + + + + + + Textures/Weapons/Crosshair/SmallThickHoleDot.png + false + + + + + + + + + + + + + Schema/Entities/HitMarker.xml + + + + + + + + + + + + + + 1 + + + + + 100/100 + Fonts/DroidSans.ttf,64 + + + + + + + + + + + + + + 1 + + + + Textures/HealthHUD3.png + + + + + + + + + + + + + + + Textures/Test/SmallDiff.png + false + + + + + + + + + + + + + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + 2 + + + + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + 3 + + + + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + 4 + + + 1 + + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + 1 + + + + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + + 1 + + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + + + + + + + + + + + + + + + Fonts/DroidSans.ttf,64 + + + + + + + + + + + + + Fonts/DroidSans.ttf,64 + + + + + + + + + + + + + + + Fonts/DroidSans.ttf,64 + + + + + + + + + + + + + + + + + + Idle + 1.0970008697500191 + 1 + + + + + Models/Characters/Assault/FirstPerson.mesh + + + + + + + + + R_Arm_Weapon_Joint + + + Models/Weapons/Red/AssaultWeaponRed.mesh + + + + + + + + + + + Schema/Entities/RayRed.xml + + + + + + + + + + + Schema/Entities/ReloadEffectViewRed.xml + + + + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + + + + + + + + 32 + Fonts/DroidSans.ttf,64 + + + + + + + + + + + + 360 + Fonts/DroidSans.ttf,64 + + + + + + + + + + + + + + + + + + + + + + + + Models/Widgets/Camera.mesh + false + + + + + + + + + + + + Run + 0.86761914148289065 + 1 + 1 + + 0.5 + 1.8342275085993549 + + + + AimRifle + + + + + Models/Characters/Assault/AssaultAnimations.mesh + + + + + + + + + R_Arm_Weapon_Joint + + + Models/Weapons/Red/AssaultWeaponRed.mesh + + + + + + + + + + + Schema/Entities/RayRed.xml + + + + + + + + + + + Schema/Entities/ReloadEffectWorldRed.xml + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + false + + + + + + + + + + + + Models/Core/UnitCube.mesh + + false + + + + + + + + + + + Insert name here + Fonts/DroidSans.ttf,100 + + + + + + + + + + + + + + Textures/Icons/Arrow.png + false + + + + + + 50 + true + + + + + + + + + @@ -213,7 +843,7 @@ - + @@ -277,7 +907,7 @@ - + @@ -309,7 +939,7 @@ - + @@ -659,7 +1289,7 @@ - + @@ -706,7 +1336,7 @@ - + @@ -766,7 +1396,7 @@ - + @@ -813,7 +1443,7 @@ - + @@ -859,7 +1489,7 @@ - + @@ -906,7 +1536,7 @@ - + @@ -953,7 +1583,7 @@ - + @@ -1367,7 +1997,7 @@ - + @@ -1376,7 +2006,7 @@ true - 0.8256214817261025 + 2.8360836966480178 3.7999999523162842 true @@ -1423,7 +2053,7 @@ - + @@ -1432,7 +2062,7 @@ - 1.8641349174045843 + 1.47485045667446 Models/Characters/Assault/AssaultTPose.mesh @@ -1475,18 +2105,22 @@ - + - + + + + + true - 1.8641349174045843 + 1.47485045667446 true @@ -1531,7 +2165,7 @@ - + @@ -1541,7 +2175,7 @@ true - 1.2301962937648341 + 8.7351898541697892 10 3 @@ -1589,7 +2223,7 @@ - + @@ -1599,7 +2233,7 @@ true - 3.4214855659573402 + 4.5370673150397351 true 5 true @@ -1712,6 +2346,7 @@ + Fonts/DroidSans.ttf,100 @@ -1780,7 +2415,7 @@ true - 0.8256214817261025 + 2.8360836966480178 3.7999999523162842 true @@ -1823,7 +2458,11 @@ - + + + + + @@ -1925,6 +2564,7 @@ Textures/Props/FoliageDiff.png + @@ -1934,6 +2574,7 @@ Textures/Props/FoliageDiff.png + @@ -1954,6 +2595,7 @@ Textures/Core/UnitHexagon.png + @@ -1971,6 +2613,7 @@ Textures/Core/UnitHexagon_Rotated.png + @@ -1986,6 +2629,7 @@ Textures/Core/UnitHexagon.png + @@ -2003,6 +2647,7 @@ Textures/Core/UnitHexagon_Rotated.png + @@ -2018,6 +2663,7 @@ Textures/Core/UnitHexagon.png + @@ -2036,6 +2682,7 @@ Textures/Core/UnitHexagon_Rotated.png + @@ -2051,6 +2698,7 @@ Textures/Core/UnitHexagon.png + @@ -2068,6 +2716,7 @@ Textures/Core/UnitHexagon_Rotated.png + @@ -2083,6 +2732,7 @@ Textures/Core/UnitHexagon.png + @@ -2099,6 +2749,7 @@ Textures/Core/UnitHexagon_Rotated.png + @@ -2167,6 +2818,7 @@ Textures/Core/ErrorTexture.png + @@ -2178,6 +2830,7 @@ Textures/Core/White.png + @@ -2206,6 +2859,7 @@ Textures/Core/White.png + @@ -2234,6 +2888,7 @@ Textures/Core/White.png + @@ -2262,6 +2917,7 @@ Textures/Core/White.png + @@ -2290,6 +2946,7 @@ Textures/Core/White.png + @@ -2331,6 +2988,7 @@ Textures/Core/ErrorTexture.png + @@ -2342,6 +3000,7 @@ Textures/Core/White.png + @@ -2370,6 +3029,7 @@ Textures/Core/White.png + @@ -2398,6 +3058,7 @@ Textures/Core/White.png + @@ -2426,6 +3087,7 @@ Textures/Core/White.png + diff --git a/resources/Schema/Types/Entity.xsd b/resources/Schema/Types/Entity.xsd index a9c5f641..d2887e95 100644 --- a/resources/Schema/Types/Entity.xsd +++ b/resources/Schema/Types/Entity.xsd @@ -50,6 +50,7 @@ + diff --git a/src/Game/Game.cpp b/src/Game/Game.cpp index 24b7cd1e..f98bcb4c 100644 --- a/src/Game/Game.cpp +++ b/src/Game/Game.cpp @@ -25,6 +25,7 @@ #include "Rendering/AnimationSystem.h" #include "Network/MultiplayerSnapshotFilter.h" #include "Game/Systems/AmmunitionHUDSystem.h" +#include "Game/Systems/AbilityCooldownHUDSystem.h" #include "Game/Systems/KillFeedSystem.h" #include "GUI/ButtonSystem.h" #include "GUI/MainMenuSystem.h" @@ -128,6 +129,7 @@ Game::Game(int argc, char* argv[]) m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); + m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel, m_Renderer); m_SystemPipeline->AddSystem(updateOrderLevel, m_Renderer); diff --git a/src/Game/Systems/AbilityCooldownHUDSystem.cpp b/src/Game/Systems/AbilityCooldownHUDSystem.cpp new file mode 100644 index 00000000..12d268c7 --- /dev/null +++ b/src/Game/Systems/AbilityCooldownHUDSystem.cpp @@ -0,0 +1,28 @@ +#include "Game/Systems/AbilityCooldownHUDSystem.h" + +void AbilityCooldownHUDSystem::Update(double dt) +{ + //HUD element for tracking cooldown on the parent entity with Dashability TODO: Make sure it support other abilities when they are made. + + auto abilityHUDs = m_World->GetComponents("AbilityCooldownHUD"); + if (abilityHUDs == nullptr) + return; + + for (auto& abilityHUDC : *abilityHUDs) { + EntityWrapper entity = EntityWrapper(m_World, abilityHUDC.EntityID); + EntityWrapper abilityEntity = entity.FirstParentWithComponent("DashAbility"); + if (!abilityEntity.Valid()) + return; + EntityWrapper cooldownTextEntity = entity.FirstChildByName("Cooldown"); + if(cooldownTextEntity.Valid()) { + if(cooldownTextEntity.HasComponent("Text")) + { + double abilityCD = (double)abilityEntity["DashAbility"]["CoolDownMaxTimer"]; + std::string t = (std::string&)cooldownTextEntity["Text"]["Content"] = std::to_string(abilityCD).substr(0, 3); + if(entity.HasComponent("Fill")) { + entity["Fill"]["Percentage"] = abilityCD/abilityCD; //TODO: current time needs to be in the component. + } + } + } + } +} From 6dd7f1a657147ad8b8134ab6cd48b0f846949b3b Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Sun, 28 Feb 2016 18:00:23 +0100 Subject: [PATCH 043/130] Buggy transparent shadows. Transparent textures might glow. --- include/Engine/Rendering/ShadowPass.h | 3 +++ resources/Schema/Entities/QualityAssurance.xml | 4 ++-- resources/Shaders/ForwardPlus.frag.glsl | 4 ++-- resources/Shaders/Shadow.frag.glsl | 16 +++++++++++++++- resources/Shaders/Shadow.vert.glsl | 8 +++++++- src/Engine/Rendering/Renderer.cpp | 10 +--------- src/Engine/Rendering/ShadowPass.cpp | 11 +++++++++++ src/Engine/Rendering/ShadowPassState.cpp | 2 ++ 8 files changed, 43 insertions(+), 15 deletions(-) diff --git a/include/Engine/Rendering/ShadowPass.h b/include/Engine/Rendering/ShadowPass.h index a26ddf97..c4007cce 100644 --- a/include/Engine/Rendering/ShadowPass.h +++ b/include/Engine/Rendering/ShadowPass.h @@ -62,6 +62,7 @@ private: GLuint m_DepthMap; FrameBuffer m_DepthBuffer; ShaderProgram* m_ShadowProgram; + //ShaderProgram* m_TransparentShadowProgram; std::array m_LightProjection; std::array m_LightView; @@ -74,6 +75,8 @@ private: float m_SplitWeight = 0.91f; std::array m_shadowFrusta; + + Texture* m_WhiteTexture = ResourceManager::Load("Textures/Core/White.png"); }; #endif \ No newline at end of file diff --git a/resources/Schema/Entities/QualityAssurance.xml b/resources/Schema/Entities/QualityAssurance.xml index 04dfc6aa..86281abd 100644 --- a/resources/Schema/Entities/QualityAssurance.xml +++ b/resources/Schema/Entities/QualityAssurance.xml @@ -568,8 +568,8 @@ - Models/Core/UnitCube.mesh - + Models/BushAlive.mesh + true diff --git a/resources/Shaders/ForwardPlus.frag.glsl b/resources/Shaders/ForwardPlus.frag.glsl index 8250d96d..c3e1a681 100644 --- a/resources/Shaders/ForwardPlus.frag.glsl +++ b/resources/Shaders/ForwardPlus.frag.glsl @@ -327,8 +327,8 @@ void main() totalLighting.Specular += light_result.Specular; } - totalLighting.Diffuse *= (1.5 + vec4(AmbientColor.rgb, 1.0)) - vec4(vec3(shadowFactor), 0.0); - totalLighting.Specular *= (1.5 + vec4(AmbientColor.rgb, 1.0)) - vec4(vec3(shadowFactor), 0.0); + totalLighting.Diffuse *= (1.0 + vec4(AmbientColor.rgba)) - vec4(vec3(shadowFactor), 0.0); + totalLighting.Specular *= (1.0 + vec4(AmbientColor.rgba)) - vec4(vec3(shadowFactor), 0.0); //LightResult getInformation; diff --git a/resources/Shaders/Shadow.frag.glsl b/resources/Shaders/Shadow.frag.glsl index 58290b59..3287df7c 100644 --- a/resources/Shaders/Shadow.frag.glsl +++ b/resources/Shaders/Shadow.frag.glsl @@ -1,10 +1,24 @@ #version 430 -layout(location = 0 ) out float ShadowMap; +#define ALPHA_CUTOFF 0.3 + +layout (binding = 12) uniform sampler2D DiffuseTexture; +uniform float Alpha; + +in VertexData{ + vec2 TextureCoordinate; +}Input; + +layout (location = 0) out float ShadowMap; void main() { + vec4 diffuseTexel = texture(DiffuseTexture, Input.TextureCoordinate) * Alpha; + if (diffuseTexel.a < ALPHA_CUTOFF) + { + discard; + } } diff --git a/resources/Shaders/Shadow.vert.glsl b/resources/Shaders/Shadow.vert.glsl index 8a0dc8f4..7b1b26fb 100644 --- a/resources/Shaders/Shadow.vert.glsl +++ b/resources/Shaders/Shadow.vert.glsl @@ -4,9 +4,15 @@ uniform mat4 M; uniform mat4 V; uniform mat4 P; -layout(location = 0) in vec3 Position; +layout (location = 0) in vec3 Position; +layout (location = 4) in vec2 TextureCoords; + +out VertexData{ + vec2 TextureCoordinate; +}Output; void main() { gl_Position = P * V * M * vec4(Position, 1.0); + Output.TextureCoordinate = TextureCoords; } \ No newline at end of file diff --git a/src/Engine/Rendering/Renderer.cpp b/src/Engine/Rendering/Renderer.cpp index cc6ab11b..cdbd5786 100644 --- a/src/Engine/Rendering/Renderer.cpp +++ b/src/Engine/Rendering/Renderer.cpp @@ -68,14 +68,6 @@ void Renderer::InitializeShaders() { m_BasicForwardProgram = ResourceManager::Load("#m_BasicForwardProgram"); m_ExplosionEffectProgram = ResourceManager::Load("#ExplosionEffectProgram"); - //m_ExplosionEffectProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/ExplosionEffect.vert.glsl"))); - //m_ExplosionEffectProgram->AddShader(std::shared_ptr(new GeometryShader("Shaders/ExplosionEffect.geom.glsl"))); - //m_ExplosionEffectProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/ExplosionEffect.frag.glsl"))); - //m_ExplosionEffectProgram->Compile(); - //m_ExplosionEffectProgram->Link(); - - - } void Renderer::InputUpdate(double dt) @@ -93,7 +85,7 @@ void Renderer::Update(double dt) void Renderer::Draw(RenderFrame& frame) { - ImGui::Combo("Draw textures", &m_DebugTextureToDraw, "Final\0Scene\0Bloom\0Gaussian\0Picking\0Shadow"); + ImGui::Combo("Draw textures", &m_DebugTextureToDraw, "Final\0Scene\0Bloom\0Gaussian\0Picking"); //clear buffer 0 glClearColor(0.f, 0.f, 0.f, 0.f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); diff --git a/src/Engine/Rendering/ShadowPass.cpp b/src/Engine/Rendering/ShadowPass.cpp index be09626d..c0ee1e54 100644 --- a/src/Engine/Rendering/ShadowPass.cpp +++ b/src/Engine/Rendering/ShadowPass.cpp @@ -147,6 +147,8 @@ void ShadowPass::InitializeShaderPrograms() m_ShadowProgram->Compile(); m_ShadowProgram->BindFragDataLocation(0, "ShadowMap"); m_ShadowProgram->Link(); + + } void ShadowPass::ClearBuffer() @@ -241,6 +243,15 @@ void ShadowPass::Draw(RenderScene & scene) auto modelJob = std::dynamic_pointer_cast(objectJob); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); + glUniform1f(glGetUniformLocation(shaderHandle, "Alpha"), modelJob->Color.a); + + glActiveTexture(GL_TEXTURE12); + if (modelJob->DiffuseTexture != nullptr) { + glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture->m_Texture); + } + else { + glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture); + } glBindVertexArray(modelJob->Model->VAO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); diff --git a/src/Engine/Rendering/ShadowPassState.cpp b/src/Engine/Rendering/ShadowPassState.cpp index 67e0dd1f..ef789487 100644 --- a/src/Engine/Rendering/ShadowPassState.cpp +++ b/src/Engine/Rendering/ShadowPassState.cpp @@ -9,6 +9,8 @@ ShadowPassState::ShadowPassState(GLuint frameBuffer) Disable(GL_TEXTURE_2D); CullFace(GL_FRONT); ClearColor(glm::vec4(0.f, 0.f, 0.f, 0.f)); + //Enable(GL_ALPHA_TEST); + //glAlphaFunc(GL_GREATER, 0.9f); } ShadowPassState::~ShadowPassState() From 7749fc5474d893c20ab5c09782cd3f4bb8b42910 Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Sun, 28 Feb 2016 19:46:50 +0100 Subject: [PATCH 044/130] Small fixing up --- resources/Shaders/ForwardPlus.frag.glsl | 14 ++++--- resources/Shaders/Shadow.frag.glsl | 2 +- src/Engine/Rendering/ShadowPass.cpp | 54 +++++++++++++++---------- 3 files changed, 41 insertions(+), 29 deletions(-) diff --git a/resources/Shaders/ForwardPlus.frag.glsl b/resources/Shaders/ForwardPlus.frag.glsl index c3e1a681..3b94df9e 100644 --- a/resources/Shaders/ForwardPlus.frag.glsl +++ b/resources/Shaders/ForwardPlus.frag.glsl @@ -211,19 +211,21 @@ float CalcShadowValue(vec4 light_space_pos, vec3 normal, vec3 light_dir, sampler // Various bias methods. //bias = max(0.05 * (1.0 - dot(normal, light_dir)), bias); - bias = bias * tan(acos(clamp(dot(normal, -light_dir), 0.0, 1.0))); + //bias = bias * tan(acos(clamp(dot(normal, -light_dir), 0.0, 1.0))); + bias = bias + bias * tan(acos(clamp(dot(normal, -light_dir), 0.0, 1.0))); // Calculate coordinates in projection space. vec3 projCoords = vec3(light_space_pos.xy, light_space_pos.z + bias) / light_space_pos.w; projCoords = projCoords * 0.5 + 0.5; + //projCoords = (floor(projCoords * 255.0)) / 255.0; // Various methods for shadow calculation in fastest to slowest order. - shadowMapDepth = PCFShadow(depth_texture_array, projCoords, layer_index); + //shadowMapDepth = PCFShadow(depth_texture_array, projCoords, layer_index); //shadowMapDepth = PoissonShadow(depth_texture_array, projCoords, layer_index, 4, 25.0 * FarDistance[MAX_SPLITS - 1]); - //shadowMapDepth = PoissonDotShadow(depth_texture_array, projCoords, layer_index, 4, 25.0 * FarDistance[MAX_SPLITS]); - //shadowMapDepth = SoftwarePCF(depth_texture_array, projCoords, layer_index, bias); + //shadowMapDepth = PoissonDotShadow(depth_texture_array, projCoords, layer_index, 4, 25.0 * FarDistance[MAX_SPLITS - 1]); + shadowMapDepth = SoftwarePCF(depth_texture_array, projCoords, layer_index, bias); return 1.0 - shadowMapDepth; } @@ -327,8 +329,8 @@ void main() totalLighting.Specular += light_result.Specular; } - totalLighting.Diffuse *= (1.0 + vec4(AmbientColor.rgba)) - vec4(vec3(shadowFactor), 0.0); - totalLighting.Specular *= (1.0 + vec4(AmbientColor.rgba)) - vec4(vec3(shadowFactor), 0.0); + totalLighting.Diffuse *= (1.5 + vec4(AmbientColor.rgba)) - vec4(vec3(shadowFactor), 0.0); + totalLighting.Specular *= (1.5 + vec4(AmbientColor.rgba)) - vec4(vec3(shadowFactor), 0.0); //LightResult getInformation; diff --git a/resources/Shaders/Shadow.frag.glsl b/resources/Shaders/Shadow.frag.glsl index 3287df7c..a03e17c7 100644 --- a/resources/Shaders/Shadow.frag.glsl +++ b/resources/Shaders/Shadow.frag.glsl @@ -2,7 +2,7 @@ #define ALPHA_CUTOFF 0.3 -layout (binding = 12) uniform sampler2D DiffuseTexture; +layout (binding = 24) uniform sampler2D DiffuseTexture; uniform float Alpha; in VertexData{ diff --git a/src/Engine/Rendering/ShadowPass.cpp b/src/Engine/Rendering/ShadowPass.cpp index c0ee1e54..185d24ab 100644 --- a/src/Engine/Rendering/ShadowPass.cpp +++ b/src/Engine/Rendering/ShadowPass.cpp @@ -186,6 +186,8 @@ void ShadowPass::PointsToLightspace(Frustum& frustum, glm::mat4 v) void ShadowPass::RadiusToLightspace(Frustum& frustum) { + float quantizationStep = 1.0f / m_ResolutionSizeHeight; + float left = -frustum.Radius; float right = frustum.Radius; float bottom = -frustum.Radius; @@ -219,6 +221,8 @@ void ShadowPass::Draw(RenderScene & scene) m_LightView[i] = glm::lookAt(glm::vec3(-directionalLightJob->Direction) + m_shadowFrusta[i].MiddlePoint, m_shadowFrusta[i].MiddlePoint, glm::vec3(0.f, 1.f, 0.f)); PointsToLightspace(m_shadowFrusta[i], m_LightView[i]); + //FindRadius(m_shadowFrusta[i]); + //RadiusToLightspace(m_shadowFrusta[i]); m_LightProjection[i] = glm::ortho(m_shadowFrusta[i].LRBT[LEFT], m_shadowFrusta[i].LRBT[RIGHT], m_shadowFrusta[i].LRBT[BOTTOM], m_shadowFrusta[i].LRBT[TOP], m_NearFarPlane[NEAR], m_NearFarPlane[FAR]); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_LightProjection[i])); @@ -227,37 +231,43 @@ void ShadowPass::Draw(RenderScene & scene) GLERROR("ShadowLight ERROR"); for (auto &objectJob : scene.OpaqueObjects) { - auto modelJob = std::dynamic_pointer_cast(objectJob); + if (!std::dynamic_pointer_cast(objectJob)) + { + auto modelJob = std::dynamic_pointer_cast(objectJob); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); - glBindVertexArray(modelJob->Model->VAO); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); - glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int))); + glBindVertexArray(modelJob->Model->VAO); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); + glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int))); - GLERROR("Shadow Draw ERROR"); + GLERROR("Shadow Draw ERROR"); + } } state->CullFace(GL_BACK); for (auto &objectJob : scene.TransparentObjects) { - auto modelJob = std::dynamic_pointer_cast(objectJob); + if (!std::dynamic_pointer_cast(objectJob)) + { + auto modelJob = std::dynamic_pointer_cast(objectJob); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); - glUniform1f(glGetUniformLocation(shaderHandle, "Alpha"), modelJob->Color.a); - - glActiveTexture(GL_TEXTURE12); - if (modelJob->DiffuseTexture != nullptr) { - glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture->m_Texture); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); + glUniform1f(glGetUniformLocation(shaderHandle, "Alpha"), modelJob->Color.a); + + glActiveTexture(GL_TEXTURE24); + if (modelJob->DiffuseTexture != nullptr) { + glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture->m_Texture); + } + else { + glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture); + } + + glBindVertexArray(modelJob->Model->VAO); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); + glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int))); + + GLERROR("Shadow Draw ERROR"); } - else { - glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture); - } - - glBindVertexArray(modelJob->Model->VAO); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); - glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int))); - - GLERROR("Shadow Draw ERROR"); } state->CullFace(GL_FRONT); } From 5bc0483f491417ad7cbbcba7de7e8760176c98c8 Mon Sep 17 00:00:00 2001 From: viktorljung Date: Mon, 29 Feb 2016 15:51:37 +0100 Subject: [PATCH 045/130] Removed AnimationOffset and improved BlendTree --- include/Engine/Core/EntityWrapper.h | 1 + include/Engine/Rendering/BlendTree.h | 2 +- resources/Schema/Components.xsd | 1 - .../Schema/Components/AnimationOffset.xml | 5 - .../Schema/Components/AnimationOffset.xsd | 17 - resources/Schema/Entities/AnimationTests2.xml | 1190 +++++++++++------ resources/Schema/Types/Entity.xsd | 1 - src/Engine/Core/EntityWrapper.cpp | 25 + src/Engine/Rendering/AnimationSystem.cpp | 20 +- src/Engine/Rendering/BlendTree.cpp | 44 +- 10 files changed, 847 insertions(+), 459 deletions(-) delete mode 100644 resources/Schema/Components/AnimationOffset.xml delete mode 100644 resources/Schema/Components/AnimationOffset.xsd diff --git a/include/Engine/Core/EntityWrapper.h b/include/Engine/Core/EntityWrapper.h index b0e65d9e..aa4cae6b 100644 --- a/include/Engine/Core/EntityWrapper.h +++ b/include/Engine/Core/EntityWrapper.h @@ -28,6 +28,7 @@ struct EntityWrapper void AttachComponent(const char* componentName); EntityWrapper Parent(); EntityWrapper FirstChildByName(const std::string& name); + EntityWrapper FirstLevelChildByName(const std::string& name); EntityWrapper FirstParentWithComponent(const std::string& componentType); bool IsChildOf(EntityWrapper potentialParent); bool Valid() const; diff --git a/include/Engine/Rendering/BlendTree.h b/include/Engine/Rendering/BlendTree.h index a472465b..5b38080d 100644 --- a/include/Engine/Rendering/BlendTree.h +++ b/include/Engine/Rendering/BlendTree.h @@ -63,7 +63,7 @@ public: std::vector GetFinalPose() { return m_FinalPose; } glm::mat4 GetBoneTransform(int boneID); - + bool IsValid() { return (m_Root == nullptr ? false : true); } void PrintTree(); diff --git a/resources/Schema/Components.xsd b/resources/Schema/Components.xsd index fc72762e..a30a4e2c 100644 --- a/resources/Schema/Components.xsd +++ b/resources/Schema/Components.xsd @@ -33,7 +33,6 @@ - diff --git a/resources/Schema/Components/AnimationOffset.xml b/resources/Schema/Components/AnimationOffset.xml deleted file mode 100644 index 4aef8219..00000000 --- a/resources/Schema/Components/AnimationOffset.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/resources/Schema/Components/AnimationOffset.xsd b/resources/Schema/Components/AnimationOffset.xsd deleted file mode 100644 index c3430cc2..00000000 --- a/resources/Schema/Components/AnimationOffset.xsd +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - Aim animation offset for the skeleton - - - - - - - - - \ No newline at end of file diff --git a/resources/Schema/Entities/AnimationTests2.xml b/resources/Schema/Entities/AnimationTests2.xml index ca7c705d..84663233 100644 --- a/resources/Schema/Entities/AnimationTests2.xml +++ b/resources/Schema/Entities/AnimationTests2.xml @@ -2,6 +2,10 @@ + + 0.5 + 2.2999999523162842 + @@ -42,25 +46,15 @@ - - - - Models/Core/UnitPlane.mesh - - - - - - - - AimAdditive - BlendOverride + Aim + FinalBlend - Models/Characters/Assault/AssaultAnimations.mesh + 4 + Models/Characters/Assault/Assaulttest.mesh @@ -74,56 +68,13 @@ Models/Weapons/Blue/AssaultWeaponBlue.mesh - + - + - - - - AimRifleA - true - - - - - - - - - ShootRifleAnimation - MovementBlend - - - - - - - - ShootFastRifleU - - 1 - - - - - - - - - RunF - - 1 - - - - - - - @@ -135,380 +86,63 @@ - - - - - - AimAdditive - BlendOverride - - - Models/Characters/Assault/AssaultAnimations.mesh - - - - - - - - - - - R_Arm_Weapon_Joint - - - Models/Weapons/Blue/AssaultWeaponBlue.mesh - - - - - - - - - - + AimRifleA - - 0.5 + + false true - + - ShootRifleAnimation + WeaponBlend MovementBlend - - - - ShootFastRifleU - - 1 - - - - - - + - BlendWalkRun - StrafeAnimation - 0 - - - - - - - - StrafeLeftF - - 1 - - - - - - - - - RunAnimtaion - WalkAnimation - 1 - - - - - - - - RunF - - 1 - - - - - - - - - WalkF - - 1 - - - - - - - - - - - - - - - - 3 - 0.80000001192092896 - 0.30000001192092896 - - - - - - - - - - - - - AimAdditive - BlendOverride - - - Models/Characters/Assault/AssaultAnimations.mesh - - - - - - - - - - - R_Arm_Weapon_Joint - - - Models/Weapons/Blue/AssaultWeaponBlue.mesh - - - - - - - - - - - - - AimRifleA - - true - - - - - - - - - ShootRifleAnimation - MovementBlend - - - - - - - - ShootRifleU - - 1 - - - - - - - - - BlendWalkRun - StrafeAnimation - 0 - - - - - - - - StrafeRightF - - 1 - - - - - - - - - RunAnimtaion - WalkAnimation - 0.43000054359436035 - - - - - - - - RunF - - 1 - - - - - - - - - WalkF - - 1 - - - - - - - - - - - - - - - - 3 - 0.30000001192092896 - - - - - - - - - - - - - AimAdditive - BlendOverride - - - Models/Characters/Assault/AssaultAnimations.mesh - - - - - - - - - - - R_Arm_Weapon_Joint - - - Models/Weapons/Blue/AssaultWeaponBlue.mesh - - - - - - - - - - - - - AimRifleA - - true - - - - - - - - - ShootRifleAnimation - MovementBlend - - - - - - - - BlendWalkRun - StrafeAnimation + ShootBlend + Reload 1 - - - - StrafeRightF - - 1 - - - - - - + - RunAnimtaion - WalkAnimation + ShootFast + ShootSlow 1 - + - CrouchWalkF - + ShootFastRifleU + 1 - + - WalkF - + ShootRifleU + 1 @@ -517,25 +151,229 @@ + + + + ReloadSwitchU + + 1 + + + + + - + - - ReloadSwitchU - - 1 - + + StandCrouchBlend + Jump + 1 + - + + + + + StandMovement + CrouchMovement + 1 + + + + + + + + Walk + StrafeBlend + 1 + + + + + + + + CrouchWalkF + + 1 + + + + + + + + + Left + Right + 1 + + + + + + + + CrouchStrafeLeftF + + 1 + + + + + + + + + CrouchStrafeRightF + + 1 + + + + + + + + + + + + + RunWalkBlend + StrafeBlend + 1 + + + + + + + + Run + Walk + 0 + + + + + + + + RunF + + 1 + + + + + + + + + WalkF + + 1 + + + + + + + + + + + Left + Right + 0 + + + + + + + + StrafeLeftF + + 1 + + + + + + + + + StrafeRightF + + 1 + + + + + + + + + + + + + + + JumpF + + 1 + + + + + + + + + + + + Aim + FinalBlend + + + Models/Characters/Assault/Assaulttest.mesh + + + + + + + + + + + R_Arm_Weapon_Joint + + + Models/Weapons/Blue/AssaultWeaponBlue.mesh + + + + + + + + + - 3 @@ -544,24 +382,554 @@ + + + + AimRifleA + false + true + + + + + + + + + WeaponBlend + MovementBlend + + + + + + + + ShootBlend + Reload + 1 + + + + + + + + ShootFast + ShootSlow + 1 + + + + + + + + ShootFastRifleU + + 1 + + + + + + + + + ShootRifleU + + 1 + + + + + + + + + + + ReloadSwitchU + + 1 + + + + + + + + + + + StandCrouchBlend + Jump + 1 + + + + + + + + StandMovement + CrouchMovement + 1 + + + + + + + + Walk + StrafeBlend + 1 + + + + + + + + CrouchWalkF + + 1 + + + + + + + + + Left + Right + 1 + + + + + + + + CrouchStrafeLeftF + + 1 + + + + + + + + + CrouchStrafeRightF + + 1 + + + + + + + + + + + + + RunWalkBlend + StrafeBlend + 1 + + + + + + + + Run + Walk + 1 + + + + + + + + RunF + + 1 + + + + + + + + + WalkF + + 1 + + + + + + + + + + + Left + Right + 1 + + + + + + + + StrafeLeftF + + 1 + + + + + + + + + StrafeRightF + + 1 + + + + + + + + + + + + + + + JumpF + + 1 + + + + + + + + + - + + + Aim + FinalBlend + - Models/Core/UnitSphere.mesh - + Models/Characters/Assault/Assaulttest.mesh + - - - 3 - - - + - + + + + + R_Arm_Weapon_Joint + + + Models/Weapons/Blue/AssaultWeaponBlue.mesh + + + + + + + + + + + + + 3 + + + + + + + + + + + AimRifleA + + false + true + + + + + + + + + WeaponBlend + MovementBlend + + + + + + + + ShootBlend + Reload + 1 + + + + + + + + ShootFast + ShootSlow + 1 + + + + + + + + ShootFastRifleU + + 1 + + + + + + + + + ShootRifleU + + 1 + + + + + + + + + + + ReloadSwitchU + + 1 + + + + + + + + + + + StandCrouchBlend + Jump + 1 + + + + + + + + StandMovement + CrouchMovement + 0 + + + + + + + + Walk + StrafeBlend + 1 + + + + + + + + CrouchWalkF + + 1 + + + + + + + + + Left + Right + 1 + + + + + + + + CrouchStrafeLeftF + + 1 + + + + + + + + + CrouchStrafeRightF + + 1 + + + + + + + + + + + + + RunWalkBlend + StrafeBlend + 1 + + + + + + + + Run + Walk + 1 + + + + + + + + RunF + + 1 + + + + + + + + + WalkF + + 1 + + + + + + + + + + + Left + Right + 1 + + + + + + + + StrafeLeftF + + 1 + + + + + + + + + StrafeRightF + + 1 + + + + + + + + + + + + + + + JumpF + + 1 + + + + + + + + + + diff --git a/resources/Schema/Types/Entity.xsd b/resources/Schema/Types/Entity.xsd index 4fba7420..b0fbd279 100644 --- a/resources/Schema/Types/Entity.xsd +++ b/resources/Schema/Types/Entity.xsd @@ -49,7 +49,6 @@ - diff --git a/src/Engine/Core/EntityWrapper.cpp b/src/Engine/Core/EntityWrapper.cpp index 4b45b8d0..78bca235 100644 --- a/src/Engine/Core/EntityWrapper.cpp +++ b/src/Engine/Core/EntityWrapper.cpp @@ -39,6 +39,31 @@ EntityWrapper EntityWrapper::FirstChildByName(const std::string& name) return firstChildByNameRecursive(name, this->ID); } + +EntityWrapper EntityWrapper::FirstLevelChildByName(const std::string& name) +{ + EntityID parent = this->ID; + if (!this->World->ValidEntity(parent)) { + return EntityWrapper::Invalid; + } + + auto itPair = this->World->GetChildren(parent); + if (itPair.first == itPair.second) { + return EntityWrapper::Invalid; + } + + for (auto it = itPair.first; it != itPair.second; ++it) { + std::string itName = this->World->GetName(it->second); + if (itName == name) { + return EntityWrapper(this->World, it->second); + } else if (it->second != EntityID_Invalid) { + continue; + } + } + + return EntityWrapper::Invalid; +} + EntityWrapper EntityWrapper::FirstParentWithComponent(const std::string& componentType) { EntityWrapper entity = *this; diff --git a/src/Engine/Rendering/AnimationSystem.cpp b/src/Engine/Rendering/AnimationSystem.cpp index 9a74da29..5bc64535 100644 --- a/src/Engine/Rendering/AnimationSystem.cpp +++ b/src/Engine/Rendering/AnimationSystem.cpp @@ -34,7 +34,16 @@ void AnimationSystem::CreateBlendTrees() continue; } - skeleton->BlendTrees[entity] = std::shared_ptr(new BlendTree(entity, skeleton)); + if (entity.HasComponent("Blend") || entity.HasComponent("BlendOverride") || + entity.HasComponent("BlendAdditive") || entity.HasComponent("Animation")) + { + std::shared_ptr blendTree = std::shared_ptr(new BlendTree(entity, skeleton)); + + if(blendTree->IsValid()) { + skeleton->BlendTrees[entity] = blendTree; + } + + } } } @@ -47,11 +56,16 @@ void AnimationSystem::UpdateAnimations(double dt) for (auto& animationC : *animationComponents) { EntityWrapper entity = EntityWrapper(m_World, animationC.EntityID); - EntityWrapper parent = entity.FirstParentWithComponent("Model"); + EntityWrapper modelEntity; + if(!entity.HasComponent("Model")) { + modelEntity = entity.FirstParentWithComponent("Model"); + } else { + modelEntity = entity; + } Model* model; try { - model = ResourceManager::Load<::Model, true>(parent["Model"]["Resource"]); + model = ResourceManager::Load<::Model, true>(modelEntity["Model"]["Resource"]); } catch (const std::exception&) { return; } diff --git a/src/Engine/Rendering/BlendTree.cpp b/src/Engine/Rendering/BlendTree.cpp index 0d87665f..0305af19 100644 --- a/src/Engine/Rendering/BlendTree.cpp +++ b/src/Engine/Rendering/BlendTree.cpp @@ -6,11 +6,6 @@ BlendTree::BlendTree(EntityWrapper ModelEntity, Skeleton* skeleton) m_Skeleton = skeleton; - auto itPair = ModelEntity.World->GetChildren(ModelEntity.ID); - if (itPair.first == itPair.second) { - return; - } - if (ModelEntity.HasComponent("Animation")) { const Skeleton::Animation* animation = skeleton->GetAnimation(ModelEntity["Animation"]["AnimationName"]); @@ -59,20 +54,21 @@ BlendTree::BlendTree(EntityWrapper ModelEntity, Skeleton* skeleton) BlendTree::~BlendTree() { Node* currentNode = m_Root; + if (currentNode != nullptr) { + while (currentNode->Child[0] != nullptr) { + currentNode = currentNode->Child[0]; + } - while (currentNode->Child[0] != nullptr) { - currentNode = currentNode->Child[0]; - } + std::list m_NodesToRemove; - std::list m_NodesToRemove; + while (currentNode != nullptr) { + m_NodesToRemove.push_back(currentNode); + currentNode = currentNode->Next(); + } - while (currentNode != nullptr) { - m_NodesToRemove.push_back(currentNode); - currentNode = currentNode->Next(); - } - - for (auto it = m_NodesToRemove.begin(); it != m_NodesToRemove.end(); it++) { - delete (*it); + for (auto it = m_NodesToRemove.begin(); it != m_NodesToRemove.end(); it++) { + delete (*it); + } } } @@ -107,7 +103,7 @@ void BlendTree::PrintTree() BlendTree::Node* BlendTree::FillTreeByName(Node* parentNode, std::string name, EntityWrapper parentEntity) { - EntityWrapper childEntity = parentEntity.FirstChildByName(name); // Make first level child by name + EntityWrapper childEntity = parentEntity.FirstLevelChildByName(name); // Make first level child by name if (!childEntity.Valid()) { return nullptr; @@ -133,8 +129,16 @@ BlendTree::Node* BlendTree::FillTreeByName(Node* parentNode, std::string name, E node->Type = NodeType::Blend; (double&)childEntity["Blend"]["Weight"] = glm::clamp((float)(double)childEntity["Blend"]["Weight"], 0.f, 1.f); node->Weight = (double)childEntity["Blend"]["Weight"]; - node->Child[0] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose1"], childEntity); - node->Child[1] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose2"], childEntity); + if (node->Weight < 1.f && node->Weight > 0.f) { + node->Child[0] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose1"], childEntity); + node->Child[1] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose2"], childEntity); + } else if (node->Weight == 1.f) { + node->Child[0] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose1"], childEntity); + } else if (node->Weight == 0.f) { + node->Child[1] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose2"], childEntity); + } + + return node; } else if (childEntity.HasComponent("BlendOverride")) { Node* node = new Node(); @@ -213,7 +217,7 @@ void BlendTree::Blend(std::map& pose) std::vector BlendTree::AccumulateFinalPose() { std::vector finalPose; - if (m_Skeleton == nullptr || m_Root == nullptr) { + if (m_Skeleton == nullptr || m_Root == nullptr || (m_Root->Child[0] == nullptr && m_Root->Child[1] == nullptr)) { for (int i = 0; i < m_Skeleton->Bones.size(); i++) { finalPose.push_back(glm::mat4(1)); From 70374fa10e53f113f7e7eb4a935f1cc2bc9a86c7 Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Mon, 29 Feb 2016 18:20:32 +0100 Subject: [PATCH 046/130] It compiles, but no shadows --- .../Engine/Rendering/DirectionalLightJob.h | 1 - include/Engine/Rendering/ShadowPass.h | 16 +++--- .../Shaders/ForwardPlusSkinned.vert.glsl | 2 + .../Shaders/ForwardPlusSplatMapRGB.frag.glsl | 1 + src/Engine/Rendering/FrameBuffer.cpp | 56 +++++++++---------- src/Engine/Rendering/ShadowPass.cpp | 43 +++++++++----- 6 files changed, 68 insertions(+), 51 deletions(-) diff --git a/include/Engine/Rendering/DirectionalLightJob.h b/include/Engine/Rendering/DirectionalLightJob.h index 0fcfaf84..4c12b1ed 100644 --- a/include/Engine/Rendering/DirectionalLightJob.h +++ b/include/Engine/Rendering/DirectionalLightJob.h @@ -17,7 +17,6 @@ struct DirectionalLightJob : RenderJob { Orientation = Transform::AbsoluteOrientation(m_World, transformComponent.EntityID); Direction = glm::vec4(0,0,-1,0) * glm::inverse(Orientation); - //Direction = glm::vec4((glm::vec3)directionalLightComponent["Direction"], 0.f); Color = (glm::vec4)directionalLightComponent["Color"]; Intensity = (double)directionalLightComponent["Intensity"]; }; diff --git a/include/Engine/Rendering/ShadowPass.h b/include/Engine/Rendering/ShadowPass.h index c4007cce..3f506cb7 100644 --- a/include/Engine/Rendering/ShadowPass.h +++ b/include/Engine/Rendering/ShadowPass.h @@ -14,7 +14,7 @@ enum NearFar { NEAR = 0, FAR = 1 }; enum LRBT { LEFT = 0, RIGHT = 1, BOTTOM = 2, TOP = 3 }; -struct Frustum +struct ShadowFrustum { float NearClip; float FarClip; @@ -47,14 +47,14 @@ public: void SetSplitWeight(float split_weight) { m_SplitWeight = split_weight; }; private: void InitializeCameras(RenderScene & scene); - void UpdateSplitDist(std::array& frusta, float near_distance, float far_distance); - void UpdateFrustumPoints(Frustum& frustum, glm::vec3 camera_position, glm::vec3 view_dir); - void UpdateFrustumPoints(Frustum& frustum, glm::mat4 p, glm::mat4 v); + void UpdateSplitDist(std::array& frusta, float near_distance, float far_distance); + void UpdateFrustumPoints(ShadowFrustum& frustum, glm::vec3 camera_position, glm::vec3 view_dir); + void UpdateFrustumPoints(ShadowFrustum& frustum, glm::mat4 p, glm::mat4 v); - void PointsToLightspace(Frustum& frustum, glm::mat4 v); + void PointsToLightspace(ShadowFrustum& frustum, glm::mat4 v); - float FindRadius(Frustum& frustum); - void RadiusToLightspace(Frustum& frustum); + float FindRadius(ShadowFrustum& frustum); + void RadiusToLightspace(ShadowFrustum& frustum); EventBroker* m_EventBroker; const IRenderer* m_Renderer; @@ -74,7 +74,7 @@ private: int m_CurrentNrOfSplits = 4; float m_SplitWeight = 0.91f; - std::array m_shadowFrusta; + std::array m_shadowFrusta; Texture* m_WhiteTexture = ResourceManager::Load("Textures/Core/White.png"); }; diff --git a/resources/Shaders/ForwardPlusSkinned.vert.glsl b/resources/Shaders/ForwardPlusSkinned.vert.glsl index 5fd55a8c..83db983b 100644 --- a/resources/Shaders/ForwardPlusSkinned.vert.glsl +++ b/resources/Shaders/ForwardPlusSkinned.vert.glsl @@ -21,6 +21,7 @@ out VertexData{ vec2 TextureCoordinate; vec4 ExplosionColor; float ExplosionPercentageElapsed; + vec4 PositionLightSpace[MAX_SPLITS]; }Output; void main() @@ -43,4 +44,5 @@ void main() Output.BiTangent = vec3(M * vec4(BiTangent, 0.0)); Output.ExplosionColor = vec4(1.0); Output.ExplosionPercentageElapsed = 0.0; + Output.PositionLightSpace = boneTransform * vec4(Position, 1.0); } \ No newline at end of file diff --git a/resources/Shaders/ForwardPlusSplatMapRGB.frag.glsl b/resources/Shaders/ForwardPlusSplatMapRGB.frag.glsl index cf358b96..af50155d 100644 --- a/resources/Shaders/ForwardPlusSplatMapRGB.frag.glsl +++ b/resources/Shaders/ForwardPlusSplatMapRGB.frag.glsl @@ -82,6 +82,7 @@ in VertexData{ vec2 TextureCoordinate; vec4 ExplosionColor; float ExplosionPercentageElapsed; + vec4 PositionLightSpace[MAX_SPLITS]; }Input; out vec4 sceneColor; diff --git a/src/Engine/Rendering/FrameBuffer.cpp b/src/Engine/Rendering/FrameBuffer.cpp index e0dd9b2d..167de142 100644 --- a/src/Engine/Rendering/FrameBuffer.cpp +++ b/src/Engine/Rendering/FrameBuffer.cpp @@ -61,45 +61,45 @@ void FrameBuffer::Generate() glBindFramebuffer(GL_FRAMEBUFFER, m_BufferHandle); GLERROR("1"); - for (auto it = m_Resources.begin(); it != m_Resources.end(); it++) { - switch ((*it)->m_ResourceType) { - case GL_TEXTURE_2D: - glFramebufferTexture2D(GL_FRAMEBUFFER, (*it)->m_Attachment, (*it)->m_ResourceType, *(*it)->m_ResourceHandle, 0); + for (auto it = m_Resources.begin(); it != m_Resources.end(); it++) { + switch ((*it)->m_ResourceType) { + case GL_TEXTURE_2D: + glFramebufferTexture2D(GL_FRAMEBUFFER, (*it)->m_Attachment, (*it)->m_ResourceType, *(*it)->m_ResourceHandle, 0); attachments.push_back((*it)->m_Attachment); - GLERROR("FrameBuffer generate: glFramebufferTexture2D"); - break; - case GL_RENDERBUFFER: - glFramebufferRenderbuffer(GL_FRAMEBUFFER, (*it)->m_Attachment, (*it)->m_ResourceType, *(*it)->m_ResourceHandle); - GLERROR("FrameBuffer generate: glFramebufferRenderbuffer"); - break; + GLERROR("FrameBuffer generate: glFramebufferTexture2D"); + break; + case GL_RENDERBUFFER: + glFramebufferRenderbuffer(GL_FRAMEBUFFER, (*it)->m_Attachment, (*it)->m_ResourceType, *(*it)->m_ResourceHandle); + GLERROR("FrameBuffer generate: glFramebufferRenderbuffer"); + break; case GL_TEXTURE_2D_ARRAY: glFramebufferTexture(GL_FRAMEBUFFER, (*it)->m_Attachment, *(*it)->m_ResourceHandle, 0); attachments.push_back((*it)->m_Attachment); GLERROR("FrameBuffer generate: GL_TEXTURE_2D_ARRAY"); break; - } - GLERROR("2"); + } + GLERROR("2"); - if ((*it)->m_Attachment != GL_DEPTH_ATTACHMENT && (*it)->m_Attachment != GL_STENCIL_ATTACHMENT && (*it)->m_Attachment != GL_DEPTH_STENCIL_ATTACHMENT) { - GLERROR("Attachment"); + if ((*it)->m_Attachment != GL_DEPTH_ATTACHMENT && (*it)->m_Attachment != GL_STENCIL_ATTACHMENT && (*it)->m_Attachment != GL_DEPTH_STENCIL_ATTACHMENT) { + GLERROR("Attachment"); - } - GLERROR("3"); + } + GLERROR("3"); - GLenum* bufferTextures = &attachments[0]; - glDrawBuffers(attachments.size(), bufferTextures); - if (GLERROR("GLBufferAttachement error")) { - printf(": AttachmentSize %i", attachments.size()); - } - - if (GLenum frameBufferStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { - GLERROR("Framebuffer incomplete"); - //LOG_ERROR("FrameBuffer incomplete: 0x%x\n", frameBufferStatus); - exit(EXIT_FAILURE); - } - GLERROR("END"); + GLenum* bufferTextures = &attachments[0]; + glDrawBuffers(attachments.size(), bufferTextures); + if (GLERROR("GLBufferAttachement error")) { + printf(": AttachmentSize %i", attachments.size()); + } + if (GLenum frameBufferStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { + GLERROR("Framebuffer incomplete"); + //LOG_ERROR("FrameBuffer incomplete: 0x%x\n", frameBufferStatus); + exit(EXIT_FAILURE); + } + GLERROR("END"); + } } void FrameBuffer::Bind() diff --git a/src/Engine/Rendering/ShadowPass.cpp b/src/Engine/Rendering/ShadowPass.cpp index 185d24ab..df0da0e1 100644 --- a/src/Engine/Rendering/ShadowPass.cpp +++ b/src/Engine/Rendering/ShadowPass.cpp @@ -34,7 +34,7 @@ void ShadowPass::InitializeCameras(RenderScene & scene) // UpdateSplitDist computes the near and far distances for every frustum slice // in camera eye space - that is, at what distance does a slice start and end -void ShadowPass::UpdateSplitDist(std::array& frusta, float near_distance, float far_distance) +void ShadowPass::UpdateSplitDist(std::array& frusta, float near_distance, float far_distance) { float lambda = m_SplitWeight; float ratio = far_distance / near_distance; @@ -51,7 +51,7 @@ void ShadowPass::UpdateSplitDist(std::array& frusta, float frusta[m_CurrentNrOfSplits - 1].FarClip = far_distance; } -void ShadowPass::UpdateFrustumPoints(Frustum& frustum, glm::mat4 p, glm::mat4 v) +void ShadowPass::UpdateFrustumPoints(ShadowFrustum& frustum, glm::mat4 p, glm::mat4 v) { std::array CornerPoint = { glm::vec4(-1.f, -1.f, -1.f, 1.f), @@ -72,7 +72,7 @@ void ShadowPass::UpdateFrustumPoints(Frustum& frustum, glm::mat4 p, glm::mat4 v) } // Compute the 8 corner points of the current view frustum in world space -void ShadowPass::UpdateFrustumPoints(Frustum& frustum, glm::vec3 camera_position, glm::vec3 view_dir) +void ShadowPass::UpdateFrustumPoints(ShadowFrustum& frustum, glm::vec3 camera_position, glm::vec3 view_dir) { glm::vec3 up = glm::vec3(0.f, 1.f, 0.f); glm::vec3 right = glm::normalize(glm::cross(view_dir, up)); @@ -100,7 +100,7 @@ void ShadowPass::UpdateFrustumPoints(Frustum& frustum, glm::vec3 camera_position frustum.CornerPoint[7] = far_center - up * far_height + right * far_width; } -float ShadowPass::FindRadius(Frustum& frustum) +float ShadowPass::FindRadius(ShadowFrustum& frustum) { float radius = 0.f; @@ -164,7 +164,7 @@ void ShadowPass::ClearBuffer() m_DepthBuffer.Unbind(); } -void ShadowPass::PointsToLightspace(Frustum& frustum, glm::mat4 v) +void ShadowPass::PointsToLightspace(ShadowFrustum& frustum, glm::mat4 v) { float left = INFINITY; float right = -INFINITY; @@ -184,7 +184,7 @@ void ShadowPass::PointsToLightspace(Frustum& frustum, glm::mat4 v) frustum.LRBT = { left, right, bottom, top }; } -void ShadowPass::RadiusToLightspace(Frustum& frustum) +void ShadowPass::RadiusToLightspace(ShadowFrustum& frustum) { float quantizationStep = 1.0f / m_ResolutionSizeHeight; @@ -214,7 +214,7 @@ void ShadowPass::Draw(RenderScene & scene) glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_DepthMap, 0, i); - for (auto &job : scene.DirectionalLightJobs) { + for (auto &job : scene.Jobs.DirectionalLight) { auto directionalLightJob = std::dynamic_pointer_cast(job); if (directionalLightJob) { @@ -230,7 +230,7 @@ void ShadowPass::Draw(RenderScene & scene) GLERROR("ShadowLight ERROR"); - for (auto &objectJob : scene.OpaqueObjects) { + for (auto &objectJob : scene.Jobs.OpaqueObjects) { if (!std::dynamic_pointer_cast(objectJob)) { auto modelJob = std::dynamic_pointer_cast(objectJob); @@ -246,20 +246,35 @@ void ShadowPass::Draw(RenderScene & scene) } state->CullFace(GL_BACK); - for (auto &objectJob : scene.TransparentObjects) { + for (auto &objectJob : scene.Jobs.TransparentObjects) { if (!std::dynamic_pointer_cast(objectJob)) { auto modelJob = std::dynamic_pointer_cast(objectJob); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); glUniform1f(glGetUniformLocation(shaderHandle, "Alpha"), modelJob->Color.a); - - glActiveTexture(GL_TEXTURE24); - if (modelJob->DiffuseTexture != nullptr) { - glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture->m_Texture); + + switch (modelJob->Type) { + case RawModel::MaterialType::SingleTextures: + case RawModel::MaterialType::Basic: + { + glActiveTexture(GL_TEXTURE24); + if (modelJob->DiffuseTexture.size() > 0 && modelJob->DiffuseTexture[0]->Texture != nullptr) { + glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture[0]->Texture->m_Texture); + glUniform2fv(glGetUniformLocation(shaderHandle, "DiffuseUVRepeat"), 1, glm::value_ptr(modelJob->DiffuseTexture[0]->UVRepeat)); + } + else { + glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture); + glUniform2fv(glGetUniformLocation(shaderHandle, "DiffuseUVRepeat"), 1, glm::value_ptr(glm::vec2(1.0f, 1.0f))); + } + break; } - else { + case RawModel::MaterialType::SplatMapping: + { glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture); + glUniform2fv(glGetUniformLocation(shaderHandle, "DiffuseUVRepeat"), 1, glm::value_ptr(glm::vec2(1.0f, 1.0f))); + break; + } } glBindVertexArray(modelJob->Model->VAO); From 2ed5fad6996778e21b734b9f9015d049fd49f7bc Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Mon, 29 Feb 2016 19:17:16 +0100 Subject: [PATCH 047/130] The shadows are working --- resources/Shaders/ForwardPlus.frag.glsl | 7 ++++--- resources/Shaders/ForwardPlus.vert.glsl | 8 -------- src/Engine/Rendering/DrawFinalPass.cpp | 18 ++++++++---------- src/Engine/Rendering/ShadowPass.cpp | 6 +++--- 4 files changed, 15 insertions(+), 24 deletions(-) diff --git a/resources/Shaders/ForwardPlus.frag.glsl b/resources/Shaders/ForwardPlus.frag.glsl index d1c75cd0..fc7527be 100644 --- a/resources/Shaders/ForwardPlus.frag.glsl +++ b/resources/Shaders/ForwardPlus.frag.glsl @@ -2,6 +2,7 @@ #define MAX_SPLITS 4 #define MIN_AMBIENT_LIGHT 0.3 +#define SHADOW_STRENGTH 0.3 //Should be ambient uniform mat4 M; uniform mat4 V; @@ -235,7 +236,7 @@ float CalcShadowValue(vec4 light_space_pos, vec3 normal, vec3 light_dir, sampler //shadowMapDepth = PoissonDotShadow(depth_texture_array, projCoords, layer_index, 4, 25.0 * FarDistance[MAX_SPLITS - 1]); shadowMapDepth = SoftwarePCF(depth_texture_array, projCoords, layer_index, bias); - return 1.0 - shadowMapDepth; + return shadowMapDepth; } int getShadowIndex(float far_distance[1]) @@ -342,8 +343,8 @@ void main() totalLighting.Specular += vec4(light_result.Specular.rgb * ao, light_result.Specular.a); } - totalLighting.Diffuse *= (1.5 + vec4(AmbientColor.rgba)) - vec4(vec3(shadowFactor), 0.0); - totalLighting.Specular *= (1.5 + vec4(AmbientColor.rgba)) - vec4(vec3(shadowFactor), 0.0); + totalLighting.Diffuse *= vec4(min(vec3(shadowFactor) + AmbientColor.xyz, vec3(1.0)), 1.0); + totalLighting.Specular *= vec4(min(vec3(shadowFactor) + AmbientColor.xyz, vec3(1.0)), 1.0); //LightResult getInformation; diff --git a/resources/Shaders/ForwardPlus.vert.glsl b/resources/Shaders/ForwardPlus.vert.glsl index b8d42b14..2a54415b 100644 --- a/resources/Shaders/ForwardPlus.vert.glsl +++ b/resources/Shaders/ForwardPlus.vert.glsl @@ -25,14 +25,6 @@ out VertexData{ vec4 PositionLightSpace[MAX_SPLITS]; }Output; -// N -mat4 biasMatrix = mat4( -vec4(0.5, 0.0, 0.0, 0.0), -vec4(0.0, 0.5, 0.0, 0.0), -vec4(0.0, 0.0, 0.5, 0.0), -vec4(0.5, 0.5, 0.5, 1.0) -); - void main() { gl_Position = P*V*M * vec4(Position, 1.0); diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index 11249703..4470ad1b 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -1014,6 +1014,14 @@ void DrawFinalPass::BindModelTextures(GLuint shaderHandle, std::shared_ptrm_Texture); glUniform2fv(glGetUniformLocation(shaderHandle, "GlowUVRepeat"), 1, glm::value_ptr(glm::vec2(1.0f, 1.0f))); } + + glActiveTexture(GL_TEXTURE6); + if (m_ShadowPass->DepthMap() != NULL) { + glBindTexture(GL_TEXTURE_2D_ARRAY, m_ShadowPass->DepthMap()); + } + else { + glBindTexture(GL_TEXTURE_2D_ARRAY, m_WhiteTexture->m_Texture); + } break; } case RawModel::MaterialType::SplatMapping: @@ -1081,15 +1089,5 @@ void DrawFinalPass::BindModelTextures(GLuint shaderHandle, std::shared_ptrDepthMap() != NULL) { - glBindTexture(GL_TEXTURE_2D_ARRAY, m_ShadowPass->DepthMap()); - } - else { - glBindTexture(GL_TEXTURE_2D_ARRAY, m_WhiteTexture->m_Texture); - } - - } diff --git a/src/Engine/Rendering/ShadowPass.cpp b/src/Engine/Rendering/ShadowPass.cpp index df0da0e1..0fa2193a 100644 --- a/src/Engine/Rendering/ShadowPass.cpp +++ b/src/Engine/Rendering/ShadowPass.cpp @@ -253,8 +253,8 @@ void ShadowPass::Draw(RenderScene & scene) glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); glUniform1f(glGetUniformLocation(shaderHandle, "Alpha"), modelJob->Color.a); - - switch (modelJob->Type) { + + /*switch (modelJob->Type) { case RawModel::MaterialType::SingleTextures: case RawModel::MaterialType::Basic: { @@ -275,7 +275,7 @@ void ShadowPass::Draw(RenderScene & scene) glUniform2fv(glGetUniformLocation(shaderHandle, "DiffuseUVRepeat"), 1, glm::value_ptr(glm::vec2(1.0f, 1.0f))); break; } - } + }*/ glBindVertexArray(modelJob->Model->VAO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); From 0908be1e0200092e4c855579badc281f5a3008a0 Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Mon, 29 Feb 2016 19:45:56 +0100 Subject: [PATCH 048/130] Shadows are pretty much done. --- .../Engine/Rendering/DirectionalLightJob.h | 2 + .../Schema/Components/DirectionalLight.xml | 1 + .../Schema/Components/DirectionalLight.xsd | 1 + resources/Shaders/ForwardPlus.frag.glsl | 1 - src/Engine/Rendering/ShadowPass.cpp | 40 ++++++++++--------- 5 files changed, 26 insertions(+), 19 deletions(-) diff --git a/include/Engine/Rendering/DirectionalLightJob.h b/include/Engine/Rendering/DirectionalLightJob.h index 4c12b1ed..65d477d1 100644 --- a/include/Engine/Rendering/DirectionalLightJob.h +++ b/include/Engine/Rendering/DirectionalLightJob.h @@ -19,12 +19,14 @@ struct DirectionalLightJob : RenderJob Direction = glm::vec4(0,0,-1,0) * glm::inverse(Orientation); Color = (glm::vec4)directionalLightComponent["Color"]; Intensity = (double)directionalLightComponent["Intensity"]; + //TextureAlphaShadows = (bool)directionalLightComponent["TextureAlphaShadows"]; }; glm::quat Orientation; glm::vec4 Direction; glm::vec4 Color; float Intensity; + bool TextureAlphaShadows = false; void CalculateHash() override { diff --git a/resources/Schema/Components/DirectionalLight.xml b/resources/Schema/Components/DirectionalLight.xml index 7f777ef8..a4b22985 100644 --- a/resources/Schema/Components/DirectionalLight.xml +++ b/resources/Schema/Components/DirectionalLight.xml @@ -2,5 +2,6 @@ 0.8 + true \ No newline at end of file diff --git a/resources/Schema/Components/DirectionalLight.xsd b/resources/Schema/Components/DirectionalLight.xsd index a14248a8..692d9677 100644 --- a/resources/Schema/Components/DirectionalLight.xsd +++ b/resources/Schema/Components/DirectionalLight.xsd @@ -9,6 +9,7 @@ + diff --git a/resources/Shaders/ForwardPlus.frag.glsl b/resources/Shaders/ForwardPlus.frag.glsl index fc7527be..0fd76f80 100644 --- a/resources/Shaders/ForwardPlus.frag.glsl +++ b/resources/Shaders/ForwardPlus.frag.glsl @@ -2,7 +2,6 @@ #define MAX_SPLITS 4 #define MIN_AMBIENT_LIGHT 0.3 -#define SHADOW_STRENGTH 0.3 //Should be ambient uniform mat4 M; uniform mat4 V; diff --git a/src/Engine/Rendering/ShadowPass.cpp b/src/Engine/Rendering/ShadowPass.cpp index 0fa2193a..14cfcc09 100644 --- a/src/Engine/Rendering/ShadowPass.cpp +++ b/src/Engine/Rendering/ShadowPass.cpp @@ -254,28 +254,31 @@ void ShadowPass::Draw(RenderScene & scene) glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); glUniform1f(glGetUniformLocation(shaderHandle, "Alpha"), modelJob->Color.a); - /*switch (modelJob->Type) { - case RawModel::MaterialType::SingleTextures: - case RawModel::MaterialType::Basic: - { - glActiveTexture(GL_TEXTURE24); - if (modelJob->DiffuseTexture.size() > 0 && modelJob->DiffuseTexture[0]->Texture != nullptr) { - glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture[0]->Texture->m_Texture); - glUniform2fv(glGetUniformLocation(shaderHandle, "DiffuseUVRepeat"), 1, glm::value_ptr(modelJob->DiffuseTexture[0]->UVRepeat)); + if (directionalLightJob->TextureAlphaShadows) { + switch (modelJob->Type) { + case RawModel::MaterialType::SingleTextures: + case RawModel::MaterialType::Basic: + { + glActiveTexture(GL_TEXTURE24); + if (modelJob->DiffuseTexture.size() > 0 && modelJob->DiffuseTexture[0]->Texture != nullptr) { + glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture[0]->Texture->m_Texture); + glUniform2fv(glGetUniformLocation(shaderHandle, "DiffuseUVRepeat"), 1, glm::value_ptr(modelJob->DiffuseTexture[0]->UVRepeat)); + } + else { + glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture); + glUniform2fv(glGetUniformLocation(shaderHandle, "DiffuseUVRepeat"), 1, glm::value_ptr(glm::vec2(1.0f, 1.0f))); + } + break; } - else { + case RawModel::MaterialType::SplatMapping: + { + glActiveTexture(GL_TEXTURE24); glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture); glUniform2fv(glGetUniformLocation(shaderHandle, "DiffuseUVRepeat"), 1, glm::value_ptr(glm::vec2(1.0f, 1.0f))); + break; + } } - break; } - case RawModel::MaterialType::SplatMapping: - { - glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture); - glUniform2fv(glGetUniformLocation(shaderHandle, "DiffuseUVRepeat"), 1, glm::value_ptr(glm::vec2(1.0f, 1.0f))); - break; - } - }*/ glBindVertexArray(modelJob->Model->VAO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); @@ -288,7 +291,8 @@ void ShadowPass::Draw(RenderScene & scene) } } } - m_ShadowProgram->Unbind(); + glActiveTexture(GL_TEXTURE24); + glDisable(GL_TEXTURE_2D); glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height); m_DepthBuffer.Unbind(); delete state; From 4153a31e3a3fe9b1bb17cba766f76cdeae21fbfb Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Mon, 29 Feb 2016 19:47:24 +0100 Subject: [PATCH 049/130] Fix goof. --- src/Engine/Rendering/ShadowPass.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Engine/Rendering/ShadowPass.cpp b/src/Engine/Rendering/ShadowPass.cpp index 14cfcc09..3fc2c5d0 100644 --- a/src/Engine/Rendering/ShadowPass.cpp +++ b/src/Engine/Rendering/ShadowPass.cpp @@ -291,8 +291,6 @@ void ShadowPass::Draw(RenderScene & scene) } } } - glActiveTexture(GL_TEXTURE24); - glDisable(GL_TEXTURE_2D); glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height); m_DepthBuffer.Unbind(); delete state; From d32a483bb42a1831962676204c48eacee9ae28a9 Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Tue, 1 Mar 2016 13:17:17 +0100 Subject: [PATCH 050/130] remove farclip override --- src/Engine/Editor/EditorSystem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Engine/Editor/EditorSystem.cpp b/src/Engine/Editor/EditorSystem.cpp index 67fad18a..e770c154 100644 --- a/src/Engine/Editor/EditorSystem.cpp +++ b/src/Engine/Editor/EditorSystem.cpp @@ -18,7 +18,7 @@ EditorSystem::EditorSystem(SystemParams params, IRenderer* renderer, RenderFrame m_ActualCamera = m_EditorCamera; m_EditorWorld->AttachComponent(m_EditorCamera.ID, "Transform"); auto cCamera = m_EditorWorld->AttachComponent(m_EditorCamera.ID, "Camera"); - (double&)cCamera["FarClip"] = 300.0; + //(double&)cCamera["FarClip"] = 300.0; m_EditorCameraInputController = new EditorCameraInputController(m_EventBroker, -1); From 1961c16fe27b7b7c82350c26f519a5a038867061 Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Tue, 1 Mar 2016 13:27:52 +0100 Subject: [PATCH 051/130] add weight slider --- src/Engine/Rendering/ShadowPass.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Engine/Rendering/ShadowPass.cpp b/src/Engine/Rendering/ShadowPass.cpp index 3fc2c5d0..7b45e31a 100644 --- a/src/Engine/Rendering/ShadowPass.cpp +++ b/src/Engine/Rendering/ShadowPass.cpp @@ -199,6 +199,7 @@ void ShadowPass::RadiusToLightspace(ShadowFrustum& frustum) void ShadowPass::Draw(RenderScene & scene) { ImGui::DragFloat2("ShadowMapNearFar", m_NearFarPlane, 1.f, -1000.f, 1000.f); + ImGui::DragFloat("ShadowClippingWeight", &m_SplitWeight, 0.001f, 0.f, 1.f); InitializeCameras(scene); UpdateSplitDist(m_shadowFrusta, scene.Camera->NearClip(), scene.Camera->FarClip()); From 7ba5e01560dbb86ff0d258476d5ed6541d2487e9 Mon Sep 17 00:00:00 2001 From: Tleety Date: Tue, 1 Mar 2016 15:37:28 +0100 Subject: [PATCH 052/130] CapturePointArrow component files --- .../Schema/Components/CapturePointArrow.xml | 5 ++++ .../Schema/Components/CapturePointArrow.xsd | 24 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 resources/Schema/Components/CapturePointArrow.xml create mode 100644 resources/Schema/Components/CapturePointArrow.xsd diff --git a/resources/Schema/Components/CapturePointArrow.xml b/resources/Schema/Components/CapturePointArrow.xml new file mode 100644 index 00000000..2943d57b --- /dev/null +++ b/resources/Schema/Components/CapturePointArrow.xml @@ -0,0 +1,5 @@ + + + 0 + + \ No newline at end of file diff --git a/resources/Schema/Components/CapturePointArrow.xsd b/resources/Schema/Components/CapturePointArrow.xsd new file mode 100644 index 00000000..7984fc50 --- /dev/null +++ b/resources/Schema/Components/CapturePointArrow.xsd @@ -0,0 +1,24 @@ + + + + + + + Hud element for tracking capture points. + + + + + + Corresponds to the number on the capture point it should track. + + + + + Specify the team that own this capturePoint. + + + + + + \ No newline at end of file From 5c6a652316bd875acad548965ddf23a681363596 Mon Sep 17 00:00:00 2001 From: William Moberg Date: Tue, 1 Mar 2016 15:53:59 +0100 Subject: [PATCH 053/130] Fixed so unregistered components are ignored instead of crashing the game. --- resources/Schema/Types/Entity.xsd | 2 ++ src/Engine/Core/EntityFileParser.cpp | 16 +++++++++++++--- src/Engine/Core/Util/Logging.cpp | 4 ++-- src/Engine/Editor/EditorSystem.cpp | 7 ++++--- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/resources/Schema/Types/Entity.xsd b/resources/Schema/Types/Entity.xsd index 0965ef89..1c9456ad 100644 --- a/resources/Schema/Types/Entity.xsd +++ b/resources/Schema/Types/Entity.xsd @@ -52,6 +52,8 @@ + + diff --git a/src/Engine/Core/EntityFileParser.cpp b/src/Engine/Core/EntityFileParser.cpp index 23c0c4c4..2beaac14 100644 --- a/src/Engine/Core/EntityFileParser.cpp +++ b/src/Engine/Core/EntityFileParser.cpp @@ -1,6 +1,6 @@ #include "Core/EntityFileParser.h" -EntityFileParser::EntityFileParser(const EntityFile* entityFile) +EntityFileParser::EntityFileParser(const EntityFile* entityFile) : m_EntityFile(entityFile) { m_Handler.SetStartEntityCallback(std::bind(&EntityFileParser::onStartEntity, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); @@ -33,13 +33,20 @@ void EntityFileParser::onStartEntity(EntityID entity, EntityID parent, const std void EntityFileParser::onStartComponent(EntityID entity, const std::string& component) { - EntityID realEntity = m_EntityIDMapper.at(entity); - m_World->AttachComponent(realEntity, component); + if (m_World->GetComponentPools().count(component) != 0) { + EntityID realEntity = m_EntityIDMapper.at(entity); + m_World->AttachComponent(realEntity, component); + } else { + LOG_ERROR("Tried to attach unregistered component \"%s\"! to entity #%i. Ignoring.", component.c_str(), entity); + } //LOG_DEBUG("Attached component of type \"%s\" to entity #%i (%i)", component.c_str(), entity, realEntity); } void EntityFileParser::onStartComponentField(EntityID entity, const std::string& componentType, const std::string& fieldName, const std::map& attributes) { + if (m_World->GetComponentPools().count(componentType) == 0) { + return; + } EntityID realEntity = m_EntityIDMapper.at(entity); ComponentWrapper component = m_World->GetComponent(realEntity, componentType); auto fieldIt = component.Info.Fields.find(fieldName); @@ -61,6 +68,9 @@ void EntityFileParser::onStartComponentField(EntityID entity, const std::string& void EntityFileParser::onFieldData(EntityID entity, const std::string& componentType, const std::string& fieldName, const char* fieldData) { + if (m_World->GetComponentPools().count(componentType) == 0) { + return; + } EntityID realEntity = m_EntityIDMapper.at(entity); ComponentWrapper component = m_World->GetComponent(realEntity, componentType); auto fieldIt = component.Info.Fields.find(fieldName); diff --git a/src/Engine/Core/Util/Logging.cpp b/src/Engine/Core/Util/Logging.cpp index c7612fd8..63a6f380 100644 --- a/src/Engine/Core/Util/Logging.cpp +++ b/src/Engine/Core/Util/Logging.cpp @@ -33,8 +33,8 @@ void _LOG(_LOG_LEVEL logLevel, const char* file, const char* func, unsigned int va_end(args); if (logLevel == LOG_LEVEL_ERROR) { - //std::cerr << file << ":" << line << " " << func << std::endl; - //std::cerr << _LOG_LEVEL_PREFIX[logLevel] << message << std::endl; + std::cerr << file << ":" << line << " " << func << std::endl; + std::cerr << _LOG_LEVEL_PREFIX[logLevel] << message << std::endl; } else { std::cout << _LOG_LEVEL_PREFIX[logLevel] << message << std::endl; } diff --git a/src/Engine/Editor/EditorSystem.cpp b/src/Engine/Editor/EditorSystem.cpp index 4bee1427..47547b8f 100644 --- a/src/Engine/Editor/EditorSystem.cpp +++ b/src/Engine/Editor/EditorSystem.cpp @@ -258,16 +258,17 @@ EntityWrapper EditorSystem::importEntity(EntityWrapper parent, boost::filesystem return EntityWrapper::Invalid; } - try { + //try { auto entityFile = ResourceManager::Load(filePath.string()); EntityFilePreprocessor fpp(entityFile); fpp.RegisterComponents(parent.World); EntityFileParser fp(entityFile); EntityID newEntity = fp.MergeEntities(parent.World, parent.ID); return EntityWrapper(parent.World, newEntity); - } catch (const std::exception&) { + /*} catch (const std::exception& e) { + LOG_ERROR("Failed to import entity \"%s\": \"%s\"", filePath.string().c_str(), e.what()); return EntityWrapper::Invalid; - } + }*/ } void EditorSystem::setWidgetMode(EditorGUI::WidgetMode mode) From b0a66f9e8369801db3b2c322052b29bdb84c2141 Mon Sep 17 00:00:00 2001 From: Tleety Date: Tue, 1 Mar 2016 16:19:59 +0100 Subject: [PATCH 054/130] Components for CapturePoint arrow HUD element and a system skeleton --- .../Game/Systems/CapturePointArrowHUDSystem.h | 20 ++++++++++++++++ resources/Schema/Components.xsd | 1 + .../Schema/Components/CapturePointArrow.xml | 5 ---- .../Schema/Components/CapturePointArrow.xsd | 24 ------------------- .../Components/CapturePointArrowHUD.xml | 4 ++++ .../Components/CapturePointArrowHUD.xsd | 18 ++++++++++++++ resources/Schema/Types/Entity.xsd | 1 + src/Game/Game.cpp | 2 ++ .../Systems/CapturePointArrowHUDSystem.cpp | 13 ++++++++++ 9 files changed, 59 insertions(+), 29 deletions(-) create mode 100644 include/Game/Systems/CapturePointArrowHUDSystem.h delete mode 100644 resources/Schema/Components/CapturePointArrow.xml delete mode 100644 resources/Schema/Components/CapturePointArrow.xsd create mode 100644 resources/Schema/Components/CapturePointArrowHUD.xml create mode 100644 resources/Schema/Components/CapturePointArrowHUD.xsd create mode 100644 src/Game/Systems/CapturePointArrowHUDSystem.cpp diff --git a/include/Game/Systems/CapturePointArrowHUDSystem.h b/include/Game/Systems/CapturePointArrowHUDSystem.h new file mode 100644 index 00000000..30406c3c --- /dev/null +++ b/include/Game/Systems/CapturePointArrowHUDSystem.h @@ -0,0 +1,20 @@ +#ifndef CapturePointArrowHUDSystem_h__ +#define CapturePointArrowHUDSystem_h__ + +#include +#include + +#include "Common.h" +#include "Core/System.h" + +class CapturePointArrowHUDSystem : public ImpureSystem +{ +public: + CapturePointArrowHUDSystem(SystemParams params); + + virtual void Update(double dt) override; + +private: +}; + +#endif \ No newline at end of file diff --git a/resources/Schema/Components.xsd b/resources/Schema/Components.xsd index eb41ed6a..d8ace908 100644 --- a/resources/Schema/Components.xsd +++ b/resources/Schema/Components.xsd @@ -50,4 +50,5 @@ + \ No newline at end of file diff --git a/resources/Schema/Components/CapturePointArrow.xml b/resources/Schema/Components/CapturePointArrow.xml deleted file mode 100644 index 2943d57b..00000000 --- a/resources/Schema/Components/CapturePointArrow.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - 0 - - \ No newline at end of file diff --git a/resources/Schema/Components/CapturePointArrow.xsd b/resources/Schema/Components/CapturePointArrow.xsd deleted file mode 100644 index 7984fc50..00000000 --- a/resources/Schema/Components/CapturePointArrow.xsd +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - Hud element for tracking capture points. - - - - - - Corresponds to the number on the capture point it should track. - - - - - Specify the team that own this capturePoint. - - - - - - \ No newline at end of file diff --git a/resources/Schema/Components/CapturePointArrowHUD.xml b/resources/Schema/Components/CapturePointArrowHUD.xml new file mode 100644 index 00000000..ebe8727a --- /dev/null +++ b/resources/Schema/Components/CapturePointArrowHUD.xml @@ -0,0 +1,4 @@ + + + 0 + \ No newline at end of file diff --git a/resources/Schema/Components/CapturePointArrowHUD.xsd b/resources/Schema/Components/CapturePointArrowHUD.xsd new file mode 100644 index 00000000..d1c035f6 --- /dev/null +++ b/resources/Schema/Components/CapturePointArrowHUD.xsd @@ -0,0 +1,18 @@ + + + + + + HUD element for tracking next capturable Capture Point. + + + + + + Corresponds to the current capturepoint the arrow points Towards + + + + + + \ No newline at end of file diff --git a/resources/Schema/Types/Entity.xsd b/resources/Schema/Types/Entity.xsd index 0965ef89..61d8e520 100644 --- a/resources/Schema/Types/Entity.xsd +++ b/resources/Schema/Types/Entity.xsd @@ -52,6 +52,7 @@ + diff --git a/src/Game/Game.cpp b/src/Game/Game.cpp index 8be665e0..e16d1841 100644 --- a/src/Game/Game.cpp +++ b/src/Game/Game.cpp @@ -25,6 +25,7 @@ #include "Rendering/AnimationSystem.h" #include "Network/MultiplayerSnapshotFilter.h" #include "Game/Systems/AmmunitionHUDSystem.h" +#include "Game/Systems/CapturePointArrowHUDSystem.h" #include "Game/Systems/KillFeedSystem.h" #include "GUI/ButtonSystem.h" #include "GUI/MainMenuSystem.h" @@ -131,6 +132,7 @@ Game::Game(int argc, char* argv[]) m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); + m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel, m_Renderer); m_SystemPipeline->AddSystem(updateOrderLevel, m_Renderer); diff --git a/src/Game/Systems/CapturePointArrowHUDSystem.cpp b/src/Game/Systems/CapturePointArrowHUDSystem.cpp new file mode 100644 index 00000000..e621d90d --- /dev/null +++ b/src/Game/Systems/CapturePointArrowHUDSystem.cpp @@ -0,0 +1,13 @@ +#include "Systems/CapturePointArrowHUDSystem.h" + +CapturePointArrowHUDSystem::CapturePointArrowHUDSystem(SystemParams params) + : System(params) + , ImpureSystem() +{ +} + + +void CapturePointArrowHUDSystem::Update(double dt) +{ + //Logic here +} \ No newline at end of file From 3d4427dd20d0c8ef62aa24d1c1deaaf18c693ea2 Mon Sep 17 00:00:00 2001 From: William Moberg Date: Tue, 1 Mar 2016 17:32:14 +0100 Subject: [PATCH 055/130] Added entity SpectatorCamera that shows respawntime, will activate when explosion effect is deleted. --- include/Game/Systems/PlayerDeathSystem.h | 5 + .../Schema/Entities/NewMapWSpectatorCam.xml | 5356 +++++++++++++++++ resources/Schema/Entities/SpectatorCamera.xml | 40 + resources/Schema/Types/Entity.xsd | 1 + src/Game/Systems/PlayerDeathSystem.cpp | 24 + src/Game/Systems/PlayerSpawnSystem.cpp | 12 + 6 files changed, 5438 insertions(+) create mode 100644 resources/Schema/Entities/NewMapWSpectatorCam.xml create mode 100644 resources/Schema/Entities/SpectatorCamera.xml diff --git a/include/Game/Systems/PlayerDeathSystem.h b/include/Game/Systems/PlayerDeathSystem.h index 112c202e..f32e32df 100644 --- a/include/Game/Systems/PlayerDeathSystem.h +++ b/include/Game/Systems/PlayerDeathSystem.h @@ -11,6 +11,7 @@ #include "Core/EntityFileParser.h" #include "Core/EPlayerDeath.h" +#include "Core/EEntityDeleted.h" class PlayerDeathSystem : public ImpureSystem { @@ -20,8 +21,12 @@ public: virtual void Update(double dt) override; private: + EntityWrapper m_LocalPlayerDeathEffect; + EventRelay m_OnPlayerDeath; bool OnPlayerDeath(Events::PlayerDeath& e); + EventRelay m_EEntityDeleted; + bool OnEntityDeleted(Events::EntityDeleted& e); void createDeathEffect(EntityWrapper player); diff --git a/resources/Schema/Entities/NewMapWSpectatorCam.xml b/resources/Schema/Entities/NewMapWSpectatorCam.xml new file mode 100644 index 00000000..f74a4857 --- /dev/null +++ b/resources/Schema/Entities/NewMapWSpectatorCam.xml @@ -0,0 +1,5356 @@ + + + + + + 3.6027407165331624 + 15 + + + + + + + + + + + + + + + Models/Props/Ground.mesh + + + + + + + + + Models/Props/Highground1.mesh + + + + + + + + + + Models/Props/Highground2.mesh + + + + + + + + + + Models/Props/Highground1.mesh + + + + + + + + + + + + Models/Props/Highground2.mesh + + + + + + + + + + + + Models/Props/Highground3.mesh + + + + + + + + + + Models/Props/Highground4.mesh + + + + + + + + + + Models/Props/Highground5.mesh + + + + + + + + + + + Models/Props/Highground6.mesh + + + + + + + + + + Models/Props/Walls/SciFiWallTop.mesh + + + + + + + + + Models/Props/Walls/SciFiWallBig.mesh + + + + + + + + + + Models/Props/Walls/SciFiWallMedium.mesh + + + + + + + + + + Models/Props/Walls/SciFiWallSmall1.mesh + + + + + + + + + + Models/Props/Walls/SciFiWallSmall2.mesh + + + + + + + + + + Models/Props/Walls/SciFiWallBig.mesh + + + + + + + + + + + + Models/Props/Walls/SciFiWallMedium.mesh + + + + + + + + + + + + Models/Props/Walls/SciFiWallSmall3.mesh + + + + + + + + + + Models/Props/Walls/SciFiWallSmall4.mesh + + + + + + + + + + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar1Blue.mesh + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar1Red.mesh + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar3Blue.mesh + + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar1Blue.mesh + + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar1Red.mesh + + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar3Red.mesh + + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + + + + Models/Props/Walls/MediumWall3.mesh + + + + + + + + + + + + Models/Props/Walls/MediumWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall4.mesh + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + Models/Props/Walls/SmallWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall2.mesh + + + + + + + + + + + + Models/Props/Walls/MediumWall2.mesh + + + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall4.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall4.mesh + + + + + + + + + + + + Models/Props/Walls/SmallWall2.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + + + + Models/Props/Walls/SmallWall2.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall2.mesh + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + + + + Models/Props/Walls/MediumWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + Models/Props/Walls/SmallWall2.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + Models/Props/Walls/SpecialWall1.mesh + + + + + + + + + + + + + + Models/Props/Flora/SpecialRoot.mesh + + + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + Models/Props/Walls/MediumWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall2.mesh + + + + + + + + + + + + Models/Props/Walls/SmallWall2.mesh + + + + + + + + + + + + Models/Props/Walls/MediumWall3.mesh + + + + + + + + + + + + Models/Props/Walls/MediumWall2.mesh + + + + + + + + + + + Models/Props/Walls/MediumWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + Models/Props/Walls/SmallWall4.mesh + + + + + + + + + + + + + + + + Models/Props/Walls/MediumWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/SpecialWall1.mesh + + + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + + Models/Props/Walls/SpecialWall1.mesh + + + + + + + + + + + + Models/Props/Walls/SpecialWall1.mesh + + + + + + + + + + + + + Models/Props/Walls/SpecialWall1.mesh + + + + + + + + + + + + + Models/Props/Walls/SpecialWall1.mesh + + + + + + + + + + + + + Models/Props/Walls/SpecialWall1.mesh + + + + + + + + + + + + + + Models/Props/Walls/SpecialWall1.mesh + + + + + + + + + + + + + + + + + + + + + Models/Props/Bridges/WoodenBridge.mesh + + + + + + + + + + + + + + Models/Props/Bridges/WoodenBridge.mesh + + + + + + + + + + + + + + Models/Props/Bridges/WoodenBridge.mesh + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridge1Red.mesh + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridge1Blue.mesh + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/Pillars/SciFiBridgePillar1.mesh + + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridge1Blue.mesh + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridge1Blue.mesh + + + + + + + + + + + + + Models/Props/Pillars/SciFiBridgePillar1.mesh + + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridge1Red.mesh + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridge1Red.mesh + + + + + + + + + + + + + Models/Props/Bridges/WoodenBridge.mesh + + + + + + + + + + + + + + + + + + + + + Models/Props/Pillars/SciFiBridgePillar1.mesh + + + + + + + + + + + + + + Models/Props/Pillars/SciFiBridgePillar1.mesh + + + + + + + + + + + + + + Models/Props/Walls/MediumWall2.mesh + + + + + + + + + + + Models/Props/Walls/MediumWall2.mesh + + + + + + + + + + + + + + + Models/Props/Walls/MediumWall3.mesh + + + + + + + + + + + Models/Props/Walls/MediumWall3.mesh + + + + + + + + + + + + + + Models/Props/Pillars/SciFiBridgePillar1.mesh + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + Models/Core/UnitPlane.mesh + + true + + + + + + + + + + + + + Models/Core/UnitPlane.mesh + + true + + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + + + Models/Props/Pillars/SciFiBridgePillar1.mesh + + + + + + + + + + + + + + Models/Props/Pillars/SciFiBridgePillar1.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + + + + Models/Props/Flora/TreeLog.mesh + + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + + + Models/Props/Flora/SpecialRoot.mesh + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + + + Models/Props/Flora/SpecialRoot.mesh + + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + + + Models/Props/Flora/AliveBush.mesh + true + + + + + + + + + + + + + + Models/Props/Flora/SpecialRoot.mesh + + + + + + + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + + + + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + + + + + + + + + + Models/Props/CapturePoint/CapturePointBlue.mesh + + + + + + + + + + + + + 4 + + + Models/Core/UnitCylinder.mesh + + true + + + + + + + + + + + + + + + + + + + + + Models/Props/CapturePoint/CapturePointNeutral.mesh + + + + + + + + + + 3 + + + Models/Core/UnitCylinder.mesh + + true + + + + + + + + + + + + + + + + + Models/Props/CapturePoint/CapturePointNeutral.mesh + + + + + + + + + + 2 + + + Models/Core/UnitCylinder.mesh + + true + + + + + + + + + + + + + + + + + Models/Props/CapturePoint/CapturePointNeutral.mesh + + + + + + + + + + 1.5498908015879351 + 1 + + + Models/Core/UnitCylinder.mesh + + true + + + + + + + + + + + + + + + + + Models/Props/CapturePoint/CapturePointRed.mesh + + + + + + + + + + + + + + + Models/Core/UnitCylinder.mesh + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + + + + + + + + + 10 + + + + + + + + + + 10 + + + + + + + + + + + + + 10 + + + + + + + + + + + 10 + + + + + + + + + + + 10 + + + + + + + + + + + 1 + + + + + + + + + + + + + + Schema/Entities/PlayerRed.xml + + + + + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + + + Schema/Entities/Player.xml + + + + + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + + + + + + + + 0.10000000149011612 + + + + Models/Props/PickUps/HealthPickUp.mesh + + + + + + + + + + + + + + + 0.10000000149011612 + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + + + + + + + + + + + + + 0.10000000149011612 + + + + Models/Props/PickUps/HealthPickUp.mesh + + + + + + + + + + + + + + + 0.10000000149011612 + + + + Models/Props/PickUps/HealthPickUp.mesh + + + + + + + + + + + + + + + 0.10000000149011612 + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + + + + + + + + + + + + + 0.10000000149011612 + + + + Models/Props/PickUps/HealthPickUp.mesh + + + + + + + + + + + + + + + 0.10000000149011612 + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + + + + + + + + + + + + + 0.10000000149011612 + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Fonts/DroidSans.ttf,64 + + + + + + + + + + + + + + + + + + + diff --git a/resources/Schema/Entities/SpectatorCamera.xml b/resources/Schema/Entities/SpectatorCamera.xml new file mode 100644 index 00000000..dbfdecf0 --- /dev/null +++ b/resources/Schema/Entities/SpectatorCamera.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + Fonts/DroidSans.ttf,64 + + + + + + + + + + + + + + + + + diff --git a/resources/Schema/Types/Entity.xsd b/resources/Schema/Types/Entity.xsd index 1c9456ad..21605953 100644 --- a/resources/Schema/Types/Entity.xsd +++ b/resources/Schema/Types/Entity.xsd @@ -54,6 +54,7 @@ + diff --git a/src/Game/Systems/PlayerDeathSystem.cpp b/src/Game/Systems/PlayerDeathSystem.cpp index 844d2ed1..f645abe7 100644 --- a/src/Game/Systems/PlayerDeathSystem.cpp +++ b/src/Game/Systems/PlayerDeathSystem.cpp @@ -4,6 +4,7 @@ PlayerDeathSystem::PlayerDeathSystem(SystemParams params) : System(params) { EVENT_SUBSCRIBE_MEMBER(m_OnPlayerDeath, &PlayerDeathSystem::OnPlayerDeath); + EVENT_SUBSCRIBE_MEMBER(m_EEntityDeleted, &PlayerDeathSystem::OnEntityDeleted); } void PlayerDeathSystem::Update(double dt) @@ -59,9 +60,32 @@ void PlayerDeathSystem::createDeathEffect(EntityWrapper player) //camera (with lifetime) behind the player if (player == LocalPlayer) { + m_LocalPlayerDeathEffect = deathEffectEW; auto cam = deathEffectEW.FirstChildByName("Camera"); Events::SetCamera eSetCamera; eSetCamera.CameraEntity = cam; m_EventBroker->Publish(eSetCamera); } } + +bool PlayerDeathSystem::OnEntityDeleted(Events::EntityDeleted& e) +{ + // We only care about when the local players death effect is removed. + if (m_LocalPlayerDeathEffect.ID != e.DeletedEntity) { + return false; + } + // Set the spectator camera as active, if it exists. + auto pool = m_World->GetComponents("CapturePointGameMode"); + if (pool == nullptr || pool->size() == 0) { + return false; + } + ComponentWrapper modeComponent = *pool->begin(); + EntityWrapper theLevel = EntityWrapper(m_LocalPlayerDeathEffect.World, modeComponent.EntityID); + EntityWrapper spectatorCam = theLevel.FirstChildByName("SpectatorCamera"); + if (!spectatorCam.Valid() && spectatorCam.HasComponent("Camera")) { + return false; + } + Events::SetCamera eSetCamera; + eSetCamera.CameraEntity = spectatorCam; + m_EventBroker->Publish(eSetCamera); +} diff --git a/src/Game/Systems/PlayerSpawnSystem.cpp b/src/Game/Systems/PlayerSpawnSystem.cpp index e03a1778..2f6928af 100644 --- a/src/Game/Systems/PlayerSpawnSystem.cpp +++ b/src/Game/Systems/PlayerSpawnSystem.cpp @@ -27,6 +27,18 @@ void PlayerSpawnSystem::Update(double dt) double& timer = (double&)modeComponent["RespawnTime"]; timer += dt; double maxRespawnTime = m_DbgConfigForceRespawn ? m_ForcedRespawnTime : (double)modeComponent["MaxRespawnTime"]; + EntityWrapper theLevel = EntityWrapper(m_World, modeComponent.EntityID); + EntityWrapper spectatorCam = theLevel.FirstChildByName("SpectatorCamera"); + if (spectatorCam.Valid()) { + EntityWrapper HUD = spectatorCam.FirstChildByName("SpectatorHUD"); + if (HUD.Valid()) { + EntityWrapper respawnTimer = spectatorCam.FirstChildByName("RespawnTimer"); + if (respawnTimer.Valid()) { + //Update respawn time in the HUD element. + respawnTimer["Text"]["Content"] = "Time to respawn: " + std::to_string(1 + (int)(maxRespawnTime - timer)); + } + } + } if (timer < maxRespawnTime) { return; } From 5a8261453e33dbec1917f300d66d7a9fcc3f9701 Mon Sep 17 00:00:00 2001 From: William Moberg Date: Tue, 1 Mar 2016 17:40:42 +0100 Subject: [PATCH 056/130] Eliminated some SAXParsing errors from our console output. --- resources/Schema/Types/Entity.xsd | 3 +++ 1 file changed, 3 insertions(+) diff --git a/resources/Schema/Types/Entity.xsd b/resources/Schema/Types/Entity.xsd index 21605953..79ac0f1b 100644 --- a/resources/Schema/Types/Entity.xsd +++ b/resources/Schema/Types/Entity.xsd @@ -55,6 +55,9 @@ + + + From 1ae2f3f5f35e16d8cebf00421354a9eb0f3cb227 Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Tue, 1 Mar 2016 19:10:13 +0100 Subject: [PATCH 057/130] Begin clean-up --- include/Engine/Rendering/DirectionalLightJob.h | 1 - include/Engine/Rendering/FrameBuffer.h | 14 -------------- include/Engine/Rendering/ShadowPass.h | 2 +- resources/Schema/Components/DirectionalLight.xml | 1 - resources/Schema/Components/DirectionalLight.xsd | 1 - src/Engine/Rendering/FrameBuffer.cpp | 15 --------------- src/Engine/Rendering/ShadowPass.cpp | 2 +- 7 files changed, 2 insertions(+), 34 deletions(-) diff --git a/include/Engine/Rendering/DirectionalLightJob.h b/include/Engine/Rendering/DirectionalLightJob.h index 65d477d1..96b2ec9c 100644 --- a/include/Engine/Rendering/DirectionalLightJob.h +++ b/include/Engine/Rendering/DirectionalLightJob.h @@ -19,7 +19,6 @@ struct DirectionalLightJob : RenderJob Direction = glm::vec4(0,0,-1,0) * glm::inverse(Orientation); Color = (glm::vec4)directionalLightComponent["Color"]; Intensity = (double)directionalLightComponent["Intensity"]; - //TextureAlphaShadows = (bool)directionalLightComponent["TextureAlphaShadows"]; }; glm::quat Orientation; diff --git a/include/Engine/Rendering/FrameBuffer.h b/include/Engine/Rendering/FrameBuffer.h index 325fbe3b..cf63b6c6 100644 --- a/include/Engine/Rendering/FrameBuffer.h +++ b/include/Engine/Rendering/FrameBuffer.h @@ -8,12 +8,10 @@ class BufferResource { public: BufferResource(GLuint* resourceHandle, GLenum resourceType, GLenum attachment); - BufferResource(GLuint* resourceHandle, GLenum resourceType, GLenum attachment, GLuint layers); GLuint* m_ResourceHandle; GLenum m_ResourceType; GLenum m_Attachment; - GLuint m_Layers; private: }; @@ -24,9 +22,6 @@ class ResourceType : public BufferResource public: ResourceType(GLuint* resourceHandle, GLenum attachment) : BufferResource(resourceHandle, RESOURCETYPE, attachment) { } - - ResourceType(GLuint* resourceHandle, GLenum attachment, GLuint layers) - : BufferResource(resourceHandle, RESOURCETYPE, attachment, layers) { } }; class Texture2D : public ResourceType @@ -48,15 +43,6 @@ public: ~RenderBuffer(); }; -class Texture2DArray : public ResourceType -{ -public: - Texture2DArray(GLuint* resourceHandle, GLenum attachment, GLuint layers) - : ResourceType(resourceHandle, attachment, layers) { }; - - ~Texture2DArray(); -}; - class FrameBuffer { public: diff --git a/include/Engine/Rendering/ShadowPass.h b/include/Engine/Rendering/ShadowPass.h index 3f506cb7..372ba6f2 100644 --- a/include/Engine/Rendering/ShadowPass.h +++ b/include/Engine/Rendering/ShadowPass.h @@ -41,7 +41,7 @@ public: GLuint DepthMap() const { return m_DepthMap; } std::array LightP() const { return m_LightProjection; } std::array LightV() const { return m_LightView; } - std::array FarDistance() const { return{ m_shadowFrusta[0].FarClip, m_shadowFrusta[1].FarClip, m_shadowFrusta[2].FarClip, m_shadowFrusta[3].FarClip }; } + std::array FarDistance() const { std::array f; for (int i = 0; i < MAX_SPLITS; i++) f[i] = m_shadowFrusta[i].FarClip; return f; } int CurrentNrOfSplits() const { return m_CurrentNrOfSplits; } void SetSplitWeight(float split_weight) { m_SplitWeight = split_weight; }; diff --git a/resources/Schema/Components/DirectionalLight.xml b/resources/Schema/Components/DirectionalLight.xml index a4b22985..7f777ef8 100644 --- a/resources/Schema/Components/DirectionalLight.xml +++ b/resources/Schema/Components/DirectionalLight.xml @@ -2,6 +2,5 @@ 0.8 - true \ No newline at end of file diff --git a/resources/Schema/Components/DirectionalLight.xsd b/resources/Schema/Components/DirectionalLight.xsd index 692d9677..a14248a8 100644 --- a/resources/Schema/Components/DirectionalLight.xsd +++ b/resources/Schema/Components/DirectionalLight.xsd @@ -9,7 +9,6 @@ - diff --git a/src/Engine/Rendering/FrameBuffer.cpp b/src/Engine/Rendering/FrameBuffer.cpp index 167de142..7c86a7e2 100644 --- a/src/Engine/Rendering/FrameBuffer.cpp +++ b/src/Engine/Rendering/FrameBuffer.cpp @@ -9,14 +9,6 @@ BufferResource::BufferResource(GLuint* resourceHandle, GLenum resourceType, GLen m_Attachment = attachment; } -BufferResource::BufferResource(GLuint* resourceHandle, GLenum resourceType, GLenum attachment, GLuint layers) -{ - m_ResourceHandle = resourceHandle; - m_ResourceType = resourceType; - m_Attachment = attachment; - m_Layers = layers; -} - Texture2D::~Texture2D() { if (m_ResourceHandle != 0) { @@ -24,13 +16,6 @@ Texture2D::~Texture2D() } } -Texture2DArray::~Texture2DArray() -{ - if (m_ResourceHandle != 0) { - glDeleteTextures(1, m_ResourceHandle); - } -} - RenderBuffer::~RenderBuffer() { if (m_ResourceHandle != 0) { diff --git a/src/Engine/Rendering/ShadowPass.cpp b/src/Engine/Rendering/ShadowPass.cpp index 7b45e31a..d7741dff 100644 --- a/src/Engine/Rendering/ShadowPass.cpp +++ b/src/Engine/Rendering/ShadowPass.cpp @@ -133,7 +133,7 @@ void ShadowPass::InitializeFrameBuffers() glTexParameterfv(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BORDER_COLOR, glm::vec4(1.f).data); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); - m_DepthBuffer.AddResource(std::shared_ptr(new Texture2DArray(&m_DepthMap, GL_DEPTH_ATTACHMENT, m_CurrentNrOfSplits))); + m_DepthBuffer.AddResource(std::shared_ptr(new Texture2D(&m_DepthMap, GL_DEPTH_ATTACHMENT))); m_DepthBuffer.Generate(); GLERROR("depthMap failed END"); From 6281e200005fb311687a517d19c14cc8e5b6bee1 Mon Sep 17 00:00:00 2001 From: Tleety Date: Tue, 1 Mar 2016 20:31:09 +0100 Subject: [PATCH 058/130] Arrow should now track the CapturePoint specified in the Component. --- .../Game/Systems/CapturePointArrowHUDSystem.h | 3 + include/Game/Systems/CapturePointHUDSystem.h | 2 +- resources/Schema/Entities/PlayerRed.xml | 58 ++++--- .../Schema/Entities/QualityAssurance.xml | 154 +++++++++++++----- .../Systems/CapturePointArrowHUDSystem.cpp | 105 +++++++++++- 5 files changed, 261 insertions(+), 61 deletions(-) diff --git a/include/Game/Systems/CapturePointArrowHUDSystem.h b/include/Game/Systems/CapturePointArrowHUDSystem.h index 30406c3c..4c197f02 100644 --- a/include/Game/Systems/CapturePointArrowHUDSystem.h +++ b/include/Game/Systems/CapturePointArrowHUDSystem.h @@ -3,9 +3,12 @@ #include #include +#include #include "Common.h" #include "Core/System.h" +#include "Core/Transform.h" + class CapturePointArrowHUDSystem : public ImpureSystem { diff --git a/include/Game/Systems/CapturePointHUDSystem.h b/include/Game/Systems/CapturePointHUDSystem.h index 41db0c12..53ca9b73 100644 --- a/include/Game/Systems/CapturePointHUDSystem.h +++ b/include/Game/Systems/CapturePointHUDSystem.h @@ -7,7 +7,7 @@ #include "Common.h" #include "Core/System.h" -#include "Engine/Collision/ETrigger.h" +#include "Collision/ETrigger.h" class CapturePointHUDSystem : public ImpureSystem { diff --git a/resources/Schema/Entities/PlayerRed.xml b/resources/Schema/Entities/PlayerRed.xml index 3cf17558..8982f58d 100644 --- a/resources/Schema/Entities/PlayerRed.xml +++ b/resources/Schema/Entities/PlayerRed.xml @@ -13,7 +13,7 @@ - 1.6944730461160304 + 326.69883589440087 @@ -30,7 +30,7 @@ - + @@ -193,7 +193,6 @@ 3 - 0.80222018197612788 @@ -228,6 +227,7 @@ 4 + 1 @@ -283,7 +283,7 @@ Textures/Core/UnitHexagon.png - + @@ -294,7 +294,8 @@ - + 1 + Textures/Core/UnitHexagon_Rotated.png @@ -303,7 +304,7 @@ - + @@ -372,7 +373,7 @@ Idle - 0.67172915251515519 + 0.20909021680133577 1 @@ -386,30 +387,44 @@ + + DefenderWeapon + Schema/Entities/DefenderWeaponViewRed.xml - - DefenderWeapon - + + AssaultWeapon + Schema/Entities/AssaultWeaponView.xml - - AssaultWeapon - + + + + + Models/Weapons/Blue/AssaultWeaponBlue.mesh + + + + + + + + + @@ -430,6 +445,7 @@ Idle + 0.22069183859343156 1 @@ -449,31 +465,31 @@ - - Schema/Entities/DefenderWeaponWorldRed.xml - - DefenderWeapon + + Schema/Entities/DefenderWeaponWorldRed.xml + + - - Schema/Entities/AssaultWeaponWorld.xml - - AssaultWeapon + + Schema/Entities/AssaultWeaponWorld.xml + + diff --git a/resources/Schema/Entities/QualityAssurance.xml b/resources/Schema/Entities/QualityAssurance.xml index 0aa2fbe7..04cc288a 100644 --- a/resources/Schema/Entities/QualityAssurance.xml +++ b/resources/Schema/Entities/QualityAssurance.xml @@ -2,6 +2,9 @@ + + 4.7473226580121377 + @@ -40,7 +43,7 @@ - + @@ -81,19 +84,19 @@ + + 1 + + 0.80000001192092896 Models/Widgets/Lights/DirectionalLightWidget.mesh - - 1 - - - + @@ -108,7 +111,11 @@ - + + + + + Models/Characters/Assault/AssaultAnimated.mesh @@ -120,7 +127,11 @@ - + + + + + Models/Characters/Assault/AssaultAnimated.mesh @@ -168,13 +179,17 @@ - + - + + + + + Models/Characters/Assault/AssaultAnimated.mesh @@ -213,7 +228,7 @@ - + @@ -277,7 +292,7 @@ - + @@ -309,7 +324,7 @@ - + @@ -659,7 +674,7 @@ - + @@ -706,7 +721,7 @@ - + @@ -766,7 +781,7 @@ - + @@ -813,7 +828,7 @@ - + @@ -859,7 +874,7 @@ - + @@ -906,7 +921,7 @@ - + @@ -953,7 +968,7 @@ - + @@ -1013,6 +1028,7 @@ 15 + Models/Core/UnitCube.mesh @@ -1027,7 +1043,6 @@ - @@ -1063,6 +1078,7 @@ 1 + Models/Core/UnitCube.mesh @@ -1073,7 +1089,6 @@ - @@ -1107,6 +1122,7 @@ 2 + Models/Core/UnitCube.mesh @@ -1117,7 +1133,6 @@ - @@ -1153,6 +1168,7 @@ 3 + Models/Core/UnitCube.mesh @@ -1163,7 +1179,6 @@ - @@ -1203,6 +1218,7 @@ -15 4 + Models/Core/UnitCube.mesh @@ -1217,7 +1233,6 @@ - @@ -1367,7 +1382,7 @@ - + @@ -1376,7 +1391,7 @@ true - 0.8256214817261025 + 2.5396116058983438 3.7999999523162842 true @@ -1423,7 +1438,7 @@ - + @@ -1432,7 +1447,7 @@ - 1.8641349174045843 + 1.5396208215609732 Models/Characters/Assault/AssaultTPose.mesh @@ -1475,18 +1490,22 @@ - + - + + + + + true - 1.8641349174045843 + 1.5396208215609732 true @@ -1531,7 +1550,7 @@ - + @@ -1541,7 +1560,7 @@ true - 1.2301962937648341 + 4.4522528839264339 10 3 @@ -1589,7 +1608,7 @@ - + @@ -1599,7 +1618,7 @@ true - 3.4214855659573402 + 3.2362842141074992 true 5 true @@ -1690,6 +1709,7 @@ 5 + @@ -1712,6 +1732,7 @@ + Fonts/DroidSans.ttf,100 @@ -1780,7 +1801,7 @@ true - 0.8256214817261025 + 2.5396116058983438 3.7999999523162842 true @@ -1823,7 +1844,11 @@ - + + + + + @@ -1925,6 +1950,7 @@ Textures/Props/FoliageDiff.png + @@ -1934,6 +1960,7 @@ Textures/Props/FoliageDiff.png + @@ -1954,6 +1981,7 @@ Textures/Core/UnitHexagon.png + @@ -1971,6 +1999,7 @@ Textures/Core/UnitHexagon_Rotated.png + @@ -1986,6 +2015,7 @@ Textures/Core/UnitHexagon.png + @@ -2003,6 +2033,7 @@ Textures/Core/UnitHexagon_Rotated.png + @@ -2018,6 +2049,7 @@ Textures/Core/UnitHexagon.png + @@ -2036,6 +2068,7 @@ Textures/Core/UnitHexagon_Rotated.png + @@ -2051,6 +2084,7 @@ Textures/Core/UnitHexagon.png + @@ -2068,6 +2102,7 @@ Textures/Core/UnitHexagon_Rotated.png + @@ -2083,6 +2118,7 @@ Textures/Core/UnitHexagon.png + @@ -2099,6 +2135,7 @@ Textures/Core/UnitHexagon_Rotated.png + @@ -2167,6 +2204,7 @@ Textures/Core/ErrorTexture.png + @@ -2178,6 +2216,7 @@ Textures/Core/White.png + @@ -2206,6 +2245,7 @@ Textures/Core/White.png + @@ -2234,6 +2274,7 @@ Textures/Core/White.png + @@ -2262,6 +2303,7 @@ Textures/Core/White.png + @@ -2290,6 +2332,7 @@ Textures/Core/White.png + @@ -2331,6 +2374,7 @@ Textures/Core/ErrorTexture.png + @@ -2342,6 +2386,7 @@ Textures/Core/White.png + @@ -2370,6 +2415,7 @@ Textures/Core/White.png + @@ -2398,6 +2444,7 @@ Textures/Core/White.png + @@ -2426,6 +2473,7 @@ Textures/Core/White.png + @@ -2482,6 +2530,36 @@ + + + + + + + + + + + + 2 + + + Models/Weapons/Blue/AssaultWeaponBlue.mesh + + + + + + + + + + + + + + + diff --git a/src/Game/Systems/CapturePointArrowHUDSystem.cpp b/src/Game/Systems/CapturePointArrowHUDSystem.cpp index e621d90d..92c6ec0a 100644 --- a/src/Game/Systems/CapturePointArrowHUDSystem.cpp +++ b/src/Game/Systems/CapturePointArrowHUDSystem.cpp @@ -9,5 +9,108 @@ CapturePointArrowHUDSystem::CapturePointArrowHUDSystem(SystemParams params) void CapturePointArrowHUDSystem::Update(double dt) { - //Logic here + + bool LoadCheck = true; + int redTeam; + int blueTeam; + int spectatorTeam; + + //Get list for all CapturePointArrowHUDComponents + auto ArrowHUDs = m_World->GetComponents("CapturePointArrowHUD"); + auto CapturePoints = m_World->GetComponents("CapturePoint"); + if(ArrowHUDs == nullptr) { + return; + } + + for(auto& cArrowHUD : *ArrowHUDs) { + //Get what team the current arrow corresponds to + EntityWrapper ArrowEntity = EntityWrapper(m_World, cArrowHUD.EntityID); + EntityWrapper teamEntity = ArrowEntity.FirstParentWithComponent("Team"); + if (!teamEntity.Valid()) { + continue; + } + auto cTeam = teamEntity["Team"]; + int currentTeam = (int)cTeam["Team"]; + + if (LoadCheck) { + redTeam = (int)cTeam["Team"].Enum("Red"); + blueTeam = (int)cTeam["Team"].Enum("Blue"); + spectatorTeam = (int)cTeam["Team"].Enum("Spectator"); + LoadCheck = false; + } + + //if red team, get red team next point, otherwise blue team next point. + //Untill this is awailable we will just use the hardcoded value in the component. + //This will also give us a position, so we wont need to loop through all capturePoints. + glm::vec3 pos; + int target = cArrowHUD["CurrentTarget"]; + for(auto& cCP : *CapturePoints) { + if((int)cCP["CapturePointNumber"] == target) { + EntityWrapper CPEntity = EntityWrapper(m_World, cCP.EntityID); + pos = Transform::AbsolutePosition(CPEntity); + break; + } + } + glm::vec3& arrowOri = ArrowEntity["Transform"]["Orientation"]; + glm::vec3 lookVector = glm::normalize(Transform::AbsolutePosition(ArrowEntity) - pos); //Maybe should be player instead + float pitch = std::asin(-lookVector.y); + float yaw = std::atan2(lookVector.x, lookVector.z); + arrowOri.x = pitch; + arrowOri.y = yaw; + arrowOri.z = 0.f; + EntityWrapper parent = ArrowEntity.Parent(); + if (parent.Valid()) { + arrowOri -= Transform::AbsoluteOrientationEuler(parent); + } + } + + /* + bool LoadCheck = true; + int redTeam; + int blueTeam; + int spectatorTeam; + + auto CapturePointHUDElements = m_World->GetComponents("CapturePointHUD"); + auto CapturePoints = m_World->GetComponents("CapturePoint"); + if (CapturePointHUDElements == nullptr) { + return; + } + + if (!CapturePointHUDElements) { + return; + } + + for (auto& cCapturePointHUD : *CapturePointHUDElements) { + int HUD_ID = cCapturePointHUD["CapturePointNumber"]; + EntityWrapper entityHUD = EntityWrapper(m_World, cCapturePointHUD.EntityID); + EntityWrapper entityHUDparent = entityHUD.Parent(); + + for (auto& cCapturePoint : *CapturePoints) { + EntityWrapper entityCP = EntityWrapper(m_World, cCapturePoint.EntityID); + + //Check if the HUD corresponds to the Capture Point Number + if (HUD_ID == (int)entityCP["CapturePoint"]["CapturePointNumber"]) { + ComponentWrapper& teamComponent = entityCP["Team"]; + if (LoadCheck) { + redTeam = (int)teamComponent["Team"].Enum("Red"); + blueTeam = (int)teamComponent["Team"].Enum("Blue"); + spectatorTeam = (int)teamComponent["Team"].Enum("Spectator"); + LoadCheck = false; + } + //Color hud with team color + auto capturePointTeam = (int)teamComponent["Team"]; + entityHUDparent["Sprite"]["Color"] = capturePointTeam == blueTeam ? glm::vec4(0, 0.2f, 1, 0.7f) : capturePointTeam == redTeam ? glm::vec4(1, 0.0f, 0, 0.7f) : glm::vec4(1, 1, 1, 0.3f); + + //Progress is scaled with time + double currentCaptureTime = (double)entityCP["CapturePoint"]["CaptureTimer"]; + double progress = glm::abs(currentCaptureTime)/15.0; + int currentCapturingTeam = currentCaptureTime > 0 ? redTeam : currentCaptureTime < 0 ? blueTeam : spectatorTeam; + ((glm::vec3&)entityHUD["Transform"]["Orientation"]).z = currentCapturingTeam == redTeam ? glm::half_pi()+glm::pi() : glm::half_pi(); + glm::vec4 fillColor = currentCapturingTeam == redTeam ? glm::vec4(1, 0.f, 0, 0.7f) : glm::vec4(0, 0.2f, 1, 0.7f); + entityHUD["Fill"]["Color"] = fillColor; + entityHUD["Fill"]["Percentage"] = progress; + } + } + } + */ } \ No newline at end of file From ab40fa715b8d47681ab58561c95b4aa02bf94391 Mon Sep 17 00:00:00 2001 From: Tleety Date: Tue, 1 Mar 2016 21:57:30 +0100 Subject: [PATCH 059/130] The arrow should now track CapturePoints correctly at start and when they are captured. --- .../Game/Systems/CapturePointArrowHUDSystem.h | 7 + .../Systems/CapturePointArrowHUDSystem.cpp | 131 ++++++++++-------- 2 files changed, 82 insertions(+), 56 deletions(-) diff --git a/include/Game/Systems/CapturePointArrowHUDSystem.h b/include/Game/Systems/CapturePointArrowHUDSystem.h index 4c197f02..26462879 100644 --- a/include/Game/Systems/CapturePointArrowHUDSystem.h +++ b/include/Game/Systems/CapturePointArrowHUDSystem.h @@ -8,6 +8,7 @@ #include "Common.h" #include "Core/System.h" #include "Core/Transform.h" +#include "Core/ECaptured.h" class CapturePointArrowHUDSystem : public ImpureSystem @@ -18,6 +19,12 @@ public: virtual void Update(double dt) override; private: + EventRelay m_ECapturedEvent; + bool OnCapturePointCaptured(Events::Captured& e); + + bool m_InitialtargetsSet = false; + glm::vec3 m_RedTeamCurrentTarget; + glm::vec3 m_BlueTeamCurrentTarget; }; #endif \ No newline at end of file diff --git a/src/Game/Systems/CapturePointArrowHUDSystem.cpp b/src/Game/Systems/CapturePointArrowHUDSystem.cpp index 92c6ec0a..ee2254c7 100644 --- a/src/Game/Systems/CapturePointArrowHUDSystem.cpp +++ b/src/Game/Systems/CapturePointArrowHUDSystem.cpp @@ -4,12 +4,12 @@ CapturePointArrowHUDSystem::CapturePointArrowHUDSystem(SystemParams params) : System(params) , ImpureSystem() { + EVENT_SUBSCRIBE_MEMBER(m_ECapturedEvent, &CapturePointArrowHUDSystem::OnCapturePointCaptured); } void CapturePointArrowHUDSystem::Update(double dt) { - bool LoadCheck = true; int redTeam; int blueTeam; @@ -25,11 +25,13 @@ void CapturePointArrowHUDSystem::Update(double dt) for(auto& cArrowHUD : *ArrowHUDs) { //Get what team the current arrow corresponds to EntityWrapper ArrowEntity = EntityWrapper(m_World, cArrowHUD.EntityID); - EntityWrapper teamEntity = ArrowEntity.FirstParentWithComponent("Team"); - if (!teamEntity.Valid()) { + if (!ArrowEntity.Valid()) { continue; } - auto cTeam = teamEntity["Team"]; + if(!ArrowEntity.HasComponent("Team")) { + continue; + } + auto cTeam = ArrowEntity["Team"]; int currentTeam = (int)cTeam["Team"]; if (LoadCheck) { @@ -37,20 +39,60 @@ void CapturePointArrowHUDSystem::Update(double dt) blueTeam = (int)cTeam["Team"].Enum("Blue"); spectatorTeam = (int)cTeam["Team"].Enum("Spectator"); LoadCheck = false; + + + if (!m_InitialtargetsSet) { + glm::vec3 target1, target2; + EntityWrapper home1, home2; + + for (auto& cCP : *CapturePoints) { + auto homePointTeam = (int)cCP["HomePointForTeam"]; + auto CPID = (int)cCP["CapturePointNumber"]; + + if(CPID == 0) { + //Home point for one team + home1 = EntityWrapper(m_World, cCP.EntityID); + } else if (CPID == 1) { + //First target for one team, so save it for later use. + target1 = Transform::AbsolutePosition(EntityWrapper(m_World, cCP.EntityID)); + } else if (CPID == 3) { + //First target for one team, so save it for later use. + target2 = Transform::AbsolutePosition(EntityWrapper(m_World, cCP.EntityID)); + } else if (CPID == 4) { + //Home point for one team + home2 = EntityWrapper(m_World, cCP.EntityID); + } + } + //Check what team is the owner of Home1 and set their target to the next capturepoint + if((int)home1["CapturePoint"]["HomePointForTeam"] == redTeam) { + m_RedTeamCurrentTarget = target1; + } else if ((int)home1["CapturePoint"]["HomePointForTeam"] == blueTeam) { + m_BlueTeamCurrentTarget = target1; + } + + //Check what team is the owner of Home2 and set their target to the next capturepoint + if ((int)home2["CapturePoint"]["HomePointForTeam"] == redTeam) { + m_RedTeamCurrentTarget = target2; + } else if ((int)home2["CapturePoint"]["HomePointForTeam"] == blueTeam) { + m_BlueTeamCurrentTarget = target2; + } + } + + } //if red team, get red team next point, otherwise blue team next point. //Untill this is awailable we will just use the hardcoded value in the component. //This will also give us a position, so we wont need to loop through all capturePoints. glm::vec3 pos; - int target = cArrowHUD["CurrentTarget"]; - for(auto& cCP : *CapturePoints) { - if((int)cCP["CapturePointNumber"] == target) { - EntityWrapper CPEntity = EntityWrapper(m_World, cCP.EntityID); - pos = Transform::AbsolutePosition(CPEntity); - break; - } + if(currentTeam == redTeam) { + pos = m_RedTeamCurrentTarget; + } else if (currentTeam == blueTeam) { + pos = m_BlueTeamCurrentTarget; } + + pos = currentTeam == redTeam ? m_RedTeamCurrentTarget : currentTeam == blueTeam ? m_BlueTeamCurrentTarget : glm::vec3(0.f); + glm::vec3& arrowOri = ArrowEntity["Transform"]["Orientation"]; glm::vec3 lookVector = glm::normalize(Transform::AbsolutePosition(ArrowEntity) - pos); //Maybe should be player instead float pitch = std::asin(-lookVector.y); @@ -63,54 +105,31 @@ void CapturePointArrowHUDSystem::Update(double dt) arrowOri -= Transform::AbsoluteOrientationEuler(parent); } } +} - /* - bool LoadCheck = true; - int redTeam; - int blueTeam; - int spectatorTeam; - - auto CapturePointHUDElements = m_World->GetComponents("CapturePointHUD"); - auto CapturePoints = m_World->GetComponents("CapturePoint"); - if (CapturePointHUDElements == nullptr) { - return; +bool CapturePointArrowHUDSystem::OnCapturePointCaptured(Events::Captured& e) +{ + if (!e.NextCapturePoint.HasComponent("Team")) + { + return 0; } - if (!CapturePointHUDElements) { - return; + auto cTeam = e.NextCapturePoint["Team"]; + + int redTeam = (int)cTeam["Team"].Enum("Red"); + int blueTeam = (int)cTeam["Team"].Enum("Blue"); + int spectatorTeam = (int)cTeam["Team"].Enum("Spectator"); + int target = -1; + + if (e.NextCapturePoint.HasComponent("CapturePoint")) { + target = (int)e.NextCapturePoint["CapturePoint"]["CapturePointNumber"]; + } else { + return 0; } - for (auto& cCapturePointHUD : *CapturePointHUDElements) { - int HUD_ID = cCapturePointHUD["CapturePointNumber"]; - EntityWrapper entityHUD = EntityWrapper(m_World, cCapturePointHUD.EntityID); - EntityWrapper entityHUDparent = entityHUD.Parent(); - - for (auto& cCapturePoint : *CapturePoints) { - EntityWrapper entityCP = EntityWrapper(m_World, cCapturePoint.EntityID); - - //Check if the HUD corresponds to the Capture Point Number - if (HUD_ID == (int)entityCP["CapturePoint"]["CapturePointNumber"]) { - ComponentWrapper& teamComponent = entityCP["Team"]; - if (LoadCheck) { - redTeam = (int)teamComponent["Team"].Enum("Red"); - blueTeam = (int)teamComponent["Team"].Enum("Blue"); - spectatorTeam = (int)teamComponent["Team"].Enum("Spectator"); - LoadCheck = false; - } - //Color hud with team color - auto capturePointTeam = (int)teamComponent["Team"]; - entityHUDparent["Sprite"]["Color"] = capturePointTeam == blueTeam ? glm::vec4(0, 0.2f, 1, 0.7f) : capturePointTeam == redTeam ? glm::vec4(1, 0.0f, 0, 0.7f) : glm::vec4(1, 1, 1, 0.3f); - - //Progress is scaled with time - double currentCaptureTime = (double)entityCP["CapturePoint"]["CaptureTimer"]; - double progress = glm::abs(currentCaptureTime)/15.0; - int currentCapturingTeam = currentCaptureTime > 0 ? redTeam : currentCaptureTime < 0 ? blueTeam : spectatorTeam; - ((glm::vec3&)entityHUD["Transform"]["Orientation"]).z = currentCapturingTeam == redTeam ? glm::half_pi()+glm::pi() : glm::half_pi(); - glm::vec4 fillColor = currentCapturingTeam == redTeam ? glm::vec4(1, 0.f, 0, 0.7f) : glm::vec4(0, 0.2f, 1, 0.7f); - entityHUD["Fill"]["Color"] = fillColor; - entityHUD["Fill"]["Percentage"] = progress; - } - } + if(e.TeamNumberThatCapturedCapturePoint == redTeam) { + m_RedTeamCurrentTarget = Transform::AbsolutePosition(e.NextCapturePoint); + } else if (e.TeamNumberThatCapturedCapturePoint == blueTeam) { + m_BlueTeamCurrentTarget = Transform::AbsolutePosition(e.NextCapturePoint);; } - */ -} \ No newline at end of file +} From 799990f44dbfd50b04a074d54d9c078efa49fb9a Mon Sep 17 00:00:00 2001 From: Tleety Date: Tue, 1 Mar 2016 22:54:13 +0100 Subject: [PATCH 060/130] Next CP indicator should now be fully working. --- assets | 2 +- resources/Schema/Entities/NewMap2version2.xml | 4690 +++++++++++++++++ .../Schema/Entities/NewMap2version3NEW.xml | 4612 ++++++++++++++++ resources/Schema/Entities/Player.xml | 61 +- resources/Schema/Entities/PlayerRed.xml | 9 +- .../Systems/CapturePointArrowHUDSystem.cpp | 8 +- 6 files changed, 9354 insertions(+), 28 deletions(-) create mode 100644 resources/Schema/Entities/NewMap2version2.xml create mode 100644 resources/Schema/Entities/NewMap2version3NEW.xml diff --git a/assets b/assets index 10a61165..72530423 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 10a611659ddaadfea6a560e707d395834855a979 +Subproject commit 72530423ad3744341f42cbfdcba18295a2cfac90 diff --git a/resources/Schema/Entities/NewMap2version2.xml b/resources/Schema/Entities/NewMap2version2.xml new file mode 100644 index 00000000..fcb81666 --- /dev/null +++ b/resources/Schema/Entities/NewMap2version2.xml @@ -0,0 +1,4690 @@ + + + + + + + + + + + + + + + + + + Models/Props/GroundTest.mesh + + + + + + + + + Models/Props/Walls/SciFiWallTop.mesh + + + + + + + + + Models/Props/Walls/SciFiWallBig.mesh + true + + + + + + + + + + Models/Props/Walls/SciFiWallMedium.mesh + + + + + + + + + + Models/Props/Walls/SciFiWallSmall1.mesh + + + + + + + + + + Models/Props/Walls/SciFiWallSmall2.mesh + + + + + + + + + + Models/Props/Walls/SciFiWallBig.mesh + + + + + + + + + + + + Models/Props/Walls/SciFiWallMedium.mesh + + + + + + + + + + + + Models/Props/Walls/SciFiWallSmall3.mesh + + + + + + + + + + Models/Props/Walls/SciFiWallSmall4.mesh + + + + + + + + + + + + Models/Props/Highground1.mesh + + + + + + + + + + Models/Props/Highground2.mesh + + + + + + + + + + + Models/Props/Highground3.mesh + + + + + + + + + + + Models/Props/Highground4.mesh + + + + + + + + + + + Models/Props/Highground5.mesh + + + + + + + + + + Models/Props/Highground6.mesh + + + + + + + + + + + Models/Props/Highground7.mesh + + + + + + + + + + + + + Models/Props/Highground8.mesh + + + + + + + + + + + + + Models/Props/Highground9.mesh + + + + + + + + + + + + + Models/Props/Highground10.mesh + + + + + + + + + + + + + Models/Props/Highground6.mesh + + + + + + + + + + + + + Models/Props/Highground1.mesh + + + + + + + + + + + + Models/Props/Highground2.mesh + + + + + + + + + + + + + Models/Props/Highground3.mesh + + + + + + + + + + + + + Models/Props/Highground4.mesh + + + + + + + + + + + + + Models/Props/Highground5.mesh + + + + + + + + + + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar1Blue.mesh + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar1Red.mesh + + + + + + + + + + + + + 4 + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar3Blue.mesh + + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar1Blue.mesh + + + + + + + + + + + + + + 4 + Models/Props/Pillars/SciFiPillar1Red.mesh + + + + + + + + + + + + + + 4 + Models/Props/Pillars/SciFiPillar3Red.mesh + + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + 4 + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2 + + + + + + + + + + + + + + 5 + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + 2 + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + 4 + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + 2 + + + + + + + + + + + + 3 + + + + + + + + + + + + 2 + 1 + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + 2 + + + + + + + + + + + Models/Props/PickUps/HealthPickUp.mesh + + + 8 + + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + 2 + + + + + + + + + + + Models/Props/PickUps/HealthPickUp.mesh + + + 8 + + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + 2 + + + + + + + + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + 8 + + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + 2 + + + + + + + + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + 8 + + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + 2 + + + + + + + + + + + Models/Props/PickUps/HealthPickUp.mesh + + + 8 + + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + 2 + + + + + + + + + + + Models/Props/PickUps/HealthPickUp.mesh + + + 8 + + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + 2 + + + + + + + + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + 8 + + + + + + + + + + + + + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridge1Red.mesh + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridge1Red.mesh + + + + + + + + + + + + Models/Props/Pillars/SciFiBridgePillar1.mesh + + + + + + + + + + + + + + + Models/Props/Pillars/SciFiBridgePillar1.mesh + + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridge1Red.mesh + + + + + + + + + + + + + + + + + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/Flora/SpecialRoot.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/MediumWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Core/UnitPlane.mesh + + true + + + + + + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar1Red.mesh + + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + 2 + + + + + + + + + + + Models/Props/PickUps/HealthPickUp.mesh + + + 8 + + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + 2 + + + + + + + + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + 8 + + + + + + + + + + + + + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + + + + + + + + Models/Props/Walls/SmallWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2 + + + + + + + + + + + + + + 5 + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + 2 + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + 4 + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + 2 + + + + + + + + + + + + 3 + + + + + + + + + + + + 2 + 1 + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + 2 + + + + + + + + + + + Models/Props/PickUps/HealthPickUp.mesh + + + 8 + + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + 2 + + + + + + + + + + + Models/Props/PickUps/HealthPickUp.mesh + + + 8 + + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + 2 + + + + + + + + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + 8 + + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + 2 + + + + + + + + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + 8 + + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + 2 + + + + + + + + + + + Models/Props/PickUps/HealthPickUp.mesh + + + 8 + + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + 2 + + + + + + + + + + + Models/Props/PickUps/HealthPickUp.mesh + + + 8 + + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + 2 + + + + + + + + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + 8 + + + + + + + + + + + + + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridge1Blue.mesh + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridge1Blue.mesh + + + + + + + + + + + + Models/Props/Pillars/SciFiBridgePillar1.mesh + + + + + + + + + + + + + + + Models/Props/Pillars/SciFiBridgePillar1.mesh + + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridge1Blue.mesh + + + + + + + + + + + + + + + + + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/Flora/SpecialRoot.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/MediumWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Core/UnitPlane.mesh + + true + + + + + + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar1Blue.mesh + + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + + + + + + + + + + + Models/Props/CapturePoint/CapturePointBlue.mesh + + + + + + + + + + + + + 4 + + + Models/Core/UnitCylinder.mesh + + true + + + + + + + + + + + + + + + + + + + + + Models/Props/CapturePoint/CapturePointNeutral.mesh + + + + + + + + + + 3 + + + Models/Core/UnitCylinder.mesh + + true + + + + + + + + + + + + + + + + + Models/Props/CapturePoint/CapturePointNeutral.mesh + + + + + + + + + + 2 + + + Models/Core/UnitCylinder.mesh + + true + + + + + + + + + + + + + + + + + Models/Props/CapturePoint/CapturePointNeutral.mesh + + + + + + + + + + 1 + + + Models/Core/UnitCylinder.mesh + + true + + + + + + + + + + + + + + + + + Models/Props/CapturePoint/CapturePointRed.mesh + + + + + + + + + + + + + + + Models/Core/UnitCylinder.mesh + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + + + + + + + + + 10 + + + + + + + + + + + 10 + + + + + + + + + + + 10 + + + + + + + + + + + + 10 + + + + + + + + + + + 1 + false + + + + + + + + + + + + 10 + + + + + + + + + + + + + + Schema/Entities/PlayerRed.xml + + + + + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + + + Schema/Entities/Player.xml + + + + + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + diff --git a/resources/Schema/Entities/NewMap2version3NEW.xml b/resources/Schema/Entities/NewMap2version3NEW.xml new file mode 100644 index 00000000..d24675cd --- /dev/null +++ b/resources/Schema/Entities/NewMap2version3NEW.xml @@ -0,0 +1,4612 @@ + + + + + + + + + + + + + + + + + + Models/Props/GroundTest.mesh + + + + + + + + + Models/Props/Walls/SciFiWallTop.mesh + + + + + + + + + Models/Props/Walls/SciFiWallBig.mesh + true + + + + + + + + + + Models/Props/Walls/SciFiWallMedium.mesh + + + + + + + + + + Models/Props/Walls/SciFiWallSmall1.mesh + + + + + + + + + + Models/Props/Walls/SciFiWallSmall2.mesh + + + + + + + + + + Models/Props/Walls/SciFiWallBig.mesh + + + + + + + + + + + + Models/Props/Walls/SciFiWallMedium.mesh + + + + + + + + + + + + Models/Props/Walls/SciFiWallSmall3.mesh + + + + + + + + + + Models/Props/Walls/SciFiWallSmall4.mesh + + + + + + + + + + + + Models/Props/Highground1.mesh + + + + + + + + + + Models/Props/Highground2.mesh + + + + + + + + + + + Models/Props/Highground3.mesh + + + + + + + + + + + Models/Props/Highground4.mesh + + + + + + + + + + + Models/Props/Highground5.mesh + + + + + + + + + + Models/Props/Highground6.mesh + + + + + + + + + + + Models/Props/Highground7.mesh + + + + + + + + + + + + + Models/Props/Highground8.mesh + + + + + + + + + + + + + Models/Props/Highground9.mesh + + + + + + + + + + + + + Models/Props/Highground10.mesh + + + + + + + + + + + + + Models/Props/Highground6.mesh + + + + + + + + + + + + + Models/Props/Highground1.mesh + + + + + + + + + + + + Models/Props/Highground2.mesh + + + + + + + + + + + + + Models/Props/Highground3.mesh + + + + + + + + + + + + + Models/Props/Highground4.mesh + + + + + + + + + + + + + Models/Props/Highground5.mesh + + + + + + + + + + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar1Blue.mesh + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar1Red.mesh + + + + + + + + + + + + + 4 + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar3Blue.mesh + + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar1Blue.mesh + + + + + + + + + + + + + + 4 + Models/Props/Pillars/SciFiPillar1Red.mesh + + + + + + + + + + + + + + 4 + Models/Props/Pillars/SciFiPillar3Red.mesh + + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + 4 + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2 + + + + + + + + + + + + + + 5 + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + 2 + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + 4 + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + 2 + + + + + + + + + + + + 3 + + + + + + + + + + + + 2 + 1 + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + 8 + + + + Models/Props/PickUps/HealthPickUp.mesh + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + 8 + + + + Models/Props/PickUps/HealthPickUp.mesh + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + 8 + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + 8 + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + 8 + + + + Models/Props/PickUps/HealthPickUp.mesh + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + 8 + + + + Models/Props/PickUps/HealthPickUp.mesh + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + 8 + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + + + + + + + + + + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridge1Red.mesh + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridge1Red.mesh + + + + + + + + + + + + Models/Props/Pillars/SciFiBridgePillar1.mesh + + + + + + + + + + + + + + + Models/Props/Pillars/SciFiBridgePillar1.mesh + + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridge1Red.mesh + + + + + + + + + + + + + + + + + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/Flora/SpecialRoot.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/MediumWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Core/UnitPlane.mesh + + true + + + + + + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar1Red.mesh + + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + 8 + + + + Models/Props/PickUps/HealthPickUp.mesh + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + 8 + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + + + + + + + + + + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + + + + + + + + Models/Props/Walls/SmallWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2 + + + + + + + + + + + + + + 5 + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + 2 + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + 4 + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + 2 + + + + + + + + + + + + 3 + + + + + + + + + + + + 2 + 1 + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + 8 + + + + Models/Props/PickUps/HealthPickUp.mesh + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + 8 + + + + Models/Props/PickUps/HealthPickUp.mesh + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + 8 + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + 8 + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + 8 + + + + Models/Props/PickUps/HealthPickUp.mesh + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + 8 + + + + Models/Props/PickUps/HealthPickUp.mesh + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + 8 + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + + + + + + + + + + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridge1Blue.mesh + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridge1Blue.mesh + + + + + + + + + + + + Models/Props/Pillars/SciFiBridgePillar1.mesh + + + + + + + + + + + + + + + Models/Props/Pillars/SciFiBridgePillar1.mesh + + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridge1Blue.mesh + + + + + + + + + + + + + + + + + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/Flora/SpecialRoot.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/MediumWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall2.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Core/UnitPlane.mesh + + true + + + + + + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar1Blue.mesh + + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + + + + + + + + + + + Models/Props/CapturePoint/CapturePointBlue.mesh + + + + + + + + + + + + + -15 + 4 + + + Models/Core/UnitCylinder.mesh + + true + + + + + + + + + + + + + + + + + + + + + Models/Props/CapturePoint/CapturePointNeutral.mesh + + + + + + + + + + 3 + + + Models/Core/UnitCylinder.mesh + + true + + + + + + + + + + + + + + + + + Models/Props/CapturePoint/CapturePointNeutral.mesh + + + + + + + + + + 2 + + + Models/Core/UnitCylinder.mesh + + true + + + + + + + + + + + + + + + + + Models/Props/CapturePoint/CapturePointNeutral.mesh + + + + + + + + + + 1 + + + Models/Core/UnitCylinder.mesh + + true + + + + + + + + + + + + + + + + + Models/Props/CapturePoint/CapturePointRed.mesh + + + + + + + + + + + + + 15 + + + Models/Core/UnitCylinder.mesh + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + + + + + + + + + 10 + + + + + + + + + + + 10 + + + + + + + + + + + 10 + + + + + + + + + + + + 10 + + + + + + + + + + + 1 + false + + + + + + + + + + + + 10 + + + + + + + + + + + + + + Schema/Entities/PlayerRed.xml + + + + + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + + + Schema/Entities/Player.xml + + + + + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + diff --git a/resources/Schema/Entities/Player.xml b/resources/Schema/Entities/Player.xml index 88f153ae..2edbd4a5 100644 --- a/resources/Schema/Entities/Player.xml +++ b/resources/Schema/Entities/Player.xml @@ -13,7 +13,7 @@ - 1.6944730461160304 + 23.911064541134579 @@ -193,7 +193,6 @@ 3 - 0.80222018197612788 @@ -228,6 +227,7 @@ 4 + 1 @@ -283,7 +283,7 @@ Textures/Core/UnitHexagon.png - + @@ -294,7 +294,8 @@ - + 1 + Textures/Core/UnitHexagon_Rotated.png @@ -303,7 +304,7 @@ - + @@ -372,7 +373,7 @@ Idle - 0.67172915251515519 + 0.22110820884665827 1 @@ -386,30 +387,49 @@ + + DefenderWeapon + Schema/Entities/DefenderWeaponView.xml - - DefenderWeapon - + + AssaultWeapon + Schema/Entities/AssaultWeaponView.xml - - AssaultWeapon - + + + + + Models/Widgets/Arrows/Arrow10.mesh + + + + + + + + + + + + + + @@ -430,6 +450,7 @@ Idle + 1.6993789132803556 1 @@ -449,31 +470,31 @@ - - Schema/Entities/DefenderWeaponWorld.xml - - DefenderWeapon + + Schema/Entities/DefenderWeaponWorld.xml + + - - Schema/Entities/AssaultWeaponWorld.xml - - AssaultWeapon + + Schema/Entities/AssaultWeaponWorld.xml + + diff --git a/resources/Schema/Entities/PlayerRed.xml b/resources/Schema/Entities/PlayerRed.xml index 8982f58d..7f81ab05 100644 --- a/resources/Schema/Entities/PlayerRed.xml +++ b/resources/Schema/Entities/PlayerRed.xml @@ -13,7 +13,7 @@ - 326.69883589440087 + 361.81593010381596 @@ -373,7 +373,7 @@ Idle - 0.20909021680133577 + 1.6231050125476969 1 @@ -417,10 +417,11 @@ Models/Weapons/Blue/AssaultWeaponBlue.mesh + - + @@ -445,7 +446,7 @@ Idle - 0.22069183859343156 + 1.8847063959212136 1 diff --git a/src/Game/Systems/CapturePointArrowHUDSystem.cpp b/src/Game/Systems/CapturePointArrowHUDSystem.cpp index ee2254c7..e86a6844 100644 --- a/src/Game/Systems/CapturePointArrowHUDSystem.cpp +++ b/src/Game/Systems/CapturePointArrowHUDSystem.cpp @@ -64,6 +64,9 @@ void CapturePointArrowHUDSystem::Update(double dt) } } //Check what team is the owner of Home1 and set their target to the next capturepoint + if(!home1.Valid() || !home2.Valid()) { + return; + } if((int)home1["CapturePoint"]["HomePointForTeam"] == redTeam) { m_RedTeamCurrentTarget = target1; } else if ((int)home1["CapturePoint"]["HomePointForTeam"] == blueTeam) { @@ -77,10 +80,7 @@ void CapturePointArrowHUDSystem::Update(double dt) m_BlueTeamCurrentTarget = target2; } } - - } - //if red team, get red team next point, otherwise blue team next point. //Untill this is awailable we will just use the hardcoded value in the component. //This will also give us a position, so we wont need to loop through all capturePoints. @@ -132,4 +132,6 @@ bool CapturePointArrowHUDSystem::OnCapturePointCaptured(Events::Captured& e) } else if (e.TeamNumberThatCapturedCapturePoint == blueTeam) { m_BlueTeamCurrentTarget = Transform::AbsolutePosition(e.NextCapturePoint);; } + + m_InitialtargetsSet = true; } From ef66f3ebe54998e0a998aaf264a4245ec1c43041 Mon Sep 17 00:00:00 2001 From: Teejoon Date: Tue, 1 Mar 2016 23:14:23 +0100 Subject: [PATCH 061/130] Transparancy with shild fix --- .../Rendering/DrawColorCorrectionPass.h | 2 +- include/Engine/Rendering/DrawFinalPass.h | 42 +- include/Engine/Rendering/ExplosionEffectJob.h | 4 +- include/Engine/Rendering/ModelJob.h | 6 +- include/Engine/Rendering/RenderQueue.h | 2 - .../Shaders/DrawColorCorrection.frag.glsl | 13 +- .../Shaders/ForwardPlusShieldCheck.frag.glsl | 207 ++++ ...orwardPlusSplatMapRGBShieldCheck.frag.glsl | 254 ++++ resources/Shaders/SpriteShieldCheck.frag.glsl | 41 + src/Engine/Editor/EditorRenderSystem.cpp | 2 +- .../Rendering/DrawColorCorrectionPass.cpp | 6 +- src/Engine/Rendering/DrawFinalPass.cpp | 1019 +++++++++++------ src/Engine/Rendering/DrawFinalPassState.cpp | 16 +- src/Engine/Rendering/PickingPass.cpp | 3 +- src/Engine/Rendering/RenderSystem.cpp | 19 +- src/Engine/Rendering/Renderer.cpp | 16 +- 16 files changed, 1252 insertions(+), 400 deletions(-) create mode 100644 resources/Shaders/ForwardPlusShieldCheck.frag.glsl create mode 100644 resources/Shaders/ForwardPlusSplatMapRGBShieldCheck.frag.glsl create mode 100644 resources/Shaders/SpriteShieldCheck.frag.glsl diff --git a/include/Engine/Rendering/DrawColorCorrectionPass.h b/include/Engine/Rendering/DrawColorCorrectionPass.h index 231e2d33..fcde73d7 100644 --- a/include/Engine/Rendering/DrawColorCorrectionPass.h +++ b/include/Engine/Rendering/DrawColorCorrectionPass.h @@ -17,7 +17,7 @@ public: void InitializeFrameBuffers(); void InitializeShaderPrograms(); - void Draw(GLuint sceneTexture, GLuint bloomTexture, GLuint sceneTextureLowRes, GLuint bloomTextureLowRes, GLfloat gamma, GLfloat exposure); + void Draw(GLuint sceneTexture, GLuint bloomTexture, GLfloat gamma, GLfloat exposure); private: const IRenderer* m_Renderer; diff --git a/include/Engine/Rendering/DrawFinalPass.h b/include/Engine/Rendering/DrawFinalPass.h index 97322603..3b83d52f 100644 --- a/include/Engine/Rendering/DrawFinalPass.h +++ b/include/Engine/Rendering/DrawFinalPass.h @@ -15,7 +15,7 @@ class DrawFinalPass { public: - DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass, CubeMapPass* cubeMapPass, SSAOPass* ssaoPass, GLuint* depthBuffer); + DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass, CubeMapPass* cubeMapPass, SSAOPass* ssaoPass); ~DrawFinalPass() { } void InitializeTextures(); void InitializeFrameBuffers(); @@ -26,20 +26,23 @@ public: //Return the texture that is used in later stages to apply the bloom effect GLuint BloomTexture() const { return m_BloomTexture; } - GLuint BloomTextureLowRes() const { return m_BloomTextureLowRes; } //Return the texture with diffuse and lighting of the scene. GLuint SceneTexture() const { return m_SceneTexture; } - GLuint SceneTextureLowRes() const { return m_SceneTextureLowRes; } //Return the framebuffer used in the scene rendering stage. FrameBuffer* FinalPassFrameBuffer() { return &m_FinalPassFrameBuffer; } - FrameBuffer* FinalPassFrameBufferLowRes() { return &m_FinalPassFrameBufferLowRes; } private: void DrawSprites(std::list>&jobs, RenderScene& scene); void DrawModelRenderQueues(std::list>& jobs, RenderScene& scene); - void DrawShieldToStencilBuffer(std::list>& jobs, RenderScene& scene); + void DrawModelRenderQueuesWithShieldCheck(std::list>& jobs, RenderScene& scene); void DrawShieldedModelRenderQueue(std::list>& jobs, RenderScene& scene); - void DrawToDepthBuffer(std::list>& jobs, RenderScene& scene); + void DrawToDepthStencilBuffer(std::list>& jobs, RenderScene& scene); + + void DrawExplosionSetup(ShaderProgram* shader, GLuint shaderHandle, std::shared_ptr& job, RenderScene& scene); + void DrawSkinnedExplosionSetup(ShaderProgram* shader, GLuint shaderHandle, std::shared_ptr& job, RenderScene& scene); + + void DrawModelSetup(ShaderProgram* shader, GLuint shaderHandle, std::shared_ptr& job, RenderScene& scene); + void DrawSkinnedModelSetup(ShaderProgram* shader, GLuint shaderHandle, std::shared_ptr& job, RenderScene& scene); void BindExplosionUniforms(GLuint shaderHandle, std::shared_ptr& job, RenderScene& scene); void BindModelUniforms(GLuint shaderHandle, std::shared_ptr& job, RenderScene& scene); @@ -54,13 +57,11 @@ private: Texture* m_ErrorTexture; FrameBuffer m_FinalPassFrameBuffer; - FrameBuffer m_FinalPassFrameBufferLowRes; + FrameBuffer m_ShieldDepthFrameBuffer; GLuint m_BloomTexture; GLuint m_SceneTexture; - GLuint m_BloomTextureLowRes; - GLuint m_SceneTextureLowRes; - GLuint* m_DepthBuffer; - GLuint m_DepthBufferLowRes; + GLuint m_DepthBuffer; + GLuint m_ShieldBuffer; GLuint m_CubeMapTexture; //maqke this component based i guess? @@ -76,16 +77,27 @@ private: ShaderProgram* m_ExplosionEffectSplatMapProgram; ShaderProgram* m_SpriteProgram; ShaderProgram* m_ForwardPlusSplatMapProgram; - ShaderProgram* m_ShieldToStencilProgram; - ShaderProgram* m_FillDepthBufferProgram; + ShaderProgram* m_FillDepthStencilBufferProgram; + + ShaderProgram* m_ForwardPlusShieldCheckProgram; + ShaderProgram* m_ExplosionEffectShieldCheckProgram; + ShaderProgram* m_ExplosionEffectSplatMapShieldCheckProgram; + ShaderProgram* m_SpriteShieldCheckProgram; + ShaderProgram* m_ForwardPlusSplatMapShieldCheckProgram; + ShaderProgram* m_ForwardPlusSkinnedProgram; ShaderProgram* m_ExplosionEffectSkinnedProgram; ShaderProgram* m_ExplosionEffectSplatMapSkinnedProgram; ShaderProgram* m_ForwardPlusSplatMapSkinnedProgram; - ShaderProgram* m_ShieldToStencilSkinnedProgram; - ShaderProgram* m_FillDepthBufferSkinnedProgram; + ShaderProgram* m_FillDepthStencilBufferSkinnedProgram; + + ShaderProgram* m_ForwardPlusSkinnedShieldCheckProgram; + ShaderProgram* m_ExplosionEffectSkinnedShieldCheckProgram; + ShaderProgram* m_ExplosionEffectSplatMapSkinnedShieldCheckProgram; + ShaderProgram* m_ForwardPlusSplatMapSkinnedShieldCheckProgram; + ShaderProgram* m_FillDepthBufferSkinnedShieldCheckProgram; }; #endif \ No newline at end of file diff --git a/include/Engine/Rendering/ExplosionEffectJob.h b/include/Engine/Rendering/ExplosionEffectJob.h index 8f339526..695a8dfe 100644 --- a/include/Engine/Rendering/ExplosionEffectJob.h +++ b/include/Engine/Rendering/ExplosionEffectJob.h @@ -15,8 +15,8 @@ struct ExplosionEffectJob : ModelJob { - ExplosionEffectJob(ComponentWrapper explosionEffectComponent, ::Model* model, Camera* camera, glm::mat4 matrix, ::RawModel::MaterialProperties matGroup, ComponentWrapper modelComponent, ::World* world, glm::vec4 fillColor, float fillPercentage) - : ModelJob(model, camera, matrix, matGroup, modelComponent, world, fillColor, fillPercentage) + ExplosionEffectJob(ComponentWrapper explosionEffectComponent, ::Model* model, Camera* camera, glm::mat4 matrix, ::RawModel::MaterialProperties matGroup, ComponentWrapper modelComponent, ::World* world, glm::vec4 fillColor, float fillPercentage, bool isShielded) + : ModelJob(model, camera, matrix, matGroup, modelComponent, world, fillColor, fillPercentage, isShielded) { ExplosionOrigin = (glm::vec3)explosionEffectComponent["ExplosionOrigin"]; TimeSinceDeath = (double)explosionEffectComponent["TimeSinceDeath"]; diff --git a/include/Engine/Rendering/ModelJob.h b/include/Engine/Rendering/ModelJob.h index c2a469d2..58993ea1 100644 --- a/include/Engine/Rendering/ModelJob.h +++ b/include/Engine/Rendering/ModelJob.h @@ -18,7 +18,7 @@ struct ModelJob : RenderJob { - ModelJob(Model* model, Camera* camera, glm::mat4 matrix, ::RawModel::MaterialProperties matProp, ComponentWrapper modelComponent, World* world, glm::vec4 fillColor, float fillPercentage) + ModelJob(Model* model, Camera* camera, glm::mat4 matrix, ::RawModel::MaterialProperties matProp, ComponentWrapper modelComponent, World* world, glm::vec4 fillColor, float fillPercentage, bool isShielded) : RenderJob() { Model = model; @@ -117,7 +117,7 @@ struct ModelJob : RenderJob FillColor = fillColor; FillPercentage = fillPercentage; - + IsShielded = isShielded; if (model->IsSkinned()) { Skeleton = Model->m_RawModel->m_Skeleton; @@ -181,7 +181,7 @@ struct ModelJob : RenderJob glm::vec4 FillColor = glm::vec4(0); float FillPercentage = 0.0; - + bool IsShielded; void CalculateHash() override { Hash = ShaderID << 20 + ModelID << 10 + TextureID; diff --git a/include/Engine/Rendering/RenderQueue.h b/include/Engine/Rendering/RenderQueue.h index 647adab8..e3c46e85 100644 --- a/include/Engine/Rendering/RenderQueue.h +++ b/include/Engine/Rendering/RenderQueue.h @@ -24,7 +24,6 @@ struct RenderScene std::list> OpaqueObjects; std::list> TransparentObjects; std::list> OpaqueShieldedObjects; - std::list> TransparentShieldedObjects; std::list> ShieldObjects; std::list> SpriteJob; std::list> PointLight; @@ -41,7 +40,6 @@ struct RenderScene Jobs.OpaqueObjects.clear(); Jobs.TransparentObjects.clear(); Jobs.OpaqueShieldedObjects.clear(); - Jobs.TransparentShieldedObjects.clear(); Jobs.ShieldObjects.clear(); Jobs.SpriteJob.clear(); Jobs.DirectionalLight.clear(); diff --git a/resources/Shaders/DrawColorCorrection.frag.glsl b/resources/Shaders/DrawColorCorrection.frag.glsl index bae50887..d8273547 100644 --- a/resources/Shaders/DrawColorCorrection.frag.glsl +++ b/resources/Shaders/DrawColorCorrection.frag.glsl @@ -2,8 +2,6 @@ layout (binding = 0) uniform sampler2D SceneTexture; layout (binding = 1) uniform sampler2D BloomTexture; -layout (binding = 2) uniform sampler2D SceneTextureLowRes; -layout (binding = 3) uniform sampler2D BloomTextureLowRes; uniform float Exposure; uniform float Gamma; @@ -17,21 +15,12 @@ void main() { vec4 hdrColor = texture(SceneTexture, Input.TextureCoordinate); vec4 bloomColor = texture(BloomTexture, Input.TextureCoordinate); - vec4 hdrColorLowRes = texture(SceneTextureLowRes, Input.TextureCoordinate); - vec4 bloomColorLowRes = texture(BloomTextureLowRes, Input.TextureCoordinate); //hdrColor = hdrColor * SSAO; hdrColor += bloomColor; - hdrColorLowRes; - float hdrColorsum = hdrColorLowRes.r + hdrColorLowRes.g + hdrColorLowRes.b; //Toon mapping thingy - vec3 result; - if(hdrColorsum > 0.0) { - result = vec3(1.0) - exp(-hdrColorLowRes.rgb * Exposure); - } else { - result = vec3(1.0) - exp(-hdrColor.rgb * Exposure); - } + vec3 result = vec3(1.0) - exp(-hdrColor.rgb * Exposure); //gamme correction result = pow(result, vec3(1.0 / Gamma)); diff --git a/resources/Shaders/ForwardPlusShieldCheck.frag.glsl b/resources/Shaders/ForwardPlusShieldCheck.frag.glsl new file mode 100644 index 00000000..35db495b --- /dev/null +++ b/resources/Shaders/ForwardPlusShieldCheck.frag.glsl @@ -0,0 +1,207 @@ +#version 430 + +#define MIN_AMBIENT_LIGHT 0.3 + +uniform mat4 M; +uniform mat4 V; +uniform mat4 P; +uniform vec4 Color; +uniform vec4 DiffuseColor; +uniform vec2 ScreenDimensions; +uniform vec4 FillColor; +uniform vec4 AmbientColor; +uniform float FillPercentage; +uniform float GlowIntensity = 10; +uniform vec3 CameraPosition; +uniform int SSAOQuality; + +uniform vec2 DiffuseUVRepeat; +uniform vec2 NormalUVRepeat; +uniform vec2 SpecularUVRepeat; +uniform vec2 GlowUVRepeat; +layout (binding = 0) uniform sampler2D AOTexture; +layout (binding = 1) uniform sampler2D DiffuseTexture; +layout (binding = 2) uniform sampler2D NormalMapTexture; +layout (binding = 3) uniform sampler2D SpecularMapTexture; +layout (binding = 4) uniform sampler2D GlowMapTexture; +layout (binding = 5) uniform samplerCube CubeMap; +layout (binding = 31) uniform sampler2D ShieldBuffer; + +#define TILE_SIZE 16 + +struct LightSource { + vec4 Position; + vec4 Direction; + vec4 Color; + float Radius; + float Intensity; + float Falloff; + int Type; +}; + +layout (std430, binding = 1) buffer LightBuffer +{ + LightSource List[]; +} LightSources; + +struct LightGrid { + float Start; + float Amount; + vec2 Padding; +}; + +layout (std430, binding = 2) buffer LightGridBuffer +{ + LightGrid Data[]; +} LightGrids; + +layout (std430, binding = 4) buffer LightIndexBuffer +{ + float LightIndex[]; +}; + + +in VertexData{ + vec3 Position; + vec3 Normal; + vec3 Tangent; + vec3 BiTangent; + vec2 TextureCoordinate; + vec4 ExplosionColor; + float ExplosionPercentageElapsed; +}Input; + +out vec4 sceneColor; +out vec4 bloomColor; + +struct LightResult { + vec4 Diffuse; + vec4 Specular; +}; + +float CalcAttenuation(float radius, float dist, float falloff) { + return 1.0 - smoothstep(radius * falloff, radius, dist); +} + +vec4 CalcSpecular(vec4 lightColor, vec4 viewVec, vec4 lightVec, vec4 normal) { + vec4 R = normalize( reflect(-lightVec, normal)); + float RdotV = max( dot(R, viewVec), 0.0); + return lightColor * pow(RdotV, 90.0); +} + +vec4 CalcDiffuse(vec4 lightColor, vec4 lightVec, vec4 normal) { + float power = max( dot(normal, lightVec), 0.0); + return lightColor * power; +} + +LightResult CalcPointLightSource(vec4 lightPos, float lightRadius, vec4 lightColor, float intensity, vec4 viewVec, vec4 position, vec4 normal, float falloff) +{ + vec4 L = lightPos - position; + float dist = length(L); + L = normalize(L); + + float attenuation = CalcAttenuation(lightRadius, dist, falloff); + + LightResult result; + result.Diffuse = CalcDiffuse(lightColor, L, normal) * attenuation * intensity; + result.Specular = CalcSpecular(lightColor, viewVec, L, normal) * attenuation * intensity; + return result; +} + +LightResult CalcDirectionalLightSource(vec4 direction, vec4 color, float intensity, vec4 viewVec, vec4 vertNormal) +{ + vec4 L = normalize( -vec4(direction.xyz, 0) ); + + LightResult result; + result.Diffuse = CalcDiffuse(color, L, vertNormal) * intensity; + result.Specular = CalcSpecular(color, viewVec, L, vertNormal) * intensity; + return result; +} + +vec4 CalcNormalMappedValue(vec3 normal, vec3 tangent, vec3 bitangent, vec2 textureCoordinate, sampler2D normalMap) +{ + mat3 TBN = mat3(tangent, bitangent, normal); + vec3 NormalMap = texture(normalMap, textureCoordinate).xyz * 2.0 - vec3(1.0); + return vec4(TBN * normalize(NormalMap), 0.0); +} + +void main() +{ + float shieldDepthValue = texelFetch(ShieldBuffer, ivec2(gl_FragCoord.xy), 0).r; + + if(shieldDepthValue < gl_FragCoord.z){ + discard; + } + + float ao = texelFetch(AOTexture, ivec2(gl_FragCoord.xy) >> int(SSAOQuality), 0).r; + ao = (clamp(1.0 - (1.0 - ao), 0.0, 1.0) + MIN_AMBIENT_LIGHT) / (1.0 + MIN_AMBIENT_LIGHT); + vec4 diffuseTexel = texture2D(DiffuseTexture, Input.TextureCoordinate * DiffuseUVRepeat); + vec4 glowTexel = texture2D(GlowMapTexture, Input.TextureCoordinate * GlowUVRepeat); + vec4 specularTexel = texture2D(SpecularMapTexture, Input.TextureCoordinate * SpecularUVRepeat); + vec4 position = V * M * vec4(Input.Position, 1.0); + vec4 normal = V * CalcNormalMappedValue(Input.Normal, Input.Tangent, Input.BiTangent, Input.TextureCoordinate * NormalUVRepeat, NormalMapTexture); + normal = normalize(normal); + //vec4 normal = normalize(V * vec4(Input.Normal, 0.0)); + vec4 viewVec = normalize(-position); + vec3 I = normalize(vec3(M * vec4(Input.Position, 1.0)) - CameraPosition); + vec3 R = reflect(-I, Input.Normal); + //R = vec3(P * vec4(R, 1.0)); + vec4 reflectionColor = texture(CubeMap, R); + + vec2 tilePos; + tilePos.x = int(gl_FragCoord.x/TILE_SIZE); + tilePos.y = int(gl_FragCoord.y/TILE_SIZE); + + LightResult totalLighting; + totalLighting.Diffuse = vec4(AmbientColor.rgb * ao, 1.0); + int currentTile = int(floor(gl_FragCoord.x/TILE_SIZE) + (floor(gl_FragCoord.y/TILE_SIZE) * int(ScreenDimensions.x/TILE_SIZE))); + + int start = int(LightGrids.Data[currentTile].Start); + int amount = int(LightGrids.Data[currentTile].Amount); + + for(int i = start; i < start + amount; i++) { + + int l = int(LightIndex[i]); + LightSource light = LightSources.List[l]; + + LightResult light_result; + //These if statements should be removed. + if(light.Type == 1) { // point + light_result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, position, normal, light.Falloff); + } else if (light.Type == 2) { //Directional + light_result = CalcDirectionalLightSource(V * light.Direction, light.Color, light.Intensity, viewVec, normal); + } + totalLighting.Diffuse += vec4(light_result.Diffuse.rgb * ao, light_result.Diffuse.a); + totalLighting.Specular += vec4(light_result.Specular.rgb * ao, light_result.Specular.a); + } + + vec4 color_result = mix((Color * diffuseTexel * DiffuseColor), Input.ExplosionColor, Input.ExplosionPercentageElapsed); + color_result = color_result * (totalLighting.Diffuse + (totalLighting.Specular * specularTexel)); + float specularResult = (specularTexel.r + specularTexel.g + specularTexel.b)/3.0; + vec4 reflectionTotal = reflectionColor * (1-specularTexel.a) * color_result.a; + color_result = color_result * clamp(1/specularTexel.a, 0, 1) + reflectionTotal; + //vec4 color_result = (DiffuseColor + Input.ExplosionColor) * (totalLighting.Diffuse + (totalLighting.Specular * specularTexel)) * diffuseTexel * Color; + + + float pos = ((P * vec4(Input.Position, 1)).y + 1.0)/2.0; + + if(pos <= FillPercentage) { + color_result += FillColor; + } + sceneColor = vec4(color_result.xyz, clamp(color_result.a, 0, 1)); + //sceneColor = vec4(reflectionColor.xyz, 1); + color_result.xyz += glowTexel.xyz*GlowIntensity; + + bloomColor = vec4(max(color_result.xyz - 1.0, 0.0), clamp(color_result.a, 0, 1)); + + //Tiled Debug Code + /* + if(int(gl_FragCoord.x)%16 == 0 || int(gl_FragCoord.y)%16 == 0 ) { + sceneColor += vec4(0.5, 0, 0, 0); + } else { + sceneColor += vec4(LightGrids.Data[int(tilePos.x + tilePos.y*80)].Amount/LightSources.List.length(), 0, 0, 1); + } + */ +} + + diff --git a/resources/Shaders/ForwardPlusSplatMapRGBShieldCheck.frag.glsl b/resources/Shaders/ForwardPlusSplatMapRGBShieldCheck.frag.glsl new file mode 100644 index 00000000..fa3af6ac --- /dev/null +++ b/resources/Shaders/ForwardPlusSplatMapRGBShieldCheck.frag.glsl @@ -0,0 +1,254 @@ +#version 430 + +#define MIN_AMBIENT_LIGHT 0.3 + +uniform mat4 M; +uniform mat4 V; +uniform mat4 P; +uniform vec2 ScreenDimensions; +uniform float FillPercentage; +uniform vec4 DiffuseColor; +uniform vec4 FillColor; +uniform vec4 Color; +uniform vec4 AmbientColor; +uniform int SSAOQuality; + +//Get bineded at the same time as the textures +uniform vec2 DiffuseUVRepeat1; +uniform vec2 DiffuseUVRepeat2; +uniform vec2 DiffuseUVRepeat3; +uniform vec2 NormalUVRepeat1; +uniform vec2 NormalUVRepeat2; +uniform vec2 NormalUVRepeat3; +uniform vec2 SpecularUVRepeat1; +uniform vec2 SpecularUVRepeat2; +uniform vec2 SpecularUVRepeat3; +uniform vec2 GlowUVRepeat1; +uniform vec2 GlowUVRepeat2; +uniform vec2 GlowUVRepeat3; +layout (binding = 0) uniform sampler2D AOTexture; +layout (binding = 1) uniform sampler2D SplatMapTexture; +layout (binding = 2) uniform sampler2D DiffuseTexture1; +layout (binding = 3) uniform sampler2D DiffuseTexture2; +layout (binding = 4) uniform sampler2D DiffuseTexture3; +layout (binding = 5) uniform sampler2D NormalMapTexture1; +layout (binding = 6) uniform sampler2D NormalMapTexture2; +layout (binding = 7) uniform sampler2D NormalMapTexture3; +layout (binding = 8) uniform sampler2D SpecularMapTexture1; +layout (binding = 9) uniform sampler2D SpecularMapTexture2; +layout (binding = 10) uniform sampler2D SpecularMapTexture3; +layout (binding = 11) uniform sampler2D GlowMapTexture1; +layout (binding = 12) uniform sampler2D GlowMapTexture2; +layout (binding = 13) uniform sampler2D GlowMapTexture3; +layout (binding = 13) uniform sampler2D GlowMapTexture3; +layout (binding = 31) uniform samplerCube ShieldBuffer; + +#define TILE_SIZE 16 + +struct LightSource { + vec4 Position; + vec4 Direction; + vec4 Color; + float Radius; + float Intensity; + float Falloff; + int Type; +}; + +layout (std430, binding = 1) buffer LightBuffer +{ + LightSource List[]; +} LightSources; + +struct LightGrid { + float Start; + float Amount; + vec2 Padding; +}; + +layout (std430, binding = 2) buffer LightGridBuffer +{ + LightGrid Data[]; +} LightGrids; + +layout (std430, binding = 4) buffer LightIndexBuffer +{ + float LightIndex[]; +}; + + +in VertexData{ + vec3 Position; + vec3 Normal; + vec3 Tangent; + vec3 BiTangent; + vec2 TextureCoordinate; + vec4 ExplosionColor; + float ExplosionPercentageElapsed; +}Input; + +out vec4 sceneColor; +out vec4 bloomColor; + +struct LightResult { + vec4 Diffuse; + vec4 Specular; +}; + +float CalcAttenuation(float radius, float dist, float falloff) { + return 1.0 - smoothstep(radius * 0.3, radius, dist); +} + +vec4 CalcSpecular(vec4 lightColor, vec4 viewVec, vec4 lightVec, vec4 normal) { + vec4 R = normalize( reflect(-lightVec, normal)); + float RdotV = max( dot(R, viewVec), 0.0); + return lightColor * pow(RdotV, 90.0); +} + +vec4 CalcDiffuse(vec4 lightColor, vec4 lightVec, vec4 normal) { + float power = max( dot(normal, lightVec), 0.0); + return lightColor * power; +} + +LightResult CalcPointLightSource(vec4 lightPos, float lightRadius, vec4 lightColor, float intensity, vec4 viewVec, vec4 position, vec4 normal, float falloff) +{ + vec4 L = lightPos - position; + float dist = length(L); + L = normalize(L); + + float attenuation = CalcAttenuation(lightRadius, dist, falloff); + + LightResult result; + result.Diffuse = CalcDiffuse(lightColor, L, normal) * attenuation * intensity; + result.Specular = CalcSpecular(lightColor, viewVec, L, normal) * attenuation * intensity; + return result; +} + +LightResult CalcDirectionalLightSource(vec4 direction, vec4 color, float intensity, vec4 viewVec, vec4 vertNormal) +{ + vec4 L = normalize( -vec4(direction.xyz, 0) ); + + LightResult result; + result.Diffuse = CalcDiffuse(color, L, vertNormal) * intensity; + result.Specular = CalcSpecular(color, viewVec, L, vertNormal) * intensity; + return result; +} + +vec4 CalcNormalMappedValue(vec3 normal, vec3 tangent, vec3 bitangent, vec2 textureCoordinate, sampler2D normalMap) +{ + mat3 TBN = mat3(tangent, bitangent, normal); + vec3 NormalMap = texture(normalMap, textureCoordinate).xyz * 2.0 - vec3(1.0); + return vec4(TBN * normalize(NormalMap), 0.0); +} + +vec4 CalcBlendedTexel(vec4 blendValue, sampler2D R, sampler2D G, sampler2D B, + vec2 R_TileValues, vec2 G_TileValues, vec2 B_TileValues){ + vec4 R_Channel = texture2D(R, Input.TextureCoordinate * R_TileValues); + vec4 G_Channel = texture2D(G, Input.TextureCoordinate * G_TileValues); + vec4 B_Channel = texture2D(B, Input.TextureCoordinate * B_TileValues); + + float total = blendValue.r + blendValue.g + blendValue.b; + float totalDiv = 1.0f / total; + blendValue.r = blendValue.r * totalDiv; + blendValue.g = blendValue.g * totalDiv; + blendValue.b = blendValue.b * totalDiv; + + return blendValue.r * R_Channel + + blendValue.g * G_Channel + + blendValue.b * B_Channel; +} + +vec4 CalcBlendedNormal(vec4 blendValue, sampler2D R, sampler2D G, sampler2D B, + vec2 R_TileValues, vec2 G_TileValues, vec2 B_TileValues){ + mat3 TBN = mat3(Input.Tangent, Input.BiTangent, Input.Normal); + vec3 R_Channel = texture(R, Input.TextureCoordinate * R_TileValues).xyz * 2.0 - vec3(1.0); + vec3 G_Channel = texture(G, Input.TextureCoordinate * G_TileValues).xyz * 2.0 - vec3(1.0); + vec3 B_Channel = texture(B, Input.TextureCoordinate * B_TileValues).xyz * 2.0 - vec3(1.0); + + float total = blendValue.r + blendValue.g + blendValue.b + blendValue.a; + float totalDiv = 1 / total; + blendValue.r = blendValue.r * totalDiv; + blendValue.g = blendValue.g * totalDiv; + blendValue.b = blendValue.b * totalDiv; + + vec3 Normal_result = blendValue.r * R_Channel + + blendValue.g * G_Channel + + blendValue.b * B_Channel; + + return vec4(TBN * normalize(Normal_result), 0.0); +} + +void main() +{ + float ao = texelFetch(AOTexture, ivec2(gl_FragCoord.xy) >> int(SSAOQuality), 0).r; + ao = (clamp(1.0 - (1.0 - ao), 0.0, 1.0) + MIN_AMBIENT_LIGHT) / (1.0 + MIN_AMBIENT_LIGHT); + + vec4 splatTexel = texture2D(SplatMapTexture, Input.TextureCoordinate); + + vec4 diffuseTexel = CalcBlendedTexel(splatTexel, DiffuseTexture1, DiffuseTexture2, DiffuseTexture3, + DiffuseUVRepeat1, DiffuseUVRepeat2, DiffuseUVRepeat3); + vec4 glowTexel = CalcBlendedTexel(splatTexel, GlowMapTexture1, GlowMapTexture2, GlowMapTexture3, + GlowUVRepeat1, GlowUVRepeat2, GlowUVRepeat3); + vec4 specularTexel = CalcBlendedTexel(splatTexel, SpecularMapTexture1, SpecularMapTexture2, SpecularMapTexture3, + SpecularUVRepeat1, SpecularUVRepeat2, SpecularUVRepeat3); + vec4 position = V * M * vec4(Input.Position, 1.0); + //vec4 normal = V * CalcNormalMappedValue(Input.Normal, Input.Tangent, Input.BiTangent, Input.TextureCoordinate, SplatMapTexture); + vec4 normal = V * CalcBlendedNormal(splatTexel, NormalMapTexture1, NormalMapTexture2, NormalMapTexture3, + NormalUVRepeat1, NormalUVRepeat2, NormalUVRepeat3); + normal = normalize(normal); + //vec4 normal = normalize(V * vec4(Input.Normal, 0.0)); + vec4 viewVec = normalize(-position); + + vec2 tilePos; + tilePos.x = int(gl_FragCoord.x/TILE_SIZE); + tilePos.y = int(gl_FragCoord.y/TILE_SIZE); + + LightResult totalLighting; + totalLighting.Diffuse = vec4(AmbientColor.rgb * ao, 1.0); + int currentTile = int(floor(gl_FragCoord.x/TILE_SIZE) + (floor(gl_FragCoord.y/TILE_SIZE) * int(ScreenDimensions.x/TILE_SIZE))); + + int start = int(LightGrids.Data[currentTile].Start); + int amount = int(LightGrids.Data[currentTile].Amount); + + for(int i = start; i < start + amount; i++) { + + int l = int(LightIndex[i]); + LightSource light = LightSources.List[l]; + + LightResult light_result; + //These if statements should be removed. + if(light.Type == 1) { // point + light_result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, position, normal, light.Falloff); + } else if (light.Type == 2) { //Directional + light_result = CalcDirectionalLightSource(V * light.Direction, light.Color, light.Intensity, viewVec, normal); + } + totalLighting.Diffuse += vec4(light_result.Diffuse.rgb * ao, light_result.Diffuse.a); + totalLighting.Specular += vec4(light_result.Specular.rgb * ao, light_result.Specular.a); + } + + vec4 color_result = mix((Color * diffuseTexel * DiffuseColor), Input.ExplosionColor, Input.ExplosionPercentageElapsed); + color_result = color_result * (totalLighting.Diffuse + (totalLighting.Specular * specularTexel)); + //vec4 color_result = (DiffuseColor + Input.ExplosionColor) * (totalLighting.Diffuse + (totalLighting.Specular * specularTexel)) * diffuseTexel * Color; + + + float pos = ((P * vec4(Input.Position, 1)).y + 1.0)/2.0; + + if(pos <= FillPercentage) { + color_result += FillColor; + } + sceneColor = vec4(color_result.xyz, clamp(color_result.a, 0, 1)); + color_result += glowTexel*3; + + bloomColor = vec4(clamp(color_result.xyz - 1.0, 0, 100), 1.0); + + //Tiled Debug Code + /* + if(int(gl_FragCoord.x)%16 == 0 || int(gl_FragCoord.y)%16 == 0 ) { + sceneColor += vec4(0.5, 0, 0, 0); + } else { + sceneColor += vec4(LightGrids.Data[int(tilePos.x + tilePos.y*80)].Amount/LightSources.List.length(), 0, 0, 1); + } + */ +} + + diff --git a/resources/Shaders/SpriteShieldCheck.frag.glsl b/resources/Shaders/SpriteShieldCheck.frag.glsl new file mode 100644 index 00000000..754be6ac --- /dev/null +++ b/resources/Shaders/SpriteShieldCheck.frag.glsl @@ -0,0 +1,41 @@ +#version 430 + +uniform vec4 Color; +uniform vec4 FillColor; +uniform float FillPercentage; +uniform mat4 M; +uniform mat4 V; +uniform mat4 P; + +layout (binding = 1) uniform sampler2D DiffuseTexture; +layout (binding = 2) uniform sampler2D GlowMapTexture; + + +in VertexData{ + vec3 Position; + vec3 Normal; + vec2 TextureCoordinate; +}Input; + + +out vec4 sceneColor; +out vec4 bloomColor; + +void main() +{ + vec4 diffuseTexel = texture2D(DiffuseTexture, Input.TextureCoordinate); + vec4 glowTexel = texture2D(GlowMapTexture, Input.TextureCoordinate); + + vec4 color_result = Color * diffuseTexel; + + float pos = ((P * vec4(Input.Position, 1)).y + 1.0)/2.0; + if(pos <= FillPercentage) { + color_result = FillColor*diffuseTexel.a; + } + sceneColor = vec4(color_result.xyz, clamp(color_result.a, 0, 1)); + + //bloomColor = vec4(clamp((glowTexel.xyz*3) - 1.0, 0, 100), 1.0); + bloomColor = vec4(1.0, 1.0, 1.0, 0.0); +} + + diff --git a/src/Engine/Editor/EditorRenderSystem.cpp b/src/Engine/Editor/EditorRenderSystem.cpp index 9a385e7d..f5fcc1a1 100644 --- a/src/Engine/Editor/EditorRenderSystem.cpp +++ b/src/Engine/Editor/EditorRenderSystem.cpp @@ -54,7 +54,7 @@ void EditorRenderSystem::Update(double dt) EntityWrapper entity(m_World, cModel.EntityID); glm::mat4 modelMatrix = Transform::ModelMatrix(entity.ID, entity.World); for (auto matGroup : model->MaterialGroups()) { - std::shared_ptr modelJob = std::make_shared(model, scene.Camera, modelMatrix, matGroup, cModel, entity.World, glm::vec4(0), 0.f); + std::shared_ptr modelJob = std::make_shared(model, scene.Camera, modelMatrix, matGroup, cModel, entity.World, glm::vec4(0), 0.f, false); if (cModel["Transparent"]) { scene.Jobs.TransparentObjects.push_back(modelJob); } else { diff --git a/src/Engine/Rendering/DrawColorCorrectionPass.cpp b/src/Engine/Rendering/DrawColorCorrectionPass.cpp index c82d614f..70d3a053 100644 --- a/src/Engine/Rendering/DrawColorCorrectionPass.cpp +++ b/src/Engine/Rendering/DrawColorCorrectionPass.cpp @@ -18,7 +18,7 @@ void DrawColorCorrectionPass::InitializeShaderPrograms() m_ColorCorrectionProgram->Link(); } -void DrawColorCorrectionPass::Draw(GLuint sceneTexture, GLuint bloomTexture, GLuint sceneTextureLowRes, GLuint bloomTextureLowRes, GLfloat gamma, GLfloat exposure) +void DrawColorCorrectionPass::Draw(GLuint sceneTexture, GLuint bloomTexture, GLfloat gamma, GLfloat exposure) { //glBindFramebuffer(GL_FRAMEBUFFER, 0); GLERROR("DrawScreenQuadPass::Draw: Pre"); @@ -33,10 +33,6 @@ void DrawColorCorrectionPass::Draw(GLuint sceneTexture, GLuint bloomTexture, GLu glBindTexture(GL_TEXTURE_2D, sceneTexture); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, bloomTexture); - glActiveTexture(GL_TEXTURE2); - glBindTexture(GL_TEXTURE_2D, sceneTextureLowRes); - glActiveTexture(GL_TEXTURE3); - glBindTexture(GL_TEXTURE_2D, bloomTextureLowRes); glBindVertexArray(m_ScreenQuad->VAO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer); diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index 44ab8fd4..16c154e3 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -1,10 +1,9 @@ #include "Rendering/DrawFinalPass.h" -DrawFinalPass::DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass, CubeMapPass* cubeMapPass, SSAOPass* ssaoPass, GLuint* depthBuffer) +DrawFinalPass::DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass, CubeMapPass* cubeMapPass, SSAOPass* ssaoPass) : m_Renderer(renderer) , m_LightCullingPass(lightCullingPass) , m_CubeMapPass(cubeMapPass) , m_SSAOPass(ssaoPass) - , m_DepthBuffer(depthBuffer) { //TODO: Make sure that uniforms are not sent into shader if not needed. m_ShieldPixelRate = 8; @@ -30,30 +29,20 @@ void DrawFinalPass::InitializeFrameBuffers() //GenerateMipMapTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RGB16F, GL_FLOAT, 4); //GenerateTexture(&m_StencilTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_STENCIL, GL_STENCIL_INDEX8, GL_INT); - m_FinalPassFrameBuffer.AddResource(std::shared_ptr(new Texture2D(m_DepthBuffer, GL_DEPTH_STENCIL_ATTACHMENT))); + CommonFunctions::GenerateTexture(&m_DepthBuffer, GL_CLAMP_TO_BORDER, GL_NEAREST, + glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8); + + m_FinalPassFrameBuffer.AddResource(std::shared_ptr(new Texture2D(&m_DepthBuffer, GL_DEPTH_STENCIL_ATTACHMENT))); //m_FinalPassFrameBuffer.AddResource(std::shared_ptr(new Texture2D(&m_StencilTexture, GL_STENCIL_ATTACHMENT))); m_FinalPassFrameBuffer.AddResource(std::shared_ptr(new Texture2D(&m_SceneTexture, GL_COLOR_ATTACHMENT0))); m_FinalPassFrameBuffer.AddResource(std::shared_ptr(new Texture2D(&m_BloomTexture, GL_COLOR_ATTACHMENT1))); m_FinalPassFrameBuffer.Generate(); GLERROR("FBO generation"); - glGenRenderbuffers(1, &m_DepthBufferLowRes); - glBindRenderbuffer(GL_RENDERBUFFER, m_DepthBufferLowRes); - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, (int)(m_Renderer->GetViewportSize().Width/m_ShieldPixelRate), (int)(m_Renderer->GetViewportSize().Height/m_ShieldPixelRate)); - GLERROR("RenderBufferLowRes generation"); - - CommonFunctions::GenerateTexture(&m_SceneTextureLowRes, GL_CLAMP_TO_EDGE, GL_NEAREST, glm::vec2((int)(m_Renderer->GetViewportSize().Width/m_ShieldPixelRate), (int)(m_Renderer->GetViewportSize().Height/m_ShieldPixelRate)), GL_RGB16F, GL_RGB, GL_FLOAT); - //GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); - CommonFunctions::GenerateTexture(&m_BloomTextureLowRes, GL_CLAMP_TO_EDGE, GL_NEAREST, glm::vec2((int)(m_Renderer->GetViewportSize().Width/m_ShieldPixelRate), (int)(m_Renderer->GetViewportSize().Height/m_ShieldPixelRate)), GL_RGB16F, GL_RGB, GL_FLOAT); - //GenerateMipMapTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RGB16F, GL_FLOAT, 4); - //GenerateTexture(&m_StencilTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_STENCIL, GL_STENCIL_INDEX8, GL_INT); - - m_FinalPassFrameBufferLowRes.AddResource(std::shared_ptr(new RenderBuffer(&m_DepthBufferLowRes, GL_DEPTH_STENCIL_ATTACHMENT))); - //m_FinalPassFrameBufferLowRes.AddResource(std::shared_ptr(new Texture2D(&m_StencilTexture, GL_STENCIL_ATTACHMENT))); - m_FinalPassFrameBufferLowRes.AddResource(std::shared_ptr(new Texture2D(&m_SceneTextureLowRes, GL_COLOR_ATTACHMENT0))); - m_FinalPassFrameBufferLowRes.AddResource(std::shared_ptr(new Texture2D(&m_BloomTextureLowRes, GL_COLOR_ATTACHMENT1))); - m_FinalPassFrameBufferLowRes.Generate(); - GLERROR("FBO2 generation"); + CommonFunctions::GenerateTexture(&m_ShieldBuffer, GL_CLAMP_TO_BORDER, GL_NEAREST, + glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_DEPTH_COMPONENT32, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT); + m_ShieldDepthFrameBuffer.AddResource(std::shared_ptr(new Texture2D(&m_ShieldBuffer, GL_DEPTH_ATTACHMENT))); + m_ShieldDepthFrameBuffer.Generate(); } void DrawFinalPass::InitializeShaderPrograms() @@ -85,6 +74,7 @@ void DrawFinalPass::InitializeShaderPrograms() m_SpriteProgram->BindFragDataLocation(1, "bloomColor"); m_SpriteProgram->Link(); GLERROR("Creating sprite program"); + m_ForwardPlusSplatMapProgram = ResourceManager::Load("#ForwardPlusSplatMapProgram"); m_ForwardPlusSplatMapProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/ForwardPlus.vert.glsl"))); m_ForwardPlusSplatMapProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/ForwardPlusSplatMapRGB.frag.glsl"))); @@ -140,152 +130,184 @@ void DrawFinalPass::InitializeShaderPrograms() m_ForwardPlusSplatMapSkinnedProgram->BindFragDataLocation(1, "bloomColor"); m_ForwardPlusSplatMapSkinnedProgram->Link(); GLERROR("Creating Forward SplatMap Skinned program"); + + m_FillDepthStencilBufferProgram = ResourceManager::Load("#FillDepthBufferProgram"); + m_FillDepthStencilBufferProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/FillDepthBuffer.vert.glsl"))); + m_FillDepthStencilBufferProgram->Compile(); + m_FillDepthStencilBufferProgram->Link(); + GLERROR("Creating DepthFill program"); + + m_FillDepthStencilBufferSkinnedProgram = ResourceManager::Load("#FillDepthBufferProgramSkinned"); + m_FillDepthStencilBufferSkinnedProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/FillDepthBufferSkinned.vert.glsl"))); + m_FillDepthStencilBufferSkinnedProgram->Compile(); + m_FillDepthStencilBufferSkinnedProgram->Link(); + GLERROR("Creating DepthFill program"); + + + + + + m_ForwardPlusShieldCheckProgram = ResourceManager::Load("#ForwardPlusShieldCheckProgram"); + m_ForwardPlusShieldCheckProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/ForwardPlus.vert.glsl"))); + m_ForwardPlusShieldCheckProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/ForwardPlusShieldCheck.frag.glsl"))); + m_ForwardPlusShieldCheckProgram->Compile(); + m_ForwardPlusShieldCheckProgram->BindFragDataLocation(0, "sceneColor"); + m_ForwardPlusShieldCheckProgram->BindFragDataLocation(1, "bloomColor"); + m_ForwardPlusShieldCheckProgram->Link(); + GLERROR("Creating forward+ program"); + + m_ExplosionEffectShieldCheckProgram = ResourceManager::Load("#ExplosionEffectShieldCheckProgram"); + m_ExplosionEffectShieldCheckProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/ForwardPlus.vert.glsl"))); + m_ExplosionEffectShieldCheckProgram->AddShader(std::shared_ptr(new GeometryShader("Shaders/ExplosionEffect.geom.glsl"))); + m_ExplosionEffectShieldCheckProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/ForwardPlusShieldCheck.frag.glsl"))); + m_ExplosionEffectShieldCheckProgram->Compile(); + m_ExplosionEffectShieldCheckProgram->BindFragDataLocation(0, "sceneColor"); + m_ExplosionEffectShieldCheckProgram->BindFragDataLocation(1, "bloomColor"); + m_ExplosionEffectShieldCheckProgram->Link(); + GLERROR("Creating explosion program"); + + m_SpriteShieldCheckProgram = ResourceManager::Load("#SpriteShieldCheckProgram"); + m_SpriteShieldCheckProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/Sprite.vert.glsl"))); + m_SpriteShieldCheckProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/SpriteShieldCheck.frag.glsl"))); + m_SpriteShieldCheckProgram->Compile(); + m_SpriteShieldCheckProgram->BindFragDataLocation(0, "sceneColor"); + m_SpriteShieldCheckProgram->BindFragDataLocation(1, "bloomColor"); + m_SpriteShieldCheckProgram->Link(); + GLERROR("Creating sprite program"); + + m_ForwardPlusSplatMapShieldCheckProgram = ResourceManager::Load("#ForwardPlusSplatMapShieldCheckProgram"); + m_ForwardPlusSplatMapShieldCheckProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/ForwardPlus.vert.glsl"))); + m_ForwardPlusSplatMapShieldCheckProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/ForwardPlusSplatMapRGBShieldCheck.frag.glsl"))); + m_ForwardPlusSplatMapShieldCheckProgram->Compile(); + m_ForwardPlusSplatMapShieldCheckProgram->BindFragDataLocation(0, "sceneColor"); + m_ForwardPlusSplatMapShieldCheckProgram->BindFragDataLocation(1, "bloomColor"); + m_ForwardPlusSplatMapShieldCheckProgram->Link(); + GLERROR("Creating Forward SplatMap program"); + + m_ExplosionEffectSplatMapShieldCheckProgram = ResourceManager::Load("#ExplosionEffectSplatMapShieldCheckProgram"); + m_ExplosionEffectSplatMapShieldCheckProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/ForwardPlus.vert.glsl"))); + m_ExplosionEffectSplatMapShieldCheckProgram->AddShader(std::shared_ptr(new GeometryShader("Shaders/ExplosionEffect.geom.glsl"))); + m_ExplosionEffectSplatMapShieldCheckProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/ForwardPlusSplatMapRGBShieldCheck.frag.glsl"))); + m_ExplosionEffectSplatMapShieldCheckProgram->Compile(); + m_ExplosionEffectSplatMapShieldCheckProgram->BindFragDataLocation(0, "sceneColor"); + m_ExplosionEffectSplatMapShieldCheckProgram->BindFragDataLocation(1, "bloomColor"); + m_ExplosionEffectSplatMapShieldCheckProgram->Link(); + GLERROR("Creating explosion SplatMap program"); + + m_ForwardPlusSkinnedShieldCheckProgram = ResourceManager::Load("#ForwardPlusSkinnedShieldCheckProgram"); + m_ForwardPlusSkinnedShieldCheckProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/ForwardPlusSkinned.vert.glsl"))); + m_ForwardPlusSkinnedShieldCheckProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/ForwardPlusShieldCheck.frag.glsl"))); + m_ForwardPlusSkinnedShieldCheckProgram->Compile(); + m_ForwardPlusSkinnedShieldCheckProgram->BindFragDataLocation(0, "sceneColor"); + m_ForwardPlusSkinnedShieldCheckProgram->BindFragDataLocation(1, "bloomColor"); + m_ForwardPlusSkinnedShieldCheckProgram->Link(); + GLERROR("Creating forward+ Skinned program"); + + m_ExplosionEffectSkinnedShieldCheckProgram = ResourceManager::Load("#ExplosionEffectSkinnedShieldCheckProgram"); + m_ExplosionEffectSkinnedShieldCheckProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/ForwardPlusSkinned.vert.glsl"))); + m_ExplosionEffectSkinnedShieldCheckProgram->AddShader(std::shared_ptr(new GeometryShader("Shaders/ExplosionEffect.geom.glsl"))); + m_ExplosionEffectSkinnedShieldCheckProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/ForwardPlusShieldCheck.frag.glsl"))); + m_ExplosionEffectSkinnedShieldCheckProgram->Compile(); + m_ExplosionEffectSkinnedShieldCheckProgram->BindFragDataLocation(0, "sceneColor"); + m_ExplosionEffectSkinnedShieldCheckProgram->BindFragDataLocation(1, "bloomColor"); + m_ExplosionEffectSkinnedShieldCheckProgram->Link(); + GLERROR("Creating explosion Skinned program"); + + m_ExplosionEffectSplatMapSkinnedShieldCheckProgram = ResourceManager::Load("#ExplosionEffectSplatMapSkinnedShieldCheckProgram"); + m_ExplosionEffectSplatMapSkinnedShieldCheckProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/ForwardPlusSkinned.vert.glsl"))); + m_ExplosionEffectSplatMapSkinnedShieldCheckProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/ForwardPlusSplatMapRGBShieldCheck.frag.glsl"))); + m_ExplosionEffectSplatMapSkinnedShieldCheckProgram->Compile(); + m_ExplosionEffectSplatMapSkinnedShieldCheckProgram->BindFragDataLocation(0, "sceneColor"); + m_ExplosionEffectSplatMapSkinnedShieldCheckProgram->BindFragDataLocation(1, "bloomColor"); + m_ExplosionEffectSplatMapSkinnedShieldCheckProgram->Link(); + GLERROR("Creating Forward SplatMap Skinned program"); + + m_ForwardPlusSplatMapSkinnedShieldCheckProgram = ResourceManager::Load("#ForwardPlusSplatMapSkinnedShieldCheckProgram"); + m_ForwardPlusSplatMapSkinnedShieldCheckProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/ForwardPlusSkinned.vert.glsl"))); + m_ForwardPlusSplatMapSkinnedShieldCheckProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/ForwardPlusSplatMapRGBShieldCheck.frag.glsl"))); + m_ForwardPlusSplatMapSkinnedShieldCheckProgram->Compile(); + m_ForwardPlusSplatMapSkinnedShieldCheckProgram->BindFragDataLocation(0, "sceneColor"); + m_ForwardPlusSplatMapSkinnedShieldCheckProgram->BindFragDataLocation(1, "bloomColor"); + m_ForwardPlusSplatMapSkinnedShieldCheckProgram->Link(); + GLERROR("Creating Forward SplatMap Skinned program"); - m_ShieldToStencilProgram = ResourceManager::Load("#ShieldToStencilProgram"); - m_ShieldToStencilProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/ShieldStencil.vert.glsl"))); - m_ShieldToStencilProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/ShieldStencil.frag.glsl"))); - m_ShieldToStencilProgram->Compile(); - m_ShieldToStencilProgram->Link(); - GLERROR("Creating Shield program"); - - m_ShieldToStencilSkinnedProgram = ResourceManager::Load("#ShieldToStencilProgramSkinned"); - m_ShieldToStencilSkinnedProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/ShieldStencilSkinned.vert.glsl"))); - m_ShieldToStencilSkinnedProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/ShieldStencil.frag.glsl"))); - m_ShieldToStencilSkinnedProgram->Compile(); - m_ShieldToStencilSkinnedProgram->Link(); - GLERROR("Creating Shield Skinned program"); - - m_FillDepthBufferProgram = ResourceManager::Load("#FillDepthBufferProgram"); - m_FillDepthBufferProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/FillDepthBuffer.vert.glsl"))); - //m_FillDepthBufferProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/FillDepthBuffer.frag.glsl"))); - m_FillDepthBufferProgram->Compile(); - m_FillDepthBufferProgram->Link(); - GLERROR("Creating DepthFill program"); - - m_FillDepthBufferSkinnedProgram = ResourceManager::Load("#FillDepthBufferProgramSkinned"); - m_FillDepthBufferSkinnedProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/FillDepthBufferSkinned.vert.glsl"))); - //m_FillDepthBufferSkinnedProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/FillDepthBuffer.frag.glsl"))); - m_FillDepthBufferSkinnedProgram->Compile(); - m_FillDepthBufferSkinnedProgram->Link(); - GLERROR("Creating DepthFill program"); } void DrawFinalPass::Draw(RenderScene& scene) { GLERROR("Pre"); - DrawFinalPassState* state = new DrawFinalPassState(m_FinalPassFrameBuffer.GetHandle()); + DrawStencilState* stateDethp = new DrawStencilState(m_ShieldDepthFrameBuffer.GetHandle()); + //Draw shields to stencil + DrawToDepthStencilBuffer(scene.Jobs.ShieldObjects, scene); + GLERROR("StencilPass"); + delete stateDethp; + + + DrawFinalPassState* state = new DrawFinalPassState(m_FinalPassFrameBuffer.GetHandle()); if (scene.ClearDepth) { //glClear(GL_DEPTH_BUFFER_BIT); state->Disable(GL_DEPTH_TEST); + state->DepthMask(GL_FALSE); } //TODO: Do we need check for this or will it be per scene always? glClearStencil(0x00); glClear(GL_STENCIL_BUFFER_BIT); //Fill depth buffer - - state->StencilMask(0x00); - DrawModelRenderQueues(scene.Jobs.OpaqueObjects, scene); - GLERROR("OpaqueObjects"); - //state->BlendFunc(GL_ONE, GL_ONE); - state->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - //state->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - DrawModelRenderQueues(scene.Jobs.TransparentObjects, scene); - GLERROR("TransparentObjects"); - //state->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - DrawSprites(scene.Jobs.SpriteJob, scene); - GLERROR("SpriteJobs"); - - //DrawStencilState* stencilState = new DrawStencilState(m_FinalPassFrameBuffer.GetHandle()); - //Draw shields to stencil pass - state->StencilFunc(GL_ALWAYS, 1, 0xFF); - state->StencilMask(0xFF); - DrawShieldToStencilBuffer(scene.Jobs.ShieldObjects, scene); - GLERROR("StencilPass"); + state->Enable(GL_STENCIL_TEST); + state->StencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); + state->StencilFunc(GL_ALWAYS, 1, 0xFF); + state->StencilMask(0xFF); + state->DepthMask(GL_FALSE); + //DrawToDepthStencilBuffer(scene.Jobs.ShieldObjects, scene); + state->DepthMask(GL_TRUE); //Draw Opaque shielded objects + state->Disable(GL_STENCIL_TEST); state->StencilFunc(GL_NOTEQUAL, 1, 0xFF); state->StencilMask(0x00); - DrawModelRenderQueues(scene.Jobs.OpaqueShieldedObjects, scene); //might need changing + DrawModelRenderQueuesWithShieldCheck(scene.Jobs.OpaqueShieldedObjects, scene); //might need changing GLERROR("Shielded Opaque object"); + //Draw Opaque objects + //state->StencilMask(0x00); + DrawModelRenderQueues(scene.Jobs.OpaqueObjects, scene); + GLERROR("OpaqueObjects"); + + //state->Disable(GL_STENCIL_TEST); //Draw Transparen Shielded objects - DrawModelRenderQueues(scene.Jobs.TransparentShieldedObjects, scene); //might need changing + DrawModelRenderQueuesWithShieldCheck(scene.Jobs.TransparentObjects, scene); //might need changing GLERROR("Shielded Transparent objects"); + //Draw Transparen objects + //state->BlendFunc(GL_ONE, GL_ONE); + //state->StencilFunc(GL_EQUAL, 1, 0xFF); + state->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + //DrawModelRenderQueues(scene.Jobs.TransparentObjects, scene); + GLERROR("TransparentObjects"); + //state->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + DrawSprites(scene.Jobs.SpriteJob, scene); + GLERROR("SpriteJobs"); + + delete state; GLERROR("END"); - delete state; - - - DrawFinalPassState* stateLowRes = new DrawFinalPassState(m_FinalPassFrameBufferLowRes.GetHandle()); - //Draw the lowres texture that will be shown behind the shield. - stateLowRes->Enable(GL_SCISSOR_TEST); - stateLowRes->Enable(GL_DEPTH_TEST); - //TODO: Viewports and scissor should be in state - glViewport(0, 0, m_Renderer->GetViewportSize().Width/m_ShieldPixelRate, m_Renderer->GetViewportSize().Height/m_ShieldPixelRate); - glScissor(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height); - - glClearStencil(0x00); - glClear(GL_STENCIL_BUFFER_BIT); - - //TODO: This should not be here... - stateLowRes->StencilFunc(GL_ALWAYS, 1, 0xFF); - stateLowRes->StencilMask(0x00); - DrawToDepthBuffer(scene.Jobs.OpaqueObjects, scene); - DrawToDepthBuffer(scene.Jobs.TransparentObjects, scene); - - //Draw shields to stencil pass - stateLowRes->StencilFunc(GL_ALWAYS, 1, 0xFF); - stateLowRes->StencilMask(0xFF); - stateLowRes->Enable(GL_DEPTH_TEST); - DrawShieldToStencilBuffer(scene.Jobs.ShieldObjects, scene); - GLERROR("StencilPass"); - - //glClear(GL_DEPTH_BUFFER_BIT); - - stateLowRes->Enable(GL_DEPTH_TEST); - stateLowRes->StencilFunc(GL_LEQUAL, 1, 0xFF); - stateLowRes->StencilMask(0x00); - DrawModelRenderQueues(scene.Jobs.OpaqueObjects, scene); - GLERROR("OpaqueObjects"); - DrawModelRenderQueues(scene.Jobs.TransparentObjects, scene); - GLERROR("TransparentObjects"); - glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height); - glScissor(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height); - delete stateLowRes; + } void DrawFinalPass::ClearBuffer() { GLERROR("PRE"); - m_FinalPassFrameBufferLowRes.Bind(); - GLERROR("Bind LowRes"); - - glViewport(0, 0, m_Renderer->GetViewportSize().Width/m_ShieldPixelRate, m_Renderer->GetViewportSize().Height/m_ShieldPixelRate); - glScissor(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height); - GLERROR("ViewPort,Scissor LowRes"); - - glClearColor(0.f, 0.f, 0.f, 0.f); - GLERROR("1"); - - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); - GLERROR("2"); - - glDisable(GL_SCISSOR_TEST); - GLERROR("3"); - - m_FinalPassFrameBufferLowRes.Unbind(); - - GLERROR("prebind HighRes"); + m_ShieldDepthFrameBuffer.Bind(); + glClear(GL_DEPTH_BUFFER_BIT); + m_ShieldDepthFrameBuffer.Unbind(); m_FinalPassFrameBuffer.Bind(); GLERROR("Bind HighRes"); glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height); glScissor(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height); GLERROR("ViewPort,Scissor LowRes"); glClearColor(0.f, 0.f, 0.f, 0.f); - glClear(GL_COLOR_BUFFER_BIT); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_FinalPassFrameBuffer.Unbind(); GLERROR("END"); } @@ -294,39 +316,25 @@ void DrawFinalPass::ClearBuffer() void DrawFinalPass::OnWindowResize() { //InitializeFrameBuffers(); - + CommonFunctions::GenerateTexture(&m_DepthBuffer, GL_CLAMP_TO_BORDER, GL_NEAREST, + glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8); CommonFunctions::GenerateTexture(&m_SceneTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); CommonFunctions::GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); m_FinalPassFrameBuffer.Generate(); - - glBindRenderbuffer(GL_RENDERBUFFER, m_DepthBufferLowRes); - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, (int)(m_Renderer->GetViewportSize().Width/m_ShieldPixelRate), (int)(m_Renderer->GetViewportSize().Height/m_ShieldPixelRate)); - - CommonFunctions::GenerateTexture(&m_SceneTextureLowRes, GL_CLAMP_TO_EDGE, GL_NEAREST, glm::vec2((int)(m_Renderer->GetViewportSize().Width/m_ShieldPixelRate), (int)(m_Renderer->GetViewportSize().Height/m_ShieldPixelRate)), GL_RGB16F, GL_RGB, GL_FLOAT); - CommonFunctions::GenerateTexture(&m_BloomTextureLowRes, GL_CLAMP_TO_EDGE, GL_NEAREST, glm::vec2((int)(m_Renderer->GetViewportSize().Width/m_ShieldPixelRate), (int)(m_Renderer->GetViewportSize().Height/m_ShieldPixelRate)), GL_RGB16F, GL_RGB, GL_FLOAT); - m_FinalPassFrameBufferLowRes.Generate(); GLERROR("Error changing texture resolutions"); } void DrawFinalPass::DrawModelRenderQueues(std::list>& jobs, RenderScene& scene) { GLuint forwardHandle = m_ForwardPlusProgram->GetHandle(); - GLERROR("forwardHandle"); GLuint explosionHandle = m_ExplosionEffectProgram->GetHandle(); - GLERROR("explosionHandle"); GLuint explosionSplatMapHandle = m_ExplosionEffectSplatMapProgram->GetHandle(); - GLERROR("explosionSplatMapHandle"); - GLuint forwardSplatHandle = m_ForwardPlusSplatMapProgram->GetHandle(); - GLERROR("forwardSplatHandle"); + GLuint forwardSplatMapHandle = m_ForwardPlusSplatMapProgram->GetHandle(); GLuint forwardSkinnedHandle = m_ForwardPlusSkinnedProgram->GetHandle(); - GLERROR("forwardSkinnedHandle"); GLuint explosionSkinnedHandle = m_ExplosionEffectSkinnedProgram->GetHandle(); - GLERROR("explosionSkinnedHandle"); GLuint explosionSplatMapSkinnedHandle = m_ExplosionEffectSplatMapSkinnedProgram->GetHandle(); - GLERROR("explosionSplatMapSkinnedHandle"); GLuint forwardSplatMapSkinnedHandle = m_ForwardPlusSplatMapSkinnedProgram->GetHandle(); - GLERROR("forwardSplatSkinnedHandle"); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, m_LightCullingPass->LightSSBO()); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, m_LightCullingPass->LightGridSSBO()); @@ -340,71 +348,79 @@ void DrawFinalPass::DrawModelRenderQueues(std::list>& if (explosionEffectJob) { switch (explosionEffectJob->Type) { case RawModel::MaterialType::Basic: - case RawModel::MaterialType::SingleTextures: - { - if (explosionEffectJob->Model->IsSkinned()) { + case RawModel::MaterialType::SingleTextures: + { + if (explosionEffectJob->Model->IsSkinned()) { - m_ExplosionEffectSkinnedProgram->Bind(); - GLERROR("Bind ExplosionEffectSkinned program"); - //bind uniforms - BindExplosionUniforms(explosionSkinnedHandle, explosionEffectJob, scene); - //bind textures - BindExplosionTextures(explosionSkinnedHandle, explosionEffectJob); - glActiveTexture(GL_TEXTURE5); - glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); - glUniform3fv(glGetUniformLocation(explosionSkinnedHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); + m_ExplosionEffectSkinnedProgram->Bind(); + GLERROR("Bind ExplosionEffectSkinned program"); + //bind uniforms + BindExplosionUniforms(explosionSkinnedHandle, explosionEffectJob, scene); + //bind textures + BindExplosionTextures(explosionSkinnedHandle, explosionEffectJob); + glActiveTexture(GL_TEXTURE5); + glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); + glUniform3fv(glGetUniformLocation(explosionSkinnedHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); - std::vector frameBones; - if (explosionEffectJob->AnimationOffset.animation != nullptr) { - frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations, explosionEffectJob->AnimationOffset); - } else { - frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations); - } - glUniformMatrix4fv(glGetUniformLocation(explosionSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); - } else { - m_ExplosionEffectProgram->Bind(); - GLERROR("Bind ExplosionEffect program"); - //bind uniforms - BindExplosionUniforms(explosionHandle, explosionEffectJob, scene); - //bind textures - BindExplosionTextures(explosionHandle, explosionEffectJob); - glActiveTexture(GL_TEXTURE5); - glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); - glUniform3fv(glGetUniformLocation(explosionHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); + std::vector frameBones; + if (explosionEffectJob->AnimationOffset.animation != nullptr) { + frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations, explosionEffectJob->AnimationOffset); + } + else { + frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations); + } + glUniformMatrix4fv(glGetUniformLocation(explosionSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); + DrawSkinnedExplosionSetup(m_ExplosionEffectSkinnedProgram, explosionSkinnedHandle, explosionEffectJob, scene); + } + else { + m_ExplosionEffectProgram->Bind(); + GLERROR("Bind ExplosionEffect program"); + //bind uniforms + BindExplosionUniforms(explosionHandle, explosionEffectJob, scene); + //bind textures + BindExplosionTextures(explosionHandle, explosionEffectJob); + glActiveTexture(GL_TEXTURE5); + glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); + glUniform3fv(glGetUniformLocation(explosionHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); - } - break; - } - case RawModel::MaterialType::SplatMapping: - { - if (explosionEffectJob->Model->IsSkinned()) { - m_ExplosionEffectSplatMapSkinnedProgram->Bind(); - GLERROR("Bind ExplosionEffectSplatMapSkinned program"); - //bind uniforms - BindExplosionUniforms(explosionSplatMapSkinnedHandle, explosionEffectJob, scene); - //bind textures - BindExplosionTextures(explosionSplatMapSkinnedHandle, explosionEffectJob); - GLERROR("asdasd"); - std::vector frameBones; - if (explosionEffectJob->AnimationOffset.animation != nullptr) { - frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations, explosionEffectJob->AnimationOffset); - } else { - frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations); - } - glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); + DrawExplosionSetup(m_ExplosionEffectProgram, explosionHandle, explosionEffectJob, scene); + } + break; + } + case RawModel::MaterialType::SplatMapping: + { + if (explosionEffectJob->Model->IsSkinned()) { + m_ExplosionEffectSplatMapSkinnedProgram->Bind(); + GLERROR("Bind ExplosionEffectSplatMapSkinned program"); + //bind uniforms + BindExplosionUniforms(explosionSplatMapSkinnedHandle, explosionEffectJob, scene); + //bind textures + BindExplosionTextures(explosionSplatMapSkinnedHandle, explosionEffectJob); + GLERROR("asdasd"); + std::vector frameBones; + if (explosionEffectJob->AnimationOffset.animation != nullptr) { + frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations, explosionEffectJob->AnimationOffset); + } + else { + frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations); + } + glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); - } else { - m_ExplosionEffectSplatMapProgram->Bind(); - GLERROR("Bind ExplosionEffectSplatMap program"); - //bind uniforms - //bind uniforms - BindExplosionUniforms(explosionSplatMapHandle, explosionEffectJob, scene); - //bind textures - BindExplosionTextures(explosionSplatMapHandle, explosionEffectJob); - GLERROR("asdasd"); - } - break; - } + DrawSkinnedExplosionSetup(m_ExplosionEffectSplatMapSkinnedProgram, explosionSplatMapSkinnedHandle, explosionEffectJob, scene); + } + else { + m_ExplosionEffectSplatMapProgram->Bind(); + GLERROR("Bind ExplosionEffectSplatMap program"); + //bind uniforms + //bind uniforms + BindExplosionUniforms(explosionSplatMapHandle, explosionEffectJob, scene); + //bind textures + BindExplosionTextures(explosionSplatMapHandle, explosionEffectJob); + GLERROR("asdasd"); + DrawExplosionSetup(m_ExplosionEffectSplatMapProgram, explosionSplatMapHandle, explosionEffectJob, scene); + } + break; + } } glDisable(GL_CULL_FACE); @@ -414,132 +430,409 @@ void DrawFinalPass::DrawModelRenderQueues(std::list>& glDrawElements(GL_TRIANGLES, explosionEffectJob->EndIndex - explosionEffectJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(explosionEffectJob->StartIndex*sizeof(unsigned int))); glEnable(GL_CULL_FACE); GLERROR("explosion effect end"); - } else { - auto modelJob = std::dynamic_pointer_cast(job); - if (modelJob) { - //bind forward program - //TODO: JOHAN/TOBIAS: Bind shader based on ModelJob->ShaderID; - switch (modelJob->Type) { - case RawModel::MaterialType::Basic: - case RawModel::MaterialType::SingleTextures: - { - if (modelJob->Model->IsSkinned()) { - m_ForwardPlusSkinnedProgram->Bind(); - GLERROR("Bind ForwardPlusSkinnedProgram"); - //bind uniforms - BindModelUniforms(forwardSkinnedHandle, modelJob, scene); - //bind textures - BindModelTextures(forwardSkinnedHandle, modelJob); - glActiveTexture(GL_TEXTURE5); - glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); - glUniform3fv(glGetUniformLocation(forwardSkinnedHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); + } else { + auto modelJob = std::dynamic_pointer_cast(job); + if (modelJob) { + //bind forward program + //TODO: JOHAN/TOBIAS: Bind shader based on ModelJob->ShaderID; + switch (modelJob->Type) { + case RawModel::MaterialType::Basic: + case RawModel::MaterialType::SingleTextures: + { + if (modelJob->Model->IsSkinned()) { + m_ForwardPlusSkinnedProgram->Bind(); + GLERROR("Bind ForwardPlusSkinnedProgram"); + //bind uniforms + BindModelUniforms(forwardSkinnedHandle, modelJob, scene); + //bind textures + BindModelTextures(forwardSkinnedHandle, modelJob); + glActiveTexture(GL_TEXTURE5); + glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); + glUniform3fv(glGetUniformLocation(forwardSkinnedHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); - std::vector frameBones; - if (modelJob->AnimationOffset.animation != nullptr) { - frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset); - } else { - frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations); - } - glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); + std::vector frameBones; + if (modelJob->AnimationOffset.animation != nullptr) { + frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset); + } + else { + frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations); + } + glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); - } else { - m_ForwardPlusProgram->Bind(); - GLERROR("Bind ForwardPlusProgram"); - //bind uniforms - BindModelUniforms(forwardHandle, modelJob, scene); - //bind textures - BindModelTextures(forwardHandle, modelJob); - glActiveTexture(GL_TEXTURE5); - glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); - glUniform3fv(glGetUniformLocation(forwardHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); - } - break; - } - case RawModel::MaterialType::SplatMapping: - { - if (modelJob->Model->IsSkinned()) { - m_ForwardPlusSplatMapSkinnedProgram->Bind(); - GLERROR("Bind SplatMap program"); - //bind uniforms - BindModelUniforms(forwardSplatMapSkinnedHandle, modelJob, scene); - //bind textures - BindModelTextures(forwardSplatMapSkinnedHandle, modelJob); - GLERROR("asdasd"); - std::vector frameBones; - if (modelJob->AnimationOffset.animation != nullptr) { - frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset); - } else { - frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations); - } - glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); + } + else { + m_ForwardPlusProgram->Bind(); + GLERROR("Bind ForwardPlusProgram"); + //bind uniforms + BindModelUniforms(forwardHandle, modelJob, scene); + //bind textures + BindModelTextures(forwardHandle, modelJob); + glActiveTexture(GL_TEXTURE5); + glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); + glUniform3fv(glGetUniformLocation(forwardHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); + } + break; + } + case RawModel::MaterialType::SplatMapping: + { + if (modelJob->Model->IsSkinned()) { + m_ForwardPlusSplatMapSkinnedProgram->Bind(); + GLERROR("Bind SplatMap program"); + //bind uniforms + BindModelUniforms(forwardSplatMapSkinnedHandle, modelJob, scene); + //bind textures + BindModelTextures(forwardSplatMapSkinnedHandle, modelJob); + GLERROR("asdasd"); + std::vector frameBones; + if (modelJob->AnimationOffset.animation != nullptr) { + frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset); + } + else { + frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations); + } + glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); - } else { - m_ForwardPlusSplatMapProgram->Bind(); - GLERROR("Bind SplatMap program"); - //bind uniforms - BindModelUniforms(forwardSplatHandle, modelJob, scene); - //bind textures - BindModelTextures(forwardSplatHandle, modelJob); - GLERROR("asdasd"); - } - break; - } - } - //draw - glBindVertexArray(modelJob->Model->VAO); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); - glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex*sizeof(unsigned int))); - if (GLERROR("models end")) { - continue; - } + } + else { + m_ForwardPlusSplatMapProgram->Bind(); + GLERROR("Bind SplatMap program"); + //bind uniforms + BindModelUniforms(forwardSplatMapHandle, modelJob, scene); + //bind textures + BindModelTextures(forwardSplatMapHandle, modelJob); + GLERROR("asdasd"); + } + break; + } } - } - } -} - - -void DrawFinalPass::DrawShieldToStencilBuffer(std::list>& jobs, RenderScene& scene) -{ - - - for (auto &job : jobs) { - auto modelJob = std::dynamic_pointer_cast(job); - if (modelJob) { - - if(modelJob->Model->IsSkinned()) { - m_ShieldToStencilSkinnedProgram->Bind(); - GLuint shaderHandle = m_ShieldToStencilSkinnedProgram->GetHandle(); - - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix())); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix())); - std::vector frameBones; - if (modelJob->AnimationOffset.animation != nullptr) { - frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset); - } else { - frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations); + //draw + glBindVertexArray(modelJob->Model->VAO); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); + glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex*sizeof(unsigned int))); + if (GLERROR("models end")) { + continue; } - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); - } else { - m_ShieldToStencilProgram->Bind(); - GLuint shaderHandle = m_ShieldToStencilProgram->GetHandle(); - - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix())); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix())); - - } - - glBindVertexArray(modelJob->Model->VAO); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); - glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex*sizeof(unsigned int))); - if (GLERROR("models end")) { - continue; } } } } +void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list>& jobs, RenderScene& scene) +{ + GLuint forwardHandle = m_ForwardPlusProgram->GetHandle(); + GLuint explosionHandle = m_ExplosionEffectProgram->GetHandle(); + GLuint explosionSplatMapHandle = m_ExplosionEffectSplatMapProgram->GetHandle(); + GLuint forwardSplatMapHandle = m_ForwardPlusSplatMapProgram->GetHandle(); + GLuint forwardSkinnedHandle = m_ForwardPlusSkinnedProgram->GetHandle(); + GLuint explosionSkinnedHandle = m_ExplosionEffectSkinnedProgram->GetHandle(); + GLuint explosionSplatMapSkinnedHandle = m_ExplosionEffectSplatMapSkinnedProgram->GetHandle(); + GLuint forwardSplatMapSkinnedHandle = m_ForwardPlusSplatMapSkinnedProgram->GetHandle(); + + GLuint forwardShieldCheckHandle = m_ForwardPlusShieldCheckProgram->GetHandle(); + GLuint explosionShieldCheckHandle = m_ExplosionEffectShieldCheckProgram->GetHandle(); + GLuint explosionSplatMapShieldCheckHandle = m_ExplosionEffectSplatMapShieldCheckProgram->GetHandle(); + GLuint forwardSplatShieldCheckHandle = m_ForwardPlusSplatMapShieldCheckProgram->GetHandle(); + GLuint forwardSkinnedShieldCheckHandle = m_ForwardPlusSkinnedShieldCheckProgram->GetHandle(); + GLuint explosionSkinnedShieldCheckHandle = m_ExplosionEffectSkinnedShieldCheckProgram->GetHandle(); + GLuint explosionSplatMapSkinnedShieldCheckHandle = m_ExplosionEffectSplatMapSkinnedShieldCheckProgram->GetHandle(); + GLuint forwardSplatMapSkinnedShieldCheckHandle = m_ForwardPlusSplatMapSkinnedShieldCheckProgram->GetHandle(); + + glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, m_LightCullingPass->LightSSBO()); + glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, m_LightCullingPass->LightGridSSBO()); + glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, m_LightCullingPass->LightIndexSSBO()); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, m_SSAOPass->SSAOTexture()); + + glActiveTexture(GL_TEXTURE31); + glBindTexture(GL_TEXTURE_2D, m_ShieldBuffer); + + for (auto &job : jobs) { + auto explosionEffectJob = std::dynamic_pointer_cast(job); + if (explosionEffectJob) { + if (explosionEffectJob->IsShielded) { + switch (explosionEffectJob->Type) { + case RawModel::MaterialType::Basic: + case RawModel::MaterialType::SingleTextures: + { + if (explosionEffectJob->Model->IsSkinned()) { + + m_ExplosionEffectSkinnedShieldCheckProgram->Bind(); + GLERROR("Bind ExplosionEffectSkinned program"); + //bind uniforms + BindExplosionUniforms(explosionSkinnedShieldCheckHandle, explosionEffectJob, scene); + //bind textures + BindExplosionTextures(explosionSkinnedShieldCheckHandle, explosionEffectJob); + glActiveTexture(GL_TEXTURE5); + glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); + glUniform3fv(glGetUniformLocation(explosionSkinnedShieldCheckHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); + + std::vector frameBones; + if (explosionEffectJob->AnimationOffset.animation != nullptr) { + frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations, explosionEffectJob->AnimationOffset); + } + else { + frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations); + } + glUniformMatrix4fv(glGetUniformLocation(explosionSkinnedShieldCheckHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); + } + else { + m_ExplosionEffectShieldCheckProgram->Bind(); + GLERROR("Bind ExplosionEffect program"); + //bind uniforms + BindExplosionUniforms(explosionShieldCheckHandle, explosionEffectJob, scene); + //bind textures + BindExplosionTextures(explosionShieldCheckHandle, explosionEffectJob); + glActiveTexture(GL_TEXTURE5); + glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); + glUniform3fv(glGetUniformLocation(explosionShieldCheckHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); + + } + break; + } + case RawModel::MaterialType::SplatMapping: + { + if (explosionEffectJob->Model->IsSkinned()) { + m_ExplosionEffectSplatMapSkinnedShieldCheckProgram->Bind(); + GLERROR("Bind ExplosionEffectSplatMapSkinned program"); + //bind uniforms + BindExplosionUniforms(explosionSplatMapSkinnedShieldCheckHandle, explosionEffectJob, scene); + //bind textures + BindExplosionTextures(explosionSplatMapSkinnedShieldCheckHandle, explosionEffectJob); + GLERROR("asdasd"); + std::vector frameBones; + if (explosionEffectJob->AnimationOffset.animation != nullptr) { + frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations, explosionEffectJob->AnimationOffset); + } + else { + frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations); + } + glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapSkinnedShieldCheckHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); + + } + else { + m_ExplosionEffectSplatMapShieldCheckProgram->Bind(); + GLERROR("Bind ExplosionEffectSplatMap program"); + //bind uniforms + //bind uniforms + BindExplosionUniforms(explosionSplatMapShieldCheckHandle, explosionEffectJob, scene); + //bind textures + BindExplosionTextures(explosionSplatMapShieldCheckHandle, explosionEffectJob); + GLERROR("asdasd"); + } + break; + } + } + } + else { + switch (explosionEffectJob->Type) { + case RawModel::MaterialType::Basic: + case RawModel::MaterialType::SingleTextures: + { + if (explosionEffectJob->Model->IsSkinned()) { + DrawSkinnedExplosionSetup(m_ExplosionEffectSkinnedProgram, explosionSkinnedHandle, explosionEffectJob, scene); + } + else { + DrawExplosionSetup(m_ExplosionEffectProgram, explosionHandle, explosionEffectJob, scene); + } + break; + } + case RawModel::MaterialType::SplatMapping: + { + if (explosionEffectJob->Model->IsSkinned()) { + DrawSkinnedExplosionSetup(m_ExplosionEffectSplatMapSkinnedProgram, explosionSplatMapSkinnedHandle, explosionEffectJob, scene); + } + else { + DrawExplosionSetup(m_ExplosionEffectSplatMapProgram, explosionSplatMapHandle, explosionEffectJob, scene); + } + break; + } + } + } + glDisable(GL_CULL_FACE); + + //draw + glBindVertexArray(explosionEffectJob->Model->VAO); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, explosionEffectJob->Model->ElementBuffer); + glDrawElements(GL_TRIANGLES, explosionEffectJob->EndIndex - explosionEffectJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(explosionEffectJob->StartIndex*sizeof(unsigned int))); + glEnable(GL_CULL_FACE); + GLERROR("explosion effect end"); + } else { + auto explosionEffectJob = std::dynamic_pointer_cast(job); + if (explosionEffectJob) { + switch (explosionEffectJob->Type) { + case RawModel::MaterialType::Basic: + case RawModel::MaterialType::SingleTextures: + { + if (explosionEffectJob->Model->IsSkinned()) { + + m_ExplosionEffectSkinnedProgram->Bind(); + GLERROR("Bind ExplosionEffectSkinned program"); + //bind uniforms + BindExplosionUniforms(explosionSkinnedHandle, explosionEffectJob, scene); + //bind textures + BindExplosionTextures(explosionSkinnedHandle, explosionEffectJob); + glActiveTexture(GL_TEXTURE5); + glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); + glUniform3fv(glGetUniformLocation(explosionSkinnedHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); + + std::vector frameBones; + if (explosionEffectJob->AnimationOffset.animation != nullptr) { + frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations, explosionEffectJob->AnimationOffset); + } + else { + frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations); + } + glUniformMatrix4fv(glGetUniformLocation(explosionSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); + DrawSkinnedExplosionSetup(m_ExplosionEffectSkinnedProgram, explosionSkinnedHandle, explosionEffectJob, scene); + } + else { + m_ExplosionEffectProgram->Bind(); + GLERROR("Bind ExplosionEffect program"); + //bind uniforms + BindExplosionUniforms(explosionHandle, explosionEffectJob, scene); + //bind textures + BindExplosionTextures(explosionHandle, explosionEffectJob); + glActiveTexture(GL_TEXTURE5); + glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); + glUniform3fv(glGetUniformLocation(explosionHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); + + DrawExplosionSetup(m_ExplosionEffectProgram, explosionHandle, explosionEffectJob, scene); + } + break; + } + case RawModel::MaterialType::SplatMapping: + { + if (explosionEffectJob->Model->IsSkinned()) { + m_ExplosionEffectSplatMapSkinnedProgram->Bind(); + GLERROR("Bind ExplosionEffectSplatMapSkinned program"); + //bind uniforms + BindExplosionUniforms(explosionSplatMapSkinnedHandle, explosionEffectJob, scene); + //bind textures + BindExplosionTextures(explosionSplatMapSkinnedHandle, explosionEffectJob); + GLERROR("asdasd"); + std::vector frameBones; + if (explosionEffectJob->AnimationOffset.animation != nullptr) { + frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations, explosionEffectJob->AnimationOffset); + } + else { + frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations); + } + glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); + + DrawSkinnedExplosionSetup(m_ExplosionEffectSplatMapSkinnedProgram, explosionSplatMapSkinnedHandle, explosionEffectJob, scene); + } + else { + m_ExplosionEffectSplatMapProgram->Bind(); + GLERROR("Bind ExplosionEffectSplatMap program"); + //bind uniforms + //bind uniforms + BindExplosionUniforms(explosionSplatMapHandle, explosionEffectJob, scene); + //bind textures + BindExplosionTextures(explosionSplatMapHandle, explosionEffectJob); + GLERROR("asdasd"); + DrawExplosionSetup(m_ExplosionEffectSplatMapProgram, explosionSplatMapHandle, explosionEffectJob, scene); + } + break; + } + } + glDisable(GL_CULL_FACE); + + //draw + glBindVertexArray(explosionEffectJob->Model->VAO); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, explosionEffectJob->Model->ElementBuffer); + glDrawElements(GL_TRIANGLES, explosionEffectJob->EndIndex - explosionEffectJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(explosionEffectJob->StartIndex*sizeof(unsigned int))); + glEnable(GL_CULL_FACE); + GLERROR("explosion effect end"); + } + else { + auto modelJob = std::dynamic_pointer_cast(job); + if (modelJob) { + //bind forward program + //TODO: JOHAN/TOBIAS: Bind shader based on ModelJob->ShaderID; + switch (modelJob->Type) { + case RawModel::MaterialType::Basic: + case RawModel::MaterialType::SingleTextures: + { + if (modelJob->Model->IsSkinned()) { + m_ForwardPlusSkinnedProgram->Bind(); + GLERROR("Bind ForwardPlusSkinnedProgram"); + //bind uniforms + BindModelUniforms(forwardSkinnedHandle, modelJob, scene); + //bind textures + BindModelTextures(forwardSkinnedHandle, modelJob); + glActiveTexture(GL_TEXTURE5); + glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); + glUniform3fv(glGetUniformLocation(forwardSkinnedHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); + + std::vector frameBones; + if (modelJob->AnimationOffset.animation != nullptr) { + frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset); + } + else { + frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations); + } + glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); + + } + else { + m_ForwardPlusProgram->Bind(); + GLERROR("Bind ForwardPlusProgram"); + //bind uniforms + BindModelUniforms(forwardHandle, modelJob, scene); + //bind textures + BindModelTextures(forwardHandle, modelJob); + glActiveTexture(GL_TEXTURE5); + glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); + glUniform3fv(glGetUniformLocation(forwardHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); + } + break; + } + case RawModel::MaterialType::SplatMapping: + { + if (modelJob->Model->IsSkinned()) { + m_ForwardPlusSplatMapSkinnedProgram->Bind(); + GLERROR("Bind SplatMap program"); + //bind uniforms + BindModelUniforms(forwardSplatMapSkinnedHandle, modelJob, scene); + //bind textures + BindModelTextures(forwardSplatMapSkinnedHandle, modelJob); + GLERROR("asdasd"); + std::vector frameBones; + if (modelJob->AnimationOffset.animation != nullptr) { + frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset); + } + else { + frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations); + } + glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); + + } + else { + m_ForwardPlusSplatMapProgram->Bind(); + GLERROR("Bind SplatMap program"); + //bind uniforms + BindModelUniforms(forwardSplatMapHandle, modelJob, scene); + //bind textures + BindModelTextures(forwardSplatMapHandle, modelJob); + GLERROR("asdasd"); + } + break; + } + } + //draw + glBindVertexArray(modelJob->Model->VAO); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); + glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex*sizeof(unsigned int))); + if (GLERROR("models end")) { + continue; + } + } + } + } + } +} + void DrawFinalPass::DrawShieldedModelRenderQueue(std::list>& jobs, RenderScene& scene) { GLuint forwardHandle = m_ForwardPlusProgram->GetHandle(); @@ -632,7 +925,7 @@ void DrawFinalPass::DrawShieldedModelRenderQueue(std::list>& jobs, RenderScene& scene) +void DrawFinalPass::DrawToDepthStencilBuffer(std::list>& jobs, RenderScene& scene) { @@ -640,8 +933,8 @@ void DrawFinalPass::DrawToDepthBuffer(std::list>& job auto modelJob = std::dynamic_pointer_cast(job); if(modelJob->Model->IsSkinned()) { - m_FillDepthBufferSkinnedProgram->Bind(); - GLuint shaderHandle = m_FillDepthBufferSkinnedProgram->GetHandle(); + m_FillDepthStencilBufferSkinnedProgram->Bind(); + GLuint shaderHandle = m_FillDepthStencilBufferSkinnedProgram->GetHandle(); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix())); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix())); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); @@ -655,8 +948,8 @@ void DrawFinalPass::DrawToDepthBuffer(std::list>& job glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); } else { - m_FillDepthBufferProgram->Bind(); - GLuint shaderHandle = m_FillDepthBufferProgram->GetHandle(); + m_FillDepthStencilBufferProgram->Bind(); + GLuint shaderHandle = m_FillDepthStencilBufferProgram->GetHandle(); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix())); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix())); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); @@ -720,6 +1013,76 @@ void DrawFinalPass::DrawSprites(std::list>&jobs, Rend // m_SpriteProgram->Unbind(); } +void DrawFinalPass::DrawExplosionSetup(ShaderProgram* shader, GLuint shaderHandle, std::shared_ptr& job, RenderScene& scene) +{ + shader->Bind(); + GLERROR("Bind ExplosionEffect program"); + //bind uniforms + BindExplosionUniforms(shaderHandle, job, scene); + //bind textures + BindExplosionTextures(shaderHandle, job); + glActiveTexture(GL_TEXTURE5); + glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); + glUniform3fv(glGetUniformLocation(shaderHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); +} + +void DrawFinalPass::DrawSkinnedExplosionSetup(ShaderProgram* shader, GLuint shaderHandle, std::shared_ptr& job, RenderScene& scene) +{ + shader->Bind(); + GLERROR("Bind ExplosionEffectSkinned program"); + //bind uniforms + BindExplosionUniforms(shaderHandle, job, scene); + //bind textures + BindExplosionTextures(shaderHandle, job); + glActiveTexture(GL_TEXTURE5); + glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); + glUniform3fv(glGetUniformLocation(shaderHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); + + std::vector frameBones; + if (job->AnimationOffset.animation != nullptr) { + frameBones = job->Skeleton->GetFrameBones(job->Animations, job->AnimationOffset); + } + else { + frameBones = job->Skeleton->GetFrameBones(job->Animations); + } + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); +} + +void DrawFinalPass::DrawModelSetup(ShaderProgram* shader, GLuint shaderHandle, std::shared_ptr& job, RenderScene& scene) +{ + m_ForwardPlusProgram->Bind(); + GLERROR("Bind ForwardPlusProgram"); + //bind uniforms + BindModelUniforms(shaderHandle, job, scene); + //bind textures + BindModelTextures(shaderHandle, job); + glActiveTexture(GL_TEXTURE5); + glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); + glUniform3fv(glGetUniformLocation(shaderHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); +} + +void DrawFinalPass::DrawSkinnedModelSetup(ShaderProgram* shader, GLuint shaderHandle , std::shared_ptr& job, RenderScene& scene) +{ + shader->Bind(); + GLERROR("Bind ForwardPlusSkinnedProgram"); + //bind uniforms + BindModelUniforms(shaderHandle, job, scene); + //bind textures + BindModelTextures(shaderHandle, job); + glActiveTexture(GL_TEXTURE5); + glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); + glUniform3fv(glGetUniformLocation(shaderHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); + + std::vector frameBones; + if (job->AnimationOffset.animation != nullptr) { + frameBones = job->Skeleton->GetFrameBones(job->Animations, job->AnimationOffset); + } + else { + frameBones = job->Skeleton->GetFrameBones(job->Animations); + } + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); +} + void DrawFinalPass::BindExplosionUniforms(GLuint shaderHandle, std::shared_ptr& job, RenderScene& scene) { glUniform1i(glGetUniformLocation(shaderHandle, "SSAOQuality"), m_SSAOPass->TextureQuality()); diff --git a/src/Engine/Rendering/DrawFinalPassState.cpp b/src/Engine/Rendering/DrawFinalPassState.cpp index 6e1e3473..62500fa5 100644 --- a/src/Engine/Rendering/DrawFinalPassState.cpp +++ b/src/Engine/Rendering/DrawFinalPassState.cpp @@ -8,13 +8,12 @@ DrawFinalPassState::DrawFinalPassState(GLuint frameBuffer) Enable(GL_BLEND); BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); Enable(GL_DEPTH_TEST); - DepthMask(GL_FALSE); - DepthFunc(GL_LEQUAL); + DepthMask(GL_TRUE); Enable(GL_CULL_FACE); - Enable(GL_STENCIL_TEST); - StencilFunc(GL_NOTEQUAL, 1, 0xFF); - StencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); - StencilMask(0xFF); + // Enable(GL_STENCIL_TEST); + // StencilFunc(GL_NOTEQUAL, 1, 0xFF); + // StencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); + // StencilMask(0xFF); ClearColor(glm::vec4(0.f, 0.f, 0.f, 0.f)); } @@ -26,11 +25,8 @@ DrawFinalPassState::~DrawFinalPassState() DrawStencilState::DrawStencilState(GLuint frameBuffer) { BindFramebuffer(frameBuffer); - Enable(GL_STENCIL_TEST); - StencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); - StencilFunc(GL_ALWAYS, 1, 0xFF); - StencilMask(0xFF); Enable(GL_DEPTH_TEST); + DepthMask(GL_TRUE); ClearColor(glm::vec4(0.f)); } diff --git a/src/Engine/Rendering/PickingPass.cpp b/src/Engine/Rendering/PickingPass.cpp index fb58edf7..7b9e2498 100644 --- a/src/Engine/Rendering/PickingPass.cpp +++ b/src/Engine/Rendering/PickingPass.cpp @@ -23,11 +23,12 @@ void PickingPass::InitializeTextures() glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RG8, GL_RG, GL_UNSIGNED_BYTE); CommonFunctions::GenerateTexture(&m_DepthBuffer, GL_CLAMP_TO_BORDER, GL_NEAREST, - glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8); + glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_DEPTH_COMPONENT32, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT); } void PickingPass::InitializeFrameBuffers() { + m_PickingBuffer.AddResource(std::shared_ptr(new Texture2D(&m_DepthBuffer, GL_DEPTH_ATTACHMENT))); m_PickingBuffer.AddResource(std::shared_ptr(new Texture2D(&m_PickingTexture, GL_COLOR_ATTACHMENT0))); m_PickingBuffer.Generate(); diff --git a/src/Engine/Rendering/RenderSystem.cpp b/src/Engine/Rendering/RenderSystem.cpp index 7b0ea84f..a1f00c88 100644 --- a/src/Engine/Rendering/RenderSystem.cpp +++ b/src/Engine/Rendering/RenderSystem.cpp @@ -240,6 +240,8 @@ void RenderSystem::fillModels(RenderScene::Queues &Jobs) fillColor = (glm::vec4)fillComponent["Color"]; } + bool isShielded = m_World->HasComponent(cModel.EntityID, "Shielded") || m_World->HasComponent(cModel.EntityID, "Player"); + glm::mat4 modelMatrix = Transform::ModelMatrix(cModel.EntityID, m_World); //Loop through all materialgroups of a model for (auto matGroup : model->MaterialGroups()) { @@ -255,20 +257,19 @@ void RenderSystem::fillModels(RenderScene::Queues &Jobs) cModel, m_World, fillColor, - fillPercentage + fillPercentage, + isShielded )); if (m_World->HasComponent(cModel.EntityID, "Shield")){ explosionEffectJob->CalculateHash(); Jobs.ShieldObjects.push_back(explosionEffectJob); - } else if (m_World->HasComponent(cModel.EntityID, "Shielded") - || m_World->HasComponent(cModel.EntityID, "Player")) { - + } else if (isShielded) { if (explosionEffectJob->Color.a != 1.f || explosionEffectJob->EndColor.a != 1.f || explosionEffectJob->DiffuseColor.a != 1.f) { cModel["Transparent"] = true; } if (cModel["Transparent"]) { - Jobs.TransparentShieldedObjects.push_back(explosionEffectJob); + Jobs.TransparentObjects.push_back(explosionEffectJob); } else { explosionEffectJob->CalculateHash(); Jobs.OpaqueShieldedObjects.push_back(explosionEffectJob); @@ -294,20 +295,20 @@ void RenderSystem::fillModels(RenderScene::Queues &Jobs) cModel, m_World, fillColor, - fillPercentage + fillPercentage, + isShielded )); if (m_World->HasComponent(cModel.EntityID, "Shield")) { modelJob->CalculateHash(); Jobs.ShieldObjects.push_back(modelJob); - } else if (m_World->HasComponent(cModel.EntityID, "Shielded") - || m_World->HasComponent(cModel.EntityID, "Player")) { + } else if (isShielded) { if (modelJob->Color.a != 1.f || modelJob->DiffuseColor.a != 1.f) { cModel["Transparent"] = true; } if (cModel["Transparent"]) { - Jobs.TransparentShieldedObjects.push_back(modelJob); + Jobs.TransparentObjects.push_back(modelJob); } else { modelJob->CalculateHash(); Jobs.OpaqueShieldedObjects.push_back(modelJob); diff --git a/src/Engine/Rendering/Renderer.cpp b/src/Engine/Rendering/Renderer.cpp index e590cd97..3ce985b6 100644 --- a/src/Engine/Rendering/Renderer.cpp +++ b/src/Engine/Rendering/Renderer.cpp @@ -110,7 +110,7 @@ void Renderer::Draw(RenderFrame& frame) { GLERROR("PRE"); glBindFramebuffer(GL_FRAMEBUFFER, 0); - ImGui::Combo("Draw textures", &m_DebugTextureToDraw, "Final\0Scene\0Bloom\0SceneLowRes\0BloomLowRes\0Gaussian\0Picking\0Ambient Occlusion"); + ImGui::Combo("Draw textures", &m_DebugTextureToDraw, "Final\0Scene\0Bloom\0Gaussian\0Picking\0Ambient Occlusion"); ImGui::Combo("CubeMap", &m_CubeMapTexture, "Nevada(512)\0Sky(1024)"); if(m_CubeMapTexture == 0) { m_CubeMapPass->LoadTextures("Nevada"); @@ -174,7 +174,7 @@ void Renderer::Draw(RenderFrame& frame) if (m_DebugTextureToDraw == 0) { PerformanceTimer::StartTimer("Renderer-Color Correction Pass"); - m_DrawColorCorrectionPass->Draw(m_DrawFinalPass->SceneTexture(), m_DrawBloomPass->GaussianTexture(), m_DrawFinalPass->SceneTextureLowRes(), m_DrawFinalPass->BloomTextureLowRes(), frame.Gamma, frame.Exposure); + m_DrawColorCorrectionPass->Draw(m_DrawFinalPass->SceneTexture(), m_DrawBloomPass->GaussianTexture(), frame.Gamma, frame.Exposure); PerformanceTimer::StopTimer("Renderer-Color Correction Pass"); } @@ -186,18 +186,12 @@ void Renderer::Draw(RenderFrame& frame) m_DrawScreenQuadPass->Draw(m_DrawFinalPass->BloomTexture()); } if (m_DebugTextureToDraw == 3) { - m_DrawScreenQuadPass->Draw(m_DrawFinalPass->SceneTextureLowRes()); - } - if (m_DebugTextureToDraw == 4) { - m_DrawScreenQuadPass->Draw(m_DrawFinalPass->BloomTextureLowRes()); - } - if (m_DebugTextureToDraw == 5) { m_DrawScreenQuadPass->Draw(m_DrawBloomPass->GaussianTexture()); } - if (m_DebugTextureToDraw == 6) { + if (m_DebugTextureToDraw == 4) { m_DrawScreenQuadPass->Draw(m_PickingPass->PickingTexture()); } - if (m_DebugTextureToDraw == 7) { + if (m_DebugTextureToDraw == 5) { m_DrawScreenQuadPass->Draw(m_SSAOPass->SSAOTexture()); } PerformanceTimer::StopTimer("Renderer-Misc Debug Draws"); @@ -250,7 +244,7 @@ void Renderer::InitializeRenderPasses() m_LightCullingPass = new LightCullingPass(this); m_CubeMapPass = new CubeMapPass(this); m_SSAOPass = new SSAOPass(this, m_Config); - m_DrawFinalPass = new DrawFinalPass(this, m_LightCullingPass, m_CubeMapPass, m_SSAOPass, m_PickingPass->DepthBuffer()); + m_DrawFinalPass = new DrawFinalPass(this, m_LightCullingPass, m_CubeMapPass, m_SSAOPass); m_DrawScreenQuadPass = new DrawScreenQuadPass(this); m_DrawBloomPass = new DrawBloomPass(this, m_Config); m_DrawColorCorrectionPass = new DrawColorCorrectionPass(this); From 96768e66de68b699ad802933ec70afefc84581ee Mon Sep 17 00:00:00 2001 From: Tleety Date: Wed, 2 Mar 2016 09:57:41 +0100 Subject: [PATCH 062/130] Redplayer arrow fix --- resources/Schema/Entities/PlayerRed.xml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/resources/Schema/Entities/PlayerRed.xml b/resources/Schema/Entities/PlayerRed.xml index 7f81ab05..fab8e21e 100644 --- a/resources/Schema/Entities/PlayerRed.xml +++ b/resources/Schema/Entities/PlayerRed.xml @@ -13,7 +13,7 @@ - 361.81593010381596 + 384.13256760035051 @@ -373,7 +373,7 @@ Idle - 1.6231050125476969 + 0.75626404186195373 1 @@ -417,11 +417,15 @@ Models/Weapons/Blue/AssaultWeaponBlue.mesh - + + + + + - + @@ -446,7 +450,7 @@ Idle - 1.8847063959212136 + 1.1511986314122282 1 From 5a6374f013f40ba8f78dfc33cc969ae711420c88 Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Wed, 2 Mar 2016 10:57:22 +0100 Subject: [PATCH 063/130] Fix the remainder of errors. Might have borked splatmap in the process. --- assets | 2 +- src/Engine/Editor/EditorSystem.cpp | 3 ++- src/Engine/Rendering/DrawFinalPass.cpp | 14 +++++++------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/assets b/assets index 1d09801c..72530423 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 1d09801cf45452e082ad08bac5e29e3102f31724 +Subproject commit 72530423ad3744341f42cbfdcba18295a2cfac90 diff --git a/src/Engine/Editor/EditorSystem.cpp b/src/Engine/Editor/EditorSystem.cpp index e770c154..0aefac9d 100644 --- a/src/Engine/Editor/EditorSystem.cpp +++ b/src/Engine/Editor/EditorSystem.cpp @@ -18,7 +18,8 @@ EditorSystem::EditorSystem(SystemParams params, IRenderer* renderer, RenderFrame m_ActualCamera = m_EditorCamera; m_EditorWorld->AttachComponent(m_EditorCamera.ID, "Transform"); auto cCamera = m_EditorWorld->AttachComponent(m_EditorCamera.ID, "Camera"); - //(double&)cCamera["FarClip"] = 300.0; + // TOBIAS TVINGADE MIG ATT HÅRDKODA + (double&)cCamera["FarClip"] = 400.0; m_EditorCameraInputController = new EditorCameraInputController(m_EventBroker, -1); diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index ef930ca6..ac4fa8e4 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -368,6 +368,13 @@ void DrawFinalPass::DrawModelRenderQueues(std::list>& glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, SSAOTexture); + glActiveTexture(GL_TEXTURE6); + if (m_ShadowPass->DepthMap() != NULL) { + glBindTexture(GL_TEXTURE_2D_ARRAY, m_ShadowPass->DepthMap()); + } + else { + glBindTexture(GL_TEXTURE_2D_ARRAY, m_WhiteTexture->m_Texture); + } for (auto &job : jobs) { auto explosionEffectJob = std::dynamic_pointer_cast(job); @@ -1017,13 +1024,6 @@ void DrawFinalPass::BindModelTextures(GLuint shaderHandle, std::shared_ptrDepthMap() != NULL) { - glBindTexture(GL_TEXTURE_2D_ARRAY, m_ShadowPass->DepthMap()); - } - else { - glBindTexture(GL_TEXTURE_2D_ARRAY, m_WhiteTexture->m_Texture); - } break; } case RawModel::MaterialType::SplatMapping: From cfba8efd24bedf9c0469a1b35dcfd4b31c576e41 Mon Sep 17 00:00:00 2001 From: Jocke Date: Wed, 2 Mar 2016 10:59:03 +0100 Subject: [PATCH 064/130] WritePrimitive would spam a warning when snapshots got bigger than 512 and it got resized. --- include/Engine/Network/Packet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/Engine/Network/Packet.h b/include/Engine/Network/Packet.h index b688b8c6..95419e10 100644 --- a/include/Engine/Network/Packet.h +++ b/include/Engine/Network/Packet.h @@ -24,7 +24,7 @@ public: { // Check if we are trying to add more than the package can fit. if (m_MaxPacketSize < m_Offset + sizeof(T)) { - LOG_WARNING("Packet AddPrimitive(): You are trying to add more than we have allocated for! New size is %i bytes\n", m_MaxPacketSize*2); + //LOG_WARNING("Packet AddPrimitive(): You are trying to add more than we have allocated for! New size is %i bytes\n", m_MaxPacketSize*2); resizeData(); } memcpy(m_Data + m_Offset, &val, sizeof(T)); From 4652cd786110419a7d6e42321e7ae3c64483d0cb Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Wed, 2 Mar 2016 11:53:04 +0100 Subject: [PATCH 065/130] Added the already-at-maxammo/health-save-trigger for the PickupSystems --- include/Game/Systems/AmmoPickupSystem.h | 9 ++ include/Game/Systems/PickupSpawnSystem.h | 9 +- src/Game/Systems/AmmoPickupSystem.cpp | 101 ++++++++++++++--------- src/Game/Systems/PickupSpawnSystem.cpp | 70 +++++++++++----- 4 files changed, 129 insertions(+), 60 deletions(-) diff --git a/include/Game/Systems/AmmoPickupSystem.h b/include/Game/Systems/AmmoPickupSystem.h index e4a6df59..7917e765 100644 --- a/include/Game/Systems/AmmoPickupSystem.h +++ b/include/Game/Systems/AmmoPickupSystem.h @@ -20,6 +20,9 @@ public: private: EventRelay m_ETriggerTouch; bool OnTriggerTouch(Events::TriggerTouch& e); + EventRelay m_ETriggerLeave; + bool OnTriggerLeave(Events::TriggerLeave& e); + EventRelay m_EAmmoPickup; bool OnAmmoPickup(Events::AmmoPickup& e); @@ -31,5 +34,11 @@ private: EntityID parentID; }; std::vector m_ETriggerTouchVector; + struct EntityAtMaxValuePickupStruct { + EntityWrapper player; + EntityWrapper trigger; + }; + std::vector m_PickupAtMaximum; + void DoPickup(EntityWrapper &player, EntityWrapper &trigger); }; #endif diff --git a/include/Game/Systems/PickupSpawnSystem.h b/include/Game/Systems/PickupSpawnSystem.h index 66c5f630..be99141c 100644 --- a/include/Game/Systems/PickupSpawnSystem.h +++ b/include/Game/Systems/PickupSpawnSystem.h @@ -9,7 +9,6 @@ #include "Core/EPlayerHealthPickup.h" #include "Engine/Collision/ETrigger.h" #include "Common.h" -#include class PickupSpawnSystem : public ImpureSystem { @@ -21,6 +20,8 @@ public: private: EventRelay m_ETriggerTouch; bool OnTriggerTouch(Events::TriggerTouch& e); + EventRelay m_ETriggerLeave; + bool OnTriggerLeave(Events::TriggerLeave& e); struct NewHealthPickup { glm::vec3 Pos; @@ -30,5 +31,11 @@ private: EntityID parentID; }; std::vector m_ETriggerTouchVector; + struct EntityAtMaxValuePickupStruct { + EntityWrapper player; + EntityWrapper trigger; + }; + std::vector m_PickupAtMaximum; + void DoPickup(EntityWrapper &player, EntityWrapper &trigger); }; #endif diff --git a/src/Game/Systems/AmmoPickupSystem.cpp b/src/Game/Systems/AmmoPickupSystem.cpp index 5927c495..6a24ee95 100644 --- a/src/Game/Systems/AmmoPickupSystem.cpp +++ b/src/Game/Systems/AmmoPickupSystem.cpp @@ -5,6 +5,7 @@ AmmoPickupSystem::AmmoPickupSystem(SystemParams params) { if (IsServer) { EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &AmmoPickupSystem::OnTriggerTouch); + EVENT_SUBSCRIBE_MEMBER(m_ETriggerLeave, &AmmoPickupSystem::OnTriggerLeave); } if (IsClient) { EVENT_SUBSCRIBE_MEMBER(m_EAmmoPickup, &AmmoPickupSystem::OnAmmoPickup); @@ -15,42 +16,47 @@ void AmmoPickupSystem::Update(double dt) { if (IsServer) { for (auto it = m_ETriggerTouchVector.begin(); it != m_ETriggerTouchVector.end(); ++it) { - auto& ammoPickupPosition = *it; - //set the double timer value (value 3) - ammoPickupPosition.DecreaseThisRespawnTimer -= dt; - if (ammoPickupPosition.DecreaseThisRespawnTimer < 0.0) { - //spawn and delete the vector item + auto& somePickup = *it; + somePickup.DecreaseThisRespawnTimer -= dt; + if (somePickup.DecreaseThisRespawnTimer < 0.0) { auto entityFile = ResourceManager::Load("Schema/Entities/AmmoPickup.xml"); EntityFileParser parser(entityFile); EntityID ammoPickupID = parser.MergeEntities(m_World); - //let the world know a pickup has spawned (graphics effects, etc) + //let the world know a pickup has spawned Events::PickupSpawned ePickupSpawned; ePickupSpawned.Pickup = EntityWrapper(m_World, ammoPickupID); m_EventBroker->Publish(ePickupSpawned); - //set values from the old entity to the new entity + //copy values from the old entity to the new entity auto& newAmmoPickupEntity = EntityWrapper(m_World, ammoPickupID); - newAmmoPickupEntity["Transform"]["Position"] = ammoPickupPosition.Pos; - newAmmoPickupEntity["AmmoPickup"]["AmmoGain"] = ammoPickupPosition.AmmoGain; - newAmmoPickupEntity["AmmoPickup"]["RespawnTimer"] = ammoPickupPosition.RespawnTimer; - m_World->SetParent(newAmmoPickupEntity.ID, ammoPickupPosition.parentID); + newAmmoPickupEntity["Transform"]["Position"] = somePickup.Pos; + newAmmoPickupEntity["AmmoPickup"]["AmmoGain"] = somePickup.AmmoGain; + newAmmoPickupEntity["AmmoPickup"]["RespawnTimer"] = somePickup.RespawnTimer; + m_World->SetParent(newAmmoPickupEntity.ID, somePickup.parentID); - //erase the current element (AmmoPickupPosition) + //erase the current element (somePickup) m_ETriggerTouchVector.erase(it); break; } } + //still touching m_PickupAtMaximum? + for (auto& it = m_PickupAtMaximum.begin(); it != m_PickupAtMaximum.end(); ++it) { + if (!it->player.Valid()) { + m_PickupAtMaximum.erase(it); + break; + } + if ((int)it->player["AssaultWeapon"]["Ammo"] < (int)it->player["AssaultWeapon"]["MaxAmmo"]) { + DoPickup(it->player, it->trigger); + m_PickupAtMaximum.erase(it); + break; + } + } } } - bool AmmoPickupSystem::OnTriggerTouch(Events::TriggerTouch& e) { - /*if (e.Entity != LocalPlayer) { - return false; - }*/ - if (!e.Entity.Valid()) { return false; } @@ -61,30 +67,13 @@ bool AmmoPickupSystem::OnTriggerTouch(Events::TriggerTouch& e) if (!e.Trigger.HasComponent("AmmoPickup")) { return false; } - int maxWeaponAmmo = (int)e.Entity["AssaultWeapon"]["MaxAmmo"]; - int& currentAmmo = (int)e.Entity["AssaultWeapon"]["Ammo"]; - int ammoGiven = 0.01*(double)e.Trigger["AmmoPickup"]["AmmoGain"] * maxWeaponAmmo; - //cant pick up ammopacks if you are already at MaxAmmo - if (currentAmmo >= maxWeaponAmmo) { + //if at maxammo, save the trigger-touch to a vector since standing inside it will not re-trigger the trigger + if ((int)e.Entity["AssaultWeapon"]["Ammo"] >= (int)e.Entity["AssaultWeapon"]["MaxAmmo"]) { + m_PickupAtMaximum.push_back({ e.Entity, e.Trigger }); return false; } - - //personEntered = e.Entity, thingEntered = e.Trigger - Events::AmmoPickup ePlayerAmmoPickup; - ePlayerAmmoPickup.AmmoGain = ammoGiven; - ePlayerAmmoPickup.Player = e.Entity; - m_EventBroker->Publish(ePlayerAmmoPickup); - //immediately give the player the ammo - //currentAmmo = std::min(currentAmmo + ammoGiven, maxWeaponAmmo); - - //copy position, ammogain, respawntimer (twice since one of the values will be counted down to 0, the other will be set in the new object) - //we need to copy all values since each value can be different for each ammoPickup - m_ETriggerTouchVector.push_back({ e.Trigger["Transform"]["Position"], e.Trigger["AmmoPickup"]["AmmoGain"], - e.Trigger["AmmoPickup"]["RespawnTimer"], e.Trigger["AmmoPickup"]["RespawnTimer"], m_World->GetParent(e.Trigger.ID) }); - - //delete the ammopickup - m_World->DeleteEntity(e.Trigger.ID); + DoPickup(e.Entity, e.Trigger); return true; } @@ -107,3 +96,39 @@ bool AmmoPickupSystem::OnAmmoPickup(Events::AmmoPickup & e) currentAmmo = std::min(currentAmmo + e.AmmoGain, maxWeaponAmmo); return false; } + +bool AmmoPickupSystem::OnTriggerLeave(Events::TriggerLeave& e) { + if (!e.Trigger.HasComponent("AmmoPickup")) { + return false; + } + //triggerleave erases possible m_PickupAtMaximum + for (auto& it = m_PickupAtMaximum.begin(); it != m_PickupAtMaximum.end(); ++it) { + if (it->trigger.ID == e.Trigger.ID && it->player.ID == e.Entity.ID) { + m_PickupAtMaximum.erase(it); + break; + } + } + return true; +} + +void AmmoPickupSystem::DoPickup(EntityWrapper &player, EntityWrapper &trigger) { + int maxWeaponAmmo = (int)player["AssaultWeapon"]["MaxAmmo"]; + int& currentAmmo = (int)player["AssaultWeapon"]["Ammo"]; + int ammoGiven = 0.01*(double)trigger["AmmoPickup"]["AmmoGain"] * maxWeaponAmmo; + + Events::AmmoPickup ePlayerAmmoPickup; + ePlayerAmmoPickup.AmmoGain = ammoGiven; + ePlayerAmmoPickup.Player = player; + m_EventBroker->Publish(ePlayerAmmoPickup); + + //immediately give the player the ammo (on server) + currentAmmo = std::min(currentAmmo + ammoGiven, maxWeaponAmmo); + + //copy position, ammogain, respawntimer (twice since one of the values will be counted down to 0, the other will be set in the new object) + //we need to copy all values since each value can be different for each ammoPickup + m_ETriggerTouchVector.push_back({ (glm::vec3)trigger["Transform"]["Position"], trigger["AmmoPickup"]["AmmoGain"], + trigger["AmmoPickup"]["RespawnTimer"], trigger["AmmoPickup"]["RespawnTimer"], m_World->GetParent(trigger.ID) }); + + //delete the ammopickup + m_World->DeleteEntity(trigger.ID); +} diff --git a/src/Game/Systems/PickupSpawnSystem.cpp b/src/Game/Systems/PickupSpawnSystem.cpp index 94fee4c6..6bfd2ee6 100644 --- a/src/Game/Systems/PickupSpawnSystem.cpp +++ b/src/Game/Systems/PickupSpawnSystem.cpp @@ -5,6 +5,7 @@ PickupSpawnSystem::PickupSpawnSystem(SystemParams params) { if (IsServer) { EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &PickupSpawnSystem::OnTriggerTouch); + EVENT_SUBSCRIBE_MEMBER(m_ETriggerLeave, &PickupSpawnSystem::OnTriggerLeave); } } @@ -12,11 +13,10 @@ void PickupSpawnSystem::Update(double dt) { if (IsServer) { for (auto it = m_ETriggerTouchVector.begin(); it != m_ETriggerTouchVector.end(); ++it) { - auto& healthPickupPosition = *it; - //set the double timer value (value 3) - healthPickupPosition.DecreaseThisRespawnTimer -= dt; - if (healthPickupPosition.DecreaseThisRespawnTimer < 0) { - //spawn and delete the vector item + auto& somePickup = *it; + somePickup.DecreaseThisRespawnTimer -= dt; + if (somePickup.DecreaseThisRespawnTimer < 0.0) { + //spawn the new healthPickup auto entityFile = ResourceManager::Load("Schema/Entities/HealthPickup.xml"); EntityFileParser parser(entityFile); EntityID healthPickupID = parser.MergeEntities(m_World); @@ -26,45 +26,73 @@ void PickupSpawnSystem::Update(double dt) ePickupSpawned.Pickup = EntityWrapper(m_World, healthPickupID); m_EventBroker->Publish(ePickupSpawned); - //set values from the old entity to the new entity + //copy values from the old entity to the new entity auto& newHealthPickupEntity = EntityWrapper(m_World, healthPickupID); - newHealthPickupEntity["Transform"]["Position"] = healthPickupPosition.Pos; - newHealthPickupEntity["HealthPickup"]["HealthGain"] = healthPickupPosition.HealthGain; - newHealthPickupEntity["HealthPickup"]["RespawnTimer"] = healthPickupPosition.RespawnTimer; - m_World->SetParent(newHealthPickupEntity.ID, healthPickupPosition.parentID); + newHealthPickupEntity["Transform"]["Position"] = somePickup.Pos; + newHealthPickupEntity["HealthPickup"]["HealthGain"] = somePickup.HealthGain; + newHealthPickupEntity["HealthPickup"]["RespawnTimer"] = somePickup.RespawnTimer; + m_World->SetParent(newHealthPickupEntity.ID, somePickup.parentID); - //erase the current element (healthPickupPosition) + //erase the current element (somePickup) m_ETriggerTouchVector.erase(it); break; } } + //still touching PickupAtMaximum? + for (auto& it = m_PickupAtMaximum.begin(); it != m_PickupAtMaximum.end(); ++it) { + if (!it->player.Valid()) { + m_PickupAtMaximum.erase(it); + break; + } + if ((double)it->player["Health"]["Health"] < (double)it->player["Health"]["MaxHealth"]) { + DoPickup(it->player, it->trigger); + m_PickupAtMaximum.erase(it); + break; + } + } } } - - bool PickupSpawnSystem::OnTriggerTouch(Events::TriggerTouch& e) { if (!e.Trigger.HasComponent("HealthPickup")) { return false; } - double healthGiven = 0.01*(double)e.Trigger["HealthPickup"]["HealthGain"] * (double)e.Entity["Health"]["MaxHealth"]; - //cant pick up healthpacks if you are already at MaxHealth + //if at maxhealth, save the trigger-touch to a vector since standing inside it will not re-trigger the trigger if ((double)e.Entity["Health"]["Health"] >= (double)e.Entity["Health"]["MaxHealth"]) { + m_PickupAtMaximum.push_back({ e.Entity, e.Trigger }); return false; } - //personEntered = e.Entity, thingEntered = e.Trigger + DoPickup(e.Entity, e.Trigger); + return true; +} +bool PickupSpawnSystem::OnTriggerLeave(Events::TriggerLeave& e) { + if (!e.Trigger.HasComponent("HealthPickup")) { + return false; + } + //triggerleave erases possible m_PickupAtMaximum + for (auto& it = m_PickupAtMaximum.begin(); it != m_PickupAtMaximum.end(); ++it) { + if (it->trigger.ID == e.Trigger.ID && it->player.ID == e.Entity.ID) { + m_PickupAtMaximum.erase(it); + break; + } + } + return true; +} +void PickupSpawnSystem::DoPickup(EntityWrapper &player, EntityWrapper &trigger) { + double healthGiven = 0.01*(double)trigger["HealthPickup"]["HealthGain"] * (double)player["Health"]["MaxHealth"]; + + //only the server will increase the players hp and set it in the next delta Events::PlayerHealthPickup ePlayerHealthPickup; ePlayerHealthPickup.HealthAmount = healthGiven; - ePlayerHealthPickup.Player = e.Entity; + ePlayerHealthPickup.Player = player; m_EventBroker->Publish(ePlayerHealthPickup); //copy position, healthgain, respawntimer (twice since one of the values will be counted down to 0, the other will be set in the new object) //we need to copy all values since each value can be different for each healthPickup - m_ETriggerTouchVector.push_back({ (glm::vec3)e.Trigger["Transform"]["Position"], e.Trigger["HealthPickup"]["HealthGain"], - e.Trigger["HealthPickup"]["RespawnTimer"], e.Trigger["HealthPickup"]["RespawnTimer"], m_World->GetParent(e.Trigger.ID) }); + m_ETriggerTouchVector.push_back({ (glm::vec3)trigger["Transform"]["Position"] ,trigger["HealthPickup"]["HealthGain"], + trigger["HealthPickup"]["RespawnTimer"],trigger["HealthPickup"]["RespawnTimer"], m_World->GetParent(trigger.ID) }); //delete the healthpickup - m_World->DeleteEntity(e.Trigger.ID); - return true; + m_World->DeleteEntity(trigger.ID); } From de9657700b1f0aed3ed42eab5724a5cc17a9b792 Mon Sep 17 00:00:00 2001 From: Teejoon Date: Wed, 2 Mar 2016 11:59:48 +0100 Subject: [PATCH 066/130] Fixed draw final pass with shided objects having to many if-statments. Shields is working with transparancy Player cameras should have nearclip fater away and far clip nearer. Defaultconfig push --- include/Engine/Rendering/DrawFinalPass.h | 6 - resources/DefaultConfig.ini | 16 +- resources/Schema/Entities/Player.xml | 43 +- resources/Schema/Entities/PlayerRed.xml | 43 +- src/Engine/Rendering/DrawFinalPass.cpp | 676 +++++++++----------- src/Engine/Rendering/DrawFinalPassState.cpp | 1 + 6 files changed, 380 insertions(+), 405 deletions(-) diff --git a/include/Engine/Rendering/DrawFinalPass.h b/include/Engine/Rendering/DrawFinalPass.h index 3b83d52f..cfddd5c6 100644 --- a/include/Engine/Rendering/DrawFinalPass.h +++ b/include/Engine/Rendering/DrawFinalPass.h @@ -38,12 +38,6 @@ private: void DrawShieldedModelRenderQueue(std::list>& jobs, RenderScene& scene); void DrawToDepthStencilBuffer(std::list>& jobs, RenderScene& scene); - void DrawExplosionSetup(ShaderProgram* shader, GLuint shaderHandle, std::shared_ptr& job, RenderScene& scene); - void DrawSkinnedExplosionSetup(ShaderProgram* shader, GLuint shaderHandle, std::shared_ptr& job, RenderScene& scene); - - void DrawModelSetup(ShaderProgram* shader, GLuint shaderHandle, std::shared_ptr& job, RenderScene& scene); - void DrawSkinnedModelSetup(ShaderProgram* shader, GLuint shaderHandle, std::shared_ptr& job, RenderScene& scene); - void BindExplosionUniforms(GLuint shaderHandle, std::shared_ptr& job, RenderScene& scene); void BindModelUniforms(GLuint shaderHandle, std::shared_ptr& job, RenderScene& scene); diff --git a/resources/DefaultConfig.ini b/resources/DefaultConfig.ini index d4696bba..e99e3437 100644 --- a/resources/DefaultConfig.ini +++ b/resources/DefaultConfig.ini @@ -68,5 +68,17 @@ Contrast=1.5 Intensity=1.0 NumSamples=24 NumTurns=17 -NumIterations=13 -TextureQuality=0 \ No newline at end of file +NumIterations=9 +TextureQuality=0 + +[GLOW] +Quality=3; + +[GLOW1] +NumIterations=5 + +[GLOW2] +NumIterations=9 + +[GLOW3] +NumIterations=13 \ No newline at end of file diff --git a/resources/Schema/Entities/Player.xml b/resources/Schema/Entities/Player.xml index 88f153ae..28ace561 100644 --- a/resources/Schema/Entities/Player.xml +++ b/resources/Schema/Entities/Player.xml @@ -13,7 +13,7 @@ - 1.6944730461160304 + 52.867678870419283 @@ -37,7 +37,10 @@ - + + 0.10000000149011612 + 300 + @@ -372,7 +375,7 @@ Idle - 0.67172915251515519 + 1.9408570429715581 1 @@ -386,25 +389,25 @@ + + DefenderWeapon + Schema/Entities/DefenderWeaponView.xml - - DefenderWeapon - + + AssaultWeapon + Schema/Entities/AssaultWeaponView.xml - - AssaultWeapon - @@ -414,7 +417,10 @@ - + + 0.10000000149011612 + 300 + Models/Widgets/Camera.mesh false @@ -430,6 +436,7 @@ Idle + 1.5631122524686134 1 @@ -449,31 +456,31 @@ - - Schema/Entities/DefenderWeaponWorld.xml - - DefenderWeapon + + Schema/Entities/DefenderWeaponWorld.xml + + - - Schema/Entities/AssaultWeaponWorld.xml - - AssaultWeapon + + Schema/Entities/AssaultWeaponWorld.xml + + diff --git a/resources/Schema/Entities/PlayerRed.xml b/resources/Schema/Entities/PlayerRed.xml index 3cf17558..c46b9d79 100644 --- a/resources/Schema/Entities/PlayerRed.xml +++ b/resources/Schema/Entities/PlayerRed.xml @@ -13,7 +13,7 @@ - 1.6944730461160304 + 22.22055262342397 @@ -37,7 +37,10 @@ - + + 0.10000000149011612 + 300 + @@ -372,7 +375,7 @@ Idle - 0.67172915251515519 + 1.1978087298230946 1 @@ -386,25 +389,25 @@ + + DefenderWeapon + Schema/Entities/DefenderWeaponViewRed.xml - - DefenderWeapon - + + AssaultWeapon + Schema/Entities/AssaultWeaponView.xml - - AssaultWeapon - @@ -414,7 +417,10 @@ - + + 0.10000000149011612 + 300 + Models/Widgets/Camera.mesh false @@ -430,6 +436,7 @@ Idle + 0.69274608502888668 1 @@ -449,31 +456,31 @@ - - Schema/Entities/DefenderWeaponWorldRed.xml - - DefenderWeapon + + Schema/Entities/DefenderWeaponWorldRed.xml + + - - Schema/Entities/AssaultWeaponWorld.xml - - AssaultWeapon + + Schema/Entities/AssaultWeaponWorld.xml + + diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index 16c154e3..6cdf42d1 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -236,7 +236,7 @@ void DrawFinalPass::InitializeShaderPrograms() void DrawFinalPass::Draw(RenderScene& scene) { GLERROR("Pre"); - DrawStencilState* stateDethp = new DrawStencilState(m_ShieldDepthFrameBuffer.GetHandle()); + DrawFinalPassState* stateDethp = new DrawFinalPassState(m_ShieldDepthFrameBuffer.GetHandle()); //Draw shields to stencil DrawToDepthStencilBuffer(scene.Jobs.ShieldObjects, scene); GLERROR("StencilPass"); @@ -276,13 +276,13 @@ void DrawFinalPass::Draw(RenderScene& scene) //state->Disable(GL_STENCIL_TEST); //Draw Transparen Shielded objects + state->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); DrawModelRenderQueuesWithShieldCheck(scene.Jobs.TransparentObjects, scene); //might need changing GLERROR("Shielded Transparent objects"); //Draw Transparen objects //state->BlendFunc(GL_ONE, GL_ONE); //state->StencilFunc(GL_EQUAL, 1, 0xFF); - state->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //DrawModelRenderQueues(scene.Jobs.TransparentObjects, scene); GLERROR("TransparentObjects"); //state->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -349,78 +349,72 @@ void DrawFinalPass::DrawModelRenderQueues(std::list>& switch (explosionEffectJob->Type) { case RawModel::MaterialType::Basic: case RawModel::MaterialType::SingleTextures: - { - if (explosionEffectJob->Model->IsSkinned()) { + { + if (explosionEffectJob->Model->IsSkinned()) { - m_ExplosionEffectSkinnedProgram->Bind(); - GLERROR("Bind ExplosionEffectSkinned program"); - //bind uniforms - BindExplosionUniforms(explosionSkinnedHandle, explosionEffectJob, scene); - //bind textures - BindExplosionTextures(explosionSkinnedHandle, explosionEffectJob); - glActiveTexture(GL_TEXTURE5); - glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); - glUniform3fv(glGetUniformLocation(explosionSkinnedHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); + m_ExplosionEffectSkinnedProgram->Bind(); + GLERROR("Bind ExplosionEffectSkinned program"); + //bind uniforms + BindExplosionUniforms(explosionSkinnedHandle, explosionEffectJob, scene); + //bind textures + BindExplosionTextures(explosionSkinnedHandle, explosionEffectJob); + glActiveTexture(GL_TEXTURE5); + glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); + glUniform3fv(glGetUniformLocation(explosionSkinnedHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); - std::vector frameBones; - if (explosionEffectJob->AnimationOffset.animation != nullptr) { - frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations, explosionEffectJob->AnimationOffset); + std::vector frameBones; + if (explosionEffectJob->AnimationOffset.animation != nullptr) { + frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations, explosionEffectJob->AnimationOffset); + } + else { + frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations); + } + glUniformMatrix4fv(glGetUniformLocation(explosionSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); } else { - frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations); + m_ExplosionEffectProgram->Bind(); + GLERROR("Bind ExplosionEffect program"); + //bind uniforms + BindExplosionUniforms(explosionHandle, explosionEffectJob, scene); + //bind textures + BindExplosionTextures(explosionHandle, explosionEffectJob); + glActiveTexture(GL_TEXTURE5); + glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); + glUniform3fv(glGetUniformLocation(explosionHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); } - glUniformMatrix4fv(glGetUniformLocation(explosionSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); - DrawSkinnedExplosionSetup(m_ExplosionEffectSkinnedProgram, explosionSkinnedHandle, explosionEffectJob, scene); - } - else { - m_ExplosionEffectProgram->Bind(); - GLERROR("Bind ExplosionEffect program"); - //bind uniforms - BindExplosionUniforms(explosionHandle, explosionEffectJob, scene); - //bind textures - BindExplosionTextures(explosionHandle, explosionEffectJob); - glActiveTexture(GL_TEXTURE5); - glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); - glUniform3fv(glGetUniformLocation(explosionHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); - - DrawExplosionSetup(m_ExplosionEffectProgram, explosionHandle, explosionEffectJob, scene); - } - break; + break; } case RawModel::MaterialType::SplatMapping: - { - if (explosionEffectJob->Model->IsSkinned()) { - m_ExplosionEffectSplatMapSkinnedProgram->Bind(); - GLERROR("Bind ExplosionEffectSplatMapSkinned program"); - //bind uniforms - BindExplosionUniforms(explosionSplatMapSkinnedHandle, explosionEffectJob, scene); - //bind textures - BindExplosionTextures(explosionSplatMapSkinnedHandle, explosionEffectJob); - GLERROR("asdasd"); - std::vector frameBones; - if (explosionEffectJob->AnimationOffset.animation != nullptr) { - frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations, explosionEffectJob->AnimationOffset); + { + if (explosionEffectJob->Model->IsSkinned()) { + m_ExplosionEffectSplatMapSkinnedProgram->Bind(); + GLERROR("Bind ExplosionEffectSplatMapSkinned program"); + //bind uniforms + BindExplosionUniforms(explosionSplatMapSkinnedHandle, explosionEffectJob, scene); + //bind textures + BindExplosionTextures(explosionSplatMapSkinnedHandle, explosionEffectJob); + GLERROR("asdasd"); + std::vector frameBones; + if (explosionEffectJob->AnimationOffset.animation != nullptr) { + frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations, explosionEffectJob->AnimationOffset); + } + else { + frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations); + } + glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); } else { - frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations); + m_ExplosionEffectSplatMapProgram->Bind(); + GLERROR("Bind ExplosionEffectSplatMap program"); + //bind uniforms + //bind uniforms + BindExplosionUniforms(explosionSplatMapHandle, explosionEffectJob, scene); + //bind textures + BindExplosionTextures(explosionSplatMapHandle, explosionEffectJob); + GLERROR("asdasd"); } - glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); - - DrawSkinnedExplosionSetup(m_ExplosionEffectSplatMapSkinnedProgram, explosionSplatMapSkinnedHandle, explosionEffectJob, scene); + break; } - else { - m_ExplosionEffectSplatMapProgram->Bind(); - GLERROR("Bind ExplosionEffectSplatMap program"); - //bind uniforms - //bind uniforms - BindExplosionUniforms(explosionSplatMapHandle, explosionEffectJob, scene); - //bind textures - BindExplosionTextures(explosionSplatMapHandle, explosionEffectJob); - GLERROR("asdasd"); - DrawExplosionSetup(m_ExplosionEffectSplatMapProgram, explosionSplatMapHandle, explosionEffectJob, scene); - } - break; - } } glDisable(GL_CULL_FACE); @@ -554,99 +548,145 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::listType) { case RawModel::MaterialType::Basic: case RawModel::MaterialType::SingleTextures: - { - if (explosionEffectJob->Model->IsSkinned()) { + { + if (explosionEffectJob->Model->IsSkinned()) { - m_ExplosionEffectSkinnedShieldCheckProgram->Bind(); - GLERROR("Bind ExplosionEffectSkinned program"); - //bind uniforms - BindExplosionUniforms(explosionSkinnedShieldCheckHandle, explosionEffectJob, scene); - //bind textures - BindExplosionTextures(explosionSkinnedShieldCheckHandle, explosionEffectJob); - glActiveTexture(GL_TEXTURE5); - glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); - glUniform3fv(glGetUniformLocation(explosionSkinnedShieldCheckHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); + m_ExplosionEffectSkinnedShieldCheckProgram->Bind(); + GLERROR("Bind ExplosionEffectSkinned program"); + //bind uniforms + BindExplosionUniforms(explosionSkinnedShieldCheckHandle, explosionEffectJob, scene); + //bind textures + BindExplosionTextures(explosionSkinnedShieldCheckHandle, explosionEffectJob); + glActiveTexture(GL_TEXTURE5); + glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); + glUniform3fv(glGetUniformLocation(explosionSkinnedShieldCheckHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); - std::vector frameBones; - if (explosionEffectJob->AnimationOffset.animation != nullptr) { - frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations, explosionEffectJob->AnimationOffset); + std::vector frameBones; + if (explosionEffectJob->AnimationOffset.animation != nullptr) { + frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations, explosionEffectJob->AnimationOffset); + } + else { + frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations); + } + glUniformMatrix4fv(glGetUniformLocation(explosionSkinnedShieldCheckHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); } else { - frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations); - } - glUniformMatrix4fv(glGetUniformLocation(explosionSkinnedShieldCheckHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); - } - else { - m_ExplosionEffectShieldCheckProgram->Bind(); - GLERROR("Bind ExplosionEffect program"); - //bind uniforms - BindExplosionUniforms(explosionShieldCheckHandle, explosionEffectJob, scene); - //bind textures - BindExplosionTextures(explosionShieldCheckHandle, explosionEffectJob); - glActiveTexture(GL_TEXTURE5); - glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); - glUniform3fv(glGetUniformLocation(explosionShieldCheckHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); + m_ExplosionEffectShieldCheckProgram->Bind(); + GLERROR("Bind ExplosionEffect program"); + //bind uniforms + BindExplosionUniforms(explosionShieldCheckHandle, explosionEffectJob, scene); + //bind textures + BindExplosionTextures(explosionShieldCheckHandle, explosionEffectJob); + glActiveTexture(GL_TEXTURE5); + glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); + glUniform3fv(glGetUniformLocation(explosionShieldCheckHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); + } + break; } - break; - } case RawModel::MaterialType::SplatMapping: - { - if (explosionEffectJob->Model->IsSkinned()) { - m_ExplosionEffectSplatMapSkinnedShieldCheckProgram->Bind(); - GLERROR("Bind ExplosionEffectSplatMapSkinned program"); - //bind uniforms - BindExplosionUniforms(explosionSplatMapSkinnedShieldCheckHandle, explosionEffectJob, scene); - //bind textures - BindExplosionTextures(explosionSplatMapSkinnedShieldCheckHandle, explosionEffectJob); - GLERROR("asdasd"); - std::vector frameBones; - if (explosionEffectJob->AnimationOffset.animation != nullptr) { - frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations, explosionEffectJob->AnimationOffset); + { + if (explosionEffectJob->Model->IsSkinned()) { + m_ExplosionEffectSplatMapSkinnedShieldCheckProgram->Bind(); + GLERROR("Bind ExplosionEffectSplatMapSkinned program"); + //bind uniforms + BindExplosionUniforms(explosionSplatMapSkinnedShieldCheckHandle, explosionEffectJob, scene); + //bind textures + BindExplosionTextures(explosionSplatMapSkinnedShieldCheckHandle, explosionEffectJob); + GLERROR("asdasd"); + std::vector frameBones; + if (explosionEffectJob->AnimationOffset.animation != nullptr) { + frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations, explosionEffectJob->AnimationOffset); + } + else { + frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations); + } + glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapSkinnedShieldCheckHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); + } else { - frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations); + m_ExplosionEffectSplatMapShieldCheckProgram->Bind(); + GLERROR("Bind ExplosionEffectSplatMap program"); + //bind uniforms + //bind uniforms + BindExplosionUniforms(explosionSplatMapShieldCheckHandle, explosionEffectJob, scene); + //bind textures + BindExplosionTextures(explosionSplatMapShieldCheckHandle, explosionEffectJob); + GLERROR("asdasd"); } - glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapSkinnedShieldCheckHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); - + break; } - else { - m_ExplosionEffectSplatMapShieldCheckProgram->Bind(); - GLERROR("Bind ExplosionEffectSplatMap program"); - //bind uniforms - //bind uniforms - BindExplosionUniforms(explosionSplatMapShieldCheckHandle, explosionEffectJob, scene); - //bind textures - BindExplosionTextures(explosionSplatMapShieldCheckHandle, explosionEffectJob); - GLERROR("asdasd"); - } - break; } - } - } - else { + } else { switch (explosionEffectJob->Type) { case RawModel::MaterialType::Basic: case RawModel::MaterialType::SingleTextures: - { - if (explosionEffectJob->Model->IsSkinned()) { - DrawSkinnedExplosionSetup(m_ExplosionEffectSkinnedProgram, explosionSkinnedHandle, explosionEffectJob, scene); + { + if (explosionEffectJob->Model->IsSkinned()) { + + m_ExplosionEffectSkinnedProgram->Bind(); + GLERROR("Bind ExplosionEffectSkinned program"); + //bind uniforms + BindExplosionUniforms(explosionSkinnedHandle, explosionEffectJob, scene); + //bind textures + BindExplosionTextures(explosionSkinnedHandle, explosionEffectJob); + glActiveTexture(GL_TEXTURE5); + glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); + glUniform3fv(glGetUniformLocation(explosionSkinnedHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); + + std::vector frameBones; + if (explosionEffectJob->AnimationOffset.animation != nullptr) { + frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations, explosionEffectJob->AnimationOffset); + } + else { + frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations); + } + glUniformMatrix4fv(glGetUniformLocation(explosionSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); + } + else { + m_ExplosionEffectProgram->Bind(); + GLERROR("Bind ExplosionEffect program"); + //bind uniforms + BindExplosionUniforms(explosionHandle, explosionEffectJob, scene); + //bind textures + BindExplosionTextures(explosionHandle, explosionEffectJob); + glActiveTexture(GL_TEXTURE5); + glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); + glUniform3fv(glGetUniformLocation(explosionHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); + } + break; } - else { - DrawExplosionSetup(m_ExplosionEffectProgram, explosionHandle, explosionEffectJob, scene); - } - break; - } case RawModel::MaterialType::SplatMapping: - { - if (explosionEffectJob->Model->IsSkinned()) { - DrawSkinnedExplosionSetup(m_ExplosionEffectSplatMapSkinnedProgram, explosionSplatMapSkinnedHandle, explosionEffectJob, scene); + { + if (explosionEffectJob->Model->IsSkinned()) { + m_ExplosionEffectSplatMapSkinnedProgram->Bind(); + GLERROR("Bind ExplosionEffectSplatMapSkinned program"); + //bind uniforms + BindExplosionUniforms(explosionSplatMapSkinnedHandle, explosionEffectJob, scene); + //bind textures + BindExplosionTextures(explosionSplatMapSkinnedHandle, explosionEffectJob); + GLERROR("asdasd"); + std::vector frameBones; + if (explosionEffectJob->AnimationOffset.animation != nullptr) { + frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations, explosionEffectJob->AnimationOffset); + } + else { + frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations); + } + glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); + } + else { + m_ExplosionEffectSplatMapProgram->Bind(); + GLERROR("Bind ExplosionEffectSplatMap program"); + //bind uniforms + //bind uniforms + BindExplosionUniforms(explosionSplatMapHandle, explosionEffectJob, scene); + //bind textures + BindExplosionTextures(explosionSplatMapHandle, explosionEffectJob); + GLERROR("asdasd"); + } + break; } - else { - DrawExplosionSetup(m_ExplosionEffectSplatMapProgram, explosionSplatMapHandle, explosionEffectJob, scene); - } - break; - } } } glDisable(GL_CULL_FACE); @@ -658,176 +698,160 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list(job); - if (explosionEffectJob) { - switch (explosionEffectJob->Type) { - case RawModel::MaterialType::Basic: - case RawModel::MaterialType::SingleTextures: - { - if (explosionEffectJob->Model->IsSkinned()) { - - m_ExplosionEffectSkinnedProgram->Bind(); - GLERROR("Bind ExplosionEffectSkinned program"); - //bind uniforms - BindExplosionUniforms(explosionSkinnedHandle, explosionEffectJob, scene); - //bind textures - BindExplosionTextures(explosionSkinnedHandle, explosionEffectJob); - glActiveTexture(GL_TEXTURE5); - glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); - glUniform3fv(glGetUniformLocation(explosionSkinnedHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); - - std::vector frameBones; - if (explosionEffectJob->AnimationOffset.animation != nullptr) { - frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations, explosionEffectJob->AnimationOffset); - } - else { - frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations); - } - glUniformMatrix4fv(glGetUniformLocation(explosionSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); - DrawSkinnedExplosionSetup(m_ExplosionEffectSkinnedProgram, explosionSkinnedHandle, explosionEffectJob, scene); - } - else { - m_ExplosionEffectProgram->Bind(); - GLERROR("Bind ExplosionEffect program"); - //bind uniforms - BindExplosionUniforms(explosionHandle, explosionEffectJob, scene); - //bind textures - BindExplosionTextures(explosionHandle, explosionEffectJob); - glActiveTexture(GL_TEXTURE5); - glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); - glUniform3fv(glGetUniformLocation(explosionHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); - - DrawExplosionSetup(m_ExplosionEffectProgram, explosionHandle, explosionEffectJob, scene); - } - break; - } - case RawModel::MaterialType::SplatMapping: - { - if (explosionEffectJob->Model->IsSkinned()) { - m_ExplosionEffectSplatMapSkinnedProgram->Bind(); - GLERROR("Bind ExplosionEffectSplatMapSkinned program"); - //bind uniforms - BindExplosionUniforms(explosionSplatMapSkinnedHandle, explosionEffectJob, scene); - //bind textures - BindExplosionTextures(explosionSplatMapSkinnedHandle, explosionEffectJob); - GLERROR("asdasd"); - std::vector frameBones; - if (explosionEffectJob->AnimationOffset.animation != nullptr) { - frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations, explosionEffectJob->AnimationOffset); - } - else { - frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations); - } - glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); - - DrawSkinnedExplosionSetup(m_ExplosionEffectSplatMapSkinnedProgram, explosionSplatMapSkinnedHandle, explosionEffectJob, scene); - } - else { - m_ExplosionEffectSplatMapProgram->Bind(); - GLERROR("Bind ExplosionEffectSplatMap program"); - //bind uniforms - //bind uniforms - BindExplosionUniforms(explosionSplatMapHandle, explosionEffectJob, scene); - //bind textures - BindExplosionTextures(explosionSplatMapHandle, explosionEffectJob); - GLERROR("asdasd"); - DrawExplosionSetup(m_ExplosionEffectSplatMapProgram, explosionSplatMapHandle, explosionEffectJob, scene); - } - break; - } - } - glDisable(GL_CULL_FACE); - - //draw - glBindVertexArray(explosionEffectJob->Model->VAO); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, explosionEffectJob->Model->ElementBuffer); - glDrawElements(GL_TRIANGLES, explosionEffectJob->EndIndex - explosionEffectJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(explosionEffectJob->StartIndex*sizeof(unsigned int))); - glEnable(GL_CULL_FACE); - GLERROR("explosion effect end"); - } - else { - auto modelJob = std::dynamic_pointer_cast(job); - if (modelJob) { - //bind forward program - //TODO: JOHAN/TOBIAS: Bind shader based on ModelJob->ShaderID; + auto modelJob = std::dynamic_pointer_cast(job); + if (modelJob) { + //bind forward program + //TODO: JOHAN/TOBIAS: Bind shader based on ModelJob->ShaderID; + if (modelJob->IsShielded) { switch (modelJob->Type) { case RawModel::MaterialType::Basic: case RawModel::MaterialType::SingleTextures: - { - if (modelJob->Model->IsSkinned()) { - m_ForwardPlusSkinnedProgram->Bind(); - GLERROR("Bind ForwardPlusSkinnedProgram"); - //bind uniforms - BindModelUniforms(forwardSkinnedHandle, modelJob, scene); - //bind textures - BindModelTextures(forwardSkinnedHandle, modelJob); - glActiveTexture(GL_TEXTURE5); - glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); - glUniform3fv(glGetUniformLocation(forwardSkinnedHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); + { + if (modelJob->Model->IsSkinned()) { + m_ForwardPlusSkinnedShieldCheckProgram->Bind(); + GLERROR("Bind ForwardPlusSkinnedProgram"); + //bind uniforms + BindModelUniforms(forwardSkinnedShieldCheckHandle, modelJob, scene); + //bind textures + BindModelTextures(forwardSkinnedShieldCheckHandle, modelJob); + glActiveTexture(GL_TEXTURE5); + glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); + glUniform3fv(glGetUniformLocation(forwardSkinnedShieldCheckHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); + + std::vector frameBones; + if (modelJob->AnimationOffset.animation != nullptr) { + frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset); + } + else { + frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations); + } + glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedShieldCheckHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); - std::vector frameBones; - if (modelJob->AnimationOffset.animation != nullptr) { - frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset); } else { - frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations); + m_ForwardPlusShieldCheckProgram->Bind(); + GLERROR("Bind ForwardPlusProgram"); + //bind uniforms + BindModelUniforms(forwardShieldCheckHandle, modelJob, scene); + //bind textures + BindModelTextures(forwardShieldCheckHandle, modelJob); + glActiveTexture(GL_TEXTURE5); + glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); + glUniform3fv(glGetUniformLocation(forwardShieldCheckHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); } - glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); - + break; } - else { - m_ForwardPlusProgram->Bind(); - GLERROR("Bind ForwardPlusProgram"); - //bind uniforms - BindModelUniforms(forwardHandle, modelJob, scene); - //bind textures - BindModelTextures(forwardHandle, modelJob); - glActiveTexture(GL_TEXTURE5); - glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); - glUniform3fv(glGetUniformLocation(forwardHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); - } - break; - } case RawModel::MaterialType::SplatMapping: - { - if (modelJob->Model->IsSkinned()) { - m_ForwardPlusSplatMapSkinnedProgram->Bind(); - GLERROR("Bind SplatMap program"); - //bind uniforms - BindModelUniforms(forwardSplatMapSkinnedHandle, modelJob, scene); - //bind textures - BindModelTextures(forwardSplatMapSkinnedHandle, modelJob); - GLERROR("asdasd"); - std::vector frameBones; - if (modelJob->AnimationOffset.animation != nullptr) { - frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset); + { + if (modelJob->Model->IsSkinned()) { + m_ForwardPlusSplatMapSkinnedShieldCheckProgram->Bind(); + GLERROR("Bind SplatMap program"); + //bind uniforms + BindModelUniforms(forwardSplatMapSkinnedShieldCheckHandle, modelJob, scene); + //bind textures + BindModelTextures(forwardSplatMapSkinnedShieldCheckHandle, modelJob); + GLERROR("asdasd"); + std::vector frameBones; + if (modelJob->AnimationOffset.animation != nullptr) { + frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset); + } + else { + frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations); + } + glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapSkinnedShieldCheckHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); + } else { - frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations); + m_ForwardPlusSplatMapShieldCheckProgram->Bind(); + GLERROR("Bind SplatMap program"); + //bind uniforms + BindModelUniforms(forwardSplatShieldCheckHandle, modelJob, scene); + //bind textures + BindModelTextures(forwardSplatShieldCheckHandle, modelJob); + GLERROR("asdasd"); } - glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); + break; + } + } + } else { + switch (modelJob->Type) { + case RawModel::MaterialType::Basic: + case RawModel::MaterialType::SingleTextures: + { + if (modelJob->Model->IsSkinned()) { + m_ForwardPlusSkinnedProgram->Bind(); + GLERROR("Bind ForwardPlusSkinnedProgram"); + //bind uniforms + BindModelUniforms(forwardSkinnedHandle, modelJob, scene); + //bind textures + BindModelTextures(forwardSkinnedHandle, modelJob); + glActiveTexture(GL_TEXTURE5); + glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); + glUniform3fv(glGetUniformLocation(forwardSkinnedHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); + std::vector frameBones; + if (modelJob->AnimationOffset.animation != nullptr) { + frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset); + } + else { + frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations); + } + glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); + + } + else { + m_ForwardPlusProgram->Bind(); + GLERROR("Bind ForwardPlusProgram"); + //bind uniforms + BindModelUniforms(forwardHandle, modelJob, scene); + //bind textures + BindModelTextures(forwardHandle, modelJob); + glActiveTexture(GL_TEXTURE5); + glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); + glUniform3fv(glGetUniformLocation(forwardHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); + } + break; } - else { - m_ForwardPlusSplatMapProgram->Bind(); - GLERROR("Bind SplatMap program"); - //bind uniforms - BindModelUniforms(forwardSplatMapHandle, modelJob, scene); - //bind textures - BindModelTextures(forwardSplatMapHandle, modelJob); - GLERROR("asdasd"); + case RawModel::MaterialType::SplatMapping: + { + if (modelJob->Model->IsSkinned()) { + m_ForwardPlusSplatMapSkinnedProgram->Bind(); + GLERROR("Bind SplatMap program"); + //bind uniforms + BindModelUniforms(forwardSplatMapSkinnedHandle, modelJob, scene); + //bind textures + BindModelTextures(forwardSplatMapSkinnedHandle, modelJob); + GLERROR("asdasd"); + std::vector frameBones; + if (modelJob->AnimationOffset.animation != nullptr) { + frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset); + } + else { + frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations); + } + glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); + + } + else { + m_ForwardPlusSplatMapProgram->Bind(); + GLERROR("Bind SplatMap program"); + //bind uniforms + BindModelUniforms(forwardSplatMapHandle, modelJob, scene); + //bind textures + BindModelTextures(forwardSplatMapHandle, modelJob); + GLERROR("asdasd"); + } + break; } - break; - } - } - //draw - glBindVertexArray(modelJob->Model->VAO); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); - glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex*sizeof(unsigned int))); - if (GLERROR("models end")) { - continue; } } + //draw + glBindVertexArray(modelJob->Model->VAO); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); + glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex*sizeof(unsigned int))); + if (GLERROR("models end")) { + continue; + } } } } @@ -1013,76 +1037,6 @@ void DrawFinalPass::DrawSprites(std::list>&jobs, Rend // m_SpriteProgram->Unbind(); } -void DrawFinalPass::DrawExplosionSetup(ShaderProgram* shader, GLuint shaderHandle, std::shared_ptr& job, RenderScene& scene) -{ - shader->Bind(); - GLERROR("Bind ExplosionEffect program"); - //bind uniforms - BindExplosionUniforms(shaderHandle, job, scene); - //bind textures - BindExplosionTextures(shaderHandle, job); - glActiveTexture(GL_TEXTURE5); - glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); - glUniform3fv(glGetUniformLocation(shaderHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); -} - -void DrawFinalPass::DrawSkinnedExplosionSetup(ShaderProgram* shader, GLuint shaderHandle, std::shared_ptr& job, RenderScene& scene) -{ - shader->Bind(); - GLERROR("Bind ExplosionEffectSkinned program"); - //bind uniforms - BindExplosionUniforms(shaderHandle, job, scene); - //bind textures - BindExplosionTextures(shaderHandle, job); - glActiveTexture(GL_TEXTURE5); - glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); - glUniform3fv(glGetUniformLocation(shaderHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); - - std::vector frameBones; - if (job->AnimationOffset.animation != nullptr) { - frameBones = job->Skeleton->GetFrameBones(job->Animations, job->AnimationOffset); - } - else { - frameBones = job->Skeleton->GetFrameBones(job->Animations); - } - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); -} - -void DrawFinalPass::DrawModelSetup(ShaderProgram* shader, GLuint shaderHandle, std::shared_ptr& job, RenderScene& scene) -{ - m_ForwardPlusProgram->Bind(); - GLERROR("Bind ForwardPlusProgram"); - //bind uniforms - BindModelUniforms(shaderHandle, job, scene); - //bind textures - BindModelTextures(shaderHandle, job); - glActiveTexture(GL_TEXTURE5); - glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); - glUniform3fv(glGetUniformLocation(shaderHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); -} - -void DrawFinalPass::DrawSkinnedModelSetup(ShaderProgram* shader, GLuint shaderHandle , std::shared_ptr& job, RenderScene& scene) -{ - shader->Bind(); - GLERROR("Bind ForwardPlusSkinnedProgram"); - //bind uniforms - BindModelUniforms(shaderHandle, job, scene); - //bind textures - BindModelTextures(shaderHandle, job); - glActiveTexture(GL_TEXTURE5); - glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture); - glUniform3fv(glGetUniformLocation(shaderHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position())); - - std::vector frameBones; - if (job->AnimationOffset.animation != nullptr) { - frameBones = job->Skeleton->GetFrameBones(job->Animations, job->AnimationOffset); - } - else { - frameBones = job->Skeleton->GetFrameBones(job->Animations); - } - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); -} - void DrawFinalPass::BindExplosionUniforms(GLuint shaderHandle, std::shared_ptr& job, RenderScene& scene) { glUniform1i(glGetUniformLocation(shaderHandle, "SSAOQuality"), m_SSAOPass->TextureQuality()); diff --git a/src/Engine/Rendering/DrawFinalPassState.cpp b/src/Engine/Rendering/DrawFinalPassState.cpp index 62500fa5..5c238985 100644 --- a/src/Engine/Rendering/DrawFinalPassState.cpp +++ b/src/Engine/Rendering/DrawFinalPassState.cpp @@ -27,6 +27,7 @@ DrawStencilState::DrawStencilState(GLuint frameBuffer) BindFramebuffer(frameBuffer); Enable(GL_DEPTH_TEST); DepthMask(GL_TRUE); + Enable(GL_CULL_FACE); ClearColor(glm::vec4(0.f)); } From 654084839252b7c6c9dd63be197e17252a0f3001 Mon Sep 17 00:00:00 2001 From: Tleety Date: Wed, 2 Mar 2016 11:59:56 +0100 Subject: [PATCH 067/130] WIP --- .../Systems/CapturePointArrowHUDSystem.cpp | 154 ++++++++++++------ src/Game/Systems/CapturePointSystem.cpp | 1 + 2 files changed, 104 insertions(+), 51 deletions(-) diff --git a/src/Game/Systems/CapturePointArrowHUDSystem.cpp b/src/Game/Systems/CapturePointArrowHUDSystem.cpp index e86a6844..3488c0a8 100644 --- a/src/Game/Systems/CapturePointArrowHUDSystem.cpp +++ b/src/Game/Systems/CapturePointArrowHUDSystem.cpp @@ -10,74 +10,134 @@ CapturePointArrowHUDSystem::CapturePointArrowHUDSystem(SystemParams params) void CapturePointArrowHUDSystem::Update(double dt) { - bool LoadCheck = true; + bool loadCheck = true; int redTeam; int blueTeam; int spectatorTeam; //Get list for all CapturePointArrowHUDComponents - auto ArrowHUDs = m_World->GetComponents("CapturePointArrowHUD"); - auto CapturePoints = m_World->GetComponents("CapturePoint"); - if(ArrowHUDs == nullptr) { + auto arrowHUDs = m_World->GetComponents("CapturePointArrowHUD"); + auto capturePoints = m_World->GetComponents("CapturePoint"); + if(arrowHUDs == nullptr) { return; } - for(auto& cArrowHUD : *ArrowHUDs) { + for(auto& cArrowHUD : *arrowHUDs) { //Get what team the current arrow corresponds to - EntityWrapper ArrowEntity = EntityWrapper(m_World, cArrowHUD.EntityID); - if (!ArrowEntity.Valid()) { + EntityWrapper arrowEntity = EntityWrapper(m_World, cArrowHUD.EntityID); + if (!arrowEntity.Valid()) { continue; } - if(!ArrowEntity.HasComponent("Team")) { + if(!arrowEntity.HasComponent("Team")) { continue; } - auto cTeam = ArrowEntity["Team"]; + auto cTeam = arrowEntity["Team"]; int currentTeam = (int)cTeam["Team"]; - if (LoadCheck) { + if (loadCheck) { redTeam = (int)cTeam["Team"].Enum("Red"); blueTeam = (int)cTeam["Team"].Enum("Blue"); spectatorTeam = (int)cTeam["Team"].Enum("Spectator"); - LoadCheck = false; + loadCheck = false; if (!m_InitialtargetsSet) { - glm::vec3 target1, target2; - EntityWrapper home1, home2; + std::unordered_map blueTargets, redTargets; + EntityWrapper homeBlue, homeRed; + int lastCP = -INFINITY; + int firstCP = INFINITY; - for (auto& cCP : *CapturePoints) { + for (auto& cCP : *capturePoints) { auto homePointTeam = (int)cCP["HomePointForTeam"]; - auto CPID = (int)cCP["CapturePointNumber"]; + EntityWrapper capturePointEntity = EntityWrapper(m_World, cCP.EntityID); + int capturePointID = (int)capturePointEntity["CapturePoint"]["CapturePointNumber"]; - if(CPID == 0) { - //Home point for one team - home1 = EntityWrapper(m_World, cCP.EntityID); - } else if (CPID == 1) { - //First target for one team, so save it for later use. - target1 = Transform::AbsolutePosition(EntityWrapper(m_World, cCP.EntityID)); - } else if (CPID == 3) { - //First target for one team, so save it for later use. - target2 = Transform::AbsolutePosition(EntityWrapper(m_World, cCP.EntityID)); - } else if (CPID == 4) { - //Home point for one team - home2 = EntityWrapper(m_World, cCP.EntityID); + if(capturePointID < firstCP) { + firstCP = capturePointID; + } + + if(capturePointID > lastCP) { + lastCP = capturePointID; + } + + if (!capturePointEntity.HasComponent("Team")) { + continue; + } + + int currentOwner = (int)capturePointEntity["Team"]["Team"]; + + if(currentOwner != redTeam) { + //This capturePoint is not owned by the red team and is therefor an eligible target for red team + glm::vec3 targetPos = Transform::AbsolutePosition(capturePointEntity); + redTargets.insert(std::pair(capturePointID, targetPos)); + } + if(currentOwner != blueTeam) { + //This capturePoint is not owned by the blue team and is therefor an eligible target for blue team + glm::vec3 targetPos = Transform::AbsolutePosition(capturePointEntity); + blueTargets.insert(std::pair(capturePointID, targetPos)); + } + + if(homePointTeam == blueTeam) { + //CP is the home point for blue team. + homeBlue = capturePointEntity; + } else if (homePointTeam == redTeam) { + //CP is the home point for red team. + homeRed = capturePointEntity; } } - //Check what team is the owner of Home1 and set their target to the next capturepoint - if(!home1.Valid() || !home2.Valid()) { + + if(!homeRed.Valid() || !homeBlue.Valid()) { + //One or both teams have no home point, cant continue return; } - if((int)home1["CapturePoint"]["HomePointForTeam"] == redTeam) { - m_RedTeamCurrentTarget = target1; - } else if ((int)home1["CapturePoint"]["HomePointForTeam"] == blueTeam) { - m_BlueTeamCurrentTarget = target1; + + std::unordered_map::const_iterator got; + //Find next target for red team. + if((int)homeRed["CapturePoint"]["CapturePointNumber"] == lastCP) { + //Red home base is the last capture point, count back from lastCP and find next target + for (int i = lastCP; i >= firstCP; i--) { + got = redTargets.find(i); + if(got == redTargets.end()) { + continue; + } else { + m_RedTeamCurrentTarget = got->second; + } + } + } else if ((int)homeRed["CapturePoint"]["CapturePointNumber"] == firstCP) { + //Red home is the first capture point, count forward from firstCP and find next target. + for (int i = firstCP; i <= lastCP; i++) { + got = redTargets.find(i); + if(got == redTargets.end()) { + //Target was not found, try the next one after that. + continue; + } else { + m_RedTeamCurrentTarget = got->second; + } + } } - //Check what team is the owner of Home2 and set their target to the next capturepoint - if ((int)home2["CapturePoint"]["HomePointForTeam"] == redTeam) { - m_RedTeamCurrentTarget = target2; - } else if ((int)home2["CapturePoint"]["HomePointForTeam"] == blueTeam) { - m_BlueTeamCurrentTarget = target2; + //Find next target for blue team + if ((int)homeBlue["CapturePoint"]["CapturePointNumber"] == lastCP) { + //Red home base is the last capture point, count back from lastCP and find next target + for (int i = lastCP; i >= firstCP; i--) { + got = blueTargets.find(i); + if (got == blueTargets.end()) { + continue; + } else { + m_BlueTeamCurrentTarget = got->second; + } + } + } else if ((int)homeBlue["CapturePoint"]["CapturePointNumber"] == firstCP) { + //Red home is the first capture point, count forward from firstCP and find next target. + for (int i = firstCP; i <= lastCP; i++) { + got = blueTargets.find(i); + if (got == blueTargets.end()) { + //Target was not found, try the next one after that. + continue; + } else { + m_BlueTeamCurrentTarget = got->second; + } + } } } } @@ -93,14 +153,14 @@ void CapturePointArrowHUDSystem::Update(double dt) pos = currentTeam == redTeam ? m_RedTeamCurrentTarget : currentTeam == blueTeam ? m_BlueTeamCurrentTarget : glm::vec3(0.f); - glm::vec3& arrowOri = ArrowEntity["Transform"]["Orientation"]; - glm::vec3 lookVector = glm::normalize(Transform::AbsolutePosition(ArrowEntity) - pos); //Maybe should be player instead + glm::vec3& arrowOri = arrowEntity["Transform"]["Orientation"]; + glm::vec3 lookVector = glm::normalize(Transform::AbsolutePosition(arrowEntity) - pos); //Maybe should be player instead float pitch = std::asin(-lookVector.y); float yaw = std::atan2(lookVector.x, lookVector.z); arrowOri.x = pitch; arrowOri.y = yaw; arrowOri.z = 0.f; - EntityWrapper parent = ArrowEntity.Parent(); + EntityWrapper parent = arrowEntity.Parent(); if (parent.Valid()) { arrowOri -= Transform::AbsoluteOrientationEuler(parent); } @@ -109,8 +169,7 @@ void CapturePointArrowHUDSystem::Update(double dt) bool CapturePointArrowHUDSystem::OnCapturePointCaptured(Events::Captured& e) { - if (!e.NextCapturePoint.HasComponent("Team")) - { + if (!e.NextCapturePoint.HasComponent("Team")) { return 0; } @@ -119,18 +178,11 @@ bool CapturePointArrowHUDSystem::OnCapturePointCaptured(Events::Captured& e) int redTeam = (int)cTeam["Team"].Enum("Red"); int blueTeam = (int)cTeam["Team"].Enum("Blue"); int spectatorTeam = (int)cTeam["Team"].Enum("Spectator"); - int target = -1; - - if (e.NextCapturePoint.HasComponent("CapturePoint")) { - target = (int)e.NextCapturePoint["CapturePoint"]["CapturePointNumber"]; - } else { - return 0; - } if(e.TeamNumberThatCapturedCapturePoint == redTeam) { m_RedTeamCurrentTarget = Transform::AbsolutePosition(e.NextCapturePoint); } else if (e.TeamNumberThatCapturedCapturePoint == blueTeam) { - m_BlueTeamCurrentTarget = Transform::AbsolutePosition(e.NextCapturePoint);; + m_BlueTeamCurrentTarget = Transform::AbsolutePosition(e.NextCapturePoint); } m_InitialtargetsSet = true; diff --git a/src/Game/Systems/CapturePointSystem.cpp b/src/Game/Systems/CapturePointSystem.cpp index f748ff09..6cbb1b2f 100644 --- a/src/Game/Systems/CapturePointSystem.cpp +++ b/src/Game/Systems/CapturePointSystem.cpp @@ -103,6 +103,7 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp } } if (m_RecentlyCapturedNeedNextCapturePointNow) { + //TODO: Next capture point for both teams m_CapturedEvent.NextCapturePoint = m_CapturedEvent.TeamNumberThatCapturedCapturePoint == blueTeam ? m_CapturePointNumberToEntityMap[nextPossibleCapturePoint["Blue"]] : m_CapturePointNumberToEntityMap[nextPossibleCapturePoint["Red"]]; From 07ccb9c04195ea45f2882fce2b92dbc071559a16 Mon Sep 17 00:00:00 2001 From: viktorljung Date: Wed, 2 Mar 2016 13:30:04 +0100 Subject: [PATCH 068/130] AutoAnimationBlend on unique node working but scale is not working correctly --- include/Engine/Rendering/AnimationSystem.h | 54 +- include/Engine/Rendering/BlendTree.h | 12 +- include/Engine/Rendering/EAnimationBlend.h | 21 + .../Engine/Rendering/EAutoAnimationBlend.h | 21 + include/Engine/Rendering/Skeleton.h | 2 +- resources/Schema/Entities/AnimationTests2.xml | 1175 ++++++++--------- resources/Schema/Entities/Skeleton.xml | 233 ++-- resources/Schema/Entities/derp.xml | 298 +++++ src/Engine/Core/Util/Logging.cpp | 4 +- src/Engine/Rendering/AnimationSystem.cpp | 227 +++- src/Engine/Rendering/BlendTree.cpp | 88 +- src/Engine/Rendering/Renderer.cpp | 2 +- src/Engine/Rendering/Skeleton.cpp | 16 +- 13 files changed, 1404 insertions(+), 749 deletions(-) create mode 100644 include/Engine/Rendering/EAnimationBlend.h create mode 100644 include/Engine/Rendering/EAutoAnimationBlend.h create mode 100644 resources/Schema/Entities/derp.xml diff --git a/include/Engine/Rendering/AnimationSystem.h b/include/Engine/Rendering/AnimationSystem.h index d05dc765..1ea076fd 100644 --- a/include/Engine/Rendering/AnimationSystem.h +++ b/include/Engine/Rendering/AnimationSystem.h @@ -3,13 +3,19 @@ #include "GLM.h" -#include "Common.h" -#include "Core/System.h" -#include "Core/ResourceManager.h" +#include "../Common.h" +#include "../Core/System.h" +#include "../Core/ResourceManager.h" #include "Rendering/Model.h" #include "Rendering/EAnimationComplete.h" #include "Rendering/Skeleton.h" #include "Rendering/BlendTree.h" +#include "Rendering/EAnimationBlend.h" +#include "Rendering/EAutoAnimationBlend.h" +#include "../Input/EInputCommand.h" +#include "../Core/EntityWrapper.h" + +#include "imgui/imgui.h" class AnimationSystem : public ImpureSystem { @@ -20,7 +26,49 @@ public: private: void CreateBlendTrees(); void UpdateAnimations(double dt); + void UpdateWeights(double dt); + void AnimationComplete(EntityWrapper animationEntity); + EventRelay m_EAnimationBlend; + bool OnAnimationBlend(Events::AnimationBlend& e); + EventRelay m_EAutoAnimationBlend; + bool OnAutoAnimationBlend(Events::AutoAnimationBlend& e); + + + EventRelay m_EInputCommand; + bool OnInputCommand(const Events::InputCommand& e); + + struct BlendJob + { + EntityWrapper BlendEntity = EntityWrapper::Invalid; + double StartWeight; + double GoalWeight; + double Duration; + double CurrentTime = 0.0; + }; + + struct QueuedBlendJob : BlendJob + { + EntityWrapper AnimationEntity = EntityWrapper::Invalid; + }; + + struct AutoBlendJob + { + EntityWrapper RootNode = EntityWrapper::Invalid; + double Duration; + double CurrentTime = 0.0; + BlendTree::AutoBlendInfo BlendInfo; + }; + + std::list m_AutoBlendJobs; + std::list m_BlendJobs; + std::list m_QueuedBlendJobs; + + char m_AnimationName1[20] = "Run"; + float m_BlendTime1 = 0.5f; + + char m_AnimationName2[20] = "Jump"; + float m_BlendTime2 = 0.5f; }; #endif \ No newline at end of file diff --git a/include/Engine/Rendering/BlendTree.h b/include/Engine/Rendering/BlendTree.h index 5b38080d..b19fbe4f 100644 --- a/include/Engine/Rendering/BlendTree.h +++ b/include/Engine/Rendering/BlendTree.h @@ -23,12 +23,13 @@ public: struct Node { std::string Name; + EntityWrapper Entity; Node* Parent = nullptr; Node* Child[2] = { nullptr, nullptr }; NodeType Type; std::map Pose; //std::vector Pose; - float Weight = 0.f; + double Weight = 0.0; Node* Next() { Node* next = this; @@ -54,7 +55,12 @@ public: }; - + struct AutoBlendInfo + { + std::string NodeName; + double progress; + std::unordered_map StartWeights; + }; BlendTree(EntityWrapper ModelEntity, Skeleton* skeleton); @@ -66,6 +72,7 @@ public: bool IsValid() { return (m_Root == nullptr ? false : true); } void PrintTree(); + BlendTree::AutoBlendInfo AutoBlendStep(AutoBlendInfo blendInfo); private: Skeleton* m_Skeleton = nullptr; @@ -76,6 +83,7 @@ private: std::vector AccumulateFinalPose(); BlendTree::Node* FillTreeByName(Node* parentNode, std::string name, EntityWrapper parentEntity); + std::vector FindNodesByName(std::string name); void Blend(std::map& pose); }; diff --git a/include/Engine/Rendering/EAnimationBlend.h b/include/Engine/Rendering/EAnimationBlend.h new file mode 100644 index 00000000..880a2fd0 --- /dev/null +++ b/include/Engine/Rendering/EAnimationBlend.h @@ -0,0 +1,21 @@ +#ifndef Events_AnimationBlend_h__ +#define Events_AnimationBlend_h__ + +#include "../Core/EventBroker.h" +#include "../Core/EntityWrapper.h" + +namespace Events +{ + +struct AnimationBlend : Event +{ + EntityWrapper BlendEntity = EntityWrapper::Invalid; + double GoalWeight; + double Duration; + + EntityWrapper AnimationEntity = EntityWrapper::Invalid; +}; + +} + +#endif diff --git a/include/Engine/Rendering/EAutoAnimationBlend.h b/include/Engine/Rendering/EAutoAnimationBlend.h new file mode 100644 index 00000000..b148664f --- /dev/null +++ b/include/Engine/Rendering/EAutoAnimationBlend.h @@ -0,0 +1,21 @@ +#ifndef Events_AutoAnimationBlend_h__ +#define Events_AutoAnimationBlend_h__ + +#include "../Core/EventBroker.h" +#include "../Core/EntityWrapper.h" + +namespace Events +{ + +struct AutoAnimationBlend : Event +{ + EntityWrapper RootNode = EntityWrapper::Invalid; + std::string NodeName; + double Duration; + + EntityWrapper AnimationEntity = EntityWrapper::Invalid; +}; + +} + +#endif diff --git a/include/Engine/Rendering/Skeleton.h b/include/Engine/Rendering/Skeleton.h index ffa08452..e812bf12 100644 --- a/include/Engine/Rendering/Skeleton.h +++ b/include/Engine/Rendering/Skeleton.h @@ -67,7 +67,7 @@ public: std::map GetFrameBones(const Animation* animation, double time, bool additive, bool noRootMotion = false); glm::mat4 GetBoneTransform(const Bone* bone, const Animation* animation, float time, glm::mat4 childMatrix); - std::map BlendPoses(const std::map& pose1, const std::map& pose2, float weight); + std::map BlendPoses(const std::map& pose1, const std::map& pose2, double weight); std::map OverridePose(const std::map& overridePose, const std::map& targetPose); std::map BlendPoseAdditive(const std::map& additivePose, const std::map& targetPose); void GetFinalPose(std::map& boneMatrices, std::vector& finalPose, std::map& boneTransforms); diff --git a/resources/Schema/Entities/AnimationTests2.xml b/resources/Schema/Entities/AnimationTests2.xml index 84663233..fa2a8463 100644 --- a/resources/Schema/Entities/AnimationTests2.xml +++ b/resources/Schema/Entities/AnimationTests2.xml @@ -3,8 +3,8 @@ - 0.5 - 2.2999999523162842 + 0.40000000596046448 + 3 @@ -21,7 +21,7 @@ - 0.10000047832727432 + 0.80000001192092896 Models/Widgets/Lights/DirectionalLightWidget.mesh @@ -53,8 +53,8 @@ FinalBlend - 4 - Models/Characters/Assault/Assaulttest.mesh + 5 + Models/Characters/Defender/DefenderRed.mesh @@ -68,9 +68,9 @@ Models/Weapons/Blue/AssaultWeaponBlue.mesh - + - + @@ -112,7 +112,7 @@ ShootBlend Reload - 1 + 0 @@ -131,7 +131,7 @@ ShootFastRifleU - + 1 @@ -142,7 +142,7 @@ ShootRifleU - + 1 @@ -155,8 +155,8 @@ ReloadSwitchU - - 1 + + false @@ -169,598 +169,7 @@ StandCrouchBlend Jump - 1 - - - - - - - - StandMovement - CrouchMovement - 1 - - - - - - - - Walk - StrafeBlend - 1 - - - - - - - - CrouchWalkF - - 1 - - - - - - - - - Left - Right - 1 - - - - - - - - CrouchStrafeLeftF - - 1 - - - - - - - - - CrouchStrafeRightF - - 1 - - - - - - - - - - - - - RunWalkBlend - StrafeBlend - 1 - - - - - - - - Run - Walk - 0 - - - - - - - - RunF - - 1 - - - - - - - - - WalkF - - 1 - - - - - - - - - - - Left - Right - 0 - - - - - - - - StrafeLeftF - - 1 - - - - - - - - - StrafeRightF - - 1 - - - - - - - - - - - - - - - JumpF - - 1 - - - - - - - - - - - - - - - Aim - FinalBlend - - - Models/Characters/Assault/Assaulttest.mesh - - - - - - - - - - - R_Arm_Weapon_Joint - - - Models/Weapons/Blue/AssaultWeaponBlue.mesh - - - - - - - - - - - - - 3 - - - - - - - - - - - AimRifleA - false - true - - - - - - - - - WeaponBlend - MovementBlend - - - - - - - - ShootBlend - Reload - 1 - - - - - - - - ShootFast - ShootSlow - 1 - - - - - - - - ShootFastRifleU - - 1 - - - - - - - - - ShootRifleU - - 1 - - - - - - - - - - - ReloadSwitchU - - 1 - - - - - - - - - - - StandCrouchBlend - Jump - 1 - - - - - - - - StandMovement - CrouchMovement - 1 - - - - - - - - Walk - StrafeBlend - 1 - - - - - - - - CrouchWalkF - - 1 - - - - - - - - - Left - Right - 1 - - - - - - - - CrouchStrafeLeftF - - 1 - - - - - - - - - CrouchStrafeRightF - - 1 - - - - - - - - - - - - - RunWalkBlend - StrafeBlend - 1 - - - - - - - - Run - Walk - 1 - - - - - - - - RunF - - 1 - - - - - - - - - WalkF - - 1 - - - - - - - - - - - Left - Right - 1 - - - - - - - - StrafeLeftF - - 1 - - - - - - - - - StrafeRightF - - 1 - - - - - - - - - - - - - - - JumpF - - 1 - - - - - - - - - - - - - - - Aim - FinalBlend - - - Models/Characters/Assault/Assaulttest.mesh - - - - - - - - - - - R_Arm_Weapon_Joint - - - Models/Weapons/Blue/AssaultWeaponBlue.mesh - - - - - - - - - - - - - 3 - - - - - - - - - - - AimRifleA - - false - true - - - - - - - - - WeaponBlend - MovementBlend - - - - - - - - ShootBlend - Reload - 1 - - - - - - - - ShootFast - ShootSlow - 1 - - - - - - - - ShootFastRifleU - - 1 - - - - - - - - - ShootRifleU - - 1 - - - - - - - - - - - ReloadSwitchU - - 1 - - - - - - - - - - - StandCrouchBlend - Jump - 1 + 0.48000049591064453 @@ -789,7 +198,7 @@ CrouchWalkF - + 1 @@ -810,7 +219,7 @@ CrouchStrafeLeftF - + 1 @@ -821,7 +230,7 @@ CrouchStrafeRightF - + 1 @@ -837,7 +246,7 @@ RunWalkBlend StrafeBlend - 1 + 0 @@ -847,7 +256,7 @@ Run Walk - 1 + 0 @@ -856,8 +265,7 @@ RunF - - 1 + @@ -867,7 +275,7 @@ WalkF - + 1 @@ -881,7 +289,7 @@ Left Right - 1 + 0 @@ -890,7 +298,7 @@ StrafeLeftF - + 1 @@ -901,7 +309,7 @@ StrafeRightF - + 1 @@ -918,8 +326,8 @@ JumpF - - 1 + + false @@ -929,8 +337,541 @@ + + + + + + + + + + + R_Arm_Weapon_Joint + + + + Models/Core/UnitCube.mesh + + true + + + + + + + + + + + + + R_Hand + + true + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + R_Arm + + true + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + R_Shoulder + + true + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + Neck + + true + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + Spine_3 + + true + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + Spine_2 + + true + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + Spine_1 + + true + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + Hip + + true + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + L_Leg_Top + + true + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + L_Leg_Bottom + + true + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + L_Foot + + true + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + L_Toe + + true + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + L_Shoulder + + true + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + L_Arm + + true + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + L_Hand + + true + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + L_Shoulder_Armor_Joint + + true + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + Chin + + true + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + Head + + true + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + Perietal + + true + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + L_Elbow + + true + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + R_Leg_Bottom + + true + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + R_Elbow + + true + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + R_Leg_Top + + true + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + R_Foot + + true + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + R_Toe + + true + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + R_Shoulder_Armor_Joint + + true + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + + + Models/Core/UnitPlane.mesh + + + + + + + diff --git a/resources/Schema/Entities/Skeleton.xml b/resources/Schema/Entities/Skeleton.xml index b8deb2eb..76674dec 100644 --- a/resources/Schema/Entities/Skeleton.xml +++ b/resources/Schema/Entities/Skeleton.xml @@ -18,9 +18,9 @@ true - + - + @@ -29,16 +29,17 @@ R_Hand - + + true Models/Core/UnitCube.mesh - - - + + + @@ -47,16 +48,17 @@ R_Arm - + + true Models/Core/UnitCube.mesh - - - + + + @@ -65,16 +67,17 @@ R_Shoulder - + + true Models/Core/UnitCube.mesh - - - + + + @@ -83,16 +86,17 @@ Neck - + + true Models/Core/UnitCube.mesh - - - + + + @@ -101,16 +105,17 @@ Spine_3 - + + true Models/Core/UnitCube.mesh - - - + + + @@ -119,16 +124,17 @@ Spine_2 - + + true Models/Core/UnitCube.mesh - - - + + + @@ -137,16 +143,17 @@ Spine_1 - + + true Models/Core/UnitCube.mesh - - - + + + @@ -155,15 +162,17 @@ Hip - + + true Models/Core/UnitCube.mesh - - + + + @@ -172,16 +181,17 @@ L_Leg_Top - + + true Models/Core/UnitCube.mesh - + - + @@ -190,16 +200,17 @@ L_Leg_Bottom - + + true Models/Core/UnitCube.mesh - + - + @@ -208,16 +219,17 @@ L_Foot - + + true Models/Core/UnitCube.mesh - - - + + + @@ -226,16 +238,17 @@ L_Toe - + + true Models/Core/UnitCube.mesh - - - + + + @@ -244,16 +257,17 @@ L_Shoulder - + + true Models/Core/UnitCube.mesh - - - + + + @@ -262,16 +276,17 @@ L_Arm - + + true Models/Core/UnitCube.mesh - - - + + + @@ -280,16 +295,17 @@ L_Hand - + + true Models/Core/UnitCube.mesh - - - + + + @@ -298,16 +314,17 @@ L_Shoulder_Armor_Joint - + + true Models/Core/UnitCube.mesh - - - + + + @@ -316,16 +333,17 @@ Chin - + + true Models/Core/UnitCube.mesh - - - + + + @@ -334,16 +352,17 @@ Head - + + true Models/Core/UnitCube.mesh - - - + + + @@ -352,16 +371,17 @@ Perietal - + + true Models/Core/UnitCube.mesh - - - + + + @@ -370,16 +390,17 @@ L_Elbow - + + true Models/Core/UnitCube.mesh - - - + + + @@ -388,16 +409,17 @@ R_Leg_Bottom - + + true Models/Core/UnitCube.mesh - - - + + + @@ -406,16 +428,17 @@ R_Elbow - + + true Models/Core/UnitCube.mesh - - - + + + @@ -424,16 +447,17 @@ R_Leg_Top - + + true Models/Core/UnitCube.mesh - - - + + + @@ -442,16 +466,17 @@ R_Foot - + + true Models/Core/UnitCube.mesh - - - + + + @@ -460,16 +485,17 @@ R_Toe - + + true Models/Core/UnitCube.mesh - - - + + + @@ -478,16 +504,17 @@ R_Shoulder_Armor_Joint - + + true Models/Core/UnitCube.mesh - - - + + + diff --git a/resources/Schema/Entities/derp.xml b/resources/Schema/Entities/derp.xml new file mode 100644 index 00000000..b8735335 --- /dev/null +++ b/resources/Schema/Entities/derp.xml @@ -0,0 +1,298 @@ + + + + + + Aim + FinalBlend + + + 4 + Models/Characters/Sniper/SniperBlue.mesh + + + + + + + + + R_Arm_Weapon_Joint + + + Models/Weapons/Blue/AssaultWeaponBlue.mesh + + + + + + + + + + + + + 3 + + + + + + + + + + + AimRifleA + + false + true + + + + + + + + + WeaponBlend + MovementBlend + + + + + + + + ShootBlend + Reload + 1 + + + + + + + + ShootFast + ShootSlow + 1 + + + + + + + + ShootFastRifleU + + 1 + + + + + + + + + ShootRifleU + + 1 + + + + + + + + + + + ReloadSwitchU + + false + + + + + + + + + + + StandCrouchBlend + Jump + 1 + + + + + + + + StandMovement + CrouchMovement + 1 + + + + + + + + Walk + StrafeBlend + 1 + + + + + + + + CrouchWalkF + + 1 + + + + + + + + + Left + Right + 1 + + + + + + + + CrouchStrafeLeftF + + 1 + + + + + + + + + CrouchStrafeRightF + + 1 + + + + + + + + + + + + + RunWalkBlend + StrafeBlend + 1 + + + + + + + + Run + Walk + 1 + + + + + + + + RunF + + 1 + + + + + + + + + WalkF + + 1 + + + + + + + + + + + Left + Right + 0 + + + + + + + + StrafeLeftF + + 1 + + + + + + + + + StrafeRightF + + 1 + + + + + + + + + + + + + + + JumpF + + false + + + + + + + + + + + + diff --git a/src/Engine/Core/Util/Logging.cpp b/src/Engine/Core/Util/Logging.cpp index 63a6f380..e5427965 100644 --- a/src/Engine/Core/Util/Logging.cpp +++ b/src/Engine/Core/Util/Logging.cpp @@ -33,8 +33,8 @@ void _LOG(_LOG_LEVEL logLevel, const char* file, const char* func, unsigned int va_end(args); if (logLevel == LOG_LEVEL_ERROR) { - std::cerr << file << ":" << line << " " << func << std::endl; - std::cerr << _LOG_LEVEL_PREFIX[logLevel] << message << std::endl; + /*std::cerr << file << ":" << line << " " << func << std::endl; + std::cerr << _LOG_LEVEL_PREFIX[logLevel] << message << std::endl;*/ } else { std::cout << _LOG_LEVEL_PREFIX[logLevel] << message << std::endl; } diff --git a/src/Engine/Rendering/AnimationSystem.cpp b/src/Engine/Rendering/AnimationSystem.cpp index 5bc64535..11a21881 100644 --- a/src/Engine/Rendering/AnimationSystem.cpp +++ b/src/Engine/Rendering/AnimationSystem.cpp @@ -3,13 +3,21 @@ AnimationSystem::AnimationSystem(SystemParams params) : System(params) { - + EVENT_SUBSCRIBE_MEMBER(m_EAnimationBlend, &AnimationSystem::OnAnimationBlend); + EVENT_SUBSCRIBE_MEMBER(m_EAutoAnimationBlend, &AnimationSystem::OnAutoAnimationBlend); + EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &AnimationSystem::OnInputCommand); } void AnimationSystem::Update(double dt) { + ImGui::InputText("AnimationName1", &m_AnimationName1[0], sizeof(m_AnimationName1)); + ImGui::SliderFloat("Blendtime1", &m_BlendTime1, 0.f, 10.f); + ImGui::InputText("AnimationName2", &m_AnimationName2[0], sizeof(m_AnimationName2)); + ImGui::SliderFloat("Blendtime2", &m_BlendTime2, 0.f, 10.f); + UpdateAnimations(dt); CreateBlendTrees(); + UpdateWeights(dt); } void AnimationSystem::CreateBlendTrees() @@ -94,16 +102,17 @@ void AnimationSystem::UpdateAnimations(double dt) e.Entity = entity; e.Name = (std::string)animationC["AnimationName"]; m_EventBroker->Publish(e); + AnimationComplete(entity); + (double&)animationC["Speed"] = 0.0; } else if (nextTime < 0) { Events::AnimationComplete e; e.Entity = entity; e.Name = (std::string)animationC["AnimationName"]; m_EventBroker->Publish(e); + AnimationComplete(entity); nextTime = 0; + (double&)animationC["Speed"] = 0.0; } - - (double&)animationC["Speed"] = 0.0; - } else { if (nextTime > animation->Duration) { Events::AnimationComplete e; @@ -131,3 +140,213 @@ void AnimationSystem::UpdateAnimations(double dt) } } + +void AnimationSystem::UpdateWeights(double dt) +{ + /* for (auto it = m_BlendJobs.begin(); it != m_BlendJobs.end(); it++) { + if (!it->BlendEntity.Valid()) { + it = m_BlendJobs.erase(it); + continue; + } + + if (it->BlendEntity.HasComponent("Blend")) { + it->CurrentTime += dt; + double progress = it->CurrentTime / it->Duration; + progress = glm::clamp(progress, 0.0, 1.0); + + double weight = ((it->GoalWeight - it->StartWeight) * progress) + it->StartWeight; + (double&)it->BlendEntity["Blend"]["Weight"] = weight; + + if(weight == it->GoalWeight) { + it = m_BlendJobs.erase(it); + } + } + }*/ + + + for (auto it = m_AutoBlendJobs.begin(); it != m_AutoBlendJobs.end();) { + it->CurrentTime += dt; + + if (!it->RootNode.Valid()) { + it = m_AutoBlendJobs.erase(it); + continue; + } + + if (!it->RootNode.HasComponent("Model")) { + it = m_AutoBlendJobs.erase(it); + continue; + } + + Model* model; + try { + model = ResourceManager::Load<::Model, true>(it->RootNode["Model"]["Resource"]); + } catch (const std::exception&) { + continue; + } + + Skeleton* skeleton = model->m_RawModel->m_Skeleton; + if (skeleton == nullptr) { + continue; + } + + std::shared_ptr blendTree; + if(skeleton->BlendTrees.find(it->RootNode) != skeleton->BlendTrees.end()) { + blendTree = skeleton->BlendTrees.at(it->RootNode); + } else { + it = m_AutoBlendJobs.erase(it); + continue; + } + + + it->BlendInfo.progress = glm::clamp(it->CurrentTime / it->Duration, 0.0, 1.0); + it->BlendInfo = blendTree->AutoBlendStep(it->BlendInfo); + + + if (it->CurrentTime >= it->Duration) { + it = m_AutoBlendJobs.erase(it); + continue; + } + + ++it; + } +} + + +void AnimationSystem::AnimationComplete(EntityWrapper animationEntity) +{ + for (auto it = m_QueuedBlendJobs.begin(); it != m_QueuedBlendJobs.end(); it++) { + if (!it->BlendEntity.Valid() || !it->AnimationEntity.Valid()) { + it = m_QueuedBlendJobs.erase(it); + continue; + } + + if(animationEntity == it->AnimationEntity) { + BlendJob bj; + bj.BlendEntity = it->BlendEntity; + bj.StartWeight = it->StartWeight; + bj.GoalWeight = it->GoalWeight; + bj.Duration = it->Duration; + bj.CurrentTime = 0.0; + m_BlendJobs.push_back(bj); + it = m_QueuedBlendJobs.erase(it); + } + + } + +} + +bool AnimationSystem::OnAnimationBlend(Events::AnimationBlend& e) +{ + if(!e.BlendEntity.Valid()) { + return false; + } + if(!e.BlendEntity.HasComponent("Blend")){ + return false; + } + + if (e.AnimationEntity.Valid()) { + if (e.AnimationEntity.HasComponent("Animation")) { + QueuedBlendJob qbj; + qbj.BlendEntity = e.BlendEntity; + qbj.StartWeight = (double)e.BlendEntity["Blend"]["Weight"]; + qbj.GoalWeight = e.GoalWeight; + qbj.Duration = e.Duration; + qbj.CurrentTime = 0.0; + qbj.AnimationEntity = e.AnimationEntity; + m_QueuedBlendJobs.push_back(qbj); + return true; + } + } + + BlendJob bj; + bj.BlendEntity = e.BlendEntity; + bj.StartWeight = (double)e.BlendEntity["Blend"]["Weight"]; + bj.GoalWeight = e.GoalWeight; + bj.Duration = e.Duration; + bj.CurrentTime = 0.0; + m_BlendJobs.push_back(bj); + + return true; +} + + +bool AnimationSystem::OnAutoAnimationBlend(Events::AutoAnimationBlend& e) +{ + if(!e.RootNode.Valid()) { + return false; + } + + if(!e.RootNode.HasComponent("Model")) { + return false; + } + + AutoBlendJob abj; + abj.RootNode = e.RootNode; + abj.CurrentTime = 0.0; + abj.Duration = e.Duration; + + BlendTree::AutoBlendInfo abInfo; + abInfo.NodeName = e.NodeName; + abInfo.progress = 0.0; + + abj.BlendInfo = abInfo; + + m_AutoBlendJobs.push_back(abj); + + +} + +bool AnimationSystem::OnInputCommand(const Events::InputCommand& e) +{ + + if (e.Value == 1.f) { + if (e.Command == "BlendTest0") { + + + auto blendComponents = m_World->GetComponents("BlendAdditive"); + + if (blendComponents == nullptr) { + return false; + } + + + for (auto& bc : *blendComponents) { + EntityWrapper entity = EntityWrapper(m_World, bc.EntityID); + + if (entity.Name() == "Assault") { + + Events::AutoAnimationBlend aeb; + aeb.Duration = m_BlendTime1; + aeb.NodeName = m_AnimationName1; + aeb.RootNode = entity; + m_EventBroker->Publish(aeb); + + } + } + + } else if (e.Command == "BlendTest1") { + + auto blendComponents = m_World->GetComponents("BlendAdditive"); + + if (blendComponents == nullptr) { + return false; + } + + + for (auto& bc : *blendComponents) { + EntityWrapper entity = EntityWrapper(m_World, bc.EntityID); + + if (entity.Name() == "Assault") { + + Events::AutoAnimationBlend aeb; + aeb.Duration = m_BlendTime2; + aeb.NodeName = m_AnimationName2; + aeb.RootNode = entity; + m_EventBroker->Publish(aeb); + + } + } + } + } +} + diff --git a/src/Engine/Rendering/BlendTree.cpp b/src/Engine/Rendering/BlendTree.cpp index 0305af19..8ef67f0f 100644 --- a/src/Engine/Rendering/BlendTree.cpp +++ b/src/Engine/Rendering/BlendTree.cpp @@ -14,6 +14,7 @@ BlendTree::BlendTree(EntityWrapper ModelEntity, Skeleton* skeleton) } m_Root = new Node(); + m_Root->Entity = ModelEntity; m_Root->Name = ModelEntity.Name(); m_Root->Pose = m_Skeleton->GetFrameBones(animation, (double)ModelEntity["Animation"]["Time"], (bool)ModelEntity["Animation"]["Additive"]); m_Root->Parent = nullptr; @@ -21,15 +22,18 @@ BlendTree::BlendTree(EntityWrapper ModelEntity, Skeleton* skeleton) } else if (ModelEntity.HasComponent("Blend")) { m_Root = new Node(); + m_Root->Entity = ModelEntity; m_Root->Name = ModelEntity.Name(); m_Root->Parent = nullptr; m_Root->Type = NodeType::Blend; m_Root->Weight = (double)ModelEntity["Blend"]["Weight"]; + (double&)ModelEntity["Blend"]["Weight"] = glm::clamp((double)ModelEntity["Blend"]["Weight"], 0.0, 1.0); m_Root->Child[0] = FillTreeByName(m_Root, (std::string)ModelEntity["Blend"]["Pose1"], ModelEntity); m_Root->Child[1] = FillTreeByName(m_Root, (std::string)ModelEntity["Blend"]["Pose2"], ModelEntity); } else if (ModelEntity.HasComponent("BlendOverride")) { m_Root = new Node(); + m_Root->Entity = ModelEntity; m_Root->Name = ModelEntity.Name(); m_Root->Parent = nullptr; m_Root->Type = NodeType::Override; @@ -38,6 +42,7 @@ BlendTree::BlendTree(EntityWrapper ModelEntity, Skeleton* skeleton) } else if (ModelEntity.HasComponent("BlendAdditive")) { m_Root = new Node(); + m_Root->Entity = ModelEntity; m_Root->Name = ModelEntity.Name(); m_Root->Parent = nullptr; m_Root->Type = NodeType::Additive; @@ -97,8 +102,6 @@ void BlendTree::PrintTree() LOG_INFO("%s", currentNode->Name.c_str()); currentNode = currentNode->Next(); } - - } BlendTree::Node* BlendTree::FillTreeByName(Node* parentNode, std::string name, EntityWrapper parentEntity) @@ -116,6 +119,7 @@ BlendTree::Node* BlendTree::FillTreeByName(Node* parentNode, std::string name, E } Node* node = new Node(); + node->Entity = childEntity; node->Name = childEntity.Name(); node->Pose = m_Skeleton->GetFrameBones(animation, (double)childEntity["Animation"]["Time"], (bool)childEntity["Animation"]["Additive"]); node->Parent = parentNode; @@ -124,24 +128,26 @@ BlendTree::Node* BlendTree::FillTreeByName(Node* parentNode, std::string name, E } else if (childEntity.HasComponent("Blend")) { Node* node = new Node(); + node->Entity = childEntity; node->Name = childEntity.Name(); node->Parent = parentNode; node->Type = NodeType::Blend; - (double&)childEntity["Blend"]["Weight"] = glm::clamp((float)(double)childEntity["Blend"]["Weight"], 0.f, 1.f); + (double&)childEntity["Blend"]["Weight"] = glm::clamp((double)childEntity["Blend"]["Weight"], 0.0, 1.0); node->Weight = (double)childEntity["Blend"]["Weight"]; - if (node->Weight < 1.f && node->Weight > 0.f) { + //if (node->Weight < 1.f && node->Weight > 0.f) { node->Child[0] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose1"], childEntity); node->Child[1] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose2"], childEntity); - } else if (node->Weight == 1.f) { + /* } else if (node->Weight == 1.f) { node->Child[0] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose1"], childEntity); } else if (node->Weight == 0.f) { node->Child[1] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose2"], childEntity); - } + }*/ return node; } else if (childEntity.HasComponent("BlendOverride")) { Node* node = new Node(); + node->Entity = childEntity; node->Name = childEntity.Name(); node->Parent = parentNode; node->Type = NodeType::Override; @@ -150,6 +156,7 @@ BlendTree::Node* BlendTree::FillTreeByName(Node* parentNode, std::string name, E return node; } else if (childEntity.HasComponent("BlendAdditive")) { Node* node = new Node(); + node->Entity = childEntity; node->Name = childEntity.Name(); node->Parent = parentNode; node->Type = NodeType::Additive; @@ -162,6 +169,75 @@ BlendTree::Node* BlendTree::FillTreeByName(Node* parentNode, std::string name, E return nullptr; } + +std::vector BlendTree::FindNodesByName(std::string name) +{ + std::vector Nodes; + Node* currentNode = m_Root; + + while (currentNode->Child[0] != nullptr) { + currentNode = currentNode->Child[0]; + } + + while (currentNode != nullptr) { + if(currentNode->Name == name) { + Nodes.push_back(currentNode); + } + currentNode = currentNode->Next(); + } + return Nodes; +} + + +BlendTree::AutoBlendInfo BlendTree::AutoBlendStep(AutoBlendInfo blendInfo) +{ + std::vector goalNodes = FindNodesByName(blendInfo.NodeName); + + if(goalNodes.size() == 0) { + return blendInfo; + } else if(goalNodes.size() == 1) { + Node* currentNode = goalNodes[0]->Parent; + Node* lastNode = goalNodes[0]; + + while (currentNode != nullptr) + { + + + if(!currentNode->Entity.HasComponent("Blend")) { + return blendInfo; + } + + double startWeight; + if(blendInfo.StartWeights.find(currentNode->Entity) != blendInfo.StartWeights.end()) { + startWeight = blendInfo.StartWeights.at(currentNode->Entity); + } else { + startWeight = currentNode->Weight; + blendInfo.StartWeights[currentNode->Entity] = startWeight; + } + + double goalWeight; + if(currentNode->Child[0] == lastNode) { + goalWeight = 0.0; + } else if (currentNode->Child[1] == lastNode) { + goalWeight = 1.0; + } + + double weight = ((goalWeight - startWeight) * blendInfo.progress) + startWeight; + (double&)currentNode->Entity["Blend"]["Weight"] = weight; + currentNode->Weight = weight; + + lastNode = currentNode; + currentNode = currentNode->Parent; + } + + + } else if(goalNodes.size() >= 2) { + + } + + return blendInfo; +} + void BlendTree::Blend(std::map& pose) { Node* currentNode; diff --git a/src/Engine/Rendering/Renderer.cpp b/src/Engine/Rendering/Renderer.cpp index 251bba2b..fd75911d 100644 --- a/src/Engine/Rendering/Renderer.cpp +++ b/src/Engine/Rendering/Renderer.cpp @@ -142,7 +142,7 @@ void Renderer::Draw(RenderFrame& frame) PerformanceTimer::StopTimer("Renderer-Depth"); } PerformanceTimer::StartTimer("AO generation"); - m_SSAOPass->Draw(m_PickingPass->DepthBuffer(), frame.RenderScenes.front()->Camera); + //m_SSAOPass->Draw(m_PickingPass->DepthBuffer(), frame.RenderScenes.front()->Camera); GLuint ao = m_SSAOPass->SSAOTexture(); PerformanceTimer::StopTimer("AO generation"); for (auto scene : frame.RenderScenes){ diff --git a/src/Engine/Rendering/Skeleton.cpp b/src/Engine/Rendering/Skeleton.cpp index 4583de92..b6fea0bb 100644 --- a/src/Engine/Rendering/Skeleton.cpp +++ b/src/Engine/Rendering/Skeleton.cpp @@ -57,7 +57,7 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, const Animation* anim Animation::Keyframe::BoneProperty nextBoneProperty = nextFrame.BoneProperties; glm::vec3 position = currentBoneProperty.Position * (1.f - progress) + nextBoneProperty.Position * progress; - glm::quat rotation = glm::slerp(currentBoneProperty.Rotation, nextBoneProperty.Rotation, progress); + glm::quat rotation = glm::normalize(glm::slerp(currentBoneProperty.Rotation, nextBoneProperty.Rotation, progress)); glm::vec3 scale = currentBoneProperty.Scale * (1.f - progress) + nextBoneProperty.Scale * progress; // Flag for no root motion @@ -71,7 +71,7 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, const Animation* anim } else { // 1 keyframes for the current bone currentFrame = boneKeyFrames.at(0); - boneMatrix = (glm::translate(currentFrame.BoneProperties.Position) * glm::toMat4(currentFrame.BoneProperties.Rotation) * glm::scale(currentFrame.BoneProperties.Scale)); + boneMatrix = (glm::translate(currentFrame.BoneProperties.Position) * glm::toMat4(glm::normalize(currentFrame.BoneProperties.Rotation)) * glm::scale(currentFrame.BoneProperties.Scale)); boneMatrices[bone->ID] = boneMatrix;// *bone->OffsetMatrix; } } else { // 0 keyframes for the current bone @@ -244,7 +244,7 @@ glm::mat4 Skeleton::GetBoneTransform(const Bone* bone, const Animation* animatio } if (progress > 1.0f || progress < 0.0f) { - LOG_INFO("Progress %f", progress); + //LOG_INFO("Progress %f", progress); progress = glm::clamp(progress, 0.0f, 1.0f); } Animation::Keyframe::BoneProperty currentBoneProperty = currentFrame.BoneProperties; @@ -276,7 +276,7 @@ glm::mat4 Skeleton::GetBoneTransform(const Bone* bone, const Animation* animatio } } -std::map Skeleton::BlendPoses(const std::map& pose1, const std::map& pose2, float weight) +std::map Skeleton::BlendPoses(const std::map& pose1, const std::map& pose2, double weight) { std::map finalPose; @@ -285,8 +285,8 @@ std::map Skeleton::BlendPoses(const std::map& po glm::mat4 blendedPose = glm::mat4(0); if(pose1.find(boneID) != pose1.end() && pose2.find(boneID) != pose2.end()) { - blendedPose += pose1.at(boneID) * weight; - blendedPose += pose2.at(boneID) * (1.f - weight); + blendedPose += pose1.at(boneID) * (float)(1.0 - weight); + blendedPose += pose2.at(boneID) * (float)weight; finalPose[boneID] = blendedPose; } else if(pose1.find(boneID) != pose1.end()) { finalPose[boneID] = pose1.at(boneID); @@ -347,15 +347,11 @@ void Skeleton::GetFinalPose(std::map& boneMatrices, std::vector< void Skeleton::AccumulateFinalPose(std::map& boneMatrices, std::map& boneTransforms, const Bone* bone, glm::mat4 parentMatrix) { - glm::mat4 boneMatrix; - if (boneMatrices.find(bone->ID) != boneMatrices.end()) { - boneMatrix = parentMatrix * boneMatrices.at(bone->ID); boneMatrices[bone->ID] = boneMatrix * bone->OffsetMatrix; - } else { if (bone->Parent) { boneMatrix = parentMatrix * (glm::inverse(bone->OffsetMatrix) * bone->Parent->OffsetMatrix); From c3f24f494d2352604d10ba349a512a51edb67da2 Mon Sep 17 00:00:00 2001 From: viktorljung Date: Wed, 2 Mar 2016 13:34:47 +0100 Subject: [PATCH 069/130] fixup! AutoAnimationBlend on unique node working but scale is not working correctly Commited some things that shouldn't have been commited --- src/Engine/Core/Util/Logging.cpp | 4 ++-- src/Engine/Rendering/Renderer.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Engine/Core/Util/Logging.cpp b/src/Engine/Core/Util/Logging.cpp index e5427965..63a6f380 100644 --- a/src/Engine/Core/Util/Logging.cpp +++ b/src/Engine/Core/Util/Logging.cpp @@ -33,8 +33,8 @@ void _LOG(_LOG_LEVEL logLevel, const char* file, const char* func, unsigned int va_end(args); if (logLevel == LOG_LEVEL_ERROR) { - /*std::cerr << file << ":" << line << " " << func << std::endl; - std::cerr << _LOG_LEVEL_PREFIX[logLevel] << message << std::endl;*/ + std::cerr << file << ":" << line << " " << func << std::endl; + std::cerr << _LOG_LEVEL_PREFIX[logLevel] << message << std::endl; } else { std::cout << _LOG_LEVEL_PREFIX[logLevel] << message << std::endl; } diff --git a/src/Engine/Rendering/Renderer.cpp b/src/Engine/Rendering/Renderer.cpp index fd75911d..251bba2b 100644 --- a/src/Engine/Rendering/Renderer.cpp +++ b/src/Engine/Rendering/Renderer.cpp @@ -142,7 +142,7 @@ void Renderer::Draw(RenderFrame& frame) PerformanceTimer::StopTimer("Renderer-Depth"); } PerformanceTimer::StartTimer("AO generation"); - //m_SSAOPass->Draw(m_PickingPass->DepthBuffer(), frame.RenderScenes.front()->Camera); + m_SSAOPass->Draw(m_PickingPass->DepthBuffer(), frame.RenderScenes.front()->Camera); GLuint ao = m_SSAOPass->SSAOTexture(); PerformanceTimer::StopTimer("AO generation"); for (auto scene : frame.RenderScenes){ From 6968e71e0706a8adedbf8b135b7d25a6cf056107 Mon Sep 17 00:00:00 2001 From: Tleety Date: Wed, 2 Mar 2016 13:36:24 +0100 Subject: [PATCH 070/130] Arrow should now correctly track the next point no matter when you join the game --- src/Game/Systems/CapturePointArrowHUDSystem.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Game/Systems/CapturePointArrowHUDSystem.cpp b/src/Game/Systems/CapturePointArrowHUDSystem.cpp index 3488c0a8..bf6951a2 100644 --- a/src/Game/Systems/CapturePointArrowHUDSystem.cpp +++ b/src/Game/Systems/CapturePointArrowHUDSystem.cpp @@ -101,6 +101,7 @@ void CapturePointArrowHUDSystem::Update(double dt) continue; } else { m_RedTeamCurrentTarget = got->second; + break; } } } else if ((int)homeRed["CapturePoint"]["CapturePointNumber"] == firstCP) { @@ -112,6 +113,7 @@ void CapturePointArrowHUDSystem::Update(double dt) continue; } else { m_RedTeamCurrentTarget = got->second; + break; } } } @@ -125,6 +127,7 @@ void CapturePointArrowHUDSystem::Update(double dt) continue; } else { m_BlueTeamCurrentTarget = got->second; + break; } } } else if ((int)homeBlue["CapturePoint"]["CapturePointNumber"] == firstCP) { @@ -136,6 +139,7 @@ void CapturePointArrowHUDSystem::Update(double dt) continue; } else { m_BlueTeamCurrentTarget = got->second; + break; } } } @@ -151,7 +155,7 @@ void CapturePointArrowHUDSystem::Update(double dt) pos = m_BlueTeamCurrentTarget; } - pos = currentTeam == redTeam ? m_RedTeamCurrentTarget : currentTeam == blueTeam ? m_BlueTeamCurrentTarget : glm::vec3(0.f); + //pos = currentTeam == redTeam ? m_RedTeamCurrentTarget : currentTeam == blueTeam ? m_BlueTeamCurrentTarget : glm::vec3(0.f); glm::vec3& arrowOri = arrowEntity["Transform"]["Orientation"]; glm::vec3 lookVector = glm::normalize(Transform::AbsolutePosition(arrowEntity) - pos); //Maybe should be player instead From 629ebb871f9f6bb70484f3aa15f1a919b1415242 Mon Sep 17 00:00:00 2001 From: William Moberg Date: Wed, 2 Mar 2016 13:45:49 +0100 Subject: [PATCH 071/130] SpectatorCamera shows capturepoint HUD and respawntimer. It no longer requires CapturePointGameMode component to work. --- include/Engine/Core/World.h | 3 + .../Schema/Entities/NewMapWSpectatorCam.xml | 183 ++++++++++++++++- resources/Schema/Entities/SpectatorCamera.xml | 185 +++++++++++++++++- src/Engine/Core/World.cpp | 18 ++ src/Game/Systems/PlayerDeathSystem.cpp | 14 +- src/Game/Systems/PlayerSpawnSystem.cpp | 51 +++-- 6 files changed, 420 insertions(+), 34 deletions(-) diff --git a/include/Engine/Core/World.h b/include/Engine/Core/World.h index c9f738ce..d8e2c7ba 100644 --- a/include/Engine/Core/World.h +++ b/include/Engine/Core/World.h @@ -6,6 +6,7 @@ #include "ObjectPool.h" #include "ComponentPool.h" #include "EventBroker.h" +struct EntityWrapper; class World { @@ -49,6 +50,8 @@ public: void SetName(EntityID entity, const std::string& name); // Get the textual name of an entity std::string GetName(EntityID entity) const; + // Get the first entity in the world with the name. + EntityWrapper GetFirstEntityByName(const std::string& name); private: EventBroker* m_EventBroker = nullptr; diff --git a/resources/Schema/Entities/NewMapWSpectatorCam.xml b/resources/Schema/Entities/NewMapWSpectatorCam.xml index f74a4857..5e8b6bc2 100644 --- a/resources/Schema/Entities/NewMapWSpectatorCam.xml +++ b/resources/Schema/Entities/NewMapWSpectatorCam.xml @@ -5335,18 +5335,197 @@ Fonts/DroidSans.ttf,64 - + - + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + 2 + + + + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + 3 + + + + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + 4 + + + + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + 1 + + + 0.59265931447347009 + + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + + + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + diff --git a/resources/Schema/Entities/SpectatorCamera.xml b/resources/Schema/Entities/SpectatorCamera.xml index dbfdecf0..5c3dc514 100644 --- a/resources/Schema/Entities/SpectatorCamera.xml +++ b/resources/Schema/Entities/SpectatorCamera.xml @@ -19,20 +19,199 @@ - + Time to respawn: 0 Fonts/DroidSans.ttf,64 - + - + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + 2 + + + + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + 3 + + + + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + 4 + + + + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + 1 + + + 0.59265931447347009 + + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + + + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + diff --git a/src/Engine/Core/World.cpp b/src/Engine/Core/World.cpp index 9b323ff4..65bc60d2 100644 --- a/src/Engine/Core/World.cpp +++ b/src/Engine/Core/World.cpp @@ -1,6 +1,7 @@ #include "Core/World.h" #include "Core/EEntityDeleted.h" #include "Core/EComponentDeleted.h" +#include "Core/EntityWrapper.h" World::~World() { @@ -151,6 +152,23 @@ std::string World::GetName(EntityID entity) const } } +EntityWrapper World::GetFirstEntityByName(const std::string& name) +{ + auto itPair = GetDirectChildren(EntityID_Invalid); + for (auto it = itPair.first; it != itPair.second; it++) { + EntityID childEntityID = it->second; + EntityWrapper childEntity(this, childEntityID); + if (!childEntity.Valid()) { + continue; + } + EntityWrapper entityWithName = childEntity.Name() == name ? childEntity : childEntity.FirstChildByName(name); + if (entityWithName.Valid()) { + return entityWithName; + } + } + return EntityWrapper::Invalid; +} + EntityID World::generateEntityID() { // TODO: Make EntityID generation smarter diff --git a/src/Game/Systems/PlayerDeathSystem.cpp b/src/Game/Systems/PlayerDeathSystem.cpp index f645abe7..0f05da57 100644 --- a/src/Game/Systems/PlayerDeathSystem.cpp +++ b/src/Game/Systems/PlayerDeathSystem.cpp @@ -74,18 +74,14 @@ bool PlayerDeathSystem::OnEntityDeleted(Events::EntityDeleted& e) if (m_LocalPlayerDeathEffect.ID != e.DeletedEntity) { return false; } - // Set the spectator camera as active, if it exists. - auto pool = m_World->GetComponents("CapturePointGameMode"); - if (pool == nullptr || pool->size() == 0) { - return false; - } - ComponentWrapper modeComponent = *pool->begin(); - EntityWrapper theLevel = EntityWrapper(m_LocalPlayerDeathEffect.World, modeComponent.EntityID); - EntityWrapper spectatorCam = theLevel.FirstChildByName("SpectatorCamera"); - if (!spectatorCam.Valid() && spectatorCam.HasComponent("Camera")) { + + // Look for the spectator camera entity in the level. + EntityWrapper spectatorCam = m_World->GetFirstEntityByName("SpectatorCamera"); + if (!spectatorCam.Valid() || !spectatorCam.HasComponent("Camera") || LocalPlayer.Valid()) { return false; } Events::SetCamera eSetCamera; eSetCamera.CameraEntity = spectatorCam; m_EventBroker->Publish(eSetCamera); + return true; } diff --git a/src/Game/Systems/PlayerSpawnSystem.cpp b/src/Game/Systems/PlayerSpawnSystem.cpp index 2f6928af..b2bb1ecf 100644 --- a/src/Game/Systems/PlayerSpawnSystem.cpp +++ b/src/Game/Systems/PlayerSpawnSystem.cpp @@ -27,8 +27,7 @@ void PlayerSpawnSystem::Update(double dt) double& timer = (double&)modeComponent["RespawnTime"]; timer += dt; double maxRespawnTime = m_DbgConfigForceRespawn ? m_ForcedRespawnTime : (double)modeComponent["MaxRespawnTime"]; - EntityWrapper theLevel = EntityWrapper(m_World, modeComponent.EntityID); - EntityWrapper spectatorCam = theLevel.FirstChildByName("SpectatorCamera"); + EntityWrapper spectatorCam = m_World->GetFirstEntityByName("SpectatorCamera"); if (spectatorCam.Valid()) { EntityWrapper HUD = spectatorCam.FirstChildByName("SpectatorHUD"); if (HUD.Valid()) { @@ -66,7 +65,14 @@ void PlayerSpawnSystem::Update(double dt) // If the spawner has a team affiliation, check it if (spawner.HasComponent("Team")) { - if ((int)spawner["Team"]["Team"] != req.Team) { + auto cSpawnerTeam = spawner["Team"]; + if ((int)cSpawnerTeam["Team"] != req.Team) { + // Increase num spawned players if someone picks spectator, since it is valid to pick spectator + // but don't spawn anything, goto next spawnrequest. + if (req.Team == (int)cSpawnerTeam["Team"].Enum("Spectator")) { + ++numSpawnedPlayers; + break; + } continue; } } @@ -87,9 +93,9 @@ void PlayerSpawnSystem::Update(double dt) } } if (numSpawnedPlayers != (int)m_SpawnRequests.size()) { - LOG_DEBUG("%i players were supposed to be spawned, but %i was spawned.", (int)m_SpawnRequests.size(), numSpawnedPlayers); + LOG_DEBUG("%i players were supposed to be spawned or set as spectator, but only %i was handled.", (int)m_SpawnRequests.size(), numSpawnedPlayers); } else { - LOG_DEBUG("%i players were spawned.", numSpawnedPlayers); + LOG_DEBUG("%i players were spawned or set as spectator.", numSpawnedPlayers); } m_SpawnRequests.clear(); } @@ -100,24 +106,29 @@ bool PlayerSpawnSystem::OnInputCommand(Events::InputCommand& e) return false; } + if (e.Value == 0) { + return false; + } + + // A dead client should be able to swap to the spectator camera. + if (IsClient && !LocalPlayer.Valid()) { + // Set the spectator camera as active, if it exists. + // Find the camera. + EntityWrapper spectatorCam = m_World->GetFirstEntityByName("SpectatorCamera"); + if (spectatorCam.Valid() && spectatorCam.HasComponent("Camera")) { + Events::SetCamera eSetCamera; + eSetCamera.CameraEntity = spectatorCam; + m_EventBroker->Publish(eSetCamera); + } + } + // Team picks should be processed ONLY server-side! // Don't make a spawn request if we're the client. if (!IsServer && m_NetworkEnabled) { return false; } - if (e.Value == 0) { - return false; - } - - //TODO: Spectating? - //Right now, return if someone picks spectator. - //1 signifies spectator here, could not get Playerteam component since it may be invalid or without team comp. - if ((ComponentInfo::EnumType)e.Value == 1) { - return false; - } - - //Check if the player already requested spawn. + // Check if the player already requested spawn. auto iter = m_SpawnRequests.begin(); for (; iter != m_SpawnRequests.end(); ++iter) { if (iter->PlayerID == e.PlayerID) { @@ -126,11 +137,11 @@ bool PlayerSpawnSystem::OnInputCommand(Events::InputCommand& e) } if (iter != m_SpawnRequests.end()) { - //If player is in queue to spawn, then change their team affiliation in the request. + // If player is in queue to spawn, then change their team affiliation in the request. iter->Team = (ComponentInfo::EnumType)e.Value; } else if (m_PlayerEntities.count(e.PlayerID) == 0 || !m_PlayerEntities[e.PlayerID].Valid()) { - //If player is not in queue to spawn, then create a spawn request, - //but only if they are spectating and/or just connected. + // If player is not in queue to spawn, then create a spawn request, + // but only if they are spectating and/or just connected. SpawnRequest req; req.PlayerID = e.PlayerID; req.Team = (ComponentInfo::EnumType)e.Value; From ab7fd8954675185fc26ee176bf9ea0102c7b1d06 Mon Sep 17 00:00:00 2001 From: Tleety Date: Wed, 2 Mar 2016 13:56:35 +0100 Subject: [PATCH 072/130] Should now correctly track if another player takes your last capture point --- include/Engine/Core/ECaptured.h | 3 +- .../Schema/Entities/NewMap2version3NEW.xml | 75 +++++++++---------- .../Systems/CapturePointArrowHUDSystem.cpp | 42 ++++------- src/Game/Systems/CapturePointSystem.cpp | 5 +- 4 files changed, 57 insertions(+), 68 deletions(-) diff --git a/include/Engine/Core/ECaptured.h b/include/Engine/Core/ECaptured.h index 48771cd7..047c5d7d 100644 --- a/include/Engine/Core/ECaptured.h +++ b/include/Engine/Core/ECaptured.h @@ -13,7 +13,8 @@ struct Captured : Event { int TeamNumberThatCapturedCapturePoint; EntityID CapturePointTakenID; - EntityWrapper NextCapturePoint; + EntityWrapper BlueTeamNextCapturePoint; + EntityWrapper RedTeamNextCapturePoint; }; } diff --git a/resources/Schema/Entities/NewMap2version3NEW.xml b/resources/Schema/Entities/NewMap2version3NEW.xml index d24675cd..5b224de3 100644 --- a/resources/Schema/Entities/NewMap2version3NEW.xml +++ b/resources/Schema/Entities/NewMap2version3NEW.xml @@ -810,6 +810,7 @@ + 8 @@ -820,9 +821,8 @@ - + - @@ -852,6 +852,7 @@ + 8 @@ -862,9 +863,8 @@ - + - @@ -894,6 +894,7 @@ + 8 @@ -904,9 +905,8 @@ - + - @@ -936,6 +936,7 @@ + 8 @@ -946,9 +947,8 @@ - + - @@ -978,6 +978,7 @@ + 8 @@ -988,9 +989,8 @@ - + - @@ -1020,6 +1020,7 @@ + 8 @@ -1030,9 +1031,8 @@ - + - @@ -1062,6 +1062,7 @@ + 8 @@ -1072,9 +1073,8 @@ - + - @@ -2326,6 +2326,7 @@ + 8 @@ -2336,9 +2337,8 @@ - + - @@ -2368,6 +2368,7 @@ + 8 @@ -2378,9 +2379,8 @@ - + - @@ -2865,6 +2865,7 @@ + 8 @@ -2875,9 +2876,8 @@ - + - @@ -2907,6 +2907,7 @@ + 8 @@ -2917,9 +2918,8 @@ - + - @@ -2949,6 +2949,7 @@ + 8 @@ -2959,9 +2960,8 @@ - + - @@ -2991,6 +2991,7 @@ + 8 @@ -3001,9 +3002,8 @@ - + - @@ -3033,6 +3033,7 @@ + 8 @@ -3043,9 +3044,8 @@ - + - @@ -3075,6 +3075,7 @@ + 8 @@ -3085,9 +3086,8 @@ - + - @@ -3117,6 +3117,7 @@ + 8 @@ -3127,9 +3128,8 @@ - + - @@ -4225,6 +4225,7 @@ -15 4 + Models/Core/UnitCylinder.mesh @@ -4239,7 +4240,6 @@ - @@ -4261,6 +4261,7 @@ 3 + Models/Core/UnitCylinder.mesh @@ -4271,7 +4272,6 @@ - @@ -4293,6 +4293,7 @@ 2 + Models/Core/UnitCylinder.mesh @@ -4303,7 +4304,6 @@ - @@ -4325,6 +4325,7 @@ 1 + Models/Core/UnitCylinder.mesh @@ -4335,7 +4336,6 @@ - @@ -4360,6 +4360,7 @@ 15 + Models/Core/UnitCylinder.mesh @@ -4374,7 +4375,6 @@ - @@ -4445,7 +4445,6 @@ 1 - false diff --git a/src/Game/Systems/CapturePointArrowHUDSystem.cpp b/src/Game/Systems/CapturePointArrowHUDSystem.cpp index bf6951a2..9e327a43 100644 --- a/src/Game/Systems/CapturePointArrowHUDSystem.cpp +++ b/src/Game/Systems/CapturePointArrowHUDSystem.cpp @@ -11,9 +11,9 @@ CapturePointArrowHUDSystem::CapturePointArrowHUDSystem(SystemParams params) void CapturePointArrowHUDSystem::Update(double dt) { bool loadCheck = true; - int redTeam; - int blueTeam; - int spectatorTeam; + int redTeamEnum; + int blueTeamEnum; + int spectatorTeamEnum; //Get list for all CapturePointArrowHUDComponents auto arrowHUDs = m_World->GetComponents("CapturePointArrowHUD"); @@ -35,9 +35,9 @@ void CapturePointArrowHUDSystem::Update(double dt) int currentTeam = (int)cTeam["Team"]; if (loadCheck) { - redTeam = (int)cTeam["Team"].Enum("Red"); - blueTeam = (int)cTeam["Team"].Enum("Blue"); - spectatorTeam = (int)cTeam["Team"].Enum("Spectator"); + redTeamEnum = (int)cTeam["Team"].Enum("Red"); + blueTeamEnum = (int)cTeam["Team"].Enum("Blue"); + spectatorTeamEnum = (int)cTeam["Team"].Enum("Spectator"); loadCheck = false; @@ -66,21 +66,21 @@ void CapturePointArrowHUDSystem::Update(double dt) int currentOwner = (int)capturePointEntity["Team"]["Team"]; - if(currentOwner != redTeam) { + if(currentOwner != redTeamEnum) { //This capturePoint is not owned by the red team and is therefor an eligible target for red team glm::vec3 targetPos = Transform::AbsolutePosition(capturePointEntity); redTargets.insert(std::pair(capturePointID, targetPos)); } - if(currentOwner != blueTeam) { + if(currentOwner != blueTeamEnum) { //This capturePoint is not owned by the blue team and is therefor an eligible target for blue team glm::vec3 targetPos = Transform::AbsolutePosition(capturePointEntity); blueTargets.insert(std::pair(capturePointID, targetPos)); } - if(homePointTeam == blueTeam) { + if(homePointTeam == blueTeamEnum) { //CP is the home point for blue team. homeBlue = capturePointEntity; - } else if (homePointTeam == redTeam) { + } else if (homePointTeam == redTeamEnum) { //CP is the home point for red team. homeRed = capturePointEntity; } @@ -149,14 +149,12 @@ void CapturePointArrowHUDSystem::Update(double dt) //Untill this is awailable we will just use the hardcoded value in the component. //This will also give us a position, so we wont need to loop through all capturePoints. glm::vec3 pos; - if(currentTeam == redTeam) { + if(currentTeam == redTeamEnum) { pos = m_RedTeamCurrentTarget; - } else if (currentTeam == blueTeam) { + } else if (currentTeam == blueTeamEnum) { pos = m_BlueTeamCurrentTarget; } - //pos = currentTeam == redTeam ? m_RedTeamCurrentTarget : currentTeam == blueTeam ? m_BlueTeamCurrentTarget : glm::vec3(0.f); - glm::vec3& arrowOri = arrowEntity["Transform"]["Orientation"]; glm::vec3 lookVector = glm::normalize(Transform::AbsolutePosition(arrowEntity) - pos); //Maybe should be player instead float pitch = std::asin(-lookVector.y); @@ -173,21 +171,13 @@ void CapturePointArrowHUDSystem::Update(double dt) bool CapturePointArrowHUDSystem::OnCapturePointCaptured(Events::Captured& e) { - if (!e.NextCapturePoint.HasComponent("Team")) { + if(!e.BlueTeamNextCapturePoint.Valid() || !e.RedTeamNextCapturePoint.Valid()) { return 0; } - auto cTeam = e.NextCapturePoint["Team"]; - - int redTeam = (int)cTeam["Team"].Enum("Red"); - int blueTeam = (int)cTeam["Team"].Enum("Blue"); - int spectatorTeam = (int)cTeam["Team"].Enum("Spectator"); - - if(e.TeamNumberThatCapturedCapturePoint == redTeam) { - m_RedTeamCurrentTarget = Transform::AbsolutePosition(e.NextCapturePoint); - } else if (e.TeamNumberThatCapturedCapturePoint == blueTeam) { - m_BlueTeamCurrentTarget = Transform::AbsolutePosition(e.NextCapturePoint); - } + m_RedTeamCurrentTarget = Transform::AbsolutePosition(e.RedTeamNextCapturePoint); + m_BlueTeamCurrentTarget = Transform::AbsolutePosition(e.BlueTeamNextCapturePoint); m_InitialtargetsSet = true; + return 0; } diff --git a/src/Game/Systems/CapturePointSystem.cpp b/src/Game/Systems/CapturePointSystem.cpp index 6cbb1b2f..0ff294b9 100644 --- a/src/Game/Systems/CapturePointSystem.cpp +++ b/src/Game/Systems/CapturePointSystem.cpp @@ -104,9 +104,8 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp } if (m_RecentlyCapturedNeedNextCapturePointNow) { //TODO: Next capture point for both teams - m_CapturedEvent.NextCapturePoint = m_CapturedEvent.TeamNumberThatCapturedCapturePoint == blueTeam ? - m_CapturePointNumberToEntityMap[nextPossibleCapturePoint["Blue"]] : - m_CapturePointNumberToEntityMap[nextPossibleCapturePoint["Red"]]; + m_CapturedEvent.BlueTeamNextCapturePoint = m_CapturePointNumberToEntityMap[nextPossibleCapturePoint["Blue"]]; + m_CapturedEvent.RedTeamNextCapturePoint = m_CapturePointNumberToEntityMap[nextPossibleCapturePoint["Red"]]; m_EventBroker->Publish(m_CapturedEvent); m_RecentlyCapturedNeedNextCapturePointNow = false; } From 1217b25d023ea78571744d3371dd1b2f5ce8ad1c Mon Sep 17 00:00:00 2001 From: stiffly Date: Wed, 2 Mar 2016 14:15:20 +0100 Subject: [PATCH 073/130] DashEffect will now spawn a player model behind the player that will fade out . --- .../Engine/Input/FirstPersonInputController.h | 5 +++- include/Game/Systems/PlayerMovementSystem.h | 2 ++ resources/Schema/Entities/DashEffect.xml | 18 ++++++++++++++ src/Game/Systems/PlayerMovementSystem.cpp | 24 ++++++++++++++++++- 4 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 resources/Schema/Entities/DashEffect.xml diff --git a/include/Engine/Input/FirstPersonInputController.h b/include/Engine/Input/FirstPersonInputController.h index d86af088..f28e4112 100644 --- a/include/Engine/Input/FirstPersonInputController.h +++ b/include/Engine/Input/FirstPersonInputController.h @@ -51,10 +51,11 @@ protected: bool m_ShiftDashing = false; bool m_ValidDoubleTap = false; - //specialabilitys + //specialabilities bool m_MovementKeyDown = false; bool m_SpecialAbilityKeyDown = false; int m_NumberOfMovementKeysDown = 0; + void spawnDashEffect(); EventRelay m_ELockMouse; bool OnLockMouse(const Events::LockMouse& e); @@ -207,6 +208,8 @@ void FirstPersonInputController::AssaultDashCheck(double dt, bool assaultDashCoolDownTimer = assaultDashCoolDownMaxTimer; m_AssaultDashDoubleTapped = true; m_AssaultDashDoubleTapDeltaTime = 0.f; + Events::DashAbility e; + m_EventBroker->Publish(e); return; } diff --git a/include/Game/Systems/PlayerMovementSystem.h b/include/Game/Systems/PlayerMovementSystem.h index 92aa1915..cdf8ee22 100644 --- a/include/Game/Systems/PlayerMovementSystem.h +++ b/include/Game/Systems/PlayerMovementSystem.h @@ -41,6 +41,8 @@ private: bool OnPlayerSpawned(Events::PlayerSpawned& e); EventRelay m_EDoubleJump; bool PlayerMovementSystem::OnDoubleJump(Events::DoubleJump & e); + EventRelay m_EDashAbility; + bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e); void updateMovementControllers(double dt); void updateVelocity(EntityWrapper player, double dt); diff --git a/resources/Schema/Entities/DashEffect.xml b/resources/Schema/Entities/DashEffect.xml new file mode 100644 index 00000000..b6bd53f7 --- /dev/null +++ b/resources/Schema/Entities/DashEffect.xml @@ -0,0 +1,18 @@ + + + + + + + 1 + + + + 0 + 1 + + + + + + diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index 47612ca0..4925baa7 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -5,6 +5,7 @@ PlayerMovementSystem::PlayerMovementSystem(SystemParams params) { EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &PlayerMovementSystem::OnPlayerSpawned); EVENT_SUBSCRIBE_MEMBER(m_EDoubleJump, &PlayerMovementSystem::OnDoubleJump); + EVENT_SUBSCRIBE_MEMBER(m_EDashAbility, &PlayerMovementSystem::OnDashAbility); } PlayerMovementSystem::~PlayerMovementSystem() @@ -322,4 +323,25 @@ void PlayerMovementSystem::spawnHexagon(EntityWrapper target) EntityID hexagonEffectID = parser.MergeEntities(m_World); EntityWrapper hexagonEW = EntityWrapper(m_World, hexagonEffectID); hexagonEW["Transform"]["Position"] = (glm::vec3)target["Transform"]["Position"]; -} \ No newline at end of file +} + +bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e) +{ + auto dashEffectResource = ResourceManager::Load("Schema/Entities/DashEffect.xml"); + EntityFileParser parser(dashEffectResource); + EntityID dashEffectID = parser.MergeEntities(m_World); + EntityWrapper dashEffect(m_World, dashEffectID); + auto playerModel = LocalPlayer.FirstChildByName("PlayerModel"); + auto playerEntityModel = playerModel["Model"]; + auto playerEntityAnimation = playerModel["Animation"]; + playerEntityModel.Copy(dashEffect["Model"]); + playerEntityAnimation.Copy(dashEffect["Animation"]); + dashEffect["ExplosionEffect"]["EndColor"] = (glm::vec4)playerEntityModel["Color"]; + ((glm::vec4&)dashEffect["ExplosionEffect"]["EndColor"]).w = 0.f; + dashEffect["Animation"]["Speed1"] = 0.0; + dashEffect["Animation"]["Speed2"] = 0.0; + dashEffect["Animation"]["Speed3"] = 0.0; + dashEffect["Transform"]["Position"] = (glm::vec3)LocalPlayer["Transform"]["Position"]; + dashEffect["Transform"]["Orientation"] = (glm::vec3)LocalPlayer["Transform"]["Orientation"]; + return true; +} From 95078b6a4b8e91ce381eb4b0b22b3d62a835dcce Mon Sep 17 00:00:00 2001 From: William Moberg Date: Wed, 2 Mar 2016 14:37:33 +0100 Subject: [PATCH 074/130] Fix so client doesn't override the servers respawn time with its config file. Server or single player client can still override the component with the config RespawnTime. --- resources/DefaultConfig.ini | 2 +- src/Game/Systems/PlayerSpawnSystem.cpp | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/resources/DefaultConfig.ini b/resources/DefaultConfig.ini index e99e3437..8917e3e1 100644 --- a/resources/DefaultConfig.ini +++ b/resources/DefaultConfig.ini @@ -4,7 +4,7 @@ LoadMap= ; if true -> Pool allocation is not used when calling Allocate/Free, just use regular dynamic allocation. ; if false -> Use pool allocation. DisableMemoryPool=false -RespawnTime = 8.0 +RespawnTime = -1.0 EditorEnabled=false OutOfBodyExperience=false diff --git a/src/Game/Systems/PlayerSpawnSystem.cpp b/src/Game/Systems/PlayerSpawnSystem.cpp index b2bb1ecf..6c41ddd4 100644 --- a/src/Game/Systems/PlayerSpawnSystem.cpp +++ b/src/Game/Systems/PlayerSpawnSystem.cpp @@ -10,7 +10,7 @@ PlayerSpawnSystem::PlayerSpawnSystem(SystemParams params) ConfigFile* config = ResourceManager::Load("Config.ini"); m_NetworkEnabled = config->Get("Networking.StartNetwork", false); m_ForcedRespawnTime = config->Get("Debug.RespawnTime", -1.0f); - m_DbgConfigForceRespawn = m_ForcedRespawnTime > 0; + m_DbgConfigForceRespawn = m_ForcedRespawnTime > 0 && IsServer; } void PlayerSpawnSystem::Update(double dt) @@ -26,7 +26,10 @@ void PlayerSpawnSystem::Update(double dt) // Increase timer. double& timer = (double&)modeComponent["RespawnTime"]; timer += dt; - double maxRespawnTime = m_DbgConfigForceRespawn ? m_ForcedRespawnTime : (double)modeComponent["MaxRespawnTime"]; + if (m_DbgConfigForceRespawn) { + (double&)modeComponent["MaxRespawnTime"] = m_ForcedRespawnTime; + } + double maxRespawnTime = (double)modeComponent["MaxRespawnTime"]; EntityWrapper spectatorCam = m_World->GetFirstEntityByName("SpectatorCamera"); if (spectatorCam.Valid()) { EntityWrapper HUD = spectatorCam.FirstChildByName("SpectatorHUD"); From cdbc348cfae65804caf5c4e5707423e7f23b3400 Mon Sep 17 00:00:00 2001 From: Tleety Date: Wed, 2 Mar 2016 14:46:37 +0100 Subject: [PATCH 075/130] AbilityCooldownHUD should now correctly track cooldown for dash ability. --- .../Schema/Components/AbilityCooldownHUD.xsd | 2 +- resources/Schema/Entities/Player.xml | 39 ++++++++++++++++++- src/Game/Systems/AbilityCooldownHUDSystem.cpp | 8 ++-- 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/resources/Schema/Components/AbilityCooldownHUD.xsd b/resources/Schema/Components/AbilityCooldownHUD.xsd index 066a9442..5bfb01a8 100644 --- a/resources/Schema/Components/AbilityCooldownHUD.xsd +++ b/resources/Schema/Components/AbilityCooldownHUD.xsd @@ -3,7 +3,7 @@ - HUD element for tracking ability cooldown + HUD element for tracking ability cooldown. If it has a sprite and fill component it will fill the sprite with chosen color depending on the cooldown.\n A child with text component named "Cooldown" \ No newline at end of file diff --git a/resources/Schema/Entities/Player.xml b/resources/Schema/Entities/Player.xml index 28ace561..91b25bcb 100644 --- a/resources/Schema/Entities/Player.xml +++ b/resources/Schema/Entities/Player.xml @@ -12,6 +12,7 @@ + 52.867678870419283 @@ -122,6 +123,7 @@ Textures/HealthHUD3.png + false @@ -132,7 +134,42 @@ - + + + + + + + + + Textures/Core/White.png + false + + + + + + + + + + + + + 0.0 + Fonts/DroidSans.ttf,64 + + + + + + + + + + + + diff --git a/src/Game/Systems/AbilityCooldownHUDSystem.cpp b/src/Game/Systems/AbilityCooldownHUDSystem.cpp index 12d268c7..44180a62 100644 --- a/src/Game/Systems/AbilityCooldownHUDSystem.cpp +++ b/src/Game/Systems/AbilityCooldownHUDSystem.cpp @@ -17,10 +17,12 @@ void AbilityCooldownHUDSystem::Update(double dt) if(cooldownTextEntity.Valid()) { if(cooldownTextEntity.HasComponent("Text")) { - double abilityCD = (double)abilityEntity["DashAbility"]["CoolDownMaxTimer"]; - std::string t = (std::string&)cooldownTextEntity["Text"]["Content"] = std::to_string(abilityCD).substr(0, 3); + double maxAbilityCD = (double)abilityEntity["DashAbility"]["CoolDownMaxTimer"]; + double currentAbilityCD = (double)abilityEntity["DashAbility"]["CoolDownTimer"]; + currentAbilityCD = currentAbilityCD >= 0.0 ? currentAbilityCD : 0.0; + std::string t = (std::string&)cooldownTextEntity["Text"]["Content"] = std::to_string(currentAbilityCD).substr(0, 3); if(entity.HasComponent("Fill")) { - entity["Fill"]["Percentage"] = abilityCD/abilityCD; //TODO: current time needs to be in the component. + entity["Fill"]["Percentage"] = currentAbilityCD/maxAbilityCD; //TODO: current time needs to be in the component. } } } From 9161c11764bf0049e5f6adf27d3a10416c8f6d36 Mon Sep 17 00:00:00 2001 From: Jocke Date: Wed, 2 Mar 2016 15:31:42 +0100 Subject: [PATCH 076/130] Changed m_ETriggerTouchVector for-loop so it wont break when an item triggers the condition. This is done to update all somePickup.DecreaseThisRespawnTimer's. --- src/Game/Systems/AmmoPickupSystem.cpp | 9 ++++++--- src/Game/Systems/PickupSpawnSystem.cpp | 18 +++++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/Game/Systems/AmmoPickupSystem.cpp b/src/Game/Systems/AmmoPickupSystem.cpp index 6a24ee95..74d86f70 100644 --- a/src/Game/Systems/AmmoPickupSystem.cpp +++ b/src/Game/Systems/AmmoPickupSystem.cpp @@ -15,7 +15,8 @@ AmmoPickupSystem::AmmoPickupSystem(SystemParams params) void AmmoPickupSystem::Update(double dt) { if (IsServer) { - for (auto it = m_ETriggerTouchVector.begin(); it != m_ETriggerTouchVector.end(); ++it) { + auto it = m_ETriggerTouchVector.begin(); + while (it != m_ETriggerTouchVector.end()) { auto& somePickup = *it; somePickup.DecreaseThisRespawnTimer -= dt; if (somePickup.DecreaseThisRespawnTimer < 0.0) { @@ -36,8 +37,10 @@ void AmmoPickupSystem::Update(double dt) m_World->SetParent(newAmmoPickupEntity.ID, somePickup.parentID); //erase the current element (somePickup) - m_ETriggerTouchVector.erase(it); - break; + it = m_ETriggerTouchVector.erase(it); + } + else { + it++; } } //still touching m_PickupAtMaximum? diff --git a/src/Game/Systems/PickupSpawnSystem.cpp b/src/Game/Systems/PickupSpawnSystem.cpp index 6bfd2ee6..79e7d66b 100644 --- a/src/Game/Systems/PickupSpawnSystem.cpp +++ b/src/Game/Systems/PickupSpawnSystem.cpp @@ -12,7 +12,8 @@ PickupSpawnSystem::PickupSpawnSystem(SystemParams params) void PickupSpawnSystem::Update(double dt) { if (IsServer) { - for (auto it = m_ETriggerTouchVector.begin(); it != m_ETriggerTouchVector.end(); ++it) { + auto it = m_ETriggerTouchVector.begin(); + while (it != m_ETriggerTouchVector.end()) { auto& somePickup = *it; somePickup.DecreaseThisRespawnTimer -= dt; if (somePickup.DecreaseThisRespawnTimer < 0.0) { @@ -34,8 +35,9 @@ void PickupSpawnSystem::Update(double dt) m_World->SetParent(newHealthPickupEntity.ID, somePickup.parentID); //erase the current element (somePickup) - m_ETriggerTouchVector.erase(it); - break; + it = m_ETriggerTouchVector.erase(it); + } else { + it++; } } //still touching PickupAtMaximum? @@ -66,7 +68,8 @@ bool PickupSpawnSystem::OnTriggerTouch(Events::TriggerTouch& e) DoPickup(e.Entity, e.Trigger); return true; } -bool PickupSpawnSystem::OnTriggerLeave(Events::TriggerLeave& e) { +bool PickupSpawnSystem::OnTriggerLeave(Events::TriggerLeave& e) +{ if (!e.Trigger.HasComponent("HealthPickup")) { return false; } @@ -79,7 +82,8 @@ bool PickupSpawnSystem::OnTriggerLeave(Events::TriggerLeave& e) { } return true; } -void PickupSpawnSystem::DoPickup(EntityWrapper &player, EntityWrapper &trigger) { +void PickupSpawnSystem::DoPickup(EntityWrapper &player, EntityWrapper &trigger) +{ double healthGiven = 0.01*(double)trigger["HealthPickup"]["HealthGain"] * (double)player["Health"]["MaxHealth"]; //only the server will increase the players hp and set it in the next delta @@ -90,8 +94,8 @@ void PickupSpawnSystem::DoPickup(EntityWrapper &player, EntityWrapper &trigger) //copy position, healthgain, respawntimer (twice since one of the values will be counted down to 0, the other will be set in the new object) //we need to copy all values since each value can be different for each healthPickup - m_ETriggerTouchVector.push_back({ (glm::vec3)trigger["Transform"]["Position"] ,trigger["HealthPickup"]["HealthGain"], - trigger["HealthPickup"]["RespawnTimer"],trigger["HealthPickup"]["RespawnTimer"], m_World->GetParent(trigger.ID) }); + m_ETriggerTouchVector.push_back({ (glm::vec3)trigger["Transform"]["Position"], trigger["HealthPickup"]["HealthGain"], + trigger["HealthPickup"]["RespawnTimer"], trigger["HealthPickup"]["RespawnTimer"], m_World->GetParent(trigger.ID) }); //delete the healthpickup m_World->DeleteEntity(trigger.ID); From dc10661e6b8eb1ce0b69fceb5d80b9ced0d8b346 Mon Sep 17 00:00:00 2001 From: William Moberg Date: Wed, 2 Mar 2016 16:45:43 +0100 Subject: [PATCH 077/130] Respawn time now only displays numbers, centered below CPHUD. --- resources/Schema/Entities/NewMapWSpectatorCam.xml | 7 ++----- src/Game/Systems/PlayerSpawnSystem.cpp | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/resources/Schema/Entities/NewMapWSpectatorCam.xml b/resources/Schema/Entities/NewMapWSpectatorCam.xml index 5e8b6bc2..bf1b4c2b 100644 --- a/resources/Schema/Entities/NewMapWSpectatorCam.xml +++ b/resources/Schema/Entities/NewMapWSpectatorCam.xml @@ -3,7 +3,7 @@ - 3.6027407165331624 + 0.0 15 @@ -5336,12 +5336,9 @@ Fonts/DroidSans.ttf,64 - - - - + diff --git a/src/Game/Systems/PlayerSpawnSystem.cpp b/src/Game/Systems/PlayerSpawnSystem.cpp index 6c41ddd4..fbda849d 100644 --- a/src/Game/Systems/PlayerSpawnSystem.cpp +++ b/src/Game/Systems/PlayerSpawnSystem.cpp @@ -37,7 +37,7 @@ void PlayerSpawnSystem::Update(double dt) EntityWrapper respawnTimer = spectatorCam.FirstChildByName("RespawnTimer"); if (respawnTimer.Valid()) { //Update respawn time in the HUD element. - respawnTimer["Text"]["Content"] = "Time to respawn: " + std::to_string(1 + (int)(maxRespawnTime - timer)); + respawnTimer["Text"]["Content"] = std::to_string(1 + (int)(maxRespawnTime - timer)); } } } From 78835f95d8bcb57e1818491ebcf780adb1d29fc0 Mon Sep 17 00:00:00 2001 From: Tleety Date: Wed, 2 Mar 2016 16:47:30 +0100 Subject: [PATCH 078/130] Removed comment --- src/Game/Systems/CapturePointSystem.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Game/Systems/CapturePointSystem.cpp b/src/Game/Systems/CapturePointSystem.cpp index 0ff294b9..0d6089c5 100644 --- a/src/Game/Systems/CapturePointSystem.cpp +++ b/src/Game/Systems/CapturePointSystem.cpp @@ -103,7 +103,6 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp } } if (m_RecentlyCapturedNeedNextCapturePointNow) { - //TODO: Next capture point for both teams m_CapturedEvent.BlueTeamNextCapturePoint = m_CapturePointNumberToEntityMap[nextPossibleCapturePoint["Blue"]]; m_CapturedEvent.RedTeamNextCapturePoint = m_CapturePointNumberToEntityMap[nextPossibleCapturePoint["Red"]]; m_EventBroker->Publish(m_CapturedEvent); From a5c086e3899c6b54520408aa860f318470878296 Mon Sep 17 00:00:00 2001 From: stiffly Date: Wed, 2 Mar 2016 16:48:38 +0100 Subject: [PATCH 079/130] Dash effect now working over network, by sending events. Similar to jump effect. --- .../Engine/Input/FirstPersonInputController.h | 14 ++++++-- include/Engine/Network/Client.h | 5 +++ include/Engine/Network/MessageType.h | 1 + include/Engine/Network/Server.h | 1 + include/Game/Events/EDashAbility.h | 6 +++- resources/Schema/Entities/DashEffect.xml | 6 ++-- src/Engine/Network/Client.cpp | 36 +++++++++++++++++-- src/Engine/Network/Server.cpp | 10 +++++- src/Game/Systems/PlayerMovementSystem.cpp | 19 ++++++---- 9 files changed, 81 insertions(+), 17 deletions(-) diff --git a/include/Engine/Input/FirstPersonInputController.h b/include/Engine/Input/FirstPersonInputController.h index f28e4112..efa3c38e 100644 --- a/include/Engine/Input/FirstPersonInputController.h +++ b/include/Engine/Input/FirstPersonInputController.h @@ -27,7 +27,7 @@ public: virtual bool OnCommand(const Events::InputCommand& e) override; virtual void Reset(); - void AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer, double& assaultDashCoolDownTimer); + void AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer, double& assaultDashCoolDownTimer, EntityWrapper player); virtual bool AssaultDashDoubleTapped() const { return m_AssaultDashDoubleTapped; } virtual bool PlayerIsDashing() const { return m_PlayerIsDashing; } @@ -41,6 +41,7 @@ protected: bool m_Crouching = false; //assault dash membervariables - needed to calculate the doubletap- and dashlogic double m_AssaultDashDoubleTapDeltaTime = 0.0; + double m_DashEffectResetTimer = 0.0; //i will let m_AssaultDashDoubleTapSensitivityTimer stay hardcoded, its not really a gamevariable (more an inputvariable), //and its very unlikely that someone wants to change that value const float m_AssaultDashDoubleTapSensitivityTimer = 0.25f; @@ -191,12 +192,19 @@ bool FirstPersonInputController::OnLockMouse(const Events::LockMou } template -void FirstPersonInputController::AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer, double& assaultDashCoolDownTimer) { +void FirstPersonInputController::AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer, double& assaultDashCoolDownTimer, EntityWrapper player) { m_AssaultDashDoubleTapDeltaTime += dt; + m_DashEffectResetTimer += dt; assaultDashCoolDownTimer -= dt; //cooldown = assaultDashCoolDownMaxTimer sec, pretend the dash lasts 0.25 sec (for friction to do its work) if (assaultDashCoolDownTimer > (assaultDashCoolDownMaxTimer - 0.25f)) { m_PlayerIsDashing = true; + if (m_DashEffectResetTimer > 0.05) { + Events::DashAbility e; + e.Player = player.ID; + m_EventBroker->Publish(e); + m_DashEffectResetTimer = 0.0; + } } else { m_PlayerIsDashing = false; } @@ -209,6 +217,7 @@ void FirstPersonInputController::AssaultDashCheck(double dt, bool m_AssaultDashDoubleTapped = true; m_AssaultDashDoubleTapDeltaTime = 0.f; Events::DashAbility e; + e.Player = player.ID; m_EventBroker->Publish(e); return; } @@ -240,6 +249,7 @@ void FirstPersonInputController::AssaultDashCheck(double dt, bool assaultDashCoolDownTimer = assaultDashCoolDownMaxTimer; Events::DashAbility e; + e.Player = player.ID; m_EventBroker->Publish(e); } diff --git a/include/Engine/Network/Client.h b/include/Engine/Network/Client.h index c407f7f8..4ee071d2 100644 --- a/include/Engine/Network/Client.h +++ b/include/Engine/Network/Client.h @@ -28,6 +28,7 @@ #include "Core/EPlayerSpawned.h" #include "Core/EAmmoPickup.h" #include "Network/ESearchForServers.h" +#include "../Game/Events/EDashAbility.h" struct ServerInfo { @@ -107,6 +108,7 @@ private: void parsePlayerDamage(Packet& packet); void parseComponentDeletion(Packet& packet); void parseDoubleJump(Packet& packet); + void parseDashEffect(Packet& packet); void parseAmmoPickup(Packet& packet); void InterpolateFields(Packet& packet, const ComponentInfo & componentInfo, const EntityID & entityID, const std::string & componentType); void parseSnapshot(Packet& packet); @@ -135,6 +137,9 @@ private: EventRelay< Client, Events::SearchForServers> m_ESearchForServers; EventRelay m_EDoubleJump; bool OnDoubleJump(Events::DoubleJump & e); + EventRelay m_EDashAbility; + bool OnDashAbility(const Events::DashAbility& e); + bool OnSearchForServers(const Events::SearchForServers& e); UDPClient m_ServerlistRequest; std::vector m_Serverlist; diff --git a/include/Engine/Network/MessageType.h b/include/Engine/Network/MessageType.h index bf773618..c34f584e 100644 --- a/include/Engine/Network/MessageType.h +++ b/include/Engine/Network/MessageType.h @@ -20,6 +20,7 @@ enum class MessageType ComponentDeleted, PlayerTransform, OnDoubleJump, + OnDashEffect, ServerlistRequest, AmmoPickup, Invalid diff --git a/include/Engine/Network/Server.h b/include/Engine/Network/Server.h index 3c956ed9..7bcefc65 100644 --- a/include/Engine/Network/Server.h +++ b/include/Engine/Network/Server.h @@ -83,6 +83,7 @@ private: void parseClientPing(); void parsePing(); bool parseDoubleJump(Packet& packet); + void parseDashEffect(Packet& packet); void parseUDPConnect(Packet& packet); void parseTCPConnect(Packet& packet); void parseDisconnect(); diff --git a/include/Game/Events/EDashAbility.h b/include/Game/Events/EDashAbility.h index 62a2b935..c5078fab 100644 --- a/include/Game/Events/EDashAbility.h +++ b/include/Game/Events/EDashAbility.h @@ -2,11 +2,15 @@ #define Events_DashAbility_h__ #include "Core/Event.h" +#include "Core/EntityWrapper.h" namespace Events { -struct DashAbility : public Event { }; +struct DashAbility : public Event +{ + EntityID Player; +}; } diff --git a/resources/Schema/Entities/DashEffect.xml b/resources/Schema/Entities/DashEffect.xml index b6bd53f7..9dfdc14c 100644 --- a/resources/Schema/Entities/DashEffect.xml +++ b/resources/Schema/Entities/DashEffect.xml @@ -1,15 +1,15 @@ - + - 1 + 0.5 0 - 1 + 0.5 diff --git a/src/Engine/Network/Client.cpp b/src/Engine/Network/Client.cpp index aa87f6ff..d666e550 100644 --- a/src/Engine/Network/Client.cpp +++ b/src/Engine/Network/Client.cpp @@ -33,6 +33,7 @@ void Client::Connect(std::string address, int port) EVENT_SUBSCRIBE_MEMBER(m_EPlayerDamage, &Client::OnPlayerDamage); EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &Client::OnPlayerSpawned); EVENT_SUBSCRIBE_MEMBER(m_EDoubleJump, &Client::OnDoubleJump); + EVENT_SUBSCRIBE_MEMBER(m_EDashAbility, &Client::OnDashAbility); EVENT_SUBSCRIBE_MEMBER(m_ESearchForServers, &Client::OnSearchForServers); auto config = ResourceManager::Load("Config.ini"); m_Address = address; @@ -143,6 +144,9 @@ void Client::parseMessageType(Packet& packet) case MessageType::OnDoubleJump: parseDoubleJump(packet); break; + case MessageType::OnDashEffect: + parseDashEffect(packet); + break; case MessageType::AmmoPickup: parseAmmoPickup(packet); break; @@ -262,7 +266,7 @@ void Client::parseEntityDeletion(Packet & packet) if (m_ServerIDToClientID.find(entityToDelete) != m_ServerIDToClientID.end()) { EntityID localEntity = m_ServerIDToClientID.at(entityToDelete); if (m_World->ValidEntity(localEntity)) { - if (m_World->HasComponent(localEntity,"Player")) { + if (m_World->HasComponent(localEntity, "Player")) { Events::PlayerDeath e; e.Player = EntityWrapper(m_World, localEntity); m_EventBroker->Publish(e); @@ -297,8 +301,22 @@ void Client::parseDoubleJump(Packet & packet) } } + +void Client::parseDashEffect(Packet& packet) +{ + EntityID serverID = packet.ReadPrimitive(); + if (!serverClientMapsHasEntity(serverID)) { + return; + } + Events::DashAbility e; + e.Player = m_ServerIDToClientID.at(serverID); + if (e.Player != m_LocalPlayer.ID) { + m_EventBroker->Publish(e); + } +} + void Client::parseAmmoPickup(Packet & packet) -{ +{ Events::AmmoPickup e; e.AmmoGain = packet.ReadPrimitive(); e.Player = m_LocalPlayer; @@ -388,7 +406,7 @@ void Client::parseSnapshot(Packet& packet) if (m_SnapshotFilter != nullptr) { shouldApply = m_SnapshotFilter->FilterComponent(localEntity, newComponent); } - if (shouldApply) { + if (shouldApply) { ComponentWrapper currentComponent = m_World->GetComponent(localEntityID, componentType); memcpy(currentComponent.Data, newComponent.Data, componentInfo.Stride); } @@ -518,6 +536,18 @@ bool Client::OnPlayerSpawned(const Events::PlayerSpawned& e) return true; } + +bool Client::OnDashAbility(const Events::DashAbility& e) +{ + if (!clientServerMapsHasEntity(e.Player) || e.Player != m_LocalPlayer.ID) { + return false; + } + Packet packet(MessageType::OnDashEffect); + packet.WritePrimitive(m_ClientIDToServerID.at(e.Player)); + m_Reliable.Send(packet); + return true; +} + bool Client::OnSearchForServers(const Events::SearchForServers& e) { m_SearchingForServers = true; diff --git a/src/Engine/Network/Server.cpp b/src/Engine/Network/Server.cpp index 08b72304..7ba54ec4 100644 --- a/src/Engine/Network/Server.cpp +++ b/src/Engine/Network/Server.cpp @@ -141,6 +141,9 @@ void Server::parseMessageType(Packet& packet) case MessageType::OnDoubleJump: parseDoubleJump(packet); break; + case MessageType::OnDashEffect: + parseDashEffect(packet); + break; default: break; } @@ -555,6 +558,11 @@ bool Server::parseDoubleJump(Packet & packet) return true; } +void Server::parseDashEffect(Packet& packet) +{ + reliableBroadcast(packet); +} + void Server::parseOnInputCommand(Packet& packet) { PlayerID player = -1; @@ -624,7 +632,7 @@ bool Server::shouldSendToClient(EntityWrapper childEntity) } return childEntity.HasComponent("Player") || childEntity.FirstParentWithComponent("Player").Valid() || childEntity.HasComponent("CapturePoint") || childEntity.HasComponent("HealthPickup") - || childEntity.HasComponent("AmmoPickup"); + || childEntity.HasComponent("AmmoPickup")/* || childEntity.Name() == "DashEffect"*/; } PlayerID Server::GetPlayerIDFromEndpoint() diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index 4925baa7..24bf6b05 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -67,7 +67,7 @@ void PlayerMovementSystem::updateMovementControllers(double dt) ComponentWrapper cPhysics = player["Physics"]; //Assault Dash Check if (player.HasComponent("DashAbility")) { - controller->AssaultDashCheck(dt, ((glm::vec3)cPhysics["Velocity"]).y != 0.0f, player["DashAbility"]["CoolDownMaxTimer"], player["DashAbility"]["CoolDownTimer"]); + controller->AssaultDashCheck(dt, ((glm::vec3)cPhysics["Velocity"]).y != 0.0f, player["DashAbility"]["CoolDownMaxTimer"], player["DashAbility"]["CoolDownTimer"], player); } wishDirection = controller->Movement() * glm::inverse(glm::quat(ori)); //this makes sure you can only dash in the 4 directions: forw,backw,left,right @@ -304,11 +304,11 @@ bool PlayerMovementSystem::OnPlayerSpawned(Events::PlayerSpawned& e) bool PlayerMovementSystem::OnDoubleJump(Events::DoubleJump & e) { // If entity does not exist, exit - if (!EntityWrapper(m_World, e.entityID).Valid()) { + if (!EntityWrapper(m_World, e.entityID).Valid()) { return false; } // If entity IsLocalPlayer, exit - if (e.entityID == m_LocalPlayer.ID) { + if (e.entityID == m_LocalPlayer.ID) { return false; } spawnHexagon(EntityWrapper(m_World, e.entityID)); @@ -316,7 +316,7 @@ bool PlayerMovementSystem::OnDoubleJump(Events::DoubleJump & e) } void PlayerMovementSystem::spawnHexagon(EntityWrapper target) -{ +{ //put a hexagon at the entitys... feet? auto hexagonEffect = ResourceManager::Load("Schema/Entities/DoubleJumpHexagon.xml"); EntityFileParser parser(hexagonEffect); @@ -327,11 +327,16 @@ void PlayerMovementSystem::spawnHexagon(EntityWrapper target) bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e) { + EntityWrapper player(m_World, e.Player); + if (!player.Valid() || !IsClient) { + return false; + } + auto dashEffectResource = ResourceManager::Load("Schema/Entities/DashEffect.xml"); EntityFileParser parser(dashEffectResource); EntityID dashEffectID = parser.MergeEntities(m_World); EntityWrapper dashEffect(m_World, dashEffectID); - auto playerModel = LocalPlayer.FirstChildByName("PlayerModel"); + auto playerModel = player.FirstChildByName("PlayerModel"); auto playerEntityModel = playerModel["Model"]; auto playerEntityAnimation = playerModel["Animation"]; playerEntityModel.Copy(dashEffect["Model"]); @@ -341,7 +346,7 @@ bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e) dashEffect["Animation"]["Speed1"] = 0.0; dashEffect["Animation"]["Speed2"] = 0.0; dashEffect["Animation"]["Speed3"] = 0.0; - dashEffect["Transform"]["Position"] = (glm::vec3)LocalPlayer["Transform"]["Position"]; - dashEffect["Transform"]["Orientation"] = (glm::vec3)LocalPlayer["Transform"]["Orientation"]; + dashEffect["Transform"]["Position"] = (glm::vec3)player["Transform"]["Position"]; + dashEffect["Transform"]["Orientation"] = (glm::vec3)player["Transform"]["Orientation"]; return true; } From 233a1d0990f53536065b5842088adaa7f0f6fa08 Mon Sep 17 00:00:00 2001 From: stiffly Date: Wed, 2 Mar 2016 16:56:43 +0100 Subject: [PATCH 080/130] The dash effect is now ignored on the local player, because it was annoying. Copies of yourself could be in your way. --- src/Game/Systems/PlayerMovementSystem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index 24bf6b05..ae1d1d9b 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -328,7 +328,7 @@ void PlayerMovementSystem::spawnHexagon(EntityWrapper target) bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e) { EntityWrapper player(m_World, e.Player); - if (!player.Valid() || !IsClient) { + if (!player.Valid() || !IsClient || player.ID == LocalPlayer.ID) { return false; } From 1aefa1dec6028ff1ad0290f3442e881d2ba9dc61 Mon Sep 17 00:00:00 2001 From: viktorljung Date: Wed, 2 Mar 2016 17:06:51 +0100 Subject: [PATCH 081/130] AutoAnimationBlend now working correctly for unique nodes --- assets | 2 +- include/Engine/Rendering/BlendTree.h | 5 +- include/Engine/Rendering/Skeleton.h | 29 +- resources/Schema/Entities/AnimationTests2.xml | 254 +++++++++--------- src/Engine/Rendering/BlendTree.cpp | 4 +- src/Engine/Rendering/BoneAttachmentSystem.cpp | 13 + src/Engine/Rendering/DrawBloomPass.cpp | 2 + src/Engine/Rendering/SSAOPass.cpp | 4 + src/Engine/Rendering/Skeleton.cpp | 236 +++++----------- 9 files changed, 240 insertions(+), 309 deletions(-) diff --git a/assets b/assets index 10a61165..4e2b71f1 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 10a611659ddaadfea6a560e707d395834855a979 +Subproject commit 4e2b71f13a3026d06ccde2337c41427e73400c80 diff --git a/include/Engine/Rendering/BlendTree.h b/include/Engine/Rendering/BlendTree.h index b19fbe4f..29ad3ca9 100644 --- a/include/Engine/Rendering/BlendTree.h +++ b/include/Engine/Rendering/BlendTree.h @@ -19,6 +19,7 @@ public: Animation, }; + struct Node { @@ -27,7 +28,7 @@ public: Node* Parent = nullptr; Node* Child[2] = { nullptr, nullptr }; NodeType Type; - std::map Pose; + std::map Pose; //std::vector Pose; double Weight = 0.0; @@ -85,7 +86,7 @@ private: BlendTree::Node* FillTreeByName(Node* parentNode, std::string name, EntityWrapper parentEntity); std::vector FindNodesByName(std::string name); - void Blend(std::map& pose); + void Blend(std::map& pose); }; #endif diff --git a/include/Engine/Rendering/Skeleton.h b/include/Engine/Rendering/Skeleton.h index e812bf12..08e348ab 100644 --- a/include/Engine/Rendering/Skeleton.h +++ b/include/Engine/Rendering/Skeleton.h @@ -50,11 +50,16 @@ public: std::map> JointAnimations; }; + struct PoseData { + glm::vec3 Translation; + glm::quat Orientation; + glm::vec3 Scale; + }; + Skeleton() { } ~Skeleton(); Bone* RootBone; - std::map Bones; std::unordered_map> BlendTrees; @@ -65,20 +70,20 @@ public: int GetBoneID(std::string name); const Animation* GetAnimation(std::string name); - std::map GetFrameBones(const Animation* animation, double time, bool additive, bool noRootMotion = false); - glm::mat4 GetBoneTransform(const Bone* bone, const Animation* animation, float time, glm::mat4 childMatrix); - std::map BlendPoses(const std::map& pose1, const std::map& pose2, double weight); - std::map OverridePose(const std::map& overridePose, const std::map& targetPose); - std::map BlendPoseAdditive(const std::map& additivePose, const std::map& targetPose); - void GetFinalPose(std::map& boneMatrices, std::vector& finalPose, std::map& boneTransforms); + std::map GetFrameBones(const Animation* animation, double time, bool additive, bool noRootMotion = false); + + std::map BlendPoses(const std::map& pose1, const std::map& pose2, double weight); + std::map OverridePose(const std::map& overridePose, const std::map& targetPose); + std::map BlendPoseAdditive(const std::map& additivePose, const std::map& targetPose); + void GetFinalPose(std::map& boneMatrices, std::vector& finalPose, std::map& boneTransforms); std::map Animations; private: - glm::mat4 GetAdditiveBonePose(const Bone* bone, const Animation* animation, double time); - glm::mat4 GetBonePose(const Bone* bone, const Animation* animation, double time, bool noRootMotion); - void AccumulateFinalPose(std::map& boneMatrices, std::map& boneTransforms, const Bone* bone, glm::mat4 parentMatrix); - void AdditiveBoneTransforms(const Animation* animation, double time, std::map& boneMatrices, const Bone* bone); - void AccumulateBoneTransforms(bool noRootMotion, const Animation* animation, double time, std::map& boneMatrices, const Bone* bone, glm::mat4 parentMatrix); + Skeleton::PoseData GetAdditiveBonePose(const Bone* bone, const Animation* animation, double time); + + void AccumulateFinalPose(std::map& boneMatrices, std::map& poseDatas, std::map& boneTransforms, const Bone* bone, glm::mat4 parentMatrix); + void AdditiveBoneTransforms(const Animation* animation, double time, std::map& boneMatrices, const Bone* bone); + void AccumulateBoneTransforms(bool noRootMotion, const Animation* animation, double time, std::map& boneMatrices, const Bone* bone); std::map m_BonesByName; diff --git a/resources/Schema/Entities/AnimationTests2.xml b/resources/Schema/Entities/AnimationTests2.xml index fa2a8463..aaa6de48 100644 --- a/resources/Schema/Entities/AnimationTests2.xml +++ b/resources/Schema/Entities/AnimationTests2.xml @@ -66,11 +66,12 @@ Models/Weapons/Blue/AssaultWeaponBlue.mesh + - + - + @@ -90,7 +91,7 @@ AimRifleA - + false true @@ -131,7 +132,7 @@ ShootFastRifleU - + 1 @@ -142,7 +143,7 @@ ShootRifleU - + 1 @@ -155,8 +156,8 @@ ReloadSwitchU - - false + + 1 @@ -169,7 +170,7 @@ StandCrouchBlend Jump - 0.48000049591064453 + 0 @@ -198,7 +199,7 @@ CrouchWalkF - + 1 @@ -219,7 +220,7 @@ CrouchStrafeLeftF - + 1 @@ -230,7 +231,7 @@ CrouchStrafeRightF - + 1 @@ -246,7 +247,7 @@ RunWalkBlend StrafeBlend - 0 + 1 @@ -265,7 +266,8 @@ RunF - + + 1 @@ -275,7 +277,7 @@ WalkF - + 1 @@ -289,7 +291,7 @@ Left Right - 0 + 1 @@ -298,7 +300,7 @@ StrafeLeftF - + 1 @@ -309,7 +311,7 @@ StrafeRightF - + 1 @@ -326,8 +328,8 @@ JumpF - - false + + 1 @@ -352,13 +354,13 @@ Models/Core/UnitCube.mesh - + true - + - + @@ -372,12 +374,12 @@ Models/Core/UnitCube.mesh - + - - - + + + @@ -391,12 +393,12 @@ Models/Core/UnitCube.mesh - + - - - + + + @@ -410,12 +412,12 @@ Models/Core/UnitCube.mesh - + - - - + + + @@ -429,12 +431,12 @@ Models/Core/UnitCube.mesh - + - - - + + + @@ -448,12 +450,12 @@ Models/Core/UnitCube.mesh - + - - - + + + @@ -467,12 +469,12 @@ Models/Core/UnitCube.mesh - + - - - + + + @@ -486,12 +488,12 @@ Models/Core/UnitCube.mesh - + - - - + + + @@ -505,12 +507,12 @@ Models/Core/UnitCube.mesh - + - - - + + + @@ -524,12 +526,12 @@ Models/Core/UnitCube.mesh - + - - - + + + @@ -543,12 +545,12 @@ Models/Core/UnitCube.mesh - + - - - + + + @@ -562,12 +564,12 @@ Models/Core/UnitCube.mesh - + - - - + + + @@ -581,12 +583,12 @@ Models/Core/UnitCube.mesh - + - - - + + + @@ -600,12 +602,12 @@ Models/Core/UnitCube.mesh - + - - - + + + @@ -619,12 +621,12 @@ Models/Core/UnitCube.mesh - + - - - + + + @@ -638,12 +640,12 @@ Models/Core/UnitCube.mesh - + - - - + + + @@ -657,12 +659,12 @@ Models/Core/UnitCube.mesh - + - - - + + + @@ -676,12 +678,12 @@ Models/Core/UnitCube.mesh - + - - - + + + @@ -695,12 +697,12 @@ Models/Core/UnitCube.mesh - + - - - + + + @@ -714,12 +716,12 @@ Models/Core/UnitCube.mesh - + - - - + + + @@ -733,12 +735,12 @@ Models/Core/UnitCube.mesh - + - - - + + + @@ -752,12 +754,12 @@ Models/Core/UnitCube.mesh - + - - - + + + @@ -771,12 +773,12 @@ Models/Core/UnitCube.mesh - + - - - + + + @@ -790,12 +792,12 @@ Models/Core/UnitCube.mesh - + - - - + + + @@ -809,12 +811,12 @@ Models/Core/UnitCube.mesh - + - - - + + + @@ -828,12 +830,12 @@ Models/Core/UnitCube.mesh - + - - - + + + @@ -847,12 +849,12 @@ Models/Core/UnitCube.mesh - + - - - + + + diff --git a/src/Engine/Rendering/BlendTree.cpp b/src/Engine/Rendering/BlendTree.cpp index 8ef67f0f..cb7ffa69 100644 --- a/src/Engine/Rendering/BlendTree.cpp +++ b/src/Engine/Rendering/BlendTree.cpp @@ -238,7 +238,7 @@ BlendTree::AutoBlendInfo BlendTree::AutoBlendStep(AutoBlendInfo blendInfo) return blendInfo; } -void BlendTree::Blend(std::map& pose) +void BlendTree::Blend(std::map& pose) { Node* currentNode; Node* start = m_Root; @@ -301,7 +301,7 @@ std::vector BlendTree::AccumulateFinalPose() return finalPose; } - std::map pose; + std::map pose; Blend(pose); m_Skeleton->GetFinalPose(pose, finalPose, m_FinalBoneTransforms); diff --git a/src/Engine/Rendering/BoneAttachmentSystem.cpp b/src/Engine/Rendering/BoneAttachmentSystem.cpp index 43dc8634..191fb3bd 100644 --- a/src/Engine/Rendering/BoneAttachmentSystem.cpp +++ b/src/Engine/Rendering/BoneAttachmentSystem.cpp @@ -50,6 +50,19 @@ void BoneAttachmentSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapp glm::vec4 perspective; glm::decompose(boneTransform, scale, rotation, translation, skew, perspective); + float lowRange = 0.98f; + float highRange = 1.02f; + if(scale.x < lowRange || scale.y < lowRange || scale.z < lowRange || + scale.x > highRange || scale.y > highRange || scale.z > highRange) { + if (entity.HasComponent("Model")) { + (glm::vec4&)entity["Model"]["Color"] = glm::vec4(1, 0, 0, 1); + } + } else { + if (entity.HasComponent("Model")) { + (glm::vec4&)entity["Model"]["Color"] = glm::vec4(0, 1, 0, 1); + } + } + glm::vec3 angles = glm::vec3(-glm::pitch(rotation), -glm::yaw(rotation), -glm::roll(rotation)); if ((bool)entity["BoneAttachment"]["InheritPosition"]) { diff --git a/src/Engine/Rendering/DrawBloomPass.cpp b/src/Engine/Rendering/DrawBloomPass.cpp index 12777941..73f73cc4 100644 --- a/src/Engine/Rendering/DrawBloomPass.cpp +++ b/src/Engine/Rendering/DrawBloomPass.cpp @@ -45,6 +45,7 @@ void DrawBloomPass::InitializeShaderPrograms() m_GaussianProgram_horiz->AddShader(std::shared_ptr(new VertexShader("Shaders/Gaussian_horiz.vert.glsl"))); m_GaussianProgram_horiz->AddShader(std::shared_ptr(new FragmentShader("Shaders/Gaussian_horiz.frag.glsl"))); m_GaussianProgram_horiz->Compile(); + m_GaussianProgram_horiz->BindFragDataLocation(0, "fragmentColor"); m_GaussianProgram_horiz->Link(); } @@ -53,6 +54,7 @@ void DrawBloomPass::InitializeShaderPrograms() m_GaussianProgram_vert->AddShader(std::shared_ptr(new VertexShader("Shaders/Gaussian_vert.vert.glsl"))); m_GaussianProgram_vert->AddShader(std::shared_ptr(new FragmentShader("Shaders/Gaussian_vert.frag.glsl"))); m_GaussianProgram_vert->Compile(); + m_GaussianProgram_vert->BindFragDataLocation(0, "fragmentColor"); m_GaussianProgram_vert->Link(); } } diff --git a/src/Engine/Rendering/SSAOPass.cpp b/src/Engine/Rendering/SSAOPass.cpp index 9992db70..3b11535f 100644 --- a/src/Engine/Rendering/SSAOPass.cpp +++ b/src/Engine/Rendering/SSAOPass.cpp @@ -56,6 +56,7 @@ void SSAOPass::InitializeShaderProgram() m_SSAOProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/SSAO.vert.glsl"))); m_SSAOProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/SSAO.frag.glsl"))); m_SSAOProgram->Compile(); + m_SSAOProgram->BindFragDataLocation(0, "AO"); m_SSAOProgram->Link(); } @@ -64,6 +65,7 @@ void SSAOPass::InitializeShaderProgram() m_SSAOViewSpaceZProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/SSAO.vert.glsl"))); m_SSAOViewSpaceZProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/SSAOViewSpaceZ.frag.glsl"))); m_SSAOViewSpaceZProgram->Compile(); + m_SSAOViewSpaceZProgram->BindFragDataLocation(0, "depthLinear"); m_SSAOViewSpaceZProgram->Link(); } @@ -72,6 +74,7 @@ void SSAOPass::InitializeShaderProgram() m_GaussianProgram_horiz->AddShader(std::shared_ptr(new VertexShader("Shaders/Gaussian_horiz.vert.glsl"))); m_GaussianProgram_horiz->AddShader(std::shared_ptr(new FragmentShader("Shaders/Gaussian_horiz.frag.glsl"))); m_GaussianProgram_horiz->Compile(); + m_GaussianProgram_horiz->BindFragDataLocation(0, "fragmentColor"); m_GaussianProgram_horiz->Link(); } @@ -80,6 +83,7 @@ void SSAOPass::InitializeShaderProgram() m_GaussianProgram_vert->AddShader(std::shared_ptr(new VertexShader("Shaders/Gaussian_vert.vert.glsl"))); m_GaussianProgram_vert->AddShader(std::shared_ptr(new FragmentShader("Shaders/Gaussian_vert.frag.glsl"))); m_GaussianProgram_vert->Compile(); + m_GaussianProgram_vert->BindFragDataLocation(0, "fragmentColor"); m_GaussianProgram_vert->Link(); } } diff --git a/src/Engine/Rendering/Skeleton.cpp b/src/Engine/Rendering/Skeleton.cpp index b6fea0bb..c9ae2732 100644 --- a/src/Engine/Rendering/Skeleton.cpp +++ b/src/Engine/Rendering/Skeleton.cpp @@ -1,20 +1,26 @@ #include "Rendering/Skeleton.h" -std::map Skeleton::GetFrameBones(const Animation* animation, double time, bool additive, bool noRootMotion /*= false*/) +std::map Skeleton::GetFrameBones(const Animation* animation, double time, bool additive, bool noRootMotion /*= false*/) { if (animation == nullptr) { - std::map finalMatrices; + std::map finalMatrices; for (auto& b : Bones) { - finalMatrices[b.second->ID] = glm::mat4(1); + PoseData poseData; + poseData.Translation = glm::vec3(0); + poseData.Orientation = glm::quat(); + poseData.Scale = glm::vec3(1); + + + finalMatrices[b.second->ID] = poseData; } return finalMatrices; } - std::map frameBones; + std::map frameBones; if(!additive) { - AccumulateBoneTransforms(true, animation, time, frameBones, RootBone, glm::mat4(1)); + AccumulateBoneTransforms(true, animation, time, frameBones, RootBone); } else { AdditiveBoneTransforms(animation, time, frameBones, RootBone); } @@ -22,11 +28,10 @@ std::map Skeleton::GetFrameBones(const Animation* animation, dou return frameBones; } -void Skeleton::AccumulateBoneTransforms(bool noRootMotion, const Animation* animation, double time, std::map& boneMatrices, const Bone* bone, glm::mat4 parentMatrix) +void Skeleton::AccumulateBoneTransforms(bool noRootMotion, const Animation* animation, double time, std::map& boneMatrices, const Bone* bone) { - glm::mat4 boneMatrix; + PoseData poseData; - if (animation->JointAnimations.find(bone->ID) != animation->JointAnimations.end()) { std::vector boneKeyFrames = animation->JointAnimations.at(bone->ID); @@ -66,37 +71,38 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, const Animation* anim position.z = 0; } - boneMatrix = (glm::translate(position) * glm::toMat4(rotation) * glm::scale(scale)); - boneMatrices[bone->ID] = boneMatrix;// *bone->OffsetMatrix; + poseData.Translation = position; + poseData.Orientation = rotation; + poseData.Scale = scale; + boneMatrices[bone->ID] = poseData; } else { // 1 keyframes for the current bone currentFrame = boneKeyFrames.at(0); - boneMatrix = (glm::translate(currentFrame.BoneProperties.Position) * glm::toMat4(glm::normalize(currentFrame.BoneProperties.Rotation)) * glm::scale(currentFrame.BoneProperties.Scale)); - boneMatrices[bone->ID] = boneMatrix;// *bone->OffsetMatrix; - } - } else { // 0 keyframes for the current bone - if (bone->Parent) { - //boneMatrix = parentMatrix * (glm::inverse(bone->OffsetMatrix) * bone->Parent->OffsetMatrix); - //boneMatrices[bone->ID] = boneMatrix *bone->OffsetMatrix; - } else { - //boneMatrix = glm::inverse(bone->OffsetMatrix); - //boneMatrices[bone->ID] = parentMatrix; + poseData.Translation = currentFrame.BoneProperties.Position; + poseData.Orientation = currentFrame.BoneProperties.Rotation; + poseData.Scale = currentFrame.BoneProperties.Scale; + boneMatrices[bone->ID] = poseData; } } for (auto &child : bone->Children) { - AccumulateBoneTransforms(noRootMotion, animation, time, boneMatrices, child, boneMatrix); + AccumulateBoneTransforms(noRootMotion, animation, time, boneMatrices, child); } } -void Skeleton::AdditiveBoneTransforms(const Animation* animation, double time, std::map& boneMatrices, const Bone* bone) +void Skeleton::AdditiveBoneTransforms(const Animation* animation, double time, std::map& boneMatrices, const Bone* bone) { if (animation->JointAnimations.find(bone->ID) != animation->JointAnimations.end()) { - glm::mat4 refPose = GetAdditiveBonePose(bone, animation, 0.0); - glm::mat4 srcPose = GetAdditiveBonePose(bone, animation, time + 1.0/60.0); - glm::mat4 boneMatrix = srcPose * glm::inverse(refPose); - boneMatrices[bone->ID] = boneMatrix; + PoseData refPose = GetAdditiveBonePose(bone, animation, 0.0); + PoseData srcPose = GetAdditiveBonePose(bone, animation, time + 1.0/60.0); + + PoseData finalPose; + finalPose.Translation = srcPose.Translation - refPose.Translation; + finalPose.Orientation = srcPose.Orientation * glm::inverse(refPose.Orientation); + finalPose.Scale = srcPose.Scale - refPose.Scale; + + boneMatrices[bone->ID] = finalPose; } for (auto &child : bone->Children) { @@ -104,7 +110,7 @@ void Skeleton::AdditiveBoneTransforms(const Animation* animation, double time, s } } -glm::mat4 Skeleton::GetAdditiveBonePose(const Bone* bone, const Animation* animation, double time) +Skeleton::PoseData Skeleton::GetAdditiveBonePose(const Bone* bone, const Animation* animation, double time) { glm::vec3 position = glm::vec3(0); glm::quat rotation = glm::quat(); @@ -152,141 +158,32 @@ glm::mat4 Skeleton::GetAdditiveBonePose(const Bone* bone, const Animation* anima } } - return (glm::translate(position) * glm::toMat4(rotation) * glm::scale(scale));; + PoseData finalPose; + finalPose.Translation = position; + finalPose.Orientation = rotation; + finalPose.Scale = scale; + + return finalPose; } - -glm::mat4 Skeleton::GetBonePose(const Bone* bone, const Animation* animation, double time, bool noRootMotion) +std::map Skeleton::BlendPoses(const std::map& pose1, const std::map& pose2, double weight) { - glm::mat4 boneMatrix; + std::map finalPose; - if (animation->JointAnimations.find(bone->ID) != animation->JointAnimations.end()) { - std::vector boneKeyFrames = animation->JointAnimations.at(bone->ID); - - Animation::Keyframe currentFrame; - Animation::Keyframe nextFrame; - - if (boneKeyFrames.size() > 1) { // 2+ keyframes for the current bone - for (int index = boneKeyFrames.size()-1; index >= 0; index--) { // find the bone keyframes that surrounds the current frame - if (time >= boneKeyFrames.at(index).Time) { - currentFrame = boneKeyFrames.at(index); - nextFrame = boneKeyFrames.at((index + 1) % boneKeyFrames.size()); - break; - } - } - - float progress; - - if (nextFrame.Index == 0) { - nextFrame = currentFrame; - progress = (time - currentFrame.Time) / (animation->Duration - currentFrame.Time); - } else { - progress = (time - currentFrame.Time) / (nextFrame.Time - currentFrame.Time); - - } - - - if (progress > 1.0f || progress < 0.0f) { - progress = glm::clamp(progress, 0.0f, 1.0f); - } - Animation::Keyframe::BoneProperty currentBoneProperty = currentFrame.BoneProperties; - Animation::Keyframe::BoneProperty nextBoneProperty = nextFrame.BoneProperties; - - glm::vec3 position = currentBoneProperty.Position * (1.f - progress) + nextBoneProperty.Position * progress; - glm::quat rotation = glm::slerp(currentBoneProperty.Rotation, nextBoneProperty.Rotation, progress); - glm::vec3 scale = currentBoneProperty.Scale * (1.f - progress) + nextBoneProperty.Scale * progress; - - // Flag for no root motion - if (bone == RootBone && noRootMotion) { - position.x = 0; - position.z = 0; - } - - boneMatrix = (glm::translate(position) * glm::toMat4(rotation) * glm::scale(scale)); - - } else { // 1 keyframes for the current bone - currentFrame = boneKeyFrames.at(0); - boneMatrix = (glm::translate(currentFrame.BoneProperties.Position) * glm::toMat4(currentFrame.BoneProperties.Rotation) * glm::scale(currentFrame.BoneProperties.Scale)); - } - } //else { // 0 keyframes for the current bone - - // } - - return boneMatrix; -} - -glm::mat4 Skeleton::GetBoneTransform(const Bone* bone, const Animation* animation, float time, glm::mat4 childMatrix) -{ - glm::mat4 boneMatrix; - - Animation::Keyframe currentFrame; - Animation::Keyframe nextFrame; - - if (animation->JointAnimations.find(bone->ID) != animation->JointAnimations.end()) { - std::vector boneKeyFrames = animation->JointAnimations.at(bone->ID); - - if (boneKeyFrames.size() > 1) { // 2+ keyframes for the current bone - for (int index = boneKeyFrames.size()-1; index >= 0; index--) { // find the bone keyframes that surrounds the current frame - if (time >= boneKeyFrames.at(index).Time) { - currentFrame = boneKeyFrames.at(index); - nextFrame = boneKeyFrames.at((index + 1) % boneKeyFrames.size()); - break; - } - } - - float progress; - - if (nextFrame.Index == 0) { - nextFrame = currentFrame; - progress = (time - currentFrame.Time) / (animation->Duration - currentFrame.Time); - } else { - progress = (time - currentFrame.Time) / (nextFrame.Time - currentFrame.Time); - } - - if (progress > 1.0f || progress < 0.0f) { - //LOG_INFO("Progress %f", progress); - progress = glm::clamp(progress, 0.0f, 1.0f); - } - Animation::Keyframe::BoneProperty currentBoneProperty = currentFrame.BoneProperties; - Animation::Keyframe::BoneProperty nextBoneProperty = nextFrame.BoneProperties; - - glm::vec3 positionInterp = currentBoneProperty.Position * (1.f - progress) + nextBoneProperty.Position * progress; - glm::quat rotationInterp = glm::slerp(currentBoneProperty.Rotation, nextBoneProperty.Rotation, progress); - glm::vec3 scaleInterp = currentBoneProperty.Scale * (1.f - progress) + nextBoneProperty.Scale * progress; - - boneMatrix = (glm::translate(positionInterp) * glm::toMat4(rotationInterp) * glm::scale(scaleInterp)) * childMatrix; - - } else { // 1 keyframes for the current bone - currentFrame = boneKeyFrames.at(0); - boneMatrix = (glm::translate(currentFrame.BoneProperties.Position) * glm::toMat4(currentFrame.BoneProperties.Rotation) * glm::scale(currentFrame.BoneProperties.Scale)) * childMatrix; - - } - } else { // 0 keyframes for the current bone - if (bone->Parent) { - boneMatrix = bone->Parent->OffsetMatrix * glm::inverse(bone->OffsetMatrix) * childMatrix; - } else { - boneMatrix = glm::inverse(bone->OffsetMatrix) * childMatrix; - } - } - - if (bone->Parent) { - return GetBoneTransform(bone->Parent, animation, time, boneMatrix); - } else { - return boneMatrix; - } -} - -std::map Skeleton::BlendPoses(const std::map& pose1, const std::map& pose2, double weight) -{ - std::map finalPose; + float weight1 = (float)(1.0 - weight); + float weight2 = (float)(weight); for (auto& b : Bones) { int boneID = b.second->ID; - glm::mat4 blendedPose = glm::mat4(0); + PoseData blendedPose; + blendedPose.Translation = glm::vec3(0); + blendedPose.Orientation = glm::quat(); + blendedPose.Scale = glm::vec3(1); if(pose1.find(boneID) != pose1.end() && pose2.find(boneID) != pose2.end()) { - blendedPose += pose1.at(boneID) * (float)(1.0 - weight); - blendedPose += pose2.at(boneID) * (float)weight; + blendedPose.Translation = pose1.at(boneID).Translation * weight1 + pose2.at(boneID).Translation * weight2; + blendedPose.Orientation = glm::slerp(pose1.at(boneID).Orientation, pose2.at(boneID).Orientation, weight2); + blendedPose.Scale = pose1.at(boneID).Scale * weight1 + pose2.at(boneID).Scale * weight2; finalPose[boneID] = blendedPose; } else if(pose1.find(boneID) != pose1.end()) { finalPose[boneID] = pose1.at(boneID); @@ -298,9 +195,9 @@ std::map Skeleton::BlendPoses(const std::map& po return finalPose; } -std::map Skeleton::OverridePose(const std::map& overridePose, const std::map& targetPose) +std::map Skeleton::OverridePose(const std::map& overridePose, const std::map& targetPose) { - std::map finalPose; + std::map finalPose; for (auto& b : Bones) { int boneID = b.second->ID; @@ -313,18 +210,22 @@ std::map Skeleton::OverridePose(const std::map& return finalPose; } -std::map Skeleton::BlendPoseAdditive(const std::map& additivePose, const std::map& targetPose) +std::map Skeleton::BlendPoseAdditive(const std::map& additivePose, const std::map& targetPose) { - std::map finalPose; + std::map finalPose; for (auto& b : Bones) { int boneID = b.second->ID; - glm::mat4 blendedPose = glm::mat4(1); + PoseData blendedPose; + blendedPose.Translation = glm::vec3(0); + blendedPose.Orientation = glm::quat(); + blendedPose.Scale = glm::vec3(1); if (additivePose.find(boneID) != additivePose.end() && targetPose.find(boneID) != targetPose.end()) { - blendedPose = additivePose.at(boneID) * targetPose.at(boneID); + blendedPose.Translation = additivePose.at(boneID).Translation + targetPose.at(boneID).Translation; + blendedPose.Orientation = additivePose.at(boneID).Orientation * targetPose.at(boneID).Orientation; + blendedPose.Scale = additivePose.at(boneID).Scale + targetPose.at(boneID).Scale; finalPose[boneID] = blendedPose; - } else if (additivePose.find(boneID) != additivePose.end()) { finalPose[boneID] = additivePose.at(boneID); } else if (targetPose.find(boneID) != targetPose.end()) { @@ -335,9 +236,12 @@ std::map Skeleton::BlendPoseAdditive(const std::map& boneMatrices, std::vector& finalPose, std::map& boneTransforms) +void Skeleton::GetFinalPose(std::map& poseDatas, std::vector& finalPose, std::map& boneTransforms) { - AccumulateFinalPose(boneMatrices, boneTransforms, RootBone, glm::mat4(1)); + + std::map boneMatrices; + + AccumulateFinalPose(boneMatrices, poseDatas, boneTransforms, RootBone, glm::mat4(1)); for(auto& b : boneMatrices) { finalPose.push_back(b.second); @@ -345,12 +249,12 @@ void Skeleton::GetFinalPose(std::map& boneMatrices, std::vector< } -void Skeleton::AccumulateFinalPose(std::map& boneMatrices, std::map& boneTransforms, const Bone* bone, glm::mat4 parentMatrix) +void Skeleton::AccumulateFinalPose(std::map& boneMatrices, std::map& poseDatas, std::map& boneTransforms, const Bone* bone, glm::mat4 parentMatrix) { glm::mat4 boneMatrix; - if (boneMatrices.find(bone->ID) != boneMatrices.end()) { - boneMatrix = parentMatrix * boneMatrices.at(bone->ID); + if (poseDatas.find(bone->ID) != poseDatas.end()) { + boneMatrix = parentMatrix * (glm::translate(poseDatas.at(bone->ID).Translation) * glm::mat4(poseDatas.at(bone->ID).Orientation) * glm::scale(poseDatas.at(bone->ID).Scale)); boneMatrices[bone->ID] = boneMatrix * bone->OffsetMatrix; } else { if (bone->Parent) { @@ -365,7 +269,7 @@ void Skeleton::AccumulateFinalPose(std::map& boneMatrices, std:: boneTransforms[bone->ID] = boneMatrix; for (auto &child : bone->Children) { - AccumulateFinalPose(boneMatrices, boneTransforms, child, boneMatrix); + AccumulateFinalPose(boneMatrices, poseDatas, boneTransforms, child, boneMatrix); } } From 53c520123a7700d7284e5fe13d0bafd50c71102a Mon Sep 17 00:00:00 2001 From: William Moberg Date: Wed, 2 Mar 2016 17:06:53 +0100 Subject: [PATCH 082/130] Uncommented code. --- src/Engine/Editor/EditorSystem.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Engine/Editor/EditorSystem.cpp b/src/Engine/Editor/EditorSystem.cpp index 47547b8f..b0929df9 100644 --- a/src/Engine/Editor/EditorSystem.cpp +++ b/src/Engine/Editor/EditorSystem.cpp @@ -258,17 +258,17 @@ EntityWrapper EditorSystem::importEntity(EntityWrapper parent, boost::filesystem return EntityWrapper::Invalid; } - //try { + try { auto entityFile = ResourceManager::Load(filePath.string()); EntityFilePreprocessor fpp(entityFile); fpp.RegisterComponents(parent.World); EntityFileParser fp(entityFile); EntityID newEntity = fp.MergeEntities(parent.World, parent.ID); return EntityWrapper(parent.World, newEntity); - /*} catch (const std::exception& e) { + } catch (const std::exception& e) { LOG_ERROR("Failed to import entity \"%s\": \"%s\"", filePath.string().c_str(), e.what()); return EntityWrapper::Invalid; - }*/ + } } void EditorSystem::setWidgetMode(EditorGUI::WidgetMode mode) From d8a0e69ff05b361974ba6db4ecc7e9ac4f0cecd5 Mon Sep 17 00:00:00 2001 From: viktorljung Date: Wed, 2 Mar 2016 17:11:18 +0100 Subject: [PATCH 083/130] fixup! AutoAnimationBlend now working correctly for unique nodes, Commited debug code --- src/Engine/Rendering/BoneAttachmentSystem.cpp | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/Engine/Rendering/BoneAttachmentSystem.cpp b/src/Engine/Rendering/BoneAttachmentSystem.cpp index 191fb3bd..43dc8634 100644 --- a/src/Engine/Rendering/BoneAttachmentSystem.cpp +++ b/src/Engine/Rendering/BoneAttachmentSystem.cpp @@ -50,19 +50,6 @@ void BoneAttachmentSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapp glm::vec4 perspective; glm::decompose(boneTransform, scale, rotation, translation, skew, perspective); - float lowRange = 0.98f; - float highRange = 1.02f; - if(scale.x < lowRange || scale.y < lowRange || scale.z < lowRange || - scale.x > highRange || scale.y > highRange || scale.z > highRange) { - if (entity.HasComponent("Model")) { - (glm::vec4&)entity["Model"]["Color"] = glm::vec4(1, 0, 0, 1); - } - } else { - if (entity.HasComponent("Model")) { - (glm::vec4&)entity["Model"]["Color"] = glm::vec4(0, 1, 0, 1); - } - } - glm::vec3 angles = glm::vec3(-glm::pitch(rotation), -glm::yaw(rotation), -glm::roll(rotation)); if ((bool)entity["BoneAttachment"]["InheritPosition"]) { From a9a19193ad18c4be8149c08651988d0bd2ea2dcc Mon Sep 17 00:00:00 2001 From: Tleety Date: Wed, 2 Mar 2016 17:21:15 +0100 Subject: [PATCH 084/130] Component for Boost icons --- resources/Schema/Components.xsd | 1 + resources/Schema/Components/BoostIconsHUD.xml | 2 ++ resources/Schema/Components/BoostIconsHUD.xsd | 10 ++++++++++ resources/Schema/Types/Entity.xsd | 1 + 4 files changed, 14 insertions(+) create mode 100644 resources/Schema/Components/BoostIconsHUD.xml create mode 100644 resources/Schema/Components/BoostIconsHUD.xsd diff --git a/resources/Schema/Components.xsd b/resources/Schema/Components.xsd index a75de84e..f0fb52d3 100644 --- a/resources/Schema/Components.xsd +++ b/resources/Schema/Components.xsd @@ -56,4 +56,5 @@ + \ No newline at end of file diff --git a/resources/Schema/Components/BoostIconsHUD.xml b/resources/Schema/Components/BoostIconsHUD.xml new file mode 100644 index 00000000..e25d9611 --- /dev/null +++ b/resources/Schema/Components/BoostIconsHUD.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/resources/Schema/Components/BoostIconsHUD.xsd b/resources/Schema/Components/BoostIconsHUD.xsd new file mode 100644 index 00000000..c5fe2e5d --- /dev/null +++ b/resources/Schema/Components/BoostIconsHUD.xsd @@ -0,0 +1,10 @@ + + + + + + + Origin for the 3 boost states. Create 3 children with Sprite and Fill components, name them "Sprint", "Defender", "Assault" + + + \ No newline at end of file diff --git a/resources/Schema/Types/Entity.xsd b/resources/Schema/Types/Entity.xsd index 61d8e520..94183c75 100644 --- a/resources/Schema/Types/Entity.xsd +++ b/resources/Schema/Types/Entity.xsd @@ -53,6 +53,7 @@ + From 7d15313209e7ef79893828f22616a8c146fb4a09 Mon Sep 17 00:00:00 2001 From: antc13 Date: Wed, 2 Mar 2016 17:22:44 +0100 Subject: [PATCH 085/130] Added a FloatingEffectSystem to the game. Pickups now move up and down, if so desired. --- include/Game/Systems/FloatingEffectSystem.h | 20 +++ resources/Schema/Components.xsd | 1 + .../Schema/Components/FloatingEffect.xml | 7 + .../Schema/Components/FloatingEffect.xsd | 17 ++ resources/Schema/Entities/NewMap2version2.xml | 98 ++++++------ .../Schema/Entities/NewMap2version3NEW.xml | 148 ++++++++++++++---- src/Game/Game.cpp | 2 + 7 files changed, 210 insertions(+), 83 deletions(-) create mode 100644 include/Game/Systems/FloatingEffectSystem.h create mode 100644 resources/Schema/Components/FloatingEffect.xml create mode 100644 resources/Schema/Components/FloatingEffect.xsd diff --git a/include/Game/Systems/FloatingEffectSystem.h b/include/Game/Systems/FloatingEffectSystem.h new file mode 100644 index 00000000..2462e029 --- /dev/null +++ b/include/Game/Systems/FloatingEffectSystem.h @@ -0,0 +1,20 @@ +#include "Common.h" +#include "Core/System.h" + +class FloatingEffectSystem : public PureSystem +{ +public: + FloatingEffectSystem(SystemParams params) + : System(params) + , PureSystem("FloatingEffect") + { } + + virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt) override + { + ComponentWrapper& transform = m_World->GetComponent(component.EntityID, "Transform"); + (double&)component["Time"] += dt; + //(double)component["Amplitude"] * glm::sin((glm::two_pi() / (double)component["Period"]) * (double)component["Time"]); + (glm::vec3&)transform["Position"] = (float)(double)component["Amplitude"] * glm::sin((glm::two_pi() / (float)(double)component["Period"]) * (float)(double)component["Time"]) * (glm::vec3)component["Axis"]; + + } +}; \ No newline at end of file diff --git a/resources/Schema/Components.xsd b/resources/Schema/Components.xsd index a75de84e..fccfd3d0 100644 --- a/resources/Schema/Components.xsd +++ b/resources/Schema/Components.xsd @@ -56,4 +56,5 @@ + \ No newline at end of file diff --git a/resources/Schema/Components/FloatingEffect.xml b/resources/Schema/Components/FloatingEffect.xml new file mode 100644 index 00000000..661e4ae4 --- /dev/null +++ b/resources/Schema/Components/FloatingEffect.xml @@ -0,0 +1,7 @@ + + + 1 + 1 + + + \ No newline at end of file diff --git a/resources/Schema/Components/FloatingEffect.xsd b/resources/Schema/Components/FloatingEffect.xsd new file mode 100644 index 00000000..a71006f5 --- /dev/null +++ b/resources/Schema/Components/FloatingEffect.xsd @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/resources/Schema/Entities/NewMap2version2.xml b/resources/Schema/Entities/NewMap2version2.xml index fcb81666..8089073f 100644 --- a/resources/Schema/Entities/NewMap2version2.xml +++ b/resources/Schema/Entities/NewMap2version2.xml @@ -804,11 +804,11 @@ - + 2 - + @@ -825,7 +825,7 @@ - + @@ -851,11 +851,11 @@ - + 2 - + @@ -872,7 +872,7 @@ - + @@ -898,11 +898,11 @@ - + 2 - + @@ -919,7 +919,7 @@ - + @@ -945,11 +945,11 @@ - + 2 - + @@ -966,7 +966,7 @@ - + @@ -992,11 +992,11 @@ - + 2 - + @@ -1013,7 +1013,7 @@ - + @@ -1039,11 +1039,11 @@ - + 2 - + @@ -1060,7 +1060,7 @@ - + @@ -1086,11 +1086,11 @@ - + 2 - + @@ -1107,7 +1107,7 @@ - + @@ -2242,7 +2242,7 @@ Models/Props/Stones/AssaultHolder.mesh - + @@ -2355,11 +2355,11 @@ - + 2 - + @@ -2376,7 +2376,7 @@ - + @@ -2402,11 +2402,11 @@ - + 2 - + @@ -2423,7 +2423,7 @@ - + @@ -2904,11 +2904,11 @@ - + 2 - + @@ -2925,7 +2925,7 @@ - + @@ -2951,11 +2951,11 @@ - + 2 - + @@ -2972,7 +2972,7 @@ - + @@ -2998,11 +2998,11 @@ - + 2 - + @@ -3019,7 +3019,7 @@ - + @@ -3045,11 +3045,11 @@ - + 2 - + @@ -3066,7 +3066,7 @@ - + @@ -3092,11 +3092,11 @@ - + 2 - + @@ -3113,7 +3113,7 @@ - + @@ -3139,11 +3139,11 @@ - + 2 - + @@ -3160,7 +3160,7 @@ - + @@ -3186,11 +3186,11 @@ - + 2 - + @@ -3207,7 +3207,7 @@ - + diff --git a/resources/Schema/Entities/NewMap2version3NEW.xml b/resources/Schema/Entities/NewMap2version3NEW.xml index 5b224de3..61e7b740 100644 --- a/resources/Schema/Entities/NewMap2version3NEW.xml +++ b/resources/Schema/Entities/NewMap2version3NEW.xml @@ -802,8 +802,13 @@ + + + + 2 + - + @@ -821,7 +826,7 @@ - + @@ -844,8 +849,13 @@ + + + + 2 + - + @@ -863,7 +873,7 @@ - + @@ -886,8 +896,13 @@ + + + + 2 + - + @@ -905,7 +920,7 @@ - + @@ -928,8 +943,13 @@ + + + + 2 + - + @@ -947,7 +967,7 @@ - + @@ -970,8 +990,13 @@ + + + + 2 + - + @@ -989,7 +1014,7 @@ - + @@ -1012,8 +1037,13 @@ + + + + 2 + - + @@ -1031,7 +1061,7 @@ - + @@ -1054,8 +1084,13 @@ + + + + 2 + - + @@ -1073,7 +1108,7 @@ - + @@ -2318,8 +2353,13 @@ + + + + 2 + - + @@ -2337,7 +2377,7 @@ - + @@ -2360,8 +2400,13 @@ + + + + 2 + - + @@ -2379,7 +2424,7 @@ - + @@ -2857,8 +2902,13 @@ + + + + 2 + - + @@ -2876,7 +2926,7 @@ - + @@ -2899,8 +2949,13 @@ + + + + 2 + - + @@ -2918,7 +2973,7 @@ - + @@ -2941,8 +2996,13 @@ + + + + 2 + - + @@ -2960,7 +3020,7 @@ - + @@ -2983,8 +3043,13 @@ + + + + 2 + - + @@ -3002,7 +3067,7 @@ - + @@ -3025,8 +3090,13 @@ + + + + 2 + - + @@ -3044,7 +3114,7 @@ - + @@ -3067,8 +3137,13 @@ + + + + 2 + - + @@ -3086,7 +3161,7 @@ - + @@ -3109,8 +3184,13 @@ + + + + 2 + - + @@ -3128,7 +3208,7 @@ - + @@ -4222,7 +4302,7 @@ - -15 + -15 4 @@ -4444,7 +4524,7 @@ - 1 + 0.40000000596046448 diff --git a/src/Game/Game.cpp b/src/Game/Game.cpp index 8c6e653e..b4c1a71d 100644 --- a/src/Game/Game.cpp +++ b/src/Game/Game.cpp @@ -10,6 +10,7 @@ #include "Systems/SpawnerSystem.h" #include "Systems/PlayerSpawnSystem.h" #include "Systems/PlayerDeathSystem.h" +#include "Systems/FloatingEffectSystem.h" #include "Core/EntityFileWriter.h" #include "Game/Systems/CapturePointSystem.h" #include "Game/Systems/CapturePointHUDSystem.h" @@ -120,6 +121,7 @@ Game::Game(int argc, char* argv[]) ++updateOrderLevel; m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); + m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); From 8b66d29adcb75311b27c4c98480f4dcf3145a406 Mon Sep 17 00:00:00 2001 From: Tleety Date: Wed, 2 Mar 2016 17:32:45 +0100 Subject: [PATCH 086/130] Skeleton system for Boost icons --- include/Game/Systems/BoostIconsHUDSystem.h | 17 +++++++++++++++++ src/Game/Game.cpp | 2 ++ src/Game/Systems/BoostIconsHUDSystem.cpp | 6 ++++++ 3 files changed, 25 insertions(+) create mode 100644 include/Game/Systems/BoostIconsHUDSystem.h create mode 100644 src/Game/Systems/BoostIconsHUDSystem.cpp diff --git a/include/Game/Systems/BoostIconsHUDSystem.h b/include/Game/Systems/BoostIconsHUDSystem.h new file mode 100644 index 00000000..fbcdfc16 --- /dev/null +++ b/include/Game/Systems/BoostIconsHUDSystem.h @@ -0,0 +1,17 @@ +#ifndef BoostIconsHUDSystem_h__ +#define BoostIconsHUDSystem_h__ + +#include "../../Engine/Core/System.h" +#include "../../Engine/GLM.h" + +class BoostIconsHUDSystem : public ImpureSystem +{ +public: + BoostIconsHUDSystem(SystemParams params) + : System(params) + { } + + virtual void Update(double dt) override; +}; + +#endif \ No newline at end of file diff --git a/src/Game/Game.cpp b/src/Game/Game.cpp index 8c6e653e..c3f1e439 100644 --- a/src/Game/Game.cpp +++ b/src/Game/Game.cpp @@ -28,6 +28,7 @@ #include "Game/Systems/CapturePointArrowHUDSystem.h" #include "Game/Systems/KillFeedSystem.h" #include "Game/Systems/BoostSystem.h" +#include "Game/Systems/BoostIconsHUDSystem.h" #include "GUI/ButtonSystem.h" #include "GUI/MainMenuSystem.h" @@ -146,6 +147,7 @@ Game::Game(int argc, char* argv[]) m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel, m_Renderer); m_SystemPipeline->AddSystem(updateOrderLevel, m_Renderer); + m_SystemPipeline->AddSystem(updateOrderLevel); // Populate Octree with collidables ++updateOrderLevel; m_SystemPipeline->AddSystem(updateOrderLevel, m_OctreeCollision, "Collidable"); diff --git a/src/Game/Systems/BoostIconsHUDSystem.cpp b/src/Game/Systems/BoostIconsHUDSystem.cpp new file mode 100644 index 00000000..6d181233 --- /dev/null +++ b/src/Game/Systems/BoostIconsHUDSystem.cpp @@ -0,0 +1,6 @@ +#include "Game/Systems/BoostIconsHUDSystem.h" + +void BoostIconsHUDSystem::Update(double dt) +{ + //Logic here +} From 267c007291997ff11271364d707e5937f4d0945d Mon Sep 17 00:00:00 2001 From: stiffly Date: Wed, 2 Mar 2016 17:39:27 +0100 Subject: [PATCH 087/130] Removed unnecessary comments, variables and functions. --- include/Engine/Input/FirstPersonInputController.h | 11 +++++------ src/Engine/Network/Server.cpp | 2 +- src/Game/Systems/PlayerMovementSystem.cpp | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/include/Engine/Input/FirstPersonInputController.h b/include/Engine/Input/FirstPersonInputController.h index efa3c38e..7ed85c84 100644 --- a/include/Engine/Input/FirstPersonInputController.h +++ b/include/Engine/Input/FirstPersonInputController.h @@ -27,7 +27,7 @@ public: virtual bool OnCommand(const Events::InputCommand& e) override; virtual void Reset(); - void AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer, double& assaultDashCoolDownTimer, EntityWrapper player); + void AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer, double& assaultDashCoolDownTimer, EntityID playerID); virtual bool AssaultDashDoubleTapped() const { return m_AssaultDashDoubleTapped; } virtual bool PlayerIsDashing() const { return m_PlayerIsDashing; } @@ -56,7 +56,6 @@ protected: bool m_MovementKeyDown = false; bool m_SpecialAbilityKeyDown = false; int m_NumberOfMovementKeysDown = 0; - void spawnDashEffect(); EventRelay m_ELockMouse; bool OnLockMouse(const Events::LockMouse& e); @@ -192,7 +191,7 @@ bool FirstPersonInputController::OnLockMouse(const Events::LockMou } template -void FirstPersonInputController::AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer, double& assaultDashCoolDownTimer, EntityWrapper player) { +void FirstPersonInputController::AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer, double& assaultDashCoolDownTimer, EntityID playerID) { m_AssaultDashDoubleTapDeltaTime += dt; m_DashEffectResetTimer += dt; assaultDashCoolDownTimer -= dt; @@ -201,7 +200,7 @@ void FirstPersonInputController::AssaultDashCheck(double dt, bool m_PlayerIsDashing = true; if (m_DashEffectResetTimer > 0.05) { Events::DashAbility e; - e.Player = player.ID; + e.Player = playerID; m_EventBroker->Publish(e); m_DashEffectResetTimer = 0.0; } @@ -217,7 +216,7 @@ void FirstPersonInputController::AssaultDashCheck(double dt, bool m_AssaultDashDoubleTapped = true; m_AssaultDashDoubleTapDeltaTime = 0.f; Events::DashAbility e; - e.Player = player.ID; + e.Player = playerID; m_EventBroker->Publish(e); return; } @@ -249,7 +248,7 @@ void FirstPersonInputController::AssaultDashCheck(double dt, bool assaultDashCoolDownTimer = assaultDashCoolDownMaxTimer; Events::DashAbility e; - e.Player = player.ID; + e.Player = playerID; m_EventBroker->Publish(e); } diff --git a/src/Engine/Network/Server.cpp b/src/Engine/Network/Server.cpp index 7ba54ec4..68c00fbe 100644 --- a/src/Engine/Network/Server.cpp +++ b/src/Engine/Network/Server.cpp @@ -632,7 +632,7 @@ bool Server::shouldSendToClient(EntityWrapper childEntity) } return childEntity.HasComponent("Player") || childEntity.FirstParentWithComponent("Player").Valid() || childEntity.HasComponent("CapturePoint") || childEntity.HasComponent("HealthPickup") - || childEntity.HasComponent("AmmoPickup")/* || childEntity.Name() == "DashEffect"*/; + || childEntity.HasComponent("AmmoPickup"); } PlayerID Server::GetPlayerIDFromEndpoint() diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index 1332ca82..9afc9c8c 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -73,7 +73,7 @@ void PlayerMovementSystem::updateMovementControllers(double dt) ComponentWrapper cPhysics = player["Physics"]; //Assault Dash Check if (player.HasComponent("DashAbility")) { - controller->AssaultDashCheck(dt, ((glm::vec3)cPhysics["Velocity"]).y != 0.0f, player["DashAbility"]["CoolDownMaxTimer"], player["DashAbility"]["CoolDownTimer"], player); + controller->AssaultDashCheck(dt, ((glm::vec3)cPhysics["Velocity"]).y != 0.0f, player["DashAbility"]["CoolDownMaxTimer"], player["DashAbility"]["CoolDownTimer"], player.ID); } wishDirection = controller->Movement() * glm::inverse(glm::quat(ori)); //this makes sure you can only dash in the 4 directions: forw,backw,left,right From e56f203f7cfb8bcfa4018e2696dbcc1e1c0a98e0 Mon Sep 17 00:00:00 2001 From: antc13 Date: Wed, 2 Mar 2016 17:42:11 +0100 Subject: [PATCH 088/130] Removed unnecessary comment & added FloatingEffect to Schema/Types/Entity.xsd --- include/Game/Systems/FloatingEffectSystem.h | 1 - resources/Schema/Types/Entity.xsd | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/include/Game/Systems/FloatingEffectSystem.h b/include/Game/Systems/FloatingEffectSystem.h index 2462e029..56931001 100644 --- a/include/Game/Systems/FloatingEffectSystem.h +++ b/include/Game/Systems/FloatingEffectSystem.h @@ -13,7 +13,6 @@ public: { ComponentWrapper& transform = m_World->GetComponent(component.EntityID, "Transform"); (double&)component["Time"] += dt; - //(double)component["Amplitude"] * glm::sin((glm::two_pi() / (double)component["Period"]) * (double)component["Time"]); (glm::vec3&)transform["Position"] = (float)(double)component["Amplitude"] * glm::sin((glm::two_pi() / (float)(double)component["Period"]) * (float)(double)component["Time"]) * (glm::vec3)component["Axis"]; } diff --git a/resources/Schema/Types/Entity.xsd b/resources/Schema/Types/Entity.xsd index 61d8e520..e2ab39e5 100644 --- a/resources/Schema/Types/Entity.xsd +++ b/resources/Schema/Types/Entity.xsd @@ -53,6 +53,7 @@ + From e9bbb5ed2a4adc2116764eaac835e98bee58803d Mon Sep 17 00:00:00 2001 From: viktorljung Date: Wed, 2 Mar 2016 17:42:55 +0100 Subject: [PATCH 089/130] Fixed BlendTree crash when animation nodes are null --- src/Engine/Rendering/BlendTree.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/Engine/Rendering/BlendTree.cpp b/src/Engine/Rendering/BlendTree.cpp index cb7ffa69..8b044134 100644 --- a/src/Engine/Rendering/BlendTree.cpp +++ b/src/Engine/Rendering/BlendTree.cpp @@ -142,9 +142,13 @@ BlendTree::Node* BlendTree::FillTreeByName(Node* parentNode, std::string name, E } else if (node->Weight == 0.f) { node->Child[1] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose2"], childEntity); }*/ + + if(node->Child[0] == nullptr && node->Child[1] == nullptr) { + return nullptr; + } else { + return node; + } - - return node; } else if (childEntity.HasComponent("BlendOverride")) { Node* node = new Node(); node->Entity = childEntity; @@ -153,7 +157,12 @@ BlendTree::Node* BlendTree::FillTreeByName(Node* parentNode, std::string name, E node->Type = NodeType::Override; node->Child[0] = FillTreeByName(node, (std::string)childEntity["BlendOverride"]["Master"], childEntity); node->Child[1] = FillTreeByName(node, (std::string)childEntity["BlendOverride"]["Slave"], childEntity); - return node; + + if (node->Child[0] == nullptr && node->Child[1] == nullptr) { + return nullptr; + } else { + return node; + } } else if (childEntity.HasComponent("BlendAdditive")) { Node* node = new Node(); node->Entity = childEntity; @@ -162,7 +171,12 @@ BlendTree::Node* BlendTree::FillTreeByName(Node* parentNode, std::string name, E node->Type = NodeType::Additive; node->Child[0] = FillTreeByName(node, (std::string)childEntity["BlendAdditive"]["Adder"], childEntity); node->Child[1] = FillTreeByName(node, (std::string)childEntity["BlendAdditive"]["Receiver"], childEntity); - return node; + + if(node->Child[0] == nullptr && node->Child[1] == nullptr) { + return nullptr; + } else { + return node; + } } @@ -252,7 +266,6 @@ void BlendTree::Blend(std::map& pose) if(currentNode->Pose.size() == 0) { if (currentNode->Child[0] != nullptr && currentNode->Child[1] != nullptr) { if (currentNode->Child[0]->Pose.size() != 0 && currentNode->Child[1]->Pose.size() != 0) { - switch (currentNode->Type) { case BlendTree::NodeType::Additive: currentNode->Pose = m_Skeleton->BlendPoseAdditive(currentNode->Child[0]->Pose, currentNode->Child[1]->Pose); From 3094dd301bd4415b97892574ef3e4da1fd70f124 Mon Sep 17 00:00:00 2001 From: antc13 Date: Wed, 2 Mar 2016 17:47:22 +0100 Subject: [PATCH 090/130] Added a default value to Position in FloatingEffect.xml --- resources/Schema/Components/FloatingEffect.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/Schema/Components/FloatingEffect.xml b/resources/Schema/Components/FloatingEffect.xml index 661e4ae4..f1fd237a 100644 --- a/resources/Schema/Components/FloatingEffect.xml +++ b/resources/Schema/Components/FloatingEffect.xml @@ -4,4 +4,5 @@ 1 + \ No newline at end of file From 7af17049e9489a0df32418da8dfe994c75c862dc Mon Sep 17 00:00:00 2001 From: Tleety Date: Wed, 2 Mar 2016 18:13:09 +0100 Subject: [PATCH 091/130] BoostIcons should now track correctly --- include/Game/Systems/BoostIconsHUDSystem.h | 6 ++-- src/Game/Systems/BoostIconsHUDSystem.cpp | 40 ++++++++++++++++++++-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/include/Game/Systems/BoostIconsHUDSystem.h b/include/Game/Systems/BoostIconsHUDSystem.h index fbcdfc16..d8de777d 100644 --- a/include/Game/Systems/BoostIconsHUDSystem.h +++ b/include/Game/Systems/BoostIconsHUDSystem.h @@ -4,14 +4,16 @@ #include "../../Engine/Core/System.h" #include "../../Engine/GLM.h" -class BoostIconsHUDSystem : public ImpureSystem +class BoostIconsHUDSystem : public PureSystem { public: BoostIconsHUDSystem(SystemParams params) : System(params) + , PureSystem("BoostIconsHUD") { } - virtual void Update(double dt) override; + virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& capturePoint, double dt) override; + }; #endif \ No newline at end of file diff --git a/src/Game/Systems/BoostIconsHUDSystem.cpp b/src/Game/Systems/BoostIconsHUDSystem.cpp index 6d181233..f83278ff 100644 --- a/src/Game/Systems/BoostIconsHUDSystem.cpp +++ b/src/Game/Systems/BoostIconsHUDSystem.cpp @@ -1,6 +1,42 @@ #include "Game/Systems/BoostIconsHUDSystem.h" -void BoostIconsHUDSystem::Update(double dt) +void BoostIconsHUDSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& capturePoint, double dt) { - //Logic here + EntityWrapper assaultEntity = entity.FirstChildByName("Assault"); + EntityWrapper defenderEntity = entity.FirstChildByName("Defender"); + EntityWrapper sniperEntity = entity.FirstChildByName("Sniper"); + + if(assaultEntity.Valid()) { + if (assaultEntity.HasComponent("Fill")) { + EntityWrapper parentWithAssaultBoost = assaultEntity.FirstParentWithComponent("BoostAssault"); + if (parentWithAssaultBoost.Valid()) { + (double&)assaultEntity["Fill"]["Percentage"] = 1.0; + } else { + (double&)assaultEntity["Fill"]["Percentage"] = 0.0; + } + } + } + + if (defenderEntity.Valid()) { + if (defenderEntity.HasComponent("Fill")) { + EntityWrapper parentWithAssaultBoost = defenderEntity.FirstParentWithComponent("BoostDefender"); + if (parentWithAssaultBoost.Valid()) { + (double&)defenderEntity["Fill"]["Percentage"] = 1.0; + } else { + (double&)defenderEntity["Fill"]["Percentage"] = 0.0; + } + } + } + + if (sniperEntity.Valid()) { + if (sniperEntity.HasComponent("Fill")) { + EntityWrapper parentWithAssaultBoost = sniperEntity.FirstParentWithComponent("BoostSniper"); + if (parentWithAssaultBoost.Valid()) { + (double&)sniperEntity["Fill"]["Percentage"] = 1.0; + } else { + (double&)sniperEntity["Fill"]["Percentage"] = 0.0; + } + } + } } + From 62c8196ad4395bce57e7071e22230552359882d6 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Wed, 2 Mar 2016 18:38:49 +0100 Subject: [PATCH 092/130] Created World::Merge which will merge a world into another one --- include/Engine/Core/World.h | 8 ++++++-- src/Engine/Core/World.cpp | 39 ++++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/include/Engine/Core/World.h b/include/Engine/Core/World.h index d8e2c7ba..28c96303 100644 --- a/include/Engine/Core/World.h +++ b/include/Engine/Core/World.h @@ -19,13 +19,13 @@ public: World(const World& other); // Create empty entity - EntityID CreateEntity(EntityID parent = 0); + EntityID CreateEntity(EntityID parent = EntityID_Invalid); // Delete entity and all components within void DeleteEntity(EntityID entity); // Check if an entity exists bool ValidEntity(EntityID entity) const; // Register a component type and allocate space for it - void RegisterComponent(ComponentInfo& ci); + void RegisterComponent(const ComponentInfo& ci); // Attach a component to an entity and fill it with default values ComponentWrapper AttachComponent(EntityID entity, const std::string& componentType); // Check if an entity has a component @@ -53,6 +53,10 @@ public: // Get the first entity in the world with the name. EntityWrapper GetFirstEntityByName(const std::string& name); + // Merge another world into this one + // Returns a map that maps entities from the other world to their copies in this one + std::unordered_map Merge(World& other); + private: EventBroker* m_EventBroker = nullptr; EntityID m_CurrentEntityID = 0; diff --git a/src/Engine/Core/World.cpp b/src/Engine/Core/World.cpp index 65bc60d2..96c4660d 100644 --- a/src/Engine/Core/World.cpp +++ b/src/Engine/Core/World.cpp @@ -45,7 +45,7 @@ bool World::ValidEntity(EntityID entity) const return m_EntityParents.find(entity) != m_EntityParents.end(); } -void World::RegisterComponent(ComponentInfo& ci) +void World::RegisterComponent(const ComponentInfo& ci) { if (m_ComponentPools.find(ci.Name) == m_ComponentPools.end()) { m_ComponentPools[ci.Name] = new ComponentPool(ci); @@ -169,6 +169,43 @@ EntityWrapper World::GetFirstEntityByName(const std::string& name) return EntityWrapper::Invalid; } +std::unordered_map World::Merge(World& other) +{ + std::unordered_map oldToNew; + + // Create new entities + for (auto& kv : other.m_EntityParents) { + EntityID entity = kv.first; + + EntityID newEntity = CreateEntity(); + SetName(newEntity, other.GetName(entity)); + oldToNew[entity] = newEntity; + } + // Fix relationships + for (auto& kv : other.m_EntityParents) { + EntityID entity = kv.first; + EntityID parent = kv.second; + SetParent(oldToNew.at(entity), oldToNew.at(parent)); + } + + // Transfer components + for (auto& kv : other.m_ComponentPools) { + auto& componentType = kv.first; + ComponentPool* pool = kv.second; + // Register pool if it's not present in world + if (m_ComponentPools.count(componentType) == 0) { + RegisterComponent(pool->ComponentInfo()); + } + // Copy components + for (auto component : *pool) { + ComponentWrapper newComponent = AttachComponent(oldToNew.at(component.EntityID), componentType); + component.Copy(newComponent); + } + } + + return oldToNew; +} + EntityID World::generateEntityID() { // TODO: Make EntityID generation smarter From 26d6546d795b0a840b06e1c423180205a4e942e0 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Wed, 2 Mar 2016 18:42:11 +0100 Subject: [PATCH 093/130] Renamed EntityFile to EntityXMLFile to be able to separate file parsing from entity creation --- .../Core/{EntityFile.h => EntityXMLFile.h} | 6 ++--- ...tityFileParser.h => EntityXMLFileParser.h} | 8 +++--- ...rocessor.h => EntityXMLFilePreprocessor.h} | 8 +++--- ...tityFileWriter.h => EntityXMLFileWriter.h} | 6 ++--- include/Engine/Editor/EditorSystem.h | 6 ++--- include/Game/Game.h | 6 ++--- include/Game/Systems/AmmoPickupSystem.h | 2 +- include/Game/Systems/BoostSystem.h | 2 +- include/Game/Systems/DamageIndicatorSystem.h | 2 +- include/Game/Systems/PickupSpawnSystem.h | 2 +- include/Game/Systems/PlayerDeathSystem.h | 4 +-- include/Game/Systems/PlayerMovementSystem.h | 4 +-- include/Game/Systems/SpawnerSystem.h | 2 +- include/Game/Systems/Weapon/WeaponSystem.h | 4 +-- .../{EntityFile.cpp => EntityXMLFile.cpp} | 18 ++++++------- ...FileParser.cpp => EntityXMLFileParser.cpp} | 26 +++++++++---------- ...ssor.cpp => EntityXMLFilePreprocessor.cpp} | 24 ++++++++--------- ...FileWriter.cpp => EntityXMLFileWriter.cpp} | 10 +++---- src/Engine/Editor/EditorSystem.cpp | 8 +++--- src/Game/Game.cpp | 10 +++---- src/Game/Systems/AmmoPickupSystem.cpp | 4 +-- src/Game/Systems/BoostSystem.cpp | 4 +-- src/Game/Systems/DamageIndicatorSystem.cpp | 10 +++---- src/Game/Systems/PickupSpawnSystem.cpp | 4 +-- src/Game/Systems/PlayerDeathSystem.cpp | 4 +-- src/Game/Systems/PlayerMovementSystem.cpp | 8 +++--- src/Game/Systems/SpawnerSystem.cpp | 4 +-- src/Tests/CapturePointTest.cpp | 10 +++---- src/Tests/CapturePointTest.h | 8 +++--- src/Tests/HealthSystemTest.cpp | 8 +++--- src/Tests/HealthSystemTest.h | 2 +- src/Tests/PickupSpawnTest.cpp | 8 +++--- src/Tests/PickupSpawnTest.h | 10 +++---- 33 files changed, 121 insertions(+), 121 deletions(-) rename include/Engine/Core/{EntityFile.h => EntityXMLFile.h} (98%) rename include/Engine/Core/{EntityFileParser.h => EntityXMLFileParser.h} (86%) rename include/Engine/Core/{EntityFilePreprocessor.h => EntityXMLFilePreprocessor.h} (87%) rename include/Engine/Core/{EntityFileWriter.h => EntityXMLFileWriter.h} (92%) rename src/Engine/Core/{EntityFile.cpp => EntityXMLFile.cpp} (94%) rename src/Engine/Core/{EntityFileParser.cpp => EntityXMLFileParser.cpp} (59%) rename src/Engine/Core/{EntityFilePreprocessor.cpp => EntityXMLFilePreprocessor.cpp} (93%) rename src/Engine/Core/{EntityFileWriter.cpp => EntityXMLFileWriter.cpp} (94%) diff --git a/include/Engine/Core/EntityFile.h b/include/Engine/Core/EntityXMLFile.h similarity index 98% rename from include/Engine/Core/EntityFile.h rename to include/Engine/Core/EntityXMLFile.h index 538e9047..6dcc74c5 100644 --- a/include/Engine/Core/EntityFile.h +++ b/include/Engine/Core/EntityXMLFile.h @@ -134,13 +134,13 @@ private: } }; -class EntityFile : public Resource +class EntityXMLFile : public Resource { friend class ResourceManager; friend class EntityFileSAXHandler; private: - EntityFile(boost::filesystem::path path); - ~EntityFile(); + EntityXMLFile(boost::filesystem::path path); + ~EntityXMLFile(); public: static unsigned int GetTypeStride(std::string typeName); diff --git a/include/Engine/Core/EntityFileParser.h b/include/Engine/Core/EntityXMLFileParser.h similarity index 86% rename from include/Engine/Core/EntityFileParser.h rename to include/Engine/Core/EntityXMLFileParser.h index b4eee5b2..c058640f 100644 --- a/include/Engine/Core/EntityFileParser.h +++ b/include/Engine/Core/EntityXMLFileParser.h @@ -1,18 +1,18 @@ #ifndef EntityFileParser_h__ #define EntityFileParser_h__ -#include "EntityFile.h" +#include "EntityXMLFile.h" #include "World.h" -class EntityFileParser +class EntityXMLFileParser { public: - EntityFileParser(const EntityFile* entityFile); + EntityXMLFileParser(const EntityXMLFile* entityFile); EntityID MergeEntities(World* world, EntityID baseParent = EntityID_Invalid); private: - const EntityFile* m_EntityFile; + const EntityXMLFile* m_EntityFile; EntityFileHandler m_Handler; World* m_World = nullptr; EntityID m_FirstEntity = EntityID_Invalid; diff --git a/include/Engine/Core/EntityFilePreprocessor.h b/include/Engine/Core/EntityXMLFilePreprocessor.h similarity index 87% rename from include/Engine/Core/EntityFilePreprocessor.h rename to include/Engine/Core/EntityXMLFilePreprocessor.h index b46bd383..45880835 100644 --- a/include/Engine/Core/EntityFilePreprocessor.h +++ b/include/Engine/Core/EntityXMLFilePreprocessor.h @@ -17,17 +17,17 @@ #include "Util/XercesString.h" #include "ResourceManager.h" #include "World.h" -#include "EntityFile.h" +#include "EntityXMLFile.h" -class EntityFilePreprocessor +class EntityXMLFilePreprocessor { public: - EntityFilePreprocessor(const EntityFile* entityFile); + EntityXMLFilePreprocessor(const EntityXMLFile* entityFile); void RegisterComponents(World* world); private: - const EntityFile* m_EntityFile; + const EntityXMLFile* m_EntityFile; std::map m_ComponentCounts; std::map m_ComponentInfo; diff --git a/include/Engine/Core/EntityFileWriter.h b/include/Engine/Core/EntityXMLFileWriter.h similarity index 92% rename from include/Engine/Core/EntityFileWriter.h rename to include/Engine/Core/EntityXMLFileWriter.h index b75bc145..9b100670 100644 --- a/include/Engine/Core/EntityFileWriter.h +++ b/include/Engine/Core/EntityXMLFileWriter.h @@ -8,13 +8,13 @@ #include #include "Util/XercesString.h" -#include "EntityFile.h" +#include "EntityXMLFile.h" #include "World.h" -class EntityFileWriter +class EntityXMLFileWriter { public: - EntityFileWriter(boost::filesystem::path file) + EntityXMLFileWriter(boost::filesystem::path file) : m_FilePath(file) { using namespace xercesc; diff --git a/include/Engine/Editor/EditorSystem.h b/include/Engine/Editor/EditorSystem.h index 06ee53b6..b565367a 100644 --- a/include/Engine/Editor/EditorSystem.h +++ b/include/Engine/Editor/EditorSystem.h @@ -5,9 +5,9 @@ #include "../Core/World.h" #include "../Core/SystemPipeline.h" #include "../Core/ResourceManager.h" -#include "../Core/EntityFilePreprocessor.h" -#include "../Core/EntityFileParser.h" -#include "../Core/EntityFileWriter.h" +#include "../Core/EntityXMLFilePreprocessor.h" +#include "../Core/EntityXMLFileParser.h" +#include "../Core/EntityXMLFileWriter.h" #include "../Core/EMousePress.h" #include "../Input/EInputCommand.h" #include "EditorGUI.h" diff --git a/include/Game/Game.h b/include/Game/Game.h index 06fd4703..4d173b48 100644 --- a/include/Game/Game.h +++ b/include/Game/Game.h @@ -13,13 +13,13 @@ #include "Input/KeyboardInputHandler.h" #include "Input/MouseInputHandler.h" #include "Core/EKeyDown.h" -#include "Core/EntityFilePreprocessor.h" +#include "Core/EntityXMLFilePreprocessor.h" #include "Core/SystemPipeline.h" #include "Systems/ExplosionEffectSystem.h" #include "Editor/EditorSystem.h" -#include "Core/EntityFile.h" +#include "Core/EntityXMLFile.h" #include "Rendering/RenderSystem.h" -#include "Core/EntityFileParser.h" +#include "Core/EntityXMLFileParser.h" #include "Core/Octree.h" #include "Rendering/Font.h" #include "Systems/InterpolationSystem.h" diff --git a/include/Game/Systems/AmmoPickupSystem.h b/include/Game/Systems/AmmoPickupSystem.h index 7917e765..8e5c4f1d 100644 --- a/include/Game/Systems/AmmoPickupSystem.h +++ b/include/Game/Systems/AmmoPickupSystem.h @@ -4,7 +4,7 @@ #include "Core/System.h" #include "Core/Transform.h" #include "Core/ResourceManager.h" -#include "Core/EntityFileParser.h" +#include "Core/EntityXMLFileParser.h" #include "Core/EPickupSpawned.h" #include "Core/EAmmoPickup.h" #include "Engine/Collision/ETrigger.h" diff --git a/include/Game/Systems/BoostSystem.h b/include/Game/Systems/BoostSystem.h index f82707ab..525918a4 100644 --- a/include/Game/Systems/BoostSystem.h +++ b/include/Game/Systems/BoostSystem.h @@ -3,7 +3,7 @@ #include "Core/System.h" #include "Core/ResourceManager.h" -#include "Core/EntityFileParser.h" +#include "Core/EntityXMLFileParser.h" #include "Core/EPlayerDamage.h" #include "Common.h" diff --git a/include/Game/Systems/DamageIndicatorSystem.h b/include/Game/Systems/DamageIndicatorSystem.h index ae9ba195..935089fa 100644 --- a/include/Game/Systems/DamageIndicatorSystem.h +++ b/include/Game/Systems/DamageIndicatorSystem.h @@ -4,7 +4,7 @@ #include "Core/System.h" #include "Core/Transform.h" #include "Core/ResourceManager.h" -#include "Core/EntityFileParser.h" +#include "Core/EntityXMLFileParser.h" #include "Core/EPlayerDamage.h" #include "Common.h" #include diff --git a/include/Game/Systems/PickupSpawnSystem.h b/include/Game/Systems/PickupSpawnSystem.h index be99141c..1151b487 100644 --- a/include/Game/Systems/PickupSpawnSystem.h +++ b/include/Game/Systems/PickupSpawnSystem.h @@ -4,7 +4,7 @@ #include "Core/System.h" #include "Core/Transform.h" #include "Core/ResourceManager.h" -#include "Core/EntityFileParser.h" +#include "Core/EntityXMLFileParser.h" #include "Core/EPickupSpawned.h" #include "Core/EPlayerHealthPickup.h" #include "Engine/Collision/ETrigger.h" diff --git a/include/Game/Systems/PlayerDeathSystem.h b/include/Game/Systems/PlayerDeathSystem.h index f32e32df..96ed2ab5 100644 --- a/include/Game/Systems/PlayerDeathSystem.h +++ b/include/Game/Systems/PlayerDeathSystem.h @@ -7,8 +7,8 @@ #include "Rendering/ESetCamera.h" #include "Core/ConfigFile.h" -#include "Core/EntityFile.h" -#include "Core/EntityFileParser.h" +#include "Core/EntityXMLFile.h" +#include "Core/EntityXMLFileParser.h" #include "Core/EPlayerDeath.h" #include "Core/EEntityDeleted.h" diff --git a/include/Game/Systems/PlayerMovementSystem.h b/include/Game/Systems/PlayerMovementSystem.h index cdf8ee22..8b6e4e54 100644 --- a/include/Game/Systems/PlayerMovementSystem.h +++ b/include/Game/Systems/PlayerMovementSystem.h @@ -7,8 +7,8 @@ #include "Events/EDoubleJump.h" #include "../Engine/Sound/EPlaySoundOnEntity.h" -#include "Core/EntityFile.h" -#include "Core/EntityFileParser.h" +#include "Core/EntityXMLFile.h" +#include "Core/EntityXMLFileParser.h" class PlayerMovementSystem : public ImpureSystem { diff --git a/include/Game/Systems/SpawnerSystem.h b/include/Game/Systems/SpawnerSystem.h index e4a44738..10817ef0 100644 --- a/include/Game/Systems/SpawnerSystem.h +++ b/include/Game/Systems/SpawnerSystem.h @@ -8,7 +8,7 @@ #include "Events/ESpawnerSpawn.h" #include "Core/Transform.h" #include "Core/ResourceManager.h" -#include "Core/EntityFileParser.h" +#include "Core/EntityXMLFileParser.h" class SpawnerSystem : public System { diff --git a/include/Game/Systems/Weapon/WeaponSystem.h b/include/Game/Systems/Weapon/WeaponSystem.h index b8278bc4..f6543ffb 100644 --- a/include/Game/Systems/Weapon/WeaponSystem.h +++ b/include/Game/Systems/Weapon/WeaponSystem.h @@ -9,8 +9,8 @@ #include "Core/EShoot.h" #include "Core/EPlayerSpawned.h" #include "Input/EInputCommand.h" -#include "Core/EntityFile.h" -#include "Core/EntityFileParser.h" +#include "Core/EntityXMLFile.h" +#include "Core/EntityXMLFileParser.h" #include "Core/Octree.h" #include "Collision/EntityAABB.h" #include "Systems/SpawnerSystem.h" diff --git a/src/Engine/Core/EntityFile.cpp b/src/Engine/Core/EntityXMLFile.cpp similarity index 94% rename from src/Engine/Core/EntityFile.cpp rename to src/Engine/Core/EntityXMLFile.cpp index 3987b092..b32d952d 100644 --- a/src/Engine/Core/EntityFile.cpp +++ b/src/Engine/Core/EntityXMLFile.cpp @@ -1,6 +1,6 @@ -#include "Core/EntityFile.h" +#include "Core/EntityXMLFile.h" -EntityFile::EntityFile(boost::filesystem::path path) +EntityXMLFile::EntityXMLFile(boost::filesystem::path path) : m_FilePath(path) { using namespace xercesc; @@ -9,14 +9,14 @@ EntityFile::EntityFile(boost::filesystem::path path) m_SAX2XMLReader = XMLReaderFactory::createXMLReader(XMLPlatformUtils::fgMemoryManager, m_GrammarPool); } -EntityFile::~EntityFile() +EntityXMLFile::~EntityXMLFile() { delete m_SAX2XMLReader; delete m_GrammarPool; xercesc::XMLPlatformUtils::Terminate(); } -void EntityFile::Parse(const EntityFileHandler* handler) const +void EntityXMLFile::Parse(const EntityFileHandler* handler) const { using namespace xercesc; @@ -28,7 +28,7 @@ void EntityFile::Parse(const EntityFileHandler* handler) const m_SAX2XMLReader->parse(m_FilePath.string().c_str()); } -void EntityFile::setReaderFeatures(xercesc::SAX2XMLReader* reader) +void EntityXMLFile::setReaderFeatures(xercesc::SAX2XMLReader* reader) { using namespace xercesc; reader->setFeature(XMLUni::fgXercesCacheGrammarFromParse, true); @@ -41,7 +41,7 @@ void EntityFile::setReaderFeatures(xercesc::SAX2XMLReader* reader) reader->setFeature(XMLUni::fgXercesIdentityConstraintChecking, true); } -unsigned int EntityFile::GetTypeStride(std::string typeName) +unsigned int EntityXMLFile::GetTypeStride(std::string typeName) { std::map typeStrides{ { "bool", sizeof(bool) }, @@ -59,7 +59,7 @@ unsigned int EntityFile::GetTypeStride(std::string typeName) return (it != typeStrides.end()) ? it->second : 0; } -void EntityFile::WriteAttributeData(char* outData, const ComponentInfo::Field_t& field, const std::map& attributes) +void EntityXMLFile::WriteAttributeData(char* outData, const ComponentInfo::Field_t& field, const std::map& attributes) { if (field.Type == "Vector") { glm::vec3 vec; @@ -86,7 +86,7 @@ void EntityFile::WriteAttributeData(char* outData, const ComponentInfo::Field_t& } } -void EntityFile::WriteValueData(char* outData, const ComponentInfo::Field_t& field, const char* valueData) +void EntityXMLFile::WriteValueData(char* outData, const ComponentInfo::Field_t& field, const char* valueData) { // Catch and ignore casting errors so whitespace around string enums won't mess anything up try { @@ -243,7 +243,7 @@ void EntityFileSAXHandler::onStartEntityRef(const xercesc::Attributes& attrs) std::string path = XS::ToString(attrs.getValue(XS::ToXMLCh("file"))); xercesc::SAX2XMLReader* reader = xercesc::XMLReaderFactory::createXMLReader(); - EntityFile::setReaderFeatures(reader); + EntityXMLFile::setReaderFeatures(reader); reader->setContentHandler(this); reader->setErrorHandler(this); reader->parse(path.c_str()); diff --git a/src/Engine/Core/EntityFileParser.cpp b/src/Engine/Core/EntityXMLFileParser.cpp similarity index 59% rename from src/Engine/Core/EntityFileParser.cpp rename to src/Engine/Core/EntityXMLFileParser.cpp index 2beaac14..9c79775c 100644 --- a/src/Engine/Core/EntityFileParser.cpp +++ b/src/Engine/Core/EntityXMLFileParser.cpp @@ -1,15 +1,15 @@ -#include "Core/EntityFileParser.h" +#include "Core/EntityXMLFileParser.h" -EntityFileParser::EntityFileParser(const EntityFile* entityFile) +EntityXMLFileParser::EntityXMLFileParser(const EntityXMLFile* entityFile) : m_EntityFile(entityFile) { - m_Handler.SetStartEntityCallback(std::bind(&EntityFileParser::onStartEntity, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); - m_Handler.SetStartComponentCallback(std::bind(&EntityFileParser::onStartComponent, this, std::placeholders::_1, std::placeholders::_2)); - m_Handler.SetStartFieldCallback(std::bind(&EntityFileParser::onStartComponentField, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); - m_Handler.SetStartFieldDataCallback(std::bind(&EntityFileParser::onFieldData, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); + m_Handler.SetStartEntityCallback(std::bind(&EntityXMLFileParser::onStartEntity, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); + m_Handler.SetStartComponentCallback(std::bind(&EntityXMLFileParser::onStartComponent, this, std::placeholders::_1, std::placeholders::_2)); + m_Handler.SetStartFieldCallback(std::bind(&EntityXMLFileParser::onStartComponentField, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); + m_Handler.SetStartFieldDataCallback(std::bind(&EntityXMLFileParser::onFieldData, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); } -EntityID EntityFileParser::MergeEntities(World* world, EntityID baseParent /*= EntityID_Invalid */) +EntityID EntityXMLFileParser::MergeEntities(World* world, EntityID baseParent /*= EntityID_Invalid */) { m_World = world; m_EntityIDMapper[0] = baseParent; @@ -17,7 +17,7 @@ EntityID EntityFileParser::MergeEntities(World* world, EntityID baseParent /*= E return m_FirstEntity; } -void EntityFileParser::onStartEntity(EntityID entity, EntityID parent, const std::string& name) +void EntityXMLFileParser::onStartEntity(EntityID entity, EntityID parent, const std::string& name) { EntityID realParent = m_EntityIDMapper.at(parent); EntityID realEntity = m_World->CreateEntity(realParent); @@ -31,7 +31,7 @@ void EntityFileParser::onStartEntity(EntityID entity, EntityID parent, const std //LOG_DEBUG("Created entity #%i (%i) with parent %i (%i)", entity, realEntity, parent, realParent); } -void EntityFileParser::onStartComponent(EntityID entity, const std::string& component) +void EntityXMLFileParser::onStartComponent(EntityID entity, const std::string& component) { if (m_World->GetComponentPools().count(component) != 0) { EntityID realEntity = m_EntityIDMapper.at(entity); @@ -42,7 +42,7 @@ void EntityFileParser::onStartComponent(EntityID entity, const std::string& comp //LOG_DEBUG("Attached component of type \"%s\" to entity #%i (%i)", component.c_str(), entity, realEntity); } -void EntityFileParser::onStartComponentField(EntityID entity, const std::string& componentType, const std::string& fieldName, const std::map& attributes) +void EntityXMLFileParser::onStartComponentField(EntityID entity, const std::string& componentType, const std::string& fieldName, const std::map& attributes) { if (m_World->GetComponentPools().count(componentType) == 0) { return; @@ -63,10 +63,10 @@ void EntityFileParser::onStartComponentField(EntityID entity, const std::string& //} char* data = component.Data + field.Offset; - EntityFile::WriteAttributeData(data, field, attributes); + EntityXMLFile::WriteAttributeData(data, field, attributes); } -void EntityFileParser::onFieldData(EntityID entity, const std::string& componentType, const std::string& fieldName, const char* fieldData) +void EntityXMLFileParser::onFieldData(EntityID entity, const std::string& componentType, const std::string& fieldName, const char* fieldData) { if (m_World->GetComponentPools().count(componentType) == 0) { return; @@ -80,5 +80,5 @@ void EntityFileParser::onFieldData(EntityID entity, const std::string& component auto& field = fieldIt->second; char* data = component.Data + field.Offset; - EntityFile::WriteValueData(data, field, fieldData); + EntityXMLFile::WriteValueData(data, field, fieldData); } diff --git a/src/Engine/Core/EntityFilePreprocessor.cpp b/src/Engine/Core/EntityXMLFilePreprocessor.cpp similarity index 93% rename from src/Engine/Core/EntityFilePreprocessor.cpp rename to src/Engine/Core/EntityXMLFilePreprocessor.cpp index 592daedb..9695509d 100644 --- a/src/Engine/Core/EntityFilePreprocessor.cpp +++ b/src/Engine/Core/EntityXMLFilePreprocessor.cpp @@ -1,10 +1,10 @@ -#include "Core/EntityFilePreprocessor.h" +#include "Core/EntityXMLFilePreprocessor.h" -EntityFilePreprocessor::EntityFilePreprocessor(const EntityFile* entityFile) +EntityXMLFilePreprocessor::EntityXMLFilePreprocessor(const EntityXMLFile* entityFile) : m_EntityFile(entityFile) { EntityFileHandler handler; - handler.SetStartComponentCallback(std::bind(&EntityFilePreprocessor::onStartComponent, this, std::placeholders::_1, std::placeholders::_2)); + handler.SetStartComponentCallback(std::bind(&EntityXMLFilePreprocessor::onStartComponent, this, std::placeholders::_1, std::placeholders::_2)); m_EntityFile->Parse(&handler); //LOG_DEBUG("___ COMPONENT DEFINITIONS ___"); @@ -28,20 +28,20 @@ EntityFilePreprocessor::EntityFilePreprocessor(const EntityFile* entityFile) parseDefaults(); } -void EntityFilePreprocessor::RegisterComponents(World* world) +void EntityXMLFilePreprocessor::RegisterComponents(World* world) { for (auto& kv : m_ComponentInfo) { world->RegisterComponent(kv.second); } } -void EntityFilePreprocessor::onStartComponent(EntityID entity, std::string type) +void EntityXMLFilePreprocessor::onStartComponent(EntityID entity, std::string type) { //LOG_DEBUG("Component: %s", type.c_str()); m_ComponentCounts[type]++; } -void EntityFilePreprocessor::parseComponentInfo() +void EntityXMLFilePreprocessor::parseComponentInfo() { using namespace xercesc; EntityFileXMLErrorHandler errorHandler; @@ -141,9 +141,9 @@ void EntityFilePreprocessor::parseComponentInfo() std::string baseType = XS::ToString(elementDeclaration->getTypeDefinition()->getBaseType()->getName()); std::string effectiveType = type; - unsigned int stride = EntityFile::GetTypeStride(type); + unsigned int stride = EntityXMLFile::GetTypeStride(type); if (stride == 0) { - stride = EntityFile::GetTypeStride(baseType); + stride = EntityXMLFile::GetTypeStride(baseType); if (stride == 0) { LOG_WARNING("Field \"%s\" in component \"%s\" uses unexpected field type \"%s\" with base type \"%s\". Skipping.", name.c_str(), compInfo.Name.c_str(), type.c_str(), baseType.c_str()); continue; @@ -196,7 +196,7 @@ void EntityFilePreprocessor::parseComponentInfo() } } -void EntityFilePreprocessor::parseDefaults() +void EntityXMLFilePreprocessor::parseDefaults() { using namespace xercesc; @@ -261,7 +261,7 @@ void EntityFilePreprocessor::parseDefaults() auto attribItem = attributeMap->item(i); attributes[XS::ToString(attribItem->getNodeName())] = XS::ToString(attribItem->getNodeValue()); } - EntityFile::WriteAttributeData(data, field, attributes); + EntityXMLFile::WriteAttributeData(data, field, attributes); } auto childNode = fieldElement->getFirstChild(); @@ -278,14 +278,14 @@ void EntityFilePreprocessor::parseDefaults() // Handle potential field values if (childNode->getNodeType() == DOMNode::TEXT_NODE) { char* cstrValue = XMLString::transcode(childNode->getNodeValue()); - EntityFile::WriteValueData(data, field, cstrValue); + EntityXMLFile::WriteValueData(data, field, cstrValue); XMLString::release(&cstrValue); } } } } -std::string EntityFilePreprocessor::parseAnnotationXML(const XMLCh* xml) +std::string EntityXMLFilePreprocessor::parseAnnotationXML(const XMLCh* xml) { using namespace xercesc; diff --git a/src/Engine/Core/EntityFileWriter.cpp b/src/Engine/Core/EntityXMLFileWriter.cpp similarity index 94% rename from src/Engine/Core/EntityFileWriter.cpp rename to src/Engine/Core/EntityXMLFileWriter.cpp index 06a3c4ca..a98d3fbd 100644 --- a/src/Engine/Core/EntityFileWriter.cpp +++ b/src/Engine/Core/EntityXMLFileWriter.cpp @@ -1,13 +1,13 @@ -#include "Core/EntityFileWriter.h" +#include "Core/EntityXMLFileWriter.h" #define X(str) XS::ToXMLCh(str) -void EntityFileWriter::WriteWorld(World* world) +void EntityXMLFileWriter::WriteWorld(World* world) { WriteEntity(world, 0); } -void EntityFileWriter::WriteEntity(World* world, EntityID entity) +void EntityXMLFileWriter::WriteEntity(World* world, EntityID entity) { using namespace xercesc; DOMDocument* doc = m_DOMImplementation->createDocument(nullptr, X("Entity"), nullptr); @@ -41,7 +41,7 @@ void EntityFileWriter::WriteEntity(World* world, EntityID entity) doc->release(); } -void EntityFileWriter::appendEntityChildren(xercesc::DOMElement* parentElement, const World* world, EntityID entity) +void EntityXMLFileWriter::appendEntityChildren(xercesc::DOMElement* parentElement, const World* world, EntityID entity) { using namespace xercesc; DOMDocument* doc = parentElement->getOwnerDocument(); @@ -67,7 +67,7 @@ void EntityFileWriter::appendEntityChildren(xercesc::DOMElement* parentElement, } } -void EntityFileWriter::appentEntityComponents(xercesc::DOMElement* parentElement, const World* world, EntityID entity) +void EntityXMLFileWriter::appentEntityComponents(xercesc::DOMElement* parentElement, const World* world, EntityID entity) { using namespace xercesc; DOMDocument* doc = parentElement->getOwnerDocument(); diff --git a/src/Engine/Editor/EditorSystem.cpp b/src/Engine/Editor/EditorSystem.cpp index b0929df9..3e664161 100644 --- a/src/Engine/Editor/EditorSystem.cpp +++ b/src/Engine/Editor/EditorSystem.cpp @@ -129,7 +129,7 @@ void EditorSystem::OnEntitySelected(EntityWrapper entity) void EditorSystem::OnEntitySave(EntityWrapper entity, boost::filesystem::path filePath) { - EntityFileWriter writer(filePath); + EntityXMLFileWriter writer(filePath); writer.WriteEntity(entity.World, entity.ID); } @@ -259,10 +259,10 @@ EntityWrapper EditorSystem::importEntity(EntityWrapper parent, boost::filesystem } try { - auto entityFile = ResourceManager::Load(filePath.string()); - EntityFilePreprocessor fpp(entityFile); + auto entityFile = ResourceManager::Load(filePath.string()); + EntityXMLFilePreprocessor fpp(entityFile); fpp.RegisterComponents(parent.World); - EntityFileParser fp(entityFile); + EntityXMLFileParser fp(entityFile); EntityID newEntity = fp.MergeEntities(parent.World, parent.ID); return EntityWrapper(parent.World, newEntity); } catch (const std::exception& e) { diff --git a/src/Game/Game.cpp b/src/Game/Game.cpp index b4c1a71d..9c9228b9 100644 --- a/src/Game/Game.cpp +++ b/src/Game/Game.cpp @@ -11,7 +11,7 @@ #include "Systems/PlayerSpawnSystem.h" #include "Systems/PlayerDeathSystem.h" #include "Systems/FloatingEffectSystem.h" -#include "Core/EntityFileWriter.h" +#include "Core/EntityXMLFileWriter.h" #include "Game/Systems/CapturePointSystem.h" #include "Game/Systems/CapturePointHUDSystem.h" #include "Game/Systems/PickupSpawnSystem.h" @@ -44,7 +44,7 @@ Game::Game(int argc, char* argv[]) ResourceManager::RegisterType("Texture"); ResourceManager::RegisterType("Png"); ResourceManager::RegisterType("ShaderProgram"); - ResourceManager::RegisterType("EntityFile"); + ResourceManager::RegisterType("EntityFile"); ResourceManager::RegisterType("FontFile"); m_Config = ResourceManager::Load("Config.ini"); @@ -80,10 +80,10 @@ Game::Game(int argc, char* argv[]) m_World = new World(m_EventBroker); std::string mapToLoad = m_Config->Get("Debug.LoadMap", ""); if (!mapToLoad.empty()) { - auto file = ResourceManager::Load(mapToLoad); - EntityFilePreprocessor fpp(file); + auto file = ResourceManager::Load(mapToLoad); + EntityXMLFilePreprocessor fpp(file); fpp.RegisterComponents(m_World); - EntityFileParser fp(file); + EntityXMLFileParser fp(file); fp.MergeEntities(m_World); } diff --git a/src/Game/Systems/AmmoPickupSystem.cpp b/src/Game/Systems/AmmoPickupSystem.cpp index 74d86f70..e3051efe 100644 --- a/src/Game/Systems/AmmoPickupSystem.cpp +++ b/src/Game/Systems/AmmoPickupSystem.cpp @@ -20,8 +20,8 @@ void AmmoPickupSystem::Update(double dt) auto& somePickup = *it; somePickup.DecreaseThisRespawnTimer -= dt; if (somePickup.DecreaseThisRespawnTimer < 0.0) { - auto entityFile = ResourceManager::Load("Schema/Entities/AmmoPickup.xml"); - EntityFileParser parser(entityFile); + auto entityFile = ResourceManager::Load("Schema/Entities/AmmoPickup.xml"); + EntityXMLFileParser parser(entityFile); EntityID ammoPickupID = parser.MergeEntities(m_World); //let the world know a pickup has spawned diff --git a/src/Game/Systems/BoostSystem.cpp b/src/Game/Systems/BoostSystem.cpp index 9e4d6968..7f335d1f 100644 --- a/src/Game/Systems/BoostSystem.cpp +++ b/src/Game/Systems/BoostSystem.cpp @@ -38,8 +38,8 @@ bool BoostSystem::OnPlayerDamage(Events::PlayerDamage& e) m_World->DeleteEntity(playerBoostAssaultEntity.ID); } //load boost XML file, set it entity parented with the victim player - auto entityFile = ResourceManager::Load(classXML); - EntityFileParser parser(entityFile); + auto entityFile = ResourceManager::Load(classXML); + EntityXMLFileParser parser(entityFile); EntityID boostAssaultEntity = parser.MergeEntities(m_World); m_World->SetName(boostAssaultEntity, className); m_World->SetParent(boostAssaultEntity, e.Victim.ID); diff --git a/src/Game/Systems/DamageIndicatorSystem.cpp b/src/Game/Systems/DamageIndicatorSystem.cpp index ca26052d..55a1046c 100644 --- a/src/Game/Systems/DamageIndicatorSystem.cpp +++ b/src/Game/Systems/DamageIndicatorSystem.cpp @@ -9,7 +9,7 @@ DamageIndicatorSystem::DamageIndicatorSystem(SystemParams params) //load texture to cache auto texture = CommonFunctions::LoadTexture("Textures/DamageIndicator.png", false); - auto entityFile = ResourceManager::Load("Schema/Entities/DamageIndicator.xml"); + auto entityFile = ResourceManager::Load("Schema/Entities/DamageIndicator.xml"); } void DamageIndicatorSystem::Update(double dt) { @@ -49,8 +49,8 @@ bool DamageIndicatorSystem::OnPlayerDamage(Events::PlayerDamage& e) float angleBetweenVectors = CalculateAngle(e.Victim, inflictorPos); //load & set the "2d" sprite - auto entityFile = ResourceManager::Load("Schema/Entities/DamageIndicator.xml"); - EntityFileParser parser(entityFile); + auto entityFile = ResourceManager::Load("Schema/Entities/DamageIndicator.xml"); + EntityXMLFileParser parser(entityFile); EntityID spriteID = parser.MergeEntities(m_World); m_World->SetParent(spriteID, m_CurrentCamera); auto spriteWrapper = EntityWrapper(m_World, spriteID); @@ -127,8 +127,8 @@ glm::vec3 DamageIndicatorSystem::DamageIndicatorTest(EntityWrapper player) { auto inflictorPos = glm::vec3(currentPos.x + testVar*6.0f, currentPos.y, currentPos.z + testVar2*6.0f); //load the explosioneffect XML - auto deathEffect = ResourceManager::Load("Schema/Entities/PlayerDeathExplosionWithCamera.xml"); - EntityFileParser parser(deathEffect); + auto deathEffect = ResourceManager::Load("Schema/Entities/PlayerDeathExplosionWithCamera.xml"); + EntityXMLFileParser parser(deathEffect); EntityID deathEffectID = parser.MergeEntities(m_World); EntityWrapper deathEffectEW = EntityWrapper(m_World, deathEffectID); diff --git a/src/Game/Systems/PickupSpawnSystem.cpp b/src/Game/Systems/PickupSpawnSystem.cpp index 79e7d66b..9d1ce5b6 100644 --- a/src/Game/Systems/PickupSpawnSystem.cpp +++ b/src/Game/Systems/PickupSpawnSystem.cpp @@ -18,8 +18,8 @@ void PickupSpawnSystem::Update(double dt) somePickup.DecreaseThisRespawnTimer -= dt; if (somePickup.DecreaseThisRespawnTimer < 0.0) { //spawn the new healthPickup - auto entityFile = ResourceManager::Load("Schema/Entities/HealthPickup.xml"); - EntityFileParser parser(entityFile); + auto entityFile = ResourceManager::Load("Schema/Entities/HealthPickup.xml"); + EntityXMLFileParser parser(entityFile); EntityID healthPickupID = parser.MergeEntities(m_World); //let the world know a pickup has spawned (graphics effects, etc) diff --git a/src/Game/Systems/PlayerDeathSystem.cpp b/src/Game/Systems/PlayerDeathSystem.cpp index 0f05da57..1a491580 100644 --- a/src/Game/Systems/PlayerDeathSystem.cpp +++ b/src/Game/Systems/PlayerDeathSystem.cpp @@ -28,8 +28,8 @@ bool PlayerDeathSystem::OnPlayerDeath(Events::PlayerDeath& e) void PlayerDeathSystem::createDeathEffect(EntityWrapper player) { //load the explosioneffect XML - auto deathEffect = ResourceManager::Load("Schema/Entities/PlayerDeathExplosionWithCamera.xml"); - EntityFileParser parser(deathEffect); + auto deathEffect = ResourceManager::Load("Schema/Entities/PlayerDeathExplosionWithCamera.xml"); + EntityXMLFileParser parser(deathEffect); EntityID deathEffectID = parser.MergeEntities(m_World); EntityWrapper deathEffectEW = EntityWrapper(m_World, deathEffectID); diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index 9afc9c8c..5a687b84 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -328,8 +328,8 @@ bool PlayerMovementSystem::OnDoubleJump(Events::DoubleJump & e) void PlayerMovementSystem::spawnHexagon(EntityWrapper target) { //put a hexagon at the entitys... feet? - auto hexagonEffect = ResourceManager::Load("Schema/Entities/DoubleJumpHexagon.xml"); - EntityFileParser parser(hexagonEffect); + auto hexagonEffect = ResourceManager::Load("Schema/Entities/DoubleJumpHexagon.xml"); + EntityXMLFileParser parser(hexagonEffect); EntityID hexagonEffectID = parser.MergeEntities(m_World); EntityWrapper hexagonEW = EntityWrapper(m_World, hexagonEffectID); hexagonEW["Transform"]["Position"] = (glm::vec3)target["Transform"]["Position"]; @@ -342,8 +342,8 @@ bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e) return false; } - auto dashEffectResource = ResourceManager::Load("Schema/Entities/DashEffect.xml"); - EntityFileParser parser(dashEffectResource); + auto dashEffectResource = ResourceManager::Load("Schema/Entities/DashEffect.xml"); + EntityXMLFileParser parser(dashEffectResource); EntityID dashEffectID = parser.MergeEntities(m_World); EntityWrapper dashEffect(m_World, dashEffectID); auto playerModel = player.FirstChildByName("PlayerModel"); diff --git a/src/Game/Systems/SpawnerSystem.cpp b/src/Game/Systems/SpawnerSystem.cpp index 6500460f..b16f7dfe 100644 --- a/src/Game/Systems/SpawnerSystem.cpp +++ b/src/Game/Systems/SpawnerSystem.cpp @@ -17,11 +17,11 @@ EntityWrapper SpawnerSystem::Spawn(EntityWrapper spawner, EntityWrapper parent / // Load the entity file and parse it const std::string& entityFilePath = spawner["Spawner"]["EntityFile"]; - auto entityFile = ResourceManager::Load(entityFilePath); + auto entityFile = ResourceManager::Load(entityFilePath); if (entityFile == nullptr) { return EntityWrapper::Invalid; } - EntityFileParser parser(entityFile); + EntityXMLFileParser parser(entityFile); EntityWrapper spawnedEntity(world, parser.MergeEntities(world, parent.ID)); //If the spawned entity is collideable, then we must not spawn it where it collides with something that diff --git a/src/Tests/CapturePointTest.cpp b/src/Tests/CapturePointTest.cpp index 8a9baf40..8fb7869c 100644 --- a/src/Tests/CapturePointTest.cpp +++ b/src/Tests/CapturePointTest.cpp @@ -7,7 +7,7 @@ using boost::unit_test_framework::test_case; #include "Collision/TriggerSystem.h" #include "Collision/CollisionSystem.h" -#include "Core/EntityFileWriter.h" +#include "Core/EntityXMLFileWriter.h" #include "Game/Systems/CapturePointSystem.h" BOOST_AUTO_TEST_SUITE(CapturePointTestSuite) @@ -82,7 +82,7 @@ bool CapturePointTest::CapturePoint_Game_Loop_OneHundredTimes() { CapturePointTest::CapturePointTest(int runTestNumber) { ResourceManager::RegisterType("ConfigFile"); - ResourceManager::RegisterType("EntityFile"); + ResourceManager::RegisterType("EntityFile"); m_Config = ResourceManager::Load("Config.ini"); LOG_LEVEL = static_cast<_LOG_LEVEL>(m_Config->Get("Debug.LogLevel", 1)); @@ -99,10 +99,10 @@ CapturePointTest::CapturePointTest(int runTestNumber) m_SystemPipeline->AddSystem(1); //must register components (Components.xsd), else you cant create entities. Easiest done by loading a test xsd file - auto file = ResourceManager::Load("Schema/Entities/TeamTest.xml"); - EntityFilePreprocessor fpp(file); + auto file = ResourceManager::Load("Schema/Entities/TeamTest.xml"); + EntityXMLFilePreprocessor fpp(file); fpp.RegisterComponents(m_World); - EntityFileParser fp(file); + EntityXMLFileParser fp(file); fp.MergeEntities(m_World); EntityID playerID = m_World->CreateEntity(); diff --git a/src/Tests/CapturePointTest.h b/src/Tests/CapturePointTest.h index 54bdc55c..1046f714 100644 --- a/src/Tests/CapturePointTest.h +++ b/src/Tests/CapturePointTest.h @@ -9,12 +9,12 @@ #include "Input/KeyboardInputHandler.h" #include "Input/MouseInputHandler.h" #include "Core/EKeyDown.h" -#include "Core/EntityFile.h" +#include "Core/EntityXMLFile.h" #include "Core/SystemPipeline.h" -#include "Core/EntityFilePreprocessor.h" -#include "Core/EntityFileParser.h" -#include "Core/EntityFileWriter.h" +#include "Core/EntityXMLFilePreprocessor.h" +#include "Core/EntityXMLFileParser.h" +#include "Core/EntityXMLFileWriter.h" #include "Engine/Collision/ETrigger.h" diff --git a/src/Tests/HealthSystemTest.cpp b/src/Tests/HealthSystemTest.cpp index bf2650a3..0a8758ae 100644 --- a/src/Tests/HealthSystemTest.cpp +++ b/src/Tests/HealthSystemTest.cpp @@ -30,7 +30,7 @@ BOOST_AUTO_TEST_SUITE_END() GameHealthSystemTest::GameHealthSystemTest() { ResourceManager::RegisterType("ConfigFile"); - ResourceManager::RegisterType("EntityFile"); + ResourceManager::RegisterType("EntityFile"); m_Config = ResourceManager::Load("Config.ini"); LOG_LEVEL = static_cast<_LOG_LEVEL>(m_Config->Get("Debug.LogLevel", 1)); @@ -41,10 +41,10 @@ GameHealthSystemTest::GameHealthSystemTest() // Create a world m_World = new World(); - auto file = ResourceManager::Load("Schema/Entities/TeamTest.xml"); - EntityFilePreprocessor fpp(file); + auto file = ResourceManager::Load("Schema/Entities/TeamTest.xml"); + EntityXMLFilePreprocessor fpp(file); fpp.RegisterComponents(m_World); - EntityFileParser fp(file); + EntityXMLFileParser fp(file); fp.MergeEntities(m_World); // Create system pipeline diff --git a/src/Tests/HealthSystemTest.h b/src/Tests/HealthSystemTest.h index 275558d2..787a2d0e 100644 --- a/src/Tests/HealthSystemTest.h +++ b/src/Tests/HealthSystemTest.h @@ -11,7 +11,7 @@ #include "Input/KeyboardInputHandler.h" #include "Input/MouseInputHandler.h" #include "Core/EKeyDown.h" -#include "Core/EntityFile.h" +#include "Core/EntityXMLFile.h" #include "Core/SystemPipeline.h" #include "Editor/EditorSystem.h" diff --git a/src/Tests/PickupSpawnTest.cpp b/src/Tests/PickupSpawnTest.cpp index 4acd897e..0af72883 100644 --- a/src/Tests/PickupSpawnTest.cpp +++ b/src/Tests/PickupSpawnTest.cpp @@ -30,7 +30,7 @@ BOOST_AUTO_TEST_SUITE_END() PickupSpawnTest::PickupSpawnTest(int runTestNumber) { ResourceManager::RegisterType("ConfigFile"); - ResourceManager::RegisterType("EntityFile"); + ResourceManager::RegisterType("EntityFile"); m_Config = ResourceManager::Load("Config.ini"); LOG_LEVEL = static_cast<_LOG_LEVEL>(m_Config->Get("Debug.LogLevel", 1)); @@ -44,10 +44,10 @@ PickupSpawnTest::PickupSpawnTest(int runTestNumber) m_SystemPipeline->AddSystem(1); //must register components (Components.xsd), else you cant create entities. Easiest done by loading a test xsd file - auto file = ResourceManager::Load("Schema/Entities/HealthPickup.xml"); - EntityFilePreprocessor fpp(file); + auto file = ResourceManager::Load("Schema/Entities/HealthPickup.xml"); + EntityXMLFilePreprocessor fpp(file); fpp.RegisterComponents(m_World); - EntityFileParser fp(file); + EntityXMLFileParser fp(file); //connect the healthpickup to the world m_HealthPickupID = fp.MergeEntities(m_World); diff --git a/src/Tests/PickupSpawnTest.h b/src/Tests/PickupSpawnTest.h index b9d5483a..372b07cd 100644 --- a/src/Tests/PickupSpawnTest.h +++ b/src/Tests/PickupSpawnTest.h @@ -9,12 +9,12 @@ #include "Input/KeyboardInputHandler.h" #include "Input/MouseInputHandler.h" #include "Core/EKeyDown.h" -#include "Core/EntityFile.h" +#include "Core/EntityXMLFile.h" #include "Core/SystemPipeline.h" -#include "Core/EntityFilePreprocessor.h" -#include "Core/EntityFileParser.h" -#include "Core/EntityFileWriter.h" +#include "Core/EntityXMLFilePreprocessor.h" +#include "Core/EntityXMLFileParser.h" +#include "Core/EntityXMLFileWriter.h" #include "Engine/Collision/ETrigger.h" @@ -29,7 +29,7 @@ //#include #include "Collision/TriggerSystem.h" #include "Collision/CollisionSystem.h" -#include "Core/EntityFileWriter.h" +#include "Core/EntityXMLFileWriter.h" #include "Game/Systems/HealthSystem.h" #include "Game/Systems/PickupSpawnSystem.h" From 0c0f2d7e50d8d14a395b95b1452571a89f59ba9c Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Wed, 2 Mar 2016 18:56:22 +0100 Subject: [PATCH 094/130] fixup! Renamed EntityFile to EntityXMLFile to be able to separate file parsing from entity creation --- include/Engine/Core/EntityXMLFile.h | 4 ++-- include/Engine/Core/EntityXMLFileParser.h | 4 ++-- include/Engine/Core/EntityXMLFilePreprocessor.h | 4 ++-- include/Engine/Core/EntityXMLFileWriter.h | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/Engine/Core/EntityXMLFile.h b/include/Engine/Core/EntityXMLFile.h index 6dcc74c5..6f24154d 100644 --- a/include/Engine/Core/EntityXMLFile.h +++ b/include/Engine/Core/EntityXMLFile.h @@ -1,5 +1,5 @@ -#ifndef EntityFile_h__ -#define EntityFile_h__ +#ifndef EntityXMLFile_h__ +#define EntityXMLFile_h__ #include #include diff --git a/include/Engine/Core/EntityXMLFileParser.h b/include/Engine/Core/EntityXMLFileParser.h index c058640f..984f9e46 100644 --- a/include/Engine/Core/EntityXMLFileParser.h +++ b/include/Engine/Core/EntityXMLFileParser.h @@ -1,5 +1,5 @@ -#ifndef EntityFileParser_h__ -#define EntityFileParser_h__ +#ifndef EntityXMLFileParser_h__ +#define EntityXMLFileParser_h__ #include "EntityXMLFile.h" #include "World.h" diff --git a/include/Engine/Core/EntityXMLFilePreprocessor.h b/include/Engine/Core/EntityXMLFilePreprocessor.h index 45880835..e102ef79 100644 --- a/include/Engine/Core/EntityXMLFilePreprocessor.h +++ b/include/Engine/Core/EntityXMLFilePreprocessor.h @@ -1,5 +1,5 @@ -#ifndef EntityFilePreprocessor_h__ -#define EntityFilePreprocessor_h__ +#ifndef EntityXMLFilePreprocessor_h__ +#define EntityXMLFilePreprocessor_h__ #include #include diff --git a/include/Engine/Core/EntityXMLFileWriter.h b/include/Engine/Core/EntityXMLFileWriter.h index 9b100670..da073a73 100644 --- a/include/Engine/Core/EntityXMLFileWriter.h +++ b/include/Engine/Core/EntityXMLFileWriter.h @@ -1,5 +1,5 @@ -#ifndef EntityFileWriter_h__ -#define EntityFileWriter_h__ +#ifndef EntityXMLFileWriter_h__ +#define EntityXMLFileWriter_h__ #include #include From fb9914d08a821d800641f7138ad9f3ca2824fe26 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Wed, 2 Mar 2016 19:48:20 +0100 Subject: [PATCH 095/130] Fixed AMD shader compilation error --- resources/Shaders/ForwardPlusSplatMapRGBShieldCheck.frag.glsl | 1 - 1 file changed, 1 deletion(-) diff --git a/resources/Shaders/ForwardPlusSplatMapRGBShieldCheck.frag.glsl b/resources/Shaders/ForwardPlusSplatMapRGBShieldCheck.frag.glsl index fa3af6ac..d61726fe 100644 --- a/resources/Shaders/ForwardPlusSplatMapRGBShieldCheck.frag.glsl +++ b/resources/Shaders/ForwardPlusSplatMapRGBShieldCheck.frag.glsl @@ -40,7 +40,6 @@ layout (binding = 10) uniform sampler2D SpecularMapTexture3; layout (binding = 11) uniform sampler2D GlowMapTexture1; layout (binding = 12) uniform sampler2D GlowMapTexture2; layout (binding = 13) uniform sampler2D GlowMapTexture3; -layout (binding = 13) uniform sampler2D GlowMapTexture3; layout (binding = 31) uniform samplerCube ShieldBuffer; #define TILE_SIZE 16 From 618e96da9084fa4d452ad1b9c1bacc9eea6b58f5 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Wed, 2 Mar 2016 19:49:54 +0100 Subject: [PATCH 096/130] "Fixed" this crash in debug. The attachment vector is sometimes empty! @Tleety --- src/Engine/Rendering/FrameBuffer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Engine/Rendering/FrameBuffer.cpp b/src/Engine/Rendering/FrameBuffer.cpp index 9ba0d2d8..da438e7a 100644 --- a/src/Engine/Rendering/FrameBuffer.cpp +++ b/src/Engine/Rendering/FrameBuffer.cpp @@ -70,7 +70,7 @@ void FrameBuffer::Generate() } GLERROR("3"); - GLenum* bufferTextures = &attachments[0]; + GLenum* bufferTextures = attachments.data(); glDrawBuffers(attachments.size(), bufferTextures); if (GLERROR("GLBufferAttachement error")) { printf(": AttachmentSize %i", attachments.size()); From 44b4a597d43e2058025caadce3e880f7a947c737 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Wed, 2 Mar 2016 19:50:52 +0100 Subject: [PATCH 097/130] fixup! Created World::Merge which will merge a world into another one --- include/Engine/Core/World.h | 2 +- src/Engine/Core/World.cpp | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/include/Engine/Core/World.h b/include/Engine/Core/World.h index 28c96303..9ae38021 100644 --- a/include/Engine/Core/World.h +++ b/include/Engine/Core/World.h @@ -55,7 +55,7 @@ public: // Merge another world into this one // Returns a map that maps entities from the other world to their copies in this one - std::unordered_map Merge(World& other); + std::unordered_map Merge(const World* other); private: EventBroker* m_EventBroker = nullptr; diff --git a/src/Engine/Core/World.cpp b/src/Engine/Core/World.cpp index 96c4660d..0952a53b 100644 --- a/src/Engine/Core/World.cpp +++ b/src/Engine/Core/World.cpp @@ -169,27 +169,29 @@ EntityWrapper World::GetFirstEntityByName(const std::string& name) return EntityWrapper::Invalid; } -std::unordered_map World::Merge(World& other) +std::unordered_map World::Merge(const World* other) { std::unordered_map oldToNew; // Create new entities - for (auto& kv : other.m_EntityParents) { + for (auto& kv : other->m_EntityParents) { EntityID entity = kv.first; EntityID newEntity = CreateEntity(); - SetName(newEntity, other.GetName(entity)); + SetName(newEntity, other->GetName(entity)); oldToNew[entity] = newEntity; } // Fix relationships - for (auto& kv : other.m_EntityParents) { + for (auto& kv : other->m_EntityParents) { EntityID entity = kv.first; EntityID parent = kv.second; - SetParent(oldToNew.at(entity), oldToNew.at(parent)); + if (parent != EntityID_Invalid) { + SetParent(oldToNew.at(entity), oldToNew.at(parent)); + } } // Transfer components - for (auto& kv : other.m_ComponentPools) { + for (auto& kv : other->m_ComponentPools) { auto& componentType = kv.first; ComponentPool* pool = kv.second; // Register pool if it's not present in world From 069583e09f29d695240f8f1423aeb48925f788eb Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Wed, 2 Mar 2016 19:52:11 +0100 Subject: [PATCH 098/130] Created EntityFile which loads an EntityXMLFile into a temporary world to be merged with another world when you want to create a copy of the entity loaded from disk. This allows us to free EntityXMLFile once it's loaded into an EntityFile. --- include/Engine/Core/EntityFile.h | 21 +++++++++++++++++++++ src/Engine/Core/EntityFile.cpp | 22 ++++++++++++++++++++++ src/Game/Game.cpp | 4 +++- 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 include/Engine/Core/EntityFile.h create mode 100644 src/Engine/Core/EntityFile.cpp diff --git a/include/Engine/Core/EntityFile.h b/include/Engine/Core/EntityFile.h new file mode 100644 index 00000000..fae39c51 --- /dev/null +++ b/include/Engine/Core/EntityFile.h @@ -0,0 +1,21 @@ +#ifndef EntityFile_h__ +#define EntityFile_h__ + +#include "World.h" +#include "EntityXMLFile.h" +#include "EntityXMLFilePreprocessor.h" +#include "EntityXMLFileParser.h" +#include "EntityWrapper.h" + +class EntityFile : private World, public Resource +{ +public: + EntityFile(std::string path); + + EntityWrapper MergeInto(World* other); + +private: + EntityID m_RootEntity = EntityID_Invalid; +}; + +#endif \ No newline at end of file diff --git a/src/Engine/Core/EntityFile.cpp b/src/Engine/Core/EntityFile.cpp new file mode 100644 index 00000000..090bbbd8 --- /dev/null +++ b/src/Engine/Core/EntityFile.cpp @@ -0,0 +1,22 @@ +#include "Core/EntityFile.h" + +EntityFile::EntityFile(std::string path) +{ + EntityXMLFile* xml = ResourceManager::Load(path); + + EntityXMLFilePreprocessor preprocessor(xml); + preprocessor.RegisterComponents(this); + + EntityXMLFileParser parser(xml); + m_RootEntity = parser.MergeEntities(this); + + if (m_RootEntity == EntityID_Invalid) { + throw Resource::FailedLoadingException("Failed to merge entities; root entity is invalid"); + } +} + +EntityWrapper EntityFile::MergeInto(World* other) +{ + auto mapping = other->Merge(this); + return EntityWrapper(other, mapping.at(m_RootEntity)); +} \ No newline at end of file diff --git a/src/Game/Game.cpp b/src/Game/Game.cpp index 9c9228b9..1a672f25 100644 --- a/src/Game/Game.cpp +++ b/src/Game/Game.cpp @@ -11,6 +11,7 @@ #include "Systems/PlayerSpawnSystem.h" #include "Systems/PlayerDeathSystem.h" #include "Systems/FloatingEffectSystem.h" +#include "Core/EntityFile.h" #include "Core/EntityXMLFileWriter.h" #include "Game/Systems/CapturePointSystem.h" #include "Game/Systems/CapturePointHUDSystem.h" @@ -44,7 +45,8 @@ Game::Game(int argc, char* argv[]) ResourceManager::RegisterType("Texture"); ResourceManager::RegisterType("Png"); ResourceManager::RegisterType("ShaderProgram"); - ResourceManager::RegisterType("EntityFile"); + ResourceManager::RegisterType("EntityFile"); + ResourceManager::RegisterType("EntityXMLFile"); ResourceManager::RegisterType("FontFile"); m_Config = ResourceManager::Load("Config.ini"); From 5923d2d7a72512137ae789755fc15fcd41334e8b Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Wed, 2 Mar 2016 19:52:34 +0100 Subject: [PATCH 099/130] Made SpawnerSystem utilize the new EntityFile for spawning instead --- include/Game/Systems/SpawnerSystem.h | 3 +-- src/Game/Systems/SpawnerSystem.cpp | 14 ++++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/Game/Systems/SpawnerSystem.h b/include/Game/Systems/SpawnerSystem.h index 10817ef0..f36f7259 100644 --- a/include/Game/Systems/SpawnerSystem.h +++ b/include/Game/Systems/SpawnerSystem.h @@ -7,8 +7,7 @@ #include "Core/System.h" #include "Events/ESpawnerSpawn.h" #include "Core/Transform.h" -#include "Core/ResourceManager.h" -#include "Core/EntityXMLFileParser.h" +#include "Core/EntityFile.h" class SpawnerSystem : public System { diff --git a/src/Game/Systems/SpawnerSystem.cpp b/src/Game/Systems/SpawnerSystem.cpp index b16f7dfe..282c958b 100644 --- a/src/Game/Systems/SpawnerSystem.cpp +++ b/src/Game/Systems/SpawnerSystem.cpp @@ -17,15 +17,17 @@ EntityWrapper SpawnerSystem::Spawn(EntityWrapper spawner, EntityWrapper parent / // Load the entity file and parse it const std::string& entityFilePath = spawner["Spawner"]["EntityFile"]; - auto entityFile = ResourceManager::Load(entityFilePath); - if (entityFile == nullptr) { + EntityWrapper spawnedEntity; + try { + auto entityFile = ResourceManager::Load(entityFilePath); + spawnedEntity = entityFile->MergeInto(world); + world->SetParent(spawnedEntity.ID, parent.ID); + } catch (const Resource::FailedLoadingException& e) { return EntityWrapper::Invalid; } - EntityXMLFileParser parser(entityFile); - EntityWrapper spawnedEntity(world, parser.MergeEntities(world, parent.ID)); - //If the spawned entity is collideable, then we must not spawn it where it collides with something that - //has a dontCollideComponent attached. + // If the spawned entity is collidable, then we must not spawn it where it collides with something that + // has a dontCollideComponent attached. bool spawnOnCollidable = dontCollideComponent.empty() || !spawnedEntity.HasComponent("Collidable"); if (!spawnOnCollidable) { boost::optional optBox = Collision::EntityAbsoluteAABB(spawnedEntity); From 3ef15dcb8108da3d9ec5d187bd674b85b6aeb6a1 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Wed, 2 Mar 2016 20:01:18 +0100 Subject: [PATCH 100/130] EntityFile now releases EntityXMLFile after processing. --- src/Engine/Core/EntityFile.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Engine/Core/EntityFile.cpp b/src/Engine/Core/EntityFile.cpp index 090bbbd8..997b9c46 100644 --- a/src/Engine/Core/EntityFile.cpp +++ b/src/Engine/Core/EntityFile.cpp @@ -11,8 +11,11 @@ EntityFile::EntityFile(std::string path) m_RootEntity = parser.MergeEntities(this); if (m_RootEntity == EntityID_Invalid) { + ResourceManager::Release("EntityXMLFile", path); throw Resource::FailedLoadingException("Failed to merge entities; root entity is invalid"); } + + ResourceManager::Release("EntityXMLFile", path); } EntityWrapper EntityFile::MergeInto(World* other) From 7624c6ee0a739a81dfcbf65e00bdbc2316f8c264 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Wed, 2 Mar 2016 20:12:59 +0100 Subject: [PATCH 101/130] Updated all uses of EntityXMLFile to use the new EntityFile to load entities into a world. --- include/Engine/Core/EntityXMLFileParser.h | 3 ++- include/Engine/Core/EntityXMLFilePreprocessor.h | 3 ++- include/Engine/Editor/EditorSystem.h | 3 +-- include/Game/Systems/AmmoPickupSystem.h | 2 +- include/Game/Systems/BoostSystem.h | 2 +- include/Game/Systems/DamageIndicatorSystem.h | 2 +- include/Game/Systems/PickupSpawnSystem.h | 2 +- include/Game/Systems/PlayerDeathSystem.h | 5 +---- include/Game/Systems/PlayerMovementSystem.h | 4 +--- src/Engine/Editor/EditorSystem.cpp | 11 +++++------ src/Game/Game.cpp | 7 ++----- src/Game/Systems/AmmoPickupSystem.cpp | 9 ++++----- src/Game/Systems/BoostSystem.cpp | 9 ++++----- src/Game/Systems/DamageIndicatorSystem.cpp | 12 +++++------- src/Game/Systems/PickupSpawnSystem.cpp | 9 ++++----- src/Game/Systems/PlayerDeathSystem.cpp | 6 ++---- src/Game/Systems/PlayerMovementSystem.cpp | 12 ++++-------- 17 files changed, 41 insertions(+), 60 deletions(-) diff --git a/include/Engine/Core/EntityXMLFileParser.h b/include/Engine/Core/EntityXMLFileParser.h index 984f9e46..4bc2fab9 100644 --- a/include/Engine/Core/EntityXMLFileParser.h +++ b/include/Engine/Core/EntityXMLFileParser.h @@ -6,12 +6,13 @@ class EntityXMLFileParser { + friend class EntityFile; public: EntityXMLFileParser(const EntityXMLFile* entityFile); +private: EntityID MergeEntities(World* world, EntityID baseParent = EntityID_Invalid); -private: const EntityXMLFile* m_EntityFile; EntityFileHandler m_Handler; World* m_World = nullptr; diff --git a/include/Engine/Core/EntityXMLFilePreprocessor.h b/include/Engine/Core/EntityXMLFilePreprocessor.h index e102ef79..4f969291 100644 --- a/include/Engine/Core/EntityXMLFilePreprocessor.h +++ b/include/Engine/Core/EntityXMLFilePreprocessor.h @@ -21,12 +21,13 @@ class EntityXMLFilePreprocessor { + friend class EntityFile; public: EntityXMLFilePreprocessor(const EntityXMLFile* entityFile); +private: void RegisterComponents(World* world); -private: const EntityXMLFile* m_EntityFile; std::map m_ComponentCounts; std::map m_ComponentInfo; diff --git a/include/Engine/Editor/EditorSystem.h b/include/Engine/Editor/EditorSystem.h index b565367a..655ac9b9 100644 --- a/include/Engine/Editor/EditorSystem.h +++ b/include/Engine/Editor/EditorSystem.h @@ -5,8 +5,7 @@ #include "../Core/World.h" #include "../Core/SystemPipeline.h" #include "../Core/ResourceManager.h" -#include "../Core/EntityXMLFilePreprocessor.h" -#include "../Core/EntityXMLFileParser.h" +#include "../Core/EntityFile.h" #include "../Core/EntityXMLFileWriter.h" #include "../Core/EMousePress.h" #include "../Input/EInputCommand.h" diff --git a/include/Game/Systems/AmmoPickupSystem.h b/include/Game/Systems/AmmoPickupSystem.h index 8e5c4f1d..70c5630f 100644 --- a/include/Game/Systems/AmmoPickupSystem.h +++ b/include/Game/Systems/AmmoPickupSystem.h @@ -4,7 +4,7 @@ #include "Core/System.h" #include "Core/Transform.h" #include "Core/ResourceManager.h" -#include "Core/EntityXMLFileParser.h" +#include "Core/EntityFile.h" #include "Core/EPickupSpawned.h" #include "Core/EAmmoPickup.h" #include "Engine/Collision/ETrigger.h" diff --git a/include/Game/Systems/BoostSystem.h b/include/Game/Systems/BoostSystem.h index 525918a4..f02e9472 100644 --- a/include/Game/Systems/BoostSystem.h +++ b/include/Game/Systems/BoostSystem.h @@ -3,7 +3,7 @@ #include "Core/System.h" #include "Core/ResourceManager.h" -#include "Core/EntityXMLFileParser.h" +#include "Core/EntityFile.h" #include "Core/EPlayerDamage.h" #include "Common.h" diff --git a/include/Game/Systems/DamageIndicatorSystem.h b/include/Game/Systems/DamageIndicatorSystem.h index 935089fa..9c88ba78 100644 --- a/include/Game/Systems/DamageIndicatorSystem.h +++ b/include/Game/Systems/DamageIndicatorSystem.h @@ -4,7 +4,7 @@ #include "Core/System.h" #include "Core/Transform.h" #include "Core/ResourceManager.h" -#include "Core/EntityXMLFileParser.h" +#include "Core/EntityFile.h" #include "Core/EPlayerDamage.h" #include "Common.h" #include diff --git a/include/Game/Systems/PickupSpawnSystem.h b/include/Game/Systems/PickupSpawnSystem.h index 1151b487..b72b8b25 100644 --- a/include/Game/Systems/PickupSpawnSystem.h +++ b/include/Game/Systems/PickupSpawnSystem.h @@ -4,7 +4,7 @@ #include "Core/System.h" #include "Core/Transform.h" #include "Core/ResourceManager.h" -#include "Core/EntityXMLFileParser.h" +#include "Core/EntityFile.h" #include "Core/EPickupSpawned.h" #include "Core/EPlayerHealthPickup.h" #include "Engine/Collision/ETrigger.h" diff --git a/include/Game/Systems/PlayerDeathSystem.h b/include/Game/Systems/PlayerDeathSystem.h index 96ed2ab5..e4f96114 100644 --- a/include/Game/Systems/PlayerDeathSystem.h +++ b/include/Game/Systems/PlayerDeathSystem.h @@ -6,10 +6,7 @@ #include "GLM.h" #include "Rendering/ESetCamera.h" #include "Core/ConfigFile.h" - -#include "Core/EntityXMLFile.h" -#include "Core/EntityXMLFileParser.h" - +#include "Core/EntityFile.h" #include "Core/EPlayerDeath.h" #include "Core/EEntityDeleted.h" diff --git a/include/Game/Systems/PlayerMovementSystem.h b/include/Game/Systems/PlayerMovementSystem.h index 8b6e4e54..bf7b4718 100644 --- a/include/Game/Systems/PlayerMovementSystem.h +++ b/include/Game/Systems/PlayerMovementSystem.h @@ -6,9 +6,7 @@ #include #include "Events/EDoubleJump.h" #include "../Engine/Sound/EPlaySoundOnEntity.h" - -#include "Core/EntityXMLFile.h" -#include "Core/EntityXMLFileParser.h" +#include "Core/EntityFile.h" class PlayerMovementSystem : public ImpureSystem { diff --git a/src/Engine/Editor/EditorSystem.cpp b/src/Engine/Editor/EditorSystem.cpp index 3e664161..62ddba88 100644 --- a/src/Engine/Editor/EditorSystem.cpp +++ b/src/Engine/Editor/EditorSystem.cpp @@ -2,6 +2,7 @@ #include "Core/UniformScaleSystem.h" #include "Editor/EditorRenderSystem.h" #include "Editor/EditorWidgetSystem.h" +#include "Core/EntityFile.h" EditorSystem::EditorSystem(SystemParams params, IRenderer* renderer, RenderFrame* renderFrame) : System(params) @@ -259,12 +260,10 @@ EntityWrapper EditorSystem::importEntity(EntityWrapper parent, boost::filesystem } try { - auto entityFile = ResourceManager::Load(filePath.string()); - EntityXMLFilePreprocessor fpp(entityFile); - fpp.RegisterComponents(parent.World); - EntityXMLFileParser fp(entityFile); - EntityID newEntity = fp.MergeEntities(parent.World, parent.ID); - return EntityWrapper(parent.World, newEntity); + auto entityFile = ResourceManager::Load(filePath.string()); + EntityWrapper newEntity = entityFile->MergeInto(parent.World); + parent.World->SetParent(newEntity.ID, parent.ID); + return newEntity; } catch (const std::exception& e) { LOG_ERROR("Failed to import entity \"%s\": \"%s\"", filePath.string().c_str(), e.what()); return EntityWrapper::Invalid; diff --git a/src/Game/Game.cpp b/src/Game/Game.cpp index 1a672f25..5e82dc2e 100644 --- a/src/Game/Game.cpp +++ b/src/Game/Game.cpp @@ -82,11 +82,8 @@ Game::Game(int argc, char* argv[]) m_World = new World(m_EventBroker); std::string mapToLoad = m_Config->Get("Debug.LoadMap", ""); if (!mapToLoad.empty()) { - auto file = ResourceManager::Load(mapToLoad); - EntityXMLFilePreprocessor fpp(file); - fpp.RegisterComponents(m_World); - EntityXMLFileParser fp(file); - fp.MergeEntities(m_World); + auto file = ResourceManager::Load(mapToLoad); + file->MergeInto(m_World); } // Create the sound manager diff --git a/src/Game/Systems/AmmoPickupSystem.cpp b/src/Game/Systems/AmmoPickupSystem.cpp index e3051efe..062efe94 100644 --- a/src/Game/Systems/AmmoPickupSystem.cpp +++ b/src/Game/Systems/AmmoPickupSystem.cpp @@ -20,17 +20,16 @@ void AmmoPickupSystem::Update(double dt) auto& somePickup = *it; somePickup.DecreaseThisRespawnTimer -= dt; if (somePickup.DecreaseThisRespawnTimer < 0.0) { - auto entityFile = ResourceManager::Load("Schema/Entities/AmmoPickup.xml"); - EntityXMLFileParser parser(entityFile); - EntityID ammoPickupID = parser.MergeEntities(m_World); + auto entityFile = ResourceManager::Load("Schema/Entities/AmmoPickup.xml"); + EntityWrapper ammoPickup = entityFile->MergeInto(m_World); //let the world know a pickup has spawned Events::PickupSpawned ePickupSpawned; - ePickupSpawned.Pickup = EntityWrapper(m_World, ammoPickupID); + ePickupSpawned.Pickup = ammoPickup; m_EventBroker->Publish(ePickupSpawned); //copy values from the old entity to the new entity - auto& newAmmoPickupEntity = EntityWrapper(m_World, ammoPickupID); + auto& newAmmoPickupEntity = ammoPickup; newAmmoPickupEntity["Transform"]["Position"] = somePickup.Pos; newAmmoPickupEntity["AmmoPickup"]["AmmoGain"] = somePickup.AmmoGain; newAmmoPickupEntity["AmmoPickup"]["RespawnTimer"] = somePickup.RespawnTimer; diff --git a/src/Game/Systems/BoostSystem.cpp b/src/Game/Systems/BoostSystem.cpp index 7f335d1f..c79576e4 100644 --- a/src/Game/Systems/BoostSystem.cpp +++ b/src/Game/Systems/BoostSystem.cpp @@ -38,11 +38,10 @@ bool BoostSystem::OnPlayerDamage(Events::PlayerDamage& e) m_World->DeleteEntity(playerBoostAssaultEntity.ID); } //load boost XML file, set it entity parented with the victim player - auto entityFile = ResourceManager::Load(classXML); - EntityXMLFileParser parser(entityFile); - EntityID boostAssaultEntity = parser.MergeEntities(m_World); - m_World->SetName(boostAssaultEntity, className); - m_World->SetParent(boostAssaultEntity, e.Victim.ID); + auto entityFile = ResourceManager::Load(classXML); + EntityWrapper boostAssaultEntity = entityFile->MergeInto(m_World); + m_World->SetName(boostAssaultEntity.ID, className); + m_World->SetParent(boostAssaultEntity.ID, e.Victim.ID); return true; } diff --git a/src/Game/Systems/DamageIndicatorSystem.cpp b/src/Game/Systems/DamageIndicatorSystem.cpp index 55a1046c..e68f741d 100644 --- a/src/Game/Systems/DamageIndicatorSystem.cpp +++ b/src/Game/Systems/DamageIndicatorSystem.cpp @@ -49,16 +49,14 @@ bool DamageIndicatorSystem::OnPlayerDamage(Events::PlayerDamage& e) float angleBetweenVectors = CalculateAngle(e.Victim, inflictorPos); //load & set the "2d" sprite - auto entityFile = ResourceManager::Load("Schema/Entities/DamageIndicator.xml"); - EntityXMLFileParser parser(entityFile); - EntityID spriteID = parser.MergeEntities(m_World); - m_World->SetParent(spriteID, m_CurrentCamera); - auto spriteWrapper = EntityWrapper(m_World, spriteID); + auto entityFile = ResourceManager::Load("Schema/Entities/DamageIndicator.xml"); + EntityWrapper sprite = entityFile->MergeInto(m_World); + m_World->SetParent(sprite.ID, m_CurrentCamera); //simply set the rotation z-wise to the angleBetweenVectors - spriteWrapper["Transform"]["Orientation"] = glm::vec3(0, 0, angleBetweenVectors); + sprite["Transform"]["Orientation"] = glm::vec3(0, 0, angleBetweenVectors); if (!IsServer) { - updateDamageIndicatorVector.emplace_back(spriteWrapper, inflictorPos); + updateDamageIndicatorVector.emplace_back(sprite, inflictorPos); } return true; diff --git a/src/Game/Systems/PickupSpawnSystem.cpp b/src/Game/Systems/PickupSpawnSystem.cpp index 9d1ce5b6..99da931f 100644 --- a/src/Game/Systems/PickupSpawnSystem.cpp +++ b/src/Game/Systems/PickupSpawnSystem.cpp @@ -18,17 +18,16 @@ void PickupSpawnSystem::Update(double dt) somePickup.DecreaseThisRespawnTimer -= dt; if (somePickup.DecreaseThisRespawnTimer < 0.0) { //spawn the new healthPickup - auto entityFile = ResourceManager::Load("Schema/Entities/HealthPickup.xml"); - EntityXMLFileParser parser(entityFile); - EntityID healthPickupID = parser.MergeEntities(m_World); + auto entityFile = ResourceManager::Load("Schema/Entities/HealthPickup.xml"); + EntityWrapper healthPickup = entityFile->MergeInto(m_World); //let the world know a pickup has spawned (graphics effects, etc) Events::PickupSpawned ePickupSpawned; - ePickupSpawned.Pickup = EntityWrapper(m_World, healthPickupID); + ePickupSpawned.Pickup = healthPickup; m_EventBroker->Publish(ePickupSpawned); //copy values from the old entity to the new entity - auto& newHealthPickupEntity = EntityWrapper(m_World, healthPickupID); + auto& newHealthPickupEntity = healthPickup; newHealthPickupEntity["Transform"]["Position"] = somePickup.Pos; newHealthPickupEntity["HealthPickup"]["HealthGain"] = somePickup.HealthGain; newHealthPickupEntity["HealthPickup"]["RespawnTimer"] = somePickup.RespawnTimer; diff --git a/src/Game/Systems/PlayerDeathSystem.cpp b/src/Game/Systems/PlayerDeathSystem.cpp index 1a491580..cbf0927f 100644 --- a/src/Game/Systems/PlayerDeathSystem.cpp +++ b/src/Game/Systems/PlayerDeathSystem.cpp @@ -28,10 +28,8 @@ bool PlayerDeathSystem::OnPlayerDeath(Events::PlayerDeath& e) void PlayerDeathSystem::createDeathEffect(EntityWrapper player) { //load the explosioneffect XML - auto deathEffect = ResourceManager::Load("Schema/Entities/PlayerDeathExplosionWithCamera.xml"); - EntityXMLFileParser parser(deathEffect); - EntityID deathEffectID = parser.MergeEntities(m_World); - EntityWrapper deathEffectEW = EntityWrapper(m_World, deathEffectID); + auto entityFile = ResourceManager::Load("Schema/Entities/PlayerDeathExplosionWithCamera.xml"); + EntityWrapper deathEffectEW = entityFile->MergeInto(m_World); //components that we need from player auto playerModel = player.FirstChildByName("PlayerModel"); diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index 5a687b84..802b5048 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -328,10 +328,8 @@ bool PlayerMovementSystem::OnDoubleJump(Events::DoubleJump & e) void PlayerMovementSystem::spawnHexagon(EntityWrapper target) { //put a hexagon at the entitys... feet? - auto hexagonEffect = ResourceManager::Load("Schema/Entities/DoubleJumpHexagon.xml"); - EntityXMLFileParser parser(hexagonEffect); - EntityID hexagonEffectID = parser.MergeEntities(m_World); - EntityWrapper hexagonEW = EntityWrapper(m_World, hexagonEffectID); + auto entityFile = ResourceManager::Load("Schema/Entities/DoubleJumpHexagon.xml"); + EntityWrapper hexagonEW = entityFile->MergeInto(m_World); hexagonEW["Transform"]["Position"] = (glm::vec3)target["Transform"]["Position"]; } @@ -342,10 +340,8 @@ bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e) return false; } - auto dashEffectResource = ResourceManager::Load("Schema/Entities/DashEffect.xml"); - EntityXMLFileParser parser(dashEffectResource); - EntityID dashEffectID = parser.MergeEntities(m_World); - EntityWrapper dashEffect(m_World, dashEffectID); + auto entityFile = ResourceManager::Load("Schema/Entities/DashEffect.xml"); + EntityWrapper dashEffect = entityFile->MergeInto(m_World); auto playerModel = player.FirstChildByName("PlayerModel"); auto playerEntityModel = playerModel["Model"]; auto playerEntityAnimation = playerModel["Animation"]; From 9a668ed7d7f298bfed7fa21114199ef88f3e0da5 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Wed, 2 Mar 2016 20:16:03 +0100 Subject: [PATCH 102/130] Now here's the real fix for the lag when loading entity files: CONSOLE SPAM --- include/Engine/Core/MemoryPool.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/include/Engine/Core/MemoryPool.h b/include/Engine/Core/MemoryPool.h index 053e75aa..da4af84e 100644 --- a/include/Engine/Core/MemoryPool.h +++ b/include/Engine/Core/MemoryPool.h @@ -118,9 +118,6 @@ public: else { m_ExtraMemory.push_back((char*)malloc(m_Stride)); //We should preferably not enter here to avoid performance issues. Set more numMaxElements in constructor instead. - if (!DisableMemoryPool::Value) { - LOG_DEBUG("Allocated slots exceed Pool size, extra memory allocated dynamically. Pool size: %u, dynamic size: %u.", m_NumSlots, m_ExtraMemory.size()); - } return m_ExtraMemory.back(); } } From 8b81ba9019b566ccca5315a5c6cea3b14f7cb15d Mon Sep 17 00:00:00 2001 From: Tleety Date: Wed, 2 Mar 2016 21:40:20 +0100 Subject: [PATCH 103/130] Some small fixes, also added new UI elements to Player --- resources/Schema/Components/Text.xml | 2 +- resources/Schema/Entities/Player.xml | 93 ++++++++++++++++++++++++++-- 2 files changed, 89 insertions(+), 6 deletions(-) diff --git a/resources/Schema/Components/Text.xml b/resources/Schema/Components/Text.xml index d38d3961..cda29b86 100644 --- a/resources/Schema/Components/Text.xml +++ b/resources/Schema/Components/Text.xml @@ -1,7 +1,7 @@ - + Fonts/DroidSans.ttf,64 true
diff --git a/resources/Schema/Entities/Player.xml b/resources/Schema/Entities/Player.xml index 28ace561..9fb563f8 100644 --- a/resources/Schema/Entities/Player.xml +++ b/resources/Schema/Entities/Player.xml @@ -132,7 +132,70 @@ - + + + + + + + + + + + + + + Textures/Core/White.png + false + + + + + + + + + + + + + + + + + Textures/Core/White.png + false + + + + + + + + + + + + + + + + + Textures/Core/White.png + false + + + + + + + + + + + + + @@ -196,7 +259,6 @@ 3 - 0.80222018197612788 @@ -231,6 +293,7 @@ 4 + 1 @@ -286,7 +349,7 @@ Textures/Core/UnitHexagon.png - + @@ -297,7 +360,8 @@ - + 1 + Textures/Core/UnitHexagon_Rotated.png @@ -306,7 +370,7 @@ - + @@ -369,6 +433,25 @@ + + + + + Models/Widgets/Arrows/Arrow9.mesh + + + + + + + + + + + + + + From 2d438060ddc5e396aa96b9c94e8ab60839c51911 Mon Sep 17 00:00:00 2001 From: Tleety Date: Wed, 2 Mar 2016 22:08:23 +0100 Subject: [PATCH 104/130] Player arrow change --- resources/Schema/Entities/Player.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/Schema/Entities/Player.xml b/resources/Schema/Entities/Player.xml index 9fb563f8..34692605 100644 --- a/resources/Schema/Entities/Player.xml +++ b/resources/Schema/Entities/Player.xml @@ -100,12 +100,12 @@ 1 - 100/100 Fonts/DroidSans.ttf,64 + @@ -437,7 +437,7 @@ - Models/Widgets/Arrows/Arrow9.mesh + Models/Widgets/Arrows/Arrow5.mesh @@ -447,7 +447,7 @@ - + From b431a875f75c741b0ecd5576b1819a2331ae5a85 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Tue, 1 Mar 2016 13:26:50 +0100 Subject: [PATCH 105/130] New weapon behaviours --- .../Systems/Weapon/DefenderWeaponBehaviour.h | 12 +-- .../Systems/Weapon/SidearmWeaponBehaviour.h | 32 ++++++++ include/Game/Systems/Weapon/WeaponBehaviour.h | 74 ++++++++++++------- resources/Schema/Components.xsd | 1 + .../Schema/Components/DefenderWeapon.xsd | 12 +++ resources/Schema/Components/SidearmWeapon.xml | 14 ++++ resources/Schema/Components/SidearmWeapon.xsd | 48 ++++++++++++ resources/Schema/Entities/Player.xml | 8 +- resources/Schema/Types/Entity.xsd | 1 + src/Engine/Rendering/Renderer.cpp | 2 +- .../Weapon/DefenderWeaponBehaviour.cpp | 24 +++--- .../Systems/Weapon/SidearmWeaponBehaviour.cpp | 58 +++++++++++++++ 12 files changed, 232 insertions(+), 54 deletions(-) create mode 100644 include/Game/Systems/Weapon/SidearmWeaponBehaviour.h create mode 100644 resources/Schema/Components/SidearmWeapon.xml create mode 100644 resources/Schema/Components/SidearmWeapon.xsd create mode 100644 src/Game/Systems/Weapon/SidearmWeaponBehaviour.cpp diff --git a/include/Game/Systems/Weapon/DefenderWeaponBehaviour.h b/include/Game/Systems/Weapon/DefenderWeaponBehaviour.h index 5ca13d3e..986d8586 100644 --- a/include/Game/Systems/Weapon/DefenderWeaponBehaviour.h +++ b/include/Game/Systems/Weapon/DefenderWeaponBehaviour.h @@ -15,10 +15,10 @@ public: } void UpdateComponent(EntityWrapper& entity, ComponentWrapper& cWeapon, double dt) override; - void UpdateWeapon(WeaponInfo& wi, double dt) override; - void OnPrimaryFire(WeaponInfo& wi) override; - void OnCeasePrimaryFire(WeaponInfo& wi) override; - bool OnInputCommand(WeaponInfo& wi, const Events::InputCommand& e) override; + void UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo& wi, double dt) override; + void OnPrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi) override; + void OnCeasePrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi) override; + bool OnInputCommand(ComponentWrapper cWeapon, WeaponInfo& wi, const Events::InputCommand& e) override; private: std::random_device m_RandomDevice; @@ -29,8 +29,8 @@ private: bool OnSetCamera(const Events::SetCamera& e); // Weapon functions - void fireShell(WeaponInfo& wi); - void dealDamage(WeaponInfo& wi, glm::vec3 direction, double damage); + void fireShell(ComponentWrapper cWeapon, WeaponInfo& wi); + void dealDamage(ComponentWrapper cWeapon, WeaponInfo& wi, glm::vec3 direction, double damage); // Utility float traceRayDistance(glm::vec3 origin, glm::vec3 direction); diff --git a/include/Game/Systems/Weapon/SidearmWeaponBehaviour.h b/include/Game/Systems/Weapon/SidearmWeaponBehaviour.h new file mode 100644 index 00000000..787c3c61 --- /dev/null +++ b/include/Game/Systems/Weapon/SidearmWeaponBehaviour.h @@ -0,0 +1,32 @@ +#include "WeaponBehaviour.h" +#include "Collision/Collision.h" +#include "Core/EPlayerDamage.h" + +class SidearmWeaponBehaviour : public WeaponBehaviour +{ +public: + SidearmWeaponBehaviour(SystemParams systemParams, IRenderer* renderer, Octree* collisionOctree) + : System(systemParams) + , WeaponBehaviour(systemParams, "SidearmWeapon", renderer, collisionOctree) + , m_RandomEngine(m_RandomDevice()) + { } + + void UpdateComponent(EntityWrapper& entity, ComponentWrapper& cWeapon, double dt) override; + void UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo& wi, double dt) override; + void OnPrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi) override; + void OnCeasePrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi) override; + void OnHolster(ComponentWrapper cWeapon, WeaponInfo& wi) override; + +private: + std::random_device m_RandomDevice; + std::mt19937 m_RandomEngine; + EntityWrapper m_CurrentCamera; + + // Weapon functions + void fireBullet(ComponentWrapper cWeapon, WeaponInfo& wi); + //void dealDamage(WeaponInfo& wi, glm::vec3 direction, double damage); + + // Utility + bool canFire(ComponentWrapper cWeapon); + //float traceRayDistance(glm::vec3 origin, glm::vec3 direction); +}; \ No newline at end of file diff --git a/include/Game/Systems/Weapon/WeaponBehaviour.h b/include/Game/Systems/Weapon/WeaponBehaviour.h index f23269df..2ab53e0e 100644 --- a/include/Game/Systems/Weapon/WeaponBehaviour.h +++ b/include/Game/Systems/Weapon/WeaponBehaviour.h @@ -24,36 +24,35 @@ public: } virtual ~WeaponBehaviour() = default; - virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt) override + virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& cWeapon, double dt) override { auto weapon = getActiveWeapon(entity); if (!weapon) { return; } else { - UpdateWeapon(*weapon, dt); + UpdateWeapon(cWeapon, *weapon, dt); } } protected: struct WeaponInfo { - std::string WeaponComponent; EntityWrapper Player; EntityWrapper WeaponEntity; EntityWrapper FirstPersonEntity; EntityWrapper ThirdPersonEntity; - ComponentWrapper GetComponent() { return WeaponEntity[WeaponComponent]; } }; IRenderer* m_Renderer; Octree* m_CollisionOctree; std::unordered_map m_ActiveWeapons; - virtual void UpdateWeapon(WeaponInfo& wi, double dt) { } - virtual void OnPrimaryFire(WeaponInfo& wi) { } - virtual void OnCeasePrimaryFire(WeaponInfo& wi) { } - virtual void OnReload(WeaponInfo& wi) { } - virtual bool OnInputCommand(WeaponInfo& wi, const Events::InputCommand& e) { return false; } + virtual void UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo& wi, double dt) { } + virtual void OnPrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi) { } + virtual void OnCeasePrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi) { } + virtual void OnReload(ComponentWrapper cWeapon, WeaponInfo& wi) { } + virtual void OnHolster(ComponentWrapper cWeapon, WeaponInfo& wi) { } + virtual bool OnInputCommand(ComponentWrapper cWeapon, WeaponInfo& wi, const Events::InputCommand& e) { return false; } private: EventRelay m_EInputCommand; @@ -70,15 +69,19 @@ private: } // Make sure the player has this weapon - auto weapon = getWeaponComponent(player); - if (!weapon) { + auto cWeapon = getWeaponComponent(player); + if (!cWeapon) { return false; } // Weapon selection if (e.Command == "SelectWeapon") { - if (static_cast(e.Value) == static_cast((*weapon)["Slot"])) { - selectWeapon(player); + if (e.Value > 0) { + if (static_cast(e.Value) == static_cast((*cWeapon)["Slot"])) { + selectWeapon(player); + } else { + holsterWeapon(*cWeapon, player); + } } } @@ -91,18 +94,18 @@ private: // Fire if (e.Command == "PrimaryFire") { if (e.Value > 0) { - OnPrimaryFire(*activeWeapon); + OnPrimaryFire(*cWeapon, *activeWeapon); } else { - OnCeasePrimaryFire(*activeWeapon); + OnCeasePrimaryFire(*cWeapon, *activeWeapon); } } // Reload if (e.Command == "Reload" && e.Value != 0) { - OnReload(*activeWeapon); + OnReload(*cWeapon, *activeWeapon); } - return OnInputCommand(*activeWeapon, e); + return OnInputCommand(*cWeapon, *activeWeapon, e); } boost::optional getWeaponComponent(EntityWrapper player) @@ -131,6 +134,11 @@ private: void selectWeapon(EntityWrapper player) { + // Don't reselect weapon if it's already active + if (getActiveWeapon(player)) { + return; + } + // Find the weapon attachments matching the weapon type std::vector weaponAttachments = player.ChildrenWithComponent("WeaponAttachment"); EntityWrapper firstPersonAttachment; @@ -152,14 +160,6 @@ private: return; } - // Purge other weapon entities - for (auto& attachment : weaponAttachments) { - //if (attachment == firstPersonAttachment || attachment == thirdPersonAttachment) { - // continue; - //} - attachment.DeleteChildren(); - } - // Spawn the weapon(s) EntityWrapper firstPersonWeapon; EntityWrapper thirdPersonWeapon; @@ -170,12 +170,34 @@ private: thirdPersonWeapon = SpawnerSystem::Spawn(thirdPersonAttachment, thirdPersonAttachment); } - m_ActiveWeapons[player].WeaponComponent = m_ComponentType; m_ActiveWeapons[player].Player = player; m_ActiveWeapons[player].WeaponEntity = player; m_ActiveWeapons[player].FirstPersonEntity = firstPersonWeapon; m_ActiveWeapons[player].ThirdPersonEntity = thirdPersonWeapon; } + + void holsterWeapon(ComponentWrapper cWeapon, EntityWrapper player) + { + auto activeWeapon = getActiveWeapon(player); + if (!activeWeapon) { + return; + } + WeaponInfo& wi = *activeWeapon; + + // Send holster event + OnHolster(cWeapon, wi); + + // Delete weapon entities + if (wi.FirstPersonEntity.Valid()) { + m_World->DeleteEntity(wi.FirstPersonEntity.ID); + } + if (wi.ThirdPersonEntity.Valid()) { + m_World->DeleteEntity(wi.ThirdPersonEntity.ID); + } + + // Make weapon inactive + m_ActiveWeapons.erase(player); + } }; #endif diff --git a/resources/Schema/Components.xsd b/resources/Schema/Components.xsd index 0c8886f3..711f4999 100644 --- a/resources/Schema/Components.xsd +++ b/resources/Schema/Components.xsd @@ -54,6 +54,7 @@ + diff --git a/resources/Schema/Components/DefenderWeapon.xsd b/resources/Schema/Components/DefenderWeapon.xsd index 3fe5a64a..0ec61964 100755 --- a/resources/Schema/Components/DefenderWeapon.xsd +++ b/resources/Schema/Components/DefenderWeapon.xsd @@ -4,6 +4,18 @@ + + + + + + + + + + + + diff --git a/resources/Schema/Components/SidearmWeapon.xml b/resources/Schema/Components/SidearmWeapon.xml new file mode 100644 index 00000000..b63706b6 --- /dev/null +++ b/resources/Schema/Components/SidearmWeapon.xml @@ -0,0 +1,14 @@ + + + 16 + 16 + 20 + 120 + 0.01 + 0.5 + + false + 0 + false + 0 + \ No newline at end of file diff --git a/resources/Schema/Components/SidearmWeapon.xsd b/resources/Schema/Components/SidearmWeapon.xsd new file mode 100644 index 00000000..844b449f --- /dev/null +++ b/resources/Schema/Components/SidearmWeapon.xsd @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + Ammo currently loaded into the magazine + + + Max number of rounds in a magazine + + + Damage dealt if all shotgun pellets hit + + + Rate of fire in rounds per minute + + + View punch in radians for each shell fired + + + Time it takes to load ONE SHELL into the weapon in seconds + + + + + + + + + + diff --git a/resources/Schema/Entities/Player.xml b/resources/Schema/Entities/Player.xml index 34692605..d157c99e 100644 --- a/resources/Schema/Entities/Player.xml +++ b/resources/Schema/Entities/Player.xml @@ -6,11 +6,6 @@ - - - - - 52.867678870419283 @@ -488,9 +483,10 @@ AssaultWeapon - Schema/Entities/AssaultWeaponView.xml + Schema/Entities/SidearmWeaponView.xml + SidearmWeapon diff --git a/resources/Schema/Types/Entity.xsd b/resources/Schema/Types/Entity.xsd index 57445a15..f9870a51 100644 --- a/resources/Schema/Types/Entity.xsd +++ b/resources/Schema/Types/Entity.xsd @@ -52,6 +52,7 @@ + diff --git a/src/Engine/Rendering/Renderer.cpp b/src/Engine/Rendering/Renderer.cpp index 3ce985b6..7e11f3b2 100644 --- a/src/Engine/Rendering/Renderer.cpp +++ b/src/Engine/Rendering/Renderer.cpp @@ -17,7 +17,7 @@ void Renderer::Initialize() m_TextPass->Initialize(); /* m_ScreenQuad = ResourceManager::Load("Models/Core/ScreenQuad.obj"); - m_UnitQuad = ResourceManager::Load("Models/Core/UnitQuad.obj"); + m_UnitQuad = ResourceManager::Load(sModels/Core/UnitQuad.obj"); m_UnitSphere = ResourceManager::Load("Models/Core/UnitSphere.obj");*/ m_ImGuiRenderPass = new ImGuiRenderPass(this, m_EventBroker); diff --git a/src/Game/Systems/Weapon/DefenderWeaponBehaviour.cpp b/src/Game/Systems/Weapon/DefenderWeaponBehaviour.cpp index 028bd10c..0a179b4c 100644 --- a/src/Game/Systems/Weapon/DefenderWeaponBehaviour.cpp +++ b/src/Game/Systems/Weapon/DefenderWeaponBehaviour.cpp @@ -6,36 +6,32 @@ void DefenderWeaponBehaviour::UpdateComponent(EntityWrapper& entity, ComponentWr WeaponBehaviour::UpdateComponent(entity, cWeapon, dt); } -void DefenderWeaponBehaviour::UpdateWeapon(WeaponInfo& wi, double dt) +void DefenderWeaponBehaviour::UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo& wi, double dt) { - ComponentWrapper cWeapon = wi.GetComponent(); - bool isFiring = cWeapon["IsFiring"]; bool cooldownPassed = (double)cWeapon["TimeSinceLastFire"] >= (60.0 / (double)cWeapon["RPM"]); bool isNotShielding = wi.Player.ChildrenWithComponent("Shield").size() == 0; if (isFiring && cooldownPassed && isNotShielding) { - fireShell(wi); + fireShell(cWeapon, wi); } } -void DefenderWeaponBehaviour::OnPrimaryFire(WeaponInfo& wi) +void DefenderWeaponBehaviour::OnPrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi) { - ComponentWrapper cWeapon = wi.GetComponent(); cWeapon["IsFiring"] = true; bool cooldownPassed = (double)cWeapon["TimeSinceLastFire"] >= (60.0 / (double)cWeapon["RPM"]); bool isNotShielding = wi.Player.ChildrenWithComponent("Shield").size() == 0; if (cooldownPassed && isNotShielding) { - fireShell(wi); + fireShell(cWeapon, wi); } } -void DefenderWeaponBehaviour::OnCeasePrimaryFire(WeaponInfo& wi) +void DefenderWeaponBehaviour::OnCeasePrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi) { - ComponentWrapper cWeapon = wi.GetComponent(); cWeapon["IsFiring"] = false; } -bool DefenderWeaponBehaviour::OnInputCommand(WeaponInfo& wi, const Events::InputCommand& e) +bool DefenderWeaponBehaviour::OnInputCommand(ComponentWrapper cWeapon, WeaponInfo& wi, const Events::InputCommand& e) { if (e.Command == "SpecialAbility" && IsServer) { EntityWrapper attachment = wi.Player.FirstChildByName("ShieldAttachment"); @@ -57,10 +53,8 @@ bool DefenderWeaponBehaviour::OnSetCamera(const Events::SetCamera& e) return true; } -void DefenderWeaponBehaviour::fireShell(WeaponInfo& wi) +void DefenderWeaponBehaviour::fireShell(ComponentWrapper cWeapon, WeaponInfo& wi) { - ComponentWrapper cWeapon = wi.GetComponent(); - cWeapon["TimeSinceLastFire"] = 0.0; int numPellets = cWeapon["NumPellets"]; float spreadAngle = cWeapon["SpreadAngle"]; @@ -95,13 +89,13 @@ void DefenderWeaponBehaviour::fireShell(WeaponInfo& wi) orientation.x += angles.x; orientation.y += angles.y; glm::vec3 trajectory = direction * distance; - dealDamage(wi, direction, pelletDamage); + dealDamage(cWeapon, wi, direction, pelletDamage); } } } -void DefenderWeaponBehaviour::dealDamage(WeaponInfo& wi, glm::vec3 direction, double damage) +void DefenderWeaponBehaviour::dealDamage(ComponentWrapper cWeapon, WeaponInfo& wi, glm::vec3 direction, double damage) { // Only deal damage client side if (!IsClient) { diff --git a/src/Game/Systems/Weapon/SidearmWeaponBehaviour.cpp b/src/Game/Systems/Weapon/SidearmWeaponBehaviour.cpp new file mode 100644 index 00000000..8c3906af --- /dev/null +++ b/src/Game/Systems/Weapon/SidearmWeaponBehaviour.cpp @@ -0,0 +1,58 @@ +#include "Systems/Weapon/SidearmWeaponBehaviour.h" + +void SidearmWeaponBehaviour::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cWeapon, double dt) +{ + double& cooldown = cWeapon["FireCooldown"]; + if (cooldown > 0) { + cooldown -= dt; + if (cooldown < 0) { + cooldown = 0; + } + } + WeaponBehaviour::UpdateComponent(entity, cWeapon, dt); +} + +void SidearmWeaponBehaviour::UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo& wi, double dt) +{ + if (canFire(cWeapon)) { + fireBullet(cWeapon, wi); + } +} + +void SidearmWeaponBehaviour::OnPrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi) +{ + cWeapon["TriggerHeld"] = true; + if (canFire(cWeapon)) { + fireBullet(cWeapon, wi); + } +} + +void SidearmWeaponBehaviour::OnCeasePrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi) +{ + cWeapon["TriggerHeld"] = false; +} + +void SidearmWeaponBehaviour::OnHolster(ComponentWrapper cWeapon, WeaponInfo& wi) +{ + // Make sure the trigger is released if weapon is holstered while firing + cWeapon["TriggerHeld"] = false; + + // Cancel any reload + cWeapon["IsReloading"] = false; + cWeapon["ReloadTimer"] = 0.0; + + LOG_DEBUG("HOLSTER"); +} + +void SidearmWeaponBehaviour::fireBullet(ComponentWrapper cWeapon, WeaponInfo& wi) +{ + +} + +bool SidearmWeaponBehaviour::canFire(ComponentWrapper cWeapon) +{ + bool triggerHeld = cWeapon["TriggerHeld"]; + double& cooldown = cWeapon["FireCooldown"]; + // TODO: Ammo checks + return triggerHeld && cooldown <= 0.0; +} \ No newline at end of file From 6f8023b285d260f68efd9ac615b702721e8ae0b4 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Tue, 1 Mar 2016 16:35:30 +0100 Subject: [PATCH 106/130] HACK: Added Activate button for spawners in editor. Right now it includes the event from Game, but SpawnerSystem should probably be moved to Engine. --- include/Engine/Editor/EditorGUI.h | 1 + src/Engine/Editor/EditorGUI.cpp | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/include/Engine/Editor/EditorGUI.h b/include/Engine/Editor/EditorGUI.h index 57574e66..807bfc8b 100644 --- a/include/Engine/Editor/EditorGUI.h +++ b/include/Engine/Editor/EditorGUI.h @@ -22,6 +22,7 @@ #include "../Core/ELockMouse.h" #include "../Core/EFileDropped.h" #include "../Rendering/Texture.h" +#include "Game/Events/ESpawnerSpawn.h" class EditorGUI { diff --git a/src/Engine/Editor/EditorGUI.cpp b/src/Engine/Editor/EditorGUI.cpp index 8ce15d0a..a1ceafd0 100644 --- a/src/Engine/Editor/EditorGUI.cpp +++ b/src/Engine/Editor/EditorGUI.cpp @@ -338,6 +338,15 @@ bool EditorGUI::drawComponentNode(EntityWrapper entity, const ComponentInfo& ci) } } + if (ci.Name == "Spawner") { + if (ImGui::Button("Activate")) { + Events::SpawnerSpawn e; + e.Spawner = entity; + e.Parent = entity; + m_EventBroker->Publish(e); + } + } + return true; } From afd0e69a8a9a0c2050429277b77ab85308731f21 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Tue, 1 Mar 2016 16:35:54 +0100 Subject: [PATCH 107/130] Updated Player.xml for multiple weapons --- .../Schema/Entities/DefenderWeaponView.xml | 8 ++--- resources/Schema/Entities/Player.xml | 30 ++++++++++++++----- .../Schema/Entities/SidearmWeaponView.xml | 27 +++++++++++++++++ .../Schema/Entities/SidearmWeaponWorld.xml | 27 +++++++++++++++++ src/Game/Game.cpp | 2 ++ 5 files changed, 81 insertions(+), 13 deletions(-) create mode 100644 resources/Schema/Entities/SidearmWeaponView.xml create mode 100644 resources/Schema/Entities/SidearmWeaponWorld.xml diff --git a/resources/Schema/Entities/DefenderWeaponView.xml b/resources/Schema/Entities/DefenderWeaponView.xml index f6b6e89d..b65194f9 100755 --- a/resources/Schema/Entities/DefenderWeaponView.xml +++ b/resources/Schema/Entities/DefenderWeaponView.xml @@ -1,16 +1,12 @@ - + - - R_Arm_Weapon_Joint - - Models/Weapons/Blue/DefenderGunBlue.mesh - + diff --git a/resources/Schema/Entities/Player.xml b/resources/Schema/Entities/Player.xml index d157c99e..394f4622 100644 --- a/resources/Schema/Entities/Player.xml +++ b/resources/Schema/Entities/Player.xml @@ -11,6 +11,7 @@ 52.867678870419283 + @@ -453,7 +454,7 @@ Idle - 1.9408570429715581 + 0.022133545026491674 1 @@ -467,26 +468,38 @@ + + R_Arm_Weapon_Joint + DefenderWeapon Schema/Entities/DefenderWeaponView.xml - + + + + + + R_Arm_Weapon_Joint + AssaultWeapon + SidearmWeapon Schema/Entities/SidearmWeaponView.xml - - SidearmWeapon + + + + @@ -515,7 +528,7 @@ Idle - 1.5631122524686134 + 0.13373697879978863 1 @@ -550,14 +563,17 @@ + + R_Arm_Weapon_Joint + - AssaultWeapon + SidearmWeapon - Schema/Entities/AssaultWeaponWorld.xml + Schema/Entities/SidearmWeaponWorld.xml diff --git a/resources/Schema/Entities/SidearmWeaponView.xml b/resources/Schema/Entities/SidearmWeaponView.xml new file mode 100644 index 00000000..68d29676 --- /dev/null +++ b/resources/Schema/Entities/SidearmWeaponView.xml @@ -0,0 +1,27 @@ + + + + + + Models/Weapons/SecondaryWeapon.mesh + + + + + + + + + + + Schema/Entities/RayBlue.xml + + + + + + + + + + diff --git a/resources/Schema/Entities/SidearmWeaponWorld.xml b/resources/Schema/Entities/SidearmWeaponWorld.xml new file mode 100644 index 00000000..21cb26a7 --- /dev/null +++ b/resources/Schema/Entities/SidearmWeaponWorld.xml @@ -0,0 +1,27 @@ + + + + + + Models/Weapons/SecondaryWeapon.mesh + + + + + + + + + + + Schema/Entities/RayBlue.xml + + + + + + + + + + diff --git a/src/Game/Game.cpp b/src/Game/Game.cpp index 21f5c901..7607efec 100644 --- a/src/Game/Game.cpp +++ b/src/Game/Game.cpp @@ -19,6 +19,7 @@ #include "Game/Systems/AmmoPickupSystem.h" #include "Game/Systems/DamageIndicatorSystem.h" #include "Game/Systems/Weapon/DefenderWeaponBehaviour.h" +#include "Game/Systems/Weapon/SidearmWeaponBehaviour.h" #include "Rendering/AnimationSystem.h" #include "Game/Systems/HealthHUDSystem.h" #include "Rendering/BoneAttachmentSystem.h" @@ -128,6 +129,7 @@ Game::Game(int argc, char* argv[]) m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel, m_Renderer, m_OctreeCollision); + m_SystemPipeline->AddSystem(updateOrderLevel, m_Renderer, m_OctreeCollision); m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); From 13546aa3fc3e24a0744f12e89aa1e2191f13a334 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Tue, 1 Mar 2016 22:37:19 +0100 Subject: [PATCH 108/130] DefenderWeapon and SidearmWeapon --- .../Systems/Weapon/DefenderWeaponBehaviour.h | 12 +-- .../Systems/Weapon/SidearmWeaponBehaviour.h | 3 +- include/Game/Systems/Weapon/WeaponBehaviour.h | 57 +++++++++-- .../Schema/Components/DefenderWeapon.xml | 6 +- .../Schema/Components/DefenderWeapon.xsd | 6 +- resources/Schema/Components/SidearmWeapon.xml | 4 +- resources/Schema/Components/SidearmWeapon.xsd | 6 +- resources/Schema/Entities/Player.xml | 14 +-- resources/Schema/Entities/Ray2Red | 18 ++++ resources/Schema/Entities/Ray2Red.xml | 43 ++++++++ .../Schema/Entities/SidearmWeaponView.xml | 63 +++++++++++- src/Engine/Editor/EditorGUI.cpp | 52 ++++++++-- .../Weapon/DefenderWeaponBehaviour.cpp | 98 ++++++++++++++----- .../Systems/Weapon/SidearmWeaponBehaviour.cpp | 23 ++++- 14 files changed, 340 insertions(+), 65 deletions(-) create mode 100644 resources/Schema/Entities/Ray2Red create mode 100644 resources/Schema/Entities/Ray2Red.xml diff --git a/include/Game/Systems/Weapon/DefenderWeaponBehaviour.h b/include/Game/Systems/Weapon/DefenderWeaponBehaviour.h index 986d8586..c1e132b1 100644 --- a/include/Game/Systems/Weapon/DefenderWeaponBehaviour.h +++ b/include/Game/Systems/Weapon/DefenderWeaponBehaviour.h @@ -1,7 +1,6 @@ #include "WeaponBehaviour.h" #include "Collision/Collision.h" #include "Core/EPlayerDamage.h" -#include "Rendering/ESetCamera.h" class DefenderWeaponBehaviour : public WeaponBehaviour { @@ -10,29 +9,24 @@ public: : System(systemParams) , WeaponBehaviour(systemParams, "DefenderWeapon", renderer, collisionOctree) , m_RandomEngine(m_RandomDevice()) - { - EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &DefenderWeaponBehaviour::OnSetCamera); - } + { } void UpdateComponent(EntityWrapper& entity, ComponentWrapper& cWeapon, double dt) override; void UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo& wi, double dt) override; void OnPrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi) override; void OnCeasePrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi) override; + void OnReload(ComponentWrapper cWeapon, WeaponInfo& wi) override; bool OnInputCommand(ComponentWrapper cWeapon, WeaponInfo& wi, const Events::InputCommand& e) override; private: std::random_device m_RandomDevice; std::mt19937 m_RandomEngine; - EntityWrapper m_CurrentCamera; - - EventRelay m_ESetCamera; - bool OnSetCamera(const Events::SetCamera& e); // Weapon functions void fireShell(ComponentWrapper cWeapon, WeaponInfo& wi); void dealDamage(ComponentWrapper cWeapon, WeaponInfo& wi, glm::vec3 direction, double damage); + bool canFire(ComponentWrapper cWeapon, WeaponInfo& wi); // Utility - float traceRayDistance(glm::vec3 origin, glm::vec3 direction); Camera cameraFromEntity(EntityWrapper camera); }; \ No newline at end of file diff --git a/include/Game/Systems/Weapon/SidearmWeaponBehaviour.h b/include/Game/Systems/Weapon/SidearmWeaponBehaviour.h index 787c3c61..d221b8bb 100644 --- a/include/Game/Systems/Weapon/SidearmWeaponBehaviour.h +++ b/include/Game/Systems/Weapon/SidearmWeaponBehaviour.h @@ -15,12 +15,12 @@ public: void UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo& wi, double dt) override; void OnPrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi) override; void OnCeasePrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi) override; + void OnEquip(ComponentWrapper cWeapon, WeaponInfo& wi) override; void OnHolster(ComponentWrapper cWeapon, WeaponInfo& wi) override; private: std::random_device m_RandomDevice; std::mt19937 m_RandomEngine; - EntityWrapper m_CurrentCamera; // Weapon functions void fireBullet(ComponentWrapper cWeapon, WeaponInfo& wi); @@ -28,5 +28,6 @@ private: // Utility bool canFire(ComponentWrapper cWeapon); + bool playerInFirstPerson(EntityWrapper player); //float traceRayDistance(glm::vec3 origin, glm::vec3 direction); }; \ No newline at end of file diff --git a/include/Game/Systems/Weapon/WeaponBehaviour.h b/include/Game/Systems/Weapon/WeaponBehaviour.h index 2ab53e0e..e0783bd2 100644 --- a/include/Game/Systems/Weapon/WeaponBehaviour.h +++ b/include/Game/Systems/Weapon/WeaponBehaviour.h @@ -7,6 +7,7 @@ #include "Collision/EntityAABB.h" #include "Input/EInputCommand.h" #include "Systems/SpawnerSystem.h" +#include "Rendering/ESetCamera.h" template class WeaponBehaviour : public PureSystem @@ -21,6 +22,7 @@ public: , m_CollisionOctree(collisionOctree) { EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &WeaponBehaviour::_OnInputCommand) + EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &WeaponBehaviour::_OnSetCamera) } virtual ~WeaponBehaviour() = default; @@ -44,6 +46,7 @@ protected: }; IRenderer* m_Renderer; + EntityWrapper m_CurrentCamera; Octree* m_CollisionOctree; std::unordered_map m_ActiveWeapons; @@ -51,10 +54,49 @@ protected: virtual void OnPrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi) { } virtual void OnCeasePrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi) { } virtual void OnReload(ComponentWrapper cWeapon, WeaponInfo& wi) { } + virtual void OnEquip(ComponentWrapper cWeapon, WeaponInfo& wi) { } virtual void OnHolster(ComponentWrapper cWeapon, WeaponInfo& wi) { } virtual bool OnInputCommand(ComponentWrapper cWeapon, WeaponInfo& wi, const Events::InputCommand& e) { return false; } + bool isPlayerInFirstPerson(EntityWrapper player) + { + if (!m_CurrentCamera.Valid()) { + return false; + } else { + return m_CurrentCamera == player || m_CurrentCamera.IsChildOf(player); + } + } + + // Returns wi.FirstPersonEntity or wi.ThirdPersonEntity depending on + // if the player is in first person mode or not. + EntityWrapper getRelevantWeaponModelEntity(WeaponInfo& wi) + { + if (isPlayerInFirstPerson(wi.Player)) { + return wi.FirstPersonEntity; + } else { + return wi.ThirdPersonEntity; + } + } + + float traceRayDistance(glm::vec3 origin, glm::vec3 direction) + { + float distance; + glm::vec3 pos; + auto entity = Collision::EntityFirstHitByRay(Ray(origin, direction), m_CollisionOctree, distance, pos); + if (entity) { + return distance; + } else { + return 100.f; + } + } + private: + EventRelay m_ESetCamera; + bool _OnSetCamera(const Events::SetCamera& e) + { + m_CurrentCamera = e.CameraEntity; + return true; + } EventRelay m_EInputCommand; bool _OnInputCommand(const Events::InputCommand& e) { @@ -78,7 +120,7 @@ private: if (e.Command == "SelectWeapon") { if (e.Value > 0) { if (static_cast(e.Value) == static_cast((*cWeapon)["Slot"])) { - selectWeapon(player); + selectWeapon(*cWeapon, player); } else { holsterWeapon(*cWeapon, player); } @@ -132,7 +174,7 @@ private: return activeWeapon; } - void selectWeapon(EntityWrapper player) + void selectWeapon(ComponentWrapper cWeapon, EntityWrapper player) { // Don't reselect weapon if it's already active if (getActiveWeapon(player)) { @@ -170,10 +212,13 @@ private: thirdPersonWeapon = SpawnerSystem::Spawn(thirdPersonAttachment, thirdPersonAttachment); } - m_ActiveWeapons[player].Player = player; - m_ActiveWeapons[player].WeaponEntity = player; - m_ActiveWeapons[player].FirstPersonEntity = firstPersonWeapon; - m_ActiveWeapons[player].ThirdPersonEntity = thirdPersonWeapon; + WeaponInfo& wi = m_ActiveWeapons[player]; + wi.Player = player; + wi.WeaponEntity = player; + wi.FirstPersonEntity = firstPersonWeapon; + wi.ThirdPersonEntity = thirdPersonWeapon; + + OnEquip(cWeapon, wi); } void holsterWeapon(ComponentWrapper cWeapon, EntityWrapper player) diff --git a/resources/Schema/Components/DefenderWeapon.xml b/resources/Schema/Components/DefenderWeapon.xml index 998f3bde..1b336fc4 100755 --- a/resources/Schema/Components/DefenderWeapon.xml +++ b/resources/Schema/Components/DefenderWeapon.xml @@ -11,6 +11,8 @@ 0.01 0.5 - false - 0 + false + 0 + false + 0 \ No newline at end of file diff --git a/resources/Schema/Components/DefenderWeapon.xsd b/resources/Schema/Components/DefenderWeapon.xsd index 0ec61964..c1b98e2f 100755 --- a/resources/Schema/Components/DefenderWeapon.xsd +++ b/resources/Schema/Components/DefenderWeapon.xsd @@ -48,8 +48,10 @@ Time it takes to load ONE SHELL into the weapon in seconds - - + + + + diff --git a/resources/Schema/Components/SidearmWeapon.xml b/resources/Schema/Components/SidearmWeapon.xml index b63706b6..1d503ecc 100644 --- a/resources/Schema/Components/SidearmWeapon.xml +++ b/resources/Schema/Components/SidearmWeapon.xml @@ -3,9 +3,11 @@ 16 16 20 - 120 + 500 + false 0.01 0.5 + 0.5 false 0 diff --git a/resources/Schema/Components/SidearmWeapon.xsd b/resources/Schema/Components/SidearmWeapon.xsd index 844b449f..bafb9de2 100644 --- a/resources/Schema/Components/SidearmWeapon.xsd +++ b/resources/Schema/Components/SidearmWeapon.xsd @@ -23,7 +23,7 @@ Ammo currently loaded into the magazine - Max number of rounds in a magazine + Max number of rounds in a magazine Damage dealt if all shotgun pellets hit @@ -31,12 +31,16 @@ Rate of fire in rounds per minute + View punch in radians for each shell fired Time it takes to load ONE SHELL into the weapon in seconds + + Time it takes from selecting the weapon until it's ready to fire + diff --git a/resources/Schema/Entities/Player.xml b/resources/Schema/Entities/Player.xml index 394f4622..5c5efc07 100644 --- a/resources/Schema/Entities/Player.xml +++ b/resources/Schema/Entities/Player.xml @@ -8,7 +8,7 @@ - 52.867678870419283 + 102.85760837900634 @@ -454,7 +454,7 @@ Idle - 0.022133545026491674 + 1.8348644854054612 1 @@ -478,8 +478,8 @@ Schema/Entities/DefenderWeaponView.xml - - + + @@ -497,8 +497,8 @@ Schema/Entities/SidearmWeaponView.xml - - + + @@ -528,7 +528,7 @@ Idle - 0.13373697879978863 + 0.013134522267137072 1 diff --git a/resources/Schema/Entities/Ray2Red b/resources/Schema/Entities/Ray2Red new file mode 100644 index 00000000..813443b2 --- /dev/null +++ b/resources/Schema/Entities/Ray2Red @@ -0,0 +1,18 @@ + + + + + + Textures/Effects/Ray.png + + + + + + + + + + + + diff --git a/resources/Schema/Entities/Ray2Red.xml b/resources/Schema/Entities/Ray2Red.xml new file mode 100644 index 00000000..6c7c3248 --- /dev/null +++ b/resources/Schema/Entities/Ray2Red.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + Textures/Effects/Ray.png + + + + + + + + + + + + + + + Textures/Effects/Ray.png + + + + + + + + + + + + + + diff --git a/resources/Schema/Entities/SidearmWeaponView.xml b/resources/Schema/Entities/SidearmWeaponView.xml index 68d29676..f01ffdf7 100644 --- a/resources/Schema/Entities/SidearmWeaponView.xml +++ b/resources/Schema/Entities/SidearmWeaponView.xml @@ -14,7 +14,7 @@ - Schema/Entities/RayBlue.xml + Schema/Entities/Ray2Red.xml @@ -22,6 +22,67 @@ + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + + + + + + + + 16 + Fonts/DroidSans.ttf,64 + + + + + + + + + + + + + 8 + Fonts/DroidSans.ttf,64 + + + + + + + + + + + + + + diff --git a/src/Engine/Editor/EditorGUI.cpp b/src/Engine/Editor/EditorGUI.cpp index a1ceafd0..4e7c8ab6 100644 --- a/src/Engine/Editor/EditorGUI.cpp +++ b/src/Engine/Editor/EditorGUI.cpp @@ -390,14 +390,52 @@ bool EditorGUI::drawComponentField_Vector(ComponentWrapper &c, const ComponentIn // Limit scale values to a minimum of 0 return ImGui::DragFloat3("", glm::value_ptr(val), 0.1f, 0.f, std::numeric_limits::max()); } else if (field.Name == "Orientation") { - // Make orentations have a period of 2*Pi - glm::vec3 tempVal = glm::fmod(val, glm::vec3(glm::two_pi())); - if (ImGui::SliderFloat3("", glm::value_ptr(tempVal), 0.f, glm::two_pi())) { - val = tempVal; - return true; - } else { - return false; + //glm::vec3 tempVal = val; + glm::vec3 originalVal = val; + + ImVec2 cursorPos = ImGui::GetCursorScreenPos(); + glm::tvec3 isSnapping(false, false, false); + bool changed = ImGui::DragFloat3("", glm::value_ptr(val), 0.066666f); + if (changed) { + // Make orentations have a period of 2*Pi + val = glm::fmod(val, glm::vec3(glm::two_pi())); + for (int i = 0; i < 3; i++) { + if (val[i] < 0) { + val[i] += glm::two_pi(); + } + } } + + // Snap to angle + //float snapRange = glm::pi() / 15.f; + //float snapAngle = glm::quarter_pi(); + //glm::vec3 snap = glm::fmod(val, glm::vec3(snapAngle)); + //for (int i = 0; i < 3; i++) { + // isSnapping[i] = glm::abs(snap[i] - (snapRange / 2.f)) < snapRange; + //} + //if (changed && ImGui::IsMouseDown(0)) { + // glm::vec3 change = val - originalVal; + // for (int i = 0; i < 3; i++) { + // if (isSnapping[i] && glm::abs(change[i]) < snapRange) { + // val[i] -= snap[i] - snapRange; + // } + // } + //} + + // Draw snapping outline + float width = ImGui::CalcItemWidth() / 3.f;; + float spacing = GImGui->Style.ItemInnerSpacing.x; + for (int i = 0; i < 3; i++) { + if (isSnapping[i]) { + ImVec2 pos = cursorPos + ImVec2(i * (width + spacing), 0.f); + ImRect bb(pos - ImVec2(1, 1), pos + ImVec2(width, 17)); + auto window = ImGui::GetCurrentWindow(); + const ImU32 col = window->Color(ImGuiCol_HeaderActive); + window->DrawList->AddRect(bb.Min, bb.Max, col, 3.f); + } + } + + return changed; } else { return ImGui::DragFloat3("", glm::value_ptr(val), 0.1f, std::numeric_limits::lowest(), std::numeric_limits::max()); } diff --git a/src/Game/Systems/Weapon/DefenderWeaponBehaviour.cpp b/src/Game/Systems/Weapon/DefenderWeaponBehaviour.cpp index 0a179b4c..4c0f9673 100644 --- a/src/Game/Systems/Weapon/DefenderWeaponBehaviour.cpp +++ b/src/Game/Systems/Weapon/DefenderWeaponBehaviour.cpp @@ -2,33 +2,73 @@ void DefenderWeaponBehaviour::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cWeapon, double dt) { - (double&)cWeapon["TimeSinceLastFire"] += dt; + double& fireCooldown = cWeapon["FireCooldown"]; + fireCooldown = glm::max(0.0, fireCooldown - dt); + WeaponBehaviour::UpdateComponent(entity, cWeapon, dt); } void DefenderWeaponBehaviour::UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo& wi, double dt) { - bool isFiring = cWeapon["IsFiring"]; - bool cooldownPassed = (double)cWeapon["TimeSinceLastFire"] >= (60.0 / (double)cWeapon["RPM"]); - bool isNotShielding = wi.Player.ChildrenWithComponent("Shield").size() == 0; - if (isFiring && cooldownPassed && isNotShielding) { + double& reloadTimer = cWeapon["ReloadTimer"]; + reloadTimer = glm::max(0.0, reloadTimer - dt); + + double reloadTime = cWeapon["ReloadTime"]; + bool& isReloading = cWeapon["IsReloading"]; + if (isReloading && reloadTimer <= 0.0) { + int& magAmmo = cWeapon["MagazineAmmo"]; + int& magSize = cWeapon["MagazineSize"]; + int& ammo = cWeapon["Ammo"]; + if (magAmmo < magSize && ammo > 0) { + ammo -= 1; + magAmmo += 1; + reloadTimer = reloadTime; + } else { + isReloading = false; + } + } + + if (canFire(cWeapon, wi)) { fireShell(cWeapon, wi); } } void DefenderWeaponBehaviour::OnPrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi) { - cWeapon["IsFiring"] = true; - bool cooldownPassed = (double)cWeapon["TimeSinceLastFire"] >= (60.0 / (double)cWeapon["RPM"]); - bool isNotShielding = wi.Player.ChildrenWithComponent("Shield").size() == 0; - if (cooldownPassed && isNotShielding) { + cWeapon["TriggerHeld"] = true; + if (canFire(cWeapon, wi)) { fireShell(cWeapon, wi); } } void DefenderWeaponBehaviour::OnCeasePrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi) { - cWeapon["IsFiring"] = false; + cWeapon["TriggerHeld"] = false; +} + +void DefenderWeaponBehaviour::OnReload(ComponentWrapper cWeapon, WeaponInfo& wi) +{ + bool& isReloading = cWeapon["IsReloading"]; + if (isReloading) { + return; + } + + int& magAmmo = cWeapon["MagazineAmmo"]; + int& magSize = cWeapon["MagazineSize"]; + if (magAmmo >= magSize) { + return; + } + int& ammo = cWeapon["Ammo"]; + if (ammo <= 0) { + return; + } + + double reloadTime = cWeapon["ReloadTime"]; + double& reloadTimer = cWeapon["ReloadTimer"]; + + // Start reload + isReloading = true; + reloadTimer = reloadTime; } bool DefenderWeaponBehaviour::OnInputCommand(ComponentWrapper cWeapon, WeaponInfo& wi, const Events::InputCommand& e) @@ -47,15 +87,23 @@ bool DefenderWeaponBehaviour::OnInputCommand(ComponentWrapper cWeapon, WeaponInf return false; } -bool DefenderWeaponBehaviour::OnSetCamera(const Events::SetCamera& e) -{ - m_CurrentCamera = e.CameraEntity; - return true; -} - void DefenderWeaponBehaviour::fireShell(ComponentWrapper cWeapon, WeaponInfo& wi) { - cWeapon["TimeSinceLastFire"] = 0.0; + cWeapon["FireCooldown"] = 60.0 / (double)cWeapon["RPM"]; + + // Stop reloading + bool& isReloading = cWeapon["IsReloading"]; + isReloading = false; + + // Ammo + int& magAmmo = cWeapon["MagazineAmmo"]; + if (magAmmo <= 0) { + OnReload(cWeapon, wi); + return; + } else { + magAmmo -= 1; + } + int numPellets = cWeapon["NumPellets"]; float spreadAngle = cWeapon["SpreadAngle"]; std::uniform_real_distribution randomSpreadAngle(-spreadAngle, spreadAngle); @@ -92,7 +140,6 @@ void DefenderWeaponBehaviour::fireShell(ComponentWrapper cWeapon, WeaponInfo& wi dealDamage(cWeapon, wi, direction, pelletDamage); } } - } void DefenderWeaponBehaviour::dealDamage(ComponentWrapper cWeapon, WeaponInfo& wi, glm::vec3 direction, double damage) @@ -154,16 +201,13 @@ void DefenderWeaponBehaviour::dealDamage(ComponentWrapper cWeapon, WeaponInfo& w LOG_DEBUG("Damage: %f", damage); } -float DefenderWeaponBehaviour::traceRayDistance(glm::vec3 origin, glm::vec3 direction) +bool DefenderWeaponBehaviour::canFire(ComponentWrapper cWeapon, WeaponInfo& wi) { - float distance; - glm::vec3 pos; - auto entity = Collision::EntityFirstHitByRay(Ray(origin, direction), m_CollisionOctree, distance, pos); - if (entity) { - return distance; - } else { - return 100.f; - } + bool triggerHeld = cWeapon["TriggerHeld"]; + bool cooldownPassed = (double)cWeapon["FireCooldown"] <= 0.0; + bool isNotShielding = wi.Player.ChildrenWithComponent("Shield").size() == 0; + // TODO: Ammo checks + return triggerHeld && cooldownPassed && isNotShielding; } Camera DefenderWeaponBehaviour::cameraFromEntity(EntityWrapper camera) diff --git a/src/Game/Systems/Weapon/SidearmWeaponBehaviour.cpp b/src/Game/Systems/Weapon/SidearmWeaponBehaviour.cpp index 8c3906af..9a3ed6ab 100644 --- a/src/Game/Systems/Weapon/SidearmWeaponBehaviour.cpp +++ b/src/Game/Systems/Weapon/SidearmWeaponBehaviour.cpp @@ -14,7 +14,7 @@ void SidearmWeaponBehaviour::UpdateComponent(EntityWrapper& entity, ComponentWra void SidearmWeaponBehaviour::UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo& wi, double dt) { - if (canFire(cWeapon)) { + if ((bool)cWeapon["Automatic"] && canFire(cWeapon)) { fireBullet(cWeapon, wi); } } @@ -32,6 +32,11 @@ void SidearmWeaponBehaviour::OnCeasePrimaryFire(ComponentWrapper cWeapon, Weapon cWeapon["TriggerHeld"] = false; } +void SidearmWeaponBehaviour::OnEquip(ComponentWrapper cWeapon, WeaponInfo& wi) +{ + cWeapon["FireCooldown"] = (double)cWeapon["EquipTime"]; +} + void SidearmWeaponBehaviour::OnHolster(ComponentWrapper cWeapon, WeaponInfo& wi) { // Make sure the trigger is released if weapon is holstered while firing @@ -46,7 +51,23 @@ void SidearmWeaponBehaviour::OnHolster(ComponentWrapper cWeapon, WeaponInfo& wi) void SidearmWeaponBehaviour::fireBullet(ComponentWrapper cWeapon, WeaponInfo& wi) { + cWeapon["FireCooldown"] = 60.0 / (double)cWeapon["RPM"]; + // Get weapon model based on current person + EntityWrapper weaponModelEntity = getRelevantWeaponModelEntity(wi); + if (!weaponModelEntity.Valid()) { + return; + } + + // Tracer + EntityWrapper tracerSpawner = weaponModelEntity.FirstChildByName("WeaponMuzzle"); + if (tracerSpawner.Valid()) { + glm::vec3 origin = Transform::AbsolutePosition(tracerSpawner); + glm::vec3 direction = Transform::AbsoluteOrientation(tracerSpawner) * glm::vec3(0, 0, -1); + float distance = traceRayDistance(origin, direction); + EntityWrapper ray = SpawnerSystem::Spawn(tracerSpawner); + ((glm::vec3&)ray["Transform"]["Scale"]).z = (distance / 100.f); + } } bool SidearmWeaponBehaviour::canFire(ComponentWrapper cWeapon) From 0e8b97dbbade6bb39c6f2b8af6c1cfc43ce67cde Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Thu, 3 Mar 2016 01:35:32 +0100 Subject: [PATCH 109/130] Made AmmunitionHUD into TextFieldReader which reads any component field on a parent and updates a Text component with the value! --- include/Engine/Core/EntityWrapper.h | 1 + include/Game/Systems/AmmunitionHUDSystem.h | 17 ---- include/Game/Systems/TextFieldReader.h | 19 +++++ resources/Schema/Components.xsd | 2 +- resources/Schema/Components/AmmunitionHUD.xml | 3 - resources/Schema/Components/AmmunitionHUD.xsd | 10 --- .../Schema/Components/TextFieldReader.xml | 6 ++ .../Schema/Components/TextFieldReader.xsd | 21 +++++ .../Schema/Entities/DefenderWeaponView.xml | 15 +++- resources/Schema/Entities/Player.xml | 82 +++++++++---------- .../Schema/Entities/SidearmWeaponView.xml | 13 ++- resources/Schema/Types/Entity.xsd | 2 +- src/Engine/Core/EntityWrapper.cpp | 12 +++ src/Game/Game.cpp | 6 +- src/Game/Systems/AmmunitionHUDSystem.cpp | 36 -------- src/Game/Systems/TextFieldReader.cpp | 46 +++++++++++ 16 files changed, 174 insertions(+), 117 deletions(-) delete mode 100644 include/Game/Systems/AmmunitionHUDSystem.h create mode 100644 include/Game/Systems/TextFieldReader.h delete mode 100644 resources/Schema/Components/AmmunitionHUD.xml delete mode 100644 resources/Schema/Components/AmmunitionHUD.xsd create mode 100644 resources/Schema/Components/TextFieldReader.xml create mode 100644 resources/Schema/Components/TextFieldReader.xsd delete mode 100644 src/Game/Systems/AmmunitionHUDSystem.cpp create mode 100644 src/Game/Systems/TextFieldReader.cpp diff --git a/include/Engine/Core/EntityWrapper.h b/include/Engine/Core/EntityWrapper.h index 8ece8e59..12029720 100644 --- a/include/Engine/Core/EntityWrapper.h +++ b/include/Engine/Core/EntityWrapper.h @@ -27,6 +27,7 @@ struct EntityWrapper bool HasComponent(const std::string& componentType); void AttachComponent(const char* componentName); EntityWrapper Parent(); + EntityWrapper FirstParentByName(const std::string& parentEntityName); EntityWrapper FirstChildByName(const std::string& name); EntityWrapper FirstParentWithComponent(const std::string& componentType); EntityWrapper Clone(EntityWrapper parent = EntityWrapper::Invalid); diff --git a/include/Game/Systems/AmmunitionHUDSystem.h b/include/Game/Systems/AmmunitionHUDSystem.h deleted file mode 100644 index b22a85b5..00000000 --- a/include/Game/Systems/AmmunitionHUDSystem.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef AmmunitionHUDSystem_h__ -#define AmmunitionHUDSystem_h__ - -#include "../../Engine/Core/System.h" -#include "../../Engine/GLM.h" - -class AmmunitionHUDSystem : public ImpureSystem -{ -public: - AmmunitionHUDSystem(SystemParams params) - : System(params) - { } - - virtual void Update(double dt) override; -}; - -#endif \ No newline at end of file diff --git a/include/Game/Systems/TextFieldReader.h b/include/Game/Systems/TextFieldReader.h new file mode 100644 index 00000000..1ea8e966 --- /dev/null +++ b/include/Game/Systems/TextFieldReader.h @@ -0,0 +1,19 @@ +#ifndef AmmunitionHUDSystem_h__ +#define AmmunitionHUDSystem_h__ + +#include +#include "../../Engine/Core/System.h" +#include "../../Engine/GLM.h" + +class TextFieldReader : public PureSystem +{ +public: + TextFieldReader(SystemParams params) + : System(params) + , PureSystem("TextFieldReader") + { } + + virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& cTextFieldReader, double dt) override; +}; + +#endif \ No newline at end of file diff --git a/resources/Schema/Components.xsd b/resources/Schema/Components.xsd index 711f4999..ee8bc31d 100644 --- a/resources/Schema/Components.xsd +++ b/resources/Schema/Components.xsd @@ -45,7 +45,7 @@ - + diff --git a/resources/Schema/Components/AmmunitionHUD.xml b/resources/Schema/Components/AmmunitionHUD.xml deleted file mode 100644 index 63b86150..00000000 --- a/resources/Schema/Components/AmmunitionHUD.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/resources/Schema/Components/AmmunitionHUD.xsd b/resources/Schema/Components/AmmunitionHUD.xsd deleted file mode 100644 index 1a48d8d1..00000000 --- a/resources/Schema/Components/AmmunitionHUD.xsd +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - Hud element for tracking ammunition from parent with AssaultWeapon component. Child with the name "MagazineAmmo" tracks clip ammunition. Child with the name "Ammo" tracks ammo. - - - \ No newline at end of file diff --git a/resources/Schema/Components/TextFieldReader.xml b/resources/Schema/Components/TextFieldReader.xml new file mode 100644 index 00000000..52430804 --- /dev/null +++ b/resources/Schema/Components/TextFieldReader.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/resources/Schema/Components/TextFieldReader.xsd b/resources/Schema/Components/TextFieldReader.xsd new file mode 100644 index 00000000..7c77890d --- /dev/null +++ b/resources/Schema/Components/TextFieldReader.xsd @@ -0,0 +1,21 @@ + + + + + + Reads a value from a specific field of a compoent of parent entity and writes it to the Text component on this entity. + + + + The name of the parent entity to read the component field from. Leave empty to read from this entity. + + + The component type to read the field value from. + + + The field name to read the value from. + + + + + \ No newline at end of file diff --git a/resources/Schema/Entities/DefenderWeaponView.xml b/resources/Schema/Entities/DefenderWeaponView.xml index b65194f9..0886ac67 100755 --- a/resources/Schema/Entities/DefenderWeaponView.xml +++ b/resources/Schema/Entities/DefenderWeaponView.xml @@ -33,7 +33,6 @@ - @@ -61,8 +60,13 @@ + + Player + DefenderWeapon + MagazineAmmo + - 32 + 0 Fonts/DroidSans.ttf,64 @@ -74,8 +78,13 @@ + + Player + DefenderWeapon + Ammo + - 360 + 0 Fonts/DroidSans.ttf,64 diff --git a/resources/Schema/Entities/Player.xml b/resources/Schema/Entities/Player.xml index 5c5efc07..e0230582 100644 --- a/resources/Schema/Entities/Player.xml +++ b/resources/Schema/Entities/Player.xml @@ -7,9 +7,7 @@ - - 102.85760837900634 - + @@ -26,7 +24,7 @@ - + @@ -66,8 +64,8 @@ Textures/Weapons/Crosshair/SmallThickHoleDot.png - false + false @@ -90,42 +88,22 @@ - - - - 1 - - - - 100/100 - Fonts/DroidSans.ttf,64 - - - - - - - - - - - 1 + Textures/HealthHUD3.png - - + @@ -142,8 +120,8 @@ Textures/Core/White.png - false + false @@ -160,8 +138,8 @@ Textures/Core/White.png - false + false @@ -178,8 +156,8 @@ Textures/Core/White.png - false + false @@ -193,6 +171,26 @@ + + + + 1 + + + + 100/100 + Fonts/DroidSans.ttf,64 + + + + + + + + + + + @@ -229,8 +227,8 @@ - + @@ -263,8 +261,8 @@ - + @@ -298,8 +296,8 @@ - + @@ -332,8 +330,8 @@ - + @@ -365,8 +363,8 @@ - + @@ -442,8 +440,8 @@ - + @@ -490,9 +488,8 @@ R_Arm_Weapon_Joint - AssaultWeapon - SidearmWeapon + Schema/Entities/SidearmWeaponView.xml @@ -575,7 +572,10 @@ Schema/Entities/SidearmWeaponWorld.xml - + + + + @@ -617,8 +617,8 @@ - + @@ -627,8 +627,8 @@ Textures/Icons/Arrow.png - false + false diff --git a/resources/Schema/Entities/SidearmWeaponView.xml b/resources/Schema/Entities/SidearmWeaponView.xml index f01ffdf7..d3dcda66 100644 --- a/resources/Schema/Entities/SidearmWeaponView.xml +++ b/resources/Schema/Entities/SidearmWeaponView.xml @@ -24,7 +24,11 @@ - + + + + + @@ -52,6 +56,11 @@ + + Player + SidearmWeapon + MagazineAmmo + 16 Fonts/DroidSans.ttf,64 @@ -73,8 +82,8 @@ - + diff --git a/resources/Schema/Types/Entity.xsd b/resources/Schema/Types/Entity.xsd index f9870a51..b4ceb6d2 100644 --- a/resources/Schema/Types/Entity.xsd +++ b/resources/Schema/Types/Entity.xsd @@ -43,7 +43,7 @@ - + diff --git a/src/Engine/Core/EntityWrapper.cpp b/src/Engine/Core/EntityWrapper.cpp index b3bef55a..3c217353 100644 --- a/src/Engine/Core/EntityWrapper.cpp +++ b/src/Engine/Core/EntityWrapper.cpp @@ -34,6 +34,18 @@ EntityWrapper EntityWrapper::Parent() } } +EntityWrapper EntityWrapper::FirstParentByName(const std::string& parentEntityName) +{ + EntityWrapper entity = *this; + while (entity.Parent().Valid()) { + entity = entity.Parent(); + if (entity.Name() == parentEntityName) { + return entity; + } + } + return EntityWrapper::Invalid; +} + EntityWrapper EntityWrapper::FirstChildByName(const std::string& name) { return firstChildByNameRecursive(name, this->ID); diff --git a/src/Game/Game.cpp b/src/Game/Game.cpp index 7607efec..10107ab1 100644 --- a/src/Game/Game.cpp +++ b/src/Game/Game.cpp @@ -27,7 +27,7 @@ #include "../Engine/Core/UniformScaleSystem.h" #include "Rendering/AnimationSystem.h" #include "Network/MultiplayerSnapshotFilter.h" -#include "Game/Systems/AmmunitionHUDSystem.h" +#include "Game/Systems/TextFieldReader.h" #include "Game/Systems/CapturePointArrowHUDSystem.h" #include "Game/Systems/KillFeedSystem.h" #include "Game/Systems/BoostSystem.h" @@ -136,7 +136,7 @@ Game::Game(int argc, char* argv[]) m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); - m_SystemPipeline->AddSystem(updateOrderLevel); + m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); @@ -145,7 +145,7 @@ Game::Game(int argc, char* argv[]) m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); - m_SystemPipeline->AddSystem(updateOrderLevel); + m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel, m_Renderer); diff --git a/src/Game/Systems/AmmunitionHUDSystem.cpp b/src/Game/Systems/AmmunitionHUDSystem.cpp deleted file mode 100644 index c9d87072..00000000 --- a/src/Game/Systems/AmmunitionHUDSystem.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "Game/Systems/AmmunitionHUDSystem.h" - -void AmmunitionHUDSystem::Update(double dt) -{ - //Hud element for tracking ammunition from parent with AssaultWeapon component.Child with the name "MagazineAmmo" tracks clip ammunition.Child with the name "Ammo" tracks ammo. - - auto ammunitionHUDs = m_World->GetComponents("AmmunitionHUD"); - if (ammunitionHUDs == nullptr) { - return; - } - - for (auto& ammunitionHUDComponent : *ammunitionHUDs) { - EntityWrapper entity = EntityWrapper(m_World, ammunitionHUDComponent.EntityID); - - EntityWrapper playerEntity = entity.FirstParentWithComponent("AssaultWeapon"); - - if (!playerEntity.Valid()) { - return; - } - - - EntityWrapper magazineAmmo = entity.FirstChildByName("MagazineAmmo"); - if(magazineAmmo.Valid()) { - if(magazineAmmo.HasComponent("Text")) { - (std::string&)magazineAmmo["Text"]["Content"] = std::to_string((int)playerEntity["AssaultWeapon"]["MagazineAmmo"]); - } - } - - EntityWrapper ammo = entity.FirstChildByName("Ammo"); - if (ammo.Valid()) { - if (ammo.HasComponent("Text")) { - (std::string&)ammo["Text"]["Content"] = std::to_string((int)playerEntity["AssaultWeapon"]["Ammo"]); - } - } - } -} diff --git a/src/Game/Systems/TextFieldReader.cpp b/src/Game/Systems/TextFieldReader.cpp new file mode 100644 index 00000000..8712a61f --- /dev/null +++ b/src/Game/Systems/TextFieldReader.cpp @@ -0,0 +1,46 @@ +#include "Game/Systems/TextFieldReader.h" + +void TextFieldReader::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cAmmunitionHUD, double dt) +{ + if (!entity.HasComponent("Text")) { + return; + } + + // Find the entity to read from + const std::string& parentEntityName = cAmmunitionHUD["ParentEntityName"]; + EntityWrapper readEntity = entity; + if (!parentEntityName.empty()) { + readEntity = entity.FirstParentByName(parentEntityName); + if (!readEntity.Valid()) { + return; + } + } + + // Find the component to read from + const std::string& componentType = cAmmunitionHUD["ComponentType"]; + if (componentType.empty() || !readEntity.HasComponent(componentType)) { + return; + } + ComponentWrapper component = readEntity[componentType]; + + // Find the field to read from + const std::string& fieldName = cAmmunitionHUD["Field"]; + if (fieldName.empty() || component.Info.Fields.count(fieldName) == 0) { + return; + } + const ComponentInfo::Field_t& field = component.Info.Fields.at(fieldName); + + std::string& text = entity["Text"]["Content"]; + + if (field.Type == "int") { + text = boost::lexical_cast((const int&)component[fieldName]); + } else if (field.Type == "float") { + text = boost::lexical_cast((const float&)component[fieldName]); + } else if (field.Type == "double") { + text = boost::lexical_cast((const double&)component[fieldName]); + } else if (field.Type == "bool") { + text = boost::lexical_cast((const bool&)component[fieldName]); + } else if (field.Type == "string") { + text = (const std::string&)component[fieldName]; + } +} From 362378536e9438b5c311dfddf31e24b6ecca5dbc Mon Sep 17 00:00:00 2001 From: viktorljung Date: Thu, 3 Mar 2016 01:39:12 +0100 Subject: [PATCH 110/130] Switching rooms --- include/Engine/Rendering/AnimationSystem.h | 3 + include/Engine/Rendering/AutoBlendQueue.h | 27 + include/Engine/Rendering/BlendTree.h | 3 + .../Engine/Rendering/EAutoAnimationBlend.h | 7 +- resources/Schema/Entities/AnimationTests2.xml | 1040 ++++++----------- resources/Schema/Entities/BlendTreeTest.xml | 557 +++++++++ resources/Schema/Entities/ble | 145 +++ src/Engine/Rendering/AnimationSystem.cpp | 294 ++++- src/Engine/Rendering/AutoBlendQueue.cpp | 0 src/Engine/Rendering/BlendTree.cpp | 15 + 10 files changed, 1375 insertions(+), 716 deletions(-) create mode 100644 include/Engine/Rendering/AutoBlendQueue.h create mode 100644 resources/Schema/Entities/BlendTreeTest.xml create mode 100644 resources/Schema/Entities/ble create mode 100644 src/Engine/Rendering/AutoBlendQueue.cpp diff --git a/include/Engine/Rendering/AnimationSystem.h b/include/Engine/Rendering/AnimationSystem.h index 1ea076fd..fd53022f 100644 --- a/include/Engine/Rendering/AnimationSystem.h +++ b/include/Engine/Rendering/AnimationSystem.h @@ -57,10 +57,13 @@ private: EntityWrapper RootNode = EntityWrapper::Invalid; double Duration; double CurrentTime = 0.0; + double Delay = 0.0; BlendTree::AutoBlendInfo BlendInfo; }; + std::list m_AutoBlendJobs; + std::unordered_map m_QueuedAutoBlendJobs; std::list m_BlendJobs; std::list m_QueuedBlendJobs; diff --git a/include/Engine/Rendering/AutoBlendQueue.h b/include/Engine/Rendering/AutoBlendQueue.h new file mode 100644 index 00000000..12dd249e --- /dev/null +++ b/include/Engine/Rendering/AutoBlendQueue.h @@ -0,0 +1,27 @@ +#ifndef AutoBlendQueue_h__ +#define AutoBlendQueue_h__ + +#include "../Core/ResourceManager.h" +#include "Skeleton.h" +#include "Model.h" +#include "BlendTree.h" + +class AutoBlendQueue +{ +public: + struct AutoBlendJob + { + EntityWrapper RootNode = EntityWrapper::Invalid; + double Duration; + double CurrentTime = 0.0; + double Delay = 0.0; + BlendTree::AutoBlendInfo BlendInfo; + }; + +private: + std::map m_BlendQueue; + + +}; + +#endif diff --git a/include/Engine/Rendering/BlendTree.h b/include/Engine/Rendering/BlendTree.h index 29ad3ca9..5605707a 100644 --- a/include/Engine/Rendering/BlendTree.h +++ b/include/Engine/Rendering/BlendTree.h @@ -60,9 +60,12 @@ public: { std::string NodeName; double progress; + bool Restart; + double AnimationSpeed; std::unordered_map StartWeights; }; + BlendTree(EntityWrapper ModelEntity, Skeleton* skeleton); ~BlendTree(); diff --git a/include/Engine/Rendering/EAutoAnimationBlend.h b/include/Engine/Rendering/EAutoAnimationBlend.h index b148664f..edd8e0bc 100644 --- a/include/Engine/Rendering/EAutoAnimationBlend.h +++ b/include/Engine/Rendering/EAutoAnimationBlend.h @@ -11,7 +11,12 @@ struct AutoAnimationBlend : Event { EntityWrapper RootNode = EntityWrapper::Invalid; std::string NodeName; - double Duration; + double Duration = 0.0; + double Delay = 0.0; + + + double AnimationSpeed = 1.0; + bool Restart = false; EntityWrapper AnimationEntity = EntityWrapper::Invalid; }; diff --git a/resources/Schema/Entities/AnimationTests2.xml b/resources/Schema/Entities/AnimationTests2.xml index aaa6de48..b5b46c85 100644 --- a/resources/Schema/Entities/AnimationTests2.xml +++ b/resources/Schema/Entities/AnimationTests2.xml @@ -3,7 +3,7 @@ - 0.40000000596046448 + 0.30000001192092896 3 @@ -21,7 +21,7 @@ - 0.80000001192092896 + 0 Models/Widgets/Lights/DirectionalLightWidget.mesh @@ -33,15 +33,15 @@ - + 8 - 0.20000000298023224 + 0.60000002384185791 - + @@ -49,12 +49,12 @@ - Aim + AimBlend FinalBlend 5 - Models/Characters/Defender/DefenderRed.mesh + Models/Characters/Assault/AssaultBlue.mesh @@ -66,110 +66,65 @@ Models/Weapons/Blue/AssaultWeaponBlue.mesh - - + - + - + - - 3 - - - - - - - - - - - AimRifleA - - false - true - + + AimPrimary + AimSecondary + 0 + - + + + + + AimRifleA + + false + true + + + + + + + + + AimSecWepA + + false + true + + + + + + - WeaponBlend + ReloadSwitchBlend MovementBlend - - - - ShootBlend - Reload - 0 - - - - - - - - ShootFast - ShootSlow - 1 - - - - - - - - ShootFastRifleU - - 1 - - - - - - - - - ShootRifleU - - 1 - - - - - - - - - - - ReloadSwitchU - - 1 - - - - - - - StandCrouchBlend - Jump + JumpDashBlend 0 @@ -185,100 +140,156 @@ - + - Walk - StrafeBlend - 1 + MovementBlend + Idle + 0 - + + + + RunWalkBlend + StrafeLRBlend + 0 + + + + + + + + Walk + Run + 1 + + + + + + + + WalkF + + + + + + + + + RunF + + 1 + + + + + + + + + + + Left + Right + 0 + + + + + + + + StrafeLeftF + + + + + + + + + StrafeRightF + + + + + + + + + + - CrouchWalkF - + IdleF + 1 - - - - Left - Right - 1 - - - - - - - - CrouchStrafeLeftF - - 1 - - - - - - - - - CrouchStrafeRightF - - 1 - - - - - - - - + - RunWalkBlend - StrafeBlend - 1 + MovementBlend + Idle - + - Run - Walk + Walk + StrafeLRBlend 0 - + - - RunF - - 1 - + + Left + Right + 0 + - + + + + + CrouchStrafeLeftF + + + + + + + + + CrouchStrafeRightF + + + + + + - WalkF - - 1 + CrouchWalkF @@ -286,33 +297,110 @@ - + + + + CrouchF + + 1 + + + + + + + + + + + + + Jump + DashBlend + 1 + + + + + + + + JumpF + + + + + + + + + + DashFBBlend + DashLRBlend + 0 + + + + + - Left - Right + DashForward + DashBackward 1 - + - StrafeLeftF - - 1 + DashForwardF + false - + - StrafeRightF - - 1 + DashBackwardF + + false + + + + + + + + + + + DashLeft + DashRight + 0 + + + + + + + + DashLeftF + + false + + + + + + + + + DashRightF + false @@ -324,543 +412,106 @@ - + + + + + + ReloadSwitch + WeaponActionBlend + 1 + + + + + - JumpF - + ReloadSwitchU + 1 + + + + IdleBlend + ShootBlend + 1 + + + + + + + + IdlePrimary + IdleSecondary + + + + + + + + IdleAssaultRifleU + + + + + + + + + IdleSecWepU + + + + + + + + + + + ShootPrimary + ShootSecondary + 0 + + + + + + + + ShootFastRifleU + + 1 + + + + + + + + + ShootSecWepFastU + + + + + + + + + - - - - - - - - - - - R_Arm_Weapon_Joint - - - - Models/Core/UnitCube.mesh - - true - - - - - - - - - - - - - R_Hand - - true - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - R_Arm - - true - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - R_Shoulder - - true - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - Neck - - true - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - Spine_3 - - true - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - Spine_2 - - true - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - Spine_1 - - true - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - Hip - - true - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - L_Leg_Top - - true - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - L_Leg_Bottom - - true - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - L_Foot - - true - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - L_Toe - - true - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - L_Shoulder - - true - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - L_Arm - - true - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - L_Hand - - true - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - L_Shoulder_Armor_Joint - - true - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - Chin - - true - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - Head - - true - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - Perietal - - true - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - L_Elbow - - true - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - R_Leg_Bottom - - true - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - R_Elbow - - true - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - R_Leg_Top - - true - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - R_Foot - - true - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - R_Toe - - true - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - R_Shoulder_Armor_Joint - - true - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - @@ -874,6 +525,31 @@ + + + + + 8 + 0.60000002384185791 + + + + + + + + + + + 8 + 0.80000001192092896 + + + + + + + diff --git a/resources/Schema/Entities/BlendTreeTest.xml b/resources/Schema/Entities/BlendTreeTest.xml new file mode 100644 index 00000000..3457fc5e --- /dev/null +++ b/resources/Schema/Entities/BlendTreeTest.xml @@ -0,0 +1,557 @@ + + + + + + 0.30000001192092896 + 3 + + + + + + + + + + + + + + + + + 0 + + + Models/Widgets/Lights/DirectionalLightWidget.mesh + + + + + + + + + + + + + 8 + 0.60000002384185791 + + + + + + + + + + + AimBlend + FinalBlend + + + 5 + Models/Characters/Assault/AssaultBlue.mesh + + + + + + + + R_Arm_Weapon_Joint + + + Models/Weapons/Blue/AssaultWeaponBlue.mesh + + + + + + + + + + + + + AimPrimary + AimSecondary + 0 + + + + + + + + AimRifleA + + false + true + + + + + + + + + AimSecWepA + + false + true + + + + + + + + + + + ReloadSwitchBlend + MovementBlend + + + + + + + + StandCrouchBlend + JumpDashBlend + 0 + + + + + + + + StandMovement + CrouchMovement + 0 + + + + + + + + MovementBlend + Idle + 0 + + + + + + + + RunWalkBlend + StrafeLRBlend + 0 + + + + + + + + Walk + Run + 1 + + + + + + + + WalkF + + + + + + + + + RunF + + 1 + + + + + + + + + + + Left + Right + 0 + + + + + + + + StrafeLeftF + + + + + + + + + StrafeRightF + + + + + + + + + + + + + IdleF + + 1 + + + + + + + + + + + MovementBlend + Idle + + + + + + + + Walk + StrafeLRBlend + 0 + + + + + + + + Left + Right + 0 + + + + + + + + CrouchStrafeLeftF + + + + + + + + + CrouchStrafeRightF + + + + + + + + + + + CrouchWalkF + + + + + + + + + + + CrouchF + + 1 + + + + + + + + + + + + + Jump + DashBlend + 1 + + + + + + + + JumpF + + + + + + + + + + DashFBBlend + DashLRBlend + 0 + + + + + + + + DashForward + DashBackward + 1 + + + + + + + + DashForwardF + false + + + + + + + + + DashBackwardF + + false + + + + + + + + + + + DashLeft + DashRight + 0 + + + + + + + + DashLeftF + + false + + + + + + + + + DashRightF + false + + + + + + + + + + + + + + + + + ReloadSwitch + WeaponActionBlend + 1 + + + + + + + + ReloadSwitchU + + 1 + + + + + + + + + IdleBlend + ShootBlend + 1 + + + + + + + + IdlePrimary + IdleSecondary + + + + + + + + IdleAssaultRifleU + + + + + + + + + IdleSecWepU + + + + + + + + + + + ShootPrimary + ShootSecondary + 0 + + + + + + + + ShootFastRifleU + + 1 + + + + + + + + + ShootSecWepFastU + + + + + + + + + + + + + + + + + + + Models/Core/UnitPlane.mesh + + + + + + + + + + + + 8 + 0.60000002384185791 + + + + + + + + + + + 8 + 0.80000001192092896 + + + + + + + + + + + + diff --git a/resources/Schema/Entities/ble b/resources/Schema/Entities/ble new file mode 100644 index 00000000..6518ee5b --- /dev/null +++ b/resources/Schema/Entities/ble @@ -0,0 +1,145 @@ + + + + + + 0.30000001192092896 + 3 + + + + + + + + + + + + + + + + + 0 + + + Models/Widgets/Lights/DirectionalLightWidget.mesh + + + + + + + + + + + + + 8 + 0.60000002384185791 + + + + + + + + + + + + + + + 5 + Models/Characters/Defender/DefenderBlue.mesh + + + + + + + + R_Arm_Weapon_Joint + + + Models/Weapons/Blue/AssaultWeaponBlue.mesh + + + + + + + + + + + AimPrimary + AimSecondary + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + Models/Core/UnitPlane.mesh + + + + + + + + + + + + 8 + 0.60000002384185791 + + + + + + + + + + + 8 + 0.80000001192092896 + + + + + + + + + + + + diff --git a/src/Engine/Rendering/AnimationSystem.cpp b/src/Engine/Rendering/AnimationSystem.cpp index 11a21881..4e7f15f6 100644 --- a/src/Engine/Rendering/AnimationSystem.cpp +++ b/src/Engine/Rendering/AnimationSystem.cpp @@ -92,9 +92,30 @@ void AnimationSystem::UpdateAnimations(double dt) double animationSpeed = (double)animationC["Speed"]; if (animationSpeed != 0.0) { + double nextTime = (double)animationC["Time"] + animationSpeed * dt; + //Pre animation end blend + if (m_QueuedAutoBlendJobs.find(entity) != m_QueuedAutoBlendJobs.end()) { + if (glm::sign(m_QueuedAutoBlendJobs.at(entity).Delay) < 0) { + if (!(bool)animationC["Loop"]) { + if (nextTime > animation->Duration + m_QueuedAutoBlendJobs.at(entity).Delay && glm::sign(animationSpeed) > 0) { + AnimationComplete(entity); + } else if (nextTime < 0 - m_QueuedAutoBlendJobs.at(entity).Delay && glm::sign(animationSpeed) < 0) { + AnimationComplete(entity); + } + } else { + if (nextTime > animation->Duration + m_QueuedAutoBlendJobs.at(entity).Delay && glm::sign(animationSpeed) > 0) { + AnimationComplete(entity); + } else if (nextTime < 0 - m_QueuedAutoBlendJobs.at(entity).Delay && glm::sign(animationSpeed) < 0) { + AnimationComplete(entity); + } + } + } + } + + if (!(bool)animationC["Loop"]) { if (nextTime > animation->Duration) { nextTime = animation->Duration; @@ -119,6 +140,7 @@ void AnimationSystem::UpdateAnimations(double dt) e.Entity = entity; e.Name = (std::string)animationC["AnimationName"]; m_EventBroker->Publish(e); + AnimationComplete(entity); while (nextTime > animation->Duration) { nextTime -= animation->Duration; @@ -128,13 +150,12 @@ void AnimationSystem::UpdateAnimations(double dt) e.Entity = entity; e.Name = (std::string)animationC["AnimationName"]; m_EventBroker->Publish(e); - + AnimationComplete(entity); while (nextTime < 0) { nextTime += animation->Duration; } } } - (double&)animationC["Time"] = nextTime; } } @@ -143,7 +164,7 @@ void AnimationSystem::UpdateAnimations(double dt) void AnimationSystem::UpdateWeights(double dt) { - /* for (auto it = m_BlendJobs.begin(); it != m_BlendJobs.end(); it++) { + for (auto it = m_BlendJobs.begin(); it != m_BlendJobs.end();) { if (!it->BlendEntity.Valid()) { it = m_BlendJobs.erase(it); continue; @@ -161,7 +182,9 @@ void AnimationSystem::UpdateWeights(double dt) it = m_BlendJobs.erase(it); } } - }*/ + + ++it; + } for (auto it = m_AutoBlendJobs.begin(); it != m_AutoBlendJobs.end();) { @@ -214,7 +237,7 @@ void AnimationSystem::UpdateWeights(double dt) void AnimationSystem::AnimationComplete(EntityWrapper animationEntity) { - for (auto it = m_QueuedBlendJobs.begin(); it != m_QueuedBlendJobs.end(); it++) { + for (auto it = m_QueuedBlendJobs.begin(); it != m_QueuedBlendJobs.end();) { if (!it->BlendEntity.Valid() || !it->AnimationEntity.Valid()) { it = m_QueuedBlendJobs.erase(it); continue; @@ -229,10 +252,28 @@ void AnimationSystem::AnimationComplete(EntityWrapper animationEntity) bj.CurrentTime = 0.0; m_BlendJobs.push_back(bj); it = m_QueuedBlendJobs.erase(it); + continue; } + ++it; } + + if (m_QueuedAutoBlendJobs.find(animationEntity) != m_QueuedAutoBlendJobs.end()) { + AutoBlendJob abj = m_QueuedAutoBlendJobs.at(animationEntity); + + if (!abj.RootNode.Valid() || !animationEntity.Valid()) { + m_QueuedAutoBlendJobs.erase(animationEntity); + } else { + m_AutoBlendJobs.push_back(abj); + m_QueuedAutoBlendJobs.erase(animationEntity); + } + + + + } + + } bool AnimationSystem::OnAnimationBlend(Events::AnimationBlend& e) @@ -256,17 +297,16 @@ bool AnimationSystem::OnAnimationBlend(Events::AnimationBlend& e) m_QueuedBlendJobs.push_back(qbj); return true; } + } else { + BlendJob bj; + bj.BlendEntity = e.BlendEntity; + bj.StartWeight = (double)e.BlendEntity["Blend"]["Weight"]; + bj.GoalWeight = e.GoalWeight; + bj.Duration = e.Duration; + bj.CurrentTime = 0.0; + m_BlendJobs.push_back(bj); + return true; } - - BlendJob bj; - bj.BlendEntity = e.BlendEntity; - bj.StartWeight = (double)e.BlendEntity["Blend"]["Weight"]; - bj.GoalWeight = e.GoalWeight; - bj.Duration = e.Duration; - bj.CurrentTime = 0.0; - m_BlendJobs.push_back(bj); - - return true; } @@ -280,18 +320,39 @@ bool AnimationSystem::OnAutoAnimationBlend(Events::AutoAnimationBlend& e) return false; } - AutoBlendJob abj; - abj.RootNode = e.RootNode; - abj.CurrentTime = 0.0; - abj.Duration = e.Duration; + if (e.AnimationEntity.Valid()) { + AutoBlendJob abj; + abj.RootNode = e.RootNode; + abj.CurrentTime = 0.0; + abj.Duration = e.Duration; + abj.Delay = e.Delay; - BlendTree::AutoBlendInfo abInfo; - abInfo.NodeName = e.NodeName; - abInfo.progress = 0.0; - - abj.BlendInfo = abInfo; + BlendTree::AutoBlendInfo abInfo; + abInfo.NodeName = e.NodeName; + abInfo.progress = 0.0; + abInfo.Restart = e.Restart; + abInfo.AnimationSpeed = e.AnimationSpeed; + abj.BlendInfo = abInfo; - m_AutoBlendJobs.push_back(abj); + m_QueuedAutoBlendJobs[e.AnimationEntity] = abj; + return true; + } else { + AutoBlendJob abj; + abj.RootNode = e.RootNode; + abj.CurrentTime = 0.0; + abj.Duration = e.Duration; + + BlendTree::AutoBlendInfo abInfo; + abInfo.NodeName = e.NodeName; + abInfo.progress = 0.0; + abInfo.Restart = e.Restart; + abInfo.AnimationSpeed = e.AnimationSpeed; + + abj.BlendInfo = abInfo; + + m_AutoBlendJobs.push_back(abj); + return true; + } } @@ -301,8 +362,6 @@ bool AnimationSystem::OnInputCommand(const Events::InputCommand& e) if (e.Value == 1.f) { if (e.Command == "BlendTest0") { - - auto blendComponents = m_World->GetComponents("BlendAdditive"); if (blendComponents == nullptr) { @@ -314,11 +373,12 @@ bool AnimationSystem::OnInputCommand(const Events::InputCommand& e) EntityWrapper entity = EntityWrapper(m_World, bc.EntityID); if (entity.Name() == "Assault") { - Events::AutoAnimationBlend aeb; aeb.Duration = m_BlendTime1; aeb.NodeName = m_AnimationName1; aeb.RootNode = entity; + aeb.Restart = true; + m_EventBroker->Publish(aeb); } @@ -338,15 +398,183 @@ bool AnimationSystem::OnInputCommand(const Events::InputCommand& e) if (entity.Name() == "Assault") { - Events::AutoAnimationBlend aeb; - aeb.Duration = m_BlendTime2; - aeb.NodeName = m_AnimationName2; - aeb.RootNode = entity; - m_EventBroker->Publish(aeb); + { + Events::AutoAnimationBlend aeb; + aeb.Duration = m_BlendTime2; + aeb.NodeName = m_AnimationName2; + aeb.RootNode = entity; + aeb.Restart = true; + m_EventBroker->Publish(aeb); + } + + { + Events::AutoAnimationBlend aeb; + aeb.Duration = m_BlendTime2; + aeb.NodeName = "Run"; + aeb.RootNode = entity; + aeb.Restart = true; + aeb.AnimationEntity = entity.FirstChildByName("DashLeft"); + m_EventBroker->Publish(aeb); + } } } } + + + if(e.Command == "DashForward") { + auto blendComponents = m_World->GetComponents("BlendAdditive"); + + if (blendComponents == nullptr) { + return false; + } + for (auto& bc : *blendComponents) { + EntityWrapper entity = EntityWrapper(m_World, bc.EntityID); + + if (entity.Name() == "Assault") { + { + Events::AutoAnimationBlend aeb; + aeb.Duration = 0.1; + aeb.NodeName = "DashForward"; + aeb.RootNode = entity; + aeb.Restart = true; + m_EventBroker->Publish(aeb); + } + { + Events::AutoAnimationBlend aeb; + aeb.Duration = 0.3; + aeb.NodeName = "Run"; + aeb.RootNode = entity; + aeb.Restart = true; + aeb.Delay = 0; + aeb.AnimationEntity = entity.FirstChildByName("DashForward"); + m_EventBroker->Publish(aeb); + } + } + } + + } else if (e.Command == "DashBackward") { + auto blendComponents = m_World->GetComponents("BlendAdditive"); + + if (blendComponents == nullptr) { + return false; + } + for (auto& bc : *blendComponents) { + EntityWrapper entity = EntityWrapper(m_World, bc.EntityID); + + if (entity.Name() == "Assault") { + { + Events::AutoAnimationBlend aeb; + aeb.Duration = 0.1; + aeb.NodeName = "DashBackward"; + aeb.RootNode = entity; + aeb.Restart = true; + m_EventBroker->Publish(aeb); + } + { + Events::AutoAnimationBlend aeb; + aeb.Duration = 0.3; + aeb.NodeName = "Run"; + aeb.RootNode = entity; + aeb.Restart = true; + aeb.Delay = -0.3; + aeb.AnimationEntity = entity.FirstChildByName("DashBackward"); + m_EventBroker->Publish(aeb); + } + } + } + } else if (e.Command == "DashLeft") { + auto blendComponents = m_World->GetComponents("BlendAdditive"); + + if (blendComponents == nullptr) { + return false; + } + for (auto& bc : *blendComponents) { + EntityWrapper entity = EntityWrapper(m_World, bc.EntityID); + + if (entity.Name() == "Assault") { + { + Events::AutoAnimationBlend aeb; + aeb.Duration = 0.1; + aeb.NodeName = "DashLeft"; + aeb.RootNode = entity; + aeb.Restart = true; + m_EventBroker->Publish(aeb); + } + { + Events::AutoAnimationBlend aeb; + aeb.Duration = 0.3; + aeb.NodeName = "Run"; + aeb.RootNode = entity; + aeb.Restart = true; + aeb.Delay = -0.3; + aeb.AnimationEntity = entity.FirstChildByName("DashLeft"); + m_EventBroker->Publish(aeb); + } + } + } + } else if (e.Command == "DashRight") { + auto blendComponents = m_World->GetComponents("BlendAdditive"); + + if (blendComponents == nullptr) { + return false; + } + for (auto& bc : *blendComponents) { + EntityWrapper entity = EntityWrapper(m_World, bc.EntityID); + + if (entity.Name() == "Assault") { + { + Events::AutoAnimationBlend aeb; + aeb.Duration = 0.1; + aeb.NodeName = "DashRight"; + aeb.RootNode = entity; + aeb.Restart = true; + m_EventBroker->Publish(aeb); + } + { + Events::AutoAnimationBlend aeb; + aeb.Duration = 0.3; + aeb.NodeName = "Run"; + aeb.RootNode = entity; + aeb.Restart = true; + aeb.AnimationEntity = entity.FirstChildByName("DashRight"); + aeb.Delay = -0.3; + m_EventBroker->Publish(aeb); + } + } + } + } else if (e.Command == "Jump") { + auto blendComponents = m_World->GetComponents("BlendAdditive"); + + if (blendComponents == nullptr) { + return false; + } + for (auto& bc : *blendComponents) { + EntityWrapper entity = EntityWrapper(m_World, bc.EntityID); + + if (entity.Name() == "Assault") { + { + Events::AutoAnimationBlend aeb; + aeb.Duration = 0.35; + aeb.NodeName = "Jump"; + aeb.RootNode = entity; + aeb.Restart = true; + m_EventBroker->Publish(aeb); + } + { + Events::AutoAnimationBlend aeb; + aeb.Duration = 0.35; + aeb.NodeName = "Run"; + aeb.RootNode = entity; + aeb.Restart = false; + aeb.AnimationEntity = entity.FirstChildByName("Jump"); + m_EventBroker->Publish(aeb); + } + } + } + } + + } } diff --git a/src/Engine/Rendering/AutoBlendQueue.cpp b/src/Engine/Rendering/AutoBlendQueue.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/Engine/Rendering/BlendTree.cpp b/src/Engine/Rendering/BlendTree.cpp index 8b044134..f7381d4d 100644 --- a/src/Engine/Rendering/BlendTree.cpp +++ b/src/Engine/Rendering/BlendTree.cpp @@ -207,6 +207,21 @@ BlendTree::AutoBlendInfo BlendTree::AutoBlendStep(AutoBlendInfo blendInfo) { std::vector goalNodes = FindNodesByName(blendInfo.NodeName); + if (blendInfo.Restart) { + for (auto it = goalNodes.begin(); it != goalNodes.end(); it++) { + EntityWrapper entity = (*it)->Entity; + + if (entity.Valid()) { + if (entity.HasComponent("Animation")) { + (double&)entity["Animation"]["Time"] = 0.0; + (double&)entity["Animation"]["Speed"] = blendInfo.AnimationSpeed; + } + } + } + blendInfo.Restart = false; + } + + if(goalNodes.size() == 0) { return blendInfo; } else if(goalNodes.size() == 1) { From 7ea26d10eeca755564d52ad6cf736981b596bb3c Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Thu, 3 Mar 2016 03:28:21 +0100 Subject: [PATCH 111/130] Rewritten. Works as a charm now. --- .../Engine/Rendering/DirectionalLightJob.h | 7 +- include/Engine/Rendering/DrawFinalPass.h | 2 +- include/Engine/Rendering/Renderer.h | 4 +- include/Engine/Rendering/ShadowPass.h | 13 +- include/Engine/Rendering/ShadowPassState.h | 4 +- resources/Shaders/ForwardPlus.frag.glsl | 135 ++++++++------- .../Shaders/ForwardPlusShieldCheck.frag.glsl | 2 + .../Shaders/ForwardPlusSkinned.vert.glsl | 10 +- .../Shaders/ForwardPlusSplatMap.frag.glsl | 3 + .../Shaders/ForwardPlusSplatMapRGB.frag.glsl | 1 + resources/Shaders/Shadow.frag.glsl | 4 +- src/Engine/Editor/EditorRenderSystem.cpp | 2 +- src/Engine/Editor/EditorSystem.cpp | 5 +- src/Engine/Rendering/DrawFinalPass.cpp | 16 +- src/Engine/Rendering/FrameBuffer.cpp | 32 ++-- src/Engine/Rendering/RenderSystem.cpp | 2 +- src/Engine/Rendering/Renderer.cpp | 16 +- src/Engine/Rendering/ShadowPass.cpp | 157 +++++++++--------- src/Engine/Rendering/ShadowPassState.cpp | 8 +- 19 files changed, 224 insertions(+), 199 deletions(-) diff --git a/include/Engine/Rendering/DirectionalLightJob.h b/include/Engine/Rendering/DirectionalLightJob.h index 96b2ec9c..5f104ca5 100644 --- a/include/Engine/Rendering/DirectionalLightJob.h +++ b/include/Engine/Rendering/DirectionalLightJob.h @@ -15,17 +15,16 @@ struct DirectionalLightJob : RenderJob DirectionalLightJob(ComponentWrapper transformComponent, ComponentWrapper directionalLightComponent, World* m_World) : RenderJob() { - Orientation = Transform::AbsoluteOrientation(m_World, transformComponent.EntityID); - Direction = glm::vec4(0,0,-1,0) * glm::inverse(Orientation); + + Direction = glm::vec4(0,0,-1,0) * glm::inverse(Transform::AbsoluteOrientation(m_World, transformComponent.EntityID)); + //Direction = glm::vec4((glm::vec3)directionalLightComponent["Direction"], 0.f); Color = (glm::vec4)directionalLightComponent["Color"]; Intensity = (double)directionalLightComponent["Intensity"]; }; - glm::quat Orientation; glm::vec4 Direction; glm::vec4 Color; float Intensity; - bool TextureAlphaShadows = false; void CalculateHash() override { diff --git a/include/Engine/Rendering/DrawFinalPass.h b/include/Engine/Rendering/DrawFinalPass.h index 82ae216d..c5b937c6 100644 --- a/include/Engine/Rendering/DrawFinalPass.h +++ b/include/Engine/Rendering/DrawFinalPass.h @@ -64,9 +64,9 @@ private: const IRenderer* m_Renderer; const LightCullingPass* m_LightCullingPass; - const ShadowPass* m_ShadowPass; const CubeMapPass* m_CubeMapPass; const SSAOPass* m_SSAOPass; + const ShadowPass* m_ShadowPass; ShaderProgram* m_ForwardPlusProgram; ShaderProgram* m_ExplosionEffectProgram; diff --git a/include/Engine/Rendering/Renderer.h b/include/Engine/Rendering/Renderer.h index 75517442..fd3b215e 100644 --- a/include/Engine/Rendering/Renderer.h +++ b/include/Engine/Rendering/Renderer.h @@ -24,9 +24,9 @@ #include "../Core/Transform.h" #include "imgui/imgui.h" #include "TextPass.h" -#include "ShadowPass.h" #include "Util/CommonFunctions.h" #include "Core/PerformanceTimer.h" +#include "ShadowPass.h" class Renderer : public IRenderer { @@ -74,9 +74,9 @@ private: DrawScreenQuadPass* m_DrawScreenQuadPass; DrawBloomPass* m_DrawBloomPass; DrawColorCorrectionPass* m_DrawColorCorrectionPass; - ShadowPass* m_ShadowPass; SSAOPass* m_SSAOPass; CubeMapPass* m_CubeMapPass; + ShadowPass* m_ShadowPass; //----------------------Functions----------------------// void InitializeWindow(); diff --git a/include/Engine/Rendering/ShadowPass.h b/include/Engine/Rendering/ShadowPass.h index 372ba6f2..6db8a624 100644 --- a/include/Engine/Rendering/ShadowPass.h +++ b/include/Engine/Rendering/ShadowPass.h @@ -1,5 +1,5 @@ -#ifndef ShadowPass_h_ -#define ShadowPass_h_ +#ifndef ShadowPass_h__ +#define ShadowPass_h__ #include "IRenderer.h" #include "FrameBuffer.h" @@ -38,6 +38,8 @@ public: void ClearBuffer(); void Draw(RenderScene& scene); + void DebugGUI(); + GLuint DepthMap() const { return m_DepthMap; } std::array LightP() const { return m_LightProjection; } std::array LightV() const { return m_LightView; } @@ -62,7 +64,6 @@ private: GLuint m_DepthMap; FrameBuffer m_DepthBuffer; ShaderProgram* m_ShadowProgram; - //ShaderProgram* m_TransparentShadowProgram; std::array m_LightProjection; std::array m_LightView; @@ -71,8 +72,12 @@ private: GLuint m_ResolutionSizeWidth = 1024 * 2; GLuint m_ResolutionSizeHeight = 1024 * 2; + bool m_TransparentObjects = false; + bool m_TexturedShadows = false; + bool m_EnableShadows = true; + int m_CurrentNrOfSplits = 4; - float m_SplitWeight = 0.91f; + float m_SplitWeight = 0.962f; std::array m_shadowFrusta; diff --git a/include/Engine/Rendering/ShadowPassState.h b/include/Engine/Rendering/ShadowPassState.h index ec08a77c..f881b48e 100644 --- a/include/Engine/Rendering/ShadowPassState.h +++ b/include/Engine/Rendering/ShadowPassState.h @@ -6,8 +6,8 @@ class ShadowPassState : public RenderState { public: - ShadowPassState(GLuint frameBuffer); - ~ShadowPassState(); + ShadowPassState(GLuint frameBuffer); + ~ShadowPassState(); private: }; diff --git a/resources/Shaders/ForwardPlus.frag.glsl b/resources/Shaders/ForwardPlus.frag.glsl index baf1baf1..f7ddd00c 100644 --- a/resources/Shaders/ForwardPlus.frag.glsl +++ b/resources/Shaders/ForwardPlus.frag.glsl @@ -1,7 +1,7 @@ #version 430 -#define MAX_SPLITS 4 #define MIN_AMBIENT_LIGHT 0.3 +#define MAX_SPLITS 4 uniform mat4 M; uniform mat4 V; @@ -12,22 +12,22 @@ uniform vec2 ScreenDimensions; uniform vec4 FillColor; uniform vec4 AmbientColor; uniform float FillPercentage; -uniform float FarDistance[MAX_SPLITS]; uniform float GlowIntensity = 10; uniform vec3 CameraPosition; uniform int SSAOQuality; +uniform float FarDistance[MAX_SPLITS]; uniform vec2 DiffuseUVRepeat; uniform vec2 NormalUVRepeat; uniform vec2 SpecularUVRepeat; uniform vec2 GlowUVRepeat; layout (binding = 0) uniform sampler2D AOTexture; -layout (binding = 6) uniform sampler2DArrayShadow DepthMap; layout (binding = 1) uniform sampler2D DiffuseTexture; layout (binding = 2) uniform sampler2D NormalMapTexture; layout (binding = 3) uniform sampler2D SpecularMapTexture; layout (binding = 4) uniform sampler2D GlowMapTexture; layout (binding = 5) uniform samplerCube CubeMap; +layout (binding = 13) uniform sampler2DArrayShadow DepthMap; #define TILE_SIZE 16 @@ -62,7 +62,6 @@ layout (std430, binding = 4) buffer LightIndexBuffer float LightIndex[]; }; - in VertexData{ vec3 Position; vec3 Normal; @@ -155,6 +154,62 @@ float Random(vec3 seed, int i) return fract(sin(dot_product) * 43758.5453); } +int getShadowIndex(float far_distance[1]) +{ + return 0; +} + +int getShadowIndex(float far_distance[2]) +{ + float depth = gl_FragCoord.z / gl_FragCoord.w; + + int index = 1; + if ( depth < far_distance[0] ) + { + index = 0; + } + + return index; +} + +int getShadowIndex(float far_distance[3]) +{ + float depth = gl_FragCoord.z / gl_FragCoord.w; + + int index = 2; + if ( depth < far_distance[0] ) + { + index = 0; + } + else if ( depth < far_distance[1] && depth > far_distance[0] ) + { + index = 1; + } + + return index; +} + +int getShadowIndex(float far_distance[4]) +{ + float depth = gl_FragCoord.z / gl_FragCoord.w; + + int index = 3; + if ( depth < far_distance[0] ) + { + index = 0; + } + else if ( depth < far_distance[1] && depth > far_distance[0] ) + { + index = 1; + } + else if ( depth < far_distance[2] && depth > far_distance[1] ) + { + index = 2; + } + + return index; +} + // Standard hardware-calculated PCF method float PCFShadow(sampler2DArrayShadow depth_texture_array, vec3 projection_coords, int layer_index) { @@ -237,62 +292,6 @@ float CalcShadowValue(vec4 light_space_pos, vec3 normal, vec3 light_dir, sampler shadowMapDepth = SoftwarePCF(depth_texture_array, projCoords, layer_index, bias); return shadowMapDepth; -} - -int getShadowIndex(float far_distance[1]) -{ - return 0; -} - -int getShadowIndex(float far_distance[2]) -{ - float depth = gl_FragCoord.z / gl_FragCoord.w; - - int index = 1; - if ( depth < far_distance[0] ) - { - index = 0; - } - - return index; -} - -int getShadowIndex(float far_distance[3]) -{ - float depth = gl_FragCoord.z / gl_FragCoord.w; - - int index = 2; - if ( depth < far_distance[0] ) - { - index = 0; - } - else if ( depth < far_distance[1] && depth > far_distance[0] ) - { - index = 1; - } - - return index; -} - -int getShadowIndex(float far_distance[4]) -{ - float depth = gl_FragCoord.z / gl_FragCoord.w; - - int index = 3; - if ( depth < far_distance[0] ) - { - index = 0; - } - else if ( depth < far_distance[1] && depth > far_distance[0] ) - { - index = 1; - } - else if ( depth < far_distance[2] && depth > far_distance[1] ) - { - index = 2; - } - - return index; } void main() @@ -322,14 +321,14 @@ void main() int start = int(LightGrids.Data[currentTile].Start); int amount = int(LightGrids.Data[currentTile].Amount); - - float shadowFactor = 0.0; + float shadowFactor = 0.0; + for(int i = start; i < start + amount; i++) { int l = int(LightIndex[i]); LightSource light = LightSources.List[l]; - + LightResult light_result; //These if statements should be removed. if(light.Type == 1) { // point @@ -342,17 +341,17 @@ void main() totalLighting.Diffuse += vec4(light_result.Diffuse.rgb * ao, light_result.Diffuse.a); totalLighting.Specular += vec4(light_result.Specular.rgb * ao, light_result.Specular.a); } - + totalLighting.Diffuse *= vec4(min(vec3(shadowFactor) + AmbientColor.xyz, vec3(1.0)), 1.0); totalLighting.Specular *= vec4(min(vec3(shadowFactor) + AmbientColor.xyz, vec3(1.0)), 1.0); - - //LightResult getInformation; - + vec4 color_result = mix((Color * diffuseTexel * DiffuseColor), Input.ExplosionColor, Input.ExplosionPercentageElapsed); - color_result = color_result * (totalLighting.Diffuse + (totalLighting.Specular * specularTexel)); + color_result = color_result * (totalLighting.Diffuse + (totalLighting.Specular * specularTexel)); float specularResult = (specularTexel.r + specularTexel.g + specularTexel.b)/3.0; vec4 reflectionTotal = reflectionColor * (1-specularTexel.a) * color_result.a; color_result = color_result * clamp(1/specularTexel.a, 0, 1) + reflectionTotal; + //vec4 color_result = (DiffuseColor + Input.ExplosionColor) * (totalLighting.Diffuse + (totalLighting.Specular * specularTexel)) * diffuseTexel * Color; + float pos = ((P * vec4(Input.Position, 1)).y + 1.0)/2.0; diff --git a/resources/Shaders/ForwardPlusShieldCheck.frag.glsl b/resources/Shaders/ForwardPlusShieldCheck.frag.glsl index 35db495b..8c7dce04 100644 --- a/resources/Shaders/ForwardPlusShieldCheck.frag.glsl +++ b/resources/Shaders/ForwardPlusShieldCheck.frag.glsl @@ -1,6 +1,7 @@ #version 430 #define MIN_AMBIENT_LIGHT 0.3 +#define MAX_SPLITS 4 uniform mat4 M; uniform mat4 V; @@ -69,6 +70,7 @@ in VertexData{ vec2 TextureCoordinate; vec4 ExplosionColor; float ExplosionPercentageElapsed; + vec4 PositionLightSpace[MAX_SPLITS]; }Input; out vec4 sceneColor; diff --git a/resources/Shaders/ForwardPlusSkinned.vert.glsl b/resources/Shaders/ForwardPlusSkinned.vert.glsl index 83db983b..12b3c406 100644 --- a/resources/Shaders/ForwardPlusSkinned.vert.glsl +++ b/resources/Shaders/ForwardPlusSkinned.vert.glsl @@ -1,9 +1,13 @@ #version 430 +#define MAX_SPLITS 4 + uniform mat4 M; uniform mat4 V; uniform mat4 P; uniform mat4 Bones[100]; +uniform mat4 LightV[MAX_SPLITS]; +uniform mat4 LightP[MAX_SPLITS]; layout(location = 0) in vec3 Position; layout(location = 1) in vec3 Normal; @@ -44,5 +48,9 @@ void main() Output.BiTangent = vec3(M * vec4(BiTangent, 0.0)); Output.ExplosionColor = vec4(1.0); Output.ExplosionPercentageElapsed = 0.0; - Output.PositionLightSpace = boneTransform * vec4(Position, 1.0); + + for(int i = 0; i < MAX_SPLITS; i++) + { + Output.PositionLightSpace[i] = LightP[i] * LightV[i] * M * boneTransform * vec4(Position, 1.0); + } } \ No newline at end of file diff --git a/resources/Shaders/ForwardPlusSplatMap.frag.glsl b/resources/Shaders/ForwardPlusSplatMap.frag.glsl index 239c51b5..655f5502 100644 --- a/resources/Shaders/ForwardPlusSplatMap.frag.glsl +++ b/resources/Shaders/ForwardPlusSplatMap.frag.glsl @@ -1,5 +1,7 @@ #version 430 +#define MAX_SPLITS 4 + uniform mat4 M; uniform mat4 V; uniform mat4 P; @@ -95,6 +97,7 @@ in VertexData{ vec2 TextureCoordinate; vec4 ExplosionColor; float ExplosionPercentageElapsed; + vec4 PositionLightSpace[MAX_SPLITS]; }Input; out vec4 sceneColor; diff --git a/resources/Shaders/ForwardPlusSplatMapRGB.frag.glsl b/resources/Shaders/ForwardPlusSplatMapRGB.frag.glsl index 87349c5d..f933a605 100644 --- a/resources/Shaders/ForwardPlusSplatMapRGB.frag.glsl +++ b/resources/Shaders/ForwardPlusSplatMapRGB.frag.glsl @@ -1,6 +1,7 @@ #version 430 #define MIN_AMBIENT_LIGHT 0.3 +#define MAX_SPLITS 4 uniform mat4 M; uniform mat4 V; diff --git a/resources/Shaders/Shadow.frag.glsl b/resources/Shaders/Shadow.frag.glsl index a03e17c7..c7d153c3 100644 --- a/resources/Shaders/Shadow.frag.glsl +++ b/resources/Shaders/Shadow.frag.glsl @@ -19,6 +19,4 @@ void main() { discard; } -} - - +} \ No newline at end of file diff --git a/src/Engine/Editor/EditorRenderSystem.cpp b/src/Engine/Editor/EditorRenderSystem.cpp index a829bc6a..f5fcc1a1 100644 --- a/src/Engine/Editor/EditorRenderSystem.cpp +++ b/src/Engine/Editor/EditorRenderSystem.cpp @@ -7,7 +7,7 @@ EditorRenderSystem::EditorRenderSystem(SystemParams params, IRenderer* renderer, { EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &EditorRenderSystem::OnSetCamera); auto resolution = Rectangle::Rectangle(1280, 720); - m_EditorCamera = new Camera((float)resolution.Width / resolution.Height, glm::radians(45.f), 0.01f, 500.f); + m_EditorCamera = new Camera((float)resolution.Width / resolution.Height, glm::radians(45.f), 0.01f, 5000.f); } void EditorRenderSystem::Update(double dt) diff --git a/src/Engine/Editor/EditorSystem.cpp b/src/Engine/Editor/EditorSystem.cpp index 0aefac9d..4bee1427 100644 --- a/src/Engine/Editor/EditorSystem.cpp +++ b/src/Engine/Editor/EditorSystem.cpp @@ -17,10 +17,7 @@ EditorSystem::EditorSystem(SystemParams params, IRenderer* renderer, RenderFrame m_EditorCamera = importEntity(EntityWrapper(m_EditorWorld, EntityID_Invalid), "Schema/Entities/Empty.xml"); m_ActualCamera = m_EditorCamera; m_EditorWorld->AttachComponent(m_EditorCamera.ID, "Transform"); - auto cCamera = m_EditorWorld->AttachComponent(m_EditorCamera.ID, "Camera"); - // TOBIAS TVINGADE MIG ATT HÅRDKODA - (double&)cCamera["FarClip"] = 400.0; - + m_EditorWorld->AttachComponent(m_EditorCamera.ID, "Camera"); m_EditorCameraInputController = new EditorCameraInputController(m_EventBroker, -1); m_EditorGUI = new EditorGUI(m_World, m_EventBroker); diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index 6152134a..510c665e 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -4,10 +4,10 @@ DrawFinalPass::DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCulling , m_LightCullingPass(lightCullingPass) , m_CubeMapPass(cubeMapPass) , m_SSAOPass(ssaoPass) + , m_ShadowPass(shadowPass) { //TODO: Make sure that uniforms are not sent into shader if not needed. m_ShieldPixelRate = 8; - m_ShadowPass = shadowPass; InitializeTextures(); InitializeShaderPrograms(); InitializeFrameBuffers(); @@ -343,7 +343,8 @@ void DrawFinalPass::DrawModelRenderQueues(std::list>& glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_SSAOPass->SSAOTexture()); - glActiveTexture(GL_TEXTURE6); + + glActiveTexture(GL_TEXTURE13); if (m_ShadowPass->DepthMap() != NULL) { glBindTexture(GL_TEXTURE_2D_ARRAY, m_ShadowPass->DepthMap()); } @@ -1091,10 +1092,10 @@ void DrawFinalPass::BindExplosionUniforms(GLuint shaderHandle, std::shared_ptrGlowIntensity); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "LightP"), MAX_SPLITS, GL_FALSE, glm::value_ptr(*m_ShadowPass->LightP().data())); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "LightV"), MAX_SPLITS, GL_FALSE, glm::value_ptr(*m_ShadowPass->LightV().data())); glUniform1fv(glGetUniformLocation(shaderHandle, "FarDistance"), MAX_SPLITS, m_ShadowPass->FarDistance().data()); - GLERROR("END"); } @@ -1133,12 +1134,10 @@ void DrawFinalPass::BindModelUniforms(GLuint shaderHandle, std::shared_ptrGlowIntensity); - glUniform1f(Location_GlowIntensity, job->GlowIntensity); - - //Shadow - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "LightP"), MAX_SPLITS, GL_FALSE, glm::value_ptr(*m_ShadowPass->LightP().data())); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "LightV"), MAX_SPLITS, GL_FALSE, glm::value_ptr(*m_ShadowPass->LightV().data())); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "LightP"), MAX_SPLITS, GL_FALSE, glm::value_ptr(*m_ShadowPass->LightP().data())); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "LightV"), MAX_SPLITS, GL_FALSE, glm::value_ptr(*m_ShadowPass->LightV().data())); glUniform1fv(glGetUniformLocation(shaderHandle, "FarDistance"), MAX_SPLITS, m_ShadowPass->FarDistance().data()); GLERROR("END"); @@ -1309,7 +1308,6 @@ void DrawFinalPass::BindModelTextures(GLuint shaderHandle, std::shared_ptrm_Texture); glUniform2fv(glGetUniformLocation(shaderHandle, "GlowUVRepeat"), 1, glm::value_ptr(glm::vec2(1.0f, 1.0f))); } - break; } case RawModel::MaterialType::SplatMapping: diff --git a/src/Engine/Rendering/FrameBuffer.cpp b/src/Engine/Rendering/FrameBuffer.cpp index 903eb2a0..c08d4dc4 100644 --- a/src/Engine/Rendering/FrameBuffer.cpp +++ b/src/Engine/Rendering/FrameBuffer.cpp @@ -16,6 +16,7 @@ Texture2D::~Texture2D() } } + RenderBuffer::~RenderBuffer() { if (m_ResourceHandle != 0) { @@ -51,7 +52,6 @@ void FrameBuffer::Generate() switch ((*it)->m_ResourceType) { case GL_TEXTURE_2D: glFramebufferTexture2D(GL_FRAMEBUFFER, (*it)->m_Attachment, (*it)->m_ResourceType, *(*it)->m_ResourceHandle, 0); - attachments.push_back((*it)->m_Attachment); GLERROR("FrameBuffer generate: glFramebufferTexture2D"); break; case GL_RENDERBUFFER: @@ -60,13 +60,13 @@ void FrameBuffer::Generate() break; case GL_TEXTURE_2D_ARRAY: glFramebufferTexture(GL_FRAMEBUFFER, (*it)->m_Attachment, *(*it)->m_ResourceHandle, 0); - attachments.push_back((*it)->m_Attachment); - GLERROR("FrameBuffer generate: GL_TEXTURE_2D_ARRAY"); + GLERROR("FrameBuffer generate: glFramebufferTexture2DArray"); break; } GLERROR("2"); - if ((*it)->m_Attachment != GL_DEPTH_ATTACHMENT && (*it)->m_Attachment != GL_STENCIL_ATTACHMENT && (*it)->m_Attachment != GL_DEPTH_STENCIL_ATTACHMENT) { + // Need GL_DEPTH_ATTACHMENT for shadows + if (/*(*it)->m_Attachment != GL_DEPTH_ATTACHMENT &&*/ (*it)->m_Attachment != GL_STENCIL_ATTACHMENT && (*it)->m_Attachment != GL_DEPTH_STENCIL_ATTACHMENT) { attachments.push_back((*it)->m_Attachment); } GLERROR("Attachment"); @@ -74,19 +74,19 @@ void FrameBuffer::Generate() } GLERROR("3"); - GLenum* bufferTextures = &attachments[0]; - glDrawBuffers(attachments.size(), bufferTextures); - if (GLERROR("GLBufferAttachement error")) { - printf(": AttachmentSize %i", attachments.size()); - } + GLenum* bufferTextures = &attachments[0]; + glDrawBuffers(attachments.size(), bufferTextures); + if (GLERROR("GLBufferAttachement error")) { + printf(": AttachmentSize %i", attachments.size()); + } + + if (GLenum frameBufferStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { + GLERROR("Framebuffer incomplete"); + //LOG_ERROR("FrameBuffer incomplete: 0x%x\n", frameBufferStatus); + exit(EXIT_FAILURE); + } + GLERROR("END"); - if (GLenum frameBufferStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { - GLERROR("Framebuffer incomplete"); - //LOG_ERROR("FrameBuffer incomplete: 0x%x\n", frameBufferStatus); - exit(EXIT_FAILURE); - } - GLERROR("END"); - } } void FrameBuffer::Bind() diff --git a/src/Engine/Rendering/RenderSystem.cpp b/src/Engine/Rendering/RenderSystem.cpp index 5de7bb51..a1f00c88 100644 --- a/src/Engine/Rendering/RenderSystem.cpp +++ b/src/Engine/Rendering/RenderSystem.cpp @@ -12,7 +12,7 @@ RenderSystem::RenderSystem(SystemParams params, const IRenderer* renderer, Rende EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &RenderSystem::OnInputCommand); EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &RenderSystem::OnPlayerSpawned); - m_Camera = new Camera((float)m_Renderer->Resolution().Width / m_Renderer->Resolution().Height, glm::radians(45.f), 0.01f, 300.f); + m_Camera = new Camera((float)m_Renderer->Resolution().Width / m_Renderer->Resolution().Height, glm::radians(45.f), 0.01f, 5000.f); } RenderSystem::~RenderSystem() diff --git a/src/Engine/Rendering/Renderer.cpp b/src/Engine/Rendering/Renderer.cpp index 748caec2..b9a6aa05 100644 --- a/src/Engine/Rendering/Renderer.cpp +++ b/src/Engine/Rendering/Renderer.cpp @@ -86,6 +86,11 @@ void Renderer::InitializeShaders() { m_BasicForwardProgram = ResourceManager::Load("#m_BasicForwardProgram"); m_ExplosionEffectProgram = ResourceManager::Load("#ExplosionEffectProgram"); + //m_ExplosionEffectProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/ExplosionEffect.vert.glsl"))); + //m_ExplosionEffectProgram->AddShader(std::shared_ptr(new GeometryShader("Shaders/ExplosionEffect.geom.glsl"))); + //m_ExplosionEffectProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/ExplosionEffect.frag.glsl"))); + //m_ExplosionEffectProgram->Compile(); + //m_ExplosionEffectProgram->Link(); } void Renderer::InputUpdate(double dt) @@ -127,8 +132,9 @@ void Renderer::Draw(RenderFrame& frame) m_PickingPass->ClearPicking(); m_DrawFinalPass->ClearBuffer(); m_DrawBloomPass->ClearBuffer(); - m_ShadowPass->ClearBuffer(); m_SSAOPass->ClearBuffer(); + m_ShadowPass->ClearBuffer(); + m_ShadowPass->DebugGUI(); PerformanceTimer::StopTimer("Renderer-ClearBuffers"); GLERROR("ClearBuffers"); for (auto scene : frame.RenderScenes) { @@ -144,7 +150,9 @@ void Renderer::Draw(RenderFrame& frame) PerformanceTimer::StartTimer("Renderer-Depth"); SortRenderJobsByDepth(*scene); GLERROR("SortByDepth"); - m_ShadowPass->Draw(*scene); + PerformanceTimer::StartTimerAndStopPrevious("Draw shadow maps"); + m_ShadowPass->Draw(*scene); + GLERROR("Draw shadow maps"); PerformanceTimer::StartTimerAndStopPrevious("Renderer-Generate Frustrums"); m_LightCullingPass->GenerateNewFrustum(*scene); GLERROR("Generate frustums"); @@ -187,7 +195,7 @@ void Renderer::Draw(RenderFrame& frame) } if (m_DebugTextureToDraw == 4) { m_DrawScreenQuadPass->Draw(m_PickingPass->PickingTexture()); - } + } if (m_DebugTextureToDraw == 5) { m_DrawScreenQuadPass->Draw(m_SSAOPass->SSAOTexture()); } @@ -239,9 +247,9 @@ void Renderer::InitializeRenderPasses() { m_PickingPass = new PickingPass(this, m_EventBroker); m_LightCullingPass = new LightCullingPass(this); - m_ShadowPass = new ShadowPass(this); m_CubeMapPass = new CubeMapPass(this); m_SSAOPass = new SSAOPass(this, m_Config); + m_ShadowPass = new ShadowPass(this); m_DrawFinalPass = new DrawFinalPass(this, m_LightCullingPass, m_CubeMapPass, m_SSAOPass, m_ShadowPass); m_DrawScreenQuadPass = new DrawScreenQuadPass(this); m_DrawBloomPass = new DrawBloomPass(this, m_Config); diff --git a/src/Engine/Rendering/ShadowPass.cpp b/src/Engine/Rendering/ShadowPass.cpp index d7741dff..daf63ef2 100644 --- a/src/Engine/Rendering/ShadowPass.cpp +++ b/src/Engine/Rendering/ShadowPass.cpp @@ -1,6 +1,5 @@ #include "Rendering/ShadowPass.h" - ShadowPass::ShadowPass(IRenderer * renderer, int shadow_res_x, int shadow_res_y) { m_Renderer = renderer; @@ -24,6 +23,15 @@ ShadowPass::~ShadowPass() } +void ShadowPass::DebugGUI() +{ + ImGui::Checkbox("EnableShadows", &m_EnableShadows); + ImGui::DragFloat2("ShadowMapNearFar", m_NearFarPlane, 1.f, -1000.f, 1000.f); + ImGui::DragFloat("ShadowClippingWeight", &m_SplitWeight, 0.001f, 0.f, 1.f); + ImGui::Checkbox("ShadowTransparentObjects", &m_TransparentObjects); + ImGui::Checkbox("ShadowOnTextureAlphas", &m_TexturedShadows); +} + void ShadowPass::InitializeCameras(RenderScene & scene) { for (int i = 0; i < m_CurrentNrOfSplits; i++) { @@ -198,101 +206,100 @@ void ShadowPass::RadiusToLightspace(ShadowFrustum& frustum) void ShadowPass::Draw(RenderScene & scene) { - ImGui::DragFloat2("ShadowMapNearFar", m_NearFarPlane, 1.f, -1000.f, 1000.f); - ImGui::DragFloat("ShadowClippingWeight", &m_SplitWeight, 0.001f, 0.f, 1.f); + if (m_EnableShadows) { + InitializeCameras(scene); + UpdateSplitDist(m_shadowFrusta, scene.Camera->NearClip(), scene.Camera->FarClip()); - InitializeCameras(scene); - UpdateSplitDist(m_shadowFrusta, scene.Camera->NearClip(), scene.Camera->FarClip()); + ShadowPassState* state = new ShadowPassState(m_DepthBuffer.GetHandle()); - ShadowPassState* state = new ShadowPassState(m_DepthBuffer.GetHandle()); + m_ShadowProgram->Bind(); + GLuint shaderHandle = m_ShadowProgram->GetHandle(); + glViewport(0, 0, m_ResolutionSizeWidth, m_ResolutionSizeHeight); - m_ShadowProgram->Bind(); - GLuint shaderHandle = m_ShadowProgram->GetHandle(); - glViewport(0, 0, m_ResolutionSizeWidth, m_ResolutionSizeHeight); + for (int i = 0; i < m_CurrentNrOfSplits; i++) { + UpdateFrustumPoints(m_shadowFrusta[i], scene.Camera->Position(), scene.Camera->Forward()); - for (int i = 0; i < m_CurrentNrOfSplits; i++) { - UpdateFrustumPoints(m_shadowFrusta[i], scene.Camera->Position(), scene.Camera->Forward()); + glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_DepthMap, 0, i); - glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_DepthMap, 0, i); + for (auto &job : scene.Jobs.DirectionalLight) { + auto directionalLightJob = std::dynamic_pointer_cast(job); - for (auto &job : scene.Jobs.DirectionalLight) { - auto directionalLightJob = std::dynamic_pointer_cast(job); + if (directionalLightJob) { + m_LightView[i] = glm::lookAt(glm::vec3(-directionalLightJob->Direction) + m_shadowFrusta[i].MiddlePoint, m_shadowFrusta[i].MiddlePoint, glm::vec3(0.f, 1.f, 0.f)); - if (directionalLightJob) { - m_LightView[i] = glm::lookAt(glm::vec3(-directionalLightJob->Direction) + m_shadowFrusta[i].MiddlePoint, m_shadowFrusta[i].MiddlePoint, glm::vec3(0.f, 1.f, 0.f)); + PointsToLightspace(m_shadowFrusta[i], m_LightView[i]); + //FindRadius(m_shadowFrusta[i]); + //RadiusToLightspace(m_shadowFrusta[i]); + m_LightProjection[i] = glm::ortho(m_shadowFrusta[i].LRBT[LEFT], m_shadowFrusta[i].LRBT[RIGHT], m_shadowFrusta[i].LRBT[BOTTOM], m_shadowFrusta[i].LRBT[TOP], m_NearFarPlane[NEAR], m_NearFarPlane[FAR]); - PointsToLightspace(m_shadowFrusta[i], m_LightView[i]); - //FindRadius(m_shadowFrusta[i]); - //RadiusToLightspace(m_shadowFrusta[i]); - m_LightProjection[i] = glm::ortho(m_shadowFrusta[i].LRBT[LEFT], m_shadowFrusta[i].LRBT[RIGHT], m_shadowFrusta[i].LRBT[BOTTOM], m_shadowFrusta[i].LRBT[TOP], m_NearFarPlane[NEAR], m_NearFarPlane[FAR]); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_LightProjection[i])); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_LightView[i])); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_LightProjection[i])); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_LightView[i])); + GLERROR("ShadowLight ERROR"); - GLERROR("ShadowLight ERROR"); + for (auto &objectJob : scene.Jobs.OpaqueObjects) { + if (!std::dynamic_pointer_cast(objectJob)) { + auto modelJob = std::dynamic_pointer_cast(objectJob); - for (auto &objectJob : scene.Jobs.OpaqueObjects) { - if (!std::dynamic_pointer_cast(objectJob)) - { - auto modelJob = std::dynamic_pointer_cast(objectJob); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); + glUniform1f(glGetUniformLocation(shaderHandle, "Alpha"), 1.f); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); + glBindVertexArray(modelJob->Model->VAO); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); + glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int))); - glBindVertexArray(modelJob->Model->VAO); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); - glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int))); - - GLERROR("Shadow Draw ERROR"); + GLERROR("Shadow Draw ERROR"); + } } - } + if (m_TransparentObjects) { + state->CullFace(GL_BACK); + for (auto &objectJob : scene.Jobs.TransparentObjects) { + if (!std::dynamic_pointer_cast(objectJob)) { + auto modelJob = std::dynamic_pointer_cast(objectJob); - state->CullFace(GL_BACK); - for (auto &objectJob : scene.Jobs.TransparentObjects) { - if (!std::dynamic_pointer_cast(objectJob)) - { - auto modelJob = std::dynamic_pointer_cast(objectJob); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); + glUniform1f(glGetUniformLocation(shaderHandle, "Alpha"), modelJob->Color.a); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); - glUniform1f(glGetUniformLocation(shaderHandle, "Alpha"), modelJob->Color.a); - - if (directionalLightJob->TextureAlphaShadows) { - switch (modelJob->Type) { - case RawModel::MaterialType::SingleTextures: - case RawModel::MaterialType::Basic: - { - glActiveTexture(GL_TEXTURE24); - if (modelJob->DiffuseTexture.size() > 0 && modelJob->DiffuseTexture[0]->Texture != nullptr) { - glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture[0]->Texture->m_Texture); - glUniform2fv(glGetUniformLocation(shaderHandle, "DiffuseUVRepeat"), 1, glm::value_ptr(modelJob->DiffuseTexture[0]->UVRepeat)); + if (m_TexturedShadows) { + switch (modelJob->Type) { + case RawModel::MaterialType::SingleTextures: + case RawModel::MaterialType::Basic: + { + glActiveTexture(GL_TEXTURE24); + if (modelJob->DiffuseTexture.size() > 0 && modelJob->DiffuseTexture[0]->Texture != nullptr) { + glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture[0]->Texture->m_Texture); + glUniform2fv(glGetUniformLocation(shaderHandle, "DiffuseUVRepeat"), 1, glm::value_ptr(modelJob->DiffuseTexture[0]->UVRepeat)); + } + else { + glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture); + glUniform2fv(glGetUniformLocation(shaderHandle, "DiffuseUVRepeat"), 1, glm::value_ptr(glm::vec2(1.0f, 1.0f))); + } + break; + } + case RawModel::MaterialType::SplatMapping: + { + glActiveTexture(GL_TEXTURE24); + glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture); + glUniform2fv(glGetUniformLocation(shaderHandle, "DiffuseUVRepeat"), 1, glm::value_ptr(glm::vec2(1.0f, 1.0f))); + break; + } + } } - else { - glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture); - glUniform2fv(glGetUniformLocation(shaderHandle, "DiffuseUVRepeat"), 1, glm::value_ptr(glm::vec2(1.0f, 1.0f))); - } - break; - } - case RawModel::MaterialType::SplatMapping: - { - glActiveTexture(GL_TEXTURE24); - glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture); - glUniform2fv(glGetUniformLocation(shaderHandle, "DiffuseUVRepeat"), 1, glm::value_ptr(glm::vec2(1.0f, 1.0f))); - break; - } + + glBindVertexArray(modelJob->Model->VAO); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); + glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int))); + + GLERROR("Shadow Draw ERROR"); } } - - glBindVertexArray(modelJob->Model->VAO); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); - glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int))); - - GLERROR("Shadow Draw ERROR"); + state->CullFace(GL_FRONT); } } - state->CullFace(GL_FRONT); } } + glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height); + m_DepthBuffer.Unbind(); + delete state; } - glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height); - m_DepthBuffer.Unbind(); - delete state; -} +} \ No newline at end of file diff --git a/src/Engine/Rendering/ShadowPassState.cpp b/src/Engine/Rendering/ShadowPassState.cpp index ef789487..2211e3ab 100644 --- a/src/Engine/Rendering/ShadowPassState.cpp +++ b/src/Engine/Rendering/ShadowPassState.cpp @@ -2,10 +2,10 @@ ShadowPassState::ShadowPassState(GLuint frameBuffer) { - BindFramebuffer(frameBuffer); - Enable(GL_DEPTH_TEST); - Enable(GL_CULL_FACE); - Disable(GL_BLEND); + BindFramebuffer(frameBuffer); + Enable(GL_DEPTH_TEST); + Enable(GL_CULL_FACE); + Disable(GL_BLEND); Disable(GL_TEXTURE_2D); CullFace(GL_FRONT); ClearColor(glm::vec4(0.f, 0.f, 0.f, 0.f)); From 9d4441852c5d27d727c17f761679d9ce08028e0f Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Thu, 3 Mar 2016 03:39:00 +0100 Subject: [PATCH 112/130] DefenderWeapon view punch and crosshair travel with return --- assets | 2 +- .../Systems/Weapon/DefenderWeaponBehaviour.h | 2 + .../Schema/Components/DefenderWeapon.xml | 5 +- .../Schema/Components/DefenderWeapon.xsd | 7 +++ resources/Schema/Entities/MovementTest.xml | 12 ++-- resources/Schema/Entities/Player.xml | 13 ++-- .../Weapon/DefenderWeaponBehaviour.cpp | 59 ++++++++++++++++++- .../Systems/Weapon/SidearmWeaponBehaviour.cpp | 2 - 8 files changed, 83 insertions(+), 19 deletions(-) diff --git a/assets b/assets index 72530423..b8baf48e 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 72530423ad3744341f42cbfdcba18295a2cfac90 +Subproject commit b8baf48e5ee88ddb7d9bd818e31e3a52d96daec5 diff --git a/include/Game/Systems/Weapon/DefenderWeaponBehaviour.h b/include/Game/Systems/Weapon/DefenderWeaponBehaviour.h index c1e132b1..77d579f8 100644 --- a/include/Game/Systems/Weapon/DefenderWeaponBehaviour.h +++ b/include/Game/Systems/Weapon/DefenderWeaponBehaviour.h @@ -1,6 +1,7 @@ #include "WeaponBehaviour.h" #include "Collision/Collision.h" #include "Core/EPlayerDamage.h" +#include "Sound/EPlaySoundOnEntity.h" class DefenderWeaponBehaviour : public WeaponBehaviour { @@ -16,6 +17,7 @@ public: void OnPrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi) override; void OnCeasePrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi) override; void OnReload(ComponentWrapper cWeapon, WeaponInfo& wi) override; + void OnHolster(ComponentWrapper cWeapon, WeaponInfo& wi) override; bool OnInputCommand(ComponentWrapper cWeapon, WeaponInfo& wi, const Events::InputCommand& e) override; private: diff --git a/resources/Schema/Components/DefenderWeapon.xml b/resources/Schema/Components/DefenderWeapon.xml index 1b336fc4..68b87759 100755 --- a/resources/Schema/Components/DefenderWeapon.xml +++ b/resources/Schema/Components/DefenderWeapon.xml @@ -6,13 +6,16 @@ 64 90 0.174533 + 0.174533 10 120 - 0.01 + 0.03 + 0.2 0.5 false 0 false 0 + 0 \ No newline at end of file diff --git a/resources/Schema/Components/DefenderWeapon.xsd b/resources/Schema/Components/DefenderWeapon.xsd index c1b98e2f..d2b503f8 100755 --- a/resources/Schema/Components/DefenderWeapon.xsd +++ b/resources/Schema/Components/DefenderWeapon.xsd @@ -37,6 +37,9 @@ Spread angle in radians + + Maximum vertical aim travel angle in radians + Rate of fire in rounds per minute @@ -44,6 +47,9 @@ View punch in radians for each shell fired + + The speed in radians per second the view returns to its original position after being punched + Time it takes to load ONE SHELL into the weapon in seconds @@ -52,6 +58,7 @@ + diff --git a/resources/Schema/Entities/MovementTest.xml b/resources/Schema/Entities/MovementTest.xml index 41474568..3429194a 100644 --- a/resources/Schema/Entities/MovementTest.xml +++ b/resources/Schema/Entities/MovementTest.xml @@ -26,7 +26,7 @@ - Models/Characters/Assault/AssaultTPose.mesh + Models/Characters/Assault/AssaultRed.mesh @@ -39,7 +39,7 @@ - Models/Characters/Assault/AssaultTPose.mesh + Models/Characters/Assault/AssaultRed.mesh @@ -94,11 +94,11 @@ - Models/Characters/Assault/AssaultTPose.mesh + Models/Characters/Assault/AssaultBlue.mesh - + @@ -107,11 +107,11 @@ - Models/Characters/Assault/AssaultTPose.mesh + Models/Characters/Assault/AssaultBlue.mesh - + diff --git a/resources/Schema/Entities/Player.xml b/resources/Schema/Entities/Player.xml index e0230582..1ee9d5d3 100644 --- a/resources/Schema/Entities/Player.xml +++ b/resources/Schema/Entities/Player.xml @@ -458,7 +458,7 @@ - Models/Characters/Assault/FirstPerson.mesh + Models/Characters/Assault/Test/FirstPerson.mesh @@ -524,8 +524,7 @@ - Idle - 0.013134522267137072 + IdleF 1 @@ -537,8 +536,8 @@ - Models/Characters/Assault/AssaultAnimations.mesh - + Models/Characters/Assault/AssaultBlue.mesh + @@ -573,8 +572,8 @@ Schema/Entities/SidearmWeaponWorld.xml - - + + diff --git a/src/Game/Systems/Weapon/DefenderWeaponBehaviour.cpp b/src/Game/Systems/Weapon/DefenderWeaponBehaviour.cpp index 4c0f9673..50d5889d 100644 --- a/src/Game/Systems/Weapon/DefenderWeaponBehaviour.cpp +++ b/src/Game/Systems/Weapon/DefenderWeaponBehaviour.cpp @@ -10,9 +10,11 @@ void DefenderWeaponBehaviour::UpdateComponent(EntityWrapper& entity, ComponentWr void DefenderWeaponBehaviour::UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo& wi, double dt) { + // Decrement reload timer double& reloadTimer = cWeapon["ReloadTimer"]; reloadTimer = glm::max(0.0, reloadTimer - dt); + // Handle reloading double reloadTime = cWeapon["ReloadTime"]; bool& isReloading = cWeapon["IsReloading"]; if (isReloading && reloadTimer <= 0.0) { @@ -23,11 +25,31 @@ void DefenderWeaponBehaviour::UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo& ammo -= 1; magAmmo += 1; reloadTimer = reloadTime; + Events::PlaySoundOnEntity e; + e.EmitterID = wi.Player.ID; + e.FilePath = "Audio/weapon/Zoom.wav"; + m_EventBroker->Publish(e); } else { isReloading = false; } } + // Restore view angle + if (IsClient) { + float& currentTravel = cWeapon["CurrentTravel"]; + float& returnSpeed = cWeapon["ViewReturnSpeed"]; + if (currentTravel > 0) { + float change = returnSpeed * dt; + currentTravel = glm::max(0.f, currentTravel - change); + EntityWrapper camera = wi.Player.FirstChildByName("Camera"); + if (camera.Valid()) { + glm::vec3& cameraOrientation = camera["Transform"]["Orientation"]; + cameraOrientation.x -= change; + } + } + } + + // Fire if we're able to fire if (canFire(cWeapon, wi)) { fireShell(cWeapon, wi); } @@ -71,6 +93,16 @@ void DefenderWeaponBehaviour::OnReload(ComponentWrapper cWeapon, WeaponInfo& wi) reloadTimer = reloadTime; } +void DefenderWeaponBehaviour::OnHolster(ComponentWrapper cWeapon, WeaponInfo& wi) +{ + // Make sure the trigger is released if weapon is holstered while firing + cWeapon["TriggerHeld"] = false; + + // Cancel any reload + cWeapon["IsReloading"] = false; + cWeapon["ReloadTimer"] = 0.0; +} + bool DefenderWeaponBehaviour::OnInputCommand(ComponentWrapper cWeapon, WeaponInfo& wi, const Events::InputCommand& e) { if (e.Command == "SpecialAbility" && IsServer) { @@ -114,11 +146,29 @@ void DefenderWeaponBehaviour::fireShell(ComponentWrapper cWeapon, WeaponInfo& wi std::vector pelletAngles; for (int i = 0; i < numPellets; i++) { pelletAngles.push_back(glm::vec2(randomSpreadAngle(m_RandomEngine), randomSpreadAngle(m_RandomEngine))); - LOG_DEBUG("%f %f", pelletAngles[i].x, pelletAngles[i].y); } double pelletDamage = (double)cWeapon["BaseDamage"] / numPellets; + // View punch + if (IsClient) { + EntityWrapper camera = wi.Player.FirstChildByName("Camera"); + if (camera.Valid()) { + glm::vec3& cameraOrientation = camera["Transform"]["Orientation"]; + float viewPunch = cWeapon["ViewPunch"]; + float maxTravelAngle = cWeapon["MaxTravelAngle"]; + float& currentTravel = cWeapon["CurrentTravel"]; + if (currentTravel < maxTravelAngle) { + float change = viewPunch; + if (currentTravel + change > maxTravelAngle) { + change = maxTravelAngle - currentTravel; + } + cameraOrientation.x += change; + currentTravel += change; + } + } + } + // Tracers EntityWrapper weaponModelEntity; if (wi.Player == LocalPlayer) { @@ -140,6 +190,12 @@ void DefenderWeaponBehaviour::fireShell(ComponentWrapper cWeapon, WeaponInfo& wi dealDamage(cWeapon, wi, direction, pelletDamage); } } + + // Sound + Events::PlaySoundOnEntity e; + e.EmitterID = wi.Player.ID; + e.FilePath = "Audio/weapon/Blast.wav"; + m_EventBroker->Publish(e); } void DefenderWeaponBehaviour::dealDamage(ComponentWrapper cWeapon, WeaponInfo& wi, glm::vec3 direction, double damage) @@ -206,7 +262,6 @@ bool DefenderWeaponBehaviour::canFire(ComponentWrapper cWeapon, WeaponInfo& wi) bool triggerHeld = cWeapon["TriggerHeld"]; bool cooldownPassed = (double)cWeapon["FireCooldown"] <= 0.0; bool isNotShielding = wi.Player.ChildrenWithComponent("Shield").size() == 0; - // TODO: Ammo checks return triggerHeld && cooldownPassed && isNotShielding; } diff --git a/src/Game/Systems/Weapon/SidearmWeaponBehaviour.cpp b/src/Game/Systems/Weapon/SidearmWeaponBehaviour.cpp index 9a3ed6ab..d32b7d7e 100644 --- a/src/Game/Systems/Weapon/SidearmWeaponBehaviour.cpp +++ b/src/Game/Systems/Weapon/SidearmWeaponBehaviour.cpp @@ -45,8 +45,6 @@ void SidearmWeaponBehaviour::OnHolster(ComponentWrapper cWeapon, WeaponInfo& wi) // Cancel any reload cWeapon["IsReloading"] = false; cWeapon["ReloadTimer"] = 0.0; - - LOG_DEBUG("HOLSTER"); } void SidearmWeaponBehaviour::fireBullet(ComponentWrapper cWeapon, WeaponInfo& wi) From cb7beae28c6164977f42b8b10e6298c848cdf2f1 Mon Sep 17 00:00:00 2001 From: Jocke Date: Thu, 3 Mar 2016 11:39:00 +0100 Subject: [PATCH 113/130] Only do physics and collision calculations on the clients side, and only for their own entity. --- src/Engine/Collision/CollisionSystem.cpp | 166 +++++++++++----------- src/Game/Systems/PlayerMovementSystem.cpp | 11 +- 2 files changed, 87 insertions(+), 90 deletions(-) diff --git a/src/Engine/Collision/CollisionSystem.cpp b/src/Engine/Collision/CollisionSystem.cpp index 95609ea6..53cabfac 100644 --- a/src/Engine/Collision/CollisionSystem.cpp +++ b/src/Engine/Collision/CollisionSystem.cpp @@ -17,105 +17,107 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c EntityAABB& boxA = *boundingBox; bool everHitTheGround = false; - auto prevPosIt = m_PrevPositions.find(entity); - if (prevPosIt != m_PrevPositions.end()) { - glm::vec3 size = boxA.Size(); - float diameter = std::min(size.x, size.z); - glm::vec3 prevOrigin = prevPosIt->second; - glm::vec3 toCurrentPos = boxA.Origin() - prevOrigin; - float rayLength = glm::length(toCurrentPos) + 0.5f*diameter; - //If the entity has moved farther than the size of its box, we need to handle it specially. - if (rayLength > diameter) { - Ray ray(prevOrigin, toCurrentPos); - m_OctreeResult.clear(); - m_Octree->ObjectsPossiblyHitByRay(ray, m_OctreeResult); - for (auto& boxB : m_OctreeResult) { - if (boxA.Entity == boxB.Entity) { - continue; - } - bool hit; - float dist; - if (boxB.Entity.HasComponent("Model")) { - RawModel* model; - std::string res = (std::string)boxB.Entity["Model"]["Resource"]; - try { - model = ResourceManager::Load(res); - } catch (const std::exception&) { + if (entity == LocalPlayer) { + auto prevPosIt = m_PrevPositions.find(entity); + if (prevPosIt != m_PrevPositions.end()) { + glm::vec3 size = boxA.Size(); + float diameter = std::min(size.x, size.z); + glm::vec3 prevOrigin = prevPosIt->second; + glm::vec3 toCurrentPos = boxA.Origin() - prevOrigin; + float rayLength = glm::length(toCurrentPos) + 0.5f*diameter; + //If the entity has moved farther than the size of its box, we need to handle it specially. + if (rayLength > diameter) { + Ray ray(prevOrigin, toCurrentPos); + m_OctreeResult.clear(); + m_Octree->ObjectsPossiblyHitByRay(ray, m_OctreeResult); + for (auto& boxB : m_OctreeResult) { + if (boxA.Entity == boxB.Entity) { continue; } - float u, v; - hit = Collision::RayVsModel(ray, model->Vertices(), model->m_Indices, Transform::ModelMatrix(boxB.Entity), dist, u, v); - } else { - hit = Collision::RayVsAABB(ray, boxB, dist); - } - if (hit && dist < rayLength) { - //Set the entity to where it was colliding, minus the maximum box size. - //TODO: Perhaps this should be done slightly more properly. - glm::vec3 newOriginPos = ray.Origin() + (dist - 0.707107f*diameter) * ray.Direction(); - glm::vec3 resolve = newOriginPos - boxA.Origin(); - (glm::vec3&)cTransform["Position"] += resolve; - boxA = *Collision::EntityAbsoluteAABB(entity); - if (resolve.y > 0) { - everHitTheGround = true; - (bool)cPhysics["IsOnGround"] = true; - ((glm::vec3&)cPhysics["Velocity"]).y = 0.f; + bool hit; + float dist; + if (boxB.Entity.HasComponent("Model")) { + RawModel* model; + std::string res = (std::string)boxB.Entity["Model"]["Resource"]; + try { + model = ResourceManager::Load(res); + } catch (const std::exception&) { + continue; + } + float u, v; + hit = Collision::RayVsModel(ray, model->Vertices(), model->m_Indices, Transform::ModelMatrix(boxB.Entity), dist, u, v); + } else { + hit = Collision::RayVsAABB(ray, boxB, dist); + } + if (hit && dist < rayLength) { + //Set the entity to where it was colliding, minus the maximum box size. + //TODO: Perhaps this should be done slightly more properly. + glm::vec3 newOriginPos = ray.Origin() + (dist - 0.707107f*diameter) * ray.Direction(); + glm::vec3 resolve = newOriginPos - boxA.Origin(); + (glm::vec3&)cTransform["Position"] += resolve; + boxA = *Collision::EntityAbsoluteAABB(entity); + if (resolve.y > 0) { + everHitTheGround = true; + (bool)cPhysics["IsOnGround"] = true; + ((glm::vec3&)cPhysics["Velocity"]).y = 0.f; + } + break; } - break; } } } - } - // Collide against octree items - m_OctreeResult.clear(); - m_Octree->ObjectsInSameRegion(*boundingBox, m_OctreeResult); - for (auto& boxB : m_OctreeResult) { - glm::vec3 resolutionVector; - if (boxA.Entity == boxB.Entity) { - continue; - } - - if (boxB.Entity.HasComponent("Model") && Collision::AABBVsAABB(boxA, boxB)) { - //Here we know boxB is a entity with Collideable, AABB, and Model. - RawModel* model; - try { - model = ResourceManager::Load(boxB.Entity["Model"]["Resource"]); - } catch (const std::exception&) { + // Collide against octree items + m_OctreeResult.clear(); + m_Octree->ObjectsInSameRegion(*boundingBox, m_OctreeResult); + for (auto& boxB : m_OctreeResult) { + glm::vec3 resolutionVector; + if (boxA.Entity == boxB.Entity) { continue; } - glm::mat4 modelMatrix = Transform::ModelMatrix(boxB.Entity); + if (boxB.Entity.HasComponent("Model") && Collision::AABBVsAABB(boxA, boxB)) { + //Here we know boxB is a entity with Collideable, AABB, and Model. + RawModel* model; + try { + model = ResourceManager::Load(boxB.Entity["Model"]["Resource"]); + } catch (const std::exception&) { + continue; + } - glm::vec3 inOutVelocity = (glm::vec3)cPhysics["Velocity"]; - bool notMovingxz = glm::all(glm::lessThan(glm::abs(glm::vec2(inOutVelocity.x, inOutVelocity.z)), glm::vec2(0.01f))) && prevPosIt != m_PrevPositions.end(); - bool isOnGround = (bool)cPhysics["IsOnGround"]; - float verticalStepHeight = (float)(double)cPhysics["VerticalStepHeight"]; - if (Collision::AABBvsTriangles(boxA, model->Vertices(), model->m_Indices, modelMatrix, inOutVelocity, verticalStepHeight, isOnGround, resolutionVector)) { - //Move the position to previous position if it is not moving in the xz-plane, else resolve with the resolution vector. - (glm::vec3&)cTransform["Position"] += notMovingxz ? prevPosIt->second - boxA.Origin() : resolutionVector; + glm::mat4 modelMatrix = Transform::ModelMatrix(boxB.Entity); + + glm::vec3 inOutVelocity = (glm::vec3)cPhysics["Velocity"]; + bool notMovingxz = glm::all(glm::lessThan(glm::abs(glm::vec2(inOutVelocity.x, inOutVelocity.z)), glm::vec2(0.01f))) && prevPosIt != m_PrevPositions.end(); + bool isOnGround = (bool)cPhysics["IsOnGround"]; + float verticalStepHeight = (float)(double)cPhysics["VerticalStepHeight"]; + if (Collision::AABBvsTriangles(boxA, model->Vertices(), model->m_Indices, modelMatrix, inOutVelocity, verticalStepHeight, isOnGround, resolutionVector)) { + //Move the position to previous position if it is not moving in the xz-plane, else resolve with the resolution vector. + (glm::vec3&)cTransform["Position"] += notMovingxz ? prevPosIt->second - boxA.Origin() : resolutionVector; + boxA = *Collision::EntityAbsoluteAABB(entity); + cPhysics["Velocity"] = inOutVelocity; + if (isOnGround) { + everHitTheGround = true; + (bool)cPhysics["IsOnGround"] = true; + } + } + } else if (Collision::AABBVsAABB(boxA, boxB, resolutionVector)) { + //Enter here if boxB has no Model. + (glm::vec3&)cTransform["Position"] += resolutionVector; boxA = *Collision::EntityAbsoluteAABB(entity); - cPhysics["Velocity"] = inOutVelocity; - if (isOnGround) { + if (resolutionVector.y > 0) { everHitTheGround = true; (bool)cPhysics["IsOnGround"] = true; + ((glm::vec3&)cPhysics["Velocity"]).y = 0.f; } } - } else if (Collision::AABBVsAABB(boxA, boxB, resolutionVector)) { - //Enter here if boxB has no Model. - (glm::vec3&)cTransform["Position"] += resolutionVector; - boxA = *Collision::EntityAbsoluteAABB(entity); - if (resolutionVector.y > 0) { - everHitTheGround = true; - (bool)cPhysics["IsOnGround"] = true; - ((glm::vec3&)cPhysics["Velocity"]).y = 0.f; - } } - } - //This should apply air friction and such, iff zero models were hit. - if (!everHitTheGround) { - (bool)cPhysics["IsOnGround"] = false; - } + //This should apply air friction and such, iff zero models were hit. + if (!everHitTheGround) { + (bool)cPhysics["IsOnGround"] = false; + } - m_PrevPositions[entity] = boxA.Origin(); + m_PrevPositions[entity] = boxA.Origin(); + } } diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index 9afc9c8c..be85fddb 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -18,14 +18,9 @@ PlayerMovementSystem::~PlayerMovementSystem() void PlayerMovementSystem::Update(double dt) { updateMovementControllers(dt); - if (IsServer) { - for (auto& kv : m_PlayerInputControllers) { - updateVelocity(kv.first, dt); - } - } else { - if (LocalPlayer.Valid()) { - updateVelocity(LocalPlayer, dt); - } + // Only do physics calculations on client and only for themselves. + if (!IsServer && LocalPlayer.Valid()) { + updateVelocity(LocalPlayer, dt); } } From 9c1a638a41ff32e49cf78d96d81c4078fc85697e Mon Sep 17 00:00:00 2001 From: maqu14 Date: Thu, 3 Mar 2016 13:28:18 +0100 Subject: [PATCH 114/130] New map (NewMap2version4NEW) --- assets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets b/assets index 10a61165..7a6d7078 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 10a611659ddaadfea6a560e707d395834855a979 +Subproject commit 7a6d70787b036d8ae8763b69ae6ad098bf221c22 From a9b19d9af18364252fea24150d3d3ebd1dc095d8 Mon Sep 17 00:00:00 2001 From: Jocke Date: Thu, 3 Mar 2016 13:29:45 +0100 Subject: [PATCH 115/130] Packet write now only warns when a a packet is huge --- include/Engine/Network/Packet.h | 4 +++- src/Engine/Network/Packet.cpp | 8 ++++++-- src/Game/Systems/PlayerMovementSystem.cpp | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/Engine/Network/Packet.h b/include/Engine/Network/Packet.h index 95419e10..e7444d9d 100644 --- a/include/Engine/Network/Packet.h +++ b/include/Engine/Network/Packet.h @@ -24,7 +24,9 @@ public: { // Check if we are trying to add more than the package can fit. if (m_MaxPacketSize < m_Offset + sizeof(T)) { - //LOG_WARNING("Packet AddPrimitive(): You are trying to add more than we have allocated for! New size is %i bytes\n", m_MaxPacketSize*2); + if (m_MaxPacketSize >= 32000) { + LOG_WARNING("Package::WritePrimitive(): New size is huge %i bytes\n", m_MaxPacketSize*2); + } resizeData(); } memcpy(m_Data + m_Offset, &val, sizeof(T)); diff --git a/src/Engine/Network/Packet.cpp b/src/Engine/Network/Packet.cpp index 475ca673..74afd656 100644 --- a/src/Engine/Network/Packet.cpp +++ b/src/Engine/Network/Packet.cpp @@ -49,7 +49,9 @@ void Packet::WriteString(const std::string& str) // Message, add one extra byte for null terminator size_t sizeOfString = str.size() + 1; if (m_Offset + sizeOfString > m_MaxPacketSize) { - //LOG_WARNING("Package::WriteString(): Data size in packet exceeded maximum package size. New size is %i bytes\n", m_MaxPacketSize*2); + if (m_MaxPacketSize >= 32000) { + LOG_WARNING("Package::WriteString(): New size is huge %i bytes\n", m_MaxPacketSize*2); + } resizeData(); } memcpy(m_Data + m_Offset, str.data(), sizeOfString * sizeof(char)); @@ -60,7 +62,9 @@ void Packet::WriteData(char * data, int sizeOfData) { if (m_Offset + sizeOfData > m_MaxPacketSize) { - //LOG_WARNING("Packet::WriteData(): Data size in packet exceeded maximum packet size. New size is %i bytes\n", m_MaxPacketSize*2); + if (m_MaxPacketSize >= 32000) { + LOG_WARNING("Package::WriteData(): New size is huge %i bytes\n", m_MaxPacketSize*2); + } while (m_Offset + sizeOfData > m_MaxPacketSize) { resizeData(); } diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index be85fddb..5037b019 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -19,7 +19,7 @@ void PlayerMovementSystem::Update(double dt) { updateMovementControllers(dt); // Only do physics calculations on client and only for themselves. - if (!IsServer && LocalPlayer.Valid()) { + if (IsClient && LocalPlayer.Valid()) { updateVelocity(LocalPlayer, dt); } } From 2cd39c718810419ae6b95bec3a1c0cc0acb42384 Mon Sep 17 00:00:00 2001 From: maqu14 Date: Thu, 3 Mar 2016 13:31:17 +0100 Subject: [PATCH 116/130] New map version (NewMap2version4NEW) --- .../Schema/Entities/NewMap2version4NEW.xml | 8770 +++++++++++++++++ 1 file changed, 8770 insertions(+) create mode 100644 resources/Schema/Entities/NewMap2version4NEW.xml diff --git a/resources/Schema/Entities/NewMap2version4NEW.xml b/resources/Schema/Entities/NewMap2version4NEW.xml new file mode 100644 index 00000000..0b94f444 --- /dev/null +++ b/resources/Schema/Entities/NewMap2version4NEW.xml @@ -0,0 +1,8770 @@ + + + + + + + + + + + + + + + + + + 2 + Models/Props/GroundTest.mesh + + + + + + + + + Models/Props/Walls/SciFiWallTop.mesh + + + + + + + + + Models/Props/Walls/SciFiWallBig.mesh + true + + + + + + + + + + Models/Props/Walls/SciFiWallMedium.mesh + + + + + + + + + + Models/Props/Walls/SciFiWallSmall1.mesh + + + + + + + + + + Models/Props/Walls/SciFiWallSmall2.mesh + + + + + + + + + + Models/Props/Walls/SciFiWallBig.mesh + + + + + + + + + + + + Models/Props/Walls/SciFiWallMedium.mesh + + + + + + + + + + + + Models/Props/Walls/SciFiWallSmall3.mesh + + + + + + + + + + Models/Props/Walls/SciFiWallSmall4.mesh + + + + + + + + + + + + Models/Props/Highground1.mesh + + + + + + + + + + Models/Props/Highground2.mesh + + + + + + + + + + + Models/Props/Highground3.mesh + + + + + + + + + + + Models/Highgrounds/Highground24.mesh + + + + + + + + + + + + Models/Highgrounds/Hg13.mesh + + + + + + + + + + + + + Models/Highgrounds/Hg25.mesh + + + + + + + + + + + + Models/Highgrounds/Hg26.mesh + + + + + + + + + + + + Models/Highgrounds/Hg9.mesh + + + + + + + + + + + + + Models/Highgrounds/Hg4.mesh + + + + + + + + + + + + + + Models/Highgrounds/Hg10.mesh + + + + + + + + + + + + + + Models/Highgrounds/Hg19.mesh + + + + + + + + + + + + + + Models/Highgrounds/Hg19.mesh + + + + + + + + + + + + + + + Models/Highgrounds/Highground12.mesh + + + + + + + + + + + + + Models/Highgrounds/Hg16.mesh + + + + + + + + + + + + Models/Highgrounds/Hg15.mesh + + + + + + + + + + + + Models/Highgrounds/Hg14.mesh + + + + + + + + + + + + + Models/Highgrounds/Hg13.mesh + + + + + + + + + + + + Models/Highgrounds/Hg11.mesh + + + + + + + + + + + + Models/Highgrounds/Hg20.mesh + + + + + + + + + + + + Models/Highgrounds/Hg18.mesh + + + + + + + + + + + + Models/Highgrounds/Hg19.mesh + + + + + + + + + + + + + Models/Highgrounds/Hg17.mesh + + + + + + + + + + + + + + + Models/Highgrounds/Hg8.mesh + + + + + + + + + + + + + Models/Highgrounds/Hg7.mesh + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + Models/Highgrounds/Hg3.mesh + + + + + + + + + + + + + + + Models/Props/Highground1.mesh + + + + + + + + + + + + Models/Props/Highground2.mesh + + + + + + + + + + + + + Models/Props/Highground3.mesh + + + + + + + + + + + + + Models/Highgrounds/Highground1.mesh + + + + + + + + + + + Models/Highgrounds/Highground2.mesh + + + + + + + + + + + + + + Models/Highgrounds/Hg1.mesh + + + + + + + + + + + Models/Highgrounds/Hg2.mesh + + + + + + + + + + + + + + Models/Highgrounds/Highground5.mesh + + + + + + + + + + + + Models/Highgrounds/Hg17.mesh + + + + + + + + + + + + + Models/Highgrounds/Hg19.mesh + + + + + + + + + + + + Models/Highgrounds/Hg18.mesh + + + + + + + + + + + + + Models/Highgrounds/Hg20.mesh + + + + + + + + + + + + + Models/Highgrounds/Hg6.mesh + + + + + + + + + + + + Models/Highgrounds/Hg8.mesh + + + + + + + + + + + + Models/Highgrounds/Hg7.mesh + + + + + + + + + + + + Models/Highgrounds/Hg10.mesh + + + + + + + + + + + + Models/Highgrounds/Hg4.mesh + + + + + + + + + + + + Models/Highgrounds/Hg16.mesh + + + + + + + + + + + + + Models/Highgrounds/Hg9.mesh + + + + + + + + + + + + Models/Highgrounds/Hg3.mesh + + + + + + + + + + + + + Models/Highgrounds/Hg19.mesh + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + + Models/Highgrounds/Hg10.mesh + + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + + + + Models/Highgrounds/Highground22.mesh + + + + + + + + + + + + Models/Highgrounds/Hg8.mesh + + + + + + + + + + + + + Models/Highgrounds/Hg19.mesh + + + + + + + + + + + + + Models/Highgrounds/Hg21.mesh + + + + + + + + + + + + Models/Highgrounds/Hg11.mesh + + + + + + + + + + + + Models/Highgrounds/Hg3.mesh + + + + + + + + + + + + + Models/Highgrounds/Hg17.mesh + + + + + + + + + + + + + Models/Highgrounds/Hg8.mesh + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + + + + Models/Highgrounds/Hg28.mesh + + + + + + + + + + + Models/Highgrounds/Hg10.mesh + + + + + + + + + + + + + Models/Highgrounds/Hg27.mesh + + + + + + + + + + + + + Models/Highgrounds/Hg15.mesh + + + + + + + + + + + + + + Models/Highgrounds/Hg13.mesh + + + + + + + + + + + + + + + Models/Highgrounds/Hg27.mesh + + + + + + + + + + + + Models/Highgrounds/Hg23.mesh + + + + + + + + + + + + + + + Models/Highgrounds/Hg27.mesh + + + + + + + + + + + + + Models/Highgrounds/Hg23.mesh + + + + + + + + + + + + + + + Models/Highgrounds/Hg28.mesh + + + + + + + + + + + + Models/Highgrounds/Hg10.mesh + + + + + + + + + + + + + Models/Highgrounds/Hg27.mesh + + + + + + + + + + + + + Models/Highgrounds/Hg15.mesh + + + + + + + + + + + + + + Models/Highgrounds/Hg13.mesh + + + + + + + + + + + + + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar1Red.mesh + + + + + + + + + + + + + 4 + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + + 4 + Models/Props/Pillars/SciFiPillar1Red.mesh + + + + + + + + + + + + + + 4 + Models/Props/Pillars/SciFiPillar3Red.mesh + + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + + 4 + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + + 4 + Models/Props/Pillars/SciFiPillar3Red.mesh + + + + + + + + + + + + + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2 + + + + + + + + + + + + + + 5 + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + 2 + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + 4 + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + 2 + + + + + + + + + + + + 3 + + + + + + + + + + + + 2 + 1 + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + 4 + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + 8 + + + + Models/Props/PickUps/HealthPickUp.mesh + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + 8 + + + + Models/Props/PickUps/HealthPickUp.mesh + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + 8 + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + 8 + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + 8 + + + + Models/Props/PickUps/HealthPickUp.mesh + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + 8 + + + + Models/Props/PickUps/HealthPickUp.mesh + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + 8 + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + 8 + + + + Models/Props/PickUps/HealthPickUp.mesh + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + 8 + + + + Models/Props/PickUps/HealthPickUp.mesh + + + + + + + + + + + + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/mediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/mediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/mediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/mediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/mediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/mediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/mediumStone2.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridge1Red.mesh + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridge1Red.mesh + + + + + + + + + + + + Models/Props/Pillars/SciFiBridgePillar1.mesh + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridge1Red.mesh + + + + + + + + + + + + Models/Props/Pillars/SciFiBridgePillar1.mesh + + + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + + + + Models/Props/Pillars/SciFiBridgePillar1.mesh + + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridge1Red.mesh + + + + + + + + + + + + + + + + + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/Flora/SpecialRoot.mesh + + + + + + + + + + + + + Models/Props/Flora/SpecialRoot.mesh + + + + + + + + + + + + + + Models/Props/Flora/SpecialRoot.mesh + + + + + + + + + + + + + + Models/Props/Flora/SpecialRoot.mesh + + + + + + + + + + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/MediumWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/MediumWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + + Models/Core/UnitPlane.mesh + + true + + + + + + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar1Red.mesh + + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + + + + + + + Models/Props/Walls/SpecialWall1.mesh + + + + + + + + + + + + + + Models/Props/Walls/SpecialWall1.mesh + + + + + + + + + + + + + + Models/Props/Walls/SpecialWall1.mesh + + + + + + + + + + + + + + Models/Props/Walls/SpecialWall1.mesh + + + + + + + + + + + + + + + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + 8 + + + + Models/Props/PickUps/HealthPickUp.mesh + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + 8 + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + + + + + + + + + + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/mediumStone2.mesh + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/MediumWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + Models/Props/Walls/BigWallRed.mesh + + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/smallWall3.mesh + + + + + + + + + + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar1Blue.mesh + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2 + + + + + + + + + + + + + + 5 + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + 2 + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + 4 + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + 2 + + + + + + + + + + + + 3 + + + + + + + + + + + + 2 + 1 + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + 4 + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + 6 + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + 8 + + + + Models/Props/PickUps/HealthPickUp.mesh + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + 8 + + + + Models/Props/PickUps/HealthPickUp.mesh + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + 8 + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + 8 + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + 8 + + + + Models/Props/PickUps/HealthPickUp.mesh + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + 8 + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + 8 + + + + Models/Props/PickUps/HealthPickUp.mesh + + + + + + + + + + + + + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/mediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridge1Blue.mesh + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + Models/Props/Bridges/SciFiBridgeDefense.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridge1Blue.mesh + + + + + + + + + + + + Models/Props/Pillars/SciFiBridgePillar1.mesh + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridge1Blue.mesh + + + + + + + + + + + + Models/Props/Pillars/SciFiBridgePillar1.mesh + + + + + + + + + + + + + + + + + Models/Props/Pillars/SciFiBridgePillar1.mesh + + + + + + + + + + + + + + Models/Props/Bridges/SciFiBridge1Blue.mesh + + + + + + + + + + + + + + + + + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/Flora/SpecialRoot.mesh + + + + + + + + + + + + + Models/Props/Flora/SpecialRoot.mesh + + + + + + + + + + + + + + Models/Props/Flora/SpecialRoot.mesh + + + + + + + + + + + + + + Models/Props/Flora/SpecialRoot.mesh + + + + + + + + + + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/MediumWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + + Models/Props/Walls/BigWallBlue.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/MediumWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Props/Walls/MediumWall3.mesh + + + + + + + + + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + + + + + + + Models/Core/UnitPlane.mesh + + true + + + + + + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar1Blue.mesh + + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + + + + + + + Models/Props/Pillars/StonePillar.mesh + + + + + + + + + + + + + + + + + + + Models/Props/Walls/SpecialWall1.mesh + + + + + + + + + + + + + + Models/Props/Walls/SpecialWall1.mesh + + + + + + + + + + + + + + Models/Props/Walls/SpecialWall1.mesh + + + + + + + + + + + + + + Models/Props/Walls/SpecialWall1.mesh + + + + + + + + + + + + + + + + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar1Blue.mesh + + + + + + + + + + + + + 4 + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + + 4 + Models/Props/Pillars/SciFiPillar3Blue.mesh + + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + + 4 + Models/Props/Pillars/SciFiPillar2Red.mesh + + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + + 6 + Models/Props/Pillars/SciFiPillar2Blue.mesh + + + + + + + + + + + + + + 4 + Models/Props/Pillars/SciFiPillar3Blue.mesh + + + + + + + + + + + + + + + + + + + + + + + Models/Props/CapturePoint/CapturePointBlue.mesh + + + + + + + + + + + + + -15 + 4 + + + Models/Core/UnitCylinder.mesh + + true + + + + + + + + + + + + + + + + + + + + + Models/Props/CapturePoint/CapturePointNeutral.mesh + + + + + + + + + + 3 + + + Models/Core/UnitCylinder.mesh + + true + + + + + + + + + + + + + + + + + Models/Props/CapturePoint/CapturePointNeutral.mesh + + + + + + + + + + 15 + 2 + + + Models/Core/UnitCylinder.mesh + + true + + + + + + + + + + + + + + + + + + + + + Models/Props/CapturePoint/CapturePointNeutral.mesh + + + + + + + + + + 15 + 1 + + + Models/Core/UnitCylinder.mesh + + true + + + + + + + + + + + + + + + + + + + + + Models/Props/CapturePoint/CapturePointRed.mesh + + + + + + + + + + + + + 15 + + + Models/Core/UnitCylinder.mesh + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + + + + + + + + + 10 + + + + + + + + + + + 10 + + + + + + + + + + + 10 + + + + + + + + + + + + 10 + + + + + + + + + + + 1 + + + + + + + + + + + + 10 + + + + + + + + + + + + + + Schema/Entities/PlayerRed.xml + + + + + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + + + Schema/Entities/Player.xml + + + + + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + From 1210c915351def2445ab8e9749e578261658d518 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Thu, 3 Mar 2016 13:51:47 +0100 Subject: [PATCH 117/130] Added Gameplay.AutoReload bool to config --- include/Game/Systems/Weapon/WeaponBehaviour.h | 8 ++++++-- resources/DefaultConfig.ini | 3 +++ src/Game/Systems/Weapon/DefenderWeaponBehaviour.cpp | 10 +++++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/include/Game/Systems/Weapon/WeaponBehaviour.h b/include/Game/Systems/Weapon/WeaponBehaviour.h index e0783bd2..d4520c9f 100644 --- a/include/Game/Systems/Weapon/WeaponBehaviour.h +++ b/include/Game/Systems/Weapon/WeaponBehaviour.h @@ -8,6 +8,7 @@ #include "Input/EInputCommand.h" #include "Systems/SpawnerSystem.h" #include "Rendering/ESetCamera.h" +#include "Core/ConfigFile.h" template class WeaponBehaviour : public PureSystem @@ -21,8 +22,10 @@ public: , m_Renderer(renderer) , m_CollisionOctree(collisionOctree) { - EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &WeaponBehaviour::_OnInputCommand) - EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &WeaponBehaviour::_OnSetCamera) + EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &WeaponBehaviour::_OnInputCommand); + EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &WeaponBehaviour::_OnSetCamera); + auto config = ResourceManager::Load("Config.ini"); + m_ConfigAutoReload = config->Get("Gameplay.AutoReload", true); } virtual ~WeaponBehaviour() = default; @@ -49,6 +52,7 @@ protected: EntityWrapper m_CurrentCamera; Octree* m_CollisionOctree; std::unordered_map m_ActiveWeapons; + bool m_ConfigAutoReload; virtual void UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo& wi, double dt) { } virtual void OnPrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi) { } diff --git a/resources/DefaultConfig.ini b/resources/DefaultConfig.ini index 8917e3e1..fd468fd6 100644 --- a/resources/DefaultConfig.ini +++ b/resources/DefaultConfig.ini @@ -1,3 +1,6 @@ +[Gameplay] +AutoReload=true + [Debug] LogLevel=1 LoadMap= diff --git a/src/Game/Systems/Weapon/DefenderWeaponBehaviour.cpp b/src/Game/Systems/Weapon/DefenderWeaponBehaviour.cpp index 50d5889d..3a4ed3a4 100644 --- a/src/Game/Systems/Weapon/DefenderWeaponBehaviour.cpp +++ b/src/Game/Systems/Weapon/DefenderWeaponBehaviour.cpp @@ -14,11 +14,16 @@ void DefenderWeaponBehaviour::UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo& double& reloadTimer = cWeapon["ReloadTimer"]; reloadTimer = glm::max(0.0, reloadTimer - dt); + // Start reloading automatically if at 0 mag ammo + int& magAmmo = cWeapon["MagazineAmmo"]; + if (m_ConfigAutoReload && magAmmo <= 0) { + OnReload(cWeapon, wi); + } + // Handle reloading - double reloadTime = cWeapon["ReloadTime"]; bool& isReloading = cWeapon["IsReloading"]; if (isReloading && reloadTimer <= 0.0) { - int& magAmmo = cWeapon["MagazineAmmo"]; + double reloadTime = cWeapon["ReloadTime"]; int& magSize = cWeapon["MagazineSize"]; int& ammo = cWeapon["Ammo"]; if (magAmmo < magSize && ammo > 0) { @@ -130,7 +135,6 @@ void DefenderWeaponBehaviour::fireShell(ComponentWrapper cWeapon, WeaponInfo& wi // Ammo int& magAmmo = cWeapon["MagazineAmmo"]; if (magAmmo <= 0) { - OnReload(cWeapon, wi); return; } else { magAmmo -= 1; From 73b8bff1f3ebfad3de5e22d06d53ce2cb1779c4f Mon Sep 17 00:00:00 2001 From: Tobias Dahl Date: Thu, 3 Mar 2016 14:24:43 +0100 Subject: [PATCH 118/130] Revert "Shadows" --- include/Engine/Rendering/DrawFinalPass.h | 4 +- include/Engine/Rendering/Renderer.h | 2 - include/Engine/Rendering/ShadowPass.h | 87 - include/Engine/Rendering/ShadowPassState.h | 15 - resources/Schema/Entities/GameMap.xml | 7 - resources/Schema/Entities/OliviaTestWorld.xml | 1558 ----------------- .../Schema/Entities/QualityAssurance.xml | 4 +- resources/Shaders/ExplosionEffect.geom.glsl | 6 - resources/Shaders/ForwardPlus.frag.glsl | 179 +- resources/Shaders/ForwardPlus.vert.glsl | 10 - .../Shaders/ForwardPlusShieldCheck.frag.glsl | 2 - .../Shaders/ForwardPlusSkinned.vert.glsl | 10 - .../Shaders/ForwardPlusSplatMap.frag.glsl | 3 - .../Shaders/ForwardPlusSplatMapRGB.frag.glsl | 2 - resources/Shaders/Shadow.frag.glsl | 22 - resources/Shaders/Shadow.vert.glsl | 18 - src/Engine/Rendering/DrawFinalPass.cpp | 20 +- src/Engine/Rendering/FrameBuffer.cpp | 8 +- src/Engine/Rendering/Renderer.cpp | 8 +- src/Engine/Rendering/ShadowPass.cpp | 305 ---- src/Engine/Rendering/ShadowPassState.cpp | 19 - 21 files changed, 9 insertions(+), 2280 deletions(-) delete mode 100644 include/Engine/Rendering/ShadowPass.h delete mode 100644 include/Engine/Rendering/ShadowPassState.h delete mode 100644 resources/Schema/Entities/OliviaTestWorld.xml delete mode 100644 resources/Shaders/Shadow.frag.glsl delete mode 100644 resources/Shaders/Shadow.vert.glsl delete mode 100644 src/Engine/Rendering/ShadowPass.cpp delete mode 100644 src/Engine/Rendering/ShadowPassState.cpp diff --git a/include/Engine/Rendering/DrawFinalPass.h b/include/Engine/Rendering/DrawFinalPass.h index c5b937c6..cfddd5c6 100644 --- a/include/Engine/Rendering/DrawFinalPass.h +++ b/include/Engine/Rendering/DrawFinalPass.h @@ -11,12 +11,11 @@ #include "Util/UnorderedMapVec2.h" #include "Util/CommonFunctions.h" #include "Texture.h" -#include "ShadowPass.h" class DrawFinalPass { public: - DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass, CubeMapPass* cubeMapPass, SSAOPass* ssaoPass, ShadowPass* shadowPass); + DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass, CubeMapPass* cubeMapPass, SSAOPass* ssaoPass); ~DrawFinalPass() { } void InitializeTextures(); void InitializeFrameBuffers(); @@ -66,7 +65,6 @@ private: const LightCullingPass* m_LightCullingPass; const CubeMapPass* m_CubeMapPass; const SSAOPass* m_SSAOPass; - const ShadowPass* m_ShadowPass; ShaderProgram* m_ForwardPlusProgram; ShaderProgram* m_ExplosionEffectProgram; diff --git a/include/Engine/Rendering/Renderer.h b/include/Engine/Rendering/Renderer.h index fd3b215e..a64a4aa3 100644 --- a/include/Engine/Rendering/Renderer.h +++ b/include/Engine/Rendering/Renderer.h @@ -26,7 +26,6 @@ #include "TextPass.h" #include "Util/CommonFunctions.h" #include "Core/PerformanceTimer.h" -#include "ShadowPass.h" class Renderer : public IRenderer { @@ -76,7 +75,6 @@ private: DrawColorCorrectionPass* m_DrawColorCorrectionPass; SSAOPass* m_SSAOPass; CubeMapPass* m_CubeMapPass; - ShadowPass* m_ShadowPass; //----------------------Functions----------------------// void InitializeWindow(); diff --git a/include/Engine/Rendering/ShadowPass.h b/include/Engine/Rendering/ShadowPass.h deleted file mode 100644 index 6db8a624..00000000 --- a/include/Engine/Rendering/ShadowPass.h +++ /dev/null @@ -1,87 +0,0 @@ -#ifndef ShadowPass_h__ -#define ShadowPass_h__ - -#include "IRenderer.h" -#include "FrameBuffer.h" -#include "ShaderProgram.h" -#include "../Core/EventBroker.h" -#include "../Core/World.h" -#include "ShadowPassState.h" -#include "imgui/imgui.h" - -#define MAX_SPLITS 4 - -enum NearFar { NEAR = 0, FAR = 1 }; -enum LRBT { LEFT = 0, RIGHT = 1, BOTTOM = 2, TOP = 3 }; - -struct ShadowFrustum -{ - float NearClip; - float FarClip; - float FOV; - float AspectRatio; - glm::vec3 MiddlePoint; - float Radius; - std::array LRBT; - std::array CornerPoint; -}; - -class ShadowPass -{ -public: - ShadowPass(IRenderer* renderer); - ShadowPass(IRenderer * renderer, int ShadowResX, int ShadowResY); - ~ShadowPass(); - - void InitializeFrameBuffers(); - void InitializeShaderPrograms(); - void ClearBuffer(); - void Draw(RenderScene& scene); - - void DebugGUI(); - - GLuint DepthMap() const { return m_DepthMap; } - std::array LightP() const { return m_LightProjection; } - std::array LightV() const { return m_LightView; } - std::array FarDistance() const { std::array f; for (int i = 0; i < MAX_SPLITS; i++) f[i] = m_shadowFrusta[i].FarClip; return f; } - int CurrentNrOfSplits() const { return m_CurrentNrOfSplits; } - - void SetSplitWeight(float split_weight) { m_SplitWeight = split_weight; }; -private: - void InitializeCameras(RenderScene & scene); - void UpdateSplitDist(std::array& frusta, float near_distance, float far_distance); - void UpdateFrustumPoints(ShadowFrustum& frustum, glm::vec3 camera_position, glm::vec3 view_dir); - void UpdateFrustumPoints(ShadowFrustum& frustum, glm::mat4 p, glm::mat4 v); - - void PointsToLightspace(ShadowFrustum& frustum, glm::mat4 v); - - float FindRadius(ShadowFrustum& frustum); - void RadiusToLightspace(ShadowFrustum& frustum); - - EventBroker* m_EventBroker; - const IRenderer* m_Renderer; - - GLuint m_DepthMap; - FrameBuffer m_DepthBuffer; - ShaderProgram* m_ShadowProgram; - - std::array m_LightProjection; - std::array m_LightView; - - GLfloat m_NearFarPlane[2] = { -34.f, 27.f }; - GLuint m_ResolutionSizeWidth = 1024 * 2; - GLuint m_ResolutionSizeHeight = 1024 * 2; - - bool m_TransparentObjects = false; - bool m_TexturedShadows = false; - bool m_EnableShadows = true; - - int m_CurrentNrOfSplits = 4; - float m_SplitWeight = 0.962f; - - std::array m_shadowFrusta; - - Texture* m_WhiteTexture = ResourceManager::Load("Textures/Core/White.png"); -}; - -#endif \ No newline at end of file diff --git a/include/Engine/Rendering/ShadowPassState.h b/include/Engine/Rendering/ShadowPassState.h deleted file mode 100644 index f881b48e..00000000 --- a/include/Engine/Rendering/ShadowPassState.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef ShadowPassState_h_ -#define ShadowPassState_h_ - -#include "Rendering/RenderState.h" - -class ShadowPassState : public RenderState -{ -public: - ShadowPassState(GLuint frameBuffer); - ~ShadowPassState(); - -private: -}; - -#endif \ No newline at end of file diff --git a/resources/Schema/Entities/GameMap.xml b/resources/Schema/Entities/GameMap.xml index 473b9037..c3a16361 100644 --- a/resources/Schema/Entities/GameMap.xml +++ b/resources/Schema/Entities/GameMap.xml @@ -245,13 +245,6 @@ - - - - - - - diff --git a/resources/Schema/Entities/OliviaTestWorld.xml b/resources/Schema/Entities/OliviaTestWorld.xml deleted file mode 100644 index 23c2b283..00000000 --- a/resources/Schema/Entities/OliviaTestWorld.xml +++ /dev/null @@ -1,1558 +0,0 @@ - - - - - - - - - - - - - - - - Models/Core/UnitPlane.mesh - - - - - - - - - - - 90 - - - - - - - - - - - - 1 - - - - - - - - - - - Audio/crosscounter.wav - true - - - - - - - - - - SoundEmitter - Fonts/DroidSans.ttf,64 - - - - - - - - - - - - - - - - - - - - - Sound Test - Fonts/DroidSans.ttf,64 - - - - - - - - - - - - - 0.80000001192092896 - - - Models/DirectionalLightWidget.mesh - - - 1 - - - - - - - - - - - - - - - - - - - - - Run - - 1 - - - models/AssaultAnimated.mesh - - - - - - - - - - - Walk - - 1 - - - models/AssaultAnimated.mesh - - - - - - - - - Animation test - Fonts/DroidSans.ttf,64 - - - - - - - - - - - - Models/Core/UnitCylinder.mesh - - - - - - - - - - - - - - - - - - - - 0.5 - - - - - - - - - - - Run - - 1 - - - Models/AssaultAnimated.mesh - - - - - - - - - - - - - - - - - - - - - - - - models/NormSpecIncdMapSphere.mesh - - - - - - - - - 1 - - - - - - - - - - - Models/Core/UnitSphere.mesh - - - - 3 - 1.1399998664855957 - - - - - - - - - - - - Models/Core/UnitSphere.mesh - - - - 5.0100002288818359 - 0.69999998807907104 - - - - - - - - - - - - Models/Core/UnitSphere.mesh - - - - 4 - 0.80000001192092896 - - - - - - - - - - - - - - 1 - - - - - - - - - - - Models/NormalMapSphere.mesh - - - - - - - - - - - Models/SpecularMapSphere.mesh - - - - - - - - - - 1 - - - - - - - - - - - Models/Core/UnitSphere.mesh - - - - 3 - 1.1399998664855957 - - - - - - - - - - - - - - - - Models/IncandescenceMapSphere.mesh - - - - - - - - - - - - - TextureMap's Test - Fonts/DroidSans.ttf,64 - - - - - - - - - - - - - - 1.3999999761581421 - - - - - - - - - - - - - - - - - Schema/Entities/Player.xml - - - - - - - - - - - - - - - - Models/Assault.mesh - - - - - - - - - - - - - Models/Assault.mesh - - - - - - - - - - - - - Models/Assault.mesh - - - - - - - - - - - - - Models/Assault.mesh - - - - - - - - - - - - - - - Schema/Entities/Player.xml - - - - - - - - - - - - - - - - - Models/Assault.mesh - - - - - - - - - - - - - Models/Assault.mesh - - - - - - - - - - - - - Models/Assault.mesh - - - - - - - - - - - - - Models/Assault.mesh - - - - - - - - - - - - - - Spawn Test - Fonts/DroidSans.ttf,64 - - - - - - - - - - - - - - - - - - - - - Models/Core/UnitCube.mesh - - true - - - - - - - - - - - Models/Core/UnitCylinder.mesh - - true - - - - - - - - - - - - Models/Core/UnitRaptor.mesh - - true - - - - - - - - - - - Models/Assault.mesh - - true - - - - - - - - - - - - Models/Core/UnitCube.mesh - - true - - - - - - - - - - - - - Transparency Test - Fonts/DroidSans.ttf,64 - - - - - - - - - - - - - - - - - - - - - Models/Core/UnitCylinder.mesh - - - - - - - - - - - - - - - - - - - - 0.5 - - - - - - - - - - - Models/AssaultBlueWeapon.mesh - - - - - - - - - - - - - - - - Models/Core/UnitCylinder.mesh - - - - - - - - - - - - - - - - - - - - 0.5 - - - - - - - - - - - Models/AssaultRedWeapon.mesh - - - - - - - - - - - - - - - - Asset Test - Fonts/DroidSans.ttf,64 - - - - - - - - - - - - Models/Core/UnitCylinder.mesh - - - - - - - - - - - - - - - - - - - - 0.5 - - - - - - - - - - - Models/SecondaryWeapon.mesh - - - - - - - - - - - - - - - - Models/Core/UnitCylinder.mesh - - - - - - - - - - - - - - - - - - - - 0.5 - - - - - - - - - - - Models/AssualtSoft.mesh - - - - - - - - - - - - - - - Models/Core/UnitCylinder.mesh - - - - - - - - - - - - - - - - - - - - 0.5 - - - - - - - - - - - Models/DefenderGunBlue.mesh - - - - - - - - - - - - - - - - Models/Core/UnitCylinder.mesh - - - - - - - - - - - - - - - - - - - - 0.5 - - - - - - - - - - - Models/DefenderGunRed.mesh - - - - - - - - - - - - - - - - Models/Core/UnitCylinder.mesh - - - - - - - - - - - - - - - - - - - - 0.5 - - - - - - - - - - - Models/Assualt.mesh - - - - - - - - - - - - - - - - - - - - - - - - CapturePoint Test - Fonts/DroidSans.ttf,64 - - - - - - - - - - - - Models/CapturePoint.mesh - - - - - - - - - - - - - - - - Models/Core/UnitCube.mesh - - true - - - - - - - - - - - - - - - - - - Red team home point - Fonts/DroidSans.ttf,64 - - - - - - - - - - - - - - - Models/CapturePoint.mesh - - - - - - - - - - - 1 - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - - RedMiddle Point - Fonts/DroidSans.ttf - - - - - - - - - - - - - - - Models/CapturePoint.mesh - - - - - - - - - 2 - - - Models/Core/UnitCube.mesh - true - - - - - - - - - - - - - - Middle Point - Fonts/DroidSans.ttf,64 - - - - - - - - - - - - - - - Models/CapturePoint.mesh - - - - - - - - - - - -12.033302729641917 - 3 - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - - BlueMiddle Point - Fonts/DroidSans.ttf - - - - - - - - - - - - - - - Models/CapturePoint.mesh - - - - - - - - - - - - - - 4 - - - Models/Core/UnitCube.mesh - - true - - - - - - - - - - - - - - - - - - Blue team home point - Fonts/DroidSans.ttf,64 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Models/Test/ObstacleCourse.mesh - - - - - - - - - - - Collision Test - Fonts/DroidSans.ttf,64 - - - - - - - - - - - - - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - - - - - - - - Models/Core/UnitCylinder.mesh - - - - - - - - - - - - - - - - - - - - 0.5 - - - - - - - - - - - true - - 2.3331127968986038 - 3.7999999523162842 - - true - - - Models/AssaultWeaponBlue.mesh - true - - - - - - - - - - - - - - - - Models/Core/UnitCylinder.mesh - - - - - - - - - - - - - - - - - - - - 0.5 - - - - - - - - - - - - - 0.28322599621543532 - - - Models/Assault.mesh - true - - - - - - - - - - - - - - - Models/Core/UnitCylinder.mesh - - - - - - - - - - - - - - - - - - - - 0.5 - - - - - - - - - - - Walk - - 1 - - - true - - - 1.8831113377486872 - - true - - - Models/AssaultAnimated.mesh - true - - - - - - - - - - - - - - - ExplosionEffect Test - Fonts/DroidSans.ttf,64 - - - - - - - - - - - - - - - - - - - - - Remember to pick random entities. - Fonts/DroidSans.ttf,64 - - - - - - - - - - - - - - diff --git a/resources/Schema/Entities/QualityAssurance.xml b/resources/Schema/Entities/QualityAssurance.xml index 0d9421ab..04cc288a 100644 --- a/resources/Schema/Entities/QualityAssurance.xml +++ b/resources/Schema/Entities/QualityAssurance.xml @@ -559,8 +559,8 @@ - Models/BushAlive.mesh - + Models/Core/UnitCube.mesh + true diff --git a/resources/Shaders/ExplosionEffect.geom.glsl b/resources/Shaders/ExplosionEffect.geom.glsl index ffc78900..44b44aa6 100644 --- a/resources/Shaders/ExplosionEffect.geom.glsl +++ b/resources/Shaders/ExplosionEffect.geom.glsl @@ -1,7 +1,5 @@ #version 430 -#define MAX_SPLITS 4 - uniform mat4 M; uniform mat4 V; uniform mat4 P; @@ -24,7 +22,6 @@ in VertexData{ vec2 TextureCoordinate; vec4 ExplosionColor; float ExplosionPercentageElapsed; - vec4 PositionLightSpace[MAX_SPLITS]; }Input[]; out VertexData{ @@ -35,7 +32,6 @@ out VertexData{ vec2 TextureCoordinate; vec4 ExplosionColor; float ExplosionPercentageElapsed; - vec4 PositionLightSpace[MAX_SPLITS]; }Output; layout(triangles) in; @@ -149,7 +145,6 @@ void main() Output.TextureCoordinate = Input[i].TextureCoordinate; Output.Tangent = Input[i].Tangent; Output.BiTangent = Input[i].BiTangent; - Output.PositionLightSpace = Input[i].PositionLightSpace; // convert to model space for the gravity to always be in -y vec4 ExplodedPositionInModelSpace = M * vec4(ExplodedPosition, 1.0); @@ -191,7 +186,6 @@ void main() Output.TextureCoordinate = Input[i].TextureCoordinate; Output.Tangent = Input[i].Tangent; Output.BiTangent = Input[i].BiTangent; - Output.PositionLightSpace = Input[i].PositionLightSpace; // no change in position, pass through vertex gl_Position = gl_in[i].gl_Position; diff --git a/resources/Shaders/ForwardPlus.frag.glsl b/resources/Shaders/ForwardPlus.frag.glsl index f7ddd00c..aa45d118 100644 --- a/resources/Shaders/ForwardPlus.frag.glsl +++ b/resources/Shaders/ForwardPlus.frag.glsl @@ -1,7 +1,6 @@ #version 430 #define MIN_AMBIENT_LIGHT 0.3 -#define MAX_SPLITS 4 uniform mat4 M; uniform mat4 V; @@ -15,7 +14,6 @@ uniform float FillPercentage; uniform float GlowIntensity = 10; uniform vec3 CameraPosition; uniform int SSAOQuality; -uniform float FarDistance[MAX_SPLITS]; uniform vec2 DiffuseUVRepeat; uniform vec2 NormalUVRepeat; @@ -27,7 +25,6 @@ layout (binding = 2) uniform sampler2D NormalMapTexture; layout (binding = 3) uniform sampler2D SpecularMapTexture; layout (binding = 4) uniform sampler2D GlowMapTexture; layout (binding = 5) uniform samplerCube CubeMap; -layout (binding = 13) uniform sampler2DArrayShadow DepthMap; #define TILE_SIZE 16 @@ -62,6 +59,7 @@ layout (std430, binding = 4) buffer LightIndexBuffer float LightIndex[]; }; + in VertexData{ vec3 Position; vec3 Normal; @@ -70,7 +68,6 @@ in VertexData{ vec2 TextureCoordinate; vec4 ExplosionColor; float ExplosionPercentageElapsed; - vec4 PositionLightSpace[MAX_SPLITS]; }Input; out vec4 sceneColor; @@ -81,25 +78,6 @@ struct LightResult { vec4 Specular; }; -vec2 poissonDisk[16] = vec2[]( - vec2( -0.94201624, -0.39906216 ), - vec2( 0.94558609, -0.76890725 ), - vec2( -0.094184101, -0.92938870 ), - vec2( 0.34495938, 0.29387760 ), - vec2( -0.91588581, 0.45771432 ), - vec2( -0.81544232, -0.87912464 ), - vec2( -0.38277543, 0.27676845 ), - vec2( 0.97484398, 0.75648379 ), - vec2( 0.44323325, -0.97511554 ), - vec2( 0.53742981, -0.47373420 ), - vec2( -0.26496911, -0.41893023 ), - vec2( 0.79197514, 0.19090188 ), - vec2( -0.24188840, 0.99706507 ), - vec2( -0.81409955, 0.91437590 ), - vec2( 0.19984126, 0.78641367 ), - vec2( 0.14383161, -0.14100790 ) - ); - float CalcAttenuation(float radius, float dist, float falloff) { return 1.0 - smoothstep(radius * falloff, radius, dist); } @@ -146,154 +124,6 @@ vec4 CalcNormalMappedValue(vec3 normal, vec3 tangent, vec3 bitangent, vec2 textu return vec4(TBN * normalize(NormalMap), 0.0); } -// Returns a "random" value. -float Random(vec3 seed, int i) -{ - vec4 seed4 = vec4(seed, i); - float dot_product = dot(seed4, vec4(12.9898, 78.233, 45.164, 94.673)); - return fract(sin(dot_product) * 43758.5453); -} - -int getShadowIndex(float far_distance[1]) -{ - return 0; -} - -int getShadowIndex(float far_distance[2]) -{ - float depth = gl_FragCoord.z / gl_FragCoord.w; - - int index = 1; - if ( depth < far_distance[0] ) - { - index = 0; - } - - return index; -} - -int getShadowIndex(float far_distance[3]) -{ - float depth = gl_FragCoord.z / gl_FragCoord.w; - - int index = 2; - if ( depth < far_distance[0] ) - { - index = 0; - } - else if ( depth < far_distance[1] && depth > far_distance[0] ) - { - index = 1; - } - - return index; -} - -int getShadowIndex(float far_distance[4]) -{ - float depth = gl_FragCoord.z / gl_FragCoord.w; - - int index = 3; - if ( depth < far_distance[0] ) - { - index = 0; - } - else if ( depth < far_distance[1] && depth > far_distance[0] ) - { - index = 1; - } - else if ( depth < far_distance[2] && depth > far_distance[1] ) - { - index = 2; - } - - return index; -} - -// Standard hardware-calculated PCF method -float PCFShadow(sampler2DArrayShadow depth_texture_array, vec3 projection_coords, int layer_index) -{ - return texture(depth_texture_array, vec4(projection_coords.xy, layer_index, projection_coords.z)); -} - -// PCF + Poisson model method -float PoissonShadow(sampler2DArrayShadow depth_texture_array, vec3 projection_coords, int layer_index, int taps, float spread) -{ - int loop; - float multiplier = 1.0 / float(taps); - float shadowMapDepth; - - for (int i = 0; i < taps; i++) - { - loop = i; - vec3 newProjCoords = projection_coords + vec3(poissonDisk[loop], 0.0) / (spread * (1.0 + layer_index)); - shadowMapDepth += multiplier * texture(depth_texture_array, vec4(newProjCoords.xy, layer_index, newProjCoords.z)); - } - - return shadowMapDepth; -} - -// PCF + Poisson + RandomSample model method -float PoissonDotShadow(sampler2DArrayShadow depth_texture_array, vec3 projection_coords, int layer_index, int taps, float spread) -{ - int loop; - float multiplier = 1.0 / float(taps); - float shadowMapDepth; - - for (int i = 0; i < taps; i++) - { - loop = int(16.0 * Random(gl_FragCoord.xyy, i)) % 16; - vec3 newProjCoords = projection_coords + vec3(poissonDisk[loop], 0.0) / (spread * (1.0 + layer_index)); - shadowMapDepth += multiplier * texture(depth_texture_array, vec4(newProjCoords.xy, layer_index, newProjCoords.z)); - } - - return shadowMapDepth; -} - -// Hardware PCF + Additional software PCF method -float SoftwarePCF(sampler2DArrayShadow depth_texture_array, vec3 projection_coords, int layer_index, float bias) -{ - float shadow = 0.0; - - vec3 texelSize = 1.0 / textureSize(depth_texture_array, 0); - for(int x = -1; x <= 1; x++) - { - for(int y = -1; y <= 1; y++) - { - shadow += texture(depth_texture_array, vec4(projection_coords.xy + vec2(x, y) * texelSize.xy / (1.0 + layer_index), layer_index, projection_coords.z)); - } - } - - return shadow / 9.0; -} - -float CalcShadowValue(vec4 light_space_pos, vec3 normal, vec3 light_dir, sampler2DArrayShadow depth_texture_array, int layer_index) -{ - float shadowMapDepth; - float bias = 0.005; - - // Various bias methods. - - //bias = max(0.05 * (1.0 - dot(normal, light_dir)), bias); - //bias = bias * tan(acos(clamp(dot(normal, -light_dir), 0.0, 1.0))); - bias = bias + bias * tan(acos(clamp(dot(normal, -light_dir), 0.0, 1.0))); - - // Calculate coordinates in projection space. - - vec3 projCoords = vec3(light_space_pos.xy, light_space_pos.z + bias) / light_space_pos.w; - projCoords = projCoords * 0.5 + 0.5; - //projCoords = (floor(projCoords * 255.0)) / 255.0; - - // Various methods for shadow calculation in fastest to slowest order. - - //shadowMapDepth = PCFShadow(depth_texture_array, projCoords, layer_index); - //shadowMapDepth = PoissonShadow(depth_texture_array, projCoords, layer_index, 4, 25.0 * FarDistance[MAX_SPLITS - 1]); - //shadowMapDepth = PoissonDotShadow(depth_texture_array, projCoords, layer_index, 4, 25.0 * FarDistance[MAX_SPLITS - 1]); - shadowMapDepth = SoftwarePCF(depth_texture_array, projCoords, layer_index, bias); - - return shadowMapDepth; -} - void main() { float ao = texelFetch(AOTexture, ivec2(gl_FragCoord.xy) >> int(SSAOQuality), 0).r; @@ -321,8 +151,6 @@ void main() int start = int(LightGrids.Data[currentTile].Start); int amount = int(LightGrids.Data[currentTile].Amount); - - float shadowFactor = 0.0; for(int i = start; i < start + amount; i++) { @@ -334,16 +162,11 @@ void main() if(light.Type == 1) { // point light_result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, position, normal, light.Falloff); } else if (light.Type == 2) { //Directional - int DepthMapIndex = getShadowIndex(FarDistance); light_result = CalcDirectionalLightSource(V * light.Direction, light.Color, light.Intensity, viewVec, normal); - shadowFactor = CalcShadowValue(Input.PositionLightSpace[DepthMapIndex], Input.Normal, vec3(light.Direction), DepthMap, DepthMapIndex); } totalLighting.Diffuse += vec4(light_result.Diffuse.rgb * ao, light_result.Diffuse.a); totalLighting.Specular += vec4(light_result.Specular.rgb * ao, light_result.Specular.a); } - - totalLighting.Diffuse *= vec4(min(vec3(shadowFactor) + AmbientColor.xyz, vec3(1.0)), 1.0); - totalLighting.Specular *= vec4(min(vec3(shadowFactor) + AmbientColor.xyz, vec3(1.0)), 1.0); vec4 color_result = mix((Color * diffuseTexel * DiffuseColor), Input.ExplosionColor, Input.ExplosionPercentageElapsed); color_result = color_result * (totalLighting.Diffuse + (totalLighting.Specular * specularTexel)); diff --git a/resources/Shaders/ForwardPlus.vert.glsl b/resources/Shaders/ForwardPlus.vert.glsl index 2a54415b..26686222 100644 --- a/resources/Shaders/ForwardPlus.vert.glsl +++ b/resources/Shaders/ForwardPlus.vert.glsl @@ -1,12 +1,8 @@ #version 430 -#define MAX_SPLITS 4 - uniform mat4 M; uniform mat4 V; uniform mat4 P; -uniform mat4 LightV[MAX_SPLITS]; -uniform mat4 LightP[MAX_SPLITS]; layout(location = 0) in vec3 Position; layout(location = 1) in vec3 Normal; @@ -22,7 +18,6 @@ out VertexData{ vec2 TextureCoordinate; vec4 ExplosionColor; float ExplosionPercentageElapsed; - vec4 PositionLightSpace[MAX_SPLITS]; }Output; void main() @@ -36,9 +31,4 @@ void main() Output.BiTangent = vec3(TIM * vec4(BiTangent, 0.0)); Output.ExplosionColor = vec4(1.0); Output.ExplosionPercentageElapsed = 0.0; - - for(int i = 0; i < MAX_SPLITS; i++) - { - Output.PositionLightSpace[i] = LightP[i] * LightV[i] * M * vec4(Position, 1.0); - } } \ No newline at end of file diff --git a/resources/Shaders/ForwardPlusShieldCheck.frag.glsl b/resources/Shaders/ForwardPlusShieldCheck.frag.glsl index 8c7dce04..35db495b 100644 --- a/resources/Shaders/ForwardPlusShieldCheck.frag.glsl +++ b/resources/Shaders/ForwardPlusShieldCheck.frag.glsl @@ -1,7 +1,6 @@ #version 430 #define MIN_AMBIENT_LIGHT 0.3 -#define MAX_SPLITS 4 uniform mat4 M; uniform mat4 V; @@ -70,7 +69,6 @@ in VertexData{ vec2 TextureCoordinate; vec4 ExplosionColor; float ExplosionPercentageElapsed; - vec4 PositionLightSpace[MAX_SPLITS]; }Input; out vec4 sceneColor; diff --git a/resources/Shaders/ForwardPlusSkinned.vert.glsl b/resources/Shaders/ForwardPlusSkinned.vert.glsl index 12b3c406..5fd55a8c 100644 --- a/resources/Shaders/ForwardPlusSkinned.vert.glsl +++ b/resources/Shaders/ForwardPlusSkinned.vert.glsl @@ -1,13 +1,9 @@ #version 430 -#define MAX_SPLITS 4 - uniform mat4 M; uniform mat4 V; uniform mat4 P; uniform mat4 Bones[100]; -uniform mat4 LightV[MAX_SPLITS]; -uniform mat4 LightP[MAX_SPLITS]; layout(location = 0) in vec3 Position; layout(location = 1) in vec3 Normal; @@ -25,7 +21,6 @@ out VertexData{ vec2 TextureCoordinate; vec4 ExplosionColor; float ExplosionPercentageElapsed; - vec4 PositionLightSpace[MAX_SPLITS]; }Output; void main() @@ -48,9 +43,4 @@ void main() Output.BiTangent = vec3(M * vec4(BiTangent, 0.0)); Output.ExplosionColor = vec4(1.0); Output.ExplosionPercentageElapsed = 0.0; - - for(int i = 0; i < MAX_SPLITS; i++) - { - Output.PositionLightSpace[i] = LightP[i] * LightV[i] * M * boneTransform * vec4(Position, 1.0); - } } \ No newline at end of file diff --git a/resources/Shaders/ForwardPlusSplatMap.frag.glsl b/resources/Shaders/ForwardPlusSplatMap.frag.glsl index 655f5502..239c51b5 100644 --- a/resources/Shaders/ForwardPlusSplatMap.frag.glsl +++ b/resources/Shaders/ForwardPlusSplatMap.frag.glsl @@ -1,7 +1,5 @@ #version 430 -#define MAX_SPLITS 4 - uniform mat4 M; uniform mat4 V; uniform mat4 P; @@ -97,7 +95,6 @@ in VertexData{ vec2 TextureCoordinate; vec4 ExplosionColor; float ExplosionPercentageElapsed; - vec4 PositionLightSpace[MAX_SPLITS]; }Input; out vec4 sceneColor; diff --git a/resources/Shaders/ForwardPlusSplatMapRGB.frag.glsl b/resources/Shaders/ForwardPlusSplatMapRGB.frag.glsl index f933a605..c67a9c99 100644 --- a/resources/Shaders/ForwardPlusSplatMapRGB.frag.glsl +++ b/resources/Shaders/ForwardPlusSplatMapRGB.frag.glsl @@ -1,7 +1,6 @@ #version 430 #define MIN_AMBIENT_LIGHT 0.3 -#define MAX_SPLITS 4 uniform mat4 M; uniform mat4 V; @@ -84,7 +83,6 @@ in VertexData{ vec2 TextureCoordinate; vec4 ExplosionColor; float ExplosionPercentageElapsed; - vec4 PositionLightSpace[MAX_SPLITS]; }Input; out vec4 sceneColor; diff --git a/resources/Shaders/Shadow.frag.glsl b/resources/Shaders/Shadow.frag.glsl deleted file mode 100644 index c7d153c3..00000000 --- a/resources/Shaders/Shadow.frag.glsl +++ /dev/null @@ -1,22 +0,0 @@ -#version 430 - -#define ALPHA_CUTOFF 0.3 - -layout (binding = 24) uniform sampler2D DiffuseTexture; -uniform float Alpha; - -in VertexData{ - vec2 TextureCoordinate; -}Input; - -layout (location = 0) out float ShadowMap; - -void main() -{ - vec4 diffuseTexel = texture(DiffuseTexture, Input.TextureCoordinate) * Alpha; - - if (diffuseTexel.a < ALPHA_CUTOFF) - { - discard; - } -} \ No newline at end of file diff --git a/resources/Shaders/Shadow.vert.glsl b/resources/Shaders/Shadow.vert.glsl deleted file mode 100644 index 7b1b26fb..00000000 --- a/resources/Shaders/Shadow.vert.glsl +++ /dev/null @@ -1,18 +0,0 @@ -#version 430 - -uniform mat4 M; -uniform mat4 V; -uniform mat4 P; - -layout (location = 0) in vec3 Position; -layout (location = 4) in vec2 TextureCoords; - -out VertexData{ - vec2 TextureCoordinate; -}Output; - -void main() -{ - gl_Position = P * V * M * vec4(Position, 1.0); - Output.TextureCoordinate = TextureCoords; -} \ No newline at end of file diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index 510c665e..6cdf42d1 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -1,10 +1,9 @@ #include "Rendering/DrawFinalPass.h" -DrawFinalPass::DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass, CubeMapPass* cubeMapPass, SSAOPass* ssaoPass, ShadowPass* shadowPass) +DrawFinalPass::DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass, CubeMapPass* cubeMapPass, SSAOPass* ssaoPass) : m_Renderer(renderer) , m_LightCullingPass(lightCullingPass) , m_CubeMapPass(cubeMapPass) , m_SSAOPass(ssaoPass) - , m_ShadowPass(shadowPass) { //TODO: Make sure that uniforms are not sent into shader if not needed. m_ShieldPixelRate = 8; @@ -344,14 +343,6 @@ void DrawFinalPass::DrawModelRenderQueues(std::list>& glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_SSAOPass->SSAOTexture()); - glActiveTexture(GL_TEXTURE13); - if (m_ShadowPass->DepthMap() != NULL) { - glBindTexture(GL_TEXTURE_2D_ARRAY, m_ShadowPass->DepthMap()); - } - else { - glBindTexture(GL_TEXTURE_2D_ARRAY, m_WhiteTexture->m_Texture); - } - for (auto &job : jobs) { auto explosionEffectJob = std::dynamic_pointer_cast(job); if (explosionEffectJob) { @@ -1092,10 +1083,6 @@ void DrawFinalPass::BindExplosionUniforms(GLuint shaderHandle, std::shared_ptrGlowIntensity); - - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "LightP"), MAX_SPLITS, GL_FALSE, glm::value_ptr(*m_ShadowPass->LightP().data())); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "LightV"), MAX_SPLITS, GL_FALSE, glm::value_ptr(*m_ShadowPass->LightV().data())); - glUniform1fv(glGetUniformLocation(shaderHandle, "FarDistance"), MAX_SPLITS, m_ShadowPass->FarDistance().data()); GLERROR("END"); } @@ -1134,11 +1121,8 @@ void DrawFinalPass::BindModelUniforms(GLuint shaderHandle, std::shared_ptrGlowIntensity); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "LightP"), MAX_SPLITS, GL_FALSE, glm::value_ptr(*m_ShadowPass->LightP().data())); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "LightV"), MAX_SPLITS, GL_FALSE, glm::value_ptr(*m_ShadowPass->LightV().data())); - glUniform1fv(glGetUniformLocation(shaderHandle, "FarDistance"), MAX_SPLITS, m_ShadowPass->FarDistance().data()); + glUniform1f(Location_GlowIntensity, job->GlowIntensity); GLERROR("END"); } diff --git a/src/Engine/Rendering/FrameBuffer.cpp b/src/Engine/Rendering/FrameBuffer.cpp index ee02db94..da438e7a 100644 --- a/src/Engine/Rendering/FrameBuffer.cpp +++ b/src/Engine/Rendering/FrameBuffer.cpp @@ -53,20 +53,16 @@ void FrameBuffer::Generate() case GL_TEXTURE_2D: glFramebufferTexture2D(GL_FRAMEBUFFER, (*it)->m_Attachment, (*it)->m_ResourceType, *(*it)->m_ResourceHandle, 0); GLERROR("FrameBuffer generate: glFramebufferTexture2D"); + break; case GL_RENDERBUFFER: glFramebufferRenderbuffer(GL_FRAMEBUFFER, (*it)->m_Attachment, (*it)->m_ResourceType, *(*it)->m_ResourceHandle); GLERROR("FrameBuffer generate: glFramebufferRenderbuffer"); break; - case GL_TEXTURE_2D_ARRAY: - glFramebufferTexture(GL_FRAMEBUFFER, (*it)->m_Attachment, *(*it)->m_ResourceHandle, 0); - GLERROR("FrameBuffer generate: glFramebufferTexture2DArray"); - break; } GLERROR("2"); - // Need GL_DEPTH_ATTACHMENT for shadows - if (/*(*it)->m_Attachment != GL_DEPTH_ATTACHMENT &&*/ (*it)->m_Attachment != GL_STENCIL_ATTACHMENT && (*it)->m_Attachment != GL_DEPTH_STENCIL_ATTACHMENT) { + if ((*it)->m_Attachment != GL_DEPTH_ATTACHMENT && (*it)->m_Attachment != GL_STENCIL_ATTACHMENT && (*it)->m_Attachment != GL_DEPTH_STENCIL_ATTACHMENT) { attachments.push_back((*it)->m_Attachment); } GLERROR("Attachment"); diff --git a/src/Engine/Rendering/Renderer.cpp b/src/Engine/Rendering/Renderer.cpp index b9a6aa05..3ce985b6 100644 --- a/src/Engine/Rendering/Renderer.cpp +++ b/src/Engine/Rendering/Renderer.cpp @@ -133,8 +133,6 @@ void Renderer::Draw(RenderFrame& frame) m_DrawFinalPass->ClearBuffer(); m_DrawBloomPass->ClearBuffer(); m_SSAOPass->ClearBuffer(); - m_ShadowPass->ClearBuffer(); - m_ShadowPass->DebugGUI(); PerformanceTimer::StopTimer("Renderer-ClearBuffers"); GLERROR("ClearBuffers"); for (auto scene : frame.RenderScenes) { @@ -150,9 +148,6 @@ void Renderer::Draw(RenderFrame& frame) PerformanceTimer::StartTimer("Renderer-Depth"); SortRenderJobsByDepth(*scene); GLERROR("SortByDepth"); - PerformanceTimer::StartTimerAndStopPrevious("Draw shadow maps"); - m_ShadowPass->Draw(*scene); - GLERROR("Draw shadow maps"); PerformanceTimer::StartTimerAndStopPrevious("Renderer-Generate Frustrums"); m_LightCullingPass->GenerateNewFrustum(*scene); GLERROR("Generate frustums"); @@ -249,8 +244,7 @@ void Renderer::InitializeRenderPasses() m_LightCullingPass = new LightCullingPass(this); m_CubeMapPass = new CubeMapPass(this); m_SSAOPass = new SSAOPass(this, m_Config); - m_ShadowPass = new ShadowPass(this); - m_DrawFinalPass = new DrawFinalPass(this, m_LightCullingPass, m_CubeMapPass, m_SSAOPass, m_ShadowPass); + m_DrawFinalPass = new DrawFinalPass(this, m_LightCullingPass, m_CubeMapPass, m_SSAOPass); m_DrawScreenQuadPass = new DrawScreenQuadPass(this); m_DrawBloomPass = new DrawBloomPass(this, m_Config); m_DrawColorCorrectionPass = new DrawColorCorrectionPass(this); diff --git a/src/Engine/Rendering/ShadowPass.cpp b/src/Engine/Rendering/ShadowPass.cpp deleted file mode 100644 index daf63ef2..00000000 --- a/src/Engine/Rendering/ShadowPass.cpp +++ /dev/null @@ -1,305 +0,0 @@ -#include "Rendering/ShadowPass.h" - -ShadowPass::ShadowPass(IRenderer * renderer, int shadow_res_x, int shadow_res_y) -{ - m_Renderer = renderer; - m_ResolutionSizeWidth = shadow_res_x; - m_ResolutionSizeHeight = shadow_res_y; - - InitializeFrameBuffers(); - InitializeShaderPrograms(); -} - -ShadowPass::ShadowPass(IRenderer * renderer) -{ - m_Renderer = renderer; - - InitializeFrameBuffers(); - InitializeShaderPrograms(); -} - -ShadowPass::~ShadowPass() -{ - -} - -void ShadowPass::DebugGUI() -{ - ImGui::Checkbox("EnableShadows", &m_EnableShadows); - ImGui::DragFloat2("ShadowMapNearFar", m_NearFarPlane, 1.f, -1000.f, 1000.f); - ImGui::DragFloat("ShadowClippingWeight", &m_SplitWeight, 0.001f, 0.f, 1.f); - ImGui::Checkbox("ShadowTransparentObjects", &m_TransparentObjects); - ImGui::Checkbox("ShadowOnTextureAlphas", &m_TexturedShadows); -} - -void ShadowPass::InitializeCameras(RenderScene & scene) -{ - for (int i = 0; i < m_CurrentNrOfSplits; i++) { - m_shadowFrusta[i].AspectRatio = scene.Camera->AspectRatio(); - m_shadowFrusta[i].FOV = scene.Camera->FOV(); - } -} - -// UpdateSplitDist computes the near and far distances for every frustum slice -// in camera eye space - that is, at what distance does a slice start and end -void ShadowPass::UpdateSplitDist(std::array& frusta, float near_distance, float far_distance) -{ - float lambda = m_SplitWeight; - float ratio = far_distance / near_distance; - - frusta[0].NearClip = near_distance; - - for (int i = 1; i < m_CurrentNrOfSplits; i++) { - float si = i / static_cast(m_CurrentNrOfSplits); - - frusta[i].NearClip = lambda * (near_distance * powf(ratio, si)) + (1 - lambda) * (near_distance + (far_distance - near_distance) * si); - frusta[i - 1].FarClip = frusta[i].NearClip * 1.005f; - } - - frusta[m_CurrentNrOfSplits - 1].FarClip = far_distance; -} - -void ShadowPass::UpdateFrustumPoints(ShadowFrustum& frustum, glm::mat4 p, glm::mat4 v) -{ - std::array CornerPoint = { - glm::vec4(-1.f, -1.f, -1.f, 1.f), - glm::vec4(-1.f, 1.f, -1.f, 1.f), - glm::vec4(1.f, 1.f, -1.f, 1.f), - glm::vec4(1.f, -1.f, -1.f, 1.f), - glm::vec4(-1.f, -1.f, 1.f, 1.f), - glm::vec4(-1.f, 1.f, 1.f, 1.f), - glm::vec4(1.f, 1.f, 1.f, 1.f), - glm::vec4(1.f, -1.f, 1.f, 1.f) - }; - - for (int i = 0; i < 8; i++) { - glm::vec4 NDC = glm::inverse(p) * CornerPoint[i]; - NDC = NDC / NDC.w; - frustum.CornerPoint[i] = glm::vec3(glm::inverse(v) * NDC); - } -} - -// Compute the 8 corner points of the current view frustum in world space -void ShadowPass::UpdateFrustumPoints(ShadowFrustum& frustum, glm::vec3 camera_position, glm::vec3 view_dir) -{ - glm::vec3 up = glm::vec3(0.f, 1.f, 0.f); - glm::vec3 right = glm::normalize(glm::cross(view_dir, up)); - - glm::vec3 far_center = camera_position + glm::normalize(view_dir) * frustum.FarClip; - glm::vec3 near_center = camera_position + glm::normalize(view_dir) * frustum.NearClip; - frustum.MiddlePoint = near_center + (far_center - near_center) * 0.5f; - - up = glm::normalize(glm::cross(right, view_dir)); - - // these heights and widths are half the heights and widths of the near and far plane rectangles. - float near_height = tan(frustum.FOV / 2.f) * frustum.NearClip; - float near_width = near_height * frustum.AspectRatio; - float far_height = tan(frustum.FOV / 2.f) * frustum.FarClip; - float far_width = far_height * frustum.AspectRatio; - - frustum.CornerPoint[0] = near_center - up * near_height - right * near_width; - frustum.CornerPoint[1] = near_center + up * near_height - right * near_width; - frustum.CornerPoint[2] = near_center + up * near_height + right * near_width; - frustum.CornerPoint[3] = near_center - up * near_height + right * near_width; - - frustum.CornerPoint[4] = far_center - up * far_height - right * far_width; - frustum.CornerPoint[5] = far_center + up * far_height - right * far_width; - frustum.CornerPoint[6] = far_center + up * far_height + right * far_width; - frustum.CornerPoint[7] = far_center - up * far_height + right * far_width; -} - -float ShadowPass::FindRadius(ShadowFrustum& frustum) -{ - float radius = 0.f; - - for (int i = 0; i < 8; i++) { - float distance = glm::distance(frustum.MiddlePoint, frustum.CornerPoint[i]); - if (distance > radius) { - radius = distance; - } - } - - frustum.Radius = radius; - return radius; -} - -void ShadowPass::InitializeFrameBuffers() -{ - // Depth texture - glGenTextures(1, &m_DepthMap); - - glBindTexture(GL_TEXTURE_2D_ARRAY, m_DepthMap); - glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_DEPTH_COMPONENT16, m_ResolutionSizeWidth, m_ResolutionSizeHeight, m_CurrentNrOfSplits); - - glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, m_ResolutionSizeWidth, m_ResolutionSizeHeight, m_CurrentNrOfSplits, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, nullptr); - - glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); - glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); - glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE); - glTexParameterfv(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BORDER_COLOR, glm::vec4(1.f).data); - glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); - - m_DepthBuffer.AddResource(std::shared_ptr(new Texture2D(&m_DepthMap, GL_DEPTH_ATTACHMENT))); - m_DepthBuffer.Generate(); - - GLERROR("depthMap failed END"); -} - -void ShadowPass::InitializeShaderPrograms() -{ - m_ShadowProgram = ResourceManager::Load("#ShadowProgram"); - m_ShadowProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/Shadow.vert.glsl"))); - m_ShadowProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/Shadow.frag.glsl"))); - m_ShadowProgram->Compile(); - m_ShadowProgram->BindFragDataLocation(0, "ShadowMap"); - m_ShadowProgram->Link(); - - -} - -void ShadowPass::ClearBuffer() -{ - m_DepthBuffer.Bind(); - - for (int i = 0; i < m_CurrentNrOfSplits; i++) { - glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_DepthMap, 0, i); - - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - } - - m_DepthBuffer.Unbind(); -} - -void ShadowPass::PointsToLightspace(ShadowFrustum& frustum, glm::mat4 v) -{ - float left = INFINITY; - float right = -INFINITY; - float bottom = INFINITY; - float top = -INFINITY; - - for (int i = 0; i < 8; i++) - { - glm::vec3 tempPoint = glm::vec3(v * glm::vec4(frustum.CornerPoint[i], 1.f)); - - if (tempPoint.x < left) { left = tempPoint.x; } - if (tempPoint.x > right) { right = tempPoint.x; } - if (tempPoint.y < bottom) { bottom = tempPoint.y; } - if (tempPoint.y > top) { top = tempPoint.y; } - } - - frustum.LRBT = { left, right, bottom, top }; -} - -void ShadowPass::RadiusToLightspace(ShadowFrustum& frustum) -{ - float quantizationStep = 1.0f / m_ResolutionSizeHeight; - - float left = -frustum.Radius; - float right = frustum.Radius; - float bottom = -frustum.Radius; - float top = frustum.Radius; - - frustum.LRBT = { left, right, bottom, top }; -} - -void ShadowPass::Draw(RenderScene & scene) -{ - if (m_EnableShadows) { - InitializeCameras(scene); - UpdateSplitDist(m_shadowFrusta, scene.Camera->NearClip(), scene.Camera->FarClip()); - - ShadowPassState* state = new ShadowPassState(m_DepthBuffer.GetHandle()); - - m_ShadowProgram->Bind(); - GLuint shaderHandle = m_ShadowProgram->GetHandle(); - glViewport(0, 0, m_ResolutionSizeWidth, m_ResolutionSizeHeight); - - for (int i = 0; i < m_CurrentNrOfSplits; i++) { - UpdateFrustumPoints(m_shadowFrusta[i], scene.Camera->Position(), scene.Camera->Forward()); - - glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_DepthMap, 0, i); - - for (auto &job : scene.Jobs.DirectionalLight) { - auto directionalLightJob = std::dynamic_pointer_cast(job); - - if (directionalLightJob) { - m_LightView[i] = glm::lookAt(glm::vec3(-directionalLightJob->Direction) + m_shadowFrusta[i].MiddlePoint, m_shadowFrusta[i].MiddlePoint, glm::vec3(0.f, 1.f, 0.f)); - - PointsToLightspace(m_shadowFrusta[i], m_LightView[i]); - //FindRadius(m_shadowFrusta[i]); - //RadiusToLightspace(m_shadowFrusta[i]); - m_LightProjection[i] = glm::ortho(m_shadowFrusta[i].LRBT[LEFT], m_shadowFrusta[i].LRBT[RIGHT], m_shadowFrusta[i].LRBT[BOTTOM], m_shadowFrusta[i].LRBT[TOP], m_NearFarPlane[NEAR], m_NearFarPlane[FAR]); - - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_LightProjection[i])); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_LightView[i])); - - GLERROR("ShadowLight ERROR"); - - for (auto &objectJob : scene.Jobs.OpaqueObjects) { - if (!std::dynamic_pointer_cast(objectJob)) { - auto modelJob = std::dynamic_pointer_cast(objectJob); - - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); - glUniform1f(glGetUniformLocation(shaderHandle, "Alpha"), 1.f); - - glBindVertexArray(modelJob->Model->VAO); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); - glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int))); - - GLERROR("Shadow Draw ERROR"); - } - } - if (m_TransparentObjects) { - state->CullFace(GL_BACK); - for (auto &objectJob : scene.Jobs.TransparentObjects) { - if (!std::dynamic_pointer_cast(objectJob)) { - auto modelJob = std::dynamic_pointer_cast(objectJob); - - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); - glUniform1f(glGetUniformLocation(shaderHandle, "Alpha"), modelJob->Color.a); - - if (m_TexturedShadows) { - switch (modelJob->Type) { - case RawModel::MaterialType::SingleTextures: - case RawModel::MaterialType::Basic: - { - glActiveTexture(GL_TEXTURE24); - if (modelJob->DiffuseTexture.size() > 0 && modelJob->DiffuseTexture[0]->Texture != nullptr) { - glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture[0]->Texture->m_Texture); - glUniform2fv(glGetUniformLocation(shaderHandle, "DiffuseUVRepeat"), 1, glm::value_ptr(modelJob->DiffuseTexture[0]->UVRepeat)); - } - else { - glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture); - glUniform2fv(glGetUniformLocation(shaderHandle, "DiffuseUVRepeat"), 1, glm::value_ptr(glm::vec2(1.0f, 1.0f))); - } - break; - } - case RawModel::MaterialType::SplatMapping: - { - glActiveTexture(GL_TEXTURE24); - glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture); - glUniform2fv(glGetUniformLocation(shaderHandle, "DiffuseUVRepeat"), 1, glm::value_ptr(glm::vec2(1.0f, 1.0f))); - break; - } - } - } - - glBindVertexArray(modelJob->Model->VAO); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); - glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int))); - - GLERROR("Shadow Draw ERROR"); - } - } - state->CullFace(GL_FRONT); - } - } - } - } - glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height); - m_DepthBuffer.Unbind(); - delete state; - } -} \ No newline at end of file diff --git a/src/Engine/Rendering/ShadowPassState.cpp b/src/Engine/Rendering/ShadowPassState.cpp deleted file mode 100644 index 2211e3ab..00000000 --- a/src/Engine/Rendering/ShadowPassState.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "Rendering/ShadowPassState.h" - -ShadowPassState::ShadowPassState(GLuint frameBuffer) -{ - BindFramebuffer(frameBuffer); - Enable(GL_DEPTH_TEST); - Enable(GL_CULL_FACE); - Disable(GL_BLEND); - Disable(GL_TEXTURE_2D); - CullFace(GL_FRONT); - ClearColor(glm::vec4(0.f, 0.f, 0.f, 0.f)); - //Enable(GL_ALPHA_TEST); - //glAlphaFunc(GL_GREATER, 0.9f); -} - -ShadowPassState::~ShadowPassState() -{ - -} \ No newline at end of file From a7bff928991f7e76b28764922c4271473b0f3913 Mon Sep 17 00:00:00 2001 From: stiffly Date: Thu, 3 Mar 2016 15:16:42 +0100 Subject: [PATCH 119/130] The readBuffer now checks if the whole packet has arrived before attempting to parse it. --- src/Engine/Network/Packet.cpp | 6 ++++-- src/Engine/Network/TCPClient.cpp | 5 ++++- src/Engine/Network/TCPServer.cpp | 5 ++++- src/Engine/Network/UDPClient.cpp | 5 ++++- src/Engine/Network/UDPServer.cpp | 5 +++++ 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/Engine/Network/Packet.cpp b/src/Engine/Network/Packet.cpp index 74afd656..6a4d0098 100644 --- a/src/Engine/Network/Packet.cpp +++ b/src/Engine/Network/Packet.cpp @@ -54,8 +54,10 @@ void Packet::WriteString(const std::string& str) } resizeData(); } - memcpy(m_Data + m_Offset, str.data(), sizeOfString * sizeof(char)); - m_Offset += sizeOfString * sizeof(char); + memcpy(m_Data + m_Offset, str.data(), str.size() * sizeof(char)); + m_Offset += str.size() * sizeof(char); + m_Data[m_Offset] = '\0'; + m_Offset += 1; } void Packet::WriteData(char * data, int sizeOfData) diff --git a/src/Engine/Network/TCPClient.cpp b/src/Engine/Network/TCPClient.cpp index f3394d3d..8bfa9ded 100644 --- a/src/Engine/Network/TCPClient.cpp +++ b/src/Engine/Network/TCPClient.cpp @@ -74,7 +74,10 @@ size_t TCPClient::readBuffer() boost::asio::ip::tcp::socket::message_peek, error); unsigned int sizeOfPacket = 0; memcpy(&sizeOfPacket, m_ReadBuffer, sizeof(int)); - + if (sizeOfPacket > m_Socket->available()) { + LOG_WARNING("TCPClient::readBuffer(): We haven't got the whole packet yet."); + return 0; + } // if the buffer is to small increase the size of it // TODO if message is huge 1 time the buffer will not decrease. if (sizeOfPacket > m_BufferSize) { diff --git a/src/Engine/Network/TCPServer.cpp b/src/Engine/Network/TCPServer.cpp index acd3d6d0..ff35aa91 100644 --- a/src/Engine/Network/TCPServer.cpp +++ b/src/Engine/Network/TCPServer.cpp @@ -106,7 +106,10 @@ int TCPServer::readBuffer(PlayerDefinition & playerDefinition) boost::asio::ip::tcp::socket::message_peek, error); unsigned int sizeOfPacket = 0; memcpy(&sizeOfPacket, m_ReadBuffer, sizeof(int)); - + if (sizeOfPacket > playerDefinition.TCPSocket->available()) { + LOG_WARNING("TCPServer::readBuffer(): We haven't got the whole packet yet."); + return 0; + } // if the buffer is to small increase the size of it if (sizeOfPacket > m_BufferSize) { delete[] m_ReadBuffer; diff --git a/src/Engine/Network/UDPClient.cpp b/src/Engine/Network/UDPClient.cpp index 51c29920..a7061884 100644 --- a/src/Engine/Network/UDPClient.cpp +++ b/src/Engine/Network/UDPClient.cpp @@ -45,7 +45,10 @@ int UDPClient::readBuffer() boost::asio::ip::udp::socket::message_peek, error); int sizeOfPacket = 0; memcpy(&sizeOfPacket, m_ReadBuffer, sizeof(int)); - + if (sizeOfPacket > m_Socket->available()) { + LOG_WARNING("UDPClient::readBuffer(): We haven't got the whole packet yet."); + return 0; + } // if the buffer is to small increase the size of it if (sizeOfPacket > m_BufferSize) { delete[] m_ReadBuffer; diff --git a/src/Engine/Network/UDPServer.cpp b/src/Engine/Network/UDPServer.cpp index 635ebd4d..13dd5ccd 100644 --- a/src/Engine/Network/UDPServer.cpp +++ b/src/Engine/Network/UDPServer.cpp @@ -92,6 +92,11 @@ int UDPServer::readBuffer() unsigned int sizeOfPacket = 0; memcpy(&sizeOfPacket, m_ReadBuffer, sizeof(int)); + if (sizeOfPacket > m_Socket->available()) { + LOG_WARNING("UDPServer::readBuffer(): We haven't got the whole packet yet."); + return 0; + } + // if the buffer is to small increase the size of it if (sizeOfPacket > m_BufferSize) { delete[] m_ReadBuffer; From 8859f652b92ffcd1a5bb8c85203036a9dd3a721f Mon Sep 17 00:00:00 2001 From: William Moberg Date: Thu, 3 Mar 2016 15:48:55 +0100 Subject: [PATCH 120/130] Input ClassPick now switches to a camera with class buttons, they do nothing now and have test textures. --- resources/DefaultInput.ini | 3 +- .../Schema/Entities/NewMapWSpectatorCam.xml | 3690 +++++++++-------- resources/Schema/Entities/OverwatchCamera.xml | 296 ++ resources/Schema/Entities/SpectatorCamera.xml | 219 - src/Game/Systems/PlayerSpawnSystem.cpp | 19 +- 5 files changed, 2196 insertions(+), 2031 deletions(-) create mode 100644 resources/Schema/Entities/OverwatchCamera.xml delete mode 100644 resources/Schema/Entities/SpectatorCamera.xml diff --git a/resources/DefaultInput.ini b/resources/DefaultInput.ini index 776cbecd..4dea88fd 100644 --- a/resources/DefaultInput.ini +++ b/resources/DefaultInput.ini @@ -27,4 +27,5 @@ M=SwitchToClient P=SwitchToPlayer K=TakeDamage,1500 F2=PerformanceTimingResetAllTimers -F3=PerformanceTimingCreateExcelData \ No newline at end of file +F3=PerformanceTimingCreateExcelData +F4=PickClass \ No newline at end of file diff --git a/resources/Schema/Entities/NewMapWSpectatorCam.xml b/resources/Schema/Entities/NewMapWSpectatorCam.xml index bf1b4c2b..79cdc2be 100644 --- a/resources/Schema/Entities/NewMapWSpectatorCam.xml +++ b/resources/Schema/Entities/NewMapWSpectatorCam.xml @@ -3,7 +3,6 @@ - 0.0 15 @@ -24,6 +23,16 @@ + + + + + Models/Props/Highground4.mesh + + + + + @@ -78,16 +87,6 @@ - - - - - Models/Props/Highground4.mesh - - - - - @@ -286,8 +285,8 @@ - + @@ -300,8 +299,8 @@ - + @@ -314,8 +313,8 @@ - + @@ -328,8 +327,8 @@ - + @@ -432,8 +431,8 @@ - + @@ -446,8 +445,8 @@ - + @@ -460,8 +459,8 @@ - + @@ -500,8 +499,8 @@ - + @@ -527,8 +526,8 @@ - + @@ -566,6 +565,19 @@ + + + + + Models/Props/Walls/SmallWall3.mesh + + + + + + + + @@ -691,8 +703,8 @@ - + @@ -705,8 +717,8 @@ - + @@ -779,19 +791,6 @@ - - - - - Models/Props/Walls/SmallWall3.mesh - - - - - - - - @@ -1042,8 +1041,8 @@ - + @@ -1512,8 +1511,8 @@ - + @@ -1744,8 +1743,8 @@ - + @@ -1822,8 +1821,8 @@ - + @@ -1836,8 +1835,8 @@ - + @@ -1857,8 +1856,8 @@ - + @@ -1871,8 +1870,8 @@ - + @@ -1898,8 +1897,8 @@ - + @@ -2017,8 +2016,8 @@ - + @@ -2137,8 +2136,8 @@ - + @@ -2177,8 +2176,8 @@ - + @@ -2217,8 +2216,8 @@ - + @@ -2238,8 +2237,8 @@ - + @@ -2252,8 +2251,8 @@ - + @@ -2407,8 +2406,8 @@ - + @@ -2436,8 +2435,8 @@ - + @@ -2451,8 +2450,8 @@ - + @@ -2465,8 +2464,8 @@ - + @@ -2478,8 +2477,8 @@ - + @@ -2494,8 +2493,8 @@ - + @@ -2508,8 +2507,8 @@ - + @@ -2616,8 +2615,8 @@ - + @@ -2877,8 +2876,8 @@ - + @@ -2891,8 +2890,8 @@ - + @@ -2917,8 +2916,8 @@ - + @@ -2933,8 +2932,8 @@ - + @@ -2947,8 +2946,8 @@ - + @@ -2975,8 +2974,8 @@ - + @@ -2989,8 +2988,8 @@ - + @@ -3016,8 +3015,8 @@ - + @@ -3031,8 +3030,8 @@ - + @@ -3046,8 +3045,8 @@ - + @@ -3061,8 +3060,8 @@ - + @@ -3083,1153 +3082,39 @@ - - - - - - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - - - - - - Models/Props/Stones/MediumStone2.mesh - - - - - - - - - - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - - - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - - - - - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - - - - - - Models/Props/Stones/MediumStone1.mesh - - - - - - - - - - - - - - Models/Props/Stones/SmallStone1.mesh - - - - - - - - - - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - - - - - Models/Props/Stones/MediumStone1.mesh - - - - - - - - - - - - - Models/Props/Stones/MediumStone1.mesh - - - - - - - - - - - - - - - Models/Props/Stones/MediumStone1.mesh - - - - - - - - - - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - - - - - - Models/Props/Stones/MediumStone2.mesh - - - - - - - - - - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - - - - - - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - - - - - - Models/Props/Stones/SmallStone1.mesh - - - - - - - - - - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - - - - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - - - - - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - - - - - Models/Props/Stones/SmallStone2.mesh - - - - - - - - - - - - - - Models/Props/Stones/MediumStone2.mesh - - - - - - - - - - - - - Models/Props/Stones/ShinyStoneCrystalRed.mesh - - - - - - - - - - - - - - Models/Props/Stones/ShinyStoneCrystalRed.mesh - - - - - - - - - - - - - - Models/Props/Stones/ShinyStoneCrystalRed.mesh - - - - - - - - - - - - - - Models/Props/Walls/MediumWall1.mesh - - - - - - - - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - - - - - - Models/Props/Stones/SmallStone1.mesh - - - - - - - - - - - - - - Models/Props/Stones/MediumStone2.mesh - - - - - - - - - - - - - Models/Props/Stones/MediumStone2.mesh - - - - - - - - - - - - - Models/Props/Stones/SmallStone2.mesh - - - - - - - - - - - - - Models/Props/Stones/MediumStone2.mesh - - - - - - - - - - - - Models/Props/Stones/MediumStone2.mesh - - - - - - - - - - - - - - Models/Props/Stones/SmallStone1.mesh - - - - - - - - - - - - - - Models/Props/Stones/MediumStone2.mesh - - - - - - - - - - - - - - Models/Props/Stones/SmallStone1.mesh - - - - - - - - - - - - - Models/Props/Stones/SmallStone2.mesh - - - - - - - - - - - - - - Models/Props/Stones/SmallStone1.mesh - - - - - - - - - - - - - - Models/Props/Stones/MediumStone1.mesh - - - - - - - - - - - - - - - - - - - Models/Props/Stones/SmallStone1.mesh - - - - - - - - - - - - - Models/Props/Stones/SmallStone2.mesh - - - - - - - - - - - - - - Models/Props/Stones/MediumStone2.mesh - - - - - - - - - - - - - Models/Props/Stones/SmallStone1.mesh - - - - - - - - - - - - - - - Models/Props/Stones/SmallStone1.mesh - - - - - - - - - - - - - - Models/Props/Stones/SmallStone1.mesh - - - - - - - - - - - - - - - - Models/Props/Stones/SmallStone2.mesh - - - - - - - - - - - - - - Models/Props/Stones/SmallStone1.mesh - - - - - - - - - - - - - Models/Props/Stones/SmallStone2.mesh - - - - - - - - - - - - - - Models/Props/Stones/MediumStone2.mesh - - - - - - - - - - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - - - - - - Models/Props/Stones/MediumStone2.mesh - - - - - - - - - - - - Models/Props/Stones/MediumStone2.mesh - - - - - - - - - - - - - Models/Props/Stones/SmallStone1.mesh - - - - - - - - - - - - - - - - Models/Props/Stones/SmallStone2.mesh - - - - - - - - - - - - - - Models/Props/Stones/MediumStone2.mesh - - - - - - - - - - - - - - Models/Props/Stones/MediumStone1.mesh - - - - - - - - - - - - - - Models/Props/Stones/MediumStone2.mesh - - - - - - - - - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - - - - - - Models/Props/Stones/SmallStone2.mesh - - - - - - - - - - - - - - Models/Props/Stones/MediumStone2.mesh - - - - - - - - - - - - - - - - - - - - - Models/Props/PickUps/PickUpHolder.mesh - - - - - - - - - - - - - - Models/Props/PickUps/PickUpHolder.mesh - - - - - - - - - - - - - - Models/Props/PickUps/PickUpHolder.mesh - - - - - - - - - - - - - - Models/Props/PickUps/PickUpHolder.mesh - - - - - - - - - - - - - - - - - - - - - - - - Models/Props/PickUps/PickUpHolder.mesh - - - - - - - - - - - - - - Models/Props/PickUps/PickUpHolder.mesh - - - - - - - - - - - - - Models/Props/PickUps/PickUpHolder.mesh - - - - - - - - - - - - - - Models/Props/PickUps/PickUpHolder.mesh - - - - - - - - - - - - - - Models/Props/PickUps/PickUpHolder.mesh - - - - - - - - - - - + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + + + + + + Models/Props/Stones/AssaultHolder.mesh + + + + + + + + + @@ -4347,22 +3232,8 @@ - - - - - - - - - - Models/Props/Stones/AssaultHolder.mesh - - - - @@ -4375,8 +3246,28 @@ - + + + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + @@ -4385,12 +3276,1120 @@ - Models/Props/Stones/AssaultHolder.mesh + Models/Props/Stones/MediumStone1.mesh - + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + - + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + @@ -4402,6 +4401,19 @@ + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + @@ -4480,19 +4492,6 @@ - - - - - Models/Props/SciFiHolder1.mesh - - - - - - - - @@ -4517,38 +4516,12 @@ - Models/Props/Stones/ShinyStoneCrystalRed.mesh + Models/Props/Stones/ShinyStoneCrystalBlue.mesh - - - - - - - - - - - Models/Props/Stones/ShinyStoneCrystalRed.mesh - - - + + - - - - - - - - - - Models/Props/Stones/ShinyStoneCrystalRed.mesh - - - - @@ -4561,133 +4534,8 @@ - - - - - - - - - - Models/Props/Stones/ShinyStoneCrystalBlue.mesh - - - - - - - - - - - - - Models/Props/Stones/ShinyStoneCrystalBlue.mesh - - - - - - - - - - - - - - Models/Props/Stones/ShinyStoneCrystalBlue.mesh - - - - - - - - - - - - - - Models/Props/Stones/ShinyStoneCrystalBlue.mesh - - - - - - - - - - - - - Models/Props/Stones/ShinyStoneCrystalRed.mesh - - - - - - - - - - - - - - Models/Props/Stones/ShinyStoneCrystalRed.mesh - - - - - - - - - - - - - - Models/Props/Stones/ShinyStoneCrystalBlue.mesh - - - - - - - - - - - - - - Models/Props/Stones/ShinyStoneCrystalBlue.mesh - - - - - - - - - - - - - - Models/Props/Stones/ShinyStoneCrystalRed.mesh - - - - - @@ -4712,9 +4560,36 @@ Models/Props/Stones/ShinyStoneCrystalBlue.mesh - + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + - @@ -4727,8 +4602,132 @@ - + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + @@ -4741,8 +4740,8 @@ - + @@ -4751,6 +4750,235 @@ + + + + + Schema/Entities/PlayerRed.xml + + + + + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + Models/Characters/Assault/AssaultTPose.mesh + false + + + + + + + + + + + + + + + + + + + + 0.10000000149011612 + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + + + + + + + + + + + + + 0.10000000149011612 + + + + Models/Props/PickUps/HealthPickUp.mesh + + + + + + + + + + + + + + + 0.10000000149011612 + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + + + + + + + + + + + + + 0.10000000149011612 + + + + Models/Props/PickUps/HealthPickUp.mesh + + + + + + + + + + + + + + + 0.10000000149011612 + + + + Models/Props/PickUps/HealthPickUp.mesh + + + + + + + + + + + + + + + 0.10000000149011612 + + + + Models/Props/PickUps/HealthPickUp.mesh + + + + + + + + + + + + + + + 0.10000000149011612 + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + + + + + + + + + + + + + 0.10000000149011612 + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + + + + + + + + + @@ -4775,6 +5003,7 @@ 4 + Models/Core/UnitCylinder.mesh @@ -4789,7 +5018,6 @@ - @@ -4811,6 +5039,7 @@ 3 + Models/Core/UnitCylinder.mesh @@ -4821,7 +5050,6 @@ - @@ -4843,6 +5071,7 @@ 2 + Models/Core/UnitCylinder.mesh @@ -4853,7 +5082,6 @@ - @@ -4876,6 +5104,7 @@ 1.5498908015879351 1 + Models/Core/UnitCylinder.mesh @@ -4886,7 +5115,6 @@ - @@ -4910,6 +5138,7 @@ + Models/Core/UnitCylinder.mesh @@ -4924,7 +5153,6 @@ - @@ -4937,6 +5165,17 @@ + + + + 10 + + + + + + + @@ -4991,17 +5230,6 @@ - - - - 10 - - - - - - - @@ -5015,76 +5243,6 @@ - - - - - Schema/Entities/PlayerRed.xml - - - - - - - - - - - - - - - - Models/Characters/Assault/AssaultTPose.mesh - false - - - - - - - - - - - - Models/Characters/Assault/AssaultTPose.mesh - false - - - - - - - - - - - - Models/Characters/Assault/AssaultTPose.mesh - false - - - - - - - - - - - - Models/Characters/Assault/AssaultTPose.mesh - false - - - - - - - - - @@ -5122,7 +5280,7 @@ false - + @@ -5135,7 +5293,7 @@ false - + @@ -5155,366 +5313,286 @@ - + - - - - - - - - 0.10000000149011612 - - - - Models/Props/PickUps/HealthPickUp.mesh - - - - - - - - - - - - - - - 0.10000000149011612 - - - - Models/Props/PickUps/AmmoPickUp.mesh - - - - - - - - - - - - - - - 0.10000000149011612 - - - - Models/Props/PickUps/HealthPickUp.mesh - - - - - - - - - - - - - - - 0.10000000149011612 - - - - Models/Props/PickUps/HealthPickUp.mesh - - - - - - - - - - - - - - - 0.10000000149011612 - - - - Models/Props/PickUps/AmmoPickUp.mesh - - - - - - - - - - - - - - - 0.10000000149011612 - - - - Models/Props/PickUps/HealthPickUp.mesh - - - - - - - - - - - - - - - 0.10000000149011612 - - - - Models/Props/PickUps/AmmoPickUp.mesh - - - - - - - - - - - - - - - 0.10000000149011612 - - - - Models/Props/PickUps/AmmoPickUp.mesh - - - - - - - - - - - - - - - + + 0.049999997019767761 + + - - + - + - + + - + - - - Fonts/DroidSans.ttf,64 - - - - - - - - - - - - - - - + + - + - - Textures/Core/UnitHexagon.png - - - - + - + - - 2 - - - - + - Textures/Core/UnitHexagon_Rotated.png + Textures/Core/UnitRaptor.png - - - + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + + + Textures/Test/aM4ME4GR.png + + + + + - + + + + + + + + + - - Textures/Core/UnitHexagon.png - - - - + - + - - 3 - - - - - - Textures/Core/UnitHexagon_Rotated.png - - - - - + + - + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + 2 + + + + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + 3 + + + + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + 4 + + + + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + 1 + + + 0.10332605343919568 + + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + + + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + - - - - - - Textures/Core/UnitHexagon.png - - - - - - - - - + - - 4 - - - - - - Textures/Core/UnitHexagon_Rotated.png - - + + 16 + Fonts/DroidSans.ttf,64 + + - - - - - - - - - - - - - Textures/Core/UnitHexagon.png - - - - - - - - - - - - 1 - - - 0.59265931447347009 - - - - Textures/Core/UnitHexagon_Rotated.png - - - - - - - - - - - - - - - - Textures/Core/UnitHexagon.png - - - - - - - - - - - - - - - - Textures/Core/UnitHexagon_Rotated.png - - - - - - + + diff --git a/resources/Schema/Entities/OverwatchCamera.xml b/resources/Schema/Entities/OverwatchCamera.xml new file mode 100644 index 00000000..323a62f2 --- /dev/null +++ b/resources/Schema/Entities/OverwatchCamera.xml @@ -0,0 +1,296 @@ + + + + + + 0.049999997019767761 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Textures/Core/UnitRaptor.png + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + + + Textures/Test/aM4ME4GR.png + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + 2 + + + + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + 3 + + + + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + 4 + + + + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + 1 + + + 0.10332605343919568 + + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + + + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + + + + + 5 + Fonts/DroidSans.ttf,64 + + + + + + + + + + + + + + + + + + diff --git a/resources/Schema/Entities/SpectatorCamera.xml b/resources/Schema/Entities/SpectatorCamera.xml deleted file mode 100644 index 5c3dc514..00000000 --- a/resources/Schema/Entities/SpectatorCamera.xml +++ /dev/null @@ -1,219 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - Time to respawn: 0 - Fonts/DroidSans.ttf,64 - - - - - - - - - - - - - - - - - - - - - - - - Textures/Core/UnitHexagon.png - - - - - - - - - - - - 2 - - - - - - Textures/Core/UnitHexagon_Rotated.png - - - - - - - - - - - - - - - - Textures/Core/UnitHexagon.png - - - - - - - - - - - - 3 - - - - - - Textures/Core/UnitHexagon_Rotated.png - - - - - - - - - - - - - - - - Textures/Core/UnitHexagon.png - - - - - - - - - - - - 4 - - - - - - Textures/Core/UnitHexagon_Rotated.png - - - - - - - - - - - - - - - - Textures/Core/UnitHexagon.png - - - - - - - - - - - - 1 - - - 0.59265931447347009 - - - - Textures/Core/UnitHexagon_Rotated.png - - - - - - - - - - - - - - - - Textures/Core/UnitHexagon.png - - - - - - - - - - - - - - - - Textures/Core/UnitHexagon_Rotated.png - - - - - - - - - - - - - - - - - - - diff --git a/src/Game/Systems/PlayerSpawnSystem.cpp b/src/Game/Systems/PlayerSpawnSystem.cpp index fbda849d..7a6881c4 100644 --- a/src/Game/Systems/PlayerSpawnSystem.cpp +++ b/src/Game/Systems/PlayerSpawnSystem.cpp @@ -105,7 +105,7 @@ void PlayerSpawnSystem::Update(double dt) bool PlayerSpawnSystem::OnInputCommand(Events::InputCommand& e) { - if (e.Command != "PickTeam") { + if (e.Command != "PickTeam" && e.Command != "PickClass") { return false; } @@ -113,11 +113,12 @@ bool PlayerSpawnSystem::OnInputCommand(Events::InputCommand& e) return false; } - // A dead client should be able to swap to the spectator camera. + // A dead client should be able to swap to the overwatch camera. if (IsClient && !LocalPlayer.Valid()) { - // Set the spectator camera as active, if it exists. - // Find the camera. - EntityWrapper spectatorCam = m_World->GetFirstEntityByName("SpectatorCamera"); + // Set the camera as active, if it exists. + // Find the respawn camera or class pick camera. + std::string camName = e.Command == "PickClass" ? "PickClassCamera" : "SpectatorCamera"; + EntityWrapper spectatorCam = m_World->GetFirstEntityByName(camName); if (spectatorCam.Valid() && spectatorCam.HasComponent("Camera")) { Events::SetCamera eSetCamera; eSetCamera.CameraEntity = spectatorCam; @@ -135,10 +136,18 @@ bool PlayerSpawnSystem::OnInputCommand(Events::InputCommand& e) auto iter = m_SpawnRequests.begin(); for (; iter != m_SpawnRequests.end(); ++iter) { if (iter->PlayerID == e.PlayerID) { + // If player wants to switch class, remove their spawn request. + if (e.Command == "PickClass") { + m_SpawnRequests.erase(iter); + } break; } } + if (e.Command == "PickClass") { + return true; + } + if (iter != m_SpawnRequests.end()) { // If player is in queue to spawn, then change their team affiliation in the request. iter->Team = (ComponentInfo::EnumType)e.Value; From 398bc725b670da2ee8b864332d0c643ca75603da Mon Sep 17 00:00:00 2001 From: William Moberg Date: Thu, 3 Mar 2016 16:32:24 +0100 Subject: [PATCH 121/130] When pick class buttons are clicked they send an InputCommand, not an ButtonClicked event. --- resources/Schema/Components.xsd | 1 + .../Schema/Components/InputCmdButton.xml | 5 + .../Schema/Components/InputCmdButton.xsd | 19 + .../Schema/Entities/NewMapWSpectatorCam.xml | 2300 +++++++++-------- resources/Schema/Entities/OverwatchCamera.xml | 132 +- resources/Schema/Types/Entity.xsd | 1 + src/Engine/GUI/ButtonSystem.cpp | 35 +- 7 files changed, 1281 insertions(+), 1212 deletions(-) create mode 100644 resources/Schema/Components/InputCmdButton.xml create mode 100644 resources/Schema/Components/InputCmdButton.xsd diff --git a/resources/Schema/Components.xsd b/resources/Schema/Components.xsd index 004a11a7..bb629094 100644 --- a/resources/Schema/Components.xsd +++ b/resources/Schema/Components.xsd @@ -59,4 +59,5 @@ + \ No newline at end of file diff --git a/resources/Schema/Components/InputCmdButton.xml b/resources/Schema/Components/InputCmdButton.xml new file mode 100644 index 00000000..58c3ba2c --- /dev/null +++ b/resources/Schema/Components/InputCmdButton.xml @@ -0,0 +1,5 @@ + + + + 0.0 + \ No newline at end of file diff --git a/resources/Schema/Components/InputCmdButton.xsd b/resources/Schema/Components/InputCmdButton.xsd new file mode 100644 index 00000000..f4dd8d3f --- /dev/null +++ b/resources/Schema/Components/InputCmdButton.xsd @@ -0,0 +1,19 @@ + + + + + + + Used with a Button component, the button will send an inputCommand event instead of ButtonPressed/Released event. + + + + The command name for the inputCommand. + + + The value in inputCommand.Value that will be sent on button press. + + + + + \ No newline at end of file diff --git a/resources/Schema/Entities/NewMapWSpectatorCam.xml b/resources/Schema/Entities/NewMapWSpectatorCam.xml index 79cdc2be..395eb1de 100644 --- a/resources/Schema/Entities/NewMapWSpectatorCam.xml +++ b/resources/Schema/Entities/NewMapWSpectatorCam.xml @@ -23,6 +23,16 @@ + + + + + Models/Props/Highground3.mesh + + + + + @@ -77,16 +87,6 @@ - - - - - Models/Props/Highground3.mesh - - - - - @@ -3082,6 +3082,148 @@ + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + + + + Models/Props/PickUps/PickUpHolder.mesh + + + + + + + + + + + @@ -3263,57 +3405,16 @@ - Models/Props/Stones/BigStone.mesh + Models/Props/Stones/SmallStone1.mesh - - - - - - - - - - - Models/Props/Stones/MediumStone1.mesh - - - - + + - - - - - Models/Props/Stones/MediumStone1.mesh - - - - - - - - - - - - - - Models/Props/Stones/SmallStone2.mesh - - - - - - - - - @@ -3342,6 +3443,47 @@ + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + @@ -3357,12 +3499,11 @@ - Models/Props/Stones/SmallStone1.mesh + Models/Props/Stones/BigStone.mesh - - - + + @@ -3384,11 +3525,12 @@ - Models/Props/Stones/BigStone.mesh + Models/Props/Stones/SmallStone1.mesh - - + + + @@ -3400,8 +3542,8 @@ Models/Props/Stones/BigStone.mesh - - + + @@ -3428,104 +3570,8 @@ Models/Props/Stones/BigStone.mesh - - - - - - - - - - - Models/Props/Stones/MediumStone2.mesh - - - - - - - - - - - - - Models/Props/Stones/ShinyStoneCrystalRed.mesh - - - - - - - - - - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - - - - - - Models/Props/Stones/SmallStone2.mesh - - - - - - - - - - - - - - Models/Props/Stones/MediumStone2.mesh - - - - - - - - - - - - - - Models/Props/Stones/MediumStone1.mesh - - - - - - - - - - - - - - Models/Props/Stones/MediumStone2.mesh - - - - - + + @@ -3544,6 +3590,34 @@ + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + @@ -3551,8 +3625,8 @@ Models/Props/Stones/BigStone.mesh - - + + @@ -3578,13 +3652,252 @@ Models/Props/Stones/SmallStone2.mesh - - + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone1.mesh + + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + + + Models/Props/Walls/MediumWall1.mesh + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + + Models/Props/Stones/SmallStone1.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + @@ -3603,11 +3916,12 @@ - Models/Props/Stones/BigStone.mesh + Models/Props/Stones/MediumStone1.mesh - - + + + @@ -3619,8 +3933,103 @@ Models/Props/Stones/SmallStone2.mesh - - + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/MediumStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + + + + + + Models/Props/Stones/SmallStone2.mesh + + + + + + + + + + + + + + Models/Props/Stones/BigStone.mesh + + + + @@ -3639,19 +4048,6 @@ - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - @@ -3666,19 +4062,6 @@ - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - @@ -3693,47 +4076,6 @@ - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - - - - @@ -3747,20 +4089,6 @@ - - - - - Models/Props/Stones/MediumStone1.mesh - - - - - - - - - @@ -3775,46 +4103,6 @@ - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - - - - - Models/Props/Stones/MediumStone1.mesh - - - - - - - - - - - - - Models/Props/Stones/MediumStone1.mesh - - - - - - - - - - @@ -3827,32 +4115,6 @@ - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - @@ -3880,6 +4142,19 @@ + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + @@ -3893,6 +4168,19 @@ + + + + + Models/Props/Stones/BigStone.mesh + + + + + + + + @@ -3909,19 +4197,6 @@ - - - - - Models/Props/Stones/BigStone.mesh - - - - - - - - @@ -3934,19 +4209,6 @@ - - - - - Models/Props/Stones/MediumStone2.mesh - - - - - - - - @@ -3961,18 +4223,6 @@ - - - - - Models/Props/Walls/MediumWall1.mesh - - - - - - - @@ -3987,19 +4237,6 @@ - - - - - Models/Props/Stones/MediumStone2.mesh - - - - - - - - @@ -4012,20 +4249,6 @@ - - - - - Models/Props/Stones/SmallStone1.mesh - - - - - - - - - @@ -4039,20 +4262,6 @@ - - - - - Models/Props/Stones/SmallStone1.mesh - - - - - - - - - @@ -4102,12 +4311,11 @@ - Models/Props/Stones/SmallStone2.mesh + Models/Props/Stones/SmallStone1.mesh - - - + + @@ -4116,11 +4324,12 @@ - Models/Props/Stones/SmallStone1.mesh + Models/Props/Stones/SmallStone2.mesh - - + + + @@ -4143,19 +4352,6 @@ - - - - - Models/Props/Stones/SmallStone1.mesh - - - - - - - - @@ -4170,47 +4366,6 @@ - - - - - Models/Props/Stones/MediumStone2.mesh - - - - - - - - - - - - Models/Props/Stones/MediumStone2.mesh - - - - - - - - - - - - - Models/Props/Stones/SmallStone1.mesh - - - - - - - - - - - @@ -4225,19 +4380,6 @@ - - - - - Models/Props/Stones/MediumStone2.mesh - - - - - - - - @@ -4254,153 +4396,24 @@ - - - - - - - - - - Models/Props/PickUps/PickUpHolder.mesh - - - - - - - - - - - - - - Models/Props/PickUps/PickUpHolder.mesh - - - - - - - - - - - - - Models/Props/PickUps/PickUpHolder.mesh - - - - - - - - - - - - - - Models/Props/PickUps/PickUpHolder.mesh - - - - - - - - - - - - - - Models/Props/PickUps/PickUpHolder.mesh - - - - - - - - - - - - - - Models/Props/PickUps/PickUpHolder.mesh - - - - - - - - - - - - - - - - - - - - - - - - Models/Props/PickUps/PickUpHolder.mesh - - - - - - - - - - - - - - Models/Props/PickUps/PickUpHolder.mesh - - - - - - - - - - - - - - Models/Props/PickUps/PickUpHolder.mesh - - - - - - - - - - - + + + + + Models/Props/SciFiHolder1.mesh + + + + + + + + @@ -4479,19 +4492,6 @@ - - - - - Models/Props/SciFiHolder1.mesh - - - - - - - - @@ -4512,74 +4512,6 @@ - - - - - Models/Props/Stones/ShinyStoneCrystalBlue.mesh - - - - - - - - - - - - - - Models/Props/Stones/ShinyStoneCrystalBlue.mesh - - - - - - - - - - - - - - Models/Props/Stones/ShinyStoneCrystalRed.mesh - - - - - - - - - - - - - Models/Props/Stones/ShinyStoneCrystalBlue.mesh - - - - - - - - - - - - - Models/Props/Stones/ShinyStoneCrystalRed.mesh - - - - - - - - - @@ -4601,91 +4533,8 @@ Models/Props/Stones/ShinyStoneCrystalBlue.mesh - - - - - - - - - - - - Models/Props/Stones/ShinyStoneCrystalRed.mesh - - - - - - - - - - - - - - Models/Props/Stones/ShinyStoneCrystalRed.mesh - - - - - - - - - - - - - Models/Props/Stones/ShinyStoneCrystalRed.mesh - - - - - - - - - - - - - Models/Props/Stones/ShinyStoneCrystalBlue.mesh - - - - - - - - - - - - - - Models/Props/Stones/ShinyStoneCrystalBlue.mesh - - - - - - - - - - - - - - Models/Props/Stones/ShinyStoneCrystalRed.mesh - - - - - + + @@ -4711,8 +4560,36 @@ Models/Props/Stones/ShinyStoneCrystalRed.mesh - - + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + @@ -4732,6 +4609,129 @@ + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalBlue.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + + + + + + Models/Props/Stones/ShinyStoneCrystalRed.mesh + + + + + + + + + @@ -4750,19 +4750,102 @@ - + + + + + + + + + 10 + + + + + + + + + + + 1 + + + + + + + + + 10 + + + + + + + + + + + 10 + + + + + + + + + + 10 + + + + + + + + + + + + + 10 + + + + + + + + + + + 1 + + + + + + + + + + - Schema/Entities/PlayerRed.xml + Schema/Entities/Player.xml - + - + @@ -4774,7 +4857,7 @@ false - + @@ -4787,7 +4870,7 @@ false - + @@ -4800,7 +4883,7 @@ false - + @@ -4813,166 +4896,7 @@ false - - - - - - - - - - - - - - - - - - 0.10000000149011612 - - - - Models/Props/PickUps/AmmoPickUp.mesh - - - - - - - - - - - - - - - 0.10000000149011612 - - - - Models/Props/PickUps/HealthPickUp.mesh - - - - - - - - - - - - - - - 0.10000000149011612 - - - - Models/Props/PickUps/AmmoPickUp.mesh - - - - - - - - - - - - - - - 0.10000000149011612 - - - - Models/Props/PickUps/HealthPickUp.mesh - - - - - - - - - - - - - - - 0.10000000149011612 - - - - Models/Props/PickUps/HealthPickUp.mesh - - - - - - - - - - - - - - - 0.10000000149011612 - - - - Models/Props/PickUps/HealthPickUp.mesh - - - - - - - - - - - - - - - 0.10000000149011612 - - - - Models/Props/PickUps/AmmoPickUp.mesh - - - - - - - - - - - - - - - 0.10000000149011612 - - - - Models/Props/PickUps/AmmoPickUp.mesh - - - - - + @@ -4988,10 +4912,42 @@ - Models/Props/CapturePoint/CapturePointBlue.mesh + Models/Props/CapturePoint/CapturePointNeutral.mesh - + + + + + + + + 2 + + + + Models/Core/UnitCylinder.mesh + + true + + + + + + + + + + + + + + + + Models/Props/CapturePoint/CapturePointRed.mesh + + + @@ -4999,24 +4955,23 @@ - + - 4 Models/Core/UnitCylinder.mesh - + true - + - - + + @@ -5055,38 +5010,6 @@ - - - - - Models/Props/CapturePoint/CapturePointNeutral.mesh - - - - - - - - - - 2 - - - - Models/Core/UnitCylinder.mesh - - true - - - - - - - - - - - @@ -5124,10 +5047,10 @@ - Models/Props/CapturePoint/CapturePointRed.mesh + Models/Props/CapturePoint/CapturePointBlue.mesh - + @@ -5135,23 +5058,24 @@ - + + 4 Models/Core/UnitCylinder.mesh - + true - + - - + + @@ -5160,102 +5084,19 @@ - - - - - - - - - 10 - - - - - - - - - - - 1 - - - - - - - - - 10 - - - - - - - - - - 10 - - - - - - - - - - - - - 10 - - - - - - - - - - - 10 - - - - - - - - - - - 1 - - - - - - - - - - + - Schema/Entities/Player.xml + Schema/Entities/PlayerRed.xml - + - + @@ -5267,7 +5108,7 @@ false - + @@ -5280,7 +5121,7 @@ false - + @@ -5293,7 +5134,7 @@ false - + @@ -5306,7 +5147,166 @@ false - + + + + + + + + + + + + + + + + + + 0.10000000149011612 + + + + Models/Props/PickUps/HealthPickUp.mesh + + + + + + + + + + + + + + + 0.10000000149011612 + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + + + + + + + + + + + + + 0.10000000149011612 + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + + + + + + + + + + + + + 0.10000000149011612 + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + + + + + + + + + + + + + 0.10000000149011612 + + + + Models/Props/PickUps/HealthPickUp.mesh + + + + + + + + + + + + + + + 0.10000000149011612 + + + + Models/Props/PickUps/HealthPickUp.mesh + + + + + + + + + + + + + + + 0.10000000149011612 + + + + Models/Props/PickUps/HealthPickUp.mesh + + + + + + + + + + + + + + + 0.10000000149011612 + + + + Models/Props/PickUps/AmmoPickUp.mesh + + + + + @@ -5332,65 +5332,6 @@ - - - - - - - - - - - - - - - - - - Textures/Core/UnitRaptor.png - - - - - - - - - - - - - - Textures/Core/UnitHexagon.png - - - - - - - - - - - - - - Textures/Test/aM4ME4GR.png - - - - - - - - - - - - - @@ -5601,6 +5542,77 @@ + + + + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + PickClass + 2 + + + + + + + + + + + + + Textures/Core/UnitRaptor.png + + + + PickClass + 1 + + + + + + + + + + + + + Textures/Test/aM4ME4GR.png + + + + PickClass + 3 + + + + + + + + + + + + diff --git a/resources/Schema/Entities/OverwatchCamera.xml b/resources/Schema/Entities/OverwatchCamera.xml index 323a62f2..a2b774d3 100644 --- a/resources/Schema/Entities/OverwatchCamera.xml +++ b/resources/Schema/Entities/OverwatchCamera.xml @@ -20,65 +20,6 @@ - - - - - - - - - - - - - - - - - - Textures/Core/UnitRaptor.png - - - - - - - - - - - - - - Textures/Core/UnitHexagon.png - - - - - - - - - - - - - - Textures/Test/aM4ME4GR.png - - - - - - - - - - - - - @@ -274,7 +215,7 @@ - 5 + 16 Fonts/DroidSans.ttf,64 @@ -289,6 +230,77 @@ + + + + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + PickClass + 2 + + + + + + + + + + + + + Textures/Core/UnitRaptor.png + + + + PickClass + 1 + + + + + + + + + + + + + Textures/Test/aM4ME4GR.png + + + + PickClass + 3 + + + + + + + + + + + + diff --git a/resources/Schema/Types/Entity.xsd b/resources/Schema/Types/Entity.xsd index 1d8ea8f3..21e517c0 100644 --- a/resources/Schema/Types/Entity.xsd +++ b/resources/Schema/Types/Entity.xsd @@ -62,6 +62,7 @@ + diff --git a/src/Engine/GUI/ButtonSystem.cpp b/src/Engine/GUI/ButtonSystem.cpp index 93ae1811..cc9f2b47 100644 --- a/src/Engine/GUI/ButtonSystem.cpp +++ b/src/Engine/GUI/ButtonSystem.cpp @@ -1,4 +1,5 @@ #include "GUI/ButtonSystem.h" +#include "Input/EInputCommand.h" ButtonSystem::ButtonSystem(SystemParams params, IRenderer* renderer) : System(params) @@ -37,10 +38,19 @@ bool ButtonSystem::OnMousePress(const Events::MousePress& e) m_PickEntity = EntityWrapper(m_World, m_PickData.Entity); //You have clicked on a button entity, send pressed event. - Events::ButtonPressed ePressed; - ePressed.Entity = m_PickEntity; - ePressed.EntityName = m_PickEntity.Name(); - m_EventBroker->Publish(ePressed); + if (m_World->HasComponent(m_PickData.Entity, "InputCmdButton")) { + Events::InputCommand eInputCmd; + eInputCmd.PlayerID = LocalPlayer.ID; + eInputCmd.Player = LocalPlayer; + EntityWrapper button = EntityWrapper(m_World, m_PickData.Entity); + eInputCmd.Command = (std::string)button["InputCmdButton"]["Command"]; + eInputCmd.Value = (float)button["InputCmdButton"]["PressValue"]; + } else { + Events::ButtonPressed ePressed; + ePressed.Entity = m_PickEntity; + ePressed.EntityName = m_PickEntity.Name(); + m_EventBroker->Publish(ePressed); + } } } } @@ -55,10 +65,19 @@ bool ButtonSystem::OnMouseRelease(const Events::MouseRelease& e) if(m_PickData.Entity != EntityID_Invalid && m_PickData.World == m_World) { EntityWrapper ent = EntityWrapper(m_World, m_PickData.Entity); - Events::ButtonReleased eReleased; - eReleased.EntityName = m_PickEntity.Name(); - eReleased.Entity = m_PickEntity; - m_EventBroker->Publish(eReleased); + if (m_World->HasComponent(m_PickData.Entity, "InputCmdButton")) { + Events::InputCommand eInputCmd; + eInputCmd.PlayerID = LocalPlayer.ID; + eInputCmd.Player = LocalPlayer; + EntityWrapper button = EntityWrapper(m_World, m_PickData.Entity); + eInputCmd.Command = (std::string)button["InputCmdButton"]["Command"]; + eInputCmd.Value = 0; + } else { + Events::ButtonReleased eReleased; + eReleased.EntityName = m_PickEntity.Name(); + eReleased.Entity = m_PickEntity; + m_EventBroker->Publish(eReleased); + } if(m_World->HasComponent(m_PickData.Entity, "Button")) { if (ent == m_PickEntity) { From 98366ec03827ed028206deb82382c6e33a941869 Mon Sep 17 00:00:00 2001 From: William Moberg Date: Thu, 3 Mar 2016 16:59:17 +0100 Subject: [PATCH 122/130] PickClass used for class-picking, SwapToClassPick to swap camera. --- resources/DefaultInput.ini | 2 +- src/Engine/GUI/ButtonSystem.cpp | 2 ++ src/Game/Systems/PlayerSpawnSystem.cpp | 8 ++++---- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/resources/DefaultInput.ini b/resources/DefaultInput.ini index 4dea88fd..b47c1e9b 100644 --- a/resources/DefaultInput.ini +++ b/resources/DefaultInput.ini @@ -28,4 +28,4 @@ P=SwitchToPlayer K=TakeDamage,1500 F2=PerformanceTimingResetAllTimers F3=PerformanceTimingCreateExcelData -F4=PickClass \ No newline at end of file +F4=SwapToClassPick \ No newline at end of file diff --git a/src/Engine/GUI/ButtonSystem.cpp b/src/Engine/GUI/ButtonSystem.cpp index cc9f2b47..b28c0119 100644 --- a/src/Engine/GUI/ButtonSystem.cpp +++ b/src/Engine/GUI/ButtonSystem.cpp @@ -45,6 +45,7 @@ bool ButtonSystem::OnMousePress(const Events::MousePress& e) EntityWrapper button = EntityWrapper(m_World, m_PickData.Entity); eInputCmd.Command = (std::string)button["InputCmdButton"]["Command"]; eInputCmd.Value = (float)button["InputCmdButton"]["PressValue"]; + m_EventBroker->Publish(eInputCmd); } else { Events::ButtonPressed ePressed; ePressed.Entity = m_PickEntity; @@ -72,6 +73,7 @@ bool ButtonSystem::OnMouseRelease(const Events::MouseRelease& e) EntityWrapper button = EntityWrapper(m_World, m_PickData.Entity); eInputCmd.Command = (std::string)button["InputCmdButton"]["Command"]; eInputCmd.Value = 0; + m_EventBroker->Publish(eInputCmd); } else { Events::ButtonReleased eReleased; eReleased.EntityName = m_PickEntity.Name(); diff --git a/src/Game/Systems/PlayerSpawnSystem.cpp b/src/Game/Systems/PlayerSpawnSystem.cpp index 7a6881c4..39fa1606 100644 --- a/src/Game/Systems/PlayerSpawnSystem.cpp +++ b/src/Game/Systems/PlayerSpawnSystem.cpp @@ -105,7 +105,7 @@ void PlayerSpawnSystem::Update(double dt) bool PlayerSpawnSystem::OnInputCommand(Events::InputCommand& e) { - if (e.Command != "PickTeam" && e.Command != "PickClass") { + if (e.Command != "PickTeam" && e.Command != "SwapToClassPick") { return false; } @@ -117,7 +117,7 @@ bool PlayerSpawnSystem::OnInputCommand(Events::InputCommand& e) if (IsClient && !LocalPlayer.Valid()) { // Set the camera as active, if it exists. // Find the respawn camera or class pick camera. - std::string camName = e.Command == "PickClass" ? "PickClassCamera" : "SpectatorCamera"; + std::string camName = e.Command == "SwapToClassPick" ? "PickClassCamera" : "SpectatorCamera"; EntityWrapper spectatorCam = m_World->GetFirstEntityByName(camName); if (spectatorCam.Valid() && spectatorCam.HasComponent("Camera")) { Events::SetCamera eSetCamera; @@ -137,14 +137,14 @@ bool PlayerSpawnSystem::OnInputCommand(Events::InputCommand& e) for (; iter != m_SpawnRequests.end(); ++iter) { if (iter->PlayerID == e.PlayerID) { // If player wants to switch class, remove their spawn request. - if (e.Command == "PickClass") { + if (e.Command == "SwapToClassPick") { m_SpawnRequests.erase(iter); } break; } } - if (e.Command == "PickClass") { + if (e.Command == "SwapToClassPick") { return true; } From c5f3bfc0cd7881437e6fba55a0512a03e18b8def Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Thu, 3 Mar 2016 17:33:41 +0100 Subject: [PATCH 123/130] Fixed the stuff in comments --- .../Engine/Input/FirstPersonInputController.h | 25 ++++++------------- src/Game/Systems/PlayerMovementSystem.cpp | 2 +- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/include/Engine/Input/FirstPersonInputController.h b/include/Engine/Input/FirstPersonInputController.h index 28795a7f..e5e6c0d5 100644 --- a/include/Engine/Input/FirstPersonInputController.h +++ b/include/Engine/Input/FirstPersonInputController.h @@ -28,9 +28,9 @@ public: virtual void Reset(); void AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer, double& assaultDashCoolDownTimer); - bool SniperSprintingCheck(); virtual bool AssaultDashDoubleTapped() const { return m_AssaultDashDoubleTapped; } virtual bool PlayerIsDashing() const { return m_PlayerIsDashing; } + bool SpecialAbilityKeyDown() const { return m_SpecialAbilityKeyDown; } protected: const int m_PlayerID; @@ -145,10 +145,10 @@ bool FirstPersonInputController::OnCommand(const Events::InputComm if (m_NumberOfMovementKeysDown == 0) { m_MovementKeyDown = false; } - //you have just released the key, store what key it was and reset the doubletap-sensitivity-timer - m_AssaultDashTapDirection = m_CurrentDirectionVector; - m_AssaultDashDoubleTapDeltaTime = 0.f; - + //you have just released the key, store what key it was and reset the doubletap-sensitivity-timer + m_AssaultDashTapDirection = m_CurrentDirectionVector; + m_AssaultDashDoubleTapDeltaTime = 0.f; + } } @@ -161,12 +161,9 @@ bool FirstPersonInputController::OnCommand(const Events::InputComm } if (e.Command == "SpecialAbility") { - if (e.Value > 0) { - m_SpecialAbilityKeyDown = true; - } else { - m_SpecialAbilityKeyDown = false; - } + m_SpecialAbilityKeyDown = e.Value > 0; } + if (m_SpecialAbilityKeyDown && m_MovementKeyDown) { m_ShiftDashing = true; } else { @@ -241,12 +238,4 @@ void FirstPersonInputController::AssaultDashCheck(double dt, bool m_EventBroker->Publish(e); } -template -bool FirstPersonInputController::SniperSprintingCheck() { - if (m_SpecialAbilityKeyDown) { - return true; - } else { - return false; - } -} #endif \ No newline at end of file diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index 8bcf092f..07090425 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -68,7 +68,7 @@ void PlayerMovementSystem::updateMovementControllers(double dt) } bool sniperSprinting = false; if (player.HasComponent("SprintAbility")) { - if (controller->SniperSprintingCheck()) { + if (controller->SpecialAbilityKeyDown()) { playerMovementSpeed *= (double)player["SprintAbility"]["StrengthOfEffect"]; playerCrouchSpeed *= (double)player["SprintAbility"]["StrengthOfEffect"]; sniperSprinting = true; From a3494b92c8cbf386bbd07ee9052ab1cde8b9ab07 Mon Sep 17 00:00:00 2001 From: viktorljung Date: Thu, 3 Mar 2016 17:48:25 +0100 Subject: [PATCH 124/130] Blending queues now working --- include/Engine/Rendering/AnimationSystem.h | 41 +- include/Engine/Rendering/AutoBlendQueue.h | 21 +- include/Engine/Rendering/BlendTree.h | 8 +- include/Engine/Rendering/EAnimationBlend.h | 21 - .../Engine/Rendering/EAutoAnimationBlend.h | 6 +- resources/Schema/Components/Animation.xml | 2 + resources/Schema/Components/Animation.xsd | 2 + resources/Schema/Entities/BlendTreeTest.xml | 37 +- src/Engine/Rendering/AnimationSystem.cpp | 504 ++++++++---------- src/Engine/Rendering/AutoBlendQueue.cpp | 195 +++++++ src/Engine/Rendering/BlendTree.cpp | 95 +++- 11 files changed, 554 insertions(+), 378 deletions(-) delete mode 100644 include/Engine/Rendering/EAnimationBlend.h diff --git a/include/Engine/Rendering/AnimationSystem.h b/include/Engine/Rendering/AnimationSystem.h index fd53022f..4f18b4a4 100644 --- a/include/Engine/Rendering/AnimationSystem.h +++ b/include/Engine/Rendering/AnimationSystem.h @@ -7,13 +7,12 @@ #include "../Core/System.h" #include "../Core/ResourceManager.h" #include "Rendering/Model.h" -#include "Rendering/EAnimationComplete.h" #include "Rendering/Skeleton.h" #include "Rendering/BlendTree.h" -#include "Rendering/EAnimationBlend.h" #include "Rendering/EAutoAnimationBlend.h" #include "../Input/EInputCommand.h" #include "../Core/EntityWrapper.h" +#include "Rendering/AutoBlendQueue.h" #include "imgui/imgui.h" @@ -27,10 +26,7 @@ private: void CreateBlendTrees(); void UpdateAnimations(double dt); void UpdateWeights(double dt); - void AnimationComplete(EntityWrapper animationEntity); - EventRelay m_EAnimationBlend; - bool OnAnimationBlend(Events::AnimationBlend& e); EventRelay m_EAutoAnimationBlend; bool OnAutoAnimationBlend(Events::AutoAnimationBlend& e); @@ -38,40 +34,7 @@ private: EventRelay m_EInputCommand; bool OnInputCommand(const Events::InputCommand& e); - struct BlendJob - { - EntityWrapper BlendEntity = EntityWrapper::Invalid; - double StartWeight; - double GoalWeight; - double Duration; - double CurrentTime = 0.0; - }; - - struct QueuedBlendJob : BlendJob - { - EntityWrapper AnimationEntity = EntityWrapper::Invalid; - }; - - struct AutoBlendJob - { - EntityWrapper RootNode = EntityWrapper::Invalid; - double Duration; - double CurrentTime = 0.0; - double Delay = 0.0; - BlendTree::AutoBlendInfo BlendInfo; - }; - - - std::list m_AutoBlendJobs; - std::unordered_map m_QueuedAutoBlendJobs; - std::list m_BlendJobs; - std::list m_QueuedBlendJobs; - - char m_AnimationName1[20] = "Run"; - float m_BlendTime1 = 0.5f; - - char m_AnimationName2[20] = "Jump"; - float m_BlendTime2 = 0.5f; + std::unordered_map m_AutoBlendQueues; }; #endif \ No newline at end of file diff --git a/include/Engine/Rendering/AutoBlendQueue.h b/include/Engine/Rendering/AutoBlendQueue.h index 12dd249e..3c808408 100644 --- a/include/Engine/Rendering/AutoBlendQueue.h +++ b/include/Engine/Rendering/AutoBlendQueue.h @@ -5,6 +5,7 @@ #include "Skeleton.h" #include "Model.h" #include "BlendTree.h" +#include "../Core/EntityWrapper.h" class AutoBlendQueue { @@ -15,11 +16,29 @@ public: double Duration; double CurrentTime = 0.0; double Delay = 0.0; + EntityWrapper AnimationEntity = EntityWrapper::Invalid; BlendTree::AutoBlendInfo BlendInfo; }; + struct AutoblendNode + { + AutoBlendJob BlendJob; + double StartTime; + double EndTime; + }; + + AutoBlendQueue() { }; + + void Insert(AutoBlendJob autoBlendJob); + void UpdateTime(double dt); + + void PrintQueue(); + bool HasActiveBlendJob(); + std::shared_ptr GetBlendTree(); + + AutoBlendQueue::AutoBlendJob& GetActiveBlendJob(); private: - std::map m_BlendQueue; + std::list m_BlendQueue; }; diff --git a/include/Engine/Rendering/BlendTree.h b/include/Engine/Rendering/BlendTree.h index 5605707a..2c5f1aa8 100644 --- a/include/Engine/Rendering/BlendTree.h +++ b/include/Engine/Rendering/BlendTree.h @@ -60,8 +60,7 @@ public: { std::string NodeName; double progress; - bool Restart; - double AnimationSpeed; + bool Start; std::unordered_map StartWeights; }; @@ -78,6 +77,11 @@ public: void PrintTree(); BlendTree::AutoBlendInfo AutoBlendStep(AutoBlendInfo blendInfo); + BlendTree::Node* GetCommonParent(std::string NodeName1, std::string NodeName2); + BlendTree::Node* FirstCommonParent(Node* node1, Node* node2); + + EntityWrapper GetSubTreeRoot(std::string nodeName); + private: Skeleton* m_Skeleton = nullptr; Node* m_Root = nullptr; diff --git a/include/Engine/Rendering/EAnimationBlend.h b/include/Engine/Rendering/EAnimationBlend.h deleted file mode 100644 index 880a2fd0..00000000 --- a/include/Engine/Rendering/EAnimationBlend.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef Events_AnimationBlend_h__ -#define Events_AnimationBlend_h__ - -#include "../Core/EventBroker.h" -#include "../Core/EntityWrapper.h" - -namespace Events -{ - -struct AnimationBlend : Event -{ - EntityWrapper BlendEntity = EntityWrapper::Invalid; - double GoalWeight; - double Duration; - - EntityWrapper AnimationEntity = EntityWrapper::Invalid; -}; - -} - -#endif diff --git a/include/Engine/Rendering/EAutoAnimationBlend.h b/include/Engine/Rendering/EAutoAnimationBlend.h index edd8e0bc..08c49191 100644 --- a/include/Engine/Rendering/EAutoAnimationBlend.h +++ b/include/Engine/Rendering/EAutoAnimationBlend.h @@ -13,9 +13,9 @@ struct AutoAnimationBlend : Event std::string NodeName; double Duration = 0.0; double Delay = 0.0; - - - double AnimationSpeed = 1.0; + + bool Start = false; + bool Reverse = false; bool Restart = false; EntityWrapper AnimationEntity = EntityWrapper::Invalid; diff --git a/resources/Schema/Components/Animation.xml b/resources/Schema/Components/Animation.xml index 45ee8428..05de9f9f 100644 --- a/resources/Schema/Components/Animation.xml +++ b/resources/Schema/Components/Animation.xml @@ -2,6 +2,8 @@ + false + false 0 true false diff --git a/resources/Schema/Components/Animation.xsd b/resources/Schema/Components/Animation.xsd index 5e82c333..1090c4c7 100644 --- a/resources/Schema/Components/Animation.xsd +++ b/resources/Schema/Components/Animation.xsd @@ -8,6 +8,8 @@ + + diff --git a/resources/Schema/Entities/BlendTreeTest.xml b/resources/Schema/Entities/BlendTreeTest.xml index 3457fc5e..69590ceb 100644 --- a/resources/Schema/Entities/BlendTreeTest.xml +++ b/resources/Schema/Entities/BlendTreeTest.xml @@ -68,9 +68,9 @@ Models/Weapons/Blue/AssaultWeaponBlue.mesh - + + - @@ -85,11 +85,11 @@ - + - AimRifleA - + AimSecWepA + false true @@ -97,11 +97,11 @@ - + - AimSecWepA - + AimRifleA + false true @@ -125,7 +125,7 @@ StandCrouchBlend JumpDashBlend - 0 + 0.00067602147306955462 @@ -183,8 +183,9 @@ RunF - + 1 + true @@ -317,7 +318,7 @@ Jump DashBlend - 1 + 0.01016461050458084 @@ -327,6 +328,8 @@ JumpF + 1 + false @@ -337,7 +340,7 @@ DashFBBlend DashLRBlend - 0 + 0.99999999999984523 @@ -347,7 +350,7 @@ DashForward DashBackward - 1 + 0.98238059685988577 @@ -356,6 +359,8 @@ DashForwardF + + 1 false @@ -367,6 +372,7 @@ DashBackwardF + 1 false @@ -380,7 +386,7 @@ DashLeft DashRight - 0 + 0.96547196574235861 @@ -390,6 +396,7 @@ DashLeftF + 1 false @@ -400,6 +407,8 @@ DashRightF + + 1 false diff --git a/src/Engine/Rendering/AnimationSystem.cpp b/src/Engine/Rendering/AnimationSystem.cpp index 4e7f15f6..166ecb47 100644 --- a/src/Engine/Rendering/AnimationSystem.cpp +++ b/src/Engine/Rendering/AnimationSystem.cpp @@ -3,21 +3,21 @@ AnimationSystem::AnimationSystem(SystemParams params) : System(params) { - EVENT_SUBSCRIBE_MEMBER(m_EAnimationBlend, &AnimationSystem::OnAnimationBlend); EVENT_SUBSCRIBE_MEMBER(m_EAutoAnimationBlend, &AnimationSystem::OnAutoAnimationBlend); EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &AnimationSystem::OnInputCommand); } void AnimationSystem::Update(double dt) { - ImGui::InputText("AnimationName1", &m_AnimationName1[0], sizeof(m_AnimationName1)); - ImGui::SliderFloat("Blendtime1", &m_BlendTime1, 0.f, 10.f); - ImGui::InputText("AnimationName2", &m_AnimationName2[0], sizeof(m_AnimationName2)); - ImGui::SliderFloat("Blendtime2", &m_BlendTime2, 0.f, 10.f); - UpdateAnimations(dt); CreateBlendTrees(); UpdateWeights(dt); + + + for(auto& autoBlendQueue : m_AutoBlendQueues) { + autoBlendQueue.second.UpdateTime(dt); + // autoBlendQueue.second.PrintQueue(); + } } void AnimationSystem::CreateBlendTrees() @@ -91,66 +91,29 @@ void AnimationSystem::UpdateAnimations(double dt) double animationSpeed = (double)animationC["Speed"]; - if (animationSpeed != 0.0) { + if((bool)animationC["Reverse"]) { + animationSpeed *= -1; + } + + + if ((bool)animationC["Play"]) { double nextTime = (double)animationC["Time"] + animationSpeed * dt; - - - //Pre animation end blend - if (m_QueuedAutoBlendJobs.find(entity) != m_QueuedAutoBlendJobs.end()) { - if (glm::sign(m_QueuedAutoBlendJobs.at(entity).Delay) < 0) { - if (!(bool)animationC["Loop"]) { - if (nextTime > animation->Duration + m_QueuedAutoBlendJobs.at(entity).Delay && glm::sign(animationSpeed) > 0) { - AnimationComplete(entity); - } else if (nextTime < 0 - m_QueuedAutoBlendJobs.at(entity).Delay && glm::sign(animationSpeed) < 0) { - AnimationComplete(entity); - } - } else { - if (nextTime > animation->Duration + m_QueuedAutoBlendJobs.at(entity).Delay && glm::sign(animationSpeed) > 0) { - AnimationComplete(entity); - } else if (nextTime < 0 - m_QueuedAutoBlendJobs.at(entity).Delay && glm::sign(animationSpeed) < 0) { - AnimationComplete(entity); - } - } - } - } - - if (!(bool)animationC["Loop"]) { if (nextTime > animation->Duration) { nextTime = animation->Duration; - Events::AnimationComplete e; - e.Entity = entity; - e.Name = (std::string)animationC["AnimationName"]; - m_EventBroker->Publish(e); - AnimationComplete(entity); - (double&)animationC["Speed"] = 0.0; + (bool&)animationC["Play"] = false; } else if (nextTime < 0) { - Events::AnimationComplete e; - e.Entity = entity; - e.Name = (std::string)animationC["AnimationName"]; - m_EventBroker->Publish(e); - AnimationComplete(entity); nextTime = 0; - (double&)animationC["Speed"] = 0.0; + (bool&)animationC["Play"] = false; } } else { if (nextTime > animation->Duration) { - Events::AnimationComplete e; - e.Entity = entity; - e.Name = (std::string)animationC["AnimationName"]; - m_EventBroker->Publish(e); - AnimationComplete(entity); while (nextTime > animation->Duration) { nextTime -= animation->Duration; } } else if (nextTime < 0) { - Events::AnimationComplete e; - e.Entity = entity; - e.Name = (std::string)animationC["AnimationName"]; - m_EventBroker->Publish(e); - AnimationComplete(entity); while (nextTime < 0) { nextTime += animation->Duration; } @@ -164,154 +127,27 @@ void AnimationSystem::UpdateAnimations(double dt) void AnimationSystem::UpdateWeights(double dt) { - for (auto it = m_BlendJobs.begin(); it != m_BlendJobs.end();) { - if (!it->BlendEntity.Valid()) { - it = m_BlendJobs.erase(it); - continue; - } + for (auto& autoBlendQueue : m_AutoBlendQueues) { - if (it->BlendEntity.HasComponent("Blend")) { - it->CurrentTime += dt; - double progress = it->CurrentTime / it->Duration; - progress = glm::clamp(progress, 0.0, 1.0); + if(autoBlendQueue.second.HasActiveBlendJob()) { + AutoBlendQueue::AutoBlendJob& blendJob = autoBlendQueue.second.GetActiveBlendJob(); - double weight = ((it->GoalWeight - it->StartWeight) * progress) + it->StartWeight; - (double&)it->BlendEntity["Blend"]["Weight"] = weight; + std::shared_ptr blendTree = autoBlendQueue.second.GetBlendTree(); - if(weight == it->GoalWeight) { - it = m_BlendJobs.erase(it); + if (blendTree != nullptr) { + blendJob.BlendInfo.progress = glm::clamp(blendJob.CurrentTime / blendJob.Duration, 0.0, 1.0); + LOG_INFO("Progress: %f, %s", blendJob.BlendInfo.progress, blendJob.BlendInfo.NodeName.c_str()); + blendJob.BlendInfo = blendTree->AutoBlendStep(blendJob.BlendInfo); } + } - ++it; - } - - - for (auto it = m_AutoBlendJobs.begin(); it != m_AutoBlendJobs.end();) { - it->CurrentTime += dt; - - if (!it->RootNode.Valid()) { - it = m_AutoBlendJobs.erase(it); - continue; - } - - if (!it->RootNode.HasComponent("Model")) { - it = m_AutoBlendJobs.erase(it); - continue; - } - - Model* model; - try { - model = ResourceManager::Load<::Model, true>(it->RootNode["Model"]["Resource"]); - } catch (const std::exception&) { - continue; - } - - Skeleton* skeleton = model->m_RawModel->m_Skeleton; - if (skeleton == nullptr) { - continue; - } - - std::shared_ptr blendTree; - if(skeleton->BlendTrees.find(it->RootNode) != skeleton->BlendTrees.end()) { - blendTree = skeleton->BlendTrees.at(it->RootNode); - } else { - it = m_AutoBlendJobs.erase(it); - continue; - } - - - it->BlendInfo.progress = glm::clamp(it->CurrentTime / it->Duration, 0.0, 1.0); - it->BlendInfo = blendTree->AutoBlendStep(it->BlendInfo); - - - if (it->CurrentTime >= it->Duration) { - it = m_AutoBlendJobs.erase(it); - continue; - } - - ++it; } } - -void AnimationSystem::AnimationComplete(EntityWrapper animationEntity) -{ - for (auto it = m_QueuedBlendJobs.begin(); it != m_QueuedBlendJobs.end();) { - if (!it->BlendEntity.Valid() || !it->AnimationEntity.Valid()) { - it = m_QueuedBlendJobs.erase(it); - continue; - } - - if(animationEntity == it->AnimationEntity) { - BlendJob bj; - bj.BlendEntity = it->BlendEntity; - bj.StartWeight = it->StartWeight; - bj.GoalWeight = it->GoalWeight; - bj.Duration = it->Duration; - bj.CurrentTime = 0.0; - m_BlendJobs.push_back(bj); - it = m_QueuedBlendJobs.erase(it); - continue; - } - - ++it; - } - - - if (m_QueuedAutoBlendJobs.find(animationEntity) != m_QueuedAutoBlendJobs.end()) { - AutoBlendJob abj = m_QueuedAutoBlendJobs.at(animationEntity); - - if (!abj.RootNode.Valid() || !animationEntity.Valid()) { - m_QueuedAutoBlendJobs.erase(animationEntity); - } else { - m_AutoBlendJobs.push_back(abj); - m_QueuedAutoBlendJobs.erase(animationEntity); - } - - - - } - - -} - -bool AnimationSystem::OnAnimationBlend(Events::AnimationBlend& e) -{ - if(!e.BlendEntity.Valid()) { - return false; - } - if(!e.BlendEntity.HasComponent("Blend")){ - return false; - } - - if (e.AnimationEntity.Valid()) { - if (e.AnimationEntity.HasComponent("Animation")) { - QueuedBlendJob qbj; - qbj.BlendEntity = e.BlendEntity; - qbj.StartWeight = (double)e.BlendEntity["Blend"]["Weight"]; - qbj.GoalWeight = e.GoalWeight; - qbj.Duration = e.Duration; - qbj.CurrentTime = 0.0; - qbj.AnimationEntity = e.AnimationEntity; - m_QueuedBlendJobs.push_back(qbj); - return true; - } - } else { - BlendJob bj; - bj.BlendEntity = e.BlendEntity; - bj.StartWeight = (double)e.BlendEntity["Blend"]["Weight"]; - bj.GoalWeight = e.GoalWeight; - bj.Duration = e.Duration; - bj.CurrentTime = 0.0; - m_BlendJobs.push_back(bj); - return true; - } -} - - bool AnimationSystem::OnAutoAnimationBlend(Events::AutoAnimationBlend& e) { + if(!e.RootNode.Valid()) { return false; } @@ -320,108 +156,80 @@ bool AnimationSystem::OnAutoAnimationBlend(Events::AutoAnimationBlend& e) return false; } - if (e.AnimationEntity.Valid()) { - AutoBlendJob abj; - abj.RootNode = e.RootNode; - abj.CurrentTime = 0.0; - abj.Duration = e.Duration; - abj.Delay = e.Delay; + Model* model; + try { + model = ResourceManager::Load<::Model, true>((std::string)e.RootNode["Model"]["Resource"]); + } catch (const std::exception&) { + return false; + } - BlendTree::AutoBlendInfo abInfo; - abInfo.NodeName = e.NodeName; - abInfo.progress = 0.0; - abInfo.Restart = e.Restart; - abInfo.AnimationSpeed = e.AnimationSpeed; - abj.BlendInfo = abInfo; + Skeleton* skeleton = model->m_RawModel->m_Skeleton; + if (skeleton == nullptr) { + return false; + } - m_QueuedAutoBlendJobs[e.AnimationEntity] = abj; - return true; + std::shared_ptr blendTree; + if (skeleton->BlendTrees.find(e.RootNode) != skeleton->BlendTrees.end()) { + blendTree = skeleton->BlendTrees.at(e.RootNode); } else { - AutoBlendJob abj; - abj.RootNode = e.RootNode; - abj.CurrentTime = 0.0; - abj.Duration = e.Duration; - - BlendTree::AutoBlendInfo abInfo; - abInfo.NodeName = e.NodeName; - abInfo.progress = 0.0; - abInfo.Restart = e.Restart; - abInfo.AnimationSpeed = e.AnimationSpeed; - - abj.BlendInfo = abInfo; - - m_AutoBlendJobs.push_back(abj); - return true; + return false; } + + EntityWrapper subTreeRoot = blendTree->GetSubTreeRoot(e.NodeName); + + if(!subTreeRoot.Valid()) { + return false; + } + + AutoBlendQueue::AutoBlendJob abj; + abj.AnimationEntity = e.AnimationEntity; + abj.CurrentTime = 0.0; + abj.Delay = e.Delay; + abj.Duration = e.Duration; + abj.RootNode = e.RootNode; + + abj.BlendInfo.NodeName = e.NodeName; + abj.BlendInfo.progress = 0.0; + abj.BlendInfo.Start = e.Start; + + if (e.Restart) { + EntityWrapper nodeEntity = subTreeRoot.FirstChildByName(e.NodeName); + if (nodeEntity.Valid()) { + if (nodeEntity.HasComponent("Animation")) { + const Skeleton::Animation* animation = skeleton->GetAnimation(nodeEntity["Animation"]["AnimationName"]); + + if (animation != nullptr) { + if (e.Restart) { + (bool&)nodeEntity["Animation"]["Reverse"] = e.Reverse; + if (e.Reverse) { + (double&)nodeEntity["Animation"]["Time"] = animation->Duration; + } else { + (double&)nodeEntity["Animation"]["Time"] = 0.0; + } + } + } + } + } + } + + + LOG_INFO("Inserting %s blendJob into %s subtree", e.NodeName.c_str(), subTreeRoot.Name().c_str()); + m_AutoBlendQueues[subTreeRoot].Insert(abj); + + LOG_INFO("\n"); + m_AutoBlendQueues.at(subTreeRoot).PrintQueue(); + LOG_INFO("\n"); + + + return true; } bool AnimationSystem::OnInputCommand(const Events::InputCommand& e) { if (e.Value == 1.f) { - if (e.Command == "BlendTest0") { - auto blendComponents = m_World->GetComponents("BlendAdditive"); - - if (blendComponents == nullptr) { - return false; - } - - - for (auto& bc : *blendComponents) { - EntityWrapper entity = EntityWrapper(m_World, bc.EntityID); - - if (entity.Name() == "Assault") { - Events::AutoAnimationBlend aeb; - aeb.Duration = m_BlendTime1; - aeb.NodeName = m_AnimationName1; - aeb.RootNode = entity; - aeb.Restart = true; - - m_EventBroker->Publish(aeb); - - } - } - - } else if (e.Command == "BlendTest1") { - - auto blendComponents = m_World->GetComponents("BlendAdditive"); - - if (blendComponents == nullptr) { - return false; - } - - - for (auto& bc : *blendComponents) { - EntityWrapper entity = EntityWrapper(m_World, bc.EntityID); - - if (entity.Name() == "Assault") { - - { - Events::AutoAnimationBlend aeb; - aeb.Duration = m_BlendTime2; - aeb.NodeName = m_AnimationName2; - aeb.RootNode = entity; - aeb.Restart = true; - m_EventBroker->Publish(aeb); - } - - { - Events::AutoAnimationBlend aeb; - aeb.Duration = m_BlendTime2; - aeb.NodeName = "Run"; - aeb.RootNode = entity; - aeb.Restart = true; - aeb.AnimationEntity = entity.FirstChildByName("DashLeft"); - m_EventBroker->Publish(aeb); - } - - } - } - } - - if(e.Command == "DashForward") { auto blendComponents = m_World->GetComponents("BlendAdditive"); @@ -434,19 +242,21 @@ bool AnimationSystem::OnInputCommand(const Events::InputCommand& e) if (entity.Name() == "Assault") { { Events::AutoAnimationBlend aeb; - aeb.Duration = 0.1; + aeb.Duration = 0.2; aeb.NodeName = "DashForward"; aeb.RootNode = entity; aeb.Restart = true; + aeb.Start = true; m_EventBroker->Publish(aeb); } { Events::AutoAnimationBlend aeb; aeb.Duration = 0.3; - aeb.NodeName = "Run"; + aeb.NodeName = "StandCrouchBlend"; aeb.RootNode = entity; - aeb.Restart = true; - aeb.Delay = 0; + aeb.Delay = -0.3; + aeb.Start = true; + aeb.Restart = false; aeb.AnimationEntity = entity.FirstChildByName("DashForward"); m_EventBroker->Publish(aeb); } @@ -469,14 +279,16 @@ bool AnimationSystem::OnInputCommand(const Events::InputCommand& e) aeb.NodeName = "DashBackward"; aeb.RootNode = entity; aeb.Restart = true; + aeb.Start = true; m_EventBroker->Publish(aeb); } { Events::AutoAnimationBlend aeb; aeb.Duration = 0.3; - aeb.NodeName = "Run"; + aeb.NodeName = "StandCrouchBlend"; aeb.RootNode = entity; - aeb.Restart = true; + aeb.Start = true; + aeb.Restart = false; aeb.Delay = -0.3; aeb.AnimationEntity = entity.FirstChildByName("DashBackward"); m_EventBroker->Publish(aeb); @@ -499,15 +311,17 @@ bool AnimationSystem::OnInputCommand(const Events::InputCommand& e) aeb.NodeName = "DashLeft"; aeb.RootNode = entity; aeb.Restart = true; + aeb.Start = true; m_EventBroker->Publish(aeb); } { Events::AutoAnimationBlend aeb; aeb.Duration = 0.3; - aeb.NodeName = "Run"; + aeb.NodeName = "StandCrouchBlend"; aeb.RootNode = entity; - aeb.Restart = true; aeb.Delay = -0.3; + aeb.Start = true; + aeb.Restart = false; aeb.AnimationEntity = entity.FirstChildByName("DashLeft"); m_EventBroker->Publish(aeb); } @@ -529,14 +343,16 @@ bool AnimationSystem::OnInputCommand(const Events::InputCommand& e) aeb.NodeName = "DashRight"; aeb.RootNode = entity; aeb.Restart = true; + aeb.Start = true; m_EventBroker->Publish(aeb); } { Events::AutoAnimationBlend aeb; aeb.Duration = 0.3; - aeb.NodeName = "Run"; + aeb.NodeName = "StandCrouchBlend"; aeb.RootNode = entity; - aeb.Restart = true; + aeb.Start = true; + aeb.Restart = false; aeb.AnimationEntity = entity.FirstChildByName("DashRight"); aeb.Delay = -0.3; m_EventBroker->Publish(aeb); @@ -558,20 +374,128 @@ bool AnimationSystem::OnInputCommand(const Events::InputCommand& e) aeb.Duration = 0.35; aeb.NodeName = "Jump"; aeb.RootNode = entity; + aeb.Start = true; aeb.Restart = true; m_EventBroker->Publish(aeb); } { Events::AutoAnimationBlend aeb; - aeb.Duration = 0.35; - aeb.NodeName = "Run"; + aeb.Duration = 0.6; + aeb.NodeName = "StandCrouchBlend"; aeb.RootNode = entity; + aeb.Start = true; aeb.Restart = false; aeb.AnimationEntity = entity.FirstChildByName("Jump"); m_EventBroker->Publish(aeb); } } } + } else if (e.Command == "Reload") { + auto blendComponents = m_World->GetComponents("BlendAdditive"); + + if (blendComponents == nullptr) { + return false; + } + for (auto& bc : *blendComponents) { + EntityWrapper entity = EntityWrapper(m_World, bc.EntityID); + + if (entity.Name() == "Assault") { + { + Events::AutoAnimationBlend aeb; + aeb.Duration = 0.2; + aeb.NodeName = "ReloadSwitch"; + aeb.RootNode = entity; + aeb.Start = true; + aeb.Restart = true; + m_EventBroker->Publish(aeb); + } + { + Events::AutoAnimationBlend aeb; + aeb.Duration = 0.2; + aeb.NodeName = "IdlePrimary"; + aeb.RootNode = entity; + aeb.Delay = -0.1; + aeb.Start = true; + aeb.Restart = false; + aeb.AnimationEntity = entity.FirstChildByName("ReloadSwitch"); + m_EventBroker->Publish(aeb); + } + } + } + } else if (e.Command == "Crouch") { + auto blendComponents = m_World->GetComponents("BlendAdditive"); + + if (blendComponents == nullptr) { + return false; + } + for (auto& bc : *blendComponents) { + EntityWrapper entity = EntityWrapper(m_World, bc.EntityID); + + if (entity.Name() == "Assault") { + { + Events::AutoAnimationBlend aeb; + aeb.Duration = 0.3; + aeb.NodeName = "CrouchMovement"; + aeb.RootNode = entity; + aeb.Start = true; + aeb.Restart = true; + m_EventBroker->Publish(aeb); + } + } + } + } else if (e.Command == "Stand") { + auto blendComponents = m_World->GetComponents("BlendAdditive"); + + if (blendComponents == nullptr) { + return false; + } + for (auto& bc : *blendComponents) { + EntityWrapper entity = EntityWrapper(m_World, bc.EntityID); + + if (entity.Name() == "Assault") { + { + Events::AutoAnimationBlend aeb; + aeb.Duration = 0.3; + aeb.NodeName = "StandMovement"; + aeb.RootNode = entity; + aeb.Start = true; + aeb.Restart = true; + m_EventBroker->Publish(aeb); + } + } + } + } else if (e.Command == "Shoot") { + auto blendComponents = m_World->GetComponents("BlendAdditive"); + + if (blendComponents == nullptr) { + return false; + } + for (auto& bc : *blendComponents) { + EntityWrapper entity = EntityWrapper(m_World, bc.EntityID); + + if (entity.Name() == "Assault") { + { + Events::AutoAnimationBlend aeb; + aeb.Duration = 0.1; + aeb.NodeName = "ShootPrimary"; + aeb.RootNode = entity; + aeb.Start = true; + aeb.Restart = true; + m_EventBroker->Publish(aeb); + } + { + Events::AutoAnimationBlend aeb; + aeb.Duration = 0.1; + aeb.NodeName = "IdlePrimary"; + aeb.RootNode = entity; + aeb.Delay = 0.0; + aeb.Start = true; + aeb.Restart = false; + aeb.AnimationEntity = entity.FirstChildByName("ShootPrimary"); + m_EventBroker->Publish(aeb); + } + } + } } diff --git a/src/Engine/Rendering/AutoBlendQueue.cpp b/src/Engine/Rendering/AutoBlendQueue.cpp index e69de29b..9f0a7366 100644 --- a/src/Engine/Rendering/AutoBlendQueue.cpp +++ b/src/Engine/Rendering/AutoBlendQueue.cpp @@ -0,0 +1,195 @@ +#include "Rendering/AutoBlendQueue.h" + +void AutoBlendQueue::Insert(AutoBlendJob autoBlendJob) +{ + if(!autoBlendJob.RootNode.HasComponent("Model")) { + return; + } + + AutoblendNode blendNode; + blendNode.BlendJob = autoBlendJob; + blendNode.StartTime = autoBlendJob.Delay; + blendNode.EndTime = autoBlendJob.Delay + autoBlendJob.Duration; + + + + if (autoBlendJob.AnimationEntity.Valid()) { + if (autoBlendJob.AnimationEntity.HasComponent("Animation")) { + Model* model; + try { + model = ResourceManager::Load<::Model, true>((std::string)autoBlendJob.RootNode["Model"]["Resource"]); + } catch (const std::exception&) { + return; + } + + Skeleton* skeleton = model->m_RawModel->m_Skeleton; + if (skeleton == nullptr) { + return; + } + + const Skeleton::Animation* animation = skeleton->GetAnimation((std::string)autoBlendJob.AnimationEntity["Animation"]["AnimationName"]); + + if (animation == nullptr) { + return; + } + + double AnimationDuration = 0.0; + + double animationSpeed = (double)autoBlendJob.AnimationEntity["Animation"]["Speed"]; + double animationTime = (double)autoBlendJob.AnimationEntity["Animation"]["Time"]; + + + if ((bool)autoBlendJob.AnimationEntity["Animation"]["Reverse"]) { + AnimationDuration = (animation->Duration * animationSpeed) - (animation->Duration - animationTime); + } else { + AnimationDuration = (animation->Duration * animationSpeed) - animationTime; + } + + LOG_INFO("Animation Duration %f", AnimationDuration); + blendNode.StartTime += AnimationDuration; + blendNode.EndTime += AnimationDuration; + if (m_BlendQueue.size() == 0) { + m_BlendQueue.push_back(blendNode); + } else { + for (auto it = m_BlendQueue.begin(); it != m_BlendQueue.end(); it++) { + auto next = std::next(it, 1); + + if (next != m_BlendQueue.end()) { + if (it->StartTime >= blendNode.StartTime && next->StartTime <= blendNode.StartTime) { + LOG_INFO("Inserted %s between %s and %s", blendNode.BlendJob.BlendInfo.NodeName.c_str(), it->BlendJob.BlendInfo.NodeName.c_str(), next->BlendJob.BlendInfo.NodeName.c_str()); + m_BlendQueue.insert(next, blendNode); + return; + } + } else if(it->StartTime > blendNode.StartTime){ + LOG_INFO("Inserted %s after %s", blendNode.BlendJob.BlendInfo.NodeName.c_str(), it->BlendJob.BlendInfo.NodeName.c_str()); + m_BlendQueue.push_front(blendNode); + return; + } else if (it->StartTime <= blendNode.StartTime) { + LOG_INFO("Inserted %s after %s", blendNode.BlendJob.BlendInfo.NodeName.c_str(), it->BlendJob.BlendInfo.NodeName.c_str()); + m_BlendQueue.push_back(blendNode); + return; + } + } + } + } + } + + + LOG_INFO("Cleared BlendQueue and inserted %s", blendNode.BlendJob.BlendInfo.NodeName.c_str()); + m_BlendQueue.clear(); + m_BlendQueue.push_back(blendNode); +} + +void AutoBlendQueue::UpdateTime(double dt) +{ + for (auto it = m_BlendQueue.begin(); it != m_BlendQueue.end();) { + it->EndTime -= dt; + it->StartTime -= dt; + if (it->EndTime < 0) { + it = m_BlendQueue.erase(it); + } else { + it++; + } + } +} + +void AutoBlendQueue::PrintQueue() +{ + for (auto it = m_BlendQueue.begin(); it != m_BlendQueue.end(); it++) { + LOG_INFO("Start: %f End: %f \t %s", it->StartTime, it->EndTime, it->BlendJob.BlendInfo.NodeName.c_str()); + } +} + + +bool AutoBlendQueue::HasActiveBlendJob() +{ + if(m_BlendQueue.empty()) { + return false; + } else { + AutoblendNode blendNode = m_BlendQueue.front(); + if (blendNode.StartTime <= 0) { + AutoBlendJob blendJob = blendNode.BlendJob; + + if (!blendJob.RootNode.Valid()) { + m_BlendQueue.pop_front(); + return false; + } + + if (!blendJob.RootNode.HasComponent("Model")) { + m_BlendQueue.pop_front(); + return HasActiveBlendJob(); + } + + Model* model; + try { + model = ResourceManager::Load<::Model, true>(blendJob.RootNode["Model"]["Resource"]); + } catch (const std::exception&) { + m_BlendQueue.pop_front(); + return HasActiveBlendJob(); + } + + Skeleton* skeleton = model->m_RawModel->m_Skeleton; + if (skeleton == nullptr) { + m_BlendQueue.pop_front(); + return HasActiveBlendJob(); + } + + + if (skeleton->BlendTrees.find(blendJob.RootNode) != skeleton->BlendTrees.end()) { + return true; + } else { + m_BlendQueue.pop_front(); + return HasActiveBlendJob(); + } + + + } else { + return false; + } + } +} + + +std::shared_ptr AutoBlendQueue::GetBlendTree() +{ + AutoblendNode blendNode = m_BlendQueue.front(); + AutoBlendJob blendJob = blendNode.BlendJob; + + if (!blendJob.RootNode.Valid()) { + m_BlendQueue.pop_front(); + return false; + } + + if (!blendJob.RootNode.HasComponent("Model")) { + return nullptr; + } + + Model* model; + try { + model = ResourceManager::Load<::Model, true>(blendJob.RootNode["Model"]["Resource"]); + } catch (const std::exception&) { + return nullptr; + } + + Skeleton* skeleton = model->m_RawModel->m_Skeleton; + if (skeleton == nullptr) { + return nullptr; + } + + + if (skeleton->BlendTrees.find(blendJob.RootNode) != skeleton->BlendTrees.end()) { + return skeleton->BlendTrees.at(blendJob.RootNode); + } else { + return nullptr; + } + + + +} + +AutoBlendQueue::AutoBlendJob& AutoBlendQueue::GetActiveBlendJob() +{ + AutoblendNode& blendNode = m_BlendQueue.front(); + blendNode.BlendJob.CurrentTime = -blendNode.StartTime; + return blendNode.BlendJob; +} diff --git a/src/Engine/Rendering/BlendTree.cpp b/src/Engine/Rendering/BlendTree.cpp index f7381d4d..036c3f49 100644 --- a/src/Engine/Rendering/BlendTree.cpp +++ b/src/Engine/Rendering/BlendTree.cpp @@ -51,8 +51,6 @@ BlendTree::BlendTree(EntityWrapper ModelEntity, Skeleton* skeleton) } m_FinalPose = AccumulateFinalPose(); - - // PrintTree(); } @@ -207,18 +205,16 @@ BlendTree::AutoBlendInfo BlendTree::AutoBlendStep(AutoBlendInfo blendInfo) { std::vector goalNodes = FindNodesByName(blendInfo.NodeName); - if (blendInfo.Restart) { + if (blendInfo.Start) { for (auto it = goalNodes.begin(); it != goalNodes.end(); it++) { EntityWrapper entity = (*it)->Entity; if (entity.Valid()) { if (entity.HasComponent("Animation")) { - (double&)entity["Animation"]["Time"] = 0.0; - (double&)entity["Animation"]["Speed"] = blendInfo.AnimationSpeed; + (bool&)entity["Animation"]["Play"] = true; } } } - blendInfo.Restart = false; } @@ -230,8 +226,6 @@ BlendTree::AutoBlendInfo BlendTree::AutoBlendStep(AutoBlendInfo blendInfo) while (currentNode != nullptr) { - - if(!currentNode->Entity.HasComponent("Blend")) { return blendInfo; } @@ -267,6 +261,91 @@ BlendTree::AutoBlendInfo BlendTree::AutoBlendStep(AutoBlendInfo blendInfo) return blendInfo; } + +BlendTree::Node* BlendTree::GetCommonParent(std::string NodeName1, std::string NodeName2) +{ + std::vector nodes1 = FindNodesByName(NodeName1); + std::vector nodes2 = FindNodesByName(NodeName2); + + for (auto it = nodes1.begin(); it != nodes1.end(); it++) { + auto next = std::next(it, 1); + + if(next != nodes1.end()) { + Node* commonParent = FirstCommonParent((*it), (*next)); + (*next) = commonParent; + nodes1.erase(it); + it = nodes1.begin(); + } + } + + for (auto it = nodes2.begin(); it != nodes2.end(); it++) { + auto next = std::next(it, 1); + + if (next != nodes2.end()) { + Node* commonParent = FirstCommonParent((*it), (*next)); + (*next) = commonParent; + nodes2.erase(it); + it = nodes2.begin(); + } + } + + return FirstCommonParent(nodes1.front(), nodes2.front());; +} + + +BlendTree::Node* BlendTree::FirstCommonParent(Node* node1, Node* node2) +{ + std::list node1Parents; + + Node* currentNode = node1; + while (currentNode != nullptr) { + node1Parents.push_back(currentNode); + currentNode = currentNode->Parent; + } + + currentNode = node2; + while (currentNode != nullptr) { + for (auto it = node1Parents.begin(); it != node1Parents.end(); it++) { + if (currentNode == (*it)) { + return currentNode; + } + } + currentNode = currentNode->Parent; + } + + return nullptr; +} + + +EntityWrapper BlendTree::GetSubTreeRoot(std::string nodeName) +{ + std::vector nodes = FindNodesByName(nodeName); + + std::vector subTreeRoots; + + for (auto it = nodes.begin(); it != nodes.end(); it++) { + Node* currentNode = (*it); + while (currentNode->Parent->Type == NodeType::Blend) { + currentNode = currentNode->Parent; + } + subTreeRoots.push_back(currentNode); + } + + + for (auto it = subTreeRoots.begin(); it != subTreeRoots.end(); it++) { + auto next = std::next(it, 1); + + if (next != subTreeRoots.end()) { + Node* commonParent = FirstCommonParent((*it), (*next)); + (*next) = commonParent; + subTreeRoots.erase(it); + it = subTreeRoots.begin(); + } + } + + return subTreeRoots.front()->Entity; +} + void BlendTree::Blend(std::map& pose) { Node* currentNode; From be331cb778665a670004cfebdea0d2b8f6dbf486 Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Thu, 3 Mar 2016 18:05:10 +0100 Subject: [PATCH 125/130] fixed --- include/Engine/Input/FirstPersonInputController.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/include/Engine/Input/FirstPersonInputController.h b/include/Engine/Input/FirstPersonInputController.h index f106a9eb..ed9469bd 100644 --- a/include/Engine/Input/FirstPersonInputController.h +++ b/include/Engine/Input/FirstPersonInputController.h @@ -165,11 +165,7 @@ bool FirstPersonInputController::OnCommand(const Events::InputComm m_SpecialAbilityKeyDown = e.Value > 0; } - if (m_SpecialAbilityKeyDown && m_MovementKeyDown) { - m_ShiftDashing = true; - } else { - m_ShiftDashing = false; - } + m_ShiftDashing = m_SpecialAbilityKeyDown && m_MovementKeyDown; return true; } From 7943fc7ad688aa4af7bec1193cdc3154ddf1783a Mon Sep 17 00:00:00 2001 From: Jocke Date: Thu, 3 Mar 2016 18:14:33 +0100 Subject: [PATCH 126/130] Hot fix: Infinite loop when a player disconnected from the server. --- src/Engine/Network/UDPClient.cpp | 2 +- src/Engine/Network/UDPServer.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Engine/Network/UDPClient.cpp b/src/Engine/Network/UDPClient.cpp index a7061884..1d71c155 100644 --- a/src/Engine/Network/UDPClient.cpp +++ b/src/Engine/Network/UDPClient.cpp @@ -47,7 +47,7 @@ int UDPClient::readBuffer() memcpy(&sizeOfPacket, m_ReadBuffer, sizeof(int)); if (sizeOfPacket > m_Socket->available()) { LOG_WARNING("UDPClient::readBuffer(): We haven't got the whole packet yet."); - return 0; + //return 0; } // if the buffer is to small increase the size of it if (sizeOfPacket > m_BufferSize) { diff --git a/src/Engine/Network/UDPServer.cpp b/src/Engine/Network/UDPServer.cpp index 13dd5ccd..8c9950dc 100644 --- a/src/Engine/Network/UDPServer.cpp +++ b/src/Engine/Network/UDPServer.cpp @@ -94,7 +94,7 @@ int UDPServer::readBuffer() if (sizeOfPacket > m_Socket->available()) { LOG_WARNING("UDPServer::readBuffer(): We haven't got the whole packet yet."); - return 0; + //return 0; } // if the buffer is to small increase the size of it From b2371f4a43a92991a79266805472be145dd295b8 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Thu, 3 Mar 2016 20:00:42 +0100 Subject: [PATCH 127/130] Working AssaultWeapon --- .../Systems/Weapon/AssaultWeaponBehaviour.h | 51 +- .../Systems/Weapon/DefenderWeaponBehaviour.h | 7 +- .../Systems/Weapon/SidearmWeaponBehaviour.h | 7 +- resources/Schema/Components/AssaultWeapon.xml | 21 +- resources/Schema/Components/AssaultWeapon.xsd | 23 +- .../Schema/Components/DefenderWeapon.xml | 2 +- .../Schema/Components/DefenderWeapon.xsd | 2 +- resources/Schema/Components/SidearmWeapon.xml | 2 +- resources/Schema/Components/SidearmWeapon.xsd | 2 +- .../Schema/Entities/AssaultWeaponView.xml | 28 +- .../Schema/Entities/AssaultWeaponWorld.xml | 10 +- resources/Schema/Entities/Player.xml | 16 +- .../Entities/PlayerAssaultFallbackBlue.xml | 695 ++++++++++++++++++ resources/Schema/Entities/Ray2Red | 18 - resources/Schema/Entities/Ray2Red.xml | 43 -- resources/Schema/Entities/RayBlue | 17 - resources/Schema/Entities/RayBlue.xml | 44 +- resources/Schema/Entities/RayRed | 17 - resources/Schema/Entities/RayRed.xml | 20 - src/Game/Game.cpp | 2 + .../Systems/Weapon/AssaultWeaponBehaviour.cpp | 228 ++++++ 21 files changed, 1061 insertions(+), 194 deletions(-) create mode 100644 resources/Schema/Entities/PlayerAssaultFallbackBlue.xml delete mode 100644 resources/Schema/Entities/Ray2Red delete mode 100644 resources/Schema/Entities/Ray2Red.xml delete mode 100644 resources/Schema/Entities/RayBlue delete mode 100644 resources/Schema/Entities/RayRed delete mode 100644 resources/Schema/Entities/RayRed.xml create mode 100644 src/Game/Systems/Weapon/AssaultWeaponBehaviour.cpp diff --git a/include/Game/Systems/Weapon/AssaultWeaponBehaviour.h b/include/Game/Systems/Weapon/AssaultWeaponBehaviour.h index 993dd060..7244d443 100644 --- a/include/Game/Systems/Weapon/AssaultWeaponBehaviour.h +++ b/include/Game/Systems/Weapon/AssaultWeaponBehaviour.h @@ -1,47 +1,40 @@ #ifndef AssaultWeaponBehaviour_h__ #define AssaultWeaponBehaviour_h__ -#include "Sound/EPlaySoundOnEntity.h" -#include "Collision/Collision.h" -#include "Core/ConfigFile.h" #include "WeaponBehaviour.h" -#include "../SpawnerSystem.h" +#include "Collision/Collision.h" #include "Core/EPlayerDamage.h" -#include "Core/EShoot.h" +#include "Sound/EPlaySoundOnEntity.h" class AssaultWeaponBehaviour : public WeaponBehaviour { public: AssaultWeaponBehaviour(SystemParams systemParams, IRenderer* renderer, Octree* collisionOctree) - : WeaponBehaviour(systemParams, "AssaultWeapon", renderer, collisionOctree) + : System(systemParams) + , WeaponBehaviour(systemParams, "AssaultWeapon", renderer, collisionOctree) + , m_RandomEngine(m_RandomDevice()) { } -protected: - virtual void OnPrimaryFire(WeaponInfo& wi) override; - virtual void OnCeasePrimaryFire(WeaponInfo& wi) override; - virtual void OnReload(WeaponInfo& wi) override; + void UpdateComponent(EntityWrapper& entity, ComponentWrapper& cWeapon, double dt) override; + void UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo& wi, double dt) override; + void OnPrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi) override; + void OnCeasePrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi) override; + void OnReload(ComponentWrapper cWeapon, WeaponInfo& wi) override; + void OnHolster(ComponentWrapper cWeapon, WeaponInfo& wi) override; + //bool OnInputCommand(ComponentWrapper cWeapon, WeaponInfo& wi, const Events::InputCommand& e) override; private: - // State - bool m_Firing = false; - bool m_Reloading = false; - double m_ReloadTimer = 0.0; - double m_TimeSinceLastFire = 0.0; - EntityWrapper m_FirstPersonReloadImpostor; + std::random_device m_RandomDevice; + std::mt19937 m_RandomEngine; - bool hasAmmo(); - void fireRound(); - void spawnTracer(); - float traceRayDistance(glm::vec3 origin, glm::vec3 direction); - void playFireSound(); - void playEmptySound(); - void viewPunch(); - void finishReload(); - void playShootAnimation(); - void playIdleAnimation(); - void playReloadAnimation(); - bool shoot(double damage); - void showHitMarker(); + // Weapon functions + void fireBullet(ComponentWrapper cWeapon, WeaponInfo& wi); + //void dealDamage(ComponentWrapper cWeapon, WeaponInfo& wi, glm::vec3 direction, double damage); + bool canFire(ComponentWrapper cWeapon, WeaponInfo& wi); + bool dealDamage(ComponentWrapper cWeapon, WeaponInfo& wi); + + // Utility + //Camera cameraFromEntity(EntityWrapper camera); }; #endif \ No newline at end of file diff --git a/include/Game/Systems/Weapon/DefenderWeaponBehaviour.h b/include/Game/Systems/Weapon/DefenderWeaponBehaviour.h index 77d579f8..9e7d4991 100644 --- a/include/Game/Systems/Weapon/DefenderWeaponBehaviour.h +++ b/include/Game/Systems/Weapon/DefenderWeaponBehaviour.h @@ -1,3 +1,6 @@ +#ifndef DefenderWeaponBehaviour_h__ +#define DefenderWeaponBehaviour_h__ + #include "WeaponBehaviour.h" #include "Collision/Collision.h" #include "Core/EPlayerDamage.h" @@ -31,4 +34,6 @@ private: // Utility Camera cameraFromEntity(EntityWrapper camera); -}; \ No newline at end of file +}; + +#endif \ No newline at end of file diff --git a/include/Game/Systems/Weapon/SidearmWeaponBehaviour.h b/include/Game/Systems/Weapon/SidearmWeaponBehaviour.h index d221b8bb..10e6105a 100644 --- a/include/Game/Systems/Weapon/SidearmWeaponBehaviour.h +++ b/include/Game/Systems/Weapon/SidearmWeaponBehaviour.h @@ -1,3 +1,6 @@ +#ifndef SidearmWeaponBehaviour_h__ +#define SidearmWeaponBehaviour_h__ + #include "WeaponBehaviour.h" #include "Collision/Collision.h" #include "Core/EPlayerDamage.h" @@ -30,4 +33,6 @@ private: bool canFire(ComponentWrapper cWeapon); bool playerInFirstPerson(EntityWrapper player); //float traceRayDistance(glm::vec3 origin, glm::vec3 direction); -}; \ No newline at end of file +}; + +#endif \ No newline at end of file diff --git a/resources/Schema/Components/AssaultWeapon.xml b/resources/Schema/Components/AssaultWeapon.xml index c835217b..ba74fbb7 100755 --- a/resources/Schema/Components/AssaultWeapon.xml +++ b/resources/Schema/Components/AssaultWeapon.xml @@ -1,12 +1,21 @@ + 32 32 - 360 - 360 - 5 - 120 - 0.01 + 320 + 320 + 15 + 0.174533 + 0.10 + 420 + 0.03 + 0.18 2 - + 0.5 + false + 0 + false + 0 + 0 \ No newline at end of file diff --git a/resources/Schema/Components/AssaultWeapon.xsd b/resources/Schema/Components/AssaultWeapon.xsd index 7e9854a2..a1e745de 100755 --- a/resources/Schema/Components/AssaultWeapon.xsd +++ b/resources/Schema/Components/AssaultWeapon.xsd @@ -7,6 +7,7 @@ + Ammo currently loaded into the magazine @@ -20,16 +21,32 @@ Maximum ammo able to be carried + + Spread angle in radians + + + Maximum vertical aim travel angle in radians + Rate of fire in rounds per minute - View punch in radians for each bullet fired + View punch in radians for each shell fired + + + The speed in radians per second the view returns to its original position after being punched - Time it takes to reload the weapon in seconds + Time it takes to load ONE SHELL into the weapon in seconds - + + Time it takes from selecting the weapon until it's ready to fire + + + + + + diff --git a/resources/Schema/Components/DefenderWeapon.xml b/resources/Schema/Components/DefenderWeapon.xml index 68b87759..b01955bc 100755 --- a/resources/Schema/Components/DefenderWeapon.xml +++ b/resources/Schema/Components/DefenderWeapon.xml @@ -1,5 +1,6 @@ + 8 8 64 @@ -12,7 +13,6 @@ 0.03 0.2 0.5 - false 0 false diff --git a/resources/Schema/Components/DefenderWeapon.xsd b/resources/Schema/Components/DefenderWeapon.xsd index d2b503f8..53200952 100755 --- a/resources/Schema/Components/DefenderWeapon.xsd +++ b/resources/Schema/Components/DefenderWeapon.xsd @@ -19,6 +19,7 @@ + Ammo currently loaded into the magazine @@ -53,7 +54,6 @@ Time it takes to load ONE SHELL into the weapon in seconds - diff --git a/resources/Schema/Components/SidearmWeapon.xml b/resources/Schema/Components/SidearmWeapon.xml index 1d503ecc..bc90c067 100644 --- a/resources/Schema/Components/SidearmWeapon.xml +++ b/resources/Schema/Components/SidearmWeapon.xml @@ -1,5 +1,6 @@ + 16 16 20 @@ -8,7 +9,6 @@ 0.01 0.5 0.5 - false 0 false diff --git a/resources/Schema/Components/SidearmWeapon.xsd b/resources/Schema/Components/SidearmWeapon.xsd index bafb9de2..514bf354 100644 --- a/resources/Schema/Components/SidearmWeapon.xsd +++ b/resources/Schema/Components/SidearmWeapon.xsd @@ -19,6 +19,7 @@ + Ammo currently loaded into the magazine @@ -41,7 +42,6 @@ Time it takes from selecting the weapon until it's ready to fire - diff --git a/resources/Schema/Entities/AssaultWeaponView.xml b/resources/Schema/Entities/AssaultWeaponView.xml index 4b985fbb..b5c87674 100755 --- a/resources/Schema/Entities/AssaultWeaponView.xml +++ b/resources/Schema/Entities/AssaultWeaponView.xml @@ -1,17 +1,11 @@ - + - - R_Arm_Weapon_Joint - Models/Weapons/Blue/AssaultWeaponBlue.mesh - - - - + @@ -21,7 +15,8 @@ Schema/Entities/RayBlue.xml - + + @@ -37,9 +32,8 @@ - - + @@ -70,6 +64,11 @@ Fonts/DroidSans.ttf,64 + + Player + AssaultWeapon + MagazineAmmo + @@ -79,10 +78,15 @@ - 360 + 320 Fonts/DroidSans.ttf,64 + + Player + AssaultWeapon + Ammo + diff --git a/resources/Schema/Entities/AssaultWeaponWorld.xml b/resources/Schema/Entities/AssaultWeaponWorld.xml index 6fcb97b3..9f33c8f2 100755 --- a/resources/Schema/Entities/AssaultWeaponWorld.xml +++ b/resources/Schema/Entities/AssaultWeaponWorld.xml @@ -1,17 +1,11 @@ - + - - R_Arm_Weapon_Joint - Models/Weapons/Blue/AssaultWeaponBlue.mesh - - - - + diff --git a/resources/Schema/Entities/Player.xml b/resources/Schema/Entities/Player.xml index 1ee9d5d3..affe9f79 100644 --- a/resources/Schema/Entities/Player.xml +++ b/resources/Schema/Entities/Player.xml @@ -6,10 +6,14 @@ + + + + + - + - @@ -470,10 +474,10 @@ R_Arm_Weapon_Joint - DefenderWeapon + AssaultWeapon - Schema/Entities/DefenderWeaponView.xml + Schema/Entities/AssaultWeaponView.xml @@ -545,13 +549,13 @@ - DefenderWeapon + AssaultWeapon - Schema/Entities/DefenderWeaponWorld.xml + Schema/Entities/AssaultWeaponWorld.xml diff --git a/resources/Schema/Entities/PlayerAssaultFallbackBlue.xml b/resources/Schema/Entities/PlayerAssaultFallbackBlue.xml new file mode 100644 index 00000000..bb6367f8 --- /dev/null +++ b/resources/Schema/Entities/PlayerAssaultFallbackBlue.xml @@ -0,0 +1,695 @@ + + + + + + + + + + + + + + + + + + 5 + + + + + + + + + + + + + + + + + 0.10000000149011612 + 300 + + + + + + + + + + Models/Widgets/Camera.mesh + false + + + + + + + + + + + + + + + + + + + Textures/Weapons/Crosshair/SmallThickHoleDot.png + + false + + + + + + + + + + + + Schema/Entities/HitMarker.xml + + + + + + + + + + + + + + 1 + + + + + Textures/HealthHUD3.png + + + + + + + + + + + + + + + + + + + + + + + Textures/Core/White.png + + false + + + + + + + + + + + + + + + + Textures/Core/White.png + + false + + + + + + + + + + + + + + + + Textures/Core/White.png + + false + + + + + + + + + + + + + + + + + 1 + + + + 100/100 + Fonts/DroidSans.ttf,64 + + + + + + + + + + + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + 2 + + + + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + 3 + + + + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + 4 + + + 1 + + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + 1 + + + + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + + 1 + + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + + + + + + + + + + + + + + + Fonts/DroidSans.ttf,64 + + + + + + + + + + + + + Fonts/DroidSans.ttf,64 + + + + + + + + + + + + + + + Fonts/DroidSans.ttf,64 + + + + + + + + + + + + + + + + + Models/Widgets/Arrows/Arrow5.mesh + + + + + + + + + + + + + + + + + + + + Idle + 1.8348644854054612 + 1 + + + + + Models/Characters/Assault/Test/FirstPerson.mesh + + + + + + + + + R_Arm_Weapon_Joint + + + AssaultWeapon + + + Schema/Entities/AssaultWeaponView.xml + + + + + + + + + + + + R_Arm_Weapon_Joint + + + SidearmWeapon + + + Schema/Entities/SidearmWeaponView.xml + + + + + + + + + + + + + + + + 0.10000000149011612 + 300 + + + Models/Widgets/Camera.mesh + false + + + + + + + + + + + + IdleF + 1 + + + + + AimRifle + + + + + + Models/Characters/Assault/AssaultBlue.mesh + + + + + + + + + R_Arm_Weapon_Joint + + + AssaultWeapon + + + + + + Schema/Entities/AssaultWeaponWorld.xml + + + + + + + + + + + Models/Weapons/Blue/AssaultWeaponBlue.mesh + + + + + + + + Schema/Entities/RayBlue.xml + + + + + + + + + + + Schema/Entities/ReloadEffectWorld.xml + + + + + + + + + + + + + R_Arm_Weapon_Joint + + + SidearmWeapon + + + + + + Schema/Entities/SidearmWeaponWorld.xml + + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + false + + + + + + + + + + + + Models/Core/UnitCube.mesh + + false + + + + + + + + + + + Insert name here + Fonts/DroidSans.ttf,100 + + + + + + + + + + + + + + Textures/Icons/Arrow.png + + false + + + + + 50 + true + + + + + + + + + + + + Schema/Entities/DefenderShield.xml + + + + + + + + + + diff --git a/resources/Schema/Entities/Ray2Red b/resources/Schema/Entities/Ray2Red deleted file mode 100644 index 813443b2..00000000 --- a/resources/Schema/Entities/Ray2Red +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - Textures/Effects/Ray.png - - - - - - - - - - - - diff --git a/resources/Schema/Entities/Ray2Red.xml b/resources/Schema/Entities/Ray2Red.xml deleted file mode 100644 index 6c7c3248..00000000 --- a/resources/Schema/Entities/Ray2Red.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - - - - - Textures/Effects/Ray.png - - - - - - - - - - - - - - - Textures/Effects/Ray.png - - - - - - - - - - - - - - diff --git a/resources/Schema/Entities/RayBlue b/resources/Schema/Entities/RayBlue deleted file mode 100644 index d34e185e..00000000 --- a/resources/Schema/Entities/RayBlue +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - Models/Core/UnitCylinder.mesh - - - - - - - - - - - diff --git a/resources/Schema/Entities/RayBlue.xml b/resources/Schema/Entities/RayBlue.xml index 022d7769..0ad0ddf0 100644 --- a/resources/Schema/Entities/RayBlue.xml +++ b/resources/Schema/Entities/RayBlue.xml @@ -1,20 +1,46 @@ - + - 0.25 + 0.10000000149011612 - - Models/Effects/CylinderShot.mesh - - true - - + - + + + + + Textures/Effects/Ray.png + + + + + + + + + + + + + + + Textures/Effects/Ray.png + + + + + + + + + + + + diff --git a/resources/Schema/Entities/RayRed b/resources/Schema/Entities/RayRed deleted file mode 100644 index d34e185e..00000000 --- a/resources/Schema/Entities/RayRed +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - Models/Core/UnitCylinder.mesh - - - - - - - - - - - diff --git a/resources/Schema/Entities/RayRed.xml b/resources/Schema/Entities/RayRed.xml deleted file mode 100644 index 0a20f148..00000000 --- a/resources/Schema/Entities/RayRed.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - 0.25 - - - Models/Effects/CylinderShot.mesh - - true - - - - - - - - - diff --git a/src/Game/Game.cpp b/src/Game/Game.cpp index 10107ab1..9ebb28eb 100644 --- a/src/Game/Game.cpp +++ b/src/Game/Game.cpp @@ -18,6 +18,7 @@ #include "Game/Systems/PickupSpawnSystem.h" #include "Game/Systems/AmmoPickupSystem.h" #include "Game/Systems/DamageIndicatorSystem.h" +#include "Game/Systems/Weapon/AssaultWeaponBehaviour.h" #include "Game/Systems/Weapon/DefenderWeaponBehaviour.h" #include "Game/Systems/Weapon/SidearmWeaponBehaviour.h" #include "Rendering/AnimationSystem.h" @@ -128,6 +129,7 @@ Game::Game(int argc, char* argv[]) m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); + m_SystemPipeline->AddSystem(updateOrderLevel, m_Renderer, m_OctreeCollision); m_SystemPipeline->AddSystem(updateOrderLevel, m_Renderer, m_OctreeCollision); m_SystemPipeline->AddSystem(updateOrderLevel, m_Renderer, m_OctreeCollision); m_SystemPipeline->AddSystem(updateOrderLevel); diff --git a/src/Game/Systems/Weapon/AssaultWeaponBehaviour.cpp b/src/Game/Systems/Weapon/AssaultWeaponBehaviour.cpp new file mode 100644 index 00000000..c982637b --- /dev/null +++ b/src/Game/Systems/Weapon/AssaultWeaponBehaviour.cpp @@ -0,0 +1,228 @@ +#include "Systems/Weapon/AssaultWeaponBehaviour.h" + +void AssaultWeaponBehaviour::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cWeapon, double dt) +{ + double& fireCooldown = cWeapon["FireCooldown"]; + fireCooldown = glm::max(0.0, fireCooldown - dt); + + WeaponBehaviour::UpdateComponent(entity, cWeapon, dt); +} + +void AssaultWeaponBehaviour::UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo& wi, double dt) +{ + // Decrement reload timer + double& reloadTimer = cWeapon["ReloadTimer"]; + reloadTimer = glm::max(0.0, reloadTimer - dt); + + // Start reloading automatically if at 0 mag ammo + int& magAmmo = cWeapon["MagazineAmmo"]; + if (m_ConfigAutoReload && magAmmo <= 0) { + OnReload(cWeapon, wi); + } + + // Handle reloading + bool& isReloading = cWeapon["IsReloading"]; + if (isReloading && reloadTimer <= 0.0) { + int& magSize = cWeapon["MagazineSize"]; + int& ammo = cWeapon["Ammo"]; + + ammo = glm::max(0, ammo - (magSize - magAmmo)); + magAmmo = glm::min(magSize, ammo); + isReloading = false; + } + + // Restore view angle + if (IsClient) { + float& currentTravel = cWeapon["CurrentTravel"]; + float& returnSpeed = cWeapon["ViewReturnSpeed"]; + if (currentTravel > 0) { + float change = returnSpeed * dt; + currentTravel = glm::max(0.f, currentTravel - change); + EntityWrapper camera = wi.Player.FirstChildByName("Camera"); + if (camera.Valid()) { + glm::vec3& cameraOrientation = camera["Transform"]["Orientation"]; + cameraOrientation.x -= change; + } + } + } + + // Fire if we're able to fire + if (canFire(cWeapon, wi)) { + fireBullet(cWeapon, wi); + } +} + +void AssaultWeaponBehaviour::OnPrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi) +{ + cWeapon["TriggerHeld"] = true; + if (canFire(cWeapon, wi)) { + fireBullet(cWeapon, wi); + } +} + +void AssaultWeaponBehaviour::OnCeasePrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi) +{ + cWeapon["TriggerHeld"] = false; +} + +void AssaultWeaponBehaviour::OnReload(ComponentWrapper cWeapon, WeaponInfo& wi) +{ + bool& isReloading = cWeapon["IsReloading"]; + if (isReloading) { + return; + } + + int& magAmmo = cWeapon["MagazineAmmo"]; + int& magSize = cWeapon["MagazineSize"]; + if (magAmmo >= magSize) { + return; + } + int& ammo = cWeapon["Ammo"]; + if (ammo <= 0) { + return; + } + + double reloadTime = cWeapon["ReloadTime"]; + double& reloadTimer = cWeapon["ReloadTimer"]; + + // Start reload + isReloading = true; + reloadTimer = reloadTime; +} + +void AssaultWeaponBehaviour::OnHolster(ComponentWrapper cWeapon, WeaponInfo& wi) +{ + // Make sure the trigger is released if weapon is holstered while firing + cWeapon["TriggerHeld"] = false; + + // Cancel any reload + cWeapon["IsReloading"] = false; + cWeapon["ReloadTimer"] = 0.0; +} + +void AssaultWeaponBehaviour::fireBullet(ComponentWrapper cWeapon, WeaponInfo& wi) +{ + cWeapon["FireCooldown"] = 60.0 / (double)cWeapon["RPM"]; + + // Ammo + int& magAmmo = cWeapon["MagazineAmmo"]; + if (magAmmo <= 0) { + return; + } else { + magAmmo -= 1; + } + + // View punch + if (IsClient) { + EntityWrapper camera = wi.Player.FirstChildByName("Camera"); + if (camera.Valid()) { + glm::vec3& cameraOrientation = camera["Transform"]["Orientation"]; + float viewPunch = cWeapon["ViewPunch"]; + float maxTravelAngle = cWeapon["MaxTravelAngle"]; + float& currentTravel = cWeapon["CurrentTravel"]; + if (currentTravel < maxTravelAngle) { + float change = viewPunch; + if (currentTravel + change > maxTravelAngle) { + change = maxTravelAngle - currentTravel; + } + cameraOrientation.x += change; + currentTravel += change; + } + } + } + + // Get weapon model based on current person + EntityWrapper weaponModelEntity = getRelevantWeaponModelEntity(wi); + if (!weaponModelEntity.Valid()) { + return; + } + + // Tracer + EntityWrapper tracerSpawner = weaponModelEntity.FirstChildByName("WeaponMuzzle"); + if (tracerSpawner.Valid()) { + glm::vec3 origin = Transform::AbsolutePosition(tracerSpawner); + glm::vec3 direction = glm::quat(Transform::AbsoluteOrientationEuler(tracerSpawner)) * glm::vec3(0, 0, -1); + float distance = traceRayDistance(origin, direction); + EntityWrapper ray = SpawnerSystem::Spawn(tracerSpawner); + if (ray.Valid()) { + ((glm::vec3&)ray["Transform"]["Scale"]).z = distance; + } + } + + // Deal damage + if (dealDamage(cWeapon, wi)) { + // Show hit marker + EntityWrapper hitMarkerSpawner = wi.Player.FirstChildByName("HitMarkerSpawner"); + if (hitMarkerSpawner.Valid()) { + SpawnerSystem::Spawn(hitMarkerSpawner, hitMarkerSpawner); + Events::PlaySoundOnEntity e; + e.EmitterID = wi.Player.ID; + e.FilePath = "Audio/weapon/hitclick.wav"; + m_EventBroker->Publish(e); + } + } +} + +bool AssaultWeaponBehaviour::canFire(ComponentWrapper cWeapon, WeaponInfo& wi) +{ + bool triggerHeld = cWeapon["TriggerHeld"]; + bool cooldownPassed = (double)cWeapon["FireCooldown"] <= 0.0; + bool isReloading = cWeapon["IsReloading"]; + return triggerHeld && cooldownPassed; +} + +bool AssaultWeaponBehaviour::dealDamage(ComponentWrapper cWeapon, WeaponInfo& wi) +{ + // Only deal damage client side + if (!IsClient) { + return false; + } + + // Only handle damage for the local player + if (wi.Player != LocalPlayer) { + return false; + } + + // Make sure the player isn't shooting from the grave + if (!wi.Player.Valid()) { + return false; + } + + // 3D-pick middle of screen + Rectangle viewport = m_Renderer->GetViewportSize(); + glm::vec2 centerScreen(viewport.Width / 2, viewport.Height / 2); + // TODO: Some horizontal spread + PickData pickData = m_Renderer->Pick(centerScreen); + EntityWrapper victim(m_World, pickData.Entity); + if (!victim.Valid()) { + return false; + } + + // Don't let us somehow shoot ourselves in the foot + if (victim == LocalPlayer) { + return false; + } + + // Only care about players being hit + if (!victim.HasComponent("Player")) { + victim = victim.FirstParentWithComponent("Player"); + } + if (!victim.Valid()) { + return false; + } + + double damage = cWeapon["BaseDamage"]; + // If friendly fire, reduce damage to 0 (needed to make Boosts, Ammosharing work) + if ((ComponentInfo::EnumType)victim["Team"]["Team"] == (ComponentInfo::EnumType)wi.Player["Team"]["Team"]) { + damage = 0; + } + + // Deal damage! + Events::PlayerDamage ePlayerDamage; + ePlayerDamage.Inflictor = wi.Player; + ePlayerDamage.Victim = victim; + ePlayerDamage.Damage = damage; + m_EventBroker->Publish(ePlayerDamage); + + return damage > 0; +} From 68332102ead701a3c07eddb7921cc3313853b989 Mon Sep 17 00:00:00 2001 From: viktorljung Date: Thu, 3 Mar 2016 21:20:55 +0100 Subject: [PATCH 128/130] Can now blend non unique nodes --- resources/Schema/Entities/BlendTreeTest.xml | 47 +++++++++---- src/Engine/Rendering/AnimationSystem.cpp | 77 ++++++++++++++++++++- src/Engine/Rendering/AutoBlendQueue.cpp | 2 +- src/Engine/Rendering/BlendTree.cpp | 62 ++++++++++++++++- 4 files changed, 168 insertions(+), 20 deletions(-) diff --git a/resources/Schema/Entities/BlendTreeTest.xml b/resources/Schema/Entities/BlendTreeTest.xml index 69590ceb..d2c7ead9 100644 --- a/resources/Schema/Entities/BlendTreeTest.xml +++ b/resources/Schema/Entities/BlendTreeTest.xml @@ -68,8 +68,8 @@ Models/Weapons/Blue/AssaultWeaponBlue.mesh - - + + @@ -125,7 +125,7 @@ StandCrouchBlend JumpDashBlend - 0.00067602147306955462 + 1.055110346338068e-57 @@ -135,7 +135,7 @@ StandMovement CrouchMovement - 0 + 0.0069837930620454403 @@ -155,7 +155,7 @@ RunWalkBlend StrafeLRBlend - 0 + 2.4565650245976452e-16 @@ -165,7 +165,7 @@ Walk Run - 1 + 1.2938206818383024e-24 @@ -174,6 +174,9 @@ WalkF + + 1 + true @@ -183,7 +186,7 @@ RunF - + 1 true @@ -198,7 +201,7 @@ Left Right - 0 + 0.033793529385008014 @@ -207,6 +210,9 @@ StrafeLeftF + + 1 + true @@ -216,6 +222,9 @@ StrafeRightF + + 1 + true @@ -243,6 +252,7 @@ MovementBlend Idle + 0 @@ -252,7 +262,7 @@ Walk StrafeLRBlend - 0 + 2.4565650245976452e-16 @@ -262,7 +272,7 @@ Left Right - 0 + 0.033793529385008014 @@ -271,6 +281,9 @@ CrouchStrafeLeftF + + 1 + true @@ -280,6 +293,9 @@ CrouchStrafeRightF + + 1 + true @@ -291,6 +307,9 @@ CrouchWalkF + + 1 + true @@ -318,7 +337,7 @@ Jump DashBlend - 0.01016461050458084 + 1 @@ -340,7 +359,7 @@ DashFBBlend DashLRBlend - 0.99999999999984523 + 0.014621149736541383 @@ -350,7 +369,7 @@ DashForward DashBackward - 0.98238059685988577 + 0.014363533804961248 @@ -386,7 +405,7 @@ DashLeft DashRight - 0.96547196574235861 + 4.3244885367500671e-16 diff --git a/src/Engine/Rendering/AnimationSystem.cpp b/src/Engine/Rendering/AnimationSystem.cpp index 166ecb47..4434e80b 100644 --- a/src/Engine/Rendering/AnimationSystem.cpp +++ b/src/Engine/Rendering/AnimationSystem.cpp @@ -371,7 +371,7 @@ bool AnimationSystem::OnInputCommand(const Events::InputCommand& e) if (entity.Name() == "Assault") { { Events::AutoAnimationBlend aeb; - aeb.Duration = 0.35; + aeb.Duration = 0.25; aeb.NodeName = "Jump"; aeb.RootNode = entity; aeb.Start = true; @@ -380,7 +380,7 @@ bool AnimationSystem::OnInputCommand(const Events::InputCommand& e) } { Events::AutoAnimationBlend aeb; - aeb.Duration = 0.6; + aeb.Duration = 0.3; aeb.NodeName = "StandCrouchBlend"; aeb.RootNode = entity; aeb.Start = true; @@ -496,6 +496,79 @@ bool AnimationSystem::OnInputCommand(const Events::InputCommand& e) } } } + } else if (e.Command == "LeftTest") { + auto blendComponents = m_World->GetComponents("BlendAdditive"); + + if (blendComponents == nullptr) { + return false; + } + for (auto& bc : *blendComponents) { + EntityWrapper entity = EntityWrapper(m_World, bc.EntityID); + + if (entity.Name() == "Assault") { + { + Events::AutoAnimationBlend aeb; + aeb.Duration = 0.1; + aeb.NodeName = "Left"; + aeb.RootNode = entity; + aeb.Start = true; + m_EventBroker->Publish(aeb); + } + } + } + } else if (e.Command == "RightTest") { + auto blendComponents = m_World->GetComponents("BlendAdditive"); + + if (blendComponents == nullptr) { + return false; + } + for (auto& bc : *blendComponents) { + EntityWrapper entity = EntityWrapper(m_World, bc.EntityID); + + if (entity.Name() == "Assault") { + /* { + Events::AutoAnimationBlend aeb; + aeb.Duration = 0.1; + aeb.NodeName = "Right"; + aeb.RootNode = entity; + aeb.Start = true; + m_EventBroker->Publish(aeb); + }*/ + + + { + Events::AutoAnimationBlend aeb; + aeb.Duration = 0.3; + aeb.NodeName = "Right"; + aeb.RootNode = entity; + aeb.Start = true; + aeb.Restart = false; + aeb.AnimationEntity = entity.FirstChildByName("DashRight"); + aeb.Delay = -0.3; + m_EventBroker->Publish(aeb); + } + } + } + } else if (e.Command == "ForwardTest") { + auto blendComponents = m_World->GetComponents("BlendAdditive"); + + if (blendComponents == nullptr) { + return false; + } + for (auto& bc : *blendComponents) { + EntityWrapper entity = EntityWrapper(m_World, bc.EntityID); + + if (entity.Name() == "Assault") { + { + Events::AutoAnimationBlend aeb; + aeb.Duration = 0.1; + aeb.NodeName = "Walk"; + aeb.RootNode = entity; + aeb.Start = true; + m_EventBroker->Publish(aeb); + } + } + } } diff --git a/src/Engine/Rendering/AutoBlendQueue.cpp b/src/Engine/Rendering/AutoBlendQueue.cpp index 9f0a7366..e75e33b5 100644 --- a/src/Engine/Rendering/AutoBlendQueue.cpp +++ b/src/Engine/Rendering/AutoBlendQueue.cpp @@ -85,7 +85,7 @@ void AutoBlendQueue::UpdateTime(double dt) for (auto it = m_BlendQueue.begin(); it != m_BlendQueue.end();) { it->EndTime -= dt; it->StartTime -= dt; - if (it->EndTime < 0) { + if (it->EndTime <= 0) { it = m_BlendQueue.erase(it); } else { it++; diff --git a/src/Engine/Rendering/BlendTree.cpp b/src/Engine/Rendering/BlendTree.cpp index 036c3f49..2f74b45e 100644 --- a/src/Engine/Rendering/BlendTree.cpp +++ b/src/Engine/Rendering/BlendTree.cpp @@ -252,16 +252,72 @@ BlendTree::AutoBlendInfo BlendTree::AutoBlendStep(AutoBlendInfo blendInfo) lastNode = currentNode; currentNode = currentNode->Parent; } - - } else if(goalNodes.size() >= 2) { + std::vector sharedParents; + std::vector nodes = goalNodes; + + for (auto it = nodes.begin(); it != nodes.end(); it++) { + auto next = std::next(it, 1); + if (next != nodes.end()) { + Node* commonParent = FirstCommonParent((*it), (*next)); + sharedParents.push_back(commonParent); + (*next) = commonParent; + nodes.erase(it); + it = nodes.begin(); + } + } + + + for (auto it = goalNodes.begin(); it != goalNodes.end(); it++) { + + Node* currentNode = (*it)->Parent; + Node* lastNode = (*it); + + while (currentNode != nullptr) { + if (!currentNode->Entity.HasComponent("Blend")) { + return blendInfo; + } + + bool ShouldBreak = false; + for (auto it = sharedParents.begin(); it != sharedParents.end(); it++) { + if(currentNode == (*it)) { + ShouldBreak = true; + } + } + + if(ShouldBreak) { + break; + } + + double startWeight; + if (blendInfo.StartWeights.find(currentNode->Entity) != blendInfo.StartWeights.end()) { + startWeight = blendInfo.StartWeights.at(currentNode->Entity); + } else { + startWeight = currentNode->Weight; + blendInfo.StartWeights[currentNode->Entity] = startWeight; + } + + double goalWeight; + if (currentNode->Child[0] == lastNode) { + goalWeight = 0.0; + } else if (currentNode->Child[1] == lastNode) { + goalWeight = 1.0; + } + + double weight = ((goalWeight - startWeight) * blendInfo.progress) + startWeight; + (double&)currentNode->Entity["Blend"]["Weight"] = weight; + currentNode->Weight = weight; + + lastNode = currentNode; + currentNode = currentNode->Parent; + } + } } return blendInfo; } - BlendTree::Node* BlendTree::GetCommonParent(std::string NodeName1, std::string NodeName2) { std::vector nodes1 = FindNodesByName(NodeName1); From e3fbd2082c18f6e761b9f7c1d211d4e0924312da Mon Sep 17 00:00:00 2001 From: viktorljung Date: Thu, 3 Mar 2016 23:20:13 +0100 Subject: [PATCH 129/130] BlendQueues fully working --- include/Engine/Rendering/BlendTree.h | 3 +- .../Engine/Rendering/EAutoAnimationBlend.h | 1 + resources/Schema/Components/Blend.xml | 1 + resources/Schema/Components/Blend.xsd | 1 + resources/Schema/Entities/BlendTreeTest.xml | 39 ++++--- src/Engine/Rendering/AnimationSystem.cpp | 101 ++++++++++-------- src/Engine/Rendering/AutoBlendQueue.cpp | 9 +- src/Engine/Rendering/BlendTree.cpp | 10 +- 8 files changed, 99 insertions(+), 66 deletions(-) diff --git a/include/Engine/Rendering/BlendTree.h b/include/Engine/Rendering/BlendTree.h index 2c5f1aa8..aa06f1e6 100644 --- a/include/Engine/Rendering/BlendTree.h +++ b/include/Engine/Rendering/BlendTree.h @@ -29,7 +29,7 @@ public: Node* Child[2] = { nullptr, nullptr }; NodeType Type; std::map Pose; - //std::vector Pose; + bool SubTreeRoot = false; double Weight = 0.0; Node* Next() { @@ -61,6 +61,7 @@ public: std::string NodeName; double progress; bool Start; + bool SingleBlend; std::unordered_map StartWeights; }; diff --git a/include/Engine/Rendering/EAutoAnimationBlend.h b/include/Engine/Rendering/EAutoAnimationBlend.h index 08c49191..ebd29848 100644 --- a/include/Engine/Rendering/EAutoAnimationBlend.h +++ b/include/Engine/Rendering/EAutoAnimationBlend.h @@ -17,6 +17,7 @@ struct AutoAnimationBlend : Event bool Start = false; bool Reverse = false; bool Restart = false; + bool SingleLevelBlend = false; EntityWrapper AnimationEntity = EntityWrapper::Invalid; }; diff --git a/resources/Schema/Components/Blend.xml b/resources/Schema/Components/Blend.xml index f949a102..a4a328ca 100644 --- a/resources/Schema/Components/Blend.xml +++ b/resources/Schema/Components/Blend.xml @@ -3,4 +3,5 @@ 0.5 + false \ No newline at end of file diff --git a/resources/Schema/Components/Blend.xsd b/resources/Schema/Components/Blend.xsd index 95fc8f49..34d32385 100644 --- a/resources/Schema/Components/Blend.xsd +++ b/resources/Schema/Components/Blend.xsd @@ -8,6 +8,7 @@ + diff --git a/resources/Schema/Entities/BlendTreeTest.xml b/resources/Schema/Entities/BlendTreeTest.xml index d2c7ead9..a3188348 100644 --- a/resources/Schema/Entities/BlendTreeTest.xml +++ b/resources/Schema/Entities/BlendTreeTest.xml @@ -68,8 +68,8 @@ Models/Weapons/Blue/AssaultWeaponBlue.mesh - - + + @@ -81,15 +81,16 @@ AimPrimary AimSecondary 0 + true - + - AimSecWepA - + AimRifleA + false true @@ -97,11 +98,11 @@ - + - AimRifleA - + AimSecWepA + false true @@ -125,7 +126,8 @@ StandCrouchBlend JumpDashBlend - 1.055110346338068e-57 + 2.5146881298480398e-63 + true @@ -135,7 +137,8 @@ StandMovement CrouchMovement - 0.0069837930620454403 + 0.012867419418159054 + true @@ -174,7 +177,7 @@ WalkF - + 1 true @@ -186,7 +189,7 @@ RunF - + 1 true @@ -210,7 +213,7 @@ StrafeLeftF - + 1 true @@ -222,7 +225,7 @@ StrafeRightF - + 1 true @@ -281,7 +284,7 @@ CrouchStrafeLeftF - + 1 true @@ -293,7 +296,7 @@ CrouchStrafeRightF - + 1 true @@ -307,7 +310,7 @@ CrouchWalkF - + 1 true @@ -338,6 +341,7 @@ Jump DashBlend 1 + true @@ -448,6 +452,7 @@ ReloadSwitch WeaponActionBlend 1 + true diff --git a/src/Engine/Rendering/AnimationSystem.cpp b/src/Engine/Rendering/AnimationSystem.cpp index 4434e80b..5c048fed 100644 --- a/src/Engine/Rendering/AnimationSystem.cpp +++ b/src/Engine/Rendering/AnimationSystem.cpp @@ -148,11 +148,11 @@ void AnimationSystem::UpdateWeights(double dt) bool AnimationSystem::OnAutoAnimationBlend(Events::AutoAnimationBlend& e) { - if(!e.RootNode.Valid()) { + if (!e.RootNode.Valid()) { return false; } - if(!e.RootNode.HasComponent("Model")) { + if (!e.RootNode.HasComponent("Model")) { return false; } @@ -179,7 +179,7 @@ bool AnimationSystem::OnAutoAnimationBlend(Events::AutoAnimationBlend& e) EntityWrapper subTreeRoot = blendTree->GetSubTreeRoot(e.NodeName); - if(!subTreeRoot.Valid()) { + if (!subTreeRoot.Valid()) { return false; } @@ -193,16 +193,18 @@ bool AnimationSystem::OnAutoAnimationBlend(Events::AutoAnimationBlend& e) abj.BlendInfo.NodeName = e.NodeName; abj.BlendInfo.progress = 0.0; abj.BlendInfo.Start = e.Start; + abj.BlendInfo.SingleBlend = e.SingleLevelBlend; - if (e.Restart) { - EntityWrapper nodeEntity = subTreeRoot.FirstChildByName(e.NodeName); - if (nodeEntity.Valid()) { - if (nodeEntity.HasComponent("Animation")) { - const Skeleton::Animation* animation = skeleton->GetAnimation(nodeEntity["Animation"]["AnimationName"]); + EntityWrapper nodeEntity = subTreeRoot.FirstChildByName(e.NodeName); // more than one + if (nodeEntity.Valid()) { + if (nodeEntity.HasComponent("Animation")) { + const Skeleton::Animation* animation = skeleton->GetAnimation(nodeEntity["Animation"]["AnimationName"]); + (bool&)nodeEntity["Animation"]["Reverse"] = e.Reverse; + + if (e.Restart) { if (animation != nullptr) { if (e.Restart) { - (bool&)nodeEntity["Animation"]["Reverse"] = e.Reverse; if (e.Reverse) { (double&)nodeEntity["Animation"]["Time"] = animation->Duration; } else { @@ -439,27 +441,7 @@ bool AnimationSystem::OnInputCommand(const Events::InputCommand& e) aeb.RootNode = entity; aeb.Start = true; aeb.Restart = true; - m_EventBroker->Publish(aeb); - } - } - } - } else if (e.Command == "Stand") { - auto blendComponents = m_World->GetComponents("BlendAdditive"); - - if (blendComponents == nullptr) { - return false; - } - for (auto& bc : *blendComponents) { - EntityWrapper entity = EntityWrapper(m_World, bc.EntityID); - - if (entity.Name() == "Assault") { - { - Events::AutoAnimationBlend aeb; - aeb.Duration = 0.3; - aeb.NodeName = "StandMovement"; - aeb.RootNode = entity; - aeb.Start = true; - aeb.Restart = true; + aeb.SingleLevelBlend = true; m_EventBroker->Publish(aeb); } } @@ -526,27 +508,15 @@ bool AnimationSystem::OnInputCommand(const Events::InputCommand& e) EntityWrapper entity = EntityWrapper(m_World, bc.EntityID); if (entity.Name() == "Assault") { - /* { + { Events::AutoAnimationBlend aeb; aeb.Duration = 0.1; aeb.NodeName = "Right"; aeb.RootNode = entity; aeb.Start = true; m_EventBroker->Publish(aeb); - }*/ - - - { - Events::AutoAnimationBlend aeb; - aeb.Duration = 0.3; - aeb.NodeName = "Right"; - aeb.RootNode = entity; - aeb.Start = true; - aeb.Restart = false; - aeb.AnimationEntity = entity.FirstChildByName("DashRight"); - aeb.Delay = -0.3; - m_EventBroker->Publish(aeb); } + } } } else if (e.Command == "ForwardTest") { @@ -570,8 +540,51 @@ bool AnimationSystem::OnInputCommand(const Events::InputCommand& e) } } } + } else if (e.Command == "BackwardTest") { + auto blendComponents = m_World->GetComponents("BlendAdditive"); + if (blendComponents == nullptr) { + return false; + } + for (auto& bc : *blendComponents) { + EntityWrapper entity = EntityWrapper(m_World, bc.EntityID); + if (entity.Name() == "Assault") { + { + Events::AutoAnimationBlend aeb; + aeb.Duration = 0.1; + aeb.NodeName = "Walk"; + aeb.RootNode = entity; + aeb.Start = true; + aeb.Reverse = true; + m_EventBroker->Publish(aeb); + } + } + } + } else if (e.Value == 0.f) { + if (e.Command == "Crouch") { + auto blendComponents = m_World->GetComponents("BlendAdditive"); + + if (blendComponents == nullptr) { + return false; + } + for (auto& bc : *blendComponents) { + EntityWrapper entity = EntityWrapper(m_World, bc.EntityID); + + if (entity.Name() == "Assault") { + { + Events::AutoAnimationBlend aeb; + aeb.Duration = 0.3; + aeb.NodeName = "StandMovement"; + aeb.RootNode = entity; + aeb.Start = true; + aeb.Restart = true; + aeb.SingleLevelBlend = true; + m_EventBroker->Publish(aeb); + } + } + } + } } } diff --git a/src/Engine/Rendering/AutoBlendQueue.cpp b/src/Engine/Rendering/AutoBlendQueue.cpp index e75e33b5..7ea79383 100644 --- a/src/Engine/Rendering/AutoBlendQueue.cpp +++ b/src/Engine/Rendering/AutoBlendQueue.cpp @@ -54,6 +54,11 @@ void AutoBlendQueue::Insert(AutoBlendJob autoBlendJob) for (auto it = m_BlendQueue.begin(); it != m_BlendQueue.end(); it++) { auto next = std::next(it, 1); + + if (it->BlendJob.BlendInfo.NodeName == autoBlendJob.BlendInfo.NodeName) { + (*it) = blendNode; + } + if (next != m_BlendQueue.end()) { if (it->StartTime >= blendNode.StartTime && next->StartTime <= blendNode.StartTime) { LOG_INFO("Inserted %s between %s and %s", blendNode.BlendJob.BlendInfo.NodeName.c_str(), it->BlendJob.BlendInfo.NodeName.c_str(), next->BlendJob.BlendInfo.NodeName.c_str()); @@ -83,11 +88,11 @@ void AutoBlendQueue::Insert(AutoBlendJob autoBlendJob) void AutoBlendQueue::UpdateTime(double dt) { for (auto it = m_BlendQueue.begin(); it != m_BlendQueue.end();) { - it->EndTime -= dt; - it->StartTime -= dt; if (it->EndTime <= 0) { it = m_BlendQueue.erase(it); } else { + it->EndTime -= dt; + it->StartTime -= dt; it++; } } diff --git a/src/Engine/Rendering/BlendTree.cpp b/src/Engine/Rendering/BlendTree.cpp index 2f74b45e..60858f2a 100644 --- a/src/Engine/Rendering/BlendTree.cpp +++ b/src/Engine/Rendering/BlendTree.cpp @@ -27,6 +27,7 @@ BlendTree::BlendTree(EntityWrapper ModelEntity, Skeleton* skeleton) m_Root->Parent = nullptr; m_Root->Type = NodeType::Blend; m_Root->Weight = (double)ModelEntity["Blend"]["Weight"]; + m_Root->SubTreeRoot = (bool)ModelEntity["Blend"]["SubTreeRoot"]; (double&)ModelEntity["Blend"]["Weight"] = glm::clamp((double)ModelEntity["Blend"]["Weight"], 0.0, 1.0); m_Root->Child[0] = FillTreeByName(m_Root, (std::string)ModelEntity["Blend"]["Pose1"], ModelEntity); m_Root->Child[1] = FillTreeByName(m_Root, (std::string)ModelEntity["Blend"]["Pose2"], ModelEntity); @@ -132,6 +133,7 @@ BlendTree::Node* BlendTree::FillTreeByName(Node* parentNode, std::string name, E node->Type = NodeType::Blend; (double&)childEntity["Blend"]["Weight"] = glm::clamp((double)childEntity["Blend"]["Weight"], 0.0, 1.0); node->Weight = (double)childEntity["Blend"]["Weight"]; + node->SubTreeRoot = (bool)childEntity["Blend"]["SubTreeRoot"]; //if (node->Weight < 1.f && node->Weight > 0.f) { node->Child[0] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose1"], childEntity); node->Child[1] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose2"], childEntity); @@ -251,6 +253,10 @@ BlendTree::AutoBlendInfo BlendTree::AutoBlendStep(AutoBlendInfo blendInfo) lastNode = currentNode; currentNode = currentNode->Parent; + + if (blendInfo.SingleBlend) { + break; + } } } else if(goalNodes.size() >= 2) { std::vector sharedParents; @@ -380,8 +386,8 @@ EntityWrapper BlendTree::GetSubTreeRoot(std::string nodeName) std::vector subTreeRoots; for (auto it = nodes.begin(); it != nodes.end(); it++) { - Node* currentNode = (*it); - while (currentNode->Parent->Type == NodeType::Blend) { + Node* currentNode = (*it)->Parent; + while (!currentNode->SubTreeRoot) { currentNode = currentNode->Parent; } subTreeRoots.push_back(currentNode); From bebdacabb4ee15da79b33ac3ea7c57f256c49751 Mon Sep 17 00:00:00 2001 From: viktorljung Date: Thu, 3 Mar 2016 23:41:08 +0100 Subject: [PATCH 130/130] Clean up --- include/Engine/Rendering/AnimationSystem.h | 5 - .../Schema/Entities/AssaultBlendTree.xml | 513 ++++++++++++++++++ resources/Schema/Entities/BlendTreeTest.xml | 42 +- src/Engine/Rendering/AnimationSystem.cpp | 373 ------------- src/Engine/Rendering/AutoBlendQueue.cpp | 5 - 5 files changed, 538 insertions(+), 400 deletions(-) create mode 100644 resources/Schema/Entities/AssaultBlendTree.xml diff --git a/include/Engine/Rendering/AnimationSystem.h b/include/Engine/Rendering/AnimationSystem.h index 4f18b4a4..a04aa3c5 100644 --- a/include/Engine/Rendering/AnimationSystem.h +++ b/include/Engine/Rendering/AnimationSystem.h @@ -10,7 +10,6 @@ #include "Rendering/Skeleton.h" #include "Rendering/BlendTree.h" #include "Rendering/EAutoAnimationBlend.h" -#include "../Input/EInputCommand.h" #include "../Core/EntityWrapper.h" #include "Rendering/AutoBlendQueue.h" @@ -30,10 +29,6 @@ private: EventRelay m_EAutoAnimationBlend; bool OnAutoAnimationBlend(Events::AutoAnimationBlend& e); - - EventRelay m_EInputCommand; - bool OnInputCommand(const Events::InputCommand& e); - std::unordered_map m_AutoBlendQueues; }; diff --git a/resources/Schema/Entities/AssaultBlendTree.xml b/resources/Schema/Entities/AssaultBlendTree.xml new file mode 100644 index 00000000..e8dcff8a --- /dev/null +++ b/resources/Schema/Entities/AssaultBlendTree.xml @@ -0,0 +1,513 @@ + + + + + + AimBlend + FinalBlend + + + 5 + Models/Characters/Assault/AssaultBlue.mesh + + + + + + + + + R_Arm_Weapon_Joint + + + Models/Weapons/Blue/AssaultWeaponBlue.mesh + + + + + + + + + + + + + AimPrimary + AimSecondary + 0 + true + + + + + + + + AimSecWepA + + false + true + + + + + + + + + AimRifleA + + false + true + + + + + + + + + + + ReloadSwitchBlend + MovementBlend + + + + + + + + StandCrouchBlend + JumpDashBlend + 2.5146881298480398e-63 + true + + + + + + + + StandMovement + CrouchMovement + 0.012867419418159054 + true + + + + + + + + MovementBlend + Idle + 1 + + + + + + + + RunWalkBlend + StrafeLRBlend + 2.4565650245976452e-16 + + + + + + + + Walk + Run + 1.2938206818383024e-24 + + + + + + + + WalkF + + 1 + true + + + + + + + + + RunF + + 1 + true + + + + + + + + + + + Left + Right + 0.033793529385008014 + + + + + + + + StrafeLeftF + + 1 + true + + + + + + + + + StrafeRightF + + 1 + true + + + + + + + + + + + + + IdleF + + 1 + true + + + + + + + + + + + MovementBlend + Idle + 0 + + + + + + + + Walk + StrafeLRBlend + 2.4565650245976452e-16 + + + + + + + + Left + Right + 0.033793529385008014 + + + + + + + + CrouchStrafeLeftF + + 1 + true + + + + + + + + + CrouchStrafeRightF + + 1 + true + + + + + + + + + + + CrouchWalkF + + 1 + true + + + + + + + + + + + CrouchF + + 1 + + + + + + + + + + + + + Jump + DashBlend + 1 + true + + + + + + + + JumpF + + 1 + false + + + + + + + + + DashFBBlend + DashLRBlend + 0.014621149736541383 + + + + + + + + DashForward + DashBackward + 0.014363533804961248 + + + + + + + + DashForwardF + + 1 + false + + + + + + + + + DashBackwardF + + 1 + false + + + + + + + + + + + DashLeft + DashRight + 4.3244885367500671e-16 + + + + + + + + DashLeftF + + 1 + false + + + + + + + + + DashRightF + + 1 + false + + + + + + + + + + + + + + + + + ReloadSwitch + WeaponActionBlend + 1 + true + + + + + + + + ReloadSwitchU + + 1 + + + + + + + + + IdleBlend + ShootBlend + 0 + + + + + + + + IdlePrimary + IdleSecondary + 0 + + + + + + + + IdleAssaultRifleU + + 1 + true + + + + + + + + + IdleSecWepU + + 1 + true + + + + + + + + + + + ShootPrimary + ShootSecondary + 0 + + + + + + + + ShootFastRifleU + + 1 + + + + + + + + + ShootSecWepFastU + + + + + + + + + + + + + + + + diff --git a/resources/Schema/Entities/BlendTreeTest.xml b/resources/Schema/Entities/BlendTreeTest.xml index a3188348..79e2e223 100644 --- a/resources/Schema/Entities/BlendTreeTest.xml +++ b/resources/Schema/Entities/BlendTreeTest.xml @@ -68,8 +68,8 @@ Models/Weapons/Blue/AssaultWeaponBlue.mesh - - + + @@ -86,11 +86,11 @@ - + - AimRifleA - + AimSecWepA + false true @@ -98,10 +98,10 @@ - + - AimSecWepA + AimRifleA false true @@ -148,7 +148,7 @@ MovementBlend Idle - 0 + 1 @@ -177,7 +177,7 @@ WalkF - + 1 true @@ -189,7 +189,7 @@ RunF - + 1 true @@ -213,7 +213,7 @@ StrafeLeftF - + 1 true @@ -225,7 +225,7 @@ StrafeRightF - + 1 true @@ -241,8 +241,9 @@ IdleF - + 1 + true @@ -284,7 +285,7 @@ CrouchStrafeLeftF - + 1 true @@ -296,7 +297,7 @@ CrouchStrafeRightF - + 1 true @@ -310,7 +311,7 @@ CrouchWalkF - + 1 true @@ -473,7 +474,7 @@ IdleBlend ShootBlend - 1 + 0 @@ -483,6 +484,7 @@ IdlePrimary IdleSecondary + 0 @@ -491,6 +493,9 @@ IdleAssaultRifleU + + 1 + true @@ -500,6 +505,9 @@ IdleSecWepU + + 1 + true diff --git a/src/Engine/Rendering/AnimationSystem.cpp b/src/Engine/Rendering/AnimationSystem.cpp index 5c048fed..99643997 100644 --- a/src/Engine/Rendering/AnimationSystem.cpp +++ b/src/Engine/Rendering/AnimationSystem.cpp @@ -4,7 +4,6 @@ AnimationSystem::AnimationSystem(SystemParams params) : System(params) { EVENT_SUBSCRIBE_MEMBER(m_EAutoAnimationBlend, &AnimationSystem::OnAutoAnimationBlend); - EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &AnimationSystem::OnInputCommand); } void AnimationSystem::Update(double dt) @@ -16,7 +15,6 @@ void AnimationSystem::Update(double dt) for(auto& autoBlendQueue : m_AutoBlendQueues) { autoBlendQueue.second.UpdateTime(dt); - // autoBlendQueue.second.PrintQueue(); } } @@ -136,7 +134,6 @@ void AnimationSystem::UpdateWeights(double dt) if (blendTree != nullptr) { blendJob.BlendInfo.progress = glm::clamp(blendJob.CurrentTime / blendJob.Duration, 0.0, 1.0); - LOG_INFO("Progress: %f, %s", blendJob.BlendInfo.progress, blendJob.BlendInfo.NodeName.c_str()); blendJob.BlendInfo = blendTree->AutoBlendStep(blendJob.BlendInfo); } @@ -215,376 +212,6 @@ bool AnimationSystem::OnAutoAnimationBlend(Events::AutoAnimationBlend& e) } } } - - - LOG_INFO("Inserting %s blendJob into %s subtree", e.NodeName.c_str(), subTreeRoot.Name().c_str()); m_AutoBlendQueues[subTreeRoot].Insert(abj); - - LOG_INFO("\n"); - m_AutoBlendQueues.at(subTreeRoot).PrintQueue(); - LOG_INFO("\n"); - - return true; } - -bool AnimationSystem::OnInputCommand(const Events::InputCommand& e) -{ - - if (e.Value == 1.f) { - if(e.Command == "DashForward") { - auto blendComponents = m_World->GetComponents("BlendAdditive"); - - if (blendComponents == nullptr) { - return false; - } - for (auto& bc : *blendComponents) { - EntityWrapper entity = EntityWrapper(m_World, bc.EntityID); - - if (entity.Name() == "Assault") { - { - Events::AutoAnimationBlend aeb; - aeb.Duration = 0.2; - aeb.NodeName = "DashForward"; - aeb.RootNode = entity; - aeb.Restart = true; - aeb.Start = true; - m_EventBroker->Publish(aeb); - } - { - Events::AutoAnimationBlend aeb; - aeb.Duration = 0.3; - aeb.NodeName = "StandCrouchBlend"; - aeb.RootNode = entity; - aeb.Delay = -0.3; - aeb.Start = true; - aeb.Restart = false; - aeb.AnimationEntity = entity.FirstChildByName("DashForward"); - m_EventBroker->Publish(aeb); - } - } - } - - } else if (e.Command == "DashBackward") { - auto blendComponents = m_World->GetComponents("BlendAdditive"); - - if (blendComponents == nullptr) { - return false; - } - for (auto& bc : *blendComponents) { - EntityWrapper entity = EntityWrapper(m_World, bc.EntityID); - - if (entity.Name() == "Assault") { - { - Events::AutoAnimationBlend aeb; - aeb.Duration = 0.1; - aeb.NodeName = "DashBackward"; - aeb.RootNode = entity; - aeb.Restart = true; - aeb.Start = true; - m_EventBroker->Publish(aeb); - } - { - Events::AutoAnimationBlend aeb; - aeb.Duration = 0.3; - aeb.NodeName = "StandCrouchBlend"; - aeb.RootNode = entity; - aeb.Start = true; - aeb.Restart = false; - aeb.Delay = -0.3; - aeb.AnimationEntity = entity.FirstChildByName("DashBackward"); - m_EventBroker->Publish(aeb); - } - } - } - } else if (e.Command == "DashLeft") { - auto blendComponents = m_World->GetComponents("BlendAdditive"); - - if (blendComponents == nullptr) { - return false; - } - for (auto& bc : *blendComponents) { - EntityWrapper entity = EntityWrapper(m_World, bc.EntityID); - - if (entity.Name() == "Assault") { - { - Events::AutoAnimationBlend aeb; - aeb.Duration = 0.1; - aeb.NodeName = "DashLeft"; - aeb.RootNode = entity; - aeb.Restart = true; - aeb.Start = true; - m_EventBroker->Publish(aeb); - } - { - Events::AutoAnimationBlend aeb; - aeb.Duration = 0.3; - aeb.NodeName = "StandCrouchBlend"; - aeb.RootNode = entity; - aeb.Delay = -0.3; - aeb.Start = true; - aeb.Restart = false; - aeb.AnimationEntity = entity.FirstChildByName("DashLeft"); - m_EventBroker->Publish(aeb); - } - } - } - } else if (e.Command == "DashRight") { - auto blendComponents = m_World->GetComponents("BlendAdditive"); - - if (blendComponents == nullptr) { - return false; - } - for (auto& bc : *blendComponents) { - EntityWrapper entity = EntityWrapper(m_World, bc.EntityID); - - if (entity.Name() == "Assault") { - { - Events::AutoAnimationBlend aeb; - aeb.Duration = 0.1; - aeb.NodeName = "DashRight"; - aeb.RootNode = entity; - aeb.Restart = true; - aeb.Start = true; - m_EventBroker->Publish(aeb); - } - { - Events::AutoAnimationBlend aeb; - aeb.Duration = 0.3; - aeb.NodeName = "StandCrouchBlend"; - aeb.RootNode = entity; - aeb.Start = true; - aeb.Restart = false; - aeb.AnimationEntity = entity.FirstChildByName("DashRight"); - aeb.Delay = -0.3; - m_EventBroker->Publish(aeb); - } - } - } - } else if (e.Command == "Jump") { - auto blendComponents = m_World->GetComponents("BlendAdditive"); - - if (blendComponents == nullptr) { - return false; - } - for (auto& bc : *blendComponents) { - EntityWrapper entity = EntityWrapper(m_World, bc.EntityID); - - if (entity.Name() == "Assault") { - { - Events::AutoAnimationBlend aeb; - aeb.Duration = 0.25; - aeb.NodeName = "Jump"; - aeb.RootNode = entity; - aeb.Start = true; - aeb.Restart = true; - m_EventBroker->Publish(aeb); - } - { - Events::AutoAnimationBlend aeb; - aeb.Duration = 0.3; - aeb.NodeName = "StandCrouchBlend"; - aeb.RootNode = entity; - aeb.Start = true; - aeb.Restart = false; - aeb.AnimationEntity = entity.FirstChildByName("Jump"); - m_EventBroker->Publish(aeb); - } - } - } - } else if (e.Command == "Reload") { - auto blendComponents = m_World->GetComponents("BlendAdditive"); - - if (blendComponents == nullptr) { - return false; - } - for (auto& bc : *blendComponents) { - EntityWrapper entity = EntityWrapper(m_World, bc.EntityID); - - if (entity.Name() == "Assault") { - { - Events::AutoAnimationBlend aeb; - aeb.Duration = 0.2; - aeb.NodeName = "ReloadSwitch"; - aeb.RootNode = entity; - aeb.Start = true; - aeb.Restart = true; - m_EventBroker->Publish(aeb); - } - { - Events::AutoAnimationBlend aeb; - aeb.Duration = 0.2; - aeb.NodeName = "IdlePrimary"; - aeb.RootNode = entity; - aeb.Delay = -0.1; - aeb.Start = true; - aeb.Restart = false; - aeb.AnimationEntity = entity.FirstChildByName("ReloadSwitch"); - m_EventBroker->Publish(aeb); - } - } - } - } else if (e.Command == "Crouch") { - auto blendComponents = m_World->GetComponents("BlendAdditive"); - - if (blendComponents == nullptr) { - return false; - } - for (auto& bc : *blendComponents) { - EntityWrapper entity = EntityWrapper(m_World, bc.EntityID); - - if (entity.Name() == "Assault") { - { - Events::AutoAnimationBlend aeb; - aeb.Duration = 0.3; - aeb.NodeName = "CrouchMovement"; - aeb.RootNode = entity; - aeb.Start = true; - aeb.Restart = true; - aeb.SingleLevelBlend = true; - m_EventBroker->Publish(aeb); - } - } - } - } else if (e.Command == "Shoot") { - auto blendComponents = m_World->GetComponents("BlendAdditive"); - - if (blendComponents == nullptr) { - return false; - } - for (auto& bc : *blendComponents) { - EntityWrapper entity = EntityWrapper(m_World, bc.EntityID); - - if (entity.Name() == "Assault") { - { - Events::AutoAnimationBlend aeb; - aeb.Duration = 0.1; - aeb.NodeName = "ShootPrimary"; - aeb.RootNode = entity; - aeb.Start = true; - aeb.Restart = true; - m_EventBroker->Publish(aeb); - } - { - Events::AutoAnimationBlend aeb; - aeb.Duration = 0.1; - aeb.NodeName = "IdlePrimary"; - aeb.RootNode = entity; - aeb.Delay = 0.0; - aeb.Start = true; - aeb.Restart = false; - aeb.AnimationEntity = entity.FirstChildByName("ShootPrimary"); - m_EventBroker->Publish(aeb); - } - } - } - } else if (e.Command == "LeftTest") { - auto blendComponents = m_World->GetComponents("BlendAdditive"); - - if (blendComponents == nullptr) { - return false; - } - for (auto& bc : *blendComponents) { - EntityWrapper entity = EntityWrapper(m_World, bc.EntityID); - - if (entity.Name() == "Assault") { - { - Events::AutoAnimationBlend aeb; - aeb.Duration = 0.1; - aeb.NodeName = "Left"; - aeb.RootNode = entity; - aeb.Start = true; - m_EventBroker->Publish(aeb); - } - } - } - } else if (e.Command == "RightTest") { - auto blendComponents = m_World->GetComponents("BlendAdditive"); - - if (blendComponents == nullptr) { - return false; - } - for (auto& bc : *blendComponents) { - EntityWrapper entity = EntityWrapper(m_World, bc.EntityID); - - if (entity.Name() == "Assault") { - { - Events::AutoAnimationBlend aeb; - aeb.Duration = 0.1; - aeb.NodeName = "Right"; - aeb.RootNode = entity; - aeb.Start = true; - m_EventBroker->Publish(aeb); - } - - } - } - } else if (e.Command == "ForwardTest") { - auto blendComponents = m_World->GetComponents("BlendAdditive"); - - if (blendComponents == nullptr) { - return false; - } - for (auto& bc : *blendComponents) { - EntityWrapper entity = EntityWrapper(m_World, bc.EntityID); - - if (entity.Name() == "Assault") { - { - Events::AutoAnimationBlend aeb; - aeb.Duration = 0.1; - aeb.NodeName = "Walk"; - aeb.RootNode = entity; - aeb.Start = true; - m_EventBroker->Publish(aeb); - } - } - } - } - } else if (e.Command == "BackwardTest") { - auto blendComponents = m_World->GetComponents("BlendAdditive"); - - if (blendComponents == nullptr) { - return false; - } - for (auto& bc : *blendComponents) { - EntityWrapper entity = EntityWrapper(m_World, bc.EntityID); - - if (entity.Name() == "Assault") { - { - Events::AutoAnimationBlend aeb; - aeb.Duration = 0.1; - aeb.NodeName = "Walk"; - aeb.RootNode = entity; - aeb.Start = true; - aeb.Reverse = true; - m_EventBroker->Publish(aeb); - } - } - } - } else if (e.Value == 0.f) { - if (e.Command == "Crouch") { - auto blendComponents = m_World->GetComponents("BlendAdditive"); - - if (blendComponents == nullptr) { - return false; - } - for (auto& bc : *blendComponents) { - EntityWrapper entity = EntityWrapper(m_World, bc.EntityID); - - if (entity.Name() == "Assault") { - { - Events::AutoAnimationBlend aeb; - aeb.Duration = 0.3; - aeb.NodeName = "StandMovement"; - aeb.RootNode = entity; - aeb.Start = true; - aeb.Restart = true; - aeb.SingleLevelBlend = true; - m_EventBroker->Publish(aeb); - } - } - } - } - } -} - diff --git a/src/Engine/Rendering/AutoBlendQueue.cpp b/src/Engine/Rendering/AutoBlendQueue.cpp index 7ea79383..cafb7ee5 100644 --- a/src/Engine/Rendering/AutoBlendQueue.cpp +++ b/src/Engine/Rendering/AutoBlendQueue.cpp @@ -45,7 +45,6 @@ void AutoBlendQueue::Insert(AutoBlendJob autoBlendJob) AnimationDuration = (animation->Duration * animationSpeed) - animationTime; } - LOG_INFO("Animation Duration %f", AnimationDuration); blendNode.StartTime += AnimationDuration; blendNode.EndTime += AnimationDuration; if (m_BlendQueue.size() == 0) { @@ -61,16 +60,13 @@ void AutoBlendQueue::Insert(AutoBlendJob autoBlendJob) if (next != m_BlendQueue.end()) { if (it->StartTime >= blendNode.StartTime && next->StartTime <= blendNode.StartTime) { - LOG_INFO("Inserted %s between %s and %s", blendNode.BlendJob.BlendInfo.NodeName.c_str(), it->BlendJob.BlendInfo.NodeName.c_str(), next->BlendJob.BlendInfo.NodeName.c_str()); m_BlendQueue.insert(next, blendNode); return; } } else if(it->StartTime > blendNode.StartTime){ - LOG_INFO("Inserted %s after %s", blendNode.BlendJob.BlendInfo.NodeName.c_str(), it->BlendJob.BlendInfo.NodeName.c_str()); m_BlendQueue.push_front(blendNode); return; } else if (it->StartTime <= blendNode.StartTime) { - LOG_INFO("Inserted %s after %s", blendNode.BlendJob.BlendInfo.NodeName.c_str(), it->BlendJob.BlendInfo.NodeName.c_str()); m_BlendQueue.push_back(blendNode); return; } @@ -80,7 +76,6 @@ void AutoBlendQueue::Insert(AutoBlendJob autoBlendJob) } - LOG_INFO("Cleared BlendQueue and inserted %s", blendNode.BlendJob.BlendInfo.NodeName.c_str()); m_BlendQueue.clear(); m_BlendQueue.push_back(blendNode); }