Godot 3.0 has a new Shading language which bases on GLES3.0 and is much more efficient and better while still providing similar capabilities. So let’s create a simple shader that displays plain COLOR.

So let’s start with a basic scene with a Node2D and then a Sprite.

Now select the sprite go to Inspector and load icon.png[The Godot ICON].

Now go to the Materials section and add a New ShaderMaterial.

Click on the newly created material and then create a New Shader.

Select the shader and a new tab opens.

Let’s start coding our first shader.

As you see the first step is to assign a shader_type and render_mode.

Shader type: for a 2D object iscanvas_item, for 3D it’sspatial and for Particles it’s particles.

This tells the shader compiler what kind of rendering system will the shader access and we get variable access accordingly.

render_mode varies with shader_type but the most basic one is unshaded.

This tells the computer what operation the shader will perform over the original texture and/or how will the shader be judged by the rendering system.

The most important(only) shader functions are: fragment() and vertex().

These functions provide access to the vertexes rendered, for vertex() and fragments on screen, for fragment().

So let’s get started with some actual code.

But first go to the documentation and read a little so that we all are on the same page. Link: http://docs.godotengine.org/en/3.0/tutorials/shading/shading_language.htm

CODING

For this tutorial we will be using fragment().

Now set COLOR = vec4(1.0)

Now you see the image turn to a plain white color.

The color changes because we set all the fragments to white color.

Every color is a vec4, it has 4 values:- red, green, blue and alpha.

You can access them by saying: COLOR.rgba or COLOR.xyzw

This is a useless trick, so let’s input a color to display instead of plain white.

Add this above the fragment():

uniform vec4 color : hint_color;

and change vec4(1.0) to color

Open the shader material.

You now see Shader Param and Color inside of it. Change it to something else.

Awesome now what? We now know how to set the color of an object through shader.

Step 2: Change the expression to COLOR.xy = UV;