0

我设置了一个基本的像素着色器(现在,它被配置为测试),它似乎没有做任何事情。我是这样设置的:

uniform extern texture ScreenTexture;    
const float bloomThreshhold = 0.4;
const float existingPixelColorMult = 1.1;

sampler ScreenS = sampler_state
{
    Texture = <ScreenTexture>;    
};

float4 BloomedColor(float2 texCoord: TEXCOORD0) : COLOR
{
    // pick a pixel on the screen for this pixel, based on
    // the calculated offset and direction
    float2 temp = texCoord;
    temp.x += 1;
    float4 mainPixelColor = 0;    
    /*
    float4 pixelPlus1X = tex2D(ScreenS, temp);
    temp.x -= 2;
    float4 pixelMinus1X = tex2D(ScreenS, temp);
    temp.x += 1;
    temp.y += 1;
    float4 pixelPlus1Y = tex2D(ScreenS, temp);
    temp.y -= 2;
    float4 pixelMinus1Y = tex2D(ScreenS, temp);
    */

    return mainPixelColor;
}

technique Bloom
{
    pass P0
    {
        PixelShader = compile ps_1_1 BloomedColor();
    }
}

加载代码如下:

        glowEffect = Content.Load<Effect>("GlowShader");
        glowEffect.CurrentTechnique = glowEffect.Techniques[0];

使用代码是:

            spriteBatch.Begin();
            glowEffect.Begin();
            glowEffect.CurrentTechnique.Passes[0].Begin();
            spriteBatch.Draw(screenImage, Vector2.Zero, Color.White);
            spriteBatch.End();
            glowEffect.CurrentTechnique.Passes[0].End();
            glowEffect.End();

加载似乎工作正常,并且当我使用该方法渲染纹理时没有抛出任何错误,但它就像效果代码不在那里一样。不可能是我使用了错误版本的着色器(我用 2.0 和 1.1 版本测试过),那为什么呢?(使用 XNA 3.1)

4

2 回答 2

1

您为每个像素返回 0。您已经注释掉了任何会返回不同于 0 的值的代码。0 是黑色,如果您正在执行任何类型的渲染,您要么会变黑(如果混合模式将其显示为颜色)或没有变化(如果混合模式将结果相乘)。您当然可以(如果您只是试图查看着色器是否正在加载和操作)尝试使用奇怪的颜色。霓虹绿有人吗?然后,一旦您确认它至少正在被处理,开始取消注释该代码并评估结果。

最后,如果 Bloom 是您所追求的,Microsoft 有一个非常有用的示例,您可能会从这里学到很多东西:

http://create.msdn.com/en-US/education/catalog/sample/bloom

于 2011-11-03T16:00:43.790 回答
0

如果您使用的是 XNA 4.0,请查看Shawn Hargreaves 对此有何评论

于 2011-11-03T13:33:52.657 回答