Skip to content

Commit 73c882f

Browse files
Introducing of Cubemap (#292)
* first draft of cubemap implementation * updated cubmape frag shader * fixed image Y flipping * introduced imgui renderer * fixed event handling while hovering scene cmpnt * reverted min frame image count * switched to use mem secure version * added engine def to bitmap
1 parent d62c270 commit 73c882f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2309
-1465
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.

Resources/Shaders/cubemap.frag

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#version 460
2+
3+
layout (location = 0) in vec3 dir;
4+
5+
layout (location = 0) out vec4 outColor;
6+
7+
layout(set = 0, binding = 5) uniform samplerCube CubemapTexture;
8+
9+
void main()
10+
{
11+
outColor = texture(CubemapTexture, dir);
12+
}

Resources/Shaders/cubemap.vert

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#version 460
2+
#extension GL_GOOGLE_include_directive : require
3+
#include "vertex_common.glsl"
4+
5+
6+
layout (location = 0) out vec3 dir;
7+
8+
void main()
9+
{
10+
float cubeScale = 100.0;
11+
12+
DrawData dd = DrawDataBuffer.Data[gl_BaseInstance];
13+
14+
uint refIdx = dd.IndexOffset + gl_VertexIndex;
15+
uint verIdx = IndexBuffer.Data[refIdx] + dd.VertexOffset;
16+
DrawVertex v = VertexBuffer.Data[verIdx];
17+
18+
vec3 vertexPosition = vec3(v.x, v.y, v.z);
19+
gl_Position = Camera.Projection * Camera.View * vec4(cubeScale * vertexPosition, 1.0f);
20+
dir = vec3(vertexPosition.x, vertexPosition.y, vertexPosition.z);
21+
}

Resources/Shaders/imgui.frag

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#version 460 core
2+
layout(location = 0) out vec4 fColor;
3+
layout(set=0, binding=0) uniform sampler2D sTexture;
4+
layout(location = 0) in struct { vec4 Color; vec2 UV; } In;
5+
void main()
6+
{
7+
fColor = In.Color * texture(sTexture, In.UV.st);
8+
}

Resources/Shaders/imgui.vert

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#version 460 core
2+
layout(location = 0) in vec2 aPos;
3+
layout(location = 1) in vec2 aUV;
4+
layout(location = 2) in vec4 aColor;
5+
layout(push_constant) uniform uPushConstant { vec2 uScale; vec2 uTranslate; } pc;
6+
7+
out gl_PerVertex { vec4 gl_Position; };
8+
layout(location = 0) out struct { vec4 Color; vec2 UV; } Out;
9+
10+
void main()
11+
{
12+
Out.Color = aColor;
13+
Out.UV = aUV;
14+
gl_Position = vec4(aPos * pc.uScale + pc.uTranslate, 0, 1);
15+
}

Tetragrama/src/Components/SceneViewportUIComponent.cpp

+8-19
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace Tetragrama::Components
2323
{
2424
if ((m_viewport_size.x != m_content_region_available_size.x) || (m_viewport_size.y != m_content_region_available_size.y))
2525
{
26-
m_viewport_size = m_content_region_available_size;
26+
m_viewport_size = m_content_region_available_size;
2727
m_request_renderer_resize = true;
2828
}
2929
else
@@ -42,13 +42,13 @@ namespace Tetragrama::Components
4242

4343
if (m_is_window_hovered && m_is_window_focused)
4444
{
45-
Messengers::IMessenger::SendAsync<ZEngine::Components::UI::UIComponent, Messengers::GenericMessage<bool>>(
46-
EDITOR_COMPONENT_SCENEVIEWPORT_FOCUSED, Messengers::GenericMessage<bool>{true});
45+
Messengers::IMessenger::SendAsync<ZEngine::Layers::Layer, Messengers::GenericMessage<bool>>(
46+
EDITOR_RENDER_LAYER_SCENE_REQUEST_FOCUS, Messengers::GenericMessage<bool>{true});
4747
}
4848
else
4949
{
50-
Messengers::IMessenger::SendAsync<ZEngine::Components::UI::UIComponent, Messengers::GenericMessage<bool>>(
51-
EDITOR_COMPONENT_SCENEVIEWPORT_UNFOCUSED, Messengers::GenericMessage<bool>{false});
50+
Messengers::IMessenger::SendAsync<ZEngine::Layers::Layer, Messengers::GenericMessage<bool>>(
51+
EDITOR_RENDER_LAYER_SCENE_REQUEST_UNFOCUS, Messengers::GenericMessage<bool>{false});
5252
}
5353

5454
if (m_is_window_clicked && m_is_window_hovered && m_is_window_focused)
@@ -59,7 +59,7 @@ namespace Tetragrama::Components
5959

6060
auto mouse_bounded_x = static_cast<int>(mouse_position.x);
6161
auto mouse_bounded_y = static_cast<int>(mouse_position.y);
62-
auto message_data = std::array{mouse_bounded_x, mouse_bounded_y};
62+
auto message_data = std::array{mouse_bounded_x, mouse_bounded_y};
6363
Messengers::IMessenger::SendAsync<ZEngine::Components::UI::UIComponent, Messengers::ArrayValueMessage<int, 2>>(
6464
EDITOR_COMPONENT_SCENEVIEWPORT_CLICKED, Messengers::ArrayValueMessage<int, 2>{message_data});
6565
}
@@ -85,19 +85,8 @@ namespace Tetragrama::Components
8585
// Scene texture representation
8686
if (!m_scene_texture || m_refresh_texture_handle)
8787
{
88-
auto frame_output = GraphicRenderer::GetFrameOutput();
89-
auto texture = frame_output->GetColorAttachmentCollection().at(0);
90-
91-
if (m_refresh_texture_handle)
92-
{
93-
VkDescriptorSet old_scene_texture = VK_NULL_HANDLE;
94-
std::swap(m_scene_texture, old_scene_texture);
95-
m_refresh_texture_handle = false;
96-
97-
VulkanDevice::EnqueueForDeletion(DeviceResourceType::DESCRIPTORSET, DirtyResource{.Handle = old_scene_texture, .Data1 = ImGUIRenderer::s_descriptor_pool});
98-
}
99-
auto texture_buffer = texture->GetImage2DBuffer();
100-
m_scene_texture = ImGui_ImplVulkan_AddTexture(texture_buffer->GetSampler(), texture_buffer->GetImageViewHandle(), VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
88+
m_scene_texture = GraphicRenderer::GetImguiFrameOutput();
89+
m_refresh_texture_handle = false;
10190
}
10291

10392
ImGui::Image(m_scene_texture, m_viewport_size, ImVec2(0, 1), ImVec2(1, 0));

Tetragrama/src/EditorCameraController.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace Tetragrama
77
{
88
EditorCameraController::EditorCameraController(double distance, float yaw_angle_degree, float pitch_angle_degree) : PerspectiveCameraController(0.0f)
99
{
10+
m_process_event = true;
1011
m_controller_type = ZEngine::Controllers::CameraControllerType::PERSPECTIVE_CONTROLLER;
1112
m_perspective_camera = ZEngine::CreateRef<PerspectiveCamera>(
1213
m_camera_fov, m_aspect_ratio, m_camera_near, m_camera_far, ZEngine::Maths::radians(yaw_angle_degree), ZEngine::Maths::radians(pitch_angle_degree));

Tetragrama/src/Layers/RenderLayer.cpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ namespace Tetragrama::Layers
2020

2121
void RenderLayer::Initialize()
2222
{
23-
auto current_window = GetAttachedWindow();
2423
m_editor_camera_controller = CreateRef<EditorCameraController>(50.0, 45.f, 40.f);
2524
GraphicScene::Initialize();
2625

@@ -49,8 +48,6 @@ namespace Tetragrama::Layers
4948
{
5049
auto camera = m_editor_camera_controller->GetCamera();
5150
GraphicRenderer::DrawScene(camera, GraphicScene::GetRawData());
52-
53-
5451
}
5552

5653
std::future<void> RenderLayer::SceneRequestResizeMessageHandlerAsync(Messengers::GenericMessage<std::pair<float, float>>& message)
@@ -64,15 +61,13 @@ namespace Tetragrama::Layers
6461

6562
std::future<void> RenderLayer::SceneRequestFocusMessageHandlerAsync(Messengers::GenericMessage<bool>& message)
6663
{
67-
// std::unique_lock lock(m_message_handler_mutex);
68-
// GraphicScene::SetShouldReactToEvent(message.GetValue());
64+
m_editor_camera_controller->ResumeEventProcessing();
6965
co_return;
7066
}
7167

7268
std::future<void> RenderLayer::SceneRequestUnfocusMessageHandlerAsync(Messengers::GenericMessage<bool>& message)
7369
{
74-
// std::unique_lock lock(m_message_handler_mutex);
75-
// GraphicScene::SetShouldReactToEvent(message.GetValue());
70+
m_editor_camera_controller->PauseEventProcessing();
7671
co_return;
7772
}
7873

ZEngine/include/ZEngine/Controllers/PerspectiveCameraController.h

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#pragma once
2+
#include <mutex>
23
#include <Controllers/ICameraController.h>
34
#include <Rendering/Cameras/PerspectiveCamera.h>
45
#include <Inputs/IMouseEventCallback.h>
@@ -10,32 +11,34 @@ namespace ZEngine::Controllers
1011
class PerspectiveCameraController : public ICameraController, public Inputs::IMouseEventCallback, public Window::ICoreWindowEventCallback
1112
{
1213
public:
13-
explicit PerspectiveCameraController()
14-
:m_perspective_camera(new Rendering::Cameras::PerspectiveCamera(m_camera_fov, m_aspect_ratio, m_camera_near, m_camera_far))
14+
explicit PerspectiveCameraController() : m_perspective_camera(new Rendering::Cameras::PerspectiveCamera(m_camera_fov, m_aspect_ratio, m_camera_near, m_camera_far))
1515
{
16-
m_controller_type = CameraControllerType::PERSPECTIVE_CONTROLLER;
1716
m_position = {0.0f, 0.0f, 1.5f};
17+
m_controller_type = CameraControllerType::PERSPECTIVE_CONTROLLER;
18+
m_process_event = true;
1819
}
1920

20-
explicit PerspectiveCameraController(Rendering::Cameras::PerspectiveCamera* const camera)
21-
:m_perspective_camera(camera)
21+
explicit PerspectiveCameraController(Rendering::Cameras::PerspectiveCamera* const camera) : m_perspective_camera(camera)
2222
{
2323
m_position = {0.0f, 0.0f, 1.5f};
2424
m_controller_type = CameraControllerType::PERSPECTIVE_CONTROLLER;
25+
m_process_event = true;
2526
}
2627

2728
explicit PerspectiveCameraController(float aspect_ratio, Rendering::Cameras::PerspectiveCamera* const camera)
2829
: ICameraController(aspect_ratio), m_perspective_camera(camera)
2930
{
3031
m_position = {0.0f, 0.0f, 1.5f};
3132
m_controller_type = CameraControllerType::PERSPECTIVE_CONTROLLER;
33+
m_process_event = true;
3234
}
3335

3436
explicit PerspectiveCameraController(float aspect_ratio)
3537
: ICameraController(aspect_ratio), m_perspective_camera(new Rendering::Cameras::PerspectiveCamera(m_camera_fov, m_aspect_ratio, m_camera_near, m_camera_far))
3638
{
3739
m_position = {0.0f, 0.0f, 1.5f};
3840
m_controller_type = CameraControllerType::PERSPECTIVE_CONTROLLER;
41+
m_process_event = true;
3942
}
4043

4144
virtual ~PerspectiveCameraController() = default;
@@ -63,6 +66,9 @@ namespace ZEngine::Controllers
6366
void SetViewport(float width, float height);
6467
void SetTarget(const glm::vec3& target);
6568

69+
virtual void ResumeEventProcessing();
70+
virtual void PauseEventProcessing();
71+
6672
public:
6773
bool OnMouseButtonPressed(Event::MouseButtonPressedEvent&) override
6874
{
@@ -107,10 +113,12 @@ namespace ZEngine::Controllers
107113
}
108114

109115
protected:
110-
float m_camera_fov{45.0f};
111-
float m_camera_near{0.1f};
112-
float m_camera_far{5000.0f};
113-
glm::vec3 m_camera_target{0.0f, 0.0f, 0.0f};
116+
float m_camera_fov{45.0f};
117+
float m_camera_near{0.1f};
118+
float m_camera_far{5000.0f};
119+
std::recursive_mutex m_event_mutex;
120+
bool m_process_event{true};
121+
glm::vec3 m_camera_target{0.0f, 0.0f, 0.0f};
114122
ZEngine::Ref<Rendering::Cameras::PerspectiveCamera> m_perspective_camera;
115123
};
116124
} // namespace ZEngine::Controllers

0 commit comments

Comments
 (0)