diff --git a/Assets/Fonts/SegoeUI.shfont b/Assets/Fonts/SegoeUI.shfont index 3f709c2a..321f62c8 100644 Binary files a/Assets/Fonts/SegoeUI.shfont and b/Assets/Fonts/SegoeUI.shfont differ diff --git a/Assets/Shaders/Text_FS.glsl b/Assets/Shaders/Text_FS.glsl index 87e29de8..fdf32583 100644 --- a/Assets/Shaders/Text_FS.glsl +++ b/Assets/Shaders/Text_FS.glsl @@ -45,15 +45,14 @@ void main() float screenPxDistance = 2 * (sd - 0.5f); float opacity = clamp (screenPxDistance + 0.5f, 0.0f, 2.0f); - vec4 fragColor = vec4 (1.0f); + vec4 fragColor; - if (opacity > 0.02f && opacity < 1.9f) - { - fragColor = vec4(0.0f, 1.0f, 1.0f, 1.0f); - } - - fragColor = mix(vec4(0.0f), vec4(In2.textColor, 1.0f), min (opacity, 1.0f)); + if (opacity < 0.2f) + discard; + else + fragColor = mix(vec4(0.0f), vec4(In2.textColor, 1.0f), min (opacity, 1.0f)); + // fragColor = vec4 (1.0f); color = fragColor; outEntityID = In2.eid; diff --git a/Assets/Shaders/Text_FS.shshaderb b/Assets/Shaders/Text_FS.shshaderb index 96c8c587..d9b47d6e 100644 Binary files a/Assets/Shaders/Text_FS.shshaderb and b/Assets/Shaders/Text_FS.shshaderb differ diff --git a/Assets/Shaders/Text_VS.glsl b/Assets/Shaders/Text_VS.glsl index 6263aba6..3501a13d 100644 --- a/Assets/Shaders/Text_VS.glsl +++ b/Assets/Shaders/Text_VS.glsl @@ -68,7 +68,7 @@ void main() // Generate UV coords and vertex positions Out.uv = CreateQuad(gl_VertexIndex); - vec3 vertexPos = vec3(Out.uv, 1.0f); + vec3 vertexPos = vec3(Out.uv, 0.0f); // Get the local matrices mat4 localModel = testPushConstant.worldTransform; @@ -87,16 +87,15 @@ void main() 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; + vertexPos = toFontSpace * vec3(vertexPos.xy, 1.0f); Out2.textColor = testPushConstant.textColor; // transform the vertex position to font space - gl_Position = PVMatrix * localModel * vec4(vertexPos, 1.0f); + gl_Position = cameraData.orthoMat * localModel * vec4(vertexPos, 1.0f); + // gl_Position = vec4(vertexPos, 1.0f); } \ No newline at end of file diff --git a/Assets/Shaders/Text_VS.shshaderb b/Assets/Shaders/Text_VS.shshaderb index 3f612654..25eff84a 100644 Binary files a/Assets/Shaders/Text_VS.shshaderb and b/Assets/Shaders/Text_VS.shshaderb differ diff --git a/SHADE_Application/src/Application/SBApplication.cpp b/SHADE_Application/src/Application/SBApplication.cpp index a8871cd8..3b7115a2 100644 --- a/SHADE_Application/src/Application/SBApplication.cpp +++ b/SHADE_Application/src/Application/SBApplication.cpp @@ -141,7 +141,7 @@ namespace Sandbox //SHComponentManager::CreateComponentSparseSet(); SHAssetManager::Load(); - auto font = SHAssetManager::GetData(176667660); + //auto font = SHAssetManager::GetData(176667660); SHSystemManager::RegisterRoutine(); diff --git a/SHADE_Engine/src/Assets/Libraries/Loaders/SHFontLoader.cpp b/SHADE_Engine/src/Assets/Libraries/Loaders/SHFontLoader.cpp index 9bbd3a71..7217b551 100644 --- a/SHADE_Engine/src/Assets/Libraries/Loaders/SHFontLoader.cpp +++ b/SHADE_Engine/src/Assets/Libraries/Loaders/SHFontLoader.cpp @@ -22,6 +22,14 @@ namespace SHADE return nullptr; } + // Attempt to load font geometry for advance data + auto ttfFilePath = path.string(); + ttfFilePath = ttfFilePath.substr(0, ttfFilePath.find_last_of('.')); + ttfFilePath += TTF_EXTENSION.data(); + msdfgen::FontHandle* fontHandle = nullptr; + fontHandle = msdfgen::loadFont(SHFreetypeInstance::GetFreetypeHandle(), ttfFilePath.c_str()); + newFontAsset->fontGeometry.loadCharset(fontHandle, 1.0f, msdf_atlas::Charset::ASCII); + uint32_t numGlyphs = 0; // read how many glyphs we have diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 3932298c..439d4cb8 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -117,6 +117,8 @@ namespace SHADE // Create generic command buffer graphicsCmdPool = device->CreateCommandPool(SH_QUEUE_FAMILY_ARRAY_INDEX::GRAPHICS, SH_CMD_POOL_RESET::POOL_BASED, true); + SHFreetypeInstance::Init(); + SHAssetManager::CompileAsset("../../Assets/Shaders/Text_VS.glsl", false); SHAssetManager::CompileAsset("../../Assets/Shaders/Text_FS.glsl", false); SHAssetManager::CompileAsset("../../Assets/Shaders/TestCube_VS.glsl", false); @@ -379,7 +381,6 @@ namespace SHADE screenRenderer->BindDescSet(cmdBuffer, frameIndex); }); - SHFreetypeInstance::Init(); } void SHGraphicsSystem::InitBuiltInResources(void) @@ -1041,7 +1042,8 @@ namespace SHADE worldViewport->SetWidth(static_cast(resizeWidth)); worldViewport->SetHeight(static_cast(resizeHeight)); - worldCamera->SetPerspective(90.0f, static_cast(resizeWidth), static_cast(resizeHeight), 0.0f, 100.0f); + //worldCamera->SetPerspective(90.0f, static_cast(resizeWidth), static_cast(resizeHeight), 0.0f, 100.0f); + //screenCamera->SetOrthographic(static_cast(resizeWidth), static_cast(resizeHeight), 0.01f, 100.0f); auto cameraSystem = SHSystemManager::GetSystem(); #ifdef SHEDITOR @@ -1053,8 +1055,6 @@ namespace SHADE for (auto& semaHandle : graphSemaphores) semaHandle = device->CreateSemaphore(); - - } void SHGraphicsSystem::AwaitGraphicsExecution() diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRendererComponent.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRendererComponent.cpp index ac1dd73f..af30c8e8 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRendererComponent.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRendererComponent.cpp @@ -24,7 +24,7 @@ namespace SHADE /***************************************************************************/ void SHTextRendererComponent::OnCreate(void) { - text = "Text"; + text = "My name is Brandon."; requiresRecompute = true; // Default white color. diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp index ed7314ba..8fbdd33b 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp @@ -16,7 +16,7 @@ namespace SHADE { void SHTextRenderingSubSystem::RecomputePositions(SHTextRendererComponent& textComp) noexcept { - if (textComp.text.empty() || textComp.fontHandle) + if (textComp.text.empty() || !textComp.fontHandle) return; // Create the buffer @@ -24,7 +24,7 @@ namespace SHADE textComp.indexingDataBuffer = logicalDevice->CreateBuffer(SHTextRendererComponent::MAX_CHARACTERS * sizeof(uint32_t), nullptr, SHTextRendererComponent::MAX_CHARACTERS * sizeof(uint32_t), vk::BufferUsageFlagBits::eVertexBuffer, VMA_MEMORY_USAGE_AUTO, VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT); if (!textComp.charPositionDataBuffer) - textComp.indexingDataBuffer = logicalDevice->CreateBuffer(SHTextRendererComponent::MAX_CHARACTERS * sizeof(SHVec4), nullptr, SHTextRendererComponent::MAX_CHARACTERS * sizeof(SHVec4), vk::BufferUsageFlagBits::eVertexBuffer, VMA_MEMORY_USAGE_AUTO, VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT); + textComp.charPositionDataBuffer = logicalDevice->CreateBuffer(SHTextRendererComponent::MAX_CHARACTERS * sizeof(SHVec4), nullptr, SHTextRendererComponent::MAX_CHARACTERS * sizeof(SHVec4), vk::BufferUsageFlagBits::eVertexBuffer, VMA_MEMORY_USAGE_AUTO, VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT); // For indexing font transformation in the shader std::vector indexingData; @@ -115,8 +115,8 @@ namespace SHADE SHVertexInputState vertexInputState; // Configure vertex attributes - vertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_4D) }); // location = 0 (character position data) - vertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::UINT32_1D) }); // location = 1 (glyph index to index matrices) + vertexInputState.AddBinding(true, false, { SHVertexAttribute(SHAttribFormat::FLOAT_4D) }); // location = 0 (character position data) + vertexInputState.AddBinding(true, false, { SHVertexAttribute(SHAttribFormat::UINT32_1D) }); // location = 1 (glyph index to index matrices) // Set vertex state for new pipeline pipeline->GetPipelineState().SetVertexInputState(vertexInputState); @@ -146,6 +146,13 @@ namespace SHADE pipeline->GetPipelineState().SetColorBlenState(colorBlendState); + SHInputAssemblyState inputAssembly{}; + inputAssembly.topology = vk::PrimitiveTopology::eTriangleFan; + pipeline->GetPipelineState().SetInputAssemblyState(inputAssembly); + + SHRasterizationState rasterState{}; + rasterState.frontFacingOrientation = vk::FrontFace::eClockwise; + pipeline->GetPipelineState().SetRasterizationState(rasterState); // Construct pipeline pipeline->ConstructPipeline();