2023-11-05 10:36:01 +01:00
|
|
|
import Common;
|
2022-04-15 11:19:30 +02:00
|
|
|
|
2023-11-15 17:42:57 +01:00
|
|
|
struct GlyphInstanceData
|
2022-04-15 11:19:30 +02:00
|
|
|
{
|
2025-01-08 19:15:12 +01:00
|
|
|
float x;
|
|
|
|
|
float y;
|
|
|
|
|
float width;
|
|
|
|
|
float height;
|
2022-04-17 09:10:20 +02:00
|
|
|
uint glyphIndex;
|
2023-11-15 17:42:57 +01:00
|
|
|
};
|
2025-01-08 19:15:12 +01:00
|
|
|
|
|
|
|
|
struct TextData
|
2023-11-15 17:42:57 +01:00
|
|
|
{
|
2025-01-08 19:15:12 +01:00
|
|
|
StructuredBuffer<GlyphInstanceData> glyphs;
|
|
|
|
|
SamplerState glyphSampler;
|
|
|
|
|
Texture2D<float> glyphTextures[];
|
|
|
|
|
};
|
|
|
|
|
ParameterBlock<TextData> pText;
|
2023-11-15 17:42:57 +01:00
|
|
|
|
|
|
|
|
struct VertexInput
|
|
|
|
|
{
|
2022-04-15 11:19:30 +02:00
|
|
|
uint vertexId : SV_VertexID;
|
2023-11-15 17:42:57 +01:00
|
|
|
uint instanceId : SV_InstanceID;
|
2022-04-15 11:19:30 +02:00
|
|
|
};
|
|
|
|
|
|
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
|
|
|
{
|
2025-01-08 19:15:12 +01:00
|
|
|
float xpos = pText.glyphs[input.instanceId].x;
|
|
|
|
|
float ypos = pText.glyphs[input.instanceId].y;
|
2022-04-15 11:19:30 +02:00
|
|
|
|
2025-01-08 19:15:12 +01:00
|
|
|
float w = pText.glyphs[input.instanceId].width;
|
|
|
|
|
float h = pText.glyphs[input.instanceId].height;
|
2022-04-15 11:19:30 +02:00
|
|
|
|
2025-01-08 19:15:12 +01:00
|
|
|
const float4 coordinates[4] = {
|
2022-04-15 11:19:30 +02:00
|
|
|
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),
|
2025-01-08 19:15:12 +01:00
|
|
|
float4(xpos + w, ypos + h, 1, 0),
|
2022-04-15 11:19:30 +02:00
|
|
|
};
|
|
|
|
|
float4 vertex = coordinates[input.vertexId];
|
2024-04-13 23:51:38 +02:00
|
|
|
VertexOutput output;
|
2022-04-17 09:10:20 +02:00
|
|
|
output.texCoords = vertex.zw;
|
2024-10-01 16:56:04 +02:00
|
|
|
output.position = mul(pViewParams.projectionMatrix, float4(vertex.xy, 0, 1));
|
2025-01-08 19:15:12 +01:00
|
|
|
output.glyphIndex = pText.glyphs[input.instanceId].glyphIndex;
|
2022-04-15 11:19:30 +02:00
|
|
|
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
|
|
|
|
|
{
|
2025-01-08 19:15:12 +01:00
|
|
|
return float4(1, 0, 0, pText.glyphTextures[glyphIndex].Sample(pText.glyphSampler, texCoords));
|
2022-04-15 11:19:30 +02:00
|
|
|
}
|