Defucked defucked rendering
This commit is contained in:
+3
-3
@@ -230,8 +230,8 @@ void GameWorld::Initialize()
|
|||||||
auto transform = AddComponent<Components::Transform>(Light, "Transform");
|
auto transform = AddComponent<Components::Transform>(Light, "Transform");
|
||||||
transform->Position = glm::vec3(20+ 10*cos(i), 3, 0 + 10*sin(i));
|
transform->Position = glm::vec3(20+ 10*cos(i), 3, 0 + 10*sin(i));
|
||||||
auto light = AddComponent<Components::PointLight>(Light, "PointLight");
|
auto light = AddComponent<Components::PointLight>(Light, "PointLight");
|
||||||
light->Diffuse = glm::vec3(94.f/255.f, 227.f/255.f, 230.f/255.f);
|
light->Diffuse = glm::vec3(0.5f, 0.5f, 1.0f);
|
||||||
light->Specular = glm::vec3(94.f/255.f, 227.f/255.f, 230.f/255.f);
|
light->Specular = glm::vec3(1.0f, 1.0f, 1.0f);
|
||||||
light->specularExponent = 1.0f;
|
light->specularExponent = 1.0f;
|
||||||
auto model = AddComponent<Components::Model>(Light, "Model");
|
auto model = AddComponent<Components::Model>(Light, "Model");
|
||||||
model->ModelFile = "Models/Placeholders/PhysicsTest/PointLight.obj";
|
model->ModelFile = "Models/Placeholders/PhysicsTest/PointLight.obj";
|
||||||
@@ -243,7 +243,7 @@ void GameWorld::Initialize()
|
|||||||
auto cube = CreateEntity();
|
auto cube = CreateEntity();
|
||||||
auto transform = AddComponent<Components::Transform>(cube, "Transform");
|
auto transform = AddComponent<Components::Transform>(cube, "Transform");
|
||||||
transform->Position = glm::vec3(20, 10 + i*2, 0);
|
transform->Position = glm::vec3(20, 10 + i*2, 0);
|
||||||
transform->Scale = glm::vec3(1);
|
//transform->Scale = glm::vec3(1);
|
||||||
transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f));
|
transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f));
|
||||||
auto model = AddComponent<Components::Model>(cube, "Model");
|
auto model = AddComponent<Components::Model>(cube, "Model");
|
||||||
model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj";
|
model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj";
|
||||||
|
|||||||
+91
-35
@@ -128,6 +128,11 @@ void Renderer::LoadContent()
|
|||||||
m_SecondPassProgram_Debug.Compile();
|
m_SecondPassProgram_Debug.Compile();
|
||||||
m_SecondPassProgram_Debug.Link();
|
m_SecondPassProgram_Debug.Link();
|
||||||
|
|
||||||
|
m_FinalPassProgram.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/FinalPass.vert.glsl")));
|
||||||
|
m_FinalPassProgram.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/FinalPass.frag.glsl")));
|
||||||
|
m_FinalPassProgram.Compile();
|
||||||
|
m_FinalPassProgram.Link();
|
||||||
|
|
||||||
m_ScreenQuad = CreateQuad();
|
m_ScreenQuad = CreateQuad();
|
||||||
|
|
||||||
FrameBufferTextures();
|
FrameBufferTextures();
|
||||||
@@ -532,10 +537,10 @@ void Renderer::ClearStuff()
|
|||||||
|
|
||||||
void Renderer::FrameBufferTextures()
|
void Renderer::FrameBufferTextures()
|
||||||
{
|
{
|
||||||
m_fb = 0;
|
m_fbBasePass = 0;
|
||||||
m_fDepthBuffer = 0;
|
m_fDepthBuffer = 0;
|
||||||
|
|
||||||
glGenFramebuffers(1, &m_fb);
|
glGenFramebuffers(1, &m_fbBasePass);
|
||||||
glGenRenderbuffers(1, &m_fDepthBuffer);
|
glGenRenderbuffers(1, &m_fDepthBuffer);
|
||||||
|
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER, m_fDepthBuffer);
|
glBindRenderbuffer(GL_RENDERBUFFER, m_fDepthBuffer);
|
||||||
@@ -562,14 +567,14 @@ void Renderer::FrameBufferTextures()
|
|||||||
//Generate and bind normal texture
|
//Generate and bind normal texture
|
||||||
glGenTextures(1, &m_fNormalsTexture);
|
glGenTextures(1, &m_fNormalsTexture);
|
||||||
glBindTexture(GL_TEXTURE_2D, m_fNormalsTexture);
|
glBindTexture(GL_TEXTURE_2D, m_fNormalsTexture);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, WIDTH, HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB10_A2, WIDTH, HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
|
|
||||||
//Bind fb
|
//Bind fb
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, m_fb);
|
glBindFramebuffer(GL_FRAMEBUFFER, m_fbBasePass);
|
||||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_fDepthBuffer);
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_fDepthBuffer);
|
||||||
|
|
||||||
//Attach textures to the FB
|
//Attach textures to the FB
|
||||||
@@ -583,6 +588,29 @@ void Renderer::FrameBufferTextures()
|
|||||||
LOG_ERROR("DeferredLighting:Init: FrameBuffer incomplete: 0x%x\n", fbStatus);
|
LOG_ERROR("DeferredLighting:Init: FrameBuffer incomplete: 0x%x\n", fbStatus);
|
||||||
//exit(1);
|
//exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_fbLightingPass = 0;
|
||||||
|
glGenFramebuffers(1, &m_fbLightingPass);
|
||||||
|
|
||||||
|
glGenTextures(1, &m_fLightingTexture);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, m_fLightingTexture);
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, WIDTH, 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);
|
||||||
|
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, m_fbLightingPass);
|
||||||
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_fLightingTexture, 0);
|
||||||
|
|
||||||
|
fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||||
|
if(fbStatus != GL_FRAMEBUFFER_COMPLETE)
|
||||||
|
{
|
||||||
|
LOG_ERROR("DeferredLighting:Init: FrameBuffer incomplete: 0x%x\n", fbStatus);
|
||||||
|
//exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//void Renderer::FrameBufferTextures()
|
//void Renderer::FrameBufferTextures()
|
||||||
@@ -654,12 +682,15 @@ void Renderer::FrameBufferTextures()
|
|||||||
|
|
||||||
void Renderer::DrawFBO()
|
void Renderer::DrawFBO()
|
||||||
{
|
{
|
||||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fb);
|
/*
|
||||||
|
Base pass
|
||||||
|
*/
|
||||||
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbBasePass);
|
||||||
|
|
||||||
// Clear G-buffer
|
// Clear G-buffer
|
||||||
GLenum windowBuffClear[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 };
|
GLenum windowBuffClear[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 };
|
||||||
glDrawBuffers(3, windowBuffClear);
|
glDrawBuffers(3, windowBuffClear);
|
||||||
glClearColor(0.2f, 0.2f, 0.2f, 0.0f);
|
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
// Execute the first render stage which will fill out the internal buffers with data(??)
|
// Execute the first render stage which will fill out the internal buffers with data(??)
|
||||||
@@ -667,35 +698,54 @@ void Renderer::DrawFBO()
|
|||||||
GLenum windowBuffOpaque[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 };
|
GLenum windowBuffOpaque[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 };
|
||||||
glDrawBuffers(3, windowBuffOpaque);
|
glDrawBuffers(3, windowBuffOpaque);
|
||||||
|
|
||||||
|
glCullFace(GL_BACK);
|
||||||
DrawFBOScene();
|
DrawFBOScene();
|
||||||
|
|
||||||
// Draw to screen
|
/*
|
||||||
|
Lighting pass
|
||||||
|
*/
|
||||||
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbLightingPass);
|
||||||
|
GLenum lightingPassAttachments[] = { GL_COLOR_ATTACHMENT0 };
|
||||||
|
glDrawBuffers(1, lightingPassAttachments);
|
||||||
|
|
||||||
|
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
m_SecondPassProgram.Bind();
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, m_fPositionTexture);
|
||||||
|
glActiveTexture(GL_TEXTURE1);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, m_fNormalsTexture);
|
||||||
|
|
||||||
|
glCullFace(GL_FRONT);
|
||||||
|
DrawLightScene();
|
||||||
|
|
||||||
|
/*
|
||||||
|
Final pass
|
||||||
|
*/
|
||||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||||
if(!m_QuadView)
|
|
||||||
{
|
|
||||||
m_SecondPassProgram.Bind();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_SecondPassProgram_Debug.Bind();
|
|
||||||
}
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
//if(!m_QuadView)
|
||||||
|
//{
|
||||||
|
m_FinalPassProgram.Bind();
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//{
|
||||||
|
// m_SecondPassProgram_Debug.Bind();
|
||||||
|
//}
|
||||||
|
|
||||||
|
// Ambient light
|
||||||
|
glUniform3fv(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "La"), 1, glm::value_ptr(glm::vec3(0.3f, 0.3f, 0.3f)));
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, m_fDiffuseTexture);
|
glBindTexture(GL_TEXTURE_2D, m_fDiffuseTexture);
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE1);
|
glActiveTexture(GL_TEXTURE1);
|
||||||
glBindTexture(GL_TEXTURE_2D, m_fPositionTexture);
|
glBindTexture(GL_TEXTURE_2D, m_fLightingTexture);
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE2);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, m_fNormalsTexture);
|
|
||||||
|
|
||||||
DrawLightScene();
|
|
||||||
|
|
||||||
|
glCullFace(GL_BACK);
|
||||||
glBindVertexArray(m_ScreenQuad);
|
glBindVertexArray(m_ScreenQuad);
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
glEnableVertexAttribArray(2);
|
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -774,7 +824,9 @@ void Renderer::DrawFBOScene()
|
|||||||
|
|
||||||
MVP = cameraMatrix * modelMatrix;
|
MVP = cameraMatrix * modelMatrix;
|
||||||
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
||||||
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "ModelMatrix"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
|
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
|
||||||
|
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
|
||||||
|
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(m_Camera->ProjectionMatrix()));
|
||||||
glBindVertexArray(model->VAO);
|
glBindVertexArray(model->VAO);
|
||||||
for (auto texGroup : model->TextureGroups)
|
for (auto texGroup : model->TextureGroups)
|
||||||
{
|
{
|
||||||
@@ -802,15 +854,18 @@ void Renderer::DrawLightScene()
|
|||||||
|
|
||||||
for(int i = 0; i < Lights; i++)
|
for(int i = 0; i < Lights; i++)
|
||||||
{
|
{
|
||||||
glm::mat4 MVP = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix() * lM[i];
|
MVP = cameraMatrix * lM[i];
|
||||||
|
|
||||||
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
glUniform2fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ViewportSize"), 1,glm::value_ptr(glm::vec2(WIDTH, HEIGHT)));
|
||||||
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
|
glUniformMatrix4fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
||||||
glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(m_Camera->ProjectionMatrix()));
|
glUniformMatrix4fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
|
||||||
|
glUniformMatrix4fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(m_Camera->ProjectionMatrix()));
|
||||||
glUniformMatrix4fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(lM[i]));
|
glUniformMatrix4fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(lM[i]));
|
||||||
glUniform3f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ls"), Light_specular[i].x, Light_specular[i].y, Light_specular[i].z);
|
glUniform3fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "la"), 1, glm::value_ptr(glm::vec3(0.3f, 0.3f, 0.3f)));
|
||||||
glUniform3f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ld"), Light_diffuse[i].x, Light_diffuse[i].y, Light_diffuse[i].z);
|
glUniform3fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ls"), 1, glm::value_ptr(Light_specular[i]));
|
||||||
glUniform3f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "lp"), Light_position[i].x, Light_position[i].y, Light_position[i].z);
|
glUniform3fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ld"), 1, glm::value_ptr(Light_diffuse[i]));
|
||||||
|
glUniform3fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "lp"), 1, glm::value_ptr(Light_position[i]));
|
||||||
|
glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "LightRadius"), 5.0f);
|
||||||
glUniform3f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "CameraPosition"), m_Camera->Position().x, m_Camera->Position().y, m_Camera->Position().z);
|
glUniform3f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "CameraPosition"), m_Camera->Position().x, m_Camera->Position().y, m_Camera->Position().z);
|
||||||
//glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "speculatExponent"), Light_specularExponent[i]);
|
//glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "speculatExponent"), Light_specularExponent[i]);
|
||||||
glDrawArrays(GL_TRIANGLES, 0, m_sphereModel->Vertices.size());
|
glDrawArrays(GL_TRIANGLES, 0, m_sphereModel->Vertices.size());
|
||||||
@@ -829,10 +884,11 @@ void Renderer::CreateLightMatrix()
|
|||||||
{
|
{
|
||||||
for(int i = 0; i < Lights; i++)
|
for(int i = 0; i < Lights; i++)
|
||||||
{
|
{
|
||||||
const float radius = 5.0f;
|
const float scale = 10.0f;
|
||||||
lM[i] = glm::scale(glm::mat4(1.0), glm::vec3(radius, radius, radius));
|
glm::mat4 model;
|
||||||
lM[i] = glm::translate(lM[i], Light_position[i]);
|
model *= glm::translate(Light_position[i]);
|
||||||
lM[i] = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix() * lM[i];
|
model *= glm::scale(glm::vec3(scale));
|
||||||
|
lM[i] = model;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-1
@@ -91,11 +91,14 @@ private:
|
|||||||
GLuint m_ShadowFrameBuffer;
|
GLuint m_ShadowFrameBuffer;
|
||||||
GLuint m_ShadowDepthTexture;
|
GLuint m_ShadowDepthTexture;
|
||||||
|
|
||||||
|
GLuint m_fbBasePass;
|
||||||
GLuint m_fDiffuseTexture;
|
GLuint m_fDiffuseTexture;
|
||||||
GLuint m_fPositionTexture;
|
GLuint m_fPositionTexture;
|
||||||
GLuint m_fNormalsTexture;
|
GLuint m_fNormalsTexture;
|
||||||
GLuint m_fBlendTexture;
|
GLuint m_fBlendTexture;
|
||||||
GLuint m_fb;
|
GLuint m_fbLightingPass;
|
||||||
|
GLuint m_fLightingTexture;
|
||||||
|
|
||||||
GLuint m_fDepthBuffer;
|
GLuint m_fDepthBuffer;
|
||||||
GLenum draw_bufs[2];
|
GLenum draw_bufs[2];
|
||||||
glm::mat4 lM[5];
|
glm::mat4 lM[5];
|
||||||
@@ -110,12 +113,16 @@ private:
|
|||||||
ShaderProgram m_FirstPassProgram;
|
ShaderProgram m_FirstPassProgram;
|
||||||
ShaderProgram m_SecondPassProgram;
|
ShaderProgram m_SecondPassProgram;
|
||||||
ShaderProgram m_SecondPassProgram_Debug;
|
ShaderProgram m_SecondPassProgram_Debug;
|
||||||
|
ShaderProgram m_FinalPassProgram;
|
||||||
|
|
||||||
ShaderProgram m_ShaderProgramNormals;
|
ShaderProgram m_ShaderProgramNormals;
|
||||||
ShaderProgram m_ShaderProgramShadows;
|
ShaderProgram m_ShaderProgramShadows;
|
||||||
ShaderProgram m_ShaderProgramShadowsDrawDepth;
|
ShaderProgram m_ShaderProgramShadowsDrawDepth;
|
||||||
ShaderProgram m_ShaderProgramDebugAABB;
|
ShaderProgram m_ShaderProgramDebugAABB;
|
||||||
ShaderProgram m_ShaderProgramSkybox;
|
ShaderProgram m_ShaderProgramSkybox;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ClearStuff();
|
void ClearStuff();
|
||||||
void DrawScene();
|
void DrawScene();
|
||||||
void DrawModels(ShaderProgram &shader);
|
void DrawModels(ShaderProgram &shader);
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
#version 430
|
||||||
|
|
||||||
|
uniform vec3 La;
|
||||||
|
|
||||||
|
layout (binding=0) uniform sampler2D DiffuseTexture;
|
||||||
|
layout (binding=1) uniform sampler2D LightingTexture;
|
||||||
|
|
||||||
|
in VertexData
|
||||||
|
{
|
||||||
|
vec3 Position;
|
||||||
|
vec2 TextureCoord;
|
||||||
|
} Input;
|
||||||
|
|
||||||
|
out vec4 FragmentColor;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec4 DiffuseTexel = texture(DiffuseTexture, Input.TextureCoord);
|
||||||
|
vec4 LightingTexel = texture(LightingTexture, Input.TextureCoord);
|
||||||
|
|
||||||
|
FragmentColor = DiffuseTexel * vec4(La, 1.0) + LightingTexel;
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#version 430
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
@@ -19,7 +19,7 @@ void main()
|
|||||||
frag_Diffuse = texture2D(DiffuseTexture, Input.TextureCoord);
|
frag_Diffuse = texture2D(DiffuseTexture, Input.TextureCoord);
|
||||||
|
|
||||||
// G-buffer Position
|
// G-buffer Position
|
||||||
frag_Position = vec4(Input.Position.xy, 0.0, 0.0);
|
frag_Position = vec4(Input.Position.xyz, 0.0);
|
||||||
|
|
||||||
// G-buffer Normal
|
// G-buffer Normal
|
||||||
frag_Normal = vec4(Input.Normal, 0.0);
|
frag_Normal = vec4(Input.Normal, 0.0);
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ void main()
|
|||||||
//FragColor = texture2D(DiffuseTexture, Input.TextureCoord * 2 + vec2(0, -1));
|
//FragColor = texture2D(DiffuseTexture, Input.TextureCoord * 2 + vec2(0, -1));
|
||||||
DrawQuadrant(texture2D(DiffuseTexture, Input.TextureCoord * 2), vec2(-1, 1));
|
DrawQuadrant(texture2D(DiffuseTexture, Input.TextureCoord * 2), vec2(-1, 1));
|
||||||
DrawQuadrant(texture2D(PositionTexture, Input.TextureCoord * 2), vec2(1, 1));
|
DrawQuadrant(texture2D(PositionTexture, Input.TextureCoord * 2), vec2(1, 1));
|
||||||
DrawQuadrant((texture2D(NormalTexture, Input.TextureCoord * 2)+1)/2, vec2(-1, -1));
|
DrawQuadrant(texture2D(NormalTexture, Input.TextureCoord * 2), vec2(-1, -1));
|
||||||
|
|
||||||
vec4 AllTexel = texture2D(DiffuseTexture, Input.TextureCoord*2)*texture2D(PositionTexture, Input.TextureCoord*2)*texture2D(NormalTexture, Input.TextureCoord*2);
|
vec4 AllTexel = texture2D(DiffuseTexture, Input.TextureCoord*2)*texture2D(PositionTexture, Input.TextureCoord*2)*texture2D(NormalTexture, Input.TextureCoord*2);
|
||||||
DrawQuadrant(AllTexel, vec2(1, -1));
|
DrawQuadrant(AllTexel, vec2(1, -1));
|
||||||
|
|||||||
+45
-59
@@ -1,94 +1,80 @@
|
|||||||
#version 430
|
#version 430
|
||||||
|
|
||||||
layout (binding=0) uniform sampler2D DiffuseTexture;
|
layout (binding=0) uniform sampler2D PositionTexture;
|
||||||
layout (binding=1) uniform sampler2D PositionTexture;
|
layout (binding=1) uniform sampler2D NormalsTexture;
|
||||||
layout (binding=2) uniform sampler2D NormalTexture;
|
|
||||||
|
|
||||||
|
uniform vec2 ViewportSize;
|
||||||
uniform mat4 MVP;
|
uniform mat4 MVP;
|
||||||
uniform mat4 M;
|
uniform mat4 M;
|
||||||
uniform mat4 V;
|
uniform mat4 V;
|
||||||
uniform mat4 P;
|
uniform mat4 P;
|
||||||
|
uniform vec3 la;
|
||||||
uniform vec3 ls;
|
uniform vec3 ls;
|
||||||
uniform vec3 ld;
|
uniform vec3 ld;
|
||||||
uniform vec3 lp;
|
uniform vec3 lp;
|
||||||
const float specularExponent = 20.0;
|
uniform float LightRadius;
|
||||||
|
const float specularExponent = 50.0;
|
||||||
uniform vec3 CameraPosition;
|
uniform vec3 CameraPosition;
|
||||||
|
|
||||||
const vec3 kd = vec3(1.0, 1.0, 1.0);
|
const vec3 ks = vec3(1.0, 0.0, 0.0);
|
||||||
const vec3 ks = vec3(1.0, 1.0, 1.0);
|
const vec3 kd = vec3(0.8, 0.8, 0.8);
|
||||||
|
const vec3 ka = vec3(1.0, 1.0, 1.0);
|
||||||
const float kshine = 1.0;
|
const float kshine = 1.0;
|
||||||
|
|
||||||
in VertexData
|
in VertexData
|
||||||
{
|
{
|
||||||
vec3 Position;
|
vec3 Position;
|
||||||
vec3 Normal;
|
|
||||||
vec2 TextureCoord;
|
vec2 TextureCoord;
|
||||||
} Input;
|
} Input;
|
||||||
|
|
||||||
out vec4 FragColor;
|
out vec4 FragColor;
|
||||||
|
|
||||||
vec3 phong (vec3 PositionTexel, vec3 NormalTexel)
|
vec4 phong4(vec3 position, vec3 normal)
|
||||||
{
|
{
|
||||||
vec3 lightPosition = vec3( M * vec4( lp, 1.0 ) );
|
// Diffuse
|
||||||
vec3 distToLight = lightPosition - PositionTexel;
|
vec3 lightPos = vec3(V * vec4(lp, 1.0));
|
||||||
vec3 directionToLight = normalize(distToLight);
|
vec3 distanceToLight = lightPos - position;
|
||||||
|
vec3 directionToLight = normalize(distanceToLight);
|
||||||
|
float dotProd = dot(directionToLight, normal);
|
||||||
|
dotProd = max(dotProd, 0.0);
|
||||||
|
vec3 Id = kd * ld * dotProd;
|
||||||
|
|
||||||
//Diffuse light
|
// Specular
|
||||||
float dotProdDiffuse = max(dot(directionToLight, NormalTexel), 0.0);
|
//vec3 reflection = reflect(-directionToLight, normal);
|
||||||
vec3 Id = ld * kd * dotProdDiffuse; //Final diffuse intensity
|
vec3 surfaceToViewer = normalize(-position);
|
||||||
|
vec3 halfWay = normalize(surfaceToViewer + directionToLight);
|
||||||
//Specular light
|
float dotSpecular = max(dot(halfWay, normal), 0.0);
|
||||||
vec3 reflection = reflect(-directionToLight, NormalTexel);
|
float specularFactor = pow(dotSpecular, specularExponent * 2);
|
||||||
vec3 surfaceToCamera = normalize(PositionTexel);
|
vec3 Is = ks * ls * specularFactor;
|
||||||
vec3 HalfWay = normalize(surfaceToCamera + directionToLight);
|
|
||||||
float dotProdSpecular = dot(HalfWay, NormalTexel);
|
|
||||||
dotProdSpecular = max(dotProdSpecular, 0.0);
|
|
||||||
float specularFactor = pow(dotProdSpecular, specularExponent);
|
|
||||||
vec3 Is = ls * ks * specularFactor; //Final specular intensity
|
|
||||||
|
|
||||||
//Attenuation
|
//Attenuation
|
||||||
float dist2D = distance(lightPosition, PositionTexel);
|
float dist = distance(lightPos, position);
|
||||||
float attenuationFactor = -log(min(1.0, dist2D / 5.0));
|
float attenuation = -log(min(1.0, dist / LightRadius));
|
||||||
|
//float attenuation = 1.0 / (1.0 - 0.0001 * pow(dist, 2));
|
||||||
|
|
||||||
//vec3 FinalOut = (Id + Is) * attenuationFactor;
|
//float attenuation = clamp(0.0, 1.0, 1.0 / (0.001 + (0.001 * dist) + (0.001 * dist * dist)));
|
||||||
vec3 FinalOut = Id + Is;
|
|
||||||
return FinalOut;
|
//float attenuation = 1.0 / dot(directionToLight, directionToLight);
|
||||||
}
|
|
||||||
|
//float att_s = 5;
|
||||||
|
//float attenuation = pow(dist, 2) / pow(5.0, 2);
|
||||||
|
//attenuation = 1.0 / (1.0 + attenuation * att_s);
|
||||||
|
//att_s = 1.0 / (1.0 + att_s);
|
||||||
|
//attenuation = attenuation / (1.0 - att_s);
|
||||||
|
|
||||||
|
float radius = 5.0;
|
||||||
|
float alpha = dist / radius;
|
||||||
|
float dampingFactor = 1.0 - pow(alpha, 3);
|
||||||
|
|
||||||
|
|
||||||
vec3 phong2 (vec3 PositionTexel, vec3 NormalTexel)
|
return vec4((Id + Is) * attenuation, 1.0);
|
||||||
{
|
|
||||||
vec3 LightVector = lp - PositionTexel;
|
|
||||||
vec3 ViewVector = normalize(PositionTexel);
|
|
||||||
|
|
||||||
//diffuse
|
|
||||||
vec3 Id = max(0.0, dot(LightVector, NormalTexel)) * ld;
|
|
||||||
|
|
||||||
vec3 FinalOut = Id;
|
|
||||||
return FinalOut;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 phong3 (vec3 PositionTexel, vec3 NormalTexel)
|
|
||||||
{
|
|
||||||
vec3 lightDir = lp - PositionTexel;
|
|
||||||
lightDir = normalize(lightDir);
|
|
||||||
|
|
||||||
vec3 eyeDir = normalize(CameraPosition-PositionTexel);
|
|
||||||
vec3 vHalfVector = normalize(lightDir.xyz+eyeDir);
|
|
||||||
vec3 Id = max(0.0, dot(NormalTexel, lightDir)) * ld;
|
|
||||||
vec3 Is = pow(max(0.0, dot(NormalTexel, vHalfVector)), 100.0) * ls;
|
|
||||||
vec3 FinalFrag = Id + Is;
|
|
||||||
return FinalFrag;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 DiffuseTexel = texture2D(DiffuseTexture, Input.TextureCoord);
|
vec2 TextureCoord = gl_FragCoord.xy / ViewportSize;
|
||||||
vec4 PositionTexel = texture2D(PositionTexture, Input.TextureCoord);
|
vec4 PositionTexel = texture(PositionTexture, TextureCoord);
|
||||||
vec4 NormalTexel = texture2D(NormalTexture, Input.TextureCoord);
|
vec4 NormalTexel = texture(NormalsTexture, TextureCoord);
|
||||||
|
|
||||||
vec4 Frag_color;
|
FragColor = phong4(vec3(PositionTexel), vec3(NormalTexel));
|
||||||
Frag_color.rgb = phong((MVP * PositionTexel).rgb, normalize(NormalTexel).rgb);
|
|
||||||
Frag_color.a = 1.0;
|
|
||||||
FragColor = Frag_color * DiffuseTexel;
|
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
#version 430
|
#version 430
|
||||||
|
|
||||||
uniform mat4 MVP;
|
uniform mat4 MVP;
|
||||||
uniform mat4 ModelMatrix;
|
uniform mat4 M;
|
||||||
|
uniform mat4 V;
|
||||||
|
uniform mat4 P;
|
||||||
|
|
||||||
layout (location = 0) in vec3 Position;
|
layout (location = 0) in vec3 Position;
|
||||||
layout (location = 1) in vec3 Normal;
|
layout (location = 1) in vec3 Normal;
|
||||||
@@ -18,7 +20,7 @@ void main()
|
|||||||
{
|
{
|
||||||
gl_Position = MVP * vec4(Position, 1.0);
|
gl_Position = MVP * vec4(Position, 1.0);
|
||||||
|
|
||||||
Output.Position = gl_Position.xyz;
|
Output.Position = vec3(V * M * vec4(Position, 1.0));
|
||||||
Output.Normal = normalize((ModelMatrix * vec4(Normal, 0.0)).xyz);
|
Output.Normal = normalize(vec3(inverse(transpose(V * M)) * vec4(Normal, 0.0)));
|
||||||
Output.TextureCoord = TextureCoord;
|
Output.TextureCoord = TextureCoord;
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
#version 430
|
#version 430
|
||||||
|
|
||||||
|
uniform mat4 MVP;
|
||||||
|
|
||||||
layout (location = 0) in vec3 Position;
|
layout (location = 0) in vec3 Position;
|
||||||
layout (location = 2) in vec2 TextureCoord;
|
layout (location = 2) in vec2 TextureCoord;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
out VertexData
|
out VertexData
|
||||||
{
|
{
|
||||||
vec3 Position;
|
vec3 Position;
|
||||||
@@ -13,7 +13,7 @@ out VertexData
|
|||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = vec4(Position, 1.0);
|
gl_Position = MVP * vec4(Position, 1.0);
|
||||||
Output.Position = Position;
|
Output.Position = Position;
|
||||||
Output.TextureCoord = TextureCoord;
|
Output.TextureCoord = (vec2(Position) + 1) / 2;
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,4 @@ Global
|
|||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(Performance) = preSolution
|
|
||||||
HasPerformanceSessions = true
|
|
||||||
EndGlobalSection
|
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|||||||
@@ -167,6 +167,8 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="..\..\src\Shaders\AABB.frag.glsl" />
|
<None Include="..\..\src\Shaders\AABB.frag.glsl" />
|
||||||
|
<None Include="..\..\src\Shaders\FinalPass.frag.glsl" />
|
||||||
|
<None Include="..\..\src\Shaders\FinalPass.vert.glsl" />
|
||||||
<None Include="..\..\src\Shaders\Fragment.glsl" />
|
<None Include="..\..\src\Shaders\Fragment.glsl" />
|
||||||
<None Include="..\..\src\Shaders\Fragment2-Debug.glsl" />
|
<None Include="..\..\src\Shaders\Fragment2-Debug.glsl" />
|
||||||
<None Include="..\..\src\Shaders\Fragment2.glsl" />
|
<None Include="..\..\src\Shaders\Fragment2.glsl" />
|
||||||
|
|||||||
@@ -271,5 +271,11 @@
|
|||||||
<None Include="..\..\src\Shaders\Fragment2-Debug.glsl">
|
<None Include="..\..\src\Shaders\Fragment2-Debug.glsl">
|
||||||
<Filter>Shaders</Filter>
|
<Filter>Shaders</Filter>
|
||||||
</None>
|
</None>
|
||||||
|
<None Include="..\..\src\Shaders\FinalPass.vert.glsl">
|
||||||
|
<Filter>Shaders</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="..\..\src\Shaders\FinalPass.frag.glsl">
|
||||||
|
<Filter>Shaders</Filter>
|
||||||
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
Reference in New Issue
Block a user