GLSL shader example

Two-Pass Separable Gaussian Blur

The first pass filters x; the second filters its output along y. Use the pass selector to inspect the horizontal intermediate.

Live example

Edit the code and the preview updates as you type.

What to observe

Two-Pass Separable Gaussian Blur.

Mechanism

The first pass filters x; the second filters its output along y. Use the pass selector to inspect the horizontal intermediate.

The controlling code

c=texture2D(u_vertical,uv).rgb;

u_horizontal reads the image fixture, then u_vertical reads u_horizontal; Fragment displays u_vertical. Replace u_vertical with u_horizontal in the final texture2D call to see horizontal blur alone, with no change to either pass.

Experiment

In both u_horizontal and u_vertical, change the spacing factor 1.+u_parameter*3. to 4.. Horizontal and vertical blur become equally wide at a fixed scale; inspect u_horizontal to see the one-axis intermediate.

Debugging and cost

Each blur pass takes five filtered samples, followed by one final display lookup. Change only u_vertical's spacing factor to 0. to collapse its taps onto the center and leave the horizontal pass's blur visible.

Understand the technique

Built-in functions used

Learn it step by step