Godot Shader Language
When you first read shader code, it is natural to assume each line works on one number at a time. It does not. Many values in a shader are bundles of numbers, and one operator works on the whole bundle at once. Learn to read a Godot shader line by line: the header, types and vectors, swizzles, your own functions,…
Godot Shader Language
When you first read shader code, it is natural to assume each line works on one number at a time. It does not. Many values in a shader are bundles of numbers, and one operator works on the whole bundle at once. Learn to read a Godot shader line by line: the header, types and vectors, swizzles, your own functions, built-ins, choices and loops, and what the compiler says when you get it wrong. Part of a series on Godot shaders. Liam, in for Bear, narrates.
Chapters 0:00 Opening 0:09 The question 0:22 Key terms 0:37 I · The Shape of a File 2:30 II · Types and Vectors 4:27 III · Your Own Functions 5:59 IV · Choices and Loops 7:15 V · Read One Aloud 8:39 Recap 8:59 Your turn
Your turn. Paste this into Claude: Go through the Godot canvas item shader below one line at a time. After each line, add a comment giving the type of each piece. Flag any line where two types do not match. Then say in one sentence what it draws. Then check two things yourself.
- Check: pick one line and say the type of each piece yourself before you read Claude's.
- Check: run the shader. Does it draw what Claude's one sentence says?
Sources
- Godot 4.7 documentation, read 2026-10-13: the shading language, canvas item shaders, introduction to shaders, built-in shader functions, the shader preprocessor, converting GLSL to Godot shaders, and the shaders style guide (docs.godotengine.org/en/stable).
- Godot 4.7.2 itself: every result on screen is a scripted capture of a real run, with its renderer stated, and the compile errors shown are the engine's own log lines.
Honest notes. The narration is a synthetic voice (Liam, in for Bear) and has not yet been reviewed by ear. The Godot documentation passage shown at 5:35 and 6:36 is a quote card of the docs text, recorded 2026-10-13, not a screenshot of the page. The numbers in the film were run in Godot 4.7.2 on an Apple M4 Pro. The facts have not yet been signed off by Bear. Nobody has watched this film yet.
Made with the brutalist.art toolkit: Manim, Remotion and Kokoro, free and local. An independent educational film.
What this video covers
- 0:00 — Opening
- 0:09 — The question
- 0:22 — Key terms
- 0:37 — I · The Shape of a File
- 2:30 — II · Types and Vectors
- 4:27 — III · Your Own Functions
- 5:59 — IV · Choices and Loops
- 7:15 — V · Read One Aloud
- 8:39 — Recap
- 8:59 — Your turn
Transcript
A lightly formatted transcript of the video, with timestamps so you can jump to any section on YouTube.
Opening
[0:00] Go do shader language. Learn how a shader file is built, what its types and vectors mean, and how to read any shader line by line, even one an AI wrote for you. Hello, this is Liam in Forbear.
The question
[0:11] When you first read shader code, it is natural to assume each line works on one number at a time. It does not. Many values in a shader are bundles of numbers, and one operator works on the whole bundle at once. Five terms. A
Key terms
[0:23] Shader is a small program the graphics card runs to decide how something is drawn. A pixel is one dot of the picture. A type is the kind of value something holds. A function is a named block of code you can call. An argument is a value you hand it. Here is a real
I · The Shape of a File
[0:38] Shader 14 lines long. It makes a color breathe between pale gray and teal. God do refuses a line that breaks the rules. It will not warn you when a legal line does something you did not mean, so you have to read it. A shader file has three zones. Read from the top down. The header says what kind of shader this is. The globals are values declared outside every function. The functions are where the work happens. The header starts with shader type and it must be the first line. Canvas item means 2D drawing and interface. Spatial means 3D. An optional second line. Render mode picks options such as how a pixel blends with the background. Globals sit outside every function. A uniform is a value your game sets from outside. A const never changes. A varying hands a value from a shape's corners to its pixels. Declare each one above the code that uses it. Then come the functions. Godo calls three of them for you. Vertex places the corners.
Fragment sets the color of each pixel. And light handles each light that touches a pixel. This film uses fragment. Any other function is one you write yourself. Inside a function, every statement ends with a semicolon and braces group statements into a block. Forget one semicolon and go do refuses the whole shader. Here it points at the next line where it noticed. Spacing and line breaks are for people. Here is one shader that draws a soft gradient written three ways. Neat, squeezed onto one line and spread over many. God do draws the same picture for all three. Comments are notes for people. Two slashes comment out the rest of a line. Slar starts a block comment and star/ ends it. Godo skips both. So a commented outline does nothing. Godo's language is close to GLSL, the shading language of OpenGL, but not identical. Names must match exactly capitals included. A capital L makes level a different name. The other languages GL frag color is unknown here. God do calls it color.
II · Types and Vectors
[2:31] Every value has a type. A float is a decimal number. An int is a whole number and a bool is true or false. A texture has a type two called sampler 2D. You declare a variable with its type first then its name. Go is strict about this. A two with no decimal point is an int and god do will not quietly turn it into a float. Put it in a float or add it to one and the shader will not compile. Write 2.0. Shaders are full of vectors. Bundles of two to four numbers. Vec 2, vec 3, vec 4. A color is a ve 4. Red, green, blue, and alpha how solid it is. Reading a texture gives back a ve two. You
Build a vector by naming its type. Give ve 3 one number and it fills all three parts. Give veour a ve 3 and a number and it joins them. The pieces must add up to the size or go do refuses. Arithmetic works on every part at once. Multiply a ve 3 by 2.0 and all three numbers double. Multiply two vectors and each part meets its partner. That is why shader code is so short. Here it is in use. UV is the address of each pixel of ve 2. Join it with one half to make a ve 3. Scale by 0.6. Add 0.4. Red grows to the right. Green grows downward. You can reach into a vector by name. RGB takes red, green, and blue
From a ve 4.xy takes the first two parts. Picking or reordering parts like this is called swizzling. Order is yours to choose.BGr reverses the order and the gradients colors turn over. RGBA, XYZW, and STPQ name the same parts, but never mix sets in one swizzle. Go do refuses. The type on the left must match the type on the right. color is a vec 4 handed a ve 3 and go do refuses fix it by adding alpha vec 4 of c in 1.0 zero. To read any line, say the type of each piece from the inside out. UV is a ve 2 joined with 1/2 of ve 3 times a float still a ve 3 plus a float still a ve 3. Now your own
III · Your Own Functions
[4:28] Functions. The first line of a function is its signature. It has three parts. The type it hands back its name and its arguments each with a type. Calling the function hands values into the arguments in order. The body runs then return hands one value back and it must have the type the signature promised. break that promise and Godo says so. Godo reads from the top down. A function must be defined above the one that calls it. Call it first and the message says no matching function found. It does not say the order is wrong. A function you write cannot see most built-ins. A built-in is a value the engine hands to a function. UV and color are handed to fragment, not to your function. Use UV inside yours and go says unknown identifier. The fix is to pass what you need
In as an argument. Here UV goes in as address and the same gradient appears. A few built-ins are global such as time and pi and any function can read those. Arguments come in three modes. In the default hands over a copy so changes stay inside the function. In out hands over the original so the caller's variable changes. Out is for writing a result back. The functions go gives you follow the same pattern and the documentation lists each signature. In it, vect type means a float or a vect 2, three or four. Sign takes one of those and hands back the same type. A name can be reused if the argument types differ and go picks by type. This call passes one and int and gets teal. This one passes 1.0 a float and gets sand. Same name, same digit, different function.
IV · Choices and Loops
[6:00] And if needs a bool, a comparison like uv.x less than 1/2 gives true or false. If true, the first block runs otherwise the else block. Declare C above a variable made inside braces ends at the closing brace. The turnary is a oneline if write the condition a question mark. The value of true a colon then the value of false. It gives back a value so it can sit inside a longer line. Same picture one line. A for loop repeats a block. This one runs five times with the counter i going from 0 to four and each pass draws one stripe. The counter is an int. So convert it with float of i before mixing it with decimals.
Use for when you know the count and while when you do not. Take care. On modern graphics cards, an infinite loop can freeze your application. The editor included and go do cannot protect you from it. Compare floats against a range, not with equals. Light UV.x equal to exactly 1/2 and nothing draws here. No pixel center lands on it. A small range draws a thin line. The documentation warns float math varies by hardware. Two performance notes from the documentation. Discard, which throws a pixel away, has a cost. Modern graphics cards handle an if well when every pixel takes the same path, but too many branches can slow a shader down. This film did not measure either. Now read
V · Read One Aloud
[7:16] The file from the top. Use the same method. Say the type of each piece inside out and check that every line's types fit together. Line three is a uniform of vec. So a color source color is a hint. The editor treats the value as a color with no default. It is black until something sets it. Line four is a float with a default of two. Line six declares breathe. It hands back a ve 3. It takes two arguments, a ve 3 called base and a float called t. So the body gets a color and a number and it must return a color. Line seven sign of t is a float that swings between minus1 and one. Half of that plus a half is still a float now swinging between zero and one. It is stored in wave.
Line 8 vec 3 of 0.9 fills all three parts. a pale gray. Mix blends that gray toward base by the amount wave. Zero gives the gray, one gives bass. The result is a vec 3 as promised. In fragment tint rgb is a vec 3 and time time speed is a float. Breathe turns them into a ve 3. Vec 4 adds tints alpha and color. A vec 4 takes it. Now watch it run. Pale gray blends to teal and back and speed sets how fast every piece has a type and every type fits. That is what it means to read a shader. Now change one thing. Make tint a vec 3 and keep reading its alpha. A vec 3 has no alpha and god do says invalid member. Reading by types catches that before you run it. Let's
Recap
[8:40] Recap with claude. A shader file has a header, globals, and functions. Every value has a type and god do not quietly convert between int and float. Many values are vectors and arithmetic works on every part at once. A function has a signature and per pixel built-ins must be passed in. Choices need a bool and floats are compared against a range. to read a line. Say the type of each piece.
Your turn
[9:00] Your turn. Paste this into Claude. Go through the GoDo canvas item shader below one line at a time. After each line, add a comment giving the type of each piece. Flag any line where two types do not match. Then say in one sentence what it draws. Put your own shader under it. Now check two things yourself. Pick one line and say the type of each piece before you read Claude's answer and run the shader. Does it draw what Claude's one sentence says? Go do shader language at Nick Bear Brown.





