Definition
A shader is a small program that works out the color and brightness of each dot when something is drawn on screen. Thousands of them run at once inside a graphics card, each taking a share of the dots and painting them fast. The same shape can look like metal or like water, depending on which rules you give it.
A mural the whole class paints together
Picture an art class painting one giant mural together. Divide the wall into small squares, and let each student take a few squares. The job is done in no time. But first, everyone needs to agree on the rules. Something like: "The sunlight comes from the upper left, so paint the lower right darker." You write the rules on a sheet of paper and hand a copy to everyone.
Game screens are drawn this way too. A screen is made of millions of tiny dots called pixels. Inside a graphics card sit thousands of simple calculators. They all work at the same time, and each one paints its own share of the dots in turn.
The sheet of rules that everyone holds is the shader. It is not a picture file full of colors. It is a set of steps for working out which color to use, and that is the key point.
Swap the rule sheet and the water starts to ripple
What you write on the rule sheet changes how the same object looks. Write "Make it bright where light hits head-on, and make only a tiny spot glow white," and the object gleams like metal. Write "Make it look softly hazy from every angle," and the very same object looks like rubber.
Shaders do more than pick colors. An object's frame is built from many corner points called vertices, and there are rule sheets for moving those points too. Add "as time passes, wave up and down," and the surface of a lake begins to ripple.
That is why the mood of a game can change completely just by swapping the rule sheet. A cartoon look and a foggy dawn are made by laying different rule sheets over the same objects. Rippling water and shining metal both come from this method. Developers can even lay one more rule sheet over the whole screen to add a glow or a blurred background.
A little more precisely
The rule sheet is not magic that paints the picture for you. A shader simply answers one question with numbers: "What color is this dot?" Collect millions of those answers and you have a finished scene. The whole process of producing the image is called rendering, and the shader handles the part that works out color and position.
This is also why the rules must be short and simple. They are repeated millions of times for every scene, and dozens of scenes per second. If the rules get too heavy, the computer can't finish a scene in time, and the screen stutters.
These days that crowd of calculators is borrowed for jobs that have nothing to do with pictures. Any task that lays out piles of numbers and repeats the same calculation works well with a split-it-up-and-do-it-all-at-once approach. Using graphics cards for AI training is the same idea: it borrows the mural-painting method as it is.
Common misconceptions
A shader is a picture file or pattern you put on an object in a game.
It is not a picture file. It is a program that calculates color and position. A pattern image is just one of the ingredients a shader can take in and use.
Shaders are only used when you need fancy special effects.
Almost everything you see on screen is drawn through a shader. Even the color of a plain wall or floor is the result of a shader's calculation.
Where you meet it
A lake in a game ripples with the wind, and the color of the sky reflects on its surface.
The moment you pick a filter in a photo app, the colors of the whole screen change right away.
In one sentence
A short set of calculation rules that tells a graphics card what color to paint every dot on the screen.