From 3fbe17e9e103d798d8a8670772d235a48ce98fcc Mon Sep 17 00:00:00 2001 From: Ferran Pons Date: Thu, 7 Dec 2017 18:56:47 +0100 Subject: [PATCH] first attempt to solve FX issues --- ZombustersInstaller/Product.wxs | 4 +- .../BloomPostProcess/BloomComponent.cs | 3 +- ZombustersWindows/Content/Content.mgcb | 18 +++++++ ZombustersWindows/Content/fx/BloomCombine.fx | 51 ++++++++++++++++++ .../Content/fx/BloomCombine.mgfxo | Bin 0 -> 959 bytes ZombustersWindows/Content/fx/BloomExtract.fx | 25 +++++++++ .../Content/fx/BloomExtract.mgfxo | Bin 0 -> 493 bytes ZombustersWindows/Content/fx/GaussianBlur.fx | 33 ++++++++++++ .../Content/fx/GaussianBlur.mgfxo | Bin 0 -> 1095 bytes ZombustersWindows/MyGame.cs | 6 +-- ZombustersWindows/ZombustersWindows.csproj | 12 ++--- 11 files changed, 137 insertions(+), 15 deletions(-) create mode 100644 ZombustersWindows/Content/fx/BloomCombine.fx create mode 100644 ZombustersWindows/Content/fx/BloomCombine.mgfxo create mode 100644 ZombustersWindows/Content/fx/BloomExtract.fx create mode 100644 ZombustersWindows/Content/fx/BloomExtract.mgfxo create mode 100644 ZombustersWindows/Content/fx/GaussianBlur.fx create mode 100644 ZombustersWindows/Content/fx/GaussianBlur.mgfxo diff --git a/ZombustersInstaller/Product.wxs b/ZombustersInstaller/Product.wxs index dddd372..a27e381 100644 --- a/ZombustersInstaller/Product.wxs +++ b/ZombustersInstaller/Product.wxs @@ -464,7 +464,7 @@ - + diff --git a/ZombustersWindows/BloomPostProcess/BloomComponent.cs b/ZombustersWindows/BloomPostProcess/BloomComponent.cs index 22b6c18..5b0643c 100644 --- a/ZombustersWindows/BloomPostProcess/BloomComponent.cs +++ b/ZombustersWindows/BloomPostProcess/BloomComponent.cs @@ -12,6 +12,7 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; +using System.IO; #endregion namespace ZombustersWindows @@ -81,8 +82,8 @@ protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); - bloomExtractEffect = Game.Content.Load("fx/BloomExtract"); bloomCombineEffect = Game.Content.Load("fx/BloomCombine"); + bloomExtractEffect = Game.Content.Load("fx/BloomExtract"); gaussianBlurEffect = Game.Content.Load("fx/GaussianBlur"); // Look up the resolution and format of our main backbuffer. diff --git a/ZombustersWindows/Content/Content.mgcb b/ZombustersWindows/Content/Content.mgcb index 312657d..a708b33 100644 --- a/ZombustersWindows/Content/Content.mgcb +++ b/ZombustersWindows/Content/Content.mgcb @@ -85,3 +85,21 @@ /processorParam:Quality=Best /build:Music/ThisCo_TakeItAway.ogg +#begin fx/BloomCombine.fx +/importer:EffectImporter +/processor:EffectProcessor +/processorParam:DebugMode=Auto +/build:fx/BloomCombine.fx + +#begin fx/BloomExtract.fx +/importer:EffectImporter +/processor:EffectProcessor +/processorParam:DebugMode=Auto +/build:fx/BloomExtract.fx + +#begin fx/GaussianBlur.fx +/importer:EffectImporter +/processor:EffectProcessor +/processorParam:DebugMode=Auto +/build:fx/GaussianBlur.fx + diff --git a/ZombustersWindows/Content/fx/BloomCombine.fx b/ZombustersWindows/Content/fx/BloomCombine.fx new file mode 100644 index 0000000..b8f25c8 --- /dev/null +++ b/ZombustersWindows/Content/fx/BloomCombine.fx @@ -0,0 +1,51 @@ +// Pixel shader combines the bloom image with the original +// scene, using tweakable intensity levels and saturation. +// This is the final step in applying a bloom postprocess. + +sampler BloomSampler : register(s0); +sampler BaseSampler : register(s1); + +float BloomIntensity; +float BaseIntensity; + +float BloomSaturation; +float BaseSaturation; + + +// Helper for modifying the saturation of a color. +float4 AdjustSaturation(float4 color, float saturation) +{ + // The constants 0.3, 0.59, and 0.11 are chosen because the + // human eye is more sensitive to green light, and less to blue. + float grey = dot(color, float3(0.3, 0.59, 0.11)); + + return lerp(grey, color, saturation); +} + + +float4 PixelShaderF(float2 texCoord : TEXCOORD0) : COLOR0 +{ + // Look up the bloom and original base image colors. + float4 bloom = tex2D(BloomSampler, texCoord); + float4 base = tex2D(BaseSampler, texCoord); + + // Adjust color saturation and intensity. + bloom = AdjustSaturation(bloom, BloomSaturation) * BloomIntensity; + base = AdjustSaturation(base, BaseSaturation) * BaseIntensity; + + // Darken down the base image in areas where there is a lot of bloom, + // to prevent things looking excessively burned-out. + base *= (1 - saturate(bloom)); + + // Combine the two images. + return base + bloom; +} + + +technique BloomCombine +{ + pass Pass1 + { + PixelShader = compile ps_3_0 PixelShaderF(); + } +} \ No newline at end of file diff --git a/ZombustersWindows/Content/fx/BloomCombine.mgfxo b/ZombustersWindows/Content/fx/BloomCombine.mgfxo new file mode 100644 index 0000000000000000000000000000000000000000..6c56e238f3e06d8e8f8ea81b8c63a16fe3eca498 GIT binary patch literal 959 zcma)4J1+!L6h1Sv%X;lj6dsl7G#Uy~c#PdOOTmgohQ^L$!Y2EW-BD1;HWUgJ8cGGl zCK^9RqwyCMqT@UF&SfMkaguW%=li~Mzk6qvbB>$P2F{MBH8LqiL|TmW1R1@g(Th%$ zb<>##ceFKp`B7YXzI!^K9!Y7SF=k*MLl%+O$fZJVh4+jnkQPz}b2$tw))(ANKEIZw zR;!i&hb9GGVRL8QtMB;%M1{rdnvL^q)US|RL^0>W!b+aK&DM&h*sC>ra))rk16kkL z_}MeY`(2Za2~*-edc0Y3y-%dG{{^D1H#`%E6Y`uBQ{0!&<32#U`!Vv`(Ir>6iEeLh zW@oww=N@yfGk`b}-@THO*Fk1;9sp}6&`06#mli5AoFA^>O||K>d1@*8w`bue;#m;j znL~NTlM2tw)$PAMi(c@-v+~SZ<(cdE=N3j8>^bBT^OWabeVSItCYrP;&UY7nLM_0a zNKL#GFk1qA?)O+z9?Kg{O<~@EL(qJTx>>wkVF4t<6rE1_;8>Qd~BsR%m z^rgLq-xf&;QNari>t0Z*RimmTtJ*oPrwiW0XL{Rw>k(PW+qSyp@t74$JU_G;0V?QCpd+m zA<2a%$LIi3(_qi1z`zc(-wkFCRF56dE1+y}`MDt(MXALZ`8g?YX$EF? tzL3<4lG38o;Kba5oYW$)E(S&(um;zPlA^@q5(Y-rfW+crLx%q#SpbVjL9hS- literal 0 HcmV?d00001 diff --git a/ZombustersWindows/Content/fx/GaussianBlur.fx b/ZombustersWindows/Content/fx/GaussianBlur.fx new file mode 100644 index 0000000..6d93524 --- /dev/null +++ b/ZombustersWindows/Content/fx/GaussianBlur.fx @@ -0,0 +1,33 @@ +// Pixel shader applies a one dimensional gaussian blur filter. +// This is used twice by the bloom postprocess, first to +// blur horizontally, and then again to blur vertically. + +sampler TextureSampler : register(s0); + +#define SAMPLE_COUNT 15 + +float2 SampleOffsets[SAMPLE_COUNT]; +float SampleWeights[SAMPLE_COUNT]; + + +float4 PixelShaderF(float2 texCoord : TEXCOORD0) : COLOR0 +{ + float4 c = 0; + + // Combine a number of weighted image filter taps. + for (int i = 0; i < SAMPLE_COUNT; i++) + { + c += tex2D(TextureSampler, texCoord + SampleOffsets[i]) * SampleWeights[i]; + } + + return c; +} + + +technique GaussianBlur +{ + pass Pass1 + { + PixelShader = compile ps_3_0 PixelShaderF(); + } +} \ No newline at end of file diff --git a/ZombustersWindows/Content/fx/GaussianBlur.mgfxo b/ZombustersWindows/Content/fx/GaussianBlur.mgfxo new file mode 100644 index 0000000000000000000000000000000000000000..9095e8096430412dfb1ec8641cbd67b16273feaa GIT binary patch literal 1095 zcmd^7yGjF55S^P%Hc|4@Lc}7h))pF2tTg1Qg+}twn8s{y^S~$}n}8yS7Fvph_zMHlkTr3o!mG>^I+E8l3?R^JBdi3ldm`DL6y=>N(AT3k|gt#-5JkRl@3 t_!o7&{y%B>!zJsaKj>L<={>n$5zLtb+isi3$ PreserveNewest - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - PreserveNewest @@ -1168,6 +1159,9 @@ PreserveNewest + + +