SHADE_Y3/Assets/Shaders/Text_VS.glsl

101 lines
2.3 KiB
Plaintext
Raw Permalink Normal View History

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;
2023-02-28 21:30:09 +08:00
vec4 textColor;
2022-11-10 08:28:44 +08:00
} Out2;
2022-11-10 16:59:26 +08:00
// Camera data
2022-12-28 20:47:20 +08:00
layout(set = 1, binding = 0) uniform CameraData
2022-11-10 08:28:44 +08:00
{
vec4 position;
mat4 vpMat;
mat4 viewMat;
mat4 projMat;
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;
2023-02-28 21:30:09 +08:00
vec4 textColor;
2022-11-10 16:59:26 +08:00
} testPushConstant;
// Descriptor sets
2022-12-28 20:47:20 +08:00
layout(std430, set = 2, 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, 0.0f);
2022-11-10 16:59:26 +08:00
// 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;
// Initialize variables for use in FS
//characterIndex = gl_InstanceID;
// Transform the vertices to font space
2023-02-28 21:30:09 +08:00
vertexPos = toFontSpace * vec3(vertexPos.xy, 1.0f);
vertexPos.z = 0.0f;
2022-11-10 16:59:26 +08:00
Out2.textColor = testPushConstant.textColor;
2022-11-10 16:59:26 +08:00
// transform the vertex position to font space
gl_Position = cameraData.projMat * localModel * vec4(vertexPos, 1.0f);
// gl_Position = vec4(vertexPos, 1.0f);
2022-11-10 08:28:44 +08:00
}