/*! (c) 2019-2025 pixiv Inc. - https://github.com/pixiv/three-vrm/blob/release/LICENSE */ var O=Object.defineProperty;var S=Object.getOwnPropertySymbols;var C=Object.prototype.hasOwnProperty,P=Object.prototype.propertyIsEnumerable;var R=(l,i,e)=>i in l?O(l,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[i]=e,v=(l,i)=>{for(var e in i||(i={}))C.call(i,e)&&R(l,e,i[e]);if(S)for(var e of S(i))P.call(i,e)&&R(l,e,i[e]);return l};var m=(l,i,e)=>new Promise((t,r)=>{var o=n=>{try{u(e.next(n))}catch(d){r(d)}},s=n=>{try{u(e.throw(n))}catch(d){r(d)}},u=n=>n.done?t(n.value):Promise.resolve(n.value).then(o,s);u((e=e.apply(l,i)).next())});import*as E from"three";import*as b from"three";import*as x from"three";var I={"":3e3,srgb:3001};function L(l,i){parseInt(x.REVISION,10)>=152?l.colorSpace=i:l.encoding=I[i]}var h=class{get pending(){return Promise.all(this._pendings)}constructor(i,e){this._parser=i,this._materialParams=e,this._pendings=[]}assignPrimitive(i,e){e!=null&&(this._materialParams[i]=e)}assignColor(i,e,t){e!=null&&(this._materialParams[i]=new b.Color().fromArray(e),t&&this._materialParams[i].convertSRGBToLinear())}assignTexture(i,e,t){return m(this,null,function*(){let r=m(this,null,function*(){e!=null&&(yield this._parser.assignTexture(this._materialParams,i,e),t&&L(this._materialParams[i],"srgb"))});return this._pendings.push(r),r})}assignTextureByIndex(i,e,t){return m(this,null,function*(){return this.assignTexture(i,e!=null?{index:e}:void 0,t)})}};import*as a from"three";var U=`// #define PHONG varying vec3 vViewPosition; #ifndef FLAT_SHADED varying vec3 vNormal; #endif #include // #include #ifdef MTOON_USE_UV varying vec2 vUv; // COMPAT: pre-r151 uses a common uvTransform #if THREE_VRM_THREE_REVISION < 151 uniform mat3 uvTransform; #endif #endif // #include // COMAPT: pre-r151 uses uv2 for lightMap and aoMap #if THREE_VRM_THREE_REVISION < 151 #if defined( USE_LIGHTMAP ) || defined( USE_AOMAP ) attribute vec2 uv2; varying vec2 vUv2; uniform mat3 uv2Transform; #endif #endif // #include // #include #include #include #include #include #include #include #include #ifdef USE_OUTLINEWIDTHMULTIPLYTEXTURE uniform sampler2D outlineWidthMultiplyTexture; uniform mat3 outlineWidthMultiplyTextureUvTransform; #endif uniform float outlineWidthFactor; void main() { // #include #ifdef MTOON_USE_UV // COMPAT: pre-r151 uses a common uvTransform #if THREE_VRM_THREE_REVISION >= 151 vUv = uv; #else vUv = ( uvTransform * vec3( uv, 1 ) ).xy; #endif #endif // #include // COMAPT: pre-r151 uses uv2 for lightMap and aoMap #if THREE_VRM_THREE_REVISION < 151 #if defined( USE_LIGHTMAP ) || defined( USE_AOMAP ) vUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy; #endif #endif #include #include #include #include #include // we need this to compute the outline properly objectNormal = normalize( objectNormal ); #include #ifndef FLAT_SHADED // Normal computed with derivatives when FLAT_SHADED vNormal = normalize( transformedNormal ); #endif #include #include #include // #include #include #include #include vViewPosition = - mvPosition.xyz; #ifdef OUTLINE float worldNormalLength = length( transformedNormal ); vec3 outlineOffset = outlineWidthFactor * worldNormalLength * objectNormal; #ifdef USE_OUTLINEWIDTHMULTIPLYTEXTURE vec2 outlineWidthMultiplyTextureUv = ( outlineWidthMultiplyTextureUvTransform * vec3( vUv, 1 ) ).xy; float outlineTex = texture2D( outlineWidthMultiplyTexture, outlineWidthMultiplyTextureUv ).g; outlineOffset *= outlineTex; #endif #ifdef OUTLINE_WIDTH_SCREEN outlineOffset *= vViewPosition.z / projectionMatrix[ 1 ].y; #endif gl_Position = projectionMatrix * modelViewMatrix * vec4( outlineOffset + transformed, 1.0 ); gl_Position.z += 1E-6 * gl_Position.w; // anti-artifact magic #endif #include // #include #include #include }`;var A=`// #define PHONG uniform vec3 litFactor; uniform float opacity; uniform vec3 shadeColorFactor; #ifdef USE_SHADEMULTIPLYTEXTURE uniform sampler2D shadeMultiplyTexture; uniform mat3 shadeMultiplyTextureUvTransform; #endif uniform float shadingShiftFactor; uniform float shadingToonyFactor; #ifdef USE_SHADINGSHIFTTEXTURE uniform sampler2D shadingShiftTexture; uniform mat3 shadingShiftTextureUvTransform; uniform float shadingShiftTextureScale; #endif uniform float giEqualizationFactor; uniform vec3 parametricRimColorFactor; #ifdef USE_RIMMULTIPLYTEXTURE uniform sampler2D rimMultiplyTexture; uniform mat3 rimMultiplyTextureUvTransform; #endif uniform float rimLightingMixFactor; uniform float parametricRimFresnelPowerFactor; uniform float parametricRimLiftFactor; #ifdef USE_MATCAPTEXTURE uniform vec3 matcapFactor; uniform sampler2D matcapTexture; uniform mat3 matcapTextureUvTransform; #endif uniform vec3 emissive; uniform float emissiveIntensity; uniform vec3 outlineColorFactor; uniform float outlineLightingMixFactor; #ifdef USE_UVANIMATIONMASKTEXTURE uniform sampler2D uvAnimationMaskTexture; uniform mat3 uvAnimationMaskTextureUvTransform; #endif uniform float uvAnimationScrollXOffset; uniform float uvAnimationScrollYOffset; uniform float uvAnimationRotationPhase; #include #include #include #include // #include #if ( defined( MTOON_USE_UV ) && !defined( MTOON_UVS_VERTEX_ONLY ) ) varying vec2 vUv; #endif // #include // COMAPT: pre-r151 uses uv2 for lightMap and aoMap #if THREE_VRM_THREE_REVISION < 151 #if defined( USE_LIGHTMAP ) || defined( USE_AOMAP ) varying vec2 vUv2; #endif #endif #include #ifdef USE_MAP uniform mat3 mapUvTransform; #endif // #include #include #include // #include #include #ifdef USE_EMISSIVEMAP uniform mat3 emissiveMapUvTransform; #endif // #include // #include // #include #include // #include // COMPAT: pre-r151 doesn't have BRDF_Lambert in #if THREE_VRM_THREE_REVISION < 151 vec3 BRDF_Lambert( const in vec3 diffuseColor ) { return RECIPROCAL_PI * diffuseColor; } #endif #include #include // #include varying vec3 vViewPosition; struct MToonMaterial { vec3 diffuseColor; vec3 shadeColor; float shadingShift; }; float linearstep( float a, float b, float t ) { return clamp( ( t - a ) / ( b - a ), 0.0, 1.0 ); } /** * Convert NdotL into toon shading factor using shadingShift and shadingToony */ float getShading( const in float dotNL, const in float shadow, const in float shadingShift ) { float shading = dotNL; shading = shading + shadingShift; shading = linearstep( -1.0 + shadingToonyFactor, 1.0 - shadingToonyFactor, shading ); shading *= shadow; return shading; } /** * Mix diffuseColor and shadeColor using shading factor and light color */ vec3 getDiffuse( const in MToonMaterial material, const in float shading, in vec3 lightColor ) { #ifdef DEBUG_LITSHADERATE return vec3( BRDF_Lambert( shading * lightColor ) ); #endif vec3 col = lightColor * BRDF_Lambert( mix( material.shadeColor, material.diffuseColor, shading ) ); // The "comment out if you want to PBR absolutely" line #ifdef V0_COMPAT_SHADE col = min( col, material.diffuseColor ); #endif return col; } // COMPAT: pre-r156 uses a struct GeometricContext #if THREE_VRM_THREE_REVISION >= 157 void RE_Direct_MToon( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in MToonMaterial material, const in float shadow, inout ReflectedLight reflectedLight ) { float dotNL = clamp( dot( geometryNormal, directLight.direction ), -1.0, 1.0 ); vec3 irradiance = directLight.color; // directSpecular will be used for rim lighting, not an actual specular reflectedLight.directSpecular += irradiance; irradiance *= dotNL; float shading = getShading( dotNL, shadow, material.shadingShift ); // toon shaded diffuse reflectedLight.directDiffuse += getDiffuse( material, shading, directLight.color ); } void RE_IndirectDiffuse_MToon( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in MToonMaterial material, inout ReflectedLight reflectedLight ) { // indirect diffuse will use diffuseColor, no shadeColor involved reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); // directSpecular will be used for rim lighting, not an actual specular reflectedLight.directSpecular += irradiance; } #else void RE_Direct_MToon( const in IncidentLight directLight, const in GeometricContext geometry, const in MToonMaterial material, const in float shadow, inout ReflectedLight reflectedLight ) { float dotNL = clamp( dot( geometry.normal, directLight.direction ), -1.0, 1.0 ); vec3 irradiance = directLight.color; // directSpecular will be used for rim lighting, not an actual specular reflectedLight.directSpecular += irradiance; irradiance *= dotNL; float shading = getShading( dotNL, shadow, material.shadingShift ); // toon shaded diffuse reflectedLight.directDiffuse += getDiffuse( material, shading, directLight.color ); } void RE_IndirectDiffuse_MToon( const in vec3 irradiance, const in GeometricContext geometry, const in MToonMaterial material, inout ReflectedLight reflectedLight ) { // indirect diffuse will use diffuseColor, no shadeColor involved reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); // directSpecular will be used for rim lighting, not an actual specular reflectedLight.directSpecular += irradiance; } #endif #define RE_Direct RE_Direct_MToon #define RE_IndirectDiffuse RE_IndirectDiffuse_MToon #define Material_LightProbeLOD( material ) (0) #include // #include // #include #ifdef USE_NORMALMAP uniform sampler2D normalMap; uniform mat3 normalMapUvTransform; uniform vec2 normalScale; #endif // COMPAT: pre-r151 // USE_NORMALMAP_OBJECTSPACE used to be OBJECTSPACE_NORMALMAP in pre-r151 #if defined( USE_NORMALMAP_OBJECTSPACE ) || defined( OBJECTSPACE_NORMALMAP ) uniform mat3 normalMatrix; #endif // COMPAT: pre-r151 // USE_NORMALMAP_TANGENTSPACE used to be TANGENTSPACE_NORMALMAP in pre-r151 #if ! defined ( USE_TANGENT ) && ( defined ( USE_NORMALMAP_TANGENTSPACE ) || defined ( TANGENTSPACE_NORMALMAP ) ) // Per-Pixel Tangent Space Normal Mapping // http://hacksoflife.blogspot.ch/2009/11/per-pixel-tangent-space-normal-mapping.html // three-vrm specific change: it requires \`uv\` as an input in order to support uv scrolls // Temporary compat against shader change @ Three.js r126, r151 #if THREE_VRM_THREE_REVISION >= 151 mat3 getTangentFrame( vec3 eye_pos, vec3 surf_norm, vec2 uv ) { vec3 q0 = dFdx( eye_pos.xyz ); vec3 q1 = dFdy( eye_pos.xyz ); vec2 st0 = dFdx( uv.st ); vec2 st1 = dFdy( uv.st ); vec3 N = surf_norm; vec3 q1perp = cross( q1, N ); vec3 q0perp = cross( N, q0 ); vec3 T = q1perp * st0.x + q0perp * st1.x; vec3 B = q1perp * st0.y + q0perp * st1.y; float det = max( dot( T, T ), dot( B, B ) ); float scale = ( det == 0.0 ) ? 0.0 : inversesqrt( det ); return mat3( T * scale, B * scale, N ); } #else vec3 perturbNormal2Arb( vec2 uv, vec3 eye_pos, vec3 surf_norm, vec3 mapN, float faceDirection ) { vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) ); vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) ); vec2 st0 = dFdx( uv.st ); vec2 st1 = dFdy( uv.st ); vec3 N = normalize( surf_norm ); vec3 q1perp = cross( q1, N ); vec3 q0perp = cross( N, q0 ); vec3 T = q1perp * st0.x + q0perp * st1.x; vec3 B = q1perp * st0.y + q0perp * st1.y; // three-vrm specific change: Workaround for the issue that happens when delta of uv = 0.0 // TODO: Is this still required? Or shall I make a PR about it? if ( length( T ) == 0.0 || length( B ) == 0.0 ) { return surf_norm; } float det = max( dot( T, T ), dot( B, B ) ); float scale = ( det == 0.0 ) ? 0.0 : faceDirection * inversesqrt( det ); return normalize( T * ( mapN.x * scale ) + B * ( mapN.y * scale ) + N * mapN.z ); } #endif #endif // #include #include #include // == post correction ========================================================== void postCorrection() { #include #include #include #include #include } // == main procedure =========================================================== void main() { #include vec2 uv = vec2(0.5, 0.5); #if ( defined( MTOON_USE_UV ) && !defined( MTOON_UVS_VERTEX_ONLY ) ) uv = vUv; float uvAnimMask = 1.0; #ifdef USE_UVANIMATIONMASKTEXTURE vec2 uvAnimationMaskTextureUv = ( uvAnimationMaskTextureUvTransform * vec3( uv, 1 ) ).xy; uvAnimMask = texture2D( uvAnimationMaskTexture, uvAnimationMaskTextureUv ).b; #endif float uvRotCos = cos( uvAnimationRotationPhase * uvAnimMask ); float uvRotSin = sin( uvAnimationRotationPhase * uvAnimMask ); uv = mat2( uvRotCos, -uvRotSin, uvRotSin, uvRotCos ) * ( uv - 0.5 ) + 0.5; uv = uv + vec2( uvAnimationScrollXOffset, uvAnimationScrollYOffset ) * uvAnimMask; #endif #ifdef DEBUG_UV gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 ); #if ( defined( MTOON_USE_UV ) && !defined( MTOON_UVS_VERTEX_ONLY ) ) gl_FragColor = vec4( uv, 0.0, 1.0 ); #endif return; #endif vec4 diffuseColor = vec4( litFactor, opacity ); ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) ); vec3 totalEmissiveRadiance = emissive * emissiveIntensity; #include // #include #ifdef USE_MAP vec2 mapUv = ( mapUvTransform * vec3( uv, 1 ) ).xy; vec4 sampledDiffuseColor = texture2D( map, mapUv ); #ifdef DECODE_VIDEO_TEXTURE sampledDiffuseColor = vec4( mix( pow( sampledDiffuseColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), sampledDiffuseColor.rgb * 0.0773993808, vec3( lessThanEqual( sampledDiffuseColor.rgb, vec3( 0.04045 ) ) ) ), sampledDiffuseColor.w ); #endif diffuseColor *= sampledDiffuseColor; #endif // #include #if ( defined( USE_COLOR ) && !defined( IGNORE_VERTEX_COLOR ) ) diffuseColor.rgb *= vColor; #endif // #include #include // #include // #include float faceDirection = gl_FrontFacing ? 1.0 : -1.0; #ifdef FLAT_SHADED vec3 fdx = dFdx( vViewPosition ); vec3 fdy = dFdy( vViewPosition ); vec3 normal = normalize( cross( fdx, fdy ) ); #else vec3 normal = normalize( vNormal ); #ifdef DOUBLE_SIDED normal *= faceDirection; #endif #endif #ifdef USE_NORMALMAP vec2 normalMapUv = ( normalMapUvTransform * vec3( uv, 1 ) ).xy; #endif #ifdef USE_NORMALMAP_TANGENTSPACE #ifdef USE_TANGENT mat3 tbn = mat3( normalize( vTangent ), normalize( vBitangent ), normal ); #else mat3 tbn = getTangentFrame( - vViewPosition, normal, normalMapUv ); #endif #if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED ) tbn[0] *= faceDirection; tbn[1] *= faceDirection; #endif #endif #ifdef USE_CLEARCOAT_NORMALMAP #ifdef USE_TANGENT mat3 tbn2 = mat3( normalize( vTangent ), normalize( vBitangent ), normal ); #else mat3 tbn2 = getTangentFrame( - vViewPosition, normal, vClearcoatNormalMapUv ); #endif #if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED ) tbn2[0] *= faceDirection; tbn2[1] *= faceDirection; #endif #endif // non perturbed normal for clearcoat among others vec3 nonPerturbedNormal = normal; #ifdef OUTLINE normal *= -1.0; #endif // #include // COMPAT: pre-r151 // USE_NORMALMAP_OBJECTSPACE used to be OBJECTSPACE_NORMALMAP in pre-r151 #if defined( USE_NORMALMAP_OBJECTSPACE ) || defined( OBJECTSPACE_NORMALMAP ) normal = texture2D( normalMap, normalMapUv ).xyz * 2.0 - 1.0; // overrides both flatShading and attribute normals #ifdef FLIP_SIDED normal = - normal; #endif #ifdef DOUBLE_SIDED normal = normal * faceDirection; #endif normal = normalize( normalMatrix * normal ); // COMPAT: pre-r151 // USE_NORMALMAP_TANGENTSPACE used to be TANGENTSPACE_NORMALMAP in pre-r151 #elif defined( USE_NORMALMAP_TANGENTSPACE ) || defined( TANGENTSPACE_NORMALMAP ) vec3 mapN = texture2D( normalMap, normalMapUv ).xyz * 2.0 - 1.0; mapN.xy *= normalScale; // COMPAT: pre-r151 #if THREE_VRM_THREE_REVISION >= 151 || defined( USE_TANGENT ) normal = normalize( tbn * mapN ); #else normal = perturbNormal2Arb( uv, -vViewPosition, normal, mapN, faceDirection ); #endif #endif // #include #ifdef USE_EMISSIVEMAP vec2 emissiveMapUv = ( emissiveMapUvTransform * vec3( uv, 1 ) ).xy; totalEmissiveRadiance *= texture2D( emissiveMap, emissiveMapUv ).rgb; #endif #ifdef DEBUG_NORMAL gl_FragColor = vec4( 0.5 + 0.5 * normal, 1.0 ); return; #endif // -- MToon: lighting -------------------------------------------------------- // accumulation // #include MToonMaterial material; material.diffuseColor = diffuseColor.rgb; material.shadeColor = shadeColorFactor; #ifdef USE_SHADEMULTIPLYTEXTURE vec2 shadeMultiplyTextureUv = ( shadeMultiplyTextureUvTransform * vec3( uv, 1 ) ).xy; material.shadeColor *= texture2D( shadeMultiplyTexture, shadeMultiplyTextureUv ).rgb; #endif #if ( defined( USE_COLOR ) && !defined( IGNORE_VERTEX_COLOR ) ) material.shadeColor.rgb *= vColor; #endif material.shadingShift = shadingShiftFactor; #ifdef USE_SHADINGSHIFTTEXTURE vec2 shadingShiftTextureUv = ( shadingShiftTextureUvTransform * vec3( uv, 1 ) ).xy; material.shadingShift += texture2D( shadingShiftTexture, shadingShiftTextureUv ).r * shadingShiftTextureScale; #endif // #include // MToon Specific changes: // Since we want to take shadows into account of shading instead of irradiance, // we had to modify the codes that multiplies the results of shadowmap into color of direct lights. // COMPAT: pre-r156 uses a struct GeometricContext #if THREE_VRM_THREE_REVISION >= 157 vec3 geometryPosition = - vViewPosition; vec3 geometryNormal = normal; vec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition ); vec3 geometryClearcoatNormal; #ifdef USE_CLEARCOAT geometryClearcoatNormal = clearcoatNormal; #endif #else GeometricContext geometry; geometry.position = - vViewPosition; geometry.normal = normal; geometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition ); #ifdef USE_CLEARCOAT geometry.clearcoatNormal = clearcoatNormal; #endif #endif IncidentLight directLight; // since these variables will be used in unrolled loop, we have to define in prior float shadow; #if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct ) PointLight pointLight; #if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0 PointLightShadow pointLightShadow; #endif #pragma unroll_loop_start for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) { pointLight = pointLights[ i ]; // COMPAT: pre-r156 uses a struct GeometricContext #if THREE_VRM_THREE_REVISION >= 157 getPointLightInfo( pointLight, geometryPosition, directLight ); #else getPointLightInfo( pointLight, geometry, directLight ); #endif shadow = 1.0; #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS ) pointLightShadow = pointLightShadows[ i ]; // COMPAT: pre-r166 // r166 introduced shadowIntensity #if THREE_VRM_THREE_REVISION >= 166 shadow = all( bvec2( directLight.visible, receiveShadow ) ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowIntensity, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0; #else shadow = all( bvec2( directLight.visible, receiveShadow ) ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0; #endif #endif // COMPAT: pre-r156 uses a struct GeometricContext #if THREE_VRM_THREE_REVISION >= 157 RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, shadow, reflectedLight ); #else RE_Direct( directLight, geometry, material, shadow, reflectedLight ); #endif } #pragma unroll_loop_end #endif #if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct ) SpotLight spotLight; #if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0 SpotLightShadow spotLightShadow; #endif #pragma unroll_loop_start for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) { spotLight = spotLights[ i ]; // COMPAT: pre-r156 uses a struct GeometricContext #if THREE_VRM_THREE_REVISION >= 157 getSpotLightInfo( spotLight, geometryPosition, directLight ); #else getSpotLightInfo( spotLight, geometry, directLight ); #endif shadow = 1.0; #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS ) spotLightShadow = spotLightShadows[ i ]; // COMPAT: pre-r166 // r166 introduced shadowIntensity #if THREE_VRM_THREE_REVISION >= 166 shadow = all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0; #else shadow = all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0; #endif #endif // COMPAT: pre-r156 uses a struct GeometricContext #if THREE_VRM_THREE_REVISION >= 157 RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, shadow, reflectedLight ); #else RE_Direct( directLight, geometry, material, shadow, reflectedLight ); #endif } #pragma unroll_loop_end #endif #if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct ) DirectionalLight directionalLight; #if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0 DirectionalLightShadow directionalLightShadow; #endif #pragma unroll_loop_start for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) { directionalLight = directionalLights[ i ]; // COMPAT: pre-r156 uses a struct GeometricContext #if THREE_VRM_THREE_REVISION >= 157 getDirectionalLightInfo( directionalLight, directLight ); #else getDirectionalLightInfo( directionalLight, geometry, directLight ); #endif shadow = 1.0; #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS ) directionalLightShadow = directionalLightShadows[ i ]; // COMPAT: pre-r166 // r166 introduced shadowIntensity #if THREE_VRM_THREE_REVISION >= 166 shadow = all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0; #else shadow = all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0; #endif #endif // COMPAT: pre-r156 uses a struct GeometricContext #if THREE_VRM_THREE_REVISION >= 157 RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, shadow, reflectedLight ); #else RE_Direct( directLight, geometry, material, shadow, reflectedLight ); #endif } #pragma unroll_loop_end #endif // #if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea ) // RectAreaLight rectAreaLight; // #pragma unroll_loop_start // for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) { // rectAreaLight = rectAreaLights[ i ]; // RE_Direct_RectArea( rectAreaLight, geometry, material, reflectedLight ); // } // #pragma unroll_loop_end // #endif #if defined( RE_IndirectDiffuse ) vec3 iblIrradiance = vec3( 0.0 ); vec3 irradiance = getAmbientLightIrradiance( ambientLightColor ); // COMPAT: pre-r156 uses a struct GeometricContext // COMPAT: pre-r156 doesn't have a define USE_LIGHT_PROBES #if THREE_VRM_THREE_REVISION >= 157 #if defined( USE_LIGHT_PROBES ) irradiance += getLightProbeIrradiance( lightProbe, geometryNormal ); #endif #else irradiance += getLightProbeIrradiance( lightProbe, geometry.normal ); #endif #if ( NUM_HEMI_LIGHTS > 0 ) #pragma unroll_loop_start for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) { // COMPAT: pre-r156 uses a struct GeometricContext #if THREE_VRM_THREE_REVISION >= 157 irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal ); #else irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry.normal ); #endif } #pragma unroll_loop_end #endif #endif // #if defined( RE_IndirectSpecular ) // vec3 radiance = vec3( 0.0 ); // vec3 clearcoatRadiance = vec3( 0.0 ); // #endif #include #include // modulation #include vec3 col = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse; #ifdef DEBUG_LITSHADERATE gl_FragColor = vec4( col, diffuseColor.a ); postCorrection(); return; #endif // -- MToon: rim lighting ----------------------------------------- vec3 viewDir = normalize( vViewPosition ); #ifndef PHYSICALLY_CORRECT_LIGHTS reflectedLight.directSpecular /= PI; #endif vec3 rimMix = mix( vec3( 1.0 ), reflectedLight.directSpecular, 1.0 ); vec3 rim = parametricRimColorFactor * pow( saturate( 1.0 - dot( viewDir, normal ) + parametricRimLiftFactor ), parametricRimFresnelPowerFactor ); #ifdef USE_MATCAPTEXTURE { vec3 x = normalize( vec3( viewDir.z, 0.0, -viewDir.x ) ); vec3 y = cross( viewDir, x ); // guaranteed to be normalized vec2 sphereUv = 0.5 + 0.5 * vec2( dot( x, normal ), -dot( y, normal ) ); sphereUv = ( matcapTextureUvTransform * vec3( sphereUv, 1 ) ).xy; vec3 matcap = texture2D( matcapTexture, sphereUv ).rgb; rim += matcapFactor * matcap; } #endif #ifdef USE_RIMMULTIPLYTEXTURE vec2 rimMultiplyTextureUv = ( rimMultiplyTextureUvTransform * vec3( uv, 1 ) ).xy; rim *= texture2D( rimMultiplyTexture, rimMultiplyTextureUv ).rgb; #endif col += rimMix * rim; // -- MToon: Emission -------------------------------------------------------- col += totalEmissiveRadiance; // #include // -- Almost done! ----------------------------------------------------------- #if defined( OUTLINE ) col = outlineColorFactor.rgb * mix( vec3( 1.0 ), col, outlineLightingMixFactor ); #endif #ifdef OPAQUE diffuseColor.a = 1.0; #endif gl_FragColor = vec4( col, diffuseColor.a ); postCorrection(); } `;var g={None:"none",Normal:"normal",LitShadeRate:"litShadeRate",UV:"uv"};var p={None:"none",WorldCoordinates:"worldCoordinates",ScreenCoordinates:"screenCoordinates"};import*as y from"three";var w={3e3:"",3001:"srgb"};function T(l){return parseInt(y.REVISION,10)>=152?l.colorSpace:w[l.encoding]}var f=class extends a.ShaderMaterial{constructor(e={}){var t;super({vertexShader:U,fragmentShader:A});this.uvAnimationScrollXSpeedFactor=0;this.uvAnimationScrollYSpeedFactor=0;this.uvAnimationRotationSpeedFactor=0;this.fog=!0;this.normalMapType=a.TangentSpaceNormalMap;this._ignoreVertexColor=!0;this._v0CompatShade=!1;this._debugMode=g.None;this._outlineWidthMode=p.None;this._isOutline=!1;e.transparentWithZWrite&&(e.depthWrite=!0),delete e.transparentWithZWrite,e.fog=!0,e.lights=!0,e.clipping=!0,this.uniforms=a.UniformsUtils.merge([a.UniformsLib.common,a.UniformsLib.normalmap,a.UniformsLib.emissivemap,a.UniformsLib.fog,a.UniformsLib.lights,{litFactor:{value:new a.Color(1,1,1)},mapUvTransform:{value:new a.Matrix3},colorAlpha:{value:1},normalMapUvTransform:{value:new a.Matrix3},shadeColorFactor:{value:new a.Color(0,0,0)},shadeMultiplyTexture:{value:null},shadeMultiplyTextureUvTransform:{value:new a.Matrix3},shadingShiftFactor:{value:0},shadingShiftTexture:{value:null},shadingShiftTextureUvTransform:{value:new a.Matrix3},shadingShiftTextureScale:{value:1},shadingToonyFactor:{value:.9},giEqualizationFactor:{value:.9},matcapFactor:{value:new a.Color(1,1,1)},matcapTexture:{value:null},matcapTextureUvTransform:{value:new a.Matrix3},parametricRimColorFactor:{value:new a.Color(0,0,0)},rimMultiplyTexture:{value:null},rimMultiplyTextureUvTransform:{value:new a.Matrix3},rimLightingMixFactor:{value:1},parametricRimFresnelPowerFactor:{value:5},parametricRimLiftFactor:{value:0},emissive:{value:new a.Color(0,0,0)},emissiveIntensity:{value:1},emissiveMapUvTransform:{value:new a.Matrix3},outlineWidthMultiplyTexture:{value:null},outlineWidthMultiplyTextureUvTransform:{value:new a.Matrix3},outlineWidthFactor:{value:0},outlineColorFactor:{value:new a.Color(0,0,0)},outlineLightingMixFactor:{value:1},uvAnimationMaskTexture:{value:null},uvAnimationMaskTextureUvTransform:{value:new a.Matrix3},uvAnimationScrollXOffset:{value:0},uvAnimationScrollYOffset:{value:0},uvAnimationRotationPhase:{value:0}},(t=e.uniforms)!=null?t:{}]),this.setValues(e),this._uploadUniformsWorkaround(),this.customProgramCacheKey=()=>[...Object.entries(this._generateDefines()).map(([r,o])=>`${r}:${o}`),this.matcapTexture?`matcapTextureColorSpace:${T(this.matcapTexture)}`:"",this.shadeMultiplyTexture?`shadeMultiplyTextureColorSpace:${T(this.shadeMultiplyTexture)}`:"",this.rimMultiplyTexture?`rimMultiplyTextureColorSpace:${T(this.rimMultiplyTexture)}`:""].join(","),this.onBeforeCompile=r=>{let o=parseInt(a.REVISION,10),s=Object.entries(v(v({},this._generateDefines()),this.defines)).filter(([u,n])=>!!n).map(([u,n])=>`#define ${u} ${n}`).join(` `)+` `;r.vertexShader=s+r.vertexShader,r.fragmentShader=s+r.fragmentShader,o<154&&(r.fragmentShader=r.fragmentShader.replace("#include ","#include "))}}get color(){return this.uniforms.litFactor.value}set color(e){this.uniforms.litFactor.value=e}get map(){return this.uniforms.map.value}set map(e){this.uniforms.map.value=e}get normalMap(){return this.uniforms.normalMap.value}set normalMap(e){this.uniforms.normalMap.value=e}get normalScale(){return this.uniforms.normalScale.value}set normalScale(e){this.uniforms.normalScale.value=e}get emissive(){return this.uniforms.emissive.value}set emissive(e){this.uniforms.emissive.value=e}get emissiveIntensity(){return this.uniforms.emissiveIntensity.value}set emissiveIntensity(e){this.uniforms.emissiveIntensity.value=e}get emissiveMap(){return this.uniforms.emissiveMap.value}set emissiveMap(e){this.uniforms.emissiveMap.value=e}get shadeColorFactor(){return this.uniforms.shadeColorFactor.value}set shadeColorFactor(e){this.uniforms.shadeColorFactor.value=e}get shadeMultiplyTexture(){return this.uniforms.shadeMultiplyTexture.value}set shadeMultiplyTexture(e){this.uniforms.shadeMultiplyTexture.value=e}get shadingShiftFactor(){return this.uniforms.shadingShiftFactor.value}set shadingShiftFactor(e){this.uniforms.shadingShiftFactor.value=e}get shadingShiftTexture(){return this.uniforms.shadingShiftTexture.value}set shadingShiftTexture(e){this.uniforms.shadingShiftTexture.value=e}get shadingShiftTextureScale(){return this.uniforms.shadingShiftTextureScale.value}set shadingShiftTextureScale(e){this.uniforms.shadingShiftTextureScale.value=e}get shadingToonyFactor(){return this.uniforms.shadingToonyFactor.value}set shadingToonyFactor(e){this.uniforms.shadingToonyFactor.value=e}get giEqualizationFactor(){return this.uniforms.giEqualizationFactor.value}set giEqualizationFactor(e){this.uniforms.giEqualizationFactor.value=e}get matcapFactor(){return this.uniforms.matcapFactor.value}set matcapFactor(e){this.uniforms.matcapFactor.value=e}get matcapTexture(){return this.uniforms.matcapTexture.value}set matcapTexture(e){this.uniforms.matcapTexture.value=e}get parametricRimColorFactor(){return this.uniforms.parametricRimColorFactor.value}set parametricRimColorFactor(e){this.uniforms.parametricRimColorFactor.value=e}get rimMultiplyTexture(){return this.uniforms.rimMultiplyTexture.value}set rimMultiplyTexture(e){this.uniforms.rimMultiplyTexture.value=e}get rimLightingMixFactor(){return this.uniforms.rimLightingMixFactor.value}set rimLightingMixFactor(e){this.uniforms.rimLightingMixFactor.value=e}get parametricRimFresnelPowerFactor(){return this.uniforms.parametricRimFresnelPowerFactor.value}set parametricRimFresnelPowerFactor(e){this.uniforms.parametricRimFresnelPowerFactor.value=e}get parametricRimLiftFactor(){return this.uniforms.parametricRimLiftFactor.value}set parametricRimLiftFactor(e){this.uniforms.parametricRimLiftFactor.value=e}get outlineWidthMultiplyTexture(){return this.uniforms.outlineWidthMultiplyTexture.value}set outlineWidthMultiplyTexture(e){this.uniforms.outlineWidthMultiplyTexture.value=e}get outlineWidthFactor(){return this.uniforms.outlineWidthFactor.value}set outlineWidthFactor(e){this.uniforms.outlineWidthFactor.value=e}get outlineColorFactor(){return this.uniforms.outlineColorFactor.value}set outlineColorFactor(e){this.uniforms.outlineColorFactor.value=e}get outlineLightingMixFactor(){return this.uniforms.outlineLightingMixFactor.value}set outlineLightingMixFactor(e){this.uniforms.outlineLightingMixFactor.value=e}get uvAnimationMaskTexture(){return this.uniforms.uvAnimationMaskTexture.value}set uvAnimationMaskTexture(e){this.uniforms.uvAnimationMaskTexture.value=e}get uvAnimationScrollXOffset(){return this.uniforms.uvAnimationScrollXOffset.value}set uvAnimationScrollXOffset(e){this.uniforms.uvAnimationScrollXOffset.value=e}get uvAnimationScrollYOffset(){return this.uniforms.uvAnimationScrollYOffset.value}set uvAnimationScrollYOffset(e){this.uniforms.uvAnimationScrollYOffset.value=e}get uvAnimationRotationPhase(){return this.uniforms.uvAnimationRotationPhase.value}set uvAnimationRotationPhase(e){this.uniforms.uvAnimationRotationPhase.value=e}get ignoreVertexColor(){return this._ignoreVertexColor}set ignoreVertexColor(e){this._ignoreVertexColor=e,this.needsUpdate=!0}get v0CompatShade(){return this._v0CompatShade}set v0CompatShade(e){this._v0CompatShade=e,this.needsUpdate=!0}get debugMode(){return this._debugMode}set debugMode(e){this._debugMode=e,this.needsUpdate=!0}get outlineWidthMode(){return this._outlineWidthMode}set outlineWidthMode(e){this._outlineWidthMode=e,this.needsUpdate=!0}get isOutline(){return this._isOutline}set isOutline(e){this._isOutline=e,this.needsUpdate=!0}get isMToonMaterial(){return!0}update(e){this._uploadUniformsWorkaround(),this._updateUVAnimation(e)}copy(e){return super.copy(e),this.map=e.map,this.normalMap=e.normalMap,this.emissiveMap=e.emissiveMap,this.shadeMultiplyTexture=e.shadeMultiplyTexture,this.shadingShiftTexture=e.shadingShiftTexture,this.matcapTexture=e.matcapTexture,this.rimMultiplyTexture=e.rimMultiplyTexture,this.outlineWidthMultiplyTexture=e.outlineWidthMultiplyTexture,this.uvAnimationMaskTexture=e.uvAnimationMaskTexture,this.normalMapType=e.normalMapType,this.uvAnimationScrollXSpeedFactor=e.uvAnimationScrollXSpeedFactor,this.uvAnimationScrollYSpeedFactor=e.uvAnimationScrollYSpeedFactor,this.uvAnimationRotationSpeedFactor=e.uvAnimationRotationSpeedFactor,this.ignoreVertexColor=e.ignoreVertexColor,this.v0CompatShade=e.v0CompatShade,this.debugMode=e.debugMode,this.outlineWidthMode=e.outlineWidthMode,this.isOutline=e.isOutline,this.needsUpdate=!0,this}_updateUVAnimation(e){this.uniforms.uvAnimationScrollXOffset.value+=e*this.uvAnimationScrollXSpeedFactor,this.uniforms.uvAnimationScrollYOffset.value+=e*this.uvAnimationScrollYSpeedFactor,this.uniforms.uvAnimationRotationPhase.value+=e*this.uvAnimationRotationSpeedFactor,this.uniforms.alphaTest.value=this.alphaTest,this.uniformsNeedUpdate=!0}_uploadUniformsWorkaround(){this.uniforms.opacity.value=this.opacity,this._updateTextureMatrix(this.uniforms.map,this.uniforms.mapUvTransform),this._updateTextureMatrix(this.uniforms.normalMap,this.uniforms.normalMapUvTransform),this._updateTextureMatrix(this.uniforms.emissiveMap,this.uniforms.emissiveMapUvTransform),this._updateTextureMatrix(this.uniforms.shadeMultiplyTexture,this.uniforms.shadeMultiplyTextureUvTransform),this._updateTextureMatrix(this.uniforms.shadingShiftTexture,this.uniforms.shadingShiftTextureUvTransform),this._updateTextureMatrix(this.uniforms.matcapTexture,this.uniforms.matcapTextureUvTransform),this._updateTextureMatrix(this.uniforms.rimMultiplyTexture,this.uniforms.rimMultiplyTextureUvTransform),this._updateTextureMatrix(this.uniforms.outlineWidthMultiplyTexture,this.uniforms.outlineWidthMultiplyTextureUvTransform),this._updateTextureMatrix(this.uniforms.uvAnimationMaskTexture,this.uniforms.uvAnimationMaskTextureUvTransform),this.uniformsNeedUpdate=!0}_generateDefines(){let e=parseInt(a.REVISION,10),t=this.outlineWidthMultiplyTexture!==null,r=this.map!==null||this.normalMap!==null||this.emissiveMap!==null||this.shadeMultiplyTexture!==null||this.shadingShiftTexture!==null||this.rimMultiplyTexture!==null||this.uvAnimationMaskTexture!==null;return{THREE_VRM_THREE_REVISION:e,OUTLINE:this._isOutline,MTOON_USE_UV:t||r,MTOON_UVS_VERTEX_ONLY:t&&!r,V0_COMPAT_SHADE:this._v0CompatShade,USE_SHADEMULTIPLYTEXTURE:this.shadeMultiplyTexture!==null,USE_SHADINGSHIFTTEXTURE:this.shadingShiftTexture!==null,USE_MATCAPTEXTURE:this.matcapTexture!==null,USE_RIMMULTIPLYTEXTURE:this.rimMultiplyTexture!==null,USE_OUTLINEWIDTHMULTIPLYTEXTURE:this._isOutline&&this.outlineWidthMultiplyTexture!==null,USE_UVANIMATIONMASKTEXTURE:this.uvAnimationMaskTexture!==null,IGNORE_VERTEX_COLOR:this._ignoreVertexColor===!0,DEBUG_NORMAL:this._debugMode==="normal",DEBUG_LITSHADERATE:this._debugMode==="litShadeRate",DEBUG_UV:this._debugMode==="uv",OUTLINE_WIDTH_SCREEN:this._isOutline&&this._outlineWidthMode===p.ScreenCoordinates}}_updateTextureMatrix(e,t){e.value&&(e.value.matrixAutoUpdate&&e.value.updateMatrix(),t.value.copy(e.value.matrix))}};var D=new Set(["1.0","1.0-beta"]),c=class c{get name(){return c.EXTENSION_NAME}constructor(i,e={}){var t,r,o,s;this.parser=i,this.materialType=(t=e.materialType)!=null?t:f,this.renderOrderOffset=(r=e.renderOrderOffset)!=null?r:0,this.v0CompatShade=(o=e.v0CompatShade)!=null?o:!1,this.debugMode=(s=e.debugMode)!=null?s:"none",this._mToonMaterialSet=new Set}beforeRoot(){return m(this,null,function*(){this._removeUnlitExtensionIfMToonExists()})}afterRoot(i){return m(this,null,function*(){i.userData.vrmMToonMaterials=Array.from(this._mToonMaterialSet)})}getMaterialType(i){return this._getMToonExtension(i)?this.materialType:null}extendMaterialParams(i,e){let t=this._getMToonExtension(i);return t?this._extendMaterialParams(t,e):null}loadMesh(i){return m(this,null,function*(){var u;let e=this.parser,r=(u=e.json.meshes)==null?void 0:u[i];if(r==null)throw new Error(`MToonMaterialLoaderPlugin: Attempt to use meshes[${i}] of glTF but the mesh doesn't exist`);let o=r.primitives,s=yield e.loadMesh(i);if(o.length===1){let n=s,d=o[0].material;d!=null&&this._setupPrimitive(n,d)}else{let n=s;for(let d=0;d{var u;this._getMToonExtension(o)&&((u=r.extensions)!=null&&u.KHR_materials_unlit)&&delete r.extensions.KHR_materials_unlit})}_getMToonExtension(i){var u,n;let r=(u=this.parser.json.materials)==null?void 0:u[i];if(r==null){console.warn(`MToonMaterialLoaderPlugin: Attempt to use materials[${i}] of glTF but the material doesn't exist`);return}let o=(n=r.extensions)==null?void 0:n[c.EXTENSION_NAME];if(o==null)return;let s=o.specVersion;if(!D.has(s)){console.warn(`MToonMaterialLoaderPlugin: Unknown ${c.EXTENSION_NAME} specVersion "${s}"`);return}return o}_extendMaterialParams(i,e){return m(this,null,function*(){var r;delete e.metalness,delete e.roughness;let t=new h(this.parser,e);t.assignPrimitive("transparentWithZWrite",i.transparentWithZWrite),t.assignColor("shadeColorFactor",i.shadeColorFactor),t.assignTexture("shadeMultiplyTexture",i.shadeMultiplyTexture,!0),t.assignPrimitive("shadingShiftFactor",i.shadingShiftFactor),t.assignTexture("shadingShiftTexture",i.shadingShiftTexture,!0),t.assignPrimitive("shadingShiftTextureScale",(r=i.shadingShiftTexture)==null?void 0:r.scale),t.assignPrimitive("shadingToonyFactor",i.shadingToonyFactor),t.assignPrimitive("giEqualizationFactor",i.giEqualizationFactor),t.assignColor("matcapFactor",i.matcapFactor),t.assignTexture("matcapTexture",i.matcapTexture,!0),t.assignColor("parametricRimColorFactor",i.parametricRimColorFactor),t.assignTexture("rimMultiplyTexture",i.rimMultiplyTexture,!0),t.assignPrimitive("rimLightingMixFactor",i.rimLightingMixFactor),t.assignPrimitive("parametricRimFresnelPowerFactor",i.parametricRimFresnelPowerFactor),t.assignPrimitive("parametricRimLiftFactor",i.parametricRimLiftFactor),t.assignPrimitive("outlineWidthMode",i.outlineWidthMode),t.assignPrimitive("outlineWidthFactor",i.outlineWidthFactor),t.assignTexture("outlineWidthMultiplyTexture",i.outlineWidthMultiplyTexture,!1),t.assignColor("outlineColorFactor",i.outlineColorFactor),t.assignPrimitive("outlineLightingMixFactor",i.outlineLightingMixFactor),t.assignTexture("uvAnimationMaskTexture",i.uvAnimationMaskTexture,!1),t.assignPrimitive("uvAnimationScrollXSpeedFactor",i.uvAnimationScrollXSpeedFactor),t.assignPrimitive("uvAnimationScrollYSpeedFactor",i.uvAnimationScrollYSpeedFactor),t.assignPrimitive("uvAnimationRotationSpeedFactor",i.uvAnimationRotationSpeedFactor),t.assignPrimitive("v0CompatShade",this.v0CompatShade),t.assignPrimitive("debugMode",this.debugMode),yield t.pending})}_setupPrimitive(i,e){let t=this._getMToonExtension(e);if(t){let r=this._parseRenderOrder(t);i.renderOrder=r+this.renderOrderOffset,this._generateOutline(i),this._addToMaterialSet(i);return}}_shouldGenerateOutline(i){return typeof i.outlineWidthMode=="string"&&i.outlineWidthMode!=="none"&&typeof i.outlineWidthFactor=="number"&&i.outlineWidthFactor>0}_generateOutline(i){let e=i.material;if(!(e instanceof E.Material)||!this._shouldGenerateOutline(e))return;i.material=[e];let t=e.clone();t.name+=" (Outline)",t.isOutline=!0,t.side=E.BackSide,i.material.push(t);let r=i.geometry,o=r.index?r.index.count:r.attributes.position.count/3;r.addGroup(0,o,0),r.addGroup(0,o,1)}_addToMaterialSet(i){let e=i.material,t=new Set;Array.isArray(e)?e.forEach(r=>t.add(r)):t.add(e);for(let r of t)this._mToonMaterialSet.add(r)}_parseRenderOrder(i){var t;return(i.transparentWithZWrite?0:19)+((t=i.renderQueueOffsetNumber)!=null?t:0)}};c.EXTENSION_NAME="VRMC_materials_mtoon";var M=c;export{f as MToonMaterial,g as MToonMaterialDebugMode,M as MToonMaterialLoaderPlugin,p as MToonMaterialOutlineWidthMode};