Merge branch 'master' of https://github.com/teamfisk/AgileBreakOut
This commit is contained in:
Regular → Executable
+47
-6
@@ -52,6 +52,8 @@
|
|||||||
#include "Physics/CRectangleShape.h"
|
#include "Physics/CRectangleShape.h"
|
||||||
#include "Physics/ESetImpulse.h"
|
#include "Physics/ESetImpulse.h"
|
||||||
#include "Physics/CWaterVolume.h"
|
#include "Physics/CWaterVolume.h"
|
||||||
|
#include "Physics/CParticle.h"
|
||||||
|
#include "Physics/CParticleEmitter.h"
|
||||||
|
|
||||||
#include "Game/EGameStart.h"
|
#include "Game/EGameStart.h"
|
||||||
#include "Sound/EPlaySound.h"
|
#include "Sound/EPlaySound.h"
|
||||||
@@ -128,6 +130,8 @@ public:
|
|||||||
m_World->ComponentFactory.Register<Components::Template>();
|
m_World->ComponentFactory.Register<Components::Template>();
|
||||||
m_World->ComponentFactory.Register<Components::PointLight>();
|
m_World->ComponentFactory.Register<Components::PointLight>();
|
||||||
m_World->ComponentFactory.Register<Components::WaterVolume>();
|
m_World->ComponentFactory.Register<Components::WaterVolume>();
|
||||||
|
m_World->ComponentFactory.Register<Components::Particle>();
|
||||||
|
m_World->ComponentFactory.Register<Components::ParticleEmitter>();
|
||||||
m_World->Initialize();
|
m_World->Initialize();
|
||||||
|
|
||||||
|
|
||||||
@@ -164,7 +168,7 @@ public:
|
|||||||
pl->Radius = 20.f;
|
pl->Radius = 20.f;
|
||||||
pl->Diffuse = glm::vec3(0.8f, 0.7f, 0.05f);
|
pl->Diffuse = glm::vec3(0.8f, 0.7f, 0.05f);
|
||||||
auto model = m_World->AddComponent<Components::Model>(t_Light);
|
auto model = m_World->AddComponent<Components::Model>(t_Light);
|
||||||
model->ModelFile = "Core/UnitSphere.obj";
|
model->ModelFile = "Models/Core/UnitSphere.obj";
|
||||||
m_World->CommitEntity(t_Light);
|
m_World->CommitEntity(t_Light);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
@@ -175,7 +179,7 @@ public:
|
|||||||
pl->Radius = 15.f;
|
pl->Radius = 15.f;
|
||||||
pl->Diffuse = glm::vec3(0.1f, 0.5f, 0.8f);
|
pl->Diffuse = glm::vec3(0.1f, 0.5f, 0.8f);
|
||||||
auto model = m_World->AddComponent<Components::Model>(t_Light);
|
auto model = m_World->AddComponent<Components::Model>(t_Light);
|
||||||
model->ModelFile = "Core/UnitSphere.obj";
|
model->ModelFile = "Models/Core/UnitSphere.obj";
|
||||||
m_World->CommitEntity(t_Light);
|
m_World->CommitEntity(t_Light);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,7 +191,7 @@ public:
|
|||||||
transform->Scale = glm::vec3(6.f, 6.f, 10.f);
|
transform->Scale = glm::vec3(6.f, 6.f, 10.f);
|
||||||
auto model = m_World->AddComponent<Components::Model>(t_halfPipe);
|
auto model = m_World->AddComponent<Components::Model>(t_halfPipe);
|
||||||
model->ModelFile = "Models/Test/halfpipe/Halfpipe.obj";
|
model->ModelFile = "Models/Test/halfpipe/Halfpipe.obj";
|
||||||
model->Color = glm::vec4(1.f, 1.f, 1.f, 0.3f);
|
model->Color = glm::vec4(1.f, 0.f, 0.f, 0.3f);
|
||||||
m_World->CommitEntity(t_halfPipe);
|
m_World->CommitEntity(t_halfPipe);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,6 +206,44 @@ public:
|
|||||||
m_World->CommitEntity(background);
|
m_World->CommitEntity(background);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//ParticleTest
|
||||||
|
// {
|
||||||
|
// auto Pe = m_World->CreateEntity();
|
||||||
|
// auto transform = m_World->AddComponent<Components::Transform>(Pe);
|
||||||
|
// auto particleEmitter= m_World->AddComponent<Components::ParticleEmitter>(Pe);
|
||||||
|
//
|
||||||
|
// transform->Position = glm::vec3(0.f, -5.f, -10.f);
|
||||||
|
// particleEmitter->GravityScale = 0.0f;
|
||||||
|
// particleEmitter->SpawnRate = 1.0f;
|
||||||
|
//
|
||||||
|
// {
|
||||||
|
// auto Pt = m_World->CreateEntity(Pe);
|
||||||
|
// auto PtTransform = m_World->AddComponent<Components::Transform>(Pt);
|
||||||
|
// auto PtSprite = m_World->AddComponent<Components::Sprite>(Pt);
|
||||||
|
// //auto PtModel = m_World->AddComponent<Components::Model>(Pt);
|
||||||
|
// auto PtParticle = m_World->AddComponent<Components::Particle>(Pt);
|
||||||
|
// auto PtTemplate = m_World->AddComponent<Components::Template>(Pt);
|
||||||
|
//
|
||||||
|
// PtTransform->Velocity = glm::vec3(1.0f, 0.f, 0.f);
|
||||||
|
// PtTransform->Position = transform->Position;
|
||||||
|
// PtSprite->SpriteFile = "Textures/Ball.png";
|
||||||
|
//
|
||||||
|
// //PtModel->ModelFile = "Models/Brick/Brick.obj";
|
||||||
|
// PtParticle->LifeTime = 1000.f;
|
||||||
|
// PtParticle->Flags = ParticleFlags::Type::powderParticle;
|
||||||
|
// }
|
||||||
|
// m_World->CommitEntity(Pe);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// {
|
||||||
|
// auto Pt = m_World->CreateEntity();
|
||||||
|
// auto PtTransform = m_World->AddComponent<Components::Transform>(Pt);
|
||||||
|
// auto PtSprite = m_World->AddComponent<Components::Sprite>(Pt);
|
||||||
|
//
|
||||||
|
// PtTransform->Position = glm::vec3(2.f, 0.f, -10.f);
|
||||||
|
// PtSprite->SpriteFile = "Textures/Ball.png";
|
||||||
|
// }
|
||||||
|
|
||||||
//Water test
|
//Water test
|
||||||
{
|
{
|
||||||
auto t_waterBody = m_World->CreateEntity();
|
auto t_waterBody = m_World->CreateEntity();
|
||||||
@@ -212,6 +254,7 @@ public:
|
|||||||
auto body = m_World->AddComponent<Components::RectangleShape>(t_waterBody);
|
auto body = m_World->AddComponent<Components::RectangleShape>(t_waterBody);
|
||||||
m_World->CommitEntity(t_waterBody);
|
m_World->CommitEntity(t_waterBody);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Why does the ball not collide with these bricks?
|
//TODO: Why does the ball not collide with these bricks?
|
||||||
//BottomBox
|
//BottomBox
|
||||||
{
|
{
|
||||||
@@ -340,7 +383,7 @@ public:
|
|||||||
// Swap event queues to get fresh input data in the read queue
|
// Swap event queues to get fresh input data in the read queue
|
||||||
//m_EventBroker->Swap();
|
//m_EventBroker->Swap();
|
||||||
|
|
||||||
ResourceManager::Update();
|
//ResourceManager::Update();
|
||||||
if (m_GameIsRunning) {
|
if (m_GameIsRunning) {
|
||||||
m_World->Update(dt);
|
m_World->Update(dt);
|
||||||
}
|
}
|
||||||
@@ -429,7 +472,6 @@ public:
|
|||||||
auto spriteComponent = m_World->GetComponent<Components::Sprite>(entity);
|
auto spriteComponent = m_World->GetComponent<Components::Sprite>(entity);
|
||||||
if (spriteComponent)
|
if (spriteComponent)
|
||||||
{
|
{
|
||||||
|
|
||||||
std::string normal = spriteComponent->NormalTexture;
|
std::string normal = spriteComponent->NormalTexture;
|
||||||
std::string spec = spriteComponent->SpecularTexture;
|
std::string spec = spriteComponent->SpecularTexture;
|
||||||
|
|
||||||
@@ -452,7 +494,6 @@ public:
|
|||||||
EnqueueSprite(texturediff, texturenorm, texturespec, modelMatrix, spriteComponent->Color, absoluteTransform.Position.z);
|
EnqueueSprite(texturediff, texturenorm, texturespec, modelMatrix, spriteComponent->Color, absoluteTransform.Position.z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Get this out of engine.h
|
//TODO: Get this out of engine.h
|
||||||
|
|||||||
+26
-38
@@ -16,8 +16,8 @@
|
|||||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef Renderer_h__
|
#ifndef DD_RENDERER_H__
|
||||||
#define Renderer_h__
|
#define DD_RENDERER_H__
|
||||||
|
|
||||||
#include "Util/Rectangle.h"
|
#include "Util/Rectangle.h"
|
||||||
#include "Camera.h"
|
#include "Camera.h"
|
||||||
@@ -30,8 +30,6 @@ namespace dd
|
|||||||
class Renderer
|
class Renderer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//Render();
|
|
||||||
|
|
||||||
GLFWwindow* Window() const { return m_Window; }
|
GLFWwindow* Window() const { return m_Window; }
|
||||||
Rectangle Resolution() const { return m_Resolution; }
|
Rectangle Resolution() const { return m_Resolution; }
|
||||||
void SetResolution(const Rectangle& resolution) { m_Resolution = resolution; }
|
void SetResolution(const Rectangle& resolution) { m_Resolution = resolution; }
|
||||||
@@ -39,8 +37,6 @@ public:
|
|||||||
void SetFullscreen(bool fullscreen) { m_Fullscreen = fullscreen; }
|
void SetFullscreen(bool fullscreen) { m_Fullscreen = fullscreen; }
|
||||||
bool VSYNC() const { return m_VSYNC; }
|
bool VSYNC() const { return m_VSYNC; }
|
||||||
void SetVSYNC(bool vsync) { m_VSYNC = vsync; }
|
void SetVSYNC(bool vsync) { m_VSYNC = vsync; }
|
||||||
//void SetViewport(const Rectangle& viewport) { m_Viewport = viewport; }
|
|
||||||
//void SetScissor(const Rectangle& scissor) { m_Scissor = scissor; }
|
|
||||||
const dd::Camera* Camera() const { return m_Camera; }
|
const dd::Camera* Camera() const { return m_Camera; }
|
||||||
void SetCamera(const dd::Camera* camera)
|
void SetCamera(const dd::Camera* camera)
|
||||||
{
|
{
|
||||||
@@ -50,7 +46,6 @@ public:
|
|||||||
m_Camera = camera;
|
m_Camera = camera;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Initialize();
|
void Initialize();
|
||||||
void Draw(RenderQueueCollection& rq);
|
void Draw(RenderQueueCollection& rq);
|
||||||
|
|
||||||
@@ -58,8 +53,6 @@ private:
|
|||||||
Rectangle m_Resolution = Rectangle(1280, 720);
|
Rectangle m_Resolution = Rectangle(1280, 720);
|
||||||
bool m_Fullscreen = false;
|
bool m_Fullscreen = false;
|
||||||
bool m_VSYNC = false;
|
bool m_VSYNC = false;
|
||||||
//Rectangle m_Viewport;
|
|
||||||
//Rectangle m_Scissor;
|
|
||||||
std::unique_ptr<dd::Camera> m_DefaultCamera = nullptr;
|
std::unique_ptr<dd::Camera> m_DefaultCamera = nullptr;
|
||||||
const dd::Camera* m_Camera = nullptr;
|
const dd::Camera* m_Camera = nullptr;
|
||||||
|
|
||||||
@@ -67,42 +60,37 @@ private:
|
|||||||
std::string m_GLVendor;
|
std::string m_GLVendor;
|
||||||
GLFWwindow* m_Window = nullptr;
|
GLFWwindow* m_Window = nullptr;
|
||||||
|
|
||||||
ShaderProgram* m_spDeferred1;
|
ShaderProgram* m_SpDeferred1;
|
||||||
ShaderProgram* m_spDeferred2;
|
ShaderProgram* m_SpDeferred2;
|
||||||
ShaderProgram* m_spDeferred3;
|
ShaderProgram* m_SpDeferred3;
|
||||||
ShaderProgram* m_spForward;
|
ShaderProgram* m_SpForward;
|
||||||
ShaderProgram* m_spScreen;
|
ShaderProgram* m_SpScreen;
|
||||||
ShaderProgram* t_m_spWater;
|
ShaderProgram* m_SpWater;
|
||||||
ShaderProgram* t_m_spWater2;
|
ShaderProgram* m_SpWater2;
|
||||||
|
|
||||||
GLuint m_ScreenQuad = 0;
|
GLuint m_ScreenQuad = 0;
|
||||||
Model* m_UnitSphere = nullptr;
|
Model* m_UnitSphere = nullptr;
|
||||||
Model* m_UnitQuad = nullptr;
|
Model* m_UnitQuad = nullptr;
|
||||||
Texture* m_StandardNormal;
|
Texture* m_StandardNormal;
|
||||||
Texture* m_StandardSpecular;
|
Texture* m_StandardSpecular;
|
||||||
Texture* t_m_WhiteSphereTexture;
|
Texture* m_WhiteSphereTexture;
|
||||||
|
|
||||||
GLuint m_rbDepthBuffer = 0;
|
|
||||||
GLuint m_fbDeferred1 = 0;
|
|
||||||
GLuint m_GDiffuse = 0;
|
|
||||||
GLuint m_GPosition = 0;
|
|
||||||
GLuint m_GNormal = 0;
|
|
||||||
GLuint m_GSpecular = 0;
|
|
||||||
GLuint m_fbDeferred2 = 0;
|
|
||||||
GLuint m_tLighting = 0;
|
|
||||||
GLuint m_fbDeferred3 = 0;
|
|
||||||
GLuint m_tFinal = 0;
|
|
||||||
//Water GTexture
|
|
||||||
GLuint t_m_Gwater = 0;
|
|
||||||
//Water blur texture
|
|
||||||
GLuint t_m_BWater;
|
|
||||||
GLuint t_m_BWater2;
|
|
||||||
//WAterpass Framebuffer
|
|
||||||
GLuint t_m_fbWater;
|
|
||||||
//Waterpass Framebuffer
|
|
||||||
GLuint t_m_fbWaterBlur;
|
|
||||||
GLuint t_m_fbWaterBlur2;
|
|
||||||
|
|
||||||
|
GLuint m_RbDepthBuffer = 0; //DepthBuffer Texture
|
||||||
|
GLuint m_FbDeferred1 = 0; //Framebuffer for first pass
|
||||||
|
GLuint m_GDiffuse = 0; //Texture for diffuseColors
|
||||||
|
GLuint m_GPosition = 0; //Texture for positions
|
||||||
|
GLuint m_GNormal = 0; //Texture for normals
|
||||||
|
GLuint m_GSpecular = 0; //Texture for specular
|
||||||
|
GLuint m_FbDeferred2 = 0; //Framebuffer that handles the lighting pass
|
||||||
|
GLuint m_TLighting = 0; //Texture for the lighting pass
|
||||||
|
GLuint m_FbDeferred3 = 0; //Frambuffer for handling the last pass.
|
||||||
|
GLuint m_TFinal = 0; //Final Texture to be printed to screen
|
||||||
|
GLuint m_Gwater = 0; //Water Color Texture
|
||||||
|
GLuint m_BWater; //Water blur texture
|
||||||
|
GLuint m_BWater2; //Water blur texture
|
||||||
|
GLuint m_FbWater; //Waterpass Framebuffer
|
||||||
|
GLuint m_FbWaterBlur; //Waterpass Framebuffer
|
||||||
|
GLuint m_FbWaterBlur2; //Waterpass Framebuffer
|
||||||
|
|
||||||
GLuint m_CurrentScreenBuffer = 0;
|
GLuint m_CurrentScreenBuffer = 0;
|
||||||
void LoadShaders();
|
void LoadShaders();
|
||||||
|
|||||||
Executable
+65
@@ -0,0 +1,65 @@
|
|||||||
|
#ifndef COMPONENTS_PARTICLE_H__
|
||||||
|
#define COMPONENTS_PARTICLE_H__
|
||||||
|
#include "Core/Component.h"
|
||||||
|
|
||||||
|
namespace dd {
|
||||||
|
|
||||||
|
namespace ParticleFlags {
|
||||||
|
|
||||||
|
enum Type {
|
||||||
|
waterParticle = 0,
|
||||||
|
zombieParticle = 1 << 1,
|
||||||
|
wallParticle = 1 << 2,
|
||||||
|
springParticle = 1 << 3,
|
||||||
|
elasticParticle = 1 << 4,
|
||||||
|
viscousParticle = 1 << 5,
|
||||||
|
powderParticle = 1 << 6,
|
||||||
|
tensileParticle = 1 << 7,
|
||||||
|
colorMixingParticle = 1 << 8,
|
||||||
|
destructionListenerParticle = 1 << 9,
|
||||||
|
barrierParticle = 1 << 10,
|
||||||
|
staticPressureParticle = 1 << 11,
|
||||||
|
reactiveParticle = 1 << 12,
|
||||||
|
repulsiveParticle = 1 << 13,
|
||||||
|
fixtureContactListenerParticle = 1 << 14,
|
||||||
|
particleContactListenerParticle = 1 << 15,
|
||||||
|
fixtureContactFilterParticle = 1 << 16,
|
||||||
|
particleContactFilterParticle = 1 << 17
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Components
|
||||||
|
{
|
||||||
|
|
||||||
|
struct Particle : public Component
|
||||||
|
{
|
||||||
|
float Radius = 0.5f;
|
||||||
|
float LifeTime = 5.0f;
|
||||||
|
|
||||||
|
ParticleFlags::Type Flags =
|
||||||
|
ParticleFlags::Type::waterParticle |
|
||||||
|
ParticleFlags::Type::zombieParticle |
|
||||||
|
ParticleFlags::Type::wallParticle |
|
||||||
|
ParticleFlags::Type::springParticle |
|
||||||
|
ParticleFlags::Type::elasticParticle |
|
||||||
|
ParticleFlags::Type::viscousParticle |
|
||||||
|
ParticleFlags::Type::powderParticle |
|
||||||
|
ParticleFlags::Type::tensileParticle |
|
||||||
|
ParticleFlags::Type::colorMixingParticle |
|
||||||
|
ParticleFlags::Type::destructionListenerParticle |
|
||||||
|
ParticleFlags::Type::barrierParticle |
|
||||||
|
ParticleFlags::Type::staticPressureParticle |
|
||||||
|
ParticleFlags::Type::reactiveParticle |
|
||||||
|
ParticleFlags::Type::repulsiveParticle |
|
||||||
|
ParticleFlags::Type::fixtureContactListenerParticle |
|
||||||
|
ParticleFlags::Type::particleContactListenerParticle |
|
||||||
|
ParticleFlags::Type::fixtureContactFilterParticle |
|
||||||
|
ParticleFlags::Type::particleContactFilterParticle;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
Executable
+25
@@ -0,0 +1,25 @@
|
|||||||
|
#ifndef COMPONENTS_PARTICLEEMITTER_H__
|
||||||
|
#define COMPONENTS_PARTICLEEMITTER_H__
|
||||||
|
#include "Core/Component.h"
|
||||||
|
|
||||||
|
namespace dd
|
||||||
|
{
|
||||||
|
namespace Components
|
||||||
|
{
|
||||||
|
|
||||||
|
struct ParticleEmitter : public Component
|
||||||
|
{
|
||||||
|
int Amount = 10.f;
|
||||||
|
float InitialSpeed = 1.f;
|
||||||
|
double SpawnRate = 1.f;
|
||||||
|
double TimeSinceLastSpawn = 0;
|
||||||
|
|
||||||
|
//ParticleSystem variables
|
||||||
|
float GravityScale = 1.0f;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -9,7 +9,7 @@ namespace Components
|
|||||||
|
|
||||||
struct WaterVolume : public Component
|
struct WaterVolume : public Component
|
||||||
{
|
{
|
||||||
|
float Radius;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Regular → Executable
+20
-5
@@ -18,6 +18,9 @@
|
|||||||
#include "Physics/CWaterVolume.h"
|
#include "Physics/CWaterVolume.h"
|
||||||
#include "Game/CBall.h"
|
#include "Game/CBall.h"
|
||||||
#include "Rendering/CSprite.h"
|
#include "Rendering/CSprite.h"
|
||||||
|
#include "Physics/CParticle.h"
|
||||||
|
#include "Physics/CParticleEmitter.h"
|
||||||
|
#include "Core/CTemplate.h"
|
||||||
|
|
||||||
|
|
||||||
namespace dd
|
namespace dd
|
||||||
@@ -67,16 +70,28 @@ private:
|
|||||||
|
|
||||||
void CreateBody(EntityID entity);
|
void CreateBody(EntityID entity);
|
||||||
|
|
||||||
b2ParticleSystem *m_ParticleSystem;
|
std::vector<b2ParticleSystem*> m_ParticleSystem;
|
||||||
b2ParticleGroup* t_watergroup;
|
std::vector<b2ParticleGroup*> t_ParticleGroup;
|
||||||
|
|
||||||
std::unordered_map<EntityID, const b2ParticleHandle*> m_EntitiesToParticleHandle;
|
std::vector<std::unordered_map<EntityID, const b2ParticleHandle*>> m_EntitiesToParticleHandle;
|
||||||
std::unordered_map<const b2ParticleHandle*, EntityID> m_ParticleHandleToEntities;
|
std::vector<std::unordered_map<const b2ParticleHandle*, EntityID>> m_ParticleHandleToEntities;
|
||||||
|
|
||||||
|
b2ParticleSystem* CreateParticleSystem(float radius, float gravityScale);
|
||||||
void InitializeWater();
|
void InitializeWater();
|
||||||
void SyncWater(); //TODO: Probably remove this
|
|
||||||
void CreateParticleGroup(EntityID entity);
|
void CreateParticleGroup(EntityID entity);
|
||||||
|
void CreateParticleEmitter(EntityID entity);
|
||||||
|
void UpdateParticleEmitters(double dt); //TODO: Remove them and particles if needed.
|
||||||
|
|
||||||
|
//TODO: Fill struct with info needed.
|
||||||
|
struct ParticleEmitter
|
||||||
|
{
|
||||||
|
std::vector<b2ParticleSystem*> ParticleSystem;
|
||||||
|
std::vector<EntityID> ParticleEmitter;
|
||||||
|
std::vector<EntityID> ParticleTemplate;
|
||||||
|
};
|
||||||
|
ParticleEmitter m_ParticleEmitters;
|
||||||
|
|
||||||
|
//TODO: Struct med listor är bättre än en lista med structs
|
||||||
struct Impulse
|
struct Impulse
|
||||||
{
|
{
|
||||||
b2Body* Body;
|
b2Body* Body;
|
||||||
|
|||||||
+98
-129
@@ -70,7 +70,7 @@ void dd::Renderer::Initialize()
|
|||||||
LoadShaders();
|
LoadShaders();
|
||||||
CreateBuffers();
|
CreateBuffers();
|
||||||
|
|
||||||
m_CurrentScreenBuffer = m_tFinal;
|
m_CurrentScreenBuffer = m_TFinal;
|
||||||
}
|
}
|
||||||
void dd::Renderer::LoadShaders()
|
void dd::Renderer::LoadShaders()
|
||||||
{
|
{
|
||||||
@@ -79,39 +79,39 @@ void dd::Renderer::LoadShaders()
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Pass #1: Fill G-buffers
|
// Pass #1: Fill G-buffers
|
||||||
m_spDeferred1 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/1/");
|
m_SpDeferred1 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/1/");
|
||||||
m_spDeferred1->BindFragDataLocation(0, "GDiffuse");
|
m_SpDeferred1->BindFragDataLocation(0, "GDiffuse");
|
||||||
m_spDeferred1->BindFragDataLocation(1, "GPosition");
|
m_SpDeferred1->BindFragDataLocation(1, "GPosition");
|
||||||
m_spDeferred1->BindFragDataLocation(2, "GNormal");
|
m_SpDeferred1->BindFragDataLocation(2, "GNormal");
|
||||||
m_spDeferred1->BindFragDataLocation(3, "GSpecular");
|
m_SpDeferred1->BindFragDataLocation(3, "GSpecular");
|
||||||
m_spDeferred1->Link();
|
m_SpDeferred1->Link();
|
||||||
|
|
||||||
// Pass #2: Lighting
|
// Pass #2: Lighting
|
||||||
m_spDeferred2 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/2/");
|
m_SpDeferred2 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/2/");
|
||||||
//glBindFragDataLocation(m_SPDeferred2, 0, "FragmentLighting");
|
//glBindFragDataLocation(m_SPDeferred2, 0, "FragmentLighting");
|
||||||
m_spDeferred2->Link();
|
m_SpDeferred2->Link();
|
||||||
|
|
||||||
//Water Pass
|
//Water Pass
|
||||||
t_m_spWater = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/water/");
|
m_SpWater = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/water/");
|
||||||
t_m_spWater->Link();
|
m_SpWater->Link();
|
||||||
t_m_spWater2 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/water2/");
|
m_SpWater2 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/water2/");
|
||||||
t_m_spWater2->Link();
|
m_SpWater2->Link();
|
||||||
|
|
||||||
// Pass #3: Combining into final image
|
// Pass #3: Combining into final image
|
||||||
m_spDeferred3 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/3/");
|
m_SpDeferred3 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/3/");
|
||||||
m_spDeferred3->Link();
|
m_SpDeferred3->Link();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Forward rendering
|
Forward rendering
|
||||||
*/
|
*/
|
||||||
m_spForward = ResourceManager::Load<ShaderProgram>("Shaders/Forward/");
|
m_SpForward = ResourceManager::Load<ShaderProgram>("Shaders/Forward/");
|
||||||
m_spForward->Link();
|
m_SpForward->Link();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Screen draw
|
Screen draw
|
||||||
*/
|
*/
|
||||||
m_spScreen = ResourceManager::Load<ShaderProgram>("Shaders/Screen/");
|
m_SpScreen = ResourceManager::Load<ShaderProgram>("Shaders/Screen/");
|
||||||
m_spScreen->Link();
|
m_SpScreen->Link();
|
||||||
}
|
}
|
||||||
|
|
||||||
void dd::Renderer::CreateBuffers()
|
void dd::Renderer::CreateBuffers()
|
||||||
@@ -122,10 +122,10 @@ void dd::Renderer::CreateBuffers()
|
|||||||
m_UnitSphere = ResourceManager::Load<Model>("Models/Core/UnitSphere.obj");
|
m_UnitSphere = ResourceManager::Load<Model>("Models/Core/UnitSphere.obj");
|
||||||
m_StandardNormal = ResourceManager::Load<Texture>("Textures/Core/NeutralNormalMap.png");
|
m_StandardNormal = ResourceManager::Load<Texture>("Textures/Core/NeutralNormalMap.png");
|
||||||
m_StandardSpecular = ResourceManager::Load<Texture>("Textures/Core/NeutralSpecularMap.png");
|
m_StandardSpecular = ResourceManager::Load<Texture>("Textures/Core/NeutralSpecularMap.png");
|
||||||
t_m_WhiteSphereTexture = ResourceManager::Load<Texture>("Textures/Test/Water.png");
|
m_WhiteSphereTexture = ResourceManager::Load<Texture>("Textures/Test/Water.png");
|
||||||
|
|
||||||
glGenRenderbuffers(1, &m_rbDepthBuffer);
|
glGenRenderbuffers(1, &m_RbDepthBuffer);
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER, m_rbDepthBuffer);
|
glBindRenderbuffer(GL_RENDERBUFFER, m_RbDepthBuffer);
|
||||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, m_Resolution.Width, m_Resolution.Height);
|
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, m_Resolution.Width, m_Resolution.Height);
|
||||||
|
|
||||||
// Generate G-buffer textures
|
// Generate G-buffer textures
|
||||||
@@ -157,8 +157,8 @@ void dd::Renderer::CreateBuffers()
|
|||||||
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);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
glGenTextures(1, &t_m_Gwater);
|
glGenTextures(1, &m_Gwater);
|
||||||
glBindTexture(GL_TEXTURE_2D, t_m_Gwater);
|
glBindTexture(GL_TEXTURE_2D, m_Gwater);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, m_Resolution.Width, m_Resolution.Height, 0, GL_RGBA, GL_FLOAT, NULL);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, m_Resolution.Width, m_Resolution.Height, 0, GL_RGBA, GL_FLOAT, 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);
|
||||||
@@ -166,9 +166,9 @@ void dd::Renderer::CreateBuffers()
|
|||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
|
|
||||||
// Create first pass framebuffer
|
// Create first pass framebuffer
|
||||||
glGenFramebuffers(1, &m_fbDeferred1);
|
glGenFramebuffers(1, &m_FbDeferred1);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, m_fbDeferred1);
|
glBindFramebuffer(GL_FRAMEBUFFER, m_FbDeferred1);
|
||||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_rbDepthBuffer);
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_RbDepthBuffer);
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_GDiffuse, 0);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_GDiffuse, 0);
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, m_GPosition, 0);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, m_GPosition, 0);
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, m_GNormal, 0);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, m_GNormal, 0);
|
||||||
@@ -176,13 +176,13 @@ void dd::Renderer::CreateBuffers()
|
|||||||
GLenum firstPassDrawBuffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 };
|
GLenum firstPassDrawBuffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 };
|
||||||
glDrawBuffers(4, firstPassDrawBuffers);
|
glDrawBuffers(4, firstPassDrawBuffers);
|
||||||
if (GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
if (GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||||
LOG_ERROR("m_fbDeferred1 incomplete: 0x%x\n", fbStatus);
|
LOG_ERROR("m_FbDeferred1 incomplete: 0x%x\n", fbStatus);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate lighting texture
|
// Generate lighting texture
|
||||||
glGenTextures(1, &m_tLighting);
|
glGenTextures(1, &m_TLighting);
|
||||||
glBindTexture(GL_TEXTURE_2D, m_tLighting);
|
glBindTexture(GL_TEXTURE_2D, m_TLighting);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Resolution.Width, m_Resolution.Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Resolution.Width, m_Resolution.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);
|
||||||
@@ -190,19 +190,19 @@ void dd::Renderer::CreateBuffers()
|
|||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
|
|
||||||
// Create second pass framebuffer
|
// Create second pass framebuffer
|
||||||
glGenFramebuffers(1, &m_fbDeferred2);
|
glGenFramebuffers(1, &m_FbDeferred2);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, m_fbDeferred2);
|
glBindFramebuffer(GL_FRAMEBUFFER, m_FbDeferred2);
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_tLighting, 0);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_TLighting, 0);
|
||||||
GLenum secondPassDrawBuffers[] = { GL_COLOR_ATTACHMENT0 };
|
GLenum secondPassDrawBuffers[] = { GL_COLOR_ATTACHMENT0 };
|
||||||
glDrawBuffers(1, secondPassDrawBuffers);
|
glDrawBuffers(1, secondPassDrawBuffers);
|
||||||
if (GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
if (GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||||
LOG_ERROR("m_fbDeferred2 incomplete: 0x%x\n", fbStatus);
|
LOG_ERROR("m_FbDeferred2 incomplete: 0x%x\n", fbStatus);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Fill Water Texture
|
//Fill Water Texture
|
||||||
glGenTextures(1, &t_m_Gwater);
|
glGenTextures(1, &m_Gwater);
|
||||||
glBindTexture(GL_TEXTURE_2D, t_m_Gwater);
|
glBindTexture(GL_TEXTURE_2D, m_Gwater);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Resolution.Width, m_Resolution.Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Resolution.Width, m_Resolution.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);
|
||||||
@@ -210,19 +210,19 @@ void dd::Renderer::CreateBuffers()
|
|||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
|
|
||||||
//Fill water pass
|
//Fill water pass
|
||||||
glGenFramebuffers(1, &t_m_fbWater);
|
glGenFramebuffers(1, &m_FbWater);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, t_m_fbWater);
|
glBindFramebuffer(GL_FRAMEBUFFER, m_FbWater);
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, t_m_Gwater, 0);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_Gwater, 0);
|
||||||
GLenum waterPassDrawBuffers[] = { GL_COLOR_ATTACHMENT0 };
|
GLenum waterPassDrawBuffers[] = { GL_COLOR_ATTACHMENT0 };
|
||||||
glDrawBuffers(1, waterPassDrawBuffers);
|
glDrawBuffers(1, waterPassDrawBuffers);
|
||||||
if (GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
if (GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||||
LOG_ERROR("m_fbDeferred2 incomplete: 0x%x\n", fbStatus);
|
LOG_ERROR("m_FbDeferred2 incomplete: 0x%x\n", fbStatus);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
//water Blur texture
|
//water Blur texture
|
||||||
glGenTextures(1, &t_m_BWater);
|
glGenTextures(1, &m_BWater);
|
||||||
glBindTexture(GL_TEXTURE_2D, t_m_BWater);
|
glBindTexture(GL_TEXTURE_2D, m_BWater);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Resolution.Width, m_Resolution.Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Resolution.Width, m_Resolution.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);
|
||||||
@@ -230,20 +230,20 @@ void dd::Renderer::CreateBuffers()
|
|||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
|
|
||||||
//Fill waterBlur pass
|
//Fill waterBlur pass
|
||||||
glGenFramebuffers(1, &t_m_fbWaterBlur);
|
glGenFramebuffers(1, &m_FbWaterBlur);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, t_m_fbWaterBlur);
|
glBindFramebuffer(GL_FRAMEBUFFER, m_FbWaterBlur);
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, t_m_BWater, 0);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_BWater, 0);
|
||||||
GLenum waterBlurDrawBuffers[] = { GL_COLOR_ATTACHMENT0 };
|
GLenum waterBlurDrawBuffers[] = { GL_COLOR_ATTACHMENT0 };
|
||||||
glDrawBuffers(1, waterBlurDrawBuffers);
|
glDrawBuffers(1, waterBlurDrawBuffers);
|
||||||
if (GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
if (GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||||
LOG_ERROR("m_fbDeferred2 incomplete: 0x%x\n", fbStatus);
|
LOG_ERROR("m_FbDeferred2 incomplete: 0x%x\n", fbStatus);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
//water Blur texture2
|
//water Blur texture2
|
||||||
glGenTextures(1, &t_m_BWater2);
|
glGenTextures(1, &m_BWater2);
|
||||||
glBindTexture(GL_TEXTURE_2D, t_m_BWater2);
|
glBindTexture(GL_TEXTURE_2D, m_BWater2);
|
||||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_rbDepthBuffer);
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_RbDepthBuffer);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Resolution.Width, m_Resolution.Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Resolution.Width, m_Resolution.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);
|
||||||
@@ -251,19 +251,19 @@ void dd::Renderer::CreateBuffers()
|
|||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
|
|
||||||
//Fill waterBlur pass2
|
//Fill waterBlur pass2
|
||||||
glGenFramebuffers(1, &t_m_fbWaterBlur2);
|
glGenFramebuffers(1, &m_FbWaterBlur2);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, t_m_fbWaterBlur2);
|
glBindFramebuffer(GL_FRAMEBUFFER, m_FbWaterBlur2);
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, t_m_BWater2, 0);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_BWater2, 0);
|
||||||
GLenum waterBlur2DrawBuffers[] = { GL_COLOR_ATTACHMENT0 };
|
GLenum waterBlur2DrawBuffers[] = { GL_COLOR_ATTACHMENT0 };
|
||||||
glDrawBuffers(1, waterBlur2DrawBuffers);
|
glDrawBuffers(1, waterBlur2DrawBuffers);
|
||||||
if (GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
if (GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||||
LOG_ERROR("m_fbDeferred2 incomplete: 0x%x\n", fbStatus);
|
LOG_ERROR("m_FbDeferred2 incomplete: 0x%x\n", fbStatus);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate final deferred texture
|
// Generate final deferred texture
|
||||||
glGenTextures(1, &m_tFinal);
|
glGenTextures(1, &m_TFinal);
|
||||||
glBindTexture(GL_TEXTURE_2D, m_tFinal);
|
glBindTexture(GL_TEXTURE_2D, m_TFinal);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Resolution.Width, m_Resolution.Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Resolution.Width, m_Resolution.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);
|
||||||
@@ -271,14 +271,14 @@ void dd::Renderer::CreateBuffers()
|
|||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
|
|
||||||
// Create third pass framebuffer
|
// Create third pass framebuffer
|
||||||
glGenFramebuffers(1, &m_fbDeferred3);
|
glGenFramebuffers(1, &m_FbDeferred3);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, m_fbDeferred3);
|
glBindFramebuffer(GL_FRAMEBUFFER, m_FbDeferred3);
|
||||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_rbDepthBuffer);
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_RbDepthBuffer);
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_tFinal, 0);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_TFinal, 0);
|
||||||
GLenum thirdPassDrawBuffers[] = { GL_COLOR_ATTACHMENT0 };
|
GLenum thirdPassDrawBuffers[] = { GL_COLOR_ATTACHMENT0 };
|
||||||
glDrawBuffers(1, thirdPassDrawBuffers);
|
glDrawBuffers(1, thirdPassDrawBuffers);
|
||||||
if (GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
if (GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||||
LOG_ERROR("m_fbDeferred3 incomplete: 0x%x\n", fbStatus);
|
LOG_ERROR("m_FbDeferred3 incomplete: 0x%x\n", fbStatus);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -298,7 +298,7 @@ void dd::Renderer::Draw(RenderQueueCollection& rq)
|
|||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
glClearColor(1, 0, 0, 1);
|
glClearColor(1, 0, 0, 1);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
m_spScreen->Bind();
|
m_SpScreen->Bind();
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, m_CurrentScreenBuffer);
|
glBindTexture(GL_TEXTURE_2D, m_CurrentScreenBuffer);
|
||||||
glBindVertexArray(m_ScreenQuad);
|
glBindVertexArray(m_ScreenQuad);
|
||||||
@@ -312,17 +312,17 @@ void dd::Renderer::Draw(RenderQueueCollection& rq)
|
|||||||
void dd::Renderer::DrawDeferred(RenderQueue &objects, RenderQueue &lights)
|
void dd::Renderer::DrawDeferred(RenderQueue &objects, RenderQueue &lights)
|
||||||
{
|
{
|
||||||
// Pass #1: Fill G-buffers
|
// Pass #1: Fill G-buffers
|
||||||
glDisable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
glCullFace(GL_BACK);
|
glCullFace(GL_BACK);
|
||||||
glDepthMask(GL_TRUE);
|
glDepthMask(GL_TRUE);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, m_fbDeferred1);
|
glBindFramebuffer(GL_FRAMEBUFFER, m_FbDeferred1);
|
||||||
glClearColor(1, 1, 1, 1);
|
glClearColor(1, 1, 1, 1);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
m_spDeferred1->Bind();
|
m_SpDeferred1->Bind();
|
||||||
DrawScene(objects, *m_spDeferred1);
|
DrawScene(objects, *m_SpDeferred1);
|
||||||
|
|
||||||
// Pass #2: Lighting
|
// Pass #2: Lighting
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
@@ -332,24 +332,24 @@ void dd::Renderer::DrawDeferred(RenderQueue &objects, RenderQueue &lights)
|
|||||||
glBlendEquation(GL_FUNC_ADD);
|
glBlendEquation(GL_FUNC_ADD);
|
||||||
glBlendFunc(GL_ONE, GL_ONE);
|
glBlendFunc(GL_ONE, GL_ONE);
|
||||||
glDepthMask(GL_FALSE);
|
glDepthMask(GL_FALSE);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, m_fbDeferred2);
|
glBindFramebuffer(GL_FRAMEBUFFER, m_FbDeferred2);
|
||||||
glClearColor(0, 0, 0, 0);
|
glClearColor(0, 0, 0, 0);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
m_spDeferred2->Bind();
|
m_SpDeferred2->Bind();
|
||||||
DrawLightSpheres(lights);
|
DrawLightSpheres(lights);
|
||||||
|
|
||||||
// Pass #3: Combine into final deferred image
|
// Pass #3: Combine into final deferred image
|
||||||
glCullFace(GL_BACK);
|
glCullFace(GL_BACK);
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, m_fbDeferred3);
|
glBindFramebuffer(GL_FRAMEBUFFER, m_FbDeferred3);
|
||||||
glClearColor(0, 0, 0, 0);
|
glClearColor(0, 0, 0, 0);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
m_spDeferred3->Bind();
|
m_SpDeferred3->Bind();
|
||||||
glUniform3fv(glGetUniformLocation(*m_spDeferred3, "La"), 1, glm::value_ptr(glm::vec3(0.5f)));
|
glUniform3fv(glGetUniformLocation(*m_SpDeferred3, "La"), 1, glm::value_ptr(glm::vec3(0.5f)));
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, m_GDiffuse);
|
glBindTexture(GL_TEXTURE_2D, m_GDiffuse);
|
||||||
glActiveTexture(GL_TEXTURE1);
|
glActiveTexture(GL_TEXTURE1);
|
||||||
glBindTexture(GL_TEXTURE_2D, m_tLighting);
|
glBindTexture(GL_TEXTURE_2D, m_TLighting);
|
||||||
glBindVertexArray(m_ScreenQuad);
|
glBindVertexArray(m_ScreenQuad);
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||||
}
|
}
|
||||||
@@ -365,12 +365,12 @@ void dd::Renderer::DrawForward(RenderQueue &objects, RenderQueue &lights)
|
|||||||
//glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
|
//glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
|
||||||
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
|
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, m_fbDeferred3);
|
glBindFramebuffer(GL_FRAMEBUFFER, m_FbDeferred3);
|
||||||
// glClearColor(1, 0.9, 0.8f, 1);
|
// glClearColor(1, 0.9, 0.8f, 1);
|
||||||
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
m_spForward->Bind();
|
m_SpForward->Bind();
|
||||||
DrawScene(objects, *m_spForward);
|
DrawScene(objects, *m_SpForward);
|
||||||
|
|
||||||
//WaterPass
|
//WaterPass
|
||||||
glDisable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
@@ -379,10 +379,10 @@ void dd::Renderer::DrawForward(RenderQueue &objects, RenderQueue &lights)
|
|||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, t_m_fbWater);
|
glBindFramebuffer(GL_FRAMEBUFFER, m_FbWater);
|
||||||
glClearColor(0, 0, 0, 0);
|
glClearColor(0, 0, 0, 0);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
t_m_spWater->Bind();
|
m_SpWater->Bind();
|
||||||
DrawWater(objects);
|
DrawWater(objects);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -444,6 +444,7 @@ void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
|
|||||||
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(viewMatrix));
|
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(viewMatrix));
|
||||||
glUniform4fv(glGetUniformLocation(shaderProgramHandle, "Color"), 1, glm::value_ptr(modelJob->Color));
|
glUniform4fv(glGetUniformLocation(shaderProgramHandle, "Color"), 1, glm::value_ptr(modelJob->Color));
|
||||||
|
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, spriteJob->DiffuseTexture);
|
glBindTexture(GL_TEXTURE_2D, spriteJob->DiffuseTexture);
|
||||||
glActiveTexture(GL_TEXTURE1);
|
glActiveTexture(GL_TEXTURE1);
|
||||||
@@ -462,7 +463,7 @@ void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
|
|||||||
|
|
||||||
void dd::Renderer::DrawLightSpheres(RenderQueue &lights)
|
void dd::Renderer::DrawLightSpheres(RenderQueue &lights)
|
||||||
{
|
{
|
||||||
GLuint shaderProgramHandle = *m_spDeferred2;
|
GLuint shaderProgramHandle = *m_SpDeferred2;
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, m_GPosition);
|
glBindTexture(GL_TEXTURE_2D, m_GPosition);
|
||||||
@@ -499,7 +500,7 @@ void dd::Renderer::DrawLightSpheres(RenderQueue &lights)
|
|||||||
|
|
||||||
void dd::Renderer::DrawWater(RenderQueue &rq)
|
void dd::Renderer::DrawWater(RenderQueue &rq)
|
||||||
{
|
{
|
||||||
GLuint shaderProgramHandle = *t_m_spWater;
|
GLuint shaderProgramHandle = *m_SpWater;
|
||||||
|
|
||||||
glm::mat4 projectionMatrix = m_Camera->ProjectionMatrix();
|
glm::mat4 projectionMatrix = m_Camera->ProjectionMatrix();
|
||||||
glm::mat4 viewMatrix = m_Camera->ViewMatrix();
|
glm::mat4 viewMatrix = m_Camera->ViewMatrix();
|
||||||
@@ -517,7 +518,7 @@ void dd::Renderer::DrawWater(RenderQueue &rq)
|
|||||||
glm::value_ptr(viewMatrix));
|
glm::value_ptr(viewMatrix));
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, *t_m_WhiteSphereTexture);
|
glBindTexture(GL_TEXTURE_2D, *m_WhiteSphereTexture);
|
||||||
|
|
||||||
glBindVertexArray(m_UnitQuad->VAO);
|
glBindVertexArray(m_UnitQuad->VAO);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_UnitQuad->ElementBuffer);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_UnitQuad->ElementBuffer);
|
||||||
@@ -528,16 +529,17 @@ void dd::Renderer::DrawWater(RenderQueue &rq)
|
|||||||
|
|
||||||
|
|
||||||
//blur1
|
//blur1
|
||||||
shaderProgramHandle = *t_m_spWater2;
|
shaderProgramHandle = *m_SpWater2;
|
||||||
glDisable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
glDepthMask(GL_FALSE);
|
glDepthMask(GL_FALSE);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, t_m_fbWaterBlur);
|
glBindFramebuffer(GL_FRAMEBUFFER, m_FbWaterBlur);
|
||||||
glClearColor(0, 0, 0, 0);
|
glClearColor(0, 0, 0, 0);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
t_m_spWater2->Bind();
|
m_SpWater2->Bind();
|
||||||
|
//TODO: Add this in water particle component. Blurradius
|
||||||
float radius = 3.f;
|
float radius = 3.f;
|
||||||
|
|
||||||
glUniform2fv(glGetUniformLocation(shaderProgramHandle, "dir"), 1, glm::value_ptr(glm::vec2(1.0f, 0.0f)));
|
glUniform2fv(glGetUniformLocation(shaderProgramHandle, "dir"), 1, glm::value_ptr(glm::vec2(1.0f, 0.0f)));
|
||||||
@@ -545,64 +547,31 @@ void dd::Renderer::DrawWater(RenderQueue &rq)
|
|||||||
glUniform1f(glGetUniformLocation(shaderProgramHandle, "radius"), radius);
|
glUniform1f(glGetUniformLocation(shaderProgramHandle, "radius"), radius);
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, t_m_Gwater);
|
glBindTexture(GL_TEXTURE_2D, m_Gwater);
|
||||||
glBindVertexArray(m_ScreenQuad);
|
glBindVertexArray(m_ScreenQuad);
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||||
|
|
||||||
|
|
||||||
//blur2
|
//blur2
|
||||||
shaderProgramHandle = *t_m_spWater2;
|
shaderProgramHandle = *m_SpWater2;
|
||||||
glDisable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
glDepthMask(GL_FALSE);
|
glDepthMask(GL_FALSE);
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, m_fbDeferred3);
|
glBindFramebuffer(GL_FRAMEBUFFER, m_FbDeferred3);
|
||||||
t_m_spWater2->Bind();
|
m_SpWater2->Bind();
|
||||||
|
|
||||||
glUniform2fv(glGetUniformLocation(shaderProgramHandle, "dir"), 1, glm::value_ptr(glm::vec2(0.0f, 1.0f)));
|
glUniform2fv(glGetUniformLocation(shaderProgramHandle, "dir"), 1, glm::value_ptr(glm::vec2(0.0f, 1.0f)));
|
||||||
glUniform1f(glGetUniformLocation(shaderProgramHandle, "res"), m_Resolution.Height);
|
glUniform1f(glGetUniformLocation(shaderProgramHandle, "res"), m_Resolution.Height);
|
||||||
glUniform1f(glGetUniformLocation(shaderProgramHandle, "radius"), radius);
|
glUniform1f(glGetUniformLocation(shaderProgramHandle, "radius"), radius);
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, t_m_BWater);
|
glBindTexture(GL_TEXTURE_2D, m_BWater);
|
||||||
glBindVertexArray(m_ScreenQuad);
|
glBindVertexArray(m_ScreenQuad);
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GLuint dd::Renderer::CreateWaterParticleVAO(RenderQueue &particles)
|
|
||||||
{
|
|
||||||
float waterVerts[particles.Size()];
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
for ( auto &job : particles ) {
|
|
||||||
auto waterJob = std::dynamic_pointer_cast<WaterParticleJob>(job);
|
|
||||||
if (!waterJob)
|
|
||||||
continue;
|
|
||||||
waterVerts[i ] = waterJob->Position.x;
|
|
||||||
waterVerts[i+1] = waterJob->Position.y;
|
|
||||||
waterVerts[i+2] = waterJob->Position.z;
|
|
||||||
i+3;
|
|
||||||
}
|
|
||||||
|
|
||||||
GLuint vbo[1], vao;
|
|
||||||
glGenBuffers(1, vbo);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vbo[0]);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, 3 * particles.Size() * sizeof(float), waterVerts, GL_STATIC_DRAW);
|
|
||||||
glGenVertexArrays(1, &vao);
|
|
||||||
glBindVertexArray(vao);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vbo[0]);
|
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
|
|
||||||
glEnableVertexAttribArray(0);
|
|
||||||
|
|
||||||
glBindVertexArray(0);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
||||||
|
|
||||||
return vao;
|
|
||||||
}
|
|
||||||
|
|
||||||
GLuint dd::Renderer::CreateQuad()
|
GLuint dd::Renderer::CreateQuad()
|
||||||
{
|
{
|
||||||
float quadVertices[] =
|
float quadVertices[] =
|
||||||
@@ -649,7 +618,7 @@ GLuint dd::Renderer::CreateQuad()
|
|||||||
void dd::Renderer::DebugKeys()
|
void dd::Renderer::DebugKeys()
|
||||||
{
|
{
|
||||||
if (glfwGetKey(m_Window, GLFW_KEY_F1)) {
|
if (glfwGetKey(m_Window, GLFW_KEY_F1)) {
|
||||||
m_CurrentScreenBuffer = m_tFinal;
|
m_CurrentScreenBuffer = m_TFinal;
|
||||||
}
|
}
|
||||||
if (glfwGetKey(m_Window, GLFW_KEY_F2)) {
|
if (glfwGetKey(m_Window, GLFW_KEY_F2)) {
|
||||||
m_CurrentScreenBuffer = m_GDiffuse;
|
m_CurrentScreenBuffer = m_GDiffuse;
|
||||||
@@ -664,19 +633,19 @@ void dd::Renderer::DebugKeys()
|
|||||||
m_CurrentScreenBuffer = m_GSpecular;
|
m_CurrentScreenBuffer = m_GSpecular;
|
||||||
}
|
}
|
||||||
if (glfwGetKey(m_Window, GLFW_KEY_F6)) {
|
if (glfwGetKey(m_Window, GLFW_KEY_F6)) {
|
||||||
m_CurrentScreenBuffer = m_tLighting;
|
m_CurrentScreenBuffer = m_TLighting;
|
||||||
}
|
}
|
||||||
if (glfwGetKey(m_Window, GLFW_KEY_F7)) {
|
if (glfwGetKey(m_Window, GLFW_KEY_F7)) {
|
||||||
m_CurrentScreenBuffer = t_m_Gwater;
|
m_CurrentScreenBuffer = m_Gwater;
|
||||||
}
|
}
|
||||||
if (glfwGetKey(m_Window, GLFW_KEY_F8)) {
|
if (glfwGetKey(m_Window, GLFW_KEY_F8)) {
|
||||||
m_CurrentScreenBuffer = t_m_BWater;
|
m_CurrentScreenBuffer = m_BWater;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void dd::Renderer::DrawGUI(dd::RenderQueue& rq)
|
void dd::Renderer::DrawGUI(dd::RenderQueue& rq)
|
||||||
{
|
{
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, m_fbDeferred3);
|
glBindFramebuffer(GL_FRAMEBUFFER, m_FbDeferred3);
|
||||||
glDisable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
glCullFace(GL_BACK);
|
glCullFace(GL_BACK);
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
@@ -684,7 +653,7 @@ void dd::Renderer::DrawGUI(dd::RenderQueue& rq)
|
|||||||
//glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
|
//glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
|
||||||
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
|
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
|
||||||
|
|
||||||
m_spScreen->Bind();
|
m_SpScreen->Bind();
|
||||||
|
|
||||||
glm::mat4 MVP;
|
glm::mat4 MVP;
|
||||||
|
|
||||||
@@ -696,9 +665,9 @@ void dd::Renderer::DrawGUI(dd::RenderQueue& rq)
|
|||||||
glm::mat4 PV = glm::mat4(1); //frameJob->ProjectionMatrix * viewMatrix;
|
glm::mat4 PV = glm::mat4(1); //frameJob->ProjectionMatrix * viewMatrix;
|
||||||
glm::mat4 modelMatrix = glm::mat4(1); //frameJob->ModelMatrix;
|
glm::mat4 modelMatrix = glm::mat4(1); //frameJob->ModelMatrix;
|
||||||
MVP = PV * modelMatrix;
|
MVP = PV * modelMatrix;
|
||||||
glUniformMatrix4fv(glGetUniformLocation(*m_spScreen, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
glUniformMatrix4fv(glGetUniformLocation(*m_SpScreen, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
||||||
glUniformMatrix4fv(glGetUniformLocation(*m_spScreen, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
|
glUniformMatrix4fv(glGetUniformLocation(*m_SpScreen, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
|
||||||
glUniformMatrix4fv(glGetUniformLocation(*m_spScreen, "V"), 1, GL_FALSE, glm::value_ptr(viewMatrix));
|
glUniformMatrix4fv(glGetUniformLocation(*m_SpScreen, "V"), 1, GL_FALSE, glm::value_ptr(viewMatrix));
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, frameJob->DiffuseTexture);
|
glBindTexture(GL_TEXTURE_2D, frameJob->DiffuseTexture);
|
||||||
|
|||||||
@@ -61,9 +61,9 @@ void main()
|
|||||||
sum += texture(WaterTexture, vec2(tc.x + 3.0*blur*hstep, tc.y + 3.0*blur*vstep)) * 0.0540540541;
|
sum += texture(WaterTexture, vec2(tc.x + 3.0*blur*hstep, tc.y + 3.0*blur*vstep)) * 0.0540540541;
|
||||||
sum += texture(WaterTexture, vec2(tc.x + 4.0*blur*hstep, tc.y + 4.0*blur*vstep)) * 0.0162162162;
|
sum += texture(WaterTexture, vec2(tc.x + 4.0*blur*hstep, tc.y + 4.0*blur*vstep)) * 0.0162162162;
|
||||||
|
|
||||||
frag_Diffuse = vec4(sum.rgb, 1.0) * vec4(0.0, 0.6, 1.5, 1.0);
|
float avgColor = sum.r + sum.g + sum.b;
|
||||||
float avgColor = frag_Diffuse.r + frag_Diffuse.g + frag_Diffuse.b;
|
|
||||||
avgColor = avgColor/3;
|
avgColor = avgColor/3;
|
||||||
|
frag_Diffuse = vec4(sum.r, sum.g, sum.b, 1.0);
|
||||||
if ( avgColor*dir.y > Threshhold ){
|
if ( avgColor*dir.y > Threshhold ){
|
||||||
frag_Diffuse = vec4(0.0, 0.3, 1.0, 1.0);
|
frag_Diffuse = vec4(0.0, 0.3, 1.0, 1.0);
|
||||||
}
|
}
|
||||||
|
|||||||
Regular → Executable
+158
-55
@@ -29,10 +29,9 @@ void dd::Systems::PhysicsSystem::Initialize()
|
|||||||
|
|
||||||
void dd::Systems::PhysicsSystem::InitializeWater()
|
void dd::Systems::PhysicsSystem::InitializeWater()
|
||||||
{
|
{
|
||||||
b2ParticleSystemDef m_ParticleSystemDef;
|
float radius = 0.13f;
|
||||||
m_ParticleSystemDef.radius = 0.13f;
|
float gravityScale = 1.0f;
|
||||||
|
CreateParticleSystem(radius, gravityScale);
|
||||||
m_ParticleSystem = m_PhysicsWorld->CreateParticleSystem(&m_ParticleSystemDef);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dd::Systems::PhysicsSystem::SetImpulse(const Events::SetImpulse &event)
|
bool dd::Systems::PhysicsSystem::SetImpulse(const Events::SetImpulse &event)
|
||||||
@@ -58,24 +57,22 @@ bool dd::Systems::PhysicsSystem::SetImpulse(const Events::SetImpulse &event)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dd::Systems::PhysicsSystem::Update(double dt)
|
void dd::Systems::PhysicsSystem::Update(double dt) {
|
||||||
{
|
|
||||||
|
|
||||||
m_Accumulator += dt;
|
m_Accumulator += dt;
|
||||||
while(m_Accumulator >= m_TimeStep)
|
while (m_Accumulator >= m_TimeStep) {
|
||||||
{
|
|
||||||
|
|
||||||
for (auto i : m_EntitiesToBodies) {
|
for (auto i : m_EntitiesToBodies) {
|
||||||
EntityID entity = i.first;
|
EntityID entity = i.first;
|
||||||
b2Body* body = i.second;
|
b2Body *body = i.second;
|
||||||
|
|
||||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
||||||
if (! transformComponent) {
|
if (!transformComponent) {
|
||||||
continue;
|
continue;
|
||||||
LOG_ERROR("RigidBody with no TransformComponent");
|
LOG_ERROR("RigidBody with no TransformComponent");
|
||||||
}
|
}
|
||||||
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity);
|
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity);
|
||||||
if (! physicsComponent) {
|
if (!physicsComponent) {
|
||||||
continue;
|
continue;
|
||||||
LOG_ERROR("RigidBody with no PhysicsComponent");
|
LOG_ERROR("RigidBody with no PhysicsComponent");
|
||||||
}
|
}
|
||||||
@@ -102,19 +99,19 @@ void dd::Systems::PhysicsSystem::Update(double dt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateParticleEmitters(dt);
|
||||||
|
|
||||||
for (auto i : m_Impulses) {
|
for (auto i : m_Impulses) {
|
||||||
i.Body->ApplyLinearImpulse(i.Impulse, i.Point, true);
|
i.Body->ApplyLinearImpulse(i.Impulse, i.Point, true);
|
||||||
}
|
}
|
||||||
m_Impulses.clear();
|
m_Impulses.clear();
|
||||||
|
|
||||||
|
|
||||||
m_PhysicsWorld->Step(m_TimeStep, m_VelocityIterations, m_PositionIterations);
|
m_PhysicsWorld->Step(m_TimeStep, m_VelocityIterations, m_PositionIterations);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (auto i : m_EntitiesToBodies) {
|
for (auto i : m_EntitiesToBodies) {
|
||||||
EntityID entity = i.first;
|
EntityID entity = i.first;
|
||||||
b2Body* body = i.second;
|
b2Body *body = i.second;
|
||||||
|
|
||||||
if (body == nullptr) {
|
if (body == nullptr) {
|
||||||
LOG_ERROR("This body should not exist");
|
LOG_ERROR("This body should not exist");
|
||||||
@@ -122,15 +119,17 @@ void dd::Systems::PhysicsSystem::Update(double dt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
||||||
if (! transformComponent)
|
if (!transformComponent)
|
||||||
continue;
|
continue;
|
||||||
auto parent = m_World->GetEntityParent(entity);
|
auto parent = m_World->GetEntityParent(entity);
|
||||||
if (parent == 0) {
|
if (parent == 0) {
|
||||||
|
|
||||||
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity);
|
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity);
|
||||||
if (physicsComponent->Calculate) { //TODO: REPLACE THIS WITH PARTICLE COLLISION FILTERS
|
if (physicsComponent->Calculate) { //TODO: REPLACE THIS WITH PARTICLE COLLISION FILTERS
|
||||||
transformComponent->Position.x = transformComponent->Position.x + (transformComponent->Velocity.x * m_TimeStep);
|
transformComponent->Position.x =
|
||||||
transformComponent->Position.y = transformComponent->Position.y + (transformComponent->Velocity.y * m_TimeStep);
|
transformComponent->Position.x + (transformComponent->Velocity.x * m_TimeStep);
|
||||||
|
transformComponent->Position.y =
|
||||||
|
transformComponent->Position.y + (transformComponent->Velocity.y * m_TimeStep);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
b2Vec2 position = body->GetPosition();
|
b2Vec2 position = body->GetPosition();
|
||||||
@@ -138,36 +137,42 @@ void dd::Systems::PhysicsSystem::Update(double dt)
|
|||||||
transformComponent->Position.y = position.y;
|
transformComponent->Position.y = position.y;
|
||||||
|
|
||||||
float angle = body->GetAngle();
|
float angle = body->GetAngle();
|
||||||
transformComponent->Orientation = glm::quat(glm::vec3(0, 0, angle));
|
transformComponent->Orientation = glm::quat(glm::vec3(0, 0, angle));
|
||||||
|
|
||||||
b2Vec2 velocity = body->GetLinearVelocity();
|
b2Vec2 velocity = body->GetLinearVelocity();
|
||||||
transformComponent->Velocity.x = velocity.x;
|
transformComponent->Velocity.x = velocity.x;
|
||||||
transformComponent->Velocity.y = velocity.y;
|
transformComponent->Velocity.y = velocity.y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
b2Vec2* positionBuffer = m_ParticleSystem->GetPositionBuffer();
|
for ( int e = 0; e < m_EntitiesToParticleHandle.size(); e++) {
|
||||||
for (auto i : m_EntitiesToParticleHandle) {
|
b2Vec2 *positionBuffer = m_ParticleSystem[e]->GetPositionBuffer();
|
||||||
EntityID entity = i.first;
|
for (auto i : m_EntitiesToParticleHandle[e]){
|
||||||
b2ParticleHandle* particleH = i.second;
|
EntityID entity = i.first;
|
||||||
|
b2ParticleHandle *particleH = i.second;
|
||||||
|
|
||||||
b2Vec2 positionB2 = positionBuffer[particleH->GetIndex()];
|
b2Vec2 positionB2 = positionBuffer[particleH->GetIndex()];
|
||||||
glm::vec2 position = glm::vec2(positionB2.x, positionB2.y);
|
glm::vec2 position = glm::vec2(positionB2.x, positionB2.y);
|
||||||
|
|
||||||
|
EntityID entityParent = m_World->GetEntityParent(entity);
|
||||||
|
glm::vec3 parentTransform = glm::vec3(0.f);
|
||||||
|
if(entityParent) {
|
||||||
|
auto tp = m_World->GetComponent<Components::Transform>(entityParent);
|
||||||
|
parentTransform = tp->Position;
|
||||||
|
}
|
||||||
|
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||||
|
|
||||||
EntityID entityParent = m_World->GetEntityParent(entity);
|
transform->Position = glm::vec3(position.x, position.y, -10) - parentTransform;
|
||||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
|
||||||
auto transformParent = m_World->GetComponent<Components::Transform>(entityParent);
|
|
||||||
|
|
||||||
transform->Position = glm::vec3(position.x, position.y, -10) - transformParent->Position;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Accumulator -= dt;
|
m_Accumulator -= dt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void dd::Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
void dd::Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -177,15 +182,23 @@ void dd::Systems::PhysicsSystem::OnEntityCommit(EntityID entity)
|
|||||||
{
|
{
|
||||||
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity);
|
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity);
|
||||||
auto waterComponent = m_World->GetComponent<Components::WaterVolume>(entity);
|
auto waterComponent = m_World->GetComponent<Components::WaterVolume>(entity);
|
||||||
|
auto particleEmitterComponent = m_World->GetComponent<Components::ParticleEmitter>(entity);
|
||||||
|
|
||||||
if (physicsComponent && waterComponent) {
|
if (physicsComponent && waterComponent) {
|
||||||
LOG_ERROR("Entity has both water and physics component, this is illegal. The police has been alerted.");
|
LOG_ERROR("Entity has both water and physics component, this is illegal. The police has been alerted.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (physicsComponent && particleEmitterComponent) {
|
||||||
|
LOG_ERROR("Entity has both particle and physics component, this is illegal. The police has been alerted.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (physicsComponent) {
|
if (physicsComponent) {
|
||||||
CreateBody(entity);
|
CreateBody(entity);
|
||||||
} else if (waterComponent) {
|
} else if (waterComponent) {
|
||||||
CreateParticleGroup(entity);
|
CreateParticleGroup(entity);
|
||||||
|
} else if (particleEmitterComponent) {
|
||||||
|
CreateParticleEmitter(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,7 +221,6 @@ void dd::Systems::PhysicsSystem::OnEntityRemoved(EntityID entity)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void dd::Systems::PhysicsSystem::CreateBody(EntityID entity)
|
void dd::Systems::PhysicsSystem::CreateBody(EntityID entity)
|
||||||
{
|
{
|
||||||
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity);
|
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity);
|
||||||
@@ -289,40 +301,131 @@ void dd::Systems::PhysicsSystem::CreateBody(EntityID entity)
|
|||||||
|
|
||||||
void dd::Systems::PhysicsSystem::CreateParticleGroup(EntityID e)
|
void dd::Systems::PhysicsSystem::CreateParticleGroup(EntityID e)
|
||||||
{
|
{
|
||||||
//TODO: L�gg alla pd i en lista
|
|
||||||
auto transform = m_World->GetComponent<Components::Transform>(e);
|
auto transform = m_World->GetComponent<Components::Transform>(e);
|
||||||
if (!transform) {
|
if (!transform) {
|
||||||
LOG_ERROR("No Transform component in CreateParticleGroup");
|
LOG_ERROR("No Transform component in CreateParticleGroup");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
b2ParticleGroupDef pd;
|
b2ParticleGroupDef pd;
|
||||||
b2PolygonShape shape;
|
b2PolygonShape shape;
|
||||||
|
auto water = m_World->GetComponent<Components::WaterVolume>(e);
|
||||||
|
if (water) {
|
||||||
|
|
||||||
shape.SetAsBox(transform->Scale.x/2.f, transform->Scale.y/2.f);
|
shape.SetAsBox(transform->Scale.x/2.f, transform->Scale.y/2.f);
|
||||||
pd.shape = &shape;
|
pd.shape = &shape;
|
||||||
pd.flags = b2_tensileParticle;
|
pd.flags = b2_tensileParticle;
|
||||||
pd.position.Set(transform->Position.x, transform->Position.y);
|
pd.position.Set(transform->Position.x, transform->Position.y);
|
||||||
//TODO: PUT IN LIST
|
t_ParticleGroup.push_back(m_ParticleSystem[0]->CreateParticleGroup(pd));
|
||||||
t_watergroup = m_ParticleSystem->CreateParticleGroup(pd);
|
b2Vec2* t_ParticlePositions = m_ParticleSystem[0]->GetPositionBuffer();
|
||||||
b2Vec2* t_ParticlePositions = m_ParticleSystem->GetPositionBuffer();
|
for(int i = 0; i < m_ParticleSystem[0]->GetParticleCount(); i++){
|
||||||
for(int i = 0; i < m_ParticleSystem->GetParticleCount(); i++){
|
{
|
||||||
{
|
auto t_waterparticle = m_World->CreateEntity(e);
|
||||||
auto t_waterparticle = m_World->CreateEntity(e);
|
auto transformChild = m_World->AddComponent<Components::Transform>(t_waterparticle);
|
||||||
auto transformChild = m_World->AddComponent<Components::Transform>(t_waterparticle);
|
|
||||||
//auto sprite = m_World->AddComponent<Components::Sprite>(t_waterparticle);
|
|
||||||
|
|
||||||
transformChild->Position = glm::vec3(t_ParticlePositions[i].x - transform->Position.x, t_ParticlePositions[i].y - transform->Position.y, -9.5f);
|
transformChild->Position = glm::vec3(t_ParticlePositions[i].x - transform->Position.x, t_ParticlePositions[i].y - transform->Position.y, -9.5f);
|
||||||
transformChild->Scale = glm::vec3(m_ParticleSystem->GetRadius())/transform->Scale;
|
transformChild->Scale = glm::vec3(m_ParticleSystem[0]->GetRadius())/transform->Scale;
|
||||||
//sprite->SpriteFile = "Textures/Ball.png";
|
m_World->CommitEntity(t_waterparticle);
|
||||||
m_World->CommitEntity(t_waterparticle);
|
|
||||||
|
m_EntitiesToParticleHandle[0].insert(std::make_pair(t_waterparticle, m_ParticleSystem[0]->GetParticleHandleFromIndex(i)));
|
||||||
|
m_ParticleHandleToEntities[0].insert(std::make_pair( m_ParticleSystem[0]->GetParticleHandleFromIndex(i), t_waterparticle));
|
||||||
|
}
|
||||||
|
|
||||||
m_EntitiesToParticleHandle.insert(std::make_pair(t_waterparticle, m_ParticleSystem->GetParticleHandleFromIndex(i)));
|
|
||||||
m_ParticleHandleToEntities.insert(std::make_pair( m_ParticleSystem->GetParticleHandleFromIndex(i), t_waterparticle));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
LOG_INFO("ParticleCount: %i", m_ParticleSystem->GetParticleCount());
|
}
|
||||||
|
|
||||||
|
void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < m_ParticleEmitters.ParticleSystem.size(); i++) {
|
||||||
|
auto e = m_ParticleEmitters.ParticleEmitter[i];
|
||||||
|
auto pt = m_ParticleEmitters.ParticleTemplate[i];
|
||||||
|
auto ps = m_ParticleEmitters.ParticleSystem[i];
|
||||||
|
|
||||||
|
|
||||||
|
auto emitter = m_World->GetComponent<Components::ParticleEmitter>(e);
|
||||||
|
auto particleTemplate = m_World->GetComponent<Components::Particle>(pt);
|
||||||
|
emitter->TimeSinceLastSpawn += dt;
|
||||||
|
if(emitter->TimeSinceLastSpawn < emitter->SpawnRate) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
emitter->TimeSinceLastSpawn -= emitter->SpawnRate;
|
||||||
|
auto templateTransform = m_World->GetComponent<Components::Transform>(pt);
|
||||||
|
|
||||||
|
b2ParticleDef particleDef;
|
||||||
|
particleDef.flags = particleTemplate->Flags;
|
||||||
|
//particleDef.color TODO: Implement this if we want color mixing and shit.
|
||||||
|
particleDef.lifetime = particleTemplate->LifeTime;
|
||||||
|
particleDef.velocity = b2Vec2(templateTransform->Velocity.x, templateTransform->Velocity.y);
|
||||||
|
particleDef.position = b2Vec2(templateTransform->Position.x, templateTransform->Position.y);
|
||||||
|
|
||||||
|
auto particle = m_World->CloneEntity(pt, 0);
|
||||||
|
m_World->RemoveComponent<Components::Template>(particle);
|
||||||
|
|
||||||
|
auto b2Particle = ps->CreateParticle(particleDef);
|
||||||
|
auto b2ParticleHandle = ps->GetParticleHandleFromIndex(b2Particle);
|
||||||
|
m_EntitiesToParticleHandle[i].insert(std::make_pair(particle, b2ParticleHandle));
|
||||||
|
m_ParticleHandleToEntities[i].insert(std::make_pair(b2ParticleHandle, particle));
|
||||||
|
|
||||||
|
//TODO: Ta bort detta
|
||||||
|
int particles = 0;
|
||||||
|
for (auto i : m_EntitiesToParticleHandle)
|
||||||
|
{
|
||||||
|
particles += i.size();
|
||||||
|
}
|
||||||
|
LOG_INFO("--I have %i particles.", particles);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void dd::Systems::PhysicsSystem::CreateParticleEmitter(EntityID entity)
|
||||||
|
{
|
||||||
|
auto childEntities = m_World->GetEntityChildren(entity);
|
||||||
|
if (childEntities.empty()) {
|
||||||
|
LOG_ERROR("Particle Emitter does not have any child. Please adopt one or this will not work.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int pf = 0;
|
||||||
|
dd::Components::Particle* particle;
|
||||||
|
EntityID childEntity;
|
||||||
|
for ( auto c : childEntities ) {
|
||||||
|
auto p = m_World->GetComponent<Components::Particle>(c);
|
||||||
|
auto particleTemplate = m_World->GetComponent<Components::Template>(c);
|
||||||
|
if (!p) {
|
||||||
|
continue;
|
||||||
|
LOG_WARNING("--ParticleEmitter's Child is not a particle.");
|
||||||
|
}
|
||||||
|
if(!particleTemplate) {
|
||||||
|
LOG_ERROR("ParticleEmitter's particleChild is not a template.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (pf != 0) {
|
||||||
|
LOG_WARNING("ParticleEmitter has more than one child that is a particleTemplate, only the first one is used.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
childEntity = c;
|
||||||
|
particle = p;
|
||||||
|
pf++;
|
||||||
|
}
|
||||||
|
//TODO: Skicka med fler flaggor till particlesystemet;
|
||||||
|
m_ParticleEmitters.ParticleSystem.push_back(CreateParticleSystem(particle->Radius, 0.f));
|
||||||
|
m_ParticleEmitters.ParticleEmitter.push_back(entity);
|
||||||
|
m_ParticleEmitters.ParticleTemplate.push_back(childEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
b2ParticleSystem* dd::Systems::PhysicsSystem::CreateParticleSystem(float radius, float gravityScale)
|
||||||
|
{
|
||||||
|
std::unordered_map<EntityID, const b2ParticleHandle*> m1;
|
||||||
|
std::unordered_map<const b2ParticleHandle*, EntityID> m2;
|
||||||
|
m_EntitiesToParticleHandle.push_back(m1);
|
||||||
|
m_ParticleHandleToEntities.push_back(m2);
|
||||||
|
|
||||||
|
b2ParticleSystemDef m_ParticleSystemDef;
|
||||||
|
m_ParticleSystemDef.radius = radius;
|
||||||
|
m_ParticleSystemDef.gravityScale = gravityScale;
|
||||||
|
|
||||||
|
m_ParticleSystem.push_back(m_PhysicsWorld->CreateParticleSystem(&m_ParticleSystemDef));
|
||||||
|
|
||||||
|
return m_ParticleSystem.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
dd::Systems::PhysicsSystem::~PhysicsSystem()
|
dd::Systems::PhysicsSystem::~PhysicsSystem()
|
||||||
|
|||||||
Reference in New Issue
Block a user