|
|
@ -48,8 +48,10 @@ sky_pass::sky_pass(::rasterizer* rasterizer, const ::framebuffer* framebuffer, r |
|
|
|
matrix_input = shader_program->get_input("matrix"); |
|
|
|
sun_direction_input = shader_program->get_input("sun_direction"); |
|
|
|
sun_angular_radius_input = shader_program->get_input("sun_angular_radius"); |
|
|
|
sky_gradient_input = shader_program->get_input("sky_gradient"); |
|
|
|
bayer_matrix_input = shader_program->get_input("bayer_matrix"); |
|
|
|
horizon_color_input = shader_program->get_input("horizon_color"); |
|
|
|
zenith_color_input = shader_program->get_input("zenith_color"); |
|
|
|
sun_angular_radius_input = shader_program->get_input("sun_angular_radius"); |
|
|
|
sun_color_input = shader_program->get_input("sun_color"); |
|
|
|
|
|
|
|
const float vertex_data[] = |
|
|
|
{ |
|
|
@ -68,32 +70,10 @@ sky_pass::sky_pass(::rasterizer* rasterizer, const ::framebuffer* framebuffer, r |
|
|
|
quad_vbo = new vertex_buffer(sizeof(float) * vertex_size * vertex_count, vertex_data); |
|
|
|
quad_vao = new vertex_array(); |
|
|
|
quad_vao->bind_attribute(VERTEX_POSITION_LOCATION, *quad_vbo, 3, vertex_attribute_type::float_32, vertex_stride, 0); |
|
|
|
|
|
|
|
sky_gradient = resource_manager->load<texture_2d>("grassland-sky-gradient.png"); |
|
|
|
sky_gradient->set_wrapping(texture_wrapping::clamp, texture_wrapping::clamp); |
|
|
|
sky_gradient->set_filters(texture_min_filter::linear, texture_mag_filter::linear); |
|
|
|
|
|
|
|
// Generate Bayer matrix texture
|
|
|
|
static const char bayer_matrix_data[] = |
|
|
|
{ |
|
|
|
0, 32, 8, 40, 2, 34, 10, 42, |
|
|
|
48, 16, 56, 24, 50, 18, 58, 26, |
|
|
|
12, 44, 4, 36, 14, 46, 6, 38, |
|
|
|
60, 28, 52, 20, 62, 30, 54, 22, |
|
|
|
3, 35, 11, 43, 1, 33, 9, 41, |
|
|
|
51, 19, 59, 27, 49, 17, 57, 25, |
|
|
|
15, 47, 7, 39, 13, 45, 5, 37, |
|
|
|
63, 31, 55, 23, 61, 29, 53, 21 |
|
|
|
}; |
|
|
|
bayer_matrix = new texture_2d(8, 8, pixel_type::int_8, pixel_format::r, bayer_matrix_data); |
|
|
|
bayer_matrix->set_wrapping(texture_wrapping::repeat, texture_wrapping::repeat); |
|
|
|
bayer_matrix->set_filters(texture_min_filter::nearest, texture_mag_filter::nearest); |
|
|
|
bayer_matrix->set_max_anisotropy(0.0f); |
|
|
|
} |
|
|
|
|
|
|
|
sky_pass::~sky_pass() |
|
|
|
{ |
|
|
|
delete bayer_matrix; |
|
|
|
delete quad_vao; |
|
|
|
delete quad_vbo; |
|
|
|
} |
|
|
@ -109,11 +89,9 @@ void sky_pass::render(render_context* context) const |
|
|
|
|
|
|
|
auto viewport = framebuffer->get_dimensions(); |
|
|
|
rasterizer->set_viewport(0, 0, std::get<0>(viewport), std::get<1>(viewport)); |
|
|
|
|
|
|
|
float3 sun_direction = {0, 0, -1}; |
|
|
|
float sun_angular_radius = math::radians<float>(3.0f); |
|
|
|
|
|
|
|
// Find sun direction
|
|
|
|
float3 sun_direction = {0, 0, -1}; |
|
|
|
const std::list<scene_object_base*>* lights = context->scene->get_objects(light::object_type_id); |
|
|
|
for (const scene_object_base* object: *lights) |
|
|
|
{ |
|
|
@ -135,13 +113,39 @@ void sky_pass::render(render_context* context) const |
|
|
|
rasterizer->use_program(*shader_program); |
|
|
|
|
|
|
|
// Upload shader parameters
|
|
|
|
matrix_input->upload(matrix); |
|
|
|
sun_direction_input->upload(sun_direction); |
|
|
|
sun_angular_radius_input->upload(sun_angular_radius); |
|
|
|
sky_gradient_input->upload(sky_gradient); |
|
|
|
bayer_matrix_input->upload(bayer_matrix); |
|
|
|
|
|
|
|
if (matrix_input) |
|
|
|
matrix_input->upload(matrix); |
|
|
|
if (sun_direction_input) |
|
|
|
sun_direction_input->upload(sun_direction); |
|
|
|
if (sun_angular_radius_input) |
|
|
|
sun_angular_radius_input->upload(sun_angular_radius); |
|
|
|
if (sun_color_input) |
|
|
|
sun_color_input->upload(sun_color); |
|
|
|
if (horizon_color_input) |
|
|
|
horizon_color_input->upload(horizon_color); |
|
|
|
if (zenith_color_input) |
|
|
|
zenith_color_input->upload(zenith_color); |
|
|
|
|
|
|
|
// Draw quad
|
|
|
|
rasterizer->draw_arrays(*quad_vao, drawing_mode::triangles, 0, 6); |
|
|
|
} |
|
|
|
|
|
|
|
void sky_pass::set_sun_angular_radius(float angle) |
|
|
|
{ |
|
|
|
sun_angular_radius = angle; |
|
|
|
} |
|
|
|
|
|
|
|
void sky_pass::set_sun_color(const float3& color) |
|
|
|
{ |
|
|
|
sun_color = color; |
|
|
|
} |
|
|
|
|
|
|
|
void sky_pass::set_horizon_color(const float3& color) |
|
|
|
{ |
|
|
|
horizon_color = color; |
|
|
|
} |
|
|
|
|
|
|
|
void sky_pass::set_zenith_color(const float3& color) |
|
|
|
{ |
|
|
|
zenith_color = color; |
|
|
|
} |