2022-11-10 08:28:44 +08:00
|
|
|
#version 450
|
|
|
|
#extension GL_KHR_vulkan_glsl : enable
|
|
|
|
|
|
|
|
//#include "ShaderDescriptorDefinitions.glsl"
|
|
|
|
|
|
|
|
|
2022-11-10 16:59:26 +08:00
|
|
|
// vertex inputs
|
2022-11-10 08:28:44 +08:00
|
|
|
layout(location = 0) in vec4 positionalOffset;
|
2022-11-10 16:59:26 +08:00
|
|
|
layout(location = 1) in uint glyphIndex;
|
2022-11-10 08:28:44 +08:00
|
|
|
|
2022-11-10 16:59:26 +08:00
|
|
|
// between shader stages
|
2022-11-10 08:28:44 +08:00
|
|
|
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;
|
2022-11-16 16:57:08 +08:00
|
|
|
vec3 textColor;
|
2022-11-10 08:28:44 +08:00
|
|
|
} Out2;
|
|
|
|
|
2022-11-10 16:59:26 +08:00
|
|
|
// Camera data
|
2022-11-10 08:28:44 +08:00
|
|
|
layout(set = 2, binding = 0) uniform CameraData
|
|
|
|
{
|
|
|
|
vec4 position;
|
|
|
|
mat4 vpMat;
|
|
|
|
mat4 viewMat;
|
2022-11-18 22:03:21 +08:00
|
|
|
mat4 perspectiveMat;
|
|
|
|
mat4 orthoMat;
|
2022-11-10 08:28:44 +08:00
|
|
|
} cameraData;
|
|
|
|
|
2022-11-10 16:59:26 +08:00
|
|
|
// push constants
|
|
|
|
layout(std140, push_constant) uniform TestPushConstant
|
|
|
|
{
|
|
|
|
mat4 worldTransform;
|
2022-11-14 18:36:26 +08:00
|
|
|
uint eid;
|
2022-11-16 16:57:08 +08:00
|
|
|
vec3 textColor;
|
2022-11-10 16:59:26 +08:00
|
|
|
|
|
|
|
} testPushConstant;
|
|
|
|
|
|
|
|
// Descriptor sets
|
2022-11-16 16:57:08 +08:00
|
|
|
layout(std430, set = 4, binding = 1) buffer GlyphTransforms
|
2022-11-10 16:59:26 +08:00
|
|
|
{
|
|
|
|
mat4 matrices[];
|
|
|
|
} glyphTransforms;
|
|
|
|
|
|
|
|
vec2 CreateQuad(in uint vertexID)
|
|
|
|
{
|
|
|
|
uint b = 1 << vertexID;
|
|
|
|
return vec2 ((0x3 & b) != 0, (0x9 & b) != 0);
|
|
|
|
}
|
|
|
|
|
2022-11-10 08:28:44 +08:00
|
|
|
void main()
|
|
|
|
{
|
2022-11-10 16:59:26 +08:00
|
|
|
// write EID data to FS
|
2022-11-14 19:31:26 +08:00
|
|
|
Out2.eid = testPushConstant.eid;
|
2022-11-10 16:59:26 +08:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2022-11-16 16:57:08 +08:00
|
|
|
Out2.textColor = testPushConstant.textColor;
|
|
|
|
|
2022-11-10 16:59:26 +08:00
|
|
|
// transform the vertex position to font space
|
|
|
|
gl_Position = PVMatrix * localModel * vec4(vertexPos, 1.0f);
|
2022-11-10 08:28:44 +08:00
|
|
|
}
|