Browse Source

Add brood state, rename play state to forage state, revise and reorganize camera compositors

master
C. J. Howard 2 years ago
parent
commit
402a75265e
16 changed files with 616 additions and 273 deletions
  1. +0
    -1
      CMakeLists.txt
  2. +37
    -0
      src/entity/components/camera.hpp
  3. +10
    -3
      src/entity/systems/astronomy.cpp
  4. +5
    -5
      src/entity/systems/control.cpp
  5. +2
    -2
      src/entity/systems/control.hpp
  6. +188
    -189
      src/game/bootloader.cpp
  7. +28
    -23
      src/game/context.hpp
  8. +97
    -0
      src/game/states/brood.cpp
  9. +6
    -6
      src/game/states/brood.hpp
  10. +32
    -8
      src/game/states/forage.cpp
  11. +39
    -0
      src/game/states/forage.hpp
  12. +41
    -10
      src/game/states/loading.cpp
  13. +31
    -9
      src/game/states/nuptial-flight.cpp
  14. +7
    -7
      src/game/states/splash.cpp
  15. +75
    -8
      src/renderer/passes/sky-pass.cpp
  16. +18
    -2
      src/renderer/passes/sky-pass.hpp

+ 0
- 1
CMakeLists.txt View File

@ -1,6 +1,5 @@
cmake_minimum_required(VERSION 3.7)
option(VERSION_STRING "Project version string" "0.0.0")
project(antkeeper VERSION ${VERSION_STRING} LANGUAGES CXX)

+ 37
- 0
src/entity/components/camera.hpp View File

@ -0,0 +1,37 @@
/*
* Copyright (C) 2021 Christopher J. Howard
*
* This file is part of Antkeeper source code.
*
* Antkeeper source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ENTITY_COMPONENT_CAMERA_HPP
#define ANTKEEPER_ENTITY_COMPONENT_CAMERA_HPP
#include "scene/camera.hpp"
namespace entity {
namespace component {
struct flight_controller
{
};
} // namespace component
} // namespace entity
#endif // ANTKEEPER_ENTITY_COMPONENT_CAMERA_HPP

+ 10
- 3
src/entity/systems/astronomy.cpp View File

@ -177,15 +177,22 @@ void astronomy::update(double t, double dt)
)
);
// Sun color at the outer atmosphere
float3 sun_color_outer = math::type_cast<float>(blackbody.luminous_intensity * distance_attenuation);
// Sun color at sea level
float3 sun_color_inner = math::type_cast<float>(blackbody.luminous_intensity * distance_attenuation * atmospheric_transmittance);
// Update blackbody light color and intensity
sun_light->set_color(math::type_cast<float>(blackbody.luminous_intensity * atmospheric_transmittance));
sun_light->set_intensity(static_cast<float>(distance_attenuation));
sun_light->set_color(sun_color_inner);
sun_light->set_intensity(1.0f);
// Upload blackbody params to sky pass
if (this->sky_pass)
{
this->sky_pass->set_sun_position(math::type_cast<float>(blackbody_position_topocentric));
this->sky_pass->set_sun_color(math::type_cast<float>(blackbody.luminous_intensity * distance_attenuation));
this->sky_pass->set_sun_color(sun_color_outer, sun_color_inner);
double blackbody_angular_radius = std::asin((celestial_body.radius * 2.0) / (blackbody_distance * 2.0));
this->sky_pass->set_sun_angular_radius(static_cast<float>(blackbody_angular_radius));

+ 5
- 5
src/entity/systems/control.cpp View File

@ -37,7 +37,7 @@ control::control(entity::registry& registry):
zoom(0.0f),
tool(nullptr),
flashlight_entity(entt::null),
underworld_camera(nullptr)
underground_camera(nullptr)
{
control_set.add_control(&move_forward_control);
control_set.add_control(&move_back_control);
@ -186,9 +186,9 @@ void control::update(double t, double dt)
command::set_transform(registry, flashlight_entity, flashlight_transform, false);
if (underworld_camera)
if (underground_camera)
{
underworld_camera->look_at({0, -flashlight_depth + 50.0f, 0}, {0, -flashlight_depth, 0}, {0, 0, -1});
underground_camera->look_at({0, -flashlight_depth + 50.0f, 0}, {0, -flashlight_depth, 0}, {0, 0, -1});
}
}
}
@ -224,9 +224,9 @@ void control::set_viewport(const float4& viewport)
this->viewport = viewport;
}
void control::set_underworld_camera(scene::camera* camera)
void control::set_underground_camera(scene::camera* camera)
{
this->underworld_camera = camera;
this->underground_camera = camera;
}
void control::handle_event(const mouse_moved_event& event)

+ 2
- 2
src/entity/systems/control.hpp View File

@ -58,7 +58,7 @@ public:
void set_camera_subject(entity::id entity_id);
void set_viewport(const float4& viewport);
void set_underworld_camera(scene::camera* camera);
void set_underground_camera(scene::camera* camera);
input::control_set* get_control_set();
input::control* get_move_forward_control();
@ -148,7 +148,7 @@ private:
entity::id flashlight_entity;
entity::id camera_subject_entity;
scene::camera* underworld_camera;
scene::camera* underground_camera;
float mouse_angle;
float old_mouse_angle;

+ 188
- 189
src/game/bootloader.cpp View File

@ -497,71 +497,87 @@ void setup_rendering(game::context* ctx)
// Load fallback material
ctx->fallback_material = ctx->resource_manager->load<material>("fallback.mtl");
// Setup overworld compositor
ctx->overworld_shadow_map_clear_pass = new clear_pass(ctx->rasterizer, ctx->shadow_map_framebuffer);
ctx->overworld_shadow_map_clear_pass->set_cleared_buffers(false, true, false);
ctx->overworld_shadow_map_clear_pass->set_clear_depth(1.0f);
ctx->overworld_shadow_map_pass = new shadow_map_pass(ctx->rasterizer, ctx->shadow_map_framebuffer, ctx->resource_manager);
ctx->overworld_shadow_map_pass->set_split_scheme_weight(0.75f);
ctx->overworld_clear_pass = new clear_pass(ctx->rasterizer, ctx->framebuffer_hdr);
ctx->overworld_clear_pass->set_cleared_buffers(true, true, true);
ctx->overworld_clear_pass->set_clear_depth(0.0f);
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->overworld_sky_pass->set_enabled(true);
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;
ctx->overworld_material_pass->shadow_map = ctx->shadow_map_depth_texture;
ctx->app->get_event_dispatcher()->subscribe<mouse_moved_event>(ctx->overworld_material_pass);
ctx->overworld_outline_pass = new outline_pass(ctx->rasterizer, ctx->framebuffer_hdr, ctx->resource_manager);
ctx->overworld_outline_pass->set_outline_width(0.25f);
ctx->overworld_outline_pass->set_outline_color(float4{1.0f, 1.0f, 1.0f, 1.0f});
ctx->overworld_outline_pass->set_enabled(false);
ctx->overworld_bloom_pass = new bloom_pass(ctx->rasterizer, ctx->framebuffer_bloom, ctx->resource_manager);
ctx->overworld_bloom_pass->set_source_texture(ctx->framebuffer_hdr_color);
ctx->overworld_bloom_pass->set_brightness_threshold(1.0f);
ctx->overworld_bloom_pass->set_blur_iterations(5);
ctx->overworld_bloom_pass->set_enabled(true);
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_bloom_texture(ctx->bloom_texture);
ctx->overworld_final_pass->set_blue_noise_texture(blue_noise_map);
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_pass);
ctx->overworld_compositor->add_pass(ctx->overworld_clear_pass);
ctx->overworld_compositor->add_pass(ctx->overworld_sky_pass);
ctx->overworld_compositor->add_pass(ctx->overworld_material_pass);
//ctx->overworld_compositor->add_pass(ctx->overworld_outline_pass);
ctx->overworld_compositor->add_pass(ctx->overworld_bloom_pass);
ctx->overworld_compositor->add_pass(ctx->overworld_final_pass);
// Setup underworld compositor
ctx->underworld_clear_pass = new clear_pass(ctx->rasterizer, ctx->framebuffer_hdr);
ctx->underworld_clear_pass->set_cleared_buffers(true, true, false);
ctx->underworld_material_pass = new material_pass(ctx->rasterizer, ctx->framebuffer_hdr, ctx->resource_manager);
ctx->underworld_material_pass->set_fallback_material(ctx->fallback_material);
ctx->app->get_event_dispatcher()->subscribe<mouse_moved_event>(ctx->underworld_material_pass);
gl::shader_program* underworld_final_shader = ctx->resource_manager->load<gl::shader_program>("underground-final.glsl");
ctx->underworld_final_pass = new simple_render_pass(ctx->rasterizer, &ctx->rasterizer->get_default_framebuffer(), underworld_final_shader);
ctx->underground_color_texture_property = ctx->underworld_final_pass->get_material()->add_property<const gl::texture_2d*>("color_texture");
ctx->underground_color_texture_property->set_value(ctx->framebuffer_hdr_color);
ctx->underworld_final_pass->get_material()->update_tweens();
ctx->underworld_compositor = new compositor();
ctx->underworld_compositor->add_pass(ctx->underworld_clear_pass);
ctx->underworld_compositor->add_pass(ctx->underworld_material_pass);
ctx->underworld_compositor->add_pass(ctx->underworld_final_pass);
// Setup UI camera compositor
ctx->ui_clear_pass = new clear_pass(ctx->rasterizer, &ctx->rasterizer->get_default_framebuffer());
ctx->ui_clear_pass->set_cleared_buffers(false, true, false);
ctx->ui_clear_pass->set_clear_depth(0.0f);
ctx->ui_material_pass = new material_pass(ctx->rasterizer, &ctx->rasterizer->get_default_framebuffer(), ctx->resource_manager);
ctx->ui_material_pass->set_fallback_material(ctx->fallback_material);
ctx->ui_compositor = new compositor();
ctx->ui_compositor->add_pass(ctx->ui_clear_pass);
ctx->ui_compositor->add_pass(ctx->ui_material_pass);
// Setup common render passes
{
ctx->common_bloom_pass = new bloom_pass(ctx->rasterizer, ctx->framebuffer_bloom, ctx->resource_manager);
ctx->common_bloom_pass->set_source_texture(ctx->framebuffer_hdr_color);
ctx->common_bloom_pass->set_brightness_threshold(1.0f);
ctx->common_bloom_pass->set_blur_iterations(5);
ctx->common_final_pass = new ::final_pass(ctx->rasterizer, &ctx->rasterizer->get_default_framebuffer(), ctx->resource_manager);
ctx->common_final_pass->set_color_texture(ctx->framebuffer_hdr_color);
ctx->common_final_pass->set_bloom_texture(ctx->bloom_texture);
ctx->common_final_pass->set_blue_noise_texture(blue_noise_map);
}
// Setup UI compositor
{
ctx->ui_clear_pass = new clear_pass(ctx->rasterizer, &ctx->rasterizer->get_default_framebuffer());
ctx->ui_clear_pass->set_cleared_buffers(false, true, false);
ctx->ui_clear_pass->set_clear_depth(0.0f);
ctx->ui_material_pass = new material_pass(ctx->rasterizer, &ctx->rasterizer->get_default_framebuffer(), ctx->resource_manager);
ctx->ui_material_pass->set_fallback_material(ctx->fallback_material);
ctx->ui_compositor = new compositor();
ctx->ui_compositor->add_pass(ctx->ui_clear_pass);
ctx->ui_compositor->add_pass(ctx->ui_material_pass);
}
// Setup underground compositor
{
ctx->underground_clear_pass = new clear_pass(ctx->rasterizer, ctx->framebuffer_hdr);
ctx->underground_clear_pass->set_cleared_buffers(true, true, false);
ctx->underground_clear_pass->set_clear_color({1, 0, 1, 0});
ctx->underground_clear_pass->set_clear_depth(0.0f);
ctx->underground_material_pass = new material_pass(ctx->rasterizer, ctx->framebuffer_hdr, ctx->resource_manager);
ctx->underground_material_pass->set_fallback_material(ctx->fallback_material);
ctx->app->get_event_dispatcher()->subscribe<mouse_moved_event>(ctx->underground_material_pass);
ctx->underground_compositor = new compositor();
ctx->underground_compositor->add_pass(ctx->underground_clear_pass);
ctx->underground_compositor->add_pass(ctx->underground_material_pass);
ctx->underground_compositor->add_pass(ctx->common_bloom_pass);
ctx->underground_compositor->add_pass(ctx->common_final_pass);
}
// Setup surface compositor
{
ctx->surface_shadow_map_clear_pass = new clear_pass(ctx->rasterizer, ctx->shadow_map_framebuffer);
ctx->surface_shadow_map_clear_pass->set_cleared_buffers(false, true, false);
ctx->surface_shadow_map_clear_pass->set_clear_depth(1.0f);
ctx->surface_shadow_map_pass = new shadow_map_pass(ctx->rasterizer, ctx->shadow_map_framebuffer, ctx->resource_manager);
ctx->surface_shadow_map_pass->set_split_scheme_weight(0.75f);
ctx->surface_clear_pass = new clear_pass(ctx->rasterizer, ctx->framebuffer_hdr);
ctx->surface_clear_pass->set_cleared_buffers(true, true, true);
ctx->surface_clear_pass->set_clear_depth(0.0f);
ctx->surface_sky_pass = new sky_pass(ctx->rasterizer, ctx->framebuffer_hdr, ctx->resource_manager);
ctx->app->get_event_dispatcher()->subscribe<mouse_moved_event>(ctx->surface_sky_pass);
ctx->surface_material_pass = new material_pass(ctx->rasterizer, ctx->framebuffer_hdr, ctx->resource_manager);
ctx->surface_material_pass->set_fallback_material(ctx->fallback_material);
ctx->surface_material_pass->shadow_map_pass = ctx->surface_shadow_map_pass;
ctx->surface_material_pass->shadow_map = ctx->shadow_map_depth_texture;
ctx->app->get_event_dispatcher()->subscribe<mouse_moved_event>(ctx->surface_material_pass);
ctx->surface_outline_pass = new outline_pass(ctx->rasterizer, ctx->framebuffer_hdr, ctx->resource_manager);
ctx->surface_outline_pass->set_outline_width(0.25f);
ctx->surface_outline_pass->set_outline_color(float4{1.0f, 1.0f, 1.0f, 1.0f});
ctx->surface_compositor = new compositor();
ctx->surface_compositor->add_pass(ctx->surface_shadow_map_clear_pass);
ctx->surface_compositor->add_pass(ctx->surface_shadow_map_pass);
ctx->surface_compositor->add_pass(ctx->surface_clear_pass);
ctx->surface_compositor->add_pass(ctx->surface_sky_pass);
ctx->surface_compositor->add_pass(ctx->surface_material_pass);
//ctx->surface_compositor->add_pass(ctx->surface_outline_pass);
ctx->surface_compositor->add_pass(ctx->common_bloom_pass);
ctx->surface_compositor->add_pass(ctx->common_final_pass);
}
// Create billboard VAO
{
@ -611,114 +627,100 @@ void setup_scenes(game::context* ctx)
// Get default framebuffer
const auto& viewport_dimensions = ctx->rasterizer->get_default_framebuffer().get_dimensions();
float viewport_aspect_ratio = static_cast<float>(viewport_dimensions[0]) / static_cast<float>(viewport_dimensions[1]);
const float viewport_aspect_ratio = static_cast<float>(viewport_dimensions[0]) / static_cast<float>(viewport_dimensions[1]);
// Create infinite culling mask
float inf = std::numeric_limits<float>::infinity();
const float inf = std::numeric_limits<float>::infinity();
ctx->no_cull = {{-inf, -inf, -inf}, {inf, inf, inf}};
// Setup overworld camera
ctx->overworld_camera = new scene::camera();
ctx->overworld_camera->set_perspective(math::radians<float>(45.0f), viewport_aspect_ratio, 0.1f, 1000.0f);
ctx->overworld_camera->set_compositor(ctx->overworld_compositor);
ctx->overworld_camera->set_composite_index(0);
ctx->overworld_camera->set_active(true);
// Setup underworld camera
ctx->underworld_camera = new scene::camera();
ctx->underworld_camera->set_perspective(math::radians<float>(45.0f), viewport_aspect_ratio, 0.1f, 1000.0f);
ctx->underworld_camera->look_at({0, 50, 0}, {0, 0, 0}, {0, 0, -1});
ctx->underworld_camera->set_compositor(ctx->underworld_compositor);
ctx->underworld_camera->set_composite_index(0);
ctx->underworld_camera->set_active(false);
// Setup UI camera
ctx->ui_camera = new scene::camera();
ctx->ui_camera->set_compositor(ctx->ui_compositor);
// Setup lights
ctx->moon_light = new scene::directional_light();
ctx->moon_light->set_intensity(0.0f);
ctx->moon_light->update_tweens();
ctx->subterrain_light = new scene::point_light();
ctx->subterrain_light->set_color({1, 1, 1});
ctx->subterrain_light->set_intensity(1.0f);
ctx->subterrain_light->set_attenuation({1.0f, 0.09f, 0.032f});
ctx->subterrain_light->update_tweens();
ctx->underworld_ambient_light = new scene::ambient_light();
ctx->underworld_ambient_light->set_color({1, 1, 1});
ctx->underworld_ambient_light->set_intensity(0.1f);
ctx->underworld_ambient_light->update_tweens();
ctx->lens_spot_light = new scene::spot_light();
ctx->lens_spot_light->set_color({1, 1, 1});
ctx->lens_spot_light->set_intensity(20.0f);
ctx->lens_spot_light->set_attenuation({1.0f, 0.0f, 0.0f});
ctx->lens_spot_light->set_cutoff({math::radians(1.25f), math::radians(1.8f)});
ctx->flashlight_spot_light = new scene::spot_light();
ctx->flashlight_spot_light->set_color({1, 1, 1});
ctx->flashlight_spot_light->set_intensity(1.0f);
ctx->flashlight_spot_light->set_attenuation({1.0f, 0.0f, 0.0f});
ctx->flashlight_spot_light->set_cutoff({math::radians(10.0f), math::radians(19.0f)});
// Setup underground camera
ctx->underground_camera = new scene::camera();
ctx->underground_camera->set_perspective(math::radians<float>(45.0f), viewport_aspect_ratio, 0.1f, 1000.0f);
ctx->underground_camera->set_compositor(ctx->underground_compositor);
ctx->underground_camera->set_composite_index(0);
ctx->underground_camera->set_active(false);
const gl::texture_2d* splash_texture = ctx->resource_manager->load<gl::texture_2d>("splash.tex");
auto splash_dimensions = splash_texture->get_dimensions();
ctx->splash_billboard_material = new material();
ctx->splash_billboard_material->set_shader_program(ctx->resource_manager->load<gl::shader_program>("ui-element-textured.glsl"));
ctx->splash_billboard_material->add_property<const gl::texture_2d*>("background")->set_value(splash_texture);
ctx->splash_billboard_material->add_property<float4>("tint")->set_value(float4{1, 1, 1, 1});
ctx->splash_billboard_material->update_tweens();
ctx->splash_billboard = new scene::billboard();
ctx->splash_billboard->set_material(ctx->splash_billboard_material);
ctx->splash_billboard->set_scale({(float)std::get<0>(splash_dimensions) * 0.5f, (float)std::get<1>(splash_dimensions) * 0.5f, 1.0f});
ctx->splash_billboard->set_translation({0.0f, 0.0f, 0.0f});
ctx->splash_billboard->update_tweens();
// Create depth debug billboard
/*
material* depth_debug_material = new material();
depth_debug_material->set_shader_program(ctx->resource_manager->load<gl::shader_program>("ui-element-textured.glsl"));
depth_debug_material->add_property<const gl::texture_2d*>("background")->set_value(shadow_map_depth_texture);
depth_debug_material->add_property<float4>("tint")->set_value(float4{1, 1, 1, 1});
billboard* depth_debug_billboard = new billboard();
depth_debug_billboard->set_material(depth_debug_material);
depth_debug_billboard->set_scale({128, 128, 1});
depth_debug_billboard->set_translation({-960 + 128, 1080 * 0.5f - 128, 0});
depth_debug_billboard->update_tweens();
ui_system->get_scene()->add_object(depth_debug_billboard);
*/
// Setup overworld scene
ctx->overworld_scene = new scene::collection();
ctx->overworld_scene->add_object(ctx->overworld_camera);
//ctx->overworld_scene->add_object(ctx->moon_light);
//ctx->overworld_scene->add_object(ctx->spot_light);
// Setup underworld scene
ctx->underworld_scene = new scene::collection();
ctx->underworld_scene->add_object(ctx->underworld_camera);
ctx->underworld_scene->add_object(ctx->underworld_ambient_light);
//ctx->underworld_scene->add_object(ctx->lantern);
//ctx->underworld_scene->add_object(ctx->subterrain_light);
//ctx->underworld_scene->add_object(ctx->portal_billboard);
//model_instance* larva = new scene::model_instance(ctx->resource_manager->load<model>("larva.mdl"));
//ctx->underworld_scene->add_object(larva);
// Setup surface camera
ctx->surface_camera = new scene::camera();
ctx->surface_camera->set_perspective(math::radians<float>(45.0f), viewport_aspect_ratio, 0.1f, 1000.0f);
ctx->surface_camera->set_compositor(ctx->surface_compositor);
ctx->surface_camera->set_composite_index(0);
ctx->surface_camera->set_active(false);
// Setup UI scene
ctx->ui_scene = new scene::collection();
ctx->ui_scene->add_object(ctx->ui_camera);
{
ctx->ui_scene = new scene::collection();
const gl::texture_2d* splash_texture = ctx->resource_manager->load<gl::texture_2d>("splash.tex");
auto splash_dimensions = splash_texture->get_dimensions();
ctx->splash_billboard_material = new material();
ctx->splash_billboard_material->set_shader_program(ctx->resource_manager->load<gl::shader_program>("ui-element-textured.glsl"));
ctx->splash_billboard_material->add_property<const gl::texture_2d*>("background")->set_value(splash_texture);
ctx->splash_billboard_material->add_property<float4>("tint")->set_value(float4{1, 1, 1, 1});
ctx->splash_billboard_material->update_tweens();
ctx->splash_billboard = new scene::billboard();
ctx->splash_billboard->set_material(ctx->splash_billboard_material);
ctx->splash_billboard->set_scale({(float)std::get<0>(splash_dimensions) * 0.5f, (float)std::get<1>(splash_dimensions) * 0.5f, 1.0f});
ctx->splash_billboard->set_translation({0.0f, 0.0f, 0.0f});
ctx->splash_billboard->update_tweens();
// Create depth debug billboard
/*
material* depth_debug_material = new material();
depth_debug_material->set_shader_program(ctx->resource_manager->load<gl::shader_program>("ui-element-textured.glsl"));
depth_debug_material->add_property<const gl::texture_2d*>("background")->set_value(shadow_map_depth_texture);
depth_debug_material->add_property<float4>("tint")->set_value(float4{1, 1, 1, 1});
billboard* depth_debug_billboard = new billboard();
depth_debug_billboard->set_material(depth_debug_material);
depth_debug_billboard->set_scale({128, 128, 1});
depth_debug_billboard->set_translation({-960 + 128, 1080 * 0.5f - 128, 0});
depth_debug_billboard->update_tweens();
ui_system->get_scene()->add_object(depth_debug_billboard);
*/
ctx->ui_scene->add_object(ctx->ui_camera);
}
//ctx->overworld_scene->add_object(ctx->lens_spot_light);
ctx->underworld_scene->add_object(ctx->flashlight_spot_light);
// Setup underground scene
{
ctx->underground_scene = new scene::collection();
ctx->underground_ambient_light = new scene::ambient_light();
ctx->underground_ambient_light->set_color({1, 1, 1});
ctx->underground_ambient_light->set_intensity(0.1f);
ctx->underground_ambient_light->update_tweens();
ctx->flashlight_spot_light = new scene::spot_light();
ctx->flashlight_spot_light->set_color({1, 1, 1});
ctx->flashlight_spot_light->set_intensity(1.0f);
ctx->flashlight_spot_light->set_attenuation({1.0f, 0.0f, 0.0f});
ctx->flashlight_spot_light->set_cutoff({math::radians(10.0f), math::radians(19.0f)});
ctx->underground_scene->add_object(ctx->underground_camera);
ctx->underground_scene->add_object(ctx->underground_ambient_light);
//ctx->underground_scene->add_object(ctx->flashlight_spot_light);
}
// Setup surface scene
{
ctx->surface_scene = new scene::collection();
ctx->lens_spot_light = new scene::spot_light();
ctx->lens_spot_light->set_color({1, 1, 1});
ctx->lens_spot_light->set_intensity(20.0f);
ctx->lens_spot_light->set_attenuation({1.0f, 0.0f, 0.0f});
ctx->lens_spot_light->set_cutoff({math::radians(1.25f), math::radians(1.8f)});
ctx->surface_scene->add_object(ctx->surface_camera);
//ctx->surface_scene->add_object(ctx->lens_spot_light);
}
// Set overworld as active scene
ctx->active_scene = ctx->overworld_scene;
// Clear active scene
ctx->active_scene = nullptr;
logger->pop_task(EXIT_SUCCESS);
}
@ -761,14 +763,12 @@ void setup_animation(game::context* ctx)
ctx->focal_point_tween->set_interpolator(math::lerp<float3, float>);
// Set material pass tweens
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_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_focal_point_tween(ctx->focal_point_tween);
ctx->underworld_final_pass->set_time_tween(ctx->time_tween);
ctx->underworld_material_pass->set_focal_point_tween(ctx->focal_point_tween);
ctx->common_final_pass->set_time_tween(ctx->time_tween);
ctx->surface_sky_pass->set_time_tween(ctx->time_tween);
ctx->surface_material_pass->set_time_tween(ctx->time_tween);
ctx->surface_material_pass->set_focal_point_tween(ctx->focal_point_tween);
ctx->underground_material_pass->set_time_tween(ctx->time_tween);
ctx->underground_material_pass->set_focal_point_tween(ctx->focal_point_tween);
ctx->ui_material_pass->set_time_tween(ctx->time_tween);
}
@ -801,7 +801,7 @@ void setup_systems(game::context* ctx)
// Setup terrain system
ctx->terrain_system = new entity::system::terrain(*ctx->entity_registry);
ctx->terrain_system->set_patch_subdivisions(30);
ctx->terrain_system->set_patch_scene_collection(ctx->overworld_scene);
ctx->terrain_system->set_patch_scene_collection(ctx->surface_scene);
ctx->terrain_system->set_max_error(200.0);
// Setup vegetation system
@ -810,7 +810,7 @@ void setup_systems(game::context* ctx)
//ctx->vegetation_system->set_vegetation_patch_resolution(VEGETATION_PATCH_RESOLUTION);
//ctx->vegetation_system->set_vegetation_density(1.0f);
//ctx->vegetation_system->set_vegetation_model(ctx->resource_manager->load<model>("grass-tuft.mdl"));
//ctx->vegetation_system->set_scene(ctx->overworld_scene);
//ctx->vegetation_system->set_scene(ctx->surface_scene);
// Setup camera system
ctx->camera_system = new entity::system::camera(*ctx->entity_registry);
@ -820,13 +820,13 @@ void setup_systems(game::context* ctx)
// Setup tool system
ctx->tool_system = new entity::system::tool(*ctx->entity_registry, event_dispatcher);
ctx->tool_system->set_camera(ctx->overworld_camera);
ctx->tool_system->set_camera(ctx->surface_camera);
ctx->tool_system->set_orbit_cam(ctx->camera_system->get_orbit_cam());
ctx->tool_system->set_viewport(viewport);
// Setup subterrain system
ctx->subterrain_system = new entity::system::subterrain(*ctx->entity_registry, ctx->resource_manager);
ctx->subterrain_system->set_scene(ctx->underworld_scene);
ctx->subterrain_system->set_scene(ctx->underground_scene);
// Setup nest system
ctx->nest_system = new entity::system::nest(*ctx->entity_registry, ctx->resource_manager);
@ -864,11 +864,11 @@ void setup_systems(game::context* ctx)
// Setup tracking system
ctx->tracking_system = new entity::system::tracking(*ctx->entity_registry, event_dispatcher, ctx->resource_manager);
ctx->tracking_system->set_scene(ctx->overworld_scene);
ctx->tracking_system->set_scene(ctx->surface_scene);
// Setup painting system
ctx->painting_system = new entity::system::painting(*ctx->entity_registry, event_dispatcher, ctx->resource_manager);
ctx->painting_system->set_scene(ctx->overworld_scene);
ctx->painting_system->set_scene(ctx->surface_scene);
// Setup solar system
ctx->orbit_system = new entity::system::orbit(*ctx->entity_registry);
@ -883,7 +883,7 @@ void setup_systems(game::context* ctx)
// Setup astronomy system
ctx->astronomy_system = new entity::system::astronomy(*ctx->entity_registry);
ctx->astronomy_system->set_sky_pass(ctx->overworld_sky_pass);
ctx->astronomy_system->set_sky_pass(ctx->surface_sky_pass);
// Setup proteome system
ctx->proteome_system = new entity::system::proteome(*ctx->entity_registry);
@ -900,15 +900,15 @@ void setup_systems(game::context* ctx)
// Setup render system
ctx->render_system = new entity::system::render(*ctx->entity_registry);
ctx->render_system->add_layer(ctx->overworld_scene);
ctx->render_system->add_layer(ctx->underworld_scene);
ctx->render_system->add_layer(ctx->underground_scene);
ctx->render_system->add_layer(ctx->surface_scene);
ctx->render_system->add_layer(ctx->ui_scene);
ctx->render_system->set_renderer(ctx->renderer);
// Setup control system
ctx->control_system = new entity::system::control(*ctx->entity_registry);
ctx->control_system->set_viewport(viewport);
ctx->control_system->set_underworld_camera(ctx->underworld_camera);
ctx->control_system->set_underground_camera(ctx->underground_camera);
ctx->control_system->set_tool(nullptr);
//ctx->control_system->set_flashlight(flashlight, flashlight_light_cone);
ctx->control_system->get_adjust_camera_control()->set_activated_callback([ctx](){ ctx->app->set_relative_mouse_mode(true); ctx->tool_system->set_pick(false); });
@ -1020,15 +1020,15 @@ void setup_controls(game::context* ctx)
ctx->control_system->get_toggle_view_control()->set_activated_callback(
[ctx]()
{
if (ctx->active_scene == ctx->overworld_scene)
if (ctx->active_scene == ctx->surface_scene)
{
ctx->active_scene = ctx->underworld_scene;
ctx->active_scene = ctx->underground_scene;
ctx->radial_transition_inner->transition(0.5f, false, ease<float, double>::in_quad);
auto switch_cameras = [ctx]()
{
ctx->overworld_camera->set_active(false);
ctx->underworld_camera->set_active(true);
ctx->surface_camera->set_active(false);
ctx->underground_camera->set_active(true);
ctx->fade_transition->transition(0.25f, true, ease<float, double>::out_quad);
};
@ -1037,13 +1037,13 @@ void setup_controls(game::context* ctx)
}
else
{
ctx->active_scene = ctx->overworld_scene;
ctx->active_scene = ctx->surface_scene;
ctx->fade_transition->transition(0.25f, false, ease<float, double>::out_quad);
auto switch_cameras = [ctx]()
{
ctx->overworld_camera->set_active(true);
ctx->underworld_camera->set_active(false);
ctx->surface_camera->set_active(true);
ctx->underground_camera->set_active(false);
ctx->radial_transition_inner->transition(0.5f, true, ease<float, double>::out_quad);
};
@ -1254,12 +1254,11 @@ void setup_callbacks(game::context* ctx)
{
// Update tweens
ctx->time_tween->update();
ctx->overworld_sky_pass->update_tweens();
ctx->overworld_scene->update_tweens();
ctx->underworld_scene->update_tweens();
ctx->surface_sky_pass->update_tweens();
ctx->surface_scene->update_tweens();
ctx->underground_scene->update_tweens();
ctx->ui_scene->update_tweens();
ctx->focal_point_tween->update();
ctx->underworld_final_pass->get_material()->update_tweens();
// Set time tween time
(*ctx->time_tween)[1] = t;

+ 28
- 23
src/game/context.hpp View File

@ -164,39 +164,44 @@ struct context
gl::texture_2d** marker_albedo_textures;
// Compositing
bloom_pass* overworld_bloom_pass;
clear_pass* overworld_clear_pass;
clear_pass* overworld_shadow_map_clear_pass;
clear_pass* ui_clear_pass;
clear_pass* underworld_clear_pass;
final_pass* overworld_final_pass;
material_pass* overworld_material_pass;
material_pass* ui_material_pass;
material_pass* underworld_material_pass;
outline_pass* overworld_outline_pass;
shadow_map_pass* overworld_shadow_map_pass;
simple_render_pass* underworld_final_pass;
sky_pass* overworld_sky_pass;
material_property<const gl::texture_2d*>* underground_color_texture_property;
compositor* overworld_compositor;
compositor* underworld_compositor;
compositor* ui_compositor;
// Scene
bloom_pass* common_bloom_pass;
final_pass* common_final_pass;
clear_pass* underground_clear_pass;
material_pass* underground_material_pass;
compositor* underground_compositor;
clear_pass* surface_shadow_map_clear_pass;
shadow_map_pass* surface_shadow_map_pass;
clear_pass* surface_clear_pass;
sky_pass* surface_sky_pass;
material_pass* surface_material_pass;
outline_pass* surface_outline_pass;
compositor* surface_compositor;
// Scene utilities
scene::collection* active_scene;
scene::collection* overworld_scene;
scene::collection* underworld_scene;
geom::aabb<float> no_cull;
// UI scene
scene::collection* ui_scene;
scene::camera* overworld_camera;
scene::camera* underworld_camera;
scene::camera* ui_camera;
scene::directional_light* moon_light;
scene::point_light* subterrain_light;
scene::ambient_light* underworld_ambient_light;
scene::billboard* splash_billboard;
// Surface scene
scene::collection* surface_scene;
scene::camera* surface_camera;
scene::spot_light* lens_spot_light;
// Underground scene
scene::collection* underground_scene;
scene::camera* underground_camera;
scene::ambient_light* underground_ambient_light;
scene::spot_light* flashlight_spot_light;
geom::aabb<float> no_cull;
// Animation
timeline* timeline;

+ 97
- 0
src/game/states/brood.cpp View File

@ -0,0 +1,97 @@
/*
* Copyright (C) 2021 Christopher J. Howard
*
* This file is part of Antkeeper source code.
*
* Antkeeper source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "game/states/brood.hpp"
#include "entity/archetype.hpp"
#include "entity/commands.hpp"
#include "entity/components/observer.hpp"
#include "entity/components/camera-follow.hpp"
#include "entity/components/terrain.hpp"
#include "entity/components/transform.hpp"
#include "entity/systems/control.hpp"
#include "entity/systems/camera.hpp"
#include "entity/systems/tool.hpp"
#include "animation/screen-transition.hpp"
#include "animation/ease.hpp"
#include "resources/resource-manager.hpp"
#include "renderer/passes/sky-pass.hpp"
namespace game {
namespace state {
namespace brood {
void enter(game::context* ctx)
{
// Switch to underground camera
ctx->surface_camera->set_active(false);
ctx->underground_camera->set_active(true);
ctx->underground_ambient_light->set_intensity(1.0f);
// Create camera focal point
{
entity::component::transform focal_point_transform;
focal_point_transform.local = math::identity_transform<float>;
focal_point_transform.warp = true;
ctx->entity_registry->assign_or_replace<entity::component::transform>(ctx->focal_point_entity, focal_point_transform);
entity::component::camera_follow focal_point_follow;
ctx->entity_registry->assign_or_replace<entity::component::camera_follow>(ctx->focal_point_entity, focal_point_follow);
}
// Setup camera
ctx->underground_camera->look_at({0, 0, 1}, {0, 0, 0}, {0, 1, 0});
ctx->underground_camera->set_exposure(0.0f);
ctx->camera_system->set_camera(ctx->underground_camera);
ctx->tool_system->set_camera(ctx->underground_camera);
ctx->tool_system->set_orbit_cam(ctx->camera_system->get_orbit_cam());
entity::system::control* control_system = ctx->control_system;
control_system->update(0.0, 0.0);
control_system->set_nest(nullptr);
// Create larva
{
entity::archetype* larva_archetype = ctx->resource_manager->load<entity::archetype>("ant-larva.ent");
auto larva_eid = larva_archetype->create(*ctx->entity_registry);
entity::command::warp_to(*ctx->entity_registry, larva_eid, {0.0f, 0.0f, 0.0f});
entity::command::assign_render_layers(*ctx->entity_registry, larva_eid, 0b1);
}
// Create cocoon
{
entity::archetype* cocoon_archetype = ctx->resource_manager->load<entity::archetype>("ant-cocoon.ent");
auto cocoon_eid = cocoon_archetype->create(*ctx->entity_registry);
entity::command::warp_to(*ctx->entity_registry, cocoon_eid, {-50, 0.1935f, 0});
entity::command::assign_render_layers(*ctx->entity_registry, cocoon_eid, 0b1);
}
ctx->underground_scene->update_tweens();
// Start fade in
ctx->fade_transition->transition(1.0f, true, ease<float>::in_quad);
}
void exit(game::context* ctx)
{}
} // namespace brood
} // namespace state
} // namespace game

src/game/states/play.hpp → src/game/states/brood.hpp View File

@ -17,23 +17,23 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_GAME_STATE_PLAY_HPP
#define ANTKEEPER_GAME_STATE_PLAY_HPP
#ifndef ANTKEEPER_GAME_STATE_BROOD_HPP
#define ANTKEEPER_GAME_STATE_BROOD_HPP
#include "game/context.hpp"
namespace game {
namespace state {
/// Play game state functions.
namespace play {
/// Brood game state functions.
namespace brood {
void enter(game::context* ctx);
void exit(game::context* ctx);
} // namespace play
} // namespace brood
} // namespace state
} // namespace game
#endif // ANTKEEPER_GAME_STATE_PLAY_HPP
#endif // ANTKEEPER_GAME_STATE_BROOD_HPP

src/game/states/play.cpp → src/game/states/forage.cpp View File

@ -17,11 +17,12 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "game/states/play.hpp"
#include "game/states/forage.hpp"
#include "entity/archetype.hpp"
#include "entity/commands.hpp"
#include "entity/components/observer.hpp"
#include "entity/components/camera-follow.hpp"
#include "entity/components/terrain.hpp"
#include "entity/components/transform.hpp"
#include "entity/systems/astronomy.hpp"
#include "entity/systems/control.hpp"
@ -32,10 +33,14 @@
namespace game {
namespace state {
namespace play {
namespace forage {
void enter(game::context* ctx)
{
// Switch to surface camera
ctx->underground_camera->set_active(false);
ctx->surface_camera->set_active(true);
// Find planet EID by name
entity::id planet_eid = entt::null;
if (auto it = ctx->named_entities.find("planet"); it != ctx->named_entities.end())
@ -43,6 +48,18 @@ void enter(game::context* ctx)
planet_eid = it->second;
}
// Create biome terrain component
entity::component::terrain biome_terrain;
biome_terrain.max_lod = 18;
biome_terrain.patch_material = ctx->resource_manager->load<material>("desert-terrain.mtl");
biome_terrain.elevation = [](double, double) -> double
{
return 0.0;
};
// Replace planet terrain component with biome terrain component
ctx->entity_registry->replace<entity::component::terrain>(planet_eid, biome_terrain);
// Create observer
auto observer_eid = ctx->entity_registry->create();
{
@ -51,7 +68,7 @@ void enter(game::context* ctx)
observer.elevation = 0.0;
observer.latitude = 0.0;
observer.longitude = 0.0;
observer.camera = ctx->overworld_camera;
observer.camera = ctx->surface_camera;
ctx->entity_registry->assign<entity::component::observer>(observer_eid, observer);
// Set reference location of astronomy system
@ -71,9 +88,9 @@ void enter(game::context* ctx)
}
// Setup camera
ctx->overworld_camera->look_at({0, 0, 1}, {0, 0, 0}, {0, 1, 0});
ctx->overworld_camera->set_exposure(-14.5f);
ctx->camera_system->set_camera(ctx->overworld_camera);
ctx->surface_camera->look_at({0, 0, 1}, {0, 0, 0}, {0, 1, 0});
ctx->surface_camera->set_exposure(-14.5f);
ctx->camera_system->set_camera(ctx->surface_camera);
entity::system::control* control_system = ctx->control_system;
control_system->update(0.0, 0.0);
@ -86,7 +103,14 @@ void enter(game::context* ctx)
entity::command::warp_to(*ctx->entity_registry, larva_eid, {50, 0.1935f, 0});
}
ctx->overworld_scene->update_tweens();
// Create cocoon
{
entity::archetype* cocoon_archetype = ctx->resource_manager->load<entity::archetype>("ant-cocoon.ent");
auto cocoon_eid = cocoon_archetype->create(*ctx->entity_registry);
entity::command::warp_to(*ctx->entity_registry, cocoon_eid, {-50, 0.1935f, 0});
}
ctx->surface_scene->update_tweens();
// Start fade in
ctx->fade_transition->transition(1.0f, true, ease<float>::in_quad);
@ -95,6 +119,6 @@ void enter(game::context* ctx)
void exit(game::context* ctx)
{}
} // namespace play
} // namespace forage
} // namespace state
} // namespace game

+ 39
- 0
src/game/states/forage.hpp View File

@ -0,0 +1,39 @@
/*
* Copyright (C) 2021 Christopher J. Howard
*
* This file is part of Antkeeper source code.
*
* Antkeeper source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_GAME_STATE_FORAGE_HPP
#define ANTKEEPER_GAME_STATE_FORAGE_HPP
#include "game/context.hpp"
namespace game {
namespace state {
/// Forage game state functions.
namespace forage {
void enter(game::context* ctx);
void exit(game::context* ctx);
} // namespace forage
} // namespace state
} // namespace game
#endif // ANTKEEPER_GAME_STATE_FORAGE_HPP

+ 41
- 10
src/game/states/loading.cpp View File

@ -30,7 +30,6 @@
#include "entity/systems/astronomy.hpp"
#include "entity/systems/orbit.hpp"
#include "game/states/nuptial-flight.hpp"
#include "game/states/play.hpp"
#include "game/states/splash.hpp"
#include "geom/spherical.hpp"
#include "gl/drawing-mode.hpp"
@ -66,6 +65,9 @@ static void selenogenesis(game::context* ctx);
/// Creates fixed stars.
static void extrasolar_heliogenesis(game::context* ctx);
/// Creates an ant colony
static void colonigenesis(game::context* ctx);
void enter(game::context* ctx)
{
// Create universe
@ -161,6 +163,19 @@ void cosmogenesis(game::context* ctx)
throw;
}
ctx->logger->pop_task(EXIT_SUCCESS);
// Create ant colony
ctx->logger->push_task("Creating ant colony");
try
{
colonigenesis(ctx);
}
catch (...)
{
ctx->logger->pop_task(EXIT_FAILURE);
throw;
}
ctx->logger->pop_task(EXIT_SUCCESS);
}
void heliogenesis(game::context* ctx)
@ -209,12 +224,12 @@ void heliogenesis(game::context* ctx)
sun_ambient->set_intensity(0.0f);
sun_ambient->update_tweens();
// Add sun light scene objects to overworld scene
ctx->overworld_scene->add_object(sun_direct);
ctx->overworld_scene->add_object(sun_ambient);
// Add sun light scene objects to surface scene
ctx->surface_scene->add_object(sun_direct);
ctx->surface_scene->add_object(sun_ambient);
// Pass direct sun light scene object to shadow map pass and astronomy system
ctx->overworld_shadow_map_pass->set_light(sun_direct);
ctx->surface_shadow_map_pass->set_light(sun_direct);
ctx->astronomy_system->set_sun_light(sun_direct);
}
@ -252,8 +267,8 @@ void planetogenesis(game::context* ctx)
//return math::random<double>(0.0, 1.0);
return 0.0;
};
terrain.max_lod = 18;
terrain.patch_material = ctx->resource_manager->load<material>("desert-terrain.mtl");
terrain.max_lod = 0;
terrain.patch_material = nullptr;
ctx->entity_registry->assign<entity::component::terrain>(planet_eid, terrain);
// Assign planetary atmosphere component
@ -277,7 +292,7 @@ void planetogenesis(game::context* ctx)
ctx->astronomy_system->set_reference_body(planet_eid);
// Load sky model
ctx->overworld_sky_pass->set_sky_model(ctx->resource_manager->load<model>("sky-dome.mdl"));
ctx->surface_sky_pass->set_sky_model(ctx->resource_manager->load<model>("sky-dome.mdl"));
}
void selenogenesis(game::context* ctx)
@ -289,7 +304,7 @@ void selenogenesis(game::context* ctx)
ctx->named_entities["moon"] = moon_eid;
// Pass moon model to sky pass
ctx->overworld_sky_pass->set_moon_model(ctx->resource_manager->load<model>("moon.mdl"));
ctx->surface_sky_pass->set_moon_model(ctx->resource_manager->load<model>("moon.mdl"));
}
void extrasolar_heliogenesis(game::context* ctx)
@ -398,7 +413,23 @@ void extrasolar_heliogenesis(game::context* ctx)
stars_model_group->set_index_count(star_count);
// Pass stars model to sky pass
ctx->overworld_sky_pass->set_stars_model(stars_model);
ctx->surface_sky_pass->set_stars_model(stars_model);
}
void colonigenesis(game::context* ctx)
{
// Create queen entity
auto queen_eid = ctx->entity_registry->create();
ctx->named_entities["queen"] = queen_eid;
// Create central shaft entity
auto shaft_eid = ctx->entity_registry->create();
ctx->named_entities["shaft"] = queen_eid;
// Create entrance "lobby" chamber entity
auto lobby_eid = ctx->entity_registry->create();
ctx->named_entities["lobby"] = lobby_eid;
}
} // namespace loading

+ 31
- 9
src/game/states/nuptial-flight.cpp View File

@ -18,6 +18,7 @@
*/
#include "game/states/nuptial-flight.hpp"
#include "entity/archetype.hpp"
#include "entity/systems/astronomy.hpp"
#include "entity/systems/orbit.hpp"
#include "entity/systems/control.hpp"
@ -38,6 +39,10 @@ namespace nuptial_flight {
void enter(game::context* ctx)
{
// Switch to surface camera
ctx->underground_camera->set_active(false);
ctx->surface_camera->set_active(true);
// Find planet EID by name
entity::id planet_eid = entt::null;
if (auto it = ctx->named_entities.find("planet"); it != ctx->named_entities.end())
@ -45,10 +50,12 @@ void enter(game::context* ctx)
planet_eid = it->second;
}
// Replace planet terrain material with cloud material
entity::component::terrain planet_terrain = ctx->entity_registry->get<entity::component::terrain>(planet_eid);
planet_terrain.patch_material = ctx->resource_manager->load<material>("cloud.mtl");
ctx->entity_registry->replace<entity::component::terrain>(planet_eid, planet_terrain);
// Remove terrain component from planet (if any)
if (ctx->entity_registry->has<entity::component::terrain>(planet_eid))
ctx->entity_registry->remove<entity::component::terrain>(planet_eid);
// Enable clouds in sky pass
ctx->surface_sky_pass->set_clouds_model(ctx->resource_manager->load<model>("cloud-plane.mdl"));
// Create observer
auto observer_eid = ctx->entity_registry->create();
@ -58,7 +65,7 @@ void enter(game::context* ctx)
observer.elevation = 2000.0;
observer.latitude = 0.0;
observer.longitude = 0.0;
observer.camera = ctx->overworld_camera;
observer.camera = ctx->surface_camera;
ctx->entity_registry->assign<entity::component::observer>(observer_eid, observer);
// Set reference location of astronomy system
@ -66,6 +73,21 @@ void enter(game::context* ctx)
ctx->astronomy_system->set_observer_location(double3{observer.elevation, observer.latitude, observer.longitude});
}
// Create wing
entity::archetype* ant_forewing_archetype = ctx->resource_manager->load<entity::archetype>("ant-forewing.ent");
auto forewing_eid = ctx->entity_registry->create();
//ant_forewing_archetype->assign(*ctx->entity_registry, forewing_eid);
// Create eye
entity::archetype* ant_round_eye_archetype = ctx->resource_manager->load<entity::archetype>("ant-round-eye.ent");
auto ant_round_eye_eid = ctx->entity_registry->create();
ant_round_eye_archetype->assign(*ctx->entity_registry, ant_round_eye_eid);
// Create green orb ring
entity::archetype* orb_ring_archetype = ctx->resource_manager->load<entity::archetype>("orb-ring.ent");
auto orb_ring_eid = ctx->entity_registry->create();
//orb_ring_archetype->assign(*ctx->entity_registry, orb_ring_eid);
// Create camera focal point
{
entity::component::transform focal_point_transform;
@ -78,14 +100,14 @@ void enter(game::context* ctx)
}
// Setup camera
ctx->overworld_camera->look_at({0, 0, 1}, {0, 0, 0}, {0, 1, 0});
ctx->overworld_camera->set_exposure(-14.5f);
ctx->camera_system->set_camera(ctx->overworld_camera);
ctx->surface_camera->look_at({0, 0, 1}, {0, 0, 0}, {0, 1, 0});
ctx->surface_camera->set_exposure(-14.5f);
ctx->camera_system->set_camera(ctx->surface_camera);
entity::system::control* control_system = ctx->control_system;
control_system->update(0.0, 0.0);
ctx->overworld_scene->update_tweens();
ctx->surface_scene->update_tweens();
// Pause motion of celestial objects
ctx->astronomy_system->set_time_scale(0.0);

+ 7
- 7
src/game/states/splash.cpp View File

@ -18,7 +18,7 @@
*/
#include "game/states/splash.hpp"
#include "game/states/play.hpp"
#include "game/states/brood.hpp"
#include "animation/screen-transition.hpp"
#include "animation/ease.hpp"
#include "animation/timeline.hpp"
@ -51,9 +51,9 @@ void enter(game::context* ctx)
auto change_state = [ctx]()
{
application::state next_state;
next_state.name = "play";
next_state.enter = std::bind(game::state::play::enter, ctx);
next_state.exit = std::bind(game::state::play::exit, ctx);
next_state.name = "brood";
next_state.enter = std::bind(game::state::brood::enter, ctx);
next_state.exit = std::bind(game::state::brood::exit, ctx);
ctx->app->change_state(next_state);
};
@ -83,9 +83,9 @@ void enter(game::context* ctx)
ctx->app->swap_buffers();
application::state next_state;
next_state.name = "play";
next_state.enter = std::bind(game::state::play::enter, ctx);
next_state.exit = std::bind(game::state::play::exit, ctx);
next_state.name = "brood";
next_state.enter = std::bind(game::state::brood::enter, ctx);
next_state.exit = std::bind(game::state::brood::exit, ctx);
ctx->app->change_state(next_state);
}

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

@ -64,10 +64,15 @@ sky_pass::sky_pass(gl::rasterizer* rasterizer, const gl::framebuffer* framebuffe
stars_model_vao(nullptr),
star_material(nullptr),
star_shader_program(nullptr),
clouds_model(nullptr),
clouds_model_vao(nullptr),
cloud_material(nullptr),
cloud_shader_program(nullptr),
time_tween(nullptr),
observer_altitude_tween(0.0f, math::lerp<float, float>),
sun_position_tween(float3{1.0f, 0.0f, 0.0f}, math::lerp<float3, float>),
sun_color_tween(float3{1.0f, 1.0f, 1.0f}, math::lerp<float3, float>),
sun_color_outer_tween(float3{1.0f, 1.0f, 1.0f}, math::lerp<float3, float>),
sun_color_inner_tween(float3{1.0f, 1.0f, 1.0f}, math::lerp<float3, float>),
topocentric_frame_translation({0, 0, 0}, math::lerp<float3, float>),
topocentric_frame_rotation(math::quaternion<float>::identity(), math::nlerp<float>)
{}
@ -88,7 +93,7 @@ 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));
float time = (*time_tween)[context->alpha];
float time = static_cast<float>((*time_tween)[context->alpha]);
float2 resolution = {static_cast<float>(std::get<0>(viewport)), static_cast<float>(std::get<1>(viewport))};
const scene::camera& camera = *context->camera;
@ -118,9 +123,11 @@ void sky_pass::render(render_context* context) const
float3 sun_direction = math::normalize(sun_position);
// Interpolate sun color
float3 sun_color = sun_color_tween.interpolate(context->alpha);
float3 sun_color_outer = sun_color_outer_tween.interpolate(context->alpha);
float3 sun_color_inner = sun_color_inner_tween.interpolate(context->alpha);
// Draw sky model
// Draw atmosphere
if (sky_model)
{
rasterizer->use_program(*sky_shader_program);
@ -143,7 +150,7 @@ void sky_pass::render(render_context* context) const
if (sun_angular_radius_input)
sun_angular_radius_input->upload(sun_angular_radius);
if (sun_color_input)
sun_color_input->upload(sun_color);
sun_color_input->upload(sun_color_outer);
if (scale_height_rm_input)
scale_height_rm_input->upload(scale_height_rm);
if (rayleigh_scattering_input)
@ -160,6 +167,27 @@ void sky_pass::render(render_context* context) const
rasterizer->draw_arrays(*sky_model_vao, sky_model_drawing_mode, sky_model_start_index, sky_model_index_count);
}
// Draw clouds
if (clouds_model)
{
rasterizer->use_program(*cloud_shader_program);
if (cloud_model_view_projection_input)
cloud_model_view_projection_input->upload(model_view_projection);
if (cloud_sun_direction_input)
cloud_sun_direction_input->upload(sun_direction);
if (cloud_sun_color_input)
cloud_sun_color_input->upload(sun_color_inner);
if (cloud_camera_position_input)
cloud_camera_position_input->upload(context->camera_transform.translation);
if (cloud_camera_exposure_input)
cloud_camera_exposure_input->upload(exposure);
cloud_material->upload(context->alpha);
rasterizer->draw_arrays(*clouds_model_vao, clouds_model_drawing_mode, clouds_model_start_index, clouds_model_index_count);
}
glEnable(GL_BLEND);
//glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glBlendFunc(GL_ONE, GL_ONE);
@ -345,11 +373,49 @@ void sky_pass::set_stars_model(const model* model)
}
}
void sky_pass::set_clouds_model(const model* model)
{
clouds_model = model;
if (clouds_model)
{
clouds_model_vao = model->get_vertex_array();
const std::vector<model_group*>& groups = *model->get_groups();
for (model_group* group: groups)
{
cloud_material = group->get_material();
clouds_model_drawing_mode = group->get_drawing_mode();
clouds_model_start_index = group->get_start_index();
clouds_model_index_count = group->get_index_count();
}
if (cloud_material)
{
cloud_shader_program = cloud_material->get_shader_program();
if (cloud_shader_program)
{
cloud_model_view_projection_input = cloud_shader_program->get_input("model_view_projection");
cloud_sun_direction_input = cloud_shader_program->get_input("sun_direction");
cloud_sun_color_input = cloud_shader_program->get_input("sun_color");
cloud_camera_position_input = cloud_shader_program->get_input("camera.position");
cloud_camera_exposure_input = cloud_shader_program->get_input("camera.exposure");
}
}
}
else
{
clouds_model = nullptr;
}
}
void sky_pass::update_tweens()
{
observer_altitude_tween.update();
sun_position_tween.update();
sun_color_tween.update();
sun_color_outer_tween.update();
sun_color_inner_tween.update();
topocentric_frame_translation.update();
topocentric_frame_rotation.update();
}
@ -370,9 +436,10 @@ void sky_pass::set_sun_position(const float3& position)
sun_position_tween[1] = position;
}
void sky_pass::set_sun_color(const float3& color)
void sky_pass::set_sun_color(const float3& color_outer, const float3& color_inner)
{
sun_color_tween[1] = color;
sun_color_outer_tween[1] = color_outer;
sun_color_inner_tween[1] = color_inner;
}
void sky_pass::set_sun_angular_radius(float radius)

+ 18
- 2
src/renderer/passes/sky-pass.hpp View File

@ -56,11 +56,12 @@ public:
void set_time_tween(const tween<double>* time);
void set_moon_model(const model* model);
void set_stars_model(const model* model);
void set_clouds_model(const model* model);
void set_topocentric_frame(const physics::frame<float>& frame);
void set_sun_position(const float3& position);
void set_sun_color(const float3& color);
void set_sun_color(const float3& color_outer, const float3& color_inner);
void set_sun_angular_radius(float radius);
void set_observer_altitude(float altitude);
void set_scale_heights(float rayleigh, float mie);
@ -118,6 +119,20 @@ private:
const gl::shader_input* star_projection_input;
const gl::shader_input* star_exposure_input;
const gl::shader_input* star_distance_input;
const model* clouds_model;
const material* cloud_material;
const gl::vertex_array* clouds_model_vao;
gl::drawing_mode clouds_model_drawing_mode;
std::size_t clouds_model_start_index;
std::size_t clouds_model_index_count;
gl::shader_program* cloud_shader_program;
const gl::shader_input* cloud_model_view_projection_input;
const gl::shader_input* cloud_sun_direction_input;
const gl::shader_input* cloud_sun_color_input;
const gl::shader_input* cloud_camera_position_input;
const gl::shader_input* cloud_camera_exposure_input;
const gl::texture_2d* blue_noise_map;
const gl::texture_2d* sky_gradient;
@ -127,7 +142,8 @@ private:
const tween<double>* time_tween;
tween<float> observer_altitude_tween;
tween<float3> sun_position_tween;
tween<float3> sun_color_tween;
tween<float3> sun_color_outer_tween;
tween<float3> sun_color_inner_tween;
tween<float3> topocentric_frame_translation;
tween<math::quaternion<float>> topocentric_frame_rotation;

Loading…
Cancel
Save