I am sure you are more than capable of taking the CPU flames and doing the calculations on the GPU, but if either you couldn’t be bothered or are un familiar with shaders, then this is the post for you.
As before we have a color palette and a fire texture, but this time we are going to use render targets and a shader with two techniques in it.
In the constructor the color palette is constructed as before.
In the LoadContent we set up the textures and render target
And then we have the super funky draw call
So, this is where all the action is, first we construct the fire map, taking the current texture and randomizing the base pixels (could probably move this to the GPU too), then load the parameters of our shader. Now we need to give our fire map to the GPU so it can work it’s magic on the texture, so we set up the render target, clear the device, render our fire texture using the shader calling the “UpdateFire” technique.
And in here we are just doing what we did on the CPU before. Once we get this texture back off the GPU, we can then use the “ColorFire” technique to render the flame.
And there you have GPU old school flames.
But what of the spinning cube!? I hear you shout…
Works as before, but the fire map is derived from the scene and I simply color the box lines to that of the level of the oxygen value. I have also added in some text as an added effect. So with this you can set anything you like on fire :)
You can get the sample code here for both the GPU and CPU fire effects.
If you want to see this effect running on your shiny WP7, then you can dld this source here to do that.