This article was prepared in collaboration with the developers and game designers of the studio zGames.
Despite the abundance of techniques that allow you to create attractive visual effects in computer games, shaders have several advantages compared with such common tools as particle or frame-by-frame animation.
The role of unique shaders in creating special effects for computer games
Unity has tools that can be used to create simple optical transformations in a couple of clicks. Using a set of standard scripts from the Unity Asset Store, you can get a huge variety of special effects that can add to the atmosphere of the game and significantly speed up the development process.
What to do if you are faced with the task of creating an original visual effect? If you need to make the game or any of its stages especially memorable? Here you can not do without creating a unique shader. Consider a specific situation on the example of the game Circle of Life, developed by the studio zGames. In this game, special emphasis was needed to give an animated object - a spherical area. The gameplay already abounded with a sufficient number of simple effects, so this element needed to be highlighted with the help of special visual transformations. Since the standard tools for creating conceived visual effects were not enough, it was decided to develop a unique shader. As a result, the final object responds to holding the finger on the touch screen, increasing in volume and changing the structure. Thanks to the unique visual transformations, this spherical area has become one of the key elements of the game, to which player's attention is riveted (the shader animation of the main object of the game Circle of Life is shown below).
')
Pros and cons of using shaders in games
Using shaders will be very useful in developing any kind of games. Suppose you want to highlight in a special way one of the elements of the game. It can be a huge fireball that the character mage launches, or a shot of the incredibly powerful weapon that the player has been searching for. Or you just want to display the distortion of the air around the demon from the underworld waving a sword of fire. Using partitions here is not enough, but frame-by-frame animation will either be very time-consuming or budget-intensive, or it will look too monotonous. Therefore, using the shader-based effect here will be most welcome. Below is an example of a shader effect applied to a static map from the Hearthstone game. Cards with a special effect are equated to "gold" and are an attractive trophy for players-collectors.
It is impractical to create unique shaders for secondary elements. First, shader programming is also a very laborious process. Secondly, considerable efforts will be made to develop here, and the return can be very conditional: the player will see the effect a maximum of one time, and maybe even not notice it. And thirdly, a unique shader on a secondary object can divert attention from objects that are really important. In the screenshot of the game Metal Planet, the shaders are lit up with turquoise windows on the left (a secondary element). The same effect is applied to the objects on the right, which are in fact the main interactive elements. As a result, the focus of attention shifts from an important (currently) part of the world.
Consider another example. Suppose you create a game whose plot is built around parallel worlds with portals, points of contact and other cosmogenic elements. You have developed a unique shader for a glowing crystal in a cave that distorts space. Because of the visual accent of the crystal, the player may get the impression that this object is important in the main storyline or is “easter egg” (a secret that needs to be discovered), although this is just an element of decor in the interior. In the end, this may simply confuse the player or even disappoint if he had to waste time on research. As a result, “flow” (state of immersion in the gameplay) is violated. Below is an example from the game Perimeter. Here shaders create too many beautiful things. It becomes unclear where important information is concentrated (tower coverage areas), and where the effect is applied simply for visual diversity. The player is more difficult to navigate the game scene. You have to spend more time on understanding the situation and making decisions.
Therefore, weighing the pros and cons of the development of the shader, it is worthwhile to think more carefully about the expediency and relevance of using this technique.
We make an assessment of labor costs for the development of shaders: possible difficulties
If you are just starting to master shader development, then making an adequate estimate of the cost of implementing the desired effect can be a nontrivial task. First, you need a good knowledge of mathematics and an understanding of the physics of the process, the graphics pipeline, equipment operation, image processing algorithms, etc. For example, in order to successfully use the technique of emulation of recesses and dents (normal / bump mapping), a programmer needs to know and understand the law of reflection and refraction of light. The specialist should also be able to implement these laws in code that basically works with a flat surface and a light source (the following is an example of using normal mapping technology).
Secondly, the evaluation should include the time required to debug the program. After all, immediately create a perfectly functioning shader is unlikely to succeed. It must be remembered that the process of developing shaders and traditional software is different. System applications have a number of tools that allow them to debug quality. You can not say about the tools for debugging shaders. For each pixel of a 3D object, the program can run 50 times in a second. It is extremely difficult to stop such a process in a certain place to check the correctness of the program. Currently, the Microsoft Visual Studio extension with a built-in graphical debugger is used to debug shaders. Another difficulty that lies in the way of shader development is the lack of a clear idea of ​​how the final result will look like independently and in the gameplay. It may be necessary to refine it or even re-develop it. So that this moment must be considered when making the assessment.
Add to this the need for knowledge of the platforms for which the game is designed, and their ability to display graphical elements - mobile devices, WebGL, Smart TV, consoles, augmented or virtual reality devices. Thus, you will receive a list of the most significant factors that can significantly affect the course of the project.
Little about the development process
The development of shaders requires not only the development of specialized programming languages, possession of a number of branches of physics and mathematics, but also an understanding of the development stages of the game product. The game designer is a key element in the project - it ensures that the created elements and functionality fit into the framework of the conceived concept. The artist is responsible for the graphic and stylistic development of the game. The programmer, in turn, offers options for implementing effects in accordance with the vision of the game designer and artist. The elimination of possible contradictions between the game designer’s idea and the time spent on its implementation is monitored by the project manager.
Shaders and devices of virtual and augmented reality
With its enormous potential for transmitting complex visual effects, virtual and augmented reality devices are already taking a leading place in the ranks of popular gadgets for computer games. Undoubtedly, shaders add realism to the game objects developed for these wearable devices. But today, not all VR or AR helmets will be able to reproduce effects based on complex shaders due to hardware limitations — an insufficiently powerful graphics card and processor. Moreover, not all VR and AR platforms provide the full range of functions necessary for programming native shaders. Nevertheless, the industry of virtual and augmented reality devices continues to grow rapidly. The emergence of high-quality 3D content using complex visual effects based on shaders is the matter of the very near future.
Summing up
If you need to further diversify the visual range, make the graphics more intricate, or if you want to achieve graphic realism, for example, believable reflection of light from surfaces, distortion of objects, light refraction in water, transmission of the internal device of an object, etc., then the development of original shaders here would be the optimal choice.
It must be remembered that an extra effect in an unnecessary place can distract the player’s attention and even harm the process. If the participant of the game receives less information about the actions taking place by means of visual feedback, or if the effects used in the game create an emphasis on secondary objects, then this process becomes obscure and contradictory. As a result - the player's confusion, loss of interest in the game.
In general, the use of shaders in game development increases the duration and budget of the project, and also imposes certain restrictions on the use of gaming platforms for which the game is created. However, there is one indisputable advantage, which more than compensates for the listed disadvantages, namely: the undoubted quality of graphics and the uniqueness of the effect produced.