{"id":18687,"date":"2024-03-07T22:40:50","date_gmt":"2024-03-07T19:40:50","guid":{"rendered":"https:\/\/www.koloro.ua\/services\/developing-shader-effects-for-the-game\/"},"modified":"2024-10-22T12:21:31","modified_gmt":"2024-10-22T09:21:31","slug":"developing-shader-effects-for-the-game","status":"publish","type":"services","link":"https:\/\/koloro.ua\/en\/developing-shader-effects-for-the-game\/","title":{"rendered":"DEVELOPING SHADER EFFECTS FOR THE GAME"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"h-&#x440;&#x430;&#x437;&#x440;&#x430;&#x431;&#x43E;&#x442;&#x43A;&#x430;-&#x448;&#x435;&#x439;&#x434;&#x435;&#x440;&#x43D;&#x44B;&#x445;-&#x44D;&#x444;&#x444;&#x435;&#x43A;&#x442;&#x43E;&#x432;-&#x434;&#x43B;&#x44F;-&#x438;&#x433;&#x440;&#x44B;\">Developing shader effects for the game<\/h2>\n\n<p class=\"wp-block-paragraph\">A shader is a script that enhances the graphics of a game. Shaders are needed for particle simulation, simple object animation and image post-processing. We tell you how shaders and other graphics effects work.  <\/p>\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/koloro.ua\/public\/files\/images\/content\/5f2d435075fb7.png\" alt=\"example of using shaders in Minecraft\" title=\"example of using shaders in Minecraft\"\/><\/figure>\n\n<p class=\"wp-block-paragraph\"><em>Minecraft with lighting and water simulation shaders<\/em><\/p>\n\n<h2 class=\"wp-block-heading\" id=\"h-&#x43A;&#x430;&#x43A;-&#x432;&#x438;&#x434;&#x435;&#x43E;&#x43A;&#x430;&#x440;&#x442;&#x430;-&#x43E;&#x431;&#x440;&#x430;&#x431;&#x430;&#x442;&#x44B;&#x432;&#x430;&#x435;&#x442;-&#x448;&#x435;&#x439;&#x434;&#x435;&#x440;&#x44B;\">How the video card handles shaders<\/h2>\n\n<p class=\"wp-block-paragraph\">A graphics card is a complex of computational units. Each unit does its own task:<\/p>\n\n<ul class=\"wp-block-list\">\n<li><strong>video chip<\/strong> &#8211; exchanges information between the computational blocks of the video card and the processor;<\/li>\n\n\n\n<li><strong>geometric blocks<\/strong> &#8211; calculate and build three-dimensional objects;<\/li>\n\n\n\n<li><strong>Texture blocks<\/strong> &#8211; select and filter <strong>texture<\/strong> data and apply it to objects;<\/li>\n\n\n\n<li><strong>shader blocks<\/strong> &#8211; calculate shaders and apply them to objects and textures;<\/li>\n\n\n\n<li><strong>Rasterization blocks<\/strong> &#8211; receive information from other blocks and form pixels from it for displaying on the screen.  <\/li>\n<\/ul>\n\n<p class=\"wp-block-paragraph\">The graphics card first generates the geometry of the objects to be displayed on the monitor. It then applies textures to the objects. Now the scene looks flat: the texture doesn&#8217;t respond to lighting, objects don&#8217;t cast a shadow. These and other effects can be added using shaders.<\/p>\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/koloro.ua\/public\/files\/images\/content\/5f2d4389bef57.png\" alt=\"The Witcher 3 shaders\" title=\"The Witcher 3 shaders\"\/><\/figure>\n\n<p class=\"wp-block-paragraph\"><em>The Witcher 3 with and without shaders<\/em><\/p>\n\n<p class=\"wp-block-paragraph\"><strong>Roughly speaking, shaders are analogous to filters in Instagram.<\/strong><\/p>\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/koloro.ua\/\">GET ADVICE<\/a><\/p>\n\n<h2 class=\"wp-block-heading\" id=\"h-&#x438;&#x441;&#x442;&#x43E;&#x440;&#x438;&#x44F;-&#x43F;&#x43E;&#x44F;&#x432;&#x43B;&#x435;&#x43D;&#x438;&#x44F;-&#x448;&#x435;&#x439;&#x434;&#x435;&#x440;&#x43E;&#x432;\">History of the emergence of shaders<\/h2>\n\n<p class=\"wp-block-paragraph\">When computers learned to display more than two colors on the screen, game developers got serious about graphics. At first, they applied color filters and non-standard video effects to change the color of pixels or an entire sprite. Algorithms were then used to create a transparency effect and the ability to dynamically change the texture.  <\/p>\n\n<p class=\"wp-block-paragraph\">Video cards from the 90s didn&#8217;t have separate shader units yet. The video cards themselves were able to execute limited sets of commands.  <strong>Because of this, non-standard algorithms had to be executed on the CPU.  <\/strong>These effects made some older games look better when the graphics were rendered by the CPU rather than an expensive graphics card.<\/p>\n\n<p class=\"wp-block-paragraph\">For example, in Quake 2, there were two ways to display water:<\/p>\n\n<ul class=\"wp-block-list\">\n<li>hardware rendering &#8211; the video card rendered the water as a static blue light filter;<\/li>\n\n\n\n<li>program rendering &#8211; the processor rendered water as a dynamic texture with a splash effect.<\/li>\n<\/ul>\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/koloro.ua\/public\/files\/images\/content\/5f2d43d3128ea.png\" alt=\"water in quake 2 without and with shader\" title=\"water in quake 2 without and with shader\"\/><\/figure>\n\n<p class=\"wp-block-paragraph\"><em>Shaders in Quake 2<\/em><\/p>\n\n<p class=\"wp-block-paragraph\"><strong>Video card developers in the late 90&#8217;s introduced shader blocks into video cards to execute special algorithms<\/strong>. First they tried to stitch standard sets of algorithms into the blocks, like they did with video memory and the central video chip. But then they realized that game developers want to invent something of their own, and allowed games to execute any scripts in shader blocks.  <\/p>\n\n<p class=\"wp-block-paragraph\"><strong>Shaders first appeared in Quake 1, where they were responsible for dynamic lighting.<\/strong>  The script received information about the coordinates of the light source, calculated the distance from the light source to the nearest polygons and lightened their texture pixels during frame rendering.<\/p>\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/koloro.ua\/public\/files\/images\/content\/5f2d44011445c.png\" alt=\"quake 1 lighting system\" title=\"quake 1 lighting system\"\/><\/figure>\n\n<p class=\"wp-block-paragraph\"><em>The lighting system in Quake 1<\/em><\/p>\n\n<p class=\"wp-block-paragraph\"><strong>Shaders were then used to create dynamic lighting and textures, water, fog and fire effects, and grass.<\/strong>  Video card maker NVidia has come up with a shader to simulate hair behavior that was used in The Witcher 3 and Tomb Raider games.<\/p>\n\n<h2 class=\"wp-block-heading\" id=\"h-&#x43A;&#x430;&#x43A;&#x438;&#x43C;&#x438;-&#x431;&#x44B;&#x432;&#x430;&#x44E;&#x442;-&#x448;&#x435;&#x439;&#x434;&#x435;&#x440;&#x44B;\">What shaders are<\/h2>\n\n<p class=\"wp-block-paragraph\">There are these basic types of shaders:<\/p>\n\n<ul class=\"wp-block-list\">\n<li><strong>Vertex (Vertex)<\/strong> &#8211; works with vertices of objects or separate points in space;<\/li>\n\n\n\n<li><strong>Geometric<\/strong> &#8211; working with lines and triangles;<\/li>\n\n\n\n<li><strong>fragment<\/strong> &#8211; work with pixels, change their color depending on what is happening in the scene.<\/li>\n<\/ul>\n\n<p class=\"wp-block-paragraph\">Prior to 2006, video cards had separate shader processors for each type of shader. But thanks to advances in technology, video card manufacturers have replaced the three types of blocks with universal processors of the same type. Such a universal block can handle any kind of shader script.  <\/p>\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/koloro.ua\/public\/files\/images\/content\/5f2d44203587f.png\" alt=\"The 2007 graphics card has 17 shader processors, the modern RTX 2080 has 3072 shader processors\" title=\"The 2007 graphics card has 17 shader processors, the modern RTX 2080 has 3072 shader processors\"\/><\/figure>\n\n<p class=\"wp-block-paragraph\"><em>The 2007 graphics card has 17 shader processors, the modern RTX 2080 has 3072 shader processors<\/em><\/p>\n\n<h2 class=\"wp-block-heading\" id=\"h-&#x447;&#x442;&#x43E;-&#x43C;&#x43E;&#x436;&#x43D;&#x43E;-&#x441;&#x434;&#x435;&#x43B;&#x430;&#x442;&#x44C;-&#x441;-&#x432;&#x435;&#x440;&#x448;&#x438;&#x43D;&#x43D;&#x44B;&#x43C;&#x438;-&#x448;&#x435;&#x439;&#x434;&#x435;&#x440;&#x430;&#x43C;&#x438;\">What you can do with vertex shaders<\/h2>\n\n<p class=\"wp-block-paragraph\"><strong>Vertex shaders are used to change the vertex coordinates of 3D objects. <\/strong>For example, a vertex shader allows you to get the coordinates of the vertices of a sphere, and then change them to make a cube. The 3D model itself in the game files does not change &#8211; only the coordinates of its vertices are changed when rendering the image.  <\/p>\n\n<p class=\"wp-block-paragraph\"><strong>The most popular task of vertex shaders is skinning or skeletal animation.<\/strong>  The developer makes a skeleton inside the 3D model and uses the vertex shader to bind the skin to the skeleton. A skin is a group of model vertices that are arranged around a single bone. When the bone moves, so do the vertices attached to it. The texture between the tops of the different bones is stretched, but it&#8217;s better than the &#8220;ripped off&#8221; arms from early 3D games.<\/p>\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/koloro.ua\/public\/files\/images\/content\/5f2d443bed16e.png\" alt=\"skinning with vertex shader  \" title=\"skinning with vertex shader  \"\/><\/figure>\n\n<p class=\"wp-block-paragraph\"><strong>The second popular task is real-time deformation of objects.<\/strong>  It used to be that shaders like this were used to make realistic waves on water. Now warping is being used to create realistic snow, mud, dents on cars and bullet marks.  <\/p>\n\n<p class=\"wp-block-paragraph\"><strong>The third task is the algorithmic animation of objects.<\/strong>  For example, you can use vertex shaders to make low-polygon grass or triangular leaves and make them move with gusts of wind. You can also make realistic animations of ropes or fabric.  <\/p>\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/koloro.ua\/public\/files\/images\/content\/5f2d445bf2758.png\" alt=\"grass shader on Unity 3D\" title=\"grass shader on Unity 3D\"\/><\/figure>\n\n<p class=\"wp-block-paragraph\"><em>It took 137 lines of code to create this herb using the Unity 3D shader<\/em><\/p>\n\n<p class=\"wp-block-paragraph\"><strong>And then there are particles &#8211; individual moving points.<\/strong>  Shader particles require fewer resources than if the engine rendered them in the same way as 3D objects or sprites.  <\/p>\n\n<h2 class=\"wp-block-heading\" id=\"h-&#x447;&#x442;&#x43E;-&#x43C;&#x43E;&#x436;&#x43D;&#x43E;-&#x441;&#x434;&#x435;&#x43B;&#x430;&#x442;&#x44C;-&#x441;-&#x433;&#x435;&#x43E;&#x43C;&#x435;&#x442;&#x440;&#x438;&#x447;&#x435;&#x441;&#x43A;&#x438;&#x43C;&#x438;-&#x448;&#x435;&#x439;&#x434;&#x435;&#x440;&#x430;&#x43C;&#x438;\">What you can do with geometric shaders<\/h2>\n\n<p class=\"wp-block-paragraph\">Geometry shaders allow you to create or destroy primitives in real time.<strong>  Roughly speaking, you can control the number of polygons in a 3D model on the fly.  <\/strong><\/p>\n\n<p class=\"wp-block-paragraph\"><strong>Most often geometric shaders are used for tessellation &#8211; adjusting the complexity of the displayed model depending on the distance to it.<\/strong>  For example, let&#8217;s take a sphere that consists of 10,000 polygons. If you move it away from the camera so that it occupies a 10&#215;10 pixel square, the graphics card will still calculate 10,000 polygons and waste resources. If you bring the sphere closer to the camera, the player will see the angular edges of a seemingly round sphere.  <\/p>\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/koloro.ua\/public\/files\/images\/content\/5f2d44b89362c.png\" alt=\"example of geometric shader operation\" title=\"example of geometric shader operation\"\/><\/figure>\n\n<p class=\"wp-block-paragraph\"><em>The geometry shader removes or adds polygons on its own<\/em><\/p>\n\n<p class=\"wp-block-paragraph\">Geometric tessellation shaders allow you to do just that:  <\/p>\n\n<ul class=\"wp-block-list\">\n<li>When the camera is distant, the shader removes some polygons so that the sphere looks round at a distance, but does not overload the graphics card;<\/li>\n\n\n\n<li>When the camera zooms in, the shader &#8220;squeezes&#8221; 2-4 more triangles out of each polygon to make the sphere appear round even if you look at it closely.  <\/li>\n<\/ul>\n\n<p class=\"wp-block-paragraph\">Also geometric shaders can be used to enhance rocks, walls, fabric and any uneven surfaces.  <strong>If you need to add irregularities &#8211; geometric shader will push in or push out polygons according to the specified algorithm.  <\/strong><\/p>\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/koloro.ua\/public\/files\/images\/content\/5f2d44d7df366.png\" alt=\"geometric shader in games\" title=\"geometric shader in games\"\/><\/figure>\n\n<p class=\"wp-block-paragraph\">In addition to triangles, geometry shaders can generate straight lines. It is possible to customize the shader so that it generates additional lines only on the faces of the object.  <strong>This way you can make the edges of objects rough or smooth depending on the type of object.<\/strong><\/p>\n\n<h2 class=\"wp-block-heading\" id=\"h-&#x447;&#x442;&#x43E;-&#x434;&#x435;&#x43B;&#x430;&#x44E;&#x442;-&#x444;&#x440;&#x430;&#x433;&#x43C;&#x435;&#x43D;&#x442;&#x43D;&#x44B;&#x435;-&#x448;&#x435;&#x439;&#x434;&#x435;&#x440;&#x44B;\">What fragment shaders do<\/h2>\n\n<p class=\"wp-block-paragraph\"><strong>Fragment or pixel shaders modify the color of the displayed pixels.  <\/strong>Pixel shaders and algorithms can be used to make gradient filters, screen edge vignettes, noise and image graininess.  <\/p>\n\n<p class=\"wp-block-paragraph\">Fragment shaders work the same way as pixel shaders, but they can be applied to fragments of bitmap images and textures. For example, add a glow effect, blur an out-of-focus object, or generate a texture using an algorithm.  <\/p>\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/koloro.ua\/public\/files\/images\/content\/5f2d450dcfc34.png\" alt=\"example of pixel shader operation\" title=\"example of pixel shader operation\"\/><\/figure>\n\n<p class=\"wp-block-paragraph\"><strong>A typical example of using fragment shaders is multitexturing.  <\/strong>Multitexturing is necessary for lightmaps (lightmap) and simulation of the lighting system. It works like this: a transparent lightmap &#8211; an additional texture that describes the object&#8217;s luminosity &#8211; is overlaid on top of the object&#8217;s texture. When the game engine realizes that light is falling on an object, it commands the shader to &#8220;manifest&#8221; the lightmap in the illuminated areas.  <\/p>\n\n<p class=\"wp-block-paragraph\">The second example is pixel-by-pixel lighting.  <strong>Such a pixel shader collects information about the illumination of the model and manually changes the brightness of each pixel of the object texture.  <\/strong>Popixel lighting allows you to achieve realistic lighting on dynamic objects, as well as make dynamic shadows.  <\/p>\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/koloro.ua\/public\/files\/images\/content\/5f2d452b0d6c6.png\" alt=\"doom 3 with a pixel shader\" title=\"doom 3 with a pixel shader\"\/><\/figure>\n\n<p class=\"wp-block-paragraph\"><em>Doom 3 is the first game with pixel shader lighting<\/em><\/p>\n\n<p class=\"wp-block-paragraph\"><strong>The third example is post-processing effects.<\/strong>  For example, halo from a light source, blurring of distant objects, fog or cloudy glass effect. The fragment shader processes objects in the player&#8217;s field of view, counts the depth of the scene, and manually paints the necessary pixels to create any effect.<\/p>\n\n<h2 class=\"wp-block-heading\" id=\"h-&#x43A;&#x430;&#x43A;-&#x43F;&#x438;&#x441;&#x430;&#x442;&#x44C;-&#x448;&#x435;&#x439;&#x434;&#x435;&#x440;&#x44B;\">How to write shaders  <\/h2>\n\n<p class=\"wp-block-paragraph\">Shader processors work with a limited instruction set, so simplified programming languages are used to write shaders.  <strong>Every major game platform or rendering technology has its own shader language.<\/strong>  For example, XBOX, PlayStation, NVidia and Apple have their own shader languages.  <\/p>\n\n<p class=\"wp-block-paragraph\">Due to the simple syntax of shader programming languages, their creation can be brought into the visual editor. That&#8217;s what the developers of the Unity3D engine did.  <strong>Unity3D shaders can be made in the Shader Graph visual interface and see the result in real time.  <\/strong><\/p>\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/koloro.ua\/public\/files\/images\/content\/5f2d454973462.png\" alt=\"ShaderGraph interface in Unity3D\" title=\"ShaderGraph interface in Unity3D\"\/><\/figure>\n\n<p class=\"wp-block-paragraph\"><em>ShaderGraph interface in Unity3D<\/em><\/p>\n\n<h2 class=\"wp-block-heading\" id=\"h-&#x432;&#x44B;&#x432;&#x43E;&#x434;&#x44B;\">Conclusions<\/h2>\n\n<p class=\"wp-block-paragraph\">If it weren&#8217;t for shaders &#8211; modern games would look like Wolfenstein 3D with detailed models. Shaders are what make games beautiful:<\/p>\n\n<ul class=\"wp-block-list\">\n<li>create lighting and other graphic effects;<\/li>\n\n\n\n<li>simulate the behavior of water, cloth, snow, and other materials;<\/li>\n\n\n\n<li>ensure that the particle system works;<\/li>\n\n\n\n<li>make the animations more realistic.<\/li>\n<\/ul>\n\n<p class=\"wp-block-paragraph\"><strong>Working with shaders requires a good math background: you need to understand math functions, matrix transformations, graphs, and more.<\/strong>  Shader specialist is a separate profession with a high threshold of entry.  <\/p>\n\n<p class=\"wp-block-paragraph\">If you need to create graphic effects (VFX) for a game &#8211; contact us. We have VFX specialists with extensive experience creating a wide variety of effects using shaders.  <\/p>\n","protected":false},"featured_media":13625,"parent":0,"menu_order":0,"template":"","categories":[116],"tags":[],"services_cat":[183],"class_list":["post-18687","services","type-services","status-publish","has-post-thumbnail","hentry","category-apps-web-dev-ux-ui","services_cat-website-and-app-development-ui-ux-design"],"yasr_visitor_votes":{"stars_attributes":{"read_only":false,"span_bottom":false},"number_of_votes":0,"sum_votes":0},"_links":{"self":[{"href":"https:\/\/koloro.ua\/en\/wp-json\/wp\/v2\/services\/18687","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/koloro.ua\/en\/wp-json\/wp\/v2\/services"}],"about":[{"href":"https:\/\/koloro.ua\/en\/wp-json\/wp\/v2\/types\/services"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/koloro.ua\/en\/wp-json\/wp\/v2\/media\/13625"}],"wp:attachment":[{"href":"https:\/\/koloro.ua\/en\/wp-json\/wp\/v2\/media?parent=18687"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/koloro.ua\/en\/wp-json\/wp\/v2\/categories?post=18687"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/koloro.ua\/en\/wp-json\/wp\/v2\/tags?post=18687"},{"taxonomy":"services_cat","embeddable":true,"href":"https:\/\/koloro.ua\/en\/wp-json\/wp\/v2\/services_cat?post=18687"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}