Merge remote-tracking branch 'origin/gui' into havok

This commit is contained in:
ViktorLjung
2014-05-28 20:29:28 +02:00
62 changed files with 2468 additions and 1626 deletions
+21 -34
View File
@@ -1,25 +1,21 @@
#include "PrecompiledHeader.h" #include "PrecompiledHeader.h"
#include "Camera.h" #include "Camera.h"
Camera::Camera(float yFOV, float aspectRatio, float nearClip, float farClip) Camera::Camera(float yFOV, float nearClip, float farClip)
{ {
m_FOV = yFOV; m_FOV = yFOV;
m_AspectRatio = aspectRatio;
m_NearClip = nearClip; m_NearClip = nearClip;
m_FarClip = farClip; m_FarClip = farClip;
m_Position = glm::vec3(0.0); m_Position = glm::vec3(0.0);
/*m_Pitch = 0.f;
m_Yaw = 0.f;*/
UpdateProjectionMatrix();
UpdateViewMatrix(); UpdateViewMatrix();
} }
//glm::vec3 Camera::Forward() glm::vec3 Camera::Forward()
//{ {
// return glm::rotate(glm::vec3(0.f, 0.f, -1.f), -m_Yaw, glm::vec3(0.f, 1.f, 0.f)); return m_Orientation * glm::vec3(0, 0, -1);
//} }
// //
//glm::vec3 Camera::Right() //glm::vec3 Camera::Right()
//{ //{
@@ -34,20 +30,14 @@ Camera::Camera(float yFOV, float aspectRatio, float nearClip, float farClip)
// return orientation; // return orientation;
//} //}
void Camera::AspectRatio(float val) void Camera::SetPosition(glm::vec3 val)
{
m_AspectRatio = val;
UpdateProjectionMatrix();
}
void Camera::Position(glm::vec3 val)
{ {
m_Position = val; m_Position = val;
UpdateViewMatrix(); UpdateViewMatrix();
} }
void Camera::Orientation(glm::quat val) void Camera::SetOrientation(glm::quat val)
{ {
m_Orientation = val; m_Orientation = val;
UpdateViewMatrix(); UpdateViewMatrix();
@@ -65,35 +55,32 @@ void Camera::Orientation(glm::quat val)
// UpdateViewMatrix(); // UpdateViewMatrix();
//} //}
void Camera::UpdateProjectionMatrix()
{
m_ProjectionMatrix = glm::perspective(
m_FOV,
m_AspectRatio,
m_NearClip,
m_FarClip
);
}
void Camera::UpdateViewMatrix() void Camera::UpdateViewMatrix()
{ {
m_ViewMatrix = glm::toMat4(glm::inverse(m_Orientation)) * glm::translate(-m_Position); m_ViewMatrix = glm::toMat4(glm::inverse(m_Orientation)) * glm::translate(-m_Position);
} }
void Camera::FOV(float val) void Camera::SetFOV(float val)
{ {
m_FOV = val; m_FOV = val;
UpdateProjectionMatrix();
} }
void Camera::NearClip(float val) void Camera::SetNearClip(float val)
{ {
m_NearClip = val; m_NearClip = val;
UpdateProjectionMatrix();
} }
void Camera::FarClip(float val) void Camera::SetFarClip(float val)
{ {
m_FarClip = val; m_FarClip = val;
UpdateProjectionMatrix(); }
}
glm::mat4 Camera::ProjectionMatrix(float aspectRatio)
{
return glm::perspective(
m_FOV,
aspectRatio,
m_NearClip,
m_FarClip
);
}
+7 -19
View File
@@ -1,60 +1,48 @@
#ifndef Camera_h__ #ifndef Camera_h__
#define Camera_h__ #define Camera_h__
//#include "PrecompiledHeader.h"
class Camera class Camera
{ {
public: public:
Camera(float yFOV, float aspectRatio, float nearClip, float farClip); Camera(float yFOV, float nearClip, float farClip);
glm::vec3 Forward(); glm::vec3 Forward();
glm::vec3 Right(); glm::vec3 Right();
float AspectRatio() const { return m_AspectRatio; }
void AspectRatio(float val);
glm::vec3 Position() const { return m_Position; } glm::vec3 Position() const { return m_Position; }
void Position(glm::vec3 val); void SetPosition(glm::vec3 val);
glm::quat Orientation() const { return m_Orientation; } glm::quat Orientation() const { return m_Orientation; }
void Orientation(glm::quat val); void SetOrientation(glm::quat val);
/*float Pitch() const { return m_Pitch; } /*float Pitch() const { return m_Pitch; }
void Pitch(float val); void Pitch(float val);
float Yaw() const { return m_Yaw; } float Yaw() const { return m_Yaw; }
void Yaw(float val);*/ void Yaw(float val);*/
glm::mat4 ProjectionMatrix() const { return m_ProjectionMatrix; } glm::mat4 ProjectionMatrix(float aspectRatio);
void ProjectionMatrix(glm::mat4 val) { m_ProjectionMatrix = val; }
glm::mat4 ViewMatrix() const { return m_ViewMatrix; } glm::mat4 ViewMatrix() const { return m_ViewMatrix; }
void ViewMatrix(glm::mat4 val) { m_ViewMatrix = val; }
float FOV() const { return m_FOV; } float FOV() const { return m_FOV; }
void FOV(float val); void SetFOV(float val);
float NearClip() const { return m_NearClip; } float NearClip() const { return m_NearClip; }
void NearClip(float val); void SetNearClip(float val);
float FarClip() const { return m_FarClip; } float FarClip() const { return m_FarClip; }
void FarClip(float val); void SetFarClip(float val);
private: private:
void UpdateProjectionMatrix();
void UpdateViewMatrix(); void UpdateViewMatrix();
float m_FOV; float m_FOV;
float m_AspectRatio;
float m_NearClip; float m_NearClip;
float m_FarClip; float m_FarClip;
glm::vec3 m_Position; glm::vec3 m_Position;
glm::quat m_Orientation; glm::quat m_Orientation;
//float m_Pitch;
//float m_Yaw;
glm::mat4 m_ProjectionMatrix;
glm::mat4 m_ViewMatrix; glm::mat4 m_ViewMatrix;
}; };
+2 -2
View File
@@ -9,9 +9,9 @@ namespace Components
struct Health : Component struct Health : Component
{ {
Health() Health()
: health(1.0f){ } : Amount(1.0f) { }
float health; float Amount;
virtual Health* Clone() const override { return new Health(*this); } virtual Health* Clone() const override { return new Health(*this); }
}; };
+2
View File
@@ -16,9 +16,11 @@ struct PointLight : Component
, ConstantAttenuation(1.0f) , ConstantAttenuation(1.0f)
, LinearAttenuation(0.f) , LinearAttenuation(0.f)
, QuadraticAttenuation(3.f) , QuadraticAttenuation(3.f)
, Radius(5.f)
{ } { }
float ConstantAttenuation, LinearAttenuation, QuadraticAttenuation; float ConstantAttenuation, LinearAttenuation, QuadraticAttenuation;
float Radius;
Color color; Color color;
glm::vec3 Specular; glm::vec3 Specular;
+34 -10
View File
@@ -1,11 +1,16 @@
#include <string> #include <string>
#include <sstream> #include <sstream>
#include "ResourceManager.h"
#include "OBJ.h"
#include "Model.h"
#include "Texture.h"
#include "EventBroker.h" #include "EventBroker.h"
#include "RenderQueue.h"
#include "Renderer.h" #include "Renderer.h"
#include "InputManager.h" #include "InputManager.h"
#include "GUI/Frame.h" #include "GUI/Frame.h"
#include "GameWorld.h" #include "GUI/GameFrame.h"
class Engine class Engine
{ {
@@ -14,15 +19,24 @@ public:
{ {
m_EventBroker = std::make_shared<EventBroker>(); m_EventBroker = std::make_shared<EventBroker>();
m_Renderer = std::make_shared<Renderer>(); m_ResourceManager = std::make_shared<ResourceManager>();
m_ResourceManager->RegisterType("OBJ", [](std::string resourceName) { return new OBJ(resourceName); });
auto rm = m_ResourceManager;
m_ResourceManager->RegisterType("Model", [rm](std::string resourceName) { return new Model(rm, *rm->Load<OBJ>("OBJ", resourceName)); });
m_ResourceManager->RegisterType("Texture", [](std::string resourceName) { return new Texture(resourceName); });
m_Renderer = std::make_shared<Renderer>(m_ResourceManager);
m_Renderer->Initialize(); m_Renderer->Initialize();
m_InputManager = std::make_shared<InputManager>(m_Renderer->GetWindow(), m_EventBroker); m_InputManager = std::make_shared<InputManager>(m_Renderer->GetWindow(), m_EventBroker);
//m_UIParent = std::make_shared<GUI::Frame>(m_EventBroker); m_FrameStack = new GUI::Frame(m_EventBroker, m_ResourceManager);
m_FrameStack->Width = 1280;
m_FrameStack->Height = 720;
new GUI::GameFrame(m_FrameStack, "GameFrame");
m_World = std::make_shared<GameWorld>(m_EventBroker, m_Renderer); //m_World = std::make_shared<GameWorld>(m_EventBroker, m_ResourceManager);
m_World->Initialize(); //m_World->Initialize();
m_LastTime = glfwGetTime(); m_LastTime = glfwGetTime();
} }
@@ -32,24 +46,34 @@ public:
void Tick() void Tick()
{ {
double currentTime = glfwGetTime(); double currentTime = glfwGetTime();
double dt = currentTime - m_LastTime; double dt = currentTime - m_LastTime;
m_LastTime = currentTime; m_LastTime = currentTime;
// Update input
m_InputManager->Update(dt); m_InputManager->Update(dt);
m_World->Update(dt);
m_Renderer->Draw(dt); // Update frame stack
m_EventBroker->Process<GUI::Frame>();
m_FrameStack->UpdateLayered(dt);
// Render scene
m_FrameStack->DrawLayered(m_Renderer);
m_Renderer->Swap();
// Swap event queues
m_EventBroker->Clear(); m_EventBroker->Clear();
glfwPollEvents(); glfwPollEvents();
} }
private: private:
std::shared_ptr<ResourceManager> m_ResourceManager;
std::shared_ptr<EventBroker> m_EventBroker; std::shared_ptr<EventBroker> m_EventBroker;
std::shared_ptr<Renderer> m_Renderer; std::shared_ptr<Renderer> m_Renderer;
std::shared_ptr<InputManager> m_InputManager; std::shared_ptr<InputManager> m_InputManager;
//std::shared_ptr<GUI::Frame> m_UIParent; GUI::Frame* m_FrameStack;
// TODO: This should ultimately live in GameFrame // TODO: This should ultimately live in GameFrame
std::shared_ptr<GameWorld> m_World; //std::shared_ptr<GameWorld> m_World;
double m_LastTime; double m_LastTime;
}; };
+3 -3
View File
@@ -5,13 +5,13 @@
namespace Events namespace Events
{ {
struct Damage : Event struct Damage : Event
{ {
EntityID Entity; EntityID Entity;
float damage; float Amount;
}; };
} }
#endif // Events_Damage_h__ #endif // Events_Damage_h__
+18
View File
@@ -0,0 +1,18 @@
#ifndef Events_SetViewportCamera_h__
#define Events_SetViewportCamera_h__
#include "EventBroker.h"
#include "Entity.h"
namespace Events
{
struct SetViewportCamera : Event
{
std::string ViewportFrame;
EntityID CameraEntity;
};
}
#endif // Events_SetViewportCamera_h__
+107 -21
View File
@@ -2,12 +2,14 @@
#define GUI_Frame_h__ #define GUI_Frame_h__
#include <memory> #include <memory>
#include <map>
#include "Util/Rectangle.h" #include "Util/Rectangle.h"
#include "EventBroker.h" #include "EventBroker.h"
#include "ResourceManager.h"
// HACK: Decouple renderer plz
#include "Renderer.h" #include "Renderer.h"
#include "RenderQueue.h"
#include "Texture.h"
namespace GUI namespace GUI
{ {
@@ -24,50 +26,134 @@ public:
}; };
// Set up a base frame with an event broker // Set up a base frame with an event broker
Frame(std::shared_ptr<::EventBroker> eventBroker) Frame(std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
: EventBroker(eventBroker) : EventBroker(eventBroker)
, Rectangle() , ResourceManager(resourceManager)
{ Initialize(); } , Rectangle()
// Create a frame as a child , m_Name("UIParent")
Frame(std::shared_ptr<Frame> parent) , m_Layer(0)
: Rectangle(static_cast<Rectangle>(*parent)) // Clone parent rectangle using copy constructor { }
{ SetParent(parent); Initialize(); }
// Create a frame as a child
Frame(Frame* parent, std::string name)
: m_Name(name)
, m_Layer(0)
{ SetParent(std::shared_ptr<Frame>(parent)); }
::RenderQueue RenderQueue;
virtual void Initialize() { }
std::shared_ptr<Frame> Parent() const { return m_Parent; } std::shared_ptr<Frame> Parent() const { return m_Parent; }
void SetParent(std::shared_ptr<Frame> parent) void SetParent(std::shared_ptr<Frame> parent)
{ {
if (parent == nullptr)
{
LOG_ERROR("Failed to create frame \"%s\": Invalid parent", m_Name.c_str());
return;
}
Width = parent->Width;
Height = parent->Height;
m_Layer = parent->Layer() + 1;
parent->AddChild(std::shared_ptr<Frame>(this)); parent->AddChild(std::shared_ptr<Frame>(this));
m_Parent = parent; m_Parent = parent;
EventBroker = parent->EventBroker; EventBroker = parent->EventBroker;
ResourceManager = parent->ResourceManager;
} }
void AddChild(std::shared_ptr<Frame> child) void AddChild(std::shared_ptr<Frame> child)
{ {
m_Children.push_back(child); m_Children[child->m_Layer].insert(std::make_pair(child->Name(), child));
if (m_Parent != nullptr) if (m_Parent)
{ {
m_Parent->AddChild(child); m_Parent->AddChild(child);
} }
} }
typedef std::list<std::shared_ptr<Frame>>::const_iterator FrameChildrenIterator; typedef std::map<std::string, std::shared_ptr<Frame>>::const_iterator FrameChildrenIterator;
FrameChildrenIterator begin()
{ std::string Name() const { return m_Name; }
return m_Children.begin(); void SetName(std::string val) { m_Name = val; }
int Layer() const { return m_Layer; }
int Left() const override
{
if (m_Parent)
return m_Parent->Left() + X;
else
return X;
} }
FrameChildrenIterator end() int Right() const override
{
return Left() + Width;
}
int Top() const override
{
if (m_Parent)
return m_Parent->Top() + Y;
else
return Y;
}
int Bottom() const override
{ {
return m_Children.end(); return Top() + Height;
} }
Rectangle AbsoluteRectangle()
{
return Rectangle(Left(), Top(), Width, Height);
}
void UpdateLayered(double dt)
{
// Update ourselves
this->Update(dt);
// Update children
for (auto &pairLayer : m_Children)
{
auto children = pairLayer.second;
for (auto &pairChild : children)
{
auto child = pairChild.second;
child->Update(dt);
}
}
}
virtual void Update(double dt) { } virtual void Update(double dt) { }
virtual void Draw(Renderer* renderer) { }
void DrawLayered(std::shared_ptr<Renderer> renderer)
{
// Draw ourselves
renderer->SetViewport(AbsoluteRectangle());
this->Draw(renderer);
// Draw children
for (auto &pairLayer : m_Children)
{
auto children = pairLayer.second;
for (auto &pairChild : children)
{
auto child = pairChild.second;
Rectangle rect = child->AbsoluteRectangle();
renderer->SetViewport(rect);
child->Draw(renderer);
}
}
}
virtual void Draw(std::shared_ptr<Renderer> renderer) { }
protected: protected:
std::shared_ptr<::EventBroker> EventBroker; std::shared_ptr<::EventBroker> EventBroker;
std::shared_ptr<::ResourceManager> ResourceManager;
std::string m_Name;
int m_Layer;
std::shared_ptr<Frame> m_Parent; std::shared_ptr<Frame> m_Parent;
std::list<std::shared_ptr<Frame>> m_Children; typedef std::multimap<std::string, std::shared_ptr<Frame>> Children_t; // name -> frame
std::map<int, Children_t> m_Children; // layer -> Children_t
}; };
} }
+51
View File
@@ -0,0 +1,51 @@
#ifndef GUI_GameFrame_h__
#define GUI_GameFrame_h__
#include "GUI/Frame.h"
#include "GUI/WorldFrame.h"
#include "GUI/Viewport.h"
#include "GUI/TextureFrame.h"
#include "GUI/PlayerHUD.h"
#include "GameWorld.h"
namespace GUI
{
class GameFrame : public Frame
{
public:
GameFrame(Frame* parent, std::string name)
: Frame(parent, name)
{
m_World = std::make_shared<GameWorld>(EventBroker, ResourceManager);
auto worldFrame = new WorldFrame(this, "GameWorldFrame", m_World);
{
vp1 = new Viewport(worldFrame, "Viewport1", m_World);
vp1->X = 0;
vp1->Width = 640;
vp1->Height = 720 / 2;
new PlayerHUD(vp1, "PlayerHUD", m_World, 1);
vp2 = new Viewport(worldFrame, "Viewport2", m_World);
vp2->X = vp1->Right();
vp2->Width = 640;
vp2->Height = 720 / 2;
new PlayerHUD(vp2, "PlayerHUD", m_World, 2);
auto vpc = new Viewport(worldFrame, "ViewportFreeCam", m_World);
vpc->Y = 720 / 2;
vpc->Height = 720 / 2;
}
m_World->Initialize();
}
private:
std::shared_ptr<GameWorld> m_World;
Viewport* vp1;
Viewport* vp2;
};
}
#endif // GUI_GameFrame_h__
+53
View File
@@ -0,0 +1,53 @@
#ifndef GUI_HealthOverlay_h__
#define GUI_HealthOverlay_h__
#include "GUI/TextureFrame.h"
#include "World.h"
#include "Events/Damage.h"
#include "Components/Player.h"
#include "Components/Health.h"
namespace GUI
{
class HealthOverlay : public TextureFrame
{
public:
HealthOverlay(Frame* parent, std::string name, std::shared_ptr<World> world, int playerID)
: TextureFrame(parent, name)
, m_World(world)
, m_PlayerID(playerID)
{
EVENT_SUBSCRIBE_MEMBER(m_EDamage, &HealthOverlay::OnDamage);
SetTexture("Textures/GUI/hurt.png");
SetColor(glm::vec4(0.f));
}
bool OnDamage(const Events::Damage &event)
{
auto player = m_World->GetComponent<Components::Player>(event.Entity);
if (!player)
return false;
if (player->ID != m_PlayerID)
return false;
auto health = m_World->GetComponent<Components::Health>(event.Entity);
if (!health)
return false;
SetColor(glm::vec4(1.f, 1.f, 1.f, 1 - health->Amount / 100.f));
return true;
}
protected:
std::shared_ptr<World> m_World;
int m_PlayerID;
EventRelay<Frame, Events::Damage> m_EDamage;
};
}
#endif // GUI_TextureFrame_h__
+30
View File
@@ -0,0 +1,30 @@
#include "GUI/Frame.h"
#include "GUI/HealthOverlay.h"
#ifndef GUI_PlayerHUD_h__
#define GUI_PlayerHUD_h__
namespace GUI
{
class PlayerHUD : public Frame
{
public:
PlayerHUD(Frame* parent, std::string name, std::shared_ptr<World> world, int playerID)
: Frame(parent, name)
, m_World(world)
, m_PlayerID(playerID)
{
m_HealthOverlay = new HealthOverlay(this, "HealthOverlay", m_World, m_PlayerID);
}
protected:
std::shared_ptr<World> m_World;
int m_PlayerID;
HealthOverlay* m_HealthOverlay;
};
}
#endif // GUI_TextureFrame_h__
+52
View File
@@ -0,0 +1,52 @@
#ifndef GUI_TextureFrame_h__
#define GUI_TextureFrame_h__
#include "GUI/Frame.h"
#include "Texture.h"
namespace GUI
{
class TextureFrame : public Frame
{
public:
TextureFrame(Frame* parent, std::string name)
: Frame(parent, name)
, m_Texture(nullptr)
, m_Color(glm::vec4(1.f, 1.f, 1.f, 1.f))
{ }
void Draw(std::shared_ptr<Renderer> renderer) override
{
if (m_Texture == nullptr)
return;
RenderQueue.Clear();
SpriteJob job;
job.TextureID = m_Texture->ResourceID;
job.Texture = *m_Texture;
job.Color = m_Color;
RenderQueue.Add(job);
renderer->SetCamera(nullptr);
renderer->DrawFrame(RenderQueue);
}
::Texture* Texture() const { return m_Texture; }
void SetTexture(std::string resourceName)
{
m_Texture = ResourceManager->Load<::Texture>("Texture", resourceName);
}
glm::vec4 Color() const { return m_Color; }
void SetColor(glm::vec4 val) { m_Color = val; }
protected:
::Texture* m_Texture;
glm::vec4 m_Color;
};
}
#endif // GUI_TextureFrame_h__
+62 -3
View File
@@ -4,6 +4,12 @@
#include <memory> #include <memory>
#include "GUI/Frame.h" #include "GUI/Frame.h"
#include "World.h"
#include "Systems/TransformSystem.h"
#include "Components/Transform.h"
#include "Components/Camera.h"
#include "RenderQueue.h"
#include "Camera.h"
namespace GUI namespace GUI
{ {
@@ -11,9 +17,62 @@ namespace GUI
class Viewport : public Frame class Viewport : public Frame
{ {
public: public:
// Create a frame as a child Viewport(Frame* parent, std::string name, std::shared_ptr<World> world)
Viewport(std::shared_ptr<Frame> parent) : Frame(parent, name)
: Frame(parent) { } , m_World(world)
{ }
EntityID CameraEntity() const { return m_CameraEntity; }
void SetCameraEntity(EntityID cameraEntity)
{
m_CameraEntity = cameraEntity;
auto transformComponent = m_World->GetComponent<Components::Transform>(cameraEntity);
if (!transformComponent)
return;
auto cameraComponent = m_World->GetComponent<Components::Camera>(cameraEntity);
if (!cameraComponent)
return;
m_Camera = std::make_shared<Camera>(cameraComponent->FOV, cameraComponent->NearClip, cameraComponent->FarClip);
}
void Update(double dt) override
{
if (!m_TransformSystem)
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>();
auto transformComponent = m_World->GetComponent<Components::Transform>(m_CameraEntity);
if (!transformComponent)
return;
auto cameraComponent = m_World->GetComponent<Components::Camera>(m_CameraEntity);
if (!cameraComponent)
return;
Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(m_CameraEntity);
m_Camera->SetFOV(cameraComponent->FOV);
m_Camera->SetNearClip(cameraComponent->NearClip);
m_Camera->SetFarClip(cameraComponent->FarClip);
m_Camera->SetPosition(absoluteTransform.Position);
m_Camera->SetOrientation(absoluteTransform.Orientation);
}
void Draw(std::shared_ptr<Renderer> renderer) override
{
if (!m_Camera)
return;
renderer->SetCamera(m_Camera);
renderer->DrawWorld(m_Parent->RenderQueue);
}
private:
std::shared_ptr<World> m_World;
std::shared_ptr<Systems::TransformSystem> m_TransformSystem;
std::shared_ptr<Camera> m_Camera;
EntityID m_CameraEntity;
}; };
} }
+150
View File
@@ -0,0 +1,150 @@
#ifndef GUI_WorldFrame_h__
#define GUI_WorldFrame_h__
#include "GUI/Frame.h"
#include "GUI/Viewport.h"
#include "RenderQueue.h"
#include "World.h"
#include "Systems/TransformSystem.h"
#include "Events/SetViewportCamera.h"
#include "Components/Transform.h"
#include "Components/Model.h"
#include "Components/Sprite.h"
#include "Components/PointLight.h"
namespace GUI
{
class WorldFrame : public Frame
{
public:
WorldFrame(Frame* parent, std::string name, std::shared_ptr<World> world)
: Frame(parent, name)
, m_World(world)
{
EVENT_SUBSCRIBE_MEMBER(m_ESetViewportCamera, &WorldFrame::OnSetViewportCamera);
}
void Update(double dt) override
{
if (!m_TransformSystem)
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>();
m_World->Update(dt);
}
void Draw(std::shared_ptr<Renderer> renderer) override
{
RenderQueue.Clear();
renderer->ClearPointLights();
for (auto &pair : *m_World->GetEntities())
{
EntityID entity = pair.first;
auto transform = m_World->GetComponent<Components::Transform>(entity);
if (!transform)
continue;
auto modelComponent = m_World->GetComponent<Components::Model>(entity);
if (modelComponent)
{
auto modelAsset = ResourceManager->Load<Model>("Model", modelComponent->ModelFile);
if (modelAsset)
{
Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity);
glm::mat4 modelMatrix = glm::translate(glm::mat4(), absoluteTransform.Position)
* glm::toMat4(absoluteTransform.Orientation)
* glm::scale(absoluteTransform.Scale);
EnqueueModel(modelAsset, modelMatrix);
}
}
auto spriteComponent = m_World->GetComponent<Components::Sprite>(entity);
if (spriteComponent)
{
auto textureAsset = ResourceManager->Load<Texture>("Texture", spriteComponent->SpriteFile);
if (textureAsset)
{
Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity);
glm::quat orientation2D = glm::angleAxis(glm::eulerAngles(absoluteTransform.Orientation).z, glm::vec3(0, 0, -1));
glm::mat4 modelMatrix = glm::translate(absoluteTransform.Position)
* glm::toMat4(orientation2D)
* glm::scale(absoluteTransform.Scale);
EnqueueSprite(textureAsset, modelMatrix);
}
}
auto pointLightComponent = m_World->GetComponent<Components::PointLight>(entity);
if (pointLightComponent)
{
glm::vec3 position = m_TransformSystem->AbsolutePosition(entity);
renderer->AddPointLightToDraw(
position,
pointLightComponent->Specular,
pointLightComponent->Diffuse,
pointLightComponent->specularExponent,
pointLightComponent->ConstantAttenuation,
pointLightComponent->LinearAttenuation,
pointLightComponent->QuadraticAttenuation,
pointLightComponent->Radius
);
}
}
}
protected:
std::shared_ptr<World> m_World;
private:
EventRelay<Frame, Events::SetViewportCamera> m_ESetViewportCamera;
bool OnSetViewportCamera(const Events::SetViewportCamera &event)
{
// Search next layer for viewports and update cameras
auto itpair = m_Children[m_Layer + 1].equal_range(event.ViewportFrame);
for (auto it = itpair.first; it != itpair.second; ++it)
{
auto viewportFrame = std::dynamic_pointer_cast<GUI::Viewport>(it->second);
if (!viewportFrame)
continue;
viewportFrame->SetCameraEntity(event.CameraEntity);
}
return true;
}
std::shared_ptr<Systems::TransformSystem> m_TransformSystem;
void EnqueueModel(Model* model, glm::mat4 modelMatrix)
{
for (auto texGroup : model->TextureGroups)
{
ModelJob job;
job.TextureID = texGroup.Texture->ResourceID;
job.DiffuseTexture = *texGroup.Texture;
job.NormalTexture = (texGroup.NormalMap) ? *texGroup.NormalMap : 0;
job.SpecularTexture = (texGroup.SpecularMap) ? *texGroup.SpecularMap : 0;
job.VAO = model->VAO;
job.StartIndex = texGroup.StartIndex;
job.EndIndex = texGroup.EndIndex;
job.ModelMatrix = modelMatrix;
RenderQueue.Add(job);
}
}
void EnqueueSprite(Texture* texture, glm::mat4 modelMatrix)
{
SpriteJob job;
job.TextureID = texture->ResourceID;
job.Texture = *texture;
job.ModelMatrix = modelMatrix;
RenderQueue.Add(job);
}
};
}
#endif // GUI_WorldFrame_h__
+664 -1094
View File
File diff suppressed because it is too large Load Diff
+6 -4
View File
@@ -51,11 +51,15 @@
class GameWorld : public World class GameWorld : public World
{ {
public: public:
GameWorld(std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<Renderer> renderer) GameWorld(std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
: World(eventBroker), m_Renderer(renderer) { } : World(eventBroker, resourceManager)
{ }
void Initialize(); void Initialize();
EntityID CreateTank(int playerID);
EntityID CreateJeep(int playerID);
void RegisterSystems() override; void RegisterSystems() override;
void AddSystems() override; void AddSystems() override;
void RegisterComponents() override; void RegisterComponents() override;
@@ -63,8 +67,6 @@ public:
void Update(double dt); void Update(double dt);
private: private:
std::shared_ptr<Renderer> m_Renderer;
void BindKey(int keyCode, std::string command, float value); void BindKey(int keyCode, std::string command, float value);
void BindMouseButton(int button, std::string command, float value); void BindMouseButton(int button, std::string command, float value);
void BindGamepadAxis(Gamepad::Axis axis, std::string command, float value); void BindGamepadAxis(Gamepad::Axis axis, std::string command, float value);
+34 -7
View File
@@ -1,7 +1,7 @@
#include "PrecompiledHeader.h" #include "PrecompiledHeader.h"
#include "Model.h" #include "Model.h"
Model::Model(ResourceManager* rm, OBJ &obj) Model::Model(std::shared_ptr<ResourceManager> rm, OBJ &obj)
{ {
OBJ::MaterialInfo* currentMaterial = nullptr; OBJ::MaterialInfo* currentMaterial = nullptr;
TextureGroup* currentTexGroup = nullptr; TextureGroup* currentTexGroup = nullptr;
@@ -23,11 +23,23 @@ Model::Model(ResourceManager* rm, OBJ &obj)
// TODO: Load normal map // TODO: Load normal map
std::shared_ptr<Texture> normalMap = nullptr; std::shared_ptr<Texture> normalMap = nullptr;
if (!currentMaterial->NormalMap.FileName.empty()) if (!currentMaterial->NormalMap.FileName.empty())
{
normalMap = std::shared_ptr<Texture>(rm->Load<Texture>("Texture", currentMaterial->NormalMap.FileName)); normalMap = std::shared_ptr<Texture>(rm->Load<Texture>("Texture", currentMaterial->NormalMap.FileName));
}
else
{
normalMap = std::shared_ptr<Texture>(rm->Load<Texture>("Texture", "Textures/NeutralNormalMap.png"));
}
// Load specular map // Load specular map
std::shared_ptr<Texture> specularMap = nullptr; std::shared_ptr<Texture> specularMap = nullptr;
if (!currentMaterial->SpecularMap.FileName.empty()) if (!currentMaterial->SpecularMap.FileName.empty())
{
specularMap = std::shared_ptr<Texture>(rm->Load<Texture>("Texture", currentMaterial->SpecularMap.FileName)); specularMap = std::shared_ptr<Texture>(rm->Load<Texture>("Texture", currentMaterial->SpecularMap.FileName));
}
else
{
specularMap = std::shared_ptr<Texture>(rm->Load<Texture>("Texture", "Textures/NeutralSpecularMap.png"));
}
// TODO: Load material parameters // TODO: Load material parameters
// Create new texture group (start index of new group is upcoming index) // Create new texture group (start index of new group is upcoming index)
@@ -36,6 +48,21 @@ Model::Model(ResourceManager* rm, OBJ &obj)
currentTexGroup = &TextureGroups.back(); currentTexGroup = &TextureGroups.back();
} }
/*std::unordered_map<int, glm::vec3> similarNormals;
std::unordered_map<int, int> normalCount;
for (auto &faceDef : face.Definitions)
{
if (faceDef.NormalIndex == 0)
continue;
similarNormals[faceDef.VertexIndex - 1] += normal;
normalCount[faceDef.VertexIndex - 1]++;
int index = pair.first;
glm::vec3 averagedNormal = ;
Normals[]
}*/
// Face definitions // Face definitions
for (auto faceDef : face.Definitions) for (auto faceDef : face.Definitions)
{ {
@@ -178,7 +205,7 @@ void Model::CreateBuffers( std::vector<glm::vec3> vertices, std::vector<glm::vec
bool Model::IsNear( float v1, float v2 ) bool Model::IsNear( float v1, float v2 )
{ {
return fabs(v1 - v2) < 0.01f; return fabs(v1 - v2) < 0.001f;
} }
void Model::getSimilarVertexIndex() void Model::getSimilarVertexIndex()
@@ -190,15 +217,15 @@ void Model::getSimilarVertexIndex()
if(i != t) if(i != t)
{ {
if(IsNear(Vertices[i].x, Vertices[t].x) if(IsNear(Vertices[i].x, Vertices[t].x)
& IsNear(Vertices[i].y, Vertices[t].y) && IsNear(Vertices[i].y, Vertices[t].y)
& IsNear(Vertices[i].z, Vertices[t].z) && IsNear(Vertices[i].z, Vertices[t].z)
) )
{ {
glm::vec3 tempNormal, tempTangent, tempBiTangent; glm::vec3 tempNormal, tempTangent, tempBiTangent;
tempNormal = glm::normalize(Normals[i] + Normals[t]); tempNormal = Normals[i] + Normals[t];
tempTangent = glm::normalize(TangentNormals[i] + TangentNormals[t]); tempTangent = TangentNormals[i] + TangentNormals[t];
tempBiTangent = glm::normalize(BiTangentNormals[i] + BiTangentNormals[t]); tempBiTangent = BiTangentNormals[i] + BiTangentNormals[t];
Normals[i] = tempNormal; Normals[i] = tempNormal;
Normals[t] = tempNormal; Normals[t] = tempNormal;
+1 -1
View File
@@ -17,7 +17,7 @@
class Model : public Resource class Model : public Resource
{ {
public: public:
Model(ResourceManager* rm, OBJ &obj); Model(std::shared_ptr<ResourceManager> resourceManager, OBJ &obj);
struct TextureGroup struct TextureGroup
{ {
+50 -19
View File
@@ -14,25 +14,10 @@ struct RenderJob
{ {
friend class RenderQueue; friend class RenderQueue;
unsigned int ViewportID;
unsigned int TextureID;
GLuint DiffuseTexture;
GLuint NormalTexture;
GLuint SpecularTexture;
GLuint VAO;
unsigned int StartIndex;
unsigned int EndIndex;
glm::mat4 ModelMatrix;
protected: protected:
uint64_t Hash; uint64_t Hash;
void CalculateHash() virtual void CalculateHash() = 0;
{
Hash = ViewportID << 58 // 6 bits
| TextureID << 42; // 16 bits
}
bool operator<(const RenderJob& rhs) bool operator<(const RenderJob& rhs)
{ {
@@ -40,13 +25,49 @@ protected:
} }
}; };
struct ModelJob : RenderJob
{
unsigned int ShaderID;
unsigned int TextureID;
GLuint DiffuseTexture;
GLuint NormalTexture;
GLuint SpecularTexture;
glm::vec4 Color;
GLuint VAO;
unsigned int StartIndex;
unsigned int EndIndex;
glm::mat4 ModelMatrix;
void CalculateHash() override
{
Hash = TextureID;
}
};
struct SpriteJob : RenderJob
{
unsigned int ShaderID;
unsigned int TextureID;
GLuint Texture;
glm::vec4 Color;
glm::mat4 ModelMatrix;
void CalculateHash() override
{
Hash = TextureID;
}
};
class RenderQueue class RenderQueue
{ {
public: public:
void Add(RenderJob &job) template <typename T>
void Add(T &job)
{ {
job.CalculateHash(); job.CalculateHash();
m_Jobs.push_front(job); m_Jobs.push_front(std::shared_ptr<T>(new T(job)));
m_Jobs.sort(); m_Jobs.sort();
} }
@@ -55,8 +76,18 @@ public:
m_Jobs.clear(); m_Jobs.clear();
} }
std::forward_list<std::shared_ptr<RenderJob>>::const_iterator begin()
{
return m_Jobs.begin();
}
std::forward_list<std::shared_ptr<RenderJob>>::const_iterator end()
{
return m_Jobs.end();
}
private: private:
std::forward_list<RenderJob> m_Jobs; std::forward_list<std::shared_ptr<RenderJob>> m_Jobs;
}; };
#endif // RenderQueue_h__ #endif // RenderQueue_h__
+534 -210
View File
@@ -1,7 +1,8 @@
#include "PrecompiledHeader.h" #include "PrecompiledHeader.h"
#include "Renderer.h" #include "Renderer.h"
Renderer::Renderer() Renderer::Renderer(std::shared_ptr<::ResourceManager> resourceManager)
: ResourceManager(resourceManager)
{ {
m_VSync = false; m_VSync = false;
#ifdef DEBUG #ifdef DEBUG
@@ -13,14 +14,17 @@ Renderer::Renderer()
m_DrawWireframe = false; m_DrawWireframe = false;
m_DrawBounds = false; m_DrawBounds = false;
#endif #endif
Gamma = 2.2f; Gamma = 0.85f;
CAtt = 1.0f; CAtt = 1.0f;
LAtt = 0.0f; LAtt = 0.0f;
QAtt = 3.0f; QAtt = 3.0f;
m_ShadowMapRes = 2048*6; m_ShadowMapRes = 2048*2;
m_SunPosition = glm::vec3(0, 3.5f, 10); m_SunPosition = glm::vec3(0.f, 1.0f, 0.5f);
m_SunTarget = glm::vec3(0, 0, 0); m_SunTarget = glm::vec3(0, 0, 0);
m_SunProjection = glm::ortho<float>(10.f, -10.f, 10.f, -10.f, 10.f, -10.f); m_SunProjection_height = glm::vec2(-40.f, 40.f);
m_SunProjection_width = glm::vec2(-40.f, 40.f);
m_SunProjection_length = glm::vec2(-500.f, 500.f);
m_SunProjection = glm::ortho<float>(m_SunProjection_width.x, m_SunProjection_width.y, m_SunProjection_height.x, m_SunProjection_height.y, m_SunProjection_length.x, m_SunProjection_length.y);
/* Lights = 0;*/ /* Lights = 0;*/
} }
@@ -66,13 +70,14 @@ void Renderer::Initialize()
} }
// Create Camera // Create Camera
m_Camera = std::make_shared<Camera>(45.f, (float)m_Width / m_Height, 0.01f, 1000.f); m_Camera = std::make_shared<Camera>(45.f, 0.01f, 1000.f);
m_Camera->Position(glm::vec3(0.0f, 0.0f, 2.f)); m_Camera->SetPosition(glm::vec3(0.0f, 0.0f, 2.f));
glfwSwapInterval(m_VSync); glfwSwapInterval(m_VSync);
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
glCullFace(GL_BACK); glCullFace(GL_BACK);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glEnable(GL_SCISSOR_TEST);
LoadContent(); LoadContent();
} }
@@ -101,12 +106,22 @@ void Renderer::LoadContent()
m_ShaderProgramDebugAABB.AddShader(standardVS); m_ShaderProgramDebugAABB.AddShader(standardVS);
m_ShaderProgramDebugAABB.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/AABB.frag.glsl"))); m_ShaderProgramDebugAABB.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/AABB.frag.glsl")));
m_ShaderProgramDebugAABB.Compile(); m_ShaderProgramDebugAABB.Compile();
m_ShaderProgramDebugAABB.Link(); m_ShaderProgramDebugAABB.Link();*/
m_ShaderProgramSkybox.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Skybox.vert.glsl"))); m_ShaderProgramSkybox.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Skybox.vert.glsl")));
m_ShaderProgramSkybox.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Skybox.frag.glsl"))); m_ShaderProgramSkybox.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Skybox.frag.glsl")));
m_ShaderProgramSkybox.Compile(); m_ShaderProgramSkybox.Compile();
m_ShaderProgramSkybox.Link();*/ m_ShaderProgramSkybox.Link();
m_SunPassProgram.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/SunPass.vert.glsl")));
m_SunPassProgram.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/SunPass.frag.glsl")));
m_SunPassProgram.Compile();
m_SunPassProgram.Link();
m_ForwardRendering.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/ForwardRendering.vert.glsl")));
m_ForwardRendering.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/ForwardRendering.frag.glsl")));
m_ForwardRendering.Compile();
m_ForwardRendering.Link();
m_ShaderProgramShadows.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/ShadowMap.vert.glsl"))); m_ShaderProgramShadows.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/ShadowMap.vert.glsl")));
m_ShaderProgramShadows.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/ShadowMap.frag.glsl"))); m_ShaderProgramShadows.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/ShadowMap.frag.glsl")));
@@ -139,6 +154,9 @@ void Renderer::LoadContent()
m_ScreenQuad = CreateQuad(); m_ScreenQuad = CreateQuad();
CreateShadowMap(m_ShadowMapRes); CreateShadowMap(m_ShadowMapRes);
FrameBufferTextures(); FrameBufferTextures();
m_sphereModel = ResourceManager->Load<Model>("Model", "Models/Placeholders/PhysicsTest/Sphere.obj");
m_Skybox = std::make_shared<Skybox>("Textures/Skybox/Sunset", "jpg");
} }
void Renderer::Draw(double dt) void Renderer::Draw(double dt)
@@ -152,17 +170,44 @@ void Renderer::Draw(double dt)
m_QuadView = true; m_QuadView = true;
} }
if(glfwGetKey(m_Window, GLFW_KEY_KP_1)) //if(glfwGetKey(m_Window, GLFW_KEY_KP_1))
//{
// Gamma -= 0.3f * dt;
// LOG_INFO("Gamma_UP: %f", Gamma);
//}
//if(glfwGetKey(m_Window, GLFW_KEY_KP_4))
//{
// Gamma += 0.3f * dt;
// LOG_INFO("Gamma_DOWN: %f", Gamma);
//}
if(glfwGetKey(m_Window, GLFW_KEY_KP_7))
{ {
Gamma -= 0.3f * dt; m_SunProjection_height.x += 10.f * dt;
LOG_INFO("Gamma_UP: %f", Gamma); LOG_INFO("Heightx+: %f", m_SunProjection_height);
m_SunProjection = glm::ortho<float>(m_SunProjection_width.x, m_SunProjection_width.y, m_SunProjection_height.x, m_SunProjection_height.y, m_SunProjection_length.x, m_SunProjection_length.y);
} }
if(glfwGetKey(m_Window, GLFW_KEY_KP_4)) else if(glfwGetKey(m_Window, GLFW_KEY_KP_4))
{ {
Gamma += 0.3f * dt; m_SunProjection_height.x -= 10.f * dt;
LOG_INFO("Gamma_DOWN: %f", Gamma); LOG_INFO("Heightx-: %f", m_SunProjection_height);
m_SunProjection = glm::ortho<float>(m_SunProjection_width.x, m_SunProjection_width.y, m_SunProjection_height.x, m_SunProjection_height.y, m_SunProjection_length.x, m_SunProjection_length.y);
} }
if(glfwGetKey(m_Window, GLFW_KEY_KP_8))
{
m_SunProjection_height.y += 10.f * dt;
LOG_INFO("Heightx+: %f", m_SunProjection_height);
m_SunProjection = glm::ortho<float>(m_SunProjection_width.x, m_SunProjection_width.y, m_SunProjection_height.x, m_SunProjection_height.y, m_SunProjection_length.x, m_SunProjection_length.y);
}
else if(glfwGetKey(m_Window, GLFW_KEY_KP_5))
{
m_SunProjection_height.y -= 10.f * dt;
LOG_INFO("Heightx-: %f", m_SunProjection_height);
m_SunProjection = glm::ortho<float>(m_SunProjection_width.x, m_SunProjection_width.y, m_SunProjection_height.x, m_SunProjection_height.y, m_SunProjection_length.x, m_SunProjection_length.y);
}
if(glfwGetKey(m_Window, GLFW_KEY_1)) if(glfwGetKey(m_Window, GLFW_KEY_1))
{ {
if(glfwGetKey(m_Window, GLFW_KEY_KP_ADD)) if(glfwGetKey(m_Window, GLFW_KEY_KP_ADD))
@@ -211,16 +256,196 @@ void Renderer::Draw(double dt)
glfwSwapBuffers(m_Window); glfwSwapBuffers(m_Window);
} }
void Renderer::DrawFrame(RenderQueue &rq)
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height);
glScissor(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height);
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glClearColor(0.0f, 0.5f, 0.0f, 1.0f);
glDisable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix((float)m_Width / m_Height) * m_Camera->ViewMatrix();
//glm::mat4 MVP;
m_ForwardRendering.Bind();
//for (auto tuple : ModelsToRender) //// Todo: Add so it's TransparentModelsToRender
//{
// Model* model;
// glm::mat4 modelMatrix;
// bool visible;
// std::tie(model, modelMatrix, visible, std::ignore) = tuple;
// if (!visible)
// continue;
// MVP = cameraMatrix * modelMatrix;
// glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
// glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
// glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
// glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(m_Camera->ProjectionMatrix((float)m_Width / m_Height)));
// glBindVertexArray(model->VAO);
// for (auto texGroup : model->TextureGroups)
// {
// glActiveTexture(GL_TEXTURE0);
// glBindTexture(GL_TEXTURE_2D, *texGroup.Texture);
// glDrawArrays(GL_TRIANGLES, texGroup.StartIndex, texGroup.EndIndex - texGroup.StartIndex + 1);
// }
//}
for (auto &job : rq)
{
//auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
//if (modelJob)
//{
// glm::mat4 modelMatrix = modelJob->ModelMatrix;
// MVP = cameraMatrix * modelMatrix;
// depthMVP = depthCameraMatrix * modelMatrix;
// glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
// glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "DepthMVP"), 1, GL_FALSE, glm::value_ptr(depthMVP));
// glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
// glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
// glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(cameraProjection));
// //glUniform3fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "SunDirection_cameraspace"), 1, glm::value_ptr(sunDirection_cameraview));
// glBindVertexArray(modelJob->VAO);
// glActiveTexture(GL_TEXTURE0);
// glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture);
// if (modelJob->NormalTexture != 0)
// {
// glActiveTexture(GL_TEXTURE2);
// glBindTexture(GL_TEXTURE_2D, modelJob->NormalTexture);
// }
// if (modelJob->SpecularTexture)
// {
// glActiveTexture(GL_TEXTURE3);
// glBindTexture(GL_TEXTURE_2D, modelJob->SpecularTexture);
// }
// glDrawArrays(GL_TRIANGLES, modelJob->StartIndex, modelJob->EndIndex - modelJob->StartIndex + 1);
// continue;
//}
auto spriteJob = std::dynamic_pointer_cast<SpriteJob>(job);
if (spriteJob)
{
glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(glm::mat4()));
glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(glm::mat4()));
glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(glm::mat4()));
glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(glm::mat4()));
glUniform4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "Color"), 1, glm::value_ptr(spriteJob->Color));
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, spriteJob->Texture);
glBindVertexArray(m_ScreenQuad);
glDrawArrays(GL_TRIANGLES, 0, 6);
continue;
}
}
}
void Renderer::DrawWorld(RenderQueue &rq)
{
glDisable(GL_BLEND);
DrawShadowMap(rq);
/*
Base pass
*/
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbBasePass);
glViewport(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height);
glScissor(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height);
//glViewport(0, 0, m_Width, m_Height);
// Clear G-buffer
GLenum windowBuffClear[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 };
glDrawBuffers(4, windowBuffClear);
glClearColor(115.f / 255, 192.f / 255, 255.f / 255, 0.f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Execute the first render stage which will fill out the internal buffers with data(??)
m_FirstPassProgram.Bind();
GLenum windowBuffOpaque[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 };
glDrawBuffers(4, windowBuffOpaque);
glCullFace(GL_BACK);
glEnable(GL_DEPTH_TEST);
DrawFBOScene(rq);
/*
Lighting pass
*/
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbLightingPass);
GLenum lightingPassAttachments[] = { GL_COLOR_ATTACHMENT0 };
glDrawBuffers(1, lightingPassAttachments);
glClearColor(0.f, 0.f, 0.f, 0.f);
glClear(GL_COLOR_BUFFER_BIT);
m_SecondPassProgram.Bind();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_fPositionTexture);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_fNormalsTexture);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, m_fSpecularTexture);
glCullFace(GL_FRONT);
DrawLightScene(rq);
DrawSunLightScene();
/*
Final pass
*/
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
//glViewport(m_Viewport.X, m_Viewport.Y, m_Viewport.Width, m_Viewport.Height);
glViewport(0, 0, m_Width, m_Height);
glScissor(0, 0, m_Width, m_Height);
glClear(GL_DEPTH_BUFFER_BIT);
m_FinalPassProgram.Bind();
// Ambient light
glUniform3fv(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "La"), 1, glm::value_ptr(glm::vec3(0.7f)));
glUniform1f(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "Gamma"), Gamma);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_fDiffuseTexture);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_fLightingTexture);
glCullFace(GL_BACK);
glBindVertexArray(m_ScreenQuad);
glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLES, 0, 6);
}
void Renderer::Swap()
{
glfwSwapBuffers(m_Window);
}
#pragma region TempRegion #pragma region TempRegion
void Renderer::DrawSkybox() void Renderer::DrawSkybox()
{ {
glBindFramebuffer(GL_FRAMEBUFFER, 0); //glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, m_Width, m_Height); //glViewport(0, 0, m_Width, m_Height);
//glScissor(0, 0, m_Width, m_Height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
m_ShaderProgramSkybox.Bind(); m_ShaderProgramSkybox.Bind();
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * glm::toMat4(glm::inverse(m_Camera->Orientation())); glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix((float)m_Width / m_Height) * glm::toMat4(glm::inverse(m_Camera->Orientation()));
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramSkybox.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(cameraMatrix)); glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramSkybox.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(cameraMatrix));
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
m_Skybox->Draw(); m_Skybox->Draw();
@@ -235,8 +460,8 @@ void Renderer::CreateShadowMap(int resolution)
glGenTextures(1, &m_ShadowDepthTexture); glGenTextures(1, &m_ShadowDepthTexture);
glBindTexture(GL_TEXTURE_2D, m_ShadowDepthTexture); glBindTexture(GL_TEXTURE_2D, m_ShadowDepthTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, resolution, resolution, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, resolution, resolution, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
@@ -253,21 +478,23 @@ void Renderer::CreateShadowMap(int resolution)
} }
} }
void Renderer::DrawShadowMap() void Renderer::DrawShadowMap(RenderQueue &rq)
{ {
glEnable(GL_DEPTH_TEST);//Tests where objects are and display them correctly glEnable(GL_DEPTH_TEST);//Tests where objects are and display them correctly
glEnable(GL_CULL_FACE); //removes triangles on the wrong side of the object glEnable(GL_CULL_FACE); //removes triangles on the wrong side of the object
glCullFace(GL_BACK); //Make it so that only the back faces are rendered glCullFace(GL_FRONT); //Make it so that only the back faces are rendered
//Binds the FBO and sets the veiwport, witch in effect is how large the shadowmap is and what resolution it has. //Binds the FBO and sets the veiwport, witch in effect is how large the shadowmap is and what resolution it has.
glBindFramebuffer(GL_FRAMEBUFFER, m_ShadowFrameBuffer); glBindFramebuffer(GL_FRAMEBUFFER, m_ShadowFrameBuffer);
glViewport(0, 0, m_ShadowMapRes, m_ShadowMapRes); glViewport(0, 0, m_ShadowMapRes, m_ShadowMapRes);
glScissor(0, 0, m_ShadowMapRes, m_ShadowMapRes);
glClear(GL_DEPTH_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT);
//glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
//Creates the "camera" for the shadowmap from the direction of the sun. //Creates the "camera" for the shadowmap from the direction of the sun.
glm::mat4 depthViewMatrix = glm::lookAt(m_SunPosition, m_SunTarget, glm::vec3(0, 1, 0)); glm::mat4 depthViewMatrix = glm::lookAt(m_SunPosition, m_SunTarget, glm::vec3(0, 1, 0)) * glm::translate(m_Camera->Position() * glm::vec3(1, 1, 1));
//glm::mat4 depthViewMatrix = glm::lookAt(m_SunPosition, m_SunTarget, glm::vec3(0, 1, 0)) * glm::translate((-m_Camera->Position() + (glm::vec3(40.0) * -m_Camera->Forward())) * glm::vec3(1, 1, 1));
glm::mat4 depthCamera = m_SunProjection * depthViewMatrix; glm::mat4 depthCamera = m_SunProjection * depthViewMatrix;
glm::mat4 MVP; glm::mat4 MVP;
@@ -275,26 +502,23 @@ void Renderer::DrawShadowMap()
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); //Draws filled polygons glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); //Draws filled polygons
//For each model, render them to the shadowmap //For each model, render them to the shadowmap
for (auto tuple : ModelsToRender) for (auto &job : rq)
{ {
Model* model; auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
glm::mat4 modelMatrix; if (modelJob)
bool shadow;
std::tie(model, modelMatrix, std::ignore, shadow) = tuple;
if (!shadow)
continue;
MVP = depthCamera * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramShadows.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
glBindVertexArray(model->VAO);
for (auto texGroup : model->TextureGroups)
{ {
glDrawArrays(GL_TRIANGLES, texGroup.StartIndex, texGroup.EndIndex - texGroup.StartIndex + 1); glm::mat4 modelMatrix = modelJob->ModelMatrix;
MVP = depthCamera * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramShadows.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
//glUniform3fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "SunDirection_cameraspace"), 1, glm::value_ptr(sunDirection_cameraview));
glBindVertexArray(modelJob->VAO);
glDrawArrays(GL_TRIANGLES, modelJob->StartIndex, modelJob->EndIndex - modelJob->StartIndex + 1);
continue;
} }
} }
} }
void Renderer::DrawDebugShadowMap() void Renderer::DrawDebugShadowMap()
@@ -355,19 +579,31 @@ void Renderer::AddModelToDraw(Model* model, glm::vec3 position, glm::quat orient
void Renderer::AddTextureToDraw(Texture* texture, glm::vec3 position, glm::quat orientation, glm::vec3 scale) void Renderer::AddTextureToDraw(Texture* texture, glm::vec3 position, glm::quat orientation, glm::vec3 scale)
{ {
glm::mat4 modelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale); //glm::mat4 modelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale);
TexturesToRender.push_back(std::make_tuple(texture, modelMatrix, position)); //glm::vec3 camToParticle = glm::normalize(m_Camera->Position() - position);
//glm::vec3 up = glm::vec3(0,1,0);
//glm::vec3 rightVec = glm::normalize(glm::cross(up, camToParticle));
//glm::vec3 up2 = glm::normalize(glm::cross(camToParticle, rightVec));
//
//glm::mat4 billboardMatrix;
//billboardMatrix[0] = glm::vec4(rightVec, 0);
//billboardMatrix[1] = glm::vec4(up2, 0);
//billboardMatrix[2] = glm::vec4(camToParticle, 0);
////billboardMatrix[3] = glm::vec4(position, 0);
//TexturesToRender.push_back(std::make_tuple(texture, modelMatrix, billboardMatrix));
} }
void Renderer::AddPointLightToDraw( void Renderer::AddPointLightToDraw(
glm::vec3 _position, glm::vec3 _position,
glm::vec3 _specular, glm::vec3 _specular,
glm::vec3 _diffuse, glm::vec3 _diffuse,
float _specularExponent, float _specularExponent,
float _ConstantAttenuation, float _ConstantAttenuation,
float _LinearAttenuation, float _LinearAttenuation,
float _QuadraticAttenuation float _QuadraticAttenuation,
float _radius
) )
{ {
Light light; Light light;
@@ -378,6 +614,7 @@ void Renderer::AddPointLightToDraw(
light.ConstantAttenuation = _ConstantAttenuation; light.ConstantAttenuation = _ConstantAttenuation;
light.LinearAttenuation = _LinearAttenuation; light.LinearAttenuation = _LinearAttenuation;
light.QuadraticAttenuation = _QuadraticAttenuation; light.QuadraticAttenuation = _QuadraticAttenuation;
light.Radius = _radius;
light.SphereModelMatrix = CreateLightMatrix(light); light.SphereModelMatrix = CreateLightMatrix(light);
Lights.push_back(light); Lights.push_back(light);
} }
@@ -537,7 +774,7 @@ void Renderer::FrameBufferTextures()
//Generate and bind diffuse texture //Generate and bind diffuse texture
glGenTextures(1, &m_fDiffuseTexture); glGenTextures(1, &m_fDiffuseTexture);
glBindTexture(GL_TEXTURE_2D, m_fDiffuseTexture); glBindTexture(GL_TEXTURE_2D, m_fDiffuseTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
@@ -546,7 +783,7 @@ void Renderer::FrameBufferTextures()
//Generate and bind position texture //Generate and bind position texture
glGenTextures(1, &m_fPositionTexture); glGenTextures(1, &m_fPositionTexture);
glBindTexture(GL_TEXTURE_2D, m_fPositionTexture); glBindTexture(GL_TEXTURE_2D, m_fPositionTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, m_Width, m_Height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
@@ -555,7 +792,7 @@ void Renderer::FrameBufferTextures()
//Generate and bind normal texture //Generate and bind normal texture
glGenTextures(1, &m_fNormalsTexture); glGenTextures(1, &m_fNormalsTexture);
glBindTexture(GL_TEXTURE_2D, m_fNormalsTexture); glBindTexture(GL_TEXTURE_2D, m_fNormalsTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB10_A2, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, m_Width, m_Height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
@@ -564,7 +801,7 @@ void Renderer::FrameBufferTextures()
//Generate and bind normal texture //Generate and bind normal texture
glGenTextures(1, &m_fSpecularTexture); glGenTextures(1, &m_fSpecularTexture);
glBindTexture(GL_TEXTURE_2D, m_fSpecularTexture); glBindTexture(GL_TEXTURE_2D, m_fSpecularTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB10_A2, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, m_Width, m_Height, 0, GL_RED, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
@@ -601,7 +838,7 @@ void Renderer::FrameBufferTextures()
glGenTextures(1, &m_fLightingTexture); glGenTextures(1, &m_fLightingTexture);
glBindTexture(GL_TEXTURE_2D, m_fLightingTexture); glBindTexture(GL_TEXTURE_2D, m_fLightingTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
@@ -623,92 +860,101 @@ void Renderer::FrameBufferTextures()
void Renderer::DrawFBO() void Renderer::DrawFBO()
{ {
DrawShadowMap(); //DrawShadowMap();
for (auto &pair : m_Viewports) //for (auto &pair : m_Viewports)
{ //{
Viewport &viewport = pair.second; // Viewport &viewport = pair.second;
if (!viewport.Camera) // if (!viewport.Camera)
continue; // continue;
int x = viewport.Left * m_Width; // int x = viewport.Left * m_Width;
int y = viewport.Top * m_Height; // int y = viewport.Top * m_Height;
int width = (viewport.Right - viewport.Left) * m_Width; // int width = (viewport.Right - viewport.Left) * m_Width;
int height = (viewport.Bottom - viewport.Top) * m_Height; // int height = (viewport.Bottom - viewport.Top) * m_Height;
//
/* // /*
Base pass // Base pass
*/ // */
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbBasePass); // glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbBasePass);
glViewport(0, 0, m_Width, m_Height); // glViewport(0, 0, m_Width, m_Height);
// Clear G-buffer // // Clear G-buffer
GLenum windowBuffClear[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 }; // GLenum windowBuffClear[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 };
glDrawBuffers(3, windowBuffClear); // glDrawBuffers(4, windowBuffClear);
glClearColor(0.f, 0.f, 0.f, 0.f); // glClearColor(0.0f, 0.3f, 0.7f, 0.f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Execute the first render stage which will fill out the internal buffers with data(??) // // Execute the first render stage which will fill out the internal buffers with data(??)
m_FirstPassProgram.Bind(); // m_FirstPassProgram.Bind();
GLenum windowBuffOpaque[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 }; // GLenum windowBuffOpaque[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 };
glDrawBuffers(3, windowBuffOpaque); // glDrawBuffers(4, windowBuffOpaque);
glCullFace(GL_BACK); // glCullFace(GL_BACK);
//
DrawFBOScene(viewport); // DrawFBOScene(viewport);
/* // /*
Lighting pass // Lighting pass
*/ // */
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbLightingPass); // glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbLightingPass);
GLenum lightingPassAttachments[] = { GL_COLOR_ATTACHMENT0 }; // GLenum lightingPassAttachments[] = { GL_COLOR_ATTACHMENT0 };
glDrawBuffers(1, lightingPassAttachments); // glDrawBuffers(1, lightingPassAttachments);
glClearColor(0.f, 0.f, 0.f, 0.f); // glClearColor(0.f, 0.f, 0.f, 0.f);
glClear(GL_COLOR_BUFFER_BIT); // glClear(GL_COLOR_BUFFER_BIT);
m_SecondPassProgram.Bind(); // m_SecondPassProgram.Bind();
glActiveTexture(GL_TEXTURE0); // glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_fPositionTexture); // glBindTexture(GL_TEXTURE_2D, m_fPositionTexture);
glActiveTexture(GL_TEXTURE1); // glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_fNormalsTexture); // glBindTexture(GL_TEXTURE_2D, m_fNormalsTexture);
// glActiveTexture(GL_TEXTURE2);
// glBindTexture(GL_TEXTURE_2D, m_fSpecularTexture);
glCullFace(GL_FRONT); // glCullFace(GL_FRONT);
DrawLightScene(viewport); // DrawLightScene(viewport);
DrawSunLightScene();
/* // /*
Final pass // Final pass
*/ // */
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); // glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glViewport(x, y, width, height); // glViewport(x, y, width, height);
glClear(GL_DEPTH_BUFFER_BIT); // glClear(GL_DEPTH_BUFFER_BIT);
m_FinalPassProgram.Bind(); // m_FinalPassProgram.Bind();
// Ambient light // // Ambient light
glUniform3fv(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "La"), 1, glm::value_ptr(glm::vec3(0.1f, 0.1f, 0.1f))); // glUniform3fv(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "La"), 1, glm::value_ptr(glm::vec3(0.7f)));
glUniform1f(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "Gamma"), Gamma); // glUniform1f(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "Gamma"), Gamma);
glActiveTexture(GL_TEXTURE0); // glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_fDiffuseTexture); // glBindTexture(GL_TEXTURE_2D, m_fDiffuseTexture);
glActiveTexture(GL_TEXTURE1); // glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_fLightingTexture); // glBindTexture(GL_TEXTURE_2D, m_fLightingTexture);
glCullFace(GL_BACK); // glCullFace(GL_BACK);
glBindVertexArray(m_ScreenQuad); // glBindVertexArray(m_ScreenQuad);
glEnableVertexAttribArray(0); // glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLES, 0, 6); // glDrawArrays(GL_TRIANGLES, 0, 6);
} //}
} }
void Renderer::DrawFBOScene(Viewport &viewport) void Renderer::DrawFBO2()
{
ForwardRendering();
}
void Renderer::DrawFBOScene(RenderQueue &rq)
{ {
// glEnable(GL_DEPTH_TEST);//Tests where objects are and display them correctly // glEnable(GL_DEPTH_TEST);//Tests where objects are and display them correctly
// glEnable(GL_CULL_FACE); //removes triangles on the wrong side of the object // glEnable(GL_CULL_FACE); //removes triangles on the wrong side of the object
// glCullFace(GL_BACK); //Make it so that only the back faces are rendered // glCullFace(GL_BACK); //Make it so that only the back faces are rendered
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); //Draws filled polygons glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); //Draws filled polygons
glm::mat4 cameraMatrix = viewport.Camera->ProjectionMatrix() * viewport.Camera->ViewMatrix(); glm::mat4 cameraProjection = m_Camera->ProjectionMatrix((float)m_Viewport.Width / m_Viewport.Height);
glm::mat4 cameraMatrix = cameraProjection * m_Camera->ViewMatrix();
glm::mat4 MVP; glm::mat4 MVP;
glm::mat4 biasMatrix( glm::mat4 biasMatrix(
0.5, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0,
@@ -717,83 +963,84 @@ void Renderer::DrawFBOScene(Viewport &viewport)
0.5, 0.5, 0.5, 1.0 0.5, 0.5, 0.5, 1.0
); );
glm::mat4 depthViewMatrix = glm::lookAt(m_SunPosition, m_SunTarget, glm::vec3(0, 1, 0)); //glm::mat4 depthViewMatrix = glm::lookAt(m_SunPosition, m_SunTarget, glm::vec3(0, 1, 0)) * glm::translate((-m_Camera->Position() + (glm::vec3(40.0) * -m_Camera->Forward())) * glm::vec3(1, 1, 1));
glm::mat4 depthViewMatrix = glm::lookAt(m_SunPosition, m_SunTarget, glm::vec3(0, 1, 0)) * glm::translate(-m_Camera->Position() * glm::vec3(1, 1, 1));
glm::mat4 depthCamera = m_SunProjection * depthViewMatrix; glm::mat4 depthCamera = m_SunProjection * depthViewMatrix;
glm::mat4 depthCameraMatrix = biasMatrix * depthCamera; glm::mat4 depthCameraMatrix = biasMatrix * depthCamera;
glm::mat4 depthMVP; glm::mat4 depthMVP;
glm::vec3 sunDirection = m_SunTarget - m_SunPosition;
glm::vec3 sunDirection_cameraview = glm::vec3(cameraProjection * m_Camera->ViewMatrix() * glm::vec4(sunDirection, 1.0));
m_FirstPassProgram.Bind();
GLuint ShaderProgramHandle = m_FirstPassProgram.GetHandle();
glActiveTexture(GL_TEXTURE1); glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_ShadowDepthTexture); glBindTexture(GL_TEXTURE_2D, m_ShadowDepthTexture);
for (auto tuple : ModelsToRender) for (auto &job : rq)
{ {
Model* model; auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
glm::mat4 modelMatrix; if (modelJob)
bool visible;
std::tie(model, modelMatrix, visible, std::ignore) = tuple;
if (!visible)
continue;
MVP = cameraMatrix * modelMatrix;
depthMVP = depthCameraMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "DepthMVP"), 1, GL_FALSE, glm::value_ptr(depthMVP));
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(viewport.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(viewport.Camera->ProjectionMatrix()));
glBindVertexArray(model->VAO);
for (auto texGroup : model->TextureGroups)
{ {
glm::mat4 modelMatrix = modelJob->ModelMatrix;
MVP = cameraMatrix * modelMatrix;
depthMVP = depthCameraMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "DepthMVP"), 1, GL_FALSE, glm::value_ptr(depthMVP));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "P"), 1, GL_FALSE, glm::value_ptr(cameraProjection));
glUniform3fv(glGetUniformLocation(ShaderProgramHandle, "SunDirection_cameraspace"), 1, glm::value_ptr(sunDirection_cameraview));
glBindVertexArray(modelJob->VAO);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, *texGroup.Texture); glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture);
if (texGroup.NormalMap) if (modelJob->NormalTexture != 0)
{ {
glActiveTexture(GL_TEXTURE2); glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, *texGroup.NormalMap); glBindTexture(GL_TEXTURE_2D, modelJob->NormalTexture);
} }
glDrawArrays(GL_TRIANGLES, texGroup.StartIndex, texGroup.EndIndex - texGroup.StartIndex + 1); if (modelJob->SpecularTexture)
{
glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_2D, modelJob->SpecularTexture);
}
glDrawArrays(GL_TRIANGLES, modelJob->StartIndex, modelJob->EndIndex - modelJob->StartIndex + 1);
continue;
} }
}
for (auto tuple : TexturesToRender)
{
Texture* texture;
glm::mat4 modelMatrix;
glm::vec3 position;
std::tie(texture, modelMatrix, position) = tuple;
//MVP = cameraMatrix * glm::inverse(glm::toMat4(m_Camera->Orientation()) * modelMatrix ); //auto spriteJob = std::dynamic_pointer_cast<SpriteJob>(job);
//if (spriteJob)
//{
// Texture* texture;
// glm::mat4 modelMatrix;
// glm::mat4 billboardMatrix;
// std::tie(texture, modelMatrix, billboardMatrix) = tuple;
glm::vec3 camToParticle = glm::normalize(viewport.Camera->Position() - position); // //MVP = cameraMatrix * glm::inverse(glm::toMat4(m_Camera->Orientation()) * modelMatrix );
glm::vec3 up = glm::vec3(0,1,0); // MVP = cameraMatrix * modelMatrix * billboardMatrix;
glm::vec3 rightVec = glm::normalize(glm::cross(up, camToParticle));
glm::vec3 up2 = glm::normalize(glm::cross(camToParticle, rightVec));
glm::mat4 billboardMatrix; // depthMVP = depthCameraMatrix * modelMatrix;
billboardMatrix[0] = glm::vec4(rightVec, 0); // glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
billboardMatrix[1] = glm::vec4(up2, 0); // glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "DepthMVP"), 1, GL_FALSE, glm::value_ptr(depthMVP));
billboardMatrix[2] = glm::vec4(camToParticle, 0); // glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
//billboardMatrix[3] = glm::vec4(position, 0); // glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
// glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(m_Camera->ProjectionMatrix((float)m_Width / m_Height)));
MVP = cameraMatrix * modelMatrix * billboardMatrix; // glActiveTexture(GL_TEXTURE0);
// glBindTexture(GL_TEXTURE_2D, *texture);
// glBindVertexArray(m_ScreenQuad);
// glDrawArrays(GL_TRIANGLES, 0, 6);
depthMVP = depthCameraMatrix * modelMatrix; // continue;
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP)); //}
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "DepthMVP"), 1, GL_FALSE, glm::value_ptr(depthMVP));
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(viewport.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(viewport.Camera->ProjectionMatrix()));
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, *texture);
glBindVertexArray(m_ScreenQuad);
glDrawArrays(GL_TRIANGLES, 0, 6);
} }
} }
void Renderer::DrawLightScene(RenderQueue &rq)
void Renderer::DrawLightScene(Viewport &viewport)
{ {
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendEquation (GL_FUNC_ADD); glBlendEquation (GL_FUNC_ADD);
@@ -803,32 +1050,72 @@ void Renderer::DrawLightScene(Viewport &viewport)
glDepthMask (GL_FALSE); glDepthMask (GL_FALSE);
glBindVertexArray(m_sphereModel->VAO); glBindVertexArray(m_sphereModel->VAO);
glm::mat4 cameraMatrix = viewport.Camera->ProjectionMatrix() * viewport.Camera->ViewMatrix(); glm::mat4 cameraProjection = m_Camera->ProjectionMatrix((float)m_Viewport.Width / m_Viewport.Height);
glm::mat4 cameraMatrix = cameraProjection * m_Camera->ViewMatrix();
glm::mat4 MVP; glm::mat4 MVP;
glm::vec3 sunDirection = m_SunTarget - m_SunPosition;
m_SecondPassProgram.Bind();
GLuint ShaderProgramHandle = m_SecondPassProgram.GetHandle();
for (auto &light : Lights) for (auto &light : Lights)
{ {
MVP = cameraMatrix * light.SphereModelMatrix; MVP = cameraMatrix * light.SphereModelMatrix;
glUniform2fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ViewportSize"), 1,glm::value_ptr(glm::vec2(m_Width, m_Height)));
glUniformMatrix4fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
glUniformMatrix4fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(viewport.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(viewport.Camera->ProjectionMatrix()));
glUniformMatrix4fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(light.SphereModelMatrix));
glUniform3fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ls"), 1, glm::value_ptr(light.Specular));
glUniform3fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ld"), 1, glm::value_ptr(light.Diffuse));
glUniform3fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "lp"), 1, glm::value_ptr(light.Position));
glUniform3f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "CameraPosition"), viewport.Camera->Position().x, viewport.Camera->Position().y, viewport.Camera->Position().z);
glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "specularExponent"), light.SpecularExponent);
// glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ConstantAttenuation"), light.ConstantAttenuation);
// glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "LinearAttenuation"), light.LinearAttenuation);
// glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "QuadraticAttenuation"), light.QuadraticAttenuation);
glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ConstantAttenuation"), CAtt);
glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "LinearAttenuation"), LAtt);
glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "QuadraticAttenuation"), QAtt);
glDrawArrays(GL_TRIANGLES, 0, m_sphereModel->Vertices.size()); glUniform2fv(glGetUniformLocation(ShaderProgramHandle, "ViewportSize"), 1,glm::value_ptr(glm::vec2(m_Width, m_Height)));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "P"), 1, GL_FALSE, glm::value_ptr(cameraProjection));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(light.SphereModelMatrix));
glUniform3fv(glGetUniformLocation(ShaderProgramHandle, "ls"), 1, glm::value_ptr(light.Specular));
glUniform3fv(glGetUniformLocation(ShaderProgramHandle, "ld"), 1, glm::value_ptr(light.Diffuse));
glUniform3fv(glGetUniformLocation(ShaderProgramHandle, "lp"), 1, glm::value_ptr(light.Position));
glUniform3f(glGetUniformLocation(ShaderProgramHandle, "CameraPosition"), m_Camera->Position().x, m_Camera->Position().y, m_Camera->Position().z);
glUniform1f(glGetUniformLocation(ShaderProgramHandle, "specularExponent"), light.SpecularExponent);
//glUniform1f(glGetUniformLocation(ShaderProgramHandle, "ConstantAttenuation"), CAtt);
//glUniform1f(glGetUniformLocation(ShaderProgramHandle, "LinearAttenuation"), LAtt);
//glUniform1f(glGetUniformLocation(ShaderProgramHandle, "QuadraticAttenuation"), QAtt);
glUniform1f(glGetUniformLocation(ShaderProgramHandle, "LightRadius"), light.Radius);
glUniform3fv(glGetUniformLocation(ShaderProgramHandle, "directionToSun"), 1, glm::value_ptr(-sunDirection));
glDrawArrays(GL_TRIANGLES, 0, m_sphereModel->Vertices.size());
}; };
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glDisable(GL_BLEND);
}
void Renderer::DrawSunLightScene()
{
glCullFace(GL_BACK);
glEnable(GL_BLEND);
glBlendEquation (GL_FUNC_ADD);
glBlendFunc(GL_ONE,GL_ONE);
glDisable (GL_DEPTH_TEST);
glDepthMask (GL_FALSE);
//glBindVertexArray(m_sphereModel->VAO);
glm::mat4 cameraProjection = m_Camera->ProjectionMatrix((float)m_Viewport.Width / m_Viewport.Height);
glm::mat4 cameraMatrix = cameraProjection * m_Camera->ViewMatrix();
glm::mat4 MVP;
m_SunPassProgram.Bind();
GLuint ShaderProgramHandle = m_SunPassProgram.GetHandle();
glUniform2fv(glGetUniformLocation(ShaderProgramHandle, "ViewportSize"), 1, glm::value_ptr(glm::vec2(m_Width, m_Height)));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "P"), 1, GL_FALSE, glm::value_ptr(cameraProjection));
glUniform3f(glGetUniformLocation(ShaderProgramHandle, "CameraPosition"), m_Camera->Position().x, m_Camera->Position().y, m_Camera->Position().z);
glUniform3fv(glGetUniformLocation(ShaderProgramHandle, "directionToSun"), 1, glm::value_ptr(glm::normalize(m_SunPosition)));
glBindVertexArray(m_ScreenQuad);
glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLES, 0, 6);
glEnable (GL_DEPTH_TEST); glEnable (GL_DEPTH_TEST);
glDepthMask (GL_TRUE); glDepthMask (GL_TRUE);
glDisable (GL_BLEND); glDisable (GL_BLEND);
@@ -844,14 +1131,14 @@ glm::mat4 Renderer::CreateLightMatrix(Light &_light)
// float c = _light.ConstantAttenuation; // float c = _light.ConstantAttenuation;
// float l = _light.LinearAttenuation; // float l = _light.LinearAttenuation;
// float q = _light.QuadraticAttenuation; // float q = _light.QuadraticAttenuation;
float c = CAtt; //float c = CAtt;
float l = LAtt; //float l = LAtt;
float q = QAtt; //float q = QAtt;
float cutOffRadius = abs(sqrt((-4*c*q) + pow(l, 2) + (1024*q) - l) / (2*q)); //float cutOffRadius = abs(sqrt((-4*c*q) + pow(l, 2) + (1024*q) - l) / (2*q));
glm::mat4 model; glm::mat4 model;
model *= glm::translate(_light.Position); model *= glm::translate(_light.Position);
model *= glm::scale(glm::vec3(cutOffRadius)); model *= glm::scale(glm::vec3(_light.Radius*2));
return model; return model;
} }
@@ -869,7 +1156,7 @@ void Renderer::UpdateSunProjection()
glm::vec3(1.f, 1.f, 1.f) glm::vec3(1.f, 1.f, 1.f)
}; };
glm::mat4 inverseProjectionViewMatrix = glm::inverse(m_Camera->ViewMatrix()) * glm::inverse(m_Camera->ProjectionMatrix()); glm::mat4 inverseProjectionViewMatrix = glm::inverse(m_Camera->ViewMatrix()) * glm::inverse(m_Camera->ProjectionMatrix((float)m_Width / m_Height));
//Also * with world matrix for light //Also * with world matrix for light
for(auto corner : NDCCube) for(auto corner : NDCCube)
@@ -882,35 +1169,72 @@ void Renderer::UpdateSunProjection()
//Pass the bounding box's extents to glOrtho or similar to set up the orthographic projection matrix for the shadow map. //Pass the bounding box's extents to glOrtho or similar to set up the orthographic projection matrix for the shadow map.
} }
void Renderer::RegisterViewport(int identifier, float left, float top, float right, float bottom) void Renderer::ForwardRendering()
{ {
Viewport v; glBindFramebuffer(GL_FRAMEBUFFER, 0);
v.Left = left; glViewport(0, 0, m_Width, m_Height);
v.Top = top;
v.Right = right; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
v.Bottom = bottom; glClearColor(0.0f, 0.5f, 0.0f, 1.0f);
v.Camera = nullptr;
m_Viewports[identifier] = v; glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix((float)m_Width / m_Height) * m_Camera->ViewMatrix();
glm::mat4 MVP;
m_ForwardRendering.Bind();
GLuint ShaderProgramHandle = m_ForwardRendering.GetHandle();
for (auto tuple : ModelsToRender) //// Todo: Add so it's TransparentModelsToRender
{
Model* model;
glm::mat4 modelMatrix;
bool visible;
std::tie(model, modelMatrix, visible, std::ignore) = tuple;
if (!visible)
continue;
MVP = cameraMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_Camera->ProjectionMatrix((float)m_Width / m_Height)));
glBindVertexArray(model->VAO);
for (auto texGroup : model->TextureGroups)
{
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, *texGroup.Texture);
glDrawArrays(GL_TRIANGLES, texGroup.StartIndex, texGroup.EndIndex - texGroup.StartIndex + 1);
}
}
} }
void Renderer::RegisterCamera(int identifier, float FOV, float nearClip, float farClip) void Renderer::RegisterCamera(int identifier, float FOV, float nearClip, float farClip)
{ {
m_Cameras[identifier] = std::make_shared<Camera>(FOV, (float)m_Width / m_Height, nearClip, farClip); m_Cameras[identifier] = std::make_shared<Camera>(FOV, nearClip, farClip);
} }
void Renderer::UpdateViewport(int viewportIdentifier, int cameraIdentifier) void Renderer::UpdateViewport(int viewportIdentifier, int cameraIdentifier)
{ {
auto &viewport = m_Viewports[viewportIdentifier]; //auto &viewport = m_Viewports[viewportIdentifier];
auto camera = m_Cameras[cameraIdentifier]; //auto camera = m_Cameras[cameraIdentifier];
camera->AspectRatio(((viewport.Right - viewport.Left) * m_Width) / ((viewport.Bottom - viewport.Top) * m_Height)); //camera->AspectRatio(((viewport.Right - viewport.Left) * m_Width) / ((viewport.Bottom - viewport.Top) * m_Height));
viewport.Camera = camera; //viewport.Camera = camera;
} }
void Renderer::UpdateCamera(int cameraIdentifier, glm::vec3 position, glm::quat orientation, float FOV, float nearClip, float farClip) void Renderer::UpdateCamera(int cameraIdentifier, glm::vec3 position, glm::quat orientation, float FOV, float nearClip, float farClip)
{ {
m_Cameras[cameraIdentifier]->Position(position); /*m_Cameras[cameraIdentifier]->Position(position);
m_Cameras[cameraIdentifier]->Orientation(orientation); m_Cameras[cameraIdentifier]->Orientation(orientation);
m_Cameras[cameraIdentifier]->FOV(FOV); m_Cameras[cameraIdentifier]->FOV(FOV);
m_Cameras[cameraIdentifier]->NearClip(nearClip); m_Cameras[cameraIdentifier]->NearClip(nearClip);
m_Cameras[cameraIdentifier]->FarClip(farClip); m_Cameras[cameraIdentifier]->FarClip(farClip);*/
}
void Renderer::ClearPointLights()
{
Lights.clear();
} }
+42 -8
View File
@@ -13,6 +13,8 @@
#include "Components/PointLight.h" #include "Components/PointLight.h"
#include "Skybox.h" #include "Skybox.h"
#include "ResourceManager.h" #include "ResourceManager.h"
#include "Util/Rectangle.h"
#include "RenderQueue.h"
class Renderer class Renderer
{ {
@@ -29,7 +31,7 @@ public:
std::list<std::tuple<Texture*, glm::mat4, glm::vec3>> TexturesToRender; std::list<std::tuple<Texture*, glm::mat4, glm::vec3>> TexturesToRender;
std::list<std::tuple<glm::mat4, bool>> AABBsToRender; std::list<std::tuple<glm::mat4, bool>> AABBsToRender;
Renderer(); Renderer(std::shared_ptr<::ResourceManager> resourceManager);
void Initialize(); void Initialize();
void Draw(double dt); void Draw(double dt);
@@ -40,6 +42,23 @@ public:
void UpdateViewport(int viewportIdentifier, int cameraIdentifier); void UpdateViewport(int viewportIdentifier, int cameraIdentifier);
void UpdateCamera(int cameraIdentifier, glm::vec3 position, glm::quat orientation, float FOV, float nearClip, float farClip); void UpdateCamera(int cameraIdentifier, glm::vec3 position, glm::quat orientation, float FOV, float nearClip, float farClip);
#pragma region NEWSTUFF
void SetViewport(const Rectangle &viewport)
{
m_Viewport = viewport;
}
void SetCamera(std::shared_ptr<Camera> camera)
{
m_Camera = camera;
}
void DrawFrame(RenderQueue &rq);
void DrawWorld(RenderQueue &rq);
void Swap();
#pragma endregion
void AddModelToDraw(Model* model, glm::vec3 position, glm::quat orientation, glm::vec3 scale, bool visible, bool shadowCaster); void AddModelToDraw(Model* model, glm::vec3 position, glm::quat orientation, glm::vec3 scale, bool visible, bool shadowCaster);
void AddTextureToDraw(Texture* texture, glm::vec3 position, glm::quat orientation, glm::vec3 scale); void AddTextureToDraw(Texture* texture, glm::vec3 position, glm::quat orientation, glm::vec3 scale);
void AddTextToDraw(); void AddTextToDraw();
@@ -50,8 +69,11 @@ public:
float _specularExponent, float _specularExponent,
float _ConstantAttenuation, float _ConstantAttenuation,
float _LinearAttenuation, float _LinearAttenuation,
float _QuadraticAttenuation float _QuadraticAttenuation,
float _radius
); );
void ClearPointLights();
void AddAABBToDraw(glm::vec3 origin, glm::vec3 volumeVector, bool colliding); void AddAABBToDraw(glm::vec3 origin, glm::vec3 volumeVector, bool colliding);
void LoadContent(); void LoadContent();
@@ -70,6 +92,8 @@ public:
void SetSphereModel(Model* _model); void SetSphereModel(Model* _model);
private: private:
std::shared_ptr<::ResourceManager> ResourceManager;
int m_Width, m_Height; int m_Width, m_Height;
struct Viewport struct Viewport
@@ -84,6 +108,9 @@ private:
std::unordered_map<int, Viewport> m_Viewports; std::unordered_map<int, Viewport> m_Viewports;
std::unordered_map<int, std::shared_ptr<Camera>> m_Cameras; std::unordered_map<int, std::shared_ptr<Camera>> m_Cameras;
Rectangle m_Viewport;
std::shared_ptr<Camera> m_Camera;
struct Light struct Light
{ {
glm::vec3 Position; glm::vec3 Position;
@@ -91,7 +118,7 @@ private:
glm::vec3 Diffuse; glm::vec3 Diffuse;
float SpecularExponent; float SpecularExponent;
glm::mat4 SphereModelMatrix; glm::mat4 SphereModelMatrix;
float ConstantAttenuation, LinearAttenuation, QuadraticAttenuation; float ConstantAttenuation, LinearAttenuation, QuadraticAttenuation, Radius;
}; };
float Gamma; float Gamma;
@@ -113,6 +140,10 @@ private:
glm::vec3 m_SunPosition; glm::vec3 m_SunPosition;
glm::vec3 m_SunTarget; glm::vec3 m_SunTarget;
glm::mat4 m_SunProjection; glm::mat4 m_SunProjection;
glm::vec2 m_SunProjection_width;
glm::vec2 m_SunProjection_height;
glm::vec2 m_SunProjection_length;
GLuint m_DebugAABB; GLuint m_DebugAABB;
GLuint m_ShadowFrameBuffer; GLuint m_ShadowFrameBuffer;
@@ -135,13 +166,13 @@ private:
bool m_QuadView; bool m_QuadView;
std::shared_ptr<Camera> m_Camera;
ShaderProgram m_ShaderProgram; ShaderProgram m_ShaderProgram;
ShaderProgram m_FirstPassProgram; ShaderProgram m_FirstPassProgram;
ShaderProgram m_SecondPassProgram; ShaderProgram m_SecondPassProgram;
ShaderProgram m_SecondPassProgram_Debug; ShaderProgram m_SecondPassProgram_Debug;
ShaderProgram m_FinalPassProgram; ShaderProgram m_FinalPassProgram;
ShaderProgram m_SunPassProgram;
ShaderProgram m_ForwardRendering;
ShaderProgram m_ShaderProgramNormals; ShaderProgram m_ShaderProgramNormals;
ShaderProgram m_ShaderProgramShadows; ShaderProgram m_ShaderProgramShadows;
@@ -154,16 +185,19 @@ private:
void ClearStuff(); void ClearStuff();
void DrawScene(); void DrawScene();
void DrawModels(ShaderProgram &shader); void DrawModels(ShaderProgram &shader);
void DrawShadowMap(); void DrawShadowMap(RenderQueue &rq);
void CreateShadowMap(int resolution); void CreateShadowMap(int resolution);
void FrameBufferTextures(); void FrameBufferTextures();
void DrawFBO(); void DrawFBO();
void DrawFBOScene(Viewport &viewport); void DrawFBO2();
void DrawLightScene(Viewport &viewport); void DrawFBOScene(RenderQueue &rq);
void DrawLightScene(RenderQueue &rq);
void DrawSunLightScene();
void BindFragDataLocation(); void BindFragDataLocation();
glm::mat4 CreateLightMatrix(Light &_light); glm::mat4 CreateLightMatrix(Light &_light);
void UpdateSunProjection(); void UpdateSunProjection();
void CreateNormalMapTangent(); void CreateNormalMapTangent();
void ForwardRendering();
GLuint CreateQuad(); GLuint CreateQuad();
+38 -1
View File
@@ -155,4 +155,41 @@ void ShaderProgram::Bind()
void ShaderProgram::Unbind() void ShaderProgram::Unbind()
{ {
glActiveShaderProgram(0, 0); glActiveShaderProgram(0, 0);
} }
void ShaderProgram::LoadFromFolder(std::string folderPath)
{
auto path = boost::filesystem::path(folderPath);
if (!boost::filesystem::is_directory(path))
{
LOG_ERROR("Failed to load shader program: \"%s\" is not a directory", folderPath.c_str());
return;
}
for (auto it = boost::filesystem::directory_iterator(path); it != boost::filesystem::directory_iterator(); it++)
{
std::string filename = it->path().filename().string();
if (filename == "Vertex.glsl")
{
AddShader(std::shared_ptr<Shader>(new VertexShader(filename)));
}
else if (filename == "Fragment.glsl")
{
AddShader(std::shared_ptr<Shader>(new FragmentShader(filename)));
}
else if (filename == "Geometry.glsl")
{
AddShader(std::shared_ptr<Shader>(new GeometryShader(filename)));
}
}
}
void ShaderProgram::BindFragDataLocation(int colorNumber, std::string name)
{
if (m_ShaderProgramHandle == 0)
return;
glBindFragDataLocation(m_ShaderProgramHandle, colorNumber, name.c_str());
}
+16 -2
View File
@@ -6,6 +6,11 @@
#include <fstream> #include <fstream>
#include <vector> #include <vector>
#include <boost/filesystem.hpp>
#include <boost/filesystem/path.hpp>
#include "ResourceManager.h"
class Shader class Shader
{ {
public: public:
@@ -57,23 +62,32 @@ public:
: ShaderType(fileName) { } : ShaderType(fileName) { }
}; };
class ShaderProgram class ShaderProgram : public Resource
{ {
public: public:
ShaderProgram() ShaderProgram()
: m_ShaderProgramHandle(0) { } : m_ShaderProgramHandle(0)
{ }
ShaderProgram(std::string folderPath)
: m_ShaderProgramHandle(0)
{ }
~ShaderProgram(); ~ShaderProgram();
void AddShader(std::shared_ptr<Shader> shader); void AddShader(std::shared_ptr<Shader> shader);
void BindFragDataLocation(int colorNumber, std::string name);
void Compile(); void Compile();
GLuint Link(); GLuint Link();
GLuint GetHandle(); GLuint GetHandle();
operator GLuint() const { return m_ShaderProgramHandle; }
void Bind(); void Bind();
void Unbind(); void Unbind();
private: private:
GLuint m_ShaderProgramHandle; GLuint m_ShaderProgramHandle;
std::vector<std::shared_ptr<Shader>> m_Shaders; std::vector<std::shared_ptr<Shader>> m_Shaders;
void LoadFromFolder(std::string folderPath);
}; };
#endif // ShaderProgram_h__ #endif // ShaderProgram_h__
+4 -3
View File
@@ -21,9 +21,10 @@ void main()
vec4 LightingTexel = texture(LightingTexture, Input.TextureCoord); vec4 LightingTexel = texture(LightingTexture, Input.TextureCoord);
vec4 ShadowTexel = texture(ShadowTexture, Input.TextureCoord); vec4 ShadowTexel = texture(ShadowTexture, Input.TextureCoord);
//FragmentColor = LightingTexel + vec4(LightingTexel.a, LightingTexel.a, LightingTexel.a, 0.0);
vec4 _FragmentColor = DiffuseTexel * vec4(La, 1.0) + LightingTexel;
FragmentColor = vec4(pow(_FragmentColor.rgb, vec3(1.0 / Gamma)), _FragmentColor.a);
//FragmentColor = DiffuseTexel; //FragmentColor = DiffuseTexel;
FragmentColor = DiffuseTexel * (vec4(La, 0.0) + vec4(LightingTexel.rgb, 0.0)) + vec4(LightingTexel.a, LightingTexel.a, LightingTexel.a, 0.0);
//FragmentColor = vec4(pow(_FragmentColor.rgb, vec3(1.0 / Gamma)), _FragmentColor.a);
} }
+20
View File
@@ -0,0 +1,20 @@
#version 430
uniform vec4 Color;
layout(binding=0) uniform sampler2D texture0;
in VertexData {
vec3 Position;
vec3 Normal;
vec2 TextureCoord;
} Input;
out vec4 fragmentColor;
void main() {
// Texture
vec4 texel = texture(texture0, Input.TextureCoord);
fragmentColor = texel * Color;
}
+25
View File
@@ -0,0 +1,25 @@
#version 430
uniform mat4 MVP;
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
layout (location = 0) in vec3 Position;
layout (location = 1) in vec3 Normal;
layout (location = 2) in vec2 TextureCoord;
out VertexData {
vec3 Position;
vec3 Normal;
vec2 TextureCoord;
} Output;
void main()
{
gl_Position = MVP * vec4(Position, 1.0);
Output.Position = Position;
Output.Normal = Normal;
Output.TextureCoord = TextureCoord;
}
+52 -11
View File
@@ -5,6 +5,15 @@ layout (binding=1) uniform sampler2D ShadowTexture;
layout (binding=2) uniform sampler2D NormalMapTexture; layout (binding=2) uniform sampler2D NormalMapTexture;
layout (binding=3) uniform sampler2D SpecularMapTexture; layout (binding=3) uniform sampler2D SpecularMapTexture;
//TerrainTextures
layout (binding=4) uniform sampler2D AsphaltTexture;
layout (binding=5) uniform sampler2D GrassTexture;
layout (binding=6) uniform sampler2D SandTexture;
layout (binding=7) uniform sampler2D BlendMap;
uniform float texScale; //Determines how many times the textures will loop over the terrain
uniform vec3 SunDirection_cameraspace;
uniform mat4 V;
in VertexData in VertexData
{ {
@@ -19,16 +28,28 @@ in VertexData
out vec4 frag_Diffuse; out vec4 frag_Diffuse;
out vec4 frag_Position; out vec4 frag_Position;
out vec4 frag_Normal; out vec4 frag_Normal;
out vec4 frag_specular; out vec4 frag_Specular;
float Shadow(vec4 ShadowCoord) float Shadow(vec4 ShadowCoord, vec3 normal)
{ {
//float cosTheta = clamp(dot(Input.Normal, 1.0), 0.0, 1.0); return 1.0;
float bias = 0.0005; // cosTheta is dot( n,l ), clamped between 0 and 1
bias = clamp(bias, 0.0, 0.01); if (Input.ShadowCoord.x < 0.0 || Input.ShadowCoord.x > 1.0 || Input.ShadowCoord.y < 0.0 || Input.ShadowCoord.y > 1.0)
if( texture(ShadowTexture, Input.ShadowCoord.xy).z < ShadowCoord.z - bias) return 0.9;
//Variable bias
vec3 n = normalize(normal);
vec3 l = normalize(SunDirection_cameraspace);
float cosTheta = clamp(dot(n, l), 0.0, 1.0);
float bias = tan(acos(cosTheta));
bias = clamp(bias, 0.0, 0.00003);
//Fixed bias
bias = 0;
if( texture(ShadowTexture, Input.ShadowCoord.xy).z < ShadowCoord.z + bias)
{ {
return 0.3; return 0.6;
} }
else else
{ {
@@ -38,18 +59,38 @@ float Shadow(vec4 ShadowCoord)
void main() void main()
{ {
//Fixa så den bara gör detta om modellen har en blend map
//vvvvvv
vec4 Blend = texture2D(BlendMap, Input.TextureCoord.st );
vec4 AsphaltTexel = texture2D(AsphaltTexture, Input.TextureCoord.st * texScale);
vec4 GrassTexel = texture2D(GrassTexture, Input.TextureCoord.st * texScale);
vec4 SandTexel = texture2D(SandTexture, Input.TextureCoord.st * texScale);
//Mix the Terrain-textures together
AsphaltTexel *= Blend.r;
GrassTexel = mix(AsphaltTexel, GrassTexel, Blend.g);
vec4 tex = mix(GrassTexel, SandTexel, Blend.b);
//^^^^^^
//Fixa så den bara gör detta om modellen har en blend map
// Diffuse Texture
frag_Diffuse = texture(DiffuseTexture, Input.TextureCoord); // * Shadow(Input.ShadowCoord);
// G-buffer Position // G-buffer Position
frag_Position = vec4(Input.Position.xyz, 1.0); frag_Position = vec4(Input.Position.xyz, 1.0);
// G-buffer Normal // G-buffer Normal
mat3 TBN = transpose(mat3(Input.Tangent, Input.BiTangent, Input.Normal)); mat3 TBN = mat3(Input.Tangent, Input.BiTangent, Input.Normal);
frag_Normal = normalize(vec4(TBN * vec3(texture(NormalMapTexture, Input.TextureCoord)), 0.0)); frag_Normal = normalize(vec4(TBN * vec3(texture(NormalMapTexture, Input.TextureCoord)), 0.0));
//frag_Diffuse = normalize(vec4(TBN * vec3(texture(NormalMapTexture, Input.TextureCoord)), 0.0));
//frag_Normal = vec4(Input.Normal, 0.0); //frag_Normal = vec4(Input.Normal, 0.0);
// Diffuse Texture
//frag_Diffuse = tex;
frag_Diffuse = texture(DiffuseTexture, Input.TextureCoord) * Shadow(Input.ShadowCoord, vec3(frag_Normal));
//G-buffer Specular //G-buffer Specular
frag_specular = texture(SpecularMapTexture, Input.TextureCoord); frag_Specular = texture(SpecularMapTexture, Input.TextureCoord);
} }
+10 -23
View File
@@ -2,6 +2,7 @@
layout (binding=0) uniform sampler2D PositionTexture; layout (binding=0) uniform sampler2D PositionTexture;
layout (binding=1) uniform sampler2D NormalsTexture; layout (binding=1) uniform sampler2D NormalsTexture;
layout (binding=2) uniform sampler2D SpecularTexture;
uniform vec2 ViewportSize; uniform vec2 ViewportSize;
uniform mat4 MVP; uniform mat4 MVP;
@@ -17,12 +18,14 @@ uniform vec3 CameraPosition;
uniform float ConstantAttenuation; uniform float ConstantAttenuation;
uniform float LinearAttenuation; uniform float LinearAttenuation;
uniform float QuadraticAttenuation; uniform float QuadraticAttenuation;
uniform float LightRadius;
const vec3 ks = vec3(1.0, 1.0, 1.0); const vec3 ks = vec3(1.0, 1.0, 1.0);
const vec3 kd = vec3(1.0, 1.0, 1.0); const vec3 kd = vec3(1.0, 1.0, 1.0);
const vec3 ka = vec3(1.0, 1.0, 1.0); const vec3 ka = vec3(1.0, 1.0, 1.0);
const float kshine = 1.0; const float kshine = 1.0;
in VertexData in VertexData
{ {
vec3 Position; vec3 Position;
@@ -31,7 +34,7 @@ in VertexData
out vec4 FragColor; out vec4 FragColor;
vec4 phong(vec3 position, vec3 normal) vec4 phong(vec3 position, vec3 normal, vec3 specular)
{ {
// Diffuse // Diffuse
vec3 lightPos = vec3(V * vec4(lp, 1.0)); vec3 lightPos = vec3(V * vec4(lp, 1.0));
@@ -46,32 +49,15 @@ vec4 phong(vec3 position, vec3 normal)
vec3 surfaceToViewer = normalize(-position); vec3 surfaceToViewer = normalize(-position);
vec3 halfWay = normalize(surfaceToViewer + directionToLight); vec3 halfWay = normalize(surfaceToViewer + directionToLight);
float dotSpecular = max(dot(halfWay, normal), 0.0); float dotSpecular = max(dot(halfWay, normal), 0.0);
float specularFactor = pow(dotSpecular, specularExponent * 2.0); float specularFactor = pow(dotSpecular, specularExponent);
vec3 Is = ks * ls * specularFactor; vec3 Is = specular.r * ls * specularFactor;
//Attenuation //Attenuation
float dist = distance(lightPos, position); float dist = distance(lightPos, position);
//float attenuation = -log(min(1.0, dist / LightRadius));
float attenuation = 1.0 / (ConstantAttenuation + (LinearAttenuation * dist) + (QuadraticAttenuation * dist * dist)); float attenuation = pow(max(0.0f, 1.0 - (dist / LightRadius)), 2);
//float attenuation = 1.0 / (1.0 - 0.0001 * pow(dist, 2)); return vec4((Id) * attenuation, Is.r * attenuation);
//float attenuation = clamp(0.0, 1.0, 1.0 / (0.001 + (0.001 * dist) + (0.001 * dist * dist)));
//float attenuation = 1.0 / dot(directionToLight, directionToLight);
//float att_s = 5;
//float attenuation = pow(dist, 2) / pow(5.0, 2);
//attenuation = 1.0 / (1.0 + attenuation * att_s);
//att_s = 1.0 / (1.0 + att_s);
//attenuation = attenuation / (1.0 - att_s);
//float radius = 5.0;
//float alpha = dist / radius;
//float dampingFactor = 1.0 - pow(alpha, 3);
return vec4((Id + Is) * attenuation, 1.0);
} }
void main() void main()
@@ -79,7 +65,8 @@ void main()
vec2 TextureCoord = gl_FragCoord.xy / ViewportSize; vec2 TextureCoord = gl_FragCoord.xy / ViewportSize;
vec4 PositionTexel = texture(PositionTexture, TextureCoord); vec4 PositionTexel = texture(PositionTexture, TextureCoord);
vec4 NormalTexel = texture(NormalsTexture, TextureCoord); vec4 NormalTexel = texture(NormalsTexture, TextureCoord);
vec4 SpecularTexel = texture(SpecularTexture, TextureCoord);
FragColor = phong(vec3(PositionTexel), vec3(NormalTexel)); FragColor = phong(vec3(PositionTexel), vec3(NormalTexel), vec3(SpecularTexel));
//FragColor = NormalTexel; //FragColor = NormalTexel;
} }
+61
View File
@@ -0,0 +1,61 @@
#version 430
layout (binding=0) uniform sampler2D PositionTexture;
layout (binding=1) uniform sampler2D NormalsTexture;
layout (binding=2) uniform sampler2D SpecularTexture;
uniform vec2 ViewportSize;
uniform mat4 MVP;
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
uniform vec3 CameraPosition;
uniform vec3 directionToSun;
const vec3 ks = vec3(1.0, 1.0, 1.0);
const vec3 kd = vec3(1.0, 1.0, 1.0);
const vec3 ka = vec3(1.0, 1.0, 1.0);
const float kshine = 1.0;
const vec3 SunDiffuseLight = vec3(0.3, 0.3, 0.3);
const vec3 SunSpecularLight = vec3(1.0, 1.0, 1.0);
const vec3 SunPos = directionToSun*vec3(100);
const float specularExponent = 5;
in VertexData
{
vec3 Position;
vec2 TextureCoord;
} Input;
out vec4 FragColor;
vec4 phong(vec3 position, vec3 normal, vec3 specular)
{
//Diffuse Sunlight
vec3 directionToLight = normalize(vec3(V * vec4(directionToSun, 0.0)));
float dotProdLight = dot(directionToLight, normal);
dotProdLight = max(dotProdLight, 0.0);
vec3 sId = kd * SunDiffuseLight * dotProdLight;
//Specular Sunlight
vec3 surfaceToViewer = normalize(-position);
vec3 halfWay = normalize(surfaceToViewer + directionToLight);
float dotSpecular = max(dot(halfWay, normal), 0.0);
float specularFactorSun = pow(dotSpecular, specularExponent);
vec3 sIs = specular.r * SunSpecularLight * specularFactorSun;
return vec4((sId), sIs.r);
}
void main()
{
vec2 TextureCoord = gl_FragCoord.xy / ViewportSize;
vec4 PositionTexel = texture(PositionTexture, TextureCoord);
vec4 NormalTexel = texture(NormalsTexture, TextureCoord);
vec4 SpecularTexel = texture(SpecularTexture, TextureCoord);
FragColor = phong(vec3(PositionTexel), vec3(normalize(NormalTexel)), vec3(SpecularTexel));
//FragColor = NormalTexel;
}
+21
View File
@@ -0,0 +1,21 @@
#version 430
uniform mat4 MVP;
layout (location = 0) in vec3 Position;
layout (location = 2) in vec2 TextureCoord;
uniform mat4 depthBiasMVP;
out VertexData
{
vec3 Position;
vec2 TextureCoord;
} Output;
void main()
{
gl_Position = MVP * vec4(Position, 1.0);
Output.Position = Position;
Output.TextureCoord = (vec2(Position) + 1.0) / 2.0;
}
+6 -3
View File
@@ -12,13 +12,15 @@ class World;
class System class System
{ {
public: public:
System(World* world, std::shared_ptr<EventBroker> eventBroker) System(World* world, std::shared_ptr<EventBroker> eventBroker, std::shared_ptr<ResourceManager> resourceManager)
: m_World(world) : m_World(world)
, EventBroker(eventBroker) { } , EventBroker(eventBroker)
, ResourceManager(resourceManager)
{ }
virtual ~System() { } virtual ~System() { }
virtual void RegisterComponents(ComponentFactory* cf) { } virtual void RegisterComponents(ComponentFactory* cf) { }
virtual void RegisterResourceTypes(ResourceManager* rm) { } virtual void RegisterResourceTypes(std::shared_ptr<::ResourceManager> rm) { }
virtual void Initialize() { } virtual void Initialize() { }
@@ -38,6 +40,7 @@ public:
protected: protected:
World* m_World; World* m_World;
std::shared_ptr<EventBroker> EventBroker; std::shared_ptr<EventBroker> EventBroker;
std::shared_ptr<ResourceManager> ResourceManager;
}; };
class SystemFactory : public Factory<System*> { }; class SystemFactory : public Factory<System*> { };
+2 -2
View File
@@ -16,7 +16,7 @@ void Systems::DamageSystem::Initialize()
bool Systems::DamageSystem::OnDamage( const Events::Damage &event ) bool Systems::DamageSystem::OnDamage( const Events::Damage &event )
{ {
auto health = m_World->GetComponent<Components::Health>(event.Entity); auto health = m_World->GetComponent<Components::Health>(event.Entity);
health->health -= event.damage; health->Amount -= event.Amount;
LOG_INFO("Damaged entity %i, Health left: %f", event.Entity, health->health); LOG_INFO("Damaged entity %i, Health left: %f", event.Entity, health->Amount);
return true; return true;
} }
+2 -2
View File
@@ -12,8 +12,8 @@ namespace Systems
{ {
public: public:
DamageSystem(World* world, std::shared_ptr<::EventBroker> eventBroker) DamageSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
: System(world, eventBroker) { } : System(world, eventBroker, resourceManager) { }
void Initialize() override; void Initialize() override;
+3 -2
View File
@@ -12,8 +12,9 @@ namespace Systems
class DebugSystem : public System class DebugSystem : public System
{ {
public: public:
DebugSystem(World* world, std::shared_ptr<::EventBroker> eventBroker) DebugSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
: System(world, eventBroker) { } : System(world, eventBroker, resourceManager)
{ }
void Initialize() override; void Initialize() override;
+3 -3
View File
@@ -40,6 +40,7 @@ void Systems::FreeSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
glm::quat mouseOrientationPitch = glm::quat(m_InputController->MouseOrientation * glm::vec3(1, 0, 0)); glm::quat mouseOrientationPitch = glm::quat(m_InputController->MouseOrientation * glm::vec3(1, 0, 0));
glm::quat mouseOrientationYaw = glm::quat(m_InputController->MouseOrientation * glm::vec3(0, 1, 0)); glm::quat mouseOrientationYaw = glm::quat(m_InputController->MouseOrientation * glm::vec3(0, 1, 0));
m_InputController->MouseOrientation = glm::vec3(0);
glm::vec3 controllerOrientationEuler = m_InputController->ControllerOrientation * (float)dt; glm::vec3 controllerOrientationEuler = m_InputController->ControllerOrientation * (float)dt;
glm::quat controllerOrientationPitch = glm::quat(controllerOrientationEuler * glm::vec3(1, 0, 0)); glm::quat controllerOrientationPitch = glm::quat(controllerOrientationEuler * glm::vec3(1, 0, 0));
@@ -53,8 +54,6 @@ void Systems::FreeSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// TOUCHING THIS CODE MIGHT CAUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS // TOUCHING THIS CODE MIGHT CAUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS
} }
m_InputController->MouseOrientation = glm::vec3(0);
} }
bool Systems::FreeSteeringSystem::FreeSteeringInputController::OnCommand(const Events::InputCommand &event) bool Systems::FreeSteeringSystem::FreeSteeringInputController::OnCommand(const Events::InputCommand &event)
@@ -80,7 +79,7 @@ bool Systems::FreeSteeringSystem::FreeSteeringInputController::OnCommand(const E
} }
// Mouse click // Mouse click
else if (event.Command == "cam_attack") else if (event.Command == "cam_lock")
{ {
OrientationActive = event.Value > 0; OrientationActive = event.Value > 0;
@@ -113,6 +112,7 @@ bool Systems::FreeSteeringSystem::FreeSteeringInputController::OnMouseMove(const
if (OrientationActive) if (OrientationActive)
{ {
MouseOrientation = -glm::vec3(event.DeltaY / 300.f, event.DeltaX / 300.f, 0.f); MouseOrientation = -glm::vec3(event.DeltaY / 300.f, event.DeltaX / 300.f, 0.f);
LOG_DEBUG("Mouse DX: %f", event.DeltaX);
} }
return true; return true;
+3 -2
View File
@@ -12,8 +12,9 @@ namespace Systems
class FreeSteeringSystem : public System class FreeSteeringSystem : public System
{ {
public: public:
FreeSteeringSystem(World* world, std::shared_ptr<::EventBroker> eventBroker) FreeSteeringSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
: System(world, eventBroker) { } : System(world, eventBroker, resourceManager)
{ }
void RegisterComponents(ComponentFactory* cf) override; void RegisterComponents(ComponentFactory* cf) override;
void Initialize() override; void Initialize() override;
+3 -2
View File
@@ -11,8 +11,9 @@ namespace Systems
class HelicopterSteeringSystem : public System class HelicopterSteeringSystem : public System
{ {
public: public:
HelicopterSteeringSystem(World* world, std::shared_ptr<::EventBroker> eventBroker) HelicopterSteeringSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
: System(world, eventBroker) { } : System(world, eventBroker, resourceManager)
{ }
void RegisterComponents(ComponentFactory* cf) override; void RegisterComponents(ComponentFactory* cf) override;
void Initialize() override; void Initialize() override;
+3 -2
View File
@@ -25,8 +25,9 @@ namespace Systems
class InputSystem : public System class InputSystem : public System
{ {
public: public:
InputSystem(World* world, std::shared_ptr<::EventBroker> eventBroker) InputSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
: System(world, eventBroker) { } : System(world, eventBroker, resourceManager)
{ }
void RegisterComponents(ComponentFactory* cf) override; void RegisterComponents(ComponentFactory* cf) override;
void Initialize() override; void Initialize() override;
+3 -2
View File
@@ -27,8 +27,9 @@ namespace Systems
class ParticleSystem : public System class ParticleSystem : public System
{ {
public: public:
ParticleSystem(World* world, std::shared_ptr<::EventBroker> eventBroker) ParticleSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
: System(world, eventBroker) { } : System(world, eventBroker, resourceManager)
{ }
void RegisterComponents(ComponentFactory* cf) override; void RegisterComponents(ComponentFactory* cf) override;
void Update(double dt) override; void Update(double dt) override;
+1 -1
View File
@@ -614,7 +614,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
{ {
std::vector<hkReal>* vertices = new std::vector<hkReal>; std::vector<hkReal>* vertices = new std::vector<hkReal>;
std::vector<hkUint16>* vertexIndices = new std::vector<hkUint16>; std::vector<hkUint16>* vertexIndices = new std::vector<hkUint16>;
auto meshShape = m_World->GetResourceManager()->Load<OBJ>("OBJ", meshShapeComponent->ResourceName); auto meshShape = ResourceManager->Load<OBJ>("OBJ", meshShapeComponent->ResourceName);
for (auto &vertex : meshShape->Vertices) for (auto &vertex : meshShape->Vertices)
{ {
+2 -2
View File
@@ -147,8 +147,8 @@ public:
}; };
friend class PhantomCallbackShape; friend class PhantomCallbackShape;
PhysicsSystem(World* world, std::shared_ptr<::EventBroker> eventBroker) PhysicsSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
: System(world, eventBroker) { } : System(world, eventBroker, resourceManager) { }
void RegisterComponents(ComponentFactory* cf) override; void RegisterComponents(ComponentFactory* cf) override;
void Initialize() override; void Initialize() override;
+81 -84
View File
@@ -2,11 +2,9 @@
#include "RenderSystem.h" #include "RenderSystem.h"
#include "World.h" #include "World.h"
void Systems::RenderSystem::RegisterResourceTypes(ResourceManager* rm) void Systems::RenderSystem::RegisterResourceTypes(std::shared_ptr<::ResourceManager> rm)
{ {
rm->RegisterType("Model", [rm](std::string resourceName) { return new Model(rm, *rm->Load<OBJ>("OBJ", resourceName)); }); rm->RegisterType("Shader", [](std::string resourceName) { return new ShaderProgram(resourceName); });
rm->RegisterType("OBJ", [](std::string resourceName) { return new OBJ(resourceName); });
rm->RegisterType("Texture", [](std::string resourceName) { return new Texture(resourceName); });
} }
void Systems::RenderSystem::RegisterComponents(ComponentFactory* cf) void Systems::RenderSystem::RegisterComponents(ComponentFactory* cf)
@@ -21,100 +19,99 @@ void Systems::RenderSystem::RegisterComponents(ComponentFactory* cf)
void Systems::RenderSystem::OnEntityCommit(EntityID entity) void Systems::RenderSystem::OnEntityCommit(EntityID entity)
{ {
auto transform = m_World->GetComponent<Components::Transform>(entity); //auto transform = m_World->GetComponent<Components::Transform>(entity);
auto camera = m_World->GetComponent<Components::Camera>(entity); //auto camera = m_World->GetComponent<Components::Camera>(entity);
if (transform && camera) //if (transform && camera)
{ //{
m_Renderer->RegisterCamera(entity, camera->FOV, camera->NearClip, camera->FarClip); // m_Renderer->RegisterCamera(entity, camera->FOV, camera->NearClip, camera->FarClip);
m_Renderer->UpdateCamera(entity, m_TransformSystem->AbsolutePosition(entity), m_TransformSystem->AbsoluteOrientation(entity), camera->FOV, camera->NearClip, camera->FarClip); // m_Renderer->UpdateCamera(entity, m_TransformSystem->AbsolutePosition(entity), m_TransformSystem->AbsoluteOrientation(entity), camera->FOV, camera->NearClip, camera->FarClip);
} //}
auto viewport = m_World->GetComponent<Components::Viewport>(entity); //auto viewport = m_World->GetComponent<Components::Viewport>(entity);
if (viewport) //if (viewport)
{ //{
m_Renderer->RegisterViewport(entity, viewport->Left, viewport->Top, viewport->Right, viewport->Bottom); // m_Renderer->RegisterViewport(entity, viewport->Left, viewport->Top, viewport->Right, viewport->Bottom);
if (viewport->Camera != 0) // if (viewport->Camera != 0)
{ // {
m_Renderer->UpdateViewport(entity, viewport->Camera); // m_Renderer->UpdateViewport(entity, viewport->Camera);
} // }
} //}
} }
void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{ {
auto templateComponent = m_World->GetComponent<Components::Template>(entity); //auto templateComponent = m_World->GetComponent<Components::Template>(entity);
if (templateComponent) //if (templateComponent)
return; // return;
auto transformComponent = m_World->GetComponent<Components::Transform>(entity); //auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
// Draw models //// Draw models
auto modelComponent = m_World->GetComponent<Components::Model>(entity); //auto modelComponent = m_World->GetComponent<Components::Model>(entity);
if (transformComponent && modelComponent) //if (transformComponent && modelComponent)
{ //{
auto model = m_World->GetResourceManager()->Load<Model>("Model", modelComponent->ModelFile); // auto model = m_World->ResourceManager->Load<Model>("Model", modelComponent->ModelFile);
if (model) // if (model)
{ // {
/*glm::vec3 position = m_TransformSystem->AbsolutePosition(entity); // /*glm::vec3 position = m_TransformSystem->AbsolutePosition(entity);
glm::quat orientation = m_TransformSystem->AbsoluteOrientation(entity); // glm::quat orientation = m_TransformSystem->AbsoluteOrientation(entity);
glm::vec3 scale = m_TransformSystem->AbsoluteScale(entity);*/ // glm::vec3 scale = m_TransformSystem->AbsoluteScale(entity);*/
Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity); // Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity);
m_Renderer->AddModelToDraw(model, absoluteTransform.Position, absoluteTransform.Orientation, absoluteTransform.Scale, modelComponent->Visible, modelComponent->ShadowCaster); // m_Renderer->AddModelToDraw(model, absoluteTransform.Position, absoluteTransform.Orientation, absoluteTransform.Scale, modelComponent->Visible, modelComponent->ShadowCaster);
} // }
} //}
auto pointLightComponent = m_World->GetComponent<Components::PointLight>(entity); //auto pointLightComponent = m_World->GetComponent<Components::PointLight>(entity);
if (transformComponent && pointLightComponent) //if (transformComponent && pointLightComponent)
{ //{
glm::vec3 position = m_TransformSystem->AbsolutePosition(entity); // glm::vec3 position = m_TransformSystem->AbsolutePosition(entity);
m_Renderer->AddPointLightToDraw( // m_Renderer->AddPointLightToDraw(
position, // position,
pointLightComponent->Specular, // pointLightComponent->Specular,
pointLightComponent->Diffuse, // pointLightComponent->Diffuse,
pointLightComponent->specularExponent, // pointLightComponent->specularExponent,
pointLightComponent->ConstantAttenuation, // pointLightComponent->ConstantAttenuation,
pointLightComponent->LinearAttenuation, // pointLightComponent->LinearAttenuation,
pointLightComponent->QuadraticAttenuation // pointLightComponent->QuadraticAttenuation
); // );
} //}
auto cameraComponent = m_World->GetComponent<Components::Camera>(entity); //auto cameraComponent = m_World->GetComponent<Components::Camera>(entity);
if (transformComponent && cameraComponent) //if (transformComponent && cameraComponent)
{ //{
m_Renderer->UpdateCamera(entity // m_Renderer->UpdateCamera(entity
, m_TransformSystem->AbsolutePosition(entity) // , m_TransformSystem->AbsolutePosition(entity)
, m_TransformSystem->AbsoluteOrientation(entity) // , m_TransformSystem->AbsoluteOrientation(entity)
, cameraComponent->FOV // , cameraComponent->FOV
, cameraComponent->NearClip // , cameraComponent->NearClip
, cameraComponent->FarClip); // , cameraComponent->FarClip);
} //}
auto viewportComponent = m_World->GetComponent<Components::Viewport>(entity); //auto viewportComponent = m_World->GetComponent<Components::Viewport>(entity);
if (viewportComponent) //if (viewportComponent)
{ //{
if (viewportComponent->Camera != 0) // if (viewportComponent->Camera != 0)
{ // {
m_Renderer->UpdateViewport(entity, viewportComponent->Camera); // m_Renderer->UpdateViewport(entity, viewportComponent->Camera);
} // }
} //}
auto spriteComponent = m_World->GetComponent<Components::Sprite>(entity); //auto spriteComponent = m_World->GetComponent<Components::Sprite>(entity);
if (transformComponent && spriteComponent) //if (transformComponent && spriteComponent)
{ //{
//TEMP // //TEMP
Texture* texture = m_World->GetResourceManager()->Load<Texture>("Texture", spriteComponent->SpriteFile); // Texture* texture = m_World->ResourceManager->Load<Texture>("Texture", spriteComponent->SpriteFile);
//glBindTexture(GL_TEXTURE_2D, texture); // //glBindTexture(GL_TEXTURE_2D, texture);
auto transform = m_World->GetComponent<Components::Transform>(spriteComponent->Entity); // auto transform = m_World->GetComponent<Components::Transform>(spriteComponent->Entity);
glm::quat orientation2D = glm::angleAxis(glm::eulerAngles(transform->Orientation).z, glm::vec3(0, 0, -1)); // glm::quat orientation2D = glm::angleAxis(glm::eulerAngles(transform->Orientation).z, glm::vec3(0, 0, -1));
m_Renderer->AddTextureToDraw(texture, transform->Position, orientation2D, transform->Scale); // m_Renderer->AddTextureToDraw(texture, transform->Position, orientation2D, transform->Scale);
} //}
} }
void Systems::RenderSystem::Initialize() void Systems::RenderSystem::Initialize()
{ {
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>(); //m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>();
m_Renderer->SetSphereModel(m_World->GetResourceManager()->Load<Model>("Model", "Models/Placeholders/PhysicsTest/Sphere.obj"));
}
//m_Renderer->SetSphereModel(m_World->ResourceManager->Load<Model>("Model", "Models/Placeholders/PhysicsTest/Sphere.obj"));
}
+11 -9
View File
@@ -5,6 +5,7 @@
#include "System.h" #include "System.h"
#include "Systems/TransformSystem.h" #include "Systems/TransformSystem.h"
#include "ShaderProgram.h"
#include "Model.h" #include "Model.h"
#include "Texture.h" #include "Texture.h"
#include "Components/Transform.h" #include "Components/Transform.h"
@@ -14,10 +15,11 @@
#include "Components/PointLight.h" #include "Components/PointLight.h"
#include "Components/DirectionalLight.h" #include "Components/DirectionalLight.h"
#include "Components/Viewport.h" #include "Components/Viewport.h"
#include "Components/Template.h" #include "Components/Template.h"
#include "Components/Transform.h" #include "Components/Transform.h"
#include "Renderer.h" #include "Renderer.h"
#include "RenderQueue.h"
#include "Events/SetViewportCamera.h"
namespace Systems namespace Systems
{ {
@@ -25,12 +27,12 @@ namespace Systems
class RenderSystem : public System class RenderSystem : public System
{ {
public: public:
RenderSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<Renderer> renderer) RenderSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
: System(world, eventBroker) : System(world, eventBroker, resourceManager)
, m_Renderer(renderer) { } { }
void RegisterComponents(ComponentFactory* cf) override; void RegisterComponents(ComponentFactory* cf) override;
void RegisterResourceTypes(ResourceManager* rm) override; void RegisterResourceTypes(std::shared_ptr<::ResourceManager> rm) override;
void Initialize() override; void Initialize() override;
std::unordered_map<std::string, std::shared_ptr<Model>> m_CachedModels; std::unordered_map<std::string, std::shared_ptr<Model>> m_CachedModels;
@@ -38,12 +40,12 @@ public:
void OnEntityCommit(EntityID entity) override; void OnEntityCommit(EntityID entity) override;
void UpdateEntity(double dt, EntityID entity, EntityID parent) override; void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
private: private:
std::shared_ptr<Renderer> m_Renderer;
std::shared_ptr<Systems::TransformSystem> m_TransformSystem; std::shared_ptr<Systems::TransformSystem> m_TransformSystem;
void EnqueueModel(Model* model, glm::mat4 modelMatrix);
void EnqueueSprite(Texture* texture, glm::mat4 modelMatrix);
}; };
+4 -4
View File
@@ -32,7 +32,7 @@ void Systems::SoundSystem::RegisterComponents(ComponentFactory* cf)
cf->Register<Components::SoundEmitter>([]() { return new Components::SoundEmitter(); }); cf->Register<Components::SoundEmitter>([]() { return new Components::SoundEmitter(); });
} }
void Systems::SoundSystem::RegisterResourceTypes(ResourceManager* rm) void Systems::SoundSystem::RegisterResourceTypes(std::shared_ptr<::ResourceManager> rm)
{ {
rm->RegisterType("Sound", [](std::string resourceName) { return new Sound(resourceName); }); rm->RegisterType("Sound", [](std::string resourceName) { return new Sound(resourceName); });
} }
@@ -94,7 +94,7 @@ void Systems::SoundSystem::PlaySound(Components::SoundEmitter* emitter, std::str
if (m_Sources.find(emitter) == m_Sources.end()) if (m_Sources.find(emitter) == m_Sources.end())
return; return;
ALuint buffer = *m_World->GetResourceManager()->Load<Sound>("Sound", fileName); ALuint buffer = *ResourceManager->Load<Sound>("Sound", fileName);
if (buffer == 0) if (buffer == 0)
return; return;
ALuint source = m_Sources[emitter]; ALuint source = m_Sources[emitter];
@@ -104,7 +104,7 @@ void Systems::SoundSystem::PlaySound(Components::SoundEmitter* emitter, std::str
void Systems::SoundSystem::PlaySound(std::shared_ptr<Components::SoundEmitter> emitter) void Systems::SoundSystem::PlaySound(std::shared_ptr<Components::SoundEmitter> emitter)
{ {
ALuint buffer = *m_World->GetResourceManager()->Load<Sound>("Sound", emitter->Path); ALuint buffer = *ResourceManager->Load<Sound>("Sound", emitter->Path);
ALuint source = m_Sources[emitter.get()]; ALuint source = m_Sources[emitter.get()];
alSourcei(source, AL_BUFFER, buffer); alSourcei(source, AL_BUFFER, buffer);
alSourcePlay(m_Sources[emitter.get()]); alSourcePlay(m_Sources[emitter.get()]);
@@ -151,7 +151,7 @@ bool Systems::SoundSystem::OnPlaySound(const Events::PlaySound &event)
{ {
LOG_DEBUG("Events::PlaySound.Resource = %s", event.Resource.c_str()); LOG_DEBUG("Events::PlaySound.Resource = %s", event.Resource.c_str());
ALuint buffer = *m_World->GetResourceManager()->Load<Sound>("Sound", event.Resource); ALuint buffer = *ResourceManager->Load<Sound>("Sound", event.Resource);
ALuint source = m_Sources.begin()->second; ALuint source = m_Sources.begin()->second;
alSourcei(source, AL_BUFFER, buffer); alSourcei(source, AL_BUFFER, buffer);
alSourcePlay(source); alSourcePlay(source);
+4 -3
View File
@@ -16,11 +16,12 @@ namespace Systems
class SoundSystem : public System class SoundSystem : public System
{ {
public: public:
SoundSystem(World* world, std::shared_ptr<::EventBroker> eventBroker) SoundSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
: System(world, eventBroker) { } : System(world, eventBroker, resourceManager)
{ }
void RegisterComponents(ComponentFactory* cf) override; void RegisterComponents(ComponentFactory* cf) override;
void RegisterResourceTypes(ResourceManager* rm) override; void RegisterResourceTypes(std::shared_ptr<::ResourceManager> rm) override;
void Initialize() override; void Initialize() override;
void Update(double dt) override; void Update(double dt) override;
+1 -1
View File
@@ -150,7 +150,7 @@ bool Systems::TankSteeringSystem::OnCollision( const Events::Collision &e )
{ {
Events::Damage d; Events::Damage d;
d.Entity = physicsEntity; d.Entity = physicsEntity;
d.damage = (1.f - pow(distance / radius, 2)) * shellComponent->Damage; d.Amount = (1.f - pow(distance / radius, 2)) * shellComponent->Damage;
EventBroker->Publish(d); EventBroker->Publish(d);
} }
+3 -2
View File
@@ -37,8 +37,9 @@ namespace Systems
class TankSteeringSystem : public System class TankSteeringSystem : public System
{ {
public: public:
TankSteeringSystem(World* world, std::shared_ptr<::EventBroker> eventBroker) TankSteeringSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
: System(world, eventBroker) { } : System(world, eventBroker, resourceManager)
{ }
void RegisterComponents(ComponentFactory* cf) override; void RegisterComponents(ComponentFactory* cf) override;
void Initialize() override; void Initialize() override;
+2 -2
View File
@@ -13,8 +13,8 @@ namespace Systems
{ {
public: public:
TimerSystem(World* world, std::shared_ptr<::EventBroker> eventBroker) TimerSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
: System(world, eventBroker) { } : System(world, eventBroker, resourceManager) { }
void RegisterComponents(ComponentFactory* cf) override; void RegisterComponents(ComponentFactory* cf) override;
void UpdateEntity(double dt, EntityID entity, EntityID parent) override; void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
+3 -2
View File
@@ -10,8 +10,9 @@ namespace Systems
class TransformSystem : public System class TransformSystem : public System
{ {
public: public:
TransformSystem(World* world, std::shared_ptr<::EventBroker> eventBroker) TransformSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
: System(world, eventBroker) { } : System(world, eventBroker, resourceManager)
{ }
//void Update(double dt) override; //void Update(double dt) override;
//void UpdateEntity(double dt, EntityID entity, EntityID parent) override; //void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
+2 -2
View File
@@ -22,8 +22,8 @@ namespace Systems
{ {
public: public:
TriggerSystem(World* world, std::shared_ptr<::EventBroker> eventBroker) TriggerSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
: System(world, eventBroker) { } : System(world, eventBroker, resourceManager) { }
void Initialize() override; void Initialize() override;
void RegisterComponents(ComponentFactory* cf) override; void RegisterComponents(ComponentFactory* cf) override;
+9 -9
View File
@@ -19,24 +19,24 @@ struct Rectangle
int Width; int Width;
int Height; int Height;
const int& GetLeft() const { return X; } virtual int Left() const { return X; }
void SetLeft(int left) void SetLeft(int left)
{ {
Width += X - left; Width += X - left;
X = left; X = left;
} }
int GetRight() const { return X + Width; } virtual int Right() const { return X + Width; }
void SetRight(int right) void SetRight(int right)
{ {
Width = right - X; Width = right - X;
} }
const int& GetTop() const { return Y; } virtual int Top() const { return Y; }
void SetTop(int top) void SetTop(int top)
{ {
Height += Y - top; Height += Y - top;
Y = top; Y = top;
} }
int GetBottom() const { return Y + Height; } virtual int Bottom() const { return Y + Height; }
int SetBottom(int bottom) int SetBottom(int bottom)
{ {
Height = bottom - Y; Height = bottom - Y;
@@ -44,15 +44,15 @@ struct Rectangle
Rectangle& operator+=(const Rectangle &rhs) Rectangle& operator+=(const Rectangle &rhs)
{ {
SetLeft(std::min(GetLeft(), rhs.GetLeft())); SetLeft(std::min(Left(), rhs.Left()));
SetRight(std::max(GetRight(), rhs.GetRight())); SetRight(std::max(Right(), rhs.Right()));
SetTop(std::min(GetTop(), rhs.GetTop())); SetTop(std::min(Top(), rhs.Top()));
SetBottom(std::max(GetBottom(), rhs.GetBottom())); SetBottom(std::max(Bottom(), rhs.Bottom()));
} }
static bool Intersects(const Rectangle &r1, const Rectangle &r2) static bool Intersects(const Rectangle &r1, const Rectangle &r2)
{ {
return !(r2.GetLeft() > r1.GetRight() || r2.GetRight() < r1.GetLeft() || r2.GetTop() > r1.GetBottom() || r2.GetBottom() < r1.GetTop()); return !(r2.Left() > r1.Right() || r2.Right() < r1.Left() || r2.Top() > r1.Bottom() || r2.Bottom() < r1.Top());
} }
}; };
+2 -2
View File
@@ -38,7 +38,7 @@ void World::Update(double dt)
{ {
const std::string &type = pair.first; const std::string &type = pair.first;
auto system = pair.second; auto system = pair.second;
m_EventBroker->Process(type); EventBroker->Process(type);
system->Update(dt); system->Update(dt);
RecursiveUpdate(system, dt, 0); RecursiveUpdate(system, dt, 0);
} }
@@ -136,7 +136,7 @@ void World::Initialize()
{ {
auto system = pair.second; auto system = pair.second;
system->RegisterComponents(&m_ComponentFactory); system->RegisterComponents(&m_ComponentFactory);
system->RegisterResourceTypes(&m_ResourceManager); system->RegisterResourceTypes(ResourceManager);
system->Initialize(); system->Initialize();
} }
} }
+6 -7
View File
@@ -22,8 +22,9 @@
class World class World
{ {
public: public:
World(std::shared_ptr<::EventBroker> eventBroker) World(std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
: m_EventBroker(eventBroker) : EventBroker(eventBroker)
, ResourceManager(resourceManager)
, m_LastEntityID(0) { } , m_LastEntityID(0) { }
~World() { } ~World() { }
@@ -95,14 +96,12 @@ public:
std::unordered_map<EntityID, EntityID>* GetEntities() { return &m_EntityParents; } std::unordered_map<EntityID, EntityID>* GetEntities() { return &m_EntityParents; }
ResourceManager* GetResourceManager() { return &m_ResourceManager; }
std::shared_ptr<::EventBroker> EventBroker() { return m_EventBroker; }
protected: protected:
std::shared_ptr<::EventBroker> m_EventBroker; std::shared_ptr<::EventBroker> EventBroker;
std::shared_ptr<::ResourceManager> ResourceManager;
SystemFactory m_SystemFactory; SystemFactory m_SystemFactory;
ComponentFactory m_ComponentFactory; ComponentFactory m_ComponentFactory;
ResourceManager m_ResourceManager;
std::unordered_map<std::string, std::shared_ptr<System>> m_Systems; std::unordered_map<std::string, std::shared_ptr<System>> m_Systems;
+1
View File
@@ -4,6 +4,7 @@
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
Engine engine(argc, argv); Engine engine(argc, argv);
LOG_INFO("------------ Engine initialized ------------");
while (engine.Running()) while (engine.Running())
engine.Tick(); engine.Tick();
+3 -1
View File
@@ -1,6 +1,8 @@
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012 # Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Returngeance", "Returngeance\Returngeance.vcxproj", "{E8B4A2A2-882B-402A-98A7-8B4F7233C8B3}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Returngeance", "Returngeance\Returngeance.vcxproj", "{E8B4A2A2-882B-402A-98A7-8B4F7233C8B3}"
EndProject EndProject
Project("{F088123C-0E9E-452A-89E6-6BA2F21D5CAC}") = "ModelingProject1", "ModelingProject1\ModelingProject1.modelproj", "{B35F204C-3377-457E-AC9E-D9606F421191}" Project("{F088123C-0E9E-452A-89E6-6BA2F21D5CAC}") = "ModelingProject1", "ModelingProject1\ModelingProject1.modelproj", "{B35F204C-3377-457E-AC9E-D9606F421191}"
+10
View File
@@ -187,12 +187,18 @@
<ClInclude Include="..\..\src\Events\MouseRelease.h" /> <ClInclude Include="..\..\src\Events\MouseRelease.h" />
<ClInclude Include="..\..\src\Events\PlaySound.h" /> <ClInclude Include="..\..\src\Events\PlaySound.h" />
<ClInclude Include="..\..\src\Events\SetVelocity.h" /> <ClInclude Include="..\..\src\Events\SetVelocity.h" />
<ClInclude Include="..\..\src\Events\SetViewportCamera.h" />
<ClInclude Include="..\..\src\Events\TankSteer.h" /> <ClInclude Include="..\..\src\Events\TankSteer.h" />
<ClInclude Include="..\..\src\Events\EnterTrigger.h" /> <ClInclude Include="..\..\src\Events\EnterTrigger.h" />
<ClInclude Include="..\..\src\Factory.h" /> <ClInclude Include="..\..\src\Factory.h" />
<ClInclude Include="..\..\src\GameWorld.h" /> <ClInclude Include="..\..\src\GameWorld.h" />
<ClInclude Include="..\..\src\GUI\Frame.h" /> <ClInclude Include="..\..\src\GUI\Frame.h" />
<ClInclude Include="..\..\src\EventBroker.h" /> <ClInclude Include="..\..\src\EventBroker.h" />
<ClInclude Include="..\..\src\GUI\GameFrame.h" />
<ClInclude Include="..\..\src\GUI\HealthOverlay.h" />
<ClInclude Include="..\..\src\GUI\PlayerHUD.h" />
<ClInclude Include="..\..\src\GUI\WorldFrame.h" />
<ClInclude Include="..\..\src\GUI\TextureFrame.h" />
<ClInclude Include="..\..\src\GUI\Viewport.h" /> <ClInclude Include="..\..\src\GUI\Viewport.h" />
<ClInclude Include="..\..\src\InputController.h" /> <ClInclude Include="..\..\src\InputController.h" />
<ClInclude Include="..\..\src\InputManager.h" /> <ClInclude Include="..\..\src\InputManager.h" />
@@ -231,6 +237,8 @@
<None Include="..\..\src\Shaders\AABB.frag.glsl" /> <None Include="..\..\src\Shaders\AABB.frag.glsl" />
<None Include="..\..\src\Shaders\FinalPass.frag.glsl" /> <None Include="..\..\src\Shaders\FinalPass.frag.glsl" />
<None Include="..\..\src\Shaders\FinalPass.vert.glsl" /> <None Include="..\..\src\Shaders\FinalPass.vert.glsl" />
<None Include="..\..\src\Shaders\ForwardRendering.frag.glsl" />
<None Include="..\..\src\Shaders\ForwardRendering.vert.glsl" />
<None Include="..\..\src\Shaders\Fragment.glsl" /> <None Include="..\..\src\Shaders\Fragment.glsl" />
<None Include="..\..\src\Shaders\Fragment2-Debug.glsl" /> <None Include="..\..\src\Shaders\Fragment2-Debug.glsl" />
<None Include="..\..\src\Shaders\Fragment2.glsl" /> <None Include="..\..\src\Shaders\Fragment2.glsl" />
@@ -240,6 +248,8 @@
<None Include="..\..\src\Shaders\ShadowMap.vert.glsl" /> <None Include="..\..\src\Shaders\ShadowMap.vert.glsl" />
<None Include="..\..\src\Shaders\Skybox.frag.glsl" /> <None Include="..\..\src\Shaders\Skybox.frag.glsl" />
<None Include="..\..\src\Shaders\Skybox.vert.glsl" /> <None Include="..\..\src\Shaders\Skybox.vert.glsl" />
<None Include="..\..\src\Shaders\SunPass.frag.glsl" />
<None Include="..\..\src\Shaders\SunPass.vert.glsl" />
<None Include="..\..\src\Shaders\Vertex.glsl" /> <None Include="..\..\src\Shaders\Vertex.glsl" />
<None Include="..\..\src\Shaders\Vertex2.glsl" /> <None Include="..\..\src\Shaders\Vertex2.glsl" />
<None Include="..\..\src\Shaders\VisualizeDepth.frag.glsl" /> <None Include="..\..\src\Shaders\VisualizeDepth.frag.glsl" />
@@ -170,6 +170,9 @@
<Filter Include="Gameplay\Systems"> <Filter Include="Gameplay\Systems">
<UniqueIdentifier>{3c2ea0e5-41a1-4b11-a891-1d59ead7223c}</UniqueIdentifier> <UniqueIdentifier>{3c2ea0e5-41a1-4b11-a891-1d59ead7223c}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="Rendering\Events">
<UniqueIdentifier>{a025d51e-594d-4844-983b-f683726bf1bf}</UniqueIdentifier>
</Filter>
<Filter Include="Gameplay\Events"> <Filter Include="Gameplay\Events">
<UniqueIdentifier>{9702064a-02a2-4b3c-a2ab-47c23a9cf49c}</UniqueIdentifier> <UniqueIdentifier>{9702064a-02a2-4b3c-a2ab-47c23a9cf49c}</UniqueIdentifier>
</Filter> </Filter>
@@ -391,6 +394,9 @@
<ClInclude Include="..\..\src\Components\Viewport.h"> <ClInclude Include="..\..\src\Components\Viewport.h">
<Filter>Physics\Components</Filter> <Filter>Physics\Components</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\Components\Health.h">
<Filter>Physics\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\LockMouse.h"> <ClInclude Include="..\..\src\Events\LockMouse.h">
<Filter>Input\Events</Filter> <Filter>Input\Events</Filter>
</ClInclude> </ClInclude>
@@ -454,6 +460,24 @@
<ClInclude Include="..\..\src\Components\Flag.h"> <ClInclude Include="..\..\src\Components\Flag.h">
<Filter>Gameplay\Components</Filter> <Filter>Gameplay\Components</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\GUI\TextureFrame.h">
<Filter>GUI</Filter>
</ClInclude>
<ClInclude Include="..\..\src\GUI\WorldFrame.h">
<Filter>GUI</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\SetViewportCamera.h">
<Filter>Rendering\Events</Filter>
</ClInclude>
<ClInclude Include="..\..\src\GUI\GameFrame.h">
<Filter>GUI</Filter>
</ClInclude>
<ClInclude Include="..\..\src\GUI\HealthOverlay.h">
<Filter>GUI</Filter>
</ClInclude>
<ClInclude Include="..\..\src\GUI\PlayerHUD.h">
<Filter>GUI</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="..\..\src\Shaders\Fragment2.glsl"> <None Include="..\..\src\Shaders\Fragment2.glsl">
@@ -504,5 +528,17 @@
<None Include="..\..\src\Shaders\FinalPass.frag.glsl"> <None Include="..\..\src\Shaders\FinalPass.frag.glsl">
<Filter>Shaders</Filter> <Filter>Shaders</Filter>
</None> </None>
<None Include="..\..\src\Shaders\ForwardRendering.frag.glsl">
<Filter>Shaders</Filter>
</None>
<None Include="..\..\src\Shaders\ForwardRendering.vert.glsl">
<Filter>Shaders</Filter>
</None>
<None Include="..\..\src\Shaders\SunPass.frag.glsl">
<Filter>Shaders</Filter>
</None>
<None Include="..\..\src\Shaders\SunPass.vert.glsl">
<Filter>Shaders</Filter>
</None>
</ItemGroup> </ItemGroup>
</Project> </Project>
+89
View File
@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?>
<VSPerformanceSession Version="1.00">
<Options>
<Solution>Returngeance.sln</Solution>
<CollectionMethod>Sampling</CollectionMethod>
<AllocationMethod>None</AllocationMethod>
<AddReport>true</AddReport>
<ResourceBasedAnalysisSelected>true</ResourceBasedAnalysisSelected>
<UniqueReport>Timestamp</UniqueReport>
<SamplingMethod>Cycles</SamplingMethod>
<CycleCount>10000000</CycleCount>
<PageFaultCount>10</PageFaultCount>
<SysCallCount>10</SysCallCount>
<SamplingCounter Name="" ReloadValue="00000000000f4240" DisplayName="" />
<RelocateBinaries>false</RelocateBinaries>
<HardwareCounters EnableHWCounters="false" />
<EtwSettings />
<PdhSettings>
<PdhCountersEnabled>false</PdhCountersEnabled>
<PdhCountersRate>500</PdhCountersRate>
<PdhCounters>
<PdhCounter>\Memory\Pages/sec</PdhCounter>
<PdhCounter>\PhysicalDisk(_Total)\Avg. Disk Queue Length</PdhCounter>
<PdhCounter>\Processor(_Total)\% Processor Time</PdhCounter>
</PdhCounters>
</PdhSettings>
</Options>
<ExcludeSmallFuncs>true</ExcludeSmallFuncs>
<InteractionProfilingEnabled>false</InteractionProfilingEnabled>
<JScriptProfilingEnabled>false</JScriptProfilingEnabled>
<PreinstrumentEvent>
<InstrEventExclude>false</InstrEventExclude>
</PreinstrumentEvent>
<PostinstrumentEvent>
<InstrEventExclude>false</InstrEventExclude>
</PostinstrumentEvent>
<Binaries>
<ProjBinary>
<Path>bin\Debug\Returngeance.exe</Path>
<ArgumentTimestamp>01/01/0001 00:00:00</ArgumentTimestamp>
<Instrument>true</Instrument>
<Sample>true</Sample>
<ExternalWebsite>false</ExternalWebsite>
<InteractionProfilingEnabled>false</InteractionProfilingEnabled>
<IsLocalJavascript>false</IsLocalJavascript>
<IsWindowsStoreApp>false</IsWindowsStoreApp>
<IsWWA>false</IsWWA>
<LaunchProject>true</LaunchProject>
<OverrideProjectSettings>false</OverrideProjectSettings>
<LaunchMethod>Executable</LaunchMethod>
<ExecutablePath>bin\Debug\Returngeance.exe</ExecutablePath>
<StartupDirectory>..\bin\Debug</StartupDirectory>
<Arguments>
</Arguments>
<NetAppHost>IIS</NetAppHost>
<NetBrowser>InternetExplorer</NetBrowser>
<ExcludeSmallFuncs>true</ExcludeSmallFuncs>
<JScriptProfilingEnabled>false</JScriptProfilingEnabled>
<PreinstrumentEvent>
<InstrEventExclude>false</InstrEventExclude>
</PreinstrumentEvent>
<PostinstrumentEvent>
<InstrEventExclude>false</InstrEventExclude>
</PostinstrumentEvent>
<ProjRef>{E8B4A2A2-882B-402A-98A7-8B4F7233C8B3}|Returngeance\Returngeance.vcxproj</ProjRef>
<ProjPath>Returngeance\Returngeance.vcxproj</ProjPath>
<ProjName>Returngeance</ProjName>
</ProjBinary>
</Binaries>
<Reports>
<Report>
<Path>Returngeance140519.vsp</Path>
</Report>
<Report>
<Path>Returngeance140519(1).vsp</Path>
</Report>
<Report>
<Path>Returngeance140519(2).vsp</Path>
</Report>
<Report>
<Path>Returngeance140519(3).vsp</Path>
</Report>
</Reports>
<Launches>
<ProjBinary>
<Path>:PB:{E8B4A2A2-882B-402A-98A7-8B4F7233C8B3}|Returngeance\Returngeance.vcxproj</Path>
</ProjBinary>
</Launches>
</VSPerformanceSession>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.