Skip to content
Merged
Show file tree
Hide file tree
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 added LNApp/Assets/Textures/HDRIs/pisa.hdr
Binary file not shown.
3 changes: 2 additions & 1 deletion LNApp/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ project "LNApp"
}

filter "configurations:Dist"
kind "WindowedApp"
runtime "Release"
symbols "Off"
optimize "On"
defines "NDEBUG"
defines "NDEBUG"
64 changes: 22 additions & 42 deletions LNApp/src/AppLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void AppLayer::SkyboxPass::OnBind(lne::FrameGraph* frameGraph, lne::FrameGraphNo
techDesc.Passes.push_back(passDesc);
SafePtr technique = renderer.CreateOrGetTechnique(techDesc);

m_MaterialV2 = lnnew Material(technique);
m_Material = lnnew Material(technique);

for (FrameGraphResourceHandle resourceHandle : node->InputResources)
{
Expand All @@ -72,11 +72,11 @@ void AppLayer::SkyboxPass::Execute(vk::CommandBuffer cmdBuffer, lne::WorldRender
if (m_Texture != worldRenderer->GetEnvironment()->SkyboxTexture)
{
m_Texture = worldRenderer->GetEnvironment()->SkyboxTexture;
m_MaterialV2->SetTexture("tCubeAlbedo", m_Texture);
m_Material->SetTexture("tCubeAlbedo", m_Texture);
}

lne::Renderer& renderer = lne::ApplicationBase::GetRenderer();
renderer.DrawFullscreenQuad(cmdBuffer, m_MaterialV2, GetID());
renderer.DrawFullscreenQuad(cmdBuffer, m_Material, GetID());
}

void AppLayer::SkyboxPass::PostExecute(vk::CommandBuffer cmdBuffer, lne::FrameGraph* frameGraph, lne::FrameGraphNode* node)
Expand Down Expand Up @@ -135,7 +135,7 @@ void AppLayer::ToneMappingPass::OnBind(lne::FrameGraph* frameGraph, lne::FrameGr
techDesc.Passes.push_back(passDesc);
SafePtr technique = renderer.CreateOrGetTechnique(techDesc);

SafePtr<Material> mat = lnnew Material(technique);
m_Material = lnnew Material(technique);

for (FrameGraphResourceHandle resourceHandle : node->OutputResources)
{
Expand All @@ -154,9 +154,18 @@ void AppLayer::ToneMappingPass::OnBind(lne::FrameGraph* frameGraph, lne::FrameGr
{
lne::FrameGraphResource* resource = frameGraph->GetResource(handle);
lne::SafePtr<lne::Texture> sceneTexture = resource->Resource.GetAs<lne::Texture>();
mat->SetTexture("tSceneTexture", sceneTexture);
m_Material->SetTexture("tSceneTexture", sceneTexture);
}
}

void AppLayer::ToneMappingPass::OnResize(lne::FrameGraph* frameGraph, lne::FrameGraphNode* node)
{
for (lne::FrameGraphResourceHandle handle : node->InputResources)
{
lne::FrameGraphResource* resource = frameGraph->GetResource(handle);
lne::SafePtr<lne::Texture> sceneTexture = resource->Resource.GetAs<lne::Texture>();
m_Material->SetTexture("tSceneTexture", sceneTexture);
}
m_MaterialV2 = mat;
}

void AppLayer::ToneMappingPass::Execute(vk::CommandBuffer cmdBuffer, class lne::WorldRenderer* worldRenderer, lne::FrameGraph* frameGraph, lne::FrameGraphNode* node)
Expand All @@ -168,7 +177,7 @@ void AppLayer::ToneMappingPass::Execute(vk::CommandBuffer cmdBuffer, class lne::
lne::FrameGraphResource* resource = frameGraph->GetResource(handle);
lne::SafePtr<lne::Texture> sceneTexture = resource->Resource.GetAs<lne::Texture>();
}
renderer.DrawFullscreenQuad(cmdBuffer, m_MaterialV2, GetID());
renderer.DrawFullscreenQuad(cmdBuffer, m_Material, GetID());
}

void AppLayer::ToneMappingPass::PostExecute(vk::CommandBuffer cmdBuffer, lne::FrameGraph* frameGraph, lne::FrameGraphNode* node)
Expand Down Expand Up @@ -219,39 +228,10 @@ void AppLayer::OnAttach()

SafePtr uvChecker = renderer.CreateTexture(lne::ApplicationBase::GetAssetsPath() + "Textures\\UVChecker.png");

SafePtr gbufferEffect = renderer.CreateOrGetEffect(ApplicationBase::GetAssetsPath() + "Engine\\Shaders\\GBuffer.glsl");
SafePtr forwardTransparentEffect = renderer.CreateOrGetEffect(ApplicationBase::GetAssetsPath() + "Engine\\Shaders\\ForwardTransparent.glsl");
SafePtr depthPrePassEffect = renderer.CreateOrGetEffect(ApplicationBase::GetAssetsPath() + "Engine\\Shaders\\DepthPrePass.glsl");

GfxTechniqueDesc techDesc{};
techDesc.Name = "DefaultMeshOpaque";
techDesc.TechniqueState.Cull = ECullMode::Back;
techDesc.TechniqueState.Fill = EFillMode::Solid;
techDesc.TechniqueState.Transparency = TransparencyMode::eOpaque;
techDesc.TechniqueState.DepthMode = DepthMode::eReadWrite;

PassBindingDesc passDesc{};
passDesc.PassName = "GBufferPass";
passDesc.PassEffect = gbufferEffect;
techDesc.Passes.push_back(passDesc);
passDesc.PassName = "DepthPrePass";
passDesc.PassEffect = depthPrePassEffect;
techDesc.Passes.push_back(passDesc);
m_OpaqueTechnique = renderer.CreateOrGetTechnique(techDesc);

techDesc.Name = "DefaultMeshTransparent";
techDesc.TechniqueState.Cull = ECullMode::Back;
techDesc.TechniqueState.Fill = EFillMode::Solid;
techDesc.TechniqueState.Transparency = TransparencyMode::eTransparent;
techDesc.TechniqueState.DepthMode = DepthMode::eReadOnly;
techDesc.Passes.clear();
passDesc.PassName = "TransparentForwardPass";
passDesc.PassEffect = forwardTransparentEffect;
techDesc.Passes.push_back(passDesc);
m_TransparentTechnique = renderer.CreateOrGetTechnique(techDesc);
SafePtr opaqueTechnique = renderer.GetTechnique("DefaultMeshOpaque");

m_BasicMaterial = lnnew Material(m_OpaqueTechnique);
m_BasicMaterial2 = lnnew Material(m_OpaqueTechnique);
m_BasicMaterial = lnnew Material(opaqueTechnique);
m_BasicMaterial2 = lnnew Material(opaqueTechnique);

m_BasicMaterial->SetProperty("uColor", glm::vec4(1.0f, 1.0f, 1.0f, 1.0f));
m_BasicMaterial->SetTexture("tAlbedo", uvChecker);
Expand Down Expand Up @@ -284,8 +264,8 @@ void AppLayer::OnAttach()
cubeMesh->SetMaterial(m_BasicMaterial, 0);
SafePtr sphereMesh = StaticMesh::GenerateUVSphere(1.0f, 32, 32);
sphereMesh->SetMaterial(m_BasicMaterial2, 0);
modelMeshComponent.Mesh = lnnew StaticMesh(ApplicationBase::GetAssetsPath() + "Models\\gltf\\Models\\Sponza\\glTF\\Sponza.gltf", m_OpaqueTechnique, m_TransparentTechnique);
modelSphereMeshComponent.Mesh = lnnew StaticMesh(ApplicationBase::GetAssetsPath() + "Models\\gltf\\Models\\SpecularTest\\glTF\\SpecularTest.gltf", m_OpaqueTechnique, m_TransparentTechnique);
modelMeshComponent.Mesh = lnnew StaticMesh(ApplicationBase::GetAssetsPath() + "Models\\gltf\\Models\\Sponza\\glTF\\Sponza.gltf");
modelSphereMeshComponent.Mesh = lnnew StaticMesh(ApplicationBase::GetAssetsPath() + "Models\\gltf\\Models\\MetalRoughSpheres\\glTF\\MetalRoughSpheres.gltf");

cubeMeshComponent.Mesh = cubeMesh;
sphereMeshComponent.Mesh = sphereMesh;
Expand Down Expand Up @@ -334,7 +314,7 @@ void AppLayer::OnAttach()
m_CameraTarget.Rotation = cameraTransform.EulerAngles;
cameraComponent.UpdateView(cameraTransform);

m_WorldRenderer->SetEnvironmentMap(ApplicationBase::GetAssetsPath() + "Textures\\HDRIs\\OvercastIndustrialCourtyard.hdr");
m_WorldRenderer->SetEnvironmentMap(ApplicationBase::GetAssetsPath() + "Textures\\HDRIs\\pisa.hdr");
m_WorldRenderer->SetSunLightDirection(m_LightDirection);
m_WorldRenderer->SetAmbientLight(m_AmbientLight);
}
Expand Down
8 changes: 3 additions & 5 deletions LNApp/src/AppLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class AppLayer final : public lne::Layer
void PostExecute(vk::CommandBuffer cmdBuffer, lne::FrameGraph* frameGraph, lne::FrameGraphNode* node) override;
void OnImGuiRender() override;
private:
lne::SafePtr<lne::Material> m_MaterialV2{};
lne::SafePtr<lne::Material> m_Material{};

lne::SafePtr<lne::Texture> m_Texture{};

Expand All @@ -67,11 +67,12 @@ class AppLayer final : public lne::Layer
m_Name = "ToneMappingPass";
}
void OnBind(lne::FrameGraph* frameGraph, lne::FrameGraphNode* node) override;
void OnResize(lne::FrameGraph* frameGraph, lne::FrameGraphNode* node) override;
void Execute(vk::CommandBuffer cmdBuffer, class lne::WorldRenderer* worldRenderer, lne::FrameGraph* frameGraph, lne::FrameGraphNode* node) override;
void PostExecute(vk::CommandBuffer cmdBuffer, lne::FrameGraph* frameGraph, lne::FrameGraphNode* node) override;
void OnImGuiRender() override;
private:
lne::SafePtr<lne::Material> m_MaterialV2{};
lne::SafePtr<lne::Material> m_Material{};
lne::SafePtr<lne::Texture> m_DebugTexture{};
bool m_IsDebugOpen{ false };
};
Expand All @@ -98,9 +99,6 @@ class AppLayer final : public lne::Layer
lne::SafePtr<lne::Material> m_BasicMaterial{};
lne::SafePtr<lne::Material> m_BasicMaterial2{};

lne::SafePtr<lne::GfxTechnique> m_OpaqueTechnique{};
lne::SafePtr<lne::GfxTechnique> m_TransparentTechnique{};

struct CameraTarget
{
glm::vec3 Position;
Expand Down
17 changes: 13 additions & 4 deletions LNEngine/Assets/Shaders/ForwardTransparent.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,16 @@ void main()

mat3 normalMatrix = transpose(inverse(mat3(model)));
oNormal = normalize(normalMatrix * vertexBuffer.vertices[currentIndex].normal);
oTangent = normalize(normalMatrix * vertexBuffer.vertices[currentIndex].tangent.xyz);
oBitangent = vertexBuffer.vertices[currentIndex].tangent.w * cross(oNormal, oTangent); // tangent.w = normal space handedness
if (vertexBuffer.vertices[currentIndex].tangent.xyz == vec3(0.0))
{
oTangent = vec3(0.0);
oBitangent = vec3(0.0);
}
else
{
oTangent = normalize(normalMatrix * vertexBuffer.vertices[currentIndex].tangent.xyz);
oBitangent = vertexBuffer.vertices[currentIndex].tangent.w * cross(oNormal, oTangent); // tangent.w = normal space handedness
}
}

#endif
Expand Down Expand Up @@ -114,14 +122,15 @@ void main()
roughness = texture(globalTextures[nonuniformEXT(mat.tRoughness)], iUVs).y;

vec3 normal = normalize(iNormal);
if (mat.tNormal != 0)
if (mat.tNormal != 0 && iTangent != vec3(0.0))
{
vec3 tangent = normalize(iTangent - normal * dot(normal, iTangent));
vec3 bitangent = normalize(iBitangent);

mat3 TBN = mat3(tangent, bitangent, normal);
normal = vec3(TBN * (texture(globalTextures[nonuniformEXT(mat.tNormal)], iUVs).xyz * 2.0 - vec3(1.0)));
normal = vec4(TBN * (texture(globalTextures[nonuniformEXT(mat.tNormal)], iUVs).xyz * 2.0 - vec3(1.0)), 1.0).xyz;
}

vec3 viewDir = normalize(uEyePos - iWorldPos);
vec3 lightDir = normalize(-uSunDir);
vec3 lightColor = length(uSunDir) * vec3(1.0);
Expand Down
1 change: 0 additions & 1 deletion LNEngine/src/Engine/Core/ApplicationBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ void ApplicationBase::Run()
LNE_PROFILE_SCOPE("Frame")
m_Clock.Tick();

m_Window->BeginFrame();
m_Renderer->BeginFrame();

for (auto layer : m_LayerStack)
Expand Down
10 changes: 8 additions & 2 deletions LNEngine/src/Engine/Core/Utils/Profiling.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
#if defined(TRACY_ENABLE) && defined(LNE_DEBUG)
# define LNE_PROFILE_SCOPE(name) ZoneScopedN(name);
# define LNE_PROFILE_SCOPE_C(name, color) ZoneScopedNC(name, color);
# define LNE_PROFILE_FUNCTION() LNE_PROFILE_SCOPE(__FUNCSIG__);
# define LNE_PROFILE_FUNCTION_C(color) LNE_PROFILE_SCOPE_C(__FUNCSIG__, color);
# define LNE_PROFILE_FUNCTION() LNE_PROFILE_SCOPE(__FUNCTION__);
# define LNE_PROFILE_FUNCTION_C(color) LNE_PROFILE_SCOPE_C(__FUNCTION__, color);
# define LNE_PROFILE_SCOPE_STR(name) ZoneScoped; ZoneName(name.c_str(), name.size());
# define LNE_PROFILE_SCOPE_STR_C(name, color) ZoneScoped; ZoneName(name.c_str(), name.size()); ZoneColor(color);
# define LNE_PROFILE_FRAME FrameMark;
# define SET_PROFILING_THREAD_NAME(name) tracy::SetThreadName(name);
#else
# define LNE_PROFILE_SCOPE(name)
# define LNE_PROFILE_SCOPE_C(name, color)
# define LNE_PROFILE_FUNCTION()
# define LNE_PROFILE_FUNCTION_C(color)
# define LNE_PROFILE_SCOPE_STR(name)
# define LNE_PROFILE_SCOPE_STR_C(name, color)
# define LNE_PROFILE_FRAME
# define SET_PROFILING_THREAD_NAME(name)
#endif
25 changes: 11 additions & 14 deletions LNEngine/src/Engine/Core/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "ApplicationBase.h"
#include "Utils/_Defines.h"
#include "Utils/Log.h"
#include "Utils/Profiling.h"
#include "Events/WindowEvents.h"
#include "Events/KeyboardEvents.h"
#include "Events/MouseEvents.h"
Expand All @@ -13,10 +14,8 @@

namespace lne
{
/**
* \brief Creates a window with the specified settings
* \param settings specifies the window settings
*/
#define PROFILING_COLOR 0x7171AB

Window::Window(WindowSettings&& settings)
: m_Settings{std::move(settings)}
{
Expand Down Expand Up @@ -52,7 +51,7 @@ Window::Window(WindowSettings&& settings)
m_GfxContext.Reset(lnnew GfxContext(surface));
m_GfxContext->InitDefaultResources();

m_SwapChain.Reset(lnnew Swapchain(m_GfxContext, surface));
m_Swapchain.Reset(lnnew Swapchain(m_GfxContext, surface));

ApplicationBase::GetEventHub().RegisterListener<WindowResizeEvent>(this, &Window::OnWindowResize);
}
Expand All @@ -66,31 +65,29 @@ Window::~Window()

lne::Framebuffer& Window::GetFramebuffer(uint32_t index) const
{
return m_SwapChain->GetFramebuffer(index);
return m_Swapchain->GetFramebuffer(index);
}

void Window::PollEvents() const
{
LNE_PROFILE_FUNCTION_C(PROFILING_COLOR);
glfwPollEvents();
}

void Window::BeginFrame() const
{
//m_SwapChain->BeginFrame();
}

void Window::Present()
{
bool hasPresented = m_SwapChain->Present();
if (hasPresented == false || m_IsDirty == true)
LNE_PROFILE_FUNCTION_C(PROFILING_COLOR);
m_Swapchain->Present();
if (m_IsDirty == true || m_Swapchain->IsDirty())
{
while (m_Settings.Width == 0 || m_Settings.Height == 0)
{
LNE_INFO("Waiting for window to be resized");
glfwWaitEvents();
}
LNE_INFO("Recreating swapchain");
m_SwapChain->CreateSwapchain();
m_Swapchain->CreateSwapchain();
m_Swapchain->ResetDirty();

for (auto&[_, callback] : m_SwapchainRecreateCallback)
callback();
Expand Down
44 changes: 22 additions & 22 deletions LNEngine/src/Engine/Core/Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,38 @@ class Window final
Window(WindowSettings&& settings);
~Window();

[[nodiscard]] SafePtr<class GfxContext> GetGfxContext() const { return m_GfxContext; }
[[nodiscard]] SafePtr<class Swapchain> GetSwapchain() const { return m_SwapChain; }
[[nodiscard]] struct GLFWwindow* GetHandle() const { return m_Handle; }
[[nodiscard]] SafePtr<class GfxContext> GetGfxContext() const { return m_GfxContext; }
[[nodiscard]] SafePtr<class Swapchain> GetSwapchain() const { return m_Swapchain; }
[[nodiscard]] struct GLFWwindow* GetHandle() const { return m_Handle; }

[[nodiscard]] uint32_t GetWidth() const { return m_Settings.Width; }
[[nodiscard]] uint32_t GetHeight() const { return m_Settings.Height; }
[[nodiscard]] const WindowSettings& GetSettings() const { return m_Settings; }
[[nodiscard]] uint32_t GetWidth() const { return m_Settings.Width; }
[[nodiscard]] uint32_t GetHeight() const { return m_Settings.Height; }
[[nodiscard]] const WindowSettings& GetSettings() const { return m_Settings; }

[[nodiscard]] Framebuffer& GetFramebuffer(uint32_t index) const;
[[nodiscard]] Framebuffer& GetFramebuffer(uint32_t index) const;

void PollEvents() const;
void BeginFrame() const;
void Present();
[[nodiscard]] bool ShouldClose() const;
void PollEvents() const;
void Present();
[[nodiscard]] bool ShouldClose() const;

void AddSwapchainRecreateCallback(void* key, std::function<void()> callback);
void RemoveSwapchainRecreateCallback(void* key);
void AddSwapchainRecreateCallback(void* key,
std::function<void()> callback);
void RemoveSwapchainRecreateCallback(void* key);

private:
struct GLFWwindow* m_Handle;
WindowSettings m_Settings;
bool m_IsDirty{ false };
struct GLFWwindow* m_Handle;
WindowSettings m_Settings;
bool m_IsDirty{ false };

std::unique_ptr<class InputManager> m_InputManager;
SafePtr<class Swapchain> m_SwapChain;
SafePtr<class GfxContext> m_GfxContext;
std::unique_ptr<class InputManager> m_InputManager;
SafePtr<class Swapchain> m_Swapchain;
SafePtr<class GfxContext> m_GfxContext;

std::map<void*, std::function<void()>> m_SwapchainRecreateCallback;
std::map<void*, std::function<void()>> m_SwapchainRecreateCallback;

private:
void InitEventCallbacks();
bool OnWindowResize(class WindowResizeEvent& e);
void InitEventCallbacks();
bool OnWindowResize(class WindowResizeEvent& e);

friend class ApplicationBase;
};
Expand Down
2 changes: 2 additions & 0 deletions LNEngine/src/Engine/Graphics/DynamicDescriptorAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ vk::DescriptorSet DynamicDescriptorAllocator::Allocate(vk::DescriptorSetLayout l
}
catch (std::exception& e)
{
(void)e;
LNE_WARN("DynamicDescriptorAllocator: {} \n Exception: {}", m_DebugName, e.what());
AllocateNewPool();
poolIdx = m_FreePoolIndices.back();
Expand Down Expand Up @@ -146,6 +147,7 @@ vk::DescriptorSet DynamicDescriptorAllocator::Allocate(vk::DescriptorSetLayout l
}
catch (std::exception& e)
{
(void)e;
LNE_WARN("DynamicDescriptorAllocator: {} \n Exception: {}", m_DebugName, e.what());
AllocateNewPool();
poolIdx = m_FreePoolIndices.back();
Expand Down
Loading