Sponsored By

Featured Blog | This community-written post highlights the best of what the game industry has to offer. Read more like it on the Game Developer Blogs.

How to Leverage Custom Shaders in Computer Game Development

As a powerful technique of adding visual punch to a game, shading is quite popular among computer game developers. This article highlights when and how using a custom shader could make a telling difference in pumping up the game imagery, and when not.

Arty Merts, Blogger

April 19, 2016

8 Min Read

Compared to such common special effects techniques as particles and frame-based animation popular with game developers, shaders offer a plethora of unique advantages to capitalize on. Here are some things to consider when working with shaders.

Custom Shaders: Taking Your Game to a New Level of Visual Appeal

Actually, the Unity platform alone provides plenty of tools that enable game developers to implement simple optical transformations in a couple of clicks. Standard scripts available in the Unity Asset Store not only allow creating a wide range of special effects that add an extra touch of excitement to a game, but also significantly accelerate the development process.

But how do you take your game to the next level of visual appeal and make it more engaging and delightful? Creating a custom shader could be extremely helpful here. For example, let us take a closer look at The Circle of Life, a fantasy 2D arcade game featuring 3D elements developed by the zGames studio.

The team had to visually emphasize the key animated object of the game – a sphere. Since the gameplay had already employed a number of simple visual effects, to make the object really stand out, the team decided to try something more elaborate and developed a custom shader. As a result, the spherical object responds to the pressure of a finger against the screen by increasing in size and changing the texture, making the interaction so much more fun.

The gif below shows a scene from The Circle of Life illustrating this shader-based effect.

Circle of Life

Shader Showdown: Weighing in on Pros and Cons

Shading is an effective technique applicable in a wide range of game types and genres. Suppose you need to put an extra emphasis on a game object. This could be a fireball thrown by a magician, or a shot from an extremely powerful weapon. You may also wish to recreate an air distortion made by the sword swung by a demon. Whatever you are up to, using simple particles here will not suffice. The same is true for frame-based animation, which is known to be pretty time- and money-consuming, while not really powerful in conveying visual excitement. So, creating a custom shader-based effect could make a whole lot of difference.

Below is an example of a shader-based effect applied to a static card from an online game, Hearthstone. A card with a special effect is rated as golden, a trophy much coveted by players who are avid collectors.

Hearthstone card

However, it does matter to what object or element in a game a custom shader is applied. I would not advise using shader-based effects on secondary elements. Firstly, that is because of the extra time and effort that shader development consumes. Secondly, the return is likely to be minor as such elements are often hardly noticed — players may spot the effect only once or just as well ignore it. Last but not least, a secondary element rendered with a custom shader may bring confusion, thus distracting a player’s attention from the main game objects.

The screenshot below features an action game, Metal Planet. Here the windows on the left, which are of minor importance, have the same turquoise color as the interactive objects on the right. As a result, the more attention worthy game objects lose the desired focus.

Metal Planet shader

Let us consider another case. Suppose, you need to develop a game with a plot revolving around parallel universes with portals, touch points, and other cosmogenic elements. To add a touch of visual appeal, you decide to design a custom shader that renders a space-distorting crystal shining in the cave depths. Applying the effect to the crystal may create a false impression that the object is either something important or it is a so-called ‘Easter Egg’ (a hidden secret to be discovered), while your intention was just to introduce some visual diversity to the scene. Anyway, on realizing it is neither this, nor that, the player is very likely to feel confused or disappointed. This is a predictable reaction to spending too much effort on exploring the hidden secret behind the animated object. As a result, the game flow is ruined.

The screenshot below features a real-time strategy game, Perimeter. The scene abounds in shader-based effects. This visual redundancy causes difficulty in differentiating significant elements (e.g. power construction) from those used to visually pump up the scene. This hampers the player’s understanding of the surroundings in order to define the playing strategies.

Perimeter shader

To sum it up, before you embark on custom shader development, you should closely consider all the pros and cons of investing yourself into this technique taking into account the above stated.

Shader Development Estimation: Possible Bumps Along the Road

If you are just starting out in shader development, getting to grips with the estimation of time and effort required for the implementation of the target effect could be quite a daunting task. It requires a fundamental knowledge of math and physics, as well as graphics pipeline, hardware operation, image processing algorithms, etc. For instance, to be able to leverage the bump mapping technique, a developer should have a thorough understanding of catadioptrics. Moreover, one should know how to transform this knowledge into code.

Below is an example of a bump mapping technique.

Normal mapping

While making the estimation, it is necessary to allocate additional time for program debugging. The probability of having a smoothly functioning shader right from the first iteration is low. Another thing to take into account is the fact that shader development and conventional software development differ. The system application implementation relies on a variety of tools for testing, whereas shaders are not that easy to debug. Just imagine that for each pixel of a 3D object the  shader can be executed with a frequency as high as 50 times a second. Stopping the program at the right spot to step through the code to diagnose the problem is not that easy. As of now, to inspect a shader you will need to employ Microsoft Visual Studio’s graphic debugger.

It is next to impossible to predict how the shader will behave as a standalone program or within the game context, which also poses a certain challenge. You may have to continuously fine-tune the program or redevelop it from scratch. Having a practical knowledge of target gaming platforms like mobile devices, WebGL, Smart TV, game consoles, and AR or VR headsets and understanding their graphics capabilities and limitations is also essential for making an accurate estimation.

Shader Development Process Overview

To take on shader development, not only do you have to excel in a number of domain specific programming languages and have a strong foothold in physics and math, but you also need to have a thorough understanding of the game development process. The Game Designer is responsible for keeping all the deliverables under control and making sure that all the designed elements and functionality are in sync with the concept. The Artist is in charge of the game graphic and stylistic rendering, while the Programmer handles special effects implementation in accord with the common vision elaborated by Game Designer and Artist. The Project Manager is responsible for eliminating any misalignments between the Game Designer’s vision and the time spent on implementation.

Shaders and Augmented Reality/Virtual Reality Devices. Ready or Not?

Designed to merge the virtual world with reality, and drawing on advanced graphics processing capabilities, AR/VR headsets have already clinched top positions among next-gen computer game devices. VR/AR games that employ shader-based visual effects enable a truly immersive gaming experience. However, we still need time before we can fully indulge ourselves in virtual or augmented reality that builds on complex shading effects. Hardware capabilities are still limited – many graphics cards and GPUs can’t provide the performance sufficient for handling complex graphics. Moreover, not every VR and AR platform provides for the functional capabilities supporting native shader development. The prospects are nevertheless bright. The VR and AR device industry keeps gaining momentum. So expect more quality 3D content based on complex visual shading effects to come in the very near future.

When Custom Shading Is Indispensable: Key Takeaways

When it comes to adding visual diversity, maximizing graphic complexity, crafting a realistic effect, say, of light reflecting from a surface, a distortion or internal structure of an object, using a custom shading technique will be the right choice.

Remember that an effect applied to a less important element may distract a player’s attention from more significant game objects thus ruining the game flow. If the player does not get a meaningful visual response during the gameplay or has difficulty in differentiating a secondary object from the primary, chances are they will end up disappointed and lose interest.

Although the custom shader creation is likely to increase the project duration and the budget, as well as limit the choice of the target gaming platforms for your game, it still affords a huge advantage, namely stunning graphics with one-of-a-kind special effect that make your game stand out.

About zGames

zGames is a mobile game development studio delivering multi-platform Unity-driven games across a variety of popular gaming genres — from casual titles to augmented and virtual reality apps to educational games— for some of the most world-renowned game producers and publishers.

Read more about:

Featured Blogs

About the Author(s)

Daily news, dev blogs, and stories from Game Developer straight to your inbox

You May Also Like