From be6a11c62971eb5690d63881843f604bbc8facf1 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Thu, 10 Nov 2022 08:28:44 +0800 Subject: [PATCH] Text Rendering WIP --- Assets/Shaders/Text_FS.glsl | 50 +++++++++++++++++++ Assets/Shaders/Text_VS.glsl | 39 +++++++++++++++ .../SHTextRenderingSubSystem.cpp | 9 ++++ .../TextRendering/SHTextRenderingSubSystem.h | 8 +++ 4 files changed, 106 insertions(+) create mode 100644 Assets/Shaders/Text_FS.glsl create mode 100644 Assets/Shaders/Text_VS.glsl diff --git a/Assets/Shaders/Text_FS.glsl b/Assets/Shaders/Text_FS.glsl new file mode 100644 index 00000000..d6f88687 --- /dev/null +++ b/Assets/Shaders/Text_FS.glsl @@ -0,0 +1,50 @@ +#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() +{ + position = In.vertPos; + normals = In.normal; + albedo = texture(textures[nonuniformEXT(MatProp.data[In2.materialIndex].textureIndex)], In.uv) * MatProp.data[In2.materialIndex].color; + + outEntityID = In2.eid; + lightLayerIndices = In2.lightLayerIndex; +} \ No newline at end of file diff --git a/Assets/Shaders/Text_VS.glsl b/Assets/Shaders/Text_VS.glsl new file mode 100644 index 00000000..bfc220d4 --- /dev/null +++ b/Assets/Shaders/Text_VS.glsl @@ -0,0 +1,39 @@ +#version 450 +#extension GL_KHR_vulkan_glsl : enable + +//#include "ShaderDescriptorDefinitions.glsl" + + +layout(location = 0) in vec4 positionalOffset; +layout(location = 1) in unsigned int glyphIndex; + + +layout(location = 0) out struct +{ + vec4 vertPos; // location 0 + vec2 uv; // location = 1 + vec4 normal; // location = 2 + +} Out; + +// material stuff +layout(location = 3) out struct +{ + uint eid; +} Out2; + +layout(set = 2, binding = 0) uniform CameraData +{ + vec4 position; + mat4 vpMat; + mat4 viewMat; + mat4 projMat; +} cameraData; + +void main() +{ + Out2.eid = integerData[0]; + + // clip space for rendering + gl_Position = cameraData.vpMat * worldTransform * vec4 (aVertexPos, 1.0f); +} \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp index f4705f32..0db0b785 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp @@ -89,6 +89,8 @@ namespace SHADE void SHTextRenderingSubSystem::Init(Handle device, Handle descPool) noexcept { logicalDevice = device; + + } void SHTextRenderingSubSystem::Run(uint32_t frameIndex) noexcept @@ -114,6 +116,13 @@ namespace SHADE { // draw the component + // bind the pipeline + // bind the pipeline layout + // bind VBO (position and indices) + // bind descriptors for font (matrices) + + // call draw call + } } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h index ec43c85b..271d3b99 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h @@ -12,6 +12,8 @@ namespace SHADE class SHLightComponent; class SHVkCommandBuffer; class SHTextRendererComponent; + class SHVkPipeline; + class SHVkPipelineLayout; class SHTextRenderingSubSystem { @@ -20,6 +22,12 @@ namespace SHADE //! Logical device for creation and destruction Handle logicalDevice; + //! Pipeline for rendering the text + Handle pipeline; + + //! Pipeline layout for the pipeline + Handle pipelineLayout; + private: void RecomputePositions(SHTextRendererComponent& textComp) noexcept;