11import ShadowBaseNode , { shadowPositionWorld } from './ShadowBaseNode.js' ;
2- import { float , vec2 , vec3 , int , Fn } from '../tsl/TSLBase.js' ;
2+ import { float , vec2 , vec3 , vec4 , int , Fn } from '../tsl/TSLBase.js' ;
33import { reference } from '../accessors/ReferenceNode.js' ;
44import { texture , textureLoad } from '../accessors/TextureNode.js' ;
55import { cubeTexture } from '../accessors/CubeTextureNode.js' ;
@@ -21,6 +21,8 @@ import { getShadowMaterial, disposeShadowMaterial, BasicShadowFilter, PCFShadowF
2121import ChainMap from '../../renderers/common/ChainMap.js' ;
2222import { textureSize } from '../accessors/TextureSizeNode.js' ;
2323import { uv } from '../accessors/UV.js' ;
24+ import { positionLocal } from '../accessors/Position.js' ;
25+ import { uniform } from '../core/UniformNode.js' ;
2426
2527//
2628
@@ -506,7 +508,27 @@ class ShadowNode extends ShadowBaseNode {
506508 const shadowIntensity = reference ( 'intensity' , 'float' , shadow ) . setGroup ( renderGroup ) ;
507509 const normalBias = reference ( 'normalBias' , 'float' , shadow ) . setGroup ( renderGroup ) ;
508510
509- const shadowPosition = lightShadowMatrix ( light ) . mul ( shadowPositionWorld . add ( normalWorld . mul ( normalBias ) ) ) ;
511+ const shadowMatrix = lightShadowMatrix ( light ) ;
512+ const shadowNormalBias = normalWorld . mul ( normalBias ) ;
513+
514+ let shadowPosition ;
515+
516+ if ( ! renderer . highPrecision || builder . material . receivedShadowPositionNode || builder . context . shadowPositionWorld ) {
517+
518+ shadowPosition = shadowMatrix . mul ( shadowPositionWorld . add ( shadowNormalBias ) ) ;
519+
520+ } else {
521+
522+ const highpShadowModelMatrix = uniform ( 'mat4' ) . onObjectUpdate ( ( { object } , self ) => {
523+
524+ return self . value . multiplyMatrices ( shadowMatrix . value , object . matrixWorld ) ;
525+
526+ } ) ;
527+
528+ shadowPosition = highpShadowModelMatrix . mul ( positionLocal ) . add ( shadowMatrix . mul ( vec4 ( shadowNormalBias , 0 ) ) ) ;
529+
530+ }
531+
510532 const shadowCoord = this . setupShadowCoord ( builder , shadowPosition ) ;
511533
512534 //
0 commit comments