Change Scene to World

This commit is contained in:
4VRDriver
2020-09-14 21:59:13 +02:00
parent 9d93d6efc3
commit b957e4a5ee
5 changed files with 42 additions and 41 deletions

View File

@@ -99,12 +99,12 @@ vec3 directionalLightContribution(DirectionalLight light, vec3 normal, vec3 view
vec3 reflectDir = reflect(-lightDir, normal);
float specularShading = pow(max(dot(viewDir, reflectDir), 0.0f), u_material.shininess);
vec3 diffuseTex = vec3(texture(u_material.texture_diffuse0, v_texCoord));
vec3 specularTex = vec3(texture(u_material.texture_specular0, v_texCoord));
vec4 diffuseTex = texture(u_material.texture_diffuse0, v_texCoord);
vec4 specularTex = texture(u_material.texture_specular0, v_texCoord);
vec3 ambient = light.ambient * diffuseTex;
vec3 diffuse = light.diffuse * diffuseShading * diffuseTex;
vec3 specular = light.specular * specularShading * specularTex;
vec3 ambient = light.ambient * vec3(diffuseTex);
vec3 diffuse = light.diffuse * diffuseShading * vec3(diffuseTex);
vec3 specular = light.specular * specularShading * vec3(specularTex);
return (ambient + diffuse + specular);
}
@@ -128,12 +128,12 @@ vec3 pointLightContribution(PointLight light, vec3 normal, vec3 fragPos, vec3 vi
float distanceLightFragment = length(light.position - fragPos);
float attenuation = 1.0f / (light.K_c + light.K_l * distanceLightFragment + light.K_q * distanceLightFragment * distanceLightFragment);
vec3 diffuseTex = vec3(texture(u_material.texture_diffuse0, v_texCoord));
vec3 specularTex = vec3(texture(u_material.texture_specular0, v_texCoord));
vec4 diffuseTex = texture(u_material.texture_diffuse0, v_texCoord);
vec4 specularTex = texture(u_material.texture_specular0, v_texCoord);
vec3 ambient = light.ambient * diffuseTex;
vec3 diffuse = light.diffuse * diffuseShading * diffuseTex;
vec3 specular = light.specular * specularShading * specularTex;
vec3 ambient = light.ambient * vec3(diffuseTex);
vec3 diffuse = light.diffuse * diffuseShading * vec3(diffuseTex);
vec3 specular = light.specular * specularShading * vec3(specularTex);
ambient *= attenuation;
diffuse *= attenuation;
@@ -165,12 +165,12 @@ vec3 spotLightContribution(SpotLight light, vec3 normal, vec3 fragPos, vec3 view
float epsilon = light.innerCutOff - light.outerCutOff;
float intensity = clamp((theta - light.outerCutOff) / epsilon, 0.0f, 1.0f);
vec3 diffuseTex = vec3(texture(u_material.texture_diffuse0, v_texCoord));
vec3 specularTex = vec3(texture(u_material.texture_specular0, v_texCoord));
vec3 ambient = light.ambient * diffuseTex;
vec3 diffuse = light.diffuse * diffuseShading * diffuseTex;
vec3 specular = light.specular * specularShading * specularTex;
vec4 diffuseTex = texture(u_material.texture_diffuse0, v_texCoord);
vec4 specularTex = texture(u_material.texture_specular0, v_texCoord);
vec3 ambient = light.ambient * vec3(diffuseTex);
vec3 diffuse = light.diffuse * diffuseShading * vec3(diffuseTex);
vec3 specular = light.specular * specularShading * vec3(specularTex);
diffuse *= intensity;
specular *= intensity;

View File

@@ -11,7 +11,7 @@ add_executable(Fall-Fever
Model.cpp
Entity.cpp
Light.cpp
Scene.cpp
World.cpp
)
target_link_libraries(

View File

@@ -23,7 +23,7 @@
#include "Texture.h"
#include "Model.h"
#include "Entity.h"
#include "Scene.h"
#include "World.h"
Controller::Controller() {
if(!glfwInit()) exit(-1);
@@ -79,23 +79,23 @@ void Controller::run() {
ShaderProgram lightProgram("res/shaders/light.vert", "res/shaders/light.frag");
//Model model_backpack("res/models/backpack.ffo");
//Model model_plant("res/models/plant.ffo");
Model model_plant("res/models/plant.ffo");
Model model_container("res/models/container.ffo");
Model model_cube("res/models/cube.ffo");
Model model_dragon("res/models/dragon.ffo");
//Model model_dragon("res/models/dragon.ffo");
//Model model_sphere("res/models/sphere.ffo");
//Entity backpack(&model_backpack, &shaderProgram);
//Entity sphere(&model_sphere, &shaderProgram);
Entity container(&model_container, &shaderProgram);
Entity dragon(&model_dragon, &shaderProgram);
//Entity plant(&model_plant, &shaderProgram);
//Entity dragon(&model_dragon, &shaderProgram);
Entity plant(&model_plant, &shaderProgram);
Entity lightSource(&model_cube, &lightProgram);
lightSource.translate(glm::vec3(-5.0f, 1.0f, 0.0f));
lightSource.setScale(0.2f);
//plant.scale(5.0f);
dragon.setScale(0.2f);
plant.setScale(5.0f);
//dragon.setScale(0.2f);
glm::vec3 lightColor = glm::vec3(1.0f, 1.0f, 1.0f);
glm::vec3 diffuseColor = lightColor * glm::vec3(1.0f);
@@ -103,6 +103,7 @@ void Controller::run() {
glm::vec3 specularColor = glm::vec3(1.0f);
shaderProgram.bind();
shaderProgram.setUniform("u_directionalLight.isActive", 1);
shaderProgram.setUniform("u_directionalLight.direction", glm::vec3(-0.2f, -1.0f, -0.3f));
shaderProgram.setUniform("u_directionalLight.ambient", ambientColor * 0.25f);
shaderProgram.setUniform("u_directionalLight.diffuse", diffuseColor * 0.25f);
@@ -111,11 +112,11 @@ void Controller::run() {
shaderProgram.setUniform("u_material.shininess", 32.0f);
shaderProgram.unbind();
Scene scene(&shaderProgram);
scene.addEntity(dragon);
scene.addEntity(lightSource);
World world(&shaderProgram);
world.addEntity(plant);
world.addEntity(lightSource);
scene.updateLight(0, lightSource.getPosition(), glm::vec3(1.0f));
world.updateLight(0, lightSource.getPosition(), glm::vec3(1.0f));
camera->translate(glm::vec3(0.0f, 0.0f, 7.5f));
@@ -133,10 +134,10 @@ void Controller::run() {
camera->lookForward();
camera->updateVPM();
scene.drawScene(camera->getViewProj(), camera->getPosition());
world.draw(camera->getViewProj(), camera->getPosition());
#ifdef _DEBUG
renderImGui(scene.getEntities());
renderImGui(world.getEntities());
#endif
glfwSwapBuffers(gameWindow->getGLFWwindow());

View File

@@ -1,4 +1,4 @@
#include "Scene.h"
#include "World.h"
#include <iostream>
@@ -6,7 +6,7 @@
// with an array of objects that don't have an default contructor. So the default
// constructors for Light and PointLight have only this reason to exist.
Scene::Scene(ShaderProgram *shaderProgram)
World::World(ShaderProgram *shaderProgram)
: shaderProgram(shaderProgram) {
for(unsigned int i = 0; i < NUM_POINT_LIGHTS; i++) {
@@ -16,13 +16,13 @@ Scene::Scene(ShaderProgram *shaderProgram)
}
void Scene::addEntity(Entity entity) {
void World::addEntity(Entity entity) {
uint32_t new_id = entities.size();
entity.setId(new_id);
entities.push_back(entity);
}
void Scene::removeEntity(uint32_t id) {
void World::removeEntity(uint32_t id) {
for(auto it = entities.begin(); it != entities.end(); it++) {
if(it->getId() == id) {
@@ -33,13 +33,13 @@ void Scene::removeEntity(uint32_t id) {
std::cout << "[Warning] Entity with ID " << id << " could not be removed." << std::endl;
}
void Scene::updateLight(unsigned int lightId, glm::vec3 position, glm::vec3 color) {
void World::updateLight(unsigned int lightId, glm::vec3 position, glm::vec3 color) {
pointLights[lightId].setActive(true);
pointLights[lightId].setPosition(position);
pointLights[lightId].setColor(color);
}
void Scene::drawScene(glm::mat4 viewProjMatrix, glm::vec3 viewPosition) {
void World::draw(glm::mat4 viewProjMatrix, glm::vec3 viewPosition) {
for(auto it = entities.begin(); it != entities.end(); it++) {
it->draw(viewProjMatrix, viewPosition);

View File

@@ -6,12 +6,12 @@
#include "Camera.h"
#include "Entity.h"
class Scene {
class World {
public:
Scene(ShaderProgram *shaderProgram);
~Scene() = default;
World(ShaderProgram *shaderProgram);
~World() = default;
void addEntity(Entity entity);
void removeEntity(uint32_t id);
@@ -20,7 +20,7 @@ public:
std::vector<Entity> * getEntities() { return &entities; }
void drawScene(glm::mat4 viewProjMatrix, glm::vec3 viewPosition);
void draw(glm::mat4 viewProjMatrix, glm::vec3 viewPosition);
private:
@@ -32,4 +32,4 @@ private:
PointLight pointLights[NUM_POINT_LIGHTS];
//SpotLight spotLight;
};
};