faceForward
Function
Face-forward chooses the sign of a normal from the dot product of a reference normal and an incident direction.
Related names in other languages
These related operations can differ in arguments, support, and semantics. The foreign names are not accepted TypeShade aliases. Check the target forms and restrictions.
- GLSL:
faceforward
Compare examples
Compare negative, positive, and zero reference dot products. Zero takes the negated-normal branch.
Model assumptionsn = nref = vec3(0, 1, 0)
Example 1i = vec3(0, -1, 0)
- Result
vec3(0, 1, 0)
Example 2i = vec3(0, 1, 0)
- Result
vec3(0, -1, 0)
Example 3i = vec3(1, 0, 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 orient a shading normal on a surface visible from either side.
Inputs and limits
The reference normal makes the decision; the returned vector is the supplied normal or its negation. This call does not normalize either vector.
For shader input rules and precision, consult WGSL and GLSL ES 3.00.
Related functions
- WGSL
faceForward(a, b, c)- GLSL ES 3.00
faceforward(a, b, c)
The signature, the sentence and any message are the compiler's own text at commit af54ddad5.
Returns n if dot(nref, i) is negative, else -n: the normal that faces the incident vector.
Syntax
declare function faceForward<V extends vec2 | vec3 | vec4>(a0: V, a1: V, a2: V): Vdeclare function faceForward<T extends Numeric>(a0: T, a1: T, a2: T): TA signature may name a type the ambient file declares for its own use. These are those declarations.
Numerictype 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.
-
a0VT -
a1VT -
a2VT
Return value
VT
Description
faceforward on GLSL.
Targets
- WGSL
-
faceForward(a, b, c) - GLSL ES 3.00
-
faceforward(a, b, c)