diff --git a/src/scene.cpp b/src/scene.cpp index 481cb16a39dc1f1bf841febaedaa1c349ef77b31..099625ecbc2cff7f3a25ee77ebdc5878b14dbdc3 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -160,6 +160,7 @@ bool Scene::interface() } ImGui::Checkbox("Animation Active", &this->animation_active); + ImGui::Checkbox("Camera Active", &this->camera_active); ImGui::Checkbox("Animation Loop", &this->animation_loop); ImGui::SliderFloat("Animation Time", &this->animation_time, 0.0f, active_animation.duration); ImGui::DragFloat("Playback Speed", &this->animation_playback_speed, 1.0f, -100.0f, 100.0); @@ -428,6 +429,11 @@ bool Scene::is_animation_active() const return this->animation_active; } +bool Scene::is_camera_active() const +{ + return this->camera_active && !this->cameras.empty(); +} + lava::descriptor::ptr Scene::get_mesh_descriptor() const { return this->mesh_descriptor; @@ -633,8 +639,12 @@ bool Scene::create_material_buffer(lava::device_ptr device) std::vector<VkWriteDescriptorSet> descriptor_writes; descriptor_writes.reserve(this->materials.size() * 5); - for (SceneMaterial& material : this->materials) + std::vector<VkDescriptorBufferInfo> buffer_infos; + buffer_infos.reserve(this->materials.size()); + + for (uint32_t index = 0; index < this->materials.size(); index++) { + SceneMaterial& material = this->materials[index]; material.descriptor_set = this->material_descriptor->allocate_set(this->descriptor_pool->get()); std::vector<lava::texture::ptr> textures; @@ -645,7 +655,7 @@ bool Scene::create_material_buffer(lava::device_ptr device) for (uint32_t binding = 0; binding < textures.size(); binding++) { - VkWriteDescriptorSet texture_write; + VkWriteDescriptorSet& texture_write = descriptor_writes.emplace_back(); texture_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; texture_write.pNext = nullptr; texture_write.dstSet = material.descriptor_set; @@ -656,11 +666,14 @@ bool Scene::create_material_buffer(lava::device_ptr device) texture_write.pImageInfo = textures[binding]->get_descriptor_info(); texture_write.pBufferInfo = nullptr; texture_write.pTexelBufferView = nullptr; - - descriptor_writes.push_back(texture_write); } - VkWriteDescriptorSet buffer_write; + VkDescriptorBufferInfo& buffer_info = buffer_infos.emplace_back(); + buffer_info.buffer = this->material_data_buffer->get(); + buffer_info.offset = sizeof(glsl::MaterialData) * index; + buffer_info.range = sizeof(glsl::MaterialData); + + VkWriteDescriptorSet& buffer_write = descriptor_writes.emplace_back(); buffer_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; buffer_write.pNext = nullptr; buffer_write.dstSet = material.descriptor_set; @@ -669,10 +682,8 @@ bool Scene::create_material_buffer(lava::device_ptr device) buffer_write.descriptorCount = 1; buffer_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; buffer_write.pImageInfo = nullptr; - buffer_write.pBufferInfo = this->material_data_buffer->get_descriptor_info(); + buffer_write.pBufferInfo = &buffer_info; buffer_write.pTexelBufferView = nullptr; - - descriptor_writes.push_back(buffer_write); } vkUpdateDescriptorSets(device->get(), descriptor_writes.size(), descriptor_writes.data(), 0, nullptr); @@ -1004,6 +1015,18 @@ bool Scene::load_sky_sphere(const std::string& file_name, uint32_t ring_count, u sky_material.normal = this->dummy_normal_texture; sky_material.emissive = this->sky_emissive_texture; + glsl::MaterialData& sky_material_data = sky_material.material_data; + sky_material_data.base_color = glm::vec3(1.0f); + sky_material_data.opacity = 1.0f; + sky_material_data.emissive = glm::vec3(1.0f); + sky_material_data.roughness = 1.0f; + sky_material_data.padding1 = glm::uvec3(0); + sky_material_data.metallic = 1.0f; + sky_material_data.padding2 = glm::uvec4(0); + sky_material_data.padding3 = glm::mat4(0.0f); + sky_material_data.padding4 = glm::mat4(0.0f); + sky_material_data.padding5 = glm::mat4(0.0f); + if (ring_count < 3) { lava::log()->error("Invalid number of rings for sky-sphere. The number of rings needs to be at least 3!"); diff --git a/src/scene.hpp b/src/scene.hpp index b4099ff0d3df0d85b84f53496618acc379055221..a53d398aab611caa1c9b0145f14754afeb304310 100644 --- a/src/scene.hpp +++ b/src/scene.hpp @@ -150,6 +150,7 @@ public: const glm::mat4& get_animation_view_matrix() const; bool is_animation_complete() const; bool is_animation_active() const; + bool is_camera_active() const; lava::descriptor::ptr get_mesh_descriptor() const; lava::descriptor::ptr get_light_descriptor() const; @@ -202,7 +203,6 @@ private: static bool compute_scale(SceneUnit unit, float& scale); private: - SceneNodeIndex camera_index = 0; SceneNodeIndex controller_left = INVALID_NODE; SceneNodeIndex controller_right = INVALID_NODE; @@ -215,6 +215,9 @@ private: float animation_time = 0.0f; float animation_playback_speed = 1.0f; + int32_t camera_index = 0; + bool camera_active = true; + glm::vec3 scene_min = glm::vec3(0.0f); glm::vec3 scene_max = glm::vec3(0.0f); diff --git a/src/vr_application.cpp b/src/vr_application.cpp index f2b841fd45affc2a8b5be04cfd4dc577c2c84fc3..c1e56d438310a074c508522cc6a32c69af7ef0d0 100644 --- a/src/vr_application.cpp +++ b/src/vr_application.cpp @@ -648,7 +648,7 @@ bool VRApplication::on_update(lava::delta delta_time) this->stereo_transform->set_projection_matrix(EYE_LEFT, this->headset->get_projection_matrix(EYE_LEFT)); this->stereo_transform->set_projection_matrix(EYE_RIGHT, this->headset->get_projection_matrix(EYE_RIGHT)); - if (this->scene->is_animation_active()) + if (this->scene->is_animation_active() && this->scene->is_camera_active()) { this->stereo_transform->set_view_matrix(this->scene->get_animation_view_matrix()); }