Browse Source

Add blue noise input to sky pass

master
C. J. Howard 4 years ago
parent
commit
c81c2b11a5
6 changed files with 33 additions and 7 deletions
  1. +8
    -0
      src/game/bootloader.cpp
  2. +1
    -1
      src/game/states/play-state.cpp
  3. +5
    -1
      src/game/systems/tool-system.cpp
  4. +6
    -0
      src/game/systems/weather-system.cpp
  5. +10
    -1
      src/renderer/passes/sky-pass.cpp
  6. +3
    -4
      src/renderer/passes/sky-pass.hpp

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

@ -482,6 +482,13 @@ void setup_rendering(game_context* ctx)
ctx->framebuffer_bloom = new framebuffer(bloom_width, bloom_height); ctx->framebuffer_bloom = new framebuffer(bloom_width, bloom_height);
ctx->framebuffer_bloom->attach(framebuffer_attachment_type::color, ctx->bloom_texture); ctx->framebuffer_bloom->attach(framebuffer_attachment_type::color, ctx->bloom_texture);
// Load blue noise texture
texture_2d* blue_noise_map = ctx->resource_manager->load<texture_2d>("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 // Load fallback material
ctx->fallback_material = ctx->resource_manager->load<material>("fallback.mtl"); ctx->fallback_material = ctx->resource_manager->load<material>("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->overworld_sky_pass = new sky_pass(ctx->rasterizer, ctx->framebuffer_hdr, ctx->resource_manager);
ctx->app->get_event_dispatcher()->subscribe<mouse_moved_event>(ctx->overworld_sky_pass); ctx->app->get_event_dispatcher()->subscribe<mouse_moved_event>(ctx->overworld_sky_pass);
ctx->overworld_sky_pass->set_enabled(false); 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 = 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->set_fallback_material(ctx->fallback_material);
ctx->overworld_material_pass->shadow_map_pass = ctx->overworld_shadow_map_pass; ctx->overworld_material_pass->shadow_map_pass = ctx->overworld_shadow_map_pass;

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

@ -93,7 +93,7 @@ void play_state_enter(game_context* ctx)
sky_pass->set_sun_color(ctx->biome->sun_color * ctx->biome->sun_intensity); 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(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_sky_palette(ctx->biome->sky_palette);
ctx->weather_system->set_sun_palette(ctx->biome->sun_palette); ctx->weather_system->set_sun_palette(ctx->biome->sun_palette);
ctx->weather_system->set_ambient_palette(ctx->biome->ambient_palette); ctx->weather_system->set_ambient_palette(ctx->biome->ambient_palette);

+ 5
- 1
src/game/systems/tool-system.cpp View File

@ -41,7 +41,8 @@ tool_system::tool_system(entt::registry& registry, ::event_dispatcher* event_dis
viewport{0, 0, 0, 0}, viewport{0, 0, 0, 0},
mouse_position{0, 0}, mouse_position{0, 0},
pick_enabled(true), 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.z = 1.0f;
hand_angle_spring.w = hz_to_rads(8.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) void tool_system::update(double t, double dt)
{ {
if (active_tool == entt::null)
return;
// Advance animations // Advance animations
ascend_animation.advance(dt); ascend_animation.advance(dt);
descend_animation.advance(dt); descend_animation.advance(dt);

+ 6
- 0
src/game/systems/weather-system.cpp View File

@ -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; 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) void find_sun_ecliptic(double jd, double* longitude, double* latitude, double* distance)
{ {
const double t = (jd - 2451545.0) / 36525.0; 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)); + 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) void ecliptic_to_equatorial(double longitude, double latitude, double ecl, double* right_ascension, double* declination)
{ {
double eclip_x = std::cos(longitude) * std::cos(latitude); 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)); *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) void equatorial_to_horizontal(double right_ascension, double declination, double lmst, double latitude, double* azimuth, double* elevation)
{ {
double hour_angle = lmst - right_ascension; double hour_angle = lmst - right_ascension;

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

@ -49,7 +49,8 @@ sky_pass::sky_pass(::rasterizer* rasterizer, const ::framebuffer* framebuffer, r
moon_light(nullptr), moon_light(nullptr),
time_of_day(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)
{ {
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");
@ -63,6 +64,7 @@ sky_pass::sky_pass(::rasterizer* rasterizer, const ::framebuffer* framebuffer, r
resolution_input = shader_program->get_input("resolution"); resolution_input = shader_program->get_input("resolution");
time_input = shader_program->get_input("time"); time_input = shader_program->get_input("time");
time_of_day_input = shader_program->get_input("time_of_day"); 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[] = const float vertex_data[] =
{ {
@ -158,6 +160,8 @@ void sky_pass::render(render_context* context) const
time_input->upload(time); time_input->upload(time);
if (time_of_day_input) if (time_of_day_input)
time_of_day_input->upload(time_of_day); time_of_day_input->upload(time_of_day);
if (blue_noise_map_input)
blue_noise_map_input->upload(blue_noise_map);
// 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);
@ -220,6 +224,11 @@ void sky_pass::set_time_tween(const tween* time)
this->time_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) void sky_pass::handle_event(const mouse_moved_event& event)
{ {
mouse_position = {static_cast<float>(event.x), static_cast<float>(event.y)}; mouse_position = {static_cast<float>(event.x), static_cast<float>(event.y)};

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

@ -54,9 +54,7 @@ public:
void set_moon_light(const directional_light* light); void set_moon_light(const directional_light* light);
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_time_tween(const tween<double>* time); void set_time_tween(const tween<double>* time);
private: private:
@ -73,6 +71,7 @@ private:
const shader_input* resolution_input; const shader_input* resolution_input;
const shader_input* time_input; const shader_input* time_input;
const shader_input* time_of_day_input; const shader_input* time_of_day_input;
const shader_input* blue_noise_map_input;
vertex_buffer* quad_vbo; vertex_buffer* quad_vbo;
vertex_array* quad_vao; vertex_array* quad_vao;
@ -87,7 +86,7 @@ private:
float3 sun_color; float3 sun_color;
const directional_light* sun_light; const directional_light* sun_light;
const directional_light* moon_light; const directional_light* moon_light;
const texture_2d* sky_palette;
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;

Loading…
Cancel
Save