@@ -7,8 +7,12 @@ import { uniform } from '../core/UniformNode.js';
77import { normalMap } from '../display/NormalMapNode.js' ;
88import { bumpMap } from '../display/BumpMapNode.js' ;
99import { Vector2 } from '../../math/Vector2.js' ;
10+ import { Euler } from '../../math/Euler.js' ;
11+ import { Matrix4 } from '../../math/Matrix4.js' ;
1012
1113const _propertyCache = new Map ( ) ;
14+ const _e1 = /*@__PURE__ */ new Euler ( ) ;
15+ const _m1 = /*@__PURE__ */ new Matrix4 ( ) ;
1216
1317/**
1418 * This class should simplify the node access to material properties.
@@ -386,6 +390,12 @@ class MaterialNode extends Node {
386390
387391 node = this . getTexture ( scope ) . r . sub ( 1.0 ) . mul ( this . getFloat ( 'aoMapIntensity' ) ) . add ( 1.0 ) ;
388392
393+ } else if ( scope === MaterialNode . ENV_INTENSITY ) {
394+
395+ const scene = builder . scene ;
396+
397+ node = material . envMap ? this . getFloat ( 'envMapIntensity' ) : reference ( 'environmentIntensity' , 'float' , scene ) ;
398+
389399 } else {
390400
391401 const outputType = this . getNodeType ( builder ) ;
@@ -437,6 +447,7 @@ MaterialNode.POINT_SIZE = 'size';
437447MaterialNode . DISPERSION = 'dispersion' ;
438448MaterialNode . LIGHT_MAP = 'light' ;
439449MaterialNode . AO = 'ao' ;
450+ MaterialNode . ENV_INTENSITY = 'envIntensity' ;
440451
441452export default MaterialNode ;
442453
@@ -769,3 +780,44 @@ export const materialAnisotropyVector = /*@__PURE__*/ uniform( new Vector2() ).o
769780 this . value . set ( material . anisotropy * Math . cos ( material . anisotropyRotation ) , material . anisotropy * Math . sin ( material . anisotropyRotation ) ) ;
770781
771782} ) ;
783+
784+ /**
785+ * TSL object that represents the intensity of environment maps of PBR materials.
786+ * When `material.envMap` is set, the value is `material.envMapIntensity` otherwise `scene.environmentIntensity`.
787+ *
788+ * @tsl
789+ * @type {Node<float> }
790+ */
791+ export const materialEnvIntensity = /*@__PURE__ */ nodeImmutable ( MaterialNode , MaterialNode . ENV_INTENSITY ) ;
792+
793+ /**
794+ * TSL object that represents the rotation of environment maps.
795+ * When `material.envMap` is set, the value is `material.envMapRotation`. `scene.environmentRotation` controls the
796+ * rotation of `scene.environment` instead.
797+ *
798+ * @tsl
799+ * @type {Node<mat4> }
800+ */
801+ export const materialEnvRotation = /*@__PURE__ */ uniform ( new Matrix4 ( ) ) . onReference ( function ( frame ) {
802+
803+ return frame . material ;
804+
805+ } ) . onRenderUpdate ( function ( { material, scene } ) {
806+
807+ const rotation = ( scene . environment !== null && material . envMap === null ) ? scene . environmentRotation : material . envMapRotation ;
808+
809+ if ( rotation ) {
810+
811+ _e1 . copy ( rotation ) ;
812+
813+ _m1 . makeRotationFromEuler ( _e1 ) ;
814+
815+ } else {
816+
817+ _m1 . identity ( ) ;
818+
819+ }
820+
821+ return _m1 ;
822+
823+ } ) ;
0 commit comments