Arkcann

I've started experimenting with full-screen post-processing after using a tutorial on Ramblings of A Hazy Mind (tutorial number 8 I believe), that lets you modify many things using pixel shaders, unfortunately I'm unable to find good examples of post-processing effects that will work with this implementation. I'm not really looking for a different way of doing this, rather I'd like to port an effect I've had trouble with into something that will work with Hazy Mind's system. The main one I've had a problem with is a Blur/Glow effect that I found on the XNA5D site, unfortunately it also implements a vertex shader which I have no knowledge of (I know very little about pixel shaders also) so I don't know how to get it to work without involving 3D models, here is the code (probably going to have some smiley faces or something). For those who don't know, Hazy Mind's post-processing system only uses pixel shaders (as far as I know). Also, if anyone has any effects they've made for this type of thing I'd love to see them, thanks!

const float2 offsets[12] = {

-0.326212, -0.405805,

-0.840144, -0.073580,

-0.695914, 0.457137,

-0.203345, 0.620716,

0.962340, -0.194983,

0.473434, -0.480026,

0.519456, 0.767022,

0.185461, -0.893124,

0.507431, 0.064425,

0.896420, 0.412458,

-0.321940, -0.932615,

-0.791559, -0.597705,

};

float BlurScale;

Texture UserTexture;

sampler SamplerState = sampler_state

{

texture = <UserTexture>;

magfilter = POINT;

minfilter = POINT;

mipfilter = POINT;

AddressU = clamp;

AddressV = clamp;

};

struct VertexToPixel

{

float4 Position : POSITION;

float2 TexCoord0 : TEXCOORD0;

};

VertexToPixel SimpleVertexShader( float4 inPos : POSITION, float2 tex0 : TEXCOORD0)

{

VertexToPixel Output = (VertexToPixel)0;

Output.Position = inPos;

Output.TexCoord0 = tex0;

return Output;

}

float4 ApplyBlur(VertexToPixel inp) : COLOR

{

float4 sum = tex2D(SamplerState, inp.TexCoord0);

float4 Gold = float4(255, 178, 0, 0);

for(int i = 0; i < 12; i++)

{

sum += tex2D(SamplerState, inp.TexCoord0 + BlurScale * offsetsIdea);

}

sum /= 13;

sum.a = 1.0f;

return sum;

}

float4 ApplyBlurMore(VertexToPixel inp) : COLOR

{

float4 sum = tex2D(SamplerState, inp.TexCoord0);

float4 Gold = float4(255, 178, 0, 0);

for(int i = 0; i < 12; i++)

{

sum += tex2D(SamplerState, inp.TexCoord0 + (2*BlurScale) * offsetsIdea);

}

sum /= 13;

sum.a = 0.5f;

return sum;

}

float4 ApplyBlurMed(VertexToPixel inp) : COLOR

{

float4 sum = tex2D(SamplerState, inp.TexCoord0);

float4 Gold = float4(255, 178, 0, 0);

for(int i = 0; i < 12; i++)

{

sum += tex2D(SamplerState, inp.TexCoord0 + (1.5*BlurScale) * offsetsIdea);

}

sum /= 13;

sum.a = 0.8f;

return sum;

}

float4 ApplyTexture(VertexToPixel inp) : COLOR

{

float4 TextureColor = tex2D(SamplerState, inp.TexCoord0);

TextureColor.a = 1.0f;

return TextureColor;

}

technique Blur

{

pass P0

{

VertexShader = compile vs_2_0 SimpleVertexShader();

PixelShader = compile ps_2_0 ApplyBlur();

}

pass P1

{

VertexShader = compile vs_2_0 SimpleVertexShader();

PixelShader = compile ps_2_0 ApplyBlurMed();

}

pass P2

{

VertexShader = compile vs_2_0 SimpleVertexShader();

PixelShader = compile ps_2_0 ApplyBlurMore();

}

pass P3

{

VertexShader = compile vs_2_0 SimpleVertexShader();

PixelShader = compile ps_2_0 ApplyTexture();

}

}



Re: XNA Game Studio Express Post-Processing Woes

Bill Reiss

As far as I know, from the limited experience I've had in the past couple of weeks with shaders, you can only use pixel shaders and not vertex shaders in the postprocess. This is the same limitation you have with SpriteBatch and custom effects. The reason for this, I assume, is because you really don't have any vertex data by the time you're in the postprocessor, you only have a flat texture.

Bill






Re: XNA Game Studio Express Post-Processing Woes

Leaf.

Post processing as used here just means rendering something that results in a change to the whole screen. There is no difference between rendering a post process effect, rendering a 3D model or rendering some 2D sprites - they all go through the same graphics pipeline (which you can read about here) with vertex processing, pixel processing, blending, fog, etc.

The Hazy Mind tutorial doesn't use a vertex shader because it is using SpriteBatch and SpriteBatch uses it's own vertex shader, the tutorial just replaces the SpriteBatch pixel shader with whatever pixel shader is in the custom effect. There is no difference to rendering your own rectangle (2 triangles) on the screen and supplying your own vertex shader and pixel shader (this is what SpriteBatch is doing internally) but using a SpriteBatch saves writing the code for that.

If you want to use the fx file you posted with the same setup as the Hazy Mind tutorial then you could start with removing the lines that set the VertexShader state in each pass so that you don't replace the SpriteBatch vertex shader.

Cheers,
Leaf.






Re: XNA Game Studio Express Post-Processing Woes

Arkcann

Thanks, I removed the vertex shader as well as the pass that draws the texture (sort of undos all the blurring when used for post-processing which isn't helpful) and it works great, thanks again!