materialEnvRotation
Exposes a 4×4 rotation matrix (mat4) to rotate environment‑map sampling directions. If a material has envMap, it uses material.envMapRotation; otherwise (no envMap and a scene environment is present) it falls back to scene.environmentRotation. If neither is set, it returns the identity matrix.
Core Advantages
Automatically picks the proper rotation source and outputs a matrix, hiding the Euler→matrix conversion and identity fallback. No JS branching or uniform syncing is needed, keeping reflections/refractions/IBL aligned with the rotated environment.
Common Uses
Rotate mirror/rough reflections to match the rotated environment map.
Per‑object behavior: materials with their own envMap use their own rotation; others use the scene rotation.
Keep PBR highlight directions in sync when rotating the background/sky.
Product shots: animate envMapRotation to ‘turn the lights’ without rotating the mesh.
How to adjust
Do not edit this node directly. Adjust via JS: 1) With a material‑specific env map: set material.envMapRotation (THREE.Euler), e.g. material.envMapRotation.set(0, Math.PI/4, 0). 2) If the material has no envMap and uses scene.environment: set scene.environmentRotation. If neither is set, the node returns the identity matrix (no rotation).
Code Examples
1
2// 1) Build a world‑space reflection vector
3const viewDirWorld = cameraPosition.sub( positionWorld ).normalize();
4const reflectedDirWorld = reflect( viewDirWorld.negate(), transformedNormalWorld );
5
6// 2) Rotate it by the material/scene environment rotation
7const rotatedDir = reflectedDirWorld.transformDirection( materialEnvRotation );
8
9// 3) Sample the environment and blend
10const env = uniformCubeTexture( myCubeTexture ).sample( rotatedDir );
11material.colorNode = mix( materialColor, env, 0.5 );
12