应用的着色器后效果模糊的照片

应用的着色器后效果模糊的照片

本文介绍了应用的着色器后效果模糊的照片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到在WPF像素着色器的怪异行为。

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

这问题是100%可重复的,所以我写了小的演示程序。你可以下载源代码。所以我申请到GrayscaleEffect MyFrameworkElement。你可以看到的结果,它看起来不错。

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.

直到我增加EndX财产急剧下降。

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?

推荐答案

通过自定义像素着色器它具有创建中间位图,然后纹理得到由像素着色器取样。

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改变了它用来过滤到lowerquality 1 ...双线性,而不是凡特...也许这会影响你获得高质量的默认过滤器了。

.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.

UPDATE2:

这样的印证了我的上述想法。

This kind of confirms what I was thinking above.

如果您使用Windows性能工具包/套件(Windows SDK中的一部分),然后就可以看到显存被吞噬了在橙色曲线,而你增加滑块值,因为正在创建一个更大的中级位图纹理。它不断增加,直到达到一个极限,那么它flatlines ...和多数民众赞成在像素化变得明显

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.

UPDATE3:

如果设置渲染模式为软件渲染器(第0层),那么你可以看看它是如何与3D渲染这样的大型视觉科佩斯 - 文物开始出现在不同的点....大概是因为纹理大小限制较大/不同的你的GPU。但文物仍然会出现,因为它是一个使用双线性过滤器内部。

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.

尝试使用RenderOptions.SetBitmapScalingMode最多过滤器范特似乎并没有改变渲染质量任何方式(我猜是因为它是不遵守当它通过自定义像素着色器路径)

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).

将这个在Application_Startup看到软件渲染的结果:

Put this in Application_Startup to see the software renderer results:

RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;

这篇关于应用的着色器后效果模糊的照片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 04:13