Browse Source

Cleaned up code.

Jef Belmans 2 years ago
parent
commit
e094d67bcf

+ 1 - 2
coral_renderer/coral_frame_info.h

@@ -24,8 +24,7 @@ namespace coral_3d
         glm::mat4 view_projection{1.f};
 
         // GLOBAL LIGHT
-        glm::vec4 global_light_direction{ glm::normalize(glm::vec4{ -0.477f,
-                                                                    0.477f, -0.477f, 1.f})}; // w is intensity
+        glm::vec4 global_light_direction{ glm::normalize(glm::vec4{ -0.477f, 0.477f, -0.477f, 0.f})}; // w is intensity
         glm::vec4 ambient_lighting{0.14f, 0.14f, 0.14f, 0.05f}; // w is intensity
 
         // POINT LIGHTS

+ 1 - 3
coral_renderer/coral_gameobject.cpp

@@ -4,11 +4,9 @@ using namespace coral_3d;
 
 coral_gameobject coral_gameobject::create_point_light(float intensity, float radius, glm::vec3 color)
 {
-    coral_gameobject gameobject = coral_gameobject::create_gameobject
-            ("point_light");
+    coral_gameobject gameobject = coral_gameobject::create_gameobject();
     gameobject.transform_.scale.x = radius;
     gameobject.point_light_ = std::make_unique<PointLightComponent>();
     gameobject.point_light_->color = glm::vec4(color, intensity);
-    gameobject.name_ += std::to_string(gameobject.id_);
     return gameobject;
 }

+ 3 - 6
coral_renderer/coral_gameobject.h

@@ -70,10 +70,10 @@ namespace coral_3d
 		using Map = std::unordered_map<id_t, std::shared_ptr<coral_gameobject>>;
 
         // Creators
-		static coral_gameobject create_gameobject(const std::string& name)
+		static coral_gameobject create_gameobject()
 		{
 			static id_t current_id = 0;
-			return coral_gameobject{ current_id++, name };
+			return coral_gameobject{ current_id++ };
 		}
 
         static coral_gameobject create_point_light(float intensity = 1.f, float radius = .1f, glm::vec3 color = glm::vec3{1.f});
@@ -84,7 +84,6 @@ namespace coral_3d
 		coral_gameobject& operator=(coral_gameobject&&) = default;
 
 		id_t get_id() const { return id_; }
-        std::string& get_name() { return name_; }
 
 		TransformComponent transform_{};
 
@@ -93,9 +92,7 @@ namespace coral_3d
         std::unique_ptr<PointLightComponent> point_light_ = nullptr;
 
 	private:
-		explicit coral_gameobject(id_t object_id, const std::string& name) :
-        id_{ object_id }, name_{name} {}
+		explicit coral_gameobject(id_t object_id) : id_{ object_id } {}
 		id_t id_;
-        std::string name_;
 	};
 }

+ 9 - 21
coral_renderer/first_app.cpp

@@ -28,7 +28,7 @@ first_app::first_app()
             .add_pool_size(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, MAX_MATERIAL_SETS)
             .build();
 
-    input.add_callback(GLFW_KEY_F1,
+    input.add_callback(GLFW_KEY_B,
                        coral_input::Callback(GLFW_PRESS, [&](){
                            show_cursor_ = !show_cursor_;
                            glfwSetInputMode(window_.get_glfw_window(), GLFW_CURSOR,
@@ -112,13 +112,11 @@ void first_app::run()
         ImGui_ImplGlfw_NewFrame();
 
         ImGui::NewFrame();
-        ImGui::SetNextWindowPos(ImVec2(20, 20));
-        ImGui::SetNextWindowSize(ImVec2(250, 300));
-        ImGui::Begin("Coral 3D", nullptr, ImGuiWindowFlags_NoResize);
 
 		if (auto command_buffer = renderer_.begin_frame())
 		{
             const int frame_index{ renderer_.get_frame_index() };
+            auto& obj = gameobjects_.at(0);
 
             FrameInfo frame_info
             {
@@ -131,21 +129,12 @@ void first_app::run()
             };
 
             // UPDATE
-            ubo_.view = camera.get_view();
-            ubo_.view_inverse = glm::inverse(camera.get_view());
-            ubo_.view_projection = camera.get_projection() * camera.get_view();
-
-            // DIRECTIONAL LIGHT
-            if(ImGui::CollapsingHeader("Directional Light"))
-            {
-                ImGui::SliderFloat3("Direction", &ubo_
-                .global_light_direction[0], -1.f, 1.f);
-                ImGui::SliderFloat("Intensity", &ubo_.global_light_direction.w,
-                                   0.f, 1.f);
-            }
-
-            point_light_system.update(frame_info, ubo_);
-            global_ubo.write_to_index(&ubo_, frame_index);
+            GlobalUBO ubo{};
+            ubo.view = camera.get_view();
+            ubo.view_inverse = glm::inverse(camera.get_view());
+            ubo.view_projection = camera.get_projection() * camera.get_view();
+            point_light_system.update(frame_info, ubo);
+            global_ubo.write_to_index(&ubo, frame_index);
             global_ubo.flush_index(frame_index);
 
             // RENDER
@@ -168,8 +157,7 @@ void first_app::load_gameobjects(coral_descriptor_set_layout& material_set_layou
                                  coral_buffer& global_ubo)
 {
     // GAMEOBJECTS
-    auto sponza_scene{std::make_shared<coral_gameobject>
-            (coral_gameobject::create_gameobject("Helmet")) };
+    auto sponza_scene{std::make_shared<coral_gameobject>(coral_gameobject::create_gameobject()) };
 
     // MESHES
     std::shared_ptr<coral_mesh> sponza_mesh

+ 0 - 3
coral_renderer/first_app.h

@@ -8,7 +8,6 @@
 #include "coral_texture.h"
 #include "coral_cubemap.h"
 #include "coral_input.h"
-#include "coral_frame_info.h"
 
 // STD
 #include <memory>
@@ -48,9 +47,7 @@ namespace coral_3d
         std::vector<VkDescriptorSet> global_descriptor_sets_{coral_swapchain::MAX_FRAMES_IN_FLIGHT};
         std::unique_ptr<coral_descriptor_set_layout> global_set_layout_;
 
-        // GAME DATA
 		coral_gameobject::Map gameobjects_;
-        GlobalUBO ubo_;
 
         // INPUT
         coral_input input{};

+ 1 - 0
coral_renderer/point_light_system.cpp

@@ -1,5 +1,6 @@
 #include "point_light_system.h"
 #include "vk_initializers.h"
+#include "imgui.h"
 
 using namespace coral_3d;
 

+ 0 - 1
coral_renderer/vk_types.h

@@ -1,7 +1,6 @@
 #pragma once
 #include <vulkan/vulkan.h>
 #include <vk_mem_alloc.h>
-#define GLM_FORCE_SWIZZLE
 #include <glm.hpp>
 
 #include <deque>