From 9581e9ac84ce6ff1d3a4bb8faa2f4f5178b3dfea Mon Sep 17 00:00:00 2001 From: William Moberg Date: Wed, 9 Mar 2016 17:51:26 +0100 Subject: [PATCH 01/24] Don't set the player to previous position when uncrouching. --- include/Engine/Input/FirstPersonInputController.h | 3 +++ resources/Schema/Components/Collidable.xml | 1 + resources/Schema/Components/Collidable.xsd | 5 +++++ src/Engine/Collision/CollisionSystem.cpp | 5 +++-- src/Game/Systems/PlayerMovementSystem.cpp | 9 +++++++++ 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/include/Engine/Input/FirstPersonInputController.h b/include/Engine/Input/FirstPersonInputController.h index 00f36ac7..f91db610 100644 --- a/include/Engine/Input/FirstPersonInputController.h +++ b/include/Engine/Input/FirstPersonInputController.h @@ -18,6 +18,7 @@ public: virtual const glm::vec3 Rotation() const { return m_Rotation; } virtual bool Jumping() const { return m_Jumping; } virtual bool Crouching() const { return m_Crouching; } + virtual bool CrouchingLastFrame() const { return m_CrouchingLastFrame; } virtual bool DoubleJumping() const { return m_DoubleJumping; } virtual void SetDoubleJumping(bool isDoubleJumping) { m_DoubleJumping = isDoubleJumping; @@ -43,6 +44,7 @@ protected: bool m_Jumping = false; bool m_DoubleJumping = false; bool m_Crouching = false; + bool m_CrouchingLastFrame = false; //assault dash membervariables - needed to calculate the doubletap- and dashlogic double m_AssaultDashDoubleTapDeltaTime = 0.0; double m_DashEffectResetTimer = 0.0; @@ -82,6 +84,7 @@ void FirstPersonInputController::Reset() { m_Rotation = glm::vec3(0.f, 0.f, 0.f); m_Jumping = false; + m_CrouchingLastFrame = m_Crouching; } template diff --git a/resources/Schema/Components/Collidable.xml b/resources/Schema/Components/Collidable.xml index 9046ea99..7bd60939 100644 --- a/resources/Schema/Components/Collidable.xml +++ b/resources/Schema/Components/Collidable.xml @@ -1,3 +1,4 @@ + true \ No newline at end of file diff --git a/resources/Schema/Components/Collidable.xsd b/resources/Schema/Components/Collidable.xsd index 93f7ac24..2dd49a20 100644 --- a/resources/Schema/Components/Collidable.xsd +++ b/resources/Schema/Components/Collidable.xsd @@ -7,5 +7,10 @@ Needs a Model or AABB component to work, uses AABB if both are attached. + + + + + \ No newline at end of file diff --git a/src/Engine/Collision/CollisionSystem.cpp b/src/Engine/Collision/CollisionSystem.cpp index 53cabfac..8333a9ae 100644 --- a/src/Engine/Collision/CollisionSystem.cpp +++ b/src/Engine/Collision/CollisionSystem.cpp @@ -66,7 +66,7 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c } } } - + bool& jitterGuard = (bool&)entity["Collidable"]["JitterGuard"]; // Collide against octree items m_OctreeResult.clear(); m_Octree->ObjectsInSameRegion(*boundingBox, m_OctreeResult); @@ -93,7 +93,7 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c 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::vec3&)cTransform["Position"] += jitterGuard && notMovingxz ? prevPosIt->second - boxA.Origin() : resolutionVector; boxA = *Collision::EntityAbsoluteAABB(entity); cPhysics["Velocity"] = inOutVelocity; if (isOnGround) { @@ -118,6 +118,7 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c (bool)cPhysics["IsOnGround"] = false; } + jitterGuard = true; m_PrevPositions[entity] = boxA.Origin(); } } diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index b927856a..b0ad37ea 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -273,6 +273,15 @@ void PlayerMovementSystem::updateMovementControllers(double dt) size = glm::vec3(1.f, 1.f, 1.f); } else { size = glm::vec3(1.f, 1.6f, 1.f); + if (controller->CrouchingLastFrame() && player.HasComponent("Collidable")) { + // Disable jitter guard so player doesn't get stuck in the ground. + (bool&)player["Collidable"]["JitterGuard"] = false; + if (isOnGround) { + // The collision should resolve this anyway, but + // this is more reliable, since the box gets larger. + ((glm::vec3&)cTransform["Position"]).y += 0.3f; + } + } } } From 90b2c702157adc03f20ece999b7e03c469c6e9d6 Mon Sep 17 00:00:00 2001 From: Tleety Date: Wed, 9 Mar 2016 19:12:06 +0100 Subject: [PATCH 02/24] Some sprite fixes --- src/Engine/Rendering/BlurHUD.cpp | 10 +++++++--- src/Engine/Rendering/DrawFinalPass.cpp | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Engine/Rendering/BlurHUD.cpp b/src/Engine/Rendering/BlurHUD.cpp index 8fdb7f1a..d9af3085 100644 --- a/src/Engine/Rendering/BlurHUD.cpp +++ b/src/Engine/Rendering/BlurHUD.cpp @@ -97,14 +97,14 @@ void BlurHUD::ClearBuffer() glClearStencil(0x00); glStencilMask(~0); glDisable(GL_SCISSOR_TEST); - glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_GaussianFrameBuffer_horiz.Unbind(); m_GaussianFrameBuffer_vert.Bind(); glClearColor(0.f, 0.f, 0.f, 0.f); glClearStencil(0x00); glStencilMask(~0); glDisable(GL_SCISSOR_TEST); - glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_GaussianFrameBuffer_vert.Unbind(); m_CombinedTextureBuffer.Bind(); @@ -211,12 +211,16 @@ void BlurHUD::FillStencil(RenderScene& scene) RenderState state; state.BindFramebuffer(m_GaussianFrameBuffer_horiz.GetHandle()); - state.Disable(GL_DEPTH_TEST); + state.Enable(GL_DEPTH_TEST); state.Enable(GL_CULL_FACE); state.Enable(GL_STENCIL_TEST); state.StencilFunc(GL_ALWAYS, 1, 0xFF); state.StencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); state.StencilMask(0xFF); + + state.AlphaFunc(GL_GEQUAL, 0.95f); + state.Enable(GL_ALPHA_TEST); + glViewport(0, 0, m_Renderer->GetViewportSize().Width/m_BlurQuality, m_Renderer->GetViewportSize().Height/m_BlurQuality); m_FillDepthStencilProgram->Bind(); diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index dce4ea05..c57ff1c9 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -302,6 +302,8 @@ void DrawFinalPass::Draw(RenderScene& scene, BlurHUD* blurHUDPass) GLERROR("TransparentObjects"); //state->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); stateSprite->Enable(GL_DEPTH_TEST); + stateSprite->AlphaFunc(GL_GEQUAL, 0.05f); + stateSprite->Enable(GL_ALPHA_TEST); DrawSprites(scene.Jobs.SpriteJob, scene); GLERROR("SpriteJobs"); From 8936b3d6c3af82f8f2f0b018fb550048d274e84b Mon Sep 17 00:00:00 2001 From: William Moberg Date: Wed, 9 Mar 2016 19:45:26 +0100 Subject: [PATCH 03/24] Probably fixed all the jittering, won't need the jitter guard anymore. --- resources/Schema/Components/Collidable.xml | 1 - resources/Schema/Components/Collidable.xsd | 5 ----- src/Engine/Collision/Collision.cpp | 1 + src/Engine/Collision/CollisionSystem.cpp | 6 ++---- src/Game/Systems/PlayerMovementSystem.cpp | 12 ++++-------- 5 files changed, 7 insertions(+), 18 deletions(-) diff --git a/resources/Schema/Components/Collidable.xml b/resources/Schema/Components/Collidable.xml index 7bd60939..9046ea99 100644 --- a/resources/Schema/Components/Collidable.xml +++ b/resources/Schema/Components/Collidable.xml @@ -1,4 +1,3 @@ - true \ No newline at end of file diff --git a/resources/Schema/Components/Collidable.xsd b/resources/Schema/Components/Collidable.xsd index 2dd49a20..93f7ac24 100644 --- a/resources/Schema/Components/Collidable.xsd +++ b/resources/Schema/Components/Collidable.xsd @@ -7,10 +7,5 @@ Needs a Model or AABB component to work, uses AABB if both are attached. - - - - - \ No newline at end of file diff --git a/src/Engine/Collision/Collision.cpp b/src/Engine/Collision/Collision.cpp index 68d99d92..31768efd 100644 --- a/src/Engine/Collision/Collision.cpp +++ b/src/Engine/Collision/Collision.cpp @@ -470,6 +470,7 @@ bool AABBvsTriangle(const AABB& box, } glm::vec3 cornerResolution = (1+t) * diagonal; + cornerResolution = glm::dot(cornerResolution, triNormal) * triNormal; //Overwrite the smallest resolution if cornerResolution is smaller. float lenSq = glm::length2(cornerResolution); if (lenSq < resolveShortest.DistanceSq) { diff --git a/src/Engine/Collision/CollisionSystem.cpp b/src/Engine/Collision/CollisionSystem.cpp index 8333a9ae..1c52209f 100644 --- a/src/Engine/Collision/CollisionSystem.cpp +++ b/src/Engine/Collision/CollisionSystem.cpp @@ -66,7 +66,7 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c } } } - bool& jitterGuard = (bool&)entity["Collidable"]["JitterGuard"]; + // Collide against octree items m_OctreeResult.clear(); m_Octree->ObjectsInSameRegion(*boundingBox, m_OctreeResult); @@ -88,12 +88,11 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c 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"] += jitterGuard && notMovingxz ? prevPosIt->second - boxA.Origin() : resolutionVector; + (glm::vec3&)cTransform["Position"] += resolutionVector; boxA = *Collision::EntityAbsoluteAABB(entity); cPhysics["Velocity"] = inOutVelocity; if (isOnGround) { @@ -118,7 +117,6 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c (bool)cPhysics["IsOnGround"] = false; } - jitterGuard = true; m_PrevPositions[entity] = boxA.Origin(); } } diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index b0ad37ea..743a8af2 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -273,14 +273,10 @@ void PlayerMovementSystem::updateMovementControllers(double dt) size = glm::vec3(1.f, 1.f, 1.f); } else { size = glm::vec3(1.f, 1.6f, 1.f); - if (controller->CrouchingLastFrame() && player.HasComponent("Collidable")) { - // Disable jitter guard so player doesn't get stuck in the ground. - (bool&)player["Collidable"]["JitterGuard"] = false; - if (isOnGround) { - // The collision should resolve this anyway, but - // this is more reliable, since the box gets larger. - ((glm::vec3&)cTransform["Position"]).y += 0.3f; - } + if (controller->CrouchingLastFrame() && isOnGround) { + // The collision should resolve this anyway, but + // this is more reliable, since the box gets larger. + ((glm::vec3&)cTransform["Position"]).y += 0.3f; } } } From 087facc22ebe4e0d8713f408d3b37b6a08a36936 Mon Sep 17 00:00:00 2001 From: Tleety Date: Wed, 9 Mar 2016 22:22:32 +0100 Subject: [PATCH 04/24] Textures are now able to keep their scale even though the sprite is scaled. --- include/Engine/Rendering/SpriteJob.h | 9 +++++++++ resources/Schema/Components/Sprite.xml | 2 ++ resources/Schema/Components/Sprite.xsd | 6 ++++++ resources/Shaders/Sprite.frag.glsl | 13 ++++++++----- src/Engine/Rendering/DrawFinalPass.cpp | 2 ++ src/Engine/Rendering/TextureSprite.cpp | 4 ++-- 6 files changed, 29 insertions(+), 7 deletions(-) diff --git a/include/Engine/Rendering/SpriteJob.h b/include/Engine/Rendering/SpriteJob.h index c323fa06..596e37f2 100644 --- a/include/Engine/Rendering/SpriteJob.h +++ b/include/Engine/Rendering/SpriteJob.h @@ -48,6 +48,13 @@ struct SpriteJob : RenderJob FillColor = fillColor; FillPercentage = fillPercentage; + + if((bool)cSprite["KeepRatioX"] == true) { + ScaleX = Transform::AbsoluteScale(world, cSprite.EntityID).x; + } + if ((bool)cSprite["KeepRatioZ"] == true) { + ScaleY = Transform::AbsoluteScale(world, cSprite.EntityID).y; + } }; unsigned int TextureID; @@ -69,6 +76,8 @@ struct SpriteJob : RenderJob bool Pickable; bool IsIndicator = false; bool BlurBackground = false; + float ScaleX = 1; + float ScaleY = 1; glm::vec4 FillColor = glm::vec4(0); float FillPercentage = 0.0; diff --git a/resources/Schema/Components/Sprite.xml b/resources/Schema/Components/Sprite.xml index e577ac96..19cd1313 100644 --- a/resources/Schema/Components/Sprite.xml +++ b/resources/Schema/Components/Sprite.xml @@ -5,5 +5,7 @@ true true + false + false false diff --git a/resources/Schema/Components/Sprite.xsd b/resources/Schema/Components/Sprite.xsd index e26d71c9..e727040c 100644 --- a/resources/Schema/Components/Sprite.xsd +++ b/resources/Schema/Components/Sprite.xsd @@ -24,6 +24,12 @@ Whether the sprite should be sorted with depth or not. Only use false for textures that are on HUD + + Wether the sprite should repeat in x instead of stretch when scaled. + + + Wether the sprite should repeat in y instead of stretch when scaled. + Wether the background should be blurred begind this sprite. diff --git a/resources/Shaders/Sprite.frag.glsl b/resources/Shaders/Sprite.frag.glsl index abad7df1..5b6567eb 100644 --- a/resources/Shaders/Sprite.frag.glsl +++ b/resources/Shaders/Sprite.frag.glsl @@ -3,6 +3,8 @@ uniform vec4 Color; uniform vec4 FillColor; uniform float FillPercentage; +uniform float ScaleX; +uniform float ScaleY; uniform mat4 P; layout (binding = 1) uniform sampler2D DiffuseTexture; @@ -21,15 +23,16 @@ out vec4 bloomColor; void main() { - vec4 diffuseTexel = texture2D(DiffuseTexture, Input.TextureCoordinate); - vec4 glowTexel = texture2D(GlowMapTexture, Input.TextureCoordinate); + vec4 diffuseTexel = texture2D(DiffuseTexture, vec2(Input.TextureCoordinate.x*ScaleX, Input.TextureCoordinate.y*ScaleY)); + vec4 glowTexel = texture2D(GlowMapTexture, vec2(Input.TextureCoordinate.x*ScaleX, Input.TextureCoordinate.y*ScaleY)); 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; - } + float fillResult = floor(pos*FillPercentage); + + color_result = FillColor*diffuseTexel.a*fillResult + color_result*(1-fillResult); + sceneColor = vec4(color_result.xyz, clamp(color_result.a, 0, 1)); //bloomColor = vec4(clamp((glowTexel.xyz*3) - 1.0, 0, 100), 1.0); diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index 81afd852..62ce846d 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -1284,6 +1284,8 @@ void DrawFinalPass::DrawSprites(std::list>&jobs, Rend glUniform4fv(glGetUniformLocation(shaderHandle, "Color"), 1, glm::value_ptr(spriteJob->Color)); glUniform4fv(glGetUniformLocation(shaderHandle, "FillColor"), 1, glm::value_ptr(spriteJob->FillColor)); glUniform1f(glGetUniformLocation(shaderHandle, "FillPercentage"), spriteJob->FillPercentage); + glUniform1f(glGetUniformLocation(shaderHandle, "ScaleX"), spriteJob->ScaleX); + glUniform1f(glGetUniformLocation(shaderHandle, "ScaleY"), spriteJob->ScaleY); glActiveTexture(GL_TEXTURE1); if (spriteJob->DiffuseTexture != nullptr) { diff --git a/src/Engine/Rendering/TextureSprite.cpp b/src/Engine/Rendering/TextureSprite.cpp index 178aebf0..2a43e455 100644 --- a/src/Engine/Rendering/TextureSprite.cpp +++ b/src/Engine/Rendering/TextureSprite.cpp @@ -3,8 +3,8 @@ TextureSprite::TextureSprite(std::string path) :Texture(path) { - 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_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST_MIPMAP_NEAREST); GLERROR("Texture load"); From 592edf7dba7a031c892892c8848c00d20b7853d7 Mon Sep 17 00:00:00 2001 From: Tleety Date: Wed, 9 Mar 2016 23:31:54 +0100 Subject: [PATCH 05/24] Sprites can now be rendered with the texture ratio in mind --- assets | 2 +- include/Engine/Rendering/SpriteJob.h | 17 ++++++++++++++--- resources/Schema/Components/Sprite.xml | 1 + resources/Schema/Components/Sprite.xsd | 3 +++ src/Engine/Rendering/DrawFinalPass.cpp | 4 ++-- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/assets b/assets index 3af64d8b..85d96f6f 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 3af64d8b1f8cdf3e20198b079dfc02f6d64fdc88 +Subproject commit 85d96f6f3d2269e46962492f9713ec67c54e8ece diff --git a/include/Engine/Rendering/SpriteJob.h b/include/Engine/Rendering/SpriteJob.h index 596e37f2..6b52144f 100644 --- a/include/Engine/Rendering/SpriteJob.h +++ b/include/Engine/Rendering/SpriteJob.h @@ -49,11 +49,22 @@ struct SpriteJob : RenderJob FillColor = fillColor; FillPercentage = fillPercentage; + glm::vec3 scale = Transform::AbsoluteScale(world, cSprite.EntityID); + if((bool)cSprite["KeepRatioX"] == true) { - ScaleX = Transform::AbsoluteScale(world, cSprite.EntityID).x; + ScaleX = scale.x; } - if ((bool)cSprite["KeepRatioZ"] == true) { - ScaleY = Transform::AbsoluteScale(world, cSprite.EntityID).y; + if ((bool)cSprite["KeepRatioY"] == true) { + ScaleY = scale.y; + } + if((bool)cSprite["KeepRatio"] == true) { + if(scale.y >= scale.x) { + ScaleY = (scale.x)/(scale.y); + ScaleX = 1; + } else { + ScaleY = 1; + ScaleX = (scale.x)/(scale.y); + } } }; diff --git a/resources/Schema/Components/Sprite.xml b/resources/Schema/Components/Sprite.xml index 19cd1313..2c0465e9 100644 --- a/resources/Schema/Components/Sprite.xml +++ b/resources/Schema/Components/Sprite.xml @@ -7,5 +7,6 @@ true false false + false false diff --git a/resources/Schema/Components/Sprite.xsd b/resources/Schema/Components/Sprite.xsd index e727040c..eab74bfc 100644 --- a/resources/Schema/Components/Sprite.xsd +++ b/resources/Schema/Components/Sprite.xsd @@ -30,6 +30,9 @@ Wether the sprite should repeat in y instead of stretch when scaled. + + Keep a 1:1 ratio between X and Y. + Wether the background should be blurred begind this sprite. diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index 62ce846d..c5b8c591 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -311,8 +311,8 @@ void DrawFinalPass::Draw(RenderScene& scene, BlurHUD* blurHUDPass) GLERROR("TransparentObjects"); //state->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); stateSprite->Enable(GL_DEPTH_TEST); - stateSprite->AlphaFunc(GL_GEQUAL, 0.05f); - stateSprite->Enable(GL_ALPHA_TEST); + //stateSprite->AlphaFunc(GL_GEQUAL, 0.05f); + //stateSprite->Enable(GL_ALPHA_TEST); DrawSprites(scene.Jobs.SpriteJob, scene); GLERROR("SpriteJobs"); From a2244e87ad74b63b4c45f60cd6d99081125b3678 Mon Sep 17 00:00:00 2001 From: Tleety Date: Thu, 10 Mar 2016 12:18:06 +0100 Subject: [PATCH 06/24] WIP, trying to get blur to work with mipmaps --- include/Engine/Rendering/DrawBloomPass.h | 6 +- include/Engine/Rendering/FrameBuffer.h | 15 ++- resources/Shaders/Gaussian_horiz.frag.glsl | 5 +- resources/Shaders/Gaussian_vert.frag.glsl | 5 +- src/Engine/Rendering/DrawBloomPass.cpp | 120 ++++++++++++------ src/Engine/Rendering/FrameBuffer.cpp | 5 +- src/Engine/Rendering/Util/CommonFunctions.cpp | 3 +- 7 files changed, 106 insertions(+), 53 deletions(-) diff --git a/include/Engine/Rendering/DrawBloomPass.h b/include/Engine/Rendering/DrawBloomPass.h index e6a87c11..204f97d1 100644 --- a/include/Engine/Rendering/DrawBloomPass.h +++ b/include/Engine/Rendering/DrawBloomPass.h @@ -39,6 +39,7 @@ public: private: + void GaussianLodPass(GLuint mipMap, GLuint texture); Texture* m_BlackTexture; Model* m_ScreenQuad; @@ -47,12 +48,13 @@ private: //const LightCullingPass* m_LightCullingPass int m_Iterations; int m_Quality = 0; + int m_BloomLod = 4; GLuint m_GaussianTexture_horiz = 0; GLuint m_GaussianTexture_vert = 0; - FrameBuffer m_GaussianFrameBuffer_horiz; - FrameBuffer m_GaussianFrameBuffer_vert; + FrameBuffer* m_GaussianFrameBuffer_horiz = nullptr; + FrameBuffer* m_GaussianFrameBuffer_vert = nullptr; ShaderProgram* m_GaussianProgram_horiz; ShaderProgram* m_GaussianProgram_vert; diff --git a/include/Engine/Rendering/FrameBuffer.h b/include/Engine/Rendering/FrameBuffer.h index e9171894..1b4f6012 100644 --- a/include/Engine/Rendering/FrameBuffer.h +++ b/include/Engine/Rendering/FrameBuffer.h @@ -7,11 +7,12 @@ class BufferResource { public: - BufferResource(GLuint* resourceHandle, GLenum resourceType, GLenum attachment); + BufferResource(GLuint* resourceHandle, GLenum resourceType, GLenum attachment, GLuint mipMapLod); GLuint* m_ResourceHandle; GLenum m_ResourceType; GLenum m_Attachment; + GLuint m_MipMapLod = 0; private: }; @@ -20,15 +21,15 @@ template class ResourceType : public BufferResource { public: - ResourceType(GLuint* resourceHandle, GLenum attachment) - : BufferResource(resourceHandle, RESOURCETYPE, attachment) { } + ResourceType(GLuint* resourceHandle, GLenum attachment, GLuint mipMapLod) + : BufferResource(resourceHandle, RESOURCETYPE, attachment, mipMapLod) { } }; class Texture2D : public ResourceType { public: - Texture2D(GLuint* resourceHandle, GLenum attachment) - : ResourceType(resourceHandle, attachment) { }; + Texture2D(GLuint* resourceHandle, GLenum attachment, GLuint mipMapLod = 0) + : ResourceType(resourceHandle, attachment, mipMapLod) { }; ~Texture2D(); }; @@ -37,7 +38,7 @@ class RenderBuffer : public ResourceType { public: RenderBuffer(GLuint* resourceHandle, GLenum attachment) - : ResourceType(resourceHandle, attachment) + : ResourceType(resourceHandle, attachment, 0) { }; ~RenderBuffer(); @@ -47,7 +48,7 @@ class Texture2DArray : public ResourceType { public: Texture2DArray(GLuint* resourceHandle, GLenum attachment) - : ResourceType(resourceHandle, attachment) + : ResourceType(resourceHandle, attachment, 0) { }; ~Texture2DArray(); diff --git a/resources/Shaders/Gaussian_horiz.frag.glsl b/resources/Shaders/Gaussian_horiz.frag.glsl index 8a306ec2..06426ed3 100644 --- a/resources/Shaders/Gaussian_horiz.frag.glsl +++ b/resources/Shaders/Gaussian_horiz.frag.glsl @@ -2,6 +2,7 @@ #extension GL_EXT_gpu_shader4 : enable layout (binding = 0) uniform sampler2D Texture; +uniform int Lod; in VertexData{ vec2 TextureCoordinate; @@ -10,12 +11,14 @@ in VertexData{ out vec4 fragmentColor; uniform float weight[5] = float[](0.227027, 0.1945946, 0.1216216, 0.054054, 0.016216); +//uniform float weight[3] = float[](0.265495, 0.226535, 0.140718); void main() { - vec2 tex_offset = 1.0 / textureSize2D(Texture, 0); + vec2 tex_offset = 1.0 / textureSize(Texture, Lod); vec3 center = texture(Texture, Input.TextureCoordinate).rgb; vec3 result = center * weight[0]; + for(int i = 1; i < 5; ++i) { vec4 eastFragments = texture(Texture, Input.TextureCoordinate + vec2(tex_offset.x * i, 0.0)); vec4 westFragments = texture(Texture, Input.TextureCoordinate - vec2(tex_offset.x * i, 0.0)); diff --git a/resources/Shaders/Gaussian_vert.frag.glsl b/resources/Shaders/Gaussian_vert.frag.glsl index 921ba55a..3924450a 100644 --- a/resources/Shaders/Gaussian_vert.frag.glsl +++ b/resources/Shaders/Gaussian_vert.frag.glsl @@ -2,6 +2,7 @@ #extension GL_EXT_gpu_shader4 : enable layout (binding = 0) uniform sampler2D Texture; +uniform int Lod; in VertexData{ vec2 TextureCoordinate; @@ -10,12 +11,14 @@ in VertexData{ out vec4 fragmentColor; uniform float weight[5] = float[](0.227027, 0.1945946, 0.1216216, 0.054054, 0.016216); +//uniform float weight[3] = float[](0.265495, 0.226535, 0.140718); void main() { - vec2 tex_offset = 1.0 / textureSize2D(Texture, 0); + vec2 tex_offset = 1.0 / textureSize(Texture, Lod); vec3 center = texture(Texture, Input.TextureCoordinate).rgb; vec3 result = center * weight[0]; + for(int i = 1; i < 5; ++i) { vec4 northFragments = texture(Texture, Input.TextureCoordinate + vec2(0.0, tex_offset.y * i)); vec4 southFragments = texture(Texture, Input.TextureCoordinate - vec2(0.0, tex_offset.y * i)); diff --git a/src/Engine/Rendering/DrawBloomPass.cpp b/src/Engine/Rendering/DrawBloomPass.cpp index 4172118c..f30734db 100644 --- a/src/Engine/Rendering/DrawBloomPass.cpp +++ b/src/Engine/Rendering/DrawBloomPass.cpp @@ -66,18 +66,31 @@ void DrawBloomPass::InitializeShaderPrograms() void DrawBloomPass::InitializeBuffers() { - CommonFunctions::GenerateTexture(&m_GaussianTexture_horiz, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); + CommonFunctions::GenerateMipMapTexture( + &m_GaussianTexture_horiz, GL_CLAMP_TO_EDGE, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height) + , GL_RGB, GL_FLOAT, m_BloomLod); + CommonFunctions::GenerateMipMapTexture( + &m_GaussianTexture_vert, GL_CLAMP_TO_EDGE, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height) + , GL_RGB, GL_FLOAT, m_BloomLod); - if (m_GaussianFrameBuffer_horiz.GetHandle() == 0) { - m_GaussianFrameBuffer_horiz.AddResource(std::shared_ptr(new Texture2D(&m_GaussianTexture_horiz, GL_COLOR_ATTACHMENT0))); - } - m_GaussianFrameBuffer_horiz.Generate(); + if(m_GaussianFrameBuffer_horiz == nullptr) { + m_GaussianFrameBuffer_horiz = new FrameBuffer[m_BloomLod]; + } + if (m_GaussianFrameBuffer_vert == nullptr) { + m_GaussianFrameBuffer_vert = new FrameBuffer[m_BloomLod]; + } - CommonFunctions::GenerateTexture(&m_GaussianTexture_vert, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); - if (m_GaussianFrameBuffer_vert.GetHandle() == 0) { - m_GaussianFrameBuffer_vert.AddResource(std::shared_ptr(new Texture2D(&m_GaussianTexture_vert, GL_COLOR_ATTACHMENT0))); - } - m_GaussianFrameBuffer_vert.Generate(); + for (int i = 0; i < m_BloomLod; i++) { + if(m_GaussianFrameBuffer_horiz[i].GetHandle() == 0) { + m_GaussianFrameBuffer_horiz[i].AddResource(std::shared_ptr(new Texture2D(&m_GaussianTexture_horiz, GL_COLOR_ATTACHMENT0, i))); + } + m_GaussianFrameBuffer_horiz[i].Generate(); + + if (m_GaussianFrameBuffer_vert[i].GetHandle() == 0) { + m_GaussianFrameBuffer_vert[i].AddResource(std::shared_ptr(new Texture2D(&m_GaussianTexture_vert, GL_COLOR_ATTACHMENT0, i))); + } + m_GaussianFrameBuffer_vert[i].Generate(); + } } @@ -87,22 +100,53 @@ void DrawBloomPass::ClearBuffer() return; } GLERROR("PRE"); - m_GaussianFrameBuffer_horiz.Bind(); - glClearColor(0.f, 0.f, 0.f, 0.f); - glClear(GL_COLOR_BUFFER_BIT); - m_GaussianFrameBuffer_horiz.Unbind(); - m_GaussianFrameBuffer_vert.Bind(); - glClearColor(0.f, 0.f, 0.f, 0.f); - glClear(GL_COLOR_BUFFER_BIT); - m_GaussianFrameBuffer_vert.Unbind(); + for (int i = 0; i < m_BloomLod; i++) { + m_GaussianFrameBuffer_horiz[i].Bind(); + glClearColor(0.f, 0.f, 0.f, 0.f); + glClear(GL_COLOR_BUFFER_BIT); + m_GaussianFrameBuffer_horiz[i].Unbind(); + m_GaussianFrameBuffer_vert[i].Bind(); + glClearColor(0.f, 0.f, 0.f, 0.f); + glClear(GL_COLOR_BUFFER_BIT); + m_GaussianFrameBuffer_vert[i].Unbind(); + } + GLERROR("END"); } void DrawBloomPass::Draw(GLuint texture) +{ + if (m_Quality == 0) { + return; + } + + for (int i = 0; i < m_BloomLod; i++) { + GaussianLodPass(i, texture); + } +} + + +void DrawBloomPass::OnWindowResize() { if (m_Quality == 0) { return; } + CommonFunctions::GenerateMipMapTexture( + &m_GaussianTexture_vert, GL_CLAMP_TO_EDGE, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height) + , GL_RGB, GL_FLOAT, m_BloomLod); + CommonFunctions::GenerateMipMapTexture( + &m_GaussianTexture_horiz, GL_CLAMP_TO_EDGE, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height) + , GL_RGB, GL_FLOAT, m_BloomLod); + for (int i = 0; i < m_BloomLod; i++) { + m_GaussianFrameBuffer_vert[i].Generate(); + m_GaussianFrameBuffer_horiz[i].Generate(); + + } + +} + +void DrawBloomPass::GaussianLodPass(GLuint mipMap, GLuint texture) +{ GLERROR("DrawBloomPass::Draw: Pre"); DrawBloomPassState state; @@ -110,10 +154,14 @@ void DrawBloomPass::Draw(GLuint texture) GLuint shaderHandle_horiz = m_GaussianProgram_horiz->GetHandle(); GLuint shaderHandle_vert = m_GaussianProgram_vert->GetHandle(); - //Horizontal pass, first use the given texture then save it to the horizontal framebuffer. - m_GaussianFrameBuffer_horiz.Bind(); + m_GaussianFrameBuffer_horiz[mipMap].Bind(); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, mipMap); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, mipMap); m_GaussianProgram_horiz->Bind(); + glUniform1i(glGetUniformLocation(shaderHandle_horiz, "Lod"), mipMap); + + glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture); glBindVertexArray(m_ScreenQuad->VAO); @@ -123,10 +171,12 @@ void DrawBloomPass::Draw(GLuint texture) //Iterate some times to make it more gaussian. for (int i = 1; i < m_Iterations; i++) { //Vertical pass - m_GaussianFrameBuffer_vert.Bind(); + m_GaussianFrameBuffer_vert[mipMap].Bind(); m_GaussianProgram_vert->Bind(); + glUniform1i(glGetUniformLocation(shaderHandle_vert, "Lod"), mipMap); - glActiveTexture(GL_TEXTURE0); + + glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_GaussianTexture_horiz); glBindVertexArray(m_ScreenQuad->VAO); @@ -134,27 +184,29 @@ void DrawBloomPass::Draw(GLuint texture) glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1 , GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex); //horizontal pass - m_GaussianFrameBuffer_vert.Unbind(); + m_GaussianFrameBuffer_vert[mipMap].Unbind(); - m_GaussianFrameBuffer_horiz.Bind(); + m_GaussianFrameBuffer_horiz[mipMap].Bind(); m_GaussianProgram_horiz->Bind(); + glUniform1i(glGetUniformLocation(shaderHandle_horiz, "Lod"), mipMap); - glActiveTexture(GL_TEXTURE0); + glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_GaussianTexture_vert); glBindVertexArray(m_ScreenQuad->VAO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer); glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1 , GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex); - m_GaussianFrameBuffer_horiz.Unbind(); + m_GaussianFrameBuffer_horiz[mipMap].Unbind(); } //final vertical gaussian after the iterations are done - m_GaussianFrameBuffer_vert.Bind(); + m_GaussianFrameBuffer_vert[mipMap].Bind(); m_GaussianProgram_vert->Bind(); + glUniform1i(glGetUniformLocation(shaderHandle_vert, "Lod"), mipMap); - glActiveTexture(GL_TEXTURE0); + glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_GaussianTexture_horiz); glBindVertexArray(m_ScreenQuad->VAO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer); @@ -162,16 +214,6 @@ void DrawBloomPass::Draw(GLuint texture) , GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex); GLERROR("DrawBloomPass::Draw: END"); -} + m_GaussianFrameBuffer_vert[mipMap].Unbind(); - -void DrawBloomPass::OnWindowResize() -{ - if (m_Quality == 0) { - return; - } - CommonFunctions::GenerateTexture(&m_GaussianTexture_vert, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); - m_GaussianFrameBuffer_vert.Generate(); - CommonFunctions::GenerateTexture(&m_GaussianTexture_horiz, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); - m_GaussianFrameBuffer_horiz.Generate(); } diff --git a/src/Engine/Rendering/FrameBuffer.cpp b/src/Engine/Rendering/FrameBuffer.cpp index c94423ba..dfabb8a3 100644 --- a/src/Engine/Rendering/FrameBuffer.cpp +++ b/src/Engine/Rendering/FrameBuffer.cpp @@ -2,11 +2,12 @@ #include "Rendering/FrameBuffer.h" -BufferResource::BufferResource(GLuint* resourceHandle, GLenum resourceType, GLenum attachment) +BufferResource::BufferResource(GLuint* resourceHandle, GLenum resourceType, GLenum attachment, GLuint mipMapLod) { m_ResourceHandle = resourceHandle; m_ResourceType = resourceType; m_Attachment = attachment; + m_MipMapLod = mipMapLod; } Texture2D::~Texture2D() @@ -58,7 +59,7 @@ void FrameBuffer::Generate() 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); + glFramebufferTexture(GL_FRAMEBUFFER, (*it)->m_Attachment, *(*it)->m_ResourceHandle, (*it)->m_MipMapLod); GLERROR("FrameBuffer generate: glFramebufferTexture2D"); break; case GL_RENDERBUFFER: diff --git a/src/Engine/Rendering/Util/CommonFunctions.cpp b/src/Engine/Rendering/Util/CommonFunctions.cpp index e1344928..dac9fca3 100644 --- a/src/Engine/Rendering/Util/CommonFunctions.cpp +++ b/src/Engine/Rendering/Util/CommonFunctions.cpp @@ -28,7 +28,8 @@ void CommonFunctions::GenerateMipMapTexture(GLuint* texture, GLenum wrapping, gl glGenTextures(1, texture); glBindTexture(GL_TEXTURE_2D, *texture); glTexStorage2D(GL_TEXTURE_2D, numMipMaps, GL_RGBA8, dimensions.x, dimensions.y); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, dimensions.x, dimensions.y, format, type, texture); + //glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, dimensions.x, dimensions.y, format, type, NULL); + GLERROR("MipMap Texture glTexSubImage2D failed"); glGenerateMipmap(GL_TEXTURE_2D); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapping); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapping); From a6ef026db5dab7a09f666a060dc9800c607ea640 Mon Sep 17 00:00:00 2001 From: Teejoon Date: Thu, 10 Mar 2016 12:27:25 +0100 Subject: [PATCH 07/24] Fixed on window resize memory leak --- src/Engine/Rendering/LightCullingPass.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Engine/Rendering/LightCullingPass.cpp b/src/Engine/Rendering/LightCullingPass.cpp index 1ce1f88c..9a6e19cf 100644 --- a/src/Engine/Rendering/LightCullingPass.cpp +++ b/src/Engine/Rendering/LightCullingPass.cpp @@ -42,6 +42,15 @@ void LightCullingPass::SetSSBOSizes() { m_NumberOfTiles = (int)(m_Renderer->GetViewportSize().Width/TILE_SIZE) * (int)(m_Renderer->GetViewportSize().Height/TILE_SIZE); + if (m_Frustums != nullptr) { + delete[] m_Frustums; + } + if (m_LightGrid != nullptr) { + delete[] m_LightGrid; + } + if (m_LightIndex != nullptr) { + delete[] m_LightIndex; + } m_Frustums = new Frustum[m_NumberOfTiles]; m_LightGrid = new LightGrid[m_NumberOfTiles]; m_LightIndex = new float[m_NumberOfTiles*MAX_LIGHTS_PER_TILE]; From bdcb33d99248cca77133272f22d85bfef4d9f815 Mon Sep 17 00:00:00 2001 From: William Moberg Date: Thu, 10 Mar 2016 12:46:06 +0100 Subject: [PATCH 08/24] Mouse always unlocked on game start and on disconnecting (i.e when menu shows). --- include/Game/Systems/SpectatorCameraSystem.h | 3 +++ resources/DefaultInput.ini | 4 +++- src/Engine/Editor/EditorSystem.cpp | 1 + src/Engine/Network/Client.cpp | 7 ++++++- src/Game/Systems/SpectatorCameraSystem.cpp | 16 +++++++++++++++- 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/include/Game/Systems/SpectatorCameraSystem.h b/include/Game/Systems/SpectatorCameraSystem.h index 5a00279b..bc7aa860 100644 --- a/include/Game/Systems/SpectatorCameraSystem.h +++ b/include/Game/Systems/SpectatorCameraSystem.h @@ -3,6 +3,7 @@ #include "Core/System.h" #include "Input/EInputCommand.h" +#include "Network/EPlayerDisconnected.h" class SpectatorCameraSystem : public ImpureSystem { @@ -17,6 +18,8 @@ private: EventRelay m_EInputCommand; bool OnInputCommand(const Events::InputCommand& e); + EventRelay m_EDisconnect; + bool OnDisconnect(const Events::PlayerDisconnected& e); }; #endif \ No newline at end of file diff --git a/resources/DefaultInput.ini b/resources/DefaultInput.ini index 18fb943f..840e5cd0 100644 --- a/resources/DefaultInput.ini +++ b/resources/DefaultInput.ini @@ -29,4 +29,6 @@ K=TakeDamage,1500 F2=PerformanceTimingResetAllTimers F3=PerformanceTimingCreateExcelData Comma=SwapToClassPick -Period=SwapToTeamPick \ No newline at end of file +Period=SwapToTeamPick +Enter=PickClass,1 +F5=DisconnectFromServer \ No newline at end of file diff --git a/src/Engine/Editor/EditorSystem.cpp b/src/Engine/Editor/EditorSystem.cpp index 5e0d02fd..89f6ef5c 100644 --- a/src/Engine/Editor/EditorSystem.cpp +++ b/src/Engine/Editor/EditorSystem.cpp @@ -47,6 +47,7 @@ EditorSystem::EditorSystem(SystemParams params, IRenderer* renderer, RenderFrame Enable(); } else { Disable(); + m_EventBroker->Publish(Events::UnlockMouse()); } } diff --git a/src/Engine/Network/Client.cpp b/src/Engine/Network/Client.cpp index b4eafbcb..02ffc78a 100644 --- a/src/Engine/Network/Client.cpp +++ b/src/Engine/Network/Client.cpp @@ -1,4 +1,5 @@ #include "Network/Client.h" +#include "Network/EPlayerDisconnected.h" using namespace boost::asio::ip; Client::Client(World* world, EventBroker* eventBroker) @@ -224,7 +225,7 @@ void Client::parseServerlist(Packet& packet) void Client::parseKick() { LOG_WARNING("You have been kicked from the server."); - m_IsConnected = false; + disconnect(); } void Client::parseSpawnEvents() @@ -464,6 +465,10 @@ void Client::disconnect() Packet packet(MessageType::Disconnect, m_SendPacketID); m_Reliable.Send(packet); m_Reliable.Disconnect(); + Events::PlayerDisconnected e; + e.Entity = m_LocalPlayer.ID; + e.PlayerID = -1; + m_EventBroker->Publish(e); createMainMenu(); } diff --git a/src/Game/Systems/SpectatorCameraSystem.cpp b/src/Game/Systems/SpectatorCameraSystem.cpp index d1f2f1ce..23dfb164 100644 --- a/src/Game/Systems/SpectatorCameraSystem.cpp +++ b/src/Game/Systems/SpectatorCameraSystem.cpp @@ -8,6 +8,7 @@ SpectatorCameraSystem::SpectatorCameraSystem(SystemParams params) , m_PickedTeam(-1) { EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &SpectatorCameraSystem::OnInputCommand); + EVENT_SUBSCRIBE_MEMBER(m_EDisconnect, &SpectatorCameraSystem::OnDisconnect); } void SpectatorCameraSystem::Update(double dt) @@ -87,4 +88,17 @@ bool SpectatorCameraSystem::OnInputCommand(const Events::InputCommand& e) } return true; -} \ No newline at end of file +} + +bool SpectatorCameraSystem::OnDisconnect(const Events::PlayerDisconnected& e) +{ + // If local player gets disconnected, they should be set to + // the spectator camera next time a map loads that has one. + if (e.Entity == LocalPlayer.ID) { + m_CamSetToTeamPick = false; + // They will also be set to menu, so unlock mouse just in case they were in game with locked mouse. + Events::UnlockMouse unlock; + m_EventBroker->Publish(unlock); + } + return true; +} From c3255519bf42991d7bf6b7d9716951b7687b7ce4 Mon Sep 17 00:00:00 2001 From: Tleety Date: Thu, 10 Mar 2016 13:07:41 +0100 Subject: [PATCH 09/24] Blur is now looking like real blur --- include/Engine/Rendering/DrawBloomPass.h | 6 ++- .../Shaders/CombineGaussianTexture.frag.glsl | 22 +++++++++ .../Shaders/CombineGaussianTexture.vert.glsl | 13 ++++++ src/Engine/Rendering/DrawBloomPass.cpp | 46 ++++++++++++++++--- src/Engine/Rendering/Util/CommonFunctions.cpp | 1 + 5 files changed, 80 insertions(+), 8 deletions(-) create mode 100644 resources/Shaders/CombineGaussianTexture.frag.glsl create mode 100644 resources/Shaders/CombineGaussianTexture.vert.glsl diff --git a/include/Engine/Rendering/DrawBloomPass.h b/include/Engine/Rendering/DrawBloomPass.h index 204f97d1..a76eb053 100644 --- a/include/Engine/Rendering/DrawBloomPass.h +++ b/include/Engine/Rendering/DrawBloomPass.h @@ -33,13 +33,14 @@ public: if (m_Quality == 0) { return m_BlackTexture->m_Texture; } else { - return m_GaussianTexture_vert; + return m_FinalGaussianTexture; } } private: void GaussianLodPass(GLuint mipMap, GLuint texture); + void CombineGaussianBlur(); Texture* m_BlackTexture; Model* m_ScreenQuad; @@ -52,12 +53,15 @@ private: GLuint m_GaussianTexture_horiz = 0; GLuint m_GaussianTexture_vert = 0; + GLuint m_FinalGaussianTexture = 0; FrameBuffer* m_GaussianFrameBuffer_horiz = nullptr; FrameBuffer* m_GaussianFrameBuffer_vert = nullptr; + FrameBuffer m_GaussianCombineBuffer; ShaderProgram* m_GaussianProgram_horiz; ShaderProgram* m_GaussianProgram_vert; + ShaderProgram* m_GaussianCombineProgram; }; diff --git a/resources/Shaders/CombineGaussianTexture.frag.glsl b/resources/Shaders/CombineGaussianTexture.frag.glsl new file mode 100644 index 00000000..66892a6a --- /dev/null +++ b/resources/Shaders/CombineGaussianTexture.frag.glsl @@ -0,0 +1,22 @@ +#version 430 + +layout (binding = 0) uniform sampler2D Texture; + + +in VertexData{ + vec2 TextureCoordinate; +}Input; + +out vec4 fragmentColor; + +void main() +{ + vec4 texel0 = textureLod(Texture, Input.TextureCoordinate, 0); + vec4 texel1 = textureLod(Texture, Input.TextureCoordinate, 1); + vec4 texel2 = textureLod(Texture, Input.TextureCoordinate, 2); + vec4 texel3 = textureLod(Texture, Input.TextureCoordinate, 3); + + fragmentColor = texel0 + texel1 + texel2 + texel3; +} + + diff --git a/resources/Shaders/CombineGaussianTexture.vert.glsl b/resources/Shaders/CombineGaussianTexture.vert.glsl new file mode 100644 index 00000000..346bc141 --- /dev/null +++ b/resources/Shaders/CombineGaussianTexture.vert.glsl @@ -0,0 +1,13 @@ +#version 430 + +layout (location = 0) in vec3 Position; + +out VertexData{ + vec2 TextureCoordinate; +}Output; + +void main() +{ + gl_Position = vec4(Position, 1.0); + Output.TextureCoordinate = (vec2(Position) + 1) / 2; +} \ No newline at end of file diff --git a/src/Engine/Rendering/DrawBloomPass.cpp b/src/Engine/Rendering/DrawBloomPass.cpp index f30734db..f73611a2 100644 --- a/src/Engine/Rendering/DrawBloomPass.cpp +++ b/src/Engine/Rendering/DrawBloomPass.cpp @@ -12,6 +12,7 @@ DrawBloomPass::DrawBloomPass(IRenderer* renderer, ConfigFile* config) DrawBloomPass::~DrawBloomPass() { CommonFunctions::DeleteTexture(&m_GaussianTexture_horiz); CommonFunctions::DeleteTexture(&m_GaussianTexture_vert); + CommonFunctions::DeleteTexture(&m_FinalGaussianTexture); } void DrawBloomPass::InitializeTextures() @@ -30,9 +31,8 @@ void DrawBloomPass::ChangeQuality(int quality) if (m_Quality == 0) { CommonFunctions::DeleteTexture(&m_GaussianTexture_horiz); - CommonFunctions::DeleteTexture(&m_GaussianTexture_vert); - m_GaussianTexture_horiz = 0; - m_GaussianTexture_vert = 0; + CommonFunctions::DeleteTexture(&m_GaussianTexture_vert); + CommonFunctions::DeleteTexture(&m_FinalGaussianTexture); return; } InitializeTextures(); @@ -62,6 +62,15 @@ void DrawBloomPass::InitializeShaderPrograms() m_GaussianProgram_vert->BindFragDataLocation(0, "fragmentColor"); m_GaussianProgram_vert->Link(); } + + m_GaussianCombineProgram = ResourceManager::Load("#GaussianCombineProgram"); + if (m_GaussianCombineProgram->GetHandle() == 0) { + m_GaussianCombineProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/CombineGaussianTexture.vert.glsl"))); + m_GaussianCombineProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/CombineGaussianTexture.frag.glsl"))); + m_GaussianCombineProgram->Compile(); + m_GaussianCombineProgram->BindFragDataLocation(0, "fragmentColor"); + m_GaussianCombineProgram->Link(); + } } void DrawBloomPass::InitializeBuffers() @@ -72,6 +81,12 @@ void DrawBloomPass::InitializeBuffers() CommonFunctions::GenerateMipMapTexture( &m_GaussianTexture_vert, GL_CLAMP_TO_EDGE, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height) , GL_RGB, GL_FLOAT, m_BloomLod); + CommonFunctions::GenerateTexture(&m_FinalGaussianTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); + + if (m_GaussianCombineBuffer.GetHandle() == 0) { + m_GaussianCombineBuffer.AddResource(std::shared_ptr(new Texture2D(&m_FinalGaussianTexture, GL_COLOR_ATTACHMENT0))); + } + m_GaussianCombineBuffer.Generate(); if(m_GaussianFrameBuffer_horiz == nullptr) { m_GaussianFrameBuffer_horiz = new FrameBuffer[m_BloomLod]; @@ -109,8 +124,12 @@ void DrawBloomPass::ClearBuffer() glClearColor(0.f, 0.f, 0.f, 0.f); glClear(GL_COLOR_BUFFER_BIT); m_GaussianFrameBuffer_vert[i].Unbind(); - } + } + m_GaussianCombineBuffer.Bind(); + glClearColor(0.f, 0.f, 0.f, 0.f); + glClear(GL_COLOR_BUFFER_BIT); + m_GaussianCombineBuffer.Unbind(); GLERROR("END"); } @@ -123,6 +142,7 @@ void DrawBloomPass::Draw(GLuint texture) for (int i = 0; i < m_BloomLod; i++) { GaussianLodPass(i, texture); } + CombineGaussianBlur(); } @@ -148,7 +168,7 @@ void DrawBloomPass::OnWindowResize() void DrawBloomPass::GaussianLodPass(GLuint mipMap, GLuint texture) { GLERROR("DrawBloomPass::Draw: Pre"); - + glViewport(0, 0, m_Renderer->GetViewportSize().Width/(glm::pow(2, mipMap)), m_Renderer->GetViewportSize().Height/(glm::pow(2, mipMap))); DrawBloomPassState state; GLuint shaderHandle_horiz = m_GaussianProgram_horiz->GetHandle(); @@ -156,8 +176,6 @@ void DrawBloomPass::GaussianLodPass(GLuint mipMap, GLuint texture) //Horizontal pass, first use the given texture then save it to the horizontal framebuffer. m_GaussianFrameBuffer_horiz[mipMap].Bind(); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, mipMap); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, mipMap); m_GaussianProgram_horiz->Bind(); glUniform1i(glGetUniformLocation(shaderHandle_horiz, "Lod"), mipMap); @@ -214,6 +232,20 @@ void DrawBloomPass::GaussianLodPass(GLuint mipMap, GLuint texture) , GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex); GLERROR("DrawBloomPass::Draw: END"); + glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height); m_GaussianFrameBuffer_vert[mipMap].Unbind(); } + +void DrawBloomPass::CombineGaussianBlur() +{ + m_GaussianCombineBuffer.Bind(); + m_GaussianCombineProgram->Bind(); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, m_GaussianTexture_vert); + glBindVertexArray(m_ScreenQuad->VAO); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer); + glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1 + , GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex); +} diff --git a/src/Engine/Rendering/Util/CommonFunctions.cpp b/src/Engine/Rendering/Util/CommonFunctions.cpp index dac9fca3..c185cd5c 100644 --- a/src/Engine/Rendering/Util/CommonFunctions.cpp +++ b/src/Engine/Rendering/Util/CommonFunctions.cpp @@ -25,6 +25,7 @@ void CommonFunctions::GenerateMultiSampleTexture(GLuint* texture, int numSamples void CommonFunctions::GenerateMipMapTexture(GLuint* texture, GLenum wrapping, glm::vec2 dimensions, GLint format, GLenum type, GLint numMipMaps) { + glDeleteTextures(1, texture); glGenTextures(1, texture); glBindTexture(GL_TEXTURE_2D, *texture); glTexStorage2D(GL_TEXTURE_2D, numMipMaps, GL_RGBA8, dimensions.x, dimensions.y); From 0346f81234d26c2e4358471c843b0e4d4d362b58 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Thu, 10 Mar 2016 13:05:21 +0100 Subject: [PATCH 10/24] Renderer resizing updated to send EResolutionChanged when the resolution is updated so cameras can update their aspect ratio and have a correct FOV. Renderer::SetResolution actually changes the resolution now too. --- include/Engine/Rendering/EResolutionChanged.h | 19 +++++++ include/Engine/Rendering/RenderSystem.h | 3 ++ include/Engine/Rendering/Renderer.h | 10 +++- src/Engine/Rendering/RenderSystem.cpp | 10 +++- src/Engine/Rendering/Renderer.cpp | 50 ++++++++++++++++--- 5 files changed, 81 insertions(+), 11 deletions(-) create mode 100644 include/Engine/Rendering/EResolutionChanged.h diff --git a/include/Engine/Rendering/EResolutionChanged.h b/include/Engine/Rendering/EResolutionChanged.h new file mode 100644 index 00000000..220a2c74 --- /dev/null +++ b/include/Engine/Rendering/EResolutionChanged.h @@ -0,0 +1,19 @@ +#ifndef EResolutionChanged_h__ +#define EResolutionChanged_h__ + +#include "../Core/Event.h" +#include "../Core/Util/Rectangle.h" + +namespace Events +{ + +// Fired when the framebuffer size changes +struct ResolutionChanged : Event +{ + Rectangle OldResolution; + Rectangle NewResolution; +}; + +} + +#endif \ No newline at end of file diff --git a/include/Engine/Rendering/RenderSystem.h b/include/Engine/Rendering/RenderSystem.h index 7580d654..fbcf7ec3 100644 --- a/include/Engine/Rendering/RenderSystem.h +++ b/include/Engine/Rendering/RenderSystem.h @@ -19,6 +19,7 @@ #include "../Core/Octree.h" #include "../Collision/EntityAABB.h" #include "../Core/ConfigFile.h" +#include "EResolutionChanged.h" class RenderSystem : public ImpureSystem { @@ -36,6 +37,8 @@ private: EntityWrapper m_LocalPlayer = EntityWrapper::Invalid; Octree* m_Octree; + EventRelay m_EResolutionChanged; + bool OnResolutionChanged(Events::ResolutionChanged &event); EventRelay m_ESetCamera; bool OnSetCamera(Events::SetCamera &event); EventRelay m_EInputCommand; diff --git a/include/Engine/Rendering/Renderer.h b/include/Engine/Rendering/Renderer.h index 16bdea9e..c36ba59a 100644 --- a/include/Engine/Rendering/Renderer.h +++ b/include/Engine/Rendering/Renderer.h @@ -28,10 +28,12 @@ #include "Util/CommonFunctions.h" #include "Core/PerformanceTimer.h" #include "ShadowPass.h" +#include "EResolutionChanged.h" class Renderer : public IRenderer { static void glfwFrameBufferCallback(GLFWwindow* window, int width, int height); + static void glfwWindowSizeCallback(GLFWwindow* window, int width, int height); public: Renderer(EventBroker* eventBroker, ConfigFile* config) @@ -40,13 +42,14 @@ public: { } ~Renderer(); + virtual void SetResolution(const Rectangle& resolution) override; + virtual void Initialize() override; virtual void Update(double dt) override; virtual void Draw(RenderFrame& frame) override; virtual PickData Pick(glm::vec2 screenCoord) override; - private: //----------------------Variables----------------------// @@ -90,11 +93,14 @@ private: void InputUpdate(double dt); //void PickingPass(RenderQueueCollection& rq); //void DrawScreenQuad(GLuint textureToDraw); + void setWindowSize(Rectangle size); + void updateFramebufferSize(); static bool DepthSort(const std::shared_ptr &i, const std::shared_ptr &j) { return (i->Depth < j->Depth); } void SortRenderJobsByDepth(RenderScene &scene); void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type); - //--------------------ShaderPrograms-------------------// + + //--------------------ShaderPrograms-------------------// ShaderProgram* m_BasicForwardProgram; ShaderProgram* m_ExplosionEffectProgram; diff --git a/src/Engine/Rendering/RenderSystem.cpp b/src/Engine/Rendering/RenderSystem.cpp index 54da9666..d685c443 100644 --- a/src/Engine/Rendering/RenderSystem.cpp +++ b/src/Engine/Rendering/RenderSystem.cpp @@ -9,10 +9,11 @@ RenderSystem::RenderSystem(SystemParams params, const IRenderer* renderer, Rende , m_Octree(frustumCullOctree) { EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &RenderSystem::OnSetCamera); + EVENT_SUBSCRIBE_MEMBER(m_EResolutionChanged, &RenderSystem::OnResolutionChanged); 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->GetViewportSize().Width / m_Renderer->GetViewportSize().Height, glm::radians(45.f), 0.01f, 5000.f); } RenderSystem::~RenderSystem() @@ -20,6 +21,13 @@ RenderSystem::~RenderSystem() delete m_Camera; } +bool RenderSystem::OnResolutionChanged(Events::ResolutionChanged& e) +{ + // Update camera aspect ration on resolution change + m_Camera->SetAspectRatio((float)e.NewResolution.Width / e.NewResolution.Height); + return true; +} + bool RenderSystem::OnSetCamera(Events::SetCamera& e) { ComponentWrapper cTransform = e.CameraEntity["Transform"]; diff --git a/src/Engine/Rendering/Renderer.cpp b/src/Engine/Rendering/Renderer.cpp index 90122f7c..09c35baa 100644 --- a/src/Engine/Rendering/Renderer.cpp +++ b/src/Engine/Rendering/Renderer.cpp @@ -36,16 +36,24 @@ void Renderer::Initialize() m_ImGuiRenderPass = new ImGuiRenderPass(this, m_EventBroker); } +void Renderer::glfwWindowSizeCallback(GLFWwindow* window, int width, int height) +{ + m_WindowToRenderer[window]->setWindowSize(Rectangle(width, height)); +} + void Renderer::glfwFrameBufferCallback(GLFWwindow* window, int width, int height) { - glViewport(0, 0, width, height); - Renderer* currentRenderer = m_WindowToRenderer[window]; - currentRenderer->m_ViewportSize = Rectangle(width, height); - currentRenderer->m_PickingPass->OnWindowResize(); - currentRenderer->m_DrawFinalPass->OnWindowResize(); - currentRenderer->m_LightCullingPass->OnWindowResize(); - currentRenderer->m_DrawBloomPass->OnWindowResize(); - currentRenderer->m_SSAOPass->OnWindowResize(); + m_WindowToRenderer[window]->updateFramebufferSize(); +} + +void Renderer::SetResolution(const Rectangle& resolution) +{ + m_Resolution = resolution; + + if (m_Window != nullptr) { + setWindowSize(resolution); + updateFramebufferSize(); + } } void Renderer::InitializeWindow() @@ -67,6 +75,7 @@ void Renderer::InitializeWindow() LOG_ERROR("GLFW: Failed to create window"); exit(EXIT_FAILURE); } + glfwSetWindowSizeCallback(m_Window, &glfwWindowSizeCallback); glfwSetFramebufferSizeCallback(m_Window, &glfwFrameBufferCallback); glfwMakeContextCurrent(m_Window); @@ -111,6 +120,30 @@ void Renderer::InputUpdate(double dt) } +void Renderer::setWindowSize(Rectangle size) +{ + glfwSetWindowSize(m_Window, size.Width, size.Height); +} + +void Renderer::updateFramebufferSize() +{ + Events::ResolutionChanged e; + e.OldResolution = m_ViewportSize; + + int width, height; + glfwGetFramebufferSize(m_Window, &width, &height); + glViewport(0, 0, width, height); + m_ViewportSize = Rectangle(width, height); + m_PickingPass->OnWindowResize(); + m_DrawFinalPass->OnWindowResize(); + m_LightCullingPass->OnWindowResize(); + m_DrawBloomPass->OnWindowResize(); + m_SSAOPass->OnWindowResize(); + + e.NewResolution = m_ViewportSize; + m_EventBroker->Publish(e); +} + void Renderer::Update(double dt) { m_EventBroker->Process(); @@ -263,6 +296,7 @@ void Renderer::GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filterin GLERROR("Texture initialization failed"); } + void Renderer::InitializeRenderPasses() { m_PickingPass = new PickingPass(this, m_EventBroker); From e9ef0e7060b5d86015496785d8d9f697cb871a05 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Thu, 10 Mar 2016 13:19:26 +0100 Subject: [PATCH 11/24] Disabled GLERROR macro for release builds --- include/Engine/Rendering/Util/GLError.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/Engine/Rendering/Util/GLError.h b/include/Engine/Rendering/Util/GLError.h index 2b244e1c..8efe45f3 100644 --- a/include/Engine/Rendering/Util/GLError.h +++ b/include/Engine/Rendering/Util/GLError.h @@ -16,7 +16,11 @@ inline bool _GLERROR(const char* info, const char* file, const char* func, unsig return false; } +#ifndef DEBUG #define GLERROR(function) \ _GLERROR(function, __BASE_FILE__, __func__, __LINE__) +#else +#define GLERROR(function) false +#endif #endif \ No newline at end of file From 28de31d84d8fffb4f59fc611c0d312352ec5d85d Mon Sep 17 00:00:00 2001 From: stiffly Date: Thu, 10 Mar 2016 13:28:38 +0100 Subject: [PATCH 12/24] FIX #196: Some variables had not been properly initialized and would cause the game to crash. --- include/Engine/Rendering/LightCullingPass.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/Engine/Rendering/LightCullingPass.h b/include/Engine/Rendering/LightCullingPass.h index 914fb8bb..f3b21705 100644 --- a/include/Engine/Rendering/LightCullingPass.h +++ b/include/Engine/Rendering/LightCullingPass.h @@ -54,7 +54,7 @@ private: struct Frustum { Plane Planes[4]; }; - Frustum* m_Frustums; + Frustum* m_Frustums = nullptr; //This should be a component struct LightSource { @@ -74,11 +74,11 @@ private: glm::vec2 Padding = glm::vec2(1.f, 2.f); }; - LightGrid* m_LightGrid; + LightGrid* m_LightGrid = nullptr; int m_LightOffset = 0; - float* m_LightIndex; + float* m_LightIndex = nullptr; }; From 329a15e08b05e350558ec742d4e5b4f01aaa50a0 Mon Sep 17 00:00:00 2001 From: Tleety Date: Thu, 10 Mar 2016 13:42:33 +0100 Subject: [PATCH 13/24] Bloom bad edge clamp fixed --- include/Engine/Rendering/DrawBloomPass.h | 2 +- .../Shaders/CombineGaussianTexture.frag.glsl | 14 +++++++++--- src/Engine/Rendering/DrawBloomPass.cpp | 22 ++++++++++--------- src/Engine/Rendering/DrawFinalPass.cpp | 8 +++---- 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/include/Engine/Rendering/DrawBloomPass.h b/include/Engine/Rendering/DrawBloomPass.h index a76eb053..eaf17570 100644 --- a/include/Engine/Rendering/DrawBloomPass.h +++ b/include/Engine/Rendering/DrawBloomPass.h @@ -49,7 +49,7 @@ private: //const LightCullingPass* m_LightCullingPass int m_Iterations; int m_Quality = 0; - int m_BloomLod = 4; + int m_BloomLod = 5; GLuint m_GaussianTexture_horiz = 0; GLuint m_GaussianTexture_vert = 0; diff --git a/resources/Shaders/CombineGaussianTexture.frag.glsl b/resources/Shaders/CombineGaussianTexture.frag.glsl index 66892a6a..b6806493 100644 --- a/resources/Shaders/CombineGaussianTexture.frag.glsl +++ b/resources/Shaders/CombineGaussianTexture.frag.glsl @@ -1,6 +1,7 @@ #version 430 layout (binding = 0) uniform sampler2D Texture; +uniform int MaxMipMap; in VertexData{ @@ -11,12 +12,19 @@ out vec4 fragmentColor; void main() { + vec4 result = vec4(0.0, 0.0, 0.0, 0.0); + + for(int i = 0; i < MaxMipMap; i++) { + result += textureLod(Texture, Input.TextureCoordinate, i); + } + fragmentColor = result; +/* vec4 texel0 = textureLod(Texture, Input.TextureCoordinate, 0); vec4 texel1 = textureLod(Texture, Input.TextureCoordinate, 1); vec4 texel2 = textureLod(Texture, Input.TextureCoordinate, 2); vec4 texel3 = textureLod(Texture, Input.TextureCoordinate, 3); + vec4 texel4 = textureLod(Texture, Input.TextureCoordinate, 4); - fragmentColor = texel0 + texel1 + texel2 + texel3; + fragmentColor = texel0 + texel1 + texel2 + texel3 + texel4;*/ + } - - diff --git a/src/Engine/Rendering/DrawBloomPass.cpp b/src/Engine/Rendering/DrawBloomPass.cpp index f73611a2..72702299 100644 --- a/src/Engine/Rendering/DrawBloomPass.cpp +++ b/src/Engine/Rendering/DrawBloomPass.cpp @@ -76,12 +76,12 @@ void DrawBloomPass::InitializeShaderPrograms() void DrawBloomPass::InitializeBuffers() { CommonFunctions::GenerateMipMapTexture( - &m_GaussianTexture_horiz, GL_CLAMP_TO_EDGE, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height) + &m_GaussianTexture_horiz, GL_CLAMP_TO_BORDER, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height) , GL_RGB, GL_FLOAT, m_BloomLod); CommonFunctions::GenerateMipMapTexture( - &m_GaussianTexture_vert, GL_CLAMP_TO_EDGE, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height) + &m_GaussianTexture_vert, GL_CLAMP_TO_BORDER, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height) , GL_RGB, GL_FLOAT, m_BloomLod); - CommonFunctions::GenerateTexture(&m_FinalGaussianTexture, 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_FinalGaussianTexture, GL_CLAMP_TO_BORDER, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); if (m_GaussianCombineBuffer.GetHandle() == 0) { m_GaussianCombineBuffer.AddResource(std::shared_ptr(new Texture2D(&m_FinalGaussianTexture, GL_COLOR_ATTACHMENT0))); @@ -152,10 +152,10 @@ void DrawBloomPass::OnWindowResize() return; } CommonFunctions::GenerateMipMapTexture( - &m_GaussianTexture_vert, GL_CLAMP_TO_EDGE, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height) + &m_GaussianTexture_vert, GL_CLAMP_TO_BORDER, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height) , GL_RGB, GL_FLOAT, m_BloomLod); CommonFunctions::GenerateMipMapTexture( - &m_GaussianTexture_horiz, GL_CLAMP_TO_EDGE, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height) + &m_GaussianTexture_horiz, GL_CLAMP_TO_BORDER, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height) , GL_RGB, GL_FLOAT, m_BloomLod); for (int i = 0; i < m_BloomLod; i++) { m_GaussianFrameBuffer_vert[i].Generate(); @@ -174,12 +174,16 @@ void DrawBloomPass::GaussianLodPass(GLuint mipMap, GLuint texture) GLuint shaderHandle_horiz = m_GaussianProgram_horiz->GetHandle(); GLuint shaderHandle_vert = m_GaussianProgram_vert->GetHandle(); - //Horizontal pass, first use the given texture then save it to the horizontal framebuffer. - m_GaussianFrameBuffer_horiz[mipMap].Bind(); + m_GaussianProgram_vert->Bind(); + glUniform1i(glGetUniformLocation(shaderHandle_vert, "Lod"), mipMap); m_GaussianProgram_horiz->Bind(); glUniform1i(glGetUniformLocation(shaderHandle_horiz, "Lod"), mipMap); + //Horizontal pass, first use the given texture then save it to the horizontal framebuffer. + m_GaussianFrameBuffer_horiz[mipMap].Bind(); + + glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture); glBindVertexArray(m_ScreenQuad->VAO); @@ -191,7 +195,6 @@ void DrawBloomPass::GaussianLodPass(GLuint mipMap, GLuint texture) //Vertical pass m_GaussianFrameBuffer_vert[mipMap].Bind(); m_GaussianProgram_vert->Bind(); - glUniform1i(glGetUniformLocation(shaderHandle_vert, "Lod"), mipMap); glActiveTexture(GL_TEXTURE0); @@ -206,7 +209,6 @@ void DrawBloomPass::GaussianLodPass(GLuint mipMap, GLuint texture) m_GaussianFrameBuffer_horiz[mipMap].Bind(); m_GaussianProgram_horiz->Bind(); - glUniform1i(glGetUniformLocation(shaderHandle_horiz, "Lod"), mipMap); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_GaussianTexture_vert); @@ -222,7 +224,6 @@ void DrawBloomPass::GaussianLodPass(GLuint mipMap, GLuint texture) m_GaussianFrameBuffer_vert[mipMap].Bind(); m_GaussianProgram_vert->Bind(); - glUniform1i(glGetUniformLocation(shaderHandle_vert, "Lod"), mipMap); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_GaussianTexture_horiz); @@ -241,6 +242,7 @@ void DrawBloomPass::CombineGaussianBlur() { m_GaussianCombineBuffer.Bind(); m_GaussianCombineProgram->Bind(); + glUniform1i(glGetUniformLocation(m_GaussianCombineProgram->GetHandle(), "MaxMipMap"), m_BloomLod); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_GaussianTexture_vert); diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index c5b8c591..a18bd411 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -32,9 +32,9 @@ void DrawFinalPass::InitializeTextures() void DrawFinalPass::InitializeFrameBuffers() { - 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_SceneTexture, GL_CLAMP_TO_BORDER, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), 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_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_BloomTexture, GL_CLAMP_TO_BORDER, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), 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); @@ -345,8 +345,8 @@ 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); + CommonFunctions::GenerateTexture(&m_SceneTexture, GL_CLAMP_TO_BORDER, 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_BORDER, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); m_FinalPassFrameBuffer.Generate(); GLERROR("Error changing texture resolutions"); From 50dbbb4ed4a5f25dd531451511b6f4390fd84db3 Mon Sep 17 00:00:00 2001 From: Tleety Date: Thu, 10 Mar 2016 13:47:16 +0100 Subject: [PATCH 14/24] SSAO now send in 0 as Lod level and some optimizations in SSAO and Blur pass. --- src/Engine/Rendering/DrawBloomPass.cpp | 7 +------ src/Engine/Rendering/SSAOPass.cpp | 12 ++++++------ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/Engine/Rendering/DrawBloomPass.cpp b/src/Engine/Rendering/DrawBloomPass.cpp index 72702299..f70f25c1 100644 --- a/src/Engine/Rendering/DrawBloomPass.cpp +++ b/src/Engine/Rendering/DrawBloomPass.cpp @@ -200,8 +200,6 @@ void DrawBloomPass::GaussianLodPass(GLuint mipMap, GLuint texture) glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_GaussianTexture_horiz); - glBindVertexArray(m_ScreenQuad->VAO); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer); glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1 , GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex); //horizontal pass @@ -213,8 +211,6 @@ void DrawBloomPass::GaussianLodPass(GLuint mipMap, GLuint texture) glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_GaussianTexture_vert); - glBindVertexArray(m_ScreenQuad->VAO); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer); glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1 , GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex); m_GaussianFrameBuffer_horiz[mipMap].Unbind(); @@ -227,8 +223,7 @@ void DrawBloomPass::GaussianLodPass(GLuint mipMap, GLuint texture) glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_GaussianTexture_horiz); - glBindVertexArray(m_ScreenQuad->VAO); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer); + glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1 , GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex); diff --git a/src/Engine/Rendering/SSAOPass.cpp b/src/Engine/Rendering/SSAOPass.cpp index f3c7f74c..166bf924 100644 --- a/src/Engine/Rendering/SSAOPass.cpp +++ b/src/Engine/Rendering/SSAOPass.cpp @@ -233,6 +233,11 @@ void SSAOPass::Draw(GLuint depthBuffer, Camera* camera) GLuint shaderHandle_horiz = m_GaussianProgram_horiz->GetHandle(); GLuint shaderHandle_vert = m_GaussianProgram_vert->GetHandle(); + m_GaussianProgram_vert->Bind(); + glUniform1i(glGetUniformLocation(shaderHandle_vert, "Lod"), 0); + m_GaussianProgram_horiz->Bind(); + glUniform1i(glGetUniformLocation(shaderHandle_horiz, "Lod"), 0); + m_GaussianFrameBuffer_horiz.Bind(); m_GaussianProgram_horiz->Bind(); @@ -252,8 +257,6 @@ void SSAOPass::Draw(GLuint depthBuffer, Camera* camera) glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_Gaussian_horiz); - glBindVertexArray(m_ScreenQuad->VAO); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer); glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex + 1 , GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex); //horizontal pass @@ -265,8 +268,6 @@ void SSAOPass::Draw(GLuint depthBuffer, Camera* camera) glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_Gaussian_vert); - glBindVertexArray(m_ScreenQuad->VAO); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer); glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex + 1 , GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex); m_GaussianFrameBuffer_horiz.Unbind(); @@ -279,8 +280,7 @@ void SSAOPass::Draw(GLuint depthBuffer, Camera* camera) glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_Gaussian_horiz); - glBindVertexArray(m_ScreenQuad->VAO); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer); + glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex + 1 , GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex); From dd63f4a1b40b799054798298fe0170fdcf770162 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Thu, 10 Mar 2016 13:51:18 +0100 Subject: [PATCH 15/24] Fixed FOV being used to calculate projection matrix being degrees when it should be radians, AGAIN. FOV angles are now correct! --- resources/Schema/Components/Camera.xml | 2 +- src/Engine/Editor/EditorRenderSystem.cpp | 2 +- src/Engine/Rendering/RenderSystem.cpp | 2 +- src/Engine/Rendering/Renderer.cpp | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/resources/Schema/Components/Camera.xml b/resources/Schema/Components/Camera.xml index b9c28d53..00edcc00 100644 --- a/resources/Schema/Components/Camera.xml +++ b/resources/Schema/Components/Camera.xml @@ -1,6 +1,6 @@ - 45 + 59 0.01 5000 \ No newline at end of file diff --git a/src/Engine/Editor/EditorRenderSystem.cpp b/src/Engine/Editor/EditorRenderSystem.cpp index 97203dea..f31b63cf 100644 --- a/src/Engine/Editor/EditorRenderSystem.cpp +++ b/src/Engine/Editor/EditorRenderSystem.cpp @@ -86,7 +86,7 @@ bool EditorRenderSystem::OnSetCamera(Events::SetCamera& e) { ComponentWrapper cTransform = e.CameraEntity["Transform"]; ComponentWrapper cCamera = e.CameraEntity["Camera"]; - m_EditorCamera->SetFOV(static_cast((double)cCamera["FOV"])); + m_EditorCamera->SetFOV(glm::radians(static_cast((double)cCamera["FOV"]))); m_EditorCamera->SetNearClip(static_cast((double)cCamera["NearClip"])); m_EditorCamera->SetFarClip(static_cast((double)cCamera["FarClip"])); m_EditorCamera->SetPosition(cTransform["Position"]); diff --git a/src/Engine/Rendering/RenderSystem.cpp b/src/Engine/Rendering/RenderSystem.cpp index d685c443..fee539d4 100644 --- a/src/Engine/Rendering/RenderSystem.cpp +++ b/src/Engine/Rendering/RenderSystem.cpp @@ -32,7 +32,7 @@ bool RenderSystem::OnSetCamera(Events::SetCamera& e) { ComponentWrapper cTransform = e.CameraEntity["Transform"]; ComponentWrapper cCamera = e.CameraEntity["Camera"]; - m_Camera->SetFOV((double)cCamera["FOV"]); + m_Camera->SetFOV(glm::radians((double)cCamera["FOV"])); m_Camera->SetNearClip((double)cCamera["NearClip"]); m_Camera->SetFarClip((double)cCamera["FarClip"]); m_Camera->SetPosition(cTransform["Position"]); diff --git a/src/Engine/Rendering/Renderer.cpp b/src/Engine/Rendering/Renderer.cpp index 09c35baa..eecb5a7a 100644 --- a/src/Engine/Rendering/Renderer.cpp +++ b/src/Engine/Rendering/Renderer.cpp @@ -122,6 +122,7 @@ void Renderer::InputUpdate(double dt) void Renderer::setWindowSize(Rectangle size) { + m_Resolution = size; glfwSetWindowSize(m_Window, size.Width, size.Height); } From 79d0ef4529cdf20eb2ccaae64b9f0c3b38db633f Mon Sep 17 00:00:00 2001 From: Tleety Date: Thu, 10 Mar 2016 14:01:45 +0100 Subject: [PATCH 16/24] Changed default value of glow intensity --- resources/Schema/Components/Model.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/Schema/Components/Model.xml b/resources/Schema/Components/Model.xml index 35b05b69..99190e1f 100644 --- a/resources/Schema/Components/Model.xml +++ b/resources/Schema/Components/Model.xml @@ -9,5 +9,5 @@ true true true - 3.0 + 1.0 \ No newline at end of file From 0a94373f3fd00aa2f8c2b18cd088dbae9e6090a0 Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Thu, 10 Mar 2016 14:38:20 +0100 Subject: [PATCH 17/24] The children of the CapturePointModels now also get their visibility on/off. This is done since a capturepoint is actually 2 models and not just 1 --- include/Game/Systems/CapturePointSystem.h | 1 + src/Game/Systems/CapturePointSystem.cpp | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/include/Game/Systems/CapturePointSystem.h b/include/Game/Systems/CapturePointSystem.h index 3cf72e15..6211ad49 100644 --- a/include/Game/Systems/CapturePointSystem.h +++ b/include/Game/Systems/CapturePointSystem.h @@ -30,6 +30,7 @@ private: bool CapturePointSystem::OnTriggerLeave(const Events::TriggerLeave& e); EventRelay m_ECaptured; bool CapturePointSystem::OnCaptured(const Events::Captured& e); + void ChangeCapturePointModelsVisibility(EntityWrapper &capturePointModels, bool isOwner); bool m_WinnerWasFound = false; //need to track these variables for the captureSystem to work as per design! diff --git a/src/Game/Systems/CapturePointSystem.cpp b/src/Game/Systems/CapturePointSystem.cpp index 4647d1b7..064136a7 100644 --- a/src/Game/Systems/CapturePointSystem.cpp +++ b/src/Game/Systems/CapturePointSystem.cpp @@ -109,9 +109,9 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp for (int i = 0; i < m_NumberOfCapturePoints; i++) { auto owner = (int)m_CapturePointNumberToEntityMap[i]["Team"]["Team"]; if (m_CapturePointNumberToEntityMap[i].FirstChildByName("Red").ID != EntityID_Invalid) { - (bool&)m_CapturePointNumberToEntityMap[i].FirstChildByName("Red")["Model"]["Visible"] = owner == redTeam ? true : false; - (bool&)m_CapturePointNumberToEntityMap[i].FirstChildByName("Blue")["Model"]["Visible"] = owner == blueTeam ? true : false; - (bool&)m_CapturePointNumberToEntityMap[i].FirstChildByName("Spectator")["Model"]["Visible"] = owner == spectatorTeam ? true : false; + ChangeCapturePointModelsVisibility(m_CapturePointNumberToEntityMap[i].FirstChildByName("Red"), owner == redTeam); + ChangeCapturePointModelsVisibility(m_CapturePointNumberToEntityMap[i].FirstChildByName("Blue"), owner == blueTeam); + ChangeCapturePointModelsVisibility(m_CapturePointNumberToEntityMap[i].FirstChildByName("Spectator"), owner == spectatorTeam); } } //save the next cap points and publish the captured event @@ -232,6 +232,14 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp } +void CapturePointSystem::ChangeCapturePointModelsVisibility(EntityWrapper &capturePointModels, bool isOwner) { + (bool&)capturePointModels["Model"]["Visible"] = isOwner; + for (auto& capModel : capturePointModels.ChildrenWithComponent("Model")) + { + (bool&)capModel["Model"]["Visible"] = isOwner; + } +} + bool CapturePointSystem::OnTriggerTouch(const Events::TriggerTouch& e) { //personEntered = e.Entity, thingEntered = e.Trigger From 4322a5d8dae2c9d1f9377d304f167cfb3d2353b8 Mon Sep 17 00:00:00 2001 From: Tleety Date: Thu, 10 Mar 2016 15:21:11 +0100 Subject: [PATCH 18/24] Some fixes for sprites --- include/Engine/Rendering/SpriteJob.h | 14 +- resources/Schema/Components/Sprite.xml | 2 + resources/Schema/Components/Sprite.xsd | 12 +- resources/Schema/Entities/OverwatchCamera.xml | 167 ++++++++++-------- src/Engine/Rendering/DrawFinalPass.cpp | 8 +- src/Engine/Rendering/TextureSprite.cpp | 2 +- 6 files changed, 124 insertions(+), 81 deletions(-) diff --git a/include/Engine/Rendering/SpriteJob.h b/include/Engine/Rendering/SpriteJob.h index 6b52144f..6ba2e63f 100644 --- a/include/Engine/Rendering/SpriteJob.h +++ b/include/Engine/Rendering/SpriteJob.h @@ -21,14 +21,23 @@ struct SpriteJob : RenderJob SpriteJob(ComponentWrapper cSprite, Camera* camera, glm::mat4 matrix, World* world, glm::vec4 fillColor, float fillPercentage, bool depthSorted, bool isIndicator) : RenderJob() { - Model = ResourceManager::Load<::Model>("Models/Core/UnitQuad.mesh"); + Model = ResourceManager::Load<::Model>((std::string)cSprite["Model"]); ::RawModel::MaterialProperties matProp = Model->MaterialGroups().front(); TextureID = 0; DiffuseTexture = CommonFunctions::TryLoadResource(cSprite["DiffuseTexture"]); - IncandescenceTexture = CommonFunctions::TryLoadResource(cSprite["GlowMap"]); + if ((bool)cSprite["Linear"]) { + glBindTexture(GL_TEXTURE_2D, DiffuseTexture->m_Texture); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + } else { + glBindTexture(GL_TEXTURE_2D, DiffuseTexture->m_Texture); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + } + StartIndex = matProp.material->StartIndex; EndIndex = matProp.material->EndIndex; Matrix = matrix; @@ -89,6 +98,7 @@ struct SpriteJob : RenderJob bool BlurBackground = false; float ScaleX = 1; float ScaleY = 1; + bool Linear = false; glm::vec4 FillColor = glm::vec4(0); float FillPercentage = 0.0; diff --git a/resources/Schema/Components/Sprite.xml b/resources/Schema/Components/Sprite.xml index 2c0465e9..a1963ff8 100644 --- a/resources/Schema/Components/Sprite.xml +++ b/resources/Schema/Components/Sprite.xml @@ -1,5 +1,6 @@ + Models/Core/UnitQuad.mesh @@ -8,5 +9,6 @@ false false false + false false diff --git a/resources/Schema/Components/Sprite.xsd b/resources/Schema/Components/Sprite.xsd index eab74bfc..af4860c8 100644 --- a/resources/Schema/Components/Sprite.xsd +++ b/resources/Schema/Components/Sprite.xsd @@ -9,14 +9,17 @@ + + The model the sprite will use. + - Diffuse Texture file + Diffuse Texture file. - GlowMap file + GlowMap file. - Color tint + Color tint. Whether the model is visible or not @@ -33,6 +36,9 @@ Keep a 1:1 ratio between X and Y. + + If it should use Linear or Nearest sampling method. + Wether the background should be blurred begind this sprite. diff --git a/resources/Schema/Entities/OverwatchCamera.xml b/resources/Schema/Entities/OverwatchCamera.xml index 6c93f033..92540e5b 100644 --- a/resources/Schema/Entities/OverwatchCamera.xml +++ b/resources/Schema/Entities/OverwatchCamera.xml @@ -8,7 +8,7 @@ - + @@ -34,13 +34,49 @@ + + + + + false + Models/Core/UnitQuad.mesh + + Textures/Icons/Classes/Assault-01.png + + + PickClass + 1 + + + + + + + + + + + Assault + Fonts/DroidSans.ttf,64 + + + + + + + + + + + - Textures/Icons/Classes/Defender-01.png - false + Models/Core/UnitQuad.mesh + + Textures/Icons/Classes/Defender-01.png PickClass @@ -72,9 +108,10 @@ - Textures/Icons/Classes/Sniper-01.png - false + Models/Core/UnitQuad.mesh + + Textures/Icons/Classes/Sniper-01.png PickClass @@ -102,40 +139,6 @@ - - - - - Textures/Icons/Classes/Assault-01.png - - false - - - PickClass - 1 - - - - - - - - - - - Assault - Fonts/DroidSans.ttf,64 - - - - - - - - - - - @@ -154,9 +157,10 @@ - Textures/Core/UnitHexagon.png - false + Models/Core/UnitQuad.mesh + + Textures/Core/UnitHexagon.png @@ -232,9 +236,10 @@ - Textures/Core/UnitHexagon.png - false + Models/Core/UnitQuad.mesh + + Textures/Core/UnitHexagon.png @@ -266,10 +271,11 @@ - Textures/Core/UnitHexagon.png + Models/Core/UnitQuad.mesh - false + Textures/Core/UnitHexagon.png + true PickTeam @@ -300,10 +306,12 @@ - Textures/Core/UnitHexagon.png - false + Models/Core/UnitQuad.mesh + + Textures/Core/UnitHexagon.png + true PickTeam @@ -334,9 +342,10 @@ - Textures/Core/UnitHexagon.png - false + Models/Core/UnitQuad.mesh + + Textures/Core/UnitHexagon.png false @@ -422,9 +431,10 @@ - Textures/Core/UnitHexagon.png - false + Models/Core/UnitQuad.mesh + + Textures/Core/UnitHexagon.png @@ -441,9 +451,10 @@ 3 - Textures/Core/UnitHexagon_Rotated.png - false + Models/Core/UnitQuad.mesh + + Textures/Core/UnitHexagon_Rotated.png @@ -458,9 +469,10 @@ - Textures/Core/UnitHexagon.png - false + Models/Core/UnitQuad.mesh + + Textures/Core/UnitHexagon.png @@ -477,9 +489,10 @@ 4 - Textures/Core/UnitHexagon_Rotated.png - false + Models/Core/UnitQuad.mesh + + Textures/Core/UnitHexagon_Rotated.png @@ -494,9 +507,10 @@ - Textures/Core/UnitHexagon.png - false + Models/Core/UnitQuad.mesh + + Textures/Core/UnitHexagon.png @@ -513,9 +527,10 @@ 2 - Textures/Core/UnitHexagon_Rotated.png - false + Models/Core/UnitQuad.mesh + + Textures/Core/UnitHexagon_Rotated.png @@ -530,9 +545,10 @@ - Textures/Core/UnitHexagon.png - false + Models/Core/UnitQuad.mesh + + Textures/Core/UnitHexagon.png @@ -550,9 +566,10 @@ 1 - Textures/Core/UnitHexagon_Rotated.png - false + Models/Core/UnitQuad.mesh + + Textures/Core/UnitHexagon_Rotated.png @@ -567,9 +584,10 @@ - Textures/Core/UnitHexagon.png - false + Models/Core/UnitQuad.mesh + + Textures/Core/UnitHexagon.png @@ -584,9 +602,10 @@ - Textures/Core/UnitHexagon_Rotated.png - false + Models/Core/UnitQuad.mesh + + Textures/Core/UnitHexagon_Rotated.png @@ -604,9 +623,10 @@ - Textures/Core/UnitHexagon.png - false + Models/Core/UnitQuad.mesh + + Textures/Core/UnitHexagon.png @@ -651,9 +671,10 @@ - Textures/Core/UnitHexagon.png - false + Models/Core/UnitQuad.mesh + + Textures/Core/UnitHexagon.png diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index a18bd411..a685a6d3 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -1271,14 +1271,15 @@ void DrawFinalPass::DrawSprites(std::list>&jobs, Rend glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix())); glUniform3fv(glGetUniformLocation(shaderHandle, "CameraPos"), 1, glm::value_ptr(scene.Camera->Position())); + RenderState* jobState = new RenderState(); + for(auto& job : jobs) { auto spriteJob = std::dynamic_pointer_cast(job); - RenderState jobState; if (spriteJob) { if(spriteJob->Depth == 0) { - jobState.Disable(GL_DEPTH_TEST); + jobState->Disable(GL_DEPTH_TEST); } glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "PVM"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix() * scene.Camera->ViewMatrix() * spriteJob->Matrix)); glUniform4fv(glGetUniformLocation(shaderHandle, "Color"), 1, glm::value_ptr(spriteJob->Color)); @@ -1294,6 +1295,8 @@ void DrawFinalPass::DrawSprites(std::list>&jobs, Rend glBindTexture(GL_TEXTURE_2D, m_ErrorTexture->m_Texture); } + + glActiveTexture(GL_TEXTURE2); if (spriteJob->IncandescenceTexture != nullptr) { glBindTexture(GL_TEXTURE_2D, spriteJob->IncandescenceTexture->m_Texture); @@ -1307,6 +1310,7 @@ void DrawFinalPass::DrawSprites(std::list>&jobs, Rend glDrawElements(GL_TRIANGLES, spriteJob->EndIndex - spriteJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(spriteJob->StartIndex*sizeof(unsigned int))); } } + delete jobState; // m_SpriteProgram->Unbind(); } diff --git a/src/Engine/Rendering/TextureSprite.cpp b/src/Engine/Rendering/TextureSprite.cpp index 2a43e455..70d086cd 100644 --- a/src/Engine/Rendering/TextureSprite.cpp +++ b/src/Engine/Rendering/TextureSprite.cpp @@ -6,6 +6,6 @@ TextureSprite::TextureSprite(std::string path) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST_MIPMAP_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); GLERROR("Texture load"); } \ No newline at end of file From 7e6288c597e42c6a04a25e80f040e2d965a0394a Mon Sep 17 00:00:00 2001 From: Tleety Date: Thu, 10 Mar 2016 15:36:33 +0100 Subject: [PATCH 19/24] Some merge fixes and some sprite fixes. --- include/Engine/Rendering/SpriteJob.h | 28 ++++++++----------- .../Shaders/CombineGaussianTexture.frag.glsl | 9 ------ src/Engine/Rendering/DrawFinalPass.cpp | 10 +++++-- 3 files changed, 19 insertions(+), 28 deletions(-) diff --git a/include/Engine/Rendering/SpriteJob.h b/include/Engine/Rendering/SpriteJob.h index 6ba2e63f..3d55e721 100644 --- a/include/Engine/Rendering/SpriteJob.h +++ b/include/Engine/Rendering/SpriteJob.h @@ -28,15 +28,7 @@ struct SpriteJob : RenderJob DiffuseTexture = CommonFunctions::TryLoadResource(cSprite["DiffuseTexture"]); IncandescenceTexture = CommonFunctions::TryLoadResource(cSprite["GlowMap"]); - if ((bool)cSprite["Linear"]) { - glBindTexture(GL_TEXTURE_2D, DiffuseTexture->m_Texture); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - } else { - glBindTexture(GL_TEXTURE_2D, DiffuseTexture->m_Texture); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - } + Linear = (bool)cSprite["Linear"]; StartIndex = matProp.material->StartIndex; EndIndex = matProp.material->EndIndex; @@ -60,21 +52,23 @@ struct SpriteJob : RenderJob glm::vec3 scale = Transform::AbsoluteScale(world, cSprite.EntityID); - if((bool)cSprite["KeepRatioX"] == true) { - ScaleX = scale.x; - } - if ((bool)cSprite["KeepRatioY"] == true) { - ScaleY = scale.y; - } if((bool)cSprite["KeepRatio"] == true) { if(scale.y >= scale.x) { ScaleY = (scale.x)/(scale.y); - ScaleX = 1; + ScaleX = 1.f; } else { - ScaleY = 1; + ScaleY = 1.f; ScaleX = (scale.x)/(scale.y); } + } else { + if ((bool)cSprite["KeepRatioX"] == true) { + ScaleX = scale.x; + } + if ((bool)cSprite["KeepRatioY"] == true) { + ScaleY = scale.y; + } } + }; unsigned int TextureID; diff --git a/resources/Shaders/CombineGaussianTexture.frag.glsl b/resources/Shaders/CombineGaussianTexture.frag.glsl index b6806493..93c36fb8 100644 --- a/resources/Shaders/CombineGaussianTexture.frag.glsl +++ b/resources/Shaders/CombineGaussianTexture.frag.glsl @@ -18,13 +18,4 @@ void main() result += textureLod(Texture, Input.TextureCoordinate, i); } fragmentColor = result; -/* - vec4 texel0 = textureLod(Texture, Input.TextureCoordinate, 0); - vec4 texel1 = textureLod(Texture, Input.TextureCoordinate, 1); - vec4 texel2 = textureLod(Texture, Input.TextureCoordinate, 2); - vec4 texel3 = textureLod(Texture, Input.TextureCoordinate, 3); - vec4 texel4 = textureLod(Texture, Input.TextureCoordinate, 4); - - fragmentColor = texel0 + texel1 + texel2 + texel3 + texel4;*/ - } diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index a685a6d3..d03b0c2b 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -1291,12 +1291,18 @@ void DrawFinalPass::DrawSprites(std::list>&jobs, Rend glActiveTexture(GL_TEXTURE1); if (spriteJob->DiffuseTexture != nullptr) { glBindTexture(GL_TEXTURE_2D, spriteJob->DiffuseTexture->m_Texture); + if (spriteJob->Linear) { + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + } else { + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + } + } else { glBindTexture(GL_TEXTURE_2D, m_ErrorTexture->m_Texture); } - - glActiveTexture(GL_TEXTURE2); if (spriteJob->IncandescenceTexture != nullptr) { glBindTexture(GL_TEXTURE_2D, spriteJob->IncandescenceTexture->m_Texture); From e734d0c953f7912caa57810a7cc629377a79f0c5 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Thu, 10 Mar 2016 15:47:32 +0100 Subject: [PATCH 20/24] Oops. --- include/Engine/Rendering/Util/GLError.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/Engine/Rendering/Util/GLError.h b/include/Engine/Rendering/Util/GLError.h index 8efe45f3..740a5a3c 100644 --- a/include/Engine/Rendering/Util/GLError.h +++ b/include/Engine/Rendering/Util/GLError.h @@ -16,7 +16,7 @@ inline bool _GLERROR(const char* info, const char* file, const char* func, unsig return false; } -#ifndef DEBUG +#ifdef DEBUG #define GLERROR(function) \ _GLERROR(function, __BASE_FILE__, __func__, __LINE__) #else From 78129cf432a0bb46ab3b89cd81048e90080c0f11 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Thu, 10 Mar 2016 15:47:47 +0100 Subject: [PATCH 21/24] Fixed picking depth values after depth buffer was changed to a texture. --- src/Engine/Rendering/PickingPass.cpp | 2 +- src/Engine/Rendering/Util/ScreenCoords.cpp | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Engine/Rendering/PickingPass.cpp b/src/Engine/Rendering/PickingPass.cpp index 93783e19..820c184e 100644 --- a/src/Engine/Rendering/PickingPass.cpp +++ b/src/Engine/Rendering/PickingPass.cpp @@ -24,7 +24,7 @@ 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_DEPTH_COMPONENT32, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT); + glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT); } void PickingPass::InitializeFrameBuffers() diff --git a/src/Engine/Rendering/Util/ScreenCoords.cpp b/src/Engine/Rendering/Util/ScreenCoords.cpp index a858524d..a8d8a662 100644 --- a/src/Engine/Rendering/Util/ScreenCoords.cpp +++ b/src/Engine/Rendering/Util/ScreenCoords.cpp @@ -36,10 +36,6 @@ ScreenCoords::PixelData ScreenCoords::ToPixelData(float x, float y, FrameBuffer* unsigned char pdata[3]; glReadPixels(x, y, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &pdata); GLERROR("glReadPixels(pdata) Error"); - PickDataBuffer->Unbind(); - GLERROR("Unbind Error"); - glBindFramebuffer(GL_FRAMEBUFFER, DepthBuffer); - GLERROR("glBindFramebuffer(DepthBuffer) Error"); float depthData; glReadPixels(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depthData); GLERROR("glReadPixels(depthData) Error"); From 038a706e28255b9f8a2406a3e96c445a9996b6f1 Mon Sep 17 00:00:00 2001 From: William Moberg Date: Thu, 10 Mar 2016 16:05:30 +0100 Subject: [PATCH 22/24] Don't collide against disabled (invisible) models. Triggers uses model vs. box instead of only box vs. box. --- include/Engine/Collision/Collision.h | 12 +++++ src/Engine/Collision/Collision.cpp | 63 ++++++++++++++++++------ src/Engine/Collision/CollisionSystem.cpp | 10 +++- src/Engine/Collision/TriggerSystem.cpp | 41 +++++++++++---- 4 files changed, 101 insertions(+), 25 deletions(-) diff --git a/include/Engine/Collision/Collision.h b/include/Engine/Collision/Collision.h index 9e1a81db..c616df6b 100644 --- a/include/Engine/Collision/Collision.h +++ b/include/Engine/Collision/Collision.h @@ -84,6 +84,18 @@ bool AABBvsTriangles(const AABB& box, const std::vector& modelIndices, const glm::mat4& modelMatrix); +enum Output +{ + OutContained, + OutSeparated, + OutIntersecting +}; +//Detects intersection and containment. +Output AABBvsTrianglesWContainment(const AABB& box, + const RawModel::Vertex* modelVertices, + const std::vector& modelIndices, + const glm::mat4& modelMatrix); + //Return true if the boxes are intersecting. bool AABBVsAABB(const AABB& a, const AABB& b); //Return true if the boxes are intersecting. diff --git a/src/Engine/Collision/Collision.cpp b/src/Engine/Collision/Collision.cpp index 68d99d92..f12435fe 100644 --- a/src/Engine/Collision/Collision.cpp +++ b/src/Engine/Collision/Collision.cpp @@ -360,7 +360,14 @@ constexpr bool FaceIsGround(float faceNormalY) //An array containing 3 int pairs { 0, 2 }, { 0, 1 }, { 1, 2 } constexpr std::array, 3> dimensionPairs({ std::pair(0, 2), std::pair(0, 1), std::pair(1, 2) }); -bool AABBvsTriangle(const AABB& box, +enum class BoxTriRes +{ + Front, + Behind, + Intersect +}; + +BoxTriRes AABBvsTriangle(const AABB& box, const std::array& triPos, const glm::vec3& originalBoxVelocity, float verticalStepHeight, @@ -374,7 +381,7 @@ bool AABBvsTriangle(const AABB& box, //Less checks, and we should be able to walk out from models if we are trapped inside. glm::vec3 triNormal = glm::cross(triPos[1] - triPos[0], triPos[2] - triPos[0]); if (!vectorHasLength(triNormal) || (glm::dot(triNormal, originalBoxVelocity) > 0)) { - return false; + return BoxTriRes::Behind; } triNormal = glm::normalize(triNormal); @@ -409,6 +416,9 @@ bool AABBvsTriangle(const AABB& box, const glm::vec3& min = box.MinCorner(); const glm::vec3& max = box.MaxCorner(); + // If there is no intersection, whether the box center is in front of or behind the triangle. + BoxTriRes noIntersection = glm::dot(triNormal, origin - triPos[0]) > 0 ? BoxTriRes::Front : BoxTriRes::Behind; + //For each projection in xy-, xz-, and yx-planes. for (std::pair dim : dimensionPairs) { //2D Triangle. @@ -426,7 +436,7 @@ bool AABBvsTriangle(const AABB& box, bool pushedFromTriangleLine; //if projections don't overlap, return false. if (!rectangleVsTriangle(boxMin, boxMax, t2D, resolutionVector, resolutionDist, pushedFromTriangleLine)) { - return false; + return noIntersection; } else if (resolveCollision) { //Overwrite the smallest resolution if this is smaller. if (resolutionDist < resolveShortest.DistanceSq) { @@ -462,11 +472,11 @@ bool AABBvsTriangle(const AABB& box, float t = glm::dot(triNormal, triPos[0] - origin) / glm::dot(triNormal, diagonal); //If intersection point between plane and diagonal is within the box. if (glm::abs(t) > 1) { - return false; + return noIntersection; } if (!resolveCollision) { - return true; + return BoxTriRes::Intersect; } glm::vec3 cornerResolution = (1+t) * diagonal; @@ -498,7 +508,7 @@ bool AABBvsTriangle(const AABB& box, case ResolveDimZ: //If we get here, the resolution is along one coordinate axis. //set velocity to 0 in y if it is along y-axis. - return true; + return BoxTriRes::Intersect; case Line: projNorm = glm::normalize(outResolution); break; @@ -533,10 +543,10 @@ bool AABBvsTriangle(const AABB& box, boxVelocity = boxVelocity - glm::dot(boxVelocity, projNorm) * projNorm; } } - return true; + return BoxTriRes::Intersect; } -bool AABBvsTriangles(const AABB& box, +Output AABBvsTriangles(const AABB& box, const RawModel::Vertex* modelVertices, const std::vector& modelIndices, const glm::mat4& modelMatrix, @@ -546,8 +556,8 @@ bool AABBvsTriangles(const AABB& box, glm::vec3& outResolutionVector, bool resolveCollision) { - bool hit = false; - + bool intersect = false; + Output out = Output::OutContained; bool everHitTheGround = false; AABB newBox = box; outResolutionVector = glm::vec3(0.f); @@ -560,20 +570,27 @@ bool AABBvsTriangles(const AABB& box, }; glm::vec3 outVec; bool collideWithGround = isOnGround; - if (AABBvsTriangle(newBox, triVertices, originalBoxVelocity, verticalStepHeight, collideWithGround, boxVelocity, outVec, resolveCollision)) { - hit = true; + switch (AABBvsTriangle(newBox, triVertices, originalBoxVelocity, verticalStepHeight, collideWithGround, boxVelocity, outVec, resolveCollision)) { + case Collision::BoxTriRes::Front: + out = Output::OutSeparated; + break; + case Collision::BoxTriRes::Intersect: + intersect = true; outResolutionVector += outVec; newBox = AABB::FromOriginSize(newBox.Origin() + outVec, newBox.Size()); if (collideWithGround) { everHitTheGround = isOnGround = true; } + break; + default: + break; } } if (!everHitTheGround) { isOnGround = false; } - return hit; + return intersect ? Output::OutIntersecting : out; } bool AABBvsTriangles(const AABB& box, @@ -593,13 +610,31 @@ bool AABBvsTriangles(const AABB& box, verticalStepHeight, isOnGround, outResolutionVector, - true); + true) == Output::OutIntersecting; } bool AABBvsTriangles(const AABB& box, const RawModel::Vertex* modelVertices, const std::vector& modelIndices, const glm::mat4& modelMatrix) +{ + glm::vec3 vel, outres; + bool g; + return AABBvsTriangles(box, + modelVertices, + modelIndices, + modelMatrix, + vel, + 0.f, + g, + outres, + false) == Output::OutIntersecting; +} + +Output AABBvsTrianglesWContainment(const AABB& box, + const RawModel::Vertex* modelVertices, + const std::vector& modelIndices, + const glm::mat4& modelMatrix) { glm::vec3 vel, outres; bool g; diff --git a/src/Engine/Collision/CollisionSystem.cpp b/src/Engine/Collision/CollisionSystem.cpp index 53cabfac..7bf76a2e 100644 --- a/src/Engine/Collision/CollisionSystem.cpp +++ b/src/Engine/Collision/CollisionSystem.cpp @@ -37,6 +37,10 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c bool hit; float dist; if (boxB.Entity.HasComponent("Model")) { + if (!((bool)boxB.Entity["Model"]["Visible"])) { + // Don't collide against invisible models. + continue; + } RawModel* model; std::string res = (std::string)boxB.Entity["Model"]["Resource"]; try { @@ -77,7 +81,11 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c } if (boxB.Entity.HasComponent("Model") && Collision::AABBVsAABB(boxA, boxB)) { - //Here we know boxB is a entity with Collideable, AABB, and Model. + // Here we know boxB is a entity with Collideable, AABB, and Model. + if (!((bool)boxB.Entity["Model"]["Visible"])) { + // Don't collide against invisible models. + continue; + } RawModel* model; try { model = ResourceManager::Load(boxB.Entity["Model"]["Resource"]); diff --git a/src/Engine/Collision/TriggerSystem.cpp b/src/Engine/Collision/TriggerSystem.cpp index 21a47721..ef18629a 100644 --- a/src/Engine/Collision/TriggerSystem.cpp +++ b/src/Engine/Collision/TriggerSystem.cpp @@ -10,6 +10,16 @@ void TriggerSystem::UpdateComponent(EntityWrapper& triggerEntity, ComponentWrapp return; } + RawModel* triggerModel = nullptr; + glm::mat4 triggerModelMat; + if (triggerEntity.HasComponent("Model")) { + try { + triggerModel = ResourceManager::Load(triggerEntity["Model"]["Resource"]); + triggerModelMat = Transform::ModelMatrix(triggerEntity); + } catch (const std::exception&) { + } + } + m_OctreeOut.clear(); m_Octree->ObjectsInSameRegion(*triggerBox, m_OctreeOut); @@ -22,7 +32,17 @@ void TriggerSystem::UpdateComponent(EntityWrapper& triggerEntity, ComponentWrapp if (colliderFitsInTrigger) { completelyInsideBox = AABB::FromOriginSize((*triggerBox).Origin(), (*triggerBox).Size() - 2.0f * colliderBox.Size()); } - if (colliderFitsInTrigger && Collision::AABBVsAABB(completelyInsideBox, colliderBox)) { + + // We know the entity is inside the trigger box, but perhaps not the model yet. + Collision::Output out = triggerModel == nullptr + ? Collision::Output::OutContained + : Collision::AABBvsTrianglesWContainment( + colliderBox, + triggerModel->Vertices(), + triggerModel->m_Indices, + triggerModelMat); + + if (colliderFitsInTrigger && Collision::AABBVsAABB(completelyInsideBox, colliderBox) && out == Collision::Output::OutContained) { // Entity is completely inside the trigger. // If it was only touching before, it is erased. m_EntitiesTouchingTrigger[triggerEntity].erase(colliderEntity); @@ -32,7 +52,8 @@ void TriggerSystem::UpdateComponent(EntityWrapper& triggerEntity, ComponentWrapp completeSet.insert(colliderEntity); publish(colliderEntity, triggerEntity); } - } else { + continue; + } else if (out != Collision::Output::OutSeparated) { // Entity is only touching the trigger. auto& touchSet = m_EntitiesTouchingTrigger[triggerEntity]; auto& completeSet = m_EntitiesCompletelyInTrigger[triggerEntity]; @@ -47,17 +68,17 @@ void TriggerSystem::UpdateComponent(EntityWrapper& triggerEntity, ComponentWrapp touchSet.insert(colliderEntity); } // Else, it was touching the trigger last frame too and nothing is done. - } - } else { - // Entity is not touching the trigger, - // Throw event if it was previously. - if (throwLeaveIfWasInTrigger(m_EntitiesTouchingTrigger[triggerEntity], colliderEntity, triggerEntity)) { continue; } - // This only occurs if the entity was completely inside the trigger one frame, - // then completely outside the trigger, e.g. when dying and respawning. - throwLeaveIfWasInTrigger(m_EntitiesCompletelyInTrigger[triggerEntity], colliderEntity, triggerEntity); } + // Only get here if entity is not touching the trigger, + // throw event if it was touching previously. + if (throwLeaveIfWasInTrigger(m_EntitiesTouchingTrigger[triggerEntity], colliderEntity, triggerEntity)) { + continue; + } + // This only occurs if the entity was completely inside the trigger one frame, + // then completely outside the trigger, e.g. when dying and respawning. + throwLeaveIfWasInTrigger(m_EntitiesCompletelyInTrigger[triggerEntity], colliderEntity, triggerEntity); } } From 8b89df00955b2c67cff0afa05ab88b9a957fa446 Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Thu, 10 Mar 2016 16:09:54 +0100 Subject: [PATCH 23/24] Changed to a better validator --- assets | 2 +- .../Entities/aim_rays_with_capturep.xml | 19 +++++++++++++++++-- src/Game/Systems/CapturePointSystem.cpp | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/assets b/assets index 3af64d8b..007b54bd 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 3af64d8b1f8cdf3e20198b079dfc02f6d64fdc88 +Subproject commit 007b54bd678d0e80af878bed457e33e73bc0834a diff --git a/resources/Schema/Entities/aim_rays_with_capturep.xml b/resources/Schema/Entities/aim_rays_with_capturep.xml index 6aa3246a..3cf5a26a 100644 --- a/resources/Schema/Entities/aim_rays_with_capturep.xml +++ b/resources/Schema/Entities/aim_rays_with_capturep.xml @@ -99,7 +99,7 @@ - Schema/Entities/Player.xml + Schema/Entities/PlayerRed.xml @@ -225,6 +225,11 @@ + + + + false + @@ -239,7 +244,17 @@ - + + + + + + + + + + + diff --git a/src/Game/Systems/CapturePointSystem.cpp b/src/Game/Systems/CapturePointSystem.cpp index 064136a7..13ac59f3 100644 --- a/src/Game/Systems/CapturePointSystem.cpp +++ b/src/Game/Systems/CapturePointSystem.cpp @@ -108,7 +108,7 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp //change what model is displaying (change all in case 2 capturepoints has been captured on the same frame) for (int i = 0; i < m_NumberOfCapturePoints; i++) { auto owner = (int)m_CapturePointNumberToEntityMap[i]["Team"]["Team"]; - if (m_CapturePointNumberToEntityMap[i].FirstChildByName("Red").ID != EntityID_Invalid) { + if (m_CapturePointNumberToEntityMap[i].FirstChildByName("Red").Valid()) { ChangeCapturePointModelsVisibility(m_CapturePointNumberToEntityMap[i].FirstChildByName("Red"), owner == redTeam); ChangeCapturePointModelsVisibility(m_CapturePointNumberToEntityMap[i].FirstChildByName("Blue"), owner == blueTeam); ChangeCapturePointModelsVisibility(m_CapturePointNumberToEntityMap[i].FirstChildByName("Spectator"), owner == spectatorTeam); From e35b09cc68c5005dd6c48e0bf1319033b8ac1236 Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Thu, 10 Mar 2016 21:59:01 +0100 Subject: [PATCH 24/24] Add alpha clipping Tobbe sa att jag fick pusha direkt --- src/Engine/Rendering/DrawFinalPassState.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Engine/Rendering/DrawFinalPassState.cpp b/src/Engine/Rendering/DrawFinalPassState.cpp index 5c238985..811d9d84 100644 --- a/src/Engine/Rendering/DrawFinalPassState.cpp +++ b/src/Engine/Rendering/DrawFinalPassState.cpp @@ -10,6 +10,8 @@ DrawFinalPassState::DrawFinalPassState(GLuint frameBuffer) Enable(GL_DEPTH_TEST); DepthMask(GL_TRUE); Enable(GL_CULL_FACE); + Enable(GL_ALPHA_TEST); + AlphaFunc(GL_GEQUAL, 0.05f); // Enable(GL_STENCIL_TEST); // StencilFunc(GL_NOTEQUAL, 1, 0xFF); // StencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);