LINE1 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300 310 320 330 340 350 360 370 380 390 400 410 420 430 440 450 460 470 480 490 500 510 520 530 540 550 560 570 580 590 600 610 620 630 640 650 660 670 680 690 700 710 720 730 740 750 760 770 780 790 800 810 820 830 840 850 860 870 880 890 900 910 920 930 940 950 960 970 980 990 1000 1010 1020 1030 1040 1050 1060 1070 1080 1090 1100 1110 1120 1130 1140 1150 1160 1170 1180 1190 1200 1210 1220 1230 1240 1250 1260 1270 1280 1290 1300 1310 1320 1330 1340 1350 1360 1370 1380 1390 1400 1410 1420 1430 1440 1450 1460 1470 1480 1490 1500 1510 1520 1530 1540 1550 1560 1570 1580 1590 1600 1610 1620 1630 1640 1650 1660 1670 1680 1690 1700 1710 1720 1730 1740 1750 1760 1770 1780 1790 1800 1810 1820 1830 1840 1850 1860 1870 1880 1890 1900 1910 1920 1930 1940 1950 1960 1970 1980 1990 2000 2010 2020 2030 2040 2050 2060 2070 2080 2090 2100 2110 2120 2130 2140 2150 2160 2170 2180 2190 2200 2210 2220 2230 2240 2250 2260 2270 2280 2290 2300 2310 2320 2330 2340 2350 2360 2370 2380 2390 2400 2410 2420 2430 2440 2450 2460 2470 2480 2490 2500 2510 2520 2530 2540 2550 2560 2570 2580 2590 2600 2610 2620 2630 2640 2650 2660 2670 2680 2690 2700 2710 2720 2730 2740 2750 2760 2770 2780 2790 2800 2810 2820 2830 2840 2850 2860 2870 2880 2890 2900 2910 2920 2930 2940 2950 2960 2970 2980 2990 3000 3010 3020 3030 3040 3050 3060 3070 3080 3090 3100 3110 3120 3130 3140 3150 3160 3170 3180 3190 3200 3210 3220 3230 3240 3250 3260 3270 3280 3290 3300 3310 3320 3330 3340 3350 3360 3370 3380 3390 3400 3410 3420 3430 3440 3450 3460 3470 3480 3490 3500 3510 3520 3530 3540 3550 3560 3570 3580 3590 3600 3610 3620 3630 3640 3650 3660 3670 3680 3690 3700 3710 3720 3730 3740 3750 3760 3770 3780 3790 3800 3810 3820 3830 3840 3850 3860 3870 3880 3890 3900 3910 3920 3930 3940 3950 3960 3970 3980 3990 4000 4010 4020 4030 4040 4050 4060 4070 4080 4090 4100 4110 4120 4130 4140 4150 4160 4170 4180 4190 4200 4210 4220 4230 4240 4250 4260 4270 4280 4290 4300 4310 4320 4330 4340 4350 4360 4370 4380 4390 4400 4410 4420 4430 4440 4450 4460 4470 4480 4490 4500 4510 4520 4530 4540 4550 4560 4570 4580 4590 4600 4610 4620 4630 4640 4650 4660 4670 4680 4690 4700 4710 4720 4730 4740 4750 4760 4770 4780 4790 4800 4810 4820 4830 4840 4850 4860 4870 4880 4890 4900 4910 4920 4930 4940 4950 4960 4970 4980 4990 5000 5010 5020 5030 5040 5050 5060 5070 5080 5090 5100 5110 5120 5130 5140 5150 5160 5170 5180 5190 5200 5210 5220 5230 5240 5250 5260 5270 5280 5290 5300 5310 5320 5330 5340 5350 5360 5370 5380 5390 5400 5410 5420 5430 5440 5450 5460 5470 5480 5490 5500 5510 5520 5530 5540 5550 5560 5570 5580 5590 5600 5610 5620 5630 5640 5650 5660 5670 5680 5690 5700 5710 5720 5730 5740 5750 5760 5770 5780 5790 5800 5810 5820 5830 5840 5850 5860 5870 5880 5890 5900 5910 5920 5930 5940 5950 5960 5970 5980 5990 6000 6010 6020 6030 6040 6050 6060 6070 6080 6090 6100 6110 6120 6130 6140 6150 6160 6170 6180 6190 6200 6210 6220 6230 6240 6250 6260 6270 6280 6290 6300 6310 6320 6330 6340 6350 6360 6370 6380 6390 6400 6410 6420 6430 6440 6450 6460 6470 6480 6490 6500 6510 6520 6530 6540 6550 6560 6570 6580 6590 6600 6610 6620 6630 6640 6650 6660 6670 6680 6690 6700 6710 6720 6730 6740 6750 6760 6770 6780 6790 6800 6810 6820 6830 6840 6850 6860 6870 6880 6890 6900 6910 6920 6930 6940 6950 6960 6970 6980 6990 7000 7010 7020 7030 7040 7050 7060 7070 7080 7090 7100 7110 7120 7130 7140 7150 7160 7170 7180 7190 7200 7210 7220 7230 7240 7250 7260 7270 7280 7290 7300 7310 7320 7330 7340 7350 7360 7370 7380 7390 7400 7410 7420 7430 7440 7450 7460 7470 7480 7490 7500 7510 7520 7530 7540 7550 7560 7570 7580 7590 7600 7610 7620 7630 7640 7650 7660 7670 7680 7690 7700 7710 7720 7730 7740 7750 7760 7770 7780 7790 7800 7810 7820 7830 7840 7850 7860 7870 7880 7890 7900 7910 7920 7930 7940 7950 7960 7970 7980 7990 8000 8010 8020 8030 8040 8050 8060 8070 8080 8090 8100 8110 8120 8130 8140 8150 8160 8170 8180 8190 8200 8210 8220 8230 8240 8250 8260 8270 8280 8290 8300 8310 8320 8330 8340 8350 8360 8370 8380 8390 8400 8410 8420 8430 8440 8450 8460 8470 8480 8490 8500 8510 8520 8530 8540 8550 8560 8570 8580 8590 8600 8610 8620 8630 8640 8650 8660 8670 8680 8690 8700 8710 8720 8730 8740 8750 8760 8770 8780 8790 8800 8810 8820 8830 8840 8850 8860 8870 8880 8890 8900 8910 8920 8930 8940 8950 8960 8970 8980 8990 9000 9010 9020 9030 9040 9050 9060 9070 9080 9090 9100 9110 9120 9130 9140 9150 9160 9170 9180 9190 9200 9210 9220 9230 9240 9250 9260 9270 9280 9290 9300 9310 9320 9330 9340 9350 9360 9370 9380 9390 9400 9410 9420 9430 9440 9450 9460 9470 9480 9490 9500 9510 9520 9530 9540 9550 9560 9570 9580 9590 9600 9610 9620 9630 9640 9650 9660 9670 9680 9690 9700 9710 9720 9730 9740 9750 9760 9770 9780 9790 9800 9810 9820 9830 9840 9850 9860 9870 9880 9890 9900 9910 9920 9930 9940 9950 9960 9970 9980 9990 10000 10010 10020 10030 10040 10050 10060 10070 10080 10090 10100 10110 10120 10130 10140 10150 10160 10170 10180 10190 10200 10210 10220 10230 10240 10250 10260 10270 10280 10290 10300 10310 10320 10330 10340 10350 10360 10370 10380 10390 10400 10410 10420 10430 10440 10450 10460 10470 10480 10490 10500 10510 10520 10530 10540 10550 10560 10570 10580 10590 10600 10610 10620 10630 10640 10650 10660 10670 10680 10690 10700 10710 10720 10730 10740 10750 10760 10770 10780 10790 10800 10810 10820 10830 10840 10850 10860 10870 10880 10890 10900 10910 10920 10930 10940 10950 10960 10970 10980 10990 11000 11010 11020 11030 11040 11050 11060 11070 11080 11090 11100 11110 11120 11130 11140 11150 11160 11170 11180 11190 11200 11210 11220 11230 11240 11250 11260 11270 11280 11290 11300 11310 11320 11330 11340 11350 11360 11370 11380 11390 11400 11410 11420 11430 11440 11450 11460 11470 11480 11490 11500 11510 11520 11530 11540 11550 11560 11570 11580 11590 11600 11610 11620 11630 11640 11650 11660 11670 11680 11690 11700 11710 11720 11730 11740 11750 11760 11770 11780 11790 11800 11810 11820 11830 11840 11850 11860 11870 11880 11890 11900 11910 11920 11930 11940 11950 11960 11970 11980 11990 12000 12010 12020 12030 12040 12050 12060 12070 12080 12090 12100 12110 12120 12130 12140 12150 12160 12170 12180 12190 12200 12210 12220 12230 12240 12250 12260 12270 12280 12290 12300 12310 12320 12330 12340 12350 12360 12370 12380 12390 12400 12410 12420 12430 12440 12450 12460 12470 12480 12490 12500 12510 12520 12530 12540 12550 12560 12570 12580 12590 12600 12610 12620 12630 12640 12650 12660 12670 12680 12690 12700 12710 12720 12730 12740 12750 12760 12770 12780 12790 12800 12810 12820 12830 12840 12850 12860 12870 12880 12890 12900 12910 12920 12930 12940 12950 12960 12970 12980 12990 13000 13010 13020 13030 13040 13050 13060 13070 13080 13090 13100 13110 13120 13130 13140 13150 13160 13170 13180 13190 13200 13210 13220 13230 13240 13250 13260 13270 13280 13290 13300 13310 13320 13330 13340 13350 13360 13370 13380 13390 13400 13410 13420 13430 13440 13450 13460 13470 13480 13490 13500 13510 13520 13530 13540 13550 13560 13570 13580 13590 13600 13610 13620 13630 13640 13650 13660 13670 13680 13690 13700 13710 13720 13730 13740 13750 13760 13770 13780 13790 13800 13810 13820 13830 13840 13850 13860 13870 13880 13890 13900 13910 13920 13930 13940 13950 13960 13970 13980 13990 14000 14010 14020 14030 14040 14050 14060 14070 14080 14090 14100 14110 14120 14130 14140 14150 14160 14170 14180 14190 14200 14210 14220 14230 14240 14250 14260 14270 14280 14290 14300 14310 14320 14330 14340 14350 14360 14370 14380 14390 14400 14410 14420 14430 14440 14450 14460 14470 14480 14490 14500 14510 14520 14530 14540 14550 14560 14570 14580 14590 14600 14610 14620 14630 14640 14650 14660 14670 14680 14690 14700 14710 14720 14730 14740 14750 14760 14770 14780 14790 14800 14810 14820 14830 14840 14850 14860 14870 14880 14890 14900 14910 14920 14930 14940 14950 14960 14970 14980 14990 15000 15010 15020 15030 15040 15050 15060 15070 15080 15090 15100 15110 15120 15130 15140 15150 15160 15170 15180 15190 15200 15210 15220 15230 15240 15250 15260 15270 15280 15290 15300 15310 15320 15330 15340 15350 15360 15370 15380 15390 15400 15410 15420 15430 15440 15450 15460 15470 15480 15490 15500 15510 15520 15530 15540 15550 15560 15570 15580 15590 15600 15610 15620 15630 15640 15650 15660 15670 15680 15690 15700 15710 15720 15730 15740 15750 15760 15770 15780 15790 15800 15810 15820 15830 15840 15850 15860 15870 15880 15890 15900 15910 15920 15930 15940 15950 15960 15970 15980 15990 16000 16010 16020 16030 16040 16050 16060 16070 16080 16090 16100 16110 16120 16130 16140 16150 16160 16170 16180 16190 16200 16210 16220 16230 16240 16250 16260 16270 16280 16290 16300 16310 16320 16330 16340 16350 16360 16370 16380 16390 16400 16410 16420 16430 16440 16450 16460 16470 16480 16490 16500 16510 16520 16530 16540 16550 16560 16570 16580 16590 16600 16610 16620 16630 16640 16650 16660 16670 16680 16690 16700 16710 16720 16730 16740 16750 16760 16770 16780 16790 16800 16810 16820 16830 16840 16850 16860 16870 16880 16890 16900 16910 16920 16930 16940 16950 16960 16970 16980 16990 17000 17010 17020 17030 17040 17050 17060 17070 17080 17090 17100 17110 17120 17130 17140 17150 17160 17170 17180 17190 17200 17210 17220 17230 17240 17250 17260 17270 17280 17290 17300 17310 17320 17330 17340 17350 17360 17370 17380 17390 17400 17410 17420 17430 17440 17450 17460 17470 17480 17490 17500 17510 17520 17530 17540 17550 17560 17570 17580 17590 17600 17610 17620 17630 17640 17650 17660 17670 17680 17690 17700 17710 17720 17730 17740 17750 17760 17770 17780 17790 17800 17810 17820 17830 17840 17850 17860 17870 17880 17890 17900 17910 17920 17930 17940 17950 17960 17970 17980 17990 18000 18010 18020 18030 18040 18050 18060 18070 18080 18090 18100 18110 18120 18130 18140 18150 18160 18170 18180 18190 18200 18210 18220 18230 18240 18250 18260 18270 18280 18290 18300 18310 18320 18330 18340 18350 18360 18370 18380 18390 18400 18410 18420 18430 18440 18450 18460 18470 18480 18490 18500 18510 18520 18530 18540 18550 18560 18570 18580 18590 18600 18610 18620 18630 18640 18650 18660 18670 18680 18690 18700 18710 18720 18730 18740 18750 18760 18770 18780 18790 18800 18810 18820 18830 18840 18850 18860 18870 18880 18890 18900 18910 18920 18930 18940 18950 18960 18970 18980 18990 19000 19010 19020 19030 19040 19050 19060 19070 19080 19090 19100 19110 19120 19130 19140 19150 19160 19170 19180 19190 19200 19210 19220 19230 19240 19250 19260 19270 19280 19290 19300 19310 19320 19330 19340 19350 19360 19370 19380 19390 19400 19410 19420 19430 19440 19450 19460 19470 19480 19490 19500 19510 19520 19530 19540 19550 19560 19570 19580 19590 19600 19610 19620 19630 19640 19650 19660 19670 19680 19690 19700 19710 19720 19730 19740 19750 19760 19770 19780 19790 19800 19810 19820 19830 19840 19850 19860 19870 19880 19890 19900 19910 19920 19930 19940 19950 19960 19970 19980 19990 20000 20010 20020 20030 20040 20050 20060 20070 20080 20090 20100 20110 20120 20130 20140 20150 20160 20170 20180 20190 20200 20210 20220 20230 20240 20250 20260 20270 20280 20290 20300 20310 20320 20330 20340 20350 20360 20370 20380 20390 20400 20410 20420 20430 20440 20450 20460 20470 20480 20490 20500 20510 20520 20530 20540 20550 20560 20570 20580 20590 20600 20610 20620 20630 20640 20650 20660 20670 20680 20690 20700 20710 20720 20730 20740 20750 20760 20770 20780 20790 20800 20810 20820 20830 20840 20850 20860 20870 20880 20890 20900 20910 20920 20930 20940 20950 20960 20970 20980 20990 21000 21010 21020 21030 21040 21050 21060 21070 21080 21090 21100 21110 21120 21130 21140 21150 21160 21170 21180 21190 21200 21210 21220 21230 21240 21250 21260 21270 21280 21290 21300 21310 21320 21330 21340 21350 21360 21370 21380 21390 21400 21410 21420 21430 21440 21450 21460 21470 21480 21490 21500 21510 21520 21530 21540 21550 21560 21570 21580 21590 21600 21610 21620 21630 21640 21650 21660 21670 21680 21690 21700 21710 21720 21730 21740 21750 21760 21770 21780 21790 21800 21810 21820 21830 21840 21850 21860 21870 21880 21890 21900 21910 21920 21930 21940 21950 21960 21970 21980 21990 22000 22010 22020 22030 22040 22050 22060 22070 22080 22090 22100 22110 22120 22130 22140 22150 22160 22170 22180 22190 22200 22210 22220 22230 22240 22250 22260 22270 22280 22290 22300 22310 22320123456import { Matrix3, Vector2, Color, mergeUniforms, Vector3, Mesh, BoxGeometry, ShaderMaterial, BackSide, cloneUniforms, Matrix4, ColorManagement, SRGBTransfer, PlaneGeometry, FrontSide, getUnlitUniformColorSpace, IntType, warn, HalfFloatType, UnsignedByteType, FloatType, RGBAFormat, Plane, WebGLRenderTarget, CubeTexture, NoBlending, LinearMipmapLinearFilter, LinearFilter, CubeCamera, floorPowerOfTwo, CubeReflectionMapping, CubeRefractionMapping, LinearSRGBColorSpace, EquirectangularReflectionMapping, EquirectangularRefractionMapping, warnOnce, Uint32BufferAttribute, Uint16BufferAttribute, error, DataArrayTexture, Vector4, BufferGeometry, Float32BufferAttribute, RawShaderMaterial, OrthographicCamera, DepthTexture, DepthStencilFormat, UnsignedInt248Type, NoToneMapping, CustomToneMapping, NeutralToneMapping, AgXToneMapping, ACESFilmicToneMapping, CineonToneMapping, ReinhardToneMapping, LinearToneMapping, Data3DTexture, AlwaysCompare, Texture, CubeDepthTexture, GLSL3, VSMShadowMap, PCFShadowMap, AddOperation, MixOperation, MultiplyOperation, LinearTransfer, UniformsUtils, DoubleSide, NormalBlending, TangentSpaceNormalMap, ObjectSpaceNormalMap, Layers, RGFormat, RG11_EAC_Format, RED_GREEN_RGTC2_Format, MeshDepthMaterial, MeshDistanceMaterial, BufferAttribute, PCFSoftShadowMap, DepthFormat, NearestFilter, UnsignedIntType, GreaterEqualCompare, LessEqualCompare, Frustum, LessEqualDepth, ReverseSubtractEquation, SubtractEquation, AddEquation, OneMinusConstantAlphaFactor, ConstantAlphaFactor, OneMinusConstantColorFactor, ConstantColorFactor, OneMinusDstAlphaFactor, OneMinusDstColorFactor, OneMinusSrcAlphaFactor, OneMinusSrcColorFactor, DstAlphaFactor, DstColorFactor, SrcAlphaSaturateFactor, SrcAlphaFactor, SrcColorFactor, OneFactor, ZeroFactor, NotEqualDepth, GreaterDepth, GreaterEqualDepth, EqualDepth, LessDepth, AlwaysDepth, NeverDepth, CullFaceNone, CullFaceBack, CullFaceFront, CustomBlending, MultiplyBlending, SubtractiveBlending, AdditiveBlending, ReversedDepthFuncs, MinEquation, MaxEquation, MirroredRepeatWrapping, ClampToEdgeWrapping, RepeatWrapping, LinearMipmapNearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, NotEqualCompare, GreaterCompare, EqualCompare, LessCompare, NeverCompare, NoColorSpace, getByteLength, UnsignedShortType, createElementNS, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedInt5999Type, UnsignedInt101111Type, ByteType, ShortType, AlphaFormat, RGBFormat, RedFormat, RedIntegerFormat, RGIntegerFormat, RGBAIntegerFormat, RGB_S3TC_DXT1_Format, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, RGB_PVRTC_4BPPV1_Format, RGB_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGBA_PVRTC_2BPPV1_Format, RGB_ETC1_Format, RGB_ETC2_Format, RGBA_ETC2_EAC_Format, R11_EAC_Format, SIGNED_R11_EAC_Format, SIGNED_RG11_EAC_Format, RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_10x10_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, RGBA_BPTC_Format, RGB_BPTC_SIGNED_Format, RGB_BPTC_UNSIGNED_Format, RED_RGTC1_Format, SIGNED_RED_RGTC1_Format, SIGNED_RED_GREEN_RGTC2_Format, ExternalTexture, EventDispatcher, PerspectiveCamera, ArrayCamera, WebXRController, RAD2DEG, DataTexture, createCanvasElement, SRGBColorSpace, REVISION, log, FrustumArray, WebGLCoordinateSystem, probeAsync } from './three.core.js';7export { AdditiveAnimationBlendMode, AlwaysStencilFunc, AmbientLight, AnimationAction, AnimationClip, AnimationLoader, AnimationMixer, AnimationObjectGroup, AnimationUtils, ArcCurve, ArrowHelper, AttachedBindMode, Audio, AudioAnalyser, AudioContext, AudioListener, AudioLoader, AxesHelper, BasicDepthPacking, BasicShadowMap, BatchedMesh, BezierInterpolant, Bone, BooleanKeyframeTrack, Box2, Box3, Box3Helper, BoxHelper, BufferGeometryLoader, Cache, Camera, CameraHelper, CanvasTexture, CapsuleGeometry, CatmullRomCurve3, CircleGeometry, Clock, ColorKeyframeTrack, Compatibility, CompressedArrayTexture, CompressedCubeTexture, CompressedTexture, CompressedTextureLoader, ConeGeometry, Controls, CubeTextureLoader, CubicBezierCurve, CubicBezierCurve3, CubicInterpolant, CullFaceFrontBack, Curve, CurvePath, CylinderGeometry, Cylindrical, DataTextureLoader, DataUtils, DecrementStencilOp, DecrementWrapStencilOp, DefaultLoadingManager, DetachedBindMode, DirectionalLight, DirectionalLightHelper, DiscreteInterpolant, DodecahedronGeometry, DynamicCopyUsage, DynamicDrawUsage, DynamicReadUsage, EdgesGeometry, EllipseCurve, EqualStencilFunc, Euler, ExtrudeGeometry, FileLoader, Float16BufferAttribute, Fog, FogExp2, FramebufferTexture, GLBufferAttribute, GLSL1, GreaterEqualStencilFunc, GreaterStencilFunc, GridHelper, Group, HTMLTexture, HemisphereLight, HemisphereLightHelper, IcosahedronGeometry, ImageBitmapLoader, ImageLoader, ImageUtils, IncrementStencilOp, IncrementWrapStencilOp, InstancedBufferAttribute, InstancedBufferGeometry, InstancedInterleavedBuffer, InstancedMesh, Int16BufferAttribute, Int32BufferAttribute, Int8BufferAttribute, InterleavedBuffer, InterleavedBufferAttribute, Interpolant, InterpolateBezier, InterpolateDiscrete, InterpolateLinear, InterpolateSmooth, InterpolationSamplingMode, InterpolationSamplingType, InvertStencilOp, KeepStencilOp, KeyframeTrack, LOD, LatheGeometry, LessEqualStencilFunc, LessStencilFunc, Light, LightProbe, LightShadow, Line, Line3, LineBasicMaterial, LineCurve, LineCurve3, LineDashedMaterial, LineLoop, LineSegments, LinearInterpolant, LinearMipMapLinearFilter, LinearMipMapNearestFilter, Loader, LoaderUtils, LoadingManager, LoopOnce, LoopPingPong, LoopRepeat, MOUSE, Material, MaterialBlending, MaterialLoader, MathUtils, Matrix2, MeshBasicMaterial, MeshLambertMaterial, MeshMatcapMaterial, MeshNormalMaterial, MeshPhongMaterial, MeshPhysicalMaterial, MeshStandardMaterial, MeshToonMaterial, NearestMipMapLinearFilter, NearestMipMapNearestFilter, NeverStencilFunc, NoNormalPacking, NormalAnimationBlendMode, NormalGAPacking, NormalRGPacking, NotEqualStencilFunc, NumberKeyframeTrack, Object3D, ObjectLoader, OctahedronGeometry, Path, PlaneHelper, PointLight, PointLightHelper, Points, PointsMaterial, PolarGridHelper, PolyhedronGeometry, PositionalAudio, PropertyBinding, PropertyMixer, QuadraticBezierCurve, QuadraticBezierCurve3, Quaternion, QuaternionKeyframeTrack, QuaternionLinearInterpolant, RGBADepthPacking, RGBDepthPacking, RGBIntegerFormat, RGDepthPacking, Ray, Raycaster, RectAreaLight, RenderObjectRefreshType, RenderTarget, RenderTarget3D, ReplaceStencilOp, RingGeometry, Scene, ShadowMaterial, Shape, ShapeGeometry, ShapePath, ShapeUtils, Skeleton, SkeletonHelper, SkinnedMesh, Source, Sphere, SphereGeometry, Spherical, SphericalHarmonics3, SplineCurve, SpotLight, SpotLightHelper, Sprite, SpriteMaterial, StaticCopyUsage, StaticDrawUsage, StaticReadUsage, StereoCamera, StreamCopyUsage, StreamDrawUsage, StreamReadUsage, StringKeyframeTrack, TOUCH, TetrahedronGeometry, TextureLoader, TextureSource, TextureUtils, Timer, TimestampQuery, TorusGeometry, TorusKnotGeometry, Triangle, TriangleFanDrawMode, TriangleStripDrawMode, TrianglesDrawMode, TubeGeometry, UVMapping, Uint8BufferAttribute, Uint8ClampedBufferAttribute, Uniform, UniformsGroup, VectorKeyframeTrack, VideoFrameTexture, VideoTexture, WebGL3DRenderTarget, WebGLArrayRenderTarget, WebGPUCoordinateSystem, WireframeGeometry, WrapAroundEnding, ZeroCurvatureEnding, ZeroSlopeEnding, ZeroStencilOp, getConsoleFunction, setConsoleFunction } from './three.core.js';89function WebGLAnimation() {1011 let context = null;12 let isAnimating = false;13 let animationLoop = null;14 let requestId = null;1516 function onAnimationFrame( time, frame ) {1718 requestId = context.requestAnimationFrame( onAnimationFrame );1920 animationLoop( time, frame );2122 }2324 return {2526 start: function () {2728 if ( isAnimating === true ) return;29 if ( animationLoop === null ) return;30 if ( context === null ) return;3132 requestId = context.requestAnimationFrame( onAnimationFrame );3334 isAnimating = true;3536 },3738 stop: function () {3940 if ( context !== null ) context.cancelAnimationFrame( requestId );4142 isAnimating = false;4344 },4546 setAnimationLoop: function ( callback ) {4748 animationLoop = callback;4950 },5152 setContext: function ( value ) {5354 context = value;5556 }5758 };5960}6162function WebGLAttributes( gl ) {6364 const buffers = new WeakMap();6566 function createBuffer( attribute, bufferType ) {6768 const array = attribute.array;69 const usage = attribute.usage;70 const size = array.byteLength;7172 const buffer = gl.createBuffer();7374 gl.bindBuffer( bufferType, buffer );75 gl.bufferData( bufferType, array, usage );7677 attribute.onUploadCallback();7879 let type;8081 if ( array instanceof Float32Array ) {8283 type = gl.FLOAT;8485 } else if ( typeof Float16Array !== 'undefined' && array instanceof Float16Array ) {8687 type = gl.HALF_FLOAT;8889 } else if ( array instanceof Uint16Array ) {9091 if ( attribute.isFloat16BufferAttribute ) {9293 type = gl.HALF_FLOAT;9495 } else {9697 type = gl.UNSIGNED_SHORT;9899 }100101 } else if ( array instanceof Int16Array ) {102103 type = gl.SHORT;104105 } else if ( array instanceof Uint32Array ) {106107 type = gl.UNSIGNED_INT;108109 } else if ( array instanceof Int32Array ) {110111 type = gl.INT;112113 } else if ( array instanceof Int8Array ) {114115 type = gl.BYTE;116117 } else if ( array instanceof Uint8Array ) {118119 type = gl.UNSIGNED_BYTE;120121 } else if ( array instanceof Uint8ClampedArray ) {122123 type = gl.UNSIGNED_BYTE;124125 } else {126127 throw new Error( 'THREE.WebGLAttributes: Unsupported buffer data format: ' + array );128129 }130131 return {132 buffer: buffer,133 type: type,134 bytesPerElement: array.BYTES_PER_ELEMENT,135 version: attribute.version,136 size: size137 };138139 }140141 function updateBuffer( buffer, attribute, bufferType ) {142143 const array = attribute.array;144 const updateRanges = attribute.updateRanges;145146 gl.bindBuffer( bufferType, buffer );147148 if ( updateRanges.length === 0 ) {149150 151 gl.bufferSubData( bufferType, 0, array );152153 } else {154155 156 157 158 159 160 161 162 163164 updateRanges.sort( ( a, b ) => a.start - b.start );165166 167 168 169 170 171 let mergeIndex = 0;172173 for ( let i = 1; i < updateRanges.length; i ++ ) {174175 const previousRange = updateRanges[ mergeIndex ];176 const range = updateRanges[ i ];177178 179 180 if ( range.start <= previousRange.start + previousRange.count + 1 ) {181182 previousRange.count = Math.max(183 previousRange.count,184 range.start + range.count - previousRange.start185 );186187 } else {188189 ++ mergeIndex;190 updateRanges[ mergeIndex ] = range;191192 }193194 }195196 197 updateRanges.length = mergeIndex + 1;198199 for ( let i = 0, l = updateRanges.length; i < l; i ++ ) {200201 const range = updateRanges[ i ];202203 gl.bufferSubData( bufferType, range.start * array.BYTES_PER_ELEMENT,204 array, range.start, range.count );205206 }207208 attribute.clearUpdateRanges();209210 }211212 attribute.onUploadCallback();213214 }215216 217218 function get( attribute ) {219220 if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;221222 return buffers.get( attribute );223224 }225226 function remove( attribute ) {227228 if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;229230 const data = buffers.get( attribute );231232 if ( data ) {233234 gl.deleteBuffer( data.buffer );235236 buffers.delete( attribute );237238 }239240 }241242 function update( attribute, bufferType ) {243244 if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;245246 if ( attribute.isGLBufferAttribute ) {247248 const cached = buffers.get( attribute );249250 if ( ! cached || cached.version < attribute.version ) {251252 buffers.set( attribute, {253 buffer: attribute.buffer,254 type: attribute.type,255 bytesPerElement: attribute.elementSize,256 version: attribute.version257 } );258259 }260261 return;262263 }264265 const data = buffers.get( attribute );266267 if ( data === undefined ) {268269 buffers.set( attribute, createBuffer( attribute, bufferType ) );270271 } else if ( data.version < attribute.version ) {272273 if ( data.size !== attribute.array.byteLength ) {274275 throw new Error( 'THREE.WebGLAttributes: The size of the buffer attribute\'s array buffer does not match the original size. Resizing buffer attributes is not supported.' );276277 }278279 updateBuffer( data.buffer, attribute, bufferType );280281 data.version = attribute.version;282283 }284285 }286287 return {288289 get: get,290 remove: remove,291 update: update292293 };294295}296297var alphahash_fragment = "#ifdef USE_ALPHAHASH\n\tif ( diffuseColor.a < getAlphaHashThreshold( vPosition ) ) discard;\n#endif";298299var alphahash_pars_fragment = "#ifdef USE_ALPHAHASH\n\tconst float ALPHA_HASH_SCALE = 0.05;\n\tfloat hash2D( vec2 value ) {\n\t\treturn fract( 1.0e4 * sin( 17.0 * value.x + 0.1 * value.y ) * ( 0.1 + abs( sin( 13.0 * value.y + value.x ) ) ) );\n\t}\n\tfloat hash3D( vec3 value ) {\n\t\treturn hash2D( vec2( hash2D( value.xy ), value.z ) );\n\t}\n\tfloat getAlphaHashThreshold( vec3 position ) {\n\t\tfloat maxDeriv = max(\n\t\t\tlength( dFdx( position.xyz ) ),\n\t\t\tlength( dFdy( position.xyz ) )\n\t\t);\n\t\tfloat pixScale = 1.0 / ( ALPHA_HASH_SCALE * maxDeriv );\n\t\tvec2 pixScales = vec2(\n\t\t\texp2( floor( log2( pixScale ) ) ),\n\t\t\texp2( ceil( log2( pixScale ) ) )\n\t\t);\n\t\tvec2 alpha = vec2(\n\t\t\thash3D( floor( pixScales.x * position.xyz ) ),\n\t\t\thash3D( floor( pixScales.y * position.xyz ) )\n\t\t);\n\t\tfloat lerpFactor = fract( log2( pixScale ) );\n\t\tfloat x = ( 1.0 - lerpFactor ) * alpha.x + lerpFactor * alpha.y;\n\t\tfloat a = min( lerpFactor, 1.0 - lerpFactor );\n\t\tvec3 cases = vec3(\n\t\t\tx * x / ( 2.0 * a * ( 1.0 - a ) ),\n\t\t\t( x - 0.5 * a ) / ( 1.0 - a ),\n\t\t\t1.0 - ( ( 1.0 - x ) * ( 1.0 - x ) / ( 2.0 * a * ( 1.0 - a ) ) )\n\t\t);\n\t\tfloat threshold = ( x < ( 1.0 - a ) )\n\t\t\t? ( ( x < a ) ? cases.x : cases.y )\n\t\t\t: cases.z;\n\t\treturn clamp( threshold , 1.0e-6, 1.0 );\n\t}\n#endif";300301var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vAlphaMapUv ).g;\n#endif";302303var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";304305var alphatest_fragment = "#ifdef USE_ALPHATEST\n\t#ifdef ALPHA_TO_COVERAGE\n\tdiffuseColor.a = smoothstep( alphaTest, alphaTest + fwidth( diffuseColor.a ), diffuseColor.a );\n\tif ( diffuseColor.a == 0.0 ) discard;\n\t#else\n\tif ( diffuseColor.a < alphaTest ) discard;\n\t#endif\n#endif";306307var alphatest_pars_fragment = "#ifdef USE_ALPHATEST\n\tuniform float alphaTest;\n#endif";308309var aomap_fragment = "#ifdef USE_AOMAP\n\tfloat ambientOcclusion = ( texture2D( aoMap, vAoMapUv ).r - 1.0 ) * aoMapIntensity + 1.0;\n\treflectedLight.indirectDiffuse *= ambientOcclusion;\n\t#if defined( USE_CLEARCOAT ) \n\t\tclearcoatSpecularIndirect *= ambientOcclusion;\n\t#endif\n\t#if defined( USE_SHEEN ) \n\t\tsheenSpecularIndirect *= ambientOcclusion;\n\t#endif\n\t#if defined( USE_ENVMAP ) && defined( STANDARD )\n\t\tfloat dotNV = saturate( dot( geometryNormal, geometryViewDir ) );\n\t\treflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.roughness );\n\t#endif\n#endif";310311var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";312313var batching_pars_vertex = "#ifdef USE_BATCHING\n\t#if ! defined( GL_ANGLE_multi_draw )\n\t#define gl_DrawID _gl_DrawID\n\tuniform int _gl_DrawID;\n\t#endif\n\tuniform highp sampler2D batchingTexture;\n\tuniform highp usampler2D batchingIdTexture;\n\tmat4 getBatchingMatrix( const in float i ) {\n\t\tint size = textureSize( batchingTexture, 0 ).x;\n\t\tint j = int( i ) * 4;\n\t\tint x = j % size;\n\t\tint y = j / size;\n\t\tvec4 v1 = texelFetch( batchingTexture, ivec2( x, y ), 0 );\n\t\tvec4 v2 = texelFetch( batchingTexture, ivec2( x + 1, y ), 0 );\n\t\tvec4 v3 = texelFetch( batchingTexture, ivec2( x + 2, y ), 0 );\n\t\tvec4 v4 = texelFetch( batchingTexture, ivec2( x + 3, y ), 0 );\n\t\treturn mat4( v1, v2, v3, v4 );\n\t}\n\tfloat getIndirectIndex( const in int i ) {\n\t\tint size = textureSize( batchingIdTexture, 0 ).x;\n\t\tint x = i % size;\n\t\tint y = i / size;\n\t\treturn float( texelFetch( batchingIdTexture, ivec2( x, y ), 0 ).r );\n\t}\n#endif\n#ifdef USE_BATCHING_COLOR\n\tuniform sampler2D batchingColorTexture;\n\tvec4 getBatchingColor( const in float i ) {\n\t\tint size = textureSize( batchingColorTexture, 0 ).x;\n\t\tint j = int( i );\n\t\tint x = j % size;\n\t\tint y = j / size;\n\t\treturn texelFetch( batchingColorTexture, ivec2( x, y ), 0 );\n\t}\n#endif";314315var batching_vertex = "#ifdef USE_BATCHING\n\tmat4 batchingMatrix = getBatchingMatrix( getIndirectIndex( gl_DrawID ) );\n#endif";316317var begin_vertex = "vec3 transformed = vec3( position );\n#ifdef USE_ALPHAHASH\n\tvPosition = vec3( position );\n#endif";318319var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";320321var bsdfs = "float G_BlinnPhong_Implicit( ) {\n\treturn 0.25;\n}\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n\treturn RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\nvec3 BRDF_BlinnPhong( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float shininess ) {\n\tvec3 halfDir = normalize( lightDir + viewDir );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat dotVH = saturate( dot( viewDir, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, 1.0, dotVH );\n\tfloat G = G_BlinnPhong_Implicit( );\n\tfloat D = D_BlinnPhong( shininess, dotNH );\n\treturn F * ( G * D );\n} // validated";322323var iridescence_fragment = "#ifdef USE_IRIDESCENCE\n\tconst mat3 XYZ_TO_REC709 = mat3(\n\t\t 3.2404542, -0.9692660, 0.0556434,\n\t\t-1.5371385, 1.8760108, -0.2040259,\n\t\t-0.4985314, 0.0415560, 1.0572252\n\t);\n\tvec3 Fresnel0ToIor( vec3 fresnel0 ) {\n\t\tvec3 sqrtF0 = sqrt( fresnel0 );\n\t\treturn ( vec3( 1.0 ) + sqrtF0 ) / ( vec3( 1.0 ) - sqrtF0 );\n\t}\n\tvec3 IorToFresnel0( vec3 transmittedIor, float incidentIor ) {\n\t\treturn pow2( ( transmittedIor - vec3( incidentIor ) ) / ( transmittedIor + vec3( incidentIor ) ) );\n\t}\n\tfloat IorToFresnel0( float transmittedIor, float incidentIor ) {\n\t\treturn pow2( ( transmittedIor - incidentIor ) / ( transmittedIor + incidentIor ));\n\t}\n\tvec3 evalSensitivity( float OPD, vec3 shift ) {\n\t\tfloat phase = 2.0 * PI * OPD * 1.0e-9;\n\t\tvec3 val = vec3( 5.4856e-13, 4.4201e-13, 5.2481e-13 );\n\t\tvec3 pos = vec3( 1.6810e+06, 1.7953e+06, 2.2084e+06 );\n\t\tvec3 var = vec3( 4.3278e+09, 9.3046e+09, 6.6121e+09 );\n\t\tvec3 xyz = val * sqrt( 2.0 * PI * var ) * cos( pos * phase + shift ) * exp( - pow2( phase ) * var );\n\t\txyz.x += 9.7470e-14 * sqrt( 2.0 * PI * 4.5282e+09 ) * cos( 2.2399e+06 * phase + shift[ 0 ] ) * exp( - 4.5282e+09 * pow2( phase ) );\n\t\txyz /= 1.0685e-7;\n\t\tvec3 rgb = XYZ_TO_REC709 * xyz;\n\t\treturn rgb;\n\t}\n\tvec3 evalIridescence( float outsideIOR, float eta2, float cosTheta1, float thinFilmThickness, vec3 baseF0 ) {\n\t\tvec3 I;\n\t\tfloat iridescenceIOR = mix( outsideIOR, eta2, smoothstep( 0.0, 0.03, thinFilmThickness ) );\n\t\tfloat sinTheta2Sq = pow2( outsideIOR / iridescenceIOR ) * ( 1.0 - pow2( cosTheta1 ) );\n\t\tfloat cosTheta2Sq = 1.0 - sinTheta2Sq;\n\t\tif ( cosTheta2Sq < 0.0 ) {\n\t\t\treturn vec3( 1.0 );\n\t\t}\n\t\tfloat cosTheta2 = sqrt( cosTheta2Sq );\n\t\tfloat R0 = IorToFresnel0( iridescenceIOR, outsideIOR );\n\t\tfloat R12 = F_Schlick( R0, 1.0, cosTheta1 );\n\t\tfloat T121 = 1.0 - R12;\n\t\tfloat phi12 = 0.0;\n\t\tif ( iridescenceIOR < outsideIOR ) phi12 = PI;\n\t\tfloat phi21 = PI - phi12;\n\t\tvec3 baseIOR = Fresnel0ToIor( clamp( baseF0, 0.0, 0.9999 ) );\t\tvec3 R1 = IorToFresnel0( baseIOR, iridescenceIOR );\n\t\tvec3 R23 = F_Schlick( R1, 1.0, cosTheta2 );\n\t\tvec3 phi23 = vec3( 0.0 );\n\t\tif ( baseIOR[ 0 ] < iridescenceIOR ) phi23[ 0 ] = PI;\n\t\tif ( baseIOR[ 1 ] < iridescenceIOR ) phi23[ 1 ] = PI;\n\t\tif ( baseIOR[ 2 ] < iridescenceIOR ) phi23[ 2 ] = PI;\n\t\tfloat OPD = 2.0 * iridescenceIOR * thinFilmThickness * cosTheta2;\n\t\tvec3 phi = vec3( phi21 ) + phi23;\n\t\tvec3 R123 = clamp( R12 * R23, 1e-5, 0.9999 );\n\t\tvec3 r123 = sqrt( R123 );\n\t\tvec3 Rs = pow2( T121 ) * R23 / ( vec3( 1.0 ) - R123 );\n\t\tvec3 C0 = R12 + Rs;\n\t\tI = C0;\n\t\tvec3 Cm = Rs - T121;\n\t\tfor ( int m = 1; m <= 2; ++ m ) {\n\t\t\tCm *= r123;\n\t\t\tvec3 Sm = 2.0 * evalSensitivity( float( m ) * OPD, float( m ) * phi );\n\t\t\tI += Cm * Sm;\n\t\t}\n\t\treturn max( I, vec3( 0.0 ) );\n\t}\n#endif";324325var bumpmap_pars_fragment = "#ifdef USE_BUMPMAP\n\tuniform sampler2D bumpMap;\n\tuniform float bumpScale;\n\tvec2 dHdxy_fwd() {\n\t\tvec2 dSTdx = dFdx( vBumpMapUv );\n\t\tvec2 dSTdy = dFdy( vBumpMapUv );\n\t\tfloat Hll = bumpScale * texture2D( bumpMap, vBumpMapUv ).x;\n\t\tfloat dBx = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdx ).x - Hll;\n\t\tfloat dBy = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdy ).x - Hll;\n\t\treturn vec2( dBx, dBy );\n\t}\n\tvec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy, float faceDirection ) {\n\t\tvec3 vSigmaX = normalize( dFdx( surf_pos.xyz ) );\n\t\tvec3 vSigmaY = normalize( dFdy( surf_pos.xyz ) );\n\t\tvec3 vN = surf_norm;\n\t\tvec3 R1 = cross( vSigmaY, vN );\n\t\tvec3 R2 = cross( vN, vSigmaX );\n\t\tfloat fDet = dot( vSigmaX, R1 ) * faceDirection;\n\t\tvec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n\t\treturn normalize( abs( fDet ) * surf_norm - vGrad );\n\t}\n#endif";326327var clipping_planes_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvec4 plane;\n\t#ifdef ALPHA_TO_COVERAGE\n\t\tfloat distanceToPlane, distanceGradient;\n\t\tfloat clipOpacity = 1.0;\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n\t\t\tplane = clippingPlanes[ i ];\n\t\t\tdistanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;\n\t\t\tdistanceGradient = fwidth( distanceToPlane ) / 2.0;\n\t\t\tclipOpacity *= smoothstep( - distanceGradient, distanceGradient, distanceToPlane );\n\t\t\tif ( clipOpacity == 0.0 ) discard;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\t\t\tfloat unionClipOpacity = 1.0;\n\t\t\t#pragma unroll_loop_start\n\t\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n\t\t\t\tplane = clippingPlanes[ i ];\n\t\t\t\tdistanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;\n\t\t\t\tdistanceGradient = fwidth( distanceToPlane ) / 2.0;\n\t\t\t\tunionClipOpacity *= 1.0 - smoothstep( - distanceGradient, distanceGradient, distanceToPlane );\n\t\t\t}\n\t\t\t#pragma unroll_loop_end\n\t\t\tclipOpacity *= 1.0 - unionClipOpacity;\n\t\t#endif\n\t\tdiffuseColor.a *= clipOpacity;\n\t\tif ( diffuseColor.a == 0.0 ) discard;\n\t#else\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n\t\t\tplane = clippingPlanes[ i ];\n\t\t\tif ( dot( vClipPosition, plane.xyz ) > plane.w ) discard;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\t\t\tbool clipped = true;\n\t\t\t#pragma unroll_loop_start\n\t\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n\t\t\t\tplane = clippingPlanes[ i ];\n\t\t\t\tclipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped;\n\t\t\t}\n\t\t\t#pragma unroll_loop_end\n\t\t\tif ( clipped ) discard;\n\t\t#endif\n\t#endif\n#endif";328329var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";330331var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif";332333var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif";334335var color_fragment = "#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA )\n\tdiffuseColor *= vColor;\n#endif";336337var color_pars_fragment = "#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA )\n\tvarying vec4 vColor;\n#endif";338339var color_pars_vertex = "#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )\n\tvarying vec4 vColor;\n#endif";340341var color_vertex = "#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )\n\tvColor = vec4( 1.0 );\n#endif\n#ifdef USE_COLOR_ALPHA\n\tvColor *= color;\n#elif defined( USE_COLOR )\n\tvColor.rgb *= color;\n#endif\n#ifdef USE_INSTANCING_COLOR\n\tvColor.rgb *= instanceColor.rgb;\n#endif\n#ifdef USE_BATCHING_COLOR\n\tvColor *= getBatchingColor( getIndirectIndex( gl_DrawID ) );\n#endif";342343var common = "#define PI 3.141592653589793\n#define PI2 6.283185307179586\n#define PI_HALF 1.5707963267948966\n#define RECIPROCAL_PI 0.3183098861837907\n#define RECIPROCAL_PI2 0.15915494309189535\n#define EPSILON 1e-6\n#ifndef saturate\n#define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\n#define whiteComplement( a ) ( 1.0 - saturate( a ) )\nfloat pow2( const in float x ) { return x*x; }\nvec3 pow2( const in vec3 x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); }\nfloat average( const in vec3 v ) { return dot( v, vec3( 0.3333333 ) ); }\nhighp float rand( const in vec2 uv ) {\n\tconst highp float a = 12.9898, b = 78.233, c = 43758.5453;\n\thighp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n\treturn fract( sin( sn ) * c );\n}\n#ifdef HIGH_PRECISION\n\tfloat precisionSafeLength( vec3 v ) { return length( v ); }\n#else\n\tfloat precisionSafeLength( vec3 v ) {\n\t\tfloat maxComponent = max3( abs( v ) );\n\t\treturn length( v / maxComponent ) * maxComponent;\n\t}\n#endif\nstruct IncidentLight {\n\tvec3 color;\n\tvec3 direction;\n\tbool visible;\n};\nstruct ReflectedLight {\n\tvec3 directDiffuse;\n\tvec3 directSpecular;\n\tvec3 indirectDiffuse;\n\tvec3 indirectSpecular;\n};\n#ifdef USE_ALPHAHASH\n\tvarying vec3 vPosition;\n#endif\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\n#define inverseTransformDirection transformDirectionByInverseViewMatrix\nvec3 transformNormalByInverseViewMatrix( in vec3 normal, in mat4 viewMatrix ) {\n\treturn normalize( ( vec4( normal, 0.0 ) * viewMatrix ).xyz );\n}\nvec3 transformDirectionByInverseViewMatrix( in vec3 dir, in mat4 viewMatrix ) {\n\treturn normalize( ( vec4( dir, 0.0 ) * viewMatrix ).xyz );\n}\nbool isPerspectiveMatrix( mat4 m ) {\n\treturn m[ 2 ][ 3 ] == - 1.0;\n}\nvec2 equirectUv( in vec3 dir ) {\n\tfloat u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5;\n\tfloat v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\treturn vec2( u, v );\n}\nvec3 BRDF_Lambert( const in vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 f0, const in float f90, const in float dotVH ) {\n\tfloat fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );\n\treturn f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );\n}\nfloat F_Schlick( const in float f0, const in float f90, const in float dotVH ) {\n\tfloat fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );\n\treturn f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );\n} // validated";344345var defaultnormal_vertex = "vec3 transformedNormal = objectNormal;\n#ifdef USE_TANGENT\n\tvec3 transformedTangent = objectTangent;\n#endif\n#ifdef USE_BATCHING\n\tmat3 bm = mat3( batchingMatrix );\n\ttransformedNormal /= vec3( dot( bm[ 0 ], bm[ 0 ] ), dot( bm[ 1 ], bm[ 1 ] ), dot( bm[ 2 ], bm[ 2 ] ) );\n\ttransformedNormal = bm * transformedNormal;\n\t#ifdef USE_TANGENT\n\t\ttransformedTangent = bm * transformedTangent;\n\t#endif\n#endif\n#ifdef USE_INSTANCING\n\tmat3 im = mat3( instanceMatrix );\n\ttransformedNormal /= vec3( dot( im[ 0 ], im[ 0 ] ), dot( im[ 1 ], im[ 1 ] ), dot( im[ 2 ], im[ 2 ] ) );\n\ttransformedNormal = im * transformedNormal;\n\t#ifdef USE_TANGENT\n\t\ttransformedTangent = im * transformedTangent;\n\t#endif\n#endif\ntransformedNormal = normalMatrix * transformedNormal;\n#ifdef FLIP_SIDED\n\ttransformedNormal = - transformedNormal;\n#endif\n#ifdef USE_TANGENT\n\ttransformedTangent = ( modelViewMatrix * vec4( transformedTangent, 0.0 ) ).xyz;\n#endif";346347var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";348349var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vDisplacementMapUv ).x * displacementScale + displacementBias );\n#endif";350351var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vEmissiveMapUv );\n\t#ifdef DECODE_VIDEO_TEXTURE_EMISSIVE\n\t\temissiveColor = sRGBTransferEOTF( emissiveColor );\n\t#endif\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";352353var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";354355var colorspace_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";356357var colorspace_pars_fragment = "vec4 LinearTransferOETF( in vec4 value ) {\n\treturn value;\n}\nvec4 sRGBTransferEOTF( in vec4 value ) {\n\treturn 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 );\n}\nvec4 sRGBTransferOETF( in vec4 value ) {\n\treturn 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 );\n}";358359var envmap_fragment = "#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvec3 cameraToFrag;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToFrag = normalize( vWorldPosition - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = transformNormalByInverseViewMatrix( normal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( cameraToFrag, worldNormal );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );\n\t\t#endif\n\t#else\n\t\tvec3 reflectVec = vReflect;\n\t#endif\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 envColor = textureCube( envMap, envMapRotation * reflectVec );\n\t\t#ifdef ENVMAP_BLENDING_MULTIPLY\n\t\t\toutgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n\t\t#elif defined( ENVMAP_BLENDING_MIX )\n\t\t\toutgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n\t\t#elif defined( ENVMAP_BLENDING_ADD )\n\t\t\toutgoingLight += envColor.xyz * specularStrength * reflectivity;\n\t\t#endif\n\t#endif\n#endif";360361var envmap_common_pars_fragment = "#ifdef USE_ENVMAP\n\tuniform float envMapIntensity;\n\tuniform mat3 envMapRotation;\n\tuniform samplerCube envMap;\n\t#ifdef ENVMAP_TYPE_PMREM\n\t\tfloat roughnessToMip( const in float roughness ) {\n\t\t\tfloat r = clamp( roughness, 0.0, 1.0 );\n\t\t\treturn ENVMAP_MAX_LOD * r * ( 2.0 - r );\n\t\t}\n\t#endif\n#endif";362363var envmap_pars_fragment = "#ifdef USE_ENVMAP\n\tuniform float reflectivity;\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )\n\t\t#define ENV_WORLDPOS\n\t#endif\n\t#ifdef ENV_WORLDPOS\n\t\tvarying vec3 vWorldPosition;\n\t\tuniform float refractionRatio;\n\t#else\n\t\tvarying vec3 vReflect;\n\t#endif\n#endif";364365var envmap_pars_vertex = "#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )\n\t\t#define ENV_WORLDPOS\n\t#endif\n\t#ifdef ENV_WORLDPOS\n\t\t\n\t\tvarying vec3 vWorldPosition;\n\t#else\n\t\tvarying vec3 vReflect;\n\t\tuniform float refractionRatio;\n\t#endif\n#endif";366367var envmap_vertex = "#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvWorldPosition = worldPosition.xyz;\n\t#else\n\t\tvec3 cameraToVertex;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = transformNormalByInverseViewMatrix( transformedNormal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvReflect = reflect( cameraToVertex, worldNormal );\n\t\t#else\n\t\t\tvReflect = refract( cameraToVertex, worldNormal, refractionRatio );\n\t\t#endif\n\t#endif\n#endif";368369var fog_vertex = "#ifdef USE_FOG\n\tvFogDepth = - mvPosition.z;\n#endif";370371var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float vFogDepth;\n#endif";372373var fog_fragment = "#ifdef USE_FOG\n\t#ifdef FOG_EXP2\n\t\tfloat fogFactor = 1.0 - exp( - fogDensity * fogDensity * vFogDepth * vFogDepth );\n\t#else\n\t\tfloat fogFactor = smoothstep( fogNear, fogFar, vFogDepth );\n\t#endif\n\tgl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );\n#endif";374375var fog_pars_fragment = "#ifdef USE_FOG\n\tuniform vec3 fogColor;\n\tvarying float vFogDepth;\n\t#ifdef FOG_EXP2\n\t\tuniform float fogDensity;\n\t#else\n\t\tuniform float fogNear;\n\t\tuniform float fogFar;\n\t#endif\n#endif";376377var gradientmap_pars_fragment = "#ifdef USE_GRADIENTMAP\n\tuniform sampler2D gradientMap;\n#endif\nvec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {\n\tfloat dotNL = dot( normal, lightDirection );\n\tvec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );\n\t#ifdef USE_GRADIENTMAP\n\t\treturn vec3( texture2D( gradientMap, coord ).r );\n\t#else\n\t\tvec2 fw = fwidth( coord ) * 0.5;\n\t\treturn mix( vec3( 0.7 ), vec3( 1.0 ), smoothstep( 0.7 - fw.x, 0.7 + fw.x, coord.x ) );\n\t#endif\n}";378379var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";380381var lights_lambert_fragment = "LambertMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularStrength = specularStrength;";382383var lights_lambert_pars_fragment = "varying vec3 vViewPosition;\nstruct LambertMaterial {\n\tvec3 diffuseColor;\n\tfloat specularStrength;\n};\nvoid 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 ) {\n\tfloat dotNL = saturate( dot( geometryNormal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid 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 ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_Lambert\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Lambert";384385var lights_pars_begin = "uniform bool receiveShadow;\nuniform vec3 ambientLightColor;\n#if defined( USE_LIGHT_PROBES )\n\tuniform vec3 lightProbe[ 9 ];\n#endif\nvec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {\n\tfloat x = normal.x, y = normal.y, z = normal.z;\n\tvec3 result = shCoefficients[ 0 ] * 0.886227;\n\tresult += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;\n\tresult += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;\n\tresult += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;\n\tresult += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;\n\tresult += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;\n\tresult += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );\n\tresult += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;\n\tresult += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );\n\treturn result;\n}\nvec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in vec3 normal ) {\n\tvec3 worldNormal = transformNormalByInverseViewMatrix( normal, viewMatrix );\n\tvec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );\n\treturn irradiance;\n}\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n\tvec3 irradiance = ambientLightColor;\n\treturn irradiance;\n}\nfloat getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\tif ( cutoffDistance > 0.0 ) {\n\t\tdistanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t}\n\treturn distanceFalloff;\n}\nfloat getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) {\n\treturn smoothstep( coneCosine, penumbraCosine, angleCosine );\n}\n#if NUM_SUN_LIGHTS > 0\n\tstruct SunLight {\n\t\tvec3 direction;\n\t\tvec3 color;\n\t};\n\tuniform SunLight sunLights[ NUM_SUN_LIGHTS ];\n\tvoid getSunLightInfo( const in SunLight sunLight, out IncidentLight light ) {\n\t\tlight.color = sunLight.color;\n\t\tlight.direction = sunLight.direction;\n\t\tlight.visible = true;\n\t}\n#endif\n#if NUM_DIR_LIGHTS > 0\n\tstruct DirectionalLight {\n\t\tvec3 direction;\n\t\tvec3 color;\n\t};\n\tuniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n\tvoid getDirectionalLightInfo( const in DirectionalLight directionalLight, out IncidentLight light ) {\n\t\tlight.color = directionalLight.color;\n\t\tlight.direction = directionalLight.direction;\n\t\tlight.visible = true;\n\t}\n#endif\n#if NUM_POINT_LIGHTS > 0\n\tstruct PointLight {\n\t\tvec3 position;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t};\n\tuniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n\tvoid getPointLightInfo( const in PointLight pointLight, const in vec3 geometryPosition, out IncidentLight light ) {\n\t\tvec3 lVector = pointLight.position - geometryPosition;\n\t\tlight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tlight.color = pointLight.color;\n\t\tlight.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay );\n\t\tlight.visible = ( light.color != vec3( 0.0 ) );\n\t}\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\tstruct SpotLight {\n\t\tvec3 position;\n\t\tvec3 direction;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t\tfloat coneCos;\n\t\tfloat penumbraCos;\n\t};\n\tuniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n\tvoid getSpotLightInfo( const in SpotLight spotLight, const in vec3 geometryPosition, out IncidentLight light ) {\n\t\tvec3 lVector = spotLight.position - geometryPosition;\n\t\tlight.direction = normalize( lVector );\n\t\tfloat angleCos = dot( light.direction, spotLight.direction );\n\t\tfloat spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos );\n\t\tif ( spotAttenuation > 0.0 ) {\n\t\t\tfloat lightDistance = length( lVector );\n\t\t\tlight.color = spotLight.color * spotAttenuation;\n\t\t\tlight.color *= getDistanceAttenuation( lightDistance, spotLight.distance, spotLight.decay );\n\t\t\tlight.visible = ( light.color != vec3( 0.0 ) );\n\t\t} else {\n\t\t\tlight.color = vec3( 0.0 );\n\t\t\tlight.visible = false;\n\t\t}\n\t}\n#endif\n#if NUM_RECT_AREA_LIGHTS > 0\n\tstruct RectAreaLight {\n\t\tvec3 color;\n\t\tvec3 position;\n\t\tvec3 halfWidth;\n\t\tvec3 halfHeight;\n\t};\n\tuniform sampler2D ltc_1;\tuniform sampler2D ltc_2;\n\tuniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\tstruct HemisphereLight {\n\t\tvec3 direction;\n\t\tvec3 skyColor;\n\t\tvec3 groundColor;\n\t};\n\tuniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n\tvec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in vec3 normal ) {\n\t\tfloat dotNL = dot( normal, hemiLight.direction );\n\t\tfloat hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n\t\tvec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n\t\treturn irradiance;\n\t}\n#endif\n#include <lightprobes_pars_fragment>";386387var envmap_physical_pars_fragment = "#ifdef USE_ENVMAP\n\tvec3 getIBLIrradiance( const in vec3 normal ) {\n\t\t#ifdef ENVMAP_TYPE_PMREM\n\t\t\tvec3 worldNormal = transformNormalByInverseViewMatrix( normal, viewMatrix );\n\t\t\tvec4 envMapColor = textureLod( envMap, envMapRotation * worldNormal, ENVMAP_MAX_LOD );\n\t\t\treturn PI * envMapColor.rgb * envMapIntensity;\n\t\t#else\n\t\t\treturn vec3( 0.0 );\n\t\t#endif\n\t}\n\tvec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {\n\t\t#ifdef ENVMAP_TYPE_PMREM\n\t\t\tvec3 reflectVec = reflect( - viewDir, normal );\n\t\t\treflectVec = normalize( mix( reflectVec, normal, pow4( roughness ) ) );\n\t\t\treflectVec = transformDirectionByInverseViewMatrix( reflectVec, viewMatrix );\n\t\t\tvec4 envMapColor = textureLod( envMap, envMapRotation * reflectVec, roughnessToMip( roughness ) );\n\t\t\treturn envMapColor.rgb * envMapIntensity;\n\t\t#else\n\t\t\treturn vec3( 0.0 );\n\t\t#endif\n\t}\n\t#ifdef USE_RETROREFLECTION\n\t\tvec3 getIBLRetroRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {\n\t\t\t#ifdef ENVMAP_TYPE_PMREM\n\t\t\t\tvec3 retroVec = normalize( mix( viewDir, normal, pow4( roughness ) ) );\n\t\t\t\tretroVec = transformDirectionByInverseViewMatrix( retroVec, viewMatrix );\n\t\t\t\tvec4 envMapColor = textureLod( envMap, envMapRotation * retroVec, roughnessToMip( roughness ) );\n\t\t\t\treturn envMapColor.rgb * envMapIntensity;\n\t\t\t#else\n\t\t\t\treturn vec3( 0.0 );\n\t\t\t#endif\n\t\t}\n\t#endif\n\t#ifdef USE_ANISOTROPY\n\t\tvec3 getIBLAnisotropyRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in vec3 bitangent, const in float anisotropy ) {\n\t\t\t#ifdef ENVMAP_TYPE_PMREM\n\t\t\t\tvec3 bentNormal = cross( bitangent, viewDir );\n\t\t\t\tbentNormal = normalize( cross( bentNormal, bitangent ) );\n\t\t\t\tbentNormal = normalize( mix( bentNormal, normal, pow2( pow2( 1.0 - anisotropy * ( 1.0 - roughness ) ) ) ) );\n\t\t\t\treturn getIBLRadiance( viewDir, bentNormal, roughness );\n\t\t\t#else\n\t\t\t\treturn vec3( 0.0 );\n\t\t\t#endif\n\t\t}\n\t\t#ifdef USE_RETROREFLECTION\n\t\t\tvec3 getIBLAnisotropyRetroRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in vec3 bitangent, const in float anisotropy ) {\n\t\t\t\t#ifdef ENVMAP_TYPE_PMREM\n\t\t\t\t\tvec3 bentNormal = cross( bitangent, viewDir );\n\t\t\t\t\tbentNormal = normalize( cross( bentNormal, bitangent ) );\n\t\t\t\t\tbentNormal = normalize( mix( bentNormal, normal, pow2( pow2( 1.0 - anisotropy * ( 1.0 - roughness ) ) ) ) );\n\t\t\t\t\treturn getIBLRetroRadiance( viewDir, bentNormal, roughness );\n\t\t\t\t#else\n\t\t\t\t\treturn vec3( 0.0 );\n\t\t\t\t#endif\n\t\t\t}\n\t\t#endif\n\t#endif\n#endif";388389var lights_toon_fragment = "ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;";390391var lights_toon_pars_fragment = "varying vec3 vViewPosition;\nstruct ToonMaterial {\n\tvec3 diffuseColor;\n};\nvoid 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 ) {\n\tvec3 irradiance = getGradientIrradiance( geometryNormal, directLight.direction ) * directLight.color;\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid 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 ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_Toon\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Toon";392393var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";394395var lights_phong_pars_fragment = "varying vec3 vViewPosition;\nstruct BlinnPhongMaterial {\n\tvec3 diffuseColor;\n\tvec3 specularColor;\n\tfloat specularShininess;\n\tfloat specularStrength;\n};\nvoid 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 ) {\n\tfloat dotNL = saturate( dot( geometryNormal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n\treflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometryViewDir, geometryNormal, material.specularColor, material.specularShininess ) * material.specularStrength;\n}\nvoid 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 ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_BlinnPhong\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_BlinnPhong";396397var lights_physical_fragment = "PhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.diffuseContribution = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nmaterial.metalness = metalnessFactor;\nvec3 dxy = max( abs( dFdx( nonPerturbedNormal ) ), abs( dFdy( nonPerturbedNormal ) ) );\nfloat geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );\nmaterial.roughness = max( roughnessFactor, 0.045 );\nmaterial.roughness += geometryRoughness;\nmaterial.roughness = min( material.roughness, 1.0 );\n#ifdef USE_DIFFUSE_ROUGHNESS\n\tfloat diffuseRoughnessFactor = diffuseRoughness;\n\t#ifdef USE_DIFFUSE_ROUGHNESSMAP\n\t\tdiffuseRoughnessFactor *= texture2D( diffuseRoughnessMap, vDiffuseRoughnessMapUv ).r;\n\t#endif\n\tmaterial.diffuseRoughness = saturate( diffuseRoughnessFactor );\n#endif\n#ifdef IOR\n\tmaterial.ior = ior;\n\t#ifdef USE_SPECULAR\n\t\tfloat specularIntensityFactor = specularIntensity;\n\t\tvec3 specularColorFactor = specularColor;\n\t\t#ifdef USE_SPECULAR_COLORMAP\n\t\t\tspecularColorFactor *= texture2D( specularColorMap, vSpecularColorMapUv ).rgb;\n\t\t#endif\n\t\t#ifdef USE_SPECULAR_INTENSITYMAP\n\t\t\tspecularIntensityFactor *= texture2D( specularIntensityMap, vSpecularIntensityMapUv ).a;\n\t\t#endif\n\t\tmaterial.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor );\n\t#else\n\t\tfloat specularIntensityFactor = 1.0;\n\t\tvec3 specularColorFactor = vec3( 1.0 );\n\t\tmaterial.specularF90 = 1.0;\n\t#endif\n\tmaterial.specularColor = min( pow2( ( material.ior - 1.0 ) / ( material.ior + 1.0 ) ) * specularColorFactor, vec3( 1.0 ) ) * specularIntensityFactor;\n\tmaterial.specularColorBlended = mix( material.specularColor, diffuseColor.rgb, metalnessFactor );\n#else\n\tmaterial.specularColor = vec3( 0.04 );\n\tmaterial.specularColorBlended = mix( material.specularColor, diffuseColor.rgb, metalnessFactor );\n\tmaterial.specularF90 = 1.0;\n#endif\n#ifdef USE_CLEARCOAT\n\tmaterial.clearcoat = clearcoat;\n\tmaterial.clearcoatRoughness = clearcoatRoughness;\n\tmaterial.clearcoatF0 = vec3( 0.04 );\n\tmaterial.clearcoatF90 = 1.0;\n\t#ifdef USE_CLEARCOATMAP\n\t\tmaterial.clearcoat *= texture2D( clearcoatMap, vClearcoatMapUv ).x;\n\t#endif\n\t#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\t\tmaterial.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vClearcoatRoughnessMapUv ).y;\n\t#endif\n\tmaterial.clearcoat = saturate( material.clearcoat );\tmaterial.clearcoatRoughness = max( material.clearcoatRoughness, 0.045 );\n\tmaterial.clearcoatRoughness += geometryRoughness;\n\tmaterial.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );\n#endif\n#ifdef USE_DISPERSION\n\tmaterial.dispersion = dispersion;\n#endif\n#ifdef USE_RETROREFLECTION\n\tmaterial.retroreflectivity = retroreflectivity;\n#endif\n#ifdef USE_IRIDESCENCE\n\tmaterial.iridescence = iridescence;\n\tmaterial.iridescenceIOR = iridescenceIOR;\n\t#ifdef USE_IRIDESCENCEMAP\n\t\tmaterial.iridescence *= texture2D( iridescenceMap, vIridescenceMapUv ).r;\n\t#endif\n\t#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\t\tmaterial.iridescenceThickness = (iridescenceThicknessMaximum - iridescenceThicknessMinimum) * texture2D( iridescenceThicknessMap, vIridescenceThicknessMapUv ).g + iridescenceThicknessMinimum;\n\t#else\n\t\tmaterial.iridescenceThickness = iridescenceThicknessMaximum;\n\t#endif\n#endif\n#ifdef USE_SHEEN\n\tmaterial.sheenColor = sheenColor;\n\t#ifdef USE_SHEEN_COLORMAP\n\t\tmaterial.sheenColor *= texture2D( sheenColorMap, vSheenColorMapUv ).rgb;\n\t#endif\n\tmaterial.sheenRoughness = clamp( sheenRoughness, 0.0001, 1.0 );\n\t#ifdef USE_SHEEN_ROUGHNESSMAP\n\t\tmaterial.sheenRoughness *= texture2D( sheenRoughnessMap, vSheenRoughnessMapUv ).a;\n\t#endif\n#endif\n#ifdef USE_ANISOTROPY\n\t#ifdef USE_ANISOTROPYMAP\n\t\tmat2 anisotropyMat = mat2( anisotropyVector.x, anisotropyVector.y, - anisotropyVector.y, anisotropyVector.x );\n\t\tvec3 anisotropyPolar = texture2D( anisotropyMap, vAnisotropyMapUv ).rgb;\n\t\tvec2 anisotropyV = anisotropyMat * normalize( 2.0 * anisotropyPolar.rg - vec2( 1.0 ) ) * anisotropyPolar.b;\n\t#else\n\t\tvec2 anisotropyV = anisotropyVector;\n\t#endif\n\tmaterial.anisotropy = length( anisotropyV );\n\tif( material.anisotropy == 0.0 ) {\n\t\tanisotropyV = vec2( 1.0, 0.0 );\n\t} else {\n\t\tanisotropyV /= material.anisotropy;\n\t\tmaterial.anisotropy = saturate( material.anisotropy );\n\t}\n\tmaterial.alphaT = mix( pow2( material.roughness ), 1.0, pow2( material.anisotropy ) );\n\tmaterial.anisotropyT = tbn[ 0 ] * anisotropyV.x + tbn[ 1 ] * anisotropyV.y;\n\tmaterial.anisotropyB = tbn[ 1 ] * anisotropyV.x - tbn[ 0 ] * anisotropyV.y;\n#endif";398399var lights_physical_pars_fragment = "uniform sampler2D dfgLUT;\nstruct PhysicalMaterial {\n\tvec3 diffuseColor;\n\tvec3 diffuseContribution;\n\tvec3 specularColor;\n\tvec3 specularColorBlended;\n\tfloat roughness;\n\tfloat metalness;\n\tfloat specularF90;\n\tfloat dispersion;\n\tvec2 dfg;\n\tvec3 multiScatteringCompensation;\n\t#ifdef USE_DIFFUSE_ROUGHNESS\n\t\tfloat diffuseRoughness;\n\t#endif\n\t#ifdef USE_RETROREFLECTION\n\t\tfloat retroreflectivity;\n\t#endif\n\t#ifdef USE_CLEARCOAT\n\t\tfloat clearcoat;\n\t\tfloat clearcoatRoughness;\n\t\tvec3 clearcoatF0;\n\t\tfloat clearcoatF90;\n\t#endif\n\t#ifdef USE_IRIDESCENCE\n\t\tfloat iridescence;\n\t\tfloat iridescenceIOR;\n\t\tfloat iridescenceThickness;\n\t\tvec3 iridescenceFresnel;\n\t\tvec3 iridescenceF0Dielectric;\n\t\tvec3 iridescenceF0Metallic;\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tvec3 sheenColor;\n\t\tfloat sheenRoughness;\n\t#endif\n\t#ifdef IOR\n\t\tfloat ior;\n\t#endif\n\t#ifdef USE_TRANSMISSION\n\t\tfloat transmission;\n\t\tfloat transmissionAlpha;\n\t\tfloat thickness;\n\t\tfloat attenuationDistance;\n\t\tvec3 attenuationColor;\n\t#endif\n\t#ifdef USE_ANISOTROPY\n\t\tfloat anisotropy;\n\t\tfloat alphaT;\n\t\tvec3 anisotropyT;\n\t\tvec3 anisotropyB;\n\t#endif\n};\nvec3 clearcoatSpecularDirect = vec3( 0.0 );\nvec3 clearcoatSpecularIndirect = vec3( 0.0 );\nvec3 sheenSpecularDirect = vec3( 0.0 );\nvec3 sheenSpecularIndirect = vec3(0.0 );\nvec3 Schlick_to_F0( const in vec3 f, const in float f90, const in float dotVH ) {\n float x = clamp( 1.0 - dotVH, 0.0, 1.0 );\n float x2 = x * x;\n float x5 = clamp( x * x2 * x2, 0.0, 0.9999 );\n return ( f - vec3( f90 ) * x5 ) / ( 1.0 - x5 );\n}\n#ifdef USE_DIFFUSE_ROUGHNESS\n\tconst float EON_EPSILON = 1e-7;\n\tfloat FON_DirectionalAlbedo( const in float mu, const in float roughness, const in float A ) {\n\t\tfloat muComp = 1.0 - mu;\n\t\tfloat gOverPi = muComp * ( 0.0571085289 + muComp * ( 0.491881867 + muComp * ( - 0.332181442 + muComp * 0.0714429953 ) ) );\n\t\treturn A * ( 1.0 + roughness * gOverPi );\n\t}\n\tvec3 BRDF_EON( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in vec3 diffuseColor, const in float roughness ) {\n\t\tvec3 rho = saturate( diffuseColor );\n\t\tif ( roughness <= EON_EPSILON ) return BRDF_Lambert( rho );\n\t\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\t\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\t\tfloat s = dot( lightDir, viewDir ) - dotNL * dotNV;\n\t\tfloat sOverT = ( s > 0.0 ) ? s / max( max( dotNL, dotNV ), EON_EPSILON ) : s;\n\t\tfloat A = 1.0 / ( 1.0 + ( 0.5 - 2.0 / ( 3.0 * PI ) ) * roughness );\n\t\tvec3 singleScatter = rho * RECIPROCAL_PI * A * ( 1.0 + roughness * sOverT );\n\t\tfloat averageAlbedo = A * ( 1.0 + ( 2.0 / 3.0 - 28.0 / ( 15.0 * PI ) ) * roughness );\n\t\tfloat albedoV = FON_DirectionalAlbedo( dotNV, roughness, A );\n\t\tfloat albedoL = FON_DirectionalAlbedo( dotNL, roughness, A );\n\t\tvec3 rhoMultiScatter = rho * rho * averageAlbedo / max( vec3( EON_EPSILON ), vec3( 1.0 ) - rho * ( 1.0 - averageAlbedo ) );\n\t\tvec3 multiScatter = rhoMultiScatter * RECIPROCAL_PI\n\t\t\t* max( EON_EPSILON, 1.0 - albedoV )\n\t\t\t* max( EON_EPSILON, 1.0 - albedoL )\n\t\t\t/ max( EON_EPSILON, 1.0 - averageAlbedo );\n\t\treturn singleScatter + multiScatter;\n\t}\n\tvec3 EON_DirectionalAlbedo( const in vec3 diffuseColor, const in float roughness, const in float dotNV ) {\n\t\tvec3 rho = saturate( diffuseColor );\n\t\tif ( roughness <= EON_EPSILON ) return rho;\n\t\tfloat A = 1.0 / ( 1.0 + ( 0.5 - 2.0 / ( 3.0 * PI ) ) * roughness );\n\t\tfloat directionalAlbedo = FON_DirectionalAlbedo( dotNV, roughness, A );\n\t\tfloat averageAlbedo = A * ( 1.0 + ( 2.0 / 3.0 - 28.0 / ( 15.0 * PI ) ) * roughness );\n\t\tvec3 rhoMultiScatter = rho * rho * averageAlbedo / max( vec3( EON_EPSILON ), vec3( 1.0 ) - rho * ( 1.0 - averageAlbedo ) );\n\t\treturn rho * directionalAlbedo + rhoMultiScatter * ( 1.0 - directionalAlbedo );\n\t}\n#endif\nfloat V_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\treturn 0.5 / max( gv + gl, EPSILON );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n\tfloat a2 = pow2( alpha );\n\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;\n\treturn RECIPROCAL_PI * a2 / pow2( denom );\n}\n#ifdef USE_ANISOTROPY\n\tfloat 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 ) {\n\t\tfloat gv = dotNL * length( vec3( alphaT * dotTV, alphaB * dotBV, dotNV ) );\n\t\tfloat gl = dotNV * length( vec3( alphaT * dotTL, alphaB * dotBL, dotNL ) );\n\t\treturn 0.5 / max( gv + gl, EPSILON );\n\t}\n\tfloat D_GGX_Anisotropic( const in float alphaT, const in float alphaB, const in float dotNH, const in float dotTH, const in float dotBH ) {\n\t\tfloat a2 = alphaT * alphaB;\n\t\thighp vec3 v = vec3( alphaB * dotTH, alphaT * dotBH, a2 * dotNH );\n\t\thighp float v2 = dot( v, v );\n\t\tfloat w2 = a2 / v2;\n\t\treturn RECIPROCAL_PI * a2 * pow2 ( w2 );\n\t}\n#endif\n#ifdef USE_CLEARCOAT\n\tvec3 BRDF_GGX_Clearcoat( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material) {\n\t\tvec3 f0 = material.clearcoatF0;\n\t\tfloat f90 = material.clearcoatF90;\n\t\tfloat roughness = max( material.clearcoatRoughness, 0.045 );\n\t\tfloat alpha = pow2( roughness );\n\t\tvec3 halfDir = normalize( lightDir + viewDir );\n\t\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\t\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\t\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\t\tfloat dotVH = saturate( dot( viewDir, halfDir ) );\n\t\tvec3 F = F_Schlick( f0, f90, dotVH );\n\t\tfloat V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\t\tfloat D = D_GGX( alpha, dotNH );\n\t\treturn F * ( V * D );\n\t}\n#endif\nvec3 BRDF_GGX( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) {\n\tvec3 f0 = material.specularColorBlended;\n\tfloat f90 = material.specularF90;\n\tfloat roughness = max( material.roughness, 0.045 );\n\tfloat alpha = pow2( roughness );\n\tvec3 halfDir = normalize( lightDir + viewDir );\n\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat dotVH = saturate( dot( viewDir, halfDir ) );\n\tvec3 F = F_Schlick( f0, f90, dotVH );\n\t#ifdef USE_IRIDESCENCE\n\t\tF = mix( F, material.iridescenceFresnel, material.iridescence );\n\t#endif\n\t#ifdef USE_ANISOTROPY\n\t\tfloat dotTL = dot( material.anisotropyT, lightDir );\n\t\tfloat dotTV = dot( material.anisotropyT, viewDir );\n\t\tfloat dotTH = dot( material.anisotropyT, halfDir );\n\t\tfloat dotBL = dot( material.anisotropyB, lightDir );\n\t\tfloat dotBV = dot( material.anisotropyB, viewDir );\n\t\tfloat dotBH = dot( material.anisotropyB, halfDir );\n\t\tfloat alphaT = max( material.alphaT, alpha );\n\t\tfloat V = V_GGX_SmithCorrelated_Anisotropic( alphaT, alpha, dotTV, dotBV, dotTL, dotBL, dotNV, dotNL );\n\t\tfloat D = D_GGX_Anisotropic( alphaT, alpha, dotNH, dotTH, dotBH );\n\t#else\n\t\tfloat V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\t\tfloat D = D_GGX( alpha, dotNH );\n\t#endif\n\treturn F * ( V * D );\n}\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\n\tconst float LUT_SIZE = 64.0;\n\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\n\tfloat dotNV = saturate( dot( N, V ) );\n\tvec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );\n\tuv = uv * LUT_SCALE + LUT_BIAS;\n\treturn uv;\n}\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\n\tfloat l = length( f );\n\treturn max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\n}\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\n\tfloat x = dot( v1, v2 );\n\tfloat y = abs( x );\n\tfloat a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;\n\tfloat b = 3.4175940 + ( 4.1616724 + y ) * y;\n\tfloat v = a / b;\n\tfloat theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;\n\treturn cross( v1, v2 ) * theta_sintheta;\n}\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\n\tvec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\n\tvec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\n\tvec3 lightNormal = cross( v1, v2 );\n\tif( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\n\tvec3 T1, T2;\n\tT1 = normalize( V - N * dot( V, N ) );\n\tT2 = - cross( N, T1 );\n\tmat3 mat = mInv * transpose( mat3( T1, T2, N ) );\n\tvec3 coords[ 4 ];\n\tcoords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\n\tcoords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\n\tcoords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\n\tcoords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\n\tcoords[ 0 ] = normalize( coords[ 0 ] );\n\tcoords[ 1 ] = normalize( coords[ 1 ] );\n\tcoords[ 2 ] = normalize( coords[ 2 ] );\n\tcoords[ 3 ] = normalize( coords[ 3 ] );\n\tvec3 vectorFormFactor = vec3( 0.0 );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\n\tfloat result = LTC_ClippedSphereFormFactor( vectorFormFactor );\n\treturn vec3( result );\n}\n#if defined( USE_SHEEN )\nfloat D_Charlie( float roughness, float dotNH ) {\n\tfloat alpha = pow2( roughness );\n\tfloat invAlpha = 1.0 / alpha;\n\tfloat cos2h = dotNH * dotNH;\n\tfloat sin2h = max( 1.0 - cos2h, 0.0078125 );\n\treturn ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI );\n}\nfloat V_Neubelt( float dotNV, float dotNL ) {\n\treturn saturate( 1.0 / ( 4.0 * ( dotNL + dotNV - dotNL * dotNV ) ) );\n}\nvec3 BRDF_Sheen( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, vec3 sheenColor, const in float sheenRoughness ) {\n\tvec3 halfDir = normalize( lightDir + viewDir );\n\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat D = D_Charlie( sheenRoughness, dotNH );\n\tfloat V = V_Neubelt( dotNV, dotNL );\n\treturn sheenColor * ( D * V );\n}\n#endif\nfloat IBLSheenBRDF( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat r2 = roughness * roughness;\n\tfloat rInv = 1.0 / ( roughness + 0.1 );\n\tfloat a = -1.9362 + 1.0678 * roughness + 0.4573 * r2 - 0.8469 * rInv;\n\tfloat b = -0.6014 + 0.5538 * roughness - 0.4670 * r2 - 0.1255 * rInv;\n\tfloat DG = exp( a * dotNV + b );\n\treturn saturate( DG );\n}\nvec3 EnvironmentBRDF( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness ) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tvec2 fab = texture2D( dfgLUT, vec2( roughness, dotNV ) ).rg;\n\treturn specularColor * fab.x + specularF90 * fab.y;\n}\n#ifdef USE_IRIDESCENCE\nvoid computeMultiscatteringIridescence( const in vec2 fab, const in vec3 specularColor, const in float specularF90, const in float iridescence, const in vec3 iridescenceF0, inout vec3 singleScatter, inout vec3 multiScatter ) {\n#else\nvoid computeMultiscattering( const in vec2 fab, const in vec3 specularColor, const in float specularF90, inout vec3 singleScatter, inout vec3 multiScatter ) {\n#endif\n\t#ifdef USE_IRIDESCENCE\n\t\tvec3 Fr = mix( specularColor, iridescenceF0, iridescence );\n\t#else\n\t\tvec3 Fr = specularColor;\n\t#endif\n\tvec3 FssEss = Fr * fab.x + specularF90 * fab.y;\n\tfloat Ess = fab.x + fab.y;\n\tfloat Ems = 1.0 - Ess;\n\tvec3 Favg = Fr + ( 1.0 - Fr ) * 0.047619;\tvec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );\n\tsingleScatter += FssEss;\n\tmultiScatter += Fms * Ems;\n}\n#if NUM_RECT_AREA_LIGHTS > 0\n\tvoid 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 ) {\n\t\tvec3 normal = geometryNormal;\n\t\tvec3 viewDir = geometryViewDir;\n\t\tvec3 position = geometryPosition;\n\t\tvec3 lightPos = rectAreaLight.position;\n\t\tvec3 halfWidth = rectAreaLight.halfWidth;\n\t\tvec3 halfHeight = rectAreaLight.halfHeight;\n\t\tvec3 lightColor = rectAreaLight.color;\n\t\tfloat roughness = material.roughness;\n\t\tvec3 rectCoords[ 4 ];\n\t\trectCoords[ 0 ] = lightPos + halfWidth - halfHeight;\t\trectCoords[ 1 ] = lightPos - halfWidth - halfHeight;\n\t\trectCoords[ 2 ] = lightPos - halfWidth + halfHeight;\n\t\trectCoords[ 3 ] = lightPos + halfWidth + halfHeight;\n\t\tvec2 uv = LTC_Uv( normal, viewDir, roughness );\n\t\tvec4 t1 = texture2D( ltc_1, uv );\n\t\tvec4 t2 = texture2D( ltc_2, uv );\n\t\tmat3 mInv = mat3(\n\t\t\tvec3( t1.x, 0, t1.y ),\n\t\t\tvec3( 0, 1, 0 ),\n\t\t\tvec3( t1.z, 0, t1.w )\n\t\t);\n\t\tvec3 fresnel = ( material.specularColorBlended * t2.x + ( material.specularF90 - material.specularColorBlended ) * t2.y );\n\t\treflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );\n\t\treflectedLight.directDiffuse += lightColor * material.diffuseContribution * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );\n\t\t#ifdef USE_CLEARCOAT\n\t\t\tvec3 Ncc = geometryClearcoatNormal;\n\t\t\tvec2 uvClearcoat = LTC_Uv( Ncc, viewDir, material.clearcoatRoughness );\n\t\t\tvec4 t1Clearcoat = texture2D( ltc_1, uvClearcoat );\n\t\t\tvec4 t2Clearcoat = texture2D( ltc_2, uvClearcoat );\n\t\t\tmat3 mInvClearcoat = mat3(\n\t\t\t\tvec3( t1Clearcoat.x, 0, t1Clearcoat.y ),\n\t\t\t\tvec3( 0, 1, 0 ),\n\t\t\t\tvec3( t1Clearcoat.z, 0, t1Clearcoat.w )\n\t\t\t);\n\t\t\tvec3 fresnelClearcoat = material.clearcoatF0 * t2Clearcoat.x + ( material.clearcoatF90 - material.clearcoatF0 ) * t2Clearcoat.y;\n\t\t\tclearcoatSpecularDirect += lightColor * fresnelClearcoat * LTC_Evaluate( Ncc, viewDir, position, mInvClearcoat, rectCoords );\n\t\t#endif\n\t}\n#endif\nvoid 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 ) {\n\tfloat dotNL = saturate( dot( geometryNormal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\t#ifdef USE_CLEARCOAT\n\t\tfloat dotNLcc = saturate( dot( geometryClearcoatNormal, directLight.direction ) );\n\t\tvec3 ccIrradiance = dotNLcc * directLight.color;\n\t\tclearcoatSpecularDirect += ccIrradiance * BRDF_GGX_Clearcoat( directLight.direction, geometryViewDir, geometryClearcoatNormal, material );\n\t#endif\n\t#ifdef USE_SHEEN\n \n \t\tsheenSpecularDirect += irradiance * BRDF_Sheen( directLight.direction, geometryViewDir, geometryNormal, material.sheenColor, material.sheenRoughness );\n \n \t\tfloat sheenAlbedoV = IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );\n \t\tfloat sheenAlbedoL = IBLSheenBRDF( geometryNormal, directLight.direction, material.sheenRoughness );\n \n \t\tfloat sheenEnergyComp = 1.0 - max3( material.sheenColor ) * max( sheenAlbedoV, sheenAlbedoL );\n \n \t\tirradiance *= sheenEnergyComp;\n \n \t#endif\n\tvec3 specularBRDF = BRDF_GGX( directLight.direction, geometryViewDir, geometryNormal, material );\n\t#ifdef USE_RETROREFLECTION\n\t\tvec3 retroViewDir = reflect( - geometryViewDir, geometryNormal );\n\t\tvec3 retroSpecularBRDF = BRDF_GGX( directLight.direction, retroViewDir, geometryNormal, material );\n\t\tspecularBRDF = mix( specularBRDF, retroSpecularBRDF, saturate( material.retroreflectivity ) );\n\t#endif\n\treflectedLight.directSpecular += irradiance * specularBRDF * material.multiScatteringCompensation;\n\tvec3 halfDir = normalize( directLight.direction + geometryViewDir );\n\tfloat dotVH = saturate( dot( geometryViewDir, halfDir ) );\n\tvec3 F = F_Schlick( material.specularColor, material.specularF90, dotVH );\n\t#ifdef USE_RETROREFLECTION\n\t\tvec3 retroHalfDir = normalize( directLight.direction + retroViewDir );\n\t\tfloat dotRetroVH = saturate( dot( retroViewDir, retroHalfDir ) );\n\t\tvec3 retroF = F_Schlick( material.specularColor, material.specularF90, dotRetroVH );\n\t\tF = mix( F, retroF, saturate( material.retroreflectivity ) );\n\t#endif\n\t#ifdef USE_DIFFUSE_ROUGHNESS\n\t\tvec3 diffuseBRDF = BRDF_EON( directLight.direction, geometryViewDir, geometryNormal, material.diffuseColor, material.diffuseRoughness ) * ( 1.0 - material.metalness );\n\t#else\n\t\tvec3 diffuseBRDF = BRDF_Lambert( material.diffuseContribution );\n\t#endif\n\treflectedLight.directDiffuse += irradiance * diffuseBRDF * ( 1.0 - F );\n}\nvoid 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 ) {\n\tvec3 singleScattering = vec3( 0.0 );\n\tvec3 multiScattering = vec3( 0.0 );\n\t#ifdef USE_IRIDESCENCE\n\t\tcomputeMultiscatteringIridescence( material.dfg, material.specularColor, material.specularF90, material.iridescence, material.iridescenceF0Dielectric, singleScattering, multiScattering );\n\t#else\n\t\tcomputeMultiscattering( material.dfg, material.specularColor, material.specularF90, singleScattering, multiScattering );\n\t#endif\n\t#ifdef USE_DIFFUSE_ROUGHNESS\n\t\tfloat dotNV = saturate( dot( geometryNormal, geometryViewDir ) );\n\t\tvec3 diffuseAlbedo = EON_DirectionalAlbedo( material.diffuseColor, material.diffuseRoughness, dotNV ) * ( 1.0 - material.metalness );\n\t\tvec3 diffuse = irradiance * RECIPROCAL_PI * diffuseAlbedo * ( 1.0 - singleScattering - multiScattering );\n\t#else\n\t\tvec3 diffuse = irradiance * BRDF_Lambert( material.diffuseContribution ) * ( 1.0 - singleScattering - multiScattering );\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tfloat sheenAlbedo = IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );\n\t\tsheenSpecularIndirect += irradiance * material.sheenColor * sheenAlbedo * RECIPROCAL_PI;\n\t\tfloat sheenEnergyComp = 1.0 - max3( material.sheenColor ) * sheenAlbedo;\n\t\tdiffuse *= sheenEnergyComp;\n\t#endif\n\treflectedLight.indirectDiffuse += diffuse;\n}\nvoid 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) {\n\t#ifdef USE_CLEARCOAT\n\t\tclearcoatSpecularIndirect += clearcoatRadiance * EnvironmentBRDF( geometryClearcoatNormal, geometryViewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tsheenSpecularIndirect += irradiance * material.sheenColor * IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness ) * RECIPROCAL_PI;\n \t#endif\n\tvec3 singleScatteringDielectric = vec3( 0.0 );\n\tvec3 multiScatteringDielectric = vec3( 0.0 );\n\tvec3 singleScatteringMetallic = vec3( 0.0 );\n\tvec3 multiScatteringMetallic = vec3( 0.0 );\n\t#ifdef USE_IRIDESCENCE\n\t\tcomputeMultiscatteringIridescence( material.dfg, material.specularColor, material.specularF90, material.iridescence, material.iridescenceF0Dielectric, singleScatteringDielectric, multiScatteringDielectric );\n\t\tcomputeMultiscatteringIridescence( material.dfg, material.diffuseColor, material.specularF90, material.iridescence, material.iridescenceF0Metallic, singleScatteringMetallic, multiScatteringMetallic );\n\t#else\n\t\tcomputeMultiscattering( material.dfg, material.specularColor, material.specularF90, singleScatteringDielectric, multiScatteringDielectric );\n\t\tcomputeMultiscattering( material.dfg, material.diffuseColor, material.specularF90, singleScatteringMetallic, multiScatteringMetallic );\n\t#endif\n\tvec3 singleScattering = mix( singleScatteringDielectric, singleScatteringMetallic, material.metalness );\n\tvec3 multiScattering = mix( multiScatteringDielectric, multiScatteringMetallic, material.metalness );\n\tvec3 totalScatteringDielectric = singleScatteringDielectric + multiScatteringDielectric;\n\t#ifdef USE_DIFFUSE_ROUGHNESS\n\t\tfloat dotNV = saturate( dot( geometryNormal, geometryViewDir ) );\n\t\tvec3 diffuse = EON_DirectionalAlbedo( material.diffuseColor, material.diffuseRoughness, dotNV ) * ( 1.0 - material.metalness ) * ( 1.0 - totalScatteringDielectric );\n\t#else\n\t\tvec3 diffuse = material.diffuseContribution * ( 1.0 - totalScatteringDielectric );\n\t#endif\n\tvec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;\n\tvec3 indirectSpecular = radiance * singleScattering;\n\tindirectSpecular += multiScattering * cosineWeightedIrradiance;\n\tvec3 indirectDiffuse = diffuse * cosineWeightedIrradiance;\n\t#ifdef USE_SHEEN\n\t\tfloat sheenAlbedo = IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );\n\t\tfloat sheenEnergyComp = 1.0 - max3( material.sheenColor ) * sheenAlbedo;\n\t\tindirectSpecular *= sheenEnergyComp;\n\t\tindirectDiffuse *= sheenEnergyComp;\n\t#endif\n\treflectedLight.indirectSpecular += indirectSpecular;\n\treflectedLight.indirectDiffuse += indirectDiffuse;\n}\n#define RE_Direct\t\t\t\tRE_Direct_Physical\n#define RE_Direct_RectArea\t\tRE_Direct_RectArea_Physical\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Physical\n#define RE_IndirectSpecular\t\tRE_IndirectSpecular_Physical\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\n\treturn saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n}";400401var lights_fragment_begin = "\nvec3 geometryPosition = - vViewPosition;\nvec3 geometryNormal = normal;\nvec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\nvec3 geometryClearcoatNormal = vec3( 0.0 );\n#ifdef USE_CLEARCOAT\n\tgeometryClearcoatNormal = clearcoatNormal;\n#endif\n#ifdef USE_IRIDESCENCE\n\tfloat dotNVi = saturate( dot( normal, geometryViewDir ) );\n\tif ( material.iridescenceThickness == 0.0 ) {\n\t\tmaterial.iridescence = 0.0;\n\t} else {\n\t\tmaterial.iridescence = saturate( material.iridescence );\n\t}\n\tif ( material.iridescence > 0.0 ) {\n\t\tvec3 iridescenceFresnelDielectric = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.specularColor );\n\t\tvec3 iridescenceFresnelMetallic = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.diffuseColor );\n\t\tmaterial.iridescenceFresnel = mix( iridescenceFresnelDielectric, iridescenceFresnelMetallic, material.metalness );\n\t\tmaterial.iridescenceF0Dielectric = Schlick_to_F0( iridescenceFresnelDielectric, 1.0, dotNVi );\n\t\tmaterial.iridescenceF0Metallic = Schlick_to_F0( iridescenceFresnelMetallic, 1.0, dotNVi );\n\t}\n#endif\n#ifdef STANDARD\n\tfloat dotNVms = saturate( dot( geometryNormal, geometryViewDir ) );\n\tmaterial.dfg = texture2D( dfgLUT, vec2( material.roughness, dotNVms ) ).rg;\n\t#if ( NUM_SUN_LIGHTS > 0 || NUM_DIR_LIGHTS > 0 || NUM_POINT_LIGHTS > 0 || NUM_SPOT_LIGHTS > 0 )\n\t\tfloat EssMs = material.dfg.x + material.dfg.y;\n\t\tmaterial.multiScatteringCompensation = 1.0 + material.specularColorBlended * ( 1.0 / EssMs - 1.0 );\n\t#endif\n#endif\nIncidentLight directLight;\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\tPointLight pointLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tgetPointLightInfo( pointLight, geometryPosition, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS ) && ( defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_BASIC ) )\n\t\tpointLightShadow = pointLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowIntensity, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n\tSpotLight spotLight;\n\tvec4 spotColor;\n\tvec3 spotLightCoord;\n\tbool inSpotLightMap;\n\t#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tspotLight = spotLights[ i ];\n\t\tgetSpotLightInfo( spotLight, geometryPosition, directLight );\n\t\t#if ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )\n\t\t#define SPOT_LIGHT_MAP_INDEX UNROLLED_LOOP_INDEX\n\t\t#elif ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\t#define SPOT_LIGHT_MAP_INDEX NUM_SPOT_LIGHT_MAPS\n\t\t#else\n\t\t#define SPOT_LIGHT_MAP_INDEX ( UNROLLED_LOOP_INDEX - NUM_SPOT_LIGHT_SHADOWS + NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )\n\t\t#endif\n\t\t#if ( SPOT_LIGHT_MAP_INDEX < NUM_SPOT_LIGHT_MAPS )\n\t\t\tspotLightCoord = vSpotLightCoord[ i ].xyz / vSpotLightCoord[ i ].w;\n\t\t\tinSpotLightMap = all( lessThan( abs( spotLightCoord * 2. - 1. ), vec3( 1.0 ) ) );\n\t\t\tspotColor = texture2D( spotLightMap[ SPOT_LIGHT_MAP_INDEX ], spotLightCoord.xy );\n\t\t\tdirectLight.color = inSpotLightMap ? directLight.color * spotColor.rgb : directLight.color;\n\t\t#endif\n\t\t#undef SPOT_LIGHT_MAP_INDEX\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\tspotLightShadow = spotLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_SUN_LIGHTS > 0 ) && defined( RE_Direct )\n\tSunLight sunLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_SUN_LIGHT_SHADOWS > 0\n\tSunLightShadow sunLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SUN_LIGHTS; i ++ ) {\n\t\tsunLight = sunLights[ i ];\n\t\tgetSunLightInfo( sunLight, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SUN_LIGHT_SHADOWS )\n\t\tsunLightShadow = sunLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getSunShadow( sunShadowMap[ i ], sunLightShadow, UNROLLED_LOOP_INDEX ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n\tDirectionalLight directionalLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tgetDirectionalLightInfo( directionalLight, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n\tRectAreaLight rectAreaLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n\t\trectAreaLight = rectAreaLights[ i ];\n\t\tRE_Direct_RectArea( rectAreaLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if defined( RE_IndirectDiffuse )\n\tvec3 iblIrradiance = vec3( 0.0 );\n\tvec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\t#if defined( USE_LIGHT_PROBES )\n\t\tirradiance += getLightProbeIrradiance( lightProbe, geometryNormal );\n\t#endif\n\t#if ( NUM_HEMI_LIGHTS > 0 )\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\t\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal );\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_LIGHT_PROBE_GRIDS > 0\n\t\tvec3 probeWorldPos = ( ( vec4( geometryPosition, 1.0 ) - viewMatrix[ 3 ] ) * viewMatrix ).xyz;\n\t\tvec3 probeWorldNormal = transformNormalByInverseViewMatrix( geometryNormal, viewMatrix );\n\t\tint probeGrid = - 1;\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_LIGHT_PROBE_GRIDS; i ++ ) {\n\t\t\tif ( isInsideLightProbeGrid( probeWorldPos, probeWorldNormal, probesMin[ i ], probesMax[ i ], probesResolution[ i ] ) ) probeGrid = UNROLLED_LOOP_INDEX;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_LIGHT_PROBE_GRIDS; i ++ ) {\n\t\t\tif ( probeGrid == UNROLLED_LOOP_INDEX ) irradiance += getLightProbeGridIrradiance( probesSH[ i ], probesMin[ i ], probesMax[ i ], probesResolution[ i ], probeWorldPos, probeWorldNormal );\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n#endif\n#if defined( RE_IndirectSpecular )\n\tvec3 radiance = vec3( 0.0 );\n\tvec3 clearcoatRadiance = vec3( 0.0 );\n#endif";402403var lights_fragment_maps = "#if defined( RE_IndirectDiffuse )\n\t#ifdef USE_LIGHTMAP\n\t\tvec4 lightMapTexel = texture2D( lightMap, vLightMapUv );\n\t\tvec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;\n\t\tirradiance += lightMapIrradiance;\n\t#endif\n\t#if defined( USE_ENVMAP ) && defined( ENVMAP_TYPE_PMREM )\n\t\t#if defined( STANDARD ) || defined( LAMBERT ) || defined( PHONG )\n\t\t\tiblIrradiance += getIBLIrradiance( geometryNormal );\n\t\t#endif\n\t#endif\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n\t#ifdef USE_ANISOTROPY\n\t\tvec3 iblRadiance = getIBLAnisotropyRadiance( geometryViewDir, geometryNormal, material.roughness, material.anisotropyB, material.anisotropy );\n\t#else\n\t\tvec3 iblRadiance = getIBLRadiance( geometryViewDir, geometryNormal, material.roughness );\n\t#endif\n\t#ifdef USE_RETROREFLECTION\n\t\t#ifdef USE_ANISOTROPY\n\t\t\tvec3 retroIBLRadiance = getIBLAnisotropyRetroRadiance( geometryViewDir, geometryNormal, material.roughness, material.anisotropyB, material.anisotropy );\n\t\t#else\n\t\t\tvec3 retroIBLRadiance = getIBLRetroRadiance( geometryViewDir, geometryNormal, material.roughness );\n\t\t#endif\n\t\tiblRadiance = mix( iblRadiance, retroIBLRadiance, saturate( material.retroreflectivity ) );\n\t#endif\n\tradiance += iblRadiance;\n\t#ifdef USE_CLEARCOAT\n\t\tclearcoatRadiance += getIBLRadiance( geometryViewDir, geometryClearcoatNormal, material.clearcoatRoughness );\n\t#endif\n#endif";404405var lights_fragment_end = "#if defined( RE_IndirectDiffuse )\n\t#if defined( LAMBERT ) || defined( PHONG )\n\t\tirradiance += iblIrradiance;\n\t#endif\n\tRE_IndirectDiffuse( irradiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n#endif\n#if defined( RE_IndirectSpecular )\n\tRE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n#endif";406407var lightprobes_pars_fragment = "#if NUM_LIGHT_PROBE_GRIDS > 0\nuniform highp sampler3D probesSH[ NUM_LIGHT_PROBE_GRIDS ];\nuniform vec3 probesMin[ NUM_LIGHT_PROBE_GRIDS ];\nuniform vec3 probesMax[ NUM_LIGHT_PROBE_GRIDS ];\nuniform vec3 probesResolution[ NUM_LIGHT_PROBE_GRIDS ];\nbool isInsideLightProbeGrid( vec3 worldPos, vec3 worldNormal, vec3 probesMin, vec3 probesMax, vec3 probesResolution ) {\n\tvec3 spacing = ( probesMax - probesMin ) / probesResolution;\n\tvec3 samplePos = worldPos + worldNormal * spacing * 0.5;\n\tvec3 margin = spacing * 0.01;\n\treturn all( greaterThanEqual( samplePos, probesMin - margin ) ) && all( lessThanEqual( samplePos, probesMax + margin ) );\n}\nvec3 getLightProbeGridIrradiance( highp sampler3D probesSH, vec3 probesMin, vec3 probesMax, vec3 probesResolution, vec3 worldPos, vec3 worldNormal ) {\n\tvec3 res = probesResolution;\n\tvec3 gridRange = probesMax - probesMin;\n\tvec3 probeSpacing = gridRange / res;\n\tvec3 samplePos = worldPos + worldNormal * probeSpacing * 0.5;\n\tvec3 uvw = clamp( ( samplePos - probesMin ) / gridRange, 0.5 / res, 1.0 - 0.5 / res );\n\tfloat nz = res.z;\n\tfloat paddedSlices = nz + 2.0;\n\tfloat atlasDepth = 7.0 * paddedSlices;\n\tfloat uvZBase = uvw.z * nz + 1.0;\n\tvec4 s0 = texture( probesSH, vec3( uvw.xy, ( uvZBase ) / atlasDepth ) );\n\tvec4 s1 = texture( probesSH, vec3( uvw.xy, ( uvZBase + paddedSlices ) / atlasDepth ) );\n\tvec4 s2 = texture( probesSH, vec3( uvw.xy, ( uvZBase + 2.0 * paddedSlices ) / atlasDepth ) );\n\tvec4 s3 = texture( probesSH, vec3( uvw.xy, ( uvZBase + 3.0 * paddedSlices ) / atlasDepth ) );\n\tvec4 s4 = texture( probesSH, vec3( uvw.xy, ( uvZBase + 4.0 * paddedSlices ) / atlasDepth ) );\n\tvec4 s5 = texture( probesSH, vec3( uvw.xy, ( uvZBase + 5.0 * paddedSlices ) / atlasDepth ) );\n\tvec4 s6 = texture( probesSH, vec3( uvw.xy, ( uvZBase + 6.0 * paddedSlices ) / atlasDepth ) );\n\tvec3 c0 = s0.xyz;\n\tvec3 c1 = vec3( s0.w, s1.xy );\n\tvec3 c2 = vec3( s1.zw, s2.x );\n\tvec3 c3 = s2.yzw;\n\tvec3 c4 = s3.xyz;\n\tvec3 c5 = vec3( s3.w, s4.xy );\n\tvec3 c6 = vec3( s4.zw, s5.x );\n\tvec3 c7 = s5.yzw;\n\tvec3 c8 = s6.xyz;\n\tfloat x = worldNormal.x, y = worldNormal.y, z = worldNormal.z;\n\tvec3 result = c0 * 0.886227;\n\tresult += c1 * 2.0 * 0.511664 * y;\n\tresult += c2 * 2.0 * 0.511664 * z;\n\tresult += c3 * 2.0 * 0.511664 * x;\n\tresult += c4 * 2.0 * 0.429043 * x * y;\n\tresult += c5 * 2.0 * 0.429043 * y * z;\n\tresult += c6 * ( 0.743125 * z * z - 0.247708 );\n\tresult += c7 * 2.0 * 0.429043 * x * z;\n\tresult += c8 * 0.429043 * ( x * x - y * y );\n\treturn max( result, vec3( 0.0 ) );\n}\n#endif";408409var logdepthbuf_fragment = "#if defined( USE_LOGARITHMIC_DEPTH_BUFFER )\n\tgl_FragDepth = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif";410411var logdepthbuf_pars_fragment = "#if defined( USE_LOGARITHMIC_DEPTH_BUFFER )\n\tuniform float logDepthBufFC;\n\tvarying float vFragDepth;\n\tvarying float vIsPerspective;\n#endif";412413var logdepthbuf_pars_vertex = "#ifdef USE_LOGARITHMIC_DEPTH_BUFFER\n\tvarying float vFragDepth;\n\tvarying float vIsPerspective;\n#endif";414415var logdepthbuf_vertex = "#ifdef USE_LOGARITHMIC_DEPTH_BUFFER\n\tvFragDepth = 1.0 + gl_Position.w;\n\tvIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );\n#endif";416417var map_fragment = "#ifdef USE_MAP\n\tvec4 sampledDiffuseColor = texture2D( map, vMapUv );\n\t#ifdef DECODE_VIDEO_TEXTURE\n\t\tsampledDiffuseColor = sRGBTransferEOTF( sampledDiffuseColor );\n\t#endif\n\tdiffuseColor *= sampledDiffuseColor;\n#endif";418419var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";420421var map_particle_fragment = "#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\t#if defined( USE_POINTS_UV )\n\t\tvec2 uv = vUv;\n\t#else\n\t\tvec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;\n\t#endif\n#endif\n#ifdef USE_MAP\n\tdiffuseColor *= texture2D( map, uv );\n#endif\n#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, uv ).g;\n#endif";422423var map_particle_pars_fragment = "#if defined( USE_POINTS_UV )\n\tvarying vec2 vUv;\n#else\n\t#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\t\tuniform mat3 uvTransform;\n\t#endif\n#endif\n#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif\n#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";424425var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vMetalnessMapUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";426427var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";428429var morphinstance_vertex = "#ifdef USE_INSTANCING_MORPH\n\tfloat morphTargetInfluences[ MORPHTARGETS_COUNT ];\n\tfloat morphTargetBaseInfluence = texelFetch( morphTexture, ivec2( 0, gl_InstanceID ), 0 ).r;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\tmorphTargetInfluences[i] = texelFetch( morphTexture, ivec2( i + 1, gl_InstanceID ), 0 ).r;\n\t}\n#endif";430431var morphcolor_vertex = "#if defined( USE_MORPHCOLORS )\n\t#if defined( USE_COLOR_ALPHA )\n\t\tvColor *= morphTargetBaseInfluence;\n\t#elif defined( USE_COLOR )\n\t\tvColor.rgb *= morphTargetBaseInfluence;\n\t#endif\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\t#if defined( USE_COLOR_ALPHA )\n\t\t\tif ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ) * morphTargetInfluences[ i ];\n\t\t#elif defined( USE_COLOR )\n\t\t\tif ( morphTargetInfluences[ i ] != 0.0 ) vColor.rgb += getMorph( gl_VertexID, i, 2 ).rgb * morphTargetInfluences[ i ];\n\t\t#endif\n\t}\n#endif";432433var morphnormal_vertex = "#ifdef USE_MORPHNORMALS\n\tobjectNormal *= morphTargetBaseInfluence;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\tif ( morphTargetInfluences[ i ] != 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1 ).xyz * morphTargetInfluences[ i ];\n\t}\n#endif";434435var morphtarget_pars_vertex = "#ifdef USE_MORPHTARGETS\n\t#ifndef USE_INSTANCING_MORPH\n\t\tuniform float morphTargetBaseInfluence;\n\t\tuniform float morphTargetInfluences[ MORPHTARGETS_COUNT ];\n\t#endif\n\tuniform sampler2DArray morphTargetsTexture;\n\tuniform ivec2 morphTargetsTextureSize;\n\tvec4 getMorph( const in int vertexIndex, const in int morphTargetIndex, const in int offset ) {\n\t\tint texelIndex = vertexIndex * MORPHTARGETS_TEXTURE_STRIDE + offset;\n\t\tint y = texelIndex / morphTargetsTextureSize.x;\n\t\tint x = texelIndex - y * morphTargetsTextureSize.x;\n\t\tivec3 morphUV = ivec3( x, y, morphTargetIndex );\n\t\treturn texelFetch( morphTargetsTexture, morphUV, 0 );\n\t}\n#endif";436437var morphtarget_vertex = "#ifdef USE_MORPHTARGETS\n\ttransformed *= morphTargetBaseInfluence;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\tif ( morphTargetInfluences[ i ] != 0.0 ) transformed += getMorph( gl_VertexID, i, 0 ).xyz * morphTargetInfluences[ i ];\n\t}\n#endif";438439var normal_fragment_begin = "float faceDirection = gl_FrontFacing ? 1.0 : - 1.0;\n#ifdef FLAT_SHADED\n\tvec3 fdx = dFdx( vViewPosition );\n\tvec3 fdy = dFdy( vViewPosition );\n\tvec3 normal = normalize( cross( fdx, fdy ) );\n#else\n\tvec3 normal = normalize( vNormal );\n\t#ifdef DOUBLE_SIDED\n\t\tnormal *= faceDirection;\n\t#endif\n#endif\n#if defined( USE_NORMALMAP_TANGENTSPACE ) || defined( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY )\n\t#ifdef USE_TANGENT\n\t\tmat3 tbn = mat3( normalize( vTangent ), normalize( vBitangent ), normal );\n\t#else\n\t\tmat3 tbn = getTangentFrame( - vViewPosition, normal,\n\t\t#if defined( USE_NORMALMAP )\n\t\t\tvNormalMapUv\n\t\t#elif defined( USE_CLEARCOAT_NORMALMAP )\n\t\t\tvClearcoatNormalMapUv\n\t\t#else\n\t\t\tvUv\n\t\t#endif\n\t\t);\n\t#endif\n\t#ifdef DOUBLE_SIDED\n\t\ttbn[0] *= faceDirection;\n\t\ttbn[1] *= faceDirection;\n\t#endif\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\t#ifdef USE_TANGENT\n\t\tmat3 tbn2 = mat3( normalize( vTangent ), normalize( vBitangent ), normal );\n\t#else\n\t\tmat3 tbn2 = getTangentFrame( - vViewPosition, normal, vClearcoatNormalMapUv );\n\t#endif\n\t#ifdef DOUBLE_SIDED\n\t\ttbn2[0] *= faceDirection;\n\t\ttbn2[1] *= faceDirection;\n\t#endif\n#endif\nvec3 nonPerturbedNormal = normal;";440441var normal_fragment_maps = "#ifdef USE_NORMALMAP_OBJECTSPACE\n\tnormal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;\n\t#ifdef FLIP_SIDED\n\t\tnormal = - normal;\n\t#endif\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * faceDirection;\n\t#endif\n\tnormal = normalize( normalMatrix * normal );\n#elif defined( USE_NORMALMAP_TANGENTSPACE )\n\tvec3 mapN = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;\n\t#if defined( USE_PACKED_NORMALMAP )\n\t\tmapN = vec3( mapN.xy, sqrt( saturate( 1.0 - dot( mapN.xy, mapN.xy ) ) ) );\n\t#endif\n\tmapN.xy *= normalScale;\n\tnormal = normalize( tbn * mapN );\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection );\n#endif";442443var normal_pars_fragment = "#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif";444445var normal_pars_vertex = "#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif";446447var normal_vertex = "#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n\t#ifdef USE_TANGENT\n\t\tvTangent = normalize( transformedTangent );\n\t\tvBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );\n\t\t#ifdef FLIP_SIDED\n\t\t\tvBitangent = - vBitangent;\n\t\t#endif\n\t#endif\n#endif";448449var normalmap_pars_fragment = "#ifdef USE_NORMALMAP\n\tuniform sampler2D normalMap;\n\tuniform vec2 normalScale;\n#endif\n#ifdef USE_NORMALMAP_OBJECTSPACE\n\tuniform mat3 normalMatrix;\n#endif\n#if ! defined ( USE_TANGENT ) && ( defined ( USE_NORMALMAP_TANGENTSPACE ) || defined ( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY ) )\n\tmat3 getTangentFrame( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {\n\t\tvec3 q0 = dFdx( eye_pos.xyz );\n\t\tvec3 q1 = dFdy( eye_pos.xyz );\n\t\tvec2 st0 = dFdx( uv.st );\n\t\tvec2 st1 = dFdy( uv.st );\n\t\tvec3 N = surf_norm;\n\t\tvec3 q1perp = cross( q1, N );\n\t\tvec3 q0perp = cross( N, q0 );\n\t\tvec3 T = q1perp * st0.x + q0perp * st1.x;\n\t\tvec3 B = q1perp * st0.y + q0perp * st1.y;\n\t\tfloat det = max( dot( T, T ), dot( B, B ) );\n\t\tfloat scale = ( det == 0.0 ) ? 0.0 : inversesqrt( det );\n\t\treturn mat3( T * scale, B * scale, N );\n\t}\n#endif";450451var clearcoat_normal_fragment_begin = "#ifdef USE_CLEARCOAT\n\tvec3 clearcoatNormal = nonPerturbedNormal;\n#endif";452453var clearcoat_normal_fragment_maps = "#ifdef USE_CLEARCOAT_NORMALMAP\n\tvec3 clearcoatMapN = texture2D( clearcoatNormalMap, vClearcoatNormalMapUv ).xyz * 2.0 - 1.0;\n\tclearcoatMapN.xy *= clearcoatNormalScale;\n\tclearcoatNormal = normalize( tbn2 * clearcoatMapN );\n#endif";454455var clearcoat_pars_fragment = "#ifdef USE_CLEARCOATMAP\n\tuniform sampler2D clearcoatMap;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tuniform sampler2D clearcoatNormalMap;\n\tuniform vec2 clearcoatNormalScale;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tuniform sampler2D clearcoatRoughnessMap;\n#endif";456457var iridescence_pars_fragment = "#ifdef USE_IRIDESCENCEMAP\n\tuniform sampler2D iridescenceMap;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\tuniform sampler2D iridescenceThicknessMap;\n#endif";458459var opaque_fragment = "#ifdef OPAQUE\ndiffuseColor.a = 1.0;\n#endif\n#ifdef USE_TRANSMISSION\ndiffuseColor.a *= material.transmissionAlpha;\n#endif\ngl_FragColor = vec4( outgoingLight, diffuseColor.a );";460461var packing = "vec3 packNormalToRGB( const in vec3 normal ) {\n\treturn normalize( normal ) * 0.5 + 0.5;\n}\nvec3 unpackRGBToNormal( const in vec3 rgb ) {\n\treturn 2.0 * rgb.xyz - 1.0;\n}\nconst float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;const float ShiftRight8 = 1. / 256.;\nconst float Inv255 = 1. / 255.;\nconst vec4 PackFactors = vec4( 1.0, 256.0, 256.0 * 256.0, 256.0 * 256.0 * 256.0 );\nconst vec2 UnpackFactors2 = vec2( UnpackDownscale, 1.0 / PackFactors.g );\nconst vec3 UnpackFactors3 = vec3( UnpackDownscale / PackFactors.rg, 1.0 / PackFactors.b );\nconst vec4 UnpackFactors4 = vec4( UnpackDownscale / PackFactors.rgb, 1.0 / PackFactors.a );\nvec4 packDepthToRGBA( const in float v ) {\n\tif( v <= 0.0 )\n\t\treturn vec4( 0., 0., 0., 0. );\n\tif( v >= 1.0 )\n\t\treturn vec4( 1., 1., 1., 1. );\n\tfloat vuf;\n\tfloat af = modf( v * PackFactors.a, vuf );\n\tfloat bf = modf( vuf * ShiftRight8, vuf );\n\tfloat gf = modf( vuf * ShiftRight8, vuf );\n\treturn vec4( vuf * Inv255, gf * PackUpscale, bf * PackUpscale, af );\n}\nvec3 packDepthToRGB( const in float v ) {\n\tif( v <= 0.0 )\n\t\treturn vec3( 0., 0., 0. );\n\tif( v >= 1.0 )\n\t\treturn vec3( 1., 1., 1. );\n\tfloat vuf;\n\tfloat bf = modf( v * PackFactors.b, vuf );\n\tfloat gf = modf( vuf * ShiftRight8, vuf );\n\treturn vec3( vuf * Inv255, gf * PackUpscale, bf );\n}\nvec2 packDepthToRG( const in float v ) {\n\tif( v <= 0.0 )\n\t\treturn vec2( 0., 0. );\n\tif( v >= 1.0 )\n\t\treturn vec2( 1., 1. );\n\tfloat vuf;\n\tfloat gf = modf( v * 256., vuf );\n\treturn vec2( vuf * Inv255, gf );\n}\nfloat unpackRGBAToDepth( const in vec4 v ) {\n\treturn dot( v, UnpackFactors4 );\n}\nfloat unpackRGBToDepth( const in vec3 v ) {\n\treturn dot( v, UnpackFactors3 );\n}\nfloat unpackRGToDepth( const in vec2 v ) {\n\treturn v.r * UnpackFactors2.r + v.g * UnpackFactors2.g;\n}\nvec4 pack2HalfToRGBA( const in vec2 v ) {\n\tvec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ) );\n\treturn vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w );\n}\nvec2 unpackRGBATo2Half( const in vec4 v ) {\n\treturn vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );\n}\nfloat viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( viewZ + near ) / ( near - far );\n}\nfloat orthographicDepthToViewZ( const in float depth, const in float near, const in float far ) {\n\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\n\t\treturn depth * ( far - near ) - far;\n\t#else\n\t\treturn depth * ( near - far ) - near;\n\t#endif\n}\nfloat viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ );\n}\nfloat perspectiveDepthToViewZ( const in float depth, const in float near, const in float far ) {\n\t\n\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\treturn ( near * far ) / ( ( near - far ) * depth - near );\n\t#else\n\t\treturn ( near * far ) / ( ( far - near ) * depth - far );\n\t#endif\n}";462463var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";464465var project_vertex = "vec4 mvPosition = vec4( transformed, 1.0 );\n#ifdef USE_BATCHING\n\tmvPosition = batchingMatrix * mvPosition;\n#endif\n#ifdef USE_INSTANCING\n\tmvPosition = instanceMatrix * mvPosition;\n#endif\nmvPosition = modelViewMatrix * mvPosition;\ngl_Position = projectionMatrix * mvPosition;";466467var dithering_fragment = "#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";468469var dithering_pars_fragment = "#ifdef DITHERING\n\tvec3 dithering( vec3 color ) {\n\t\tfloat grid_position = rand( gl_FragCoord.xy );\n\t\tvec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );\n\t\tdither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );\n\t\treturn color + dither_shift_RGB;\n\t}\n#endif";470471var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vRoughnessMapUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";472473var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";474475var shadowmap_pars_fragment = "#if NUM_SPOT_LIGHT_COORDS > 0\n\tvarying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];\n#endif\n#if NUM_SPOT_LIGHT_MAPS > 0\n\tuniform sampler2D spotLightMap[ NUM_SPOT_LIGHT_MAPS ];\n#endif\n#ifdef USE_SHADOWMAP\n\t#if NUM_SUN_LIGHT_SHADOWS > 0\n\t\t#define SUN_LIGHT_CASCADES 2\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\t\tuniform sampler2DShadow sunShadowMap[ NUM_SUN_LIGHT_SHADOWS ];\n\t\t#else\n\t\t\tuniform sampler2D sunShadowMap[ NUM_SUN_LIGHT_SHADOWS ];\n\t\t#endif\n\t\tuniform mat4 sunShadowMatrix[ NUM_SUN_LIGHT_SHADOWS * SUN_LIGHT_CASCADES ];\n\t\tuniform vec4 sunShadowCascade[ NUM_SUN_LIGHT_SHADOWS * SUN_LIGHT_CASCADES ];\n\t\tvarying vec4 vSunShadowWorldPosition;\n\t\tvarying vec3 vSunShadowWorldNormal;\n\t\tstruct SunLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SunLightShadow sunLightShadows[ NUM_SUN_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\t\tuniform sampler2DShadow directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];\n\t\t#else\n\t\t\tuniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];\n\t\t#endif\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\t\tuniform sampler2DShadow spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\t#else\n\t\t\tuniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\t#endif\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\t\tuniform samplerCubeShadow pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];\n\t\t#elif defined( SHADOWMAP_TYPE_BASIC )\n\t\t\tuniform samplerCube pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];\n\t\t#endif\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\tfloat interleavedGradientNoise( vec2 position ) {\n\t\t\treturn fract( 52.9829189 * fract( dot( position, vec2( 0.06711056, 0.00583715 ) ) ) );\n\t\t}\n\t\tvec2 vogelDiskSample( int sampleIndex, int samplesCount, float phi ) {\n\t\t\tconst float goldenAngle = 2.399963229728653;\n\t\t\tfloat r = sqrt( ( float( sampleIndex ) + 0.5 ) / float( samplesCount ) );\n\t\t\tfloat theta = float( sampleIndex ) * goldenAngle + phi;\n\t\t\treturn vec2( cos( theta ), sin( theta ) ) * r;\n\t\t}\n\t#endif\n\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\tfloat getShadow( sampler2DShadow shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\t\t\tfloat shadow = 1.0;\n\t\t\tshadowCoord.xyz /= shadowCoord.w;\n\t\t\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\t\t\tshadowCoord.z -= shadowBias;\n\t\t\t#else\n\t\t\t\tshadowCoord.z += shadowBias;\n\t\t\t#endif\n\t\t\tbool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;\n\t\t\tbool frustumTest = inFrustum && shadowCoord.z <= 1.0;\n\t\t\tif ( frustumTest ) {\n\t\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\t\tvec2 radius = shadowRadius * texelSize;\n\t\t\t\tfloat phi = interleavedGradientNoise( gl_FragCoord.xy ) * PI2;\n\t\t\t\tshadow = (\n\t\t\t\t\ttexture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 0, 5, phi ) * radius, shadowCoord.z ) ) +\n\t\t\t\t\ttexture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 1, 5, phi ) * radius, shadowCoord.z ) ) +\n\t\t\t\t\ttexture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 2, 5, phi ) * radius, shadowCoord.z ) ) +\n\t\t\t\t\ttexture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 3, 5, phi ) * radius, shadowCoord.z ) ) +\n\t\t\t\t\ttexture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 4, 5, phi ) * radius, shadowCoord.z ) )\n\t\t\t\t) * 0.2;\n\t\t\t}\n\t\t\treturn mix( 1.0, shadow, shadowIntensity );\n\t\t}\n\t#elif defined( SHADOWMAP_TYPE_VSM )\n\t\tfloat getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\t\t\tfloat shadow = 1.0;\n\t\t\tshadowCoord.xyz /= shadowCoord.w;\n\t\t\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\t\t\tshadowCoord.z -= shadowBias;\n\t\t\t#else\n\t\t\t\tshadowCoord.z += shadowBias;\n\t\t\t#endif\n\t\t\tbool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;\n\t\t\tbool frustumTest = inFrustum && shadowCoord.z <= 1.0;\n\t\t\tif ( frustumTest ) {\n\t\t\t\tvec2 distribution = texture2D( shadowMap, shadowCoord.xy ).rg;\n\t\t\t\tfloat mean = distribution.x;\n\t\t\t\tfloat variance = distribution.y * distribution.y;\n\t\t\t\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\t\t\t\tfloat hard_shadow = step( mean, shadowCoord.z );\n\t\t\t\t#else\n\t\t\t\t\tfloat hard_shadow = step( shadowCoord.z, mean );\n\t\t\t\t#endif\n\t\t\t\t\n\t\t\t\tif ( hard_shadow == 1.0 ) {\n\t\t\t\t\tshadow = 1.0;\n\t\t\t\t} else {\n\t\t\t\t\tvariance = max( variance, 0.0000001 );\n\t\t\t\t\tfloat d = shadowCoord.z - mean;\n\t\t\t\t\tfloat p_max = variance / ( variance + d * d );\n\t\t\t\t\tp_max = clamp( ( p_max - 0.3 ) / 0.65, 0.0, 1.0 );\n\t\t\t\t\tshadow = max( hard_shadow, p_max );\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn mix( 1.0, shadow, shadowIntensity );\n\t\t}\n\t#else\n\t\tfloat getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\t\t\tfloat shadow = 1.0;\n\t\t\tshadowCoord.xyz /= shadowCoord.w;\n\t\t\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\t\t\tshadowCoord.z -= shadowBias;\n\t\t\t#else\n\t\t\t\tshadowCoord.z += shadowBias;\n\t\t\t#endif\n\t\t\tbool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;\n\t\t\tbool frustumTest = inFrustum && shadowCoord.z <= 1.0;\n\t\t\tif ( frustumTest ) {\n\t\t\t\tfloat depth = texture2D( shadowMap, shadowCoord.xy ).r;\n\t\t\t\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\t\t\t\tshadow = step( depth, shadowCoord.z );\n\t\t\t\t#else\n\t\t\t\t\tshadow = step( shadowCoord.z, depth );\n\t\t\t\t#endif\n\t\t\t}\n\t\t\treturn mix( 1.0, shadow, shadowIntensity );\n\t\t}\n\t#endif\n\t#if NUM_SUN_LIGHT_SHADOWS > 0\n\t\tfloat getSunShadow(\n\t\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\t\t\tsampler2DShadow shadowMap,\n\t\t\t#else\n\t\t\t\tsampler2D shadowMap,\n\t\t\t#endif\n\t\t\tSunLightShadow sunLightShadow,\n\t\t\tint shadowIndex\n\t\t) {\n\t\t\tvec4 shadowWorldPosition = vec4( vSunShadowWorldPosition.xyz + vSunShadowWorldNormal * sunLightShadow.shadowNormalBias, 1.0 );\n\t\t\tfloat viewDepth = vSunShadowWorldPosition.w;\n\t\t\tint cascadeOffset = shadowIndex * SUN_LIGHT_CASCADES;\n\t\t\tfloat shadow = 1.0;\n\t\t\tfor ( int i = SUN_LIGHT_CASCADES - 1; i >= 0; i -- ) {\n\t\t\t\tvec4 cascade = sunShadowCascade[ cascadeOffset + i ];\n\t\t\t\tif ( viewDepth >= cascade.x && viewDepth < cascade.y ) {\n\t\t\t\t\tfloat cascadeShadow = getShadow(\n\t\t\t\t\t\tshadowMap,\n\t\t\t\t\t\tsunLightShadow.shadowMapSize,\n\t\t\t\t\t\tsunLightShadow.shadowIntensity,\n\t\t\t\t\t\tsunLightShadow.shadowBias,\n\t\t\t\t\t\tsunLightShadow.shadowRadius,\n\t\t\t\t\t\tsunShadowMatrix[ cascadeOffset + i ] * shadowWorldPosition\n\t\t\t\t\t);\n\t\t\t\t\tshadow = mix( cascadeShadow, shadow, smoothstep( cascade.z, cascade.y, viewDepth ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn shadow;\n\t\t}\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t#if defined( SHADOWMAP_TYPE_PCF )\n\tfloat getPointShadow( samplerCubeShadow shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {\n\t\tfloat shadow = 1.0;\n\t\tvec3 lightToPosition = shadowCoord.xyz;\n\t\tvec3 bd3D = normalize( lightToPosition );\n\t\tvec3 absVec = abs( lightToPosition );\n\t\tfloat viewSpaceZ = max( max( absVec.x, absVec.y ), absVec.z );\n\t\tif ( viewSpaceZ - shadowCameraFar <= 0.0 && viewSpaceZ - shadowCameraNear >= 0.0 ) {\n\t\t\tfloat lightDistance = length( lightToPosition );\n\t\t\tfloat depthRange = shadowCameraFar - shadowCameraNear;\n\t\t\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\t\t\tfloat depthA = - shadowCameraNear / depthRange - shadowBias;\n\t\t\t\tfloat depthB = shadowCameraNear * shadowCameraFar / ( depthRange * lightDistance );\n\t\t\t#else\n\t\t\t\tfloat depthA = shadowCameraFar / depthRange + shadowBias;\n\t\t\t\tfloat depthB = - shadowCameraNear * shadowCameraFar / ( depthRange * lightDistance );\n\t\t\t#endif\n\t\t\tfloat texelSize = shadowRadius / shadowMapSize.x;\n\t\t\tvec3 absDir = abs( bd3D );\n\t\t\tvec3 tangent = absDir.x > absDir.z ? vec3( 0.0, 1.0, 0.0 ) : vec3( 1.0, 0.0, 0.0 );\n\t\t\ttangent = normalize( cross( bd3D, tangent ) );\n\t\t\tvec3 bitangent = cross( bd3D, tangent );\n\t\t\tfloat phi = interleavedGradientNoise( gl_FragCoord.xy ) * PI2;\n\t\t\tshadow = 0.0;\n\t\t\tfor ( int i = 0; i < 5; i ++ ) {\n\t\t\t\tvec2 offset = vogelDiskSample( i, 5, phi );\n\t\t\t\tvec3 direction = bd3D + ( tangent * offset.x + bitangent * offset.y ) * texelSize;\n\t\t\t\tvec3 absDirection = abs( direction );\n\t\t\t\tfloat dp = depthA + depthB / max( max( absDirection.x, absDirection.y ), absDirection.z );\n\t\t\t\tshadow += texture( shadowMap, vec4( direction, dp ) );\n\t\t\t}\n\t\t\tshadow *= 0.2;\n\t\t}\n\t\treturn mix( 1.0, shadow, shadowIntensity );\n\t}\n\t#elif defined( SHADOWMAP_TYPE_BASIC )\n\tfloat getPointShadow( samplerCube shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {\n\t\tfloat shadow = 1.0;\n\t\tvec3 lightToPosition = shadowCoord.xyz;\n\t\tvec3 absVec = abs( lightToPosition );\n\t\tfloat viewSpaceZ = max( max( absVec.x, absVec.y ), absVec.z );\n\t\tif ( viewSpaceZ - shadowCameraFar <= 0.0 && viewSpaceZ - shadowCameraNear >= 0.0 ) {\n\t\t\tfloat dp = ( shadowCameraFar * ( viewSpaceZ - shadowCameraNear ) ) / ( viewSpaceZ * ( shadowCameraFar - shadowCameraNear ) );\n\t\t\tdp += shadowBias;\n\t\t\tvec3 bd3D = normalize( lightToPosition );\n\t\t\tfloat depth = textureCube( shadowMap, bd3D ).r;\n\t\t\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\t\t\tdepth = 1.0 - depth;\n\t\t\t#endif\n\t\t\tshadow = step( dp, depth );\n\t\t}\n\t\treturn mix( 1.0, shadow, shadowIntensity );\n\t}\n\t#endif\n\t#endif\n#endif";476477var shadowmap_pars_vertex = "#if NUM_SPOT_LIGHT_COORDS > 0\n\tuniform mat4 spotLightMatrix[ NUM_SPOT_LIGHT_COORDS ];\n\tvarying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];\n#endif\n#ifdef USE_SHADOWMAP\n\t#if NUM_SUN_LIGHT_SHADOWS > 0\n\t\tvarying vec4 vSunShadowWorldPosition;\n\t\tvarying vec3 vSunShadowWorldNormal;\n\t#endif\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n#endif";478479var shadowmap_vertex = "#if ( defined( USE_SHADOWMAP ) && ( NUM_DIR_LIGHT_SHADOWS > 0 || NUM_SUN_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0 ) ) || ( NUM_SPOT_LIGHT_COORDS > 0 )\n\t#ifdef HAS_NORMAL\n\t\tvec3 shadowWorldNormal = transformNormalByInverseViewMatrix( transformedNormal, viewMatrix );\n\t#else\n\t\tvec3 shadowWorldNormal = vec3( 0.0 );\n\t#endif\n\tvec4 shadowWorldPosition;\n#endif\n#if defined( USE_SHADOWMAP )\n\t#if NUM_SUN_LIGHT_SHADOWS > 0\n\t\tvSunShadowWorldPosition = vec4( worldPosition.xyz, - mvPosition.z );\n\t\tvSunShadowWorldNormal = shadowWorldNormal;\n\t#endif\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 );\n\t\t\tvDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 );\n\t\t\tvPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n#endif\n#if NUM_SPOT_LIGHT_COORDS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_COORDS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition;\n\t\t#if ( defined( USE_SHADOWMAP ) && UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\t\tshadowWorldPosition.xyz += shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias;\n\t\t#endif\n\t\tvSpotLightCoord[ i ] = spotLightMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n#endif";480481var shadowmask_pars_fragment = "float getShadowMask() {\n\tfloat shadow = 1.0;\n\t#ifdef USE_SHADOWMAP\n\t#if NUM_SUN_LIGHT_SHADOWS > 0\n\tSunLightShadow sunLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SUN_LIGHT_SHADOWS; i ++ ) {\n\t\tsunLight = sunLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getSunShadow( sunShadowMap[ i ], sunLight, UNROLLED_LOOP_INDEX ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\tdirectionalLight = directionalLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowIntensity, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\t\tspotLight = spotLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowIntensity, spotLight.shadowBias, spotLight.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0 && ( defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_BASIC ) )\n\tPointLightShadow pointLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tpointLight = pointLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowIntensity, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#endif\n\treturn shadow;\n}";482483var skinbase_vertex = "#ifdef USE_SKINNING\n\tmat4 boneMatX = getBoneMatrix( skinIndex.x );\n\tmat4 boneMatY = getBoneMatrix( skinIndex.y );\n\tmat4 boneMatZ = getBoneMatrix( skinIndex.z );\n\tmat4 boneMatW = getBoneMatrix( skinIndex.w );\n#endif";484485var skinning_pars_vertex = "#ifdef USE_SKINNING\n\tuniform mat4 bindMatrix;\n\tuniform mat4 bindMatrixInverse;\n\tuniform highp sampler2D boneTexture;\n\tmat4 getBoneMatrix( const in float i ) {\n\t\tint size = textureSize( boneTexture, 0 ).x;\n\t\tint j = int( i ) * 4;\n\t\tint x = j % size;\n\t\tint y = j / size;\n\t\tvec4 v1 = texelFetch( boneTexture, ivec2( x, y ), 0 );\n\t\tvec4 v2 = texelFetch( boneTexture, ivec2( x + 1, y ), 0 );\n\t\tvec4 v3 = texelFetch( boneTexture, ivec2( x + 2, y ), 0 );\n\t\tvec4 v4 = texelFetch( boneTexture, ivec2( x + 3, y ), 0 );\n\t\treturn mat4( v1, v2, v3, v4 );\n\t}\n#endif";486487var skinning_vertex = "#ifdef USE_SKINNING\n\tvec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\n\tvec4 skinned = vec4( 0.0 );\n\tskinned += boneMatX * skinVertex * skinWeight.x;\n\tskinned += boneMatY * skinVertex * skinWeight.y;\n\tskinned += boneMatZ * skinVertex * skinWeight.z;\n\tskinned += boneMatW * skinVertex * skinWeight.w;\n\ttransformed = ( bindMatrixInverse * skinned ).xyz;\n#endif";488489var skinnormal_vertex = "#ifdef USE_SKINNING\n\tmat4 skinMatrix = mat4( 0.0 );\n\tskinMatrix += skinWeight.x * boneMatX;\n\tskinMatrix += skinWeight.y * boneMatY;\n\tskinMatrix += skinWeight.z * boneMatZ;\n\tskinMatrix += skinWeight.w * boneMatW;\n\tskinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;\n\tobjectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n\t#ifdef USE_TANGENT\n\t\tobjectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n\t#endif\n#endif";490491var specularmap_fragment = "float specularStrength;\n#ifdef USE_SPECULARMAP\n\tvec4 texelSpecular = texture2D( specularMap, vSpecularMapUv );\n\tspecularStrength = texelSpecular.r;\n#else\n\tspecularStrength = 1.0;\n#endif";492493var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";494495var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";496497var tonemapping_pars_fragment = "#ifndef saturate\n#define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\nuniform float toneMappingExposure;\nvec3 LinearToneMapping( vec3 color ) {\n\treturn saturate( toneMappingExposure * color );\n}\nvec3 ReinhardToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( color / ( vec3( 1.0 ) + color ) );\n}\nvec3 CineonToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\tcolor = max( vec3( 0.0 ), color - 0.004 );\n\treturn pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\n}\nvec3 RRTAndODTFit( vec3 v ) {\n\tvec3 a = v * ( v + 0.0245786 ) - 0.000090537;\n\tvec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081;\n\treturn a / b;\n}\nvec3 ACESFilmicToneMapping( vec3 color ) {\n\tconst mat3 ACESInputMat = mat3(\n\t\tvec3( 0.59719, 0.07600, 0.02840 ),\t\tvec3( 0.35458, 0.90834, 0.13383 ),\n\t\tvec3( 0.04823, 0.01566, 0.83777 )\n\t);\n\tconst mat3 ACESOutputMat = mat3(\n\t\tvec3( 1.60475, -0.10208, -0.00327 ),\t\tvec3( -0.53108, 1.10813, -0.07276 ),\n\t\tvec3( -0.07367, -0.00605, 1.07602 )\n\t);\n\tcolor *= toneMappingExposure / 0.6;\n\tcolor = ACESInputMat * color;\n\tcolor = RRTAndODTFit( color );\n\tcolor = ACESOutputMat * color;\n\treturn saturate( color );\n}\nconst mat3 LINEAR_REC2020_TO_LINEAR_SRGB = mat3(\n\tvec3( 1.6605, - 0.1246, - 0.0182 ),\n\tvec3( - 0.5876, 1.1329, - 0.1006 ),\n\tvec3( - 0.0728, - 0.0083, 1.1187 )\n);\nconst mat3 LINEAR_SRGB_TO_LINEAR_REC2020 = mat3(\n\tvec3( 0.6274, 0.0691, 0.0164 ),\n\tvec3( 0.3293, 0.9195, 0.0880 ),\n\tvec3( 0.0433, 0.0113, 0.8956 )\n);\nvec3 agxDefaultContrastApprox( vec3 x ) {\n\tvec3 x2 = x * x;\n\tvec3 x4 = x2 * x2;\n\treturn + 15.5 * x4 * x2\n\t\t- 40.14 * x4 * x\n\t\t+ 31.96 * x4\n\t\t- 6.868 * x2 * x\n\t\t+ 0.4298 * x2\n\t\t+ 0.1191 * x\n\t\t- 0.00232;\n}\nvec3 AgXToneMapping( vec3 color ) {\n\tconst mat3 AgXInsetMatrix = mat3(\n\t\tvec3( 0.856627153315983, 0.137318972929847, 0.11189821299995 ),\n\t\tvec3( 0.0951212405381588, 0.761241990602591, 0.0767994186031903 ),\n\t\tvec3( 0.0482516061458583, 0.101439036467562, 0.811302368396859 )\n\t);\n\tconst mat3 AgXOutsetMatrix = mat3(\n\t\tvec3( 1.1271005818144368, - 0.1413297634984383, - 0.14132976349843826 ),\n\t\tvec3( - 0.11060664309660323, 1.157823702216272, - 0.11060664309660294 ),\n\t\tvec3( - 0.016493938717834573, - 0.016493938717834257, 1.2519364065950405 )\n\t);\n\tconst float AgxMinEv = - 12.47393;\tconst float AgxMaxEv = 4.026069;\n\tcolor *= toneMappingExposure;\n\tcolor = LINEAR_SRGB_TO_LINEAR_REC2020 * color;\n\tcolor = AgXInsetMatrix * color;\n\tcolor = max( color, 1e-10 );\tcolor = log2( color );\n\tcolor = ( color - AgxMinEv ) / ( AgxMaxEv - AgxMinEv );\n\tcolor = clamp( color, 0.0, 1.0 );\n\tcolor = agxDefaultContrastApprox( color );\n\tcolor = AgXOutsetMatrix * color;\n\tcolor = pow( max( vec3( 0.0 ), color ), vec3( 2.2 ) );\n\tcolor = LINEAR_REC2020_TO_LINEAR_SRGB * color;\n\tcolor = clamp( color, 0.0, 1.0 );\n\treturn color;\n}\nvec3 NeutralToneMapping( vec3 color ) {\n\tconst float StartCompression = 0.8 - 0.04;\n\tconst float Desaturation = 0.15;\n\tcolor *= toneMappingExposure;\n\tfloat x = min( color.r, min( color.g, color.b ) );\n\tfloat offset = x < 0.08 ? x - 6.25 * x * x : 0.04;\n\tcolor -= offset;\n\tfloat peak = max( color.r, max( color.g, color.b ) );\n\tif ( peak < StartCompression ) return color;\n\tfloat d = 1. - StartCompression;\n\tfloat newPeak = 1. - d * d / ( peak + d - StartCompression );\n\tcolor *= newPeak / peak;\n\tfloat g = 1. - 1. / ( Desaturation * ( peak - newPeak ) + 1. );\n\treturn mix( color, vec3( newPeak ), g );\n}\nvec3 CustomToneMapping( vec3 color ) { return color; }";498499var transmission_fragment = "#ifdef USE_TRANSMISSION\n\tmaterial.transmission = transmission;\n\tmaterial.transmissionAlpha = 1.0;\n\tmaterial.thickness = thickness;\n\tmaterial.attenuationDistance = attenuationDistance;\n\tmaterial.attenuationColor = attenuationColor;\n\t#ifdef USE_TRANSMISSIONMAP\n\t\tmaterial.transmission *= texture2D( transmissionMap, vTransmissionMapUv ).r;\n\t#endif\n\t#ifdef USE_THICKNESSMAP\n\t\tmaterial.thickness *= texture2D( thicknessMap, vThicknessMapUv ).g;\n\t#endif\n\tvec3 pos = vWorldPosition;\n\tvec3 v = normalize( cameraPosition - pos );\n\tvec3 n = transformNormalByInverseViewMatrix( normal, viewMatrix );\n\tvec4 transmitted = getIBLVolumeRefraction(\n\t\tn, v, material.roughness, material.diffuseContribution, material.specularColorBlended, material.specularF90,\n\t\tpos, modelMatrix, viewMatrix, projectionMatrix, material.dispersion, material.ior, material.thickness,\n\t\tmaterial.attenuationColor, material.attenuationDistance );\n\tmaterial.transmissionAlpha = mix( material.transmissionAlpha, transmitted.a, material.transmission );\n\ttotalDiffuse = mix( totalDiffuse, transmitted.rgb, material.transmission );\n#endif";500501var transmission_pars_fragment = "#ifdef USE_TRANSMISSION\n\tuniform float transmission;\n\tuniform float thickness;\n\tuniform float attenuationDistance;\n\tuniform vec3 attenuationColor;\n\t#ifdef USE_TRANSMISSIONMAP\n\t\tuniform sampler2D transmissionMap;\n\t#endif\n\t#ifdef USE_THICKNESSMAP\n\t\tuniform sampler2D thicknessMap;\n\t#endif\n\tuniform vec2 transmissionSamplerSize;\n\tuniform sampler2D transmissionSamplerMap;\n\tuniform mat4 modelMatrix;\n\tuniform mat4 projectionMatrix;\n\tvarying vec3 vWorldPosition;\n\tfloat w0( float a ) {\n\t\treturn ( 1.0 / 6.0 ) * ( a * ( a * ( - a + 3.0 ) - 3.0 ) + 1.0 );\n\t}\n\tfloat w1( float a ) {\n\t\treturn ( 1.0 / 6.0 ) * ( a * a * ( 3.0 * a - 6.0 ) + 4.0 );\n\t}\n\tfloat w2( float a ){\n\t\treturn ( 1.0 / 6.0 ) * ( a * ( a * ( - 3.0 * a + 3.0 ) + 3.0 ) + 1.0 );\n\t}\n\tfloat w3( float a ) {\n\t\treturn ( 1.0 / 6.0 ) * ( a * a * a );\n\t}\n\tfloat g0( float a ) {\n\t\treturn w0( a ) + w1( a );\n\t}\n\tfloat g1( float a ) {\n\t\treturn w2( a ) + w3( a );\n\t}\n\tfloat h0( float a ) {\n\t\treturn - 1.0 + w1( a ) / ( w0( a ) + w1( a ) );\n\t}\n\tfloat h1( float a ) {\n\t\treturn 1.0 + w3( a ) / ( w2( a ) + w3( a ) );\n\t}\n\tvec4 bicubic( sampler2D tex, vec2 uv, vec4 texelSize, float lod ) {\n\t\tuv = uv * texelSize.zw + 0.5;\n\t\tvec2 iuv = floor( uv );\n\t\tvec2 fuv = fract( uv );\n\t\tfloat g0x = g0( fuv.x );\n\t\tfloat g1x = g1( fuv.x );\n\t\tfloat h0x = h0( fuv.x );\n\t\tfloat h1x = h1( fuv.x );\n\t\tfloat h0y = h0( fuv.y );\n\t\tfloat h1y = h1( fuv.y );\n\t\tvec2 p0 = ( vec2( iuv.x + h0x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;\n\t\tvec2 p1 = ( vec2( iuv.x + h1x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;\n\t\tvec2 p2 = ( vec2( iuv.x + h0x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;\n\t\tvec2 p3 = ( vec2( iuv.x + h1x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;\n\t\treturn g0( fuv.y ) * ( g0x * textureLod( tex, p0, lod ) + g1x * textureLod( tex, p1, lod ) ) +\n\t\t\tg1( fuv.y ) * ( g0x * textureLod( tex, p2, lod ) + g1x * textureLod( tex, p3, lod ) );\n\t}\n\tvec4 textureBicubic( sampler2D sampler, vec2 uv, float lod ) {\n\t\tvec2 fLodSize = vec2( textureSize( sampler, int( lod ) ) );\n\t\tvec2 cLodSize = vec2( textureSize( sampler, int( lod + 1.0 ) ) );\n\t\tvec2 fLodSizeInv = 1.0 / fLodSize;\n\t\tvec2 cLodSizeInv = 1.0 / cLodSize;\n\t\tvec4 fSample = bicubic( sampler, uv, vec4( fLodSizeInv, fLodSize ), floor( lod ) );\n\t\tvec4 cSample = bicubic( sampler, uv, vec4( cLodSizeInv, cLodSize ), ceil( lod ) );\n\t\treturn mix( fSample, cSample, fract( lod ) );\n\t}\n\tvec3 getVolumeTransmissionRay( const in vec3 n, const in vec3 v, const in float thickness, const in float ior, const in mat4 modelMatrix ) {\n\t\tvec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior );\n\t\tvec3 modelScale;\n\t\tmodelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) );\n\t\tmodelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) );\n\t\tmodelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) );\n\t\treturn normalize( refractionVector ) * thickness * modelScale;\n\t}\n\tfloat applyIorToRoughness( const in float roughness, const in float ior ) {\n\t\treturn roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );\n\t}\n\tvec4 getTransmissionSample( const in vec2 fragCoord, const in float roughness, const in float ior ) {\n\t\tfloat lod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior );\n\t\treturn textureBicubic( transmissionSamplerMap, fragCoord.xy, lod );\n\t}\n\tvec3 volumeAttenuation( const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) {\n\t\tif ( isinf( attenuationDistance ) ) {\n\t\t\treturn vec3( 1.0 );\n\t\t} else {\n\t\t\tvec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance;\n\t\t\tvec3 transmittance = exp( - attenuationCoefficient * transmissionDistance );\t\t\treturn transmittance;\n\t\t}\n\t}\n\tvec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor,\n\t\tconst in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix,\n\t\tconst in mat4 viewMatrix, const in mat4 projMatrix, const in float dispersion, const in float ior, const in float thickness,\n\t\tconst in vec3 attenuationColor, const in float attenuationDistance ) {\n\t\tvec4 transmittedLight;\n\t\tvec3 transmittance;\n\t\t#ifdef USE_DISPERSION\n\t\t\tfloat halfSpread = ( ior - 1.0 ) * 0.025 * dispersion;\n\t\t\tvec3 iors = vec3( ior - halfSpread, ior, ior + halfSpread );\n\t\t\tfor ( int i = 0; i < 3; i ++ ) {\n\t\t\t\tvec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, iors[ i ], modelMatrix );\n\t\t\t\tvec3 refractedRayExit = position + transmissionRay;\n\t\t\t\tvec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );\n\t\t\t\tvec2 refractionCoords = ndcPos.xy / ndcPos.w;\n\t\t\t\trefractionCoords += 1.0;\n\t\t\t\trefractionCoords /= 2.0;\n\t\t\t\tvec4 transmissionSample = getTransmissionSample( refractionCoords, roughness, iors[ i ] );\n\t\t\t\ttransmittedLight[ i ] = transmissionSample[ i ];\n\t\t\t\ttransmittedLight.a += transmissionSample.a;\n\t\t\t\ttransmittance[ i ] = diffuseColor[ i ] * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance )[ i ];\n\t\t\t}\n\t\t\ttransmittedLight.a /= 3.0;\n\t\t#else\n\t\t\tvec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );\n\t\t\tvec3 refractedRayExit = position + transmissionRay;\n\t\t\tvec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );\n\t\t\tvec2 refractionCoords = ndcPos.xy / ndcPos.w;\n\t\t\trefractionCoords += 1.0;\n\t\t\trefractionCoords /= 2.0;\n\t\t\ttransmittedLight = getTransmissionSample( refractionCoords, roughness, ior );\n\t\t\ttransmittance = diffuseColor * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance );\n\t\t#endif\n\t\tvec3 attenuatedColor = transmittance * transmittedLight.rgb;\n\t\tvec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );\n\t\tfloat transmittanceFactor = ( transmittance.r + transmittance.g + transmittance.b ) / 3.0;\n\t\treturn vec4( ( 1.0 - F ) * attenuatedColor, 1.0 - ( 1.0 - transmittedLight.a ) * transmittanceFactor );\n\t}\n#endif";502503var uv_pars_fragment = "#if defined( USE_UV ) || defined( USE_ANISOTROPY )\n\tvarying vec2 vUv;\n#endif\n#ifdef USE_MAP\n\tvarying vec2 vMapUv;\n#endif\n#ifdef USE_ALPHAMAP\n\tvarying vec2 vAlphaMapUv;\n#endif\n#ifdef USE_LIGHTMAP\n\tvarying vec2 vLightMapUv;\n#endif\n#ifdef USE_AOMAP\n\tvarying vec2 vAoMapUv;\n#endif\n#ifdef USE_BUMPMAP\n\tvarying vec2 vBumpMapUv;\n#endif\n#ifdef USE_NORMALMAP\n\tvarying vec2 vNormalMapUv;\n#endif\n#ifdef USE_EMISSIVEMAP\n\tvarying vec2 vEmissiveMapUv;\n#endif\n#ifdef USE_METALNESSMAP\n\tvarying vec2 vMetalnessMapUv;\n#endif\n#ifdef USE_ROUGHNESSMAP\n\tvarying vec2 vRoughnessMapUv;\n#endif\n#ifdef USE_DIFFUSE_ROUGHNESSMAP\n\tvarying vec2 vDiffuseRoughnessMapUv;\n#endif\n#ifdef USE_ANISOTROPYMAP\n\tvarying vec2 vAnisotropyMapUv;\n#endif\n#ifdef USE_CLEARCOATMAP\n\tvarying vec2 vClearcoatMapUv;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tvarying vec2 vClearcoatNormalMapUv;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tvarying vec2 vClearcoatRoughnessMapUv;\n#endif\n#ifdef USE_IRIDESCENCEMAP\n\tvarying vec2 vIridescenceMapUv;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\tvarying vec2 vIridescenceThicknessMapUv;\n#endif\n#ifdef USE_SHEEN_COLORMAP\n\tvarying vec2 vSheenColorMapUv;\n#endif\n#ifdef USE_SHEEN_ROUGHNESSMAP\n\tvarying vec2 vSheenRoughnessMapUv;\n#endif\n#ifdef USE_SPECULARMAP\n\tvarying vec2 vSpecularMapUv;\n#endif\n#ifdef USE_SPECULAR_COLORMAP\n\tvarying vec2 vSpecularColorMapUv;\n#endif\n#ifdef USE_SPECULAR_INTENSITYMAP\n\tvarying vec2 vSpecularIntensityMapUv;\n#endif\n#ifdef USE_TRANSMISSIONMAP\n\tuniform mat3 transmissionMapTransform;\n\tvarying vec2 vTransmissionMapUv;\n#endif\n#ifdef USE_THICKNESSMAP\n\tuniform mat3 thicknessMapTransform;\n\tvarying vec2 vThicknessMapUv;\n#endif";504505var uv_pars_vertex = "#if defined( USE_UV ) || defined( USE_ANISOTROPY )\n\tvarying vec2 vUv;\n#endif\n#ifdef USE_MAP\n\tuniform mat3 mapTransform;\n\tvarying vec2 vMapUv;\n#endif\n#ifdef USE_ALPHAMAP\n\tuniform mat3 alphaMapTransform;\n\tvarying vec2 vAlphaMapUv;\n#endif\n#ifdef USE_LIGHTMAP\n\tuniform mat3 lightMapTransform;\n\tvarying vec2 vLightMapUv;\n#endif\n#ifdef USE_AOMAP\n\tuniform mat3 aoMapTransform;\n\tvarying vec2 vAoMapUv;\n#endif\n#ifdef USE_BUMPMAP\n\tuniform mat3 bumpMapTransform;\n\tvarying vec2 vBumpMapUv;\n#endif\n#ifdef USE_NORMALMAP\n\tuniform mat3 normalMapTransform;\n\tvarying vec2 vNormalMapUv;\n#endif\n#ifdef USE_DISPLACEMENTMAP\n\tuniform mat3 displacementMapTransform;\n\tvarying vec2 vDisplacementMapUv;\n#endif\n#ifdef USE_EMISSIVEMAP\n\tuniform mat3 emissiveMapTransform;\n\tvarying vec2 vEmissiveMapUv;\n#endif\n#ifdef USE_METALNESSMAP\n\tuniform mat3 metalnessMapTransform;\n\tvarying vec2 vMetalnessMapUv;\n#endif\n#ifdef USE_ROUGHNESSMAP\n\tuniform mat3 roughnessMapTransform;\n\tvarying vec2 vRoughnessMapUv;\n#endif\n#ifdef USE_DIFFUSE_ROUGHNESSMAP\n\tuniform mat3 diffuseRoughnessMapTransform;\n\tvarying vec2 vDiffuseRoughnessMapUv;\n#endif\n#ifdef USE_ANISOTROPYMAP\n\tuniform mat3 anisotropyMapTransform;\n\tvarying vec2 vAnisotropyMapUv;\n#endif\n#ifdef USE_CLEARCOATMAP\n\tuniform mat3 clearcoatMapTransform;\n\tvarying vec2 vClearcoatMapUv;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tuniform mat3 clearcoatNormalMapTransform;\n\tvarying vec2 vClearcoatNormalMapUv;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tuniform mat3 clearcoatRoughnessMapTransform;\n\tvarying vec2 vClearcoatRoughnessMapUv;\n#endif\n#ifdef USE_SHEEN_COLORMAP\n\tuniform mat3 sheenColorMapTransform;\n\tvarying vec2 vSheenColorMapUv;\n#endif\n#ifdef USE_SHEEN_ROUGHNESSMAP\n\tuniform mat3 sheenRoughnessMapTransform;\n\tvarying vec2 vSheenRoughnessMapUv;\n#endif\n#ifdef USE_IRIDESCENCEMAP\n\tuniform mat3 iridescenceMapTransform;\n\tvarying vec2 vIridescenceMapUv;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\tuniform mat3 iridescenceThicknessMapTransform;\n\tvarying vec2 vIridescenceThicknessMapUv;\n#endif\n#ifdef USE_SPECULARMAP\n\tuniform mat3 specularMapTransform;\n\tvarying vec2 vSpecularMapUv;\n#endif\n#ifdef USE_SPECULAR_COLORMAP\n\tuniform mat3 specularColorMapTransform;\n\tvarying vec2 vSpecularColorMapUv;\n#endif\n#ifdef USE_SPECULAR_INTENSITYMAP\n\tuniform mat3 specularIntensityMapTransform;\n\tvarying vec2 vSpecularIntensityMapUv;\n#endif\n#ifdef USE_TRANSMISSIONMAP\n\tuniform mat3 transmissionMapTransform;\n\tvarying vec2 vTransmissionMapUv;\n#endif\n#ifdef USE_THICKNESSMAP\n\tuniform mat3 thicknessMapTransform;\n\tvarying vec2 vThicknessMapUv;\n#endif";506507var uv_vertex = "#if defined( USE_UV ) || defined( USE_ANISOTROPY )\n\tvUv = vec3( uv, 1 ).xy;\n#endif\n#ifdef USE_MAP\n\tvMapUv = ( mapTransform * vec3( MAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_ALPHAMAP\n\tvAlphaMapUv = ( alphaMapTransform * vec3( ALPHAMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_LIGHTMAP\n\tvLightMapUv = ( lightMapTransform * vec3( LIGHTMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_AOMAP\n\tvAoMapUv = ( aoMapTransform * vec3( AOMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_BUMPMAP\n\tvBumpMapUv = ( bumpMapTransform * vec3( BUMPMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_NORMALMAP\n\tvNormalMapUv = ( normalMapTransform * vec3( NORMALMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_DISPLACEMENTMAP\n\tvDisplacementMapUv = ( displacementMapTransform * vec3( DISPLACEMENTMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_EMISSIVEMAP\n\tvEmissiveMapUv = ( emissiveMapTransform * vec3( EMISSIVEMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_METALNESSMAP\n\tvMetalnessMapUv = ( metalnessMapTransform * vec3( METALNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_ROUGHNESSMAP\n\tvRoughnessMapUv = ( roughnessMapTransform * vec3( ROUGHNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_DIFFUSE_ROUGHNESSMAP\n\tvDiffuseRoughnessMapUv = ( diffuseRoughnessMapTransform * vec3( DIFFUSE_ROUGHNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_ANISOTROPYMAP\n\tvAnisotropyMapUv = ( anisotropyMapTransform * vec3( ANISOTROPYMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_CLEARCOATMAP\n\tvClearcoatMapUv = ( clearcoatMapTransform * vec3( CLEARCOATMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tvClearcoatNormalMapUv = ( clearcoatNormalMapTransform * vec3( CLEARCOAT_NORMALMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tvClearcoatRoughnessMapUv = ( clearcoatRoughnessMapTransform * vec3( CLEARCOAT_ROUGHNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_IRIDESCENCEMAP\n\tvIridescenceMapUv = ( iridescenceMapTransform * vec3( IRIDESCENCEMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\tvIridescenceThicknessMapUv = ( iridescenceThicknessMapTransform * vec3( IRIDESCENCE_THICKNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SHEEN_COLORMAP\n\tvSheenColorMapUv = ( sheenColorMapTransform * vec3( SHEEN_COLORMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SHEEN_ROUGHNESSMAP\n\tvSheenRoughnessMapUv = ( sheenRoughnessMapTransform * vec3( SHEEN_ROUGHNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SPECULARMAP\n\tvSpecularMapUv = ( specularMapTransform * vec3( SPECULARMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SPECULAR_COLORMAP\n\tvSpecularColorMapUv = ( specularColorMapTransform * vec3( SPECULAR_COLORMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SPECULAR_INTENSITYMAP\n\tvSpecularIntensityMapUv = ( specularIntensityMapTransform * vec3( SPECULAR_INTENSITYMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_TRANSMISSIONMAP\n\tvTransmissionMapUv = ( transmissionMapTransform * vec3( TRANSMISSIONMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_THICKNESSMAP\n\tvThicknessMapUv = ( thicknessMapTransform * vec3( THICKNESSMAP_UV, 1 ) ).xy;\n#endif";508509var worldpos_vertex = "#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ) || defined ( USE_TRANSMISSION ) || NUM_SPOT_LIGHT_COORDS > 0\n\tvec4 worldPosition = vec4( transformed, 1.0 );\n\t#ifdef USE_BATCHING\n\t\tworldPosition = batchingMatrix * worldPosition;\n\t#endif\n\t#ifdef USE_INSTANCING\n\t\tworldPosition = instanceMatrix * worldPosition;\n\t#endif\n\tworldPosition = modelMatrix * worldPosition;\n#endif";510511const vertex$h = "varying vec2 vUv;\nuniform mat3 uvTransform;\nvoid main() {\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n\tgl_Position = vec4( position.xy, 1.0, 1.0 );\n}";512513const fragment$h = "uniform sampler2D t2D;\nuniform float backgroundIntensity;\nvarying vec2 vUv;\nvoid main() {\n\tvec4 texColor = texture2D( t2D, vUv );\n\t#ifdef DECODE_VIDEO_TEXTURE\n\t\ttexColor = 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 );\n\t#endif\n\ttexColor.rgb *= backgroundIntensity;\n\tgl_FragColor = texColor;\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n}";514515const vertex$g = "varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\tgl_Position.z = gl_Position.w;\n}";516517const fragment$g = "uniform float backgroundBlurriness;\nuniform float backgroundIntensity;\nuniform mat3 backgroundRotation;\nvarying vec3 vWorldDirection;\n#include <envmap_common_pars_fragment>\nvoid main() {\n\t#ifdef ENVMAP_TYPE_PMREM\n\t\tvec4 texColor = textureLod( envMap, backgroundRotation * vWorldDirection, roughnessToMip( backgroundBlurriness ) );\n\t#else\n\t\tvec4 texColor = textureCube( envMap, backgroundRotation * vWorldDirection );\n\t#endif\n\ttexColor.rgb *= backgroundIntensity;\n\tgl_FragColor = texColor;\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n}";518519const vertex$f = "varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\tgl_Position.z = gl_Position.w;\n}";520521const fragment$f = "uniform samplerCube tCube;\nuniform float tFlip;\nuniform float opacity;\nvarying vec3 vWorldDirection;\nvoid main() {\n\tvec4 texColor = textureCube( tCube, vec3( tFlip * vWorldDirection.x, vWorldDirection.yz ) );\n\tgl_FragColor = texColor;\n\tgl_FragColor.a *= opacity;\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n}";522523const vertex$e = "#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\t#include <uv_vertex>\n\t#include <batching_vertex>\n\t#include <skinbase_vertex>\n\t#include <morphinstance_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvHighPrecisionZW = gl_Position.zw;\n}";524525const fragment$e = "#if DEPTH_PACKING == 3200\n\tuniform float opacity;\n#endif\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#include <clipping_planes_fragment>\n\t#if DEPTH_PACKING == 3200\n\t\tdiffuseColor.a = opacity;\n\t#endif\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <logdepthbuf_fragment>\n\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\tfloat fragCoordZ = vHighPrecisionZW[ 0 ] / vHighPrecisionZW[ 1 ];\n\t#else\n\t\tfloat fragCoordZ = 0.5 * vHighPrecisionZW[ 0 ] / vHighPrecisionZW[ 1 ] + 0.5;\n\t#endif\n\t#if DEPTH_PACKING == 3200\n\t\tgl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );\n\t#elif DEPTH_PACKING == 3201\n\t\tgl_FragColor = packDepthToRGBA( fragCoordZ );\n\t#elif DEPTH_PACKING == 3202\n\t\tgl_FragColor = vec4( packDepthToRGB( fragCoordZ ), 1.0 );\n\t#elif DEPTH_PACKING == 3203\n\t\tgl_FragColor = vec4( packDepthToRG( fragCoordZ ), 0.0, 1.0 );\n\t#endif\n}";526527const vertex$d = "#define DISTANCE\nvarying vec3 vWorldPosition;\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <batching_vertex>\n\t#include <skinbase_vertex>\n\t#include <morphinstance_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <worldpos_vertex>\n\t#include <clipping_planes_vertex>\n\tvWorldPosition = worldPosition.xyz;\n}";528529const fragment$d = "#define DISTANCE\nuniform vec3 referencePosition;\nuniform float nearDistance;\nuniform float farDistance;\nvarying vec3 vWorldPosition;\n#include <common>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#include <clipping_planes_fragment>\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\tfloat dist = length( vWorldPosition - referencePosition );\n\tdist = ( dist - nearDistance ) / ( farDistance - nearDistance );\n\tdist = saturate( dist );\n\tgl_FragColor = vec4( dist, 0.0, 0.0, 1.0 );\n}";530531const vertex$c = "varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n}";532533const fragment$c = "uniform sampler2D tEquirect;\nvarying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvec3 direction = normalize( vWorldDirection );\n\tvec2 sampleUV = equirectUv( direction );\n\tgl_FragColor = texture2D( tEquirect, sampleUV );\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n}";534535const vertex$b = "uniform float scale;\nattribute float lineDistance;\nvarying float vLineDistance;\n#include <common>\n#include <uv_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\tvLineDistance = scale * lineDistance;\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphcolor_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}";536537const fragment$b = "uniform vec3 diffuse;\nuniform float opacity;\nuniform float dashSize;\nuniform float totalSize;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tif ( mod( vLineDistance, totalSize ) > dashSize ) {\n\t\tdiscard;\n\t}\n\tvec3 outgoingLight = vec3( 0.0 );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n}";538539const vertex$a = "#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphcolor_vertex>\n\t#include <batching_vertex>\n\t#if defined ( USE_ENVMAP ) || defined ( USE_SKINNING )\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinbase_vertex>\n\t\t#include <skinnormal_vertex>\n\t\t#include <defaultnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <fog_vertex>\n}";540541const fragment$a = "uniform vec3 diffuse;\nuniform float opacity;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <specularmap_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\t#ifdef USE_LIGHTMAP\n\t\tvec4 lightMapTexel = texture2D( lightMap, vLightMapUv );\n\t\treflectedLight.indirectDiffuse += lightMapTexel.rgb * lightMapIntensity * RECIPROCAL_PI;\n\t#else\n\t\treflectedLight.indirectDiffuse += vec3( 1.0 );\n\t#endif\n\t#include <aomap_fragment>\n\treflectedLight.indirectDiffuse *= diffuseColor.rgb;\n\tvec3 outgoingLight = reflectedLight.indirectDiffuse;\n\t#include <envmap_fragment>\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";542543const vertex$9 = "#define LAMBERT\nvarying vec3 vViewPosition;\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphcolor_vertex>\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";544545const fragment$9 = "#define LAMBERT\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <envmap_physical_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_lambert_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <specularmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_lambert_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";546547const vertex$8 = "#define MATCAP\nvarying vec3 vViewPosition;\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <color_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphcolor_vertex>\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n\tvViewPosition = - mvPosition.xyz;\n}";548549const fragment$8 = "#define MATCAP\nuniform vec3 diffuse;\nuniform float opacity;\nuniform sampler2D matcap;\nvarying vec3 vViewPosition;\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <fog_pars_fragment>\n#include <normal_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tvec3 viewDir = normalize( vViewPosition );\n\tvec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) );\n\tvec3 y = cross( viewDir, x );\n\tvec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5;\n\t#ifdef USE_MATCAP\n\t\tvec4 matcapColor = texture2D( matcap, uv );\n\t#else\n\t\tvec4 matcapColor = vec4( vec3( mix( 0.2, 0.8, uv.y ) ), 1.0 );\n\t#endif\n\tvec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";550551const vertex$7 = "#define NORMAL\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )\n\tvarying vec3 vViewPosition;\n#endif\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n}";552553const fragment$7 = "#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )\n\tvarying vec3 vViewPosition;\n#endif\n#include <uv_pars_fragment>\n#include <normal_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( 0.0, 0.0, 0.0, opacity );\n\t#include <clipping_planes_fragment>\n\t#include <logdepthbuf_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tgl_FragColor = vec4( normalize( normal ) * 0.5 + 0.5, diffuseColor.a );\n\t#ifdef OPAQUE\n\t\tgl_FragColor.a = 1.0;\n\t#endif\n}";554555const vertex$6 = "#define PHONG\nvarying vec3 vViewPosition;\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphcolor_vertex>\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";556557const fragment$6 = "#define PHONG\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 specular;\nuniform float shininess;\nuniform float opacity;\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <envmap_physical_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_phong_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <specularmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_phong_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";558559const vertex$5 = "#define STANDARD\nvarying vec3 vViewPosition;\n#ifdef USE_TRANSMISSION\n\tvarying vec3 vWorldPosition;\n#endif\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphcolor_vertex>\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n#ifdef USE_TRANSMISSION\n\tvWorldPosition = worldPosition.xyz;\n#endif\n}";560561const fragment$5 = "#define STANDARD\n#ifdef PHYSICAL\n\t#define IOR\n\t#define USE_SPECULAR\n#endif\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifdef IOR\n\tuniform float ior;\n#endif\n#ifdef USE_SPECULAR\n\tuniform float specularIntensity;\n\tuniform vec3 specularColor;\n\t#ifdef USE_SPECULAR_COLORMAP\n\t\tuniform sampler2D specularColorMap;\n\t#endif\n\t#ifdef USE_SPECULAR_INTENSITYMAP\n\t\tuniform sampler2D specularIntensityMap;\n\t#endif\n#endif\n#ifdef USE_CLEARCOAT\n\tuniform float clearcoat;\n\tuniform float clearcoatRoughness;\n#endif\n#ifdef USE_DIFFUSE_ROUGHNESS\n\tuniform float diffuseRoughness;\n\t#ifdef USE_DIFFUSE_ROUGHNESSMAP\n\t\tuniform sampler2D diffuseRoughnessMap;\n\t#endif\n#endif\n#ifdef USE_DISPERSION\n\tuniform float dispersion;\n#endif\n#ifdef USE_RETROREFLECTION\n\tuniform float retroreflectivity;\n#endif\n#ifdef USE_IRIDESCENCE\n\tuniform float iridescence;\n\tuniform float iridescenceIOR;\n\tuniform float iridescenceThicknessMinimum;\n\tuniform float iridescenceThicknessMaximum;\n#endif\n#ifdef USE_SHEEN\n\tuniform vec3 sheenColor;\n\tuniform float sheenRoughness;\n\t#ifdef USE_SHEEN_COLORMAP\n\t\tuniform sampler2D sheenColorMap;\n\t#endif\n\t#ifdef USE_SHEEN_ROUGHNESSMAP\n\t\tuniform sampler2D sheenRoughnessMap;\n\t#endif\n#endif\n#ifdef USE_ANISOTROPY\n\tuniform vec2 anisotropyVector;\n\t#ifdef USE_ANISOTROPYMAP\n\t\tuniform sampler2D anisotropyMap;\n\t#endif\n#endif\nvarying vec3 vViewPosition;\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <iridescence_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_physical_pars_fragment>\n#include <fog_pars_fragment>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_physical_pars_fragment>\n#include <transmission_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <clearcoat_pars_fragment>\n#include <iridescence_pars_fragment>\n#include <roughnessmap_pars_fragment>\n#include <metalnessmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <roughnessmap_fragment>\n\t#include <metalnessmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <clearcoat_normal_fragment_begin>\n\t#include <clearcoat_normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_physical_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;\n\tvec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;\n\t#include <transmission_fragment>\n\tvec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;\n\t#ifdef USE_SHEEN\n \n\t\toutgoingLight = outgoingLight + sheenSpecularDirect + sheenSpecularIndirect;\n \n \t#endif\n\t#ifdef USE_CLEARCOAT\n\t\tfloat dotNVcc = saturate( dot( geometryClearcoatNormal, geometryViewDir ) );\n\t\tvec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );\n\t\toutgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + ( clearcoatSpecularDirect + clearcoatSpecularIndirect ) * material.clearcoat;\n\t#endif\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";562563const vertex$4 = "#define TOON\nvarying vec3 vViewPosition;\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphcolor_vertex>\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";564565const fragment$4 = "#define TOON\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <gradientmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_toon_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_toon_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";566567const vertex$3 = "uniform float size;\nuniform float scale;\n#include <common>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\n#ifdef USE_POINTS_UV\n\tvarying vec2 vUv;\n\tuniform mat3 uvTransform;\n#endif\nvoid main() {\n\t#ifdef USE_POINTS_UV\n\t\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n\t#endif\n\t#include <color_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphcolor_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <project_vertex>\n\tgl_PointSize = size;\n\t#ifdef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z );\n\t#endif\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <fog_vertex>\n}";568569const fragment$3 = "uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <color_pars_fragment>\n#include <map_particle_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\t#include <logdepthbuf_fragment>\n\t#include <map_particle_fragment>\n\t#include <color_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n}";570571const vertex$2 = "#include <common>\n#include <batching_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <shadowmap_pars_vertex>\nvoid main() {\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";572573const fragment$2 = "uniform vec3 color;\nuniform float opacity;\n#include <common>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <logdepthbuf_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\nvoid main() {\n\t#include <logdepthbuf_fragment>\n\tgl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n}";574575const vertex$1 = "uniform float rotation;\nuniform vec2 center;\n#include <common>\n#include <uv_pars_vertex>\n#include <fog_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\tvec4 mvPosition = modelViewMatrix[ 3 ];\n\tvec2 scale = vec2( length( modelMatrix[ 0 ].xyz ), length( modelMatrix[ 1 ].xyz ) );\n\t#ifndef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) scale *= - mvPosition.z;\n\t#endif\n\tvec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;\n\tvec2 rotatedPosition;\n\trotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n\trotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n\tmvPosition.xy += rotatedPosition;\n\tgl_Position = projectionMatrix * mvPosition;\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}";576577const fragment$1 = "uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n}";578579const ShaderChunk = {580 alphahash_fragment: alphahash_fragment,581 alphahash_pars_fragment: alphahash_pars_fragment,582 alphamap_fragment: alphamap_fragment,583 alphamap_pars_fragment: alphamap_pars_fragment,584 alphatest_fragment: alphatest_fragment,585 alphatest_pars_fragment: alphatest_pars_fragment,586 aomap_fragment: aomap_fragment,587 aomap_pars_fragment: aomap_pars_fragment,588 batching_pars_vertex: batching_pars_vertex,589 batching_vertex: batching_vertex,590 begin_vertex: begin_vertex,591 beginnormal_vertex: beginnormal_vertex,592 bsdfs: bsdfs,593 iridescence_fragment: iridescence_fragment,594 bumpmap_pars_fragment: bumpmap_pars_fragment,595 clipping_planes_fragment: clipping_planes_fragment,596 clipping_planes_pars_fragment: clipping_planes_pars_fragment,597 clipping_planes_pars_vertex: clipping_planes_pars_vertex,598 clipping_planes_vertex: clipping_planes_vertex,599 color_fragment: color_fragment,600 color_pars_fragment: color_pars_fragment,601 color_pars_vertex: color_pars_vertex,602 color_vertex: color_vertex,603 common: common,604 defaultnormal_vertex: defaultnormal_vertex,605 displacementmap_pars_vertex: displacementmap_pars_vertex,606 displacementmap_vertex: displacementmap_vertex,607 emissivemap_fragment: emissivemap_fragment,608 emissivemap_pars_fragment: emissivemap_pars_fragment,609 colorspace_fragment: colorspace_fragment,610 colorspace_pars_fragment: colorspace_pars_fragment,611 envmap_fragment: envmap_fragment,612 envmap_common_pars_fragment: envmap_common_pars_fragment,613 envmap_pars_fragment: envmap_pars_fragment,614 envmap_pars_vertex: envmap_pars_vertex,615 envmap_physical_pars_fragment: envmap_physical_pars_fragment,616 envmap_vertex: envmap_vertex,617 fog_vertex: fog_vertex,618 fog_pars_vertex: fog_pars_vertex,619 fog_fragment: fog_fragment,620 fog_pars_fragment: fog_pars_fragment,621 gradientmap_pars_fragment: gradientmap_pars_fragment,622 lightmap_pars_fragment: lightmap_pars_fragment,623 lights_lambert_fragment: lights_lambert_fragment,624 lights_lambert_pars_fragment: lights_lambert_pars_fragment,625 lights_pars_begin: lights_pars_begin,626 lights_toon_fragment: lights_toon_fragment,627 lights_toon_pars_fragment: lights_toon_pars_fragment,628 lights_phong_fragment: lights_phong_fragment,629 lights_phong_pars_fragment: lights_phong_pars_fragment,630 lights_physical_fragment: lights_physical_fragment,631 lights_physical_pars_fragment: lights_physical_pars_fragment,632 lights_fragment_begin: lights_fragment_begin,633 lights_fragment_maps: lights_fragment_maps,634 lights_fragment_end: lights_fragment_end,635 lightprobes_pars_fragment: lightprobes_pars_fragment,636 logdepthbuf_fragment: logdepthbuf_fragment,637 logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,638 logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,639 logdepthbuf_vertex: logdepthbuf_vertex,640 map_fragment: map_fragment,641 map_pars_fragment: map_pars_fragment,642 map_particle_fragment: map_particle_fragment,643 map_particle_pars_fragment: map_particle_pars_fragment,644 metalnessmap_fragment: metalnessmap_fragment,645 metalnessmap_pars_fragment: metalnessmap_pars_fragment,646 morphinstance_vertex: morphinstance_vertex,647 morphcolor_vertex: morphcolor_vertex,648 morphnormal_vertex: morphnormal_vertex,649 morphtarget_pars_vertex: morphtarget_pars_vertex,650 morphtarget_vertex: morphtarget_vertex,651 normal_fragment_begin: normal_fragment_begin,652 normal_fragment_maps: normal_fragment_maps,653 normal_pars_fragment: normal_pars_fragment,654 normal_pars_vertex: normal_pars_vertex,655 normal_vertex: normal_vertex,656 normalmap_pars_fragment: normalmap_pars_fragment,657 clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,658 clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,659 clearcoat_pars_fragment: clearcoat_pars_fragment,660 iridescence_pars_fragment: iridescence_pars_fragment,661 opaque_fragment: opaque_fragment,662 packing: packing,663 premultiplied_alpha_fragment: premultiplied_alpha_fragment,664 project_vertex: project_vertex,665 dithering_fragment: dithering_fragment,666 dithering_pars_fragment: dithering_pars_fragment,667 roughnessmap_fragment: roughnessmap_fragment,668 roughnessmap_pars_fragment: roughnessmap_pars_fragment,669 shadowmap_pars_fragment: shadowmap_pars_fragment,670 shadowmap_pars_vertex: shadowmap_pars_vertex,671 shadowmap_vertex: shadowmap_vertex,672 shadowmask_pars_fragment: shadowmask_pars_fragment,673 skinbase_vertex: skinbase_vertex,674 skinning_pars_vertex: skinning_pars_vertex,675 skinning_vertex: skinning_vertex,676 skinnormal_vertex: skinnormal_vertex,677 specularmap_fragment: specularmap_fragment,678 specularmap_pars_fragment: specularmap_pars_fragment,679 tonemapping_fragment: tonemapping_fragment,680 tonemapping_pars_fragment: tonemapping_pars_fragment,681 transmission_fragment: transmission_fragment,682 transmission_pars_fragment: transmission_pars_fragment,683 uv_pars_fragment: uv_pars_fragment,684 uv_pars_vertex: uv_pars_vertex,685 uv_vertex: uv_vertex,686 worldpos_vertex: worldpos_vertex,687688 background_vert: vertex$h,689 background_frag: fragment$h,690 backgroundCube_vert: vertex$g,691 backgroundCube_frag: fragment$g,692 cube_vert: vertex$f,693 cube_frag: fragment$f,694 depth_vert: vertex$e,695 depth_frag: fragment$e,696 distance_vert: vertex$d,697 distance_frag: fragment$d,698 equirect_vert: vertex$c,699 equirect_frag: fragment$c,700 linedashed_vert: vertex$b,701 linedashed_frag: fragment$b,702 meshbasic_vert: vertex$a,703 meshbasic_frag: fragment$a,704 meshlambert_vert: vertex$9,705 meshlambert_frag: fragment$9,706 meshmatcap_vert: vertex$8,707 meshmatcap_frag: fragment$8,708 meshnormal_vert: vertex$7,709 meshnormal_frag: fragment$7,710 meshphong_vert: vertex$6,711 meshphong_frag: fragment$6,712 meshphysical_vert: vertex$5,713 meshphysical_frag: fragment$5,714 meshtoon_vert: vertex$4,715 meshtoon_frag: fragment$4,716 points_vert: vertex$3,717 points_frag: fragment$3,718 shadow_vert: vertex$2,719 shadow_frag: fragment$2,720 sprite_vert: vertex$1,721 sprite_frag: fragment$1722};723724725const UniformsLib = {726727 common: {728729 diffuse: { value: new Color( 0xffffff ) },730 opacity: { value: 1.0 },731732 map: { value: null },733 mapTransform: { value: new Matrix3() },734735 alphaMap: { value: null },736 alphaMapTransform: { value: new Matrix3() },737738 alphaTest: { value: 0 }739740 },741742 specularmap: {743744 specularMap: { value: null },745 specularMapTransform: { value: new Matrix3() }746747 },748749 envmap: {750751 envMap: { value: null },752 envMapRotation: { value: new Matrix3() },753 reflectivity: { value: 1.0 }, 754 ior: { value: 1.5 }, 755 refractionRatio: { value: 0.98 }, 756 dfgLUT: { value: null } 757758 },759760 aomap: {761762 aoMap: { value: null },763 aoMapIntensity: { value: 1 },764 aoMapTransform: { value: new Matrix3() }765766 },767768 lightmap: {769770 lightMap: { value: null },771 lightMapIntensity: { value: 1 },772 lightMapTransform: { value: new Matrix3() }773774 },775776 bumpmap: {777778 bumpMap: { value: null },779 bumpMapTransform: { value: new Matrix3() },780 bumpScale: { value: 1 }781782 },783784 normalmap: {785786 normalMap: { value: null },787 normalMapTransform: { value: new Matrix3() },788 normalScale: { value: new Vector2( 1, 1 ) }789790 },791792 displacementmap: {793794 displacementMap: { value: null },795 displacementMapTransform: { value: new Matrix3() },796 displacementScale: { value: 1 },797 displacementBias: { value: 0 }798799 },800801 emissivemap: {802803 emissiveMap: { value: null },804 emissiveMapTransform: { value: new Matrix3() }805806 },807808 metalnessmap: {809810 metalnessMap: { value: null },811 metalnessMapTransform: { value: new Matrix3() }812813 },814815 roughnessmap: {816817 roughnessMap: { value: null },818 roughnessMapTransform: { value: new Matrix3() }819820 },821822 gradientmap: {823824 gradientMap: { value: null }825826 },827828 fog: {829830 fogDensity: { value: 0.00025 },831 fogNear: { value: 1 },832 fogFar: { value: 2000 },833 fogColor: { value: new Color( 0xffffff ) }834835 },836837 lights: {838839 ambientLightColor: { value: [] },840841 lightProbe: { value: [] },842843 sunLights: { value: [], properties: {844 direction: {},845 color: {}846 } },847848 sunLightShadows: { value: [], properties: {849 shadowIntensity: 1,850 shadowBias: {},851 shadowNormalBias: {},852 shadowRadius: {},853 shadowMapSize: {}854 } },855856 sunShadowMatrix: { value: [] },857 sunShadowCascade: { value: [] },858859 directionalLights: { value: [], properties: {860 direction: {},861 color: {}862 } },863864 directionalLightShadows: { value: [], properties: {865 shadowIntensity: 1,866 shadowBias: {},867 shadowNormalBias: {},868 shadowRadius: {},869 shadowMapSize: {}870 } },871872 directionalShadowMatrix: { value: [] },873874 spotLights: { value: [], properties: {875 color: {},876 position: {},877 direction: {},878 distance: {},879 coneCos: {},880 penumbraCos: {},881 decay: {}882 } },883884 spotLightShadows: { value: [], properties: {885 shadowIntensity: 1,886 shadowBias: {},887 shadowNormalBias: {},888 shadowRadius: {},889 shadowMapSize: {}890 } },891892 spotLightMap: { value: [] },893 spotLightMatrix: { value: [] },894895 pointLights: { value: [], properties: {896 color: {},897 position: {},898 decay: {},899 distance: {}900 } },901902 pointLightShadows: { value: [], properties: {903 shadowIntensity: 1,904 shadowBias: {},905 shadowNormalBias: {},906 shadowRadius: {},907 shadowMapSize: {},908 shadowCameraNear: {},909 shadowCameraFar: {}910 } },911912 pointShadowMatrix: { value: [] },913914 hemisphereLights: { value: [], properties: {915 direction: {},916 skyColor: {},917 groundColor: {}918 } },919920 921 rectAreaLights: { value: [], properties: {922 color: {},923 position: {},924 width: {},925 height: {}926 } },927928 ltc_1: { value: null },929 ltc_2: { value: null },930931 probesSH: { value: [] },932 probesMin: { value: [] },933 probesMax: { value: [] },934 probesResolution: { value: [] }935936 },937938 points: {939940 diffuse: { value: new Color( 0xffffff ) },941 opacity: { value: 1.0 },942 size: { value: 1.0 },943 scale: { value: 1.0 },944 map: { value: null },945 alphaMap: { value: null },946 alphaMapTransform: { value: new Matrix3() },947 alphaTest: { value: 0 },948 uvTransform: { value: new Matrix3() }949950 },951952 sprite: {953954 diffuse: { value: new Color( 0xffffff ) },955 opacity: { value: 1.0 },956 center: { value: new Vector2( 0.5, 0.5 ) },957 rotation: { value: 0.0 },958 map: { value: null },959 mapTransform: { value: new Matrix3() },960 alphaMap: { value: null },961 alphaMapTransform: { value: new Matrix3() },962 alphaTest: { value: 0 }963964 }965966};967968const ShaderLib = {969970 basic: {971972 uniforms: mergeUniforms( [973 UniformsLib.common,974 UniformsLib.specularmap,975 UniformsLib.envmap,976 UniformsLib.aomap,977 UniformsLib.lightmap,978 UniformsLib.fog979 ] ),980981 vertexShader: ShaderChunk.meshbasic_vert,982 fragmentShader: ShaderChunk.meshbasic_frag983984 },985986 lambert: {987988 uniforms: mergeUniforms( [989 UniformsLib.common,990 UniformsLib.specularmap,991 UniformsLib.envmap,992 UniformsLib.aomap,993 UniformsLib.lightmap,994 UniformsLib.emissivemap,995 UniformsLib.bumpmap,996 UniformsLib.normalmap,997 UniformsLib.displacementmap,998 UniformsLib.fog,999 UniformsLib.lights,1000 {1001 emissive: { value: new Color( 0x000000 ) },1002 envMapIntensity: { value: 1 }1003 }1004 ] ),10051006 vertexShader: ShaderChunk.meshlambert_vert,1007 fragmentShader: ShaderChunk.meshlambert_frag10081009 },10101011 phong: {10121013 uniforms: mergeUniforms( [1014 UniformsLib.common,1015 UniformsLib.specularmap,1016 UniformsLib.envmap,1017 UniformsLib.aomap,1018 UniformsLib.lightmap,1019 UniformsLib.emissivemap,1020 UniformsLib.bumpmap,1021 UniformsLib.normalmap,1022 UniformsLib.displacementmap,1023 UniformsLib.fog,1024 UniformsLib.lights,1025 {1026 emissive: { value: new Color( 0x000000 ) },1027 specular: { value: new Color( 0x111111 ) },1028 shininess: { value: 30 },1029 envMapIntensity: { value: 1 }1030 }1031 ] ),10321033 vertexShader: ShaderChunk.meshphong_vert,1034 fragmentShader: ShaderChunk.meshphong_frag10351036 },10371038 standard: {10391040 uniforms: mergeUniforms( [1041 UniformsLib.common,1042 UniformsLib.envmap,1043 UniformsLib.aomap,1044 UniformsLib.lightmap,1045 UniformsLib.emissivemap,1046 UniformsLib.bumpmap,1047 UniformsLib.normalmap,1048 UniformsLib.displacementmap,1049 UniformsLib.roughnessmap,1050 UniformsLib.metalnessmap,1051 UniformsLib.fog,1052 UniformsLib.lights,1053 {1054 emissive: { value: new Color( 0x000000 ) },1055 roughness: { value: 1.0 },1056 metalness: { value: 0.0 },1057 envMapIntensity: { value: 1 }1058 }1059 ] ),10601061 vertexShader: ShaderChunk.meshphysical_vert,1062 fragmentShader: ShaderChunk.meshphysical_frag10631064 },10651066 toon: {10671068 uniforms: mergeUniforms( [1069 UniformsLib.common,1070 UniformsLib.aomap,1071 UniformsLib.lightmap,1072 UniformsLib.emissivemap,1073 UniformsLib.bumpmap,1074 UniformsLib.normalmap,1075 UniformsLib.displacementmap,1076 UniformsLib.gradientmap,1077 UniformsLib.fog,1078 UniformsLib.lights,1079 {1080 emissive: { value: new Color( 0x000000 ) }1081 }1082 ] ),10831084 vertexShader: ShaderChunk.meshtoon_vert,1085 fragmentShader: ShaderChunk.meshtoon_frag10861087 },10881089 matcap: {10901091 uniforms: mergeUniforms( [1092 UniformsLib.common,1093 UniformsLib.bumpmap,1094 UniformsLib.normalmap,1095 UniformsLib.displacementmap,1096 UniformsLib.fog,1097 {1098 matcap: { value: null }1099 }1100 ] ),11011102 vertexShader: ShaderChunk.meshmatcap_vert,1103 fragmentShader: ShaderChunk.meshmatcap_frag11041105 },11061107 points: {11081109 uniforms: mergeUniforms( [1110 UniformsLib.points,1111 UniformsLib.fog1112 ] ),11131114 vertexShader: ShaderChunk.points_vert,1115 fragmentShader: ShaderChunk.points_frag11161117 },11181119 dashed: {11201121 uniforms: mergeUniforms( [1122 UniformsLib.common,1123 UniformsLib.fog,1124 {1125 scale: { value: 1 },1126 dashSize: { value: 1 },1127 totalSize: { value: 2 }1128 }1129 ] ),11301131 vertexShader: ShaderChunk.linedashed_vert,1132 fragmentShader: ShaderChunk.linedashed_frag11331134 },11351136 depth: {11371138 uniforms: mergeUniforms( [1139 UniformsLib.common,1140 UniformsLib.displacementmap1141 ] ),11421143 vertexShader: ShaderChunk.depth_vert,1144 fragmentShader: ShaderChunk.depth_frag11451146 },11471148 normal: {11491150 uniforms: mergeUniforms( [1151 UniformsLib.common,1152 UniformsLib.bumpmap,1153 UniformsLib.normalmap,1154 UniformsLib.displacementmap,1155 {1156 opacity: { value: 1.0 }1157 }1158 ] ),11591160 vertexShader: ShaderChunk.meshnormal_vert,1161 fragmentShader: ShaderChunk.meshnormal_frag11621163 },11641165 sprite: {11661167 uniforms: mergeUniforms( [1168 UniformsLib.sprite,1169 UniformsLib.fog1170 ] ),11711172 vertexShader: ShaderChunk.sprite_vert,1173 fragmentShader: ShaderChunk.sprite_frag11741175 },11761177 background: {11781179 uniforms: {1180 uvTransform: { value: new Matrix3() },1181 t2D: { value: null },1182 backgroundIntensity: { value: 1 }1183 },11841185 vertexShader: ShaderChunk.background_vert,1186 fragmentShader: ShaderChunk.background_frag11871188 },11891190 backgroundCube: {11911192 uniforms: {1193 envMap: { value: null },1194 backgroundBlurriness: { value: 0 },1195 backgroundIntensity: { value: 1 },1196 backgroundRotation: { value: new Matrix3() }1197 },11981199 vertexShader: ShaderChunk.backgroundCube_vert,1200 fragmentShader: ShaderChunk.backgroundCube_frag12011202 },12031204 cube: {12051206 uniforms: {1207 tCube: { value: null },1208 tFlip: { value: -1 },1209 opacity: { value: 1.0 }1210 },12111212 vertexShader: ShaderChunk.cube_vert,1213 fragmentShader: ShaderChunk.cube_frag12141215 },12161217 equirect: {12181219 uniforms: {1220 tEquirect: { value: null },1221 },12221223 vertexShader: ShaderChunk.equirect_vert,1224 fragmentShader: ShaderChunk.equirect_frag12251226 },12271228 distance: {12291230 uniforms: mergeUniforms( [1231 UniformsLib.common,1232 UniformsLib.displacementmap,1233 {1234 referencePosition: { value: new Vector3() },1235 nearDistance: { value: 1 },1236 farDistance: { value: 1000 }1237 }1238 ] ),12391240 vertexShader: ShaderChunk.distance_vert,1241 fragmentShader: ShaderChunk.distance_frag12421243 },12441245 shadow: {12461247 uniforms: mergeUniforms( [1248 UniformsLib.lights,1249 UniformsLib.fog,1250 {1251 color: { value: new Color( 0x00000 ) },1252 opacity: { value: 1.0 }1253 },1254 ] ),12551256 vertexShader: ShaderChunk.shadow_vert,1257 fragmentShader: ShaderChunk.shadow_frag12581259 }12601261};12621263ShaderLib.physical = {12641265 uniforms: mergeUniforms( [1266 ShaderLib.standard.uniforms,1267 {1268 clearcoat: { value: 0 },1269 clearcoatMap: { value: null },1270 clearcoatMapTransform: { value: new Matrix3() },1271 clearcoatNormalMap: { value: null },1272 clearcoatNormalMapTransform: { value: new Matrix3() },1273 clearcoatNormalScale: { value: new Vector2( 1, 1 ) },1274 clearcoatRoughness: { value: 0 },1275 clearcoatRoughnessMap: { value: null },1276 clearcoatRoughnessMapTransform: { value: new Matrix3() },1277 diffuseRoughness: { value: 0 },1278 diffuseRoughnessMap: { value: null },1279 diffuseRoughnessMapTransform: { value: new Matrix3() },1280 dispersion: { value: 0 },1281 retroreflectivity: { value: 0 },1282 iridescence: { value: 0 },1283 iridescenceMap: { value: null },1284 iridescenceMapTransform: { value: new Matrix3() },1285 iridescenceIOR: { value: 1.3 },1286 iridescenceThicknessMinimum: { value: 100 },1287 iridescenceThicknessMaximum: { value: 400 },1288 iridescenceThicknessMap: { value: null },1289 iridescenceThicknessMapTransform: { value: new Matrix3() },1290 sheen: { value: 0 },1291 sheenColor: { value: new Color( 0x000000 ) },1292 sheenColorMap: { value: null },1293 sheenColorMapTransform: { value: new Matrix3() },1294 sheenRoughness: { value: 1 },1295 sheenRoughnessMap: { value: null },1296 sheenRoughnessMapTransform: { value: new Matrix3() },1297 transmission: { value: 0 },1298 transmissionMap: { value: null },1299 transmissionMapTransform: { value: new Matrix3() },1300 transmissionSamplerSize: { value: new Vector2() },1301 transmissionSamplerMap: { value: null },1302 thickness: { value: 0 },1303 thicknessMap: { value: null },1304 thicknessMapTransform: { value: new Matrix3() },1305 attenuationDistance: { value: 0 },1306 attenuationColor: { value: new Color( 0x000000 ) },1307 specularColor: { value: new Color( 1, 1, 1 ) },1308 specularColorMap: { value: null },1309 specularColorMapTransform: { value: new Matrix3() },1310 specularIntensity: { value: 1 },1311 specularIntensityMap: { value: null },1312 specularIntensityMapTransform: { value: new Matrix3() },1313 anisotropyVector: { value: new Vector2() },1314 anisotropyMap: { value: null },1315 anisotropyMapTransform: { value: new Matrix3() },1316 }1317 ] ),13181319 vertexShader: ShaderChunk.meshphysical_vert,1320 fragmentShader: ShaderChunk.meshphysical_frag13211322};13231324const _rgb = { r: 0, b: 0, g: 0 };1325const _m1$1 = new Matrix4();1326const _m$1 = new Matrix3();13271328_m$1.set( -1, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0 );13291330function WebGLBackground( renderer, environments, state, objects, alpha, premultipliedAlpha ) {13311332 const clearColor = new Color( 0x000000 );1333 let clearAlpha = alpha === true ? 0 : 1;13341335 let planeMesh;1336 let boxMesh;13371338 let currentBackground = null;1339 let currentBackgroundVersion = 0;1340 let currentTonemapping = null;13411342 function getBackground( scene ) {13431344 let background = scene.isScene === true ? scene.background : null;13451346 if ( background && background.isTexture ) {13471348 const usePMREM = scene.backgroundBlurriness > 0; 1349 background = environments.get( background, usePMREM );13501351 }13521353 return background;13541355 }13561357 function render( scene ) {13581359 let forceClear = false;1360 const background = getBackground( scene );13611362 if ( background === null ) {13631364 setClear( clearColor, clearAlpha );13651366 } else if ( background && background.isColor ) {13671368 setClear( background, 1 );1369 forceClear = true;13701371 }13721373 const environmentBlendMode = renderer.xr.getEnvironmentBlendMode();13741375 if ( environmentBlendMode === 'additive' ) {13761377 state.buffers.color.setClear( 0, 0, 0, 1, premultipliedAlpha );13781379 } else if ( environmentBlendMode === 'alpha-blend' ) {13801381 state.buffers.color.setClear( 0, 0, 0, 0, premultipliedAlpha );13821383 }13841385 if ( renderer.autoClear || forceClear ) {13861387 13881389 state.buffers.depth.setTest( true );1390 state.buffers.depth.setMask( true );1391 state.buffers.color.setMask( true );13921393 renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );13941395 }13961397 }13981399 function addToRenderList( renderList, scene ) {14001401 const background = getBackground( scene );14021403 if ( background && background.isCubeTexture ) {14041405 if ( boxMesh === undefined ) {14061407 boxMesh = new Mesh(1408 new BoxGeometry( 1, 1, 1 ),1409 new ShaderMaterial( {1410 name: 'BackgroundCubeMaterial',1411 uniforms: cloneUniforms( ShaderLib.backgroundCube.uniforms ),1412 vertexShader: ShaderLib.backgroundCube.vertexShader,1413 fragmentShader: ShaderLib.backgroundCube.fragmentShader,1414 side: BackSide,1415 depthTest: false,1416 depthWrite: false,1417 fog: false,1418 allowOverride: false1419 } )1420 );14211422 boxMesh.geometry.deleteAttribute( 'normal' );1423 boxMesh.geometry.deleteAttribute( 'uv' );14241425 boxMesh.onBeforeRender = function ( renderer, scene, camera ) {14261427 this.matrixWorld.copyPosition( camera.matrixWorld );14281429 };14301431 1432 Object.defineProperty( boxMesh.material, 'envMap', {14331434 get: function () {14351436 return this.uniforms.envMap.value;14371438 }14391440 } );14411442 objects.update( boxMesh );14431444 }144514461447 boxMesh.material.uniforms.envMap.value = background;1448 boxMesh.material.uniforms.backgroundBlurriness.value = scene.backgroundBlurriness;1449 boxMesh.material.uniforms.backgroundIntensity.value = scene.backgroundIntensity;145014511452 1453 boxMesh.material.uniforms.backgroundRotation.value.setFromMatrix4( _m1$1.makeRotationFromEuler( scene.backgroundRotation ) ).transpose();14541455 if ( background.isRenderTargetTexture === false ) {14561457 boxMesh.material.uniforms.backgroundRotation.value.premultiply( _m$1 );14581459 }146014611462 boxMesh.material.toneMapped = ColorManagement.getTransfer( background.colorSpace ) !== SRGBTransfer;14631464 if ( currentBackground !== background ||1465 currentBackgroundVersion !== background.version ||1466 currentTonemapping !== renderer.toneMapping ) {14671468 boxMesh.material.needsUpdate = true;14691470 currentBackground = background;1471 currentBackgroundVersion = background.version;1472 currentTonemapping = renderer.toneMapping;14731474 }14751476 boxMesh.layers.enableAll();14771478 1479 renderList.unshift( boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null );14801481 } else if ( background && background.isTexture ) {14821483 if ( planeMesh === undefined ) {14841485 planeMesh = new Mesh(1486 new PlaneGeometry( 2, 2 ),1487 new ShaderMaterial( {1488 name: 'BackgroundMaterial',1489 uniforms: cloneUniforms( ShaderLib.background.uniforms ),1490 vertexShader: ShaderLib.background.vertexShader,1491 fragmentShader: ShaderLib.background.fragmentShader,1492 side: FrontSide,1493 depthTest: false,1494 depthWrite: false,1495 fog: false,1496 allowOverride: false1497 } )1498 );14991500 planeMesh.geometry.deleteAttribute( 'normal' );15011502 1503 Object.defineProperty( planeMesh.material, 'map', {15041505 get: function () {15061507 return this.uniforms.t2D.value;15081509 }15101511 } );15121513 objects.update( planeMesh );15141515 }15161517 planeMesh.material.uniforms.t2D.value = background;1518 planeMesh.material.uniforms.backgroundIntensity.value = scene.backgroundIntensity;1519 planeMesh.material.toneMapped = ColorManagement.getTransfer( background.colorSpace ) !== SRGBTransfer;15201521 if ( background.matrixAutoUpdate === true ) {15221523 background.updateMatrix();15241525 }15261527 planeMesh.material.uniforms.uvTransform.value.copy( background.matrix );15281529 if ( currentBackground !== background ||1530 currentBackgroundVersion !== background.version ||1531 currentTonemapping !== renderer.toneMapping ) {15321533 planeMesh.material.needsUpdate = true;15341535 currentBackground = background;1536 currentBackgroundVersion = background.version;1537 currentTonemapping = renderer.toneMapping;15381539 }15401541 planeMesh.layers.enableAll();15421543 1544 renderList.unshift( planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null );15451546 }15471548 }15491550 function setClear( color, alpha ) {15511552 color.getRGB( _rgb, getUnlitUniformColorSpace( renderer ) );15531554 state.buffers.color.setClear( _rgb.r, _rgb.g, _rgb.b, alpha, premultipliedAlpha );15551556 }15571558 function dispose() {15591560 if ( boxMesh !== undefined ) {15611562 boxMesh.geometry.dispose();1563 boxMesh.material.dispose();15641565 boxMesh = undefined;15661567 }15681569 if ( planeMesh !== undefined ) {15701571 planeMesh.geometry.dispose();1572 planeMesh.material.dispose();15731574 planeMesh = undefined;15751576 }15771578 }15791580 return {15811582 getClearColor: function () {15831584 return clearColor;15851586 },1587 setClearColor: function ( color, alpha = 1 ) {15881589 clearColor.set( color );1590 clearAlpha = alpha;1591 setClear( clearColor, clearAlpha );15921593 },1594 getClearAlpha: function () {15951596 return clearAlpha;15971598 },1599 setClearAlpha: function ( alpha ) {16001601 clearAlpha = alpha;1602 setClear( clearColor, clearAlpha );16031604 },1605 render: render,1606 addToRenderList: addToRenderList,1607 dispose: dispose16081609 };16101611}16121613function WebGLBindingStates( gl, attributes ) {16141615 const maxVertexAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );16161617 const bindingStates = {};16181619 const defaultState = createBindingState( null );1620 let currentState = defaultState;1621 let forceUpdate = false;16221623 function setup( object, material, program, geometry, index ) {16241625 let updateBuffers = false;16261627 const state = getBindingState( object, geometry, program, material );16281629 if ( currentState !== state ) {16301631 currentState = state;1632 bindVertexArrayObject( currentState.object );16331634 }16351636 updateBuffers = needsUpdate( object, geometry, program, index );16371638 if ( updateBuffers ) saveCache( object, geometry, program, index );16391640 if ( index !== null ) {16411642 attributes.update( index, gl.ELEMENT_ARRAY_BUFFER );16431644 }16451646 if ( updateBuffers || forceUpdate ) {16471648 forceUpdate = false;16491650 setupVertexAttributes( object, material, program, geometry );16511652 if ( index !== null ) {16531654 gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, attributes.get( index ).buffer );16551656 }16571658 }16591660 }16611662 function createVertexArrayObject() {16631664 return gl.createVertexArray();16651666 }16671668 function bindVertexArrayObject( vao ) {16691670 return gl.bindVertexArray( vao );16711672 }16731674 function deleteVertexArrayObject( vao ) {16751676 return gl.deleteVertexArray( vao );16771678 }16791680 function getBindingState( object, geometry, program, material ) {16811682 const wireframe = ( material.wireframe === true );16831684 let objectMap = bindingStates[ geometry.id ];16851686 if ( objectMap === undefined ) {16871688 objectMap = {};1689 bindingStates[ geometry.id ] = objectMap;16901691 }16921693 1694 const objectId = ( object.isInstancedMesh === true ) ? object.id : 0;16951696 let programMap = objectMap[ objectId ];16971698 if ( programMap === undefined ) {16991700 programMap = {};1701 objectMap[ objectId ] = programMap;17021703 }17041705 let stateMap = programMap[ program.id ];17061707 if ( stateMap === undefined ) {17081709 stateMap = {};1710 programMap[ program.id ] = stateMap;17111712 }17131714 let state = stateMap[ wireframe ];17151716 if ( state === undefined ) {17171718 state = createBindingState( createVertexArrayObject() );1719 stateMap[ wireframe ] = state;17201721 }17221723 return state;17241725 }17261727 function createBindingState( vao ) {17281729 const newAttributes = [];1730 const enabledAttributes = [];1731 const attributeDivisors = [];17321733 for ( let i = 0; i < maxVertexAttributes; i ++ ) {17341735 newAttributes[ i ] = 0;1736 enabledAttributes[ i ] = 0;1737 attributeDivisors[ i ] = 0;17381739 }17401741 return {17421743 1744 geometry: null,1745 program: null,1746 wireframe: false,17471748 newAttributes: newAttributes,1749 enabledAttributes: enabledAttributes,1750 attributeDivisors: attributeDivisors,1751 object: vao,1752 attributes: {},1753 index: null17541755 };17561757 }17581759 function needsUpdate( object, geometry, program, index ) {17601761 const cachedAttributes = currentState.attributes;1762 const geometryAttributes = geometry.attributes;17631764 let attributesNum = 0;17651766 const programAttributes = program.getAttributes();17671768 for ( const name in programAttributes ) {17691770 const programAttribute = programAttributes[ name ];17711772 if ( programAttribute.location >= 0 ) {17731774 const cachedAttribute = cachedAttributes[ name ];1775 let geometryAttribute = geometryAttributes[ name ];17761777 if ( geometryAttribute === undefined ) {17781779 if ( name === 'instanceMatrix' && object.instanceMatrix ) geometryAttribute = object.instanceMatrix;1780 if ( name === 'instanceColor' && object.instanceColor ) geometryAttribute = object.instanceColor;17811782 }17831784 if ( cachedAttribute === undefined ) return true;17851786 if ( cachedAttribute.attribute !== geometryAttribute ) return true;17871788 if ( geometryAttribute && cachedAttribute.data !== geometryAttribute.data ) return true;17891790 attributesNum ++;17911792 }17931794 }17951796 if ( currentState.attributesNum !== attributesNum ) return true;17971798 if ( currentState.index !== index ) return true;17991800 return false;18011802 }18031804 function saveCache( object, geometry, program, index ) {18051806 const cache = {};1807 const attributes = geometry.attributes;1808 let attributesNum = 0;18091810 const programAttributes = program.getAttributes();18111812 for ( const name in programAttributes ) {18131814 const programAttribute = programAttributes[ name ];18151816 if ( programAttribute.location >= 0 ) {18171818 let attribute = attributes[ name ];18191820 if ( attribute === undefined ) {18211822 if ( name === 'instanceMatrix' && object.instanceMatrix ) attribute = object.instanceMatrix;1823 if ( name === 'instanceColor' && object.instanceColor ) attribute = object.instanceColor;18241825 }18261827 const data = {};1828 data.attribute = attribute;18291830 if ( attribute && attribute.data ) {18311832 data.data = attribute.data;18331834 }18351836 cache[ name ] = data;18371838 attributesNum ++;18391840 }18411842 }18431844 currentState.attributes = cache;1845 currentState.attributesNum = attributesNum;18461847 currentState.index = index;18481849 }18501851 function initAttributes() {18521853 const newAttributes = currentState.newAttributes;18541855 for ( let i = 0, il = newAttributes.length; i < il; i ++ ) {18561857 newAttributes[ i ] = 0;18581859 }18601861 }18621863 function enableAttribute( attribute ) {18641865 enableAttributeAndDivisor( attribute, 0 );18661867 }18681869 function enableAttributeAndDivisor( attribute, meshPerAttribute ) {18701871 const newAttributes = currentState.newAttributes;1872 const enabledAttributes = currentState.enabledAttributes;1873 const attributeDivisors = currentState.attributeDivisors;18741875 newAttributes[ attribute ] = 1;18761877 if ( enabledAttributes[ attribute ] === 0 ) {18781879 gl.enableVertexAttribArray( attribute );1880 enabledAttributes[ attribute ] = 1;18811882 }18831884 if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {18851886 gl.vertexAttribDivisor( attribute, meshPerAttribute );1887 attributeDivisors[ attribute ] = meshPerAttribute;18881889 }18901891 }18921893 function disableUnusedAttributes() {18941895 const newAttributes = currentState.newAttributes;1896 const enabledAttributes = currentState.enabledAttributes;18971898 for ( let i = 0, il = enabledAttributes.length; i < il; i ++ ) {18991900 if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {19011902 gl.disableVertexAttribArray( i );1903 enabledAttributes[ i ] = 0;19041905 }19061907 }19081909 }19101911 function vertexAttribPointer( index, size, type, normalized, stride, offset, integer ) {19121913 if ( integer === true ) {19141915 gl.vertexAttribIPointer( index, size, type, stride, offset );19161917 } else {19181919 gl.vertexAttribPointer( index, size, type, normalized, stride, offset );19201921 }19221923 }19241925 function setupVertexAttributes( object, material, program, geometry ) {19261927 initAttributes();19281929 const geometryAttributes = geometry.attributes;19301931 const programAttributes = program.getAttributes();19321933 const materialDefaultAttributeValues = material.defaultAttributeValues;19341935 for ( const name in programAttributes ) {19361937 const programAttribute = programAttributes[ name ];19381939 if ( programAttribute.location >= 0 ) {19401941 let geometryAttribute = geometryAttributes[ name ];19421943 if ( geometryAttribute === undefined ) {19441945 if ( name === 'instanceMatrix' && object.instanceMatrix ) geometryAttribute = object.instanceMatrix;1946 if ( name === 'instanceColor' && object.instanceColor ) geometryAttribute = object.instanceColor;19471948 }19491950 if ( geometryAttribute !== undefined ) {19511952 const normalized = geometryAttribute.normalized;1953 const size = geometryAttribute.itemSize;19541955 const attribute = attributes.get( geometryAttribute );19561957 19581959 if ( attribute === undefined ) continue;19601961 const buffer = attribute.buffer;1962 const type = attribute.type;1963 const bytesPerElement = attribute.bytesPerElement;19641965 19661967 const integer = ( type === gl.INT || type === gl.UNSIGNED_INT || geometryAttribute.gpuType === IntType );19681969 if ( geometryAttribute.isInterleavedBufferAttribute ) {19701971 19721973 const data = geometryAttribute.data;1974 const stride = data.isInterleavedBuffer === true ? data.stride : data.itemSize;1975 const offset = geometryAttribute.offset;19761977 if ( data.isInstancedInterleavedBuffer || data.isInstancedBufferAttribute ) {19781979 for ( let i = 0; i < programAttribute.locationSize; i ++ ) {19801981 enableAttributeAndDivisor( programAttribute.location + i, data.meshPerAttribute );19821983 }19841985 if ( object.isInstancedMesh !== true && geometry._maxInstanceCount === undefined ) {19861987 geometry._maxInstanceCount = data.meshPerAttribute * data.count;19881989 }19901991 } else {19921993 for ( let i = 0; i < programAttribute.locationSize; i ++ ) {19941995 enableAttribute( programAttribute.location + i );19961997 }19981999 }20002001 gl.bindBuffer( gl.ARRAY_BUFFER, buffer );20022003 for ( let i = 0; i < programAttribute.locationSize; i ++ ) {20042005 vertexAttribPointer(2006 programAttribute.location + i,2007 size / programAttribute.locationSize,2008 type,2009 normalized,2010 stride * bytesPerElement,2011 ( offset + ( size / programAttribute.locationSize ) * i ) * bytesPerElement,2012 integer2013 );20142015 }20162017 } else {20182019 if ( geometryAttribute.isInstancedBufferAttribute ) {20202021 for ( let i = 0; i < programAttribute.locationSize; i ++ ) {20222023 enableAttributeAndDivisor( programAttribute.location + i, geometryAttribute.meshPerAttribute );20242025 }20262027 if ( object.isInstancedMesh !== true && geometry._maxInstanceCount === undefined ) {20282029 geometry._maxInstanceCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;20302031 }20322033 } else {20342035 for ( let i = 0; i < programAttribute.locationSize; i ++ ) {20362037 enableAttribute( programAttribute.location + i );20382039 }20402041 }20422043 gl.bindBuffer( gl.ARRAY_BUFFER, buffer );20442045 for ( let i = 0; i < programAttribute.locationSize; i ++ ) {20462047 vertexAttribPointer(2048 programAttribute.location + i,2049 size / programAttribute.locationSize,2050 type,2051 normalized,2052 size * bytesPerElement,2053 ( size / programAttribute.locationSize ) * i * bytesPerElement,2054 integer2055 );20562057 }20582059 }20602061 } else if ( materialDefaultAttributeValues !== undefined ) {20622063 const value = materialDefaultAttributeValues[ name ];20642065 if ( value !== undefined ) {20662067 switch ( value.length ) {20682069 case 2:2070 gl.vertexAttrib2fv( programAttribute.location, value );2071 break;20722073 case 3:2074 gl.vertexAttrib3fv( programAttribute.location, value );2075 break;20762077 case 4:2078 gl.vertexAttrib4fv( programAttribute.location, value );2079 break;20802081 default:2082 gl.vertexAttrib1fv( programAttribute.location, value );20832084 }20852086 }20872088 }20892090 }20912092 }20932094 disableUnusedAttributes();20952096 }20972098 function dispose() {20992100 reset();21012102 for ( const geometryId in bindingStates ) {21032104 const objectMap = bindingStates[ geometryId ];21052106 for ( const objectId in objectMap ) {21072108 const programMap = objectMap[ objectId ];21092110 for ( const programId in programMap ) {21112112 const stateMap = programMap[ programId ];21132114 for ( const wireframe in stateMap ) {21152116 deleteVertexArrayObject( stateMap[ wireframe ].object );21172118 delete stateMap[ wireframe ];21192120 }21212122 delete programMap[ programId ];21232124 }21252126 }21272128 delete bindingStates[ geometryId ];21292130 }21312132 }21332134 function releaseStatesOfGeometry( geometry ) {21352136 if ( bindingStates[ geometry.id ] === undefined ) return;21372138 const objectMap = bindingStates[ geometry.id ];21392140 for ( const objectId in objectMap ) {21412142 const programMap = objectMap[ objectId ];21432144 for ( const programId in programMap ) {21452146 const stateMap = programMap[ programId ];21472148 for ( const wireframe in stateMap ) {21492150 deleteVertexArrayObject( stateMap[ wireframe ].object );21512152 delete stateMap[ wireframe ];21532154 }21552156 delete programMap[ programId ];21572158 }21592160 }21612162 delete bindingStates[ geometry.id ];21632164 }21652166 function releaseStatesOfProgram( program ) {21672168 for ( const geometryId in bindingStates ) {21692170 const objectMap = bindingStates[ geometryId ];21712172 for ( const objectId in objectMap ) {21732174 const programMap = objectMap[ objectId ];21752176 if ( programMap[ program.id ] === undefined ) continue;21772178 const stateMap = programMap[ program.id ];21792180 for ( const wireframe in stateMap ) {21812182 deleteVertexArrayObject( stateMap[ wireframe ].object );21832184 delete stateMap[ wireframe ];21852186 }21872188 delete programMap[ program.id ];21892190 }21912192 }21932194 }21952196 function releaseStatesOfObject( object ) {21972198 for ( const geometryId in bindingStates ) {21992200 const objectMap = bindingStates[ geometryId ];22012202 const objectId = ( object.isInstancedMesh === true ) ? object.id : 0;22032204 const programMap = objectMap[ objectId ];22052206 if ( programMap === undefined ) continue;22072208 for ( const programId in programMap ) {22092210 const stateMap = programMap[ programId ];22112212 for ( const wireframe in stateMap ) {22132214 deleteVertexArrayObject( stateMap[ wireframe ].object );22152216 delete stateMap[ wireframe ];22172218 }22192220 delete programMap[ programId ];22212222 }22232224 delete objectMap[ objectId ];22252226 if ( Object.keys( objectMap ).length === 0 ) {22272228 delete bindingStates[ geometryId ];22292230 }22312232 }22332234 }223522362237 function reset() {22382239 resetDefaultState();2240 forceUpdate = true;22412242 if ( currentState === defaultState ) return;22432244 currentState = defaultState;2245 bindVertexArrayObject( currentState.object );22462247 }22482249 22502251 function resetDefaultState() {22522253 defaultState.geometry = null;2254 defaultState.program = null;2255 defaultState.wireframe = false;22562257 }22582259 return {22602261 setup: setup,2262 reset: reset,2263 resetDefaultState: resetDefaultState,2264 dispose: dispose,2265 releaseStatesOfGeometry: releaseStatesOfGeometry,2266 releaseStatesOfObject: releaseStatesOfObject,2267 releaseStatesOfProgram: releaseStatesOfProgram,22682269 initAttributes: initAttributes,2270 enableAttribute: enableAttribute,2271 disableUnusedAttributes: disableUnusedAttributes22722273 };22742275}22762277function WebGLBufferRenderer( gl, extensions, info ) {22782279 let mode;22802281 function setMode( value ) {22822283 mode = value;22842285 }22862287 function render( start, count ) {22882289 gl.drawArrays( mode, start, count );22902291 info.update( count, mode, 1 );22922293 }22942295 function renderInstances( start, count, primcount ) {22962297 if ( primcount === 0 ) return;22982299 gl.drawArraysInstanced( mode, start, count, primcount );23002301 info.update( count, mode, primcount );23022303 }23042305 function renderMultiDraw( starts, counts, drawCount ) {23062307 if ( drawCount === 0 ) return;23082309 const extension = extensions.get( 'WEBGL_multi_draw' );2310 extension.multiDrawArraysWEBGL( mode, starts, 0, counts, 0, drawCount );23112312 let elementCount = 0;2313 for ( let i = 0; i < drawCount; i ++ ) {23142315 elementCount += counts[ i ];23162317 }23182319 info.update( elementCount, mode, 1 );23202321 }23222323 23242325 this.setMode = setMode;2326 this.render = render;2327 this.renderInstances = renderInstances;2328 this.renderMultiDraw = renderMultiDraw;23292330}23312332function WebGLCapabilities( gl, extensions, parameters, utils ) {23332334 let maxAnisotropy;23352336 function getMaxAnisotropy() {23372338 if ( maxAnisotropy !== undefined ) return maxAnisotropy;23392340 if ( extensions.has( 'EXT_texture_filter_anisotropic' ) === true ) {23412342 const extension = extensions.get( 'EXT_texture_filter_anisotropic' );23432344 maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );23452346 } else {23472348 maxAnisotropy = 0;23492350 }23512352 return maxAnisotropy;23532354 }23552356 function textureFormatReadable( textureFormat ) {23572358 if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== gl.getParameter( gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {23592360 return false;23612362 }23632364 return true;23652366 }23672368 function textureTypeReadable( textureType ) {23692370 const halfFloatSupportedByExt = ( textureType === HalfFloatType ) && ( extensions.has( 'EXT_color_buffer_half_float' ) || extensions.has( 'EXT_color_buffer_float' ) );23712372 if ( textureType !== UnsignedByteType && textureType !== FloatType && ! halfFloatSupportedByExt &&2373 utils.convert( textureType ) !== gl.getParameter( gl.IMPLEMENTATION_COLOR_READ_TYPE ) ) { 23742375 return false;23762377 }23782379 return true;23802381 }23822383 function getMaxPrecision( precision ) {23842385 if ( precision === 'highp' ) {23862387 if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.HIGH_FLOAT ).precision > 0 &&2388 gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.HIGH_FLOAT ).precision > 0 ) {23892390 return 'highp';23912392 }23932394 precision = 'mediump';23952396 }23972398 if ( precision === 'mediump' ) {23992400 if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.MEDIUM_FLOAT ).precision > 0 &&2401 gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT ).precision > 0 ) {24022403 return 'mediump';24042405 }24062407 }24082409 return 'lowp';24102411 }24122413 let precision = parameters.precision !== undefined ? parameters.precision : 'highp';2414 const maxPrecision = getMaxPrecision( precision );24152416 if ( maxPrecision !== precision ) {24172418 warn( 'WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.' );2419 precision = maxPrecision;24202421 }24222423 const reversedDepthBuffer = parameters.reversedDepthBuffer === true && extensions.has( 'EXT_clip_control' );2424 const logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true && reversedDepthBuffer === false;24252426 if ( parameters.reversedDepthBuffer === true && reversedDepthBuffer === false ) {24272428 warn( 'WebGLRenderer: Unable to use reversed depth buffer due to missing EXT_clip_control extension. Fallback to default depth buffer.' );24292430 }24312432 if ( parameters.logarithmicDepthBuffer === true && reversedDepthBuffer === true ) {24332434 warn( 'WebGLRenderer: Logarithmic depth buffer is ignored when reversed depth buffer is enabled.' );24352436 }24372438 const maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );2439 const maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );2440 const maxTextureSize = gl.getParameter( gl.MAX_TEXTURE_SIZE );2441 const maxCubemapSize = gl.getParameter( gl.MAX_CUBE_MAP_TEXTURE_SIZE );24422443 const maxAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );2444 const maxVertexUniforms = gl.getParameter( gl.MAX_VERTEX_UNIFORM_VECTORS );2445 const maxVaryings = gl.getParameter( gl.MAX_VARYING_VECTORS );2446 const maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS );24472448 const maxSamples = gl.getParameter( gl.MAX_SAMPLES );2449 const samples = gl.getParameter( gl.SAMPLES );24502451 return {24522453 isWebGL2: true, 24542455 getMaxAnisotropy: getMaxAnisotropy,2456 getMaxPrecision: getMaxPrecision,24572458 textureFormatReadable: textureFormatReadable,2459 textureTypeReadable: textureTypeReadable,24602461 precision: precision,2462 logarithmicDepthBuffer: logarithmicDepthBuffer,2463 reversedDepthBuffer: reversedDepthBuffer,24642465 maxTextures: maxTextures,2466 maxVertexTextures: maxVertexTextures,2467 maxTextureSize: maxTextureSize,2468 maxCubemapSize: maxCubemapSize,24692470 maxAttributes: maxAttributes,2471 maxVertexUniforms: maxVertexUniforms,2472 maxVaryings: maxVaryings,2473 maxFragmentUniforms: maxFragmentUniforms,24742475 maxSamples: maxSamples,24762477 samples: samples24782479 };24802481}24822483function WebGLClipping( properties ) {24842485 const scope = this;24862487 let globalState = null,2488 numGlobalPlanes = 0,2489 localClippingEnabled = false,2490 renderingShadows = false;24912492 const plane = new Plane(),2493 viewNormalMatrix = new Matrix3(),24942495 uniform = { value: null, needsUpdate: false };24962497 this.uniform = uniform;2498 this.numPlanes = 0;2499 this.numIntersection = 0;25002501 this.init = function ( planes, enableLocalClipping ) {25022503 const enabled =2504 planes.length !== 0 ||2505 enableLocalClipping ||2506 2507 2508 numGlobalPlanes !== 0 ||2509 localClippingEnabled;25102511 localClippingEnabled = enableLocalClipping;25122513 numGlobalPlanes = planes.length;25142515 return enabled;25162517 };25182519 this.beginShadows = function () {25202521 renderingShadows = true;2522 projectPlanes( null );25232524 };25252526 this.endShadows = function () {25272528 renderingShadows = false;25292530 };25312532 this.setGlobalState = function ( planes, camera ) {25332534 globalState = projectPlanes( planes, camera, 0 );25352536 };25372538 this.setState = function ( material, camera, useCache ) {25392540 const planes = material.clippingPlanes,2541 clipIntersection = material.clipIntersection,2542 clipShadows = material.clipShadows;25432544 const materialProperties = properties.get( material );25452546 if ( ! localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && ! clipShadows ) {25472548 25492550 if ( renderingShadows ) {25512552 25532554 projectPlanes( null );25552556 } else {25572558 resetGlobalState();25592560 }25612562 } else {25632564 const nGlobal = renderingShadows ? 0 : numGlobalPlanes,2565 lGlobal = nGlobal * 4;25662567 let dstArray = materialProperties.clippingState || null;25682569 uniform.value = dstArray; 25702571 dstArray = projectPlanes( planes, camera, lGlobal, useCache );25722573 for ( let i = 0; i !== lGlobal; ++ i ) {25742575 dstArray[ i ] = globalState[ i ];25762577 }25782579 materialProperties.clippingState = dstArray;2580 this.numIntersection = clipIntersection ? this.numPlanes : 0;2581 this.numPlanes += nGlobal;25822583 }258425852586 };25872588 function resetGlobalState() {25892590 if ( uniform.value !== globalState ) {25912592 uniform.value = globalState;2593 uniform.needsUpdate = numGlobalPlanes > 0;25942595 }25962597 scope.numPlanes = numGlobalPlanes;2598 scope.numIntersection = 0;25992600 }26012602 function projectPlanes( planes, camera, dstOffset, skipTransform ) {26032604 const nPlanes = planes !== null ? planes.length : 0;2605 let dstArray = null;26062607 if ( nPlanes !== 0 ) {26082609 dstArray = uniform.value;26102611 if ( skipTransform !== true || dstArray === null ) {26122613 const flatSize = dstOffset + nPlanes * 4,2614 viewMatrix = camera.matrixWorldInverse;26152616 viewNormalMatrix.getNormalMatrix( viewMatrix );26172618 if ( dstArray === null || dstArray.length < flatSize ) {26192620 dstArray = new Float32Array( flatSize );26212622 }26232624 for ( let i = 0, i4 = dstOffset; i !== nPlanes; ++ i, i4 += 4 ) {26252626 plane.copy( planes[ i ] ).applyMatrix4( viewMatrix, viewNormalMatrix );26272628 plane.normal.toArray( dstArray, i4 );2629 dstArray[ i4 + 3 ] = plane.constant;26302631 }26322633 }26342635 uniform.value = dstArray;2636 uniform.needsUpdate = true;26372638 }26392640 scope.numPlanes = nPlanes;2641 scope.numIntersection = 0;26422643 return dstArray;26442645 }26462647}2648264926502651265226532654class WebGLCubeRenderTarget extends WebGLRenderTarget {26552656 265726582659266026612662 constructor( size = 1, options = {} ) {26632664 super( size, size, options );26652666 2667266826692670267126722673 this.isWebGLCubeRenderTarget = true;26742675 const image = { width: size, height: size, depth: 1 };2676 const images = [ image, image, image, image, image, image ];26772678 26792680268126822683 this.texture = new CubeTexture( images );2684 this._setTextureOptions( options );26852686 2687 2688 26892690 2691 2692 26932694 this.texture.isRenderTargetTexture = true;26952696 }26972698 2699270027012702270327042705 fromEquirectangularTexture( renderer, texture ) {27062707 this.texture.type = texture.type;2708 this.texture.colorSpace = texture.colorSpace;27092710 this.texture.generateMipmaps = texture.generateMipmaps;2711 this.texture.minFilter = texture.minFilter;2712 this.texture.magFilter = texture.magFilter;27132714 const shader = {27152716 uniforms: {2717 tEquirect: { value: null },2718 },27192720 vertexShader: `27212722 varying vec3 vWorldDirection;27232724 vec3 transformDirection( in vec3 dir, in mat4 matrix ) {27252726 return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );27272728 }27292730 void main() {27312732 vWorldDirection = transformDirection( position, modelMatrix );27332734 #include <begin_vertex>2735 #include <project_vertex>27362737 }2738 `,27392740 fragmentShader: `27412742 uniform sampler2D tEquirect;27432744 varying vec3 vWorldDirection;27452746 #include <common>27472748 void main() {27492750 vec3 direction = normalize( vWorldDirection );27512752 vec2 sampleUV = equirectUv( direction );27532754 gl_FragColor = texture2D( tEquirect, sampleUV );27552756 }2757 `2758 };27592760 const geometry = new BoxGeometry( 5, 5, 5 );27612762 const material = new ShaderMaterial( {27632764 name: 'CubemapFromEquirect',27652766 uniforms: cloneUniforms( shader.uniforms ),2767 vertexShader: shader.vertexShader,2768 fragmentShader: shader.fragmentShader,2769 side: BackSide,2770 blending: NoBlending27712772 } );27732774 material.uniforms.tEquirect.value = texture;27752776 const mesh = new Mesh( geometry, material );27772778 const currentMinFilter = texture.minFilter;27792780 2781 if ( texture.minFilter === LinearMipmapLinearFilter ) texture.minFilter = LinearFilter;27822783 const camera = new CubeCamera( 1, 10, this );2784 camera.update( renderer, mesh );27852786 texture.minFilter = currentMinFilter;27872788 mesh.geometry.dispose();2789 mesh.material.dispose();27902791 return this;27922793 }27942795 27962797279827992800280128022803 clear( renderer, color = true, depth = true, stencil = true ) {28042805 const currentRenderTarget = renderer.getRenderTarget();28062807 for ( let i = 0; i < 6; i ++ ) {28082809 renderer.setRenderTarget( this, i );28102811 renderer.clear( color, depth, stencil );28122813 }28142815 renderer.setRenderTarget( currentRenderTarget );28162817 }28182819}282028212822const MIN_SIZE = 256;2823282428252826const LOD_MIN = 3;282728282829const BLUR_SAMPLES = 20;283028312832const GGX_SAMPLES = 256;283328342835const INTEGRATION_SIZE = 16;2836const INTEGRATION_LEVELS = 3;28372838const _origin = new Vector3();2839const _clearColor = new Color();28402841284228432844284528462847284828492850285128522853class PMREMGenerator {28542855 28562857285828592860 constructor( renderer ) {28612862 this._renderer = renderer;28632864 this._cubeSize = 0;2865 this._sourceTarget = null;28662867 this._cubeCamera = new CubeCamera( 1, 10, null );2868 this._boxMesh = new Mesh( new BoxGeometry( 5, 5, 5 ), null );28692870 this._cubemapMaterial = null;2871 this._equirectMaterial = null;28722873 this._blurMaterial = null;2874 this._ggxMaterial = null;2875 this._integrationMaterial = null;28762877 }28782879 2880288128822883288428852886288728882889289028912892 fromScene( scene, sigma = 0, near = 0.1, far = 100, options = {} ) {28932894 const {2895 size = 256,2896 position = _origin,2897 } = options;28982899 const renderer = this._renderer;29002901 this._setSize( size );29022903 const pmremTarget = this._allocateTarget();2904 const sourceTarget = this._getSourceTarget( true );29052906 if ( sigma > 0 ) {29072908 sourceTarget.texture.mipmapsAutoUpdate = false;29092910 }29112912 29132914 const autoClear = renderer.autoClear;2915 const autoClearColor = renderer.autoClearColor;2916 const autoClearDepth = renderer.autoClearDepth;2917 const autoClearStencil = renderer.autoClearStencil;2918 const background = scene.background;29192920 renderer.autoClear = true;2921 renderer.autoClearColor = true;2922 renderer.autoClearDepth = true;2923 renderer.autoClearStencil = true;29242925 if ( background === null ) scene.background = renderer.getClearColor( _clearColor );29262927 const cubeCamera = new CubeCamera( near, far, sourceTarget );2928 cubeCamera.position.copy( position );2929 cubeCamera.update( renderer, scene );29302931 renderer.autoClear = autoClear;2932 renderer.autoClearColor = autoClearColor;2933 renderer.autoClearDepth = autoClearDepth;2934 renderer.autoClearStencil = autoClearStencil;29352936 scene.background = background;29372938 if ( sigma > 0 ) {29392940 sourceTarget.texture.mipmapsAutoUpdate = true;2941 this._blur( pmremTarget, sigma );29422943 }29442945 this._applyPMREM( pmremTarget );29462947 return pmremTarget;29482949 }29502951 295229532954295529562957295829592960 fromEquirectangular( equirectangular, renderTarget = null ) {29612962 return this._fromTexture( equirectangular, renderTarget );29632964 }29652966 29672968296929702971297229732974 fromCubemap( cubemap, renderTarget = null ) {29752976 return this._fromTexture( cubemap, renderTarget );29772978 }29792980 2981298229832984 compileCubemapShader() {29852986 if ( this._cubemapMaterial === null ) {29872988 this._cubemapMaterial = _getCubemapMaterial();2989 this._compileMaterial( this._cubemapMaterial );29902991 }29922993 }29942995 2996299729982999 compileEquirectangularShader() {30003001 if ( this._equirectMaterial === null ) {30023003 this._equirectMaterial = _getEquirectMaterial();3004 this._compileMaterial( this._equirectMaterial );30053006 }30073008 }30093010 3011301230133014 dispose() {30153016 if ( this._sourceTarget !== null ) this._sourceTarget.dispose();30173018 if ( this._cubemapMaterial !== null ) this._cubemapMaterial.dispose();3019 if ( this._equirectMaterial !== null ) this._equirectMaterial.dispose();3020 if ( this._blurMaterial !== null ) this._blurMaterial.dispose();3021 if ( this._ggxMaterial !== null ) this._ggxMaterial.dispose();3022 if ( this._integrationMaterial !== null ) this._integrationMaterial.dispose();30233024 this._boxMesh.geometry.dispose();30253026 }30273028 30293030303130323033303430353036 static lodToRoughness( lod, maxLod ) {30373038 return maxLod > 0 ? 1 - Math.sqrt( 1 - lod / maxLod ) : 0;30393040 }30413042 30433044 _setSize( cubeSize ) {30453046 this._cubeSize = Math.max( MIN_SIZE, floorPowerOfTwo( cubeSize ) );30473048 }30493050 _fromTexture( texture, renderTarget ) {30513052 if ( texture.mapping === CubeReflectionMapping || texture.mapping === CubeRefractionMapping ) {30533054 this._setSize( texture.image.length === 0 ? MIN_SIZE : ( texture.image[ 0 ].width || texture.image[ 0 ].image.width ) );30553056 } else { 30573058 this._setSize( texture.image.width / 4 );30593060 }30613062 const pmremTarget = renderTarget || this._allocateTarget();30633064 this._textureToCubemap( texture );3065 this._applyPMREM( pmremTarget );30663067 return pmremTarget;30683069 }30703071 _allocateTarget() {30723073 const size = this._cubeSize;30743075 const pmremTarget = _createRenderTarget( size, false, false );30763077 30783079 const maxLod = Math.log2( size ) - LOD_MIN;30803081 for ( let lod = 0; lod <= maxLod; lod ++ ) {30823083 pmremTarget.texture.mipmaps.push( { width: size >> lod, height: size >> lod } );30843085 }30863087 pmremTarget.texture.name = 'PMREM';3088 pmremTarget.texture.isPMREMTexture = true;30893090 return pmremTarget;30913092 }30933094 _getSourceTarget( depthBuffer = false ) {30953096 const size = this._cubeSize;3097 const sourceTarget = this._sourceTarget;30983099 if ( sourceTarget === null || sourceTarget.width !== size || ( depthBuffer && sourceTarget.depthBuffer === false ) ) {31003101 if ( sourceTarget !== null ) sourceTarget.dispose();31023103 this._sourceTarget = _createRenderTarget( size, true, depthBuffer );31043105 }31063107 return this._sourceTarget;31083109 }31103111 _compileMaterial( material ) {31123113 this._boxMesh.material = material;3114 this._renderer.compile( this._boxMesh, this._cubeCamera.children[ 0 ] );31153116 }31173118 31193120312131223123312431253126 _renderCube( target, lod, material ) {31273128 const boxMesh = this._boxMesh;3129 const cubeCamera = this._cubeCamera;31303131 boxMesh.material = material;31323133 cubeCamera.renderTarget = target;3134 cubeCamera.activeMipmapLevel = lod;31353136 31373138 const size = target.width >> lod;31393140 target.viewport.set( 0, 0, size, size );31413142 cubeCamera.update( this._renderer, boxMesh );31433144 target.viewport.set( 0, 0, target.width, target.height );31453146 }31473148 _textureToCubemap( texture ) {31493150 let material;31513152 if ( texture.mapping === CubeReflectionMapping || texture.mapping === CubeRefractionMapping ) {31533154 if ( this._cubemapMaterial === null ) {31553156 this._cubemapMaterial = _getCubemapMaterial();31573158 }31593160 material = this._cubemapMaterial;3161 material.uniforms.flipEnvMap.value = ( texture.isRenderTargetTexture === false ) ? -1 : 1;31623163 } else {31643165 if ( this._equirectMaterial === null ) {31663167 this._equirectMaterial = _getEquirectMaterial();31683169 }31703171 material = this._equirectMaterial;31723173 }31743175 material.uniforms.envMap.value = texture;31763177 this._renderCube( this._getSourceTarget(), 0, material );31783179 }31803181 318231833184318531863187318831893190 _applyPMREM( pmremTarget ) {31913192 if ( this._ggxMaterial === null ) {31933194 this._ggxMaterial = _getGGXMaterial();3195 this._integrationMaterial = _getIntegrationMaterial();31963197 }31983199 const size = this._cubeSize;3200 const maxLod = pmremTarget.texture.mipmaps.length - 1;32013202 const ggxUniforms = this._ggxMaterial.uniforms;3203 ggxUniforms.envMap.value = this._sourceTarget.texture;32043205 const integrationUniforms = this._integrationMaterial.uniforms;3206 integrationUniforms.envMap.value = this._sourceTarget.texture;3207 integrationUniforms.sourceLod.value = Math.log2( size / INTEGRATION_SIZE );32083209 for ( let lod = 0; lod <= maxLod; lod ++ ) {32103211 const roughness = PMREMGenerator.lodToRoughness( lod, maxLod );32123213 if ( lod > maxLod - INTEGRATION_LEVELS ) {32143215 integrationUniforms.roughness.value = roughness;32163217 this._renderCube( pmremTarget, lod, this._integrationMaterial );32183219 } else {32203221 3222 3223 3224 const lodBias = roughness > 0 ? Math.log2( size ) + 0.5 * Math.log2( 6 / ( GGX_SAMPLES * Math.pow( roughness, 4 ) ) ) + 0.5 : 0;32253226 ggxUniforms.roughness.value = roughness;3227 ggxUniforms.lodBias.value = lodBias;32283229 this._renderCube( pmremTarget, lod, this._ggxMaterial );32303231 }32323233 }32343235 }32363237 32383239324032413242324332443245 _blur( pmremTarget, sigma ) {32463247 if ( this._blurMaterial === null ) {32483249 this._blurMaterial = _getBlurMaterial();32503251 }32523253 const material = this._blurMaterial;3254 const uniforms = material.uniforms;32553256 const sourceTarget = this._sourceTarget;32573258 3259 3260 uniforms.sigma.value = Math.min( sigma, Math.PI ) / Math.SQRT2;32613262 uniforms.envMap.value = sourceTarget.texture;3263 this._renderCube( pmremTarget, 0, material );32643265 uniforms.envMap.value = pmremTarget.texture;3266 this._renderCube( sourceTarget, 0, material );32673268 }32693270}32713272function _createRenderTarget( size, generateMipmaps, depthBuffer ) {32733274 return new WebGLCubeRenderTarget( size, {3275 minFilter: LinearMipmapLinearFilter,3276 generateMipmaps: generateMipmaps,3277 type: HalfFloatType,3278 colorSpace: LinearSRGBColorSpace,3279 depthBuffer: depthBuffer3280 } );32813282}32833284function _getMaterial( name, uniforms, fragmentShader ) {32853286 return new ShaderMaterial( {32873288 name: name,32893290 uniforms: uniforms,32913292 vertexShader: ShaderChunk.cube_vert,3293 fragmentShader: fragmentShader,32943295 side: BackSide,3296 blending: NoBlending,3297 depthTest: false,3298 depthWrite: false32993300 } );33013302}33033304function _getGGXMaterial() {33053306 return _getMaterial( 'PMREMGGXConvolution', {3307 'envMap': { value: null },3308 'roughness': { value: 0 },3309 'lodBias': { value: 0 }3310 }, `33113312 #define GGX_SAMPLES ${ GGX_SAMPLES }u33133314 varying vec3 vWorldDirection;33153316 uniform samplerCube envMap;3317 uniform float roughness;3318 uniform float lodBias;33193320 #include <common>33213322 // Van der Corput radical inverse3323 float radicalInverse_VdC( uint bits ) {33243325 bits = ( bits << 16u ) | ( bits >> 16u );3326 bits = ( ( bits & 0x55555555u ) << 1u ) | ( ( bits & 0xAAAAAAAAu ) >> 1u );3327 bits = ( ( bits & 0x33333333u ) << 2u ) | ( ( bits & 0xCCCCCCCCu ) >> 2u );3328 bits = ( ( bits & 0x0F0F0F0Fu ) << 4u ) | ( ( bits & 0xF0F0F0F0u ) >> 4u );3329 bits = ( ( bits & 0x00FF00FFu ) << 8u ) | ( ( bits & 0xFF00FF00u ) >> 8u );3330 return float( bits ) * 2.3283064365386963e-10; // / 0x10000000033313332 }33333334 // Hammersley sequence3335 vec2 hammersley( uint i, uint N ) {33363337 return vec2( float( i ) / float( N ), radicalInverse_VdC( i ) );33383339 }33403341 void main() {33423343 vec3 N = normalize( vWorldDirection );33443345 // For very low roughness, just sample the environment directly3346 if ( roughness < 0.001 ) {33473348 gl_FragColor = vec4( textureLod( envMap, N, 0.0 ).rgb, 1.0 );3349 return;33503351 }33523353 float alpha = roughness * roughness;3354 float alpha2 = alpha * alpha;33553356 // Tangent space basis for VNDF sampling3357 vec3 up = abs( N.z ) < 0.999 ? vec3( 0.0, 0.0, 1.0 ) : vec3( 1.0, 0.0, 0.0 );3358 vec3 tangent = normalize( cross( up, N ) );3359 vec3 bitangent = cross( N, tangent );33603361 vec3 prefilteredColor = vec3( 0.0 );3362 float totalWeight = 0.0;33633364 for ( uint i = 0u; i < GGX_SAMPLES; i ++ ) {33653366 vec2 Xi = hammersley( i, GGX_SAMPLES );33673368 // With V = N, sample the reflected direction directly.3369 float invQ = 1.0 / ( 1.0 - Xi.x + alpha2 * Xi.x );3370 float NdotL = ( 1.0 - Xi.x - alpha2 * Xi.x ) * invQ;33713372 if ( NdotL > 0.0 ) {33733374 float phi = 2.0 * PI * Xi.y;3375 float sinTheta = 2.0 * alpha * sqrt( Xi.x * ( 1.0 - Xi.x ) ) * invQ;3376 vec3 L = N * NdotL + ( tangent * cos( phi ) + bitangent * sin( phi ) ) * sinTheta;33773378 // Match the source mip to the sample's solid angle. The terms3379 // independent of the sample are precomputed in lodBias.3380 float d = alpha2 * invQ;3381 float lod = max( log2( d ) + lodBias, 0.0 );33823383 // Weight by NdotL for the split-sum approximation3384 prefilteredColor += textureLod( envMap, L, lod ).rgb * NdotL;3385 totalWeight += NdotL;33863387 }33883389 }33903391 gl_FragColor = vec4( prefilteredColor / totalWeight, 1.0 );33923393 }3394 ` );33953396}33973398function _getIntegrationMaterial() {33993400 return _getMaterial( 'PMREMGGXIntegration', {3401 'envMap': { value: null },3402 'roughness': { value: 0 },3403 'sourceLod': { value: 0 },3404 'sourceSize': { value: INTEGRATION_SIZE } 3405 }, `34063407 varying vec3 vWorldDirection;34083409 uniform samplerCube envMap;3410 uniform float roughness;3411 uniform float sourceLod;3412 uniform int sourceSize;34133414 void main() {34153416 vec3 N = normalize( vWorldDirection );34173418 float alpha = roughness * roughness;3419 float alpha2 = alpha * alpha;34203421 float texelSize = 2.0 / float( sourceSize );34223423 vec3 prefilteredColor = vec3( 0.0 );3424 float totalWeight = 0.0;34253426 // Pair opposite texels: only the one in N's hemisphere contributes.3427 for ( int face = 0; face < 3; face ++ ) {34283429 for ( int y = 0; y < sourceSize; y ++ ) {34303431 for ( int x = 0; x < sourceSize; x ++ ) {34323433 vec2 uv = ( vec2( x, y ) + 0.5 ) * texelSize - 1.0;3434 vec3 texelDirection = face == 0 ? vec3( 1.0, uv ) : ( face == 1 ? vec3( uv.x, 1.0, uv.y ) : vec3( uv, 1.0 ) );34353436 float invDistance = inversesqrt( 1.0 + dot( uv, uv ) );3437 float NdotL = dot( N, texelDirection );3438 texelDirection *= NdotL < 0.0 ? - 1.0 : 1.0;3439 NdotL = abs( NdotL ) * invDistance;34403441 // With V = N, NdotH squared is ( 1 + NdotL ) / 2. Common factors3442 // in the GGX distribution and texel solid angle cancel when normalized.3443 float d = 1.0 + alpha2 + ( alpha2 - 1.0 ) * NdotL;3444 float weight = NdotL * invDistance * invDistance * invDistance / ( d * d );34453446 prefilteredColor += textureLod( envMap, texelDirection, sourceLod ).rgb * weight;3447 totalWeight += weight;34483449 }34503451 }34523453 }34543455 gl_FragColor = vec4( prefilteredColor / totalWeight, 1.0 );34563457 }3458 ` );34593460}34613462function _getBlurMaterial() {34633464 return _getMaterial( 'PMREMSphericalGaussianBlur', {3465 'envMap': { value: null },3466 'sigma': { value: 0 }3467 }, `34683469 #define SAMPLES ${ BLUR_SAMPLES }3470 #define GOLDEN_ANGLE 2.3999632297334713472 varying vec3 vWorldDirection;34733474 uniform samplerCube envMap;3475 uniform float sigma;34763477 #include <common>34783479 void main() {34803481 vec3 outputDirection = normalize( vWorldDirection );34823483 vec3 up = abs( outputDirection.z ) < 0.999 ? vec3( 0.0, 0.0, 1.0 ) : vec3( 1.0, 0.0, 0.0 );3484 vec3 tangent = normalize( cross( up, outputDirection ) );3485 vec3 bitangent = cross( outputDirection, tangent );34863487 // Truncate the kernel at three standard deviations or at the antipode.3488 float thetaMax = min( 3.0 * sigma, PI );3489 float truncation = 1.0 - exp( - 0.5 * thetaMax * thetaMax / ( sigma * sigma ) );34903491 vec3 accumColor = vec3( 0.0 );3492 float accumWeight = 0.0;34933494 for ( int i = 0; i < SAMPLES; i ++ ) {34953496 // Stratified inverse-CDF sampling of the Gaussian, placed on a golden-angle spiral.3497 float stratum = ( float( i ) + 0.5 ) / float( SAMPLES );3498 float theta = sigma * sqrt( - 2.0 * log( 1.0 - stratum * truncation ) );3499 float phi = float( i ) * GOLDEN_ANGLE;35003501 vec3 offset = cos( phi ) * tangent + sin( phi ) * bitangent;3502 vec3 sampleDirection = cos( theta ) * outputDirection + sin( theta ) * offset;35033504 // Correct the planar sample density to solid angle.3505 float weight = sin( theta ) / theta;35063507 accumColor += weight * textureLod( envMap, sampleDirection, 0.0 ).rgb;3508 accumWeight += weight;35093510 }35113512 gl_FragColor = vec4( accumColor / accumWeight, 1.0 );35133514 }3515 ` );35163517}35183519function _getEquirectMaterial() {35203521 return _getMaterial( 'PMREMEquirectangularToCubemap', {3522 'envMap': { value: null }3523 }, `35243525 varying vec3 vWorldDirection;35263527 uniform sampler2D envMap;35283529 #include <common>35303531 void main() {35323533 // Average four subpixel samples to preserve small, bright features.3534 vec3 direction = normalize( vWorldDirection );3535 vec3 dx = dFdx( direction ) * 0.25;3536 vec3 dy = dFdy( direction ) * 0.25;35373538 vec3 color = textureLod( envMap, equirectUv( normalize( direction - dx - dy ) ), 0.0 ).rgb;3539 color += textureLod( envMap, equirectUv( normalize( direction + dx - dy ) ), 0.0 ).rgb;3540 color += textureLod( envMap, equirectUv( normalize( direction - dx + dy ) ), 0.0 ).rgb;3541 color += textureLod( envMap, equirectUv( normalize( direction + dx + dy ) ), 0.0 ).rgb;3542 gl_FragColor = vec4( color * 0.25, 1.0 );35433544 }3545 ` );35463547}35483549function _getCubemapMaterial() {35503551 return _getMaterial( 'PMREMCubemapToCubemap', {3552 'envMap': { value: null },3553 'flipEnvMap': { value: -1 }3554 }, `35553556 varying vec3 vWorldDirection;35573558 uniform samplerCube envMap;3559 uniform float flipEnvMap;35603561 void main() {35623563 gl_FragColor = vec4( textureCube( envMap, vec3( flipEnvMap * vWorldDirection.x, vWorldDirection.yz ) ).rgb, 1.0 );35643565 }3566 ` );35673568}35693570function WebGLEnvironments( renderer ) {35713572 let cubeMaps = new WeakMap();3573 let pmremMaps = new WeakMap();35743575 let pmremGenerator = null;35763577 function get( texture, usePMREM = false ) {35783579 if ( texture === null || texture === undefined ) return null;35803581 if ( usePMREM ) {35823583 return getPMREM( texture );35843585 }35863587 return getCube( texture );35883589 }35903591 function getCube( texture ) {35923593 if ( texture && texture.isTexture ) {35943595 const mapping = texture.mapping;35963597 if ( mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping ) {35983599 if ( cubeMaps.has( texture ) ) {36003601 const cubemap = cubeMaps.get( texture ).texture;3602 return mapTextureMapping( cubemap, texture.mapping );36033604 } else {36053606 const image = texture.image;36073608 if ( image && image.height > 0 ) {36093610 const renderTarget = new WebGLCubeRenderTarget( image.height );3611 renderTarget.fromEquirectangularTexture( renderer, texture );3612 cubeMaps.set( texture, renderTarget );36133614 texture.addEventListener( 'dispose', onCubemapDispose );36153616 return mapTextureMapping( renderTarget.texture, texture.mapping );36173618 } else {36193620 36213622 return null;36233624 }36253626 }36273628 }36293630 }36313632 return texture;36333634 }36353636 function getPMREM( texture ) {36373638 if ( texture && texture.isTexture && texture.isPMREMTexture !== true ) {36393640 const mapping = texture.mapping;36413642 const isEquirectMap = ( mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping );3643 const isCubeMap = ( mapping === CubeReflectionMapping || mapping === CubeRefractionMapping );36443645 36463647 if ( isEquirectMap || isCubeMap ) {36483649 let renderTarget = pmremMaps.get( texture );36503651 const currentPMREMVersion = renderTarget !== undefined ? renderTarget.texture.pmremVersion : 0;36523653 if ( texture.isRenderTargetTexture && texture.pmremVersion !== currentPMREMVersion ) {36543655 if ( pmremGenerator === null ) pmremGenerator = new PMREMGenerator( renderer );36563657 renderTarget = isEquirectMap ? pmremGenerator.fromEquirectangular( texture, renderTarget ) : pmremGenerator.fromCubemap( texture, renderTarget );3658 renderTarget.texture.pmremVersion = texture.pmremVersion;36593660 pmremMaps.set( texture, renderTarget );36613662 return renderTarget.texture;36633664 } else {36653666 if ( renderTarget !== undefined ) {36673668 return renderTarget.texture;36693670 } else {36713672 const image = texture.image;36733674 if ( ( isEquirectMap && image && image.height > 0 ) || ( isCubeMap && image && isCubeTextureComplete( image ) ) ) {36753676 if ( pmremGenerator === null ) pmremGenerator = new PMREMGenerator( renderer );36773678 renderTarget = isEquirectMap ? pmremGenerator.fromEquirectangular( texture ) : pmremGenerator.fromCubemap( texture );3679 renderTarget.texture.pmremVersion = texture.pmremVersion;36803681 pmremMaps.set( texture, renderTarget );36823683 texture.addEventListener( 'dispose', onPMREMDispose );36843685 return renderTarget.texture;36863687 } else {36883689 36903691 return null;36923693 }36943695 }36963697 }36983699 }37003701 }37023703 return texture;37043705 }37063707 function mapTextureMapping( texture, mapping ) {37083709 if ( mapping === EquirectangularReflectionMapping ) {37103711 texture.mapping = CubeReflectionMapping;37123713 } else if ( mapping === EquirectangularRefractionMapping ) {37143715 texture.mapping = CubeRefractionMapping;37163717 }37183719 return texture;37203721 }37223723 function isCubeTextureComplete( image ) {37243725 let count = 0;3726 const length = 6;37273728 for ( let i = 0; i < length; i ++ ) {37293730 if ( image[ i ] !== undefined ) count ++;37313732 }37333734 return count === length;37353736 }37373738 function onCubemapDispose( event ) {37393740 const texture = event.target;37413742 texture.removeEventListener( 'dispose', onCubemapDispose );37433744 const cubemap = cubeMaps.get( texture );37453746 if ( cubemap !== undefined ) {37473748 cubeMaps.delete( texture );3749 cubemap.dispose();37503751 }37523753 }37543755 function onPMREMDispose( event ) {37563757 const texture = event.target;37583759 texture.removeEventListener( 'dispose', onPMREMDispose );37603761 const pmrem = pmremMaps.get( texture );37623763 if ( pmrem !== undefined ) {37643765 pmremMaps.delete( texture );3766 pmrem.dispose();37673768 }37693770 }37713772 function dispose() {37733774 cubeMaps = new WeakMap();3775 pmremMaps = new WeakMap();37763777 if ( pmremGenerator !== null ) {37783779 pmremGenerator.dispose();3780 pmremGenerator = null;37813782 }37833784 }37853786 return {3787 get: get,3788 dispose: dispose3789 };37903791}37923793function WebGLExtensions( gl ) {37943795 const extensions = {};37963797 function getExtension( name ) {37983799 if ( extensions[ name ] !== undefined ) {38003801 return extensions[ name ];38023803 }38043805 const extension = gl.getExtension( name );38063807 extensions[ name ] = extension;38083809 return extension;38103811 }38123813 return {38143815 has: function ( name ) {38163817 return getExtension( name ) !== null;38183819 },38203821 init: function () {38223823 getExtension( 'EXT_color_buffer_float' );3824 getExtension( 'WEBGL_clip_cull_distance' );3825 getExtension( 'OES_texture_float_linear' );3826 getExtension( 'EXT_color_buffer_half_float' );3827 getExtension( 'WEBGL_multisampled_render_to_texture' );3828 getExtension( 'WEBGL_render_shared_exponent' );38293830 },38313832 get: function ( name ) {38333834 const extension = getExtension( name );38353836 if ( extension === null ) {38373838 warnOnce( 'WebGLRenderer: ' + name + ' extension not supported.' );38393840 }38413842 return extension;38433844 }38453846 };38473848}38493850function WebGLGeometries( gl, attributes, info, bindingStates ) {38513852 const geometries = {};3853 const wireframeAttributes = new WeakMap();38543855 const registry = new FinalizationRegistry( ( id ) => delete geometries[ id ] );38563857 function onGeometryDispose( event ) {38583859 destroyGeometry( event.target );38603861 }38623863 function destroyGeometry( geometry ) {38643865 if ( geometry.index !== null ) {38663867 attributes.remove( geometry.index );38683869 }38703871 for ( const name in geometry.attributes ) {38723873 attributes.remove( geometry.attributes[ name ] );38743875 }38763877 geometry.removeEventListener( 'dispose', onGeometryDispose );38783879 delete geometries[ geometry.id ];3880 registry.unregister( geometry );38813882 const attribute = wireframeAttributes.get( geometry );38833884 if ( attribute ) {38853886 attributes.remove( attribute );3887 wireframeAttributes.delete( geometry );38883889 }38903891 bindingStates.releaseStatesOfGeometry( geometry );38923893 if ( geometry.isInstancedBufferGeometry === true ) {38943895 delete geometry._maxInstanceCount;38963897 }38983899 39003901 info.memory.geometries --;39023903 }39043905 function get( object, geometry ) {39063907 if ( geometries[ geometry.id ] !== undefined ) return geometry;39083909 geometry.addEventListener( 'dispose', onGeometryDispose );39103911 geometries[ geometry.id ] = new WeakRef( geometry );3912 registry.register( geometry, geometry.id, geometry );39133914 info.memory.geometries ++;39153916 return geometry;39173918 }39193920 function update( geometry ) {39213922 const geometryAttributes = geometry.attributes;39233924 39253926 for ( const name in geometryAttributes ) {39273928 attributes.update( geometryAttributes[ name ], gl.ARRAY_BUFFER );39293930 }39313932 }39333934 function updateWireframeAttribute( geometry ) {39353936 const geometryIndex = geometry.index;3937 const geometryPosition = geometry.attributes.position;3938 let version = 0;39393940 if ( geometryPosition === undefined ) {39413942 return;39433944 }39453946 const count = geometryIndex !== null ? geometryIndex.array.length : ( geometryPosition.array.length / 3 ) - 1;39473948 3949 3950 const IndexBufferAttribute = geometryPosition.count >= 65535 ? Uint32BufferAttribute : Uint16BufferAttribute;3951 const attribute = new IndexBufferAttribute( Math.ceil( count / 3 ) * 6, 1 );3952 const indices = attribute.array;39533954 if ( geometryIndex !== null ) {39553956 const array = geometryIndex.array;3957 version = geometryIndex.version;39583959 for ( let i = 0, j = 0; i < count; i += 3 ) {39603961 const a = array[ i + 0 ];3962 const b = array[ i + 1 ];3963 const c = array[ i + 2 ];39643965 indices[ j ++ ] = a; indices[ j ++ ] = b;3966 indices[ j ++ ] = b; indices[ j ++ ] = c;3967 indices[ j ++ ] = c; indices[ j ++ ] = a;39683969 }39703971 } else {39723973 version = geometryPosition.version;39743975 for ( let i = 0, j = 0; i < count; i += 3 ) {39763977 const a = i + 0;3978 const b = i + 1;3979 const c = i + 2;39803981 indices[ j ++ ] = a; indices[ j ++ ] = b;3982 indices[ j ++ ] = b; indices[ j ++ ] = c;3983 indices[ j ++ ] = c; indices[ j ++ ] = a;39843985 }39863987 }39883989 attribute.version = version;39903991 39923993 39943995 const previousAttribute = wireframeAttributes.get( geometry );39963997 if ( previousAttribute ) attributes.remove( previousAttribute );39983999 40004001 wireframeAttributes.set( geometry, attribute );40024003 }40044005 function getWireframeAttribute( geometry ) {40064007 const currentAttribute = wireframeAttributes.get( geometry );40084009 if ( currentAttribute ) {40104011 const geometryIndex = geometry.index;40124013 if ( geometryIndex !== null ) {40144015 40164017 if ( currentAttribute.version < geometryIndex.version ) {40184019 updateWireframeAttribute( geometry );40204021 }40224023 }40244025 } else {40264027 updateWireframeAttribute( geometry );40284029 }40304031 return wireframeAttributes.get( geometry );40324033 }40344035 function dispose() {40364037 for ( const id in geometries ) {40384039 const geometry = geometries[ id ].deref();40404041 if ( geometry !== undefined ) destroyGeometry( geometry );40424043 }40444045 }40464047 return {40484049 get: get,4050 update: update,40514052 getWireframeAttribute: getWireframeAttribute,40534054 dispose: dispose40554056 };40574058}40594060function WebGLIndexedBufferRenderer( gl, extensions, info ) {40614062 let mode;40634064 function setMode( value ) {40654066 mode = value;40674068 }40694070 let type, bytesPerElement;40714072 function setIndex( value ) {40734074 type = value.type;4075 bytesPerElement = value.bytesPerElement;40764077 }40784079 function render( start, count ) {40804081 gl.drawElements( mode, count, type, start * bytesPerElement );40824083 info.update( count, mode, 1 );40844085 }40864087 function renderInstances( start, count, primcount ) {40884089 if ( primcount === 0 ) return;40904091 gl.drawElementsInstanced( mode, count, type, start * bytesPerElement, primcount );40924093 info.update( count, mode, primcount );40944095 }40964097 function renderMultiDraw( starts, counts, drawCount ) {40984099 if ( drawCount === 0 ) return;41004101 const extension = extensions.get( 'WEBGL_multi_draw' );4102 extension.multiDrawElementsWEBGL( mode, counts, 0, type, starts, 0, drawCount );41034104 let elementCount = 0;4105 for ( let i = 0; i < drawCount; i ++ ) {41064107 elementCount += counts[ i ];41084109 }41104111 info.update( elementCount, mode, 1 );411241134114 }41154116 41174118 this.setMode = setMode;4119 this.setIndex = setIndex;4120 this.render = render;4121 this.renderInstances = renderInstances;4122 this.renderMultiDraw = renderMultiDraw;41234124}41254126function WebGLInfo( gl ) {41274128 const memory = {4129 geometries: 0,4130 textures: 04131 };41324133 const render = {4134 frame: 0,4135 calls: 0,4136 triangles: 0,4137 points: 0,4138 lines: 04139 };41404141 function update( count, mode, instanceCount ) {41424143 render.calls ++;41444145 switch ( mode ) {41464147 case gl.TRIANGLES:4148 render.triangles += instanceCount * ( count / 3 );4149 break;41504151 case gl.LINES:4152 render.lines += instanceCount * ( count / 2 );4153 break;41544155 case gl.LINE_STRIP:4156 render.lines += instanceCount * ( count - 1 );4157 break;41584159 case gl.LINE_LOOP:4160 render.lines += instanceCount * count;4161 break;41624163 case gl.POINTS:4164 render.points += instanceCount * count;4165 break;41664167 default:4168 error( 'WebGLInfo: Unknown draw mode:', mode );4169 break;41704171 }41724173 }41744175 function reset() {41764177 render.calls = 0;4178 render.triangles = 0;4179 render.points = 0;4180 render.lines = 0;41814182 }41834184 return {4185 memory: memory,4186 render: render,4187 programs: null,4188 autoReset: true,4189 reset: reset,4190 update: update4191 };41924193}41944195function WebGLMorphtargets( gl, capabilities, textures ) {41964197 const morphTextures = new WeakMap();4198 const morph = new Vector4();41994200 function update( object, geometry, program ) {42014202 const objectInfluences = object.morphTargetInfluences;42034204 42054206 const morphAttribute = geometry.morphAttributes.position || geometry.morphAttributes.normal || geometry.morphAttributes.color;4207 const morphTargetsCount = ( morphAttribute !== undefined ) ? morphAttribute.length : 0;42084209 let entry = morphTextures.get( geometry );42104211 if ( entry === undefined || entry.count !== morphTargetsCount ) {42124213 if ( entry !== undefined ) entry.texture.dispose();42144215 const hasMorphPosition = geometry.morphAttributes.position !== undefined;4216 const hasMorphNormals = geometry.morphAttributes.normal !== undefined;4217 const hasMorphColors = geometry.morphAttributes.color !== undefined;42184219 const morphTargets = geometry.morphAttributes.position || [];4220 const morphNormals = geometry.morphAttributes.normal || [];4221 const morphColors = geometry.morphAttributes.color || [];42224223 let vertexDataCount = 0;42244225 if ( hasMorphPosition === true ) vertexDataCount = 1;4226 if ( hasMorphNormals === true ) vertexDataCount = 2;4227 if ( hasMorphColors === true ) vertexDataCount = 3;42284229 let width = geometry.attributes.position.count * vertexDataCount;4230 let height = 1;42314232 if ( width > capabilities.maxTextureSize ) {42334234 height = Math.ceil( width / capabilities.maxTextureSize );4235 width = capabilities.maxTextureSize;42364237 }42384239 const buffer = new Float32Array( width * height * 4 * morphTargetsCount );42404241 const texture = new DataArrayTexture( buffer, width, height, morphTargetsCount );4242 texture.type = FloatType;4243 texture.needsUpdate = true;42444245 42464247 const vertexDataStride = vertexDataCount * 4;42484249 for ( let i = 0; i < morphTargetsCount; i ++ ) {42504251 const morphTarget = morphTargets[ i ];4252 const morphNormal = morphNormals[ i ];4253 const morphColor = morphColors[ i ];42544255 const offset = width * height * 4 * i;42564257 for ( let j = 0; j < morphTarget.count; j ++ ) {42584259 const stride = j * vertexDataStride;42604261 if ( hasMorphPosition === true ) {42624263 morph.fromBufferAttribute( morphTarget, j );42644265 buffer[ offset + stride + 0 ] = morph.x;4266 buffer[ offset + stride + 1 ] = morph.y;4267 buffer[ offset + stride + 2 ] = morph.z;4268 buffer[ offset + stride + 3 ] = 0;42694270 }42714272 if ( hasMorphNormals === true ) {42734274 morph.fromBufferAttribute( morphNormal, j );42754276 buffer[ offset + stride + 4 ] = morph.x;4277 buffer[ offset + stride + 5 ] = morph.y;4278 buffer[ offset + stride + 6 ] = morph.z;4279 buffer[ offset + stride + 7 ] = 0;42804281 }42824283 if ( hasMorphColors === true ) {42844285 morph.fromBufferAttribute( morphColor, j );42864287 buffer[ offset + stride + 8 ] = morph.x;4288 buffer[ offset + stride + 9 ] = morph.y;4289 buffer[ offset + stride + 10 ] = morph.z;4290 buffer[ offset + stride + 11 ] = ( morphColor.itemSize === 4 ) ? morph.w : 1;42914292 }42934294 }42954296 }42974298 entry = {4299 count: morphTargetsCount,4300 texture: texture,4301 size: new Vector2( width, height )4302 };43034304 morphTextures.set( geometry, entry );43054306 function disposeTexture() {43074308 texture.dispose();43094310 morphTextures.delete( geometry );43114312 geometry.removeEventListener( 'dispose', disposeTexture );43134314 }43154316 geometry.addEventListener( 'dispose', disposeTexture );43174318 }43194320 4321 if ( object.isInstancedMesh === true && object.morphTexture !== null ) {43224323 program.getUniforms().setValue( gl, 'morphTexture', object.morphTexture, textures );43244325 } else {43264327 let morphInfluencesSum = 0;43284329 for ( let i = 0; i < objectInfluences.length; i ++ ) {43304331 morphInfluencesSum += objectInfluences[ i ];43324333 }43344335 const morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;433643374338 program.getUniforms().setValue( gl, 'morphTargetBaseInfluence', morphBaseInfluence );4339 program.getUniforms().setValue( gl, 'morphTargetInfluences', objectInfluences );43404341 }43424343 program.getUniforms().setValue( gl, 'morphTargetsTexture', entry.texture, textures );4344 program.getUniforms().setValue( gl, 'morphTargetsTextureSize', entry.size );43454346 }43474348 return {43494350 update: update43514352 };43534354}43554356function WebGLObjects( gl, geometries, attributes, bindingStates, info ) {43574358 let updateMap = new WeakMap();43594360 function update( object ) {43614362 const frame = info.render.frame;43634364 const geometry = object.geometry;4365 const buffergeometry = geometries.get( object, geometry );43664367 43684369 if ( updateMap.get( buffergeometry ) !== frame ) {43704371 geometries.update( buffergeometry );43724373 updateMap.set( buffergeometry, frame );43744375 }43764377 if ( object.isInstancedMesh ) {43784379 if ( object.hasEventListener( 'dispose', onInstancedMeshDispose ) === false ) {43804381 object.addEventListener( 'dispose', onInstancedMeshDispose );43824383 }43844385 if ( updateMap.get( object ) !== frame ) {43864387 attributes.update( object.instanceMatrix, gl.ARRAY_BUFFER );43884389 if ( object.instanceColor !== null ) {43904391 attributes.update( object.instanceColor, gl.ARRAY_BUFFER );43924393 }43944395 updateMap.set( object, frame );43964397 }43984399 }44004401 if ( object.isSkinnedMesh ) {44024403 const skeleton = object.skeleton;44044405 if ( updateMap.get( skeleton ) !== frame ) {44064407 skeleton.update();44084409 updateMap.set( skeleton, frame );44104411 }44124413 }44144415 return buffergeometry;44164417 }44184419 function dispose() {44204421 updateMap = new WeakMap();44224423 }44244425 function onInstancedMeshDispose( event ) {44264427 const instancedMesh = event.target;44284429 instancedMesh.removeEventListener( 'dispose', onInstancedMeshDispose );44304431 bindingStates.releaseStatesOfObject( instancedMesh );44324433 attributes.remove( instancedMesh.instanceMatrix );44344435 if ( instancedMesh.instanceColor !== null ) attributes.remove( instancedMesh.instanceColor );44364437 }44384439 return {44404441 update: update,4442 dispose: dispose44434444 };44454446}44474448const toneMappingMap = {4449 [ LinearToneMapping ]: 'LINEAR_TONE_MAPPING',4450 [ ReinhardToneMapping ]: 'REINHARD_TONE_MAPPING',4451 [ CineonToneMapping ]: 'CINEON_TONE_MAPPING',4452 [ ACESFilmicToneMapping ]: 'ACES_FILMIC_TONE_MAPPING',4453 [ AgXToneMapping ]: 'AGX_TONE_MAPPING',4454 [ NeutralToneMapping ]: 'NEUTRAL_TONE_MAPPING',4455 [ CustomToneMapping ]: 'CUSTOM_TONE_MAPPING'4456};44574458function WebGLOutput( type, width, height, antialias, depth, stencil ) {44594460 4461 const targetScene = new WebGLRenderTarget( width, height, {4462 type: type,4463 depthBuffer: depth,4464 stencilBuffer: stencil,4465 samples: antialias ? 4 : 0,4466 storeMultisampledDepthBuffer: false,4467 storeMultisampledStencilBuffer: false,4468 resolveDepthBuffer: false,4469 resolveStencilBuffer: false4470 } );44714472 4473 let targetA = null;4474 let targetB = null;44754476 4477 let depthTexture = null;44784479 4480 const geometry = new BufferGeometry();4481 geometry.setAttribute( 'position', new Float32BufferAttribute( [ -1, 3, 0, -1, -1, 0, 3, -1, 0 ], 3 ) );4482 geometry.setAttribute( 'uv', new Float32BufferAttribute( [ 0, 2, 0, 0, 2, 0 ], 2 ) );44834484 4485 const material = new RawShaderMaterial( {4486 uniforms: {4487 tDiffuse: { value: null }4488 },4489 vertexShader: `4490 precision highp float;44914492 uniform mat4 modelViewMatrix;4493 uniform mat4 projectionMatrix;44944495 attribute vec3 position;4496 attribute vec2 uv;44974498 varying vec2 vUv;44994500 void main() {4501 vUv = uv;4502 gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );4503 }`,4504 fragmentShader: `4505 precision highp float;45064507 uniform sampler2D tDiffuse;45084509 varying vec2 vUv;45104511 #include <tonemapping_pars_fragment>4512 #include <colorspace_pars_fragment>45134514 void main() {4515 gl_FragColor = texture2D( tDiffuse, vUv );45164517 #ifdef LINEAR_TONE_MAPPING4518 gl_FragColor.rgb = LinearToneMapping( gl_FragColor.rgb );4519 #elif defined( REINHARD_TONE_MAPPING )4520 gl_FragColor.rgb = ReinhardToneMapping( gl_FragColor.rgb );4521 #elif defined( CINEON_TONE_MAPPING )4522 gl_FragColor.rgb = CineonToneMapping( gl_FragColor.rgb );4523 #elif defined( ACES_FILMIC_TONE_MAPPING )4524 gl_FragColor.rgb = ACESFilmicToneMapping( gl_FragColor.rgb );4525 #elif defined( AGX_TONE_MAPPING )4526 gl_FragColor.rgb = AgXToneMapping( gl_FragColor.rgb );4527 #elif defined( NEUTRAL_TONE_MAPPING )4528 gl_FragColor.rgb = NeutralToneMapping( gl_FragColor.rgb );4529 #elif defined( CUSTOM_TONE_MAPPING )4530 gl_FragColor.rgb = CustomToneMapping( gl_FragColor.rgb );4531 #endif45324533 #ifdef SRGB_TRANSFER4534 gl_FragColor = sRGBTransferOETF( gl_FragColor );4535 #endif4536 }`,4537 depthTest: false,4538 depthWrite: false4539 } );45404541 const mesh = new Mesh( geometry, material );4542 const camera = new OrthographicCamera( -1, 1, 1, -1, 0, 1 );45434544 let _outputColorSpace = null;4545 let _outputToneMapping = null;4546 let _isCompositing = false;4547 let _savedToneMapping;4548 let _savedRenderTarget = null;4549 let _effects = [];4550 let _hasRenderPass = false;45514552 this.setSize = function ( width, height ) {45534554 targetScene.setSize( width, height );45554556 if ( targetA !== null ) targetA.setSize( width, height );4557 if ( targetB !== null ) targetB.setSize( width, height );45584559 for ( let i = 0; i < _effects.length; i ++ ) {45604561 const effect = _effects[ i ];4562 if ( effect.setSize ) effect.setSize( width, height );45634564 }45654566 };45674568 this.setEffects = function ( effects ) {45694570 _effects = effects;4571 _hasRenderPass = _effects.length > 0 && _effects[ 0 ].isRenderPass === true;45724573 const width = targetScene.width;4574 const height = targetScene.height;45754576 if ( _effects.length > 0 && targetA === null ) {45774578 targetA = new WebGLRenderTarget( width, height, { type: HalfFloatType, depthBuffer: false, stencilBuffer: false } );4579 targetB = new WebGLRenderTarget( width, height, { type: HalfFloatType, depthBuffer: false, stencilBuffer: false } );45804581 }45824583 45844585 const needsDepthTexture = depth === true && _effects.some( ( effect ) => effect.needsDepthTexture === true );45864587 if ( needsDepthTexture !== ( targetScene.depthTexture !== null ) ) {45884589 if ( needsDepthTexture === true && depthTexture === null ) {45904591 depthTexture = new DepthTexture( width, height );45924593 if ( stencil === true ) {45944595 depthTexture.format = DepthStencilFormat;4596 depthTexture.type = UnsignedInt248Type;45974598 }45994600 }46014602 46034604 targetScene.dispose();46054606 targetScene.depthTexture = needsDepthTexture ? depthTexture : null;4607 targetScene.resolveDepthBuffer = needsDepthTexture;4608 targetScene.storeMultisampledDepthBuffer = needsDepthTexture;46094610 }46114612 for ( let i = 0; i < _effects.length; i ++ ) {46134614 const effect = _effects[ i ];4615 if ( effect.setSize ) effect.setSize( width, height );4616 if ( needsDepthTexture && effect.needsDepthTexture === true && effect.setDepthTexture ) effect.setDepthTexture( depthTexture );46174618 }46194620 };46214622 this.begin = function ( renderer, renderTarget ) {46234624 4625 if ( _isCompositing ) return false;46264627 if ( renderer.toneMapping === NoToneMapping && _effects.length === 0 ) return false;46284629 _savedRenderTarget = renderTarget;46304631 4632 if ( renderTarget !== null ) {46334634 const width = renderTarget.width;4635 const height = renderTarget.height;46364637 if ( targetScene.width !== width || targetScene.height !== height ) {46384639 this.setSize( width, height );46404641 }46424643 }46444645 4646 if ( _hasRenderPass === false ) {46474648 renderer.setRenderTarget( targetScene );46494650 }46514652 4653 _savedToneMapping = renderer.toneMapping;4654 renderer.toneMapping = NoToneMapping;46554656 return true;46574658 };46594660 this.hasRenderPass = function () {46614662 return _hasRenderPass;46634664 };46654666 this.end = function ( renderer, deltaTime ) {46674668 4669 renderer.toneMapping = _savedToneMapping;46704671 _isCompositing = true;46724673 4674 4675 let readBuffer = targetScene;4676 let writeBuffer = targetA;46774678 for ( let i = 0; i < _effects.length; i ++ ) {46794680 const effect = _effects[ i ];46814682 if ( effect.enabled === false ) continue;46834684 effect.render( renderer, writeBuffer, readBuffer, deltaTime );46854686 if ( effect.needsSwap !== false ) {46874688 4689 readBuffer = writeBuffer;4690 writeBuffer = ( writeBuffer === targetA ) ? targetB : targetA;46914692 }46934694 }46954696 4697 if ( _outputColorSpace !== renderer.outputColorSpace || _outputToneMapping !== renderer.toneMapping ) {46984699 _outputColorSpace = renderer.outputColorSpace;4700 _outputToneMapping = renderer.toneMapping;47014702 material.defines = {};47034704 if ( ColorManagement.getTransfer( _outputColorSpace ) === SRGBTransfer ) material.defines.SRGB_TRANSFER = '';47054706 const toneMapping = toneMappingMap[ _outputToneMapping ];4707 if ( toneMapping ) material.defines[ toneMapping ] = '';47084709 material.needsUpdate = true;47104711 }47124713 4714 material.uniforms.tDiffuse.value = readBuffer.texture;4715 renderer.setRenderTarget( _savedRenderTarget );4716 renderer.render( mesh, camera );47174718 _savedRenderTarget = null;4719 _isCompositing = false;47204721 };47224723 this.isCompositing = function () {47244725 return _isCompositing;47264727 };47284729 this.dispose = function () {47304731 targetScene.dispose();47324733 if ( targetA !== null ) targetA.dispose();4734 if ( targetB !== null ) targetB.dispose();47354736 geometry.dispose();4737 material.dispose();47384739 };47404741}4742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787const emptyTexture = new Texture();47884789const emptyShadowTexture = new DepthTexture( 1, 1 );4790const emptyCubeShadowTexture = new CubeDepthTexture( 1 );47914792const emptyArrayTexture = new DataArrayTexture();4793const empty3dTexture = new Data3DTexture();4794const emptyCubeTexture = new CubeTexture();479547964797479847994800const arrayCacheF32 = [];4801const arrayCacheI32 = [];4802480348044805const mat4array = new Float32Array( 16 );4806const mat3array = new Float32Array( 9 );4807const mat2array = new Float32Array( 4 );4808480948104811function flatten( array, nBlocks, blockSize ) {48124813 const firstElem = array[ 0 ];48144815 if ( firstElem <= 0 || firstElem > 0 ) return array;4816 4817 48184819 const n = nBlocks * blockSize;4820 let r = arrayCacheF32[ n ];48214822 if ( r === undefined ) {48234824 r = new Float32Array( n );4825 arrayCacheF32[ n ] = r;48264827 }48284829 if ( nBlocks !== 0 ) {48304831 firstElem.toArray( r, 0 );48324833 for ( let i = 1, offset = 0; i !== nBlocks; ++ i ) {48344835 offset += blockSize;4836 array[ i ].toArray( r, offset );48374838 }48394840 }48414842 return r;48434844}48454846function arraysEqual( a, b ) {48474848 if ( a.length !== b.length ) return false;48494850 for ( let i = 0, l = a.length; i < l; i ++ ) {48514852 if ( a[ i ] !== b[ i ] ) return false;48534854 }48554856 return true;48574858}48594860function copyArray( a, b ) {48614862 for ( let i = 0, l = b.length; i < l; i ++ ) {48634864 a[ i ] = b[ i ];48654866 }48674868}4869487048714872function allocTexUnits( textures, n ) {48734874 let r = arrayCacheI32[ n ];48754876 if ( r === undefined ) {48774878 r = new Int32Array( n );4879 arrayCacheI32[ n ] = r;48804881 }48824883 for ( let i = 0; i !== n; ++ i ) {48844885 r[ i ] = textures.allocateTextureUnit();48864887 }48884889 return r;48904891}489248934894489548964897489848994900function setValueV1f( gl, v ) {49014902 const cache = this.cache;49034904 if ( cache[ 0 ] === v ) return;49054906 gl.uniform1f( this.addr, v );49074908 cache[ 0 ] = v;49094910}4911491249134914function setValueV2f( gl, v ) {49154916 const cache = this.cache;49174918 if ( v.x !== undefined ) {49194920 if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y ) {49214922 gl.uniform2f( this.addr, v.x, v.y );49234924 cache[ 0 ] = v.x;4925 cache[ 1 ] = v.y;49264927 }49284929 } else {49304931 if ( arraysEqual( cache, v ) ) return;49324933 gl.uniform2fv( this.addr, v );49344935 copyArray( cache, v );49364937 }49384939}49404941function setValueV3f( gl, v ) {49424943 const cache = this.cache;49444945 if ( v.x !== undefined ) {49464947 if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z ) {49484949 gl.uniform3f( this.addr, v.x, v.y, v.z );49504951 cache[ 0 ] = v.x;4952 cache[ 1 ] = v.y;4953 cache[ 2 ] = v.z;49544955 }49564957 } else if ( v.r !== undefined ) {49584959 if ( cache[ 0 ] !== v.r || cache[ 1 ] !== v.g || cache[ 2 ] !== v.b ) {49604961 gl.uniform3f( this.addr, v.r, v.g, v.b );49624963 cache[ 0 ] = v.r;4964 cache[ 1 ] = v.g;4965 cache[ 2 ] = v.b;49664967 }49684969 } else {49704971 if ( arraysEqual( cache, v ) ) return;49724973 gl.uniform3fv( this.addr, v );49744975 copyArray( cache, v );49764977 }49784979}49804981function setValueV4f( gl, v ) {49824983 const cache = this.cache;49844985 if ( v.x !== undefined ) {49864987 if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z || cache[ 3 ] !== v.w ) {49884989 gl.uniform4f( this.addr, v.x, v.y, v.z, v.w );49904991 cache[ 0 ] = v.x;4992 cache[ 1 ] = v.y;4993 cache[ 2 ] = v.z;4994 cache[ 3 ] = v.w;49954996 }49974998 } else {49995000 if ( arraysEqual( cache, v ) ) return;50015002 gl.uniform4fv( this.addr, v );50035004 copyArray( cache, v );50055006 }50075008}5009501050115012function setValueM2( gl, v ) {50135014 const cache = this.cache;5015 const elements = v.elements;50165017 if ( elements === undefined ) {50185019 if ( arraysEqual( cache, v ) ) return;50205021 gl.uniformMatrix2fv( this.addr, false, v );50225023 copyArray( cache, v );50245025 } else {50265027 if ( arraysEqual( cache, elements ) ) return;50285029 mat2array.set( elements );50305031 gl.uniformMatrix2fv( this.addr, false, mat2array );50325033 copyArray( cache, elements );50345035 }50365037}50385039function setValueM3( gl, v ) {50405041 const cache = this.cache;5042 const elements = v.elements;50435044 if ( elements === undefined ) {50455046 if ( arraysEqual( cache, v ) ) return;50475048 gl.uniformMatrix3fv( this.addr, false, v );50495050 copyArray( cache, v );50515052 } else {50535054 if ( arraysEqual( cache, elements ) ) return;50555056 mat3array.set( elements );50575058 gl.uniformMatrix3fv( this.addr, false, mat3array );50595060 copyArray( cache, elements );50615062 }50635064}50655066function setValueM4( gl, v ) {50675068 const cache = this.cache;5069 const elements = v.elements;50705071 if ( elements === undefined ) {50725073 if ( arraysEqual( cache, v ) ) return;50745075 gl.uniformMatrix4fv( this.addr, false, v );50765077 copyArray( cache, v );50785079 } else {50805081 if ( arraysEqual( cache, elements ) ) return;50825083 mat4array.set( elements );50845085 gl.uniformMatrix4fv( this.addr, false, mat4array );50865087 copyArray( cache, elements );50885089 }50905091}5092509350945095function setValueV1i( gl, v ) {50965097 const cache = this.cache;50985099 if ( cache[ 0 ] === v ) return;51005101 gl.uniform1i( this.addr, v );51025103 cache[ 0 ] = v;51045105}5106510751085109function setValueV2i( gl, v ) {51105111 const cache = this.cache;51125113 if ( v.x !== undefined ) {51145115 if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y ) {51165117 gl.uniform2i( this.addr, v.x, v.y );51185119 cache[ 0 ] = v.x;5120 cache[ 1 ] = v.y;51215122 }51235124 } else {51255126 if ( arraysEqual( cache, v ) ) return;51275128 gl.uniform2iv( this.addr, v );51295130 copyArray( cache, v );51315132 }51335134}51355136function setValueV3i( gl, v ) {51375138 const cache = this.cache;51395140 if ( v.x !== undefined ) {51415142 if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z ) {51435144 gl.uniform3i( this.addr, v.x, v.y, v.z );51455146 cache[ 0 ] = v.x;5147 cache[ 1 ] = v.y;5148 cache[ 2 ] = v.z;51495150 }51515152 } else {51535154 if ( arraysEqual( cache, v ) ) return;51555156 gl.uniform3iv( this.addr, v );51575158 copyArray( cache, v );51595160 }51615162}51635164function setValueV4i( gl, v ) {51655166 const cache = this.cache;51675168 if ( v.x !== undefined ) {51695170 if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z || cache[ 3 ] !== v.w ) {51715172 gl.uniform4i( this.addr, v.x, v.y, v.z, v.w );51735174 cache[ 0 ] = v.x;5175 cache[ 1 ] = v.y;5176 cache[ 2 ] = v.z;5177 cache[ 3 ] = v.w;51785179 }51805181 } else {51825183 if ( arraysEqual( cache, v ) ) return;51845185 gl.uniform4iv( this.addr, v );51865187 copyArray( cache, v );51885189 }51905191}5192519351945195function setValueV1ui( gl, v ) {51965197 const cache = this.cache;51985199 if ( cache[ 0 ] === v ) return;52005201 gl.uniform1ui( this.addr, v );52025203 cache[ 0 ] = v;52045205}5206520752085209function setValueV2ui( gl, v ) {52105211 const cache = this.cache;52125213 if ( v.x !== undefined ) {52145215 if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y ) {52165217 gl.uniform2ui( this.addr, v.x, v.y );52185219 cache[ 0 ] = v.x;5220 cache[ 1 ] = v.y;52215222 }52235224 } else {52255226 if ( arraysEqual( cache, v ) ) return;52275228 gl.uniform2uiv( this.addr, v );52295230 copyArray( cache, v );52315232 }52335234}52355236function setValueV3ui( gl, v ) {52375238 const cache = this.cache;52395240 if ( v.x !== undefined ) {52415242 if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z ) {52435244 gl.uniform3ui( this.addr, v.x, v.y, v.z );52455246 cache[ 0 ] = v.x;5247 cache[ 1 ] = v.y;5248 cache[ 2 ] = v.z;52495250 }52515252 } else {52535254 if ( arraysEqual( cache, v ) ) return;52555256 gl.uniform3uiv( this.addr, v );52575258 copyArray( cache, v );52595260 }52615262}52635264function setValueV4ui( gl, v ) {52655266 const cache = this.cache;52675268 if ( v.x !== undefined ) {52695270 if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z || cache[ 3 ] !== v.w ) {52715272 gl.uniform4ui( this.addr, v.x, v.y, v.z, v.w );52735274 cache[ 0 ] = v.x;5275 cache[ 1 ] = v.y;5276 cache[ 2 ] = v.z;5277 cache[ 3 ] = v.w;52785279 }52805281 } else {52825283 if ( arraysEqual( cache, v ) ) return;52845285 gl.uniform4uiv( this.addr, v );52865287 copyArray( cache, v );52885289 }52905291}529252935294function initShadowTexture( texture ) {52955296 if ( texture.version === 0 ) {52975298 texture.compareFunction = AlwaysCompare;5299 texture.needsUpdate = true;53005301 }53025303 return texture;53045305}5306530753085309function setValueT1( gl, v, textures ) {53105311 const cache = this.cache;5312 const unit = textures.allocateTextureUnit();53135314 if ( cache[ 0 ] !== unit ) {53155316 gl.uniform1i( this.addr, unit );5317 cache[ 0 ] = unit;53185319 }53205321 let emptyTexture2D;53225323 if ( this.type === gl.SAMPLER_2D_SHADOW ) {53245325 emptyTexture2D = initShadowTexture( emptyShadowTexture );53265327 } else {53285329 emptyTexture2D = emptyTexture;53305331 }53325333 textures.setTexture2D( v || emptyTexture2D, unit );53345335}53365337function setValueT3D1( gl, v, textures ) {53385339 const cache = this.cache;5340 const unit = textures.allocateTextureUnit();53415342 if ( cache[ 0 ] !== unit ) {53435344 gl.uniform1i( this.addr, unit );5345 cache[ 0 ] = unit;53465347 }53485349 textures.setTexture3D( v || empty3dTexture, unit );53505351}53525353function setValueT6( gl, v, textures ) {53545355 const cache = this.cache;5356 const unit = textures.allocateTextureUnit();53575358 if ( cache[ 0 ] !== unit ) {53595360 gl.uniform1i( this.addr, unit );5361 cache[ 0 ] = unit;53625363 }53645365 let emptyTextureCube;53665367 if ( this.type === gl.SAMPLER_CUBE_SHADOW ) {53685369 emptyTextureCube = initShadowTexture( emptyCubeShadowTexture );53705371 } else {53725373 emptyTextureCube = emptyCubeTexture;53745375 }53765377 textures.setTextureCube( v || emptyTextureCube, unit );53785379}53805381function setValueT2DArray1( gl, v, textures ) {53825383 const cache = this.cache;5384 const unit = textures.allocateTextureUnit();53855386 if ( cache[ 0 ] !== unit ) {53875388 gl.uniform1i( this.addr, unit );5389 cache[ 0 ] = unit;53905391 }53925393 textures.setTexture2DArray( v || emptyArrayTexture, unit );53945395}5396539753985399function getSingularSetter( type ) {54005401 switch ( type ) {54025403 case 0x1406: return setValueV1f; 5404 case 0x8b50: return setValueV2f; 5405 case 0x8b51: return setValueV3f; 5406 case 0x8b52: return setValueV4f; 54075408 case 0x8b5a: return setValueM2; 5409 case 0x8b5b: return setValueM3; 5410 case 0x8b5c: return setValueM4; 54115412 case 0x1404: case 0x8b56: return setValueV1i; 5413 case 0x8b53: case 0x8b57: return setValueV2i; 5414 case 0x8b54: case 0x8b58: return setValueV3i; 5415 case 0x8b55: case 0x8b59: return setValueV4i; 54165417 case 0x1405: return setValueV1ui; 5418 case 0x8dc6: return setValueV2ui; 5419 case 0x8dc7: return setValueV3ui; 5420 case 0x8dc8: return setValueV4ui; 54215422 case 0x8b5e: 5423 case 0x8d66: 5424 case 0x8dca: 5425 case 0x8dd2: 5426 case 0x8b62: 5427 return setValueT1;54285429 case 0x8b5f: 5430 case 0x8dcb: 5431 case 0x8dd3: 5432 return setValueT3D1;54335434 case 0x8b60: 5435 case 0x8dcc: 5436 case 0x8dd4: 5437 case 0x8dc5: 5438 return setValueT6;54395440 case 0x8dc1: 5441 case 0x8dcf: 5442 case 0x8dd7: 5443 case 0x8dc4: 5444 return setValueT2DArray1;54455446 }54475448}54495450545154525453function setValueV1fArray( gl, v ) {54545455 gl.uniform1fv( this.addr, v );54565457}5458545954605461function setValueV2fArray( gl, v ) {54625463 const data = flatten( v, this.size, 2 );54645465 gl.uniform2fv( this.addr, data );54665467}54685469function setValueV3fArray( gl, v ) {54705471 const data = flatten( v, this.size, 3 );54725473 gl.uniform3fv( this.addr, data );54745475}54765477function setValueV4fArray( gl, v ) {54785479 const data = flatten( v, this.size, 4 );54805481 gl.uniform4fv( this.addr, data );54825483}5484548554865487function setValueM2Array( gl, v ) {54885489 const data = flatten( v, this.size, 4 );54905491 gl.uniformMatrix2fv( this.addr, false, data );54925493}54945495function setValueM3Array( gl, v ) {54965497 const data = flatten( v, this.size, 9 );54985499 gl.uniformMatrix3fv( this.addr, false, data );55005501}55025503function setValueM4Array( gl, v ) {55045505 const data = flatten( v, this.size, 16 );55065507 gl.uniformMatrix4fv( this.addr, false, data );55085509}5510551155125513function setValueV1iArray( gl, v ) {55145515 gl.uniform1iv( this.addr, v );55165517}5518551955205521function setValueV2iArray( gl, v ) {55225523 gl.uniform2iv( this.addr, v );55245525}55265527function setValueV3iArray( gl, v ) {55285529 gl.uniform3iv( this.addr, v );55305531}55325533function setValueV4iArray( gl, v ) {55345535 gl.uniform4iv( this.addr, v );55365537}5538553955405541function setValueV1uiArray( gl, v ) {55425543 gl.uniform1uiv( this.addr, v );55445545}5546554755485549function setValueV2uiArray( gl, v ) {55505551 gl.uniform2uiv( this.addr, v );55525553}55545555function setValueV3uiArray( gl, v ) {55565557 gl.uniform3uiv( this.addr, v );55585559}55605561function setValueV4uiArray( gl, v ) {55625563 gl.uniform4uiv( this.addr, v );55645565}55665567556855695570function setValueT1Array( gl, v, textures ) {55715572 const cache = this.cache;55735574 const n = v.length;55755576 const units = allocTexUnits( textures, n );55775578 if ( ! arraysEqual( cache, units ) ) {55795580 gl.uniform1iv( this.addr, units );55815582 copyArray( cache, units );55835584 }55855586 let emptyTexture2D;55875588 if ( this.type === gl.SAMPLER_2D_SHADOW ) {55895590 emptyTexture2D = initShadowTexture( emptyShadowTexture );55915592 } else {55935594 emptyTexture2D = emptyTexture;55955596 }55975598 for ( let i = 0; i !== n; ++ i ) {55995600 textures.setTexture2D( v[ i ] || emptyTexture2D, units[ i ] );56015602 }56035604}56055606function setValueT3DArray( gl, v, textures ) {56075608 const cache = this.cache;56095610 const n = v.length;56115612 const units = allocTexUnits( textures, n );56135614 if ( ! arraysEqual( cache, units ) ) {56155616 gl.uniform1iv( this.addr, units );56175618 copyArray( cache, units );56195620 }56215622 for ( let i = 0; i !== n; ++ i ) {56235624 textures.setTexture3D( v[ i ] || empty3dTexture, units[ i ] );56255626 }56275628}56295630function setValueT6Array( gl, v, textures ) {56315632 const cache = this.cache;56335634 const n = v.length;56355636 const units = allocTexUnits( textures, n );56375638 if ( ! arraysEqual( cache, units ) ) {56395640 gl.uniform1iv( this.addr, units );56415642 copyArray( cache, units );56435644 }56455646 let emptyTextureCube;56475648 if ( this.type === gl.SAMPLER_CUBE_SHADOW ) {56495650 emptyTextureCube = initShadowTexture( emptyCubeShadowTexture );56515652 } else {56535654 emptyTextureCube = emptyCubeTexture;56555656 }56575658 for ( let i = 0; i !== n; ++ i ) {56595660 textures.setTextureCube( v[ i ] || emptyTextureCube, units[ i ] );56615662 }56635664}56655666function setValueT2DArrayArray( gl, v, textures ) {56675668 const cache = this.cache;56695670 const n = v.length;56715672 const units = allocTexUnits( textures, n );56735674 if ( ! arraysEqual( cache, units ) ) {56755676 gl.uniform1iv( this.addr, units );56775678 copyArray( cache, units );56795680 }56815682 for ( let i = 0; i !== n; ++ i ) {56835684 textures.setTexture2DArray( v[ i ] || emptyArrayTexture, units[ i ] );56855686 }56875688}56895690569156925693function getPureArraySetter( type ) {56945695 switch ( type ) {56965697 case 0x1406: return setValueV1fArray; 5698 case 0x8b50: return setValueV2fArray; 5699 case 0x8b51: return setValueV3fArray; 5700 case 0x8b52: return setValueV4fArray; 57015702 case 0x8b5a: return setValueM2Array; 5703 case 0x8b5b: return setValueM3Array; 5704 case 0x8b5c: return setValueM4Array; 57055706 case 0x1404: case 0x8b56: return setValueV1iArray; 5707 case 0x8b53: case 0x8b57: return setValueV2iArray; 5708 case 0x8b54: case 0x8b58: return setValueV3iArray; 5709 case 0x8b55: case 0x8b59: return setValueV4iArray; 57105711 case 0x1405: return setValueV1uiArray; 5712 case 0x8dc6: return setValueV2uiArray; 5713 case 0x8dc7: return setValueV3uiArray; 5714 case 0x8dc8: return setValueV4uiArray; 57155716 case 0x8b5e: 5717 case 0x8d66: 5718 case 0x8dca: 5719 case 0x8dd2: 5720 case 0x8b62: 5721 return setValueT1Array;57225723 case 0x8b5f: 5724 case 0x8dcb: 5725 case 0x8dd3: 5726 return setValueT3DArray;57275728 case 0x8b60: 5729 case 0x8dcc: 5730 case 0x8dd4: 5731 case 0x8dc5: 5732 return setValueT6Array;57335734 case 0x8dc1: 5735 case 0x8dcf: 5736 case 0x8dd7: 5737 case 0x8dc4: 5738 return setValueT2DArrayArray;57395740 }57415742}5743574457455746class SingleUniform {57475748 constructor( id, activeInfo, addr ) {57495750 this.id = id;5751 this.addr = addr;5752 this.cache = [];5753 this.type = activeInfo.type;5754 this.setValue = getSingularSetter( activeInfo.type );57555756 57575758 }57595760}57615762class PureArrayUniform {57635764 constructor( id, activeInfo, addr ) {57655766 this.id = id;5767 this.addr = addr;5768 this.cache = [];5769 this.type = activeInfo.type;5770 this.size = activeInfo.size;5771 this.setValue = getPureArraySetter( activeInfo.type );57725773 57745775 }57765777}57785779class StructuredUniform {57805781 constructor( id ) {57825783 this.id = id;57845785 this.seq = [];5786 this.map = {};57875788 }57895790 setValue( gl, value, textures ) {57915792 const seq = this.seq;57935794 for ( let i = 0, n = seq.length; i !== n; ++ i ) {57955796 const u = seq[ i ];5797 u.setValue( gl, value[ u.id ], textures );57985799 }58005801 }58025803}580458055806580758085809const RePathPart = /(\w+)(\])?(\[|\.)?/g;58105811581258135814581558165817581858195820function addUniform( container, uniformObject ) {58215822 container.seq.push( uniformObject );5823 container.map[ uniformObject.id ] = uniformObject;58245825}58265827function parseUniform( activeInfo, addr, container ) {58285829 const path = activeInfo.name,5830 pathLength = path.length;58315832 5833 RePathPart.lastIndex = 0;58345835 while ( true ) {58365837 const match = RePathPart.exec( path ),5838 matchEnd = RePathPart.lastIndex;58395840 let id = match[ 1 ];5841 const idIsIndex = match[ 2 ] === ']',5842 subscript = match[ 3 ];58435844 if ( idIsIndex ) id = id | 0; 58455846 if ( subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength ) {58475848 58495850 addUniform( container, subscript === undefined ?5851 new SingleUniform( id, activeInfo, addr ) :5852 new PureArrayUniform( id, activeInfo, addr ) );58535854 break;58555856 } else {58575858 58595860 const map = container.map;5861 let next = map[ id ];58625863 if ( next === undefined ) {58645865 next = new StructuredUniform( id );5866 addUniform( container, next );58675868 }58695870 container = next;58715872 }58735874 }58755876}5877587858795880class WebGLUniforms {58815882 constructor( gl, program ) {58835884 this.seq = [];5885 this.map = {};58865887 const n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS );58885889 for ( let i = 0; i < n; ++ i ) {58905891 const info = gl.getActiveUniform( program, i ),5892 addr = gl.getUniformLocation( program, info.name );58935894 parseUniform( info, addr, this );58955896 }58975898 58995900 const shadowSamplers = [];5901 const otherUniforms = [];59025903 for ( const u of this.seq ) {59045905 if ( u.type === gl.SAMPLER_2D_SHADOW || u.type === gl.SAMPLER_CUBE_SHADOW || u.type === gl.SAMPLER_2D_ARRAY_SHADOW ) {59065907 shadowSamplers.push( u );59085909 } else {59105911 otherUniforms.push( u );59125913 }59145915 }59165917 if ( shadowSamplers.length > 0 ) {59185919 this.seq = shadowSamplers.concat( otherUniforms );59205921 }59225923 }59245925 setValue( gl, name, value, textures ) {59265927 const u = this.map[ name ];59285929 if ( u !== undefined ) u.setValue( gl, value, textures );59305931 }59325933 setOptional( gl, object, name ) {59345935 const v = object[ name ];59365937 if ( v !== undefined ) this.setValue( gl, name, v );59385939 }59405941 static upload( gl, seq, values, textures ) {59425943 for ( let i = 0, n = seq.length; i !== n; ++ i ) {59445945 const u = seq[ i ],5946 v = values[ u.id ];59475948 if ( v.needsUpdate !== false ) {59495950 5951 u.setValue( gl, v.value, textures );59525953 }59545955 }59565957 }59585959 static seqWithValue( seq, values ) {59605961 const r = [];59625963 for ( let i = 0, n = seq.length; i !== n; ++ i ) {59645965 const u = seq[ i ];5966 if ( u.id in values ) r.push( u );59675968 }59695970 return r;59715972 }59735974}59755976function WebGLShader( gl, type, string ) {59775978 const shader = gl.createShader( type );59795980 gl.shaderSource( shader, string );5981 gl.compileShader( shader );59825983 return shader;59845985}598659875988const COMPLETION_STATUS_KHR = 0x91B1;59895990let programIdCount = 0;59915992function handleSource( string, errorLine ) {59935994 const lines = string.split( '\n' );5995 const lines2 = [];59965997 const from = Math.max( errorLine - 6, 0 );5998 const to = Math.min( errorLine + 6, lines.length );59996000 for ( let i = from; i < to; i ++ ) {60016002 const line = i + 1;6003 lines2.push( `${line === errorLine ? '>' : ' '} ${line}: ${lines[ i ]}` );60046005 }60066007 return lines2.join( '\n' );60086009}60106011const _m0 = new Matrix3();60126013function getEncodingComponents( colorSpace ) {60146015 ColorManagement._getMatrix( _m0, ColorManagement.workingColorSpace, colorSpace );60166017 const encodingMatrix = `mat3( ${ _m0.elements.map( ( v ) => v.toFixed( 4 ) ) } )`;60186019 switch ( ColorManagement.getTransfer( colorSpace ) ) {60206021 case LinearTransfer:6022 return [ encodingMatrix, 'LinearTransferOETF' ];60236024 case SRGBTransfer:6025 return [ encodingMatrix, 'sRGBTransferOETF' ];60266027 default:6028 warn( 'WebGLProgram: Unsupported color space: ', colorSpace );6029 return [ encodingMatrix, 'LinearTransferOETF' ];60306031 }60326033}60346035function getShaderErrors( gl, shader, type ) {60366037 const status = gl.getShaderParameter( shader, gl.COMPILE_STATUS );60386039 const shaderInfoLog = gl.getShaderInfoLog( shader ) || '';6040 const errors = shaderInfoLog.trim();60416042 if ( status && errors === '' ) return '';60436044 const errorMatches = /ERROR: 0:(\d+)/.exec( errors );6045 if ( errorMatches ) {60466047 6048 60496050 const errorLine = parseInt( errorMatches[ 1 ] );6051 return type.toUpperCase() + '\n\n' + errors + '\n\n' + handleSource( gl.getShaderSource( shader ), errorLine );60526053 } else {60546055 return errors;60566057 }60586059}60606061function getTexelEncodingFunction( functionName, colorSpace ) {60626063 const components = getEncodingComponents( colorSpace );60646065 return [60666067 `vec4 ${functionName}( vec4 value ) {`,60686069 ` return ${components[ 1 ]}( vec4( ${components[ 0 ]} * value.rgb, value.a ) );`,60706071 '}',60726073 ].join( '\n' );60746075}60766077const toneMappingFunctions = {6078 [ LinearToneMapping ]: 'Linear',6079 [ ReinhardToneMapping ]: 'Reinhard',6080 [ CineonToneMapping ]: 'Cineon',6081 [ ACESFilmicToneMapping ]: 'ACESFilmic',6082 [ AgXToneMapping ]: 'AgX',6083 [ NeutralToneMapping ]: 'Neutral',6084 [ CustomToneMapping ]: 'Custom'6085};60866087function getToneMappingFunction( functionName, toneMapping ) {60886089 const toneMappingName = toneMappingFunctions[ toneMapping ];60906091 if ( toneMappingName === undefined ) {60926093 warn( 'WebGLProgram: Unsupported toneMapping:', toneMapping );6094 return 'vec3 ' + functionName + '( vec3 color ) { return LinearToneMapping( color ); }';60956096 }60976098 return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';60996100}61016102const _v0 = new Vector3();61036104function getLuminanceFunction() {61056106 ColorManagement.getLuminanceCoefficients( _v0 );61076108 const r = _v0.x.toFixed( 4 );6109 const g = _v0.y.toFixed( 4 );6110 const b = _v0.z.toFixed( 4 );61116112 return [61136114 'float luminance( const in vec3 rgb ) {',61156116 ` const vec3 weights = vec3( ${ r }, ${ g }, ${ b } );`,61176118 ' return dot( weights, rgb );',61196120 '}'61216122 ].join( '\n' );61236124}61256126function generateVertexExtensions( parameters ) {61276128 const chunks = [6129 parameters.extensionClipCullDistance ? '#extension GL_ANGLE_clip_cull_distance : require' : '',6130 parameters.extensionMultiDraw ? '#extension GL_ANGLE_multi_draw : require' : '',6131 ];61326133 return chunks.filter( filterEmptyLine ).join( '\n' );61346135}61366137function generateDefines( defines ) {61386139 const chunks = [];61406141 for ( const name in defines ) {61426143 const value = defines[ name ];61446145 if ( value === false ) continue;61466147 chunks.push( '#define ' + name + ' ' + value );61486149 }61506151 return chunks.join( '\n' );61526153}61546155function fetchAttributeLocations( gl, program ) {61566157 const attributes = {};61586159 const n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES );61606161 for ( let i = 0; i < n; i ++ ) {61626163 const info = gl.getActiveAttrib( program, i );6164 const name = info.name;61656166 let locationSize = 1;6167 if ( info.type === gl.FLOAT_MAT2 ) locationSize = 2;6168 if ( info.type === gl.FLOAT_MAT3 ) locationSize = 3;6169 if ( info.type === gl.FLOAT_MAT4 ) locationSize = 4;61706171 61726173 attributes[ name ] = {6174 type: info.type,6175 location: gl.getAttribLocation( program, name ),6176 locationSize: locationSize6177 };61786179 }61806181 return attributes;61826183}61846185function filterEmptyLine( string ) {61866187 return string !== '';61886189}61906191function replaceLightNums( string, parameters ) {61926193 const numSpotLightCoords = parameters.numSpotLightShadows + parameters.numSpotLightMaps - parameters.numSpotLightShadowsWithMaps;61946195 return string6196 .replace( /NUM_SUN_LIGHTS/g, parameters.numSunLights )6197 .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )6198 .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )6199 .replace( /NUM_SPOT_LIGHT_MAPS/g, parameters.numSpotLightMaps )6200 .replace( /NUM_SPOT_LIGHT_COORDS/g, numSpotLightCoords )6201 .replace( /NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights )6202 .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )6203 .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights )6204 .replace( /NUM_SUN_LIGHT_SHADOWS/g, parameters.numSunLightShadows )6205 .replace( /NUM_DIR_LIGHT_SHADOWS/g, parameters.numDirLightShadows )6206 .replace( /NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS/g, parameters.numSpotLightShadowsWithMaps )6207 .replace( /NUM_SPOT_LIGHT_SHADOWS/g, parameters.numSpotLightShadows )6208 .replace( /NUM_POINT_LIGHT_SHADOWS/g, parameters.numPointLightShadows )6209 .replace( /NUM_LIGHT_PROBE_GRIDS/g, parameters.numLightProbeGrids );62106211}62126213function replaceClippingPlaneNums( string, parameters ) {62146215 return string6216 .replace( /NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes )6217 .replace( /UNION_CLIPPING_PLANES/g, ( parameters.numClippingPlanes - parameters.numClipIntersection ) );62186219}6220622162226223const includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm;62246225function resolveIncludes( string ) {62266227 return string.replace( includePattern, includeReplacer );62286229}62306231function includeReplacer( match, include ) {62326233 const string = ShaderChunk[ include ];62346235 if ( string === undefined ) {62366237 throw new Error( 'THREE.WebGLProgram: Can not resolve #include <' + include + '>' );62386239 }62406241 return resolveIncludes( string );62426243}6244624562466247const unrollLoopPattern = /#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;62486249function unrollLoops( string ) {62506251 return string.replace( unrollLoopPattern, loopReplacer );62526253}62546255function loopReplacer( match, start, end, snippet ) {62566257 let string = '';62586259 for ( let i = parseInt( start ); i < parseInt( end ); i ++ ) {62606261 string += snippet6262 .replace( /\[\s*i\s*\]/g, '[ ' + i + ' ]' )6263 .replace( /UNROLLED_LOOP_INDEX/g, i );62646265 }62666267 return string;62686269}6270627162726273function generatePrecision( parameters ) {62746275 let precisionstring = `precision ${parameters.precision} float;6276 precision ${parameters.precision} int;6277 precision ${parameters.precision} sampler2D;6278 precision ${parameters.precision} samplerCube;6279 precision ${parameters.precision} sampler3D;6280 precision ${parameters.precision} sampler2DArray;6281 precision ${parameters.precision} sampler2DShadow;6282 precision ${parameters.precision} samplerCubeShadow;6283 precision ${parameters.precision} sampler2DArrayShadow;6284 precision ${parameters.precision} isampler2D;6285 precision ${parameters.precision} isampler3D;6286 precision ${parameters.precision} isamplerCube;6287 precision ${parameters.precision} isampler2DArray;6288 precision ${parameters.precision} usampler2D;6289 precision ${parameters.precision} usampler3D;6290 precision ${parameters.precision} usamplerCube;6291 precision ${parameters.precision} usampler2DArray;6292 `;62936294 if ( parameters.precision === 'highp' ) {62956296 precisionstring += '\n#define HIGH_PRECISION';62976298 } else if ( parameters.precision === 'mediump' ) {62996300 precisionstring += '\n#define MEDIUM_PRECISION';63016302 } else if ( parameters.precision === 'lowp' ) {63036304 precisionstring += '\n#define LOW_PRECISION';63056306 }63076308 return precisionstring;63096310}63116312const shadowMapTypeDefines = {6313 [ PCFShadowMap ]: 'SHADOWMAP_TYPE_PCF',6314 [ VSMShadowMap ]: 'SHADOWMAP_TYPE_VSM'6315};63166317function generateShadowMapTypeDefine( parameters ) {63186319 return shadowMapTypeDefines[ parameters.shadowMapType ] || 'SHADOWMAP_TYPE_BASIC';63206321}63226323const envMapModeDefines = {6324 [ CubeRefractionMapping ]: 'ENVMAP_MODE_REFRACTION'6325};63266327function generateEnvMapModeDefine( parameters ) {63286329 if ( parameters.envMap === false ) return 'ENVMAP_MODE_REFLECTION';63306331 return envMapModeDefines[ parameters.envMapMode ] || 'ENVMAP_MODE_REFLECTION';63326333}63346335const envMapBlendingDefines = {6336 [ MultiplyOperation ]: 'ENVMAP_BLENDING_MULTIPLY',6337 [ MixOperation ]: 'ENVMAP_BLENDING_MIX',6338 [ AddOperation ]: 'ENVMAP_BLENDING_ADD'6339};63406341function generateEnvMapBlendingDefine( parameters ) {63426343 if ( parameters.envMap === false ) return 'ENVMAP_BLENDING_NONE';63446345 return envMapBlendingDefines[ parameters.combine ] || 'ENVMAP_BLENDING_NONE';63466347}63486349function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {63506351 6352 63536354 const gl = renderer.getContext();63556356 const defines = parameters.defines;63576358 let vertexShader = parameters.vertexShader;6359 let fragmentShader = parameters.fragmentShader;63606361 const shadowMapTypeDefine = generateShadowMapTypeDefine( parameters );6362 const envMapTypeDefine = parameters.envMapPMREM === true ? 'ENVMAP_TYPE_PMREM' : 'ENVMAP_TYPE_CUBE';6363 const envMapModeDefine = generateEnvMapModeDefine( parameters );6364 const envMapBlendingDefine = generateEnvMapBlendingDefine( parameters );63656366 const customVertexExtensions = generateVertexExtensions( parameters );63676368 const customDefines = generateDefines( defines );63696370 const program = gl.createProgram();63716372 let prefixVertex, prefixFragment;6373 let versionString = parameters.glslVersion ? '#version ' + parameters.glslVersion + '\n' : '';63746375 if ( parameters.isRawShaderMaterial ) {63766377 prefixVertex = [63786379 '#define SHADER_TYPE ' + parameters.shaderType,6380 '#define SHADER_NAME ' + parameters.shaderName,63816382 customDefines63836384 ].filter( filterEmptyLine ).join( '\n' );63856386 if ( prefixVertex.length > 0 ) {63876388 prefixVertex += '\n';63896390 }63916392 prefixFragment = [63936394 '#define SHADER_TYPE ' + parameters.shaderType,6395 '#define SHADER_NAME ' + parameters.shaderName,63966397 customDefines63986399 ].filter( filterEmptyLine ).join( '\n' );64006401 if ( prefixFragment.length > 0 ) {64026403 prefixFragment += '\n';64046405 }64066407 } else {64086409 prefixVertex = [64106411 generatePrecision( parameters ),64126413 '#define SHADER_TYPE ' + parameters.shaderType,6414 '#define SHADER_NAME ' + parameters.shaderName,64156416 customDefines,64176418 parameters.extensionClipCullDistance ? '#define USE_CLIP_DISTANCE' : '',6419 parameters.batching ? '#define USE_BATCHING' : '',6420 parameters.batchingColor ? '#define USE_BATCHING_COLOR' : '',6421 parameters.instancing ? '#define USE_INSTANCING' : '',6422 parameters.instancingColor ? '#define USE_INSTANCING_COLOR' : '',6423 parameters.instancingMorph ? '#define USE_INSTANCING_MORPH' : '',64246425 parameters.useFog && parameters.fog ? '#define USE_FOG' : '',6426 parameters.useFog && parameters.fogExp2 ? '#define FOG_EXP2' : '',64276428 parameters.map ? '#define USE_MAP' : '',6429 parameters.envMap ? '#define USE_ENVMAP' : '',6430 parameters.envMap ? '#define ' + envMapModeDefine : '',6431 parameters.lightMap ? '#define USE_LIGHTMAP' : '',6432 parameters.aoMap ? '#define USE_AOMAP' : '',6433 parameters.bumpMap ? '#define USE_BUMPMAP' : '',6434 parameters.normalMap ? '#define USE_NORMALMAP' : '',6435 parameters.normalMapObjectSpace ? '#define USE_NORMALMAP_OBJECTSPACE' : '',6436 parameters.normalMapTangentSpace ? '#define USE_NORMALMAP_TANGENTSPACE' : '',6437 parameters.displacementMap ? '#define USE_DISPLACEMENTMAP' : '',6438 parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',64396440 parameters.anisotropy ? '#define USE_ANISOTROPY' : '',6441 parameters.anisotropyMap ? '#define USE_ANISOTROPYMAP' : '',64426443 parameters.clearcoatMap ? '#define USE_CLEARCOATMAP' : '',6444 parameters.clearcoatRoughnessMap ? '#define USE_CLEARCOAT_ROUGHNESSMAP' : '',6445 parameters.clearcoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '',6446 parameters.diffuseRoughnessMap ? '#define USE_DIFFUSE_ROUGHNESSMAP' : '',64476448 parameters.iridescenceMap ? '#define USE_IRIDESCENCEMAP' : '',6449 parameters.iridescenceThicknessMap ? '#define USE_IRIDESCENCE_THICKNESSMAP' : '',64506451 parameters.specularMap ? '#define USE_SPECULARMAP' : '',6452 parameters.specularColorMap ? '#define USE_SPECULAR_COLORMAP' : '',6453 parameters.specularIntensityMap ? '#define USE_SPECULAR_INTENSITYMAP' : '',64546455 parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',6456 parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',6457 parameters.alphaMap ? '#define USE_ALPHAMAP' : '',6458 parameters.alphaHash ? '#define USE_ALPHAHASH' : '',64596460 parameters.transmission ? '#define USE_TRANSMISSION' : '',6461 parameters.transmissionMap ? '#define USE_TRANSMISSIONMAP' : '',6462 parameters.thicknessMap ? '#define USE_THICKNESSMAP' : '',64636464 parameters.sheenColorMap ? '#define USE_SHEEN_COLORMAP' : '',6465 parameters.sheenRoughnessMap ? '#define USE_SHEEN_ROUGHNESSMAP' : '',64666467 64686469 parameters.mapUv ? '#define MAP_UV ' + parameters.mapUv : '',6470 parameters.alphaMapUv ? '#define ALPHAMAP_UV ' + parameters.alphaMapUv : '',6471 parameters.lightMapUv ? '#define LIGHTMAP_UV ' + parameters.lightMapUv : '',6472 parameters.aoMapUv ? '#define AOMAP_UV ' + parameters.aoMapUv : '',6473 parameters.emissiveMapUv ? '#define EMISSIVEMAP_UV ' + parameters.emissiveMapUv : '',6474 parameters.bumpMapUv ? '#define BUMPMAP_UV ' + parameters.bumpMapUv : '',6475 parameters.normalMapUv ? '#define NORMALMAP_UV ' + parameters.normalMapUv : '',6476 parameters.displacementMapUv ? '#define DISPLACEMENTMAP_UV ' + parameters.displacementMapUv : '',64776478 parameters.metalnessMapUv ? '#define METALNESSMAP_UV ' + parameters.metalnessMapUv : '',6479 parameters.roughnessMapUv ? '#define ROUGHNESSMAP_UV ' + parameters.roughnessMapUv : '',64806481 parameters.anisotropyMapUv ? '#define ANISOTROPYMAP_UV ' + parameters.anisotropyMapUv : '',64826483 parameters.clearcoatMapUv ? '#define CLEARCOATMAP_UV ' + parameters.clearcoatMapUv : '',6484 parameters.clearcoatNormalMapUv ? '#define CLEARCOAT_NORMALMAP_UV ' + parameters.clearcoatNormalMapUv : '',6485 parameters.clearcoatRoughnessMapUv ? '#define CLEARCOAT_ROUGHNESSMAP_UV ' + parameters.clearcoatRoughnessMapUv : '',6486 parameters.diffuseRoughnessMapUv ? '#define DIFFUSE_ROUGHNESSMAP_UV ' + parameters.diffuseRoughnessMapUv : '',64876488 parameters.iridescenceMapUv ? '#define IRIDESCENCEMAP_UV ' + parameters.iridescenceMapUv : '',6489 parameters.iridescenceThicknessMapUv ? '#define IRIDESCENCE_THICKNESSMAP_UV ' + parameters.iridescenceThicknessMapUv : '',64906491 parameters.sheenColorMapUv ? '#define SHEEN_COLORMAP_UV ' + parameters.sheenColorMapUv : '',6492 parameters.sheenRoughnessMapUv ? '#define SHEEN_ROUGHNESSMAP_UV ' + parameters.sheenRoughnessMapUv : '',64936494 parameters.specularMapUv ? '#define SPECULARMAP_UV ' + parameters.specularMapUv : '',6495 parameters.specularColorMapUv ? '#define SPECULAR_COLORMAP_UV ' + parameters.specularColorMapUv : '',6496 parameters.specularIntensityMapUv ? '#define SPECULAR_INTENSITYMAP_UV ' + parameters.specularIntensityMapUv : '',64976498 parameters.transmissionMapUv ? '#define TRANSMISSIONMAP_UV ' + parameters.transmissionMapUv : '',6499 parameters.thicknessMapUv ? '#define THICKNESSMAP_UV ' + parameters.thicknessMapUv : '',65006501 65026503 parameters.vertexTangents && parameters.flatShading === false ? '#define USE_TANGENT' : '',6504 parameters.vertexNormals ? '#define HAS_NORMAL' : '',6505 parameters.vertexColors ? '#define USE_COLOR' : '',6506 parameters.vertexAlphas ? '#define USE_COLOR_ALPHA' : '',6507 parameters.vertexUv1s ? '#define USE_UV1' : '',6508 parameters.vertexUv2s ? '#define USE_UV2' : '',6509 parameters.vertexUv3s ? '#define USE_UV3' : '',65106511 parameters.pointsUvs ? '#define USE_POINTS_UV' : '',65126513 parameters.flatShading ? '#define FLAT_SHADED' : '',65146515 parameters.skinning ? '#define USE_SKINNING' : '',65166517 parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',6518 parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',6519 ( parameters.morphColors ) ? '#define USE_MORPHCOLORS' : '',6520 ( parameters.morphTargetsCount > 0 ) ? '#define MORPHTARGETS_TEXTURE_STRIDE ' + parameters.morphTextureStride : '',6521 ( parameters.morphTargetsCount > 0 ) ? '#define MORPHTARGETS_COUNT ' + parameters.morphTargetsCount : '',6522 parameters.doubleSided ? '#define DOUBLE_SIDED' : '',6523 parameters.flipSided ? '#define FLIP_SIDED' : '',65246525 parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',6526 parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',65276528 parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',65296530 parameters.numLightProbes > 0 ? '#define USE_LIGHT_PROBES' : '',65316532 parameters.logarithmicDepthBuffer ? '#define USE_LOGARITHMIC_DEPTH_BUFFER' : '',6533 parameters.reversedDepthBuffer ? '#define USE_REVERSED_DEPTH_BUFFER' : '',65346535 'uniform mat4 modelMatrix;',6536 'uniform mat4 modelViewMatrix;',6537 'uniform mat4 projectionMatrix;',6538 'uniform mat4 viewMatrix;',6539 'uniform mat3 normalMatrix;',6540 'uniform vec3 cameraPosition;',6541 'uniform bool isOrthographic;',65426543 '#ifdef USE_INSTANCING',65446545 ' attribute mat4 instanceMatrix;',65466547 '#endif',65486549 '#ifdef USE_INSTANCING_COLOR',65506551 ' attribute vec3 instanceColor;',65526553 '#endif',65546555 '#ifdef USE_INSTANCING_MORPH',65566557 ' uniform sampler2D morphTexture;',65586559 '#endif',65606561 'attribute vec3 position;',6562 'attribute vec3 normal;',6563 'attribute vec2 uv;',65646565 '#ifdef USE_UV1',65666567 ' attribute vec2 uv1;',65686569 '#endif',65706571 '#ifdef USE_UV2',65726573 ' attribute vec2 uv2;',65746575 '#endif',65766577 '#ifdef USE_UV3',65786579 ' attribute vec2 uv3;',65806581 '#endif',65826583 '#ifdef USE_TANGENT',65846585 ' attribute vec4 tangent;',65866587 '#endif',65886589 '#if defined( USE_COLOR_ALPHA )',65906591 ' attribute vec4 color;',65926593 '#elif defined( USE_COLOR )',65946595 ' attribute vec3 color;',65966597 '#endif',65986599 '#ifdef USE_SKINNING',66006601 ' attribute vec4 skinIndex;',6602 ' attribute vec4 skinWeight;',66036604 '#endif',66056606 '\n'66076608 ].filter( filterEmptyLine ).join( '\n' );66096610 prefixFragment = [66116612 generatePrecision( parameters ),66136614 '#define SHADER_TYPE ' + parameters.shaderType,6615 '#define SHADER_NAME ' + parameters.shaderName,66166617 customDefines,66186619 parameters.useFog && parameters.fog ? '#define USE_FOG' : '',6620 parameters.useFog && parameters.fogExp2 ? '#define FOG_EXP2' : '',66216622 parameters.alphaToCoverage ? '#define ALPHA_TO_COVERAGE' : '',6623 parameters.map ? '#define USE_MAP' : '',6624 parameters.matcap ? '#define USE_MATCAP' : '',6625 parameters.envMap ? '#define USE_ENVMAP' : '',6626 parameters.envMap ? '#define ' + envMapTypeDefine : '',6627 parameters.envMap ? '#define ' + envMapModeDefine : '',6628 parameters.envMap ? '#define ' + envMapBlendingDefine : '',6629 parameters.envMapPMREM ? '#define ENVMAP_MAX_LOD ' + parameters.envMapMaxLod + '.0' : '',6630 parameters.envMapPMREM ? '#define ENVMAP_SIZE ' + parameters.envMapSize + '.0' : '',6631 parameters.lightMap ? '#define USE_LIGHTMAP' : '',6632 parameters.aoMap ? '#define USE_AOMAP' : '',6633 parameters.bumpMap ? '#define USE_BUMPMAP' : '',6634 parameters.normalMap ? '#define USE_NORMALMAP' : '',6635 parameters.normalMapObjectSpace ? '#define USE_NORMALMAP_OBJECTSPACE' : '',6636 parameters.normalMapTangentSpace ? '#define USE_NORMALMAP_TANGENTSPACE' : '',6637 parameters.packedNormalMap ? '#define USE_PACKED_NORMALMAP' : '',6638 parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',66396640 parameters.anisotropy ? '#define USE_ANISOTROPY' : '',6641 parameters.anisotropyMap ? '#define USE_ANISOTROPYMAP' : '',66426643 parameters.clearcoat ? '#define USE_CLEARCOAT' : '',6644 parameters.clearcoatMap ? '#define USE_CLEARCOATMAP' : '',6645 parameters.clearcoatRoughnessMap ? '#define USE_CLEARCOAT_ROUGHNESSMAP' : '',6646 parameters.clearcoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '',66476648 parameters.diffuseRoughness ? '#define USE_DIFFUSE_ROUGHNESS' : '',6649 parameters.diffuseRoughnessMap ? '#define USE_DIFFUSE_ROUGHNESSMAP' : '',6650 parameters.dispersion ? '#define USE_DISPERSION' : '',6651 parameters.retroreflection ? '#define USE_RETROREFLECTION' : '',66526653 parameters.iridescence ? '#define USE_IRIDESCENCE' : '',6654 parameters.iridescenceMap ? '#define USE_IRIDESCENCEMAP' : '',6655 parameters.iridescenceThicknessMap ? '#define USE_IRIDESCENCE_THICKNESSMAP' : '',66566657 parameters.specularMap ? '#define USE_SPECULARMAP' : '',6658 parameters.specularColorMap ? '#define USE_SPECULAR_COLORMAP' : '',6659 parameters.specularIntensityMap ? '#define USE_SPECULAR_INTENSITYMAP' : '',66606661 parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',6662 parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',66636664 parameters.alphaMap ? '#define USE_ALPHAMAP' : '',6665 parameters.alphaTest ? '#define USE_ALPHATEST' : '',6666 parameters.alphaHash ? '#define USE_ALPHAHASH' : '',66676668 parameters.sheen ? '#define USE_SHEEN' : '',6669 parameters.sheenColorMap ? '#define USE_SHEEN_COLORMAP' : '',6670 parameters.sheenRoughnessMap ? '#define USE_SHEEN_ROUGHNESSMAP' : '',66716672 parameters.transmission ? '#define USE_TRANSMISSION' : '',6673 parameters.transmissionMap ? '#define USE_TRANSMISSIONMAP' : '',6674 parameters.thicknessMap ? '#define USE_THICKNESSMAP' : '',66756676 parameters.vertexTangents && parameters.flatShading === false ? '#define USE_TANGENT' : '',6677 parameters.vertexColors || parameters.instancingColor ? '#define USE_COLOR' : '',6678 parameters.vertexAlphas || parameters.batchingColor ? '#define USE_COLOR_ALPHA' : '',6679 parameters.vertexUv1s ? '#define USE_UV1' : '',6680 parameters.vertexUv2s ? '#define USE_UV2' : '',6681 parameters.vertexUv3s ? '#define USE_UV3' : '',66826683 parameters.pointsUvs ? '#define USE_POINTS_UV' : '',66846685 parameters.gradientMap ? '#define USE_GRADIENTMAP' : '',66866687 parameters.flatShading ? '#define FLAT_SHADED' : '',66886689 parameters.doubleSided ? '#define DOUBLE_SIDED' : '',6690 parameters.flipSided ? '#define FLIP_SIDED' : '',66916692 parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',6693 parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',66946695 parameters.premultipliedAlpha ? '#define PREMULTIPLIED_ALPHA' : '',66966697 parameters.numLightProbes > 0 ? '#define USE_LIGHT_PROBES' : '',669866996700 parameters.decodeVideoTexture ? '#define DECODE_VIDEO_TEXTURE' : '',6701 parameters.decodeVideoTextureEmissive ? '#define DECODE_VIDEO_TEXTURE_EMISSIVE' : '',67026703 parameters.logarithmicDepthBuffer ? '#define USE_LOGARITHMIC_DEPTH_BUFFER' : '',6704 parameters.reversedDepthBuffer ? '#define USE_REVERSED_DEPTH_BUFFER' : '',67056706 'uniform mat4 viewMatrix;',6707 'uniform vec3 cameraPosition;',6708 'uniform bool isOrthographic;',67096710 ( parameters.toneMapping !== NoToneMapping ) ? '#define TONE_MAPPING' : '',6711 ( parameters.toneMapping !== NoToneMapping ) ? ShaderChunk[ 'tonemapping_pars_fragment' ] : '', 6712 ( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( 'toneMapping', parameters.toneMapping ) : '',67136714 parameters.dithering ? '#define DITHERING' : '',6715 parameters.opaque ? '#define OPAQUE' : '',67166717 ShaderChunk[ 'colorspace_pars_fragment' ], 6718 getTexelEncodingFunction( 'linearToOutputTexel', parameters.outputColorSpace ),6719 getLuminanceFunction(),67206721 parameters.useDepthPacking ? '#define DEPTH_PACKING ' + parameters.depthPacking : '',67226723 '\n'67246725 ].filter( filterEmptyLine ).join( '\n' );67266727 }67286729 vertexShader = resolveIncludes( vertexShader );6730 vertexShader = replaceLightNums( vertexShader, parameters );6731 vertexShader = replaceClippingPlaneNums( vertexShader, parameters );67326733 fragmentShader = resolveIncludes( fragmentShader );6734 fragmentShader = replaceLightNums( fragmentShader, parameters );6735 fragmentShader = replaceClippingPlaneNums( fragmentShader, parameters );67366737 vertexShader = unrollLoops( vertexShader );6738 fragmentShader = unrollLoops( fragmentShader );67396740 if ( parameters.isRawShaderMaterial !== true ) {67416742 67436744 versionString = '#version 300 es\n';67456746 prefixVertex = [6747 customVertexExtensions,6748 '#define attribute in',6749 '#define varying out',6750 '#define texture2D texture'6751 ].join( '\n' ) + '\n' + prefixVertex;67526753 prefixFragment = [6754 '#define varying in',6755 ( parameters.glslVersion === GLSL3 ) ? '' : 'layout(location = 0) out highp vec4 pc_fragColor;',6756 ( parameters.glslVersion === GLSL3 ) ? '' : '#define gl_FragColor pc_fragColor',6757 '#define gl_FragDepthEXT gl_FragDepth',6758 '#define texture2D texture',6759 '#define textureCube texture',6760 '#define texture2DProj textureProj',6761 '#define texture2DLodEXT textureLod',6762 '#define texture2DProjLodEXT textureProjLod',6763 '#define textureCubeLodEXT textureLod',6764 '#define texture2DGradEXT textureGrad',6765 '#define texture2DProjGradEXT textureProjGrad',6766 '#define textureCubeGradEXT textureGrad'6767 ].join( '\n' ) + '\n' + prefixFragment;67686769 }67706771 const vertexGlsl = versionString + prefixVertex + vertexShader;6772 const fragmentGlsl = versionString + prefixFragment + fragmentShader;67736774 6775 67766777 const glVertexShader = WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl );6778 const glFragmentShader = WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl );67796780 gl.attachShader( program, glVertexShader );6781 gl.attachShader( program, glFragmentShader );67826783 67846785 if ( parameters.index0AttributeName !== undefined ) {67866787 gl.bindAttribLocation( program, 0, parameters.index0AttributeName );67886789 } else if ( parameters.hasPositionAttribute === true ) {67906791 67926793 gl.bindAttribLocation( program, 0, 'position' );67946795 }67966797 gl.linkProgram( program );67986799 function onFirstUse( self ) {68006801 6802 if ( renderer.debug.checkShaderErrors ) {68036804 const programInfoLog = gl.getProgramInfoLog( program ) || '';6805 const vertexShaderInfoLog = gl.getShaderInfoLog( glVertexShader ) || '';6806 const fragmentShaderInfoLog = gl.getShaderInfoLog( glFragmentShader ) || '';68076808 const programLog = programInfoLog.trim();6809 const vertexLog = vertexShaderInfoLog.trim();6810 const fragmentLog = fragmentShaderInfoLog.trim();68116812 let runnable = true;6813 let haveDiagnostics = true;68146815 if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {68166817 runnable = false;68186819 if ( typeof renderer.debug.onShaderError === 'function' ) {68206821 renderer.debug.onShaderError( gl, program, glVertexShader, glFragmentShader );68226823 } else {68246825 68266827 const vertexErrors = getShaderErrors( gl, glVertexShader, 'vertex' );6828 const fragmentErrors = getShaderErrors( gl, glFragmentShader, 'fragment' );68296830 error(6831 'WebGLProgram: Shader Error ' + gl.getError() + ' - ' +6832 'VALIDATE_STATUS ' + gl.getProgramParameter( program, gl.VALIDATE_STATUS ) + '\n\n' +6833 'Material Name: ' + self.name + '\n' +6834 'Material Type: ' + self.type + '\n\n' +6835 'Program Info Log: ' + programLog + '\n' +6836 vertexErrors + '\n' +6837 fragmentErrors6838 );68396840 }68416842 } else if ( programLog !== '' ) {68436844 warn( 'WebGLProgram: Program Info Log:', programLog );68456846 } else if ( vertexLog === '' || fragmentLog === '' ) {68476848 haveDiagnostics = false;68496850 }68516852 if ( haveDiagnostics ) {68536854 self.diagnostics = {68556856 runnable: runnable,68576858 programLog: programLog,68596860 vertexShader: {68616862 log: vertexLog,6863 prefix: prefixVertex68646865 },68666867 fragmentShader: {68686869 log: fragmentLog,6870 prefix: prefixFragment68716872 }68736874 };68756876 }68776878 }68796880 68816882 6883 6884 68856886 gl.deleteShader( glVertexShader );6887 gl.deleteShader( glFragmentShader );68886889 cachedUniforms = new WebGLUniforms( gl, program );6890 cachedAttributes = fetchAttributeLocations( gl, program );68916892 }68936894 68956896 let cachedUniforms;68976898 this.getUniforms = function () {68996900 if ( cachedUniforms === undefined ) {69016902 6903 onFirstUse( this );69046905 }69066907 return cachedUniforms;69086909 };69106911 69126913 let cachedAttributes;69146915 this.getAttributes = function () {69166917 if ( cachedAttributes === undefined ) {69186919 6920 onFirstUse( this );69216922 }69236924 return cachedAttributes;69256926 };69276928 6929 69306931 let programReady = ( parameters.rendererExtensionParallelShaderCompile === false );69326933 this.isReady = function () {69346935 if ( programReady === false ) {69366937 programReady = gl.getProgramParameter( program, COMPLETION_STATUS_KHR );69386939 }69406941 return programReady;69426943 };69446945 69466947 this.destroy = function () {69486949 bindingStates.releaseStatesOfProgram( this );69506951 gl.deleteProgram( program );6952 this.program = undefined;69536954 };69556956 69576958 this.type = parameters.shaderType;6959 this.name = parameters.shaderName;6960 this.id = programIdCount ++;6961 this.cacheKey = cacheKey;6962 this.usedTimes = 1;6963 this.program = program;6964 this.vertexShader = glVertexShader;6965 this.fragmentShader = glFragmentShader;69666967 return this;69686969}69706971let _id = 0;69726973class WebGLShaderCache {69746975 constructor() {69766977 this.shaderCache = new Map();6978 this.materialCache = new Map();69796980 }69816982 update( material, vertexShaderStage, fragmentShaderStage ) {69836984 const materialShaders = this._getShaderCacheForMaterial( material );69856986 if ( materialShaders.has( vertexShaderStage ) === false ) {69876988 materialShaders.add( vertexShaderStage );6989 vertexShaderStage.usedTimes ++;69906991 }69926993 if ( materialShaders.has( fragmentShaderStage ) === false ) {69946995 materialShaders.add( fragmentShaderStage );6996 fragmentShaderStage.usedTimes ++;69976998 }69997000 return this;70017002 }70037004 remove( material ) {70057006 const materialShaders = this.materialCache.get( material );70077008 for ( const shaderStage of materialShaders ) {70097010 shaderStage.usedTimes --;70117012 if ( shaderStage.usedTimes === 0 ) this.shaderCache.delete( shaderStage.code );70137014 }70157016 this.materialCache.delete( material );70177018 return this;70197020 }70217022 getVertexShaderStage( material ) {70237024 return this._getShaderStage( material.vertexShader );70257026 }70277028 getFragmentShaderStage( material ) {70297030 return this._getShaderStage( material.fragmentShader );70317032 }70337034 dispose() {70357036 this.shaderCache.clear();7037 this.materialCache.clear();70387039 }70407041 _getShaderCacheForMaterial( material ) {70427043 const cache = this.materialCache;7044 let set = cache.get( material );70457046 if ( set === undefined ) {70477048 set = new Set();7049 cache.set( material, set );70507051 }70527053 return set;70547055 }70567057 _getShaderStage( code ) {70587059 const cache = this.shaderCache;7060 let stage = cache.get( code );70617062 if ( stage === undefined ) {70637064 stage = new WebGLShaderStage( code );7065 cache.set( code, stage );70667067 }70687069 return stage;70707071 }70727073}70747075class WebGLShaderStage {70767077 constructor( code ) {70787079 this.id = _id ++;70807081 this.code = code;7082 this.usedTimes = 0;70837084 }70857086}70877088function isPackedRGFormat( format ) {70897090 return format === RGFormat || format === RG11_EAC_Format || format === RED_GREEN_RGTC2_Format;70917092}70937094function WebGLPrograms( renderer, environments, extensions, capabilities, bindingStates, clipping ) {70957096 const _programLayers = new Layers();7097 const _customShaders = new WebGLShaderCache();7098 const _activeChannels = new Set();7099 const programs = [];7100 const programsMap = new Map();71017102 const logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;71037104 const shaderIDs = {7105 MeshDepthMaterial: 'depth',7106 MeshDistanceMaterial: 'distance',7107 MeshNormalMaterial: 'normal',7108 MeshBasicMaterial: 'basic',7109 MeshLambertMaterial: 'lambert',7110 MeshPhongMaterial: 'phong',7111 MeshToonMaterial: 'toon',7112 MeshStandardMaterial: 'physical',7113 MeshPhysicalMaterial: 'physical',7114 MeshMatcapMaterial: 'matcap',7115 LineBasicMaterial: 'basic',7116 LineDashedMaterial: 'dashed',7117 PointsMaterial: 'points',7118 ShadowMaterial: 'shadow',7119 SpriteMaterial: 'sprite'7120 };71217122 function getChannel( value ) {71237124 _activeChannels.add( value );71257126 if ( value === 0 ) return 'uv';71277128 return `uv${ value }`;71297130 }71317132 function getParameters( material, lights, shadows, scene, object, lightProbeGrids ) {71337134 const fog = scene.fog;7135 const geometry = object.geometry;7136 const environment = ( material.isMeshStandardMaterial || material.isMeshLambertMaterial || material.isMeshPhongMaterial ) ? scene.environment : null;71377138 const usePMREM = material.isMeshStandardMaterial || ( material.isMeshLambertMaterial && ! material.envMap ) || ( material.isMeshPhongMaterial && ! material.envMap );7139 const envMap = environments.get( material.envMap || environment, usePMREM );71407141 const shaderID = shaderIDs[ material.type ];71427143 7144 71457146 let precision = capabilities.precision;71477148 if ( material.precision !== null ) {71497150 precision = capabilities.getMaxPrecision( material.precision );71517152 if ( precision !== material.precision ) {71537154 warn( 'WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );71557156 }71577158 }71597160 71617162 const morphAttribute = geometry.morphAttributes.position || geometry.morphAttributes.normal || geometry.morphAttributes.color;7163 const morphTargetsCount = ( morphAttribute !== undefined ) ? morphAttribute.length : 0;71647165 let morphTextureStride = 0;71667167 if ( geometry.morphAttributes.position !== undefined ) morphTextureStride = 1;7168 if ( geometry.morphAttributes.normal !== undefined ) morphTextureStride = 2;7169 if ( geometry.morphAttributes.color !== undefined ) morphTextureStride = 3;71707171 71727173 let vertexShader, fragmentShader;7174 let customVertexShaderID, customFragmentShaderID;71757176 if ( shaderID ) {71777178 const shader = ShaderLib[ shaderID ];71797180 vertexShader = shader.vertexShader;7181 fragmentShader = shader.fragmentShader;71827183 } else {71847185 vertexShader = material.vertexShader;7186 fragmentShader = material.fragmentShader;71877188 const vertexShaderStage = _customShaders.getVertexShaderStage( material );7189 const fragmentShaderStage = _customShaders.getFragmentShaderStage( material );71907191 _customShaders.update( material, vertexShaderStage, fragmentShaderStage );71927193 customVertexShaderID = vertexShaderStage.id;7194 customFragmentShaderID = fragmentShaderStage.id;71957196 }71977198 const currentRenderTarget = renderer.getRenderTarget();7199 const reversedDepthBuffer = renderer.state.buffers.depth.getReversed();72007201 const IS_INSTANCEDMESH = object.isInstancedMesh === true;7202 const IS_BATCHEDMESH = object.isBatchedMesh === true;72037204 const HAS_MAP = !! material.map;7205 const HAS_MATCAP = !! material.matcap;7206 const HAS_ENVMAP = !! envMap;7207 const HAS_PMREM = HAS_ENVMAP && envMap.isPMREMTexture === true;7208 const HAS_AOMAP = !! material.aoMap;7209 const HAS_LIGHTMAP = !! material.lightMap;7210 const HAS_BUMPMAP = !! material.bumpMap && material.wireframe === false;7211 const HAS_NORMALMAP = !! material.normalMap;7212 const HAS_DISPLACEMENTMAP = !! material.displacementMap;7213 const HAS_EMISSIVEMAP = !! material.emissiveMap;72147215 const HAS_METALNESSMAP = !! material.metalnessMap;7216 const HAS_ROUGHNESSMAP = !! material.roughnessMap;72177218 const HAS_ANISOTROPY = material.anisotropy > 0;7219 const HAS_CLEARCOAT = material.clearcoat > 0;7220 const HAS_DIFFUSE_ROUGHNESS = material.diffuseRoughness > 0;7221 const HAS_DISPERSION = material.dispersion > 0;7222 const HAS_RETROREFLECTION = material.retroreflectivity > 0;7223 const HAS_IRIDESCENCE = material.iridescence > 0;7224 const HAS_SHEEN = material.sheen > 0;7225 const HAS_TRANSMISSION = material.transmission > 0;72267227 const HAS_ANISOTROPYMAP = HAS_ANISOTROPY && !! material.anisotropyMap;72287229 const HAS_CLEARCOATMAP = HAS_CLEARCOAT && !! material.clearcoatMap;7230 const HAS_CLEARCOAT_NORMALMAP = HAS_CLEARCOAT && !! material.clearcoatNormalMap;7231 const HAS_CLEARCOAT_ROUGHNESSMAP = HAS_CLEARCOAT && !! material.clearcoatRoughnessMap;7232 const HAS_DIFFUSE_ROUGHNESSMAP = HAS_DIFFUSE_ROUGHNESS && !! material.diffuseRoughnessMap;72337234 const HAS_IRIDESCENCEMAP = HAS_IRIDESCENCE && !! material.iridescenceMap;7235 const HAS_IRIDESCENCE_THICKNESSMAP = HAS_IRIDESCENCE && !! material.iridescenceThicknessMap;72367237 const HAS_SHEEN_COLORMAP = HAS_SHEEN && !! material.sheenColorMap;7238 const HAS_SHEEN_ROUGHNESSMAP = HAS_SHEEN && !! material.sheenRoughnessMap;72397240 const HAS_SPECULARMAP = !! material.specularMap;7241 const HAS_SPECULAR_COLORMAP = !! material.specularColorMap;7242 const HAS_SPECULAR_INTENSITYMAP = !! material.specularIntensityMap;72437244 const HAS_TRANSMISSIONMAP = HAS_TRANSMISSION && !! material.transmissionMap;7245 const HAS_THICKNESSMAP = HAS_TRANSMISSION && !! material.thicknessMap;72467247 const HAS_GRADIENTMAP = !! material.gradientMap;72487249 const HAS_ALPHAMAP = !! material.alphaMap;72507251 const HAS_ALPHATEST = material.alphaTest > 0;72527253 const HAS_ALPHAHASH = !! material.alphaHash;72547255 const HAS_EXTENSIONS = !! material.extensions;72567257 let toneMapping = NoToneMapping;72587259 if ( material.toneMapped ) {72607261 if ( currentRenderTarget === null || currentRenderTarget.isXRRenderTarget === true ) {72627263 toneMapping = renderer.toneMapping;72647265 }72667267 }72687269 const envMapMipmaps = HAS_PMREM ? ( envMap.isCompressedCubeTexture ? envMap.image[ 0 ].mipmaps : envMap.mipmaps ) : null;72707271 const parameters = {72727273 shaderID: shaderID,7274 shaderType: material.type,7275 shaderName: material.name,72767277 vertexShader: vertexShader,7278 fragmentShader: fragmentShader,7279 defines: material.defines,72807281 customVertexShaderID: customVertexShaderID,7282 customFragmentShaderID: customFragmentShaderID,72837284 isRawShaderMaterial: material.isRawShaderMaterial === true,7285 glslVersion: material.glslVersion,72867287 precision: precision,72887289 batching: IS_BATCHEDMESH,7290 batchingColor: IS_BATCHEDMESH && object._colorsTexture !== null,7291 instancing: IS_INSTANCEDMESH,7292 instancingColor: IS_INSTANCEDMESH && object.instanceColor !== null,7293 instancingMorph: IS_INSTANCEDMESH && object.morphTexture !== null,72947295 outputColorSpace: ( currentRenderTarget === null ) ? renderer.outputColorSpace : ( currentRenderTarget.isXRRenderTarget === true ? currentRenderTarget.texture.colorSpace : ColorManagement.workingColorSpace ),7296 alphaToCoverage: !! material.alphaToCoverage,72977298 map: HAS_MAP,7299 matcap: HAS_MATCAP,7300 envMap: HAS_ENVMAP,7301 envMapMode: HAS_ENVMAP && envMap.mapping,7302 envMapPMREM: HAS_PMREM,7303 envMapMaxLod: HAS_PMREM ? envMapMipmaps.length - 1 : null,7304 envMapSize: HAS_PMREM ? envMapMipmaps[ 0 ].width : null,7305 aoMap: HAS_AOMAP,7306 lightMap: HAS_LIGHTMAP,7307 bumpMap: HAS_BUMPMAP,7308 normalMap: HAS_NORMALMAP,7309 displacementMap: HAS_DISPLACEMENTMAP,7310 emissiveMap: HAS_EMISSIVEMAP,73117312 normalMapObjectSpace: HAS_NORMALMAP && material.normalMapType === ObjectSpaceNormalMap,7313 normalMapTangentSpace: HAS_NORMALMAP && material.normalMapType === TangentSpaceNormalMap,7314 packedNormalMap: HAS_NORMALMAP && material.normalMapType === TangentSpaceNormalMap && isPackedRGFormat( material.normalMap.format ),73157316 metalnessMap: HAS_METALNESSMAP,7317 roughnessMap: HAS_ROUGHNESSMAP,73187319 anisotropy: HAS_ANISOTROPY,7320 anisotropyMap: HAS_ANISOTROPYMAP,73217322 clearcoat: HAS_CLEARCOAT,7323 clearcoatMap: HAS_CLEARCOATMAP,7324 clearcoatNormalMap: HAS_CLEARCOAT_NORMALMAP,7325 clearcoatRoughnessMap: HAS_CLEARCOAT_ROUGHNESSMAP,73267327 diffuseRoughness: HAS_DIFFUSE_ROUGHNESS,7328 diffuseRoughnessMap: HAS_DIFFUSE_ROUGHNESSMAP,7329 dispersion: HAS_DISPERSION,7330 retroreflection: HAS_RETROREFLECTION,73317332 iridescence: HAS_IRIDESCENCE,7333 iridescenceMap: HAS_IRIDESCENCEMAP,7334 iridescenceThicknessMap: HAS_IRIDESCENCE_THICKNESSMAP,73357336 sheen: HAS_SHEEN,7337 sheenColorMap: HAS_SHEEN_COLORMAP,7338 sheenRoughnessMap: HAS_SHEEN_ROUGHNESSMAP,73397340 specularMap: HAS_SPECULARMAP,7341 specularColorMap: HAS_SPECULAR_COLORMAP,7342 specularIntensityMap: HAS_SPECULAR_INTENSITYMAP,73437344 transmission: HAS_TRANSMISSION,7345 transmissionMap: HAS_TRANSMISSIONMAP,7346 thicknessMap: HAS_THICKNESSMAP,73477348 gradientMap: HAS_GRADIENTMAP,73497350 opaque: material.transparent === false && material.blending === NormalBlending && material.alphaToCoverage === false,73517352 alphaMap: HAS_ALPHAMAP,7353 alphaTest: HAS_ALPHATEST,7354 alphaHash: HAS_ALPHAHASH,73557356 combine: material.combine,73577358 73597360 mapUv: HAS_MAP && getChannel( material.map.channel ),7361 aoMapUv: HAS_AOMAP && getChannel( material.aoMap.channel ),7362 lightMapUv: HAS_LIGHTMAP && getChannel( material.lightMap.channel ),7363 bumpMapUv: HAS_BUMPMAP && getChannel( material.bumpMap.channel ),7364 normalMapUv: HAS_NORMALMAP && getChannel( material.normalMap.channel ),7365 displacementMapUv: HAS_DISPLACEMENTMAP && getChannel( material.displacementMap.channel ),7366 emissiveMapUv: HAS_EMISSIVEMAP && getChannel( material.emissiveMap.channel ),73677368 metalnessMapUv: HAS_METALNESSMAP && getChannel( material.metalnessMap.channel ),7369 roughnessMapUv: HAS_ROUGHNESSMAP && getChannel( material.roughnessMap.channel ),73707371 anisotropyMapUv: HAS_ANISOTROPYMAP && getChannel( material.anisotropyMap.channel ),73727373 clearcoatMapUv: HAS_CLEARCOATMAP && getChannel( material.clearcoatMap.channel ),7374 clearcoatNormalMapUv: HAS_CLEARCOAT_NORMALMAP && getChannel( material.clearcoatNormalMap.channel ),7375 clearcoatRoughnessMapUv: HAS_CLEARCOAT_ROUGHNESSMAP && getChannel( material.clearcoatRoughnessMap.channel ),7376 diffuseRoughnessMapUv: HAS_DIFFUSE_ROUGHNESSMAP && getChannel( material.diffuseRoughnessMap.channel ),73777378 iridescenceMapUv: HAS_IRIDESCENCEMAP && getChannel( material.iridescenceMap.channel ),7379 iridescenceThicknessMapUv: HAS_IRIDESCENCE_THICKNESSMAP && getChannel( material.iridescenceThicknessMap.channel ),73807381 sheenColorMapUv: HAS_SHEEN_COLORMAP && getChannel( material.sheenColorMap.channel ),7382 sheenRoughnessMapUv: HAS_SHEEN_ROUGHNESSMAP && getChannel( material.sheenRoughnessMap.channel ),73837384 specularMapUv: HAS_SPECULARMAP && getChannel( material.specularMap.channel ),7385 specularColorMapUv: HAS_SPECULAR_COLORMAP && getChannel( material.specularColorMap.channel ),7386 specularIntensityMapUv: HAS_SPECULAR_INTENSITYMAP && getChannel( material.specularIntensityMap.channel ),73877388 transmissionMapUv: HAS_TRANSMISSIONMAP && getChannel( material.transmissionMap.channel ),7389 thicknessMapUv: HAS_THICKNESSMAP && getChannel( material.thicknessMap.channel ),73907391 alphaMapUv: HAS_ALPHAMAP && getChannel( material.alphaMap.channel ),73927393 73947395 vertexTangents: !! geometry.attributes.tangent && ( HAS_NORMALMAP || HAS_ANISOTROPY ),7396 vertexNormals: !! geometry.attributes.normal,7397 vertexColors: material.vertexColors,7398 vertexAlphas: material.vertexColors === true && !! geometry.attributes.color && geometry.attributes.color.itemSize === 4,73997400 pointsUvs: object.isPoints === true && !! geometry.attributes.uv && ( HAS_MAP || HAS_ALPHAMAP ),74017402 fog: !! fog,7403 useFog: material.fog === true,7404 fogExp2: ( !! fog && fog.isFogExp2 ),74057406 flatShading: material.wireframe === false && (7407 material.flatShading === true ||7408 ( geometry.attributes.normal === undefined && HAS_NORMALMAP === false &&7409 ( material.isMeshLambertMaterial || material.isMeshPhongMaterial || material.isMeshStandardMaterial || material.isMeshPhysicalMaterial )7410 )7411 ),74127413 sizeAttenuation: material.sizeAttenuation === true,7414 logarithmicDepthBuffer: logarithmicDepthBuffer,7415 reversedDepthBuffer: reversedDepthBuffer,74167417 skinning: object.isSkinnedMesh === true,74187419 hasPositionAttribute: geometry.attributes.position !== undefined,74207421 morphTargets: geometry.morphAttributes.position !== undefined,7422 morphNormals: geometry.morphAttributes.normal !== undefined,7423 morphColors: geometry.morphAttributes.color !== undefined,7424 morphTargetsCount: morphTargetsCount,7425 morphTextureStride: morphTextureStride,74267427 numSunLights: lights.sun.length,7428 numDirLights: lights.directional.length,7429 numPointLights: lights.point.length,7430 numSpotLights: lights.spot.length,7431 numSpotLightMaps: lights.spotLightMap.length,7432 numRectAreaLights: lights.rectArea.length,7433 numHemiLights: lights.hemi.length,74347435 numSunLightShadows: lights.sunShadowMap.length,7436 numDirLightShadows: lights.directionalShadowMap.length,7437 numPointLightShadows: lights.pointShadowMap.length,7438 numSpotLightShadows: lights.spotShadowMap.length,7439 numSpotLightShadowsWithMaps: lights.numSpotLightShadowsWithMaps,74407441 numLightProbes: lights.numLightProbes,74427443 numLightProbeGrids: lightProbeGrids.filter( grid => grid.texture !== null ).length,74447445 numClippingPlanes: clipping.numPlanes,7446 numClipIntersection: clipping.numIntersection,74477448 dithering: material.dithering,74497450 shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,7451 shadowMapType: renderer.shadowMap.type,74527453 toneMapping: toneMapping,74547455 decodeVideoTexture: HAS_MAP && ( material.map.isVideoTexture === true ) && ( ColorManagement.getTransfer( material.map.colorSpace ) === SRGBTransfer ),7456 decodeVideoTextureEmissive: HAS_EMISSIVEMAP && ( material.emissiveMap.isVideoTexture === true ) && ( ColorManagement.getTransfer( material.emissiveMap.colorSpace ) === SRGBTransfer ),74577458 premultipliedAlpha: material.premultipliedAlpha,74597460 doubleSided: material.side === DoubleSide,7461 flipSided: material.side === BackSide,74627463 useDepthPacking: material.depthPacking >= 0,7464 depthPacking: material.depthPacking || 0,74657466 index0AttributeName: material.index0AttributeName,74677468 extensionClipCullDistance: HAS_EXTENSIONS && material.extensions.clipCullDistance === true && extensions.has( 'WEBGL_clip_cull_distance' ),7469 extensionMultiDraw: ( HAS_EXTENSIONS && material.extensions.multiDraw === true || IS_BATCHEDMESH ) && extensions.has( 'WEBGL_multi_draw' ),74707471 rendererExtensionParallelShaderCompile: extensions.has( 'KHR_parallel_shader_compile' ),74727473 customProgramCacheKey: material.customProgramCacheKey()74747475 };74767477 74787479 parameters.vertexUv1s = _activeChannels.has( 1 );7480 parameters.vertexUv2s = _activeChannels.has( 2 );7481 parameters.vertexUv3s = _activeChannels.has( 3 );74827483 _activeChannels.clear();74847485 return parameters;74867487 }74887489 function getProgramCacheKey( parameters ) {74907491 const array = [];74927493 if ( parameters.shaderID ) {74947495 array.push( parameters.shaderID );74967497 } else {74987499 array.push( parameters.customVertexShaderID );7500 array.push( parameters.customFragmentShaderID );75017502 }75037504 if ( parameters.defines !== undefined ) {75057506 for ( const name in parameters.defines ) {75077508 array.push( name );7509 array.push( parameters.defines[ name ] );75107511 }75127513 }75147515 if ( parameters.isRawShaderMaterial === false ) {75167517 getProgramCacheKeyParameters( array, parameters );7518 getProgramCacheKeyBooleans( array, parameters );7519 array.push( renderer.outputColorSpace );75207521 }75227523 array.push( parameters.customProgramCacheKey );75247525 return array.join();75267527 }75287529 function getProgramCacheKeyParameters( array, parameters ) {75307531 array.push( parameters.precision );7532 array.push( parameters.outputColorSpace );7533 array.push( parameters.envMapMode );7534 array.push( parameters.envMapPMREM );7535 array.push( parameters.envMapMaxLod );7536 array.push( parameters.envMapSize );7537 array.push( parameters.mapUv );7538 array.push( parameters.alphaMapUv );7539 array.push( parameters.lightMapUv );7540 array.push( parameters.aoMapUv );7541 array.push( parameters.bumpMapUv );7542 array.push( parameters.normalMapUv );7543 array.push( parameters.displacementMapUv );7544 array.push( parameters.emissiveMapUv );7545 array.push( parameters.metalnessMapUv );7546 array.push( parameters.roughnessMapUv );7547 array.push( parameters.anisotropyMapUv );7548 array.push( parameters.clearcoatMapUv );7549 array.push( parameters.clearcoatNormalMapUv );7550 array.push( parameters.clearcoatRoughnessMapUv );7551 array.push( parameters.diffuseRoughnessMapUv );7552 array.push( parameters.iridescenceMapUv );7553 array.push( parameters.iridescenceThicknessMapUv );7554 array.push( parameters.sheenColorMapUv );7555 array.push( parameters.sheenRoughnessMapUv );7556 array.push( parameters.specularMapUv );7557 array.push( parameters.specularColorMapUv );7558 array.push( parameters.specularIntensityMapUv );7559 array.push( parameters.transmissionMapUv );7560 array.push( parameters.thicknessMapUv );7561 array.push( parameters.combine );7562 array.push( parameters.fogExp2 );7563 array.push( parameters.sizeAttenuation );7564 array.push( parameters.morphTargetsCount );7565 array.push( parameters.numSunLights );7566 array.push( parameters.numDirLights );7567 array.push( parameters.numPointLights );7568 array.push( parameters.numSpotLights );7569 array.push( parameters.numSpotLightMaps );7570 array.push( parameters.numHemiLights );7571 array.push( parameters.numRectAreaLights );7572 array.push( parameters.numSunLightShadows );7573 array.push( parameters.numDirLightShadows );7574 array.push( parameters.numPointLightShadows );7575 array.push( parameters.numSpotLightShadows );7576 array.push( parameters.numSpotLightShadowsWithMaps );7577 array.push( parameters.numLightProbes );7578 array.push( parameters.numLightProbeGrids );7579 array.push( parameters.shadowMapType );7580 array.push( parameters.toneMapping );7581 array.push( parameters.numClippingPlanes );7582 array.push( parameters.numClipIntersection );7583 array.push( parameters.depthPacking );75847585 }75867587 function getProgramCacheKeyBooleans( array, parameters ) {75887589 _programLayers.disableAll();75907591 if ( parameters.instancing )7592 _programLayers.enable( 0 );7593 if ( parameters.instancingColor )7594 _programLayers.enable( 1 );7595 if ( parameters.instancingMorph )7596 _programLayers.enable( 2 );7597 if ( parameters.matcap )7598 _programLayers.enable( 3 );7599 if ( parameters.envMap )7600 _programLayers.enable( 4 );7601 if ( parameters.normalMapObjectSpace )7602 _programLayers.enable( 5 );7603 if ( parameters.normalMapTangentSpace )7604 _programLayers.enable( 6 );7605 if ( parameters.clearcoat )7606 _programLayers.enable( 7 );7607 if ( parameters.iridescence )7608 _programLayers.enable( 8 );7609 if ( parameters.alphaTest )7610 _programLayers.enable( 9 );7611 if ( parameters.vertexColors )7612 _programLayers.enable( 10 );7613 if ( parameters.vertexAlphas )7614 _programLayers.enable( 11 );7615 if ( parameters.vertexUv1s )7616 _programLayers.enable( 12 );7617 if ( parameters.vertexUv2s )7618 _programLayers.enable( 13 );7619 if ( parameters.vertexUv3s )7620 _programLayers.enable( 14 );7621 if ( parameters.vertexTangents )7622 _programLayers.enable( 15 );7623 if ( parameters.anisotropy )7624 _programLayers.enable( 16 );7625 if ( parameters.alphaHash )7626 _programLayers.enable( 17 );7627 if ( parameters.batching )7628 _programLayers.enable( 18 );7629 if ( parameters.dispersion )7630 _programLayers.enable( 19 );7631 if ( parameters.retroreflection )7632 _programLayers.enable( 24 );7633 if ( parameters.diffuseRoughness )7634 _programLayers.enable( 25 );7635 if ( parameters.batchingColor )7636 _programLayers.enable( 20 );7637 if ( parameters.gradientMap )7638 _programLayers.enable( 21 );7639 if ( parameters.packedNormalMap )7640 _programLayers.enable( 22 );7641 if ( parameters.vertexNormals )7642 _programLayers.enable( 23 );76437644 array.push( _programLayers.mask );7645 _programLayers.disableAll();76467647 if ( parameters.fog )7648 _programLayers.enable( 0 );7649 if ( parameters.useFog )7650 _programLayers.enable( 1 );7651 if ( parameters.flatShading )7652 _programLayers.enable( 2 );7653 if ( parameters.logarithmicDepthBuffer )7654 _programLayers.enable( 3 );7655 if ( parameters.reversedDepthBuffer )7656 _programLayers.enable( 4 );7657 if ( parameters.skinning )7658 _programLayers.enable( 5 );7659 if ( parameters.morphTargets )7660 _programLayers.enable( 6 );7661 if ( parameters.morphNormals )7662 _programLayers.enable( 7 );7663 if ( parameters.morphColors )7664 _programLayers.enable( 8 );7665 if ( parameters.premultipliedAlpha )7666 _programLayers.enable( 9 );7667 if ( parameters.shadowMapEnabled )7668 _programLayers.enable( 10 );7669 if ( parameters.doubleSided )7670 _programLayers.enable( 11 );7671 if ( parameters.flipSided )7672 _programLayers.enable( 12 );7673 if ( parameters.useDepthPacking )7674 _programLayers.enable( 13 );7675 if ( parameters.dithering )7676 _programLayers.enable( 14 );7677 if ( parameters.transmission )7678 _programLayers.enable( 15 );7679 if ( parameters.sheen )7680 _programLayers.enable( 16 );7681 if ( parameters.opaque )7682 _programLayers.enable( 17 );7683 if ( parameters.pointsUvs )7684 _programLayers.enable( 18 );7685 if ( parameters.decodeVideoTexture )7686 _programLayers.enable( 19 );7687 if ( parameters.decodeVideoTextureEmissive )7688 _programLayers.enable( 20 );7689 if ( parameters.alphaToCoverage )7690 _programLayers.enable( 21 );7691 if ( parameters.numLightProbeGrids > 0 )7692 _programLayers.enable( 22 );7693 if ( parameters.hasPositionAttribute )7694 _programLayers.enable( 23 );76957696 array.push( _programLayers.mask );76977698 }76997700 function getUniforms( material ) {77017702 const shaderID = shaderIDs[ material.type ];7703 let uniforms;77047705 if ( shaderID ) {77067707 const shader = ShaderLib[ shaderID ];7708 uniforms = UniformsUtils.clone( shader.uniforms );77097710 } else {77117712 uniforms = material.uniforms;77137714 }77157716 return uniforms;77177718 }77197720 function acquireProgram( parameters, cacheKey ) {77217722 let program = programsMap.get( cacheKey );77237724 if ( program !== undefined ) {77257726 ++ program.usedTimes;77277728 } else {77297730 program = new WebGLProgram( renderer, cacheKey, parameters, bindingStates );7731 programs.push( program );77327733 programsMap.set( cacheKey, program );77347735 }77367737 return program;77387739 }77407741 function releaseProgram( program ) {77427743 if ( -- program.usedTimes === 0 ) {77447745 7746 const i = programs.indexOf( program );7747 programs[ i ] = programs[ programs.length - 1 ];7748 programs.pop();77497750 7751 programsMap.delete( program.cacheKey );77527753 7754 program.destroy();77557756 }77577758 }77597760 function releaseShaderCache( material ) {77617762 _customShaders.remove( material );77637764 }77657766 function dispose() {77677768 _customShaders.dispose();77697770 }77717772 return {7773 getParameters: getParameters,7774 getProgramCacheKey: getProgramCacheKey,7775 getUniforms: getUniforms,7776 acquireProgram: acquireProgram,7777 releaseProgram: releaseProgram,7778 releaseShaderCache: releaseShaderCache,7779 7780 programs: programs,7781 dispose: dispose7782 };77837784}77857786function WebGLProperties() {77877788 let properties = new WeakMap();77897790 function has( object ) {77917792 return properties.has( object );77937794 }77957796 function get( object ) {77977798 let map = properties.get( object );77997800 if ( map === undefined ) {78017802 map = {};7803 properties.set( object, map );78047805 }78067807 return map;78087809 }78107811 function remove( object ) {78127813 properties.delete( object );78147815 }78167817 function update( object, key, value ) {78187819 properties.get( object )[ key ] = value;78207821 }78227823 function dispose() {78247825 properties = new WeakMap();78267827 }78287829 return {7830 has: has,7831 get: get,7832 remove: remove,7833 update: update,7834 dispose: dispose7835 };78367837}78387839function painterSortStable( a, b ) {78407841 if ( a.groupOrder !== b.groupOrder ) {78427843 return a.groupOrder - b.groupOrder;78447845 } else if ( a.renderOrder !== b.renderOrder ) {78467847 return a.renderOrder - b.renderOrder;78487849 } else if ( a.material.id !== b.material.id ) {78507851 return a.material.id - b.material.id;78527853 } else if ( a.materialVariant !== b.materialVariant ) {78547855 return a.materialVariant - b.materialVariant;78567857 } else if ( a.z !== b.z ) {78587859 return a.z - b.z;78607861 } else {78627863 return a.id - b.id;78647865 }78667867}78687869function reversePainterSortStable( a, b ) {78707871 if ( a.groupOrder !== b.groupOrder ) {78727873 return a.groupOrder - b.groupOrder;78747875 } else if ( a.renderOrder !== b.renderOrder ) {78767877 return a.renderOrder - b.renderOrder;78787879 } else if ( a.z !== b.z ) {78807881 return b.z - a.z;78827883 } else {78847885 return a.id - b.id;78867887 }78887889}789078917892function WebGLRenderList() {78937894 const renderItems = [];7895 let renderItemsIndex = 0;78967897 const opaque = [];7898 const transmissive = [];7899 const transparent = [];79007901 function init() {79027903 renderItemsIndex = 0;79047905 opaque.length = 0;7906 transmissive.length = 0;7907 transparent.length = 0;79087909 }79107911 function materialVariant( object ) {79127913 let variant = 0;7914 if ( object.isInstancedMesh ) variant += 2;7915 if ( object.isSkinnedMesh ) variant += 1;7916 return variant;79177918 }79197920 function getNextRenderItem( object, geometry, material, groupOrder, z, group ) {79217922 let renderItem = renderItems[ renderItemsIndex ];79237924 if ( renderItem === undefined ) {79257926 renderItem = {7927 id: object.id,7928 object: object,7929 geometry: geometry,7930 material: material,7931 materialVariant: materialVariant( object ),7932 groupOrder: groupOrder,7933 renderOrder: object.renderOrder,7934 z: z,7935 group: group7936 };79377938 renderItems[ renderItemsIndex ] = renderItem;79397940 } else {79417942 renderItem.id = object.id;7943 renderItem.object = object;7944 renderItem.geometry = geometry;7945 renderItem.material = material;7946 renderItem.materialVariant = materialVariant( object );7947 renderItem.groupOrder = groupOrder;7948 renderItem.renderOrder = object.renderOrder;7949 renderItem.z = z;7950 renderItem.group = group;79517952 }79537954 renderItemsIndex ++;79557956 return renderItem;79577958 }79597960 function push( object, geometry, material, groupOrder, z, group, camera ) {79617962 79637964 if ( camera.reversedDepth === true ) z = - z;79657966 const renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );79677968 if ( material.transmission > 0.0 ) {79697970 transmissive.push( renderItem );79717972 } else if ( material.transparent === true ) {79737974 transparent.push( renderItem );79757976 } else {79777978 opaque.push( renderItem );79797980 }79817982 }79837984 function unshift( object, geometry, material, groupOrder, z, group ) {79857986 const renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );79877988 if ( material.transmission > 0.0 ) {79897990 transmissive.unshift( renderItem );79917992 } else if ( material.transparent === true ) {79937994 transparent.unshift( renderItem );79957996 } else {79977998 opaque.unshift( renderItem );79998000 }80018002 }80038004 function sort( customOpaqueSort, customTransparentSort ) {80058006 if ( opaque.length > 1 ) opaque.sort( customOpaqueSort || painterSortStable );8007 if ( transmissive.length > 1 ) transmissive.sort( customTransparentSort || reversePainterSortStable );8008 if ( transparent.length > 1 ) transparent.sort( customTransparentSort || reversePainterSortStable );80098010 }80118012 function finish() {80138014 80158016 for ( let i = renderItemsIndex, il = renderItems.length; i < il; i ++ ) {80178018 const renderItem = renderItems[ i ];80198020 if ( renderItem.id === null ) break;80218022 renderItem.id = null;8023 renderItem.object = null;8024 renderItem.geometry = null;8025 renderItem.material = null;8026 renderItem.group = null;80278028 }80298030 }80318032 return {80338034 opaque: opaque,8035 transmissive: transmissive,8036 transparent: transparent,80378038 init: init,8039 push: push,8040 unshift: unshift,8041 finish: finish,80428043 sort: sort8044 };80458046}80478048function WebGLRenderLists() {80498050 let lists = new WeakMap();80518052 function get( scene, renderCallDepth ) {80538054 const listArray = lists.get( scene );8055 let list;80568057 if ( listArray === undefined ) {80588059 list = new WebGLRenderList();8060 lists.set( scene, [ list ] );80618062 } else {80638064 if ( renderCallDepth >= listArray.length ) {80658066 list = new WebGLRenderList();8067 listArray.push( list );80688069 } else {80708071 list = listArray[ renderCallDepth ];80728073 }80748075 }80768077 return list;80788079 }80808081 function dispose() {80828083 lists = new WeakMap();80848085 }80868087 return {8088 get: get,8089 dispose: dispose8090 };80918092}80938094function UniformsCache() {80958096 const lights = {};80978098 return {80998100 get: function ( light ) {81018102 if ( lights[ light.id ] !== undefined ) {81038104 return lights[ light.id ];81058106 }81078108 let uniforms;81098110 switch ( light.type ) {81118112 case 'SunLight':8113 case 'DirectionalLight':8114 uniforms = {8115 direction: new Vector3(),8116 color: new Color()8117 };8118 break;81198120 case 'SpotLight':8121 uniforms = {8122 position: new Vector3(),8123 direction: new Vector3(),8124 color: new Color(),8125 distance: 0,8126 coneCos: 0,8127 penumbraCos: 0,8128 decay: 08129 };8130 break;81318132 case 'PointLight':8133 uniforms = {8134 position: new Vector3(),8135 color: new Color(),8136 distance: 0,8137 decay: 08138 };8139 break;81408141 case 'HemisphereLight':8142 uniforms = {8143 direction: new Vector3(),8144 skyColor: new Color(),8145 groundColor: new Color()8146 };8147 break;81488149 case 'RectAreaLight':8150 uniforms = {8151 color: new Color(),8152 position: new Vector3(),8153 halfWidth: new Vector3(),8154 halfHeight: new Vector3()8155 };8156 break;81578158 }81598160 lights[ light.id ] = uniforms;81618162 return uniforms;81638164 }81658166 };81678168}81698170function ShadowUniformsCache() {81718172 const lights = {};81738174 return {81758176 get: function ( light ) {81778178 if ( lights[ light.id ] !== undefined ) {81798180 return lights[ light.id ];81818182 }81838184 let uniforms;81858186 switch ( light.type ) {81878188 case 'SunLight':8189 case 'DirectionalLight':8190 uniforms = {8191 shadowIntensity: 1,8192 shadowBias: 0,8193 shadowNormalBias: 0,8194 shadowRadius: 1,8195 shadowMapSize: new Vector2()8196 };8197 break;81988199 case 'SpotLight':8200 uniforms = {8201 shadowIntensity: 1,8202 shadowBias: 0,8203 shadowNormalBias: 0,8204 shadowRadius: 1,8205 shadowMapSize: new Vector2()8206 };8207 break;82088209 case 'PointLight':8210 uniforms = {8211 shadowIntensity: 1,8212 shadowBias: 0,8213 shadowNormalBias: 0,8214 shadowRadius: 1,8215 shadowMapSize: new Vector2(),8216 shadowCameraNear: 1,8217 shadowCameraFar: 10008218 };8219 break;82208221 82228223 }82248225 lights[ light.id ] = uniforms;82268227 return uniforms;82288229 }82308231 };82328233}8234823582368237let nextVersion = 0;82388239function shadowCastingAndTexturingLightsFirst( lightA, lightB ) {82408241 return ( lightB.castShadow ? 2 : 0 ) - ( lightA.castShadow ? 2 : 0 ) + ( lightB.map ? 1 : 0 ) - ( lightA.map ? 1 : 0 );82428243}82448245function WebGLLights( extensions ) {82468247 const cache = new UniformsCache();82488249 const shadowCache = ShadowUniformsCache();82508251 const state = {82528253 version: 0,82548255 hash: {8256 sunLength: -1,8257 directionalLength: -1,8258 pointLength: -1,8259 spotLength: -1,8260 rectAreaLength: -1,8261 hemiLength: -1,82628263 numSunShadows: -1,8264 numDirectionalShadows: -1,8265 numPointShadows: -1,8266 numSpotShadows: -1,8267 numSpotMaps: -1,82688269 numLightProbes: -18270 },82718272 ambient: [ 0, 0, 0 ],8273 probe: [],8274 sun: [],8275 sunShadow: [],8276 sunShadowMap: [],8277 sunShadowMatrix: [],8278 sunShadowCascade: [],8279 directional: [],8280 directionalShadow: [],8281 directionalShadowMap: [],8282 directionalShadowMatrix: [],8283 spot: [],8284 spotLightMap: [],8285 spotShadow: [],8286 spotShadowMap: [],8287 spotLightMatrix: [],8288 rectArea: [],8289 rectAreaLTC1: null,8290 rectAreaLTC2: null,8291 point: [],8292 pointShadow: [],8293 pointShadowMap: [],8294 pointShadowMatrix: [],8295 hemi: [],8296 numSpotLightShadowsWithMaps: 0,8297 numLightProbes: 082988299 };83008301 for ( let i = 0; i < 9; i ++ ) state.probe.push( new Vector3() );83028303 const vector3 = new Vector3();8304 const matrix4 = new Matrix4();8305 const matrix42 = new Matrix4();83068307 function setup( lights ) {83088309 let r = 0, g = 0, b = 0;83108311 for ( let i = 0; i < 9; i ++ ) state.probe[ i ].set( 0, 0, 0 );83128313 let sunLength = 0;8314 let numSunShadows = 0;8315 let numSunShadowCascades = 0;8316 let directionalLength = 0;8317 let pointLength = 0;8318 let spotLength = 0;8319 let rectAreaLength = 0;8320 let hemiLength = 0;83218322 let numDirectionalShadows = 0;8323 let numPointShadows = 0;8324 let numSpotShadows = 0;8325 let numSpotMaps = 0;8326 let numSpotShadowsWithMaps = 0;83278328 let numLightProbes = 0;83298330 8331 lights.sort( shadowCastingAndTexturingLightsFirst );83328333 for ( let i = 0, l = lights.length; i < l; i ++ ) {83348335 const light = lights[ i ];83368337 const color = light.color;8338 const intensity = light.intensity;8339 const distance = light.distance;83408341 let shadowMap = null;83428343 if ( light.shadow && light.shadow.map ) {83448345 if ( light.shadow.map.texture.format === RGFormat ) {83468347 8348 shadowMap = light.shadow.map.texture;83498350 } else {83518352 8353 shadowMap = light.shadow.map.depthTexture || light.shadow.map.texture;83548355 }83568357 }83588359 if ( light.isAmbientLight ) {83608361 r += color.r * intensity;8362 g += color.g * intensity;8363 b += color.b * intensity;83648365 } else if ( light.isLightProbe ) {83668367 for ( let j = 0; j < 9; j ++ ) {83688369 state.probe[ j ].addScaledVector( light.sh.coefficients[ j ], intensity );83708371 }83728373 numLightProbes ++;83748375 } else if ( light.isSunLight ) {83768377 const uniforms = cache.get( light );83788379 uniforms.color.copy( light.color ).multiplyScalar( light.intensity );83808381 if ( light.castShadow ) {83828383 const shadow = light.shadow;83848385 const shadowUniforms = shadowCache.get( light );83868387 shadowUniforms.shadowIntensity = shadow.intensity;8388 shadowUniforms.shadowBias = shadow.bias;8389 shadowUniforms.shadowNormalBias = shadow.normalBias;8390 shadowUniforms.shadowRadius = shadow.radius;8391 shadowUniforms.shadowMapSize.copy( shadow.mapSize ).multiply( shadow.getFrameExtents() );83928393 state.sunShadow[ numSunShadows ] = shadowUniforms;8394 state.sunShadowMap[ numSunShadows ] = shadowMap;83958396 const cascadeCount = shadow.getViewportCount();83978398 for ( let j = 0; j < cascadeCount; j ++ ) {83998400 state.sunShadowMatrix[ numSunShadowCascades + j ] = shadow.getMatrix( j );8401 state.sunShadowCascade[ numSunShadowCascades + j ] = shadow._cascadeData[ j ];84028403 }84048405 numSunShadowCascades += cascadeCount;8406 numSunShadows ++;84078408 }84098410 state.sun[ sunLength ] = uniforms;84118412 sunLength ++;84138414 } else if ( light.isDirectionalLight ) {84158416 const uniforms = cache.get( light );84178418 uniforms.color.copy( light.color ).multiplyScalar( light.intensity );84198420 if ( light.castShadow ) {84218422 const shadow = light.shadow;84238424 const shadowUniforms = shadowCache.get( light );84258426 shadowUniforms.shadowIntensity = shadow.intensity;8427 shadowUniforms.shadowBias = shadow.bias;8428 shadowUniforms.shadowNormalBias = shadow.normalBias;8429 shadowUniforms.shadowRadius = shadow.radius;8430 shadowUniforms.shadowMapSize = shadow.mapSize;84318432 state.directionalShadow[ directionalLength ] = shadowUniforms;8433 state.directionalShadowMap[ directionalLength ] = shadowMap;8434 state.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;84358436 numDirectionalShadows ++;84378438 }84398440 state.directional[ directionalLength ] = uniforms;84418442 directionalLength ++;84438444 } else if ( light.isSpotLight ) {84458446 const uniforms = cache.get( light );84478448 uniforms.position.setFromMatrixPosition( light.matrixWorld );84498450 uniforms.color.copy( color ).multiplyScalar( intensity );8451 uniforms.distance = distance;84528453 uniforms.coneCos = Math.cos( light.angle );8454 uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );8455 uniforms.decay = light.decay;84568457 state.spot[ spotLength ] = uniforms;84588459 const shadow = light.shadow;84608461 if ( light.map ) {84628463 state.spotLightMap[ numSpotMaps ] = light.map;8464 numSpotMaps ++;84658466 8467 8468 shadow.updateMatrices( light );84698470 if ( light.castShadow ) numSpotShadowsWithMaps ++;84718472 }84738474 state.spotLightMatrix[ spotLength ] = shadow.matrix;84758476 if ( light.castShadow ) {84778478 const shadowUniforms = shadowCache.get( light );84798480 shadowUniforms.shadowIntensity = shadow.intensity;8481 shadowUniforms.shadowBias = shadow.bias;8482 shadowUniforms.shadowNormalBias = shadow.normalBias;8483 shadowUniforms.shadowRadius = shadow.radius;8484 shadowUniforms.shadowMapSize = shadow.mapSize;84858486 state.spotShadow[ spotLength ] = shadowUniforms;8487 state.spotShadowMap[ spotLength ] = shadowMap;84888489 numSpotShadows ++;84908491 }84928493 spotLength ++;84948495 } else if ( light.isRectAreaLight ) {84968497 const uniforms = cache.get( light );84988499 uniforms.color.copy( color ).multiplyScalar( intensity );85008501 uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );8502 uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );85038504 state.rectArea[ rectAreaLength ] = uniforms;85058506 rectAreaLength ++;85078508 } else if ( light.isPointLight ) {85098510 const uniforms = cache.get( light );85118512 uniforms.color.copy( light.color ).multiplyScalar( light.intensity );8513 uniforms.distance = light.distance;8514 uniforms.decay = light.decay;85158516 if ( light.castShadow ) {85178518 const shadow = light.shadow;85198520 const shadowUniforms = shadowCache.get( light );85218522 shadowUniforms.shadowIntensity = shadow.intensity;8523 shadowUniforms.shadowBias = shadow.bias;8524 shadowUniforms.shadowNormalBias = shadow.normalBias;8525 shadowUniforms.shadowRadius = shadow.radius;8526 shadowUniforms.shadowMapSize = shadow.mapSize;8527 shadowUniforms.shadowCameraNear = shadow.camera.near;8528 shadowUniforms.shadowCameraFar = shadow.camera.far;85298530 state.pointShadow[ pointLength ] = shadowUniforms;8531 state.pointShadowMap[ pointLength ] = shadowMap;8532 state.pointShadowMatrix[ pointLength ] = light.shadow.matrix;85338534 numPointShadows ++;85358536 }85378538 state.point[ pointLength ] = uniforms;85398540 pointLength ++;85418542 } else if ( light.isHemisphereLight ) {85438544 const uniforms = cache.get( light );85458546 uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );8547 uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );85488549 state.hemi[ hemiLength ] = uniforms;85508551 hemiLength ++;85528553 }85548555 }85568557 if ( rectAreaLength > 0 ) {85588559 if ( extensions.has( 'OES_texture_float_linear' ) === true ) {85608561 state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;8562 state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;85638564 } else {85658566 state.rectAreaLTC1 = UniformsLib.LTC_HALF_1;8567 state.rectAreaLTC2 = UniformsLib.LTC_HALF_2;85688569 }85708571 }85728573 state.ambient[ 0 ] = r;8574 state.ambient[ 1 ] = g;8575 state.ambient[ 2 ] = b;85768577 const hash = state.hash;85788579 if ( hash.sunLength !== sunLength ||8580 hash.directionalLength !== directionalLength ||8581 hash.pointLength !== pointLength ||8582 hash.spotLength !== spotLength ||8583 hash.rectAreaLength !== rectAreaLength ||8584 hash.hemiLength !== hemiLength ||8585 hash.numSunShadows !== numSunShadows ||8586 hash.numDirectionalShadows !== numDirectionalShadows ||8587 hash.numPointShadows !== numPointShadows ||8588 hash.numSpotShadows !== numSpotShadows ||8589 hash.numSpotMaps !== numSpotMaps ||8590 hash.numLightProbes !== numLightProbes ) {85918592 state.sun.length = sunLength;8593 state.directional.length = directionalLength;8594 state.spot.length = spotLength;8595 state.rectArea.length = rectAreaLength;8596 state.point.length = pointLength;8597 state.hemi.length = hemiLength;85988599 state.sunShadow.length = numSunShadows;8600 state.sunShadowMap.length = numSunShadows;8601 state.sunShadowMatrix.length = numSunShadowCascades;8602 state.sunShadowCascade.length = numSunShadowCascades;8603 state.directionalShadow.length = numDirectionalShadows;8604 state.directionalShadowMap.length = numDirectionalShadows;8605 state.directionalShadowMatrix.length = numDirectionalShadows;8606 state.pointShadow.length = numPointShadows;8607 state.pointShadowMap.length = numPointShadows;8608 state.pointShadowMatrix.length = numPointShadows;8609 state.spotShadow.length = numSpotShadows;8610 state.spotShadowMap.length = numSpotShadows;8611 state.spotLightMatrix.length = numSpotShadows + numSpotMaps - numSpotShadowsWithMaps;8612 state.spotLightMap.length = numSpotMaps;8613 state.numSpotLightShadowsWithMaps = numSpotShadowsWithMaps;8614 state.numLightProbes = numLightProbes;86158616 hash.sunLength = sunLength;8617 hash.directionalLength = directionalLength;8618 hash.pointLength = pointLength;8619 hash.spotLength = spotLength;8620 hash.rectAreaLength = rectAreaLength;8621 hash.hemiLength = hemiLength;86228623 hash.numSunShadows = numSunShadows;8624 hash.numDirectionalShadows = numDirectionalShadows;8625 hash.numPointShadows = numPointShadows;8626 hash.numSpotShadows = numSpotShadows;8627 hash.numSpotMaps = numSpotMaps;86288629 hash.numLightProbes = numLightProbes;86308631 state.version = nextVersion ++;86328633 }86348635 }86368637 function setupView( lights, camera ) {86388639 let sunLength = 0;8640 let directionalLength = 0;8641 let pointLength = 0;8642 let spotLength = 0;8643 let rectAreaLength = 0;8644 let hemiLength = 0;86458646 const viewMatrix = camera.matrixWorldInverse;86478648 for ( let i = 0, l = lights.length; i < l; i ++ ) {86498650 const light = lights[ i ];86518652 if ( light.isSunLight ) {86538654 const uniforms = state.sun[ sunLength ];86558656 uniforms.direction.setFromMatrixPosition( light.matrixWorld );8657 uniforms.direction.transformDirection( viewMatrix );86588659 sunLength ++;86608661 } else if ( light.isDirectionalLight ) {86628663 const uniforms = state.directional[ directionalLength ];86648665 uniforms.direction.setFromMatrixPosition( light.matrixWorld );8666 vector3.setFromMatrixPosition( light.target.matrixWorld );8667 uniforms.direction.sub( vector3 );8668 uniforms.direction.transformDirection( viewMatrix );86698670 directionalLength ++;86718672 } else if ( light.isSpotLight ) {86738674 const uniforms = state.spot[ spotLength ];86758676 uniforms.position.setFromMatrixPosition( light.matrixWorld );8677 uniforms.position.applyMatrix4( viewMatrix );86788679 uniforms.direction.setFromMatrixPosition( light.matrixWorld );8680 vector3.setFromMatrixPosition( light.target.matrixWorld );8681 uniforms.direction.sub( vector3 );8682 uniforms.direction.transformDirection( viewMatrix );86838684 spotLength ++;86858686 } else if ( light.isRectAreaLight ) {86878688 const uniforms = state.rectArea[ rectAreaLength ];86898690 uniforms.position.setFromMatrixPosition( light.matrixWorld );8691 uniforms.position.applyMatrix4( viewMatrix );86928693 8694 matrix42.identity();8695 matrix4.copy( light.matrixWorld );8696 matrix4.premultiply( viewMatrix );8697 matrix42.extractRotation( matrix4 );86988699 uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );8700 uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );87018702 uniforms.halfWidth.applyMatrix4( matrix42 );8703 uniforms.halfHeight.applyMatrix4( matrix42 );87048705 rectAreaLength ++;87068707 } else if ( light.isPointLight ) {87088709 const uniforms = state.point[ pointLength ];87108711 uniforms.position.setFromMatrixPosition( light.matrixWorld );8712 uniforms.position.applyMatrix4( viewMatrix );87138714 pointLength ++;87158716 } else if ( light.isHemisphereLight ) {87178718 const uniforms = state.hemi[ hemiLength ];87198720 uniforms.direction.setFromMatrixPosition( light.matrixWorld );8721 uniforms.direction.transformDirection( viewMatrix );87228723 hemiLength ++;87248725 }87268727 }87288729 }87308731 return {8732 setup: setup,8733 setupView: setupView,8734 state: state8735 };87368737}87388739function WebGLRenderState( extensions ) {87408741 const lights = new WebGLLights( extensions );87428743 const lightsArray = [];8744 const shadowsArray = [];8745 const lightProbeGridArray = [];87468747 function init( camera ) {87488749 state.camera = camera;87508751 lightsArray.length = 0;8752 shadowsArray.length = 0;8753 lightProbeGridArray.length = 0;87548755 }87568757 function pushLight( light ) {87588759 if ( light.isLightProbeGrid ) {87608761 lightProbeGridArray.push( light );87628763 } else {87648765 lightsArray.push( light );87668767 }87688769 }87708771 function pushShadow( shadowLight ) {87728773 shadowsArray.push( shadowLight );87748775 }87768777 function setupLights() {87788779 lights.setup( lightsArray );87808781 lightProbeGridArray.sort( ( a, b ) => a.priority - b.priority || a.id - b.id );87828783 }87848785 function setupLightsView( camera ) {87868787 lights.setupView( lightsArray, camera );87888789 }87908791 const state = {8792 lightsArray: lightsArray,8793 shadowsArray: shadowsArray,8794 lightProbeGridArray: lightProbeGridArray,87958796 camera: null,87978798 lights: lights,87998800 transmissionRenderTarget: {},8801 textureUnits: 08802 };88038804 return {8805 init: init,8806 state: state,8807 setupLights: setupLights,8808 setupLightsView: setupLightsView,88098810 pushLight: pushLight,8811 pushShadow: pushShadow8812 };88138814}88158816function WebGLRenderStates( extensions ) {88178818 let renderStates = new WeakMap();88198820 function get( scene, renderCallDepth = 0 ) {88218822 const renderStateArray = renderStates.get( scene );8823 let renderState;88248825 if ( renderStateArray === undefined ) {88268827 renderState = new WebGLRenderState( extensions );8828 renderStates.set( scene, [ renderState ] );88298830 } else {88318832 if ( renderCallDepth >= renderStateArray.length ) {88338834 renderState = new WebGLRenderState( extensions );8835 renderStateArray.push( renderState );88368837 } else {88388839 renderState = renderStateArray[ renderCallDepth ];88408841 }88428843 }88448845 return renderState;88468847 }88488849 function dispose() {88508851 renderStates = new WeakMap();88528853 }88548855 return {8856 get: get,8857 dispose: dispose8858 };88598860}88618862const vertex = "void main() {\n\tgl_Position = vec4( position, 1.0 );\n}";88638864const fragment = "uniform sampler2D shadow_pass;\nuniform vec2 resolution;\nuniform float radius;\nvoid main() {\n\tconst float samples = float( VSM_SAMPLES );\n\tfloat mean = 0.0;\n\tfloat squared_mean = 0.0;\n\tfloat uvStride = samples <= 1.0 ? 0.0 : 2.0 / ( samples - 1.0 );\n\tfloat uvStart = samples <= 1.0 ? 0.0 : - 1.0;\n\tfor ( float i = 0.0; i < samples; i ++ ) {\n\t\tfloat uvOffset = uvStart + i * uvStride;\n\t\t#ifdef HORIZONTAL_PASS\n\t\t\tvec2 distribution = texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( uvOffset, 0.0 ) * radius ) / resolution ).rg;\n\t\t\tmean += distribution.x;\n\t\t\tsquared_mean += distribution.y * distribution.y + distribution.x * distribution.x;\n\t\t#else\n\t\t\tfloat depth = texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, uvOffset ) * radius ) / resolution ).r;\n\t\t\tmean += depth;\n\t\t\tsquared_mean += depth * depth;\n\t\t#endif\n\t}\n\tmean = mean / samples;\n\tsquared_mean = squared_mean / samples;\n\tfloat std_dev = sqrt( max( 0.0, squared_mean - mean * mean ) );\n\tgl_FragColor = vec4( mean, std_dev, 0.0, 1.0 );\n}";88658866const _cubeDirections = [8867 new Vector3( 1, 0, 0 ), new Vector3( -1, 0, 0 ), new Vector3( 0, 1, 0 ),8868 new Vector3( 0, -1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, -1 )8869];88708871const _cubeUps = [8872 new Vector3( 0, -1, 0 ), new Vector3( 0, -1, 0 ), new Vector3( 0, 0, 1 ),8873 new Vector3( 0, 0, -1 ), new Vector3( 0, -1, 0 ), new Vector3( 0, -1, 0 )8874];88758876const _projScreenMatrix = new Matrix4();8877const _lightPositionWorld = new Vector3();8878const _lookTarget = new Vector3();88798880function WebGLShadowMap( renderer, objects, capabilities ) {88818882 let _frustum = new Frustum();88838884 const _shadowMapSize = new Vector2(),8885 _viewportSize = new Vector2(),88868887 _viewport = new Vector4(),88888889 _depthMaterial = new MeshDepthMaterial(),8890 _distanceMaterial = new MeshDistanceMaterial(),88918892 _materialCache = {},88938894 _maxTextureSize = capabilities.maxTextureSize;88958896 const shadowSide = { [ FrontSide ]: BackSide, [ BackSide ]: FrontSide, [ DoubleSide ]: DoubleSide };88978898 const shadowMaterialVertical = new ShaderMaterial( {8899 defines: {8900 VSM_SAMPLES: 88901 },8902 uniforms: {8903 shadow_pass: { value: null },8904 resolution: { value: new Vector2() },8905 radius: { value: 4.0 }8906 },89078908 vertexShader: vertex,8909 fragmentShader: fragment89108911 } );89128913 const shadowMaterialHorizontal = shadowMaterialVertical.clone();8914 shadowMaterialHorizontal.defines.HORIZONTAL_PASS = 1;89158916 const fullScreenTri = new BufferGeometry();8917 fullScreenTri.setAttribute(8918 'position',8919 new BufferAttribute(8920 new Float32Array( [ -1, -1, 0.5, 3, -1, 0.5, -1, 3, 0.5 ] ),8921 38922 )8923 );89248925 const fullScreenMesh = new Mesh( fullScreenTri, shadowMaterialVertical );89268927 const scope = this;89288929 this.enabled = false;89308931 this.autoUpdate = true;8932 this.needsUpdate = false;89338934 this.type = PCFShadowMap;8935 let _previousType = this.type;89368937 this.render = function ( lights, scene, camera ) {89388939 if ( scope.enabled === false ) return;8940 if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;89418942 if ( lights.length === 0 ) return;89438944 if ( this.type === PCFSoftShadowMap ) {89458946 warn( 'WebGLShadowMap: PCFSoftShadowMap has been removed. Using PCFShadowMap instead.' );8947 this.type = PCFShadowMap;89488949 }89508951 const currentRenderTarget = renderer.getRenderTarget();8952 const activeCubeFace = renderer.getActiveCubeFace();8953 const activeMipmapLevel = renderer.getActiveMipmapLevel();89548955 const _state = renderer.state;89568957 8958 _state.setBlending( NoBlending );89598960 if ( _state.buffers.depth.getReversed() === true ) {89618962 _state.buffers.color.setClear( 0, 0, 0, 0 );89638964 } else {89658966 _state.buffers.color.setClear( 1, 1, 1, 1 );89678968 }89698970 _state.buffers.depth.setTest( true );8971 _state.setScissorTest( false );89728973 89748975 const typeChanged = _previousType !== this.type;89768977 8978 8979 if ( typeChanged ) {89808981 scene.traverse( function ( object ) {89828983 if ( object.material ) {89848985 if ( Array.isArray( object.material ) ) {89868987 object.material.forEach( mat => mat.needsUpdate = true );89888989 } else {89908991 object.material.needsUpdate = true;89928993 }89948995 }89968997 } );89988999 }90009001 90029003 for ( let i = 0, il = lights.length; i < il; i ++ ) {90049005 const light = lights[ i ];9006 const shadow = light.shadow;90079008 if ( shadow === undefined ) {90099010 warn( 'WebGLShadowMap:', light, 'has no shadow.' );9011 continue;90129013 }90149015 if ( shadow.autoUpdate === false && shadow.needsUpdate === false ) continue;90169017 _shadowMapSize.copy( shadow.mapSize );90189019 const shadowFrameExtents = shadow.getFrameExtents();90209021 _shadowMapSize.multiply( shadowFrameExtents );90229023 _viewportSize.copy( shadow.mapSize );90249025 if ( _shadowMapSize.x > _maxTextureSize || _shadowMapSize.y > _maxTextureSize ) {90269027 if ( _shadowMapSize.x > _maxTextureSize ) {90289029 _viewportSize.x = Math.floor( _maxTextureSize / shadowFrameExtents.x );9030 _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;9031 shadow.mapSize.x = _viewportSize.x;90329033 }90349035 if ( _shadowMapSize.y > _maxTextureSize ) {90369037 _viewportSize.y = Math.floor( _maxTextureSize / shadowFrameExtents.y );9038 _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;9039 shadow.mapSize.y = _viewportSize.y;90409041 }90429043 }90449045 const reversedDepthBuffer = renderer.state.buffers.depth.getReversed();9046 shadow.camera._reversedDepth = reversedDepthBuffer;90479048 if ( shadow.map === null || typeChanged === true ) {90499050 if ( shadow.map !== null ) {90519052 if ( shadow.map.depthTexture !== null ) {90539054 shadow.map.depthTexture.dispose();9055 shadow.map.depthTexture = null;90569057 }90589059 shadow.map.dispose();90609061 }90629063 if ( this.type === VSMShadowMap ) {90649065 if ( light.isPointLight ) {90669067 warn( 'WebGLShadowMap: VSM shadow maps are not supported for PointLights. Use PCF or BasicShadowMap instead.' );9068 continue;90699070 }90719072 shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, {9073 format: RGFormat,9074 type: HalfFloatType,9075 minFilter: LinearFilter,9076 magFilter: LinearFilter,9077 generateMipmaps: false9078 } );9079 shadow.map.texture.name = light.name + '.shadowMap';90809081 9082 shadow.map.depthTexture = new DepthTexture( _shadowMapSize.x, _shadowMapSize.y, FloatType );9083 shadow.map.depthTexture.name = light.name + '.shadowMapDepth';9084 shadow.map.depthTexture.format = DepthFormat;9085 shadow.map.depthTexture.compareFunction = null; 9086 shadow.map.depthTexture.minFilter = NearestFilter;9087 shadow.map.depthTexture.magFilter = NearestFilter;90889089 } else {90909091 if ( light.isPointLight ) {90929093 shadow.map = new WebGLCubeRenderTarget( _shadowMapSize.x );9094 shadow.map.depthTexture = new CubeDepthTexture( _shadowMapSize.x, UnsignedIntType );90959096 } else {90979098 shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y );9099 shadow.map.depthTexture = new DepthTexture( _shadowMapSize.x, _shadowMapSize.y, UnsignedIntType );91009101 }91029103 shadow.map.depthTexture.name = light.name + '.shadowMap';9104 shadow.map.depthTexture.format = DepthFormat;91059106 if ( this.type === PCFShadowMap ) {91079108 shadow.map.depthTexture.compareFunction = reversedDepthBuffer ? GreaterEqualCompare : LessEqualCompare;9109 shadow.map.depthTexture.minFilter = LinearFilter;9110 shadow.map.depthTexture.magFilter = LinearFilter;91119112 } else {91139114 shadow.map.depthTexture.compareFunction = null;9115 shadow.map.depthTexture.minFilter = NearestFilter;9116 shadow.map.depthTexture.magFilter = NearestFilter;91179118 }91199120 }91219122 shadow.camera.updateProjectionMatrix();91239124 }91259126 if ( shadow.map.isWebGLCubeRenderTarget !== true && ( shadow.map.width !== _shadowMapSize.x || shadow.map.height !== _shadowMapSize.y ) ) {91279128 shadow.map.setSize( _shadowMapSize.x, _shadowMapSize.y );91299130 }91319132 9133 9134 const faceCount = shadow.map.isWebGLCubeRenderTarget ? 6 : shadow.getViewportCount();91359136 if ( light.isPointLight !== true ) shadow.updateMatrices( light, camera );91379138 const layers = ( shadow.camera.layers.mask & 0xFFFFFFFE ) !== 0 ? shadow.camera.layers : camera.layers;91399140 for ( let face = 0; face < faceCount; face ++ ) {91419142 const shadowCamera = shadow.getCamera( face );91439144 if ( light.isPointLight ) {91459146 const camera = shadow.camera;9147 const shadowMatrix = shadow.matrix;91489149 const far = light.distance || camera.far;91509151 if ( far !== camera.far ) {91529153 camera.far = far;9154 camera.updateProjectionMatrix();91559156 }91579158 _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );9159 camera.position.copy( _lightPositionWorld );91609161 _lookTarget.copy( camera.position );9162 _lookTarget.add( _cubeDirections[ face ] );9163 camera.up.copy( _cubeUps[ face ] );9164 camera.lookAt( _lookTarget );9165 camera.updateMatrixWorld();91669167 shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );91689169 _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );9170 shadow._frustum.setFromProjectionMatrix( _projScreenMatrix, camera.coordinateSystem, camera.reversedDepth );91719172 }91739174 9175 if ( shadow.map.isWebGLCubeRenderTarget ) {91769177 renderer.setRenderTarget( shadow.map, face );9178 renderer.clear();91799180 } else {91819182 9183 if ( face === 0 ) {91849185 renderer.setRenderTarget( shadow.map );9186 renderer.clear();91879188 }91899190 const viewport = shadow.getViewport( face );91919192 _viewport.set(9193 _viewportSize.x * viewport.x,9194 _viewportSize.y * viewport.y,9195 _viewportSize.x * viewport.z,9196 _viewportSize.y * viewport.w9197 );91989199 _state.viewport( _viewport );92009201 }92029203 _frustum = shadow.getFrustum( face );92049205 renderObject( scene, camera, shadowCamera, light, layers, this.type );92069207 }92089209 92109211 if ( shadow.isPointLightShadow !== true && this.type === VSMShadowMap ) {92129213 VSMPass( shadow, camera );92149215 }92169217 shadow.needsUpdate = false;92189219 }92209221 _previousType = this.type;92229223 scope.needsUpdate = false;92249225 renderer.setRenderTarget( currentRenderTarget, activeCubeFace, activeMipmapLevel );92269227 };92289229 function VSMPass( shadow, camera ) {92309231 const geometry = objects.update( fullScreenMesh );92329233 if ( shadowMaterialVertical.defines.VSM_SAMPLES !== shadow.blurSamples ) {92349235 shadowMaterialVertical.defines.VSM_SAMPLES = shadow.blurSamples;9236 shadowMaterialHorizontal.defines.VSM_SAMPLES = shadow.blurSamples;92379238 shadowMaterialVertical.needsUpdate = true;9239 shadowMaterialHorizontal.needsUpdate = true;92409241 }92429243 if ( shadow.mapPass === null ) {92449245 shadow.mapPass = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, {9246 format: RGFormat,9247 type: HalfFloatType9248 } );92499250 } else if ( shadow.mapPass.width !== shadow.map.width || shadow.mapPass.height !== shadow.map.height ) {92519252 shadow.mapPass.setSize( shadow.map.width, shadow.map.height );92539254 }92559256 92579258 shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.depthTexture;9259 shadowMaterialVertical.uniforms.resolution.value.set( shadow.map.width, shadow.map.height );9260 shadowMaterialVertical.uniforms.radius.value = shadow.radius;9261 renderer.setRenderTarget( shadow.mapPass );9262 renderer.clear();9263 renderer.renderBufferDirect( camera, null, geometry, shadowMaterialVertical, fullScreenMesh, null );92649265 92669267 shadowMaterialHorizontal.uniforms.shadow_pass.value = shadow.mapPass.texture;9268 shadowMaterialHorizontal.uniforms.resolution.value.set( shadow.map.width, shadow.map.height );9269 shadowMaterialHorizontal.uniforms.radius.value = shadow.radius;9270 renderer.setRenderTarget( shadow.map );9271 renderer.clear();9272 renderer.renderBufferDirect( camera, null, geometry, shadowMaterialHorizontal, fullScreenMesh, null );92739274 }92759276 function getDepthMaterial( object, material, light, type ) {92779278 let result = null;92799280 const customMaterial = ( light.isPointLight === true ) ? object.customDistanceMaterial : object.customDepthMaterial;92819282 if ( customMaterial !== undefined ) {92839284 result = customMaterial;92859286 } else {92879288 result = ( light.isPointLight === true ) ? _distanceMaterial : _depthMaterial;92899290 if ( ( renderer.localClippingEnabled && material.clipShadows === true && Array.isArray( material.clippingPlanes ) && material.clippingPlanes.length !== 0 ) ||9291 ( material.displacementMap && material.displacementScale !== 0 ) ||9292 ( material.alphaMap && material.alphaTest > 0 ) ||9293 ( material.map && material.alphaTest > 0 ) ||9294 ( material.alphaToCoverage === true ) ) {92959296 9297 92989299 const keyA = result.uuid, keyB = material.uuid;93009301 let materialsForVariant = _materialCache[ keyA ];93029303 if ( materialsForVariant === undefined ) {93049305 materialsForVariant = {};9306 _materialCache[ keyA ] = materialsForVariant;93079308 }93099310 let cachedMaterial = materialsForVariant[ keyB ];93119312 if ( cachedMaterial === undefined ) {93139314 cachedMaterial = result.clone();9315 materialsForVariant[ keyB ] = cachedMaterial;9316 material.addEventListener( 'dispose', onMaterialDispose );93179318 }93199320 result = cachedMaterial;93219322 }93239324 }93259326 result.visible = material.visible;9327 result.wireframe = material.wireframe;93289329 if ( type === VSMShadowMap ) {93309331 result.side = ( material.shadowSide !== null ) ? material.shadowSide : material.side;93329333 } else {93349335 result.side = ( material.shadowSide !== null ) ? material.shadowSide : shadowSide[ material.side ];93369337 }93389339 result.alphaMap = material.alphaMap;9340 result.alphaTest = ( material.alphaToCoverage === true ) ? 0.5 : material.alphaTest; 9341 result.map = material.map;93429343 result.clipShadows = material.clipShadows;9344 result.clippingPlanes = material.clippingPlanes;9345 result.clipIntersection = material.clipIntersection;93469347 result.displacementMap = material.displacementMap;9348 result.displacementScale = material.displacementScale;9349 result.displacementBias = material.displacementBias;93509351 result.wireframeLinewidth = material.wireframeLinewidth;9352 result.linewidth = material.linewidth;93539354 if ( light.isPointLight === true && result.isMeshDistanceMaterial === true ) {93559356 const materialProperties = renderer.properties.get( result );9357 materialProperties.light = light;93589359 }93609361 return result;93629363 }93649365 function renderObject( object, camera, shadowCamera, light, layers, type ) {93669367 if ( object.visible === false ) return;93689369 const visible = object.layers.test( layers );93709371 if ( visible && ( object.isMesh || object.isLine || object.isPoints ) ) {93729373 if ( ( object.castShadow || ( object.receiveShadow && type === VSMShadowMap ) ) && ( ! object.frustumCulled || object.intersectsFrustum( _frustum ) ) ) {93749375 object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );93769377 const geometry = objects.update( object );9378 const material = object.material;93799380 if ( Array.isArray( material ) ) {93819382 const groups = geometry.groups;93839384 for ( let k = 0, kl = groups.length; k < kl; k ++ ) {93859386 const group = groups[ k ];9387 const groupMaterial = material[ group.materialIndex ];93889389 if ( groupMaterial && groupMaterial.visible ) {93909391 const depthMaterial = getDepthMaterial( object, groupMaterial, light, type );93929393 object.onBeforeShadow( renderer, object, camera, shadowCamera, geometry, depthMaterial, group );93949395 renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );93969397 object.onAfterShadow( renderer, object, camera, shadowCamera, geometry, depthMaterial, group );93989399 }94009401 }94029403 } else if ( material.visible ) {94049405 const depthMaterial = getDepthMaterial( object, material, light, type );94069407 object.onBeforeShadow( renderer, object, camera, shadowCamera, geometry, depthMaterial, null );94089409 renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );94109411 object.onAfterShadow( renderer, object, camera, shadowCamera, geometry, depthMaterial, null );94129413 }94149415 }94169417 }94189419 const children = object.children;94209421 for ( let i = 0, l = children.length; i < l; i ++ ) {94229423 renderObject( children[ i ], camera, shadowCamera, light, layers, type );94249425 }94269427 }94289429 function onMaterialDispose( event ) {94309431 const material = event.target;94329433 material.removeEventListener( 'dispose', onMaterialDispose );94349435 94369437 for ( const id in _materialCache ) {94389439 const cache = _materialCache[ id ];94409441 const uuid = event.target.uuid;94429443 if ( uuid in cache ) {94449445 const shadowMaterial = cache[ uuid ];9446 shadowMaterial.dispose();9447 delete cache[ uuid ];94489449 }94509451 }94529453 }94549455}94569457function WebGLState( gl, extensions ) {94589459 function ColorBuffer() {94609461 let locked = false;94629463 const color = new Vector4();9464 let currentColorMask = null;9465 const currentColorClear = new Vector4( 0, 0, 0, 0 );94669467 return {94689469 setMask: function ( colorMask ) {94709471 if ( currentColorMask !== colorMask && ! locked ) {94729473 gl.colorMask( colorMask, colorMask, colorMask, colorMask );9474 currentColorMask = colorMask;94759476 }94779478 },94799480 setLocked: function ( lock ) {94819482 locked = lock;94839484 },94859486 setClear: function ( r, g, b, a, premultipliedAlpha ) {94879488 if ( premultipliedAlpha === true ) {94899490 r *= a; g *= a; b *= a;94919492 }94939494 color.set( r, g, b, a );94959496 if ( currentColorClear.equals( color ) === false ) {94979498 gl.clearColor( r, g, b, a );9499 currentColorClear.copy( color );95009501 }95029503 },95049505 reset: function () {95069507 locked = false;95089509 currentColorMask = null;9510 currentColorClear.set( -1, 0, 0, 0 ); 95119512 }95139514 };95159516 }95179518 function DepthBuffer() {95199520 let locked = false;95219522 let currentReversed = false;9523 let currentDepthMask = null;9524 let currentDepthFunc = null;9525 let currentDepthClear = null;95269527 return {95289529 setReversed: function ( reversed ) {95309531 if ( currentReversed !== reversed ) {95329533 const ext = extensions.get( 'EXT_clip_control' );95349535 if ( reversed ) {95369537 ext.clipControlEXT( ext.LOWER_LEFT_EXT, ext.ZERO_TO_ONE_EXT );95389539 } else {95409541 ext.clipControlEXT( ext.LOWER_LEFT_EXT, ext.NEGATIVE_ONE_TO_ONE_EXT );95429543 }95449545 currentReversed = reversed;95469547 const oldDepth = currentDepthClear;9548 currentDepthClear = null;9549 this.setClear( oldDepth );95509551 }95529553 },95549555 getReversed: function () {95569557 return currentReversed;95589559 },95609561 setTest: function ( depthTest ) {95629563 if ( depthTest ) {95649565 enable( gl.DEPTH_TEST );95669567 } else {95689569 disable( gl.DEPTH_TEST );95709571 }95729573 },95749575 setMask: function ( depthMask ) {95769577 if ( currentDepthMask !== depthMask && ! locked ) {95789579 gl.depthMask( depthMask );9580 currentDepthMask = depthMask;95819582 }95839584 },95859586 setFunc: function ( depthFunc ) {95879588 if ( currentReversed ) depthFunc = ReversedDepthFuncs[ depthFunc ];95899590 if ( currentDepthFunc !== depthFunc ) {95919592 switch ( depthFunc ) {95939594 case NeverDepth:95959596 gl.depthFunc( gl.NEVER );9597 break;95989599 case AlwaysDepth:96009601 gl.depthFunc( gl.ALWAYS );9602 break;96039604 case LessDepth:96059606 gl.depthFunc( gl.LESS );9607 break;96089609 case LessEqualDepth:96109611 gl.depthFunc( gl.LEQUAL );9612 break;96139614 case EqualDepth:96159616 gl.depthFunc( gl.EQUAL );9617 break;96189619 case GreaterEqualDepth:96209621 gl.depthFunc( gl.GEQUAL );9622 break;96239624 case GreaterDepth:96259626 gl.depthFunc( gl.GREATER );9627 break;96289629 case NotEqualDepth:96309631 gl.depthFunc( gl.NOTEQUAL );9632 break;96339634 default:96359636 gl.depthFunc( gl.LEQUAL );96379638 }96399640 currentDepthFunc = depthFunc;96419642 }96439644 },96459646 setLocked: function ( lock ) {96479648 locked = lock;96499650 },96519652 setClear: function ( depth ) {96539654 if ( currentDepthClear !== depth ) {96559656 currentDepthClear = depth;96579658 if ( currentReversed ) {96599660 depth = 1 - depth;96619662 }96639664 gl.clearDepth( depth );96659666 }96679668 },96699670 reset: function () {96719672 locked = false;96739674 currentDepthMask = null;9675 currentDepthFunc = null;9676 currentDepthClear = null;9677 currentReversed = false;96789679 }96809681 };96829683 }96849685 function StencilBuffer() {96869687 let locked = false;96889689 let currentStencilMask = null;9690 let currentStencilFunc = null;9691 let currentStencilRef = null;9692 let currentStencilFuncMask = null;9693 let currentStencilFail = null;9694 let currentStencilZFail = null;9695 let currentStencilZPass = null;9696 let currentStencilClear = null;96979698 return {96999700 setTest: function ( stencilTest ) {97019702 if ( ! locked ) {97039704 if ( stencilTest ) {97059706 enable( gl.STENCIL_TEST );97079708 } else {97099710 disable( gl.STENCIL_TEST );97119712 }97139714 }97159716 },97179718 setMask: function ( stencilMask ) {97199720 if ( currentStencilMask !== stencilMask && ! locked ) {97219722 gl.stencilMask( stencilMask );9723 currentStencilMask = stencilMask;97249725 }97269727 },97289729 setFunc: function ( stencilFunc, stencilRef, stencilMask ) {97309731 if ( currentStencilFunc !== stencilFunc ||9732 currentStencilRef !== stencilRef ||9733 currentStencilFuncMask !== stencilMask ) {97349735 gl.stencilFunc( stencilFunc, stencilRef, stencilMask );97369737 currentStencilFunc = stencilFunc;9738 currentStencilRef = stencilRef;9739 currentStencilFuncMask = stencilMask;97409741 }97429743 },97449745 setOp: function ( stencilFail, stencilZFail, stencilZPass ) {97469747 if ( currentStencilFail !== stencilFail ||9748 currentStencilZFail !== stencilZFail ||9749 currentStencilZPass !== stencilZPass ) {97509751 gl.stencilOp( stencilFail, stencilZFail, stencilZPass );97529753 currentStencilFail = stencilFail;9754 currentStencilZFail = stencilZFail;9755 currentStencilZPass = stencilZPass;97569757 }97589759 },97609761 setLocked: function ( lock ) {97629763 locked = lock;97649765 },97669767 setClear: function ( stencil ) {97689769 if ( currentStencilClear !== stencil ) {97709771 gl.clearStencil( stencil );9772 currentStencilClear = stencil;97739774 }97759776 },97779778 reset: function () {97799780 locked = false;97819782 currentStencilMask = null;9783 currentStencilFunc = null;9784 currentStencilRef = null;9785 currentStencilFuncMask = null;9786 currentStencilFail = null;9787 currentStencilZFail = null;9788 currentStencilZPass = null;9789 currentStencilClear = null;97909791 }97929793 };97949795 }97969797 97989799 const colorBuffer = new ColorBuffer();9800 const depthBuffer = new DepthBuffer();9801 const stencilBuffer = new StencilBuffer();98029803 let uboBindings = {};9804 const uboProgramMap = new WeakMap();98059806 let enabledCapabilities = {};9807 let parameters = {};98089809 let currentBoundFramebuffers = {};9810 let currentDrawbuffers = new WeakMap();9811 let defaultDrawbuffers = [];98129813 let currentProgram = null;98149815 let currentBlendingEnabled = false;9816 let currentBlending = null;9817 let currentBlendEquation = null;9818 let currentBlendSrc = null;9819 let currentBlendDst = null;9820 let currentBlendEquationAlpha = null;9821 let currentBlendSrcAlpha = null;9822 let currentBlendDstAlpha = null;9823 let currentBlendColor = new Color( 0, 0, 0 );9824 let currentBlendAlpha = 0;9825 let currentPremultipledAlpha = false;98269827 let currentFlipSided = null;9828 let currentCullFace = null;98299830 let currentLineWidth = null;98319832 let currentPolygonOffsetFactor = null;9833 let currentPolygonOffsetUnits = null;98349835 const maxTextures = gl.getParameter( gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS );98369837 let lineWidthAvailable = false;9838 let version = 0;9839 const glVersion = gl.getParameter( gl.VERSION );98409841 if ( glVersion.indexOf( 'WebGL' ) !== -1 ) {98429843 version = parseFloat( /^WebGL (\d)/.exec( glVersion )[ 1 ] );9844 lineWidthAvailable = ( version >= 1.0 );98459846 } else if ( glVersion.indexOf( 'OpenGL ES' ) !== -1 ) {98479848 version = parseFloat( /^OpenGL ES (\d)/.exec( glVersion )[ 1 ] );9849 lineWidthAvailable = ( version >= 2.0 );98509851 }98529853 let currentTextureSlot = null;9854 let currentBoundTextures = {};98559856 const scissorParam = gl.getParameter( gl.SCISSOR_BOX );9857 const viewportParam = gl.getParameter( gl.VIEWPORT );98589859 const currentScissor = new Vector4().fromArray( scissorParam );9860 const currentViewport = new Vector4().fromArray( viewportParam );98619862 function createTexture( type, target, count, dimensions ) {98639864 const data = new Uint8Array( 4 ); 9865 const texture = gl.createTexture();98669867 gl.bindTexture( type, texture );9868 gl.texParameteri( type, gl.TEXTURE_MIN_FILTER, gl.NEAREST );9869 gl.texParameteri( type, gl.TEXTURE_MAG_FILTER, gl.NEAREST );98709871 for ( let i = 0; i < count; i ++ ) {98729873 if ( type === gl.TEXTURE_3D || type === gl.TEXTURE_2D_ARRAY ) {98749875 gl.texImage3D( target, 0, gl.RGBA, 1, 1, dimensions, 0, gl.RGBA, gl.UNSIGNED_BYTE, data );98769877 } else {98789879 gl.texImage2D( target + i, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, data );98809881 }98829883 }98849885 return texture;98869887 }98889889 const emptyTextures = {};9890 emptyTextures[ gl.TEXTURE_2D ] = createTexture( gl.TEXTURE_2D, gl.TEXTURE_2D, 1 );9891 emptyTextures[ gl.TEXTURE_CUBE_MAP ] = createTexture( gl.TEXTURE_CUBE_MAP, gl.TEXTURE_CUBE_MAP_POSITIVE_X, 6 );9892 emptyTextures[ gl.TEXTURE_2D_ARRAY ] = createTexture( gl.TEXTURE_2D_ARRAY, gl.TEXTURE_2D_ARRAY, 1, 1 );9893 emptyTextures[ gl.TEXTURE_3D ] = createTexture( gl.TEXTURE_3D, gl.TEXTURE_3D, 1, 1 );98949895 98969897 colorBuffer.setClear( 0, 0, 0, 1 );9898 depthBuffer.setClear( 1 );9899 stencilBuffer.setClear( 0 );99009901 enable( gl.DEPTH_TEST );9902 depthBuffer.setFunc( LessEqualDepth );99039904 setFlipSided( false );9905 setCullFace( CullFaceBack );9906 enable( gl.CULL_FACE );99079908 setBlending( NoBlending );99099910 99119912 function enable( id ) {99139914 if ( enabledCapabilities[ id ] !== true ) {99159916 gl.enable( id );9917 enabledCapabilities[ id ] = true;99189919 }99209921 }99229923 function disable( id ) {99249925 if ( enabledCapabilities[ id ] !== false ) {99269927 gl.disable( id );9928 enabledCapabilities[ id ] = false;99299930 }99319932 }99339934 function bindFramebuffer( target, framebuffer ) {99359936 if ( currentBoundFramebuffers[ target ] !== framebuffer ) {99379938 gl.bindFramebuffer( target, framebuffer );99399940 currentBoundFramebuffers[ target ] = framebuffer;99419942 99439944 if ( target === gl.DRAW_FRAMEBUFFER ) {99459946 currentBoundFramebuffers[ gl.FRAMEBUFFER ] = framebuffer;99479948 }99499950 if ( target === gl.FRAMEBUFFER ) {99519952 currentBoundFramebuffers[ gl.DRAW_FRAMEBUFFER ] = framebuffer;99539954 }99559956 return true;99579958 }99599960 return false;99619962 }99639964 function drawBuffers( renderTarget, framebuffer ) {99659966 let drawBuffers = defaultDrawbuffers;99679968 let needsUpdate = false;99699970 if ( renderTarget ) {99719972 drawBuffers = currentDrawbuffers.get( framebuffer );99739974 if ( drawBuffers === undefined ) {99759976 drawBuffers = [];9977 currentDrawbuffers.set( framebuffer, drawBuffers );99789979 }99809981 const textures = renderTarget.textures;99829983 if ( drawBuffers.length !== textures.length || drawBuffers[ 0 ] !== gl.COLOR_ATTACHMENT0 ) {99849985 for ( let i = 0, il = textures.length; i < il; i ++ ) {99869987 drawBuffers[ i ] = gl.COLOR_ATTACHMENT0 + i;99889989 }99909991 drawBuffers.length = textures.length;99929993 needsUpdate = true;99949995 }99969997 } else {99989999 if ( drawBuffers[ 0 ] !== gl.BACK ) {1000010001 drawBuffers[ 0 ] = gl.BACK;1000210003 needsUpdate = true;1000410005 }1000610007 }1000810009 if ( needsUpdate ) {1001010011 gl.drawBuffers( drawBuffers );1001210013 }1001410015 }1001610017 function useProgram( program ) {1001810019 if ( currentProgram !== program ) {1002010021 gl.useProgram( program );1002210023 currentProgram = program;1002410025 return true;1002610027 }1002810029 return false;1003010031 }1003210033 const equationToGL = {10034 [ AddEquation ]: gl.FUNC_ADD,10035 [ SubtractEquation ]: gl.FUNC_SUBTRACT,10036 [ ReverseSubtractEquation ]: gl.FUNC_REVERSE_SUBTRACT10037 };1003810039 equationToGL[ MinEquation ] = gl.MIN;10040 equationToGL[ MaxEquation ] = gl.MAX;1004110042 const factorToGL = {10043 [ ZeroFactor ]: gl.ZERO,10044 [ OneFactor ]: gl.ONE,10045 [ SrcColorFactor ]: gl.SRC_COLOR,10046 [ SrcAlphaFactor ]: gl.SRC_ALPHA,10047 [ SrcAlphaSaturateFactor ]: gl.SRC_ALPHA_SATURATE,10048 [ DstColorFactor ]: gl.DST_COLOR,10049 [ DstAlphaFactor ]: gl.DST_ALPHA,10050 [ OneMinusSrcColorFactor ]: gl.ONE_MINUS_SRC_COLOR,10051 [ OneMinusSrcAlphaFactor ]: gl.ONE_MINUS_SRC_ALPHA,10052 [ OneMinusDstColorFactor ]: gl.ONE_MINUS_DST_COLOR,10053 [ OneMinusDstAlphaFactor ]: gl.ONE_MINUS_DST_ALPHA,10054 [ ConstantColorFactor ]: gl.CONSTANT_COLOR,10055 [ OneMinusConstantColorFactor ]: gl.ONE_MINUS_CONSTANT_COLOR,10056 [ ConstantAlphaFactor ]: gl.CONSTANT_ALPHA,10057 [ OneMinusConstantAlphaFactor ]: gl.ONE_MINUS_CONSTANT_ALPHA10058 };1005910060 function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, blendColor, blendAlpha, premultipliedAlpha ) {1006110062 if ( blending === NoBlending ) {1006310064 if ( currentBlendingEnabled === true ) {1006510066 disable( gl.BLEND );10067 currentBlendingEnabled = false;1006810069 }1007010071 return;1007210073 }1007410075 if ( currentBlendingEnabled === false ) {1007610077 enable( gl.BLEND );10078 currentBlendingEnabled = true;1007910080 }1008110082 if ( blending !== CustomBlending ) {1008310084 if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {1008510086 if ( currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation ) {1008710088 gl.blendEquation( gl.FUNC_ADD );1008910090 currentBlendEquation = AddEquation;10091 currentBlendEquationAlpha = AddEquation;1009210093 }1009410095 if ( premultipliedAlpha ) {1009610097 switch ( blending ) {1009810099 case NormalBlending:10100 gl.blendFuncSeparate( gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );10101 break;1010210103 case AdditiveBlending:10104 gl.blendFunc( gl.ONE, gl.ONE );10105 break;1010610107 case SubtractiveBlending:10108 gl.blendFuncSeparate( gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ZERO, gl.ONE );10109 break;1011010111 case MultiplyBlending:10112 gl.blendFuncSeparate( gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA, gl.ZERO, gl.ONE );10113 break;1011410115 default:10116 error( 'WebGLState: Invalid blending: ', blending );10117 break;1011810119 }1012010121 } else {1012210123 switch ( blending ) {1012410125 case NormalBlending:10126 gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );10127 break;1012810129 case AdditiveBlending:10130 gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE, gl.ONE, gl.ONE );10131 break;1013210133 case SubtractiveBlending:10134 error( 'WebGLState: SubtractiveBlending requires material.premultipliedAlpha = true' );10135 break;1013610137 case MultiplyBlending:10138 error( 'WebGLState: MultiplyBlending requires material.premultipliedAlpha = true' );10139 break;1014010141 default:10142 error( 'WebGLState: Invalid blending: ', blending );10143 break;1014410145 }1014610147 }1014810149 currentBlendSrc = null;10150 currentBlendDst = null;10151 currentBlendSrcAlpha = null;10152 currentBlendDstAlpha = null;10153 currentBlendColor.set( 0, 0, 0 );10154 currentBlendAlpha = 0;1015510156 currentBlending = blending;10157 currentPremultipledAlpha = premultipliedAlpha;1015810159 }1016010161 return;1016210163 }1016410165 1016610167 blendEquationAlpha = blendEquationAlpha || blendEquation;10168 blendSrcAlpha = blendSrcAlpha || blendSrc;10169 blendDstAlpha = blendDstAlpha || blendDst;1017010171 if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {1017210173 gl.blendEquationSeparate( equationToGL[ blendEquation ], equationToGL[ blendEquationAlpha ] );1017410175 currentBlendEquation = blendEquation;10176 currentBlendEquationAlpha = blendEquationAlpha;1017710178 }1017910180 if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {1018110182 gl.blendFuncSeparate( factorToGL[ blendSrc ], factorToGL[ blendDst ], factorToGL[ blendSrcAlpha ], factorToGL[ blendDstAlpha ] );1018310184 currentBlendSrc = blendSrc;10185 currentBlendDst = blendDst;10186 currentBlendSrcAlpha = blendSrcAlpha;10187 currentBlendDstAlpha = blendDstAlpha;1018810189 }1019010191 if ( blendColor.equals( currentBlendColor ) === false || blendAlpha !== currentBlendAlpha ) {1019210193 gl.blendColor( blendColor.r, blendColor.g, blendColor.b, blendAlpha );1019410195 currentBlendColor.copy( blendColor );10196 currentBlendAlpha = blendAlpha;1019710198 }1019910200 currentBlending = blending;10201 currentPremultipledAlpha = false;1020210203 }1020410205 function setMaterial( material, frontFaceCW ) {1020610207 material.side === DoubleSide10208 ? disable( gl.CULL_FACE )10209 : enable( gl.CULL_FACE );1021010211 let flipSided = ( material.side === BackSide );10212 if ( frontFaceCW ) flipSided = ! flipSided;1021310214 setFlipSided( flipSided );1021510216 ( material.blending === NormalBlending && material.transparent === false )10217 ? setBlending( NoBlending )10218 : setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.blendColor, material.blendAlpha, material.premultipliedAlpha );1021910220 depthBuffer.setFunc( material.depthFunc );10221 depthBuffer.setTest( material.depthTest );10222 depthBuffer.setMask( material.depthWrite );10223 colorBuffer.setMask( material.colorWrite );1022410225 const stencilWrite = material.stencilWrite;10226 stencilBuffer.setTest( stencilWrite );10227 if ( stencilWrite ) {1022810229 stencilBuffer.setMask( material.stencilWriteMask );10230 stencilBuffer.setFunc( material.stencilFunc, material.stencilRef, material.stencilFuncMask );10231 stencilBuffer.setOp( material.stencilFail, material.stencilZFail, material.stencilZPass );1023210233 }1023410235 setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );1023610237 material.alphaToCoverage === true10238 ? enable( gl.SAMPLE_ALPHA_TO_COVERAGE )10239 : disable( gl.SAMPLE_ALPHA_TO_COVERAGE );1024010241 }1024210243 1024410245 function setFlipSided( flipSided ) {1024610247 if ( currentFlipSided !== flipSided ) {1024810249 if ( flipSided ) {1025010251 gl.frontFace( gl.CW );1025210253 } else {1025410255 gl.frontFace( gl.CCW );1025610257 }1025810259 currentFlipSided = flipSided;1026010261 }1026210263 }1026410265 function setCullFace( cullFace ) {1026610267 if ( cullFace !== CullFaceNone ) {1026810269 enable( gl.CULL_FACE );1027010271 if ( cullFace !== currentCullFace ) {1027210273 if ( cullFace === CullFaceBack ) {1027410275 gl.cullFace( gl.BACK );1027610277 } else if ( cullFace === CullFaceFront ) {1027810279 gl.cullFace( gl.FRONT );1028010281 } else {1028210283 gl.cullFace( gl.FRONT_AND_BACK );1028410285 }1028610287 }1028810289 } else {1029010291 disable( gl.CULL_FACE );1029210293 }1029410295 currentCullFace = cullFace;1029610297 }1029810299 function setLineWidth( width ) {1030010301 if ( width !== currentLineWidth ) {1030210303 if ( lineWidthAvailable ) gl.lineWidth( width );1030410305 currentLineWidth = width;1030610307 }1030810309 }1031010311 function setPolygonOffset( polygonOffset, factor, units ) {1031210313 if ( polygonOffset ) {1031410315 enable( gl.POLYGON_OFFSET_FILL );1031610317 if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {1031810319 currentPolygonOffsetFactor = factor;10320 currentPolygonOffsetUnits = units;1032110322 if ( depthBuffer.getReversed() ) {1032310324 factor = - factor;10325 units = - units;1032610327 }1032810329 gl.polygonOffset( factor, units );1033010331 }1033210333 } else {1033410335 disable( gl.POLYGON_OFFSET_FILL );1033610337 }1033810339 }1034010341 function setScissorTest( scissorTest ) {1034210343 if ( scissorTest ) {1034410345 enable( gl.SCISSOR_TEST );1034610347 } else {1034810349 disable( gl.SCISSOR_TEST );1035010351 }1035210353 }1035410355 1035610357 function activeTexture( webglSlot ) {1035810359 if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;1036010361 if ( currentTextureSlot !== webglSlot ) {1036210363 gl.activeTexture( webglSlot );10364 currentTextureSlot = webglSlot;1036510366 }1036710368 }1036910370 function bindTexture( webglType, webglTexture, webglSlot ) {1037110372 if ( webglSlot === undefined ) {1037310374 if ( currentTextureSlot === null ) {1037510376 webglSlot = gl.TEXTURE0 + maxTextures - 1;1037710378 } else {1037910380 webglSlot = currentTextureSlot;1038110382 }1038310384 }1038510386 let boundTexture = currentBoundTextures[ webglSlot ];1038710388 if ( boundTexture === undefined ) {1038910390 boundTexture = { type: undefined, texture: undefined };10391 currentBoundTextures[ webglSlot ] = boundTexture;1039210393 }1039410395 if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {1039610397 if ( currentTextureSlot !== webglSlot ) {1039810399 gl.activeTexture( webglSlot );10400 currentTextureSlot = webglSlot;1040110402 }1040310404 gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );1040510406 boundTexture.type = webglType;10407 boundTexture.texture = webglTexture;1040810409 }1041010411 }1041210413 function unbindTexture() {1041410415 const boundTexture = currentBoundTextures[ currentTextureSlot ];1041610417 if ( boundTexture !== undefined && boundTexture.type !== undefined ) {1041810419 gl.bindTexture( boundTexture.type, null );1042010421 boundTexture.type = undefined;10422 boundTexture.texture = undefined;1042310424 }1042510426 }1042710428 function compressedTexImage2D() {1042910430 try {1043110432 gl.compressedTexImage2D( ...arguments );1043310434 } catch ( e ) {1043510436 error( 'WebGLState:', e );1043710438 }1043910440 }1044110442 function compressedTexImage3D() {1044310444 try {1044510446 gl.compressedTexImage3D( ...arguments );1044710448 } catch ( e ) {1044910450 error( 'WebGLState:', e );1045110452 }1045310454 }1045510456 function texSubImage2D() {1045710458 try {1045910460 gl.texSubImage2D( ...arguments );1046110462 } catch ( e ) {1046310464 error( 'WebGLState:', e );1046510466 }1046710468 }1046910470 function texSubImage3D() {1047110472 try {1047310474 gl.texSubImage3D( ...arguments );1047510476 } catch ( e ) {1047710478 error( 'WebGLState:', e );1047910480 }1048110482 }1048310484 function compressedTexSubImage2D() {1048510486 try {1048710488 gl.compressedTexSubImage2D( ...arguments );1048910490 } catch ( e ) {1049110492 error( 'WebGLState:', e );1049310494 }1049510496 }1049710498 function compressedTexSubImage3D() {1049910500 try {1050110502 gl.compressedTexSubImage3D( ...arguments );1050310504 } catch ( e ) {1050510506 error( 'WebGLState:', e );1050710508 }1050910510 }1051110512 function texStorage2D() {1051310514 try {1051510516 gl.texStorage2D( ...arguments );1051710518 } catch ( e ) {1051910520 error( 'WebGLState:', e );1052110522 }1052310524 }1052510526 function texStorage3D() {1052710528 try {1052910530 gl.texStorage3D( ...arguments );1053110532 } catch ( e ) {1053310534 error( 'WebGLState:', e );1053510536 }1053710538 }1053910540 function texImage2D() {1054110542 try {1054310544 gl.texImage2D( ...arguments );1054510546 } catch ( e ) {1054710548 error( 'WebGLState:', e );1054910550 }1055110552 }1055310554 function texImage3D() {1055510556 try {1055710558 gl.texImage3D( ...arguments );1055910560 } catch ( e ) {1056110562 error( 'WebGLState:', e );1056310564 }1056510566 }1056710568 function getParameter( name ) {1056910570 if ( parameters[ name ] !== undefined ) {1057110572 return parameters[ name ];1057310574 } else {1057510576 return gl.getParameter( name );1057710578 }1057910580 }1058110582 function pixelStorei( name, value ) {1058310584 if ( parameters[ name ] !== value ) {1058510586 gl.pixelStorei( name, value );10587 parameters[ name ] = value;1058810589 }1059010591 }1059210593 1059410595 function scissor( scissor ) {1059610597 if ( currentScissor.equals( scissor ) === false ) {1059810599 gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );10600 currentScissor.copy( scissor );1060110602 }1060310604 }1060510606 function viewport( viewport ) {1060710608 if ( currentViewport.equals( viewport ) === false ) {1060910610 gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );10611 currentViewport.copy( viewport );1061210613 }1061410615 }1061610617 function updateUBOMapping( uniformsGroup, program ) {1061810619 let mapping = uboProgramMap.get( program );1062010621 if ( mapping === undefined ) {1062210623 mapping = new WeakMap();1062410625 uboProgramMap.set( program, mapping );1062610627 }1062810629 let blockIndex = mapping.get( uniformsGroup );1063010631 if ( blockIndex === undefined ) {1063210633 blockIndex = gl.getUniformBlockIndex( program, uniformsGroup.name );1063410635 10636 gl.uniformBlockBinding( program, blockIndex, blockIndex );1063710638 mapping.set( uniformsGroup, blockIndex );1063910640 }1064110642 }1064310644 function uniformBlockBinding( uniformsGroup, program, buffer ) {1064510646 const mapping = uboProgramMap.get( program );10647 const blockIndex = mapping.get( uniformsGroup );1064810649 if ( uboBindings[ blockIndex ] !== buffer ) {1065010651 gl.bindBufferBase( gl.UNIFORM_BUFFER, blockIndex, buffer );1065210653 uboBindings[ blockIndex ] = buffer;1065410655 }1065610657 }1065810659 1066010661 function reset() {1066210663 1066410665 gl.disable( gl.BLEND );10666 gl.disable( gl.CULL_FACE );10667 gl.disable( gl.DEPTH_TEST );10668 gl.disable( gl.POLYGON_OFFSET_FILL );10669 gl.disable( gl.SCISSOR_TEST );10670 gl.disable( gl.STENCIL_TEST );10671 gl.disable( gl.SAMPLE_ALPHA_TO_COVERAGE );1067210673 gl.blendEquation( gl.FUNC_ADD );10674 gl.blendFunc( gl.ONE, gl.ZERO );10675 gl.blendFuncSeparate( gl.ONE, gl.ZERO, gl.ONE, gl.ZERO );10676 gl.blendColor( 0, 0, 0, 0 );1067710678 gl.colorMask( true, true, true, true );10679 gl.clearColor( 0, 0, 0, 0 );1068010681 gl.depthMask( true );10682 gl.depthFunc( gl.LESS );1068310684 depthBuffer.setReversed( false );1068510686 gl.clearDepth( 1 );1068710688 gl.stencilMask( 0xffffffff );10689 gl.stencilFunc( gl.ALWAYS, 0, 0xffffffff );10690 gl.stencilOp( gl.KEEP, gl.KEEP, gl.KEEP );10691 gl.clearStencil( 0 );1069210693 gl.cullFace( gl.BACK );10694 gl.frontFace( gl.CCW );1069510696 gl.polygonOffset( 0, 0 );1069710698 gl.activeTexture( gl.TEXTURE0 );1069910700 gl.bindFramebuffer( gl.FRAMEBUFFER, null );10701 gl.bindFramebuffer( gl.DRAW_FRAMEBUFFER, null );10702 gl.bindFramebuffer( gl.READ_FRAMEBUFFER, null );1070310704 gl.useProgram( null );1070510706 gl.lineWidth( 1 );1070710708 gl.scissor( 0, 0, gl.canvas.width, gl.canvas.height );10709 gl.viewport( 0, 0, gl.canvas.width, gl.canvas.height );1071010711 gl.pixelStorei( gl.PACK_ALIGNMENT, 4 );10712 gl.pixelStorei( gl.UNPACK_ALIGNMENT, 4 );10713 gl.pixelStorei( gl.UNPACK_FLIP_Y_WEBGL, false );10714 gl.pixelStorei( gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false );10715 gl.pixelStorei( gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.BROWSER_DEFAULT_WEBGL );10716 gl.pixelStorei( gl.PACK_ROW_LENGTH, 0 );10717 gl.pixelStorei( gl.PACK_SKIP_PIXELS, 0 );10718 gl.pixelStorei( gl.PACK_SKIP_ROWS, 0 );10719 gl.pixelStorei( gl.UNPACK_ROW_LENGTH, 0 );10720 gl.pixelStorei( gl.UNPACK_IMAGE_HEIGHT, 0 );10721 gl.pixelStorei( gl.UNPACK_SKIP_PIXELS, 0 );10722 gl.pixelStorei( gl.UNPACK_SKIP_ROWS, 0 );10723 gl.pixelStorei( gl.UNPACK_SKIP_IMAGES, 0 );1072410725 1072610727 enabledCapabilities = {};10728 parameters = {};1072910730 currentTextureSlot = null;10731 currentBoundTextures = {};1073210733 currentBoundFramebuffers = {};10734 uboBindings = {};10735 currentDrawbuffers = new WeakMap();10736 defaultDrawbuffers = [];1073710738 currentProgram = null;1073910740 currentBlendingEnabled = false;10741 currentBlending = null;10742 currentBlendEquation = null;10743 currentBlendSrc = null;10744 currentBlendDst = null;10745 currentBlendEquationAlpha = null;10746 currentBlendSrcAlpha = null;10747 currentBlendDstAlpha = null;10748 currentBlendColor = new Color( 0, 0, 0 );10749 currentBlendAlpha = 0;10750 currentPremultipledAlpha = false;1075110752 currentFlipSided = null;10753 currentCullFace = null;1075410755 currentLineWidth = null;1075610757 currentPolygonOffsetFactor = null;10758 currentPolygonOffsetUnits = null;1075910760 currentScissor.set( 0, 0, gl.canvas.width, gl.canvas.height );10761 currentViewport.set( 0, 0, gl.canvas.width, gl.canvas.height );1076210763 colorBuffer.reset();10764 depthBuffer.reset();10765 stencilBuffer.reset();1076610767 }1076810769 return {1077010771 buffers: {10772 color: colorBuffer,10773 depth: depthBuffer,10774 stencil: stencilBuffer10775 },1077610777 enable: enable,10778 disable: disable,1077910780 bindFramebuffer: bindFramebuffer,10781 drawBuffers: drawBuffers,1078210783 useProgram: useProgram,1078410785 setBlending: setBlending,10786 setMaterial: setMaterial,1078710788 setFlipSided: setFlipSided,10789 setCullFace: setCullFace,1079010791 setLineWidth: setLineWidth,10792 setPolygonOffset: setPolygonOffset,1079310794 setScissorTest: setScissorTest,1079510796 activeTexture: activeTexture,10797 bindTexture: bindTexture,10798 unbindTexture: unbindTexture,10799 compressedTexImage2D: compressedTexImage2D,10800 compressedTexImage3D: compressedTexImage3D,10801 texImage2D: texImage2D,10802 texImage3D: texImage3D,10803 pixelStorei: pixelStorei,10804 getParameter: getParameter,1080510806 updateUBOMapping: updateUBOMapping,10807 uniformBlockBinding: uniformBlockBinding,1080810809 texStorage2D: texStorage2D,10810 texStorage3D: texStorage3D,10811 texSubImage2D: texSubImage2D,10812 texSubImage3D: texSubImage3D,10813 compressedTexSubImage2D: compressedTexSubImage2D,10814 compressedTexSubImage3D: compressedTexSubImage3D,1081510816 scissor: scissor,10817 viewport: viewport,1081810819 reset: reset1082010821 };1082210823}1082410825function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) {1082610827 const multisampledRTTExt = extensions.has( 'WEBGL_multisampled_render_to_texture' ) ? extensions.get( 'WEBGL_multisampled_render_to_texture' ) : null;10828 const supportsInvalidateFramebuffer = typeof navigator === 'undefined' ? false : /OculusBrowser/g.test( navigator.userAgent );1082910830 const _imageDimensions = new Vector2();10831 const _videoTextures = new WeakMap();10832 const _htmlTextures = new Set();10833 let _canvas;1083410835 const _sources = new WeakMap(); 1083610837 const _tracked = new Set();10838 const _registry = new FinalizationRegistry( ( ref ) => _tracked.delete( ref ) );1083910840 10841 10842 1084310844 let useOffscreenCanvas = false;1084510846 try {1084710848 useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined'10849 && ( new OffscreenCanvas( 1, 1 ).getContext( '2d' ) ) !== null;108501085110852 } catch ( err ) {1085310854 1085510856 }1085710858 function createCanvas( width, height ) {1085910860 1086110862 return useOffscreenCanvas ?10863 new OffscreenCanvas( width, height ) : createElementNS( 'canvas' );1086410865 }1086610867 function resizeImage( image, needsNewCanvas, maxSize ) {1086810869 let scale = 1;1087010871 const dimensions = getDimensions( image );1087210873 1087410875 if ( dimensions.width > maxSize || dimensions.height > maxSize ) {1087610877 scale = maxSize / Math.max( dimensions.width, dimensions.height );1087810879 }1088010881 1088210883 if ( scale < 1 ) {1088410885 1088610887 if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||10888 ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||10889 ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ||10890 ( typeof VideoFrame !== 'undefined' && image instanceof VideoFrame ) ) {1089110892 const width = Math.floor( scale * dimensions.width );10893 const height = Math.floor( scale * dimensions.height );1089410895 if ( _canvas === undefined ) _canvas = createCanvas( width, height );1089610897 1089810899 const canvas = needsNewCanvas ? createCanvas( width, height ) : _canvas;1090010901 canvas.width = width;10902 canvas.height = height;1090310904 const context = canvas.getContext( '2d' );10905 context.drawImage( image, 0, 0, width, height );1090610907 warn( 'WebGLRenderer: Texture has been resized from (' + dimensions.width + 'x' + dimensions.height + ') to (' + width + 'x' + height + ').' );1090810909 return canvas;1091010911 } else {1091210913 if ( 'data' in image ) {1091410915 warn( 'WebGLRenderer: Image in DataTexture is too big (' + dimensions.width + 'x' + dimensions.height + ').' );1091610917 }1091810919 return image;1092010921 }1092210923 }1092410925 return image;1092610927 }1092810929 function textureNeedsGenerateMipmaps( texture ) {1093010931 return texture.generateMipmaps;1093210933 }1093410935 function generateMipmap( target ) {1093610937 _gl.generateMipmap( target );1093810939 }1094010941 function getTargetType( texture ) {1094210943 if ( texture.isWebGLCubeRenderTarget ) return _gl.TEXTURE_CUBE_MAP;10944 if ( texture.isWebGL3DRenderTarget ) return _gl.TEXTURE_3D;10945 if ( texture.isWebGLArrayRenderTarget || texture.isCompressedArrayTexture ) return _gl.TEXTURE_2D_ARRAY;10946 return _gl.TEXTURE_2D;1094710948 }1094910950 function getInternalFormat( internalFormatName, glFormat, glType, normalized, colorSpace, forceLinearTransfer = false ) {1095110952 if ( internalFormatName !== null ) {1095310954 if ( _gl[ internalFormatName ] !== undefined ) return _gl[ internalFormatName ];1095510956 warn( 'WebGLRenderer: Attempt to use non-existing WebGL internal format \'' + internalFormatName + '\'' );1095710958 }1095910960 let ext_texture_norm16;1096110962 if ( normalized ) {1096310964 ext_texture_norm16 = extensions.get( 'EXT_texture_norm16' );1096510966 if ( ! ext_texture_norm16 ) {1096710968 warn( 'WebGLRenderer: Unable to use normalized textures without EXT_texture_norm16 extension' );1096910970 }1097110972 }1097310974 let internalFormat = glFormat;1097510976 if ( glFormat === _gl.RED ) {1097710978 if ( glType === _gl.FLOAT ) internalFormat = _gl.R32F;10979 if ( glType === _gl.HALF_FLOAT ) internalFormat = _gl.R16F;10980 if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = _gl.R8;10981 if ( glType === _gl.UNSIGNED_SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.R16_EXT;10982 if ( glType === _gl.SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.R16_SNORM_EXT;1098310984 }1098510986 if ( glFormat === _gl.RED_INTEGER ) {1098710988 if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = _gl.R8UI;10989 if ( glType === _gl.UNSIGNED_SHORT ) internalFormat = _gl.R16UI;10990 if ( glType === _gl.UNSIGNED_INT ) internalFormat = _gl.R32UI;10991 if ( glType === _gl.BYTE ) internalFormat = _gl.R8I;10992 if ( glType === _gl.SHORT ) internalFormat = _gl.R16I;10993 if ( glType === _gl.INT ) internalFormat = _gl.R32I;1099410995 }1099610997 if ( glFormat === _gl.RG ) {1099810999 if ( glType === _gl.FLOAT ) internalFormat = _gl.RG32F;11000 if ( glType === _gl.HALF_FLOAT ) internalFormat = _gl.RG16F;11001 if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = _gl.RG8;11002 if ( glType === _gl.UNSIGNED_SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.RG16_EXT;11003 if ( glType === _gl.SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.RG16_SNORM_EXT;1100411005 }1100611007 if ( glFormat === _gl.RG_INTEGER ) {1100811009 if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = _gl.RG8UI;11010 if ( glType === _gl.UNSIGNED_SHORT ) internalFormat = _gl.RG16UI;11011 if ( glType === _gl.UNSIGNED_INT ) internalFormat = _gl.RG32UI;11012 if ( glType === _gl.BYTE ) internalFormat = _gl.RG8I;11013 if ( glType === _gl.SHORT ) internalFormat = _gl.RG16I;11014 if ( glType === _gl.INT ) internalFormat = _gl.RG32I;1101511016 }1101711018 if ( glFormat === _gl.RGB_INTEGER ) {1101911020 if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = _gl.RGB8UI;11021 if ( glType === _gl.UNSIGNED_SHORT ) internalFormat = _gl.RGB16UI;11022 if ( glType === _gl.UNSIGNED_INT ) internalFormat = _gl.RGB32UI;11023 if ( glType === _gl.BYTE ) internalFormat = _gl.RGB8I;11024 if ( glType === _gl.SHORT ) internalFormat = _gl.RGB16I;11025 if ( glType === _gl.INT ) internalFormat = _gl.RGB32I;1102611027 }1102811029 if ( glFormat === _gl.RGBA_INTEGER ) {1103011031 if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = _gl.RGBA8UI;11032 if ( glType === _gl.UNSIGNED_SHORT ) internalFormat = _gl.RGBA16UI;11033 if ( glType === _gl.UNSIGNED_INT ) internalFormat = _gl.RGBA32UI;11034 if ( glType === _gl.BYTE ) internalFormat = _gl.RGBA8I;11035 if ( glType === _gl.SHORT ) internalFormat = _gl.RGBA16I;11036 if ( glType === _gl.INT ) internalFormat = _gl.RGBA32I;1103711038 }1103911040 if ( glFormat === _gl.RGB ) {1104111042 if ( glType === _gl.UNSIGNED_SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.RGB16_EXT;11043 if ( glType === _gl.SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.RGB16_SNORM_EXT;11044 if ( glType === _gl.UNSIGNED_INT_5_9_9_9_REV ) internalFormat = _gl.RGB9_E5;11045 if ( glType === _gl.UNSIGNED_INT_10F_11F_11F_REV ) internalFormat = _gl.R11F_G11F_B10F;1104611047 }1104811049 if ( glFormat === _gl.RGBA ) {1105011051 const transfer = forceLinearTransfer ? LinearTransfer : ColorManagement.getTransfer( colorSpace );1105211053 if ( glType === _gl.FLOAT ) internalFormat = _gl.RGBA32F;11054 if ( glType === _gl.HALF_FLOAT ) internalFormat = _gl.RGBA16F;11055 if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = ( transfer === SRGBTransfer ) ? _gl.SRGB8_ALPHA8 : _gl.RGBA8;11056 if ( glType === _gl.UNSIGNED_SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.RGBA16_EXT;11057 if ( glType === _gl.SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.RGBA16_SNORM_EXT;11058 if ( glType === _gl.UNSIGNED_SHORT_4_4_4_4 ) internalFormat = _gl.RGBA4;11059 if ( glType === _gl.UNSIGNED_SHORT_5_5_5_1 ) internalFormat = _gl.RGB5_A1;1106011061 }1106211063 if ( internalFormat === _gl.R16F || internalFormat === _gl.R32F ||11064 internalFormat === _gl.RG16F || internalFormat === _gl.RG32F ||11065 internalFormat === _gl.RGBA16F || internalFormat === _gl.RGBA32F ) {1106611067 extensions.get( 'EXT_color_buffer_float' );1106811069 }1107011071 return internalFormat;1107211073 }1107411075 function getInternalDepthFormat( useStencil, depthType ) {1107611077 let glInternalFormat;11078 if ( useStencil ) {1107911080 if ( depthType === null || depthType === UnsignedIntType || depthType === UnsignedInt248Type ) {1108111082 glInternalFormat = _gl.DEPTH24_STENCIL8;1108311084 } else if ( depthType === FloatType ) {1108511086 glInternalFormat = _gl.DEPTH32F_STENCIL8;1108711088 } else if ( depthType === UnsignedShortType ) {1108911090 glInternalFormat = _gl.DEPTH24_STENCIL8;11091 warn( 'DepthTexture: 16 bit depth attachment is not supported with stencil. Using 24-bit attachment.' );1109211093 }1109411095 } else {1109611097 if ( depthType === null || depthType === UnsignedIntType || depthType === UnsignedInt248Type ) {1109811099 glInternalFormat = _gl.DEPTH_COMPONENT24;1110011101 } else if ( depthType === FloatType ) {1110211103 glInternalFormat = _gl.DEPTH_COMPONENT32F;1110411105 } else if ( depthType === UnsignedShortType ) {1110611107 glInternalFormat = _gl.DEPTH_COMPONENT16;1110811109 }1111011111 }1111211113 return glInternalFormat;1111411115 }1111611117 function getMipLevels( texture, image ) {1111811119 if ( textureNeedsGenerateMipmaps( texture ) === true || ( texture.isFramebufferTexture && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) ) {1112011121 return Math.log2( Math.max( image.width, image.height ) ) + 1;1112211123 } else if ( texture.mipmaps.length > 0 ) {1112411125 1112611127 return texture.mipmaps.length;1112811129 } else if ( texture.isCompressedTexture && Array.isArray( texture.image ) ) {1113011131 return image.mipmaps.length;1113211133 } else {1113411135 1113611137 return 1;1113811139 }1114011141 }1114211143 1114411145 function track( object ) {1114611147 const ref = new WeakRef( object );1114811149 properties.get( object ).__ref = ref;1115011151 _tracked.add( ref );11152 _registry.register( object, ref, ref );1115311154 }1115511156 function untrack( object ) {1115711158 const ref = properties.get( object ).__ref;1115911160 if ( ref === undefined ) return;1116111162 _tracked.delete( ref );11163 _registry.unregister( ref );1116411165 }1116611167 function onTextureDispose( event ) {1116811169 destroyTexture( event.target );1117011171 }1117211173 function onRenderTargetDispose( event ) {1117411175 destroyRenderTarget( event.target );1117611177 }1117811179 function destroyTexture( texture ) {1118011181 texture.removeEventListener( 'dispose', onTextureDispose );1118211183 untrack( texture );11184 deallocateTexture( texture );1118511186 if ( texture.isVideoTexture ) {1118711188 _videoTextures.delete( texture );1118911190 }1119111192 if ( texture.isHTMLTexture ) {1119311194 _htmlTextures.delete( texture );1119511196 }1119711198 }1119911200 function destroyRenderTarget( renderTarget ) {1120111202 renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );1120311204 untrack( renderTarget );11205 deallocateRenderTarget( renderTarget );1120611207 }1120811209 function dispose() {1121011211 for ( const ref of _tracked ) {1121211213 const object = ref.deref();1121411215 if ( object === undefined ) continue;1121611217 if ( object.isRenderTarget === true ) {1121811219 destroyRenderTarget( object );1122011221 } else {1122211223 destroyTexture( object );1122411225 }1122611227 }1122811229 _tracked.clear();11230 _htmlTextures.clear();1123111232 }1123311234 1123511236 function deallocateTexture( texture ) {1123711238 const textureProperties = properties.get( texture );1123911240 if ( textureProperties.__webglInit === undefined ) return;1124111242 1124311244 const source = texture.source;11245 const webglTextures = _sources.get( source );1124611247 if ( webglTextures ) {1124811249 const webglTexture = webglTextures[ textureProperties.__cacheKey ];11250 webglTexture.usedTimes --;1125111252 1125311254 if ( webglTexture.usedTimes === 0 ) {1125511256 deleteTexture( texture );1125711258 }1125911260 1126111262 if ( Object.keys( webglTextures ).length === 0 ) {1126311264 _sources.delete( source );1126511266 }1126711268 }1126911270 properties.remove( texture );1127111272 }1127311274 function deleteTexture( texture ) {1127511276 const textureProperties = properties.get( texture );11277 _gl.deleteTexture( textureProperties.__webglTexture );1127811279 const source = texture.source;11280 const webglTextures = _sources.get( source );11281 delete webglTextures[ textureProperties.__cacheKey ];1128211283 info.memory.textures --;1128411285 }1128611287 function deallocateRenderTarget( renderTarget ) {1128811289 const renderTargetProperties = properties.get( renderTarget );1129011291 if ( renderTargetProperties.__depthDisposeCallback ) renderTargetProperties.__depthDisposeCallback();1129211293 const depthTexture = renderTarget.depthTexture;1129411295 1129611297 if ( depthTexture && depthTexture.renderTarget === renderTarget ) destroyTexture( depthTexture );1129811299 if ( renderTarget.isWebGLCubeRenderTarget ) {1130011301 for ( let i = 0; i < 6; i ++ ) {1130211303 if ( Array.isArray( renderTargetProperties.__webglFramebuffer[ i ] ) ) {1130411305 for ( let level = 0; level < renderTargetProperties.__webglFramebuffer[ i ].length; level ++ ) _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ][ level ] );1130611307 } else {1130811309 _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );1131011311 }1131211313 if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );1131411315 }1131611317 } else {1131811319 if ( Array.isArray( renderTargetProperties.__webglFramebuffer ) ) {1132011321 for ( let level = 0; level < renderTargetProperties.__webglFramebuffer.length; level ++ ) _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ level ] );1132211323 } else {1132411325 _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );1132611327 }1132811329 if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );11330 if ( renderTargetProperties.__webglMultisampledFramebuffer ) _gl.deleteFramebuffer( renderTargetProperties.__webglMultisampledFramebuffer );1133111332 if ( renderTargetProperties.__webglColorRenderbuffer ) {1133311334 for ( let i = 0; i < renderTargetProperties.__webglColorRenderbuffer.length; i ++ ) {1133511336 if ( renderTargetProperties.__webglColorRenderbuffer[ i ] ) _gl.deleteRenderbuffer( renderTargetProperties.__webglColorRenderbuffer[ i ] );1133711338 }1133911340 }1134111342 if ( renderTargetProperties.__webglDepthRenderbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthRenderbuffer );1134311344 }1134511346 const textures = renderTarget.textures;1134711348 for ( let i = 0, il = textures.length; i < il; i ++ ) {1134911350 const attachmentProperties = properties.get( textures[ i ] );1135111352 if ( attachmentProperties.__webglTexture ) {1135311354 _gl.deleteTexture( attachmentProperties.__webglTexture );1135511356 info.memory.textures --;1135711358 }1135911360 properties.remove( textures[ i ] );1136111362 }1136311364 properties.remove( renderTarget );1136511366 }1136711368 1136911370 let textureUnits = 0;1137111372 function resetTextureUnits() {1137311374 textureUnits = 0;1137511376 }1137711378 function getTextureUnits() {1137911380 return textureUnits;1138111382 }1138311384 function setTextureUnits( value ) {1138511386 textureUnits = value;1138711388 }1138911390 function allocateTextureUnit() {1139111392 const textureUnit = textureUnits;1139311394 if ( textureUnit >= capabilities.maxTextures ) {1139511396 warn( 'WebGLTextures: Trying to use ' + ( textureUnit + 1 ) + ' texture units while this GPU supports only ' + capabilities.maxTextures );1139711398 }1139911400 textureUnits += 1;1140111402 return textureUnit;1140311404 }1140511406 function getTextureCacheKey( texture ) {1140711408 const array = [];1140911410 array.push( texture.wrapS );11411 array.push( texture.wrapT );11412 array.push( texture.wrapR || 0 );11413 array.push( texture.magFilter );11414 array.push( texture.minFilter );11415 array.push( texture.anisotropy );11416 array.push( texture.internalFormat );11417 array.push( texture.format );11418 array.push( texture.type );11419 array.push( texture.generateMipmaps );11420 array.push( texture.mipmapsAutoUpdate );11421 array.push( texture.premultiplyAlpha );11422 array.push( texture.flipY );11423 array.push( texture.unpackAlignment );11424 array.push( texture.colorSpace );1142511426 return array.join();1142711428 }1142911430 1143111432 function setTexture2D( texture, slot ) {1143311434 const textureProperties = properties.get( texture );1143511436 if ( texture.isVideoTexture ) updateVideoTexture( texture );1143711438 if ( texture.isRenderTargetTexture === false && texture.isExternalTexture !== true && texture.version > 0 && textureProperties.__version !== texture.version ) {1143911440 const image = texture.image;1144111442 if ( image === null ) {1144311444 warn( 'WebGLRenderer: Texture marked for update but no image data found.' );1144511446 } else if ( image.complete === false ) {1144711448 warn( 'WebGLRenderer: Texture marked for update but image is incomplete' );1144911450 } else {1145111452 uploadTexture( textureProperties, texture, slot );11453 return;1145411455 }1145611457 } else if ( texture.isExternalTexture ) {1145811459 textureProperties.__webglTexture = texture.sourceTexture ? texture.sourceTexture : null;1146011461 }1146211463 state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture, _gl.TEXTURE0 + slot );1146411465 }1146611467 function setTexture2DArray( texture, slot ) {1146811469 const textureProperties = properties.get( texture );1147011471 if ( texture.isRenderTargetTexture === false && texture.version > 0 && textureProperties.__version !== texture.version ) {1147211473 uploadTexture( textureProperties, texture, slot );11474 return;1147511476 } else if ( texture.isExternalTexture ) {1147711478 textureProperties.__webglTexture = texture.sourceTexture ? texture.sourceTexture : null;1147911480 }1148111482 state.bindTexture( _gl.TEXTURE_2D_ARRAY, textureProperties.__webglTexture, _gl.TEXTURE0 + slot );1148311484 }1148511486 function setTexture3D( texture, slot ) {1148711488 const textureProperties = properties.get( texture );1148911490 if ( texture.isRenderTargetTexture === false && texture.version > 0 && textureProperties.__version !== texture.version ) {1149111492 uploadTexture( textureProperties, texture, slot );11493 return;1149411495 }1149611497 state.bindTexture( _gl.TEXTURE_3D, textureProperties.__webglTexture, _gl.TEXTURE0 + slot );1149811499 }1150011501 function setTextureCube( texture, slot ) {1150211503 const textureProperties = properties.get( texture );1150411505 if ( texture.version > 0 && textureProperties.__version !== texture.version ) {1150611507 uploadCubeTexture( textureProperties, texture, slot );11508 return;1150911510 }1151111512 state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture, _gl.TEXTURE0 + slot );1151311514 }1151511516 const wrappingToGL = {11517 [ RepeatWrapping ]: _gl.REPEAT,11518 [ ClampToEdgeWrapping ]: _gl.CLAMP_TO_EDGE,11519 [ MirroredRepeatWrapping ]: _gl.MIRRORED_REPEAT11520 };1152111522 const filterToGL = {11523 [ NearestFilter ]: _gl.NEAREST,11524 [ NearestMipmapNearestFilter ]: _gl.NEAREST_MIPMAP_NEAREST,11525 [ NearestMipmapLinearFilter ]: _gl.NEAREST_MIPMAP_LINEAR,1152611527 [ LinearFilter ]: _gl.LINEAR,11528 [ LinearMipmapNearestFilter ]: _gl.LINEAR_MIPMAP_NEAREST,11529 [ LinearMipmapLinearFilter ]: _gl.LINEAR_MIPMAP_LINEAR11530 };1153111532 const compareToGL = {11533 [ NeverCompare ]: _gl.NEVER,11534 [ AlwaysCompare ]: _gl.ALWAYS,11535 [ LessCompare ]: _gl.LESS,11536 [ LessEqualCompare ]: _gl.LEQUAL,11537 [ EqualCompare ]: _gl.EQUAL,11538 [ GreaterEqualCompare ]: _gl.GEQUAL,11539 [ GreaterCompare ]: _gl.GREATER,11540 [ NotEqualCompare ]: _gl.NOTEQUAL11541 };1154211543 function setTextureParameters( textureType, texture ) {1154411545 if ( texture.type === FloatType && extensions.has( 'OES_texture_float_linear' ) === false &&11546 ( texture.magFilter === LinearFilter || texture.magFilter === LinearMipmapNearestFilter || texture.magFilter === NearestMipmapLinearFilter || texture.magFilter === LinearMipmapLinearFilter ||11547 texture.minFilter === LinearFilter || texture.minFilter === LinearMipmapNearestFilter || texture.minFilter === NearestMipmapLinearFilter || texture.minFilter === LinearMipmapLinearFilter ) ) {1154811549 warn( 'WebGLRenderer: Unable to use linear filtering with floating point textures. OES_texture_float_linear not supported on this device.' );1155011551 }1155211553 _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, wrappingToGL[ texture.wrapS ] );11554 _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, wrappingToGL[ texture.wrapT ] );1155511556 if ( textureType === _gl.TEXTURE_3D || textureType === _gl.TEXTURE_2D_ARRAY ) {1155711558 _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_R, wrappingToGL[ texture.wrapR ] );1155911560 }1156111562 _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterToGL[ texture.magFilter ] );11563 _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterToGL[ texture.minFilter ] );1156411565 if ( texture.compareFunction ) {1156611567 _gl.texParameteri( textureType, _gl.TEXTURE_COMPARE_MODE, _gl.COMPARE_REF_TO_TEXTURE );11568 _gl.texParameteri( textureType, _gl.TEXTURE_COMPARE_FUNC, compareToGL[ texture.compareFunction ] );1156911570 }1157111572 if ( extensions.has( 'EXT_texture_filter_anisotropic' ) === true ) {1157311574 if ( texture.magFilter === NearestFilter ) return;11575 if ( texture.minFilter !== NearestMipmapLinearFilter && texture.minFilter !== LinearMipmapLinearFilter ) return;11576 if ( texture.type === FloatType && extensions.has( 'OES_texture_float_linear' ) === false ) return; 1157711578 if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {1157911580 const extension = extensions.get( 'EXT_texture_filter_anisotropic' );11581 _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) );11582 properties.get( texture ).__currentAnisotropy = texture.anisotropy;1158311584 }1158511586 }1158711588 }1158911590 function initTexture( textureProperties, texture ) {1159111592 let forceUpload = false;1159311594 if ( textureProperties.__webglInit === undefined ) {1159511596 textureProperties.__webglInit = true;1159711598 texture.addEventListener( 'dispose', onTextureDispose );11599 track( texture );1160011601 }1160211603 1160411605 const source = texture.source;11606 let webglTextures = _sources.get( source );1160711608 if ( webglTextures === undefined ) {1160911610 webglTextures = {};11611 _sources.set( source, webglTextures );1161211613 }1161411615 1161611617 const textureCacheKey = getTextureCacheKey( texture );1161811619 if ( textureCacheKey !== textureProperties.__cacheKey ) {1162011621 1162211623 if ( webglTextures[ textureCacheKey ] === undefined ) {1162411625 1162611627 webglTextures[ textureCacheKey ] = {11628 texture: _gl.createTexture(),11629 usedTimes: 011630 };1163111632 info.memory.textures ++;1163311634 11635 1163611637 forceUpload = true;1163811639 }1164011641 webglTextures[ textureCacheKey ].usedTimes ++;1164211643 11644 1164511646 const webglTexture = webglTextures[ textureProperties.__cacheKey ];1164711648 if ( webglTexture !== undefined ) {1164911650 webglTextures[ textureProperties.__cacheKey ].usedTimes --;1165111652 if ( webglTexture.usedTimes === 0 ) {1165311654 deleteTexture( texture );1165511656 }1165711658 }1165911660 1166111662 textureProperties.__cacheKey = textureCacheKey;11663 textureProperties.__webglTexture = webglTextures[ textureCacheKey ].texture;1166411665 }1166611667 return forceUpload;1166811669 }1167011671 function getRow( index, rowLength, componentStride ) {1167211673 return Math.floor( Math.floor( index / componentStride ) / rowLength );1167411675 }1167611677 function updateTexture( texture, image, glFormat, glType ) {1167811679 const componentStride = 4; 1168011681 const updateRanges = texture.updateRanges;1168211683 if ( updateRanges.length === 0 ) {1168411685 state.texSubImage2D( _gl.TEXTURE_2D, 0, 0, 0, image.width, image.height, glFormat, glType, image.data );1168611687 } else {1168811689 11690 11691 11692 11693 11694 11695 11696 1169711698 updateRanges.sort( ( a, b ) => a.start - b.start );1169911700 11701 11702 11703 11704 11705 let mergeIndex = 0;1170611707 for ( let i = 1; i < updateRanges.length; i ++ ) {1170811709 const previousRange = updateRanges[ mergeIndex ];11710 const range = updateRanges[ i ];1171111712 11713 const previousEnd = previousRange.start + previousRange.count;11714 const currentRow = getRow( range.start, image.width, componentStride );11715 const previousRow = getRow( previousRange.start, image.width, componentStride );1171611717 11718 11719 if (11720 range.start <= previousEnd + 1 &&11721 currentRow === previousRow &&11722 getRow( range.start + range.count - 1, image.width, componentStride ) === currentRow 11723 ) {1172411725 previousRange.count = Math.max(11726 previousRange.count,11727 range.start + range.count - previousRange.start11728 );1172911730 } else {1173111732 ++ mergeIndex;11733 updateRanges[ mergeIndex ] = range;1173411735 }117361173711738 }1173911740 11741 updateRanges.length = mergeIndex + 1;1174211743 const currentUnpackRowLen = state.getParameter( _gl.UNPACK_ROW_LENGTH );11744 const currentUnpackSkipPixels = state.getParameter( _gl.UNPACK_SKIP_PIXELS );11745 const currentUnpackSkipRows = state.getParameter( _gl.UNPACK_SKIP_ROWS );1174611747 state.pixelStorei( _gl.UNPACK_ROW_LENGTH, image.width );1174811749 for ( let i = 0, l = updateRanges.length; i < l; i ++ ) {1175011751 const range = updateRanges[ i ];1175211753 const pixelStart = Math.floor( range.start / componentStride );11754 const pixelCount = Math.ceil( range.count / componentStride );1175511756 const x = pixelStart % image.width;11757 const y = Math.floor( pixelStart / image.width );1175811759 11760 const width = pixelCount;11761 const height = 1;1176211763 state.pixelStorei( _gl.UNPACK_SKIP_PIXELS, x );11764 state.pixelStorei( _gl.UNPACK_SKIP_ROWS, y );1176511766 state.texSubImage2D( _gl.TEXTURE_2D, 0, x, y, width, height, glFormat, glType, image.data );1176711768 }1176911770 texture.clearUpdateRanges();1177111772 state.pixelStorei( _gl.UNPACK_ROW_LENGTH, currentUnpackRowLen );11773 state.pixelStorei( _gl.UNPACK_SKIP_PIXELS, currentUnpackSkipPixels );11774 state.pixelStorei( _gl.UNPACK_SKIP_ROWS, currentUnpackSkipRows );1177511776 }1177711778 }1177911780 function uploadTexture( textureProperties, texture, slot ) {1178111782 let textureType = _gl.TEXTURE_2D;1178311784 if ( texture.isDataArrayTexture || texture.isCompressedArrayTexture ) textureType = _gl.TEXTURE_2D_ARRAY;11785 if ( texture.isData3DTexture ) textureType = _gl.TEXTURE_3D;1178611787 const forceUpload = initTexture( textureProperties, texture );11788 const source = texture.source;1178911790 state.bindTexture( textureType, textureProperties.__webglTexture, _gl.TEXTURE0 + slot );1179111792 const sourceProperties = properties.get( source );1179311794 if ( source.version !== sourceProperties.__version || forceUpload === true ) {1179511796 state.activeTexture( _gl.TEXTURE0 + slot );1179711798 const isImageBitmap = ( typeof ImageBitmap !== 'undefined' && texture.image instanceof ImageBitmap );1179911800 if ( isImageBitmap === false ) {1180111802 const workingPrimaries = ColorManagement.getPrimaries( ColorManagement.workingColorSpace );11803 const texturePrimaries = texture.colorSpace === NoColorSpace ? null : ColorManagement.getPrimaries( texture.colorSpace );11804 const unpackConversion = texture.colorSpace === NoColorSpace || workingPrimaries === texturePrimaries ? _gl.NONE : _gl.BROWSER_DEFAULT_WEBGL;1180511806 state.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );11807 state.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );11808 state.pixelStorei( _gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, unpackConversion );1180911810 }1181111812 state.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );1181311814 let image = resizeImage( texture.image, false, capabilities.maxTextureSize );11815 image = verifyColorSpace( texture, image );1181611817 const glFormat = utils.convert( texture.format, texture.colorSpace );1181811819 const glType = utils.convert( texture.type );11820 let glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.normalized, texture.colorSpace, texture.isVideoTexture );1182111822 setTextureParameters( textureType, texture );1182311824 let mipmap;11825 const mipmaps = texture.mipmaps;1182611827 const useTexStorage = ( texture.isVideoTexture !== true );11828 const allocateMemory = ( sourceProperties.__version === undefined ) || ( forceUpload === true );11829 const dataReady = source.dataReady;11830 const levels = getMipLevels( texture, image );1183111832 if ( texture.isDepthTexture ) {1183311834 glInternalFormat = getInternalDepthFormat( texture.format === DepthStencilFormat, texture.type );1183511836 1183711838 if ( allocateMemory ) {1183911840 if ( useTexStorage ) {1184111842 state.texStorage2D( _gl.TEXTURE_2D, 1, glInternalFormat, image.width, image.height );1184311844 } else {1184511846 state.texImage2D( _gl.TEXTURE_2D, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null );1184711848 }1184911850 }1185111852 } else if ( texture.isDataTexture ) {1185311854 11855 11856 1185711858 if ( mipmaps.length > 0 ) {1185911860 if ( useTexStorage && allocateMemory ) {1186111862 state.texStorage2D( _gl.TEXTURE_2D, levels, glInternalFormat, mipmaps[ 0 ].width, mipmaps[ 0 ].height );1186311864 }1186511866 for ( let i = 0, il = mipmaps.length; i < il; i ++ ) {1186711868 mipmap = mipmaps[ i ];1186911870 if ( useTexStorage ) {1187111872 if ( dataReady ) {1187311874 state.texSubImage2D( _gl.TEXTURE_2D, i, 0, 0, mipmap.width, mipmap.height, glFormat, glType, mipmap.data );1187511876 }1187711878 } else {1187911880 state.texImage2D( _gl.TEXTURE_2D, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );1188111882 }1188311884 }1188511886 texture.generateMipmaps = false;1188711888 } else {1188911890 if ( useTexStorage ) {1189111892 if ( allocateMemory ) {1189311894 state.texStorage2D( _gl.TEXTURE_2D, levels, glInternalFormat, image.width, image.height );1189511896 }1189711898 if ( dataReady ) {1189911900 updateTexture( texture, image, glFormat, glType );1190111902 }1190311904 } else {1190511906 state.texImage2D( _gl.TEXTURE_2D, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data );1190711908 }1190911910 }1191111912 } else if ( texture.isCompressedTexture ) {1191311914 if ( texture.isCompressedArrayTexture ) {1191511916 if ( useTexStorage && allocateMemory ) {1191711918 state.texStorage3D( _gl.TEXTURE_2D_ARRAY, levels, glInternalFormat, mipmaps[ 0 ].width, mipmaps[ 0 ].height, image.depth );1191911920 }1192111922 for ( let i = 0, il = mipmaps.length; i < il; i ++ ) {1192311924 mipmap = mipmaps[ i ];1192511926 if ( texture.format !== RGBAFormat ) {1192711928 if ( glFormat !== null ) {1192911930 if ( useTexStorage ) {1193111932 if ( dataReady ) {1193311934 if ( texture.layerUpdates.size > 0 ) {1193511936 const layerByteLength = getByteLength( mipmap.width, mipmap.height, texture.format, texture.type );1193711938 for ( const layerIndex of texture.layerUpdates ) {1193911940 const layerData = mipmap.data.subarray(11941 layerIndex * layerByteLength / mipmap.data.BYTES_PER_ELEMENT,11942 ( layerIndex + 1 ) * layerByteLength / mipmap.data.BYTES_PER_ELEMENT11943 );11944 state.compressedTexSubImage3D( _gl.TEXTURE_2D_ARRAY, i, 0, 0, layerIndex, mipmap.width, mipmap.height, 1, glFormat, layerData );1194511946 }1194711948 } else {1194911950 state.compressedTexSubImage3D( _gl.TEXTURE_2D_ARRAY, i, 0, 0, 0, mipmap.width, mipmap.height, image.depth, glFormat, mipmap.data );1195111952 }1195311954 }1195511956 } else {1195711958 state.compressedTexImage3D( _gl.TEXTURE_2D_ARRAY, i, glInternalFormat, mipmap.width, mipmap.height, image.depth, 0, mipmap.data, 0, 0 );1195911960 }1196111962 } else {1196311964 warn( 'WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()' );1196511966 }1196711968 } else {1196911970 if ( useTexStorage ) {1197111972 if ( dataReady ) {1197311974 state.texSubImage3D( _gl.TEXTURE_2D_ARRAY, i, 0, 0, 0, mipmap.width, mipmap.height, image.depth, glFormat, glType, mipmap.data );1197511976 }1197711978 } else {1197911980 state.texImage3D( _gl.TEXTURE_2D_ARRAY, i, glInternalFormat, mipmap.width, mipmap.height, image.depth, 0, glFormat, glType, mipmap.data );1198111982 }1198311984 }1198511986 }1198711988 if ( texture.layerUpdates.size > 0 ) texture.clearLayerUpdates();1198911990 } else {1199111992 if ( useTexStorage && allocateMemory ) {1199311994 state.texStorage2D( _gl.TEXTURE_2D, levels, glInternalFormat, mipmaps[ 0 ].width, mipmaps[ 0 ].height );1199511996 }1199711998 for ( let i = 0, il = mipmaps.length; i < il; i ++ ) {1199912000 mipmap = mipmaps[ i ];1200112002 if ( texture.format !== RGBAFormat ) {1200312004 if ( glFormat !== null ) {1200512006 if ( useTexStorage ) {1200712008 if ( dataReady ) {1200912010 state.compressedTexSubImage2D( _gl.TEXTURE_2D, i, 0, 0, mipmap.width, mipmap.height, glFormat, mipmap.data );1201112012 }1201312014 } else {1201512016 state.compressedTexImage2D( _gl.TEXTURE_2D, i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );1201712018 }1201912020 } else {1202112022 warn( 'WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()' );1202312024 }1202512026 } else {1202712028 if ( useTexStorage ) {1202912030 if ( dataReady ) {1203112032 state.texSubImage2D( _gl.TEXTURE_2D, i, 0, 0, mipmap.width, mipmap.height, glFormat, glType, mipmap.data );1203312034 }1203512036 } else {1203712038 state.texImage2D( _gl.TEXTURE_2D, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );1203912040 }1204112042 }1204312044 }1204512046 }1204712048 } else if ( texture.isDataArrayTexture ) {1204912050 if ( useTexStorage ) {1205112052 if ( allocateMemory ) {1205312054 state.texStorage3D( _gl.TEXTURE_2D_ARRAY, levels, glInternalFormat, image.width, image.height, image.depth );1205512056 }1205712058 if ( dataReady ) {1205912060 if ( texture.layerUpdates.size > 0 ) {1206112062 const layerByteLength = getByteLength( image.width, image.height, texture.format, texture.type );1206312064 for ( const layerIndex of texture.layerUpdates ) {1206512066 const layerData = image.data.subarray(12067 layerIndex * layerByteLength / image.data.BYTES_PER_ELEMENT,12068 ( layerIndex + 1 ) * layerByteLength / image.data.BYTES_PER_ELEMENT12069 );12070 state.texSubImage3D( _gl.TEXTURE_2D_ARRAY, 0, 0, 0, layerIndex, image.width, image.height, 1, glFormat, glType, layerData );1207112072 }1207312074 texture.clearLayerUpdates();1207512076 } else {1207712078 state.texSubImage3D( _gl.TEXTURE_2D_ARRAY, 0, 0, 0, 0, image.width, image.height, image.depth, glFormat, glType, image.data );1207912080 }1208112082 }1208312084 } else {1208512086 state.texImage3D( _gl.TEXTURE_2D_ARRAY, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );1208712088 }1208912090 } else if ( texture.isData3DTexture ) {1209112092 if ( useTexStorage ) {1209312094 if ( allocateMemory ) {1209512096 state.texStorage3D( _gl.TEXTURE_3D, levels, glInternalFormat, image.width, image.height, image.depth );1209712098 }1209912100 if ( dataReady ) {1210112102 state.texSubImage3D( _gl.TEXTURE_3D, 0, 0, 0, 0, image.width, image.height, image.depth, glFormat, glType, image.data );1210312104 }1210512106 } else {1210712108 state.texImage3D( _gl.TEXTURE_3D, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );1210912110 }1211112112 } else if ( texture.isFramebufferTexture ) {1211312114 if ( allocateMemory ) {1211512116 if ( useTexStorage ) {1211712118 state.texStorage2D( _gl.TEXTURE_2D, levels, glInternalFormat, image.width, image.height );1211912120 } else {1212112122 let width = image.width, height = image.height;1212312124 for ( let i = 0; i < levels; i ++ ) {1212512126 state.texImage2D( _gl.TEXTURE_2D, i, glInternalFormat, width, height, 0, glFormat, glType, null );1212712128 width >>= 1;12129 height >>= 1;1213012131 }1213212133 }1213412135 }1213612137 } else if ( texture.isHTMLTexture ) {1213812139 if ( 'texElementImage2D' in _gl ) {1214012141 const canvas = _gl.canvas;1214212143 12144 if ( ! canvas.hasAttribute( 'layoutsubtree' ) ) {1214512146 canvas.setAttribute( 'layoutsubtree', 'true' );1214712148 }1214912150 if ( image.parentNode !== canvas ) {1215112152 canvas.appendChild( image );1215312154 12155 _htmlTextures.add( texture );1215612157 canvas.onpaint = ( event ) => {1215812159 const changed = event.changedElements;1216012161 for ( const t of _htmlTextures ) {1216212163 if ( changed.includes( t.image ) ) {1216412165 t.needsUpdate = true;1216612167 }1216812169 }1217012171 };1217212173 canvas.requestPaint();12174 return;1217512176 }1217712178 if ( _gl.texElementImage2D.length === 3 ) {1217912180 1218112182 _gl.texElementImage2D( _gl.TEXTURE_2D, _gl.RGBA8, image );1218312184 } else {1218512186 1218712188 const level = 0;12189 const internalFormat = _gl.RGBA;12190 const srcFormat = _gl.RGBA;12191 const srcType = _gl.UNSIGNED_BYTE;1219212193 _gl.texElementImage2D( _gl.TEXTURE_2D, level, internalFormat, srcFormat, srcType, image );1219412195 }1219612197 _gl.texParameteri( _gl.TEXTURE_2D, _gl.TEXTURE_MIN_FILTER, _gl.LINEAR );12198 _gl.texParameteri( _gl.TEXTURE_2D, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );12199 _gl.texParameteri( _gl.TEXTURE_2D, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );1220012201 }1220212203 } else {1220412205 1220612207 12208 12209 1221012211 if ( mipmaps.length > 0 ) {1221212213 if ( useTexStorage && allocateMemory ) {1221412215 const dimensions = getDimensions( mipmaps[ 0 ] );1221612217 state.texStorage2D( _gl.TEXTURE_2D, levels, glInternalFormat, dimensions.width, dimensions.height );1221812219 }1222012221 for ( let i = 0, il = mipmaps.length; i < il; i ++ ) {1222212223 mipmap = mipmaps[ i ];1222412225 if ( useTexStorage ) {1222612227 if ( dataReady ) {1222812229 state.texSubImage2D( _gl.TEXTURE_2D, i, 0, 0, glFormat, glType, mipmap );1223012231 }1223212233 } else {1223412235 state.texImage2D( _gl.TEXTURE_2D, i, glInternalFormat, glFormat, glType, mipmap );1223612237 }1223812239 }1224012241 texture.generateMipmaps = false;1224212243 } else {1224412245 if ( useTexStorage ) {1224612247 if ( allocateMemory ) {1224812249 const dimensions = getDimensions( image );1225012251 state.texStorage2D( _gl.TEXTURE_2D, levels, glInternalFormat, dimensions.width, dimensions.height );1225212253 }1225412255 if ( dataReady ) {1225612257 state.texSubImage2D( _gl.TEXTURE_2D, 0, 0, 0, glFormat, glType, image );1225812259 }1226012261 } else {1226212263 state.texImage2D( _gl.TEXTURE_2D, 0, glInternalFormat, glFormat, glType, image );1226412265 }1226612267 }1226812269 }1227012271 if ( textureNeedsGenerateMipmaps( texture ) && texture.mipmapsAutoUpdate === true ) {1227212273 generateMipmap( textureType );1227412275 }1227612277 sourceProperties.__version = source.version;1227812279 if ( texture.onUpdate ) texture.onUpdate( texture );1228012281 }1228212283 textureProperties.__version = texture.version;1228412285 }1228612287 function uploadCubeTexture( textureProperties, texture, slot ) {1228812289 if ( texture.image.length !== 6 ) return;1229012291 const forceUpload = initTexture( textureProperties, texture );12292 const source = texture.source;1229312294 state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture, _gl.TEXTURE0 + slot );1229512296 const sourceProperties = properties.get( source );1229712298 if ( source.version !== sourceProperties.__version || forceUpload === true ) {1229912300 state.activeTexture( _gl.TEXTURE0 + slot );1230112302 const workingPrimaries = ColorManagement.getPrimaries( ColorManagement.workingColorSpace );12303 const texturePrimaries = texture.colorSpace === NoColorSpace ? null : ColorManagement.getPrimaries( texture.colorSpace );12304 const unpackConversion = texture.colorSpace === NoColorSpace || workingPrimaries === texturePrimaries ? _gl.NONE : _gl.BROWSER_DEFAULT_WEBGL;1230512306 state.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );12307 state.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );12308 state.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );12309 state.pixelStorei( _gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, unpackConversion );1231012311 const isCompressed = ( texture.isCompressedTexture || texture.image[ 0 ].isCompressedTexture );12312 const isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );1231312314 const cubeImage = [];1231512316 for ( let i = 0; i < 6; i ++ ) {1231712318 if ( ! isCompressed && ! isDataTexture ) {1231912320 cubeImage[ i ] = resizeImage( texture.image[ i ], true, capabilities.maxCubemapSize );1232112322 } else {1232312324 cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];1232512326 }1232712328 cubeImage[ i ] = verifyColorSpace( texture, cubeImage[ i ] );1232912330 }1233112332 const image = cubeImage[ 0 ],12333 glFormat = utils.convert( texture.format, texture.colorSpace ),12334 glType = utils.convert( texture.type );1233512336 let glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.normalized, texture.colorSpace );1233712338 const useTexStorage = ( texture.isVideoTexture !== true );12339 const allocateMemory = ( sourceProperties.__version === undefined ) || ( forceUpload === true );12340 const dataReady = source.dataReady;12341 let levels = getMipLevels( texture, image );1234212343 setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture );1234412345 let mipmaps;1234612347 if ( texture.isDepthTexture ) {1234812349 glInternalFormat = getInternalDepthFormat( texture.format === DepthStencilFormat, texture.type );1235012351 1235212353 if ( allocateMemory ) {1235412355 if ( useTexStorage ) {1235612357 state.texStorage2D( _gl.TEXTURE_CUBE_MAP, 1, glInternalFormat, image.width, image.height );1235812359 } else {1236012361 for ( let i = 0; i < 6; i ++ ) {1236212363 state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null );1236412365 }1236612367 }1236812369 }1237012371 } else if ( isCompressed ) {1237212373 if ( useTexStorage && allocateMemory ) {1237412375 state.texStorage2D( _gl.TEXTURE_CUBE_MAP, levels, glInternalFormat, image.width, image.height );1237612377 }1237812379 for ( let i = 0; i < 6; i ++ ) {1238012381 mipmaps = cubeImage[ i ].mipmaps;1238212383 for ( let j = 0; j < mipmaps.length; j ++ ) {1238412385 const mipmap = mipmaps[ j ];1238612387 if ( texture.format !== RGBAFormat ) {1238812389 if ( glFormat !== null ) {1239012391 if ( useTexStorage ) {1239212393 if ( dataReady ) {1239412395 state.compressedTexSubImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, 0, 0, mipmap.width, mipmap.height, glFormat, mipmap.data );1239612397 }1239812399 } else {1240012401 state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );1240212403 }1240412405 } else {1240612407 warn( 'WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()' );1240812409 }1241012411 } else {1241212413 if ( useTexStorage ) {1241412415 if ( dataReady ) {1241612417 state.texSubImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, 0, 0, mipmap.width, mipmap.height, glFormat, glType, mipmap.data );1241812419 }1242012421 } else {1242212423 state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );1242412425 }1242612427 }1242812429 }1243012431 }1243212433 } else {1243412435 mipmaps = texture.mipmaps;1243612437 if ( useTexStorage && allocateMemory ) {1243812439 12440 12441 1244212443 if ( mipmaps.length > 0 ) levels ++;1244412445 const dimensions = getDimensions( cubeImage[ 0 ] );1244612447 state.texStorage2D( _gl.TEXTURE_CUBE_MAP, levels, glInternalFormat, dimensions.width, dimensions.height );1244812449 }1245012451 for ( let i = 0; i < 6; i ++ ) {1245212453 if ( isDataTexture ) {1245412455 if ( useTexStorage ) {1245612457 if ( dataReady ) {1245812459 state.texSubImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, 0, 0, cubeImage[ i ].width, cubeImage[ i ].height, glFormat, glType, cubeImage[ i ].data );1246012461 }1246212463 } else {1246412465 state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glInternalFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );1246612467 }1246812469 for ( let j = 0; j < mipmaps.length; j ++ ) {1247012471 const mipmap = mipmaps[ j ];12472 const mipmapImage = mipmap.image[ i ].image;1247312474 if ( useTexStorage ) {1247512476 if ( dataReady ) {1247712478 state.texSubImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j + 1, 0, 0, mipmapImage.width, mipmapImage.height, glFormat, glType, mipmapImage.data );1247912480 }1248112482 } else {1248312484 state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data );1248512486 }1248712488 }1248912490 } else {1249112492 if ( useTexStorage ) {1249312494 if ( dataReady ) {1249512496 state.texSubImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, 0, 0, glFormat, glType, cubeImage[ i ] );1249712498 }1249912500 } else {1250112502 state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glInternalFormat, glFormat, glType, cubeImage[ i ] );1250312504 }1250512506 for ( let j = 0; j < mipmaps.length; j ++ ) {1250712508 const mipmap = mipmaps[ j ];1250912510 if ( useTexStorage ) {1251112512 if ( dataReady ) {1251312514 state.texSubImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j + 1, 0, 0, glFormat, glType, mipmap.image[ i ] );1251512516 }1251712518 } else {1251912520 state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j + 1, glInternalFormat, glFormat, glType, mipmap.image[ i ] );1252112522 }1252312524 }1252512526 }1252712528 }1252912530 }1253112532 if ( textureNeedsGenerateMipmaps( texture ) && texture.mipmapsAutoUpdate === true ) {1253312534 12535 generateMipmap( _gl.TEXTURE_CUBE_MAP );1253612537 }1253812539 sourceProperties.__version = source.version;1254012541 if ( texture.onUpdate ) texture.onUpdate( texture );1254212543 }1254412545 textureProperties.__version = texture.version;1254612547 }1254812549 1255012551 12552 function setupFrameBufferTexture( framebuffer, renderTarget, texture, attachment, textureTarget, level ) {1255312554 const glFormat = utils.convert( texture.format, texture.colorSpace );12555 const glType = utils.convert( texture.type );12556 const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.normalized, texture.colorSpace );12557 const renderTargetProperties = properties.get( renderTarget );12558 const textureProperties = properties.get( texture );1255912560 textureProperties.__renderTarget = renderTarget;1256112562 if ( ! renderTargetProperties.__hasExternalTextures ) {1256312564 const width = Math.max( 1, renderTarget.width >> level );12565 const height = Math.max( 1, renderTarget.height >> level );1256612567 if ( textureTarget === _gl.TEXTURE_3D || textureTarget === _gl.TEXTURE_2D_ARRAY ) {1256812569 state.texImage3D( textureTarget, level, glInternalFormat, width, height, renderTarget.depth, 0, glFormat, glType, null );1257012571 } else {1257212573 state.texImage2D( textureTarget, level, glInternalFormat, width, height, 0, glFormat, glType, null );1257412575 }1257612577 }1257812579 state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );1258012581 if ( useMultisampledRTT( renderTarget ) ) {1258212583 multisampledRTTExt.framebufferTexture2DMultisampleEXT( _gl.FRAMEBUFFER, attachment, textureTarget, textureProperties.__webglTexture, 0, getRenderTargetSamples( renderTarget ) );1258412585 } else if ( textureTarget === _gl.TEXTURE_2D || ( textureTarget >= _gl.TEXTURE_CUBE_MAP_POSITIVE_X && textureTarget <= _gl.TEXTURE_CUBE_MAP_NEGATIVE_Z ) ) { 1258612587 _gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, textureProperties.__webglTexture, level );1258812589 }1259012591 state.bindFramebuffer( _gl.FRAMEBUFFER, null );1259212593 }1259412595 12596 function setupRenderBufferStorage( renderbuffer, renderTarget, useMultisample ) {1259712598 _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );1259912600 if ( renderTarget.depthBuffer ) {1260112602 12603 const depthTexture = renderTarget.depthTexture;12604 const depthType = depthTexture && depthTexture.isDepthTexture ? depthTexture.type : null;12605 const glInternalFormat = getInternalDepthFormat( renderTarget.stencilBuffer, depthType );12606 const glAttachmentType = renderTarget.stencilBuffer ? _gl.DEPTH_STENCIL_ATTACHMENT : _gl.DEPTH_ATTACHMENT;1260712608 12609 if ( useMultisampledRTT( renderTarget ) ) {1261012611 multisampledRTTExt.renderbufferStorageMultisampleEXT( _gl.RENDERBUFFER, getRenderTargetSamples( renderTarget ), glInternalFormat, renderTarget.width, renderTarget.height );1261212613 } else if ( useMultisample ) {1261412615 _gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, getRenderTargetSamples( renderTarget ), glInternalFormat, renderTarget.width, renderTarget.height );1261612617 } else {1261812619 _gl.renderbufferStorage( _gl.RENDERBUFFER, glInternalFormat, renderTarget.width, renderTarget.height );1262012621 }1262212623 _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, glAttachmentType, _gl.RENDERBUFFER, renderbuffer );1262412625 } else {1262612627 const textures = renderTarget.textures;1262812629 for ( let i = 0; i < textures.length; i ++ ) {1263012631 const texture = textures[ i ];1263212633 const glFormat = utils.convert( texture.format, texture.colorSpace );12634 const glType = utils.convert( texture.type );12635 const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.normalized, texture.colorSpace );1263612637 if ( useMultisampledRTT( renderTarget ) ) {1263812639 multisampledRTTExt.renderbufferStorageMultisampleEXT( _gl.RENDERBUFFER, getRenderTargetSamples( renderTarget ), glInternalFormat, renderTarget.width, renderTarget.height );1264012641 } else if ( useMultisample ) {1264212643 _gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, getRenderTargetSamples( renderTarget ), glInternalFormat, renderTarget.width, renderTarget.height );1264412645 } else {1264612647 _gl.renderbufferStorage( _gl.RENDERBUFFER, glInternalFormat, renderTarget.width, renderTarget.height );1264812649 }1265012651 }1265212653 }1265412655 _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );1265612657 }1265812659 12660 function setupDepthTexture( framebuffer, renderTarget, cubeFace ) {1266112662 const isCube = ( renderTarget.isWebGLCubeRenderTarget === true );1266312664 state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );1266512666 if ( ! ( renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture ) ) {1266712668 throw new Error( 'THREE.WebGLTextures: renderTarget.depthTexture must be an instance of THREE.DepthTexture.' );1266912670 }1267112672 const textureProperties = properties.get( renderTarget.depthTexture );12673 textureProperties.__renderTarget = renderTarget;1267412675 12676 const image = isCube ? renderTarget.depthTexture.image[ 0 ] : renderTarget.depthTexture.image;1267712678 if ( ! textureProperties.__webglTexture ||12679 image.width !== renderTarget.width ||12680 image.height !== renderTarget.height ) {1268112682 image.width = renderTarget.width;12683 image.height = renderTarget.height;12684 renderTarget.depthTexture.needsUpdate = true;1268512686 }1268712688 if ( isCube ) {1268912690 setTextureCube( renderTarget.depthTexture, 0 );1269112692 } else {1269312694 setTexture2D( renderTarget.depthTexture, 0 );1269512696 }1269712698 const webglDepthTexture = textureProperties.__webglTexture;12699 const samples = getRenderTargetSamples( renderTarget );1270012701 const glTextureType = isCube ? _gl.TEXTURE_CUBE_MAP_POSITIVE_X + cubeFace : _gl.TEXTURE_2D;12702 const glAttachmentType = renderTarget.depthTexture.format === DepthStencilFormat ? _gl.DEPTH_STENCIL_ATTACHMENT : _gl.DEPTH_ATTACHMENT;1270312704 if ( renderTarget.depthTexture.format === DepthFormat ) {1270512706 if ( useMultisampledRTT( renderTarget ) ) {1270712708 multisampledRTTExt.framebufferTexture2DMultisampleEXT( _gl.FRAMEBUFFER, glAttachmentType, glTextureType, webglDepthTexture, 0, samples );1270912710 } else {1271112712 _gl.framebufferTexture2D( _gl.FRAMEBUFFER, glAttachmentType, glTextureType, webglDepthTexture, 0 );1271312714 }1271512716 } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {1271712718 if ( useMultisampledRTT( renderTarget ) ) {1271912720 multisampledRTTExt.framebufferTexture2DMultisampleEXT( _gl.FRAMEBUFFER, glAttachmentType, glTextureType, webglDepthTexture, 0, samples );1272112722 } else {1272312724 _gl.framebufferTexture2D( _gl.FRAMEBUFFER, glAttachmentType, glTextureType, webglDepthTexture, 0 );1272512726 }1272712728 } else {1272912730 throw new Error( 'THREE.WebGLTextures: Unknown depthTexture format.' );1273112732 }1273312734 }1273512736 12737 function setupDepthRenderbuffer( renderTarget ) {1273812739 const renderTargetProperties = properties.get( renderTarget );12740 const isCube = ( renderTarget.isWebGLCubeRenderTarget === true );1274112742 12743 if ( renderTargetProperties.__boundDepthTexture !== renderTarget.depthTexture ) {1274412745 12746 const depthTexture = renderTarget.depthTexture;12747 if ( renderTargetProperties.__depthDisposeCallback ) {1274812749 renderTargetProperties.__depthDisposeCallback();1275012751 }1275212753 12754 if ( depthTexture ) {1275512756 const disposeEvent = () => {1275712758 delete renderTargetProperties.__boundDepthTexture;12759 delete renderTargetProperties.__depthDisposeCallback;12760 depthTexture.removeEventListener( 'dispose', disposeEvent );1276112762 };1276312764 depthTexture.addEventListener( 'dispose', disposeEvent );12765 renderTargetProperties.__depthDisposeCallback = disposeEvent;1276612767 }1276812769 renderTargetProperties.__boundDepthTexture = depthTexture;1277012771 }1277212773 if ( renderTarget.depthTexture && ! renderTargetProperties.__autoAllocateDepthBuffer ) {1277412775 if ( isCube ) {1277612777 12778 for ( let i = 0; i < 6; i ++ ) {1277912780 setupDepthTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, i );1278112782 }1278312784 } else {1278512786 const mipmaps = renderTarget.texture.mipmaps;1278712788 if ( mipmaps.length > 0 ) {1278912790 setupDepthTexture( renderTargetProperties.__webglFramebuffer[ 0 ], renderTarget, 0 );1279112792 } else {1279312794 setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget, 0 );1279512796 }1279712798 }1279912800 } else {1280112802 if ( isCube ) {1280312804 renderTargetProperties.__webglDepthbuffer = [];1280512806 for ( let i = 0; i < 6; i ++ ) {1280712808 state.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer[ i ] );1280912810 if ( renderTargetProperties.__webglDepthbuffer[ i ] === undefined ) {1281112812 renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();12813 setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget, false );1281412815 } else {1281612817 12818 const glAttachmentType = renderTarget.stencilBuffer ? _gl.DEPTH_STENCIL_ATTACHMENT : _gl.DEPTH_ATTACHMENT;12819 const renderbuffer = renderTargetProperties.__webglDepthbuffer[ i ];12820 _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );12821 _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, glAttachmentType, _gl.RENDERBUFFER, renderbuffer );1282212823 }1282412825 }1282612827 } else {1282812829 const mipmaps = renderTarget.texture.mipmaps;1283012831 if ( mipmaps.length > 0 ) {1283212833 state.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer[ 0 ] );1283412835 } else {1283612837 state.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer );1283812839 }1284012841 if ( renderTargetProperties.__webglDepthbuffer === undefined ) {1284212843 renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();12844 setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget, false );1284512846 } else {1284712848 12849 const glAttachmentType = renderTarget.stencilBuffer ? _gl.DEPTH_STENCIL_ATTACHMENT : _gl.DEPTH_ATTACHMENT;12850 const renderbuffer = renderTargetProperties.__webglDepthbuffer;12851 _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );12852 _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, glAttachmentType, _gl.RENDERBUFFER, renderbuffer );1285312854 }1285512856 }1285712858 }1285912860 state.bindFramebuffer( _gl.FRAMEBUFFER, null );1286112862 }1286312864 12865 function rebindTextures( renderTarget, colorTexture, depthTexture ) {1286612867 const renderTargetProperties = properties.get( renderTarget );1286812869 if ( colorTexture !== undefined ) {1287012871 setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, renderTarget.texture, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D, 0 );1287212873 }1287412875 if ( depthTexture !== undefined ) {1287612877 setupDepthRenderbuffer( renderTarget );1287812879 }1288012881 }1288212883 12884 function setupRenderTarget( renderTarget ) {1288512886 const texture = renderTarget.texture;1288712888 const renderTargetProperties = properties.get( renderTarget );12889 const textureProperties = properties.get( texture );1289012891 renderTarget.addEventListener( 'dispose', onRenderTargetDispose );12892 track( renderTarget );1289312894 const textures = renderTarget.textures;1289512896 const isCube = ( renderTarget.isWebGLCubeRenderTarget === true );12897 const isMultipleRenderTargets = ( textures.length > 1 );1289812899 if ( ! isMultipleRenderTargets ) {1290012901 if ( textureProperties.__webglTexture === undefined ) {1290212903 textureProperties.__webglTexture = _gl.createTexture();1290412905 }1290612907 textureProperties.__version = texture.version;12908 info.memory.textures ++;1290912910 }1291112912 1291312914 if ( isCube ) {1291512916 renderTargetProperties.__webglFramebuffer = [];1291712918 for ( let i = 0; i < 6; i ++ ) {1291912920 if ( texture.mipmaps.length > 0 ) {1292112922 renderTargetProperties.__webglFramebuffer[ i ] = [];1292312924 for ( let level = 0; level < texture.mipmaps.length; level ++ ) {1292512926 renderTargetProperties.__webglFramebuffer[ i ][ level ] = _gl.createFramebuffer();1292712928 }1292912930 } else {1293112932 renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();1293312934 }1293512936 }1293712938 } else {1293912940 if ( texture.mipmaps.length > 0 ) {1294112942 renderTargetProperties.__webglFramebuffer = [];1294312944 for ( let level = 0; level < texture.mipmaps.length; level ++ ) {1294512946 renderTargetProperties.__webglFramebuffer[ level ] = _gl.createFramebuffer();1294712948 }1294912950 } else {1295112952 renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();1295312954 }1295512956 if ( isMultipleRenderTargets ) {1295712958 for ( let i = 0, il = textures.length; i < il; i ++ ) {1295912960 const attachmentProperties = properties.get( textures[ i ] );1296112962 if ( attachmentProperties.__webglTexture === undefined ) {1296312964 attachmentProperties.__webglTexture = _gl.createTexture();1296512966 info.memory.textures ++;1296712968 }1296912970 }1297112972 }1297312974 if ( ( renderTarget.samples > 0 ) && useMultisampledRTT( renderTarget ) === false ) {1297512976 renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();12977 renderTargetProperties.__webglColorRenderbuffer = [];1297812979 state.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer );1298012981 for ( let i = 0; i < textures.length; i ++ ) {1298212983 const texture = textures[ i ];12984 renderTargetProperties.__webglColorRenderbuffer[ i ] = _gl.createRenderbuffer();1298512986 _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderTargetProperties.__webglColorRenderbuffer[ i ] );1298712988 const glFormat = utils.convert( texture.format, texture.colorSpace );12989 const glType = utils.convert( texture.type );12990 const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.normalized, texture.colorSpace, renderTarget.isXRRenderTarget === true );12991 const samples = getRenderTargetSamples( renderTarget );12992 _gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height );1299312994 _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0 + i, _gl.RENDERBUFFER, renderTargetProperties.__webglColorRenderbuffer[ i ] );1299512996 }1299712998 _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );1299913000 if ( renderTarget.depthBuffer ) {1300113002 renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();13003 setupRenderBufferStorage( renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true );1300413005 }1300613007 state.bindFramebuffer( _gl.FRAMEBUFFER, null );1300813009 }1301013011 }1301213013 1301413015 if ( isCube ) {1301613017 state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );13018 setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture );1301913020 for ( let i = 0; i < 6; i ++ ) {1302113022 if ( texture.mipmaps.length > 0 ) {1302313024 for ( let level = 0; level < texture.mipmaps.length; level ++ ) {1302513026 setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ][ level ], renderTarget, texture, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, level );1302713028 }1302913030 } else {1303113032 setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, texture, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0 );1303313034 }1303513036 }1303713038 if ( textureNeedsGenerateMipmaps( texture ) ) {1303913040 generateMipmap( _gl.TEXTURE_CUBE_MAP );1304113042 } else if ( texture.mipmaps.length > 0 ) {1304313044 13045 _gl.texParameteri( _gl.TEXTURE_CUBE_MAP, _gl.TEXTURE_MAX_LEVEL, texture.mipmaps.length - 1 );1304613047 }1304813049 state.unbindTexture();1305013051 } else if ( isMultipleRenderTargets ) {1305213053 for ( let i = 0, il = textures.length; i < il; i ++ ) {1305413055 const attachment = textures[ i ];13056 const attachmentProperties = properties.get( attachment );1305713058 let glTextureType = _gl.TEXTURE_2D;1305913060 if ( renderTarget.isWebGL3DRenderTarget || renderTarget.isWebGLArrayRenderTarget ) {1306113062 glTextureType = renderTarget.isWebGL3DRenderTarget ? _gl.TEXTURE_3D : _gl.TEXTURE_2D_ARRAY;1306313064 }1306513066 state.bindTexture( glTextureType, attachmentProperties.__webglTexture );13067 setTextureParameters( glTextureType, attachment );13068 setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, attachment, _gl.COLOR_ATTACHMENT0 + i, glTextureType, 0 );1306913070 if ( textureNeedsGenerateMipmaps( attachment ) ) {1307113072 generateMipmap( glTextureType );1307313074 }1307513076 }1307713078 state.unbindTexture();1307913080 } else {1308113082 let glTextureType = _gl.TEXTURE_2D;1308313084 if ( renderTarget.isWebGL3DRenderTarget || renderTarget.isWebGLArrayRenderTarget ) {1308513086 glTextureType = renderTarget.isWebGL3DRenderTarget ? _gl.TEXTURE_3D : _gl.TEXTURE_2D_ARRAY;1308713088 }1308913090 state.bindTexture( glTextureType, textureProperties.__webglTexture );13091 setTextureParameters( glTextureType, texture );1309213093 if ( texture.mipmaps.length > 0 ) {1309413095 for ( let level = 0; level < texture.mipmaps.length; level ++ ) {1309613097 setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ level ], renderTarget, texture, _gl.COLOR_ATTACHMENT0, glTextureType, level );1309813099 }1310013101 } else {1310213103 setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, texture, _gl.COLOR_ATTACHMENT0, glTextureType, 0 );1310413105 }1310613107 if ( textureNeedsGenerateMipmaps( texture ) ) {1310813109 generateMipmap( glTextureType );1311013111 } else if ( texture.mipmaps.length > 0 ) {1311213113 13114 _gl.texParameteri( glTextureType, _gl.TEXTURE_MAX_LEVEL, texture.mipmaps.length - 1 );1311513116 }1311713118 state.unbindTexture();1311913120 }1312113122 1312313124 if ( renderTarget.depthBuffer ) {1312513126 setupDepthRenderbuffer( renderTarget );1312713128 }1312913130 }1313113132 function updateRenderTargetMipmap( renderTarget ) {1313313134 const textures = renderTarget.textures;1313513136 for ( let i = 0, il = textures.length; i < il; i ++ ) {1313713138 const texture = textures[ i ];1313913140 if ( textureNeedsGenerateMipmaps( texture ) && texture.mipmapsAutoUpdate === true ) {1314113142 const targetType = getTargetType( renderTarget );13143 const webglTexture = properties.get( texture ).__webglTexture;1314413145 state.bindTexture( targetType, webglTexture );13146 generateMipmap( targetType );13147 state.unbindTexture();1314813149 }1315013151 }1315213153 }1315413155 const invalidationArrayRead = [];1315613157 function updateMultisampleRenderTarget( renderTarget ) {1315813159 if ( renderTarget.samples > 0 ) {1316013161 if ( useMultisampledRTT( renderTarget ) === false ) {1316213163 const textures = renderTarget.textures;13164 const width = renderTarget.width;13165 const height = renderTarget.height;13166 let mask = _gl.COLOR_BUFFER_BIT;13167 const depthStyle = renderTarget.stencilBuffer ? _gl.DEPTH_STENCIL_ATTACHMENT : _gl.DEPTH_ATTACHMENT;13168 const renderTargetProperties = properties.get( renderTarget );13169 const isMultipleRenderTargets = ( textures.length > 1 );1317013171 13172 if ( isMultipleRenderTargets ) {1317313174 for ( let i = 0; i < textures.length; i ++ ) {1317513176 state.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer );13177 _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0 + i, _gl.RENDERBUFFER, null );1317813179 state.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer );13180 _gl.framebufferTexture2D( _gl.DRAW_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0 + i, _gl.TEXTURE_2D, null, 0 );1318113182 }1318313184 }1318513186 state.bindFramebuffer( _gl.READ_FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer );1318713188 const mipmaps = renderTarget.texture.mipmaps;1318913190 if ( mipmaps.length > 0 ) {1319113192 state.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, renderTargetProperties.__webglFramebuffer[ 0 ] );1319313194 } else {1319513196 state.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, renderTargetProperties.__webglFramebuffer );1319713198 }1319913200 for ( let i = 0; i < textures.length; i ++ ) {1320113202 if ( renderTarget.resolveDepthBuffer ) {1320313204 if ( renderTarget.depthBuffer ) mask |= _gl.DEPTH_BUFFER_BIT;1320513206 1320713208 if ( renderTarget.stencilBuffer && renderTarget.resolveStencilBuffer ) mask |= _gl.STENCIL_BUFFER_BIT;1320913210 }1321113212 if ( isMultipleRenderTargets ) {1321313214 _gl.framebufferRenderbuffer( _gl.READ_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.RENDERBUFFER, renderTargetProperties.__webglColorRenderbuffer[ i ] );1321513216 const webglTexture = properties.get( textures[ i ] ).__webglTexture;13217 _gl.framebufferTexture2D( _gl.DRAW_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D, webglTexture, 0 );1321813219 }1322013221 _gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, _gl.NEAREST );1322213223 if ( supportsInvalidateFramebuffer === true ) {1322413225 invalidationArrayRead.length = 0;1322613227 invalidationArrayRead.push( _gl.COLOR_ATTACHMENT0 + i );1322813229 if ( renderTarget.depthBuffer && renderTarget.storeMultisampledDepthBuffer === false ) {1323013231 invalidationArrayRead.push( depthStyle );1323213233 }1323413235 _gl.invalidateFramebuffer( _gl.READ_FRAMEBUFFER, invalidationArrayRead );1323613237 }1323813239 }1324013241 state.bindFramebuffer( _gl.READ_FRAMEBUFFER, null );13242 state.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, null );1324313244 13245 if ( isMultipleRenderTargets ) {1324613247 for ( let i = 0; i < textures.length; i ++ ) {1324813249 state.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer );13250 _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0 + i, _gl.RENDERBUFFER, renderTargetProperties.__webglColorRenderbuffer[ i ] );1325113252 const webglTexture = properties.get( textures[ i ] ).__webglTexture;1325313254 state.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer );13255 _gl.framebufferTexture2D( _gl.DRAW_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0 + i, _gl.TEXTURE_2D, webglTexture, 0 );1325613257 }1325813259 }1326013261 state.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer );1326213263 } else {1326413265 if ( renderTarget.depthBuffer && renderTarget.storeMultisampledDepthBuffer === false && supportsInvalidateFramebuffer ) {1326613267 const depthStyle = renderTarget.stencilBuffer ? _gl.DEPTH_STENCIL_ATTACHMENT : _gl.DEPTH_ATTACHMENT;1326813269 _gl.invalidateFramebuffer( _gl.DRAW_FRAMEBUFFER, [ depthStyle ] );1327013271 }1327213273 }1327413275 }1327613277 }1327813279 function getRenderTargetSamples( renderTarget ) {1328013281 return Math.min( capabilities.maxSamples, renderTarget.samples );1328213283 }1328413285 function useMultisampledRTT( renderTarget ) {1328613287 const renderTargetProperties = properties.get( renderTarget );1328813289 return renderTarget.samples > 0 && extensions.has( 'WEBGL_multisampled_render_to_texture' ) === true && renderTargetProperties.__useRenderToTexture !== false;1329013291 }1329213293 function updateVideoTexture( texture ) {1329413295 const frame = info.render.frame;1329613297 1329813299 if ( _videoTextures.get( texture ) !== frame ) {1330013301 _videoTextures.set( texture, frame );13302 texture.update();1330313304 }1330513306 }1330713308 function verifyColorSpace( texture, image ) {1330913310 const colorSpace = texture.colorSpace;13311 const format = texture.format;13312 const type = texture.type;1331313314 if ( texture.isCompressedTexture === true || texture.isVideoTexture === true ) return image;1331513316 if ( colorSpace !== LinearSRGBColorSpace && colorSpace !== NoColorSpace ) {1331713318 1331913320 if ( ColorManagement.getTransfer( colorSpace ) === SRGBTransfer ) {1332113322 1332313324 if ( format !== RGBAFormat || type !== UnsignedByteType ) {1332513326 warn( 'WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType.' );1332713328 }1332913330 } else {1333113332 error( 'WebGLTextures: Unsupported texture color space:', colorSpace );1333313334 }1333513336 }1333713338 return image;1333913340 }1334113342 function getDimensions( image ) {1334313344 if ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) {1334513346 1334713348 _imageDimensions.width = image.naturalWidth || image.width;13349 _imageDimensions.height = image.naturalHeight || image.height;1335013351 } else if ( typeof VideoFrame !== 'undefined' && image instanceof VideoFrame ) {1335213353 _imageDimensions.width = image.displayWidth;13354 _imageDimensions.height = image.displayHeight;1335513356 } else {1335713358 _imageDimensions.width = image.width;13359 _imageDimensions.height = image.height;1336013361 }1336213363 return _imageDimensions;1336413365 }1336613367 1336813369 this.allocateTextureUnit = allocateTextureUnit;13370 this.resetTextureUnits = resetTextureUnits;13371 this.getTextureUnits = getTextureUnits;13372 this.setTextureUnits = setTextureUnits;1337313374 this.setTexture2D = setTexture2D;13375 this.setTexture2DArray = setTexture2DArray;13376 this.setTexture3D = setTexture3D;13377 this.setTextureCube = setTextureCube;13378 this.rebindTextures = rebindTextures;13379 this.setupRenderTarget = setupRenderTarget;13380 this.updateRenderTargetMipmap = updateRenderTargetMipmap;13381 this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;13382 this.setupDepthRenderbuffer = setupDepthRenderbuffer;13383 this.setupFrameBufferTexture = setupFrameBufferTexture;13384 this.useMultisampledRTT = useMultisampledRTT;13385 this.dispose = dispose;1338613387}1338813389function WebGLUtils( gl, extensions ) {1339013391 function convert( p, colorSpace = NoColorSpace ) {1339213393 let extension;1339413395 const transfer = ColorManagement.getTransfer( colorSpace );1339613397 if ( p === UnsignedByteType ) return gl.UNSIGNED_BYTE;13398 if ( p === UnsignedShort4444Type ) return gl.UNSIGNED_SHORT_4_4_4_4;13399 if ( p === UnsignedShort5551Type ) return gl.UNSIGNED_SHORT_5_5_5_1;13400 if ( p === UnsignedInt5999Type ) return gl.UNSIGNED_INT_5_9_9_9_REV;13401 if ( p === UnsignedInt101111Type ) return gl.UNSIGNED_INT_10F_11F_11F_REV;1340213403 if ( p === ByteType ) return gl.BYTE;13404 if ( p === ShortType ) return gl.SHORT;13405 if ( p === UnsignedShortType ) return gl.UNSIGNED_SHORT;13406 if ( p === IntType ) return gl.INT;13407 if ( p === UnsignedIntType ) return gl.UNSIGNED_INT;13408 if ( p === FloatType ) return gl.FLOAT;13409 if ( p === HalfFloatType ) return gl.HALF_FLOAT;1341013411 if ( p === AlphaFormat ) return gl.ALPHA;13412 if ( p === RGBFormat ) return gl.RGB;13413 if ( p === RGBAFormat ) return gl.RGBA;13414 if ( p === DepthFormat ) return gl.DEPTH_COMPONENT;13415 if ( p === DepthStencilFormat ) return gl.DEPTH_STENCIL;1341613417 1341813419 if ( p === RedFormat ) return gl.RED;13420 if ( p === RedIntegerFormat ) return gl.RED_INTEGER;13421 if ( p === RGFormat ) return gl.RG;13422 if ( p === RGIntegerFormat ) return gl.RG_INTEGER;13423 if ( p === RGBAIntegerFormat ) return gl.RGBA_INTEGER;1342413425 1342613427 if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format || p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) {1342813429 if ( transfer === SRGBTransfer ) {1343013431 extension = extensions.get( 'WEBGL_compressed_texture_s3tc_srgb' );1343213433 if ( extension !== null ) {1343413435 if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_SRGB_S3TC_DXT1_EXT;13436 if ( p === RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;13437 if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;13438 if ( p === RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;1343913440 } else {1344113442 return null;1344313444 }1344513446 } else {1344713448 extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );1344913450 if ( extension !== null ) {1345113452 if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;13453 if ( p === RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;13454 if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;13455 if ( p === RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;1345613457 } else {1345813459 return null;1346013461 }1346213463 }1346413465 }1346613467 1346813469 if ( p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format || p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format ) {1347013471 extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );1347213473 if ( extension !== null ) {1347413475 if ( p === RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;13476 if ( p === RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;13477 if ( p === RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;13478 if ( p === RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;1347913480 } else {1348113482 return null;1348313484 }1348513486 }1348713488 1348913490 if ( p === RGB_ETC1_Format || p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format || p === R11_EAC_Format || p === SIGNED_R11_EAC_Format || p === RG11_EAC_Format || p === SIGNED_RG11_EAC_Format ) {1349113492 extension = extensions.get( 'WEBGL_compressed_texture_etc' );1349313494 if ( extension !== null ) {1349513496 if ( p === RGB_ETC1_Format || p === RGB_ETC2_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB8_ETC2 : extension.COMPRESSED_RGB8_ETC2;13497 if ( p === RGBA_ETC2_EAC_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC : extension.COMPRESSED_RGBA8_ETC2_EAC;13498 if ( p === R11_EAC_Format ) return extension.COMPRESSED_R11_EAC;13499 if ( p === SIGNED_R11_EAC_Format ) return extension.COMPRESSED_SIGNED_R11_EAC;13500 if ( p === RG11_EAC_Format ) return extension.COMPRESSED_RG11_EAC;13501 if ( p === SIGNED_RG11_EAC_Format ) return extension.COMPRESSED_SIGNED_RG11_EAC;1350213503 } else {1350413505 return null;1350613507 }1350813509 }1351013511 1351213513 if ( p === RGBA_ASTC_4x4_Format || p === RGBA_ASTC_5x4_Format || p === RGBA_ASTC_5x5_Format ||13514 p === RGBA_ASTC_6x5_Format || p === RGBA_ASTC_6x6_Format || p === RGBA_ASTC_8x5_Format ||13515 p === RGBA_ASTC_8x6_Format || p === RGBA_ASTC_8x8_Format || p === RGBA_ASTC_10x5_Format ||13516 p === RGBA_ASTC_10x6_Format || p === RGBA_ASTC_10x8_Format || p === RGBA_ASTC_10x10_Format ||13517 p === RGBA_ASTC_12x10_Format || p === RGBA_ASTC_12x12_Format ) {1351813519 extension = extensions.get( 'WEBGL_compressed_texture_astc' );1352013521 if ( extension !== null ) {1352213523 if ( p === RGBA_ASTC_4x4_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR : extension.COMPRESSED_RGBA_ASTC_4x4_KHR;13524 if ( p === RGBA_ASTC_5x4_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR : extension.COMPRESSED_RGBA_ASTC_5x4_KHR;13525 if ( p === RGBA_ASTC_5x5_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR : extension.COMPRESSED_RGBA_ASTC_5x5_KHR;13526 if ( p === RGBA_ASTC_6x5_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR : extension.COMPRESSED_RGBA_ASTC_6x5_KHR;13527 if ( p === RGBA_ASTC_6x6_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR : extension.COMPRESSED_RGBA_ASTC_6x6_KHR;13528 if ( p === RGBA_ASTC_8x5_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR : extension.COMPRESSED_RGBA_ASTC_8x5_KHR;13529 if ( p === RGBA_ASTC_8x6_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR : extension.COMPRESSED_RGBA_ASTC_8x6_KHR;13530 if ( p === RGBA_ASTC_8x8_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR : extension.COMPRESSED_RGBA_ASTC_8x8_KHR;13531 if ( p === RGBA_ASTC_10x5_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR : extension.COMPRESSED_RGBA_ASTC_10x5_KHR;13532 if ( p === RGBA_ASTC_10x6_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR : extension.COMPRESSED_RGBA_ASTC_10x6_KHR;13533 if ( p === RGBA_ASTC_10x8_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR : extension.COMPRESSED_RGBA_ASTC_10x8_KHR;13534 if ( p === RGBA_ASTC_10x10_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR : extension.COMPRESSED_RGBA_ASTC_10x10_KHR;13535 if ( p === RGBA_ASTC_12x10_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR : extension.COMPRESSED_RGBA_ASTC_12x10_KHR;13536 if ( p === RGBA_ASTC_12x12_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR : extension.COMPRESSED_RGBA_ASTC_12x12_KHR;1353713538 } else {1353913540 return null;1354113542 }1354313544 }1354513546 1354713548 if ( p === RGBA_BPTC_Format || p === RGB_BPTC_SIGNED_Format || p === RGB_BPTC_UNSIGNED_Format ) {1354913550 extension = extensions.get( 'EXT_texture_compression_bptc' );1355113552 if ( extension !== null ) {1355313554 if ( p === RGBA_BPTC_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT : extension.COMPRESSED_RGBA_BPTC_UNORM_EXT;13555 if ( p === RGB_BPTC_SIGNED_Format ) return extension.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;13556 if ( p === RGB_BPTC_UNSIGNED_Format ) return extension.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT;1355713558 } else {1355913560 return null;1356113562 }1356313564 }1356513566 1356713568 if ( p === RED_RGTC1_Format || p === SIGNED_RED_RGTC1_Format || p === RED_GREEN_RGTC2_Format || p === SIGNED_RED_GREEN_RGTC2_Format ) {1356913570 extension = extensions.get( 'EXT_texture_compression_rgtc' );1357113572 if ( extension !== null ) {1357313574 if ( p === RED_RGTC1_Format ) return extension.COMPRESSED_RED_RGTC1_EXT;13575 if ( p === SIGNED_RED_RGTC1_Format ) return extension.COMPRESSED_SIGNED_RED_RGTC1_EXT;13576 if ( p === RED_GREEN_RGTC2_Format ) return extension.COMPRESSED_RED_GREEN_RGTC2_EXT;13577 if ( p === SIGNED_RED_GREEN_RGTC2_Format ) return extension.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT;1357813579 } else {1358013581 return null;1358213583 }1358413585 }1358613587 1358813589 if ( p === UnsignedInt248Type ) return gl.UNSIGNED_INT_24_8;1359013591 1359213593 return ( gl[ p ] !== undefined ) ? gl[ p ] : null;1359413595 }1359613597 return { convert: convert };1359813599}1360013601const _occlusion_vertex = `13602void main() {1360313604 gl_Position = vec4( position, 1.0 );1360513606}`;1360713608const _occlusion_fragment = `13609uniform sampler2DArray depthColor;13610uniform float depthWidth;13611uniform float depthHeight;1361213613void main() {1361413615 vec2 coord = vec2( gl_FragCoord.x / depthWidth, gl_FragCoord.y / depthHeight );1361613617 if ( coord.x >= 1.0 ) {1361813619 gl_FragDepth = texture( depthColor, vec3( coord.x - 1.0, coord.y, 1 ) ).r;1362013621 } else {1362213623 gl_FragDepth = texture( depthColor, vec3( coord.x, coord.y, 0 ) ).r;1362413625 }1362613627}`;1362813629136301363113632class WebXRDepthSensing {1363313634 136351363613637 constructor() {1363813639 1364013641136421364313644 this.texture = null;1364513646 1364713648136491365013651 this.mesh = null;1365213653 1365413655136561365713658 this.depthNear = 0;1365913660 1366113662136631366413665 this.depthFar = 0;1366613667 }1366813669 136701367113672136731367413675 init( depthData, renderState ) {1367613677 if ( this.texture === null ) {1367813679 const texture = new ExternalTexture( depthData.texture );1368013681 if ( ( depthData.depthNear !== renderState.depthNear ) || ( depthData.depthFar !== renderState.depthFar ) ) {1368213683 this.depthNear = depthData.depthNear;13684 this.depthFar = depthData.depthFar;1368513686 }1368713688 this.texture = texture;1368913690 }1369113692 }1369313694 136951369613697136981369913700 getMesh( cameraXR ) {1370113702 if ( this.texture !== null ) {1370313704 if ( this.mesh === null ) {1370513706 const viewport = cameraXR.cameras[ 0 ].viewport;13707 const material = new ShaderMaterial( {13708 vertexShader: _occlusion_vertex,13709 fragmentShader: _occlusion_fragment,13710 uniforms: {13711 depthColor: { value: this.texture },13712 depthWidth: { value: viewport.z },13713 depthHeight: { value: viewport.w }13714 }13715 } );1371613717 this.mesh = new Mesh( new PlaneGeometry( 20, 20 ), material );1371813719 }1372013721 }1372213723 return this.mesh;1372413725 }1372613727 137281372913730 reset() {1373113732 this.texture = null;13733 this.mesh = null;1373413735 }1373613737 1373813739137401374113742 getDepthTexture() {1374313744 return this.texture;1374513746 }1374713748}1374913750137511375213753137541375513756137571375813759class WebXRManager extends EventDispatcher {1376013761 137621376313764137651376613767 constructor( renderer, gl ) {1376813769 super();1377013771 const scope = this;1377213773 let session = null;1377413775 let framebufferScaleFactor = 1.0;1377613777 let referenceSpace = null;13778 let referenceSpaceType = 'local-floor';13779 13780 let foveation = 1.0;13781 let customReferenceSpace = null;1378213783 let pose = null;13784 let glBinding = null;13785 let glProjLayer = null;13786 let glBaseLayer = null;13787 let xrFrame = null;1378813789 const supportsGlBinding = typeof XRWebGLBinding !== 'undefined';1379013791 const depthSensing = new WebXRDepthSensing();13792 const cameraAccessTextures = {};13793 const attributes = gl.getContextAttributes();1379413795 let initialRenderTarget = null;13796 let newRenderTarget = null;1379713798 const controllers = [];13799 const controllerInputSources = [];1380013801 const currentSize = new Vector2();13802 let currentPixelRatio = null;13803 let currentCameraSettings = null;1380413805 1380613807 const cameraL = new PerspectiveCamera();13808 cameraL.viewport = new Vector4();1380913810 const cameraR = new PerspectiveCamera();13811 cameraR.viewport = new Vector4();1381213813 const cameras = [ cameraL, cameraR ];1381413815 const cameraXR = new ArrayCamera();1381613817 let _currentDepthNear = null;13818 let _currentDepthFar = null;1381913820 1382113822 138231382413825138261382713828 this.cameraAutoUpdate = true;1382913830 13831138321383313834138351383613837 this.enabled = false;1383813839 13840138411384213843138441384513846 this.isPresenting = false;1384713848 1384913850138511385213853138541385513856 this.getController = function ( index ) {1385713858 let controller = controllers[ index ];1385913860 if ( controller === undefined ) {1386113862 controller = new WebXRController();13863 controllers[ index ] = controller;1386413865 }1386613867 return controller.getTargetRaySpace();1386813869 };1387013871 138721387313874138751387613877138781387913880138811388213883138841388513886 this.getControllerGrip = function ( index ) {1388713888 let controller = controllers[ index ];1388913890 if ( controller === undefined ) {1389113892 controller = new WebXRController();13893 controllers[ index ] = controller;1389413895 }1389613897 return controller.getGripSpace();1389813899 };1390013901 1390213903139041390513906139071390813909 this.getHand = function ( index ) {1391013911 let controller = controllers[ index ];1391213913 if ( controller === undefined ) {1391413915 controller = new WebXRController();13916 controllers[ index ] = controller;1391713918 }1391913920 return controller.getHandSpace();1392113922 };1392313924 1392513926 function onSessionEvent( event ) {1392713928 const controllerIndex = controllerInputSources.indexOf( event.inputSource );1392913930 if ( controllerIndex === -1 ) {1393113932 return;1393313934 }1393513936 const controller = controllers[ controllerIndex ];1393713938 if ( controller !== undefined ) {1393913940 controller.update( event.inputSource, event.frame, customReferenceSpace || referenceSpace );13941 controller.dispatchEvent( { type: event.type, data: event.inputSource } );1394213943 }1394413945 }1394613947 function onSessionEnd() {1394813949 session.removeEventListener( 'select', onSessionEvent );13950 session.removeEventListener( 'selectstart', onSessionEvent );13951 session.removeEventListener( 'selectend', onSessionEvent );13952 session.removeEventListener( 'squeeze', onSessionEvent );13953 session.removeEventListener( 'squeezestart', onSessionEvent );13954 session.removeEventListener( 'squeezeend', onSessionEvent );13955 session.removeEventListener( 'end', onSessionEnd );13956 session.removeEventListener( 'inputsourceschange', onInputSourcesChange );1395713958 for ( let i = 0; i < controllers.length; i ++ ) {1395913960 const inputSource = controllerInputSources[ i ];1396113962 if ( inputSource === null ) continue;1396313964 controllerInputSources[ i ] = null;1396513966 controllers[ i ].disconnect( inputSource );1396713968 }1396913970 _currentDepthNear = null;13971 _currentDepthFar = null;1397213973 depthSensing.reset();13974 for ( const key in cameraAccessTextures ) {1397513976 delete cameraAccessTextures[ key ];1397713978 }1397913980 1398113982 renderer.setRenderTarget( initialRenderTarget );1398313984 glBaseLayer = null;13985 glProjLayer = null;13986 glBinding = null;13987 session = null;13988 newRenderTarget = null;1398913990 1399113992 animation.stop();1399313994 scope.isPresenting = false;1399513996 renderer.setPixelRatio( currentPixelRatio );13997 renderer.setSize( currentSize.width, currentSize.height, false );1399813999 if ( currentCameraSettings !== null ) {1400014001 const camera = currentCameraSettings.camera;1400214003 camera.fov = currentCameraSettings.fov;14004 camera.zoom = currentCameraSettings.zoom;14005 camera.updateProjectionMatrix();1400614007 currentCameraSettings = null;1400814009 }1401014011 scope.dispatchEvent( { type: 'sessionend' } );1401214013 }1401414015 14016140171401814019140201402114022 this.setFramebufferScaleFactor = function ( value ) {1402314024 framebufferScaleFactor = value;1402514026 if ( scope.isPresenting === true ) {1402714028 warn( 'WebXRManager: Cannot change framebuffer scale while presenting.' );1402914030 }1403114032 };1403314034 14035140361403714038140391404014041140421404314044 this.setReferenceSpaceType = function ( value ) {1404514046 referenceSpaceType = value;1404714048 if ( scope.isPresenting === true ) {1404914050 warn( 'WebXRManager: Cannot change reference space type while presenting.' );1405114052 }1405314054 };1405514056 1405714058140591406014061 this.getReferenceSpace = function () {1406214063 return customReferenceSpace || referenceSpace;1406414065 };1406614067 1406814069140701407114072 this.setReferenceSpace = function ( space ) {1407314074 customReferenceSpace = space;1407514076 };1407714078 1407914080140811408214083140841408514086 this.getBaseLayer = function () {1408714088 return glProjLayer !== null ? glProjLayer : glBaseLayer;1408914090 };1409114092 1409314094140951409614097140981409914100 this.getBinding = function () {1410114102 if ( glBinding === null && supportsGlBinding ) {1410314104 glBinding = new XRWebGLBinding( session, gl );1410514106 }1410714108 return glBinding;1410914110 };1411114112 1411314114141151411614117 this.getFrame = function () {1411814119 return xrFrame;1412014121 };1412214123 1412414125141261412714128 this.getSession = function () {1412914130 return session;1413114132 };1413314134 141351413614137141381413914140141411414214143 this.setSession = async function ( value ) {1414414145 session = value;1414614147 if ( session !== null ) {1414814149 initialRenderTarget = renderer.getRenderTarget();1415014151 session.addEventListener( 'select', onSessionEvent );14152 session.addEventListener( 'selectstart', onSessionEvent );14153 session.addEventListener( 'selectend', onSessionEvent );14154 session.addEventListener( 'squeeze', onSessionEvent );14155 session.addEventListener( 'squeezestart', onSessionEvent );14156 session.addEventListener( 'squeezeend', onSessionEvent );14157 session.addEventListener( 'end', onSessionEnd );14158 session.addEventListener( 'inputsourceschange', onInputSourcesChange );1415914160 if ( attributes.xrCompatible !== true ) {1416114162 await gl.makeXRCompatible();1416314164 }1416514166 currentPixelRatio = renderer.getPixelRatio();14167 renderer.getSize( currentSize );141681416914170 14171 14172 const supportsLayers = supportsGlBinding && 'createProjectionLayer' in XRWebGLBinding.prototype;1417314174 if ( ! supportsLayers ) {1417514176 const layerInit = {14177 antialias: attributes.antialias,14178 alpha: true,14179 depth: attributes.depth,14180 stencil: attributes.stencil,14181 framebufferScaleFactor: framebufferScaleFactor14182 };1418314184 glBaseLayer = new XRWebGLLayer( session, gl, layerInit );1418514186 session.updateRenderState( { baseLayer: glBaseLayer } );1418714188 renderer.setPixelRatio( 1 );14189 renderer.setSize( glBaseLayer.framebufferWidth, glBaseLayer.framebufferHeight, false );1419014191 newRenderTarget = new WebGLRenderTarget(14192 glBaseLayer.framebufferWidth,14193 glBaseLayer.framebufferHeight,14194 {14195 format: RGBAFormat,14196 type: UnsignedByteType,14197 colorSpace: renderer.outputColorSpace,14198 stencilBuffer: attributes.stencil,14199 resolveDepthBuffer: ( glBaseLayer.ignoreDepthValues === false ),14200 resolveStencilBuffer: ( glBaseLayer.ignoreDepthValues === false ),14201 storeMultisampledDepthBuffer: ( glBaseLayer.ignoreDepthValues === false ),14202 storeMultisampledStencilBuffer: ( glBaseLayer.ignoreDepthValues === false )1420314204 }14205 );1420614207 } else {1420814209 let depthFormat = null;14210 let depthType = null;14211 let glDepthFormat = null;1421214213 if ( attributes.depth ) {1421414215 glDepthFormat = attributes.stencil ? gl.DEPTH24_STENCIL8 : gl.DEPTH_COMPONENT24;14216 depthFormat = attributes.stencil ? DepthStencilFormat : DepthFormat;14217 depthType = attributes.stencil ? UnsignedInt248Type : UnsignedIntType;1421814219 }1422014221 const projectionlayerInit = {14222 colorFormat: gl.RGBA8,14223 depthFormat: glDepthFormat,14224 scaleFactor: framebufferScaleFactor14225 };1422614227 glBinding = this.getBinding();1422814229 glProjLayer = glBinding.createProjectionLayer( projectionlayerInit );1423014231 session.updateRenderState( { layers: [ glProjLayer ] } );1423214233 renderer.setPixelRatio( 1 );14234 renderer.setSize( glProjLayer.textureWidth, glProjLayer.textureHeight, false );1423514236 newRenderTarget = new WebGLRenderTarget(14237 glProjLayer.textureWidth,14238 glProjLayer.textureHeight,14239 {14240 format: RGBAFormat,14241 type: UnsignedByteType,14242 depthTexture: new DepthTexture( glProjLayer.textureWidth, glProjLayer.textureHeight, depthType, undefined, undefined, undefined, undefined, undefined, undefined, depthFormat ),14243 stencilBuffer: attributes.stencil,14244 colorSpace: renderer.outputColorSpace,14245 samples: attributes.antialias ? 4 : 0,14246 resolveDepthBuffer: ( glProjLayer.ignoreDepthValues === false ),14247 resolveStencilBuffer: ( glProjLayer.ignoreDepthValues === false ),14248 storeMultisampledDepthBuffer: ( glProjLayer.ignoreDepthValues === false ),14249 storeMultisampledStencilBuffer: ( glProjLayer.ignoreDepthValues === false )14250 } );1425114252 }1425314254 newRenderTarget.isXRRenderTarget = true; 1425514256 this.setFoveation( foveation );1425714258 customReferenceSpace = null;14259 referenceSpace = await session.requestReferenceSpace( referenceSpaceType );1426014261 animation.setContext( session );14262 animation.start();1426314264 scope.isPresenting = true;1426514266 scope.dispatchEvent( { type: 'sessionstart' } );1426714268 }1426914270 };1427114272 1427314274142751427614277 this.getEnvironmentBlendMode = function () {1427814279 if ( session !== null ) {1428014281 return session.environmentBlendMode;1428214283 }1428414285 };1428614287 14288142891429014291142921429314294 this.getDepthTexture = function () {1429514296 return depthSensing.getDepthTexture();1429714298 };1429914300 function onInputSourcesChange( event ) {1430114302 1430314304 for ( let i = 0; i < event.removed.length; i ++ ) {1430514306 const inputSource = event.removed[ i ];14307 const index = controllerInputSources.indexOf( inputSource );1430814309 if ( index >= 0 ) {1431014311 controllerInputSources[ index ] = null;14312 controllers[ index ].disconnect( inputSource );1431314314 }1431514316 }1431714318 1431914320 for ( let i = 0; i < event.added.length; i ++ ) {1432114322 const inputSource = event.added[ i ];1432314324 let controllerIndex = controllerInputSources.indexOf( inputSource );1432514326 if ( controllerIndex === -1 ) {1432714328 1432914330 for ( let i = 0; i < controllers.length; i ++ ) {1433114332 if ( i >= controllerInputSources.length ) {1433314334 controllerInputSources.push( inputSource );14335 controllerIndex = i;14336 break;1433714338 } else if ( controllerInputSources[ i ] === null ) {1433914340 controllerInputSources[ i ] = inputSource;14341 controllerIndex = i;14342 break;1434314344 }1434514346 }1434714348 1434914350 if ( controllerIndex === -1 ) break;1435114352 }1435314354 const controller = controllers[ controllerIndex ];1435514356 if ( controller ) {1435714358 controller.connect( inputSource );1435914360 }1436114362 }1436314364 }1436514366 1436714368 function updateCamera( camera, parent ) {1436914370 if ( parent === null ) {1437114372 camera.matrixWorld.copy( camera.matrix );1437314374 } else {1437514376 camera.matrixWorld.multiplyMatrices( parent.matrixWorld, camera.matrix );1437714378 }1437914380 camera.matrixWorldInverse.copy( camera.matrixWorld ).invert();1438114382 }1438314384 143851438614387143881438914390143911439214393 this.updateCamera = function ( camera ) {1439414395 if ( session === null ) return;1439614397 let depthNear = camera.near;14398 let depthFar = camera.far;1439914400 if ( depthSensing.texture !== null ) {1440114402 if ( depthSensing.depthNear > 0 ) depthNear = depthSensing.depthNear;14403 if ( depthSensing.depthFar > 0 ) depthFar = depthSensing.depthFar;1440414405 }1440614407 cameraXR.near = cameraR.near = cameraL.near = depthNear;14408 cameraXR.far = cameraR.far = cameraL.far = depthFar;1440914410 if ( _currentDepthNear !== cameraXR.near || _currentDepthFar !== cameraXR.far ) {1441114412 1441314414 session.updateRenderState( {14415 depthNear: cameraXR.near,14416 depthFar: cameraXR.far14417 } );1441814419 _currentDepthNear = cameraXR.near;14420 _currentDepthFar = cameraXR.far;1442114422 }1442314424 14425 cameraXR.layers.mask = camera.layers.mask | 0b110;14426 cameraL.layers.mask = cameraXR.layers.mask & -5;14427 cameraR.layers.mask = cameraXR.layers.mask & -3;1442814429 const parent = camera.parent;14430 const cameras = cameraXR.cameras;1443114432 updateCamera( cameraXR, parent );1443314434 for ( let i = 0; i < cameras.length; i ++ ) {1443514436 updateCamera( cameras[ i ], parent );1443714438 }1443914440 cameraXR.projectionMatrix.copy( cameraL.projectionMatrix );14441 cameraXR.projectionMatrixInverse.copy( cameraL.projectionMatrixInverse );1444214443 1444414445 if ( currentCameraSettings === null && camera.isPerspectiveCamera ) {1444614447 currentCameraSettings = { camera: camera, fov: camera.fov, zoom: camera.zoom };1444814449 }1445014451 updateUserCamera( camera, cameraXR, parent );1445214453 };1445414455 function updateUserCamera( camera, cameraXR, parent ) {1445614457 if ( parent === null ) {1445814459 camera.matrix.copy( cameraXR.matrixWorld );1446014461 } else {1446214463 camera.matrix.copy( parent.matrixWorld );14464 camera.matrix.invert();14465 camera.matrix.multiply( cameraXR.matrixWorld );1446614467 }1446814469 camera.matrix.decompose( camera.position, camera.quaternion, camera.scale );14470 camera.updateMatrixWorld( true );1447114472 camera.projectionMatrix.copy( cameraXR.projectionMatrix );14473 camera.projectionMatrixInverse.copy( cameraXR.projectionMatrixInverse );1447414475 if ( camera.isPerspectiveCamera ) {1447614477 camera.fov = RAD2DEG * 2 * Math.atan( 1 / camera.projectionMatrix.elements[ 5 ] );14478 camera.zoom = 1;1447914480 }1448114482 }1448314484 14485144861448714488144891449014491144921449314494144951449614497 this.getCamera = function () {1449814499 return cameraXR;1450014501 };1450214503 1450414505145061450714508 this.getFoveation = function () {1450914510 if ( glProjLayer === null && glBaseLayer === null ) {1451114512 return undefined;1451314514 }1451514516 return foveation;1451714518 };1451914520 145211452214523145241452514526 this.setFoveation = function ( value ) {1452714528 14529 1453014531 foveation = value;1453214533 if ( glProjLayer !== null ) {1453414535 glProjLayer.fixedFoveation = value;1453614537 }1453814539 if ( glBaseLayer !== null && glBaseLayer.fixedFoveation !== undefined ) {1454014541 glBaseLayer.fixedFoveation = value;1454214543 }1454414545 };1454614547 1454814549145501455114552 this.hasDepthSensing = function () {1455314554 return depthSensing.texture !== null;1455514556 };1455714558 14559145601456114562145631456414565 this.getDepthSensingMesh = function () {1456614567 return depthSensing.getMesh( cameraXR );1456814569 };1457014571 14572145731457414575145761457714578 this.getCameraTexture = function ( xrCamera ) {1457914580 return cameraAccessTextures[ xrCamera ];1458114582 };1458314584 1458514586 let onAnimationFrameCallback = null;1458714588 function onAnimationFrame( time, frame ) {1458914590 pose = frame.getViewerPose( customReferenceSpace || referenceSpace );14591 xrFrame = frame;1459214593 if ( pose !== null ) {1459414595 const views = pose.views;1459614597 if ( glBaseLayer !== null ) {1459814599 renderer.setRenderTargetFramebuffer( newRenderTarget, glBaseLayer.framebuffer );14600 renderer.setRenderTarget( newRenderTarget );1460114602 }1460314604 let cameraXRNeedsUpdate = false;1460514606 1460714608 if ( views.length !== cameraXR.cameras.length ) {1460914610 cameraXR.cameras.length = 0;14611 cameraXRNeedsUpdate = true;1461214613 }1461414615 for ( let i = 0; i < views.length; i ++ ) {1461614617 const view = views[ i ];1461814619 let viewport = null;1462014621 if ( glBaseLayer !== null ) {1462214623 viewport = glBaseLayer.getViewport( view );1462414625 } else {1462614627 const glSubImage = glBinding.getViewSubImage( glProjLayer, view );14628 viewport = glSubImage.viewport;1462914630 14631 if ( i === 0 ) {1463214633 renderer.setRenderTargetTextures(14634 newRenderTarget,14635 glSubImage.colorTexture,14636 glSubImage.depthStencilTexture );1463714638 renderer.setRenderTarget( newRenderTarget );1463914640 }1464114642 }1464314644 let camera = cameras[ i ];1464514646 if ( camera === undefined ) {1464714648 camera = new PerspectiveCamera();14649 camera.layers.enable( i );14650 camera.viewport = new Vector4();14651 cameras[ i ] = camera;1465214653 }1465414655 camera.matrix.fromArray( view.transform.matrix );14656 camera.matrix.decompose( camera.position, camera.quaternion, camera.scale );14657 camera.projectionMatrix.fromArray( view.projectionMatrix );14658 camera.projectionMatrixInverse.copy( camera.projectionMatrix ).invert();14659 camera.viewport.set( viewport.x, viewport.y, viewport.width, viewport.height );1466014661 if ( i === 0 ) {1466214663 cameraXR.matrix.copy( camera.matrix );14664 cameraXR.matrix.decompose( cameraXR.position, cameraXR.quaternion, cameraXR.scale );1466514666 }1466714668 if ( cameraXRNeedsUpdate === true ) {1466914670 cameraXR.cameras.push( camera );1467114672 }1467314674 }1467514676 1467714678 const enabledFeatures = session.enabledFeatures;14679 const gpuDepthSensingEnabled = enabledFeatures &&14680 enabledFeatures.includes( 'depth-sensing' ) &&14681 session.depthUsage == 'gpu-optimized';1468214683 if ( gpuDepthSensingEnabled && supportsGlBinding ) {1468414685 glBinding = scope.getBinding();1468614687 const depthData = glBinding.getDepthInformation( views[ 0 ] );1468814689 if ( depthData && depthData.isValid && depthData.texture ) {1469014691 depthSensing.init( depthData, session.renderState );1469214693 }1469414695 }1469614697 const cameraAccessEnabled = enabledFeatures &&14698 enabledFeatures.includes( 'camera-access' );1469914700 if ( cameraAccessEnabled && supportsGlBinding ) {1470114702 renderer.state.unbindTexture();1470314704 glBinding = scope.getBinding();1470514706 for ( let i = 0; i < views.length; i ++ ) {1470714708 const camera = views[ i ].camera;1470914710 if ( camera ) {1471114712 let cameraTex = cameraAccessTextures[ camera ];1471314714 if ( ! cameraTex ) {1471514716 cameraTex = new ExternalTexture();14717 cameraAccessTextures[ camera ] = cameraTex;1471814719 }1472014721 const glTexture = glBinding.getCameraImage( camera );14722 cameraTex.sourceTexture = glTexture;1472314724 }1472514726 }1472714728 }1472914730 }1473114732 1473314734 for ( let i = 0; i < controllers.length; i ++ ) {1473514736 const inputSource = controllerInputSources[ i ];14737 const controller = controllers[ i ];1473814739 if ( inputSource !== null && controller !== undefined ) {1474014741 controller.update( inputSource, frame, customReferenceSpace || referenceSpace );1474214743 }1474414745 }1474614747 if ( onAnimationFrameCallback ) onAnimationFrameCallback( time, frame );1474814749 if ( frame.detectedPlanes ) {1475014751 scope.dispatchEvent( { type: 'planesdetected', data: frame } );1475214753 }1475414755 xrFrame = null;1475614757 }1475814759 const animation = new WebGLAnimation();1476014761 animation.setAnimationLoop( onAnimationFrame );1476214763 this.setAnimationLoop = function ( callback ) {1476414765 onAnimationFrameCallback = callback;1476614767 };1476814769 this.dispose = function () {};1477014771 }1477214773}1477414775const _m1 = new Matrix4();14776const _m = new Matrix3();1477714778_m.set( -1, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0 );1477914780function WebGLMaterials( renderer, properties ) {1478114782 function refreshTransformUniform( map, uniform ) {1478314784 if ( map.matrixAutoUpdate === true ) {1478514786 map.updateMatrix();1478714788 }1478914790 uniform.value.copy( map.matrix );1479114792 }1479314794 function refreshFogUniforms( uniforms, fog ) {1479514796 fog.color.getRGB( uniforms.fogColor.value, getUnlitUniformColorSpace( renderer ) );1479714798 if ( fog.isFog ) {1479914800 uniforms.fogNear.value = fog.near;14801 uniforms.fogFar.value = fog.far;1480214803 } else if ( fog.isFogExp2 ) {1480414805 uniforms.fogDensity.value = fog.density;1480614807 }1480814809 }1481014811 function refreshMaterialUniforms( uniforms, material, pixelRatio, height, transmissionRenderTarget ) {1481214813 if ( material.isNodeMaterial ) {1481414815 material.uniformsNeedUpdate = false;1481614817 } else if ( material.isMeshBasicMaterial ) {1481814819 refreshUniformsCommon( uniforms, material );1482014821 } else if ( material.isMeshLambertMaterial ) {1482214823 refreshUniformsCommon( uniforms, material );1482414825 if ( material.envMap ) {1482614827 uniforms.envMapIntensity.value = material.envMapIntensity;1482814829 }1483014831 } else if ( material.isMeshToonMaterial ) {1483214833 refreshUniformsCommon( uniforms, material );14834 refreshUniformsToon( uniforms, material );1483514836 } else if ( material.isMeshPhongMaterial ) {1483714838 refreshUniformsCommon( uniforms, material );14839 refreshUniformsPhong( uniforms, material );1484014841 if ( material.envMap ) {1484214843 uniforms.envMapIntensity.value = material.envMapIntensity;1484414845 }1484614847 } else if ( material.isMeshStandardMaterial ) {1484814849 refreshUniformsCommon( uniforms, material );14850 refreshUniformsStandard( uniforms, material );1485114852 if ( material.isMeshPhysicalMaterial ) {1485314854 refreshUniformsPhysical( uniforms, material, transmissionRenderTarget );1485514856 }1485714858 } else if ( material.isMeshMatcapMaterial ) {1485914860 refreshUniformsCommon( uniforms, material );14861 refreshUniformsMatcap( uniforms, material );1486214863 } else if ( material.isMeshDepthMaterial ) {1486414865 refreshUniformsCommon( uniforms, material );1486614867 } else if ( material.isMeshDistanceMaterial ) {1486814869 refreshUniformsCommon( uniforms, material );14870 refreshUniformsDistance( uniforms, material );1487114872 } else if ( material.isMeshNormalMaterial ) {1487314874 refreshUniformsCommon( uniforms, material );1487514876 } else if ( material.isLineBasicMaterial ) {1487714878 refreshUniformsLine( uniforms, material );1487914880 if ( material.isLineDashedMaterial ) {1488114882 refreshUniformsDash( uniforms, material );1488314884 }1488514886 } else if ( material.isPointsMaterial ) {1488714888 refreshUniformsPoints( uniforms, material, pixelRatio, height );1488914890 } else if ( material.isSpriteMaterial ) {1489114892 refreshUniformsSprites( uniforms, material );1489314894 } else if ( material.isShadowMaterial ) {1489514896 uniforms.color.value.copy( material.color );14897 uniforms.opacity.value = material.opacity;1489814899 } else if ( material.isShaderMaterial ) {1490014901 material.uniformsNeedUpdate = false; 1490214903 }1490414905 }1490614907 function refreshUniformsCommon( uniforms, material ) {1490814909 uniforms.opacity.value = material.opacity;1491014911 if ( material.color ) {1491214913 uniforms.diffuse.value.copy( material.color );1491414915 }1491614917 if ( material.emissive ) {1491814919 uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );1492014921 }1492214923 if ( material.map ) {1492414925 uniforms.map.value = material.map;1492614927 refreshTransformUniform( material.map, uniforms.mapTransform );1492814929 }1493014931 if ( material.alphaMap ) {1493214933 uniforms.alphaMap.value = material.alphaMap;1493414935 refreshTransformUniform( material.alphaMap, uniforms.alphaMapTransform );1493614937 }1493814939 if ( material.bumpMap ) {1494014941 uniforms.bumpMap.value = material.bumpMap;1494214943 refreshTransformUniform( material.bumpMap, uniforms.bumpMapTransform );1494414945 uniforms.bumpScale.value = material.bumpScale;1494614947 if ( material.side === BackSide ) {1494814949 uniforms.bumpScale.value *= -1;1495014951 }1495214953 }1495414955 if ( material.normalMap ) {1495614957 uniforms.normalMap.value = material.normalMap;1495814959 refreshTransformUniform( material.normalMap, uniforms.normalMapTransform );1496014961 uniforms.normalScale.value.copy( material.normalScale );1496214963 if ( material.side === BackSide ) {1496414965 uniforms.normalScale.value.negate();1496614967 }1496814969 }1497014971 if ( material.displacementMap ) {1497214973 uniforms.displacementMap.value = material.displacementMap;1497414975 refreshTransformUniform( material.displacementMap, uniforms.displacementMapTransform );1497614977 uniforms.displacementScale.value = material.displacementScale;14978 uniforms.displacementBias.value = material.displacementBias;1497914980 }1498114982 if ( material.emissiveMap ) {1498314984 uniforms.emissiveMap.value = material.emissiveMap;1498514986 refreshTransformUniform( material.emissiveMap, uniforms.emissiveMapTransform );1498714988 }1498914990 if ( material.specularMap ) {1499114992 uniforms.specularMap.value = material.specularMap;1499314994 refreshTransformUniform( material.specularMap, uniforms.specularMapTransform );1499514996 }1499714998 if ( material.alphaTest > 0 ) {1499915000 uniforms.alphaTest.value = material.alphaTest;1500115002 }1500315004 const materialProperties = properties.get( material );1500515006 const envMap = materialProperties.envMap;15007 const envMapRotation = materialProperties.envMapRotation;1500815009 if ( envMap ) {1501015011 uniforms.envMap.value = envMap;1501215013 15014 uniforms.envMapRotation.value.setFromMatrix4( _m1.makeRotationFromEuler( envMapRotation ) ).transpose();150151501615017 if ( envMap.isCubeTexture && envMap.isRenderTargetTexture === false ) {1501815019 uniforms.envMapRotation.value.premultiply( _m );1502015021 }1502215023 uniforms.reflectivity.value = material.reflectivity;15024 uniforms.ior.value = material.ior;15025 uniforms.refractionRatio.value = material.refractionRatio;1502615027 }1502815029 if ( material.lightMap ) {1503015031 uniforms.lightMap.value = material.lightMap;15032 uniforms.lightMapIntensity.value = material.lightMapIntensity;1503315034 refreshTransformUniform( material.lightMap, uniforms.lightMapTransform );1503515036 }1503715038 if ( material.aoMap ) {1503915040 uniforms.aoMap.value = material.aoMap;15041 uniforms.aoMapIntensity.value = material.aoMapIntensity;1504215043 refreshTransformUniform( material.aoMap, uniforms.aoMapTransform );1504415045 }1504615047 }1504815049 function refreshUniformsLine( uniforms, material ) {1505015051 uniforms.diffuse.value.copy( material.color );15052 uniforms.opacity.value = material.opacity;1505315054 if ( material.map ) {1505515056 uniforms.map.value = material.map;1505715058 refreshTransformUniform( material.map, uniforms.mapTransform );1505915060 }1506115062 }1506315064 function refreshUniformsDash( uniforms, material ) {1506515066 uniforms.dashSize.value = material.dashSize;15067 uniforms.totalSize.value = material.dashSize + material.gapSize;15068 uniforms.scale.value = material.scale;1506915070 }1507115072 function refreshUniformsPoints( uniforms, material, pixelRatio, height ) {1507315074 uniforms.diffuse.value.copy( material.color );15075 uniforms.opacity.value = material.opacity;15076 uniforms.size.value = material.size * pixelRatio;15077 uniforms.scale.value = height * 0.5;1507815079 if ( material.map ) {1508015081 uniforms.map.value = material.map;1508215083 refreshTransformUniform( material.map, uniforms.uvTransform );1508415085 }1508615087 if ( material.alphaMap ) {1508815089 uniforms.alphaMap.value = material.alphaMap;1509015091 refreshTransformUniform( material.alphaMap, uniforms.alphaMapTransform );1509215093 }1509415095 if ( material.alphaTest > 0 ) {1509615097 uniforms.alphaTest.value = material.alphaTest;1509815099 }1510015101 }1510215103 function refreshUniformsSprites( uniforms, material ) {1510415105 uniforms.diffuse.value.copy( material.color );15106 uniforms.opacity.value = material.opacity;15107 uniforms.rotation.value = material.rotation;1510815109 if ( material.map ) {1511015111 uniforms.map.value = material.map;1511215113 refreshTransformUniform( material.map, uniforms.mapTransform );1511415115 }1511615117 if ( material.alphaMap ) {1511815119 uniforms.alphaMap.value = material.alphaMap;1512015121 refreshTransformUniform( material.alphaMap, uniforms.alphaMapTransform );1512215123 }1512415125 if ( material.alphaTest > 0 ) {1512615127 uniforms.alphaTest.value = material.alphaTest;1512815129 }1513015131 }1513215133 function refreshUniformsPhong( uniforms, material ) {1513415135 uniforms.specular.value.copy( material.specular );15136 uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); 1513715138 }1513915140 function refreshUniformsToon( uniforms, material ) {1514115142 if ( material.gradientMap ) {1514315144 uniforms.gradientMap.value = material.gradientMap;1514515146 }1514715148 }1514915150 function refreshUniformsStandard( uniforms, material ) {1515115152 uniforms.metalness.value = material.metalness;1515315154 if ( material.metalnessMap ) {1515515156 uniforms.metalnessMap.value = material.metalnessMap;1515715158 refreshTransformUniform( material.metalnessMap, uniforms.metalnessMapTransform );1515915160 }1516115162 uniforms.roughness.value = material.roughness;1516315164 if ( material.roughnessMap ) {1516515166 uniforms.roughnessMap.value = material.roughnessMap;1516715168 refreshTransformUniform( material.roughnessMap, uniforms.roughnessMapTransform );1516915170 }1517115172 if ( material.envMap ) {1517315174 1517515176 uniforms.envMapIntensity.value = material.envMapIntensity;1517715178 }1517915180 }1518115182 function refreshUniformsPhysical( uniforms, material, transmissionRenderTarget ) {1518315184 uniforms.ior.value = material.ior; 1518515186 if ( material.diffuseRoughness > 0 ) {1518715188 uniforms.diffuseRoughness.value = material.diffuseRoughness;1518915190 if ( material.diffuseRoughnessMap ) {1519115192 uniforms.diffuseRoughnessMap.value = material.diffuseRoughnessMap;15193 refreshTransformUniform( material.diffuseRoughnessMap, uniforms.diffuseRoughnessMapTransform );1519415195 }1519615197 }1519815199 if ( material.sheen > 0 ) {1520015201 uniforms.sheenColor.value.copy( material.sheenColor ).multiplyScalar( material.sheen );1520215203 uniforms.sheenRoughness.value = material.sheenRoughness;1520415205 if ( material.sheenColorMap ) {1520615207 uniforms.sheenColorMap.value = material.sheenColorMap;1520815209 refreshTransformUniform( material.sheenColorMap, uniforms.sheenColorMapTransform );1521015211 }1521215213 if ( material.sheenRoughnessMap ) {1521415215 uniforms.sheenRoughnessMap.value = material.sheenRoughnessMap;1521615217 refreshTransformUniform( material.sheenRoughnessMap, uniforms.sheenRoughnessMapTransform );1521815219 }1522015221 }1522215223 if ( material.clearcoat > 0 ) {1522415225 uniforms.clearcoat.value = material.clearcoat;15226 uniforms.clearcoatRoughness.value = material.clearcoatRoughness;1522715228 if ( material.clearcoatMap ) {1522915230 uniforms.clearcoatMap.value = material.clearcoatMap;1523115232 refreshTransformUniform( material.clearcoatMap, uniforms.clearcoatMapTransform );1523315234 }1523515236 if ( material.clearcoatRoughnessMap ) {1523715238 uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap;1523915240 refreshTransformUniform( material.clearcoatRoughnessMap, uniforms.clearcoatRoughnessMapTransform );1524115242 }1524315244 if ( material.clearcoatNormalMap ) {1524515246 uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap;1524715248 refreshTransformUniform( material.clearcoatNormalMap, uniforms.clearcoatNormalMapTransform );1524915250 uniforms.clearcoatNormalScale.value.copy( material.clearcoatNormalScale );1525115252 if ( material.side === BackSide ) {1525315254 uniforms.clearcoatNormalScale.value.negate();1525515256 }1525715258 }1525915260 }1526115262 if ( material.dispersion > 0 ) {1526315264 uniforms.dispersion.value = material.dispersion;1526515266 }1526715268 if ( material.retroreflectivity > 0 ) {1526915270 uniforms.retroreflectivity.value = material.retroreflectivity;1527115272 }1527315274 if ( material.iridescence > 0 ) {1527515276 uniforms.iridescence.value = material.iridescence;15277 uniforms.iridescenceIOR.value = material.iridescenceIOR;15278 uniforms.iridescenceThicknessMinimum.value = material.iridescenceThicknessMinimum;15279 uniforms.iridescenceThicknessMaximum.value = material.iridescenceThicknessMaximum;1528015281 if ( material.iridescenceMap ) {1528215283 uniforms.iridescenceMap.value = material.iridescenceMap;1528415285 refreshTransformUniform( material.iridescenceMap, uniforms.iridescenceMapTransform );1528615287 }1528815289 if ( material.iridescenceThicknessMap ) {1529015291 uniforms.iridescenceThicknessMap.value = material.iridescenceThicknessMap;1529215293 refreshTransformUniform( material.iridescenceThicknessMap, uniforms.iridescenceThicknessMapTransform );1529415295 }1529615297 }1529815299 if ( material.transmission > 0 ) {1530015301 uniforms.transmission.value = material.transmission;15302 uniforms.transmissionSamplerMap.value = transmissionRenderTarget.texture;15303 uniforms.transmissionSamplerSize.value.set( transmissionRenderTarget.width, transmissionRenderTarget.height );1530415305 if ( material.transmissionMap ) {1530615307 uniforms.transmissionMap.value = material.transmissionMap;1530815309 refreshTransformUniform( material.transmissionMap, uniforms.transmissionMapTransform );1531015311 }1531215313 uniforms.thickness.value = material.thickness;1531415315 if ( material.thicknessMap ) {1531615317 uniforms.thicknessMap.value = material.thicknessMap;1531815319 refreshTransformUniform( material.thicknessMap, uniforms.thicknessMapTransform );1532015321 }1532215323 uniforms.attenuationDistance.value = material.attenuationDistance;15324 uniforms.attenuationColor.value.copy( material.attenuationColor );1532515326 }1532715328 if ( material.anisotropy > 0 ) {1532915330 uniforms.anisotropyVector.value.set( material.anisotropy * Math.cos( material.anisotropyRotation ), material.anisotropy * Math.sin( material.anisotropyRotation ) );1533115332 if ( material.anisotropyMap ) {1533315334 uniforms.anisotropyMap.value = material.anisotropyMap;1533515336 refreshTransformUniform( material.anisotropyMap, uniforms.anisotropyMapTransform );1533715338 }1533915340 }1534115342 uniforms.specularIntensity.value = material.specularIntensity;15343 uniforms.specularColor.value.copy( material.specularColor );1534415345 if ( material.specularColorMap ) {1534615347 uniforms.specularColorMap.value = material.specularColorMap;1534815349 refreshTransformUniform( material.specularColorMap, uniforms.specularColorMapTransform );1535015351 }1535215353 if ( material.specularIntensityMap ) {1535415355 uniforms.specularIntensityMap.value = material.specularIntensityMap;1535615357 refreshTransformUniform( material.specularIntensityMap, uniforms.specularIntensityMapTransform );1535815359 }1536015361 }1536215363 function refreshUniformsMatcap( uniforms, material ) {1536415365 if ( material.matcap ) {1536615367 uniforms.matcap.value = material.matcap;1536815369 }1537015371 }1537215373 function refreshUniformsDistance( uniforms, material ) {1537415375 const light = properties.get( material ).light;1537615377 uniforms.referencePosition.value.setFromMatrixPosition( light.matrixWorld );15378 uniforms.nearDistance.value = light.shadow.camera.near;15379 uniforms.farDistance.value = light.shadow.camera.far;1538015381 }1538215383 return {15384 refreshFogUniforms: refreshFogUniforms,15385 refreshMaterialUniforms: refreshMaterialUniforms15386 };1538715388}1538915390function WebGLUniformsGroups( gl, info, capabilities, state ) {1539115392 let buffers = {};15393 let updateList = {};1539415395 function bind( uniformsGroup, program ) {1539615397 const webglProgram = program.program;15398 state.uniformBlockBinding( uniformsGroup, webglProgram, buffers[ uniformsGroup.id ] );1539915400 }1540115402 function update( uniformsGroup, program ) {1540315404 let buffer = buffers[ uniformsGroup.id ];1540515406 if ( buffer === undefined ) {1540715408 prepareUniformsGroup( uniformsGroup );1540915410 buffer = createBuffer( uniformsGroup );15411 buffers[ uniformsGroup.id ] = buffer;1541215413 uniformsGroup.addEventListener( 'dispose', onUniformsGroupsDispose );1541415415 }1541615417 1541815419 const webglProgram = program.program;15420 state.updateUBOMapping( uniformsGroup, webglProgram );1542115422 1542315424 const frame = info.render.frame;1542515426 if ( updateList[ uniformsGroup.id ] !== frame ) {1542715428 updateBufferData( uniformsGroup );1542915430 updateList[ uniformsGroup.id ] = frame;1543115432 }1543315434 }1543515436 function createBuffer( uniformsGroup ) {1543715438 const buffer = gl.createBuffer();15439 const size = uniformsGroup.__size;15440 const usage = uniformsGroup.usage;1544115442 gl.bindBuffer( gl.UNIFORM_BUFFER, buffer );15443 gl.bufferData( gl.UNIFORM_BUFFER, size, usage );15444 gl.bindBuffer( gl.UNIFORM_BUFFER, null );1544515446 return buffer;1544715448 }1544915450 function updateBufferData( uniformsGroup ) {1545115452 const buffer = buffers[ uniformsGroup.id ];15453 const uniforms = uniformsGroup.uniforms;15454 const cache = uniformsGroup.__cache;1545515456 gl.bindBuffer( gl.UNIFORM_BUFFER, buffer );1545715458 for ( let i = 0, il = uniforms.length; i < il; i ++ ) {1545915460 const uniformItem = uniforms[ i ];1546115462 if ( Array.isArray( uniformItem ) ) {1546315464 for ( let j = 0, jl = uniformItem.length; j < jl; j ++ ) {1546515466 updateUniform( uniformItem[ j ], i, j, cache );1546715468 }1546915470 } else {1547115472 updateUniform( uniformItem, i, 0, cache );1547315474 }1547515476 }1547715478 gl.bindBuffer( gl.UNIFORM_BUFFER, null );1547915480 }1548115482 function updateUniform( uniform, index, indexArray, cache ) {1548315484 if ( hasUniformChanged( uniform, index, indexArray, cache ) === true ) {1548515486 const offset = uniform.__offset;15487 const value = uniform.value;1548815489 if ( Array.isArray( value ) ) {1549015491 let arrayOffset = 0;1549215493 for ( let k = 0; k < value.length; k ++ ) {1549415495 const val = value[ k ];15496 const info = getUniformSize( val, true );1549715498 writeUniformValue( val, uniform.__data, arrayOffset );1549915500 arrayOffset += info.storage / Float32Array.BYTES_PER_ELEMENT;1550115502 }1550315504 } else {1550515506 writeUniformValue( value, uniform.__data, 0 );1550715508 }1550915510 gl.bufferSubData( gl.UNIFORM_BUFFER, offset, uniform.__data );1551115512 }1551315514 }1551515516 function writeUniformValue( value, data, offset ) {1551715518 15519 if ( typeof value === 'number' || typeof value === 'boolean' ) {1552015521 data[ offset ] = value;1552215523 } else if ( value.isMatrix3 ) {1552415525 1552615527 data[ offset ] = value.elements[ 0 ];15528 data[ offset + 1 ] = value.elements[ 1 ];15529 data[ offset + 2 ] = value.elements[ 2 ];15530 data[ offset + 3 ] = 0;15531 data[ offset + 4 ] = value.elements[ 3 ];15532 data[ offset + 5 ] = value.elements[ 4 ];15533 data[ offset + 6 ] = value.elements[ 5 ];15534 data[ offset + 7 ] = 0;15535 data[ offset + 8 ] = value.elements[ 6 ];15536 data[ offset + 9 ] = value.elements[ 7 ];15537 data[ offset + 10 ] = value.elements[ 8 ];15538 data[ offset + 11 ] = 0;1553915540 } else if ( ArrayBuffer.isView( value ) ) {1554115542 15543 data.set( value.subarray( 0, data.length - offset ), offset );1554415545 } else {1554615547 value.toArray( data, offset );1554815549 }1555015551 }1555215553 function hasUniformChanged( uniform, index, indexArray, cache ) {1555415555 const value = uniform.value;15556 const indexString = index + '_' + indexArray;1555715558 if ( Array.isArray( value ) ) {1555915560 1556115562 if ( cache[ indexString ] === undefined ) cache[ indexString ] = [];1556315564 const cachedArray = cache[ indexString ];1556515566 let changed = false;1556715568 for ( let k = 0; k < value.length; k ++ ) {1556915570 if ( hasValueChanged( value[ k ], cachedArray, k ) === true ) changed = true;1557115572 }1557315574 return changed;1557515576 }1557715578 return hasValueChanged( value, cache, indexString );1557915580 }1558115582 function hasValueChanged( value, cache, key ) {1558315584 if ( cache[ key ] === undefined ) {1558515586 1558715588 if ( typeof value === 'number' || typeof value === 'boolean' ) {1558915590 cache[ key ] = value;1559115592 } else if ( ArrayBuffer.isView( value ) ) {1559315594 cache[ key ] = value.slice();1559515596 } else {1559715598 cache[ key ] = value.clone();1559915600 }1560115602 return true;1560315604 } else {1560515606 const cachedObject = cache[ key ];1560715608 1560915610 if ( typeof value === 'number' || typeof value === 'boolean' ) {1561115612 if ( cachedObject !== value ) {1561315614 cache[ key ] = value;15615 return true;1561615617 }1561815619 } else if ( ArrayBuffer.isView( value ) ) {1562015621 15622 return true;1562315624 } else {1562515626 if ( cachedObject.equals( value ) === false ) {1562715628 cachedObject.copy( value );15629 return true;1563015631 }1563215633 }1563415635 }1563615637 return false;1563815639 }1564015641 function prepareUniformsGroup( uniformsGroup ) {1564215643 15644 1564515646 const uniforms = uniformsGroup.uniforms;1564715648 let offset = 0; 15649 const chunkSize = 16; 1565015651 for ( let i = 0, l = uniforms.length; i < l; i ++ ) {1565215653 const uniformArray = Array.isArray( uniforms[ i ] ) ? uniforms[ i ] : [ uniforms[ i ] ];1565415655 for ( let j = 0, jl = uniformArray.length; j < jl; j ++ ) {1565615657 const uniform = uniformArray[ j ];1565815659 const values = Array.isArray( uniform.value ) ? uniform.value : [ uniform.value ];1566015661 15662 const isArray = Array.isArray( uniforms[ i ] ) || Array.isArray( uniform.value );1566315664 let start = offset;1566515666 for ( let k = 0, kl = values.length; k < kl; k ++ ) {1566715668 const value = values[ k ];1566915670 const info = getUniformSize( value, isArray );1567115672 const chunkOffset = offset % chunkSize; 15673 const chunkPadding = chunkOffset % info.boundary; 15674 const chunkStart = chunkOffset + chunkPadding; 1567515676 offset += chunkPadding;1567715678 15679 if ( chunkStart !== 0 && ( chunkSize - chunkStart ) < info.storage ) {1568015681 15682 offset += ( chunkSize - chunkStart );1568315684 }1568515686 if ( k === 0 ) start = offset;1568715688 15689 offset += info.storage;1569015691 }1569215693 15694 const ArrayType = uniform.type === 'int' ? Int32Array : uniform.type === 'uint' ? Uint32Array : Float32Array;15695 uniform.__data = new ArrayType( ( offset - start ) / Float32Array.BYTES_PER_ELEMENT );15696 uniform.__offset = start;1569715698 }1569915700 }1570115702 1570315704 const chunkOffset = offset % chunkSize;1570515706 if ( chunkOffset > 0 ) offset += ( chunkSize - chunkOffset );1570715708 1570915710 uniformsGroup.__size = offset;15711 uniformsGroup.__cache = {};1571215713 return this;1571415715 }1571615717 function getUniformSize( value, isArrayElement ) {1571815719 const info = {15720 boundary: 0, 15721 storage: 0 15722 };1572315724 1572515726 if ( typeof value === 'number' || typeof value === 'boolean' ) {1572715728 1572915730 info.boundary = 4;15731 info.storage = 4;1573215733 } else if ( value.isVector2 ) {1573415735 1573615737 info.boundary = 8;15738 info.storage = 8;1573915740 } else if ( value.isVector3 || value.isColor ) {1574115742 1574315744 info.boundary = 16;15745 info.storage = 12; 1574615747 } else if ( value.isVector4 ) {1574815749 1575015751 info.boundary = 16;15752 info.storage = 16;1575315754 } else if ( value.isMatrix3 ) {1575515756 1575715758 info.boundary = 16;15759 info.storage = 48;1576015761 } else if ( value.isMatrix4 ) {1576215763 1576415765 info.boundary = 16;15766 info.storage = 64;1576715768 } else if ( value.isTexture ) {1576915770 warn( 'WebGLRenderer: Texture samplers can not be part of an uniforms group.' );1577115772 } else if ( ArrayBuffer.isView( value ) ) {1577315774 info.boundary = 16;15775 info.storage = value.byteLength;1577615777 } else {1577815779 warn( 'WebGLRenderer: Unsupported uniform value type.', value );1578015781 }1578215783 if ( isArrayElement === true ) {1578415785 1578615787 info.boundary = 16;15788 info.storage = Math.ceil( info.storage / 16 ) * 16;1578915790 }1579115792 return info;1579315794 }1579515796 function onUniformsGroupsDispose( event ) {1579715798 const uniformsGroup = event.target;1579915800 uniformsGroup.removeEventListener( 'dispose', onUniformsGroupsDispose );1580115802 gl.deleteBuffer( buffers[ uniformsGroup.id ] );1580315804 delete buffers[ uniformsGroup.id ];15805 delete updateList[ uniformsGroup.id ];1580615807 }1580815809 function dispose() {1581015811 for ( const id in buffers ) {1581215813 gl.deleteBuffer( buffers[ id ] );1581415815 }1581615817 buffers = {};15818 updateList = {};1581915820 }1582115822 return {1582315824 bind: bind,15825 update: update,1582615827 dispose: dispose1582815829 };1583015831}1583215833158341583515836158371583815839158401584115842const DATA = new Uint16Array( [15843 0x30b5, 0x3ad1, 0x314c, 0x3a4d, 0x33d2, 0x391c, 0x35ef, 0x3828, 0x37f3, 0x36a6, 0x38d1, 0x3539, 0x3979, 0x3410, 0x39f8, 0x3252, 0x3a53, 0x30f0, 0x3a94, 0x2fc9, 0x3abf, 0x2e35, 0x3ada, 0x2d05, 0x3ae8, 0x2c1f, 0x3aed, 0x2ae0, 0x3aea, 0x29d1, 0x3ae1, 0x28ff,15844 0x3638, 0x38e4, 0x364a, 0x38ce, 0x3699, 0x385e, 0x374e, 0x372c, 0x3839, 0x35a4, 0x38dc, 0x3462, 0x396e, 0x32c4, 0x39de, 0x3134, 0x3a2b, 0x3003, 0x3a59, 0x2e3a, 0x3a6d, 0x2ce1, 0x3a6e, 0x2bba, 0x3a5f, 0x2a33, 0x3a49, 0x290a, 0x3a2d, 0x2826, 0x3a0a, 0x26e8,15845 0x3894, 0x36d7, 0x3897, 0x36c9, 0x38a3, 0x3675, 0x38bc, 0x35ac, 0x38ee, 0x349c, 0x393e, 0x3332, 0x3997, 0x3186, 0x39e2, 0x3038, 0x3a13, 0x2e75, 0x3a29, 0x2cf5, 0x3a2d, 0x2bac, 0x3a21, 0x29ff, 0x3a04, 0x28bc, 0x39dc, 0x2790, 0x39ad, 0x261a, 0x3978, 0x24fa,15846 0x39ac, 0x34a8, 0x39ac, 0x34a3, 0x39ae, 0x3480, 0x39ae, 0x3423, 0x39b1, 0x330e, 0x39c2, 0x31a9, 0x39e0, 0x3063, 0x39fc, 0x2eb5, 0x3a0c, 0x2d1d, 0x3a14, 0x2bcf, 0x3a07, 0x29ff, 0x39e9, 0x28a3, 0x39be, 0x273c, 0x3989, 0x25b3, 0x394a, 0x2488, 0x3907, 0x2345,15847 0x3a77, 0x3223, 0x3a76, 0x321f, 0x3a73, 0x3204, 0x3a6a, 0x31b3, 0x3a58, 0x3114, 0x3a45, 0x303b, 0x3a34, 0x2eb6, 0x3a26, 0x2d31, 0x3a1e, 0x2bef, 0x3a0b, 0x2a0d, 0x39ec, 0x28a1, 0x39c0, 0x271b, 0x3987, 0x2580, 0x3944, 0x2449, 0x38fa, 0x22bd, 0x38ac, 0x2155,15848 0x3b07, 0x2fca, 0x3b06, 0x2fca, 0x3b00, 0x2fb8, 0x3af4, 0x2f7c, 0x3adb, 0x2eea, 0x3ab4, 0x2e00, 0x3a85, 0x2cec, 0x3a5e, 0x2bc5, 0x3a36, 0x2a00, 0x3a0d, 0x2899, 0x39dc, 0x2707, 0x39a0, 0x2562, 0x395a, 0x2424, 0x390b, 0x2268, 0x38b7, 0x20fd, 0x385f, 0x1fd1,15849 0x3b69, 0x2cb9, 0x3b68, 0x2cbb, 0x3b62, 0x2cbb, 0x3b56, 0x2cae, 0x3b3b, 0x2c78, 0x3b0d, 0x2c0a, 0x3acf, 0x2ae3, 0x3a92, 0x2998, 0x3a54, 0x2867, 0x3a17, 0x26d0, 0x39d3, 0x253c, 0x3989, 0x2402, 0x3935, 0x2226, 0x38dc, 0x20bd, 0x387d, 0x1f54, 0x381d, 0x1db3,15850 0x3ba9, 0x296b, 0x3ba8, 0x296f, 0x3ba3, 0x297b, 0x3b98, 0x2987, 0x3b7f, 0x2976, 0x3b4e, 0x2927, 0x3b0e, 0x2895, 0x3ac2, 0x27b7, 0x3a73, 0x263b, 0x3a23, 0x24e7, 0x39d0, 0x239b, 0x3976, 0x21d9, 0x3917, 0x207e, 0x38b2, 0x1ee7, 0x384b, 0x1d53, 0x37c7, 0x1c1e,15851 0x3bd2, 0x25cb, 0x3bd1, 0x25d3, 0x3bcd, 0x25f0, 0x3bc2, 0x261f, 0x3bad, 0x2645, 0x3b7d, 0x262d, 0x3b3e, 0x25c4, 0x3aec, 0x250f, 0x3a93, 0x243a, 0x3a32, 0x22ce, 0x39d0, 0x215b, 0x3969, 0x202a, 0x38fe, 0x1e6e, 0x388f, 0x1cf1, 0x381f, 0x1b9b, 0x3762, 0x19dd,15852 0x3be9, 0x21ab, 0x3be9, 0x21b7, 0x3be5, 0x21e5, 0x3bdd, 0x2241, 0x3bc9, 0x22a7, 0x3ba0, 0x22ec, 0x3b62, 0x22cd, 0x3b0f, 0x2247, 0x3aae, 0x2175, 0x3a44, 0x2088, 0x39d4, 0x1f49, 0x3960, 0x1dbe, 0x38e9, 0x1c77, 0x3870, 0x1ae8, 0x37f1, 0x1953, 0x3708, 0x181b,15853 0x3bf6, 0x1cea, 0x3bf6, 0x1cfb, 0x3bf3, 0x1d38, 0x3bec, 0x1dbd, 0x3bda, 0x1e7c, 0x3bb7, 0x1f25, 0x3b7d, 0x1f79, 0x3b2c, 0x1f4c, 0x3ac6, 0x1ea6, 0x3a55, 0x1dbb, 0x39da, 0x1cbd, 0x395a, 0x1b9d, 0x38d8, 0x1a00, 0x3855, 0x18ac, 0x37ab, 0x173c, 0x36b7, 0x1598,15854 0x3bfc, 0x1736, 0x3bfc, 0x1759, 0x3bf9, 0x17e7, 0x3bf4, 0x1896, 0x3be4, 0x1997, 0x3bc6, 0x1aa8, 0x3b91, 0x1b84, 0x3b43, 0x1bd2, 0x3ade, 0x1b8a, 0x3a65, 0x1acd, 0x39e2, 0x19d3, 0x3957, 0x18cd, 0x38ca, 0x17b3, 0x383e, 0x1613, 0x376d, 0x14bf, 0x366f, 0x135e,15855 0x3bff, 0x101b, 0x3bff, 0x1039, 0x3bfc, 0x10c8, 0x3bf9, 0x1226, 0x3bea, 0x1428, 0x3bcf, 0x1584, 0x3b9f, 0x16c5, 0x3b54, 0x179a, 0x3af0, 0x17ce, 0x3a76, 0x1771, 0x39ea, 0x16a4, 0x3956, 0x15a7, 0x38bf, 0x14a7, 0x3829, 0x1379, 0x3735, 0x11ea, 0x362d, 0x10a1,15856 0x3c00, 0x061b, 0x3c00, 0x066a, 0x3bfe, 0x081c, 0x3bfa, 0x0a4c, 0x3bed, 0x0d16, 0x3bd5, 0x0fb3, 0x3ba9, 0x114d, 0x3b63, 0x127c, 0x3b01, 0x132f, 0x3a85, 0x1344, 0x39f4, 0x12d2, 0x3957, 0x120d, 0x38b5, 0x1122, 0x3817, 0x103c, 0x3703, 0x0ed3, 0x35f0, 0x0d6d,15857 0x3c00, 0x007a, 0x3c00, 0x0089, 0x3bfe, 0x011d, 0x3bfb, 0x027c, 0x3bf0, 0x04fa, 0x3bda, 0x0881, 0x3bb1, 0x0acd, 0x3b6f, 0x0c97, 0x3b10, 0x0d7b, 0x3a93, 0x0df1, 0x39fe, 0x0def, 0x3959, 0x0d8a, 0x38af, 0x0ce9, 0x3808, 0x0c31, 0x36d5, 0x0af0, 0x35b9, 0x09a3,15858 0x3c00, 0x0000, 0x3c00, 0x0001, 0x3bff, 0x0015, 0x3bfb, 0x0059, 0x3bf2, 0x00fd, 0x3bdd, 0x01df, 0x3bb7, 0x031c, 0x3b79, 0x047c, 0x3b1d, 0x05d4, 0x3aa0, 0x06d5, 0x3a08, 0x075a, 0x395d, 0x075e, 0x38aa, 0x06f7, 0x37f4, 0x0648, 0x36ac, 0x0576, 0x3586, 0x049f15859] );1586015861let lut = null;1586215863function getDFGLUT() {1586415865 if ( lut === null ) {1586615867 lut = new DataTexture( DATA, 16, 16, RGFormat, HalfFloatType );15868 lut.name = 'DFG_LUT';15869 lut.minFilter = LinearFilter;15870 lut.magFilter = LinearFilter;15871 lut.wrapS = ClampToEdgeWrapping;15872 lut.wrapT = ClampToEdgeWrapping;15873 lut.generateMipmaps = false;15874 lut.needsUpdate = true;1587515876 }1587715878 return lut;1587915880}15881158821588315884158851588615887class WebGLRenderer {1588815889 1589015891158921589315894 constructor( parameters = {} ) {1589515896 const {15897 canvas = createCanvasElement(),15898 context = null,15899 depth = true,15900 stencil = false,15901 alpha = false,15902 antialias = false,15903 premultipliedAlpha = true,15904 preserveDrawingBuffer = false,15905 powerPreference = 'default',15906 failIfMajorPerformanceCaveat = false,15907 reversedDepthBuffer = false,15908 outputBufferType = UnsignedByteType,15909 } = parameters;1591015911 15912159131591415915159161591715918 this.isWebGLRenderer = true;1591915920 let _alpha;1592115922 if ( context !== null ) {1592315924 if ( typeof WebGLRenderingContext !== 'undefined' && context instanceof WebGLRenderingContext ) {1592515926 throw new Error( 'THREE.WebGLRenderer: WebGL 1 is not supported since r163.' );1592715928 }1592915930 _alpha = context.getContextAttributes().alpha;1593115932 } else {1593315934 _alpha = alpha;1593515936 }1593715938 const _outputBufferType = outputBufferType;1593915940 const INTEGER_FORMATS = new Set( [15941 RGBAIntegerFormat,15942 RGIntegerFormat,15943 RedIntegerFormat15944 ] );1594515946 const UNSIGNED_TYPES = new Set( [15947 UnsignedByteType,15948 UnsignedIntType,15949 UnsignedShortType,15950 UnsignedInt248Type,15951 UnsignedShort4444Type,15952 UnsignedShort5551Type15953 ] );1595415955 const uintClearColor = new Uint32Array( 4 );15956 const intClearColor = new Int32Array( 4 );15957 const lightProbeGridUniforms = { textures: [], min: [], max: [], resolution: [] };1595815959 let currentRenderList = null;15960 let currentRenderState = null;1596115962 15963 1596415965 const renderListStack = [];15966 const renderStateStack = [];1596715968 1596915970 let output = null;1597115972 1597315974 159751597615977159781597915980159811598215983 this.domElement = canvas;1598415985 159861598715988159891599015991159921599315994159951599615997159981599916000 this.debug = {1600116002 16003160041600516006 checkShaderErrors: true,16007 1600816009160101601116012 diagnostics: {16013 keywords: false16014 },16015 16016160171601816019 onShaderError: null16020 };1602116022 1602316024 160251602616027160281602916030 this.autoClear = true;1603116032 16033160341603516036160371603816039 this.autoClearColor = true;1604016041 16042160431604416045160461604716048 this.autoClearDepth = true;1604916050 16051160521605316054160551605616057 this.autoClearStencil = true;1605816059 1606016061 160621606316064160651606616067160681606916070160711607216073 this.sortObjects = true;1607416075 1607616077 160781607916080160811608216083 this.clippingPlanes = [];1608416085 160861608716088160891609016091 this.localClippingEnabled = false;1609216093 1609416095 160961609716098160991610016101 this.toneMapping = NoToneMapping;1610216103 161041610516106161071610816109 this.toneMappingExposure = 1.0;1611016111 1611216113 1611416115161161611716118161191612016121 this.transmissionResolutionScale = 1.0;1612216123 1612416125 const _this = this;1612616127 let _isContextLost = false;16128 let _nodesHandler = null;1612916130 let _scratchFramebuffer = null;16131 let _srcFramebuffer = null;16132 let _dstFramebuffer = null;1613316134 1613516136 this._outputColorSpace = SRGBColorSpace;1613716138 let _currentActiveCubeFace = 0;16139 let _currentActiveMipmapLevel = 0;16140 let _currentRenderTarget = null;16141 let _currentMaterialId = -1;1614216143 let _currentCamera = null;1614416145 const _currentViewport = new Vector4();16146 const _currentScissor = new Vector4();16147 let _currentScissorTest = null;1614816149 const _currentClearColor = new Color( 0x000000 );16150 let _currentClearAlpha = 0;1615116152 1615316154 let _width = canvas.width;16155 let _height = canvas.height;1615616157 let _pixelRatio = 1;16158 let _opaqueSort = null;16159 let _transparentSort = null;1616016161 const _viewport = new Vector4( 0, 0, _width, _height );16162 const _scissor = new Vector4( 0, 0, _width, _height );16163 let _scissorTest = false;1616416165 1616616167 const _frustum = new Frustum();16168 const _frustumArray = new FrustumArray();1616916170 1617116172 let _clippingEnabled = false;16173 let _localClippingEnabled = false;1617416175 1617616177 const _projScreenMatrix = new Matrix4();1617816179 const _vector3 = new Vector3();1618016181 const _vector4 = new Vector4();1618216183 const _emptyScene = { background: null, fog: null, environment: null, overrideMaterial: null, isScene: true };1618416185 let _renderBackground = false;1618616187 function getTargetPixelRatio() {1618816189 return _currentRenderTarget === null ? _pixelRatio : 1;1619016191 }1619216193 1619416195 let _gl = context;1619616197 function getContext( contextName, contextAttributes ) {1619816199 return canvas.getContext( contextName, contextAttributes );1620016201 }1620216203 let extensions, capabilities, state, info;16204 let properties, textures, environments, attributes, geometries, objects;16205 let programCache, materials, renderLists, renderStates, clipping, shadowMap;1620616207 let background, morphtargets, bufferRenderer, indexedBufferRenderer;1620816209 let utils, bindingStates, uniformsGroups;1621016211 try {1621216213 const contextAttributes = {16214 alpha: true,16215 depth,16216 stencil,16217 antialias,16218 premultipliedAlpha,16219 preserveDrawingBuffer,16220 powerPreference,16221 failIfMajorPerformanceCaveat,16222 };1622316224 16225 if ( 'setAttribute' in canvas ) canvas.setAttribute( 'data-engine', `three.js r${REVISION}` );1622616227 16228 canvas.addEventListener( 'webglcontextlost', onContextLost, false );16229 canvas.addEventListener( 'webglcontextrestored', onContextRestore, false );16230 canvas.addEventListener( 'webglcontextcreationerror', onContextCreationError, false );1623116232 if ( _gl === null ) {1623316234 const contextName = 'webgl2';1623516236 _gl = getContext( contextName, contextAttributes );1623716238 if ( _gl === null ) {1623916240 if ( getContext( contextName ) ) {1624116242 throw new Error( 'THREE.WebGLRenderer: Error creating WebGL context with your selected attributes.' );1624316244 } else {1624516246 throw new Error( 'THREE.WebGLRenderer: Error creating WebGL context.' );1624716248 }1624916250 }1625116252 }1625316254 initGLContext();1625516256 } catch ( e ) {1625716258 canvas.removeEventListener( 'webglcontextlost', onContextLost, false );16259 canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false );16260 canvas.removeEventListener( 'webglcontextcreationerror', onContextCreationError, false );1626116262 error( 'WebGLRenderer: ' + e.message );16263 throw e;1626416265 }1626616267 function initGLContext() {1626816269 extensions = new WebGLExtensions( _gl );16270 extensions.init();1627116272 utils = new WebGLUtils( _gl, extensions );1627316274 capabilities = new WebGLCapabilities( _gl, extensions, parameters, utils );1627516276 state = new WebGLState( _gl, extensions );1627716278 if ( capabilities.reversedDepthBuffer && reversedDepthBuffer ) {1627916280 state.buffers.depth.setReversed( true );1628116282 }1628316284 _scratchFramebuffer = _gl.createFramebuffer();16285 _srcFramebuffer = _gl.createFramebuffer();16286 _dstFramebuffer = _gl.createFramebuffer();1628716288 info = new WebGLInfo( _gl );16289 properties = new WebGLProperties();16290 textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );16291 environments = new WebGLEnvironments( _this );16292 attributes = new WebGLAttributes( _gl );16293 bindingStates = new WebGLBindingStates( _gl, attributes );16294 geometries = new WebGLGeometries( _gl, attributes, info, bindingStates );16295 objects = new WebGLObjects( _gl, geometries, attributes, bindingStates, info );16296 morphtargets = new WebGLMorphtargets( _gl, capabilities, textures );16297 clipping = new WebGLClipping( properties );16298 programCache = new WebGLPrograms( _this, environments, extensions, capabilities, bindingStates, clipping );16299 materials = new WebGLMaterials( _this, properties );16300 renderLists = new WebGLRenderLists();16301 renderStates = new WebGLRenderStates( extensions );16302 background = new WebGLBackground( _this, environments, state, objects, _alpha, premultipliedAlpha );16303 shadowMap = new WebGLShadowMap( _this, objects, capabilities );16304 uniformsGroups = new WebGLUniformsGroups( _gl, info, capabilities, state );1630516306 bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info );16307 indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, info );1630816309 info.programs = programCache.programs;1631016311 163121631316314163151631616317 _this.capabilities = capabilities;1631816319 16320163211632216323163241632516326163271632816329 _this.extensions = extensions;1633016331 163321633316334163351633616337 _this.properties = properties;1633816339 163401634116342163431634416345 _this.renderLists = renderLists;16346163471634816349 163501635116352163531635416355 _this.shadowMap = shadowMap;1635616357 163581635916360163611636216363 _this.state = state;1636416365 16366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384 _this.info = info;1638516386 }1638716388 1638916390 if ( _outputBufferType !== UnsignedByteType ) {1639116392 output = new WebGLOutput( _outputBufferType, canvas.width, canvas.height, antialias, depth, stencil );1639316394 }1639516396 1639716398 const xr = new WebXRManager( _this, _gl );1639916400 1640116402164031640416405 this.xr = xr;1640616407 1640816409164101641116412 this.getContext = function () {1641316414 return _gl;1641516416 };1641716418 1641916420164211642216423 this.getContextAttributes = function () {1642416425 return _gl.getContextAttributes();1642616427 };1642816429 164301643116432 this.forceContextLoss = function () {1643316434 const extension = extensions.get( 'WEBGL_lose_context' );16435 if ( extension ) extension.loseContext();1643616437 };1643816439 164401644116442 this.forceContextRestore = function () {1644316444 const extension = extensions.get( 'WEBGL_lose_context' );16445 if ( extension ) extension.restoreContext();1644616447 };1644816449 1645016451164521645316454 this.getPixelRatio = function () {1645516456 return _pixelRatio;1645716458 };1645916460 1646116462164631646416465 this.setPixelRatio = function ( value ) {1646616467 if ( value === undefined ) return;1646816469 _pixelRatio = value;1647016471 this.setSize( _width, _height, false );1647216473 };1647416475 164761647716478164791648016481 this.getSize = function ( target ) {1648216483 return target.set( _width, _height );1648416485 };1648616487 164881648916490164911649216493164941649516496 this.setSize = function ( width, height, updateStyle = true ) {1649716498 if ( xr.isPresenting ) {1649916500 warn( 'WebGLRenderer: Can\'t change size while VR device is presenting.' );16501 return;1650216503 }1650416505 _width = width;16506 _height = height;1650716508 canvas.width = Math.floor( width * _pixelRatio );16509 canvas.height = Math.floor( height * _pixelRatio );1651016511 if ( updateStyle === true ) {1651216513 canvas.style.width = width + 'px';16514 canvas.style.height = height + 'px';1651516516 }1651716518 if ( output !== null ) {1651916520 output.setSize( canvas.width, canvas.height );1652116522 }1652316524 this.setViewport( 0, 0, width, height );1652516526 };1652716528 165291653016531165321653316534 this.getDrawingBufferSize = function ( target ) {1653516536 return target.set( _width * _pixelRatio, _height * _pixelRatio ).floor();1653716538 };1653916540 16541165421654316544165451654616547165481654916550165511655216553 this.setDrawingBufferSize = function ( width, height, pixelRatio ) {1655416555 _width = width;16556 _height = height;1655716558 _pixelRatio = pixelRatio;1655916560 canvas.width = Math.floor( width * pixelRatio );16561 canvas.height = Math.floor( height * pixelRatio );1656216563 this.setViewport( 0, 0, width, height );1656416565 };1656616567 1656816569165701657116572 this.setEffects = function ( effects ) {1657316574 if ( _outputBufferType === UnsignedByteType ) {1657516576 error( 'WebGLRenderer: setEffects() requires outputBufferType set to HalfFloatType or FloatType.' );16577 return;1657816579 }1658016581 if ( effects ) {1658216583 for ( let i = 0; i < effects.length; i ++ ) {1658416585 if ( effects[ i ].isOutputPass === true ) {1658616587 warn( 'WebGLRenderer: OutputPass is not needed in setEffects(). Tone mapping and color space conversion are applied automatically.' );16588 break;1658916590 }1659116592 }1659316594 }1659516596 output.setEffects( effects || [] );1659716598 };1659916600 166011660216603166041660516606 this.getCurrentViewport = function ( target ) {1660716608 return target.copy( _currentViewport );1660916610 };1661116612 166131661416615166161661716618 this.getViewport = function ( target ) {1661916620 return target.copy( _viewport );1662116622 };1662316624 166251662616627166281662916630166311663216633 this.setViewport = function ( x, y, width, height ) {1663416635 if ( x.isVector4 ) {1663616637 _viewport.set( x.x, x.y, x.z, x.w );1663816639 } else {1664016641 _viewport.set( x, y, width, height );1664216643 }1664416645 state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( getTargetPixelRatio() ).round() );1664616647 };1664816649 166501665116652166531665416655 this.getScissor = function ( target ) {1665616657 return target.copy( _scissor );1665816659 };1666016661 166621666316664166651666616667166681666916670 this.setScissor = function ( x, y, width, height ) {1667116672 if ( x.isVector4 ) {1667316674 _scissor.set( x.x, x.y, x.z, x.w );1667516676 } else {1667716678 _scissor.set( x, y, width, height );1667916680 }1668116682 state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( getTargetPixelRatio() ).round() );1668316684 };1668516686 1668716688166891669016691 this.getScissorTest = function () {1669216693 return _scissorTest;1669416695 };1669616697 16698166991670016701167021670316704 this.setScissorTest = function ( boolean ) {1670516706 state.setScissorTest( _scissorTest = boolean );1670716708 };1670916710 167111671216713167141671516716 this.setOpaqueSort = function ( method ) {1671716718 _opaqueSort = method;1671916720 };1672116722 167231672416725167261672716728 this.setTransparentSort = function ( method ) {1672916730 _transparentSort = method;1673116732 };1673316734 1673516736 167371673816739167401674116742 this.getClearColor = function ( target ) {1674316744 return target.copy( background.getClearColor() );1674516746 };1674716748 167491675016751167521675316754 this.setClearColor = function () {1675516756 background.setClearColor( ...arguments );1675716758 };1675916760 1676116762167631676416765 this.getClearAlpha = function () {1676616767 return background.getClearAlpha();1676816769 };1677016771 1677216773167741677516776 this.setClearAlpha = function () {1677716778 background.setClearAlpha( ...arguments );1677916780 };1678116782 1678316784167851678616787167881678916790 this.clear = function ( color = true, depth = true, stencil = true ) {1679116792 let bits = 0;1679316794 if ( color ) {1679516796 16797 let isIntegerFormat = false;16798 if ( _currentRenderTarget !== null ) {1679916800 const targetFormat = _currentRenderTarget.texture.format;16801 isIntegerFormat = INTEGER_FORMATS.has( targetFormat );1680216803 }1680416805 16806 16807 if ( isIntegerFormat ) {1680816809 const targetType = _currentRenderTarget.texture.type;16810 const isUnsignedType = UNSIGNED_TYPES.has( targetType );1681116812 const clearColor = background.getClearColor();16813 const a = background.getClearAlpha();16814 const r = clearColor.r;16815 const g = clearColor.g;16816 const b = clearColor.b;1681716818 if ( isUnsignedType ) {1681916820 uintClearColor[ 0 ] = r;16821 uintClearColor[ 1 ] = g;16822 uintClearColor[ 2 ] = b;16823 uintClearColor[ 3 ] = a;16824 _gl.clearBufferuiv( _gl.COLOR, 0, uintClearColor );1682516826 } else {1682716828 intClearColor[ 0 ] = r;16829 intClearColor[ 1 ] = g;16830 intClearColor[ 2 ] = b;16831 intClearColor[ 3 ] = a;16832 _gl.clearBufferiv( _gl.COLOR, 0, intClearColor );1683316834 }1683516836 } else {1683716838 bits |= _gl.COLOR_BUFFER_BIT;1683916840 }1684116842 }1684316844 if ( depth ) {1684516846 bits |= _gl.DEPTH_BUFFER_BIT;16847 this.state.buffers.depth.setMask( true );1684816849 }1685016851 if ( stencil ) {1685216853 bits |= _gl.STENCIL_BUFFER_BIT;16854 this.state.buffers.stencil.setMask( 0xffffffff );1685516856 }1685716858 if ( bits !== 0 ) {1685916860 _gl.clear( bits );1686116862 }1686316864 };1686516866 168671686816869 this.clearColor = function () {1687016871 this.clear( true, false, false );1687216873 };1687416875 168761687716878 this.clearDepth = function () {1687916880 this.clear( false, true, false );1688116882 };1688316884 168851688616887 this.clearStencil = function () {1688816889 this.clear( false, false, true );1689016891 };1689216893 16894168951689616897168981689916900 this.setNodesHandler = function ( nodesHandler ) {1690116902 nodesHandler.setRenderer( this );16903 _nodesHandler = nodesHandler;1690416905 };1690616907 16908169091691016911 this.dispose = function () {1691216913 canvas.removeEventListener( 'webglcontextlost', onContextLost, false );16914 canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false );16915 canvas.removeEventListener( 'webglcontextcreationerror', onContextCreationError, false );1691616917 background.dispose();16918 renderLists.dispose();16919 renderStates.dispose();16920 textures.dispose();16921 properties.dispose();16922 environments.dispose();16923 objects.dispose();16924 geometries.dispose();16925 bindingStates.dispose();16926 uniformsGroups.dispose();16927 programCache.dispose();1692816929 xr.dispose();1693016931 xr.removeEventListener( 'sessionstart', onXRSessionStart );16932 xr.removeEventListener( 'sessionend', onXRSessionEnd );1693316934 animation.stop();1693516936 };1693716938 1693916940 function onContextLost( event ) {1694116942 event.preventDefault();1694316944 log( 'WebGLRenderer: Context Lost.' );1694516946 _isContextLost = true;1694716948 }1694916950 function onContextRestore( ) {1695116952 log( 'WebGLRenderer: Context Restored.' );1695316954 _isContextLost = false;1695516956 const infoAutoReset = info.autoReset;16957 const shadowMapEnabled = shadowMap.enabled;16958 const shadowMapAutoUpdate = shadowMap.autoUpdate;16959 const shadowMapNeedsUpdate = shadowMap.needsUpdate;16960 const shadowMapType = shadowMap.type;1696116962 initGLContext();1696316964 info.autoReset = infoAutoReset;16965 shadowMap.enabled = shadowMapEnabled;16966 shadowMap.autoUpdate = shadowMapAutoUpdate;16967 shadowMap.needsUpdate = shadowMapNeedsUpdate;16968 shadowMap.type = shadowMapType;1696916970 }1697116972 function onContextCreationError( event ) {1697316974 error( 'WebGLRenderer: A WebGL context could not be created. Reason: ', event.statusMessage );1697516976 }1697716978 function onMaterialDispose( event ) {1697916980 const material = event.target;1698116982 material.removeEventListener( 'dispose', onMaterialDispose );1698316984 deallocateMaterial( material );1698516986 }1698716988 1698916990 function deallocateMaterial( material ) {1699116992 releaseMaterialProgramReferences( material );1699316994 properties.remove( material );1699516996 }169971699816999 function releaseMaterialProgramReferences( material ) {1700017001 const programs = properties.get( material ).programs;1700217003 if ( programs !== undefined ) {1700417005 programs.forEach( function ( program ) {1700617007 programCache.releaseProgram( program );1700817009 } );1701017011 if ( material.isShaderMaterial ) {1701217013 programCache.releaseShaderCache( material );1701417015 }1701617017 }1701817019 }1702017021 1702217023 this.renderBufferDirect = function ( camera, scene, geometry, material, object, group ) {1702417025 if ( scene === null ) scene = _emptyScene; 1702617027 const frontFaceCW = ( object.isMesh && object.matrixWorld.determinantAffine() < 0 );1702817029 const program = setProgram( camera, scene, geometry, material, object );1703017031 state.setMaterial( material, frontFaceCW );1703217033 1703417035 let index = geometry.index;17036 let rangeFactor = 1;1703717038 if ( material.wireframe === true ) {1703917040 index = geometries.getWireframeAttribute( geometry );1704117042 if ( index === undefined ) return;1704317044 rangeFactor = 2;1704517046 }1704717048 1704917050 const drawRange = geometry.drawRange;17051 const position = geometry.attributes.position;1705217053 let drawStart = drawRange.start * rangeFactor;17054 let drawEnd = ( drawRange.start + drawRange.count ) * rangeFactor;1705517056 if ( group !== null ) {1705717058 drawStart = Math.max( drawStart, group.start * rangeFactor );17059 drawEnd = Math.min( drawEnd, ( group.start + group.count ) * rangeFactor );1706017061 }1706217063 if ( index !== null ) {1706417065 drawStart = Math.max( drawStart, 0 );17066 drawEnd = Math.min( drawEnd, index.count );1706717068 } else if ( position !== undefined && position !== null ) {1706917070 drawStart = Math.max( drawStart, 0 );17071 drawEnd = Math.min( drawEnd, position.count );1707217073 }1707417075 const drawCount = drawEnd - drawStart;1707617077 if ( drawCount < 0 || drawCount === Infinity ) return;1707817079 1708017081 bindingStates.setup( object, material, program, geometry, index );1708217083 let attribute;17084 let renderer = bufferRenderer;1708517086 if ( index !== null ) {1708717088 attribute = attributes.get( index );1708917090 renderer = indexedBufferRenderer;17091 renderer.setIndex( attribute );1709217093 }1709417095 1709617097 if ( object.isMesh ) {1709817099 if ( material.wireframe === true ) {1710017101 state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );17102 renderer.setMode( _gl.LINES );1710317104 } else {1710517106 renderer.setMode( _gl.TRIANGLES );1710717108 }1710917110 } else if ( object.isLine ) {1711117112 let lineWidth = material.linewidth;1711317114 if ( lineWidth === undefined ) lineWidth = 1; 1711517116 state.setLineWidth( lineWidth * getTargetPixelRatio() );1711717118 if ( object.isLineSegments ) {1711917120 renderer.setMode( _gl.LINES );1712117122 } else if ( object.isLineLoop ) {1712317124 renderer.setMode( _gl.LINE_LOOP );1712517126 } else {1712717128 renderer.setMode( _gl.LINE_STRIP );1712917130 }1713117132 } else if ( object.isPoints ) {1713317134 renderer.setMode( _gl.POINTS );1713517136 } else if ( object.isSprite ) {1713717138 renderer.setMode( _gl.TRIANGLES );1713917140 }1714117142 if ( object.isBatchedMesh ) {1714317144 if ( ! extensions.get( 'WEBGL_multi_draw' ) ) {1714517146 const starts = object._multiDrawStarts;17147 const counts = object._multiDrawCounts;17148 const drawCount = object._multiDrawCount;17149 const bytesPerElement = index ? attributes.get( index ).bytesPerElement : 1;17150 const uniforms = properties.get( material ).currentProgram.getUniforms();17151 for ( let i = 0; i < drawCount; i ++ ) {1715217153 uniforms.setValue( _gl, '_gl_DrawID', i );17154 renderer.render( starts[ i ] / bytesPerElement, counts[ i ] );1715517156 }1715717158 } else {1715917160 renderer.renderMultiDraw( object._multiDrawStarts, object._multiDrawCounts, object._multiDrawCount );1716117162 }1716317164 } else if ( object.isInstancedMesh ) {1716517166 renderer.renderInstances( drawStart, drawCount, object.count );1716717168 } else if ( geometry.isInstancedBufferGeometry ) {1716917170 const maxInstanceCount = geometry._maxInstanceCount !== undefined ? geometry._maxInstanceCount : Infinity;17171 const instanceCount = Math.min( geometry.instanceCount, maxInstanceCount );1717217173 renderer.renderInstances( drawStart, drawCount, instanceCount );1717417175 } else {1717617177 renderer.render( drawStart, drawCount );1717817179 }1718017181 };1718217183 1718417185 function prepareMaterial( material, scene, camera, object ) {1718617187 if ( _nodesHandler !== null && material.isNodeMaterial ) _nodesHandler.setObject( object, material );1718817189 if ( _clippingEnabled === true ) clipping.setState( material, camera, false );1719017191 if ( material.transparent === true && material.side === DoubleSide && material.forceSinglePass === false ) {1719217193 material.side = BackSide;17194 material.needsUpdate = true;17195 getProgram( material, scene, object );1719617197 material.side = FrontSide;17198 material.needsUpdate = true;17199 getProgram( material, scene, object );1720017201 material.side = DoubleSide;1720217203 } else {1720417205 getProgram( material, scene, object );1720617207 }1720817209 }1721017211 172121721317214172151721617217172181721917220172211722217223 this.compile = function ( scene, camera, targetScene = null ) {1722417225 if ( targetScene === null ) targetScene = scene;17226 if ( _nodesHandler !== null ) _nodesHandler.renderStart( scene, camera, targetScene );1722717228 currentRenderState = renderStates.get( targetScene );17229 currentRenderState.init( camera );1723017231 renderStateStack.push( currentRenderState );1723217233 1723417235 targetScene.traverseVisible( function ( object ) {1723617237 if ( object.isLight && object.layers.test( camera.layers ) ) {1723817239 currentRenderState.pushLight( object );1724017241 if ( object.castShadow ) {1724217243 currentRenderState.pushShadow( object );1724417245 }1724617247 }1724817249 } );1725017251 if ( scene !== targetScene ) {1725217253 scene.traverseVisible( function ( object ) {1725417255 if ( object.isLight && object.layers.test( camera.layers ) ) {1725617257 currentRenderState.pushLight( object );1725817259 if ( object.castShadow ) {1726017261 currentRenderState.pushShadow( object );1726217263 }1726417265 }1726617267 } );1726817269 }1727017271 currentRenderState.setupLights();17272 if ( _nodesHandler !== null ) _nodesHandler.updateLights( currentRenderState.state.lightsArray );1727317274 _localClippingEnabled = this.localClippingEnabled;17275 _clippingEnabled = clipping.init( this.clippingPlanes, _localClippingEnabled );1727617277 if ( _clippingEnabled === true ) clipping.setGlobalState( this.clippingPlanes, camera );1727817279 1728017281 if ( _nodesHandler !== null ) shadowMap.render( currentRenderState.state.shadowsArray, targetScene, camera );1728217283 1728417285 const materials = new Set();1728617287 scene.traverse( function ( object ) {1728817289 if ( ! ( object.isMesh || object.isPoints || object.isLine || object.isSprite ) ) {1729017291 return;1729217293 }1729417295 const material = object.material;1729617297 if ( material ) {1729817299 if ( Array.isArray( material ) ) {1730017301 for ( let i = 0; i < material.length; i ++ ) {1730217303 const material2 = material[ i ];1730417305 prepareMaterial( material2, targetScene, camera, object );17306 materials.add( material2 );1730717308 }1730917310 } else {1731117312 prepareMaterial( material, targetScene, camera, object );17313 materials.add( material );1731417315 }1731617317 }1731817319 } );1732017321 currentRenderState = renderStateStack.pop();17322 if ( _nodesHandler !== null ) _nodesHandler.renderEnd();1732317324 return materials;1732517326 };1732717328 1732917330 173311733217333173341733517336173371733817339173401734117342 this.compileAsync = function ( scene, camera, targetScene = null ) {1734317344 const materials = this.compile( scene, camera, targetScene );1734517346 17347 1734817349 return new Promise( ( resolve ) => {1735017351 function checkMaterialsReady() {1735217353 materials.forEach( function ( material ) {1735417355 const materialProperties = properties.get( material );17356 const program = materialProperties.currentProgram;1735717358 if ( program === undefined || program.isReady() ) {1735917360 17361 materials.delete( material );1736217363 }1736417365 } );1736617367 1736817369 if ( materials.size === 0 ) {1737017371 resolve( scene );17372 return;1737317374 }1737517376 1737717378 setTimeout( checkMaterialsReady, 10 );1737917380 }1738117382 if ( extensions.get( 'KHR_parallel_shader_compile' ) !== null ) {1738317384 17385 1738617387 checkMaterialsReady();1738817389 } else {1739017391 17392 1739317394 setTimeout( checkMaterialsReady, 10 );1739517396 }1739717398 } );1739917400 };1740117402 1740317404 let onAnimationFrameCallback = null;1740517406 function onAnimationFrame( time ) {1740717408 if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );1740917410 }1741117412 function onXRSessionStart() {1741317414 animation.stop();1741517416 }1741717418 function onXRSessionEnd() {1741917420 animation.start();1742117422 }1742317424 const animation = new WebGLAnimation();17425 animation.setAnimationLoop( onAnimationFrame );1742617427 if ( typeof self !== 'undefined' ) animation.setContext( self );1742817429 17430174311743217433174341743517436 this.setAnimationLoop = function ( callback ) {1743717438 onAnimationFrameCallback = callback;17439 xr.setAnimationLoop( callback );1744017441 ( callback === null ) ? animation.stop() : animation.start();1744217443 };1744417445 xr.addEventListener( 'sessionstart', onXRSessionStart );17446 xr.addEventListener( 'sessionend', onXRSessionEnd );1744717448 1744917450 1745117452174531745417455174561745717458174591746017461174621746317464 this.render = function ( scene, camera ) {1746517466 if ( camera !== undefined && camera.isCamera !== true ) {1746717468 error( 'WebGLRenderer.render: camera is not an instance of THREE.Camera.' );17469 return;1747017471 }1747217473 if ( _isContextLost === true ) return;1747417475 17476 if ( _nodesHandler !== null ) {1747717478 _nodesHandler.renderStart( scene, camera );1747917480 }1748117482 1748317484 const isXRPresenting = xr.enabled === true && xr.isPresenting === true;1748517486 const useOutput = output !== null && ( _currentRenderTarget === null || isXRPresenting ) && output.begin( _this, _currentRenderTarget );1748717488 1748917490 if ( scene.matrixWorldAutoUpdate === true ) scene.updateMatrixWorld();1749117492 1749317494 if ( camera.parent === null && camera.matrixWorldAutoUpdate === true ) camera.updateMatrixWorld();1749517496 if ( xr.enabled === true && xr.isPresenting === true && ( output === null || output.isCompositing() === false ) ) {1749717498 if ( xr.cameraAutoUpdate === true ) xr.updateCamera( camera );1749917500 camera = xr.getCamera(); 1750117502 }1750317504 17505 if ( scene.isScene === true ) scene.onBeforeRender( _this, scene, camera, _currentRenderTarget );1750617507 currentRenderState = renderStates.get( scene, renderStateStack.length );17508 currentRenderState.init( camera );1750917510 currentRenderState.state.textureUnits = textures.getTextureUnits();17511 renderStateStack.push( currentRenderState );1751217513 _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );1751417515 if ( camera.isArrayCamera ) {1751617517 _frustumArray.setFromArrayCamera( camera );1751817519 } else {1752017521 _frustum.setFromProjectionMatrix( _projScreenMatrix, WebGLCoordinateSystem, camera.reversedDepth );1752217523 }1752417525 _localClippingEnabled = this.localClippingEnabled;17526 _clippingEnabled = clipping.init( this.clippingPlanes, _localClippingEnabled );1752717528 currentRenderList = renderLists.get( scene, renderListStack.length );17529 currentRenderList.init();1753017531 renderListStack.push( currentRenderList );1753217533 this.info.render.frame ++; 1753417535 if ( xr.enabled === true && xr.isPresenting === true ) {1753617537 const depthSensingMesh = _this.xr.getDepthSensingMesh();1753817539 if ( depthSensingMesh !== null ) {1754017541 projectObject( depthSensingMesh, camera, - Infinity, _this.sortObjects );1754217543 }1754417545 }1754617547 projectObject( scene, camera, 0, _this.sortObjects );1754817549 currentRenderList.finish();17550 if ( _nodesHandler !== null ) _nodesHandler.updateLights( currentRenderState.state.lightsArray );1755117552 if ( _this.sortObjects === true ) {1755317554 currentRenderList.sort( _opaqueSort, _transparentSort );1755517556 }1755717558 _renderBackground = xr.enabled === false || xr.isPresenting === false || xr.hasDepthSensing() === false;17559 if ( _renderBackground ) {1756017561 background.addToRenderList( currentRenderList, scene );1756217563 }1756417565 1756617567 if ( this.info.autoReset === true ) this.info.reset();1756817569 if ( _clippingEnabled === true ) clipping.beginShadows();1757017571 const shadowsArray = currentRenderState.state.shadowsArray;1757217573 shadowMap.render( shadowsArray, scene, camera );1757417575 if ( _clippingEnabled === true ) clipping.endShadows();1757617577 1757817579 1758017581 const skipSceneRender = useOutput && output.hasRenderPass();1758217583 if ( skipSceneRender === false ) {1758417585 const opaqueObjects = currentRenderList.opaque;17586 const transmissiveObjects = currentRenderList.transmissive;1758717588 currentRenderState.setupLights();1758917590 if ( camera.isArrayCamera ) {1759117592 const cameras = camera.cameras;1759317594 if ( transmissiveObjects.length > 0 ) {1759517596 for ( let i = 0, l = cameras.length; i < l; i ++ ) {1759717598 const camera2 = cameras[ i ];1759917600 renderTransmissionPass( opaqueObjects, transmissiveObjects, scene, camera2 );1760117602 }1760317604 }1760517606 if ( _renderBackground ) background.render( scene );1760717608 for ( let i = 0, l = cameras.length; i < l; i ++ ) {1760917610 const camera2 = cameras[ i ];1761117612 renderScene( currentRenderList, scene, camera2, camera2.viewport );1761317614 }1761517616 } else {1761717618 if ( transmissiveObjects.length > 0 ) renderTransmissionPass( opaqueObjects, transmissiveObjects, scene, camera );1761917620 if ( _renderBackground ) background.render( scene );1762117622 renderScene( currentRenderList, scene, camera );1762317624 }1762517626 }1762717628 1762917630 if ( _currentRenderTarget !== null && _currentActiveMipmapLevel === 0 ) {1763117632 1763317634 textures.updateMultisampleRenderTarget( _currentRenderTarget );1763517636 1763717638 textures.updateRenderTargetMipmap( _currentRenderTarget );1763917640 }1764117642 1764317644 if ( useOutput ) {1764517646 output.end( _this );1764717648 }1764917650 1765117652 if ( scene.isScene === true ) scene.onAfterRender( _this, scene, camera );1765317654 1765517656 bindingStates.resetDefaultState();17657 _currentMaterialId = -1;17658 _currentCamera = null;1765917660 renderStateStack.pop();1766117662 if ( renderStateStack.length > 0 ) {1766317664 currentRenderState = renderStateStack[ renderStateStack.length - 1 ];1766517666 textures.setTextureUnits( currentRenderState.state.textureUnits );1766717668 if ( _clippingEnabled === true ) clipping.setGlobalState( _this.clippingPlanes, currentRenderState.state.camera );1766917670 } else {1767117672 currentRenderState = null;1767317674 }1767517676 renderListStack.pop();1767717678 if ( renderListStack.length > 0 ) {1767917680 currentRenderList = renderListStack[ renderListStack.length - 1 ];1768117682 } else {1768317684 currentRenderList = null;1768517686 }1768717688 if ( _nodesHandler !== null ) {1768917690 _nodesHandler.renderEnd();1769117692 }1769317694 };1769517696 function projectObject( object, camera, groupOrder, sortObjects ) {1769717698 if ( object.visible === false ) return;1769917700 const visible = object.layers.test( camera.layers );1770117702 if ( visible ) {1770317704 if ( object.isGroup ) {1770517706 groupOrder = object.renderOrder;1770717708 } else if ( object.isLOD ) {1770917710 if ( object.autoUpdate === true ) object.update( camera );1771117712 } else if ( object.isLight ) {1771317714 currentRenderState.pushLight( object );1771517716 if ( object.castShadow ) {1771717718 currentRenderState.pushShadow( object );1771917720 }1772117722 } else if ( object.isSprite ) {1772317724 const frustum = camera.isArrayCamera ? _frustumArray : _frustum;1772517726 if ( ! object.frustumCulled || object.intersectsFrustum( frustum ) ) {1772717728 if ( sortObjects ) {1772917730 _vector4.setFromMatrixPosition( object.matrixWorld )17731 .applyMatrix4( _projScreenMatrix );1773217733 }1773417735 const geometry = objects.update( object );17736 const material = object.material;1773717738 if ( material.visible ) {1773917740 currentRenderList.push( object, geometry, material, groupOrder, _vector4.z, null, camera );1774117742 }1774317744 }1774517746 } else if ( object.isMesh || object.isLine || object.isPoints ) {1774717748 const frustum = camera.isArrayCamera ? _frustumArray : _frustum;1774917750 if ( ! object.frustumCulled || object.intersectsFrustum( frustum ) ) {1775117752 const geometry = objects.update( object );17753 const material = object.material;1775417755 if ( sortObjects ) {1775617757 if ( object.boundingSphere !== undefined ) {1775817759 if ( object.boundingSphere === null ) object.computeBoundingSphere();17760 _vector4.copy( object.boundingSphere.center );1776117762 } else {1776317764 if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();17765 _vector4.copy( geometry.boundingSphere.center );1776617767 }1776817769 _vector417770 .applyMatrix4( object.matrixWorld )17771 .applyMatrix4( _projScreenMatrix );1777217773 }1777417775 if ( Array.isArray( material ) ) {1777617777 const groups = geometry.groups;1777817779 for ( let i = 0, l = groups.length; i < l; i ++ ) {1778017781 const group = groups[ i ];17782 const groupMaterial = material[ group.materialIndex ];1778317784 if ( groupMaterial && groupMaterial.visible ) {1778517786 currentRenderList.push( object, geometry, groupMaterial, groupOrder, _vector4.z, group, camera );1778717788 }1778917790 }1779117792 } else if ( material.visible ) {1779317794 currentRenderList.push( object, geometry, material, groupOrder, _vector4.z, null, camera );1779517796 }1779717798 }1779917800 }1780117802 }1780317804 const children = object.children;1780517806 for ( let i = 0, l = children.length; i < l; i ++ ) {1780717808 projectObject( children[ i ], camera, groupOrder, sortObjects );1780917810 }1781117812 }1781317814 function renderScene( currentRenderList, scene, camera, viewport ) {1781517816 const { opaque: opaqueObjects, transmissive: transmissiveObjects, transparent: transparentObjects } = currentRenderList;1781717818 currentRenderState.setupLightsView( camera );1781917820 if ( _clippingEnabled === true ) clipping.setGlobalState( _this.clippingPlanes, camera );1782117822 if ( viewport ) state.viewport( _currentViewport.copy( viewport ) );1782317824 if ( opaqueObjects.length > 0 ) renderObjects( opaqueObjects, scene, camera );17825 if ( transmissiveObjects.length > 0 ) renderObjects( transmissiveObjects, scene, camera );17826 if ( transparentObjects.length > 0 ) renderObjects( transparentObjects, scene, camera );1782717828 1782917830 state.buffers.depth.setTest( true );17831 state.buffers.depth.setMask( true );17832 state.buffers.color.setMask( true );1783317834 state.setPolygonOffset( false );1783517836 }1783717838 function renderTransmissionPass( opaqueObjects, transmissiveObjects, scene, camera ) {1783917840 const overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;1784117842 if ( overrideMaterial !== null ) {1784317844 return;1784517846 }1784717848 if ( currentRenderState.state.transmissionRenderTarget[ camera.id ] === undefined ) {1784917850 const hasHalfFloatSupport = extensions.has( 'EXT_color_buffer_half_float' ) || extensions.has( 'EXT_color_buffer_float' );1785117852 currentRenderState.state.transmissionRenderTarget[ camera.id ] = new WebGLRenderTarget( 1, 1, {17853 generateMipmaps: true,17854 type: hasHalfFloatSupport ? HalfFloatType : UnsignedByteType,17855 minFilter: LinearMipmapLinearFilter,17856 samples: Math.max( 4, capabilities.samples ), 17857 stencilBuffer: stencil,17858 resolveDepthBuffer: false,17859 resolveStencilBuffer: false,17860 storeMultisampledDepthBuffer: false,17861 storeMultisampledStencilBuffer: false,17862 colorSpace: ColorManagement.workingColorSpace,17863 } );1786417865 1786617867 1786817869178701787117872178731787417875 }1787617877 const transmissionRenderTarget = currentRenderState.state.transmissionRenderTarget[ camera.id ];1787817879 const activeViewport = camera.viewport || _currentViewport;17880 transmissionRenderTarget.setSize( activeViewport.z * _this.transmissionResolutionScale, activeViewport.w * _this.transmissionResolutionScale );1788117882 1788317884 const currentRenderTarget = _this.getRenderTarget();17885 const currentActiveCubeFace = _this.getActiveCubeFace();17886 const currentActiveMipmapLevel = _this.getActiveMipmapLevel();1788717888 _this.setRenderTarget( transmissionRenderTarget );1788917890 _this.getClearColor( _currentClearColor );17891 _currentClearAlpha = _this.getClearAlpha();17892 if ( _currentClearAlpha < 1 ) _this.setClearColor( 0xffffff, 0.5 );1789317894 _this.clear();1789517896 if ( _renderBackground ) background.render( scene );1789717898 17899 17900 const currentToneMapping = _this.toneMapping;17901 _this.toneMapping = NoToneMapping;1790217903 17904 17905 const currentCameraViewport = camera.viewport;17906 if ( camera.viewport !== undefined ) camera.viewport = undefined;1790717908 currentRenderState.setupLightsView( camera );1790917910 if ( _clippingEnabled === true ) clipping.setGlobalState( _this.clippingPlanes, camera );1791117912 renderObjects( opaqueObjects, scene, camera );1791317914 textures.updateMultisampleRenderTarget( transmissionRenderTarget );17915 textures.updateRenderTargetMipmap( transmissionRenderTarget );1791617917 if ( extensions.has( 'WEBGL_multisampled_render_to_texture' ) === false ) { 1791817919 let renderTargetNeedsUpdate = false;1792017921 for ( let i = 0, l = transmissiveObjects.length; i < l; i ++ ) {1792217923 const renderItem = transmissiveObjects[ i ];1792417925 const { object, geometry, material, group } = renderItem;1792617927 if ( material.side === DoubleSide && object.layers.test( camera.layers ) ) {1792817929 const currentSide = material.side;1793017931 material.side = BackSide;17932 material.needsUpdate = true;1793317934 renderObject( object, scene, camera, geometry, material, group );1793517936 material.side = currentSide;17937 material.needsUpdate = true;1793817939 renderTargetNeedsUpdate = true;1794017941 }1794217943 }1794417945 if ( renderTargetNeedsUpdate === true ) {1794617947 textures.updateMultisampleRenderTarget( transmissionRenderTarget );17948 textures.updateRenderTargetMipmap( transmissionRenderTarget );1794917950 }1795117952 }1795317954 _this.setRenderTarget( currentRenderTarget, currentActiveCubeFace, currentActiveMipmapLevel );1795517956 _this.setClearColor( _currentClearColor, _currentClearAlpha );1795717958 if ( currentCameraViewport !== undefined ) camera.viewport = currentCameraViewport;1795917960 _this.toneMapping = currentToneMapping;1796117962 }1796317964 function renderObjects( renderList, scene, camera ) {1796517966 const overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;1796717968 for ( let i = 0, l = renderList.length; i < l; i ++ ) {1796917970 const renderItem = renderList[ i ];1797117972 const { object, geometry, group } = renderItem;17973 let material = renderItem.material;1797417975 if ( material.allowOverride === true && overrideMaterial !== null ) {1797617977 material = overrideMaterial;1797817979 }1798017981 if ( object.layers.test( camera.layers ) ) {1798217983 renderObject( object, scene, camera, geometry, material, group );1798417985 }1798617987 }1798817989 }1799017991 function renderObject( object, scene, camera, geometry, material, group ) {1799217993 if ( _nodesHandler !== null && material.isNodeMaterial ) _nodesHandler.setObject( object, material );17994 object.onBeforeRender( _this, scene, camera, geometry, material, group );1799517996 object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );17997 object.normalMatrix.getNormalMatrix( object.modelViewMatrix );1799817999 material.onBeforeRender( _this, scene, camera, geometry, object, group );1800018001 if ( material.transparent === true && material.side === DoubleSide && material.forceSinglePass === false ) {1800218003 material.side = BackSide;18004 material.needsUpdate = true;18005 _this.renderBufferDirect( camera, scene, geometry, material, object, group );1800618007 material.side = FrontSide;18008 material.needsUpdate = true;18009 _this.renderBufferDirect( camera, scene, geometry, material, object, group );1801018011 material.side = DoubleSide;1801218013 } else {1801418015 _this.renderBufferDirect( camera, scene, geometry, material, object, group );1801618017 }1801818019 object.onAfterRender( _this, scene, camera, geometry, material, group );1802018021 }1802218023 function countLightProbeGrids( grids ) {1802418025 let count = 0;1802618027 for ( const grid of grids ) if ( grid.texture !== null ) count ++;1802818029 return count;1803018031 }1803218033 function getProgram( material, scene, object ) {1803418035 if ( scene.isScene !== true ) scene = _emptyScene; 1803618037 const materialProperties = properties.get( material );1803818039 const lights = currentRenderState.state.lights;18040 const shadowsArray = currentRenderState.state.shadowsArray;1804118042 const lightsStateVersion = lights.state.version;1804318044 const parameters = programCache.getParameters( material, lights.state, shadowsArray, scene, object, currentRenderState.state.lightProbeGridArray );18045 const programCacheKey = programCache.getProgramCacheKey( parameters );1804618047 let programs = materialProperties.programs;1804818049 1805018051 materialProperties.environment = ( material.isMeshStandardMaterial || material.isMeshLambertMaterial || material.isMeshPhongMaterial ) ? scene.environment : null;18052 materialProperties.fog = scene.fog;1805318054 const usePMREM = material.isMeshStandardMaterial || ( material.isMeshLambertMaterial && ! material.envMap ) || ( material.isMeshPhongMaterial && ! material.envMap );18055 materialProperties.envMap = environments.get( material.envMap || materialProperties.environment, usePMREM );18056 materialProperties.envMapRotation = ( materialProperties.environment !== null && material.envMap === null ) ? scene.environmentRotation : material.envMapRotation;1805718058 if ( programs === undefined ) {1805918060 1806118062 material.addEventListener( 'dispose', onMaterialDispose );1806318064 programs = new Map();18065 materialProperties.programs = programs;18066 materialProperties.programVariants = new Map();1806718068 }1806918070 let program = programs.get( programCacheKey );1807118072 if ( program !== undefined ) {1807318074 1807518076 if ( materialProperties.currentProgram === program && materialProperties.lightsStateVersion === lightsStateVersion ) {1807718078 updateCommonMaterialProperties( material, parameters );1807918080 return program;1808118082 }1808318084 } else {1808518086 parameters.uniforms = programCache.getUniforms( material );1808718088 18089 if ( _nodesHandler !== null && material.isNodeMaterial ) {1809018091 _nodesHandler.build( material, object, parameters );1809218093 }1809418095 material.onBeforeCompile( parameters, _this );1809618097 program = programCache.acquireProgram( parameters, programCacheKey );18098 programs.set( programCacheKey, program );1809918100 materialProperties.uniforms = parameters.uniforms;1810118102 }1810318104 const uniforms = materialProperties.uniforms;1810518106 if ( ( ! material.isShaderMaterial && ! material.isRawShaderMaterial ) || material.clipping === true ) {1810718108 uniforms.clippingPlanes = clipping.uniform;1810918110 }1811118112 updateCommonMaterialProperties( material, parameters );1811318114 1811518116 materialProperties.needsLights = materialNeedsLights( material );18117 materialProperties.lightsStateVersion = lightsStateVersion;1811818119 if ( materialProperties.needsLights ) {1812018121 1812218123 uniforms.ambientLightColor.value = lights.state.ambient;18124 uniforms.lightProbe.value = lights.state.probe;18125 uniforms.sunLights.value = lights.state.sun;18126 uniforms.sunLightShadows.value = lights.state.sunShadow;18127 uniforms.directionalLights.value = lights.state.directional;18128 uniforms.directionalLightShadows.value = lights.state.directionalShadow;18129 uniforms.spotLights.value = lights.state.spot;18130 uniforms.spotLightShadows.value = lights.state.spotShadow;18131 uniforms.rectAreaLights.value = lights.state.rectArea;18132 uniforms.ltc_1.value = lights.state.rectAreaLTC1;18133 uniforms.ltc_2.value = lights.state.rectAreaLTC2;18134 uniforms.pointLights.value = lights.state.point;18135 uniforms.pointLightShadows.value = lights.state.pointShadow;18136 uniforms.hemisphereLights.value = lights.state.hemi;1813718138 uniforms.sunShadowMatrix.value = lights.state.sunShadowMatrix;18139 uniforms.sunShadowCascade.value = lights.state.sunShadowCascade;18140 uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;18141 uniforms.spotLightMatrix.value = lights.state.spotLightMatrix;18142 uniforms.spotLightMap.value = lights.state.spotLightMap;18143 uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix;18144 1814518146 }1814718148 materialProperties.numLightProbeGrids = countLightProbeGrids( currentRenderState.state.lightProbeGridArray );1814918150 materialProperties.currentProgram = program;18151 materialProperties.uniformsList = null;1815218153 return program;1815418155 }1815618157 function getProgramVariant( material, scene, object, colorSpace, toneMapping ) {1815818159 const materialProperties = properties.get( material );1816018161 const programVariantKey = materialProperties.currentProgram.id + ',' + colorSpace + ',' + toneMapping;1816218163 let program = materialProperties.programVariants.get( programVariantKey );1816418165 if ( program === undefined ) {1816618167 program = getProgram( material, scene, object );1816818169 materialProperties.programVariants.set( programVariantKey, program );1817018171 } else {1817218173 materialProperties.currentProgram = program;18174 materialProperties.uniformsList = null;18175 materialProperties.outputColorSpace = colorSpace;18176 materialProperties.toneMapping = toneMapping;1817718178 }1817918180 return program;1818118182 }1818318184 function getUniformList( materialProperties ) {1818518186 if ( materialProperties.uniformsList === null ) {1818718188 const progUniforms = materialProperties.currentProgram.getUniforms();18189 materialProperties.uniformsList = WebGLUniforms.seqWithValue( progUniforms.seq, materialProperties.uniforms );1819018191 }1819218193 return materialProperties.uniformsList;1819418195 }1819618197 function updateCommonMaterialProperties( material, parameters ) {1819818199 const materialProperties = properties.get( material );1820018201 materialProperties.outputColorSpace = parameters.outputColorSpace;18202 materialProperties.batching = parameters.batching;18203 materialProperties.batchingColor = parameters.batchingColor;18204 materialProperties.instancing = parameters.instancing;18205 materialProperties.instancingColor = parameters.instancingColor;18206 materialProperties.instancingMorph = parameters.instancingMorph;18207 materialProperties.skinning = parameters.skinning;18208 materialProperties.morphTargets = parameters.morphTargets;18209 materialProperties.morphNormals = parameters.morphNormals;18210 materialProperties.morphColors = parameters.morphColors;18211 materialProperties.morphTargetsCount = parameters.morphTargetsCount;18212 materialProperties.numClippingPlanes = parameters.numClippingPlanes;18213 materialProperties.numIntersection = parameters.numClipIntersection;18214 materialProperties.vertexAlphas = parameters.vertexAlphas;18215 materialProperties.vertexTangents = parameters.vertexTangents;18216 materialProperties.toneMapping = parameters.toneMapping;1821718218 }1821918220 function setProgram( camera, scene, geometry, material, object ) {1822118222 if ( scene.isScene !== true ) scene = _emptyScene; 1822318224 textures.resetTextureUnits();1822518226 const fog = scene.fog;18227 const environment = ( material.isMeshStandardMaterial || material.isMeshLambertMaterial || material.isMeshPhongMaterial ) ? scene.environment : null;18228 const colorSpace = ( _currentRenderTarget === null ) ? _this.outputColorSpace : ( _currentRenderTarget.isXRRenderTarget === true ? _currentRenderTarget.texture.colorSpace : ColorManagement.workingColorSpace );18229 const usePMREM = material.isMeshStandardMaterial || ( material.isMeshLambertMaterial && ! material.envMap ) || ( material.isMeshPhongMaterial && ! material.envMap );18230 const envMap = environments.get( material.envMap || environment, usePMREM );18231 const vertexAlphas = material.vertexColors === true && !! geometry.attributes.color && geometry.attributes.color.itemSize === 4;18232 const vertexTangents = !! geometry.attributes.tangent && ( !! material.normalMap || material.anisotropy > 0 );18233 const morphTargets = !! geometry.morphAttributes.position;18234 const morphNormals = !! geometry.morphAttributes.normal;18235 const morphColors = !! geometry.morphAttributes.color;1823618237 let toneMapping = NoToneMapping;1823818239 if ( material.toneMapped ) {1824018241 if ( _currentRenderTarget === null || _currentRenderTarget.isXRRenderTarget === true ) {1824218243 toneMapping = _this.toneMapping;1824418245 }1824618247 }1824818249 const morphAttribute = geometry.morphAttributes.position || geometry.morphAttributes.normal || geometry.morphAttributes.color;18250 const morphTargetsCount = ( morphAttribute !== undefined ) ? morphAttribute.length : 0;1825118252 const materialProperties = properties.get( material );18253 const lights = currentRenderState.state.lights;1825418255 if ( _clippingEnabled === true ) {1825618257 if ( _localClippingEnabled === true || camera !== _currentCamera ) {1825818259 const useCache =18260 camera === _currentCamera &&18261 material.id === _currentMaterialId;1826218263 18264 18265 18266 clipping.setState( material, camera, useCache );1826718268 }1826918270 }1827118272 1827318274 let needsProgramChange = false;18275 let needsProgramVariant = false;1827618277 if ( material.version === materialProperties.__version ) {1827818279 if ( materialProperties.needsLights && ( materialProperties.lightsStateVersion !== lights.state.version ) ) {1828018281 needsProgramChange = true;1828218283 } else if ( object.isBatchedMesh && materialProperties.batching === false ) {1828418285 needsProgramChange = true;1828618287 } else if ( ! object.isBatchedMesh && materialProperties.batching === true ) {1828818289 needsProgramChange = true;1829018291 } else if ( object.isBatchedMesh && materialProperties.batchingColor === true && object._colorsTexture === null ) {1829218293 needsProgramChange = true;1829418295 } else if ( object.isBatchedMesh && materialProperties.batchingColor === false && object._colorsTexture !== null ) {1829618297 needsProgramChange = true;1829818299 } else if ( object.isInstancedMesh && materialProperties.instancing === false ) {1830018301 needsProgramChange = true;1830218303 } else if ( ! object.isInstancedMesh && materialProperties.instancing === true ) {1830418305 needsProgramChange = true;1830618307 } else if ( object.isSkinnedMesh && materialProperties.skinning === false ) {1830818309 needsProgramChange = true;1831018311 } else if ( ! object.isSkinnedMesh && materialProperties.skinning === true ) {1831218313 needsProgramChange = true;1831418315 } else if ( object.isInstancedMesh && materialProperties.instancingColor === true && object.instanceColor === null ) {1831618317 needsProgramChange = true;1831818319 } else if ( object.isInstancedMesh && materialProperties.instancingColor === false && object.instanceColor !== null ) {1832018321 needsProgramChange = true;1832218323 } else if ( object.isInstancedMesh && materialProperties.instancingMorph === true && object.morphTexture === null ) {1832418325 needsProgramChange = true;1832618327 } else if ( object.isInstancedMesh && materialProperties.instancingMorph === false && object.morphTexture !== null ) {1832818329 needsProgramChange = true;1833018331 } else if ( materialProperties.envMap !== envMap ) {1833218333 needsProgramChange = true;1833418335 } else if ( material.fog === true && materialProperties.fog !== fog ) {1833618337 needsProgramChange = true;1833818339 } else if ( materialProperties.numClippingPlanes !== undefined &&18340 ( materialProperties.numClippingPlanes !== clipping.numPlanes ||18341 materialProperties.numIntersection !== clipping.numIntersection ) ) {1834218343 needsProgramChange = true;1834418345 } else if ( materialProperties.vertexAlphas !== vertexAlphas ) {1834618347 needsProgramChange = true;1834818349 } else if ( materialProperties.vertexTangents !== vertexTangents ) {1835018351 needsProgramChange = true;1835218353 } else if ( materialProperties.morphTargets !== morphTargets ) {1835418355 needsProgramChange = true;1835618357 } else if ( materialProperties.morphNormals !== morphNormals ) {1835818359 needsProgramChange = true;1836018361 } else if ( materialProperties.morphColors !== morphColors ) {1836218363 needsProgramChange = true;1836418365 } else if ( materialProperties.morphTargetsCount !== morphTargetsCount ) {1836618367 needsProgramChange = true;1836818369 } else if ( materialProperties.numLightProbeGrids !== countLightProbeGrids( currentRenderState.state.lightProbeGridArray ) ) {1837018371 needsProgramChange = true;1837218373 } else if ( materialProperties.outputColorSpace !== colorSpace || materialProperties.toneMapping !== toneMapping ) {1837418375 needsProgramVariant = true;1837618377 }1837818379 } else {1838018381 needsProgramChange = true;18382 materialProperties.__version = material.version;1838318384 }1838518386 1838718388 let program = materialProperties.currentProgram;1838918390 if ( needsProgramChange === true || needsProgramVariant === true ) {1839118392 program = ( needsProgramVariant === true ) ? getProgramVariant( material, scene, object, colorSpace, toneMapping ) : getProgram( material, scene, object );1839318394 18395 18396 if ( _nodesHandler && material.isNodeMaterial ) {1839718398 _nodesHandler.onUpdateProgram( material, program, materialProperties );1839918400 }1840118402 }1840318404 let refreshProgram = false;18405 let refreshMaterial = false;18406 let refreshLights = false;1840718408 const p_uniforms = program.getUniforms(),18409 m_uniforms = materialProperties.uniforms;1841018411 if ( state.useProgram( program.program ) ) {1841218413 refreshProgram = true;18414 refreshMaterial = true;18415 refreshLights = true;1841618417 }1841818419 if ( material.id !== _currentMaterialId ) {1842018421 _currentMaterialId = material.id;1842218423 refreshMaterial = true;1842418425 }1842618427 if ( refreshProgram || _currentCamera !== camera ) {1842818429 1843018431 const reversedDepthBuffer = state.buffers.depth.getReversed();1843218433 if ( reversedDepthBuffer && camera.reversedDepth !== true ) {1843418435 camera._reversedDepth = true;18436 camera.updateProjectionMatrix();1843718438 }1843918440 p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );1844118442 p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );1844318444 const uCamPos = p_uniforms.map.cameraPosition;1844518446 if ( uCamPos !== undefined ) {1844718448 uCamPos.setValue( _gl, _vector3.setFromMatrixPosition( camera.matrixWorld ) );1844918450 }1845118452 if ( capabilities.logarithmicDepthBuffer ) {1845318454 p_uniforms.setValue( _gl, 'logDepthBufFC',18455 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );1845618457 }1845818459 1846018461 if ( material.isMeshPhongMaterial ||18462 material.isMeshToonMaterial ||18463 material.isMeshLambertMaterial ||18464 material.isMeshBasicMaterial ||18465 material.isMeshStandardMaterial ||18466 material.isShaderMaterial ) {1846718468 p_uniforms.setValue( _gl, 'isOrthographic', camera.isOrthographicCamera === true );1846918470 }1847118472 if ( _currentCamera !== camera ) {1847318474 _currentCamera = camera;1847518476 18477 18478 1847918480 refreshMaterial = true; 18481 refreshLights = true; 1848218483 }1848418485 }1848618487 18488 if ( materialProperties.needsLights ) {1848918490 18491 if ( lights.state.sunShadowMap.length > 0 ) {1849218493 p_uniforms.setValue( _gl, 'sunShadowMap', lights.state.sunShadowMap, textures );1849418495 }1849618497 if ( lights.state.directionalShadowMap.length > 0 ) {1849818499 p_uniforms.setValue( _gl, 'directionalShadowMap', lights.state.directionalShadowMap, textures );1850018501 }1850218503 if ( lights.state.spotShadowMap.length > 0 ) {1850418505 p_uniforms.setValue( _gl, 'spotShadowMap', lights.state.spotShadowMap, textures );1850618507 }1850818509 if ( lights.state.pointShadowMap.length > 0 ) {1851018511 p_uniforms.setValue( _gl, 'pointShadowMap', lights.state.pointShadowMap, textures );1851218513 }1851418515 }1851618517 18518 18519 1852018521 if ( object.isSkinnedMesh ) {1852218523 p_uniforms.setOptional( _gl, object, 'bindMatrix' );18524 p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );1852518526 const skeleton = object.skeleton;1852718528 if ( skeleton ) {1852918530 if ( skeleton.boneTexture === null ) skeleton.computeBoneTexture();1853118532 p_uniforms.setValue( _gl, 'boneTexture', skeleton.boneTexture, textures );1853318534 }1853518536 }1853718538 if ( object.isBatchedMesh ) {1853918540 p_uniforms.setOptional( _gl, object, 'batchingTexture' );18541 p_uniforms.setValue( _gl, 'batchingTexture', object._matricesTexture, textures );1854218543 p_uniforms.setOptional( _gl, object, 'batchingIdTexture' );18544 p_uniforms.setValue( _gl, 'batchingIdTexture', object._indirectTexture, textures );1854518546 p_uniforms.setOptional( _gl, object, 'batchingColorTexture' );18547 if ( object._colorsTexture !== null ) {1854818549 p_uniforms.setValue( _gl, 'batchingColorTexture', object._colorsTexture, textures );1855018551 }1855218553 }1855418555 const morphAttributes = geometry.morphAttributes;1855618557 if ( morphAttributes.position !== undefined || morphAttributes.normal !== undefined || ( morphAttributes.color !== undefined ) ) {1855818559 morphtargets.update( object, geometry, program );1856018561 }1856218563 if ( refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow ) {1856418565 materialProperties.receiveShadow = object.receiveShadow;18566 p_uniforms.setValue( _gl, 'receiveShadow', object.receiveShadow );1856718568 }1856918570 if ( ( material.isMeshStandardMaterial || material.isMeshLambertMaterial || material.isMeshPhongMaterial ) && material.envMap === null && scene.environment !== null ) {1857118572 m_uniforms.envMapIntensity.value = scene.environmentIntensity;1857318574 }1857518576 18577 if ( m_uniforms.dfgLUT !== undefined ) {1857818579 m_uniforms.dfgLUT.value = getDFGLUT();1858018581 }1858218583 if ( refreshMaterial ) {1858418585 p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );1858618587 if ( materialProperties.needsLights ) {1858818589 1859018591 18592 18593 18594 18595 18596 1859718598 markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );1859918600 }1860118602 1860318604 if ( fog && material.fog === true ) {1860518606 materials.refreshFogUniforms( m_uniforms, fog );1860718608 }1860918610 materials.refreshMaterialUniforms( m_uniforms, material, _pixelRatio, _height, currentRenderState.state.transmissionRenderTarget[ camera.id ] );1861118612 1861318614 if ( materialProperties.needsLights && materialProperties.numLightProbeGrids > 0 ) {1861518616 const grids = lightProbeGridUniforms;18617 let count = 0;1861818619 for ( const grid of currentRenderState.state.lightProbeGridArray ) {1862018621 if ( grid.texture === null ) continue;1862218623 grids.textures[ count ] = grid.texture;18624 grids.min[ count ] = grid.boundingBox.min;18625 grids.max[ count ] = grid.boundingBox.max;18626 grids.resolution[ count ] = grid.resolution;18627 count ++;1862818629 }1863018631 for ( const key in grids ) grids[ key ].length = count;1863218633 m_uniforms.probesSH.value = grids.textures;18634 m_uniforms.probesMin.value = grids.min;18635 m_uniforms.probesMax.value = grids.max;18636 m_uniforms.probesResolution.value = grids.resolution;1863718638 }1863918640 WebGLUniforms.upload( _gl, getUniformList( materialProperties ), m_uniforms, textures );1864118642 }1864318644 if ( material.isShaderMaterial && material.uniformsNeedUpdate === true ) {1864518646 WebGLUniforms.upload( _gl, getUniformList( materialProperties ), m_uniforms, textures );18647 material.uniformsNeedUpdate = false;1864818649 }1865018651 if ( material.isSpriteMaterial ) {1865218653 p_uniforms.setValue( _gl, 'center', object.center );1865418655 }1865618657 1865818659 p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );18660 p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );18661 p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );1866218663 1866418665 if ( material.uniformsGroups !== undefined ) {1866618667 const groups = material.uniformsGroups;1866818669 for ( let i = 0, l = groups.length; i < l; i ++ ) {1867018671 const group = groups[ i ];1867218673 uniformsGroups.update( group, program );18674 uniformsGroups.bind( group, program );1867518676 }1867718678 }1867918680 return program;1868118682 }1868318684 1868518686 function markUniformsLightsNeedsUpdate( uniforms, value ) {1868718688 uniforms.ambientLightColor.needsUpdate = value;18689 uniforms.lightProbe.needsUpdate = value;1869018691 uniforms.sunLights.needsUpdate = value;18692 uniforms.sunLightShadows.needsUpdate = value;18693 uniforms.directionalLights.needsUpdate = value;18694 uniforms.directionalLightShadows.needsUpdate = value;18695 uniforms.pointLights.needsUpdate = value;18696 uniforms.pointLightShadows.needsUpdate = value;18697 uniforms.spotLights.needsUpdate = value;18698 uniforms.spotLightShadows.needsUpdate = value;18699 uniforms.rectAreaLights.needsUpdate = value;18700 uniforms.hemisphereLights.needsUpdate = value;1870118702 }1870318704 function materialNeedsLights( material ) {1870518706 return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial ||18707 material.isMeshStandardMaterial || material.isShadowMaterial ||18708 ( material.isShaderMaterial && material.lights === true );1870918710 }1871118712 1871318714187151871618717 this.getActiveCubeFace = function () {1871818719 return _currentActiveCubeFace;1872018721 };1872218723 1872418725187261872718728 this.getActiveMipmapLevel = function () {1872918730 return _currentActiveMipmapLevel;1873118732 };1873318734 187351873618737187381873918740 this.getRenderTarget = function () {1874118742 return _currentRenderTarget;1874318744 };1874518746 this.setRenderTargetTextures = function ( renderTarget, colorTexture, depthTexture ) {1874718748 const renderTargetProperties = properties.get( renderTarget );1874918750 renderTargetProperties.__autoAllocateDepthBuffer = renderTarget.resolveDepthBuffer === false;18751 if ( renderTargetProperties.__autoAllocateDepthBuffer === false ) {1875218753 18754 18755 renderTargetProperties.__useRenderToTexture = false;1875618757 }1875818759 properties.get( renderTarget.texture ).__webglTexture = colorTexture;18760 properties.get( renderTarget.depthTexture ).__webglTexture = renderTargetProperties.__autoAllocateDepthBuffer ? undefined : depthTexture;1876118762 renderTargetProperties.__hasExternalTextures = true;1876318764 };1876518766 this.setRenderTargetFramebuffer = function ( renderTarget, defaultFramebuffer ) {1876718768 const renderTargetProperties = properties.get( renderTarget );18769 renderTargetProperties.__webglFramebuffer = defaultFramebuffer;18770 renderTargetProperties.__useDefaultFramebuffer = defaultFramebuffer === undefined;1877118772 };1877318774 187751877618777187781877918780187811878218783 this.setRenderTarget = function ( renderTarget, activeCubeFace = 0, activeMipmapLevel = 0 ) {1878418785 _currentRenderTarget = renderTarget;18786 _currentActiveCubeFace = activeCubeFace;18787 _currentActiveMipmapLevel = activeMipmapLevel;1878818789 let framebuffer = null;18790 let isCube = false;18791 let isRenderTarget3D = false;1879218793 if ( renderTarget ) {1879418795 const renderTargetProperties = properties.get( renderTarget );1879618797 if ( renderTargetProperties.__useDefaultFramebuffer !== undefined ) {1879818799 18800 18801 state.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer );1880218803 _currentViewport.copy( renderTarget.viewport );18804 _currentScissor.copy( renderTarget.scissor );18805 _currentScissorTest = renderTarget.scissorTest;1880618807 state.viewport( _currentViewport );18808 state.scissor( _currentScissor );18809 state.setScissorTest( _currentScissorTest );1881018811 _currentMaterialId = -1;1881218813 return;1881418815 } else if ( renderTargetProperties.__webglFramebuffer === undefined ) {1881618817 textures.setupRenderTarget( renderTarget );1881818819 } else if ( renderTargetProperties.__hasExternalTextures ) {1882018821 18822 textures.rebindTextures( renderTarget, properties.get( renderTarget.texture ).__webglTexture, properties.get( renderTarget.depthTexture ).__webglTexture );1882318824 } else if ( renderTarget.depthBuffer ) {1882518826 18827 const depthTexture = renderTarget.depthTexture;18828 if ( renderTargetProperties.__boundDepthTexture !== depthTexture ) {1882918830 18831 if (18832 depthTexture !== null &&18833 properties.has( depthTexture ) &&18834 ( renderTarget.width !== depthTexture.image.width || renderTarget.height !== depthTexture.image.height )18835 ) {1883618837 throw new Error( 'THREE.WebGLRenderer: Attached DepthTexture is initialized to the incorrect size.' );1883818839 }1884018841 18842 textures.setupDepthRenderbuffer( renderTarget );1884318844 }1884518846 }1884718848 const texture = renderTarget.texture;1884918850 if ( texture.isData3DTexture || texture.isDataArrayTexture || texture.isCompressedArrayTexture ) {1885118852 isRenderTarget3D = true;1885318854 }1885518856 const __webglFramebuffer = properties.get( renderTarget ).__webglFramebuffer;1885718858 if ( renderTarget.isWebGLCubeRenderTarget ) {1885918860 if ( Array.isArray( __webglFramebuffer[ activeCubeFace ] ) ) {1886118862 framebuffer = __webglFramebuffer[ activeCubeFace ][ activeMipmapLevel ];1886318864 } else {1886518866 framebuffer = __webglFramebuffer[ activeCubeFace ];1886718868 }1886918870 isCube = true;1887118872 } else if ( ( renderTarget.samples > 0 ) && textures.useMultisampledRTT( renderTarget ) === false ) {1887318874 framebuffer = properties.get( renderTarget ).__webglMultisampledFramebuffer;1887518876 } else {1887718878 if ( Array.isArray( __webglFramebuffer ) ) {1887918880 framebuffer = __webglFramebuffer[ activeMipmapLevel ];1888118882 } else {1888318884 framebuffer = __webglFramebuffer;1888518886 }1888718888 }1888918890 _currentViewport.copy( renderTarget.viewport );18891 _currentScissor.copy( renderTarget.scissor );18892 _currentScissorTest = renderTarget.scissorTest;1889318894 } else {1889518896 _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor();18897 _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor();18898 _currentScissorTest = _scissorTest;1889918900 }1890118902 18903 18904 if ( activeMipmapLevel !== 0 ) {1890518906 framebuffer = _scratchFramebuffer;1890718908 }1890918910 const framebufferBound = state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );1891118912 if ( framebufferBound ) {1891318914 state.drawBuffers( renderTarget, framebuffer );1891518916 }1891718918 state.viewport( _currentViewport );18919 state.scissor( _currentScissor );18920 state.setScissorTest( _currentScissorTest );1892118922 if ( isCube ) {1892318924 const textureProperties = properties.get( renderTarget.texture );18925 _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + activeCubeFace, textureProperties.__webglTexture, activeMipmapLevel );1892618927 } else if ( isRenderTarget3D ) {1892818929 const layer = activeCubeFace;1893018931 for ( let i = 0; i < renderTarget.textures.length; i ++ ) {1893218933 const textureProperties = properties.get( renderTarget.textures[ i ] );1893418935 _gl.framebufferTextureLayer( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0 + i, textureProperties.__webglTexture, activeMipmapLevel, layer );1893618937 }1893818939 } else if ( renderTarget !== null && activeMipmapLevel !== 0 ) {1894018941 18942 18943 const textureProperties = properties.get( renderTarget.texture );18944 _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D, textureProperties.__webglTexture, activeMipmapLevel );1894518946 }1894718948 _currentMaterialId = -1; 1894918950 };1895118952 function getReadableState( texture ) {1895318954 const textureProperties = properties.get( texture );1895518956 if ( textureProperties.__readFormat !== texture.format || textureProperties.__readType !== texture.type ) {1895718958 textureProperties.__readFormat = texture.format;18959 textureProperties.__readType = texture.type;18960 textureProperties.__formatReadable = capabilities.textureFormatReadable( texture.format );18961 textureProperties.__typeReadable = capabilities.textureTypeReadable( texture.type );1896218963 }1896418965 return textureProperties;1896618967 }1896818969 189701897118972189731897418975189761897718978189791898018981 this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer, activeCubeFaceIndex, textureIndex = 0 ) {1898218983 if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {1898418985 error( 'WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );18986 return;1898718988 }1898918990 let framebuffer = properties.get( renderTarget ).__webglFramebuffer;1899118992 if ( renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined ) {1899318994 framebuffer = framebuffer[ activeCubeFaceIndex ];1899518996 18997 if ( Array.isArray( framebuffer ) ) framebuffer = framebuffer[ 0 ];1899818999 }1900019001 if ( framebuffer ) {1900219003 state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );1900419005 try {1900619007 const texture = renderTarget.textures[ textureIndex ];19008 const textureFormat = texture.format;19009 const textureType = texture.type;1901019011 1901219013 if ( renderTarget.textures.length > 1 ) _gl.readBuffer( _gl.COLOR_ATTACHMENT0 + textureIndex );1901419015 const readableState = getReadableState( texture );1901619017 if ( readableState.__formatReadable === false ) {1901819019 error( 'WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );19020 return;1902119022 }1902319024 if ( readableState.__typeReadable === false ) {1902519026 error( 'WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );19027 return;1902819029 }1903019031 1903219033 if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {1903419035 _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );1903619037 }1903819039 } finally {1904019041 1904219043 const framebuffer = ( _currentRenderTarget !== null ) ? properties.get( _currentRenderTarget ).__webglFramebuffer : null;19044 state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );1904519046 }1904719048 }1904919050 };1905119052 19053190541905519056190571905819059190601906119062190631906419065190661906719068 this.readRenderTargetPixelsAsync = async function ( renderTarget, x, y, width, height, buffer, activeCubeFaceIndex, textureIndex = 0 ) {1906919070 if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {1907119072 throw new Error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );1907319074 }1907519076 let framebuffer = properties.get( renderTarget ).__webglFramebuffer;19077 if ( renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined ) {1907819079 framebuffer = framebuffer[ activeCubeFaceIndex ];1908019081 19082 if ( Array.isArray( framebuffer ) ) framebuffer = framebuffer[ 0 ];1908319084 }1908519086 if ( framebuffer ) {1908719088 19089 if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {1909019091 19092 state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );1909319094 const texture = renderTarget.textures[ textureIndex ];19095 const textureFormat = texture.format;19096 const textureType = texture.type;1909719098 1909919100 if ( renderTarget.textures.length > 1 ) _gl.readBuffer( _gl.COLOR_ATTACHMENT0 + textureIndex );1910119102 const readableState = getReadableState( texture );1910319104 if ( readableState.__formatReadable === false ) {1910519106 throw new Error( 'THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.' );1910719108 }1910919110 if ( readableState.__typeReadable === false ) {1911119112 throw new Error( 'THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.' );1911319114 }1911519116 const glBuffer = _gl.createBuffer();19117 _gl.bindBuffer( _gl.PIXEL_PACK_BUFFER, glBuffer );19118 _gl.bufferData( _gl.PIXEL_PACK_BUFFER, buffer.byteLength, _gl.STREAM_READ );1911919120 _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), 0 );19121 _gl.bindBuffer( _gl.PIXEL_PACK_BUFFER, null );1912219123 19124 const currFramebuffer = _currentRenderTarget !== null ? properties.get( _currentRenderTarget ).__webglFramebuffer : null;19125 state.bindFramebuffer( _gl.FRAMEBUFFER, currFramebuffer );1912619127 19128 const sync = _gl.fenceSync( _gl.SYNC_GPU_COMMANDS_COMPLETE, 0 );1912919130 _gl.flush();1913119132 await probeAsync( _gl, sync, 4 );1913319134 19135 _gl.bindBuffer( _gl.PIXEL_PACK_BUFFER, glBuffer );19136 _gl.getBufferSubData( _gl.PIXEL_PACK_BUFFER, 0, buffer );19137 _gl.bindBuffer( _gl.PIXEL_PACK_BUFFER, null );19138 _gl.deleteBuffer( glBuffer );19139 _gl.deleteSync( sync );1914019141 return buffer;1914219143 } else {1914419145 throw new Error( 'THREE.WebGLRenderer.readRenderTargetPixelsAsync: requested read bounds are out of range.' );1914619147 }1914819149 }1915019151 };1915219153 19154191551915619157191581915919160 this.copyFramebufferToTexture = function ( texture, position = null, level = 0 ) {1916119162 const levelScale = Math.pow( 2, - level );19163 const width = Math.floor( texture.image.width * levelScale );19164 const height = Math.floor( texture.image.height * levelScale );1916519166 const x = position !== null ? position.x : 0;19167 const y = position !== null ? position.y : 0;1916819169 textures.setTexture2D( texture, 0 );1917019171 _gl.copyTexSubImage2D( _gl.TEXTURE_2D, level, 0, 0, x, y, width, height );1917219173 state.unbindTexture();1917419175 };191761917719178 19179191801918119182191831918419185191861918719188191891919019191 this.copyTextureToTexture = function ( srcTexture, dstTexture, srcRegion = null, dstPosition = null, srcLevel = 0, dstLevel = 0 ) {1919219193 19194 let width, height, depth, minX, minY, minZ;19195 let dstX, dstY, dstZ;19196 const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ dstLevel ] : srcTexture.image;19197 if ( srcRegion !== null ) {1919819199 width = srcRegion.max.x - srcRegion.min.x;19200 height = srcRegion.max.y - srcRegion.min.y;19201 depth = srcRegion.isBox3 ? srcRegion.max.z - srcRegion.min.z : 1;19202 minX = srcRegion.min.x;19203 minY = srcRegion.min.y;19204 minZ = srcRegion.isBox3 ? srcRegion.min.z : 0;1920519206 } else {1920719208 const levelScale = Math.pow( 2, - srcLevel );19209 width = Math.floor( image.width * levelScale );19210 height = Math.floor( image.height * levelScale );19211 if ( srcTexture.isDataArrayTexture ) {1921219213 depth = image.depth;1921419215 } else if ( srcTexture.isData3DTexture ) {1921619217 depth = Math.floor( image.depth * levelScale );1921819219 } else {1922019221 depth = 1;1922219223 }1922419225 minX = 0;19226 minY = 0;19227 minZ = 0;1922819229 }1923019231 if ( dstPosition !== null ) {1923219233 dstX = dstPosition.x;19234 dstY = dstPosition.y;19235 dstZ = dstPosition.z;1923619237 } else {1923819239 dstX = 0;19240 dstY = 0;19241 dstZ = 0;1924219243 }1924419245 19246 const glFormat = utils.convert( dstTexture.format );19247 const glType = utils.convert( dstTexture.type );19248 let glTarget;1924919250 if ( dstTexture.isData3DTexture ) {1925119252 textures.setTexture3D( dstTexture, 0 );19253 glTarget = _gl.TEXTURE_3D;1925419255 } else if ( dstTexture.isDataArrayTexture || dstTexture.isCompressedArrayTexture ) {1925619257 textures.setTexture2DArray( dstTexture, 0 );19258 glTarget = _gl.TEXTURE_2D_ARRAY;1925919260 } else {1926119262 textures.setTexture2D( dstTexture, 0 );19263 glTarget = _gl.TEXTURE_2D;1926419265 }1926619267 state.activeTexture( _gl.TEXTURE0 ); 1926819269 state.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, dstTexture.flipY );19270 state.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha );19271 state.pixelStorei( _gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment );1927219273 19274 const currentUnpackRowLen = state.getParameter( _gl.UNPACK_ROW_LENGTH );19275 const currentUnpackImageHeight = state.getParameter( _gl.UNPACK_IMAGE_HEIGHT );19276 const currentUnpackSkipPixels = state.getParameter( _gl.UNPACK_SKIP_PIXELS );19277 const currentUnpackSkipRows = state.getParameter( _gl.UNPACK_SKIP_ROWS );19278 const currentUnpackSkipImages = state.getParameter( _gl.UNPACK_SKIP_IMAGES );1927919280 state.pixelStorei( _gl.UNPACK_ROW_LENGTH, image.width );19281 state.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, image.height );19282 state.pixelStorei( _gl.UNPACK_SKIP_PIXELS, minX );19283 state.pixelStorei( _gl.UNPACK_SKIP_ROWS, minY );19284 state.pixelStorei( _gl.UNPACK_SKIP_IMAGES, minZ );1928519286 19287 const isSrc3D = srcTexture.isDataArrayTexture || srcTexture.isData3DTexture;19288 const isDst3D = dstTexture.isDataArrayTexture || dstTexture.isData3DTexture;19289 if ( srcTexture.isDepthTexture ) {1929019291 const srcTextureProperties = properties.get( srcTexture );19292 const dstTextureProperties = properties.get( dstTexture );19293 const srcRenderTargetProperties = properties.get( srcTextureProperties.__renderTarget );19294 const dstRenderTargetProperties = properties.get( dstTextureProperties.__renderTarget );19295 state.bindFramebuffer( _gl.READ_FRAMEBUFFER, srcRenderTargetProperties.__webglFramebuffer );19296 state.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, dstRenderTargetProperties.__webglFramebuffer );1929719298 for ( let i = 0; i < depth; i ++ ) {1929919300 19301 if ( isSrc3D ) {1930219303 _gl.framebufferTextureLayer( _gl.READ_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, properties.get( srcTexture ).__webglTexture, srcLevel, minZ + i );19304 _gl.framebufferTextureLayer( _gl.DRAW_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, properties.get( dstTexture ).__webglTexture, dstLevel, dstZ + i );1930519306 }1930719308 _gl.blitFramebuffer( minX, minY, minX + width, minY + height, dstX, dstY, dstX + width, dstY + height, _gl.DEPTH_BUFFER_BIT, _gl.NEAREST );1930919310 }1931119312 state.bindFramebuffer( _gl.READ_FRAMEBUFFER, null );19313 state.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, null );1931419315 } else if ( srcLevel !== 0 || srcTexture.isRenderTargetTexture || properties.has( srcTexture ) ) {1931619317 19318 const srcTextureProperties = properties.get( srcTexture );19319 const dstTextureProperties = properties.get( dstTexture );1932019321 19322 state.bindFramebuffer( _gl.READ_FRAMEBUFFER, _srcFramebuffer );19323 state.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, _dstFramebuffer );1932419325 for ( let i = 0; i < depth; i ++ ) {1932619327 19328 if ( isSrc3D ) {1932919330 _gl.framebufferTextureLayer( _gl.READ_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, srcTextureProperties.__webglTexture, srcLevel, minZ + i );1933119332 } else {1933319334 _gl.framebufferTexture2D( _gl.READ_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D, srcTextureProperties.__webglTexture, srcLevel );1933519336 }1933719338 if ( isDst3D ) {1933919340 _gl.framebufferTextureLayer( _gl.DRAW_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, dstTextureProperties.__webglTexture, dstLevel, dstZ + i );1934119342 } else {1934319344 _gl.framebufferTexture2D( _gl.DRAW_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D, dstTextureProperties.__webglTexture, dstLevel );1934519346 }1934719348 19349 if ( srcLevel !== 0 ) {1935019351 _gl.blitFramebuffer( minX, minY, minX + width, minY + height, dstX, dstY, dstX + width, dstY + height, _gl.COLOR_BUFFER_BIT, _gl.NEAREST );1935219353 } else if ( isDst3D ) {1935419355 _gl.copyTexSubImage3D( glTarget, dstLevel, dstX, dstY, dstZ + i, minX, minY, width, height );1935619357 } else {1935819359 _gl.copyTexSubImage2D( glTarget, dstLevel, dstX, dstY, minX, minY, width, height );1936019361 }1936219363 }1936419365 19366 state.bindFramebuffer( _gl.READ_FRAMEBUFFER, null );19367 state.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, null );1936819369 } else {1937019371 if ( isDst3D ) {1937219373 19374 if ( srcTexture.isDataTexture || srcTexture.isData3DTexture ) {1937519376 _gl.texSubImage3D( glTarget, dstLevel, dstX, dstY, dstZ, width, height, depth, glFormat, glType, image.data );1937719378 } else if ( dstTexture.isCompressedArrayTexture ) {1937919380 _gl.compressedTexSubImage3D( glTarget, dstLevel, dstX, dstY, dstZ, width, height, depth, glFormat, image.data );1938119382 } else {1938319384 _gl.texSubImage3D( glTarget, dstLevel, dstX, dstY, dstZ, width, height, depth, glFormat, glType, image );1938519386 }1938719388 } else {1938919390 19391 if ( srcTexture.isDataTexture ) {1939219393 _gl.texSubImage2D( _gl.TEXTURE_2D, dstLevel, dstX, dstY, width, height, glFormat, glType, image.data );1939419395 } else if ( srcTexture.isCompressedTexture ) {1939619397 _gl.compressedTexSubImage2D( _gl.TEXTURE_2D, dstLevel, dstX, dstY, image.width, image.height, glFormat, image.data );1939819399 } else {1940019401 _gl.texSubImage2D( _gl.TEXTURE_2D, dstLevel, dstX, dstY, width, height, glFormat, glType, image );1940219403 }1940419405 }1940619407 }1940819409 19410 state.pixelStorei( _gl.UNPACK_ROW_LENGTH, currentUnpackRowLen );19411 state.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, currentUnpackImageHeight );19412 state.pixelStorei( _gl.UNPACK_SKIP_PIXELS, currentUnpackSkipPixels );19413 state.pixelStorei( _gl.UNPACK_SKIP_ROWS, currentUnpackSkipRows );19414 state.pixelStorei( _gl.UNPACK_SKIP_IMAGES, currentUnpackSkipImages );1941519416 19417 if ( dstLevel === 0 && dstTexture.generateMipmaps === true && dstTexture.mipmapsAutoUpdate === true ) {1941819419 _gl.generateMipmap( glTarget );1942019421 }1942219423 state.unbindTexture();1942419425 };1942619427 19428194291943019431194321943319434 this.initRenderTarget = function ( target ) {1943519436 if ( properties.get( target ).__webglFramebuffer === undefined ) {1943719438 textures.setupRenderTarget( target );1943919440 }1944119442 };1944319444 194451944619447194481944919450 this.initTexture = function ( texture ) {1945119452 if ( texture.isCubeTexture ) {1945319454 textures.setTextureCube( texture, 0 );1945519456 } else if ( texture.isData3DTexture ) {1945719458 textures.setTexture3D( texture, 0 );1945919460 } else if ( texture.isDataArrayTexture || texture.isCompressedArrayTexture ) {1946119462 textures.setTexture2DArray( texture, 0 );1946319464 } else {1946519466 textures.setTexture2D( texture, 0 );1946719468 }1946919470 state.unbindTexture();1947119472 };1947319474 1947519476194771947819479 this.resetState = function () {1948019481 _currentActiveCubeFace = 0;19482 _currentActiveMipmapLevel = 0;19483 _currentRenderTarget = null;1948419485 state.reset();19486 bindingStates.reset();1948719488 };1948919490 if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {1949119492 __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) );1949319494 }1949519496 }1949719498 194991950019501195021950319504195051950619507 get coordinateSystem() {1950819509 return WebGLCoordinateSystem;1951019511 }1951219513 195141951519516195171951819519 get outputColorSpace() {1952019521 return this._outputColorSpace;1952219523 }1952419525 set outputColorSpace( colorSpace ) {1952619527 this._outputColorSpace = colorSpace;1952819529 const gl = this.getContext();19530 gl.drawingBufferColorSpace = ColorManagement._getDrawingBufferColorSpace( colorSpace );19531 gl.unpackColorSpace = ColorManagement._getUnpackColorSpace();1953219533 }1953419535}1953619537export { ACESFilmicToneMapping, AddEquation, AddOperation, AdditiveBlending, AgXToneMapping, AlphaFormat, AlwaysCompare, AlwaysDepth, ArrayCamera, BackSide, BoxGeometry, BufferAttribute, BufferGeometry, ByteType, CineonToneMapping, ClampToEdgeWrapping, Color, ColorManagement, ConstantAlphaFactor, ConstantColorFactor, CubeCamera, CubeDepthTexture, CubeReflectionMapping, CubeRefractionMapping, CubeTexture, CullFaceBack, CullFaceFront, CullFaceNone, CustomBlending, CustomToneMapping, Data3DTexture, DataArrayTexture, DataTexture, DepthFormat, DepthStencilFormat, DepthTexture, DoubleSide, DstAlphaFactor, DstColorFactor, EqualCompare, EqualDepth, EquirectangularReflectionMapping, EquirectangularRefractionMapping, EventDispatcher, ExternalTexture, Float32BufferAttribute, FloatType, FrontSide, Frustum, FrustumArray, GLSL3, GreaterCompare, GreaterDepth, GreaterEqualCompare, GreaterEqualDepth, HalfFloatType, IntType, Layers, LessCompare, LessDepth, LessEqualCompare, LessEqualDepth, LinearFilter, LinearMipmapLinearFilter, LinearMipmapNearestFilter, LinearSRGBColorSpace, LinearToneMapping, LinearTransfer, Matrix3, Matrix4, MaxEquation, Mesh, MeshDepthMaterial, MeshDistanceMaterial, MinEquation, MirroredRepeatWrapping, MixOperation, MultiplyBlending, MultiplyOperation, NearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, NeutralToneMapping, NeverCompare, NeverDepth, NoBlending, NoColorSpace, NoToneMapping, NormalBlending, NotEqualCompare, NotEqualDepth, ObjectSpaceNormalMap, OneFactor, OneMinusConstantAlphaFactor, OneMinusConstantColorFactor, OneMinusDstAlphaFactor, OneMinusDstColorFactor, OneMinusSrcAlphaFactor, OneMinusSrcColorFactor, OrthographicCamera, PCFShadowMap, PCFSoftShadowMap, PMREMGenerator, PerspectiveCamera, Plane, PlaneGeometry, R11_EAC_Format, RED_GREEN_RGTC2_Format, RED_RGTC1_Format, REVISION, RG11_EAC_Format, RGBAFormat, RGBAIntegerFormat, RGBA_ASTC_10x10_Format, RGBA_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_BPTC_Format, RGBA_ETC2_EAC_Format, RGBA_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, RGBFormat, RGB_BPTC_SIGNED_Format, RGB_BPTC_UNSIGNED_Format, RGB_ETC1_Format, RGB_ETC2_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGB_S3TC_DXT1_Format, RGFormat, RGIntegerFormat, RawShaderMaterial, RedFormat, RedIntegerFormat, ReinhardToneMapping, RepeatWrapping, ReverseSubtractEquation, SIGNED_R11_EAC_Format, SIGNED_RED_GREEN_RGTC2_Format, SIGNED_RED_RGTC1_Format, SIGNED_RG11_EAC_Format, SRGBColorSpace, SRGBTransfer, ShaderChunk, ShaderLib, ShaderMaterial, ShortType, SrcAlphaFactor, SrcAlphaSaturateFactor, SrcColorFactor, SubtractEquation, SubtractiveBlending, TangentSpaceNormalMap, Texture, Uint16BufferAttribute, Uint32BufferAttribute, UniformsLib, UniformsUtils, UnsignedByteType, UnsignedInt101111Type, UnsignedInt248Type, UnsignedInt5999Type, UnsignedIntType, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedShortType, VSMShadowMap, Vector2, Vector3, Vector4, WebGLCoordinateSystem, WebGLCubeRenderTarget, WebGLRenderTarget, WebGLRenderer, WebGLUtils, WebXRController, ZeroFactor, createCanvasElement, error, log, warn, warnOnce };