Skip to content

Introducing of Cubemap #292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Dec 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
12 changes: 12 additions & 0 deletions Resources/Shaders/cubemap.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#version 460

layout (location = 0) in vec3 dir;

layout (location = 0) out vec4 outColor;

layout(set = 0, binding = 5) uniform samplerCube CubemapTexture;

void main()
{
outColor = texture(CubemapTexture, dir);
}
21 changes: 21 additions & 0 deletions Resources/Shaders/cubemap.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#version 460
#extension GL_GOOGLE_include_directive : require
#include "vertex_common.glsl"


layout (location = 0) out vec3 dir;

void main()
{
float cubeScale = 100.0;

DrawData dd = DrawDataBuffer.Data[gl_BaseInstance];

uint refIdx = dd.IndexOffset + gl_VertexIndex;
uint verIdx = IndexBuffer.Data[refIdx] + dd.VertexOffset;
DrawVertex v = VertexBuffer.Data[verIdx];

vec3 vertexPosition = vec3(v.x, v.y, v.z);
gl_Position = Camera.Projection * Camera.View * vec4(cubeScale * vertexPosition, 1.0f);
dir = vec3(vertexPosition.x, vertexPosition.y, vertexPosition.z);
}
8 changes: 8 additions & 0 deletions Resources/Shaders/imgui.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#version 460 core
layout(location = 0) out vec4 fColor;
layout(set=0, binding=0) uniform sampler2D sTexture;
layout(location = 0) in struct { vec4 Color; vec2 UV; } In;
void main()
{
fColor = In.Color * texture(sTexture, In.UV.st);
}
15 changes: 15 additions & 0 deletions Resources/Shaders/imgui.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#version 460 core
layout(location = 0) in vec2 aPos;
layout(location = 1) in vec2 aUV;
layout(location = 2) in vec4 aColor;
layout(push_constant) uniform uPushConstant { vec2 uScale; vec2 uTranslate; } pc;

out gl_PerVertex { vec4 gl_Position; };
layout(location = 0) out struct { vec4 Color; vec2 UV; } Out;

void main()
{
Out.Color = aColor;
Out.UV = aUV;
gl_Position = vec4(aPos * pc.uScale + pc.uTranslate, 0, 1);
}
27 changes: 8 additions & 19 deletions Tetragrama/src/Components/SceneViewportUIComponent.cpp
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ namespace Tetragrama::Components
{
if ((m_viewport_size.x != m_content_region_available_size.x) || (m_viewport_size.y != m_content_region_available_size.y))
{
m_viewport_size = m_content_region_available_size;
m_viewport_size = m_content_region_available_size;
m_request_renderer_resize = true;
}
else
@@ -42,13 +42,13 @@ namespace Tetragrama::Components

if (m_is_window_hovered && m_is_window_focused)
{
Messengers::IMessenger::SendAsync<ZEngine::Components::UI::UIComponent, Messengers::GenericMessage<bool>>(
EDITOR_COMPONENT_SCENEVIEWPORT_FOCUSED, Messengers::GenericMessage<bool>{true});
Messengers::IMessenger::SendAsync<ZEngine::Layers::Layer, Messengers::GenericMessage<bool>>(
EDITOR_RENDER_LAYER_SCENE_REQUEST_FOCUS, Messengers::GenericMessage<bool>{true});
}
else
{
Messengers::IMessenger::SendAsync<ZEngine::Components::UI::UIComponent, Messengers::GenericMessage<bool>>(
EDITOR_COMPONENT_SCENEVIEWPORT_UNFOCUSED, Messengers::GenericMessage<bool>{false});
Messengers::IMessenger::SendAsync<ZEngine::Layers::Layer, Messengers::GenericMessage<bool>>(
EDITOR_RENDER_LAYER_SCENE_REQUEST_UNFOCUS, Messengers::GenericMessage<bool>{false});
}

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

auto mouse_bounded_x = static_cast<int>(mouse_position.x);
auto mouse_bounded_y = static_cast<int>(mouse_position.y);
auto message_data = std::array{mouse_bounded_x, mouse_bounded_y};
auto message_data = std::array{mouse_bounded_x, mouse_bounded_y};
Messengers::IMessenger::SendAsync<ZEngine::Components::UI::UIComponent, Messengers::ArrayValueMessage<int, 2>>(
EDITOR_COMPONENT_SCENEVIEWPORT_CLICKED, Messengers::ArrayValueMessage<int, 2>{message_data});
}
@@ -85,19 +85,8 @@ namespace Tetragrama::Components
// Scene texture representation
if (!m_scene_texture || m_refresh_texture_handle)
{
auto frame_output = GraphicRenderer::GetFrameOutput();
auto texture = frame_output->GetColorAttachmentCollection().at(0);

if (m_refresh_texture_handle)
{
VkDescriptorSet old_scene_texture = VK_NULL_HANDLE;
std::swap(m_scene_texture, old_scene_texture);
m_refresh_texture_handle = false;

VulkanDevice::EnqueueForDeletion(DeviceResourceType::DESCRIPTORSET, DirtyResource{.Handle = old_scene_texture, .Data1 = ImGUIRenderer::s_descriptor_pool});
}
auto texture_buffer = texture->GetImage2DBuffer();
m_scene_texture = ImGui_ImplVulkan_AddTexture(texture_buffer->GetSampler(), texture_buffer->GetImageViewHandle(), VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
m_scene_texture = GraphicRenderer::GetImguiFrameOutput();
m_refresh_texture_handle = false;
}

ImGui::Image(m_scene_texture, m_viewport_size, ImVec2(0, 1), ImVec2(1, 0));
1 change: 1 addition & 0 deletions Tetragrama/src/EditorCameraController.cpp
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ namespace Tetragrama
{
EditorCameraController::EditorCameraController(double distance, float yaw_angle_degree, float pitch_angle_degree) : PerspectiveCameraController(0.0f)
{
m_process_event = true;
m_controller_type = ZEngine::Controllers::CameraControllerType::PERSPECTIVE_CONTROLLER;
m_perspective_camera = ZEngine::CreateRef<PerspectiveCamera>(
m_camera_fov, m_aspect_ratio, m_camera_near, m_camera_far, ZEngine::Maths::radians(yaw_angle_degree), ZEngine::Maths::radians(pitch_angle_degree));
9 changes: 2 additions & 7 deletions Tetragrama/src/Layers/RenderLayer.cpp
Original file line number Diff line number Diff line change
@@ -20,7 +20,6 @@ namespace Tetragrama::Layers

void RenderLayer::Initialize()
{
auto current_window = GetAttachedWindow();
m_editor_camera_controller = CreateRef<EditorCameraController>(50.0, 45.f, 40.f);
GraphicScene::Initialize();

@@ -49,8 +48,6 @@ namespace Tetragrama::Layers
{
auto camera = m_editor_camera_controller->GetCamera();
GraphicRenderer::DrawScene(camera, GraphicScene::GetRawData());


}

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

std::future<void> RenderLayer::SceneRequestFocusMessageHandlerAsync(Messengers::GenericMessage<bool>& message)
{
// std::unique_lock lock(m_message_handler_mutex);
// GraphicScene::SetShouldReactToEvent(message.GetValue());
m_editor_camera_controller->ResumeEventProcessing();
co_return;
}

std::future<void> RenderLayer::SceneRequestUnfocusMessageHandlerAsync(Messengers::GenericMessage<bool>& message)
{
// std::unique_lock lock(m_message_handler_mutex);
// GraphicScene::SetShouldReactToEvent(message.GetValue());
m_editor_camera_controller->PauseEventProcessing();
co_return;
}

26 changes: 17 additions & 9 deletions ZEngine/include/ZEngine/Controllers/PerspectiveCameraController.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include <mutex>
#include <Controllers/ICameraController.h>
#include <Rendering/Cameras/PerspectiveCamera.h>
#include <Inputs/IMouseEventCallback.h>
@@ -10,32 +11,34 @@ namespace ZEngine::Controllers
class PerspectiveCameraController : public ICameraController, public Inputs::IMouseEventCallback, public Window::ICoreWindowEventCallback
{
public:
explicit PerspectiveCameraController()
:m_perspective_camera(new Rendering::Cameras::PerspectiveCamera(m_camera_fov, m_aspect_ratio, m_camera_near, m_camera_far))
explicit PerspectiveCameraController() : m_perspective_camera(new Rendering::Cameras::PerspectiveCamera(m_camera_fov, m_aspect_ratio, m_camera_near, m_camera_far))
{
m_controller_type = CameraControllerType::PERSPECTIVE_CONTROLLER;
m_position = {0.0f, 0.0f, 1.5f};
m_controller_type = CameraControllerType::PERSPECTIVE_CONTROLLER;
m_process_event = true;
}

explicit PerspectiveCameraController(Rendering::Cameras::PerspectiveCamera* const camera)
:m_perspective_camera(camera)
explicit PerspectiveCameraController(Rendering::Cameras::PerspectiveCamera* const camera) : m_perspective_camera(camera)
{
m_position = {0.0f, 0.0f, 1.5f};
m_controller_type = CameraControllerType::PERSPECTIVE_CONTROLLER;
m_process_event = true;
}

explicit PerspectiveCameraController(float aspect_ratio, Rendering::Cameras::PerspectiveCamera* const camera)
: ICameraController(aspect_ratio), m_perspective_camera(camera)
{
m_position = {0.0f, 0.0f, 1.5f};
m_controller_type = CameraControllerType::PERSPECTIVE_CONTROLLER;
m_process_event = true;
}

explicit PerspectiveCameraController(float aspect_ratio)
: ICameraController(aspect_ratio), m_perspective_camera(new Rendering::Cameras::PerspectiveCamera(m_camera_fov, m_aspect_ratio, m_camera_near, m_camera_far))
{
m_position = {0.0f, 0.0f, 1.5f};
m_controller_type = CameraControllerType::PERSPECTIVE_CONTROLLER;
m_process_event = true;
}

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

virtual void ResumeEventProcessing();
virtual void PauseEventProcessing();

public:
bool OnMouseButtonPressed(Event::MouseButtonPressedEvent&) override
{
@@ -107,10 +113,12 @@ namespace ZEngine::Controllers
}

protected:
float m_camera_fov{45.0f};
float m_camera_near{0.1f};
float m_camera_far{5000.0f};
glm::vec3 m_camera_target{0.0f, 0.0f, 0.0f};
float m_camera_fov{45.0f};
float m_camera_near{0.1f};
float m_camera_far{5000.0f};
std::recursive_mutex m_event_mutex;
bool m_process_event{true};
glm::vec3 m_camera_target{0.0f, 0.0f, 0.0f};
ZEngine::Ref<Rendering::Cameras::PerspectiveCamera> m_perspective_camera;
};
} // namespace ZEngine::Controllers
Loading