cameraPosition
Provides the camera's precise position in World Space to the shader, acting as the core data source for all view-dependent effects like lighting, fog, and reflections.
Core Advantages
Automatically and accurately provides the camera's world position, eliminating the need for manual uniform management and updates. It ensures performance through efficient in-place updates and leads to cleaner, decoupled material code.
Common Uses
Calculating the view direction for specular highlights
Calculating distance-based effects like fog and depth of field
Implementing Fresnel effects and rim lighting
Calculating reflection/refraction vectors for environment mapping
Creating billboarding effects (making objects always face the camera)
How to adjust
This node's value is not adjusted directly within the shader. You 'adjust' it by moving the THREE.Camera object in your JavaScript scene. Any change in the camera's position will automatically update this node's value, instantly affecting all dependent visual effects, e.g., rim lighting will dynamically hug the object's silhouette from the new viewpoint.
Code Examples
1
2// Calculate the view direction from the surface to the camera
3const viewDirection = TSL.normalize(TSL.cameraPosition.sub(positionWorld));
4