121 lines
3.0 KiB
HLSL
121 lines
3.0 KiB
HLSL
#include "rect_shared.hlsli"
|
|
#include "fragmentHelpers.hlsli"
|
|
|
|
|
|
struct PSOut{
|
|
float4 Color: SV_Target0;
|
|
};
|
|
|
|
Texture2D<float4> Texture0 : register(t0, space2);
|
|
SamplerState Sampler0 : register(s0, space2);
|
|
|
|
StructuredBuffer<Scene> scene: register(t1, space2);
|
|
|
|
PSOut main(
|
|
float4 Color : TEXCOORD0,
|
|
float2 UV : TEXCOORD1,
|
|
float2 pixelPosition: TEXCOORD2,
|
|
uint Instance: TEXCOORD3
|
|
) {
|
|
Scene s = scene[Instance];
|
|
PSOut o;
|
|
|
|
// check to discard topleft
|
|
float3 color = Color.xyz;
|
|
float alpha = s.alpha;
|
|
uint usesImage = s.flags & 1;
|
|
float4 rounding = s.rounding;
|
|
float borderWidth = s.borderWidth;
|
|
float2 imageSize = s.imageSize;
|
|
|
|
|
|
if(pixelPosition.x < rounding.x && pixelPosition.y < rounding.y)
|
|
{
|
|
float dist = distance(pixelPosition, float2(rounding.x, rounding.x));
|
|
if(dist > (rounding.x ))
|
|
{
|
|
discard;
|
|
}
|
|
else if(somewhatEqual(dist, rounding.x))
|
|
{
|
|
color = s.edgeColor.xyz;
|
|
alpha = s.edgeColor.w;
|
|
}
|
|
}
|
|
|
|
// top right
|
|
if(pixelPosition.x > imageSize.x - rounding.y && pixelPosition.y < rounding.y )
|
|
{
|
|
float dist = distance(pixelPosition, float2(imageSize.x - rounding.y, rounding.y));
|
|
if(dist > rounding.y)
|
|
{
|
|
discard;
|
|
}
|
|
else if(somewhatEqual(dist, rounding.y))
|
|
{
|
|
color = s.edgeColor.xyz;
|
|
alpha = s.edgeColor.w;
|
|
}
|
|
}
|
|
|
|
// bottom Left
|
|
if(pixelPosition.x < rounding.x && pixelPosition.y > imageSize.y - rounding.y)
|
|
{
|
|
float dist = distance(pixelPosition, float2(rounding.x, imageSize.y - rounding.y));
|
|
if(dist > rounding.y)
|
|
{
|
|
discard;
|
|
}
|
|
else if(somewhatEqual(dist, rounding.y))
|
|
{
|
|
color = s.edgeColor.xyz;
|
|
alpha = s.edgeColor.w;
|
|
}
|
|
}
|
|
|
|
// bottom right
|
|
if(pixelPosition.x > imageSize.x - rounding.a && imageSize.y - pixelPosition.y < rounding.a )
|
|
{
|
|
float dist = distance(pixelPosition, float2(imageSize.x - rounding.x, imageSize.y - rounding.y));
|
|
if(dist > rounding.y)
|
|
{
|
|
discard;
|
|
}
|
|
else if(somewhatEqual(dist, rounding.y))
|
|
{
|
|
color = s.edgeColor.xyz;
|
|
alpha = s.edgeColor.w;
|
|
}
|
|
}
|
|
|
|
// check to discard topright
|
|
|
|
// determine border colors
|
|
|
|
if( pixelPosition.x < borderWidth
|
|
|| pixelPosition.x > imageSize.x - borderWidth
|
|
|| pixelPosition.y < borderWidth
|
|
|| pixelPosition.y > imageSize.y - borderWidth
|
|
)
|
|
{
|
|
color = s.edgeColor.xyz;
|
|
alpha = s.edgeColor.w;
|
|
}
|
|
|
|
// scale the color
|
|
if(usesImage > 0)
|
|
{
|
|
// vec4 sampledColor = texture(tex, float2(texCoord.x, 1 - texCoord.y));
|
|
float4 sampledColor = Texture0.Sample(Sampler0, float2(UV.x, 1 - UV.y));
|
|
o.Color = float4(sampledColor.rgb, sampledColor.a * alpha);
|
|
}
|
|
else
|
|
{
|
|
o.Color = float4(pow(color, 2.2), alpha);
|
|
}
|
|
|
|
return o;
|
|
}
|
|
|
|
|