diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index e3d86ea..09e535c 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -70,26 +70,26 @@ void GameWorld::Initialize() EventBroker->Publish(e); } - { - auto road_base = CreateEntity(); - auto transform = AddComponent(road_base); - transform->Position = glm::vec3(0, -50, 0); - auto model = AddComponent(road_base); - model->ModelFile = "Models/TerrainFiveIstles/Roads/BaseRoad.obj"; - auto physics = AddComponent(road_base); - physics->Mass = 10; - physics->Static = true; - physics->CollisionLayer = 1; - - auto groundshape = CreateEntity(road_base); - auto transformshape = AddComponent(groundshape); - auto meshShape = AddComponent(groundshape); - meshShape->ResourceName = "Models/TerrainFiveIstles/Roads/BaseRoad.obj"; - - - CommitEntity(groundshape); - CommitEntity(road_base); - } + { + auto road_base = CreateEntity(); + auto transform = AddComponent(road_base); + transform->Position = glm::vec3(0, -50, 0); + auto model = AddComponent(road_base); + model->ModelFile = "Models/TerrainFiveIstles/Roads/BaseRoad.obj"; + auto physics = AddComponent(road_base); + physics->Mass = 10; + physics->Static = true; + physics->CollisionLayer = 1; + + auto groundshape = CreateEntity(road_base); + auto transformshape = AddComponent(groundshape); + auto meshShape = AddComponent(groundshape); + meshShape->ResourceName = "Models/TerrainFiveIstles/Roads/BaseRoad.obj"; + + + CommitEntity(groundshape); + CommitEntity(road_base); + } { auto road_middle = CreateEntity(); @@ -143,13 +143,10 @@ void GameWorld::Initialize() auto model = AddComponent(water); model->ModelFile = "Models/Placeholders/PhysicsTest/Cube.obj"; auto blendmap = AddComponent(water); - blendmap->TextureRed = "Textures/Ground/WaterPlain0017_6_S.png"; - blendmap->TextureRedNormal = "Textures/Ground/SoilBeach0087_11_SNM.png"; - blendmap->TextureGreen = "Textures/Ground/WaterPlain0017_6_S.jpg"; - blendmap->TextureGreenNormal = "Textures/Ground/Grass0126_2_SNM.png"; - blendmap->TextureBlue = "Textures/Ground/WaterPlain0017_6_S.png"; - blendmap->TextureBlueNormal = "Textures/Ground/Cliffs2NM.png"; - blendmap->TextureRepeats = 400.f; + blendmap->TextureRed = "Textures/Skybox/Sky34/bottom.jpg"; + blendmap->TextureGreen = "Textures/Skybox/Sky34/bottom.jpg"; + blendmap->TextureBlue = "Textures/Skybox/Sky34/bottom.jpg"; + blendmap->TextureRepeats = 1.f; auto physics = AddComponent(water); physics->Mass = 10; @@ -327,11 +324,33 @@ void GameWorld::Initialize() { auto tree = CreateEntity(); auto transform = AddComponent(tree); - transform->Position = glm::vec3(0, -15, 0); + transform->Position = glm::vec3(0, -10, 0); auto model = AddComponent(tree); - model->ModelFile = "Models/Tree/leafs/Leafs.obj"; + model->ModelFile = "Models/Tree/Stem/Stem.obj"; + auto physics = AddComponent(tree); + physics->Mass = 100.f; + physics->Static = false; + physics->CalculateCenterOfMass = true; + { + auto leafs = CreateEntity(tree); + auto transform = AddComponent(leafs); + auto model = AddComponent(leafs); + model->ModelFile = "Models/Tree/Leafs/Leafs.obj"; model->Transparent = true; + CommitEntity(leafs); + } + { + auto shape = CreateEntity(tree); + auto transform = AddComponent(shape); + auto box = AddComponent(shape); + transform->Position = glm::vec3(0.f, 0.f, 2.29552f); + box->Width = 0.296f; + box->Height = 2.511f; + box->Depth = 0.296f; + + CommitEntity(shape); + } CommitEntity(tree); } diff --git a/src/GameWorld.h b/src/GameWorld.h index 3837c77..aae2472 100755 --- a/src/GameWorld.h +++ b/src/GameWorld.h @@ -34,7 +34,6 @@ #include "Components/Template.h" #include "Components/Transform.h" #include "Components/Viewport.h" -#include "Components/BlendMap.h" #include "Components/Physics.h" #include "Components/SphereShape.h" diff --git a/src/RenderQueue.h b/src/RenderQueue.h index 932dd69..2636f84 100644 --- a/src/RenderQueue.h +++ b/src/RenderQueue.h @@ -14,6 +14,9 @@ struct RenderJob { friend class RenderQueue; + glm::mat4 ModelMatrix; + float Depth; + protected: uint64_t Hash; @@ -37,7 +40,6 @@ struct ModelJob : RenderJob GLuint VAO; unsigned int StartIndex; unsigned int EndIndex; - glm::mat4 ModelMatrix; float Transparent; void CalculateHash() override @@ -67,7 +69,6 @@ struct SpriteJob : RenderJob GLuint Texture; glm::vec4 Color; - glm::mat4 ModelMatrix; void CalculateHash() override { @@ -82,31 +83,30 @@ public: void Add(T &job) { job.CalculateHash(); - m_Jobs.push_front(std::shared_ptr(new T(job))); + Jobs.push_front(std::shared_ptr(new T(job))); } void Sort() { - m_Jobs.sort(); + Jobs.sort(); } void Clear() { - m_Jobs.clear(); + Jobs.clear(); } std::forward_list>::const_iterator begin() { - return m_Jobs.begin(); + return Jobs.begin(); } std::forward_list>::const_iterator end() { - return m_Jobs.end(); + return Jobs.end(); } -private: - std::forward_list> m_Jobs; + std::forward_list> Jobs; }; struct RenderQueuePair diff --git a/src/Renderer.cpp b/src/Renderer.cpp index 62626b7..142f7ec 100755 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -18,7 +18,7 @@ Renderer::Renderer(std::shared_ptr<::ResourceManager> resourceManager) CAtt = 1.0f; LAtt = 0.0f; QAtt = 3.0f; - m_ShadowMapRes = 2048*2; + m_ShadowMapRes = 1; m_SunPosition = glm::vec3(0.f, 1.0f, 0.5f); m_SunTarget = glm::vec3(0, 0, 0); m_SunProjection_height = glm::vec2(-40.f, 40.f); @@ -163,7 +163,7 @@ void Renderer::LoadContent() FrameBufferTextures(); m_sphereModel = ResourceManager->Load("Model", "Models/Placeholders/PhysicsTest/Sphere.obj"); - m_Skybox = std::make_shared("Textures/Skybox/Sky34", "jpg"); + m_Skybox = std::make_shared("Textures/Skybox/sky36", "jpg"); } void Renderer::Draw(double dt) @@ -369,6 +369,17 @@ void Renderer::DrawWorld(RenderQueuePair &rq) glDepthMask(GL_TRUE); glEnable(GL_SCISSOR_TEST); + //Sort forward rendering items by z value. + for(auto job : rq.Forward) + { + glm::mat4 cameraProjection = m_Camera->ProjectionMatrix((float)m_Viewport.Width / m_Viewport.Height); + glm::mat4 cameraMatrix = cameraProjection * m_Camera->ViewMatrix(); + + glm::vec3 spritePos = glm::vec3(cameraMatrix * job->ModelMatrix * glm::vec4(1, 1, 1, 0)); + job->Depth = spritePos.z; + } + rq.Forward.Jobs.sort(Renderer::DepthSort); + //DrawShadowMap(rq.Deferred); /* @@ -392,7 +403,7 @@ void Renderer::DrawWorld(RenderQueuePair &rq) glCullFace(GL_BACK); glEnable(GL_DEPTH_TEST); - //DrawSkybox(); + DrawSkybox(); DrawFBOScene(rq.Deferred); /* @@ -512,6 +523,8 @@ void Renderer::ForwardRendering(RenderQueue &rq) continue; } + + auto spriteJob = std::dynamic_pointer_cast(job); if (spriteJob) { diff --git a/src/Renderer.h b/src/Renderer.h index 445601f..dacc6db 100755 --- a/src/Renderer.h +++ b/src/Renderer.h @@ -201,7 +201,8 @@ private: void CreateNormalMapTangent(); void ForwardRendering(RenderQueue &rq); - + static bool DepthSort(const std::shared_ptr &i, const std::shared_ptr &j) { return (i->Depth < j->Depth); } + GLuint CreateQuad(); void DrawDebugShadowMap(); GLuint CreateAABB(); diff --git a/src/Systems/TankSteeringSystem.cpp b/src/Systems/TankSteeringSystem.cpp index cc1008b..af7e41b 100644 --- a/src/Systems/TankSteeringSystem.cpp +++ b/src/Systems/TankSteeringSystem.cpp @@ -88,7 +88,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit Events::ApplyPointImpulse ePointImpulse ; ePointImpulse.Entity = entity; ePointImpulse.Position = absoluteTransform.Position; - ePointImpulse.Impulse = glm::normalize(absoluteTransform.Orientation * glm::vec3(0, 0, 1)) * clonePhysicsComponent->Mass * 1670.f; + ePointImpulse.Impulse = glm::normalize(absoluteTransform.Orientation * glm::vec3(0, 0, 1)) * clonePhysicsComponent->Mass * 6.f * 1670.f; EventBroker->Publish(ePointImpulse); }