Skip to content

DefaultShaders.SimpleFragmentShaderHLSL Field

Definition

Namespace: Brine2D.Rendering.SDL.Shaders

Fragment shader HLSL source. Handles textured quads, font rendering, and SDF circles. UV sentinel ranges: [0,1] — normal texture/sprite quad \(sample UVs directly\). [2,3] — SDF filled circle \(TexCoord emitted by DrawCircleFilled\). [4,5] — font atlas glyph \(TexCoord = actual UV \+ \(4,4\), decoded here).

C#
public const string SimpleFragmentShaderHLSL = "
struct PSInput
{
    float4 Position : SV_Position;
    float4 Color    : COLOR;
    float2 TexCoord : TEXCOORD0;
};

Texture2D Texture : register(t0, space2);
SamplerState Sampler : register(s0, space2);

float4 main(PSInput input) : SV_Target
{
    float2 uv = input.TexCoord;

    if (uv.x >= 1.5 && uv.x < 3.5)
    {
        float2 circleUV = uv - 2.0;
        float dist = length(circleUV - 0.5);
        float fw = fwidth(dist) * 0.5;
        float alpha = 1.0 - smoothstep(0.5 - fw, 0.5 + fw, dist);
        if (alpha <= 0.0) discard;
        return float4(input.Color.rgb, input.Color.a * alpha);
    }

    if (uv.x >= 3.5)
    {
        float2 fontUV = uv - float2(4.0, 4.0);
        float4 texColor = Texture.Sample(Sampler, fontUV);
        return float4(input.Color.rgb, input.Color.a * texColor.a);
    }

    float4 texColor = Texture.Sample(Sampler, uv);
    return texColor * input.Color;
}
";

Field Value

System.String