All my eight articles on Habré are articles about game devs, most of them are related to such a wonderful framework as XNA. The first acquaintance with XNA was an article about creating a musical toy , then the complexity of the articles was increasing, I started writing about particle systems , and then about shaders and more shaders . ')
In general - on the shaders I wanted to finish, however, to cost a bit to complement them, I will talk about several algorithms for improving the graphics in the game. Examples of improvements:
If interested - under habrakat.
Introduction
We will touch again on the 2D component of games and will work only with pixel shaders.
This article will be slightly different from my other, here will immediately go and theory and practice, it is implied that you have already read articles about shaders here and here .
Consider all the effects that were used in the game and a couple of effects that were not there, the video is quite old, and the game has already suffered qualitative changes since.
Distortion
The very first effect that catches your eye is distortion:
This effect is not handled by a special shader, in general, it is the same as in the article I wrote earlier.
Let's take that explosion effect.
The following textures are used here:
In the upper left corner - the texture of smoke, smoke forms a "ring" around the explosion, a bright area in the explosion, which quickly goes out and the plume from the rocket. This is the main texture of this effect. Used as a visible texture and distorting texture.
Next - a point near the smoke, thanks to her - there are lightning that emanate from the center of the explosion. It is also used as a visible texture and distorting texture.
Well, for extra beauty - particles from the explosion, the biggest texture on the strip. But here it is worth noting that the player will never see it directly. It is distorting and quickly disappears.
PS a couple of tips for beginners making a particle system:
Never create particles during the game, use the Pool Object pattern.
Never create a “texture” property on a particle class. Use enum and a single texture (strip), where all the textures of your particles lie. Because if in the process of drawing particles you constantly change the state of the graphic device (change the texture, for example) - do not expect high speeds from your system.
The rule: “The more particles, the more beautiful” - does not always work.
HUD Distortion (interface distortion)
The second effect that could have been noticed in the video is the distortion of the interface. I was inspired by games like Crysis 2 and Deus Ex: Human revolution . There, with the death - the interfaces began to be distorted in various ways. It seemed to me interesting. Also, I strengthened the interface distortions with a simple hit.
For example, the death of a player:
This shader is very similar to the one that was before - image distortion. However, the root is different from it. The distortions do not come from the distortion map, but from mathematical formulas, let's consider the shader code (the shader is as simple as possible to understand):
The code is quite simple, and the result of the shader itself looks impressive.
Static texture to dynamic texture
Creating "live" textures from less alive. For example, few people noticed - the twinkling of distant stars in the video above. Although, the texture itself is static.
If the pixel brightness ( grayscale ) is more than 20% - a slight flicker is created, if more than 80% - strong. The picture of this can not be shown, everything can be seen in the video.
Well, consider two more effects, which are not in the video and they are implemented in newer versions.
Bloom (glow effect)
The glow effect is familiar to everyone, also referred to as Bloom . The idea is simple, extract bright areas from an image (some threshold is entered), then draw our scene and above the blurred scene. Bright areas begin to glow.
Examples in pictures: Scene brightness:
Original scene:
Finished scene:
Consider the shader code, it consists of two parts, a shader that extracts the brightness and a shader that forms the final image. Listing shader that extracts brightness:
With the help of such things here - you can give your game a big "highlight", and such things are done quite simply.
At this, I think, the “course” in 2D games is over, after a while - I will start writing about creating three-dimensional games.
PS the creation of this game (the one in the video) - most likely will remain at this stage.I do not have enough resources (time, enthusiasm, inspiration), to work on such a big project alone is suicide.
PSS is a huge request to write me a personal message about ochepyatka / errors, do not write comments without useful semantic meaning.