Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am currently working on a 2D "Worms" clone in XNA, and one of the features is "deformable" terrain (e.g. when a rocket hits the terrain, there is an explosion and a chunk of the terrain disappears).

How I am currently doing this is by using a texture that has a progressively higher Red value as it approaches the center. I cycle through every pixel of that "Deform" texture, and if the current pixel overlaps a terrain pixel and has a high enough red value, I modify the color array representing the terrain to transparent. If the current pixel does NOT have a high enough Red value, I blacken the terrain color (it gets blacker the closer the Red value is to the threshold). At the end of this operation I use SetData to update my terrain texture.

I realize this is not a good way to do it, not only because I have read about pipeline stalls and such, but also because it can become quite laggy if lots of craters are being added at the same time. I want to remake my Crater Generation on the GPU instead using Render Targets "ping-ponging" between being the target and the texture to modify. That isn't the problem, I know how to do that. the problem is I don't know how to keep my burn effect using this method.

Here's how the burn effect looks right now:

Burn Effect

Does anybody have an idea how I would create a similar burn effect (darkening the edges around the formed crater)? I am completely unfamiliar with Shaders but if it requires it I would be really thankful if someone walked me through on how to do it. If there are any other ways that'd be great too.

share|improve this question
    
This might help: gamedev.stackexchange.com/q/6721/1163 –  Adam Harte Apr 7 '11 at 21:33

1 Answer 1

up vote 7 down vote accepted

One way you could do it is similar to what you have been doing. Have a "Damage" texture and the actual background texture, but instead of copying the data over each time, just keep the two as two separate textures.

When a blast is made, draw a circle on the Damage texture that has a slightly transparent edge. This will be the "burn" area.

Whenever you draw the terrain, give the GPU both textures, and have your shader multiply the color (.rgb) of the background pixels by 1 - the alpha value of the damage texture. Get rid of the fully black pixels (alpha them to 0, or you can multiply this to alpha as well (.rgba instead of .rgb) depending if you want translucent scorched areas) and voila!

I doubt this is the best solution, but it is fairly similar to what you've done before which may make transferring easier. You could probably also get away with passing in an array of Vector3's (x,y,radius) and doing some math in the shader based on those explosion points but I am unsure as to the efficiency of such.

Hope this helps!

share|improve this answer
    
Thanks! That's a cool way of doing it too, and similar to what I'm doing now, as you said. I know nothing about HLSL but I'll definitely look into it. Another way I was told I could do is blacken it as I approach the edge of the crater, but I'll try this way too. –  Benixo Apr 7 '11 at 19:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.