---
title: "reflect: WGSL and GLSL examples, uses and input limits"
description: "Reflection mirrors an incident direction across a surface normal. Use it to aim an environment-map lookup or trace a reflected ray."
url: https://typeshade.dev/reference/functions/reflect/
language: en
---

# `reflect`

Function

Reflection mirrors an incident direction across a surface normal.

## Compare examples

Compare an incoming ray, a grazing ray, and a ray along the normal. The normal component changes sign.

**Model assumptions**`n = vec3(0, 1, 0)`

**Example 1`i = vec3(0.6, -0.8, 0)`**

**Result**

`vec3(0.6, 0.8, 0)`

**Example 2`i = vec3(1, 0, 0)`**

**Result**

`vec3(1, 0, 0)`

**Example 3`i = vec3(0, -1, 0)`**

**Result**

`vec3(0, 1, 0)`

The examples are calculation models and do not run GPU work. The reference below gives the complete call signatures. Decimal results are rounded for display. The stated assumptions determine each example; actual shader results follow the target precision and execution rules.

## When to use it

Use it to aim an environment-map lookup or trace a reflected ray.

## Inputs and limits

Normalize the surface normal. This is a direction calculation; surface roughness and material brightness require separate models.

For shader input rules and precision, consult [WGSL](https://www.w3.org/TR/WGSL/) and [GLSL ES 3.00](https://registry.khronos.org/OpenGL/specs/es/3.0/GLSL_ES_Specification_3.00.pdf).

## Related functions

- [`refract`](https://typeshade.dev/reference/functions/refract/)
- [`dot`](https://typeshade.dev/reference/functions/dot/)
- [`normalize`](https://typeshade.dev/reference/functions/normalize/)

**WGSL**

`reflect(a, b)`

**GLSL ES 3.00**

`reflect(a, b)`

The signature, the sentence and any message are the compiler's own text at commit af54ddad5.

Reflects the incident vector `i` about the normal `n`: `i - 2 * dot(n, i) * n`.

## Syntax

```ts
declare function reflect<V extends vec2 | vec3 | vec4>(a0: V, a1: V): V
declare function reflect<T extends Numeric>(a0: T, a1: T): T
```

A signature may name a type the ambient file declares for its own use. These are those declarations.

**`Numeric`**

`type Numeric = number | vec2 | vec3 | vec4 | vec2i | vec3i | vec4i | vec2u | vec3u | vec4u`

## Parameters

A parameter named by position (`a0`, `a1`) carries a name the ambient file generates. A call passes its arguments in order and names none of them.

- `a0` `V``T`
- `a1` `V``T`

## Return value

`V``T`

## Description

`n` should be normalized. Same shape in, same shape out.

## Targets

**WGSL**

`reflect(a, b)`

**GLSL ES 3.00**

`reflect(a, b)`

## Examples

- [`path/ray-tracer/ray-tracer.shade.ts`](https://typeshade.dev/guide/examples/ray-tracer/)
- [`gallery/bit-bump/bit-bump.shade.ts`](https://typeshade.dev/guide/examples/bit-bump/)

## See also

- [Functions](https://typeshade.dev/reference/functions/)
- [Builtin table](https://typeshade.dev/guide/language/builtins/#geometry)
