#version 450 #extension GL_KHR_vulkan_glsl : enable //#include "ShaderDescriptorDefinitions.glsl" // vertex inputs layout(location = 0) in vec4 positionalOffset; layout(location = 1) in uint glyphIndex; // between shader stages 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; vec3 textColor; } Out2; // Camera data layout(set = 2, binding = 0) uniform CameraData { vec4 position; mat4 vpMat; mat4 viewMat; mat4 perspectiveMat; mat4 orthoMat; } cameraData; // push constants layout(std140, push_constant) uniform TestPushConstant { mat4 worldTransform; uint eid; vec3 textColor; } testPushConstant; // Descriptor sets layout(std430, set = 4, 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 = testPushConstant.eid; // 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; Out2.textColor = testPushConstant.textColor; // transform the vertex position to font space gl_Position = PVMatrix * localModel * vec4(vertexPos, 1.0f); }