Browse Source

Tween sky pass shader inputs

master
C. J. Howard 4 years ago
parent
commit
2238e4abdd
5 changed files with 43 additions and 22 deletions
  1. +1
    -0
      src/game/bootloader.cpp
  2. +0
    -1
      src/game/states/play-state.cpp
  3. +2
    -1
      src/game/systems/weather-system.cpp
  4. +28
    -11
      src/renderer/passes/sky-pass.cpp
  5. +12
    -9
      src/renderer/passes/sky-pass.hpp

+ 1
- 0
src/game/bootloader.cpp View File

@ -1234,6 +1234,7 @@ void setup_callbacks(game_context* ctx)
{ {
(*ctx->time_tween)[1] = t; (*ctx->time_tween)[1] = t;
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();

+ 0
- 1
src/game/states/play-state.cpp View File

@ -89,7 +89,6 @@ void play_state_enter(game_context* ctx)
sky_pass* sky_pass = ctx->overworld_sky_pass; sky_pass* sky_pass = ctx->overworld_sky_pass;
sky_pass->set_enabled(true); sky_pass->set_enabled(true);
sky_pass->set_sky_model(ctx->resource_manager->load<model>("sky-dome.mdl")); sky_pass->set_sky_model(ctx->resource_manager->load<model>("sky-dome.mdl"));
sky_pass->set_sun_color(ctx->biome->sun_color * ctx->biome->sun_intensity);
ctx->weather_system->set_coordinates(ctx->biome->coordinates); ctx->weather_system->set_coordinates(ctx->biome->coordinates);
ctx->weather_system->set_time(2020, 10, 1, 6, 0, 0, -7.0); ctx->weather_system->set_time(2020, 10, 1, 6, 0, 0, -7.0);

+ 2
- 1
src/game/systems/weather-system.cpp View File

@ -320,10 +320,11 @@ void weather_system::update(double t, double dt)
ambient_light->set_color(ambient_color); ambient_light->set_color(ambient_color);
sky_pass->set_sky_gradient(gradient); sky_pass->set_sky_gradient(gradient);
sky_pass->set_time_of_day(hour * 60.0 * 60.0);
sky_pass->set_time_of_day(static_cast<float>(hour * 60.0 * 60.0));
sky_pass->set_observer_coordinates(coordinates); sky_pass->set_observer_coordinates(coordinates);
sky_pass->set_sun_coordinates(sun_position, sun_az_el); sky_pass->set_sun_coordinates(sun_position, sun_az_el);
sky_pass->set_moon_coordinates(moon_position, moon_az_el); sky_pass->set_moon_coordinates(moon_position, moon_az_el);
sky_pass->set_julian_day(static_cast<float>(jd));
} }
shadow_light = sun_light; shadow_light = sun_light;

+ 28
- 11
src/renderer/passes/sky-pass.cpp View File

@ -43,7 +43,6 @@
sky_pass::sky_pass(::rasterizer* rasterizer, const ::framebuffer* framebuffer, resource_manager* resource_manager): sky_pass::sky_pass(::rasterizer* rasterizer, const ::framebuffer* framebuffer, resource_manager* resource_manager):
render_pass(rasterizer, framebuffer), render_pass(rasterizer, framebuffer),
mouse_position({0.0f, 0.0f}), mouse_position({0.0f, 0.0f}),
time_of_day(0.0f),
sky_model(nullptr), sky_model(nullptr),
sky_model_vao(nullptr), sky_model_vao(nullptr),
blue_noise_map(nullptr), blue_noise_map(nullptr),
@ -51,7 +50,6 @@ sky_pass::sky_pass(::rasterizer* rasterizer, const ::framebuffer* framebuffer, r
{ {
shader_program = resource_manager->load<::shader_program>("sky.glsl"); shader_program = resource_manager->load<::shader_program>("sky.glsl");
model_view_projection_input = shader_program->get_input("model_view_projection"); model_view_projection_input = shader_program->get_input("model_view_projection");
sun_color_input = shader_program->get_input("sun_color");
sky_gradient_input = shader_program->get_input("sky_gradient"); sky_gradient_input = shader_program->get_input("sky_gradient");
mouse_input = shader_program->get_input("mouse"); mouse_input = shader_program->get_input("mouse");
resolution_input = shader_program->get_input("resolution"); resolution_input = shader_program->get_input("resolution");
@ -63,6 +61,7 @@ sky_pass::sky_pass(::rasterizer* rasterizer, const ::framebuffer* framebuffer, r
sun_az_el_input = shader_program->get_input("sun_az_el"); sun_az_el_input = shader_program->get_input("sun_az_el");
moon_position_input = shader_program->get_input("moon_position"); moon_position_input = shader_program->get_input("moon_position");
moon_az_el_input = shader_program->get_input("moon_az_el"); moon_az_el_input = shader_program->get_input("moon_az_el");
julian_day_input = shader_program->get_input("julian_day");
const float vertex_data[] = const float vertex_data[] =
{ {
@ -122,14 +121,20 @@ void sky_pass::render(render_context* context) const
float4x4 projection = camera.get_projection_tween().interpolate(context->alpha); float4x4 projection = camera.get_projection_tween().interpolate(context->alpha);
float4x4 model_view_projection = projection * model_view; float4x4 model_view_projection = projection * model_view;
float time_of_day = time_of_day_tween.interpolate(context->alpha);
float julian_day = julian_day_tween.interpolate(context->alpha);
float3 sun_position = sun_position_tween.interpolate(context->alpha);
float2 sun_az_el = sun_az_el_tween.interpolate(context->alpha);
float3 moon_position = moon_position_tween.interpolate(context->alpha);
float2 moon_az_el = moon_az_el_tween.interpolate(context->alpha);
// Change shader program // Change shader program
rasterizer->use_program(*shader_program); rasterizer->use_program(*shader_program);
// Upload shader parameters // Upload shader parameters
if (model_view_projection_input) if (model_view_projection_input)
model_view_projection_input->upload(model_view_projection); model_view_projection_input->upload(model_view_projection);
if (sun_color_input)
sun_color_input->upload(sun_color);
if (sky_gradient_input) if (sky_gradient_input)
sky_gradient_input->upload(0, &sky_gradient[0], 4); sky_gradient_input->upload(0, &sky_gradient[0], 4);
if (mouse_input) if (mouse_input)
@ -153,6 +158,8 @@ void sky_pass::render(render_context* context) const
moon_position_input->upload(moon_position); moon_position_input->upload(moon_position);
if (moon_az_el_input) if (moon_az_el_input)
moon_az_el_input->upload(moon_az_el); moon_az_el_input->upload(moon_az_el);
if (julian_day_input)
julian_day_input->upload(julian_day);
// Draw sky model // Draw sky model
rasterizer->draw_arrays(*sky_model_vao, sky_model_drawing_mode, sky_model_start_index, sky_model_index_count); rasterizer->draw_arrays(*sky_model_vao, sky_model_drawing_mode, sky_model_start_index, sky_model_index_count);
@ -180,9 +187,14 @@ void sky_pass::set_sky_model(const model* model)
} }
} }
void sky_pass::set_sun_color(const float3& color)
void sky_pass::update_tweens()
{ {
sun_color = color;
julian_day_tween.update();
sun_position_tween.update();
sun_az_el_tween.update();
moon_position_tween.update();
moon_az_el_tween.update();
time_of_day_tween.update();
} }
void sky_pass::set_sky_gradient(const std::array<float4, 4>& gradient) void sky_pass::set_sky_gradient(const std::array<float4, 4>& gradient)
@ -192,7 +204,7 @@ void sky_pass::set_sky_gradient(const std::array& gradient)
void sky_pass::set_time_of_day(float time) void sky_pass::set_time_of_day(float time)
{ {
time_of_day = time;
time_of_day_tween[1] = time;
} }
void sky_pass::set_time_tween(const tween<double>* time) void sky_pass::set_time_tween(const tween<double>* time)
@ -205,6 +217,11 @@ void sky_pass::set_blue_noise_map(const texture_2d* texture)
blue_noise_map = texture; blue_noise_map = texture;
} }
void sky_pass::set_julian_day(float jd)
{
julian_day_tween[1] = jd;
}
void sky_pass::set_observer_coordinates(const float2& coordinates) void sky_pass::set_observer_coordinates(const float2& coordinates)
{ {
observer_coordinates = coordinates; observer_coordinates = coordinates;
@ -212,14 +229,14 @@ void sky_pass::set_observer_coordinates(const float2& coordinates)
void sky_pass::set_sun_coordinates(const float3& position, const float2& az_el) void sky_pass::set_sun_coordinates(const float3& position, const float2& az_el)
{ {
sun_position = position;
sun_az_el = az_el;
sun_position_tween[1] = position;
sun_az_el_tween[1] = az_el;
} }
void sky_pass::set_moon_coordinates(const float3& position, const float2& az_el) void sky_pass::set_moon_coordinates(const float3& position, const float2& az_el)
{ {
moon_position = position;
moon_az_el = az_el;
moon_position_tween[1] = position;
moon_az_el_tween[1] = az_el;
} }
void sky_pass::handle_event(const mouse_moved_event& event) void sky_pass::handle_event(const mouse_moved_event& event)

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

@ -46,12 +46,15 @@ public:
virtual ~sky_pass(); virtual ~sky_pass();
virtual void render(render_context* context) const final; virtual void render(render_context* context) const final;
void update_tweens();
void set_sky_model(const model* model); void set_sky_model(const model* model);
void set_sun_color(const float3& color);
void set_sky_gradient(const std::array<float4, 4>& gradient); void set_sky_gradient(const std::array<float4, 4>& gradient);
void set_time_of_day(float time); void set_time_of_day(float time);
void set_blue_noise_map(const texture_2d* texture); void set_blue_noise_map(const texture_2d* texture);
void set_time_tween(const tween<double>* time); void set_time_tween(const tween<double>* time);
void set_julian_day(float jd);
void set_observer_coordinates(const float2& coordinates); void set_observer_coordinates(const float2& coordinates);
void set_sun_coordinates(const float3& position, const float2& az_el); void set_sun_coordinates(const float3& position, const float2& az_el);
void set_moon_coordinates(const float3& position, const float2& az_el); void set_moon_coordinates(const float3& position, const float2& az_el);
@ -61,7 +64,6 @@ private:
shader_program* shader_program; shader_program* shader_program;
const shader_input* model_view_projection_input; const shader_input* model_view_projection_input;
const shader_input* sun_color_input;
const shader_input* sky_gradient_input; const shader_input* sky_gradient_input;
const shader_input* mouse_input; const shader_input* mouse_input;
const shader_input* resolution_input; const shader_input* resolution_input;
@ -73,6 +75,7 @@ private:
const shader_input* moon_position_input; const shader_input* moon_position_input;
const shader_input* moon_az_el_input; const shader_input* moon_az_el_input;
const shader_input* blue_noise_map_input; const shader_input* blue_noise_map_input;
const shader_input* julian_day_input;
vertex_buffer* quad_vbo; vertex_buffer* quad_vbo;
@ -84,18 +87,18 @@ private:
std::size_t sky_model_start_index; std::size_t sky_model_start_index;
std::size_t sky_model_index_count; std::size_t sky_model_index_count;
float sun_angular_radius;
float3 sun_color;
const texture_2d* blue_noise_map; const texture_2d* blue_noise_map;
float2 mouse_position; float2 mouse_position;
std::array<float4, 4> sky_gradient; std::array<float4, 4> sky_gradient;
const tween<double>* time_tween; const tween<double>* time_tween;
float time_of_day;
float2 observer_coordinates; float2 observer_coordinates;
float3 sun_position;
float2 sun_az_el;
float3 moon_position;
float2 moon_az_el;
tween<float> time_of_day_tween;
tween<float> julian_day_tween;
tween<float3> sun_position_tween;
tween<float2> sun_az_el_tween;
tween<float3> moon_position_tween;
tween<float2> moon_az_el_tween;
}; };
#endif // ANTKEEPER_SKY_PASS_HPP #endif // ANTKEEPER_SKY_PASS_HPP

Loading…
Cancel
Save