Files

63 lines
1.5 KiB
Plaintext
Raw Permalink Normal View History

2023-11-05 10:36:01 +01:00
import Common;
2022-04-18 18:08:38 +02:00
struct RenderElementStyle
2021-09-23 10:10:39 +02:00
{
2025-01-12 11:26:52 +01:00
float x;
float y;
float w;
float h;
float3 color;
2022-04-18 18:08:38 +02:00
float opacity;
2025-01-12 11:26:52 +01:00
float z;
uint textureIndex;
uint pad0;
uint pad1;
2021-09-23 10:10:39 +02:00
};
2023-11-05 10:36:01 +01:00
struct UIParameter
2022-04-18 18:08:38 +02:00
{
2025-01-12 11:26:52 +01:00
StructuredBuffer<RenderElementStyle> elements;
SamplerState sampler;
Texture2D textures[];
};
2023-11-08 23:27:21 +01:00
ParameterBlock<UIParameter> pParams;
2022-04-18 18:08:38 +02:00
2023-11-08 23:27:21 +01:00
struct VertexOutput
2022-04-18 18:08:38 +02:00
{
float4 position : SV_Position;
float2 texCoords : TEXCOORD;
2025-01-12 11:26:52 +01:00
RenderElementStyle style : STYLE;
2022-04-18 18:08:38 +02:00
};
2021-09-23 10:10:39 +02:00
[shader("vertex")]
2025-01-12 11:26:52 +01:00
VertexOutput vertexMain(uint vertexId : SV_VertexID, uint instanceId: SV_InstanceID)
2021-09-23 10:10:39 +02:00
{
2025-01-12 11:26:52 +01:00
RenderElementStyle style = pParams.elements[instanceId];
float xMin = style.x;
float xMax = xMin + style.w;
float yMin = style.y;
float yMax = yMin + style.h;
2022-04-18 18:08:38 +02:00
float4 coordinates[] = {
float4(xMin, yMin, 0, 0),
float4(xMin, yMax, 0, 1),
float4(xMax, yMin, 1, 0),
float4(xMax, yMax, 1, 1)
2021-09-23 10:10:39 +02:00
};
2023-11-08 23:27:21 +01:00
VertexOutput output;
2025-01-12 11:26:52 +01:00
output.position = mul(pViewParams.projectionMatrix, float4(coordinates[vertexId].xy, style.z-1, 1));
2022-04-18 18:08:38 +02:00
output.texCoords = coordinates[vertexId].zw;
output.style = style;
2021-09-23 10:10:39 +02:00
return output;
}
[shader("fragment")]
float4 fragmentMain(
2022-04-18 18:08:38 +02:00
float2 texCoords : TEXCOORD,
2025-01-12 11:26:52 +01:00
RenderElementStyle style : STYLE
2021-09-23 10:10:39 +02:00
) : SV_Target
{
2025-01-12 11:26:52 +01:00
if(style.textureIndex == -1) {
return float4(style.color, style.opacity);
}
2025-01-29 16:15:48 +01:00
return pParams.textures[style.textureIndex].Sample(pParams.sampler, texCoords.xy);
2021-09-23 10:10:39 +02:00
}