positionViewDirection
Provides a normalized direction vector from the surface to the camera (the View Vector), a common input for lighting and material calculations.
Core Advantages
Its core advantage is replacing a verbose calculation (`normalize(-positionView)`) with a semantically clear node (`positionViewDirection`), greatly simplifying the implementation of lighting models and Fresnel effects while improving code readability.
Common Uses
Implementing the Fresnel effect (rim lighting) by taking its dot product with the normal to detect object silhouettes.
Serving as the view vector `V` in lighting models for calculating specular highlights.
Calculating the reflection vector for environment maps to achieve environmental reflection effects.
How to adjust
This is a read-only direction vector. Adjustments come from how it's used: for example, tuning the exponent in a `pow()` operation can change the sharpness of the resulting rim light, or using the dot product to control opacity can create an 'X-ray' like effect.
Code Examples
1// Calculate the Fresnel/rim light factor
2const rimFactor = positionViewDirection.dot( normalView ).oneMinus().pow( 3.0 );
3
4// Mix between a base color and a rim color based on the factor
5output.color.rgb = mix( baseColor, rimColor, rimFactor );