Merge branch 'develop' of https://github.com/antopilo/Nuake into develop

# Conflicts:
#	Nuake/src/Resource/StaticResources.cpp
This commit is contained in:
antopilo
2024-11-19 23:23:16 -05:00
26 changed files with 842 additions and 34815 deletions

View File

@@ -119,11 +119,12 @@ Nuake::Application* Nuake::CreateApplication(int argc, char** argv)
ApplicationSpecification specification
{
.Name = "Editor",
.WindowWidth = 1100,
.WindowHeight = 630,
.WindowWidth = static_cast<uint32_t>(launchSettings.resolution.x),
.WindowHeight = static_cast<uint32_t>(launchSettings.resolution.y),
.VSync = true
};
#ifdef NK_DEBUG
specification.Name += "(DEBUG BUILD)";
#endif

View File

@@ -5,7 +5,7 @@
struct LaunchSettings
{
int32_t monitor = 1;
Nuake::Vector2 resolution = { 1920, 1080 };
Nuake::Vector2 resolution = { 1100, 630 };
std::string windowTitle = "Nuake Editor ";
std::string projectPath;
};

View File

@@ -3094,12 +3094,12 @@ namespace Nuake {
std::string selectedProject = FileDialog::SaveFile("Project file\0*.project");
if(!String::EndsWith(selectedProject, ".project"))
selectedProject += ".project";
if (selectedProject.empty()) // Hit cancel
return;
if(!String::EndsWith(selectedProject, ".project"))
selectedProject += ".project";
auto backslashSplits = String::Split(selectedProject, '\\');
auto fileName = backslashSplits[backslashSplits.size() - 1];

View File

@@ -14,8 +14,11 @@
#include <src/FileSystem/FileDialog.h>
#include <Engine.h>
#include <src/Resource/SkyResource.h>
#include <src/Resource/Prefab.h>
#include "src/Rendering/Textures/TextureManager.h"
#include <entt/entt.hpp>
#include "Tracy.hpp"
@@ -64,6 +67,12 @@ void EditorSelectionPanel::ResolveFile(Ref<Nuake::File> file)
Ref<Material> material = ResourceLoader::LoadMaterial(currentFile->GetRelativePath());
selectedResource = material;
}
if (currentFile->GetFileType() == FileType::Sky)
{
Ref<SkyResource> sky = ResourceLoader::LoadSky(currentFile->GetRelativePath());
selectedResource = sky;
}
}
void EditorSelectionPanel::Draw(EditorSelection selection, const std::string& id)
@@ -236,6 +245,199 @@ void EditorSelectionPanel::DrawFile(Ref<Nuake::File> file)
{
//Ref<Prefab> prefab = CreateRef<Prefab>(file->GetRelativePath());
//DrawPrefabPanel(prefab);
break;
}
case FileType::Sky:
{
auto sky = std::static_pointer_cast<SkyResource>(selectedResource);
std::string skyName = sky->Path;
{
UIFont boldfont = UIFont(Fonts::SubTitle);
ImGui::Text(sky->Path.c_str());
}
ImGui::SameLine();
{
UIFont boldfont = UIFont(Fonts::Icons);
if (ImGui::Button(ICON_FA_SAVE))
{
if (ResourceManager::IsResourceLoaded(sky->ID))
{
ResourceManager::RegisterResource(sky);
}
std::string fileData = sky->Serialize().dump(4);
FileSystem::BeginWriteFile(sky->Path);
FileSystem::WriteLine(fileData);
FileSystem::EndWriteFile();
}
}
int textureId = 0;
// Top
ImGui::Text("Top");
if (auto topTexture = sky->GetFaceTexture(SkyFaces::Top);
!topTexture.empty())
{
textureId = TextureManager::Get()->GetTexture(FileSystem::RelativeToAbsolute(topTexture))->GetID();
}
if (ImGui::ImageButtonEx(ImGui::GetCurrentWindow()->GetID("#skytexture1"), (void*)textureId, ImVec2(80, 80), ImVec2(0, 1), ImVec2(1, 0), ImVec4(0, 0, 0, 0), ImVec4(1, 1, 1, 1)))
{
std::string texture = FileDialog::OpenFile("*.png | *.jpg");
if (!texture.empty())
{
sky->SetTextureFace(SkyFaces::Top, FileSystem::AbsoluteToRelative(texture));
}
}
if (ImGui::BeginPopupContextWindow())
{
if (ImGui::MenuItem("Clear Texture"))
{
sky->SetTextureFace(SkyFaces::Top, "");
}
ImGui::EndPopup();
}
textureId = 0;
ImGui::Text("Bottom");
if (auto bottomTexture = sky->GetFaceTexture(SkyFaces::Bottom);
!bottomTexture.empty())
{
textureId = TextureManager::Get()->GetTexture(FileSystem::RelativeToAbsolute(bottomTexture))->GetID();
}
if (ImGui::ImageButtonEx(ImGui::GetCurrentWindow()->GetID("#skytexture2"), (void*)textureId, ImVec2(80, 80), ImVec2(0, 1), ImVec2(1, 0), ImVec4(0, 0, 0, 0), ImVec4(1, 1, 1, 1)))
{
std::string texture = FileDialog::OpenFile("*.png | *.jpg");
if (!texture.empty())
{
sky->SetTextureFace(SkyFaces::Bottom, FileSystem::AbsoluteToRelative(texture));
}
}
if (ImGui::BeginPopupContextWindow())
{
if (ImGui::MenuItem("Clear Texture"))
{
sky->SetTextureFace(SkyFaces::Bottom, "");
}
ImGui::EndPopup();
}
textureId = 0;
ImGui::Text("Left");
if (auto bottomTexture = sky->GetFaceTexture(SkyFaces::Left);
!bottomTexture.empty())
{
textureId = TextureManager::Get()->GetTexture(FileSystem::RelativeToAbsolute(bottomTexture))->GetID();
}
if (ImGui::ImageButtonEx(ImGui::GetCurrentWindow()->GetID("#skytexture3"), (void*)textureId, ImVec2(80, 80), ImVec2(0, 1), ImVec2(1, 0), ImVec4(0, 0, 0, 0), ImVec4(1, 1, 1, 1)))
{
std::string texture = FileDialog::OpenFile("*.png | *.jpg");
if (!texture.empty())
{
sky->SetTextureFace(SkyFaces::Left, FileSystem::AbsoluteToRelative(texture));
}
}
if (ImGui::BeginPopupContextWindow())
{
if (ImGui::MenuItem("Clear Texture"))
{
sky->SetTextureFace(SkyFaces::Left, "");
}
ImGui::EndPopup();
}
textureId = 0;
ImGui::Text("Right");
if (auto bottomTexture = sky->GetFaceTexture(SkyFaces::Right);
!bottomTexture.empty())
{
textureId = TextureManager::Get()->GetTexture(FileSystem::RelativeToAbsolute(bottomTexture))->GetID();
}
if (ImGui::ImageButtonEx(ImGui::GetCurrentWindow()->GetID("#skytexture4"), (void*)textureId, ImVec2(80, 80), ImVec2(0, 1), ImVec2(1, 0), ImVec4(0, 0, 0, 0), ImVec4(1, 1, 1, 1)))
{
std::string texture = FileDialog::OpenFile("*.png | *.jpg");
if (!texture.empty())
{
sky->SetTextureFace(SkyFaces::Right, FileSystem::AbsoluteToRelative(texture));
}
}
if (ImGui::BeginPopupContextWindow())
{
if (ImGui::MenuItem("Clear Texture"))
{
sky->SetTextureFace(SkyFaces::Right, "");
}
ImGui::EndPopup();
}
textureId = 0;
ImGui::Text("Front");
if (auto bottomTexture = sky->GetFaceTexture(SkyFaces::Front);
!bottomTexture.empty())
{
textureId = TextureManager::Get()->GetTexture(FileSystem::RelativeToAbsolute(bottomTexture))->GetID();
}
if (ImGui::ImageButtonEx(ImGui::GetCurrentWindow()->GetID("#skytexture5"), (void*)textureId, ImVec2(80, 80), ImVec2(0, 1), ImVec2(1, 0), ImVec4(0, 0, 0, 0), ImVec4(1, 1, 1, 1)))
{
std::string texture = FileDialog::OpenFile("*.png | *.jpg");
if (!texture.empty())
{
sky->SetTextureFace(SkyFaces::Front, FileSystem::AbsoluteToRelative(texture));
}
}
if (ImGui::BeginPopupContextWindow())
{
if (ImGui::MenuItem("Clear Texture"))
{
sky->SetTextureFace(SkyFaces::Front, "");
}
ImGui::EndPopup();
}
textureId = 0;
ImGui::Text("Back");
if (auto bottomTexture = sky->GetFaceTexture(SkyFaces::Back);
!bottomTexture.empty())
{
textureId = TextureManager::Get()->GetTexture(FileSystem::RelativeToAbsolute(bottomTexture))->GetID();
}
if (ImGui::ImageButtonEx(ImGui::GetCurrentWindow()->GetID("#skytexture6"), (void*)textureId, ImVec2(80, 80), ImVec2(0, 1), ImVec2(1, 0), ImVec4(0, 0, 0, 0), ImVec4(1, 1, 1, 1)))
{
std::string texture = FileDialog::OpenFile("*.png | *.jpg");
if (!texture.empty())
{
sky->SetTextureFace(SkyFaces::Back, FileSystem::AbsoluteToRelative(texture));
}
}
if (ImGui::BeginPopupContextWindow())
{
if (ImGui::MenuItem("Clear Texture"))
{
sky->SetTextureFace(SkyFaces::Back, "");
}
ImGui::EndPopup();
}
break;
}
}

View File

@@ -19,6 +19,7 @@
#include "../Misc/ThumbnailManager.h"
#include <Tracy.hpp>
#include <src/Resource/SkyResource.h>
namespace Nuake
{
@@ -328,6 +329,10 @@ namespace Nuake
{
dragType = "_UIFile";
}
else if (fileExtension == ".sky")
{
dragType = "_SkyFile";
}
ImGui::SetDragDropPayload(dragType.c_str(), (void*)(pathBuffer), sizeof(pathBuffer));
ImGui::Text(file->GetName().c_str());
@@ -674,6 +679,28 @@ namespace Nuake
RefreshFileBrowser();
}
}
if (ImGui::MenuItem("Sky"))
{
const std::string path = FileDialog::SaveFile("*.sky");
if (!path.empty())
{
std::string finalPath = path;
if (!String::EndsWith(path, ".sky"))
{
finalPath = path + ".sky";
}
Ref<SkyResource> sky = CreateRef<SkyResource>(FileSystem::AbsoluteToRelative(finalPath));
sky->IsEmbedded = false;
auto jsonData = sky->Serialize();
FileSystem::BeginWriteFile(finalPath, true);
FileSystem::WriteLine(jsonData.dump(4));
FileSystem::EndWriteFile();
RefreshFileBrowser();
}
}
ImGui::EndMenu();
}

View File

@@ -18,6 +18,7 @@
#include "src/Scene/Components/SphereCollider.h"
#include "src/Scene/Components/SpriteComponent.h"
#include "src/Scene/Components/UIComponent.h"
#include "src/Scene/Components/SkyComponent.h"
namespace Nuake
{
@@ -42,6 +43,7 @@ namespace Nuake
BoxColliderComponent::InternalInitializeClass();
BoneComponent::InternalInitializeClass();
AudioEmitterComponent::InternalInitializeClass();
SkyComponent::InternalInitializeClass();
}
}

View File

@@ -94,6 +94,11 @@ FileType File::GetFileType() const
return FileType::CSS;
}
if (ext == ".sky")
{
return FileType::Sky;
}
return FileType::Unknown;
}
@@ -160,6 +165,11 @@ std::string File::GetFileTypeAsString() const
return "StyleSheet";
}
if (ext == ".sky")
{
return "Sky";
}
return "File";
}

View File

@@ -20,6 +20,7 @@ namespace Nuake
Solution,
Audio,
UI,
CSS
CSS,
Sky
};
}

View File

@@ -18,7 +18,7 @@
#include "src/Rendering/Vertex.h"
#include <imgui/imgui.h>
#include <Tracy.hpp>
#include <vector>
namespace Nuake
{
uint32_t Renderer::MAX_LIGHT = 42;
@@ -49,25 +49,45 @@ namespace Nuake
std::vector<Vertex> CubeVertices
{
{ Vector3(-0.5f, -0.5f, -0.5f), Vector2(0, 0), Vector3(-1, 0, 0) },
{ Vector3( 0.5f, -0.5f, -0.5f), Vector2(1, 0), Vector3(-1, -1,0)},
{ Vector3( 0.5f, 0.5f, -0.5f), Vector2(0, 1), Vector3(-1, 0, 0) },
{ Vector3(-0.5f, 0.5f, -0.5f), Vector2(1, 1), Vector3(-1, 0, 0) },
{ Vector3(-0.5f, -0.5f, 0.5f), Vector2(0, 1), Vector3(-1, 0, 0) },
{ Vector3( 0.5f, -0.5f, 0.5f), Vector2(1, 0), Vector3(-1, 0, 0) },
{ Vector3( 0.5f, 0.5f, 0.5f), Vector2(1, 1), Vector3(-1, 0, 0) },
{ Vector3(-0.5f, 0.5f, 0.5f), Vector2(1, 1), Vector3(-1, 0, 0) }
{ Vector3(-1.0f, 1.0f, -1.0f), Vector2(0, 0), Vector3(-1, 0, 0) },
{ Vector3(-1.0f, -1.0f, -1.0f), Vector2(1, 0), Vector3(-1,-1, 0) },
{ Vector3(1.0f, -1.0f, -1.0f), Vector2(0, 1), Vector3(-1, 0, 0) },
{ Vector3(1.0f, -1.0f, -1.0f), Vector2(1, 1), Vector3(-1, 0, 0) },
{ Vector3(1.0f, 1.0f, -1.0f), Vector2(0, 1), Vector3(-1, 0, 0) },
{ Vector3(-1.0f, 1.0f, -1.0f), Vector2(1, 0), Vector3(-1, 0, 0) },
{ Vector3(-1.0f, -1.0f, 1.0f), Vector2(1, 1), Vector3(-1, 0, 0) },
{ Vector3(-1.0f, -1.0f, -1.0f), Vector2(1, 1), Vector3(-1, 0, 0) },
{ Vector3(-1.0f, 1.0f, -1.0f), Vector2(0, 0), Vector3(-1, 0, 0) },
{ Vector3(-1.0f, 1.0f, -1.0f), Vector2(1, 0), Vector3(-1,-1, 0) },
{ Vector3(-1.0f, 1.0f, 1.0f), Vector2(0, 1), Vector3(-1, 0, 0) },
{ Vector3(-1.0f, -1.0f, 1.0f), Vector2(1, 1), Vector3(-1, 0, 0) },
{ Vector3(1.0f, -1.0f, -1.0f), Vector2(0, 1), Vector3(-1, 0, 0) },
{ Vector3(1.0f, -1.0f, 1.0f), Vector2(1, 0), Vector3(-1, 0, 0) },
{ Vector3(1.0f, 1.0f, 1.0f), Vector2(1, 1), Vector3(-1, 0, 0) },
{ Vector3(1.0f, 1.0f, 1.0f), Vector2(1, 1), Vector3(-1, 0, 0) },
{ Vector3(1.0f, 1.0f, -1.0f), Vector2(0, 0), Vector3(-1, 0, 0) },
{ Vector3(1.0f, -1.0f, -1.0f), Vector2(1, 0), Vector3(-1,-1, 0) },
{ Vector3(-1.0f, -1.0f, 1.0f), Vector2(0, 1), Vector3(-1, 0, 0) },
{ Vector3(-1.0f, 1.0f, 1.0f), Vector2(1, 1), Vector3(-1, 0, 0) },
{ Vector3(1.0f, 1.0f, 1.0f), Vector2(0, 1), Vector3(-1, 0, 0) },
{ Vector3(1.0f, 1.0f, 1.0f), Vector2(1, 0), Vector3(-1, 0, 0) },
{ Vector3(1.0f, -1.0f, 1.0f), Vector2(1, 1), Vector3(-1, 0, 0) },
{ Vector3(-1.0f, -1.0f, 1.0f), Vector2(1, 1), Vector3(-1, 0, 0) },
{ Vector3(-1.0f, 1.0f, -1.0f), Vector2(0, 0), Vector3(-1, 0, 0) },
{ Vector3(1.0f, 1.0f, -1.0f), Vector2(1, 0), Vector3(-1,-1, 0) },
{ Vector3(1.0f, 1.0f, 1.0f), Vector2(0, 1), Vector3(-1, 0, 0) },
{ Vector3(1.0f, 1.0f, 1.0f), Vector2(1, 1), Vector3(-1, 0, 0) },
{ Vector3(-1.0f, 1.0f, 1.0f), Vector2(0, 1), Vector3(-1, 0, 0) },
{ Vector3(-1.0f, 1.0f, -1.0f), Vector2(1, 0), Vector3(-1, 0, 0) },
{ Vector3(-1.0f, -1.0f, -1.0f), Vector2(1, 1), Vector3(-1, 0, 0) },
{ Vector3(-1.0f, -1.0f, 1.0f), Vector2(1, 1), Vector3(-1, 0, 0) },
{ Vector3(1.0f, -1.0f, -1.0f), Vector2(0, 0), Vector3(-1, 0, 0) },
{ Vector3(1.0f, -1.0f, -1.0f), Vector2(1, 0), Vector3(-1,-1, 0) },
{ Vector3(-1.0f, -1.0f, 1.0f), Vector2(0, 1), Vector3(-1, 0, 0) },
{ Vector3(1.0f, -1.0f, 1.0f), Vector2(1, 1), Vector3(-1, 0, 0) }
};
std::vector<uint32_t> CubeIndices
{
0, 1, 3, 3, 1, 2,
1, 5, 2, 2, 5, 6,
5, 4, 6, 6, 4, 7,
4, 0, 7, 7, 0, 3,
3, 2, 7, 7, 2, 6,
4, 5, 0, 0, 5, 1
};
std::vector<uint32_t> CubeIndices;
std::vector<Vertex> QuadVertices
{
@@ -92,6 +112,12 @@ namespace Nuake
defaultMaterial->SetName("white");
MaterialManager::Get()->RegisterMaterial(defaultMaterial);
CubeIndices.reserve(36);
for (int i = 0; i < 36; i++)
{
CubeIndices.push_back(i);
}
CubeMesh = CreateRef<Mesh>();
CubeMesh->AddSurface(CubeVertices, CubeIndices);
CubeMesh->SetMaterial(defaultMaterial);
@@ -395,12 +421,9 @@ namespace Nuake
//m_DebugShader->SetUniform("u_Color", color.r, color.g, color.b, color.a);
}
void Renderer::DrawCube(TransformComponent transform, glm::vec4 color)
void Renderer::DrawCube(Matrix4 transform)
{
//glDisable(GL_DEPTH_TEST);
m_DebugShader->SetUniform("u_Model", transform.GetGlobalTransform());
m_DebugShader->SetUniform("u_Color", color.r, color.g, color.b, color.a);
ZoneScoped;
CubeMesh->Bind();
RenderCommand::DrawArrays(0, 36);
}

View File

@@ -80,7 +80,7 @@ namespace Nuake
// Debug
static void DrawLine(Vector3 start, Vector3 end, Color color, Matrix4 transform = Matrix4());
static void DrawLine(Vector3 start, Vector3 end, Vector3 color);
static void DrawCube(TransformComponent transform, glm::vec4 color);
static void DrawCube(Matrix4 transform);
static void DrawSphere(TransformComponent transform, glm::vec4 color);
static void DrawQuad(Matrix4 transform = Matrix4());
};

View File

@@ -19,6 +19,8 @@
#include <src/UI/Renderer.h>
#include "src/UI/Inspector.h"
#include <src/Scene/Components/SkyComponent.h>
#include "src/Resource/SkyResource.h"
namespace Nuake
{
@@ -1162,20 +1164,54 @@ namespace Nuake
RenderCommand::Disable(RendererEnum::DEPTH_TEST);
RenderCommand::Disable(RendererEnum::FACE_CULL);
Ref<Environment> environment = scene.GetEnvironment();
if (environment->CurrentSkyType == SkyType::ProceduralSky)
//if (environment->CurrentSkyType == SkyType::ProceduralSky)
//{
// RenderCommand::Clear();
// RenderCommand::SetClearColor(Color(0, 0, 0, 1));
// environment->ProceduralSkybox->Draw(mProjection, mView);
//}
//else if (environment->CurrentSkyType == SkyType::ClearColor)
//{
// RenderCommand::SetClearColor(environment->AmbientColor);
// RenderCommand::Clear();
// RenderCommand::SetClearColor(Color(0, 0, 0, 1));
//}
//
//RenderCommand::Enable(RendererEnum::FACE_CULL);
// Draw a cube
{
RenderCommand::Clear();
RenderCommand::SetClearColor(Color(0, 0, 0, 1));
environment->ProceduralSkybox->Draw(mProjection, mView);
}
else if (environment->CurrentSkyType == SkyType::ClearColor)
{
RenderCommand::SetClearColor(environment->AmbientColor);
RenderCommand::Clear();
RenderCommand::SetClearColor(Color(0, 0, 0, 1));
auto skyView = scene.m_Registry.view<SkyComponent>();
for (auto l : skyView)
{
SkyComponent& sky = skyView.get<SkyComponent>(l);
Shader* cubemapShader = ShaderManager::GetShader("Resources/Shaders/skybox.shader");
cubemapShader->Bind();
if (sky.SkyResourceFilePath.Exist() && sky.SkyResource == UUID(0))
{
sky.SkyResource = ResourceLoader::LoadSky(sky.SkyResourceFilePath.GetRelativePath())->ID;
}
if (ResourceManager::IsResourceLoaded(sky.SkyResource))
{
auto skyResource = ResourceManager::GetResource<SkyResource>(sky.SkyResource);
skyResource->GetCubemap()->Bind(1);
cubemapShader->SetUniform("skybox", 1);
}
cubemapShader->SetUniform("skybox", 1);
cubemapShader->SetUniforms({
{ "projection", mProjection},
{ "view", mView}
});
Renderer::DrawCube(Matrix4());
}
}
RenderCommand::Enable(RendererEnum::FACE_CULL);
Shader* shadingShader = ShaderManager::GetShader("Resources/Shaders/deferred.shader");
shadingShader->Bind();

View File

@@ -2,6 +2,9 @@
#include <glad/glad.h>
#include <iostream>
#include "HDR.h"
#include <src/Resource/SkyResource.h>
#include "src/FileSystem/FileSystem.h"
namespace Nuake
{
@@ -63,6 +66,61 @@ namespace Nuake
}
}
CubemapTexture::CubemapTexture(const SkyResource& sky)
{
m_RendererId = 0;
m_LocalBuffer = nullptr;
m_Width = 0;
m_Height = 0;
m_BPP = 0;
stbi_set_flip_vertically_on_load(0);
std::vector<std::string> faces
{
sky.GetFaceTexture(SkyFaces::Right),
sky.GetFaceTexture(SkyFaces::Left),
sky.GetFaceTexture(SkyFaces::Top),
sky.GetFaceTexture(SkyFaces::Bottom),
sky.GetFaceTexture(SkyFaces::Front),
sky.GetFaceTexture(SkyFaces::Back),
};
GLvoid* texture_data[6];
// Load file data.
for (int face = 0; face < 6; face++)
{
texture_data[face] = stbi_load(FileSystem::RelativeToAbsolute(faces[face]).c_str(), &m_Width, &m_Height, &m_BPP, 4);
}
// Create cube map.
glGenTextures(1, &m_RendererId);
glBindTexture(GL_TEXTURE_CUBE_MAP, m_RendererId);
// Set each face of the cube with image data.
for (int face = 0; face < 6; face++)
{
GLenum target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + face;
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face,
0, GL_RGBA, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture_data[face]
);
// Clear.
if (texture_data[face])
stbi_image_free(texture_data[face]);
else
std::cout << "Error: failed to load texture" << std::endl;
}
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
}
void CubemapTexture::CreateFromHDR()
{

View File

@@ -1,13 +1,17 @@
#pragma once
#include "stb_image/stb_image.h"
#include <string>
#include "src/Core/Core.h"
namespace Nuake
{
class SkyResource;
class CubemapTexture
{
public:
CubemapTexture(const std::string& path);
CubemapTexture(const SkyResource& sky);
void CreateFromHDR();
~CubemapTexture();

View File

@@ -7,7 +7,7 @@
#include "src/Rendering/Textures/Material.h"
#include "src/Resource/Model.h"
#include "src/Resource/UI.h"
#include "src/Resource/SkyResource.h"
using namespace Nuake;
Ref<Material> ResourceLoader::LoadMaterial(const std::string& path)
@@ -96,6 +96,49 @@ Ref<Model> ResourceLoader::LoadModel(const std::string& path)
return model;
}
Ref<SkyResource> ResourceLoader::LoadSky(const std::string& path)
{
const std::string FILE_NOT_FOUND = "[Resource Loader] File doesn't exists. \n ";
const std::string WRONG_EXTENSION = "[Resource Loader] Resource type mismatch file extension. \n expected: ";
const std::string SKY_EXT = ".sky";
if (path.empty())
{
Logger::Log(FILE_NOT_FOUND + path, "resource", LOG_TYPE::WARNING);
return nullptr;
}
if (!FileSystem::FileExists(path))
{
Logger::Log(FILE_NOT_FOUND + path, "resource", LOG_TYPE::WARNING);
return nullptr;
}
if (!String::EndsWith(path, SKY_EXT))
{
std::string message = WRONG_EXTENSION + SKY_EXT + " actual: " + path;
Logger::Log(message, "resource", LOG_TYPE::WARNING);
}
std::string content = FileSystem::ReadFile(path);
json j = json::parse(content);
UUID uuid = ReadUUID(j);
// Check if resource is already loaded.
if (ResourceManager::IsResourceLoaded(uuid))
{
return ResourceManager::GetResource<SkyResource>(uuid);
}
Ref<SkyResource> sky = CreateRef<SkyResource>();
sky->ID = uuid;
sky->Path = path;
sky->Deserialize(j);
ResourceManager::RegisterResource(sky);
return sky;
}
Ref<UIResource> ResourceLoader::LoadUI(const std::string& path)
{
auto uiResource = CreateRef<UIResource>(path);

View File

@@ -9,6 +9,7 @@ namespace Nuake
class Model;
class UIResource;
class File;
class SkyResource;
class ResourceLoader
{
@@ -23,6 +24,7 @@ namespace Nuake
static Ref<Material> LoadMaterial(const std::string& path);
static Ref<Model> LoadModel(const std::string& path);
static Ref<SkyResource> LoadSky(const std::string& path);
static Ref<UIResource> LoadUI(const std::string& path);
static Ref<UIResource> LoadUI(const Ref<File>& file);

View File

@@ -0,0 +1,97 @@
#include "SkyResource.h"
using namespace Nuake;
SkyResource::SkyResource(const std::string &path) :
cubemapTexture(nullptr)
{
this->Path = path;
}
void SkyResource::SetTextureFace(SkyFaces face, const std::string& path)
{
switch (face)
{
case SkyFaces::Top:
UpTexturePath = path;
break;
case SkyFaces::Bottom:
DownTexturePath = path;
break;
case SkyFaces::Left:
LeftTexturePath = path;
break;
case SkyFaces::Right:
RightTexturePath = path;
break;
case SkyFaces::Front:
FrontTexturePath = path;
break;
case SkyFaces::Back:
BackTexturePath = path;
break;
}
ResetCubemap();
}
std::string SkyResource::GetFaceTexture(SkyFaces face) const
{
switch (face)
{
case SkyFaces::Top:
return UpTexturePath;
case SkyFaces::Bottom:
return DownTexturePath;
case SkyFaces::Left:
return LeftTexturePath;
case SkyFaces::Right:
return RightTexturePath;
case SkyFaces::Front:
return FrontTexturePath;
case SkyFaces::Back:
return BackTexturePath;
}
return "";
}
Ref<CubemapTexture> SkyResource::GetCubemap()
{
if (cubemapTexture != nullptr)
{
return cubemapTexture;
}
cubemapTexture = CreateRef<CubemapTexture>(*this);
return cubemapTexture;
}
void SkyResource::ResetCubemap()
{
cubemapTexture = nullptr;
}
json SkyResource::Serialize()
{
BEGIN_SERIALIZE();
SERIALIZE_VAL(FrontTexturePath);
SERIALIZE_VAL(BackTexturePath);
SERIALIZE_VAL(UpTexturePath);
SERIALIZE_VAL(DownTexturePath);
SERIALIZE_VAL(LeftTexturePath);
SERIALIZE_VAL(RightTexturePath);
END_SERIALIZE();
}
bool SkyResource::Deserialize(const json& j)
{
DESERIALIZE_VAL(FrontTexturePath);
DESERIALIZE_VAL(BackTexturePath);
DESERIALIZE_VAL(UpTexturePath);
DESERIALIZE_VAL(DownTexturePath);
DESERIALIZE_VAL(LeftTexturePath);
DESERIALIZE_VAL(RightTexturePath);
return true;
}

View File

@@ -0,0 +1,48 @@
#pragma once
#include "src/Core/Core.h"
#include "src/Resource/Resource.h"
#include "src/Resource/Serializable.h"
#include "src/Rendering/Textures/Cubemap.h"
namespace Nuake
{
enum class SkyFaces
{
Top,
Bottom,
Left,
Right,
Front,
Back
};
class SkyResource : public Resource, ISerializable
{
public:
SkyResource(const std::string& path);
SkyResource() = default;
json Serialize() override;
bool Deserialize(const json& j) override;
void SetTextureFace(SkyFaces face, const std::string& path);
std::string GetFaceTexture(SkyFaces face) const;
Ref<CubemapTexture> GetCubemap();
private:
std::string FrontTexturePath;
std::string BackTexturePath;
std::string LeftTexturePath;
std::string RightTexturePath;
std::string UpTexturePath;
std::string DownTexturePath;
Ref<CubemapTexture> cubemapTexture;
private:
void ResetCubemap();
};
}

File diff suppressed because it is too large Load Diff

View File

@@ -8,9 +8,6 @@ namespace Nuake {
extern const std::string Resources_default_layout_ini_path;
extern unsigned int Resources_default_layout_ini_len;
extern unsigned char Resources_default_layout_ini[];
extern const std::string Resources_resources_aps_path;
extern unsigned int Resources_resources_aps_len;
extern unsigned char Resources_resources_aps[];
extern const std::string Resources_resources_rc_path;
extern unsigned int Resources_resources_rc_len;
extern unsigned char Resources_resources_rc[];

View File

@@ -24,4 +24,5 @@
#include "Components/SphereCollider.h"
#include "Components/SpriteComponent.h"
#include "Components/TransformComponent.h"
#include "Components/UIComponent.h"
#include "Components/UIComponent.h"
#include "Components/SkyComponent.h"

View File

@@ -0,0 +1,19 @@
#include "SkyComponent.h"
#include "src/FileSystem/File.h"
#include "src/FileSystem/FileSystem.h"
using namespace Nuake;
json SkyComponent::Serialize()
{
BEGIN_SERIALIZE();
SERIALIZE_RES_FILE(SkyResourceFilePath);
END_SERIALIZE();
}
bool SkyComponent::Deserialize(const json& j)
{
DESERIALIZE_RES_FILE(SkyResourceFilePath);
return true;
}

View File

@@ -0,0 +1,34 @@
#pragma once
#include "Component.h"
#include "src/Core/Core.h"
#include "src/Resource/Serializable.h"
#include "src/Resource/UUID.h"
namespace Nuake
{
class SkyComponent : public Component
{
NUAKECOMPONENT(SkyComponent, "Sky Component")
static void InitializeComponentClass()
{
BindComponentField<&SkyComponent::SkyResource>("SkyResource", "Sky Resource");
SetFlags(ComponentFieldTrait::Internal, ComponentFieldTrait::Transient);
BindComponentField<&SkyComponent::SkyResourceFilePath>("SkyResourceFilePath", "File Path");
ResourceFileRestriction("_SkyFile");
//BindComponentField<&BoxColliderComponent::IsTrigger>("IsTrigger", "Is Trigger");
//BindComponentProperty<&BoxColliderComponent::SetSize, &BoxColliderComponent::GetSize>("Size", "Size");
}
public:
SkyComponent() = default;
~SkyComponent() = default;
UUID SkyResource = UUID(0);
ResourceFile SkyResourceFilePath;
json Serialize();
bool Deserialize(const json& j);
};
}

View File

@@ -89,6 +89,8 @@ namespace Nuake
SERIALIZE_OBJECT_REF_LBL("PrefabComponent", GetComponent<PrefabComponent>())
if (HasComponent<PrefabMember>())
SERIALIZE_OBJECT_REF_LBL("PrefabMember", GetComponent<PrefabMember>())
if (HasComponent<SkyComponent>())
SERIALIZE_OBJECT_REF_LBL("SkyComponent", GetComponent<SkyComponent>())
END_SERIALIZE();
}
@@ -171,6 +173,7 @@ namespace Nuake
DESERIALIZE_COMPONENT(NetScriptComponent);
DESERIALIZE_COMPONENT(NavMeshVolumeComponent);
DESERIALIZE_COMPONENT(UIComponent);
DESERIALIZE_COMPONENT(SkyComponent);
return false;
}

View File

@@ -67,7 +67,7 @@ int Window::Init()
Logger::Log("Window creation failed", "window", CRITICAL);
return -1;
}
SetWindowIcon("resources/Images/nuake-logo.png");
glfwMakeContextCurrent(this->window);
SetVSync(false);
@@ -78,7 +78,7 @@ int Window::Init()
return -1;
}
Logger::Log("Driver detected " + std::string(((char*)glGetString(GL_VERSION))), "renderer");
Logger::Log("Driver detected " + std::string(((char*)glGetString(GL_VERSION))), "window");
if (glfwRawMouseMotionSupported())
glfwSetInputMode(this->window, GLFW_RAW_MOUSE_MOTION, GLFW_TRUE);

View File

@@ -73,7 +73,7 @@ namespace Nuake
OnWindowSetSceneDelegate& OnWindowSetScene() { return windowSetSceneDelegate; }
private:
const std::string DEFAULT_TITLE = "Untitled Window";
const std::string DEFAULT_TITLE = "Nuake Engine";
const uint32_t DEFAULT_WIDTH = 1280;
const uint32_t DEFAULT_HEIGHT = 720;

View File

@@ -96,87 +96,6 @@ vec3 ImportanceSampleGGX(vec2 Xi, vec3 N, float roughness)
void main()
{
if (prefilter == 1) {
vec3 N = normalize(LocalPos);
vec3 R = N;
vec3 V = R;
const uint SAMPLE_COUNT = 2048;
float totalWeight = 0.0;
vec3 prefilteredColor = vec3(0.0);
for (uint i = 0u; i < SAMPLE_COUNT; ++i)
{
vec2 Xi = Hammersley(i, SAMPLE_COUNT);
vec3 H = ImportanceSampleGGX(Xi, N, roughness);
vec3 L = normalize(2.0 * dot(V, H) * H - V);
float NdotL = max(dot(N, L), 0.0);
if (NdotL > 0.0)
{
// sample from the environment's mip level based on roughness/pdf
float D = DistributionGGX(N, H, roughness);
float NdotH = max(dot(N, H), 0.0);
float HdotV = max(dot(H, V), 0.0);
float pdf = D * NdotH / (4.0 * HdotV) + 0.0001;
float resolution = 1024.0; // resolution of source cubemap (per face)
float saTexel = 4.0 * PI / (6.0 * resolution * resolution);
float saSample = 1.0 / (float(SAMPLE_COUNT) * pdf + 0.0001);
float mipLevel = roughness == 0.0 ? 0.0 : 0.5 * log2(saSample / saTexel);
prefilteredColor += textureLod(skybox, L, mipLevel).rgb * NdotL;
totalWeight += NdotL;
}
}
prefilteredColor = prefilteredColor / totalWeight;
FragColor = vec4(prefilteredColor, 1.0);
}
else if (convulate == 1) {
// The world vector acts as the normal of a tangent surface
// from the origin, aligned to WorldPos. Given this normal, calculate all
// incoming radiance of the environment. The result of this radiance
// is the radiance of light coming from -Normal direction, which is what
// we use in the PBR shader to sample irradiance.
vec3 N = normalize(LocalPos);
vec3 irradiance = vec3(0.0);
// tangent space calculation from origin point
vec3 up = vec3(0.0, 1.0, 0.0);
vec3 right = cross(up, N);
up = cross(N, right);
float sampleDelta = 0.025;
float nrSamples = 0.0;
for (float phi = 0.0; phi < 2.0 * PI; phi += sampleDelta)
{
for (float theta = 0.0; theta < 0.5 * PI; theta += sampleDelta)
{
// spherical to cartesian (in tangent space)
vec3 tangentSample = vec3(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta));
// tangent space to world
vec3 sampleVec = tangentSample.x * right + tangentSample.y * up + tangentSample.z * N;
irradiance += texture(skybox, sampleVec).rgb * cos(theta) * sin(theta);
nrSamples++;
}
}
irradiance = PI * irradiance * (1.0 / float(nrSamples));
FragColor = vec4(irradiance, 1.0);
}
else {
if (isHDR == 1) {
vec2 uv = SampleSphericalMap(normalize(LocalPos)); // make sure to normalize localPos
vec3 color = texture(equirectangularMap, uv).rgb;
FragColor = vec4(color, 1.0);
}
else {
vec4 sky = textureLod(skybox, LocalPos, 1.2); //texture(skybox, TexCoords);
FragColor = sky;
}
}
vec4 sky = texture(skybox, normalize(TexCoords));
FragColor = sky;
}