From c81c2b11a5b55e4bc96376edca7ae9e952bab32a Mon Sep 17 00:00:00 2001 From: "C. J. Howard" Date: Sun, 27 Sep 2020 14:32:33 -0700 Subject: [PATCH] Add blue noise input to sky pass --- src/game/bootloader.cpp | 8 ++++++++ src/game/states/play-state.cpp | 2 +- src/game/systems/tool-system.cpp | 6 +++++- src/game/systems/weather-system.cpp | 6 ++++++ src/renderer/passes/sky-pass.cpp | 11 ++++++++++- src/renderer/passes/sky-pass.hpp | 7 +++---- 6 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/game/bootloader.cpp b/src/game/bootloader.cpp index 90b603c..97e8df7 100644 --- a/src/game/bootloader.cpp +++ b/src/game/bootloader.cpp @@ -482,6 +482,13 @@ void setup_rendering(game_context* ctx) ctx->framebuffer_bloom = new framebuffer(bloom_width, bloom_height); ctx->framebuffer_bloom->attach(framebuffer_attachment_type::color, ctx->bloom_texture); + // Load blue noise texture + texture_2d* blue_noise_map = ctx->resource_manager->load("blue-noise.png"); + blue_noise_map->set_wrapping(texture_wrapping::repeat, texture_wrapping::repeat); + blue_noise_map->set_wrapping(texture_wrapping::repeat, texture_wrapping::repeat); + blue_noise_map->set_filters(texture_min_filter::nearest, texture_mag_filter::nearest); + blue_noise_map->set_filters(texture_min_filter::nearest, texture_mag_filter::nearest); + // Load fallback material ctx->fallback_material = ctx->resource_manager->load("fallback.mtl"); @@ -495,6 +502,7 @@ void setup_rendering(game_context* ctx) ctx->overworld_sky_pass = new sky_pass(ctx->rasterizer, ctx->framebuffer_hdr, ctx->resource_manager); ctx->app->get_event_dispatcher()->subscribe(ctx->overworld_sky_pass); ctx->overworld_sky_pass->set_enabled(false); + ctx->overworld_sky_pass->set_blue_noise_map(blue_noise_map); ctx->overworld_material_pass = new material_pass(ctx->rasterizer, ctx->framebuffer_hdr, ctx->resource_manager); ctx->overworld_material_pass->set_fallback_material(ctx->fallback_material); ctx->overworld_material_pass->shadow_map_pass = ctx->overworld_shadow_map_pass; diff --git a/src/game/states/play-state.cpp b/src/game/states/play-state.cpp index 37d51fa..cfd90bb 100644 --- a/src/game/states/play-state.cpp +++ b/src/game/states/play-state.cpp @@ -93,7 +93,7 @@ void play_state_enter(game_context* ctx) 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_time(2017, 8, 21, 6, 0, 0, -7.0); + ctx->weather_system->set_time(2020, 10, 1, 6, 0, 0, -7.0); ctx->weather_system->set_sky_palette(ctx->biome->sky_palette); ctx->weather_system->set_sun_palette(ctx->biome->sun_palette); ctx->weather_system->set_ambient_palette(ctx->biome->ambient_palette); diff --git a/src/game/systems/tool-system.cpp b/src/game/systems/tool-system.cpp index 24f0333..3b19da5 100644 --- a/src/game/systems/tool-system.cpp +++ b/src/game/systems/tool-system.cpp @@ -41,7 +41,8 @@ tool_system::tool_system(entt::registry& registry, ::event_dispatcher* event_dis viewport{0, 0, 0, 0}, mouse_position{0, 0}, pick_enabled(true), - was_pick_enabled(pick_enabled) + was_pick_enabled(pick_enabled), + active_tool(entt::null) { hand_angle_spring.z = 1.0f; hand_angle_spring.w = hz_to_rads(8.0f); @@ -94,6 +95,9 @@ tool_system::~tool_system() void tool_system::update(double t, double dt) { + if (active_tool == entt::null) + return; + // Advance animations ascend_animation.advance(dt); descend_animation.advance(dt); diff --git a/src/game/systems/weather-system.cpp b/src/game/systems/weather-system.cpp index fa6c827..cf445db 100644 --- a/src/game/systems/weather-system.cpp +++ b/src/game/systems/weather-system.cpp @@ -54,6 +54,8 @@ static double julian_day(int year, int month, int day, double time) return std::floor(365.25 * y) + std::floor(30.6001 * (m + 1.0)) - 15.0 + 1720996.5 + d + time; } +/// @see A Physically-Based Night Sky Model +/// @see http://www.powerfromthesun.net/Book/chapter03/chapter03.html void find_sun_ecliptic(double jd, double* longitude, double* latitude, double* distance) { const double t = (jd - 2451545.0) / 36525.0; @@ -118,6 +120,8 @@ void find_moon_ecliptic(double jd, double* longitude, double* latitude, double* + 0.000009 * std::cos(d2 - m)); } +/// @see http://www.stjarnhimlen.se/comp/ppcomp.html +/// @see http://www.geoastro.de/elevazmoon/basics/index.htm void ecliptic_to_equatorial(double longitude, double latitude, double ecl, double* right_ascension, double* declination) { double eclip_x = std::cos(longitude) * std::cos(latitude); @@ -132,6 +136,8 @@ void ecliptic_to_equatorial(double longitude, double latitude, double ecl, doubl *declination = std::atan2(equat_z, sqrt(equat_x * equat_x + equat_y * equat_y)); } +/// @see http://www.stjarnhimlen.se/comp/ppcomp.html +/// @see http://www.geoastro.de/elevazmoon/basics/index.htm void equatorial_to_horizontal(double right_ascension, double declination, double lmst, double latitude, double* azimuth, double* elevation) { double hour_angle = lmst - right_ascension; diff --git a/src/renderer/passes/sky-pass.cpp b/src/renderer/passes/sky-pass.cpp index 934c341..8f670a3 100644 --- a/src/renderer/passes/sky-pass.cpp +++ b/src/renderer/passes/sky-pass.cpp @@ -49,7 +49,8 @@ sky_pass::sky_pass(::rasterizer* rasterizer, const ::framebuffer* framebuffer, r moon_light(nullptr), time_of_day(0.0f), sky_model(nullptr), - sky_model_vao(nullptr) + sky_model_vao(nullptr), + blue_noise_map(nullptr) { shader_program = resource_manager->load<::shader_program>("sky.glsl"); model_view_projection_input = shader_program->get_input("model_view_projection"); @@ -63,6 +64,7 @@ sky_pass::sky_pass(::rasterizer* rasterizer, const ::framebuffer* framebuffer, r resolution_input = shader_program->get_input("resolution"); time_input = shader_program->get_input("time"); time_of_day_input = shader_program->get_input("time_of_day"); + blue_noise_map_input = shader_program->get_input("blue_noise_map"); const float vertex_data[] = { @@ -158,6 +160,8 @@ void sky_pass::render(render_context* context) const time_input->upload(time); if (time_of_day_input) time_of_day_input->upload(time_of_day); + if (blue_noise_map_input) + blue_noise_map_input->upload(blue_noise_map); // Draw sky model rasterizer->draw_arrays(*sky_model_vao, sky_model_drawing_mode, sky_model_start_index, sky_model_index_count); @@ -220,6 +224,11 @@ void sky_pass::set_time_tween(const tween* time) this->time_tween = time; } +void sky_pass::set_blue_noise_map(const texture_2d* texture) +{ + blue_noise_map = texture; +} + void sky_pass::handle_event(const mouse_moved_event& event) { mouse_position = {static_cast(event.x), static_cast(event.y)}; diff --git a/src/renderer/passes/sky-pass.hpp b/src/renderer/passes/sky-pass.hpp index f49539a..7fc3df2 100644 --- a/src/renderer/passes/sky-pass.hpp +++ b/src/renderer/passes/sky-pass.hpp @@ -54,9 +54,7 @@ public: void set_moon_light(const directional_light* light); void set_sky_gradient(const std::array& gradient); void set_time_of_day(float time); - - - + void set_blue_noise_map(const texture_2d* texture); void set_time_tween(const tween* time); private: @@ -73,6 +71,7 @@ private: const shader_input* resolution_input; const shader_input* time_input; const shader_input* time_of_day_input; + const shader_input* blue_noise_map_input; vertex_buffer* quad_vbo; vertex_array* quad_vao; @@ -87,7 +86,7 @@ private: float3 sun_color; const directional_light* sun_light; const directional_light* moon_light; - const texture_2d* sky_palette; + const texture_2d* blue_noise_map; float2 mouse_position; std::array sky_gradient; const tween* time_tween;