Skip to content

Commit

Permalink
Added option to disable bloom, 4x game speed option, minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake committed Oct 5, 2022
1 parent 1f713d6 commit 182c194
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 22 deletions.
6 changes: 3 additions & 3 deletions data/assets/shaders/particles/ResolveParticleImage.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ layout(location = 0) out vec4 o_color;
void main()
{
o_color = vec4(
float(texture(s_target_r, v_uv).r) / 256.0,
float(texture(s_target_g, v_uv).r) / 256.0,
float(texture(s_target_b, v_uv).r) / 256.0,
min(float(texture(s_target_r, v_uv).r) / 256.0, 64000),
min(float(texture(s_target_g, v_uv).r) / 256.0, 64000),
min(float(texture(s_target_b, v_uv).r) / 256.0, 64000),
1.0
);
}
4 changes: 2 additions & 2 deletions data/assets/shaders/particles/UpdateParticles.comp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ void main()
if (ppos.x > bpos.x - bscl.x && ppos.y > bpos.y - bscl.y &&
ppos.x < bpos.x + bscl.x && ppos.y < bpos.y + bscl.y)
{
particle.emissive.x = packHalf2x16(vec2(8.0, .1));
particle.emissive.y = packHalf2x16(vec2(.1, .0));
particle.emissive.x = packHalf2x16(vec2(40.0, .4));
particle.emissive.y = packHalf2x16(vec2(.4, .0));
//vec2 refldir = reflect(-normalize(velocity), vec2(normal));
//velocity = refldir * length(velocity) * 2;

Expand Down
43 changes: 30 additions & 13 deletions src/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,14 @@ void Application::Run()
GameState gameState = GameState::MENU;
int startParticles = 1000;
auto milestoneTracker = MilestoneTracker();
double gameSpeed = 1.0;

struct Pause {};
struct ScreenshotMode {};
struct Speedup : ecs::AxisBindingBase {};
_input->AddActionBinding<Pause>(input::ActionInput{ .type{ input::Button::KEY_ESCAPE} });
_input->AddActionBinding<ScreenshotMode>(input::ActionInput{ .type{ input::Button::KEY_F1} });
_input->AddAxisBinding<Speedup>(input::AxisInput{ .type{ input::Button::KEY_SPACE } });

struct Handler
{
Expand Down Expand Up @@ -424,20 +427,29 @@ void Application::Run()
_eventBus->Subscribe(&handler, &Handler::PauseHandler);
_eventBus->Subscribe(&handler, &Handler::ScreenshotModeHandler);

auto speedupHandler = [&gameSpeed](Speedup&) mutable -> void
{
gameSpeed = 4;
};

_eventBus->Subscribe(&speedupHandler, &decltype(speedupHandler)::operator());

Timer timer;
double simulationAccum = 0;
double inputAccum = 0;
//double inputAccum = 0;
while (!glfwWindowShouldClose(_window))
{
double dt = timer.Elapsed_s();
timer.Reset();

inputAccum += dt;
while (inputAccum > _simulationTick)
{
gameSpeed = 1;

//inputAccum += dt;
//while (inputAccum > _simulationTick)
//{
_input->PollEvents(_simulationTick);
inputAccum -= _simulationTick;
}
// inputAccum -= _simulationTick;
//}

ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
Expand Down Expand Up @@ -488,14 +500,16 @@ void Application::Run()
int simHz = static_cast<int>(1.0 / _simulationTick);
ImGui::SliderInt("Simulation Hz", &simHz, 15, 240);
_simulationTick = 1.0 / simHz;
ImGui::Checkbox("Enable bloom", &Renderer::enableBloom);

ImGui::TreePop();
}

if (ImGui::TreeNode("Controls"))
{
ImGui::Text("Escape: pauses game");
ImGui::Text("Cursor: control flock");
ImGui::Text("Escape: pauses game");
ImGui::Text("Space: 4x game speed");

ImGui::TreePop();
}
Expand All @@ -512,6 +526,7 @@ void Application::Run()
}
case GameState::RUNNING:
{
dt *= gameSpeed;
simulationAccum += dt;
while (simulationAccum > _simulationTick)
{
Expand All @@ -529,7 +544,7 @@ void Application::Run()
}
}

gameTime += dt;
gameTime += _simulationTick;
particleSystem.Update(_simulationTick);

simulationAccum -= _simulationTick;
Expand Down Expand Up @@ -574,17 +589,19 @@ void Application::Run()
{
ImGui::Text("Your flock survived!");
ImGui::Text("Well, %.3f%% of it did anyways.", 100.0 * double(survived) / (uint64_t(startParticles) << 12u));
}
ImGui::Text("(%u / %d)", survived, startParticles << 12);

if (ImGui::Button("Free Play"))
{
gameState = GameState::RUNNING;
sandboxMode = true;
if (ImGui::Button("Free Play"))
{
gameState = GameState::RUNNING;
sandboxMode = true;
}
}

if (ImGui::Button("Main Menu"))
{
gameState = GameState::MENU;
_scene->Registry().clear();
}

ImGui::End();
Expand Down
5 changes: 1 addition & 4 deletions src/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,6 @@ void Renderer::ApplyBloom(const Fwog::Texture& target, uint32_t passes, float st
samplerState.mipmapFilter = Fwog::Filter::NEAREST;
samplerState.addressModeU = Fwog::AddressMode::MIRRORED_REPEAT;
samplerState.addressModeV = Fwog::AddressMode::MIRRORED_REPEAT;
samplerState.lodBias = 0;
samplerState.minLod = -1000;
samplerState.maxLod = 1000;
auto sampler = Fwog::Sampler(samplerState);

Fwog::BeginCompute("Bloom");
Expand Down Expand Up @@ -648,7 +645,7 @@ void Renderer::DrawParticles(const Fwog::Buffer& particles, const Fwog::Buffer&
}
Fwog::EndRendering();

ApplyBloom(_resources->frame.output_hdr, 6, 1.0f / 64.0f, 1.0f, _resources->frame.output_hdr_scratch);
ApplyBloom(_resources->frame.output_hdr, 6, enableBloom ? 1.0f / 64.0f : 0.0f, 1.0f, _resources->frame.output_hdr_scratch);

// fuggit, I'm gonna resolve the final image here too
Fwog::BeginCompute("Tonemap");
Expand Down
2 changes: 2 additions & 0 deletions src/Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class Renderer

struct Resources;

// stinky GLOBAL (basically)
static inline bool enableBloom = true;
private:
void ApplyBloom(const Fwog::Texture& target, uint32_t passes, float strength, float width, const Fwog::Texture& scratchTexture);

Expand Down

0 comments on commit 182c194

Please sign in to comment.