简体   繁体   中英

Size of WPF Textblock used in a shader cannot be resized

I have a shader that I want to apply to a WPF TextBlock. However, my shader always seems to be limited to the texture that is equal to the bounding box of the text. And, as result I cannot access pixels outside the bounding box (eg to add a large border or color effect). Everything I've tried to increase the bounding box, either in XAML or C#, before applying the shader has failed.

This picture shows the effect of applying a simple blue overlay shader to the text. It shows the extents of the bounding box and the pixels that the shader has access to. So the question is really how to expand the text bounding box before calling the shader? Hope someone has been through this problem before...

I included the simply shader code below:

sampler2D texSampler : register(S0);
float threshold : register (C0);
float4 txtColor : register (C1);

float4 main(float2 uv : TEXCOORD) : COLOR
{
    float4 color = tex2D(texSampler, uv);

    color.r = txtColor[0];
    color.g = txtColor[1];
    color.b = txtColor[2];

    return color;
}

Sample text and bounding box

Here's what's going on - If a background is not specified for the TextBlock, then wpf puts a tight bounding box around the text regardless of the width and height specified for the TextBlock. To fix the problem just set the Background color to Transparent for the TextBlock.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM