babylon-mtoon-material
Version:
Unity MToon Shader WebGL porting with babylon.js
1 lines • 98 kB
JavaScript
!function(e,i){"object"==typeof exports&&"object"==typeof module?module.exports=i(require("@babylonjs/core/Misc/decorators"),require("@babylonjs/core/Misc/smartArray"),require("@babylonjs/core/scene"),require("@babylonjs/core/Maths/math.vector"),require("@babylonjs/core/Maths/math.color"),require("@babylonjs/core/Buffers/buffer"),require("@babylonjs/core/Materials/imageProcessingConfiguration"),require("@babylonjs/core/Materials/material"),require("@babylonjs/core/Materials/pushMaterial"),require("@babylonjs/core/Materials/materialHelper"),require("@babylonjs/core/Engines/constants"),require("@babylonjs/core/Materials/effectFallbacks"),require("@babylonjs/core/Materials/effect"),require("@babylonjs/core/Materials/material.detailMapConfiguration"),require("@babylonjs/core/Materials/materialPluginEvent"),require("@babylonjs/core/Misc/iInspectable"),require("@babylonjs/core/sceneComponent"),require("@babylonjs/core/Materials/materialDefines")):"function"==typeof define&&define.amd?define(["@babylonjs/core/Misc/decorators","@babylonjs/core/Misc/smartArray","@babylonjs/core/scene","@babylonjs/core/Maths/math.vector","@babylonjs/core/Maths/math.color","@babylonjs/core/Buffers/buffer","@babylonjs/core/Materials/imageProcessingConfiguration","@babylonjs/core/Materials/material","@babylonjs/core/Materials/pushMaterial","@babylonjs/core/Materials/materialHelper","@babylonjs/core/Engines/constants","@babylonjs/core/Materials/effectFallbacks","@babylonjs/core/Materials/effect","@babylonjs/core/Materials/material.detailMapConfiguration","@babylonjs/core/Materials/materialPluginEvent","@babylonjs/core/Misc/iInspectable","@babylonjs/core/sceneComponent","@babylonjs/core/Materials/materialDefines"],i):"object"==typeof exports?exports["babylon-mtoon-material"]=i(require("@babylonjs/core/Misc/decorators"),require("@babylonjs/core/Misc/smartArray"),require("@babylonjs/core/scene"),require("@babylonjs/core/Maths/math.vector"),require("@babylonjs/core/Maths/math.color"),require("@babylonjs/core/Buffers/buffer"),require("@babylonjs/core/Materials/imageProcessingConfiguration"),require("@babylonjs/core/Materials/material"),require("@babylonjs/core/Materials/pushMaterial"),require("@babylonjs/core/Materials/materialHelper"),require("@babylonjs/core/Engines/constants"),require("@babylonjs/core/Materials/effectFallbacks"),require("@babylonjs/core/Materials/effect"),require("@babylonjs/core/Materials/material.detailMapConfiguration"),require("@babylonjs/core/Materials/materialPluginEvent"),require("@babylonjs/core/Misc/iInspectable"),require("@babylonjs/core/sceneComponent"),require("@babylonjs/core/Materials/materialDefines")):e["babylon-mtoon-material"]=i(e["@babylonjs/core/Misc/decorators"],e["@babylonjs/core/Misc/smartArray"],e["@babylonjs/core/scene"],e["@babylonjs/core/Maths/math.vector"],e["@babylonjs/core/Maths/math.color"],e["@babylonjs/core/Buffers/buffer"],e["@babylonjs/core/Materials/imageProcessingConfiguration"],e["@babylonjs/core/Materials/material"],e["@babylonjs/core/Materials/pushMaterial"],e["@babylonjs/core/Materials/materialHelper"],e["@babylonjs/core/Engines/constants"],e["@babylonjs/core/Materials/effectFallbacks"],e["@babylonjs/core/Materials/effect"],e["@babylonjs/core/Materials/material.detailMapConfiguration"],e["@babylonjs/core/Materials/materialPluginEvent"],e["@babylonjs/core/Misc/iInspectable"],e["@babylonjs/core/sceneComponent"],e["@babylonjs/core/Materials/materialDefines"])}(self,((e,i,n,t,o,a,r,s,l,d,h,f,u,m,c,p,g,_)=>(()=>{"use strict";var A={908:e=>{e.exports=a},556:e=>{e.exports=h},272:e=>{e.exports=u},55:e=>{e.exports=f},677:e=>{e.exports=r},66:e=>{e.exports=s},824:e=>{e.exports=m},713:e=>{e.exports=_},221:e=>{e.exports=d},628:e=>{e.exports=c},721:e=>{e.exports=l},548:e=>{e.exports=o},694:e=>{e.exports=t},388:i=>{i.exports=e},812:e=>{e.exports=p},474:e=>{e.exports=i},538:e=>{e.exports=n},667:e=>{e.exports=g}},I={};function v(e){var i=I[e];if(void 0!==i)return i.exports;var n=I[e]={exports:{}};return A[e](n,n.exports,v),n.exports}v.d=(e,i)=>{for(var n in i)v.o(i,n)&&!v.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:i[n]})},v.o=(e,i)=>Object.prototype.hasOwnProperty.call(e,i),v.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var M={};return(()=>{function e(e,i,n,t){var o,a=arguments.length,r=a<3?i:null===t?t=Object.getOwnPropertyDescriptor(i,n):t;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,i,n,t);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(r=(a<3?o(r):a>3?o(i,n,r):o(i,n))||r);return a>3&&r&&Object.defineProperty(i,n,r),r}v.r(M),v.d(M,{CullMode:()=>L,DebugMode:()=>T,MToonMaterial:()=>x,OutlineColorMode:()=>N,OutlineWidthMode:()=>D}),Object.create,Object.create;var i=v(388),n=v(474),t=v(538),o=v(694),a=v(548),r=v(908),s=v(677),l=v(66),d=v(721),h=v(221),f=v(556),u=v(55),m=v(272),c=v(824),p=v(628),g=v(812),_=v(667);class A{constructor(e,i){this.scene=e,this.material=i,this.name=`MToonOutline_${i.name}_${A.rendererId++}`,this.scene._addComponent(this),this._engine=this.scene.getEngine(),this._passIdForDrawWrapper=[];for(let e=0;e<1;++e)this._passIdForDrawWrapper[e]=this._engine.createRenderPassId(`Outline Renderer (${e})`)}register(){this.scene._afterRenderingMeshStage.registerStep(_.SceneComponentConstants.STEP_AFTERRENDERINGMESH_OUTLINE,this,this._afterRenderingMesh)}rebuild(){}dispose(){for(let e=0;e<this._passIdForDrawWrapper.length;++e)this._engine.releaseRenderPassId(this._passIdForDrawWrapper[e])}render(e,i,n){n=null!=n?n:this._passIdForDrawWrapper[0];const t=this.scene,o=e.effect;if(!o||!o.isReady()||!this.scene.activeCamera)return;const a=e._getDrawWrapper(n,!0);if(!a)return;if(a.setEffect(o),!a.effect||!a.effect.isReady())return;const r=e.getMesh(),s=r._internalAbstractMeshDataInfo._actAsRegularMesh?r:null,l=e.getRenderingMesh(),d=s||l;t.activeCamera&&(this.material.applyOutlineCullMode(),this.material.enableOutlineRender(),this._engine.enableEffect(a),this.isHardwareInstancedRendering(e,i)||l._bind(e,o,this.material.fillMode),this.material._preBind(o),l._processRendering(d,e,o,this.material.fillMode,i,this.isHardwareInstancedRendering(e,i),((i,n,t)=>{t&&t.bindForSubMesh(n,d,e)}),this.material),this.material.restoreOutlineCullMode(),this.material.disaableOutlineRender())}_afterRenderingMesh(e,i,n){if(!this.willRender(i))return;const t=this._engine.cullBackFaces;this._engine.cullBackFaces=!1,this.render(i,n,this._passIdForDrawWrapper[0]),this._engine.cullBackFaces=t}isHardwareInstancedRendering(e,i){return!!this._engine.getCaps().instancedArrays&&null!==i.visibleInstances[e._id]&&void 0!==i.visibleInstances[e._id]&&e.getRenderingMesh().hasThinInstances}willRender(e){const i=e.getMaterial();return!(!i||"MToonMaterial"!==i.getClassName()||i.getOutlineRendererName()!==this.name)}}A.rendererId=0;var I=v(713);class E extends I.MaterialDefines{constructor(e){super(e),this.CUSTOMUSERLIGHTING=!0,this.MTOON_OUTLINE_WIDTH_WORLD=!1,this.MTOON_OUTLINE_WIDTH_SCREEN=!1,this.MTOON_OUTLINE_COLOR_FIXED=!1,this.MTOON_OUTLINE_COLOR_MIXED=!1,this.MTOON_DEBUG_NORMAL=!1,this.MTOON_DEBUG_LITSHADERRATE=!1,this.SHADE=!1,this.SHADEDIRECTUV=0,this.RECEIVE_SHADOW=!1,this.RECEIVE_SHADOWDIRECTUV=0,this.SHADING_GRADE=!1,this.SHADING_GRADEDIRECTUV=0,this.RIM=!1,this.RIMDIRECTUV=0,this.MATCAP=!1,this.MATCAPDIRECTUV=0,this.OUTLINE_WIDTH=!1,this.OUTLINE_WIDTHDIRECTUV=0,this.UV_ANIMATION_MASK=!1,this.UV_ANIMATION_MASKDIRECTUV=0,this.MAINUV1=!1,this.MAINUV2=!1,this.MAINUV3=!1,this.MAINUV4=!1,this.MAINUV5=!1,this.MAINUV6=!1,this.DIFFUSE=!1,this.DIFFUSEDIRECTUV=0,this.BAKED_VERTEX_ANIMATION_TEXTURE=!1,this.EMISSIVE=!1,this.EMISSIVEDIRECTUV=0,this.BUMP=!1,this.BUMPDIRECTUV=0,this.PARALLAX=!1,this.PARALLAXOCCLUSION=!1,this.CLIPPLANE=!1,this.CLIPPLANE2=!1,this.CLIPPLANE3=!1,this.CLIPPLANE4=!1,this.CLIPPLANE5=!1,this.CLIPPLANE6=!1,this.ALPHATEST=!1,this.DEPTHPREPASS=!1,this.ALPHAFROMDIFFUSE=!1,this.POINTSIZE=!1,this.FOG=!1,this.NORMAL=!1,this.UV1=!1,this.UV2=!1,this.UV3=!1,this.UV4=!1,this.UV5=!1,this.UV6=!1,this.VERTEXCOLOR=!1,this.VERTEXALPHA=!1,this.NUM_BONE_INFLUENCERS=0,this.BonesPerMesh=0,this.BONETEXTURE=!1,this.BONES_VELOCITY_ENABLED=!1,this.INSTANCES=!1,this.THIN_INSTANCES=!1,this.OBJECTSPACE_NORMALMAP=!1,this.LOGARITHMICDEPTH=!1,this.TWOSIDEDLIGHTING=!1,this.SHADOWFLOAT=!1,this.MORPHTARGETS=!1,this.MORPHTARGETS_NORMAL=!1,this.MORPHTARGETS_TANGENT=!1,this.MORPHTARGETS_UV=!1,this.NUM_MORPH_INFLUENCERS=0,this.MORPHTARGETS_TEXTURE=!1,this.NONUNIFORMSCALING=!1,this.PREMULTIPLYALPHA=!1,this.ALPHATEST_AFTERALLALPHACOMPUTATIONS=!1,this.ALPHABLEND=!0,this.PREPASS=!1,this.PREPASS_IRRADIANCE=!1,this.PREPASS_IRRADIANCE_INDEX=-1,this.PREPASS_ALBEDO_SQRT=!1,this.PREPASS_ALBEDO_SQRT_INDEX=-1,this.PREPASS_DEPTH=!1,this.PREPASS_DEPTH_INDEX=-1,this.PREPASS_NORMAL=!1,this.PREPASS_NORMAL_INDEX=-1,this.PREPASS_POSITION=!1,this.PREPASS_POSITION_INDEX=-1,this.PREPASS_VELOCITY=!1,this.PREPASS_VELOCITY_INDEX=-1,this.PREPASS_REFLECTIVITY=!1,this.PREPASS_REFLECTIVITY_INDEX=-1,this.SCENE_MRT_COUNT=0,this.IMAGEPROCESSING=!1,this.VIGNETTE=!1,this.VIGNETTEBLENDMODEMULTIPLY=!1,this.VIGNETTEBLENDMODEOPAQUE=!1,this.TONEMAPPING=!1,this.TONEMAPPING_ACES=!1,this.CONTRAST=!1,this.COLORCURVES=!1,this.COLORGRADING=!1,this.COLORGRADING3D=!1,this.SAMPLER3DGREENDEPTH=!1,this.SAMPLER3DBGRMAP=!1,this.IMAGEPROCESSINGPOSTPROCESS=!1,this.SKIPFINALCOLORCLAMP=!1,this.MULTIVIEW=!1,this.ORDER_INDEPENDENT_TRANSPARENCY=!1,this.ORDER_INDEPENDENT_TRANSPARENCY_16BITS=!1,this.IS_REFLECTION_LINEAR=!1,this.IS_REFRACTION_LINEAR=!1,this.EXPOSURE=!1,this.FLIP_U=!1,this.FLIP_V=!1,this.rebuild()}setReflectionMode(e){throw new Error("This material cannot use `setReflectionMode`")}}const S={effect:null,subMesh:null};var T,N,D,L;!function(e){e[e.None=0]="None",e[e.Normal=1]="Normal",e[e.LitShadeRate=2]="LitShadeRate"}(T||(T={})),function(e){e[e.FixedColor=0]="FixedColor",e[e.MixedLighting=1]="MixedLighting"}(N||(N={})),function(e){e[e.None=0]="None",e[e.WorldCorrdinates=1]="WorldCorrdinates",e[e.ScreenCoordinates=2]="ScreenCoordinates"}(D||(D={})),function(e){e[e.Off=0]="Off",e[e.Front=1]="Front",e[e.Back=2]="Back"}(L||(L={}));class x extends d.PushMaterial{constructor(e,i){super(e,i),this._diffuseTexture=null,this.diffuseTexture=null,this._emissiveTexture=null,this.emissiveTexture=null,this._bumpTexture=null,this.bumpTexture=null,this._shadeTexture=null,this.shadeTexture=null,this._receiveShadowTexture=null,this.receiveShadowTexture=null,this._shadingGradeTexture=null,this.shadingGradeTexture=null,this._rimTexture=null,this.rimTexture=null,this._matCapTexture=null,this.matCapTexture=null,this._outlineWidthTexture=null,this.outlineWidthTexture=null,this._uvAnimationMaskTexture=null,this.uvAnimationMaskTexture=null,this.diffuseColor=new a.Color3(1,1,1),this.ambientColor=new a.Color3(0,0,0),this.emissiveColor=new a.Color3(0,0,0),this.shadeColor=new a.Color3(.97,.81,.86),this.rimColor=new a.Color3(0,0,0),this.outlineColor=new a.Color3(0,0,0),this.useEmissiveAsIllumination=!1,this.linkEmissiveWithDiffuse=!1,this.useReflectionOverAlpha=!1,this._disableLighting=!1,this.useObjectSpaceNormalMap=!1,this.useParallax=!1,this.useParallaxOcclusion=!1,this.specularSupported=!1,this.useLightmapAsShadowmap=!1,this.useVertexColor=!1,this.useBones=!0,this.useMorphTargets=!0,this.useVertexAlpha=!1,this.useBakedVertexAnimation=!1,this.alphaCutOff=.4,this._useAlphaFromDiffuseTexture=!0,this._maxSimultaneousLights=4,this._invertNormalMapX=!0,this._invertNormalMapY=!0,this._twoSidedLighting=!1,this._renderTargets=new n.SmartArray(16),this._worldViewProjectionMatrix=o.Matrix.Zero(),this._globalAmbientColor=new a.Color3(0,0,0),this._cacheHasRenderTargetTextures=!1,this._bumpScale=1,this._receiveShadowRate=1,this._shadingGradeRate=1,this._shadeShift=0,this._shadeToony=.9,this._lightColorAttenuation=0,this._indirectLightIntensity=.1,this._rimLightingMix=0,this._rimFresnelPower=1,this._rimLift=0,this._outlineWidth=.5,this._outlineScaledMaxDistance=1,this._outlineLightingMix=1,this._uvAnimationScrollX=0,this._uvAnimationScrollY=0,this._uvAnimationRotation=0,this._alphaTest=!1,this._alphaBlend=!1,this._debugMode=T.None,this.debugMode=T.None,this._outlineWidthMode=D.None,this.isOutline=0,this.outlineColorMode=N.MixedLighting,this._cullMode=L.Back,this._outlineCullMode=L.Front,this.outlineCullMode=L.Front,this.storedCullMode=L.Back,this.flipU=!1,this.flipV=!1,this.detailMap=new c.DetailMapConfiguration(this),this._attachImageProcessingConfiguration(null),this.getRenderTargetTextures=()=>(this._renderTargets.reset(),this._eventInfo.renderTargets=this._renderTargets,this._callbackPluginEventFillRenderTargetTextures(this._eventInfo),this._renderTargets),m.Effect.IncludesShadersStore.mtoonUboDeclaration||(m.Effect.IncludesShadersStore.mtoonUboDeclaration="// it will be replaced to UboDeclaration(WebGL2) or VertexDeclaration(WebGL1).\n\nlayout(std140, column_major) uniform;\n\nuniform Material\n{\n // Color & Texture\n vec4 vDiffuseColor;\n vec2 vDiffuseInfos;\n mat4 diffuseMatrix;\n vec4 vEmissiveColor;\n vec2 vEmissiveInfos;\n mat4 emissiveMatrix;\n vec3 vBumpInfos;\n mat4 bumpMatrix;\n vec3 vShadeColor;\n vec2 vShadeInfos;\n mat4 shadeMatrix;\n vec2 vReceiveShadowInfos;\n mat4 receiveShadowMatrix;\n vec2 vShadingGradeInfos;\n mat4 shadingGradeMatrix;\n vec3 vRimColor;\n vec2 vRimInfos;\n mat4 rimMatrix;\n vec2 vMatCapInfos;\n mat4 matCapMatrix;\n vec4 vOutlineColor;\n vec2 vOutlineWidthInfos;\n mat4 outlineWidthMatrix;\n vec2 vUvAnimationMaskInfos;\n mat4 uvAnimationMaskMatrix;\n\n // babylon specific\n vec2 vTangentSpaceParams;\n float pointSize;\n\n // MToon params\n float shadingGradeRate;\n float receiveShadowRate;\n float shadeShift;\n float shadeToony;\n float lightColorAttenuation;\n float indirectLightIntensity;\n float rimLightingMix;\n float rimFresnelPower;\n float rimLift;\n float outlineWidth;\n float outlineScaledMaxDistance;\n float outlineLightingMix;\n float uvAnimationScrollX;\n float uvAnimationScrollY;\n float uvAnimationRotation;\n\n vec3 vEyeUp;\n float alphaCutOff;\n vec3 vAmbientColor;\n float aspect;\n float isOutline;\n vec4 time;\n};\n\n// babylon specific\n#include<sceneUboDeclaration>\n#include<meshUboDeclaration>\n",m.Effect.IncludesShadersStore.mtoonVertexDeclaration="// Uniforms\nuniform mat4 viewProjection;\nuniform mat4 view;\nuniform mat4 projection;\nuniform float outlineWidth;\nuniform float outlineScaledMaxDistance;\nuniform float outlineLightingMix;\nuniform float isOutline;\nuniform float aspect;\n\n#ifdef DIFFUSE\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;\nuniform mat4 emissiveMatrix;\n#endif\n\n#ifdef BUMP\nuniform vec3 vBumpInfos;\nuniform mat4 bumpMatrix;\n#endif\n\n#ifdef SHADE\nuniform vec2 vShadeInfos;\nuniform mat4 shadeMatrix;\n#endif\n\n#ifdef RECEIVE_SHADOW\nuniform vec2 vReceiveShadowInfos;\nuniform mat4 receiveShadowMatrix;\n#endif\n\n#ifdef SHADING_GRADE\nuniform vec2 vShadingGradeInfos;\nuniform mat4 shadingGradeMatrix;\n#endif\n\n#ifdef RIM\nuniform vec2 vRimInfos;\nuniform mat4 rimMatrix;\n#endif\n\n#ifdef MATCAP\nuniform vec2 vMatCapInfos;\nuniform mat4 matCapMatrix;\n#endif\n\n#ifdef OUTLINE_WIDTH\nuniform vec2 vOutlineWidthInfos;\nuniform mat4 outlineWidthMatrix;\n#endif\n\n#ifdef UV_ANIMATION_MASK\nuniform vec2 vUvAnimationMaskInfos;\nuniform mat4 uvAnimationMaskMatrix;\n#endif\n\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n",m.Effect.IncludesShadersStore.mtoonFragmentDeclaration="uniform vec4 vEyePosition;\n\n// Colors\nuniform vec4 vDiffuseColor;\nuniform vec3 vEmissiveColor;\nuniform vec3 vShadeColor;\nuniform vec3 vRimColor;\nuniform vec4 vOutlineColor;\nuniform vec3 vAmbientColor;\n\nuniform vec3 vEyeUp;\nuniform float aspect;\nuniform float alphaCutOff;\nuniform float visibility;\nuniform float isOutline;\nuniform vec4 time;\n\n// Samplers\n#ifdef DIFFUSE\nuniform vec2 vDiffuseInfos;\n#endif\n\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;\n#endif\n\n#ifdef BUMP\nuniform vec3 vBumpInfos;\nuniform vec2 vTangentSpaceParams;\n#endif\n\n#ifdef SHADE\nuniform vec2 vShadeInfos;\n#endif\n\n#ifdef RECEIVE_SHADOW\nuniform vec2 vReceiveShadowInfos;\n#endif\n\n#ifdef SHADING_GRADE\nuniform vec2 vShadingGradeInfos;\n#endif\n\n#ifdef RIM\nuniform vec2 vRimInfos;\n#endif\n\n#ifdef MATCAP\nuniform vec2 vMatCapInfos;\n#endif\n\n#ifdef OUTLINE_WIDTH\nuniform vec2 vOutlineWidthInfos;\n#endif\n\n#ifdef UV_ANIMATION_MASK\nuniform vec2 vUvAnimationMaskInfos;\n#endif\n\n// MToon params\nuniform float shadingGradeRate;\nuniform float receiveShadowRate;\nuniform float shadeShift;\nuniform float shadeToony;\nuniform float lightColorAttenuation;\nuniform float indirectLightIntensity;\nuniform float rimLightingMix;\nuniform float rimFresnelPower;\nuniform float rimLift;\nuniform float outlineWidth;\nuniform float outlineScaledMaxDistance;\nuniform float outlineLightingMix;\nuniform float uvAnimationScrollX;\nuniform float uvAnimationScrollY;\nuniform float uvAnimationRotation;\n",m.Effect.IncludesShadersStore.mtoonFragmentFunctions="\n/**\n* Compute Directional or Point light direction\n*/\nvec3 computeLightDirection(vec4 lightData) {\n return normalize(mix(lightData.xyz - vPositionW, -lightData.xyz, lightData.w));\n}\n\n/**\n* Compute Spot Light direction\n*/\nvec3 computeSpotLightDirection(vec4 lightData) {\n return normalize(lightData.xyz - vPositionW);\n}\n\n/**\n* Compute Hemispheric light direction\n*/\nvec3 computeHemisphericLightDirection(vec4 lightData, vec3 vNormal) {\n return normalize(lightData.xyz);\n}\n\n/**\n* Compute MToon diffuse lighting\n*/\nvec4 computeMToonDiffuseLighting(vec3 worldView, vec3 worldNormal, vec2 mainUv, vec3 lightDirection, vec4 lightDiffuse, float shadowAttenuation) {\n float _receiveShadow = receiveShadowRate;\n#ifdef RECEIVE_SHADOW\n _receiveShadow = _receiveShadow * texture2D(receiveShadowSampler, mainUv).r * vReceiveShadowInfos.y;\n#endif\n\n float _shadingGrade = 0.0;\n#ifdef SHADING_GRADE\n _shadingGrade = 1.0 - texture2D(shadingGradeSampler, mainUv).r * vShadingGradeInfos.y;\n#endif\n _shadingGrade = 1.0 - shadingGradeRate * _shadingGrade;\n\n // Lighting\n vec3 _lightColor = lightDiffuse.rgb * step(0.5, length(lightDirection)); // length(lightDir) is zero if directional light is disabled.\n float _dotNL = dot(lightDirection, worldNormal);\n#ifdef MTOON_FORWARD_ADD\n float _lightAttenuation = 1.0;\n#else\n float _lightAttenuation = shadowAttenuation * mix(1.0, shadowAttenuation, _receiveShadow);\n#endif\n\n // lighting intensity\n float _lightIntensity = _dotNL;\n _lightIntensity = _lightIntensity * 0.5 + 0.5; // from [-1, +1] to [0, 1]\n _lightIntensity = _lightIntensity * _lightAttenuation; // receive shadow\n _lightIntensity = _lightIntensity * _shadingGrade; // darker\n _lightIntensity = _lightIntensity * 2.0 - 1.0; // from [0, 1] to [-1, +1]\n // tooned. mapping from [minIntensityThreshold, maxIntensityThreshold] to [0, 1]\n float _maxIntensityThreshold = mix(1.0, shadeShift, shadeToony);\n float _minIntensityThreshold = shadeShift;\n _lightIntensity = clamp((_lightIntensity - _minIntensityThreshold) / max(EPS_COL, (_maxIntensityThreshold - _minIntensityThreshold)), 0.0, 1.0);\n\n // Albedo color\n vec3 _shade = vShadeColor;\n#ifdef SHADE\n _shade = _shade * texture2D(shadeSampler, mainUv).rgb * vShadeInfos.y;\n#endif\n\n vec4 _lit = vDiffuseColor;\n#ifdef DIFFUSE\n _lit = _lit * texture2D(diffuseSampler, mainUv) * vDiffuseInfos.y;\n#endif\n vec3 _col = mix(_shade.rgb, _lit.rgb, _lightIntensity);\n\n // Direct Light\n vec3 _lighting = _lightColor;\n _lighting = mix(_lighting, vec3(max(EPS_COL, max(_lighting.x, max(_lighting.y, _lighting.z)))), lightColorAttenuation); // color atten\n#ifdef MTOON_FORWARD_ADD\n _lighting *= 0.5; // darken if additional light\n _lighting *= min(0, dotNL) + 1.0; // darken dotNL < 0 area by using half lambert\n _lighting *= shadowAttenuation; // darken if receiving shadow\n#else\n // base light does not darken.\n#endif\n _col *= _lighting;\n\n // Indirect Light\n#ifdef MTOON_FORWARD_ADD\n#else\n vec3 _toonedGI = vAmbientColor.rgb; // TODO: GI\n vec3 _indirectLighting = mix(_toonedGI, vAmbientColor.rgb, indirectLightIntensity);\n _indirectLighting = mix(_indirectLighting, vec3(max(EPS_COL, max(_indirectLighting.x, max(_indirectLighting.y, _indirectLighting.z)))), lightColorAttenuation); // color atten\n _col += _indirectLighting * _lit.rgb;\n\n _col = min(_col.rgb, _lit.rgb); // comment out if you want to PBR absolutely.\n#endif\n\n // parametric rim lighting\n#ifdef MTOON_FORWARD_ADD\n vec3 _staticRimLighting = vec3(0.0);\n vec3 _mixedRimLighting = _lighting;\n#else\n vec3 _staticRimLighting = vec3(1.0);\n vec3 _mixedRimLighting = _lighting + _indirectLighting;\n#endif\n vec3 _rimLighting = mix(_staticRimLighting, _mixedRimLighting, rimLightingMix);\n vec3 _rimColor = vRimColor.rgb;\n#ifdef RIM\n _rimColor = _rimColor * texture2D(rimSampler, vRimUV + mainUv).rgb * vRimInfos.y;\n#endif\n vec3 _rim = pow(clamp(1.0 - dot(worldNormal, worldView) + rimLift, 0.0, 1.0), rimFresnelPower) * _rimColor.rgb;\n _col += mix(_rim * _rimLighting, vec3(0.0), isOutline);\n\n // additive matcap\n#ifdef MTOON_FORWARD_ADD\n#else\n#ifdef MATCAP\n vec3 _worldViewUp = normalize(vEyeUp - worldView * dot(worldView, vEyeUp));\n vec3 _worldViewRight = normalize(cross(worldView, _worldViewUp));\n vec2 _matCapUv = vec2(dot(_worldViewRight, worldNormal), dot(_worldViewUp, worldNormal)) * 0.5 + 0.5;\n // uv.y is reversed\n _matCapUv.y = (1.0 - _matCapUv.y);\n vec3 _matCapLighting = texture2D(matCapSampler, _matCapUv).rgb * vMatCapInfos.y;\n _col += mix(_matCapLighting, vec3(0.0), isOutline);\n#endif\n#endif\n\n // Emission\n#ifdef MTOON_FORWARD_ADD\n#else\n vec3 _emission = vEmissiveColor.rgb;\n#ifdef EMISSIVE\n _emission *= texture2D(emissiveSampler, mainUv).rgb * vEmissiveInfos.y;\n#endif\n _col += mix(_emission, vec3(0.0), isOutline);\n#endif\n\n float _alpha = 1.0;\n\n#if defined(ALPHABLEND) || defined(ALPHATEST)\n _alpha = mix(_lit.a, _lit.a * vOutlineColor.a, isOutline);\n#endif\n\n // outline\n#ifdef MTOON_OUTLINE_COLOR_FIXED\n _col = mix(_col, vOutlineColor.rgb, isOutline);\n#elif defined(MTOON_OUTLINE_COLOR_MIXED)\n _col = mix(_col, vOutlineColor.rgb * mix(vec3(1.0), _col, outlineLightingMix), isOutline);\n#else\n#endif\n\n // debug\n#ifdef MTOON_DEBUG_NORMAL\n #ifdef MTOON_FORWARD_ADD\n return vec4(0.0);\n #else\n return vec4(worldNormal * 0.5 + 0.5, _lit.a);\n #endif\n#elif defined(MTOON_DEBUG_LITSHADERATE)\n #ifdef MTOON_FORWARD_ADD\n return vec4(0.0);\n #else\n return vec4(_lightIntensity, _lit.a);\n #endif\n#endif\n\n return vec4(_col, _alpha);\n}\n",m.Effect.IncludesShadersStore.mtoonLightFragment="#ifdef LIGHT{X}\n #if defined(SHADOWONLY) || defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED{X}) && defined(LIGHTMAPNOSPECULAR{X})\n //No light calculation\n #else\n #ifdef PBR\n // Compute Pre Lighting infos\n #ifdef SPOTLIGHT{X}\n preInfo = computePointAndSpotPreLightingInfo(light{X}.vLightData, viewDirectionW, normalW);\n #elif defined(POINTLIGHT{X})\n preInfo = computePointAndSpotPreLightingInfo(light{X}.vLightData, viewDirectionW, normalW);\n #elif defined(HEMILIGHT{X})\n preInfo = computeHemisphericPreLightingInfo(light{X}.vLightData, viewDirectionW, normalW);\n #elif defined(DIRLIGHT{X})\n preInfo = computeDirectionalPreLightingInfo(light{X}.vLightData, viewDirectionW, normalW);\n #endif\n\n preInfo.NdotV = NdotV;\n\n // Compute Attenuation infos\n #ifdef SPOTLIGHT{X}\n #ifdef LIGHT_FALLOFF_GLTF{X}\n preInfo.attenuation = computeDistanceLightFalloff_GLTF(preInfo.lightDistanceSquared, light{X}.vLightFalloff.y);\n preInfo.attenuation *= computeDirectionalLightFalloff_GLTF(light{X}.vLightDirection.xyz, preInfo.L, light{X}.vLightFalloff.z, light{X}.vLightFalloff.w);\n #elif defined(LIGHT_FALLOFF_PHYSICAL{X})\n preInfo.attenuation = computeDistanceLightFalloff_Physical(preInfo.lightDistanceSquared);\n preInfo.attenuation *= computeDirectionalLightFalloff_Physical(light{X}.vLightDirection.xyz, preInfo.L, light{X}.vLightDirection.w);\n #elif defined(LIGHT_FALLOFF_STANDARD{X})\n preInfo.attenuation = computeDistanceLightFalloff_Standard(preInfo.lightOffset, light{X}.vLightFalloff.x);\n preInfo.attenuation *= computeDirectionalLightFalloff_Standard(light{X}.vLightDirection.xyz, preInfo.L, light{X}.vLightDirection.w, light{X}.vLightData.w);\n #else\n preInfo.attenuation = computeDistanceLightFalloff(preInfo.lightOffset, preInfo.lightDistanceSquared, light{X}.vLightFalloff.x, light{X}.vLightFalloff.y);\n preInfo.attenuation *= computeDirectionalLightFalloff(light{X}.vLightDirection.xyz, preInfo.L, light{X}.vLightDirection.w, light{X}.vLightData.w, light{X}.vLightFalloff.z, light{X}.vLightFalloff.w);\n #endif\n #elif defined(POINTLIGHT{X})\n #ifdef LIGHT_FALLOFF_GLTF{X}\n preInfo.attenuation = computeDistanceLightFalloff_GLTF(preInfo.lightDistanceSquared, light{X}.vLightFalloff.y);\n #elif defined(LIGHT_FALLOFF_PHYSICAL{X})\n preInfo.attenuation = computeDistanceLightFalloff_Physical(preInfo.lightDistanceSquared);\n #elif defined(LIGHT_FALLOFF_STANDARD{X})\n preInfo.attenuation = computeDistanceLightFalloff_Standard(preInfo.lightOffset, light{X}.vLightFalloff.x);\n #else\n preInfo.attenuation = computeDistanceLightFalloff(preInfo.lightOffset, preInfo.lightDistanceSquared, light{X}.vLightFalloff.x, light{X}.vLightFalloff.y);\n #endif\n #else\n preInfo.attenuation = 1.0;\n #endif\n\n // Simulates Light radius for diffuse and spec term\n // clear coat is using a dedicated roughness\n #ifdef HEMILIGHT{X}\n preInfo.roughness = roughness;\n #else\n preInfo.roughness = adjustRoughnessFromLightProperties(roughness, light{X}.vLightSpecular.a, preInfo.lightDistance);\n #endif\n\n // Diffuse contribution\n #ifdef HEMILIGHT{X}\n info.diffuse = computeHemisphericDiffuseLighting(preInfo, light{X}.vLightDiffuse.rgb, light{X}.vLightGround);\n #elif defined(SS_TRANSLUCENCY)\n info.diffuse = computeDiffuseAndTransmittedLighting(preInfo, light{X}.vLightDiffuse.rgb, subSurfaceOut.transmittance);\n #else\n info.diffuse = computeDiffuseLighting(preInfo, light{X}.vLightDiffuse.rgb);\n #endif\n\n // Specular contribution\n #ifdef SPECULARTERM\n #ifdef ANISOTROPIC\n info.specular = computeAnisotropicSpecularLighting(preInfo, viewDirectionW, normalW, anisotropicOut.anisotropicTangent, anisotropicOut.anisotropicBitangent, anisotropicOut.anisotropy, clearcoatOut.specularEnvironmentR0, specularEnvironmentR90, AARoughnessFactors.x, light{X}.vLightDiffuse.rgb);\n #else\n info.specular = computeSpecularLighting(preInfo, normalW, clearcoatOut.specularEnvironmentR0, specularEnvironmentR90, AARoughnessFactors.x, light{X}.vLightDiffuse.rgb);\n #endif\n #endif\n\n // Sheen contribution\n #ifdef SHEEN\n #ifdef SHEEN_LINKWITHALBEDO\n // BE Carefull: Sheen intensity is replacing the roughness value.\n preInfo.roughness = sheenOut.sheenIntensity;\n #else\n #ifdef HEMILIGHT{X}\n preInfo.roughness = sheenOut.sheenRoughness;\n #else\n preInfo.roughness = adjustRoughnessFromLightProperties(sheenOut.sheenRoughness, light{X}.vLightSpecular.a, preInfo.lightDistance);\n #endif\n #endif\n info.sheen = computeSheenLighting(preInfo, normalW, sheenOut.sheenColor, specularEnvironmentR90, AARoughnessFactors.x, light{X}.vLightDiffuse.rgb);\n #endif\n\n // Clear Coat contribution\n #ifdef CLEARCOAT\n // Simulates Light radius\n #ifdef HEMILIGHT{X}\n preInfo.roughness = clearcoatOut.clearCoatRoughness;\n #else\n preInfo.roughness = adjustRoughnessFromLightProperties(clearcoatOut.clearCoatRoughness, light{X}.vLightSpecular.a, preInfo.lightDistance);\n #endif\n\n info.clearCoat = computeClearCoatLighting(preInfo, clearcoatOut.clearCoatNormalW, clearcoatOut.clearCoatAARoughnessFactors.x, clearcoatOut.clearCoatIntensity, light{X}.vLightDiffuse.rgb);\n\n #ifdef CLEARCOAT_TINT\n // Absorption\n absorption = computeClearCoatLightingAbsorption(clearcoatOut.clearCoatNdotVRefract, preInfo.L, clearcoatOut.clearCoatNormalW, clearcoatOut.clearCoatColor, clearcoatOut.clearCoatThickness, clearcoatOut.clearCoatIntensity);\n info.diffuse *= absorption;\n #ifdef SPECULARTERM\n info.specular *= absorption;\n #endif\n #endif\n\n // Apply energy conservation on diffuse and specular term.\n info.diffuse *= info.clearCoat.w;\n #ifdef SPECULARTERM\n info.specular *= info.clearCoat.w;\n #endif\n #ifdef SHEEN\n info.sheen *= info.clearCoat.w;\n #endif\n #endif\n #else\n #ifdef SPOTLIGHT{X}\n info = computeSpotLighting(viewDirectionW, normalW, light{X}.vLightData, light{X}.vLightDirection, light{X}.vLightDiffuse.rgb, light{X}.vLightSpecular.rgb, light{X}.vLightDiffuse.a, glossiness);\n #elif defined(HEMILIGHT{X})\n info = computeHemisphericLighting(viewDirectionW, normalW, light{X}.vLightData, light{X}.vLightDiffuse.rgb, light{X}.vLightSpecular.rgb, light{X}.vLightGround, glossiness);\n #elif defined(POINTLIGHT{X}) || defined(DIRLIGHT{X})\n info = computeLighting(viewDirectionW, normalW, light{X}.vLightData, light{X}.vLightDiffuse.rgb, light{X}.vLightSpecular.rgb, light{X}.vLightDiffuse.a, glossiness);\n #endif\n #endif\n\n #ifdef PROJECTEDLIGHTTEXTURE{X}\n info.diffuse *= computeProjectionTextureDiffuseLighting(projectionLightSampler{X}, textureProjectionMatrix{X});\n #endif\n #endif\n\n #ifdef SHADOW{X}\n #ifdef SHADOWCSM{X}\n for (int i = 0; i < SHADOWCSMNUM_CASCADES{X}; i++)\n {\n #ifdef SHADOWCSM_RIGHTHANDED{X}\n diff{X} = viewFrustumZ{X}[i] + vPositionFromCamera{X}.z;\n #else\n diff{X} = viewFrustumZ{X}[i] - vPositionFromCamera{X}.z;\n #endif\n if (diff{X} >= 0.) {\n index{X} = i;\n break;\n }\n }\n\n #ifdef SHADOWCSMUSESHADOWMAXZ{X}\n if (index{X} >= 0)\n #endif\n {\n #if defined(SHADOWPCF{X})\n #if defined(SHADOWLOWQUALITY{X})\n shadow = computeShadowWithCSMPCF1(float(index{X}), vPositionFromLight{X}[index{X}], vDepthMetric{X}[index{X}], shadowSampler{X}, light{X}.shadowsInfo.x, light{X}.shadowsInfo.w);\n #elif defined(SHADOWMEDIUMQUALITY{X})\n shadow = computeShadowWithCSMPCF3(float(index{X}), vPositionFromLight{X}[index{X}], vDepthMetric{X}[index{X}], shadowSampler{X}, light{X}.shadowsInfo.yz, light{X}.shadowsInfo.x, light{X}.shadowsInfo.w);\n #else\n shadow = computeShadowWithCSMPCF5(float(index{X}), vPositionFromLight{X}[index{X}], vDepthMetric{X}[index{X}], shadowSampler{X}, light{X}.shadowsInfo.yz, light{X}.shadowsInfo.x, light{X}.shadowsInfo.w);\n #endif\n #elif defined(SHADOWPCSS{X})\n #if defined(SHADOWLOWQUALITY{X})\n shadow = computeShadowWithCSMPCSS16(float(index{X}), vPositionFromLight{X}[index{X}], vDepthMetric{X}[index{X}], depthSampler{X}, shadowSampler{X}, light{X}.shadowsInfo.y, light{X}.shadowsInfo.z, light{X}.shadowsInfo.x, light{X}.shadowsInfo.w, lightSizeUVCorrection{X}[index{X}], depthCorrection{X}[index{X}], penumbraDarkness{X});\n #elif defined(SHADOWMEDIUMQUALITY{X})\n shadow = computeShadowWithCSMPCSS32(float(index{X}), vPositionFromLight{X}[index{X}], vDepthMetric{X}[index{X}], depthSampler{X}, shadowSampler{X}, light{X}.shadowsInfo.y, light{X}.shadowsInfo.z, light{X}.shadowsInfo.x, light{X}.shadowsInfo.w, lightSizeUVCorrection{X}[index{X}], depthCorrection{X}[index{X}], penumbraDarkness{X});\n #else\n shadow = computeShadowWithCSMPCSS64(float(index{X}), vPositionFromLight{X}[index{X}], vDepthMetric{X}[index{X}], depthSampler{X}, shadowSampler{X}, light{X}.shadowsInfo.y, light{X}.shadowsInfo.z, light{X}.shadowsInfo.x, light{X}.shadowsInfo.w, lightSizeUVCorrection{X}[index{X}], depthCorrection{X}[index{X}], penumbraDarkness{X});\n #endif\n #else\n shadow = computeShadowCSM(float(index{X}), vPositionFromLight{X}[index{X}], vDepthMetric{X}[index{X}], shadowSampler{X}, light{X}.shadowsInfo.x, light{X}.shadowsInfo.w);\n #endif\n\n #ifdef SHADOWCSMDEBUG{X}\n shadowDebug{X} = vec3(shadow) * vCascadeColorsMultiplier{X}[index{X}];\n #endif\n\n #ifndef SHADOWCSMNOBLEND{X}\n float frustumLength = frustumLengths{X}[index{X}];\n float diffRatio = clamp(diff{X} / frustumLength, 0., 1.) * cascadeBlendFactor{X};\n if (index{X} < (SHADOWCSMNUM_CASCADES{X} - 1) && diffRatio < 1.)\n {\n index{X} += 1;\n float nextShadow = 0.;\n #if defined(SHADOWPCF{X})\n #if defined(SHADOWLOWQUALITY{X})\n nextShadow = computeShadowWithCSMPCF1(float(index{X}), vPositionFromLight{X}[index{X}], vDepthMetric{X}[index{X}], shadowSampler{X}, light{X}.shadowsInfo.x, light{X}.shadowsInfo.w);\n #elif defined(SHADOWMEDIUMQUALITY{X})\n nextShadow = computeShadowWithCSMPCF3(float(index{X}), vPositionFromLight{X}[index{X}], vDepthMetric{X}[index{X}], shadowSampler{X}, light{X}.shadowsInfo.yz, light{X}.shadowsInfo.x, light{X}.shadowsInfo.w);\n #else\n nextShadow = computeShadowWithCSMPCF5(float(index{X}), vPositionFromLight{X}[index{X}], vDepthMetric{X}[index{X}], shadowSampler{X}, light{X}.shadowsInfo.yz, light{X}.shadowsInfo.x, light{X}.shadowsInfo.w);\n #endif\n #elif defined(SHADOWPCSS{X})\n #if defined(SHADOWLOWQUALITY{X})\n nextShadow = computeShadowWithCSMPCSS16(float(index{X}), vPositionFromLight{X}[index{X}], vDepthMetric{X}[index{X}], depthSampler{X}, shadowSampler{X}, light{X}.shadowsInfo.y, light{X}.shadowsInfo.z, light{X}.shadowsInfo.x, light{X}.shadowsInfo.w, lightSizeUVCorrection{X}[index{X}], depthCorrection{X}[index{X}], penumbraDarkness{X});\n #elif defined(SHADOWMEDIUMQUALITY{X})\n nextShadow = computeShadowWithCSMPCSS32(float(index{X}), vPositionFromLight{X}[index{X}], vDepthMetric{X}[index{X}], depthSampler{X}, shadowSampler{X}, light{X}.shadowsInfo.y, light{X}.shadowsInfo.z, light{X}.shadowsInfo.x, light{X}.shadowsInfo.w, lightSizeUVCorrection{X}[index{X}], depthCorrection{X}[index{X}], penumbraDarkness{X});\n #else\n nextShadow = computeShadowWithCSMPCSS64(float(index{X}), vPositionFromLight{X}[index{X}], vDepthMetric{X}[index{X}], depthSampler{X}, shadowSampler{X}, light{X}.shadowsInfo.y, light{X}.shadowsInfo.z, light{X}.shadowsInfo.x, light{X}.shadowsInfo.w, lightSizeUVCorrection{X}[index{X}], depthCorrection{X}[index{X}], penumbraDarkness{X});\n #endif\n #else\n nextShadow = computeShadowCSM(float(index{X}), vPositionFromLight{X}[index{X}], vDepthMetric{X}[index{X}], shadowSampler{X}, light{X}.shadowsInfo.x, light{X}.shadowsInfo.w);\n #endif\n\n shadow = mix(nextShadow, shadow, diffRatio);\n #ifdef SHADOWCSMDEBUG{X}\n shadowDebug{X} = mix(vec3(nextShadow) * vCascadeColorsMultiplier{X}[index{X}], shadowDebug{X}, diffRatio);\n #endif\n }\n #endif\n }\n #elif defined(SHADOWCLOSEESM{X})\n #if defined(SHADOWCUBE{X})\n shadow = computeShadowWithCloseESMCube(light{X}.vLightData.xyz, shadowSampler{X}, light{X}.shadowsInfo.x, light{X}.shadowsInfo.z, light{X}.depthValues);\n #else\n shadow = computeShadowWithCloseESM(vPositionFromLight{X}, vDepthMetric{X}, shadowSampler{X}, light{X}.shadowsInfo.x, light{X}.shadowsInfo.z, light{X}.shadowsInfo.w);\n #endif\n #elif defined(SHADOWESM{X})\n #if defined(SHADOWCUBE{X})\n shadow = computeShadowWithESMCube(light{X}.vLightData.xyz, shadowSampler{X}, light{X}.shadowsInfo.x, light{X}.shadowsInfo.z, light{X}.depthValues);\n #else\n shadow = computeShadowWithESM(vPositionFromLight{X}, vDepthMetric{X}, shadowSampler{X}, light{X}.shadowsInfo.x, light{X}.shadowsInfo.z, light{X}.shadowsInfo.w);\n #endif\n #elif defined(SHADOWPOISSON{X})\n #if defined(SHADOWCUBE{X})\n shadow = computeShadowWithPoissonSamplingCube(light{X}.vLightData.xyz, shadowSampler{X}, light{X}.shadowsInfo.y, light{X}.shadowsInfo.x, light{X}.depthValues);\n #else\n shadow = computeShadowWithPoissonSampling(vPositionFromLight{X}, vDepthMetric{X}, shadowSampler{X}, light{X}.shadowsInfo.y, light{X}.shadowsInfo.x, light{X}.shadowsInfo.w);\n #endif\n #elif defined(SHADOWPCF{X})\n #if defined(SHADOWLOWQUALITY{X})\n shadow = computeShadowWithPCF1(vPositionFromLight{X}, vDepthMetric{X}, shadowSampler{X}, light{X}.shadowsInfo.x, light{X}.shadowsInfo.w);\n #elif defined(SHADOWMEDIUMQUALITY{X})\n shadow = computeShadowWithPCF3(vPositionFromLight{X}, vDepthMetric{X}, shadowSampler{X}, light{X}.shadowsInfo.yz, light{X}.shadowsInfo.x, light{X}.shadowsInfo.w);\n #else\n shadow = computeShadowWithPCF5(vPositionFromLight{X}, vDepthMetric{X}, shadowSampler{X}, light{X}.shadowsInfo.yz, light{X}.shadowsInfo.x, light{X}.shadowsInfo.w);\n #endif\n #elif defined(SHADOWPCSS{X})\n #if defined(SHADOWLOWQUALITY{X})\n shadow = computeShadowWithPCSS16(vPositionFromLight{X}, vDepthMetric{X}, depthSampler{X}, shadowSampler{X}, light{X}.shadowsInfo.y, light{X}.shadowsInfo.z, light{X}.shadowsInfo.x, light{X}.shadowsInfo.w);\n #elif defined(SHADOWMEDIUMQUALITY{X})\n shadow = computeShadowWithPCSS32(vPositionFromLight{X}, vDepthMetric{X}, depthSampler{X}, shadowSampler{X}, light{X}.shadowsInfo.y, light{X}.shadowsInfo.z, light{X}.shadowsInfo.x, light{X}.shadowsInfo.w);\n #else\n shadow = computeShadowWithPCSS64(vPositionFromLight{X}, vDepthMetric{X}, depthSampler{X}, shadowSampler{X}, light{X}.shadowsInfo.y, light{X}.shadowsInfo.z, light{X}.shadowsInfo.x, light{X}.shadowsInfo.w);\n #endif\n #else\n #if defined(SHADOWCUBE{X})\n shadow = computeShadowCube(light{X}.vLightData.xyz, shadowSampler{X}, light{X}.shadowsInfo.x, light{X}.depthValues);\n #else\n shadow = computeShadow(vPositionFromLight{X}, vDepthMetric{X}, shadowSampler{X}, light{X}.shadowsInfo.x, light{X}.shadowsInfo.w);\n #endif\n #endif\n\n #ifdef SHADOWONLY\n #ifndef SHADOWINUSE\n #define SHADOWINUSE\n #endif\n globalShadow += shadow;\n shadowLightCount += 1.0;\n #endif\n #else\n shadow = 1.;\n #endif\n\n #ifndef SHADOWONLY\n #ifdef CUSTOMUSERLIGHTING\n // Compute and reflect MToon lighting\n #ifdef SPOTLIGHT{X}\n lightDirection = computeSpotLightDirection(light{X}.vLightData);\n #elif defined(HEMILIGHT{X})\n lightDirection = computeHemisphericLightDirection(light{X}.vLightData, normalW.xyz);\n #elif defined(POINTLIGHT{X}) || defined(DIRLIGHT{X})\n lightDirection = computeLightDirection(light{X}.vLightData);\n #endif\n mtoonDiffuse = computeMToonDiffuseLighting(viewDirectionW.xyz, normalW.xyz, mainUv, lightDirection, light{X}.vLightDiffuse.rgba, shadow);\n diffuseBase += mtoonDiffuse.rgb;\n alpha = min(alpha, mtoonDiffuse.a);\n #if defined(ALPHATEST) && ALPHATEST\n alpha = (alpha - alphaCutOff) / max(fwidth(alpha), EPS_COL) + 0.5; // Alpha to Coverage\n if (alpha < alphaCutOff) {\n discard;\n }\n alpha = 1.0; // Discarded, otherwise it should be assumed to have full opacity\n #else\n if (alpha - 0.0001 < 0.000) { // Slightly improves rendering with layered transparency\n discard;\n }\n #endif\n #elif defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED{X})\n diffuseBase += lightmapColor.rgb * shadow;\n #ifdef SPECULARTERM\n #ifndef LIGHTMAPNOSPECULAR{X}\n specularBase += info.specular * shadow * lightmapColor.rgb;\n #endif\n #endif\n #ifdef CLEARCOAT\n #ifndef LIGHTMAPNOSPECULAR{X}\n clearCoatBase += info.clearCoat.rgb * shadow * lightmapColor.rgb;\n #endif\n #endif\n #ifdef SHEEN\n #ifndef LIGHTMAPNOSPECULAR{X}\n sheenBase += info.sheen.rgb * shadow;\n #endif\n #endif\n #else\n #ifdef SHADOWCSMDEBUG{X}\n diffuseBase += info.diffuse * shadowDebug{X};\n #else\n diffuseBase += info.diffuse * shadow;\n #endif\n #ifdef SPECULARTERM\n specularBase += info.specular * shadow;\n #endif\n #ifdef CLEARCOAT\n clearCoatBase += info.clearCoat.rgb * shadow;\n #endif\n #ifdef SHEEN\n sheenBase += info.sheen.rgb * shadow;\n #endif\n #endif\n #endif\n#endif\n",m.Effect.IncludesShadersStore.mtoonBumpFragment="// replace vBumpUV to mainUv\nvec2 uvOffset = vec2(0.0, 0.0);\n\n#if defined(BUMP) || defined(PARALLAX) || defined(DETAIL)\n #ifdef NORMALXYSCALE\n float normalScale = 1.0;\n #elif defined(BUMP)\n float normalScale = vBumpInfos.y;\n #else\n float normalScale = 1.0;\n #endif\n\n #if defined(TANGENT) && defined(NORMAL)\n mat3 TBN = vTBN;\n #elif defined(BUMP)\n // vec2 TBNUV = gl_FrontFacing ? vBumpUV : -vBumpUV;\n vec2 TBNUV = gl_FrontFacing ? mainUv : -mainUv;\n mat3 TBN = cotangent_frame(normalW * normalScale, vPositionW, TBNUV, vTangentSpaceParams);\n #else\n vec2 TBNUV = gl_FrontFacing ? vDetailUV : -vDetailUV;\n mat3 TBN = cotangent_frame(normalW * normalScale, vPositionW, TBNUV, vec2(1., 1.));\n #endif\n#elif defined(ANISOTROPIC)\n #if defined(TANGENT) && defined(NORMAL)\n mat3 TBN = vTBN;\n #else\n // flip the uv for the backface\n vec2 TBNUV = gl_FrontFacing ? vMainUV1 : -vMainUV1;\n mat3 TBN = cotangent_frame(normalW, vPositionW, TBNUV, vec2(1., 1.));\n #endif\n#endif\n\n#ifdef PARALLAX\n mat3 invTBN = transposeMat3(TBN);\n\n #ifdef PARALLAXOCCLUSION\n // uvOffset = parallaxOcclusion(invTBN * -viewDirectionW, invTBN * normalW, vBumpUV, vBumpInfos.z);\n uvOffset = parallaxOcclusion(invTBN * -viewDirectionW, invTBN * normalW, mainUv, vBumpInfos.z);\n #else\n uvOffset = parallaxOffset(invTBN * viewDirectionW, vBumpInfos.z);\n #endif\n#endif\n\n#ifdef DETAIL\n vec4 detailColor = texture2D(detailSampler, vDetailUV + uvOffset);\n vec2 detailNormalRG = detailColor.wy * 2.0 - 1.0;\n float detailNormalB = sqrt(1. - saturate(dot(detailNormalRG, detailNormalRG)));\n vec3 detailNormal = vec3(detailNormalRG, detailNormalB);\n#endif\n\n#ifdef BUMP\n #ifdef OBJECTSPACE_NORMALMAP\n // normalW = normalize(texture2D(bumpSampler, vBumpUV).xyz * 2.0 - 1.0);\n normalW = normalize(texture2D(bumpSampler, mainUv).xyz * 2.0 - 1.0);\n normalW = normalize(mat3(normalMatrix) * normalW);\n #elif !defined(DETAIL)\n // normalW = perturbNormal(TBN, texture2D(bumpSampler, vBumpUV + uvOffset).xyz, vBumpInfos.y);\n normalW = perturbNormal(TBN, texture2D(bumpSampler, mainUv + uvOffset).xyz, vBumpInfos.y);\n #else\n // vec3 bumpNormal = texture2D(bumpSampler, vBumpUV + uvOffset).xyz * 2.0 - 1.0;\n vec3 bumpNormal = texture2D(bumpSampler, mainUv + uvOffset).xyz * 2.0 - 1.0;\n // Reference for normal blending: https://blog.selfshadow.com/publications/blending-in-detail/\n #if DETAIL_NORMALBLENDMETHOD == 0 // whiteout\n detailNormal.xy *= vDetailInfos.z;\n vec3 blendedNormal = normalize(vec3(bumpNormal.xy + detailNormal.xy, bumpNormal.z * detailNormal.z));\n #elif DETAIL_NORMALBLENDMETHOD == 1 // RNM\n detailNormal.xy *= vDetailInfos.z;\n bumpNormal += vec3(0.0, 0.0, 1.0);\n detailNormal *= vec3(-1.0, -1.0, 1.0);\n vec3 blendedNormal = bumpNormal * dot(bumpNormal, detailNormal) / bumpNormal.z - detailNormal;\n #endif\n normalW = perturbNormalBase(TBN, blendedNormal, vBumpInfos.y);\n #endif\n#elif defined(DETAIL)\n detailNormal.xy *= vDetailInfos.z;\n normalW = perturbNormalBase(TBN, detailNormal, vDetailInfos.z);\n#endif\n",m.Effect.ShadersStore.mtoonVertexShader="// it is based on default.vertex.fx\n// This include is special, it will be replaced to UboDeclaration(WebGL2) or VertexDeclaration(WebGL1).\n// @see effect.ts\n#include<__decl__mtoonVertex>\n\n// Attributes\n\n#define CUSTOM_VERTEX_BEGIN\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef TANGENT\nattribute vec4 tangent;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#include<uvAttributeDeclaration>[2..7]\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n\n#include<helperFunctions>\n\n#include<bonesDeclaration>\n#include<bakedVertexAnimationDeclaration>\n\n// Uniforms\n#include<instancesDeclaration>\n#include<prePassVertexDeclaration>\n\n#include<mainUVVaryingDeclaration>[1..7]\n\n#include<samplerVertexDeclaration>(_DEFINENAME_,DIFFUSE,_VARYINGNAME_,Diffuse)\n// # include<samplerVertexDeclaration>(_DEFINENAME_,DETAIL,_VARYINGNAME_,Detail)\n// # include<samplerVertexDeclaration>(_DEFINENAME_,AMBIENT,_VARYINGNAME_,Ambient)\n// # include<samplerVertexDeclaration>(_DEFINENAME_,OPACITY,_VARYINGNAME_,Opacity)\n#include<samplerVertexDeclaration>(_DEFINENAME_,EMISSIVE,_VARYINGNAME_,Emissive)\n// # include<samplerVertexDeclaration>(_DEFINENAME_,LIGHTMAP,_VARYINGNAME_,Lightmap)\n// # if defined(SPECULARTERM)\n// # include<samplerVertexDeclaration>(_DEFINENAME_,SPECULAR,_VARYINGNAME_,Specular)\n// # endif\n#include<samplerVertexDeclaration>(_DEFINENAME_,BUMP,_VARYINGNAME_,Bump)\n#include<samplerVertexDeclaration>(_DEFINENAME_,SHADE,_VARYINGNAME_,Shade)\n#include<samplerVertexDeclaration>(_DEFINENAME_,RECEIVE_SHADOW,_VARYINGNAME_,ReceiveShadow)\n#include<samplerVertexDeclaration>(_DEFINENAME_,SHADING_GRADE,_VARYINGNAME_,ShadingGrade)\n#include<samplerVertexDeclaration>(_DEFINENAME_,RIM,_VARYINGNAME_,Rim)\n#include<samplerVertexDeclaration>(_DEFINENAME_,MATCAP,_VARYINGNAME_,MatCap)\n#include<samplerVertexDeclaration>(_DEFINENAME_,OUTLINE_WIDTH,_VARYINGNAME_,OutlineWidth)\n#include<samplerVertexDeclaration>(_DEFINENAME_,UV_ANIMATION_MASK,_VARYINGNAME_,UvAnimationMask)\n\n// Additional Uniforms\n#ifdef OUTLINE_WIDTH\n uniform sampler2D outlineWidthSampler;\n#endif\n\n// Output\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n\n#if defined(VERTEXCOLOR) || defined(INSTANCESCOLOR)\nvarying vec4 vColor;\n#endif\n\n#include<bumpVertexDeclaration>\n\n#include<clipPlaneVertexDeclaration>\n\n#include<fogVertexDeclaration