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)
|
||||
, LinearAttenuation(0.f)
|
||||
, QuadraticAttenuation(3.f)
|
||||
, Radius(5.f)
|
||||
{ }
|
||||
|
||||
float ConstantAttenuation, LinearAttenuation, QuadraticAttenuation;
|
||||
float Radius;
|
||||
Color color;
|
||||
|
||||
glm::vec3 Specular;
|
||||
|
||||
+9
-8
@@ -57,6 +57,7 @@ void GameWorld::Initialize()
|
||||
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";
|
||||
}
|
||||
@@ -89,8 +90,8 @@ void GameWorld::Initialize()
|
||||
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
||||
transform->Position = glm::vec3(1.4f, 0.5546f - 0.6577f - 0.2, -0.9242f);
|
||||
transform->Scale = glm::vec3(1.0f);
|
||||
auto model = AddComponent<Components::Model>(wheel, "Model");
|
||||
model->ModelFile = "Models/Jeep/WheelFront/wheelFront.obj";
|
||||
//auto model = AddComponent<Components::Model>(wheel, "Model");
|
||||
//model->ModelFile = "Models/Jeep/WheelFront/wheelFront.obj";
|
||||
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
||||
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f, 0.f);
|
||||
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->Scale = glm::vec3(1.0f);
|
||||
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 0, 1));
|
||||
auto model = AddComponent<Components::Model>(wheel, "Model");
|
||||
model->ModelFile = "Models/Jeep/WheelFront/wheelFront.obj";
|
||||
//auto model = AddComponent<Components::Model>(wheel, "Model");
|
||||
//model->ModelFile = "Models/Jeep/WheelFront/wheelFront.obj";
|
||||
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
||||
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f, 0.f);
|
||||
Wheel->AxleID = 0;
|
||||
@@ -127,8 +128,8 @@ void GameWorld::Initialize()
|
||||
auto wheel = CreateEntity(jeep);
|
||||
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
||||
transform->Position = glm::vec3(0.2726f, 0.2805f - 0.6577f, 1.9307f);
|
||||
auto model = AddComponent<Components::Model>(wheel, "Model");
|
||||
model->ModelFile = "Models/Jeep/WheelBack/wheelBack.obj";
|
||||
//auto model = AddComponent<Components::Model>(wheel, "Model");
|
||||
//model->ModelFile = "Models/Jeep/WheelBack/wheelBack.obj";
|
||||
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
||||
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f, 0.f);
|
||||
Wheel->AxleID = 1;
|
||||
@@ -145,8 +146,8 @@ void GameWorld::Initialize()
|
||||
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
||||
transform->Position = glm::vec3(-0.2726f, 0.2805f - 0.6577f, 1.9307f);
|
||||
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 0, 1));
|
||||
auto model = AddComponent<Components::Model>(wheel, "Model");
|
||||
model->ModelFile = "Models/Jeep/WheelBack/wheelBack.obj";
|
||||
//auto model = AddComponent<Components::Model>(wheel, "Model");
|
||||
//model->ModelFile = "Models/Jeep/WheelBack/wheelBack.obj";
|
||||
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
||||
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f, 0.f);
|
||||
Wheel->AxleID = 1;
|
||||
|
||||
@@ -23,11 +23,23 @@ Model::Model(OBJ &obj, ResourceManager* rm)
|
||||
// TODO: Load normal map
|
||||
std::shared_ptr<Texture> normalMap = nullptr;
|
||||
if (!currentMaterial->NormalMap.FileName.empty())
|
||||
{
|
||||
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
|
||||
std::shared_ptr<Texture> specularMap = nullptr;
|
||||
if (!currentMaterial->SpecularMap.FileName.empty())
|
||||
{
|
||||
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
|
||||
// Create new texture group (start index of new group is upcoming index)
|
||||
|
||||
+9
-9
@@ -358,7 +358,8 @@ void Renderer::AddPointLightToDraw(
|
||||
float _specularExponent,
|
||||
float _ConstantAttenuation,
|
||||
float _LinearAttenuation,
|
||||
float _QuadraticAttenuation
|
||||
float _QuadraticAttenuation,
|
||||
float _radius
|
||||
)
|
||||
{
|
||||
Light light;
|
||||
@@ -369,6 +370,7 @@ void Renderer::AddPointLightToDraw(
|
||||
light.ConstantAttenuation = _ConstantAttenuation;
|
||||
light.LinearAttenuation = _LinearAttenuation;
|
||||
light.QuadraticAttenuation = _QuadraticAttenuation;
|
||||
light.Radius = _radius;
|
||||
light.SphereModelMatrix = CreateLightMatrix(light);
|
||||
Lights.push_back(light);
|
||||
}
|
||||
@@ -775,6 +777,7 @@ void Renderer::DrawLightScene()
|
||||
glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ConstantAttenuation"), CAtt);
|
||||
glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "LinearAttenuation"), LAtt);
|
||||
glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "QuadraticAttenuation"), QAtt);
|
||||
glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "LightRadius"), light.Radius);
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, 0, m_sphereModel->Vertices.size());
|
||||
};
|
||||
@@ -793,14 +796,14 @@ glm::mat4 Renderer::CreateLightMatrix(Light &_light)
|
||||
// float c = _light.ConstantAttenuation;
|
||||
// float l = _light.LinearAttenuation;
|
||||
// float q = _light.QuadraticAttenuation;
|
||||
float c = CAtt;
|
||||
float l = LAtt;
|
||||
float q = QAtt;
|
||||
float cutOffRadius = abs(sqrt((-4*c*q) + pow(l, 2) + (1024*q) - l) / (2*q));
|
||||
//float c = CAtt;
|
||||
//float l = LAtt;
|
||||
//float q = QAtt;
|
||||
//float cutOffRadius = abs(sqrt((-4*c*q) + pow(l, 2) + (1024*q) - l) / (2*q));
|
||||
|
||||
glm::mat4 model;
|
||||
model *= glm::translate(_light.Position);
|
||||
model *= glm::scale(glm::vec3(cutOffRadius));
|
||||
model *= glm::scale(glm::vec3(_light.Radius*2));
|
||||
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.
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
+3
-2
@@ -41,7 +41,8 @@ public:
|
||||
float _specularExponent,
|
||||
float _ConstantAttenuation,
|
||||
float _LinearAttenuation,
|
||||
float _QuadraticAttenuation
|
||||
float _QuadraticAttenuation,
|
||||
float _radius
|
||||
);
|
||||
void AddAABBToDraw(glm::vec3 origin, glm::vec3 volumeVector, bool colliding);
|
||||
|
||||
@@ -71,7 +72,7 @@ private:
|
||||
glm::vec3 Diffuse;
|
||||
float SpecularExponent;
|
||||
glm::mat4 SphereModelMatrix;
|
||||
float ConstantAttenuation, LinearAttenuation, QuadraticAttenuation;
|
||||
float ConstantAttenuation, LinearAttenuation, QuadraticAttenuation, Radius;
|
||||
};
|
||||
|
||||
float Gamma;
|
||||
|
||||
@@ -21,11 +21,11 @@ void main()
|
||||
vec4 LightingTexel = texture(LightingTexture, Input.TextureCoord);
|
||||
vec4 ShadowTexel = texture(ShadowTexture, Input.TextureCoord);
|
||||
|
||||
//FragmentColor = DiffuseTexel;
|
||||
|
||||
FragmentColor = DiffuseTexel * (LightingTexel + vec4(La, 0.0));
|
||||
//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);
|
||||
|
||||
// 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_Diffuse = normalize(vec4(TBN * vec3(texture(NormalMapTexture, Input.TextureCoord)), 0.0));
|
||||
//frag_Normal = vec4(Input.Normal, 0.0);
|
||||
|
||||
//G-buffer Specular
|
||||
|
||||
@@ -18,12 +18,13 @@ uniform vec3 CameraPosition;
|
||||
uniform float ConstantAttenuation;
|
||||
uniform float LinearAttenuation;
|
||||
uniform float QuadraticAttenuation;
|
||||
uniform float LightRadius;
|
||||
|
||||
const vec3 ks = 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 float kshine = 1.0;
|
||||
const float LRadius = 5.0;
|
||||
|
||||
|
||||
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 = 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));
|
||||
|
||||
@@ -85,6 +86,6 @@ void main()
|
||||
vec4 NormalTexel = texture(NormalsTexture, 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;
|
||||
}
|
||||
@@ -41,7 +41,8 @@ void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
||||
pointLightComponent->specularExponent,
|
||||
pointLightComponent->ConstantAttenuation,
|
||||
pointLightComponent->LinearAttenuation,
|
||||
pointLightComponent->QuadraticAttenuation
|
||||
pointLightComponent->QuadraticAttenuation,
|
||||
pointLightComponent->Radius
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user