<!-- NEW4 — TEST 4 · THE QUILT · part 382 -->
 shadow.map.isWebGLCubeRenderTarget ? 6 : shadow.getViewportCount();

			if ( light.isPointLight !== true ) shadow.updateMatrices( light, camera );

			for ( let face = 0; face < faceCount; face ++ ) {

				const shadowCamera = shadow.getCamera( face );

				if ( light.isPointLight ) {

					const camera = shadow.camera;
					const shadowMatrix = shadow.matrix;

					const far = light.distance || camera.far;

					if ( far !== camera.far ) {

						camera.far = far;
						camera.updateProjectionMatrix();

					}

					_lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
					camera.position.copy( _lightPositionWorld );

					_lookTarget.copy( camera.position );
					_lookTarget.add( _cubeDirections[ face ] );
					camera.up.copy( _cubeUps[ face ] );
					camera.lookAt( _lookTarget );
					camera.updateMatrixWorld();

					shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );

					_projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
					shadow._frustum.setFromProjectionMatrix( _projScreenMatrix, camera.coordinateSystem, camera.reversedDepth );

				}

				// For cube render targets, render to each face separately
				if ( shadow.map.isWebGLCubeRenderTarget ) {

					renderer.setRenderTarget( shadow.map, face );
					renderer.clear();

				} else {

					// For 2D render targets, use viewports
					if ( face === 0 ) {

						renderer.setRenderTarget( shadow.map );
						renderer.clear();

					}

					const viewport = shadow.getViewport( face );

					_viewport.set(
						_viewportSize.x * viewport.x,
						_viewportSize.y * viewport.y,
						_viewportSize.x * viewport.z,
						_viewportSize.y * viewport.w
					);

					_state.viewport( _viewport );

				}

				_frustum = shadow.getFrustum( face );

				renderObject( scene, camera, shadowCamera, light, this.type );

			}

			// do blur pass for VSM

			if ( shadow.isPointLightShadow !== true && this.type === VSMShadowMap ) {

				VSMPass( shadow, camera );

			}

			shadow.needsUpdate = false;

		}

		_previousType = this.type;

		scope.needsUpdate = false;

		renderer.setRenderTarget( currentRenderTarget, activeCubeFace, activeMipmapLevel );

	};

	function VSMPass( shadow, camera ) {

		const geometry = objects.update( fullScreenMesh );

		if ( shadowMaterialVertical.defines.VSM_SAMPLES !== shadow.blurSamples ) {

			shadowMaterialVertical.defines.VSM_SAMPLES = shadow.blurSamples;
			shadowMaterialHorizontal.defines.VSM_SAMPLES = shadow.blurSamples;

			shadowMaterialVertical.needsUpdate = true;
			shadowMaterialHorizontal.needsUpdate = true;

		}

		if ( shadow.mapPass === null ) {

			shadow.mapPass = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, {
				format: RGFormat,
				type: HalfFloatType
			} );

		} else if ( shadow.mapPass.width !== shadow.map.width || shadow.mapPass.height !== shadow.map.height ) {

			shadow.mapPass.setSize( shadow.map.width, shadow.map.height );

		}

		// vertical pass - read from native depth texture

		shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.depthTexture;
		shadowMaterialVertical.uniforms.resolution.value.set( shadow.map.width, shadow.map.height );
		shadowMaterialVertical.uniforms.radius.value = shadow.radius;
		renderer.setRenderTarget( shadow.mapPass );
		renderer.clear();
		renderer.renderBufferDirect( camera, null, geometry, shadowMaterialVertical, fullScreenMesh, null );

		// horizontal pass

		shadowMaterialHorizontal.uniforms.shadow_pass.value = shadow.mapPass.texture;
		shadowMaterialHorizontal.uniforms.resolution.value.set( shadow.map.width, shadow.map.height );
		shadowMaterialHorizontal.uniforms.radius.value = shadow.radius;
		renderer.setRenderTarget( shadow.map );
		renderer.clear();
		renderer.renderBufferDirect( camera, null, geometry, shadowMaterialHorizontal, fullScreenMesh, null );

	}

	function getDepthMaterial( object, material, light, type ) {

		let result = null;

		const customMaterial = ( light.isPointLight === true ) ? object.customDistanceMaterial : object.customDepthMaterial;

		if ( customMaterial !== undefined ) {

			result = customMaterial;

		} else {

			result = ( light.isPointLight === true ) ? _distanceMaterial : _depthMaterial;

			if ( ( renderer.localClippingEnabled && material.clipShadows === true && Array.isArray( material.clippingPlanes ) && material.clippingPlanes.length !== 0 ) ||
				( material.displacementMap && material.displacementScale !== 0 ) ||
				( material.alphaMap && material.alphaTest > 0 ) ||
				( material.map && material.alphaTest > 0 ) ||
				( material.alphaToCoverage === true ) ) {

				// in this case we need a unique material instance reflecting the
				// appropriate state

				const keyA = result.uuid, keyB = material.uuid;

				let materialsForVariant = _materialCache[ keyA ];

				if ( materialsForVariant === undefined ) {

					materialsForVariant = {};
					_materialCa