---
title: "dot"
description: "The dot product of two vectors."
group: "space"
groupTitle: "Shapes, frames & warps"
categoryId: "math"
categorySlug: "math"
categoryTitle: "Math"
kind: "function"
sourceUrl: "https://github.com/shader-effects-inc/shaders/blob/main/packages/core/src/std/math.ts#L339"
---

# dot

The dot product of two vectors.

```ts
dot(a: Val, b: Val): Expr
```

Import `math` from `shaders/std` and use `math.dot`.

With two unit vectors it is the cosine of the angle between them, which is how a light direction meets a surface normal.

## Parameters

| Name | Type | Notes |
|---|---|---|
| `a` | `Val` |  |
| `b` | `Val` |  |

## Example

```ts
const facing = max(dot(normal, lightDir), 0)
```

## See also

- [`normalize`](/docs/primitives/math/normalize) — The vector scaled to length 1.
- [`cross`](/docs/primitives/math/cross) — The cross product of two 3D vectors.

## Used by

[CarbonFiber](/docs/components/carbonfiber), [Crystal](/docs/components/crystal), [Frost](/docs/components/frost), [Goo](/docs/components/goo), [Heatmap](/docs/components/heatmap), [Holographic](/docs/components/holographic), [Irradiance](/docs/components/irradiance), [Nebula](/docs/components/nebula), [PixelThrow](/docs/components/pixelthrow), [Plastic](/docs/components/plastic), [ReactionDiffusion](/docs/components/reactiondiffusion), [Sparkle](/docs/components/sparkle), [TimeTrail](/docs/components/timetrail), [Voxels](/docs/components/voxels), [Water](/docs/components/water)