Home โ€บ Module 2
๐Ÿ”ฅ Module 02 ยท Advanced

Paint with Code ๐ŸŽจ

What if you could paint with pure code? In this mission, you'll learn how to write special instructions for your computer's graphics card to create wild visual effects like shimmering water, gooey slime, or a hero that glows with power!

๐Ÿงช

What is a Shader?

โฌ…๏ธ Without Shaders vs. With Shaders โžก๏ธ. See the difference? That's the power you're about to learn.

Welcome back, Master Builder! Have you ever wondered how games make fire look so fiery, or how an enemy glows red when they take damage? The secret is a special program called a Shader. Normal game code runs on the computer's main brain (the CPU), but a Shader is a tiny program designed to run on the Graphics Card (the GPU). It's built to do one job incredibly fast: tell every single pixel on your screen exactly what color it should be, all at the same time.

๐Ÿ’ก Pan's Pro Tip: The Painter's Army!

Think of the CPU like one super-smart painter, carefully deciding where to put the next brush stroke. ๐Ÿง‘โ€๐ŸŽจ

Now, think of the GPU running a Shader like an army of 10,000 tiny painters, each painting exactly one dot on the screen at the exact same time. That's how games get so fast and look so amazing!

๐Ÿ“บ The Cherno gives a super clear explanation of what shaders are and how they create incredible visual magic.

๐Ÿ”ฎ Deep Dive: The Two Types of Shader Painters

Your painter's army has two main teams. You need both to make cool effects!

  • Vertex Shaders ๐ŸŸฆ: This team is in charge of SHAPE. They grab all the corners (vertices) of a 3D model and decide where they go on the screen. Want to make a jello cube wiggle or a flag wave in the wind? That's a job for the Vertex Shader team!
  • Fragment Shaders ๐ŸŸฅ: This team is in charge of COLOR. After the Vertex Shader team positions everything, the Fragment Shader team comes in and paints every single pixel. Want to make a robot's armor look metallic and shiny, or make a magical sword glow? That's a job for the Fragment Shader team!

๐Ÿ•ต๏ธ Knowledge Check: Which painter is in charge?

Making a character's armor shiny and reflective.

Fragment Shader
Vertex Shader

Making a jello cube wiggle when it moves.

Fragment Shader
Vertex Shader
๐Ÿ“บ See how a pro game developer at Brackeys uses a visual "Shader Graph" to build a cool force field without writing code. This is how the magic happens in real game engines!
๐Ÿง‘โ€๐Ÿ’ป

Let's Build a Shader!

Time to get hands-on. We'll start simple and level up to writing a real, live shader. Ready? Let's go! ๐Ÿš€

Level 1: The Color Switch

Let's start with the basics. Code can tell an object what color to be. Press the buttons below to change the color of the sphere. You're controlling its shader with a single click!

Level 2: The Color Mixer

Awesome! Now, let's mix our own colors. In shaders, colors are made of Red, Green, and Blue light, with values from 0.0 (off) to 1.0 (full brightness). Drag the sliders to mix your own color and see how the code changes!

vec3 tint = vec3(1.00, 1.00, 1.00);
Tell Me More! ๅฅฝๅฅ‡

When shader code says `finalColor = objectColor * tint;`, what does "multiplying" a color mean?

Think of the `tint` color as a light filter. `vec3(1,1,1)` is a pure white light โ€” it lets all of the object's original colors pass through perfectly. But `vec3(1,0,0)` is a pure red filterโ€”it blocks all the green and blue light, only letting the red part of the object's color show up. That's why a white object turns red!

๐Ÿ›ก๏ธ Safety Check: Exploring with a Partner

As you explore sites with user-created content like Shadertoy, you'll find amazing code from creators all over the world. But remember, these are unmoderated communities. The #1 rule is to **explore with a parent.** If you see anything that makes you feel weird or confused, show them right away. You're not in troubleโ€”you're being a smart explorer and helping keep the community fun for everyone.

Level 3: The Live Lab ๐Ÿš€

You're ready for the real thing. This isn't a simulationโ€”it's a live shader editor embedded from a site called Shadertoy. The code is controlling the animation. Click on it, change some numbers, and hit the "play" button at the bottom to see what happens. This is what real shader development feels like!

๐Ÿงช Try this: In the code, find the line that starts with `vec3 col =`. Can you change `cos(iTime...` to `sin(iTime...`? What happens if you change `0.5*cos(...)` to `5.0*cos(...)`? Don't be afraid to break itโ€”that's how you learn!

๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘ง Parent Corner

Your young developer is learning a real, professional-level skill. Shader programming is used in everything from blockbuster games to movie CGI and even medical imaging! This isn't just a toy; it's a window into a powerful career.

  • Next Steps Together: Ready for a real challenge? Follow this official Godot tutorial on writing your first 2D shader to make a character flash when they take damage. This is a real skill used in thousands of games.
  • Conversation Starter: Ask them, "If you could create any visual effect for a game, what would it be? How would you use color and motion to make a player feel powerful, or fast, or magical?"

๐Ÿ“š Learn More

โ† Previous