Files

65 lines
1.6 KiB
Plaintext
Raw Permalink Normal View History

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 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;
};
2025-04-10 16:42:37 +02:00
struct GlyphInstanceData
{
float x;
float y;
float z;
float width;
float height;
uint glyphIndex;
};
struct TextData
{
StructuredBuffer<GlyphInstanceData> glyphs;
SamplerState glyphSampler;
Texture2D<float> glyphTextures[];
};
ParameterBlock<TextData> pText;
2022-04-15 11:19:30 +02:00
[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] = {
2025-01-12 11:26:52 +01:00
float4(xpos, ypos, 0, 0),
float4(xpos, ypos + h, 0, 1),
float4(xpos + w, ypos, 1, 0),
float4(xpos + w, ypos + h, 1, 1),
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;
2025-01-12 11:26:52 +01:00
output.position = mul(pViewParams.projectionMatrix, float4(vertex.xy, pText.glyphs[input.instanceId].z-1, 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-12 11:26:52 +01:00
return float4(0,0,0,pText.glyphTextures[glyphIndex].Sample(pText.glyphSampler, texCoords));
2022-04-15 11:19:30 +02:00
}