<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Chayan Vinayak on Medium]]></title>
        <description><![CDATA[Stories by Chayan Vinayak on Medium]]></description>
        <link>https://medium.com/@chayanvinayak?source=rss-479079610431------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*c3w-cPon5Q2T9qtZ.jpg</url>
            <title>Stories by Chayan Vinayak on Medium</title>
            <link>https://medium.com/@chayanvinayak?source=rss-479079610431------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 19:45:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@chayanvinayak/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Beginner’s guide to Shader Development using Unity — Part 2]]></title>
            <link>https://medium.com/@chayanvinayak/beginners-guide-to-shader-development-using-unity-part-2-578441bf6e80?source=rss-479079610431------2</link>
            <guid isPermaLink="false">https://medium.com/p/578441bf6e80</guid>
            <category><![CDATA[game-graphics]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[rendering]]></category>
            <category><![CDATA[shaders]]></category>
            <dc:creator><![CDATA[Chayan Vinayak]]></dc:creator>
            <pubDate>Wed, 30 Nov 2016 19:08:22 GMT</pubDate>
            <atom:updated>2016-12-05T18:59:25.839Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*FSDvAUFN0aTIN_Ppo7CUvA.jpeg" /><figcaption><a href="http://shaderdev.com/">http://shaderdev.com</a></figcaption></figure><p><strong>What are we going to understand in this article/ tutorial?</strong></p><p>In the <a href="https://medium.com/@chayanvinayak/beginners-guide-to-shader-development-using-unity-part-1-a81e8f87ee3e#.9clt8jf9y">previous article</a>, we discussed what is a Shader and what are it’s types. In this article, we will understand that why do we need two of the most basic shaders to draw a mesh on the screen — which are <strong><em>Vertex </em></strong><em>shader </em>and <strong><em>Pixel</em></strong><em> shader</em> and how both types of shaders work in the shading/rendering pipeline.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FEU7ScIwSTxg%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DEU7ScIwSTxg&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FEU7ScIwSTxg%2Fhqdefault.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/e9ba80cfcaf34a739863ea5ddd7ba8f9/href">https://medium.com/media/e9ba80cfcaf34a739863ea5ddd7ba8f9/href</a></iframe><p>Video Content from <a href="http://shaderdev.com/">http://shaderdev.com</a></p><p>Let’s start with an example of drawing a mesh triangle to understand the process.</p><p>Every mesh is composed of vertices, which is why to draw a mesh we will first collect the information of vertices and package it up one by one before sending it to Vertex shader. These packages/ packets are called as <strong><em>Vertex Input </em></strong>(as they are the input for Vertex-shader)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*NZR4vr-F2-VvtQZf.jpg" /></figure><p>Each packet/ package contains the information about the vertex which in the most basic scenario, is the — position value of the vertex. It can also contain color or normal value of the vertex. This packet of information is sent to Vertex shader.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*M241CAh4d2Dn2PyU.jpg" /></figure><p>Vertex shader act as a processing machine to process the data sent inside each packet as instructed. After vertex shader finishes processing the vertex data, it provides the processed information in the form of another packet called as <strong><em>Vertex Output</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*XdzRj-1Cp7pZUvmy.jpg" /></figure><p>The way the <em>Vertex Input</em> should at least have vertex position data. Similarly, <em>Vertex Output</em> should also have processed vertex position data which will be later passed over to the <strong><em>Rasterizer</em></strong>.</p><p>Usually, Vertex shader transforms object-space position value to projection-space position values of the vertex. If you don’t understand object-space and projection-space values then don’t worry about it, we will cover it in later articles.</p><p>In the Vertex shader, we can also manipulate the position of the vertex eg: To create a flag-shader, we can make the mesh of the flag wave based on the Sin wave function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*7dWv_fLCQUi4fUbo.jpg" /></figure><p>The Vertex Output then goes to <em>Rasterizer</em>, which is a hardware that based on the position of the vertices of the mesh determines that which pixels of the screen will be covered in order to draw the mesh on the screen. In other Rasterizer determine which pixels will be inside the geometric region.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*GzzOvB-U67aTWlrv.jpg" /></figure><p>Rasterization rules determine that which pixels will be covered by the geometry and one of those rules is Sampling. In the Sampling process, a Sample is given to each pixel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*kiPkkzOtY_B7Hu1f.jpg" /></figure><p>When a Rasterizer uses the process of Sampling to find out pixels covered by a geometric region, each pixel is given a sample and a ray is passed from the location of sample point. If the ray hits the geometry that means the pixel will be covered by geometry or it will be inside the geometric region.</p><p>Another role of Rasterizer is to <em>interpolate</em> the data for the pixels between the vertices. Let’s take a moment to understand what an interpolation of data means.</p><p><strong><em>Interpolation:</em></strong></p><p>If we have a triangle and this time with the position information, we will also pack normal information of the vertex inside Vertex input. After going through Vertex-shader, Rasterizer will receive the normal information of each vertex and figure out which pixels of the screen will be covered by the mesh when the triangle will be drawn on the screen, with that Rasterizer will also provide the normal value to each pixel based on the normal value read by each vertex.</p><p>Eg :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*0ADQkQ-Ts8KftOQn.jpg" /></figure><p>If this is the triangle and here are its normal values of the vertex.</p><p>Let’s first discuss the interpolation these two vertices to figure out the interpolated normal value of the pixel that lies at the center of this line (formed by two vertices).</p><p>x-normal value of top vertex is 0 and x-normal value of bottom vertex is 1 so the x normal value at the center will be 0.5</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*GB6VpKjdxH0CUVb1.jpg" /></figure><p>Similarly, y normal value of top vertex is — 1 and y normal value of bottom vertex is — 0 so the x normal value at the center will be 0.5</p><p>This is why the normal value for the pixel that lies at the center of this line will be — (0.5, 0.5, 0). In this manner, the normal value for each pixel will be calculated by the Rasterizer.</p><p>At this point, Rasterizer has figured out that which pixels of the screen will be covered by the geometric region and every pixel has its own interpolated values.</p><p>For every determined pixel, Fragment/Pixel shader will be executed. “Vertex-output” — the packet of information that came out of Vertex-shader which was then passed to Rasterizer — is passed to Fragment/Pixel Shader.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*sBr0VUMe9kae7J1P.jpg" /></figure><p>Fragment/Pixel shader will process the information as instructed and output the color and alpha value for the pixel which will eventually contribute to the final pixel color on the screen.</p><p>In my next post, I will share more about the components of a shader. In the meantime, you can watch tutorials from my shader development series: <a href="http://shaderdev.com/">Shader Development using Unity 5</a>, which is available on:</p><ul><li><a href="http://cvgshader.teachable.com/">Teachable.com</a></li><li><a href="http://www.cgcircuit.com/course/shader-development-using-unity-5">Cgcircuit.com</a></li></ul><p>And here is the full preview playlist on youtube : <a href="http://bit.ly/shaderguide">Shaderguide</a> or <a href="http://www.youtube.com/playlist?list=PL09X4HXJpa8kfw8cZjyYZel8WlOT5B1_k">Youtube</a></p><p>Thank you!</p><p>Chayan Vinayak Goswami</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=578441bf6e80" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Beginner’s guide to Shader Development using Unity — Part 1]]></title>
            <link>https://medium.com/@chayanvinayak/beginners-guide-to-shader-development-using-unity-part-1-a81e8f87ee3e?source=rss-479079610431------2</link>
            <guid isPermaLink="false">https://medium.com/p/a81e8f87ee3e</guid>
            <category><![CDATA[mobile-game-development]]></category>
            <category><![CDATA[shader-in-unity]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[shaders]]></category>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[Chayan Vinayak]]></dc:creator>
            <pubDate>Sun, 11 Sep 2016 06:52:34 GMT</pubDate>
            <atom:updated>2016-12-06T21:00:48.271Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MSWiaGuJyMEbTxK0XO4_5Q.jpeg" /><figcaption>Shader Development using Unity 5</figcaption></figure><p><strong>What we are going to understand in this article/ tutorial?</strong></p><ol><li>What is a shader?</li><li>Types of shaders based on their functionality.</li></ol><p><strong><em>Shader and their types</em></strong>:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FV0E5WH7JRLo%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DV0E5WH7JRLo&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FV0E5WH7JRLo%2Fhqdefault.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/c88a6bbfc5d7a74db20b08172f39c403/href">https://medium.com/media/c88a6bbfc5d7a74db20b08172f39c403/href</a></iframe><p><strong>W<em>hat is a shader</em></strong>?</p><p>When we ask a computer to perform any operation, we give an instruction to it, and a set of these instructions is called a <a href="https://en.wikipedia.org/wiki/Computer_program">Program</a>. <em>A program that is used or contributes to shade or draw something on the screen is called a </em><a href="https://en.wikipedia.org/wiki/Shader"><em>shader</em></a>.</p><p>Shader is a set of instructions that is run on <a href="http://www.nvidia.com/object/what-is-gpu-computing.html">GPU — Graphics Processing Unit</a></p><p><strong>GPU: </strong>A processing unit or circuit specially designed for faster and efficient computer graphics operation or image manipulation. GPU is also being used in deep-learning calculations. If we quickly take a look at the comparison of GPU and CPU.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/269/0*WtriJrDTMibyBViL.png" /></figure><p>A CPU with four (or 8 or 10) cores in it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/269/0*hbjYfT1o93Dmtejc.png" /></figure><p>A GPU with thousands of cores in it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/0*wieLEFO0LY2uiNjZ.png" /></figure><p>Cores of CPU are designed for serial operations, whereas cores of GPU are designed for parallel or simultaneous operations.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F-P28LKWTzrI%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D-P28LKWTzrI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F-P28LKWTzrI%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/c8c58ef177d27eb81996524f560952f6/href">https://medium.com/media/c8c58ef177d27eb81996524f560952f6/href</a></iframe><p><a href="https://www.youtube.com/watch?v=-P28LKWTzrI">That’s how fast GPU is, in comparison of CPU</a>.</p><p>Now, let’s take a look at the types of shaders based on their functionality.</p><p>Based of the functionality or the purpose of the shader, they can be classified as:</p><p>1. Vertex shader</p><p>2. Pixel shader</p><p>3. Geometry shader</p><p>4. Compute shader</p><p>5. Tessellation shader</p><p>When we have to show or draw any object on the screen, it will be in the form of primitives or a mesh.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*NgjlDGoEnTd-Vl3WBxVRBQ.png" /></figure><p>If we have to draw a geometry of a specialized character in the game, it will be made up of a mesh/vertices. Additionally, a texture can be applied on the mesh or it can even be rigged to make it animate. At the simplest level, even if we have to draw a texture, we will have to draw a mesh card and then we will draw a texture on top of it. If we shade something, we will draw the object (i.e. its mesh first) and then shade it. That means it all comes down to drawing a mesh.</p><p>A mesh is composed of vertices or primitives.</p><p><strong><em>What is a </em></strong><a href="https://www.opengl.org/wiki/Primitive"><strong><em>Primitive</em></strong></a><strong><em>?</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*f_Ciu8BNKaEAmGmc.png" /></figure><p>Primitives are the basic units of a mesh:</p><p>1. Triangle</p><p>2. Line</p><p>3. Point</p><p><strong><em>How will we draw and shade a triangle on the screen?</em></strong></p><p>In order to draw a triangle on the screen we will first have to draw the vertices as a mesh is made up of vertices. To draw the vertices, we will use our first type of shader: a Vertex shader. We will collect the information of the vertex-position (in addition it can be vertex-normal and vertex-color information) and give it to Vertex shader to draw them on the screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*Vy2YVTOjsED8HkzNF6MN8A.png" /></figure><p>Our next problem is — how to fill the area in between these vertices? In other words, how to shade the pixels of the screen in the region of this geometry. To perform that operation, we will use Pixel shaders. A Pixel shader, also known as Fragment shader, is a type of shader that works on a pixel or a fragment.</p><p><strong><em>Fragment</em></strong>: The term, fragment, is used to define an element that will eventually contribute to the final color of the pixel. A fragment is like a presidential candidate: a candidate can be a president, it can not be a president, or it can contribute to a president. In future blog-posts, we will see how a fragment contributes to the final color of the pixel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*Tt5XHRFHHpZYG0FF_VswtA.jpeg" /></figure><p><strong><em>Tessellation shader</em></strong>: Also known as Hull shader, these are relatively new shaders as they are added in OpenGL 4 and Directx 3d 11. In a nutshell, Tessellation shader is used to subdivide the mesh.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*7qF9PaPx2JTzfSLfBfYb-A.png" /></figure><p><a href="https://developer.apple.com/videos/wwdc2016/">In 2016 WWDC</a>, which is Apple’s Worldwide Developer’s Conference, Apple introduced their <a href="https://developer.apple.com/videos/play/wwdc2016/606/">new metal tessellation pipeline</a>. Metal is Apple’s graphics API, but in this pipeline, Tessellation shaders are Fixed function shaders which means they are non programmable shaders because they are embedded inside the hardware.</p><p><strong><em>Fixed function shader</em></strong><em>:</em> A shader that is not programmable and is embedded inside the hardware.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*Ifbv4XT9qJMcdZj-EjO0sA.png" /></figure><p><strong><em>Geometry shader</em></strong>: As the name suggests, these are used to manipulate the geometry. Geometry shader takes a primitive as input (as Vertex shaders take a vertex as input). In the rendering pipeline, a Geometry shader comes in between the Vertex shader and Pixel shader.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*6BgNm0lJMxmeJoUdGSt3Pw.png" /></figure><p><strong><em>Compute shade</em></strong><em>r</em>: Compute shader is a general purpose shader that is used outside of rendering pipeline which means they are not used to draw a primitive or shade pixel. Instead, we use Compute shaders to utilize GPU’s parallel processing capability for general purpose tasks.</p><p>In my next post, I will share more about the workings of a shader. In the meantime, you can watch tutorials from my shader development series, <a href="http://bit.ly/shaderdev">Shader Development using Unity 5</a>, which is available on:</p><ul><li><a href="http://www.linkedin.com/redir/redirect?url=Teachable%2Ecom&amp;urlhash=8moB&amp;_t=tracking_anet">Teachable.com</a></li><li><a href="http://www.linkedin.com/redir/redirect?url=Cgcircuit%2Ecom&amp;urlhash=fisc&amp;_t=tracking_anet">Cgcircuit.com</a></li></ul><p>Thank you!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a81e8f87ee3e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>