modelViewPosition
A vec3 vector that provides the coordinates of the current object's pivot point in view space (camera space). It is crucial for creating holistic effects originating from the object's center.
Core Advantages
It provides a stable, object-level anchor point, greatly simplifying the implementation of object-centric radial effects like energy shields. It abstracts away the underlying matrix transformations and is efficiently managed by the renderer, avoiding the tedious work of passing manual uniforms and improving code readability.
Common Uses
Object-centric radial effects: Acts as the effect's origin to calculate the distance from a fragment to the object's center, driving energy shields or shockwaves.
Depth-based object-level fade/highlight: Uses its Z component as a measure of the entire object's depth to control fade-in/fade-out.
Simulating an attached light source: Serves as the virtual light's position in view space to create lighting that emanates from the object's core.
How to adjust
This node is read-only; its value is determined by the object and camera positions. The key to adjustment lies in how its output vec3 is used. For example, its Z component can be used for depth-based color changes: `modelViewPosition.z.remap(-5, -50, 0, 1)` can serve as a mix factor to smoothly transition between a near color and a far color, making the entire object change color based on its distance from the camera.
Code Examples
1
2// Calculate the distance from the surface point to the object's center to create a radial effect
3const distanceToCenter = positionView.distance( modelViewPosition );
4
5// Create an outward-propagating wave combined with time
6const wave = sin( distanceToCenter.mul( 20 ).sub( timerLocal().mul( 5 ) ) );
7const rings = step( 0.5, wave );
8