Files
Seele/res/shaders/TextPass.slang
T

74 lines
1.8 KiB
Plaintext
Raw Normal View History

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;
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
{
float2 position;
2022-04-17 09:10:20 +02:00
float2 widthHeight;
uint glyphIndex;
2023-11-15 17:42:57 +01:00
};
struct TextRender
{
StructuredBuffer<GlyphInstanceData> instances;
TextData textData;
}
ParameterBuffer<TextRender> pRender;
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
{
2023-11-15 17:42:57 +01:00
float xpos = pRender.instances[input.instanceId].position.x;
float ypos = pRender.instances[input.instanceId].position.y;
2022-04-15 11:19:30 +02:00
2023-11-15 17:42:57 +01:00
float w = pRender.instances[input.instanceId].widthHeight.x;
float h = pRender.instances[input.instanceId].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));
2023-11-15 17:42:57 +01:00
output.glyphIndex = pRender.instances[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
{
2023-11-08 23:27:21 +01:00
return textData.textColor * pGlyphTextures[glyphIndex].Sample(glyphSampler, texCoords);
2022-04-15 11:19:30 +02:00
}