Files
Seele/res/shaders/TextPass.slang
T

82 lines
1.9 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;
}
2024-04-13 23:51:38 +02:00
struct GlyphSampler
{
SamplerState s;
}
ParameterBlock<GlyphSampler> glyphSampler;
2022-04-17 09:10:20 +02:00
//layout(set = 1)
2023-08-28 21:23:13 +02:00
//ShaderBuffer<GlyphData> glyphData;
2024-04-13 23:51:38 +02:00
struct GlyphTextures
{
Texture2D[256] textures;
}
ParameterBlock<GlyphTextures> 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;
}
2024-04-13 23:51:38 +02:00
ParameterBlock<TextRender> pRender;
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
{
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];
2024-04-13 23:51:38 +02:00
VertexOutput output;
2022-04-17 09:10:20 +02:00
output.texCoords = vertex.zw;
2024-09-16 13:00:53 +02:00
output.position = mul(pViewParams.c.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
{
2024-04-13 23:51:38 +02:00
return pRender.textData.textColor * pGlyphTextures.textures[glyphIndex].Sample(glyphSampler.s, texCoords);
2022-04-15 11:19:30 +02:00
}