From a0c1ffb4e2e159593e1ab82aceccb5396b05bba5 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sun, 8 Sep 2024 15:25:46 +0300 Subject: [PATCH] enabled lighting --- gameObject.cpp | 2 +- main.cpp | 1 + map.cpp | 8 +++++++- player.cpp | 2 +- unit.cpp | 22 +++++++++++++++++++--- unit.h | 4 +++- 6 files changed, 32 insertions(+), 7 deletions(-) diff --git a/gameObject.cpp b/gameObject.cpp index 4083569..0249480 100644 --- a/gameObject.cpp +++ b/gameObject.cpp @@ -102,7 +102,7 @@ namespace battleship{ string f[]{albedoPath == configData::DEFAULT_TEXTURE ? GameManager::getSingleton()->getPath() + albedoPath : basePath + albedoPath}; Texture *diffuseTexture = new Texture(f, 1, false); mat->addBoolUniform("texturingEnabled", true); - mat->addBoolUniform("lightingEnabled", false); + mat->addBoolUniform("lightingEnabled", true); mat->addTexUniform("textures[0]", diffuseTexture, true); } else{ diff --git a/main.cpp b/main.cpp index bea132f..064259f 100755 --- a/main.cpp +++ b/main.cpp @@ -6,6 +6,7 @@ #include #include +#include #include diff --git a/map.cpp b/map.cpp index cbcdadc..7d337e9 100755 --- a/map.cpp +++ b/map.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -123,7 +124,7 @@ namespace battleship{ Material *mat = new Material(Root::getSingleton()->getLibPath() + "texture"); mat->addBoolUniform("texturingEnabled", true); - mat->addBoolUniform("lightingEnabled", false); + mat->addBoolUniform("lightingEnabled", true); string fr[]{texPath}; AssetManager::getSingleton()->load(fr[0]); @@ -230,6 +231,7 @@ namespace battleship{ cam->setFarPlane(600); cam->setPosition(Vector3(1, 1, 1) * configData::CAMERA_DISTANCE); cam->lookAt(Vector3(-1, -1, -1).norm(), Vector3(-1, 1, -1).norm()); + } //TODO implement toggleable cell rendering @@ -294,6 +296,10 @@ namespace battleship{ for(int i = 0; i < numWaterbodies; i++) loadTerrainObject(i); } + + Node *lightNode = new Node(Vector3::VEC_ZERO, Quaternion(1.57, Vector3::VEC_I)); + lightNode->addLight(new Light(Light::Type::DIRECTIONAL)); + Root::getSingleton()->getRootNode()->attachChild(lightNode); } //TODO unload skybox assets diff --git a/player.cpp b/player.cpp index 92b3b5f..5845d4c 100755 --- a/player.cpp +++ b/player.cpp @@ -24,7 +24,7 @@ namespace battleship{ trader(new Trader()) { colorMaterial = new Material(Root::getSingleton()->getLibPath() + "texture"); - colorMaterial->addBoolUniform("lightingEnabled", false); + colorMaterial->addBoolUniform("lightingEnabled", true); colorMaterial->addBoolUniform("texturingEnabled", false); colorMaterial->addVec4Uniform("diffuseColor", Vector4(color.x, color.y, color.z, 1)); } diff --git a/unit.cpp b/unit.cpp index 4c89ff6..751001c 100755 --- a/unit.cpp +++ b/unit.cpp @@ -1,9 +1,10 @@ -#include -#include #include +#include +#include +#include +#include #include #include -#include #include #include @@ -291,6 +292,7 @@ namespace battleship{ Unit::initProperties(); initModel(); initHitbox(); + initLosLight(); initSound(); initWeapons(); placeAt(pos); @@ -306,6 +308,7 @@ namespace battleship{ removeBar(hpForegroundNode); destroyWeapons(); destroySound(); + destroyLosLight(); destroyHitbox(); destroyModel(); } @@ -405,6 +408,19 @@ namespace battleship{ weapons.clear(); } + + void Unit::initLosLight(){ + lightNode = new Node(); + Light *light = new Light(Light::Type::POINT); + //light->setAttenuationValues(1, 1, 1); + model->attachChild(lightNode); + } + + void Unit::destroyLosLight(){ + model->dettachChild(lightNode); + delete lightNode; + lightNode = nullptr; + } void Unit::destroySound(){ selectionSfx->stop(); diff --git a/unit.h b/unit.h index 716f0ab..04df3be 100755 --- a/unit.h +++ b/unit.h @@ -161,12 +161,14 @@ namespace battleship{ void updateScreenCoordinates(); void initWeapons(); void destroyWeapons(); + void initLosLight(); + void destroyLosLight(); inline bool canDisplayOrderLine(){return vb01::getTime() - orderLineDispTime < orderVecDispLength;} const int orderVecDispLength = 2000, DEATH_HP = 0; sf::SoundBuffer *selectionSfxBuffer; sf::Sound *selectionSfx = nullptr; - vb01::Node *hpBackgroundNode = nullptr, *hpForegroundNode = nullptr; + vb01::Node *hpBackgroundNode = nullptr, *hpForegroundNode = nullptr, *lightNode = nullptr; bool vehicle; protected: UnitClass unitClass;