Defucked defucked rendering
This commit is contained in:
+3
-3
@@ -230,8 +230,8 @@ void GameWorld::Initialize()
|
||||
auto transform = AddComponent<Components::Transform>(Light, "Transform");
|
||||
transform->Position = glm::vec3(20+ 10*cos(i), 3, 0 + 10*sin(i));
|
||||
auto light = AddComponent<Components::PointLight>(Light, "PointLight");
|
||||
light->Diffuse = glm::vec3(94.f/255.f, 227.f/255.f, 230.f/255.f);
|
||||
light->Specular = 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(1.0f, 1.0f, 1.0f);
|
||||
light->specularExponent = 1.0f;
|
||||
auto model = AddComponent<Components::Model>(Light, "Model");
|
||||
model->ModelFile = "Models/Placeholders/PhysicsTest/PointLight.obj";
|
||||
@@ -243,7 +243,7 @@ void GameWorld::Initialize()
|
||||
auto cube = CreateEntity();
|
||||
auto transform = AddComponent<Components::Transform>(cube, "Transform");
|
||||
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));
|
||||
auto model = AddComponent<Components::Model>(cube, "Model");
|
||||
model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj";
|
||||
|
||||
+93
-37
@@ -128,6 +128,11 @@ void Renderer::LoadContent()
|
||||
m_SecondPassProgram_Debug.Compile();
|
||||
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();
|
||||
|
||||
FrameBufferTextures();
|
||||
@@ -532,10 +537,10 @@ void Renderer::ClearStuff()
|
||||
|
||||
void Renderer::FrameBufferTextures()
|
||||
{
|
||||
m_fb = 0;
|
||||
m_fbBasePass = 0;
|
||||
m_fDepthBuffer = 0;
|
||||
|
||||
glGenFramebuffers(1, &m_fb);
|
||||
glGenFramebuffers(1, &m_fbBasePass);
|
||||
glGenRenderbuffers(1, &m_fDepthBuffer);
|
||||
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, m_fDepthBuffer);
|
||||
@@ -562,14 +567,14 @@ void Renderer::FrameBufferTextures()
|
||||
//Generate and bind normal texture
|
||||
glGenTextures(1, &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_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
|
||||
//Bind fb
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_fb);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_fbBasePass);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_fDepthBuffer);
|
||||
|
||||
//Attach textures to the FB
|
||||
@@ -583,6 +588,29 @@ void Renderer::FrameBufferTextures()
|
||||
LOG_ERROR("DeferredLighting:Init: FrameBuffer incomplete: 0x%x\n", fbStatus);
|
||||
//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()
|
||||
@@ -654,12 +682,15 @@ void Renderer::FrameBufferTextures()
|
||||
|
||||
void Renderer::DrawFBO()
|
||||
{
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fb);
|
||||
/*
|
||||
Base pass
|
||||
*/
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbBasePass);
|
||||
|
||||
// Clear G-buffer
|
||||
GLenum windowBuffClear[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 };
|
||||
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);
|
||||
|
||||
// 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 };
|
||||
glDrawBuffers(3, windowBuffOpaque);
|
||||
|
||||
glCullFace(GL_BACK);
|
||||
DrawFBOScene();
|
||||
|
||||
// Draw to screen
|
||||
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);
|
||||
/*
|
||||
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_fDiffuseTexture);
|
||||
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, m_fPositionTexture);
|
||||
|
||||
glActiveTexture(GL_TEXTURE2);
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, m_fNormalsTexture);
|
||||
|
||||
glCullFace(GL_FRONT);
|
||||
DrawLightScene();
|
||||
|
||||
/*
|
||||
Final pass
|
||||
*/
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||
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);
|
||||
glBindTexture(GL_TEXTURE_2D, m_fDiffuseTexture);
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, m_fLightingTexture);
|
||||
|
||||
glCullFace(GL_BACK);
|
||||
glBindVertexArray(m_ScreenQuad);
|
||||
glEnableVertexAttribArray(0);
|
||||
glEnableVertexAttribArray(2);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
}
|
||||
|
||||
@@ -774,7 +824,9 @@ void Renderer::DrawFBOScene()
|
||||
|
||||
MVP = cameraMatrix * modelMatrix;
|
||||
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);
|
||||
for (auto texGroup : model->TextureGroups)
|
||||
{
|
||||
@@ -792,7 +844,7 @@ void Renderer::DrawLightScene()
|
||||
glEnable(GL_BLEND);
|
||||
glBlendEquation (GL_FUNC_ADD);
|
||||
glBlendFunc(GL_ONE,GL_ONE);
|
||||
|
||||
|
||||
glDisable (GL_DEPTH_TEST);
|
||||
glDepthMask (GL_FALSE);
|
||||
glBindVertexArray(m_sphereModel->VAO);
|
||||
@@ -802,15 +854,18 @@ void Renderer::DrawLightScene()
|
||||
|
||||
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));
|
||||
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()));
|
||||
glUniform2fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ViewportSize"), 1,glm::value_ptr(glm::vec2(WIDTH, HEIGHT)));
|
||||
glUniformMatrix4fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
||||
glUniformMatrix4fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(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]));
|
||||
glUniform3f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ls"), Light_specular[i].x, Light_specular[i].y, Light_specular[i].z);
|
||||
glUniform3f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ld"), Light_diffuse[i].x, Light_diffuse[i].y, Light_diffuse[i].z);
|
||||
glUniform3f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "lp"), Light_position[i].x, Light_position[i].y, Light_position[i].z);
|
||||
glUniform3fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "la"), 1, glm::value_ptr(glm::vec3(0.3f, 0.3f, 0.3f)));
|
||||
glUniform3fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ls"), 1, glm::value_ptr(Light_specular[i]));
|
||||
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);
|
||||
//glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "speculatExponent"), Light_specularExponent[i]);
|
||||
glDrawArrays(GL_TRIANGLES, 0, m_sphereModel->Vertices.size());
|
||||
@@ -829,10 +884,11 @@ void Renderer::CreateLightMatrix()
|
||||
{
|
||||
for(int i = 0; i < Lights; i++)
|
||||
{
|
||||
const float radius = 5.0f;
|
||||
lM[i] = glm::scale(glm::mat4(1.0), glm::vec3(radius, radius, radius));
|
||||
lM[i] = glm::translate(lM[i], Light_position[i]);
|
||||
lM[i] = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix() * lM[i];
|
||||
const float scale = 10.0f;
|
||||
glm::mat4 model;
|
||||
model *= glm::translate(Light_position[i]);
|
||||
model *= glm::scale(glm::vec3(scale));
|
||||
lM[i] = model;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+8
-1
@@ -91,11 +91,14 @@ private:
|
||||
GLuint m_ShadowFrameBuffer;
|
||||
GLuint m_ShadowDepthTexture;
|
||||
|
||||
GLuint m_fbBasePass;
|
||||
GLuint m_fDiffuseTexture;
|
||||
GLuint m_fPositionTexture;
|
||||
GLuint m_fNormalsTexture;
|
||||
GLuint m_fBlendTexture;
|
||||
GLuint m_fb;
|
||||
GLuint m_fbLightingPass;
|
||||
GLuint m_fLightingTexture;
|
||||
|
||||
GLuint m_fDepthBuffer;
|
||||
GLenum draw_bufs[2];
|
||||
glm::mat4 lM[5];
|
||||
@@ -110,12 +113,16 @@ private:
|
||||
ShaderProgram m_FirstPassProgram;
|
||||
ShaderProgram m_SecondPassProgram;
|
||||
ShaderProgram m_SecondPassProgram_Debug;
|
||||
ShaderProgram m_FinalPassProgram;
|
||||
|
||||
ShaderProgram m_ShaderProgramNormals;
|
||||
ShaderProgram m_ShaderProgramShadows;
|
||||
ShaderProgram m_ShaderProgramShadowsDrawDepth;
|
||||
ShaderProgram m_ShaderProgramDebugAABB;
|
||||
ShaderProgram m_ShaderProgramSkybox;
|
||||
|
||||
|
||||
|
||||
void ClearStuff();
|
||||
void DrawScene();
|
||||
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);
|
||||
|
||||
// G-buffer Position
|
||||
frag_Position = vec4(Input.Position.xy, 0.0, 0.0);
|
||||
frag_Position = vec4(Input.Position.xyz, 0.0);
|
||||
|
||||
// G-buffer Normal
|
||||
frag_Normal = vec4(Input.Normal, 0.0);
|
||||
|
||||
@@ -30,7 +30,7 @@ void main()
|
||||
//FragColor = texture2D(DiffuseTexture, Input.TextureCoord * 2 + vec2(0, -1));
|
||||
DrawQuadrant(texture2D(DiffuseTexture, 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);
|
||||
DrawQuadrant(AllTexel, vec2(1, -1));
|
||||
|
||||
+46
-60
@@ -1,94 +1,80 @@
|
||||
#version 430
|
||||
|
||||
layout (binding=0) uniform sampler2D DiffuseTexture;
|
||||
layout (binding=1) uniform sampler2D PositionTexture;
|
||||
layout (binding=2) uniform sampler2D NormalTexture;
|
||||
layout (binding=0) uniform sampler2D PositionTexture;
|
||||
layout (binding=1) uniform sampler2D NormalsTexture;
|
||||
|
||||
uniform vec2 ViewportSize;
|
||||
uniform mat4 MVP;
|
||||
uniform mat4 M;
|
||||
uniform mat4 V;
|
||||
uniform mat4 P;
|
||||
uniform vec3 la;
|
||||
uniform vec3 ls;
|
||||
uniform vec3 ld;
|
||||
uniform vec3 lp;
|
||||
const float specularExponent = 20.0;
|
||||
uniform vec3 lp;
|
||||
uniform float LightRadius;
|
||||
const float specularExponent = 50.0;
|
||||
uniform vec3 CameraPosition;
|
||||
|
||||
const vec3 kd = vec3(1.0, 1.0, 1.0);
|
||||
const vec3 ks = vec3(1.0, 1.0, 1.0);
|
||||
const vec3 ks = vec3(1.0, 0.0, 0.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;
|
||||
|
||||
in VertexData
|
||||
{
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
vec2 TextureCoord;
|
||||
} Input;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
vec3 phong (vec3 PositionTexel, vec3 NormalTexel)
|
||||
vec4 phong4(vec3 position, vec3 normal)
|
||||
{
|
||||
vec3 lightPosition = vec3( M * vec4( lp, 1.0 ) );
|
||||
vec3 distToLight = lightPosition - PositionTexel;
|
||||
vec3 directionToLight = normalize(distToLight);
|
||||
// Diffuse
|
||||
vec3 lightPos = vec3(V * vec4(lp, 1.0));
|
||||
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
|
||||
float dotProdDiffuse = max(dot(directionToLight, NormalTexel), 0.0);
|
||||
vec3 Id = ld * kd * dotProdDiffuse; //Final diffuse intensity
|
||||
|
||||
//Specular light
|
||||
vec3 reflection = reflect(-directionToLight, NormalTexel);
|
||||
vec3 surfaceToCamera = normalize(PositionTexel);
|
||||
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
|
||||
// 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 * 2);
|
||||
vec3 Is = ks * ls * specularFactor;
|
||||
|
||||
//Attenuation
|
||||
float dist2D = distance(lightPosition, PositionTexel);
|
||||
float attenuationFactor = -log(min(1.0, dist2D / 5.0));
|
||||
float dist = distance(lightPos, position);
|
||||
float attenuation = -log(min(1.0, dist / LightRadius));
|
||||
//float attenuation = 1.0 / (1.0 - 0.0001 * pow(dist, 2));
|
||||
|
||||
//vec3 FinalOut = (Id + Is) * attenuationFactor;
|
||||
vec3 FinalOut = Id + Is;
|
||||
return FinalOut;
|
||||
}
|
||||
//float attenuation = clamp(0.0, 1.0, 1.0 / (0.001 + (0.001 * dist) + (0.001 * dist * dist)));
|
||||
|
||||
//float attenuation = 1.0 / dot(directionToLight, directionToLight);
|
||||
|
||||
//float att_s = 5;
|
||||
//float attenuation = pow(dist, 2) / pow(5.0, 2);
|
||||
//attenuation = 1.0 / (1.0 + attenuation * att_s);
|
||||
//att_s = 1.0 / (1.0 + att_s);
|
||||
//attenuation = attenuation / (1.0 - att_s);
|
||||
|
||||
float radius = 5.0;
|
||||
float alpha = dist / radius;
|
||||
float dampingFactor = 1.0 - pow(alpha, 3);
|
||||
|
||||
|
||||
vec3 phong2 (vec3 PositionTexel, vec3 NormalTexel)
|
||||
{
|
||||
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;
|
||||
return vec4((Id + Is) * attenuation, 1.0);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 DiffuseTexel = texture2D(DiffuseTexture, Input.TextureCoord);
|
||||
vec4 PositionTexel = texture2D(PositionTexture, Input.TextureCoord);
|
||||
vec4 NormalTexel = texture2D(NormalTexture, Input.TextureCoord);
|
||||
vec2 TextureCoord = gl_FragCoord.xy / ViewportSize;
|
||||
vec4 PositionTexel = texture(PositionTexture, TextureCoord);
|
||||
vec4 NormalTexel = texture(NormalsTexture, TextureCoord);
|
||||
|
||||
vec4 Frag_color;
|
||||
Frag_color.rgb = phong((MVP * PositionTexel).rgb, normalize(NormalTexel).rgb);
|
||||
Frag_color.a = 1.0;
|
||||
FragColor = Frag_color * DiffuseTexel;
|
||||
FragColor = phong4(vec3(PositionTexel), vec3(NormalTexel));
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
#version 430
|
||||
|
||||
uniform mat4 MVP;
|
||||
uniform mat4 ModelMatrix;
|
||||
uniform mat4 M;
|
||||
uniform mat4 V;
|
||||
uniform mat4 P;
|
||||
|
||||
layout (location = 0) in vec3 Position;
|
||||
layout (location = 1) in vec3 Normal;
|
||||
@@ -18,7 +20,7 @@ void main()
|
||||
{
|
||||
gl_Position = MVP * vec4(Position, 1.0);
|
||||
|
||||
Output.Position = gl_Position.xyz;
|
||||
Output.Normal = normalize((ModelMatrix * vec4(Normal, 0.0)).xyz);
|
||||
Output.Position = vec3(V * M * vec4(Position, 1.0));
|
||||
Output.Normal = normalize(vec3(inverse(transpose(V * M)) * vec4(Normal, 0.0)));
|
||||
Output.TextureCoord = TextureCoord;
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
#version 430
|
||||
|
||||
uniform mat4 MVP;
|
||||
|
||||
layout (location = 0) in vec3 Position;
|
||||
layout (location = 2) in vec2 TextureCoord;
|
||||
|
||||
|
||||
|
||||
out VertexData
|
||||
{
|
||||
vec3 Position;
|
||||
@@ -13,7 +13,7 @@ out VertexData
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(Position, 1.0);
|
||||
gl_Position = MVP * vec4(Position, 1.0);
|
||||
Output.Position = Position;
|
||||
Output.TextureCoord = TextureCoord;
|
||||
Output.TextureCoord = (vec2(Position) + 1) / 2;
|
||||
}
|
||||
@@ -39,7 +39,4 @@ Global
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(Performance) = preSolution
|
||||
HasPerformanceSessions = true
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
@@ -167,6 +167,8 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<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\Fragment2-Debug.glsl" />
|
||||
<None Include="..\..\src\Shaders\Fragment2.glsl" />
|
||||
|
||||
@@ -271,5 +271,11 @@
|
||||
<None Include="..\..\src\Shaders\Fragment2-Debug.glsl">
|
||||
<Filter>Shaders</Filter>
|
||||
</None>
|
||||
<None Include="..\..\src\Shaders\FinalPass.vert.glsl">
|
||||
<Filter>Shaders</Filter>
|
||||
</None>
|
||||
<None Include="..\..\src\Shaders\FinalPass.frag.glsl">
|
||||
<Filter>Shaders</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user