0
votes

Have made a hlsl pixel shader for adding outline/shadow for subtitles. My problem is that I use Shazzam - Shader Editor to see how it's going to like, the result is quite different in my program. For example:

I have used a .png with text to make the image for Shazzam

I have used a .png with text to make the image for Shazzam Editor, but as you can see there is just a little bit of a hint in the program (video player) and I don't get it..

My code:

struct VertexShaderInput
{
    float4 Position : POSITION0;    // model xyzw
    float2 uv0: TEXCOORD0;          // texture 0 uv
};

struct VertexShaderOutput
{
    float4 Position : POSITION0;    // model xyzw
    float2 uv0: TEXCOORD0;          // texture 0 uv
};

VertexShaderOutput vs(VertexShaderInput input)
{
    VertexShaderOutput output;
    output.Position = input.Position;
    output.uv0 = input.uv0; 
    return output;
}

sampler2D YTexture : register(s0); 

struct PixelShaderInput
{
    float2 uv0: TEXCOORD0;          // texture 0 uv
    float4 color: COLOR;            // color
};

float4 ps_osd(PixelShaderInput input): COLOR {
    float4 px = tex2D(YTexture, input.uv0);
    const float d = 0.2;

    float cnt = 0;
    float a = 0;
    for (float x = -0.02*d; x < 0.02*d; x += 0.028*d)
    {
        a += tex2D(YTexture,  input.uv0 + float2(x, 0)).a;
        a += tex2D(YTexture,  input.uv0 + float2(0, x)).a;
        a += tex2D(YTexture,  input.uv0 + x).a;
        cnt += 0.1;
    }
    a /= cnt;

    float4 s = a;
    s.rgb = 0;
    float4 r = float4(px.rgb*px.a + s.rgb*(1-px.a), max(px.a, a));

    return r;
}

The actually pixel shader is ps_osd() and vs is the vertex shader. I'm quite new to HLSL, but I can't see why it shouldn't work. The video is on a 1280x720, I have tried to use the same size image with the shader in Shazzam to see if it could a size issue but no.

Can you guys see if I have missed something? Have tried s.r = 0; s.g = 0; s.b = 0; s.a = 1;..

Hope you can help :)

1

1 Answers

0
votes

After a lot of trial and error, it seemed it didn't like the for loop. So am just using it without the for loop and with constants for now.

It's an answer not really a solution..