Starting implementation of UI framework

This commit is contained in:
Dynamitos
2021-01-19 15:30:00 +01:00
parent 65caae9e21
commit fb3c66cc4c
57 changed files with 381 additions and 186 deletions
-1
View File
@@ -1,7 +1,6 @@
{
"telemetry.enableTelemetry": false,
"cmake.buildDirectory": "${workspaceFolder}/bin/${buildType}",
"git.enabled": false,
"files.associations": {
"*.h": "cpp",
"*.ush": "hlsl",
-39
View File
@@ -1,39 +0,0 @@
import LightEnv;
struct VertexInput
{
float3 basePosition;
float3 position;
float3 velocity;
}
struct ViewParameter
{
float4 cameraPos_WS;
float4x4 viewMatrix;
float4x4 projectionMatrix;
PointLight light;
}
layout(set = 0, std430)
ParameterBlock<ViewParameter> gViewParams;
struct VertexToPixel
{
float4 position_CS : SV_Position;
}
VertexToPixel vertexMain(VertexInput input)
{
VertexToPixel output = (VertexToPixel)0;
float3 cameraRight_WS = float3(gViewParams.viewMatrix[0][0], gViewParams.viewMatrix[0][1], gViewParams.viewMatrix[0][2]);
float3 cameraUp_WS = float3(gViewParams.viewMatrix[1][0], gViewParams.viewMatrix[1][1], gViewParams.viewMatrix[1][2]);
float3 worldPosition = input.position + cameraRight_WS * input.basePosition.x + cameraUp_WS * input.basePosition.y;
float4 viewPosition = mul(gViewParams.viewMatrix, float4(worldPosition, 1));
output.position_CS = mul(gViewParams.projectionMatrix, viewPosition);
return output;
}
float4 fragMain(VertexToPixel input) : SV_Target
{
return float4(0, 1, 0, 0.001f);
}
+2 -3
View File
@@ -55,7 +55,7 @@ float4 fragmentMain(
float3 result = float3(0, 0, 0);
for (int i = 0; i < 5; i++)
for (int i = 0; i < gLightEnv.numDirectionalLights; i++)
{
result += gLightEnv.directionalLights[i].illuminate(materialParams, brdf, viewDir);
}
@@ -72,6 +72,5 @@ float4 fragmentMain(
result += pointLight.illuminate(materialParams, brdf, viewDir);
}
return float4(0, 1, 0, 1);
return float4(result, 1);
}
-1
View File
@@ -1,4 +1,3 @@
#pragma pack_matrix(column_major)
const static float PI = 3.1415926535897932f;
const static uint MAX_PARTICLES = 65536;
const static uint BLOCK_SIZE = 8;
+7 -3
View File
@@ -6,7 +6,7 @@
#include "MeshLoader.h"
#include "Material/Material.h"
#include "Graphics/Graphics.h"
#include "Graphics/WindowManager.h"
#include "Window/WindowManager.h"
#include <iostream>
using namespace Seele;
@@ -133,10 +133,14 @@ void AssetRegistry::registerMaterial(PMaterialAsset material)
std::ofstream AssetRegistry::internalCreateWriteStream(const std::string& relativePath, std::ios_base::openmode openmode)
{
return std::ofstream(rootFolder.generic_string().append(relativePath), openmode);
auto fullPath = rootFolder;
fullPath.append(relativePath);
return std::ofstream(fullPath.string(), openmode);
}
std::ifstream AssetRegistry::internalCreateReadStream(const std::string& relativePath, std::ios_base::openmode openmode)
{
return std::ifstream(rootFolder.generic_string().append(relativePath), openmode);
auto fullPath = rootFolder;
fullPath.append(relativePath);
return std::ifstream(fullPath.string(), openmode);
}
+14 -13
View File
@@ -44,39 +44,39 @@ void MeshLoader::loadMaterials(const aiScene* scene, Array<PMaterialAsset>& glob
matCode["profile"] = "BlinnPhong"; //TODO: other shading models
aiString texPath;
//TODO make samplers based on used textures
matCode["params"]["texSampler"] =
matCode["params"]["textureSampler"] =
{
{"type", "SamplerState"}
};
if(material->GetTexture(aiTextureType_DIFFUSE, 0, &texPath) == AI_SUCCESS)
{
std::string texFilename = std::filesystem::path(texPath.C_Str()).stem().string();
std::string texFilename = std::filesystem::path(texPath.C_Str()).replace_extension("asset").stem().string();
matCode["params"]["diffuseTexture"] =
{
{"type", "Texture2D"},
{"default", texPath.C_Str()}
{"default", texFilename}
};
matCode["code"]["baseColor"] = "return diffuseTexture.Sample(textureSampler, geometry.texCoord).xyz;";
matCode["code"]["baseColor"] = "return diffuseTexture.Sample(textureSampler, input.texCoords[0]).xyz;";
}
if(material->GetTexture(aiTextureType_SPECULAR, 0, &texPath) == AI_SUCCESS)
{
std::string texFilename = std::filesystem::path(texPath.C_Str()).stem().string();
std::string texFilename = std::filesystem::path(texPath.C_Str()).replace_extension("asset").stem().string();
matCode["params"]["specularTexture"] =
{
{"type", "Texture2D"},
{"default", texPath.C_Str()}
{"default", texFilename}
};
matCode["code"]["specular"] = "return specularTexture.Sample(textureSampler, geometry.texCoord).xyz;";
matCode["code"]["specular"] = "return specularTexture.Sample(textureSampler, input.texCoords[0]).x;";
}
if(material->GetTexture(aiTextureType_NORMALS, 0, &texPath) == AI_SUCCESS)
{
std::string texFilename = std::filesystem::path(texPath.C_Str()).stem().string();
std::string texFilename = std::filesystem::path(texPath.C_Str()).replace_extension("asset").stem().string();
matCode["params"]["normalTexture"] =
{
{"type", "Texture2D"},
{"default", texPath.C_Str()}
{"default", texFilename}
};
matCode["code"]["normal"] = "return normalTexture.Sample(textureSampler, geometry.texCoord).xyz;";
matCode["code"]["normal"] = "return normalTexture.Sample(textureSampler, input.texCoords[0]).xyz;";
}
std::string outMatFilename = matCode["name"].get<std::string>().append(".asset");
std::ofstream outMatFile = AssetRegistry::createWriteStream(outMatFilename);
@@ -198,13 +198,14 @@ void MeshLoader::convertAssimpARGB(unsigned char* dst, aiTexel* src, uint32 numP
dst[i * 4 + 3] = src[i].a;
}
}
void MeshLoader::loadTextures(const aiScene* scene, Gfx::PGraphics graphics, const std::filesystem::path& meshPath)
void MeshLoader::loadTextures(const aiScene* scene, Gfx::PGraphics graphics, const std::filesystem::path& meshDirectory)
{
for (uint32 i = 0; i < scene->mNumTextures; ++i)
{
aiTexture* tex = scene->mTextures[i];
auto texPath = std::filesystem::path(tex->mFilename.C_Str());
auto texPngPath = meshPath.parent_path().append(texPath.filename().string());
auto texPngPath = meshDirectory;
texPngPath.append(texPath.filename().string());
if(tex->mHeight == 0)
{
// already compressed, just dump it to the disk
@@ -237,7 +238,7 @@ void MeshLoader::import(const std::filesystem::path &path)
const aiScene *scene = importer.ApplyPostProcessing(aiProcess_CalcTangentSpace);
Array<PMaterialAsset> globalMaterials(scene->mNumMaterials);
loadTextures(scene, graphics, path);
loadTextures(scene, graphics, path.parent_path());
loadMaterials(scene, globalMaterials, graphics);
Array<PMesh> globalMeshes(scene->mNumMeshes);
+2 -1
View File
@@ -1,7 +1,7 @@
#include "TextureAsset.h"
#include "Graphics/GraphicsResources.h"
#include "Graphics/Graphics.h"
#include "Graphics/WindowManager.h"
#include "Window/WindowManager.h"
#include <stb_image.h>
#include <stb_image_write.h>
@@ -28,6 +28,7 @@ TextureAsset::~TextureAsset()
void TextureAsset::save()
{
//TODO: make this an actual file, not just a png wrapper
assert(false && "Editing textures is not yet supported");
}
void TextureAsset::load()
+1
View File
@@ -23,6 +23,7 @@ public:
}
private:
Gfx::PTexture texture;
friend class TextureLoader;
};
DEFINE_REF(TextureAsset);
} // namespace Seele
+3 -2
View File
@@ -28,7 +28,7 @@ void TextureLoader::importAsset(const std::filesystem::path& filePath)
PTextureAsset asset = new TextureAsset(assetFileName.replace_extension("asset").filename().generic_string());
asset->setStatus(Asset::Status::Loading);
asset->setTexture(placeholderTexture);
AssetRegistry::get().textures[filePath.string()] = asset;
AssetRegistry::get().textures[asset->getFileName()] = asset;
//futures.add(std::async(std::launch::async, [this, filePath, asset] () mutable {
Gfx::PTexture2D texture = import(filePath);
asset->setTexture(texture);
@@ -45,8 +45,9 @@ Gfx::PTexture2D TextureLoader::import(const std::filesystem::path& path)
{
int x, y, n;
unsigned char* data = stbi_load(path.string().c_str(), &x, &y, &n, 4);
TextureCreateInfo createInfo;
createInfo.format = Gfx::SE_FORMAT_R8G8B8A8_UINT;
createInfo.format = Gfx::SE_FORMAT_R8G8B8A8_SRGB;
createInfo.resourceData.data = data;
createInfo.resourceData.size = x * y * 4 * sizeof(unsigned char);
createInfo.resourceData.owner = Gfx::QueueType::DEDICATED_TRANSFER;
+2
View File
@@ -10,3 +10,5 @@ add_subdirectory(Graphics/)
add_subdirectory(Material/)
add_subdirectory(Math/)
add_subdirectory(Scene/)
add_subdirectory(UI/)
add_subdirectory(Window/)
+1 -13
View File
@@ -13,24 +13,12 @@ target_sources(SeeleEngine
RenderCore.cpp
RenderMaterial.h
RenderMaterial.cpp
RenderPath.h
RenderPath.cpp
SceneView.h
SceneView.cpp
SceneRenderPath.h
SceneRenderPath.cpp
ShaderCompiler.h
ShaderCompiler.cpp
View.h
View.cpp
VertexShaderInput.h
VertexShaderInput.cpp
StaticMeshVertexInput.h
StaticMeshVertexInput.cpp
Window.cpp
Window.h
WindowManager.h
WindowManager.cpp)
StaticMeshVertexInput.cpp)
add_subdirectory(RenderPass/)
add_subdirectory(Vulkan/)
+2
View File
@@ -502,6 +502,8 @@ public:
virtual void setKeyCallback(std::function<void(KeyCode, InputAction, KeyModifier)> callback) = 0;
virtual void setMouseMoveCallback(std::function<void(double, double)> callback) = 0;
virtual void setMouseButtonCallback(std::function<void(MouseButton, InputAction, KeyModifier)> callback) = 0;
virtual void setScrollCallback(std::function<void(double, double)> callback) = 0;
virtual void setFileCallback(std::function<void(int, const char**)> callback) = 0;
SeFormat getSwapchainFormat() const
{
return pixelFormat;
+1 -1
View File
@@ -1,5 +1,5 @@
#include "RenderCore.h"
#include "SceneView.h"
#include "Window/SceneView.h"
Seele::RenderCore::RenderCore()
{
+1 -1
View File
@@ -1,5 +1,5 @@
#pragma once
#include "WindowManager.h"
#include "Window/WindowManager.h"
#include "Scene/Scene.h"
namespace Seele
{
+3 -2
View File
@@ -1,8 +1,9 @@
#include "BasePass.h"
#include "Graphics/Graphics.h"
#include "Graphics/Window.h"
#include "Window/Window.h"
#include "Scene/Components/CameraComponent.h"
#include "Scene/Actor/CameraActor.h"
#include "Math/Vector.h"
using namespace Seele;
@@ -162,7 +163,7 @@ void BasePass::beginFrame()
viewParams.viewMatrix = source->getViewMatrix();
viewParams.projectionMatrix = source->getProjectionMatrix();
viewParams.cameraPosition = Vector4(source->getTransform().getPosition(), 0);
viewParams.cameraPosition = Vector4(source->getCameraPosition(), 0);
screenToViewParams.inverseProjectionMatrix = glm::inverse(viewParams.projectionMatrix);
screenToViewParams.screenDimensions = Vector2(static_cast<float>(viewport->getSizeX()), static_cast<float>(viewport->getSizeY()));
uniformUpdate.size = sizeof(ViewParameter);
@@ -89,6 +89,10 @@ void CmdBuffer::executeCommands(Array<Gfx::PRenderCommand> commands)
auto command = commands[i].cast<SecondaryCmdBuffer>();
command->end();
executingCommands.add(command);
for(PDescriptorSet set : command->boundDescriptors)
{
set->setCurrentlyBound(this);
}
cmdBuffers[i] = command->getHandle();
}
vkCmdExecuteCommands(handle, cmdBuffers.size(), cmdBuffers.data());
@@ -112,7 +116,7 @@ void CmdBuffer::refreshFence()
{
command->reset();
}
executingCommands.clear();
fence->reset();
}
}
@@ -92,6 +92,7 @@ public:
private:
PGraphicsPipeline pipeline;
Array<PDescriptorSet> boundDescriptors;
friend class CmdBuffer;
};
DEFINE_REF(SecondaryCmdBuffer);
@@ -208,6 +208,7 @@ void DescriptorSet::writeChanges()
if(currentlyBound != nullptr)
{
currentlyBound->getManager()->waitForCommands(currentlyBound);
currentlyBound = nullptr;
}
vkUpdateDescriptorSets(graphics->getDevice(), writeDescriptors.size(), writeDescriptors.data(), 0, nullptr);
writeDescriptors.clear();
@@ -324,10 +324,14 @@ public:
virtual void setKeyCallback(std::function<void(KeyCode, InputAction, KeyModifier)> callback) override;
virtual void setMouseMoveCallback(std::function<void(double, double)> callback) override;
virtual void setMouseButtonCallback(std::function<void(MouseButton, InputAction, KeyModifier)> callback) override;
virtual void setScrollCallback(std::function<void(double, double)> callback) override;
virtual void setFileCallback(std::function<void(int, const char**)> callback) override;
std::function<void(KeyCode, InputAction, KeyModifier)> keyCallback;
std::function<void(double, double)> mouseMoveCallback;
std::function<void(MouseButton, InputAction, KeyModifier)> mouseButtonCallback;
std::function<void(double, double)> scrollCallback;
std::function<void(int, const char**)> fileCallback;
protected:
void advanceBackBuffer();
void recreateSwapchain(const WindowCreateInfo &createInfo);
@@ -768,15 +768,7 @@ VkPipelineShaderStageCreateInfo init::PipelineShaderStageCreateInfo(VkShaderStag
#pragma warning(disable : 4100)
VkBool32 Seele::Vulkan::debugCallback(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t obj, size_t location, int32_t code, const char *layerPrefix, const char *msg, void *userDataManager)
{
if(flags & VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT)
{
//std::cerr << layerPrefix << ": " << msg << std::endl;
}
else
{
std::cerr << layerPrefix << ": " << msg << std::endl;
return VK_FALSE;
}
std::cerr << layerPrefix << ": " << msg << std::endl;
return VK_FALSE;
}
#pragma warning(default : 4100)
@@ -14,6 +14,30 @@ void glfwKeyCallback(GLFWwindow* handle, int key, int scancode, int action, int
window->keyCallback((KeyCode)key, (InputAction)action, (KeyModifier)modifier);
}
void glfwMouseMoveCallback(GLFWwindow* handle, double xpos, double ypos)
{
Window* window = (Window*)glfwGetWindowUserPointer(handle);
window->mouseMoveCallback(xpos, ypos);
}
void glfwMouseButtonCallback(GLFWwindow* handle, int button, int action, int modifier)
{
Window* window = (Window*)glfwGetWindowUserPointer(handle);
window->mouseButtonCallback((MouseButton)button, (InputAction)action, (KeyModifier)modifier);
}
void glfwScrollCallback(GLFWwindow* handle, double xoffset, double yoffset)
{
Window* window = (Window*)glfwGetWindowUserPointer(handle);
window->scrollCallback(xoffset, yoffset);
}
void glfwFileCallback(GLFWwindow* handle, int count, const char** paths)
{
Window* window = (Window*)glfwGetWindowUserPointer(handle);
window->fileCallback(count, paths);
}
Window::Window(PGraphics graphics, const WindowCreateInfo &createInfo)
: Gfx::Window(createInfo), graphics(graphics), instance(graphics->getInstance()), swapchain(VK_NULL_HANDLE), numSamples(createInfo.numSamples), pixelFormat(cast(createInfo.pixelFormat))
{
@@ -23,6 +47,10 @@ Window::Window(PGraphics graphics, const WindowCreateInfo &createInfo)
glfwSetWindowUserPointer(handle, this);
glfwSetKeyCallback(handle, &glfwKeyCallback);
glfwSetCursorPosCallback(handle, &glfwMouseMoveCallback);
glfwSetMouseButtonCallback(handle, &glfwMouseButtonCallback);
glfwSetScrollCallback(handle, &glfwScrollCallback);
glfwSetDropCallback(handle, &glfwFileCallback);
glfwCreateWindowSurface(instance, handle, nullptr, &surface);
@@ -91,6 +119,16 @@ void Window::setMouseButtonCallback(std::function<void(MouseButton, InputAction,
mouseButtonCallback = callback;
}
void Window::setScrollCallback(std::function<void(double, double)> callback)
{
scrollCallback = callback;
}
void Window::setFileCallback(std::function<void(int, const char**)> callback)
{
fileCallback = callback;
}
void Window::advanceBackBuffer()
{
VkResult res = VK_ERROR_OUT_OF_DATE_KHR;
-54
View File
@@ -1,54 +0,0 @@
#include "Window.h"
#include <functional>
Seele::Window::Window(Gfx::PWindow handle)
: gfxHandle(handle)
{
}
Seele::Window::~Window()
{
}
void Seele::Window::addView(PView view)
{
viewports.add(view);
}
void Seele::Window::beginFrame()
{
gfxHandle->beginFrame();
for (auto view : viewports)
{
view->beginFrame();
}
}
void Seele::Window::render()
{
for (auto view : viewports)
{
view->render();
}
}
void Seele::Window::endFrame()
{
gfxHandle->endFrame();
for (auto view : viewports)
{
view->endFrame();
}
}
Gfx::PWindow Seele::Window::getGfxHandle()
{
return gfxHandle;
}
void Window::setFocused(PView view)
{
focusedView = view;
auto boundFunction = std::bind(&View::keyCallback, view.getHandle(), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
gfxHandle->setKeyCallback(boundFunction);
}
+13 -3
View File
@@ -2,7 +2,7 @@
#include "Asset/AssetRegistry.h"
#include "Graphics/VertexShaderInput.h"
#include "BRDF.h"
#include "Graphics/WindowManager.h"
#include "Window/WindowManager.h"
#include <nlohmann/json.hpp>
#include <sstream>
#include <iostream>
@@ -60,8 +60,8 @@ void Material::compile()
codeStream << "struct " << materialName << ": IMaterial {" << std::endl;
uint32 uniformBufferOffset = 0;
uint32 bindingCounter = 1; // Uniform buffers are always binding 0
layout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
uint32 bindingCounter = 0; // Uniform buffers are always binding 0
uniformBinding = -1;
for(auto param : j["params"].items())
{
std::string type = param.value()["type"].get<std::string>();
@@ -70,6 +70,11 @@ void Material::compile()
{
PFloatParameter p = new FloatParameter(param.key(), uniformBufferOffset, 0);
codeStream << "layout(offset = " << uniformBufferOffset << ")";
if(uniformBinding == -1)
{
layout->addDescriptorBinding(bindingCounter, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
uniformBinding = bindingCounter++;
}
uniformBufferOffset += 4;
if(default != param.value().end())
{
@@ -81,6 +86,11 @@ void Material::compile()
{
PVectorParameter p = new VectorParameter(param.key(), uniformBufferOffset, 0);
codeStream << "layout(offset = " << uniformBufferOffset << ")";
if(uniformBinding == -1)
{
layout->addDescriptorBinding(bindingCounter, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
uniformBinding = bindingCounter++;
}
uniformBufferOffset += 12;
if(default != param.value().end())
{
+2 -2
View File
@@ -1,5 +1,5 @@
#include "MaterialAsset.h"
#include "Graphics/WindowManager.h"
#include "Window/WindowManager.h"
using namespace Seele;
@@ -41,7 +41,7 @@ void MaterialAsset::updateDescriptorData()
if(uniformUpdate.size != 0)
{
uniformBuffer->updateContents(uniformUpdate);
descriptorSet->updateBuffer(0, uniformBuffer);
descriptorSet->updateBuffer(uniformBinding, uniformBuffer);
}
descriptorSet->writeChanges();
}
+1
View File
@@ -32,6 +32,7 @@ protected:
Gfx::PUniformBuffer uniformBuffer;
uint32 uniformDataSize;
uint8* uniformData;
int32 uniformBinding;
};
DEFINE_REF(MaterialAsset);
} // namespace Seele
+1 -1
View File
@@ -1,6 +1,6 @@
#include "MaterialInstance.h"
#include "Material.h"
#include "Graphics/WindowManager.h"
#include "Window/WindowManager.h"
using namespace Seele;
+10 -5
View File
@@ -1,4 +1,5 @@
#include "Transform.h"
#include <glm/gtx/quaternion.hpp>
using namespace Seele;
@@ -45,7 +46,7 @@ Vector Transform::inverseTransformPosition(const Vector &v) const
}
Matrix4 Transform::toMatrix()
{
Matrix4 mat(1.0f);
Matrix4 mat;
mat[3][0] = position.x;
mat[3][1] = position.y;
@@ -123,6 +124,11 @@ Vector Transform::getSafeScaleReciprocal(const Vector4 &inScale, float tolerance
return safeReciprocalScale;
}
Vector Transform::transformPosition(const Vector &v) const
{
return Vector(glm::toMat4(rotation) * Vector4(v, 1));
}
Vector Transform::getPosition() const
{
return Vector(position);
@@ -158,7 +164,7 @@ bool Transform::equals(const Transform &other, float tolerance)
void Transform::multiply(Transform *outTransform, const Transform *a, const Transform *b)
{
outTransform->rotation = b->rotation * a->rotation;
outTransform->position = b->position * (b->scale * a->position) + b->position;
outTransform->position = b->rotation * (b->scale * a->position) + b->position;
outTransform->scale = b->scale * a->scale;
}
@@ -181,10 +187,9 @@ Transform &Transform::operator=(Transform &&other)
return *this;
}
Transform &Transform::operator*(const Transform &other)
Transform Transform::operator*(const Transform &other) const
{
Transform outTransform;
multiply(&outTransform, this, &other);
*this = std::move(outTransform);
return *this;
return std::move(outTransform);
}
+2 -1
View File
@@ -18,6 +18,7 @@ public:
Vector inverseTransformPosition(const Vector &v) const;
Matrix4 toMatrix();
static Vector getSafeScaleReciprocal(const Vector4 &inScale, float tolerance = 0.000000001f);
Vector transformPosition(const Vector &v) const;
Vector getPosition() const;
Quaternion getRotation() const;
@@ -28,7 +29,7 @@ public:
Transform &operator=(const Transform &other);
Transform &operator=(Transform &&other);
Transform &operator*(const Transform &other);
Transform operator*(const Transform &other) const;
private:
Vector4 position;
-1
View File
@@ -47,7 +47,6 @@ protected:
PActor parent;
Array<PActor> children;
PComponent rootComponent;
Transform transform;
};
DEFINE_REF(Actor);
} // namespace Seele
+1 -1
View File
@@ -15,7 +15,7 @@ CameraActor::CameraActor()
cameraComponent->setParent(sceneComponent);
cameraComponent->setOwner(this);
addWorldTranslation(Vector(0, 0, 50));
addWorldRotation(Vector(0, -1, 0));
addWorldRotation(Vector(0, -100, 0));
}
CameraActor::~CameraActor()
@@ -1,5 +1,7 @@
#include "CameraComponent.h"
#include "Scene/Actor/Actor.h"
#include <algorithm>
#include <iostream>
using namespace Seele;
@@ -11,7 +13,7 @@ CameraComponent::CameraComponent()
{
distance = 50;
rotationX = 0;
rotationY = -0.5f;
rotationY = -1.f;
}
CameraComponent::~CameraComponent()
@@ -21,25 +23,26 @@ CameraComponent::~CameraComponent()
void CameraComponent::mouseMove(float deltaX, float deltaY)
{
//0.01 mouse sensitivity
rotationX += deltaX/100.f;
rotationY += deltaY/100.f;
rotationX += deltaX/500.f;
rotationY += deltaY/500.f;
rotationY = std::clamp(rotationY, -1.5f, 1.5f);
addWorldRotation(Vector(rotationX, rotationY, 0));
getParent()->setWorldRotation(glm::rotate(glm::quat(), rotationX, Vector(0, 1, 0)));
getParent()->setWorldRotation(glm::rotate(glm::quat(), rotationY, Vector(1, 0, 0)));
bNeedsViewBuild = true;
}
void CameraComponent::mouseScroll(double x)
{
distance += static_cast<float>(x);
distance -= static_cast<float>(x);
distance = std::max(distance, 1.f);
addWorldTranslation(Vector(0, 0, x));
getParent()->addWorldTranslation(Vector(0, 0, x));
bNeedsViewBuild = true;
}
void CameraComponent::moveOrigin(float up)
{
originPoint.y += up;
addWorldTranslation(Vector(0, up, 0));
getParent()->addWorldTranslation(Vector(0, up, 0));
bNeedsViewBuild = true;
}
@@ -26,6 +26,14 @@ public:
}
return projectionMatrix;
}
Vector getCameraPosition()
{
if(bNeedsViewBuild)
{
buildViewMatrix();
}
return cameraPosition;
}
void mouseMove(float deltaX, float deltaY);
void mouseScroll(double x);
void moveOrigin(float up);
+12 -5
View File
@@ -6,6 +6,9 @@ using namespace Seele;
Component::Component()
{
relativeLocation = Vector(0);
relativeRotation = Vector(0);
relativeScale = Vector(1, 1, 1);
}
Component::~Component()
{
@@ -101,17 +104,17 @@ void Component::setRelativeScale(Vector scale)
}
void Component::addWorldTranslation(Vector translation)
{
const Vector newWorldLocation = translation + transform.getPosition();
const Vector newWorldLocation = translation + getTransform().getPosition();
setWorldLocation(newWorldLocation);
}
void Component::addWorldRotation(Vector rotation)
{
const Quaternion newWorldRotation = toQuaternion(rotation) * transform.getRotation();
const Quaternion newWorldRotation = toQuaternion(rotation) * getTransform().getRotation();
setWorldRotation(newWorldRotation);
}
void Component::addWorldRotation(Quaternion rotation)
{
const Quaternion newWorldRotation = rotation * transform.getRotation();
const Quaternion newWorldRotation = rotation * getTransform().getRotation();
setWorldRotation(newWorldRotation);
}
Transform Component::getTransform() const
@@ -169,9 +172,13 @@ void Component::updateComponentTransform(Quaternion relativeRotationQuat)
bComponentTransformClean = true;
Transform newTransform;
const Transform relTransform(relativeLocation, relativeRotationQuat, relativeScale);
if (parent != nullptr)
if(parent != nullptr)
{
newTransform = parent->getTransform() * relTransform;
newTransform = relTransform * parent->getTransform();
}
else
{
newTransform = relTransform;
}
bool bHasChanged = !getTransform().equals(newTransform);
if (bHasChanged)
@@ -3,6 +3,7 @@
#include "Material/MaterialInstance.h"
#include "Asset/MeshAsset.h"
#include "Graphics/VertexShaderInput.h"
#include <iostream>
using namespace Seele;
+6
View File
@@ -10,6 +10,12 @@ using namespace Seele;
Scene::Scene(Gfx::PGraphics graphics)
: graphics(graphics)
{
lightEnv.directionalLights[0].color = Vector4(1, 0, 0, 1);
lightEnv.directionalLights[0].direction = Vector4(1, 1, 0, 1);
lightEnv.directionalLights[0].intensity = Vector4(1, 1, 1, 1);
lightEnv.numDirectionalLights = 1;
lightEnv.numPointLights = 0;
srand(time(NULL));
}
Scene::~Scene()
+1 -1
View File
@@ -30,7 +30,7 @@ struct LightEnv
{
DirectionalLight directionalLights[MAX_DIRECTIONAL_LIGHTS];
PointLight pointLights[MAX_POINT_LIGHTS];
uint32 numDirectionalLgiths;
uint32 numDirectionalLights;
uint32 numPointLights;
};
+6
View File
@@ -0,0 +1,6 @@
target_sources(SeeleEngine
PRIVATE
UIComponent.h
UIComponent.cpp
UIRenderPath.h
UIRenderPath.cpp)
View File
+15
View File
@@ -0,0 +1,15 @@
#pragma once
#include "MinimalEngine.h"
namespace Seele
{
DECLARE_REF(UIRenderPath)
class UIComponent
{
public:
UIComponent(PUIRenderPath renderer);
virtual ~UIComponent();
private:
PUIRenderPath renderer;
};
DEFINE_REF(UIComponent);
} // namespace Seele
View File
+19
View File
@@ -0,0 +1,19 @@
#pragma once
#include "Window/RenderPath.h"
#include "UIComponent.h"
namespace Seele
{
class UIRenderPath : public RenderPath
{
public:
UIRenderPath();
virtual ~UIRenderPath();
virtual void beginFrame();
virtual void render();
virtual void endFrame();
private:
};
DEFINE_REF(UIRenderPath);
} // namespace Seele
+16
View File
@@ -0,0 +1,16 @@
target_sources(SeeleEngine
PRIVATE
InspectorView.h
InspectorView.cpp
RenderPath.h
RenderPath.cpp
SceneView.h
SceneView.cpp
SceneRenderPath.h
SceneRenderPath.cpp
View.h
View.cpp
Window.cpp
Window.h
WindowManager.h
WindowManager.cpp)
+26
View File
@@ -0,0 +1,26 @@
#include "InspectorView.h"
using namespace Seele;
InspectorView::InspectorView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &createInfo)
: View(graphics, window, createInfo)
{
}
InspectorView::~InspectorView()
{
}
void InspectorView::beginFrame()
{
}
void InspectorView::render()
{
}
void InspectorView::endFrame()
{
}
+19
View File
@@ -0,0 +1,19 @@
#pragma once
#include "View.h"
#include "UI/UIRenderPath.h"
namespace Seele
{
class InspectorView : public View
{
public:
InspectorView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &createInfo);
virtual ~InspectorView();
virtual void beginFrame();
virtual void render();
virtual void endFrame();
private:
PUIComponent root;
};
} // namespace Seele
@@ -1,5 +1,5 @@
#include "RenderPath.h"
#include "GraphicsResources.h"
#include "Graphics/GraphicsResources.h"
Seele::RenderPath::RenderPath(Gfx::PGraphics graphics, Gfx::PViewport target)
: graphics(graphics), target(target)
@@ -1,5 +1,5 @@
#pragma once
#include "Graphics.h"
#include "Graphics/Graphics.h"
namespace Seele
{
//A renderpath is a general Renderer for a view.
@@ -4,7 +4,6 @@
#include "Window.h"
#include "Scene/Actor/CameraActor.h"
#include "Scene/Components/CameraComponent.h"
#include <iostream>
using namespace Seele;
@@ -21,20 +20,60 @@ Seele::SceneView::~SceneView()
{
}
void SceneView::beginFrame()
{
View::beginFrame();
scene->tick(0);//TODO: update in separate thread
}
void SceneView::keyCallback(KeyCode code, InputAction action, KeyModifier modifier)
{
if(action != InputAction::RELEASE)
{
if(code == KeyCode::KEY_W)
{
activeCamera->getCameraComponent()->moveOrigin(1);
}
if(code == KeyCode::KEY_S)
{
activeCamera->getCameraComponent()->moveOrigin(-1);
}
}
}
static bool mouseDown = false;
void SceneView::mouseMoveCallback(double xPos, double yPos)
{
static double prevXPos = 0.0f, prevYPos = 0.0f;
double deltaX = xPos - prevXPos;
double deltaY = yPos - prevYPos;
double deltaX = prevXPos - xPos;
double deltaY = prevYPos - yPos;
prevXPos = xPos;
prevYPos = yPos;
activeCamera->getCameraComponent()->mouseMove(deltaX, deltaY);
if(mouseDown)
{
activeCamera->getCameraComponent()->mouseMove((float)deltaX, (float)deltaY);
}
}
void SceneView::mouseButtonCallback(MouseButton button, InputAction action, KeyModifier modifier)
{
if(button == MouseButton::MOUSE_BUTTON_1 && action != InputAction::RELEASE)
{
mouseDown = true;
}
else
{
mouseDown = false;
}
}
void SceneView::scrollCallback(double xOffset, double yOffset)
{
activeCamera->getCameraComponent()->mouseScroll(yOffset);
}
void SceneView::fileCallback(int count, const char** paths)
{
}
@@ -9,6 +9,7 @@ class SceneView : public View
public:
SceneView(Gfx::PGraphics graphics, PWindow owner, const ViewportCreateInfo &createInfo);
~SceneView();
virtual void beginFrame();
PScene getScene() const { return scene; }
private:
PScene scene;
@@ -16,6 +17,8 @@ private:
virtual void keyCallback(KeyCode code, InputAction action, KeyModifier modifier) override;
virtual void mouseMoveCallback(double xPos, double yPos) override;
virtual void mouseButtonCallback(MouseButton button, InputAction action, KeyModifier modifier) override;
virtual void scrollCallback(double xOffset, double yOffset) override;
virtual void fileCallback(int count, const char** paths) override;
};
DEFINE_REF(SceneView);
} // namespace Seele
@@ -1,3 +1,4 @@
#pragma once
#include "View.h"
#include "Window.h"
@@ -9,9 +9,9 @@ class View
public:
View(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &createInfo);
virtual ~View();
void beginFrame();
void render();
void endFrame();
virtual void beginFrame();
virtual void render();
virtual void endFrame();
void applyArea(URect area);
void setFocused();
@@ -24,6 +24,8 @@ protected:
virtual void keyCallback(KeyCode code, InputAction action, KeyModifier modifier) = 0;
virtual void mouseMoveCallback(double xPos, double yPos) = 0;
virtual void mouseButtonCallback(MouseButton button, InputAction action, KeyModifier modifier) = 0;
virtual void scrollCallback(double xOffset, double yOffset) = 0;
virtual void fileCallback(int count, const char** paths) = 0;
friend class Window;
};
+62
View File
@@ -0,0 +1,62 @@
#include "Window.h"
#include <functional>
Seele::Window::Window(Gfx::PWindow handle)
: gfxHandle(handle)
{
}
Seele::Window::~Window()
{
}
void Seele::Window::addView(PView view)
{
viewports.add(view);
}
void Seele::Window::beginFrame()
{
gfxHandle->beginFrame();
for (auto view : viewports)
{
view->beginFrame();
}
}
void Seele::Window::render()
{
for (auto view : viewports)
{
view->render();
}
}
void Seele::Window::endFrame()
{
gfxHandle->endFrame();
for (auto view : viewports)
{
view->endFrame();
}
}
Gfx::PWindow Seele::Window::getGfxHandle()
{
return gfxHandle;
}
void Window::setFocused(PView view)
{
focusedView = view;
auto keyFunction = std::bind(&View::keyCallback, view.getHandle(), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
auto mouseMoveFunction = std::bind(&View::mouseMoveCallback, view.getHandle(), std::placeholders::_1, std::placeholders::_2);
auto mouseButtonFunction = std::bind(&View::mouseButtonCallback, view.getHandle(), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
auto scrollFunction = std::bind(&View::scrollCallback, view.getHandle(), std::placeholders::_1, std::placeholders::_2);
auto fileFunction = std::bind(&View::fileCallback, view.getHandle(), std::placeholders::_1, std::placeholders::_2);
gfxHandle->setKeyCallback(keyFunction);
gfxHandle->setMouseMoveCallback(mouseMoveFunction);
gfxHandle->setMouseButtonCallback(mouseButtonFunction);
gfxHandle->setScrollCallback(scrollFunction);
gfxHandle->setFileCallback(fileFunction);
}
@@ -1,5 +1,5 @@
#pragma once
#include "GraphicsResources.h"
#include "Graphics/GraphicsResources.h"
#include "View.h"
namespace Seele
@@ -1,5 +1,5 @@
#include "WindowManager.h"
#include "Vulkan/VulkanGraphics.h"
#include "Graphics/Vulkan/VulkanGraphics.h"
Gfx::PGraphics WindowManager::graphics;
@@ -1,6 +1,6 @@
#pragma once
#include "GraphicsResources.h"
#include "Graphics.h"
#include "Graphics/GraphicsResources.h"
#include "Graphics/Graphics.h"
#include "Containers/Array.h"
#include "Window.h"
+3 -2
View File
@@ -1,5 +1,5 @@
#include "Graphics/RenderCore.h"
#include "Graphics/SceneView.h"
#include "Window/SceneView.h"
#include "Asset/AssetRegistry.h"
using namespace Seele;
int main()
@@ -22,10 +22,11 @@ int main()
PSceneView sceneView = new SceneView(core.getWindowManager()->getGraphics(), window, sceneViewInfo);
window->addView(sceneView);
sceneView->setFocused();
AssetRegistry::init("D:\\Private\\Programming\\C++\\TestSeeleProject");
AssetRegistry::init("D:\\Private\\Programming\\C++\\TestSeeleProject\\");
AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Arissa\\Arissa.fbx");
PPrimitiveComponent arissa = new PrimitiveComponent(AssetRegistry::findMesh("Arissa"));
arissa->addWorldTranslation(Vector(0, 0, 100));
arissa->setWorldScale(Vector(0.1f, 0.1f, 0.1f));
sceneView->getScene()->addPrimitiveComponent(arissa);
core.renderLoop();
core.shutdown();