2023-11-05 10:36:01 +01:00
|
|
|
import Common;
|
2022-04-15 11:19:30 +02:00
|
|
|
|
|
|
|
|
struct GlyphData
|
|
|
|
|
{
|
2022-04-17 09:10:20 +02:00
|
|
|
float4 bearingSize;
|
2022-04-15 11:19:30 +02:00
|
|
|
};
|
2022-04-17 09:10:20 +02:00
|
|
|
struct TextData
|
|
|
|
|
{
|
|
|
|
|
float4 textColor;
|
|
|
|
|
float scale;
|
|
|
|
|
}
|
2023-11-08 23:27:21 +01:00
|
|
|
ParameterBlock<SamplerState> glyphSampler;
|
2022-04-17 09:10:20 +02:00
|
|
|
//layout(set = 1)
|
2023-08-28 21:23:13 +02:00
|
|
|
//ShaderBuffer<GlyphData> glyphData;
|
2023-11-08 23:27:21 +01:00
|
|
|
ParameterBuffer<Texture2D<uint>[]> pGlyphTextures;
|
2023-11-05 10:36:01 +01:00
|
|
|
[[vk::push_constant]]
|
2022-04-17 09:10:20 +02:00
|
|
|
ConstantBuffer<TextData> textData;
|
2022-04-15 11:19:30 +02:00
|
|
|
|
2023-11-08 23:27:21 +01:00
|
|
|
struct VertexInput
|
2022-04-15 11:19:30 +02:00
|
|
|
{
|
|
|
|
|
float2 position;
|
2022-04-17 09:10:20 +02:00
|
|
|
float2 widthHeight;
|
|
|
|
|
uint glyphIndex;
|
2022-04-15 11:19:30 +02:00
|
|
|
uint vertexId : SV_VertexID;
|
|
|
|
|
};
|
|
|
|
|
|
2023-11-08 23:27:21 +01:00
|
|
|
struct VertexOutput
|
2022-04-15 11:19:30 +02:00
|
|
|
{
|
|
|
|
|
float4 position : SV_Position;
|
2022-04-17 09:10:20 +02:00
|
|
|
float2 texCoords : TEXCOORD;
|
2022-04-15 11:19:30 +02:00
|
|
|
uint glyphIndex : GLYPHINDEX;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
[shader("vertex")]
|
2023-11-08 23:27:21 +01:00
|
|
|
VertexOutput vertexMain(VertexInput input)
|
2022-04-15 11:19:30 +02:00
|
|
|
{
|
2022-04-17 09:10:20 +02:00
|
|
|
float xpos = input.position.x;
|
|
|
|
|
float ypos = input.position.y;
|
2022-04-15 11:19:30 +02:00
|
|
|
|
2022-04-17 09:10:20 +02:00
|
|
|
float w = input.widthHeight.x;
|
|
|
|
|
float h = input.widthHeight.y;
|
2022-04-15 11:19:30 +02:00
|
|
|
|
|
|
|
|
float4 coordinates[4] = {
|
|
|
|
|
float4(xpos, ypos, 0, 1),
|
2022-04-15 23:45:44 +02:00
|
|
|
float4(xpos, ypos + h, 0, 0),
|
|
|
|
|
float4(xpos + w, ypos, 1, 1),
|
|
|
|
|
float4(xpos + w, ypos + h, 1, 0)
|
2022-04-15 11:19:30 +02:00
|
|
|
};
|
|
|
|
|
float4 vertex = coordinates[input.vertexId];
|
|
|
|
|
VertexStageOutput output;
|
2022-04-17 09:10:20 +02:00
|
|
|
output.texCoords = vertex.zw;
|
2022-04-15 11:19:30 +02:00
|
|
|
output.position = mul(viewData.projectionMatrix, float4(vertex.xy, 0, 1));
|
|
|
|
|
output.glyphIndex = input.glyphIndex;
|
|
|
|
|
return output;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[shader("fragment")]
|
|
|
|
|
float4 fragmentMain(
|
|
|
|
|
float4 position : SV_Position,
|
2022-04-17 09:10:20 +02:00
|
|
|
float2 texCoords : TEXCOORD,
|
2022-04-15 11:19:30 +02:00
|
|
|
uint glyphIndex : GLYPHINDEX
|
|
|
|
|
) : SV_Target
|
|
|
|
|
{
|
2023-11-08 23:27:21 +01:00
|
|
|
return textData.textColor * pGlyphTextures[glyphIndex].Sample(glyphSampler, texCoords);
|
2022-04-15 11:19:30 +02:00
|
|
|
}
|