diff --git a/Game/src/MainState.cpp b/Game/src/MainState.cpp index f90f9a5..04db89b 100644 --- a/Game/src/MainState.cpp +++ b/Game/src/MainState.cpp @@ -22,5 +22,4 @@ void MainState::render(nf::Renderer& renderer) { void MainState::onExit() { Log("MainState onExit!"); - } \ No newline at end of file diff --git a/Game/src/include/MainState.h b/Game/src/include/MainState.h index c7a829c..15c6cc1 100644 --- a/Game/src/include/MainState.h +++ b/Game/src/include/MainState.h @@ -13,5 +13,4 @@ public: void onExit() override; private: - }; \ No newline at end of file diff --git a/NFPackCreator/AssetBuild/base/shaders/entityFragment.shader b/NFPackCreator/AssetBuild/base/shaders/entityFragment.shader index 5374e4d..404dc15 100644 --- a/NFPackCreator/AssetBuild/base/shaders/entityFragment.shader +++ b/NFPackCreator/AssetBuild/base/shaders/entityFragment.shader @@ -14,17 +14,11 @@ struct Material { }; struct Light { - //Directional = 1, Point = 2, Spotlight = 3 + //Directional = 1, Point = 2 int type; vec3 pos; - vec3 direction; vec3 color; - - float falloffConstant; - float falloffLinear; - float falloffQuad; - - float cutoff; + float strength; }; uniform sampler2D modelTexture; @@ -48,18 +42,37 @@ void main() { break; } - vec3 norm = normalize(normals); - vec3 lightDir = normalize(light[i].pos - fragPos); - float diff = max(dot(norm, lightDir), 0.0); - vec3 diffuse = light[i].color * (diff * texColor.rgb); + if (light[i].type == 1) { + vec3 lightDir = normalize(-light[i].pos); + vec3 norm = normalize(normals); + float diff = max(dot(norm, lightDir), 0.0); + vec3 diffuse = light[i].color * (diff * texColor.rgb) * light[i].strength; - vec3 viewDir = normalize(camera.pos - fragPos); - vec3 reflectDir = reflect(-lightDir, norm); - float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess * 32.0f); - vec3 specular = light[i].color * spec; + vec3 viewDir = normalize(camera.pos - fragPos); + vec3 reflectDir = reflect(-lightDir, norm); + float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess * 32.0f); + vec3 specular = light[i].color * spec * light[i].strength; - color += (ambient + diffuse + specular); + color += (ambient + diffuse + specular); + continue; + } + if (light[i].type == 2) { + vec3 lightDir = normalize(light[i].pos - fragPos); + vec3 norm = normalize(normals); + float diff = max(dot(norm, lightDir), 0.0); + vec3 diffuse = light[i].color * (diff * texColor.rgb) * light[i].strength; + + vec3 viewDir = normalize(camera.pos - fragPos); + vec3 reflectDir = reflect(-lightDir, norm); + float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess * 32.0f); + vec3 specular = light[i].color * spec * (light[i].strength) / 8.0f; + + float length = length(light[i].pos - fragPos); + float att = clamp(10.0 / length, 0.0, 1.0) * light[i].strength; + + color += ((ambient + diffuse + specular) * att); + continue; + } } - outColor = vec4(color, texColor.a); } diff --git a/NothinFancy/src/Gamestate.cpp b/NothinFancy/src/Gamestate.cpp index 1f8d46d..addc579 100644 --- a/NothinFancy/src/Gamestate.cpp +++ b/NothinFancy/src/Gamestate.cpp @@ -5,9 +5,9 @@ namespace nf { Gamestate::Gamestate(Application* app) : - m_camera(app) + camera(app) { - m_app = app; + this->app = app; } void Gamestate::onEnter() { @@ -19,7 +19,7 @@ namespace nf { } Camera* Gamestate::getCamera() { - return &m_camera; + return &camera; } void Gamestate::render(Renderer& renderer) { diff --git a/NothinFancy/src/IntroGamestate.cpp b/NothinFancy/src/IntroGamestate.cpp index a841907..b673d92 100644 --- a/NothinFancy/src/IntroGamestate.cpp +++ b/NothinFancy/src/IntroGamestate.cpp @@ -18,7 +18,7 @@ namespace nf { void IntroGamestate::update(double deltaTime) { if (m_counter >= 120) { - m_app->changeState("Main State"); + app->changeState("Main State"); } m_counter++; } diff --git a/NothinFancy/src/Renderer/Camera.cpp b/NothinFancy/src/Renderer/Camera.cpp index 250af73..4181953 100644 --- a/NothinFancy/src/Renderer/Camera.cpp +++ b/NothinFancy/src/Renderer/Camera.cpp @@ -67,6 +67,10 @@ namespace nf { return m_position; } + const Vec3& Camera::getRotation() { + return m_front; + } + void Camera::bind(Shader* shader) { glm::mat4 view; diff --git a/NothinFancy/src/Renderer/Drawable/Light.cpp b/NothinFancy/src/Renderer/Drawable/Light.cpp index 1927e3a..dc1cc83 100644 --- a/NothinFancy/src/Renderer/Drawable/Light.cpp +++ b/NothinFancy/src/Renderer/Drawable/Light.cpp @@ -11,7 +11,7 @@ namespace nf { } - void Light::create(const Vec3& position, const Vec3& color, Type type, float strength) { + void Light::create(const Vec3& position, const Vec3& color, float strength, Type type) { m_constructed = true; m_position = position; m_color = color; @@ -32,37 +32,33 @@ namespace nf { m_color = color; } + void Light::setStrength(double strength) { + m_strength = (float)strength; + } + void Light::bind(Shader* shader, unsigned int lightNumber) { - glm::vec3 pos(m_position.x, m_position.y, m_position.z); - glm::vec3 color(m_color.x, m_color.y, m_color.z); std::string stringPos = "light["; - std::string stringLocation = std::to_string(lightNumber); - stringPos += stringLocation; + stringPos += std::to_string(lightNumber); stringPos += "]."; std::string lightPos = stringPos + (std::string)"pos"; std::string lightColor = stringPos + (std::string)"color"; + std::string lightStrength = stringPos + (std::string)"strength"; + glm::vec3 pos(m_position.x, m_position.y, m_position.z); + glm::vec3 color(m_color.x, m_color.y, m_color.z); shader->setUniform(lightPos, pos); shader->setUniform(lightColor, color); - //switch (m_type) { - // case Type::DIRECTIONAL: { - // shader->setUniform(lightType.c_str(), 1); - // std::string lightConsant = light + (std::string)"falloffConstant"; - // std::string lightLinear = light + (std::string)"falloffLinear"; - // std::string lightQuad = light + (std::string)"falloffQuad"; - // shader->setUniform(lightConsant.c_str(), 1.0f); - // shader->setUniform(lightLinear.c_str(), 0.7f); - // shader->setUniform(lightQuad.c_str(), 1.8f); - // break; - // } - // case Type::POINT: { - // //shader->setUniform(lightType.c_str(), 2); - // break; - // } - // case Type::SPOTLIGHT: { - // shader->setUniform(lightType.c_str(), 3); - // break; - // } - //} + shader->setUniform(lightStrength, m_strength); + std::string lightType = stringPos + (std::string)"type"; + switch (m_type) { + case Type::DIRECTIONAL: { + shader->setUniform(lightType, 1); + break; + } + case Type::POINT: { + shader->setUniform(lightType, 2); + break; + } + } } Light::Type Light::getType() { diff --git a/NothinFancy/src/include/Camera.h b/NothinFancy/src/include/Camera.h index 41299c1..d594ba5 100644 --- a/NothinFancy/src/include/Camera.h +++ b/NothinFancy/src/include/Camera.h @@ -25,6 +25,7 @@ namespace nf { void setPosition(double x, double y, double z); void setPosition(const Vec3& position); const Vec3& getPosition(); + const Vec3& getRotation(); void bind(Shader* shader); diff --git a/NothinFancy/src/include/Gamestate.h b/NothinFancy/src/include/Gamestate.h index 6ba41b1..d686046 100644 --- a/NothinFancy/src/include/Gamestate.h +++ b/NothinFancy/src/include/Gamestate.h @@ -19,7 +19,7 @@ namespace nf { virtual void onExit(); protected: - Application* m_app; - Camera m_camera; + Application* app; + Camera camera; }; } \ No newline at end of file diff --git a/NothinFancy/src/include/Light.h b/NothinFancy/src/include/Light.h index 7fb7b05..b60678f 100644 --- a/NothinFancy/src/include/Light.h +++ b/NothinFancy/src/include/Light.h @@ -8,15 +8,15 @@ namespace nf { public: enum class Type { DIRECTIONAL, - POINT, - SPOTLIGHT + POINT }; Light(); - void create(const Vec3& position, const Vec3& color, Type type = Type::POINT, float strength = 1.0f); + void create(const Vec3& position, const Vec3& color, float strength = 1.0f, Type type = Type::POINT); bool isConstructed(); void setPosition(const Vec3& position); void setColor(const Vec3& color); + void setStrength(double strength); void bind(Shader* shader, unsigned int lightNumber);