fix u_timer behaviour when paused

This commit is contained in:
MihailRis 2024-07-18 13:50:57 +03:00
parent 3549c1f326
commit 2c1adcedbd
3 changed files with 9 additions and 5 deletions

View File

@ -99,7 +99,7 @@ void LevelScreen::saveWorldPreview() {
Viewport viewport(previewSize * 1.5, previewSize);
DrawContext ctx(&pctx, viewport, batch.get());
worldRenderer->draw(ctx, &camera, false, true, postProcessing.get());
worldRenderer->draw(ctx, &camera, false, true, 0.0f, postProcessing.get());
auto image = postProcessing->toImage();
image->flipY();
imageio::write(paths->resolve("world:preview.png").u8string(), image.get());
@ -156,13 +156,13 @@ void LevelScreen::update(float delta) {
hud->update(hudVisible);
}
void LevelScreen::draw(float) {
void LevelScreen::draw(float delta) {
auto camera = controller->getPlayer()->currentCamera;
Viewport viewport(Window::width, Window::height);
DrawContext ctx(nullptr, viewport, batch.get());
worldRenderer->draw(ctx, camera.get(), hudVisible, hud->isPause(), postProcessing.get());
worldRenderer->draw(ctx, camera.get(), hudVisible, hud->isPause(), delta, postProcessing.get());
if (hudVisible) {
hud->draw(ctx);

View File

@ -170,7 +170,7 @@ void WorldRenderer::renderLevel(
shader->use();
shader->uniformMatrix("u_proj", camera->getProjection());
shader->uniformMatrix("u_view", camera->getView());
shader->uniform1f("u_timer", Window::time());
shader->uniform1f("u_timer", timer);
shader->uniform1f("u_gamma", settings.graphics.gamma.get());
shader->uniform1f("u_fogFactor", fogFactor);
shader->uniform1f("u_fogCurve", settings.graphics.fogCurve.get());
@ -301,8 +301,10 @@ void WorldRenderer::draw(
Camera* camera,
bool hudVisible,
bool pause,
float delta,
PostProcessing* postProcessing
){
timer += delta * !pause;
auto world = level->getWorld();
const Viewport& vp = pctx.getViewport();
camera->aspect = vp.getWidth() / static_cast<float>(vp.getHeight());
@ -343,7 +345,7 @@ void WorldRenderer::draw(
// Rendering fullscreen quad with
auto screenShader = assets->get<Shader>("screen");
screenShader->use();
screenShader->uniform1f("u_timer", Window::time());
screenShader->uniform1f("u_timer", timer);
screenShader->uniform1f("u_dayTime", level->getWorld()->daytime);
postProcessing->render(pctx, screenShader);
}

View File

@ -40,6 +40,7 @@ class WorldRenderer {
std::unique_ptr<Skybox> skybox;
std::unique_ptr<Batch3D> batch3d;
std::unique_ptr<ModelBatch> modelBatch;
float timer = 0.0f;
bool drawChunk(size_t index, Camera* camera, Shader* shader, bool culling);
void drawChunks(Chunks* chunks, Camera* camera, Shader* shader);
@ -73,6 +74,7 @@ public:
Camera* camera,
bool hudVisible,
bool pause,
float delta,
PostProcessing* postProcessing
);
void drawBorders(int sx, int sy, int sz, int ex, int ey, int ez);