Load lights from Json file and fix a bug in pointshadows

This commit is contained in:
2021-01-16 11:50:13 +01:00
parent 831c726f4d
commit 74a604de8b
15 changed files with 251 additions and 182 deletions

4
.gitignore vendored
View File

@@ -1,7 +1,5 @@
build build
.directory .directory
lib/assimp/libassimp.so.5.0.0 .vscode
res/models res/models
res/textures res/textures
.kdev4/Fall-Fever.kdev4
Fall-Fever.kdev4

60
.kdev4/Fall-Fever.kdev4 Normal file
View File

@@ -0,0 +1,60 @@
[Buildset]
BuildItems=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x01\x00\x00\x00\x0b\x00\x00\x00\x00\x01\x00\x00\x00\x14\x00F\x00a\x00l\x00l\x00-\x00F\x00e\x00v\x00e\x00r)
[CMake]
Build Directory Count=1
Current Build Directory Index-Host-System=0
[CMake][CMake Build Directory 0]
Build Directory Path=/home/derek/Projekte/CXX/OpenGL/Fall-Fever/build
Build Type=DEBUG
CMake Binary=/usr/bin/cmake
CMake Executable=/usr/bin/cmake
Environment Profile=
Extra Arguments=
Install Directory=/usr/local
Runtime=Host-System
[Launch]
Launch Configurations=Launch Configuration 0,Launch Configuration 1
[Launch][Launch Configuration 0]
Configured Launch Modes=execute
Configured Launchers=nativeAppLauncher
Name=Fall-Fever
Type=Native Application
[Launch][Launch Configuration 0][Data]
Arguments=
Dependencies=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x01\x00\x00\x00\x0b\x00\x00\x00\x00\x03\x00\x00\x00\x14\x00F\x00a\x00l\x00l\x00-\x00F\x00e\x00v\x00e\x00r\x00\x00\x00\x06\x00s\x00r\x00c\x00\x00\x00\x14\x00F\x00a\x00l\x00l\x00-\x00F\x00e\x00v\x00e\x00r)
Dependency Action=Build
EnvironmentGroup=
Executable=file:///home/derek/Projekte/CXX/OpenGL/Fall-Fever
External Terminal=konsole --noclose --workdir %workdir -e %exe
Kill Before Executing Again=4194304
Project Target=Fall-Fever,src,Fall-Fever
Use External Terminal=false
Working Directory=file:///home/derek/Projekte/CXX/OpenGL/Fall-Fever
isExecutable=false
[Launch][Launch Configuration 1]
Configured Launch Modes=execute
Configured Launchers=nativeAppLauncher
Name=RenderDoc
Type=Native Application
[Launch][Launch Configuration 1][Data]
Arguments=
Dependencies=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x01\x00\x00\x00\x0b\x00\x00\x00\x00\x03\x00\x00\x00\x14\x00F\x00a\x00l\x00l\x00-\x00F\x00e\x00v\x00e\x00r\x00\x00\x00\x06\x00s\x00r\x00c\x00\x00\x00\x14\x00F\x00a\x00l\x00l\x00-\x00F\x00e\x00v\x00e\x00r)
Dependency Action=Build
EnvironmentGroup=
Executable=file:///home/derek/Projekte/CXX/OpenGL/Fall-Fever
External Terminal=/home/derek/Tools/RenderDoc/bin/renderdoccmd capture %exe
Kill Before Executing Again=4194304
Project Target=Fall-Fever,src,Fall-Fever
Use External Terminal=true
Working Directory=file:///home/derek/Projekte/CXX/OpenGL/Fall-Fever
isExecutable=false
[Project]
VersionControlSupport=kdevgit

29
.vscode/launch.json vendored
View File

@@ -1,29 +0,0 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Starten",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/src/Fall-Fever",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": flase,
"MIMode": "gdb",
"preLaunchTask": "Build",
"setupCommands": [
{
"description": "Automatische Strukturierung und Einrückung für \"gdb\" aktivieren",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

78
.vscode/settings.json vendored
View File

@@ -1,78 +0,0 @@
{
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"files.associations": {
"*.h": "c",
"ostream": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"ranges": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"cinttypes": "cpp",
"typeinfo": "cpp",
"csignal": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"hash_map": "cpp",
"strstream": "cpp",
"bitset": "cpp",
"chrono": "cpp",
"complex": "cpp",
"condition_variable": "cpp",
"list": "cpp",
"map": "cpp",
"set": "cpp",
"unordered_set": "cpp",
"ratio": "cpp",
"fstream": "cpp",
"future": "cpp",
"iomanip": "cpp",
"mutex": "cpp",
"sstream": "cpp",
"stop_token": "cpp",
"thread": "cpp",
"cfenv": "cpp",
"typeindex": "cpp",
"valarray": "cpp",
"variant": "cpp",
"forward_list": "cpp"
}
}

20
.vscode/tasks.json vendored
View File

@@ -1,20 +0,0 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Build",
"type": "shell",
"command": "cmake --build . -j4",
"options": {
"cwd": "build"
},
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}

4
Fall-Fever.kdev4 Normal file
View File

@@ -0,0 +1,4 @@
[Project]
CreatedFrom=CMakeLists.txt
Manager=KDevCMakeManager
Name=Fall-Fever

View File

@@ -9,7 +9,7 @@ Size=894,195
Collapsed=0 Collapsed=0
[Window][Debug Utils] [Window][Debug Utils]
Pos=3,6 Pos=-1,6
Size=791,379 Size=791,379
Collapsed=0 Collapsed=0

14
res/lights.json Normal file
View File

@@ -0,0 +1,14 @@
{
"directionalLight": {
"intensity": 0.5,
"direction": [-0.2, -1.0, -0.3],
"color": [1.0, 1.0, 1.0],
},
"pointLights": [
{
"intensity": 10.0,
"position": [0.0, 1.0, 0.0],
"color": [1.0, 1.0, 1.0]
}
]
}

View File

@@ -109,8 +109,7 @@ void Controller::run()
} }
static glm::vec3 lightColor = glm::vec3(1.f); static glm::vec3 lightColor = glm::vec3(1.f);
static float intensity = 20.f; static float intensity = 20.f;
world->updatePointLight(0, true, world->getEntityByName("light")->getPosition(), lightColor * intensity); world->updatePointLight(0, true, world->getEntityByName("light")->getPosition(), lightColor, intensity);
world->updateDirectionalLight(true, glm::vec3(-0.2f, -1.0f, -0.3f), lightColor * 0.25f);
getShaderProgramByName("lightProgram")->bind(); getShaderProgramByName("lightProgram")->bind();
getShaderProgramByName("lightProgram")->setUniform("v_lightColor", lightColor * 100.0f); getShaderProgramByName("lightProgram")->setUniform("v_lightColor", lightColor * 100.0f);
getShaderProgramByName("lightProgram")->unbind(); getShaderProgramByName("lightProgram")->unbind();
@@ -145,7 +144,7 @@ void Controller::run()
pp_framebuffer->render(); pp_framebuffer->render();
#ifdef _DEBUG #ifdef _DEBUG
renderImGui(world, &world->getPointLights()[0], &lightColor, &rotateEntity, &rotateLightSource, getShaderProgramByName("postProcessingProgram"), &intensity, &drawShadows); renderImGui(world, world->getPointLights()[0], &lightColor, &rotateEntity, &rotateLightSource, getShaderProgramByName("postProcessingProgram"), &intensity, &drawShadows);
#endif #endif
glfwSwapBuffers(gameWindow->getGLFWwindow()); glfwSwapBuffers(gameWindow->getGLFWwindow());

View File

@@ -130,6 +130,83 @@ std::vector<ShaderProgram *> JsonParser::getShaderPrograms()
return temp_shaderPrograms; return temp_shaderPrograms;
} }
std::vector<Light*> JsonParser::getLights(ShaderProgram* shaderProgram)
{
std::vector<Light*> temp_lights;
glm::vec3 light_direction = {1.0f, 0.0f, 0.0f};
glm::vec3 light_position = {};
glm::vec3 light_color = {1.0f, 1.0f, 1.0f};
float light_intensity = 10.0f;
const Json::Value directionalLightsJson = root["directionalLight"];
const Json::Value directionJson = directionalLightsJson["direction"];
Json::Value colorJson = directionalLightsJson["color"];
Json::Value intensityJson = directionalLightsJson["intensity"];
if(!intensityJson.empty()) {
light_intensity = intensityJson.asFloat();
}
if(!directionJson.empty()) {
light_direction.x = directionJson[0].asFloat();
light_direction.y = directionJson[1].asFloat();
light_direction.z = directionJson[2].asFloat();
}
if(!colorJson.empty()) {
light_color.x = colorJson[0].asFloat();
light_color.y = colorJson[1].asFloat();
light_color.z = colorJson[2].asFloat();
}
DirectionalLight *current_directionalLight = new DirectionalLight(light_direction, light_color, light_intensity, shaderProgram);
current_directionalLight->setActive(true);
temp_lights.push_back(current_directionalLight);
// Pointlights
const Json::Value pointLightsJson = root["pointLights"];
unsigned int index = 0;
for (; index < pointLightsJson.size(); index++) {
PointLight *current_pointLight;
const Json::Value positionJson = pointLightsJson[index]["position"];
colorJson = pointLightsJson[index]["color"];
intensityJson = pointLightsJson[index]["intensity"];
if(!intensityJson.empty()) {
light_intensity = intensityJson.asFloat();
}
if(!positionJson.empty()) {
light_position.x = positionJson[0].asFloat();
light_position.y = positionJson[1].asFloat();
light_position.z = positionJson[2].asFloat();
}
if(!colorJson.empty()) {
light_color.x = colorJson[0].asFloat();
light_color.y = colorJson[1].asFloat();
light_color.z = colorJson[2].asFloat();
}
current_pointLight = new PointLight(light_position, light_color, light_intensity, shaderProgram);
current_pointLight->setActive(true);
temp_lights.push_back(current_pointLight);
}
// In case there aren't enough PointLights defined in the Json file
for(; NUM_POINT_LIGHTS - index > 0; index++) {
const glm::vec3 default_position(0.0f);
const glm::vec3 default_color(1.0f);
const float default_intensity = 10.0f;
PointLight *current_pointLight = new PointLight(default_position, default_color, default_intensity, shaderProgram);
current_pointLight->setActive(false);
temp_lights.push_back(current_pointLight);
}
return temp_lights;
}
Skybox *JsonParser::getSkybox(Model *cubeModel, ShaderProgram *skyboxProgram) Skybox *JsonParser::getSkybox(Model *cubeModel, ShaderProgram *skyboxProgram)
{ {
Skybox* temp_skybox; Skybox* temp_skybox;

View File

@@ -3,6 +3,7 @@
#include "Model.h" #include "Model.h"
#include "Entity.h" #include "Entity.h"
#include "ShaderProgram.h" #include "ShaderProgram.h"
#include "Light.h"
#include <jsoncpp/json/json.h> #include <jsoncpp/json/json.h>
#include <string> #include <string>
@@ -16,6 +17,7 @@ public:
std::vector<Model*> getModels(); std::vector<Model*> getModels();
std::vector<Entity*> getEntities(std::vector<Model*> &models, std::vector<ShaderProgram*> shaderPrograms); std::vector<Entity*> getEntities(std::vector<Model*> &models, std::vector<ShaderProgram*> shaderPrograms);
std::vector<Light*> getLights(ShaderProgram* shaderProgram);
Skybox *getSkybox(Model *cubeModel, ShaderProgram *skyboxProgram); Skybox *getSkybox(Model *cubeModel, ShaderProgram *skyboxProgram);
std::vector<ShaderProgram*> getShaderPrograms(); std::vector<ShaderProgram*> getShaderPrograms();

View File

@@ -2,8 +2,22 @@
#include <string> #include <string>
uint32_t Light::id_counter = 0;
// Light // Light
Light::Light(glm::vec3 color, float intensity, ShaderProgram* shaderProgram) :
shaderProgram(shaderProgram),
intensity(intensity)
{
id = id_counter++;
lightColor = color * intensity;
diffuseColor = lightColor * glm::vec3(1.0f);
ambientColor = diffuseColor * glm::vec3(0.002f);
specularColor = lightColor * glm::vec3(1.0f);
}
glm::vec3 Light::getColor() glm::vec3 Light::getColor()
{ {
return lightColor; return lightColor;
@@ -17,13 +31,19 @@ void Light::setShaderProgram(ShaderProgram* shaderProgram)
void Light::setColor(glm::vec3 color) void Light::setColor(glm::vec3 color)
{ {
lightColor = color; lightColor = color * intensity;
diffuseColor = lightColor * glm::vec3(1.0f); diffuseColor = lightColor * glm::vec3(1.0f);
ambientColor = diffuseColor * glm::vec3(0.002f); ambientColor = diffuseColor * glm::vec3(0.002f);
specularColor = lightColor * glm::vec3(1.0f); specularColor = lightColor * glm::vec3(1.0f);
update(); update();
} }
void Light::setIntensity(float intensity)
{
this->intensity = intensity;
}
void Light::setActive(bool active) void Light::setActive(bool active)
{ {
isActive = active; isActive = active;
@@ -32,8 +52,9 @@ void Light::setActive(bool active)
// PointLight // PointLight
PointLight::PointLight(ShaderProgram *shaderProgram) : PointLight::PointLight(glm::vec3 position, glm::vec3 color, float intensity, ShaderProgram *shaderProgram) :
Light(shaderProgram) Light(color, intensity, shaderProgram),
position(position)
{ {
// Empty // Empty
} }
@@ -54,7 +75,7 @@ void PointLight::update()
std::string PointLight::getStructMemberName() std::string PointLight::getStructMemberName()
{ {
std::string temp = "u_pointLight[" + std::to_string(lightId) + "]."; std::string temp = "u_pointLight[" + std::to_string(id) + "].";
return temp; return temp;
} }
@@ -74,15 +95,11 @@ void PointLight::setParameters(float K_q)
this->K_q = K_q; this->K_q = K_q;
} }
void PointLight::setId(unsigned int id)
{
this->lightId = id;
}
// DirectionalLight // DirectionalLight
DirectionalLight::DirectionalLight(ShaderProgram *shaderProgram) : DirectionalLight::DirectionalLight(glm::vec3 direction, glm::vec3 color, float intensity, ShaderProgram *shaderProgram) :
Light(shaderProgram) Light(color, intensity, shaderProgram),
direction(direction)
{ {
// Empty // Empty
} }

View File

@@ -4,7 +4,7 @@
#include "ShaderProgram.h" #include "ShaderProgram.h"
#define NUM_POINT_LIGHTS 16 #define NUM_POINT_LIGHTS 4
class Light class Light
{ {
@@ -15,19 +15,25 @@ public:
void setActive(bool active); void setActive(bool active);
void setColor(glm::vec3 color); void setColor(glm::vec3 color);
void setIntensity(float intensity);
void setShaderProgram(ShaderProgram *shaderProgram); void setShaderProgram(ShaderProgram *shaderProgram);
glm::vec3 getColor(); glm::vec3 getColor();
protected: protected:
Light(ShaderProgram *shaderProgram) : shaderProgram(shaderProgram) {} Light(glm::vec3 color, float intensity, ShaderProgram *shaderProgram);
protected: protected:
ShaderProgram *shaderProgram; ShaderProgram *shaderProgram;
bool isActive = false; uint32_t id;
static uint32_t id_counter;
bool isActive;
bool shouldCastShadow = true; bool shouldCastShadow = true;
float intensity;
// Color // Color
glm::vec3 lightColor; glm::vec3 lightColor;
glm::vec3 diffuseColor; glm::vec3 diffuseColor;
@@ -38,12 +44,11 @@ protected:
class PointLight : public Light class PointLight : public Light
{ {
public: public:
PointLight(ShaderProgram *shaderProgram); PointLight(glm::vec3 position, glm::vec3 color, float intensity, ShaderProgram *shaderProgram);
~PointLight() = default; ~PointLight() = default;
void setPosition(glm::vec3 position); void setPosition(glm::vec3 position);
void setParameters(float K_q); void setParameters(float K_q);
void setId(unsigned int id);
glm::vec3 getPosition(); glm::vec3 getPosition();
@@ -52,8 +57,6 @@ private:
std::string getStructMemberName(); std::string getStructMemberName();
private: private:
unsigned int lightId;
glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f); glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f);
float K_q = 0.032f; float K_q = 0.032f;
@@ -62,7 +65,7 @@ private:
class DirectionalLight : public Light class DirectionalLight : public Light
{ {
public: public:
DirectionalLight(ShaderProgram *shaderProgram); DirectionalLight(glm::vec3 direction, glm::vec3 color, float intensity, ShaderProgram *shaderProgram);
void setDirection(glm::vec3 direction); void setDirection(glm::vec3 direction);

View File

@@ -6,16 +6,8 @@
World::World(std::vector<ShaderProgram*> shaderPrograms) : World::World(std::vector<ShaderProgram*> shaderPrograms) :
shaderProgram(Controller::getShaderProgramByName(shaderPrograms, "defaultProgram")), shaderProgram(Controller::getShaderProgramByName(shaderPrograms, "defaultProgram")),
directionalLight(shaderProgram),
depthMapDirectionalFBO(DEPTHMAP_NORMAL, SHADOW_RES) depthMapDirectionalFBO(DEPTHMAP_NORMAL, SHADOW_RES)
{ {
// PointLights
for (unsigned int i = 0; i < NUM_POINT_LIGHTS; i++) {
PointLight new_pointLight(shaderProgram);
new_pointLight.setId(i);
pointLights.push_back(new_pointLight);
}
// Create 4 depthMaps // Create 4 depthMaps
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
DepthMap *temp_depthMap = new DepthMap(DEPTHMAP_CUBEMAP, SHADOW_RES); DepthMap *temp_depthMap = new DepthMap(DEPTHMAP_CUBEMAP, SHADOW_RES);
@@ -27,10 +19,13 @@ World::World(std::vector<ShaderProgram*> shaderPrograms) :
shaderProgram->setUniform("u_material.shininess", 100.0f); shaderProgram->setUniform("u_material.shininess", 100.0f);
shaderProgram->unbind(); shaderProgram->unbind();
JsonParser worldParser("res/models.json"); JsonParser modelParser("res/models.json");
models = worldParser.getModels(); models = modelParser.getModels();
entities = worldParser.getEntities(models, shaderPrograms); entities = modelParser.getEntities(models, shaderPrograms);
skybox = worldParser.getSkybox(getModelByName("cube"), Controller::getShaderProgramByName(shaderPrograms, "skyboxProgram")); skybox = modelParser.getSkybox(getModelByName("cube"), Controller::getShaderProgramByName(shaderPrograms, "skyboxProgram"));
JsonParser lightParser("res/lights.json");
lights = lightParser.getLights(shaderProgram);
} }
World::~World() World::~World()
@@ -74,19 +69,21 @@ void World::clearEntities()
} }
} }
void World::updatePointLight(unsigned int lightId, bool active, glm::vec3 position, glm::vec3 color) void World::updatePointLight(unsigned int lightId, bool active, glm::vec3 position, glm::vec3 color, float intensity)
{ {
pointLights[lightId].setActive(active); std::vector<PointLight*> pointLights = getPointLights();
pointLights[lightId].setPosition(position); pointLights[lightId]->setActive(active);
pointLights[lightId].setColor(color); pointLights[lightId]->setPosition(position);
pointLights[lightId]->setIntensity(intensity);
pointLights[lightId]->setColor(color);
} }
void World::updateDirectionalLight(bool active, glm::vec3 direction, glm::vec3 color) void World::updateDirectionalLight(bool active, glm::vec3 direction, glm::vec3 color)
{ {
directionalLight.setActive(active); DirectionalLight *directionalLight = getDirectionalLight();
directionalLight.setDirection(direction); directionalLight->setActive(active);
directionalLight.setDirection(glm::vec3(-0.2f, -1.0f, -0.3f)); directionalLight->setDirection(direction);
directionalLight.setColor(color); directionalLight->setColor(color);
} }
void World::draw(glm::mat4 viewProjMatrix, glm::vec3 viewPosition) void World::draw(glm::mat4 viewProjMatrix, glm::vec3 viewPosition)
@@ -140,6 +137,7 @@ void World::calculateShadows(ShaderProgram *directionalShaderProgram, ShaderProg
shaderProgram->unbind(); shaderProgram->unbind();
// --- Point shadows --- // --- Point shadows ---
std::vector<PointLight*> pointLights = getPointLights();
// 4 depthMaps for 4 point lights // 4 depthMaps for 4 point lights
for (int i = 0; i < 1; i++) { for (int i = 0; i < 1; i++) {
@@ -149,11 +147,11 @@ void World::calculateShadows(ShaderProgram *directionalShaderProgram, ShaderProg
// Create 6 view matrices for every face of the cubeMap // Create 6 view matrices for every face of the cubeMap
std::vector<glm::mat4> viewProjMatrices; std::vector<glm::mat4> viewProjMatrices;
glm::vec3 lightPos = pointLights[i].getPosition(); glm::vec3 lightPos = pointLights[i]->getPosition();
viewProjMatrices.push_back(pointLightProjection * glm::lookAt(lightPos, lightPos + glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.0f, -1.0f, 0.0f))); viewProjMatrices.push_back(pointLightProjection * glm::lookAt(lightPos, lightPos + glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.0f, -1.0f, 0.0f)));
viewProjMatrices.push_back(pointLightProjection * glm::lookAt(lightPos, lightPos + glm::vec3(-1.0f, 0.0f, 0.0f), glm::vec3(0.0f, -1.0f, 0.0f))); viewProjMatrices.push_back(pointLightProjection * glm::lookAt(lightPos, lightPos + glm::vec3(-1.0f, 0.0f, 0.0f), glm::vec3(0.0f, -1.0f, 0.0f)));
viewProjMatrices.push_back(pointLightProjection * glm::lookAt(lightPos, lightPos + glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f))); viewProjMatrices.push_back(pointLightProjection * glm::lookAt(lightPos, lightPos + glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f)));
viewProjMatrices.push_back(pointLightProjection * glm::lookAt(lightPos, lightPos + glm::vec3(0.0f, -1.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f))); viewProjMatrices.push_back(pointLightProjection * glm::lookAt(lightPos, lightPos + glm::vec3(0.0f, -1.0f, 0.0f), glm::vec3(0.0f, 0.0f, -1.0f)));
viewProjMatrices.push_back(pointLightProjection * glm::lookAt(lightPos, lightPos + glm::vec3(0.0f, 0.0f, 1.0f), glm::vec3(0.0f, -1.0f, 0.0f))); viewProjMatrices.push_back(pointLightProjection * glm::lookAt(lightPos, lightPos + glm::vec3(0.0f, 0.0f, 1.0f), glm::vec3(0.0f, -1.0f, 0.0f)));
viewProjMatrices.push_back(pointLightProjection * glm::lookAt(lightPos, lightPos + glm::vec3(0.0f, 0.0f, -1.0f), glm::vec3(0.0f, -1.0f, 0.0f))); viewProjMatrices.push_back(pointLightProjection * glm::lookAt(lightPos, lightPos + glm::vec3(0.0f, 0.0f, -1.0f), glm::vec3(0.0f, -1.0f, 0.0f)));
@@ -224,12 +222,34 @@ Entity* World::getEntityById(uint32_t id)
return nullptr; return nullptr;
} }
PointLight* World::getPointLights() std::vector<PointLight*> World::getPointLights()
{ {
return pointLights.data(); std::vector<PointLight*> temp_pointLights;
for (auto it = lights.begin(); it != lights.end(); it++) {
PointLight *temp_pointLight = dynamic_cast<PointLight*>(*it);
if (temp_pointLight) {
temp_pointLights.push_back(temp_pointLight);
}
}
return temp_pointLights;
} }
std::vector< Entity* > World::getEntities() DirectionalLight * World::getDirectionalLight()
{
DirectionalLight *temp_directionalLight = nullptr;
for (auto it = lights.begin(); it != lights.end(); it++) {
temp_directionalLight = dynamic_cast<DirectionalLight*>(*it);
if(temp_directionalLight)
break;
}
return temp_directionalLight;
}
std::vector<Entity*> World::getEntities()
{ {
return entities; return entities;
} }

View File

@@ -18,11 +18,12 @@ public:
void removeEntityByName(std::string name); void removeEntityByName(std::string name);
void clearEntities(); void clearEntities();
void updatePointLight(unsigned int lightId, bool active, glm::vec3 position, glm::vec3 color); void updatePointLight(unsigned int lightId, bool active, glm::vec3 position, glm::vec3 color, float intensity);
void updateDirectionalLight(bool active, glm::vec3 direction, glm::vec3 color); void updateDirectionalLight(bool active, glm::vec3 direction, glm::vec3 color);
std::vector<Entity*> getEntities(); std::vector<Entity*> getEntities();
PointLight *getPointLights(); std::vector<PointLight*> getPointLights();
DirectionalLight * getDirectionalLight();
Skybox *getSkybox(); Skybox *getSkybox();
Entity* getEntityByName(std::string name); Entity* getEntityByName(std::string name);
Entity* getEntityById(uint32_t id); Entity* getEntityById(uint32_t id);
@@ -39,8 +40,9 @@ private:
Skybox *skybox; Skybox *skybox;
// Lights // Lights
DirectionalLight directionalLight; std::vector<Light*> lights;
std::vector<PointLight> pointLights; //DirectionalLight directionalLight;
//std::vector<PointLight> pointLights;
//SpotLight spotLight; //SpotLight spotLight;
// Shadows // Shadows