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
|
|
|
{
|
2022-04-18 18:08:38 +02:00
|
|
|
float3 position;
|
|
|
|
|
uint backgroundImageIndex;
|
|
|
|
|
float3 backgroundColor;
|
|
|
|
|
float opacity;
|
|
|
|
|
//float4 borderBottomColor;
|
|
|
|
|
//float4 borderLeftColor;
|
|
|
|
|
//float4 borderRightColor;
|
|
|
|
|
//float4 borderTopColor;
|
|
|
|
|
//float borderBottomLeftRadius;
|
|
|
|
|
//float borderBottomRightRadius;
|
|
|
|
|
//float borderTopLeftRadius;
|
|
|
|
|
//float borderTopRightRadius;
|
|
|
|
|
float2 dimensions;
|
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
|
|
|
{
|
2023-11-05 10:36:01 +01:00
|
|
|
SamplerState backgroundSampler;
|
|
|
|
|
uint numBackgroundTextures;
|
|
|
|
|
Texture2D<float4> backgroundTextures[];
|
|
|
|
|
}
|
2022-04-18 18:08:38 +02:00
|
|
|
|
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;
|
|
|
|
|
RenderElementStyle style : RENDER_STYLE;
|
|
|
|
|
};
|
2021-09-23 10:10:39 +02:00
|
|
|
|
|
|
|
|
[shader("vertex")]
|
2023-11-08 23:27:21 +01:00
|
|
|
VertexOutput vertexMain(uint vertexId : SV_VertexID, RenderElementStyle style)
|
2021-09-23 10:10:39 +02:00
|
|
|
{
|
2022-04-18 18:08:38 +02:00
|
|
|
float xMin = style.position.x;
|
|
|
|
|
float xMax = xMin + style.dimensions.x;
|
|
|
|
|
float yMin = style.position.y;
|
|
|
|
|
float yMax = yMin + style.dimensions.y;
|
|
|
|
|
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;
|
|
|
|
|
output.position = mul(pViewData.projectionMatrix, float4(coordinates[vertexId].xy, style.position.z, 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(
|
|
|
|
|
float4 position : SV_Position,
|
2022-04-18 18:08:38 +02:00
|
|
|
float2 texCoords : TEXCOORD,
|
|
|
|
|
RenderElementStyle style : RENDER_STYLE
|
2021-09-23 10:10:39 +02:00
|
|
|
) : SV_Target
|
|
|
|
|
{
|
2022-04-18 18:08:38 +02:00
|
|
|
float4 bgTextureColor = float4(1, 1, 1, 1);
|
|
|
|
|
uint imageIndex = style.backgroundImageIndex;
|
|
|
|
|
if(imageIndex < numBackgroundTextures)
|
|
|
|
|
{
|
2023-11-08 23:27:21 +01:00
|
|
|
bgTextureColor = pParams.backgroundTextures[imageIndex].Sample(pParams.backgroundSampler, texCoords);
|
2022-04-18 18:08:38 +02:00
|
|
|
}
|
|
|
|
|
return float4(style.backgroundColor, style.opacity) * bgTextureColor;
|
2021-09-23 10:10:39 +02:00
|
|
|
}
|