Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8289003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:24:21+00:00 2026-06-08T12:24:21+00:00

I’ve come across strange behavior of pixel shader in WPF. This problem is 100%

  • 0

I’ve come across strange behavior of pixel shader in WPF.

This problem is 100% reproducible, so I wrote small demo program. You can download source code here.

The root of all evil is tiny class titled MyFrameworkElement:

internal sealed class MyFrameworkElement : FrameworkElement
{
    public double EndX
    {
        get
        {
            return (double)this.GetValue(MyFrameworkElement.EndXProperty);
        }
        set
        {
            this.SetValue(MyFrameworkElement.EndXProperty, value);
        }
    }

    public static readonly DependencyProperty EndXProperty =
        DependencyProperty.Register("EndX",
            typeof(double),
            typeof(MyFrameworkElement),
            new FrameworkPropertyMetadata(0d, FrameworkPropertyMetadataOptions.AffectsRender));

    protected override void OnRender(DrawingContext dc)
    {
        dc.DrawLine(new Pen(Brushes.Red, 2), new Point(0, 0), new Point(this.EndX, 100));
        dc.DrawLine(new Pen(Brushes.Green, 3), new Point(10, 300), new Point(200, 10));
    }
}

As you can see this framework element renders 2 lines: lower line has permanent coordinates but upper line depends on EndX dependency property.

So this framework element is target for pixel shader effect. For simplicity’s sake I use grayscale shader effect found here. So I applied GrayscaleEffect to MyFrameworkElement. You can see result, it looks nice.

Until I increase EndX property drastically.

Small line is blurred and big line is fine!

But if I remove grayscale effect, all lines will look as they should.

Can anybody explain what’s the reason of this blurring?
Or even better how can I solve this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:24:22+00:00Added an answer on June 8, 2026 at 12:24 pm

    With a custom pixel shader it has to create an Intermediate Bitmap and then that texture gets sampled by the pixel shader.

    You’re creating a massive rendering, so your hitting some limitation in the render path.

    A quick fix is to clip what you want rendered as follows:

    Geometry clip = new RectangleGeometry(new Rect(0,0,this.ActualWidth, this.ActualHeight));
    
    dc.PushClip(clip);
    
    dc.DrawLine(new Pen(Brushes.Red, 2), new Point(0, 0), new Point(this.EndX, 100));
    dc.DrawLine(new Pen(Brushes.Green, 3), new Point(200, 10), new Point(10, 300));
    
    dc.Pop();
    

    UPDATE:

    One theory is that it’s using a filter to scale the bitmap when it exceeds the maximum texture size (which can vary depending on your graphics card architecture)…so it goes through the pixel shader at a different size….then it gets scaled back to original size.

    Thus the scaling filter is causing artifacts depending on the content of your bitmap (i.e. horizontal lines and vertical lines survive a scale down and up better than diagonal lines).

    .NET 4 changed the default filter it uses for filtering to a lowerquality one…Bilinear, instead of Fant…maybe this impacts the quality that you get too.

    http://10rem.net/blog/2010/05/16/more-on-image-resizing-in-net-4-vs-net-35sp1-bilinear-vs-fant

    UPDATE2:

    This kind of confirms what I was thinking above.

    If you use the Windows Performance Toolkit/Suite (part of Windows SDK), then you can see the Video Memory being gobbled up in the orange graph while you increase the slider value because a bigger Intermediate Bitmap texture is being created. It keeps increasing until it hits a limit, then it flatlines…and thats when the pixelation becomes evident.

    enter image description here

    UPDATE3:

    If you set the render mode to the “Software Renderer” (Tier 0) then you can see how it copes with rendering such a large visual – the artifacts start appearing at a different point….presumably because the texture size limit is larger/different to your GPUs. But the artifacts still appear because it’s using a Bilinear filter internally.

    Trying to use RenderOptions.SetBitmapScalingMode to up the filter to Fant doesn’t seem to change the rendering quality in any way (I guess because it isn’t honoured when it goes through the custom pixel shader path).

    Put this in Application_Startup to see the software renderer results:

    RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I know there's a lot of other questions out there that deal with this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.