Some work done on lights and normals and other buggs/fixes
This commit is contained in:
+1
-1
Submodule assets updated: cdee701579...836ffcb9de
@@ -16,9 +16,11 @@ struct PointLight : Component
|
|||||||
, ConstantAttenuation(1.0f)
|
, ConstantAttenuation(1.0f)
|
||||||
, LinearAttenuation(0.f)
|
, LinearAttenuation(0.f)
|
||||||
, QuadraticAttenuation(3.f)
|
, QuadraticAttenuation(3.f)
|
||||||
|
, Radius(5.f)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
float ConstantAttenuation, LinearAttenuation, QuadraticAttenuation;
|
float ConstantAttenuation, LinearAttenuation, QuadraticAttenuation;
|
||||||
|
float Radius;
|
||||||
Color color;
|
Color color;
|
||||||
|
|
||||||
glm::vec3 Specular;
|
glm::vec3 Specular;
|
||||||
|
|||||||
+9
-8
@@ -57,6 +57,7 @@ void GameWorld::Initialize()
|
|||||||
auto light = AddComponent<Components::PointLight>(Light, "PointLight");
|
auto light = AddComponent<Components::PointLight>(Light, "PointLight");
|
||||||
light->Specular = glm::vec3(1.0f, 1.0f, 1.0f);
|
light->Specular = glm::vec3(1.0f, 1.0f, 1.0f);
|
||||||
light->Diffuse = 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");
|
auto model = AddComponent<Components::Model>(Light, "Model");
|
||||||
model->ModelFile = "Models/Placeholders/PhysicsTest/PointLight.obj";
|
model->ModelFile = "Models/Placeholders/PhysicsTest/PointLight.obj";
|
||||||
}
|
}
|
||||||
@@ -89,8 +90,8 @@ void GameWorld::Initialize()
|
|||||||
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
||||||
transform->Position = glm::vec3(1.4f, 0.5546f - 0.6577f - 0.2, -0.9242f);
|
transform->Position = glm::vec3(1.4f, 0.5546f - 0.6577f - 0.2, -0.9242f);
|
||||||
transform->Scale = glm::vec3(1.0f);
|
transform->Scale = glm::vec3(1.0f);
|
||||||
auto model = AddComponent<Components::Model>(wheel, "Model");
|
//auto model = AddComponent<Components::Model>(wheel, "Model");
|
||||||
model->ModelFile = "Models/Jeep/WheelFront/wheelFront.obj";
|
//model->ModelFile = "Models/Jeep/WheelFront/wheelFront.obj";
|
||||||
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
||||||
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f, 0.f);
|
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f, 0.f);
|
||||||
Wheel->AxleID = 0;
|
Wheel->AxleID = 0;
|
||||||
@@ -109,8 +110,8 @@ void GameWorld::Initialize()
|
|||||||
transform->Position = glm::vec3(-1.4f, 0.5546f - 0.6577f - 0.2, -0.9242f);
|
transform->Position = glm::vec3(-1.4f, 0.5546f - 0.6577f - 0.2, -0.9242f);
|
||||||
transform->Scale = glm::vec3(1.0f);
|
transform->Scale = glm::vec3(1.0f);
|
||||||
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 0, 1));
|
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 0, 1));
|
||||||
auto model = AddComponent<Components::Model>(wheel, "Model");
|
//auto model = AddComponent<Components::Model>(wheel, "Model");
|
||||||
model->ModelFile = "Models/Jeep/WheelFront/wheelFront.obj";
|
//model->ModelFile = "Models/Jeep/WheelFront/wheelFront.obj";
|
||||||
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
||||||
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f, 0.f);
|
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f, 0.f);
|
||||||
Wheel->AxleID = 0;
|
Wheel->AxleID = 0;
|
||||||
@@ -127,8 +128,8 @@ void GameWorld::Initialize()
|
|||||||
auto wheel = CreateEntity(jeep);
|
auto wheel = CreateEntity(jeep);
|
||||||
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
||||||
transform->Position = glm::vec3(0.2726f, 0.2805f - 0.6577f, 1.9307f);
|
transform->Position = glm::vec3(0.2726f, 0.2805f - 0.6577f, 1.9307f);
|
||||||
auto model = AddComponent<Components::Model>(wheel, "Model");
|
//auto model = AddComponent<Components::Model>(wheel, "Model");
|
||||||
model->ModelFile = "Models/Jeep/WheelBack/wheelBack.obj";
|
//model->ModelFile = "Models/Jeep/WheelBack/wheelBack.obj";
|
||||||
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
||||||
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f, 0.f);
|
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f, 0.f);
|
||||||
Wheel->AxleID = 1;
|
Wheel->AxleID = 1;
|
||||||
@@ -145,8 +146,8 @@ void GameWorld::Initialize()
|
|||||||
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
||||||
transform->Position = glm::vec3(-0.2726f, 0.2805f - 0.6577f, 1.9307f);
|
transform->Position = glm::vec3(-0.2726f, 0.2805f - 0.6577f, 1.9307f);
|
||||||
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 0, 1));
|
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 0, 1));
|
||||||
auto model = AddComponent<Components::Model>(wheel, "Model");
|
//auto model = AddComponent<Components::Model>(wheel, "Model");
|
||||||
model->ModelFile = "Models/Jeep/WheelBack/wheelBack.obj";
|
//model->ModelFile = "Models/Jeep/WheelBack/wheelBack.obj";
|
||||||
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
||||||
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f, 0.f);
|
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f, 0.f);
|
||||||
Wheel->AxleID = 1;
|
Wheel->AxleID = 1;
|
||||||
|
|||||||
@@ -23,11 +23,23 @@ Model::Model(OBJ &obj, ResourceManager* rm)
|
|||||||
// TODO: Load normal map
|
// TODO: Load normal map
|
||||||
std::shared_ptr<Texture> normalMap = nullptr;
|
std::shared_ptr<Texture> normalMap = nullptr;
|
||||||
if (!currentMaterial->NormalMap.FileName.empty())
|
if (!currentMaterial->NormalMap.FileName.empty())
|
||||||
|
{
|
||||||
normalMap = std::shared_ptr<Texture>(rm->Load<Texture>("Texture", currentMaterial->NormalMap.FileName));
|
normalMap = std::shared_ptr<Texture>(rm->Load<Texture>("Texture", currentMaterial->NormalMap.FileName));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
normalMap = std::shared_ptr<Texture>(rm->Load<Texture>("Texture", "Textures/NeutralNormalMap.png"));
|
||||||
|
}
|
||||||
// Load specular map
|
// Load specular map
|
||||||
std::shared_ptr<Texture> specularMap = nullptr;
|
std::shared_ptr<Texture> specularMap = nullptr;
|
||||||
if (!currentMaterial->SpecularMap.FileName.empty())
|
if (!currentMaterial->SpecularMap.FileName.empty())
|
||||||
|
{
|
||||||
specularMap = std::shared_ptr<Texture>(rm->Load<Texture>("Texture", currentMaterial->SpecularMap.FileName));
|
specularMap = std::shared_ptr<Texture>(rm->Load<Texture>("Texture", currentMaterial->SpecularMap.FileName));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
specularMap = std::shared_ptr<Texture>(rm->Load<Texture>("Texture", "Textures/NeutralSpecularMap.png"));
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Load material parameters
|
// TODO: Load material parameters
|
||||||
// Create new texture group (start index of new group is upcoming index)
|
// Create new texture group (start index of new group is upcoming index)
|
||||||
|
|||||||
+9
-9
@@ -358,7 +358,8 @@ void Renderer::AddPointLightToDraw(
|
|||||||
float _specularExponent,
|
float _specularExponent,
|
||||||
float _ConstantAttenuation,
|
float _ConstantAttenuation,
|
||||||
float _LinearAttenuation,
|
float _LinearAttenuation,
|
||||||
float _QuadraticAttenuation
|
float _QuadraticAttenuation,
|
||||||
|
float _radius
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
Light light;
|
Light light;
|
||||||
@@ -369,6 +370,7 @@ void Renderer::AddPointLightToDraw(
|
|||||||
light.ConstantAttenuation = _ConstantAttenuation;
|
light.ConstantAttenuation = _ConstantAttenuation;
|
||||||
light.LinearAttenuation = _LinearAttenuation;
|
light.LinearAttenuation = _LinearAttenuation;
|
||||||
light.QuadraticAttenuation = _QuadraticAttenuation;
|
light.QuadraticAttenuation = _QuadraticAttenuation;
|
||||||
|
light.Radius = _radius;
|
||||||
light.SphereModelMatrix = CreateLightMatrix(light);
|
light.SphereModelMatrix = CreateLightMatrix(light);
|
||||||
Lights.push_back(light);
|
Lights.push_back(light);
|
||||||
}
|
}
|
||||||
@@ -775,6 +777,7 @@ void Renderer::DrawLightScene()
|
|||||||
glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ConstantAttenuation"), CAtt);
|
glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ConstantAttenuation"), CAtt);
|
||||||
glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "LinearAttenuation"), LAtt);
|
glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "LinearAttenuation"), LAtt);
|
||||||
glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "QuadraticAttenuation"), QAtt);
|
glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "QuadraticAttenuation"), QAtt);
|
||||||
|
glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "LightRadius"), light.Radius);
|
||||||
|
|
||||||
glDrawArrays(GL_TRIANGLES, 0, m_sphereModel->Vertices.size());
|
glDrawArrays(GL_TRIANGLES, 0, m_sphereModel->Vertices.size());
|
||||||
};
|
};
|
||||||
@@ -793,14 +796,14 @@ glm::mat4 Renderer::CreateLightMatrix(Light &_light)
|
|||||||
// float c = _light.ConstantAttenuation;
|
// float c = _light.ConstantAttenuation;
|
||||||
// float l = _light.LinearAttenuation;
|
// float l = _light.LinearAttenuation;
|
||||||
// float q = _light.QuadraticAttenuation;
|
// float q = _light.QuadraticAttenuation;
|
||||||
float c = CAtt;
|
//float c = CAtt;
|
||||||
float l = LAtt;
|
//float l = LAtt;
|
||||||
float q = QAtt;
|
//float q = QAtt;
|
||||||
float cutOffRadius = abs(sqrt((-4*c*q) + pow(l, 2) + (1024*q) - l) / (2*q));
|
//float cutOffRadius = abs(sqrt((-4*c*q) + pow(l, 2) + (1024*q) - l) / (2*q));
|
||||||
|
|
||||||
glm::mat4 model;
|
glm::mat4 model;
|
||||||
model *= glm::translate(_light.Position);
|
model *= glm::translate(_light.Position);
|
||||||
model *= glm::scale(glm::vec3(cutOffRadius));
|
model *= glm::scale(glm::vec3(_light.Radius*2));
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -830,6 +833,3 @@ void Renderer::UpdateSunProjection()
|
|||||||
|
|
||||||
//Pass the bounding box's extents to glOrtho or similar to set up the orthographic projection matrix for the shadow map.
|
//Pass the bounding box's extents to glOrtho or similar to set up the orthographic projection matrix for the shadow map.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -41,7 +41,8 @@ public:
|
|||||||
float _specularExponent,
|
float _specularExponent,
|
||||||
float _ConstantAttenuation,
|
float _ConstantAttenuation,
|
||||||
float _LinearAttenuation,
|
float _LinearAttenuation,
|
||||||
float _QuadraticAttenuation
|
float _QuadraticAttenuation,
|
||||||
|
float _radius
|
||||||
);
|
);
|
||||||
void AddAABBToDraw(glm::vec3 origin, glm::vec3 volumeVector, bool colliding);
|
void AddAABBToDraw(glm::vec3 origin, glm::vec3 volumeVector, bool colliding);
|
||||||
|
|
||||||
@@ -71,7 +72,7 @@ private:
|
|||||||
glm::vec3 Diffuse;
|
glm::vec3 Diffuse;
|
||||||
float SpecularExponent;
|
float SpecularExponent;
|
||||||
glm::mat4 SphereModelMatrix;
|
glm::mat4 SphereModelMatrix;
|
||||||
float ConstantAttenuation, LinearAttenuation, QuadraticAttenuation;
|
float ConstantAttenuation, LinearAttenuation, QuadraticAttenuation, Radius;
|
||||||
};
|
};
|
||||||
|
|
||||||
float Gamma;
|
float Gamma;
|
||||||
|
|||||||
@@ -21,11 +21,11 @@ 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 = DiffuseTexel * (LightingTexel + vec4(La, 0.0));
|
FragmentColor = DiffuseTexel * (LightingTexel + vec4(La, 0.0));
|
||||||
//FragmentColor = vec4(pow(_FragmentColor.rgb, vec3(1.0 / Gamma)), _FragmentColor.a);
|
//FragmentColor = vec4(pow(_FragmentColor.rgb, vec3(1.0 / Gamma)), _FragmentColor.a);
|
||||||
|
|
||||||
//FragmentColor = DiffuseTexel;
|
|
||||||
//FragmentColor = DiffuseTexel;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -46,8 +46,9 @@ void main()
|
|||||||
frag_Position = vec4(Input.Position.xyz, 1.0);
|
frag_Position = vec4(Input.Position.xyz, 1.0);
|
||||||
|
|
||||||
// G-buffer Normal
|
// G-buffer Normal
|
||||||
mat3 TBN = transpose(mat3(Input.Tangent, Input.BiTangent, Input.Normal));
|
mat3 TBN = mat3(Input.Tangent, Input.BiTangent, Input.Normal);
|
||||||
frag_Normal = normalize(vec4(TBN * vec3(texture(NormalMapTexture, Input.TextureCoord)), 0.0));
|
frag_Normal = normalize(vec4(TBN * vec3(texture(NormalMapTexture, Input.TextureCoord)), 0.0));
|
||||||
|
//frag_Diffuse = normalize(vec4(TBN * vec3(texture(NormalMapTexture, Input.TextureCoord)), 0.0));
|
||||||
//frag_Normal = vec4(Input.Normal, 0.0);
|
//frag_Normal = vec4(Input.Normal, 0.0);
|
||||||
|
|
||||||
//G-buffer Specular
|
//G-buffer Specular
|
||||||
|
|||||||
@@ -18,12 +18,13 @@ uniform vec3 CameraPosition;
|
|||||||
uniform float ConstantAttenuation;
|
uniform float ConstantAttenuation;
|
||||||
uniform float LinearAttenuation;
|
uniform float LinearAttenuation;
|
||||||
uniform float QuadraticAttenuation;
|
uniform float QuadraticAttenuation;
|
||||||
|
uniform float LightRadius;
|
||||||
|
|
||||||
const vec3 ks = vec3(1.0, 1.0, 1.0);
|
const vec3 ks = vec3(1.0, 1.0, 1.0);
|
||||||
const vec3 kd = vec3(1.0, 1.0, 1.0);
|
const vec3 kd = vec3(1.0, 1.0, 1.0);
|
||||||
const vec3 ka = vec3(1.0, 1.0, 1.0);
|
const vec3 ka = vec3(1.0, 1.0, 1.0);
|
||||||
const float kshine = 1.0;
|
const float kshine = 1.0;
|
||||||
const float LRadius = 5.0;
|
|
||||||
|
|
||||||
in VertexData
|
in VertexData
|
||||||
{
|
{
|
||||||
@@ -57,7 +58,7 @@ vec4 phong(vec3 position, vec3 normal, vec3 specular)
|
|||||||
|
|
||||||
//float attenuation = 1.0 / (ConstantAttenuation + (LinearAttenuation * dist) + (QuadraticAttenuation * dist * dist));
|
//float attenuation = 1.0 / (ConstantAttenuation + (LinearAttenuation * dist) + (QuadraticAttenuation * dist * dist));
|
||||||
|
|
||||||
float attenuation = pow(max(0.0f, 1.0 - (dist / LRadius)), 2);
|
float attenuation = pow(max(0.0f, 1.0 - (dist / LightRadius)), 2);
|
||||||
|
|
||||||
//float attenuation = 1.0 / (1.0 - 0.0001 * pow(dist, 2));
|
//float attenuation = 1.0 / (1.0 - 0.0001 * pow(dist, 2));
|
||||||
|
|
||||||
@@ -85,6 +86,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));
|
FragColor = phong(vec3(PositionTexel), vec3(NormalTexel), vec3(SpecularTexel))+vec4(0.1f);
|
||||||
//FragColor = NormalTexel;
|
//FragColor = NormalTexel;
|
||||||
}
|
}
|
||||||
@@ -41,7 +41,8 @@ void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
|||||||
pointLightComponent->specularExponent,
|
pointLightComponent->specularExponent,
|
||||||
pointLightComponent->ConstantAttenuation,
|
pointLightComponent->ConstantAttenuation,
|
||||||
pointLightComponent->LinearAttenuation,
|
pointLightComponent->LinearAttenuation,
|
||||||
pointLightComponent->QuadraticAttenuation
|
pointLightComponent->QuadraticAttenuation,
|
||||||
|
pointLightComponent->Radius
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user