Work done on light and shadows.

This commit is contained in:
Tleety
2014-05-21 16:51:05 +02:00
parent e414087816
commit dbad1ee7f5
7 changed files with 49 additions and 51 deletions
+1 -1
Submodule assets updated: 836ffcb9de...21182efb93
+14 -12
View File
@@ -33,6 +33,19 @@ void GameWorld::Initialize()
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();
@@ -49,18 +62,7 @@ void GameWorld::Initialize()
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();
+21 -6
View File
@@ -48,6 +48,21 @@ Model::Model(OBJ &obj, ResourceManager* rm)
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
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 )
{
return fabs(v1 - v2) < 0.01f;
return fabs(v1 - v2) < 0.001f;
}
void Model::getSimilarVertexIndex()
@@ -202,15 +217,15 @@ void Model::getSimilarVertexIndex()
if(i != t)
{
if(IsNear(Vertices[i].x, Vertices[t].x)
& IsNear(Vertices[i].y, Vertices[t].y)
& IsNear(Vertices[i].z, Vertices[t].z)
&& IsNear(Vertices[i].y, Vertices[t].y)
&& IsNear(Vertices[i].z, Vertices[t].z)
)
{
glm::vec3 tempNormal, tempTangent, tempBiTangent;
tempNormal = glm::normalize(Normals[i] + Normals[t]);
tempTangent = glm::normalize(TangentNormals[i] + TangentNormals[t]);
tempBiTangent = glm::normalize(BiTangentNormals[i] + BiTangentNormals[t]);
tempNormal = Normals[i] + Normals[t];
tempTangent = TangentNormals[i] + TangentNormals[t];
tempBiTangent = BiTangentNormals[i] + BiTangentNormals[t];
Normals[i] = tempNormal;
Normals[t] = tempNormal;
+8 -8
View File
@@ -13,14 +13,14 @@ Renderer::Renderer()
m_DrawWireframe = false;
m_DrawBounds = false;
#endif
Gamma = 2.2f;
Gamma = 0.85f;
CAtt = 1.0f;
LAtt = 0.0f;
QAtt = 3.0f;
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_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;*/
}
@@ -529,7 +529,7 @@ void Renderer::FrameBufferTextures()
//Generate and bind diffuse texture
glGenTextures(1, &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_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
@@ -547,7 +547,7 @@ void Renderer::FrameBufferTextures()
//Generate and bind normal texture
glGenTextures(1, &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_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
@@ -593,7 +593,7 @@ void Renderer::FrameBufferTextures()
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);
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_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
@@ -625,7 +625,7 @@ void Renderer::DrawFBO()
// Clear G-buffer
GLenum windowBuffClear[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 };
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);
// Execute the first render stage which will fill out the internal buffers with data(??)
@@ -668,7 +668,7 @@ void Renderer::DrawFBO()
m_FinalPassProgram.Bind();
// 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);
glActiveTexture(GL_TEXTURE0);
+2 -2
View File
@@ -21,9 +21,9 @@ void main()
vec4 LightingTexel = texture(LightingTexture, 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);
+1 -1
View File
@@ -28,7 +28,7 @@ float Shadow(vec4 ShadowCoord)
bias = clamp(bias, 0.0, 0.01);
if( texture(ShadowTexture, Input.ShadowCoord.xy).z < ShadowCoord.z - bias)
{
return 0.3;
return 0.6;
}
else
{
+2 -21
View File
@@ -54,29 +54,10 @@ vec4 phong(vec3 position, vec3 normal, vec3 specular)
//Attenuation
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 = 1.0 / (1.0 - 0.0001 * pow(dist, 2));
//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);
return vec4((Id) * attenuation, Is.r * attenuation);
}
void main()
@@ -86,6 +67,6 @@ void main()
vec4 NormalTexel = texture(NormalsTexture, 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;
}