WIP Lights
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -11,8 +11,11 @@ struct PointLight : Component
|
|||||||
{
|
{
|
||||||
float Intensity;
|
float Intensity;
|
||||||
float MaxRange;
|
float MaxRange;
|
||||||
float SpecularIntensity;
|
glm::vec3 Specular;
|
||||||
Color Color;
|
glm::vec3 Diffuse;
|
||||||
|
float constantAttenuation, linearAttenuation, quadraticAttenuation;
|
||||||
|
float spotExponent;
|
||||||
|
Color color;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -160,6 +160,7 @@
|
|||||||
<ClInclude Include="World.h" />
|
<ClInclude Include="World.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<None Include="Fragment2.glsl" />
|
||||||
<None Include="Shaders\Fragment.glsl" />
|
<None Include="Shaders\Fragment.glsl" />
|
||||||
<None Include="Shaders\Vertex.glsl" />
|
<None Include="Shaders\Vertex.glsl" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -150,6 +150,9 @@
|
|||||||
<None Include="Shaders\Vertex.glsl">
|
<None Include="Shaders\Vertex.glsl">
|
||||||
<Filter>Shaders</Filter>
|
<Filter>Shaders</Filter>
|
||||||
</None>
|
</None>
|
||||||
|
<None Include="Fragment2.glsl">
|
||||||
|
<Filter>Shaders</Filter>
|
||||||
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Filter Include="Systems">
|
<Filter Include="Systems">
|
||||||
|
|||||||
@@ -0,0 +1,97 @@
|
|||||||
|
newmtl default_body2
|
||||||
|
d 1
|
||||||
|
Ns 0.75
|
||||||
|
Ni 0
|
||||||
|
Ka 0 0 0
|
||||||
|
Kd 1 1 1
|
||||||
|
Ks 1 1 1
|
||||||
|
Km 0
|
||||||
|
map_Kd /Maps/as2.jpg
|
||||||
|
|
||||||
|
newmtl default
|
||||||
|
d 1
|
||||||
|
Ns 0.75
|
||||||
|
Ni 0
|
||||||
|
Ka 0 0 0
|
||||||
|
Kd 0.27451 0.27451 0.27451
|
||||||
|
Ks 1 1 1
|
||||||
|
Km 0
|
||||||
|
|
||||||
|
newmtl default_cockpits_1_cushions
|
||||||
|
d 1
|
||||||
|
Ns 0.75
|
||||||
|
Ni 0
|
||||||
|
Ka 0 0 0
|
||||||
|
Kd 1 1 1
|
||||||
|
Ks 1 1 1
|
||||||
|
Km 0
|
||||||
|
map_Kd /Maps/yx1_02_01_01_02.jpg
|
||||||
|
|
||||||
|
newmtl default_cockpits_1_display
|
||||||
|
d 1
|
||||||
|
Ns 0.75
|
||||||
|
Ni 0
|
||||||
|
Ka 1 1 1
|
||||||
|
Kd 1 1 1
|
||||||
|
Ks 1 1 1
|
||||||
|
Km 0
|
||||||
|
map_Kd /Maps/ggt1.jpg
|
||||||
|
|
||||||
|
newmtl default_cockpits_joysticks
|
||||||
|
d 1
|
||||||
|
Ns 0.75
|
||||||
|
Ni 0
|
||||||
|
Ka 0 0 0
|
||||||
|
Kd 0 0 0
|
||||||
|
Ks 1 1 1
|
||||||
|
Km 0
|
||||||
|
|
||||||
|
newmtl default_skin
|
||||||
|
d 1
|
||||||
|
Ns 0.75
|
||||||
|
Ni 0
|
||||||
|
Ka 0 0 0
|
||||||
|
Kd 1 1 1
|
||||||
|
Ks 1 1 1
|
||||||
|
Km 0
|
||||||
|
map_Kd /Maps/ahm1_01_01.jpg
|
||||||
|
|
||||||
|
newmtl default_cabins1glass
|
||||||
|
d 0.65
|
||||||
|
Ns 0.75
|
||||||
|
Ni 0
|
||||||
|
Ka 0 0 0
|
||||||
|
Kd 0.501961 1 0
|
||||||
|
Ks 1 1 1
|
||||||
|
Km 0
|
||||||
|
|
||||||
|
newmtl default_ship_door
|
||||||
|
d 1
|
||||||
|
Ns 1
|
||||||
|
Ni 0
|
||||||
|
Ka 0 0 0
|
||||||
|
Kd 1 1 1
|
||||||
|
Ks 1 1 1
|
||||||
|
Km 0
|
||||||
|
map_Kd /Maps/as1_02.jpg
|
||||||
|
|
||||||
|
newmtl default_door
|
||||||
|
d 1
|
||||||
|
Ns 0.75
|
||||||
|
Ni 0
|
||||||
|
Ka 0 0 0
|
||||||
|
Kd 1 1 1
|
||||||
|
Ks 1 1 1
|
||||||
|
Km 0
|
||||||
|
map_Kd /Maps/as1_02.jpg
|
||||||
|
|
||||||
|
newmtl default_steps
|
||||||
|
d 1
|
||||||
|
Ns 1
|
||||||
|
Ni 0
|
||||||
|
Ka 0 0 0
|
||||||
|
Kd 1 1 1
|
||||||
|
Ks 1 1 1
|
||||||
|
Km 0
|
||||||
|
map_Kd /Maps/rmp1.jpg
|
||||||
|
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
uniform mat4 model;
|
||||||
|
uniform mat4 view;
|
||||||
|
|
||||||
|
layout(binding=0) uniform sampler2D texture;
|
||||||
|
|
||||||
|
const int numberOfLights = 2;
|
||||||
|
lightSource lights[numberOfLights];
|
||||||
|
|
||||||
|
uniform vec4 position[numberOfLights];
|
||||||
|
uniform vec4 specular[numberOfLights];
|
||||||
|
uniform vec4 diffuse[numberOfLights];
|
||||||
|
uniform float constantAttenuation[numberOfLights];
|
||||||
|
uniform float linearAttenuation[numberOfLights];
|
||||||
|
uniform float quadraticAttenuation[numberOfLights];
|
||||||
|
uniform float spotExponent[numberOfLights];
|
||||||
|
|
||||||
|
in VertexData {
|
||||||
|
vec3 Position;
|
||||||
|
vec3 Normal;
|
||||||
|
vec2 TextureCoord;
|
||||||
|
} Input;
|
||||||
|
|
||||||
|
vec4 scene_ambient = vec4(0.2, 0.2, 0.2, 1.0);
|
||||||
|
|
||||||
|
out vec4 fragmentColor;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
|
||||||
|
vec4 texel = texture2D(texture, Input.TextureCoord);
|
||||||
|
|
||||||
|
vec3 normalDirection = normalize(Normal);
|
||||||
|
vec3 viewDirection = normalize(vec3(v_inv * vec4(0.0, 0.0, 0.0, 1.0) - Position));
|
||||||
|
vec3 lightDirection;
|
||||||
|
float attenuation;
|
||||||
|
|
||||||
|
// initialize total lighting with ambient lighting
|
||||||
|
vec3 totalLighting = vec3(scene_ambient) * vec3(frontMaterial.ambient);
|
||||||
|
|
||||||
|
for (int index = 0; index < numberOfLights; index++) // for all light sources
|
||||||
|
{
|
||||||
|
vec3 positionToLightSource = vec3(position[index] - Position);
|
||||||
|
float distance = length(positionToLightSource);
|
||||||
|
lightDirection = normalize(positionToLightSource);
|
||||||
|
|
||||||
|
attenuation = 1.0 / (constantAttenuation[index]
|
||||||
|
+ linearAttenuation[index] * distance
|
||||||
|
+ quadraticAttenuation[index] * distance * distance);
|
||||||
|
|
||||||
|
attenuation = attenuation * pow(clampedCosine, spotExponent[index]);
|
||||||
|
|
||||||
|
vec3 diffuseReflection = attenuation
|
||||||
|
* vec3(diffuse[index]) * vec3(frontMaterial.diffuse)
|
||||||
|
* max(0.0, dot(normalDirection, lightDirection));
|
||||||
|
|
||||||
|
vec3 specularReflection;
|
||||||
|
if (dot(normalDirection, lightDirection) < 0.0) // light source on the wrong side?
|
||||||
|
{
|
||||||
|
specularReflection = vec3(0.0, 0.0, 0.0); // no specular reflection
|
||||||
|
}
|
||||||
|
else // light source on the right side
|
||||||
|
{
|
||||||
|
specularReflection = attenuation * vec3(specular[index]) * vec3(frontMaterial.specular)
|
||||||
|
* pow(max(0.0, dot(reflect(-lightDirection, normalDirection), viewDirection)), frontMaterial.shininess);
|
||||||
|
}
|
||||||
|
|
||||||
|
totalLighting = totalLighting + diffuseReflection + specularReflection;
|
||||||
|
}
|
||||||
|
|
||||||
|
fragmentColor = vec4(totalLighting, 1.0) * texel;
|
||||||
|
}
|
||||||
@@ -62,23 +62,51 @@ void GameWorld::Initialize()
|
|||||||
|
|
||||||
std::shared_ptr<Components::Transform> transform;
|
std::shared_ptr<Components::Transform> transform;
|
||||||
std::shared_ptr<Components::Model> model;
|
std::shared_ptr<Components::Model> model;
|
||||||
|
std::shared_ptr<Components::PointLight> pointLight;
|
||||||
std::shared_ptr<Components::Camera> camera;
|
std::shared_ptr<Components::Camera> camera;
|
||||||
EntityID ent;
|
EntityID ent;
|
||||||
|
|
||||||
|
ent = CreateEntity();
|
||||||
|
transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||||
|
transform->Position = glm::vec3(0.f, 4.f, 0.f);
|
||||||
|
pointLight = AddComponent<Components::PointLight>(ent, "PointLight");
|
||||||
|
pointLight->Specular = glm::vec3(1.0, 1.0, 1.0);
|
||||||
|
pointLight->Diffuse = glm::vec3(1.0, 1.0, 1.0);
|
||||||
|
pointLight->constantAttenuation = 0.f;
|
||||||
|
pointLight->linearAttenuation = 1.f;
|
||||||
|
pointLight->quadraticAttenuation = 0.f;
|
||||||
|
pointLight->spotExponent = 0.0f;
|
||||||
|
|
||||||
|
ent = CreateEntity();
|
||||||
|
transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||||
|
transform->Position = glm::vec3(10.f, 4.f, 0.f);
|
||||||
|
pointLight = AddComponent<Components::PointLight>(ent, "PointLight");
|
||||||
|
pointLight->Specular = glm::vec3(1.0, 1.0, 1.0);
|
||||||
|
pointLight->Diffuse = glm::vec3(1.0, 1.0, 1.0);
|
||||||
|
pointLight->constantAttenuation = 0.f;
|
||||||
|
pointLight->linearAttenuation = 1.f;
|
||||||
|
pointLight->quadraticAttenuation = 0.f;
|
||||||
|
pointLight->spotExponent = 0.0f;
|
||||||
|
|
||||||
|
ent = CreateEntity();
|
||||||
|
transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||||
|
transform->Position = glm::vec3(10.f, 0.f, 0.f);
|
||||||
|
model = AddComponent<Components::Model>(ent, "Model");
|
||||||
|
model->ModelFile = "ship.obj";
|
||||||
|
|
||||||
ent = CreateEntity();
|
ent = CreateEntity();
|
||||||
transform = AddComponent<Components::Transform>(ent, "Transform");
|
transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||||
transform->Position = glm::vec3(0.f, 0.f, 0.f);
|
transform->Position = glm::vec3(0.f, 0.f, 0.f);
|
||||||
model = AddComponent<Components::Model>(ent, "Model");
|
model = AddComponent<Components::Model>(ent, "Model");
|
||||||
model->ModelFile = "ship.obj";
|
model->ModelFile = "ship.obj";
|
||||||
auto soundEmitter = AddComponent<Components::SoundEmitter>(ent, "SoundEmitter");
|
// auto soundEmitter = AddComponent<Components::SoundEmitter>(ent, "SoundEmitter");
|
||||||
soundEmitter->Gain = 1;
|
// soundEmitter->Gain = 1;
|
||||||
soundEmitter->MaxDistance = 10;
|
// soundEmitter->MaxDistance = 10;
|
||||||
soundEmitter->Loop = true;
|
// soundEmitter->Loop = true;
|
||||||
soundEmitter->ReferenceDistance = 0.1;
|
// soundEmitter->ReferenceDistance = 0.1;
|
||||||
soundEmitter->Pitch = 1;
|
// soundEmitter->Pitch = 1;
|
||||||
GetSystem<Systems::SoundSystem>("SoundSystem")->PlaySound(soundEmitter, "Sounds/hallelujah.wav");
|
// GetSystem<Systems::SoundSystem>("SoundSystem")->PlaySound(soundEmitter, "Sounds/hallelujah.wav");
|
||||||
|
|
||||||
|
|
||||||
ent = CreateEntity();
|
ent = CreateEntity();
|
||||||
SetProperty(ent, "Name", std::string("Camera"));
|
SetProperty(ent, "Name", std::string("Camera"));
|
||||||
transform = AddComponent<Components::Transform>(ent, "Transform");
|
transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||||
|
|||||||
@@ -0,0 +1,150 @@
|
|||||||
|
#
|
||||||
|
# Wavefront material file
|
||||||
|
# Converted by the DEEP Exploration Deep Exploration 6.5 x64 6.5.0.9182
|
||||||
|
# Right Hemisphere, LTD
|
||||||
|
# http://www.righthemisphere.com/
|
||||||
|
#
|
||||||
|
|
||||||
|
newmtl MG_MovieCycle_Body_MI
|
||||||
|
Ka 0 0 0
|
||||||
|
Kd 0 0 0
|
||||||
|
Ks 1 1 1
|
||||||
|
illum 2
|
||||||
|
Ns 32
|
||||||
|
map_Kd MG_MovieCycle_BodyHeadLight_EMSS.tga
|
||||||
|
map_bump MG_MovieCycle_Body_NORM.tga
|
||||||
|
bump MG_MovieCycle_Body_NORM.tga
|
||||||
|
map_opacity
|
||||||
|
map_d
|
||||||
|
refl
|
||||||
|
map_kS MG_MovieCycle_Body_SPEC.tga
|
||||||
|
map_kA
|
||||||
|
map_Ns
|
||||||
|
|
||||||
|
newmtl MG_MovieCycle_Glass_MI
|
||||||
|
Ka 0 0 0
|
||||||
|
Kd 1 1 1
|
||||||
|
Ks 0.84 0.84 0.84
|
||||||
|
illum 2
|
||||||
|
Ns 33.6359
|
||||||
|
map_Kd Glass.tga
|
||||||
|
map_bump
|
||||||
|
bump
|
||||||
|
map_opacity Glass.tga
|
||||||
|
map_d Glass.tga
|
||||||
|
refl
|
||||||
|
map_kS
|
||||||
|
map_kA
|
||||||
|
map_Ns
|
||||||
|
|
||||||
|
newmtl MG_MovieCycle_Tire_MI
|
||||||
|
Ka 0 0 0
|
||||||
|
Kd 1 1 1
|
||||||
|
Ks 0 0 0
|
||||||
|
illum 2
|
||||||
|
Ns 10
|
||||||
|
map_Kd MG_MovieCycle_Tire_EMSS.tga
|
||||||
|
map_bump MG_MovieCycle_Tire_NORM.tga
|
||||||
|
bump MG_MovieCycle_Tire_NORM.tga
|
||||||
|
map_opacity
|
||||||
|
map_d
|
||||||
|
refl
|
||||||
|
map_kS
|
||||||
|
map_kA
|
||||||
|
map_Ns
|
||||||
|
|
||||||
|
newmtl MG_MovieCycle_Engine_MI
|
||||||
|
Ka 0 0 0
|
||||||
|
Kd 1 1 1
|
||||||
|
Ks 0 0 0
|
||||||
|
illum 2
|
||||||
|
Ns 10
|
||||||
|
map_Kd MG_MovieCycle_Engine_EMSS.tga
|
||||||
|
map_bump MG_MovieCycle_Engine_NORM.tga
|
||||||
|
bump MG_MovieCycle_Engine_NORM.tga
|
||||||
|
map_opacity
|
||||||
|
map_d
|
||||||
|
refl
|
||||||
|
map_kS
|
||||||
|
map_kA
|
||||||
|
map_Ns
|
||||||
|
|
||||||
|
newmtl MG_MovieCycle_PlayerBody_MI
|
||||||
|
Ka 0 0 0
|
||||||
|
Kd 1 1 1
|
||||||
|
Ks 1 1 1
|
||||||
|
illum 2
|
||||||
|
Ns 10
|
||||||
|
map_Kd MG_Player_Body_EMSS.tga
|
||||||
|
map_bump MG_Player_Body_NORM.tga
|
||||||
|
bump MG_Player_Body_NORM.tga
|
||||||
|
map_opacity
|
||||||
|
map_d
|
||||||
|
refl
|
||||||
|
map_kS MG_Player_Body_SPEC.tga
|
||||||
|
map_kA
|
||||||
|
map_Ns
|
||||||
|
|
||||||
|
newmtl MG_MovieCycle_PlayerHelmet_MI
|
||||||
|
Ka 0 0 0
|
||||||
|
Kd 1 1 1
|
||||||
|
Ks 1 1 1
|
||||||
|
illum 2
|
||||||
|
Ns 6.27667
|
||||||
|
map_Kd MG_Player_Helmet_EMSS.tga
|
||||||
|
map_bump MG_Player_Helmet_NORM.tga
|
||||||
|
bump MG_Player_Helmet_NORM.tga
|
||||||
|
map_opacity
|
||||||
|
map_d
|
||||||
|
refl
|
||||||
|
map_kS MG_Player_Helmet_SPEC.tga
|
||||||
|
map_kA
|
||||||
|
map_Ns
|
||||||
|
|
||||||
|
newmtl MG_MovieCycle_PlayerDisc_MI
|
||||||
|
Ka 0 0 0
|
||||||
|
Kd 1 1 1
|
||||||
|
Ks 1 1 1
|
||||||
|
illum 2
|
||||||
|
Ns 10
|
||||||
|
map_Kd MG_Player_Disc_EMSS.tga
|
||||||
|
map_bump MG_Player_Disc_NORM.tga
|
||||||
|
bump MG_Player_Disc_NORM.tga
|
||||||
|
map_opacity
|
||||||
|
map_d
|
||||||
|
refl
|
||||||
|
map_kS MG_Player_Disc_SPEC.tga
|
||||||
|
map_kA
|
||||||
|
map_Ns
|
||||||
|
|
||||||
|
newmtl MG_MovieCycle_PlayerBaton_MI
|
||||||
|
Ka 0 0 0
|
||||||
|
Kd 1 1 1
|
||||||
|
Ks 1 1 1
|
||||||
|
illum 2
|
||||||
|
Ns 10
|
||||||
|
map_Kd MG_Player_Baton_EMSS.tga
|
||||||
|
map_bump MG_Player_Baton_NORM.tga
|
||||||
|
bump MG_Player_Baton_NORM.tga
|
||||||
|
map_opacity
|
||||||
|
map_d
|
||||||
|
refl
|
||||||
|
map_kS MG_Player_Baton_SPEC.tga
|
||||||
|
map_kA
|
||||||
|
map_Ns
|
||||||
|
|
||||||
|
newmtl Explorer_Default
|
||||||
|
Ka 0.117647 0.117647 0.117647
|
||||||
|
Kd 0.752941 0.752941 0.752941
|
||||||
|
Ks 0.752941 0.752941 0.752941
|
||||||
|
illum 2
|
||||||
|
Ns 8
|
||||||
|
map_Kd
|
||||||
|
map_bump
|
||||||
|
bump
|
||||||
|
map_opacity
|
||||||
|
map_d
|
||||||
|
refl
|
||||||
|
map_kS
|
||||||
|
map_kA
|
||||||
|
map_Ns
|
||||||
@@ -67,10 +67,13 @@ void Renderer::Draw(double _dt)
|
|||||||
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
||||||
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "model"), 1, GL_FALSE, glm::value_ptr(ModelsToRender[i]->ModelMatrix));
|
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "model"), 1, GL_FALSE, glm::value_ptr(ModelsToRender[i]->ModelMatrix));
|
||||||
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "view"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
|
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "view"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
|
||||||
glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "lightPosition"), 1, glm::value_ptr(glm::vec3(2.0f, 4.0f, 1.0f)));
|
glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "position"), 2, Light_position.data());
|
||||||
glUniform1f(glGetUniformLocation(m_ShaderProgram.GetHandle(), "constantAttenuation"), 1.5f);
|
glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "specular"), 2, Light_specular.data());
|
||||||
glUniform1f(glGetUniformLocation(m_ShaderProgram.GetHandle(), "linearAttenuation"), 0.0f);
|
glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "diffuse"), 2, Light_diffuse.data());
|
||||||
glUniform1f(glGetUniformLocation(m_ShaderProgram.GetHandle(), "quadraticAttenuation"), 0.0f);
|
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "constantAttenuation"), 2, Light_constantAttenuation.data());
|
||||||
|
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "linearAttenuation"), 2, Light_linearAttenuation.data());
|
||||||
|
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "quadraticAttenuation"), 2, Light_quadraticAttenuation.data());
|
||||||
|
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "spotExponent"), 2, Light_spotExponent.data());
|
||||||
glBindVertexArray(ModelsToRender[i]->model->VAO);
|
glBindVertexArray(ModelsToRender[i]->model->VAO);
|
||||||
glDrawArrays(GL_TRIANGLES, 0, ModelsToRender[i]->model->Vertices.size());
|
glDrawArrays(GL_TRIANGLES, 0, ModelsToRender[i]->model->Vertices.size());
|
||||||
|
|
||||||
@@ -98,7 +101,32 @@ void Renderer::AddModelToDraw(Model* _model, glm::vec3 _position, glm::quat _ori
|
|||||||
ModelsToRender.push_back(new ModelData(_model, ModelMatrix));
|
ModelsToRender.push_back(new ModelData(_model, ModelMatrix));
|
||||||
}
|
}
|
||||||
|
|
||||||
//Fixa med shaders, lägga in alla verts osv.
|
void Renderer::AddPointLightToDraw(
|
||||||
|
glm::vec3 _position,
|
||||||
|
glm::vec3 _specular,
|
||||||
|
glm::vec3 _diffuse,
|
||||||
|
float _constantAttenuation,
|
||||||
|
float _linearAttenuation,
|
||||||
|
float _quadraticAttenuation,
|
||||||
|
float _spotExponent
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Light_position.push_back(_position.x);
|
||||||
|
Light_position.push_back(_position.y);
|
||||||
|
Light_position.push_back(_position.z);
|
||||||
|
Light_specular.push_back(_specular.x);
|
||||||
|
Light_specular.push_back(_specular.y);
|
||||||
|
Light_specular.push_back(_specular.z);
|
||||||
|
Light_diffuse.push_back(_diffuse.x);
|
||||||
|
Light_diffuse.push_back(_diffuse.y);
|
||||||
|
Light_diffuse.push_back(_diffuse.z);
|
||||||
|
Light_constantAttenuation.push_back(_constantAttenuation);
|
||||||
|
Light_linearAttenuation.push_back(_linearAttenuation);
|
||||||
|
Light_quadraticAttenuation.push_back(_quadraticAttenuation);
|
||||||
|
Light_spotExponent.push_back(_spotExponent);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Renderer::LoadContent()
|
void Renderer::LoadContent()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
#include "Camera.h"
|
#include "Camera.h"
|
||||||
#include "ShaderProgram.h"
|
#include "ShaderProgram.h"
|
||||||
#include "Model.h"
|
#include "Model.h"
|
||||||
|
#include "Components/PointLight.h"
|
||||||
|
|
||||||
class Renderer
|
class Renderer
|
||||||
{
|
{
|
||||||
@@ -43,6 +44,13 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::vector<ModelData*> ModelsToRender;
|
std::vector<ModelData*> ModelsToRender;
|
||||||
|
std::vector<float> Light_position;
|
||||||
|
std::vector<float> Light_specular;
|
||||||
|
std::vector<float> Light_diffuse;
|
||||||
|
std::vector<float> Light_constantAttenuation;
|
||||||
|
std::vector<float> Light_linearAttenuation;
|
||||||
|
std::vector<float> Light_quadraticAttenuation;
|
||||||
|
std::vector<float> Light_spotExponent;
|
||||||
|
|
||||||
Renderer();
|
Renderer();
|
||||||
|
|
||||||
@@ -52,6 +60,15 @@ public:
|
|||||||
|
|
||||||
void AddModelToDraw(Model*, glm::vec3, glm::quat);
|
void AddModelToDraw(Model*, glm::vec3, glm::quat);
|
||||||
void AddTextToDraw();
|
void AddTextToDraw();
|
||||||
|
void AddPointLightToDraw(
|
||||||
|
glm::vec3 _position,
|
||||||
|
glm::vec3 _specular,
|
||||||
|
glm::vec3 _diffuse,
|
||||||
|
float _constantAttenuation,
|
||||||
|
float _linearAttenuation,
|
||||||
|
float _quadraticAttenuation,
|
||||||
|
float _spotExponent
|
||||||
|
);
|
||||||
|
|
||||||
void LoadContent();
|
void LoadContent();
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
newmtl material_1
|
||||||
|
d 1
|
||||||
|
Ns 1
|
||||||
|
Ni 0
|
||||||
|
Ka 0.121569 0.121569 0.121569
|
||||||
|
Kd 1 1 1
|
||||||
|
Ks 0 0 0
|
||||||
|
Km 0
|
||||||
|
map_Kd /Maps/snd2_01.jpg
|
||||||
|
|
||||||
|
newmtl material_1_mountain
|
||||||
|
d 1
|
||||||
|
Ns 1
|
||||||
|
Ni 0
|
||||||
|
Ka 0 0 0
|
||||||
|
Kd 0.501961 0.501961 0.501961
|
||||||
|
Ks 0 0 0
|
||||||
|
Km 0
|
||||||
|
map_Kd /Maps/mtlm1.jpg
|
||||||
|
|
||||||
|
newmtl default
|
||||||
|
d 1
|
||||||
|
Ns 1
|
||||||
|
Ni 0
|
||||||
|
Ka 0 0 0
|
||||||
|
Kd 0.290196 0.282353 0.254902
|
||||||
|
Ks 1 1 1
|
||||||
|
Km 0
|
||||||
|
map_Kd /Maps/1thr.jpg
|
||||||
|
|
||||||
|
newmtl default_bldgs2
|
||||||
|
d 1
|
||||||
|
Ns 1
|
||||||
|
Ni 0
|
||||||
|
Ka 0 0 0
|
||||||
|
Kd 1 1 1
|
||||||
|
Ks 1 1 1
|
||||||
|
Km 0
|
||||||
|
map_Kd /Maps/axq2.jpg
|
||||||
|
|
||||||
@@ -2,74 +2,92 @@
|
|||||||
|
|
||||||
uniform mat4 model;
|
uniform mat4 model;
|
||||||
uniform mat4 view;
|
uniform mat4 view;
|
||||||
|
|
||||||
layout(binding=0) uniform sampler2D texture;
|
layout(binding=0) uniform sampler2D texture;
|
||||||
|
|
||||||
uniform vec3 lightPosition;
|
const int numberOfLights = 2;
|
||||||
uniform float constantAttenuation;
|
|
||||||
uniform float linearAttenuation;
|
|
||||||
uniform float quadraticAttenuation;
|
|
||||||
|
|
||||||
in VertexData {
|
uniform vec4 position[numberOfLights];
|
||||||
|
uniform vec4 specular[numberOfLights];
|
||||||
|
uniform vec4 diffuse[numberOfLights];
|
||||||
|
uniform float constantAttenuation[numberOfLights];
|
||||||
|
uniform float linearAttenuation[numberOfLights];
|
||||||
|
uniform float quadraticAttenuation[numberOfLights];
|
||||||
|
uniform float spotExponent[numberOfLights];
|
||||||
|
|
||||||
|
in VertexData {
|
||||||
vec3 Position;
|
vec3 Position;
|
||||||
vec3 Normal;
|
vec3 Normal;
|
||||||
vec2 TextureCoord;
|
vec2 TextureCoord;
|
||||||
} Input;
|
} Input;
|
||||||
|
|
||||||
|
vec3 scene_ambient = vec3(0.2, 0.2, 0.2);
|
||||||
|
|
||||||
out vec4 fragmentColor;
|
out vec4 fragmentColor;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
|
||||||
// Texture
|
// Texture
|
||||||
vec4 texel = texture2D(texture, Input.TextureCoord);
|
vec4 texel = texture2D(texture, Input.TextureCoord);
|
||||||
//vec4 texel1 = texture2D(texture1, Input.TextureCoord * 32.0);
|
|
||||||
//vec4 texel2 = texture2D(texture2, Input.TextureCoord * 100.0);
|
|
||||||
//vec4 blend = texture2D(blendmap, Input.TextureCoord);
|
|
||||||
|
|
||||||
//vec4 texel = (blend.x * texel0) + (blend.y * texel1) + (blend.z * texel2);
|
//vec4 texel = (blend.x * texel0) + (blend.y * texel1) + (blend.z * texel2);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Phong shading
|
// Phong shading
|
||||||
//
|
//
|
||||||
|
|
||||||
// Light
|
// Ambient light
|
||||||
//vec3 lightPosition = vec3(0, 0, 2);
|
vec3 La = scene_ambient; // Ambient light
|
||||||
vec3 Ls = vec3(1.0, 1.0, 0.9); // Specular light
|
|
||||||
vec3 Ld = vec3(1.0, 1.0, 0.9); // Diffuse light
|
|
||||||
vec3 La = vec3(0.6, 0.6, 0.6); // Ambient light
|
|
||||||
|
|
||||||
// Object
|
|
||||||
vec3 Ks = vec3(0.3, 0.3, 0.3); // Specular reflectance
|
vec3 Ks = vec3(0.3, 0.3, 0.3); // Specular reflectance
|
||||||
vec3 Kd = vec3(1.0, 1.0, 1.0); // Diffuse reflectance
|
vec3 Kd = vec3(1.0, 1.0, 1.0); // Diffuse reflectance
|
||||||
vec3 Ka = vec3(1.0, 1.0, 1.0); // Ambient reflectance
|
vec3 Ka = vec3(1.0, 1.0, 1.0); // Ambient reflectance
|
||||||
|
|
||||||
vec3 lightPosView = vec3(view * vec4(lightPosition, 1.0));
|
vec3 totalLighting = La * Ka;
|
||||||
|
|
||||||
|
float attenuation;
|
||||||
|
|
||||||
|
for(int i = 0; i < numberOfLights; i++)
|
||||||
|
{
|
||||||
|
// Light
|
||||||
|
//vec3 lightPosition = vec3(0, 0, 2);
|
||||||
|
vec3 Ls = specular[i]; // Specular light
|
||||||
|
vec3 Ld = diffuse[i]; // Diffuse light
|
||||||
|
|
||||||
|
|
||||||
|
// Object
|
||||||
|
|
||||||
|
vec3 lightPosView = vec3(view * vec4(LightPos[i], 1.0));
|
||||||
vec3 surfacePosition = vec3(model * vec4(Input.Position, 1.0));
|
vec3 surfacePosition = vec3(model * vec4(Input.Position, 1.0));
|
||||||
vec3 surfacePosView = vec3(view * vec4(surfacePosition, 1.0));
|
vec3 surfacePosView = vec3(view * vec4(surfacePosition, 1.0));
|
||||||
vec3 surfaceToLight = normalize(lightPosView - surfacePosView);
|
vec3 surfaceToLight = normalize(lightPosView - surfacePosView);
|
||||||
mat3 normalMatrix = transpose(inverse(mat3(view * model)));
|
mat3 normalMatrix = transpose(inverse(mat3(view * model)));
|
||||||
vec3 surfaceNormal = normalize(normalMatrix * Input.Normal);
|
vec3 surfaceNormal = normalize(normalMatrix * Input.Normal);
|
||||||
|
|
||||||
|
float dist = length(LightPos[i] - surfacePosition);
|
||||||
|
|
||||||
|
attenuation = 1.0 / (constantAttenuation
|
||||||
|
+ linearAttenuation * dist
|
||||||
|
+ quadraticAttenuation * pow(dist, 2.0));
|
||||||
|
|
||||||
|
attenuation = attenuation * pow(clampedCosine, spotExponent[i]);
|
||||||
|
|
||||||
|
// Diffuse light
|
||||||
|
float dotProd = dot(surfaceToLight, surfaceNormal);
|
||||||
|
dotProd = max(dotProd, 0.0);
|
||||||
|
|
||||||
|
Id = Ld * Kd * abs(dotProd) * attenuation;
|
||||||
|
|
||||||
// Specular light
|
// Specular light
|
||||||
vec3 reflection = reflect(-surfaceToLight, surfaceNormal);
|
vec3 reflection = reflect(-surfaceToLight, surfaceNormal);
|
||||||
float dotSpecular = dot(reflection, normalize(-surfacePosView));
|
float dotSpecular = dot(reflection, normalize(-surfacePosView));
|
||||||
dotSpecular = max(dotSpecular, 0.0);
|
dotSpecular = max(dotSpecular, 0.0);
|
||||||
float specularFactor = pow(dotSpecular, 30.0); // Specular factor
|
float specularFactor = pow(dotSpecular, 30.0); // Specular factor
|
||||||
vec3 Is = Ls * Ks * specularFactor;
|
|
||||||
|
Is = attenuation * Ls * Ks * specularFactor;
|
||||||
|
|
||||||
// Diffuse light
|
totalLighting = totalLighting + Id + Is;
|
||||||
float dotProd = dot(surfaceToLight, surfaceNormal);
|
}
|
||||||
dotProd = max(dotProd, 0.0);
|
fragmentColor = vec4(totalLighting, 1.0) * texel;
|
||||||
vec3 Id = Ld * Kd * abs(dotProd);
|
|
||||||
|
|
||||||
// Ambient light
|
|
||||||
vec3 Ia = La * Ka;
|
|
||||||
|
|
||||||
float dist = length(lightPosition - surfacePosition);
|
|
||||||
float attenuation = 1.0 / (constantAttenuation
|
|
||||||
+ linearAttenuation * dist
|
|
||||||
+ quadraticAttenuation * pow(dist, 2.0));
|
|
||||||
|
|
||||||
fragmentColor = vec4((Is + Id) * attenuation + Ia, 1.0) * texel;
|
|
||||||
|
|
||||||
//fragmentColor = vec4(Id, 1.0) * texel;
|
//fragmentColor = vec4(Id, 1.0) * texel;
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,19 @@ void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID p
|
|||||||
Model* model = m_CachedModels[modelComponent->ModelFile];
|
Model* model = m_CachedModels[modelComponent->ModelFile];
|
||||||
m_Renderer->AddModelToDraw(model, transformComponent->Position, transformComponent->Orientation);
|
m_Renderer->AddModelToDraw(model, transformComponent->Position, transformComponent->Orientation);
|
||||||
}
|
}
|
||||||
|
auto pointLightComponent = m_World->GetComponent<Components::PointLight>(entity, "PointLight");
|
||||||
|
if (pointLightComponent != nullptr)
|
||||||
|
{
|
||||||
|
|
||||||
|
m_Renderer->AddPointLightToDraw(
|
||||||
|
transformComponent->Position,
|
||||||
|
pointLightComponent->Specular,
|
||||||
|
pointLightComponent->Diffuse,
|
||||||
|
pointLightComponent->constantAttenuation,
|
||||||
|
pointLightComponent->linearAttenuation,
|
||||||
|
pointLightComponent->quadraticAttenuation,
|
||||||
|
pointLightComponent->spotExponent);
|
||||||
|
}
|
||||||
auto cameraComponent = m_World->GetComponent<Components::Camera>(entity, "Camera");
|
auto cameraComponent = m_World->GetComponent<Components::Camera>(entity, "Camera");
|
||||||
if (cameraComponent != nullptr)
|
if (cameraComponent != nullptr)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,115 @@
|
|||||||
|
# Max2Mtl Version 4.0 Mar 10th, 2001
|
||||||
|
#
|
||||||
|
# Multi/Sub Material__10791 (9) to come
|
||||||
|
#
|
||||||
|
newmtl Material__46
|
||||||
|
Ka 0.1 0.1 0.1
|
||||||
|
Kd 0.5 0.5 0.5
|
||||||
|
Ks 0.9 0.9 0.9
|
||||||
|
d 1.0
|
||||||
|
Ns 0.5
|
||||||
|
illum 2
|
||||||
|
#
|
||||||
|
newmtl Material__47
|
||||||
|
Ka 0.1 0.1 0.1
|
||||||
|
Kd 0.5 0.5 0.5
|
||||||
|
Ks 0.9 0.9 0.9
|
||||||
|
d 1.0
|
||||||
|
Ns 0.5
|
||||||
|
illum 2
|
||||||
|
#
|
||||||
|
newmtl Material__48
|
||||||
|
Ka 0.1 0.1 0.1
|
||||||
|
Kd 0.5 0.5 0.5
|
||||||
|
Ks 0.9 0.9 0.9
|
||||||
|
d 1.0
|
||||||
|
Ns 0.5
|
||||||
|
illum 2
|
||||||
|
#
|
||||||
|
newmtl Material__49
|
||||||
|
Ka 0.1 0.1 0.1
|
||||||
|
Kd 0.5 0.5 0.5
|
||||||
|
Ks 0.9 0.9 0.9
|
||||||
|
d 1.0
|
||||||
|
Ns 0.5
|
||||||
|
illum 2
|
||||||
|
#
|
||||||
|
newmtl Material__50
|
||||||
|
Ka 0.1 0.1 0.1
|
||||||
|
Kd 0.5 0.5 0.5
|
||||||
|
Ks 0.9 0.9 0.9
|
||||||
|
d 1.0
|
||||||
|
Ns 0.5
|
||||||
|
illum 2
|
||||||
|
#
|
||||||
|
newmtl Material__51
|
||||||
|
Ka 0.1 0.1 0.1
|
||||||
|
Kd 0.5 0.5 0.5
|
||||||
|
Ks 0.9 0.9 0.9
|
||||||
|
d 1.0
|
||||||
|
Ns 0.5
|
||||||
|
illum 2
|
||||||
|
#
|
||||||
|
newmtl Material__52
|
||||||
|
Ka 0.1 0.1 0.1
|
||||||
|
Kd 0.5 0.5 0.5
|
||||||
|
Ks 0.9 0.9 0.9
|
||||||
|
d 1.0
|
||||||
|
Ns 0.5
|
||||||
|
illum 2
|
||||||
|
#
|
||||||
|
newmtl Material__10657
|
||||||
|
Ka 0.6 0.6 0.6
|
||||||
|
Kd 0.6 0.6 0.6
|
||||||
|
Ks 0.9 0.9 0.9
|
||||||
|
d 1.0
|
||||||
|
Ns 0.0
|
||||||
|
illum 2
|
||||||
|
#
|
||||||
|
newmtl Material__10658
|
||||||
|
Ka 0.6 0.6 0.6
|
||||||
|
Kd 0.6 0.6 0.6
|
||||||
|
Ks 0.9 0.9 0.9
|
||||||
|
d 1.0
|
||||||
|
Ns 0.0
|
||||||
|
illum 2
|
||||||
|
#
|
||||||
|
# Multi/Sub Material__10791 done
|
||||||
|
#
|
||||||
|
# Multi/Sub Material__10737 (3) to come
|
||||||
|
#
|
||||||
|
newmtl Material__10678
|
||||||
|
Ka 1.0 1.0 1.0
|
||||||
|
Kd 1.0 1.0 1.0
|
||||||
|
Ks 0.9 0.9 0.9
|
||||||
|
d 1.0
|
||||||
|
Ns 0.0
|
||||||
|
illum 2
|
||||||
|
#
|
||||||
|
newmtl Material__69
|
||||||
|
Ka 0.6 0.6 0.6
|
||||||
|
Kd 0.6 0.6 0.6
|
||||||
|
Ks 0.9 0.9 0.9
|
||||||
|
d 1.0
|
||||||
|
Ns 0.0
|
||||||
|
illum 2
|
||||||
|
#
|
||||||
|
newmtl Material__10677
|
||||||
|
Ka 0.6 0.6 0.6
|
||||||
|
Kd 0.6 0.6 0.6
|
||||||
|
Ks 0.9 0.9 0.9
|
||||||
|
d 1.0
|
||||||
|
Ns 0.0
|
||||||
|
illum 2
|
||||||
|
#
|
||||||
|
# Multi/Sub Material__10737 done
|
||||||
|
#
|
||||||
|
newmtl 03_-_Default
|
||||||
|
Ka 0.5 0.5 0.5
|
||||||
|
Kd 0.5 0.5 0.5
|
||||||
|
Ks 0.9 0.9 0.9
|
||||||
|
d 1.0
|
||||||
|
Ns 0.0
|
||||||
|
illum 2
|
||||||
|
#
|
||||||
|
# EOF
|
||||||
Reference in New Issue
Block a user