2026-03-13 23:00:08 -07:00
import { n as e } from "./chunk-DECur_0Z.js" ; var t = { LEFT : 0 , MIDDLE : 1 , RIGHT : 2 , ROTATE : 0 , DOLLY : 1 , PAN : 2 } , n = { ROTATE : 0 , PAN : 1 , DOLLY _PAN : 2 , DOLLY _ROTATE : 3 } , r = ` attached ` , i = ` detached ` , a = 1e3 , o = 1001 , s = 1002 , c = 1003 , l = 1004 , u = 1004 , d = 1005 , f = 1005 , p = 1006 , m = 1007 , h = 1007 , g = 1008 , _ = 1008 , v = 1009 , y = 1010 , b = 1011 , x = 1012 , S = 1013 , C = 1014 , w = 1015 , T = 1016 , E = 1017 , D = 1018 , ee = 1020 , O = 35902 , k = 35899 , A = 1021 , j = 1022 , M = 1023 , te = 1026 , ne = 1027 , N = 1028 , re = 1029 , ie = 1030 , ae = 1031 , oe = 1032 , se = 1033 , ce = 33776 , le = 33777 , P = 33778 , ue = 33779 , de = 35840 , fe = 35841 , pe = 35842 , me = 35843 , he = 36196 , ge = 37492 , _e = 37496 , ve = 37488 , ye = 37489 , be = 37490 , xe = 37491 , Se = 37808 , Ce = 37809 , we = 37810 , Te = 37811 , Ee = 37812 , De = 37813 , Oe = 37814 , F = 37815 , ke = 37816 , Ae = 37817 , je = 37818 , I = 37819 , Me = 37820 , L = 37821 , R = 36492 , Ne = 36494 , Pe = 36495 , Fe = 36283 , Ie = 36284 , Le = 36285 , Re = 36286 , ze = 2200 , Be = 2201 , Ve = 2202 , He = 2300 , Ue = 2301 , We = 2302 , Ge = 2400 , Ke = 2401 , qe = 2402 , Je = 2500 , Ye = 2501 , Xe = 3200 , Ze = 3201 , Qe = 3202 , $e = 3203 , et = ` srgb ` , tt = ` srgb-linear ` , nt = ` linear ` , rt = ` srgb ` , it = 7680 , at = 7681 , ot = 7682 , st = 7683 , ct = 34055 , lt = 34056 , ut = 5386 , dt = 35044 , ft = 35048 , pt = 35040 , mt = 35045 , ht = 35049 , gt = 35041 , _t = 35046 , vt = 35050 , yt = 35042 , bt = ` 300 es ` , xt = 2e3 , St = 2001 , Ct = { COMPUTE : ` compute ` , RENDER : ` render ` } , wt = { PERSPECTIVE : ` perspective ` , LINEAR : ` linear ` , FLAT : ` flat ` } , Tt = { NORMAL : ` normal ` , CENTROID : ` centroid ` , SAMPLE : ` sample ` , FIRST : ` first ` , EITHER : ` either ` } ; function Et ( e ) { for ( let t = e . length - 1 ; t >= 0 ; -- t ) if ( e [ t ] >= 65535 ) return ! 0 ; return ! 1 } var Dt = { Int8Array , Uint8Array , Uint8ClampedArray , Int16Array , Uint16Array , Int32Array , Uint32Array , Float32Array , Float64Array } ; function Ot ( e , t ) { return new Dt [ e ] ( t ) } function kt ( e ) { return ArrayBuffer . isView ( e ) && ! ( e instanceof DataView ) } function At ( e ) { return document . createElementNS ( ` http://www.w3.org/1999/xhtml ` , e ) } function jt ( ) { let e = At ( ` canvas ` ) ; return e . style . display = ` block ` , e } var Mt = { } , Nt = null ; function Pt ( e ) { Nt = e } function Ft ( ) { return Nt } function It ( ... e ) { let t = ` THREE. ` + e . shift ( ) ; Nt ? Nt ( ` log ` , t , ... e ) : console . log ( t , ... e ) } function z ( ... e ) { let t = ` THREE. ` + e . shift ( ) ; Nt ? Nt ( ` warn ` , t , ... e ) : console . warn ( t , ... e ) } function B ( ... e ) { let t = ` THREE. ` + e . shift ( ) ; Nt ? Nt ( ` error ` , t , ... e ) : console . error ( t , ... e ) } function Lt ( ... e ) { let t = e . join ( ` ` ) ; t in Mt || ( Mt [ t ] = ! 0 , z ( ... e ) ) } function Rt ( e , t , n ) { return new Promise ( function ( r , i ) { function a ( ) { switch ( e . clientWaitSync ( t , e . SYNC _FLUSH _COMMANDS _BIT , 0 ) ) { case e . WAIT _FAILED : i ( ) ; break ; case e . TIMEOUT _EXPIRED : setTimeout ( a , n ) ; break ; default : r ( ) } } setTimeout ( a , n ) } ) } var zt = class { addEventListener ( e , t ) { this . _listeners === void 0 && ( this . _listeners = { } ) ; let n = this . _listeners ; n [ e ] === void 0 && ( n [ e ] = [ ] ) , n [ e ] . indexOf ( t ) === - 1 && n [ e ] . push ( t ) } hasEventListener ( e , t ) { let n = this . _listeners ; return n === void 0 ? ! 1 : n [ e ] !== void 0 && n [ e ] . indexOf ( t ) !== - 1 } removeEventListener ( e , t ) { let n = this . _listeners ; if ( n === void 0 ) return ; let r = n [ e ] ; if ( r !== void 0 ) { let e = r . indexOf ( t ) ; e !== - 1 && r . splice ( e , 1 ) } } dispatchEvent ( e ) { let t = this . _listeners ; if ( t === void 0 ) return ; let n = t [ e . type ] ; if ( n !== void 0 ) { e . target = this ; let t = n . slice ( 0 ) ; for ( let n = 0 , r = t . length ; n < r ; n ++ ) t [ n ] . call ( this , e ) ; e . target = null } } } , Bt = ` 00.01.02.03.04.05.06.07.08.09.0a.0b.0c.0d.0e.0f.10.11.12.13.14.15.16.17.18.19.1a.1b.1c.1d.1e.1f.20.21.22.23.24.25.26.27.28.29.2a.2b.2c.2d.2e.2f.30.31.32.33.34.35.36.37.38.39.3a.3b.3c.3d.3e.3f.40.41.42.43.44.45.46.47.48.49.4a.4b.4c.4d.4e.4f.50.51.52.53.54.55.56.57.58.59.5a.5b.5c.5d.5e.5f.60.61.62.63.64.65.66.67.68.69.6a.6b.6c.6d.6e.6f.70.71.72.73.74.75.76.77.78.79.7a.7b.7c.7d.7e.7f.80.81.82.83.84.85.86.87.88.89.8a.8b.8c.8d.8e.8f.90.91.92.93.94.95.96.97.98.99.9a.9b.9c.9d.9e.9f.a0.a1.a2.a3.a4.a5.a6.a7.a8.a9.aa.ab.ac.ad.ae.af.b0.b1.b2.b3.b4.b5.b6.b7.b8.b9.ba.bb.bc.bd.be.bf.c0.c1.c2.c3.c4.c5.c6.c7.c8.c9.ca.cb.cc.cd.ce.cf.d0.d1.d2.d3.d4.d5.d6.d7.d8.d9.da.db.dc.dd.de.df.e0.e1.e2.e3.e4.e5.e6.e7.e8.e9.ea.eb.ec.ed.ee.ef.f0.f1.f2.f3.f4.f5.f6.f7.f8.f9.fa.fb.fc.fd.fe.ff ` . split ( ` . ` ) , Vt = 1234567 , Ht = Math . PI / 180 , Ut = 180 / Math . PI ; function Wt ( ) { let e = Math . random ( ) * 4294967295 | 0 , t = Math . random ( ) * 4294967295 | 0 , n = Math . random ( ) * 4294967295 | 0 , r = Math . random ( ) * 4294967295 | 0 ; return ( Bt [ e & 255 ] + Bt [ e >> 8 & 255 ] + Bt [ e >> 16 & 255 ] + Bt [ e >> 24 & 255 ] + ` - ` + Bt [ t & 255 ] + Bt [ t >> 8 & 255 ] + ` - ` + Bt [ t >> 16 & 15 | 64 ] + Bt [ t >> 24 & 255 ] + ` - ` + Bt [ n & 63 | 128 ] + Bt [ n >> 8 & 255 ] + ` - ` + Bt [ n >> 16 & 255 ] + Bt [ n >> 24 & 255 ] + Bt [ r & 255 ] + Bt [ r >> 8 & 255 ] + Bt [ r >> 16 & 255
gl _Position = projectionMatrix * modelViewMatrix * vec4 ( position , 1.0 ) ;
} ` ,Ji= ` void main ( ) {
gl _FragColor = vec4 ( 1.0 , 0.0 , 0.0 , 1.0 ) ;
} ` ,Yi=class extends ti{constructor(e){super(),this.isShaderMaterial=!0,this.type= ` ShaderMaterial ` ,this.defines={},this.uniforms={},this.uniformsGroups=[],this.vertexShader=qi,this.fragmentShader=Ji,this.linewidth=1,this.wireframe=!1,this.wireframeLinewidth=1,this.fog=!1,this.lights=!1,this.clipping=!1,this.forceSinglePass=!0,this.extensions={clipCullDistance:!1,multiDraw:!1},this.defaultAttributeValues={color:[1,1,1],uv:[0,0],uv1:[0,0]},this.index0AttributeName=void 0,this.uniformsNeedUpdate=!1,this.glslVersion=null,e!==void 0&&this.setValues(e)}copy(e){return super.copy(e),this.fragmentShader=e.fragmentShader,this.vertexShader=e.vertexShader,this.uniforms=Hi(e.uniforms),this.uniformsGroups=Wi(e.uniformsGroups),this.defines=Object.assign({},e.defines),this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.fog=e.fog,this.lights=e.lights,this.clipping=e.clipping,this.extensions=Object.assign({},e.extensions),this.glslVersion=e.glslVersion,this.defaultAttributeValues=Object.assign({},e.defaultAttributeValues),this.index0AttributeName=e.index0AttributeName,this.uniformsNeedUpdate=e.uniformsNeedUpdate,this}toJSON(e){let t=super.toJSON(e);t.glslVersion=this.glslVersion,t.uniforms={};for(let n in this.uniforms){let r=this.uniforms[n].value;r&&r.isTexture?t.uniforms[n]={type: ` t ` ,value:r.toJSON(e).uuid}:r&&r.isColor?t.uniforms[n]={type: ` c ` ,value:r.getHex()}:r&&r.isVector2?t.uniforms[n]={type: ` v2 ` ,value:r.toArray()}:r&&r.isVector3?t.uniforms[n]={type: ` v3 ` ,value:r.toArray()}:r&&r.isVector4?t.uniforms[n]={type: ` v4 ` ,value:r.toArray()}:r&&r.isMatrix3?t.uniforms[n]={type: ` m3 ` ,value:r.toArray()}:r&&r.isMatrix4?t.uniforms[n]={type: ` m4 ` ,value:r.toArray()}:t.uniforms[n]={value:r}}Object.keys(this.defines).length>0&&(t.defines=this.defines),t.vertexShader=this.vertexShader,t.fragmentShader=this.fragmentShader,t.lights=this.lights,t.clipping=this.clipping;let n={};for(let e in this.extensions)this.extensions[e]===!0&&(n[e]=!0);return Object.keys(n).length>0&&(t.extensions=n),t}},Xi=class extends J{constructor(){super(),this.isCamera=!0,this.type= ` Camera ` ,this.matrixWorldInverse=new q,this.projectionMatrix=new q,this.projectionMatrixInverse=new q,this.coordinateSystem=xt,this._reversedDepth=!1}get reversedDepth(){return this._reversedDepth}copy(e,t){return super.copy(e,t),this.matrixWorldInverse.copy(e.matrixWorldInverse),this.projectionMatrix.copy(e.projectionMatrix),this.projectionMatrixInverse.copy(e.projectionMatrixInverse),this.coordinateSystem=e.coordinateSystem,this}getWorldDirection(e){return super.getWorldDirection(e).negate()}updateMatrixWorld(e){super.updateMatrixWorld(e),this.matrixWorldInverse.copy(this.matrixWorld).invert()}updateWorldMatrix(e,t){super.updateWorldMatrix(e,t),this.matrixWorldInverse.copy(this.matrixWorld).invert()}clone(){return new this.constructor().copy(this)}},Zi=new W,Qi=new U, $ i=new U,ea=class extends Xi{constructor(e=50,t=1,n=.1,r=2e3){super(),this.isPerspectiveCamera=!0,this.type= ` PerspectiveCamera ` ,this.fov=e,this.zoom=1,this.near=n,this.far=r,this.focus=10,this.aspect=t,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}copy(e,t){return super.copy(e,t),this.fov=e.fov,this.zoom=e.zoom,this.near=e.near,this.far=e.far,this.focus=e.focus,this.aspect=e.aspect,this.view=e.view===null?null:Object.assign({},e.view),this.filmGauge=e.filmGauge,this.filmOffset=e.filmOffset,this}setFocalLength(e){let t=.5*this.getFilmHeight()/e;this.fov=Ut*2*Math.atan(t),this.updateProjectionMatrix()}getFocalLength(){let e=Math.tan(Ht*.5*this.fov);return .5*this.getFilmHeight()/e}getEffectiveFOV(){return Ut*2*Math.atan(Math.tan(Ht*.5*this.fov)/this.zoom)}getFilmWidth(){return this.filmGauge*Math.min(this.aspect,1)}getFilmHeight(){return this.filmGauge/Math.max(this.aspect,1)}getViewBounds(e,t,n){Zi.set(-1,-1,.5).applyMatrix4(this.projectionMatrixInverse),t.set(Zi.x,Zi.y).multiplyScalar(-e/Zi.z),Zi.set(1,1,.5).applyMatrix4(this.projectionMatrixInverse),n.set(Zi.x,Zi.y).multiplyScalar(-e/Zi.z)}getViewSize(e,t){return this.getViewBounds(e,Qi, $ i),t.subVectors( $ i,Qi)}setViewOffset(e,t
varying vec3 vWorldDirection ;
vec3 transformDirection ( in vec3 dir , in mat4 matrix ) {
return normalize ( ( matrix * vec4 ( dir , 0.0 ) ) . xyz ) ;
}
void main ( ) {
vWorldDirection = transformDirection ( position , modelMatrix ) ;
# include < begin _vertex >
# include < project _vertex >
}
` ,fragmentShader: `
uniform sampler2D tEquirect ;
varying vec3 vWorldDirection ;
# include < common >
void main ( ) {
vec3 direction = normalize ( vWorldDirection ) ;
vec2 sampleUV = equirectUv ( direction ) ;
gl _FragColor = texture2D ( tEquirect , sampleUV ) ;
}
` },r=new Vi(5,5,5),i=new Yi({name: ` CubemapFromEquirect ` ,uniforms:Hi(n.uniforms),vertexShader:n.vertexShader,fragmentShader:n.fragmentShader,side:1,blending:0});i.uniforms.tEquirect.value=t;let a=new Ri(r,i),o=t.minFilter;return t.minFilter===1008&&(t.minFilter=p),new ra(1,10,this).update(e,a),t.minFilter=o,a.geometry.dispose(),a.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)}},oa=class extends J{constructor(){super(),this.isGroup=!0,this.type= ` Group ` }},sa={type: ` move ` },ca=class{constructor(){this._targetRay=null,this._grip=null,this._hand=null}getHandSpace(){return this._hand===null&&(this._hand=new oa,this._hand.matrixAutoUpdate=!1,this._hand.visible=!1,this._hand.joints={},this._hand.inputState={pinching:!1}),this._hand}getTargetRaySpace(){return this._targetRay===null&&(this._targetRay=new oa,this._targetRay.matrixAutoUpdate=!1,this._targetRay.visible=!1,this._targetRay.hasLinearVelocity=!1,this._targetRay.linearVelocity=new W,this._targetRay.hasAngularVelocity=!1,this._targetRay.angularVelocity=new W),this._targetRay}getGripSpace(){return this._grip===null&&(this._grip=new oa,this._grip.matrixAutoUpdate=!1,this._grip.visible=!1,this._grip.hasLinearVelocity=!1,this._grip.linearVelocity=new W,this._grip.hasAngularVelocity=!1,this._grip.angularVelocity=new W),this._grip}dispatchEvent(e){return this._targetRay!==null&&this._targetRay.dispatchEvent(e),this._grip!==null&&this._grip.dispatchEvent(e),this._hand!==null&&this._hand.dispatchEvent(e),this}connect(e){if(e&&e.hand){let t=this._hand;if(t)for(let n of e.hand.values())this._getHandJoint(t,n)}return this.dispatchEvent({type: ` connected ` ,data:e}),this}disconnect(e){return this.dispatchEvent({type: ` disconnected ` ,data:e}),this._targetRay!==null&&(this._targetRay.visible=!1),this._grip!==null&&(this._grip.visible=!1),this._hand!==null&&(this._hand.visible=!1),this}update(e,t,n){let r=null,i=null,a=null,o=this._targetRay,s=this._grip,c=this._hand;if(e&&t.session.visibilityState!== ` visible - blurred ` ){if(c&&e.hand){a=!0;for(let r of e.hand.values()){let e=t.getJointPose(r,n),i=this._getHandJoint(c,r);e!==null&&(i.matrix.fromArray(e.transform.matrix),i.matrix.decompose(i.position,i.rotation,i.scale),i.matrixWorldNeedsUpdate=!0,i.jointRadius=e.radius),i.visible=e!==null}let r=c.joints[ ` index - finger - tip ` ],i=c.joints[ ` thumb - tip ` ],o=r.position.distanceTo(i.position),s=.02,l=.005;c.inputState.pinching&&o>s+l?(c.inputState.pinching=!1,this.dispatchEvent({type: ` pinchend ` ,handedness:e.handedness,target:this})):!c.inputState.pinching&&o<=s-l&&(c.inputState.pinching=!0,this.dispatchEvent({type: ` pinchstart ` ,handedness:e.handedness,target:this}))}else s!==null&&e.gripSpace&&(i=t.getPose(e.gripSpace,n),i!==null&&(s.matrix.fromArray(i.transform.matrix),s.matrix.decompose(s.position,s.rotation,s.scale),s.matrixWorldNeedsUpdate=!0,i.linearVelocity?(s.hasLinearVelocity=!0,s.linearVelocity.copy(i.linearVelocity)):s.hasLinearVelocity=!1,i.angularVelocity?(s.hasAngularVelocity=!0,s.angularVelocity.copy(i.angularVelocity)):s.hasAngularVelocity=!1));o!==null&&(r=t.getPose(e.targetRaySpace,n),r===null&&i!==null&&(r=i),r!==null&&(o.matrix.fromArray(r.transform.matrix),o.matrix.decompose(o.position,o.rotation,o.scale),o.matrixWorldNeedsUpdate=!0,r.linearVelocity?(o.hasLinearVelocity=!0,o.linearVelocity.copy(r.linearVelocity)):o.hasLinearVelocity=!1,r.angularVelocity?(o.hasAngularVelocity=!0,o.angularVelocity.copy(r.angularVelocity)):o.hasAngularVelocity=!1,this.dispatchEvent(sa)))}return o!==null&&(o.visible=r!==null),s!==null&&(s.visible=i!==null),c!==null&&(c.visible=a!==null),this}_getHandJoint(e,t){if(e.joints[t.jointName]===void 0){let n=new oa;n.matrixAutoUpdate=!1,n.visible=!1,e.joints[t.jointName]=n,e.add(n)}return e.joints[t.jointName]}},la=class e{constructor(e,t=25e-5){this.isFogExp2=!0,this.name= ` ` ,this.color=new Y(e),this.density=t}clone(){return new e(this.color,this.density)}toJSON(){return{type: ` FogExp2 ` ,name:this.name,color:this.color.getHex(),density:this.density}}},ua=clas
if ( diffuseColor . a < getAlphaHashThreshold ( vPosition ) ) discard ;
# endif ` ,alphahash_pars_fragment: ` # ifdef USE _ALPHAHASH
const float ALPHA _HASH _SCALE = 0.05 ;
float hash2D ( vec2 value ) {
return fract ( 1.0 e4 * sin ( 17.0 * value . x + 0.1 * value . y ) * ( 0.1 + abs ( sin ( 13.0 * value . y + value . x ) ) ) ) ;
}
float hash3D ( vec3 value ) {
return hash2D ( vec2 ( hash2D ( value . xy ) , value . z ) ) ;
}
float getAlphaHashThreshold ( vec3 position ) {
float maxDeriv = max (
length ( dFdx ( position . xyz ) ) ,
length ( dFdy ( position . xyz ) )
) ;
float pixScale = 1.0 / ( ALPHA _HASH _SCALE * maxDeriv ) ;
vec2 pixScales = vec2 (
exp2 ( floor ( log2 ( pixScale ) ) ) ,
exp2 ( ceil ( log2 ( pixScale ) ) )
) ;
vec2 alpha = vec2 (
hash3D ( floor ( pixScales . x * position . xyz ) ) ,
hash3D ( floor ( pixScales . y * position . xyz ) )
) ;
float lerpFactor = fract ( log2 ( pixScale ) ) ;
float x = ( 1.0 - lerpFactor ) * alpha . x + lerpFactor * alpha . y ;
float a = min ( lerpFactor , 1.0 - lerpFactor ) ;
vec3 cases = vec3 (
x * x / ( 2.0 * a * ( 1.0 - a ) ) ,
( x - 0.5 * a ) / ( 1.0 - a ) ,
1.0 - ( ( 1.0 - x ) * ( 1.0 - x ) / ( 2.0 * a * ( 1.0 - a ) ) )
) ;
float threshold = ( x < ( 1.0 - a ) )
? ( ( x < a ) ? cases . x : cases . y )
: cases . z ;
return clamp ( threshold , 1.0 e - 6 , 1.0 ) ;
}
# endif ` ,alphamap_fragment: ` # ifdef USE _ALPHAMAP
diffuseColor . a *= texture2D ( alphaMap , vAlphaMapUv ) . g ;
# endif ` ,alphamap_pars_fragment: ` # ifdef USE _ALPHAMAP
uniform sampler2D alphaMap ;
# endif ` ,alphatest_fragment: ` # ifdef USE _ALPHATEST
# ifdef ALPHA _TO _COVERAGE
diffuseColor . a = smoothstep ( alphaTest , alphaTest + fwidth ( diffuseColor . a ) , diffuseColor . a ) ;
if ( diffuseColor . a == 0.0 ) discard ;
# else
if ( diffuseColor . a < alphaTest ) discard ;
# endif
# endif ` ,alphatest_pars_fragment: ` # ifdef USE _ALPHATEST
uniform float alphaTest ;
# endif ` ,aomap_fragment: ` # ifdef USE _AOMAP
float ambientOcclusion = ( texture2D ( aoMap , vAoMapUv ) . r - 1.0 ) * aoMapIntensity + 1.0 ;
reflectedLight . indirectDiffuse *= ambientOcclusion ;
# if defined ( USE _CLEARCOAT )
clearcoatSpecularIndirect *= ambientOcclusion ;
# endif
# if defined ( USE _SHEEN )
sheenSpecularIndirect *= ambientOcclusion ;
# endif
# if defined ( USE _ENVMAP ) && defined ( STANDARD )
float dotNV = saturate ( dot ( geometryNormal , geometryViewDir ) ) ;
reflectedLight . indirectSpecular *= computeSpecularOcclusion ( dotNV , ambientOcclusion , material . roughness ) ;
# endif
# endif ` ,aomap_pars_fragment: ` # ifdef USE _AOMAP
uniform sampler2D aoMap ;
uniform float aoMapIntensity ;
# endif ` ,batching_pars_vertex: ` # ifdef USE _BATCHING
# if ! defined ( GL _ANGLE _multi _draw )
# define gl _DrawID _gl _DrawID
uniform int _gl _DrawID ;
# endif
uniform highp sampler2D batchingTexture ;
uniform highp usampler2D batchingIdTexture ;
mat4 getBatchingMatrix ( const in float i ) {
int size = textureSize ( batchingTexture , 0 ) . x ;
int j = int ( i ) * 4 ;
int x = j % size ;
int y = j / size ;
vec4 v1 = texelFetch ( batchingTexture , ivec2 ( x , y ) , 0 ) ;
vec4 v2 = texelFetch ( batchingTexture , ivec2 ( x + 1 , y ) , 0 ) ;
vec4 v3 = texelFetch ( batchingTexture , ivec2 ( x + 2 , y ) , 0 ) ;
vec4 v4 = texelFetch ( batchingTexture , ivec2 ( x + 3 , y ) , 0 ) ;
return mat4 ( v1 , v2 , v3 , v4 ) ;
}
float getIndirectIndex ( const in int i ) {
int size = textureSize ( batchingIdTexture , 0 ) . x ;
int x = i % size ;
int y = i / size ;
return float ( texelFetch ( batchingIdTexture , ivec2 ( x , y ) , 0 ) . r ) ;
}
# endif
# ifdef USE _BATCHING _COLOR
uniform sampler2D batchingColorTexture ;
vec3 getBatchingColor ( const in float i ) {
int size = textureSize ( batchingColorTexture , 0 ) . x ;
int j = int ( i ) ;
int x = j % size ;
int y = j / size ;
return texelFetch ( batchingColorTexture , ivec2 ( x , y ) , 0 ) . rgb ;
}
# endif ` ,batching_vertex: ` # ifdef USE _BATCHING
mat4 batchingMatrix = getBatchingMatrix ( getIndirectIndex ( gl _DrawID ) ) ;
# endif ` ,begin_vertex: ` vec3 transformed = vec3 ( position ) ;
# ifdef USE _ALPHAHASH
vPosition = vec3 ( position ) ;
# endif ` ,beginnormal_vertex: ` vec3 objectNormal = vec3 ( normal ) ;
# ifdef USE _TANGENT
vec3 objectTangent = vec3 ( tangent . xyz ) ;
# endif ` ,bsdfs: ` float G _BlinnPhong _Implicit ( ) {
return 0.25 ;
}
float D _BlinnPhong ( const in float shininess , const in float dotNH ) {
return RECIPROCAL _PI * ( shininess * 0.5 + 1.0 ) * pow ( dotNH , shininess ) ;
}
vec3 BRDF _BlinnPhong ( const in vec3 lightDir , const in vec3 viewDir , const in vec3 normal , const in vec3 specularColor , const in float shininess ) {
vec3 halfDir = normalize ( lightDir + viewDir ) ;
float dotNH = saturate ( dot ( normal , halfDir ) ) ;
float dotVH = saturate ( dot ( viewDir , halfDir ) ) ;
vec3 F = F _Schlick ( specularColor , 1.0 , dotVH ) ;
float G = G _BlinnPhong _Implicit ( ) ;
float D = D _BlinnPhong ( shininess , dotNH ) ;
return F * ( G * D ) ;
} // validated`,iridescence_fragment:`#ifdef USE_IRIDESCENCE
const mat3 XYZ _TO _REC709 = mat3 (
3.2404542 , - 0.9692660 , 0.0556434 ,
- 1.5371385 , 1.8760108 , - 0.2040259 ,
- 0.4985314 , 0.0415560 , 1.0572252
) ;
vec3 Fresnel0ToIor ( vec3 fresnel0 ) {
vec3 sqrtF0 = sqrt ( fresnel0 ) ;
return ( vec3 ( 1.0 ) + sqrtF0 ) / ( vec3 ( 1.0 ) - sqrtF0 ) ;
}
vec3 IorToFresnel0 ( vec3 transmittedIor , float incidentIor ) {
return pow2 ( ( transmittedIor - vec3 ( incidentIor ) ) / ( transmittedIor + vec3 ( incidentIor ) ) ) ;
}
float IorToFresnel0 ( float transmittedIor , float incidentIor ) {
return pow2 ( ( transmittedIor - incidentIor ) / ( transmittedIor + incidentIor ) ) ;
}
vec3 evalSensitivity ( float OPD , vec3 shift ) {
float phase = 2.0 * PI * OPD * 1.0 e - 9 ;
vec3 val = vec3 ( 5.4856 e - 13 , 4.4201 e - 13 , 5.2481 e - 13 ) ;
vec3 pos = vec3 ( 1.6810 e + 06 , 1.7953 e + 06 , 2.2084 e + 06 ) ;
vec3 var = vec3 ( 4.3278 e + 09 , 9.3046 e + 09 , 6.6121 e + 09 ) ;
vec3 xyz = val * sqrt ( 2.0 * PI * var ) * cos ( pos * phase + shift ) * exp ( - pow2 ( phase ) * var ) ;
xyz . x += 9.7470 e - 14 * sqrt ( 2.0 * PI * 4.5282 e + 09 ) * cos ( 2.2399 e + 06 * phase + shift [ 0 ] ) * exp ( - 4.5282 e + 09 * pow2 ( phase ) ) ;
xyz /= 1.0685 e - 7 ;
vec3 rgb = XYZ _TO _REC709 * xyz ;
return rgb ;
}
vec3 evalIridescence ( float outsideIOR , float eta2 , float cosTheta1 , float thinFilmThickness , vec3 baseF0 ) {
vec3 I ;
float iridescenceIOR = mix ( outsideIOR , eta2 , smoothstep ( 0.0 , 0.03 , thinFilmThickness ) ) ;
float sinTheta2Sq = pow2 ( outsideIOR / iridescenceIOR ) * ( 1.0 - pow2 ( cosTheta1 ) ) ;
float cosTheta2Sq = 1.0 - sinTheta2Sq ;
if ( cosTheta2Sq < 0.0 ) {
return vec3 ( 1.0 ) ;
}
float cosTheta2 = sqrt ( cosTheta2Sq ) ;
float R0 = IorToFresnel0 ( iridescenceIOR , outsideIOR ) ;
float R12 = F _Schlick ( R0 , 1.0 , cosTheta1 ) ;
float T121 = 1.0 - R12 ;
float phi12 = 0.0 ;
if ( iridescenceIOR < outsideIOR ) phi12 = PI ;
float phi21 = PI - phi12 ;
vec3 baseIOR = Fresnel0ToIor ( clamp ( baseF0 , 0.0 , 0.9999 ) ) ; vec3 R1 = IorToFresnel0 ( baseIOR , iridescenceIOR ) ;
vec3 R23 = F _Schlick ( R1 , 1.0 , cosTheta2 ) ;
vec3 phi23 = vec3 ( 0.0 ) ;
if ( baseIOR [ 0 ] < iridescenceIOR ) phi23 [ 0 ] = PI ;
if ( baseIOR [ 1 ] < iridescenceIOR ) phi23 [ 1 ] = PI ;
if ( baseIOR [ 2 ] < iridescenceIOR ) phi23 [ 2 ] = PI ;
float OPD = 2.0 * iridescenceIOR * thinFilmThickness * cosTheta2 ;
vec3 phi = vec3 ( phi21 ) + phi23 ;
vec3 R123 = clamp ( R12 * R23 , 1e-5 , 0.9999 ) ;
vec3 r123 = sqrt ( R123 ) ;
vec3 Rs = pow2 ( T121 ) * R23 / ( vec3 ( 1.0 ) - R123 ) ;
vec3 C0 = R12 + Rs ;
I = C0 ;
vec3 Cm = Rs - T121 ;
for ( int m = 1 ; m <= 2 ; ++ m ) {
Cm *= r123 ;
vec3 Sm = 2.0 * evalSensitivity ( float ( m ) * OPD , float ( m ) * phi ) ;
I += Cm * Sm ;
}
return max ( I , vec3 ( 0.0 ) ) ;
}
# endif ` ,bumpmap_pars_fragment: ` # ifdef USE _BUMPMAP
uniform sampler2D bumpMap ;
uniform float bumpScale ;
vec2 dHdxy _fwd ( ) {
vec2 dSTdx = dFdx ( vBumpMapUv ) ;
vec2 dSTdy = dFdy ( vBumpMapUv ) ;
float Hll = bumpScale * texture2D ( bumpMap , vBumpMapUv ) . x ;
float dBx = bumpScale * texture2D ( bumpMap , vBumpMapUv + dSTdx ) . x - Hll ;
float dBy = bumpScale * texture2D ( bumpMap , vBumpMapUv + dSTdy ) . x - Hll ;
return vec2 ( dBx , dBy ) ;
}
vec3 perturbNormalArb ( vec3 surf _pos , vec3 surf _norm , vec2 dHdxy , float faceDirection ) {
vec3 vSigmaX = normalize ( dFdx ( surf _pos . xyz ) ) ;
vec3 vSigmaY = normalize ( dFdy ( surf _pos . xyz ) ) ;
vec3 vN = surf _norm ;
vec3 R1 = cross ( vSigmaY , vN ) ;
vec3 R2 = cross ( vN , vSigmaX ) ;
float fDet = dot ( vSigmaX , R1 ) * faceDirection ;
vec3 vGrad = sign ( fDet ) * ( dHdxy . x * R1 + dHdxy . y * R2 ) ;
return normalize ( abs ( fDet ) * surf _norm - vGrad ) ;
}
# endif ` ,clipping_planes_fragment: ` # if NUM _CLIPPING _PLANES > 0
vec4 plane ;
# ifdef ALPHA _TO _COVERAGE
float distanceToPlane , distanceGradient ;
float clipOpacity = 1.0 ;
# pragma unroll _loop _start
for ( int i = 0 ; i < UNION _CLIPPING _PLANES ; i ++ ) {
plane = clippingPlanes [ i ] ;
distanceToPlane = - dot ( vClipPosition , plane . xyz ) + plane . w ;
distanceGradient = fwidth ( distanceToPlane ) / 2.0 ;
clipOpacity *= smoothstep ( - distanceGradient , distanceGradient , distanceToPlane ) ;
if ( clipOpacity == 0.0 ) discard ;
}
# pragma unroll _loop _end
# if UNION _CLIPPING _PLANES < NUM _CLIPPING _PLANES
float unionClipOpacity = 1.0 ;
# pragma unroll _loop _start
for ( int i = UNION _CLIPPING _PLANES ; i < NUM _CLIPPING _PLANES ; i ++ ) {
plane = clippingPlanes [ i ] ;
distanceToPlane = - dot ( vClipPosition , plane . xyz ) + plane . w ;
distanceGradient = fwidth ( distanceToPlane ) / 2.0 ;
unionClipOpacity *= 1.0 - smoothstep ( - distanceGradient , distanceGradient , distanceToPlane ) ;
}
# pragma unroll _loop _end
clipOpacity *= 1.0 - unionClipOpacity ;
# endif
diffuseColor . a *= clipOpacity ;
if ( diffuseColor . a == 0.0 ) discard ;
# else
# pragma unroll _loop _start
for ( int i = 0 ; i < UNION _CLIPPING _PLANES ; i ++ ) {
plane = clippingPlanes [ i ] ;
if ( dot ( vClipPosition , plane . xyz ) > plane . w ) discard ;
}
# pragma unroll _loop _end
# if UNION _CLIPPING _PLANES < NUM _CLIPPING _PLANES
bool clipped = true ;
# pragma unroll _loop _start
for ( int i = UNION _CLIPPING _PLANES ; i < NUM _CLIPPING _PLANES ; i ++ ) {
plane = clippingPlanes [ i ] ;
clipped = ( dot ( vClipPosition , plane . xyz ) > plane . w ) && clipped ;
}
# pragma unroll _loop _end
if ( clipped ) discard ;
# endif
# endif
# endif ` ,clipping_planes_pars_fragment: ` # if NUM _CLIPPING _PLANES > 0
varying vec3 vClipPosition ;
uniform vec4 clippingPlanes [ NUM _CLIPPING _PLANES ] ;
# endif ` ,clipping_planes_pars_vertex: ` # if NUM _CLIPPING _PLANES > 0
varying vec3 vClipPosition ;
# endif ` ,clipping_planes_vertex: ` # if NUM _CLIPPING _PLANES > 0
vClipPosition = - mvPosition . xyz ;
# endif ` ,color_fragment: ` # if defined ( USE _COLOR _ALPHA )
diffuseColor *= vColor ;
# elif defined ( USE _COLOR )
diffuseColor . rgb *= vColor ;
# endif ` ,color_pars_fragment: ` # if defined ( USE _COLOR _ALPHA )
varying vec4 vColor ;
# elif defined ( USE _COLOR )
varying vec3 vColor ;
# endif ` ,color_pars_vertex: ` # if defined ( USE _COLOR _ALPHA )
varying vec4 vColor ;
# elif defined ( USE _COLOR ) || defined ( USE _INSTANCING _COLOR ) || defined ( USE _BATCHING _COLOR )
varying vec3 vColor ;
# endif ` ,color_vertex: ` # if defined ( USE _COLOR _ALPHA )
vColor = vec4 ( 1.0 ) ;
# elif defined ( USE _COLOR ) || defined ( USE _INSTANCING _COLOR ) || defined ( USE _BATCHING _COLOR )
vColor = vec3 ( 1.0 ) ;
# endif
# ifdef USE _COLOR
vColor *= color ;
# endif
# ifdef USE _INSTANCING _COLOR
vColor . xyz *= instanceColor . xyz ;
# endif
# ifdef USE _BATCHING _COLOR
vec3 batchingColor = getBatchingColor ( getIndirectIndex ( gl _DrawID ) ) ;
vColor . xyz *= batchingColor . xyz ;
# endif ` ,common: ` # define PI 3.141592653589793
# define PI2 6.283185307179586
# define PI _HALF 1.5707963267948966
# define RECIPROCAL _PI 0.3183098861837907
# define RECIPROCAL _PI2 0.15915494309189535
# define EPSILON 1e-6
# ifndef saturate
# define saturate ( a ) clamp ( a , 0.0 , 1.0 )
# endif
# define whiteComplement ( a ) ( 1.0 - saturate ( a ) )
float pow2 ( const in float x ) { return x * x ; }
vec3 pow2 ( const in vec3 x ) { return x * x ; }
float pow3 ( const in float x ) { return x * x * x ; }
float pow4 ( const in float x ) { float x2 = x * x ; return x2 * x2 ; }
float max3 ( const in vec3 v ) { return max ( max ( v . x , v . y ) , v . z ) ; }
float average ( const in vec3 v ) { return dot ( v , vec3 ( 0.3333333 ) ) ; }
highp float rand ( const in vec2 uv ) {
const highp float a = 12.9898 , b = 78.233 , c = 43758.5453 ;
highp float dt = dot ( uv . xy , vec2 ( a , b ) ) , sn = mod ( dt , PI ) ;
return fract ( sin ( sn ) * c ) ;
}
# ifdef HIGH _PRECISION
float precisionSafeLength ( vec3 v ) { return length ( v ) ; }
# else
float precisionSafeLength ( vec3 v ) {
float maxComponent = max3 ( abs ( v ) ) ;
return length ( v / maxComponent ) * maxComponent ;
}
# endif
struct IncidentLight {
vec3 color ;
vec3 direction ;
bool visible ;
} ;
struct ReflectedLight {
vec3 directDiffuse ;
vec3 directSpecular ;
vec3 indirectDiffuse ;
vec3 indirectSpecular ;
} ;
# ifdef USE _ALPHAHASH
varying vec3 vPosition ;
# endif
vec3 transformDirection ( in vec3 dir , in mat4 matrix ) {
return normalize ( ( matrix * vec4 ( dir , 0.0 ) ) . xyz ) ;
}
vec3 inverseTransformDirection ( in vec3 dir , in mat4 matrix ) {
return normalize ( ( vec4 ( dir , 0.0 ) * matrix ) . xyz ) ;
}
bool isPerspectiveMatrix ( mat4 m ) {
return m [ 2 ] [ 3 ] == - 1.0 ;
}
vec2 equirectUv ( in vec3 dir ) {
float u = atan ( dir . z , dir . x ) * RECIPROCAL _PI2 + 0.5 ;
float v = asin ( clamp ( dir . y , - 1.0 , 1.0 ) ) * RECIPROCAL _PI + 0.5 ;
return vec2 ( u , v ) ;
}
vec3 BRDF _Lambert ( const in vec3 diffuseColor ) {
return RECIPROCAL _PI * diffuseColor ;
}
vec3 F _Schlick ( const in vec3 f0 , const in float f90 , const in float dotVH ) {
float fresnel = exp2 ( ( - 5.55473 * dotVH - 6.98316 ) * dotVH ) ;
return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel ) ;
}
float F _Schlick ( const in float f0 , const in float f90 , const in float dotVH ) {
float fresnel = exp2 ( ( - 5.55473 * dotVH - 6.98316 ) * dotVH ) ;
return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel ) ;
} // validated`,cube_uv_reflection_fragment:`#ifdef ENVMAP_TYPE_CUBE_UV
# define cubeUV _minMipLevel 4.0
# define cubeUV _minTileSize 16.0
float getFace ( vec3 direction ) {
vec3 absDirection = abs ( direction ) ;
float face = - 1.0 ;
if ( absDirection . x > absDirection . z ) {
if ( absDirection . x > absDirection . y )
face = direction . x > 0.0 ? 0.0 : 3.0 ;
else
face = direction . y > 0.0 ? 1.0 : 4.0 ;
} else {
if ( absDirection . z > absDirection . y )
face = direction . z > 0.0 ? 2.0 : 5.0 ;
else
face = direction . y > 0.0 ? 1.0 : 4.0 ;
}
return face ;
}
vec2 getUV ( vec3 direction , float face ) {
vec2 uv ;
if ( face == 0.0 ) {
uv = vec2 ( direction . z , direction . y ) / abs ( direction . x ) ;
} else if ( face == 1.0 ) {
uv = vec2 ( - direction . x , - direction . z ) / abs ( direction . y ) ;
} else if ( face == 2.0 ) {
uv = vec2 ( - direction . x , direction . y ) / abs ( direction . z ) ;
} else if ( face == 3.0 ) {
uv = vec2 ( - direction . z , direction . y ) / abs ( direction . x ) ;
} else if ( face == 4.0 ) {
uv = vec2 ( - direction . x , direction . z ) / abs ( direction . y ) ;
} else {
uv = vec2 ( direction . x , direction . y ) / abs ( direction . z ) ;
}
return 0.5 * ( uv + 1.0 ) ;
}
vec3 bilinearCubeUV ( sampler2D envMap , vec3 direction , float mipInt ) {
float face = getFace ( direction ) ;
float filterInt = max ( cubeUV _minMipLevel - mipInt , 0.0 ) ;
mipInt = max ( mipInt , cubeUV _minMipLevel ) ;
float faceSize = exp2 ( mipInt ) ;
highp vec2 uv = getUV ( direction , face ) * ( faceSize - 2.0 ) + 1.0 ;
if ( face > 2.0 ) {
uv . y += faceSize ;
face -= 3.0 ;
}
uv . x += face * faceSize ;
uv . x += filterInt * 3.0 * cubeUV _minTileSize ;
uv . y += 4.0 * ( exp2 ( CUBEUV _MAX _MIP ) - faceSize ) ;
uv . x *= CUBEUV _TEXEL _WIDTH ;
uv . y *= CUBEUV _TEXEL _HEIGHT ;
# ifdef texture2DGradEXT
return texture2DGradEXT ( envMap , uv , vec2 ( 0.0 ) , vec2 ( 0.0 ) ) . rgb ;
# else
return texture2D ( envMap , uv ) . rgb ;
# endif
}
# define cubeUV _r0 1.0
# define cubeUV _m0 - 2.0
# define cubeUV _r1 0.8
# define cubeUV _m1 - 1.0
# define cubeUV _r4 0.4
# define cubeUV _m4 2.0
# define cubeUV _r5 0.305
# define cubeUV _m5 3.0
# define cubeUV _r6 0.21
# define cubeUV _m6 4.0
float roughnessToMip ( float roughness ) {
float mip = 0.0 ;
if ( roughness >= cubeUV _r1 ) {
mip = ( cubeUV _r0 - roughness ) * ( cubeUV _m1 - cubeUV _m0 ) / ( cubeUV _r0 - cubeUV _r1 ) + cubeUV _m0 ;
} else if ( roughness >= cubeUV _r4 ) {
mip = ( cubeUV _r1 - roughness ) * ( cubeUV _m4 - cubeUV _m1 ) / ( cubeUV _r1 - cubeUV _r4 ) + cubeUV _m1 ;
} else if ( roughness >= cubeUV _r5 ) {
mip = ( cubeUV _r4 - roughness ) * ( cubeUV _m5 - cubeUV _m4 ) / ( cubeUV _r4 - cubeUV _r5 ) + cubeUV _m4 ;
} else if ( roughness >= cubeUV _r6 ) {
mip = ( cubeUV _r5 - roughness ) * ( cubeUV _m6 - cubeUV _m5 ) / ( cubeUV _r5 - cubeUV _r6 ) + cubeUV _m5 ;
} else {
mip = - 2.0 * log2 ( 1.16 * roughness ) ; }
return mip ;
}
vec4 textureCubeUV ( sampler2D envMap , vec3 sampleDir , float roughness ) {
float mip = clamp ( roughnessToMip ( roughness ) , cubeUV _m0 , CUBEUV _MAX _MIP ) ;
float mipF = fract ( mip ) ;
float mipInt = floor ( mip ) ;
vec3 color0 = bilinearCubeUV ( envMap , sampleDir , mipInt ) ;
if ( mipF == 0.0 ) {
return vec4 ( color0 , 1.0 ) ;
} else {
vec3 color1 = bilinearCubeUV ( envMap , sampleDir , mipInt + 1.0 ) ;
return vec4 ( mix ( color0 , color1 , mipF ) , 1.0 ) ;
}
}
# endif ` ,defaultnormal_vertex: ` vec3 transformedNormal = objectNormal ;
# ifdef USE _TANGENT
vec3 transformedTangent = objectTangent ;
# endif
# ifdef USE _BATCHING
mat3 bm = mat3 ( batchingMatrix ) ;
transformedNormal /= vec3 ( dot ( bm [ 0 ] , bm [ 0 ] ) , dot ( bm [ 1 ] , bm [ 1 ] ) , dot ( bm [ 2 ] , bm [ 2 ] ) ) ;
transformedNormal = bm * transformedNormal ;
# ifdef USE _TANGENT
transformedTangent = bm * transformedTangent ;
# endif
# endif
# ifdef USE _INSTANCING
mat3 im = mat3 ( instanceMatrix ) ;
transformedNormal /= vec3 ( dot ( im [ 0 ] , im [ 0 ] ) , dot ( im [ 1 ] , im [ 1 ] ) , dot ( im [ 2 ] , im [ 2 ] ) ) ;
transformedNormal = im * transformedNormal ;
# ifdef USE _TANGENT
transformedTangent = im * transformedTangent ;
# endif
# endif
transformedNormal = normalMatrix * transformedNormal ;
# ifdef FLIP _SIDED
transformedNormal = - transformedNormal ;
# endif
# ifdef USE _TANGENT
transformedTangent = ( modelViewMatrix * vec4 ( transformedTangent , 0.0 ) ) . xyz ;
# ifdef FLIP _SIDED
transformedTangent = - transformedTangent ;
# endif
# endif ` ,displacementmap_pars_vertex: ` # ifdef USE _DISPLACEMENTMAP
uniform sampler2D displacementMap ;
uniform float displacementScale ;
uniform float displacementBias ;
# endif ` ,displacementmap_vertex: ` # ifdef USE _DISPLACEMENTMAP
transformed += normalize ( objectNormal ) * ( texture2D ( displacementMap , vDisplacementMapUv ) . x * displacementScale + displacementBias ) ;
# endif ` ,emissivemap_fragment: ` # ifdef USE _EMISSIVEMAP
vec4 emissiveColor = texture2D ( emissiveMap , vEmissiveMapUv ) ;
# ifdef DECODE _VIDEO _TEXTURE _EMISSIVE
emissiveColor = sRGBTransferEOTF ( emissiveColor ) ;
# endif
totalEmissiveRadiance *= emissiveColor . rgb ;
# endif ` ,emissivemap_pars_fragment: ` # ifdef USE _EMISSIVEMAP
uniform sampler2D emissiveMap ;
# endif ` ,colorspace_fragment: ` gl _FragColor = linearToOutputTexel ( gl _FragColor ) ; ` ,colorspace_pars_fragment: ` vec4 LinearTransferOETF ( in vec4 value ) {
return value ;
}
vec4 sRGBTransferEOTF ( in vec4 value ) {
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 ) ;
}
vec4 sRGBTransferOETF ( in vec4 value ) {
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 ) ;
} ` ,envmap_fragment: ` # ifdef USE _ENVMAP
# ifdef ENV _WORLDPOS
vec3 cameraToFrag ;
if ( isOrthographic ) {
cameraToFrag = normalize ( vec3 ( - viewMatrix [ 0 ] [ 2 ] , - viewMatrix [ 1 ] [ 2 ] , - viewMatrix [ 2 ] [ 2 ] ) ) ;
} else {
cameraToFrag = normalize ( vWorldPosition - cameraPosition ) ;
}
vec3 worldNormal = inverseTransformDirection ( normal , viewMatrix ) ;
# ifdef ENVMAP _MODE _REFLECTION
vec3 reflectVec = reflect ( cameraToFrag , worldNormal ) ;
# else
vec3 reflectVec = refract ( cameraToFrag , worldNormal , refractionRatio ) ;
# endif
# else
vec3 reflectVec = vReflect ;
# endif
# ifdef ENVMAP _TYPE _CUBE
vec4 envColor = textureCube ( envMap , envMapRotation * vec3 ( flipEnvMap * reflectVec . x , reflectVec . yz ) ) ;
# else
vec4 envColor = vec4 ( 0.0 ) ;
# endif
# ifdef ENVMAP _BLENDING _MULTIPLY
outgoingLight = mix ( outgoingLight , outgoingLight * envColor . xyz , specularStrength * reflectivity ) ;
# elif defined ( ENVMAP _BLENDING _MIX )
outgoingLight = mix ( outgoingLight , envColor . xyz , specularStrength * reflectivity ) ;
# elif defined ( ENVMAP _BLENDING _ADD )
outgoingLight += envColor . xyz * specularStrength * reflectivity ;
# endif
# endif ` ,envmap_common_pars_fragment: ` # ifdef USE _ENVMAP
uniform float envMapIntensity ;
uniform float flipEnvMap ;
uniform mat3 envMapRotation ;
# ifdef ENVMAP _TYPE _CUBE
uniform samplerCube envMap ;
# else
uniform sampler2D envMap ;
# endif
# endif ` ,envmap_pars_fragment: ` # ifdef USE _ENVMAP
uniform float reflectivity ;
# if defined ( USE _BUMPMAP ) || defined ( USE _NORMALMAP ) || defined ( PHONG ) || defined ( LAMBERT )
# define ENV _WORLDPOS
# endif
# ifdef ENV _WORLDPOS
varying vec3 vWorldPosition ;
uniform float refractionRatio ;
# else
varying vec3 vReflect ;
# endif
# endif ` ,envmap_pars_vertex: ` # ifdef USE _ENVMAP
# if defined ( USE _BUMPMAP ) || defined ( USE _NORMALMAP ) || defined ( PHONG ) || defined ( LAMBERT )
# define ENV _WORLDPOS
# endif
# ifdef ENV _WORLDPOS
varying vec3 vWorldPosition ;
# else
varying vec3 vReflect ;
uniform float refractionRatio ;
# endif
# endif ` ,envmap_physical_pars_fragment: ` # ifdef USE _ENVMAP
vec3 getIBLIrradiance ( const in vec3 normal ) {
# ifdef ENVMAP _TYPE _CUBE _UV
vec3 worldNormal = inverseTransformDirection ( normal , viewMatrix ) ;
vec4 envMapColor = textureCubeUV ( envMap , envMapRotation * worldNormal , 1.0 ) ;
return PI * envMapColor . rgb * envMapIntensity ;
# else
return vec3 ( 0.0 ) ;
# endif
}
vec3 getIBLRadiance ( const in vec3 viewDir , const in vec3 normal , const in float roughness ) {
# ifdef ENVMAP _TYPE _CUBE _UV
vec3 reflectVec = reflect ( - viewDir , normal ) ;
reflectVec = normalize ( mix ( reflectVec , normal , pow4 ( roughness ) ) ) ;
reflectVec = inverseTransformDirection ( reflectVec , viewMatrix ) ;
vec4 envMapColor = textureCubeUV ( envMap , envMapRotation * reflectVec , roughness ) ;
return envMapColor . rgb * envMapIntensity ;
# else
return vec3 ( 0.0 ) ;
# endif
}
# ifdef USE _ANISOTROPY
vec3 getIBLAnisotropyRadiance ( const in vec3 viewDir , const in vec3 normal , const in float roughness , const in vec3 bitangent , const in float anisotropy ) {
# ifdef ENVMAP _TYPE _CUBE _UV
vec3 bentNormal = cross ( bitangent , viewDir ) ;
bentNormal = normalize ( cross ( bentNormal , bitangent ) ) ;
bentNormal = normalize ( mix ( bentNormal , normal , pow2 ( pow2 ( 1.0 - anisotropy * ( 1.0 - roughness ) ) ) ) ) ;
return getIBLRadiance ( viewDir , bentNormal , roughness ) ;
# else
return vec3 ( 0.0 ) ;
# endif
}
# endif
# endif ` ,envmap_vertex: ` # ifdef USE _ENVMAP
# ifdef ENV _WORLDPOS
vWorldPosition = worldPosition . xyz ;
# else
vec3 cameraToVertex ;
if ( isOrthographic ) {
cameraToVertex = normalize ( vec3 ( - viewMatrix [ 0 ] [ 2 ] , - viewMatrix [ 1 ] [ 2 ] , - viewMatrix [ 2 ] [ 2 ] ) ) ;
} else {
cameraToVertex = normalize ( worldPosition . xyz - cameraPosition ) ;
}
vec3 worldNormal = inverseTransformDirection ( transformedNormal , viewMatrix ) ;
# ifdef ENVMAP _MODE _REFLECTION
vReflect = reflect ( cameraToVertex , worldNormal ) ;
# else
vReflect = refract ( cameraToVertex , worldNormal , refractionRatio ) ;
# endif
# endif
# endif ` ,fog_vertex: ` # ifdef USE _FOG
vFogDepth = - mvPosition . z ;
# endif ` ,fog_pars_vertex: ` # ifdef USE _FOG
varying float vFogDepth ;
# endif ` ,fog_fragment: ` # ifdef USE _FOG
# ifdef FOG _EXP2
float fogFactor = 1.0 - exp ( - fogDensity * fogDensity * vFogDepth * vFogDepth ) ;
# else
float fogFactor = smoothstep ( fogNear , fogFar , vFogDepth ) ;
# endif
gl _FragColor . rgb = mix ( gl _FragColor . rgb , fogColor , fogFactor ) ;
# endif ` ,fog_pars_fragment: ` # ifdef USE _FOG
uniform vec3 fogColor ;
varying float vFogDepth ;
# ifdef FOG _EXP2
uniform float fogDensity ;
# else
uniform float fogNear ;
uniform float fogFar ;
# endif
# endif ` ,gradientmap_pars_fragment: ` # ifdef USE _GRADIENTMAP
uniform sampler2D gradientMap ;
# endif
vec3 getGradientIrradiance ( vec3 normal , vec3 lightDirection ) {
float dotNL = dot ( normal , lightDirection ) ;
vec2 coord = vec2 ( dotNL * 0.5 + 0.5 , 0.0 ) ;
# ifdef USE _GRADIENTMAP
return vec3 ( texture2D ( gradientMap , coord ) . r ) ;
# else
vec2 fw = fwidth ( coord ) * 0.5 ;
return mix ( vec3 ( 0.7 ) , vec3 ( 1.0 ) , smoothstep ( 0.7 - fw . x , 0.7 + fw . x , coord . x ) ) ;
# endif
} ` ,lightmap_pars_fragment: ` # ifdef USE _LIGHTMAP
uniform sampler2D lightMap ;
uniform float lightMapIntensity ;
# endif ` ,lights_lambert_fragment: ` LambertMaterial material ;
material . diffuseColor = diffuseColor . rgb ;
material . specularStrength = specularStrength ; ` ,lights_lambert_pars_fragment: ` varying vec3 vViewPosition ;
struct LambertMaterial {
vec3 diffuseColor ;
float specularStrength ;
} ;
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 ) {
float dotNL = saturate ( dot ( geometryNormal , directLight . direction ) ) ;
vec3 irradiance = dotNL * directLight . color ;
reflectedLight . directDiffuse += irradiance * BRDF _Lambert ( material . diffuseColor ) ;
}
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 ) {
reflectedLight . indirectDiffuse += irradiance * BRDF _Lambert ( material . diffuseColor ) ;
}
# define RE _Direct RE _Direct _Lambert
# define RE _IndirectDiffuse RE _IndirectDiffuse _Lambert ` ,lights_pars_begin: ` uniform bool receiveShadow ;
uniform vec3 ambientLightColor ;
# if defined ( USE _LIGHT _PROBES )
uniform vec3 lightProbe [ 9 ] ;
# endif
vec3 shGetIrradianceAt ( in vec3 normal , in vec3 shCoefficients [ 9 ] ) {
float x = normal . x , y = normal . y , z = normal . z ;
vec3 result = shCoefficients [ 0 ] * 0.886227 ;
result += shCoefficients [ 1 ] * 2.0 * 0.511664 * y ;
result += shCoefficients [ 2 ] * 2.0 * 0.511664 * z ;
result += shCoefficients [ 3 ] * 2.0 * 0.511664 * x ;
result += shCoefficients [ 4 ] * 2.0 * 0.429043 * x * y ;
result += shCoefficients [ 5 ] * 2.0 * 0.429043 * y * z ;
result += shCoefficients [ 6 ] * ( 0.743125 * z * z - 0.247708 ) ;
result += shCoefficients [ 7 ] * 2.0 * 0.429043 * x * z ;
result += shCoefficients [ 8 ] * 0.429043 * ( x * x - y * y ) ;
return result ;
}
vec3 getLightProbeIrradiance ( const in vec3 lightProbe [ 9 ] , const in vec3 normal ) {
vec3 worldNormal = inverseTransformDirection ( normal , viewMatrix ) ;
vec3 irradiance = shGetIrradianceAt ( worldNormal , lightProbe ) ;
return irradiance ;
}
vec3 getAmbientLightIrradiance ( const in vec3 ambientLightColor ) {
vec3 irradiance = ambientLightColor ;
return irradiance ;
}
float getDistanceAttenuation ( const in float lightDistance , const in float cutoffDistance , const in float decayExponent ) {
float distanceFalloff = 1.0 / max ( pow ( lightDistance , decayExponent ) , 0.01 ) ;
if ( cutoffDistance > 0.0 ) {
distanceFalloff *= pow2 ( saturate ( 1.0 - pow4 ( lightDistance / cutoffDistance ) ) ) ;
}
return distanceFalloff ;
}
float getSpotAttenuation ( const in float coneCosine , const in float penumbraCosine , const in float angleCosine ) {
return smoothstep ( coneCosine , penumbraCosine , angleCosine ) ;
}
# if NUM _DIR _LIGHTS > 0
struct DirectionalLight {
vec3 direction ;
vec3 color ;
} ;
uniform DirectionalLight directionalLights [ NUM _DIR _LIGHTS ] ;
void getDirectionalLightInfo ( const in DirectionalLight directionalLight , out IncidentLight light ) {
light . color = directionalLight . color ;
light . direction = directionalLight . direction ;
light . visible = true ;
}
# endif
# if NUM _POINT _LIGHTS > 0
struct PointLight {
vec3 position ;
vec3 color ;
float distance ;
float decay ;
} ;
uniform PointLight pointLights [ NUM _POINT _LIGHTS ] ;
void getPointLightInfo ( const in PointLight pointLight , const in vec3 geometryPosition , out IncidentLight light ) {
vec3 lVector = pointLight . position - geometryPosition ;
light . direction = normalize ( lVector ) ;
float lightDistance = length ( lVector ) ;
light . color = pointLight . color ;
light . color *= getDistanceAttenuation ( lightDistance , pointLight . distance , pointLight . decay ) ;
light . visible = ( light . color != vec3 ( 0.0 ) ) ;
}
# endif
# if NUM _SPOT _LIGHTS > 0
struct SpotLight {
vec3 position ;
vec3 direction ;
vec3 color ;
float distance ;
float decay ;
float coneCos ;
float penumbraCos ;
} ;
uniform SpotLight spotLights [ NUM _SPOT _LIGHTS ] ;
void getSpotLightInfo ( const in SpotLight spotLight , const in vec3 geometryPosition , out IncidentLight light ) {
vec3 lVector = spotLight . position - geometryPosition ;
light . direction = normalize ( lVector ) ;
float angleCos = dot ( light . direction , spotLight . direction ) ;
float spotAttenuation = getSpotAttenuation ( spotLight . coneCos , spotLight . penumbraCos , angleCos ) ;
if ( spotAttenuation > 0.0 ) {
float lightDistance = length ( lVector ) ;
light . color = spotLight . color * spotAttenuation ;
light . color *= getDistanceAttenuation ( lightDistance , spotLight . distance , spotLight . decay ) ;
light . visible = ( light . color != vec3 ( 0.0 ) ) ;
} else {
light . color = vec3 ( 0.0 ) ;
light . visible = false ;
}
}
# endif
# if NUM _RECT _AREA _LIGHTS > 0
struct RectAreaLight {
vec3 color ;
vec3 position ;
vec3 halfWidth ;
vec3 halfHeight ;
} ;
uniform sampler2D ltc _1 ; uniform sampler2D ltc _2 ;
uniform RectAreaLight rectAreaLights [ NUM _RECT _AREA _LIGHTS ] ;
# endif
# if NUM _HEMI _LIGHTS > 0
struct HemisphereLight {
vec3 direction ;
vec3 skyColor ;
vec3 groundColor ;
} ;
uniform HemisphereLight hemisphereLights [ NUM _HEMI _LIGHTS ] ;
vec3 getHemisphereLightIrradiance ( const in HemisphereLight hemiLight , const in vec3 normal ) {
float dotNL = dot ( normal , hemiLight . direction ) ;
float hemiDiffuseWeight = 0.5 * dotNL + 0.5 ;
vec3 irradiance = mix ( hemiLight . groundColor , hemiLight . skyColor , hemiDiffuseWeight ) ;
return irradiance ;
}
# endif ` ,lights_toon_fragment: ` ToonMaterial material ;
material . diffuseColor = diffuseColor . rgb ; ` ,lights_toon_pars_fragment: ` varying vec3 vViewPosition ;
struct ToonMaterial {
vec3 diffuseColor ;
} ;
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 ) {
vec3 irradiance = getGradientIrradiance ( geometryNormal , directLight . direction ) * directLight . color ;
reflectedLight . directDiffuse += irradiance * BRDF _Lambert ( material . diffuseColor ) ;
}
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 ) {
reflectedLight . indirectDiffuse += irradiance * BRDF _Lambert ( material . diffuseColor ) ;
}
# define RE _Direct RE _Direct _Toon
# define RE _IndirectDiffuse RE _IndirectDiffuse _Toon ` ,lights_phong_fragment: ` BlinnPhongMaterial material ;
material . diffuseColor = diffuseColor . rgb ;
material . specularColor = specular ;
material . specularShininess = shininess ;
material . specularStrength = specularStrength ; ` ,lights_phong_pars_fragment: ` varying vec3 vViewPosition ;
struct BlinnPhongMaterial {
vec3 diffuseColor ;
vec3 specularColor ;
float specularShininess ;
float specularStrength ;
} ;
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 ) {
float dotNL = saturate ( dot ( geometryNormal , directLight . direction ) ) ;
vec3 irradiance = dotNL * directLight . color ;
reflectedLight . directDiffuse += irradiance * BRDF _Lambert ( material . diffuseColor ) ;
reflectedLight . directSpecular += irradiance * BRDF _BlinnPhong ( directLight . direction , geometryViewDir , geometryNormal , material . specularColor , material . specularShininess ) * material . specularStrength ;
}
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 ) {
reflectedLight . indirectDiffuse += irradiance * BRDF _Lambert ( material . diffuseColor ) ;
}
# define RE _Direct RE _Direct _BlinnPhong
# define RE _IndirectDiffuse RE _IndirectDiffuse _BlinnPhong ` ,lights_physical_fragment: ` PhysicalMaterial material ;
material . diffuseColor = diffuseColor . rgb ;
material . diffuseContribution = diffuseColor . rgb * ( 1.0 - metalnessFactor ) ;
material . metalness = metalnessFactor ;
vec3 dxy = max ( abs ( dFdx ( nonPerturbedNormal ) ) , abs ( dFdy ( nonPerturbedNormal ) ) ) ;
float geometryRoughness = max ( max ( dxy . x , dxy . y ) , dxy . z ) ;
material . roughness = max ( roughnessFactor , 0.0525 ) ; material . roughness += geometryRoughness ;
material . roughness = min ( material . roughness , 1.0 ) ;
# ifdef IOR
material . ior = ior ;
# ifdef USE _SPECULAR
float specularIntensityFactor = specularIntensity ;
vec3 specularColorFactor = specularColor ;
# ifdef USE _SPECULAR _COLORMAP
specularColorFactor *= texture2D ( specularColorMap , vSpecularColorMapUv ) . rgb ;
# endif
# ifdef USE _SPECULAR _INTENSITYMAP
specularIntensityFactor *= texture2D ( specularIntensityMap , vSpecularIntensityMapUv ) . a ;
# endif
material . specularF90 = mix ( specularIntensityFactor , 1.0 , metalnessFactor ) ;
# else
float specularIntensityFactor = 1.0 ;
vec3 specularColorFactor = vec3 ( 1.0 ) ;
material . specularF90 = 1.0 ;
# endif
material . specularColor = min ( pow2 ( ( material . ior - 1.0 ) / ( material . ior + 1.0 ) ) * specularColorFactor , vec3 ( 1.0 ) ) * specularIntensityFactor ;
material . specularColorBlended = mix ( material . specularColor , diffuseColor . rgb , metalnessFactor ) ;
# else
material . specularColor = vec3 ( 0.04 ) ;
material . specularColorBlended = mix ( material . specularColor , diffuseColor . rgb , metalnessFactor ) ;
material . specularF90 = 1.0 ;
# endif
# ifdef USE _CLEARCOAT
material . clearcoat = clearcoat ;
material . clearcoatRoughness = clearcoatRoughness ;
material . clearcoatF0 = vec3 ( 0.04 ) ;
material . clearcoatF90 = 1.0 ;
# ifdef USE _CLEARCOATMAP
material . clearcoat *= texture2D ( clearcoatMap , vClearcoatMapUv ) . x ;
# endif
# ifdef USE _CLEARCOAT _ROUGHNESSMAP
material . clearcoatRoughness *= texture2D ( clearcoatRoughnessMap , vClearcoatRoughnessMapUv ) . y ;
# endif
material . clearcoat = saturate ( material . clearcoat ) ; material . clearcoatRoughness = max ( material . clearcoatRoughness , 0.0525 ) ;
material . clearcoatRoughness += geometryRoughness ;
material . clearcoatRoughness = min ( material . clearcoatRoughness , 1.0 ) ;
# endif
# ifdef USE _DISPERSION
material . dispersion = dispersion ;
# endif
# ifdef USE _IRIDESCENCE
material . iridescence = iridescence ;
material . iridescenceIOR = iridescenceIOR ;
# ifdef USE _IRIDESCENCEMAP
material . iridescence *= texture2D ( iridescenceMap , vIridescenceMapUv ) . r ;
# endif
# ifdef USE _IRIDESCENCE _THICKNESSMAP
material . iridescenceThickness = ( iridescenceThicknessMaximum - iridescenceThicknessMinimum ) * texture2D ( iridescenceThicknessMap , vIridescenceThicknessMapUv ) . g + iridescenceThicknessMinimum ;
# else
material . iridescenceThickness = iridescenceThicknessMaximum ;
# endif
# endif
# ifdef USE _SHEEN
material . sheenColor = sheenColor ;
# ifdef USE _SHEEN _COLORMAP
material . sheenColor *= texture2D ( sheenColorMap , vSheenColorMapUv ) . rgb ;
# endif
material . sheenRoughness = clamp ( sheenRoughness , 0.0001 , 1.0 ) ;
# ifdef USE _SHEEN _ROUGHNESSMAP
material . sheenRoughness *= texture2D ( sheenRoughnessMap , vSheenRoughnessMapUv ) . a ;
# endif
# endif
# ifdef USE _ANISOTROPY
# ifdef USE _ANISOTROPYMAP
mat2 anisotropyMat = mat2 ( anisotropyVector . x , anisotropyVector . y , - anisotropyVector . y , anisotropyVector . x ) ;
vec3 anisotropyPolar = texture2D ( anisotropyMap , vAnisotropyMapUv ) . rgb ;
vec2 anisotropyV = anisotropyMat * normalize ( 2.0 * anisotropyPolar . rg - vec2 ( 1.0 ) ) * anisotropyPolar . b ;
# else
vec2 anisotropyV = anisotropyVector ;
# endif
material . anisotropy = length ( anisotropyV ) ;
if ( material . anisotropy == 0.0 ) {
anisotropyV = vec2 ( 1.0 , 0.0 ) ;
} else {
anisotropyV /= material . anisotropy ;
material . anisotropy = saturate ( material . anisotropy ) ;
}
material . alphaT = mix ( pow2 ( material . roughness ) , 1.0 , pow2 ( material . anisotropy ) ) ;
material . anisotropyT = tbn [ 0 ] * anisotropyV . x + tbn [ 1 ] * anisotropyV . y ;
material . anisotropyB = tbn [ 1 ] * anisotropyV . x - tbn [ 0 ] * anisotropyV . y ;
# endif ` ,lights_physical_pars_fragment: ` uniform sampler2D dfgLUT ;
struct PhysicalMaterial {
vec3 diffuseColor ;
vec3 diffuseContribution ;
vec3 specularColor ;
vec3 specularColorBlended ;
float roughness ;
float metalness ;
float specularF90 ;
float dispersion ;
# ifdef USE _CLEARCOAT
float clearcoat ;
float clearcoatRoughness ;
vec3 clearcoatF0 ;
float clearcoatF90 ;
# endif
# ifdef USE _IRIDESCENCE
float iridescence ;
float iridescenceIOR ;
float iridescenceThickness ;
vec3 iridescenceFresnel ;
vec3 iridescenceF0 ;
vec3 iridescenceFresnelDielectric ;
vec3 iridescenceFresnelMetallic ;
# endif
# ifdef USE _SHEEN
vec3 sheenColor ;
float sheenRoughness ;
# endif
# ifdef IOR
float ior ;
# endif
# ifdef USE _TRANSMISSION
float transmission ;
float transmissionAlpha ;
float thickness ;
float attenuationDistance ;
vec3 attenuationColor ;
# endif
# ifdef USE _ANISOTROPY
float anisotropy ;
float alphaT ;
vec3 anisotropyT ;
vec3 anisotropyB ;
# endif
} ;
vec3 clearcoatSpecularDirect = vec3 ( 0.0 ) ;
vec3 clearcoatSpecularIndirect = vec3 ( 0.0 ) ;
vec3 sheenSpecularDirect = vec3 ( 0.0 ) ;
vec3 sheenSpecularIndirect = vec3 ( 0.0 ) ;
vec3 Schlick _to _F0 ( const in vec3 f , const in float f90 , const in float dotVH ) {
float x = clamp ( 1.0 - dotVH , 0.0 , 1.0 ) ;
float x2 = x * x ;
float x5 = clamp ( x * x2 * x2 , 0.0 , 0.9999 ) ;
return ( f - vec3 ( f90 ) * x5 ) / ( 1.0 - x5 ) ;
}
float V _GGX _SmithCorrelated ( const in float alpha , const in float dotNL , const in float dotNV ) {
float a2 = pow2 ( alpha ) ;
float gv = dotNL * sqrt ( a2 + ( 1.0 - a2 ) * pow2 ( dotNV ) ) ;
float gl = dotNV * sqrt ( a2 + ( 1.0 - a2 ) * pow2 ( dotNL ) ) ;
return 0.5 / max ( gv + gl , EPSILON ) ;
}
float D _GGX ( const in float alpha , const in float dotNH ) {
float a2 = pow2 ( alpha ) ;
float denom = pow2 ( dotNH ) * ( a2 - 1.0 ) + 1.0 ;
return RECIPROCAL _PI * a2 / pow2 ( denom ) ;
}
# ifdef USE _ANISOTROPY
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 ) {
float gv = dotNL * length ( vec3 ( alphaT * dotTV , alphaB * dotBV , dotNV ) ) ;
float gl = dotNV * length ( vec3 ( alphaT * dotTL , alphaB * dotBL , dotNL ) ) ;
float v = 0.5 / ( gv + gl ) ;
return v ;
}
float D _GGX _Anisotropic ( const in float alphaT , const in float alphaB , const in float dotNH , const in float dotTH , const in float dotBH ) {
float a2 = alphaT * alphaB ;
highp vec3 v = vec3 ( alphaB * dotTH , alphaT * dotBH , a2 * dotNH ) ;
highp float v2 = dot ( v , v ) ;
float w2 = a2 / v2 ;
return RECIPROCAL _PI * a2 * pow2 ( w2 ) ;
}
# endif
# ifdef USE _CLEARCOAT
vec3 BRDF _GGX _Clearcoat ( const in vec3 lightDir , const in vec3 viewDir , const in vec3 normal , const in PhysicalMaterial material ) {
vec3 f0 = material . clearcoatF0 ;
float f90 = material . clearcoatF90 ;
float roughness = material . clearcoatRoughness ;
float alpha = pow2 ( roughness ) ;
vec3 halfDir = normalize ( lightDir + viewDir ) ;
float dotNL = saturate ( dot ( normal , lightDir ) ) ;
float dotNV = saturate ( dot ( normal , viewDir ) ) ;
float dotNH = saturate ( dot ( normal , halfDir ) ) ;
float dotVH = saturate ( dot ( viewDir , halfDir ) ) ;
vec3 F = F _Schlick ( f0 , f90 , dotVH ) ;
float V = V _GGX _SmithCorrelated ( alpha , dotNL , dotNV ) ;
float D = D _GGX ( alpha , dotNH ) ;
return F * ( V * D ) ;
}
# endif
vec3 BRDF _GGX ( const in vec3 lightDir , const in vec3 viewDir , const in vec3 normal , const in PhysicalMaterial material ) {
vec3 f0 = material . specularColorBlended ;
float f90 = material . specularF90 ;
float roughness = material . roughness ;
float alpha = pow2 ( roughness ) ;
vec3 halfDir = normalize ( lightDir + viewDir ) ;
float dotNL = saturate ( dot ( normal , lightDir ) ) ;
float dotNV = saturate ( dot ( normal , viewDir ) ) ;
float dotNH = saturate ( dot ( normal , halfDir ) ) ;
float dotVH = saturate ( dot ( viewDir , halfDir ) ) ;
vec3 F = F _Schlick ( f0 , f90 , dotVH ) ;
# ifdef USE _IRIDESCENCE
F = mix ( F , material . iridescenceFresnel , material . iridescence ) ;
# endif
# ifdef USE _ANISOTROPY
float dotTL = dot ( material . anisotropyT , lightDir ) ;
float dotTV = dot ( material . anisotropyT , viewDir ) ;
float dotTH = dot ( material . anisotropyT , halfDir ) ;
float dotBL = dot ( material . anisotropyB , lightDir ) ;
float dotBV = dot ( material . anisotropyB , viewDir ) ;
float dotBH = dot ( material . anisotropyB , halfDir ) ;
float V = V _GGX _SmithCorrelated _Anisotropic ( material . alphaT , alpha , dotTV , dotBV , dotTL , dotBL , dotNV , dotNL ) ;
float D = D _GGX _Anisotropic ( material . alphaT , alpha , dotNH , dotTH , dotBH ) ;
# else
float V = V _GGX _SmithCorrelated ( alpha , dotNL , dotNV ) ;
float D = D _GGX ( alpha , dotNH ) ;
# endif
return F * ( V * D ) ;
}
vec2 LTC _Uv ( const in vec3 N , const in vec3 V , const in float roughness ) {
const float LUT _SIZE = 64.0 ;
const float LUT _SCALE = ( LUT _SIZE - 1.0 ) / LUT _SIZE ;
const float LUT _BIAS = 0.5 / LUT _SIZE ;
float dotNV = saturate ( dot ( N , V ) ) ;
vec2 uv = vec2 ( roughness , sqrt ( 1.0 - dotNV ) ) ;
uv = uv * LUT _SCALE + LUT _BIAS ;
return uv ;
}
float LTC _ClippedSphereFormFactor ( const in vec3 f ) {
float l = length ( f ) ;
return max ( ( l * l + f . z ) / ( l + 1.0 ) , 0.0 ) ;
}
vec3 LTC _EdgeVectorFormFactor ( const in vec3 v1 , const in vec3 v2 ) {
float x = dot ( v1 , v2 ) ;
float y = abs ( x ) ;
float a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y ;
float b = 3.4175940 + ( 4.1616724 + y ) * y ;
float v = a / b ;
float theta _sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt ( max ( 1.0 - x * x , 1e-7 ) ) - v ;
return cross ( v1 , v2 ) * theta _sintheta ;
}
vec3 LTC _Evaluate ( const in vec3 N , const in vec3 V , const in vec3 P , const in mat3 mInv , const in vec3 rectCoords [ 4 ] ) {
vec3 v1 = rectCoords [ 1 ] - rectCoords [ 0 ] ;
vec3 v2 = rectCoords [ 3 ] - rectCoords [ 0 ] ;
vec3 lightNormal = cross ( v1 , v2 ) ;
if ( dot ( lightNormal , P - rectCoords [ 0 ] ) < 0.0 ) return vec3 ( 0.0 ) ;
vec3 T1 , T2 ;
T1 = normalize ( V - N * dot ( V , N ) ) ;
T2 = - cross ( N , T1 ) ;
mat3 mat = mInv * transpose ( mat3 ( T1 , T2 , N ) ) ;
vec3 coords [ 4 ] ;
coords [ 0 ] = mat * ( rectCoords [ 0 ] - P ) ;
coords [ 1 ] = mat * ( rectCoords [ 1 ] - P ) ;
coords [ 2 ] = mat * ( rectCoords [ 2 ] - P ) ;
coords [ 3 ] = mat * ( rectCoords [ 3 ] - P ) ;
coords [ 0 ] = normalize ( coords [ 0 ] ) ;
coords [ 1 ] = normalize ( coords [ 1 ] ) ;
coords [ 2 ] = normalize ( coords [ 2 ] ) ;
coords [ 3 ] = normalize ( coords [ 3 ] ) ;
vec3 vectorFormFactor = vec3 ( 0.0 ) ;
vectorFormFactor += LTC _EdgeVectorFormFactor ( coords [ 0 ] , coords [ 1 ] ) ;
vectorFormFactor += LTC _EdgeVectorFormFactor ( coords [ 1 ] , coords [ 2 ] ) ;
vectorFormFactor += LTC _EdgeVectorFormFactor ( coords [ 2 ] , coords [ 3 ] ) ;
vectorFormFactor += LTC _EdgeVectorFormFactor ( coords [ 3 ] , coords [ 0 ] ) ;
float result = LTC _ClippedSphereFormFactor ( vectorFormFactor ) ;
return vec3 ( result ) ;
}
# if defined ( USE _SHEEN )
float D _Charlie ( float roughness , float dotNH ) {
float alpha = pow2 ( roughness ) ;
float invAlpha = 1.0 / alpha ;
float cos2h = dotNH * dotNH ;
float sin2h = max ( 1.0 - cos2h , 0.0078125 ) ;
return ( 2.0 + invAlpha ) * pow ( sin2h , invAlpha * 0.5 ) / ( 2.0 * PI ) ;
}
float V _Neubelt ( float dotNV , float dotNL ) {
return saturate ( 1.0 / ( 4.0 * ( dotNL + dotNV - dotNL * dotNV ) ) ) ;
}
vec3 BRDF _Sheen ( const in vec3 lightDir , const in vec3 viewDir , const in vec3 normal , vec3 sheenColor , const in float sheenRoughness ) {
vec3 halfDir = normalize ( lightDir + viewDir ) ;
float dotNL = saturate ( dot ( normal , lightDir ) ) ;
float dotNV = saturate ( dot ( normal , viewDir ) ) ;
float dotNH = saturate ( dot ( normal , halfDir ) ) ;
float D = D _Charlie ( sheenRoughness , dotNH ) ;
float V = V _Neubelt ( dotNV , dotNL ) ;
return sheenColor * ( D * V ) ;
}
# endif
float IBLSheenBRDF ( const in vec3 normal , const in vec3 viewDir , const in float roughness ) {
float dotNV = saturate ( dot ( normal , viewDir ) ) ;
float r2 = roughness * roughness ;
float rInv = 1.0 / ( roughness + 0.1 ) ;
float a = - 1.9362 + 1.0678 * roughness + 0.4573 * r2 - 0.8469 * rInv ;
float b = - 0.6014 + 0.5538 * roughness - 0.4670 * r2 - 0.1255 * rInv ;
float DG = exp ( a * dotNV + b ) ;
return saturate ( DG ) ;
}
vec3 EnvironmentBRDF ( const in vec3 normal , const in vec3 viewDir , const in vec3 specularColor , const in float specularF90 , const in float roughness ) {
float dotNV = saturate ( dot ( normal , viewDir ) ) ;
vec2 fab = texture2D ( dfgLUT , vec2 ( roughness , dotNV ) ) . rg ;
return specularColor * fab . x + specularF90 * fab . y ;
}
# ifdef USE _IRIDESCENCE
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 ) {
# else
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 ) {
# endif
float dotNV = saturate ( dot ( normal , viewDir ) ) ;
vec2 fab = texture2D ( dfgLUT , vec2 ( roughness , dotNV ) ) . rg ;
# ifdef USE _IRIDESCENCE
vec3 Fr = mix ( specularColor , iridescenceF0 , iridescence ) ;
# else
vec3 Fr = specularColor ;
# endif
vec3 FssEss = Fr * fab . x + specularF90 * fab . y ;
float Ess = fab . x + fab . y ;
float Ems = 1.0 - Ess ;
vec3 Favg = Fr + ( 1.0 - Fr ) * 0.047619 ; vec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg ) ;
singleScatter += FssEss ;
multiScatter += Fms * Ems ;
}
vec3 BRDF _GGX _Multiscatter ( const in vec3 lightDir , const in vec3 viewDir , const in vec3 normal , const in PhysicalMaterial material ) {
vec3 singleScatter = BRDF _GGX ( lightDir , viewDir , normal , material ) ;
float dotNL = saturate ( dot ( normal , lightDir ) ) ;
float dotNV = saturate ( dot ( normal , viewDir ) ) ;
vec2 dfgV = texture2D ( dfgLUT , vec2 ( material . roughness , dotNV ) ) . rg ;
vec2 dfgL = texture2D ( dfgLUT , vec2 ( material . roughness , dotNL ) ) . rg ;
vec3 FssEss _V = material . specularColorBlended * dfgV . x + material . specularF90 * dfgV . y ;
vec3 FssEss _L = material . specularColorBlended * dfgL . x + material . specularF90 * dfgL . y ;
float Ess _V = dfgV . x + dfgV . y ;
float Ess _L = dfgL . x + dfgL . y ;
float Ems _V = 1.0 - Ess _V ;
float Ems _L = 1.0 - Ess _L ;
vec3 Favg = material . specularColorBlended + ( 1.0 - material . specularColorBlended ) * 0.047619 ;
vec3 Fms = FssEss _V * FssEss _L * Favg / ( 1.0 - Ems _V * Ems _L * Favg + EPSILON ) ;
float compensationFactor = Ems _V * Ems _L ;
vec3 multiScatter = Fms * compensationFactor ;
return singleScatter + multiScatter ;
}
# if NUM _RECT _AREA _LIGHTS > 0
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 ) {
vec3 normal = geometryNormal ;
vec3 viewDir = geometryViewDir ;
vec3 position = geometryPosition ;
vec3 lightPos = rectAreaLight . position ;
vec3 halfWidth = rectAreaLight . halfWidth ;
vec3 halfHeight = rectAreaLight . halfHeight ;
vec3 lightColor = rectAreaLight . color ;
float roughness = material . roughness ;
vec3 rectCoords [ 4 ] ;
rectCoords [ 0 ] = lightPos + halfWidth - halfHeight ; rectCoords [ 1 ] = lightPos - halfWidth - halfHeight ;
rectCoords [ 2 ] = lightPos - halfWidth + halfHeight ;
rectCoords [ 3 ] = lightPos + halfWidth + halfHeight ;
vec2 uv = LTC _Uv ( normal , viewDir , roughness ) ;
vec4 t1 = texture2D ( ltc _1 , uv ) ;
vec4 t2 = texture2D ( ltc _2 , uv ) ;
mat3 mInv = mat3 (
vec3 ( t1 . x , 0 , t1 . y ) ,
vec3 ( 0 , 1 , 0 ) ,
vec3 ( t1 . z , 0 , t1 . w )
) ;
vec3 fresnel = ( material . specularColorBlended * t2 . x + ( vec3 ( 1.0 ) - material . specularColorBlended ) * t2 . y ) ;
reflectedLight . directSpecular += lightColor * fresnel * LTC _Evaluate ( normal , viewDir , position , mInv , rectCoords ) ;
reflectedLight . directDiffuse += lightColor * material . diffuseContribution * LTC _Evaluate ( normal , viewDir , position , mat3 ( 1.0 ) , rectCoords ) ;
}
# endif
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 ) {
float dotNL = saturate ( dot ( geometryNormal , directLight . direction ) ) ;
vec3 irradiance = dotNL * directLight . color ;
# ifdef USE _CLEARCOAT
float dotNLcc = saturate ( dot ( geometryClearcoatNormal , directLight . direction ) ) ;
vec3 ccIrradiance = dotNLcc * directLight . color ;
clearcoatSpecularDirect += ccIrradiance * BRDF _GGX _Clearcoat ( directLight . direction , geometryViewDir , geometryClearcoatNormal , material ) ;
# endif
# ifdef USE _SHEEN
sheenSpecularDirect += irradiance * BRDF _Sheen ( directLight . direction , geometryViewDir , geometryNormal , material . sheenColor , material . sheenRoughness ) ;
float sheenAlbedoV = IBLSheenBRDF ( geometryNormal , geometryViewDir , material . sheenRoughness ) ;
float sheenAlbedoL = IBLSheenBRDF ( geometryNormal , directLight . direction , material . sheenRoughness ) ;
float sheenEnergyComp = 1.0 - max3 ( material . sheenColor ) * max ( sheenAlbedoV , sheenAlbedoL ) ;
irradiance *= sheenEnergyComp ;
# endif
reflectedLight . directSpecular += irradiance * BRDF _GGX _Multiscatter ( directLight . direction , geometryViewDir , geometryNormal , material ) ;
reflectedLight . directDiffuse += irradiance * BRDF _Lambert ( material . diffuseContribution ) ;
}
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 ) {
vec3 diffuse = irradiance * BRDF _Lambert ( material . diffuseContribution ) ;
# ifdef USE _SHEEN
float sheenAlbedo = IBLSheenBRDF ( geometryNormal , geometryViewDir , material . sheenRoughness ) ;
float sheenEnergyComp = 1.0 - max3 ( material . sheenColor ) * sheenAlbedo ;
diffuse *= sheenEnergyComp ;
# endif
reflectedLight . indirectDiffuse += diffuse ;
}
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 ) {
# ifdef USE _CLEARCOAT
clearcoatSpecularIndirect += clearcoatRadiance * EnvironmentBRDF ( geometryClearcoatNormal , geometryViewDir , material . clearcoatF0 , material . clearcoatF90 , material . clearcoatRoughness ) ;
# endif
# ifdef USE _SHEEN
sheenSpecularIndirect += irradiance * material . sheenColor * IBLSheenBRDF ( geometryNormal , geometryViewDir , material . sheenRoughness ) * RECIPROCAL _PI ;
# endif
vec3 singleScatteringDielectric = vec3 ( 0.0 ) ;
vec3 multiScatteringDielectric = vec3 ( 0.0 ) ;
vec3 singleScatteringMetallic = vec3 ( 0.0 ) ;
vec3 multiScatteringMetallic = vec3 ( 0.0 ) ;
# ifdef USE _IRIDESCENCE
computeMultiscatteringIridescence ( geometryNormal , geometryViewDir , material . specularColor , material . specularF90 , material . iridescence , material . iridescenceFresnelDielectric , material . roughness , singleScatteringDielectric , multiScatteringDielectric ) ;
computeMultiscatteringIridescence ( geometryNormal , geometryViewDir , material . diffuseColor , material . specularF90 , material . iridescence , material . iridescenceFresnelMetallic , material . roughness , singleScatteringMetallic , multiScatteringMetallic ) ;
# else
computeMultiscattering ( geometryNormal , geometryViewDir , material . specularColor , material . specularF90 , material . roughness , singleScatteringDielectric , multiScatteringDielectric ) ;
computeMultiscattering ( geometryNormal , geometryViewDir , material . diffuseColor , material . specularF90 , material . roughness , singleScatteringMetallic , multiScatteringMetallic ) ;
# endif
vec3 singleScattering = mix ( singleScatteringDielectric , singleScatteringMetallic , material . metalness ) ;
vec3 multiScattering = mix ( multiScatteringDielectric , multiScatteringMetallic , material . metalness ) ;
vec3 totalScatteringDielectric = singleScatteringDielectric + multiScatteringDielectric ;
vec3 diffuse = material . diffuseContribution * ( 1.0 - totalScatteringDielectric ) ;
vec3 cosineWeightedIrradiance = irradiance * RECIPROCAL _PI ;
vec3 indirectSpecular = radiance * singleScattering ;
indirectSpecular += multiScattering * cosineWeightedIrradiance ;
vec3 indirectDiffuse = diffuse * cosineWeightedIrradiance ;
# ifdef USE _SHEEN
float sheenAlbedo = IBLSheenBRDF ( geometryNormal , geometryViewDir , material . sheenRoughness ) ;
float sheenEnergyComp = 1.0 - max3 ( material . sheenColor ) * sheenAlbedo ;
indirectSpecular *= sheenEnergyComp ;
indirectDiffuse *= sheenEnergyComp ;
# endif
reflectedLight . indirectSpecular += indirectSpecular ;
reflectedLight . indirectDiffuse += indirectDiffuse ;
}
# define RE _Direct RE _Direct _Physical
# define RE _Direct _RectArea RE _Direct _RectArea _Physical
# define RE _IndirectDiffuse RE _IndirectDiffuse _Physical
# define RE _IndirectSpecular RE _IndirectSpecular _Physical
float computeSpecularOcclusion ( const in float dotNV , const in float ambientOcclusion , const in float roughness ) {
return saturate ( pow ( dotNV + ambientOcclusion , exp2 ( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion ) ;
} ` ,lights_fragment_begin: `
vec3 geometryPosition = - vViewPosition ;
vec3 geometryNormal = normal ;
vec3 geometryViewDir = ( isOrthographic ) ? vec3 ( 0 , 0 , 1 ) : normalize ( vViewPosition ) ;
vec3 geometryClearcoatNormal = vec3 ( 0.0 ) ;
# ifdef USE _CLEARCOAT
geometryClearcoatNormal = clearcoatNormal ;
# endif
# ifdef USE _IRIDESCENCE
float dotNVi = saturate ( dot ( normal , geometryViewDir ) ) ;
if ( material . iridescenceThickness == 0.0 ) {
material . iridescence = 0.0 ;
} else {
material . iridescence = saturate ( material . iridescence ) ;
}
if ( material . iridescence > 0.0 ) {
material . iridescenceFresnelDielectric = evalIridescence ( 1.0 , material . iridescenceIOR , dotNVi , material . iridescenceThickness , material . specularColor ) ;
material . iridescenceFresnelMetallic = evalIridescence ( 1.0 , material . iridescenceIOR , dotNVi , material . iridescenceThickness , material . diffuseColor ) ;
material . iridescenceFresnel = mix ( material . iridescenceFresnelDielectric , material . iridescenceFresnelMetallic , material . metalness ) ;
material . iridescenceF0 = Schlick _to _F0 ( material . iridescenceFresnel , 1.0 , dotNVi ) ;
}
# endif
IncidentLight directLight ;
# if ( NUM _POINT _LIGHTS > 0 ) && defined ( RE _Direct )
PointLight pointLight ;
# if defined ( USE _SHADOWMAP ) && NUM _POINT _LIGHT _SHADOWS > 0
PointLightShadow pointLightShadow ;
# endif
# pragma unroll _loop _start
for ( int i = 0 ; i < NUM _POINT _LIGHTS ; i ++ ) {
pointLight = pointLights [ i ] ;
getPointLightInfo ( pointLight , geometryPosition , directLight ) ;
# if defined ( USE _SHADOWMAP ) && ( UNROLLED _LOOP _INDEX < NUM _POINT _LIGHT _SHADOWS ) && ( defined ( SHADOWMAP _TYPE _PCF ) || defined ( SHADOWMAP _TYPE _BASIC ) )
pointLightShadow = pointLightShadows [ i ] ;
directLight . color *= ( directLight . visible && receiveShadow ) ? getPointShadow ( pointShadowMap [ i ] , pointLightShadow . shadowMapSize , pointLightShadow . shadowIntensity , pointLightShadow . shadowBias , pointLightShadow . shadowRadius , vPointShadowCoord [ i ] , pointLightShadow . shadowCameraNear , pointLightShadow . shadowCameraFar ) : 1.0 ;
# endif
RE _Direct ( directLight , geometryPosition , geometryNormal , geometryViewDir , geometryClearcoatNormal , material , reflectedLight ) ;
}
# pragma unroll _loop _end
# endif
# if ( NUM _SPOT _LIGHTS > 0 ) && defined ( RE _Direct )
SpotLight spotLight ;
vec4 spotColor ;
vec3 spotLightCoord ;
bool inSpotLightMap ;
# if defined ( USE _SHADOWMAP ) && NUM _SPOT _LIGHT _SHADOWS > 0
SpotLightShadow spotLightShadow ;
# endif
# pragma unroll _loop _start
for ( int i = 0 ; i < NUM _SPOT _LIGHTS ; i ++ ) {
spotLight = spotLights [ i ] ;
getSpotLightInfo ( spotLight , geometryPosition , directLight ) ;
# if ( UNROLLED _LOOP _INDEX < NUM _SPOT _LIGHT _SHADOWS _WITH _MAPS )
# define SPOT _LIGHT _MAP _INDEX UNROLLED _LOOP _INDEX
# elif ( UNROLLED _LOOP _INDEX < NUM _SPOT _LIGHT _SHADOWS )
# define SPOT _LIGHT _MAP _INDEX NUM _SPOT _LIGHT _MAPS
# else
# define SPOT _LIGHT _MAP _INDEX ( UNROLLED _LOOP _INDEX - NUM _SPOT _LIGHT _SHADOWS + NUM _SPOT _LIGHT _SHADOWS _WITH _MAPS )
# endif
# if ( SPOT _LIGHT _MAP _INDEX < NUM _SPOT _LIGHT _MAPS )
spotLightCoord = vSpotLightCoord [ i ] . xyz / vSpotLightCoord [ i ] . w ;
inSpotLightMap = all ( lessThan ( abs ( spotLightCoord * 2. - 1. ) , vec3 ( 1.0 ) ) ) ;
spotColor = texture2D ( spotLightMap [ SPOT _LIGHT _MAP _INDEX ] , spotLightCoord . xy ) ;
directLight . color = inSpotLightMap ? directLight . color * spotColor . rgb : directLight . color ;
# endif
# undef SPOT _LIGHT _MAP _INDEX
# if defined ( USE _SHADOWMAP ) && ( UNROLLED _LOOP _INDEX < NUM _SPOT _LIGHT _SHADOWS )
spotLightShadow = spotLightShadows [ i ] ;
directLight . color *= ( directLight . visible && receiveShadow ) ? getShadow ( spotShadowMap [ i ] , spotLightShadow . shadowMapSize , spotLightShadow . shadowIntensity , spotLightShadow . shadowBias , spotLightShadow . shadowRadius , vSpotLightCoord [ i ] ) : 1.0 ;
# endif
RE _Direct ( directLight , geometryPosition , geometryNormal , geometryViewDir , geometryClearcoatNormal , material , reflectedLight ) ;
}
# pragma unroll _loop _end
# endif
# if ( NUM _DIR _LIGHTS > 0 ) && defined ( RE _Direct )
DirectionalLight directionalLight ;
# if defined ( USE _SHADOWMAP ) && NUM _DIR _LIGHT _SHADOWS > 0
DirectionalLightShadow directionalLightShadow ;
# endif
# pragma unroll _loop _start
for ( int i = 0 ; i < NUM _DIR _LIGHTS ; i ++ ) {
directionalLight = directionalLights [ i ] ;
getDirectionalLightInfo ( directionalLight , directLight ) ;
# if defined ( USE _SHADOWMAP ) && ( UNROLLED _LOOP _INDEX < NUM _DIR _LIGHT _SHADOWS )
directionalLightShadow = directionalLightShadows [ i ] ;
directLight . color *= ( directLight . visible && receiveShadow ) ? getShadow ( directionalShadowMap [ i ] , directionalLightShadow . shadowMapSize , directionalLightShadow . shadowIntensity , directionalLightShadow . shadowBias , directionalLightShadow . shadowRadius , vDirectionalShadowCoord [ i ] ) : 1.0 ;
# endif
RE _Direct ( directLight , geometryPosition , geometryNormal , geometryViewDir , geometryClearcoatNormal , material , reflectedLight ) ;
}
# pragma unroll _loop _end
# endif
# if ( NUM _RECT _AREA _LIGHTS > 0 ) && defined ( RE _Direct _RectArea )
RectAreaLight rectAreaLight ;
# pragma unroll _loop _start
for ( int i = 0 ; i < NUM _RECT _AREA _LIGHTS ; i ++ ) {
rectAreaLight = rectAreaLights [ i ] ;
RE _Direct _RectArea ( rectAreaLight , geometryPosition , geometryNormal , geometryViewDir , geometryClearcoatNormal , material , reflectedLight ) ;
}
# pragma unroll _loop _end
# endif
# if defined ( RE _IndirectDiffuse )
vec3 iblIrradiance = vec3 ( 0.0 ) ;
vec3 irradiance = getAmbientLightIrradiance ( ambientLightColor ) ;
# if defined ( USE _LIGHT _PROBES )
irradiance += getLightProbeIrradiance ( lightProbe , geometryNormal ) ;
# endif
# if ( NUM _HEMI _LIGHTS > 0 )
# pragma unroll _loop _start
for ( int i = 0 ; i < NUM _HEMI _LIGHTS ; i ++ ) {
irradiance += getHemisphereLightIrradiance ( hemisphereLights [ i ] , geometryNormal ) ;
}
# pragma unroll _loop _end
# endif
# endif
# if defined ( RE _IndirectSpecular )
vec3 radiance = vec3 ( 0.0 ) ;
vec3 clearcoatRadiance = vec3 ( 0.0 ) ;
# endif ` ,lights_fragment_maps: ` # if defined ( RE _IndirectDiffuse )
# ifdef USE _LIGHTMAP
vec4 lightMapTexel = texture2D ( lightMap , vLightMapUv ) ;
vec3 lightMapIrradiance = lightMapTexel . rgb * lightMapIntensity ;
irradiance += lightMapIrradiance ;
# endif
# if defined ( USE _ENVMAP ) && defined ( STANDARD ) && defined ( ENVMAP _TYPE _CUBE _UV )
iblIrradiance += getIBLIrradiance ( geometryNormal ) ;
# endif
# endif
# if defined ( USE _ENVMAP ) && defined ( RE _IndirectSpecular )
# ifdef USE _ANISOTROPY
radiance += getIBLAnisotropyRadiance ( geometryViewDir , geometryNormal , material . roughness , material . anisotropyB , material . anisotropy ) ;
# else
radiance += getIBLRadiance ( geometryViewDir , geometryNormal , material . roughness ) ;
# endif
# ifdef USE _CLEARCOAT
clearcoatRadiance += getIBLRadiance ( geometryViewDir , geometryClearcoatNormal , material . clearcoatRoughness ) ;
# endif
# endif ` ,lights_fragment_end: ` # if defined ( RE _IndirectDiffuse )
RE _IndirectDiffuse ( irradiance , geometryPosition , geometryNormal , geometryViewDir , geometryClearcoatNormal , material , reflectedLight ) ;
# endif
# if defined ( RE _IndirectSpecular )
RE _IndirectSpecular ( radiance , iblIrradiance , clearcoatRadiance , geometryPosition , geometryNormal , geometryViewDir , geometryClearcoatNormal , material , reflectedLight ) ;
# endif ` ,logdepthbuf_fragment: ` # if defined ( USE _LOGARITHMIC _DEPTH _BUFFER )
gl _FragDepth = vIsPerspective == 0.0 ? gl _FragCoord . z : log2 ( vFragDepth ) * logDepthBufFC * 0.5 ;
# endif ` ,logdepthbuf_pars_fragment: ` # if defined ( USE _LOGARITHMIC _DEPTH _BUFFER )
uniform float logDepthBufFC ;
varying float vFragDepth ;
varying float vIsPerspective ;
# endif ` ,logdepthbuf_pars_vertex: ` # ifdef USE _LOGARITHMIC _DEPTH _BUFFER
varying float vFragDepth ;
varying float vIsPerspective ;
# endif ` ,logdepthbuf_vertex: ` # ifdef USE _LOGARITHMIC _DEPTH _BUFFER
vFragDepth = 1.0 + gl _Position . w ;
vIsPerspective = float ( isPerspectiveMatrix ( projectionMatrix ) ) ;
# endif ` ,map_fragment: ` # ifdef USE _MAP
vec4 sampledDiffuseColor = texture2D ( map , vMapUv ) ;
# ifdef DECODE _VIDEO _TEXTURE
sampledDiffuseColor = sRGBTransferEOTF ( sampledDiffuseColor ) ;
# endif
diffuseColor *= sampledDiffuseColor ;
# endif ` ,map_pars_fragment: ` # ifdef USE _MAP
uniform sampler2D map ;
# endif ` ,map_particle_fragment: ` # if defined ( USE _MAP ) || defined ( USE _ALPHAMAP )
# if defined ( USE _POINTS _UV )
vec2 uv = vUv ;
# else
vec2 uv = ( uvTransform * vec3 ( gl _PointCoord . x , 1.0 - gl _PointCoord . y , 1 ) ) . xy ;
# endif
# endif
# ifdef USE _MAP
diffuseColor *= texture2D ( map , uv ) ;
# endif
# ifdef USE _ALPHAMAP
diffuseColor . a *= texture2D ( alphaMap , uv ) . g ;
# endif ` ,map_particle_pars_fragment: ` # if defined ( USE _POINTS _UV )
varying vec2 vUv ;
# else
# if defined ( USE _MAP ) || defined ( USE _ALPHAMAP )
uniform mat3 uvTransform ;
# endif
# endif
# ifdef USE _MAP
uniform sampler2D map ;
# endif
# ifdef USE _ALPHAMAP
uniform sampler2D alphaMap ;
# endif ` ,metalnessmap_fragment: ` float metalnessFactor = metalness ;
# ifdef USE _METALNESSMAP
vec4 texelMetalness = texture2D ( metalnessMap , vMetalnessMapUv ) ;
metalnessFactor *= texelMetalness . b ;
# endif ` ,metalnessmap_pars_fragment: ` # ifdef USE _METALNESSMAP
uniform sampler2D metalnessMap ;
# endif ` ,morphinstance_vertex: ` # ifdef USE _INSTANCING _MORPH
float morphTargetInfluences [ MORPHTARGETS _COUNT ] ;
float morphTargetBaseInfluence = texelFetch ( morphTexture , ivec2 ( 0 , gl _InstanceID ) , 0 ) . r ;
for ( int i = 0 ; i < MORPHTARGETS _COUNT ; i ++ ) {
morphTargetInfluences [ i ] = texelFetch ( morphTexture , ivec2 ( i + 1 , gl _InstanceID ) , 0 ) . r ;
}
# endif ` ,morphcolor_vertex: ` # if defined ( USE _MORPHCOLORS )
vColor *= morphTargetBaseInfluence ;
for ( int i = 0 ; i < MORPHTARGETS _COUNT ; i ++ ) {
# if defined ( USE _COLOR _ALPHA )
if ( morphTargetInfluences [ i ] != 0.0 ) vColor += getMorph ( gl _VertexID , i , 2 ) * morphTargetInfluences [ i ] ;
# elif defined ( USE _COLOR )
if ( morphTargetInfluences [ i ] != 0.0 ) vColor += getMorph ( gl _VertexID , i , 2 ) . rgb * morphTargetInfluences [ i ] ;
# endif
}
# endif ` ,morphnormal_vertex: ` # ifdef USE _MORPHNORMALS
objectNormal *= morphTargetBaseInfluence ;
for ( int i = 0 ; i < MORPHTARGETS _COUNT ; i ++ ) {
if ( morphTargetInfluences [ i ] != 0.0 ) objectNormal += getMorph ( gl _VertexID , i , 1 ) . xyz * morphTargetInfluences [ i ] ;
}
# endif ` ,morphtarget_pars_vertex: ` # ifdef USE _MORPHTARGETS
# ifndef USE _INSTANCING _MORPH
uniform float morphTargetBaseInfluence ;
uniform float morphTargetInfluences [ MORPHTARGETS _COUNT ] ;
# endif
uniform sampler2DArray morphTargetsTexture ;
uniform ivec2 morphTargetsTextureSize ;
vec4 getMorph ( const in int vertexIndex , const in int morphTargetIndex , const in int offset ) {
int texelIndex = vertexIndex * MORPHTARGETS _TEXTURE _STRIDE + offset ;
int y = texelIndex / morphTargetsTextureSize . x ;
int x = texelIndex - y * morphTargetsTextureSize . x ;
ivec3 morphUV = ivec3 ( x , y , morphTargetIndex ) ;
return texelFetch ( morphTargetsTexture , morphUV , 0 ) ;
}
# endif ` ,morphtarget_vertex: ` # ifdef USE _MORPHTARGETS
transformed *= morphTargetBaseInfluence ;
for ( int i = 0 ; i < MORPHTARGETS _COUNT ; i ++ ) {
if ( morphTargetInfluences [ i ] != 0.0 ) transformed += getMorph ( gl _VertexID , i , 0 ) . xyz * morphTargetInfluences [ i ] ;
}
# endif ` ,normal_fragment_begin: ` float faceDirection = gl _FrontFacing ? 1.0 : - 1.0 ;
# ifdef FLAT _SHADED
vec3 fdx = dFdx ( vViewPosition ) ;
vec3 fdy = dFdy ( vViewPosition ) ;
vec3 normal = normalize ( cross ( fdx , fdy ) ) ;
# else
vec3 normal = normalize ( vNormal ) ;
# ifdef DOUBLE _SIDED
normal *= faceDirection ;
# endif
# endif
# if defined ( USE _NORMALMAP _TANGENTSPACE ) || defined ( USE _CLEARCOAT _NORMALMAP ) || defined ( USE _ANISOTROPY )
# ifdef USE _TANGENT
mat3 tbn = mat3 ( normalize ( vTangent ) , normalize ( vBitangent ) , normal ) ;
# else
mat3 tbn = getTangentFrame ( - vViewPosition , normal ,
# if defined ( USE _NORMALMAP )
vNormalMapUv
# elif defined ( USE _CLEARCOAT _NORMALMAP )
vClearcoatNormalMapUv
# else
vUv
# endif
) ;
# endif
# if defined ( DOUBLE _SIDED ) && ! defined ( FLAT _SHADED )
tbn [ 0 ] *= faceDirection ;
tbn [ 1 ] *= faceDirection ;
# endif
# endif
# ifdef USE _CLEARCOAT _NORMALMAP
# ifdef USE _TANGENT
mat3 tbn2 = mat3 ( normalize ( vTangent ) , normalize ( vBitangent ) , normal ) ;
# else
mat3 tbn2 = getTangentFrame ( - vViewPosition , normal , vClearcoatNormalMapUv ) ;
# endif
# if defined ( DOUBLE _SIDED ) && ! defined ( FLAT _SHADED )
tbn2 [ 0 ] *= faceDirection ;
tbn2 [ 1 ] *= faceDirection ;
# endif
# endif
vec3 nonPerturbedNormal = normal ; ` ,normal_fragment_maps: ` # ifdef USE _NORMALMAP _OBJECTSPACE
normal = texture2D ( normalMap , vNormalMapUv ) . xyz * 2.0 - 1.0 ;
# ifdef FLIP _SIDED
normal = - normal ;
# endif
# ifdef DOUBLE _SIDED
normal = normal * faceDirection ;
# endif
normal = normalize ( normalMatrix * normal ) ;
# elif defined ( USE _NORMALMAP _TANGENTSPACE )
vec3 mapN = texture2D ( normalMap , vNormalMapUv ) . xyz * 2.0 - 1.0 ;
mapN . xy *= normalScale ;
normal = normalize ( tbn * mapN ) ;
# elif defined ( USE _BUMPMAP )
normal = perturbNormalArb ( - vViewPosition , normal , dHdxy _fwd ( ) , faceDirection ) ;
# endif ` ,normal_pars_fragment: ` # ifndef FLAT _SHADED
varying vec3 vNormal ;
# ifdef USE _TANGENT
varying vec3 vTangent ;
varying vec3 vBitangent ;
# endif
# endif ` ,normal_pars_vertex: ` # ifndef FLAT _SHADED
varying vec3 vNormal ;
# ifdef USE _TANGENT
varying vec3 vTangent ;
varying vec3 vBitangent ;
# endif
# endif ` ,normal_vertex: ` # ifndef FLAT _SHADED
vNormal = normalize ( transformedNormal ) ;
# ifdef USE _TANGENT
vTangent = normalize ( transformedTangent ) ;
vBitangent = normalize ( cross ( vNormal , vTangent ) * tangent . w ) ;
# endif
# endif ` ,normalmap_pars_fragment: ` # ifdef USE _NORMALMAP
uniform sampler2D normalMap ;
uniform vec2 normalScale ;
# endif
# ifdef USE _NORMALMAP _OBJECTSPACE
uniform mat3 normalMatrix ;
# endif
# if ! defined ( USE _TANGENT ) && ( defined ( USE _NORMALMAP _TANGENTSPACE ) || defined ( USE _CLEARCOAT _NORMALMAP ) || defined ( USE _ANISOTROPY ) )
mat3 getTangentFrame ( vec3 eye _pos , vec3 surf _norm , vec2 uv ) {
vec3 q0 = dFdx ( eye _pos . xyz ) ;
vec3 q1 = dFdy ( eye _pos . xyz ) ;
vec2 st0 = dFdx ( uv . st ) ;
vec2 st1 = dFdy ( uv . st ) ;
vec3 N = surf _norm ;
vec3 q1perp = cross ( q1 , N ) ;
vec3 q0perp = cross ( N , q0 ) ;
vec3 T = q1perp * st0 . x + q0perp * st1 . x ;
vec3 B = q1perp * st0 . y + q0perp * st1 . y ;
float det = max ( dot ( T , T ) , dot ( B , B ) ) ;
float scale = ( det == 0.0 ) ? 0.0 : inversesqrt ( det ) ;
return mat3 ( T * scale , B * scale , N ) ;
}
# endif ` ,clearcoat_normal_fragment_begin: ` # ifdef USE _CLEARCOAT
vec3 clearcoatNormal = nonPerturbedNormal ;
# endif ` ,clearcoat_normal_fragment_maps: ` # ifdef USE _CLEARCOAT _NORMALMAP
vec3 clearcoatMapN = texture2D ( clearcoatNormalMap , vClearcoatNormalMapUv ) . xyz * 2.0 - 1.0 ;
clearcoatMapN . xy *= clearcoatNormalScale ;
clearcoatNormal = normalize ( tbn2 * clearcoatMapN ) ;
# endif ` ,clearcoat_pars_fragment: ` # ifdef USE _CLEARCOATMAP
uniform sampler2D clearcoatMap ;
# endif
# ifdef USE _CLEARCOAT _NORMALMAP
uniform sampler2D clearcoatNormalMap ;
uniform vec2 clearcoatNormalScale ;
# endif
# ifdef USE _CLEARCOAT _ROUGHNESSMAP
uniform sampler2D clearcoatRoughnessMap ;
# endif ` ,iridescence_pars_fragment: ` # ifdef USE _IRIDESCENCEMAP
uniform sampler2D iridescenceMap ;
# endif
# ifdef USE _IRIDESCENCE _THICKNESSMAP
uniform sampler2D iridescenceThicknessMap ;
# endif ` ,opaque_fragment: ` # ifdef OPAQUE
diffuseColor . a = 1.0 ;
# endif
# ifdef USE _TRANSMISSION
diffuseColor . a *= material . transmissionAlpha ;
# endif
gl _FragColor = vec4 ( outgoingLight , diffuseColor . a ) ; ` ,packing: ` vec3 packNormalToRGB ( const in vec3 normal ) {
return normalize ( normal ) * 0.5 + 0.5 ;
}
vec3 unpackRGBToNormal ( const in vec3 rgb ) {
return 2.0 * rgb . xyz - 1.0 ;
}
const float PackUpscale = 256. / 255. ; const float UnpackDownscale = 255. / 256. ; const float ShiftRight8 = 1. / 256. ;
const float Inv255 = 1. / 255. ;
const vec4 PackFactors = vec4 ( 1.0 , 256.0 , 256.0 * 256.0 , 256.0 * 256.0 * 256.0 ) ;
const vec2 UnpackFactors2 = vec2 ( UnpackDownscale , 1.0 / PackFactors . g ) ;
const vec3 UnpackFactors3 = vec3 ( UnpackDownscale / PackFactors . rg , 1.0 / PackFactors . b ) ;
const vec4 UnpackFactors4 = vec4 ( UnpackDownscale / PackFactors . rgb , 1.0 / PackFactors . a ) ;
vec4 packDepthToRGBA ( const in float v ) {
if ( v <= 0.0 )
return vec4 ( 0. , 0. , 0. , 0. ) ;
if ( v >= 1.0 )
return vec4 ( 1. , 1. , 1. , 1. ) ;
float vuf ;
float af = modf ( v * PackFactors . a , vuf ) ;
float bf = modf ( vuf * ShiftRight8 , vuf ) ;
float gf = modf ( vuf * ShiftRight8 , vuf ) ;
return vec4 ( vuf * Inv255 , gf * PackUpscale , bf * PackUpscale , af ) ;
}
vec3 packDepthToRGB ( const in float v ) {
if ( v <= 0.0 )
return vec3 ( 0. , 0. , 0. ) ;
if ( v >= 1.0 )
return vec3 ( 1. , 1. , 1. ) ;
float vuf ;
float bf = modf ( v * PackFactors . b , vuf ) ;
float gf = modf ( vuf * ShiftRight8 , vuf ) ;
return vec3 ( vuf * Inv255 , gf * PackUpscale , bf ) ;
}
vec2 packDepthToRG ( const in float v ) {
if ( v <= 0.0 )
return vec2 ( 0. , 0. ) ;
if ( v >= 1.0 )
return vec2 ( 1. , 1. ) ;
float vuf ;
float gf = modf ( v * 256. , vuf ) ;
return vec2 ( vuf * Inv255 , gf ) ;
}
float unpackRGBAToDepth ( const in vec4 v ) {
return dot ( v , UnpackFactors4 ) ;
}
float unpackRGBToDepth ( const in vec3 v ) {
return dot ( v , UnpackFactors3 ) ;
}
float unpackRGToDepth ( const in vec2 v ) {
return v . r * UnpackFactors2 . r + v . g * UnpackFactors2 . g ;
}
vec4 pack2HalfToRGBA ( const in vec2 v ) {
vec4 r = vec4 ( v . x , fract ( v . x * 255.0 ) , v . y , fract ( v . y * 255.0 ) ) ;
return vec4 ( r . x - r . y / 255.0 , r . y , r . z - r . w / 255.0 , r . w ) ;
}
vec2 unpackRGBATo2Half ( const in vec4 v ) {
return vec2 ( v . x + ( v . y / 255.0 ) , v . z + ( v . w / 255.0 ) ) ;
}
float viewZToOrthographicDepth ( const in float viewZ , const in float near , const in float far ) {
return ( viewZ + near ) / ( near - far ) ;
}
float orthographicDepthToViewZ ( const in float depth , const in float near , const in float far ) {
return depth * ( near - far ) - near ;
}
float viewZToPerspectiveDepth ( const in float viewZ , const in float near , const in float far ) {
return ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ ) ;
}
float perspectiveDepthToViewZ ( const in float depth , const in float near , const in float far ) {
return ( near * far ) / ( ( far - near ) * depth - far ) ;
} ` ,premultiplied_alpha_fragment: ` # ifdef PREMULTIPLIED _ALPHA
gl _FragColor . rgb *= gl _FragColor . a ;
# endif ` ,project_vertex: ` vec4 mvPosition = vec4 ( transformed , 1.0 ) ;
# ifdef USE _BATCHING
mvPosition = batchingMatrix * mvPosition ;
# endif
# ifdef USE _INSTANCING
mvPosition = instanceMatrix * mvPosition ;
# endif
mvPosition = modelViewMatrix * mvPosition ;
gl _Position = projectionMatrix * mvPosition ; ` ,dithering_fragment: ` # ifdef DITHERING
gl _FragColor . rgb = dithering ( gl _FragColor . rgb ) ;
# endif ` ,dithering_pars_fragment: ` # ifdef DITHERING
vec3 dithering ( vec3 color ) {
float grid _position = rand ( gl _FragCoord . xy ) ;
vec3 dither _shift _RGB = vec3 ( 0.25 / 255.0 , - 0.25 / 255.0 , 0.25 / 255.0 ) ;
dither _shift _RGB = mix ( 2.0 * dither _shift _RGB , - 2.0 * dither _shift _RGB , grid _position ) ;
return color + dither _shift _RGB ;
}
# endif ` ,roughnessmap_fragment: ` float roughnessFactor = roughness ;
# ifdef USE _ROUGHNESSMAP
vec4 texelRoughness = texture2D ( roughnessMap , vRoughnessMapUv ) ;
roughnessFactor *= texelRoughness . g ;
# endif ` ,roughnessmap_pars_fragment: ` # ifdef USE _ROUGHNESSMAP
uniform sampler2D roughnessMap ;
# endif ` ,shadowmap_pars_fragment: ` # if NUM _SPOT _LIGHT _COORDS > 0
varying vec4 vSpotLightCoord [ NUM _SPOT _LIGHT _COORDS ] ;
# endif
# if NUM _SPOT _LIGHT _MAPS > 0
uniform sampler2D spotLightMap [ NUM _SPOT _LIGHT _MAPS ] ;
# endif
# ifdef USE _SHADOWMAP
# if NUM _DIR _LIGHT _SHADOWS > 0
# if defined ( SHADOWMAP _TYPE _PCF )
uniform sampler2DShadow directionalShadowMap [ NUM _DIR _LIGHT _SHADOWS ] ;
# else
uniform sampler2D directionalShadowMap [ NUM _DIR _LIGHT _SHADOWS ] ;
# endif
varying vec4 vDirectionalShadowCoord [ NUM _DIR _LIGHT _SHADOWS ] ;
struct DirectionalLightShadow {
float shadowIntensity ;
float shadowBias ;
float shadowNormalBias ;
float shadowRadius ;
vec2 shadowMapSize ;
} ;
uniform DirectionalLightShadow directionalLightShadows [ NUM _DIR _LIGHT _SHADOWS ] ;
# endif
# if NUM _SPOT _LIGHT _SHADOWS > 0
# if defined ( SHADOWMAP _TYPE _PCF )
uniform sampler2DShadow spotShadowMap [ NUM _SPOT _LIGHT _SHADOWS ] ;
# else
uniform sampler2D spotShadowMap [ NUM _SPOT _LIGHT _SHADOWS ] ;
# endif
struct SpotLightShadow {
float shadowIntensity ;
float shadowBias ;
float shadowNormalBias ;
float shadowRadius ;
vec2 shadowMapSize ;
} ;
uniform SpotLightShadow spotLightShadows [ NUM _SPOT _LIGHT _SHADOWS ] ;
# endif
# if NUM _POINT _LIGHT _SHADOWS > 0
# if defined ( SHADOWMAP _TYPE _PCF )
uniform samplerCubeShadow pointShadowMap [ NUM _POINT _LIGHT _SHADOWS ] ;
# elif defined ( SHADOWMAP _TYPE _BASIC )
uniform samplerCube pointShadowMap [ NUM _POINT _LIGHT _SHADOWS ] ;
# endif
varying vec4 vPointShadowCoord [ NUM _POINT _LIGHT _SHADOWS ] ;
struct PointLightShadow {
float shadowIntensity ;
float shadowBias ;
float shadowNormalBias ;
float shadowRadius ;
vec2 shadowMapSize ;
float shadowCameraNear ;
float shadowCameraFar ;
} ;
uniform PointLightShadow pointLightShadows [ NUM _POINT _LIGHT _SHADOWS ] ;
# endif
# if defined ( SHADOWMAP _TYPE _PCF )
float interleavedGradientNoise ( vec2 position ) {
return fract ( 52.9829189 * fract ( dot ( position , vec2 ( 0.06711056 , 0.00583715 ) ) ) ) ;
}
vec2 vogelDiskSample ( int sampleIndex , int samplesCount , float phi ) {
const float goldenAngle = 2.399963229728653 ;
float r = sqrt ( ( float ( sampleIndex ) + 0.5 ) / float ( samplesCount ) ) ;
float theta = float ( sampleIndex ) * goldenAngle + phi ;
return vec2 ( cos ( theta ) , sin ( theta ) ) * r ;
}
# endif
# if defined ( SHADOWMAP _TYPE _PCF )
float getShadow ( sampler2DShadow shadowMap , vec2 shadowMapSize , float shadowIntensity , float shadowBias , float shadowRadius , vec4 shadowCoord ) {
float shadow = 1.0 ;
shadowCoord . xyz /= shadowCoord . w ;
shadowCoord . z += shadowBias ;
bool inFrustum = shadowCoord . x >= 0.0 && shadowCoord . x <= 1.0 && shadowCoord . y >= 0.0 && shadowCoord . y <= 1.0 ;
bool frustumTest = inFrustum && shadowCoord . z <= 1.0 ;
if ( frustumTest ) {
vec2 texelSize = vec2 ( 1.0 ) / shadowMapSize ;
float radius = shadowRadius * texelSize . x ;
float phi = interleavedGradientNoise ( gl _FragCoord . xy ) * 6.28318530718 ;
shadow = (
texture ( shadowMap , vec3 ( shadowCoord . xy + vogelDiskSample ( 0 , 5 , phi ) * radius , shadowCoord . z ) ) +
texture ( shadowMap , vec3 ( shadowCoord . xy + vogelDiskSample ( 1 , 5 , phi ) * radius , shadowCoord . z ) ) +
texture ( shadowMap , vec3 ( shadowCoord . xy + vogelDiskSample ( 2 , 5 , phi ) * radius , shadowCoord . z ) ) +
texture ( shadowMap , vec3 ( shadowCoord . xy + vogelDiskSample ( 3 , 5 , phi ) * radius , shadowCoord . z ) ) +
texture ( shadowMap , vec3 ( shadowCoord . xy + vogelDiskSample ( 4 , 5 , phi ) * radius , shadowCoord . z ) )
) * 0.2 ;
}
return mix ( 1.0 , shadow , shadowIntensity ) ;
}
# elif defined ( SHADOWMAP _TYPE _VSM )
float getShadow ( sampler2D shadowMap , vec2 shadowMapSize , float shadowIntensity , float shadowBias , float shadowRadius , vec4 shadowCoord ) {
float shadow = 1.0 ;
shadowCoord . xyz /= shadowCoord . w ;
shadowCoord . z += shadowBias ;
bool inFrustum = shadowCoord . x >= 0.0 && shadowCoord . x <= 1.0 && shadowCoord . y >= 0.0 && shadowCoord . y <= 1.0 ;
bool frustumTest = inFrustum && shadowCoord . z <= 1.0 ;
if ( frustumTest ) {
vec2 distribution = texture2D ( shadowMap , shadowCoord . xy ) . rg ;
float mean = distribution . x ;
float variance = distribution . y * distribution . y ;
# ifdef USE _REVERSED _DEPTH _BUFFER
float hard _shadow = step ( mean , shadowCoord . z ) ;
# else
float hard _shadow = step ( shadowCoord . z , mean ) ;
# endif
if ( hard _shadow == 1.0 ) {
shadow = 1.0 ;
} else {
variance = max ( variance , 0.0000001 ) ;
float d = shadowCoord . z - mean ;
float p _max = variance / ( variance + d * d ) ;
p _max = clamp ( ( p _max - 0.3 ) / 0.65 , 0.0 , 1.0 ) ;
shadow = max ( hard _shadow , p _max ) ;
}
}
return mix ( 1.0 , shadow , shadowIntensity ) ;
}
# else
float getShadow ( sampler2D shadowMap , vec2 shadowMapSize , float shadowIntensity , float shadowBias , float shadowRadius , vec4 shadowCoord ) {
float shadow = 1.0 ;
shadowCoord . xyz /= shadowCoord . w ;
shadowCoord . z += shadowBias ;
bool inFrustum = shadowCoord . x >= 0.0 && shadowCoord . x <= 1.0 && shadowCoord . y >= 0.0 && shadowCoord . y <= 1.0 ;
bool frustumTest = inFrustum && shadowCoord . z <= 1.0 ;
if ( frustumTest ) {
float depth = texture2D ( shadowMap , shadowCoord . xy ) . r ;
# ifdef USE _REVERSED _DEPTH _BUFFER
shadow = step ( depth , shadowCoord . z ) ;
# else
shadow = step ( shadowCoord . z , depth ) ;
# endif
}
return mix ( 1.0 , shadow , shadowIntensity ) ;
}
# endif
# if NUM _POINT _LIGHT _SHADOWS > 0
# if defined ( SHADOWMAP _TYPE _PCF )
float getPointShadow ( samplerCubeShadow shadowMap , vec2 shadowMapSize , float shadowIntensity , float shadowBias , float shadowRadius , vec4 shadowCoord , float shadowCameraNear , float shadowCameraFar ) {
float shadow = 1.0 ;
vec3 lightToPosition = shadowCoord . xyz ;
vec3 bd3D = normalize ( lightToPosition ) ;
vec3 absVec = abs ( lightToPosition ) ;
float viewSpaceZ = max ( max ( absVec . x , absVec . y ) , absVec . z ) ;
if ( viewSpaceZ - shadowCameraFar <= 0.0 && viewSpaceZ - shadowCameraNear >= 0.0 ) {
float dp = ( shadowCameraFar * ( viewSpaceZ - shadowCameraNear ) ) / ( viewSpaceZ * ( shadowCameraFar - shadowCameraNear ) ) ;
dp += shadowBias ;
float texelSize = shadowRadius / shadowMapSize . x ;
vec3 absDir = abs ( bd3D ) ;
vec3 tangent = absDir . x > absDir . z ? vec3 ( 0.0 , 1.0 , 0.0 ) : vec3 ( 1.0 , 0.0 , 0.0 ) ;
tangent = normalize ( cross ( bd3D , tangent ) ) ;
vec3 bitangent = cross ( bd3D , tangent ) ;
float phi = interleavedGradientNoise ( gl _FragCoord . xy ) * 6.28318530718 ;
shadow = (
texture ( shadowMap , vec4 ( bd3D + ( tangent * vogelDiskSample ( 0 , 5 , phi ) . x + bitangent * vogelDiskSample ( 0 , 5 , phi ) . y ) * texelSize , dp ) ) +
texture ( shadowMap , vec4 ( bd3D + ( tangent * vogelDiskSample ( 1 , 5 , phi ) . x + bitangent * vogelDiskSample ( 1 , 5 , phi ) . y ) * texelSize , dp ) ) +
texture ( shadowMap , vec4 ( bd3D + ( tangent * vogelDiskSample ( 2 , 5 , phi ) . x + bitangent * vogelDiskSample ( 2 , 5 , phi ) . y ) * texelSize , dp ) ) +
texture ( shadowMap , vec4 ( bd3D + ( tangent * vogelDiskSample ( 3 , 5 , phi ) . x + bitangent * vogelDiskSample ( 3 , 5 , phi ) . y ) * texelSize , dp ) ) +
texture ( shadowMap , vec4 ( bd3D + ( tangent * vogelDiskSample ( 4 , 5 , phi ) . x + bitangent * vogelDiskSample ( 4 , 5 , phi ) . y ) * texelSize , dp ) )
) * 0.2 ;
}
return mix ( 1.0 , shadow , shadowIntensity ) ;
}
# elif defined ( SHADOWMAP _TYPE _BASIC )
float getPointShadow ( samplerCube shadowMap , vec2 shadowMapSize , float shadowIntensity , float shadowBias , float shadowRadius , vec4 shadowCoord , float shadowCameraNear , float shadowCameraFar ) {
float shadow = 1.0 ;
vec3 lightToPosition = shadowCoord . xyz ;
vec3 bd3D = normalize ( lightToPosition ) ;
vec3 absVec = abs ( lightToPosition ) ;
float viewSpaceZ = max ( max ( absVec . x , absVec . y ) , absVec . z ) ;
if ( viewSpaceZ - shadowCameraFar <= 0.0 && viewSpaceZ - shadowCameraNear >= 0.0 ) {
float dp = ( shadowCameraFar * ( viewSpaceZ - shadowCameraNear ) ) / ( viewSpaceZ * ( shadowCameraFar - shadowCameraNear ) ) ;
dp += shadowBias ;
float depth = textureCube ( shadowMap , bd3D ) . r ;
# ifdef USE _REVERSED _DEPTH _BUFFER
shadow = step ( depth , dp ) ;
# else
shadow = step ( dp , depth ) ;
# endif
}
return mix ( 1.0 , shadow , shadowIntensity ) ;
}
# endif
# endif
# endif ` ,shadowmap_pars_vertex: ` # if NUM _SPOT _LIGHT _COORDS > 0
uniform mat4 spotLightMatrix [ NUM _SPOT _LIGHT _COORDS ] ;
varying vec4 vSpotLightCoord [ NUM _SPOT _LIGHT _COORDS ] ;
# endif
# ifdef USE _SHADOWMAP
# if NUM _DIR _LIGHT _SHADOWS > 0
uniform mat4 directionalShadowMatrix [ NUM _DIR _LIGHT _SHADOWS ] ;
varying vec4 vDirectionalShadowCoord [ NUM _DIR _LIGHT _SHADOWS ] ;
struct DirectionalLightShadow {
float shadowIntensity ;
float shadowBias ;
float shadowNormalBias ;
float shadowRadius ;
vec2 shadowMapSize ;
} ;
uniform DirectionalLightShadow directionalLightShadows [ NUM _DIR _LIGHT _SHADOWS ] ;
# endif
# if NUM _SPOT _LIGHT _SHADOWS > 0
struct SpotLightShadow {
float shadowIntensity ;
float shadowBias ;
float shadowNormalBias ;
float shadowRadius ;
vec2 shadowMapSize ;
} ;
uniform SpotLightShadow spotLightShadows [ NUM _SPOT _LIGHT _SHADOWS ] ;
# endif
# if NUM _POINT _LIGHT _SHADOWS > 0
uniform mat4 pointShadowMatrix [ NUM _POINT _LIGHT _SHADOWS ] ;
varying vec4 vPointShadowCoord [ NUM _POINT _LIGHT _SHADOWS ] ;
struct PointLightShadow {
float shadowIntensity ;
float shadowBias ;
float shadowNormalBias ;
float shadowRadius ;
vec2 shadowMapSize ;
float shadowCameraNear ;
float shadowCameraFar ;
} ;
uniform PointLightShadow pointLightShadows [ NUM _POINT _LIGHT _SHADOWS ] ;
# endif
# endif ` ,shadowmap_vertex: ` # if ( defined ( USE _SHADOWMAP ) && ( NUM _DIR _LIGHT _SHADOWS > 0 || NUM _POINT _LIGHT _SHADOWS > 0 ) ) || ( NUM _SPOT _LIGHT _COORDS > 0 )
vec3 shadowWorldNormal = inverseTransformDirection ( transformedNormal , viewMatrix ) ;
vec4 shadowWorldPosition ;
# endif
# if defined ( USE _SHADOWMAP )
# if NUM _DIR _LIGHT _SHADOWS > 0
# pragma unroll _loop _start
for ( int i = 0 ; i < NUM _DIR _LIGHT _SHADOWS ; i ++ ) {
shadowWorldPosition = worldPosition + vec4 ( shadowWorldNormal * directionalLightShadows [ i ] . shadowNormalBias , 0 ) ;
vDirectionalShadowCoord [ i ] = directionalShadowMatrix [ i ] * shadowWorldPosition ;
}
# pragma unroll _loop _end
# endif
# if NUM _POINT _LIGHT _SHADOWS > 0
# pragma unroll _loop _start
for ( int i = 0 ; i < NUM _POINT _LIGHT _SHADOWS ; i ++ ) {
shadowWorldPosition = worldPosition + vec4 ( shadowWorldNormal * pointLightShadows [ i ] . shadowNormalBias , 0 ) ;
vPointShadowCoord [ i ] = pointShadowMatrix [ i ] * shadowWorldPosition ;
}
# pragma unroll _loop _end
# endif
# endif
# if NUM _SPOT _LIGHT _COORDS > 0
# pragma unroll _loop _start
for ( int i = 0 ; i < NUM _SPOT _LIGHT _COORDS ; i ++ ) {
shadowWorldPosition = worldPosition ;
# if ( defined ( USE _SHADOWMAP ) && UNROLLED _LOOP _INDEX < NUM _SPOT _LIGHT _SHADOWS )
shadowWorldPosition . xyz += shadowWorldNormal * spotLightShadows [ i ] . shadowNormalBias ;
# endif
vSpotLightCoord [ i ] = spotLightMatrix [ i ] * shadowWorldPosition ;
}
# pragma unroll _loop _end
# endif ` ,shadowmask_pars_fragment: ` float getShadowMask ( ) {
float shadow = 1.0 ;
# ifdef USE _SHADOWMAP
# if NUM _DIR _LIGHT _SHADOWS > 0
DirectionalLightShadow directionalLight ;
# pragma unroll _loop _start
for ( int i = 0 ; i < NUM _DIR _LIGHT _SHADOWS ; i ++ ) {
directionalLight = directionalLightShadows [ i ] ;
shadow *= receiveShadow ? getShadow ( directionalShadowMap [ i ] , directionalLight . shadowMapSize , directionalLight . shadowIntensity , directionalLight . shadowBias , directionalLight . shadowRadius , vDirectionalShadowCoord [ i ] ) : 1.0 ;
}
# pragma unroll _loop _end
# endif
# if NUM _SPOT _LIGHT _SHADOWS > 0
SpotLightShadow spotLight ;
# pragma unroll _loop _start
for ( int i = 0 ; i < NUM _SPOT _LIGHT _SHADOWS ; i ++ ) {
spotLight = spotLightShadows [ i ] ;
shadow *= receiveShadow ? getShadow ( spotShadowMap [ i ] , spotLight . shadowMapSize , spotLight . shadowIntensity , spotLight . shadowBias , spotLight . shadowRadius , vSpotLightCoord [ i ] ) : 1.0 ;
}
# pragma unroll _loop _end
# endif
# if NUM _POINT _LIGHT _SHADOWS > 0 && ( defined ( SHADOWMAP _TYPE _PCF ) || defined ( SHADOWMAP _TYPE _BASIC ) )
PointLightShadow pointLight ;
# pragma unroll _loop _start
for ( int i = 0 ; i < NUM _POINT _LIGHT _SHADOWS ; i ++ ) {
pointLight = pointLightShadows [ i ] ;
shadow *= receiveShadow ? getPointShadow ( pointShadowMap [ i ] , pointLight . shadowMapSize , pointLight . shadowIntensity , pointLight . shadowBias , pointLight . shadowRadius , vPointShadowCoord [ i ] , pointLight . shadowCameraNear , pointLight . shadowCameraFar ) : 1.0 ;
}
# pragma unroll _loop _end
# endif
# endif
return shadow ;
} ` ,skinbase_vertex: ` # ifdef USE _SKINNING
mat4 boneMatX = getBoneMatrix ( skinIndex . x ) ;
mat4 boneMatY = getBoneMatrix ( skinIndex . y ) ;
mat4 boneMatZ = getBoneMatrix ( skinIndex . z ) ;
mat4 boneMatW = getBoneMatrix ( skinIndex . w ) ;
# endif ` ,skinning_pars_vertex: ` # ifdef USE _SKINNING
uniform mat4 bindMatrix ;
uniform mat4 bindMatrixInverse ;
uniform highp sampler2D boneTexture ;
mat4 getBoneMatrix ( const in float i ) {
int size = textureSize ( boneTexture , 0 ) . x ;
int j = int ( i ) * 4 ;
int x = j % size ;
int y = j / size ;
vec4 v1 = texelFetch ( boneTexture , ivec2 ( x , y ) , 0 ) ;
vec4 v2 = texelFetch ( boneTexture , ivec2 ( x + 1 , y ) , 0 ) ;
vec4 v3 = texelFetch ( boneTexture , ivec2 ( x + 2 , y ) , 0 ) ;
vec4 v4 = texelFetch ( boneTexture , ivec2 ( x + 3 , y ) , 0 ) ;
return mat4 ( v1 , v2 , v3 , v4 ) ;
}
# endif ` ,skinning_vertex: ` # ifdef USE _SKINNING
vec4 skinVertex = bindMatrix * vec4 ( transformed , 1.0 ) ;
vec4 skinned = vec4 ( 0.0 ) ;
skinned += boneMatX * skinVertex * skinWeight . x ;
skinned += boneMatY * skinVertex * skinWeight . y ;
skinned += boneMatZ * skinVertex * skinWeight . z ;
skinned += boneMatW * skinVertex * skinWeight . w ;
transformed = ( bindMatrixInverse * skinned ) . xyz ;
# endif ` ,skinnormal_vertex: ` # ifdef USE _SKINNING
mat4 skinMatrix = mat4 ( 0.0 ) ;
skinMatrix += skinWeight . x * boneMatX ;
skinMatrix += skinWeight . y * boneMatY ;
skinMatrix += skinWeight . z * boneMatZ ;
skinMatrix += skinWeight . w * boneMatW ;
skinMatrix = bindMatrixInverse * skinMatrix * bindMatrix ;
objectNormal = vec4 ( skinMatrix * vec4 ( objectNormal , 0.0 ) ) . xyz ;
# ifdef USE _TANGENT
objectTangent = vec4 ( skinMatrix * vec4 ( objectTangent , 0.0 ) ) . xyz ;
# endif
# endif ` ,specularmap_fragment: ` float specularStrength ;
# ifdef USE _SPECULARMAP
vec4 texelSpecular = texture2D ( specularMap , vSpecularMapUv ) ;
specularStrength = texelSpecular . r ;
# else
specularStrength = 1.0 ;
# endif ` ,specularmap_pars_fragment: ` # ifdef USE _SPECULARMAP
uniform sampler2D specularMap ;
# endif ` ,tonemapping_fragment: ` # if defined ( TONE _MAPPING )
gl _FragColor . rgb = toneMapping ( gl _FragColor . rgb ) ;
# endif ` ,tonemapping_pars_fragment: ` # ifndef saturate
# define saturate ( a ) clamp ( a , 0.0 , 1.0 )
# endif
uniform float toneMappingExposure ;
vec3 LinearToneMapping ( vec3 color ) {
return saturate ( toneMappingExposure * color ) ;
}
vec3 ReinhardToneMapping ( vec3 color ) {
color *= toneMappingExposure ;
return saturate ( color / ( vec3 ( 1.0 ) + color ) ) ;
}
vec3 CineonToneMapping ( vec3 color ) {
color *= toneMappingExposure ;
color = max ( vec3 ( 0.0 ) , color - 0.004 ) ;
return pow ( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ) , vec3 ( 2.2 ) ) ;
}
vec3 RRTAndODTFit ( vec3 v ) {
vec3 a = v * ( v + 0.0245786 ) - 0.000090537 ;
vec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081 ;
return a / b ;
}
vec3 ACESFilmicToneMapping ( vec3 color ) {
const mat3 ACESInputMat = mat3 (
vec3 ( 0.59719 , 0.07600 , 0.02840 ) , vec3 ( 0.35458 , 0.90834 , 0.13383 ) ,
vec3 ( 0.04823 , 0.01566 , 0.83777 )
) ;
const mat3 ACESOutputMat = mat3 (
vec3 ( 1.60475 , - 0.10208 , - 0.00327 ) , vec3 ( - 0.53108 , 1.10813 , - 0.07276 ) ,
vec3 ( - 0.07367 , - 0.00605 , 1.07602 )
) ;
color *= toneMappingExposure / 0.6 ;
color = ACESInputMat * color ;
color = RRTAndODTFit ( color ) ;
color = ACESOutputMat * color ;
return saturate ( color ) ;
}
const mat3 LINEAR _REC2020 _TO _LINEAR _SRGB = mat3 (
vec3 ( 1.6605 , - 0.1246 , - 0.0182 ) ,
vec3 ( - 0.5876 , 1.1329 , - 0.1006 ) ,
vec3 ( - 0.0728 , - 0.0083 , 1.1187 )
) ;
const mat3 LINEAR _SRGB _TO _LINEAR _REC2020 = mat3 (
vec3 ( 0.6274 , 0.0691 , 0.0164 ) ,
vec3 ( 0.3293 , 0.9195 , 0.0880 ) ,
vec3 ( 0.0433 , 0.0113 , 0.8956 )
) ;
vec3 agxDefaultContrastApprox ( vec3 x ) {
vec3 x2 = x * x ;
vec3 x4 = x2 * x2 ;
return + 15.5 * x4 * x2
- 40.14 * x4 * x
+ 31.96 * x4
- 6.868 * x2 * x
+ 0.4298 * x2
+ 0.1191 * x
- 0.00232 ;
}
vec3 AgXToneMapping ( vec3 color ) {
const mat3 AgXInsetMatrix = mat3 (
vec3 ( 0.856627153315983 , 0.137318972929847 , 0.11189821299995 ) ,
vec3 ( 0.0951212405381588 , 0.761241990602591 , 0.0767994186031903 ) ,
vec3 ( 0.0482516061458583 , 0.101439036467562 , 0.811302368396859 )
) ;
const mat3 AgXOutsetMatrix = mat3 (
vec3 ( 1.1271005818144368 , - 0.1413297634984383 , - 0.14132976349843826 ) ,
vec3 ( - 0.11060664309660323 , 1.157823702216272 , - 0.11060664309660294 ) ,
vec3 ( - 0.016493938717834573 , - 0.016493938717834257 , 1.2519364065950405 )
) ;
const float AgxMinEv = - 12.47393 ; const float AgxMaxEv = 4.026069 ;
color *= toneMappingExposure ;
color = LINEAR _SRGB _TO _LINEAR _REC2020 * color ;
color = AgXInsetMatrix * color ;
color = max ( color , 1e-10 ) ; color = log2 ( color ) ;
color = ( color - AgxMinEv ) / ( AgxMaxEv - AgxMinEv ) ;
color = clamp ( color , 0.0 , 1.0 ) ;
color = agxDefaultContrastApprox ( color ) ;
color = AgXOutsetMatrix * color ;
color = pow ( max ( vec3 ( 0.0 ) , color ) , vec3 ( 2.2 ) ) ;
color = LINEAR _REC2020 _TO _LINEAR _SRGB * color ;
color = clamp ( color , 0.0 , 1.0 ) ;
return color ;
}
vec3 NeutralToneMapping ( vec3 color ) {
const float StartCompression = 0.8 - 0.04 ;
const float Desaturation = 0.15 ;
color *= toneMappingExposure ;
float x = min ( color . r , min ( color . g , color . b ) ) ;
float offset = x < 0.08 ? x - 6.25 * x * x : 0.04 ;
color -= offset ;
float peak = max ( color . r , max ( color . g , color . b ) ) ;
if ( peak < StartCompression ) return color ;
float d = 1. - StartCompression ;
float newPeak = 1. - d * d / ( peak + d - StartCompression ) ;
color *= newPeak / peak ;
float g = 1. - 1. / ( Desaturation * ( peak - newPeak ) + 1. ) ;
return mix ( color , vec3 ( newPeak ) , g ) ;
}
vec3 CustomToneMapping ( vec3 color ) { return color ; } ` ,transmission_fragment: ` # ifdef USE _TRANSMISSION
material . transmission = transmission ;
material . transmissionAlpha = 1.0 ;
material . thickness = thickness ;
material . attenuationDistance = attenuationDistance ;
material . attenuationColor = attenuationColor ;
# ifdef USE _TRANSMISSIONMAP
material . transmission *= texture2D ( transmissionMap , vTransmissionMapUv ) . r ;
# endif
# ifdef USE _THICKNESSMAP
material . thickness *= texture2D ( thicknessMap , vThicknessMapUv ) . g ;
# endif
vec3 pos = vWorldPosition ;
vec3 v = normalize ( cameraPosition - pos ) ;
vec3 n = inverseTransformDirection ( normal , viewMatrix ) ;
vec4 transmitted = getIBLVolumeRefraction (
n , v , material . roughness , material . diffuseContribution , material . specularColorBlended , material . specularF90 ,
pos , modelMatrix , viewMatrix , projectionMatrix , material . dispersion , material . ior , material . thickness ,
material . attenuationColor , material . attenuationDistance ) ;
material . transmissionAlpha = mix ( material . transmissionAlpha , transmitted . a , material . transmission ) ;
totalDiffuse = mix ( totalDiffuse , transmitted . rgb , material . transmission ) ;
# endif ` ,transmission_pars_fragment: ` # ifdef USE _TRANSMISSION
uniform float transmission ;
uniform float thickness ;
uniform float attenuationDistance ;
uniform vec3 attenuationColor ;
# ifdef USE _TRANSMISSIONMAP
uniform sampler2D transmissionMap ;
# endif
# ifdef USE _THICKNESSMAP
uniform sampler2D thicknessMap ;
# endif
uniform vec2 transmissionSamplerSize ;
uniform sampler2D transmissionSamplerMap ;
uniform mat4 modelMatrix ;
uniform mat4 projectionMatrix ;
varying vec3 vWorldPosition ;
float w0 ( float a ) {
return ( 1.0 / 6.0 ) * ( a * ( a * ( - a + 3.0 ) - 3.0 ) + 1.0 ) ;
}
float w1 ( float a ) {
return ( 1.0 / 6.0 ) * ( a * a * ( 3.0 * a - 6.0 ) + 4.0 ) ;
}
float w2 ( float a ) {
return ( 1.0 / 6.0 ) * ( a * ( a * ( - 3.0 * a + 3.0 ) + 3.0 ) + 1.0 ) ;
}
float w3 ( float a ) {
return ( 1.0 / 6.0 ) * ( a * a * a ) ;
}
float g0 ( float a ) {
return w0 ( a ) + w1 ( a ) ;
}
float g1 ( float a ) {
return w2 ( a ) + w3 ( a ) ;
}
float h0 ( float a ) {
return - 1.0 + w1 ( a ) / ( w0 ( a ) + w1 ( a ) ) ;
}
float h1 ( float a ) {
return 1.0 + w3 ( a ) / ( w2 ( a ) + w3 ( a ) ) ;
}
vec4 bicubic ( sampler2D tex , vec2 uv , vec4 texelSize , float lod ) {
uv = uv * texelSize . zw + 0.5 ;
vec2 iuv = floor ( uv ) ;
vec2 fuv = fract ( uv ) ;
float g0x = g0 ( fuv . x ) ;
float g1x = g1 ( fuv . x ) ;
float h0x = h0 ( fuv . x ) ;
float h1x = h1 ( fuv . x ) ;
float h0y = h0 ( fuv . y ) ;
float h1y = h1 ( fuv . y ) ;
vec2 p0 = ( vec2 ( iuv . x + h0x , iuv . y + h0y ) - 0.5 ) * texelSize . xy ;
vec2 p1 = ( vec2 ( iuv . x + h1x , iuv . y + h0y ) - 0.5 ) * texelSize . xy ;
vec2 p2 = ( vec2 ( iuv . x + h0x , iuv . y + h1y ) - 0.5 ) * texelSize . xy ;
vec2 p3 = ( vec2 ( iuv . x + h1x , iuv . y + h1y ) - 0.5 ) * texelSize . xy ;
return g0 ( fuv . y ) * ( g0x * textureLod ( tex , p0 , lod ) + g1x * textureLod ( tex , p1 , lod ) ) +
g1 ( fuv . y ) * ( g0x * textureLod ( tex , p2 , lod ) + g1x * textureLod ( tex , p3 , lod ) ) ;
}
vec4 textureBicubic ( sampler2D sampler , vec2 uv , float lod ) {
vec2 fLodSize = vec2 ( textureSize ( sampler , int ( lod ) ) ) ;
vec2 cLodSize = vec2 ( textureSize ( sampler , int ( lod + 1.0 ) ) ) ;
vec2 fLodSizeInv = 1.0 / fLodSize ;
vec2 cLodSizeInv = 1.0 / cLodSize ;
vec4 fSample = bicubic ( sampler , uv , vec4 ( fLodSizeInv , fLodSize ) , floor ( lod ) ) ;
vec4 cSample = bicubic ( sampler , uv , vec4 ( cLodSizeInv , cLodSize ) , ceil ( lod ) ) ;
return mix ( fSample , cSample , fract ( lod ) ) ;
}
vec3 getVolumeTransmissionRay ( const in vec3 n , const in vec3 v , const in float thickness , const in float ior , const in mat4 modelMatrix ) {
vec3 refractionVector = refract ( - v , normalize ( n ) , 1.0 / ior ) ;
vec3 modelScale ;
modelScale . x = length ( vec3 ( modelMatrix [ 0 ] . xyz ) ) ;
modelScale . y = length ( vec3 ( modelMatrix [ 1 ] . xyz ) ) ;
modelScale . z = length ( vec3 ( modelMatrix [ 2 ] . xyz ) ) ;
return normalize ( refractionVector ) * thickness * modelScale ;
}
float applyIorToRoughness ( const in float roughness , const in float ior ) {
return roughness * clamp ( ior * 2.0 - 2.0 , 0.0 , 1.0 ) ;
}
vec4 getTransmissionSample ( const in vec2 fragCoord , const in float roughness , const in float ior ) {
float lod = log2 ( transmissionSamplerSize . x ) * applyIorToRoughness ( roughness , ior ) ;
return textureBicubic ( transmissionSamplerMap , fragCoord . xy , lod ) ;
}
vec3 volumeAttenuation ( const in float transmissionDistance , const in vec3 attenuationColor , const in float attenuationDistance ) {
if ( isinf ( attenuationDistance ) ) {
return vec3 ( 1.0 ) ;
} else {
vec3 attenuationCoefficient = - log ( attenuationColor ) / attenuationDistance ;
vec3 transmittance = exp ( - attenuationCoefficient * transmissionDistance ) ; return transmittance ;
}
}
vec4 getIBLVolumeRefraction ( const in vec3 n , const in vec3 v , const in float roughness , const in vec3 diffuseColor ,
const in vec3 specularColor , const in float specularF90 , const in vec3 position , const in mat4 modelMatrix ,
const in mat4 viewMatrix , const in mat4 projMatrix , const in float dispersion , const in float ior , const in float thickness ,
const in vec3 attenuationColor , const in float attenuationDistance ) {
vec4 transmittedLight ;
vec3 transmittance ;
# ifdef USE _DISPERSION
float halfSpread = ( ior - 1.0 ) * 0.025 * dispersion ;
vec3 iors = vec3 ( ior - halfSpread , ior , ior + halfSpread ) ;
for ( int i = 0 ; i < 3 ; i ++ ) {
vec3 transmissionRay = getVolumeTransmissionRay ( n , v , thickness , iors [ i ] , modelMatrix ) ;
vec3 refractedRayExit = position + transmissionRay ;
vec4 ndcPos = projMatrix * viewMatrix * vec4 ( refractedRayExit , 1.0 ) ;
vec2 refractionCoords = ndcPos . xy / ndcPos . w ;
refractionCoords += 1.0 ;
refractionCoords /= 2.0 ;
vec4 transmissionSample = getTransmissionSample ( refractionCoords , roughness , iors [ i ] ) ;
transmittedLight [ i ] = transmissionSample [ i ] ;
transmittedLight . a += transmissionSample . a ;
transmittance [ i ] = diffuseColor [ i ] * volumeAttenuation ( length ( transmissionRay ) , attenuationColor , attenuationDistance ) [ i ] ;
}
transmittedLight . a /= 3.0 ;
# else
vec3 transmissionRay = getVolumeTransmissionRay ( n , v , thickness , ior , modelMatrix ) ;
vec3 refractedRayExit = position + transmissionRay ;
vec4 ndcPos = projMatrix * viewMatrix * vec4 ( refractedRayExit , 1.0 ) ;
vec2 refractionCoords = ndcPos . xy / ndcPos . w ;
refractionCoords += 1.0 ;
refractionCoords /= 2.0 ;
transmittedLight = getTransmissionSample ( refractionCoords , roughness , ior ) ;
transmittance = diffuseColor * volumeAttenuation ( length ( transmissionRay ) , attenuationColor , attenuationDistance ) ;
# endif
vec3 attenuatedColor = transmittance * transmittedLight . rgb ;
vec3 F = EnvironmentBRDF ( n , v , specularColor , specularF90 , roughness ) ;
float transmittanceFactor = ( transmittance . r + transmittance . g + transmittance . b ) / 3.0 ;
return vec4 ( ( 1.0 - F ) * attenuatedColor , 1.0 - ( 1.0 - transmittedLight . a ) * transmittanceFactor ) ;
}
# endif ` ,uv_pars_fragment: ` # if defined ( USE _UV ) || defined ( USE _ANISOTROPY )
varying vec2 vUv ;
# endif
# ifdef USE _MAP
varying vec2 vMapUv ;
# endif
# ifdef USE _ALPHAMAP
varying vec2 vAlphaMapUv ;
# endif
# ifdef USE _LIGHTMAP
varying vec2 vLightMapUv ;
# endif
# ifdef USE _AOMAP
varying vec2 vAoMapUv ;
# endif
# ifdef USE _BUMPMAP
varying vec2 vBumpMapUv ;
# endif
# ifdef USE _NORMALMAP
varying vec2 vNormalMapUv ;
# endif
# ifdef USE _EMISSIVEMAP
varying vec2 vEmissiveMapUv ;
# endif
# ifdef USE _METALNESSMAP
varying vec2 vMetalnessMapUv ;
# endif
# ifdef USE _ROUGHNESSMAP
varying vec2 vRoughnessMapUv ;
# endif
# ifdef USE _ANISOTROPYMAP
varying vec2 vAnisotropyMapUv ;
# endif
# ifdef USE _CLEARCOATMAP
varying vec2 vClearcoatMapUv ;
# endif
# ifdef USE _CLEARCOAT _NORMALMAP
varying vec2 vClearcoatNormalMapUv ;
# endif
# ifdef USE _CLEARCOAT _ROUGHNESSMAP
varying vec2 vClearcoatRoughnessMapUv ;
# endif
# ifdef USE _IRIDESCENCEMAP
varying vec2 vIridescenceMapUv ;
# endif
# ifdef USE _IRIDESCENCE _THICKNESSMAP
varying vec2 vIridescenceThicknessMapUv ;
# endif
# ifdef USE _SHEEN _COLORMAP
varying vec2 vSheenColorMapUv ;
# endif
# ifdef USE _SHEEN _ROUGHNESSMAP
varying vec2 vSheenRoughnessMapUv ;
# endif
# ifdef USE _SPECULARMAP
varying vec2 vSpecularMapUv ;
# endif
# ifdef USE _SPECULAR _COLORMAP
varying vec2 vSpecularColorMapUv ;
# endif
# ifdef USE _SPECULAR _INTENSITYMAP
varying vec2 vSpecularIntensityMapUv ;
# endif
# ifdef USE _TRANSMISSIONMAP
uniform mat3 transmissionMapTransform ;
varying vec2 vTransmissionMapUv ;
# endif
# ifdef USE _THICKNESSMAP
uniform mat3 thicknessMapTransform ;
varying vec2 vThicknessMapUv ;
# endif ` ,uv_pars_vertex: ` # if defined ( USE _UV ) || defined ( USE _ANISOTROPY )
varying vec2 vUv ;
# endif
# ifdef USE _MAP
uniform mat3 mapTransform ;
varying vec2 vMapUv ;
# endif
# ifdef USE _ALPHAMAP
uniform mat3 alphaMapTransform ;
varying vec2 vAlphaMapUv ;
# endif
# ifdef USE _LIGHTMAP
uniform mat3 lightMapTransform ;
varying vec2 vLightMapUv ;
# endif
# ifdef USE _AOMAP
uniform mat3 aoMapTransform ;
varying vec2 vAoMapUv ;
# endif
# ifdef USE _BUMPMAP
uniform mat3 bumpMapTransform ;
varying vec2 vBumpMapUv ;
# endif
# ifdef USE _NORMALMAP
uniform mat3 normalMapTransform ;
varying vec2 vNormalMapUv ;
# endif
# ifdef USE _DISPLACEMENTMAP
uniform mat3 displacementMapTransform ;
varying vec2 vDisplacementMapUv ;
# endif
# ifdef USE _EMISSIVEMAP
uniform mat3 emissiveMapTransform ;
varying vec2 vEmissiveMapUv ;
# endif
# ifdef USE _METALNESSMAP
uniform mat3 metalnessMapTransform ;
varying vec2 vMetalnessMapUv ;
# endif
# ifdef USE _ROUGHNESSMAP
uniform mat3 roughnessMapTransform ;
varying vec2 vRoughnessMapUv ;
# endif
# ifdef USE _ANISOTROPYMAP
uniform mat3 anisotropyMapTransform ;
varying vec2 vAnisotropyMapUv ;
# endif
# ifdef USE _CLEARCOATMAP
uniform mat3 clearcoatMapTransform ;
varying vec2 vClearcoatMapUv ;
# endif
# ifdef USE _CLEARCOAT _NORMALMAP
uniform mat3 clearcoatNormalMapTransform ;
varying vec2 vClearcoatNormalMapUv ;
# endif
# ifdef USE _CLEARCOAT _ROUGHNESSMAP
uniform mat3 clearcoatRoughnessMapTransform ;
varying vec2 vClearcoatRoughnessMapUv ;
# endif
# ifdef USE _SHEEN _COLORMAP
uniform mat3 sheenColorMapTransform ;
varying vec2 vSheenColorMapUv ;
# endif
# ifdef USE _SHEEN _ROUGHNESSMAP
uniform mat3 sheenRoughnessMapTransform ;
varying vec2 vSheenRoughnessMapUv ;
# endif
# ifdef USE _IRIDESCENCEMAP
uniform mat3 iridescenceMapTransform ;
varying vec2 vIridescenceMapUv ;
# endif
# ifdef USE _IRIDESCENCE _THICKNESSMAP
uniform mat3 iridescenceThicknessMapTransform ;
varying vec2 vIridescenceThicknessMapUv ;
# endif
# ifdef USE _SPECULARMAP
uniform mat3 specularMapTransform ;
varying vec2 vSpecularMapUv ;
# endif
# ifdef USE _SPECULAR _COLORMAP
uniform mat3 specularColorMapTransform ;
varying vec2 vSpecularColorMapUv ;
# endif
# ifdef USE _SPECULAR _INTENSITYMAP
uniform mat3 specularIntensityMapTransform ;
varying vec2 vSpecularIntensityMapUv ;
# endif
# ifdef USE _TRANSMISSIONMAP
uniform mat3 transmissionMapTransform ;
varying vec2 vTransmissionMapUv ;
# endif
# ifdef USE _THICKNESSMAP
uniform mat3 thicknessMapTransform ;
varying vec2 vThicknessMapUv ;
# endif ` ,uv_vertex: ` # if defined ( USE _UV ) || defined ( USE _ANISOTROPY )
vUv = vec3 ( uv , 1 ) . xy ;
# endif
# ifdef USE _MAP
vMapUv = ( mapTransform * vec3 ( MAP _UV , 1 ) ) . xy ;
# endif
# ifdef USE _ALPHAMAP
vAlphaMapUv = ( alphaMapTransform * vec3 ( ALPHAMAP _UV , 1 ) ) . xy ;
# endif
# ifdef USE _LIGHTMAP
vLightMapUv = ( lightMapTransform * vec3 ( LIGHTMAP _UV , 1 ) ) . xy ;
# endif
# ifdef USE _AOMAP
vAoMapUv = ( aoMapTransform * vec3 ( AOMAP _UV , 1 ) ) . xy ;
# endif
# ifdef USE _BUMPMAP
vBumpMapUv = ( bumpMapTransform * vec3 ( BUMPMAP _UV , 1 ) ) . xy ;
# endif
# ifdef USE _NORMALMAP
vNormalMapUv = ( normalMapTransform * vec3 ( NORMALMAP _UV , 1 ) ) . xy ;
# endif
# ifdef USE _DISPLACEMENTMAP
vDisplacementMapUv = ( displacementMapTransform * vec3 ( DISPLACEMENTMAP _UV , 1 ) ) . xy ;
# endif
# ifdef USE _EMISSIVEMAP
vEmissiveMapUv = ( emissiveMapTransform * vec3 ( EMISSIVEMAP _UV , 1 ) ) . xy ;
# endif
# ifdef USE _METALNESSMAP
vMetalnessMapUv = ( metalnessMapTransform * vec3 ( METALNESSMAP _UV , 1 ) ) . xy ;
# endif
# ifdef USE _ROUGHNESSMAP
vRoughnessMapUv = ( roughnessMapTransform * vec3 ( ROUGHNESSMAP _UV , 1 ) ) . xy ;
# endif
# ifdef USE _ANISOTROPYMAP
vAnisotropyMapUv = ( anisotropyMapTransform * vec3 ( ANISOTROPYMAP _UV , 1 ) ) . xy ;
# endif
# ifdef USE _CLEARCOATMAP
vClearcoatMapUv = ( clearcoatMapTransform * vec3 ( CLEARCOATMAP _UV , 1 ) ) . xy ;
# endif
# ifdef USE _CLEARCOAT _NORMALMAP
vClearcoatNormalMapUv = ( clearcoatNormalMapTransform * vec3 ( CLEARCOAT _NORMALMAP _UV , 1 ) ) . xy ;
# endif
# ifdef USE _CLEARCOAT _ROUGHNESSMAP
vClearcoatRoughnessMapUv = ( clearcoatRoughnessMapTransform * vec3 ( CLEARCOAT _ROUGHNESSMAP _UV , 1 ) ) . xy ;
# endif
# ifdef USE _IRIDESCENCEMAP
vIridescenceMapUv = ( iridescenceMapTransform * vec3 ( IRIDESCENCEMAP _UV , 1 ) ) . xy ;
# endif
# ifdef USE _IRIDESCENCE _THICKNESSMAP
vIridescenceThicknessMapUv = ( iridescenceThicknessMapTransform * vec3 ( IRIDESCENCE _THICKNESSMAP _UV , 1 ) ) . xy ;
# endif
# ifdef USE _SHEEN _COLORMAP
vSheenColorMapUv = ( sheenColorMapTransform * vec3 ( SHEEN _COLORMAP _UV , 1 ) ) . xy ;
# endif
# ifdef USE _SHEEN _ROUGHNESSMAP
vSheenRoughnessMapUv = ( sheenRoughnessMapTransform * vec3 ( SHEEN _ROUGHNESSMAP _UV , 1 ) ) . xy ;
# endif
# ifdef USE _SPECULARMAP
vSpecularMapUv = ( specularMapTransform * vec3 ( SPECULARMAP _UV , 1 ) ) . xy ;
# endif
# ifdef USE _SPECULAR _COLORMAP
vSpecularColorMapUv = ( specularColorMapTransform * vec3 ( SPECULAR _COLORMAP _UV , 1 ) ) . xy ;
# endif
# ifdef USE _SPECULAR _INTENSITYMAP
vSpecularIntensityMapUv = ( specularIntensityMapTransform * vec3 ( SPECULAR _INTENSITYMAP _UV , 1 ) ) . xy ;
# endif
# ifdef USE _TRANSMISSIONMAP
vTransmissionMapUv = ( transmissionMapTransform * vec3 ( TRANSMISSIONMAP _UV , 1 ) ) . xy ;
# endif
# ifdef USE _THICKNESSMAP
vThicknessMapUv = ( thicknessMapTransform * vec3 ( THICKNESSMAP _UV , 1 ) ) . xy ;
# endif ` ,worldpos_vertex: ` # if defined ( USE _ENVMAP ) || defined ( DISTANCE ) || defined ( USE _SHADOWMAP ) || defined ( USE _TRANSMISSION ) || NUM _SPOT _LIGHT _COORDS > 0
vec4 worldPosition = vec4 ( transformed , 1.0 ) ;
# ifdef USE _BATCHING
worldPosition = batchingMatrix * worldPosition ;
# endif
# ifdef USE _INSTANCING
worldPosition = instanceMatrix * worldPosition ;
# endif
worldPosition = modelMatrix * worldPosition ;
# endif ` ,background_vert: ` varying vec2 vUv ;
uniform mat3 uvTransform ;
void main ( ) {
vUv = ( uvTransform * vec3 ( uv , 1 ) ) . xy ;
gl _Position = vec4 ( position . xy , 1.0 , 1.0 ) ;
} ` ,background_frag: ` uniform sampler2D t2D ;
uniform float backgroundIntensity ;
varying vec2 vUv ;
void main ( ) {
vec4 texColor = texture2D ( t2D , vUv ) ;
# ifdef DECODE _VIDEO _TEXTURE
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 ) ;
# endif
texColor . rgb *= backgroundIntensity ;
gl _FragColor = texColor ;
# include < tonemapping _fragment >
# include < colorspace _fragment >
} ` ,backgroundCube_vert: ` varying vec3 vWorldDirection ;
# include < common >
void main ( ) {
vWorldDirection = transformDirection ( position , modelMatrix ) ;
# include < begin _vertex >
# include < project _vertex >
gl _Position . z = gl _Position . w ;
} ` ,backgroundCube_frag: ` # ifdef ENVMAP _TYPE _CUBE
uniform samplerCube envMap ;
# elif defined ( ENVMAP _TYPE _CUBE _UV )
uniform sampler2D envMap ;
# endif
uniform float flipEnvMap ;
uniform float backgroundBlurriness ;
uniform float backgroundIntensity ;
uniform mat3 backgroundRotation ;
varying vec3 vWorldDirection ;
# include < cube _uv _reflection _fragment >
void main ( ) {
# ifdef ENVMAP _TYPE _CUBE
vec4 texColor = textureCube ( envMap , backgroundRotation * vec3 ( flipEnvMap * vWorldDirection . x , vWorldDirection . yz ) ) ;
# elif defined ( ENVMAP _TYPE _CUBE _UV )
vec4 texColor = textureCubeUV ( envMap , backgroundRotation * vWorldDirection , backgroundBlurriness ) ;
# else
vec4 texColor = vec4 ( 0.0 , 0.0 , 0.0 , 1.0 ) ;
# endif
texColor . rgb *= backgroundIntensity ;
gl _FragColor = texColor ;
# include < tonemapping _fragment >
# include < colorspace _fragment >
} ` ,cube_vert: ` varying vec3 vWorldDirection ;
# include < common >
void main ( ) {
vWorldDirection = transformDirection ( position , modelMatrix ) ;
# include < begin _vertex >
# include < project _vertex >
gl _Position . z = gl _Position . w ;
} ` ,cube_frag: ` uniform samplerCube tCube ;
uniform float tFlip ;
uniform float opacity ;
varying vec3 vWorldDirection ;
void main ( ) {
vec4 texColor = textureCube ( tCube , vec3 ( tFlip * vWorldDirection . x , vWorldDirection . yz ) ) ;
gl _FragColor = texColor ;
gl _FragColor . a *= opacity ;
# include < tonemapping _fragment >
# include < colorspace _fragment >
} ` ,depth_vert: ` # include < common >
# include < batching _pars _vertex >
# include < uv _pars _vertex >
# include < displacementmap _pars _vertex >
# include < morphtarget _pars _vertex >
# include < skinning _pars _vertex >
# include < logdepthbuf _pars _vertex >
# include < clipping _planes _pars _vertex >
varying vec2 vHighPrecisionZW ;
void main ( ) {
# include < uv _vertex >
# include < batching _vertex >
# include < skinbase _vertex >
# include < morphinstance _vertex >
# ifdef USE _DISPLACEMENTMAP
# include < beginnormal _vertex >
# include < morphnormal _vertex >
# include < skinnormal _vertex >
# endif
# include < begin _vertex >
# include < morphtarget _vertex >
# include < skinning _vertex >
# include < displacementmap _vertex >
# include < project _vertex >
# include < logdepthbuf _vertex >
# include < clipping _planes _vertex >
vHighPrecisionZW = gl _Position . zw ;
} ` ,depth_frag: ` # if DEPTH _PACKING == 3200
uniform float opacity ;
# endif
# include < common >
# include < packing >
# include < uv _pars _fragment >
# include < map _pars _fragment >
# include < alphamap _pars _fragment >
# include < alphatest _pars _fragment >
# include < alphahash _pars _fragment >
# include < logdepthbuf _pars _fragment >
# include < clipping _planes _pars _fragment >
varying vec2 vHighPrecisionZW ;
void main ( ) {
vec4 diffuseColor = vec4 ( 1.0 ) ;
# include < clipping _planes _fragment >
# if DEPTH _PACKING == 3200
diffuseColor . a = opacity ;
# endif
# include < map _fragment >
# include < alphamap _fragment >
# include < alphatest _fragment >
# include < alphahash _fragment >
# include < logdepthbuf _fragment >
# ifdef USE _REVERSED _DEPTH _BUFFER
float fragCoordZ = vHighPrecisionZW [ 0 ] / vHighPrecisionZW [ 1 ] ;
# else
float fragCoordZ = 0.5 * vHighPrecisionZW [ 0 ] / vHighPrecisionZW [ 1 ] + 0.5 ;
# endif
# if DEPTH _PACKING == 3200
gl _FragColor = vec4 ( vec3 ( 1.0 - fragCoordZ ) , opacity ) ;
# elif DEPTH _PACKING == 3201
gl _FragColor = packDepthToRGBA ( fragCoordZ ) ;
# elif DEPTH _PACKING == 3202
gl _FragColor = vec4 ( packDepthToRGB ( fragCoordZ ) , 1.0 ) ;
# elif DEPTH _PACKING == 3203
gl _FragColor = vec4 ( packDepthToRG ( fragCoordZ ) , 0.0 , 1.0 ) ;
# endif
} ` ,distance_vert: ` # define DISTANCE
varying vec3 vWorldPosition ;
# include < common >
# include < batching _pars _vertex >
# include < uv _pars _vertex >
# include < displacementmap _pars _vertex >
# include < morphtarget _pars _vertex >
# include < skinning _pars _vertex >
# include < clipping _planes _pars _vertex >
void main ( ) {
# include < uv _vertex >
# include < batching _vertex >
# include < skinbase _vertex >
# include < morphinstance _vertex >
# ifdef USE _DISPLACEMENTMAP
# include < beginnormal _vertex >
# include < morphnormal _vertex >
# include < skinnormal _vertex >
# endif
# include < begin _vertex >
# include < morphtarget _vertex >
# include < skinning _vertex >
# include < displacementmap _vertex >
# include < project _vertex >
# include < worldpos _vertex >
# include < clipping _planes _vertex >
vWorldPosition = worldPosition . xyz ;
} ` ,distance_frag: ` # define DISTANCE
uniform vec3 referencePosition ;
uniform float nearDistance ;
uniform float farDistance ;
varying vec3 vWorldPosition ;
# include < common >
# include < uv _pars _fragment >
# include < map _pars _fragment >
# include < alphamap _pars _fragment >
# include < alphatest _pars _fragment >
# include < alphahash _pars _fragment >
# include < clipping _planes _pars _fragment >
void main ( ) {
vec4 diffuseColor = vec4 ( 1.0 ) ;
# include < clipping _planes _fragment >
# include < map _fragment >
# include < alphamap _fragment >
# include < alphatest _fragment >
# include < alphahash _fragment >
float dist = length ( vWorldPosition - referencePosition ) ;
dist = ( dist - nearDistance ) / ( farDistance - nearDistance ) ;
dist = saturate ( dist ) ;
gl _FragColor = vec4 ( dist , 0.0 , 0.0 , 1.0 ) ;
} ` ,equirect_vert: ` varying vec3 vWorldDirection ;
# include < common >
void main ( ) {
vWorldDirection = transformDirection ( position , modelMatrix ) ;
# include < begin _vertex >
# include < project _vertex >
} ` ,equirect_frag: ` uniform sampler2D tEquirect ;
varying vec3 vWorldDirection ;
# include < common >
void main ( ) {
vec3 direction = normalize ( vWorldDirection ) ;
vec2 sampleUV = equirectUv ( direction ) ;
gl _FragColor = texture2D ( tEquirect , sampleUV ) ;
# include < tonemapping _fragment >
# include < colorspace _fragment >
} ` ,linedashed_vert: ` uniform float scale ;
attribute float lineDistance ;
varying float vLineDistance ;
# include < common >
# include < uv _pars _vertex >
# include < color _pars _vertex >
# include < fog _pars _vertex >
# include < morphtarget _pars _vertex >
# include < logdepthbuf _pars _vertex >
# include < clipping _planes _pars _vertex >
void main ( ) {
vLineDistance = scale * lineDistance ;
# include < uv _vertex >
# include < color _vertex >
# include < morphinstance _vertex >
# include < morphcolor _vertex >
# include < begin _vertex >
# include < morphtarget _vertex >
# include < project _vertex >
# include < logdepthbuf _vertex >
# include < clipping _planes _vertex >
# include < fog _vertex >
} ` ,linedashed_frag: ` uniform vec3 diffuse ;
uniform float opacity ;
uniform float dashSize ;
uniform float totalSize ;
varying float vLineDistance ;
# include < common >
# include < color _pars _fragment >
# include < uv _pars _fragment >
# include < map _pars _fragment >
# include < fog _pars _fragment >
# include < logdepthbuf _pars _fragment >
# include < clipping _planes _pars _fragment >
void main ( ) {
vec4 diffuseColor = vec4 ( diffuse , opacity ) ;
# include < clipping _planes _fragment >
if ( mod ( vLineDistance , totalSize ) > dashSize ) {
discard ;
}
vec3 outgoingLight = vec3 ( 0.0 ) ;
# include < logdepthbuf _fragment >
# include < map _fragment >
# include < color _fragment >
outgoingLight = diffuseColor . rgb ;
# include < opaque _fragment >
# include < tonemapping _fragment >
# include < colorspace _fragment >
# include < fog _fragment >
# include < premultiplied _alpha _fragment >
} ` ,meshbasic_vert: ` # include < common >
# include < batching _pars _vertex >
# include < uv _pars _vertex >
# include < envmap _pars _vertex >
# include < color _pars _vertex >
# include < fog _pars _vertex >
# include < morphtarget _pars _vertex >
# include < skinning _pars _vertex >
# include < logdepthbuf _pars _vertex >
# include < clipping _planes _pars _vertex >
void main ( ) {
# include < uv _vertex >
# include < color _vertex >
# include < morphinstance _vertex >
# include < morphcolor _vertex >
# include < batching _vertex >
# if defined ( USE _ENVMAP ) || defined ( USE _SKINNING )
# include < beginnormal _vertex >
# include < morphnormal _vertex >
# include < skinbase _vertex >
# include < skinnormal _vertex >
# include < defaultnormal _vertex >
# endif
# include < begin _vertex >
# include < morphtarget _vertex >
# include < skinning _vertex >
# include < project _vertex >
# include < logdepthbuf _vertex >
# include < clipping _planes _vertex >
# include < worldpos _vertex >
# include < envmap _vertex >
# include < fog _vertex >
} ` ,meshbasic_frag: ` uniform vec3 diffuse ;
uniform float opacity ;
# ifndef FLAT _SHADED
varying vec3 vNormal ;
# endif
# include < common >
# include < dithering _pars _fragment >
# include < color _pars _fragment >
# include < uv _pars _fragment >
# include < map _pars _fragment >
# include < alphamap _pars _fragment >
# include < alphatest _pars _fragment >
# include < alphahash _pars _fragment >
# include < aomap _pars _fragment >
# include < lightmap _pars _fragment >
# include < envmap _common _pars _fragment >
# include < envmap _pars _fragment >
# include < fog _pars _fragment >
# include < specularmap _pars _fragment >
# include < logdepthbuf _pars _fragment >
# include < clipping _planes _pars _fragment >
void main ( ) {
vec4 diffuseColor = vec4 ( diffuse , opacity ) ;
# include < clipping _planes _fragment >
# include < logdepthbuf _fragment >
# include < map _fragment >
# include < color _fragment >
# include < alphamap _fragment >
# include < alphatest _fragment >
# include < alphahash _fragment >
# include < specularmap _fragment >
ReflectedLight reflectedLight = ReflectedLight ( vec3 ( 0.0 ) , vec3 ( 0.0 ) , vec3 ( 0.0 ) , vec3 ( 0.0 ) ) ;
# ifdef USE _LIGHTMAP
vec4 lightMapTexel = texture2D ( lightMap , vLightMapUv ) ;
reflectedLight . indirectDiffuse += lightMapTexel . rgb * lightMapIntensity * RECIPROCAL _PI ;
# else
reflectedLight . indirectDiffuse += vec3 ( 1.0 ) ;
# endif
# include < aomap _fragment >
reflectedLight . indirectDiffuse *= diffuseColor . rgb ;
vec3 outgoingLight = reflectedLight . indirectDiffuse ;
# include < envmap _fragment >
# include < opaque _fragment >
# include < tonemapping _fragment >
# include < colorspace _fragment >
# include < fog _fragment >
# include < premultiplied _alpha _fragment >
# include < dithering _fragment >
} ` ,meshlambert_vert: ` # define LAMBERT
varying vec3 vViewPosition ;
# include < common >
# include < batching _pars _vertex >
# include < uv _pars _vertex >
# include < displacementmap _pars _vertex >
# include < envmap _pars _vertex >
# include < color _pars _vertex >
# include < fog _pars _vertex >
# include < normal _pars _vertex >
# include < morphtarget _pars _vertex >
# include < skinning _pars _vertex >
# include < shadowmap _pars _vertex >
# include < logdepthbuf _pars _vertex >
# include < clipping _planes _pars _vertex >
void main ( ) {
# include < uv _vertex >
# include < color _vertex >
# include < morphinstance _vertex >
# include < morphcolor _vertex >
# include < batching _vertex >
# include < beginnormal _vertex >
# include < morphnormal _vertex >
# include < skinbase _vertex >
# include < skinnormal _vertex >
# include < defaultnormal _vertex >
# include < normal _vertex >
# include < begin _vertex >
# include < morphtarget _vertex >
# include < skinning _vertex >
# include < displacementmap _vertex >
# include < project _vertex >
# include < logdepthbuf _vertex >
# include < clipping _planes _vertex >
vViewPosition = - mvPosition . xyz ;
# include < worldpos _vertex >
# include < envmap _vertex >
# include < shadowmap _vertex >
# include < fog _vertex >
} ` ,meshlambert_frag: ` # define LAMBERT
uniform vec3 diffuse ;
uniform vec3 emissive ;
uniform float opacity ;
# include < common >
# include < dithering _pars _fragment >
# include < color _pars _fragment >
# include < uv _pars _fragment >
# include < map _pars _fragment >
# include < alphamap _pars _fragment >
# include < alphatest _pars _fragment >
# include < alphahash _pars _fragment >
# include < aomap _pars _fragment >
# include < lightmap _pars _fragment >
# include < emissivemap _pars _fragment >
# include < envmap _common _pars _fragment >
# include < envmap _pars _fragment >
# include < fog _pars _fragment >
# include < bsdfs >
# include < lights _pars _begin >
# include < normal _pars _fragment >
# include < lights _lambert _pars _fragment >
# include < shadowmap _pars _fragment >
# include < bumpmap _pars _fragment >
# include < normalmap _pars _fragment >
# include < specularmap _pars _fragment >
# include < logdepthbuf _pars _fragment >
# include < clipping _planes _pars _fragment >
void main ( ) {
vec4 diffuseColor = vec4 ( diffuse , opacity ) ;
# include < clipping _planes _fragment >
ReflectedLight reflectedLight = ReflectedLight ( vec3 ( 0.0 ) , vec3 ( 0.0 ) , vec3 ( 0.0 ) , vec3 ( 0.0 ) ) ;
vec3 totalEmissiveRadiance = emissive ;
# include < logdepthbuf _fragment >
# include < map _fragment >
# include < color _fragment >
# include < alphamap _fragment >
# include < alphatest _fragment >
# include < alphahash _fragment >
# include < specularmap _fragment >
# include < normal _fragment _begin >
# include < normal _fragment _maps >
# include < emissivemap _fragment >
# include < lights _lambert _fragment >
# include < lights _fragment _begin >
# include < lights _fragment _maps >
# include < lights _fragment _end >
# include < aomap _fragment >
vec3 outgoingLight = reflectedLight . directDiffuse + reflectedLight . indirectDiffuse + totalEmissiveRadiance ;
# include < envmap _fragment >
# include < opaque _fragment >
# include < tonemapping _fragment >
# include < colorspace _fragment >
# include < fog _fragment >
# include < premultiplied _alpha _fragment >
# include < dithering _fragment >
} ` ,meshmatcap_vert: ` # define MATCAP
varying vec3 vViewPosition ;
# include < common >
# include < batching _pars _vertex >
# include < uv _pars _vertex >
# include < color _pars _vertex >
# include < displacementmap _pars _vertex >
# include < fog _pars _vertex >
# include < normal _pars _vertex >
# include < morphtarget _pars _vertex >
# include < skinning _pars _vertex >
# include < logdepthbuf _pars _vertex >
# include < clipping _planes _pars _vertex >
void main ( ) {
# include < uv _vertex >
# include < color _vertex >
# include < morphinstance _vertex >
# include < morphcolor _vertex >
# include < batching _vertex >
# include < beginnormal _vertex >
# include < morphnormal _vertex >
# include < skinbase _vertex >
# include < skinnormal _vertex >
# include < defaultnormal _vertex >
# include < normal _vertex >
# include < begin _vertex >
# include < morphtarget _vertex >
# include < skinning _vertex >
# include < displacementmap _vertex >
# include < project _vertex >
# include < logdepthbuf _vertex >
# include < clipping _planes _vertex >
# include < fog _vertex >
vViewPosition = - mvPosition . xyz ;
} ` ,meshmatcap_frag: ` # define MATCAP
uniform vec3 diffuse ;
uniform float opacity ;
uniform sampler2D matcap ;
varying vec3 vViewPosition ;
# include < common >
# include < dithering _pars _fragment >
# include < color _pars _fragment >
# include < uv _pars _fragment >
# include < map _pars _fragment >
# include < alphamap _pars _fragment >
# include < alphatest _pars _fragment >
# include < alphahash _pars _fragment >
# include < fog _pars _fragment >
# include < normal _pars _fragment >
# include < bumpmap _pars _fragment >
# include < normalmap _pars _fragment >
# include < logdepthbuf _pars _fragment >
# include < clipping _planes _pars _fragment >
void main ( ) {
vec4 diffuseColor = vec4 ( diffuse , opacity ) ;
# include < clipping _planes _fragment >
# include < logdepthbuf _fragment >
# include < map _fragment >
# include < color _fragment >
# include < alphamap _fragment >
# include < alphatest _fragment >
# include < alphahash _fragment >
# include < normal _fragment _begin >
# include < normal _fragment _maps >
vec3 viewDir = normalize ( vViewPosition ) ;
vec3 x = normalize ( vec3 ( viewDir . z , 0.0 , - viewDir . x ) ) ;
vec3 y = cross ( viewDir , x ) ;
vec2 uv = vec2 ( dot ( x , normal ) , dot ( y , normal ) ) * 0.495 + 0.5 ;
# ifdef USE _MATCAP
vec4 matcapColor = texture2D ( matcap , uv ) ;
# else
vec4 matcapColor = vec4 ( vec3 ( mix ( 0.2 , 0.8 , uv . y ) ) , 1.0 ) ;
# endif
vec3 outgoingLight = diffuseColor . rgb * matcapColor . rgb ;
# include < opaque _fragment >
# include < tonemapping _fragment >
# include < colorspace _fragment >
# include < fog _fragment >
# include < premultiplied _alpha _fragment >
# include < dithering _fragment >
} ` ,meshnormal_vert: ` # define NORMAL
# if defined ( FLAT _SHADED ) || defined ( USE _BUMPMAP ) || defined ( USE _NORMALMAP _TANGENTSPACE )
varying vec3 vViewPosition ;
# endif
# include < common >
# include < batching _pars _vertex >
# include < uv _pars _vertex >
# include < displacementmap _pars _vertex >
# include < normal _pars _vertex >
# include < morphtarget _pars _vertex >
# include < skinning _pars _vertex >
# include < logdepthbuf _pars _vertex >
# include < clipping _planes _pars _vertex >
void main ( ) {
# include < uv _vertex >
# include < batching _vertex >
# include < beginnormal _vertex >
# include < morphinstance _vertex >
# include < morphnormal _vertex >
# include < skinbase _vertex >
# include < skinnormal _vertex >
# include < defaultnormal _vertex >
# include < normal _vertex >
# include < begin _vertex >
# include < morphtarget _vertex >
# include < skinning _vertex >
# include < displacementmap _vertex >
# include < project _vertex >
# include < logdepthbuf _vertex >
# include < clipping _planes _vertex >
# if defined ( FLAT _SHADED ) || defined ( USE _BUMPMAP ) || defined ( USE _NORMALMAP _TANGENTSPACE )
vViewPosition = - mvPosition . xyz ;
# endif
} ` ,meshnormal_frag: ` # define NORMAL
uniform float opacity ;
# if defined ( FLAT _SHADED ) || defined ( USE _BUMPMAP ) || defined ( USE _NORMALMAP _TANGENTSPACE )
varying vec3 vViewPosition ;
# endif
# include < uv _pars _fragment >
# include < normal _pars _fragment >
# include < bumpmap _pars _fragment >
# include < normalmap _pars _fragment >
# include < logdepthbuf _pars _fragment >
# include < clipping _planes _pars _fragment >
void main ( ) {
vec4 diffuseColor = vec4 ( 0.0 , 0.0 , 0.0 , opacity ) ;
# include < clipping _planes _fragment >
# include < logdepthbuf _fragment >
# include < normal _fragment _begin >
# include < normal _fragment _maps >
gl _FragColor = vec4 ( normalize ( normal ) * 0.5 + 0.5 , diffuseColor . a ) ;
# ifdef OPAQUE
gl _FragColor . a = 1.0 ;
# endif
} ` ,meshphong_vert: ` # define PHONG
varying vec3 vViewPosition ;
# include < common >
# include < batching _pars _vertex >
# include < uv _pars _vertex >
# include < displacementmap _pars _vertex >
# include < envmap _pars _vertex >
# include < color _pars _vertex >
# include < fog _pars _vertex >
# include < normal _pars _vertex >
# include < morphtarget _pars _vertex >
# include < skinning _pars _vertex >
# include < shadowmap _pars _vertex >
# include < logdepthbuf _pars _vertex >
# include < clipping _planes _pars _vertex >
void main ( ) {
# include < uv _vertex >
# include < color _vertex >
# include < morphcolor _vertex >
# include < batching _vertex >
# include < beginnormal _vertex >
# include < morphinstance _vertex >
# include < morphnormal _vertex >
# include < skinbase _vertex >
# include < skinnormal _vertex >
# include < defaultnormal _vertex >
# include < normal _vertex >
# include < begin _vertex >
# include < morphtarget _vertex >
# include < skinning _vertex >
# include < displacementmap _vertex >
# include < project _vertex >
# include < logdepthbuf _vertex >
# include < clipping _planes _vertex >
vViewPosition = - mvPosition . xyz ;
# include < worldpos _vertex >
# include < envmap _vertex >
# include < shadowmap _vertex >
# include < fog _vertex >
} ` ,meshphong_frag: ` # define PHONG
uniform vec3 diffuse ;
uniform vec3 emissive ;
uniform vec3 specular ;
uniform float shininess ;
uniform float opacity ;
# include < common >
# include < dithering _pars _fragment >
# include < color _pars _fragment >
# include < uv _pars _fragment >
# include < map _pars _fragment >
# include < alphamap _pars _fragment >
# include < alphatest _pars _fragment >
# include < alphahash _pars _fragment >
# include < aomap _pars _fragment >
# include < lightmap _pars _fragment >
# include < emissivemap _pars _fragment >
# include < envmap _common _pars _fragment >
# include < envmap _pars _fragment >
# include < fog _pars _fragment >
# include < bsdfs >
# include < lights _pars _begin >
# include < normal _pars _fragment >
# include < lights _phong _pars _fragment >
# include < shadowmap _pars _fragment >
# include < bumpmap _pars _fragment >
# include < normalmap _pars _fragment >
# include < specularmap _pars _fragment >
# include < logdepthbuf _pars _fragment >
# include < clipping _planes _pars _fragment >
void main ( ) {
vec4 diffuseColor = vec4 ( diffuse , opacity ) ;
# include < clipping _planes _fragment >
ReflectedLight reflectedLight = ReflectedLight ( vec3 ( 0.0 ) , vec3 ( 0.0 ) , vec3 ( 0.0 ) , vec3 ( 0.0 ) ) ;
vec3 totalEmissiveRadiance = emissive ;
# include < logdepthbuf _fragment >
# include < map _fragment >
# include < color _fragment >
# include < alphamap _fragment >
# include < alphatest _fragment >
# include < alphahash _fragment >
# include < specularmap _fragment >
# include < normal _fragment _begin >
# include < normal _fragment _maps >
# include < emissivemap _fragment >
# include < lights _phong _fragment >
# include < lights _fragment _begin >
# include < lights _fragment _maps >
# include < lights _fragment _end >
# include < aomap _fragment >
vec3 outgoingLight = reflectedLight . directDiffuse + reflectedLight . indirectDiffuse + reflectedLight . directSpecular + reflectedLight . indirectSpecular + totalEmissiveRadiance ;
# include < envmap _fragment >
# include < opaque _fragment >
# include < tonemapping _fragment >
# include < colorspace _fragment >
# include < fog _fragment >
# include < premultiplied _alpha _fragment >
# include < dithering _fragment >
} ` ,meshphysical_vert: ` # define STANDARD
varying vec3 vViewPosition ;
# ifdef USE _TRANSMISSION
varying vec3 vWorldPosition ;
# endif
# include < common >
# include < batching _pars _vertex >
# include < uv _pars _vertex >
# include < displacementmap _pars _vertex >
# include < color _pars _vertex >
# include < fog _pars _vertex >
# include < normal _pars _vertex >
# include < morphtarget _pars _vertex >
# include < skinning _pars _vertex >
# include < shadowmap _pars _vertex >
# include < logdepthbuf _pars _vertex >
# include < clipping _planes _pars _vertex >
void main ( ) {
# include < uv _vertex >
# include < color _vertex >
# include < morphinstance _vertex >
# include < morphcolor _vertex >
# include < batching _vertex >
# include < beginnormal _vertex >
# include < morphnormal _vertex >
# include < skinbase _vertex >
# include < skinnormal _vertex >
# include < defaultnormal _vertex >
# include < normal _vertex >
# include < begin _vertex >
# include < morphtarget _vertex >
# include < skinning _vertex >
# include < displacementmap _vertex >
# include < project _vertex >
# include < logdepthbuf _vertex >
# include < clipping _planes _vertex >
vViewPosition = - mvPosition . xyz ;
# include < worldpos _vertex >
# include < shadowmap _vertex >
# include < fog _vertex >
# ifdef USE _TRANSMISSION
vWorldPosition = worldPosition . xyz ;
# endif
} ` ,meshphysical_frag: ` # define STANDARD
# ifdef PHYSICAL
# define IOR
# define USE _SPECULAR
# endif
uniform vec3 diffuse ;
uniform vec3 emissive ;
uniform float roughness ;
uniform float metalness ;
uniform float opacity ;
# ifdef IOR
uniform float ior ;
# endif
# ifdef USE _SPECULAR
uniform float specularIntensity ;
uniform vec3 specularColor ;
# ifdef USE _SPECULAR _COLORMAP
uniform sampler2D specularColorMap ;
# endif
# ifdef USE _SPECULAR _INTENSITYMAP
uniform sampler2D specularIntensityMap ;
# endif
# endif
# ifdef USE _CLEARCOAT
uniform float clearcoat ;
uniform float clearcoatRoughness ;
# endif
# ifdef USE _DISPERSION
uniform float dispersion ;
# endif
# ifdef USE _IRIDESCENCE
uniform float iridescence ;
uniform float iridescenceIOR ;
uniform float iridescenceThicknessMinimum ;
uniform float iridescenceThicknessMaximum ;
# endif
# ifdef USE _SHEEN
uniform vec3 sheenColor ;
uniform float sheenRoughness ;
# ifdef USE _SHEEN _COLORMAP
uniform sampler2D sheenColorMap ;
# endif
# ifdef USE _SHEEN _ROUGHNESSMAP
uniform sampler2D sheenRoughnessMap ;
# endif
# endif
# ifdef USE _ANISOTROPY
uniform vec2 anisotropyVector ;
# ifdef USE _ANISOTROPYMAP
uniform sampler2D anisotropyMap ;
# endif
# endif
varying vec3 vViewPosition ;
# include < common >
# include < dithering _pars _fragment >
# include < color _pars _fragment >
# include < uv _pars _fragment >
# include < map _pars _fragment >
# include < alphamap _pars _fragment >
# include < alphatest _pars _fragment >
# include < alphahash _pars _fragment >
# include < aomap _pars _fragment >
# include < lightmap _pars _fragment >
# include < emissivemap _pars _fragment >
# include < iridescence _fragment >
# include < cube _uv _reflection _fragment >
# include < envmap _common _pars _fragment >
# include < envmap _physical _pars _fragment >
# include < fog _pars _fragment >
# include < lights _pars _begin >
# include < normal _pars _fragment >
# include < lights _physical _pars _fragment >
# include < transmission _pars _fragment >
# include < shadowmap _pars _fragment >
# include < bumpmap _pars _fragment >
# include < normalmap _pars _fragment >
# include < clearcoat _pars _fragment >
# include < iridescence _pars _fragment >
# include < roughnessmap _pars _fragment >
# include < metalnessmap _pars _fragment >
# include < logdepthbuf _pars _fragment >
# include < clipping _planes _pars _fragment >
void main ( ) {
vec4 diffuseColor = vec4 ( diffuse , opacity ) ;
# include < clipping _planes _fragment >
ReflectedLight reflectedLight = ReflectedLight ( vec3 ( 0.0 ) , vec3 ( 0.0 ) , vec3 ( 0.0 ) , vec3 ( 0.0 ) ) ;
vec3 totalEmissiveRadiance = emissive ;
# include < logdepthbuf _fragment >
# include < map _fragment >
# include < color _fragment >
# include < alphamap _fragment >
# include < alphatest _fragment >
# include < alphahash _fragment >
# include < roughnessmap _fragment >
# include < metalnessmap _fragment >
# include < normal _fragment _begin >
# include < normal _fragment _maps >
# include < clearcoat _normal _fragment _begin >
# include < clearcoat _normal _fragment _maps >
# include < emissivemap _fragment >
# include < lights _physical _fragment >
# include < lights _fragment _begin >
# include < lights _fragment _maps >
# include < lights _fragment _end >
# include < aomap _fragment >
vec3 totalDiffuse = reflectedLight . directDiffuse + reflectedLight . indirectDiffuse ;
vec3 totalSpecular = reflectedLight . directSpecular + reflectedLight . indirectSpecular ;
# include < transmission _fragment >
vec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance ;
# ifdef USE _SHEEN
outgoingLight = outgoingLight + sheenSpecularDirect + sheenSpecularIndirect ;
# endif
# ifdef USE _CLEARCOAT
float dotNVcc = saturate ( dot ( geometryClearcoatNormal , geometryViewDir ) ) ;
vec3 Fcc = F _Schlick ( material . clearcoatF0 , material . clearcoatF90 , dotNVcc ) ;
outgoingLight = outgoingLight * ( 1.0 - material . clearcoat * Fcc ) + ( clearcoatSpecularDirect + clearcoatSpecularIndirect ) * material . clearcoat ;
# endif
# include < opaque _fragment >
# include < tonemapping _fragment >
# include < colorspace _fragment >
# include < fog _fragment >
# include < premultiplied _alpha _fragment >
# include < dithering _fragment >
} ` ,meshtoon_vert: ` # define TOON
varying vec3 vViewPosition ;
# include < common >
# include < batching _pars _vertex >
# include < uv _pars _vertex >
# include < displacementmap _pars _vertex >
# include < color _pars _vertex >
# include < fog _pars _vertex >
# include < normal _pars _vertex >
# include < morphtarget _pars _vertex >
# include < skinning _pars _vertex >
# include < shadowmap _pars _vertex >
# include < logdepthbuf _pars _vertex >
# include < clipping _planes _pars _vertex >
void main ( ) {
# include < uv _vertex >
# include < color _vertex >
# include < morphinstance _vertex >
# include < morphcolor _vertex >
# include < batching _vertex >
# include < beginnormal _vertex >
# include < morphnormal _vertex >
# include < skinbase _vertex >
# include < skinnormal _vertex >
# include < defaultnormal _vertex >
# include < normal _vertex >
# include < begin _vertex >
# include < morphtarget _vertex >
# include < skinning _vertex >
# include < displacementmap _vertex >
# include < project _vertex >
# include < logdepthbuf _vertex >
# include < clipping _planes _vertex >
vViewPosition = - mvPosition . xyz ;
# include < worldpos _vertex >
# include < shadowmap _vertex >
# include < fog _vertex >
} ` ,meshtoon_frag: ` # define TOON
uniform vec3 diffuse ;
uniform vec3 emissive ;
uniform float opacity ;
# include < common >
# include < dithering _pars _fragment >
# include < color _pars _fragment >
# include < uv _pars _fragment >
# include < map _pars _fragment >
# include < alphamap _pars _fragment >
# include < alphatest _pars _fragment >
# include < alphahash _pars _fragment >
# include < aomap _pars _fragment >
# include < lightmap _pars _fragment >
# include < emissivemap _pars _fragment >
# include < gradientmap _pars _fragment >
# include < fog _pars _fragment >
# include < bsdfs >
# include < lights _pars _begin >
# include < normal _pars _fragment >
# include < lights _toon _pars _fragment >
# include < shadowmap _pars _fragment >
# include < bumpmap _pars _fragment >
# include < normalmap _pars _fragment >
# include < logdepthbuf _pars _fragment >
# include < clipping _planes _pars _fragment >
void main ( ) {
vec4 diffuseColor = vec4 ( diffuse , opacity ) ;
# include < clipping _planes _fragment >
ReflectedLight reflectedLight = ReflectedLight ( vec3 ( 0.0 ) , vec3 ( 0.0 ) , vec3 ( 0.0 ) , vec3 ( 0.0 ) ) ;
vec3 totalEmissiveRadiance = emissive ;
# include < logdepthbuf _fragment >
# include < map _fragment >
# include < color _fragment >
# include < alphamap _fragment >
# include < alphatest _fragment >
# include < alphahash _fragment >
# include < normal _fragment _begin >
# include < normal _fragment _maps >
# include < emissivemap _fragment >
# include < lights _toon _fragment >
# include < lights _fragment _begin >
# include < lights _fragment _maps >
# include < lights _fragment _end >
# include < aomap _fragment >
vec3 outgoingLight = reflectedLight . directDiffuse + reflectedLight . indirectDiffuse + totalEmissiveRadiance ;
# include < opaque _fragment >
# include < tonemapping _fragment >
# include < colorspace _fragment >
# include < fog _fragment >
# include < premultiplied _alpha _fragment >
# include < dithering _fragment >
} ` ,points_vert: ` uniform float size ;
uniform float scale ;
# include < common >
# include < color _pars _vertex >
# include < fog _pars _vertex >
# include < morphtarget _pars _vertex >
# include < logdepthbuf _pars _vertex >
# include < clipping _planes _pars _vertex >
# ifdef USE _POINTS _UV
varying vec2 vUv ;
uniform mat3 uvTransform ;
# endif
void main ( ) {
# ifdef USE _POINTS _UV
vUv = ( uvTransform * vec3 ( uv , 1 ) ) . xy ;
# endif
# include < color _vertex >
# include < morphinstance _vertex >
# include < morphcolor _vertex >
# include < begin _vertex >
# include < morphtarget _vertex >
# include < project _vertex >
gl _PointSize = size ;
# ifdef USE _SIZEATTENUATION
bool isPerspective = isPerspectiveMatrix ( projectionMatrix ) ;
if ( isPerspective ) gl _PointSize *= ( scale / - mvPosition . z ) ;
# endif
# include < logdepthbuf _vertex >
# include < clipping _planes _vertex >
# include < worldpos _vertex >
# include < fog _vertex >
} ` ,points_frag: ` uniform vec3 diffuse ;
uniform float opacity ;
# include < common >
# include < color _pars _fragment >
# include < map _particle _pars _fragment >
# include < alphatest _pars _fragment >
# include < alphahash _pars _fragment >
# include < fog _pars _fragment >
# include < logdepthbuf _pars _fragment >
# include < clipping _planes _pars _fragment >
void main ( ) {
vec4 diffuseColor = vec4 ( diffuse , opacity ) ;
# include < clipping _planes _fragment >
vec3 outgoingLight = vec3 ( 0.0 ) ;
# include < logdepthbuf _fragment >
# include < map _particle _fragment >
# include < color _fragment >
# include < alphatest _fragment >
# include < alphahash _fragment >
outgoingLight = diffuseColor . rgb ;
# include < opaque _fragment >
# include < tonemapping _fragment >
# include < colorspace _fragment >
# include < fog _fragment >
# include < premultiplied _alpha _fragment >
} ` ,shadow_vert: ` # include < common >
# include < batching _pars _vertex >
# include < fog _pars _vertex >
# include < morphtarget _pars _vertex >
# include < skinning _pars _vertex >
# include < logdepthbuf _pars _vertex >
# include < shadowmap _pars _vertex >
void main ( ) {
# include < batching _vertex >
# include < beginnormal _vertex >
# include < morphinstance _vertex >
# include < morphnormal _vertex >
# include < skinbase _vertex >
# include < skinnormal _vertex >
# include < defaultnormal _vertex >
# include < begin _vertex >
# include < morphtarget _vertex >
# include < skinning _vertex >
# include < project _vertex >
# include < logdepthbuf _vertex >
# include < worldpos _vertex >
# include < shadowmap _vertex >
# include < fog _vertex >
} ` ,shadow_frag: ` uniform vec3 color ;
uniform float opacity ;
# include < common >
# include < fog _pars _fragment >
# include < bsdfs >
# include < lights _pars _begin >
# include < logdepthbuf _pars _fragment >
# include < shadowmap _pars _fragment >
# include < shadowmask _pars _fragment >
void main ( ) {
# include < logdepthbuf _fragment >
gl _FragColor = vec4 ( color , opacity * ( 1.0 - getShadowMask ( ) ) ) ;
# include < tonemapping _fragment >
# include < colorspace _fragment >
# include < fog _fragment >
} ` ,sprite_vert: ` uniform float rotation ;
uniform vec2 center ;
# include < common >
# include < uv _pars _vertex >
# include < fog _pars _vertex >
# include < logdepthbuf _pars _vertex >
# include < clipping _planes _pars _vertex >
void main ( ) {
# include < uv _vertex >
vec4 mvPosition = modelViewMatrix [ 3 ] ;
vec2 scale = vec2 ( length ( modelMatrix [ 0 ] . xyz ) , length ( modelMatrix [ 1 ] . xyz ) ) ;
# ifndef USE _SIZEATTENUATION
bool isPerspective = isPerspectiveMatrix ( projectionMatrix ) ;
if ( isPerspective ) scale *= - mvPosition . z ;
# endif
vec2 alignedPosition = ( position . xy - ( center - vec2 ( 0.5 ) ) ) * scale ;
vec2 rotatedPosition ;
rotatedPosition . x = cos ( rotation ) * alignedPosition . x - sin ( rotation ) * alignedPosition . y ;
rotatedPosition . y = sin ( rotation ) * alignedPosition . x + cos ( rotation ) * alignedPosition . y ;
mvPosition . xy += rotatedPosition ;
gl _Position = projectionMatrix * mvPosition ;
# include < logdepthbuf _vertex >
# include < clipping _planes _vertex >
# include < fog _vertex >
} ` ,sprite_frag: ` uniform vec3 diffuse ;
uniform float opacity ;
# include < common >
# include < uv _pars _fragment >
# include < map _pars _fragment >
# include < alphamap _pars _fragment >
# include < alphatest _pars _fragment >
# include < alphahash _pars _fragment >
# include < fog _pars _fragment >
# include < logdepthbuf _pars _fragment >
# include < clipping _planes _pars _fragment >
void main ( ) {
vec4 diffuseColor = vec4 ( diffuse , opacity ) ;
# include < clipping _planes _fragment >
vec3 outgoingLight = vec3 ( 0.0 ) ;
# include < logdepthbuf _fragment >
# include < map _fragment >
# include < alphamap _fragment >
# include < alphatest _fragment >
# include < alphahash _fragment >
outgoingLight = diffuseColor . rgb ;
# include < opaque _fragment >
# include < tonemapping _fragment >
# include < colorspace _fragment >
# include < fog _fragment >
} ` }, $ ={common:{diffuse:{value:new Y(16777215)},opacity:{value:1},map:{value:null},mapTransform:{value:new G},alphaMap:{value:null},alphaMapTransform:{value:new G},alphaTest:{value:0}},specularmap:{specularMap:{value:null},specularMapTransform:{value:new G}},envmap:{envMap:{value:null},envMapRotation:{value:new G},flipEnvMap:{value:-1},reflectivity:{value:1},ior:{value:1.5},refractionRatio:{value:.98},dfgLUT:{value:null}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1},aoMapTransform:{value:new G}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1},lightMapTransform:{value:new G}},bumpmap:{bumpMap:{value:null},bumpMapTransform:{value:new G},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalMapTransform:{value:new G},normalScale:{value:new U(1,1)}},displacementmap:{displacementMap:{value:null},displacementMapTransform:{value:new G},displacementScale:{value:1},displacementBias:{value:0}},emissivemap:{emissiveMap:{value:null},emissiveMapTransform:{value:new G}},metalnessmap:{metalnessMap:{value:null},metalnessMapTransform:{value:new G}},roughnessmap:{roughnessMap:{value:null},roughnessMapTransform:{value:new G}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new Y(16777215)}},lights:{ambientLightColor:{value:[]},lightProbe:{value:[]},directionalLights:{value:[],properties:{direction:{},color:{}}},directionalLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},directionalShadowMap:{value:[]},directionalShadowMatrix:{value:[]},spotLights:{value:[],properties:{color:{},position:{},direction:{},distance:{},coneCos:{},penumbraCos:{},decay:{}}},spotLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},spotLightMap:{value:[]},spotShadowMap:{value:[]},spotLightMatrix:{value:[]},pointLights:{value:[],properties:{color:{},position:{},decay:{},distance:{}}},pointLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{},shadowCameraNear:{},shadowCameraFar:{}}},pointShadowMap:{value:[]},pointShadowMatrix:{value:[]},hemisphereLights:{value:[],properties:{direction:{},skyColor:{},groundColor:{}}},rectAreaLights:{value:[],properties:{color:{},position:{},width:{},height:{}}},ltc_1:{value:null},ltc_2:{value:null}},points:{diffuse:{value:new Y(16777215)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},alphaMapTransform:{value:new G},alphaTest:{value:0},uvTransform:{value:new G}},sprite:{diffuse:{value:new Y(16777215)},opacity:{value:1},center:{value:new U(.5,.5)},rotation:{value:0},map:{value:null},mapTransform:{value:new G},alphaMap:{value:null},alphaMapTransform:{value:new G},alphaTest:{value:0}}},bf={basic:{uniforms:Ui([ $ .common, $ .specularmap, $ .envmap, $ .aomap, $ .lightmap, $ .fog]),vertexShader:Q.meshbasic_vert,fragmentShader:Q.meshbasic_frag},lambert:{uniforms:Ui([ $ .common, $ .specularmap, $ .envmap, $ .aomap, $ .lightmap, $ .emissivemap, $ .bumpmap, $ .normalmap, $ .displacementmap, $ .fog, $ .lights,{emissive:{value:new Y(0)}}]),vertexShader:Q.meshlambert_vert,fragmentShader:Q.meshlambert_frag},phong:{uniforms:Ui([ $ .common, $ .specularmap, $ .envmap, $ .aomap, $ .lightmap, $ .emissivemap, $ .bumpmap, $ .normalmap, $ .displacementmap, $ .fog, $ .lights,{emissive:{value:new Y(0)},specular:{value:new Y(1118481)},shininess:{value:30}}]),vertexShader:Q.meshphong_vert,fragmentShader:Q.meshphong_frag},standard:{uniforms:Ui([ $ .common, $ .envmap, $ .aomap, $ .lightmap, $ .emissivemap, $ .bumpmap, $ .normalmap, $ .displacementmap, $ .roughnessmap, $ .metalnessmap, $ .fog, $ .lights,{emissive:{value:new Y(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:Q.meshphysical_vert,fragmentShader:Q.meshphysical_frag},toon:{uniforms:Ui([ $ .common, $ .aomap, $ .lightmap, $ .emissivemap, $ .bumpmap, $ .normalmap, $ .displacementmap, $ .gradientmap, $ .fog, $ .lights,{emissive:{value:new Y(0)}}]),vertexShader:Q.meshtoon_vert,fragmentShader:Q.meshtoon_frag},matcap:{uniforms:Ui
precision highp float ;
precision highp int ;
varying vec3 vOutputDirection ;
uniform sampler2D envMap ;
uniform float roughness ;
uniform float mipInt ;
# define ENVMAP _TYPE _CUBE _UV
# include < cube _uv _reflection _fragment >
# define PI 3.14159265359
// Van der Corput radical inverse
float radicalInverse _VdC ( uint bits ) {
bits = ( bits << 16 u ) | ( bits >> 16 u ) ;
bits = ( ( bits & 0x55555555 u ) << 1 u ) | ( ( bits & 0xAAAAAAAA u ) >> 1 u ) ;
bits = ( ( bits & 0x33333333 u ) << 2 u ) | ( ( bits & 0xCCCCCCCC u ) >> 2 u ) ;
bits = ( ( bits & 0x0F0F0F0F u ) << 4 u ) | ( ( bits & 0xF0F0F0F0 u ) >> 4 u ) ;
bits = ( ( bits & 0x00FF00FF u ) << 8 u ) | ( ( bits & 0xFF00FF00 u ) >> 8 u ) ;
return float ( bits ) * 2.3283064365386963 e - 10 ; // / 0x100000000
}
// Hammersley sequence
vec2 hammersley ( uint i , uint N ) {
return vec2 ( float ( i ) / float ( N ) , radicalInverse _VdC ( i ) ) ;
}
// GGX VNDF importance sampling (Eric Heitz 2018)
// "Sampling the GGX Distribution of Visible Normals"
// https://jcgt.org/published/0007/04/01/
vec3 importanceSampleGGX _VNDF ( vec2 Xi , vec3 V , float roughness ) {
float alpha = roughness * roughness ;
// Section 3.2: Transform view direction to hemisphere configuration
vec3 Vh = normalize ( vec3 ( alpha * V . x , alpha * V . y , V . z ) ) ;
// Section 4.1: Orthonormal basis
float lensq = Vh . x * Vh . x + Vh . y * Vh . y ;
vec3 T1 = lensq > 0.0 ? vec3 ( - Vh . y , Vh . x , 0.0 ) / sqrt ( lensq ) : vec3 ( 1.0 , 0.0 , 0.0 ) ;
vec3 T2 = cross ( Vh , T1 ) ;
// Section 4.2: Parameterization of projected area
float r = sqrt ( Xi . x ) ;
float phi = 2.0 * PI * Xi . y ;
float t1 = r * cos ( phi ) ;
float t2 = r * sin ( phi ) ;
float s = 0.5 * ( 1.0 + Vh . z ) ;
t2 = ( 1.0 - s ) * sqrt ( 1.0 - t1 * t1 ) + s * t2 ;
// Section 4.3: Reprojection onto hemisphere
vec3 Nh = t1 * T1 + t2 * T2 + sqrt ( max ( 0.0 , 1.0 - t1 * t1 - t2 * t2 ) ) * Vh ;
// Section 3.4: Transform back to ellipsoid configuration
return normalize ( vec3 ( alpha * Nh . x , alpha * Nh . y , max ( 0.0 , Nh . z ) ) ) ;
}
void main ( ) {
vec3 N = normalize ( vOutputDirection ) ;
vec3 V = N ; // Assume view direction equals normal for pre-filtering
vec3 prefilteredColor = vec3 ( 0.0 ) ;
float totalWeight = 0.0 ;
// For very low roughness, just sample the environment directly
if ( roughness < 0.001 ) {
gl _FragColor = vec4 ( bilinearCubeUV ( envMap , N , mipInt ) , 1.0 ) ;
return ;
}
// Tangent space basis for VNDF sampling
vec3 up = abs ( N . z ) < 0.999 ? vec3 ( 0.0 , 0.0 , 1.0 ) : vec3 ( 1.0 , 0.0 , 0.0 ) ;
vec3 tangent = normalize ( cross ( up , N ) ) ;
vec3 bitangent = cross ( N , tangent ) ;
for ( uint i = 0 u ; i < uint ( GGX _SAMPLES ) ; i ++ ) {
vec2 Xi = hammersley ( i , uint ( GGX _SAMPLES ) ) ;
// For PMREM, V = N, so in tangent space V is always (0, 0, 1)
vec3 H _tangent = importanceSampleGGX _VNDF ( Xi , vec3 ( 0.0 , 0.0 , 1.0 ) , roughness ) ;
// Transform H back to world space
vec3 H = normalize ( tangent * H _tangent . x + bitangent * H _tangent . y + N * H _tangent . z ) ;
vec3 L = normalize ( 2.0 * dot ( V , H ) * H - V ) ;
float NdotL = max ( dot ( N , L ) , 0.0 ) ;
if ( NdotL > 0.0 ) {
// Sample environment at fixed mip level
// VNDF importance sampling handles the distribution filtering
vec3 sampleColor = bilinearCubeUV ( envMap , L , mipInt ) ;
// Weight by NdotL for the split-sum approximation
// VNDF PDF naturally accounts for the visible microfacet distribution
prefilteredColor += sampleColor * NdotL ;
totalWeight += NdotL ;
}
}
if ( totalWeight > 0.0 ) {
prefilteredColor = prefilteredColor / totalWeight ;
}
gl _FragColor = vec4 ( prefilteredColor , 1.0 ) ;
}
` ,blending:0,depthTest:!1,depthWrite:!1})}function Kf(e,t,n){let r=new Float32Array(Mf),i=new W(0,1,0);return new Yi({name: ` SphericalGaussianBlur ` ,defines:{n:Mf,CUBEUV_TEXEL_WIDTH:1/t,CUBEUV_TEXEL_HEIGHT:1/n,CUBEUV_MAX_MIP: ` $ { e } . 0 ` },uniforms:{envMap:{value:null},samples:{value:1},weights:{value:r},latitudinal:{value:!1},dTheta:{value:0},mipInt:{value:0},poleAxis:{value:i}},vertexShader:Yf(),fragmentShader: `
precision mediump float ;
precision mediump int ;
varying vec3 vOutputDirection ;
uniform sampler2D envMap ;
uniform int samples ;
uniform float weights [ n ] ;
uniform bool latitudinal ;
uniform float dTheta ;
uniform float mipInt ;
uniform vec3 poleAxis ;
# define ENVMAP _TYPE _CUBE _UV
# include < cube _uv _reflection _fragment >
vec3 getSample ( float theta , vec3 axis ) {
float cosTheta = cos ( theta ) ;
// Rodrigues' axis-angle rotation
vec3 sampleDirection = vOutputDirection * cosTheta
+ cross ( axis , vOutputDirection ) * sin ( theta )
+ axis * dot ( axis , vOutputDirection ) * ( 1.0 - cosTheta ) ;
return bilinearCubeUV ( envMap , sampleDirection , mipInt ) ;
}
void main ( ) {
vec3 axis = latitudinal ? poleAxis : cross ( poleAxis , vOutputDirection ) ;
if ( all ( equal ( axis , vec3 ( 0.0 ) ) ) ) {
axis = vec3 ( vOutputDirection . z , 0.0 , - vOutputDirection . x ) ;
}
axis = normalize ( axis ) ;
gl _FragColor = vec4 ( 0.0 , 0.0 , 0.0 , 1.0 ) ;
gl _FragColor . rgb += weights [ 0 ] * getSample ( 0.0 , axis ) ;
for ( int i = 1 ; i < n ; i ++ ) {
if ( i >= samples ) {
break ;
}
float theta = dTheta * float ( i ) ;
gl _FragColor . rgb += weights [ i ] * getSample ( - 1.0 * theta , axis ) ;
gl _FragColor . rgb += weights [ i ] * getSample ( theta , axis ) ;
}
}
` ,blending:0,depthTest:!1,depthWrite:!1})}function qf(){return new Yi({name: ` EquirectangularToCubeUV ` ,uniforms:{envMap:{value:null}},vertexShader:Yf(),fragmentShader: `
precision mediump float ;
precision mediump int ;
varying vec3 vOutputDirection ;
uniform sampler2D envMap ;
# include < common >
void main ( ) {
vec3 outputDirection = normalize ( vOutputDirection ) ;
vec2 uv = equirectUv ( outputDirection ) ;
gl _FragColor = vec4 ( texture2D ( envMap , uv ) . rgb , 1.0 ) ;
}
` ,blending:0,depthTest:!1,depthWrite:!1})}function Jf(){return new Yi({name: ` CubemapToCubeUV ` ,uniforms:{envMap:{value:null},flipEnvMap:{value:-1}},vertexShader:Yf(),fragmentShader: `
precision mediump float ;
precision mediump int ;
uniform float flipEnvMap ;
varying vec3 vOutputDirection ;
uniform samplerCube envMap ;
void main ( ) {
gl _FragColor = textureCube ( envMap , vec3 ( flipEnvMap * vOutputDirection . x , vOutputDirection . yz ) ) ;
}
` ,blending:0,depthTest:!1,depthWrite:!1})}function Yf(){return `
precision mediump float ;
precision mediump int ;
attribute float faceIndex ;
varying vec3 vOutputDirection ;
// RH coordinate system; PMREM face-indexing convention
vec3 getDirection ( vec2 uv , float face ) {
uv = 2.0 * uv - 1.0 ;
vec3 direction = vec3 ( uv , 1.0 ) ;
if ( face == 0.0 ) {
direction = direction . zyx ; // ( 1, v, u ) pos x
} else if ( face == 1.0 ) {
direction = direction . xzy ;
direction . xz *= - 1.0 ; // ( -u, 1, -v ) pos y
} else if ( face == 2.0 ) {
direction . x *= - 1.0 ; // ( -u, v, 1 ) pos z
} else if ( face == 3.0 ) {
direction = direction . zyx ;
direction . xz *= - 1.0 ; // ( -1, v, -u ) neg x
} else if ( face == 4.0 ) {
direction = direction . xzy ;
direction . xy *= - 1.0 ; // ( -u, -1, v ) neg y
} else if ( face == 5.0 ) {
direction . z *= - 1.0 ; // ( u, v, -1 ) neg z
}
return direction ;
}
void main ( ) {
vOutputDirection = getDirection ( uv , faceIndex ) ;
gl _Position = vec4 ( position , 1.0 ) ;
}
` }function Xf(e){let t=new WeakMap,n=null;function r(r){if(r&&r.isTexture){let o=r.mapping,s=o===303||o===304,c=o===301||o===302;if(s||c){let o=t.get(r),l=o===void 0?0:o.texture.pmremVersion;if(r.isRenderTargetTexture&&r.pmremVersion!==l)return n===null&&(n=new Vf(e)),o=s?n.fromEquirectangular(r,o):n.fromCubemap(r,o),o.texture.pmremVersion=r.pmremVersion,t.set(r,o),o.texture;if(o!==void 0)return o.texture;{let l=r.image;return s&&l&&l.height>0||c&&l&&i(l)?(n===null&&(n=new Vf(e)),o=s?n.fromEquirectangular(r):n.fromCubemap(r),o.texture.pmremVersion=r.pmremVersion,t.set(r,o),r.addEventListener( ` dispose ` ,a),o.texture):null}}}return r}function i(e){let t=0;for(let n=0;n<6;n++)e[n]!==void 0&&t++;return t===6}function a(e){let n=e.target;n.removeEventListener( ` dispose ` ,a);let r=t.get(n);r!==void 0&&(t.delete(n),r.dispose())}function o(){t=new WeakMap,n!==null&&(n.dispose(),n=null)}return{get:r,dispose:o}}function Zf(e){let t={};function n(n){if(t[n]!==void 0)return t[n];let r=e.getExtension(n);return t[n]=r,r}return{has:function(e){return n(e)!==null},init:function(){n( ` EXT _color _buffer _float ` ),n( ` WEBGL _clip _cull _distance ` ),n( ` OES _texture _float _linear ` ),n( ` EXT _color _buffer _half _float ` ),n( ` WEBGL _multisampled _render _to _texture ` ),n( ` WEBGL _render _shared _exponent ` )},get:function(e){let t=n(e);return t===null&&Lt( ` WebGLRenderer : ` +e+ ` extension not supported . ` ),t}}}function Qf(e,t,n,r){let i={},a=new WeakMap;function o(e){let s=e.target;s.index!==null&&t.remove(s.index);for(let e in s.attributes)t.remove(s.attributes[e]);s.removeEventListener( ` dispose ` ,o),delete i[s.id];let c=a.get(s);c&&(t.remove(c),a.delete(s)),r.releaseStatesOfGeometry(s),s.isInstancedBufferGeometry===!0&&delete s._maxInstanceCount,n.memory.geometries--}function s(e,t){return i[t.id]===!0?t:(t.addEventListener( ` dispose ` ,o),i[t.id]=!0,n.memory.geometries++,t)}function c(n){let r=n.attributes;for(let n in r)t.update(r[n],e.ARRAY_BUFFER)}function l(e){let n=[],r=e.index,i=e.attributes.position,o=0;if(r!==null){let e=r.array;o=r.version;for(let t=0,r=e.length;t<r;t+=3){let r=e[t+0],i=e[t+1],a=e[t+2];n.push(r,i,i,a,a,r)}}else if(i!==void 0){let e=i.array;o=i.version;for(let t=0,r=e.length/3-1;t<r;t+=3){let e=t+0,r=t+1,i=t+2;n.push(e,r,r,i,i,e)}}else return;let s=new(Et(n)?vi:gi)(n,1);s.version=o;let c=a.get(e);c&&t.remove(c),a.set(e,s)}function u(e){let t=a.get(e);if(t){let n=e.index;n!==null&&t.version<n.version&&l(e)}else l(e);return a.get(e)}return{get:s,update:c,getWireframeAttribute:u}}function $ f(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)}function d(e,i,s,c){if(s===0)return;let u=t.get( ` WEBGL _multi _draw ` );if(u===null)for(let t=0;t<e.length;t++)l(e[t]/o,i[t],c[t]);else{u.multiDrawElementsInstancedWEBGL(r,i,0,a,e,0,c,0,s);let t=0;for(let e=0;e<s;e++)t+=i[e]*c[e];n.update(t,r,1)}}this.setMode=i,this.setIndex=s,this.render=c,this.renderInstances=l,this.renderMultiDraw=u,this.renderMultiDrawInstances=d}function ep(e){let t={geometries:0,textures:0},n={frame:0,calls:0,triangles:0,points:0,lines:0};function r(t,r,i){switch(n.calls++,r){case e.TRIANGLES:n.triangles+=t/3*i;break;case e.LINES:n.lines+=t/2*i;break;case e.LINE_STRIP:n.lines+=i*(t-1);break;case e.LINE_LOOP:n.lines+=i*t;break;case e.POINTS:n.points+=i*t;break;default:B( ` WebGLInfo : Unknown draw mode : ` ,r);break}}function i(){n.calls=0,n.triangles=0,n.points=0,n.lines=0}return{memory:t,render:n,programs:null,autoReset:!0,reset:i,update:r}}function tp(e,t,n){let r=new WeakMap,i=new kn;function a(a,o,s){let c=a.morphTargetInfluences,l=o.morphAttributes.position||o.morphAttributes.normal||o.morphAttributes.color,u=l===void 0?0:l.length,d=r.get(o);if(d===void 0||d.count!==u){d!==void 0&&d.texture.dispose();let e=o.morphAttributes.position!==void 0,n=o.morphAttributes.normal!==void 0,a=o.morphA
precision highp float ;
uniform mat4 modelViewMatrix ;
uniform mat4 projectionMatrix ;
attribute vec3 position ;
attribute vec2 uv ;
varying vec2 vUv ;
void main ( ) {
vUv = uv ;
gl _Position = projectionMatrix * modelViewMatrix * vec4 ( position , 1.0 ) ;
} ` ,fragmentShader: `
precision highp float ;
uniform sampler2D tDiffuse ;
varying vec2 vUv ;
# include < tonemapping _pars _fragment >
# include < colorspace _pars _fragment >
void main ( ) {
gl _FragColor = texture2D ( tDiffuse , vUv ) ;
# ifdef LINEAR _TONE _MAPPING
gl _FragColor . rgb = LinearToneMapping ( gl _FragColor . rgb ) ;
# elif defined ( REINHARD _TONE _MAPPING )
gl _FragColor . rgb = ReinhardToneMapping ( gl _FragColor . rgb ) ;
# elif defined ( CINEON _TONE _MAPPING )
gl _FragColor . rgb = CineonToneMapping ( gl _FragColor . rgb ) ;
# elif defined ( ACES _FILMIC _TONE _MAPPING )
gl _FragColor . rgb = ACESFilmicToneMapping ( gl _FragColor . rgb ) ;
# elif defined ( AGX _TONE _MAPPING )
gl _FragColor . rgb = AgXToneMapping ( gl _FragColor . rgb ) ;
# elif defined ( NEUTRAL _TONE _MAPPING )
gl _FragColor . rgb = NeutralToneMapping ( gl _FragColor . rgb ) ;
# elif defined ( CUSTOM _TONE _MAPPING )
gl _FragColor . rgb = CustomToneMapping ( gl _FragColor . rgb ) ;
# endif
# ifdef SRGB _TRANSFER
gl _FragColor = sRGBTransferOETF ( gl _FragColor ) ;
# endif
} ` ,depthTest:!1,depthWrite:!1}),l=new Ri(s,c),u=new iu(-1,1,1,-1,0,1),d=null,f=null,p=!1,m,h=null,g=[],_=!1;this.setSize=function(e,t){a.setSize(e,t),o.setSize(e,t);for(let n=0;n<g.length;n++){let r=g[n];r.setSize&&r.setSize(e,t)}},this.setEffects=function(e){g=e,_=g.length>0&&g[0].isRenderPass===!0;let t=a.width,n=a.height;for(let e=0;e<g.length;e++){let r=g[e];r.setSize&&r.setSize(t,n)}},this.begin=function(e,t){if(p||e.toneMapping===0&&g.length===0)return!1;if(h=t,t!==null){let e=t.width,n=t.height;(a.width!==e||a.height!==n)&&this.setSize(e,n)}return _===!1&&e.setRenderTarget(a),m=e.toneMapping,e.toneMapping=0,!0},this.hasRenderPass=function(){return _},this.end=function(e,t){e.toneMapping=m,p=!0;let n=a,r=o;for(let i=0;i<g.length;i++){let a=g[i];if(a.enabled!==!1&&(a.render(e,r,n,t),a.needsSwap!==!1)){let e=n;n=r,r=e}}if(d!==e.outputColorSpace||f!==e.toneMapping){d=e.outputColorSpace,f=e.toneMapping,c.defines={},K.getTransfer(d)=== ` srgb ` &&(c.defines.SRGB_TRANSFER= ` ` );let t=rp[f];t&&(c.defines[t]= ` ` ),c.needsUpdate=!0}c.uniforms.tDiffuse.value=n.texture,e.setRenderTarget(h),e.render(l,u),h=null,p=!1},this.isCompositing=function(){return p},this.dispose=function(){a.dispose(),o.dispose(),s.dispose(),c.dispose()}}var ap=new On,op=new ls(1,1),sp=new Mn,cp=new Pn,lp=new ia,up=[],dp=[],fp=new Float32Array(16),pp=new Float32Array(9),mp=new Float32Array(4);function hp(e,t,n){let r=e[0];if(r<=0||r>0)return e;let i=t*n,a=up[i];if(a===void 0&&(a=new Float32Array(i),up[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 gp(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 _p(e,t){for(let n=0,r=t.length;n<r;n++)e[n]=t[n]}function vp(e,t){let n=dp[t];n===void 0&&(n=new Int32Array(t),dp[t]=n);for(let r=0;r!==t;++r)n[r]=e.allocateTextureUnit();return n}function yp(e,t){let n=this.cache;n[0]!==t&&(e.uniform1f(this.addr,t),n[0]=t)}function bp(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(gp(n,t))return;e.uniform2fv(this.addr,t),_p(n,t)}}function xp(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(gp(n,t))return;e.uniform3fv(this.addr,t),_p(n,t)}}function Sp(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(gp(n,t))return;e.uniform4fv(this.addr,t),_p(n,t)}}function Cp(e,t){let n=this.cache,r=t.elements;if(r===void 0){if(gp(n,t))return;e.uniformMatrix2fv(this.addr,!1,t),_p(n,t)}else{if(gp(n,r))return;mp.set(r),e.uniformMatrix2fv(this.addr,!1,mp),_p(n,r)}}function wp(e,t){let n=this.cache,r=t.elements;if(r===void 0){if(gp(n,t))return;e.uniformMatrix3fv(this.addr,!1,t),_p(n,t)}else{if(gp(n,r))return;pp.set(r),e.uniformMatrix3fv(this.addr,!1,pp),_p(n,r)}}function Tp(e,t){let n=this.cache,r=t.elements;if(r===void 0){if(gp(n,t))return;e.uniformMatrix4fv(this.addr,!1,t),_p(n,t)}else{if(gp(n,r))return;fp.set(r),e.uniformMatrix4fv(this.addr,!1,fp),_p(n,r)}}function Ep(e,t){let n=this.cache;n[0]!==t&&(e.uniform1i(this.addr,t),n[0]=t)}function Dp(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(gp(n,t))return;e.uniform2iv(this.addr,t),_p(n,t)}}function Op(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(gp(n,t))return;e.uniform3iv(this.addr,t),_p(n,t)}}function kp(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(gp(n,t))return;e.uniform4iv(this.addr,t),_p(n,t)}}function Ap(e,t){let n=this.cache;n[0]!==t&&(e.uniform1ui(this.addr,t),n[0]=
` ),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( `
` )}var gm=new G;function _m(e){K._getMatrix(gm,K.workingColorSpace,e);let t= ` mat3 ( $ { gm . elements . map ( e => e . toFixed ( 4 ) ) } ) ` ;switch(K.getTransfer(e)){case nt:return[t, ` LinearTransferOETF ` ];case rt:return[t, ` sRGBTransferOETF ` ];default:return z( ` WebGLProgram : Unsupported color space : ` ,e),[t, ` LinearTransferOETF ` ]}}function vm(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()+ `
` +i+ `
` +hm(e.getShaderSource(t),r)}else return i}function ym(e,t){let n=_m(t);return[ ` vec4 $ { e } ( vec4 value ) { ` , ` return $ { n [ 1 ] } ( vec4 ( value . rgb * $ { n [ 0 ] } , value . a ) ) ; ` , ` } ` ].join( `
` )}var bm={1: ` Linear ` ,2: ` Reinhard ` ,3: ` Cineon ` ,4: ` ACESFilmic ` ,6: ` AgX ` ,7: ` Neutral ` ,5: ` Custom ` };function xm(e,t){let n=bm[t];return n===void 0?(z( ` WebGLProgram : Unsupported toneMapping : ` ,t), ` vec3 ` +e+ ` ( vec3 color ) { return LinearToneMapping ( color ) ; } ` ): ` vec3 ` +e+ ` ( vec3 color ) { return ` +n+ ` ToneMapping ( color ) ; } ` }var Sm=new W;function Cm(){return K.getLuminanceCoefficients(Sm),[ ` float luminance ( const in vec3 rgb ) { ` , ` const vec3 weights = vec3 ( $ { Sm . x . toFixed ( 4 ) } , $ { Sm . y . toFixed ( 4 ) } , $ { Sm . z . toFixed ( 4 ) } ) ; ` , ` return dot ( weights , rgb ) ; ` , ` } ` ].join( `
` )}function wm(e){return[e.extensionClipCullDistance? ` # extension GL _ANGLE _clip _cull _distance : require ` : ` ` ,e.extensionMultiDraw? ` # extension GL _ANGLE _multi _draw : require ` : ` ` ].filter(Dm).join( `
` )}function Tm(e){let t=[];for(let n in e){let r=e[n];r!==!1&&t.push( ` # define ` +n+ ` ` +r)}return t.join( `
` )}function Em(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 Dm(e){return e!== ` ` }function Om(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 km(e,t){return e.replace(/NUM_CLIPPING_PLANES/g,t.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g,t.numClippingPlanes-t.numClipIntersection)}var Am=/^[ \t ]*#include +<([ \w \d ./]+)>/gm;function jm(e){return e.replace(Am,Nm)}var Mm=new Map;function Nm(e,t){let n=Q[t];if(n===void 0){let e=Mm.get(t);if(e!==void 0)n=Q[e],z( ` WebGLRenderer : Shader chunk "%s" has been deprecated . Use "%s" instead . ` ,t,e);else throw Error( ` Can not resolve # include < ` +t+ ` > ` )}return jm(n)}var Pm=/#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 Fm(e){return e.replace(Pm,Im)}function Im(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 Lm(e){let t= ` precision $ { e . precision } float ;
precision $ { e . precision } int ;
precision $ { e . precision } sampler2D ;
precision $ { e . precision } samplerCube ;
precision $ { e . precision } sampler3D ;
precision $ { e . precision } sampler2DArray ;
precision $ { e . precision } sampler2DShadow ;
precision $ { e . precision } samplerCubeShadow ;
precision $ { e . precision } sampler2DArrayShadow ;
precision $ { e . precision } isampler2D ;
precision $ { e . precision } isampler3D ;
precision $ { e . precision } isamplerCube ;
precision $ { e . precision } isampler2DArray ;
precision $ { e . precision } usampler2D ;
precision $ { e . precision } usampler3D ;
precision $ { e . precision } usamplerCube ;
precision $ { e . precision } usampler2DArray ;
` ;return e.precision=== ` highp ` ?t+= `
# define HIGH _PRECISION ` :e.precision=== ` mediump ` ?t+= `
# define MEDIUM _PRECISION ` :e.precision=== ` lowp ` &&(t+= `
# define LOW _PRECISION ` ),t}var Rm={1: ` SHADOWMAP _TYPE _PCF ` ,3: ` SHADOWMAP _TYPE _VSM ` };function zm(e){return Rm[e.shadowMapType]|| ` SHADOWMAP _TYPE _BASIC ` }var Bm={301: ` ENVMAP _TYPE _CUBE ` ,302: ` ENVMAP _TYPE _CUBE ` ,306: ` ENVMAP _TYPE _CUBE _UV ` };function Vm(e){return e.envMap===!1? ` ENVMAP _TYPE _CUBE ` :Bm[e.envMapMode]|| ` ENVMAP _TYPE _CUBE ` }var Hm={302: ` ENVMAP _MODE _REFRACTION ` };function Um(e){return e.envMap===!1? ` ENVMAP _MODE _REFLECTION ` :Hm[e.envMapMode]|| ` ENVMAP _MODE _REFLECTION ` }var Wm={0: ` ENVMAP _BLENDING _MULTIPLY ` ,1: ` ENVMAP _BLENDING _MIX ` ,2: ` ENVMAP _BLENDING _ADD ` };function Gm(e){return e.envMap===!1? ` ENVMAP _BLENDING _NONE ` :Wm[e.combine]|| ` ENVMAP _BLENDING _NONE ` }function Km(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 qm(e,t,n,r){let i=e.getContext(),a=n.defines,o=n.vertexShader,s=n.fragmentShader,c=zm(n),l=Vm(n),u=Um(n),d=Gm(n),f=Km(n),p=wm(n),m=Tm(a),h=i.createProgram(),g,_,v=n.glslVersion? ` # version ` +n.glslVersion+ `
` : ` ` ;n.isRawShaderMaterial?(g=[ ` # define SHADER _TYPE ` +n.shaderType, ` # define SHADER _NAME ` +n.shaderName,m].filter(Dm).join( `
` ),g.length>0&&(g+= `
` ),_=[ ` # define SHADER _TYPE ` +n.shaderType, ` # define SHADER _NAME ` +n.shaderName,m].filter(Dm).join( `
` ),_.length>0&&(_+= `
` )):(g=[Lm(n), ` # define SHADER _TYPE ` +n.shaderType, ` # define SHADER _NAME ` +n.shaderName,m,n.extensionClipCullDistance? ` # define USE _CLIP _DISTANCE ` : ` ` ,n.batching? ` # define USE _BATCHING ` : ` ` ,n.batchingColor? ` # define USE _BATCHING _COLOR ` : ` ` ,n.instancing? ` # define USE _INSTANCING ` : ` ` ,n.instancingColor? ` # define USE _INSTANCING _COLOR ` : ` ` ,n.instancingMorph? ` # define USE _INSTANCING _MORPH ` : ` ` ,n.useFog&&n.fog? ` # define USE _FOG ` : ` ` ,n.useFog&&n.fogExp2? ` # define FOG _EXP2 ` : ` ` ,n.map? ` # define USE _MAP ` : ` ` ,n.envMap? ` # define USE _ENVMAP ` : ` ` ,n.envMap? ` # define ` +u: ` ` ,n.lightMap? ` # define USE _LIGHTMAP ` : ` ` ,n.aoMap? ` # define USE _AOMAP ` : ` ` ,n.bumpMap? ` # define USE _BUMPMAP ` : ` ` ,n.normalMap? ` # define USE _NORMALMAP ` : ` ` ,n.normalMapObjectSpace? ` # define USE _NORMALMAP _OBJECTSPACE ` : ` ` ,n.normalMapTangentSpace? ` # define USE _NORMALMAP _TANGENTSPACE ` : ` ` ,n.displacementMap? ` # define USE _DISPLACEMENTMAP ` : ` ` ,n.emissiveMap? ` # define USE _EMISSIVEMAP ` : ` ` ,n.anisotropy? ` # define USE _ANISOTROPY ` : ` ` ,n.anisotropyMap? ` # define USE _ANISOTROPYMAP ` : ` ` ,n.clearcoatMap? ` # define USE _CLEARCOATMAP ` : ` ` ,n.clearcoatRoughnessMap? ` # define USE _CLEARCOAT _ROUGHNESSMAP ` : ` ` ,n.clearcoatNormalMap? ` # define USE _CLEARCOAT _NORMALMAP ` : ` ` ,n.iridescenceMap? ` # define USE _IRIDESCENCEMAP ` : ` ` ,n.iridescenceThicknessMap? ` # define USE _IRIDESCENCE _THICKNESSMAP ` : ` ` ,n.specularMap? ` # define USE _SPECULARMAP ` : ` ` ,n.specularColorMap? ` # define USE _SPECULAR _COLORMAP ` : ` ` ,n.specularIntensityMap? ` # define USE _SPECULAR _INTENSITYMAP ` : ` ` ,n.roughnessMap? ` # define USE _ROUGHNESSMAP ` : ` ` ,n.metalnessMap? ` # define USE _METALNESSMAP ` : ` ` ,n.alphaMap? ` # define USE _ALPHAMAP ` : ` ` ,n.alphaHash? ` # define USE _ALPHAHASH ` : ` ` ,n.transmission? ` # define USE _TRANSMISSION ` : ` ` ,n.transmissionMap? ` # define USE _TRANSMISSIONMAP ` : ` ` ,n.thicknessMap? ` # define USE _THICKNESSMAP ` : ` ` ,n.sheenColorMap? ` # define USE _SHEEN _COLORMAP ` : ` ` ,n.sheenRoughnessMap? ` # define USE _SHEEN _ROUGHNESSMAP ` : ` ` ,n.mapUv? ` # define MAP _UV ` +n.mapUv: ` ` ,n.alphaMapUv? ` # define ALPHAMAP _UV ` +n.alphaMapUv: ` ` ,n.lightMapUv? ` # define LIGHTMAP _UV ` +n.lightMapUv: ` ` ,n.aoMapUv? ` # define AOMAP _UV ` +n.aoMapUv: ` ` ,n.emissiveMapUv? ` # define EMISSIVEMAP _UV ` +n.emissiveMapUv: ` ` ,n.bumpMapUv? ` # define BUMPMAP _UV ` +n.bumpMapUv: ` ` ,n.normalMapUv? ` # define NORMALMAP _UV ` +n.normalMapUv: ` ` ,n.displacementMapUv? ` # define DISPLACEMENTMAP _UV ` +n.displacementMapUv: ` ` ,n.metalnessMapUv? ` # define METALNESSMAP _UV ` +n.metalnessMapUv: ` ` ,n.roughnessMapUv? ` # define ROUGHNESSMAP _UV ` +n.roughnessMapUv: ` ` ,n.anisotropyMapUv? ` # define ANISOTROPYMAP _UV ` +n.anisotropyMapUv: ` ` ,n.clearcoatMapUv? ` # define CLEARCOATMAP _UV ` +n.clearcoatMapUv: ` ` ,n.clearcoatNormalMapUv? ` # define CLEARCOAT _NORMALMAP _UV ` +n.clearcoatNormalMapUv: ` ` ,n.clearcoatRoughnessMapUv? ` # define CLEARCOAT _ROUGHNESSMAP _UV ` +n.clearcoatRoughnessMapUv: ` ` ,n.iridescenceMapUv? ` # define IRIDESCENCEMAP _UV ` +n.iridescenceMapUv: ` ` ,n.iridescenceThicknessMapUv? ` # define IRIDESCENCE _THICKNESSMAP _UV ` +n.iridescenceThicknessMapUv: ` ` ,n.sheenColorMapUv? ` # define SHEEN _COLORMAP _UV ` +n.sheenColorMapUv: ` ` ,n.sheenRoughnessMapUv? ` # define SHEEN _ROUGHNESSMAP _UV ` +n.sheenRoughnessMapUv: ` ` ,n.specularMapUv? ` # define SPECULARMAP _UV ` +n.specularMapUv: ` ` ,n.specularColorMapUv? ` # define SPECULAR _COLORMAP _UV ` +n.specularColorMapUv: ` ` ,n.specularIntensityMapUv? ` # define SPECULAR _INTENSITYMAP _UV ` +n.specularIntensityMapUv: ` ` ,n.transmissionMapUv? ` # define TRANSMISSIONMAP _UV ` +n.transmissionMapUv: ` ` ,n.thicknessMapUv? ` # define THICKNESSMAP _UV ` +n.thicknessMapUv: ` ` ,n.vertexTangents&&n.flatShading===!1? ` # define USE _TANGENT ` : ` ` ,n.vertexColors? ` # define USE _COLOR ` : ` ` ,n.vertexAlphas? ` # define USE _COLOR _ALPHA ` : ` ` ,n.vertexUv1s? ` # define USE _UV1 ` : ` ` ,n.vertexUv2s? ` # define USE _UV2 ` : ` ` ,n.vertexUv3s? ` # define USE _UV3 ` : ` ` ,n.pointsUvs? ` # define USE _POINTS _UV ` : ` ` ,n.flatShading? ` # define FLAT _SHADED ` : ` ` ,n.skinning? ` # define USE _SKINNING ` : ` ` ,n.morphTargets? ` # define USE _MORPHTARGETS ` : ` ` ,n.morphNormals&&n.flatShading===!1? ` # define USE _MORPHNORMALS ` : ` ` ,n.morphColors? ` # define USE _MORPHCOLORS ` : ` ` ,n.morphTargetsCount>0? ` # define MORPHTARGETS _TEXTURE _STRIDE ` +n.morphTextureStride: ` ` ,n.morphTargetsCount>0? ` # define MORPHTARGETS _COUNT ` +n.morphTargetsCount: ` ` ,n.doubleSided? ` # define DOUBLE _SIDED ` : ` ` ,
` ].filter(Dm).join( `
` ),_=[Lm(n), ` # define SHADER _TYPE ` +n.shaderType, ` # define SHADER _NAME ` +n.shaderName,m,n.useFog&&n.fog? ` # define USE _FOG ` : ` ` ,n.useFog&&n.fogExp2? ` # define FOG _EXP2 ` : ` ` ,n.alphaToCoverage? ` # define ALPHA _TO _COVERAGE ` : ` ` ,n.map? ` # define USE _MAP ` : ` ` ,n.matcap? ` # define USE _MATCAP ` : ` ` ,n.envMap? ` # define USE _ENVMAP ` : ` ` ,n.envMap? ` # define ` +l: ` ` ,n.envMap? ` # define ` +u: ` ` ,n.envMap? ` # define ` +d: ` ` ,f? ` # define CUBEUV _TEXEL _WIDTH ` +f.texelWidth: ` ` ,f? ` # define CUBEUV _TEXEL _HEIGHT ` +f.texelHeight: ` ` ,f? ` # define CUBEUV _MAX _MIP ` +f.maxMip+ ` . 0 ` : ` ` ,n.lightMap? ` # define USE _LIGHTMAP ` : ` ` ,n.aoMap? ` # define USE _AOMAP ` : ` ` ,n.bumpMap? ` # define USE _BUMPMAP ` : ` ` ,n.normalMap? ` # define USE _NORMALMAP ` : ` ` ,n.normalMapObjectSpace? ` # define USE _NORMALMAP _OBJECTSPACE ` : ` ` ,n.normalMapTangentSpace? ` # define USE _NORMALMAP _TANGENTSPACE ` : ` ` ,n.emissiveMap? ` # define USE _EMISSIVEMAP ` : ` ` ,n.anisotropy? ` # define USE _ANISOTROPY ` : ` ` ,n.anisotropyMap? ` # define USE _ANISOTROPYMAP ` : ` ` ,n.clearcoat? ` # define USE _CLEARCOAT ` : ` ` ,n.clearcoatMap? ` # define USE _CLEARCOATMAP ` : ` ` ,n.clearcoatRoughnessMap? ` # define USE _CLEARCOAT _ROUGHNESSMAP ` : ` ` ,n.clearcoatNormalMap? ` # define USE _CLEARCOAT _NORMALMAP ` : ` ` ,n.dispersion? ` # define USE _DISPERSION ` : ` ` ,n.iridescence? ` # define USE _IRIDESCENCE ` : ` ` ,n.iridescenceMap? ` # define USE _IRIDESCENCEMAP ` : ` ` ,n.iridescenceThicknessMap? ` # define USE _IRIDESCENCE _THICKNESSMAP ` : ` ` ,n.specularMap? ` # define USE _SPECULARMAP ` : ` ` ,n.specularColorMap? ` # define USE _SPECULAR _COLORMAP ` : ` ` ,n.specularIntensityMap? ` # define USE _SPECULAR _INTENSITYMAP ` : ` ` ,n.roughnessMap? ` # define USE _ROUGHNESSMAP ` : ` ` ,n.metalnessMap? ` # define USE _METALNESSMAP ` : ` ` ,n.alphaMap? ` # define USE _ALPHAMAP ` : ` ` ,n.alphaTest? ` # define USE _ALPHATEST ` : ` ` ,n.alphaHash? ` # define USE _ALPHAHASH ` : ` ` ,n.sheen? ` # define USE _SHEEN ` : ` ` ,n.sheenColorMap? ` # define USE _SHEEN _COLORMAP ` : ` ` ,n.sheenRoughnessMap? ` # define USE _SHEEN _ROUGHNESSMAP ` : ` ` ,n.transmission? ` # define USE _TRANSMISSION ` : ` ` ,n.transmissionMap? ` # define USE _TRANSMISSIONMAP ` : ` ` ,n.thicknessMap? ` # define USE _THICKNESSMAP ` : ` ` ,n.vertexTangents&&n.flatShading===!1? ` # define USE _TANGENT ` : ` ` ,n.vertexColors||n.instancingColor||n.batchingColor? ` # define USE _COLOR ` : ` ` ,n.vertexAlphas? ` # define USE _COLOR _ALPHA ` : ` ` ,n.vertexUv1s? ` # define USE _UV1 ` : ` ` ,n.vertexUv2s? ` # define USE _UV2 ` : ` ` ,n.vertexUv3s? ` # define USE _UV3 ` : ` ` ,n.pointsUvs? ` # define USE _POINTS _UV ` : ` ` ,n.gradientMap? ` # define USE _GRADIENTMAP ` : ` ` ,n.flatShading? ` # define FLAT _SHADED ` : ` ` ,n.doubleSided? ` # define DOUBLE _SIDED ` : ` ` ,n.flipSided? ` # define FLIP _SIDED ` : ` ` ,n.shadowMapEnabled? ` # define USE _SHADOWMAP ` : ` ` ,n.shadowMapEnabled? ` # define ` +c: ` ` ,n.premultipliedAlpha? ` # define PREMULTIPLIED _ALPHA ` : ` ` ,n.numLightProbes>0? ` # define USE _LIGHT _PROBES ` : ` ` ,n.decodeVideoTexture? ` # define DECODE _VIDEO _TEXTURE ` : ` ` ,n.decodeVideoTextureEmissive? ` # define DECODE _VIDEO _TEXTURE _EMISSIVE ` : ` ` ,n.logarithmicDepthBuffer? ` # define USE _LOGARITHMIC _DEPTH _BUFFER ` : ` ` ,n.reversedDepthBuffer? ` # define USE _REVERSED _DEPTH _BUFFER ` : ` ` , ` uniform mat4 viewMatrix ; ` , ` uniform vec3 cameraPosition ; ` , ` uniform bool isOrthographic ; ` ,n.toneMapping===0? ` ` : ` # define TONE _MAPPING ` ,n.toneMapping===0? ` ` :Q.tonemapping_pars_fragment,n.toneMapping===0? ` ` :xm( ` toneMapping ` ,n.toneMapping),n.dithering? ` # define DITHERING ` : ` ` ,n.opaque? ` # define OPAQUE ` : ` ` ,Q.colorspace_pars_fragment,ym( ` linearToOutputTexel ` ,n.outputColorSpace),Cm(),n.useDepthPacking? ` # define DEPTH _PACKING ` +n.depthPacking: ` ` , `
` ].filter(Dm).join( `
` )),o=jm(o),o=Om(o,n),o=km(o,n),s=jm(s),s=Om(s,n),s=km(s,n),o=Fm(o),s=Fm(s),n.isRawShaderMaterial!==!0&&(v= ` # version 300 es
` ,g=[p, ` # define attribute in ` , ` # define varying out ` , ` # define texture2D texture ` ].join( `
` )+ `
` +g,_=[ ` # define varying in ` ,n.glslVersion=== ` 300 es ` ? ` ` : ` layout ( location = 0 ) out highp vec4 pc _fragColor ; ` ,n.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( `
` )+ `
` +_);let y=v+g+o,b=v+_+s,x=fm(i,i.VERTEX_SHADER,y),S=fm(i,i.FRAGMENT_SHADER,b);i.attachShader(h,x),i.attachShader(h,S),n.index0AttributeName===void 0?n.morphTargets===!0&&i.bindAttribLocation(h,0, ` position ` ):i.bindAttribLocation(h,0,n.index0AttributeName),i.linkProgram(h);function C(t){if(e.debug.checkShaderErrors){let n=i.getProgramInfoLog(h)|| ` ` ,r=i.getShaderInfoLog(x)|| ` ` ,a=i.getShaderInfoLog(S)|| ` ` ,o=n.trim(),s=r.trim(),c=a.trim(),l=!0,u=!0;if(i.getProgramParameter(h,i.LINK_STATUS)===!1)if(l=!1,typeof e.debug.onShaderError== ` function ` )e.debug.onShaderError(i,h,x,S);else{let e=vm(i,x, ` vertex ` ),n=vm(i,S, ` fragment ` );B( ` THREE . WebGLProgram : Shader Error ` +i.getError()+ ` - VALIDATE _STATUS ` +i.getProgramParameter(h,i.VALIDATE_STATUS)+ `
Material Name : ` +t.name+ `
Material Type : ` +t.type+ `
Program Info Log : ` +o+ `
` +e+ `
` +n)}else o=== ` ` ?(s=== ` ` ||c=== ` ` )&&(u=!1):z( ` WebGLProgram : Program Info Log : ` ,o);u&&(t.diagnostics={runnable:l,programLog:o,vertexShader:{log:s,prefix:g},fragmentShader:{log:c,prefix:_}})}i.deleteShader(x),i.deleteShader(S),w=new dm(i,h),T=Em(i,h)}let w;this.getUniforms=function(){return w===void 0&&C(this),w};let T;this.getAttributes=function(){return T===void 0&&C(this),T};let E=n.rendererExtensionParallelShaderCompile===!1;return this.isReady=function(){return E===!1&&(E=i.getProgramParameter(h,pm)),E},this.destroy=function(){r.releaseStatesOfProgram(this),i.deleteProgram(h),this.program=void 0},this.type=n.shaderType,this.name=n.shaderName,this.id=mm++,this.cacheKey=t,this.usedTimes=1,this.program=h,this.vertexShader=x,this.fragmentShader=S,this}var Jm=0,Ym=class{constructor(){this.shaderCache=new Map,this.materialCache=new Map}update(e){let t=e.vertexShader,n=e.fragmentShader,r=this._getShaderStage(t),i=this._getShaderStage(n),a=this._getShaderCacheForMaterial(e);return a.has(r)===!1&&(a.add(r),r.usedTimes++),a.has(i)===!1&&(a.add(i),i.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}getVertexShaderID(e){return this._getShaderStage(e.vertexShader).id}getFragmentShaderID(e){return this._getShaderStage(e.fragmentShader).id}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 Xm(e),t.set(e,n)),n}},Xm=class{constructor(e){this.id=Jm++,this.code=e,this.usedTimes=0}};function Zm(e,t,n,r,i,a,o){let s=new yr,c=new Ym,l=new Set,u=[],d=new Map,f=i.logarithmicDepthBuffer,p=i.precision,m={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 h(e){return l.add(e),e===0? ` uv ` : ` uv$ { e } ` }function g(a,s,u,d,g){let _=d.fog,v=g.geometry,y=a.isMeshStandardMaterial?d.environment:null,b=(a.isMeshStandardMaterial?n:t).get(a.envMap||y),x=b&&b.mapping===306?b.image.height:null,S=m[a.type];a.precision!==null&&(p=i.getMaxPrecision(a.precision),p!==a.precision&&z( ` WebGLProgram . getParameters : ` ,a.precision, ` not supported , using ` ,p, ` instead . ` ));let C=v.morphAttributes.position||v.morphAttributes.normal||v.morphAttributes.color,w=C===void 0?0:C.length,T=0;v.morphAttributes.position!==void 0&&(T=1),v.morphAttributes.normal!==void 0&&(T=2),v.morphAttributes.color!==void 0&&(T=3);let E,D,ee,O;if(S){let e=bf[S];E=e.vertexShader,D=e.fragmentShader}else E=a.vertexShader,D=a.fragmentShader,c.update(a),ee=c.getVertexShaderID(a),O=c.getFragmentShaderID(a);let k=e.getRenderTarget(),A=e.state.buffers.depth.getReversed(),j=g.isInstancedMesh===!0,M=g.isBatchedMesh===!0,te=!!a.map,ne=!!a.matcap,N=!!b,re=!!a.aoMap,ie=!!a.lightMap,ae=!!a.bumpMap,oe=!!a.normalMap,se=!!a.displacementMap,ce=!!a.emissiveMap,le=!!a.metalnessMap,P=!!a.roughnessMap,ue=a.anisotropy>0,de=a.clearcoat>0,fe=a.dispersion>0,pe=a.iridescence>0,me=a.sheen>0,he=a.transmission>0,ge=ue&&!!a.anisotropyMap,_e=de&&!!a.clearcoatMap,ve=de&&!!a.clearcoatNormalMap,ye=de&&!!a.clearcoatRoughnessMap,be=pe&&!!a.iridescenceMap,xe=pe&&!!a.iridescenceThicknessMap,Se=me&&!!a.sheenColorMap,Ce=me&&!!a.sheenRoughnessMap,we=!!a.specularMap,Te=!!a.specularColorMap,Ee=!!a.specularIntensityMap,De=he&&!!a.transmissionMap,Oe=he&&!!a.thicknessMap,F=!!a.gradientMap,ke=!!a.alphaMap,Ae=a.alphaTest>0,je=!!a.alphaHash,I=!!a.extensions,Me=0;a.toneMapped&&(k===null||k.isXRRenderTarget===!0)&&(Me=e.toneMapping);let L={shaderID:S,shaderType:a.type,shaderName:a.name,vertexShader:E,fragmentShader:D,defines:a.defines,customVertexShaderID:ee,customFragment
gl _Position = vec4 ( position , 1.0 ) ;
} ` ,dh= ` uniform sampler2D shadow _pass ;
uniform vec2 resolution ;
uniform float radius ;
void main ( ) {
const float samples = float ( VSM _SAMPLES ) ;
float mean = 0.0 ;
float squared _mean = 0.0 ;
float uvStride = samples <= 1.0 ? 0.0 : 2.0 / ( samples - 1.0 ) ;
float uvStart = samples <= 1.0 ? 0.0 : - 1.0 ;
for ( float i = 0.0 ; i < samples ; i ++ ) {
float uvOffset = uvStart + i * uvStride ;
# ifdef HORIZONTAL _PASS
vec2 distribution = texture2D ( shadow _pass , ( gl _FragCoord . xy + vec2 ( uvOffset , 0.0 ) * radius ) / resolution ) . rg ;
mean += distribution . x ;
squared _mean += distribution . y * distribution . y + distribution . x * distribution . x ;
# else
float depth = texture2D ( shadow _pass , ( gl _FragCoord . xy + vec2 ( 0.0 , uvOffset ) * radius ) / resolution ) . r ;
mean += depth ;
squared _mean += depth * depth ;
# endif
}
mean = mean / samples ;
squared _mean = squared _mean / samples ;
float std _dev = sqrt ( max ( 0.0 , squared _mean - mean * mean ) ) ;
gl _FragColor = vec4 ( mean , std _dev , 0.0 , 1.0 ) ;
} ` ,fh=[new W(1,0,0),new W(-1,0,0),new W(0,1,0),new W(0,-1,0),new W(0,0,1),new W(0,0,-1)],ph=[new W(0,-1,0),new W(0,-1,0),new W(0,0,1),new W(0,0,-1),new W(0,-1,0),new W(0,-1,0)],mh=new q,hh=new W,gh=new W;function _h(e,t,n){let r=new fo,i=new U,a=new U,o=new kn,s=new cl,l=new ll,u={},d=n.maxTextureSize,f={0:1,1:0,2:2},m=new Yi({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new U},radius:{value:4}},vertexShader:uh,fragmentShader:dh}),h=m.clone();h.defines.HORIZONTAL_PASS=1;let g=new Z;g.setAttribute( ` position ` ,new di(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));let _=new Ri(g,m),v=this;this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=1;let y=this.type;this.render=function(t,n,s){if(v.enabled===!1||v.autoUpdate===!1&&v.needsUpdate===!1||t.length===0)return;t.type===2&&(z( ` WebGLShadowMap : PCFSoftShadowMap has been deprecated . Using PCFShadowMap instead . ` ),t.type=1);let l=e.getRenderTarget(),u=e.getActiveCubeFace(),f=e.getActiveMipmapLevel(),m=e.state;m.setBlending(0),m.buffers.depth.getReversed()===!0?m.buffers.color.setClear(0,0,0,0):m.buffers.color.setClear(1,1,1,1),m.buffers.depth.setTest(!0),m.setScissorTest(!1);let h=y!==this.type;h&&n.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=t.length;l<u;l++){let u=t[l],f=u.shadow;if(f===void 0){z( ` WebGLShadowMap : ` ,u, ` has no shadow . ` );continue}if(f.autoUpdate===!1&&f.needsUpdate===!1)continue;i.copy(f.mapSize);let g=f.getFrameExtents();if(i.multiply(g),a.copy(f.mapSize),(i.x>d||i.y>d)&&(i.x>d&&(a.x=Math.floor(d/g.x),i.x=a.x*g.x,f.mapSize.x=a.x),i.y>d&&(a.y=Math.floor(d/g.y),i.y=a.y*g.y,f.mapSize.y=a.y)),f.map===null||h===!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){z( ` WebGLShadowMap : VSM shadow maps are not supported for PointLights . Use PCF or BasicShadowMap instead . ` );continue}f.map=new jn(i.x,i.y,{format:ie,type:T,minFilter:p,magFilter:p,generateMipmaps:!1}),f.map.texture.name=u.name+ ` . shadowMap ` ,f.map.depthTexture=new ls(i.x,i.y,w),f.map.depthTexture.name=u.name+ ` . shadowMapDepth ` ,f.map.depthTexture.format=te,f.map.depthTexture.compareFunction=null,f.map.depthTexture.minFilter=c,f.map.depthTexture.magFilter=c}else{u.isPointLight?(f.map=new aa(i.x),f.map.depthTexture=new us(i.x,C)):(f.map=new jn(i.x,i.y),f.map.depthTexture=new ls(i.x,i.y,C)),f.map.depthTexture.name=u.name+ ` . shadowMap ` ,f.map.depthTexture.format=te;let t=e.state.buffers.depth.getReversed();this.type===1?(f.map.depthTexture.compareFunction=t?518:515,f.map.depthTexture.minFilter=p,f.map.depthTexture.magFilter=p):(f.map.depthTexture.compareFunction=null,f.map.depthTexture.minFilter=c,f.map.depthTexture.magFilter=c)}f.camera.updateProjectionMatrix()}let _=f.map.isWebGLCubeRenderTarget?6:1;for(let t=0;t<_;t++){if(f.map.isWebGLCubeRenderTarget)e.setRenderTarget(f.map,t),e.clear();else{t===0&&(e.setRenderTarget(f.map),e.clear());let n=f.getViewport(t);o.set(a.x*n.x,a.y*n.y,a.x*n.z,a.y*n.w),m.viewport(o)}if(u.isPointLight){let e=f.camera,n=f.matrix,r=u.distance||e.far;r!==e.far&&(e.far=r,e.updateProjectionMatrix()),hh.setFromMatrixPosition(u.matrixWorld),e.position.copy(hh),gh.copy(e.position),gh.add(fh[t]),e.up.copy(ph[t]),e.lookAt(gh),e.updateMatrixWorld(),n.makeTranslation(-hh.x,-hh.y,-hh.z),mh.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),f._frustum.setFromProjectionMatrix(mh,e.coordinateSystem,e.reversedDepth)}else f.updateMatrices(u);r=f.getFrustum(),S(n,s,f.camera,u,this.type)}f.isPointLightShadow!==!0&&this.type===3&&b(f,s),f.needsUpdate=!1}y=this.type,v.needsUpdate=!1,e.setRenderTarget(l,u,f)};function b(n,r){let a=t.update(_);m.defines.VSM_SAMPLES!==n.blurSamples&&(m.defines.VSM_SAMPLES=n.blurSamples,h.defines.VSM_SAMPLES=n.blurSamples,m.needsUpdate=!0,h.needsUpdate=!0),n.mapPass===null&&(n.mapPass=new jn(i.x,i.y,{format:ie,type:T})),m.uniforms.shadow_pass.value=n.map.depthTexture,m.uniforms.resolution.value=n.mapSize,m.uniforms.radius.value=n.ra
void main ( ) {
gl _Position = vec4 ( position , 1.0 ) ;
} ` ,Ch= `
uniform sampler2DArray depthColor ;
uniform float depthWidth ;
uniform float depthHeight ;
void main ( ) {
vec2 coord = vec2 ( gl _FragCoord . x / depthWidth , gl _FragCoord . y / depthHeight ) ;
if ( coord . x >= 1.0 ) {
gl _FragDepth = texture ( depthColor , vec3 ( coord . x - 1.0 , coord . y , 1 ) ) . r ;
} else {
gl _FragDepth = texture ( depthColor , vec3 ( coord . x , coord . y , 0 ) ) . r ;
}
2026-03-18 06:26:17 -07:00
} ` ,wh=class{constructor(){this.texture=null,this.mesh=null,this.depthNear=0,this.depthFar=0}init(e,t){if(this.texture===null){let n=new ds(e.texture);(e.depthNear!==t.depthNear||e.depthFar!==t.depthFar)&&(this.depthNear=e.depthNear,this.depthFar=e.depthFar),this.texture=n}}getMesh(e){if(this.texture!==null&&this.mesh===null){let t=e.cameras[0].viewport,n=new Yi({vertexShader:Sh,fragmentShader:Ch,uniforms:{depthColor:{value:this.texture},depthWidth:{value:t.z},depthHeight:{value:t.w}}});this.mesh=new Ri(new Hc(20,20),n)}return this.mesh}reset(){this.texture=null,this.mesh=null}getDepthTexture(){return this.texture}},Th=class extends zt{constructor(e,t){super();let n=this,r=null,i=1,a=null,o= ` local - floor ` ,s=1,c=null,l=null,u=null,d=null,f=null,p=null,m=typeof XRWebGLBinding< ` u ` ,h=new wh,g={},_=t.getContextAttributes(),y=null,b=null,x=[],S=[],w=new U,T=null,E=new ea;E.viewport=new kn;let D=new ea;D.viewport=new kn;let O=[E,D],k=new Ou,A=null,j=null;this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function(e){let t=x[e];return t===void 0&&(t=new ca,x[e]=t),t.getTargetRaySpace()},this.getControllerGrip=function(e){let t=x[e];return t===void 0&&(t=new ca,x[e]=t),t.getGripSpace()},this.getHand=function(e){let t=x[e];return t===void 0&&(t=new ca,x[e]=t),t.getHandSpace()};function N(e){let t=S.indexOf(e.inputSource);if(t===-1)return;let n=x[t];n!==void 0&&(n.update(e.inputSource,e.frame,c||a),n.dispatchEvent({type:e.type,data:e.inputSource}))}function re(){r.removeEventListener( ` select ` ,N),r.removeEventListener( ` selectstart ` ,N),r.removeEventListener( ` selectend ` ,N),r.removeEventListener( ` squeeze ` ,N),r.removeEventListener( ` squeezestart ` ,N),r.removeEventListener( ` squeezeend ` ,N),r.removeEventListener( ` end ` ,re),r.removeEventListener( ` inputsourceschange ` ,ie);for(let e=0;e<x.length;e++){let t=S[e];t!==null&&(S[e]=null,x[e].disconnect(t))}A=null,j=null,h.reset();for(let e in g)delete g[e];e.setRenderTarget(y),f=null,d=null,u=null,r=null,b=null,de.stop(),n.isPresenting=!1,e.setPixelRatio(T),e.setSize(w.width,w.height,!1),n.dispatchEvent({type: ` sessionend ` })}this.setFramebufferScaleFactor=function(e){i=e,n.isPresenting===!0&&z( ` WebXRManager : Cannot change framebuffer scale while presenting . ` )},this.setReferenceSpaceType=function(e){o=e,n.isPresenting===!0&&z( ` WebXRManager : Cannot change reference space type while presenting . ` )},this.getReferenceSpace=function(){return c||a},this.setReferenceSpace=function(e){c=e},this.getBaseLayer=function(){return d===null?f:d},this.getBinding=function(){return u===null&&m&&(u=new XRWebGLBinding(r,t)),u},this.getFrame=function(){return p},this.getSession=function(){return r},this.setSession=async function(l){if(r=l,r!==null){if(y=e.getRenderTarget(),r.addEventListener( ` select ` ,N),r.addEventListener( ` selectstart ` ,N),r.addEventListener( ` selectend ` ,N),r.addEventListener( ` squeeze ` ,N),r.addEventListener( ` squeezestart ` ,N),r.addEventListener( ` squeezeend ` ,N),r.addEventListener( ` end ` ,re),r.addEventListener( ` inputsourceschange ` ,ie),_.xrCompatible!==!0&&await t.makeXRCompatible(),T=e.getPixelRatio(),e.getSize(w),m&& ` createProjectionLayer ` in XRWebGLBinding.prototype){let n=null,a=null,o=null;_.depth&&(o=_.stencil?t.DEPTH24_STENCIL8:t.DEPTH_COMPONENT24,n=_.stencil?ne:te,a=_.stencil?ee:C);let s={colorFormat:t.RGBA8,depthFormat:o,scaleFactor:i};u=this.getBinding(),d=u.createProjectionLayer(s),r.updateRenderState({layers:[d]}),e.setPixelRatio(1),e.setSize(d.textureWidth,d.textureHeight,!1),b=new jn(d.textureWidth,d.textureHeight,{format:M,type:v,depthTexture:new ls(d.textureWidth,d.textureHeight,a,void 0,void 0,void 0,void 0,void 0,void 0,n),stencilBuffer:_.stencil,colorSpace:e.outputColorSpace,samples:_.antialias?4:0,resolveDepthBuffer:d.ignoreDepthValues===!1,resolveStencilBuffer:d.ignoreDepthValues===!1})}else{let n={antialias:_.antialias,alpha:!0,depth:_.depth,stencil:_.stencil,framebufferScaleFactor:i};f=new XRWebGLLayer(r,t,n),r.updateRenderState({baseLayer:f}),e.setPixelRatio(1),e.setSize(f.framebufferWidth,f.framebufferHeight,!1),b=new jn(f.framebufferWidth,f.framebufferHeight,{fo