Edge detection · Beginner
Laplacian edge detection
A one-kernel edge detector — the second derivative of depth and normals, live and editable.
Where Sobel estimates the first derivative of an image (the
slope, from two directional kernels) and takes its magnitude, the Laplacian goes
straight for the second derivative — the change in the slope — with a single kernel.
It's cheaper (one convolution, no gx/gy to combine), rotationally symmetric, and tends
to draw thinner lines. The trade is that a second derivative amplifies noise, so it
usually wants a clean signal — which is exactly what a depth/normal buffer gives us.
This runs on the same G-buffer as the Sobel page (see there for the full pipeline write-up
and the sampleAlbedo/Normal/Depth API). Drag to orbit, + / − to zoom, and use the
buffers switch to watch which channel the operator fires on — including a mask
view of the edge it draws.
The kernel
The classic 4-neighbour Laplacian is a single 3×3 stencil:
0 1 0
1 -4 1
0 1 0
It sums a pixel's neighbours and subtracts the centre four times: zero on flat regions, and a sharp spike (positive or negative) right at an edge. Take the absolute value and you have your edge strength. Edit it live:
Things to try
- The raw response:
O = vec4(vec3(edge), 1.0);— notice the lines are crisper and thinner than Sobel's. - The 8-neighbour version: add the four diagonals and change the centre weight to
-8for a stronger, slightly thicker result. - Depth vs. normals: zero the
normalLapterm and flip to the depth buffer — the Laplacian misses same-depth creases just like Sobel does, which is why we add normals.
Sobel or Laplacian?
Both find edges from the same buffers; they differ in character. Sobel (gradient magnitude) gives thicker, more forgiving lines and a direction you can reuse (for flow, hatching, anisotropic effects). Laplacian (single kernel) is cheaper and thinner but more sensitive — great when the input is clean, like a depth buffer. For stylised outlines, try both on the same scene and pick the line weight you like.