reflect
On this page

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 assumptionsn = vec3(0, 1, 0)

Example 1i = vec3(0.6, -0.8, 0)
Result
vec3(0.6, 0.8, 0)
Example 2i = vec3(1, 0, 0)
Result
vec3(1, 0, 0)
Example 3i = 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 and GLSL ES 3.00.

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

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 VT
  • a1 VT

Return value

VT

Description

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

Targets

WGSL
reflect(a, b)
GLSL ES 3.00
reflect(a, b)

Examples

See also

Edit this page Report a problem