3( 0.0 )",this.getType(e),r)}},Kc=aE;Kc.Nodes=function(){return{customColor:new Ee(`vec3 customColor(vec3 color, float mask, float alpha, out float calpha) { float lalpha = alpha * mask; calpha = lalpha / clamp(lalpha + accumAlpha, 0.00001, 1.0); accumAlpha += (1.0 - accumAlpha) * lalpha; return color; }`)}}();var lE=class extends tt{constructor(e,r){super("v3");this.nodeType="CustomNormal";this.cnormal=e,this.alpha=r,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`}generate(e,r){if(e.isShader("fragment")){let i=e.include(lE.Nodes.customNormal);e.addFragmentVariable(this.calpha,"float");let s=[];return s.push(this.cnormal.build(e,"v3")),s.push("normal"),s.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),s.push(this.alpha.build(e,"f")),s.push(this.calpha),e.format(i+"("+s.join(",")+")",this.getType(e),r)}else return console.warn("CustomNormalNode is not compatible with "+e.shader+" shader."),e.format("vec3( 0.0 )",this.getType(e),r)}},jd=lE;jd.Nodes=function(){return{customNormal:new Ee(`vec3 customNormal(vec3 cnormal, vec3 norm, float mask, float alpha, out float calpha) { vec3 normal = packNormalToRGB( norm ).rgb; normal *= step( vec3(0.5), cnormal ); float lalpha = alpha * mask; calpha = lalpha / clamp( lalpha + accumAlpha, 0.00001, 1.0 ); accumAlpha += ( 1.0 - accumAlpha ) * lalpha; return normal; }`)}}();var Hd=class extends tt{constructor(e,r,i,s,o,a,l,c,u,h,d,f){super("v3");this.nodeType="CustomTexture";this.texture=e,this.textureSize=r,this.crop=i,this.projection=s,this.axis=o,this.side=a,this.size=l,this.blending=c,this.mat=u,this.isMask=f,this.alpha=h,this.mode=d,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`}generate(e,r){e.require("position"),e.require("normal"),e.require("uv"),e.requires.uv=[!0],e.extensions.shaderTextureLOD=!0,e.extensions.derivatives=!0;let i=`g${this.uuid.toString().replace(/-/g,"")}`,s;switch(this.projection.value){case 3:s=e.include(Hd.Nodes.cylindrical);break;case 2:s=e.include(Hd.Nodes.spherical);break;case 1:let a=["vec3(1.0, 0.0, 0.0)","vec3(0.0, 1.0, 0.0)","vec3(0.0, 0.0, 1.0)"][this.axis.value],l=["zy","xz","xy"][this.axis.value],c=new Ee(` vec3 ${i}_planarTexture(vec3 normal, sampler2D tex, vec2 textureSize, float crop, mat3 mat, vec2 size, float blending, bool isMask, float mask, float alpha, int mode, out float calpha, out vec2 writeUv) { vec2 projected = (1. + (position.${l})) / 2.; vec2 uvs = ( mat * vec3( (projected * 2. - 1.) / (size * .5), 1. ) / 2. + 0.5 ).xy; writeUv = uvs; vec4 tmp = texture2D( tex, uvs ); vec3 col = tmp.rgb; float lalpha = alpha * tmp.a; ${this.side.value===2?"":`lalpha *= step(0.0, ${this.side.value===1?"-1.0 * ":""}dot(vObjectNormal, ${a}));`} if ( crop > 0.5 ) { if ( uvs.x < 0.0 || uvs.x > 1.0 || uvs.y < 0.0 || uvs.y > 1.0 ) { lalpha = 0.0; } } lalpha *= mask; calpha = lalpha / clamp( lalpha + accumAlpha, 0.00001, 1.0 ); accumAlpha += (1.0 - accumAlpha) * lalpha * (1.0 - float(isMask)); return col; }`);s=e.include(c);break;case 4:s=e.include(Hd.Nodes.triplanar);break;default:s=e.include(Hd.Nodes.uv);break}e.addFragmentVariable(this.calpha,"float");let o=[];if(o.push("normal"),o.push(this.texture.generate(e,"t")),o.push(this.textureSize.build(e,"v2")),o.push(this.crop.build(e,"f")),o.push(this.mat.build(e,"mat3")),o.push(this.size.build(e,"v2")),o.push(this.blending.build(e,"f")),o.push(this.isMask.build(e,"b")),o.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),o.push(this.alpha.build(e,"f")),o.push(this.mode.build(e,"i")),o.push(this.calpha),this.projection.value===4){let a=`${i}_writeUvs`,l=a+"0",c=a+"1",u=a+"2",h=`${i}_triplanarWeights`;e.addFragmentVariable(l,"vec2"),e.addFragmentVariable(c,"vec2"),e.addFragmentVariable(u,"vec2"),e.addFragmentVariable(h,"vec3"),o.push(l),o.push(c),o.push(u),o.push(h)}else{let a=`${i}_writeUvs`;e.addFragmentVariable(a,"vec2"),o.push(a)}return e.format(s+"("+o.join(",")+")",this.getType(e),r)}},Gl=Hd;Gl.Nodes=function(){let e=new Ee(` vec3 cylindricalTexture(vec3 normal, sampler2D tex, vec2 textureSize, float crop, mat3 mat, vec2 size, float blending, bool isMask, float mask, float alpha, int mode, out float calpha, out vec2 writeUv) { vec3 posN = normalize(position); float u = 0.5 + atan(posN.z, posN.x) / (2.*3.1415); float scaledHeight = position.y / (size.y * 0.5); float v = (scaledHeight / 2.) + .5; vec2 calculatedUv = vec2(u,v); vec2 uvs = ( mat * vec3( calculatedUv * 2. - 1., 1. ) / 2. + 0.5 ).xy; writeUv = uvs; vec2 df = fwidth(uvs); if(df.x > 0.5) df.x = 0.; #ifdef GL_EXT_shader_texture_lod vec4 tmp = texture2DLodEXT(tex, uvs, log2(max(df.x, df.y)*min(textureSize.x, textureSize.y))); #else vec4 tmp = textureLod(tex, uvs, log2(max(df.x, df.y)*min(textureSize.x, textureSize.y))); #endif vec3 col = tmp.rgb; float lalpha = alpha * tmp.a; if ( crop > 0.5 ) { if ( uvs.x < 0.0 || uvs.x > 1.0 || uvs.y < 0.0 || uvs.y > 1.0 ) { lalpha = 0.0; } } lalpha *= mask; calpha = lalpha / clamp( lalpha + accumAlpha, 0.00001, 1.0 ); accumAlpha += (1.0 - accumAlpha) * lalpha * (1.0 - float(isMask)); return col; } `),r=new Ee(` vec3 sphericalTexture(vec3 normal, sampler2D tex, vec2 textureSize, float crop, mat3 mat, vec2 size, float blending, bool isMask, float mask, float alpha, int mode, out float calpha, out vec2 writeUv) { vec3 posN = normalize(vPosition); float u = 0.5 + atan(posN.z, posN.x) / (2.*3.1415); float v = 0.5 + asin(posN.y) / 3.1415; vec2 calculatedUv = vec2(u,v); vec2 uvs = ( mat * vec3( calculatedUv * 2. - 1., 1. ) / 2. + 0.5 ).xy; writeUv = uvs; vec2 df = fwidth(uvs); if(df.x > 0.5) df.x = 0.; #ifdef GL_EXT_shader_texture_lod vec4 tmp = texture2DLodEXT(tex, uvs, log2(max(df.x, df.y)*min(textureSize.x, textureSize.y))); #else vec4 tmp = textureLod(tex, uvs, log2(max(df.x, df.y)*min(textureSize.x, textureSize.y))); #endif vec3 col = tmp.rgb; float lalpha = alpha * tmp.a; if ( crop > 0.5 ) { if ( uvs.x < 0.0 || uvs.x > 1.0 || uvs.y < 0.0 || uvs.y > 1.0 ) { lalpha = 0.0; } } lalpha *= mask; calpha = lalpha / clamp( lalpha + accumAlpha, 0.00001, 1.0 ); accumAlpha += (1.0 - accumAlpha) * lalpha * (1.0 - float(isMask)); return col; } `),i=new Ee(`vec3 uvTexture(vec3 normal, sampler2D tex, vec2 textureSize, float crop, mat3 mat, vec2 size, float blending, bool isMask, float mask, float alpha, int mode, out float calpha, out vec2 writeUv) { vec2 uvs = ( mat * vec3( vUv * 2. - 1., 1. ) / 2. + 0.5 ).xy; writeUv = uvs; vec4 tmp = texture2D( tex, uvs ); vec3 col = tmp.rgb; float lalpha = alpha * tmp.a; if ( crop > 0.5 ) { if ( uvs.x < 0.0 || uvs.x > 1.0 || uvs.y < 0.0 || uvs.y > 1.0 ) { lalpha = 0.0; } } lalpha *= mask; calpha = lalpha / clamp( lalpha + accumAlpha, 0.00001, 1.0 ); accumAlpha += (1.0 - accumAlpha) * lalpha * (1.0 - float(isMask)); return col; }`),s=new Ee(`vec3 triplanarTexture(vec3 normal, sampler2D tex, vec2 textureSize, float crop, mat3 mat, vec2 size, float blending, bool isMask, float mask, float alpha, int mode, out float calpha, out vec2 writeUvs0, out vec2 writeUvs1, out vec2 writeUvs2, out vec3 writeWeights) { vec3 p = position; vec2 uv0 = (1.0 + p.xy) / 2.0; vec2 uv1 = (1.0 + p.zy) / 2.0; vec2 uv2 = (1.0 + p.xz) / 2.0; uv0 = (mat * vec3((uv0 * 2.0 - 1.0) / (size * 0.5), 1.0) / 2.0 + 0.5).xy; uv1 = (mat * vec3((uv1 * 2.0 - 1.0) / (size * 0.5), 1.0) / 2.0 + 0.5).xy; uv2 = (mat * vec3((uv2 * 2.0 - 1.0) / (size * 0.5), 1.0) / 2.0 + 0.5).xy; // Range from 3 to 128 seems to be good float exponent = (1.0 - blending) * 125.0 + 3.0; vec3 n = vObjectNormal; vec3 weights = abs(normalize(n)); weights = pow(weights, vec3(exponent)); weights /= dot(weights, vec3(1.0)); // Write out all sets of UVs that we generated writeUvs0 = uv0; writeUvs1 = uv1; writeUvs2 = uv2; writeWeights = weights; // Derivatives for LOD vec2 df0 = fwidth(uv0); vec2 df1 = fwidth(uv1); vec2 df2 = fwidth(uv2); if (df0.x > 0.5) df0.x = 0.0; if (df1.x > 0.5) df1.x = 0.0; if (df2.x > 0.5) df2.x = 0.0; #ifdef GL_EXT_shader_texture_lod vec4 tmp = texture2DLodEXT(tex, uv0, log2(max(df0.x, df0.y)*min(textureSize.x, textureSize.y))) * weights.z + texture2DLodEXT(tex, uv1, log2(max(df1.x, df1.y)*min(textureSize.x, textureSize.y))) * weights.x + texture2DLodEXT(tex, uv2, log2(max(df2.x, df2.y)*min(textureSize.x, textureSize.y))) * weights.y; #else vec4 tmp = textureLod(tex, uv0, log2(max(df0.x, df0.y)*min(textureSize.x, textureSize.y))) * weights.z + textureLod(tex, uv1, log2(max(df1.x, df1.y)*min(textureSize.x, textureSize.y))) * weights.x + textureLod(tex, uv2, log2(max(df2.x, df2.y)*min(textureSize.x, textureSize.y))) * weights.y; #endif vec3 col = tmp.rgb; float lalpha = alpha * tmp.a; // Apply cropping across all 3 planes if ( crop > 0.5 ) { if ( uv0.x < 0.0 || uv0.x > 1.0 || uv0.y < 0.0 || uv0.y > 1.0 ) { lalpha = 0.0; } if ( uv1.x < 0.0 || uv1.x > 1.0 || uv1.y < 0.0 || uv1.y > 1.0 ) { lalpha = 0.0; } if ( uv2.x < 0.0 || uv2.x > 1.0 || uv2.y < 0.0 || uv2.y > 1.0 ) { lalpha = 0.0; } } lalpha *= mask; calpha = lalpha / clamp(lalpha + accumAlpha, 0.00001, 1.0); accumAlpha += (1.0 - accumAlpha) * lalpha * (1.0 - float(isMask)); return col;//n * 0.5 + 0.5; } `);return{cylindrical:e,spherical:r,uv:i,triplanar:s}}();var Wd=class extends tt{constructor(e,r,i,s,o,a,l,c,u,h,d,f){super("v3");this.nodeType="Depth";this.gradientType=e,this.smooth=r,this.near=i,this.far=s,this.isVector=o,this.isWorldSpace=a,this.origin=l,this.direction=c,this.colors=u,this.steps=h,this.isMask=f,this.alpha=d,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`}generate(e,r){let i=`g${this.uuid.toString().replace(/-/g,"")}`,s=new Ee(`vec3 ${i}_sdepth(float near, float far, vec3 origin, vec3 direction, vec4 colors[${i}_MAX_COLORS], float steps[${i}_MAX_COLORS], bool isMask, float mask, float alpha, out float calpha) { vec4 color = colors[0]; #ifdef ${i}_IS_VECTOR #ifdef ${i}_LINEAR #ifdef ${i}_WORLDSPACE float depth = vectorLinearWorldSpaceDepth(direction, origin, near, far); #else float depth = vectorLinearObjectSpaceDepth(direction, origin, near, far); #endif #else #ifdef ${i}_WORLDSPACE float depth = vectorSphericalWorldSpaceDepth(origin, near, far); #else float depth = vectorSphericalObjectSpaceDepth(origin, near, far); #endif #endif #else float dist = length(vWPosition - cameraPosition); float depth = ( dist - near ) / ( far - near ); #endif float p; #ifdef ${i}_SMOOTH for ( int i = 1; i < ${i}_MAX_COLORS; i++ ) { p = clamp( ( depth - steps[i-1] ) / ( steps[i] - steps[i-1] ), 0.0, 1.0 ); color = mix(color, colors[i], smoothstep(0.0, 1.0, p)); } #else for ( int i = 1; i < ${i}_MAX_COLORS; i++ ) { p = clamp(( depth - steps[i - 1] ) / ( steps[i] - steps[i - 1] ), 0.0, 1.0); color = mix(color, colors[i], p); } #endif float lalpha = alpha * color.a * mask; calpha = mix(lalpha / clamp(lalpha + accumAlpha, 0.00001, 1.0), lalpha, float(isMask)); accumAlpha += (1.0 - accumAlpha) * lalpha * (1.0 - float(isMask)); return color.rgb; }`,[Wd.Nodes.vectorLinearWorldSpaceDepth,Wd.Nodes.vectorLinearObjectSpaceDepth,Wd.Nodes.vectorSphericalObjectSpaceDepth,Wd.Nodes.vectorSphericalWorldSpaceDepth]);if(e.isShader("fragment")){e.define(`${i}_MAX_COLORS`,this.colors.value.length),this.smooth.value&&e.define(`${i}_SMOOTH`),this.isVector.value>.5&&e.define(`${i}_IS_VECTOR`),this.gradientType.value===0&&e.define(`${i}_LINEAR`),this.isWorldSpace.value>.5&&e.define(`${i}_WORLDSPACE`),e.require("worldPosition"),e.addFragmentVariable(this.calpha,"float");let o=e.include(s),a=[];return a.push(this.near.build(e,"f")),a.push(this.far.build(e,"f")),a.push(this.origin.build(e,"v3")),a.push(this.direction.build(e,"v3")),a.push(this.colors.build(e,"v4[]")),a.push(this.steps.build(e,"f[]")),a.push(this.isMask.build(e,"b")),a.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),a.push(this.alpha.build(e,"f")),a.push(this.calpha),e.format(o+"("+a.join(",")+")",this.getType(e),r)}else return console.warn("DepthNode is not compatible with "+e.shader+" shader."),e.format("vec3( 0.0 )",this.getType(e),r)}},qd=Wd;qd.Nodes=function(){let e=new Ee(`float vectorLinearWorldSpaceDepth(vec3 direction, vec3 origin, float near, float far) { vec3 n = normalize(direction); float dist = (n.x*(vWPosition.x - origin.x) + n.y*(vWPosition.y - origin.y) + n.z*(vWPosition.z - origin.z)); return ( dist - near ) / ( far - near ); }`),r=new Ee(`float vectorLinearObjectSpaceDepth(vec3 direction, vec3 origin, float near, float far) { vec3 n = normalize(direction); float dist = (n.x*(position.x - origin.x) + n.y*(position.y - origin.y) + n.z*(position.z - origin.z)); return ( dist - near ) / ( far - near ); }`),i=new Ee(`float vectorSphericalWorldSpaceDepth(vec3 origin, float near, float far) { float dist = length(vWPosition - origin); return ( dist - near ) / ( far - near ); }`),s=new Ee(`float vectorSphericalObjectSpaceDepth(vec3 origin, float near, float far) { float dist = length(position - origin); return ( dist - near ) / ( far - near ); }`);return{vectorLinearWorldSpaceDepth:e,vectorLinearObjectSpaceDepth:r,vectorSphericalWorldSpaceDepth:i,vectorSphericalObjectSpaceDepth:s}}();var bm=class extends tt{constructor(e,r,i,s,o,a,l,c){super("v3");this.nodeType="Fresnel";this.color=e,this.bias=r,this.scale=i,this.intensity=s,this.factor=o,this.isMask=c,this.alpha=a,this.mode=l,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`}generate(e,r){if(e.require("vWorldViewDir"),e.require("worldNormal"),e.isShader("fragment")){e.addFragmentVariable(this.calpha,"float");let i=new Ee(`vec3 fresnel(vec3 color, float bias, float scale, float intensity, float factor, bool isMask, float mask, float alpha, int mode, out float calpha) { float fresnel = bias + scale * pow( abs( factor + dot( normalize( vWorldViewDir ), normalize( vWNormal ) ) ), intensity ); float lalpha = clamp(fresnel, 0.0, 1.0) * alpha * mask; calpha = mix(lalpha / clamp(lalpha + accumAlpha, 0.00001, 1.0), lalpha, float(isMask)); accumAlpha += (1.0 - accumAlpha) * lalpha * (1.0 - float(isMask)); return color; }`),s=e.include(i),o=[];return o.push(this.color.build(e,"c")),o.push(this.bias.build(e,"f")),o.push(this.scale.build(e,"f")),o.push(this.intensity.build(e,"f")),o.push(this.factor.build(e,"f")),o.push(this.isMask.build(e,"b")),o.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),o.push(this.alpha.build(e,"f")),o.push(this.mode.build(e,"i")),o.push(this.calpha),e.format(s+"("+o.join(",")+")",this.getType(e),r)}else return console.warn("FresnelNode is not compatible with "+e.shader+" shader."),e.format("vec3( 0.0 )",this.getType(e),r)}};var cE=class extends tt{constructor(e,r,i,s,o,a,l,c,u){super("v3");this.nodeType="Gradient";this.gradientType=e,this.smooth=r,this.colors=i,this.steps=s,this.offset=o,this.morph=a,this.angle=l,this.isMask=u,this.alpha=c,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`}generate(e,r){if(e.isShader("fragment")){e.define("GRAD_MAX",10),e.require("uv"),e.requires.uv=[!0],e.addFragmentVariable(this.calpha,"float");let i=e.include(cE.Nodes.gradient),s=[];return s.push(this.gradientType.build(e,"i")),s.push(this.smooth.build(e,"b")),s.push(this.colors.build(e,"v4[]")),s.push(this.steps.build(e,"f[]")),s.push(this.offset.build(e,"v2")),s.push(this.morph.build(e,"v2")),s.push(this.angle.build(e,"f")),s.push(this.isMask.build(e,"b")),s.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),s.push(this.alpha.build(e,"f")),s.push(this.calpha),e.format(i+"("+s.join(",")+")",this.getType(e),r)}else return console.warn("GradientNode is not compatible with "+e.shader+" shader."),e.format("vec3( 0.0 )",this.getType(e),r)}},Yd=cE;Yd.Nodes=function(){return{gradient:new Ee(`vec3 gradient(int gradientType, bool smoothed, vec4 colors[GRAD_MAX], float steps[GRAD_MAX], vec2 offset, vec2 morph, float angle, bool isMask, float mask, float alpha, out float calpha) { vec4 color = colors[0]; vec2 m = morph / vUv.xy; vec2 rot = vec2( 0.5 + m.x, m.y ); vec2 dt = vec2( cos( angle ) * rot.x - sin( angle ) * rot.y, sin( angle ) * rot.x + cos( angle ) * rot.y ); vec2 pt = ( vUv - 0.5 + offset ) / 2.0 + dt / 2.0; float t = dot( pt, dt ) / dot( dt, dt ); if ( gradientType == 1 ) { t = distance ( ( vUv + morph ) * 3.0, ( vUv + offset ) + 1.0 ) + angle; } else if ( gradientType == 2 ) { float polar = atan( vUv.x + morph.x - 0.5 + offset.x, vUv.y + morph.y - 0.5 + offset.y ) * -1.0; t = fract( ( angle / PI / -2.0 ) + 0.5 * ( polar / PI ) ); } float p; if (smoothed) { for ( int i = 1; i < GRAD_MAX; i++ ) { p = clamp( ( t - steps[i-1] ) / ( steps[i] - steps[i-1] ), 0.0, 1.0 ); color = mix(color, colors[i], smoothstep(0.0, 1.0, p)); } } else { for ( int i = 1; i < GRAD_MAX; i++ ) { p = clamp( ( t - steps[i-1] ) / ( steps[i] - steps[i-1] ), 0.0, 1.0 ); color = mix(color, colors[i], p); } } float lalpha = alpha * color.a * mask; calpha = mix(lalpha / clamp(lalpha + accumAlpha, 0.00001, 1.0), lalpha, float(isMask)); accumAlpha += (1.0 - accumAlpha) * lalpha * (1.0 - float(isMask)); return color.xyz; }`)}}();var uE=class extends tt{constructor(e,r,i,s,o){super("v3");this.nodeType="Matcap";this.texture=e,this.isMask=s,this.alpha=r,this.mode=i,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`,this.rotation=o}generate(e,r){if(e.isShader("fragment")){e.addFragmentVariable(this.calpha,"float");let i=e.include(uE.Nodes.matcap);e.require("normal"),e.requires.normal=!0;let s=[];return s.push(this.texture.generate(e,"t")),s.push("normal"),s.push(this.isMask.build(e,"b")),s.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),s.push(this.alpha.build(e,"f")),s.push(this.mode.build(e,"i")),s.push(this.calpha),s.push(this.rotation.build(e,"f")),e.format(i+"("+s.join(",")+")",this.getType(e),r)}else return console.warn("MatcapNode is not compatible with "+e.shader+" shader."),e.format("vec3( 0.0 )",this.getType(e),r)}},Xd=uE;Xd.Nodes=function(){return{matcap:new Ee(`vec3 matcap(sampler2D matcapTex, vec3 normal, bool isMask, float mask, float alpha, int mode, out float calpha, float rotation) { vec3 viewDir = normalize( vViewPosition ); vec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) ); vec3 y = cross( viewDir, x ); vec2 uv = vec2( dot( x, normal ), dot( y, normal ) ); uv = mat2( cos(rotation), sin(rotation), -sin(rotation), cos(rotation) ) * uv; uv = uv * 0.495 + 0.5; vec4 matcapColor = texture2D( matcapTex, uv ); float lalpha = alpha * mask; calpha = mix(lalpha / clamp(lalpha + accumAlpha, 0.00001, 1.0), lalpha, float(isMask)); accumAlpha += (1.0 - accumAlpha) * lalpha * (1.0 - float(isMask)); return matcapColor.rgb; }`)}}();var Sm=(o=>(o.SIMPLEX="simplex3d",o.SIMPLEX_FRACTAL="simplex3dFractal",o.ASHIMA="simplexAshima",o.FBM="fbm",o.PERLIN="perlin",o.VORONOI="voronoi",o))(Sm||{}),zi=function(){let t=new Ee(`vec3 random3(vec3 c) { float j = 4096.0*sin(dot(c,vec3(17.0, 59.4, 15.0))); vec3 r; r.z = fract(512.0*j); j *= .125; r.x = fract(512.0*j); j *= .125; r.y = fract(512.0*j); return r-0.5; }`),e=new Ee(`float simplex3d(vec3 p) { vec3 s = floor(p + dot(p, vec3(F3))); vec3 x = p - s + dot(s, vec3(G3)); vec3 e = step(vec3(0.0), x - x.yzx); vec3 i1 = e*(1.0 - e.zxy); vec3 i2 = 1.0 - e.zxy*(1.0 - e); vec3 x1 = x - i1 + G3; vec3 x2 = x - i2 + 2.0*G3; vec3 x3 = x - 1.0 + 3.0*G3; vec4 w, d; w.x = dot(x, x); w.y = dot(x1, x1); w.z = dot(x2, x2); w.w = dot(x3, x3); w = max(0.6 - w, 0.0); d.x = dot(random3(s), x); d.y = dot(random3(s + i1), x1); d.z = dot(random3(s + i2), x2); d.w = dot(random3(s + 1.0), x3); w *= w; w *= w; d *= w; return dot(d, vec4(52.0)); }`,[t]);e.keywords.F3=new qt("float F3 0.3333333"),e.keywords.G3=new qt("float G3 0.1666667");let r=new Ee(`float simplex3dFractal(vec3 m) { mat3 rot1 = mat3(-0.37, 0.36, 0.85,-0.14,-0.93, 0.34,0.92, 0.01,0.4); mat3 rot2 = mat3(-0.55,-0.39, 0.74, 0.33,-0.91,-0.24,0.77, 0.12,0.63); mat3 rot3 = mat3(-0.71, 0.52,-0.47,-0.08,-0.72,-0.68,-0.7,-0.45,0.56); return 0.5333333 * simplex3d(m * rot1) + 0.2666667 * simplex3d(2.0 * m * rot2) + 0.1333333 * simplex3d(4.0 * m * rot3) + 0.0666667 * simplex3d(8.0 * m); }`,[e]),i=new Ee("vec4 permute(vec4 x){return mod(((x*34.0)+1.0)*x, 289.0);}"),s=new Ee("vec4 taylorInvSqrt(vec4 r){return 1.79284291400159 - 0.85373472095314 * r;}"),o=new Ee(`float simplexAshima(vec3 v) { const vec2 C = vec2(1.0/6.0, 1.0/3.0) ; const vec4 D = vec4(0.0, 0.5, 1.0, 2.0); vec3 i = floor(v + dot(v, C.yyy) ); vec3 x0 = v - i + dot(i, C.xxx) ; vec3 g = step(x0.yzx, x0.xyz); vec3 l = 1.0 - g; vec3 i1 = min( g.xyz, l.zxy ); vec3 i2 = max( g.xyz, l.zxy ); vec3 x1 = x0 - i1 + 1.0 * C.xxx; vec3 x2 = x0 - i2 + 2.0 * C.xxx; vec3 x3 = x0 - 1. + 3.0 * C.xxx; i = mod(i, 289.0 ); vec4 p = permute( permute( permute( i.z + vec4(0.0, i1.z, i2.z, 1.0 )) + i.y + vec4(0.0, i1.y, i2.y, 1.0 )) + i.x + vec4(0.0, i1.x, i2.x, 1.0 )); float n_ = 1.0/7.0; // N=7 vec3 ns = n_ * D.wyz - D.xzx; vec4 j = p - 49.0 * floor(p * ns.z *ns.z); // mod(p,N*N) vec4 x_ = floor(j * ns.z); vec4 y_ = floor(j - 7.0 * x_ ); // mod(j,N) vec4 x = x_ *ns.x + ns.yyyy; vec4 y = y_ *ns.x + ns.yyyy; vec4 h = 1.0 - abs(x) - abs(y); vec4 b0 = vec4( x.xy, y.xy ); vec4 b1 = vec4( x.zw, y.zw ); vec4 s0 = floor(b0)*2.0 + 1.0; vec4 s1 = floor(b1)*2.0 + 1.0; vec4 sh = -step(h, vec4(0.0)); vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ; vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww ; vec3 p0 = vec3(a0.xy,h.x); vec3 p1 = vec3(a0.zw,h.y); vec3 p2 = vec3(a1.xy,h.z); vec3 p3 = vec3(a1.zw,h.w); vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3))); p0 *= norm.x; p1 *= norm.y; p2 *= norm.z; p3 *= norm.w; vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0); m = m * m; return 42.0 * dot( m*m, vec4( dot(p0,x0), dot(p1,x1), dot(p2,x2), dot(p3,x3) ) ); }`,[i,s]),a=new Ee("vec4 mod289(vec4 x){return x - floor(x * (1.0 / 289.0)) * 289.0;}"),l=new Ee("vec4 perm(vec4 x){return mod289(((x * 34.0) + 1.0) * x);}",[a]),c=new Ee(`float noise(vec3 p){ vec3 a = floor(p); vec3 d = p - a; d = d * d * (3.0 - 2.0 * d); vec4 b = a.xxyy + vec4(0.0, 1.0, 0.0, 1.0); vec4 k1 = perm(b.xyxy); vec4 k2 = perm(k1.xyxy + b.zzww); vec4 c = k2 + a.zzzz; vec4 k3 = perm(c); vec4 k4 = perm(c + 1.0); vec4 o1 = fract(k3 * (1.0 / 41.0)); vec4 o2 = fract(k4 * (1.0 / 41.0)); vec4 o3 = o2 * d.z + o1 * (1.0 - d.z); vec2 o4 = o3.yw * d.x + o3.xz * (1.0 - d.x); return o4.y * d.y + o4.x * (1.0 - d.y); }`,[l]),u=new Ee(`float fbm(vec3 x) { float v = 0.0; float a = 0.5; vec3 shift = vec3(100); for (int i = 0; i < NUM_OCTAVES; ++i) { v += a * noise(x); x = x * 2.0 + shift; a *= 0.5; } return v; }`,[c]);u.keywords.NUM_OCTAVES=new qt(`int NUM_OCTAVES ${5}`);let h=new Ee("vec3 fade(vec3 t) {return t*t*t*(t*(t*6.0-15.0)+10.0);}"),d=new Ee(`float perlin(vec3 P){ vec3 Pi0 = floor(P); vec3 Pi1 = Pi0 + vec3(1.0); Pi0 = mod(Pi0, 289.0); Pi1 = mod(Pi1, 289.0); vec3 Pf0 = fract(P); vec3 Pf1 = Pf0 - vec3(1.0); vec4 ix = vec4(Pi0.x, Pi1.x, Pi0.x, Pi1.x); vec4 iy = vec4(Pi0.yy, Pi1.yy); vec4 iz0 = Pi0.zzzz; vec4 iz1 = Pi1.zzzz; vec4 ixy = permute(permute(ix) + iy); vec4 ixy0 = permute(ixy + iz0); vec4 ixy1 = permute(ixy + iz1); vec4 gx0 = ixy0 / 7.0; vec4 gy0 = fract(floor(gx0) / 7.0) - 0.5; gx0 = fract(gx0); vec4 gz0 = vec4(0.5) - abs(gx0) - abs(gy0); vec4 sz0 = step(gz0, vec4(0.0)); gx0 -= sz0 * (step(0.0, gx0) - 0.5); gy0 -= sz0 * (step(0.0, gy0) - 0.5); vec4 gx1 = ixy1 / 7.0; vec4 gy1 = fract(floor(gx1) / 7.0) - 0.5; gx1 = fract(gx1); vec4 gz1 = vec4(0.5) - abs(gx1) - abs(gy1); vec4 sz1 = step(gz1, vec4(0.0)); gx1 -= sz1 * (step(0.0, gx1) - 0.5); gy1 -= sz1 * (step(0.0, gy1) - 0.5); vec3 g000 = vec3(gx0.x,gy0.x,gz0.x); vec3 g100 = vec3(gx0.y,gy0.y,gz0.y); vec3 g010 = vec3(gx0.z,gy0.z,gz0.z); vec3 g110 = vec3(gx0.w,gy0.w,gz0.w); vec3 g001 = vec3(gx1.x,gy1.x,gz1.x); vec3 g101 = vec3(gx1.y,gy1.y,gz1.y); vec3 g011 = vec3(gx1.z,gy1.z,gz1.z); vec3 g111 = vec3(gx1.w,gy1.w,gz1.w); vec4 norm0 = taylorInvSqrt(vec4(dot(g000, g000), dot(g010, g010), dot(g100, g100), dot(g110, g110))); g000 *= norm0.x; g010 *= norm0.y; g100 *= norm0.z; g110 *= norm0.w; vec4 norm1 = taylorInvSqrt(vec4(dot(g001, g001), dot(g011, g011), dot(g101, g101), dot(g111, g111))); g001 *= norm1.x; g011 *= norm1.y; g101 *= norm1.z; g111 *= norm1.w; float n000 = dot(g000, Pf0); float n100 = dot(g100, vec3(Pf1.x, Pf0.yz)); float n010 = dot(g010, vec3(Pf0.x, Pf1.y, Pf0.z)); float n110 = dot(g110, vec3(Pf1.xy, Pf0.z)); float n001 = dot(g001, vec3(Pf0.xy, Pf1.z)); float n101 = dot(g101, vec3(Pf1.x, Pf0.y, Pf1.z)); float n011 = dot(g011, vec3(Pf0.x, Pf1.yz)); float n111 = dot(g111, Pf1); vec3 fade_xyz = fade(Pf0); vec4 n_z = mix(vec4(n000, n100, n010, n110), vec4(n001, n101, n011, n111), fade_xyz.z); vec2 n_yz = mix(n_z.xy, n_z.zw, fade_xyz.y); float n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x); return 2.2 * n_xyz; }`,[i,s,h]),f=new Ee(`float hashwithoutsine13(vec3 p3) { p3 = fract(p3 * .1031); p3 += dot(p3, p3.yzx + 33.33); return fract((p3.x + p3.y) * p3.z); }`),p=new Ee(`vec3 hashwithoutsine33(vec3 p3) { p3 = fract(p3 * vec3(.1031, .1030, .0973)); p3 += dot(p3, p3.yxz+33.33); return fract((p3.xxy + p3.yxx)*p3.zyx); }`),m=new Ee(`float metric(in vec3 p) { // L2 return length(p); // Chebyshev // vec3 a = abs(p); // return max(a.x, max(a.y, a.z)); }`),g=new Ee(`float smin( float a, float b, float k ) { float h = smoothstep(0.0, 1.0, 0.5 + 0.5 * (b - a) / k); float correction = k * h * (1.0 - h); return mix(b, a, h) - correction; }`),y=new Ee(`float smax( float a, float b, float k ) { float h = smoothstep(1.0, 0.0, 0.5 + 0.5 * (a - b) / k); float correction = k * h * (1.0 - h); return mix(a, b, h) + correction; }`),v=new Ee(`float remap(float value, float input_min, float input_max, float output_min, float output_max) { // Compute width of each interval float input_width = input_max - input_min; float output_width = output_max - output_min; // Convert input range into a 0-1 range float scaled = (value - input_min) / input_width; // Convert the 0-1 range into a value in output range return output_min + (scaled * output_width); }`),x=new Ee(`float voronoi(in vec3 x, in int style, in float smoothness, in float seed, in int quality) { // Integer and fractional parts of this point's coordinates ivec3 p = ivec3(floor(x)); vec3 f = fract(x); // Different variables that we will use to construct noise: // // f1: distance to the closest feature point // f2: distance to the second closest feature point // e: distance to the closest edge (cell boundary) // // We also compute "smooth" versions of all of the above quantites, essentially // replacing "hard" minimums with "smooth" minimums (described by IQ) float f1_smooth = 8.0; float f1 = 8.0; float f2_smooth = 8.0; float f2 = 8.0; float e_smooth = 8.0; float e = 8.0; // Variables stored from closest cell ivec3 mb; vec3 mr; int steps = quality; for (int x = -steps; x <= steps; x++) for (int y = -steps; y <= steps; y++) for (int z = -steps; z <= steps; z++) { ivec3 b = ivec3(x, y, z); vec3 r = vec3(b) + hashwithoutsine33(vec3(p + b) + seed) - f; float d = length(r); f1_smooth = smin(d, f1_smooth, smoothness); // Store un-smoothed distances too if (d < f1) { f2 = f1; f1 = d; mb = ivec3(x, y, z); mr = r; } else if (d < f2) { f2 = d; } } float id = hashwithoutsine13(vec3(p + mb) + seed); // Second pass for edge distance for (int x = -steps; x <= steps; x++) for (int y = -steps; y <= steps; y++) for (int z = -steps; z <= steps; z++) { // Start search at the cell that contains the closest point to "x" (found in 1st pass) ivec3 b = mb + ivec3(x, y, z); vec3 r = vec3(b) + hashwithoutsine33(vec3(p + b) + seed) - f; float d1 = dot(0.5 * (mr + r), (r - mr)); // IQ normalizes "r - mr" but that breaks things for the smooth version? float d2 = dot(0.5 * (mr + r), normalize(r - mr)); e_smooth = smin(d1, e_smooth, smoothness); e = min(e, d2); // Also compute a smooth version of F2 in this pass { ivec3 b = ivec3(x, y, z); if (b != mb) { vec3 r = vec3(b) + hashwithoutsine33(vec3(p + b) + seed) - f; float d = length(r); f2_smooth = smin(d, f2_smooth, smoothness); } } } // Different visualization modes if (style == 0) { return f1_smooth; } if (style == 1) { return f2_smooth; } if (style == 2) { return f2_smooth - f1_smooth; // "Pebbles" also cool //return step(0.2, f2_smooth - f1_smooth); } if (style == 3) { // This one is really good for rock / stone effects float a = f1; float b = f2; float k = 3.0; float h = max(k - abs(a - b), 0.0) / k; float final = min(a, b) - h * h * k * (1.0 / 4.0); return final; } if (style == 4) { // Some random adjustments to make this style stand out more return exp(5.0 * e_smooth); } if (style == 5) { return pow(f1_smooth, 3.0); } if (style == 6) { const float eps = 0.0125; // Thicker lines as the user increases the smoothness slider float thickness = smoothness * 0.25 + eps; // Blurrier lines as the user increases the smoothness slider float blur = pow(smoothness, 3.0) * 0.25 + eps; return smoothstep( thickness - thickness * blur, thickness + thickness * blur, e ); } if (style == 7) { return hashwithoutsine13(vec3(p + mb) + seed); } } `,[f,p,m,g,y,v]);return{simplex:e,simplexFractal:r,simplexAshima:o,fbm:u,perlin:d,voronoi:x}}();var Kd=class extends tt{constructor(e,r,i,s,o,a,l,c,u,h,d,f,p,m,g,y,v,x,S){super("v3");this.nodeType="Noise";this.scale=e,this.size=r,this.move=i,this.fA=s,this.fB=o,this.distortion=a,this.colorA=l,this.colorB=c,this.colorC=u,this.colorD=h,this.noiseType=f,this.voronoiStyle=m,this.highCut=g,this.lowCut=y,this.smoothness=v,this.seed=x,this.quality=S,this.isMask=p,this.alpha=d,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`}generate(e,r,i,s,o){e.require("uv"),e.requires.uv=[!0],e.addFragmentVariable(this.calpha,"float");let a=Object.values(Sm)[this.noiseType.value],l=a=="voronoi"?` float v = ${a}(st + move, voronoiStyle, smoothness, seed, quality); // Apply clipping to colors v = remap(v, lowCut, highCut, 0.0, 1.0); v = smax(v, 0.0, smoothness * 0.25); v = smin(v, 1.0, smoothness * 0.25); // Note that the voronoi mode only uses colors "A" and "C" from the UI vec4 color = mix(colorA, colorC, v); `:` vec3 q = vec3(${a}(st), ${a}(st + vec3(1.0)), ${a}(st + vec3(1.0))); vec3 r = vec3(${a}(st + vec3(distortion, 1.0) * q + vec3(fA, 1.0) + move), ${a}(st + vec3(distortion, 1.0) * q + vec3(fB, 1.0) + move), ${a}(st * q)); float f = ${a}(st + r); vec4 color; color = mix(colorA, colorB, clamp((f * f) * 4.0, 0.0, 1.0)); color = mix(color, colorC, clamp(length(q), 0.0, 1.0)); color = mix(color, colorD, clamp(length(r.x), 0.0, 1.0)); `,c=new Ee(`vec3 ${a}customNoise(float scale, vec3 size, float move, vec2 fA, vec2 fB, vec2 distortion, vec4 colorA, vec4 colorB, vec4 colorC, vec4 colorD, int voronoiStyle, float highCut, float lowCut, float smoothness, float seed, int quality, bool isMask, float mask, float alpha, out float calpha) { // Prevent scale of zero scale = max(abs(scale), 0.001); vec3 st = position / size; st /= scale; ${l} float lalpha = alpha * color.a * mask; calpha = mix(lalpha / clamp(lalpha + accumAlpha, 0.00001, 1.0), lalpha, float(isMask)); accumAlpha += (1.0 - accumAlpha) * lalpha * (1.0 - float(isMask)); return clamp(color, 0.0, 1.0).rgb; }`,[zi.simplex,zi.simplexFractal,zi.simplexAshima,zi.fbm,zi.perlin,zi.voronoi]),u=e.include(c),h=[];return h.push(this.scale.build(e,"f")),h.push(this.size.build(e,"v3")),h.push(this.move.build(e,"f")),h.push(this.fA.build(e,"v2")),h.push(this.fB.build(e,"v2")),h.push(this.distortion.build(e,"v2")),h.push(this.colorA.build(e,"v4")),h.push(this.colorB.build(e,"v4")),h.push(this.colorC.build(e,"v4")),h.push(this.colorD.build(e,"v4")),h.push(this.voronoiStyle.build(e,"i")),h.push(this.highCut.build(e,"f")),h.push(this.lowCut.build(e,"f")),h.push(this.smoothness.build(e,"f")),h.push(this.seed.build(e,"f")),h.push(this.quality.build(e,"i")),h.push(this.isMask.build(e,"b")),h.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),h.push(this.alpha.build(e,"f")),h.push(this.calpha),e.format(u+"("+h.join(",")+")",this.getType(e),r)}};Kd.numOctaves=5;var hE=class extends tt{constructor(e,r,i,s,o,a,l,c,u,h,d,f,p,m,g,y){super("v3");this.nodeType="Outline";this.firstTime=!0,this.outlineColor=e,this.contourColor=r,this.outlineWidth=i,this.contourWidth=s,this.contourThreshold=o,this.outlineThreshold=a,this.contourFrequency=l,this.outlineSmoothing=c,this.contourDirection=u,this.positionalLines=h,this.compensation=d,this.resolution=f,this.normalMap=p,this.depthMap=m,this.pixelRatio=g,this.alpha=y,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`}generate(e,r){let i=`g${this.uuid.toString().replace(/-/g,"")}`;if(e.require("vWorldViewDir"),e.require("worldNormal"),e.extensions.derivatives=!0,this.compensation.value&&e.define("OUTLINE_COMPENSATION",`${i}_offset`),this.firstTime){let s=this.outlineWidth.build(e,"f"),o=this.resolution.build(e,"v2"),a=this.compensation.build(e,"b"),l=this.pixelRatio.build(e,"f");e.addVertexParsVariable("randomColor","attribute vec3"),e.addVertexParsVariable("extrudeNormal","attribute vec3"),e.addVertexParsVariable(s,"uniform float"),e.addVertexParsVariable(o,"uniform vec2"),e.addVertexParsVariable(a,"uniform bool"),e.addVertexParsVariable(l,"uniform float"),e.addVertexParsVariable("vID","flat out float"),e.addFragmentParsVariable("vID","flat in float"),e.addVertexFinalCode(` vID = randomColor.r; vec2 ${i}_offset = vec2(0.0); if (${a}) { vec4 ${i}_clipPosition = projectionMatrix * (modelViewMatrix * vec4(transformed, 1.0)); // NOTE: For certain shapes, like spheres, we get incorrect extrusion when the // normals face the camera directly. So we hackily fix this by offsetting the normal // by a tiny amount. vec3 ${i}_clipNormal = mat3(projectionMatrix) * (mat3(modelViewMatrix) * extrudeNormal) + 0.0000001; ${i}_offset = normalize(${i}_clipNormal.xy) / ${o} * (${s} / 2.0) * ${i}_clipPosition.w * 2.0 * ${l}; ${i}_clipPosition.xy += ${i}_offset; // TODO(MAX): To handle multiple outline layers, we only want to extrude // if this offset is the biggest of all the potential offsets gl_Position = ${i}_clipPosition; } `)}if(e.isShader("fragment")){e.require("uv"),e.requires.uv=[!0],e.addFragmentVariable(this.calpha,"float");let s=e.include(hE.Nodes.outline),o=[];return o.push(this.outlineColor.build(e,"c")),o.push(this.contourColor.build(e,"c")),o.push(this.outlineWidth.build(e,"f")),o.push(this.contourWidth.build(e,"f")),o.push(this.contourThreshold.build(e,"f")),o.push(this.outlineThreshold.build(e,"f")),o.push(this.contourFrequency.build(e,"f")),o.push(this.outlineSmoothing.build(e,"f")),o.push(this.contourDirection.build(e,"v3")),o.push(this.positionalLines.build(e,"b")),o.push(this.resolution.build(e,"v2")),o.push(this.normalMap.getTexture(e,"t")),o.push(this.depthMap.getTexture(e,"t")),o.push(this.pixelRatio.build(e,"f")),o.push(this.compensation.build(e,"b")),o.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),o.push(this.alpha.build(e,"f")),o.push(this.calpha),this.firstTime=!this.firstTime,e.format(s+"("+o.join(",")+")",this.getType(e),r)}else return console.warn("OutlineNode is not compatible with "+e.shader+" shader."),""}},Qd=hE;Qd.Nodes=function(){let e=new Ee(` float sobelSample(sampler2D t, sampler2D d, vec2 uv, vec2 resolution, float outlineWidth, float pixelRatio) { vec2 halton = haltonSequence[frameIndex]; float temporalOffset = getNoiseInterleavedGradient(gl_FragCoord.xy + halton); float temporalAngle = temporalOffset * PI2; vec2 texelSize = (vec2(1.0) / resolution); vec2 offsetSize = texelSize * outlineWidth * pixelRatio; vec2 uvSamples[9]; vec4 normalSamples[9]; uvSamples[0] = uv + vec2( -offsetSize.x, -offsetSize.y) + (vogelDiskSample(0, 9, temporalAngle) * texelSize); uvSamples[1] = uv + vec2(0.0, -offsetSize.y) + (vogelDiskSample(1, 9, temporalAngle) * texelSize); uvSamples[2] = uv + vec2( offsetSize.x, -offsetSize.y) + (vogelDiskSample(2, 9, temporalAngle) * texelSize); uvSamples[3] = uv + vec2( -offsetSize.x, 0.0) + (vogelDiskSample(3, 9, temporalAngle) * texelSize); uvSamples[4] = uv; uvSamples[5] = uv + vec2( offsetSize.x, 0.0) + (vogelDiskSample(5, 9, temporalAngle) * texelSize); uvSamples[6] = uv + vec2( -offsetSize.x, offsetSize.y) + (vogelDiskSample(6, 9, temporalAngle) * texelSize); uvSamples[7] = uv + vec2(0.0, offsetSize.y) + (vogelDiskSample(7, 9, temporalAngle) * texelSize); uvSamples[8] = uv + vec2( offsetSize.x, offsetSize.y) + (vogelDiskSample(8, 9, temporalAngle) * texelSize); normalSamples[0] = texture2D(t, uvSamples[0]); normalSamples[1] = texture2D(t, uvSamples[1]); normalSamples[2] = texture2D(t, uvSamples[2]); normalSamples[3] = texture2D(t, uvSamples[3]); normalSamples[4] = texture2D(t, uvSamples[4]); normalSamples[5] = texture2D(t, uvSamples[5]); normalSamples[6] = texture2D(t, uvSamples[6]); normalSamples[7] = texture2D(t, uvSamples[7]); normalSamples[8] = texture2D(t, uvSamples[8]); float depthBias = 0.0001; // TODO(MAX): Can we somehow reduce the number of conditionals here with MATH?! if (normalSamples[0].a != vID && normalSamples[0].a != 0.0) { float depthAtSample = texture2D(d, uvSamples[0]).r + depthBias; if (gl_FragCoord.z > depthAtSample) { return 0.0; } } if (normalSamples[1].a != vID && normalSamples[1].a != 0.0) { float depthAtSample = texture2D(d, uvSamples[1]).r + depthBias; if (gl_FragCoord.z > depthAtSample) { return 0.0; } } if (normalSamples[2].a != vID && normalSamples[2].a != 0.0) { float depthAtSample = texture2D(d, uvSamples[2]).r + depthBias; if (gl_FragCoord.z > depthAtSample) { return 0.0; } } if (normalSamples[3].a != vID && normalSamples[3].a != 0.0) { float depthAtSample = texture2D(d, uvSamples[3]).r + depthBias; if (gl_FragCoord.z > depthAtSample) { return 0.0; } } if (normalSamples[4].a != vID && normalSamples[4].a != 0.0) { float depthAtSample = texture2D(d, uvSamples[4]).r + depthBias; if (gl_FragCoord.z > depthAtSample) { return 0.0; } } if (normalSamples[5].a != vID && normalSamples[5].a != 0.0) { float depthAtSample = texture2D(d, uvSamples[5]).r + depthBias; if (gl_FragCoord.z > depthAtSample) { return 0.0; } } if (normalSamples[6].a != vID && normalSamples[6].a != 0.0) { float depthAtSample = texture2D(d, uvSamples[6]).r + depthBias; if (gl_FragCoord.z > depthAtSample) { return 0.0; } } if (normalSamples[7].a != vID && normalSamples[7].a != 0.0) { float depthAtSample = texture2D(d, uvSamples[7]).r + depthBias; if (gl_FragCoord.z > depthAtSample) { return 0.0; } } if (normalSamples[8].a != vID && normalSamples[8].a != 0.0) { float depthAtSample = texture2D(d, uvSamples[8]).r + depthBias; if (gl_FragCoord.z > depthAtSample) { return 0.0; } } vec3 sobel_edge_h = normalSamples[2].rgb + (2.0*normalSamples[5].rgb) + normalSamples[8].rgb - (normalSamples[0].rgb + (2.0*normalSamples[3].rgb) + normalSamples[6].rgb); vec3 sobel_edge_v = normalSamples[0].rgb + (2.0*normalSamples[1].rgb) + normalSamples[2].rgb - (normalSamples[6].rgb + (2.0*normalSamples[7].rgb) + normalSamples[8].rgb); float edgeNormal = sqrt(dot(sobel_edge_h, sobel_edge_h) + dot(sobel_edge_v, sobel_edge_v)); return edgeNormal; } `);return{outline:new Ee(`vec3 outline(vec3 outlineColor, vec3 contourColor, float outlineWidth, float contourWidth, float outlineThreshold, float contourThreshold, float outlineSmoothing, float contourFrequency, vec3 contourDirection, bool positionalLines, vec2 resolution, sampler2D normalMap, sampler2D depthMap, float pixelRatio, bool compensation, float mask, float alpha, out float calpha) { vec3 result = outlineColor; float resultAlpha = 0.0; vec3 N = normalize(vWNormal); vec2 nuv = (gl_FragCoord.xy / resolution); float sobelSample = compensation ? sobelSample(normalMap, depthMap, nuv, resolution, outlineWidth / 2., pixelRatio) : sobelSample(normalMap, depthMap, nuv, resolution, outlineWidth, pixelRatio); resultAlpha = smoothstep(outlineThreshold - outlineSmoothing, outlineThreshold + outlineSmoothing, sobelSample); //resultAlpha = 1.0; //result = vec3(sobelSample); float t = 1.0 - contourThreshold; if(positionalLines) { vec3 NDir = position * contourDirection; float NT = NDir.x + NDir.y + NDir.z; float f = fract(NT * contourFrequency * 0.01); float df = fwidth(NT * contourFrequency); float g = smoothstep(df * (contourWidth * 0.01), df * (contourWidth * 0.01 * 2.0), f); if (g < 1.0 && resultAlpha == 0.0) { result = contourColor; resultAlpha = 1.0; } } else { vec3 NDir = N * contourDirection; float NT = NDir.x + NDir.y + NDir.z; float df = fwidth(NT * contourThreshold); float f = sin(NT * 1.0 * contourFrequency); float g = smoothstep(0.0, df * contourWidth, 1.0 - f); if (df > (t * 0.5) && g < 1.0 && resultAlpha == 0.0) { result = contourColor; resultAlpha = 1.0 - g; } } float lalpha = alpha * resultAlpha * mask; calpha = lalpha / clamp( lalpha + accumAlpha, 0.00001, 1.0 ); accumAlpha += ( 1.0 - accumAlpha ) * lalpha; return result; }`,[e])}}();var Fo=class extends tt{constructor(e,r,i,s,o,a,l,c,u,h,d,f,p,m,g,y,v,x){super("v3");this.nodeType="Pattern";this.style=e,this.projection=r,this.axis=i,this.blending=s,this.offset=o,this.colorA=a,this.colorB=l,this.frequency=c,this.size=u,this.variation=h,this.smoothness=d,this.zigzag=f,this.rotation=p,this.vertical=m,this.horizontal=g,this.sides=y,this.isMask=x,this.alpha=v,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`}generate(e,r){if(e.isShader("fragment")){e.require("position"),e.require("uv"),e.requires.uv=[!0],e.require("normal"),e.requires.normal=!0,e.addFragmentVariable(this.calpha,"float");let i;switch(this.style.value){case 0:i="circle";break;case 1:i="ring";break;case 2:i="polygon";break;case 3:i="xcross";break;case 4:i="diamond";break;case 5:i="checkerboard";break;case 6:i="line";break;case 7:i="wave";break;default:i="circle";break}let s=`g${this.uuid.toString().replace(/-/g,"")}`,o=new Ee(`float hashwithoutsine12(vec2 p) { vec3 p3 = fract(vec3(p.xyx) * .1031); p3 += dot(p3, p3.yzx + 33.33); return fract((p3.x + p3.y) * p3.z); }`),a=new Ee(`vec2 rotate_uv(in vec2 uv, float a, bool repeat) { const float mid = 0.5; float radians = a * (PI / 180.0); vec2 rotated = vec2( cos(radians) * (uv.x - mid) + sin(radians) * (uv.y - mid) + mid, cos(radians) * (uv.y - mid) - sin(radians) * (uv.x - mid) + mid ); return repeat ? fract(rotated): rotated; }`),l="";if(this.projection.value===4){let d=this.style.value===2?`${i}(uv0, frequency, size, variation, smoothness_remapped, zigzag, rotation, sides)`:`${i}(uv0, frequency, size, variation, smoothness_remapped, zigzag, rotation)`,f=this.style.value===2?`${i}(uv1, frequency, size, variation, smoothness_remapped, zigzag, rotation, sides)`:`${i}(uv1, frequency, size, variation, smoothness_remapped, zigzag, rotation)`,p=this.style.value===2?`${i}(uv2, frequency, size, variation, smoothness_remapped, zigzag, rotation, sides)`:`${i}(uv2, frequency, size, variation, smoothness_remapped, zigzag, rotation)`;l=` vec3 p = position; float factor = 0.0125; vec2 uv0 = fract(p.xy * factor); vec2 uv1 = fract(p.zy * factor); vec2 uv2 = fract(p.xz * factor); uv0 = rotate_uv(uv0 + offset, rotation, true); uv1 = rotate_uv(uv1 + offset, rotation, true); uv2 = rotate_uv(uv2 + offset, rotation, true); float d0 = ${d}; float d1 = ${f}; float d2 = ${p}; // Range from 3 to 128 seems to be good float exponent = (1.0 - blending) * 125.0 + 3.0; vec3 n = vObjectNormal; vec3 weights = abs(normalize(n)); weights = pow(weights, vec3(exponent)); weights /= dot(weights, vec3(1.0)); d0 *= weights.z; d1 *= weights.x; d2 *= weights.y; float draw = d0 + d1 + d2; vec2 custom_uv = uv0 * weights.z + uv1 * weights.x + uv2 * weights.y; `}else{let d=this.style.value===2?`${i}(custom_uv, frequency, size, variation, smoothness_remapped, zigzag, rotation, sides)`:`${i}(custom_uv, frequency, size, variation, smoothness_remapped, zigzag, rotation)`,f="";this.axis.value===0?f=`float radius = length(p); float theta = atan(p.y, p.z); float phi = acos(p.x / radius);`:this.axis.value===1?f=`float radius = length(p); float theta = atan(p.x, p.z); float phi = acos(p.y / radius);`:(this.axis.value,f=`float radius = length(p); float theta = atan(p.y, p.x); float phi = acos(p.z / radius);`);let p="";switch(this.projection.value){case 0:p="custom_uv = vUv.st;";break;case 1:break;case 2:p=` vec3 p = position; ${f} custom_uv = vec2(theta, phi); custom_uv /= PI; `;break;case 3:break;default:break}l=` vec2 custom_uv; ${p} custom_uv += offset; custom_uv = fract(custom_uv); custom_uv = rotate_uv(custom_uv, rotation, true); float draw = ${d}; `}let c=new Ee(`vec3 ${s}_pattern(vec3 normal, float blending, int style, vec2 offset, vec4 colorA, vec4 colorB, vec2 frequency, float size, float variation, float smoothness, float zigzag, float rotation, vec2 vertical, vec2 horizontal, int sides, bool isMask, float mask, float alpha, out float calpha) { const float TWO_PI = PI * 2.0; float smoothness_remapped = pow(smoothness, 5.0); ${l} // Construct final output color vec4 color = mix(colorA, colorB, draw); color.a = clamp(color.a, 0.0, 1.0); // Apply cuts color.a *= step(vertical.x, custom_uv.y) * step(custom_uv.y, vertical.y); color.a *= step(horizontal.x, abs(custom_uv.x)) * step(abs(custom_uv.x), horizontal.y); // Accumulate alpha float lalpha = alpha * clamp(color.a, 0.0, 1.0) * mask; calpha = mix(lalpha / clamp(lalpha + accumAlpha, 0.00001, 1.0), lalpha, float(isMask)); accumAlpha += (1.0 - accumAlpha) * lalpha * (1.0 - float(isMask)); return clamp(color, 0.0, 1.0).rgb; }`,[a,o,Fo.DrawFunctions.circle,Fo.DrawFunctions.ring,Fo.DrawFunctions.polygon,Fo.DrawFunctions.cross,Fo.DrawFunctions.diamond,Fo.DrawFunctions.checkerboard,Fo.DrawFunctions.line,Fo.DrawFunctions.wave]),u=e.include(c),h=[];return h.push("normal"),h.push(this.blending.build(e,"f")),h.push(this.style.build(e,"i")),h.push(this.offset.build(e,"v2")),h.push(this.colorA.build(e,"v4")),h.push(this.colorB.build(e,"v4")),h.push(this.frequency.build(e,"v2")),h.push(this.size.build(e,"f")),h.push(this.variation.build(e,"f")),h.push(this.smoothness.build(e,"f")),h.push(this.zigzag.build(e,"f")),h.push(this.rotation.build(e,"f")),h.push(this.vertical.build(e,"v2")),h.push(this.horizontal.build(e,"v2")),h.push(this.sides.build(e,"i")),h.push(this.isMask.build(e,"b")),h.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),h.push(this.alpha.build(e,"f")),h.push(this.calpha),e.format(u+"("+h.join(",")+")",this.getType(e),r)}else return console.warn("PatterNode is not compatible with "+e.shader+" shader."),e.format("vec3(0.0)",this.getType(e),r)}},Zd=Fo;Zd.DrawFunctions=function(){let e=new Ee(`float hashwithoutsine12(vec2 p) { vec3 p3 = fract(vec3(p.xyx) * 0.1031); p3 += dot(p3, p3.yzx + 33.33); return fract((p3.x + p3.y) * p3.z); }`),r=new Ee(`vec2 tile_and_center(in vec2 uv, in vec2 frequency, in float variation, in float zigzag, in float rotation) { // Create tiles in UV-space uv *= frequency; // Integer coords vec2 i = floor(uv); // Offset every other row based on zigzag param, then compute fractional coords float row_offset = mod(i.y, 2.0); uv.x += row_offset * zigzag; vec2 f = fract(uv); // Rotate the tile itself: // const float mid = 0.5; // f = vec2( // cos(rotation) * (f.x - mid) + sin(rotation) * (f.y - mid) + mid, // cos(rotation) * (f.y - mid) - sin(rotation) * (f.x - mid) + mid // ); // f = fract(f); f = f * 2.0 - 1.0; // Recompute integer coords after shifting - then, random value per tile i = floor(uv); float rand = (hashwithoutsine12(i) * 5.0 + 1.0); float jitter = mix(1.0, rand, variation); f *= jitter; return f; }`,[e]),i=new Ee(`float circle(in vec2 uv, in vec2 frequency, in float size, in float variation, in float smoothness, in float zigzag, in float rotation) { vec2 f = tile_and_center(uv, frequency, variation, zigzag, rotation); return smoothstep( -smoothness, smoothness, length(f) - size ); }`,[r]),s=new Ee(`float ring(in vec2 uv, in vec2 frequency, in float size, in float variation, in float smoothness, in float zigzag, in float rotation) { vec2 f = tile_and_center(uv, frequency, variation, zigzag, rotation); float d = length(f); const float inner_width = 0.5; float outer = smoothstep(-smoothness, smoothness, d - size); float inner = smoothstep(-smoothness, smoothness, d - size * inner_width); return outer + (1.0 - inner); }`,[r]),o=new Ee(`float sdf_ngon(in vec2 p, in float r, in int n) { float an = (PI * 2.0) / float(n); float he = r * tan(0.5 * an); // Rotate to first sector p = -p.yx; float bn = an * floor((atan(p.y, p.x) + 0.5 * an) / an); vec2 cs = vec2(cos(bn), sin(bn)); p = mat2(cs.x, -cs.y, cs.y, cs.x)*p; // Side of polygon return length(p - vec2(r, clamp(p.y, -he, he))) * sign(p.x - r); } float polygon(in vec2 uv, in vec2 frequency, in float size, in float variation, in float smoothness, in float zigzag, in float rotation, in int sides) { vec2 f = tile_and_center(uv, frequency, variation, zigzag, rotation); return smoothstep(-smoothness, smoothness, sdf_ngon(f, size, sides)); }`,[r]),a=new Ee(`float sdf_cross(in vec2 p, in vec2 b, float r ) { p = abs(p); p = (p.y > p.x) ? p.yx : p.xy; vec2 q = p - b; float k = max(q.y, q.x); vec2 w = (k > 0.0) ? q : vec2(b.y - p.x, -k); return sign(k) * length(max(w, 0.0)) + r; } // Avoid namespace conflicts float xcross(in vec2 uv, in vec2 frequency, in float size, in float variation, in float smoothness, in float zigzag, in float rotation) { vec2 f = tile_and_center(uv, frequency, variation, zigzag, rotation); return smoothstep(-smoothness, smoothness, sdf_cross(f, vec2(size, size * 0.25), smoothness)); }`,[r]),l=new Ee(`float ndot(vec2 a, vec2 b) { return a.x*b.x - a.y*b.y; } float sdf_diamond(in vec2 p, in vec2 b) { p = abs(p); float h = clamp(ndot(b - 2.0 * p, b) / dot(b, b), -1.0, 1.0); float d = length(p - 0.5 * b * vec2(1.0 - h, 1.0 + h)); return d * sign(p.x * b.y + p.y * b.x - b.x * b.y); } float diamond(in vec2 uv, in vec2 frequency, in float size, in float variation, in float smoothness, in float zigzag, in float rotation) { vec2 f = tile_and_center(uv, frequency, variation, zigzag, rotation); return smoothstep(-smoothness, smoothness, sdf_diamond(f, vec2(size))); }`,[r]),c=new Ee(`float checkerboard(in vec2 uv, in vec2 frequency, in float size, in float variation, in float smoothness, in float zigzag, in float rotation) { uv *= frequency; vec2 i = floor(uv); float offset = mod(i.y, 2.0); uv.x += offset + zigzag * offset; float x = floor(uv.x); return mod(x, 2.0); }`),u=new Ee(`float line(in vec2 uv, in vec2 frequency, in float size, in float variation, in float smoothness, in float zigzag, in float rotation) { vec2 f = tile_and_center(uv, frequency, 0.0, zigzag, rotation); // Different approach for variation param here float row = floor(uv * frequency).y; float rand = hashwithoutsine12(vec2(row)); float s = mix(size, size * rand, variation); return smoothstep( s - smoothness, s + smoothness, abs(f.y) ); }`,[r]),h=new Ee(`// Uses bisection float udf_cos(in vec2 p, in float a, in float b, in float c, in float d) { // Convert all data to a primitive cosine wave p = c * (p - vec2(d, a)); const float TWO_PI = PI * 2.0; // Reduce to principal half cycle p.x = mod(p.x, TWO_PI); if (p.x > PI) { p.x = TWO_PI - p.x; } // Find zero of derivative (minimize distance) float xa = 0.0; float xb = TWO_PI; // 24 bit precision for (int i = 0; i < 24; i++) { float x = 0.5 * (xa + xb); float y = x - p.x + b * c * sin(x) * (p.y - b * c * cos(x)); if (y < 0.0) xa = x; else xb = x; } float x = 0.5 * (xa + xb); // Compute distance vec2 q = vec2(x, b * c * cos(x)); return length(p - q) / c; } float wave(in vec2 uv, in vec2 frequency, in float size, in float variation, in float smoothness, in float zigzag, in float rotation) { float repeat = frequency.x; uv *= repeat; vec2 i = floor(uv); float row_offset = mod(i.y, 2.0); uv.x += row_offset * zigzag; vec2 f = vec2(uv.x, fract(uv.y)); // Generalized cosine: y(x) = a + b * cos(cx + d) const float amplitude = 0.125; float wave_frequency = frequency.y * 0.1; float distance_estimate = udf_cos(f, 0.50, amplitude, wave_frequency * (2.0 * PI), 0.0); // Different approach for variation param here float rand = hashwithoutsine12(vec2(i.y)); float s = mix(size, size * rand, variation); return smoothstep(-smoothness, smoothness, distance_estimate - s * 0.5); }`);return{tileAndCenter:r,circle:i,ring:s,polygon:o,cross:a,diamond:l,checkerboard:c,line:u,wave:h}}();var dE=class extends tt{constructor(e,r,i,s,o,a,l,c){super("v3");this.nodeType="Rainbow";this.filmThickness=e,this.movement=r,this.wavelengths=i,this.noiseStrength=s,this.noiseScale=o,this.offset=a,this.isMask=c,this.alpha=l,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`}generate(e,r){if(e.require("vWorldViewDir"),e.require("worldNormal"),e.isShader("fragment")){e.require("uv"),e.requires.uv=[!0],e.addFragmentVariable(this.calpha,"float");let i=e.include(dE.Nodes.rainbow),s=[];return s.push(this.filmThickness.build(e,"f")),s.push(this.movement.build(e,"f")),s.push(this.wavelengths.build(e,"v3")),s.push(this.noiseStrength.build(e,"f")),s.push(this.noiseScale.build(e,"f")),s.push(this.offset.build(e,"v3")),s.push(this.isMask.build(e,"b")),s.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),s.push(this.alpha.build(e,"f")),s.push(this.calpha),e.format(i+"("+s.join(",")+")",this.getType(e),r)}else return console.warn("RainbowNode is not compatible with "+e.shader+" shader."),e.format("vec3( 0.0 )",this.getType(e),r)}},Jd=dE;Jd.Nodes=function(){let e=new Ee(`vec3 attenuation(vec3 wavelengths, float filmThickness, float movement, float noiseStrength, float noiseScale, vec3 offset) { vec3 st = position / noiseScale; vec3 q = vec3(simplex3d(st), simplex3d(st + vec3(1.0)), simplex3d(st + vec3(1.0))); vec3 r = vec3(simplex3d(st + vec3(1.4, 1.3, 1.0) * q + vec3(1.7, 9.2, 1.0)), simplex3d(st + vec3(2.0, 1.2, 1.0) * q + vec3(8.3, 2.8, 1.0)), simplex3d(st * q)); float noise = simplex3d(st + r); return .5 + .5 * cos((((filmThickness + (noise * noiseStrength)) / (vec3(wavelengths.r * 1.0, wavelengths.g * 0.8, wavelengths.b * 0.6) + 1.0)) * dot(normalize(vWorldViewDir + (offset * -0.001)), normalize(vWNormal))) + movement); }`,[zi.simplex]);return{rainbow:new Ee(`vec3 rainbow(float filmThickness, float movement, vec3 wavelengths, float noiseStrength, float noiseScale, vec3 offset, bool isMask, float mask, float alpha, out float calpha) { vec3 res = clamp(attenuation(wavelengths, filmThickness, movement, noiseStrength, noiseScale, offset), 0.0, 2.0); float rainbowContribution = clamp(res.r + res.g + res.b, 0.0, 1.0); float lalpha = alpha * rainbowContribution * mask; calpha = mix(lalpha / clamp(lalpha + accumAlpha, 0.00001, 1.0), lalpha, float(isMask)); accumAlpha += (1.0 - accumAlpha) * lalpha * (1.0 - float(isMask)); return res; }`,[e])}}();var fE=class extends tt{constructor(e,r,i,s,o,a,l,c,u,h){super("v3");this.nodeType="Toon";this.positioning=e,this.colors=r,this.steps=i,this.source=s,this.isWorldSpace=o,this.noiseStrength=a,this.noiseScale=l,this.shadowColor=c,this.offset=u,this.alpha=h,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`}generate(e,r){if(e.require("worldNormal"),e.require("worldPosition"),e.isShader("fragment")){e.define("COLORS_MAX",10),e.addFragmentVariable(this.calpha,"float");let i=e.include(fE.Nodes.toon),s=[];return s.push(this.positioning.build(e,"i")),s.push(this.colors.build(e,"v4[]")),s.push(this.steps.build(e,"f[]")),s.push(this.source.build(e,"v3")),s.push(this.isWorldSpace.build(e,"b")),s.push(this.noiseStrength.build(e,"f")),s.push(this.noiseScale.build(e,"f")),s.push(this.shadowColor.build(e,"v4")),s.push(this.offset.build(e,"v3")),s.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),s.push(this.alpha.build(e,"f")),s.push(this.calpha),e.format(i+"("+s.join(",")+")",this.getType(e),r)}else return console.warn("ToonNode is not compatible with "+e.shader+" shader."),e.format("vec3( 0.0 )",this.getType(e),r)}},$d=fE;$d.Nodes=function(){let e=new Ee(`float rand(float n) { return fract(sin(n) * 43758.5453123); }`),r=new Ee(`float hash1(float p) { p = fract(p * 0.011); p *= p + 7.5; p *= p + p; return fract(p); }`),i=new Ee(`float valueNoise(vec3 x) { const vec3 step = vec3(110, 241, 171); vec3 i = floor(x); vec3 f = fract(x); // For performance, compute the base input to a 1D hash from the integer part of the argument and the // incremental change to the 1D based on the 3D -> 1D wrapping float n = dot(i, step); vec3 u = f * f * (3.0 - 2.0 * f); return mix(mix(mix( hash1(n + dot(step, vec3(0, 0, 0))), hash1(n + dot(step, vec3(1, 0, 0))), u.x), mix( hash1(n + dot(step, vec3(0, 1, 0))), hash1(n + dot(step, vec3(1, 1, 0))), u.x), u.y), mix(mix( hash1(n + dot(step, vec3(0, 0, 1))), hash1(n + dot(step, vec3(1, 0, 1))), u.x), mix( hash1(n + dot(step, vec3(0, 1, 1))), hash1(n + dot(step, vec3(1, 1, 1))), u.x), u.y), u.z); }`,[r]),s=new Ee(`vec3 hash3(vec3 x) { x = vec3(dot(x,vec3(127.1, 311.7, 74.7)), dot(x,vec3(269.5, 183.3, 246.1)), dot(x,vec3(113.5, 271.9, 124.6))); return fract(sin(x)*43758.5453123); }`),o=new Ee(`vec3 voronoiNoise(in vec3 x) { vec3 p = floor(x); vec3 f = fract(x); float id = 0.0; vec2 res = vec2(100.0); for(int k=-1; k<=1; k++) for(int j=-1; j<=1; j++) for(int i=-1; i<=1; i++) { vec3 b = vec3(float(i), float(j), float(k)); // Comment out the "+ hash(p + b);" part below to get "square" cells vec3 r = vec3(b) - f + hash3(p + b); float d = dot(r, r); if (d < res.x) { id = dot(p + b, vec3(1.0, 57.0, 113.0)); res = vec2(d, res.x); } else if (d < res.y) { res.y = d; } } return vec3(sqrt(res), abs(id)); } `,[s]);return{toon:new Ee(`vec3 toon(int positioning, vec4 colors[COLORS_MAX], float steps[COLORS_MAX], vec3 source, bool isWorldSpace, float noiseStrength, float noiseScale, vec4 shadowColor, vec3 offset, float mask, float alpha, out float calpha) { float t = 0.0; float shadow = 1.0; if (positioning == 0) { // Can't do this mode if lighting is "none" #if (defined(PHONG) || defined(LAMBERT) || defined(STANDARD)) // Algorithm from Chapter 10 of Graphics Shaders const vec3 weights = vec3(0.2125, 0.7154, 0.0721); vec3 lpos; vec3 l; float dproduct; #if (NUM_POINT_LIGHTS > 0) #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++) { // Light positions are in view-space for some reason? lpos = (inverse(viewMatrix) * vec4(pointLights[UNROLLED_LOOP_INDEX].position, 1.0)).xyz; l = normalize(lpos - worldPosition); dproduct = dot(l, normalize(worldNormal)) * 0.5 + 0.5; // TODO: we want to use "intensity" but it isn't available in the shader code //dproduct += dot(pointLights[UNROLLED_LOOP_INDEX].color, weights); t = max(t, dproduct); // Accumulate shadow contribution #if defined(USE_SHADOWMAP) && (UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS) pointLightShadow = pointLightShadows[UNROLLED_LOOP_INDEX]; shadow *= getPointShadow( pointShadowMap[UNROLLED_LOOP_INDEX], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[UNROLLED_LOOP_INDEX], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar); #endif } #pragma unroll_loop_end #endif #if NUM_DIR_LIGHTS > 0 #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++) { // Use the direction vector for directional lights instead l = (inverse(viewMatrix) * vec4(directionalLights[UNROLLED_LOOP_INDEX].direction, 0.0)).xyz; dproduct = dot(l, normalize(worldNormal)) * 0.5 + 0.5; t = max(t, dproduct); // Accumulate shadow contribution #if defined(USE_SHADOWMAP) && (UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS) directionalLightShadow = directionalLightShadows[UNROLLED_LOOP_INDEX]; shadow *= getShadow( UNROLLED_LOOP_INDEX, directionalShadowMap[UNROLLED_LOOP_INDEX], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[UNROLLED_LOOP_INDEX]); #endif } #pragma unroll_loop_end #endif #if NUM_SPOT_LIGHTS > 0 #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++) { lpos = (inverse(viewMatrix) * vec4(spotLights[UNROLLED_LOOP_INDEX].position, 1.0)).xyz; l = normalize(lpos - worldPosition); dproduct = dot(l, normalize(worldNormal)) * 0.5 + 0.5; t = max(t, dproduct); // Accumulate shadow contribution #if defined(USE_SHADOWMAP) && (UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS) spotLightShadow = spotLightShadows[UNROLLED_LOOP_INDEX]; shadow *= getShadow( UNROLLED_LOOP_INDEX, spotShadowMap[UNROLLED_LOOP_INDEX], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[UNROLLED_LOOP_INDEX]); #endif } #pragma unroll_loop_end #endif t = clamp(t, 0.0, 1.0); #endif } else if (positioning == 1) { vec3 origin = mix(position, worldPosition, float(isWorldSpace)); vec3 direction = normalize(source - origin); t = dot(direction, normalize(worldNormal)) * 0.5 + 0.5; } else { vec3 origin = worldPosition; vec3 source = cameraPosition - offset; vec3 direction = normalize(source - origin); t = dot(direction, normalize(worldNormal)) * 0.5 + 0.5; } if (noiseStrength > 0.0) { // Distort with noise vec3 st = position / noiseScale; // Voronoi "smooth" noise float noise = 1.0 - voronoiNoise(st).x; // Voronoi cellular noise //float noise = 1.0 - rand(voronoiNoise(st).z); // Position warp noise // vec3 offset = vec3( // simplex3d(st), // simplex3d(st + vec3(111.1, 143.89, 217.19)), // simplex3d(st + vec3(171.1, 247.89, 117.23)) // ); // st += offset; // float noise = valueNoise(st); t += noise * noiseStrength; } t = clamp(t, 0.0, 1.0); // Compute ramp color float p; vec4 color = colors[0]; for (int i = 1; i < COLORS_MAX; i++) { p = clamp((t - steps[i-1]) / (steps[i] - steps[i-1]), 0.0, 1.0); color = mix(color, colors[i], smoothstep(0.0, 1.0, p)); } // Incorporate custom shadow color if (positioning == 0) { vec3 blendedShadow = mix(color.rgb, shadowColor.rgb, shadowColor.a); color.rgb = mix(blendedShadow, color.rgb, shadow); } // Accumulate alpha as usual float lalpha = alpha * color.a * mask; calpha = lalpha / clamp(lalpha + accumAlpha, 0.00001, 1.0); accumAlpha += (1.0 - accumAlpha) * lalpha; return color.xyz; }`,[zi.simplex,e,i,o])}}();var IR=function(){return{textureBicubic:new Ee(`float w0( float a ) { return ( 1.0 / 6.0 ) * ( a * ( a * ( - a + 3.0 ) - 3.0 ) + 1.0 ); } float w1( float a ) { return ( 1.0 / 6.0 ) * ( a * a * ( 3.0 * a - 6.0 ) + 4.0 ); } float w2( float a ){ return ( 1.0 / 6.0 ) * ( a * ( a * ( - 3.0 * a + 3.0 ) + 3.0 ) + 1.0 ); } float w3( float a ) { return ( 1.0 / 6.0 ) * ( a * a * a ); } // g0 and g1 are the two amplitude functions float g0( float a ) { return w0( a ) + w1( a ); } float g1( float a ) { return w2( a ) + w3( a ); } // h0 and h1 are the two offset functions float h0( float a ) { return - 1.0 + w1( a ) / ( w0( a ) + w1( a ) ); } float h1( float a ) { return 1.0 + w3( a ) / ( w2( a ) + w3( a ) ); } vec4 bicubic( sampler2D tex, vec2 uv, vec4 texelSize, float lod ) { uv = uv * texelSize.zw + 0.5; vec2 iuv = floor( uv ); vec2 fuv = fract( uv ); float g0x = g0( fuv.x ); float g1x = g1( fuv.x ); float h0x = h0( fuv.x ); float h1x = h1( fuv.x ); float h0y = h0( fuv.y ); float h1y = h1( fuv.y ); vec2 p0 = ( vec2( iuv.x + h0x, iuv.y + h0y ) - 0.5 ) * texelSize.xy; vec2 p1 = ( vec2( iuv.x + h1x, iuv.y + h0y ) - 0.5 ) * texelSize.xy; vec2 p2 = ( vec2( iuv.x + h0x, iuv.y + h1y ) - 0.5 ) * texelSize.xy; vec2 p3 = ( vec2( iuv.x + h1x, iuv.y + h1y ) - 0.5 ) * texelSize.xy; return g0( fuv.y ) * ( g0x * textureLod( tex, p0, lod ) + g1x * textureLod( tex, p1, lod ) ) + g1( fuv.y ) * ( g0x * textureLod( tex, p2, lod ) + g1x * textureLod( tex, p3, lod ) ); } vec4 textureBicubic( sampler2D sampler, vec2 uv, float lod ) { vec2 fLodSize = vec2( textureSize( sampler, int( lod ) ) ); vec2 cLodSize = vec2( textureSize( sampler, int( lod + 1.0 ) ) ); vec2 fLodSizeInv = 1.0 / fLodSize; vec2 cLodSizeInv = 1.0 / cLodSize; vec4 fSample = bicubic( sampler, uv, vec4( fLodSizeInv, fLodSize ), floor( lod ) ); vec4 cSample = bicubic( sampler, uv, vec4( cLodSizeInv, cLodSize ), ceil( lod ) ); return mix( fSample, cSample, fract( lod ) ); }`)}}();function DR(n,t){return n>=t?new k(t/n,1):new k(1,n/t)}var pE=class extends tt{constructor(e,r,i,s,o,a,l,c){super("v3");this.nodeType="Transmission";this.thickness=e,this.ior=r,this.roughness=i,this.transmissionSamplerSize=s,this.transmissionSamplerMap=o,this.transmissionDepthMap=a,this.aspectRatio=l,this.alpha=c,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`}generate(e,r){if(e.extensions.shaderTextureLOD=!0,e.extensions.derivatives=!0,e.isShader("fragment")){e.define("NUM_SAMPLES",6),e.define("BLUR_SLOD",Math.pow(2,$e.transmissionLod.value)),e.require("worldPosition"),e.requires.worldNormal=!0,e.requires.modelMatrix=!0,e.requires.projectionMatrix=!0,e.addFragmentVariable(this.calpha,"float");let i=e.include(pE.Nodes.transmission),s=[];return s.push(this.thickness.build(e,"f")),s.push(this.ior.build(e,"f")),s.push(this.roughness.build(e,"f")),s.push(this.transmissionSamplerSize.build(e,"v2")),s.push(this.transmissionSamplerMap.getTexture(e,"t")),s.push(this.transmissionDepthMap.getTexture(e,"t")),s.push(this.aspectRatio.build(e,"v2")),s.push("normal"),s.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),s.push(this.alpha.build(e,"f")),s.push(this.calpha),e.format(i+"("+s.join(",")+")",this.getType(e),r)}else return console.warn("TransmissionNode is not compatible with "+e.shader+" shader."),e.format("vec3( 0.0 )",this.getType(e),r)}},ef=pE;ef.Nodes=function(){let e=new Ee(`vec3 blur(sampler2D sp, vec2 U, vec2 scale, float lod, sampler2D dm, vec2 unrefractedU, vec2 aspectRatio) { // Slightly modified version of this: // https://www.shadertoy.com/view/ltScRG // Special case for blur == 0.0 if (lod == 0.0) { #ifdef TEXTURE_LOD_EXT return texture2DLodEXT( sp, U, 0.0).rgb; #else return textureLod( sp, U, 0.0).rgb; #endif } vec2 texelSize = vec2(1.0) / resolution; vec2 halton = haltonSequence[frameIndex]; float temporalOffset = getNoiseInterleavedGradient(gl_FragCoord.xy + halton); float temporalAngle = temporalOffset * PI2; vec3 res = vec3(0.0); vec2 uv = vec2(0.0); vec2 offset = vec2(0.0); vec2 vogelSample = vec2(0.0); for (int i = 0; i < NUM_SAMPLES; i++) { vogelSample = vogelDiskSample(i, NUM_SAMPLES, temporalAngle) * texelSize; offset = vogelSample * scale * (lod * 10.0); // TODO: used to be hardcoded to 20 uv = U + offset; float opaqueDepth = unpackRGBAToDepth(textureLod(dm, uv, lod)); if (opaqueDepth != 0.0 && opaqueDepth < gl_FragCoord.z) { uv = unrefractedU; lod = lod > 4.0 ? lod : lod / 2.0; } res += textureLod(sp, uv, lod).rgb; } return res / float(NUM_SAMPLES); }`),r=new Ee(`vec3 getVolumeTransmissionRay( vec3 n, vec3 v, float thickness, float ior, mat4 modelMatrix ) { // Direction of refracted light. vec3 refractionVector = refract( -v, n, 1.0 / ior ); // Compute rotation-independant scaling of the model matrix. vec3 modelScale; modelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) ); modelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) ); modelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) ); // The thickness is specified in local space return normalize( refractionVector ) * thickness * modelScale; }`),i=new Ee(`float applyIorToRoughness( float roughness, float ior ) { // Scale roughness with IOR so that an IOR of 1.0 results in no microfacet refraction and // an IOR of 1.5 results in the default amount of microfacet refraction. return roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 ); }`),s=new Ee(`vec3 getTransmissionSample( vec2 fragCoord, float roughness, float ior, vec2 transmissionSamplerSize, sampler2D transmissionSamplerMap, sampler2D transmissionDepthMap, vec2 unrefractedCoords, vec2 aspectRatio) { // Threejs exports do not pass a depth map to this shader, so we have to fallback to the "Threejs method of blurring" - see // also the code in convertTransmission.ts, which runs during export #ifdef IS_THREEJS_EXPORT float lod = log2(transmissionSamplerSize.x) * applyIorToRoughness(roughness / 5.0, ior); return textureBicubic(transmissionSamplerMap, fragCoord.xy, lod).rgb; #else float framebufferLod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior ); float lod = applyIorToRoughness(roughness, ior); return blur(transmissionSamplerMap, fragCoord, vec2(lod), min(framebufferLod / 5.5, 8.5), transmissionDepthMap, unrefractedCoords, aspectRatio); #endif }`,[IR.textureBicubic,i,e]),o=new Ee(`vec3 getIBLVolumeRefraction( vec3 n, vec3 v, float roughness, vec3 position, mat4 modelMatrix, mat4 viewMatrix, mat4 projMatrix, float ior, float thickness, vec2 transmissionSamplerSize, sampler2D transmissionSamplerMap, sampler2D transmissionDepthMap, vec2 aspectRatio ) { vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix ); vec3 refractedRayExit = position + transmissionRay; // Project refracted vector on the framebuffer, while mapping to normalized device coordinates. vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 ); vec2 refractionCoords = ndcPos.xy / ndcPos.w; refractionCoords += 1.0; refractionCoords /= 2.0; vec4 ndcPosUnrefracted = projMatrix * viewMatrix * vec4(position, 1.0 ); vec2 unrefractedCoords = ndcPosUnrefracted.xy / ndcPosUnrefracted.w; unrefractedCoords += 1.0; unrefractedCoords /= 2.0; // Sample framebuffer to get pixel the refracted ray hits. return getTransmissionSample( refractionCoords, roughness, ior, transmissionSamplerSize, transmissionSamplerMap, transmissionDepthMap, unrefractedCoords, aspectRatio ); }`,[s,r]);return{transmission:new Ee(`vec3 transmission(float thickness, float ior, float roughness, vec2 transmissionSamplerSize, sampler2D transmissionSamplerMap, sampler2D transmissionDepthMap, vec2 aspectRatio, vec3 normal, float mask, float alpha, out float calpha) { vec3 v = vec3(0.); if (isOrthographic) { v = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) ); } else { v = normalize(vWPosition - cameraPosition); } vec3 transmission = getIBLVolumeRefraction(vWNormal, -v, roughness, vWPosition, modelMatrix, viewMatrix, projectionMatrix, ior, thickness, transmissionSamplerSize, transmissionSamplerMap, transmissionDepthMap, aspectRatio ); float lalpha = alpha * mask; calpha = lalpha / clamp( lalpha + accumAlpha, 0.00001, 1.0 ); accumAlpha += ( 1.0 - accumAlpha ) * alpha; return transmission; }`,[o])}}();var mE=(e=>(e.NOISE="noise",e.MAP="map",e))(mE||{}),gE=class extends tt{constructor(e,r,i,s,o,a,l,c,u,h,d){super("v3");this.displacementTypeIndex=new Dt(0);this.nodeType="VertexDisplacement";this.intensity=e,this.movementOrTexture=r,Object.values(mE)[this.displacementTypeIndex.value]==="map"&&(this.mat=new zd(this.movementOrTexture.value.matrix)),this.cropOrOffset=i,this.scale=h,this.noiseFunctionIndex=d,this.voronoiStyle=s,this.smoothness=o,this.seed=a,this.highCut=l,this.lowCut=c,this.quality=u}generate(e,r){if(e.isShader("vertex")){e.define("USE_LAYER_DISPLACE");let i,s=[];switch(s.push("displaced_position"),s.push("displaced_normal"),Object.values(mE)[this.displacementTypeIndex.value]){case"map":{i=e.include(gE.Nodes.map),s.push(this.movementOrTexture.getTexture(e,"t")),s.push("uv"),s.push(this.cropOrOffset.build(e,"f")),this.mat&&s.push(this.mat.build(e,"mat3"));break}case"noise":{let a=Object.values(Sm)[this.noiseFunctionIndex.value],l=new Ee(`vec3 orthogonal(vec3 v) { return normalize(abs(v.x) > abs(v.z) ? vec3(-v.y, v.x, 0.0) : vec3(0.0, -v.z, v.y)); }`),c=a=="voronoi"?` float v = ${a}((p + offset) * scale * 0.001 + neighbour_offset + (movement * 0.1), voronoiStyle, smoothness, seed, quality); v = remap(v, lowCut, highCut, 0.0, 1.0); v = smax(v, 0.0, smoothness * 0.25); v = smin(v, 1.0, smoothness * 0.25); return p + n * v * intensity; `:` return p + n * ${a}((p + offset) * scale * 0.001 + neighbour_offset + (movement * 0.1)) * intensity; `,u=new Ee(`vec3 distorted(vec3 p, vec3 n, float scale, float intensity, vec3 offset, float neighbour_offset, float movement, int voronoiStyle, float smoothness, float seed, float highCut, float lowCut, int quality) { ${c} }`,[zi.simplex,zi.simplexFractal,zi.simplexAshima,zi.fbm,zi.perlin,zi.voronoi]),h=new Ee(`vec3 vertexDisplacementNoise(vec3 position, vec3 normal, float scale, vec3 offset, float movement, int voronoiStyle, float smoothness, float seed, float highCut, float lowCut, int quality, float intensity, out vec3 displaced_normal) { vec3 displaced_position = distorted(position, normal, scale, intensity, offset, neighbor_offset, movement, voronoiStyle, smoothness, seed, highCut, lowCut, quality); vec3 tangent1 = orthogonal(normal); vec3 tangent2 = normalize(cross(normal, tangent1)); // TODO(Max): The distance to the neighbors was originally scaled by 0.1. // This caused some small oval/circular visual artifacts in the lighting. // For now, simply using neighbors further away betters the problem, // but we should figure out the underlying cause when we have some time. // Maybe its related to how we calculate the tangent and bitangent? vec3 nearby1 = position + tangent1; vec3 nearby2 = position + tangent2; vec3 distorted1 = distorted(nearby1, normal, scale, intensity, offset, neighbor_offset, movement, voronoiStyle, smoothness, seed, highCut, lowCut, quality); vec3 distorted2 = distorted(nearby2, normal, scale, intensity, offset, neighbor_offset, movement, voronoiStyle, smoothness, seed, highCut, lowCut, quality); displaced_normal = normalize(cross(distorted1 - displaced_position, distorted2 - displaced_position)); return displaced_position; }`,[u,l]);i=e.include(h),s.push(this.scale.build(e,"f")),s.push(this.cropOrOffset.build(e,"v3")),s.push(this.movementOrTexture.build(e,"f")),s.push(this.voronoiStyle.build(e,"i")),s.push(this.smoothness.build(e,"f")),s.push(this.seed.build(e,"f")),s.push(this.highCut.build(e,"f")),s.push(this.lowCut.build(e,"f")),s.push(this.quality.build(e,"i"));break}}return s.push(this.intensity.build(e,"f")),s.push("displaced_normal"),e.format(i+"("+s.join(",")+")",this.getType(e),r)}else return console.warn("VertexDisplacementNode is not compatible with "+e.shader+" shader."),e.format("vec3( 0.0 )",this.getType(e),r)}},tf=gE;tf.Nodes=function(){let e=new Ee(`vec3 orthogonal(vec3 v) { return normalize(abs(v.x) > abs(v.z) ? vec3(-v.y, v.x, 0.0) : vec3(0.0, -v.z, v.y)); }`),r=new Ee(`float displacementMapTexture(sampler2D tex, float crop, vec2 uv, mat3 mat, vec2 offset) { vec2 uvs = (mat * vec3(uv * 2.0 - 1.0, 1.0) / 2.0 + 0.5).xy + offset; vec4 tmp = texture2D(tex, uvs); vec3 col = tmp.rgb; if (crop > 0.5) { if ( uvs.x < 0.0 || uvs.x > 1.0 || uvs.y < 0.0 || uvs.y > 1.0 ) { return 0.0; } } return col.r; }`);return{map:new Ee(`vec3 vertexDisplacementMap(vec3 position, vec3 normal, sampler2D tex, vec2 uv, float crop, mat3 mat, float intensity, out vec3 displaced_normal) { vec3 displaced_position = position + normal * displacementMapTexture(tex, crop, uv, mat, vec2(0.0)) * intensity; vec3 tangent1 = normalize(orthogonal(normal)); vec3 tangent2 = normalize(cross(normal, tangent1)); vec3 nearby1 = position + tangent1 * 0.1; vec3 nearby2 = position + tangent2 * 0.1; vec3 distorted1 = nearby1 + normal * displacementMapTexture(tex, crop, uv, mat, vec2(neighbor_offset)) * intensity; vec3 distorted2 = nearby2 + normal * displacementMapTexture(tex, crop, uv, mat, vec2(neighbor_offset)) * intensity; displaced_normal = normalize(cross(distorted1 - displaced_position, distorted2 - displaced_position)); return displaced_position; }`,[e,r])}}();var $e={normalRenderTarget:new bn,normalRenderTargetDepth:new bn,transmissionRenderTarget:new bn,aspectRatio:new Hr,transmissionSize:new Hr(2048,2048),transmissionRenderTargetDepth:new bn,aoRenderTarget:new bn,aoEnabled:new Qr,pixelRatioNode:new Fe(1),resolution:new Hr,penumbraSize:new Xs(5,.5),frameIndex:new Dt(0),transmissionLod:new Dt(2)};for(let n of Object.values($e))n.isRenderGlobal=!0;var J0={skiaWasmUrl:"https://unpkg.com/@splinetool/ui-wasm@1.9.35/build/ui.wasm"};var Ra=class extends or{constructor(){super("basic");this.nodeType="Basic";this.color=new tr(ii),this.shadingAlpha=new Fe(1),this.shadingBlend=new Dt(0),this.previousModelViewMatrix=new Ki,this.previouseProjectionMatrix=new Ki}get category(){return"phong"}generate(e){let r;if(e.isShader("vertex")){let i=this.position?this.position.analyzeAndFlow(e,"v3",{cache:"position"}):void 0;e.mergeUniform({frameIndex:$e.frameIndex}),e.mergeUniform({resolution:$e.resolution}),e.mergeUniform({previousModelViewMatrix:this.previousModelViewMatrix}),e.mergeUniform({previousProjectionMatrix:this.previouseProjectionMatrix}),e.mergeUniform(Ns.merge([Ie.fog])),e.addParsCode(["varying vec3 vViewPosition;","varying vec3 vWPosition;","#include ","#include ","#include ","#include "].join(` `));let s=["#include ","#include ",` #include #include #if !defined( USE_LAYER_DISPLACE ) #include #endif vec3 displaced_position = position; vec3 displaced_normal = normal; #if defined( USE_LAYER_DISPLACE ) vec3 transformed; vec3 transformedNormal; #endif `,"#include ",` #if !defined( USE_LAYER_DISPLACE ) #include #endif /* !USE_LAYER_DISPLACE */ `];i&&s.push(i.code,i.result?"displaced_position = "+i.result+";":""),s.push("transformed = displaced_position;","#include ","#include ","transformedNormal = normalMatrix * displaced_normal;","#ifndef FLAT_SHADED"," vNormal = transformedNormal;","#endif"),s.push("#include ","#include ","#include "," vViewPosition = - mvPosition.xyz;","#include "),s.push("vWPosition = ( modelMatrix * vec4( transformed, 1.0 ) ).xyz;"),r=s.join(` `)}else{this.color===void 0&&(this.color=new tr(ii)),this.color.analyze(e,{slot:"color"}),this.alpha&&this.alpha.analyze(e),this.afterColor&&this.afterColor.analyze(e,{slot:"afterColor"});let i=this.color.flow(e,"c",{slot:"color"}),s=this.alpha?this.alpha.flow(e,"f"):void 0,o=this.alphaOverride?this.alphaOverride.flow(e,"f"):void 0,a=this.afterColor?this.afterColor.flow(e,"c",{slot:"afterColor"}):void 0;e.requires.transparent=s!==void 0,e.addParsCode(["varying vec3 vWPosition;","#include ","#include ","varying vec3 vViewPosition;","#include "].join(` `));let l=["#include ",i.code];s&&l.push(s.code,"#ifdef ALPHATEST"," if ( "+s.result+" <= ALPHATEST ) discard;","#endif"),a?l.push(a.code,`vec3 outgoingLight = ${i.result};`,`vec3 finalColor = spe_blend(outgoingLight, ${a.result}, 1.0, SPE_BLENDING_NORMAL);`):l.push(`vec3 finalColor = ${i.result};`);let c="1.0";this.mask&&(this.mask.analyze(e),c=`luminance(${this.mask.flow(e,"v3").result})`),s?l.push(`gl_FragColor = vec4( finalColor, accumAlpha * ${s.result} * ${c} );`):l.push("gl_FragColor = vec4("+i.result+", 1.0 );"),o&&l.push(`gl_FragColor.a *= ${o.result};`),l.push("#include ","#include "),r=l.join(` `)}return r}};var wm=class extends or{constructor(){super("lambert");this.nodeType="Lambert";this.color=new tr(ii),this.emissive=new tr(0),this.emissiveIntensity=new Fe(1),this.previousModelViewMatrix=new Ki,this.previouseProjectionMatrix=new Ki,this.shadingAlpha=new Fe(1),this.shadingBlend=new Dt(0),this.occlusion=new Qr(!0)}get category(){return"lambert"}build(e){let r;if(e.define("LAMBERT"),e.requires.lights=!0,e.extensions.derivatives=!0,e.isShader("vertex")){let i=this.position?this.position.analyzeAndFlow(e,"v3",{cache:"position"}):void 0;e.mergeUniform({frameIndex:$e.frameIndex}),e.mergeUniform({resolution:$e.resolution}),e.mergeUniform({previousModelViewMatrix:this.previousModelViewMatrix}),e.mergeUniform({previousProjectionMatrix:this.previouseProjectionMatrix}),e.mergeUniform(Ns.merge([Ie.fog,Ie.lights])),e.addParsCode(["varying vec3 vViewPosition;","varying vec3 vWPosition;","varying vec3 vLightFront;","varying vec3 vIndirectFront;","#ifndef DOUBLE_SIDED"," #define DOUBLE_SIDED","#endif","#ifdef DOUBLE_SIDED"," varying vec3 vLightBack;"," varying vec3 vIndirectBack;","#endif","#include ","#include ","#include ","#include ","#include ","#include ","#include ","#include ","#include "].join(` `));let s=["#include ","#include ",` #include #include #ifndef USE_LAYER_DISPLACE #include #endif vec3 displaced_position = position; vec3 displaced_normal = objectNormal; #ifdef USE_LAYER_DISPLACE vec3 transformed; vec3 transformedNormal; #endif `,"#include ",` #ifndef USE_LAYER_DISPLACE #include #endif `];i&&s.push(i.code,i.result?"displaced_position = "+i.result+";":""),s.push("transformed = displaced_position;","#include ","#include ","transformedNormal = normalMatrix * displaced_normal;","#ifndef FLAT_SHADED"," vNormal = transformedNormal;","#endif"),s.push(" #include "," #include "," vViewPosition = - mvPosition.xyz;"," #include ",` vec3 diffuse = vec3( 1.0 ); GeometricContext geometry; geometry.position = mvPosition.xyz; geometry.normal = normalize( transformedNormal ); geometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( -mvPosition.xyz ); `),s.push(` GeometricContext backGeometry; backGeometry.position = geometry.position; backGeometry.normal = -geometry.normal; backGeometry.viewDir = geometry.viewDir; vLightFront = vec3( 0.0 ); vIndirectFront = vec3( 0.0 ); #ifdef DOUBLE_SIDED vLightBack = vec3( 0.0 ); vIndirectBack = vec3( 0.0 ); #endif IncidentLight directLight; float dotNL; vec3 directLightColor_Diffuse; vIndirectFront += getAmbientLightIrradiance( ambientLightColor ); vIndirectFront += getLightProbeIrradiance( lightProbe, geometry.normal ); #ifdef DOUBLE_SIDED vIndirectBack += getAmbientLightIrradiance( ambientLightColor ); vIndirectBack += getLightProbeIrradiance( lightProbe, backGeometry.normal ); #endif #if NUM_POINT_LIGHTS > 0 #pragma unroll_loop_start for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) { getPointLightInfo( pointLights[ i ], geometry, directLight ); dotNL = dot( geometry.normal, directLight.direction ); directLightColor_Diffuse = directLight.color; vLightFront += saturate( dotNL ) * directLightColor_Diffuse; #ifdef DOUBLE_SIDED vLightBack += saturate( -dotNL ) * directLightColor_Diffuse; #endif } #pragma unroll_loop_end #endif #if NUM_SPOT_LIGHTS > 0 #pragma unroll_loop_start for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) { getSpotLightInfo( spotLights[ i ], geometry, directLight ); dotNL = dot( geometry.normal, directLight.direction ); directLightColor_Diffuse = directLight.color; vLightFront += saturate( dotNL ) * directLightColor_Diffuse; #ifdef DOUBLE_SIDED vLightBack += saturate( -dotNL ) * directLightColor_Diffuse; #endif } #pragma unroll_loop_end #endif #if NUM_DIR_LIGHTS > 0 #pragma unroll_loop_start for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) { getDirectionalLightInfo( directionalLights[ i ], geometry, directLight ); dotNL = dot( geometry.normal, directLight.direction ); directLightColor_Diffuse = directLight.color; vLightFront += saturate( dotNL ) * directLightColor_Diffuse; #ifdef DOUBLE_SIDED vLightBack += saturate( -dotNL ) * directLightColor_Diffuse; #endif } #pragma unroll_loop_end #endif #if NUM_HEMI_LIGHTS > 0 #pragma unroll_loop_start for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) { vIndirectFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry.normal ); #ifdef DOUBLE_SIDED vIndirectBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry.normal ); #endif } #pragma unroll_loop_end #endif `," #include "," #include "),s.push("vWPosition = ( modelMatrix * vec4( transformed, 1.0 ) ).xyz;"),r=s.join(` `)}else{e.mergeUniform({penumbraSize:$e.penumbraSize}),e.mergeUniform({frameIndex:$e.frameIndex}),e.mergeUniform({aoMap:$e.aoRenderTarget}),e.mergeUniform({aoEnabled:$e.aoEnabled}),this.color===void 0&&(this.color=new tr(ii)),this.color.analyze(e,{slot:"color"}),this.shadingAlpha.analyze(e),this.shadingBlend.analyze(e),this.afterColor&&this.afterColor.analyze(e,{slot:"afterColor"}),this.alpha&&this.alpha.analyze(e);let i=this.color.flow(e,"c",{slot:"color"}),s=this.emissive.flow(e,"c",{slot:"emissive"}),o=this.emissiveIntensity.flow(e,"f",{slot:"emissive"}),a=this.occlusion.flow(e,"b",{slot:"occlusion"}),l=this.shadingAlpha.flow(e,"f"),c=this.shadingBlend.flow(e,"i"),u=this.afterColor?this.afterColor.flow(e,"c",{slot:"afterColor"}):void 0,h=this.alpha?this.alpha.flow(e,"f"):void 0,d=this.alphaOverride?this.alphaOverride.flow(e,"f"):void 0;e.requires.transparent=h!==void 0,e.addParsCode([`uniform float penumbraSize[${5}];`,"uniform sampler2D aoMap;","uniform bool aoEnabled;","varying vec3 vViewPosition;","varying vec3 vWPosition;","varying vec3 vLightFront;","varying vec3 vIndirectFront;","#ifndef DOUBLE_SIDED"," #define DOUBLE_SIDED","#endif","#include ","#ifdef DOUBLE_SIDED"," varying vec3 vLightBack;"," varying vec3 vIndirectBack;","#endif","#include ","#include ","#include ","#include ","#include ","#include ","#include "].join(` `));let f=["#include ",` // NOTE: gl_FrontFacing alternative using face normal estimation. vec3 viewdx = dFdx(vViewPosition); vec3 viewdy = dFdy(vViewPosition); vec3 faceNormal = normalize(cross(viewdx, viewdy)); bool isFrontFacing = (dot(normal, faceNormal) >= 0.0); `,"#include "];f.push(i.code,"vec3 diffuseColor = "+i.result+";","ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );"),h&&f.push(h.code,"#ifdef ALPHATEST","if ( "+h.result+" <= ALPHATEST ) discard;","#endif"),f.push("#ifdef DOUBLE_SIDED"," reflectedLight.indirectDiffuse += ( isFrontFacing ) ? vIndirectFront : vIndirectBack;","#else"," reflectedLight.indirectDiffuse += vIndirectFront;","#endif","#include ","reflectedLight.indirectDiffuse *= BRDF_Lambert( diffuseColor.rgb );","#ifdef DOUBLE_SIDED"," reflectedLight.directDiffuse = ( isFrontFacing ) ? vLightFront : vLightBack;","#else"," reflectedLight.directDiffuse = vLightFront;","#endif","reflectedLight.directDiffuse *= BRDF_Lambert( diffuseColor.rgb ) * getShadowMask();"),s&&f.push(s.code,"reflectedLight.directDiffuse += "+s.result+" * "+o.result+";"),f.push("vec3 ao = aoEnabled && "+a.result+" ? tex2D(aoMap, gl_FragCoord.xy / resolution).rgb : vec3(1.0);","vec3 outgoingLight = (reflectedLight.directDiffuse + reflectedLight.indirectDiffuse) ;");let p="1.0";this.mask&&(this.mask.analyze(e),p=`luminance(${this.mask.flow(e,"v3").result})`),f.push(` if (outgoingLight != diffuseColor) { float lightAccu = clamp( length( reflectedLight.directSpecular + reflectedLight.indirectSpecular ), 0.0, 1.0 ); accumAlpha += ( 1.0 - accumAlpha ) * ${l.result} * ${p} * lightAccu; outgoingLight = spe_blend( diffuseColor, outgoingLight, ${l.result} * ${p}, ${c.result} ); outgoingLight *= ao; } `),u&&f.push(u.code,`outgoingLight = spe_blend(outgoingLight, ${u.result}, 1.0, SPE_BLENDING_NORMAL);`),h?f.push(`gl_FragColor = vec4( outgoingLight, accumAlpha * ${h.result} );`):f.push("gl_FragColor = vec4( outgoingLight, 1.0 );"),d&&f.push(`gl_FragColor.a *= ${d.result};`),f.push("#include ","#include ","#include "),r=f.join(` `)}return r}};var La=function(){let n=new Ee(`vec2 dHdxy(sampler2D bumpMap, vec2 bumpMapUv, float bumpScale) { // Gradient of UVs w.r.t. X coordinate (in screen-space) vec2 dSTdx = dFdx(bumpMapUv); // Gradient of UVs w.r.t. Y coordinate (in screen-space) vec2 dSTdy = dFdy(bumpMapUv); // Forward differencing float Hll = bumpScale * luminance(texture(bumpMap, bumpMapUv).rgb); float dBx = bumpScale * luminance(texture(bumpMap, bumpMapUv + dSTdx).rgb) - Hll; float dBy = bumpScale * luminance(texture(bumpMap, bumpMapUv + dSTdy).rgb) - Hll; return vec2( dBx, dBy ); }`),t=new Ee(`vec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy, float faceDirection ) { vec3 vSigmaX = dFdx( surf_pos.xyz ); vec3 vSigmaY = dFdy( surf_pos.xyz ); vec3 vN = surf_norm; // normalized vN = normalize(vN); vec3 R1 = cross( vSigmaY, vN ); vec3 R2 = cross( vN, vSigmaX ); R1 = normalize(R1); R2 = normalize(R2); float fDet = dot( vSigmaX, R1 ) * faceDirection; vec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 ); return normalize( abs( fDet ) * vN - vGrad ); }`);return{dHdxy:n,perturbNormalArb:t}}();var Am=class extends or{constructor(){super("phong");this.nodeType="Phong";this.color=new tr(ii),this.specular=new tr(1118481),this.shininess=new Fe(30),this.previousModelViewMatrix=new Ki,this.previouseProjectionMatrix=new Ki,this.shadingAlpha=new Fe(1),this.shadingBlend=new Dt(0),this.occlusion=new Qr(!0)}get category(){return"phong"}build(e){let r;if(e.define("PHONG"),e.requires.lights=!0,e.extensions.derivatives=!0,e.isShader("vertex")){let i=this.position?this.position.analyzeAndFlow(e,"v3",{cache:"position"}):void 0;e.mergeUniform({frameIndex:$e.frameIndex}),e.mergeUniform({resolution:$e.resolution}),e.mergeUniform({previousModelViewMatrix:this.previousModelViewMatrix}),e.mergeUniform({previousProjectionMatrix:this.previouseProjectionMatrix}),e.mergeUniform(Ns.merge([Ie.fog,Ie.lights])),e.addParsCode(["varying vec3 vViewPosition;","varying vec3 vWPosition;","#include ","#include ","#include ","#include ","#include ","#include "].join(` `));let s=["#include ","#include ",` #include #include #ifndef USE_LAYER_DISPLACE #include #endif vec3 displaced_position = position; vec3 displaced_normal = objectNormal; #ifdef USE_LAYER_DISPLACE vec3 transformed; vec3 transformedNormal; #endif `,"#include ",` #ifndef USE_LAYER_DISPLACE #include #endif `];i&&s.push(i.code,i.result?"displaced_position = "+i.result+";":""),s.push("transformed = displaced_position;","#include ","#include ","transformedNormal = normalMatrix * displaced_normal;","#ifndef FLAT_SHADED"," vNormal = transformedNormal;","#endif"),s.push(" #include "," #include "," vViewPosition = - mvPosition.xyz;"," #include "," #include "," #include "),s.push("vWPosition = ( modelMatrix * vec4( transformed, 1.0 ) ).xyz;"),r=s.join(` `)}else{e.mergeUniform({penumbraSize:$e.penumbraSize}),e.mergeUniform({frameIndex:$e.frameIndex}),e.mergeUniform({aoMap:$e.aoRenderTarget}),e.mergeUniform({aoEnabled:$e.aoEnabled}),this.color===void 0&&(this.color=new tr(ii)),this.color.analyze(e,{slot:"color"}),this.specular.analyze(e),this.shininess.analyze(e);let i=this.occlusion.flow(e,"b",{slot:"occlusion"});this.shadingAlpha.analyze(e),this.shadingBlend.analyze(e),this.afterColor&&this.afterColor.analyze(e,{slot:"afterColor"}),this.alpha&&this.alpha.analyze(e);let s=this.color.flow(e,"c",{slot:"color"}),o=this.specular.flow(e,"c"),a=this.shininess.flow(e,"f"),l=this.shadingAlpha.flow(e,"f"),c=this.shadingBlend.flow(e,"i"),u=this.afterColor?this.afterColor.flow(e,"c",{slot:"afterColor"}):void 0,h=this.alpha?this.alpha.flow(e,"f"):void 0,d=this.alphaOverride?this.alphaOverride.flow(e,"f"):void 0;e.requires.transparent=h!==void 0,e.addParsCode(["varying vec3 vWPosition;","uniform vec3 emissive;",`uniform float penumbraSize[${5}];`,"uniform sampler2D aoMap;","uniform bool aoEnabled;","#include ","#include ","#include ","#include ","#include ","#include ","#include "].join(` `));let f=["#include ",` // NOTE: gl_FrontFacing alternative using face normal estimation. vec3 viewdx = dFdx(vViewPosition); vec3 viewdy = dFdy(vViewPosition); vec3 faceNormal = normalize(cross(viewdx,viewdy)); if (dot(normal, faceNormal) < 0.0) { normal *= -1.0; } `," BlinnPhongMaterial material;"];if(this.bumpMap){e.include(La.dHdxy),e.include(La.perturbNormalArb);let m=this.bumpMap.texture.flow(e,"t"),g=this.bumpMap.flow(e,"v3"),y=this.bumpMapIntensity?this.bumpMapIntensity.flow(e,"f").result:"1.0",v="";this.bumpMap.projection.value===4?v=` vec3 bumpNormal = vec3(0.0); { vec2 uv0 = g${this.bumpMap.uuid.toString().replace(/-/g,"")}_writeUvs0; vec2 uv1 = g${this.bumpMap.uuid.toString().replace(/-/g,"")}_writeUvs1; vec2 uv2 = g${this.bumpMap.uuid.toString().replace(/-/g,"")}_writeUvs2; vec3 weights = g${this.bumpMap.uuid.toString().replace(/-/g,"")}_triplanarWeights; vec2 grad0 = dHdxy(${m.result}, uv0, ${y}); vec3 n0 = perturbNormalArb(-vViewPosition, normal, grad0, faceDirection); vec2 grad1 = dHdxy(${m.result}, uv1, ${y}); vec3 n1 = perturbNormalArb(-vViewPosition, normal, grad1, faceDirection); vec2 grad2 = dHdxy(${m.result}, uv2, ${y}); vec3 n2 = perturbNormalArb(-vViewPosition, normal, grad2, faceDirection); bumpNormal = n0 * weights.z + n1 * weights.x + n2 * weights.y; bumpNormal = normalize(bumpNormal); } normal = bumpNormal; `:v=` vec2 bumpMapCachedUv = g${this.bumpMap.uuid.toString().replace(/-/g,"")}_writeUvs; vec2 grad = dHdxy(${m.result}, bumpMapCachedUv, ${y}); normal = perturbNormalArb( - vViewPosition, normal, grad, faceDirection ); `,f.push(`// Call the Texture Layer's function once here so that it writes out its procedural UV coordinates ${g.result}; ${v} `)}f.push(s.code," vec3 diffuseColor = "+s.result+";"," ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );"," vec3 totalEmissiveRadiance = emissive;",o.code," vec3 specular = "+o.result+";",a.code," float shininess = max( 0.0001, "+a.result+" );"," float specularStrength = 1.0;"),h&&f.push(h.code,"#ifdef ALPHATEST","if ( "+h.result+" <= ALPHATEST ) discard;","#endif"),f.push("material.diffuseColor = diffuseColor;"),f.push("material.specularColor = specular;","material.specularShininess = shininess;","material.specularStrength = specularStrength;","#include ","#include "),f.push("vec3 ao = aoEnabled && "+i.result+" ? tex2D(aoMap, gl_FragCoord.xy / resolution).rgb : vec3(1.0);","vec3 outgoingLight = ((reflectedLight.directDiffuse + reflectedLight.indirectDiffuse)) + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;");let p="1.0";this.mask&&(this.mask.analyze(e),p=`luminance(${this.mask.flow(e,"v3").result})`),f.push(` if (outgoingLight != diffuseColor) { float lightAccu = clamp( length( reflectedLight.directSpecular + reflectedLight.indirectSpecular ), 0.0, 1.0 ); accumAlpha += ( 1.0 - accumAlpha ) * ${l.result} * ${p} * lightAccu; outgoingLight = spe_blend( diffuseColor, outgoingLight, ${l.result} * ${p}, ${c.result} ); outgoingLight *= ao; } `),u&&f.push(u.code,`outgoingLight = spe_blend(outgoingLight, ${u.result}, 1.0, SPE_BLENDING_NORMAL);`),h?f.push(`gl_FragColor = vec4( outgoingLight, accumAlpha * ${h.result});`):f.push("gl_FragColor = vec4( outgoingLight, 1.0 );"),d&&f.push(`gl_FragColor.a *= ${d.result};`),f.push("#include ","#include ","#include "),r=f.join(` `)}return r}};var Em=class extends or{constructor(){super("standard");this.nodeType="Standard";this.color=new tr(ii),this.roughness=new Fe(.3),this.metalness=new Fe(0),this.reflectivity=new Fe(.5),this.previousModelViewMatrix=new Ki,this.previouseProjectionMatrix=new Ki,this.shadingAlpha=new Fe(1),this.shadingBlend=new Dt(0),this.occlusion=new Qr(!0)}get category(){return"physical"}build(e){let r;if(e.define("STANDARD"),e.requires.lights=!0,e.extensions.derivatives=!0,e.extensions.shaderTextureLOD=!0,e.isShader("vertex")){let i=this.position?this.position.analyzeAndFlow(e,"v3",{cache:"position"}):void 0;e.mergeUniform({frameIndex:$e.frameIndex}),e.mergeUniform({resolution:$e.resolution}),e.mergeUniform({previousModelViewMatrix:this.previousModelViewMatrix}),e.mergeUniform({previousProjectionMatrix:this.previouseProjectionMatrix}),e.mergeUniform(Ns.merge([Ie.fog,Ie.lights])),Ie.LTC_1&&(e.uniforms.ltc_1={value:void 0},e.uniforms.ltc_2={value:void 0}),e.addParsCode(["varying vec3 vViewPosition;","varying vec3 vWPosition;","#include ","#include ","#include ","#include ","#include ","#include "].join(` `));let s=["#include ","#include ",` #include #include #if !defined( USE_LAYER_DISPLACE ) #include #endif vec3 displaced_position = position; vec3 displaced_normal = objectNormal; #if defined( USE_LAYER_DISPLACE ) vec3 transformed; vec3 transformedNormal; #endif `,"#include ",` #if !defined( USE_LAYER_DISPLACE ) #include #endif /* !USE_LAYER_DISPLACE */ `];i&&s.push(i.code,i.result?"displaced_position = "+i.result+";":""),s.push("transformed = displaced_position;","#include ","#include ","transformedNormal = normalMatrix * displaced_normal;","#ifndef FLAT_SHADED"," vNormal = transformedNormal;","#endif"),s.push("#include ","#include ","#include "," vViewPosition = - mvPosition.xyz;","#include ","#include "),s.push("vWPosition = ( modelMatrix * vec4( transformed, 1.0 ) ).xyz;"),r=s.join(` `)}else{e.mergeUniform({penumbraSize:$e.penumbraSize}),e.mergeUniform({frameIndex:$e.frameIndex}),e.mergeUniform({aoMap:$e.aoRenderTarget}),e.mergeUniform({aoEnabled:$e.aoEnabled});let i={gamma:!0};this.color===void 0&&(this.color=new tr(ii)),this.color.analyze(e,{slot:"color",context:i}),this.roughness.analyze(e),this.metalness.analyze(e);let s=this.occlusion.flow(e,"b",{slot:"occlusion"});this.shadingAlpha.analyze(e),this.shadingBlend.analyze(e),this.afterColor&&this.afterColor.analyze(e,{slot:"afterColor"}),this.alpha&&this.alpha.analyze(e),this.reflectivity&&this.reflectivity.analyze(e);let o=this.color.flow(e,"c",{slot:"color",context:i}),a=this.roughness.flow(e,"f"),l=this.metalness.flow(e,"f"),c=this.shadingAlpha.flow(e,"f"),u=this.shadingBlend.flow(e,"i"),h=this.afterColor?this.afterColor.flow(e,"c",{slot:"afterColor"}):void 0,d=this.alpha?this.alpha.flow(e,"f"):void 0,f=this.alphaOverride?this.alphaOverride.flow(e,"f"):void 0,p=this.reflectivity?this.reflectivity.flow(e,"f"):void 0;e.requires.transparent=d!==void 0,e.addParsCode(["varying vec3 vViewPosition;","varying vec3 vWPosition;",`uniform float penumbraSize[${5}];`,"uniform sampler2D aoMap;","uniform bool aoEnabled;","#include ","#include ","#include ","#include ","#include ","#include ","#include "].join(` `));let m=["#include "," #include ",` // NOTE: gl_FrontFacing alternative using face normal estimation. vec3 viewdx = dFdx(vViewPosition); vec3 viewdy = dFdy(vViewPosition); vec3 faceNormal = normalize(cross(viewdx,viewdy)); if (dot(normal, faceNormal) < 0.0) { normal *= -1.0; } `," PhysicalMaterial material;"," material.diffuseColor = vec3( 1.0 );"];if(this.bumpMap){e.include(La.dHdxy),e.include(La.perturbNormalArb);let y=this.bumpMap.texture.flow(e,"t"),v=this.bumpMap.flow(e,"v3"),x=this.bumpMapIntensity?this.bumpMapIntensity.flow(e,"f").result:"1.0",S="";this.bumpMap.projection.value===4?S=` vec3 bumpNormal = vec3(0.0); { vec2 uv0 = g${this.bumpMap.uuid.toString().replace(/-/g,"")}_writeUvs0; vec2 uv1 = g${this.bumpMap.uuid.toString().replace(/-/g,"")}_writeUvs1; vec2 uv2 = g${this.bumpMap.uuid.toString().replace(/-/g,"")}_writeUvs2; vec3 weights = g${this.bumpMap.uuid.toString().replace(/-/g,"")}_triplanarWeights; vec2 grad0 = dHdxy(${y.result}, uv0, ${x}); vec3 n0 = perturbNormalArb(-vViewPosition, normal, grad0, faceDirection); vec2 grad1 = dHdxy(${y.result}, uv1, ${x}); vec3 n1 = perturbNormalArb(-vViewPosition, normal, grad1, faceDirection); vec2 grad2 = dHdxy(${y.result}, uv2, ${x}); vec3 n2 = perturbNormalArb(-vViewPosition, normal, grad2, faceDirection); bumpNormal = n0 * weights.z + n1 * weights.x + n2 * weights.y; bumpNormal = normalize(bumpNormal); } normal = bumpNormal; `:S=` vec2 bumpMapCachedUv = g${this.bumpMap.uuid.toString().replace(/-/g,"")}_writeUvs; vec2 grad = dHdxy(${y.result}, bumpMapCachedUv, ${x}); normal = perturbNormalArb( - vViewPosition, normal, grad, faceDirection ); `,m.push(`// Call the Texture Layer's function once here so that it writes out its procedural UV coordinates ${v.result}; ${S} `)}if(m.push(o.code," vec3 diffuseColor = "+o.result+";"," ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );",l.code," float metalnessFactor = "+l.result+";"),this.roughnessMap){let y=this.roughnessMap.texture.flow(e,"t"),v=this.roughnessMap.flow(e,"v3"),x="";this.roughnessMap.projection.value===4?x=` float roughnessChange = 1.0; { vec2 uv0 = g${this.roughnessMap.uuid.toString().replace(/-/g,"")}_writeUvs0; vec2 uv1 = g${this.roughnessMap.uuid.toString().replace(/-/g,"")}_writeUvs1; vec2 uv2 = g${this.roughnessMap.uuid.toString().replace(/-/g,"")}_writeUvs2; vec3 weights = g${this.roughnessMap.uuid.toString().replace(/-/g,"")}_triplanarWeights; float r0 = luminance(texture(${y.result}, uv0).rgb) * roughnessScale; float r1 = luminance(texture(${y.result}, uv1).rgb) * roughnessScale; float r2 = luminance(texture(${y.result}, uv2).rgb) * roughnessScale; roughnessChange = (r0 * weights.z + r1 * weights.x + r2 * weights.y); } float roughnessFactor = roughnessChange * ${a.result}; `:x=` vec2 roughnessMapCachedUv = g${this.roughnessMap.uuid.toString().replace(/-/g,"")}_writeUvs; vec4 vals = texture(${y.result}, roughnessMapCachedUv); float roughnessFactor = luminance(vals.rgb) * ${a.result}; `,m.push(`// Call the Texture Layer's function once here so that it writes out its procedural UV coordinates ${v.result}; const float roughnessScale = 1.0; ${x} `)}else m.push(a.code," float roughnessFactor = "+a.result+";");d&&m.push(d.code,"#ifdef ALPHATEST"," if ( "+d.result+" <= ALPHATEST ) discard;","#endif"),m.push("vec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );","float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );"),m.push("material.diffuseColor = diffuseColor * ( 1.0 - metalnessFactor );","material.roughness = max( roughnessFactor, 0.0525 );","material.roughness += geometryRoughness;","material.roughness = min( material.roughness, 1.0 );","material.roughness = clamp( roughnessFactor, 0.04, 1.0 );"),p?m.push(p.code,"material.specularColor = mix( vec3( 0.16 * pow2( "+p.result+" ) ), diffuseColor, metalnessFactor );"):m.push("material.specularColor = mix( vec3( 0.04 ), diffuseColor, metalnessFactor );"),m.push("#include "),m.push("#include "),m.push("vec3 ao = aoEnabled && "+s.result+" ? tex2D(aoMap, gl_FragCoord.xy / resolution).rgb : vec3(1.0);","vec3 outgoingLight = ((reflectedLight.directDiffuse + reflectedLight.indirectDiffuse)) + reflectedLight.directSpecular + reflectedLight.indirectSpecular;");let g="1.0";this.mask&&(this.mask.analyze(e),g=`luminance(${this.mask.flow(e,"v3").result})`),m.push(` if (outgoingLight != diffuseColor) { float lightAccu = clamp( length( reflectedLight.directSpecular + reflectedLight.indirectSpecular ), 0.0, 1.0 ); accumAlpha += ( 1.0 - accumAlpha ) * ${c.result} * ${g} * lightAccu; outgoingLight = spe_blend( diffuseColor, outgoingLight, ${c.result} * ${g}, ${u.result} ); outgoingLight *= ao; } `),h&&m.push(h.code,`outgoingLight = spe_blend(outgoingLight, ${h.result}, 1.0, SPE_BLENDING_NORMAL);`),d?m.push(`gl_FragColor = vec4( outgoingLight, accumAlpha * ${d.result} );`):m.push("gl_FragColor = vec4( outgoingLight, 1.0 );"),f&&m.push(`gl_FragColor.a *= ${f.result};`),m.push("#include ","#include ","#include "),r=m.join(` `)}return r}};var Tm=class extends or{constructor(){super("toon");this.nodeType="Toon";this.color=new tr(ii),this.specular=new tr(1118481),this.shininess=new Fe(30),this.previousModelViewMatrix=new Ki,this.previouseProjectionMatrix=new Ki,this.shadingAlpha=new Fe(1),this.shadingBlend=new Dt(0)}get category(){return"toon"}build(e){let r;if(e.define("TOON"),e.requires.lights=!0,e.extensions.derivatives=!0,e.isShader("vertex")){let i=this.position?this.position.analyzeAndFlow(e,"v3",{cache:"position"}):void 0;e.mergeUniform({frameIndex:$e.frameIndex}),e.mergeUniform({resolution:$e.resolution}),e.mergeUniform({previousModelViewMatrix:this.previousModelViewMatrix}),e.mergeUniform({previousProjectionMatrix:this.previouseProjectionMatrix}),e.mergeUniform(Ns.merge([Ie.fog,Ie.lights])),e.addParsCode(["varying vec3 vViewPosition;","varying vec3 vWPosition;","#include ","#include ","#include ","#include ","#include ","#include "].join(` `));let s=["#include ","#include ",` #include #include #ifndef USE_LAYER_DISPLACE #include #endif vec3 displaced_position = position; vec3 displaced_normal = objectNormal; #ifdef USE_LAYER_DISPLACE vec3 transformed; vec3 transformedNormal; #endif `,"#include ",` #ifndef USE_LAYER_DISPLACE #include #endif `];i&&s.push(i.code,i.result?"displaced_position = "+i.result+";":""),s.push("transformed = displaced_position;","#include ","#include ","transformedNormal = normalMatrix * displaced_normal;","#ifndef FLAT_SHADED"," vNormal = transformedNormal;","#endif"),s.push(" #include "," #include "," #include "," vViewPosition = - mvPosition.xyz;"," #include "," #include "," #include "),s.push("vWPosition = ( modelMatrix * vec4( transformed, 1.0 ) ).xyz;"),r=s.join(` `)}else{e.mergeUniform({penumbraSize:$e.penumbraSize}),e.mergeUniform({frameIndex:$e.frameIndex}),e.mergeUniform({aoMap:$e.aoRenderTarget}),e.mergeUniform({aoEnabled:$e.aoEnabled}),this.color===void 0&&(this.color=new tr(ii)),this.color.analyze(e,{slot:"color"}),this.specular.analyze(e),this.shininess.analyze(e),this.shadingAlpha.analyze(e),this.shadingBlend.analyze(e),this.afterColor&&this.afterColor.analyze(e,{slot:"afterColor"}),this.alpha&&this.alpha.analyze(e);let i=this.color.flow(e,"c",{slot:"color"}),s=this.specular.flow(e,"c"),o=this.shininess.flow(e,"f"),a=this.shadingAlpha.flow(e,"f"),l=this.shadingBlend.flow(e,"i"),c=this.afterColor?this.afterColor.flow(e,"c",{slot:"afterColor"}):void 0,u=this.alpha?this.alpha.flow(e,"f"):void 0,h=this.alphaOverride?this.alphaOverride.flow(e,"f"):void 0;e.requires.transparent=u!==void 0,e.addParsCode([`uniform float penumbraSize[${5}];`,"uniform sampler2D aoMap;","uniform bool aoEnabled;","varying vec3 vWPosition;","#include ","#include ","#include ","#include ","#include ","#include ",` varying vec3 vViewPosition; struct ToonMaterial { vec3 diffuseColor; vec3 specularColor; float specularShininess; float specularStrength; }; void RE_Direct_Toon( const in IncidentLight directLight, const in GeometricContext geometry, const in ToonMaterial material, inout ReflectedLight reflectedLight ) { vec3 irradiance = getGradientIrradiance( geometry.normal, directLight.direction ) * directLight.color; reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); reflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometry.viewDir, geometry.normal, material.specularColor, material.specularShininess ) * material.specularStrength; } void RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in GeometricContext geometry, const in ToonMaterial material, inout ReflectedLight reflectedLight ) { reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); } #define RE_Direct RE_Direct_Toon #define RE_IndirectDiffuse RE_IndirectDiffuse_Toon #define Material_LightProbeLOD( material ) (0) `,"#include ","#include ","#include "].join(` `));let d=["#include ",` // NOTE: gl_FrontFacing alternative using face normal estimation. vec3 viewdx = dFdx(vViewPosition); vec3 viewdy = dFdy(vViewPosition); vec3 faceNormal = normalize(cross(viewdx,viewdy)); if (dot(normal, faceNormal) < 0.0) { normal *= -1.0; } `," ToonMaterial material;"];if(this.bumpMap){e.include(La.dHdxy),e.include(La.perturbNormalArb);let p=this.bumpMap.texture.flow(e,"t"),m=this.bumpMap.flow(e,"v3"),g=this.bumpMapIntensity?this.bumpMapIntensity.flow(e,"f").result:"1.0",y="";this.bumpMap.projection.value===4?y=` vec3 bumpNormal = vec3(0.0); { vec2 uv0 = g${this.bumpMap.uuid.toString().replace(/-/g,"")}_writeUvs0; vec2 uv1 = g${this.bumpMap.uuid.toString().replace(/-/g,"")}_writeUvs1; vec2 uv2 = g${this.bumpMap.uuid.toString().replace(/-/g,"")}_writeUvs2; vec3 weights = g${this.bumpMap.uuid.toString().replace(/-/g,"")}_triplanarWeights; vec2 grad0 = dHdxy(${p.result}, uv0, ${g}); vec3 n0 = perturbNormalArb(-vViewPosition, normal, grad0, faceDirection); vec2 grad1 = dHdxy(${p.result}, uv1, ${g}); vec3 n1 = perturbNormalArb(-vViewPosition, normal, grad1, faceDirection); vec2 grad2 = dHdxy(${p.result}, uv2, ${g}); vec3 n2 = perturbNormalArb(-vViewPosition, normal, grad2, faceDirection); bumpNormal = n0 * weights.z + n1 * weights.x + n2 * weights.y; bumpNormal = normalize(bumpNormal); } normal = bumpNormal; `:y=` vec2 bumpMapCachedUv = g${this.bumpMap.uuid.toString().replace(/-/g,"")}_writeUvs; vec2 grad = dHdxy(${p.result}, bumpMapCachedUv, ${g}); normal = perturbNormalArb( - vViewPosition, normal, grad, faceDirection ); `,d.push(`// Call the Texture Layer's function once here so that it writes out its procedural UV coordinates ${m.result}; ${y} `)}d.push(i.code," vec3 diffuseColor = "+i.result+";"," ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );",s.code," vec3 specular = "+s.result+";",o.code," float shininess = max( 0.0001, "+o.result+" );"," float specularStrength = 1.0;"),u&&d.push(u.code,"#ifdef ALPHATEST","if ( "+u.result+" <= ALPHATEST ) discard;","#endif"),d.push("material.diffuseColor = diffuseColor;"),d.push("material.specularColor = specular;","material.specularShininess = shininess;","material.specularStrength = specularStrength;","#include ","#include "),d.push("vec3 ao = aoEnabled ? tex2D(aoMap, gl_FragCoord.xy / resolution).rgb : vec3(1.0);","vec3 outgoingLight = ((reflectedLight.directDiffuse + reflectedLight.indirectDiffuse) * ao) + reflectedLight.directSpecular;");let f="1.0";this.mask&&(this.mask.analyze(e),f=`luminance(${this.mask.flow(e,"v3").result})`),d.push(` if (outgoingLight != diffuseColor) { float lightAccu = clamp( length( reflectedLight.directSpecular + reflectedLight.indirectSpecular ), 0.0, 1.0 ); accumAlpha += ( 1.0 - a