Skip to main content

Simple yet powerful Shaders in GODOT

Watch the Video Tutorial

https://youtu.be/j_fCGoaoRmg
   


Hit Flash Effect Shader

This is a very simple shader and mostly used to make the player white indicating a hit or damage.


shader_type canvas_item;


uniform float quantity : hint_range(0.0, 1.0);


void fragment(){

vec4 base = texture(TEXTURE, UV);

vec4 new_color = vec4(1.0,1.0,1.0, base.a);

COLOR = mix(base,new_color,quantity);

}

 

Grayscale Shader

                  GrayScale can be useful in many cases, 

like if you   have a shop and some items are locked then You can turn them grayscale. 

Or maybe  use it to turn the entire scene grayscale when the  player dies, similar to GTA V.


shader_type canvas_item;

uniform float quantity : hint_range(0.0, 1.0);

void fragment(){

vec4 original = texture(TEXTURE, UV);

float mean = (base.x + base.y + base.z) / 3.0;

vec4 gray = vec4(mean, mean ,mean, original.a);

COLOR = mix(original, gray, quantity);

}


Moving background Shader

                  A long time ago I made an endless runner game in which 

                  I want to move the road vertically. But instead of actually moving the road 

                  I used a shader to move it. Since Shaders work on GPU thus it reduce a little pressure on CPU                 

                 Similar to this you can also apply this shader to move it horizontally instead of actually moving the sprite.


shader_type canvas_item;

uniform float speed : hint_range(0.0, 5.0) ;

void fragment(){

vec2 uv = vec2(UV.x, UV.y - TIME * speed);

COLOR = texture(TEXTURE, uv);

}


Brightness Contrast Saturation Shaders

I don’t think I have to tell the use case for this shader. You can really use it in every single game of yours.
You can also put the Color correction shader in the ColorRect And then use SCREEN_TEXTURE and SCREEN_UV instead of regular TEXTURE and UV. This will apply color correction to the entire scene at once.


shader_type canvas_item;


uniform float brightness : hint_range(0.0,3.0) ;

uniform float contrast : hint_range(0.0,3.0) ;

uniform float saturation : hint_range(0.0,3.0);


void fragment(){

// Viewport texture

vec4 input_color = texture(SCREEN_TEXTURE, SCREEN_UV);

//Brightness adjustment

input_color.rgb = mix(vec3(0.0), input_color.rgb, brightness);

//Contrast adjustment

   input_color.rgb = mix(vec3(0.5), input_color.rgb, contrast);

//Saturation adjustment

float gray = (input_color.r + input_color.g + input_color.b) / 3.0;

    input_color.rgb = mix(vec3(gray), input_color.rgb, saturation);


//Final result

COLOR = input_color;

}



Blur

Creating the Blur effect is simplest among all. But you have to apply this Blur effect on ColorRect Node.


shader_type canvas_item;

uniform float blur : hint_range(0.0,5.0);

void fragment() {

COLOR = texture(SCREEN_TEXTURE, SCREEN_UV, blur);

}



Comments

Popular posts from this blog

Complete 2D player movement, Beginner to Pro in Godot

 Have you ever wondered why these games feel so good to play? If your answer is visuals then ,  No the key component is their controls. The character movement feels natural, and they move exactly how you want. A good character movement will always make the player feel that they are in total control of the character.  So, you are wondering how to achieve this?  Well, there are some tricks that professional developers use to make their control better. And today we are goanna see what they are and how you can do it in Godot. VIDEO TUTORIAL COMPLETE CODE: extends KinematicBody2D var velocity : Vector2 export var max_speed : int = 1000 export var gravity : float = 55 export var jump_force : int = 1600 export var acceleration : int = 50 export var jump_buffer_time : int = 15 export var cayote_time : int = 15 var jump_buffer_counter : int = 0 var cayote_counter : int = 0 func _physics_process(_delta): if is_on_floor(): cayote_counter = cayote_time if not is_on_floor(): if cayot

Background Loading in Godot | DICODE

Video Tutorial       

Improve your jumping! | Type of jumps in Godot

Wall jump, Wall climbing, Wall sliding and double jump are some of the most common mechanics for a plat-former game. And on top of that they are super easy to create in Godot. So in this Godot tutorial, I have tried to implement all these things in the simplest way possible. I would highly recommend you to watch the 2-D movement video first, because I am adding wall jumps and other stuff in that same script. So, watch it at 1.5x speed! to get an overview. VIDEO TUTORIAL TEXT TUTORIAL Double Jump For this, create a variable jump_counter. This will keep track of how many jumps we have done, while we're in the air. So by default it will be 0. var jump_counter : int = 0 <------- var jump_buffer_counter : int = 0 var cayote_counter : int = 0 Now if you remember, in the previous video, when we are pressing the jump button. We are setting the jump_buffer_counter. So, when we are not on the ground, we will check if buffer_counter > 0 This will be true, only when we have pressed th