{"id":13,"date":"2007-04-26T00:50:58","date_gmt":"2007-04-25T23:50:58","guid":{"rendered":"http:\/\/blog.jbriguet.com\/?p=13"},"modified":"2010-01-24T23:10:55","modified_gmt":"2010-01-24T22:10:55","slug":"testing-my-new-plugin","status":"publish","type":"post","link":"https:\/\/blog.jbriguet.com\/?p=13","title":{"rendered":"Testing my new plugin :)"},"content":{"rendered":"<p>Well, i just installed <a href=\"http:\/\/www.lastengine.com\/syntax-highlighter-wordpress-plugin\" rel=external>this new plugin<\/a> and i&#8217;m trying it right now.<br \/>\nIt&#8217;s a simple formatting coloring plugin. The file is courtesy from <a href=\"http:\/\/www.ziggyware.com\/profile.php?lookup=277\">Jamezila<\/a> from his tutorial on <a href=\"http:\/\/www.ziggyware.com\/readarticle.php?article_id=89\">post processing bloom\/blur effects<\/a>.<\/p>\n<pre class=\"brush:csharp\">#region Using Statements\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing Microsoft.Xna.Framework;\r\nusing Microsoft.Xna.Framework.Audio;\r\nusing Microsoft.Xna.Framework.Content;\r\nusing Microsoft.Xna.Framework.Graphics;\r\nusing Microsoft.Xna.Framework.Input;\r\nusing Microsoft.Xna.Framework.Storage;\r\n#endregion\r\n\r\nnamespace XNAGame1\r\n{\r\n    public class Game1 : Microsoft.Xna.Framework.Game\r\n    {\r\n        GraphicsDeviceManager graphics;\r\n        ContentManager content;\r\n\r\n        Texture2D[] screenShot;\r\n        Effect bloomatic;\r\n        SpriteBatch sprite;\r\n\r\n        RenderTarget2D rTarg;\r\n        RenderTarget2D bloomTarg;\r\n\r\n        int currentPic;\r\n        double alphaFrame;\r\n        GamePadState oldState;\r\n\r\n        bool Additive;\r\n        bool HiRange;\r\n\r\n\r\n        public Game1()\r\n        {\r\n            graphics = new GraphicsDeviceManager(this);\r\n            content = new ContentManager(Services);\r\n        }\r\n\r\n        protected override void Initialize()\r\n        {\r\n            \/\/ TODO: Add your initialization logic here\r\n\r\n            base.Initialize();\r\n        }\r\n\r\n\r\n        protected override void LoadGraphicsContent(bool loadAllContent)\r\n        {\r\n            if (loadAllContent)\r\n            {\r\n                \/\/ TODO: Load any ResourceManagementMode.Automatic content\r\n            }\r\n\r\n            sprite = new SpriteBatch(graphics.GraphicsDevice);\r\n\r\n            rTarg = new RenderTarget2D(graphics.GraphicsDevice, 1024, 1024,\r\n                0, SurfaceFormat.Color);\r\n            bloomTarg = new RenderTarget2D(graphics.GraphicsDevice, 256, 256,\r\n                0, SurfaceFormat.Color);\r\n\r\n            screenShot = new Texture2D[8];\r\n            for (int i = 0; i < screenShot.Length; i++)\r\n            {\r\n                screenShot[i] = content.Load<Texture2D>(@\"gfx\/screen\" +\r\n                    (i + 1).ToString());\r\n            }\r\n\r\n            bloomatic = content.Load<Effect>(@\"fx\/bloomatic\");\r\n\r\n            \/\/ TODO: Load any ResourceManagementMode.Manual content\r\n        }\r\n\r\n\r\n         protected override void UnloadGraphicsContent(bool unloadAllContent)\r\n        {\r\n            if (unloadAllContent == true)\r\n            {\r\n                content.Unload();\r\n            }\r\n        }\r\n\r\n        protected override void Update(GameTime gameTime)\r\n        {\r\n            \/\/ Allows the default game to exit on Xbox 360 and Windows\r\n            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)\r\n                this.Exit();\r\n\r\n            if (GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed\r\n                && oldState.Buttons.A == ButtonState.Released)\r\n                    currentPic = (currentPic + 1) % screenShot.Length;\r\n\r\n            if (GamePad.GetState(PlayerIndex.One).Buttons.B == ButtonState.Pressed\r\n                && oldState.Buttons.B == ButtonState.Released)\r\n                    Additive = !Additive;\r\n            if (GamePad.GetState(PlayerIndex.One).Buttons.Y == ButtonState.Pressed\r\n                && oldState.Buttons.Y == ButtonState.Released)\r\n                    HiRange = !HiRange;\r\n\r\n            alphaFrame += (gameTime.ElapsedGameTime.TotalSeconds * 2.0);\r\n\r\n            oldState = GamePad.GetState(PlayerIndex.One);\r\n            \/\/ TODO: Add your update logic here\r\n\r\n            base.Update(gameTime);\r\n        }\r\n\r\n\r\n        protected override void Draw(GameTime gameTime)\r\n        {\r\n            \r\n\r\n            graphics.GraphicsDevice.SetRenderTarget(0, rTarg);\r\n            graphics.GraphicsDevice.Clear(Color.Black);\r\n            sprite.Begin();\r\n\r\n            sprite.Draw(screenShot[currentPic], new Rectangle(0, 0, 800, 600),\r\n                Color.White);\r\n\r\n            sprite.End();\r\n            graphics.GraphicsDevice.ResolveRenderTarget(0);\r\n\r\n            graphics.GraphicsDevice.SetRenderTarget(0, bloomTarg);\r\n\r\n            graphics.GraphicsDevice.Clear(Color.Black);\r\n\r\n            bloomatic.Parameters[\"mag\"].SetValue(0.008f);\r\n            bloomatic.Parameters[\"alpha\"].SetValue((float)(Math.Cos(alphaFrame) * 0.5 + 0.5));\r\n            \r\n            \r\n            bloomatic.Parameters[\"hirange\"].SetValue(HiRange);\r\n\r\n            bloomatic.Begin();\r\n            sprite.Begin(SpriteBlendMode.None, SpriteSortMode.Immediate,\r\n                SaveStateMode.SaveState);\r\n\r\n            EffectPass pass = bloomatic.CurrentTechnique.Passes[0];\r\n            pass.Begin();\r\n\r\n            sprite.Draw(rTarg.GetTexture(), new Rectangle(0, 0, 256, 256),\r\n                new Rectangle(0, 0, 800, 600), Color.White);\r\n\r\n            pass.End();\r\n            sprite.End();\r\n            bloomatic.End();\r\n\r\n            graphics.GraphicsDevice.ResolveRenderTarget(0);\r\n\r\n            graphics.GraphicsDevice.SetRenderTarget(0, null);\r\n\r\n            sprite.Begin();\r\n            sprite.Draw(rTarg.GetTexture(), new Rectangle(0, 0, 800, 600),\r\n                new Rectangle(0, 0, 800, 600), Color.White);\r\n            sprite.End();\r\n\r\n            if (Additive)\r\n            {\r\n                sprite.Begin(SpriteBlendMode.Additive);\r\n            }\r\n            else\r\n            {\r\n                sprite.Begin(SpriteBlendMode.AlphaBlend);\r\n            }\r\n            sprite.Draw(bloomTarg.GetTexture(), new Rectangle(0, 0, 800, 600),\r\n                Color.White);\r\n            sprite.End();\r\n\r\n            \/\/ TODO: Add your drawing code here\r\n\r\n            base.Draw(gameTime);\r\n        }\r\n    }\r\n}<\/pre>\n<p>And here is the shader he used. (Just for trying language marquers on a shader, and it looks like csharp marquer is the most appropriate)<\/p>\n<pre class=\"brush:cpp\">\/\/ bloomatic.fx\r\nsampler samplerState;\r\n\r\n\/\/Width to sample from\r\nfloat mag;\r\n\r\n\/\/Alpha value\r\nfloat alpha;\r\n\r\n\/\/Operate on a high range (0.5 - 1.0) or the full range (0.0 - 1.0)\r\nbool hirange;\r\n\r\nconst float2 offsets[12] = {\r\n-0.326212, -0.405805,\r\n-0.840144, -0.073580,\r\n-0.695914,  0.457137,\r\n-0.203345,  0.620716,\r\n0.962340, -0.194983,\r\n0.473434, -0.480026,\r\n0.519456,  0.767022,\r\n0.185461, -0.893124,\r\n0.507431,  0.064425,\r\n0.896420,  0.412458,\r\n-0.321940, -0.932615,\r\n-0.791559, -0.597705,\r\n};\r\n\r\nstruct PS_INPUT\r\n{\r\nfloat2 TexCoord : TEXCOORD0;\r\n};\r\n\r\nfloat4 bloomEffect(PS_INPUT Input) : COLOR0 {\r\nfloat4 sum = tex2D(samplerState, Input.TexCoord);\r\nfloat4 tex;\r\n\r\n\/\/accumulate the color values from 12 neighboring pixels\r\nfor(int i = 0; i < 12; i++){\r\ntex = tex2D(samplerState, Input.TexCoord + mag * offsets[i]);\r\n\r\nsum += tex;\r\n}\r\n\/\/average the sum\r\nsum \/= 13;\r\n\r\n\/\/fix alpha\r\nsum.a = alpha;\r\n\r\n\/\/expand the higher range if applicable\r\nif (hirange) {\r\nsum.r = (sum.r - 0.5) * 2.0;\r\nsum.g = (sum.g - 0.5) * 2.0;\r\nsum.b = (sum.b - 0.5) * 2.0;\r\n}\r\n\r\nreturn sum;\r\n}\r\n\r\ntechnique Bloom {\r\npass P0{\r\nPixelShader = compile ps_2_0 bloomEffect();\r\n}\r\n\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Well, i just installed this new plugin and i&#8217;m trying it right now. It&#8217;s a simple formatting coloring plugin. The file is courtesy from Jamezila from his tutorial on post processing bloom\/blur effects. #region Using Statements using System; using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Storage; #endregion namespace XNAGame1 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4],"tags":[],"class_list":["post-13","post","type-post","status-publish","format-standard","hentry","category-4"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p6Eo2-d","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blog.jbriguet.com\/index.php?rest_route=\/wp\/v2\/posts\/13","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.jbriguet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.jbriguet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jbriguet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jbriguet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=13"}],"version-history":[{"count":3,"href":"https:\/\/blog.jbriguet.com\/index.php?rest_route=\/wp\/v2\/posts\/13\/revisions"}],"predecessor-version":[{"id":43,"href":"https:\/\/blog.jbriguet.com\/index.php?rest_route=\/wp\/v2\/posts\/13\/revisions\/43"}],"wp:attachment":[{"href":"https:\/\/blog.jbriguet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jbriguet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jbriguet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}