From 798803cf819fc2749830ea77d58f363b0341006e Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Fri, 18 Nov 2022 22:03:21 +0800 Subject: [PATCH] UI WIP --- Assets/Materials/UIMat.shmat | 8 ++ Assets/Materials/UIMat.shmat.shmeta | 3 + Assets/Models/Quad.gltf | 104 ++++++++++++++++++ Assets/Models/Quad.shmodel | Bin 0 -> 224 bytes Assets/Models/Quad.shmodel.shmeta | 7 ++ Assets/Shaders/DebugDraw_VS.glsl | 3 + Assets/Shaders/TestCube_VS.glsl | 3 +- Assets/Shaders/TestCube_VS.shshaderb | Bin 3689 -> 3781 bytes Assets/Shaders/Text_VS.glsl | 3 +- Assets/Shaders/Text_VS.shshaderb | Bin 4785 -> 4877 bytes Assets/Shaders/UI_FS.glsl | 48 ++++++++ Assets/Shaders/UI_FS.shshaderb | Bin 0 -> 1877 bytes Assets/Shaders/UI_FS.shshaderb.shmeta | 3 + Assets/Shaders/UI_VS.glsl | 64 +++++++++++ Assets/Shaders/UI_VS.shshaderb | Bin 0 -> 3797 bytes Assets/Shaders/UI_VS.shshaderb.shmeta | 3 + .../src/Editor/DragDrop/SHDragDrop.hpp | 2 +- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 7 +- .../MiddleEnd/Interface/SHRenderer.cpp | 9 +- .../Graphics/MiddleEnd/Interface/SHRenderer.h | 5 +- .../MiddleEnd/TextRendering/SHFont.cpp | 2 +- 21 files changed, 263 insertions(+), 11 deletions(-) create mode 100644 Assets/Materials/UIMat.shmat create mode 100644 Assets/Materials/UIMat.shmat.shmeta create mode 100644 Assets/Models/Quad.gltf create mode 100644 Assets/Models/Quad.shmodel create mode 100644 Assets/Models/Quad.shmodel.shmeta create mode 100644 Assets/Shaders/UI_FS.glsl create mode 100644 Assets/Shaders/UI_FS.shshaderb create mode 100644 Assets/Shaders/UI_FS.shshaderb.shmeta create mode 100644 Assets/Shaders/UI_VS.glsl create mode 100644 Assets/Shaders/UI_VS.shshaderb create mode 100644 Assets/Shaders/UI_VS.shshaderb.shmeta diff --git a/Assets/Materials/UIMat.shmat b/Assets/Materials/UIMat.shmat new file mode 100644 index 00000000..b31fed2e --- /dev/null +++ b/Assets/Materials/UIMat.shmat @@ -0,0 +1,8 @@ +- VertexShader: 46580970 + FragmentShader: 35983630 + SubPass: G-Buffer Write + Properties: + data.color: {x: 1, y: 1, z: 1, w: 1} + data.textureIndex: 0 + data.alpha: 0 + data.beta: {x: 1, y: 1, z: 1} \ No newline at end of file diff --git a/Assets/Materials/UIMat.shmat.shmeta b/Assets/Materials/UIMat.shmat.shmeta new file mode 100644 index 00000000..2a2d2572 --- /dev/null +++ b/Assets/Materials/UIMat.shmat.shmeta @@ -0,0 +1,3 @@ +Name: UIMat +ID: 129340704 +Type: 7 diff --git a/Assets/Models/Quad.gltf b/Assets/Models/Quad.gltf new file mode 100644 index 00000000..493c164d --- /dev/null +++ b/Assets/Models/Quad.gltf @@ -0,0 +1,104 @@ +{ + "asset" : { + "generator" : "Khronos glTF Blender I/O v3.3.27", + "version" : "2.0" + }, + "scene" : 0, + "scenes" : [ + { + "name" : "Scene", + "nodes" : [ + 0 + ] + } + ], + "nodes" : [ + { + "mesh" : 0, + "name" : "Quad" + } + ], + "meshes" : [ + { + "name" : "Plane", + "primitives" : [ + { + "attributes" : { + "POSITION" : 0, + "NORMAL" : 1, + "TEXCOORD_0" : 2 + }, + "indices" : 3 + } + ] + } + ], + "accessors" : [ + { + "bufferView" : 0, + "componentType" : 5126, + "count" : 4, + "max" : [ + 0.5, + 0.5, + 3.774895063202166e-08 + ], + "min" : [ + -0.5, + -0.5, + -3.774895063202166e-08 + ], + "type" : "VEC3" + }, + { + "bufferView" : 1, + "componentType" : 5126, + "count" : 4, + "type" : "VEC3" + }, + { + "bufferView" : 2, + "componentType" : 5126, + "count" : 4, + "type" : "VEC2" + }, + { + "bufferView" : 3, + "componentType" : 5123, + "count" : 6, + "type" : "SCALAR" + } + ], + "bufferViews" : [ + { + "buffer" : 0, + "byteLength" : 48, + "byteOffset" : 0, + "target" : 34962 + }, + { + "buffer" : 0, + "byteLength" : 48, + "byteOffset" : 48, + "target" : 34962 + }, + { + "buffer" : 0, + "byteLength" : 32, + "byteOffset" : 96, + "target" : 34962 + }, + { + "buffer" : 0, + "byteLength" : 12, + "byteOffset" : 128, + "target" : 34963 + } + ], + "buffers" : [ + { + "byteLength" : 140, + "uri" : "data:application/octet-stream;base64,AAAAvwAAAL9pISIzAAAAPwAAAL9pISIzAAAAvwAAAD9pISKzAAAAPwAAAD9pISKzAAAAAGkhojMAAIA/AAAAAGkhojMAAIA/AAAAAGkhojMAAIA/AAAAAGkhojMAAIA/AAAAAAAAgD8AAIA/AACAPwAAAAAAAAAAAACAPwAAAAAAAAEAAwAAAAMAAgA=" + } + ] +} diff --git a/Assets/Models/Quad.shmodel b/Assets/Models/Quad.shmodel new file mode 100644 index 0000000000000000000000000000000000000000..aebbb0a667149deddd7e27627fbbaa0dc3ae4497 GIT binary patch literal 224 zcmZQ%fB+UC#RkM6Iv(V<2sh#0H7m1I0H(#i8s5kQyi;hRwi`skjJe aHbgBkY=~NrdhF&i0&Qo8x&TBo0WkovZWxFF literal 0 HcmV?d00001 diff --git a/Assets/Models/Quad.shmodel.shmeta b/Assets/Models/Quad.shmodel.shmeta new file mode 100644 index 00000000..9fbd4b9c --- /dev/null +++ b/Assets/Models/Quad.shmodel.shmeta @@ -0,0 +1,7 @@ +Name: Quad +ID: 80501355 +Type: 4 +Sub Assets: +Name: Quad +ID: 141771688 +Type: 8 diff --git a/Assets/Shaders/DebugDraw_VS.glsl b/Assets/Shaders/DebugDraw_VS.glsl index cb0886d1..7b370730 100644 --- a/Assets/Shaders/DebugDraw_VS.glsl +++ b/Assets/Shaders/DebugDraw_VS.glsl @@ -15,6 +15,9 @@ layout(set = 2, binding = 0) uniform CameraData { vec4 position; mat4 vpMat; + mat4 viewMat; + mat4 perspectiveMat; + mat4 orthoMat; } cameraData; void main() diff --git a/Assets/Shaders/TestCube_VS.glsl b/Assets/Shaders/TestCube_VS.glsl index 0e055395..774bc580 100644 --- a/Assets/Shaders/TestCube_VS.glsl +++ b/Assets/Shaders/TestCube_VS.glsl @@ -34,7 +34,8 @@ layout(set = 2, binding = 0) uniform CameraData vec4 position; mat4 vpMat; mat4 viewMat; - mat4 projMat; + mat4 perspectiveMat; + mat4 orthoMat; } cameraData; void main() diff --git a/Assets/Shaders/TestCube_VS.shshaderb b/Assets/Shaders/TestCube_VS.shshaderb index fb282b4df95c458e637710753ab4b5beb88c23e2..28c4655bda732cb87ba8fafeabaa9a900d25f9c1 100644 GIT binary patch delta 128 zcmaDUb5xdzanDAkmyCw&45|za49q}WkXlq+keXbQS(fUXSi-=-2819v79h?qD#^$P wi!yBf!x+k>>j4yoNwNYJcrdWS`N}~41!S?!ZY-HhjO>#)u!(Ly$hLwV0F){hcK`qY delta 52 zcmX>q`%;F9F<~RqOGZIf22}W diff --git a/Assets/Shaders/Text_VS.glsl b/Assets/Shaders/Text_VS.glsl index 62316533..6263aba6 100644 --- a/Assets/Shaders/Text_VS.glsl +++ b/Assets/Shaders/Text_VS.glsl @@ -30,7 +30,8 @@ layout(set = 2, binding = 0) uniform CameraData vec4 position; mat4 vpMat; mat4 viewMat; - mat4 projMat; + mat4 perspectiveMat; + mat4 orthoMat; } cameraData; // push constants diff --git a/Assets/Shaders/Text_VS.shshaderb b/Assets/Shaders/Text_VS.shshaderb index b6f0afe7c0998cf1ec4b49d6aa7f4f1704be3ccc..3f61265468da3180337a6ae798606126ca0a420b 100644 GIT binary patch delta 135 zcmdm}+N;LQ$RfOvxrf=1ouQS1fq@x_3sQ@U3sRFyGRsnZ6H6Ev*nkiu#{$IpMI{;e xU{Qw63z#P|>3RT#VUnys1s)8naK18-e*sx+vl^Q$3pd0jEue(%u=5DPmSSWav6GOlzE E0ASAy^#A|> diff --git a/Assets/Shaders/UI_FS.glsl b/Assets/Shaders/UI_FS.glsl new file mode 100644 index 00000000..85cf6ef6 --- /dev/null +++ b/Assets/Shaders/UI_FS.glsl @@ -0,0 +1,48 @@ +#version 450 +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable +#extension GL_EXT_nonuniform_qualifier : require + +struct MatPropData +{ + vec4 color; + int textureIndex; + float alpha; + vec3 beta; +}; + +layout(location = 0) in struct +{ + vec4 vertPos; // location 0 + vec2 uv; // location = 1 + vec4 normal; // location = 2 + +} In; + +// material stuff +layout(location = 3) flat in struct +{ + int materialIndex; + uint eid; + uint lightLayerIndex; +} In2; + +layout (set = 0, binding = 1) uniform sampler2D textures[]; // for textures (global) +layout (std430, set = 3, binding = 0) buffer MaterialProperties // For materials +{ + MatPropData data[]; +} MatProp; + +layout(location = 0) out vec4 position; +layout(location = 1) out uint outEntityID; +layout(location = 2) out uint lightLayerIndices; +layout(location = 3) out vec4 normals; +layout(location = 4) out vec4 albedo; + +void main() +{ + albedo = vec4(1.0f); + + outEntityID = In2.eid; + lightLayerIndices = In2.lightLayerIndex; +} \ No newline at end of file diff --git a/Assets/Shaders/UI_FS.shshaderb b/Assets/Shaders/UI_FS.shshaderb new file mode 100644 index 0000000000000000000000000000000000000000..9c8800e0e6250c2ba8a453474bfaee5ade383eef GIT binary patch literal 1877 zcmY+ET~8B16ov;%3-YZ9hMUH+m-OkE{;fa*I#sI&d!Ii9 zZP&7iO@yU1BNZYqLa{1^i2yJxMv1cyW-Pvy0#t+3ABF@3LuR##L7Cz?dd{cIp z%dA3wcAnPlwM)8eVlwB$Xh-n}vw7d*_=eNyvfK;Otct8+f9aC+IBsV-!N}RUyy1{D z(gXzy6vG%FEN;^rGBE!~%eX{9s61VnkYO`EmtVSHhi8TFykt;u6wEmw@ zUK_T~ZN@KWd|us&Q&25>eJZV7+3ZNDRy>u^A3j!-BDA=l=hAs?S*^UuR^0ZfkF$3R zhd0{ow{2?qozgRRjm@26Q+q9+Js3Xj0Uvc@7jK_lu<;=*Z05I;SvU5wY+`>@g~i-f zb54Qb2jh(t7&*Z1_h8fkR+W%%UAiLKmT<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(Y(z)AFy*j;Ekx(-_zV*C^UrNWvU8wCV2^ectzr6INEdfVZGeJ`Cj>L(5!n8p1d-Qpfe zx40jr6Gu;og9m0a@{@Fn<9>D7T?x4L@NtfTv#f{A0r&TEj9xvKSWQ1mx7@`Z^n??` zq9%A?7T1?Ph@jG9DB!I>D!VS3BAFF K_n%I>F8LoVSs)Vt literal 0 HcmV?d00001 diff --git a/Assets/Shaders/UI_VS.shshaderb.shmeta b/Assets/Shaders/UI_VS.shshaderb.shmeta new file mode 100644 index 00000000..08fa8435 --- /dev/null +++ b/Assets/Shaders/UI_VS.shshaderb.shmeta @@ -0,0 +1,3 @@ +Name: UI_VS +ID: 46580970 +Type: 2 diff --git a/SHADE_Engine/src/Editor/DragDrop/SHDragDrop.hpp b/SHADE_Engine/src/Editor/DragDrop/SHDragDrop.hpp index f111eaeb..50930e4f 100644 --- a/SHADE_Engine/src/Editor/DragDrop/SHDragDrop.hpp +++ b/SHADE_Engine/src/Editor/DragDrop/SHDragDrop.hpp @@ -21,7 +21,7 @@ namespace SHADE template static bool SetPayload(DragDropTag const& type, T* object, ImGuiCond const cond = 0) { - ImGui::SetDragDropPayload(type.data(), static_cast(object), sizeof(T), cond); + hasDragDrop = ImGui::SetDragDropPayload(type.data(), static_cast(object), sizeof(T), cond); hasDragDrop = true; currentDragDropTag = type; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 32d61f1d..d8cb3933 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -119,6 +119,11 @@ namespace SHADE SHAssetManager::CompileAsset("../../Assets/Shaders/Text_VS.glsl", false); SHAssetManager::CompileAsset("../../Assets/Shaders/Text_FS.glsl", false); + SHAssetManager::CompileAsset("../../Assets/Shaders/TestCube_VS.glsl", false); + SHAssetManager::CompileAsset("../../Assets/Shaders/UI_VS.glsl", false); + SHAssetManager::CompileAsset("../../Assets/Shaders/UI_FS.glsl", false); + + SHAssetManager::CompileAsset("../../Assets/Models/Quad.gltf", false); // Load Built In Shaders static constexpr AssetID VS_DEFAULT = 39210065; defaultVertShader = SHResourceManager::LoadOrGet(VS_DEFAULT); @@ -574,7 +579,7 @@ namespace SHADE { auto editorSystem = SHSystemManager::GetSystem(); if (editorSystem->editorState != SHEditor::State::PLAY) - worldRenderer->UpdateDataAndBind(currentCmdBuffer, frameIndex, cameraSystem->GetEditorCamera()->GetViewMatrix(), cameraSystem->GetEditorCamera()->GetProjMatrix()); + worldRenderer->UpdateDataAndBind(currentCmdBuffer, frameIndex, cameraSystem->GetEditorCamera()->GetViewMatrix(), cameraSystem->GetEditorCamera()->GetProjMatrix(), cameraSystem->GetEditorCamera()->GetOrthoMatrix()); else renderers[renIndex]->UpdateDataAndBind(currentCmdBuffer, frameIndex); } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp index 55b52645..e47055df 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp @@ -90,13 +90,13 @@ namespace SHADE if (camera && cameraDirector) { //UpdateDataAndBind(cmdBuffer, frameIndex, SHMatrix::Transpose(cameraDirector->GetVPMatrix())); - UpdateDataAndBind(cmdBuffer, frameIndex, cameraDirector->GetViewMatrix(), cameraDirector->GetProjMatrix()); + UpdateDataAndBind(cmdBuffer, frameIndex, cameraDirector->GetViewMatrix(), cameraDirector->GetProjMatrix(), cameraDirector->GetOrthoMatrix()); } } - void SHRenderer::UpdateDataAndBind(Handle cmdBuffer, uint32_t frameIndex, SHMatrix const& viewMatrix, SHMatrix const& projMatrix) noexcept + void SHRenderer::UpdateDataAndBind(Handle cmdBuffer, uint32_t frameIndex, SHMatrix const& viewMatrix, SHMatrix const& projMatrix, SHMatrix const& orthoMatrix) noexcept { - SetViewProjectionMatrix(viewMatrix, projMatrix); + SetViewProjectionMatrix(viewMatrix, projMatrix, orthoMatrix); //cpuCameraData.viewProjectionMatrix = camera->GetViewProjectionMatrix(); cameraBuffer->WriteToMemory(&cpuCameraData, sizeof(SHShaderCameraData), 0, cameraDataAlignedSize * frameIndex); @@ -116,12 +116,13 @@ namespace SHADE { } - void SHRenderer::SetViewProjectionMatrix(SHMatrix const& viewMatrix, SHMatrix const& projMatrix) noexcept + void SHRenderer::SetViewProjectionMatrix(SHMatrix const& viewMatrix, SHMatrix const& projMatrix, SHMatrix const& orthoMatrix) noexcept { //cpuCameraData.viewProjectionMatrix = camera->GetViewMatrix() * camera->GetProjectionMatrix(); cpuCameraData.viewProjectionMatrix = SHMatrix::Transpose(projMatrix * viewMatrix); cpuCameraData.viewMatrix = SHMatrix::Transpose(viewMatrix); cpuCameraData.projectionMatrix = SHMatrix::Transpose(projMatrix); + cpuCameraData.orthoMatrix = SHMatrix::Transpose (orthoMatrix); } Handle SHRenderer::GetRenderGraph(void) const noexcept diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h index c6146a56..83291700 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h @@ -48,6 +48,7 @@ namespace SHADE SHMatrix viewProjectionMatrix; SHMatrix viewMatrix; SHMatrix projectionMatrix; + SHMatrix orthoMatrix; }; /*---------------------------------------------------------------------------------*/ @@ -82,10 +83,10 @@ namespace SHADE /*-----------------------------------------------------------------------------*/ void Draw(uint32_t frameIndex, Handle descPool) noexcept; void UpdateDataAndBind(Handle cmdBuffer, uint32_t frameIndex) noexcept; - void UpdateDataAndBind(Handle cmdBuffer, uint32_t frameIndex, SHMatrix const& viewMatrix, SHMatrix const& projMatrix) noexcept; + void UpdateDataAndBind(Handle cmdBuffer, uint32_t frameIndex, SHMatrix const& viewMatrix, SHMatrix const& projMatrix, SHMatrix const& orthoMatrix) noexcept; void BindDescSet (Handle cmdBuffer, uint32_t frameIndex) noexcept; void UpdateCameraDataToBuffer (void) noexcept; - void SetViewProjectionMatrix (SHMatrix const& viewMatrix, SHMatrix const& projMatrix) noexcept; + void SetViewProjectionMatrix (SHMatrix const& viewMatrix, SHMatrix const& projMatrix, SHMatrix const& orthoMatrix) noexcept; /*-----------------------------------------------------------------------------*/ /* Setters and Getters */ diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.cpp index 7d8e2b44..3dd54ca5 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.cpp @@ -65,7 +65,7 @@ namespace SHADE // allocate GPU buffer for matrices matrixDataBuffer = logicalDevice->CreateBuffer(glyphDataSize, fontAsset.glyphTransformations.data(), glyphDataSize, vk::BufferUsageFlagBits::eTransferDst | vk::BufferUsageFlagBits::eStorageBuffer, VMA_MEMORY_USAGE_AUTO, {}); - + sampler = logicalDevice->CreateSampler(SHVkSamplerParams{}); }