font.fx: generate quad via geometry shader

This commit is contained in:
Zack Buhman 2026-01-06 22:15:24 -06:00
parent 16f2ee8a1e
commit c2557116a8
2 changed files with 35 additions and 13 deletions

44
font.fx
View File

@ -16,27 +16,49 @@ struct VS_INPUT
float2 Pos : POSITION;
};
struct PS_INPUT
struct GSPS_INPUT
{
float4 Pos : SV_POSITION;
float2 Tex : TEXCOORD0;
};
PS_INPUT VS(VS_INPUT input)
GSPS_INPUT VS(VS_INPUT input)
{
PS_INPUT output = (PS_INPUT)0;
GSPS_INPUT output = (GSPS_INPUT)0;
float2 Pos = input.Pos * vGlyphScale + vPosition;
Pos = Pos * vInvScreenSize + float2(-1, 1);
output.Pos = float4(Pos.xy, 0, 1);
output.Pos = float4(0, 0, 0, 0);
output.Tex = float2(0, 0);
float2 Tex = float2(input.Pos.x, -input.Pos.y);
output.Tex = (Tex + vCharCoord) * vTexScale;
return output;
}
float4 PS(PS_INPUT input) : SV_Target
static const float2 vertices[] = {
float2( 0.0f, 0.0f), // -- top right
float2( 1.0f, 0.0f), // -- top left
float2( 0.0f, -1.0f), // -- bottom right
float2( 1.0f, -1.0f), // -- bottom left
};
[maxvertexcount(4)]
void GS (point GSPS_INPUT input[1], inout TriangleStream<GSPS_INPUT> TriStream)
{
GSPS_INPUT output;
for (int i = 0; i < 4; i++) {
float2 Pos;
Pos = vertices[i] * vGlyphScale + vPosition;
Pos = Pos * vInvScreenSize + float2(-1, 1);
output.Pos = float4(Pos.xy, 0, 1);
output.Tex = vertices[i] * float2(1, -1);
output.Tex = (output.Tex + vCharCoord) * vTexScale;
TriStream.Append(output);
}
TriStream.RestartStrip();
}
float4 PS(GSPS_INPUT input) : SV_Target
{
float4 texColor = txDiffuse.Sample(samPoint, input.Tex);
@ -50,7 +72,7 @@ technique10 Font
pass P0
{
SetVertexShader(CompileShader(vs_4_0, VS()));
SetGeometryShader(NULL);
SetGeometryShader(CompileShader(gs_4_0, GS()));
SetPixelShader(CompileShader(ps_4_0, PS()));
}
}

View File

@ -923,14 +923,14 @@ void RenderFont()
UINT offset[] = { 0 };
g_pd3dDevice->IASetInputLayout(g_pVertexLayoutFont);
g_pd3dDevice->IASetVertexBuffers(0, g_dwVertexBufferCountFont, g_pVertexBuffersFont, stride, offset);
g_pd3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
g_pd3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_POINTLIST);
D3D10_TECHNIQUE_DESC techDesc;
g_pTechniqueFont->GetDesc(&techDesc);
for (UINT p = 0; p < techDesc.Passes; p++) {
g_pTechniqueFont->GetPassByIndex(p)->Apply(0);
g_pd3dDevice->Draw(4, 0);
g_pd3dDevice->Draw(1, 0);
}
}