//Vertex Shader input struct VS_INPUT { float4 pos : POSITION; float2 tex0 : TEXCOORD0; }; //Vertex Shader output struct VS_OUTPUT { float4 pos : POSITION; float2 tex0 : TEXCOORD0; }; // Texture samplers texture Original; sampler2D OriginalSampler = sampler_state { texture = ; mipfilter = LINEAR; minfilter = LINEAR; magfilter = LINEAR; AddressU = Wrap; AddressV = Wrap; }; texture Glow; sampler2D GlowSampler = sampler_state { texture = ; mipfilter = LINEAR; minfilter = LINEAR; magfilter = LINEAR; AddressU = Wrap; AddressV = Wrap; }; texture OldGlow; sampler2D OldGlowSampler = sampler_state { texture = ; mipfilter = LINEAR; minfilter = LINEAR; magfilter = LINEAR; AddressU = Wrap; AddressV = Wrap; }; texture SourceTexture; sampler2D SourceTextureSampler = sampler_state { texture = ; mipfilter = LINEAR; AddressU = Clamp; AddressV = Clamp; }; //Uniform parameters. uniform float4x4 modelViewProjection; // Width and height of the viewport uniform float dsWidth, dsHeight; // Number of glow passes and the gain uniform float GlowPasses, GlowGain; // Blur sample strecth uniform float Stretch; // Simple vertex shader with MVP VS_OUTPUT VS_myVertexShader(in VS_INPUT input){ VS_OUTPUT output0; output0.pos = mul(input.pos,modelViewProjection); output0.tex0 = input.tex0; return output0; } // Vertex shader for the full screen triangle rendering VS_OUTPUT VS_myVertexBlurShader(in VS_INPUT input){ VS_OUTPUT output0; output0.pos = mul(input.pos,modelViewProjection); output0.tex0 = input.tex0 + 0.5*float2(1.0f/dsWidth, 1.0f/dsHeight); return output0; } // Simple texturing shader half4 PS_Cube(in float2 tex0:TEXCOORD0) : COLOR { half4 texLookUp; texLookUp.rgba = tex2D(SourceTextureSampler,tex0).rgba; return texLookUp; } // Glow cutting shader // Based on the alpha value of the texture half4 PS_CubeGlow(in float2 tex0:TEXCOORD0) : COLOR { half4 texLookUp; texLookUp.rgba = tex2D(SourceTextureSampler,tex0).rgba; if (texLookUp.a > 0.6f) texLookUp = half4(0,0,0,0); return texLookUp; } // Final compositing shader // Original + Glow -> Final image half4 PS_Final(in float2 tex0:TEXCOORD0) : COLOR { half4 Orig; Orig.rgba = tex2D(OriginalSampler,tex0).rgba; half4 Glow; Glow.rgba = tex2D(GlowSampler,tex0).rgba; return Orig + Glow; } // Horizontal blur with addition from the blur history // Separated Gaussian blur half4 PS_Blur_h(in float2 tex0:TEXCOORD0) : COLOR { half4 texLookUp_h; texLookUp_h = tex2D(GlowSampler, float2(tex0.x-(3.86979f*Stretch/dsWidth / 2), tex0.y)) + tex2D(GlowSampler, float2(tex0.x-(1.72291f*Stretch/dsWidth / 2), tex0.y)) + tex2D(GlowSampler, tex0) + tex2D(GlowSampler, float2(tex0.x+(1.72291f*Stretch/dsWidth / 2), tex0.y)) + tex2D(GlowSampler, float2(tex0.x+(3.86979f*Stretch/dsWidth / 2), tex0.y)); half4 oldGlow = tex2D(OldGlowSampler, tex0); return texLookUp_h / 5 + oldGlow * GlowGain; } // Vertical blur with addition from the blur history // Separated Gaussian blur half4 PS_Blur_v(in float2 tex0:TEXCOORD0) : COLOR { half4 texLookUp_v; texLookUp_v = tex2D(GlowSampler, float2(tex0.x, tex0.y-(3.86979f*Stretch/dsHeight / 2)))+ tex2D(GlowSampler, float2(tex0.x, tex0.y-(1.72291f*Stretch/dsHeight / 2)))+ tex2D(GlowSampler, tex0)+ tex2D(GlowSampler, float2(tex0.x, tex0.y+(1.72291f*Stretch/dsHeight / 2)))+ tex2D(GlowSampler, float2(tex0.x, tex0.y+(3.86979f*Stretch/dsHeight / 2))); half4 oldGlow = tex2D(OldGlowSampler, tex0); return texLookUp_v / 5 + oldGlow * GlowGain; } // Original dice technique Cube { pass P0{ // compiler directives VertexShader = compile vs_2_0 VS_myVertexShader(); PixelShader = compile ps_2_0 PS_Cube(); } } // Glow cut technique CubeGlow { pass P0{ // compiler directives VertexShader = compile vs_2_0 VS_myVertexShader(); PixelShader = compile ps_2_0 PS_CubeGlow(); } } // Horizontal blur technique Blur_h { pass P0{ // compiler directives VertexShader = compile vs_2_0 VS_myVertexBlurShader(); PixelShader = compile ps_2_0 PS_Blur_h(); } } // Vertical blur technique Blur_v { pass P0{ // compiler directives VertexShader = compile vs_2_0 VS_myVertexBlurShader(); PixelShader = compile ps_2_0 PS_Blur_v(); } } // Final compositing technique Final { pass P0{ // compiler directives VertexShader = compile vs_2_0 VS_myVertexShader(); PixelShader = compile ps_2_0 PS_Final(); } }