diff --git a/CMakeLists.txt b/CMakeLists.txt index c7a360c..d4aa351 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,6 @@ option(VERSION_STRING "Project version string" "0.0.0") project(antkeeper VERSION ${VERSION_STRING} LANGUAGES CXX) - # Find dependency packages find_package(dr_wav REQUIRED CONFIG) find_package(stb REQUIRED CONFIG) diff --git a/src/ecs/systems/render-system.cpp b/src/ecs/systems/render-system.cpp index a26906d..61a46d7 100644 --- a/src/ecs/systems/render-system.cpp +++ b/src/ecs/systems/render-system.cpp @@ -23,7 +23,7 @@ #include "scene/point-light.hpp" #include "scene/directional-light.hpp" #include "scene/ambient-light.hpp" -#include "scene/spotlight.hpp" +#include "scene/spot-light.hpp" #include namespace ecs { @@ -163,7 +163,7 @@ void render_system::update_light(ecs::entity entity, ecs::light_component& compo case scene::light_type::spot: { - scene::spotlight* spot = static_cast(light); + scene::spot_light* spot = static_cast(light); spot->set_attenuation(component.attenuation); spot->set_cutoff(component.cutoff); break; @@ -221,7 +221,7 @@ void render_system::on_light_construct(ecs::registry& registry, ecs::entity enti break; case scene::light_type::spot: - light = new scene::spotlight(); + light = new scene::spot_light(); break; default: diff --git a/src/game/bootloader.cpp b/src/game/bootloader.cpp index 43dc670..9aeca53 100644 --- a/src/game/bootloader.cpp +++ b/src/game/bootloader.cpp @@ -644,17 +644,17 @@ void setup_scenes(game_context* ctx) ctx->underworld_ambient_light->set_intensity(0.1f); ctx->underworld_ambient_light->update_tweens(); - ctx->lens_spotlight = new scene::spotlight(); - ctx->lens_spotlight->set_color({1, 1, 1}); - ctx->lens_spotlight->set_intensity(20.0f); - ctx->lens_spotlight->set_attenuation({1.0f, 0.0f, 0.0f}); - ctx->lens_spotlight->set_cutoff({math::radians(1.25f), math::radians(1.8f)}); - - ctx->flashlight_spotlight = new scene::spotlight(); - ctx->flashlight_spotlight->set_color({1, 1, 1}); - ctx->flashlight_spotlight->set_intensity(1.0f); - ctx->flashlight_spotlight->set_attenuation({1.0f, 0.0f, 0.0f}); - ctx->flashlight_spotlight->set_cutoff({math::radians(10.0f), math::radians(19.0f)}); + 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)}); @@ -690,7 +690,7 @@ void setup_scenes(game_context* ctx) 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->spotlight); + //ctx->overworld_scene->add_object(ctx->spot_light); // Setup underworld scene ctx->underworld_scene = new scene::collection(); @@ -706,8 +706,8 @@ void setup_scenes(game_context* ctx) ctx->ui_scene = new scene::collection(); ctx->ui_scene->add_object(ctx->ui_camera); - //ctx->overworld_scene->add_object(ctx->lens_spotlight); - ctx->underworld_scene->add_object(ctx->flashlight_spotlight); + //ctx->overworld_scene->add_object(ctx->lens_spot_light); + ctx->underworld_scene->add_object(ctx->flashlight_spot_light); // Set overworld as active scene ctx->active_scene = ctx->overworld_scene; @@ -1271,11 +1271,11 @@ void setup_callbacks(game_context* ctx) //(*ctx->focal_point_tween)[1] = ctx->orbit_cam->get_focal_point(); auto xf = ecs::command::get_world_transform(*ctx->ecs_registry, ctx->lens_entity); - //ctx->lens_spotlight->look_at(xf.translation, xf.translation + ctx->sun_direct->get_direction(), {0, 1, 0}); + //ctx->lens_spot_light->look_at(xf.translation, xf.translation + ctx->sun_direct->get_direction(), {0, 1, 0}); xf = ecs::command::get_world_transform(*ctx->ecs_registry, ctx->flashlight_entity); - //ctx->flashlight_spotlight->set_transform(xf); - ctx->flashlight_spotlight->look_at(xf.translation, xf.translation + xf.rotation * float3{0, 0, 1}, {0, 0, -1}); + //ctx->flashlight_spot_light->set_transform(xf); + ctx->flashlight_spot_light->look_at(xf.translation, xf.translation + xf.rotation * float3{0, 0, 1}, {0, 0, -1}); ctx->ui_system->update(dt); ctx->render_system->update(t, dt); diff --git a/src/game/game-context.hpp b/src/game/game-context.hpp index d8579f4..ac56e49 100644 --- a/src/game/game-context.hpp +++ b/src/game/game-context.hpp @@ -189,8 +189,8 @@ struct game_context scene::point_light* subterrain_light; scene::ambient_light* underworld_ambient_light; scene::billboard* splash_billboard; - scene::spotlight* lens_spotlight; - scene::spotlight* flashlight_spotlight; + scene::spot_light* lens_spot_light; + scene::spot_light* flashlight_spot_light; geom::aabb no_cull; // Animation diff --git a/src/renderer/passes/material-pass.cpp b/src/renderer/passes/material-pass.cpp index c8fe468..8a2e6fa 100644 --- a/src/renderer/passes/material-pass.cpp +++ b/src/renderer/passes/material-pass.cpp @@ -42,7 +42,7 @@ #include "scene/ambient-light.hpp" #include "scene/directional-light.hpp" #include "scene/point-light.hpp" -#include "scene/spotlight.hpp" +#include "scene/spot-light.hpp" #include "configuration.hpp" #include "math/math.hpp" #include @@ -64,7 +64,7 @@ material_pass::material_pass(gl::rasterizer* rasterizer, const gl::framebuffer* max_ambient_light_count = MATERIAL_PASS_MAX_AMBIENT_LIGHT_COUNT; max_point_light_count = MATERIAL_PASS_MAX_POINT_LIGHT_COUNT; max_directional_light_count = MATERIAL_PASS_MAX_DIRECTIONAL_LIGHT_COUNT; - max_spotlight_count = MATERIAL_PASS_MAX_SPOTLIGHT_COUNT; + max_spot_light_count = MATERIAL_PASS_MAX_SPOTLIGHT_COUNT; ambient_light_colors = new float3[max_ambient_light_count]; point_light_colors = new float3[max_point_light_count]; @@ -76,11 +76,11 @@ material_pass::material_pass(gl::rasterizer* rasterizer, const gl::framebuffer* directional_light_texture_matrices = new float4x4[max_directional_light_count]; directional_light_texture_opacities = new float[max_directional_light_count]; - spotlight_colors = new float3[max_spotlight_count]; - spotlight_positions = new float3[max_spotlight_count]; - spotlight_directions = new float3[max_spotlight_count]; - spotlight_attenuations = new float3[max_spotlight_count]; - spotlight_cutoffs = new float2[max_spotlight_count]; + spot_light_colors = new float3[max_spot_light_count]; + spot_light_positions = new float3[max_spot_light_count]; + spot_light_directions = new float3[max_spot_light_count]; + spot_light_attenuations = new float3[max_spot_light_count]; + spot_light_cutoffs = new float2[max_spot_light_count]; } material_pass::~material_pass() @@ -94,11 +94,11 @@ material_pass::~material_pass() delete[] directional_light_textures; delete[] directional_light_texture_matrices; delete[] directional_light_texture_opacities; - delete[] spotlight_colors; - delete[] spotlight_positions; - delete[] spotlight_directions; - delete[] spotlight_attenuations; - delete[] spotlight_cutoffs; + delete[] spot_light_colors; + delete[] spot_light_positions; + delete[] spot_light_directions; + delete[] spot_light_attenuations; + delete[] spot_light_cutoffs; } void material_pass::render(render_context* context) const @@ -148,7 +148,7 @@ void material_pass::render(render_context* context) const ambient_light_count = 0; point_light_count = 0; directional_light_count = 0; - spotlight_count = 0; + spot_light_count = 0; // Collect lights const std::list* lights = context->collection->get_objects(scene::light::object_type_id); @@ -227,25 +227,25 @@ void material_pass::render(render_context* context) const break; } - // Add spotlight + // Add spot_light case scene::light_type::spot: { - if (spotlight_count < max_spotlight_count) + if (spot_light_count < max_spot_light_count) { - const scene::spotlight* spotlight = static_cast(light); + const scene::spot_light* spot_light = static_cast(light); - spotlight_colors[spotlight_count] = light->get_scaled_color_tween().interpolate(context->alpha); + spot_light_colors[spot_light_count] = light->get_scaled_color_tween().interpolate(context->alpha); float3 position = light->get_transform_tween().interpolate(context->alpha).translation; - spotlight_positions[spotlight_count] = position; + spot_light_positions[spot_light_count] = position; - float3 direction = spotlight->get_direction_tween().interpolate(context->alpha); - spotlight_directions[spotlight_count] = direction; + float3 direction = spot_light->get_direction_tween().interpolate(context->alpha); + spot_light_directions[spot_light_count] = direction; - spotlight_attenuations[spotlight_count] = spotlight->get_attenuation_tween().interpolate(context->alpha); - spotlight_cutoffs[spotlight_count] = spotlight->get_cosine_cutoff_tween().interpolate(context->alpha); + spot_light_attenuations[spot_light_count] = spot_light->get_attenuation_tween().interpolate(context->alpha); + spot_light_cutoffs[spot_light_count] = spot_light->get_cosine_cutoff_tween().interpolate(context->alpha); - ++spotlight_count; + ++spot_light_count; } break; } @@ -474,18 +474,18 @@ void material_pass::render(render_context* context) const if (parameters->directional_light_texture_opacities) parameters->directional_light_texture_opacities->upload(0, directional_light_texture_opacities, directional_light_count); - if (parameters->spotlight_count) - parameters->spotlight_count->upload(spotlight_count); - if (parameters->spotlight_colors) - parameters->spotlight_colors->upload(0, spotlight_colors, spotlight_count); - if (parameters->spotlight_positions) - parameters->spotlight_positions->upload(0, spotlight_positions, spotlight_count); - if (parameters->spotlight_directions) - parameters->spotlight_directions->upload(0, spotlight_directions, spotlight_count); - if (parameters->spotlight_attenuations) - parameters->spotlight_attenuations->upload(0, spotlight_attenuations, spotlight_count); - if (parameters->spotlight_cutoffs) - parameters->spotlight_cutoffs->upload(0, spotlight_cutoffs, spotlight_count); + if (parameters->spot_light_count) + parameters->spot_light_count->upload(spot_light_count); + if (parameters->spot_light_colors) + parameters->spot_light_colors->upload(0, spot_light_colors, spot_light_count); + if (parameters->spot_light_positions) + parameters->spot_light_positions->upload(0, spot_light_positions, spot_light_count); + if (parameters->spot_light_directions) + parameters->spot_light_directions->upload(0, spot_light_directions, spot_light_count); + if (parameters->spot_light_attenuations) + parameters->spot_light_attenuations->upload(0, spot_light_attenuations, spot_light_count); + if (parameters->spot_light_cutoffs) + parameters->spot_light_cutoffs->upload(0, spot_light_cutoffs, spot_light_count); if (parameters->focal_point) parameters->focal_point->upload(focal_point); @@ -579,12 +579,12 @@ const material_pass::parameter_set* material_pass::load_parameter_set(const gl:: parameters->directional_light_textures = program->get_input("directional_light_textures"); parameters->directional_light_texture_matrices = program->get_input("directional_light_texture_matrices"); parameters->directional_light_texture_opacities = program->get_input("directional_light_texture_opacities"); - parameters->spotlight_count = program->get_input("spotlight_count"); - parameters->spotlight_colors = program->get_input("spotlight_colors"); - parameters->spotlight_positions = program->get_input("spotlight_positions"); - parameters->spotlight_directions = program->get_input("spotlight_directions"); - parameters->spotlight_attenuations = program->get_input("spotlight_attenuations"); - parameters->spotlight_cutoffs = program->get_input("spotlight_cutoffs"); + parameters->spot_light_count = program->get_input("spot_light_count"); + parameters->spot_light_colors = program->get_input("spot_light_colors"); + parameters->spot_light_positions = program->get_input("spot_light_positions"); + parameters->spot_light_directions = program->get_input("spot_light_directions"); + parameters->spot_light_attenuations = program->get_input("spot_light_attenuations"); + parameters->spot_light_cutoffs = program->get_input("spot_light_cutoffs"); parameters->focal_point = program->get_input("focal_point"); parameters->shadow_map_directional = program->get_input("shadow_map_directional"); parameters->shadow_splits_directional = program->get_input("shadow_splits_directional"); diff --git a/src/renderer/passes/material-pass.hpp b/src/renderer/passes/material-pass.hpp index 726faca..d81a199 100644 --- a/src/renderer/passes/material-pass.hpp +++ b/src/renderer/passes/material-pass.hpp @@ -92,12 +92,12 @@ private: const gl::shader_input* directional_light_textures; const gl::shader_input* directional_light_texture_matrices; const gl::shader_input* directional_light_texture_opacities; - const gl::shader_input* spotlight_count; - const gl::shader_input* spotlight_colors; - const gl::shader_input* spotlight_positions; - const gl::shader_input* spotlight_directions; - const gl::shader_input* spotlight_attenuations; - const gl::shader_input* spotlight_cutoffs; + const gl::shader_input* spot_light_count; + const gl::shader_input* spot_light_colors; + const gl::shader_input* spot_light_positions; + const gl::shader_input* spot_light_directions; + const gl::shader_input* spot_light_attenuations; + const gl::shader_input* spot_light_cutoffs; const gl::shader_input* focal_point; @@ -117,12 +117,12 @@ private: int max_ambient_light_count; int max_point_light_count; int max_directional_light_count; - int max_spotlight_count; + int max_spot_light_count; mutable int ambient_light_count; mutable int point_light_count; mutable int directional_light_count; - mutable int spotlight_count; + mutable int spot_light_count; float3* ambient_light_colors; float3* point_light_colors; @@ -133,11 +133,11 @@ private: const gl::texture_2d** directional_light_textures; float4x4* directional_light_texture_matrices; float* directional_light_texture_opacities; - float3* spotlight_colors; - float3* spotlight_positions; - float3* spotlight_directions; - float3* spotlight_attenuations; - float2* spotlight_cutoffs; + float3* spot_light_colors; + float3* spot_light_positions; + float3* spot_light_directions; + float3* spot_light_attenuations; + float2* spot_light_cutoffs; }; #endif // ANTKEEPER_MATERIAL_PASS_HPP diff --git a/src/scene/scene.hpp b/src/scene/scene.hpp index 0682496..97aeb4a 100644 --- a/src/scene/scene.hpp +++ b/src/scene/scene.hpp @@ -33,6 +33,6 @@ namespace scene {} #include "model-instance.hpp" #include "object.hpp" #include "point-light.hpp" -#include "spotlight.hpp" +#include "spot-light.hpp" #endif // ANTKEEPER_SCENE_HPP diff --git a/src/scene/spotlight.cpp b/src/scene/spot-light.cpp similarity index 88% rename from src/scene/spotlight.cpp rename to src/scene/spot-light.cpp index e0febdc..c460ba1 100644 --- a/src/scene/spotlight.cpp +++ b/src/scene/spot-light.cpp @@ -17,7 +17,7 @@ * along with Antkeeper source code. If not, see . */ -#include "spotlight.hpp" +#include "spot-light.hpp" #include "configuration.hpp" #include "math/math.hpp" #include @@ -31,25 +31,25 @@ static float3 interpolate_direction(const float3& x, const float3& y, float a) return math::normalize(math::slerp(q0, q1, a) * global_forward); } -spotlight::spotlight(): +spot_light::spot_light(): direction(global_forward, interpolate_direction), attenuation(float3{1, 0, 0}, math::lerp), cutoff(float2{math::pi, math::pi}, math::lerp), cosine_cutoff(float2{std::cos(math::pi), std::cos(math::pi)}, math::lerp) {} -void spotlight::set_attenuation(const float3& attenuation) +void spot_light::set_attenuation(const float3& attenuation) { this->attenuation[1] = attenuation; } -void spotlight::set_cutoff(const float2& cutoff) +void spot_light::set_cutoff(const float2& cutoff) { this->cutoff[1] = cutoff; this->cosine_cutoff[1] = {std::cos(cutoff.x), std::cos(cutoff.y)}; } -void spotlight::update_tweens() +void spot_light::update_tweens() { light::update_tweens(); direction.update(); @@ -58,7 +58,7 @@ void spotlight::update_tweens() cosine_cutoff.update(); } -void spotlight::transformed() +void spot_light::transformed() { direction[1] = math::normalize(get_transform().rotation * global_forward); } diff --git a/src/scene/spotlight.hpp b/src/scene/spot-light.hpp similarity index 73% rename from src/scene/spotlight.hpp rename to src/scene/spot-light.hpp index 7b06673..4550ab3 100644 --- a/src/scene/spotlight.hpp +++ b/src/scene/spot-light.hpp @@ -17,8 +17,8 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_SCENE_SPOTLIGHT_HPP -#define ANTKEEPER_SCENE_SPOTLIGHT_HPP +#ifndef ANTKEEPER_SCENE_SPOT_LIGHT_HPP +#define ANTKEEPER_SCENE_SPOT_LIGHT_HPP #include "scene/light.hpp" #include "utility/fundamental-types.hpp" @@ -28,11 +28,11 @@ namespace scene { /** * Directional cone light source. */ -class spotlight: public light +class spot_light: public light { public: - /// Creates a spotlight. - spotlight(); + /// Creates a spot light. + spot_light(); /// Returns light_type::spot virtual light_type get_light_type() const; @@ -45,7 +45,7 @@ public: void set_attenuation(const float3& attenuation); /** - * Sets the spotlight cutoff angles. + * Sets the spot light cutoff angles. * * @param cutoff Vector containing the inner and outer cutoff angles, as x and y, respectively. */ @@ -57,10 +57,10 @@ public: /// Returns the attenuation factors of the light. const float3& get_attenuation() const; - /// Returns the spotlight cutoff angles. + /// Returns the spot light cutoff angles. const float2& get_cutoff() const; - /// Returns the cosine of the spotlight cutoff angles. + /// Returns the cosine of the spot light cutoff angles. const float2& get_cosine_cutoff() const; /// Returns the direction tween. @@ -87,52 +87,52 @@ private: tween cosine_cutoff; }; -inline light_type spotlight::get_light_type() const +inline light_type spot_light::get_light_type() const { return light_type::spot; } -inline const float3& spotlight::get_direction() const +inline const float3& spot_light::get_direction() const { return direction[1]; } -inline const float3& spotlight::get_attenuation() const +inline const float3& spot_light::get_attenuation() const { return attenuation[1]; } -inline const float2& spotlight::get_cutoff() const +inline const float2& spot_light::get_cutoff() const { return cutoff[1]; } -inline const float2& spotlight::get_cosine_cutoff() const +inline const float2& spot_light::get_cosine_cutoff() const { return cosine_cutoff[1]; } -inline const tween& spotlight::get_direction_tween() const +inline const tween& spot_light::get_direction_tween() const { return direction; } -inline const tween& spotlight::get_attenuation_tween() const +inline const tween& spot_light::get_attenuation_tween() const { return attenuation; } -inline const tween& spotlight::get_cutoff_tween() const +inline const tween& spot_light::get_cutoff_tween() const { return cutoff; } -inline const tween& spotlight::get_cosine_cutoff_tween() const +inline const tween& spot_light::get_cosine_cutoff_tween() const { return cosine_cutoff; } } // namespace scene -#endif // ANTKEEPER_SCENE_SPOTLIGHT_HPP +#endif // ANTKEEPER_SCENE_SPOT_LIGHT_HPP