objectScale
A vec3 vector representing the object's final scale in world space. It accurately reflects how much the object is stretched or compressed along the X, Y, and Z axes, combining its own scale and that of its parents.
Core Advantages
It prevents texture and lighting distortions on non-uniformly scaled objects and is fundamental for creating deformation effects like 'squash and stretch'. It simplifies development by automatically decomposing the scale from the world matrix, avoiding manual uniforms and complex calculations.
Common Uses
Correcting Tri-planar Mapping: To counteract object scaling and ensure procedural textures maintain their correct proportions.
Squash and Stretch Effects: Acts as a direct input for the degree of deformation, driving color changes or vertex displacement.
Normal Correction in Custom Lighting: Provides the critical scale data needed for accurate lighting calculations.
How to adjust
This node is read-only within the shader. Its effect is adjusted by modifying the object's `.scale` property in JavaScript (e.g., `mesh.scale.set(2, 0.5, 1)`). The shader will react to these changes in real-time; for instance, in tri-planar mapping, this would alter the correction factor used to counteract stretching.
Code Examples
1
2// Use objectScale to correct coordinates for tri-planar mapping
3// This prevents texture stretching on non-uniformly scaled objects
4const correctedCoords = positionWorld.div( objectScale() );
5const triplanarTexture = texture( myTexture, correctedCoords );
6