---
title: "cross: WGSL and GLSL examples, uses and input limits"
description: "A cross product makes a vector perpendicular to two three-dimensional vectors, using the right-hand rule."
url: https://typeshade.dev/reference/functions/cross/
language: en
---

# `cross`

Function

A cross product makes a vector perpendicular to two three-dimensional vectors, using the right-hand rule.

## Compare examples

Swap the input vectors and compare the sign. Parallel inputs give a zero vector.

**Example 1`cross(vec3(1, 0, 0), vec3(0, 1, 0))`**

**Result**

`vec3(0, 0, 1)`

**Example 2`cross(vec3(0, 1, 0), vec3(1, 0, 0))`**

**Result**

`vec3(0, 0, -1)`

**Example 3`cross(vec3(1, 0, 0), vec3(2, 0, 0))`**

**Result**

`vec3(0, 0, 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 build a surface normal or measure an oriented parallelogram area.

## Inputs and limits

The magnitude depends on both lengths and the angle. Normalize the result only when it is nonzero; use three-component vectors.

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

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

**WGSL**

`cross(a, b)`

**GLSL ES 3.00**

`cross(a, b)`

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

Computes the cross product of two `vec3` values, returning a `vec3`.

## Syntax

```ts
declare function cross<V extends vec3>(a0: V, a1: V): V
declare function cross(a: vec3, b: vec3): vec3
```

## Parameters

- `a` `V``vec3`
- `b` `V``vec3`

## Return value

`V``vec3`

## Description

Undefined for other vector shapes.

## Targets

**WGSL**

`cross(a, b)`

**GLSL ES 3.00**

`cross(a, b)`

## Examples

- [`gallery/capsule-corp-namek-class/capsule-corp-namek-class.shade.ts`](https://typeshade.dev/guide/examples/capsule-corp-namek-class/)
- [`gallery/path-tracer/path-tracer.shade.ts`](https://typeshade.dev/guide/examples/path-tracer/)
- [`gallery/rt-renderer-class/rt-renderer-class.shade.ts`](https://typeshade.dev/guide/examples/rt-renderer-class/)

## See also

- [Functions](https://typeshade.dev/reference/functions/)
- [Builtin table](https://typeshade.dev/guide/language/builtins/#geometry)
- [`cross()` in `typeshade/core/ir`](https://typeshade.dev/api/cross/)
