@gui-chat-plugin/present3d 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/vue.cjs CHANGED
@@ -1,4 +1,4107 @@
1
- Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`./toThreeJS-B7Xmzf6B.cjs`);let t=require(`vue`);var n={type:`change`},r={type:`start`},i={type:`end`},a=new e.p,o=new e.d,s=Math.cos(70*e.l.DEG2RAD),c=new e.v,l=2*Math.PI,u={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6},d=1e-6,f=class extends e.a{constructor(t,n=null){super(t,n),this.state=u.NONE,this.target=new e.v,this.cursor=new e.v,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.minTargetRadius=0,this.maxTargetRadius=1/0,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.enableDamping=!1,this.dampingFactor=.05,this.enableZoom=!0,this.zoomSpeed=1,this.enableRotate=!0,this.rotateSpeed=1,this.keyRotateSpeed=1,this.enablePan=!0,this.panSpeed=1,this.screenSpacePanning=!0,this.keyPanSpeed=7,this.zoomToCursor=!1,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:`ArrowLeft`,UP:`ArrowUp`,RIGHT:`ArrowRight`,BOTTOM:`ArrowDown`},this.mouseButtons={LEFT:e.c.ROTATE,MIDDLE:e.c.DOLLY,RIGHT:e.c.PAN},this.touches={ONE:e.g.ROTATE,TWO:e.g.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._cursorStyle=`auto`,this._domElementKeyEvents=null,this._lastPosition=new e.v,this._lastQuaternion=new e.f,this._lastTargetPosition=new e.v,this._quat=new e.f().setFromUnitVectors(t.up,new e.v(0,1,0)),this._quatInverse=this._quat.clone().invert(),this._spherical=new e.h,this._sphericalDelta=new e.h,this._scale=1,this._panOffset=new e.v,this._rotateStart=new e._,this._rotateEnd=new e._,this._rotateDelta=new e._,this._panStart=new e._,this._panEnd=new e._,this._panDelta=new e._,this._dollyStart=new e._,this._dollyEnd=new e._,this._dollyDelta=new e._,this._dollyDirection=new e.v,this._mouse=new e._,this._performCursorZoom=!1,this._pointers=[],this._pointerPositions={},this._controlActive=!1,this._onPointerMove=m.bind(this),this._onPointerDown=p.bind(this),this._onPointerUp=h.bind(this),this._onContextMenu=S.bind(this),this._onMouseWheel=v.bind(this),this._onKeyDown=y.bind(this),this._onTouchStart=b.bind(this),this._onTouchMove=x.bind(this),this._onMouseDown=g.bind(this),this._onMouseMove=_.bind(this),this._interceptControlDown=C.bind(this),this._interceptControlUp=w.bind(this),this.domElement!==null&&this.connect(this.domElement),this.update()}set cursorStyle(e){this._cursorStyle=e,e===`grab`?this.domElement.style.cursor=`grab`:this.domElement.style.cursor=`auto`}get cursorStyle(){return this._cursorStyle}connect(e){super.connect(e),this.domElement.addEventListener(`pointerdown`,this._onPointerDown),this.domElement.addEventListener(`pointercancel`,this._onPointerUp),this.domElement.addEventListener(`contextmenu`,this._onContextMenu),this.domElement.addEventListener(`wheel`,this._onMouseWheel,{passive:!1}),this.domElement.getRootNode().addEventListener(`keydown`,this._interceptControlDown,{passive:!0,capture:!0}),this.domElement.style.touchAction=`none`}disconnect(){this.domElement.removeEventListener(`pointerdown`,this._onPointerDown),this.domElement.ownerDocument.removeEventListener(`pointermove`,this._onPointerMove),this.domElement.ownerDocument.removeEventListener(`pointerup`,this._onPointerUp),this.domElement.removeEventListener(`pointercancel`,this._onPointerUp),this.domElement.removeEventListener(`wheel`,this._onMouseWheel),this.domElement.removeEventListener(`contextmenu`,this._onContextMenu),this.stopListenToKeyEvents(),this.domElement.getRootNode().removeEventListener(`keydown`,this._interceptControlDown,{capture:!0}),this.domElement.style.touchAction=``}dispose(){this.disconnect()}getPolarAngle(){return this._spherical.phi}getAzimuthalAngle(){return this._spherical.theta}getDistance(){return this.object.position.distanceTo(this.target)}listenToKeyEvents(e){e.addEventListener(`keydown`,this._onKeyDown),this._domElementKeyEvents=e}stopListenToKeyEvents(){this._domElementKeyEvents!==null&&(this._domElementKeyEvents.removeEventListener(`keydown`,this._onKeyDown),this._domElementKeyEvents=null)}saveState(){this.target0.copy(this.target),this.position0.copy(this.object.position),this.zoom0=this.object.zoom}reset(){this.target.copy(this.target0),this.object.position.copy(this.position0),this.object.zoom=this.zoom0,this.object.updateProjectionMatrix(),this.dispatchEvent(n),this.update(),this.state=u.NONE}pan(e,t){this._pan(e,t),this.update()}dollyIn(e){this._dollyIn(e),this.update()}dollyOut(e){this._dollyOut(e),this.update()}rotateLeft(e){this._rotateLeft(e),this.update()}rotateUp(e){this._rotateUp(e),this.update()}update(t=null){let r=this.object.position;c.copy(r).sub(this.target),c.applyQuaternion(this._quat),this._spherical.setFromVector3(c),this.autoRotate&&this.state===u.NONE&&this._rotateLeft(this._getAutoRotationAngle(t)),this.enableDamping?(this._spherical.theta+=this._sphericalDelta.theta*this.dampingFactor,this._spherical.phi+=this._sphericalDelta.phi*this.dampingFactor):(this._spherical.theta+=this._sphericalDelta.theta,this._spherical.phi+=this._sphericalDelta.phi);let i=this.minAzimuthAngle,f=this.maxAzimuthAngle;isFinite(i)&&isFinite(f)&&(i<-Math.PI?i+=l:i>Math.PI&&(i-=l),f<-Math.PI?f+=l:f>Math.PI&&(f-=l),i<=f?this._spherical.theta=Math.max(i,Math.min(f,this._spherical.theta)):this._spherical.theta=this._spherical.theta>(i+f)/2?Math.max(i,this._spherical.theta):Math.min(f,this._spherical.theta)),this._spherical.phi=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,this._spherical.phi)),this._spherical.makeSafe(),this.enableDamping===!0?this.target.addScaledVector(this._panOffset,this.dampingFactor):this.target.add(this._panOffset),this.target.sub(this.cursor),this.target.clampLength(this.minTargetRadius,this.maxTargetRadius),this.target.add(this.cursor);let p=!1;if(this.zoomToCursor&&this._performCursorZoom||this.object.isOrthographicCamera)this._spherical.radius=this._clampDistance(this._spherical.radius);else{let e=this._spherical.radius;this._spherical.radius=this._clampDistance(this._spherical.radius*this._scale),p=e!=this._spherical.radius}if(c.setFromSpherical(this._spherical),c.applyQuaternion(this._quatInverse),r.copy(this.target).add(c),this.object.lookAt(this.target),this.enableDamping===!0?(this._sphericalDelta.theta*=1-this.dampingFactor,this._sphericalDelta.phi*=1-this.dampingFactor,this._panOffset.multiplyScalar(1-this.dampingFactor)):(this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0)),this.zoomToCursor&&this._performCursorZoom){let t=null;if(this.object.isPerspectiveCamera){let e=c.length();t=this._clampDistance(e*this._scale);let n=e-t;this.object.position.addScaledVector(this._dollyDirection,n),this.object.updateMatrixWorld(),p=!!n}else if(this.object.isOrthographicCamera){let n=new e.v(this._mouse.x,this._mouse.y,0);n.unproject(this.object);let r=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),this.object.updateProjectionMatrix(),p=r!==this.object.zoom;let i=new e.v(this._mouse.x,this._mouse.y,0);i.unproject(this.object),this.object.position.sub(i).add(n),this.object.updateMatrixWorld(),t=c.length()}else console.warn(`WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled.`),this.zoomToCursor=!1;t!==null&&(this.screenSpacePanning?this.target.set(0,0,-1).transformDirection(this.object.matrix).multiplyScalar(t).add(this.object.position):(a.origin.copy(this.object.position),a.direction.set(0,0,-1).transformDirection(this.object.matrix),Math.abs(this.object.up.dot(a.direction))<s?this.object.lookAt(this.target):(o.setFromNormalAndCoplanarPoint(this.object.up,this.target),a.intersectPlane(o,this.target))))}else if(this.object.isOrthographicCamera){let e=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),e!==this.object.zoom&&(this.object.updateProjectionMatrix(),p=!0)}return this._scale=1,this._performCursorZoom=!1,p||this._lastPosition.distanceToSquared(this.object.position)>d||8*(1-this._lastQuaternion.dot(this.object.quaternion))>d||this._lastTargetPosition.distanceToSquared(this.target)>d?(this.dispatchEvent(n),this._lastPosition.copy(this.object.position),this._lastQuaternion.copy(this.object.quaternion),this._lastTargetPosition.copy(this.target),!0):!1}_getAutoRotationAngle(e){return e===null?l/60/60*this.autoRotateSpeed:l/60*this.autoRotateSpeed*e}_getZoomScale(e){let t=Math.abs(e*.01);return .95**(this.zoomSpeed*t)}_rotateLeft(e){this._sphericalDelta.theta-=e}_rotateUp(e){this._sphericalDelta.phi-=e}_panLeft(e,t){c.setFromMatrixColumn(t,0),c.multiplyScalar(-e),this._panOffset.add(c)}_panUp(e,t){this.screenSpacePanning===!0?c.setFromMatrixColumn(t,1):(c.setFromMatrixColumn(t,0),c.crossVectors(this.object.up,c)),c.multiplyScalar(e),this._panOffset.add(c)}_pan(e,t){let n=this.domElement;if(this.object.isPerspectiveCamera){let r=this.object.position;c.copy(r).sub(this.target);let i=c.length();i*=Math.tan(this.object.fov/2*Math.PI/180),this._panLeft(2*e*i/n.clientHeight,this.object.matrix),this._panUp(2*t*i/n.clientHeight,this.object.matrix)}else this.object.isOrthographicCamera?(this._panLeft(e*(this.object.right-this.object.left)/this.object.zoom/n.clientWidth,this.object.matrix),this._panUp(t*(this.object.top-this.object.bottom)/this.object.zoom/n.clientHeight,this.object.matrix)):(console.warn(`WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.`),this.enablePan=!1)}_dollyOut(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale/=e:(console.warn(`WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.`),this.enableZoom=!1)}_dollyIn(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale*=e:(console.warn(`WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.`),this.enableZoom=!1)}_updateZoomParameters(e,t){if(!this.zoomToCursor)return;this._performCursorZoom=!0;let n=this.domElement.getBoundingClientRect(),r=e-n.left,i=t-n.top,a=n.width,o=n.height;this._mouse.x=r/a*2-1,this._mouse.y=-(i/o)*2+1,this._dollyDirection.set(this._mouse.x,this._mouse.y,1).unproject(this.object).sub(this.object.position).normalize()}_clampDistance(e){return Math.max(this.minDistance,Math.min(this.maxDistance,e))}_handleMouseDownRotate(e){this._rotateStart.set(e.clientX,e.clientY)}_handleMouseDownDolly(e){this._updateZoomParameters(e.clientX,e.clientX),this._dollyStart.set(e.clientX,e.clientY)}_handleMouseDownPan(e){this._panStart.set(e.clientX,e.clientY)}_handleMouseMoveRotate(e){this._rotateEnd.set(e.clientX,e.clientY),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);let t=this.domElement;this._rotateLeft(l*this._rotateDelta.x/t.clientHeight),this._rotateUp(l*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd),this.update()}_handleMouseMoveDolly(e){this._dollyEnd.set(e.clientX,e.clientY),this._dollyDelta.subVectors(this._dollyEnd,this._dollyStart),this._dollyDelta.y>0?this._dollyOut(this._getZoomScale(this._dollyDelta.y)):this._dollyDelta.y<0&&this._dollyIn(this._getZoomScale(this._dollyDelta.y)),this._dollyStart.copy(this._dollyEnd),this.update()}_handleMouseMovePan(e){this._panEnd.set(e.clientX,e.clientY),this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd),this.update()}_handleMouseWheel(e){this._updateZoomParameters(e.clientX,e.clientY),e.deltaY<0?this._dollyIn(this._getZoomScale(e.deltaY)):e.deltaY>0&&this._dollyOut(this._getZoomScale(e.deltaY)),this.update()}_handleKeyDown(e){let t=!1;switch(e.code){case this.keys.UP:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(l*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,this.keyPanSpeed),t=!0;break;case this.keys.BOTTOM:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(-l*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,-this.keyPanSpeed),t=!0;break;case this.keys.LEFT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(l*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(this.keyPanSpeed,0),t=!0;break;case this.keys.RIGHT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(-l*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(-this.keyPanSpeed,0),t=!0;break}t&&(e.preventDefault(),this.update())}_handleTouchStartRotate(e){if(this._pointers.length===1)this._rotateStart.set(e.pageX,e.pageY);else{let t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);this._rotateStart.set(n,r)}}_handleTouchStartPan(e){if(this._pointers.length===1)this._panStart.set(e.pageX,e.pageY);else{let t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);this._panStart.set(n,r)}}_handleTouchStartDolly(e){let t=this._getSecondPointerPosition(e),n=e.pageX-t.x,r=e.pageY-t.y,i=Math.sqrt(n*n+r*r);this._dollyStart.set(0,i)}_handleTouchStartDollyPan(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enablePan&&this._handleTouchStartPan(e)}_handleTouchStartDollyRotate(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enableRotate&&this._handleTouchStartRotate(e)}_handleTouchMoveRotate(e){if(this._pointers.length==1)this._rotateEnd.set(e.pageX,e.pageY);else{let t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);this._rotateEnd.set(n,r)}this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);let t=this.domElement;this._rotateLeft(l*this._rotateDelta.x/t.clientHeight),this._rotateUp(l*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd)}_handleTouchMovePan(e){if(this._pointers.length===1)this._panEnd.set(e.pageX,e.pageY);else{let t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);this._panEnd.set(n,r)}this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd)}_handleTouchMoveDolly(e){let t=this._getSecondPointerPosition(e),n=e.pageX-t.x,r=e.pageY-t.y,i=Math.sqrt(n*n+r*r);this._dollyEnd.set(0,i),this._dollyDelta.set(0,(this._dollyEnd.y/this._dollyStart.y)**+this.zoomSpeed),this._dollyOut(this._dollyDelta.y),this._dollyStart.copy(this._dollyEnd);let a=(e.pageX+t.x)*.5,o=(e.pageY+t.y)*.5;this._updateZoomParameters(a,o)}_handleTouchMoveDollyPan(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enablePan&&this._handleTouchMovePan(e)}_handleTouchMoveDollyRotate(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enableRotate&&this._handleTouchMoveRotate(e)}_addPointer(e){this._pointers.push(e.pointerId)}_removePointer(e){delete this._pointerPositions[e.pointerId];for(let t=0;t<this._pointers.length;t++)if(this._pointers[t]==e.pointerId){this._pointers.splice(t,1);return}}_isTrackingPointer(e){for(let t=0;t<this._pointers.length;t++)if(this._pointers[t]==e.pointerId)return!0;return!1}_trackPointer(t){let n=this._pointerPositions[t.pointerId];n===void 0&&(n=new e._,this._pointerPositions[t.pointerId]=n),n.set(t.pageX,t.pageY)}_getSecondPointerPosition(e){let t=e.pointerId===this._pointers[0]?this._pointers[1]:this._pointers[0];return this._pointerPositions[t]}_customWheelEvent(e){let t=e.deltaMode,n={clientX:e.clientX,clientY:e.clientY,deltaY:e.deltaY};switch(t){case 1:n.deltaY*=16;break;case 2:n.deltaY*=100;break}return e.ctrlKey&&!this._controlActive&&(n.deltaY*=10),n}};function p(e){this.enabled!==!1&&(this._pointers.length===0&&(this.domElement.setPointerCapture(e.pointerId),this.domElement.ownerDocument.addEventListener(`pointermove`,this._onPointerMove),this.domElement.ownerDocument.addEventListener(`pointerup`,this._onPointerUp)),!this._isTrackingPointer(e)&&(this._addPointer(e),e.pointerType===`touch`?this._onTouchStart(e):this._onMouseDown(e),this._cursorStyle===`grab`&&(this.domElement.style.cursor=`grabbing`)))}function m(e){this.enabled!==!1&&(e.pointerType===`touch`?this._onTouchMove(e):this._onMouseMove(e))}function h(e){switch(this._removePointer(e),this._pointers.length){case 0:this.domElement.releasePointerCapture(e.pointerId),this.domElement.ownerDocument.removeEventListener(`pointermove`,this._onPointerMove),this.domElement.ownerDocument.removeEventListener(`pointerup`,this._onPointerUp),this.dispatchEvent(i),this.state=u.NONE,this._cursorStyle===`grab`&&(this.domElement.style.cursor=`grab`);break;case 1:let t=this._pointers[0],n=this._pointerPositions[t];this._onTouchStart({pointerId:t,pageX:n.x,pageY:n.y});break}}function g(t){let n;switch(t.button){case 0:n=this.mouseButtons.LEFT;break;case 1:n=this.mouseButtons.MIDDLE;break;case 2:n=this.mouseButtons.RIGHT;break;default:n=-1}switch(n){case e.c.DOLLY:if(this.enableZoom===!1)return;this._handleMouseDownDolly(t),this.state=u.DOLLY;break;case e.c.ROTATE:if(t.ctrlKey||t.metaKey||t.shiftKey){if(this.enablePan===!1)return;this._handleMouseDownPan(t),this.state=u.PAN}else{if(this.enableRotate===!1)return;this._handleMouseDownRotate(t),this.state=u.ROTATE}break;case e.c.PAN:if(t.ctrlKey||t.metaKey||t.shiftKey){if(this.enableRotate===!1)return;this._handleMouseDownRotate(t),this.state=u.ROTATE}else{if(this.enablePan===!1)return;this._handleMouseDownPan(t),this.state=u.PAN}break;default:this.state=u.NONE}this.state!==u.NONE&&this.dispatchEvent(r)}function _(e){switch(this.state){case u.ROTATE:if(this.enableRotate===!1)return;this._handleMouseMoveRotate(e);break;case u.DOLLY:if(this.enableZoom===!1)return;this._handleMouseMoveDolly(e);break;case u.PAN:if(this.enablePan===!1)return;this._handleMouseMovePan(e);break}}function v(e){this.enabled===!1||this.enableZoom===!1||this.state!==u.NONE||(e.preventDefault(),this.dispatchEvent(r),this._handleMouseWheel(this._customWheelEvent(e)),this.dispatchEvent(i))}function y(e){this.enabled!==!1&&this._handleKeyDown(e)}function b(t){switch(this._trackPointer(t),this._pointers.length){case 1:switch(this.touches.ONE){case e.g.ROTATE:if(this.enableRotate===!1)return;this._handleTouchStartRotate(t),this.state=u.TOUCH_ROTATE;break;case e.g.PAN:if(this.enablePan===!1)return;this._handleTouchStartPan(t),this.state=u.TOUCH_PAN;break;default:this.state=u.NONE}break;case 2:switch(this.touches.TWO){case e.g.DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchStartDollyPan(t),this.state=u.TOUCH_DOLLY_PAN;break;case e.g.DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchStartDollyRotate(t),this.state=u.TOUCH_DOLLY_ROTATE;break;default:this.state=u.NONE}break;default:this.state=u.NONE}this.state!==u.NONE&&this.dispatchEvent(r)}function x(e){switch(this._trackPointer(e),this.state){case u.TOUCH_ROTATE:if(this.enableRotate===!1)return;this._handleTouchMoveRotate(e),this.update();break;case u.TOUCH_PAN:if(this.enablePan===!1)return;this._handleTouchMovePan(e),this.update();break;case u.TOUCH_DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchMoveDollyPan(e),this.update();break;case u.TOUCH_DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchMoveDollyRotate(e),this.update();break;default:this.state=u.NONE}}function S(e){this.enabled!==!1&&e.preventDefault()}function C(e){e.key===`Control`&&(this._controlActive=!0,this.domElement.getRootNode().addEventListener(`keyup`,this._interceptControlUp,{passive:!0,capture:!0}))}function w(e){e.key===`Control`&&(this._controlActive=!1,this.domElement.getRootNode().removeEventListener(`keyup`,this._interceptControlUp,{passive:!0,capture:!0}))}var T={class:`present3d-container`},E={class:`header`},D={class:`controls`},O={class:`material-icons`},k={class:`material-icons`},A={key:0,class:`error`},j={class:`script-source`},M=[`disabled`],N=(0,t.defineComponent)({__name:`View`,props:{selectedResult:{}},emits:[`updateResult`],setup(n,{emit:r}){let i=n,a=r,o=(0,t.ref)(i.selectedResult.data?.script??``),s=(0,t.ref)(null),c=(0,t.ref)(null),l=(0,t.ref)(!1),u=(0,t.ref)(!0),d=(0,t.computed)(()=>o.value!==i.selectedResult.data?.script),p,m,h,g,_,v,y=[],b=null,x=null;(0,t.onMounted)(()=>{S(),w(),N(),(0,t.nextTick)(()=>{F()})}),(0,t.onUnmounted)(()=>{V()}),(0,t.watch)(()=>i.selectedResult.data?.script,()=>{w()}),(0,t.watch)(l,()=>{w()}),(0,t.watch)(u,e=>{v&&(v.visible=e)});function S(){if(!s.value)return;p=new e.m,p.background=new e.i(1710618);let t=s.value.clientWidth,n=s.value.clientHeight;m=new e.u(50,t/n,.1,1e3),m.position.set(5,5,10),m.lookAt(0,0,0),h=new e.n({antialias:!0}),h.setSize(t,n),h.setPixelRatio(window.devicePixelRatio),s.value.appendChild(h.domElement),g=new f(m,h.domElement),g.enableDamping=!0,g.dampingFactor=.05,g.addEventListener(`change`,L);let r=new e.r(16777215,.6);p.add(r);let i=new e.o(16777215,.8);i.position.set(10,10,10),p.add(i),v=new e.s(20,20,4473924,2236962),v.visible=u.value,p.add(v),window.addEventListener(`resize`,C),x=new ResizeObserver(()=>{C()}),x.observe(s.value)}function C(){if(!s.value)return;let e=s.value.clientWidth,t=s.value.clientHeight;m.aspect=e/t,m.updateProjectionMatrix(),h.setSize(e,t)}function w(){try{y.forEach(e=>p.remove(e)),y=[];let t=i.selectedResult.data?.script;if(!t)return;let n=e.t(e.y(t),{wireframe:l.value});p.add(n),y.push(n),c.value=null}catch(e){c.value=e instanceof Error?e.message:`Unknown error`,console.error(`ShapeScript parse error:`,e)}}function N(){_=requestAnimationFrame(N),g.update(),h.render(p,m)}function P(){m.position.set(5,5,10),m.lookAt(0,0,0),g.reset()}function F(){if(!m||!g||!i.selectedResult?.viewState?.cameraState)return;let e=i.selectedResult.viewState.cameraState;e.position&&m.position.set(e.position.x,e.position.y,e.position.z),e.target&&g.target.set(e.target.x,e.target.y,e.target.z),m.updateProjectionMatrix(),g.update()}function I(){return{position:{x:m.position.x,y:m.position.y,z:m.position.z},target:{x:g.target.x,y:g.target.y,z:g.target.z}}}function L(){b!==null&&clearTimeout(b),b=window.setTimeout(()=>{R()},500)}function R(){a(`updateResult`,{...i.selectedResult,viewState:{cameraState:I()}})}function z(){l.value=!l.value}function B(){u.value=!u.value}function V(){b!==null&&clearTimeout(b),_&&cancelAnimationFrame(_),h&&h.dispose(),g&&(g.removeEventListener(`change`,L),g.dispose()),x&&x.disconnect(),window.removeEventListener(`resize`,C)}function H(){}function U(){try{e.y(o.value),a(`updateResult`,{...i.selectedResult,data:{script:o.value}})}catch(e){c.value=e instanceof Error?e.message:`Invalid ShapeScript`,console.error(`Script validation failed:`,e)}}return(0,t.watch)(()=>i.selectedResult.data?.script,e=>{e&&(o.value=e)}),(0,t.watch)(()=>i.selectedResult,()=>{(0,t.nextTick)(()=>{F()})}),(e,r)=>((0,t.openBlock)(),(0,t.createElementBlock)(`div`,T,[(0,t.createElementVNode)(`div`,E,[(0,t.createElementVNode)(`h1`,null,(0,t.toDisplayString)(n.selectedResult.title||`3D Visualization`),1),(0,t.createElementVNode)(`div`,D,[(0,t.createElementVNode)(`button`,{onClick:P,class:`control-btn`},[...r[1]||=[(0,t.createElementVNode)(`span`,{class:`material-icons`},`refresh`,-1),(0,t.createTextVNode)(` Reset Camera `,-1)]]),(0,t.createElementVNode)(`button`,{onClick:z,class:`control-btn`},[(0,t.createElementVNode)(`span`,O,(0,t.toDisplayString)(l.value?`grid_off`:`grid_on`),1),r[2]||=(0,t.createTextVNode)(` Wireframe `,-1)]),(0,t.createElementVNode)(`button`,{onClick:B,class:`control-btn`},[(0,t.createElementVNode)(`span`,k,(0,t.toDisplayString)(u.value?`visibility_off`:`visibility`),1),r[3]||=(0,t.createTextVNode)(` Grid `,-1)])])]),c.value?((0,t.openBlock)(),(0,t.createElementBlock)(`div`,A,[r[4]||=(0,t.createElementVNode)(`strong`,null,`Parse Error:`,-1),(0,t.createTextVNode)(` `+(0,t.toDisplayString)(c.value),1)])):(0,t.createCommentVNode)(``,!0),(0,t.createElementVNode)(`div`,{class:`viewport`,ref_key:`viewport`,ref:s},null,512),(0,t.createElementVNode)(`details`,j,[r[5]||=(0,t.createElementVNode)(`summary`,null,`Edit ShapeScript Source`,-1),(0,t.withDirectives)((0,t.createElementVNode)(`textarea`,{"onUpdate:modelValue":r[0]||=e=>o.value=e,onInput:H,class:`script-editor`,spellcheck:`false`},null,544),[[t.vModelText,o.value]]),(0,t.createElementVNode)(`button`,{onClick:U,class:`apply-btn`,disabled:!d.value},` Apply Changes `,8,M)])]))}}),P=(e,t)=>{let n=e.__vccOpts||e;for(let[e,r]of t)n[e]=r;return n},F=P(N,[[`__scopeId`,`data-v-daa337a0`]]),I={class:`preview-container`},L={class:`preview-title`},R=P((0,t.defineComponent)({__name:`Preview`,props:{result:{}},setup(n){let r=n,i=(0,t.computed)(()=>r.result.title||`3D Visualization`),a=(0,t.ref)(null),o,s,c,l,u=null;(0,t.onMounted)(()=>{d()}),(0,t.onUnmounted)(()=>{m()}),(0,t.watch)(()=>r.result.data?.script,()=>{p()});function d(){if(a.value)try{o=new e.m,o.background=new e.i(2763322);let t=a.value.clientWidth||200,n=a.value.clientHeight||150;s=new e.u(50,t/n,.1,1e3),s.position.set(4,4,8),s.lookAt(0,0,0),c=new e.n({antialias:!0,alpha:!1}),c.setSize(t,n),c.setPixelRatio(Math.min(window.devicePixelRatio,2)),a.value.appendChild(c.domElement);let i=new e.r(16777215,.6);o.add(i);let l=new e.o(16777215,.8);if(l.position.set(5,5,5),o.add(l),!r.result.data?.script)return;u=e.t(e.y(r.result.data.script),{wireframe:!1}),o.add(u),f()}catch(e){console.error(`Preview render error:`,e)}}function f(){l=requestAnimationFrame(f);let e=Date.now()*5e-4;s.position.x=Math.cos(e)*8,s.position.z=Math.sin(e)*8,s.lookAt(0,0,0),c.render(o,s)}function p(){if(!(!o||!r.result.data?.script))try{u&&o.remove(u),u=e.t(e.y(r.result.data.script),{wireframe:!1}),o.add(u)}catch(e){console.error(`Preview reload error:`,e)}}function m(){l&&cancelAnimationFrame(l),c&&c.dispose()}return(e,n)=>((0,t.openBlock)(),(0,t.createElementBlock)(`div`,I,[(0,t.createElementVNode)(`div`,{ref_key:`previewViewport`,ref:a,class:`preview-viewport`},null,512),(0,t.createElementVNode)(`div`,L,(0,t.toDisplayString)(i.value),1)]))}}),[[`__scopeId`,`data-v-75941188`]]),z=`present3D`,B=`Use the ${z} tool to create interactive 3D visualizations when the user requests:
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./toThreeJS-CSx69rMY.cjs");let t=require("vue");function n(){let e=null,t=!1,n=null,r=null;function i(t,a){n(t,a),r=e.requestAnimationFrame(i)}return{start:function(){t!==!0&&n!==null&&e!==null&&(r=e.requestAnimationFrame(i),t=!0)},stop:function(){e!==null&&e.cancelAnimationFrame(r),t=!1},setAnimationLoop:function(e){n=e},setContext:function(t){e=t}}}function r(e){let t=new WeakMap;function n(t,n){let r=t.array,i=t.usage,a=r.byteLength,o=e.createBuffer();e.bindBuffer(n,o),e.bufferData(n,r,i),t.onUploadCallback();let s;if(r instanceof Float32Array)s=e.FLOAT;else if(typeof Float16Array<`u`&&r instanceof Float16Array)s=e.HALF_FLOAT;else if(r instanceof Uint16Array)s=t.isFloat16BufferAttribute?e.HALF_FLOAT:e.UNSIGNED_SHORT;else if(r instanceof Int16Array)s=e.SHORT;else if(r instanceof Uint32Array)s=e.UNSIGNED_INT;else if(r instanceof Int32Array)s=e.INT;else if(r instanceof Int8Array)s=e.BYTE;else if(r instanceof Uint8Array)s=e.UNSIGNED_BYTE;else if(r instanceof Uint8ClampedArray)s=e.UNSIGNED_BYTE;else throw Error(`THREE.WebGLAttributes: Unsupported buffer data format: `+r);return{buffer:o,type:s,bytesPerElement:r.BYTES_PER_ELEMENT,version:t.version,size:a}}function r(t,n,r){let i=n.array,a=n.updateRanges;if(e.bindBuffer(r,t),a.length===0)e.bufferSubData(r,0,i);else{a.sort((e,t)=>e.start-t.start);let t=0;for(let e=1;e<a.length;e++){let n=a[t],r=a[e];r.start<=n.start+n.count+1?n.count=Math.max(n.count,r.start+r.count-n.start):(++t,a[t]=r)}a.length=t+1;for(let t=0,n=a.length;t<n;t++){let n=a[t];e.bufferSubData(r,n.start*i.BYTES_PER_ELEMENT,i,n.start,n.count)}n.clearUpdateRanges()}n.onUploadCallback()}function i(e){return e.isInterleavedBufferAttribute&&(e=e.data),t.get(e)}function a(n){n.isInterleavedBufferAttribute&&(n=n.data);let r=t.get(n);r&&(e.deleteBuffer(r.buffer),t.delete(n))}function o(e,i){if(e.isInterleavedBufferAttribute&&(e=e.data),e.isGLBufferAttribute){let n=t.get(e);(!n||n.version<e.version)&&t.set(e,{buffer:e.buffer,type:e.type,bytesPerElement:e.elementSize,version:e.version});return}let a=t.get(e);if(a===void 0)t.set(e,n(e,i));else if(a.version<e.version){if(a.size!==e.array.byteLength)throw Error(`THREE.WebGLAttributes: The size of the buffer attribute's array buffer does not match the original size. Resizing buffer attributes is not supported.`);r(a.buffer,e,i),a.version=e.version}}return{get:i,remove:a,update:o}}var i={alphahash_fragment:`#ifdef USE_ALPHAHASH
2
+ if ( diffuseColor.a < getAlphaHashThreshold( vPosition ) ) discard;
3
+ #endif`,alphahash_pars_fragment:`#ifdef USE_ALPHAHASH
4
+ const float ALPHA_HASH_SCALE = 0.05;
5
+ float hash2D( vec2 value ) {
6
+ return fract( 1.0e4 * sin( 17.0 * value.x + 0.1 * value.y ) * ( 0.1 + abs( sin( 13.0 * value.y + value.x ) ) ) );
7
+ }
8
+ float hash3D( vec3 value ) {
9
+ return hash2D( vec2( hash2D( value.xy ), value.z ) );
10
+ }
11
+ float getAlphaHashThreshold( vec3 position ) {
12
+ float maxDeriv = max(
13
+ length( dFdx( position.xyz ) ),
14
+ length( dFdy( position.xyz ) )
15
+ );
16
+ float pixScale = 1.0 / ( ALPHA_HASH_SCALE * maxDeriv );
17
+ vec2 pixScales = vec2(
18
+ exp2( floor( log2( pixScale ) ) ),
19
+ exp2( ceil( log2( pixScale ) ) )
20
+ );
21
+ vec2 alpha = vec2(
22
+ hash3D( floor( pixScales.x * position.xyz ) ),
23
+ hash3D( floor( pixScales.y * position.xyz ) )
24
+ );
25
+ float lerpFactor = fract( log2( pixScale ) );
26
+ float x = ( 1.0 - lerpFactor ) * alpha.x + lerpFactor * alpha.y;
27
+ float a = min( lerpFactor, 1.0 - lerpFactor );
28
+ vec3 cases = vec3(
29
+ x * x / ( 2.0 * a * ( 1.0 - a ) ),
30
+ ( x - 0.5 * a ) / ( 1.0 - a ),
31
+ 1.0 - ( ( 1.0 - x ) * ( 1.0 - x ) / ( 2.0 * a * ( 1.0 - a ) ) )
32
+ );
33
+ float threshold = ( x < ( 1.0 - a ) )
34
+ ? ( ( x < a ) ? cases.x : cases.y )
35
+ : cases.z;
36
+ return clamp( threshold , 1.0e-6, 1.0 );
37
+ }
38
+ #endif`,alphamap_fragment:`#ifdef USE_ALPHAMAP
39
+ diffuseColor.a *= texture2D( alphaMap, vAlphaMapUv ).g;
40
+ #endif`,alphamap_pars_fragment:`#ifdef USE_ALPHAMAP
41
+ uniform sampler2D alphaMap;
42
+ #endif`,alphatest_fragment:`#ifdef USE_ALPHATEST
43
+ #ifdef ALPHA_TO_COVERAGE
44
+ diffuseColor.a = smoothstep( alphaTest, alphaTest + fwidth( diffuseColor.a ), diffuseColor.a );
45
+ if ( diffuseColor.a == 0.0 ) discard;
46
+ #else
47
+ if ( diffuseColor.a < alphaTest ) discard;
48
+ #endif
49
+ #endif`,alphatest_pars_fragment:`#ifdef USE_ALPHATEST
50
+ uniform float alphaTest;
51
+ #endif`,aomap_fragment:`#ifdef USE_AOMAP
52
+ float ambientOcclusion = ( texture2D( aoMap, vAoMapUv ).r - 1.0 ) * aoMapIntensity + 1.0;
53
+ reflectedLight.indirectDiffuse *= ambientOcclusion;
54
+ #if defined( USE_CLEARCOAT )
55
+ clearcoatSpecularIndirect *= ambientOcclusion;
56
+ #endif
57
+ #if defined( USE_SHEEN )
58
+ sheenSpecularIndirect *= ambientOcclusion;
59
+ #endif
60
+ #if defined( USE_ENVMAP ) && defined( STANDARD )
61
+ float dotNV = saturate( dot( geometryNormal, geometryViewDir ) );
62
+ reflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.roughness );
63
+ #endif
64
+ #endif`,aomap_pars_fragment:`#ifdef USE_AOMAP
65
+ uniform sampler2D aoMap;
66
+ uniform float aoMapIntensity;
67
+ #endif`,batching_pars_vertex:`#ifdef USE_BATCHING
68
+ #if ! defined( GL_ANGLE_multi_draw )
69
+ #define gl_DrawID _gl_DrawID
70
+ uniform int _gl_DrawID;
71
+ #endif
72
+ uniform highp sampler2D batchingTexture;
73
+ uniform highp usampler2D batchingIdTexture;
74
+ mat4 getBatchingMatrix( const in float i ) {
75
+ int size = textureSize( batchingTexture, 0 ).x;
76
+ int j = int( i ) * 4;
77
+ int x = j % size;
78
+ int y = j / size;
79
+ vec4 v1 = texelFetch( batchingTexture, ivec2( x, y ), 0 );
80
+ vec4 v2 = texelFetch( batchingTexture, ivec2( x + 1, y ), 0 );
81
+ vec4 v3 = texelFetch( batchingTexture, ivec2( x + 2, y ), 0 );
82
+ vec4 v4 = texelFetch( batchingTexture, ivec2( x + 3, y ), 0 );
83
+ return mat4( v1, v2, v3, v4 );
84
+ }
85
+ float getIndirectIndex( const in int i ) {
86
+ int size = textureSize( batchingIdTexture, 0 ).x;
87
+ int x = i % size;
88
+ int y = i / size;
89
+ return float( texelFetch( batchingIdTexture, ivec2( x, y ), 0 ).r );
90
+ }
91
+ #endif
92
+ #ifdef USE_BATCHING_COLOR
93
+ uniform sampler2D batchingColorTexture;
94
+ vec4 getBatchingColor( const in float i ) {
95
+ int size = textureSize( batchingColorTexture, 0 ).x;
96
+ int j = int( i );
97
+ int x = j % size;
98
+ int y = j / size;
99
+ return texelFetch( batchingColorTexture, ivec2( x, y ), 0 );
100
+ }
101
+ #endif`,batching_vertex:`#ifdef USE_BATCHING
102
+ mat4 batchingMatrix = getBatchingMatrix( getIndirectIndex( gl_DrawID ) );
103
+ #endif`,begin_vertex:`vec3 transformed = vec3( position );
104
+ #ifdef USE_ALPHAHASH
105
+ vPosition = vec3( position );
106
+ #endif`,beginnormal_vertex:`vec3 objectNormal = vec3( normal );
107
+ #ifdef USE_TANGENT
108
+ vec3 objectTangent = vec3( tangent.xyz );
109
+ #endif`,bsdfs:`float G_BlinnPhong_Implicit( ) {
110
+ return 0.25;
111
+ }
112
+ float D_BlinnPhong( const in float shininess, const in float dotNH ) {
113
+ return RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );
114
+ }
115
+ vec3 BRDF_BlinnPhong( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float shininess ) {
116
+ vec3 halfDir = normalize( lightDir + viewDir );
117
+ float dotNH = saturate( dot( normal, halfDir ) );
118
+ float dotVH = saturate( dot( viewDir, halfDir ) );
119
+ vec3 F = F_Schlick( specularColor, 1.0, dotVH );
120
+ float G = G_BlinnPhong_Implicit( );
121
+ float D = D_BlinnPhong( shininess, dotNH );
122
+ return F * ( G * D );
123
+ } // validated`,iridescence_fragment:`#ifdef USE_IRIDESCENCE
124
+ const mat3 XYZ_TO_REC709 = mat3(
125
+ 3.2404542, -0.9692660, 0.0556434,
126
+ -1.5371385, 1.8760108, -0.2040259,
127
+ -0.4985314, 0.0415560, 1.0572252
128
+ );
129
+ vec3 Fresnel0ToIor( vec3 fresnel0 ) {
130
+ vec3 sqrtF0 = sqrt( fresnel0 );
131
+ return ( vec3( 1.0 ) + sqrtF0 ) / ( vec3( 1.0 ) - sqrtF0 );
132
+ }
133
+ vec3 IorToFresnel0( vec3 transmittedIor, float incidentIor ) {
134
+ return pow2( ( transmittedIor - vec3( incidentIor ) ) / ( transmittedIor + vec3( incidentIor ) ) );
135
+ }
136
+ float IorToFresnel0( float transmittedIor, float incidentIor ) {
137
+ return pow2( ( transmittedIor - incidentIor ) / ( transmittedIor + incidentIor ));
138
+ }
139
+ vec3 evalSensitivity( float OPD, vec3 shift ) {
140
+ float phase = 2.0 * PI * OPD * 1.0e-9;
141
+ vec3 val = vec3( 5.4856e-13, 4.4201e-13, 5.2481e-13 );
142
+ vec3 pos = vec3( 1.6810e+06, 1.7953e+06, 2.2084e+06 );
143
+ vec3 var = vec3( 4.3278e+09, 9.3046e+09, 6.6121e+09 );
144
+ vec3 xyz = val * sqrt( 2.0 * PI * var ) * cos( pos * phase + shift ) * exp( - pow2( phase ) * var );
145
+ xyz.x += 9.7470e-14 * sqrt( 2.0 * PI * 4.5282e+09 ) * cos( 2.2399e+06 * phase + shift[ 0 ] ) * exp( - 4.5282e+09 * pow2( phase ) );
146
+ xyz /= 1.0685e-7;
147
+ vec3 rgb = XYZ_TO_REC709 * xyz;
148
+ return rgb;
149
+ }
150
+ vec3 evalIridescence( float outsideIOR, float eta2, float cosTheta1, float thinFilmThickness, vec3 baseF0 ) {
151
+ vec3 I;
152
+ float iridescenceIOR = mix( outsideIOR, eta2, smoothstep( 0.0, 0.03, thinFilmThickness ) );
153
+ float sinTheta2Sq = pow2( outsideIOR / iridescenceIOR ) * ( 1.0 - pow2( cosTheta1 ) );
154
+ float cosTheta2Sq = 1.0 - sinTheta2Sq;
155
+ if ( cosTheta2Sq < 0.0 ) {
156
+ return vec3( 1.0 );
157
+ }
158
+ float cosTheta2 = sqrt( cosTheta2Sq );
159
+ float R0 = IorToFresnel0( iridescenceIOR, outsideIOR );
160
+ float R12 = F_Schlick( R0, 1.0, cosTheta1 );
161
+ float T121 = 1.0 - R12;
162
+ float phi12 = 0.0;
163
+ if ( iridescenceIOR < outsideIOR ) phi12 = PI;
164
+ float phi21 = PI - phi12;
165
+ vec3 baseIOR = Fresnel0ToIor( clamp( baseF0, 0.0, 0.9999 ) ); vec3 R1 = IorToFresnel0( baseIOR, iridescenceIOR );
166
+ vec3 R23 = F_Schlick( R1, 1.0, cosTheta2 );
167
+ vec3 phi23 = vec3( 0.0 );
168
+ if ( baseIOR[ 0 ] < iridescenceIOR ) phi23[ 0 ] = PI;
169
+ if ( baseIOR[ 1 ] < iridescenceIOR ) phi23[ 1 ] = PI;
170
+ if ( baseIOR[ 2 ] < iridescenceIOR ) phi23[ 2 ] = PI;
171
+ float OPD = 2.0 * iridescenceIOR * thinFilmThickness * cosTheta2;
172
+ vec3 phi = vec3( phi21 ) + phi23;
173
+ vec3 R123 = clamp( R12 * R23, 1e-5, 0.9999 );
174
+ vec3 r123 = sqrt( R123 );
175
+ vec3 Rs = pow2( T121 ) * R23 / ( vec3( 1.0 ) - R123 );
176
+ vec3 C0 = R12 + Rs;
177
+ I = C0;
178
+ vec3 Cm = Rs - T121;
179
+ for ( int m = 1; m <= 2; ++ m ) {
180
+ Cm *= r123;
181
+ vec3 Sm = 2.0 * evalSensitivity( float( m ) * OPD, float( m ) * phi );
182
+ I += Cm * Sm;
183
+ }
184
+ return max( I, vec3( 0.0 ) );
185
+ }
186
+ #endif`,bumpmap_pars_fragment:`#ifdef USE_BUMPMAP
187
+ uniform sampler2D bumpMap;
188
+ uniform float bumpScale;
189
+ vec2 dHdxy_fwd() {
190
+ vec2 dSTdx = dFdx( vBumpMapUv );
191
+ vec2 dSTdy = dFdy( vBumpMapUv );
192
+ float Hll = bumpScale * texture2D( bumpMap, vBumpMapUv ).x;
193
+ float dBx = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdx ).x - Hll;
194
+ float dBy = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdy ).x - Hll;
195
+ return vec2( dBx, dBy );
196
+ }
197
+ vec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy, float faceDirection ) {
198
+ vec3 vSigmaX = normalize( dFdx( surf_pos.xyz ) );
199
+ vec3 vSigmaY = normalize( dFdy( surf_pos.xyz ) );
200
+ vec3 vN = surf_norm;
201
+ vec3 R1 = cross( vSigmaY, vN );
202
+ vec3 R2 = cross( vN, vSigmaX );
203
+ float fDet = dot( vSigmaX, R1 ) * faceDirection;
204
+ vec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );
205
+ return normalize( abs( fDet ) * surf_norm - vGrad );
206
+ }
207
+ #endif`,clipping_planes_fragment:`#if NUM_CLIPPING_PLANES > 0
208
+ vec4 plane;
209
+ #ifdef ALPHA_TO_COVERAGE
210
+ float distanceToPlane, distanceGradient;
211
+ float clipOpacity = 1.0;
212
+ #pragma unroll_loop_start
213
+ for ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {
214
+ plane = clippingPlanes[ i ];
215
+ distanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;
216
+ distanceGradient = fwidth( distanceToPlane ) / 2.0;
217
+ clipOpacity *= smoothstep( - distanceGradient, distanceGradient, distanceToPlane );
218
+ if ( clipOpacity == 0.0 ) discard;
219
+ }
220
+ #pragma unroll_loop_end
221
+ #if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES
222
+ float unionClipOpacity = 1.0;
223
+ #pragma unroll_loop_start
224
+ for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {
225
+ plane = clippingPlanes[ i ];
226
+ distanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;
227
+ distanceGradient = fwidth( distanceToPlane ) / 2.0;
228
+ unionClipOpacity *= 1.0 - smoothstep( - distanceGradient, distanceGradient, distanceToPlane );
229
+ }
230
+ #pragma unroll_loop_end
231
+ clipOpacity *= 1.0 - unionClipOpacity;
232
+ #endif
233
+ diffuseColor.a *= clipOpacity;
234
+ if ( diffuseColor.a == 0.0 ) discard;
235
+ #else
236
+ #pragma unroll_loop_start
237
+ for ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {
238
+ plane = clippingPlanes[ i ];
239
+ if ( dot( vClipPosition, plane.xyz ) > plane.w ) discard;
240
+ }
241
+ #pragma unroll_loop_end
242
+ #if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES
243
+ bool clipped = true;
244
+ #pragma unroll_loop_start
245
+ for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {
246
+ plane = clippingPlanes[ i ];
247
+ clipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped;
248
+ }
249
+ #pragma unroll_loop_end
250
+ if ( clipped ) discard;
251
+ #endif
252
+ #endif
253
+ #endif`,clipping_planes_pars_fragment:`#if NUM_CLIPPING_PLANES > 0
254
+ varying vec3 vClipPosition;
255
+ uniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];
256
+ #endif`,clipping_planes_pars_vertex:`#if NUM_CLIPPING_PLANES > 0
257
+ varying vec3 vClipPosition;
258
+ #endif`,clipping_planes_vertex:`#if NUM_CLIPPING_PLANES > 0
259
+ vClipPosition = - mvPosition.xyz;
260
+ #endif`,color_fragment:`#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA )
261
+ diffuseColor *= vColor;
262
+ #endif`,color_pars_fragment:`#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA )
263
+ varying vec4 vColor;
264
+ #endif`,color_pars_vertex:`#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )
265
+ varying vec4 vColor;
266
+ #endif`,color_vertex:`#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )
267
+ vColor = vec4( 1.0 );
268
+ #endif
269
+ #ifdef USE_COLOR_ALPHA
270
+ vColor *= color;
271
+ #elif defined( USE_COLOR )
272
+ vColor.rgb *= color;
273
+ #endif
274
+ #ifdef USE_INSTANCING_COLOR
275
+ vColor.rgb *= instanceColor.rgb;
276
+ #endif
277
+ #ifdef USE_BATCHING_COLOR
278
+ vColor *= getBatchingColor( getIndirectIndex( gl_DrawID ) );
279
+ #endif`,common:`#define PI 3.141592653589793
280
+ #define PI2 6.283185307179586
281
+ #define PI_HALF 1.5707963267948966
282
+ #define RECIPROCAL_PI 0.3183098861837907
283
+ #define RECIPROCAL_PI2 0.15915494309189535
284
+ #define EPSILON 1e-6
285
+ #ifndef saturate
286
+ #define saturate( a ) clamp( a, 0.0, 1.0 )
287
+ #endif
288
+ #define whiteComplement( a ) ( 1.0 - saturate( a ) )
289
+ float pow2( const in float x ) { return x*x; }
290
+ vec3 pow2( const in vec3 x ) { return x*x; }
291
+ float pow3( const in float x ) { return x*x*x; }
292
+ float pow4( const in float x ) { float x2 = x*x; return x2*x2; }
293
+ float max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); }
294
+ float average( const in vec3 v ) { return dot( v, vec3( 0.3333333 ) ); }
295
+ highp float rand( const in vec2 uv ) {
296
+ const highp float a = 12.9898, b = 78.233, c = 43758.5453;
297
+ highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );
298
+ return fract( sin( sn ) * c );
299
+ }
300
+ #ifdef HIGH_PRECISION
301
+ float precisionSafeLength( vec3 v ) { return length( v ); }
302
+ #else
303
+ float precisionSafeLength( vec3 v ) {
304
+ float maxComponent = max3( abs( v ) );
305
+ return length( v / maxComponent ) * maxComponent;
306
+ }
307
+ #endif
308
+ struct IncidentLight {
309
+ vec3 color;
310
+ vec3 direction;
311
+ bool visible;
312
+ };
313
+ struct ReflectedLight {
314
+ vec3 directDiffuse;
315
+ vec3 directSpecular;
316
+ vec3 indirectDiffuse;
317
+ vec3 indirectSpecular;
318
+ };
319
+ #ifdef USE_ALPHAHASH
320
+ varying vec3 vPosition;
321
+ #endif
322
+ vec3 transformDirection( in vec3 dir, in mat4 matrix ) {
323
+ return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );
324
+ }
325
+ #define inverseTransformDirection transformDirectionByInverseViewMatrix
326
+ vec3 transformNormalByInverseViewMatrix( in vec3 normal, in mat4 viewMatrix ) {
327
+ return normalize( ( vec4( normal, 0.0 ) * viewMatrix ).xyz );
328
+ }
329
+ vec3 transformDirectionByInverseViewMatrix( in vec3 dir, in mat4 viewMatrix ) {
330
+ return normalize( ( vec4( dir, 0.0 ) * viewMatrix ).xyz );
331
+ }
332
+ bool isPerspectiveMatrix( mat4 m ) {
333
+ return m[ 2 ][ 3 ] == - 1.0;
334
+ }
335
+ vec2 equirectUv( in vec3 dir ) {
336
+ float u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5;
337
+ float v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;
338
+ return vec2( u, v );
339
+ }
340
+ vec3 BRDF_Lambert( const in vec3 diffuseColor ) {
341
+ return RECIPROCAL_PI * diffuseColor;
342
+ }
343
+ vec3 F_Schlick( const in vec3 f0, const in float f90, const in float dotVH ) {
344
+ float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );
345
+ return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );
346
+ }
347
+ float F_Schlick( const in float f0, const in float f90, const in float dotVH ) {
348
+ float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );
349
+ return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );
350
+ } // validated`,cube_uv_reflection_fragment:`#ifdef ENVMAP_TYPE_CUBE_UV
351
+ #define cubeUV_minMipLevel 4.0
352
+ #define cubeUV_minTileSize 16.0
353
+ float getFace( vec3 direction ) {
354
+ vec3 absDirection = abs( direction );
355
+ float face = - 1.0;
356
+ if ( absDirection.x > absDirection.z ) {
357
+ if ( absDirection.x > absDirection.y )
358
+ face = direction.x > 0.0 ? 0.0 : 3.0;
359
+ else
360
+ face = direction.y > 0.0 ? 1.0 : 4.0;
361
+ } else {
362
+ if ( absDirection.z > absDirection.y )
363
+ face = direction.z > 0.0 ? 2.0 : 5.0;
364
+ else
365
+ face = direction.y > 0.0 ? 1.0 : 4.0;
366
+ }
367
+ return face;
368
+ }
369
+ vec2 getUV( vec3 direction, float face ) {
370
+ vec2 uv;
371
+ if ( face == 0.0 ) {
372
+ uv = vec2( direction.z, direction.y ) / abs( direction.x );
373
+ } else if ( face == 1.0 ) {
374
+ uv = vec2( - direction.x, - direction.z ) / abs( direction.y );
375
+ } else if ( face == 2.0 ) {
376
+ uv = vec2( - direction.x, direction.y ) / abs( direction.z );
377
+ } else if ( face == 3.0 ) {
378
+ uv = vec2( - direction.z, direction.y ) / abs( direction.x );
379
+ } else if ( face == 4.0 ) {
380
+ uv = vec2( - direction.x, direction.z ) / abs( direction.y );
381
+ } else {
382
+ uv = vec2( direction.x, direction.y ) / abs( direction.z );
383
+ }
384
+ return 0.5 * ( uv + 1.0 );
385
+ }
386
+ vec3 bilinearCubeUV( sampler2D envMap, vec3 direction, float mipInt ) {
387
+ float face = getFace( direction );
388
+ float filterInt = max( cubeUV_minMipLevel - mipInt, 0.0 );
389
+ mipInt = max( mipInt, cubeUV_minMipLevel );
390
+ float faceSize = exp2( mipInt );
391
+ highp vec2 uv = getUV( direction, face ) * ( faceSize - 2.0 ) + 1.0;
392
+ if ( face > 2.0 ) {
393
+ uv.y += faceSize;
394
+ face -= 3.0;
395
+ }
396
+ uv.x += face * faceSize;
397
+ uv.x += filterInt * 3.0 * cubeUV_minTileSize;
398
+ uv.y += 4.0 * ( exp2( CUBEUV_MAX_MIP ) - faceSize );
399
+ uv.x *= CUBEUV_TEXEL_WIDTH;
400
+ uv.y *= CUBEUV_TEXEL_HEIGHT;
401
+ #ifdef texture2DGradEXT
402
+ return texture2DGradEXT( envMap, uv, vec2( 0.0 ), vec2( 0.0 ) ).rgb;
403
+ #else
404
+ return texture2D( envMap, uv ).rgb;
405
+ #endif
406
+ }
407
+ #define cubeUV_r0 1.0
408
+ #define cubeUV_m0 - 2.0
409
+ #define cubeUV_r1 0.8
410
+ #define cubeUV_m1 - 1.0
411
+ #define cubeUV_r4 0.4
412
+ #define cubeUV_m4 2.0
413
+ #define cubeUV_r5 0.305
414
+ #define cubeUV_m5 3.0
415
+ #define cubeUV_r6 0.21
416
+ #define cubeUV_m6 4.0
417
+ float roughnessToMip( float roughness ) {
418
+ float mip = 0.0;
419
+ if ( roughness >= cubeUV_r1 ) {
420
+ mip = ( cubeUV_r0 - roughness ) * ( cubeUV_m1 - cubeUV_m0 ) / ( cubeUV_r0 - cubeUV_r1 ) + cubeUV_m0;
421
+ } else if ( roughness >= cubeUV_r4 ) {
422
+ mip = ( cubeUV_r1 - roughness ) * ( cubeUV_m4 - cubeUV_m1 ) / ( cubeUV_r1 - cubeUV_r4 ) + cubeUV_m1;
423
+ } else if ( roughness >= cubeUV_r5 ) {
424
+ mip = ( cubeUV_r4 - roughness ) * ( cubeUV_m5 - cubeUV_m4 ) / ( cubeUV_r4 - cubeUV_r5 ) + cubeUV_m4;
425
+ } else if ( roughness >= cubeUV_r6 ) {
426
+ mip = ( cubeUV_r5 - roughness ) * ( cubeUV_m6 - cubeUV_m5 ) / ( cubeUV_r5 - cubeUV_r6 ) + cubeUV_m5;
427
+ } else {
428
+ mip = - 2.0 * log2( 1.16 * roughness ); }
429
+ return mip;
430
+ }
431
+ vec4 textureCubeUV( sampler2D envMap, vec3 sampleDir, float roughness ) {
432
+ float mip = clamp( roughnessToMip( roughness ), cubeUV_m0, CUBEUV_MAX_MIP );
433
+ float mipF = fract( mip );
434
+ float mipInt = floor( mip );
435
+ vec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt );
436
+ if ( mipF == 0.0 ) {
437
+ return vec4( color0, 1.0 );
438
+ } else {
439
+ vec3 color1 = bilinearCubeUV( envMap, sampleDir, mipInt + 1.0 );
440
+ return vec4( mix( color0, color1, mipF ), 1.0 );
441
+ }
442
+ }
443
+ #endif`,defaultnormal_vertex:`vec3 transformedNormal = objectNormal;
444
+ #ifdef USE_TANGENT
445
+ vec3 transformedTangent = objectTangent;
446
+ #endif
447
+ #ifdef USE_BATCHING
448
+ mat3 bm = mat3( batchingMatrix );
449
+ transformedNormal /= vec3( dot( bm[ 0 ], bm[ 0 ] ), dot( bm[ 1 ], bm[ 1 ] ), dot( bm[ 2 ], bm[ 2 ] ) );
450
+ transformedNormal = bm * transformedNormal;
451
+ #ifdef USE_TANGENT
452
+ transformedTangent = bm * transformedTangent;
453
+ #endif
454
+ #endif
455
+ #ifdef USE_INSTANCING
456
+ mat3 im = mat3( instanceMatrix );
457
+ transformedNormal /= vec3( dot( im[ 0 ], im[ 0 ] ), dot( im[ 1 ], im[ 1 ] ), dot( im[ 2 ], im[ 2 ] ) );
458
+ transformedNormal = im * transformedNormal;
459
+ #ifdef USE_TANGENT
460
+ transformedTangent = im * transformedTangent;
461
+ #endif
462
+ #endif
463
+ transformedNormal = normalMatrix * transformedNormal;
464
+ #ifdef FLIP_SIDED
465
+ transformedNormal = - transformedNormal;
466
+ #endif
467
+ #ifdef USE_TANGENT
468
+ transformedTangent = ( modelViewMatrix * vec4( transformedTangent, 0.0 ) ).xyz;
469
+ #endif`,displacementmap_pars_vertex:`#ifdef USE_DISPLACEMENTMAP
470
+ uniform sampler2D displacementMap;
471
+ uniform float displacementScale;
472
+ uniform float displacementBias;
473
+ #endif`,displacementmap_vertex:`#ifdef USE_DISPLACEMENTMAP
474
+ transformed += normalize( objectNormal ) * ( texture2D( displacementMap, vDisplacementMapUv ).x * displacementScale + displacementBias );
475
+ #endif`,emissivemap_fragment:`#ifdef USE_EMISSIVEMAP
476
+ vec4 emissiveColor = texture2D( emissiveMap, vEmissiveMapUv );
477
+ #ifdef DECODE_VIDEO_TEXTURE_EMISSIVE
478
+ emissiveColor = sRGBTransferEOTF( emissiveColor );
479
+ #endif
480
+ totalEmissiveRadiance *= emissiveColor.rgb;
481
+ #endif`,emissivemap_pars_fragment:`#ifdef USE_EMISSIVEMAP
482
+ uniform sampler2D emissiveMap;
483
+ #endif`,colorspace_fragment:`gl_FragColor = linearToOutputTexel( gl_FragColor );`,colorspace_pars_fragment:`vec4 LinearTransferOETF( in vec4 value ) {
484
+ return value;
485
+ }
486
+ vec4 sRGBTransferEOTF( in vec4 value ) {
487
+ return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.a );
488
+ }
489
+ vec4 sRGBTransferOETF( in vec4 value ) {
490
+ return vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a );
491
+ }`,envmap_fragment:`#ifdef USE_ENVMAP
492
+ #ifdef ENV_WORLDPOS
493
+ vec3 cameraToFrag;
494
+ if ( isOrthographic ) {
495
+ cameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );
496
+ } else {
497
+ cameraToFrag = normalize( vWorldPosition - cameraPosition );
498
+ }
499
+ vec3 worldNormal = transformNormalByInverseViewMatrix( normal, viewMatrix );
500
+ #ifdef ENVMAP_MODE_REFLECTION
501
+ vec3 reflectVec = reflect( cameraToFrag, worldNormal );
502
+ #else
503
+ vec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );
504
+ #endif
505
+ #else
506
+ vec3 reflectVec = vReflect;
507
+ #endif
508
+ #ifdef ENVMAP_TYPE_CUBE
509
+ vec4 envColor = textureCube( envMap, envMapRotation * reflectVec );
510
+ #ifdef ENVMAP_BLENDING_MULTIPLY
511
+ outgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );
512
+ #elif defined( ENVMAP_BLENDING_MIX )
513
+ outgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );
514
+ #elif defined( ENVMAP_BLENDING_ADD )
515
+ outgoingLight += envColor.xyz * specularStrength * reflectivity;
516
+ #endif
517
+ #endif
518
+ #endif`,envmap_common_pars_fragment:`#ifdef USE_ENVMAP
519
+ uniform float envMapIntensity;
520
+ uniform mat3 envMapRotation;
521
+ #ifdef ENVMAP_TYPE_CUBE
522
+ uniform samplerCube envMap;
523
+ #else
524
+ uniform sampler2D envMap;
525
+ #endif
526
+ #endif`,envmap_pars_fragment:`#ifdef USE_ENVMAP
527
+ uniform float reflectivity;
528
+ #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )
529
+ #define ENV_WORLDPOS
530
+ #endif
531
+ #ifdef ENV_WORLDPOS
532
+ varying vec3 vWorldPosition;
533
+ uniform float refractionRatio;
534
+ #else
535
+ varying vec3 vReflect;
536
+ #endif
537
+ #endif`,envmap_pars_vertex:`#ifdef USE_ENVMAP
538
+ #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )
539
+ #define ENV_WORLDPOS
540
+ #endif
541
+ #ifdef ENV_WORLDPOS
542
+
543
+ varying vec3 vWorldPosition;
544
+ #else
545
+ varying vec3 vReflect;
546
+ uniform float refractionRatio;
547
+ #endif
548
+ #endif`,envmap_physical_pars_fragment:`#ifdef USE_ENVMAP
549
+ vec3 getIBLIrradiance( const in vec3 normal ) {
550
+ #ifdef ENVMAP_TYPE_CUBE_UV
551
+ vec3 worldNormal = transformNormalByInverseViewMatrix( normal, viewMatrix );
552
+ vec4 envMapColor = textureCubeUV( envMap, envMapRotation * worldNormal, 1.0 );
553
+ return PI * envMapColor.rgb * envMapIntensity;
554
+ #else
555
+ return vec3( 0.0 );
556
+ #endif
557
+ }
558
+ vec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {
559
+ #ifdef ENVMAP_TYPE_CUBE_UV
560
+ vec3 reflectVec = reflect( - viewDir, normal );
561
+ reflectVec = normalize( mix( reflectVec, normal, pow4( roughness ) ) );
562
+ reflectVec = transformDirectionByInverseViewMatrix( reflectVec, viewMatrix );
563
+ vec4 envMapColor = textureCubeUV( envMap, envMapRotation * reflectVec, roughness );
564
+ return envMapColor.rgb * envMapIntensity;
565
+ #else
566
+ return vec3( 0.0 );
567
+ #endif
568
+ }
569
+ #ifdef USE_ANISOTROPY
570
+ vec3 getIBLAnisotropyRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in vec3 bitangent, const in float anisotropy ) {
571
+ #ifdef ENVMAP_TYPE_CUBE_UV
572
+ vec3 bentNormal = cross( bitangent, viewDir );
573
+ bentNormal = normalize( cross( bentNormal, bitangent ) );
574
+ bentNormal = normalize( mix( bentNormal, normal, pow2( pow2( 1.0 - anisotropy * ( 1.0 - roughness ) ) ) ) );
575
+ return getIBLRadiance( viewDir, bentNormal, roughness );
576
+ #else
577
+ return vec3( 0.0 );
578
+ #endif
579
+ }
580
+ #endif
581
+ #endif`,envmap_vertex:`#ifdef USE_ENVMAP
582
+ #ifdef ENV_WORLDPOS
583
+ vWorldPosition = worldPosition.xyz;
584
+ #else
585
+ vec3 cameraToVertex;
586
+ if ( isOrthographic ) {
587
+ cameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );
588
+ } else {
589
+ cameraToVertex = normalize( worldPosition.xyz - cameraPosition );
590
+ }
591
+ vec3 worldNormal = transformNormalByInverseViewMatrix( transformedNormal, viewMatrix );
592
+ #ifdef ENVMAP_MODE_REFLECTION
593
+ vReflect = reflect( cameraToVertex, worldNormal );
594
+ #else
595
+ vReflect = refract( cameraToVertex, worldNormal, refractionRatio );
596
+ #endif
597
+ #endif
598
+ #endif`,fog_vertex:`#ifdef USE_FOG
599
+ vFogDepth = - mvPosition.z;
600
+ #endif`,fog_pars_vertex:`#ifdef USE_FOG
601
+ varying float vFogDepth;
602
+ #endif`,fog_fragment:`#ifdef USE_FOG
603
+ #ifdef FOG_EXP2
604
+ float fogFactor = 1.0 - exp( - fogDensity * fogDensity * vFogDepth * vFogDepth );
605
+ #else
606
+ float fogFactor = smoothstep( fogNear, fogFar, vFogDepth );
607
+ #endif
608
+ gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );
609
+ #endif`,fog_pars_fragment:`#ifdef USE_FOG
610
+ uniform vec3 fogColor;
611
+ varying float vFogDepth;
612
+ #ifdef FOG_EXP2
613
+ uniform float fogDensity;
614
+ #else
615
+ uniform float fogNear;
616
+ uniform float fogFar;
617
+ #endif
618
+ #endif`,gradientmap_pars_fragment:`#ifdef USE_GRADIENTMAP
619
+ uniform sampler2D gradientMap;
620
+ #endif
621
+ vec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {
622
+ float dotNL = dot( normal, lightDirection );
623
+ vec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );
624
+ #ifdef USE_GRADIENTMAP
625
+ return vec3( texture2D( gradientMap, coord ).r );
626
+ #else
627
+ vec2 fw = fwidth( coord ) * 0.5;
628
+ return mix( vec3( 0.7 ), vec3( 1.0 ), smoothstep( 0.7 - fw.x, 0.7 + fw.x, coord.x ) );
629
+ #endif
630
+ }`,lightmap_pars_fragment:`#ifdef USE_LIGHTMAP
631
+ uniform sampler2D lightMap;
632
+ uniform float lightMapIntensity;
633
+ #endif`,lights_lambert_fragment:`LambertMaterial material;
634
+ material.diffuseColor = diffuseColor.rgb;
635
+ material.specularStrength = specularStrength;`,lights_lambert_pars_fragment:`varying vec3 vViewPosition;
636
+ struct LambertMaterial {
637
+ vec3 diffuseColor;
638
+ float specularStrength;
639
+ };
640
+ void RE_Direct_Lambert( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {
641
+ float dotNL = saturate( dot( geometryNormal, directLight.direction ) );
642
+ vec3 irradiance = dotNL * directLight.color;
643
+ reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
644
+ }
645
+ void RE_IndirectDiffuse_Lambert( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {
646
+ reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
647
+ }
648
+ #define RE_Direct RE_Direct_Lambert
649
+ #define RE_IndirectDiffuse RE_IndirectDiffuse_Lambert`,lights_pars_begin:`uniform bool receiveShadow;
650
+ uniform vec3 ambientLightColor;
651
+ #if defined( USE_LIGHT_PROBES )
652
+ uniform vec3 lightProbe[ 9 ];
653
+ #endif
654
+ vec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {
655
+ float x = normal.x, y = normal.y, z = normal.z;
656
+ vec3 result = shCoefficients[ 0 ] * 0.886227;
657
+ result += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;
658
+ result += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;
659
+ result += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;
660
+ result += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;
661
+ result += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;
662
+ result += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );
663
+ result += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;
664
+ result += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );
665
+ return result;
666
+ }
667
+ vec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in vec3 normal ) {
668
+ vec3 worldNormal = transformNormalByInverseViewMatrix( normal, viewMatrix );
669
+ vec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );
670
+ return irradiance;
671
+ }
672
+ vec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {
673
+ vec3 irradiance = ambientLightColor;
674
+ return irradiance;
675
+ }
676
+ float getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {
677
+ float distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );
678
+ if ( cutoffDistance > 0.0 ) {
679
+ distanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );
680
+ }
681
+ return distanceFalloff;
682
+ }
683
+ float getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) {
684
+ return smoothstep( coneCosine, penumbraCosine, angleCosine );
685
+ }
686
+ #if NUM_DIR_LIGHTS > 0
687
+ struct DirectionalLight {
688
+ vec3 direction;
689
+ vec3 color;
690
+ };
691
+ uniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];
692
+ void getDirectionalLightInfo( const in DirectionalLight directionalLight, out IncidentLight light ) {
693
+ light.color = directionalLight.color;
694
+ light.direction = directionalLight.direction;
695
+ light.visible = true;
696
+ }
697
+ #endif
698
+ #if NUM_POINT_LIGHTS > 0
699
+ struct PointLight {
700
+ vec3 position;
701
+ vec3 color;
702
+ float distance;
703
+ float decay;
704
+ };
705
+ uniform PointLight pointLights[ NUM_POINT_LIGHTS ];
706
+ void getPointLightInfo( const in PointLight pointLight, const in vec3 geometryPosition, out IncidentLight light ) {
707
+ vec3 lVector = pointLight.position - geometryPosition;
708
+ light.direction = normalize( lVector );
709
+ float lightDistance = length( lVector );
710
+ light.color = pointLight.color;
711
+ light.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay );
712
+ light.visible = ( light.color != vec3( 0.0 ) );
713
+ }
714
+ #endif
715
+ #if NUM_SPOT_LIGHTS > 0
716
+ struct SpotLight {
717
+ vec3 position;
718
+ vec3 direction;
719
+ vec3 color;
720
+ float distance;
721
+ float decay;
722
+ float coneCos;
723
+ float penumbraCos;
724
+ };
725
+ uniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];
726
+ void getSpotLightInfo( const in SpotLight spotLight, const in vec3 geometryPosition, out IncidentLight light ) {
727
+ vec3 lVector = spotLight.position - geometryPosition;
728
+ light.direction = normalize( lVector );
729
+ float angleCos = dot( light.direction, spotLight.direction );
730
+ float spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos );
731
+ if ( spotAttenuation > 0.0 ) {
732
+ float lightDistance = length( lVector );
733
+ light.color = spotLight.color * spotAttenuation;
734
+ light.color *= getDistanceAttenuation( lightDistance, spotLight.distance, spotLight.decay );
735
+ light.visible = ( light.color != vec3( 0.0 ) );
736
+ } else {
737
+ light.color = vec3( 0.0 );
738
+ light.visible = false;
739
+ }
740
+ }
741
+ #endif
742
+ #if NUM_RECT_AREA_LIGHTS > 0
743
+ struct RectAreaLight {
744
+ vec3 color;
745
+ vec3 position;
746
+ vec3 halfWidth;
747
+ vec3 halfHeight;
748
+ };
749
+ uniform sampler2D ltc_1; uniform sampler2D ltc_2;
750
+ uniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];
751
+ #endif
752
+ #if NUM_HEMI_LIGHTS > 0
753
+ struct HemisphereLight {
754
+ vec3 direction;
755
+ vec3 skyColor;
756
+ vec3 groundColor;
757
+ };
758
+ uniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];
759
+ vec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in vec3 normal ) {
760
+ float dotNL = dot( normal, hemiLight.direction );
761
+ float hemiDiffuseWeight = 0.5 * dotNL + 0.5;
762
+ vec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );
763
+ return irradiance;
764
+ }
765
+ #endif
766
+ #include <lightprobes_pars_fragment>`,lights_toon_fragment:`ToonMaterial material;
767
+ material.diffuseColor = diffuseColor.rgb;`,lights_toon_pars_fragment:`varying vec3 vViewPosition;
768
+ struct ToonMaterial {
769
+ vec3 diffuseColor;
770
+ };
771
+ void RE_Direct_Toon( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {
772
+ vec3 irradiance = getGradientIrradiance( geometryNormal, directLight.direction ) * directLight.color;
773
+ reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
774
+ }
775
+ void RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {
776
+ reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
777
+ }
778
+ #define RE_Direct RE_Direct_Toon
779
+ #define RE_IndirectDiffuse RE_IndirectDiffuse_Toon`,lights_phong_fragment:`BlinnPhongMaterial material;
780
+ material.diffuseColor = diffuseColor.rgb;
781
+ material.specularColor = specular;
782
+ material.specularShininess = shininess;
783
+ material.specularStrength = specularStrength;`,lights_phong_pars_fragment:`varying vec3 vViewPosition;
784
+ struct BlinnPhongMaterial {
785
+ vec3 diffuseColor;
786
+ vec3 specularColor;
787
+ float specularShininess;
788
+ float specularStrength;
789
+ };
790
+ void RE_Direct_BlinnPhong( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {
791
+ float dotNL = saturate( dot( geometryNormal, directLight.direction ) );
792
+ vec3 irradiance = dotNL * directLight.color;
793
+ reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
794
+ reflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometryViewDir, geometryNormal, material.specularColor, material.specularShininess ) * material.specularStrength;
795
+ }
796
+ void RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {
797
+ reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
798
+ }
799
+ #define RE_Direct RE_Direct_BlinnPhong
800
+ #define RE_IndirectDiffuse RE_IndirectDiffuse_BlinnPhong`,lights_physical_fragment:`PhysicalMaterial material;
801
+ material.diffuseColor = diffuseColor.rgb;
802
+ material.diffuseContribution = diffuseColor.rgb * ( 1.0 - metalnessFactor );
803
+ material.metalness = metalnessFactor;
804
+ vec3 dxy = max( abs( dFdx( nonPerturbedNormal ) ), abs( dFdy( nonPerturbedNormal ) ) );
805
+ float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );
806
+ material.roughness = max( roughnessFactor, 0.0525 );material.roughness += geometryRoughness;
807
+ material.roughness = min( material.roughness, 1.0 );
808
+ #ifdef IOR
809
+ material.ior = ior;
810
+ #ifdef USE_SPECULAR
811
+ float specularIntensityFactor = specularIntensity;
812
+ vec3 specularColorFactor = specularColor;
813
+ #ifdef USE_SPECULAR_COLORMAP
814
+ specularColorFactor *= texture2D( specularColorMap, vSpecularColorMapUv ).rgb;
815
+ #endif
816
+ #ifdef USE_SPECULAR_INTENSITYMAP
817
+ specularIntensityFactor *= texture2D( specularIntensityMap, vSpecularIntensityMapUv ).a;
818
+ #endif
819
+ material.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor );
820
+ #else
821
+ float specularIntensityFactor = 1.0;
822
+ vec3 specularColorFactor = vec3( 1.0 );
823
+ material.specularF90 = 1.0;
824
+ #endif
825
+ material.specularColor = min( pow2( ( material.ior - 1.0 ) / ( material.ior + 1.0 ) ) * specularColorFactor, vec3( 1.0 ) ) * specularIntensityFactor;
826
+ material.specularColorBlended = mix( material.specularColor, diffuseColor.rgb, metalnessFactor );
827
+ #else
828
+ material.specularColor = vec3( 0.04 );
829
+ material.specularColorBlended = mix( material.specularColor, diffuseColor.rgb, metalnessFactor );
830
+ material.specularF90 = 1.0;
831
+ #endif
832
+ #ifdef USE_CLEARCOAT
833
+ material.clearcoat = clearcoat;
834
+ material.clearcoatRoughness = clearcoatRoughness;
835
+ material.clearcoatF0 = vec3( 0.04 );
836
+ material.clearcoatF90 = 1.0;
837
+ #ifdef USE_CLEARCOATMAP
838
+ material.clearcoat *= texture2D( clearcoatMap, vClearcoatMapUv ).x;
839
+ #endif
840
+ #ifdef USE_CLEARCOAT_ROUGHNESSMAP
841
+ material.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vClearcoatRoughnessMapUv ).y;
842
+ #endif
843
+ material.clearcoat = saturate( material.clearcoat ); material.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 );
844
+ material.clearcoatRoughness += geometryRoughness;
845
+ material.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );
846
+ #endif
847
+ #ifdef USE_DISPERSION
848
+ material.dispersion = dispersion;
849
+ #endif
850
+ #ifdef USE_IRIDESCENCE
851
+ material.iridescence = iridescence;
852
+ material.iridescenceIOR = iridescenceIOR;
853
+ #ifdef USE_IRIDESCENCEMAP
854
+ material.iridescence *= texture2D( iridescenceMap, vIridescenceMapUv ).r;
855
+ #endif
856
+ #ifdef USE_IRIDESCENCE_THICKNESSMAP
857
+ material.iridescenceThickness = (iridescenceThicknessMaximum - iridescenceThicknessMinimum) * texture2D( iridescenceThicknessMap, vIridescenceThicknessMapUv ).g + iridescenceThicknessMinimum;
858
+ #else
859
+ material.iridescenceThickness = iridescenceThicknessMaximum;
860
+ #endif
861
+ #endif
862
+ #ifdef USE_SHEEN
863
+ material.sheenColor = sheenColor;
864
+ #ifdef USE_SHEEN_COLORMAP
865
+ material.sheenColor *= texture2D( sheenColorMap, vSheenColorMapUv ).rgb;
866
+ #endif
867
+ material.sheenRoughness = clamp( sheenRoughness, 0.0001, 1.0 );
868
+ #ifdef USE_SHEEN_ROUGHNESSMAP
869
+ material.sheenRoughness *= texture2D( sheenRoughnessMap, vSheenRoughnessMapUv ).a;
870
+ #endif
871
+ #endif
872
+ #ifdef USE_ANISOTROPY
873
+ #ifdef USE_ANISOTROPYMAP
874
+ mat2 anisotropyMat = mat2( anisotropyVector.x, anisotropyVector.y, - anisotropyVector.y, anisotropyVector.x );
875
+ vec3 anisotropyPolar = texture2D( anisotropyMap, vAnisotropyMapUv ).rgb;
876
+ vec2 anisotropyV = anisotropyMat * normalize( 2.0 * anisotropyPolar.rg - vec2( 1.0 ) ) * anisotropyPolar.b;
877
+ #else
878
+ vec2 anisotropyV = anisotropyVector;
879
+ #endif
880
+ material.anisotropy = length( anisotropyV );
881
+ if( material.anisotropy == 0.0 ) {
882
+ anisotropyV = vec2( 1.0, 0.0 );
883
+ } else {
884
+ anisotropyV /= material.anisotropy;
885
+ material.anisotropy = saturate( material.anisotropy );
886
+ }
887
+ material.alphaT = mix( pow2( material.roughness ), 1.0, pow2( material.anisotropy ) );
888
+ material.anisotropyT = tbn[ 0 ] * anisotropyV.x + tbn[ 1 ] * anisotropyV.y;
889
+ material.anisotropyB = tbn[ 1 ] * anisotropyV.x - tbn[ 0 ] * anisotropyV.y;
890
+ #endif`,lights_physical_pars_fragment:`uniform sampler2D dfgLUT;
891
+ struct PhysicalMaterial {
892
+ vec3 diffuseColor;
893
+ vec3 diffuseContribution;
894
+ vec3 specularColor;
895
+ vec3 specularColorBlended;
896
+ float roughness;
897
+ float metalness;
898
+ float specularF90;
899
+ float dispersion;
900
+ #ifdef USE_CLEARCOAT
901
+ float clearcoat;
902
+ float clearcoatRoughness;
903
+ vec3 clearcoatF0;
904
+ float clearcoatF90;
905
+ #endif
906
+ #ifdef USE_IRIDESCENCE
907
+ float iridescence;
908
+ float iridescenceIOR;
909
+ float iridescenceThickness;
910
+ vec3 iridescenceFresnel;
911
+ vec3 iridescenceF0;
912
+ vec3 iridescenceFresnelDielectric;
913
+ vec3 iridescenceFresnelMetallic;
914
+ #endif
915
+ #ifdef USE_SHEEN
916
+ vec3 sheenColor;
917
+ float sheenRoughness;
918
+ #endif
919
+ #ifdef IOR
920
+ float ior;
921
+ #endif
922
+ #ifdef USE_TRANSMISSION
923
+ float transmission;
924
+ float transmissionAlpha;
925
+ float thickness;
926
+ float attenuationDistance;
927
+ vec3 attenuationColor;
928
+ #endif
929
+ #ifdef USE_ANISOTROPY
930
+ float anisotropy;
931
+ float alphaT;
932
+ vec3 anisotropyT;
933
+ vec3 anisotropyB;
934
+ #endif
935
+ };
936
+ vec3 clearcoatSpecularDirect = vec3( 0.0 );
937
+ vec3 clearcoatSpecularIndirect = vec3( 0.0 );
938
+ vec3 sheenSpecularDirect = vec3( 0.0 );
939
+ vec3 sheenSpecularIndirect = vec3(0.0 );
940
+ vec3 Schlick_to_F0( const in vec3 f, const in float f90, const in float dotVH ) {
941
+ float x = clamp( 1.0 - dotVH, 0.0, 1.0 );
942
+ float x2 = x * x;
943
+ float x5 = clamp( x * x2 * x2, 0.0, 0.9999 );
944
+ return ( f - vec3( f90 ) * x5 ) / ( 1.0 - x5 );
945
+ }
946
+ float V_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {
947
+ float a2 = pow2( alpha );
948
+ float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );
949
+ float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );
950
+ return 0.5 / max( gv + gl, EPSILON );
951
+ }
952
+ float D_GGX( const in float alpha, const in float dotNH ) {
953
+ float a2 = pow2( alpha );
954
+ float denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;
955
+ return RECIPROCAL_PI * a2 / pow2( denom );
956
+ }
957
+ #ifdef USE_ANISOTROPY
958
+ float V_GGX_SmithCorrelated_Anisotropic( const in float alphaT, const in float alphaB, const in float dotTV, const in float dotBV, const in float dotTL, const in float dotBL, const in float dotNV, const in float dotNL ) {
959
+ float gv = dotNL * length( vec3( alphaT * dotTV, alphaB * dotBV, dotNV ) );
960
+ float gl = dotNV * length( vec3( alphaT * dotTL, alphaB * dotBL, dotNL ) );
961
+ return 0.5 / max( gv + gl, EPSILON );
962
+ }
963
+ float D_GGX_Anisotropic( const in float alphaT, const in float alphaB, const in float dotNH, const in float dotTH, const in float dotBH ) {
964
+ float a2 = alphaT * alphaB;
965
+ highp vec3 v = vec3( alphaB * dotTH, alphaT * dotBH, a2 * dotNH );
966
+ highp float v2 = dot( v, v );
967
+ float w2 = a2 / v2;
968
+ return RECIPROCAL_PI * a2 * pow2 ( w2 );
969
+ }
970
+ #endif
971
+ #ifdef USE_CLEARCOAT
972
+ vec3 BRDF_GGX_Clearcoat( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material) {
973
+ vec3 f0 = material.clearcoatF0;
974
+ float f90 = material.clearcoatF90;
975
+ float roughness = material.clearcoatRoughness;
976
+ float alpha = pow2( roughness );
977
+ vec3 halfDir = normalize( lightDir + viewDir );
978
+ float dotNL = saturate( dot( normal, lightDir ) );
979
+ float dotNV = saturate( dot( normal, viewDir ) );
980
+ float dotNH = saturate( dot( normal, halfDir ) );
981
+ float dotVH = saturate( dot( viewDir, halfDir ) );
982
+ vec3 F = F_Schlick( f0, f90, dotVH );
983
+ float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );
984
+ float D = D_GGX( alpha, dotNH );
985
+ return F * ( V * D );
986
+ }
987
+ #endif
988
+ vec3 BRDF_GGX( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) {
989
+ vec3 f0 = material.specularColorBlended;
990
+ float f90 = material.specularF90;
991
+ float roughness = material.roughness;
992
+ float alpha = pow2( roughness );
993
+ vec3 halfDir = normalize( lightDir + viewDir );
994
+ float dotNL = saturate( dot( normal, lightDir ) );
995
+ float dotNV = saturate( dot( normal, viewDir ) );
996
+ float dotNH = saturate( dot( normal, halfDir ) );
997
+ float dotVH = saturate( dot( viewDir, halfDir ) );
998
+ vec3 F = F_Schlick( f0, f90, dotVH );
999
+ #ifdef USE_IRIDESCENCE
1000
+ F = mix( F, material.iridescenceFresnel, material.iridescence );
1001
+ #endif
1002
+ #ifdef USE_ANISOTROPY
1003
+ float dotTL = dot( material.anisotropyT, lightDir );
1004
+ float dotTV = dot( material.anisotropyT, viewDir );
1005
+ float dotTH = dot( material.anisotropyT, halfDir );
1006
+ float dotBL = dot( material.anisotropyB, lightDir );
1007
+ float dotBV = dot( material.anisotropyB, viewDir );
1008
+ float dotBH = dot( material.anisotropyB, halfDir );
1009
+ float V = V_GGX_SmithCorrelated_Anisotropic( material.alphaT, alpha, dotTV, dotBV, dotTL, dotBL, dotNV, dotNL );
1010
+ float D = D_GGX_Anisotropic( material.alphaT, alpha, dotNH, dotTH, dotBH );
1011
+ #else
1012
+ float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );
1013
+ float D = D_GGX( alpha, dotNH );
1014
+ #endif
1015
+ return F * ( V * D );
1016
+ }
1017
+ vec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {
1018
+ const float LUT_SIZE = 64.0;
1019
+ const float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;
1020
+ const float LUT_BIAS = 0.5 / LUT_SIZE;
1021
+ float dotNV = saturate( dot( N, V ) );
1022
+ vec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );
1023
+ uv = uv * LUT_SCALE + LUT_BIAS;
1024
+ return uv;
1025
+ }
1026
+ float LTC_ClippedSphereFormFactor( const in vec3 f ) {
1027
+ float l = length( f );
1028
+ return max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );
1029
+ }
1030
+ vec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {
1031
+ float x = dot( v1, v2 );
1032
+ float y = abs( x );
1033
+ float a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;
1034
+ float b = 3.4175940 + ( 4.1616724 + y ) * y;
1035
+ float v = a / b;
1036
+ float theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;
1037
+ return cross( v1, v2 ) * theta_sintheta;
1038
+ }
1039
+ vec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {
1040
+ vec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];
1041
+ vec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];
1042
+ vec3 lightNormal = cross( v1, v2 );
1043
+ if( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );
1044
+ vec3 T1, T2;
1045
+ T1 = normalize( V - N * dot( V, N ) );
1046
+ T2 = - cross( N, T1 );
1047
+ mat3 mat = mInv * transpose( mat3( T1, T2, N ) );
1048
+ vec3 coords[ 4 ];
1049
+ coords[ 0 ] = mat * ( rectCoords[ 0 ] - P );
1050
+ coords[ 1 ] = mat * ( rectCoords[ 1 ] - P );
1051
+ coords[ 2 ] = mat * ( rectCoords[ 2 ] - P );
1052
+ coords[ 3 ] = mat * ( rectCoords[ 3 ] - P );
1053
+ coords[ 0 ] = normalize( coords[ 0 ] );
1054
+ coords[ 1 ] = normalize( coords[ 1 ] );
1055
+ coords[ 2 ] = normalize( coords[ 2 ] );
1056
+ coords[ 3 ] = normalize( coords[ 3 ] );
1057
+ vec3 vectorFormFactor = vec3( 0.0 );
1058
+ vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );
1059
+ vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );
1060
+ vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );
1061
+ vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );
1062
+ float result = LTC_ClippedSphereFormFactor( vectorFormFactor );
1063
+ return vec3( result );
1064
+ }
1065
+ #if defined( USE_SHEEN )
1066
+ float D_Charlie( float roughness, float dotNH ) {
1067
+ float alpha = pow2( roughness );
1068
+ float invAlpha = 1.0 / alpha;
1069
+ float cos2h = dotNH * dotNH;
1070
+ float sin2h = max( 1.0 - cos2h, 0.0078125 );
1071
+ return ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI );
1072
+ }
1073
+ float V_Neubelt( float dotNV, float dotNL ) {
1074
+ return saturate( 1.0 / ( 4.0 * ( dotNL + dotNV - dotNL * dotNV ) ) );
1075
+ }
1076
+ vec3 BRDF_Sheen( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, vec3 sheenColor, const in float sheenRoughness ) {
1077
+ vec3 halfDir = normalize( lightDir + viewDir );
1078
+ float dotNL = saturate( dot( normal, lightDir ) );
1079
+ float dotNV = saturate( dot( normal, viewDir ) );
1080
+ float dotNH = saturate( dot( normal, halfDir ) );
1081
+ float D = D_Charlie( sheenRoughness, dotNH );
1082
+ float V = V_Neubelt( dotNV, dotNL );
1083
+ return sheenColor * ( D * V );
1084
+ }
1085
+ #endif
1086
+ float IBLSheenBRDF( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {
1087
+ float dotNV = saturate( dot( normal, viewDir ) );
1088
+ float r2 = roughness * roughness;
1089
+ float rInv = 1.0 / ( roughness + 0.1 );
1090
+ float a = -1.9362 + 1.0678 * roughness + 0.4573 * r2 - 0.8469 * rInv;
1091
+ float b = -0.6014 + 0.5538 * roughness - 0.4670 * r2 - 0.1255 * rInv;
1092
+ float DG = exp( a * dotNV + b );
1093
+ return saturate( DG );
1094
+ }
1095
+ vec3 EnvironmentBRDF( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness ) {
1096
+ float dotNV = saturate( dot( normal, viewDir ) );
1097
+ vec2 fab = texture2D( dfgLUT, vec2( roughness, dotNV ) ).rg;
1098
+ return specularColor * fab.x + specularF90 * fab.y;
1099
+ }
1100
+ #ifdef USE_IRIDESCENCE
1101
+ void computeMultiscatteringIridescence( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float iridescence, const in vec3 iridescenceF0, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {
1102
+ #else
1103
+ void computeMultiscattering( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {
1104
+ #endif
1105
+ float dotNV = saturate( dot( normal, viewDir ) );
1106
+ vec2 fab = texture2D( dfgLUT, vec2( roughness, dotNV ) ).rg;
1107
+ #ifdef USE_IRIDESCENCE
1108
+ vec3 Fr = mix( specularColor, iridescenceF0, iridescence );
1109
+ #else
1110
+ vec3 Fr = specularColor;
1111
+ #endif
1112
+ vec3 FssEss = Fr * fab.x + specularF90 * fab.y;
1113
+ float Ess = fab.x + fab.y;
1114
+ float Ems = 1.0 - Ess;
1115
+ vec3 Favg = Fr + ( 1.0 - Fr ) * 0.047619; vec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );
1116
+ singleScatter += FssEss;
1117
+ multiScatter += Fms * Ems;
1118
+ }
1119
+ vec3 BRDF_GGX_Multiscatter( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) {
1120
+ vec3 singleScatter = BRDF_GGX( lightDir, viewDir, normal, material );
1121
+ float dotNL = saturate( dot( normal, lightDir ) );
1122
+ float dotNV = saturate( dot( normal, viewDir ) );
1123
+ vec2 dfgV = texture2D( dfgLUT, vec2( material.roughness, dotNV ) ).rg;
1124
+ vec2 dfgL = texture2D( dfgLUT, vec2( material.roughness, dotNL ) ).rg;
1125
+ vec3 FssEss_V = material.specularColorBlended * dfgV.x + material.specularF90 * dfgV.y;
1126
+ vec3 FssEss_L = material.specularColorBlended * dfgL.x + material.specularF90 * dfgL.y;
1127
+ float Ess_V = dfgV.x + dfgV.y;
1128
+ float Ess_L = dfgL.x + dfgL.y;
1129
+ float Ems_V = 1.0 - Ess_V;
1130
+ float Ems_L = 1.0 - Ess_L;
1131
+ vec3 Favg = material.specularColorBlended + ( 1.0 - material.specularColorBlended ) * 0.047619;
1132
+ vec3 Fms = FssEss_V * FssEss_L * Favg / ( 1.0 - Ems_V * Ems_L * Favg + EPSILON );
1133
+ float compensationFactor = Ems_V * Ems_L;
1134
+ vec3 multiScatter = Fms * compensationFactor;
1135
+ return singleScatter + multiScatter;
1136
+ }
1137
+ #if NUM_RECT_AREA_LIGHTS > 0
1138
+ void RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
1139
+ vec3 normal = geometryNormal;
1140
+ vec3 viewDir = geometryViewDir;
1141
+ vec3 position = geometryPosition;
1142
+ vec3 lightPos = rectAreaLight.position;
1143
+ vec3 halfWidth = rectAreaLight.halfWidth;
1144
+ vec3 halfHeight = rectAreaLight.halfHeight;
1145
+ vec3 lightColor = rectAreaLight.color;
1146
+ float roughness = material.roughness;
1147
+ vec3 rectCoords[ 4 ];
1148
+ rectCoords[ 0 ] = lightPos + halfWidth - halfHeight; rectCoords[ 1 ] = lightPos - halfWidth - halfHeight;
1149
+ rectCoords[ 2 ] = lightPos - halfWidth + halfHeight;
1150
+ rectCoords[ 3 ] = lightPos + halfWidth + halfHeight;
1151
+ vec2 uv = LTC_Uv( normal, viewDir, roughness );
1152
+ vec4 t1 = texture2D( ltc_1, uv );
1153
+ vec4 t2 = texture2D( ltc_2, uv );
1154
+ mat3 mInv = mat3(
1155
+ vec3( t1.x, 0, t1.y ),
1156
+ vec3( 0, 1, 0 ),
1157
+ vec3( t1.z, 0, t1.w )
1158
+ );
1159
+ vec3 fresnel = ( material.specularColorBlended * t2.x + ( material.specularF90 - material.specularColorBlended ) * t2.y );
1160
+ reflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );
1161
+ reflectedLight.directDiffuse += lightColor * material.diffuseContribution * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );
1162
+ #ifdef USE_CLEARCOAT
1163
+ vec3 Ncc = geometryClearcoatNormal;
1164
+ vec2 uvClearcoat = LTC_Uv( Ncc, viewDir, material.clearcoatRoughness );
1165
+ vec4 t1Clearcoat = texture2D( ltc_1, uvClearcoat );
1166
+ vec4 t2Clearcoat = texture2D( ltc_2, uvClearcoat );
1167
+ mat3 mInvClearcoat = mat3(
1168
+ vec3( t1Clearcoat.x, 0, t1Clearcoat.y ),
1169
+ vec3( 0, 1, 0 ),
1170
+ vec3( t1Clearcoat.z, 0, t1Clearcoat.w )
1171
+ );
1172
+ vec3 fresnelClearcoat = material.clearcoatF0 * t2Clearcoat.x + ( material.clearcoatF90 - material.clearcoatF0 ) * t2Clearcoat.y;
1173
+ clearcoatSpecularDirect += lightColor * fresnelClearcoat * LTC_Evaluate( Ncc, viewDir, position, mInvClearcoat, rectCoords );
1174
+ #endif
1175
+ }
1176
+ #endif
1177
+ void RE_Direct_Physical( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
1178
+ float dotNL = saturate( dot( geometryNormal, directLight.direction ) );
1179
+ vec3 irradiance = dotNL * directLight.color;
1180
+ #ifdef USE_CLEARCOAT
1181
+ float dotNLcc = saturate( dot( geometryClearcoatNormal, directLight.direction ) );
1182
+ vec3 ccIrradiance = dotNLcc * directLight.color;
1183
+ clearcoatSpecularDirect += ccIrradiance * BRDF_GGX_Clearcoat( directLight.direction, geometryViewDir, geometryClearcoatNormal, material );
1184
+ #endif
1185
+ #ifdef USE_SHEEN
1186
+
1187
+ sheenSpecularDirect += irradiance * BRDF_Sheen( directLight.direction, geometryViewDir, geometryNormal, material.sheenColor, material.sheenRoughness );
1188
+
1189
+ float sheenAlbedoV = IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );
1190
+ float sheenAlbedoL = IBLSheenBRDF( geometryNormal, directLight.direction, material.sheenRoughness );
1191
+
1192
+ float sheenEnergyComp = 1.0 - max3( material.sheenColor ) * max( sheenAlbedoV, sheenAlbedoL );
1193
+
1194
+ irradiance *= sheenEnergyComp;
1195
+
1196
+ #endif
1197
+ reflectedLight.directSpecular += irradiance * BRDF_GGX_Multiscatter( directLight.direction, geometryViewDir, geometryNormal, material );
1198
+ reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseContribution );
1199
+ }
1200
+ void RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
1201
+ vec3 diffuse = irradiance * BRDF_Lambert( material.diffuseContribution );
1202
+ #ifdef USE_SHEEN
1203
+ float sheenAlbedo = IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );
1204
+ float sheenEnergyComp = 1.0 - max3( material.sheenColor ) * sheenAlbedo;
1205
+ diffuse *= sheenEnergyComp;
1206
+ #endif
1207
+ reflectedLight.indirectDiffuse += diffuse;
1208
+ }
1209
+ void RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {
1210
+ #ifdef USE_CLEARCOAT
1211
+ clearcoatSpecularIndirect += clearcoatRadiance * EnvironmentBRDF( geometryClearcoatNormal, geometryViewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );
1212
+ #endif
1213
+ #ifdef USE_SHEEN
1214
+ sheenSpecularIndirect += irradiance * material.sheenColor * IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness ) * RECIPROCAL_PI;
1215
+ #endif
1216
+ vec3 singleScatteringDielectric = vec3( 0.0 );
1217
+ vec3 multiScatteringDielectric = vec3( 0.0 );
1218
+ vec3 singleScatteringMetallic = vec3( 0.0 );
1219
+ vec3 multiScatteringMetallic = vec3( 0.0 );
1220
+ #ifdef USE_IRIDESCENCE
1221
+ computeMultiscatteringIridescence( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.iridescence, material.iridescenceFresnelDielectric, material.roughness, singleScatteringDielectric, multiScatteringDielectric );
1222
+ computeMultiscatteringIridescence( geometryNormal, geometryViewDir, material.diffuseColor, material.specularF90, material.iridescence, material.iridescenceFresnelMetallic, material.roughness, singleScatteringMetallic, multiScatteringMetallic );
1223
+ #else
1224
+ computeMultiscattering( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.roughness, singleScatteringDielectric, multiScatteringDielectric );
1225
+ computeMultiscattering( geometryNormal, geometryViewDir, material.diffuseColor, material.specularF90, material.roughness, singleScatteringMetallic, multiScatteringMetallic );
1226
+ #endif
1227
+ vec3 singleScattering = mix( singleScatteringDielectric, singleScatteringMetallic, material.metalness );
1228
+ vec3 multiScattering = mix( multiScatteringDielectric, multiScatteringMetallic, material.metalness );
1229
+ vec3 totalScatteringDielectric = singleScatteringDielectric + multiScatteringDielectric;
1230
+ vec3 diffuse = material.diffuseContribution * ( 1.0 - totalScatteringDielectric );
1231
+ vec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;
1232
+ vec3 indirectSpecular = radiance * singleScattering;
1233
+ indirectSpecular += multiScattering * cosineWeightedIrradiance;
1234
+ vec3 indirectDiffuse = diffuse * cosineWeightedIrradiance;
1235
+ #ifdef USE_SHEEN
1236
+ float sheenAlbedo = IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );
1237
+ float sheenEnergyComp = 1.0 - max3( material.sheenColor ) * sheenAlbedo;
1238
+ indirectSpecular *= sheenEnergyComp;
1239
+ indirectDiffuse *= sheenEnergyComp;
1240
+ #endif
1241
+ reflectedLight.indirectSpecular += indirectSpecular;
1242
+ reflectedLight.indirectDiffuse += indirectDiffuse;
1243
+ }
1244
+ #define RE_Direct RE_Direct_Physical
1245
+ #define RE_Direct_RectArea RE_Direct_RectArea_Physical
1246
+ #define RE_IndirectDiffuse RE_IndirectDiffuse_Physical
1247
+ #define RE_IndirectSpecular RE_IndirectSpecular_Physical
1248
+ float computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {
1249
+ return saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );
1250
+ }`,lights_fragment_begin:`
1251
+ vec3 geometryPosition = - vViewPosition;
1252
+ vec3 geometryNormal = normal;
1253
+ vec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );
1254
+ vec3 geometryClearcoatNormal = vec3( 0.0 );
1255
+ #ifdef USE_CLEARCOAT
1256
+ geometryClearcoatNormal = clearcoatNormal;
1257
+ #endif
1258
+ #ifdef USE_IRIDESCENCE
1259
+ float dotNVi = saturate( dot( normal, geometryViewDir ) );
1260
+ if ( material.iridescenceThickness == 0.0 ) {
1261
+ material.iridescence = 0.0;
1262
+ } else {
1263
+ material.iridescence = saturate( material.iridescence );
1264
+ }
1265
+ if ( material.iridescence > 0.0 ) {
1266
+ material.iridescenceFresnelDielectric = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.specularColor );
1267
+ material.iridescenceFresnelMetallic = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.diffuseColor );
1268
+ material.iridescenceFresnel = mix( material.iridescenceFresnelDielectric, material.iridescenceFresnelMetallic, material.metalness );
1269
+ material.iridescenceF0 = Schlick_to_F0( material.iridescenceFresnel, 1.0, dotNVi );
1270
+ }
1271
+ #endif
1272
+ IncidentLight directLight;
1273
+ #if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )
1274
+ PointLight pointLight;
1275
+ #if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0
1276
+ PointLightShadow pointLightShadow;
1277
+ #endif
1278
+ #pragma unroll_loop_start
1279
+ for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {
1280
+ pointLight = pointLights[ i ];
1281
+ getPointLightInfo( pointLight, geometryPosition, directLight );
1282
+ #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS ) && ( defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_BASIC ) )
1283
+ pointLightShadow = pointLightShadows[ i ];
1284
+ directLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowIntensity, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;
1285
+ #endif
1286
+ RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
1287
+ }
1288
+ #pragma unroll_loop_end
1289
+ #endif
1290
+ #if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )
1291
+ SpotLight spotLight;
1292
+ vec4 spotColor;
1293
+ vec3 spotLightCoord;
1294
+ bool inSpotLightMap;
1295
+ #if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0
1296
+ SpotLightShadow spotLightShadow;
1297
+ #endif
1298
+ #pragma unroll_loop_start
1299
+ for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {
1300
+ spotLight = spotLights[ i ];
1301
+ getSpotLightInfo( spotLight, geometryPosition, directLight );
1302
+ #if ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )
1303
+ #define SPOT_LIGHT_MAP_INDEX UNROLLED_LOOP_INDEX
1304
+ #elif ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
1305
+ #define SPOT_LIGHT_MAP_INDEX NUM_SPOT_LIGHT_MAPS
1306
+ #else
1307
+ #define SPOT_LIGHT_MAP_INDEX ( UNROLLED_LOOP_INDEX - NUM_SPOT_LIGHT_SHADOWS + NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )
1308
+ #endif
1309
+ #if ( SPOT_LIGHT_MAP_INDEX < NUM_SPOT_LIGHT_MAPS )
1310
+ spotLightCoord = vSpotLightCoord[ i ].xyz / vSpotLightCoord[ i ].w;
1311
+ inSpotLightMap = all( lessThan( abs( spotLightCoord * 2. - 1. ), vec3( 1.0 ) ) );
1312
+ spotColor = texture2D( spotLightMap[ SPOT_LIGHT_MAP_INDEX ], spotLightCoord.xy );
1313
+ directLight.color = inSpotLightMap ? directLight.color * spotColor.rgb : directLight.color;
1314
+ #endif
1315
+ #undef SPOT_LIGHT_MAP_INDEX
1316
+ #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
1317
+ spotLightShadow = spotLightShadows[ i ];
1318
+ directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;
1319
+ #endif
1320
+ RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
1321
+ }
1322
+ #pragma unroll_loop_end
1323
+ #endif
1324
+ #if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )
1325
+ DirectionalLight directionalLight;
1326
+ #if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0
1327
+ DirectionalLightShadow directionalLightShadow;
1328
+ #endif
1329
+ #pragma unroll_loop_start
1330
+ for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
1331
+ directionalLight = directionalLights[ i ];
1332
+ getDirectionalLightInfo( directionalLight, directLight );
1333
+ #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
1334
+ directionalLightShadow = directionalLightShadows[ i ];
1335
+ directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
1336
+ #endif
1337
+ RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
1338
+ }
1339
+ #pragma unroll_loop_end
1340
+ #endif
1341
+ #if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )
1342
+ RectAreaLight rectAreaLight;
1343
+ #pragma unroll_loop_start
1344
+ for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {
1345
+ rectAreaLight = rectAreaLights[ i ];
1346
+ RE_Direct_RectArea( rectAreaLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
1347
+ }
1348
+ #pragma unroll_loop_end
1349
+ #endif
1350
+ #if defined( RE_IndirectDiffuse )
1351
+ vec3 iblIrradiance = vec3( 0.0 );
1352
+ vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );
1353
+ #if defined( USE_LIGHT_PROBES )
1354
+ irradiance += getLightProbeIrradiance( lightProbe, geometryNormal );
1355
+ #endif
1356
+ #if ( NUM_HEMI_LIGHTS > 0 )
1357
+ #pragma unroll_loop_start
1358
+ for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {
1359
+ irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal );
1360
+ }
1361
+ #pragma unroll_loop_end
1362
+ #endif
1363
+ #ifdef USE_LIGHT_PROBES_GRID
1364
+ vec3 probeWorldPos = ( ( vec4( geometryPosition, 1.0 ) - viewMatrix[ 3 ] ) * viewMatrix ).xyz;
1365
+ vec3 probeWorldNormal = transformNormalByInverseViewMatrix( geometryNormal, viewMatrix );
1366
+ irradiance += getLightProbeGridIrradiance( probeWorldPos, probeWorldNormal );
1367
+ #endif
1368
+ #endif
1369
+ #if defined( RE_IndirectSpecular )
1370
+ vec3 radiance = vec3( 0.0 );
1371
+ vec3 clearcoatRadiance = vec3( 0.0 );
1372
+ #endif`,lights_fragment_maps:`#if defined( RE_IndirectDiffuse )
1373
+ #ifdef USE_LIGHTMAP
1374
+ vec4 lightMapTexel = texture2D( lightMap, vLightMapUv );
1375
+ vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;
1376
+ irradiance += lightMapIrradiance;
1377
+ #endif
1378
+ #if defined( USE_ENVMAP ) && defined( ENVMAP_TYPE_CUBE_UV )
1379
+ #if defined( STANDARD ) || defined( LAMBERT ) || defined( PHONG )
1380
+ iblIrradiance += getIBLIrradiance( geometryNormal );
1381
+ #endif
1382
+ #endif
1383
+ #endif
1384
+ #if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )
1385
+ #ifdef USE_ANISOTROPY
1386
+ radiance += getIBLAnisotropyRadiance( geometryViewDir, geometryNormal, material.roughness, material.anisotropyB, material.anisotropy );
1387
+ #else
1388
+ radiance += getIBLRadiance( geometryViewDir, geometryNormal, material.roughness );
1389
+ #endif
1390
+ #ifdef USE_CLEARCOAT
1391
+ clearcoatRadiance += getIBLRadiance( geometryViewDir, geometryClearcoatNormal, material.clearcoatRoughness );
1392
+ #endif
1393
+ #endif`,lights_fragment_end:`#if defined( RE_IndirectDiffuse )
1394
+ #if defined( LAMBERT ) || defined( PHONG )
1395
+ irradiance += iblIrradiance;
1396
+ #endif
1397
+ RE_IndirectDiffuse( irradiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
1398
+ #endif
1399
+ #if defined( RE_IndirectSpecular )
1400
+ RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
1401
+ #endif`,lightprobes_pars_fragment:`#ifdef USE_LIGHT_PROBES_GRID
1402
+ uniform highp sampler3D probesSH;
1403
+ uniform vec3 probesMin;
1404
+ uniform vec3 probesMax;
1405
+ uniform vec3 probesResolution;
1406
+ vec3 getLightProbeGridIrradiance( vec3 worldPos, vec3 worldNormal ) {
1407
+ vec3 res = probesResolution;
1408
+ vec3 gridRange = probesMax - probesMin;
1409
+ vec3 resMinusOne = res - 1.0;
1410
+ vec3 probeSpacing = gridRange / resMinusOne;
1411
+ vec3 samplePos = worldPos + worldNormal * probeSpacing * 0.5;
1412
+ vec3 uvw = clamp( ( samplePos - probesMin ) / gridRange, 0.0, 1.0 );
1413
+ uvw = uvw * resMinusOne / res + 0.5 / res;
1414
+ float nz = res.z;
1415
+ float paddedSlices = nz + 2.0;
1416
+ float atlasDepth = 7.0 * paddedSlices;
1417
+ float uvZBase = uvw.z * nz + 1.0;
1418
+ vec4 s0 = texture( probesSH, vec3( uvw.xy, ( uvZBase ) / atlasDepth ) );
1419
+ vec4 s1 = texture( probesSH, vec3( uvw.xy, ( uvZBase + paddedSlices ) / atlasDepth ) );
1420
+ vec4 s2 = texture( probesSH, vec3( uvw.xy, ( uvZBase + 2.0 * paddedSlices ) / atlasDepth ) );
1421
+ vec4 s3 = texture( probesSH, vec3( uvw.xy, ( uvZBase + 3.0 * paddedSlices ) / atlasDepth ) );
1422
+ vec4 s4 = texture( probesSH, vec3( uvw.xy, ( uvZBase + 4.0 * paddedSlices ) / atlasDepth ) );
1423
+ vec4 s5 = texture( probesSH, vec3( uvw.xy, ( uvZBase + 5.0 * paddedSlices ) / atlasDepth ) );
1424
+ vec4 s6 = texture( probesSH, vec3( uvw.xy, ( uvZBase + 6.0 * paddedSlices ) / atlasDepth ) );
1425
+ vec3 c0 = s0.xyz;
1426
+ vec3 c1 = vec3( s0.w, s1.xy );
1427
+ vec3 c2 = vec3( s1.zw, s2.x );
1428
+ vec3 c3 = s2.yzw;
1429
+ vec3 c4 = s3.xyz;
1430
+ vec3 c5 = vec3( s3.w, s4.xy );
1431
+ vec3 c6 = vec3( s4.zw, s5.x );
1432
+ vec3 c7 = s5.yzw;
1433
+ vec3 c8 = s6.xyz;
1434
+ float x = worldNormal.x, y = worldNormal.y, z = worldNormal.z;
1435
+ vec3 result = c0 * 0.886227;
1436
+ result += c1 * 2.0 * 0.511664 * y;
1437
+ result += c2 * 2.0 * 0.511664 * z;
1438
+ result += c3 * 2.0 * 0.511664 * x;
1439
+ result += c4 * 2.0 * 0.429043 * x * y;
1440
+ result += c5 * 2.0 * 0.429043 * y * z;
1441
+ result += c6 * ( 0.743125 * z * z - 0.247708 );
1442
+ result += c7 * 2.0 * 0.429043 * x * z;
1443
+ result += c8 * 0.429043 * ( x * x - y * y );
1444
+ return max( result, vec3( 0.0 ) );
1445
+ }
1446
+ #endif`,logdepthbuf_fragment:`#if defined( USE_LOGARITHMIC_DEPTH_BUFFER )
1447
+ gl_FragDepth = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;
1448
+ #endif`,logdepthbuf_pars_fragment:`#if defined( USE_LOGARITHMIC_DEPTH_BUFFER )
1449
+ uniform float logDepthBufFC;
1450
+ varying float vFragDepth;
1451
+ varying float vIsPerspective;
1452
+ #endif`,logdepthbuf_pars_vertex:`#ifdef USE_LOGARITHMIC_DEPTH_BUFFER
1453
+ varying float vFragDepth;
1454
+ varying float vIsPerspective;
1455
+ #endif`,logdepthbuf_vertex:`#ifdef USE_LOGARITHMIC_DEPTH_BUFFER
1456
+ vFragDepth = 1.0 + gl_Position.w;
1457
+ vIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );
1458
+ #endif`,map_fragment:`#ifdef USE_MAP
1459
+ vec4 sampledDiffuseColor = texture2D( map, vMapUv );
1460
+ #ifdef DECODE_VIDEO_TEXTURE
1461
+ sampledDiffuseColor = sRGBTransferEOTF( sampledDiffuseColor );
1462
+ #endif
1463
+ diffuseColor *= sampledDiffuseColor;
1464
+ #endif`,map_pars_fragment:`#ifdef USE_MAP
1465
+ uniform sampler2D map;
1466
+ #endif`,map_particle_fragment:`#if defined( USE_MAP ) || defined( USE_ALPHAMAP )
1467
+ #if defined( USE_POINTS_UV )
1468
+ vec2 uv = vUv;
1469
+ #else
1470
+ vec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;
1471
+ #endif
1472
+ #endif
1473
+ #ifdef USE_MAP
1474
+ diffuseColor *= texture2D( map, uv );
1475
+ #endif
1476
+ #ifdef USE_ALPHAMAP
1477
+ diffuseColor.a *= texture2D( alphaMap, uv ).g;
1478
+ #endif`,map_particle_pars_fragment:`#if defined( USE_POINTS_UV )
1479
+ varying vec2 vUv;
1480
+ #else
1481
+ #if defined( USE_MAP ) || defined( USE_ALPHAMAP )
1482
+ uniform mat3 uvTransform;
1483
+ #endif
1484
+ #endif
1485
+ #ifdef USE_MAP
1486
+ uniform sampler2D map;
1487
+ #endif
1488
+ #ifdef USE_ALPHAMAP
1489
+ uniform sampler2D alphaMap;
1490
+ #endif`,metalnessmap_fragment:`float metalnessFactor = metalness;
1491
+ #ifdef USE_METALNESSMAP
1492
+ vec4 texelMetalness = texture2D( metalnessMap, vMetalnessMapUv );
1493
+ metalnessFactor *= texelMetalness.b;
1494
+ #endif`,metalnessmap_pars_fragment:`#ifdef USE_METALNESSMAP
1495
+ uniform sampler2D metalnessMap;
1496
+ #endif`,morphinstance_vertex:`#ifdef USE_INSTANCING_MORPH
1497
+ float morphTargetInfluences[ MORPHTARGETS_COUNT ];
1498
+ float morphTargetBaseInfluence = texelFetch( morphTexture, ivec2( 0, gl_InstanceID ), 0 ).r;
1499
+ for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
1500
+ morphTargetInfluences[i] = texelFetch( morphTexture, ivec2( i + 1, gl_InstanceID ), 0 ).r;
1501
+ }
1502
+ #endif`,morphcolor_vertex:`#if defined( USE_MORPHCOLORS )
1503
+ vColor *= morphTargetBaseInfluence;
1504
+ for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
1505
+ #if defined( USE_COLOR_ALPHA )
1506
+ if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ) * morphTargetInfluences[ i ];
1507
+ #elif defined( USE_COLOR )
1508
+ if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ).rgb * morphTargetInfluences[ i ];
1509
+ #endif
1510
+ }
1511
+ #endif`,morphnormal_vertex:`#ifdef USE_MORPHNORMALS
1512
+ objectNormal *= morphTargetBaseInfluence;
1513
+ for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
1514
+ if ( morphTargetInfluences[ i ] != 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1 ).xyz * morphTargetInfluences[ i ];
1515
+ }
1516
+ #endif`,morphtarget_pars_vertex:`#ifdef USE_MORPHTARGETS
1517
+ #ifndef USE_INSTANCING_MORPH
1518
+ uniform float morphTargetBaseInfluence;
1519
+ uniform float morphTargetInfluences[ MORPHTARGETS_COUNT ];
1520
+ #endif
1521
+ uniform sampler2DArray morphTargetsTexture;
1522
+ uniform ivec2 morphTargetsTextureSize;
1523
+ vec4 getMorph( const in int vertexIndex, const in int morphTargetIndex, const in int offset ) {
1524
+ int texelIndex = vertexIndex * MORPHTARGETS_TEXTURE_STRIDE + offset;
1525
+ int y = texelIndex / morphTargetsTextureSize.x;
1526
+ int x = texelIndex - y * morphTargetsTextureSize.x;
1527
+ ivec3 morphUV = ivec3( x, y, morphTargetIndex );
1528
+ return texelFetch( morphTargetsTexture, morphUV, 0 );
1529
+ }
1530
+ #endif`,morphtarget_vertex:`#ifdef USE_MORPHTARGETS
1531
+ transformed *= morphTargetBaseInfluence;
1532
+ for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
1533
+ if ( morphTargetInfluences[ i ] != 0.0 ) transformed += getMorph( gl_VertexID, i, 0 ).xyz * morphTargetInfluences[ i ];
1534
+ }
1535
+ #endif`,normal_fragment_begin:`float faceDirection = gl_FrontFacing ? 1.0 : - 1.0;
1536
+ #ifdef FLAT_SHADED
1537
+ vec3 fdx = dFdx( vViewPosition );
1538
+ vec3 fdy = dFdy( vViewPosition );
1539
+ vec3 normal = normalize( cross( fdx, fdy ) );
1540
+ #else
1541
+ vec3 normal = normalize( vNormal );
1542
+ #ifdef DOUBLE_SIDED
1543
+ normal *= faceDirection;
1544
+ #endif
1545
+ #endif
1546
+ #if defined( USE_NORMALMAP_TANGENTSPACE ) || defined( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY )
1547
+ #ifdef USE_TANGENT
1548
+ mat3 tbn = mat3( normalize( vTangent ), normalize( vBitangent ), normal );
1549
+ #else
1550
+ mat3 tbn = getTangentFrame( - vViewPosition, normal,
1551
+ #if defined( USE_NORMALMAP )
1552
+ vNormalMapUv
1553
+ #elif defined( USE_CLEARCOAT_NORMALMAP )
1554
+ vClearcoatNormalMapUv
1555
+ #else
1556
+ vUv
1557
+ #endif
1558
+ );
1559
+ #endif
1560
+ #ifdef DOUBLE_SIDED
1561
+ tbn[0] *= faceDirection;
1562
+ tbn[1] *= faceDirection;
1563
+ #endif
1564
+ #endif
1565
+ #ifdef USE_CLEARCOAT_NORMALMAP
1566
+ #ifdef USE_TANGENT
1567
+ mat3 tbn2 = mat3( normalize( vTangent ), normalize( vBitangent ), normal );
1568
+ #else
1569
+ mat3 tbn2 = getTangentFrame( - vViewPosition, normal, vClearcoatNormalMapUv );
1570
+ #endif
1571
+ #ifdef DOUBLE_SIDED
1572
+ tbn2[0] *= faceDirection;
1573
+ tbn2[1] *= faceDirection;
1574
+ #endif
1575
+ #endif
1576
+ vec3 nonPerturbedNormal = normal;`,normal_fragment_maps:`#ifdef USE_NORMALMAP_OBJECTSPACE
1577
+ normal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;
1578
+ #ifdef FLIP_SIDED
1579
+ normal = - normal;
1580
+ #endif
1581
+ #ifdef DOUBLE_SIDED
1582
+ normal = normal * faceDirection;
1583
+ #endif
1584
+ normal = normalize( normalMatrix * normal );
1585
+ #elif defined( USE_NORMALMAP_TANGENTSPACE )
1586
+ vec3 mapN = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;
1587
+ #if defined( USE_PACKED_NORMALMAP )
1588
+ mapN = vec3( mapN.xy, sqrt( saturate( 1.0 - dot( mapN.xy, mapN.xy ) ) ) );
1589
+ #endif
1590
+ mapN.xy *= normalScale;
1591
+ normal = normalize( tbn * mapN );
1592
+ #elif defined( USE_BUMPMAP )
1593
+ normal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection );
1594
+ #endif`,normal_pars_fragment:`#ifndef FLAT_SHADED
1595
+ varying vec3 vNormal;
1596
+ #ifdef USE_TANGENT
1597
+ varying vec3 vTangent;
1598
+ varying vec3 vBitangent;
1599
+ #endif
1600
+ #endif`,normal_pars_vertex:`#ifndef FLAT_SHADED
1601
+ varying vec3 vNormal;
1602
+ #ifdef USE_TANGENT
1603
+ varying vec3 vTangent;
1604
+ varying vec3 vBitangent;
1605
+ #endif
1606
+ #endif`,normal_vertex:`#ifndef FLAT_SHADED
1607
+ vNormal = normalize( transformedNormal );
1608
+ #ifdef USE_TANGENT
1609
+ vTangent = normalize( transformedTangent );
1610
+ vBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );
1611
+ #ifdef FLIP_SIDED
1612
+ vBitangent = - vBitangent;
1613
+ #endif
1614
+ #endif
1615
+ #endif`,normalmap_pars_fragment:`#ifdef USE_NORMALMAP
1616
+ uniform sampler2D normalMap;
1617
+ uniform vec2 normalScale;
1618
+ #endif
1619
+ #ifdef USE_NORMALMAP_OBJECTSPACE
1620
+ uniform mat3 normalMatrix;
1621
+ #endif
1622
+ #if ! defined ( USE_TANGENT ) && ( defined ( USE_NORMALMAP_TANGENTSPACE ) || defined ( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY ) )
1623
+ mat3 getTangentFrame( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {
1624
+ vec3 q0 = dFdx( eye_pos.xyz );
1625
+ vec3 q1 = dFdy( eye_pos.xyz );
1626
+ vec2 st0 = dFdx( uv.st );
1627
+ vec2 st1 = dFdy( uv.st );
1628
+ vec3 N = surf_norm;
1629
+ vec3 q1perp = cross( q1, N );
1630
+ vec3 q0perp = cross( N, q0 );
1631
+ vec3 T = q1perp * st0.x + q0perp * st1.x;
1632
+ vec3 B = q1perp * st0.y + q0perp * st1.y;
1633
+ float det = max( dot( T, T ), dot( B, B ) );
1634
+ float scale = ( det == 0.0 ) ? 0.0 : inversesqrt( det );
1635
+ return mat3( T * scale, B * scale, N );
1636
+ }
1637
+ #endif`,clearcoat_normal_fragment_begin:`#ifdef USE_CLEARCOAT
1638
+ vec3 clearcoatNormal = nonPerturbedNormal;
1639
+ #endif`,clearcoat_normal_fragment_maps:`#ifdef USE_CLEARCOAT_NORMALMAP
1640
+ vec3 clearcoatMapN = texture2D( clearcoatNormalMap, vClearcoatNormalMapUv ).xyz * 2.0 - 1.0;
1641
+ clearcoatMapN.xy *= clearcoatNormalScale;
1642
+ clearcoatNormal = normalize( tbn2 * clearcoatMapN );
1643
+ #endif`,clearcoat_pars_fragment:`#ifdef USE_CLEARCOATMAP
1644
+ uniform sampler2D clearcoatMap;
1645
+ #endif
1646
+ #ifdef USE_CLEARCOAT_NORMALMAP
1647
+ uniform sampler2D clearcoatNormalMap;
1648
+ uniform vec2 clearcoatNormalScale;
1649
+ #endif
1650
+ #ifdef USE_CLEARCOAT_ROUGHNESSMAP
1651
+ uniform sampler2D clearcoatRoughnessMap;
1652
+ #endif`,iridescence_pars_fragment:`#ifdef USE_IRIDESCENCEMAP
1653
+ uniform sampler2D iridescenceMap;
1654
+ #endif
1655
+ #ifdef USE_IRIDESCENCE_THICKNESSMAP
1656
+ uniform sampler2D iridescenceThicknessMap;
1657
+ #endif`,opaque_fragment:`#ifdef OPAQUE
1658
+ diffuseColor.a = 1.0;
1659
+ #endif
1660
+ #ifdef USE_TRANSMISSION
1661
+ diffuseColor.a *= material.transmissionAlpha;
1662
+ #endif
1663
+ gl_FragColor = vec4( outgoingLight, diffuseColor.a );`,packing:`vec3 packNormalToRGB( const in vec3 normal ) {
1664
+ return normalize( normal ) * 0.5 + 0.5;
1665
+ }
1666
+ vec3 unpackRGBToNormal( const in vec3 rgb ) {
1667
+ return 2.0 * rgb.xyz - 1.0;
1668
+ }
1669
+ const float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;const float ShiftRight8 = 1. / 256.;
1670
+ const float Inv255 = 1. / 255.;
1671
+ const vec4 PackFactors = vec4( 1.0, 256.0, 256.0 * 256.0, 256.0 * 256.0 * 256.0 );
1672
+ const vec2 UnpackFactors2 = vec2( UnpackDownscale, 1.0 / PackFactors.g );
1673
+ const vec3 UnpackFactors3 = vec3( UnpackDownscale / PackFactors.rg, 1.0 / PackFactors.b );
1674
+ const vec4 UnpackFactors4 = vec4( UnpackDownscale / PackFactors.rgb, 1.0 / PackFactors.a );
1675
+ vec4 packDepthToRGBA( const in float v ) {
1676
+ if( v <= 0.0 )
1677
+ return vec4( 0., 0., 0., 0. );
1678
+ if( v >= 1.0 )
1679
+ return vec4( 1., 1., 1., 1. );
1680
+ float vuf;
1681
+ float af = modf( v * PackFactors.a, vuf );
1682
+ float bf = modf( vuf * ShiftRight8, vuf );
1683
+ float gf = modf( vuf * ShiftRight8, vuf );
1684
+ return vec4( vuf * Inv255, gf * PackUpscale, bf * PackUpscale, af );
1685
+ }
1686
+ vec3 packDepthToRGB( const in float v ) {
1687
+ if( v <= 0.0 )
1688
+ return vec3( 0., 0., 0. );
1689
+ if( v >= 1.0 )
1690
+ return vec3( 1., 1., 1. );
1691
+ float vuf;
1692
+ float bf = modf( v * PackFactors.b, vuf );
1693
+ float gf = modf( vuf * ShiftRight8, vuf );
1694
+ return vec3( vuf * Inv255, gf * PackUpscale, bf );
1695
+ }
1696
+ vec2 packDepthToRG( const in float v ) {
1697
+ if( v <= 0.0 )
1698
+ return vec2( 0., 0. );
1699
+ if( v >= 1.0 )
1700
+ return vec2( 1., 1. );
1701
+ float vuf;
1702
+ float gf = modf( v * 256., vuf );
1703
+ return vec2( vuf * Inv255, gf );
1704
+ }
1705
+ float unpackRGBAToDepth( const in vec4 v ) {
1706
+ return dot( v, UnpackFactors4 );
1707
+ }
1708
+ float unpackRGBToDepth( const in vec3 v ) {
1709
+ return dot( v, UnpackFactors3 );
1710
+ }
1711
+ float unpackRGToDepth( const in vec2 v ) {
1712
+ return v.r * UnpackFactors2.r + v.g * UnpackFactors2.g;
1713
+ }
1714
+ vec4 pack2HalfToRGBA( const in vec2 v ) {
1715
+ vec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ) );
1716
+ return vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w );
1717
+ }
1718
+ vec2 unpackRGBATo2Half( const in vec4 v ) {
1719
+ return vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );
1720
+ }
1721
+ float viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {
1722
+ return ( viewZ + near ) / ( near - far );
1723
+ }
1724
+ float orthographicDepthToViewZ( const in float depth, const in float near, const in float far ) {
1725
+ #ifdef USE_REVERSED_DEPTH_BUFFER
1726
+
1727
+ return depth * ( far - near ) - far;
1728
+ #else
1729
+ return depth * ( near - far ) - near;
1730
+ #endif
1731
+ }
1732
+ float viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {
1733
+ return ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ );
1734
+ }
1735
+ float perspectiveDepthToViewZ( const in float depth, const in float near, const in float far ) {
1736
+
1737
+ #ifdef USE_REVERSED_DEPTH_BUFFER
1738
+ return ( near * far ) / ( ( near - far ) * depth - near );
1739
+ #else
1740
+ return ( near * far ) / ( ( far - near ) * depth - far );
1741
+ #endif
1742
+ }`,premultiplied_alpha_fragment:`#ifdef PREMULTIPLIED_ALPHA
1743
+ gl_FragColor.rgb *= gl_FragColor.a;
1744
+ #endif`,project_vertex:`vec4 mvPosition = vec4( transformed, 1.0 );
1745
+ #ifdef USE_BATCHING
1746
+ mvPosition = batchingMatrix * mvPosition;
1747
+ #endif
1748
+ #ifdef USE_INSTANCING
1749
+ mvPosition = instanceMatrix * mvPosition;
1750
+ #endif
1751
+ mvPosition = modelViewMatrix * mvPosition;
1752
+ gl_Position = projectionMatrix * mvPosition;`,dithering_fragment:`#ifdef DITHERING
1753
+ gl_FragColor.rgb = dithering( gl_FragColor.rgb );
1754
+ #endif`,dithering_pars_fragment:`#ifdef DITHERING
1755
+ vec3 dithering( vec3 color ) {
1756
+ float grid_position = rand( gl_FragCoord.xy );
1757
+ vec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );
1758
+ dither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );
1759
+ return color + dither_shift_RGB;
1760
+ }
1761
+ #endif`,roughnessmap_fragment:`float roughnessFactor = roughness;
1762
+ #ifdef USE_ROUGHNESSMAP
1763
+ vec4 texelRoughness = texture2D( roughnessMap, vRoughnessMapUv );
1764
+ roughnessFactor *= texelRoughness.g;
1765
+ #endif`,roughnessmap_pars_fragment:`#ifdef USE_ROUGHNESSMAP
1766
+ uniform sampler2D roughnessMap;
1767
+ #endif`,shadowmap_pars_fragment:`#if NUM_SPOT_LIGHT_COORDS > 0
1768
+ varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];
1769
+ #endif
1770
+ #if NUM_SPOT_LIGHT_MAPS > 0
1771
+ uniform sampler2D spotLightMap[ NUM_SPOT_LIGHT_MAPS ];
1772
+ #endif
1773
+ #ifdef USE_SHADOWMAP
1774
+ #if NUM_DIR_LIGHT_SHADOWS > 0
1775
+ #if defined( SHADOWMAP_TYPE_PCF )
1776
+ uniform sampler2DShadow directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];
1777
+ #else
1778
+ uniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];
1779
+ #endif
1780
+ varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];
1781
+ struct DirectionalLightShadow {
1782
+ float shadowIntensity;
1783
+ float shadowBias;
1784
+ float shadowNormalBias;
1785
+ float shadowRadius;
1786
+ vec2 shadowMapSize;
1787
+ };
1788
+ uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];
1789
+ #endif
1790
+ #if NUM_SPOT_LIGHT_SHADOWS > 0
1791
+ #if defined( SHADOWMAP_TYPE_PCF )
1792
+ uniform sampler2DShadow spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];
1793
+ #else
1794
+ uniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];
1795
+ #endif
1796
+ struct SpotLightShadow {
1797
+ float shadowIntensity;
1798
+ float shadowBias;
1799
+ float shadowNormalBias;
1800
+ float shadowRadius;
1801
+ vec2 shadowMapSize;
1802
+ };
1803
+ uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];
1804
+ #endif
1805
+ #if NUM_POINT_LIGHT_SHADOWS > 0
1806
+ #if defined( SHADOWMAP_TYPE_PCF )
1807
+ uniform samplerCubeShadow pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];
1808
+ #elif defined( SHADOWMAP_TYPE_BASIC )
1809
+ uniform samplerCube pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];
1810
+ #endif
1811
+ varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];
1812
+ struct PointLightShadow {
1813
+ float shadowIntensity;
1814
+ float shadowBias;
1815
+ float shadowNormalBias;
1816
+ float shadowRadius;
1817
+ vec2 shadowMapSize;
1818
+ float shadowCameraNear;
1819
+ float shadowCameraFar;
1820
+ };
1821
+ uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];
1822
+ #endif
1823
+ #if defined( SHADOWMAP_TYPE_PCF )
1824
+ float interleavedGradientNoise( vec2 position ) {
1825
+ return fract( 52.9829189 * fract( dot( position, vec2( 0.06711056, 0.00583715 ) ) ) );
1826
+ }
1827
+ vec2 vogelDiskSample( int sampleIndex, int samplesCount, float phi ) {
1828
+ const float goldenAngle = 2.399963229728653;
1829
+ float r = sqrt( ( float( sampleIndex ) + 0.5 ) / float( samplesCount ) );
1830
+ float theta = float( sampleIndex ) * goldenAngle + phi;
1831
+ return vec2( cos( theta ), sin( theta ) ) * r;
1832
+ }
1833
+ #endif
1834
+ #if defined( SHADOWMAP_TYPE_PCF )
1835
+ float getShadow( sampler2DShadow shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {
1836
+ float shadow = 1.0;
1837
+ shadowCoord.xyz /= shadowCoord.w;
1838
+ shadowCoord.z += shadowBias;
1839
+ bool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;
1840
+ bool frustumTest = inFrustum && shadowCoord.z <= 1.0;
1841
+ if ( frustumTest ) {
1842
+ vec2 texelSize = vec2( 1.0 ) / shadowMapSize;
1843
+ float radius = shadowRadius * texelSize.x;
1844
+ float phi = interleavedGradientNoise( gl_FragCoord.xy ) * PI2;
1845
+ shadow = (
1846
+ texture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 0, 5, phi ) * radius, shadowCoord.z ) ) +
1847
+ texture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 1, 5, phi ) * radius, shadowCoord.z ) ) +
1848
+ texture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 2, 5, phi ) * radius, shadowCoord.z ) ) +
1849
+ texture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 3, 5, phi ) * radius, shadowCoord.z ) ) +
1850
+ texture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 4, 5, phi ) * radius, shadowCoord.z ) )
1851
+ ) * 0.2;
1852
+ }
1853
+ return mix( 1.0, shadow, shadowIntensity );
1854
+ }
1855
+ #elif defined( SHADOWMAP_TYPE_VSM )
1856
+ float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {
1857
+ float shadow = 1.0;
1858
+ shadowCoord.xyz /= shadowCoord.w;
1859
+ #ifdef USE_REVERSED_DEPTH_BUFFER
1860
+ shadowCoord.z -= shadowBias;
1861
+ #else
1862
+ shadowCoord.z += shadowBias;
1863
+ #endif
1864
+ bool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;
1865
+ bool frustumTest = inFrustum && shadowCoord.z <= 1.0;
1866
+ if ( frustumTest ) {
1867
+ vec2 distribution = texture2D( shadowMap, shadowCoord.xy ).rg;
1868
+ float mean = distribution.x;
1869
+ float variance = distribution.y * distribution.y;
1870
+ #ifdef USE_REVERSED_DEPTH_BUFFER
1871
+ float hard_shadow = step( mean, shadowCoord.z );
1872
+ #else
1873
+ float hard_shadow = step( shadowCoord.z, mean );
1874
+ #endif
1875
+
1876
+ if ( hard_shadow == 1.0 ) {
1877
+ shadow = 1.0;
1878
+ } else {
1879
+ variance = max( variance, 0.0000001 );
1880
+ float d = shadowCoord.z - mean;
1881
+ float p_max = variance / ( variance + d * d );
1882
+ p_max = clamp( ( p_max - 0.3 ) / 0.65, 0.0, 1.0 );
1883
+ shadow = max( hard_shadow, p_max );
1884
+ }
1885
+ }
1886
+ return mix( 1.0, shadow, shadowIntensity );
1887
+ }
1888
+ #else
1889
+ float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {
1890
+ float shadow = 1.0;
1891
+ shadowCoord.xyz /= shadowCoord.w;
1892
+ #ifdef USE_REVERSED_DEPTH_BUFFER
1893
+ shadowCoord.z -= shadowBias;
1894
+ #else
1895
+ shadowCoord.z += shadowBias;
1896
+ #endif
1897
+ bool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;
1898
+ bool frustumTest = inFrustum && shadowCoord.z <= 1.0;
1899
+ if ( frustumTest ) {
1900
+ float depth = texture2D( shadowMap, shadowCoord.xy ).r;
1901
+ #ifdef USE_REVERSED_DEPTH_BUFFER
1902
+ shadow = step( depth, shadowCoord.z );
1903
+ #else
1904
+ shadow = step( shadowCoord.z, depth );
1905
+ #endif
1906
+ }
1907
+ return mix( 1.0, shadow, shadowIntensity );
1908
+ }
1909
+ #endif
1910
+ #if NUM_POINT_LIGHT_SHADOWS > 0
1911
+ #if defined( SHADOWMAP_TYPE_PCF )
1912
+ float getPointShadow( samplerCubeShadow shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {
1913
+ float shadow = 1.0;
1914
+ vec3 lightToPosition = shadowCoord.xyz;
1915
+ vec3 bd3D = normalize( lightToPosition );
1916
+ vec3 absVec = abs( lightToPosition );
1917
+ float viewSpaceZ = max( max( absVec.x, absVec.y ), absVec.z );
1918
+ if ( viewSpaceZ - shadowCameraFar <= 0.0 && viewSpaceZ - shadowCameraNear >= 0.0 ) {
1919
+ #ifdef USE_REVERSED_DEPTH_BUFFER
1920
+ float dp = ( shadowCameraNear * ( shadowCameraFar - viewSpaceZ ) ) / ( viewSpaceZ * ( shadowCameraFar - shadowCameraNear ) );
1921
+ dp -= shadowBias;
1922
+ #else
1923
+ float dp = ( shadowCameraFar * ( viewSpaceZ - shadowCameraNear ) ) / ( viewSpaceZ * ( shadowCameraFar - shadowCameraNear ) );
1924
+ dp += shadowBias;
1925
+ #endif
1926
+ float texelSize = shadowRadius / shadowMapSize.x;
1927
+ vec3 absDir = abs( bd3D );
1928
+ vec3 tangent = absDir.x > absDir.z ? vec3( 0.0, 1.0, 0.0 ) : vec3( 1.0, 0.0, 0.0 );
1929
+ tangent = normalize( cross( bd3D, tangent ) );
1930
+ vec3 bitangent = cross( bd3D, tangent );
1931
+ float phi = interleavedGradientNoise( gl_FragCoord.xy ) * PI2;
1932
+ vec2 sample0 = vogelDiskSample( 0, 5, phi );
1933
+ vec2 sample1 = vogelDiskSample( 1, 5, phi );
1934
+ vec2 sample2 = vogelDiskSample( 2, 5, phi );
1935
+ vec2 sample3 = vogelDiskSample( 3, 5, phi );
1936
+ vec2 sample4 = vogelDiskSample( 4, 5, phi );
1937
+ shadow = (
1938
+ texture( shadowMap, vec4( bd3D + ( tangent * sample0.x + bitangent * sample0.y ) * texelSize, dp ) ) +
1939
+ texture( shadowMap, vec4( bd3D + ( tangent * sample1.x + bitangent * sample1.y ) * texelSize, dp ) ) +
1940
+ texture( shadowMap, vec4( bd3D + ( tangent * sample2.x + bitangent * sample2.y ) * texelSize, dp ) ) +
1941
+ texture( shadowMap, vec4( bd3D + ( tangent * sample3.x + bitangent * sample3.y ) * texelSize, dp ) ) +
1942
+ texture( shadowMap, vec4( bd3D + ( tangent * sample4.x + bitangent * sample4.y ) * texelSize, dp ) )
1943
+ ) * 0.2;
1944
+ }
1945
+ return mix( 1.0, shadow, shadowIntensity );
1946
+ }
1947
+ #elif defined( SHADOWMAP_TYPE_BASIC )
1948
+ float getPointShadow( samplerCube shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {
1949
+ float shadow = 1.0;
1950
+ vec3 lightToPosition = shadowCoord.xyz;
1951
+ vec3 absVec = abs( lightToPosition );
1952
+ float viewSpaceZ = max( max( absVec.x, absVec.y ), absVec.z );
1953
+ if ( viewSpaceZ - shadowCameraFar <= 0.0 && viewSpaceZ - shadowCameraNear >= 0.0 ) {
1954
+ float dp = ( shadowCameraFar * ( viewSpaceZ - shadowCameraNear ) ) / ( viewSpaceZ * ( shadowCameraFar - shadowCameraNear ) );
1955
+ dp += shadowBias;
1956
+ vec3 bd3D = normalize( lightToPosition );
1957
+ float depth = textureCube( shadowMap, bd3D ).r;
1958
+ #ifdef USE_REVERSED_DEPTH_BUFFER
1959
+ depth = 1.0 - depth;
1960
+ #endif
1961
+ shadow = step( dp, depth );
1962
+ }
1963
+ return mix( 1.0, shadow, shadowIntensity );
1964
+ }
1965
+ #endif
1966
+ #endif
1967
+ #endif`,shadowmap_pars_vertex:`#if NUM_SPOT_LIGHT_COORDS > 0
1968
+ uniform mat4 spotLightMatrix[ NUM_SPOT_LIGHT_COORDS ];
1969
+ varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];
1970
+ #endif
1971
+ #ifdef USE_SHADOWMAP
1972
+ #if NUM_DIR_LIGHT_SHADOWS > 0
1973
+ uniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ];
1974
+ varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];
1975
+ struct DirectionalLightShadow {
1976
+ float shadowIntensity;
1977
+ float shadowBias;
1978
+ float shadowNormalBias;
1979
+ float shadowRadius;
1980
+ vec2 shadowMapSize;
1981
+ };
1982
+ uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];
1983
+ #endif
1984
+ #if NUM_SPOT_LIGHT_SHADOWS > 0
1985
+ struct SpotLightShadow {
1986
+ float shadowIntensity;
1987
+ float shadowBias;
1988
+ float shadowNormalBias;
1989
+ float shadowRadius;
1990
+ vec2 shadowMapSize;
1991
+ };
1992
+ uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];
1993
+ #endif
1994
+ #if NUM_POINT_LIGHT_SHADOWS > 0
1995
+ uniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ];
1996
+ varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];
1997
+ struct PointLightShadow {
1998
+ float shadowIntensity;
1999
+ float shadowBias;
2000
+ float shadowNormalBias;
2001
+ float shadowRadius;
2002
+ vec2 shadowMapSize;
2003
+ float shadowCameraNear;
2004
+ float shadowCameraFar;
2005
+ };
2006
+ uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];
2007
+ #endif
2008
+ #endif`,shadowmap_vertex:`#if ( defined( USE_SHADOWMAP ) && ( NUM_DIR_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0 ) ) || ( NUM_SPOT_LIGHT_COORDS > 0 )
2009
+ #ifdef HAS_NORMAL
2010
+ vec3 shadowWorldNormal = transformNormalByInverseViewMatrix( transformedNormal, viewMatrix );
2011
+ #else
2012
+ vec3 shadowWorldNormal = vec3( 0.0 );
2013
+ #endif
2014
+ vec4 shadowWorldPosition;
2015
+ #endif
2016
+ #if defined( USE_SHADOWMAP )
2017
+ #if NUM_DIR_LIGHT_SHADOWS > 0
2018
+ #pragma unroll_loop_start
2019
+ for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {
2020
+ shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 );
2021
+ vDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition;
2022
+ }
2023
+ #pragma unroll_loop_end
2024
+ #endif
2025
+ #if NUM_POINT_LIGHT_SHADOWS > 0
2026
+ #pragma unroll_loop_start
2027
+ for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {
2028
+ shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 );
2029
+ vPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition;
2030
+ }
2031
+ #pragma unroll_loop_end
2032
+ #endif
2033
+ #endif
2034
+ #if NUM_SPOT_LIGHT_COORDS > 0
2035
+ #pragma unroll_loop_start
2036
+ for ( int i = 0; i < NUM_SPOT_LIGHT_COORDS; i ++ ) {
2037
+ shadowWorldPosition = worldPosition;
2038
+ #if ( defined( USE_SHADOWMAP ) && UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
2039
+ shadowWorldPosition.xyz += shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias;
2040
+ #endif
2041
+ vSpotLightCoord[ i ] = spotLightMatrix[ i ] * shadowWorldPosition;
2042
+ }
2043
+ #pragma unroll_loop_end
2044
+ #endif`,shadowmask_pars_fragment:`float getShadowMask() {
2045
+ float shadow = 1.0;
2046
+ #ifdef USE_SHADOWMAP
2047
+ #if NUM_DIR_LIGHT_SHADOWS > 0
2048
+ DirectionalLightShadow directionalLight;
2049
+ #pragma unroll_loop_start
2050
+ for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {
2051
+ directionalLight = directionalLightShadows[ i ];
2052
+ shadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowIntensity, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
2053
+ }
2054
+ #pragma unroll_loop_end
2055
+ #endif
2056
+ #if NUM_SPOT_LIGHT_SHADOWS > 0
2057
+ SpotLightShadow spotLight;
2058
+ #pragma unroll_loop_start
2059
+ for ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {
2060
+ spotLight = spotLightShadows[ i ];
2061
+ shadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowIntensity, spotLight.shadowBias, spotLight.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;
2062
+ }
2063
+ #pragma unroll_loop_end
2064
+ #endif
2065
+ #if NUM_POINT_LIGHT_SHADOWS > 0 && ( defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_BASIC ) )
2066
+ PointLightShadow pointLight;
2067
+ #pragma unroll_loop_start
2068
+ for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {
2069
+ pointLight = pointLightShadows[ i ];
2070
+ shadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowIntensity, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;
2071
+ }
2072
+ #pragma unroll_loop_end
2073
+ #endif
2074
+ #endif
2075
+ return shadow;
2076
+ }`,skinbase_vertex:`#ifdef USE_SKINNING
2077
+ mat4 boneMatX = getBoneMatrix( skinIndex.x );
2078
+ mat4 boneMatY = getBoneMatrix( skinIndex.y );
2079
+ mat4 boneMatZ = getBoneMatrix( skinIndex.z );
2080
+ mat4 boneMatW = getBoneMatrix( skinIndex.w );
2081
+ #endif`,skinning_pars_vertex:`#ifdef USE_SKINNING
2082
+ uniform mat4 bindMatrix;
2083
+ uniform mat4 bindMatrixInverse;
2084
+ uniform highp sampler2D boneTexture;
2085
+ mat4 getBoneMatrix( const in float i ) {
2086
+ int size = textureSize( boneTexture, 0 ).x;
2087
+ int j = int( i ) * 4;
2088
+ int x = j % size;
2089
+ int y = j / size;
2090
+ vec4 v1 = texelFetch( boneTexture, ivec2( x, y ), 0 );
2091
+ vec4 v2 = texelFetch( boneTexture, ivec2( x + 1, y ), 0 );
2092
+ vec4 v3 = texelFetch( boneTexture, ivec2( x + 2, y ), 0 );
2093
+ vec4 v4 = texelFetch( boneTexture, ivec2( x + 3, y ), 0 );
2094
+ return mat4( v1, v2, v3, v4 );
2095
+ }
2096
+ #endif`,skinning_vertex:`#ifdef USE_SKINNING
2097
+ vec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );
2098
+ vec4 skinned = vec4( 0.0 );
2099
+ skinned += boneMatX * skinVertex * skinWeight.x;
2100
+ skinned += boneMatY * skinVertex * skinWeight.y;
2101
+ skinned += boneMatZ * skinVertex * skinWeight.z;
2102
+ skinned += boneMatW * skinVertex * skinWeight.w;
2103
+ transformed = ( bindMatrixInverse * skinned ).xyz;
2104
+ #endif`,skinnormal_vertex:`#ifdef USE_SKINNING
2105
+ mat4 skinMatrix = mat4( 0.0 );
2106
+ skinMatrix += skinWeight.x * boneMatX;
2107
+ skinMatrix += skinWeight.y * boneMatY;
2108
+ skinMatrix += skinWeight.z * boneMatZ;
2109
+ skinMatrix += skinWeight.w * boneMatW;
2110
+ skinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;
2111
+ objectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;
2112
+ #ifdef USE_TANGENT
2113
+ objectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz;
2114
+ #endif
2115
+ #endif`,specularmap_fragment:`float specularStrength;
2116
+ #ifdef USE_SPECULARMAP
2117
+ vec4 texelSpecular = texture2D( specularMap, vSpecularMapUv );
2118
+ specularStrength = texelSpecular.r;
2119
+ #else
2120
+ specularStrength = 1.0;
2121
+ #endif`,specularmap_pars_fragment:`#ifdef USE_SPECULARMAP
2122
+ uniform sampler2D specularMap;
2123
+ #endif`,tonemapping_fragment:`#if defined( TONE_MAPPING )
2124
+ gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );
2125
+ #endif`,tonemapping_pars_fragment:`#ifndef saturate
2126
+ #define saturate( a ) clamp( a, 0.0, 1.0 )
2127
+ #endif
2128
+ uniform float toneMappingExposure;
2129
+ vec3 LinearToneMapping( vec3 color ) {
2130
+ return saturate( toneMappingExposure * color );
2131
+ }
2132
+ vec3 ReinhardToneMapping( vec3 color ) {
2133
+ color *= toneMappingExposure;
2134
+ return saturate( color / ( vec3( 1.0 ) + color ) );
2135
+ }
2136
+ vec3 CineonToneMapping( vec3 color ) {
2137
+ color *= toneMappingExposure;
2138
+ color = max( vec3( 0.0 ), color - 0.004 );
2139
+ return pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );
2140
+ }
2141
+ vec3 RRTAndODTFit( vec3 v ) {
2142
+ vec3 a = v * ( v + 0.0245786 ) - 0.000090537;
2143
+ vec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081;
2144
+ return a / b;
2145
+ }
2146
+ vec3 ACESFilmicToneMapping( vec3 color ) {
2147
+ const mat3 ACESInputMat = mat3(
2148
+ vec3( 0.59719, 0.07600, 0.02840 ), vec3( 0.35458, 0.90834, 0.13383 ),
2149
+ vec3( 0.04823, 0.01566, 0.83777 )
2150
+ );
2151
+ const mat3 ACESOutputMat = mat3(
2152
+ vec3( 1.60475, -0.10208, -0.00327 ), vec3( -0.53108, 1.10813, -0.07276 ),
2153
+ vec3( -0.07367, -0.00605, 1.07602 )
2154
+ );
2155
+ color *= toneMappingExposure / 0.6;
2156
+ color = ACESInputMat * color;
2157
+ color = RRTAndODTFit( color );
2158
+ color = ACESOutputMat * color;
2159
+ return saturate( color );
2160
+ }
2161
+ const mat3 LINEAR_REC2020_TO_LINEAR_SRGB = mat3(
2162
+ vec3( 1.6605, - 0.1246, - 0.0182 ),
2163
+ vec3( - 0.5876, 1.1329, - 0.1006 ),
2164
+ vec3( - 0.0728, - 0.0083, 1.1187 )
2165
+ );
2166
+ const mat3 LINEAR_SRGB_TO_LINEAR_REC2020 = mat3(
2167
+ vec3( 0.6274, 0.0691, 0.0164 ),
2168
+ vec3( 0.3293, 0.9195, 0.0880 ),
2169
+ vec3( 0.0433, 0.0113, 0.8956 )
2170
+ );
2171
+ vec3 agxDefaultContrastApprox( vec3 x ) {
2172
+ vec3 x2 = x * x;
2173
+ vec3 x4 = x2 * x2;
2174
+ return + 15.5 * x4 * x2
2175
+ - 40.14 * x4 * x
2176
+ + 31.96 * x4
2177
+ - 6.868 * x2 * x
2178
+ + 0.4298 * x2
2179
+ + 0.1191 * x
2180
+ - 0.00232;
2181
+ }
2182
+ vec3 AgXToneMapping( vec3 color ) {
2183
+ const mat3 AgXInsetMatrix = mat3(
2184
+ vec3( 0.856627153315983, 0.137318972929847, 0.11189821299995 ),
2185
+ vec3( 0.0951212405381588, 0.761241990602591, 0.0767994186031903 ),
2186
+ vec3( 0.0482516061458583, 0.101439036467562, 0.811302368396859 )
2187
+ );
2188
+ const mat3 AgXOutsetMatrix = mat3(
2189
+ vec3( 1.1271005818144368, - 0.1413297634984383, - 0.14132976349843826 ),
2190
+ vec3( - 0.11060664309660323, 1.157823702216272, - 0.11060664309660294 ),
2191
+ vec3( - 0.016493938717834573, - 0.016493938717834257, 1.2519364065950405 )
2192
+ );
2193
+ const float AgxMinEv = - 12.47393; const float AgxMaxEv = 4.026069;
2194
+ color *= toneMappingExposure;
2195
+ color = LINEAR_SRGB_TO_LINEAR_REC2020 * color;
2196
+ color = AgXInsetMatrix * color;
2197
+ color = max( color, 1e-10 ); color = log2( color );
2198
+ color = ( color - AgxMinEv ) / ( AgxMaxEv - AgxMinEv );
2199
+ color = clamp( color, 0.0, 1.0 );
2200
+ color = agxDefaultContrastApprox( color );
2201
+ color = AgXOutsetMatrix * color;
2202
+ color = pow( max( vec3( 0.0 ), color ), vec3( 2.2 ) );
2203
+ color = LINEAR_REC2020_TO_LINEAR_SRGB * color;
2204
+ color = clamp( color, 0.0, 1.0 );
2205
+ return color;
2206
+ }
2207
+ vec3 NeutralToneMapping( vec3 color ) {
2208
+ const float StartCompression = 0.8 - 0.04;
2209
+ const float Desaturation = 0.15;
2210
+ color *= toneMappingExposure;
2211
+ float x = min( color.r, min( color.g, color.b ) );
2212
+ float offset = x < 0.08 ? x - 6.25 * x * x : 0.04;
2213
+ color -= offset;
2214
+ float peak = max( color.r, max( color.g, color.b ) );
2215
+ if ( peak < StartCompression ) return color;
2216
+ float d = 1. - StartCompression;
2217
+ float newPeak = 1. - d * d / ( peak + d - StartCompression );
2218
+ color *= newPeak / peak;
2219
+ float g = 1. - 1. / ( Desaturation * ( peak - newPeak ) + 1. );
2220
+ return mix( color, vec3( newPeak ), g );
2221
+ }
2222
+ vec3 CustomToneMapping( vec3 color ) { return color; }`,transmission_fragment:`#ifdef USE_TRANSMISSION
2223
+ material.transmission = transmission;
2224
+ material.transmissionAlpha = 1.0;
2225
+ material.thickness = thickness;
2226
+ material.attenuationDistance = attenuationDistance;
2227
+ material.attenuationColor = attenuationColor;
2228
+ #ifdef USE_TRANSMISSIONMAP
2229
+ material.transmission *= texture2D( transmissionMap, vTransmissionMapUv ).r;
2230
+ #endif
2231
+ #ifdef USE_THICKNESSMAP
2232
+ material.thickness *= texture2D( thicknessMap, vThicknessMapUv ).g;
2233
+ #endif
2234
+ vec3 pos = vWorldPosition;
2235
+ vec3 v = normalize( cameraPosition - pos );
2236
+ vec3 n = transformNormalByInverseViewMatrix( normal, viewMatrix );
2237
+ vec4 transmitted = getIBLVolumeRefraction(
2238
+ n, v, material.roughness, material.diffuseContribution, material.specularColorBlended, material.specularF90,
2239
+ pos, modelMatrix, viewMatrix, projectionMatrix, material.dispersion, material.ior, material.thickness,
2240
+ material.attenuationColor, material.attenuationDistance );
2241
+ material.transmissionAlpha = mix( material.transmissionAlpha, transmitted.a, material.transmission );
2242
+ totalDiffuse = mix( totalDiffuse, transmitted.rgb, material.transmission );
2243
+ #endif`,transmission_pars_fragment:`#ifdef USE_TRANSMISSION
2244
+ uniform float transmission;
2245
+ uniform float thickness;
2246
+ uniform float attenuationDistance;
2247
+ uniform vec3 attenuationColor;
2248
+ #ifdef USE_TRANSMISSIONMAP
2249
+ uniform sampler2D transmissionMap;
2250
+ #endif
2251
+ #ifdef USE_THICKNESSMAP
2252
+ uniform sampler2D thicknessMap;
2253
+ #endif
2254
+ uniform vec2 transmissionSamplerSize;
2255
+ uniform sampler2D transmissionSamplerMap;
2256
+ uniform mat4 modelMatrix;
2257
+ uniform mat4 projectionMatrix;
2258
+ varying vec3 vWorldPosition;
2259
+ float w0( float a ) {
2260
+ return ( 1.0 / 6.0 ) * ( a * ( a * ( - a + 3.0 ) - 3.0 ) + 1.0 );
2261
+ }
2262
+ float w1( float a ) {
2263
+ return ( 1.0 / 6.0 ) * ( a * a * ( 3.0 * a - 6.0 ) + 4.0 );
2264
+ }
2265
+ float w2( float a ){
2266
+ return ( 1.0 / 6.0 ) * ( a * ( a * ( - 3.0 * a + 3.0 ) + 3.0 ) + 1.0 );
2267
+ }
2268
+ float w3( float a ) {
2269
+ return ( 1.0 / 6.0 ) * ( a * a * a );
2270
+ }
2271
+ float g0( float a ) {
2272
+ return w0( a ) + w1( a );
2273
+ }
2274
+ float g1( float a ) {
2275
+ return w2( a ) + w3( a );
2276
+ }
2277
+ float h0( float a ) {
2278
+ return - 1.0 + w1( a ) / ( w0( a ) + w1( a ) );
2279
+ }
2280
+ float h1( float a ) {
2281
+ return 1.0 + w3( a ) / ( w2( a ) + w3( a ) );
2282
+ }
2283
+ vec4 bicubic( sampler2D tex, vec2 uv, vec4 texelSize, float lod ) {
2284
+ uv = uv * texelSize.zw + 0.5;
2285
+ vec2 iuv = floor( uv );
2286
+ vec2 fuv = fract( uv );
2287
+ float g0x = g0( fuv.x );
2288
+ float g1x = g1( fuv.x );
2289
+ float h0x = h0( fuv.x );
2290
+ float h1x = h1( fuv.x );
2291
+ float h0y = h0( fuv.y );
2292
+ float h1y = h1( fuv.y );
2293
+ vec2 p0 = ( vec2( iuv.x + h0x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;
2294
+ vec2 p1 = ( vec2( iuv.x + h1x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;
2295
+ vec2 p2 = ( vec2( iuv.x + h0x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;
2296
+ vec2 p3 = ( vec2( iuv.x + h1x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;
2297
+ return g0( fuv.y ) * ( g0x * textureLod( tex, p0, lod ) + g1x * textureLod( tex, p1, lod ) ) +
2298
+ g1( fuv.y ) * ( g0x * textureLod( tex, p2, lod ) + g1x * textureLod( tex, p3, lod ) );
2299
+ }
2300
+ vec4 textureBicubic( sampler2D sampler, vec2 uv, float lod ) {
2301
+ vec2 fLodSize = vec2( textureSize( sampler, int( lod ) ) );
2302
+ vec2 cLodSize = vec2( textureSize( sampler, int( lod + 1.0 ) ) );
2303
+ vec2 fLodSizeInv = 1.0 / fLodSize;
2304
+ vec2 cLodSizeInv = 1.0 / cLodSize;
2305
+ vec4 fSample = bicubic( sampler, uv, vec4( fLodSizeInv, fLodSize ), floor( lod ) );
2306
+ vec4 cSample = bicubic( sampler, uv, vec4( cLodSizeInv, cLodSize ), ceil( lod ) );
2307
+ return mix( fSample, cSample, fract( lod ) );
2308
+ }
2309
+ vec3 getVolumeTransmissionRay( const in vec3 n, const in vec3 v, const in float thickness, const in float ior, const in mat4 modelMatrix ) {
2310
+ vec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior );
2311
+ vec3 modelScale;
2312
+ modelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) );
2313
+ modelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) );
2314
+ modelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) );
2315
+ return normalize( refractionVector ) * thickness * modelScale;
2316
+ }
2317
+ float applyIorToRoughness( const in float roughness, const in float ior ) {
2318
+ return roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );
2319
+ }
2320
+ vec4 getTransmissionSample( const in vec2 fragCoord, const in float roughness, const in float ior ) {
2321
+ float lod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior );
2322
+ return textureBicubic( transmissionSamplerMap, fragCoord.xy, lod );
2323
+ }
2324
+ vec3 volumeAttenuation( const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) {
2325
+ if ( isinf( attenuationDistance ) ) {
2326
+ return vec3( 1.0 );
2327
+ } else {
2328
+ vec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance;
2329
+ vec3 transmittance = exp( - attenuationCoefficient * transmissionDistance ); return transmittance;
2330
+ }
2331
+ }
2332
+ vec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor,
2333
+ const in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix,
2334
+ const in mat4 viewMatrix, const in mat4 projMatrix, const in float dispersion, const in float ior, const in float thickness,
2335
+ const in vec3 attenuationColor, const in float attenuationDistance ) {
2336
+ vec4 transmittedLight;
2337
+ vec3 transmittance;
2338
+ #ifdef USE_DISPERSION
2339
+ float halfSpread = ( ior - 1.0 ) * 0.025 * dispersion;
2340
+ vec3 iors = vec3( ior - halfSpread, ior, ior + halfSpread );
2341
+ for ( int i = 0; i < 3; i ++ ) {
2342
+ vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, iors[ i ], modelMatrix );
2343
+ vec3 refractedRayExit = position + transmissionRay;
2344
+ vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );
2345
+ vec2 refractionCoords = ndcPos.xy / ndcPos.w;
2346
+ refractionCoords += 1.0;
2347
+ refractionCoords /= 2.0;
2348
+ vec4 transmissionSample = getTransmissionSample( refractionCoords, roughness, iors[ i ] );
2349
+ transmittedLight[ i ] = transmissionSample[ i ];
2350
+ transmittedLight.a += transmissionSample.a;
2351
+ transmittance[ i ] = diffuseColor[ i ] * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance )[ i ];
2352
+ }
2353
+ transmittedLight.a /= 3.0;
2354
+ #else
2355
+ vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );
2356
+ vec3 refractedRayExit = position + transmissionRay;
2357
+ vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );
2358
+ vec2 refractionCoords = ndcPos.xy / ndcPos.w;
2359
+ refractionCoords += 1.0;
2360
+ refractionCoords /= 2.0;
2361
+ transmittedLight = getTransmissionSample( refractionCoords, roughness, ior );
2362
+ transmittance = diffuseColor * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance );
2363
+ #endif
2364
+ vec3 attenuatedColor = transmittance * transmittedLight.rgb;
2365
+ vec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );
2366
+ float transmittanceFactor = ( transmittance.r + transmittance.g + transmittance.b ) / 3.0;
2367
+ return vec4( ( 1.0 - F ) * attenuatedColor, 1.0 - ( 1.0 - transmittedLight.a ) * transmittanceFactor );
2368
+ }
2369
+ #endif`,uv_pars_fragment:`#if defined( USE_UV ) || defined( USE_ANISOTROPY )
2370
+ varying vec2 vUv;
2371
+ #endif
2372
+ #ifdef USE_MAP
2373
+ varying vec2 vMapUv;
2374
+ #endif
2375
+ #ifdef USE_ALPHAMAP
2376
+ varying vec2 vAlphaMapUv;
2377
+ #endif
2378
+ #ifdef USE_LIGHTMAP
2379
+ varying vec2 vLightMapUv;
2380
+ #endif
2381
+ #ifdef USE_AOMAP
2382
+ varying vec2 vAoMapUv;
2383
+ #endif
2384
+ #ifdef USE_BUMPMAP
2385
+ varying vec2 vBumpMapUv;
2386
+ #endif
2387
+ #ifdef USE_NORMALMAP
2388
+ varying vec2 vNormalMapUv;
2389
+ #endif
2390
+ #ifdef USE_EMISSIVEMAP
2391
+ varying vec2 vEmissiveMapUv;
2392
+ #endif
2393
+ #ifdef USE_METALNESSMAP
2394
+ varying vec2 vMetalnessMapUv;
2395
+ #endif
2396
+ #ifdef USE_ROUGHNESSMAP
2397
+ varying vec2 vRoughnessMapUv;
2398
+ #endif
2399
+ #ifdef USE_ANISOTROPYMAP
2400
+ varying vec2 vAnisotropyMapUv;
2401
+ #endif
2402
+ #ifdef USE_CLEARCOATMAP
2403
+ varying vec2 vClearcoatMapUv;
2404
+ #endif
2405
+ #ifdef USE_CLEARCOAT_NORMALMAP
2406
+ varying vec2 vClearcoatNormalMapUv;
2407
+ #endif
2408
+ #ifdef USE_CLEARCOAT_ROUGHNESSMAP
2409
+ varying vec2 vClearcoatRoughnessMapUv;
2410
+ #endif
2411
+ #ifdef USE_IRIDESCENCEMAP
2412
+ varying vec2 vIridescenceMapUv;
2413
+ #endif
2414
+ #ifdef USE_IRIDESCENCE_THICKNESSMAP
2415
+ varying vec2 vIridescenceThicknessMapUv;
2416
+ #endif
2417
+ #ifdef USE_SHEEN_COLORMAP
2418
+ varying vec2 vSheenColorMapUv;
2419
+ #endif
2420
+ #ifdef USE_SHEEN_ROUGHNESSMAP
2421
+ varying vec2 vSheenRoughnessMapUv;
2422
+ #endif
2423
+ #ifdef USE_SPECULARMAP
2424
+ varying vec2 vSpecularMapUv;
2425
+ #endif
2426
+ #ifdef USE_SPECULAR_COLORMAP
2427
+ varying vec2 vSpecularColorMapUv;
2428
+ #endif
2429
+ #ifdef USE_SPECULAR_INTENSITYMAP
2430
+ varying vec2 vSpecularIntensityMapUv;
2431
+ #endif
2432
+ #ifdef USE_TRANSMISSIONMAP
2433
+ uniform mat3 transmissionMapTransform;
2434
+ varying vec2 vTransmissionMapUv;
2435
+ #endif
2436
+ #ifdef USE_THICKNESSMAP
2437
+ uniform mat3 thicknessMapTransform;
2438
+ varying vec2 vThicknessMapUv;
2439
+ #endif`,uv_pars_vertex:`#if defined( USE_UV ) || defined( USE_ANISOTROPY )
2440
+ varying vec2 vUv;
2441
+ #endif
2442
+ #ifdef USE_MAP
2443
+ uniform mat3 mapTransform;
2444
+ varying vec2 vMapUv;
2445
+ #endif
2446
+ #ifdef USE_ALPHAMAP
2447
+ uniform mat3 alphaMapTransform;
2448
+ varying vec2 vAlphaMapUv;
2449
+ #endif
2450
+ #ifdef USE_LIGHTMAP
2451
+ uniform mat3 lightMapTransform;
2452
+ varying vec2 vLightMapUv;
2453
+ #endif
2454
+ #ifdef USE_AOMAP
2455
+ uniform mat3 aoMapTransform;
2456
+ varying vec2 vAoMapUv;
2457
+ #endif
2458
+ #ifdef USE_BUMPMAP
2459
+ uniform mat3 bumpMapTransform;
2460
+ varying vec2 vBumpMapUv;
2461
+ #endif
2462
+ #ifdef USE_NORMALMAP
2463
+ uniform mat3 normalMapTransform;
2464
+ varying vec2 vNormalMapUv;
2465
+ #endif
2466
+ #ifdef USE_DISPLACEMENTMAP
2467
+ uniform mat3 displacementMapTransform;
2468
+ varying vec2 vDisplacementMapUv;
2469
+ #endif
2470
+ #ifdef USE_EMISSIVEMAP
2471
+ uniform mat3 emissiveMapTransform;
2472
+ varying vec2 vEmissiveMapUv;
2473
+ #endif
2474
+ #ifdef USE_METALNESSMAP
2475
+ uniform mat3 metalnessMapTransform;
2476
+ varying vec2 vMetalnessMapUv;
2477
+ #endif
2478
+ #ifdef USE_ROUGHNESSMAP
2479
+ uniform mat3 roughnessMapTransform;
2480
+ varying vec2 vRoughnessMapUv;
2481
+ #endif
2482
+ #ifdef USE_ANISOTROPYMAP
2483
+ uniform mat3 anisotropyMapTransform;
2484
+ varying vec2 vAnisotropyMapUv;
2485
+ #endif
2486
+ #ifdef USE_CLEARCOATMAP
2487
+ uniform mat3 clearcoatMapTransform;
2488
+ varying vec2 vClearcoatMapUv;
2489
+ #endif
2490
+ #ifdef USE_CLEARCOAT_NORMALMAP
2491
+ uniform mat3 clearcoatNormalMapTransform;
2492
+ varying vec2 vClearcoatNormalMapUv;
2493
+ #endif
2494
+ #ifdef USE_CLEARCOAT_ROUGHNESSMAP
2495
+ uniform mat3 clearcoatRoughnessMapTransform;
2496
+ varying vec2 vClearcoatRoughnessMapUv;
2497
+ #endif
2498
+ #ifdef USE_SHEEN_COLORMAP
2499
+ uniform mat3 sheenColorMapTransform;
2500
+ varying vec2 vSheenColorMapUv;
2501
+ #endif
2502
+ #ifdef USE_SHEEN_ROUGHNESSMAP
2503
+ uniform mat3 sheenRoughnessMapTransform;
2504
+ varying vec2 vSheenRoughnessMapUv;
2505
+ #endif
2506
+ #ifdef USE_IRIDESCENCEMAP
2507
+ uniform mat3 iridescenceMapTransform;
2508
+ varying vec2 vIridescenceMapUv;
2509
+ #endif
2510
+ #ifdef USE_IRIDESCENCE_THICKNESSMAP
2511
+ uniform mat3 iridescenceThicknessMapTransform;
2512
+ varying vec2 vIridescenceThicknessMapUv;
2513
+ #endif
2514
+ #ifdef USE_SPECULARMAP
2515
+ uniform mat3 specularMapTransform;
2516
+ varying vec2 vSpecularMapUv;
2517
+ #endif
2518
+ #ifdef USE_SPECULAR_COLORMAP
2519
+ uniform mat3 specularColorMapTransform;
2520
+ varying vec2 vSpecularColorMapUv;
2521
+ #endif
2522
+ #ifdef USE_SPECULAR_INTENSITYMAP
2523
+ uniform mat3 specularIntensityMapTransform;
2524
+ varying vec2 vSpecularIntensityMapUv;
2525
+ #endif
2526
+ #ifdef USE_TRANSMISSIONMAP
2527
+ uniform mat3 transmissionMapTransform;
2528
+ varying vec2 vTransmissionMapUv;
2529
+ #endif
2530
+ #ifdef USE_THICKNESSMAP
2531
+ uniform mat3 thicknessMapTransform;
2532
+ varying vec2 vThicknessMapUv;
2533
+ #endif`,uv_vertex:`#if defined( USE_UV ) || defined( USE_ANISOTROPY )
2534
+ vUv = vec3( uv, 1 ).xy;
2535
+ #endif
2536
+ #ifdef USE_MAP
2537
+ vMapUv = ( mapTransform * vec3( MAP_UV, 1 ) ).xy;
2538
+ #endif
2539
+ #ifdef USE_ALPHAMAP
2540
+ vAlphaMapUv = ( alphaMapTransform * vec3( ALPHAMAP_UV, 1 ) ).xy;
2541
+ #endif
2542
+ #ifdef USE_LIGHTMAP
2543
+ vLightMapUv = ( lightMapTransform * vec3( LIGHTMAP_UV, 1 ) ).xy;
2544
+ #endif
2545
+ #ifdef USE_AOMAP
2546
+ vAoMapUv = ( aoMapTransform * vec3( AOMAP_UV, 1 ) ).xy;
2547
+ #endif
2548
+ #ifdef USE_BUMPMAP
2549
+ vBumpMapUv = ( bumpMapTransform * vec3( BUMPMAP_UV, 1 ) ).xy;
2550
+ #endif
2551
+ #ifdef USE_NORMALMAP
2552
+ vNormalMapUv = ( normalMapTransform * vec3( NORMALMAP_UV, 1 ) ).xy;
2553
+ #endif
2554
+ #ifdef USE_DISPLACEMENTMAP
2555
+ vDisplacementMapUv = ( displacementMapTransform * vec3( DISPLACEMENTMAP_UV, 1 ) ).xy;
2556
+ #endif
2557
+ #ifdef USE_EMISSIVEMAP
2558
+ vEmissiveMapUv = ( emissiveMapTransform * vec3( EMISSIVEMAP_UV, 1 ) ).xy;
2559
+ #endif
2560
+ #ifdef USE_METALNESSMAP
2561
+ vMetalnessMapUv = ( metalnessMapTransform * vec3( METALNESSMAP_UV, 1 ) ).xy;
2562
+ #endif
2563
+ #ifdef USE_ROUGHNESSMAP
2564
+ vRoughnessMapUv = ( roughnessMapTransform * vec3( ROUGHNESSMAP_UV, 1 ) ).xy;
2565
+ #endif
2566
+ #ifdef USE_ANISOTROPYMAP
2567
+ vAnisotropyMapUv = ( anisotropyMapTransform * vec3( ANISOTROPYMAP_UV, 1 ) ).xy;
2568
+ #endif
2569
+ #ifdef USE_CLEARCOATMAP
2570
+ vClearcoatMapUv = ( clearcoatMapTransform * vec3( CLEARCOATMAP_UV, 1 ) ).xy;
2571
+ #endif
2572
+ #ifdef USE_CLEARCOAT_NORMALMAP
2573
+ vClearcoatNormalMapUv = ( clearcoatNormalMapTransform * vec3( CLEARCOAT_NORMALMAP_UV, 1 ) ).xy;
2574
+ #endif
2575
+ #ifdef USE_CLEARCOAT_ROUGHNESSMAP
2576
+ vClearcoatRoughnessMapUv = ( clearcoatRoughnessMapTransform * vec3( CLEARCOAT_ROUGHNESSMAP_UV, 1 ) ).xy;
2577
+ #endif
2578
+ #ifdef USE_IRIDESCENCEMAP
2579
+ vIridescenceMapUv = ( iridescenceMapTransform * vec3( IRIDESCENCEMAP_UV, 1 ) ).xy;
2580
+ #endif
2581
+ #ifdef USE_IRIDESCENCE_THICKNESSMAP
2582
+ vIridescenceThicknessMapUv = ( iridescenceThicknessMapTransform * vec3( IRIDESCENCE_THICKNESSMAP_UV, 1 ) ).xy;
2583
+ #endif
2584
+ #ifdef USE_SHEEN_COLORMAP
2585
+ vSheenColorMapUv = ( sheenColorMapTransform * vec3( SHEEN_COLORMAP_UV, 1 ) ).xy;
2586
+ #endif
2587
+ #ifdef USE_SHEEN_ROUGHNESSMAP
2588
+ vSheenRoughnessMapUv = ( sheenRoughnessMapTransform * vec3( SHEEN_ROUGHNESSMAP_UV, 1 ) ).xy;
2589
+ #endif
2590
+ #ifdef USE_SPECULARMAP
2591
+ vSpecularMapUv = ( specularMapTransform * vec3( SPECULARMAP_UV, 1 ) ).xy;
2592
+ #endif
2593
+ #ifdef USE_SPECULAR_COLORMAP
2594
+ vSpecularColorMapUv = ( specularColorMapTransform * vec3( SPECULAR_COLORMAP_UV, 1 ) ).xy;
2595
+ #endif
2596
+ #ifdef USE_SPECULAR_INTENSITYMAP
2597
+ vSpecularIntensityMapUv = ( specularIntensityMapTransform * vec3( SPECULAR_INTENSITYMAP_UV, 1 ) ).xy;
2598
+ #endif
2599
+ #ifdef USE_TRANSMISSIONMAP
2600
+ vTransmissionMapUv = ( transmissionMapTransform * vec3( TRANSMISSIONMAP_UV, 1 ) ).xy;
2601
+ #endif
2602
+ #ifdef USE_THICKNESSMAP
2603
+ vThicknessMapUv = ( thicknessMapTransform * vec3( THICKNESSMAP_UV, 1 ) ).xy;
2604
+ #endif`,worldpos_vertex:`#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ) || defined ( USE_TRANSMISSION ) || NUM_SPOT_LIGHT_COORDS > 0
2605
+ vec4 worldPosition = vec4( transformed, 1.0 );
2606
+ #ifdef USE_BATCHING
2607
+ worldPosition = batchingMatrix * worldPosition;
2608
+ #endif
2609
+ #ifdef USE_INSTANCING
2610
+ worldPosition = instanceMatrix * worldPosition;
2611
+ #endif
2612
+ worldPosition = modelMatrix * worldPosition;
2613
+ #endif`,background_vert:`varying vec2 vUv;
2614
+ uniform mat3 uvTransform;
2615
+ void main() {
2616
+ vUv = ( uvTransform * vec3( uv, 1 ) ).xy;
2617
+ gl_Position = vec4( position.xy, 1.0, 1.0 );
2618
+ }`,background_frag:`uniform sampler2D t2D;
2619
+ uniform float backgroundIntensity;
2620
+ varying vec2 vUv;
2621
+ void main() {
2622
+ vec4 texColor = texture2D( t2D, vUv );
2623
+ #ifdef DECODE_VIDEO_TEXTURE
2624
+ texColor = vec4( mix( pow( texColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), texColor.rgb * 0.0773993808, vec3( lessThanEqual( texColor.rgb, vec3( 0.04045 ) ) ) ), texColor.w );
2625
+ #endif
2626
+ texColor.rgb *= backgroundIntensity;
2627
+ gl_FragColor = texColor;
2628
+ #include <tonemapping_fragment>
2629
+ #include <colorspace_fragment>
2630
+ }`,backgroundCube_vert:`varying vec3 vWorldDirection;
2631
+ #include <common>
2632
+ void main() {
2633
+ vWorldDirection = transformDirection( position, modelMatrix );
2634
+ #include <begin_vertex>
2635
+ #include <project_vertex>
2636
+ gl_Position.z = gl_Position.w;
2637
+ }`,backgroundCube_frag:`#ifdef ENVMAP_TYPE_CUBE
2638
+ uniform samplerCube envMap;
2639
+ #elif defined( ENVMAP_TYPE_CUBE_UV )
2640
+ uniform sampler2D envMap;
2641
+ #endif
2642
+ uniform float backgroundBlurriness;
2643
+ uniform float backgroundIntensity;
2644
+ uniform mat3 backgroundRotation;
2645
+ varying vec3 vWorldDirection;
2646
+ #include <cube_uv_reflection_fragment>
2647
+ void main() {
2648
+ #ifdef ENVMAP_TYPE_CUBE
2649
+ vec4 texColor = textureCube( envMap, backgroundRotation * vWorldDirection );
2650
+ #elif defined( ENVMAP_TYPE_CUBE_UV )
2651
+ vec4 texColor = textureCubeUV( envMap, backgroundRotation * vWorldDirection, backgroundBlurriness );
2652
+ #else
2653
+ vec4 texColor = vec4( 0.0, 0.0, 0.0, 1.0 );
2654
+ #endif
2655
+ texColor.rgb *= backgroundIntensity;
2656
+ gl_FragColor = texColor;
2657
+ #include <tonemapping_fragment>
2658
+ #include <colorspace_fragment>
2659
+ }`,cube_vert:`varying vec3 vWorldDirection;
2660
+ #include <common>
2661
+ void main() {
2662
+ vWorldDirection = transformDirection( position, modelMatrix );
2663
+ #include <begin_vertex>
2664
+ #include <project_vertex>
2665
+ gl_Position.z = gl_Position.w;
2666
+ }`,cube_frag:`uniform samplerCube tCube;
2667
+ uniform float tFlip;
2668
+ uniform float opacity;
2669
+ varying vec3 vWorldDirection;
2670
+ void main() {
2671
+ vec4 texColor = textureCube( tCube, vec3( tFlip * vWorldDirection.x, vWorldDirection.yz ) );
2672
+ gl_FragColor = texColor;
2673
+ gl_FragColor.a *= opacity;
2674
+ #include <tonemapping_fragment>
2675
+ #include <colorspace_fragment>
2676
+ }`,depth_vert:`#include <common>
2677
+ #include <batching_pars_vertex>
2678
+ #include <uv_pars_vertex>
2679
+ #include <displacementmap_pars_vertex>
2680
+ #include <morphtarget_pars_vertex>
2681
+ #include <skinning_pars_vertex>
2682
+ #include <logdepthbuf_pars_vertex>
2683
+ #include <clipping_planes_pars_vertex>
2684
+ varying vec2 vHighPrecisionZW;
2685
+ void main() {
2686
+ #include <uv_vertex>
2687
+ #include <batching_vertex>
2688
+ #include <skinbase_vertex>
2689
+ #include <morphinstance_vertex>
2690
+ #ifdef USE_DISPLACEMENTMAP
2691
+ #include <beginnormal_vertex>
2692
+ #include <morphnormal_vertex>
2693
+ #include <skinnormal_vertex>
2694
+ #endif
2695
+ #include <begin_vertex>
2696
+ #include <morphtarget_vertex>
2697
+ #include <skinning_vertex>
2698
+ #include <displacementmap_vertex>
2699
+ #include <project_vertex>
2700
+ #include <logdepthbuf_vertex>
2701
+ #include <clipping_planes_vertex>
2702
+ vHighPrecisionZW = gl_Position.zw;
2703
+ }`,depth_frag:`#if DEPTH_PACKING == 3200
2704
+ uniform float opacity;
2705
+ #endif
2706
+ #include <common>
2707
+ #include <packing>
2708
+ #include <uv_pars_fragment>
2709
+ #include <map_pars_fragment>
2710
+ #include <alphamap_pars_fragment>
2711
+ #include <alphatest_pars_fragment>
2712
+ #include <alphahash_pars_fragment>
2713
+ #include <logdepthbuf_pars_fragment>
2714
+ #include <clipping_planes_pars_fragment>
2715
+ varying vec2 vHighPrecisionZW;
2716
+ void main() {
2717
+ vec4 diffuseColor = vec4( 1.0 );
2718
+ #include <clipping_planes_fragment>
2719
+ #if DEPTH_PACKING == 3200
2720
+ diffuseColor.a = opacity;
2721
+ #endif
2722
+ #include <map_fragment>
2723
+ #include <alphamap_fragment>
2724
+ #include <alphatest_fragment>
2725
+ #include <alphahash_fragment>
2726
+ #include <logdepthbuf_fragment>
2727
+ #ifdef USE_REVERSED_DEPTH_BUFFER
2728
+ float fragCoordZ = vHighPrecisionZW[ 0 ] / vHighPrecisionZW[ 1 ];
2729
+ #else
2730
+ float fragCoordZ = 0.5 * vHighPrecisionZW[ 0 ] / vHighPrecisionZW[ 1 ] + 0.5;
2731
+ #endif
2732
+ #if DEPTH_PACKING == 3200
2733
+ gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );
2734
+ #elif DEPTH_PACKING == 3201
2735
+ gl_FragColor = packDepthToRGBA( fragCoordZ );
2736
+ #elif DEPTH_PACKING == 3202
2737
+ gl_FragColor = vec4( packDepthToRGB( fragCoordZ ), 1.0 );
2738
+ #elif DEPTH_PACKING == 3203
2739
+ gl_FragColor = vec4( packDepthToRG( fragCoordZ ), 0.0, 1.0 );
2740
+ #endif
2741
+ }`,distance_vert:`#define DISTANCE
2742
+ varying vec3 vWorldPosition;
2743
+ #include <common>
2744
+ #include <batching_pars_vertex>
2745
+ #include <uv_pars_vertex>
2746
+ #include <displacementmap_pars_vertex>
2747
+ #include <morphtarget_pars_vertex>
2748
+ #include <skinning_pars_vertex>
2749
+ #include <clipping_planes_pars_vertex>
2750
+ void main() {
2751
+ #include <uv_vertex>
2752
+ #include <batching_vertex>
2753
+ #include <skinbase_vertex>
2754
+ #include <morphinstance_vertex>
2755
+ #ifdef USE_DISPLACEMENTMAP
2756
+ #include <beginnormal_vertex>
2757
+ #include <morphnormal_vertex>
2758
+ #include <skinnormal_vertex>
2759
+ #endif
2760
+ #include <begin_vertex>
2761
+ #include <morphtarget_vertex>
2762
+ #include <skinning_vertex>
2763
+ #include <displacementmap_vertex>
2764
+ #include <project_vertex>
2765
+ #include <worldpos_vertex>
2766
+ #include <clipping_planes_vertex>
2767
+ vWorldPosition = worldPosition.xyz;
2768
+ }`,distance_frag:`#define DISTANCE
2769
+ uniform vec3 referencePosition;
2770
+ uniform float nearDistance;
2771
+ uniform float farDistance;
2772
+ varying vec3 vWorldPosition;
2773
+ #include <common>
2774
+ #include <uv_pars_fragment>
2775
+ #include <map_pars_fragment>
2776
+ #include <alphamap_pars_fragment>
2777
+ #include <alphatest_pars_fragment>
2778
+ #include <alphahash_pars_fragment>
2779
+ #include <clipping_planes_pars_fragment>
2780
+ void main() {
2781
+ vec4 diffuseColor = vec4( 1.0 );
2782
+ #include <clipping_planes_fragment>
2783
+ #include <map_fragment>
2784
+ #include <alphamap_fragment>
2785
+ #include <alphatest_fragment>
2786
+ #include <alphahash_fragment>
2787
+ float dist = length( vWorldPosition - referencePosition );
2788
+ dist = ( dist - nearDistance ) / ( farDistance - nearDistance );
2789
+ dist = saturate( dist );
2790
+ gl_FragColor = vec4( dist, 0.0, 0.0, 1.0 );
2791
+ }`,equirect_vert:`varying vec3 vWorldDirection;
2792
+ #include <common>
2793
+ void main() {
2794
+ vWorldDirection = transformDirection( position, modelMatrix );
2795
+ #include <begin_vertex>
2796
+ #include <project_vertex>
2797
+ }`,equirect_frag:`uniform sampler2D tEquirect;
2798
+ varying vec3 vWorldDirection;
2799
+ #include <common>
2800
+ void main() {
2801
+ vec3 direction = normalize( vWorldDirection );
2802
+ vec2 sampleUV = equirectUv( direction );
2803
+ gl_FragColor = texture2D( tEquirect, sampleUV );
2804
+ #include <tonemapping_fragment>
2805
+ #include <colorspace_fragment>
2806
+ }`,linedashed_vert:`uniform float scale;
2807
+ attribute float lineDistance;
2808
+ varying float vLineDistance;
2809
+ #include <common>
2810
+ #include <uv_pars_vertex>
2811
+ #include <color_pars_vertex>
2812
+ #include <fog_pars_vertex>
2813
+ #include <morphtarget_pars_vertex>
2814
+ #include <logdepthbuf_pars_vertex>
2815
+ #include <clipping_planes_pars_vertex>
2816
+ void main() {
2817
+ vLineDistance = scale * lineDistance;
2818
+ #include <uv_vertex>
2819
+ #include <color_vertex>
2820
+ #include <morphinstance_vertex>
2821
+ #include <morphcolor_vertex>
2822
+ #include <begin_vertex>
2823
+ #include <morphtarget_vertex>
2824
+ #include <project_vertex>
2825
+ #include <logdepthbuf_vertex>
2826
+ #include <clipping_planes_vertex>
2827
+ #include <fog_vertex>
2828
+ }`,linedashed_frag:`uniform vec3 diffuse;
2829
+ uniform float opacity;
2830
+ uniform float dashSize;
2831
+ uniform float totalSize;
2832
+ varying float vLineDistance;
2833
+ #include <common>
2834
+ #include <color_pars_fragment>
2835
+ #include <uv_pars_fragment>
2836
+ #include <map_pars_fragment>
2837
+ #include <fog_pars_fragment>
2838
+ #include <logdepthbuf_pars_fragment>
2839
+ #include <clipping_planes_pars_fragment>
2840
+ void main() {
2841
+ vec4 diffuseColor = vec4( diffuse, opacity );
2842
+ #include <clipping_planes_fragment>
2843
+ if ( mod( vLineDistance, totalSize ) > dashSize ) {
2844
+ discard;
2845
+ }
2846
+ vec3 outgoingLight = vec3( 0.0 );
2847
+ #include <logdepthbuf_fragment>
2848
+ #include <map_fragment>
2849
+ #include <color_fragment>
2850
+ outgoingLight = diffuseColor.rgb;
2851
+ #include <opaque_fragment>
2852
+ #include <tonemapping_fragment>
2853
+ #include <colorspace_fragment>
2854
+ #include <fog_fragment>
2855
+ #include <premultiplied_alpha_fragment>
2856
+ }`,meshbasic_vert:`#include <common>
2857
+ #include <batching_pars_vertex>
2858
+ #include <uv_pars_vertex>
2859
+ #include <envmap_pars_vertex>
2860
+ #include <color_pars_vertex>
2861
+ #include <fog_pars_vertex>
2862
+ #include <morphtarget_pars_vertex>
2863
+ #include <skinning_pars_vertex>
2864
+ #include <logdepthbuf_pars_vertex>
2865
+ #include <clipping_planes_pars_vertex>
2866
+ void main() {
2867
+ #include <uv_vertex>
2868
+ #include <color_vertex>
2869
+ #include <morphinstance_vertex>
2870
+ #include <morphcolor_vertex>
2871
+ #include <batching_vertex>
2872
+ #if defined ( USE_ENVMAP ) || defined ( USE_SKINNING )
2873
+ #include <beginnormal_vertex>
2874
+ #include <morphnormal_vertex>
2875
+ #include <skinbase_vertex>
2876
+ #include <skinnormal_vertex>
2877
+ #include <defaultnormal_vertex>
2878
+ #endif
2879
+ #include <begin_vertex>
2880
+ #include <morphtarget_vertex>
2881
+ #include <skinning_vertex>
2882
+ #include <project_vertex>
2883
+ #include <logdepthbuf_vertex>
2884
+ #include <clipping_planes_vertex>
2885
+ #include <worldpos_vertex>
2886
+ #include <envmap_vertex>
2887
+ #include <fog_vertex>
2888
+ }`,meshbasic_frag:`uniform vec3 diffuse;
2889
+ uniform float opacity;
2890
+ #ifndef FLAT_SHADED
2891
+ varying vec3 vNormal;
2892
+ #endif
2893
+ #include <common>
2894
+ #include <dithering_pars_fragment>
2895
+ #include <color_pars_fragment>
2896
+ #include <uv_pars_fragment>
2897
+ #include <map_pars_fragment>
2898
+ #include <alphamap_pars_fragment>
2899
+ #include <alphatest_pars_fragment>
2900
+ #include <alphahash_pars_fragment>
2901
+ #include <aomap_pars_fragment>
2902
+ #include <lightmap_pars_fragment>
2903
+ #include <envmap_common_pars_fragment>
2904
+ #include <envmap_pars_fragment>
2905
+ #include <fog_pars_fragment>
2906
+ #include <specularmap_pars_fragment>
2907
+ #include <logdepthbuf_pars_fragment>
2908
+ #include <clipping_planes_pars_fragment>
2909
+ void main() {
2910
+ vec4 diffuseColor = vec4( diffuse, opacity );
2911
+ #include <clipping_planes_fragment>
2912
+ #include <logdepthbuf_fragment>
2913
+ #include <map_fragment>
2914
+ #include <color_fragment>
2915
+ #include <alphamap_fragment>
2916
+ #include <alphatest_fragment>
2917
+ #include <alphahash_fragment>
2918
+ #include <specularmap_fragment>
2919
+ ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
2920
+ #ifdef USE_LIGHTMAP
2921
+ vec4 lightMapTexel = texture2D( lightMap, vLightMapUv );
2922
+ reflectedLight.indirectDiffuse += lightMapTexel.rgb * lightMapIntensity * RECIPROCAL_PI;
2923
+ #else
2924
+ reflectedLight.indirectDiffuse += vec3( 1.0 );
2925
+ #endif
2926
+ #include <aomap_fragment>
2927
+ reflectedLight.indirectDiffuse *= diffuseColor.rgb;
2928
+ vec3 outgoingLight = reflectedLight.indirectDiffuse;
2929
+ #include <envmap_fragment>
2930
+ #include <opaque_fragment>
2931
+ #include <tonemapping_fragment>
2932
+ #include <colorspace_fragment>
2933
+ #include <fog_fragment>
2934
+ #include <premultiplied_alpha_fragment>
2935
+ #include <dithering_fragment>
2936
+ }`,meshlambert_vert:`#define LAMBERT
2937
+ varying vec3 vViewPosition;
2938
+ #include <common>
2939
+ #include <batching_pars_vertex>
2940
+ #include <uv_pars_vertex>
2941
+ #include <displacementmap_pars_vertex>
2942
+ #include <envmap_pars_vertex>
2943
+ #include <color_pars_vertex>
2944
+ #include <fog_pars_vertex>
2945
+ #include <normal_pars_vertex>
2946
+ #include <morphtarget_pars_vertex>
2947
+ #include <skinning_pars_vertex>
2948
+ #include <shadowmap_pars_vertex>
2949
+ #include <logdepthbuf_pars_vertex>
2950
+ #include <clipping_planes_pars_vertex>
2951
+ void main() {
2952
+ #include <uv_vertex>
2953
+ #include <color_vertex>
2954
+ #include <morphinstance_vertex>
2955
+ #include <morphcolor_vertex>
2956
+ #include <batching_vertex>
2957
+ #include <beginnormal_vertex>
2958
+ #include <morphnormal_vertex>
2959
+ #include <skinbase_vertex>
2960
+ #include <skinnormal_vertex>
2961
+ #include <defaultnormal_vertex>
2962
+ #include <normal_vertex>
2963
+ #include <begin_vertex>
2964
+ #include <morphtarget_vertex>
2965
+ #include <skinning_vertex>
2966
+ #include <displacementmap_vertex>
2967
+ #include <project_vertex>
2968
+ #include <logdepthbuf_vertex>
2969
+ #include <clipping_planes_vertex>
2970
+ vViewPosition = - mvPosition.xyz;
2971
+ #include <worldpos_vertex>
2972
+ #include <envmap_vertex>
2973
+ #include <shadowmap_vertex>
2974
+ #include <fog_vertex>
2975
+ }`,meshlambert_frag:`#define LAMBERT
2976
+ uniform vec3 diffuse;
2977
+ uniform vec3 emissive;
2978
+ uniform float opacity;
2979
+ #include <common>
2980
+ #include <dithering_pars_fragment>
2981
+ #include <color_pars_fragment>
2982
+ #include <uv_pars_fragment>
2983
+ #include <map_pars_fragment>
2984
+ #include <alphamap_pars_fragment>
2985
+ #include <alphatest_pars_fragment>
2986
+ #include <alphahash_pars_fragment>
2987
+ #include <aomap_pars_fragment>
2988
+ #include <lightmap_pars_fragment>
2989
+ #include <emissivemap_pars_fragment>
2990
+ #include <cube_uv_reflection_fragment>
2991
+ #include <envmap_common_pars_fragment>
2992
+ #include <envmap_pars_fragment>
2993
+ #include <envmap_physical_pars_fragment>
2994
+ #include <fog_pars_fragment>
2995
+ #include <bsdfs>
2996
+ #include <lights_pars_begin>
2997
+ #include <normal_pars_fragment>
2998
+ #include <lights_lambert_pars_fragment>
2999
+ #include <shadowmap_pars_fragment>
3000
+ #include <bumpmap_pars_fragment>
3001
+ #include <normalmap_pars_fragment>
3002
+ #include <specularmap_pars_fragment>
3003
+ #include <logdepthbuf_pars_fragment>
3004
+ #include <clipping_planes_pars_fragment>
3005
+ void main() {
3006
+ vec4 diffuseColor = vec4( diffuse, opacity );
3007
+ #include <clipping_planes_fragment>
3008
+ ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
3009
+ vec3 totalEmissiveRadiance = emissive;
3010
+ #include <logdepthbuf_fragment>
3011
+ #include <map_fragment>
3012
+ #include <color_fragment>
3013
+ #include <alphamap_fragment>
3014
+ #include <alphatest_fragment>
3015
+ #include <alphahash_fragment>
3016
+ #include <specularmap_fragment>
3017
+ #include <normal_fragment_begin>
3018
+ #include <normal_fragment_maps>
3019
+ #include <emissivemap_fragment>
3020
+ #include <lights_lambert_fragment>
3021
+ #include <lights_fragment_begin>
3022
+ #include <lights_fragment_maps>
3023
+ #include <lights_fragment_end>
3024
+ #include <aomap_fragment>
3025
+ vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;
3026
+ #include <envmap_fragment>
3027
+ #include <opaque_fragment>
3028
+ #include <tonemapping_fragment>
3029
+ #include <colorspace_fragment>
3030
+ #include <fog_fragment>
3031
+ #include <premultiplied_alpha_fragment>
3032
+ #include <dithering_fragment>
3033
+ }`,meshmatcap_vert:`#define MATCAP
3034
+ varying vec3 vViewPosition;
3035
+ #include <common>
3036
+ #include <batching_pars_vertex>
3037
+ #include <uv_pars_vertex>
3038
+ #include <color_pars_vertex>
3039
+ #include <displacementmap_pars_vertex>
3040
+ #include <fog_pars_vertex>
3041
+ #include <normal_pars_vertex>
3042
+ #include <morphtarget_pars_vertex>
3043
+ #include <skinning_pars_vertex>
3044
+ #include <logdepthbuf_pars_vertex>
3045
+ #include <clipping_planes_pars_vertex>
3046
+ void main() {
3047
+ #include <uv_vertex>
3048
+ #include <color_vertex>
3049
+ #include <morphinstance_vertex>
3050
+ #include <morphcolor_vertex>
3051
+ #include <batching_vertex>
3052
+ #include <beginnormal_vertex>
3053
+ #include <morphnormal_vertex>
3054
+ #include <skinbase_vertex>
3055
+ #include <skinnormal_vertex>
3056
+ #include <defaultnormal_vertex>
3057
+ #include <normal_vertex>
3058
+ #include <begin_vertex>
3059
+ #include <morphtarget_vertex>
3060
+ #include <skinning_vertex>
3061
+ #include <displacementmap_vertex>
3062
+ #include <project_vertex>
3063
+ #include <logdepthbuf_vertex>
3064
+ #include <clipping_planes_vertex>
3065
+ #include <fog_vertex>
3066
+ vViewPosition = - mvPosition.xyz;
3067
+ }`,meshmatcap_frag:`#define MATCAP
3068
+ uniform vec3 diffuse;
3069
+ uniform float opacity;
3070
+ uniform sampler2D matcap;
3071
+ varying vec3 vViewPosition;
3072
+ #include <common>
3073
+ #include <dithering_pars_fragment>
3074
+ #include <color_pars_fragment>
3075
+ #include <uv_pars_fragment>
3076
+ #include <map_pars_fragment>
3077
+ #include <alphamap_pars_fragment>
3078
+ #include <alphatest_pars_fragment>
3079
+ #include <alphahash_pars_fragment>
3080
+ #include <fog_pars_fragment>
3081
+ #include <normal_pars_fragment>
3082
+ #include <bumpmap_pars_fragment>
3083
+ #include <normalmap_pars_fragment>
3084
+ #include <logdepthbuf_pars_fragment>
3085
+ #include <clipping_planes_pars_fragment>
3086
+ void main() {
3087
+ vec4 diffuseColor = vec4( diffuse, opacity );
3088
+ #include <clipping_planes_fragment>
3089
+ #include <logdepthbuf_fragment>
3090
+ #include <map_fragment>
3091
+ #include <color_fragment>
3092
+ #include <alphamap_fragment>
3093
+ #include <alphatest_fragment>
3094
+ #include <alphahash_fragment>
3095
+ #include <normal_fragment_begin>
3096
+ #include <normal_fragment_maps>
3097
+ vec3 viewDir = normalize( vViewPosition );
3098
+ vec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) );
3099
+ vec3 y = cross( viewDir, x );
3100
+ vec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5;
3101
+ #ifdef USE_MATCAP
3102
+ vec4 matcapColor = texture2D( matcap, uv );
3103
+ #else
3104
+ vec4 matcapColor = vec4( vec3( mix( 0.2, 0.8, uv.y ) ), 1.0 );
3105
+ #endif
3106
+ vec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;
3107
+ #include <opaque_fragment>
3108
+ #include <tonemapping_fragment>
3109
+ #include <colorspace_fragment>
3110
+ #include <fog_fragment>
3111
+ #include <premultiplied_alpha_fragment>
3112
+ #include <dithering_fragment>
3113
+ }`,meshnormal_vert:`#define NORMAL
3114
+ #if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )
3115
+ varying vec3 vViewPosition;
3116
+ #endif
3117
+ #include <common>
3118
+ #include <batching_pars_vertex>
3119
+ #include <uv_pars_vertex>
3120
+ #include <displacementmap_pars_vertex>
3121
+ #include <normal_pars_vertex>
3122
+ #include <morphtarget_pars_vertex>
3123
+ #include <skinning_pars_vertex>
3124
+ #include <logdepthbuf_pars_vertex>
3125
+ #include <clipping_planes_pars_vertex>
3126
+ void main() {
3127
+ #include <uv_vertex>
3128
+ #include <batching_vertex>
3129
+ #include <beginnormal_vertex>
3130
+ #include <morphinstance_vertex>
3131
+ #include <morphnormal_vertex>
3132
+ #include <skinbase_vertex>
3133
+ #include <skinnormal_vertex>
3134
+ #include <defaultnormal_vertex>
3135
+ #include <normal_vertex>
3136
+ #include <begin_vertex>
3137
+ #include <morphtarget_vertex>
3138
+ #include <skinning_vertex>
3139
+ #include <displacementmap_vertex>
3140
+ #include <project_vertex>
3141
+ #include <logdepthbuf_vertex>
3142
+ #include <clipping_planes_vertex>
3143
+ #if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )
3144
+ vViewPosition = - mvPosition.xyz;
3145
+ #endif
3146
+ }`,meshnormal_frag:`#define NORMAL
3147
+ uniform float opacity;
3148
+ #if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )
3149
+ varying vec3 vViewPosition;
3150
+ #endif
3151
+ #include <uv_pars_fragment>
3152
+ #include <normal_pars_fragment>
3153
+ #include <bumpmap_pars_fragment>
3154
+ #include <normalmap_pars_fragment>
3155
+ #include <logdepthbuf_pars_fragment>
3156
+ #include <clipping_planes_pars_fragment>
3157
+ void main() {
3158
+ vec4 diffuseColor = vec4( 0.0, 0.0, 0.0, opacity );
3159
+ #include <clipping_planes_fragment>
3160
+ #include <logdepthbuf_fragment>
3161
+ #include <normal_fragment_begin>
3162
+ #include <normal_fragment_maps>
3163
+ gl_FragColor = vec4( normalize( normal ) * 0.5 + 0.5, diffuseColor.a );
3164
+ #ifdef OPAQUE
3165
+ gl_FragColor.a = 1.0;
3166
+ #endif
3167
+ }`,meshphong_vert:`#define PHONG
3168
+ varying vec3 vViewPosition;
3169
+ #include <common>
3170
+ #include <batching_pars_vertex>
3171
+ #include <uv_pars_vertex>
3172
+ #include <displacementmap_pars_vertex>
3173
+ #include <envmap_pars_vertex>
3174
+ #include <color_pars_vertex>
3175
+ #include <fog_pars_vertex>
3176
+ #include <normal_pars_vertex>
3177
+ #include <morphtarget_pars_vertex>
3178
+ #include <skinning_pars_vertex>
3179
+ #include <shadowmap_pars_vertex>
3180
+ #include <logdepthbuf_pars_vertex>
3181
+ #include <clipping_planes_pars_vertex>
3182
+ void main() {
3183
+ #include <uv_vertex>
3184
+ #include <color_vertex>
3185
+ #include <morphcolor_vertex>
3186
+ #include <batching_vertex>
3187
+ #include <beginnormal_vertex>
3188
+ #include <morphinstance_vertex>
3189
+ #include <morphnormal_vertex>
3190
+ #include <skinbase_vertex>
3191
+ #include <skinnormal_vertex>
3192
+ #include <defaultnormal_vertex>
3193
+ #include <normal_vertex>
3194
+ #include <begin_vertex>
3195
+ #include <morphtarget_vertex>
3196
+ #include <skinning_vertex>
3197
+ #include <displacementmap_vertex>
3198
+ #include <project_vertex>
3199
+ #include <logdepthbuf_vertex>
3200
+ #include <clipping_planes_vertex>
3201
+ vViewPosition = - mvPosition.xyz;
3202
+ #include <worldpos_vertex>
3203
+ #include <envmap_vertex>
3204
+ #include <shadowmap_vertex>
3205
+ #include <fog_vertex>
3206
+ }`,meshphong_frag:`#define PHONG
3207
+ uniform vec3 diffuse;
3208
+ uniform vec3 emissive;
3209
+ uniform vec3 specular;
3210
+ uniform float shininess;
3211
+ uniform float opacity;
3212
+ #include <common>
3213
+ #include <dithering_pars_fragment>
3214
+ #include <color_pars_fragment>
3215
+ #include <uv_pars_fragment>
3216
+ #include <map_pars_fragment>
3217
+ #include <alphamap_pars_fragment>
3218
+ #include <alphatest_pars_fragment>
3219
+ #include <alphahash_pars_fragment>
3220
+ #include <aomap_pars_fragment>
3221
+ #include <lightmap_pars_fragment>
3222
+ #include <emissivemap_pars_fragment>
3223
+ #include <cube_uv_reflection_fragment>
3224
+ #include <envmap_common_pars_fragment>
3225
+ #include <envmap_pars_fragment>
3226
+ #include <envmap_physical_pars_fragment>
3227
+ #include <fog_pars_fragment>
3228
+ #include <bsdfs>
3229
+ #include <lights_pars_begin>
3230
+ #include <normal_pars_fragment>
3231
+ #include <lights_phong_pars_fragment>
3232
+ #include <shadowmap_pars_fragment>
3233
+ #include <bumpmap_pars_fragment>
3234
+ #include <normalmap_pars_fragment>
3235
+ #include <specularmap_pars_fragment>
3236
+ #include <logdepthbuf_pars_fragment>
3237
+ #include <clipping_planes_pars_fragment>
3238
+ void main() {
3239
+ vec4 diffuseColor = vec4( diffuse, opacity );
3240
+ #include <clipping_planes_fragment>
3241
+ ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
3242
+ vec3 totalEmissiveRadiance = emissive;
3243
+ #include <logdepthbuf_fragment>
3244
+ #include <map_fragment>
3245
+ #include <color_fragment>
3246
+ #include <alphamap_fragment>
3247
+ #include <alphatest_fragment>
3248
+ #include <alphahash_fragment>
3249
+ #include <specularmap_fragment>
3250
+ #include <normal_fragment_begin>
3251
+ #include <normal_fragment_maps>
3252
+ #include <emissivemap_fragment>
3253
+ #include <lights_phong_fragment>
3254
+ #include <lights_fragment_begin>
3255
+ #include <lights_fragment_maps>
3256
+ #include <lights_fragment_end>
3257
+ #include <aomap_fragment>
3258
+ vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;
3259
+ #include <envmap_fragment>
3260
+ #include <opaque_fragment>
3261
+ #include <tonemapping_fragment>
3262
+ #include <colorspace_fragment>
3263
+ #include <fog_fragment>
3264
+ #include <premultiplied_alpha_fragment>
3265
+ #include <dithering_fragment>
3266
+ }`,meshphysical_vert:`#define STANDARD
3267
+ varying vec3 vViewPosition;
3268
+ #ifdef USE_TRANSMISSION
3269
+ varying vec3 vWorldPosition;
3270
+ #endif
3271
+ #include <common>
3272
+ #include <batching_pars_vertex>
3273
+ #include <uv_pars_vertex>
3274
+ #include <displacementmap_pars_vertex>
3275
+ #include <color_pars_vertex>
3276
+ #include <fog_pars_vertex>
3277
+ #include <normal_pars_vertex>
3278
+ #include <morphtarget_pars_vertex>
3279
+ #include <skinning_pars_vertex>
3280
+ #include <shadowmap_pars_vertex>
3281
+ #include <logdepthbuf_pars_vertex>
3282
+ #include <clipping_planes_pars_vertex>
3283
+ void main() {
3284
+ #include <uv_vertex>
3285
+ #include <color_vertex>
3286
+ #include <morphinstance_vertex>
3287
+ #include <morphcolor_vertex>
3288
+ #include <batching_vertex>
3289
+ #include <beginnormal_vertex>
3290
+ #include <morphnormal_vertex>
3291
+ #include <skinbase_vertex>
3292
+ #include <skinnormal_vertex>
3293
+ #include <defaultnormal_vertex>
3294
+ #include <normal_vertex>
3295
+ #include <begin_vertex>
3296
+ #include <morphtarget_vertex>
3297
+ #include <skinning_vertex>
3298
+ #include <displacementmap_vertex>
3299
+ #include <project_vertex>
3300
+ #include <logdepthbuf_vertex>
3301
+ #include <clipping_planes_vertex>
3302
+ vViewPosition = - mvPosition.xyz;
3303
+ #include <worldpos_vertex>
3304
+ #include <shadowmap_vertex>
3305
+ #include <fog_vertex>
3306
+ #ifdef USE_TRANSMISSION
3307
+ vWorldPosition = worldPosition.xyz;
3308
+ #endif
3309
+ }`,meshphysical_frag:`#define STANDARD
3310
+ #ifdef PHYSICAL
3311
+ #define IOR
3312
+ #define USE_SPECULAR
3313
+ #endif
3314
+ uniform vec3 diffuse;
3315
+ uniform vec3 emissive;
3316
+ uniform float roughness;
3317
+ uniform float metalness;
3318
+ uniform float opacity;
3319
+ #ifdef IOR
3320
+ uniform float ior;
3321
+ #endif
3322
+ #ifdef USE_SPECULAR
3323
+ uniform float specularIntensity;
3324
+ uniform vec3 specularColor;
3325
+ #ifdef USE_SPECULAR_COLORMAP
3326
+ uniform sampler2D specularColorMap;
3327
+ #endif
3328
+ #ifdef USE_SPECULAR_INTENSITYMAP
3329
+ uniform sampler2D specularIntensityMap;
3330
+ #endif
3331
+ #endif
3332
+ #ifdef USE_CLEARCOAT
3333
+ uniform float clearcoat;
3334
+ uniform float clearcoatRoughness;
3335
+ #endif
3336
+ #ifdef USE_DISPERSION
3337
+ uniform float dispersion;
3338
+ #endif
3339
+ #ifdef USE_IRIDESCENCE
3340
+ uniform float iridescence;
3341
+ uniform float iridescenceIOR;
3342
+ uniform float iridescenceThicknessMinimum;
3343
+ uniform float iridescenceThicknessMaximum;
3344
+ #endif
3345
+ #ifdef USE_SHEEN
3346
+ uniform vec3 sheenColor;
3347
+ uniform float sheenRoughness;
3348
+ #ifdef USE_SHEEN_COLORMAP
3349
+ uniform sampler2D sheenColorMap;
3350
+ #endif
3351
+ #ifdef USE_SHEEN_ROUGHNESSMAP
3352
+ uniform sampler2D sheenRoughnessMap;
3353
+ #endif
3354
+ #endif
3355
+ #ifdef USE_ANISOTROPY
3356
+ uniform vec2 anisotropyVector;
3357
+ #ifdef USE_ANISOTROPYMAP
3358
+ uniform sampler2D anisotropyMap;
3359
+ #endif
3360
+ #endif
3361
+ varying vec3 vViewPosition;
3362
+ #include <common>
3363
+ #include <dithering_pars_fragment>
3364
+ #include <color_pars_fragment>
3365
+ #include <uv_pars_fragment>
3366
+ #include <map_pars_fragment>
3367
+ #include <alphamap_pars_fragment>
3368
+ #include <alphatest_pars_fragment>
3369
+ #include <alphahash_pars_fragment>
3370
+ #include <aomap_pars_fragment>
3371
+ #include <lightmap_pars_fragment>
3372
+ #include <emissivemap_pars_fragment>
3373
+ #include <iridescence_fragment>
3374
+ #include <cube_uv_reflection_fragment>
3375
+ #include <envmap_common_pars_fragment>
3376
+ #include <envmap_physical_pars_fragment>
3377
+ #include <fog_pars_fragment>
3378
+ #include <lights_pars_begin>
3379
+ #include <normal_pars_fragment>
3380
+ #include <lights_physical_pars_fragment>
3381
+ #include <transmission_pars_fragment>
3382
+ #include <shadowmap_pars_fragment>
3383
+ #include <bumpmap_pars_fragment>
3384
+ #include <normalmap_pars_fragment>
3385
+ #include <clearcoat_pars_fragment>
3386
+ #include <iridescence_pars_fragment>
3387
+ #include <roughnessmap_pars_fragment>
3388
+ #include <metalnessmap_pars_fragment>
3389
+ #include <logdepthbuf_pars_fragment>
3390
+ #include <clipping_planes_pars_fragment>
3391
+ void main() {
3392
+ vec4 diffuseColor = vec4( diffuse, opacity );
3393
+ #include <clipping_planes_fragment>
3394
+ ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
3395
+ vec3 totalEmissiveRadiance = emissive;
3396
+ #include <logdepthbuf_fragment>
3397
+ #include <map_fragment>
3398
+ #include <color_fragment>
3399
+ #include <alphamap_fragment>
3400
+ #include <alphatest_fragment>
3401
+ #include <alphahash_fragment>
3402
+ #include <roughnessmap_fragment>
3403
+ #include <metalnessmap_fragment>
3404
+ #include <normal_fragment_begin>
3405
+ #include <normal_fragment_maps>
3406
+ #include <clearcoat_normal_fragment_begin>
3407
+ #include <clearcoat_normal_fragment_maps>
3408
+ #include <emissivemap_fragment>
3409
+ #include <lights_physical_fragment>
3410
+ #include <lights_fragment_begin>
3411
+ #include <lights_fragment_maps>
3412
+ #include <lights_fragment_end>
3413
+ #include <aomap_fragment>
3414
+ vec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;
3415
+ vec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;
3416
+ #include <transmission_fragment>
3417
+ vec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;
3418
+ #ifdef USE_SHEEN
3419
+
3420
+ outgoingLight = outgoingLight + sheenSpecularDirect + sheenSpecularIndirect;
3421
+
3422
+ #endif
3423
+ #ifdef USE_CLEARCOAT
3424
+ float dotNVcc = saturate( dot( geometryClearcoatNormal, geometryViewDir ) );
3425
+ vec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );
3426
+ outgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + ( clearcoatSpecularDirect + clearcoatSpecularIndirect ) * material.clearcoat;
3427
+ #endif
3428
+ #include <opaque_fragment>
3429
+ #include <tonemapping_fragment>
3430
+ #include <colorspace_fragment>
3431
+ #include <fog_fragment>
3432
+ #include <premultiplied_alpha_fragment>
3433
+ #include <dithering_fragment>
3434
+ }`,meshtoon_vert:`#define TOON
3435
+ varying vec3 vViewPosition;
3436
+ #include <common>
3437
+ #include <batching_pars_vertex>
3438
+ #include <uv_pars_vertex>
3439
+ #include <displacementmap_pars_vertex>
3440
+ #include <color_pars_vertex>
3441
+ #include <fog_pars_vertex>
3442
+ #include <normal_pars_vertex>
3443
+ #include <morphtarget_pars_vertex>
3444
+ #include <skinning_pars_vertex>
3445
+ #include <shadowmap_pars_vertex>
3446
+ #include <logdepthbuf_pars_vertex>
3447
+ #include <clipping_planes_pars_vertex>
3448
+ void main() {
3449
+ #include <uv_vertex>
3450
+ #include <color_vertex>
3451
+ #include <morphinstance_vertex>
3452
+ #include <morphcolor_vertex>
3453
+ #include <batching_vertex>
3454
+ #include <beginnormal_vertex>
3455
+ #include <morphnormal_vertex>
3456
+ #include <skinbase_vertex>
3457
+ #include <skinnormal_vertex>
3458
+ #include <defaultnormal_vertex>
3459
+ #include <normal_vertex>
3460
+ #include <begin_vertex>
3461
+ #include <morphtarget_vertex>
3462
+ #include <skinning_vertex>
3463
+ #include <displacementmap_vertex>
3464
+ #include <project_vertex>
3465
+ #include <logdepthbuf_vertex>
3466
+ #include <clipping_planes_vertex>
3467
+ vViewPosition = - mvPosition.xyz;
3468
+ #include <worldpos_vertex>
3469
+ #include <shadowmap_vertex>
3470
+ #include <fog_vertex>
3471
+ }`,meshtoon_frag:`#define TOON
3472
+ uniform vec3 diffuse;
3473
+ uniform vec3 emissive;
3474
+ uniform float opacity;
3475
+ #include <common>
3476
+ #include <dithering_pars_fragment>
3477
+ #include <color_pars_fragment>
3478
+ #include <uv_pars_fragment>
3479
+ #include <map_pars_fragment>
3480
+ #include <alphamap_pars_fragment>
3481
+ #include <alphatest_pars_fragment>
3482
+ #include <alphahash_pars_fragment>
3483
+ #include <aomap_pars_fragment>
3484
+ #include <lightmap_pars_fragment>
3485
+ #include <emissivemap_pars_fragment>
3486
+ #include <gradientmap_pars_fragment>
3487
+ #include <fog_pars_fragment>
3488
+ #include <bsdfs>
3489
+ #include <lights_pars_begin>
3490
+ #include <normal_pars_fragment>
3491
+ #include <lights_toon_pars_fragment>
3492
+ #include <shadowmap_pars_fragment>
3493
+ #include <bumpmap_pars_fragment>
3494
+ #include <normalmap_pars_fragment>
3495
+ #include <logdepthbuf_pars_fragment>
3496
+ #include <clipping_planes_pars_fragment>
3497
+ void main() {
3498
+ vec4 diffuseColor = vec4( diffuse, opacity );
3499
+ #include <clipping_planes_fragment>
3500
+ ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
3501
+ vec3 totalEmissiveRadiance = emissive;
3502
+ #include <logdepthbuf_fragment>
3503
+ #include <map_fragment>
3504
+ #include <color_fragment>
3505
+ #include <alphamap_fragment>
3506
+ #include <alphatest_fragment>
3507
+ #include <alphahash_fragment>
3508
+ #include <normal_fragment_begin>
3509
+ #include <normal_fragment_maps>
3510
+ #include <emissivemap_fragment>
3511
+ #include <lights_toon_fragment>
3512
+ #include <lights_fragment_begin>
3513
+ #include <lights_fragment_maps>
3514
+ #include <lights_fragment_end>
3515
+ #include <aomap_fragment>
3516
+ vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;
3517
+ #include <opaque_fragment>
3518
+ #include <tonemapping_fragment>
3519
+ #include <colorspace_fragment>
3520
+ #include <fog_fragment>
3521
+ #include <premultiplied_alpha_fragment>
3522
+ #include <dithering_fragment>
3523
+ }`,points_vert:`uniform float size;
3524
+ uniform float scale;
3525
+ #include <common>
3526
+ #include <color_pars_vertex>
3527
+ #include <fog_pars_vertex>
3528
+ #include <morphtarget_pars_vertex>
3529
+ #include <logdepthbuf_pars_vertex>
3530
+ #include <clipping_planes_pars_vertex>
3531
+ #ifdef USE_POINTS_UV
3532
+ varying vec2 vUv;
3533
+ uniform mat3 uvTransform;
3534
+ #endif
3535
+ void main() {
3536
+ #ifdef USE_POINTS_UV
3537
+ vUv = ( uvTransform * vec3( uv, 1 ) ).xy;
3538
+ #endif
3539
+ #include <color_vertex>
3540
+ #include <morphinstance_vertex>
3541
+ #include <morphcolor_vertex>
3542
+ #include <begin_vertex>
3543
+ #include <morphtarget_vertex>
3544
+ #include <project_vertex>
3545
+ gl_PointSize = size;
3546
+ #ifdef USE_SIZEATTENUATION
3547
+ bool isPerspective = isPerspectiveMatrix( projectionMatrix );
3548
+ if ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z );
3549
+ #endif
3550
+ #include <logdepthbuf_vertex>
3551
+ #include <clipping_planes_vertex>
3552
+ #include <worldpos_vertex>
3553
+ #include <fog_vertex>
3554
+ }`,points_frag:`uniform vec3 diffuse;
3555
+ uniform float opacity;
3556
+ #include <common>
3557
+ #include <color_pars_fragment>
3558
+ #include <map_particle_pars_fragment>
3559
+ #include <alphatest_pars_fragment>
3560
+ #include <alphahash_pars_fragment>
3561
+ #include <fog_pars_fragment>
3562
+ #include <logdepthbuf_pars_fragment>
3563
+ #include <clipping_planes_pars_fragment>
3564
+ void main() {
3565
+ vec4 diffuseColor = vec4( diffuse, opacity );
3566
+ #include <clipping_planes_fragment>
3567
+ vec3 outgoingLight = vec3( 0.0 );
3568
+ #include <logdepthbuf_fragment>
3569
+ #include <map_particle_fragment>
3570
+ #include <color_fragment>
3571
+ #include <alphatest_fragment>
3572
+ #include <alphahash_fragment>
3573
+ outgoingLight = diffuseColor.rgb;
3574
+ #include <opaque_fragment>
3575
+ #include <tonemapping_fragment>
3576
+ #include <colorspace_fragment>
3577
+ #include <fog_fragment>
3578
+ #include <premultiplied_alpha_fragment>
3579
+ }`,shadow_vert:`#include <common>
3580
+ #include <batching_pars_vertex>
3581
+ #include <fog_pars_vertex>
3582
+ #include <morphtarget_pars_vertex>
3583
+ #include <skinning_pars_vertex>
3584
+ #include <logdepthbuf_pars_vertex>
3585
+ #include <shadowmap_pars_vertex>
3586
+ void main() {
3587
+ #include <batching_vertex>
3588
+ #include <beginnormal_vertex>
3589
+ #include <morphinstance_vertex>
3590
+ #include <morphnormal_vertex>
3591
+ #include <skinbase_vertex>
3592
+ #include <skinnormal_vertex>
3593
+ #include <defaultnormal_vertex>
3594
+ #include <begin_vertex>
3595
+ #include <morphtarget_vertex>
3596
+ #include <skinning_vertex>
3597
+ #include <project_vertex>
3598
+ #include <logdepthbuf_vertex>
3599
+ #include <worldpos_vertex>
3600
+ #include <shadowmap_vertex>
3601
+ #include <fog_vertex>
3602
+ }`,shadow_frag:`uniform vec3 color;
3603
+ uniform float opacity;
3604
+ #include <common>
3605
+ #include <fog_pars_fragment>
3606
+ #include <bsdfs>
3607
+ #include <lights_pars_begin>
3608
+ #include <logdepthbuf_pars_fragment>
3609
+ #include <shadowmap_pars_fragment>
3610
+ #include <shadowmask_pars_fragment>
3611
+ void main() {
3612
+ #include <logdepthbuf_fragment>
3613
+ gl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );
3614
+ #include <tonemapping_fragment>
3615
+ #include <colorspace_fragment>
3616
+ #include <fog_fragment>
3617
+ #include <premultiplied_alpha_fragment>
3618
+ }`,sprite_vert:`uniform float rotation;
3619
+ uniform vec2 center;
3620
+ #include <common>
3621
+ #include <uv_pars_vertex>
3622
+ #include <fog_pars_vertex>
3623
+ #include <logdepthbuf_pars_vertex>
3624
+ #include <clipping_planes_pars_vertex>
3625
+ void main() {
3626
+ #include <uv_vertex>
3627
+ vec4 mvPosition = modelViewMatrix[ 3 ];
3628
+ vec2 scale = vec2( length( modelMatrix[ 0 ].xyz ), length( modelMatrix[ 1 ].xyz ) );
3629
+ #ifndef USE_SIZEATTENUATION
3630
+ bool isPerspective = isPerspectiveMatrix( projectionMatrix );
3631
+ if ( isPerspective ) scale *= - mvPosition.z;
3632
+ #endif
3633
+ vec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;
3634
+ vec2 rotatedPosition;
3635
+ rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;
3636
+ rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;
3637
+ mvPosition.xy += rotatedPosition;
3638
+ gl_Position = projectionMatrix * mvPosition;
3639
+ #include <logdepthbuf_vertex>
3640
+ #include <clipping_planes_vertex>
3641
+ #include <fog_vertex>
3642
+ }`,sprite_frag:`uniform vec3 diffuse;
3643
+ uniform float opacity;
3644
+ #include <common>
3645
+ #include <uv_pars_fragment>
3646
+ #include <map_pars_fragment>
3647
+ #include <alphamap_pars_fragment>
3648
+ #include <alphatest_pars_fragment>
3649
+ #include <alphahash_pars_fragment>
3650
+ #include <fog_pars_fragment>
3651
+ #include <logdepthbuf_pars_fragment>
3652
+ #include <clipping_planes_pars_fragment>
3653
+ void main() {
3654
+ vec4 diffuseColor = vec4( diffuse, opacity );
3655
+ #include <clipping_planes_fragment>
3656
+ vec3 outgoingLight = vec3( 0.0 );
3657
+ #include <logdepthbuf_fragment>
3658
+ #include <map_fragment>
3659
+ #include <alphamap_fragment>
3660
+ #include <alphatest_fragment>
3661
+ #include <alphahash_fragment>
3662
+ outgoingLight = diffuseColor.rgb;
3663
+ #include <opaque_fragment>
3664
+ #include <tonemapping_fragment>
3665
+ #include <colorspace_fragment>
3666
+ #include <fog_fragment>
3667
+ }`},a={common:{diffuse:{value:new e.u(16777215)},opacity:{value:1},map:{value:null},mapTransform:{value:new e.B},alphaMap:{value:null},alphaMapTransform:{value:new e.B},alphaTest:{value:0}},specularmap:{specularMap:{value:null},specularMapTransform:{value:new e.B}},envmap:{envMap:{value:null},envMapRotation:{value:new e.B},reflectivity:{value:1},ior:{value:1.5},refractionRatio:{value:.98},dfgLUT:{value:null}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1},aoMapTransform:{value:new e.B}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1},lightMapTransform:{value:new e.B}},bumpmap:{bumpMap:{value:null},bumpMapTransform:{value:new e.B},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalMapTransform:{value:new e.B},normalScale:{value:new e.mn(1,1)}},displacementmap:{displacementMap:{value:null},displacementMapTransform:{value:new e.B},displacementScale:{value:1},displacementBias:{value:0}},emissivemap:{emissiveMap:{value:null},emissiveMapTransform:{value:new e.B}},metalnessmap:{metalnessMap:{value:null},metalnessMapTransform:{value:new e.B}},roughnessmap:{roughnessMap:{value:null},roughnessMapTransform:{value:new e.B}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new e.u(16777215)}},lights:{ambientLightColor:{value:[]},lightProbe:{value:[]},directionalLights:{value:[],properties:{direction:{},color:{}}},directionalLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},directionalShadowMatrix:{value:[]},spotLights:{value:[],properties:{color:{},position:{},direction:{},distance:{},coneCos:{},penumbraCos:{},decay:{}}},spotLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},spotLightMap:{value:[]},spotLightMatrix:{value:[]},pointLights:{value:[],properties:{color:{},position:{},decay:{},distance:{}}},pointLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{},shadowCameraNear:{},shadowCameraFar:{}}},pointShadowMatrix:{value:[]},hemisphereLights:{value:[],properties:{direction:{},skyColor:{},groundColor:{}}},rectAreaLights:{value:[],properties:{color:{},position:{},width:{},height:{}}},ltc_1:{value:null},ltc_2:{value:null},probesSH:{value:null},probesMin:{value:new e.hn},probesMax:{value:new e.hn},probesResolution:{value:new e.hn}},points:{diffuse:{value:new e.u(16777215)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},alphaMapTransform:{value:new e.B},alphaTest:{value:0},uvTransform:{value:new e.B}},sprite:{diffuse:{value:new e.u(16777215)},opacity:{value:1},center:{value:new e.mn(.5,.5)},rotation:{value:0},map:{value:null},mapTransform:{value:new e.B},alphaMap:{value:null},alphaMapTransform:{value:new e.B},alphaTest:{value:0}}},o={basic:{uniforms:e.Dn([a.common,a.specularmap,a.envmap,a.aomap,a.lightmap,a.fog]),vertexShader:i.meshbasic_vert,fragmentShader:i.meshbasic_frag},lambert:{uniforms:e.Dn([a.common,a.specularmap,a.envmap,a.aomap,a.lightmap,a.emissivemap,a.bumpmap,a.normalmap,a.displacementmap,a.fog,a.lights,{emissive:{value:new e.u(0)},envMapIntensity:{value:1}}]),vertexShader:i.meshlambert_vert,fragmentShader:i.meshlambert_frag},phong:{uniforms:e.Dn([a.common,a.specularmap,a.envmap,a.aomap,a.lightmap,a.emissivemap,a.bumpmap,a.normalmap,a.displacementmap,a.fog,a.lights,{emissive:{value:new e.u(0)},specular:{value:new e.u(1118481)},shininess:{value:30},envMapIntensity:{value:1}}]),vertexShader:i.meshphong_vert,fragmentShader:i.meshphong_frag},standard:{uniforms:e.Dn([a.common,a.envmap,a.aomap,a.lightmap,a.emissivemap,a.bumpmap,a.normalmap,a.displacementmap,a.roughnessmap,a.metalnessmap,a.fog,a.lights,{emissive:{value:new e.u(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:i.meshphysical_vert,fragmentShader:i.meshphysical_frag},toon:{uniforms:e.Dn([a.common,a.aomap,a.lightmap,a.emissivemap,a.bumpmap,a.normalmap,a.displacementmap,a.gradientmap,a.fog,a.lights,{emissive:{value:new e.u(0)}}]),vertexShader:i.meshtoon_vert,fragmentShader:i.meshtoon_frag},matcap:{uniforms:e.Dn([a.common,a.bumpmap,a.normalmap,a.displacementmap,a.fog,{matcap:{value:null}}]),vertexShader:i.meshmatcap_vert,fragmentShader:i.meshmatcap_frag},points:{uniforms:e.Dn([a.points,a.fog]),vertexShader:i.points_vert,fragmentShader:i.points_frag},dashed:{uniforms:e.Dn([a.common,a.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:i.linedashed_vert,fragmentShader:i.linedashed_frag},depth:{uniforms:e.Dn([a.common,a.displacementmap]),vertexShader:i.depth_vert,fragmentShader:i.depth_frag},normal:{uniforms:e.Dn([a.common,a.bumpmap,a.normalmap,a.displacementmap,{opacity:{value:1}}]),vertexShader:i.meshnormal_vert,fragmentShader:i.meshnormal_frag},sprite:{uniforms:e.Dn([a.sprite,a.fog]),vertexShader:i.sprite_vert,fragmentShader:i.sprite_frag},background:{uniforms:{uvTransform:{value:new e.B},t2D:{value:null},backgroundIntensity:{value:1}},vertexShader:i.background_vert,fragmentShader:i.background_frag},backgroundCube:{uniforms:{envMap:{value:null},backgroundBlurriness:{value:0},backgroundIntensity:{value:1},backgroundRotation:{value:new e.B}},vertexShader:i.backgroundCube_vert,fragmentShader:i.backgroundCube_frag},cube:{uniforms:{tCube:{value:null},tFlip:{value:-1},opacity:{value:1}},vertexShader:i.cube_vert,fragmentShader:i.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:i.equirect_vert,fragmentShader:i.equirect_frag},distance:{uniforms:e.Dn([a.common,a.displacementmap,{referencePosition:{value:new e.hn},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:i.distance_vert,fragmentShader:i.distance_frag},shadow:{uniforms:e.Dn([a.lights,a.fog,{color:{value:new e.u(0)},opacity:{value:1}}]),vertexShader:i.shadow_vert,fragmentShader:i.shadow_frag}};o.physical={uniforms:e.Dn([o.standard.uniforms,{clearcoat:{value:0},clearcoatMap:{value:null},clearcoatMapTransform:{value:new e.B},clearcoatNormalMap:{value:null},clearcoatNormalMapTransform:{value:new e.B},clearcoatNormalScale:{value:new e.mn(1,1)},clearcoatRoughness:{value:0},clearcoatRoughnessMap:{value:null},clearcoatRoughnessMapTransform:{value:new e.B},dispersion:{value:0},iridescence:{value:0},iridescenceMap:{value:null},iridescenceMapTransform:{value:new e.B},iridescenceIOR:{value:1.3},iridescenceThicknessMinimum:{value:100},iridescenceThicknessMaximum:{value:400},iridescenceThicknessMap:{value:null},iridescenceThicknessMapTransform:{value:new e.B},sheen:{value:0},sheenColor:{value:new e.u(0)},sheenColorMap:{value:null},sheenColorMapTransform:{value:new e.B},sheenRoughness:{value:1},sheenRoughnessMap:{value:null},sheenRoughnessMapTransform:{value:new e.B},transmission:{value:0},transmissionMap:{value:null},transmissionMapTransform:{value:new e.B},transmissionSamplerSize:{value:new e.mn},transmissionSamplerMap:{value:null},thickness:{value:0},thicknessMap:{value:null},thicknessMapTransform:{value:new e.B},attenuationDistance:{value:0},attenuationColor:{value:new e.u(0)},specularColor:{value:new e.u(1,1,1)},specularColorMap:{value:null},specularColorMapTransform:{value:new e.B},specularIntensity:{value:1},specularIntensityMap:{value:null},specularIntensityMapTransform:{value:new e.B},anisotropyVector:{value:new e.mn},anisotropyMap:{value:null},anisotropyMapTransform:{value:new e.B}}]),vertexShader:i.meshphysical_vert,fragmentShader:i.meshphysical_frag};var s={r:0,b:0,g:0},c=new e.V,l=new e.B;l.set(-1,0,0,0,1,0,0,0,1);function u(t,n,r,i,a,u){let d=new e.u(0),f=a===!0?0:1,p,m,h=null,g=0,_=null;function v(e){let t=e.isScene===!0?e.background:null;if(t&&t.isTexture){let r=e.backgroundBlurriness>0;t=n.get(t,r)}return t}function y(e){let n=!1,i=v(e);i===null?x(d,f):i&&i.isColor&&(x(i,1),n=!0);let a=t.xr.getEnvironmentBlendMode();a===`additive`?r.buffers.color.setClear(0,0,0,1,u):a===`alpha-blend`&&r.buffers.color.setClear(0,0,0,0,u),(t.autoClear||n)&&(r.buffers.depth.setTest(!0),r.buffers.depth.setMask(!0),r.buffers.color.setMask(!0),t.clear(t.autoClearColor,t.autoClearDepth,t.autoClearStencil))}function b(n,r){let a=v(r);a&&(a.isCubeTexture||a.mapping===306)?(m===void 0&&(m=new e.H(new e.a(1,1,1),new e.Qt({name:`BackgroundCubeMaterial`,uniforms:e.bn(o.backgroundCube.uniforms),vertexShader:o.backgroundCube.vertexShader,fragmentShader:o.backgroundCube.fragmentShader,side:1,depthTest:!1,depthWrite:!1,fog:!1,allowOverride:!1})),m.geometry.deleteAttribute(`normal`),m.geometry.deleteAttribute(`uv`),m.onBeforeRender=function(e,t,n){this.matrixWorld.copyPosition(n.matrixWorld)},Object.defineProperty(m.material,"envMap",{get:function(){return this.uniforms.envMap.value}}),i.update(m)),m.material.uniforms.envMap.value=a,m.material.uniforms.backgroundBlurriness.value=r.backgroundBlurriness,m.material.uniforms.backgroundIntensity.value=r.backgroundIntensity,m.material.uniforms.backgroundRotation.value.setFromMatrix4(c.makeRotationFromEuler(r.backgroundRotation)).transpose(),a.isCubeTexture&&a.isRenderTargetTexture===!1&&m.material.uniforms.backgroundRotation.value.premultiply(l),m.material.toneMapped=e.d.getTransfer(a.colorSpace)!==e.Xt,(h!==a||g!==a.version||_!==t.toneMapping)&&(m.material.needsUpdate=!0,h=a,g=a.version,_=t.toneMapping),m.layers.enableAll(),n.unshift(m,m.geometry,m.material,0,0,null)):a&&a.isTexture&&(p===void 0&&(p=new e.H(new e.$(2,2),new e.Qt({name:`BackgroundMaterial`,uniforms:e.bn(o.background.uniforms),vertexShader:o.background.vertexShader,fragmentShader:o.background.fragmentShader,side:0,depthTest:!1,depthWrite:!1,fog:!1,allowOverride:!1})),p.geometry.deleteAttribute(`normal`),Object.defineProperty(p.material,"map",{get:function(){return this.uniforms.t2D.value}}),i.update(p)),p.material.uniforms.t2D.value=a,p.material.uniforms.backgroundIntensity.value=r.backgroundIntensity,p.material.toneMapped=e.d.getTransfer(a.colorSpace)!==e.Xt,a.matrixAutoUpdate===!0&&a.updateMatrix(),p.material.uniforms.uvTransform.value.copy(a.matrix),(h!==a||g!==a.version||_!==t.toneMapping)&&(p.material.needsUpdate=!0,h=a,g=a.version,_=t.toneMapping),p.layers.enableAll(),n.unshift(p,p.geometry,p.material,0,0,null))}function x(n,i){n.getRGB(s,e.Tn(t)),r.buffers.color.setClear(s.r,s.g,s.b,i,u)}function S(){m!==void 0&&(m.geometry.dispose(),m.material.dispose(),m=void 0),p!==void 0&&(p.geometry.dispose(),p.material.dispose(),p=void 0)}return{getClearColor:function(){return d},setClearColor:function(e,t=1){d.set(e),f=t,x(d,f)},getClearAlpha:function(){return f},setClearAlpha:function(e){f=e,x(d,f)},render:y,addToRenderList:b,dispose:S}}function d(e,t){let n=e.getParameter(e.MAX_VERTEX_ATTRIBS),r={},i=f(null),a=i,o=!1;function s(n,r,i,s,c){let u=!1,f=d(n,s,i,r);a!==f&&(a=f,l(a.object)),u=p(n,s,i,c),u&&m(n,s,i,c),c!==null&&t.update(c,e.ELEMENT_ARRAY_BUFFER),(u||o)&&(o=!1,b(n,r,i,s),c!==null&&e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,t.get(c).buffer))}function c(){return e.createVertexArray()}function l(t){return e.bindVertexArray(t)}function u(t){return e.deleteVertexArray(t)}function d(e,t,n,i){let a=i.wireframe===!0,o=r[t.id];o===void 0&&(o={},r[t.id]=o);let s=e.isInstancedMesh===!0?e.id:0,l=o[s];l===void 0&&(l={},o[s]=l);let u=l[n.id];u===void 0&&(u={},l[n.id]=u);let d=u[a];return d===void 0&&(d=f(c()),u[a]=d),d}function f(e){let t=[],r=[],i=[];for(let e=0;e<n;e++)t[e]=0,r[e]=0,i[e]=0;return{geometry:null,program:null,wireframe:!1,newAttributes:t,enabledAttributes:r,attributeDivisors:i,object:e,attributes:{},index:null}}function p(e,t,n,r){let i=a.attributes,o=t.attributes,s=0,c=n.getAttributes();for(let t in c)if(c[t].location>=0){let n=i[t],r=o[t];if(r===void 0&&(t===`instanceMatrix`&&e.instanceMatrix&&(r=e.instanceMatrix),t===`instanceColor`&&e.instanceColor&&(r=e.instanceColor)),n===void 0||n.attribute!==r||r&&n.data!==r.data)return!0;s++}return a.attributesNum!==s||a.index!==r}function m(e,t,n,r){let i={},o=t.attributes,s=0,c=n.getAttributes();for(let t in c)if(c[t].location>=0){let n=o[t];n===void 0&&(t===`instanceMatrix`&&e.instanceMatrix&&(n=e.instanceMatrix),t===`instanceColor`&&e.instanceColor&&(n=e.instanceColor));let r={};r.attribute=n,n&&n.data&&(r.data=n.data),i[t]=r,s++}a.attributes=i,a.attributesNum=s,a.index=r}function h(){let e=a.newAttributes;for(let t=0,n=e.length;t<n;t++)e[t]=0}function g(e){_(e,0)}function _(t,n){let r=a.newAttributes,i=a.enabledAttributes,o=a.attributeDivisors;r[t]=1,i[t]===0&&(e.enableVertexAttribArray(t),i[t]=1),o[t]!==n&&(e.vertexAttribDivisor(t,n),o[t]=n)}function v(){let t=a.newAttributes,n=a.enabledAttributes;for(let r=0,i=n.length;r<i;r++)n[r]!==t[r]&&(e.disableVertexAttribArray(r),n[r]=0)}function y(t,n,r,i,a,o,s){s===!0?e.vertexAttribIPointer(t,n,r,a,o):e.vertexAttribPointer(t,n,r,i,a,o)}function b(n,r,i,a){h();let o=a.attributes,s=i.getAttributes(),c=r.defaultAttributeValues;for(let r in s){let i=s[r];if(i.location>=0){let s=o[r];if(s===void 0&&(r===`instanceMatrix`&&n.instanceMatrix&&(s=n.instanceMatrix),r===`instanceColor`&&n.instanceColor&&(s=n.instanceColor)),s!==void 0){let r=s.normalized,o=s.itemSize,c=t.get(s);if(c===void 0)continue;let l=c.buffer,u=c.type,d=c.bytesPerElement,f=u===e.INT||u===e.UNSIGNED_INT||s.gpuType===1013;if(s.isInterleavedBufferAttribute){let t=s.data,c=t.stride,p=s.offset;if(t.isInstancedInterleavedBuffer){for(let e=0;e<i.locationSize;e++)_(i.location+e,t.meshPerAttribute);n.isInstancedMesh!==!0&&a._maxInstanceCount===void 0&&(a._maxInstanceCount=t.meshPerAttribute*t.count)}else for(let e=0;e<i.locationSize;e++)g(i.location+e);e.bindBuffer(e.ARRAY_BUFFER,l);for(let e=0;e<i.locationSize;e++)y(i.location+e,o/i.locationSize,u,r,c*d,(p+o/i.locationSize*e)*d,f)}else{if(s.isInstancedBufferAttribute){for(let e=0;e<i.locationSize;e++)_(i.location+e,s.meshPerAttribute);n.isInstancedMesh!==!0&&a._maxInstanceCount===void 0&&(a._maxInstanceCount=s.meshPerAttribute*s.count)}else for(let e=0;e<i.locationSize;e++)g(i.location+e);e.bindBuffer(e.ARRAY_BUFFER,l);for(let e=0;e<i.locationSize;e++)y(i.location+e,o/i.locationSize,u,r,o*d,o/i.locationSize*e*d,f)}}else if(c!==void 0){let t=c[r];if(t!==void 0)switch(t.length){case 2:e.vertexAttrib2fv(i.location,t);break;case 3:e.vertexAttrib3fv(i.location,t);break;case 4:e.vertexAttrib4fv(i.location,t);break;default:e.vertexAttrib1fv(i.location,t)}}}}v()}function x(){T();for(let e in r){let t=r[e];for(let e in t){let n=t[e];for(let e in n){let t=n[e];for(let e in t)u(t[e].object),delete t[e];delete n[e]}}delete r[e]}}function S(e){if(r[e.id]===void 0)return;let t=r[e.id];for(let e in t){let n=t[e];for(let e in n){let t=n[e];for(let e in t)u(t[e].object),delete t[e];delete n[e]}}delete r[e.id]}function C(e){for(let t in r){let n=r[t];for(let t in n){let r=n[t];if(r[e.id]===void 0)continue;let i=r[e.id];for(let e in i)u(i[e].object),delete i[e];delete r[e.id]}}}function w(e){for(let t in r){let n=r[t],i=e.isInstancedMesh===!0?e.id:0,a=n[i];if(a!==void 0){for(let e in a){let t=a[e];for(let e in t)u(t[e].object),delete t[e];delete a[e]}delete n[i],Object.keys(n).length===0&&delete r[t]}}}function T(){E(),o=!0,a!==i&&(a=i,l(a.object))}function E(){i.geometry=null,i.program=null,i.wireframe=!1}return{setup:s,reset:T,resetDefaultState:E,dispose:x,releaseStatesOfGeometry:S,releaseStatesOfObject:w,releaseStatesOfProgram:C,initAttributes:h,enableAttribute:g,disableUnusedAttributes:v}}function f(e,t,n){let r;function i(e){r=e}function a(t,i){e.drawArrays(r,t,i),n.update(i,r,1)}function o(t,i,a){a!==0&&(e.drawArraysInstanced(r,t,i,a),n.update(i,r,a))}function s(e,i,a){if(a===0)return;t.get(`WEBGL_multi_draw`).multiDrawArraysWEBGL(r,e,0,i,0,a);let o=0;for(let e=0;e<a;e++)o+=i[e];n.update(o,r,1)}this.setMode=i,this.render=a,this.renderInstances=o,this.renderMultiDraw=s}function p(t,n,r,i){let a;function o(){if(a!==void 0)return a;if(n.has(`EXT_texture_filter_anisotropic`)===!0){let e=n.get(`EXT_texture_filter_anisotropic`);a=t.getParameter(e.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else a=0;return a}function s(e){return!(e!==1023&&i.convert(e)!==t.getParameter(t.IMPLEMENTATION_COLOR_READ_FORMAT))}function c(e){let r=e===1016&&(n.has(`EXT_color_buffer_half_float`)||n.has(`EXT_color_buffer_float`));return!(e!==1009&&i.convert(e)!==t.getParameter(t.IMPLEMENTATION_COLOR_READ_TYPE)&&e!==1015&&!r)}function l(e){if(e===`highp`){if(t.getShaderPrecisionFormat(t.VERTEX_SHADER,t.HIGH_FLOAT).precision>0&&t.getShaderPrecisionFormat(t.FRAGMENT_SHADER,t.HIGH_FLOAT).precision>0)return`highp`;e=`mediump`}return e===`mediump`&&t.getShaderPrecisionFormat(t.VERTEX_SHADER,t.MEDIUM_FLOAT).precision>0&&t.getShaderPrecisionFormat(t.FRAGMENT_SHADER,t.MEDIUM_FLOAT).precision>0?`mediump`:`lowp`}let u=r.precision===void 0?`highp`:r.precision,d=l(u);d!==u&&(e.kn(`WebGLRenderer:`,u,`not supported, using`,d,`instead.`),u=d);let f=r.logarithmicDepthBuffer===!0,p=r.reversedDepthBuffer===!0&&n.has(`EXT_clip_control`);r.reversedDepthBuffer===!0&&p===!1&&e.kn(`WebGLRenderer: Unable to use reversed depth buffer due to missing EXT_clip_control extension. Fallback to default depth buffer.`);let m=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS),h=t.getParameter(t.MAX_VERTEX_TEXTURE_IMAGE_UNITS),g=t.getParameter(t.MAX_TEXTURE_SIZE),_=t.getParameter(t.MAX_CUBE_MAP_TEXTURE_SIZE),v=t.getParameter(t.MAX_VERTEX_ATTRIBS),y=t.getParameter(t.MAX_VERTEX_UNIFORM_VECTORS),b=t.getParameter(t.MAX_VARYING_VECTORS),x=t.getParameter(t.MAX_FRAGMENT_UNIFORM_VECTORS),S=t.getParameter(t.MAX_SAMPLES),C=t.getParameter(t.SAMPLES);return{isWebGL2:!0,getMaxAnisotropy:o,getMaxPrecision:l,textureFormatReadable:s,textureTypeReadable:c,precision:u,logarithmicDepthBuffer:f,reversedDepthBuffer:p,maxTextures:m,maxVertexTextures:h,maxTextureSize:g,maxCubemapSize:_,maxAttributes:v,maxVertexUniforms:y,maxVaryings:b,maxFragmentUniforms:x,maxSamples:S,samples:C}}function m(t){let n=this,r=null,i=0,a=!1,o=!1,s=new e.Q,c=new e.B,l={value:null,needsUpdate:!1};this.uniform=l,this.numPlanes=0,this.numIntersection=0,this.init=function(e,t){let n=e.length!==0||t||i!==0||a;return a=t,i=e.length,n},this.beginShadows=function(){o=!0,d(null)},this.endShadows=function(){o=!1},this.setGlobalState=function(e,t){r=d(e,t,0)},this.setState=function(e,n,s){let c=e.clippingPlanes,f=e.clipIntersection,p=e.clipShadows,m=t.get(e);if(!a||c===null||c.length===0||o&&!p)o?d(null):u();else{let e=o?0:i,t=e*4,a=m.clippingState||null;l.value=a,a=d(c,n,t,s);for(let e=0;e!==t;++e)a[e]=r[e];m.clippingState=a,this.numIntersection=f?this.numPlanes:0,this.numPlanes+=e}};function u(){l.value!==r&&(l.value=r,l.needsUpdate=i>0),n.numPlanes=i,n.numIntersection=0}function d(e,t,r,i){let a=e===null?0:e.length,o=null;if(a!==0){if(o=l.value,i!==!0||o===null){let n=r+a*4,i=t.matrixWorldInverse;c.getNormalMatrix(i),(o===null||o.length<n)&&(o=new Float32Array(n));for(let t=0,n=r;t!==a;++t,n+=4)s.copy(e[t]).applyMatrix4(i,c),s.normal.toArray(o,n),o[n+3]=s.constant}l.value=o,l.needsUpdate=!0}return n.numPlanes=a,n.numIntersection=0,o}}var h=4,g=[.125,.215,.35,.446,.526,.582],_=20,v=256,y=new e.X,b=new e.u,x=null,S=0,C=0,w=!1,T=new e.hn,E=class{constructor(e){this._renderer=e,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._sizeLods=[],this._sigmas=[],this._lodMeshes=[],this._backgroundBox=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._blurMaterial=null,this._ggxMaterial=null}fromScene(e,t=0,n=.1,r=100,i={}){let{size:a=256,position:o=T}=i;x=this._renderer.getRenderTarget(),S=this._renderer.getActiveCubeFace(),C=this._renderer.getActiveMipmapLevel(),w=this._renderer.xr.enabled,this._renderer.xr.enabled=!1,this._setSize(a);let s=this._allocateTargets();return s.depthBuffer=!0,this._sceneToCubeUV(e,n,r,s,o),t>0&&this._blur(s,0,0,t),this._applyPMREM(s),this._cleanup(s),s}fromEquirectangular(e,t=null){return this._fromTexture(e,t)}fromCubemap(e,t=null){return this._fromTexture(e,t)}compileCubemapShader(){this._cubemapMaterial===null&&(this._cubemapMaterial=N(),this._compileMaterial(this._cubemapMaterial))}compileEquirectangularShader(){this._equirectMaterial===null&&(this._equirectMaterial=M(),this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),this._cubemapMaterial!==null&&this._cubemapMaterial.dispose(),this._equirectMaterial!==null&&this._equirectMaterial.dispose(),this._backgroundBox!==null&&(this._backgroundBox.geometry.dispose(),this._backgroundBox.material.dispose())}_setSize(e){this._lodMax=Math.floor(Math.log2(e)),this._cubeSize=2**this._lodMax}_dispose(){this._blurMaterial!==null&&this._blurMaterial.dispose(),this._ggxMaterial!==null&&this._ggxMaterial.dispose(),this._pingPongRenderTarget!==null&&this._pingPongRenderTarget.dispose();for(let e=0;e<this._lodMeshes.length;e++)this._lodMeshes[e].geometry.dispose()}_cleanup(e){this._renderer.setRenderTarget(x,S,C),this._renderer.xr.enabled=w,e.scissorTest=!1,k(e,0,0,e.width,e.height)}_fromTexture(e,t){e.mapping===301||e.mapping===302?this._setSize(e.image.length===0?16:e.image[0].width||e.image[0].image.width):this._setSize(e.image.width/4),x=this._renderer.getRenderTarget(),S=this._renderer.getActiveCubeFace(),C=this._renderer.getActiveMipmapLevel(),w=this._renderer.xr.enabled,this._renderer.xr.enabled=!1;let n=t||this._allocateTargets();return this._textureToCubeUV(e,n),this._applyPMREM(n),this._cleanup(n),n}_allocateTargets(){let t=3*Math.max(this._cubeSize,112),n=4*this._cubeSize,r={magFilter:e.N,minFilter:e.N,generateMipmaps:!1,type:e.A,format:e.ot,colorSpace:e.I,depthBuffer:!1},i=O(t,n,r);if(this._pingPongRenderTarget===null||this._pingPongRenderTarget.width!==t||this._pingPongRenderTarget.height!==n){this._pingPongRenderTarget!==null&&this._dispose(),this._pingPongRenderTarget=O(t,n,r);let{_lodMax:e}=this;({lodMeshes:this._lodMeshes,sizeLods:this._sizeLods,sigmas:this._sigmas}=D(e)),this._blurMaterial=j(e,t,n),this._ggxMaterial=A(e,t,n)}return i}_compileMaterial(t){let n=new e.H(new e.s,t);this._renderer.compile(n,y)}_sceneToCubeUV(t,n,r,i,a){let o=new e.Z(90,1,n,r),s=[1,-1,1,1,1,1],c=[1,1,1,-1,-1,-1],l=this._renderer,u=l.autoClear,d=l.toneMapping;l.getClearColor(b),l.toneMapping=0,l.autoClear=!1,l.state.buffers.depth.getReversed()&&(l.setRenderTarget(i),l.clearDepth(),l.setRenderTarget(null)),this._backgroundBox===null&&(this._backgroundBox=new e.H(new e.a,new e.U({name:`PMREM.Background`,side:1,depthWrite:!1,depthTest:!1})));let f=this._backgroundBox,p=f.material,m=!1,h=t.background;h?h.isColor&&(p.color.copy(h),t.background=null,m=!0):(p.color.copy(b),m=!0);for(let e=0;e<6;e++){let n=e%3;n===0?(o.up.set(0,s[e],0),o.position.set(a.x,a.y,a.z),o.lookAt(a.x+c[e],a.y,a.z)):n===1?(o.up.set(0,0,s[e]),o.position.set(a.x,a.y,a.z),o.lookAt(a.x,a.y+c[e],a.z)):(o.up.set(0,s[e],0),o.position.set(a.x,a.y,a.z),o.lookAt(a.x,a.y,a.z+c[e]));let r=this._cubeSize;k(i,n*r,e>2?r:0,r,r),l.setRenderTarget(i),m&&l.render(f,o),l.render(t,o)}l.toneMapping=d,l.autoClear=u,t.background=h}_textureToCubeUV(e,t){let n=this._renderer,r=e.mapping===301||e.mapping===302;r?(this._cubemapMaterial===null&&(this._cubemapMaterial=N()),this._cubemapMaterial.uniforms.flipEnvMap.value=e.isRenderTargetTexture===!1?-1:1):this._equirectMaterial===null&&(this._equirectMaterial=M());let i=r?this._cubemapMaterial:this._equirectMaterial,a=this._lodMeshes[0];a.material=i;let o=i.uniforms;o.envMap.value=e;let s=this._cubeSize;k(t,0,0,3*s,2*s),n.setRenderTarget(t),n.render(a,y)}_applyPMREM(e){let t=this._renderer,n=t.autoClear;t.autoClear=!1;let r=this._lodMeshes.length;for(let t=1;t<r;t++)this._applyGGXFilter(e,t-1,t);t.autoClear=n}_applyGGXFilter(e,t,n){let r=this._renderer,i=this._pingPongRenderTarget,a=this._ggxMaterial,o=this._lodMeshes[n];o.material=a;let s=a.uniforms,c=n/(this._lodMeshes.length-1),l=t/(this._lodMeshes.length-1),u=Math.sqrt(c*c-l*l)*(0+c*1.25),{_lodMax:d}=this,f=this._sizeLods[n],p=3*f*(n>d-h?n-d+h:0),m=4*(this._cubeSize-f);s.envMap.value=e.texture,s.roughness.value=u,s.mipInt.value=d-t,k(i,p,m,3*f,2*f),r.setRenderTarget(i),r.render(o,y),s.envMap.value=i.texture,s.roughness.value=0,s.mipInt.value=d-n,k(e,p,m,3*f,2*f),r.setRenderTarget(e),r.render(o,y)}_blur(e,t,n,r,i){let a=this._pingPongRenderTarget;this._halfBlur(e,a,t,n,r,`latitudinal`,i),this._halfBlur(a,e,n,n,r,`longitudinal`,i)}_halfBlur(t,n,r,i,a,o,s){let c=this._renderer,l=this._blurMaterial;o!==`latitudinal`&&o!==`longitudinal`&&e.Cn(`blur direction must be either latitudinal or longitudinal!`);let u=this._lodMeshes[i];u.material=l;let d=l.uniforms,f=this._sizeLods[r]-1,p=isFinite(a)?Math.PI/(2*f):2*Math.PI/(2*_-1),m=a/p,g=isFinite(a)?1+Math.floor(3*m):_;g>_&&e.kn(`sigmaRadians, ${a}, is too large and will clip, as it requested ${g} samples when the maximum is set to ${_}`);let v=[],b=0;for(let e=0;e<_;++e){let t=e/m,n=Math.exp(-t*t/2);v.push(n),e===0?b+=n:e<g&&(b+=2*n)}for(let e=0;e<v.length;e++)v[e]=v[e]/b;d.envMap.value=t.texture,d.samples.value=g,d.weights.value=v,d.latitudinal.value=o===`latitudinal`,s&&(d.poleAxis.value=s);let{_lodMax:x}=this;d.dTheta.value=p,d.mipInt.value=x-r;let S=this._sizeLods[i];k(n,3*S*(i>x-h?i-x+h:0),4*(this._cubeSize-S),3*S,2*S),c.setRenderTarget(n),c.render(u,y)}};function D(t){let n=[],r=[],i=[],a=t,o=t-h+1+g.length;for(let s=0;s<o;s++){let o=2**a;n.push(o);let c=1/o;s>t-h?c=g[s-t+h-1]:s===0&&(c=0),r.push(c);let l=1/(o-2),u=-l,d=1+l,f=[u,u,d,u,d,d,u,u,d,d,u,d],p=new Float32Array(108),m=new Float32Array(72),_=new Float32Array(36);for(let e=0;e<6;e++){let t=e%3*2/3-1,n=e>2?0:-1,r=[t,n,0,t+2/3,n,0,t+2/3,n+1,0,t,n,0,t+2/3,n+1,0,t,n+1,0];p.set(r,18*e),m.set(f,12*e);let i=[e,e,e,e,e,e];_.set(i,6*e)}let v=new e.s;v.setAttribute(`position`,new e.o(p,3)),v.setAttribute(`uv`,new e.o(m,2)),v.setAttribute(`faceIndex`,new e.o(_,1)),i.push(new e.H(v,null)),a>h&&a--}return{lodMeshes:i,sizeLods:n,sigmas:r}}function O(t,n,r){let i=new e.vn(t,n,r);return i.texture.mapping=306,i.texture.name=`PMREM.cubeUv`,i.scissorTest=!0,i}function k(e,t,n,r,i){e.viewport.set(t,n,r,i),e.scissor.set(t,n,r,i)}function A(t,n,r){return new e.Qt({name:`PMREMGGXConvolution`,defines:{GGX_SAMPLES:v,CUBEUV_TEXEL_WIDTH:1/n,CUBEUV_TEXEL_HEIGHT:1/r,CUBEUV_MAX_MIP:`${t}.0`},uniforms:{envMap:{value:null},roughness:{value:0},mipInt:{value:0}},vertexShader:ee(),fragmentShader:`
3668
+
3669
+ precision highp float;
3670
+ precision highp int;
3671
+
3672
+ varying vec3 vOutputDirection;
3673
+
3674
+ uniform sampler2D envMap;
3675
+ uniform float roughness;
3676
+ uniform float mipInt;
3677
+
3678
+ #define ENVMAP_TYPE_CUBE_UV
3679
+ #include <cube_uv_reflection_fragment>
3680
+
3681
+ #define PI 3.14159265359
3682
+
3683
+ // Van der Corput radical inverse
3684
+ float radicalInverse_VdC(uint bits) {
3685
+ bits = (bits << 16u) | (bits >> 16u);
3686
+ bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u);
3687
+ bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);
3688
+ bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);
3689
+ bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);
3690
+ return float(bits) * 2.3283064365386963e-10; // / 0x100000000
3691
+ }
3692
+
3693
+ // Hammersley sequence
3694
+ vec2 hammersley(uint i, uint N) {
3695
+ return vec2(float(i) / float(N), radicalInverse_VdC(i));
3696
+ }
3697
+
3698
+ // GGX VNDF importance sampling (Eric Heitz 2018)
3699
+ // "Sampling the GGX Distribution of Visible Normals"
3700
+ // https://jcgt.org/published/0007/04/01/
3701
+ vec3 importanceSampleGGX_VNDF(vec2 Xi, vec3 V, float roughness) {
3702
+ float alpha = roughness * roughness;
3703
+
3704
+ // Section 4.1: Orthonormal basis
3705
+ vec3 T1 = vec3(1.0, 0.0, 0.0);
3706
+ vec3 T2 = cross(V, T1);
3707
+
3708
+ // Section 4.2: Parameterization of projected area
3709
+ float r = sqrt(Xi.x);
3710
+ float phi = 2.0 * PI * Xi.y;
3711
+ float t1 = r * cos(phi);
3712
+ float t2 = r * sin(phi);
3713
+ float s = 0.5 * (1.0 + V.z);
3714
+ t2 = (1.0 - s) * sqrt(1.0 - t1 * t1) + s * t2;
3715
+
3716
+ // Section 4.3: Reprojection onto hemisphere
3717
+ vec3 Nh = t1 * T1 + t2 * T2 + sqrt(max(0.0, 1.0 - t1 * t1 - t2 * t2)) * V;
3718
+
3719
+ // Section 3.4: Transform back to ellipsoid configuration
3720
+ return normalize(vec3(alpha * Nh.x, alpha * Nh.y, max(0.0, Nh.z)));
3721
+ }
3722
+
3723
+ void main() {
3724
+ vec3 N = normalize(vOutputDirection);
3725
+ vec3 V = N; // Assume view direction equals normal for pre-filtering
3726
+
3727
+ vec3 prefilteredColor = vec3(0.0);
3728
+ float totalWeight = 0.0;
3729
+
3730
+ // For very low roughness, just sample the environment directly
3731
+ if (roughness < 0.001) {
3732
+ gl_FragColor = vec4(bilinearCubeUV(envMap, N, mipInt), 1.0);
3733
+ return;
3734
+ }
3735
+
3736
+ // Tangent space basis for VNDF sampling
3737
+ vec3 up = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);
3738
+ vec3 tangent = normalize(cross(up, N));
3739
+ vec3 bitangent = cross(N, tangent);
3740
+
3741
+ for(uint i = 0u; i < uint(GGX_SAMPLES); i++) {
3742
+ vec2 Xi = hammersley(i, uint(GGX_SAMPLES));
3743
+
3744
+ // For PMREM, V = N, so in tangent space V is always (0, 0, 1)
3745
+ vec3 H_tangent = importanceSampleGGX_VNDF(Xi, vec3(0.0, 0.0, 1.0), roughness);
3746
+
3747
+ // Transform H back to world space
3748
+ vec3 H = normalize(tangent * H_tangent.x + bitangent * H_tangent.y + N * H_tangent.z);
3749
+ vec3 L = normalize(2.0 * dot(V, H) * H - V);
3750
+
3751
+ float NdotL = max(dot(N, L), 0.0);
3752
+
3753
+ if(NdotL > 0.0) {
3754
+ // Sample environment at fixed mip level
3755
+ // VNDF importance sampling handles the distribution filtering
3756
+ vec3 sampleColor = bilinearCubeUV(envMap, L, mipInt);
3757
+
3758
+ // Weight by NdotL for the split-sum approximation
3759
+ // VNDF PDF naturally accounts for the visible microfacet distribution
3760
+ prefilteredColor += sampleColor * NdotL;
3761
+ totalWeight += NdotL;
3762
+ }
3763
+ }
3764
+
3765
+ if (totalWeight > 0.0) {
3766
+ prefilteredColor = prefilteredColor / totalWeight;
3767
+ }
3768
+
3769
+ gl_FragColor = vec4(prefilteredColor, 1.0);
3770
+ }
3771
+ `,blending:0,depthTest:!1,depthWrite:!1})}function j(t,n,r){let i=new Float32Array(_),a=new e.hn(0,1,0);return new e.Qt({name:`SphericalGaussianBlur`,defines:{n:_,CUBEUV_TEXEL_WIDTH:1/n,CUBEUV_TEXEL_HEIGHT:1/r,CUBEUV_MAX_MIP:`${t}.0`},uniforms:{envMap:{value:null},samples:{value:1},weights:{value:i},latitudinal:{value:!1},dTheta:{value:0},mipInt:{value:0},poleAxis:{value:a}},vertexShader:ee(),fragmentShader:`
3772
+
3773
+ precision mediump float;
3774
+ precision mediump int;
3775
+
3776
+ varying vec3 vOutputDirection;
3777
+
3778
+ uniform sampler2D envMap;
3779
+ uniform int samples;
3780
+ uniform float weights[ n ];
3781
+ uniform bool latitudinal;
3782
+ uniform float dTheta;
3783
+ uniform float mipInt;
3784
+ uniform vec3 poleAxis;
3785
+
3786
+ #define ENVMAP_TYPE_CUBE_UV
3787
+ #include <cube_uv_reflection_fragment>
3788
+
3789
+ vec3 getSample( float theta, vec3 axis ) {
3790
+
3791
+ float cosTheta = cos( theta );
3792
+ // Rodrigues' axis-angle rotation
3793
+ vec3 sampleDirection = vOutputDirection * cosTheta
3794
+ + cross( axis, vOutputDirection ) * sin( theta )
3795
+ + axis * dot( axis, vOutputDirection ) * ( 1.0 - cosTheta );
3796
+
3797
+ return bilinearCubeUV( envMap, sampleDirection, mipInt );
3798
+
3799
+ }
3800
+
3801
+ void main() {
3802
+
3803
+ vec3 axis = latitudinal ? poleAxis : cross( poleAxis, vOutputDirection );
3804
+
3805
+ if ( all( equal( axis, vec3( 0.0 ) ) ) ) {
3806
+
3807
+ axis = vec3( vOutputDirection.z, 0.0, - vOutputDirection.x );
3808
+
3809
+ }
3810
+
3811
+ axis = normalize( axis );
3812
+
3813
+ gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );
3814
+ gl_FragColor.rgb += weights[ 0 ] * getSample( 0.0, axis );
3815
+
3816
+ for ( int i = 1; i < n; i++ ) {
3817
+
3818
+ if ( i >= samples ) {
3819
+
3820
+ break;
3821
+
3822
+ }
3823
+
3824
+ float theta = dTheta * float( i );
3825
+ gl_FragColor.rgb += weights[ i ] * getSample( -1.0 * theta, axis );
3826
+ gl_FragColor.rgb += weights[ i ] * getSample( theta, axis );
3827
+
3828
+ }
3829
+
3830
+ }
3831
+ `,blending:0,depthTest:!1,depthWrite:!1})}function M(){return new e.Qt({name:`EquirectangularToCubeUV`,uniforms:{envMap:{value:null}},vertexShader:ee(),fragmentShader:`
3832
+
3833
+ precision mediump float;
3834
+ precision mediump int;
3835
+
3836
+ varying vec3 vOutputDirection;
3837
+
3838
+ uniform sampler2D envMap;
3839
+
3840
+ #include <common>
3841
+
3842
+ void main() {
3843
+
3844
+ vec3 outputDirection = normalize( vOutputDirection );
3845
+ vec2 uv = equirectUv( outputDirection );
3846
+
3847
+ gl_FragColor = vec4( texture2D ( envMap, uv ).rgb, 1.0 );
3848
+
3849
+ }
3850
+ `,blending:0,depthTest:!1,depthWrite:!1})}function N(){return new e.Qt({name:`CubemapToCubeUV`,uniforms:{envMap:{value:null},flipEnvMap:{value:-1}},vertexShader:ee(),fragmentShader:`
3851
+
3852
+ precision mediump float;
3853
+ precision mediump int;
3854
+
3855
+ uniform float flipEnvMap;
3856
+
3857
+ varying vec3 vOutputDirection;
3858
+
3859
+ uniform samplerCube envMap;
3860
+
3861
+ void main() {
3862
+
3863
+ gl_FragColor = textureCube( envMap, vec3( flipEnvMap * vOutputDirection.x, vOutputDirection.yz ) );
3864
+
3865
+ }
3866
+ `,blending:0,depthTest:!1,depthWrite:!1})}function ee(){return`
3867
+
3868
+ precision mediump float;
3869
+ precision mediump int;
3870
+
3871
+ attribute float faceIndex;
3872
+
3873
+ varying vec3 vOutputDirection;
3874
+
3875
+ // RH coordinate system; PMREM face-indexing convention
3876
+ vec3 getDirection( vec2 uv, float face ) {
3877
+
3878
+ uv = 2.0 * uv - 1.0;
3879
+
3880
+ vec3 direction = vec3( uv, 1.0 );
3881
+
3882
+ if ( face == 0.0 ) {
3883
+
3884
+ direction = direction.zyx; // ( 1, v, u ) pos x
3885
+
3886
+ } else if ( face == 1.0 ) {
3887
+
3888
+ direction = direction.xzy;
3889
+ direction.xz *= -1.0; // ( -u, 1, -v ) pos y
3890
+
3891
+ } else if ( face == 2.0 ) {
3892
+
3893
+ direction.x *= -1.0; // ( -u, v, 1 ) pos z
3894
+
3895
+ } else if ( face == 3.0 ) {
3896
+
3897
+ direction = direction.zyx;
3898
+ direction.xz *= -1.0; // ( -1, v, -u ) neg x
3899
+
3900
+ } else if ( face == 4.0 ) {
3901
+
3902
+ direction = direction.xzy;
3903
+ direction.xy *= -1.0; // ( -u, -1, v ) neg y
3904
+
3905
+ } else if ( face == 5.0 ) {
3906
+
3907
+ direction.z *= -1.0; // ( u, v, -1 ) neg z
3908
+
3909
+ }
3910
+
3911
+ return direction;
3912
+
3913
+ }
3914
+
3915
+ void main() {
3916
+
3917
+ vOutputDirection = getDirection( uv, faceIndex );
3918
+ gl_Position = vec4( position, 1.0 );
3919
+
3920
+ }
3921
+ `}var P=class extends e.vn{constructor(t=1,n={}){super(t,t,n),this.isWebGLCubeRenderTarget=!0;let r={width:t,height:t,depth:1},i=[r,r,r,r,r,r];this.texture=new e.h(i),this._setTextureOptions(n),this.texture.isRenderTargetTexture=!0}fromEquirectangularTexture(t,n){this.texture.type=n.type,this.texture.colorSpace=n.colorSpace,this.texture.generateMipmaps=n.generateMipmaps,this.texture.minFilter=n.minFilter,this.texture.magFilter=n.magFilter;let r={uniforms:{tEquirect:{value:null}},vertexShader:`
3922
+
3923
+ varying vec3 vWorldDirection;
3924
+
3925
+ vec3 transformDirection( in vec3 dir, in mat4 matrix ) {
3926
+
3927
+ return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );
3928
+
3929
+ }
3930
+
3931
+ void main() {
3932
+
3933
+ vWorldDirection = transformDirection( position, modelMatrix );
3934
+
3935
+ #include <begin_vertex>
3936
+ #include <project_vertex>
3937
+
3938
+ }
3939
+ `,fragmentShader:`
3940
+
3941
+ uniform sampler2D tEquirect;
3942
+
3943
+ varying vec3 vWorldDirection;
3944
+
3945
+ #include <common>
3946
+
3947
+ void main() {
3948
+
3949
+ vec3 direction = normalize( vWorldDirection );
3950
+
3951
+ vec2 sampleUV = equirectUv( direction );
3952
+
3953
+ gl_FragColor = texture2D( tEquirect, sampleUV );
3954
+
3955
+ }
3956
+ `},i=new e.a(5,5,5),a=new e.Qt({name:`CubemapFromEquirect`,uniforms:e.bn(r.uniforms),vertexShader:r.vertexShader,fragmentShader:r.fragmentShader,side:1,blending:0});a.uniforms.tEquirect.value=n;let o=new e.H(i,a),s=n.minFilter;return n.minFilter===1008&&(n.minFilter=e.N),new e.p(1,10,this).update(t,o),n.minFilter=s,o.geometry.dispose(),o.material.dispose(),this}clear(e,t=!0,n=!0,r=!0){let i=e.getRenderTarget();for(let i=0;i<6;i++)e.setRenderTarget(this,i),e.clear(t,n,r);e.setRenderTarget(i)}};function te(e){let t=new WeakMap,n=new WeakMap,r=null;function i(e,t=!1){return e==null?null:t?o(e):a(e)}function a(n){if(n&&n.isTexture){let r=n.mapping;if(r===303||r===304)if(t.has(n)){let e=t.get(n).texture;return s(e,n.mapping)}else{let r=n.image;if(r&&r.height>0){let i=new P(r.height);return i.fromEquirectangularTexture(e,n),t.set(n,i),n.addEventListener(`dispose`,l),s(i.texture,n.mapping)}else return null}}return n}function o(t){if(t&&t.isTexture){let i=t.mapping,a=i===303||i===304,o=i===301||i===302;if(a||o){let i=n.get(t),s=i===void 0?0:i.texture.pmremVersion;if(t.isRenderTargetTexture&&t.pmremVersion!==s)return r===null&&(r=new E(e)),i=a?r.fromEquirectangular(t,i):r.fromCubemap(t,i),i.texture.pmremVersion=t.pmremVersion,n.set(t,i),i.texture;if(i!==void 0)return i.texture;{let s=t.image;return a&&s&&s.height>0||o&&s&&c(s)?(r===null&&(r=new E(e)),i=a?r.fromEquirectangular(t):r.fromCubemap(t),i.texture.pmremVersion=t.pmremVersion,n.set(t,i),t.addEventListener(`dispose`,u),i.texture):null}}}return t}function s(e,t){return t===303?e.mapping=301:t===304&&(e.mapping=302),e}function c(e){let t=0;for(let n=0;n<6;n++)e[n]!==void 0&&t++;return t===6}function l(e){let n=e.target;n.removeEventListener(`dispose`,l);let r=t.get(n);r!==void 0&&(t.delete(n),r.dispose())}function u(e){let t=e.target;t.removeEventListener(`dispose`,u);let r=n.get(t);r!==void 0&&(n.delete(t),r.dispose())}function d(){t=new WeakMap,n=new WeakMap,r!==null&&(r.dispose(),r=null)}return{get:i,dispose:d}}function ne(t){let n={};function r(e){if(n[e]!==void 0)return n[e];let r=t.getExtension(e);return n[e]=r,r}return{has:function(e){return r(e)!==null},init:function(){r(`EXT_color_buffer_float`),r(`WEBGL_clip_cull_distance`),r(`OES_texture_float_linear`),r(`EXT_color_buffer_half_float`),r(`WEBGL_multisampled_render_to_texture`),r(`WEBGL_render_shared_exponent`)},get:function(t){let n=r(t);return n===null&&e.An(`WebGLRenderer: `+t+` extension not supported.`),n}}}function re(t,n,r,i){let a={},o=new WeakMap;function s(e){let t=e.target;t.index!==null&&n.remove(t.index);for(let e in t.attributes)n.remove(t.attributes[e]);t.removeEventListener(`dispose`,s),delete a[t.id];let c=o.get(t);c&&(n.remove(c),o.delete(t)),i.releaseStatesOfGeometry(t),t.isInstancedBufferGeometry===!0&&delete t._maxInstanceCount,r.memory.geometries--}function c(e,t){return a[t.id]===!0?t:(t.addEventListener(`dispose`,s),a[t.id]=!0,r.memory.geometries++,t)}function l(e){let r=e.attributes;for(let e in r)n.update(r[e],t.ARRAY_BUFFER)}function u(t){let r=[],i=t.index,a=t.attributes.position,s=0;if(a===void 0)return;if(i!==null){let e=i.array;s=i.version;for(let t=0,n=e.length;t<n;t+=3){let n=e[t+0],i=e[t+1],a=e[t+2];r.push(n,i,i,a,a,n)}}else{let e=a.array;s=a.version;for(let t=0,n=e.length/3-1;t<n;t+=3){let e=t+0,n=t+1,i=t+2;r.push(e,n,n,i,i,e)}}let c=new(a.count>=65535?e.in:e.rn)(r,1);c.version=s;let l=o.get(t);l&&n.remove(l),o.set(t,c)}function d(e){let t=o.get(e);if(t){let n=e.index;n!==null&&t.version<n.version&&u(e)}else u(e);return o.get(e)}return{get:c,update:l,getWireframeAttribute:d}}function ie(e,t,n){let r;function i(e){r=e}let a,o;function s(e){a=e.type,o=e.bytesPerElement}function c(t,i){e.drawElements(r,i,a,t*o),n.update(i,r,1)}function l(t,i,s){s!==0&&(e.drawElementsInstanced(r,i,a,t*o,s),n.update(i,r,s))}function u(e,i,o){if(o===0)return;t.get(`WEBGL_multi_draw`).multiDrawElementsWEBGL(r,i,0,a,e,0,o);let s=0;for(let e=0;e<o;e++)s+=i[e];n.update(s,r,1)}this.setMode=i,this.setIndex=s,this.render=c,this.renderInstances=l,this.renderMultiDraw=u}function ae(t){let n={geometries:0,textures:0},r={frame:0,calls:0,triangles:0,points:0,lines:0};function i(n,i,a){switch(r.calls++,i){case t.TRIANGLES:r.triangles+=n/3*a;break;case t.LINES:r.lines+=n/2*a;break;case t.LINE_STRIP:r.lines+=a*(n-1);break;case t.LINE_LOOP:r.lines+=a*n;break;case t.POINTS:r.points+=a*n;break;default:e.Cn(`WebGLInfo: Unknown draw mode:`,i);break}}function a(){r.calls=0,r.triangles=0,r.points=0,r.lines=0}return{memory:n,render:r,programs:null,autoReset:!0,reset:a,update:i}}function oe(t,n,r){let i=new WeakMap,a=new e.gn;function o(o,s,c){let l=o.morphTargetInfluences,u=s.morphAttributes.position||s.morphAttributes.normal||s.morphAttributes.color,d=u===void 0?0:u.length,f=i.get(s);if(f===void 0||f.count!==d){f!==void 0&&f.texture.dispose();let t=s.morphAttributes.position!==void 0,r=s.morphAttributes.normal!==void 0,o=s.morphAttributes.color!==void 0,c=s.morphAttributes.position||[],l=s.morphAttributes.normal||[],u=s.morphAttributes.color||[],m=0;t===!0&&(m=1),r===!0&&(m=2),o===!0&&(m=3);let h=s.attributes.position.count*m,g=1;h>n.maxTextureSize&&(g=Math.ceil(h/n.maxTextureSize),h=n.maxTextureSize);let _=new Float32Array(h*g*4*d),v=new e._(_,h,g,d);v.type=e.E,v.needsUpdate=!0;let y=m*4;for(let e=0;e<d;e++){let n=c[e],i=l[e],s=u[e],d=h*g*4*e;for(let e=0;e<n.count;e++){let c=e*y;t===!0&&(a.fromBufferAttribute(n,e),_[d+c+0]=a.x,_[d+c+1]=a.y,_[d+c+2]=a.z,_[d+c+3]=0),r===!0&&(a.fromBufferAttribute(i,e),_[d+c+4]=a.x,_[d+c+5]=a.y,_[d+c+6]=a.z,_[d+c+7]=0),o===!0&&(a.fromBufferAttribute(s,e),_[d+c+8]=a.x,_[d+c+9]=a.y,_[d+c+10]=a.z,_[d+c+11]=s.itemSize===4?a.w:1)}}f={count:d,texture:v,size:new e.mn(h,g)},i.set(s,f);function p(){v.dispose(),i.delete(s),s.removeEventListener(`dispose`,p)}s.addEventListener(`dispose`,p)}if(o.isInstancedMesh===!0&&o.morphTexture!==null)c.getUniforms().setValue(t,`morphTexture`,o.morphTexture,r);else{let e=0;for(let t=0;t<l.length;t++)e+=l[t];let n=s.morphTargetsRelative?1:1-e;c.getUniforms().setValue(t,`morphTargetBaseInfluence`,n),c.getUniforms().setValue(t,`morphTargetInfluences`,l)}c.getUniforms().setValue(t,`morphTargetsTexture`,f.texture,r),c.getUniforms().setValue(t,`morphTargetsTextureSize`,f.size)}return{update:o}}function se(e,t,n,r,i){let a=new WeakMap;function o(r){let o=i.render.frame,s=r.geometry,l=t.get(r,s);if(a.get(l)!==o&&(t.update(l),a.set(l,o)),r.isInstancedMesh&&(r.hasEventListener(`dispose`,c)===!1&&r.addEventListener(`dispose`,c),a.get(r)!==o&&(n.update(r.instanceMatrix,e.ARRAY_BUFFER),r.instanceColor!==null&&n.update(r.instanceColor,e.ARRAY_BUFFER),a.set(r,o))),r.isSkinnedMesh){let e=r.skeleton;a.get(e)!==o&&(e.update(),a.set(e,o))}return l}function s(){a=new WeakMap}function c(e){let t=e.target;t.removeEventListener(`dispose`,c),r.releaseStatesOfObject(t),n.remove(t.instanceMatrix),t.instanceColor!==null&&n.remove(t.instanceColor)}return{update:o,dispose:s}}var ce={1:`LINEAR_TONE_MAPPING`,2:`REINHARD_TONE_MAPPING`,3:`CINEON_TONE_MAPPING`,4:`ACES_FILMIC_TONE_MAPPING`,6:`AGX_TONE_MAPPING`,7:`NEUTRAL_TONE_MAPPING`,5:`CUSTOM_TONE_MAPPING`};function le(t,n,r,i,a,o){let s=new e.vn(n,r,{type:t,depthBuffer:a,stencilBuffer:o,samples:i?4:0,depthTexture:a?new e.x(n,r):void 0}),c=new e.vn(n,r,{type:e.A,depthBuffer:!1,stencilBuffer:!1}),l=new e.s;l.setAttribute(`position`,new e.T([-1,3,0,-1,-1,0,3,-1,0],3)),l.setAttribute(`uv`,new e.T([0,2,0,0,2,0],2));let u=new e.zt({uniforms:{tDiffuse:{value:null}},vertexShader:`
3957
+ precision highp float;
3958
+
3959
+ uniform mat4 modelViewMatrix;
3960
+ uniform mat4 projectionMatrix;
3961
+
3962
+ attribute vec3 position;
3963
+ attribute vec2 uv;
3964
+
3965
+ varying vec2 vUv;
3966
+
3967
+ void main() {
3968
+ vUv = uv;
3969
+ gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
3970
+ }`,fragmentShader:`
3971
+ precision highp float;
3972
+
3973
+ uniform sampler2D tDiffuse;
3974
+
3975
+ varying vec2 vUv;
3976
+
3977
+ #include <tonemapping_pars_fragment>
3978
+ #include <colorspace_pars_fragment>
3979
+
3980
+ void main() {
3981
+ gl_FragColor = texture2D( tDiffuse, vUv );
3982
+
3983
+ #ifdef LINEAR_TONE_MAPPING
3984
+ gl_FragColor.rgb = LinearToneMapping( gl_FragColor.rgb );
3985
+ #elif defined( REINHARD_TONE_MAPPING )
3986
+ gl_FragColor.rgb = ReinhardToneMapping( gl_FragColor.rgb );
3987
+ #elif defined( CINEON_TONE_MAPPING )
3988
+ gl_FragColor.rgb = CineonToneMapping( gl_FragColor.rgb );
3989
+ #elif defined( ACES_FILMIC_TONE_MAPPING )
3990
+ gl_FragColor.rgb = ACESFilmicToneMapping( gl_FragColor.rgb );
3991
+ #elif defined( AGX_TONE_MAPPING )
3992
+ gl_FragColor.rgb = AgXToneMapping( gl_FragColor.rgb );
3993
+ #elif defined( NEUTRAL_TONE_MAPPING )
3994
+ gl_FragColor.rgb = NeutralToneMapping( gl_FragColor.rgb );
3995
+ #elif defined( CUSTOM_TONE_MAPPING )
3996
+ gl_FragColor.rgb = CustomToneMapping( gl_FragColor.rgb );
3997
+ #endif
3998
+
3999
+ #ifdef SRGB_TRANSFER
4000
+ gl_FragColor = sRGBTransferOETF( gl_FragColor );
4001
+ #endif
4002
+ }`,depthTest:!1,depthWrite:!1}),d=new e.H(l,u),f=new e.X(-1,1,1,-1,0,1),p=null,m=null,h=!1,g,_=null,v=[],y=!1;this.setSize=function(e,t){s.setSize(e,t),c.setSize(e,t);for(let n=0;n<v.length;n++){let r=v[n];r.setSize&&r.setSize(e,t)}},this.setEffects=function(e){v=e,y=v.length>0&&v[0].isRenderPass===!0;let t=s.width,n=s.height;for(let e=0;e<v.length;e++){let r=v[e];r.setSize&&r.setSize(t,n)}},this.begin=function(e,t){if(h||e.toneMapping===0&&v.length===0)return!1;if(_=t,t!==null){let e=t.width,n=t.height;(s.width!==e||s.height!==n)&&this.setSize(e,n)}return y===!1&&e.setRenderTarget(s),g=e.toneMapping,e.toneMapping=0,!0},this.hasRenderPass=function(){return y},this.end=function(t,n){t.toneMapping=g,h=!0;let r=s,i=c;for(let e=0;e<v.length;e++){let a=v[e];if(a.enabled!==!1&&(a.render(t,i,r,n),a.needsSwap!==!1)){let e=r;r=i,i=e}}if(p!==t.outputColorSpace||m!==t.toneMapping){p=t.outputColorSpace,m=t.toneMapping,u.defines={},e.d.getTransfer(p)===`srgb`&&(u.defines.SRGB_TRANSFER=``);let n=ce[m];n&&(u.defines[n]=``),u.needsUpdate=!0}u.uniforms.tDiffuse.value=r.texture,t.setRenderTarget(_),t.render(d,f),_=null,h=!1},this.isCompositing=function(){return h},this.dispose=function(){s.depthTexture&&s.depthTexture.dispose(),s.dispose(),c.dispose(),l.dispose(),u.dispose()}}var F=new e.nn,I=new e.x(1,1),ue=new e._,L=new e.g,R=new e.h,de=[],z=[],B=new Float32Array(16),fe=new Float32Array(9),pe=new Float32Array(4);function me(e,t,n){let r=e[0];if(r<=0||r>0)return e;let i=t*n,a=de[i];if(a===void 0&&(a=new Float32Array(i),de[i]=a),t!==0){r.toArray(a,0);for(let r=1,i=0;r!==t;++r)i+=n,e[r].toArray(a,i)}return a}function V(e,t){if(e.length!==t.length)return!1;for(let n=0,r=e.length;n<r;n++)if(e[n]!==t[n])return!1;return!0}function H(e,t){for(let n=0,r=t.length;n<r;n++)e[n]=t[n]}function U(e,t){let n=z[t];n===void 0&&(n=new Int32Array(t),z[t]=n);for(let r=0;r!==t;++r)n[r]=e.allocateTextureUnit();return n}function W(e,t){let n=this.cache;n[0]!==t&&(e.uniform1f(this.addr,t),n[0]=t)}function he(e,t){let n=this.cache;if(t.x!==void 0)(n[0]!==t.x||n[1]!==t.y)&&(e.uniform2f(this.addr,t.x,t.y),n[0]=t.x,n[1]=t.y);else{if(V(n,t))return;e.uniform2fv(this.addr,t),H(n,t)}}function ge(e,t){let n=this.cache;if(t.x!==void 0)(n[0]!==t.x||n[1]!==t.y||n[2]!==t.z)&&(e.uniform3f(this.addr,t.x,t.y,t.z),n[0]=t.x,n[1]=t.y,n[2]=t.z);else if(t.r!==void 0)(n[0]!==t.r||n[1]!==t.g||n[2]!==t.b)&&(e.uniform3f(this.addr,t.r,t.g,t.b),n[0]=t.r,n[1]=t.g,n[2]=t.b);else{if(V(n,t))return;e.uniform3fv(this.addr,t),H(n,t)}}function _e(e,t){let n=this.cache;if(t.x!==void 0)(n[0]!==t.x||n[1]!==t.y||n[2]!==t.z||n[3]!==t.w)&&(e.uniform4f(this.addr,t.x,t.y,t.z,t.w),n[0]=t.x,n[1]=t.y,n[2]=t.z,n[3]=t.w);else{if(V(n,t))return;e.uniform4fv(this.addr,t),H(n,t)}}function ve(e,t){let n=this.cache,r=t.elements;if(r===void 0){if(V(n,t))return;e.uniformMatrix2fv(this.addr,!1,t),H(n,t)}else{if(V(n,r))return;pe.set(r),e.uniformMatrix2fv(this.addr,!1,pe),H(n,r)}}function ye(e,t){let n=this.cache,r=t.elements;if(r===void 0){if(V(n,t))return;e.uniformMatrix3fv(this.addr,!1,t),H(n,t)}else{if(V(n,r))return;fe.set(r),e.uniformMatrix3fv(this.addr,!1,fe),H(n,r)}}function be(e,t){let n=this.cache,r=t.elements;if(r===void 0){if(V(n,t))return;e.uniformMatrix4fv(this.addr,!1,t),H(n,t)}else{if(V(n,r))return;B.set(r),e.uniformMatrix4fv(this.addr,!1,B),H(n,r)}}function xe(e,t){let n=this.cache;n[0]!==t&&(e.uniform1i(this.addr,t),n[0]=t)}function Se(e,t){let n=this.cache;if(t.x!==void 0)(n[0]!==t.x||n[1]!==t.y)&&(e.uniform2i(this.addr,t.x,t.y),n[0]=t.x,n[1]=t.y);else{if(V(n,t))return;e.uniform2iv(this.addr,t),H(n,t)}}function Ce(e,t){let n=this.cache;if(t.x!==void 0)(n[0]!==t.x||n[1]!==t.y||n[2]!==t.z)&&(e.uniform3i(this.addr,t.x,t.y,t.z),n[0]=t.x,n[1]=t.y,n[2]=t.z);else{if(V(n,t))return;e.uniform3iv(this.addr,t),H(n,t)}}function we(e,t){let n=this.cache;if(t.x!==void 0)(n[0]!==t.x||n[1]!==t.y||n[2]!==t.z||n[3]!==t.w)&&(e.uniform4i(this.addr,t.x,t.y,t.z,t.w),n[0]=t.x,n[1]=t.y,n[2]=t.z,n[3]=t.w);else{if(V(n,t))return;e.uniform4iv(this.addr,t),H(n,t)}}function Te(e,t){let n=this.cache;n[0]!==t&&(e.uniform1ui(this.addr,t),n[0]=t)}function Ee(e,t){let n=this.cache;if(t.x!==void 0)(n[0]!==t.x||n[1]!==t.y)&&(e.uniform2ui(this.addr,t.x,t.y),n[0]=t.x,n[1]=t.y);else{if(V(n,t))return;e.uniform2uiv(this.addr,t),H(n,t)}}function De(e,t){let n=this.cache;if(t.x!==void 0)(n[0]!==t.x||n[1]!==t.y||n[2]!==t.z)&&(e.uniform3ui(this.addr,t.x,t.y,t.z),n[0]=t.x,n[1]=t.y,n[2]=t.z);else{if(V(n,t))return;e.uniform3uiv(this.addr,t),H(n,t)}}function Oe(e,t){let n=this.cache;if(t.x!==void 0)(n[0]!==t.x||n[1]!==t.y||n[2]!==t.z||n[3]!==t.w)&&(e.uniform4ui(this.addr,t.x,t.y,t.z,t.w),n[0]=t.x,n[1]=t.y,n[2]=t.z,n[3]=t.w);else{if(V(n,t))return;e.uniform4uiv(this.addr,t),H(n,t)}}function G(e,t,n){let r=this.cache,i=n.allocateTextureUnit();r[0]!==i&&(e.uniform1i(this.addr,i),r[0]=i);let a;this.type===e.SAMPLER_2D_SHADOW?(I.compareFunction=n.isReversedDepthBuffer()?518:515,a=I):a=F,n.setTexture2D(t||a,i)}function ke(e,t,n){let r=this.cache,i=n.allocateTextureUnit();r[0]!==i&&(e.uniform1i(this.addr,i),r[0]=i),n.setTexture3D(t||L,i)}function K(e,t,n){let r=this.cache,i=n.allocateTextureUnit();r[0]!==i&&(e.uniform1i(this.addr,i),r[0]=i),n.setTextureCube(t||R,i)}function q(e,t,n){let r=this.cache,i=n.allocateTextureUnit();r[0]!==i&&(e.uniform1i(this.addr,i),r[0]=i),n.setTexture2DArray(t||ue,i)}function J(e){switch(e){case 5126:return W;case 35664:return he;case 35665:return ge;case 35666:return _e;case 35674:return ve;case 35675:return ye;case 35676:return be;case 5124:case 35670:return xe;case 35667:case 35671:return Se;case 35668:case 35672:return Ce;case 35669:case 35673:return we;case 5125:return Te;case 36294:return Ee;case 36295:return De;case 36296:return Oe;case 35678:case 36198:case 36298:case 36306:case 35682:return G;case 35679:case 36299:case 36307:return ke;case 35680:case 36300:case 36308:case 36293:return K;case 36289:case 36303:case 36311:case 36292:return q}}function Ae(e,t){e.uniform1fv(this.addr,t)}function Y(e,t){let n=me(t,this.size,2);e.uniform2fv(this.addr,n)}function X(e,t){let n=me(t,this.size,3);e.uniform3fv(this.addr,n)}function je(e,t){let n=me(t,this.size,4);e.uniform4fv(this.addr,n)}function Me(e,t){let n=me(t,this.size,4);e.uniformMatrix2fv(this.addr,!1,n)}function Ne(e,t){let n=me(t,this.size,9);e.uniformMatrix3fv(this.addr,!1,n)}function Pe(e,t){let n=me(t,this.size,16);e.uniformMatrix4fv(this.addr,!1,n)}function Fe(e,t){e.uniform1iv(this.addr,t)}function Ie(e,t){e.uniform2iv(this.addr,t)}function Le(e,t){e.uniform3iv(this.addr,t)}function Re(e,t){e.uniform4iv(this.addr,t)}function ze(e,t){e.uniform1uiv(this.addr,t)}function Be(e,t){e.uniform2uiv(this.addr,t)}function Ve(e,t){e.uniform3uiv(this.addr,t)}function He(e,t){e.uniform4uiv(this.addr,t)}function Ue(e,t,n){let r=this.cache,i=t.length,a=U(n,i);V(r,a)||(e.uniform1iv(this.addr,a),H(r,a));let o;o=this.type===e.SAMPLER_2D_SHADOW?I:F;for(let e=0;e!==i;++e)n.setTexture2D(t[e]||o,a[e])}function We(e,t,n){let r=this.cache,i=t.length,a=U(n,i);V(r,a)||(e.uniform1iv(this.addr,a),H(r,a));for(let e=0;e!==i;++e)n.setTexture3D(t[e]||L,a[e])}function Ge(e,t,n){let r=this.cache,i=t.length,a=U(n,i);V(r,a)||(e.uniform1iv(this.addr,a),H(r,a));for(let e=0;e!==i;++e)n.setTextureCube(t[e]||R,a[e])}function Ke(e,t,n){let r=this.cache,i=t.length,a=U(n,i);V(r,a)||(e.uniform1iv(this.addr,a),H(r,a));for(let e=0;e!==i;++e)n.setTexture2DArray(t[e]||ue,a[e])}function qe(e){switch(e){case 5126:return Ae;case 35664:return Y;case 35665:return X;case 35666:return je;case 35674:return Me;case 35675:return Ne;case 35676:return Pe;case 5124:case 35670:return Fe;case 35667:case 35671:return Ie;case 35668:case 35672:return Le;case 35669:case 35673:return Re;case 5125:return ze;case 36294:return Be;case 36295:return Ve;case 36296:return He;case 35678:case 36198:case 36298:case 36306:case 35682:return Ue;case 35679:case 36299:case 36307:return We;case 35680:case 36300:case 36308:case 36293:return Ge;case 36289:case 36303:case 36311:case 36292:return Ke}}var Je=class{constructor(e,t,n){this.id=e,this.addr=n,this.cache=[],this.type=t.type,this.setValue=J(t.type)}},Z=class{constructor(e,t,n){this.id=e,this.addr=n,this.cache=[],this.type=t.type,this.size=t.size,this.setValue=qe(t.type)}},Ye=class{constructor(e){this.id=e,this.seq=[],this.map={}}setValue(e,t,n){let r=this.seq;for(let i=0,a=r.length;i!==a;++i){let a=r[i];a.setValue(e,t[a.id],n)}}},Xe=/(\w+)(\])?(\[|\.)?/g;function Ze(e,t){e.seq.push(t),e.map[t.id]=t}function Qe(e,t,n){let r=e.name,i=r.length;for(Xe.lastIndex=0;;){let a=Xe.exec(r),o=Xe.lastIndex,s=a[1],c=a[2]===`]`,l=a[3];if(c&&(s|=0),l===void 0||l===`[`&&o+2===i){Ze(n,l===void 0?new Je(s,e,t):new Z(s,e,t));break}else{let e=n.map[s];e===void 0&&(e=new Ye(s),Ze(n,e)),n=e}}}var $e=class{constructor(e,t){this.seq=[],this.map={};let n=e.getProgramParameter(t,e.ACTIVE_UNIFORMS);for(let r=0;r<n;++r){let n=e.getActiveUniform(t,r);Qe(n,e.getUniformLocation(t,n.name),this)}let r=[],i=[];for(let t of this.seq)t.type===e.SAMPLER_2D_SHADOW||t.type===e.SAMPLER_CUBE_SHADOW||t.type===e.SAMPLER_2D_ARRAY_SHADOW?r.push(t):i.push(t);r.length>0&&(this.seq=r.concat(i))}setValue(e,t,n,r){let i=this.map[t];i!==void 0&&i.setValue(e,n,r)}setOptional(e,t,n){let r=t[n];r!==void 0&&this.setValue(e,n,r)}static upload(e,t,n,r){for(let i=0,a=t.length;i!==a;++i){let a=t[i],o=n[a.id];o.needsUpdate!==!1&&a.setValue(e,o.value,r)}}static seqWithValue(e,t){let n=[];for(let r=0,i=e.length;r!==i;++r){let i=e[r];i.id in t&&n.push(i)}return n}};function et(e,t,n){let r=e.createShader(t);return e.shaderSource(r,n),e.compileShader(r),r}var tt=37297,nt=0;function rt(e,t){let n=e.split(`
4003
+ `),r=[],i=Math.max(t-6,0),a=Math.min(t+6,n.length);for(let e=i;e<a;e++){let i=e+1;r.push(`${i===t?`>`:` `} ${i}: ${n[e]}`)}return r.join(`
4004
+ `)}var it=new e.B;function at(t){e.d._getMatrix(it,e.d.workingColorSpace,t);let n=`mat3( ${it.elements.map(e=>e.toFixed(4))} )`;switch(e.d.getTransfer(t)){case e.L:return[n,`LinearTransferOETF`];case e.Xt:return[n,`sRGBTransferOETF`];default:return e.kn(`WebGLProgram: Unsupported color space: `,t),[n,`LinearTransferOETF`]}}function ot(e,t,n){let r=e.getShaderParameter(t,e.COMPILE_STATUS),i=(e.getShaderInfoLog(t)||``).trim();if(r&&i===``)return``;let a=/ERROR: 0:(\d+)/.exec(i);if(a){let r=parseInt(a[1]);return n.toUpperCase()+`
4005
+
4006
+ `+i+`
4007
+
4008
+ `+rt(e.getShaderSource(t),r)}else return i}function st(e,t){let n=at(t);return[`vec4 ${e}( vec4 value ) {`,` return ${n[1]}( vec4( value.rgb * ${n[0]}, value.a ) );`,`}`].join(`
4009
+ `)}var ct={1:`Linear`,2:`Reinhard`,3:`Cineon`,4:`ACESFilmic`,6:`AgX`,7:`Neutral`,5:`Custom`};function lt(t,n){let r=ct[n];return r===void 0?(e.kn(`WebGLProgram: Unsupported toneMapping:`,n),`vec3 `+t+`( vec3 color ) { return LinearToneMapping( color ); }`):`vec3 `+t+`( vec3 color ) { return `+r+`ToneMapping( color ); }`}var ut=new e.hn;function dt(){return e.d.getLuminanceCoefficients(ut),[`float luminance( const in vec3 rgb ) {`,` const vec3 weights = vec3( ${ut.x.toFixed(4)}, ${ut.y.toFixed(4)}, ${ut.z.toFixed(4)} );`,` return dot( weights, rgb );`,`}`].join(`
4010
+ `)}function ft(e){return[e.extensionClipCullDistance?`#extension GL_ANGLE_clip_cull_distance : require`:``,e.extensionMultiDraw?`#extension GL_ANGLE_multi_draw : require`:``].filter(ht).join(`
4011
+ `)}function pt(e){let t=[];for(let n in e){let r=e[n];r!==!1&&t.push(`#define `+n+` `+r)}return t.join(`
4012
+ `)}function mt(e,t){let n={},r=e.getProgramParameter(t,e.ACTIVE_ATTRIBUTES);for(let i=0;i<r;i++){let r=e.getActiveAttrib(t,i),a=r.name,o=1;r.type===e.FLOAT_MAT2&&(o=2),r.type===e.FLOAT_MAT3&&(o=3),r.type===e.FLOAT_MAT4&&(o=4),n[a]={type:r.type,location:e.getAttribLocation(t,a),locationSize:o}}return n}function ht(e){return e!==``}function gt(e,t){let n=t.numSpotLightShadows+t.numSpotLightMaps-t.numSpotLightShadowsWithMaps;return e.replace(/NUM_DIR_LIGHTS/g,t.numDirLights).replace(/NUM_SPOT_LIGHTS/g,t.numSpotLights).replace(/NUM_SPOT_LIGHT_MAPS/g,t.numSpotLightMaps).replace(/NUM_SPOT_LIGHT_COORDS/g,n).replace(/NUM_RECT_AREA_LIGHTS/g,t.numRectAreaLights).replace(/NUM_POINT_LIGHTS/g,t.numPointLights).replace(/NUM_HEMI_LIGHTS/g,t.numHemiLights).replace(/NUM_DIR_LIGHT_SHADOWS/g,t.numDirLightShadows).replace(/NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS/g,t.numSpotLightShadowsWithMaps).replace(/NUM_SPOT_LIGHT_SHADOWS/g,t.numSpotLightShadows).replace(/NUM_POINT_LIGHT_SHADOWS/g,t.numPointLightShadows)}function _t(e,t){return e.replace(/NUM_CLIPPING_PLANES/g,t.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g,t.numClippingPlanes-t.numClipIntersection)}var vt=/^[ \t]*#include +<([\w\d./]+)>/gm;function yt(e){return e.replace(vt,xt)}var bt=new Map;function xt(t,n){let r=i[n];if(r===void 0){let t=bt.get(n);if(t!==void 0)r=i[t],e.kn(`WebGLRenderer: Shader chunk "%s" has been deprecated. Use "%s" instead.`,n,t);else throw Error(`THREE.WebGLProgram: Can not resolve #include <`+n+`>`)}return yt(r)}var St=/#pragma unroll_loop_start\s+for\s*\(\s*int\s+i\s*=\s*(\d+)\s*;\s*i\s*<\s*(\d+)\s*;\s*i\s*\+\+\s*\)\s*{([\s\S]+?)}\s+#pragma unroll_loop_end/g;function Ct(e){return e.replace(St,wt)}function wt(e,t,n,r){let i=``;for(let e=parseInt(t);e<parseInt(n);e++)i+=r.replace(/\[\s*i\s*\]/g,`[ `+e+` ]`).replace(/UNROLLED_LOOP_INDEX/g,e);return i}function Tt(e){let t=`precision ${e.precision} float;
4013
+ precision ${e.precision} int;
4014
+ precision ${e.precision} sampler2D;
4015
+ precision ${e.precision} samplerCube;
4016
+ precision ${e.precision} sampler3D;
4017
+ precision ${e.precision} sampler2DArray;
4018
+ precision ${e.precision} sampler2DShadow;
4019
+ precision ${e.precision} samplerCubeShadow;
4020
+ precision ${e.precision} sampler2DArrayShadow;
4021
+ precision ${e.precision} isampler2D;
4022
+ precision ${e.precision} isampler3D;
4023
+ precision ${e.precision} isamplerCube;
4024
+ precision ${e.precision} isampler2DArray;
4025
+ precision ${e.precision} usampler2D;
4026
+ precision ${e.precision} usampler3D;
4027
+ precision ${e.precision} usamplerCube;
4028
+ precision ${e.precision} usampler2DArray;
4029
+ `;return e.precision===`highp`?t+=`
4030
+ #define HIGH_PRECISION`:e.precision===`mediump`?t+=`
4031
+ #define MEDIUM_PRECISION`:e.precision===`lowp`&&(t+=`
4032
+ #define LOW_PRECISION`),t}var Et={1:`SHADOWMAP_TYPE_PCF`,3:`SHADOWMAP_TYPE_VSM`};function Dt(e){return Et[e.shadowMapType]||`SHADOWMAP_TYPE_BASIC`}var Ot={301:`ENVMAP_TYPE_CUBE`,302:`ENVMAP_TYPE_CUBE`,306:`ENVMAP_TYPE_CUBE_UV`};function kt(e){return e.envMap===!1?`ENVMAP_TYPE_CUBE`:Ot[e.envMapMode]||`ENVMAP_TYPE_CUBE`}var At={302:`ENVMAP_MODE_REFRACTION`};function jt(e){return e.envMap===!1?`ENVMAP_MODE_REFLECTION`:At[e.envMapMode]||`ENVMAP_MODE_REFLECTION`}var Mt={0:`ENVMAP_BLENDING_MULTIPLY`,1:`ENVMAP_BLENDING_MIX`,2:`ENVMAP_BLENDING_ADD`};function Nt(e){return e.envMap===!1?`ENVMAP_BLENDING_NONE`:Mt[e.combine]||`ENVMAP_BLENDING_NONE`}function Pt(e){let t=e.envMapCubeUVHeight;if(t===null)return null;let n=Math.log2(t)-2,r=1/t;return{texelWidth:1/(3*Math.max(2**n,112)),texelHeight:r,maxMip:n}}function Ft(t,n,r,a){let o=t.getContext(),s=r.defines,c=r.vertexShader,l=r.fragmentShader,u=Dt(r),d=kt(r),f=jt(r),p=Nt(r),m=Pt(r),h=ft(r),g=pt(s),_=o.createProgram(),v,y,b=r.glslVersion?`#version `+r.glslVersion+`
4033
+ `:``;r.isRawShaderMaterial?(v=[`#define SHADER_TYPE `+r.shaderType,`#define SHADER_NAME `+r.shaderName,g].filter(ht).join(`
4034
+ `),v.length>0&&(v+=`
4035
+ `),y=[`#define SHADER_TYPE `+r.shaderType,`#define SHADER_NAME `+r.shaderName,g].filter(ht).join(`
4036
+ `),y.length>0&&(y+=`
4037
+ `)):(v=[Tt(r),`#define SHADER_TYPE `+r.shaderType,`#define SHADER_NAME `+r.shaderName,g,r.extensionClipCullDistance?`#define USE_CLIP_DISTANCE`:``,r.batching?`#define USE_BATCHING`:``,r.batchingColor?`#define USE_BATCHING_COLOR`:``,r.instancing?`#define USE_INSTANCING`:``,r.instancingColor?`#define USE_INSTANCING_COLOR`:``,r.instancingMorph?`#define USE_INSTANCING_MORPH`:``,r.useFog&&r.fog?`#define USE_FOG`:``,r.useFog&&r.fogExp2?`#define FOG_EXP2`:``,r.map?`#define USE_MAP`:``,r.envMap?`#define USE_ENVMAP`:``,r.envMap?`#define `+f:``,r.lightMap?`#define USE_LIGHTMAP`:``,r.aoMap?`#define USE_AOMAP`:``,r.bumpMap?`#define USE_BUMPMAP`:``,r.normalMap?`#define USE_NORMALMAP`:``,r.normalMapObjectSpace?`#define USE_NORMALMAP_OBJECTSPACE`:``,r.normalMapTangentSpace?`#define USE_NORMALMAP_TANGENTSPACE`:``,r.displacementMap?`#define USE_DISPLACEMENTMAP`:``,r.emissiveMap?`#define USE_EMISSIVEMAP`:``,r.anisotropy?`#define USE_ANISOTROPY`:``,r.anisotropyMap?`#define USE_ANISOTROPYMAP`:``,r.clearcoatMap?`#define USE_CLEARCOATMAP`:``,r.clearcoatRoughnessMap?`#define USE_CLEARCOAT_ROUGHNESSMAP`:``,r.clearcoatNormalMap?`#define USE_CLEARCOAT_NORMALMAP`:``,r.iridescenceMap?`#define USE_IRIDESCENCEMAP`:``,r.iridescenceThicknessMap?`#define USE_IRIDESCENCE_THICKNESSMAP`:``,r.specularMap?`#define USE_SPECULARMAP`:``,r.specularColorMap?`#define USE_SPECULAR_COLORMAP`:``,r.specularIntensityMap?`#define USE_SPECULAR_INTENSITYMAP`:``,r.roughnessMap?`#define USE_ROUGHNESSMAP`:``,r.metalnessMap?`#define USE_METALNESSMAP`:``,r.alphaMap?`#define USE_ALPHAMAP`:``,r.alphaHash?`#define USE_ALPHAHASH`:``,r.transmission?`#define USE_TRANSMISSION`:``,r.transmissionMap?`#define USE_TRANSMISSIONMAP`:``,r.thicknessMap?`#define USE_THICKNESSMAP`:``,r.sheenColorMap?`#define USE_SHEEN_COLORMAP`:``,r.sheenRoughnessMap?`#define USE_SHEEN_ROUGHNESSMAP`:``,r.mapUv?`#define MAP_UV `+r.mapUv:``,r.alphaMapUv?`#define ALPHAMAP_UV `+r.alphaMapUv:``,r.lightMapUv?`#define LIGHTMAP_UV `+r.lightMapUv:``,r.aoMapUv?`#define AOMAP_UV `+r.aoMapUv:``,r.emissiveMapUv?`#define EMISSIVEMAP_UV `+r.emissiveMapUv:``,r.bumpMapUv?`#define BUMPMAP_UV `+r.bumpMapUv:``,r.normalMapUv?`#define NORMALMAP_UV `+r.normalMapUv:``,r.displacementMapUv?`#define DISPLACEMENTMAP_UV `+r.displacementMapUv:``,r.metalnessMapUv?`#define METALNESSMAP_UV `+r.metalnessMapUv:``,r.roughnessMapUv?`#define ROUGHNESSMAP_UV `+r.roughnessMapUv:``,r.anisotropyMapUv?`#define ANISOTROPYMAP_UV `+r.anisotropyMapUv:``,r.clearcoatMapUv?`#define CLEARCOATMAP_UV `+r.clearcoatMapUv:``,r.clearcoatNormalMapUv?`#define CLEARCOAT_NORMALMAP_UV `+r.clearcoatNormalMapUv:``,r.clearcoatRoughnessMapUv?`#define CLEARCOAT_ROUGHNESSMAP_UV `+r.clearcoatRoughnessMapUv:``,r.iridescenceMapUv?`#define IRIDESCENCEMAP_UV `+r.iridescenceMapUv:``,r.iridescenceThicknessMapUv?`#define IRIDESCENCE_THICKNESSMAP_UV `+r.iridescenceThicknessMapUv:``,r.sheenColorMapUv?`#define SHEEN_COLORMAP_UV `+r.sheenColorMapUv:``,r.sheenRoughnessMapUv?`#define SHEEN_ROUGHNESSMAP_UV `+r.sheenRoughnessMapUv:``,r.specularMapUv?`#define SPECULARMAP_UV `+r.specularMapUv:``,r.specularColorMapUv?`#define SPECULAR_COLORMAP_UV `+r.specularColorMapUv:``,r.specularIntensityMapUv?`#define SPECULAR_INTENSITYMAP_UV `+r.specularIntensityMapUv:``,r.transmissionMapUv?`#define TRANSMISSIONMAP_UV `+r.transmissionMapUv:``,r.thicknessMapUv?`#define THICKNESSMAP_UV `+r.thicknessMapUv:``,r.vertexTangents&&r.flatShading===!1?`#define USE_TANGENT`:``,r.vertexNormals?`#define HAS_NORMAL`:``,r.vertexColors?`#define USE_COLOR`:``,r.vertexAlphas?`#define USE_COLOR_ALPHA`:``,r.vertexUv1s?`#define USE_UV1`:``,r.vertexUv2s?`#define USE_UV2`:``,r.vertexUv3s?`#define USE_UV3`:``,r.pointsUvs?`#define USE_POINTS_UV`:``,r.flatShading?`#define FLAT_SHADED`:``,r.skinning?`#define USE_SKINNING`:``,r.morphTargets?`#define USE_MORPHTARGETS`:``,r.morphNormals&&r.flatShading===!1?`#define USE_MORPHNORMALS`:``,r.morphColors?`#define USE_MORPHCOLORS`:``,r.morphTargetsCount>0?`#define MORPHTARGETS_TEXTURE_STRIDE `+r.morphTextureStride:``,r.morphTargetsCount>0?`#define MORPHTARGETS_COUNT `+r.morphTargetsCount:``,r.doubleSided?`#define DOUBLE_SIDED`:``,r.flipSided?`#define FLIP_SIDED`:``,r.shadowMapEnabled?`#define USE_SHADOWMAP`:``,r.shadowMapEnabled?`#define `+u:``,r.sizeAttenuation?`#define USE_SIZEATTENUATION`:``,r.numLightProbes>0?`#define USE_LIGHT_PROBES`:``,r.logarithmicDepthBuffer?`#define USE_LOGARITHMIC_DEPTH_BUFFER`:``,r.reversedDepthBuffer?`#define USE_REVERSED_DEPTH_BUFFER`:``,`uniform mat4 modelMatrix;`,`uniform mat4 modelViewMatrix;`,`uniform mat4 projectionMatrix;`,`uniform mat4 viewMatrix;`,`uniform mat3 normalMatrix;`,`uniform vec3 cameraPosition;`,`uniform bool isOrthographic;`,`#ifdef USE_INSTANCING`,` attribute mat4 instanceMatrix;`,`#endif`,`#ifdef USE_INSTANCING_COLOR`,` attribute vec3 instanceColor;`,`#endif`,`#ifdef USE_INSTANCING_MORPH`,` uniform sampler2D morphTexture;`,`#endif`,`attribute vec3 position;`,`attribute vec3 normal;`,`attribute vec2 uv;`,`#ifdef USE_UV1`,` attribute vec2 uv1;`,`#endif`,`#ifdef USE_UV2`,` attribute vec2 uv2;`,`#endif`,`#ifdef USE_UV3`,` attribute vec2 uv3;`,`#endif`,`#ifdef USE_TANGENT`,` attribute vec4 tangent;`,`#endif`,`#if defined( USE_COLOR_ALPHA )`,` attribute vec4 color;`,`#elif defined( USE_COLOR )`,` attribute vec3 color;`,`#endif`,`#ifdef USE_SKINNING`,` attribute vec4 skinIndex;`,` attribute vec4 skinWeight;`,`#endif`,`
4038
+ `].filter(ht).join(`
4039
+ `),y=[Tt(r),`#define SHADER_TYPE `+r.shaderType,`#define SHADER_NAME `+r.shaderName,g,r.useFog&&r.fog?`#define USE_FOG`:``,r.useFog&&r.fogExp2?`#define FOG_EXP2`:``,r.alphaToCoverage?`#define ALPHA_TO_COVERAGE`:``,r.map?`#define USE_MAP`:``,r.matcap?`#define USE_MATCAP`:``,r.envMap?`#define USE_ENVMAP`:``,r.envMap?`#define `+d:``,r.envMap?`#define `+f:``,r.envMap?`#define `+p:``,m?`#define CUBEUV_TEXEL_WIDTH `+m.texelWidth:``,m?`#define CUBEUV_TEXEL_HEIGHT `+m.texelHeight:``,m?`#define CUBEUV_MAX_MIP `+m.maxMip+`.0`:``,r.lightMap?`#define USE_LIGHTMAP`:``,r.aoMap?`#define USE_AOMAP`:``,r.bumpMap?`#define USE_BUMPMAP`:``,r.normalMap?`#define USE_NORMALMAP`:``,r.normalMapObjectSpace?`#define USE_NORMALMAP_OBJECTSPACE`:``,r.normalMapTangentSpace?`#define USE_NORMALMAP_TANGENTSPACE`:``,r.packedNormalMap?`#define USE_PACKED_NORMALMAP`:``,r.emissiveMap?`#define USE_EMISSIVEMAP`:``,r.anisotropy?`#define USE_ANISOTROPY`:``,r.anisotropyMap?`#define USE_ANISOTROPYMAP`:``,r.clearcoat?`#define USE_CLEARCOAT`:``,r.clearcoatMap?`#define USE_CLEARCOATMAP`:``,r.clearcoatRoughnessMap?`#define USE_CLEARCOAT_ROUGHNESSMAP`:``,r.clearcoatNormalMap?`#define USE_CLEARCOAT_NORMALMAP`:``,r.dispersion?`#define USE_DISPERSION`:``,r.iridescence?`#define USE_IRIDESCENCE`:``,r.iridescenceMap?`#define USE_IRIDESCENCEMAP`:``,r.iridescenceThicknessMap?`#define USE_IRIDESCENCE_THICKNESSMAP`:``,r.specularMap?`#define USE_SPECULARMAP`:``,r.specularColorMap?`#define USE_SPECULAR_COLORMAP`:``,r.specularIntensityMap?`#define USE_SPECULAR_INTENSITYMAP`:``,r.roughnessMap?`#define USE_ROUGHNESSMAP`:``,r.metalnessMap?`#define USE_METALNESSMAP`:``,r.alphaMap?`#define USE_ALPHAMAP`:``,r.alphaTest?`#define USE_ALPHATEST`:``,r.alphaHash?`#define USE_ALPHAHASH`:``,r.sheen?`#define USE_SHEEN`:``,r.sheenColorMap?`#define USE_SHEEN_COLORMAP`:``,r.sheenRoughnessMap?`#define USE_SHEEN_ROUGHNESSMAP`:``,r.transmission?`#define USE_TRANSMISSION`:``,r.transmissionMap?`#define USE_TRANSMISSIONMAP`:``,r.thicknessMap?`#define USE_THICKNESSMAP`:``,r.vertexTangents&&r.flatShading===!1?`#define USE_TANGENT`:``,r.vertexColors||r.instancingColor?`#define USE_COLOR`:``,r.vertexAlphas||r.batchingColor?`#define USE_COLOR_ALPHA`:``,r.vertexUv1s?`#define USE_UV1`:``,r.vertexUv2s?`#define USE_UV2`:``,r.vertexUv3s?`#define USE_UV3`:``,r.pointsUvs?`#define USE_POINTS_UV`:``,r.gradientMap?`#define USE_GRADIENTMAP`:``,r.flatShading?`#define FLAT_SHADED`:``,r.doubleSided?`#define DOUBLE_SIDED`:``,r.flipSided?`#define FLIP_SIDED`:``,r.shadowMapEnabled?`#define USE_SHADOWMAP`:``,r.shadowMapEnabled?`#define `+u:``,r.premultipliedAlpha?`#define PREMULTIPLIED_ALPHA`:``,r.numLightProbes>0?`#define USE_LIGHT_PROBES`:``,r.numLightProbeGrids>0?`#define USE_LIGHT_PROBES_GRID`:``,r.decodeVideoTexture?`#define DECODE_VIDEO_TEXTURE`:``,r.decodeVideoTextureEmissive?`#define DECODE_VIDEO_TEXTURE_EMISSIVE`:``,r.logarithmicDepthBuffer?`#define USE_LOGARITHMIC_DEPTH_BUFFER`:``,r.reversedDepthBuffer?`#define USE_REVERSED_DEPTH_BUFFER`:``,`uniform mat4 viewMatrix;`,`uniform vec3 cameraPosition;`,`uniform bool isOrthographic;`,r.toneMapping===0?``:`#define TONE_MAPPING`,r.toneMapping===0?``:i.tonemapping_pars_fragment,r.toneMapping===0?``:lt(`toneMapping`,r.toneMapping),r.dithering?`#define DITHERING`:``,r.opaque?`#define OPAQUE`:``,i.colorspace_pars_fragment,st(`linearToOutputTexel`,r.outputColorSpace),dt(),r.useDepthPacking?`#define DEPTH_PACKING `+r.depthPacking:``,`
4040
+ `].filter(ht).join(`
4041
+ `)),c=yt(c),c=gt(c,r),c=_t(c,r),l=yt(l),l=gt(l,r),l=_t(l,r),c=Ct(c),l=Ct(l),r.isRawShaderMaterial!==!0&&(b=`#version 300 es
4042
+ `,v=[h,`#define attribute in`,`#define varying out`,`#define texture2D texture`].join(`
4043
+ `)+`
4044
+ `+v,y=[`#define varying in`,r.glslVersion===`300 es`?``:`layout(location = 0) out highp vec4 pc_fragColor;`,r.glslVersion===`300 es`?``:`#define gl_FragColor pc_fragColor`,`#define gl_FragDepthEXT gl_FragDepth`,`#define texture2D texture`,`#define textureCube texture`,`#define texture2DProj textureProj`,`#define texture2DLodEXT textureLod`,`#define texture2DProjLodEXT textureProjLod`,`#define textureCubeLodEXT textureLod`,`#define texture2DGradEXT textureGrad`,`#define texture2DProjGradEXT textureProjGrad`,`#define textureCubeGradEXT textureGrad`].join(`
4045
+ `)+`
4046
+ `+y);let x=b+v+c,S=b+y+l,C=et(o,o.VERTEX_SHADER,x),w=et(o,o.FRAGMENT_SHADER,S);o.attachShader(_,C),o.attachShader(_,w),r.index0AttributeName===void 0?r.hasPositionAttribute===!0&&o.bindAttribLocation(_,0,`position`):o.bindAttribLocation(_,0,r.index0AttributeName),o.linkProgram(_);function T(n){if(t.debug.checkShaderErrors){let r=o.getProgramInfoLog(_)||``,i=o.getShaderInfoLog(C)||``,a=o.getShaderInfoLog(w)||``,s=r.trim(),c=i.trim(),l=a.trim(),u=!0,d=!0;if(o.getProgramParameter(_,o.LINK_STATUS)===!1)if(u=!1,typeof t.debug.onShaderError==`function`)t.debug.onShaderError(o,_,C,w);else{let t=ot(o,C,`vertex`),r=ot(o,w,`fragment`);e.Cn(`WebGLProgram: Shader Error `+o.getError()+` - VALIDATE_STATUS `+o.getProgramParameter(_,o.VALIDATE_STATUS)+`
4047
+
4048
+ Material Name: `+n.name+`
4049
+ Material Type: `+n.type+`
4050
+
4051
+ Program Info Log: `+s+`
4052
+ `+t+`
4053
+ `+r)}else s===``?(c===``||l===``)&&(d=!1):e.kn(`WebGLProgram: Program Info Log:`,s);d&&(n.diagnostics={runnable:u,programLog:s,vertexShader:{log:c,prefix:v},fragmentShader:{log:l,prefix:y}})}o.deleteShader(C),o.deleteShader(w),E=new $e(o,_),D=mt(o,_)}let E;this.getUniforms=function(){return E===void 0&&T(this),E};let D;this.getAttributes=function(){return D===void 0&&T(this),D};let O=r.rendererExtensionParallelShaderCompile===!1;return this.isReady=function(){return O===!1&&(O=o.getProgramParameter(_,tt)),O},this.destroy=function(){a.releaseStatesOfProgram(this),o.deleteProgram(_),this.program=void 0},this.type=r.shaderType,this.name=r.shaderName,this.id=nt++,this.cacheKey=n,this.usedTimes=1,this.program=_,this.vertexShader=C,this.fragmentShader=w,this}var It=0,Lt=class{constructor(){this.shaderCache=new Map,this.materialCache=new Map}update(e,t,n){let r=this._getShaderCacheForMaterial(e);return r.has(t)===!1&&(r.add(t),t.usedTimes++),r.has(n)===!1&&(r.add(n),n.usedTimes++),this}remove(e){let t=this.materialCache.get(e);for(let e of t)e.usedTimes--,e.usedTimes===0&&this.shaderCache.delete(e.code);return this.materialCache.delete(e),this}getVertexShaderStage(e){return this._getShaderStage(e.vertexShader)}getFragmentShaderStage(e){return this._getShaderStage(e.fragmentShader)}dispose(){this.shaderCache.clear(),this.materialCache.clear()}_getShaderCacheForMaterial(e){let t=this.materialCache,n=t.get(e);return n===void 0&&(n=new Set,t.set(e,n)),n}_getShaderStage(e){let t=this.shaderCache,n=t.get(e);return n===void 0&&(n=new Rt(e),t.set(e,n)),n}},Rt=class{constructor(e){this.id=It++,this.code=e,this.usedTimes=0}};function zt(e){return e===1030||e===37490||e===36285}function Bt(t,n,r,i,a,s){let c=new e.M,l=new Lt,u=new Set,d=[],f=new Map,p=i.logarithmicDepthBuffer,m=i.precision,h={MeshDepthMaterial:`depth`,MeshDistanceMaterial:`distance`,MeshNormalMaterial:`normal`,MeshBasicMaterial:`basic`,MeshLambertMaterial:`lambert`,MeshPhongMaterial:`phong`,MeshToonMaterial:`toon`,MeshStandardMaterial:`physical`,MeshPhysicalMaterial:`physical`,MeshMatcapMaterial:`matcap`,LineBasicMaterial:`basic`,LineDashedMaterial:`dashed`,PointsMaterial:`points`,ShadowMaterial:`shadow`,SpriteMaterial:`sprite`};function g(e){return u.add(e),e===0?`uv`:`uv${e}`}function _(a,c,d,f,_,v){let y=f.fog,b=_.geometry,x=a.isMeshStandardMaterial||a.isMeshLambertMaterial||a.isMeshPhongMaterial?f.environment:null,S=a.isMeshStandardMaterial||a.isMeshLambertMaterial&&!a.envMap||a.isMeshPhongMaterial&&!a.envMap,C=n.get(a.envMap||x,S),w=C&&C.mapping===306?C.image.height:null,T=h[a.type];a.precision!==null&&(m=i.getMaxPrecision(a.precision),m!==a.precision&&e.kn(`WebGLProgram.getParameters:`,a.precision,`not supported, using`,m,`instead.`));let E=b.morphAttributes.position||b.morphAttributes.normal||b.morphAttributes.color,D=E===void 0?0:E.length,O=0;b.morphAttributes.position!==void 0&&(O=1),b.morphAttributes.normal!==void 0&&(O=2),b.morphAttributes.color!==void 0&&(O=3);let k,A,j,M;if(T){let e=o[T];k=e.vertexShader,A=e.fragmentShader}else{k=a.vertexShader,A=a.fragmentShader;let e=l.getVertexShaderStage(a),t=l.getFragmentShaderStage(a);l.update(a,e,t),j=e.id,M=t.id}let N=t.getRenderTarget(),ee=t.state.buffers.depth.getReversed(),P=_.isInstancedMesh===!0,te=_.isBatchedMesh===!0,ne=!!a.map,re=!!a.matcap,ie=!!C,ae=!!a.aoMap,oe=!!a.lightMap,se=!!a.bumpMap&&a.wireframe===!1,ce=!!a.normalMap,le=!!a.displacementMap,F=!!a.emissiveMap,I=!!a.metalnessMap,ue=!!a.roughnessMap,L=a.anisotropy>0,R=a.clearcoat>0,de=a.dispersion>0,z=a.iridescence>0,B=a.sheen>0,fe=a.transmission>0,pe=L&&!!a.anisotropyMap,me=R&&!!a.clearcoatMap,V=R&&!!a.clearcoatNormalMap,H=R&&!!a.clearcoatRoughnessMap,U=z&&!!a.iridescenceMap,W=z&&!!a.iridescenceThicknessMap,he=B&&!!a.sheenColorMap,ge=B&&!!a.sheenRoughnessMap,_e=!!a.specularMap,ve=!!a.specularColorMap,ye=!!a.specularIntensityMap,be=fe&&!!a.transmissionMap,xe=fe&&!!a.thicknessMap,Se=!!a.gradientMap,Ce=!!a.alphaMap,we=a.alphaTest>0,Te=!!a.alphaHash,Ee=!!a.extensions,De=0;a.toneMapped&&(N===null||N.isXRRenderTarget===!0)&&(De=t.toneMapping);let Oe={shaderID:T,shaderType:a.type,shaderName:a.name,vertexShader:k,fragmentShader:A,defines:a.defines,customVertexShaderID:j,customFragmentShaderID:M,isRawShaderMaterial:a.isRawShaderMaterial===!0,glslVersion:a.glslVersion,precision:m,batching:te,batchingColor:te&&_._colorsTexture!==null,instancing:P,instancingColor:P&&_.instanceColor!==null,instancingMorph:P&&_.morphTexture!==null,outputColorSpace:N===null?t.outputColorSpace:N.isXRRenderTarget===!0?N.texture.colorSpace:e.d.workingColorSpace,alphaToCoverage:!!a.alphaToCoverage,map:ne,matcap:re,envMap:ie,envMapMode:ie&&C.mapping,envMapCubeUVHeight:w,aoMap:ae,lightMap:oe,bumpMap:se,normalMap:ce,displacementMap:le,emissiveMap:F,normalMapObjectSpace:ce&&a.normalMapType===1,normalMapTangentSpace:ce&&a.normalMapType===0,packedNormalMap:ce&&a.normalMapType===0&&zt(a.normalMap.format),metalnessMap:I,roughnessMap:ue,anisotropy:L,anisotropyMap:pe,clearcoat:R,clearcoatMap:me,clearcoatNormalMap:V,clearcoatRoughnessMap:H,dispersion:de,iridescence:z,iridescenceMap:U,iridescenceThicknessMap:W,sheen:B,sheenColorMap:he,sheenRoughnessMap:ge,specularMap:_e,specularColorMap:ve,specularIntensityMap:ye,transmission:fe,transmissionMap:be,thicknessMap:xe,gradientMap:Se,opaque:a.transparent===!1&&a.blending===1&&a.alphaToCoverage===!1,alphaMap:Ce,alphaTest:we,alphaHash:Te,combine:a.combine,mapUv:ne&&g(a.map.channel),aoMapUv:ae&&g(a.aoMap.channel),lightMapUv:oe&&g(a.lightMap.channel),bumpMapUv:se&&g(a.bumpMap.channel),normalMapUv:ce&&g(a.normalMap.channel),displacementMapUv:le&&g(a.displacementMap.channel),emissiveMapUv:F&&g(a.emissiveMap.channel),metalnessMapUv:I&&g(a.metalnessMap.channel),roughnessMapUv:ue&&g(a.roughnessMap.channel),anisotropyMapUv:pe&&g(a.anisotropyMap.channel),clearcoatMapUv:me&&g(a.clearcoatMap.channel),clearcoatNormalMapUv:V&&g(a.clearcoatNormalMap.channel),clearcoatRoughnessMapUv:H&&g(a.clearcoatRoughnessMap.channel),iridescenceMapUv:U&&g(a.iridescenceMap.channel),iridescenceThicknessMapUv:W&&g(a.iridescenceThicknessMap.channel),sheenColorMapUv:he&&g(a.sheenColorMap.channel),sheenRoughnessMapUv:ge&&g(a.sheenRoughnessMap.channel),specularMapUv:_e&&g(a.specularMap.channel),specularColorMapUv:ve&&g(a.specularColorMap.channel),specularIntensityMapUv:ye&&g(a.specularIntensityMap.channel),transmissionMapUv:be&&g(a.transmissionMap.channel),thicknessMapUv:xe&&g(a.thicknessMap.channel),alphaMapUv:Ce&&g(a.alphaMap.channel),vertexTangents:!!b.attributes.tangent&&(ce||L),vertexNormals:!!b.attributes.normal,vertexColors:a.vertexColors,vertexAlphas:a.vertexColors===!0&&!!b.attributes.color&&b.attributes.color.itemSize===4,pointsUvs:_.isPoints===!0&&!!b.attributes.uv&&(ne||Ce),fog:!!y,useFog:a.fog===!0,fogExp2:!!y&&y.isFogExp2,flatShading:a.wireframe===!1&&(a.flatShading===!0||b.attributes.normal===void 0&&ce===!1&&(a.isMeshLambertMaterial||a.isMeshPhongMaterial||a.isMeshStandardMaterial||a.isMeshPhysicalMaterial)),sizeAttenuation:a.sizeAttenuation===!0,logarithmicDepthBuffer:p,reversedDepthBuffer:ee,skinning:_.isSkinnedMesh===!0,hasPositionAttribute:b.attributes.position!==void 0,morphTargets:b.morphAttributes.position!==void 0,morphNormals:b.morphAttributes.normal!==void 0,morphColors:b.morphAttributes.color!==void 0,morphTargetsCount:D,morphTextureStride:O,numDirLights:c.directional.length,numPointLights:c.point.length,numSpotLights:c.spot.length,numSpotLightMaps:c.spotLightMap.length,numRectAreaLights:c.rectArea.length,numHemiLights:c.hemi.length,numDirLightShadows:c.directionalShadowMap.length,numPointLightShadows:c.pointShadowMap.length,numSpotLightShadows:c.spotShadowMap.length,numSpotLightShadowsWithMaps:c.numSpotLightShadowsWithMaps,numLightProbes:c.numLightProbes,numLightProbeGrids:v.length,numClippingPlanes:s.numPlanes,numClipIntersection:s.numIntersection,dithering:a.dithering,shadowMapEnabled:t.shadowMap.enabled&&d.length>0,shadowMapType:t.shadowMap.type,toneMapping:De,decodeVideoTexture:ne&&a.map.isVideoTexture===!0&&e.d.getTransfer(a.map.colorSpace)===`srgb`,decodeVideoTextureEmissive:F&&a.emissiveMap.isVideoTexture===!0&&e.d.getTransfer(a.emissiveMap.colorSpace)===`srgb`,premultipliedAlpha:a.premultipliedAlpha,doubleSided:a.side===2,flipSided:a.side===1,useDepthPacking:a.depthPacking>=0,depthPacking:a.depthPacking||0,index0AttributeName:a.index0AttributeName,extensionClipCullDistance:Ee&&a.extensions.clipCullDistance===!0&&r.has(`WEBGL_clip_cull_distance`),extensionMultiDraw:(Ee&&a.extensions.multiDraw===!0||te)&&r.has(`WEBGL_multi_draw`),rendererExtensionParallelShaderCompile:r.has(`KHR_parallel_shader_compile`),customProgramCacheKey:a.customProgramCacheKey()};return Oe.vertexUv1s=u.has(1),Oe.vertexUv2s=u.has(2),Oe.vertexUv3s=u.has(3),u.clear(),Oe}function v(e){let n=[];if(e.shaderID?n.push(e.shaderID):(n.push(e.customVertexShaderID),n.push(e.customFragmentShaderID)),e.defines!==void 0)for(let t in e.defines)n.push(t),n.push(e.defines[t]);return e.isRawShaderMaterial===!1&&(y(n,e),b(n,e),n.push(t.outputColorSpace)),n.push(e.customProgramCacheKey),n.join()}function y(e,t){e.push(t.precision),e.push(t.outputColorSpace),e.push(t.envMapMode),e.push(t.envMapCubeUVHeight),e.push(t.mapUv),e.push(t.alphaMapUv),e.push(t.lightMapUv),e.push(t.aoMapUv),e.push(t.bumpMapUv),e.push(t.normalMapUv),e.push(t.displacementMapUv),e.push(t.emissiveMapUv),e.push(t.metalnessMapUv),e.push(t.roughnessMapUv),e.push(t.anisotropyMapUv),e.push(t.clearcoatMapUv),e.push(t.clearcoatNormalMapUv),e.push(t.clearcoatRoughnessMapUv),e.push(t.iridescenceMapUv),e.push(t.iridescenceThicknessMapUv),e.push(t.sheenColorMapUv),e.push(t.sheenRoughnessMapUv),e.push(t.specularMapUv),e.push(t.specularColorMapUv),e.push(t.specularIntensityMapUv),e.push(t.transmissionMapUv),e.push(t.thicknessMapUv),e.push(t.combine),e.push(t.fogExp2),e.push(t.sizeAttenuation),e.push(t.morphTargetsCount),e.push(t.morphAttributeCount),e.push(t.numDirLights),e.push(t.numPointLights),e.push(t.numSpotLights),e.push(t.numSpotLightMaps),e.push(t.numHemiLights),e.push(t.numRectAreaLights),e.push(t.numDirLightShadows),e.push(t.numPointLightShadows),e.push(t.numSpotLightShadows),e.push(t.numSpotLightShadowsWithMaps),e.push(t.numLightProbes),e.push(t.shadowMapType),e.push(t.toneMapping),e.push(t.numClippingPlanes),e.push(t.numClipIntersection),e.push(t.depthPacking)}function b(e,t){c.disableAll(),t.instancing&&c.enable(0),t.instancingColor&&c.enable(1),t.instancingMorph&&c.enable(2),t.matcap&&c.enable(3),t.envMap&&c.enable(4),t.normalMapObjectSpace&&c.enable(5),t.normalMapTangentSpace&&c.enable(6),t.clearcoat&&c.enable(7),t.iridescence&&c.enable(8),t.alphaTest&&c.enable(9),t.vertexColors&&c.enable(10),t.vertexAlphas&&c.enable(11),t.vertexUv1s&&c.enable(12),t.vertexUv2s&&c.enable(13),t.vertexUv3s&&c.enable(14),t.vertexTangents&&c.enable(15),t.anisotropy&&c.enable(16),t.alphaHash&&c.enable(17),t.batching&&c.enable(18),t.dispersion&&c.enable(19),t.batchingColor&&c.enable(20),t.gradientMap&&c.enable(21),t.packedNormalMap&&c.enable(22),t.vertexNormals&&c.enable(23),e.push(c.mask),c.disableAll(),t.fog&&c.enable(0),t.useFog&&c.enable(1),t.flatShading&&c.enable(2),t.logarithmicDepthBuffer&&c.enable(3),t.reversedDepthBuffer&&c.enable(4),t.skinning&&c.enable(5),t.morphTargets&&c.enable(6),t.morphNormals&&c.enable(7),t.morphColors&&c.enable(8),t.premultipliedAlpha&&c.enable(9),t.shadowMapEnabled&&c.enable(10),t.doubleSided&&c.enable(11),t.flipSided&&c.enable(12),t.useDepthPacking&&c.enable(13),t.dithering&&c.enable(14),t.transmission&&c.enable(15),t.sheen&&c.enable(16),t.opaque&&c.enable(17),t.pointsUvs&&c.enable(18),t.decodeVideoTexture&&c.enable(19),t.decodeVideoTextureEmissive&&c.enable(20),t.alphaToCoverage&&c.enable(21),t.numLightProbeGrids>0&&c.enable(22),t.hasPositionAttribute&&c.enable(23),e.push(c.mask)}function x(t){let n=h[t.type],r;if(n){let t=o[n];r=e.an.clone(t.uniforms)}else r=t.uniforms;return r}function S(e,n){let r=f.get(n);return r===void 0?(r=new Ft(t,n,e,a),d.push(r),f.set(n,r)):++r.usedTimes,r}function C(e){if(--e.usedTimes===0){let t=d.indexOf(e);d[t]=d[d.length-1],d.pop(),f.delete(e.cacheKey),e.destroy()}}function w(e){l.remove(e)}function T(){l.dispose()}return{getParameters:_,getProgramCacheKey:v,getUniforms:x,acquireProgram:S,releaseProgram:C,releaseShaderCache:w,programs:d,dispose:T}}function Vt(){let e=new WeakMap;function t(t){return e.has(t)}function n(t){let n=e.get(t);return n===void 0&&(n={},e.set(t,n)),n}function r(t){e.delete(t)}function i(t,n,r){e.get(t)[n]=r}function a(){e=new WeakMap}return{has:t,get:n,remove:r,update:i,dispose:a}}function Ht(e,t){return e.groupOrder===t.groupOrder?e.renderOrder===t.renderOrder?e.material.id===t.material.id?e.materialVariant===t.materialVariant?e.z===t.z?e.id-t.id:e.z-t.z:e.materialVariant-t.materialVariant:e.material.id-t.material.id:e.renderOrder-t.renderOrder:e.groupOrder-t.groupOrder}function Ut(e,t){return e.groupOrder===t.groupOrder?e.renderOrder===t.renderOrder?e.z===t.z?e.id-t.id:t.z-e.z:e.renderOrder-t.renderOrder:e.groupOrder-t.groupOrder}function Wt(){let e=[],t=0,n=[],r=[],i=[];function a(){t=0,n.length=0,r.length=0,i.length=0}function o(e){let t=0;return e.isInstancedMesh&&(t+=2),e.isSkinnedMesh&&(t+=1),t}function s(n,r,i,a,s,c){let l=e[t];return l===void 0?(l={id:n.id,object:n,geometry:r,material:i,materialVariant:o(n),groupOrder:a,renderOrder:n.renderOrder,z:s,group:c},e[t]=l):(l.id=n.id,l.object=n,l.geometry=r,l.material=i,l.materialVariant=o(n),l.groupOrder=a,l.renderOrder=n.renderOrder,l.z=s,l.group=c),t++,l}function c(e,t,a,o,c,l){let u=s(e,t,a,o,c,l);a.transmission>0?r.push(u):a.transparent===!0?i.push(u):n.push(u)}function l(e,t,a,o,c,l){let u=s(e,t,a,o,c,l);a.transmission>0?r.unshift(u):a.transparent===!0?i.unshift(u):n.unshift(u)}function u(e,t,a){n.length>1&&n.sort(e||Ht),r.length>1&&r.sort(t||Ut),i.length>1&&i.sort(t||Ut),a&&(n.reverse(),r.reverse(),i.reverse())}function d(){for(let n=t,r=e.length;n<r;n++){let t=e[n];if(t.id===null)break;t.id=null,t.object=null,t.geometry=null,t.material=null,t.group=null}}return{opaque:n,transmissive:r,transparent:i,init:a,push:c,unshift:l,finish:d,sort:u}}function Gt(){let e=new WeakMap;function t(t,n){let r=e.get(t),i;return r===void 0?(i=new Wt,e.set(t,[i])):n>=r.length?(i=new Wt,r.push(i)):i=r[n],i}function n(){e=new WeakMap}return{get:t,dispose:n}}function Kt(){let t={};return{get:function(n){if(t[n.id]!==void 0)return t[n.id];let r;switch(n.type){case`DirectionalLight`:r={direction:new e.hn,color:new e.u};break;case`SpotLight`:r={position:new e.hn,direction:new e.hn,color:new e.u,distance:0,coneCos:0,penumbraCos:0,decay:0};break;case`PointLight`:r={position:new e.hn,color:new e.u,distance:0,decay:0};break;case`HemisphereLight`:r={direction:new e.hn,skyColor:new e.u,groundColor:new e.u};break;case`RectAreaLight`:r={color:new e.u,position:new e.hn,halfWidth:new e.hn,halfHeight:new e.hn};break}return t[n.id]=r,r}}}function qt(){let t={};return{get:function(n){if(t[n.id]!==void 0)return t[n.id];let r;switch(n.type){case`DirectionalLight`:r={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new e.mn};break;case`SpotLight`:r={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new e.mn};break;case`PointLight`:r={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new e.mn,shadowCameraNear:1,shadowCameraFar:1e3};break}return t[n.id]=r,r}}}var Jt=0;function Yt(e,t){return(t.castShadow?2:0)-(e.castShadow?2:0)+ +!!t.map-!!e.map}function Xt(t){let n=new Kt,r=qt(),i={version:0,hash:{directionalLength:-1,pointLength:-1,spotLength:-1,rectAreaLength:-1,hemiLength:-1,numDirectionalShadows:-1,numPointShadows:-1,numSpotShadows:-1,numSpotMaps:-1,numLightProbes:-1},ambient:[0,0,0],probe:[],directional:[],directionalShadow:[],directionalShadowMap:[],directionalShadowMatrix:[],spot:[],spotLightMap:[],spotShadow:[],spotShadowMap:[],spotLightMatrix:[],rectArea:[],rectAreaLTC1:null,rectAreaLTC2:null,point:[],pointShadow:[],pointShadowMap:[],pointShadowMatrix:[],hemi:[],numSpotLightShadowsWithMaps:0,numLightProbes:0};for(let t=0;t<9;t++)i.probe.push(new e.hn);let o=new e.hn,s=new e.V,c=new e.V;function l(e){let o=0,s=0,c=0;for(let e=0;e<9;e++)i.probe[e].set(0,0,0);let l=0,u=0,d=0,f=0,p=0,m=0,h=0,g=0,_=0,v=0,y=0;e.sort(Yt);for(let t=0,a=e.length;t<a;t++){let a=e[t],b=a.color,x=a.intensity,S=a.distance,C=null;if(a.shadow&&a.shadow.map&&(C=a.shadow.map.texture.format===1030?a.shadow.map.texture:a.shadow.map.depthTexture||a.shadow.map.texture),a.isAmbientLight)o+=b.r*x,s+=b.g*x,c+=b.b*x;else if(a.isLightProbe){for(let e=0;e<9;e++)i.probe[e].addScaledVector(a.sh.coefficients[e],x);y++}else if(a.isDirectionalLight){let e=n.get(a);if(e.color.copy(a.color).multiplyScalar(a.intensity),a.castShadow){let e=a.shadow,t=r.get(a);t.shadowIntensity=e.intensity,t.shadowBias=e.bias,t.shadowNormalBias=e.normalBias,t.shadowRadius=e.radius,t.shadowMapSize=e.mapSize,i.directionalShadow[l]=t,i.directionalShadowMap[l]=C,i.directionalShadowMatrix[l]=a.shadow.matrix,m++}i.directional[l]=e,l++}else if(a.isSpotLight){let e=n.get(a);e.position.setFromMatrixPosition(a.matrixWorld),e.color.copy(b).multiplyScalar(x),e.distance=S,e.coneCos=Math.cos(a.angle),e.penumbraCos=Math.cos(a.angle*(1-a.penumbra)),e.decay=a.decay,i.spot[d]=e;let t=a.shadow;if(a.map&&(i.spotLightMap[_]=a.map,_++,t.updateMatrices(a),a.castShadow&&v++),i.spotLightMatrix[d]=t.matrix,a.castShadow){let e=r.get(a);e.shadowIntensity=t.intensity,e.shadowBias=t.bias,e.shadowNormalBias=t.normalBias,e.shadowRadius=t.radius,e.shadowMapSize=t.mapSize,i.spotShadow[d]=e,i.spotShadowMap[d]=C,g++}d++}else if(a.isRectAreaLight){let e=n.get(a);e.color.copy(b).multiplyScalar(x),e.halfWidth.set(a.width*.5,0,0),e.halfHeight.set(0,a.height*.5,0),i.rectArea[f]=e,f++}else if(a.isPointLight){let e=n.get(a);if(e.color.copy(a.color).multiplyScalar(a.intensity),e.distance=a.distance,e.decay=a.decay,a.castShadow){let e=a.shadow,t=r.get(a);t.shadowIntensity=e.intensity,t.shadowBias=e.bias,t.shadowNormalBias=e.normalBias,t.shadowRadius=e.radius,t.shadowMapSize=e.mapSize,t.shadowCameraNear=e.camera.near,t.shadowCameraFar=e.camera.far,i.pointShadow[u]=t,i.pointShadowMap[u]=C,i.pointShadowMatrix[u]=a.shadow.matrix,h++}i.point[u]=e,u++}else if(a.isHemisphereLight){let e=n.get(a);e.skyColor.copy(a.color).multiplyScalar(x),e.groundColor.copy(a.groundColor).multiplyScalar(x),i.hemi[p]=e,p++}}f>0&&(t.has(`OES_texture_float_linear`)===!0?(i.rectAreaLTC1=a.LTC_FLOAT_1,i.rectAreaLTC2=a.LTC_FLOAT_2):(i.rectAreaLTC1=a.LTC_HALF_1,i.rectAreaLTC2=a.LTC_HALF_2)),i.ambient[0]=o,i.ambient[1]=s,i.ambient[2]=c;let b=i.hash;(b.directionalLength!==l||b.pointLength!==u||b.spotLength!==d||b.rectAreaLength!==f||b.hemiLength!==p||b.numDirectionalShadows!==m||b.numPointShadows!==h||b.numSpotShadows!==g||b.numSpotMaps!==_||b.numLightProbes!==y)&&(i.directional.length=l,i.spot.length=d,i.rectArea.length=f,i.point.length=u,i.hemi.length=p,i.directionalShadow.length=m,i.directionalShadowMap.length=m,i.pointShadow.length=h,i.pointShadowMap.length=h,i.spotShadow.length=g,i.spotShadowMap.length=g,i.directionalShadowMatrix.length=m,i.pointShadowMatrix.length=h,i.spotLightMatrix.length=g+_-v,i.spotLightMap.length=_,i.numSpotLightShadowsWithMaps=v,i.numLightProbes=y,b.directionalLength=l,b.pointLength=u,b.spotLength=d,b.rectAreaLength=f,b.hemiLength=p,b.numDirectionalShadows=m,b.numPointShadows=h,b.numSpotShadows=g,b.numSpotMaps=_,b.numLightProbes=y,i.version=Jt++)}function u(e,t){let n=0,r=0,a=0,l=0,u=0,d=t.matrixWorldInverse;for(let t=0,f=e.length;t<f;t++){let f=e[t];if(f.isDirectionalLight){let e=i.directional[n];e.direction.setFromMatrixPosition(f.matrixWorld),o.setFromMatrixPosition(f.target.matrixWorld),e.direction.sub(o),e.direction.transformDirection(d),n++}else if(f.isSpotLight){let e=i.spot[a];e.position.setFromMatrixPosition(f.matrixWorld),e.position.applyMatrix4(d),e.direction.setFromMatrixPosition(f.matrixWorld),o.setFromMatrixPosition(f.target.matrixWorld),e.direction.sub(o),e.direction.transformDirection(d),a++}else if(f.isRectAreaLight){let e=i.rectArea[l];e.position.setFromMatrixPosition(f.matrixWorld),e.position.applyMatrix4(d),c.identity(),s.copy(f.matrixWorld),s.premultiply(d),c.extractRotation(s),e.halfWidth.set(f.width*.5,0,0),e.halfHeight.set(0,f.height*.5,0),e.halfWidth.applyMatrix4(c),e.halfHeight.applyMatrix4(c),l++}else if(f.isPointLight){let e=i.point[r];e.position.setFromMatrixPosition(f.matrixWorld),e.position.applyMatrix4(d),r++}else if(f.isHemisphereLight){let e=i.hemi[u];e.direction.setFromMatrixPosition(f.matrixWorld),e.direction.transformDirection(d),u++}}}return{setup:l,setupView:u,state:i}}function Zt(e){let t=new Xt(e),n=[],r=[],i=[];function a(e){d.camera=e,n.length=0,r.length=0,i.length=0}function o(e){n.push(e)}function s(e){r.push(e)}function c(e){i.push(e)}function l(){t.setup(n)}function u(e){t.setupView(n,e)}let d={lightsArray:n,shadowsArray:r,lightProbeGridArray:i,camera:null,lights:t,transmissionRenderTarget:{},textureUnits:0};return{init:a,state:d,setupLights:l,setupLightsView:u,pushLight:o,pushShadow:s,pushLightProbeGrid:c}}function Qt(e){let t=new WeakMap;function n(n,r=0){let i=t.get(n),a;return i===void 0?(a=new Zt(e),t.set(n,[a])):r>=i.length?(a=new Zt(e),i.push(a)):a=i[r],a}function r(){t=new WeakMap}return{get:n,dispose:r}}var $t=`void main() {
4054
+ gl_Position = vec4( position, 1.0 );
4055
+ }`,en=`uniform sampler2D shadow_pass;
4056
+ uniform vec2 resolution;
4057
+ uniform float radius;
4058
+ void main() {
4059
+ const float samples = float( VSM_SAMPLES );
4060
+ float mean = 0.0;
4061
+ float squared_mean = 0.0;
4062
+ float uvStride = samples <= 1.0 ? 0.0 : 2.0 / ( samples - 1.0 );
4063
+ float uvStart = samples <= 1.0 ? 0.0 : - 1.0;
4064
+ for ( float i = 0.0; i < samples; i ++ ) {
4065
+ float uvOffset = uvStart + i * uvStride;
4066
+ #ifdef HORIZONTAL_PASS
4067
+ vec2 distribution = texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( uvOffset, 0.0 ) * radius ) / resolution ).rg;
4068
+ mean += distribution.x;
4069
+ squared_mean += distribution.y * distribution.y + distribution.x * distribution.x;
4070
+ #else
4071
+ float depth = texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, uvOffset ) * radius ) / resolution ).r;
4072
+ mean += depth;
4073
+ squared_mean += depth * depth;
4074
+ #endif
4075
+ }
4076
+ mean = mean / samples;
4077
+ squared_mean = squared_mean / samples;
4078
+ float std_dev = sqrt( max( 0.0, squared_mean - mean * mean ) );
4079
+ gl_FragColor = vec4( mean, std_dev, 0.0, 1.0 );
4080
+ }`,tn=[new e.hn(1,0,0),new e.hn(-1,0,0),new e.hn(0,1,0),new e.hn(0,-1,0),new e.hn(0,0,1),new e.hn(0,0,-1)],nn=[new e.hn(0,-1,0),new e.hn(0,-1,0),new e.hn(0,0,1),new e.hn(0,0,-1),new e.hn(0,-1,0),new e.hn(0,-1,0)],rn=new e.V,an=new e.hn,on=new e.hn;function sn(t,n,r){let i=new e.D,a=new e.mn,o=new e.mn,s=new e.gn,c=new e.W,l=new e.G,u={},d=r.maxTextureSize,f={0:1,1:0,2:2},p=new e.Qt({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new e.mn},radius:{value:4}},vertexShader:$t,fragmentShader:en}),m=p.clone();m.defines.HORIZONTAL_PASS=1;let h=new e.s;h.setAttribute(`position`,new e.o(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));let g=new e.H(h,p),_=this;this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=1;let v=this.type;this.render=function(n,r,c){if(_.enabled===!1||_.autoUpdate===!1&&_.needsUpdate===!1||n.length===0)return;this.type===2&&(e.kn(`WebGLShadowMap: PCFSoftShadowMap has been deprecated. Using PCFShadowMap instead.`),this.type=1);let l=t.getRenderTarget(),u=t.getActiveCubeFace(),f=t.getActiveMipmapLevel(),p=t.state;p.setBlending(0),p.buffers.depth.getReversed()===!0?p.buffers.color.setClear(0,0,0,0):p.buffers.color.setClear(1,1,1,1),p.buffers.depth.setTest(!0),p.setScissorTest(!1);let m=v!==this.type;m&&r.traverse(function(e){e.material&&(Array.isArray(e.material)?e.material.forEach(e=>e.needsUpdate=!0):e.material.needsUpdate=!0)});for(let l=0,u=n.length;l<u;l++){let u=n[l],f=u.shadow;if(f===void 0){e.kn(`WebGLShadowMap:`,u,`has no shadow.`);continue}if(f.autoUpdate===!1&&f.needsUpdate===!1)continue;a.copy(f.mapSize);let h=f.getFrameExtents();a.multiply(h),o.copy(f.mapSize),(a.x>d||a.y>d)&&(a.x>d&&(o.x=Math.floor(d/h.x),a.x=o.x*h.x,f.mapSize.x=o.x),a.y>d&&(o.y=Math.floor(d/h.y),a.y=o.y*h.y,f.mapSize.y=o.y));let g=t.state.buffers.depth.getReversed();if(f.camera._reversedDepth=g,f.map===null||m===!0){if(f.map!==null&&(f.map.depthTexture!==null&&(f.map.depthTexture.dispose(),f.map.depthTexture=null),f.map.dispose()),this.type===3){if(u.isPointLight){e.kn(`WebGLShadowMap: VSM shadow maps are not supported for PointLights. Use PCF or BasicShadowMap instead.`);continue}f.map=new e.vn(a.x,a.y,{format:e.Lt,type:e.A,minFilter:e.N,magFilter:e.N,generateMipmaps:!1}),f.map.texture.name=u.name+`.shadowMap`,f.map.depthTexture=new e.x(a.x,a.y,e.E),f.map.depthTexture.name=u.name+`.shadowMapDepth`,f.map.depthTexture.format=e.y,f.map.depthTexture.compareFunction=null,f.map.depthTexture.minFilter=e.q,f.map.depthTexture.magFilter=e.q}else u.isPointLight?(f.map=new P(a.x),f.map.depthTexture=new e.m(a.x,e.un)):(f.map=new e.vn(a.x,a.y),f.map.depthTexture=new e.x(a.x,a.y,e.un)),f.map.depthTexture.name=u.name+`.shadowMap`,f.map.depthTexture.format=e.y,this.type===1?(f.map.depthTexture.compareFunction=g?518:515,f.map.depthTexture.minFilter=e.N,f.map.depthTexture.magFilter=e.N):(f.map.depthTexture.compareFunction=null,f.map.depthTexture.minFilter=e.q,f.map.depthTexture.magFilter=e.q);f.camera.updateProjectionMatrix()}let _=f.map.isWebGLCubeRenderTarget?6:1;for(let e=0;e<_;e++){if(f.map.isWebGLCubeRenderTarget)t.setRenderTarget(f.map,e),t.clear();else{e===0&&(t.setRenderTarget(f.map),t.clear());let n=f.getViewport(e);s.set(o.x*n.x,o.y*n.y,o.x*n.z,o.y*n.w),p.viewport(s)}if(u.isPointLight){let t=f.camera,n=f.matrix,r=u.distance||t.far;r!==t.far&&(t.far=r,t.updateProjectionMatrix()),an.setFromMatrixPosition(u.matrixWorld),t.position.copy(an),on.copy(t.position),on.add(tn[e]),t.up.copy(nn[e]),t.lookAt(on),t.updateMatrixWorld(),n.makeTranslation(-an.x,-an.y,-an.z),rn.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),f._frustum.setFromProjectionMatrix(rn,t.coordinateSystem,t.reversedDepth)}else f.updateMatrices(u);i=f.getFrustum(),x(r,c,f.camera,u,this.type)}f.isPointLightShadow!==!0&&this.type===3&&y(f,c),f.needsUpdate=!1}v=this.type,_.needsUpdate=!1,t.setRenderTarget(l,u,f)};function y(r,i){let o=n.update(g);p.defines.VSM_SAMPLES!==r.blurSamples&&(p.defines.VSM_SAMPLES=r.blurSamples,m.defines.VSM_SAMPLES=r.blurSamples,p.needsUpdate=!0,m.needsUpdate=!0),r.mapPass===null&&(r.mapPass=new e.vn(a.x,a.y,{format:e.Lt,type:e.A})),p.uniforms.shadow_pass.value=r.map.depthTexture,p.uniforms.resolution.value=r.mapSize,p.uniforms.radius.value=r.radius,t.setRenderTarget(r.mapPass),t.clear(),t.renderBufferDirect(i,null,o,p,g,null),m.uniforms.shadow_pass.value=r.mapPass.texture,m.uniforms.resolution.value=r.mapSize,m.uniforms.radius.value=r.radius,t.setRenderTarget(r.map),t.clear(),t.renderBufferDirect(i,null,o,m,g,null)}function b(e,n,r,i){let a=null,o=r.isPointLight===!0?e.customDistanceMaterial:e.customDepthMaterial;if(o!==void 0)a=o;else if(a=r.isPointLight===!0?l:c,t.localClippingEnabled&&n.clipShadows===!0&&Array.isArray(n.clippingPlanes)&&n.clippingPlanes.length!==0||n.displacementMap&&n.displacementScale!==0||n.alphaMap&&n.alphaTest>0||n.map&&n.alphaTest>0||n.alphaToCoverage===!0){let e=a.uuid,t=n.uuid,r=u[e];r===void 0&&(r={},u[e]=r);let i=r[t];i===void 0&&(i=a.clone(),r[t]=i,n.addEventListener(`dispose`,S)),a=i}if(a.visible=n.visible,a.wireframe=n.wireframe,i===3?a.side=n.shadowSide===null?n.side:n.shadowSide:a.side=n.shadowSide===null?f[n.side]:n.shadowSide,a.alphaMap=n.alphaMap,a.alphaTest=n.alphaToCoverage===!0?.5:n.alphaTest,a.map=n.map,a.clipShadows=n.clipShadows,a.clippingPlanes=n.clippingPlanes,a.clipIntersection=n.clipIntersection,a.displacementMap=n.displacementMap,a.displacementScale=n.displacementScale,a.displacementBias=n.displacementBias,a.wireframeLinewidth=n.wireframeLinewidth,a.linewidth=n.linewidth,r.isPointLight===!0&&a.isMeshDistanceMaterial===!0){let e=t.properties.get(a);e.light=r}return a}function x(e,r,a,o,s){if(e.visible===!1)return;if(e.layers.test(r.layers)&&(e.isMesh||e.isLine||e.isPoints)&&(e.castShadow||e.receiveShadow&&s===3)&&(!e.frustumCulled||i.intersectsObject(e))){e.modelViewMatrix.multiplyMatrices(a.matrixWorldInverse,e.matrixWorld);let i=n.update(e),c=e.material;if(Array.isArray(c)){let n=i.groups;for(let l=0,u=n.length;l<u;l++){let u=n[l],d=c[u.materialIndex];if(d&&d.visible){let n=b(e,d,o,s);e.onBeforeShadow(t,e,r,a,i,n,u),t.renderBufferDirect(a,null,i,n,e,u),e.onAfterShadow(t,e,r,a,i,n,u)}}}else if(c.visible){let n=b(e,c,o,s);e.onBeforeShadow(t,e,r,a,i,n,null),t.renderBufferDirect(a,null,i,n,e,null),e.onAfterShadow(t,e,r,a,i,n,null)}}let c=e.children;for(let e=0,t=c.length;e<t;e++)x(c[e],r,a,o,s)}function S(e){e.target.removeEventListener(`dispose`,S);for(let t in u){let n=u[t],r=e.target.uuid;r in n&&(n[r].dispose(),delete n[r])}}}function cn(t,n){function r(){let n=!1,r=new e.gn,i=null,a=new e.gn(0,0,0,0);return{setMask:function(e){i!==e&&!n&&(t.colorMask(e,e,e,e),i=e)},setLocked:function(e){n=e},setClear:function(e,n,i,o,s){s===!0&&(e*=o,n*=o,i*=o),r.set(e,n,i,o),a.equals(r)===!1&&(t.clearColor(e,n,i,o),a.copy(r))},reset:function(){n=!1,i=null,a.set(-1,0,0,0)}}}function i(){let r=!1,i=!1,a=null,o=null,s=null;return{setReversed:function(e){if(i!==e){let t=n.get(`EXT_clip_control`);e?t.clipControlEXT(t.LOWER_LEFT_EXT,t.ZERO_TO_ONE_EXT):t.clipControlEXT(t.LOWER_LEFT_EXT,t.NEGATIVE_ONE_TO_ONE_EXT),i=e;let r=s;s=null,this.setClear(r)}},getReversed:function(){return i},setTest:function(e){e?F(t.DEPTH_TEST):I(t.DEPTH_TEST)},setMask:function(e){a!==e&&!r&&(t.depthMask(e),a=e)},setFunc:function(n){if(i&&(n=e.Wt[n]),o!==n){switch(n){case 0:t.depthFunc(t.NEVER);break;case 1:t.depthFunc(t.ALWAYS);break;case 2:t.depthFunc(t.LESS);break;case 3:t.depthFunc(t.LEQUAL);break;case 4:t.depthFunc(t.EQUAL);break;case 5:t.depthFunc(t.GEQUAL);break;case 6:t.depthFunc(t.GREATER);break;case 7:t.depthFunc(t.NOTEQUAL);break;default:t.depthFunc(t.LEQUAL)}o=n}},setLocked:function(e){r=e},setClear:function(e){s!==e&&(s=e,i&&(e=1-e),t.clearDepth(e))},reset:function(){r=!1,a=null,o=null,s=null,i=!1}}}function a(){let e=!1,n=null,r=null,i=null,a=null,o=null,s=null,c=null,l=null;return{setTest:function(n){e||(n?F(t.STENCIL_TEST):I(t.STENCIL_TEST))},setMask:function(r){n!==r&&!e&&(t.stencilMask(r),n=r)},setFunc:function(e,n,o){(r!==e||i!==n||a!==o)&&(t.stencilFunc(e,n,o),r=e,i=n,a=o)},setOp:function(e,n,r){(o!==e||s!==n||c!==r)&&(t.stencilOp(e,n,r),o=e,s=n,c=r)},setLocked:function(t){e=t},setClear:function(e){l!==e&&(t.clearStencil(e),l=e)},reset:function(){e=!1,n=null,r=null,i=null,a=null,o=null,s=null,c=null,l=null}}}let o=new r,s=new i,c=new a,l=new WeakMap,u=new WeakMap,d={},f={},p={},m=new WeakMap,h=[],g=null,_=!1,v=null,y=null,b=null,x=null,S=null,C=null,w=null,T=new e.u(0,0,0),E=0,D=!1,O=null,k=null,A=null,j=null,M=null,N=t.getParameter(t.MAX_COMBINED_TEXTURE_IMAGE_UNITS),ee=!1,P=0,te=t.getParameter(t.VERSION);te.indexOf(`WebGL`)===-1?te.indexOf(`OpenGL ES`)!==-1&&(P=parseFloat(/^OpenGL ES (\d)/.exec(te)[1]),ee=P>=2):(P=parseFloat(/^WebGL (\d)/.exec(te)[1]),ee=P>=1);let ne=null,re={},ie=t.getParameter(t.SCISSOR_BOX),ae=t.getParameter(t.VIEWPORT),oe=new e.gn().fromArray(ie),se=new e.gn().fromArray(ae);function ce(e,n,r,i){let a=new Uint8Array(4),o=t.createTexture();t.bindTexture(e,o),t.texParameteri(e,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(e,t.TEXTURE_MAG_FILTER,t.NEAREST);for(let o=0;o<r;o++)e===t.TEXTURE_3D||e===t.TEXTURE_2D_ARRAY?t.texImage3D(n,0,t.RGBA,1,1,i,0,t.RGBA,t.UNSIGNED_BYTE,a):t.texImage2D(n+o,0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,a);return o}let le={};le[t.TEXTURE_2D]=ce(t.TEXTURE_2D,t.TEXTURE_2D,1),le[t.TEXTURE_CUBE_MAP]=ce(t.TEXTURE_CUBE_MAP,t.TEXTURE_CUBE_MAP_POSITIVE_X,6),le[t.TEXTURE_2D_ARRAY]=ce(t.TEXTURE_2D_ARRAY,t.TEXTURE_2D_ARRAY,1,1),le[t.TEXTURE_3D]=ce(t.TEXTURE_3D,t.TEXTURE_3D,1,1),o.setClear(0,0,0,1),s.setClear(1),c.setClear(0),F(t.DEPTH_TEST),s.setFunc(3),pe(!1),me(1),F(t.CULL_FACE),B(0);function F(e){d[e]!==!0&&(t.enable(e),d[e]=!0)}function I(e){d[e]!==!1&&(t.disable(e),d[e]=!1)}function ue(e,n){return p[e]===n?!1:(t.bindFramebuffer(e,n),p[e]=n,e===t.DRAW_FRAMEBUFFER&&(p[t.FRAMEBUFFER]=n),e===t.FRAMEBUFFER&&(p[t.DRAW_FRAMEBUFFER]=n),!0)}function L(e,n){let r=h,i=!1;if(e){r=m.get(n),r===void 0&&(r=[],m.set(n,r));let a=e.textures;if(r.length!==a.length||r[0]!==t.COLOR_ATTACHMENT0){for(let e=0,n=a.length;e<n;e++)r[e]=t.COLOR_ATTACHMENT0+e;r.length=a.length,i=!0}}else r[0]!==t.BACK&&(r[0]=t.BACK,i=!0);i&&t.drawBuffers(r)}function R(e){return g===e?!1:(t.useProgram(e),g=e,!0)}let de={100:t.FUNC_ADD,101:t.FUNC_SUBTRACT,102:t.FUNC_REVERSE_SUBTRACT};de[103]=t.MIN,de[104]=t.MAX;let z={200:t.ZERO,201:t.ONE,202:t.SRC_COLOR,204:t.SRC_ALPHA,210:t.SRC_ALPHA_SATURATE,208:t.DST_COLOR,206:t.DST_ALPHA,203:t.ONE_MINUS_SRC_COLOR,205:t.ONE_MINUS_SRC_ALPHA,209:t.ONE_MINUS_DST_COLOR,207:t.ONE_MINUS_DST_ALPHA,211:t.CONSTANT_COLOR,212:t.ONE_MINUS_CONSTANT_COLOR,213:t.CONSTANT_ALPHA,214:t.ONE_MINUS_CONSTANT_ALPHA};function B(n,r,i,a,o,s,c,l,u,d){if(n===0){_===!0&&(I(t.BLEND),_=!1);return}if(_===!1&&(F(t.BLEND),_=!0),n!==5){if(n!==v||d!==D){if((y!==100||S!==100)&&(t.blendEquation(t.FUNC_ADD),y=100,S=100),d)switch(n){case 1:t.blendFuncSeparate(t.ONE,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA);break;case 2:t.blendFunc(t.ONE,t.ONE);break;case 3:t.blendFuncSeparate(t.ZERO,t.ONE_MINUS_SRC_COLOR,t.ZERO,t.ONE);break;case 4:t.blendFuncSeparate(t.DST_COLOR,t.ONE_MINUS_SRC_ALPHA,t.ZERO,t.ONE);break;default:e.Cn(`WebGLState: Invalid blending: `,n);break}else switch(n){case 1:t.blendFuncSeparate(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA);break;case 2:t.blendFuncSeparate(t.SRC_ALPHA,t.ONE,t.ONE,t.ONE);break;case 3:e.Cn(`WebGLState: SubtractiveBlending requires material.premultipliedAlpha = true`);break;case 4:e.Cn(`WebGLState: MultiplyBlending requires material.premultipliedAlpha = true`);break;default:e.Cn(`WebGLState: Invalid blending: `,n);break}b=null,x=null,C=null,w=null,T.set(0,0,0),E=0,v=n,D=d}return}o||=r,s||=i,c||=a,(r!==y||o!==S)&&(t.blendEquationSeparate(de[r],de[o]),y=r,S=o),(i!==b||a!==x||s!==C||c!==w)&&(t.blendFuncSeparate(z[i],z[a],z[s],z[c]),b=i,x=a,C=s,w=c),(l.equals(T)===!1||u!==E)&&(t.blendColor(l.r,l.g,l.b,u),T.copy(l),E=u),v=n,D=!1}function fe(e,n){e.side===2?I(t.CULL_FACE):F(t.CULL_FACE);let r=e.side===1;n&&(r=!r),pe(r),e.blending===1&&e.transparent===!1?B(0):B(e.blending,e.blendEquation,e.blendSrc,e.blendDst,e.blendEquationAlpha,e.blendSrcAlpha,e.blendDstAlpha,e.blendColor,e.blendAlpha,e.premultipliedAlpha),s.setFunc(e.depthFunc),s.setTest(e.depthTest),s.setMask(e.depthWrite),o.setMask(e.colorWrite);let i=e.stencilWrite;c.setTest(i),i&&(c.setMask(e.stencilWriteMask),c.setFunc(e.stencilFunc,e.stencilRef,e.stencilFuncMask),c.setOp(e.stencilFail,e.stencilZFail,e.stencilZPass)),H(e.polygonOffset,e.polygonOffsetFactor,e.polygonOffsetUnits),e.alphaToCoverage===!0?F(t.SAMPLE_ALPHA_TO_COVERAGE):I(t.SAMPLE_ALPHA_TO_COVERAGE)}function pe(e){O!==e&&(e?t.frontFace(t.CW):t.frontFace(t.CCW),O=e)}function me(e){e===0?I(t.CULL_FACE):(F(t.CULL_FACE),e!==k&&(e===1?t.cullFace(t.BACK):e===2?t.cullFace(t.FRONT):t.cullFace(t.FRONT_AND_BACK))),k=e}function V(e){e!==A&&(ee&&t.lineWidth(e),A=e)}function H(e,n,r){e?(F(t.POLYGON_OFFSET_FILL),(j!==n||M!==r)&&(j=n,M=r,s.getReversed()&&(n=-n),t.polygonOffset(n,r))):I(t.POLYGON_OFFSET_FILL)}function U(e){e?F(t.SCISSOR_TEST):I(t.SCISSOR_TEST)}function W(e){e===void 0&&(e=t.TEXTURE0+N-1),ne!==e&&(t.activeTexture(e),ne=e)}function he(e,n,r){r===void 0&&(r=ne===null?t.TEXTURE0+N-1:ne);let i=re[r];i===void 0&&(i={type:void 0,texture:void 0},re[r]=i),(i.type!==e||i.texture!==n)&&(ne!==r&&(t.activeTexture(r),ne=r),t.bindTexture(e,n||le[e]),i.type=e,i.texture=n)}function ge(){let e=re[ne];e!==void 0&&e.type!==void 0&&(t.bindTexture(e.type,null),e.type=void 0,e.texture=void 0)}function _e(){try{t.compressedTexImage2D(...arguments)}catch(t){e.Cn(`WebGLState:`,t)}}function ve(){try{t.compressedTexImage3D(...arguments)}catch(t){e.Cn(`WebGLState:`,t)}}function ye(){try{t.texSubImage2D(...arguments)}catch(t){e.Cn(`WebGLState:`,t)}}function be(){try{t.texSubImage3D(...arguments)}catch(t){e.Cn(`WebGLState:`,t)}}function xe(){try{t.compressedTexSubImage2D(...arguments)}catch(t){e.Cn(`WebGLState:`,t)}}function Se(){try{t.compressedTexSubImage3D(...arguments)}catch(t){e.Cn(`WebGLState:`,t)}}function Ce(){try{t.texStorage2D(...arguments)}catch(t){e.Cn(`WebGLState:`,t)}}function we(){try{t.texStorage3D(...arguments)}catch(t){e.Cn(`WebGLState:`,t)}}function Te(){try{t.texImage2D(...arguments)}catch(t){e.Cn(`WebGLState:`,t)}}function Ee(){try{t.texImage3D(...arguments)}catch(t){e.Cn(`WebGLState:`,t)}}function De(e){return f[e]===void 0?t.getParameter(e):f[e]}function Oe(e,n){f[e]!==n&&(t.pixelStorei(e,n),f[e]=n)}function G(e){oe.equals(e)===!1&&(t.scissor(e.x,e.y,e.z,e.w),oe.copy(e))}function ke(e){se.equals(e)===!1&&(t.viewport(e.x,e.y,e.z,e.w),se.copy(e))}function K(e,n){let r=u.get(n);r===void 0&&(r=new WeakMap,u.set(n,r));let i=r.get(e);i===void 0&&(i=t.getUniformBlockIndex(n,e.name),r.set(e,i))}function q(e,n){let r=u.get(n).get(e);l.get(n)!==r&&(t.uniformBlockBinding(n,r,e.__bindingPointIndex),l.set(n,r))}function J(){t.disable(t.BLEND),t.disable(t.CULL_FACE),t.disable(t.DEPTH_TEST),t.disable(t.POLYGON_OFFSET_FILL),t.disable(t.SCISSOR_TEST),t.disable(t.STENCIL_TEST),t.disable(t.SAMPLE_ALPHA_TO_COVERAGE),t.blendEquation(t.FUNC_ADD),t.blendFunc(t.ONE,t.ZERO),t.blendFuncSeparate(t.ONE,t.ZERO,t.ONE,t.ZERO),t.blendColor(0,0,0,0),t.colorMask(!0,!0,!0,!0),t.clearColor(0,0,0,0),t.depthMask(!0),t.depthFunc(t.LESS),s.setReversed(!1),t.clearDepth(1),t.stencilMask(4294967295),t.stencilFunc(t.ALWAYS,0,4294967295),t.stencilOp(t.KEEP,t.KEEP,t.KEEP),t.clearStencil(0),t.cullFace(t.BACK),t.frontFace(t.CCW),t.polygonOffset(0,0),t.activeTexture(t.TEXTURE0),t.bindFramebuffer(t.FRAMEBUFFER,null),t.bindFramebuffer(t.DRAW_FRAMEBUFFER,null),t.bindFramebuffer(t.READ_FRAMEBUFFER,null),t.useProgram(null),t.lineWidth(1),t.scissor(0,0,t.canvas.width,t.canvas.height),t.viewport(0,0,t.canvas.width,t.canvas.height),t.pixelStorei(t.PACK_ALIGNMENT,4),t.pixelStorei(t.UNPACK_ALIGNMENT,4),t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,!1),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),t.pixelStorei(t.UNPACK_COLORSPACE_CONVERSION_WEBGL,t.BROWSER_DEFAULT_WEBGL),t.pixelStorei(t.PACK_ROW_LENGTH,0),t.pixelStorei(t.PACK_SKIP_PIXELS,0),t.pixelStorei(t.PACK_SKIP_ROWS,0),t.pixelStorei(t.UNPACK_ROW_LENGTH,0),t.pixelStorei(t.UNPACK_IMAGE_HEIGHT,0),t.pixelStorei(t.UNPACK_SKIP_PIXELS,0),t.pixelStorei(t.UNPACK_SKIP_ROWS,0),t.pixelStorei(t.UNPACK_SKIP_IMAGES,0),d={},f={},ne=null,re={},p={},m=new WeakMap,h=[],g=null,_=!1,v=null,y=null,b=null,x=null,S=null,C=null,w=null,T=new e.u(0,0,0),E=0,D=!1,O=null,k=null,A=null,j=null,M=null,oe.set(0,0,t.canvas.width,t.canvas.height),se.set(0,0,t.canvas.width,t.canvas.height),o.reset(),s.reset(),c.reset()}return{buffers:{color:o,depth:s,stencil:c},enable:F,disable:I,bindFramebuffer:ue,drawBuffers:L,useProgram:R,setBlending:B,setMaterial:fe,setFlipSided:pe,setCullFace:me,setLineWidth:V,setPolygonOffset:H,setScissorTest:U,activeTexture:W,bindTexture:he,unbindTexture:ge,compressedTexImage2D:_e,compressedTexImage3D:ve,texImage2D:Te,texImage3D:Ee,pixelStorei:Oe,getParameter:De,updateUBOMapping:K,uniformBlockBinding:q,texStorage2D:Ce,texStorage3D:we,texSubImage2D:ye,texSubImage3D:be,compressedTexSubImage2D:xe,compressedTexSubImage3D:Se,scissor:G,viewport:ke,reset:J}}function ln(t,n,r,i,a,o,s){let c=n.has(`WEBGL_multisampled_render_to_texture`)?n.get(`WEBGL_multisampled_render_to_texture`):null,l=typeof navigator>`u`?!1:/OculusBrowser/g.test(navigator.userAgent),u=new e.mn,d=new WeakMap,f=new Set,p,m=new WeakMap,h=!1;try{h=typeof OffscreenCanvas<`u`&&new OffscreenCanvas(1,1).getContext(`2d`)!==null}catch{}function g(t,n){return h?new OffscreenCanvas(t,n):e.Sn(`canvas`)}function _(t,n,r){let i=1,a=_e(t);if((a.width>r||a.height>r)&&(i=r/Math.max(a.width,a.height)),i<1)if(typeof HTMLImageElement<`u`&&t instanceof HTMLImageElement||typeof HTMLCanvasElement<`u`&&t instanceof HTMLCanvasElement||typeof ImageBitmap<`u`&&t instanceof ImageBitmap||typeof VideoFrame<`u`&&t instanceof VideoFrame){let r=Math.floor(i*a.width),o=Math.floor(i*a.height);p===void 0&&(p=g(r,o));let s=n?g(r,o):p;return s.width=r,s.height=o,s.getContext(`2d`).drawImage(t,0,0,r,o),e.kn(`WebGLRenderer: Texture has been resized from (`+a.width+`x`+a.height+`) to (`+r+`x`+o+`).`),s}else return`data`in t&&e.kn(`WebGLRenderer: Image in DataTexture is too big (`+a.width+`x`+a.height+`).`),t;return t}function v(e){return e.generateMipmaps}function y(e){t.generateMipmap(e)}function b(e){return e.isWebGLCubeRenderTarget?t.TEXTURE_CUBE_MAP:e.isWebGL3DRenderTarget?t.TEXTURE_3D:e.isWebGLArrayRenderTarget||e.isCompressedArrayTexture?t.TEXTURE_2D_ARRAY:t.TEXTURE_2D}function x(r,i,a,o,s,c=!1){if(r!==null){if(t[r]!==void 0)return t[r];e.kn(`WebGLRenderer: Attempt to use non-existing WebGL internal format '`+r+`'`)}let l;o&&(l=n.get(`EXT_texture_norm16`),l||e.kn(`WebGLRenderer: Unable to use normalized textures without EXT_texture_norm16 extension`));let u=i;if(i===t.RED&&(a===t.FLOAT&&(u=t.R32F),a===t.HALF_FLOAT&&(u=t.R16F),a===t.UNSIGNED_BYTE&&(u=t.R8),a===t.UNSIGNED_SHORT&&l&&(u=l.R16_EXT),a===t.SHORT&&l&&(u=l.R16_SNORM_EXT)),i===t.RED_INTEGER&&(a===t.UNSIGNED_BYTE&&(u=t.R8UI),a===t.UNSIGNED_SHORT&&(u=t.R16UI),a===t.UNSIGNED_INT&&(u=t.R32UI),a===t.BYTE&&(u=t.R8I),a===t.SHORT&&(u=t.R16I),a===t.INT&&(u=t.R32I)),i===t.RG&&(a===t.FLOAT&&(u=t.RG32F),a===t.HALF_FLOAT&&(u=t.RG16F),a===t.UNSIGNED_BYTE&&(u=t.RG8),a===t.UNSIGNED_SHORT&&l&&(u=l.RG16_EXT),a===t.SHORT&&l&&(u=l.RG16_SNORM_EXT)),i===t.RG_INTEGER&&(a===t.UNSIGNED_BYTE&&(u=t.RG8UI),a===t.UNSIGNED_SHORT&&(u=t.RG16UI),a===t.UNSIGNED_INT&&(u=t.RG32UI),a===t.BYTE&&(u=t.RG8I),a===t.SHORT&&(u=t.RG16I),a===t.INT&&(u=t.RG32I)),i===t.RGB_INTEGER&&(a===t.UNSIGNED_BYTE&&(u=t.RGB8UI),a===t.UNSIGNED_SHORT&&(u=t.RGB16UI),a===t.UNSIGNED_INT&&(u=t.RGB32UI),a===t.BYTE&&(u=t.RGB8I),a===t.SHORT&&(u=t.RGB16I),a===t.INT&&(u=t.RGB32I)),i===t.RGBA_INTEGER&&(a===t.UNSIGNED_BYTE&&(u=t.RGBA8UI),a===t.UNSIGNED_SHORT&&(u=t.RGBA16UI),a===t.UNSIGNED_INT&&(u=t.RGBA32UI),a===t.BYTE&&(u=t.RGBA8I),a===t.SHORT&&(u=t.RGBA16I),a===t.INT&&(u=t.RGBA32I)),i===t.RGB&&(a===t.UNSIGNED_SHORT&&l&&(u=l.RGB16_EXT),a===t.SHORT&&l&&(u=l.RGB16_SNORM_EXT),a===t.UNSIGNED_INT_5_9_9_9_REV&&(u=t.RGB9_E5),a===t.UNSIGNED_INT_10F_11F_11F_REV&&(u=t.R11F_G11F_B10F)),i===t.RGBA){let n=c?e.L:e.d.getTransfer(s);a===t.FLOAT&&(u=t.RGBA32F),a===t.HALF_FLOAT&&(u=t.RGBA16F),a===t.UNSIGNED_BYTE&&(u=n===`srgb`?t.SRGB8_ALPHA8:t.RGBA8),a===t.UNSIGNED_SHORT&&l&&(u=l.RGBA16_EXT),a===t.SHORT&&l&&(u=l.RGBA16_SNORM_EXT),a===t.UNSIGNED_SHORT_4_4_4_4&&(u=t.RGBA4),a===t.UNSIGNED_SHORT_5_5_5_1&&(u=t.RGB5_A1)}return(u===t.R16F||u===t.R32F||u===t.RG16F||u===t.RG32F||u===t.RGBA16F||u===t.RGBA32F)&&n.get(`EXT_color_buffer_float`),u}function S(n,r){let i;return n?r===null||r===1014||r===1020?i=t.DEPTH24_STENCIL8:r===1015?i=t.DEPTH32F_STENCIL8:r===1012&&(i=t.DEPTH24_STENCIL8,e.kn(`DepthTexture: 16 bit depth attachment is not supported with stencil. Using 24-bit attachment.`)):r===null||r===1014||r===1020?i=t.DEPTH_COMPONENT24:r===1015?i=t.DEPTH_COMPONENT32F:r===1012&&(i=t.DEPTH_COMPONENT16),i}function C(e,t){return v(e)===!0||e.isFramebufferTexture&&e.minFilter!==1003&&e.minFilter!==1006?Math.log2(Math.max(t.width,t.height))+1:e.mipmaps!==void 0&&e.mipmaps.length>0?e.mipmaps.length:e.isCompressedTexture&&Array.isArray(e.image)?t.mipmaps.length:1}function w(e){let t=e.target;t.removeEventListener(`dispose`,w),E(t),t.isVideoTexture&&d.delete(t),t.isHTMLTexture&&f.delete(t)}function T(e){let t=e.target;t.removeEventListener(`dispose`,T),O(t)}function E(e){let t=i.get(e);if(t.__webglInit===void 0)return;let n=e.source,r=m.get(n);if(r){let i=r[t.__cacheKey];i.usedTimes--,i.usedTimes===0&&D(e),Object.keys(r).length===0&&m.delete(n)}i.remove(e)}function D(e){let n=i.get(e);t.deleteTexture(n.__webglTexture);let r=e.source,a=m.get(r);delete a[n.__cacheKey],s.memory.textures--}function O(e){let n=i.get(e);if(e.depthTexture&&(e.depthTexture.dispose(),i.remove(e.depthTexture)),e.isWebGLCubeRenderTarget)for(let e=0;e<6;e++){if(Array.isArray(n.__webglFramebuffer[e]))for(let r=0;r<n.__webglFramebuffer[e].length;r++)t.deleteFramebuffer(n.__webglFramebuffer[e][r]);else t.deleteFramebuffer(n.__webglFramebuffer[e]);n.__webglDepthbuffer&&t.deleteRenderbuffer(n.__webglDepthbuffer[e])}else{if(Array.isArray(n.__webglFramebuffer))for(let e=0;e<n.__webglFramebuffer.length;e++)t.deleteFramebuffer(n.__webglFramebuffer[e]);else t.deleteFramebuffer(n.__webglFramebuffer);if(n.__webglDepthbuffer&&t.deleteRenderbuffer(n.__webglDepthbuffer),n.__webglMultisampledFramebuffer&&t.deleteFramebuffer(n.__webglMultisampledFramebuffer),n.__webglColorRenderbuffer)for(let e=0;e<n.__webglColorRenderbuffer.length;e++)n.__webglColorRenderbuffer[e]&&t.deleteRenderbuffer(n.__webglColorRenderbuffer[e]);n.__webglDepthRenderbuffer&&t.deleteRenderbuffer(n.__webglDepthRenderbuffer)}let r=e.textures;for(let e=0,n=r.length;e<n;e++){let n=i.get(r[e]);n.__webglTexture&&(t.deleteTexture(n.__webglTexture),s.memory.textures--),i.remove(r[e])}i.remove(e)}let k=0;function A(){k=0}function j(){return k}function M(e){k=e}function N(){let t=k;return t>=a.maxTextures&&e.kn(`WebGLTextures: Trying to use `+t+` texture units while this GPU supports only `+a.maxTextures),k+=1,t}function ee(e){let t=[];return t.push(e.wrapS),t.push(e.wrapT),t.push(e.wrapR||0),t.push(e.magFilter),t.push(e.minFilter),t.push(e.anisotropy),t.push(e.internalFormat),t.push(e.format),t.push(e.type),t.push(e.generateMipmaps),t.push(e.premultiplyAlpha),t.push(e.flipY),t.push(e.unpackAlignment),t.push(e.colorSpace),t.join()}function P(n,a){let o=i.get(n);if(n.isVideoTexture&&he(n),n.isRenderTargetTexture===!1&&n.isExternalTexture!==!0&&n.version>0&&o.__version!==n.version){let t=n.image;if(t===null)e.kn(`WebGLRenderer: Texture marked for update but no image data found.`);else if(t.complete===!1)e.kn(`WebGLRenderer: Texture marked for update but image is incomplete`);else{I(o,n,a);return}}else n.isExternalTexture&&(o.__webglTexture=n.sourceTexture?n.sourceTexture:null);r.bindTexture(t.TEXTURE_2D,o.__webglTexture,t.TEXTURE0+a)}function te(e,n){let a=i.get(e);if(e.isRenderTargetTexture===!1&&e.version>0&&a.__version!==e.version){I(a,e,n);return}else e.isExternalTexture&&(a.__webglTexture=e.sourceTexture?e.sourceTexture:null);r.bindTexture(t.TEXTURE_2D_ARRAY,a.__webglTexture,t.TEXTURE0+n)}function ne(e,n){let a=i.get(e);if(e.isRenderTargetTexture===!1&&e.version>0&&a.__version!==e.version){I(a,e,n);return}r.bindTexture(t.TEXTURE_3D,a.__webglTexture,t.TEXTURE0+n)}function re(e,n){let a=i.get(e);if(e.isCubeDepthTexture!==!0&&e.version>0&&a.__version!==e.version){ue(a,e,n);return}r.bindTexture(t.TEXTURE_CUBE_MAP,a.__webglTexture,t.TEXTURE0+n)}let ie={[e.Ut]:t.REPEAT,[e.l]:t.CLAMP_TO_EDGE,[e.K]:t.MIRRORED_REPEAT},ae={[e.q]:t.NEAREST,[e.Y]:t.NEAREST_MIPMAP_NEAREST,[e.J]:t.NEAREST_MIPMAP_LINEAR,[e.N]:t.LINEAR,[e.F]:t.LINEAR_MIPMAP_NEAREST,[e.P]:t.LINEAR_MIPMAP_LINEAR},oe={512:t.NEVER,519:t.ALWAYS,513:t.LESS,515:t.LEQUAL,514:t.EQUAL,518:t.GEQUAL,516:t.GREATER,517:t.NOTEQUAL};function se(r,o){if(o.type===1015&&n.has(`OES_texture_float_linear`)===!1&&(o.magFilter===1006||o.magFilter===1007||o.magFilter===1005||o.magFilter===1008||o.minFilter===1006||o.minFilter===1007||o.minFilter===1005||o.minFilter===1008)&&e.kn(`WebGLRenderer: Unable to use linear filtering with floating point textures. OES_texture_float_linear not supported on this device.`),t.texParameteri(r,t.TEXTURE_WRAP_S,ie[o.wrapS]),t.texParameteri(r,t.TEXTURE_WRAP_T,ie[o.wrapT]),(r===t.TEXTURE_3D||r===t.TEXTURE_2D_ARRAY)&&t.texParameteri(r,t.TEXTURE_WRAP_R,ie[o.wrapR]),t.texParameteri(r,t.TEXTURE_MAG_FILTER,ae[o.magFilter]),t.texParameteri(r,t.TEXTURE_MIN_FILTER,ae[o.minFilter]),o.compareFunction&&(t.texParameteri(r,t.TEXTURE_COMPARE_MODE,t.COMPARE_REF_TO_TEXTURE),t.texParameteri(r,t.TEXTURE_COMPARE_FUNC,oe[o.compareFunction])),n.has(`EXT_texture_filter_anisotropic`)===!0){if(o.magFilter===1003||o.minFilter!==1005&&o.minFilter!==1008||o.type===1015&&n.has(`OES_texture_float_linear`)===!1)return;if(o.anisotropy>1||i.get(o).__currentAnisotropy){let e=n.get(`EXT_texture_filter_anisotropic`);t.texParameterf(r,e.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(o.anisotropy,a.getMaxAnisotropy())),i.get(o).__currentAnisotropy=o.anisotropy}}}function ce(e,n){let r=!1;e.__webglInit===void 0&&(e.__webglInit=!0,n.addEventListener(`dispose`,w));let i=n.source,a=m.get(i);a===void 0&&(a={},m.set(i,a));let o=ee(n);if(o!==e.__cacheKey){a[o]===void 0&&(a[o]={texture:t.createTexture(),usedTimes:0},s.memory.textures++,r=!0),a[o].usedTimes++;let i=a[e.__cacheKey];i!==void 0&&(a[e.__cacheKey].usedTimes--,i.usedTimes===0&&D(n)),e.__cacheKey=o,e.__webglTexture=a[o].texture}return r}function le(e,t,n){return Math.floor(Math.floor(e/n)/t)}function F(e,n,i,a){let o=e.updateRanges;if(o.length===0)r.texSubImage2D(t.TEXTURE_2D,0,0,0,n.width,n.height,i,a,n.data);else{o.sort((e,t)=>e.start-t.start);let s=0;for(let e=1;e<o.length;e++){let t=o[s],r=o[e],i=t.start+t.count,a=le(r.start,n.width,4),c=le(t.start,n.width,4);r.start<=i+1&&a===c&&le(r.start+r.count-1,n.width,4)===a?t.count=Math.max(t.count,r.start+r.count-t.start):(++s,o[s]=r)}o.length=s+1;let c=r.getParameter(t.UNPACK_ROW_LENGTH),l=r.getParameter(t.UNPACK_SKIP_PIXELS),u=r.getParameter(t.UNPACK_SKIP_ROWS);r.pixelStorei(t.UNPACK_ROW_LENGTH,n.width);for(let e=0,s=o.length;e<s;e++){let s=o[e],c=Math.floor(s.start/4),l=Math.ceil(s.count/4),u=c%n.width,d=Math.floor(c/n.width),f=l;r.pixelStorei(t.UNPACK_SKIP_PIXELS,u),r.pixelStorei(t.UNPACK_SKIP_ROWS,d),r.texSubImage2D(t.TEXTURE_2D,0,u,d,f,1,i,a,n.data)}e.clearUpdateRanges(),r.pixelStorei(t.UNPACK_ROW_LENGTH,c),r.pixelStorei(t.UNPACK_SKIP_PIXELS,l),r.pixelStorei(t.UNPACK_SKIP_ROWS,u)}}function I(n,s,c){let l=t.TEXTURE_2D;(s.isDataArrayTexture||s.isCompressedArrayTexture)&&(l=t.TEXTURE_2D_ARRAY),s.isData3DTexture&&(l=t.TEXTURE_3D);let u=ce(n,s),d=s.source;r.bindTexture(l,n.__webglTexture,t.TEXTURE0+c);let p=i.get(d);if(d.version!==p.__version||u===!0){if(r.activeTexture(t.TEXTURE0+c),!(typeof ImageBitmap<`u`&&s.image instanceof ImageBitmap)){let n=e.d.getPrimaries(e.d.workingColorSpace),i=s.colorSpace===``?null:e.d.getPrimaries(s.colorSpace),a=s.colorSpace===``||n===i?t.NONE:t.BROWSER_DEFAULT_WEBGL;r.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,s.flipY),r.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,s.premultiplyAlpha),r.pixelStorei(t.UNPACK_COLORSPACE_CONVERSION_WEBGL,a)}r.pixelStorei(t.UNPACK_ALIGNMENT,s.unpackAlignment);let n=_(s.image,!1,a.maxTextureSize);n=ge(s,n);let i=o.convert(s.format,s.colorSpace),m=o.convert(s.type),h=x(s.internalFormat,i,m,s.normalized,s.colorSpace,s.isVideoTexture);se(l,s);let g,b=s.mipmaps,w=s.isVideoTexture!==!0,T=p.__version===void 0||u===!0,E=d.dataReady,D=C(s,n);if(s.isDepthTexture)h=S(s.format===e.b,s.type),T&&(w?r.texStorage2D(t.TEXTURE_2D,1,h,n.width,n.height):r.texImage2D(t.TEXTURE_2D,0,h,n.width,n.height,0,i,m,null));else if(s.isDataTexture)if(b.length>0){w&&T&&r.texStorage2D(t.TEXTURE_2D,D,h,b[0].width,b[0].height);for(let e=0,n=b.length;e<n;e++)g=b[e],w?E&&r.texSubImage2D(t.TEXTURE_2D,e,0,0,g.width,g.height,i,m,g.data):r.texImage2D(t.TEXTURE_2D,e,h,g.width,g.height,0,i,m,g.data);s.generateMipmaps=!1}else w?(T&&r.texStorage2D(t.TEXTURE_2D,D,h,n.width,n.height),E&&F(s,n,i,m)):r.texImage2D(t.TEXTURE_2D,0,h,n.width,n.height,0,i,m,n.data);else if(s.isCompressedTexture)if(s.isCompressedArrayTexture){w&&T&&r.texStorage3D(t.TEXTURE_2D_ARRAY,D,h,b[0].width,b[0].height,n.depth);for(let a=0,o=b.length;a<o;a++)if(g=b[a],s.format!==1023)if(i!==null)if(w){if(E)if(s.layerUpdates.size>0){let n=e.wn(g.width,g.height,s.format,s.type);for(let e of s.layerUpdates){let o=g.data.subarray(e*n/g.data.BYTES_PER_ELEMENT,(e+1)*n/g.data.BYTES_PER_ELEMENT);r.compressedTexSubImage3D(t.TEXTURE_2D_ARRAY,a,0,0,e,g.width,g.height,1,i,o)}s.clearLayerUpdates()}else r.compressedTexSubImage3D(t.TEXTURE_2D_ARRAY,a,0,0,0,g.width,g.height,n.depth,i,g.data)}else r.compressedTexImage3D(t.TEXTURE_2D_ARRAY,a,h,g.width,g.height,n.depth,0,g.data,0,0);else e.kn(`WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()`);else w?E&&r.texSubImage3D(t.TEXTURE_2D_ARRAY,a,0,0,0,g.width,g.height,n.depth,i,m,g.data):r.texImage3D(t.TEXTURE_2D_ARRAY,a,h,g.width,g.height,n.depth,0,i,m,g.data)}else{w&&T&&r.texStorage2D(t.TEXTURE_2D,D,h,b[0].width,b[0].height);for(let n=0,a=b.length;n<a;n++)g=b[n],s.format===1023?w?E&&r.texSubImage2D(t.TEXTURE_2D,n,0,0,g.width,g.height,i,m,g.data):r.texImage2D(t.TEXTURE_2D,n,h,g.width,g.height,0,i,m,g.data):i===null?e.kn(`WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()`):w?E&&r.compressedTexSubImage2D(t.TEXTURE_2D,n,0,0,g.width,g.height,i,g.data):r.compressedTexImage2D(t.TEXTURE_2D,n,h,g.width,g.height,0,g.data)}else if(s.isDataArrayTexture)if(w){if(T&&r.texStorage3D(t.TEXTURE_2D_ARRAY,D,h,n.width,n.height,n.depth),E)if(s.layerUpdates.size>0){let a=e.wn(n.width,n.height,s.format,s.type);for(let e of s.layerUpdates){let o=n.data.subarray(e*a/n.data.BYTES_PER_ELEMENT,(e+1)*a/n.data.BYTES_PER_ELEMENT);r.texSubImage3D(t.TEXTURE_2D_ARRAY,0,0,0,e,n.width,n.height,1,i,m,o)}s.clearLayerUpdates()}else r.texSubImage3D(t.TEXTURE_2D_ARRAY,0,0,0,0,n.width,n.height,n.depth,i,m,n.data)}else r.texImage3D(t.TEXTURE_2D_ARRAY,0,h,n.width,n.height,n.depth,0,i,m,n.data);else if(s.isData3DTexture)w?(T&&r.texStorage3D(t.TEXTURE_3D,D,h,n.width,n.height,n.depth),E&&r.texSubImage3D(t.TEXTURE_3D,0,0,0,0,n.width,n.height,n.depth,i,m,n.data)):r.texImage3D(t.TEXTURE_3D,0,h,n.width,n.height,n.depth,0,i,m,n.data);else if(s.isFramebufferTexture){if(T)if(w)r.texStorage2D(t.TEXTURE_2D,D,h,n.width,n.height);else{let e=n.width,a=n.height;for(let n=0;n<D;n++)r.texImage2D(t.TEXTURE_2D,n,h,e,a,0,i,m,null),e>>=1,a>>=1}}else if(s.isHTMLTexture){if(`texElementImage2D`in t){let e=t.canvas;if(e.hasAttribute(`layoutsubtree`)||e.setAttribute(`layoutsubtree`,`true`),n.parentNode!==e){e.appendChild(n),f.add(s),e.onpaint=e=>{let t=e.changedElements;for(let e of f)t.includes(e.image)&&(e.needsUpdate=!0)},e.requestPaint();return}if(t.texElementImage2D.length===3)t.texElementImage2D(t.TEXTURE_2D,t.RGBA8,n);else{let e=t.RGBA,r=t.RGBA,i=t.UNSIGNED_BYTE;t.texElementImage2D(t.TEXTURE_2D,0,e,r,i,n)}t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE)}}else if(b.length>0){if(w&&T){let e=_e(b[0]);r.texStorage2D(t.TEXTURE_2D,D,h,e.width,e.height)}for(let e=0,n=b.length;e<n;e++)g=b[e],w?E&&r.texSubImage2D(t.TEXTURE_2D,e,0,0,i,m,g):r.texImage2D(t.TEXTURE_2D,e,h,i,m,g);s.generateMipmaps=!1}else if(w){if(T){let e=_e(n);r.texStorage2D(t.TEXTURE_2D,D,h,e.width,e.height)}E&&r.texSubImage2D(t.TEXTURE_2D,0,0,0,i,m,n)}else r.texImage2D(t.TEXTURE_2D,0,h,i,m,n);v(s)&&y(l),p.__version=d.version,s.onUpdate&&s.onUpdate(s)}n.__version=s.version}function ue(n,s,c){if(s.image.length!==6)return;let l=ce(n,s),u=s.source;r.bindTexture(t.TEXTURE_CUBE_MAP,n.__webglTexture,t.TEXTURE0+c);let d=i.get(u);if(u.version!==d.__version||l===!0){r.activeTexture(t.TEXTURE0+c);let n=e.d.getPrimaries(e.d.workingColorSpace),i=s.colorSpace===``?null:e.d.getPrimaries(s.colorSpace),f=s.colorSpace===``||n===i?t.NONE:t.BROWSER_DEFAULT_WEBGL;r.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,s.flipY),r.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,s.premultiplyAlpha),r.pixelStorei(t.UNPACK_ALIGNMENT,s.unpackAlignment),r.pixelStorei(t.UNPACK_COLORSPACE_CONVERSION_WEBGL,f);let p=s.isCompressedTexture||s.image[0].isCompressedTexture,m=s.image[0]&&s.image[0].isDataTexture,h=[];for(let e=0;e<6;e++)!p&&!m?h[e]=_(s.image[e],!0,a.maxCubemapSize):h[e]=m?s.image[e].image:s.image[e],h[e]=ge(s,h[e]);let g=h[0],b=o.convert(s.format,s.colorSpace),S=o.convert(s.type),w=x(s.internalFormat,b,S,s.normalized,s.colorSpace),T=s.isVideoTexture!==!0,E=d.__version===void 0||l===!0,D=u.dataReady,O=C(s,g);se(t.TEXTURE_CUBE_MAP,s);let k;if(p){T&&E&&r.texStorage2D(t.TEXTURE_CUBE_MAP,O,w,g.width,g.height);for(let n=0;n<6;n++){k=h[n].mipmaps;for(let i=0;i<k.length;i++){let a=k[i];s.format===1023?T?D&&r.texSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+n,i,0,0,a.width,a.height,b,S,a.data):r.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+n,i,w,a.width,a.height,0,b,S,a.data):b===null?e.kn(`WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()`):T?D&&r.compressedTexSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+n,i,0,0,a.width,a.height,b,a.data):r.compressedTexImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+n,i,w,a.width,a.height,0,a.data)}}}else{if(k=s.mipmaps,T&&E){k.length>0&&O++;let e=_e(h[0]);r.texStorage2D(t.TEXTURE_CUBE_MAP,O,w,e.width,e.height)}for(let e=0;e<6;e++)if(m){T?D&&r.texSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,0,0,h[e].width,h[e].height,b,S,h[e].data):r.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,w,h[e].width,h[e].height,0,b,S,h[e].data);for(let n=0;n<k.length;n++){let i=k[n].image[e].image;T?D&&r.texSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,n+1,0,0,i.width,i.height,b,S,i.data):r.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,n+1,w,i.width,i.height,0,b,S,i.data)}}else{T?D&&r.texSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,0,0,b,S,h[e]):r.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,w,b,S,h[e]);for(let n=0;n<k.length;n++){let i=k[n];T?D&&r.texSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,n+1,0,0,b,S,i.image[e]):r.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,n+1,w,b,S,i.image[e])}}}v(s)&&y(t.TEXTURE_CUBE_MAP),d.__version=u.version,s.onUpdate&&s.onUpdate(s)}n.__version=s.version}function L(e,n,a,s,l,u){let d=o.convert(a.format,a.colorSpace),f=o.convert(a.type),p=x(a.internalFormat,d,f,a.normalized,a.colorSpace),m=i.get(n),h=i.get(a);if(h.__renderTarget=n,!m.__hasExternalTextures){let e=Math.max(1,n.width>>u),i=Math.max(1,n.height>>u);l===t.TEXTURE_3D||l===t.TEXTURE_2D_ARRAY?r.texImage3D(l,u,p,e,i,n.depth,0,d,f,null):r.texImage2D(l,u,p,e,i,0,d,f,null)}r.bindFramebuffer(t.FRAMEBUFFER,e),W(n)?c.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,s,l,h.__webglTexture,0,U(n)):(l===t.TEXTURE_2D||l>=t.TEXTURE_CUBE_MAP_POSITIVE_X&&l<=t.TEXTURE_CUBE_MAP_NEGATIVE_Z)&&t.framebufferTexture2D(t.FRAMEBUFFER,s,l,h.__webglTexture,u),r.bindFramebuffer(t.FRAMEBUFFER,null)}function R(e,n,r){if(t.bindRenderbuffer(t.RENDERBUFFER,e),n.depthBuffer){let i=n.depthTexture,a=i&&i.isDepthTexture?i.type:null,o=S(n.stencilBuffer,a),s=n.stencilBuffer?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;W(n)?c.renderbufferStorageMultisampleEXT(t.RENDERBUFFER,U(n),o,n.width,n.height):r?t.renderbufferStorageMultisample(t.RENDERBUFFER,U(n),o,n.width,n.height):t.renderbufferStorage(t.RENDERBUFFER,o,n.width,n.height),t.framebufferRenderbuffer(t.FRAMEBUFFER,s,t.RENDERBUFFER,e)}else{let e=n.textures;for(let i=0;i<e.length;i++){let a=e[i],s=o.convert(a.format,a.colorSpace),l=o.convert(a.type),u=x(a.internalFormat,s,l,a.normalized,a.colorSpace);W(n)?c.renderbufferStorageMultisampleEXT(t.RENDERBUFFER,U(n),u,n.width,n.height):r?t.renderbufferStorageMultisample(t.RENDERBUFFER,U(n),u,n.width,n.height):t.renderbufferStorage(t.RENDERBUFFER,u,n.width,n.height)}}t.bindRenderbuffer(t.RENDERBUFFER,null)}function de(e,n,a){let s=n.isWebGLCubeRenderTarget===!0;if(r.bindFramebuffer(t.FRAMEBUFFER,e),!(n.depthTexture&&n.depthTexture.isDepthTexture))throw Error(`THREE.WebGLTextures: renderTarget.depthTexture must be an instance of THREE.DepthTexture.`);let l=i.get(n.depthTexture);if(l.__renderTarget=n,(!l.__webglTexture||n.depthTexture.image.width!==n.width||n.depthTexture.image.height!==n.height)&&(n.depthTexture.image.width=n.width,n.depthTexture.image.height=n.height,n.depthTexture.needsUpdate=!0),s){if(l.__webglInit===void 0&&(l.__webglInit=!0,n.depthTexture.addEventListener(`dispose`,w)),l.__webglTexture===void 0){l.__webglTexture=t.createTexture(),r.bindTexture(t.TEXTURE_CUBE_MAP,l.__webglTexture),se(t.TEXTURE_CUBE_MAP,n.depthTexture);let e=o.convert(n.depthTexture.format),i=o.convert(n.depthTexture.type),a;n.depthTexture.format===1026?a=t.DEPTH_COMPONENT24:n.depthTexture.format===1027&&(a=t.DEPTH24_STENCIL8);for(let r=0;r<6;r++)t.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+r,0,a,n.width,n.height,0,e,i,null)}}else P(n.depthTexture,0);let u=l.__webglTexture,d=U(n),f=s?t.TEXTURE_CUBE_MAP_POSITIVE_X+a:t.TEXTURE_2D,p=n.depthTexture.format===1027?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;if(n.depthTexture.format===1026)W(n)?c.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,p,f,u,0,d):t.framebufferTexture2D(t.FRAMEBUFFER,p,f,u,0);else if(n.depthTexture.format===1027)W(n)?c.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,p,f,u,0,d):t.framebufferTexture2D(t.FRAMEBUFFER,p,f,u,0);else throw Error(`THREE.WebGLTextures: Unknown depthTexture format.`)}function z(e){let n=i.get(e),a=e.isWebGLCubeRenderTarget===!0;if(n.__boundDepthTexture!==e.depthTexture){let t=e.depthTexture;if(n.__depthDisposeCallback&&n.__depthDisposeCallback(),t){let e=()=>{delete n.__boundDepthTexture,delete n.__depthDisposeCallback,t.removeEventListener(`dispose`,e)};t.addEventListener(`dispose`,e),n.__depthDisposeCallback=e}n.__boundDepthTexture=t}if(e.depthTexture&&!n.__autoAllocateDepthBuffer)if(a)for(let t=0;t<6;t++)de(n.__webglFramebuffer[t],e,t);else{let t=e.texture.mipmaps;t&&t.length>0?de(n.__webglFramebuffer[0],e,0):de(n.__webglFramebuffer,e,0)}else if(a){n.__webglDepthbuffer=[];for(let i=0;i<6;i++)if(r.bindFramebuffer(t.FRAMEBUFFER,n.__webglFramebuffer[i]),n.__webglDepthbuffer[i]===void 0)n.__webglDepthbuffer[i]=t.createRenderbuffer(),R(n.__webglDepthbuffer[i],e,!1);else{let r=e.stencilBuffer?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT,a=n.__webglDepthbuffer[i];t.bindRenderbuffer(t.RENDERBUFFER,a),t.framebufferRenderbuffer(t.FRAMEBUFFER,r,t.RENDERBUFFER,a)}}else{let i=e.texture.mipmaps;if(i&&i.length>0?r.bindFramebuffer(t.FRAMEBUFFER,n.__webglFramebuffer[0]):r.bindFramebuffer(t.FRAMEBUFFER,n.__webglFramebuffer),n.__webglDepthbuffer===void 0)n.__webglDepthbuffer=t.createRenderbuffer(),R(n.__webglDepthbuffer,e,!1);else{let r=e.stencilBuffer?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT,i=n.__webglDepthbuffer;t.bindRenderbuffer(t.RENDERBUFFER,i),t.framebufferRenderbuffer(t.FRAMEBUFFER,r,t.RENDERBUFFER,i)}}r.bindFramebuffer(t.FRAMEBUFFER,null)}function B(e,n,r){let a=i.get(e);n!==void 0&&L(a.__webglFramebuffer,e,e.texture,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,0),r!==void 0&&z(e)}function fe(e){let n=e.texture,a=i.get(e),c=i.get(n);e.addEventListener(`dispose`,T);let l=e.textures,u=e.isWebGLCubeRenderTarget===!0,d=l.length>1;if(d||(c.__webglTexture===void 0&&(c.__webglTexture=t.createTexture()),c.__version=n.version,s.memory.textures++),u){a.__webglFramebuffer=[];for(let e=0;e<6;e++)if(n.mipmaps&&n.mipmaps.length>0){a.__webglFramebuffer[e]=[];for(let r=0;r<n.mipmaps.length;r++)a.__webglFramebuffer[e][r]=t.createFramebuffer()}else a.__webglFramebuffer[e]=t.createFramebuffer()}else{if(n.mipmaps&&n.mipmaps.length>0){a.__webglFramebuffer=[];for(let e=0;e<n.mipmaps.length;e++)a.__webglFramebuffer[e]=t.createFramebuffer()}else a.__webglFramebuffer=t.createFramebuffer();if(d)for(let e=0,n=l.length;e<n;e++){let n=i.get(l[e]);n.__webglTexture===void 0&&(n.__webglTexture=t.createTexture(),s.memory.textures++)}if(e.samples>0&&W(e)===!1){a.__webglMultisampledFramebuffer=t.createFramebuffer(),a.__webglColorRenderbuffer=[],r.bindFramebuffer(t.FRAMEBUFFER,a.__webglMultisampledFramebuffer);for(let n=0;n<l.length;n++){let r=l[n];a.__webglColorRenderbuffer[n]=t.createRenderbuffer(),t.bindRenderbuffer(t.RENDERBUFFER,a.__webglColorRenderbuffer[n]);let i=o.convert(r.format,r.colorSpace),s=o.convert(r.type),c=x(r.internalFormat,i,s,r.normalized,r.colorSpace,e.isXRRenderTarget===!0),u=U(e);t.renderbufferStorageMultisample(t.RENDERBUFFER,u,c,e.width,e.height),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0+n,t.RENDERBUFFER,a.__webglColorRenderbuffer[n])}t.bindRenderbuffer(t.RENDERBUFFER,null),e.depthBuffer&&(a.__webglDepthRenderbuffer=t.createRenderbuffer(),R(a.__webglDepthRenderbuffer,e,!0)),r.bindFramebuffer(t.FRAMEBUFFER,null)}}if(u){r.bindTexture(t.TEXTURE_CUBE_MAP,c.__webglTexture),se(t.TEXTURE_CUBE_MAP,n);for(let r=0;r<6;r++)if(n.mipmaps&&n.mipmaps.length>0)for(let i=0;i<n.mipmaps.length;i++)L(a.__webglFramebuffer[r][i],e,n,t.COLOR_ATTACHMENT0,t.TEXTURE_CUBE_MAP_POSITIVE_X+r,i);else L(a.__webglFramebuffer[r],e,n,t.COLOR_ATTACHMENT0,t.TEXTURE_CUBE_MAP_POSITIVE_X+r,0);v(n)&&y(t.TEXTURE_CUBE_MAP),r.unbindTexture()}else if(d){for(let n=0,o=l.length;n<o;n++){let o=l[n],s=i.get(o),c=t.TEXTURE_2D;(e.isWebGL3DRenderTarget||e.isWebGLArrayRenderTarget)&&(c=e.isWebGL3DRenderTarget?t.TEXTURE_3D:t.TEXTURE_2D_ARRAY),r.bindTexture(c,s.__webglTexture),se(c,o),L(a.__webglFramebuffer,e,o,t.COLOR_ATTACHMENT0+n,c,0),v(o)&&y(c)}r.unbindTexture()}else{let i=t.TEXTURE_2D;if((e.isWebGL3DRenderTarget||e.isWebGLArrayRenderTarget)&&(i=e.isWebGL3DRenderTarget?t.TEXTURE_3D:t.TEXTURE_2D_ARRAY),r.bindTexture(i,c.__webglTexture),se(i,n),n.mipmaps&&n.mipmaps.length>0)for(let r=0;r<n.mipmaps.length;r++)L(a.__webglFramebuffer[r],e,n,t.COLOR_ATTACHMENT0,i,r);else L(a.__webglFramebuffer,e,n,t.COLOR_ATTACHMENT0,i,0);v(n)&&y(i),r.unbindTexture()}e.depthBuffer&&z(e)}function pe(e){let t=e.textures;for(let n=0,a=t.length;n<a;n++){let a=t[n];if(v(a)){let t=b(e),n=i.get(a).__webglTexture;r.bindTexture(t,n),y(t),r.unbindTexture()}}}let me=[],V=[];function H(e){if(e.samples>0){if(W(e)===!1){let n=e.textures,a=e.width,o=e.height,s=t.COLOR_BUFFER_BIT,c=e.stencilBuffer?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT,u=i.get(e),d=n.length>1;if(d)for(let e=0;e<n.length;e++)r.bindFramebuffer(t.FRAMEBUFFER,u.__webglMultisampledFramebuffer),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0+e,t.RENDERBUFFER,null),r.bindFramebuffer(t.FRAMEBUFFER,u.__webglFramebuffer),t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0+e,t.TEXTURE_2D,null,0);r.bindFramebuffer(t.READ_FRAMEBUFFER,u.__webglMultisampledFramebuffer);let f=e.texture.mipmaps;f&&f.length>0?r.bindFramebuffer(t.DRAW_FRAMEBUFFER,u.__webglFramebuffer[0]):r.bindFramebuffer(t.DRAW_FRAMEBUFFER,u.__webglFramebuffer);for(let r=0;r<n.length;r++){if(e.resolveDepthBuffer&&(e.depthBuffer&&(s|=t.DEPTH_BUFFER_BIT),e.stencilBuffer&&e.resolveStencilBuffer&&(s|=t.STENCIL_BUFFER_BIT)),d){t.framebufferRenderbuffer(t.READ_FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.RENDERBUFFER,u.__webglColorRenderbuffer[r]);let e=i.get(n[r]).__webglTexture;t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,e,0)}t.blitFramebuffer(0,0,a,o,0,0,a,o,s,t.NEAREST),l===!0&&(me.length=0,V.length=0,me.push(t.COLOR_ATTACHMENT0+r),e.depthBuffer&&e.resolveDepthBuffer===!1&&(me.push(c),V.push(c),t.invalidateFramebuffer(t.DRAW_FRAMEBUFFER,V)),t.invalidateFramebuffer(t.READ_FRAMEBUFFER,me))}if(r.bindFramebuffer(t.READ_FRAMEBUFFER,null),r.bindFramebuffer(t.DRAW_FRAMEBUFFER,null),d)for(let e=0;e<n.length;e++){r.bindFramebuffer(t.FRAMEBUFFER,u.__webglMultisampledFramebuffer),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0+e,t.RENDERBUFFER,u.__webglColorRenderbuffer[e]);let a=i.get(n[e]).__webglTexture;r.bindFramebuffer(t.FRAMEBUFFER,u.__webglFramebuffer),t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0+e,t.TEXTURE_2D,a,0)}r.bindFramebuffer(t.DRAW_FRAMEBUFFER,u.__webglMultisampledFramebuffer)}else if(e.depthBuffer&&e.resolveDepthBuffer===!1&&l){let n=e.stencilBuffer?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;t.invalidateFramebuffer(t.DRAW_FRAMEBUFFER,[n])}}}function U(e){return Math.min(a.maxSamples,e.samples)}function W(e){let t=i.get(e);return e.samples>0&&n.has(`WEBGL_multisampled_render_to_texture`)===!0&&t.__useRenderToTexture!==!1}function he(e){let t=s.render.frame;d.get(e)!==t&&(d.set(e,t),e.update())}function ge(t,n){let r=t.colorSpace,i=t.format,a=t.type;return t.isCompressedTexture===!0||t.isVideoTexture===!0||r!==`srgb-linear`&&r!==``&&(e.d.getTransfer(r)===`srgb`?(i!==1023||a!==1009)&&e.kn(`WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType.`):e.Cn(`WebGLTextures: Unsupported texture color space:`,r)),n}function _e(e){return typeof HTMLImageElement<`u`&&e instanceof HTMLImageElement?(u.width=e.naturalWidth||e.width,u.height=e.naturalHeight||e.height):typeof VideoFrame<`u`&&e instanceof VideoFrame?(u.width=e.displayWidth,u.height=e.displayHeight):(u.width=e.width,u.height=e.height),u}this.allocateTextureUnit=N,this.resetTextureUnits=A,this.getTextureUnits=j,this.setTextureUnits=M,this.setTexture2D=P,this.setTexture2DArray=te,this.setTexture3D=ne,this.setTextureCube=re,this.rebindTextures=B,this.setupRenderTarget=fe,this.updateRenderTargetMipmap=pe,this.updateMultisampleRenderTarget=H,this.setupDepthRenderbuffer=z,this.setupFrameBufferTexture=L,this.useMultisampledRTT=W,this.isReversedDepthBuffer=function(){return r.buffers.depth.getReversed()}}function un(t,n){function r(r,i=``){let a,o=e.d.getTransfer(i);if(r===1009)return t.UNSIGNED_BYTE;if(r===1017)return t.UNSIGNED_SHORT_4_4_4_4;if(r===1018)return t.UNSIGNED_SHORT_5_5_5_1;if(r===35902)return t.UNSIGNED_INT_5_9_9_9_REV;if(r===35899)return t.UNSIGNED_INT_10F_11F_11F_REV;if(r===1010)return t.BYTE;if(r===1011)return t.SHORT;if(r===1012)return t.UNSIGNED_SHORT;if(r===1013)return t.INT;if(r===1014)return t.UNSIGNED_INT;if(r===1015)return t.FLOAT;if(r===1016)return t.HALF_FLOAT;if(r===1021)return t.ALPHA;if(r===1022)return t.RGB;if(r===1023)return t.RGBA;if(r===1026)return t.DEPTH_COMPONENT;if(r===1027)return t.DEPTH_STENCIL;if(r===1028)return t.RED;if(r===1029)return t.RED_INTEGER;if(r===1030)return t.RG;if(r===1031)return t.RG_INTEGER;if(r===1033)return t.RGBA_INTEGER;if(r===33776||r===33777||r===33778||r===33779)if(o===`srgb`)if(a=n.get(`WEBGL_compressed_texture_s3tc_srgb`),a!==null){if(r===33776)return a.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(r===33777)return a.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(r===33778)return a.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(r===33779)return a.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else return null;else if(a=n.get(`WEBGL_compressed_texture_s3tc`),a!==null){if(r===33776)return a.COMPRESSED_RGB_S3TC_DXT1_EXT;if(r===33777)return a.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(r===33778)return a.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(r===33779)return a.COMPRESSED_RGBA_S3TC_DXT5_EXT}else return null;if(r===35840||r===35841||r===35842||r===35843)if(a=n.get(`WEBGL_compressed_texture_pvrtc`),a!==null){if(r===35840)return a.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(r===35841)return a.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(r===35842)return a.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(r===35843)return a.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}else return null;if(r===36196||r===37492||r===37496||r===37488||r===37489||r===37490||r===37491)if(a=n.get(`WEBGL_compressed_texture_etc`),a!==null){if(r===36196||r===37492)return o===`srgb`?a.COMPRESSED_SRGB8_ETC2:a.COMPRESSED_RGB8_ETC2;if(r===37496)return o===`srgb`?a.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:a.COMPRESSED_RGBA8_ETC2_EAC;if(r===37488)return a.COMPRESSED_R11_EAC;if(r===37489)return a.COMPRESSED_SIGNED_R11_EAC;if(r===37490)return a.COMPRESSED_RG11_EAC;if(r===37491)return a.COMPRESSED_SIGNED_RG11_EAC}else return null;if(r===37808||r===37809||r===37810||r===37811||r===37812||r===37813||r===37814||r===37815||r===37816||r===37817||r===37818||r===37819||r===37820||r===37821)if(a=n.get(`WEBGL_compressed_texture_astc`),a!==null){if(r===37808)return o===`srgb`?a.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:a.COMPRESSED_RGBA_ASTC_4x4_KHR;if(r===37809)return o===`srgb`?a.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:a.COMPRESSED_RGBA_ASTC_5x4_KHR;if(r===37810)return o===`srgb`?a.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:a.COMPRESSED_RGBA_ASTC_5x5_KHR;if(r===37811)return o===`srgb`?a.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:a.COMPRESSED_RGBA_ASTC_6x5_KHR;if(r===37812)return o===`srgb`?a.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:a.COMPRESSED_RGBA_ASTC_6x6_KHR;if(r===37813)return o===`srgb`?a.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:a.COMPRESSED_RGBA_ASTC_8x5_KHR;if(r===37814)return o===`srgb`?a.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:a.COMPRESSED_RGBA_ASTC_8x6_KHR;if(r===37815)return o===`srgb`?a.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:a.COMPRESSED_RGBA_ASTC_8x8_KHR;if(r===37816)return o===`srgb`?a.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:a.COMPRESSED_RGBA_ASTC_10x5_KHR;if(r===37817)return o===`srgb`?a.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:a.COMPRESSED_RGBA_ASTC_10x6_KHR;if(r===37818)return o===`srgb`?a.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:a.COMPRESSED_RGBA_ASTC_10x8_KHR;if(r===37819)return o===`srgb`?a.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:a.COMPRESSED_RGBA_ASTC_10x10_KHR;if(r===37820)return o===`srgb`?a.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:a.COMPRESSED_RGBA_ASTC_12x10_KHR;if(r===37821)return o===`srgb`?a.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:a.COMPRESSED_RGBA_ASTC_12x12_KHR}else return null;if(r===36492||r===36494||r===36495)if(a=n.get(`EXT_texture_compression_bptc`),a!==null){if(r===36492)return o===`srgb`?a.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:a.COMPRESSED_RGBA_BPTC_UNORM_EXT;if(r===36494)return a.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;if(r===36495)return a.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT}else return null;if(r===36283||r===36284||r===36285||r===36286)if(a=n.get(`EXT_texture_compression_rgtc`),a!==null){if(r===36283)return a.COMPRESSED_RED_RGTC1_EXT;if(r===36284)return a.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(r===36285)return a.COMPRESSED_RED_GREEN_RGTC2_EXT;if(r===36286)return a.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}else return null;return r===1020?t.UNSIGNED_INT_24_8:t[r]===void 0?null:t[r]}return{convert:r}}var dn=`
4081
+ void main() {
4082
+
4083
+ gl_Position = vec4( position, 1.0 );
4084
+
4085
+ }`,fn=`
4086
+ uniform sampler2DArray depthColor;
4087
+ uniform float depthWidth;
4088
+ uniform float depthHeight;
4089
+
4090
+ void main() {
4091
+
4092
+ vec2 coord = vec2( gl_FragCoord.x / depthWidth, gl_FragCoord.y / depthHeight );
4093
+
4094
+ if ( coord.x >= 1.0 ) {
4095
+
4096
+ gl_FragDepth = texture( depthColor, vec3( coord.x - 1.0, coord.y, 1 ) ).r;
4097
+
4098
+ } else {
4099
+
4100
+ gl_FragDepth = texture( depthColor, vec3( coord.x, coord.y, 0 ) ).r;
4101
+
4102
+ }
4103
+
4104
+ }`,pn=class{constructor(){this.texture=null,this.mesh=null,this.depthNear=0,this.depthFar=0}init(t,n){if(this.texture===null){let r=new e.w(t.texture);(t.depthNear!==n.depthNear||t.depthFar!==n.depthFar)&&(this.depthNear=t.depthNear,this.depthFar=t.depthFar),this.texture=r}}getMesh(t){if(this.texture!==null&&this.mesh===null){let n=t.cameras[0].viewport,r=new e.Qt({vertexShader:dn,fragmentShader:fn,uniforms:{depthColor:{value:this.texture},depthWidth:{value:n.z},depthHeight:{value:n.w}}});this.mesh=new e.H(new e.$(20,20),r)}return this.mesh}reset(){this.texture=null,this.mesh=null}getDepthTexture(){return this.texture}},mn=class extends e.C{constructor(t,r){super();let i=this,a=null,o=1,s=null,c=`local-floor`,l=1,u=null,d=null,f=null,p=null,m=null,h=null,g=typeof XRWebGLBinding<`u`,_=new pn,v={},y=r.getContextAttributes(),b=null,x=null,S=[],C=[],w=new e.mn,T=null,E=new e.Z;E.viewport=new e.gn;let D=new e.Z;D.viewport=new e.gn;let O=[E,D],k=new e.i,A=null,j=null;this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function(t){let n=S[t];return n===void 0&&(n=new e.yn,S[t]=n),n.getTargetRaySpace()},this.getControllerGrip=function(t){let n=S[t];return n===void 0&&(n=new e.yn,S[t]=n),n.getGripSpace()},this.getHand=function(t){let n=S[t];return n===void 0&&(n=new e.yn,S[t]=n),n.getHandSpace()};function M(e){let t=C.indexOf(e.inputSource);if(t===-1)return;let n=S[t];n!==void 0&&(n.update(e.inputSource,e.frame,u||s),n.dispatchEvent({type:e.type,data:e.inputSource}))}function N(){a.removeEventListener(`select`,M),a.removeEventListener(`selectstart`,M),a.removeEventListener(`selectend`,M),a.removeEventListener(`squeeze`,M),a.removeEventListener(`squeezestart`,M),a.removeEventListener(`squeezeend`,M),a.removeEventListener(`end`,N),a.removeEventListener(`inputsourceschange`,ee);for(let e=0;e<S.length;e++){let t=C[e];t!==null&&(C[e]=null,S[e].disconnect(t))}A=null,j=null,_.reset();for(let e in v)delete v[e];t.setRenderTarget(b),m=null,p=null,f=null,a=null,x=null,se.stop(),i.isPresenting=!1,t.setPixelRatio(T),t.setSize(w.width,w.height,!1),i.dispatchEvent({type:`sessionend`})}this.setFramebufferScaleFactor=function(t){o=t,i.isPresenting===!0&&e.kn(`WebXRManager: Cannot change framebuffer scale while presenting.`)},this.setReferenceSpaceType=function(t){c=t,i.isPresenting===!0&&e.kn(`WebXRManager: Cannot change reference space type while presenting.`)},this.getReferenceSpace=function(){return u||s},this.setReferenceSpace=function(e){u=e},this.getBaseLayer=function(){return p===null?m:p},this.getBinding=function(){return f===null&&g&&(f=new XRWebGLBinding(a,r)),f},this.getFrame=function(){return h},this.getSession=function(){return a},this.setSession=async function(n){if(a=n,a!==null){if(b=t.getRenderTarget(),a.addEventListener(`select`,M),a.addEventListener(`selectstart`,M),a.addEventListener(`selectend`,M),a.addEventListener(`squeeze`,M),a.addEventListener(`squeezestart`,M),a.addEventListener(`squeezeend`,M),a.addEventListener(`end`,N),a.addEventListener(`inputsourceschange`,ee),y.xrCompatible!==!0&&await r.makeXRCompatible(),T=t.getPixelRatio(),t.getSize(w),g&&`createProjectionLayer`in XRWebGLBinding.prototype){let n=null,i=null,s=null;y.depth&&(s=y.stencil?r.DEPTH24_STENCIL8:r.DEPTH_COMPONENT24,n=y.stencil?e.b:e.y,i=y.stencil?e.cn:e.un);let c={colorFormat:r.RGBA8,depthFormat:s,scaleFactor:o};f=this.getBinding(),p=f.createProjectionLayer(c),a.updateRenderState({layers:[p]}),t.setPixelRatio(1),t.setSize(p.textureWidth,p.textureHeight,!1),x=new e.vn(p.textureWidth,p.textureHeight,{format:e.ot,type:e.on,depthTexture:new e.x(p.textureWidth,p.textureHeight,i,void 0,void 0,void 0,void 0,void 0,void 0,n),stencilBuffer:y.stencil,colorSpace:t.outputColorSpace,samples:y.antialias?4:0,resolveDepthBuffer:p.ignoreDepthValues===!1,resolveStencilBuffer:p.ignoreDepthValues===!1})}else{let n={antialias:y.antialias,alpha:!0,depth:y.depth,stencil:y.stencil,framebufferScaleFactor:o};m=new XRWebGLLayer(a,r,n),a.updateRenderState({baseLayer:m}),t.setPixelRatio(1),t.setSize(m.framebufferWidth,m.framebufferHeight,!1),x=new e.vn(m.framebufferWidth,m.framebufferHeight,{format:e.ot,type:e.on,colorSpace:t.outputColorSpace,stencilBuffer:y.stencil,resolveDepthBuffer:m.ignoreDepthValues===!1,resolveStencilBuffer:m.ignoreDepthValues===!1})}x.isXRRenderTarget=!0,this.setFoveation(l),u=null,s=await a.requestReferenceSpace(c),se.setContext(a),se.start(),i.isPresenting=!0,i.dispatchEvent({type:`sessionstart`})}},this.getEnvironmentBlendMode=function(){if(a!==null)return a.environmentBlendMode},this.getDepthTexture=function(){return _.getDepthTexture()};function ee(e){for(let t=0;t<e.removed.length;t++){let n=e.removed[t],r=C.indexOf(n);r>=0&&(C[r]=null,S[r].disconnect(n))}for(let t=0;t<e.added.length;t++){let n=e.added[t],r=C.indexOf(n);if(r===-1){for(let e=0;e<S.length;e++)if(e>=C.length){C.push(n),r=e;break}else if(C[e]===null){C[e]=n,r=e;break}if(r===-1)break}let i=S[r];i&&i.connect(n)}}let P=new e.hn,te=new e.hn;function ne(e,t,n){P.setFromMatrixPosition(t.matrixWorld),te.setFromMatrixPosition(n.matrixWorld);let r=P.distanceTo(te),i=t.projectionMatrix.elements,a=n.projectionMatrix.elements,o=i[14]/(i[10]-1),s=i[14]/(i[10]+1),c=(i[9]+1)/i[5],l=(i[9]-1)/i[5],u=(i[8]-1)/i[0],d=(a[8]+1)/a[0],f=o*u,p=o*d,m=r/(-u+d),h=m*-u;if(t.matrixWorld.decompose(e.position,e.quaternion,e.scale),e.translateX(h),e.translateZ(m),e.matrixWorld.compose(e.position,e.quaternion,e.scale),e.matrixWorldInverse.copy(e.matrixWorld).invert(),i[10]===-1)e.projectionMatrix.copy(t.projectionMatrix),e.projectionMatrixInverse.copy(t.projectionMatrixInverse);else{let t=o+m,n=s+m,i=f-h,a=p+(r-h),u=c*s/n*t,d=l*s/n*t;e.projectionMatrix.makePerspective(i,a,u,d,t,n),e.projectionMatrixInverse.copy(e.projectionMatrix).invert()}}function re(e,t){t===null?e.matrixWorld.copy(e.matrix):e.matrixWorld.multiplyMatrices(t.matrixWorld,e.matrix),e.matrixWorldInverse.copy(e.matrixWorld).invert()}this.updateCamera=function(e){if(a===null)return;let t=e.near,n=e.far;_.texture!==null&&(_.depthNear>0&&(t=_.depthNear),_.depthFar>0&&(n=_.depthFar)),k.near=D.near=E.near=t,k.far=D.far=E.far=n,(A!==k.near||j!==k.far)&&(a.updateRenderState({depthNear:k.near,depthFar:k.far}),A=k.near,j=k.far),k.layers.mask=e.layers.mask|6,E.layers.mask=k.layers.mask&-5,D.layers.mask=k.layers.mask&-3;let r=e.parent,i=k.cameras;re(k,r);for(let e=0;e<i.length;e++)re(i[e],r);i.length===2?ne(k,E,D):k.projectionMatrix.copy(E.projectionMatrix),ie(e,k,r)};function ie(t,n,r){r===null?t.matrix.copy(n.matrixWorld):(t.matrix.copy(r.matrixWorld),t.matrix.invert(),t.matrix.multiply(n.matrixWorld)),t.matrix.decompose(t.position,t.quaternion,t.scale),t.updateMatrixWorld(!0),t.projectionMatrix.copy(n.projectionMatrix),t.projectionMatrixInverse.copy(n.projectionMatrixInverse),t.isPerspectiveCamera&&(t.fov=e.nt*2*Math.atan(1/t.projectionMatrix.elements[5]),t.zoom=1)}this.getCamera=function(){return k},this.getFoveation=function(){if(!(p===null&&m===null))return l},this.setFoveation=function(e){l=e,p!==null&&(p.fixedFoveation=e),m!==null&&m.fixedFoveation!==void 0&&(m.fixedFoveation=e)},this.hasDepthSensing=function(){return _.texture!==null},this.getDepthSensingMesh=function(){return _.getMesh(k)},this.getCameraTexture=function(e){return v[e]};let ae=null;function oe(n,r){if(d=r.getViewerPose(u||s),h=r,d!==null){let n=d.views;m!==null&&(t.setRenderTargetFramebuffer(x,m.framebuffer),t.setRenderTarget(x));let r=!1;n.length!==k.cameras.length&&(k.cameras.length=0,r=!0);for(let i=0;i<n.length;i++){let a=n[i],o=null;if(m!==null)o=m.getViewport(a);else{let e=f.getViewSubImage(p,a);o=e.viewport,i===0&&(t.setRenderTargetTextures(x,e.colorTexture,e.depthStencilTexture),t.setRenderTarget(x))}let s=O[i];s===void 0&&(s=new e.Z,s.layers.enable(i),s.viewport=new e.gn,O[i]=s),s.matrix.fromArray(a.transform.matrix),s.matrix.decompose(s.position,s.quaternion,s.scale),s.projectionMatrix.fromArray(a.projectionMatrix),s.projectionMatrixInverse.copy(s.projectionMatrix).invert(),s.viewport.set(o.x,o.y,o.width,o.height),i===0&&(k.matrix.copy(s.matrix),k.matrix.decompose(k.position,k.quaternion,k.scale)),r===!0&&k.cameras.push(s)}let o=a.enabledFeatures;if(o&&o.includes(`depth-sensing`)&&a.depthUsage==`gpu-optimized`&&g){f=i.getBinding();let e=f.getDepthInformation(n[0]);e&&e.isValid&&e.texture&&_.init(e,a.renderState)}if(o&&o.includes(`camera-access`)&&g){t.state.unbindTexture(),f=i.getBinding();for(let t=0;t<n.length;t++){let r=n[t].camera;if(r){let t=v[r];t||(t=new e.w,v[r]=t);let n=f.getCameraImage(r);t.sourceTexture=n}}}}for(let e=0;e<S.length;e++){let t=C[e],n=S[e];t!==null&&n!==void 0&&n.update(t,r,u||s)}ae&&ae(n,r),r.detectedPlanes&&i.dispatchEvent({type:`planesdetected`,data:r}),h=null}let se=new n;se.setAnimationLoop(oe),this.setAnimationLoop=function(e){ae=e},this.dispose=function(){}}},hn=new e.V,gn=new e.B;gn.set(-1,0,0,0,1,0,0,0,1);function _n(t,n){function r(e,t){e.matrixAutoUpdate===!0&&e.updateMatrix(),t.value.copy(e.matrix)}function i(n,r){r.color.getRGB(n.fogColor.value,e.Tn(t)),r.isFog?(n.fogNear.value=r.near,n.fogFar.value=r.far):r.isFogExp2&&(n.fogDensity.value=r.density)}function a(e,t,n,r,i){t.isNodeMaterial?t.uniformsNeedUpdate=!1:t.isMeshBasicMaterial?o(e,t):t.isMeshLambertMaterial?(o(e,t),t.envMap&&(e.envMapIntensity.value=t.envMapIntensity)):t.isMeshToonMaterial?(o(e,t),f(e,t)):t.isMeshPhongMaterial?(o(e,t),d(e,t),t.envMap&&(e.envMapIntensity.value=t.envMapIntensity)):t.isMeshStandardMaterial?(o(e,t),p(e,t),t.isMeshPhysicalMaterial&&m(e,t,i)):t.isMeshMatcapMaterial?(o(e,t),h(e,t)):t.isMeshDepthMaterial?o(e,t):t.isMeshDistanceMaterial?(o(e,t),g(e,t)):t.isMeshNormalMaterial?o(e,t):t.isLineBasicMaterial?(s(e,t),t.isLineDashedMaterial&&c(e,t)):t.isPointsMaterial?l(e,t,n,r):t.isSpriteMaterial?u(e,t):t.isShadowMaterial?(e.color.value.copy(t.color),e.opacity.value=t.opacity):t.isShaderMaterial&&(t.uniformsNeedUpdate=!1)}function o(e,t){e.opacity.value=t.opacity,t.color&&e.diffuse.value.copy(t.color),t.emissive&&e.emissive.value.copy(t.emissive).multiplyScalar(t.emissiveIntensity),t.map&&(e.map.value=t.map,r(t.map,e.mapTransform)),t.alphaMap&&(e.alphaMap.value=t.alphaMap,r(t.alphaMap,e.alphaMapTransform)),t.bumpMap&&(e.bumpMap.value=t.bumpMap,r(t.bumpMap,e.bumpMapTransform),e.bumpScale.value=t.bumpScale,t.side===1&&(e.bumpScale.value*=-1)),t.normalMap&&(e.normalMap.value=t.normalMap,r(t.normalMap,e.normalMapTransform),e.normalScale.value.copy(t.normalScale),t.side===1&&e.normalScale.value.negate()),t.displacementMap&&(e.displacementMap.value=t.displacementMap,r(t.displacementMap,e.displacementMapTransform),e.displacementScale.value=t.displacementScale,e.displacementBias.value=t.displacementBias),t.emissiveMap&&(e.emissiveMap.value=t.emissiveMap,r(t.emissiveMap,e.emissiveMapTransform)),t.specularMap&&(e.specularMap.value=t.specularMap,r(t.specularMap,e.specularMapTransform)),t.alphaTest>0&&(e.alphaTest.value=t.alphaTest);let i=n.get(t),a=i.envMap,o=i.envMapRotation;a&&(e.envMap.value=a,e.envMapRotation.value.setFromMatrix4(hn.makeRotationFromEuler(o)).transpose(),a.isCubeTexture&&a.isRenderTargetTexture===!1&&e.envMapRotation.value.premultiply(gn),e.reflectivity.value=t.reflectivity,e.ior.value=t.ior,e.refractionRatio.value=t.refractionRatio),t.lightMap&&(e.lightMap.value=t.lightMap,e.lightMapIntensity.value=t.lightMapIntensity,r(t.lightMap,e.lightMapTransform)),t.aoMap&&(e.aoMap.value=t.aoMap,e.aoMapIntensity.value=t.aoMapIntensity,r(t.aoMap,e.aoMapTransform))}function s(e,t){e.diffuse.value.copy(t.color),e.opacity.value=t.opacity,t.map&&(e.map.value=t.map,r(t.map,e.mapTransform))}function c(e,t){e.dashSize.value=t.dashSize,e.totalSize.value=t.dashSize+t.gapSize,e.scale.value=t.scale}function l(e,t,n,i){e.diffuse.value.copy(t.color),e.opacity.value=t.opacity,e.size.value=t.size*n,e.scale.value=i*.5,t.map&&(e.map.value=t.map,r(t.map,e.uvTransform)),t.alphaMap&&(e.alphaMap.value=t.alphaMap,r(t.alphaMap,e.alphaMapTransform)),t.alphaTest>0&&(e.alphaTest.value=t.alphaTest)}function u(e,t){e.diffuse.value.copy(t.color),e.opacity.value=t.opacity,e.rotation.value=t.rotation,t.map&&(e.map.value=t.map,r(t.map,e.mapTransform)),t.alphaMap&&(e.alphaMap.value=t.alphaMap,r(t.alphaMap,e.alphaMapTransform)),t.alphaTest>0&&(e.alphaTest.value=t.alphaTest)}function d(e,t){e.specular.value.copy(t.specular),e.shininess.value=Math.max(t.shininess,1e-4)}function f(e,t){t.gradientMap&&(e.gradientMap.value=t.gradientMap)}function p(e,t){e.metalness.value=t.metalness,t.metalnessMap&&(e.metalnessMap.value=t.metalnessMap,r(t.metalnessMap,e.metalnessMapTransform)),e.roughness.value=t.roughness,t.roughnessMap&&(e.roughnessMap.value=t.roughnessMap,r(t.roughnessMap,e.roughnessMapTransform)),t.envMap&&(e.envMapIntensity.value=t.envMapIntensity)}function m(e,t,n){e.ior.value=t.ior,t.sheen>0&&(e.sheenColor.value.copy(t.sheenColor).multiplyScalar(t.sheen),e.sheenRoughness.value=t.sheenRoughness,t.sheenColorMap&&(e.sheenColorMap.value=t.sheenColorMap,r(t.sheenColorMap,e.sheenColorMapTransform)),t.sheenRoughnessMap&&(e.sheenRoughnessMap.value=t.sheenRoughnessMap,r(t.sheenRoughnessMap,e.sheenRoughnessMapTransform))),t.clearcoat>0&&(e.clearcoat.value=t.clearcoat,e.clearcoatRoughness.value=t.clearcoatRoughness,t.clearcoatMap&&(e.clearcoatMap.value=t.clearcoatMap,r(t.clearcoatMap,e.clearcoatMapTransform)),t.clearcoatRoughnessMap&&(e.clearcoatRoughnessMap.value=t.clearcoatRoughnessMap,r(t.clearcoatRoughnessMap,e.clearcoatRoughnessMapTransform)),t.clearcoatNormalMap&&(e.clearcoatNormalMap.value=t.clearcoatNormalMap,r(t.clearcoatNormalMap,e.clearcoatNormalMapTransform),e.clearcoatNormalScale.value.copy(t.clearcoatNormalScale),t.side===1&&e.clearcoatNormalScale.value.negate())),t.dispersion>0&&(e.dispersion.value=t.dispersion),t.iridescence>0&&(e.iridescence.value=t.iridescence,e.iridescenceIOR.value=t.iridescenceIOR,e.iridescenceThicknessMinimum.value=t.iridescenceThicknessRange[0],e.iridescenceThicknessMaximum.value=t.iridescenceThicknessRange[1],t.iridescenceMap&&(e.iridescenceMap.value=t.iridescenceMap,r(t.iridescenceMap,e.iridescenceMapTransform)),t.iridescenceThicknessMap&&(e.iridescenceThicknessMap.value=t.iridescenceThicknessMap,r(t.iridescenceThicknessMap,e.iridescenceThicknessMapTransform))),t.transmission>0&&(e.transmission.value=t.transmission,e.transmissionSamplerMap.value=n.texture,e.transmissionSamplerSize.value.set(n.width,n.height),t.transmissionMap&&(e.transmissionMap.value=t.transmissionMap,r(t.transmissionMap,e.transmissionMapTransform)),e.thickness.value=t.thickness,t.thicknessMap&&(e.thicknessMap.value=t.thicknessMap,r(t.thicknessMap,e.thicknessMapTransform)),e.attenuationDistance.value=t.attenuationDistance,e.attenuationColor.value.copy(t.attenuationColor)),t.anisotropy>0&&(e.anisotropyVector.value.set(t.anisotropy*Math.cos(t.anisotropyRotation),t.anisotropy*Math.sin(t.anisotropyRotation)),t.anisotropyMap&&(e.anisotropyMap.value=t.anisotropyMap,r(t.anisotropyMap,e.anisotropyMapTransform))),e.specularIntensity.value=t.specularIntensity,e.specularColor.value.copy(t.specularColor),t.specularColorMap&&(e.specularColorMap.value=t.specularColorMap,r(t.specularColorMap,e.specularColorMapTransform)),t.specularIntensityMap&&(e.specularIntensityMap.value=t.specularIntensityMap,r(t.specularIntensityMap,e.specularIntensityMapTransform))}function h(e,t){t.matcap&&(e.matcap.value=t.matcap)}function g(e,t){let r=n.get(t).light;e.referencePosition.value.setFromMatrixPosition(r.matrixWorld),e.nearDistance.value=r.shadow.camera.near,e.farDistance.value=r.shadow.camera.far}return{refreshFogUniforms:i,refreshMaterialUniforms:a}}function vn(t,n,r,i){let a={},o={},s=[],c=t.getParameter(t.MAX_UNIFORM_BUFFER_BINDINGS);function l(e,t){let n=t.program;i.uniformBlockBinding(e,n)}function u(e,t){let r=a[e.id];r===void 0&&(_(e),r=d(e),a[e.id]=r,e.addEventListener(`dispose`,y));let s=t.program;i.updateUBOMapping(e,s);let c=n.render.frame;o[e.id]!==c&&(p(e),o[e.id]=c)}function d(e){let n=f();e.__bindingPointIndex=n;let r=t.createBuffer(),i=e.__size,a=e.usage;return t.bindBuffer(t.UNIFORM_BUFFER,r),t.bufferData(t.UNIFORM_BUFFER,i,a),t.bindBuffer(t.UNIFORM_BUFFER,null),t.bindBufferBase(t.UNIFORM_BUFFER,n,r),r}function f(){for(let e=0;e<c;e++)if(s.indexOf(e)===-1)return s.push(e),e;return e.Cn(`WebGLRenderer: Maximum number of simultaneously usable uniforms groups reached.`),0}function p(e){let n=a[e.id],r=e.uniforms,i=e.__cache;t.bindBuffer(t.UNIFORM_BUFFER,n);for(let e=0,t=r.length;e<t;e++){let t=r[e];if(Array.isArray(t))for(let n=0,r=t.length;n<r;n++)m(t[n],e,n,i);else m(t,e,0,i)}t.bindBuffer(t.UNIFORM_BUFFER,null)}function m(e,n,r,i){if(g(e,n,r,i)===!0){let n=e.__offset,r=e.value;if(Array.isArray(r)){let t=0;for(let n=0;n<r.length;n++){let i=r[n],a=v(i);h(i,e.__data,t),typeof i!=`number`&&typeof i!=`boolean`&&!i.isMatrix3&&!ArrayBuffer.isView(i)&&(t+=a.storage/Float32Array.BYTES_PER_ELEMENT)}}else h(r,e.__data,0);t.bufferSubData(t.UNIFORM_BUFFER,n,e.__data)}}function h(e,t,n){typeof e==`number`||typeof e==`boolean`?t[0]=e:e.isMatrix3?(t[0]=e.elements[0],t[1]=e.elements[1],t[2]=e.elements[2],t[3]=0,t[4]=e.elements[3],t[5]=e.elements[4],t[6]=e.elements[5],t[7]=0,t[8]=e.elements[6],t[9]=e.elements[7],t[10]=e.elements[8],t[11]=0):ArrayBuffer.isView(e)?t.set(new e.constructor(e.buffer,e.byteOffset,t.length)):e.toArray(t,n)}function g(e,t,n,r){let i=e.value,a=t+`_`+n;if(r[a]===void 0)return typeof i==`number`||typeof i==`boolean`?r[a]=i:ArrayBuffer.isView(i)?r[a]=i.slice():r[a]=i.clone(),!0;{let e=r[a];if(typeof i==`number`||typeof i==`boolean`){if(e!==i)return r[a]=i,!0}else if(ArrayBuffer.isView(i))return!0;else if(e.equals(i)===!1)return e.copy(i),!0}return!1}function _(e){let t=e.uniforms,n=0;for(let e=0,r=t.length;e<r;e++){let r=Array.isArray(t[e])?t[e]:[t[e]];for(let e=0,t=r.length;e<t;e++){let t=r[e],i=Array.isArray(t.value)?t.value:[t.value];for(let e=0,r=i.length;e<r;e++){let r=i[e],a=v(r),o=n%16,s=o%a.boundary,c=o+s;n+=s,c!==0&&16-c<a.storage&&(n+=16-c),t.__data=new Float32Array(a.storage/Float32Array.BYTES_PER_ELEMENT),t.__offset=n,n+=a.storage}}}let r=n%16;return r>0&&(n+=16-r),e.__size=n,e.__cache={},this}function v(t){let n={boundary:0,storage:0};return typeof t==`number`||typeof t==`boolean`?(n.boundary=4,n.storage=4):t.isVector2?(n.boundary=8,n.storage=8):t.isVector3||t.isColor?(n.boundary=16,n.storage=12):t.isVector4?(n.boundary=16,n.storage=16):t.isMatrix3?(n.boundary=48,n.storage=48):t.isMatrix4?(n.boundary=64,n.storage=64):t.isTexture?e.kn(`WebGLRenderer: Texture samplers can not be part of an uniforms group.`):ArrayBuffer.isView(t)?(n.boundary=16,n.storage=t.byteLength):e.kn(`WebGLRenderer: Unsupported uniform value type.`,t),n}function y(e){let n=e.target;n.removeEventListener(`dispose`,y);let r=s.indexOf(n.__bindingPointIndex);s.splice(r,1),t.deleteBuffer(a[n.id]),delete a[n.id],delete o[n.id]}function b(){for(let e in a)t.deleteBuffer(a[e]);s=[],a={},o={}}return{bind:l,update:u,dispose:b}}var yn=new Uint16Array([12469,15057,12620,14925,13266,14620,13807,14376,14323,13990,14545,13625,14713,13328,14840,12882,14931,12528,14996,12233,15039,11829,15066,11525,15080,11295,15085,10976,15082,10705,15073,10495,13880,14564,13898,14542,13977,14430,14158,14124,14393,13732,14556,13410,14702,12996,14814,12596,14891,12291,14937,11834,14957,11489,14958,11194,14943,10803,14921,10506,14893,10278,14858,9960,14484,14039,14487,14025,14499,13941,14524,13740,14574,13468,14654,13106,14743,12678,14818,12344,14867,11893,14889,11509,14893,11180,14881,10751,14852,10428,14812,10128,14765,9754,14712,9466,14764,13480,14764,13475,14766,13440,14766,13347,14769,13070,14786,12713,14816,12387,14844,11957,14860,11549,14868,11215,14855,10751,14825,10403,14782,10044,14729,9651,14666,9352,14599,9029,14967,12835,14966,12831,14963,12804,14954,12723,14936,12564,14917,12347,14900,11958,14886,11569,14878,11247,14859,10765,14828,10401,14784,10011,14727,9600,14660,9289,14586,8893,14508,8533,15111,12234,15110,12234,15104,12216,15092,12156,15067,12010,15028,11776,14981,11500,14942,11205,14902,10752,14861,10393,14812,9991,14752,9570,14682,9252,14603,8808,14519,8445,14431,8145,15209,11449,15208,11451,15202,11451,15190,11438,15163,11384,15117,11274,15055,10979,14994,10648,14932,10343,14871,9936,14803,9532,14729,9218,14645,8742,14556,8381,14461,8020,14365,7603,15273,10603,15272,10607,15267,10619,15256,10631,15231,10614,15182,10535,15118,10389,15042,10167,14963,9787,14883,9447,14800,9115,14710,8665,14615,8318,14514,7911,14411,7507,14279,7198,15314,9675,15313,9683,15309,9712,15298,9759,15277,9797,15229,9773,15166,9668,15084,9487,14995,9274,14898,8910,14800,8539,14697,8234,14590,7790,14479,7409,14367,7067,14178,6621,15337,8619,15337,8631,15333,8677,15325,8769,15305,8871,15264,8940,15202,8909,15119,8775,15022,8565,14916,8328,14804,8009,14688,7614,14569,7287,14448,6888,14321,6483,14088,6171,15350,7402,15350,7419,15347,7480,15340,7613,15322,7804,15287,7973,15229,8057,15148,8012,15046,7846,14933,7611,14810,7357,14682,7069,14552,6656,14421,6316,14251,5948,14007,5528,15356,5942,15356,5977,15353,6119,15348,6294,15332,6551,15302,6824,15249,7044,15171,7122,15070,7050,14949,6861,14818,6611,14679,6349,14538,6067,14398,5651,14189,5311,13935,4958,15359,4123,15359,4153,15356,4296,15353,4646,15338,5160,15311,5508,15263,5829,15188,6042,15088,6094,14966,6001,14826,5796,14678,5543,14527,5287,14377,4985,14133,4586,13869,4257,15360,1563,15360,1642,15358,2076,15354,2636,15341,3350,15317,4019,15273,4429,15203,4732,15105,4911,14981,4932,14836,4818,14679,4621,14517,4386,14359,4156,14083,3795,13808,3437,15360,122,15360,137,15358,285,15355,636,15344,1274,15322,2177,15281,2765,15215,3223,15120,3451,14995,3569,14846,3567,14681,3466,14511,3305,14344,3121,14037,2800,13753,2467,15360,0,15360,1,15359,21,15355,89,15346,253,15325,479,15287,796,15225,1148,15133,1492,15008,1749,14856,1882,14685,1886,14506,1783,14324,1608,13996,1398,13702,1183]),bn=null;function xn(){return bn===null&&(bn=new e.v(yn,16,16,e.Lt,e.A),bn.name=`DFG_LUT`,bn.minFilter=e.N,bn.magFilter=e.N,bn.wrapS=e.l,bn.wrapT=e.l,bn.generateMipmaps=!1,bn.needsUpdate=!0),bn}var Sn=class{constructor(t={}){let{canvas:i=e.xn(),context:a=null,depth:o=!0,stencil:s=!1,alpha:c=!1,antialias:l=!1,premultipliedAlpha:h=!0,preserveDrawingBuffer:g=!1,powerPreference:_=`default`,failIfMajorPerformanceCaveat:v=!1,reversedDepthBuffer:y=!1,outputBufferType:b=e.on}=t;this.isWebGLRenderer=!0;let x;if(a!==null){if(typeof WebGLRenderingContext<`u`&&a instanceof WebGLRenderingContext)throw Error(`THREE.WebGLRenderer: WebGL 1 is not supported since r163.`);x=a.getContextAttributes().alpha}else x=c;let S=b,C=new Set([e.st,e.Rt,e.Ht]),w=new Set([e.on,e.un,e.pn,e.cn,e.dn,e.fn]),T=new Uint32Array(4),E=new Int32Array(4),D=new e.hn,O=null,k=null,A=[],j=[],M=null;this.domElement=i,this.debug={checkShaderErrors:!0,onShaderError:null},this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.sortObjects=!0,this.clippingPlanes=[],this.localClippingEnabled=!1,this.toneMapping=0,this.toneMappingExposure=1,this.transmissionResolutionScale=1;let N=this,ee=!1,P=null,ce=null,F=null,I=null;this._outputColorSpace=e.Yt;let ue=0,L=0,R=null,de=-1,z=null,B=new e.gn,fe=new e.gn,pe=null,me=new e.u(0),V=0,H=i.width,U=i.height,W=1,he=null,ge=null,_e=new e.gn(0,0,H,U),ve=new e.gn(0,0,H,U),ye=!1,be=new e.D,xe=!1,Se=!1,Ce=new e.V,we=new e.hn,Te=new e.gn,Ee={background:null,fog:null,environment:null,overrideMaterial:null,isScene:!0},De=!1;function Oe(){return R===null?W:1}let G=a;function ke(e,t){return i.getContext(e,t)}try{let e={alpha:!0,depth:o,stencil:s,antialias:l,premultipliedAlpha:h,preserveDrawingBuffer:g,powerPreference:_,failIfMajorPerformanceCaveat:v};if(`setAttribute`in i&&i.setAttribute(`data-engine`,`three.js r185`),i.addEventListener(`webglcontextlost`,Ye,!1),i.addEventListener(`webglcontextrestored`,Xe,!1),i.addEventListener(`webglcontextcreationerror`,Ze,!1),G===null){let t=`webgl2`;if(G=ke(t,e),G===null)throw ke(t)?Error(`THREE.WebGLRenderer: Error creating WebGL context with your selected attributes.`):Error(`THREE.WebGLRenderer: Error creating WebGL context.`)}}catch(t){throw e.Cn(`WebGLRenderer: `+t.message),t}let K,q,J,Ae,Y,X,je,Me,Ne,Pe,Fe,Ie,Le,Re,ze,Be,Ve,He,Ue,We,Ge,Ke,qe;function Je(){K=new ne(G),K.init(),Ge=new un(G,K),q=new p(G,K,t,Ge),J=new cn(G,K),q.reversedDepthBuffer&&y&&J.buffers.depth.setReversed(!0),ce=G.createFramebuffer(),F=G.createFramebuffer(),I=G.createFramebuffer(),Ae=new ae(G),Y=new Vt,X=new ln(G,K,J,Y,q,Ge,Ae),je=new te(N),Me=new r(G),Ke=new d(G,Me),Ne=new re(G,Me,Ae,Ke),Pe=new se(G,Ne,Me,Ke,Ae),He=new oe(G,q,X),ze=new m(Y),Fe=new Bt(N,je,K,q,Ke,ze),Ie=new _n(N,Y),Le=new Gt,Re=new Qt(K),Ve=new u(N,je,J,Pe,x,h),Be=new sn(N,Pe,q),qe=new vn(G,Ae,q,J),Ue=new f(G,K,Ae),We=new ie(G,K,Ae),Ae.programs=Fe.programs,N.capabilities=q,N.extensions=K,N.properties=Y,N.renderLists=Le,N.shadowMap=Be,N.state=J,N.info=Ae}Je(),S!==1009&&(M=new le(S,i.width,i.height,l,o,s));let Z=new mn(N,G);this.xr=Z,this.getContext=function(){return G},this.getContextAttributes=function(){return G.getContextAttributes()},this.forceContextLoss=function(){let e=K.get(`WEBGL_lose_context`);e&&e.loseContext()},this.forceContextRestore=function(){let e=K.get(`WEBGL_lose_context`);e&&e.restoreContext()},this.getPixelRatio=function(){return W},this.setPixelRatio=function(e){e!==void 0&&(W=e,this.setSize(H,U,!1))},this.getSize=function(e){return e.set(H,U)},this.setSize=function(t,n,r=!0){if(Z.isPresenting){e.kn(`WebGLRenderer: Can't change size while VR device is presenting.`);return}H=t,U=n,i.width=Math.floor(t*W),i.height=Math.floor(n*W),r===!0&&(i.style.width=t+`px`,i.style.height=n+`px`),M!==null&&M.setSize(i.width,i.height),this.setViewport(0,0,t,n)},this.getDrawingBufferSize=function(e){return e.set(H*W,U*W).floor()},this.setDrawingBufferSize=function(e,t,n){H=e,U=t,W=n,i.width=Math.floor(e*n),i.height=Math.floor(t*n),this.setViewport(0,0,e,t)},this.setEffects=function(t){if(S===1009){e.Cn(`WebGLRenderer: setEffects() requires outputBufferType set to HalfFloatType or FloatType.`);return}if(t){for(let n=0;n<t.length;n++)if(t[n].isOutputPass===!0){e.kn(`WebGLRenderer: OutputPass is not needed in setEffects(). Tone mapping and color space conversion are applied automatically.`);break}}M.setEffects(t||[])},this.getCurrentViewport=function(e){return e.copy(B)},this.getViewport=function(e){return e.copy(_e)},this.setViewport=function(e,t,n,r){e.isVector4?_e.set(e.x,e.y,e.z,e.w):_e.set(e,t,n,r),J.viewport(B.copy(_e).multiplyScalar(W).round())},this.getScissor=function(e){return e.copy(ve)},this.setScissor=function(e,t,n,r){e.isVector4?ve.set(e.x,e.y,e.z,e.w):ve.set(e,t,n,r),J.scissor(fe.copy(ve).multiplyScalar(W).round())},this.getScissorTest=function(){return ye},this.setScissorTest=function(e){J.setScissorTest(ye=e)},this.setOpaqueSort=function(e){he=e},this.setTransparentSort=function(e){ge=e},this.getClearColor=function(e){return e.copy(Ve.getClearColor())},this.setClearColor=function(){Ve.setClearColor(...arguments)},this.getClearAlpha=function(){return Ve.getClearAlpha()},this.setClearAlpha=function(){Ve.setClearAlpha(...arguments)},this.clear=function(e=!0,t=!0,n=!0){let r=0;if(e){let e=!1;if(R!==null){let t=R.texture.format;e=C.has(t)}if(e){let e=R.texture.type,t=w.has(e),n=Ve.getClearColor(),r=Ve.getClearAlpha(),i=n.r,a=n.g,o=n.b;t?(T[0]=i,T[1]=a,T[2]=o,T[3]=r,G.clearBufferuiv(G.COLOR,0,T)):(E[0]=i,E[1]=a,E[2]=o,E[3]=r,G.clearBufferiv(G.COLOR,0,E))}else r|=G.COLOR_BUFFER_BIT}t&&(r|=G.DEPTH_BUFFER_BIT,this.state.buffers.depth.setMask(!0)),n&&(r|=G.STENCIL_BUFFER_BIT,this.state.buffers.stencil.setMask(4294967295)),r!==0&&G.clear(r)},this.clearColor=function(){this.clear(!0,!1,!1)},this.clearDepth=function(){this.clear(!1,!0,!1)},this.clearStencil=function(){this.clear(!1,!1,!0)},this.setNodesHandler=function(e){e.setRenderer(this),P=e},this.dispose=function(){i.removeEventListener(`webglcontextlost`,Ye,!1),i.removeEventListener(`webglcontextrestored`,Xe,!1),i.removeEventListener(`webglcontextcreationerror`,Ze,!1),Ve.dispose(),Le.dispose(),Re.dispose(),Y.dispose(),je.dispose(),Pe.dispose(),Ke.dispose(),qe.dispose(),Fe.dispose(),Z.dispose(),Z.removeEventListener(`sessionstart`,at),Z.removeEventListener(`sessionend`,ot),st.stop()};function Ye(t){t.preventDefault(),e.En(`WebGLRenderer: Context Lost.`),ee=!0}function Xe(){e.En(`WebGLRenderer: Context Restored.`),ee=!1;let t=Ae.autoReset,n=Be.enabled,r=Be.autoUpdate,i=Be.needsUpdate,a=Be.type;Je(),Ae.autoReset=t,Be.enabled=n,Be.autoUpdate=r,Be.needsUpdate=i,Be.type=a}function Ze(t){e.Cn(`WebGLRenderer: A WebGL context could not be created. Reason: `,t.statusMessage)}function Qe(e){let t=e.target;t.removeEventListener(`dispose`,Qe),et(t)}function et(e){tt(e),Y.remove(e)}function tt(e){let t=Y.get(e).programs;t!==void 0&&(t.forEach(function(e){Fe.releaseProgram(e)}),e.isShaderMaterial&&Fe.releaseShaderCache(e))}this.renderBufferDirect=function(e,t,n,r,i,a){t===null&&(t=Ee);let o=i.isMesh&&i.matrixWorld.determinantAffine()<0,s=_t(e,t,n,r,i);J.setMaterial(r,o);let c=n.index,l=1;if(r.wireframe===!0){if(c=Ne.getWireframeAttribute(n),c===void 0)return;l=2}let u=n.drawRange,d=n.attributes.position,f=u.start*l,p=(u.start+u.count)*l;a!==null&&(f=Math.max(f,a.start*l),p=Math.min(p,(a.start+a.count)*l)),c===null?d!=null&&(f=Math.max(f,0),p=Math.min(p,d.count)):(f=Math.max(f,0),p=Math.min(p,c.count));let m=p-f;if(m<0||m===1/0)return;Ke.setup(i,r,s,n,c);let h,g=Ue;if(c!==null&&(h=Me.get(c),g=We,g.setIndex(h)),i.isMesh)r.wireframe===!0?(J.setLineWidth(r.wireframeLinewidth*Oe()),g.setMode(G.LINES)):g.setMode(G.TRIANGLES);else if(i.isLine){let e=r.linewidth;e===void 0&&(e=1),J.setLineWidth(e*Oe()),i.isLineSegments?g.setMode(G.LINES):i.isLineLoop?g.setMode(G.LINE_LOOP):g.setMode(G.LINE_STRIP)}else i.isPoints?g.setMode(G.POINTS):i.isSprite&&g.setMode(G.TRIANGLES);if(i.isBatchedMesh)if(K.get(`WEBGL_multi_draw`))g.renderMultiDraw(i._multiDrawStarts,i._multiDrawCounts,i._multiDrawCount);else{let e=i._multiDrawStarts,t=i._multiDrawCounts,n=i._multiDrawCount,a=c?Me.get(c).bytesPerElement:1,o=Y.get(r).currentProgram.getUniforms();for(let r=0;r<n;r++)o.setValue(G,`_gl_DrawID`,r),g.render(e[r]/a,t[r])}else if(i.isInstancedMesh)g.renderInstances(f,m,i.count);else if(n.isInstancedBufferGeometry){let e=n._maxInstanceCount===void 0?1/0:n._maxInstanceCount,t=Math.min(n.instanceCount,e);g.renderInstances(f,m,t)}else g.render(f,m)};function nt(e,t,n){e.transparent===!0&&e.side===2&&e.forceSinglePass===!1?(e.side=1,e.needsUpdate=!0,pt(e,t,n),e.side=0,e.needsUpdate=!0,pt(e,t,n),e.side=2):pt(e,t,n)}this.compile=function(e,t,n=null){n===null&&(n=e),k=Re.get(n),k.init(t),j.push(k),n.traverseVisible(function(e){e.isLight&&e.layers.test(t.layers)&&(k.pushLight(e),e.castShadow&&k.pushShadow(e))}),e!==n&&e.traverseVisible(function(e){e.isLight&&e.layers.test(t.layers)&&(k.pushLight(e),e.castShadow&&k.pushShadow(e))}),k.setupLights();let r=new Set;return e.traverse(function(e){if(!(e.isMesh||e.isPoints||e.isLine||e.isSprite))return;let t=e.material;if(t)if(Array.isArray(t))for(let i=0;i<t.length;i++){let a=t[i];nt(a,n,e),r.add(a)}else nt(t,n,e),r.add(t)}),k=j.pop(),r},this.compileAsync=function(e,t,n=null){let r=this.compile(e,t,n);return new Promise(t=>{function n(){if(r.forEach(function(e){Y.get(e).currentProgram.isReady()&&r.delete(e)}),r.size===0){t(e);return}setTimeout(n,10)}K.get(`KHR_parallel_shader_compile`)===null?setTimeout(n,10):n()})};let rt=null;function it(e){rt&&rt(e)}function at(){st.stop()}function ot(){st.start()}let st=new n;st.setAnimationLoop(it),typeof self<`u`&&st.setContext(self),this.setAnimationLoop=function(e){rt=e,Z.setAnimationLoop(e),e===null?st.stop():st.start()},Z.addEventListener(`sessionstart`,at),Z.addEventListener(`sessionend`,ot),this.render=function(t,n){if(n!==void 0&&n.isCamera!==!0){e.Cn(`WebGLRenderer.render: camera is not an instance of THREE.Camera.`);return}if(ee===!0)return;P!==null&&P.renderStart(t,n);let r=Z.enabled===!0&&Z.isPresenting===!0,i=M!==null&&(R===null||r)&&M.begin(N,R);if(t.matrixWorldAutoUpdate===!0&&t.updateMatrixWorld(),n.parent===null&&n.matrixWorldAutoUpdate===!0&&n.updateMatrixWorld(),Z.enabled===!0&&Z.isPresenting===!0&&(M===null||M.isCompositing()===!1)&&(Z.cameraAutoUpdate===!0&&Z.updateCamera(n),n=Z.getCamera()),t.isScene===!0&&t.onBeforeRender(N,t,n,R),k=Re.get(t,j.length),k.init(n),k.state.textureUnits=X.getTextureUnits(),j.push(k),Ce.multiplyMatrices(n.projectionMatrix,n.matrixWorldInverse),be.setFromProjectionMatrix(Ce,e._n,n.reversedDepth),Se=this.localClippingEnabled,xe=ze.init(this.clippingPlanes,Se),O=Le.get(t,A.length),O.init(),A.push(O),Z.enabled===!0&&Z.isPresenting===!0){let e=N.xr.getDepthSensingMesh();e!==null&&ct(e,n,-1/0,N.sortObjects)}ct(t,n,0,N.sortObjects),O.finish(),N.sortObjects===!0&&O.sort(he,ge,n.reversedDepth),De=Z.enabled===!1||Z.isPresenting===!1||Z.hasDepthSensing()===!1,De&&Ve.addToRenderList(O,t),this.info.render.frame++,this.info.autoReset===!0&&this.info.reset(),xe===!0&&ze.beginShadows();let a=k.state.shadowsArray;if(Be.render(a,t,n),xe===!0&&ze.endShadows(),(i&&M.hasRenderPass())===!1){let e=O.opaque,r=O.transmissive;if(k.setupLights(),n.isArrayCamera){let i=n.cameras;if(r.length>0)for(let n=0,a=i.length;n<a;n++){let a=i[n];ut(e,r,t,a)}De&&Ve.render(t);for(let e=0,n=i.length;e<n;e++){let n=i[e];lt(O,t,n,n.viewport)}}else r.length>0&&ut(e,r,t,n),De&&Ve.render(t),lt(O,t,n)}R!==null&&L===0&&(X.updateMultisampleRenderTarget(R),X.updateRenderTargetMipmap(R)),i&&M.end(N),t.isScene===!0&&t.onAfterRender(N,t,n),Ke.resetDefaultState(),de=-1,z=null,j.pop(),j.length>0?(k=j[j.length-1],X.setTextureUnits(k.state.textureUnits),xe===!0&&ze.setGlobalState(N.clippingPlanes,k.state.camera)):k=null,A.pop(),O=A.length>0?A[A.length-1]:null,P!==null&&P.renderEnd()};function ct(e,t,n,r){if(e.visible===!1)return;if(e.layers.test(t.layers)){if(e.isGroup)n=e.renderOrder;else if(e.isLOD)e.autoUpdate===!0&&e.update(t);else if(e.isLightProbeGrid)k.pushLightProbeGrid(e);else if(e.isLight)k.pushLight(e),e.castShadow&&k.pushShadow(e);else if(e.isSprite){if(!e.frustumCulled||be.intersectsSprite(e)){r&&Te.setFromMatrixPosition(e.matrixWorld).applyMatrix4(Ce);let t=Pe.update(e),i=e.material;i.visible&&O.push(e,t,i,n,Te.z,null)}}else if((e.isMesh||e.isLine||e.isPoints)&&(!e.frustumCulled||be.intersectsObject(e))){let t=Pe.update(e),i=e.material;if(r&&(e.boundingSphere===void 0?(t.boundingSphere===null&&t.computeBoundingSphere(),Te.copy(t.boundingSphere.center)):(e.boundingSphere===null&&e.computeBoundingSphere(),Te.copy(e.boundingSphere.center)),Te.applyMatrix4(e.matrixWorld).applyMatrix4(Ce)),Array.isArray(i)){let r=t.groups;for(let a=0,o=r.length;a<o;a++){let o=r[a],s=i[o.materialIndex];s&&s.visible&&O.push(e,t,s,n,Te.z,o)}}else i.visible&&O.push(e,t,i,n,Te.z,null)}}let i=e.children;for(let e=0,a=i.length;e<a;e++)ct(i[e],t,n,r)}function lt(e,t,n,r){let{opaque:i,transmissive:a,transparent:o}=e;k.setupLightsView(n),xe===!0&&ze.setGlobalState(N.clippingPlanes,n),r&&J.viewport(B.copy(r)),i.length>0&&dt(i,t,n),a.length>0&&dt(a,t,n),o.length>0&&dt(o,t,n),J.buffers.depth.setTest(!0),J.buffers.depth.setMask(!0),J.buffers.color.setMask(!0),J.setPolygonOffset(!1)}function ut(t,n,r,i){if((r.isScene===!0?r.overrideMaterial:null)!==null)return;if(k.state.transmissionRenderTarget[i.id]===void 0){let t=K.has(`EXT_color_buffer_half_float`)||K.has(`EXT_color_buffer_float`);k.state.transmissionRenderTarget[i.id]=new e.vn(1,1,{generateMipmaps:!0,type:t?e.A:e.on,minFilter:e.P,samples:Math.max(4,q.samples),stencilBuffer:s,resolveDepthBuffer:!1,resolveStencilBuffer:!1,colorSpace:e.d.workingColorSpace})}let a=k.state.transmissionRenderTarget[i.id],o=i.viewport||B;a.setSize(o.z*N.transmissionResolutionScale,o.w*N.transmissionResolutionScale);let c=N.getRenderTarget(),l=N.getActiveCubeFace(),u=N.getActiveMipmapLevel();N.setRenderTarget(a),N.getClearColor(me),V=N.getClearAlpha(),V<1&&N.setClearColor(16777215,.5),N.clear(),De&&Ve.render(r);let d=N.toneMapping;N.toneMapping=0;let f=i.viewport;if(i.viewport!==void 0&&(i.viewport=void 0),k.setupLightsView(i),xe===!0&&ze.setGlobalState(N.clippingPlanes,i),dt(t,r,i),X.updateMultisampleRenderTarget(a),X.updateRenderTargetMipmap(a),K.has(`WEBGL_multisampled_render_to_texture`)===!1){let e=!1;for(let t=0,a=n.length;t<a;t++){let{object:a,geometry:o,material:s,group:c}=n[t];if(s.side===2&&a.layers.test(i.layers)){let t=s.side;s.side=1,s.needsUpdate=!0,ft(a,r,i,o,s,c),s.side=t,s.needsUpdate=!0,e=!0}}e===!0&&(X.updateMultisampleRenderTarget(a),X.updateRenderTargetMipmap(a))}N.setRenderTarget(c,l,u),N.setClearColor(me,V),f!==void 0&&(i.viewport=f),N.toneMapping=d}function dt(e,t,n){let r=t.isScene===!0?t.overrideMaterial:null;for(let i=0,a=e.length;i<a;i++){let a=e[i],{object:o,geometry:s,group:c}=a,l=a.material;l.allowOverride===!0&&r!==null&&(l=r),o.layers.test(n.layers)&&ft(o,t,n,s,l,c)}}function ft(e,t,n,r,i,a){e.onBeforeRender(N,t,n,r,i,a),e.modelViewMatrix.multiplyMatrices(n.matrixWorldInverse,e.matrixWorld),e.normalMatrix.getNormalMatrix(e.modelViewMatrix),i.onBeforeRender(N,t,n,r,e,a),i.transparent===!0&&i.side===2&&i.forceSinglePass===!1?(i.side=1,i.needsUpdate=!0,N.renderBufferDirect(n,t,r,i,e,a),i.side=0,i.needsUpdate=!0,N.renderBufferDirect(n,t,r,i,e,a),i.side=2):N.renderBufferDirect(n,t,r,i,e,a),e.onAfterRender(N,t,n,r,i,a)}function pt(e,t,n){t.isScene!==!0&&(t=Ee);let r=Y.get(e),i=k.state.lights,a=k.state.shadowsArray,o=i.state.version,s=Fe.getParameters(e,i.state,a,t,n,k.state.lightProbeGridArray),c=Fe.getProgramCacheKey(s),l=r.programs;r.environment=e.isMeshStandardMaterial||e.isMeshLambertMaterial||e.isMeshPhongMaterial?t.environment:null,r.fog=t.fog;let u=e.isMeshStandardMaterial||e.isMeshLambertMaterial&&!e.envMap||e.isMeshPhongMaterial&&!e.envMap;r.envMap=je.get(e.envMap||r.environment,u),r.envMapRotation=r.environment!==null&&e.envMap===null?t.environmentRotation:e.envMapRotation,l===void 0&&(e.addEventListener(`dispose`,Qe),l=new Map,r.programs=l);let d=l.get(c);if(d!==void 0){if(r.currentProgram===d&&r.lightsStateVersion===o)return ht(e,s),d}else s.uniforms=Fe.getUniforms(e),P!==null&&e.isNodeMaterial&&P.build(e,n,s),e.onBeforeCompile(s,N),d=Fe.acquireProgram(s,c),l.set(c,d),r.uniforms=s.uniforms;let f=r.uniforms;return(!e.isShaderMaterial&&!e.isRawShaderMaterial||e.clipping===!0)&&(f.clippingPlanes=ze.uniform),ht(e,s),r.needsLights=yt(e),r.lightsStateVersion=o,r.needsLights&&(f.ambientLightColor.value=i.state.ambient,f.lightProbe.value=i.state.probe,f.directionalLights.value=i.state.directional,f.directionalLightShadows.value=i.state.directionalShadow,f.spotLights.value=i.state.spot,f.spotLightShadows.value=i.state.spotShadow,f.rectAreaLights.value=i.state.rectArea,f.ltc_1.value=i.state.rectAreaLTC1,f.ltc_2.value=i.state.rectAreaLTC2,f.pointLights.value=i.state.point,f.pointLightShadows.value=i.state.pointShadow,f.hemisphereLights.value=i.state.hemi,f.directionalShadowMatrix.value=i.state.directionalShadowMatrix,f.spotLightMatrix.value=i.state.spotLightMatrix,f.spotLightMap.value=i.state.spotLightMap,f.pointShadowMatrix.value=i.state.pointShadowMatrix),r.lightProbeGrid=k.state.lightProbeGridArray.length>0,r.currentProgram=d,r.uniformsList=null,d}function mt(e){if(e.uniformsList===null){let t=e.currentProgram.getUniforms();e.uniformsList=$e.seqWithValue(t.seq,e.uniforms)}return e.uniformsList}function ht(e,t){let n=Y.get(e);n.outputColorSpace=t.outputColorSpace,n.batching=t.batching,n.batchingColor=t.batchingColor,n.instancing=t.instancing,n.instancingColor=t.instancingColor,n.instancingMorph=t.instancingMorph,n.skinning=t.skinning,n.morphTargets=t.morphTargets,n.morphNormals=t.morphNormals,n.morphColors=t.morphColors,n.morphTargetsCount=t.morphTargetsCount,n.numClippingPlanes=t.numClippingPlanes,n.numIntersection=t.numClipIntersection,n.vertexAlphas=t.vertexAlphas,n.vertexTangents=t.vertexTangents,n.toneMapping=t.toneMapping}function gt(e,t){if(e.length===0)return null;if(e.length===1)return e[0].texture===null?null:e[0];D.setFromMatrixPosition(t.matrixWorld);for(let t=0,n=e.length;t<n;t++){let n=e[t];if(n.texture!==null&&n.boundingBox.containsPoint(D))return n}return null}function _t(t,n,r,i,a){n.isScene!==!0&&(n=Ee),X.resetTextureUnits();let o=n.fog,s=i.isMeshStandardMaterial||i.isMeshLambertMaterial||i.isMeshPhongMaterial?n.environment:null,c=R===null?N.outputColorSpace:R.isXRRenderTarget===!0?R.texture.colorSpace:e.d.workingColorSpace,l=i.isMeshStandardMaterial||i.isMeshLambertMaterial&&!i.envMap||i.isMeshPhongMaterial&&!i.envMap,u=je.get(i.envMap||s,l),d=i.vertexColors===!0&&!!r.attributes.color&&r.attributes.color.itemSize===4,f=!!r.attributes.tangent&&(!!i.normalMap||i.anisotropy>0),p=!!r.morphAttributes.position,m=!!r.morphAttributes.normal,h=!!r.morphAttributes.color,g=0;i.toneMapped&&(R===null||R.isXRRenderTarget===!0)&&(g=N.toneMapping);let _=r.morphAttributes.position||r.morphAttributes.normal||r.morphAttributes.color,v=_===void 0?0:_.length,y=Y.get(i),b=k.state.lights;if(xe===!0&&(Se===!0||t!==z)){let e=t===z&&i.id===de;ze.setState(i,t,e)}let x=!1;i.version===y.__version?y.needsLights&&y.lightsStateVersion!==b.state.version?x=!0:y.outputColorSpace===c?a.isBatchedMesh&&y.batching===!1||!a.isBatchedMesh&&y.batching===!0||a.isBatchedMesh&&y.batchingColor===!0&&a.colorTexture===null||a.isBatchedMesh&&y.batchingColor===!1&&a.colorTexture!==null||a.isInstancedMesh&&y.instancing===!1||!a.isInstancedMesh&&y.instancing===!0||a.isSkinnedMesh&&y.skinning===!1||!a.isSkinnedMesh&&y.skinning===!0||a.isInstancedMesh&&y.instancingColor===!0&&a.instanceColor===null||a.isInstancedMesh&&y.instancingColor===!1&&a.instanceColor!==null||a.isInstancedMesh&&y.instancingMorph===!0&&a.morphTexture===null||a.isInstancedMesh&&y.instancingMorph===!1&&a.morphTexture!==null?x=!0:y.envMap===u?i.fog===!0&&y.fog!==o||y.numClippingPlanes!==void 0&&(y.numClippingPlanes!==ze.numPlanes||y.numIntersection!==ze.numIntersection)?x=!0:y.vertexAlphas===d&&y.vertexTangents===f&&y.morphTargets===p&&y.morphNormals===m&&y.morphColors===h&&y.toneMapping===g&&y.morphTargetsCount===v?!!y.lightProbeGrid!=k.state.lightProbeGridArray.length>0&&(x=!0):x=!0:x=!0:x=!0:(x=!0,y.__version=i.version);let S=y.currentProgram;x===!0&&(S=pt(i,n,a),P&&i.isNodeMaterial&&P.onUpdateProgram(i,S,y));let C=!1,w=!1,T=!1,E=S.getUniforms(),D=y.uniforms;if(J.useProgram(S.program)&&(C=!0,w=!0,T=!0),i.id!==de&&(de=i.id,w=!0),y.needsLights){let e=gt(k.state.lightProbeGridArray,a);y.lightProbeGrid!==e&&(y.lightProbeGrid=e,w=!0)}if(C||z!==t){J.buffers.depth.getReversed()&&t.reversedDepth!==!0&&(t._reversedDepth=!0,t.updateProjectionMatrix()),E.setValue(G,`projectionMatrix`,t.projectionMatrix),E.setValue(G,`viewMatrix`,t.matrixWorldInverse);let e=E.map.cameraPosition;e!==void 0&&e.setValue(G,we.setFromMatrixPosition(t.matrixWorld)),q.logarithmicDepthBuffer&&E.setValue(G,`logDepthBufFC`,2/(Math.log(t.far+1)/Math.LN2)),(i.isMeshPhongMaterial||i.isMeshToonMaterial||i.isMeshLambertMaterial||i.isMeshBasicMaterial||i.isMeshStandardMaterial||i.isShaderMaterial)&&E.setValue(G,`isOrthographic`,t.isOrthographicCamera===!0),z!==t&&(z=t,w=!0,T=!0)}if(y.needsLights&&(b.state.directionalShadowMap.length>0&&E.setValue(G,`directionalShadowMap`,b.state.directionalShadowMap,X),b.state.spotShadowMap.length>0&&E.setValue(G,`spotShadowMap`,b.state.spotShadowMap,X),b.state.pointShadowMap.length>0&&E.setValue(G,`pointShadowMap`,b.state.pointShadowMap,X)),a.isSkinnedMesh){E.setOptional(G,a,`bindMatrix`),E.setOptional(G,a,`bindMatrixInverse`);let e=a.skeleton;e&&(e.boneTexture===null&&e.computeBoneTexture(),E.setValue(G,`boneTexture`,e.boneTexture,X))}a.isBatchedMesh&&(E.setOptional(G,a,`batchingTexture`),E.setValue(G,`batchingTexture`,a._matricesTexture,X),E.setOptional(G,a,`batchingIdTexture`),E.setValue(G,`batchingIdTexture`,a._indirectTexture,X),E.setOptional(G,a,`batchingColorTexture`),a._colorsTexture!==null&&E.setValue(G,`batchingColorTexture`,a._colorsTexture,X));let O=r.morphAttributes;if((O.position!==void 0||O.normal!==void 0||O.color!==void 0)&&He.update(a,r,S),(w||y.receiveShadow!==a.receiveShadow)&&(y.receiveShadow=a.receiveShadow,E.setValue(G,`receiveShadow`,a.receiveShadow)),(i.isMeshStandardMaterial||i.isMeshLambertMaterial||i.isMeshPhongMaterial)&&i.envMap===null&&n.environment!==null&&(D.envMapIntensity.value=n.environmentIntensity),D.dfgLUT!==void 0&&(D.dfgLUT.value=xn()),w){if(E.setValue(G,`toneMappingExposure`,N.toneMappingExposure),y.needsLights&&vt(D,T),o&&i.fog===!0&&Ie.refreshFogUniforms(D,o),Ie.refreshMaterialUniforms(D,i,W,U,k.state.transmissionRenderTarget[t.id]),y.needsLights&&y.lightProbeGrid){let e=y.lightProbeGrid;D.probesSH.value=e.texture,D.probesMin.value.copy(e.boundingBox.min),D.probesMax.value.copy(e.boundingBox.max),D.probesResolution.value.copy(e.resolution)}$e.upload(G,mt(y),D,X)}if(i.isShaderMaterial&&i.uniformsNeedUpdate===!0&&($e.upload(G,mt(y),D,X),i.uniformsNeedUpdate=!1),i.isSpriteMaterial&&E.setValue(G,`center`,a.center),E.setValue(G,`modelViewMatrix`,a.modelViewMatrix),E.setValue(G,`normalMatrix`,a.normalMatrix),E.setValue(G,`modelMatrix`,a.matrixWorld),i.uniformsGroups!==void 0){let e=i.uniformsGroups;for(let t=0,n=e.length;t<n;t++){let n=e[t];qe.update(n,S),qe.bind(n,S)}}return S}function vt(e,t){e.ambientLightColor.needsUpdate=t,e.lightProbe.needsUpdate=t,e.directionalLights.needsUpdate=t,e.directionalLightShadows.needsUpdate=t,e.pointLights.needsUpdate=t,e.pointLightShadows.needsUpdate=t,e.spotLights.needsUpdate=t,e.spotLightShadows.needsUpdate=t,e.rectAreaLights.needsUpdate=t,e.hemisphereLights.needsUpdate=t}function yt(e){return e.isMeshLambertMaterial||e.isMeshToonMaterial||e.isMeshPhongMaterial||e.isMeshStandardMaterial||e.isShadowMaterial||e.isShaderMaterial&&e.lights===!0}this.getActiveCubeFace=function(){return ue},this.getActiveMipmapLevel=function(){return L},this.getRenderTarget=function(){return R},this.setRenderTargetTextures=function(e,t,n){let r=Y.get(e);r.__autoAllocateDepthBuffer=e.resolveDepthBuffer===!1,r.__autoAllocateDepthBuffer===!1&&(r.__useRenderToTexture=!1),Y.get(e.texture).__webglTexture=t,Y.get(e.depthTexture).__webglTexture=r.__autoAllocateDepthBuffer?void 0:n,r.__hasExternalTextures=!0},this.setRenderTargetFramebuffer=function(e,t){let n=Y.get(e);n.__webglFramebuffer=t,n.__useDefaultFramebuffer=t===void 0},this.setRenderTarget=function(e,t=0,n=0){R=e,ue=t,L=n;let r=null,i=!1,a=!1;if(e){let o=Y.get(e);if(o.__useDefaultFramebuffer!==void 0){J.bindFramebuffer(G.FRAMEBUFFER,o.__webglFramebuffer),B.copy(e.viewport),fe.copy(e.scissor),pe=e.scissorTest,J.viewport(B),J.scissor(fe),J.setScissorTest(pe),de=-1;return}else if(o.__webglFramebuffer===void 0)X.setupRenderTarget(e);else if(o.__hasExternalTextures)X.rebindTextures(e,Y.get(e.texture).__webglTexture,Y.get(e.depthTexture).__webglTexture);else if(e.depthBuffer){let t=e.depthTexture;if(o.__boundDepthTexture!==t){if(t!==null&&Y.has(t)&&(e.width!==t.image.width||e.height!==t.image.height))throw Error(`THREE.WebGLRenderer: Attached DepthTexture is initialized to the incorrect size.`);X.setupDepthRenderbuffer(e)}}let s=e.texture;(s.isData3DTexture||s.isDataArrayTexture||s.isCompressedArrayTexture)&&(a=!0);let c=Y.get(e).__webglFramebuffer;e.isWebGLCubeRenderTarget?(r=Array.isArray(c[t])?c[t][n]:c[t],i=!0):r=e.samples>0&&X.useMultisampledRTT(e)===!1?Y.get(e).__webglMultisampledFramebuffer:Array.isArray(c)?c[n]:c,B.copy(e.viewport),fe.copy(e.scissor),pe=e.scissorTest}else B.copy(_e).multiplyScalar(W).floor(),fe.copy(ve).multiplyScalar(W).floor(),pe=ye;if(n!==0&&(r=ce),J.bindFramebuffer(G.FRAMEBUFFER,r)&&J.drawBuffers(e,r),J.viewport(B),J.scissor(fe),J.setScissorTest(pe),i){let r=Y.get(e.texture);G.framebufferTexture2D(G.FRAMEBUFFER,G.COLOR_ATTACHMENT0,G.TEXTURE_CUBE_MAP_POSITIVE_X+t,r.__webglTexture,n)}else if(a){let r=t;for(let t=0;t<e.textures.length;t++){let i=Y.get(e.textures[t]);G.framebufferTextureLayer(G.FRAMEBUFFER,G.COLOR_ATTACHMENT0+t,i.__webglTexture,n,r)}}else if(e!==null&&n!==0){let t=Y.get(e.texture);G.framebufferTexture2D(G.FRAMEBUFFER,G.COLOR_ATTACHMENT0,G.TEXTURE_2D,t.__webglTexture,n)}de=-1},this.readRenderTargetPixels=function(t,n,r,i,a,o,s,c=0){if(!(t&&t.isWebGLRenderTarget)){e.Cn(`WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.`);return}let l=Y.get(t).__webglFramebuffer;if(t.isWebGLCubeRenderTarget&&s!==void 0&&(l=l[s]),l){J.bindFramebuffer(G.FRAMEBUFFER,l);try{let s=t.textures[c],l=s.format,u=s.type;if(t.textures.length>1&&G.readBuffer(G.COLOR_ATTACHMENT0+c),!q.textureFormatReadable(l)){e.Cn(`WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.`);return}if(!q.textureTypeReadable(u)){e.Cn(`WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.`);return}n>=0&&n<=t.width-i&&r>=0&&r<=t.height-a&&G.readPixels(n,r,i,a,Ge.convert(l),Ge.convert(u),o)}finally{let e=R===null?null:Y.get(R).__webglFramebuffer;J.bindFramebuffer(G.FRAMEBUFFER,e)}}},this.readRenderTargetPixelsAsync=async function(t,n,r,i,a,o,s,c=0){if(!(t&&t.isWebGLRenderTarget))throw Error(`THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.`);let l=Y.get(t).__webglFramebuffer;if(t.isWebGLCubeRenderTarget&&s!==void 0&&(l=l[s]),l)if(n>=0&&n<=t.width-i&&r>=0&&r<=t.height-a){J.bindFramebuffer(G.FRAMEBUFFER,l);let s=t.textures[c],u=s.format,d=s.type;if(t.textures.length>1&&G.readBuffer(G.COLOR_ATTACHMENT0+c),!q.textureFormatReadable(u))throw Error(`THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.`);if(!q.textureTypeReadable(d))throw Error(`THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.`);let f=G.createBuffer();G.bindBuffer(G.PIXEL_PACK_BUFFER,f),G.bufferData(G.PIXEL_PACK_BUFFER,o.byteLength,G.STREAM_READ),G.readPixels(n,r,i,a,Ge.convert(u),Ge.convert(d),0);let p=R===null?null:Y.get(R).__webglFramebuffer;J.bindFramebuffer(G.FRAMEBUFFER,p);let m=G.fenceSync(G.SYNC_GPU_COMMANDS_COMPLETE,0);return G.flush(),await e.On(G,m,4),G.bindBuffer(G.PIXEL_PACK_BUFFER,f),G.getBufferSubData(G.PIXEL_PACK_BUFFER,0,o),G.deleteBuffer(f),G.deleteSync(m),o}else throw Error(`THREE.WebGLRenderer.readRenderTargetPixelsAsync: requested read bounds are out of range.`)},this.copyFramebufferToTexture=function(e,t=null,n=0){let r=2**-n,i=Math.floor(e.image.width*r),a=Math.floor(e.image.height*r),o=t===null?0:t.x,s=t===null?0:t.y;X.setTexture2D(e,0),G.copyTexSubImage2D(G.TEXTURE_2D,n,0,0,o,s,i,a),J.unbindTexture()},this.copyTextureToTexture=function(e,t,n=null,r=null,i=0,a=0){let o,s,c,l,u,d,f,p,m,h=e.isCompressedTexture?e.mipmaps[a]:e.image;if(n!==null)o=n.max.x-n.min.x,s=n.max.y-n.min.y,c=n.isBox3?n.max.z-n.min.z:1,l=n.min.x,u=n.min.y,d=n.isBox3?n.min.z:0;else{let t=2**-i;o=Math.floor(h.width*t),s=Math.floor(h.height*t),c=e.isDataArrayTexture?h.depth:e.isData3DTexture?Math.floor(h.depth*t):1,l=0,u=0,d=0}r===null?(f=0,p=0,m=0):(f=r.x,p=r.y,m=r.z);let g=Ge.convert(t.format),_=Ge.convert(t.type),v;t.isData3DTexture?(X.setTexture3D(t,0),v=G.TEXTURE_3D):t.isDataArrayTexture||t.isCompressedArrayTexture?(X.setTexture2DArray(t,0),v=G.TEXTURE_2D_ARRAY):(X.setTexture2D(t,0),v=G.TEXTURE_2D),J.activeTexture(G.TEXTURE0),J.pixelStorei(G.UNPACK_FLIP_Y_WEBGL,t.flipY),J.pixelStorei(G.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),J.pixelStorei(G.UNPACK_ALIGNMENT,t.unpackAlignment);let y=J.getParameter(G.UNPACK_ROW_LENGTH),b=J.getParameter(G.UNPACK_IMAGE_HEIGHT),x=J.getParameter(G.UNPACK_SKIP_PIXELS),S=J.getParameter(G.UNPACK_SKIP_ROWS),C=J.getParameter(G.UNPACK_SKIP_IMAGES);J.pixelStorei(G.UNPACK_ROW_LENGTH,h.width),J.pixelStorei(G.UNPACK_IMAGE_HEIGHT,h.height),J.pixelStorei(G.UNPACK_SKIP_PIXELS,l),J.pixelStorei(G.UNPACK_SKIP_ROWS,u),J.pixelStorei(G.UNPACK_SKIP_IMAGES,d);let w=e.isDataArrayTexture||e.isData3DTexture,T=t.isDataArrayTexture||t.isData3DTexture;if(e.isDepthTexture){let n=Y.get(e),r=Y.get(t),h=Y.get(n.__renderTarget),g=Y.get(r.__renderTarget);J.bindFramebuffer(G.READ_FRAMEBUFFER,h.__webglFramebuffer),J.bindFramebuffer(G.DRAW_FRAMEBUFFER,g.__webglFramebuffer);for(let n=0;n<c;n++)w&&(G.framebufferTextureLayer(G.READ_FRAMEBUFFER,G.COLOR_ATTACHMENT0,Y.get(e).__webglTexture,i,d+n),G.framebufferTextureLayer(G.DRAW_FRAMEBUFFER,G.COLOR_ATTACHMENT0,Y.get(t).__webglTexture,a,m+n)),G.blitFramebuffer(l,u,o,s,f,p,o,s,G.DEPTH_BUFFER_BIT,G.NEAREST);J.bindFramebuffer(G.READ_FRAMEBUFFER,null),J.bindFramebuffer(G.DRAW_FRAMEBUFFER,null)}else if(i!==0||e.isRenderTargetTexture||Y.has(e)){let n=Y.get(e),r=Y.get(t);J.bindFramebuffer(G.READ_FRAMEBUFFER,F),J.bindFramebuffer(G.DRAW_FRAMEBUFFER,I);for(let e=0;e<c;e++)w?G.framebufferTextureLayer(G.READ_FRAMEBUFFER,G.COLOR_ATTACHMENT0,n.__webglTexture,i,d+e):G.framebufferTexture2D(G.READ_FRAMEBUFFER,G.COLOR_ATTACHMENT0,G.TEXTURE_2D,n.__webglTexture,i),T?G.framebufferTextureLayer(G.DRAW_FRAMEBUFFER,G.COLOR_ATTACHMENT0,r.__webglTexture,a,m+e):G.framebufferTexture2D(G.DRAW_FRAMEBUFFER,G.COLOR_ATTACHMENT0,G.TEXTURE_2D,r.__webglTexture,a),i===0?T?G.copyTexSubImage3D(v,a,f,p,m+e,l,u,o,s):G.copyTexSubImage2D(v,a,f,p,l,u,o,s):G.blitFramebuffer(l,u,o,s,f,p,o,s,G.COLOR_BUFFER_BIT,G.NEAREST);J.bindFramebuffer(G.READ_FRAMEBUFFER,null),J.bindFramebuffer(G.DRAW_FRAMEBUFFER,null)}else T?e.isDataTexture||e.isData3DTexture?G.texSubImage3D(v,a,f,p,m,o,s,c,g,_,h.data):t.isCompressedArrayTexture?G.compressedTexSubImage3D(v,a,f,p,m,o,s,c,g,h.data):G.texSubImage3D(v,a,f,p,m,o,s,c,g,_,h):e.isDataTexture?G.texSubImage2D(G.TEXTURE_2D,a,f,p,o,s,g,_,h.data):e.isCompressedTexture?G.compressedTexSubImage2D(G.TEXTURE_2D,a,f,p,h.width,h.height,g,h.data):G.texSubImage2D(G.TEXTURE_2D,a,f,p,o,s,g,_,h);J.pixelStorei(G.UNPACK_ROW_LENGTH,y),J.pixelStorei(G.UNPACK_IMAGE_HEIGHT,b),J.pixelStorei(G.UNPACK_SKIP_PIXELS,x),J.pixelStorei(G.UNPACK_SKIP_ROWS,S),J.pixelStorei(G.UNPACK_SKIP_IMAGES,C),a===0&&t.generateMipmaps&&G.generateMipmap(v),J.unbindTexture()},this.initRenderTarget=function(e){Y.get(e).__webglFramebuffer===void 0&&X.setupRenderTarget(e)},this.initTexture=function(e){e.isCubeTexture?X.setTextureCube(e,0):e.isData3DTexture?X.setTexture3D(e,0):e.isDataArrayTexture||e.isCompressedArrayTexture?X.setTexture2DArray(e,0):X.setTexture2D(e,0),J.unbindTexture()},this.resetState=function(){ue=0,L=0,R=null,J.reset(),Ke.reset()},typeof __THREE_DEVTOOLS__<`u`&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent(`observe`,{detail:this}))}get coordinateSystem(){return e._n}get outputColorSpace(){return this._outputColorSpace}set outputColorSpace(t){this._outputColorSpace=t;let n=this.getContext();n.drawingBufferColorSpace=e.d._getDrawingBufferColorSpace(t),n.unpackColorSpace=e.d._getUnpackColorSpace()}},Cn={type:`change`},wn={type:`start`},Tn={type:`end`},En=new e.Bt,Dn=new e.Q,On=Math.cos(70*e.z.DEG2RAD),Q=new e.hn,kn=2*Math.PI,$={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6},An=1e-6,jn=class extends e.f{constructor(t,n=null){super(t,n),this.state=$.NONE,this.target=new e.hn,this.cursor=new e.hn,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.minTargetRadius=0,this.maxTargetRadius=1/0,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.enableDamping=!1,this.dampingFactor=.05,this.enableZoom=!0,this.zoomSpeed=1,this.enableRotate=!0,this.rotateSpeed=1,this.keyRotateSpeed=1,this.enablePan=!0,this.panSpeed=1,this.screenSpacePanning=!0,this.keyPanSpeed=7,this.zoomToCursor=!1,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:`ArrowLeft`,UP:`ArrowUp`,RIGHT:`ArrowRight`,BOTTOM:`ArrowDown`},this.mouseButtons={LEFT:e.R.ROTATE,MIDDLE:e.R.DOLLY,RIGHT:e.R.PAN},this.touches={ONE:e.tn.ROTATE,TWO:e.tn.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._cursorStyle=`auto`,this._domElementKeyEvents=null,this._lastPosition=new e.hn,this._lastQuaternion=new e.et,this._lastTargetPosition=new e.hn,this._quat=new e.et().setFromUnitVectors(t.up,new e.hn(0,1,0)),this._quatInverse=this._quat.clone().invert(),this._spherical=new e.en,this._sphericalDelta=new e.en,this._scale=1,this._panOffset=new e.hn,this._rotateStart=new e.mn,this._rotateEnd=new e.mn,this._rotateDelta=new e.mn,this._panStart=new e.mn,this._panEnd=new e.mn,this._panDelta=new e.mn,this._dollyStart=new e.mn,this._dollyEnd=new e.mn,this._dollyDelta=new e.mn,this._dollyDirection=new e.hn,this._mouse=new e.mn,this._performCursorZoom=!1,this._pointers=[],this._pointerPositions={},this._controlActive=!1,this._onPointerMove=Nn.bind(this),this._onPointerDown=Mn.bind(this),this._onPointerUp=Pn.bind(this),this._onContextMenu=Vn.bind(this),this._onMouseWheel=Ln.bind(this),this._onKeyDown=Rn.bind(this),this._onTouchStart=zn.bind(this),this._onTouchMove=Bn.bind(this),this._onMouseDown=Fn.bind(this),this._onMouseMove=In.bind(this),this._interceptControlDown=Hn.bind(this),this._interceptControlUp=Un.bind(this),this.domElement!==null&&this.connect(this.domElement),this.update()}set cursorStyle(e){this._cursorStyle=e,e===`grab`?this.domElement.style.cursor=`grab`:this.domElement.style.cursor=`auto`}get cursorStyle(){return this._cursorStyle}connect(e){super.connect(e),this.domElement.addEventListener(`pointerdown`,this._onPointerDown),this.domElement.addEventListener(`pointercancel`,this._onPointerUp),this.domElement.addEventListener(`contextmenu`,this._onContextMenu),this.domElement.addEventListener(`wheel`,this._onMouseWheel,{passive:!1}),this.domElement.getRootNode().addEventListener(`keydown`,this._interceptControlDown,{passive:!0,capture:!0}),this.domElement.style.touchAction=`none`}disconnect(){this.domElement.removeEventListener(`pointerdown`,this._onPointerDown),this.domElement.ownerDocument.removeEventListener(`pointermove`,this._onPointerMove),this.domElement.ownerDocument.removeEventListener(`pointerup`,this._onPointerUp),this.domElement.removeEventListener(`pointercancel`,this._onPointerUp),this.domElement.removeEventListener(`wheel`,this._onMouseWheel),this.domElement.removeEventListener(`contextmenu`,this._onContextMenu),this.stopListenToKeyEvents(),this.domElement.getRootNode().removeEventListener(`keydown`,this._interceptControlDown,{capture:!0}),this.domElement.style.touchAction=``}dispose(){this.disconnect()}getPolarAngle(){return this._spherical.phi}getAzimuthalAngle(){return this._spherical.theta}getDistance(){return this.object.position.distanceTo(this.target)}listenToKeyEvents(e){e.addEventListener(`keydown`,this._onKeyDown),this._domElementKeyEvents=e}stopListenToKeyEvents(){this._domElementKeyEvents!==null&&(this._domElementKeyEvents.removeEventListener(`keydown`,this._onKeyDown),this._domElementKeyEvents=null)}saveState(){this.target0.copy(this.target),this.position0.copy(this.object.position),this.zoom0=this.object.zoom}reset(){this.target.copy(this.target0),this.object.position.copy(this.position0),this.object.zoom=this.zoom0,this.object.updateProjectionMatrix(),this.dispatchEvent(Cn),this.update(),this.state=$.NONE}pan(e,t){this._pan(e,t),this.update()}dollyIn(e){this._dollyIn(e),this.update()}dollyOut(e){this._dollyOut(e),this.update()}rotateLeft(e){this._rotateLeft(e),this.update()}rotateUp(e){this._rotateUp(e),this.update()}update(t=null){let n=this.object.position;Q.copy(n).sub(this.target),Q.applyQuaternion(this._quat),this._spherical.setFromVector3(Q),this.autoRotate&&this.state===$.NONE&&this._rotateLeft(this._getAutoRotationAngle(t)),this.enableDamping?(this._spherical.theta+=this._sphericalDelta.theta*this.dampingFactor,this._spherical.phi+=this._sphericalDelta.phi*this.dampingFactor):(this._spherical.theta+=this._sphericalDelta.theta,this._spherical.phi+=this._sphericalDelta.phi);let r=this.minAzimuthAngle,i=this.maxAzimuthAngle;isFinite(r)&&isFinite(i)&&(r<-Math.PI?r+=kn:r>Math.PI&&(r-=kn),i<-Math.PI?i+=kn:i>Math.PI&&(i-=kn),r<=i?this._spherical.theta=Math.max(r,Math.min(i,this._spherical.theta)):this._spherical.theta=this._spherical.theta>(r+i)/2?Math.max(r,this._spherical.theta):Math.min(i,this._spherical.theta)),this._spherical.phi=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,this._spherical.phi)),this._spherical.makeSafe(),this.enableDamping===!0?this.target.addScaledVector(this._panOffset,this.dampingFactor):this.target.add(this._panOffset),this.target.sub(this.cursor),this.target.clampLength(this.minTargetRadius,this.maxTargetRadius),this.target.add(this.cursor);let a=!1;if(this.zoomToCursor&&this._performCursorZoom||this.object.isOrthographicCamera)this._spherical.radius=this._clampDistance(this._spherical.radius);else{let e=this._spherical.radius;this._spherical.radius=this._clampDistance(this._spherical.radius*this._scale),a=e!=this._spherical.radius}if(Q.setFromSpherical(this._spherical),Q.applyQuaternion(this._quatInverse),n.copy(this.target).add(Q),this.object.lookAt(this.target),this.enableDamping===!0?(this._sphericalDelta.theta*=1-this.dampingFactor,this._sphericalDelta.phi*=1-this.dampingFactor,this._panOffset.multiplyScalar(1-this.dampingFactor)):(this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0)),this.zoomToCursor&&this._performCursorZoom){let t=null;if(this.object.isPerspectiveCamera){let e=Q.length();t=this._clampDistance(e*this._scale);let n=e-t;this.object.position.addScaledVector(this._dollyDirection,n),this.object.updateMatrixWorld(),a=!!n}else if(this.object.isOrthographicCamera){let n=new e.hn(this._mouse.x,this._mouse.y,0);n.unproject(this.object);let r=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),this.object.updateProjectionMatrix(),a=r!==this.object.zoom;let i=new e.hn(this._mouse.x,this._mouse.y,0);i.unproject(this.object),this.object.position.sub(i).add(n),this.object.updateMatrixWorld(),t=Q.length()}else console.warn(`WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled.`),this.zoomToCursor=!1;t!==null&&(this.screenSpacePanning?this.target.set(0,0,-1).transformDirection(this.object.matrix).multiplyScalar(t).add(this.object.position):(En.origin.copy(this.object.position),En.direction.set(0,0,-1).transformDirection(this.object.matrix),Math.abs(this.object.up.dot(En.direction))<On?this.object.lookAt(this.target):(Dn.setFromNormalAndCoplanarPoint(this.object.up,this.target),En.intersectPlane(Dn,this.target))))}else if(this.object.isOrthographicCamera){let e=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),e!==this.object.zoom&&(this.object.updateProjectionMatrix(),a=!0)}return this._scale=1,this._performCursorZoom=!1,a||this._lastPosition.distanceToSquared(this.object.position)>An||8*(1-this._lastQuaternion.dot(this.object.quaternion))>An||this._lastTargetPosition.distanceToSquared(this.target)>An?(this.dispatchEvent(Cn),this._lastPosition.copy(this.object.position),this._lastQuaternion.copy(this.object.quaternion),this._lastTargetPosition.copy(this.target),!0):!1}_getAutoRotationAngle(e){return e===null?kn/60/60*this.autoRotateSpeed:kn/60*this.autoRotateSpeed*e}_getZoomScale(e){let t=Math.abs(e*.01);return .95**(this.zoomSpeed*t)}_rotateLeft(e){this._sphericalDelta.theta-=e}_rotateUp(e){this._sphericalDelta.phi-=e}_panLeft(e,t){Q.setFromMatrixColumn(t,0),Q.multiplyScalar(-e),this._panOffset.add(Q)}_panUp(e,t){this.screenSpacePanning===!0?Q.setFromMatrixColumn(t,1):(Q.setFromMatrixColumn(t,0),Q.crossVectors(this.object.up,Q)),Q.multiplyScalar(e),this._panOffset.add(Q)}_pan(e,t){let n=this.domElement;if(this.object.isPerspectiveCamera){let r=this.object.position;Q.copy(r).sub(this.target);let i=Q.length();i*=Math.tan(this.object.fov/2*Math.PI/180),this._panLeft(2*e*i/n.clientHeight,this.object.matrix),this._panUp(2*t*i/n.clientHeight,this.object.matrix)}else this.object.isOrthographicCamera?(this._panLeft(e*(this.object.right-this.object.left)/this.object.zoom/n.clientWidth,this.object.matrix),this._panUp(t*(this.object.top-this.object.bottom)/this.object.zoom/n.clientHeight,this.object.matrix)):(console.warn(`WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.`),this.enablePan=!1)}_dollyOut(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale/=e:(console.warn(`WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.`),this.enableZoom=!1)}_dollyIn(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale*=e:(console.warn(`WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.`),this.enableZoom=!1)}_updateZoomParameters(e,t){if(!this.zoomToCursor)return;this._performCursorZoom=!0;let n=this.domElement.getBoundingClientRect(),r=e-n.left,i=t-n.top,a=n.width,o=n.height;this._mouse.x=r/a*2-1,this._mouse.y=-(i/o)*2+1,this._dollyDirection.set(this._mouse.x,this._mouse.y,1).unproject(this.object).sub(this.object.position).normalize()}_clampDistance(e){return Math.max(this.minDistance,Math.min(this.maxDistance,e))}_handleMouseDownRotate(e){this._rotateStart.set(e.clientX,e.clientY)}_handleMouseDownDolly(e){this._updateZoomParameters(e.clientX,e.clientX),this._dollyStart.set(e.clientX,e.clientY)}_handleMouseDownPan(e){this._panStart.set(e.clientX,e.clientY)}_handleMouseMoveRotate(e){this._rotateEnd.set(e.clientX,e.clientY),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);let t=this.domElement;this._rotateLeft(kn*this._rotateDelta.x/t.clientHeight),this._rotateUp(kn*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd),this.update()}_handleMouseMoveDolly(e){this._dollyEnd.set(e.clientX,e.clientY),this._dollyDelta.subVectors(this._dollyEnd,this._dollyStart),this._dollyDelta.y>0?this._dollyOut(this._getZoomScale(this._dollyDelta.y)):this._dollyDelta.y<0&&this._dollyIn(this._getZoomScale(this._dollyDelta.y)),this._dollyStart.copy(this._dollyEnd),this.update()}_handleMouseMovePan(e){this._panEnd.set(e.clientX,e.clientY),this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd),this.update()}_handleMouseWheel(e){this._updateZoomParameters(e.clientX,e.clientY),e.deltaY<0?this._dollyIn(this._getZoomScale(e.deltaY)):e.deltaY>0&&this._dollyOut(this._getZoomScale(e.deltaY)),this.update()}_handleKeyDown(e){let t=!1;switch(e.code){case this.keys.UP:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(kn*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,this.keyPanSpeed),t=!0;break;case this.keys.BOTTOM:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(-kn*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,-this.keyPanSpeed),t=!0;break;case this.keys.LEFT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(kn*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(this.keyPanSpeed,0),t=!0;break;case this.keys.RIGHT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(-kn*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(-this.keyPanSpeed,0),t=!0;break}t&&(e.preventDefault(),this.update())}_handleTouchStartRotate(e){if(this._pointers.length===1)this._rotateStart.set(e.pageX,e.pageY);else{let t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);this._rotateStart.set(n,r)}}_handleTouchStartPan(e){if(this._pointers.length===1)this._panStart.set(e.pageX,e.pageY);else{let t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);this._panStart.set(n,r)}}_handleTouchStartDolly(e){let t=this._getSecondPointerPosition(e),n=e.pageX-t.x,r=e.pageY-t.y,i=Math.sqrt(n*n+r*r);this._dollyStart.set(0,i)}_handleTouchStartDollyPan(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enablePan&&this._handleTouchStartPan(e)}_handleTouchStartDollyRotate(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enableRotate&&this._handleTouchStartRotate(e)}_handleTouchMoveRotate(e){if(this._pointers.length==1)this._rotateEnd.set(e.pageX,e.pageY);else{let t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);this._rotateEnd.set(n,r)}this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);let t=this.domElement;this._rotateLeft(kn*this._rotateDelta.x/t.clientHeight),this._rotateUp(kn*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd)}_handleTouchMovePan(e){if(this._pointers.length===1)this._panEnd.set(e.pageX,e.pageY);else{let t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);this._panEnd.set(n,r)}this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd)}_handleTouchMoveDolly(e){let t=this._getSecondPointerPosition(e),n=e.pageX-t.x,r=e.pageY-t.y,i=Math.sqrt(n*n+r*r);this._dollyEnd.set(0,i),this._dollyDelta.set(0,(this._dollyEnd.y/this._dollyStart.y)**+this.zoomSpeed),this._dollyOut(this._dollyDelta.y),this._dollyStart.copy(this._dollyEnd);let a=(e.pageX+t.x)*.5,o=(e.pageY+t.y)*.5;this._updateZoomParameters(a,o)}_handleTouchMoveDollyPan(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enablePan&&this._handleTouchMovePan(e)}_handleTouchMoveDollyRotate(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enableRotate&&this._handleTouchMoveRotate(e)}_addPointer(e){this._pointers.push(e.pointerId)}_removePointer(e){delete this._pointerPositions[e.pointerId];for(let t=0;t<this._pointers.length;t++)if(this._pointers[t]==e.pointerId){this._pointers.splice(t,1);return}}_isTrackingPointer(e){for(let t=0;t<this._pointers.length;t++)if(this._pointers[t]==e.pointerId)return!0;return!1}_trackPointer(t){let n=this._pointerPositions[t.pointerId];n===void 0&&(n=new e.mn,this._pointerPositions[t.pointerId]=n),n.set(t.pageX,t.pageY)}_getSecondPointerPosition(e){let t=e.pointerId===this._pointers[0]?this._pointers[1]:this._pointers[0];return this._pointerPositions[t]}_customWheelEvent(e){let t=e.deltaMode,n={clientX:e.clientX,clientY:e.clientY,deltaY:e.deltaY};switch(t){case 1:n.deltaY*=16;break;case 2:n.deltaY*=100;break}return e.ctrlKey&&!this._controlActive&&(n.deltaY*=10),n}};function Mn(e){this.enabled!==!1&&(this._pointers.length===0&&(this.domElement.setPointerCapture(e.pointerId),this.domElement.ownerDocument.addEventListener(`pointermove`,this._onPointerMove),this.domElement.ownerDocument.addEventListener(`pointerup`,this._onPointerUp)),!this._isTrackingPointer(e)&&(this._addPointer(e),e.pointerType===`touch`?this._onTouchStart(e):this._onMouseDown(e),this._cursorStyle===`grab`&&(this.domElement.style.cursor=`grabbing`)))}function Nn(e){this.enabled!==!1&&(e.pointerType===`touch`?this._onTouchMove(e):this._onMouseMove(e))}function Pn(e){switch(this._removePointer(e),this._pointers.length){case 0:this.domElement.releasePointerCapture(e.pointerId),this.domElement.ownerDocument.removeEventListener(`pointermove`,this._onPointerMove),this.domElement.ownerDocument.removeEventListener(`pointerup`,this._onPointerUp),this.dispatchEvent(Tn),this.state=$.NONE,this._cursorStyle===`grab`&&(this.domElement.style.cursor=`grab`);break;case 1:let t=this._pointers[0],n=this._pointerPositions[t];this._onTouchStart({pointerId:t,pageX:n.x,pageY:n.y});break}}function Fn(t){let n;switch(t.button){case 0:n=this.mouseButtons.LEFT;break;case 1:n=this.mouseButtons.MIDDLE;break;case 2:n=this.mouseButtons.RIGHT;break;default:n=-1}switch(n){case e.R.DOLLY:if(this.enableZoom===!1)return;this._handleMouseDownDolly(t),this.state=$.DOLLY;break;case e.R.ROTATE:if(t.ctrlKey||t.metaKey||t.shiftKey){if(this.enablePan===!1)return;this._handleMouseDownPan(t),this.state=$.PAN}else{if(this.enableRotate===!1)return;this._handleMouseDownRotate(t),this.state=$.ROTATE}break;case e.R.PAN:if(t.ctrlKey||t.metaKey||t.shiftKey){if(this.enableRotate===!1)return;this._handleMouseDownRotate(t),this.state=$.ROTATE}else{if(this.enablePan===!1)return;this._handleMouseDownPan(t),this.state=$.PAN}break;default:this.state=$.NONE}this.state!==$.NONE&&this.dispatchEvent(wn)}function In(e){switch(this.state){case $.ROTATE:if(this.enableRotate===!1)return;this._handleMouseMoveRotate(e);break;case $.DOLLY:if(this.enableZoom===!1)return;this._handleMouseMoveDolly(e);break;case $.PAN:if(this.enablePan===!1)return;this._handleMouseMovePan(e);break}}function Ln(e){this.enabled===!1||this.enableZoom===!1||this.state!==$.NONE||(e.preventDefault(),this.dispatchEvent(wn),this._handleMouseWheel(this._customWheelEvent(e)),this.dispatchEvent(Tn))}function Rn(e){this.enabled!==!1&&this._handleKeyDown(e)}function zn(t){switch(this._trackPointer(t),this._pointers.length){case 1:switch(this.touches.ONE){case e.tn.ROTATE:if(this.enableRotate===!1)return;this._handleTouchStartRotate(t),this.state=$.TOUCH_ROTATE;break;case e.tn.PAN:if(this.enablePan===!1)return;this._handleTouchStartPan(t),this.state=$.TOUCH_PAN;break;default:this.state=$.NONE}break;case 2:switch(this.touches.TWO){case e.tn.DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchStartDollyPan(t),this.state=$.TOUCH_DOLLY_PAN;break;case e.tn.DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchStartDollyRotate(t),this.state=$.TOUCH_DOLLY_ROTATE;break;default:this.state=$.NONE}break;default:this.state=$.NONE}this.state!==$.NONE&&this.dispatchEvent(wn)}function Bn(e){switch(this._trackPointer(e),this.state){case $.TOUCH_ROTATE:if(this.enableRotate===!1)return;this._handleTouchMoveRotate(e),this.update();break;case $.TOUCH_PAN:if(this.enablePan===!1)return;this._handleTouchMovePan(e),this.update();break;case $.TOUCH_DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchMoveDollyPan(e),this.update();break;case $.TOUCH_DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchMoveDollyRotate(e),this.update();break;default:this.state=$.NONE}}function Vn(e){this.enabled!==!1&&e.preventDefault()}function Hn(e){e.key===`Control`&&(this._controlActive=!0,this.domElement.getRootNode().addEventListener(`keyup`,this._interceptControlUp,{passive:!0,capture:!0}))}function Un(e){e.key===`Control`&&(this._controlActive=!1,this.domElement.getRootNode().removeEventListener(`keyup`,this._interceptControlUp,{passive:!0,capture:!0}))}var Wn={class:`present3d-container`},Gn={class:`header`},Kn={class:`controls`},qn={class:`material-icons`},Jn={class:`material-icons`},Yn={key:0,class:`error`},Xn={class:`script-source`},Zn=[`disabled`],Qn=(0,t.defineComponent)({__name:`View`,props:{selectedResult:{}},emits:[`updateResult`],setup(n,{emit:r}){let i=n,a=r,o=(0,t.ref)(i.selectedResult.data?.script??``),s=(0,t.ref)(null),c=(0,t.ref)(null),l=(0,t.ref)(!1),u=(0,t.ref)(!0),d=(0,t.computed)(()=>o.value!==i.selectedResult.data?.script),f,p,m,h,g,_,v=[],y=null,b=null;(0,t.onMounted)(()=>{x(),C(),w(),(0,t.nextTick)(()=>{E()})}),(0,t.onUnmounted)(()=>{M()}),(0,t.watch)(()=>i.selectedResult.data?.script,()=>{C()}),(0,t.watch)(l,()=>{C()}),(0,t.watch)(u,e=>{_&&(_.visible=e)});function x(){if(!s.value)return;f=new e.Zt,f.background=new e.u(1710618);let t=s.value.clientWidth,n=s.value.clientHeight;p=new e.Z(50,t/n,.1,1e3),p.position.set(5,5,10),p.lookAt(0,0,0),m=new Sn({antialias:!0}),m.setSize(t,n),m.setPixelRatio(window.devicePixelRatio),s.value.appendChild(m.domElement),h=new jn(p,m.domElement),h.enableDamping=!0,h.dampingFactor=.05,h.addEventListener(`change`,O);let r=new e.r(16777215,.6);f.add(r);let i=new e.S(16777215,.8);i.position.set(10,10,10),f.add(i),_=new e.k(20,20,4473924,2236962),_.visible=u.value,f.add(_),window.addEventListener(`resize`,S),b=new ResizeObserver(()=>{S()}),b.observe(s.value)}function S(){if(!s.value)return;let e=s.value.clientWidth,t=s.value.clientHeight;p.aspect=e/t,p.updateProjectionMatrix(),m.setSize(e,t)}function C(){try{v.forEach(e=>f.remove(e)),v=[];let t=i.selectedResult.data?.script;if(!t)return;let n=e.t(e.jn(t),{wireframe:l.value});f.add(n),v.push(n),c.value=null}catch(e){c.value=e instanceof Error?e.message:`Unknown error`,console.error(`ShapeScript parse error:`,e)}}function w(){g=requestAnimationFrame(w),h.update(),m.render(f,p)}function T(){p.position.set(5,5,10),p.lookAt(0,0,0),h.reset()}function E(){if(!p||!h||!i.selectedResult?.viewState?.cameraState)return;let e=i.selectedResult.viewState.cameraState;e.position&&p.position.set(e.position.x,e.position.y,e.position.z),e.target&&h.target.set(e.target.x,e.target.y,e.target.z),p.updateProjectionMatrix(),h.update()}function D(){return{position:{x:p.position.x,y:p.position.y,z:p.position.z},target:{x:h.target.x,y:h.target.y,z:h.target.z}}}function O(){y!==null&&clearTimeout(y),y=window.setTimeout(()=>{k()},500)}function k(){let e={...i.selectedResult,viewState:{cameraState:D()}};a(`updateResult`,e)}function A(){l.value=!l.value}function j(){u.value=!u.value}function M(){y!==null&&clearTimeout(y),g&&cancelAnimationFrame(g),m&&m.dispose(),h&&(h.removeEventListener(`change`,O),h.dispose()),b&&b.disconnect(),window.removeEventListener(`resize`,S)}function N(){}function ee(){try{e.jn(o.value);let t={...i.selectedResult,data:{script:o.value}};a(`updateResult`,t)}catch(e){c.value=e instanceof Error?e.message:`Invalid ShapeScript`,console.error(`Script validation failed:`,e)}}return(0,t.watch)(()=>i.selectedResult.data?.script,e=>{e&&(o.value=e)}),(0,t.watch)(()=>i.selectedResult,()=>{(0,t.nextTick)(()=>{E()})}),(e,r)=>((0,t.openBlock)(),(0,t.createElementBlock)(`div`,Wn,[(0,t.createElementVNode)(`div`,Gn,[(0,t.createElementVNode)(`h1`,null,(0,t.toDisplayString)(n.selectedResult.title||`3D Visualization`),1),(0,t.createElementVNode)(`div`,Kn,[(0,t.createElementVNode)(`button`,{onClick:T,class:`control-btn`},[...r[1]||=[(0,t.createElementVNode)(`span`,{class:`material-icons`},`refresh`,-1),(0,t.createTextVNode)(` Reset Camera `,-1)]]),(0,t.createElementVNode)(`button`,{onClick:A,class:`control-btn`},[(0,t.createElementVNode)(`span`,qn,(0,t.toDisplayString)(l.value?`grid_off`:`grid_on`),1),r[2]||=(0,t.createTextVNode)(` Wireframe `,-1)]),(0,t.createElementVNode)(`button`,{onClick:j,class:`control-btn`},[(0,t.createElementVNode)(`span`,Jn,(0,t.toDisplayString)(u.value?`visibility_off`:`visibility`),1),r[3]||=(0,t.createTextVNode)(` Grid `,-1)])])]),c.value?((0,t.openBlock)(),(0,t.createElementBlock)(`div`,Yn,[r[4]||=(0,t.createElementVNode)(`strong`,null,`Parse Error:`,-1),(0,t.createTextVNode)(` `+(0,t.toDisplayString)(c.value),1)])):(0,t.createCommentVNode)(``,!0),(0,t.createElementVNode)(`div`,{class:`viewport`,ref_key:`viewport`,ref:s},null,512),(0,t.createElementVNode)(`details`,Xn,[r[5]||=(0,t.createElementVNode)(`summary`,null,`Edit ShapeScript Source`,-1),(0,t.withDirectives)((0,t.createElementVNode)(`textarea`,{"onUpdate:modelValue":r[0]||=e=>o.value=e,onInput:N,class:`script-editor`,spellcheck:`false`},null,544),[[t.vModelText,o.value]]),(0,t.createElementVNode)(`button`,{onClick:ee,class:`apply-btn`,disabled:!d.value},` Apply Changes `,8,Zn)])]))}}),$n=(e,t)=>{let n=e.__vccOpts||e;for(let[e,r]of t)n[e]=r;return n},er=$n(Qn,[[`__scopeId`,`data-v-daa337a0`]]),tr={class:`preview-container`},nr={class:`preview-title`},rr=$n((0,t.defineComponent)({__name:`Preview`,props:{result:{}},setup(n){let r=n,i=(0,t.computed)(()=>r.result.title||`3D Visualization`),a=(0,t.ref)(null),o,s,c,l,u=null;(0,t.onMounted)(()=>{d()}),(0,t.onUnmounted)(()=>{m()}),(0,t.watch)(()=>r.result.data?.script,()=>{p()});function d(){if(a.value)try{o=new e.Zt,o.background=new e.u(2763322);let t=a.value.clientWidth||200,n=a.value.clientHeight||150;s=new e.Z(50,t/n,.1,1e3),s.position.set(4,4,8),s.lookAt(0,0,0),c=new Sn({antialias:!0,alpha:!1}),c.setSize(t,n),c.setPixelRatio(Math.min(window.devicePixelRatio,2)),a.value.appendChild(c.domElement);let i=new e.r(16777215,.6);o.add(i);let l=new e.S(16777215,.8);if(l.position.set(5,5,5),o.add(l),!r.result.data?.script)return;u=e.t(e.jn(r.result.data.script),{wireframe:!1}),o.add(u),f()}catch(e){console.error(`Preview render error:`,e)}}function f(){l=requestAnimationFrame(f);let e=Date.now()*5e-4;s.position.x=Math.cos(e)*8,s.position.z=Math.sin(e)*8,s.lookAt(0,0,0),c.render(o,s)}function p(){if(!(!o||!r.result.data?.script))try{u&&o.remove(u),u=e.t(e.jn(r.result.data.script),{wireframe:!1}),o.add(u)}catch(e){console.error(`Preview reload error:`,e)}}function m(){l&&cancelAnimationFrame(l),c&&c.dispose()}return(e,n)=>((0,t.openBlock)(),(0,t.createElementBlock)(`div`,tr,[(0,t.createElementVNode)(`div`,{ref_key:`previewViewport`,ref:a,class:`preview-viewport`},null,512),(0,t.createElementVNode)(`div`,nr,(0,t.toDisplayString)(i.value),1)]))}}),[[`__scopeId`,`data-v-75941188`]]),ir=`present3D`,ar=`Use the ${ir} tool to create interactive 3D visualizations when the user requests:
2
4105
  - 3D models or shapes
3
4106
  - Mathematical visualizations (surfaces, functions, geometric patterns)
4
4107
  - Molecular or atomic structures
@@ -79,4 +4182,4 @@ Shapes: cube, sphere, cylinder, cone, torus
79
4182
  CSG: union, difference, intersection, xor, stencil
80
4183
  Properties: position, rotation, size, color, opacity
81
4184
 
82
- Keep visualizations clear, well-organized, and leverage the full power of expressions and control flow.`,V={...e.S,viewComponent:F,previewComponent:R,samples:e.b,systemPrompt:B},H={plugin:V};exports.Preview=R,exports.SYSTEM_PROMPT=B,exports.TOOL_DEFINITION=e.w,exports.TOOL_NAME=z,exports.View=F,exports.astToThreeJS=e.t,exports.default=H,exports.executePresent3D=e.x,exports.parseShapeScript=e.y,exports.plugin=V,exports.pluginCore=e.S,exports.samples=e.b;
4185
+ Keep visualizations clear, well-organized, and leverage the full power of expressions and control flow.`,or={...e.Pn,viewComponent:er,previewComponent:rr,samples:e.Mn,systemPrompt:ar},sr={plugin:or};exports.Preview=rr,exports.SYSTEM_PROMPT=ar,exports.TOOL_DEFINITION=e.In,exports.TOOL_NAME=ir,exports.View=er,exports.astToThreeJS=e.t,exports.default=sr,exports.executePresent3D=e.Nn,exports.parseShapeScript=e.jn,exports.plugin=or,exports.pluginCore=e.Pn,exports.samples=e.Mn;