需要一个简单的像素着色器代码,只需将输入纹理绘制到屏幕(视口)

发布于 2024-10-01 18:57:01 字数 747 浏览 0 评论 0原文

我需要一个简单的着色器代码与我的 XNA 应用程序一起使用,该代码仅将给定的纹理绘制到屏幕上。本质上,我正在尝试进行后期处理,但我的目标是不应用任何后期处理效果,而只是应用显示纹理本身..

我尝试了以下像素着色器代码,但遇到了一些问题(如下所述):

sampler textureSampler;

float4 PostProcessingPS(float2 texCoord: TEXCOORD0, float4 Position : POSITION0) : COLOR0
{
    float4 color = tex2D(textureSampler,texCoord);
    return color;
}

technique PostProcessingEffect
{
    pass Pass1
    {
        PixelShader = compile ps_2_0 PostProcessingPS();
    }
}

我遇到的问题是没有绘制整个纹理..仅由于某种原因正在绘制边界?!即使关于边界,我也不确定它们是否被正确绘制..我只是说它们被绘制是因为那里的像素值随着场景本身的变化而变化..

这应该是这样的: alt text

这就是我所看到的: alt text

有什么想法吗?

I need a simple shader code to use with my XNA application which just draws a given texture to the screen .. Essentially, I'm trying to do post processing, but my aim here is to not apply any post processing effect, but to just display the texture as itself ..

I tried the following pixel shader code but I'm getting some problem (explained below):

sampler textureSampler;

float4 PostProcessingPS(float2 texCoord: TEXCOORD0, float4 Position : POSITION0) : COLOR0
{
    float4 color = tex2D(textureSampler,texCoord);
    return color;
}

technique PostProcessingEffect
{
    pass Pass1
    {
        PixelShader = compile ps_2_0 PostProcessingPS();
    }
}

The issue I'm getting is that the entire texture is not drawn .. Only the borders are being drawn for some reason ?! And even regarding the borders, I'm not sure if they are being drawn properly .. I'm just saying they are being drawn because the pixel values there change as the scene itself changes ..

This is what it should be like:
alt text

And this is what I see:
alt text

Any ideas ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光无声 2024-10-08 18:57:01

我最好的建议是只在绘制代码中显示纹理。为什么不能在应用程序中而不是在像素着色器中执行此操作?

如果您真的想做像素着色器,则需要提供更多代码。绘制的内容取决于纹理坐标,因此我需要查看您的绘制代码来回答这个问题。

My best advice is to just display the texture in your draw code. Why exactly can't you do this in the application instead of in the pixel shader?

If you REALLY want to do the pixel shader, you'll need to give more code. What is drawn is dependent on the texture coordinates, so i would need to see your draw code to answer this.

故事还在继续 2024-10-08 18:57:01

你是如何绘制全屏四边形的?您的顶点缠绕可能与当前剔除模式相反,因此三角形被背面剔除。您可以通过在 XNA 3.x 中使用 GraphicsDevice.RenderState.CullMode = CullMode.None 或在 4.0 中使用 GraphicsDevice.RasterizerState = RasterizerState.CullNone 来检查这一点。

您在屏幕中心看到的对角线是因为您缺少半像素偏移,无法将纹素与屏幕上的像素正确对齐。当您将顶点位置从顶点着色器传递到像素着色器时,尝试向顶点位置添加偏移量,如下所示:

Position.x -= 1.0 / ViewportSize.x;

Position.y += 1.0 / ViewportSize.y;

其中 ViewportSize 包含视口的像素尺寸,例如 (1024,768)。

How are you drawing the full-screen quad? You may have the vertex winding opposite to the current cull mode so the triangles are being backface culled. You can check this by using GraphicsDevice.RenderState.CullMode = CullMode.None in XNA 3.x, or GraphicsDevice.RasterizerState = RasterizerState.CullNone in 4.0.

The diagonal line you're seeing down the center of the screen is because you're missing the half-pixel offset to correctly align texels to pixels on screen. Try adding an offset to your vertex positions when you pass them from the vertex shader to the pixel shader like this:

Position.x -= 1.0 / ViewportSize.x;

Position.y += 1.0 / ViewportSize.y;

Where ViewportSize contains the pixel dimensions of your viewport, (1024,768) for example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文