Work done on light and shadows.
This commit is contained in:
+1
-1
Submodule assets updated: 836ffcb9de...21182efb93
+14
-12
@@ -33,6 +33,19 @@ void GameWorld::Initialize()
|
|||||||
CommitEntity(ground);
|
CommitEntity(ground);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(int i = 15; i < 200; i++)
|
||||||
|
{
|
||||||
|
auto Light = CreateEntity();
|
||||||
|
auto transform = AddComponent<Components::Transform>(Light, "Transform");
|
||||||
|
transform->Position = glm::vec3((5+(i/2.f))*cos(i/5.0f), 3.f, (5+(i/2.f))*sin(i/5.0f));
|
||||||
|
auto light = AddComponent<Components::PointLight>(Light, "PointLight");
|
||||||
|
light->Specular = glm::vec3(0.5f, 0.5f, 0.5f);
|
||||||
|
light->Diffuse = glm::vec3(0.5f, 0.5f, 0.5f);
|
||||||
|
light->Radius = 15.f;
|
||||||
|
light->specularExponent = 100.f;
|
||||||
|
auto model = AddComponent<Components::Model>(Light, "Model");
|
||||||
|
model->ModelFile = "Models/Placeholders/PhysicsTest/PointLight.obj";
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
auto jeep = CreateEntity();
|
auto jeep = CreateEntity();
|
||||||
@@ -49,18 +62,7 @@ void GameWorld::Initialize()
|
|||||||
|
|
||||||
AddComponent<Components::Input>(jeep, "Input");
|
AddComponent<Components::Input>(jeep, "Input");
|
||||||
|
|
||||||
for(int i = 0; i < 1; i++)
|
|
||||||
{
|
|
||||||
auto Light = CreateEntity(jeep);
|
|
||||||
auto transform = AddComponent<Components::Transform>(Light, "Transform");
|
|
||||||
transform->Position = glm::vec3((5+(i/2.f))*cos(i/5.0f), 0.3f, 0 + (5+(i/5.f))*sin(i/2.0f));
|
|
||||||
auto light = AddComponent<Components::PointLight>(Light, "PointLight");
|
|
||||||
light->Specular = glm::vec3(1.0f, 1.0f, 1.0f);
|
|
||||||
light->Diffuse = glm::vec3(1.0f, 1.0f, 1.0f);
|
|
||||||
light->Radius = 150.f;
|
|
||||||
auto model = AddComponent<Components::Model>(Light, "Model");
|
|
||||||
model->ModelFile = "Models/Placeholders/PhysicsTest/PointLight.obj";
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
auto camera = CreateEntity();
|
auto camera = CreateEntity();
|
||||||
|
|||||||
+21
-6
@@ -48,6 +48,21 @@ Model::Model(OBJ &obj, ResourceManager* rm)
|
|||||||
currentTexGroup = &TextureGroups.back();
|
currentTexGroup = &TextureGroups.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*std::unordered_map<int, glm::vec3> similarNormals;
|
||||||
|
std::unordered_map<int, int> normalCount;
|
||||||
|
for (auto &faceDef : face.Definitions)
|
||||||
|
{
|
||||||
|
if (faceDef.NormalIndex == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
|
||||||
|
similarNormals[faceDef.VertexIndex - 1] += normal;
|
||||||
|
normalCount[faceDef.VertexIndex - 1]++;
|
||||||
|
int index = pair.first;
|
||||||
|
glm::vec3 averagedNormal = ;
|
||||||
|
Normals[]
|
||||||
|
}*/
|
||||||
|
|
||||||
// Face definitions
|
// Face definitions
|
||||||
for (auto faceDef : face.Definitions)
|
for (auto faceDef : face.Definitions)
|
||||||
{
|
{
|
||||||
@@ -190,7 +205,7 @@ void Model::CreateBuffers( std::vector<glm::vec3> vertices, std::vector<glm::vec
|
|||||||
|
|
||||||
bool Model::IsNear( float v1, float v2 )
|
bool Model::IsNear( float v1, float v2 )
|
||||||
{
|
{
|
||||||
return fabs(v1 - v2) < 0.01f;
|
return fabs(v1 - v2) < 0.001f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Model::getSimilarVertexIndex()
|
void Model::getSimilarVertexIndex()
|
||||||
@@ -202,15 +217,15 @@ void Model::getSimilarVertexIndex()
|
|||||||
if(i != t)
|
if(i != t)
|
||||||
{
|
{
|
||||||
if(IsNear(Vertices[i].x, Vertices[t].x)
|
if(IsNear(Vertices[i].x, Vertices[t].x)
|
||||||
& IsNear(Vertices[i].y, Vertices[t].y)
|
&& IsNear(Vertices[i].y, Vertices[t].y)
|
||||||
& IsNear(Vertices[i].z, Vertices[t].z)
|
&& IsNear(Vertices[i].z, Vertices[t].z)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
glm::vec3 tempNormal, tempTangent, tempBiTangent;
|
glm::vec3 tempNormal, tempTangent, tempBiTangent;
|
||||||
|
|
||||||
tempNormal = glm::normalize(Normals[i] + Normals[t]);
|
tempNormal = Normals[i] + Normals[t];
|
||||||
tempTangent = glm::normalize(TangentNormals[i] + TangentNormals[t]);
|
tempTangent = TangentNormals[i] + TangentNormals[t];
|
||||||
tempBiTangent = glm::normalize(BiTangentNormals[i] + BiTangentNormals[t]);
|
tempBiTangent = BiTangentNormals[i] + BiTangentNormals[t];
|
||||||
|
|
||||||
Normals[i] = tempNormal;
|
Normals[i] = tempNormal;
|
||||||
Normals[t] = tempNormal;
|
Normals[t] = tempNormal;
|
||||||
|
|||||||
+8
-8
@@ -13,14 +13,14 @@ Renderer::Renderer()
|
|||||||
m_DrawWireframe = false;
|
m_DrawWireframe = false;
|
||||||
m_DrawBounds = false;
|
m_DrawBounds = false;
|
||||||
#endif
|
#endif
|
||||||
Gamma = 2.2f;
|
Gamma = 0.85f;
|
||||||
CAtt = 1.0f;
|
CAtt = 1.0f;
|
||||||
LAtt = 0.0f;
|
LAtt = 0.0f;
|
||||||
QAtt = 3.0f;
|
QAtt = 3.0f;
|
||||||
m_ShadowMapRes = 2048*6;
|
m_ShadowMapRes = 2048*6;
|
||||||
m_SunPosition = glm::vec3(0, 3.5f, 10);
|
m_SunPosition = glm::vec3(3.f, 5.f, 3.f);
|
||||||
m_SunTarget = glm::vec3(0, 0, 0);
|
m_SunTarget = glm::vec3(0, 0, 0);
|
||||||
m_SunProjection = glm::ortho<float>(10.f, -10.f, 10.f, -10.f, 10.f, -10.f);
|
m_SunProjection = glm::ortho<float>(200.f, -200.f, 200.f, -200.f, -100.f, 100.f);
|
||||||
/* Lights = 0;*/
|
/* Lights = 0;*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -529,7 +529,7 @@ void Renderer::FrameBufferTextures()
|
|||||||
//Generate and bind diffuse texture
|
//Generate and bind diffuse texture
|
||||||
glGenTextures(1, &m_fDiffuseTexture);
|
glGenTextures(1, &m_fDiffuseTexture);
|
||||||
glBindTexture(GL_TEXTURE_2D, m_fDiffuseTexture);
|
glBindTexture(GL_TEXTURE_2D, m_fDiffuseTexture);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, WIDTH, HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, 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);
|
||||||
@@ -547,7 +547,7 @@ 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_RGB, WIDTH, HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, WIDTH, HEIGHT, 0, GL_RGB, 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);
|
||||||
@@ -593,7 +593,7 @@ void Renderer::FrameBufferTextures()
|
|||||||
|
|
||||||
glGenTextures(1, &m_fLightingTexture);
|
glGenTextures(1, &m_fLightingTexture);
|
||||||
glBindTexture(GL_TEXTURE_2D, m_fLightingTexture);
|
glBindTexture(GL_TEXTURE_2D, m_fLightingTexture);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, WIDTH, HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, 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);
|
||||||
@@ -625,7 +625,7 @@ void Renderer::DrawFBO()
|
|||||||
// Clear G-buffer
|
// Clear G-buffer
|
||||||
GLenum windowBuffClear[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 };
|
GLenum windowBuffClear[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 };
|
||||||
glDrawBuffers(4, windowBuffClear);
|
glDrawBuffers(4, windowBuffClear);
|
||||||
glClearColor(0.5f, 0.f, 0.f, 0.f);
|
glClearColor(0.0f, 0.3f, 0.7f, 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(??)
|
||||||
@@ -668,7 +668,7 @@ void Renderer::DrawFBO()
|
|||||||
m_FinalPassProgram.Bind();
|
m_FinalPassProgram.Bind();
|
||||||
|
|
||||||
// Ambient light
|
// Ambient light
|
||||||
glUniform3fv(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "La"), 1, glm::value_ptr(glm::vec3(0.4f, 0.4f, 0.4f)));
|
glUniform3fv(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "La"), 1, glm::value_ptr(glm::vec3(0.7f)));
|
||||||
glUniform1f(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "Gamma"), Gamma);
|
glUniform1f(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "Gamma"), Gamma);
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ void main()
|
|||||||
vec4 LightingTexel = texture(LightingTexture, Input.TextureCoord);
|
vec4 LightingTexel = texture(LightingTexture, Input.TextureCoord);
|
||||||
vec4 ShadowTexel = texture(ShadowTexture, Input.TextureCoord);
|
vec4 ShadowTexel = texture(ShadowTexture, Input.TextureCoord);
|
||||||
|
|
||||||
//FragmentColor = DiffuseTexel;
|
//FragmentColor = LightingTexel;
|
||||||
|
|
||||||
FragmentColor = DiffuseTexel * (LightingTexel + vec4(La, 0.0));
|
FragmentColor = DiffuseTexel * (vec4(La, 0.0) + vec4(LightingTexel.rgb, 0.0)) + vec4(LightingTexel.a, LightingTexel.a, LightingTexel.a, 0.0);
|
||||||
//FragmentColor = vec4(pow(_FragmentColor.rgb, vec3(1.0 / Gamma)), _FragmentColor.a);
|
//FragmentColor = vec4(pow(_FragmentColor.rgb, vec3(1.0 / Gamma)), _FragmentColor.a);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ float Shadow(vec4 ShadowCoord)
|
|||||||
bias = clamp(bias, 0.0, 0.01);
|
bias = clamp(bias, 0.0, 0.01);
|
||||||
if( texture(ShadowTexture, Input.ShadowCoord.xy).z < ShadowCoord.z - bias)
|
if( texture(ShadowTexture, Input.ShadowCoord.xy).z < ShadowCoord.z - bias)
|
||||||
{
|
{
|
||||||
return 0.3;
|
return 0.6;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -54,29 +54,10 @@ vec4 phong(vec3 position, vec3 normal, vec3 specular)
|
|||||||
|
|
||||||
//Attenuation
|
//Attenuation
|
||||||
float dist = distance(lightPos, position);
|
float dist = distance(lightPos, position);
|
||||||
//float attenuation = -log(min(1.0, dist / LightRadius));
|
|
||||||
|
|
||||||
//float attenuation = 1.0 / (ConstantAttenuation + (LinearAttenuation * dist) + (QuadraticAttenuation * dist * dist));
|
|
||||||
|
|
||||||
float attenuation = pow(max(0.0f, 1.0 - (dist / LightRadius)), 2);
|
float attenuation = pow(max(0.0f, 1.0 - (dist / LightRadius)), 2);
|
||||||
|
|
||||||
//float attenuation = 1.0 / (1.0 - 0.0001 * pow(dist, 2));
|
return vec4((Id) * attenuation, Is.r * attenuation);
|
||||||
|
|
||||||
//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);
|
|
||||||
|
|
||||||
return vec4((Id + Is) * attenuation, 1.0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
@@ -86,6 +67,6 @@ void main()
|
|||||||
vec4 NormalTexel = texture(NormalsTexture, TextureCoord);
|
vec4 NormalTexel = texture(NormalsTexture, TextureCoord);
|
||||||
vec4 SpecularTexel = texture(SpecularTexture, TextureCoord);
|
vec4 SpecularTexel = texture(SpecularTexture, TextureCoord);
|
||||||
|
|
||||||
FragColor = phong(vec3(PositionTexel), vec3(NormalTexel), vec3(SpecularTexel))+vec4(0.1f);
|
FragColor = phong(vec3(PositionTexel), vec3(NormalTexel), vec3(SpecularTexel));
|
||||||
//FragColor = NormalTexel;
|
//FragColor = NormalTexel;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user