Article: Derived Effect Classes in XNA 4
by Dave Carlile

One of the nice API changes in XNA 4.0 is the simplified syntax used when drawing with an Effect. In previous versions you would draw things like this:
effect.Begin();
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Begin();
// draw your stuff
pass.End();
}
effect.End();
Now you can draw things like this, with EffectPass.Apply handling all the magic:
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
// draw your stuff
}
Related to this is the new Effect.OnApply virtual method which gets called by EffectPass.Apply. By overriding this method in a derived class you can do things like perform pre-shader calculations and set shader parameters from properties. This is how BasicEffect and the other new standard shaders work, and it would be nice to be able to duplicate that functionality in our own derived effects.
Ideally we would like to be able to do something like this:
MyEffect effect = Content.Load<MyEffect>(“myeffect”);
effect.World = Matrix.Identity;
effect.Color = Color.Blue;
...
effect.Apply();
...
The first line is where we begin running into issues. In order to load a derived class using the content pipeline you have to write your own content processor, reader, and writer, for every single class. You might think that you could load an Effect instance using the content manager, then create an instance of your derived Effect class and pass in the code. Unfortunately, there is no way to get at the code in the Effect instance (okay, that is not entirely true, but this solution requires the full Game Studio install).
If you want to store the class properties (e.g. MyEffect.World, MyEffect.Color) as content then extending the content pipeline for each class is your best option. But what if you don't need to store the properties? What if you just want a cleaner interface to your shaders? Extending the pipeline each time for these cases seems like a lot of unnecessary work.
A Solution
This remainder of this tutorial will show you how to load any derived Effect class from the content pipeline without having to extend the pipeline for each class. To accomplish this we're going to create a content pipeline extension library that will compile the effect into an intermediate object that will let us get at the compiled code. We will also create a game library that will define the intermediate class so we can get to it at run time. And finally we’ll add an extension method that will do the work of loading our derived Effect class.
Brute Force 2D Shadows
Because he is a much less busy man (it would seem), Charles Humprey made his own implementation for shader-based dynamic 2D shadows and posted it for everyone to see. You can read about it here.
Article : Sun- and Lens Flare as a Post Process
by Charles Humphrey

Now this sample has come from my current XNA toy which is the Blacksun engine I am currently writing in XNA 3.1. It uses deferred lighting, instancing and a post processing framework that I found on a great site here, all I had to do was make it engine ready.
If you want to have a look at the effect in the engine you can see it here.
This sample is just one of the elements from the post processing framework in the engine, there are none of the other goodies in this sample, just the Sun post process. This sample has also been created using the XNA 4.0 CTP, so I only had one render target to work with at the time. This means that you can't see the sun being culled behind objects in the scene as I can't create a depth map as well as the rendered scene, to be honest, I still don't have that bit of the shader 100% anyway
XNA 4.0 MultiEffect
X-Tatic has created a wrapper for all 4 built in effect types in XNA 4.0
What this means is that you can store a single type of effect yet have it be any one of the four included effect types, while still having access to all of the properties that any of the underlying effects expose.
The reason for MultiEffect is that its useful to use an effect without trying to figure out which of the 4 types it is and which properties/methods to call. You can call any of them, regardless of whether the effect implements them.
// to create a MultiEffect MultiEffect effect = new MultiEffect(); // this defaults to BasicEffect // or via any one of the built in effects MultiEffect effect = builtInEffect.ToMultiEffect(); // you can access the underlying Effect Effect effect = multiEffect.Effect; // or explicitly cast it Effect effect = (Effect)multiEffect; // Finally, you can query the type MultiEffectType effectType = multiEffect.CurrentType;
Download the binaries: http://www.xtaticware.com/downloads/XNA4MultiEffect.zip
or the source: http://www.xtaticware.com/downloads/XNA4MultiEffectSource.zip (MS-PL)
Distance field based decal rendering
Rim van Wersch shares an XNA Framework implementation of the Valve paper Improved Alpha-Tested Magnification for Vector Textures and Special Effects, presenting “[a] simple and efficient method […] which allows improved rendering of glyphs composed of curved and linear elements. A distance field is generated from a high resolution image, and then stored into a channel of a lower-resolution texture.”
Post Processing Trick from MJP
Matt Pettineo took a crack at a trick used in Killzone 2 for Lens Flare, and decided to share his new shader with the world.
Two Samples For The Price Of One at MJP’s XNA Danger Zone
Over at MJP’s XNA Danger Zone Matt J. Pettineo writes:
Today I have two XNA samples fresh out of the oven: a Motion Blur Sample, and Depth Of Field Sample. I figure all of the kids these days wanna add fancy post-processing tricks to their games, right?
Instanced Deferred Render
Nemo Krad (of RandomChaos) continues to tease us with yet another video of his Deferred Render Instancing sample.
Let's hope he releases the code soon, because what he's doing there definitely looks sweet, and there can never be too many samples about deferred rendering, or instancing!
See all his posts about this so far, here.
Scrolls from the Past: Crash Course in HLSL
Greetings again, good sirs and ladies.
This week, we will have a different kind of scoll to look at. Instead of looking into the archives for scrolls written by other people in times past, I will show you something that I accidentally found in my own archives today.
This was written many moons ago, as a sample for a book that was to be written for a great library together with some other wizards of XNA land. Even though the library keepers liked my writing, their plans for that book changed, and it never got written.
Alas, I decided to not let those scrolls be forgotten, so I blew the dust off of them, made some corrections, and decided to bring them to your attention. In them, I talked about a detailed introduction into the magic of HLSL, and the basic elements needed to understand and use this wonderful kind of magic. You can find it here.
Have a nice reading, and I wholeheartedly hope it helps at least some of my usual readers.
Article: Crash Course in HLSL
by Catalin Zima
What does HLSL stand for? Why was it created? How does an HLSL effect file look like? What can you do with HLSL? What do float4x4, TEXCOORD0 or compile ps_3_0 mean? The answer to the first question is simple: HLSL means High Level Shader Language. This answer by itself might raise a few questions. The answers for these and a few other questions will be found in this article.



