enabled lighting

This commit is contained in:
devZoGok
2024-09-08 15:25:46 +03:00
parent 52b9ac2ffd
commit a0c1ffb4e2
6 changed files with 32 additions and 7 deletions
+1 -1
View File
@@ -102,7 +102,7 @@ namespace battleship{
string f[]{albedoPath == configData::DEFAULT_TEXTURE ? GameManager::getSingleton()->getPath() + albedoPath : basePath + albedoPath}; string f[]{albedoPath == configData::DEFAULT_TEXTURE ? GameManager::getSingleton()->getPath() + albedoPath : basePath + albedoPath};
Texture *diffuseTexture = new Texture(f, 1, false); Texture *diffuseTexture = new Texture(f, 1, false);
mat->addBoolUniform("texturingEnabled", true); mat->addBoolUniform("texturingEnabled", true);
mat->addBoolUniform("lightingEnabled", false); mat->addBoolUniform("lightingEnabled", true);
mat->addTexUniform("textures[0]", diffuseTexture, true); mat->addTexUniform("textures[0]", diffuseTexture, true);
} }
else{ else{
+1
View File
@@ -6,6 +6,7 @@
#include <stateManager.h> #include <stateManager.h>
#include <assetManager.h> #include <assetManager.h>
#include <root.h>
#include <string> #include <string>
+7 -1
View File
@@ -1,6 +1,7 @@
#include <root.h> #include <root.h>
#include <quad.h> #include <quad.h>
#include <model.h> #include <model.h>
#include <light.h>
#include <material.h> #include <material.h>
#include <assetManager.h> #include <assetManager.h>
@@ -123,7 +124,7 @@ namespace battleship{
Material *mat = new Material(Root::getSingleton()->getLibPath() + "texture"); Material *mat = new Material(Root::getSingleton()->getLibPath() + "texture");
mat->addBoolUniform("texturingEnabled", true); mat->addBoolUniform("texturingEnabled", true);
mat->addBoolUniform("lightingEnabled", false); mat->addBoolUniform("lightingEnabled", true);
string fr[]{texPath}; string fr[]{texPath};
AssetManager::getSingleton()->load(fr[0]); AssetManager::getSingleton()->load(fr[0]);
@@ -230,6 +231,7 @@ namespace battleship{
cam->setFarPlane(600); cam->setFarPlane(600);
cam->setPosition(Vector3(1, 1, 1) * configData::CAMERA_DISTANCE); cam->setPosition(Vector3(1, 1, 1) * configData::CAMERA_DISTANCE);
cam->lookAt(Vector3(-1, -1, -1).norm(), Vector3(-1, 1, -1).norm()); cam->lookAt(Vector3(-1, -1, -1).norm(), Vector3(-1, 1, -1).norm());
} }
//TODO implement toggleable cell rendering //TODO implement toggleable cell rendering
@@ -294,6 +296,10 @@ namespace battleship{
for(int i = 0; i < numWaterbodies; i++) for(int i = 0; i < numWaterbodies; i++)
loadTerrainObject(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 //TODO unload skybox assets
+1 -1
View File
@@ -24,7 +24,7 @@ namespace battleship{
trader(new Trader()) trader(new Trader())
{ {
colorMaterial = new Material(Root::getSingleton()->getLibPath() + "texture"); colorMaterial = new Material(Root::getSingleton()->getLibPath() + "texture");
colorMaterial->addBoolUniform("lightingEnabled", false); colorMaterial->addBoolUniform("lightingEnabled", true);
colorMaterial->addBoolUniform("texturingEnabled", false); colorMaterial->addBoolUniform("texturingEnabled", false);
colorMaterial->addVec4Uniform("diffuseColor", Vector4(color.x, color.y, color.z, 1)); colorMaterial->addVec4Uniform("diffuseColor", Vector4(color.x, color.y, color.z, 1));
} }
+19 -3
View File
@@ -1,9 +1,10 @@
#include <model.h>
#include <quad.h>
#include <box.h> #include <box.h>
#include <quad.h>
#include <model.h>
#include <light.h>
#include <texture.h>
#include <material.h> #include <material.h>
#include <particleEmitter.h> #include <particleEmitter.h>
#include <texture.h>
#include <stateManager.h> #include <stateManager.h>
#include <solUtil.h> #include <solUtil.h>
@@ -291,6 +292,7 @@ namespace battleship{
Unit::initProperties(); Unit::initProperties();
initModel(); initModel();
initHitbox(); initHitbox();
initLosLight();
initSound(); initSound();
initWeapons(); initWeapons();
placeAt(pos); placeAt(pos);
@@ -306,6 +308,7 @@ namespace battleship{
removeBar(hpForegroundNode); removeBar(hpForegroundNode);
destroyWeapons(); destroyWeapons();
destroySound(); destroySound();
destroyLosLight();
destroyHitbox(); destroyHitbox();
destroyModel(); destroyModel();
} }
@@ -405,6 +408,19 @@ namespace battleship{
weapons.clear(); 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(){ void Unit::destroySound(){
selectionSfx->stop(); selectionSfx->stop();
+3 -1
View File
@@ -161,12 +161,14 @@ namespace battleship{
void updateScreenCoordinates(); void updateScreenCoordinates();
void initWeapons(); void initWeapons();
void destroyWeapons(); void destroyWeapons();
void initLosLight();
void destroyLosLight();
inline bool canDisplayOrderLine(){return vb01::getTime() - orderLineDispTime < orderVecDispLength;} inline bool canDisplayOrderLine(){return vb01::getTime() - orderLineDispTime < orderVecDispLength;}
const int orderVecDispLength = 2000, DEATH_HP = 0; const int orderVecDispLength = 2000, DEATH_HP = 0;
sf::SoundBuffer *selectionSfxBuffer; sf::SoundBuffer *selectionSfxBuffer;
sf::Sound *selectionSfx = nullptr; sf::Sound *selectionSfx = nullptr;
vb01::Node *hpBackgroundNode = nullptr, *hpForegroundNode = nullptr; vb01::Node *hpBackgroundNode = nullptr, *hpForegroundNode = nullptr, *lightNode = nullptr;
bool vehicle; bool vehicle;
protected: protected:
UnitClass unitClass; UnitClass unitClass;