- Domain
- Post Process
- Blendable location
- Scene Color Before DOF
- Output
- Emissive Color
- Samples
- 4 per signal
Thickness that scales with distance
Thickness is set in pixels and goes from 2 px near the camera to 1 px far away, starting at 20 m and finishing 10 m later. Dividing by the view size converts pixels to UV, so the offset is computed once and reused by every sample.
Four diagonal samples
The screen UV is pushed toward the four corners around the pixel. In screen space Y grows downward, so bottom-left is (−1, 1).
Normal edges
The two diagonal differences of World Normal are added and the largest component is kept. A SmoothStep with its own threshold and softness turns that into a mask. This catches creases where depth barely changes.
Depth edges, made relative
The same cross runs on Scene Depth, divided by the largest of the four depths. Depth is in centimeters and grows with distance, so the raw difference would draw lines everywhere far away and almost none up close. Dividing turns it into a relative jump.
Mask and composition
The final mask is the Max of both edges. The outline color is blended over the scene color by the mask times Outline_Strength and sent to Emissive Color.
HLSL (reference) // Reference for the flow, not a ready-made Custom node float t = lerp(Thickness, ThicknessFar, saturate((Depth(uv) - Offset) / Falloff)); float2 px = t / ViewSize; float2 bl = uv + px * float2(-1, 1), tr = uv + px * float2( 1, -1); float2 br = uv + px * float2( 1, 1), tl = uv + px * float2(-1, -1); // Normal float3 dn = abs(Normal(bl) - Normal(tr)) + abs(Normal(br) - Normal(tl)); float nEdge = max(dn.r, max(dn.g, dn.b)); float nMask = smoothstep(NormalThreshold, NormalThreshold + NormalSoftness, nEdge); // Depth (relative) float dBL = Depth(bl), dTR = Depth(tr), dBR = Depth(br), dTL = Depth(tl); float dEdge = (abs(dBL - dTR) + abs(dBR - dTL)) / max(max(dBL, dTR), max(dBR, dTL)); float dMask = smoothstep(DepthThreshold, DepthThreshold + DepthSoftness, dEdge); float mask = saturate(max(nMask, dMask)) * Strength; return lerp(SceneColor(uv).rgb, OutlineColor, mask);
Exposed parameters
- Outline_Thickness
- thickness in px near the camera (2)
- Outline_Thickness_Far
- thickness in px far away (1)
- Offset / Falloff
- where the thinning starts and how long it takes
- NormalThreshold / NormalSoftness
- sensitivity of crease edges
- DepthThreshold / DepthSoftness
- sensitivity of silhouette edges
- Color / Outline_Strength
- look of the line
Next iteration
- Scale thickness by ViewSize.Y / 1080 so the line looks the same at 1080p and 4K.
- Fade the strength with distance, reusing the alpha from the thickness block.
- Compare normals by angle, 1 − dot(a, b), instead of the largest component.
- Use Custom Stencil to choose which objects get an outline.
From v1 to v2
- Pixel offset
- computed once instead of repeating ViewSize and Divide in all four corners
- ConstantBiasScale on normals
- removed: the bias cancels in the subtraction and the scale only halved the sensitivity
- Thresholds
- separate for normal and depth, because the signals have different scales
- Far thickness
- raised from 0.5 px to 1 px, because below one pixel the line flickers
Decisions and known issues
- Before DOF
- the outline blurs with depth of field instead of staying sharp over a blurred background
- Lines behind glass
- translucent surfaces write no normal or depth, so edges behind them show through