Godot Shader Tutorial [Basics] in 7 minutes

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] what's up neck beards would you be interested in some shaders shaders are amazing they give a lot of life to our effects or just the visual look of our games in general super useful from the simplest things like flashing enemies when the player hits them making colored silhouette effects screen transitions dramatic effects and many many more if you're making a game now and you're not using shaders your opinion is wrong and you should be ashamed of yourself for the longest time i have postponed trying to learn shaders some people say it's complicated particularly because it uses a different language from whatever language our game engine uses but i'm here to tell you now you can use go dot shader's friend i guess the simplest example we can start with is flashing enemies in this case we will only apply the shader to our sprite so let's focus only on the sprite mode and you can ignore all the other nodes to apply shader to any sprite go to material and select new shader material go to shader and select new shader and there we go we can now start coding our shader as i mentioned before the shader language is different from the usual gd script but it's pretty easy once you get used to it first we start by declaring our shader type in this case we are going to use canvas item since we are using it on a sprite which derives from a canvas item class next we declare the shader function we are going to use we only need the fragment function for this one the fragment function runs for every pixel in a sprite and determines what color that pixel should be to make it easier to understand let's make an example let's take the built-in variable called color in all caps whatever we put in color will be the final output to the sprite now let's assign a vector4 to color color takes four values red green blue and alpha that's why we use vector4 to assign colors to it let's assign one to all the values this will make our sprite full white as you can see adjusting these values will also adjust the color of our sprite to make it more convenient we can also store the color we want into a variable let's store it in small case color and then assign that variable to the final output as you can see the results are the same but there is a problem we only want the enemy texture itself to flash and not the whole sprite so how do we check only for the position of the enemy texture within the sprite we use uv of course uv basically means the coordinates within the sprite and we take the uv of the sprite by using the texture built-in variable which takes the uv from our texture just like this and now all we have to do is mix it with another color just like this we use the built-in function mix and we assign it to our color variable we want to mix the color values of our current texture to whatever color we want so we mix the rgb values the first two arguments are the colors we want to mix and the last argument is how much we want to apply the second value to the first value and there we go we have our flashing enemy as always we could just alter these numbers to get the color we want we can also alter the last argument if we don't want the flash effect fully opaque but how do we actually access these values with our normal gd script code by using uniforms of course uniforms let us access the variables in our shader language from our usual language and the inspector let's declare our first one which is flash color as you can see we now have access to a color wheel on the inspector it's like exporting a variable in normal gd script let's now assign this flash color value to our second argument in the mix function below our next uniform will be our flash modifier which will be the last argument in our mix function below [Music] and we should be ready to go [Music] amazing [Music] now we know how to make the shader but how do we actually apply it in game first let's save the shader that we made so that it can be used by any object in our game which might need this shader go to resource tab and check local to scene don't forget this otherwise all the objects that has this shader will all flash at the same time now let me show you how i applied the shader on my actual code in my enemy script i added a function called flash this function will get called every time the enemy is hit with the player bullet inside the function i use the set shader param function to access the uniform flash modifier and set it to 1. i also added a timer which will reset it back to zero after a short amount of time creating the flash effect that's how simple it is i use the same shader and applied it to my player as well when she gets hit the dash effect silhouette also uses the same shader but with a pink color [Music] so now that we know the basics of god at shader where do we go from here well like this guy suggested i also suggest downloading the demo shaders in the godot library simply copy those shaders into your own project and use them as needed there are also tons of free shaders on the internet like go.shaders.com remember the best way to create the best games is to steal from others [Music] now it's time to address the elephant in the room what is this beautiful game that i have been showing throughout this video well let me tell you about a latest game polaris it's a new passion project that we have been working on for the past few weeks right now i'm in the middle of transferring it from gms2 to godot i will make a proper video about it soon but if you want to follow the game or even contribute to it join our discord server you can also play the gms to alpha build links in description but that's all i have for you right now i hope you learned something please check my references in the description if you want to learn more about go dot shaders smash that like button or i will smash your
Info
Channel: Master Albert
Views: 18,292
Rating: undefined out of 5
Keywords: godot, godot shader tutorial, godot engine, shaders in godot, godot shader, devlog, indie game devlog, game devlog, indie devlog, godot game engine, game development, godot tutorial, godot flash shader, godot full screen shader
Id: ctevHwoRl24
Channel Id: undefined
Length: 7min 46sec (466 seconds)
Published: Thu May 06 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.