Question

I set up a basic pixel shader (right now, its configured for testing), and it doesn't seem to do anything. I set it up like so:

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();
    }
}

with the loading code like:

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

and use code is:

            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();

Loading seems to work fine, and there are no errors thrown when I use that method to render the texture, but it acts like the effect code isn't in there. It can't be that I'm using the wrong version of shaders (I tested with 2.0 and 1.1 versions), so why? (Using XNA 3.1)

Was it helpful?

Solution

You're returning 0 for every pixel. You have commented out any code that would return a different value than 0. 0 is black and if you're doing any sort of render you'll either get black (if the blend mode shows this as a color) or no change (if the blend mode multiplies the result). You can of course (if you were just attempting to see if the shader is being loaded and operated) try using an oddball color. Neon green anyone? Then, once you confirm it is being at least processed, start uncommenting that code and assessing the result.

Finally, if Bloom is what you're after, Microsoft has a very useful sample you will probably learn a lot from here:

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

OTHER TIPS

If you're using XNA 4.0, see what Shawn Hargreaves has to say about this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top