---
title: "nearestEdge"
description: "The closest point on the shape's edge to this pixel, and the outward normal there."
group: "light"
groupTitle: "Noise, light & materials"
categoryId: "materials"
categorySlug: "materials"
categoryTitle: "Materials & surfaces"
kind: "function"
sourceUrl: "https://github.com/shader-effects-inc/shaders/blob/main/packages/core/src/std/paint/materials.ts#L1305"
---

# nearestEdge

The closest point on the shape's edge to this pixel, and the outward normal there.

```ts
nearestEdge(
  sdfUV: Expr,
  sdf: Expr,
  slope: Expr,
  hint: string = 'edge',
): {point: Expr; normal: Expr}
```

Import `materials` from `shaders/std` and use `materials.nearestEdge`.

Where a rim glow or contact shadow comes from for pixels outside the shape. `slope` is `fieldSlope`; its length is guarded.

## Parameters

| Name | Type | Notes |
|---|---|---|
| `sdfUV` | `Expr` |  |
| `sdf` | `Expr` |  |
| `slope` | `Expr` |  |
| `hint` | `string` | Optional. Default `'edge'`. |

## Example

```ts
const edge = nearestEdge(frame.sdfUV!, field.sdf, fieldSlope(field))
```

## See also

- [`fieldSlope`](/docs/primitives/materials/fieldslope) — The direction the shape's distance grows in: a 2D vector pointing outward at this pixel.
- [`pointLightFrom`](/docs/primitives/materials/pointlightfrom) — A point light as seen from a point on the shape: the 3D light vector `L`, the 2D direction `toLight` and the `distance`.
- [`continuedField`](/docs/primitives/materials/continuedfield) — The distance field extended past the edge of an SVG shape's texture.

## Used by

[Irradiance](/docs/components/irradiance)