Added UI functionality to the Graphics System #232

Merged
Xenosas1337 merged 40 commits from UI_Integration into main 2022-11-20 15:43:34 +08:00
10 changed files with 121 additions and 23 deletions
Showing only changes of commit 9d367a359a - Show all commits

View File

@ -22,29 +22,43 @@ layout(location = 0) in struct
// 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
// push constants
layout(std140, push_constant) uniform TestPushConstant
{
MatPropData data[];
} MatProp;
vec3 textColor;
layout(location = 0) out vec4 position;
} testPushConstant;
layout(set = 6, binding = 0) uniform sampler2D fontBitmap;
layout(location = 0) out vec4 color;
layout(location = 1) out uint outEntityID;
layout(location = 2) out uint lightLayerIndices;
layout(location = 3) out vec4 normals;
layout(location = 4) out vec4 albedo;
float median(float r, float g, float b)
{
return max(min(r, g), min(max(r, g), b));
}
void main()
{
position = In.vertPos;
normals = In.normal;
albedo = texture(textures[nonuniformEXT(MatProp.data[In2.materialIndex].textureIndex)], In.uv) * MatProp.data[In2.materialIndex].color;
vec3 msd = texture (fontBitmap, In.uv).rgb;
float sd = median (msd.r, msd.g, msd.b);
float screenPxDistance = 2 * (sd - 0.5f);
float opacity = clamp (screenPxDistance + 0.5f, 0.0f, 2.0f);
vec4 fragColor = vec4 (1.0f);
if (opacity > 0.02f && opacity < 1.9f)
{
fragColor = vec4(0.0f, 1.0f, 1.0f, 1.0f);
}
fragColor = mix(vec4(0.0f), vec4(testPushConstant.textColor, 1.0f), min (opacity, 1.0f));
color = fragColor;
outEntityID = In2.eid;
lightLayerIndices = In2.lightLayerIndex;
}

Binary file not shown.

View File

@ -0,0 +1,3 @@
Name: Text_FS
ID: 38024754
Type: 2

View File

@ -4,10 +4,12 @@
//#include "ShaderDescriptorDefinitions.glsl"
// vertex inputs
layout(location = 0) in vec4 positionalOffset;
layout(location = 1) in unsigned int glyphIndex;
layout(location = 1) in uint glyphIndex;
layout(location = 2) in uvec2 integerData;
// between shader stages
layout(location = 0) out struct
{
vec4 vertPos; // location 0
@ -22,6 +24,7 @@ layout(location = 3) out struct
uint eid;
} Out2;
// Camera data
layout(set = 2, binding = 0) uniform CameraData
{
vec4 position;
@ -30,10 +33,65 @@ layout(set = 2, binding = 0) uniform CameraData
mat4 projMat;
} cameraData;
// push constants
layout(std140, push_constant) uniform TestPushConstant
{
mat4 worldTransform;
} testPushConstant;
// Descriptor sets
layout(std430, set = 6, binding = 1) buffer GlyphTransforms
{
mat4 matrices[];
} glyphTransforms;
vec2 CreateQuad(in uint vertexID)
{
uint b = 1 << vertexID;
return vec2 ((0x3 & b) != 0, (0x9 & b) != 0);
}
void main()
{
// write EID data to FS
Out2.eid = integerData[0];
// clip space for rendering
gl_Position = cameraData.vpMat * worldTransform * vec4 (aVertexPos, 1.0f);
// local variable for font index
uint fontIndex = glyphIndex;
// get font data
mat4 fontData = glyphTransforms.matrices[fontIndex];
// Generate UV coords and vertex positions
Out.uv = CreateQuad(gl_VertexIndex);
vec3 vertexPos = vec3(Out.uv, 1.0f);
// Get the local matrices
mat4 localModel = testPushConstant.worldTransform;
//mat4 uiScale = mat4(1.0f);
//uiScale[0][0] = cameraData.cameraRight / 20.49f;
//uiScale[1][1] = cameraData.cameraTop / 11.323f;
// transform the UV to atlas space to sample the font bitmap correctly
Out.uv = vec2(mat3(fontData) * vec3(Out.uv, 1.0f));
// Matrix to transform the quad from local to font space (for a font to be of correct size)
mat3 toFontSpace = mat3(1.0f);
toFontSpace[0][0] = fontData[3][0];
toFontSpace[1][1] = fontData[3][1];
toFontSpace[2][0] = positionalOffset.x;
toFontSpace[2][1] = positionalOffset.y;
mat4 PVMatrix = cameraData.vpMat;
// Initialize variables for use in FS
//characterIndex = gl_InstanceID;
// Transform the vertices to font space
vertexPos = toFontSpace * vertexPos;
// transform the vertex position to font space
gl_Position = PVMatrix * localModel * vec4(vertexPos, 1.0f);
}

Binary file not shown.

View File

@ -0,0 +1,3 @@
Name: Text_VS
ID: 39816727
Type: 2

View File

@ -116,6 +116,9 @@ namespace SHADE
// Create generic command buffer
graphicsCmdPool = device->CreateCommandPool(SH_QUEUE_FAMILY_ARRAY_INDEX::GRAPHICS, SH_CMD_POOL_RESET::POOL_BASED, true);
SHAssetManager::CompileAsset("../../Assets/Shaders/Text_VS.glsl");
SHAssetManager::CompileAsset("../../Assets/Shaders/Text_FS.glsl");
// Load Built In Shaders
static constexpr AssetID VS_DEFAULT = 39210065; defaultVertShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(VS_DEFAULT);
static constexpr AssetID FS_DEFAULT = 46377769; defaultFragShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(FS_DEFAULT);
@ -123,7 +126,8 @@ namespace SHADE
static constexpr AssetID FS_DEBUG = 36671027; debugFragShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(FS_DEBUG);
static constexpr AssetID CS_COMPOSITE = 45072428; deferredCompositeShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(CS_COMPOSITE);
static constexpr AssetID SSAO = 38430899; ssaoShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(SSAO);
static constexpr AssetID SSAO_BLUR = 39760835; ssaoBlurShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(SSAO_BLUR);
static constexpr AssetID TEXT_VS = 39816727; textVS = SHResourceManager::LoadOrGet<SHVkShaderModule>(TEXT_VS);
static constexpr AssetID TEXT_FS = 38024754; textFS = SHResourceManager::LoadOrGet<SHVkShaderModule>(TEXT_FS);
}
void SHGraphicsSystem::InitSceneRenderGraph(void) noexcept

View File

@ -412,6 +412,8 @@ namespace SHADE
Handle<SHVkShaderModule> deferredCompositeShader;
Handle<SHVkShaderModule> ssaoShader;
Handle<SHVkShaderModule> ssaoBlurShader;
Handle<SHVkShaderModule> textVS;
Handle<SHVkShaderModule> textFS;
// Built-In Materials

View File

@ -6,6 +6,7 @@
#include "Graphics/Devices/SHVkLogicalDevice.h"
#include "Graphics/MiddleEnd/TextRendering/SHFont.h"
#include "Graphics/Buffers/SHVkBuffer.h"
#include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h"
namespace SHADE
{
@ -86,11 +87,21 @@ namespace SHADE
}
void SHTextRenderingSubSystem::Init(Handle<SHVkLogicalDevice> device, Handle<SHVkDescriptorPool> descPool) noexcept
void SHTextRenderingSubSystem::Init(Handle<SHVkLogicalDevice> device, Handle<SHVkRenderpass> compatibleRenderpass, Handle<SHSubpass> subpass, Handle<SHVkDescriptorPool> descPool, Handle<SHVkShaderModule> textVS, Handle<SHVkShaderModule> textFS) noexcept
{
logicalDevice = device;
// prepare pipeline layout params
SHPipelineLayoutParams plParams
{
.shaderModules = {textVS, textFS},
.globalDescSetLayouts = SHGraphicsGlobalData::GetDescSetLayouts()
};
pipelineLayout = logicalDevice->CreatePipelineLayout(plParams);
// Create pipeline
pipeline = logicalDevice->CreateGraphicsPipeline(pipelineLayout, nullptr, compatibleRenderpass, subpass);
}
void SHTextRenderingSubSystem::Run(uint32_t frameIndex) noexcept

View File

@ -14,6 +14,9 @@ namespace SHADE
class SHTextRendererComponent;
class SHVkPipeline;
class SHVkPipelineLayout;
class SHVkRenderpass;
class SHSubpass;
class SHVkShaderModule;
class SHTextRenderingSubSystem
{
@ -32,7 +35,7 @@ namespace SHADE
void RecomputePositions(SHTextRendererComponent& textComp) noexcept;
public:
void Init(Handle<SHVkLogicalDevice> device, Handle<SHVkDescriptorPool> descPool) noexcept;
void Init(Handle<SHVkLogicalDevice> device, Handle<SHVkRenderpass> compatibleRenderpass, Handle<SHSubpass> subpass, Handle<SHVkDescriptorPool> descPool, Handle<SHVkShaderModule> textVS, Handle<SHVkShaderModule> textFS) noexcept;
void Run(uint32_t frameIndex) noexcept;
void Render (void) noexcept;
void Exit(void) noexcept;