Browse Source

Add blue noise to final render pass, apply luminance correction to scaled color of star catalog stars

master
C. J. Howard 3 years ago
parent
commit
832da4d38d
4 changed files with 49 additions and 11 deletions
  1. +2
    -0
      src/game/bootloader.cpp
  2. +28
    -3
      src/renderer/passes/final-pass.cpp
  3. +10
    -0
      src/renderer/passes/final-pass.hpp
  4. +9
    -8
      src/renderer/passes/sky-pass.cpp

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

@ -520,6 +520,7 @@ void setup_rendering(game_context* ctx)
ctx->overworld_final_pass = new ::final_pass(ctx->rasterizer, &ctx->rasterizer->get_default_framebuffer(), ctx->resource_manager); ctx->overworld_final_pass = new ::final_pass(ctx->rasterizer, &ctx->rasterizer->get_default_framebuffer(), ctx->resource_manager);
ctx->overworld_final_pass->set_color_texture(ctx->framebuffer_hdr_color); ctx->overworld_final_pass->set_color_texture(ctx->framebuffer_hdr_color);
ctx->overworld_final_pass->set_bloom_texture(ctx->bloom_texture); ctx->overworld_final_pass->set_bloom_texture(ctx->bloom_texture);
ctx->overworld_final_pass->set_blue_noise_texture(blue_noise_map);
ctx->overworld_compositor = new compositor(); ctx->overworld_compositor = new compositor();
ctx->overworld_compositor->add_pass(ctx->overworld_shadow_map_clear_pass); ctx->overworld_compositor->add_pass(ctx->overworld_shadow_map_clear_pass);
ctx->overworld_compositor->add_pass(ctx->overworld_shadow_map_pass); ctx->overworld_compositor->add_pass(ctx->overworld_shadow_map_pass);
@ -755,6 +756,7 @@ void setup_animation(game_context* ctx)
ctx->overworld_sky_pass->set_time_tween(ctx->time_tween); ctx->overworld_sky_pass->set_time_tween(ctx->time_tween);
ctx->overworld_material_pass->set_time_tween(ctx->time_tween); ctx->overworld_material_pass->set_time_tween(ctx->time_tween);
ctx->overworld_material_pass->set_focal_point_tween(ctx->focal_point_tween); ctx->overworld_material_pass->set_focal_point_tween(ctx->focal_point_tween);
ctx->overworld_final_pass->set_time_tween(ctx->time_tween);
ctx->underworld_material_pass->set_time_tween(ctx->time_tween); ctx->underworld_material_pass->set_time_tween(ctx->time_tween);
ctx->underworld_material_pass->set_focal_point_tween(ctx->focal_point_tween); ctx->underworld_material_pass->set_focal_point_tween(ctx->focal_point_tween);
ctx->underworld_final_pass->set_time_tween(ctx->time_tween); ctx->underworld_final_pass->set_time_tween(ctx->time_tween);

+ 28
- 3
src/renderer/passes/final-pass.cpp View File

@ -39,12 +39,18 @@
final_pass::final_pass(gl::rasterizer* rasterizer, const gl::framebuffer* framebuffer, resource_manager* resource_manager): final_pass::final_pass(gl::rasterizer* rasterizer, const gl::framebuffer* framebuffer, resource_manager* resource_manager):
render_pass(rasterizer, framebuffer), render_pass(rasterizer, framebuffer),
color_texture(nullptr), color_texture(nullptr),
bloom_texture(nullptr)
bloom_texture(nullptr),
blue_noise_texture(nullptr),
blue_noise_scale(1.0),
time_tween(nullptr)
{ {
shader_program = resource_manager->load<gl::shader_program>("final.glsl"); shader_program = resource_manager->load<gl::shader_program>("final.glsl");
color_texture_input = shader_program->get_input("color_texture"); color_texture_input = shader_program->get_input("color_texture");
bloom_texture_input = shader_program->get_input("bloom_texture"); bloom_texture_input = shader_program->get_input("bloom_texture");
blue_noise_texture_input = shader_program->get_input("blue_noise_texture");
blue_noise_scale_input = shader_program->get_input("blue_noise_scale");
resolution_input = shader_program->get_input("resolution"); resolution_input = shader_program->get_input("resolution");
time_input = shader_program->get_input("time");
const float vertex_data[] = const float vertex_data[] =
{ {
@ -85,14 +91,23 @@ void final_pass::render(render_context* context) const
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));
float2 resolution = {std::get<0>(viewport), std::get<1>(viewport)}; float2 resolution = {std::get<0>(viewport), std::get<1>(viewport)};
float time = (time_tween) ? (*time_tween)[context->alpha] : 0.0f;
// Change shader program // Change shader program
rasterizer->use_program(*shader_program); rasterizer->use_program(*shader_program);
// Upload shader parameters // Upload shader parameters
color_texture_input->upload(color_texture); color_texture_input->upload(color_texture);
bloom_texture_input->upload(bloom_texture);
resolution_input->upload(resolution);
if (bloom_texture && bloom_texture_input)
bloom_texture_input->upload(bloom_texture);
if (blue_noise_texture && blue_noise_texture_input)
blue_noise_texture_input->upload(blue_noise_texture);
if (blue_noise_scale_input)
blue_noise_scale_input->upload(blue_noise_scale);
if (resolution_input)
resolution_input->upload(resolution);
if (time_input)
time_input->upload(time);
// Draw quad // Draw quad
rasterizer->draw_arrays(*quad_vao, gl::drawing_mode::triangles, 0, 6); rasterizer->draw_arrays(*quad_vao, gl::drawing_mode::triangles, 0, 6);
@ -108,3 +123,13 @@ void final_pass::set_bloom_texture(const gl::texture_2d* texture)
this->bloom_texture = texture; this->bloom_texture = texture;
} }
void final_pass::set_blue_noise_texture(const gl::texture_2d* texture)
{
this->blue_noise_texture = texture;
blue_noise_scale = 1.0f / static_cast<float>(texture->get_dimensions()[0]);
}
void final_pass::set_time_tween(const tween<double>* time)
{
this->time_tween = time;
}

+ 10
- 0
src/renderer/passes/final-pass.hpp View File

@ -27,6 +27,7 @@
#include "gl/vertex-buffer.hpp" #include "gl/vertex-buffer.hpp"
#include "gl/vertex-array.hpp" #include "gl/vertex-array.hpp"
#include "gl/texture-2d.hpp" #include "gl/texture-2d.hpp"
#include "animation/tween.hpp"
class resource_manager; class resource_manager;
@ -42,17 +43,26 @@ public:
void set_color_texture(const gl::texture_2d* texture); void set_color_texture(const gl::texture_2d* texture);
void set_bloom_texture(const gl::texture_2d* texture); void set_bloom_texture(const gl::texture_2d* texture);
void set_blue_noise_texture(const gl::texture_2d* texture);
void set_time_tween(const tween<double>* time);
private: private:
gl::shader_program* shader_program; gl::shader_program* shader_program;
const gl::shader_input* color_texture_input; const gl::shader_input* color_texture_input;
const gl::shader_input* bloom_texture_input; const gl::shader_input* bloom_texture_input;
const gl::shader_input* blue_noise_texture_input;
const gl::shader_input* blue_noise_scale_input;
const gl::shader_input* resolution_input; const gl::shader_input* resolution_input;
const gl::shader_input* time_input;
gl::vertex_buffer* quad_vbo; gl::vertex_buffer* quad_vbo;
gl::vertex_array* quad_vao; gl::vertex_array* quad_vao;
const gl::texture_2d* color_texture; const gl::texture_2d* color_texture;
const gl::texture_2d* bloom_texture; const gl::texture_2d* bloom_texture;
const gl::texture_2d* blue_noise_texture;
float blue_noise_scale;
const tween<double>* time_tween;
}; };
#endif // ANTKEEPER_FINAL_PASS_HPP #endif // ANTKEEPER_FINAL_PASS_HPP

+ 9
- 8
src/renderer/passes/sky-pass.cpp View File

@ -103,7 +103,7 @@ sky_pass::sky_pass(gl::rasterizer* rasterizer, const gl::framebuffer* framebuffe
catch (const std::exception& e) catch (const std::exception& e)
{} {}
// Convert degrees to radians
// Convert right ascension and declination from degrees to radians
ra = math::wrap_radians(math::radians(ra)); ra = math::wrap_radians(math::radians(ra));
dec = math::wrap_radians(math::radians(dec)); dec = math::wrap_radians(math::radians(dec));
@ -120,9 +120,14 @@ sky_pass::sky_pass(gl::rasterizer* rasterizer, const gl::framebuffer* framebuffe
// Transform to ACEScg colorspace // Transform to ACEScg colorspace
double3 color_acescg = srgb_to_acescg(color_srgb); double3 color_acescg = srgb_to_acescg(color_srgb);
// Scale color by apparent magnitude
double intensity = astro::vmag_to_lux(vmag);
double3 scaled_color = color_acescg * intensity;
// Calculate color luminance
double color_luminance = acescg_to_luminance(color_acescg);
// Convert apparent magnitude to lux
double vmag_lux = astro::vmag_to_lux(vmag);
// Normalized color luminance and scale by apparent magnitude
double3 scaled_color = color_acescg * ((1.0 / color_luminance) * vmag_lux);
// Build vertex // Build vertex
*(star_vertex++) = static_cast<float>(rectangular.x); *(star_vertex++) = static_cast<float>(rectangular.x);
@ -157,10 +162,6 @@ sky_pass::sky_pass(gl::rasterizer* rasterizer, const gl::framebuffer* framebuffe
star_projection_input = star_shader_program->get_input("projection"); star_projection_input = star_shader_program->get_input("projection");
star_distance_input = star_shader_program->get_input("star_distance"); star_distance_input = star_shader_program->get_input("star_distance");
star_exposure_input = star_shader_program->get_input("camera.exposure"); star_exposure_input = star_shader_program->get_input("camera.exposure");
std::cout << "vmag_to_lux(-14.2) = " << astro::vmag_to_lux(-14.2) << std::endl;
std::cout << "vmag_to_lux(-26.74) = " << astro::vmag_to_lux(-26.74) << std::endl;
std::cout << "vmag_to_lux(-1.47) = " << astro::vmag_to_lux(-1.47) << std::endl;
} }
sky_pass::~sky_pass() sky_pass::~sky_pass()

Loading…
Cancel
Save