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 1cross(vec3(1, 0, 0), vec3(0, 1, 0))
- Result
vec3(0, 0, 1)
Example 2cross(vec3(0, 1, 0), vec3(1, 0, 0))
- Result
vec3(0, 0, -1)
Example 3cross(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 and GLSL ES 3.00.
Related functions
- 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
declare function cross<V extends vec3>(a0: V, a1: V): Vdeclare function cross(a: vec3, b: vec3): vec3Parameters
Return value
Vvec3
Description
Undefined for other vector shapes.
Targets
- WGSL
-
cross(a, b) - GLSL ES 3.00
-
cross(a, b)