Fixat med ljus
This commit is contained in:
@@ -34,12 +34,10 @@ void GameWorld::Initialize()
|
|||||||
// Fucking lights
|
// Fucking lights
|
||||||
ent = CreateEntity();
|
ent = CreateEntity();
|
||||||
transform = AddComponent<Components::Transform>(ent, "Transform");
|
transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||||
transform->Position = glm::vec3(0.f, 4.f, 0.f);
|
transform->Position = glm::vec3(0.f, 7.f, 0.f);
|
||||||
transform->Position = glm::vec3(10.f, 2.f, 5.f);
|
|
||||||
pointLight = AddComponent<Components::PointLight>(ent, "PointLight");
|
pointLight = AddComponent<Components::PointLight>(ent, "PointLight");
|
||||||
pointLight->Specular = glm::vec3(1.0, 1.0, 1.0);
|
pointLight->Specular = glm::vec3(1.0, 1.0, 1.0);
|
||||||
pointLight->Diffuse = glm::vec3(1.0, 1.0, 1.0);
|
pointLight->Diffuse = glm::vec3(0.0, 0.0, 5.0);
|
||||||
pointLight->Diffuse = glm::vec3(1.0, 1.0, 5.0);
|
|
||||||
pointLight->constantAttenuation = 0.f;
|
pointLight->constantAttenuation = 0.f;
|
||||||
pointLight->linearAttenuation = 1.f;
|
pointLight->linearAttenuation = 1.f;
|
||||||
pointLight->quadraticAttenuation = 0.f;
|
pointLight->quadraticAttenuation = 0.f;
|
||||||
@@ -48,13 +46,10 @@ void GameWorld::Initialize()
|
|||||||
model->ModelFile = "Models/sphere.obj";
|
model->ModelFile = "Models/sphere.obj";
|
||||||
ent = CreateEntity();
|
ent = CreateEntity();
|
||||||
transform = AddComponent<Components::Transform>(ent, "Transform");
|
transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||||
transform->Position = glm::vec3(10.f, 4.f, 0.f);
|
transform->Position = glm::vec3(10.f, 7.f, 0.f);
|
||||||
transform->Position = glm::vec3(0.f, 2.f, 5.f);
|
|
||||||
pointLight = AddComponent<Components::PointLight>(ent, "PointLight");
|
pointLight = AddComponent<Components::PointLight>(ent, "PointLight");
|
||||||
pointLight->Specular = glm::vec3(1.0, 1.0, 1.0);
|
pointLight->Specular = glm::vec3(1.0, 1.0, 1.0);
|
||||||
pointLight->Diffuse = glm::vec3(1.0, 1.0, 1.0);
|
pointLight->Diffuse = glm::vec3(0.0, 5.0, 0.0);
|
||||||
pointLight->Specular = glm::vec3(3.0, 3.0, 3.0);
|
|
||||||
pointLight->Diffuse = glm::vec3(3.0, 0.0, 0.0);
|
|
||||||
pointLight->constantAttenuation = 0.f;
|
pointLight->constantAttenuation = 0.f;
|
||||||
pointLight->linearAttenuation = 1.f;
|
pointLight->linearAttenuation = 1.f;
|
||||||
pointLight->quadraticAttenuation = 0.f;
|
pointLight->quadraticAttenuation = 0.f;
|
||||||
@@ -63,12 +58,10 @@ void GameWorld::Initialize()
|
|||||||
model->ModelFile = "Models/sphere.obj";
|
model->ModelFile = "Models/sphere.obj";
|
||||||
ent = CreateEntity();
|
ent = CreateEntity();
|
||||||
transform = AddComponent<Components::Transform>(ent, "Transform");
|
transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||||
transform->Position = glm::vec3(0.f, -4.f, 0.f);
|
transform->Position = glm::vec3(-10.f, 7.f, 0.f);
|
||||||
transform->Position = glm::vec3(-10.f, 2.f, 5.f);
|
|
||||||
pointLight = AddComponent<Components::PointLight>(ent, "PointLight");
|
pointLight = AddComponent<Components::PointLight>(ent, "PointLight");
|
||||||
pointLight->Specular = glm::vec3(1.0, 1.0, 1.0);
|
pointLight->Specular = glm::vec3(1.0, 1.0, 1.0);
|
||||||
pointLight->Diffuse = glm::vec3(1.0, 1.0, 1.0);
|
pointLight->Diffuse = glm::vec3(5.0, 0.0, 0.0);
|
||||||
pointLight->Diffuse = glm::vec3(0.0, 3.0, 0.0);
|
|
||||||
pointLight->constantAttenuation = 0.f;
|
pointLight->constantAttenuation = 0.f;
|
||||||
pointLight->linearAttenuation = 1.f;
|
pointLight->linearAttenuation = 1.f;
|
||||||
pointLight->quadraticAttenuation = 0.f;
|
pointLight->quadraticAttenuation = 0.f;
|
||||||
@@ -91,6 +84,13 @@ void GameWorld::Initialize()
|
|||||||
transform->Scale = glm::vec3(1.0f);
|
transform->Scale = glm::vec3(1.0f);
|
||||||
model = AddComponent<Components::Model>(m_Player, "Model");
|
model = AddComponent<Components::Model>(m_Player, "Model");
|
||||||
model->ModelFile = "Models/ship.obj";
|
model->ModelFile = "Models/ship.obj";
|
||||||
|
pointLight = AddComponent<Components::PointLight>(m_Player, "PointLight");
|
||||||
|
pointLight->Specular = glm::vec3(1.0, 1.0, 1.0);
|
||||||
|
pointLight->Diffuse = glm::vec3(5.0, 0.0, 0.0);
|
||||||
|
pointLight->constantAttenuation = 0.f;
|
||||||
|
pointLight->linearAttenuation = 1.f;
|
||||||
|
pointLight->quadraticAttenuation = 0.f;
|
||||||
|
pointLight->spotExponent = 0.0f;
|
||||||
AddComponent<Components::Input>(m_Player, "Input");
|
AddComponent<Components::Input>(m_Player, "Input");
|
||||||
auto bounds = AddComponent<Components::Bounds>(m_Player, "Bounds");
|
auto bounds = AddComponent<Components::Bounds>(m_Player, "Bounds");
|
||||||
bounds->Origin = glm::vec3(0.f, 0.f, 2.f);
|
bounds->Origin = glm::vec3(0.f, 0.f, 2.f);
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ Renderer::Renderer()
|
|||||||
m_SunPosition = glm::vec3(0, 10, 10);
|
m_SunPosition = glm::vec3(0, 10, 10);
|
||||||
m_SunTarget = glm::vec3(0, 0, 0);
|
m_SunTarget = glm::vec3(0, 0, 0);
|
||||||
m_SunProjection = glm::ortho<float>(-20, 20, -20, 20, -10, 20);
|
m_SunProjection = glm::ortho<float>(-20, 20, -20, 20, -10, 20);
|
||||||
|
Lights = 512;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::Initialize()
|
void Renderer::Initialize()
|
||||||
@@ -138,12 +139,12 @@ void Renderer::Draw(double dt)
|
|||||||
glBindVertexArray(m_DebugAABB);
|
glBindVertexArray(m_DebugAABB);
|
||||||
glDrawArrays(GL_LINES, 0, 24);
|
glDrawArrays(GL_LINES, 0, 24);
|
||||||
}
|
}
|
||||||
AABBsToRender.clear();
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DrawDebugShadowMap();
|
DrawDebugShadowMap();
|
||||||
|
|
||||||
ModelsToRender.clear();
|
ClearStuff();
|
||||||
glfwSwapBuffers(m_Window);
|
glfwSwapBuffers(m_Window);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,13 +178,13 @@ void Renderer::DrawScene()
|
|||||||
|
|
||||||
m_ShaderProgram.Bind();
|
m_ShaderProgram.Bind();
|
||||||
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "DepthMVP"), 1, GL_FALSE, glm::value_ptr(depthBiasMVP));
|
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "DepthMVP"), 1, GL_FALSE, glm::value_ptr(depthBiasMVP));
|
||||||
glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "position"), 3, Light_position.data());
|
glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "position"), Lights, Light_position.data());
|
||||||
glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "specular"), 3, Light_specular.data());
|
glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "specular"), Lights, Light_specular.data());
|
||||||
glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "diffuse"), 3, Light_diffuse.data());
|
glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "diffuse"), Lights, Light_diffuse.data());
|
||||||
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "constantAttenuation"), 3, Light_constantAttenuation.data());
|
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "constantAttenuation"), Lights, Light_constantAttenuation.data());
|
||||||
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "linearAttenuation"), 3, Light_linearAttenuation.data());
|
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "linearAttenuation"), Lights, Light_linearAttenuation.data());
|
||||||
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "quadraticAttenuation"), 3, Light_quadraticAttenuation.data());
|
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "quadraticAttenuation"), Lights, Light_quadraticAttenuation.data());
|
||||||
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "spotExponent"), 3, Light_spotExponent.data());
|
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "spotExponent"), Lights, Light_spotExponent.data());
|
||||||
if (m_DrawWireframe) {
|
if (m_DrawWireframe) {
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||||
}
|
}
|
||||||
@@ -315,7 +316,7 @@ void Renderer::AddPointLightToDraw(
|
|||||||
Light_linearAttenuation.push_back(_linearAttenuation);
|
Light_linearAttenuation.push_back(_linearAttenuation);
|
||||||
Light_quadraticAttenuation.push_back(_quadraticAttenuation);
|
Light_quadraticAttenuation.push_back(_quadraticAttenuation);
|
||||||
Light_spotExponent.push_back(_spotExponent);
|
Light_spotExponent.push_back(_spotExponent);
|
||||||
|
Lights = Light_constantAttenuation.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint Renderer::CreateQuad()
|
GLuint Renderer::CreateQuad()
|
||||||
@@ -417,3 +418,16 @@ void Renderer::AddAABBToDraw(glm::vec3 origin, glm::vec3 volumeVector)
|
|||||||
model *= glm::scale(volumeVector);
|
model *= glm::scale(volumeVector);
|
||||||
AABBsToRender.push_back(model);
|
AABBsToRender.push_back(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Renderer::ClearStuff()
|
||||||
|
{
|
||||||
|
AABBsToRender.clear();
|
||||||
|
ModelsToRender.clear();
|
||||||
|
Light_position.clear();
|
||||||
|
Light_specular.clear();
|
||||||
|
Light_diffuse.clear();
|
||||||
|
Light_constantAttenuation.clear();
|
||||||
|
Light_linearAttenuation.clear();
|
||||||
|
Light_quadraticAttenuation.clear();
|
||||||
|
Light_spotExponent.clear();
|
||||||
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ public:
|
|||||||
glm::mat4 projectionMatrix;
|
glm::mat4 projectionMatrix;
|
||||||
|
|
||||||
int HEIGHT, WIDTH;
|
int HEIGHT, WIDTH;
|
||||||
|
float Lights;
|
||||||
|
|
||||||
struct ModelData
|
struct ModelData
|
||||||
{
|
{
|
||||||
@@ -102,6 +103,7 @@ private:
|
|||||||
ShaderProgram m_ShaderProgramShadowsDrawDepth;
|
ShaderProgram m_ShaderProgramShadowsDrawDepth;
|
||||||
ShaderProgram m_ShaderProgramDebugAABB;
|
ShaderProgram m_ShaderProgramDebugAABB;
|
||||||
|
|
||||||
|
void ClearStuff();
|
||||||
void DrawScene();
|
void DrawScene();
|
||||||
void DrawModels(ShaderProgram &shader);
|
void DrawModels(ShaderProgram &shader);
|
||||||
void DrawShadowMap();
|
void DrawShadowMap();
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ uniform mat4 view;
|
|||||||
layout(binding=0) uniform sampler2D texture0;
|
layout(binding=0) uniform sampler2D texture0;
|
||||||
layout(binding=1) uniform sampler2D shadowMap;
|
layout(binding=1) uniform sampler2D shadowMap;
|
||||||
|
|
||||||
const int numberOfLights = 3;
|
const int numberOfLights = 128;
|
||||||
|
|
||||||
uniform vec3 position[numberOfLights];
|
uniform vec3 position[numberOfLights];
|
||||||
uniform vec3 specular[numberOfLights];
|
uniform vec3 specular[numberOfLights];
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ void Systems::LevelGenerationSystem::SpawnObstacle()
|
|||||||
bounds = m_World->AddComponent<Components::Bounds>(ent, "Bounds");
|
bounds = m_World->AddComponent<Components::Bounds>(ent, "Bounds");
|
||||||
collision = m_World->AddComponent<Components::Collision>(ent, "Collision");
|
collision = m_World->AddComponent<Components::Collision>(ent, "Collision");
|
||||||
model = m_World->AddComponent<Components::Model>(ent, "Model");
|
model = m_World->AddComponent<Components::Model>(ent, "Model");
|
||||||
|
//pointLight = m_World->AddComponent<Components::PointLight>(ent, "PointLight");
|
||||||
|
|
||||||
positionRandom = -500 + (rand() % 1000);
|
positionRandom = -500 + (rand() % 1000);
|
||||||
|
|
||||||
@@ -47,6 +48,13 @@ void Systems::LevelGenerationSystem::SpawnObstacle()
|
|||||||
transform->Position = glm::vec3( positionRandom, startyz); // fix position
|
transform->Position = glm::vec3( positionRandom, startyz); // fix position
|
||||||
bounds->VolumeVector = glm::vec3(1, 1, 1);
|
bounds->VolumeVector = glm::vec3(1, 1, 1);
|
||||||
bounds->Origin = glm::vec3(0,1,0);
|
bounds->Origin = glm::vec3(0,1,0);
|
||||||
|
// pointLight->Specular = glm::vec3(1.0, 1.0, 1.0);
|
||||||
|
// pointLight->Diffuse = glm::vec3(1.0, 1.0, 1.0);
|
||||||
|
// pointLight->Diffuse = glm::vec3(0.0, 3.0, 0.0);
|
||||||
|
// pointLight->constantAttenuation = 0.f;
|
||||||
|
// pointLight->linearAttenuation = 1.f;
|
||||||
|
// pointLight->quadraticAttenuation = 0.f;
|
||||||
|
// pointLight->spotExponent = 0.0f;
|
||||||
model->ModelFile = "Models/obstacle_cube_1.obj";
|
model->ModelFile = "Models/obstacle_cube_1.obj";
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "Components/Bounds.h"
|
#include "Components/Bounds.h"
|
||||||
#include "Components/Collision.h"
|
#include "Components/Collision.h"
|
||||||
#include "Components/Model.h"
|
#include "Components/Model.h"
|
||||||
|
#include "Components/PointLight.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Systems
|
namespace Systems
|
||||||
@@ -34,6 +35,7 @@ namespace Systems
|
|||||||
std::shared_ptr<Components::Bounds> bounds;
|
std::shared_ptr<Components::Bounds> bounds;
|
||||||
std::shared_ptr<Components::Collision> collision;
|
std::shared_ptr<Components::Collision> collision;
|
||||||
std::shared_ptr<Components::Model> model;
|
std::shared_ptr<Components::Model> model;
|
||||||
|
std::shared_ptr<Components::PointLight> pointLight;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
Systems::PlayerSystem::PlayerSystem( World* world ) : System(world)
|
Systems::PlayerSystem::PlayerSystem( World* world ) : System(world)
|
||||||
{
|
{
|
||||||
|
speed = 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Systems::PlayerSystem::Update(double dt)
|
void Systems::PlayerSystem::Update(double dt)
|
||||||
@@ -18,8 +19,6 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
|||||||
if (input == nullptr)
|
if (input == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
float speed = 20.0f;
|
|
||||||
|
|
||||||
auto name = m_World->GetProperty<std::string>(entity, "Name");
|
auto name = m_World->GetProperty<std::string>(entity, "Name");
|
||||||
if (name == "Camera") {
|
if (name == "Camera") {
|
||||||
|
|
||||||
@@ -60,7 +59,6 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
|||||||
// TOUCHING THIS CODE MIGHT COUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS
|
// TOUCHING THIS CODE MIGHT COUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
name = m_World->GetProperty<std::string>(entity, "Name");
|
name = m_World->GetProperty<std::string>(entity, "Name");
|
||||||
if (name == "PlayerShip")
|
if (name == "PlayerShip")
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace Systems
|
|||||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
float speed;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user