Article: Texture Modification using Render Targets, with some Stencil Buffer Action
by Dave Carlile

Sometimes you need to modify a texture while your game is running, and there are a number of ways to do this. One of the first things newer game programmers often try to do is use Texture2D.GetData to copy the texture data from the GPU to an array on the CPU, modify the bytes, and then send it back to the GPU with Texture2D.SetData.
This is a bad idea on many, levels. Beyond issues with pipeline stalls, GetData and SetData can be slow, especially when working with a large texture. Any time you’re tempted grab data from the GPU for use on the CPU you should very carefully consider all of your options. There are often other solutions that let you keep the data entirely on the GPU and accomplish the same thing.
This tutorial will use an example that could be solved with GetData and SetData, and show you another alternative using render targets and the stencil buffer that will let you perform the same function entirely on the GPU.
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.
Windows Phone 7 – XNA Brightness and Contrast
With the addition of Windows Phone 7 support to XNA comes some limitations. If one wanted to have brightness and contrast controls for their game, previous methods may not be available. Considering features such as programmable shaders or device gamma ramp to achieve such a task will leave you out of luck. However there is a simple (and perhaps old school) way of doing it, and that is blend states.
Click Continue reading to see how!
Placeholder in Games
Barnaby Smith shares his thoughts about using placeholder assets during the development of games:
Creation and use of placeholders, whether levels, 3d models, sprites or sounds, has a number of advantages when developing computer games. In this article I discuss some aspects of the use of placeholders in games.
Render Target Changes in XNA Game Studio 4.0
The Shawn of Hargreaves details the changes to the render target API in XNA Framework 4.0. The high level summary of these changes are:
RenderTarget2Dinherits fromTexture2DandRenderTargetCubefromTextureCubeto properly denote the Is-a in the API (no moreRenderTarget*.GetTexture())- Multiple render targets are set at once without explicitly specifying its index and all previous set render targets are unset automatically
- An optional depth buffer for a render target is now a property of the render target itself, which might be shared across multiple render targets if certain conditions are met
For the motivation and details of these changes see Rendertarget changes in XNA Game Studio 4.0.
HOWTO: Resolution Independent Rendering in 2D
David Amador shares his code to work with a fixed resolution on Windows without having to manage the placement of your renderables yourself. Sez David:
Independent Resolution Rendering?? What’s this all about?
Basically a way of not caring what you resolution is. Ever had Gui elements misplaced because you changed the resolution? Or getting out of the screen?
If you are doing a game on Xna just for Xbox360 you can basically use a 1280×720 base resolution and the Xbox will scale the game for you making the proper Letterbox.
But what about on Windows? Or if you use a different resolution on the Xbox? You have to manage that yourself.
I’ve made a small example on how to achieve this.
Light Pre-Pass
Michael Quandt has posted a write up detailing the theory behind his Light Pre-Pass code he released for educational use previously.
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.”
sgMotion v1.0.0 Released
Tom Looman released his sgMotion library to CodePlex. Says Tom:
sgMotion is an animation library (based on XNAnimation by Bruno Evangelista) and provides full integration with both the Sunburn Engine and the Sunburn Framework.
More at the source.
