objectViewPosition
objectViewPosition
Provides the 3D position of the object's origin in view space (camera space). Its Z-component directly corresponds to the object's depth.
Core Advantages
Drastically simplifies depth and camera-related calculations (e.g., fog, DoF) by eliminating manual matrix math and directly providing the object's position within the camera's view.
Common Uses
Creating custom fog effects based on depth (Z-component) or height (Y-component).
Implementing depth-based object culling or Level of Detail (LOD) switching.
Creating vignette or highlight effects based on the object's screen position (XY-components).
How to adjust
Change the output by moving the camera or its target `Object3D` in JavaScript. Its `.object3d` property can also be set to track a specific object's position relative to the camera.
Code Examples
1// Calculate the distance of the object's center from the screen's center
2const distFromCenter = objectViewPosition().xy.length();
3
4// Create a falloff factor to make objects at the edge darker
5const vignetteFactor = smoothstep( 5.0, 1.0, distFromCenter );
6material.colorNode = baseColor.mul( vignetteFactor );