Commit 128828d9 authored by Al's avatar Al

flickering torch light bitch

parent f5084786
......@@ -55,11 +55,11 @@ void Game::ProcessInput()
void Game::UpdateModel()
{
scene.Update(wnd.kbd,wnd.mouse,dt);
//#ifdef NDEBUG
#ifdef NDEBUG
dt = timer.Mark();
//#else
// dt = 1.0f / 6.0f;
//#endif
#else
dt = 1.0f / 6.0f;
#endif
CombatManager::GetCombatManager().UpdateCombatState(dt);
......
......@@ -23,7 +23,7 @@ MainScene::MainScene(Graphics & gfx,LevelMap& map)
enemy(map.GetEnemyPosition())
{
SPI::Play(Sounds::Ambient_Dungeon, 1.0f, 0.5f);
SPI::Play(Sounds::Ambient_Torch, 1.0f, 0.5f);
SPI::Play(Sounds::Ambient_Torch, 1.0f, 0.4f);
enemPos = map.GetEnemyPosition();
// set light sphere colors
for (auto& v : lightIndicator.vertices)
......@@ -45,13 +45,15 @@ MainScene::MainScene(Graphics & gfx,LevelMap& map)
hkPipeline.effect.vs.BindWorldView((Mat4::Translation(cam_pos - Vec3(0.0f, 0.0f, -nearClippingPlane)))*Mat4::Translation(-cam_pos) * cam_rot_inv);//same for all HUD
LightFlickerer.SetLights(lightColors);
}
void MainScene::Update(Keyboard& kbd, Mouse& mouse, float dt)
{
LightFlickerer.Update(dt);
//updating HUD
hud.Update(dt);
for (int i = 0; i < scenarios.size(); i++)
{
......@@ -136,6 +138,8 @@ void MainScene::Update(Keyboard& kbd, Mouse& mouse, float dt)
void MainScene::Draw()
{
hPipeline.BeginFrame(); //clears Z buffer. necessary even for hud
const auto proj = Mat4::ProjectionHFOV(hfov, aspect_ratio, nearClippingPlane, farClippingPlane);
const auto view = Mat4::Translation(-cam_pos) * cam_rot_inv;
......@@ -162,7 +166,7 @@ void MainScene::Draw()
}
wPipeline.effect.vs.SetLightPosition(lPosTemp);
wPipeline.effect.vs.SetAmbientLight(l_ambient);
wPipeline.effect.vs.SetDiffuseLight(lightColors);
wPipeline.effect.vs.SetDiffuseLight(LightFlickerer.GetLights());
const std::vector<WallsETC::Wall>& wal = walls.GetWalls();
for (const auto w : wal)
{
......@@ -199,7 +203,7 @@ void MainScene::Draw()
pPipeline.effect.vs.SetLightPosition(lPosTemp);
pPipeline.effect.vs.SetAmbientLight (l_ambient);
pPipeline.effect.vs.SetDiffuseLight (lightColors);
pPipeline.effect.vs.SetDiffuseLight(LightFlickerer.GetLights());
for (auto& pb : partBursts)
{
......
......@@ -17,6 +17,7 @@
#include "LevelMap.h"
#include "RandomUnit.h"
class MainScene : public Scene
{
......@@ -61,6 +62,66 @@ public:
return (bool)scenarios.size();
}
private:
class LightFlickerer
{
public:
void SetLights(std::vector<Vec3> in_lights)
{
lights = in_lights;
int sz = lights.size();
endFlickerPower.reserve(sz);
curFlickerPower.reserve(sz);
totalFlickerTime.reserve(sz);
curFlickerTime.reserve(sz);
for (int i = 0; i < sz; i++)
{
endFlickerPower.push_back(1.0f);
curFlickerPower.push_back(1.0f);
totalFlickerTime.push_back(0.0f);
curFlickerTime.push_back(0.0f);
}
}
void Update(float dt)
{
for (int i = 0; i < lights.size(); i++)
{
curFlickerTime[i] += dt;
if (curFlickerTime[i] >= totalFlickerTime[i])
{
curFlickerTime[i] = 0.0f;
totalFlickerTime[i] = RandomUnit::GetRandomUnit().GetRandFloat(0.08f, 0.4f);
endFlickerPower[i] = RandomUnit::GetRandomUnit().GetRandFloat(0.8f, 1.2f);
}
else
{
float flickProgress = curFlickerTime[i] / totalFlickerTime[i];
curFlickerPower[i] = curFlickerPower[i] * (1 - flickProgress) + flickProgress * endFlickerPower[i];
}
}
}
std::vector<Vec3> GetLights()
{
std::vector<Vec3> temp;
for (int i = 0;i<lights.size();i++)
{
temp.push_back((lights[i]*curFlickerPower[i]).GetSaturated());
}
return temp;
}
private:
std::vector<Vec3> lights;
std::vector <float> curFlickerPower;
std::vector <float> endFlickerPower;
std::vector <float> curFlickerTime;
std::vector <float> totalFlickerTime;
};
public:
static constexpr float farClippingPlane = 6.0f;
......@@ -117,6 +178,7 @@ private:
Vec3 l_ambient = { 0.15f,0.055f,0.045f };
LightFlickerer LightFlickerer;
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment