Added renderQueue for water and created buffers for the water to use.
This commit is contained in:
@@ -440,6 +440,15 @@ public:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EnqueueWaterParticles(glm::vec3 position, glm::vec4 color)
|
||||||
|
{
|
||||||
|
WaterParticleJob job;
|
||||||
|
job.Position = position;
|
||||||
|
job.Color = color;
|
||||||
|
|
||||||
|
m_RendererQueue.Deferred.Add(job);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<ResourceManager> m_ResourceManager;
|
std::shared_ptr<ResourceManager> m_ResourceManager;
|
||||||
std::shared_ptr<EventBroker> m_EventBroker;
|
std::shared_ptr<EventBroker> m_EventBroker;
|
||||||
|
|||||||
@@ -115,6 +115,12 @@ struct PointLightJob : RenderJob
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct WaterParticleJob : RenderJob
|
||||||
|
{
|
||||||
|
glm::vec3 Position;
|
||||||
|
glm::vec4 Color;
|
||||||
|
};
|
||||||
|
|
||||||
class RenderQueue
|
class RenderQueue
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -153,12 +159,14 @@ struct RenderQueueCollection
|
|||||||
RenderQueue Deferred;
|
RenderQueue Deferred;
|
||||||
RenderQueue Forward;
|
RenderQueue Forward;
|
||||||
RenderQueue Lights;
|
RenderQueue Lights;
|
||||||
|
RenderQueue Water;
|
||||||
|
|
||||||
void Clear()
|
void Clear()
|
||||||
{
|
{
|
||||||
Deferred.Clear();
|
Deferred.Clear();
|
||||||
Forward.Clear();
|
Forward.Clear();
|
||||||
Lights.Clear();
|
Lights.Clear();
|
||||||
|
Water.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sort()
|
void Sort()
|
||||||
@@ -166,6 +174,8 @@ struct RenderQueueCollection
|
|||||||
Deferred.Sort();
|
Deferred.Sort();
|
||||||
Forward.Sort();
|
Forward.Sort();
|
||||||
Lights.Sort();
|
Lights.Sort();
|
||||||
|
//TODO: Is water sort needed?
|
||||||
|
Water.Sort();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ private:
|
|||||||
ShaderProgram* m_spDeferred3;
|
ShaderProgram* m_spDeferred3;
|
||||||
ShaderProgram* m_spForward;
|
ShaderProgram* m_spForward;
|
||||||
ShaderProgram* m_spScreen;
|
ShaderProgram* m_spScreen;
|
||||||
|
ShaderProgram* t_m_spWater;
|
||||||
|
|
||||||
GLuint m_ScreenQuad = 0;
|
GLuint m_ScreenQuad = 0;
|
||||||
Model* m_UnitSphere = nullptr;
|
Model* m_UnitSphere = nullptr;
|
||||||
@@ -89,6 +90,12 @@ private:
|
|||||||
GLuint m_tLighting = 0;
|
GLuint m_tLighting = 0;
|
||||||
GLuint m_fbDeferred3 = 0;
|
GLuint m_fbDeferred3 = 0;
|
||||||
GLuint m_tFinal = 0;
|
GLuint m_tFinal = 0;
|
||||||
|
//Water "Diffuse" texture
|
||||||
|
GLuint t_m_GWater = 0;
|
||||||
|
//Water blur texture
|
||||||
|
GLuint t_m_tWater;
|
||||||
|
//WAterpass Framebuffer
|
||||||
|
GLuint t_m_fbWater;
|
||||||
|
|
||||||
GLuint m_CurrentScreenBuffer = 0;
|
GLuint m_CurrentScreenBuffer = 0;
|
||||||
void LoadShaders();
|
void LoadShaders();
|
||||||
@@ -101,6 +108,7 @@ private:
|
|||||||
void DrawForward(RenderQueue &objects, RenderQueue &lights);
|
void DrawForward(RenderQueue &objects, RenderQueue &lights);
|
||||||
void DrawScene(RenderQueue &objects, ShaderProgram &program);
|
void DrawScene(RenderQueue &objects, ShaderProgram &program);
|
||||||
void DrawLightSpheres(RenderQueue &lights);
|
void DrawLightSpheres(RenderQueue &lights);
|
||||||
|
void DrawWater(RenderQueue &objects);
|
||||||
void DebugKeys();
|
void DebugKeys();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -149,6 +149,15 @@ 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);
|
||||||
|
//WaterTest
|
||||||
|
glGenTextures(1, &t_m_GWater);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, t_m_GWater);
|
||||||
|
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_MAG_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, 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);
|
||||||
@@ -158,8 +167,10 @@ void dd::Renderer::CreateBuffers()
|
|||||||
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);
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_TEXTURE_2D, m_GSpecular, 0);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_TEXTURE_2D, m_GSpecular, 0);
|
||||||
GLenum firstPassDrawBuffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 };
|
//WaterTest
|
||||||
glDrawBuffers(4, firstPassDrawBuffers);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT4, GL_TEXTURE_2D, t_m_GWater, 0);
|
||||||
|
GLenum firstPassDrawBuffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3, GL_COLOR_ATTACHMENT4 };
|
||||||
|
glDrawBuffers(5, 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);
|
||||||
@@ -185,6 +196,26 @@ void dd::Renderer::CreateBuffers()
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Blur the water
|
||||||
|
glGenTextures(1, &t_m_tWater);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, t_m_tWater);
|
||||||
|
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_MAG_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
|
|
||||||
|
//Blur water pass
|
||||||
|
glGenFramebuffers(1, &t_m_fbWater);
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, t_m_fbWater);
|
||||||
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, t_m_tWater, 0);
|
||||||
|
GLenum waterPassDrawBuffers[] = { GL_COLOR_ATTACHMENT0 };
|
||||||
|
glDrawBuffers(1, secondPassDrawBuffers);
|
||||||
|
if (GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||||
|
LOG_ERROR("m_fbDeferred2 incomplete: 0x%x\n", fbStatus);
|
||||||
|
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user