Name

faceforward - returns a normal as-is if a vertex's eye-space position vector points in the opposite direction of a geometric normal, otherwise return the negated version of the normal

Synopsis

float  faceforward(float  N, float  I, float  Ng);
float1 faceforward(float1 N, float1 I, float1 Ng);
float2 faceforward(float2 N, float2 I, float2 Ng);
float3 faceforward(float3 N, float3 I, float3 Ng);
float4 faceforward(float4 N, float4 I, float4 Ng);

half  faceforward(half  N, half  I, half  Ng);
half1 faceforward(half1 N, half1 I, half1 Ng);
half2 faceforward(half2 N, half2 I, half2 Ng);
half3 faceforward(half3 N, half3 I, half3 Ng);
half4 faceforward(half4 N, half4 I, half4 Ng);

fixed  faceforward(fixed  N, fixed  I, fixed  Ng);
fixed1 faceforward(fixed1 N, fixed1 I, fixed1 Ng);
fixed2 faceforward(fixed2 N, fixed2 I, fixed2 Ng);
fixed3 faceforward(fixed3 N, fixed3 I, fixed3 Ng);
fixed4 faceforward(fixed4 N, fixed4 I, fixed4 Ng);

Parameters

N
Peturbed normal vector.
I
Incidence vector (typically a direction vector from the eye to a vertex).
Ng
Geometric normal vector (for some facet the peturbed normal belongs).

Description

Returns a (peturbed) normal as-is if a vertex's eye-space position vector points in the opposite direction of a geometric normal, otherwise return the negated version of the (peturbed) normal

Mathematically, if the dot product of I and Ng is negative, N is returned unchanged; otherwise -N is returned.

This function is inspired by a RenderMan funciton of the same name though the RenderMan version has only two parameters.

Reference Implementation

faceforward for float3 vectors could be implemented this way:

float3 faceforward( float3 N, float3 I, float Ng )
{
  return dot(I, Ng) < 0 ? N : -N;
}

Profile Support

refract is supported in all profiles.

See Also

dot, reflect, refract, normalize