Merge remote-tracking branch 'origin/master' into Sound
Conflicts: src/game/Sound/SoundSystem.cpp
This commit is contained in:
@@ -79,7 +79,7 @@ int dd::EventBroker::Process(std::string contextTypeName)
|
||||
return eventsProcessed;
|
||||
}
|
||||
|
||||
void dd::EventBroker::Clear()
|
||||
void dd::EventBroker::Swap()
|
||||
{
|
||||
std::swap(m_EventQueueRead, m_EventQueueWrite);
|
||||
m_EventQueueWrite->clear();
|
||||
|
||||
+264
-10
@@ -91,6 +91,12 @@ void dd::Renderer::LoadShaders()
|
||||
//glBindFragDataLocation(m_SPDeferred2, 0, "FragmentLighting");
|
||||
m_spDeferred2->Link();
|
||||
|
||||
//Water Pass
|
||||
t_m_spWater = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/water/");
|
||||
t_m_spWater->Link();
|
||||
t_m_spWater2 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/water2/");
|
||||
t_m_spWater2->Link();
|
||||
|
||||
// Pass #3: Combining into final image
|
||||
m_spDeferred3 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/3/");
|
||||
m_spDeferred3->Link();
|
||||
@@ -110,11 +116,13 @@ void dd::Renderer::LoadShaders()
|
||||
|
||||
void dd::Renderer::CreateBuffers()
|
||||
{
|
||||
//TODO: Make the most common cases of texture create and FBO create into a function so it's not so cluttered in here.
|
||||
m_ScreenQuad = CreateQuad();
|
||||
m_UnitQuad = ResourceManager::Load<Model>("Models/Core/UnitQuad.obj");
|
||||
m_UnitSphere = ResourceManager::Load<Model>("Models/Core/UnitSphere.obj");
|
||||
m_StandardNormal = ResourceManager::Load<Texture>("Textures/Core/NeutralNormalMap.png");
|
||||
m_StandardSpecular = ResourceManager::Load<Texture>("Textures/Core/NeutralSpecularMap.png");
|
||||
t_m_WhiteSphereTexture = ResourceManager::Load<Texture>("Textures/Test/Water.png");
|
||||
|
||||
glGenRenderbuffers(1, &m_rbDepthBuffer);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, m_rbDepthBuffer);
|
||||
@@ -149,6 +157,13 @@ void dd::Renderer::CreateBuffers()
|
||||
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);
|
||||
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
|
||||
glGenFramebuffers(1, &m_fbDeferred1);
|
||||
@@ -185,14 +200,75 @@ void dd::Renderer::CreateBuffers()
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
//Fill Water Texture
|
||||
glGenTextures(1, &t_m_Gwater);
|
||||
glBindTexture(GL_TEXTURE_2D, t_m_Gwater);
|
||||
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);
|
||||
|
||||
//Fill water pass
|
||||
glGenFramebuffers(1, &t_m_fbWater);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, t_m_fbWater);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, t_m_Gwater, 0);
|
||||
GLenum waterPassDrawBuffers[] = { GL_COLOR_ATTACHMENT0 };
|
||||
glDrawBuffers(1, waterPassDrawBuffers);
|
||||
if (GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||
LOG_ERROR("m_fbDeferred2 incomplete: 0x%x\n", fbStatus);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
//water Blur texture
|
||||
glGenTextures(1, &t_m_BWater);
|
||||
glBindTexture(GL_TEXTURE_2D, t_m_BWater);
|
||||
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_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
//Fill waterBlur pass
|
||||
glGenFramebuffers(1, &t_m_fbWaterBlur);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, t_m_fbWaterBlur);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, t_m_BWater, 0);
|
||||
GLenum waterBlurDrawBuffers[] = { GL_COLOR_ATTACHMENT0 };
|
||||
glDrawBuffers(1, waterBlurDrawBuffers);
|
||||
if (GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||
LOG_ERROR("m_fbDeferred2 incomplete: 0x%x\n", fbStatus);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
//water Blur texture2
|
||||
glGenTextures(1, &t_m_BWater2);
|
||||
glBindTexture(GL_TEXTURE_2D, t_m_BWater2);
|
||||
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);
|
||||
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_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
//Fill waterBlur pass2
|
||||
glGenFramebuffers(1, &t_m_fbWaterBlur2);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, t_m_fbWaterBlur2);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, t_m_BWater2, 0);
|
||||
GLenum waterBlur2DrawBuffers[] = { GL_COLOR_ATTACHMENT0 };
|
||||
glDrawBuffers(1, waterBlur2DrawBuffers);
|
||||
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
|
||||
glGenTextures(1, &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);
|
||||
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);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
// Create third pass framebuffer
|
||||
glGenFramebuffers(1, &m_fbDeferred3);
|
||||
@@ -209,13 +285,13 @@ void dd::Renderer::CreateBuffers()
|
||||
|
||||
void dd::Renderer::Draw(RenderQueueCollection& rq)
|
||||
{
|
||||
|
||||
DrawDeferred(rq.Deferred, rq.Lights);
|
||||
rq.Forward.Jobs.sort(dd::Renderer::DepthSort);
|
||||
DrawDeferred(rq.Deferred, rq.Lights);
|
||||
DrawForward(rq.Forward, rq.Lights);
|
||||
DrawGUI(rq.GUI);
|
||||
|
||||
// Finally: Draw the deferred+forward combined texture to the screen
|
||||
glCullFace(GL_BACK);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glDepthMask(GL_FALSE);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_BLEND);
|
||||
@@ -257,7 +333,7 @@ void dd::Renderer::DrawDeferred(RenderQueue &objects, RenderQueue &lights)
|
||||
glBlendFunc(GL_ONE, GL_ONE);
|
||||
glDepthMask(GL_FALSE);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_fbDeferred2);
|
||||
glClearColor(0, 0, 0, 1);
|
||||
glClearColor(0, 0, 0, 0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
m_spDeferred2->Bind();
|
||||
DrawLightSpheres(lights);
|
||||
@@ -266,7 +342,7 @@ void dd::Renderer::DrawDeferred(RenderQueue &objects, RenderQueue &lights)
|
||||
glCullFace(GL_BACK);
|
||||
glDisable(GL_BLEND);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_fbDeferred3);
|
||||
glClearColor(0, 0, 0, 1);
|
||||
glClearColor(0, 0, 0, 0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
m_spDeferred3->Bind();
|
||||
glUniform3fv(glGetUniformLocation(*m_spDeferred3, "La"), 1, glm::value_ptr(glm::vec3(0.5f)));
|
||||
@@ -280,7 +356,6 @@ void dd::Renderer::DrawDeferred(RenderQueue &objects, RenderQueue &lights)
|
||||
|
||||
void dd::Renderer::DrawForward(RenderQueue &objects, RenderQueue &lights)
|
||||
{
|
||||
|
||||
// Forward-render semi-transparent objects on top of the current framebuffer
|
||||
glDisable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
@@ -296,6 +371,19 @@ void dd::Renderer::DrawForward(RenderQueue &objects, RenderQueue &lights)
|
||||
|
||||
m_spForward->Bind();
|
||||
DrawScene(objects, *m_spForward);
|
||||
|
||||
//WaterPass
|
||||
glDisable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
glDepthMask(GL_TRUE);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, t_m_fbWater);
|
||||
glClearColor(0, 0, 0, 0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
t_m_spWater->Bind();
|
||||
DrawWater(objects);
|
||||
}
|
||||
|
||||
void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
|
||||
@@ -311,6 +399,7 @@ void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
|
||||
if (modelJob) {
|
||||
glm::mat4 modelMatrix = modelJob->ModelMatrix;
|
||||
MVP = PV * modelMatrix;
|
||||
glUniform4fv(glGetUniformLocation(shaderProgramHandle, "Color"), 1, glm::value_ptr(modelJob->Color));
|
||||
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(viewMatrix));
|
||||
@@ -318,7 +407,6 @@ void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
|
||||
glUniform3fv(glGetUniformLocation(shaderProgramHandle, "LightSpecular"), 1, glm::value_ptr(glm::vec3(1.f)));
|
||||
glUniform3fv(glGetUniformLocation(shaderProgramHandle, "LightDiffuse"), 1, glm::value_ptr(glm::vec3(1.f)));
|
||||
glUniform1f(glGetUniformLocation(shaderProgramHandle, "LightRadius"), 40.0f);
|
||||
|
||||
glUniform1f(glGetUniformLocation(shaderProgramHandle, "MaterialShininess"), modelJob->Shininess);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
@@ -339,7 +427,6 @@ void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
|
||||
glBindTexture(GL_TEXTURE_2D, *m_StandardSpecular);
|
||||
}
|
||||
|
||||
|
||||
glBindVertexArray(modelJob->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->ElementBuffer);
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, 0, modelJob->StartIndex);
|
||||
@@ -355,6 +442,7 @@ void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
|
||||
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(viewMatrix));
|
||||
glUniform4fv(glGetUniformLocation(shaderProgramHandle, "Color"), 1, glm::value_ptr(modelJob->Color));
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, spriteJob->DiffuseTexture);
|
||||
@@ -409,6 +497,112 @@ void dd::Renderer::DrawLightSpheres(RenderQueue &lights)
|
||||
}
|
||||
}
|
||||
|
||||
void dd::Renderer::DrawWater(RenderQueue &rq)
|
||||
{
|
||||
GLuint shaderProgramHandle = *t_m_spWater;
|
||||
|
||||
glm::mat4 projectionMatrix = m_Camera->ProjectionMatrix();
|
||||
glm::mat4 viewMatrix = m_Camera->ViewMatrix();
|
||||
glm::mat4 PV = projectionMatrix * viewMatrix;
|
||||
glm::mat4 MVP;
|
||||
for ( auto &job : rq ) {
|
||||
auto waterJob = std::dynamic_pointer_cast<WaterParticleJob>(job);
|
||||
if (waterJob) {
|
||||
glm::mat4 modelMatrix = waterJob->ModelMatrix;
|
||||
MVP = PV * 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(viewMatrix));
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, *t_m_WhiteSphereTexture);
|
||||
|
||||
glBindVertexArray(m_UnitQuad->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_UnitQuad->ElementBuffer);
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, m_UnitQuad->m_Indices.size(), GL_UNSIGNED_INT, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//blur1
|
||||
shaderProgramHandle = *t_m_spWater2;
|
||||
glDisable(GL_CULL_FACE);
|
||||
glDepthMask(GL_FALSE);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, t_m_fbWaterBlur);
|
||||
glClearColor(0, 0, 0, 0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
t_m_spWater2->Bind();
|
||||
float radius = 3.f;
|
||||
|
||||
glUniform2fv(glGetUniformLocation(shaderProgramHandle, "dir"), 1, glm::value_ptr(glm::vec2(1.0f, 0.0f)));
|
||||
glUniform1f(glGetUniformLocation(shaderProgramHandle, "res"), m_Resolution.Width);
|
||||
glUniform1f(glGetUniformLocation(shaderProgramHandle, "radius"), radius);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, t_m_Gwater);
|
||||
glBindVertexArray(m_ScreenQuad);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
|
||||
|
||||
//blur2
|
||||
shaderProgramHandle = *t_m_spWater2;
|
||||
glDisable(GL_CULL_FACE);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_FALSE);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_fbDeferred3);
|
||||
t_m_spWater2->Bind();
|
||||
|
||||
glUniform2fv(glGetUniformLocation(shaderProgramHandle, "dir"), 1, glm::value_ptr(glm::vec2(0.0f, 1.0f)));
|
||||
glUniform1f(glGetUniformLocation(shaderProgramHandle, "res"), m_Resolution.Height);
|
||||
glUniform1f(glGetUniformLocation(shaderProgramHandle, "radius"), radius);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, t_m_BWater);
|
||||
glBindVertexArray(m_ScreenQuad);
|
||||
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()
|
||||
{
|
||||
float quadVertices[] =
|
||||
@@ -472,4 +666,64 @@ void dd::Renderer::DebugKeys()
|
||||
if (glfwGetKey(m_Window, GLFW_KEY_F6)) {
|
||||
m_CurrentScreenBuffer = m_tLighting;
|
||||
}
|
||||
if (glfwGetKey(m_Window, GLFW_KEY_F7)) {
|
||||
m_CurrentScreenBuffer = t_m_Gwater;
|
||||
}
|
||||
if (glfwGetKey(m_Window, GLFW_KEY_F8)) {
|
||||
m_CurrentScreenBuffer = t_m_BWater;
|
||||
}
|
||||
}
|
||||
|
||||
void dd::Renderer::DrawGUI(dd::RenderQueue& rq)
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_fbDeferred3);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
//glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
|
||||
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
|
||||
|
||||
m_spScreen->Bind();
|
||||
|
||||
glm::mat4 MVP;
|
||||
|
||||
for (auto &job : rq) {
|
||||
auto frameJob = std::dynamic_pointer_cast<FrameJob>(job);
|
||||
if (frameJob) {
|
||||
FrameJob jobCopy = *(frameJob.get());
|
||||
glm::mat4 viewMatrix = glm::mat4(1); //frameJob->ViewMatrix;
|
||||
glm::mat4 PV = glm::mat4(1); //frameJob->ProjectionMatrix * viewMatrix;
|
||||
glm::mat4 modelMatrix = glm::mat4(1); //frameJob->ModelMatrix;
|
||||
MVP = PV * modelMatrix;
|
||||
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, "V"), 1, GL_FALSE, glm::value_ptr(viewMatrix));
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, frameJob->DiffuseTexture);
|
||||
//glActiveTexture(GL_TEXTURE1);
|
||||
//glBindTexture(GL_TEXTURE_2D, frameJob->NormalTexture);
|
||||
//glActiveTexture(GL_TEXTURE2);
|
||||
//glBindTexture(GL_TEXTURE_2D, frameJob->SpecularTexture);
|
||||
|
||||
Rectangle& vp = frameJob->Viewport;
|
||||
glViewport(vp.X, m_Resolution.Height - vp.Y - vp.Height, vp.Width, vp.Height);
|
||||
Rectangle& sc = frameJob->Scissor;
|
||||
if (sc == Rectangle()) {
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
} else {
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
glScissor(sc.X, m_Resolution.Height - sc.Y - sc.Height, sc.Width, sc.Height);
|
||||
}
|
||||
|
||||
glBindVertexArray(m_ScreenQuad);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
glViewport(0, 0, m_Resolution.Width, m_Resolution.Height);
|
||||
}
|
||||
|
||||
Regular → Executable
+2
@@ -24,6 +24,7 @@ layout (binding = 2) uniform sampler2D SpecularMap;
|
||||
|
||||
uniform mat4 V;
|
||||
uniform float MaterialShininess;
|
||||
uniform vec4 Color;
|
||||
|
||||
in VertexData
|
||||
{
|
||||
@@ -49,6 +50,7 @@ void main()
|
||||
{
|
||||
// Diffuse Texture
|
||||
GDiffuse = texture(DiffuseTexture, Input.TextureCoord) * Input.DiffuseColor;
|
||||
GDiffuse = GDiffuse * Color;
|
||||
|
||||
// G-buffer Position
|
||||
GPosition = vec4(Input.Position.xyz, 1.0);
|
||||
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
This file is part of Daydream Engine.
|
||||
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
|
||||
|
||||
Daydream Engine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Daydream Engine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#version 440
|
||||
|
||||
layout (binding=0) uniform sampler2D DiffuseTexture;
|
||||
layout (binding=1) uniform sampler2D NormalMap;
|
||||
layout (binding=2) uniform sampler2D SpecularMap;
|
||||
|
||||
uniform mat4 MVP;
|
||||
uniform mat4 M;
|
||||
uniform mat4 V;
|
||||
uniform mat4 P;
|
||||
uniform vec3 LightPosition;
|
||||
uniform float LightRadius;
|
||||
uniform vec3 LightSpecular;
|
||||
uniform vec3 LightDiffuse;
|
||||
|
||||
in VertexData
|
||||
{
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
vec3 Tangent;
|
||||
vec3 BiTangent;
|
||||
vec2 TextureCoord;
|
||||
vec4 DiffuseColor;
|
||||
vec4 SpecularColor;
|
||||
vec4 BoneIndices1;
|
||||
vec4 BoneIndices2;
|
||||
vec4 BoneWeights1;
|
||||
vec4 BoneWeights2;
|
||||
} Input;
|
||||
|
||||
out vec4 frag_Diffuse;
|
||||
|
||||
vec4 phong(vec3 position, vec3 normal, vec3 specular, float specularExponent)
|
||||
{
|
||||
// Diffuse
|
||||
vec3 lightPos = vec3(V * vec4(LightPosition, 1.0));
|
||||
vec3 distanceToLight = lightPos - position;
|
||||
vec3 directionToLight = normalize(distanceToLight);
|
||||
float dotProd = dot(directionToLight, normal);
|
||||
dotProd = max(dotProd, 0.0);
|
||||
vec3 Idiffuse = LightDiffuse * dotProd;
|
||||
|
||||
// Specular
|
||||
//vec3 reflection = reflect(-directionToLight, normal);
|
||||
vec3 surfaceToViewer = normalize(-position);
|
||||
vec3 halfWay = normalize(surfaceToViewer + directionToLight);
|
||||
float dotSpecular = max(dot(halfWay, normal), 0.0);
|
||||
float specularFactor = pow(dotSpecular, specularExponent);
|
||||
vec3 Ispecular = specular * LightSpecular * specularFactor;
|
||||
|
||||
//Attenuation
|
||||
float dist = distance(lightPos, position);
|
||||
//float attenuation = 1.0 - pow(dist / LightRadius, 2);
|
||||
float attenuation = pow(max(0.0f, 1.0 - (dist / LightRadius)), 2);
|
||||
|
||||
return vec4((Idiffuse + Ispecular) * attenuation, 1.0);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 normalTexel = texture(NormalMap, Input.TextureCoord);
|
||||
mat3 TBN = mat3(Input.Tangent, Input.BiTangent, Input.Normal);
|
||||
vec3 normal = normalize(vec4(TBN * normalTexel.xyz, 0.0).xyz);
|
||||
|
||||
vec4 specularTexel = texture(SpecularMap, Input.TextureCoord);
|
||||
|
||||
vec4 diffuseTexel = texture(DiffuseTexture, Input.TextureCoord);
|
||||
vec4 La = vec4(0.3, 0.3, 0.3, 1.0);
|
||||
vec4 light = phong(Input.Position, normalize(normal), specularTexel.rgb, specularTexel.a);
|
||||
//frag_Diffuse = light;
|
||||
frag_Diffuse = diffuseTexel;
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
This file is part of Daydream Engine.
|
||||
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
|
||||
|
||||
Daydream Engine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Daydream Engine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#version 440
|
||||
|
||||
uniform mat4 MVP;
|
||||
uniform mat4 M;
|
||||
uniform mat4 V;
|
||||
uniform mat4 P;
|
||||
uniform mat4 Bones[100];
|
||||
|
||||
layout (location = 0) in vec3 Position;
|
||||
layout (location = 1) in vec3 Normal;
|
||||
layout (location = 2) in vec3 Tangent;
|
||||
layout (location = 3) in vec3 BiTangent;
|
||||
layout (location = 4) in vec2 TextureCoord;
|
||||
layout (location = 5) in vec4 DiffuseColor;
|
||||
layout (location = 6) in vec4 SpecularColor;
|
||||
layout (location = 7) in vec4 BoneIndices1;
|
||||
layout (location = 8) in vec4 BoneIndices2;
|
||||
layout (location = 9) in vec4 BoneWeights1;
|
||||
layout (location = 10) in vec4 BoneWeights2;
|
||||
|
||||
out VertexData
|
||||
{
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
vec3 Tangent;
|
||||
vec3 BiTangent;
|
||||
vec2 TextureCoord;
|
||||
vec4 DiffuseColor;
|
||||
vec4 SpecularColor;
|
||||
vec4 BoneIndices1;
|
||||
vec4 BoneIndices2;
|
||||
vec4 BoneWeights1;
|
||||
vec4 BoneWeights2;
|
||||
} Output;
|
||||
|
||||
void main()
|
||||
{
|
||||
mat4 boneTransform = mat4(1);
|
||||
if (length(BoneWeights1 + BoneWeights2) > 0) {
|
||||
boneTransform = BoneWeights1[0] * Bones[int(BoneIndices1[0])]
|
||||
+ BoneWeights1[1] * Bones[int(BoneIndices1[1])]
|
||||
+ BoneWeights1[2] * Bones[int(BoneIndices1[2])]
|
||||
+ BoneWeights1[3] * Bones[int(BoneIndices1[3])]
|
||||
+ BoneWeights2[0] * Bones[int(BoneIndices2[0])]
|
||||
+ BoneWeights2[1] * Bones[int(BoneIndices2[1])]
|
||||
+ BoneWeights2[2] * Bones[int(BoneIndices2[2])]
|
||||
+ BoneWeights2[3] * Bones[int(BoneIndices2[3])];
|
||||
}
|
||||
|
||||
//gl_Position = MVP * boneTransform * vec4(Position, 1.0);
|
||||
gl_Position = MVP * vec4(Position, 1.0);
|
||||
|
||||
//TODO: Make sure that boneTransform works here.
|
||||
Output.Position = (V * M * boneTransform * vec4(Position, 1.0)).xyz;
|
||||
Output.Normal = (inverse(transpose(V * M)) * boneTransform * vec4(Normal, 0.0)).xyz;
|
||||
Output.Tangent = Tangent;
|
||||
Output.BiTangent = BiTangent;
|
||||
Output.TextureCoord = TextureCoord;
|
||||
Output.DiffuseColor = DiffuseColor;
|
||||
Output.SpecularColor = SpecularColor;
|
||||
Output.BoneIndices1 = BoneIndices1;
|
||||
Output.BoneIndices2 = BoneIndices2;
|
||||
Output.BoneWeights1 = BoneWeights1;
|
||||
Output.BoneWeights2 = BoneWeights2;
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
This file is part of Daydream Engine.
|
||||
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
|
||||
|
||||
Daydream Engine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Daydream Engine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#version 440
|
||||
|
||||
uniform vec2 dir;
|
||||
uniform float res;
|
||||
uniform float radius;
|
||||
|
||||
layout (binding=0) uniform sampler2D WaterTexture;
|
||||
|
||||
in VertexData
|
||||
{
|
||||
vec3 Position;
|
||||
vec2 TextureCoord;
|
||||
} Input;
|
||||
|
||||
out vec4 frag_Diffuse;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 WaterTexel = texture(WaterTexture, Input.TextureCoord);
|
||||
|
||||
vec4 sum = vec4(0.0);
|
||||
vec2 tc = Input.TextureCoord;
|
||||
|
||||
//How much blur, 1 = blur by one pixel.
|
||||
float blur = radius/res;
|
||||
|
||||
float hstep = dir.x;
|
||||
float vstep = dir.y;
|
||||
|
||||
float Threshhold = 0.1;
|
||||
|
||||
//apply filter using a 9 tap filter with predefined gaussian weights
|
||||
|
||||
sum += texture(WaterTexture, vec2(tc.x - 4.0*blur*hstep, tc.y - 4.0*blur*vstep)) * 0.0162162162;
|
||||
sum += texture(WaterTexture, vec2(tc.x - 3.0*blur*hstep, tc.y - 3.0*blur*vstep)) * 0.0540540541;
|
||||
sum += texture(WaterTexture, vec2(tc.x - 2.0*blur*hstep, tc.y - 2.0*blur*vstep)) * 0.1216216216;
|
||||
sum += texture(WaterTexture, vec2(tc.x - 1.0*blur*hstep, tc.y - 1.0*blur*vstep)) * 0.1945945946;
|
||||
|
||||
sum += texture(WaterTexture, vec2(tc.x, tc.y)) * 0.2270270270;
|
||||
|
||||
sum += texture(WaterTexture, vec2(tc.x + 1.0*blur*hstep, tc.y + 1.0*blur*vstep)) * 0.1945945946;
|
||||
sum += texture(WaterTexture, vec2(tc.x + 2.0*blur*hstep, tc.y + 2.0*blur*vstep)) * 0.1216216216;
|
||||
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;
|
||||
|
||||
frag_Diffuse = vec4(sum.rgb, 1.0) * vec4(0.0, 0.6, 1.5, 1.0);
|
||||
float avgColor = frag_Diffuse.r + frag_Diffuse.g + frag_Diffuse.b;
|
||||
avgColor = avgColor/3;
|
||||
if ( avgColor*dir.y > Threshhold ){
|
||||
frag_Diffuse = vec4(0.0, 0.3, 1.0, 1.0);
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
This file is part of Daydream Engine.
|
||||
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
|
||||
|
||||
Daydream Engine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Daydream Engine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#version 440
|
||||
|
||||
layout (location = 0) in vec3 Position;
|
||||
|
||||
out VertexData
|
||||
{
|
||||
vec3 Position;
|
||||
vec2 TextureCoord;
|
||||
} Output;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(Position, 1.0);
|
||||
Output.Position = Position;
|
||||
Output.TextureCoord = (vec2(Position) + 1) / 2;
|
||||
}
|
||||
@@ -31,6 +31,9 @@ dd::Texture::Texture(std::string path)
|
||||
}
|
||||
}
|
||||
|
||||
this->Width = image->Width;
|
||||
this->Height = image->Height;
|
||||
|
||||
GLint format;
|
||||
switch (image->Format) {
|
||||
case Image::ImageFormat::RGB:
|
||||
|
||||
Reference in New Issue
Block a user