Browse Source

Fix sky pass and time tweening issues

master
C. J. Howard 3 years ago
parent
commit
bf51b4ae1d
5 changed files with 26 additions and 15 deletions
  1. +5
    -5
      src/animation/frame-scheduler.cpp
  2. +6
    -4
      src/game/bootloader.cpp
  3. +1
    -1
      src/renderer/passes/material-pass.cpp
  4. +12
    -3
      src/renderer/passes/sky-pass.cpp
  5. +2
    -2
      src/renderer/passes/sky-pass.hpp

+ 5
- 5
src/animation/frame-scheduler.cpp View File

@ -67,6 +67,10 @@ void frame_scheduler::reset()
void frame_scheduler::tick() void frame_scheduler::tick()
{ {
frame_end = std::chrono::high_resolution_clock::now();
frame_duration = static_cast<double>(std::chrono::duration_cast<std::chrono::microseconds>(frame_end - frame_start).count()) / 1000000.0;
frame_start = frame_end;
accumulator += std::min<double>(max_frame_duration, frame_duration); accumulator += std::min<double>(max_frame_duration, frame_duration);
while (accumulator >= update_timestep) while (accumulator >= update_timestep)
@ -75,10 +79,6 @@ void frame_scheduler::tick()
elapsed_time += update_timestep; elapsed_time += update_timestep;
accumulator -= update_timestep; accumulator -= update_timestep;
} }
render_callback(accumulator * update_rate); render_callback(accumulator * update_rate);
frame_end = std::chrono::high_resolution_clock::now();
frame_duration = static_cast<double>(std::chrono::duration_cast<std::chrono::microseconds>(frame_end - frame_start).count()) / 1000000.0;
frame_start = frame_end;
} }

+ 6
- 4
src/game/bootloader.cpp View File

@ -1236,14 +1236,17 @@ void setup_callbacks(game_context* ctx)
( (
[ctx](double t, double dt) [ctx](double t, double dt)
{ {
(*ctx->time_tween)[1] = t;
// Update tweens
ctx->time_tween->update();
ctx->overworld_sky_pass->update_tweens(); ctx->overworld_sky_pass->update_tweens();
ctx->overworld_scene->update_tweens(); ctx->overworld_scene->update_tweens();
ctx->underworld_scene->update_tweens(); ctx->underworld_scene->update_tweens();
ctx->ui_scene->update_tweens(); ctx->ui_scene->update_tweens();
ctx->focal_point_tween->update(); ctx->focal_point_tween->update();
ctx->underworld_final_pass->get_material()->update_tweens(); ctx->underworld_final_pass->get_material()->update_tweens();
// Set time tween time
(*ctx->time_tween)[1] = t;
ctx->timeline->advance(dt); ctx->timeline->advance(dt);
@ -1286,8 +1289,7 @@ void setup_callbacks(game_context* ctx)
ctx->menu_controls->update(); ctx->menu_controls->update();
ctx->camera_controls->update(); ctx->camera_controls->update();
// Update tweens
ctx->time_tween->update();
} }
); );

+ 1
- 1
src/renderer/passes/material-pass.cpp View File

@ -122,7 +122,7 @@ void material_pass::render(render_context* context) const
float2 resolution = {static_cast<float>(std::get<0>(viewport)), static_cast<float>(std::get<1>(viewport))}; float2 resolution = {static_cast<float>(std::get<0>(viewport)), static_cast<float>(std::get<1>(viewport))};
float time = (time_tween) ? time_tween->interpolate(context->alpha) : 0.0f;
float time = time_tween->interpolate(context->alpha);
const float3& camera_position = context->camera_transform.translation; const float3& camera_position = context->camera_transform.translation;
float3 focal_point = (focal_point_tween) ? focal_point_tween->interpolate(context->alpha) : float3{0, 0, 0}; float3 focal_point = (focal_point_tween) ? focal_point_tween->interpolate(context->alpha) : float3{0, 0, 0};
float4x4 view = context->camera->get_view_tween().interpolate(context->alpha); float4x4 view = context->camera->get_view_tween().interpolate(context->alpha);

+ 12
- 3
src/renderer/passes/sky-pass.cpp View File

@ -36,9 +36,9 @@
#include "renderer/material.hpp" #include "renderer/material.hpp"
#include "scene/camera.hpp" #include "scene/camera.hpp"
#include "utility/fundamental-types.hpp" #include "utility/fundamental-types.hpp"
#include "math/interpolation.hpp"
#include <cmath> #include <cmath>
#include <glad/glad.h> #include <glad/glad.h>
#include <iostream>
sky_pass::sky_pass(gl::rasterizer* rasterizer, const gl::framebuffer* framebuffer, resource_manager* resource_manager): sky_pass::sky_pass(gl::rasterizer* rasterizer, const gl::framebuffer* framebuffer, resource_manager* resource_manager):
render_pass(rasterizer, framebuffer), render_pass(rasterizer, framebuffer),
@ -52,7 +52,16 @@ sky_pass::sky_pass(gl::rasterizer* rasterizer, const gl::framebuffer* framebuffe
moon_model_vao(nullptr), moon_model_vao(nullptr),
moon_shader_program(nullptr), moon_shader_program(nullptr),
blue_noise_map(nullptr), blue_noise_map(nullptr),
observer_location{0.0f, 0.0f, 0.0f}
observer_location{0.0f, 0.0f, 0.0f},
time_tween(nullptr),
time_of_day_tween(0.0, math::lerp<float, float>),
julian_day_tween(0.0, math::lerp<float, float>),
sun_position_tween(float3{1.0f, 1.0f, 1.0f}, math::lerp<float3, float>),
sun_az_el_tween(float2{0.0f, 0.0f}, math::lerp<float2, float>),
moon_position_tween(float3{1.0f, 1.0f, 1.0f}, math::lerp<float3, float>),
moon_az_el_tween(float2{0.0f, 0.0f}, math::lerp<float2, float>),
horizon_color_tween(float3{0.0f, 0.0f, 0.0f}, math::lerp<float3, float>),
zenith_color_tween(float3{1.0f, 1.0f, 1.0f}, math::lerp<float3, float>)
{} {}
sky_pass::~sky_pass() sky_pass::~sky_pass()
@ -71,7 +80,7 @@ void sky_pass::render(render_context* context) const
auto viewport = framebuffer->get_dimensions(); auto viewport = framebuffer->get_dimensions();
rasterizer->set_viewport(0, 0, std::get<0>(viewport), std::get<1>(viewport)); rasterizer->set_viewport(0, 0, std::get<0>(viewport), std::get<1>(viewport));
float time = (time_tween) ? time_tween->interpolate(context->alpha) : 0.0f;
float time = time_tween->interpolate(context->alpha);
float2 resolution = {static_cast<float>(std::get<0>(viewport)), static_cast<float>(std::get<1>(viewport))}; float2 resolution = {static_cast<float>(std::get<0>(viewport)), static_cast<float>(std::get<1>(viewport))};
const scene::camera& camera = *context->camera; const scene::camera& camera = *context->camera;

+ 2
- 2
src/renderer/passes/sky-pass.hpp View File

@ -111,10 +111,10 @@ private:
const gl::texture_2d* blue_noise_map; const gl::texture_2d* blue_noise_map;
float2 mouse_position; float2 mouse_position;
const tween<double>* time_tween;
float3 observer_location; float3 observer_location;
tween<float> time_of_day_tween;
const tween<double>* time_tween;
tween<float> time_of_day_tween;
tween<float> julian_day_tween; tween<float> julian_day_tween;
tween<float3> sun_position_tween; tween<float3> sun_position_tween;
tween<float2> sun_az_el_tween; tween<float2> sun_az_el_tween;

Loading…
Cancel
Save