UNPKG

@tresjs/post-processing

Version:
527 lines (402 loc) 135 kB
/** * name: @tresjs/post-processing * version: v2.3.1 * (c) 2025 * description: Post-processing library for TresJS * author: Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/) */ (function(d,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("vue"),require("postprocessing"),require("@tresjs/core"),require("three"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","vue","postprocessing","@tresjs/core","three","@vueuse/core"],r):(d=typeof globalThis<"u"?globalThis:d||self,r(d["tres-post-processing"]={},d.Vue,d.Postprocessing,d.TresjsCore,d.Three,d.VueUseCore))})(this,function(d,r,u,x,s,N){"use strict";class z{static isWebGL2Available(){try{const e=document.createElement("canvas");return!!(window.WebGL2RenderingContext&&e.getContext("webgl2"))}catch{return!1}}static isColorSpaceAvailable(e){try{const t=document.createElement("canvas"),o=window.WebGL2RenderingContext&&t.getContext("webgl2");return o.drawingBufferColorSpace=e,o.drawingBufferColorSpace===e}catch{return!1}}static getWebGL2ErrorMessage(){return this.getErrorMessage(2)}static getErrorMessage(e){const t={1:"WebGL",2:"WebGL 2"},o={1:window.WebGLRenderingContext,2:window.WebGL2RenderingContext};let a='Your $0 does not seem to support <a href="http://khronos.org/webgl/wiki/Getting_a_WebGL_Implementation" style="color:#000">$1</a>';const n=document.createElement("div");return n.id="webglmessage",n.style.fontFamily="monospace",n.style.fontSize="13px",n.style.fontWeight="normal",n.style.textAlign="center",n.style.background="#fff",n.style.color="#000",n.style.padding="1.5em",n.style.width="400px",n.style.margin="5em auto 0",o[e]?a=a.replace("$0","graphics card"):a=a.replace("$0","browser"),a=a.replace("$1",t[e]),n.innerHTML=a,n}static isWebGLAvailable(){console.warn("isWebGLAvailable() has been deprecated and will be removed in r178. Use isWebGL2Available() instead.");try{const e=document.createElement("canvas");return!!(window.WebGLRenderingContext&&(e.getContext("webgl")||e.getContext("experimental-webgl")))}catch{return!1}}static getWebGLErrorMessage(){return console.warn("getWebGLErrorMessage() has been deprecated and will be removed in r178. Use getWebGL2ErrorMessage() instead."),this.getErrorMessage(1)}}const R=Symbol("effectComposerPmndrs"),J=r.defineComponent({__name:"EffectComposerPmndrs",props:{enabled:{type:Boolean,default:!0},depthBuffer:{type:Boolean,default:void 0},disableNormalPass:{type:Boolean,default:!1},stencilBuffer:{type:Boolean,default:void 0},resolutionScale:{},autoClear:{type:Boolean,default:!0},multisampling:{default:0},frameBufferType:{default:s.HalfFloatType}},emits:["render"],setup(i,{expose:e,emit:t}){const o=i,a=t,{scene:n,camera:l,renderer:c,sizes:f,render:m}=x.useTresContext(),g=r.shallowRef(null);let b=null,h=null;r.provide(R,g),e({composer:g});const S=()=>{g.value&&(h=new u.NormalPass(n.value,l.value),h.enabled=!1,g.value.addPass(h),o.resolutionScale!==void 0&&z.isWebGL2Available()&&(b=new u.DepthDownsamplingPass({normalBuffer:h.texture,resolutionScale:o.resolutionScale}),b.enabled=!1,g.value.addPass(b)))},y=r.computed(()=>{const w=new u.EffectComposer,P={depthBuffer:o.depthBuffer!==void 0?o.depthBuffer:w.inputBuffer.depthBuffer,stencilBuffer:o.stencilBuffer!==void 0?o.stencilBuffer:w.inputBuffer.stencilBuffer,multisampling:z.isWebGL2Available()?o.multisampling!==void 0?o.multisampling:w.multisampling:0,frameBufferType:o.frameBufferType!==void 0?o.frameBufferType:s.HalfFloatType};return w.dispose(),P}),K=()=>{var w;!c.value&&!n.value&&!l.value||((w=g.value)==null||w.dispose(),g.value=new u.EffectComposer(c.value,y.value),g.value.addPass(new u.RenderPass(n.value,l.value)),o.disableNormalPass||S())};r.watch([c,n,l,()=>o.disableNormalPass],()=>{!f.width.value||!f.height.value||K()}),r.watch(()=>[f.width.value,f.height.value],([w,P])=>{!w&&!P||(g.value?g.value.setSize(w,P):K())},{immediate:!0});const{render:Ye}=x.useLoop();return Ye(()=>{if(o.enabled&&c.value&&g.value&&f.width.value&&f.height.value&&m.frames.value>0){const w=c.value.autoClear;c.value.autoClear=o.autoClear,o.stencilBuffer&&!o.autoClear&&c.value.clearStencil(),g.value.render(),a("render",g.value),c.value.autoClear=w}m.frames.value=m.mode.value==="always"?1:Math.max(0,m.frames.value-1)}),r.onUnmounted(()=>{var w;(w=g.value)==null||w.dispose()}),(w,P)=>r.renderSlot(w.$slots,"default")}}),p=(i,e,t)=>{const o=r.inject(R),a=r.shallowRef(null),n=r.shallowRef(null),{scene:l,camera:c,invalidate:f}=x.useTresContext();r.watch(e,()=>f());const m=()=>{var h,S,y;a.value&&((h=o==null?void 0:o.value)==null||h.removePass(a.value)),(S=n.value)==null||S.dispose(),(y=a.value)==null||y.dispose()},g=h=>{!c.value||!(o!=null&&o.value)||!l.value||(n.value=i(),a.value=new u.EffectPass(c.value,n.value),o.value.addPass(a.value,h))};t&&r.watch(()=>t.map(h=>e[h]),()=>{var S;if(!(o!=null&&o.value))return;const h=(S=o.value)==null?void 0:S.passes.findIndex(y=>y===a.value);~h&&(m(),g(h))}),r.watchEffect(()=>{!c.value||!(n!=null&&n.value)||(n.value.mainCamera=c.value)});const b=r.watchEffect(()=>{!c.value||!(o!=null&&o.value)||!l.value||(r.nextTick(()=>b()),!n.value&&g())});return r.onUnmounted(()=>{m()}),{pass:a,effect:n}},U=/([^[.\]])+/g,Z=(i,e)=>{if(!e)return;const t=Array.isArray(e)?e:e.match(U);return t==null?void 0:t.reduce((o,a)=>o&&o[a],i)},W=(i,e,t)=>{const o=Array.isArray(e)?e:e.match(U);o&&o.reduce((a,n,l)=>(a[n]===void 0&&(a[n]={}),l===o.length-1&&(a[n]=t),a[n]),i)},_=(i,e)=>{const t={...i};return e.forEach(o=>delete t[o]),t},E=(i,e,t,o,a={})=>r.watch(i,n=>{var l;if(e.value)if(n===void 0){const c=o();W(e.value,t,Z(c,t)),(l=c.dispose)==null||l.call(c)}else W(e.value,t,i())},a),v=(i,e,t)=>i.map(([o,a])=>E(o,e,a,t)),O=(i,e,t)=>Object.keys(i).map(o=>E(()=>i[o],e,o,t)),$=r.defineComponent({__name:"BloomPmndrs",props:{blendFunction:{},intensity:{},kernelSize:{},luminanceThreshold:{},luminanceSmoothing:{},mipmapBlur:{type:Boolean,default:void 0}},setup(i,{expose:e}){const t=i,{pass:o,effect:a}=p(()=>new u.BloomEffect(t),t,["mipmapBlur"]);return e({pass:o,effect:a}),v([[()=>t.blendFunction,"blendMode.blendFunction"],[()=>t.intensity,"intensity"],[()=>t.kernelSize,"kernelSize"],[()=>t.luminanceSmoothing,"luminanceMaterial.smoothing"],[()=>t.luminanceThreshold,"luminanceMaterial.threshold"]],a,()=>new u.BloomEffect),()=>{}}}),ee=r.defineComponent({__name:"DepthOfFieldPmndrs",props:{blendFunction:{},worldFocusDistance:{},worldFocusRange:{},focusDistance:{},focusRange:{},bokehScale:{},resolutionScale:{},resolutionX:{},resolutionY:{}},setup(i,{expose:e}){const t=i,{camera:o}=x.useTresContext(),{pass:a,effect:n}=p(()=>new u.DepthOfFieldEffect(o.value,t),t);return e({pass:a,effect:n}),v([[()=>t.blendFunction,"blendMode.blendFunction"],[()=>t.worldFocusDistance,"circleOfConfusionMaterial.worldFocusDistance"],[()=>t.focusDistance,"circleOfConfusionMaterial.focusDistance"],[()=>t.worldFocusRange,"circleOfConfusionMaterial.worldFocusRange"],[()=>t.focusRange,"circleOfConfusionMaterial.focusRange"],[()=>t.bokehScale,"bokehScale"],[()=>t.resolutionScale,"blurPass.resolution.scale"],[()=>t.resolutionX,"resolution.width"],[()=>t.resolutionY,"resolution.height"]],n,()=>new u.DepthOfFieldEffect),()=>{}}}),te=r.defineComponent({__name:"GlitchPmndrs",props:{blendFunction:{},delay:{},duration:{},strength:{},mode:{},active:{type:Boolean},ratio:{},columns:{},chromaticAberrationOffset:{},perturbationMap:{},dtSize:{}},setup(i,{expose:e}){const t=i,{pass:o,effect:a}=p(()=>new u.GlitchEffect(t),t,["dtSize"]);e({pass:o,effect:a});const{onBeforeRender:n}=x.useLoop();return n(({invalidate:l})=>l()),r.watchEffect(()=>{const l=()=>{if(t.mode!==void 0)return t.active===!1?u.GlitchMode.DISABLED:t.mode;const c=new u.GlitchEffect,f=c.mode;return c.dispose(),f};a.value&&(a.value.mode=l())}),E(()=>t.blendFunction,a,"blendMode.blendFunction",()=>new u.GlitchEffect),O(_(t,["active","blendFunction"]),a,()=>new u.GlitchEffect),()=>{}}}),oe=r.defineComponent({__name:"NoisePmndrs",props:{premultiply:{type:Boolean,default:void 0},blendFunction:{}},setup(i,{expose:e}){const t=i,{pass:o,effect:a}=p(()=>new u.NoiseEffect(t),t);e({pass:o,effect:a});const{onBeforeRender:n}=x.useLoop();return n(({invalidate:l})=>l()),v([[()=>t.blendFunction,"blendMode.blendFunction"],[()=>t.premultiply,"premultiply"]],a,()=>new u.NoiseEffect),()=>{}}}),ae=r.defineComponent({__name:"OutlinePmndrs",props:{outlinedObjects:{},blur:{type:Boolean,default:void 0},xRay:{type:Boolean,default:void 0},kernelSize:{},pulseSpeed:{},resolutionX:{},resolutionY:{},edgeStrength:{},patternScale:{},multisampling:{},blendFunction:{},patternTexture:{},resolutionScale:{},hiddenEdgeColor:{},visibleEdgeColor:{}},setup(i,{expose:e}){const t=i,o=m=>m!==void 0?x.normalizeColor(m).getHex():void 0,{camera:a,scene:n}=x.useTresContext(),{pass:l,effect:c}=p(()=>new u.OutlineEffect(n.value,a.value,{blur:t.blur,xRay:t.xRay,kernelSize:t.kernelSize,pulseSpeed:t.pulseSpeed,resolutionX:t.resolutionX,resolutionY:t.resolutionY,patternScale:t.patternScale,edgeStrength:t.edgeStrength,blendFunction:t.blendFunction,multisampling:t.multisampling,patternTexture:t.patternTexture,resolutionScale:t.resolutionScale,hiddenEdgeColor:o(t.hiddenEdgeColor),visibleEdgeColor:o(t.visibleEdgeColor)}),t);e({pass:l,effect:c}),r.watch([()=>t.outlinedObjects,c],()=>{var m;(m=c.value)==null||m.selection.set(t.outlinedObjects||[])},{immediate:!0});const f=r.computed(()=>({hiddenEdgeColor:t.hiddenEdgeColor?x.normalizeColor(t.hiddenEdgeColor):void 0,visibleEdgeColor:t.visibleEdgeColor?x.normalizeColor(t.visibleEdgeColor):void 0}));return v([[()=>t.blendFunction,"blendMode.blendFunction"],[()=>t.blur,"blur"],[()=>t.xRay,"xRay"],[()=>t.pulseSpeed,"pulseSpeed"],[()=>t.kernelSize,"kernelSize"],[()=>t.edgeStrength,"edgeStrength"],[()=>t.patternScale,"patternScale"],[()=>t.multisampling,"multisampling"],[()=>t.resolutionX,"resolution.width"],[()=>t.resolutionY,"resolution.height"],[()=>t.patternTexture,"patternTexture"],[()=>t.resolutionScale,"resolution.scale"],[()=>f.value.hiddenEdgeColor,"hiddenEdgeColor"],[()=>f.value.visibleEdgeColor,"visibleEdgeColor"]],c,()=>new u.OutlineEffect),()=>{}}}),ne=r.defineComponent({__name:"PixelationPmndrs",props:{granularity:{}},setup(i,{expose:e}){const t=i,{pass:o,effect:a}=p(()=>new u.PixelationEffect(t.granularity),t);return e({pass:o,effect:a}),O(t,a,()=>new u.PixelationEffect),()=>{}}}),se=r.defineComponent({__name:"VignettePmndrs",props:{technique:{},blendFunction:{},offset:{},darkness:{}},setup(i,{expose:e}){const t=i,{pass:o,effect:a}=p(()=>new u.VignetteEffect(t),t);return e({pass:o,effect:a}),v([[()=>t.blendFunction,"blendMode.blendFunction"],[()=>t.offset,"offset"],[()=>t.darkness,"darkness"],[()=>t.technique,"technique"]],a,()=>new u.VignetteEffect),()=>{}}});class G extends u.Effect{constructor({blendFunction:e=u.BlendFunction.NORMAL,amount:t=.15,offset:o=new s.Vector2(.5,.5)}={}){super("BarrelBlurEffect",` uniform float amount; uniform vec2 offset; #define NUM_ITER 16 #define RECIP_NUM_ITER 0.0625 #define GAMMA 1.0 vec3 spectrum_offset(float t) { float lo = step(t, 0.5); float hi = 1.0 - lo; float w = 1.0 - abs(2.0 * t - 1.0); return pow(vec3(lo, 1.0, hi) * vec3(1.0 - w, w, 1.0 - w), vec3(1.0 / GAMMA)); } vec2 barrelDistortion(vec2 p, float amt) { p = p - offset; float theta = atan(p.y, p.x); float radius = pow(length(p), 1.0 + 3.0 * amt); return vec2(cos(theta), sin(theta)) * radius + offset; } void mainUv(inout vec2 uv) { uv = barrelDistortion(uv, amount * 0.5); } void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) { vec3 sumcol = vec3(0.0); vec3 sumw = vec3(0.0); for (int i = 0; i < NUM_ITER; ++i) { float t = float(i) * RECIP_NUM_ITER; vec3 w = spectrum_offset(t); vec2 distortedUV = barrelDistortion(uv, amount * t); sumcol += w * texture(inputBuffer, distortedUV).rgb; sumw += w; } vec3 outcol = pow(sumcol / sumw, vec3(1.0 / GAMMA)); outcol = clamp(outcol, 0.0, 1.0); // Ensures normalized color values outputColor = vec4(outcol, inputColor.a); // Preserves original alpha } `,{blendFunction:e,uniforms:new Map([["amount",new s.Uniform(t)],["offset",new s.Uniform(o)]])})}get amount(){var e;return(e=this.uniforms.get("amount"))==null?void 0:e.value}set amount(e){this.uniforms.get("amount").value=e}get offset(){var e;return(e=this.uniforms.get("offset"))==null?void 0:e.value}set offset(e){this.uniforms.get("offset").value=e}}const ie=r.defineComponent({__name:"BarrelBlurPmndrs",props:{blendFunction:{},amount:{},offset:{}},setup(i,{expose:e}){const t=i,{pass:o,effect:a}=p(()=>new G({...t,offset:Array.isArray(t.offset)?new s.Vector2(...t.offset):t.offset}),t);return e({pass:o,effect:a}),v([[()=>t.blendFunction,"blendMode.blendFunction"],[()=>t.amount,"amount"],[()=>t.offset,"offset"]],a,()=>new G),()=>{}}}),re=r.defineComponent({__name:"ToneMappingPmndrs",props:{mode:{},blendFunction:{},resolution:{},averageLuminance:{},middleGrey:{},minLuminance:{},whitePoint:{}},setup(i,{expose:e}){const t=i,{pass:o,effect:a}=p(()=>new u.ToneMappingEffect(t),t);return e({pass:o,effect:a}),v([[()=>t.mode,"mode"],[()=>t.blendFunction,"blendMode.blendFunction"],[()=>t.resolution,"resolution"],[()=>t.averageLuminance,"averageLuminance"],[()=>t.middleGrey,"middleGrey"],[()=>t.minLuminance,"adaptiveLuminanceMaterial.minLuminance"],[()=>t.whitePoint,"whitePoint"]],a,()=>new u.ToneMappingEffect),()=>{}}}),le=r.defineComponent({__name:"ChromaticAberrationPmndrs",props:{blendFunction:{},offset:{},radialModulation:{type:Boolean,default:void 0},modulationOffset:{}},setup(i,{expose:e}){const t=i,o=new u.ChromaticAberrationEffect,{pass:a,effect:n}=p(()=>new u.ChromaticAberrationEffect({...t,radialModulation:t.radialModulation??o.radialModulation,modulationOffset:t.modulationOffset??o.modulationOffset}),t);return o.dispose(),e({pass:a,effect:n}),v([[()=>t.blendFunction,"blendMode.blendFunction"],[()=>t.offset,"offset"],[()=>t.radialModulation,"radialModulation"],[()=>t.modulationOffset,"modulationOffset"]],n,()=>new u.ChromaticAberrationEffect),()=>{}}}),ce=r.defineComponent({__name:"HueSaturationPmndrs",props:{saturation:{},hue:{},blendFunction:{}},setup(i,{expose:e}){const t=i,{pass:o,effect:a}=p(()=>new u.HueSaturationEffect(t),t);return e({pass:o,effect:a}),v([[()=>t.blendFunction,"blendMode.blendFunction"],[()=>t.hue,"hue"],[()=>t.saturation,"saturation"]],a,()=>new u.HueSaturationEffect),()=>{}}}),ue=r.defineComponent({__name:"ScanlinePmndrs",props:{blendFunction:{},density:{},scrollSpeed:{},opacity:{}},setup(i,{expose:e}){const t=i,{pass:o,effect:a}=p(()=>new u.ScanlineEffect(t),t);return e({pass:o,effect:a}),v([[()=>t.blendFunction,"blendMode.blendFunction"],[()=>t.density,"density"],[()=>t.scrollSpeed,"scrollSpeed"]],a,()=>new u.ScanlineEffect),r.watch([()=>t.opacity],()=>{var n,l;if(t.opacity!==void 0)(n=a.value)==null||n.blendMode.setOpacity(t.opacity);else{const c=new u.ScanlineEffect;(l=a.value)==null||l.blendMode.setOpacity(c.blendMode.getOpacity()),c.dispose()}},{immediate:!0}),()=>{}}}),de=` uniform float radius; uniform int sectorCount; const int MAX_SECTOR_COUNT = 8; float polynomialWeight(float x, float y, float eta, float lambda) { float polyValue = (x + eta) - lambda * (y * y); return max(0.0, polyValue * polyValue); } void getSectorVarianceAndAverageColor(mat2 anisotropyMat, float angle, float radius, out vec3 avgColor, out float variance) { vec3 weightedColorSum = vec3(0.0); vec3 weightedSquaredColorSum = vec3(0.0); float totalWeight = 0.0; float eta = 0.1; float lambda = 0.5; float angleStep = 0.196349; // Precompute angle step float halfAngleRange = 0.392699; // Precompute half angle range float cosAngle = cos(angle); float sinAngle = sin(angle); for (float r = 1.0; r <= radius; r += 1.0) { float rCosAngle = r * cosAngle; float rSinAngle = r * sinAngle; for (float a = -halfAngleRange; a <= halfAngleRange; a += angleStep) { float cosA = cos(a); float sinA = sin(a); vec2 sampleOffset = vec2(rCosAngle * cosA - rSinAngle * sinA, rCosAngle * sinA + rSinAngle * cosA) / resolution; sampleOffset *= anisotropyMat; vec3 color = texture2D(inputBuffer, vUv + sampleOffset).rgb; float weight = polynomialWeight(sampleOffset.x, sampleOffset.y, eta, lambda); weightedColorSum += color * weight; weightedSquaredColorSum += color * color * weight; totalWeight += weight; } } // Calculate average color and variance avgColor = weightedColorSum / totalWeight; vec3 varianceRes = (weightedSquaredColorSum / totalWeight) - (avgColor * avgColor); variance = dot(varianceRes, vec3(0.299, 0.587, 0.114)); // Convert to luminance } vec4 getDominantOrientation(vec4 structureTensor) { float Jxx = structureTensor.r; float Jyy = structureTensor.g; float Jxy = structureTensor.b; float trace = Jxx + Jyy; float det = Jxx * Jyy - Jxy * Jxy; float lambda1 = 0.5 * (trace + sqrt(trace * trace - 4.0 * det)); float lambda2 = 0.5 * (trace - sqrt(trace * trace - 4.0 * det)); float dominantOrientation = atan(2.0 * Jxy, Jxx - Jyy) / 2.0; return vec4(dominantOrientation, lambda1, lambda2, 0.0); } void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) { vec4 structureTensor = texture2D(inputBuffer, uv); vec3 sectorAvgColors[MAX_SECTOR_COUNT]; float sectorVariances[MAX_SECTOR_COUNT]; vec4 orientationAndAnisotropy = getDominantOrientation(structureTensor); vec2 orientation = orientationAndAnisotropy.xy; float anisotropy = (orientationAndAnisotropy.z - orientationAndAnisotropy.w) / (orientationAndAnisotropy.z + orientationAndAnisotropy.w + 1e-7); float alpha = 25.0; float scaleX = alpha / (anisotropy + alpha); float scaleY = (anisotropy + alpha) / alpha; mat2 anisotropyMat = mat2(orientation.x, -orientation.y, orientation.y, orientation.x) * mat2(scaleX, 0.0, 0.0, scaleY); for (int i = 0; i < sectorCount; i++) { float angle = float(i) * 6.28318 / float(sectorCount); // 2π / sectorCount getSectorVarianceAndAverageColor(anisotropyMat, angle, float(radius), sectorAvgColors[i], sectorVariances[i]); } float minVariance = sectorVariances[0]; vec3 finalColor = sectorAvgColors[0]; for (int i = 1; i < sectorCount; i++) { if (sectorVariances[i] < minVariance) { minVariance = sectorVariances[i]; finalColor = sectorAvgColors[i]; } } outputColor = vec4(finalColor, inputColor.a); } `;class H extends u.Effect{constructor({blendFunction:e=u.BlendFunction.NORMAL,radius:t=1,sectorCount:o=4}={}){super("KuwaharaEffect",de,{blendFunction:e,uniforms:new Map([["radius",new s.Uniform(t)],["sectorCount",new s.Uniform(o)]])})}get radius(){var e;return(e=this.uniforms.get("radius"))==null?void 0:e.value}set radius(e){this.uniforms.get("radius").value=e}get sectorCount(){var e;return(e=this.uniforms.get("sectorCount"))==null?void 0:e.value}set sectorCount(e){this.uniforms.get("sectorCount").value=e}}const fe=r.defineComponent({__name:"KuwaharaPmndrs",props:{blendFunction:{},radius:{},sectorCount:{}},setup(i,{expose:e}){const t=i,{pass:o,effect:a}=p(()=>new H(t),t);return e({pass:o,effect:a}),v([[()=>t.blendFunction,"blendMode.blendFunction"],[()=>t.radius,"radius"],[()=>t.sectorCount,"sectorCount"]],a,()=>new H),()=>{}}}),he=r.defineComponent({__name:"ColorAveragePmndrs",props:{blendFunction:{},opacity:{}},setup(i,{expose:e}){const t=i,{pass:o,effect:a}=p(()=>new u.ColorAverageEffect(t.blendFunction),t);return e({pass:o,effect:a}),E(()=>t.blendFunction,a,"blendMode.blendFunction",()=>new u.ColorAverageEffect),r.watch([a,()=>t.opacity],()=>{var n,l;if(a.value)if(t.opacity!==void 0)(n=a.value)==null||n.blendMode.setOpacity(t.opacity);else{const c=new u.ColorAverageEffect;(l=a.value)==null||l.blendMode.setOpacity(c.blendMode.getOpacity()),c.dispose()}}),()=>{}}}),me=r.defineComponent({__name:"LensDistortionPmndrs",props:{distortion:{},principalPoint:{},focalLength:{},skew:{}},setup(i,{expose:e}){const t=i,{pass:o,effect:a}=p(()=>new u.LensDistortionEffect({...t,distortion:t.distortion?Array.isArray(t.distortion)?new s.Vector2(...t.distortion):t.distortion:new s.Vector2,principalPoint:t.principalPoint?Array.isArray(t.principalPoint)?new s.Vector2(...t.principalPoint):t.principalPoint:new s.Vector2,focalLength:t.focalLength?Array.isArray(t.focalLength)?new s.Vector2(...t.focalLength):t.focalLength:new s.Vector2}),t);return e({pass:o,effect:a}),O(t,a,()=>new u.LensDistortionEffect),()=>{}}}),pe=r.defineComponent({__name:"ShockWavePmndrs",props:{position:{},amplitude:{},speed:{},maxRadius:{},waveSize:{}},setup(i,{expose:e}){const t=i,{camera:o}=x.useTresContext(),{pass:a,effect:n}=p(()=>new u.ShockWaveEffect(o.value,Array.isArray(t.position)?new s.Vector3(...t.position):t.position,t),t);return e({pass:a,effect:n}),r.watch(()=>t.position,l=>{n.value&&(Array.isArray(l)?n.value.position.set(...l):l instanceof s.Vector3&&n.value.position.copy(l))},{immediate:!0}),v([[()=>t.amplitude,"amplitude"],[()=>t.waveSize,"waveSize"],[()=>t.maxRadius,"maxRadius"],[()=>t.speed,"speed"]],n,()=>new u.ShockWaveEffect),()=>{}}}),ge=r.defineComponent({__name:"TiltShiftPmndrs",props:{blendFunction:{},offset:{},rotation:{},focusArea:{},feather:{},kernelSize:{},resolutionScale:{},resolutionX:{},resolutionY:{}},setup(i,{expose:e}){const t=i,{pass:o,effect:a}=p(()=>new u.TiltShiftEffect(t),t);return e({pass:o,effect:a}),v([[()=>t.blendFunction,"blendMode.blendFunction"],[()=>t.offset,"offset"],[()=>t.rotation,"rotation"],[()=>t.focusArea,"focusArea"],[()=>t.feather,"feather"],[()=>t.kernelSize,"kernelSize"],[()=>t.resolutionScale,"resolution.scale"],[()=>t.resolutionX,"resolution.width"],[()=>t.resolutionY,"resolution.height"]],a,()=>new u.TiltShiftEffect),()=>{}}}),ve=r.defineComponent({__name:"DotScreenPmndrs",props:{angle:{},scale:{},blendFunction:{}},setup(i,{expose:e}){const t=i,{pass:o,effect:a}=p(()=>new u.DotScreenEffect(t),t);return e({pass:o,effect:a}),v([[()=>t.blendFunction,"blendMode.blendFunction"],[()=>t.angle,"angle"],[()=>t.scale,"scale"]],a,()=>new u.DotScreenEffect),()=>{}}}),xe=r.defineComponent({__name:"SepiaPmndrs",props:{blendFunction:{},intensity:{}},setup(i,{expose:e}){const t=i,{pass:o,effect:a}=p(()=>new u.SepiaEffect(t),t);return e({pass:o,effect:a}),v([[()=>t.blendFunction,"blendMode.blendFunction"],[()=>t.intensity,"intensity"]],a,()=>new u.SepiaEffect),()=>{}}});class V extends u.Effect{constructor({blendFunction:e=u.BlendFunction.NORMAL,scale:t=.85,noiseScale:o=0,center:a=[.5,.5],rotation:n=0}={}){const l=Array.isArray(a)?new s.Vector2().fromArray(a):a;super("LinocutEffect",` uniform float scale; uniform float noiseScale; uniform vec2 center; uniform float rotation; float luma(vec3 color) { return dot(color, vec3(0.299, 0.587, 0.114)); } float luma(vec4 color) { return dot(color.rgb, vec3(0.299, 0.587, 0.114)); } // Simple pseudo-random noise function float noise(vec2 p) { return fract(sin(dot(p, vec2(12.9898, 78.233))) * 43758.5453123); } void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) { // Calculate the center based on center vec2 fragCoord = uv * resolution.xy; // Apply rotation to the coordinates vec2 d = fragCoord - center * resolution.xy; mat2 rotMat = mat2(cos(rotation), -sin(rotation), sin(rotation), cos(rotation)); vec2 rotatedD = d * rotMat; // Calculate radial distance and angle float r = length(rotatedD) / (1000.0 / max(scale, 0.01)); // Normalization to avoid artifacts float a = atan(rotatedD.y, rotatedD.x) + scale * (0.5 - r) / 0.5; // Calculate transformed coordinates vec2 uvt = center * resolution.xy + r * vec2(cos(a), sin(a)); // Normalize UV coordinates vec2 uv2 = fragCoord / resolution.xy; // Generate sinusoidal line patterns float c = (0.75 + 0.25 * sin(uvt.x * 1000.0 * max(scale, 0.01))); // Prevent excessive distortions // Load the texture and convert to grayscale vec4 color = texture(inputBuffer, uv2); color.rgb = color.rgb * color.rgb; // Convert from sRGB to linear float l = luma(color); // Add noise based on noiseScale float n = noise(uv2 * 10.0); // Generate noise l += noiseScale * (n - 0.5); // Apply noise as a perturbation // Apply smoothing to achieve the linocut effect float f = smoothstep(0.5 * c, c, l); f = smoothstep(0.0, 0.5, f); // Convert the final value back to sRGB f = sqrt(f); // Output the final color in black and white outputColor = vec4(vec3(f), 1.0); } `,{blendFunction:e,uniforms:new Map([["scale",new s.Uniform(t)],["noiseScale",new s.Uniform(o)],["center",new s.Uniform(l)],["rotation",new s.Uniform(n)]])})}get scale(){var e;return(e=this.uniforms.get("scale"))==null?void 0:e.value}set scale(e){this.uniforms.get("scale").value=e}get noiseScale(){var e;return(e=this.uniforms.get("noiseScale"))==null?void 0:e.value}set noiseScale(e){this.uniforms.get("noiseScale").value=e}get center(){var e;return(e=this.uniforms.get("center"))==null?void 0:e.value}set center(e){this.uniforms.get("center").value=Array.isArray(e)?new s.Vector2().fromArray(e):e}get rotation(){var e;return(e=this.uniforms.get("rotation"))==null?void 0:e.value}set rotation(e){this.uniforms.get("rotation").value=e}}const be=r.defineComponent({__name:"LinocutPmndrs",props:{blendFunction:{},scale:{},noiseScale:{},center:{},rotation:{}},setup(i,{expose:e}){const t=i,{pass:o,effect:a}=p(()=>new V({...t,center:t.center instanceof s.Vector2?[t.center.x,t.center.y]:t.center}),t);return e({pass:o,effect:a}),v([[()=>t.blendFunction,"blendMode.blendFunction"],[()=>t.scale,"scale"],[()=>t.noiseScale,"noiseScale"],[()=>t.center,"center"],[()=>t.rotation,"rotation"]],a,()=>new V),()=>{}}}),we=r.defineComponent({__name:"DepthPickingPassPmndrs",props:{depthPacking:{},mode:{}},setup(i,{expose:e}){const t=i,o=r.inject(R),a=new u.DepthPickingPass(t),n=r.watchEffect(()=>{o!=null&&o.value&&(r.nextTick(()=>n()),o.value.addPass(a))});return r.onUnmounted(()=>{var l;!(o!=null&&o.value)||!a||((l=o==null?void 0:o.value)==null||l.removePass(a),a.dispose())}),e({pass:a}),()=>{}}}),Se=r.defineComponent({__name:"GodRaysPmndrs",props:{blendFunction:{},lightSource:{},opacity:{},density:{},decay:{},kernelSize:{},resolutionScale:{},blur:{type:Boolean},resolutionX:{},resolutionY:{},weight:{},exposure:{},samples:{},clampMax:{}},setup(i,{expose:e}){const t=i,{camera:o}=x.useTresContext(),a=r.computed(()=>t.lightSource??new s.Mesh(new s.SphereGeometry(1e-5),new s.MeshBasicMaterial({visible:!1}))),{pass:n,effect:l}=p(()=>new u.GodRaysEffect(o.value,a.value,t),t);return e({pass:n,effect:l}),v([[()=>t.blendFunction,"blendMode.blendFunction"],[()=>t.density,"godRaysMaterial.density"],[()=>t.decay,"godRaysMaterial.decay"],[()=>t.weight,"godRaysMaterial.weight"],[()=>t.exposure,"godRaysMaterial.exposure"],[()=>t.samples,"godRaysMaterial.samples"],[()=>t.clampMax,"godRaysMaterial.maxIntensity"],[()=>t.resolutionScale,"resolution.scale"],[()=>t.resolutionX,"resolution.width"],[()=>t.resolutionY,"resolution.height"],[()=>t.kernelSize,"blurPass.kernelSize"],[()=>t.blur,"blurPass.enabled"]],l,()=>new u.GodRaysEffect),r.watch([()=>t.lightSource,l],()=>{l.value&&(l.value.lightSource=r.toRaw(a.value))},{immediate:!0}),r.watch([()=>t.opacity],()=>{var c,f;if(t.opacity!==void 0)(c=l.value)==null||c.blendMode.setOpacity(t.opacity);else{const m=new u.GodRaysEffect(o.value,r.toRaw(a.value));(f=l.value)==null||f.blendMode.setOpacity(m.blendMode.getOpacity()),m.dispose()}},{immediate:!0}),()=>{}}}),Ae=r.defineComponent({__name:"ColorDepthPmndrs",props:{blendFunction:{},bits:{},opacity:{}},setup(i,{expose:e}){const t=i,{pass:o,effect:a}=p(()=>new u.ColorDepthEffect(t),t);return e({pass:o,effect:a}),E(()=>t.blendFunction,a,"blendMode.blendFunction",()=>new u.ColorDepthEffect),r.watch([a,()=>t.bits],()=>{var n,l;if(a.value)if(t.bits!==void 0)(n=a.value)==null||n.setBitDepth(t.bits);else{const c=new u.ColorDepthEffect;(l=a.value)==null||l.setBitDepth(c.getBitDepth()),c.dispose()}}),r.watch([a,()=>t.opacity],()=>{var n,l;if(a.value)if(t.opacity!==void 0)(n=a.value)==null||n.blendMode.setOpacity(t.opacity);else{const c=new u.ColorDepthEffect;(l=a.value)==null||l.blendMode.setOpacity(c.blendMode.getOpacity()),c.dispose()}}),()=>{}}}),ye=r.defineComponent({__name:"GridPmndrs",props:{blendFunction:{},scale:{},lineWidth:{}},setup(i,{expose:e}){const t=i,{pass:o,effect:a}=p(()=>new u.GridEffect(t),t);return e({pass:o,effect:a}),v([[()=>t.blendFunction,"blendMode.blendFunction"],[()=>t.scale,"scale"],[()=>t.lineWidth,"lineWidth"]],a,()=>new u.GridEffect),()=>{}}});class X extends u.Effect{constructor({blendFunction:e=u.BlendFunction.NORMAL,lensS:t=new s.Vector2(1,1),lensF:o=new s.Vector2(0,1),scale:a=1}={}){super("FishEyeEffect",` uniform vec2 lensS; uniform vec2 lensF; uniform float scale; void mainUv(inout vec2 uv) { vec2 newUv = uv * 2.0 - 1.0; newUv.x = newUv.x + ((pow(newUv.y, 2.0) / scale) * newUv.x / scale) * -lensF.x; newUv.y = newUv.y + ((pow(newUv.x, 2.0) / scale) * newUv.y / scale) * -lensF.y; newUv = newUv * lensS; newUv = newUv / scale * 0.5 + 0.5; uv = newUv; } void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) { outputColor = vec4(inputColor.rgb, inputColor.a); // Preserves original alpha } `,{blendFunction:e,uniforms:new Map([["lensS",new s.Uniform(t)],["lensF",new s.Uniform(o)],["scale",new s.Uniform(a)]])})}get lensS(){var e;return(e=this.uniforms.get("lensS"))==null?void 0:e.value}set lensS(e){this.uniforms.get("lensS").value=e}get lensF(){var e;return(e=this.uniforms.get("lensF"))==null?void 0:e.value}set lensF(e){this.uniforms.get("lensF").value=e}get scale(){var e;return(e=this.uniforms.get("scale"))==null?void 0:e.value}set scale(e){this.uniforms.get("scale").value=e}}const Me=r.defineComponent({__name:"FishEyePmndrs",props:{blendFunction:{},lensS:{},lensF:{},scale:{}},setup(i,{expose:e}){const t=i,o=r.computed(()=>Array.isArray(t.lensS)?new s.Vector2(...t.lensS):t.lensS),a=r.computed(()=>Array.isArray(t.lensF)?new s.Vector2(...t.lensF):t.lensF),{pass:n,effect:l}=p(()=>new X({...t,lensS:o.value,lensF:a.value}),t);return e({pass:n,effect:l}),v([[()=>t.blendFunction,"blendMode.blendFunction"],[()=>o.value,"lensS"],[()=>a.value,"lensF"],[()=>t.scale,"scale"]],l,()=>new X),()=>{}}}),Te=r.defineComponent({__name:"BrightnessContrastPmndrs",props:{blendFunction:{},brightness:{},contrast:{}},setup(i,{expose:e}){const t=i,{pass:o,effect:a}=p(()=>new u.BrightnessContrastEffect(t),t);return e({pass:o,effect:a}),v([[()=>t.blendFunction,"blendMode.blendFunction"],[()=>t.brightness,"brightness"],[()=>t.contrast,"contrast"]],a,()=>new u.BrightnessContrastEffect),()=>{}}}),I={name:"CopyShader",uniforms:{tDiffuse:{value:null},opacity:{value:1}},vertexShader:` varying vec2 vUv; void main() { vUv = uv; gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); }`,fragmentShader:` uniform float opacity; uniform sampler2D tDiffuse; varying vec2 vUv; void main() { vec4 texel = texture2D( tDiffuse, vUv ); gl_FragColor = opacity * texel; }`};class A{constructor(){this.isPass=!0,this.enabled=!0,this.needsSwap=!0,this.clear=!1,this.renderToScreen=!1}setSize(){}render(){console.error("THREE.Pass: .render() must be implemented in derived pass.")}dispose(){}}const Ce=new s.OrthographicCamera(-1,1,1,-1,0,1);class Ee extends s.BufferGeometry{constructor(){super(),this.setAttribute("position",new s.Float32BufferAttribute([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new s.Float32BufferAttribute([0,2,0,0,2,0],2))}}const Pe=new Ee;class M{constructor(e){this._mesh=new s.Mesh(Pe,e)}dispose(){this._mesh.geometry.dispose()}render(e){e.render(this._mesh,Ce)}get material(){return this._mesh.material}set material(e){this._mesh.material=e}}class De extends A{constructor(e,t){super(),this.textureID=t!==void 0?t:"tDiffuse",e instanceof s.ShaderMaterial?(this.uniforms=e.uniforms,this.material=e):e&&(this.uniforms=s.UniformsUtils.clone(e.uniforms),this.material=new s.ShaderMaterial({name:e.name!==void 0?e.name:"unspecified",defines:Object.assign({},e.defines),uniforms:this.uniforms,vertexShader:e.vertexShader,fragmentShader:e.fragmentShader})),this.fsQuad=new M(this.material)}render(e,t,o){this.uniforms[this.textureID]&&(this.uniforms[this.textureID].value=o.texture),this.fsQuad.material=this.material,this.renderToScreen?(e.setRenderTarget(null),this.fsQuad.render(e)):(e.setRenderTarget(t),this.clear&&e.clear(e.autoClearColor,e.autoClearDepth,e.autoClearStencil),this.fsQuad.render(e))}dispose(){this.material.dispose(),this.fsQuad.dispose()}}class j extends A{constructor(e,t){super(),this.scene=e,this.camera=t,this.clear=!0,this.needsSwap=!1,this.inverse=!1}render(e,t,o){const a=e.getContext(),n=e.state;n.buffers.color.setMask(!1),n.buffers.depth.setMask(!1),n.buffers.color.setLocked(!0),n.buffers.depth.setLocked(!0);let l,c;this.inverse?(l=0,c=1):(l=1,c=0),n.buffers.stencil.setTest(!0),n.buffers.stencil.setOp(a.REPLACE,a.REPLACE,a.REPLACE),n.buffers.stencil.setFunc(a.ALWAYS,l,4294967295),n.buffers.stencil.setClear(c),n.buffers.stencil.setLocked(!0),e.setRenderTarget(o),this.clear&&e.clear(),e.render(this.scene,this.camera),e.setRenderTarget(t),this.clear&&e.clear(),e.render(this.scene,this.camera),n.buffers.color.setLocked(!1),n.buffers.depth.setLocked(!1),n.buffers.color.setMask(!0),n.buffers.depth.setMask(!0),n.buffers.stencil.setLocked(!1),n.buffers.stencil.setFunc(a.EQUAL,1,4294967295),n.buffers.stencil.setOp(a.KEEP,a.KEEP,a.KEEP),n.buffers.stencil.setLocked(!0)}}class Le extends A{constructor(){super(),this.needsSwap=!1}render(e){e.state.buffers.stencil.setLocked(!1),e.state.buffers.stencil.setTest(!1)}}class Fe{constructor(e,t){if(this.renderer=e,this._pixelRatio=e.getPixelRatio(),t===void 0){const o=e.getSize(new s.Vector2);this._width=o.width,this._height=o.height,t=new s.WebGLRenderTarget(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:s.HalfFloatType}),t.texture.name="EffectComposer.rt1"}else this._width=t.width,this._height=t.height;this.renderTarget1=t,this.renderTarget2=t.clone(),this.renderTarget2.texture.name="EffectComposer.rt2",this.writeBuffer=this.renderTarget1,this.readBuffer=this.renderTarget2,this.renderToScreen=!0,this.passes=[],this.copyPass=new De(I),this.copyPass.material.blending=s.NoBlending,this.clock=new s.Clock}swapBuffers(){const e=this.readBuffer;this.readBuffer=this.writeBuffer,this.writeBuffer=e}addPass(e){this.passes.push(e),e.setSize(this._width*this._pixelRatio,this._height*this._pixelRatio)}insertPass(e,t){this.passes.splice(t,0,e),e.setSize(this._width*this._pixelRatio,this._height*this._pixelRatio)}removePass(e){const t=this.passes.indexOf(e);t!==-1&&this.passes.splice(t,1)}isLastEnabledPass(e){for(let t=e+1;t<this.passes.length;t++)if(this.passes[t].enabled)return!1;return!0}render(e){e===void 0&&(e=this.clock.getDelta());const t=this.renderer.getRenderTarget();let o=!1;for(let a=0,n=this.passes.length;a<n;a++){const l=this.passes[a];if(l.enabled!==!1){if(l.renderToScreen=this.renderToScreen&&this.isLastEnabledPass(a),l.render(this.renderer,this.writeBuffer,this.readBuffer,e,o),l.needsSwap){if(o){const c=this.renderer.getContext(),f=this.renderer.state.buffers.stencil;f.setFunc(c.NOTEQUAL,1,4294967295),this.copyPass.render(this.renderer,this.writeBuffer,this.readBuffer,e),f.setFunc(c.EQUAL,1,4294967295)}this.swapBuffers()}j!==void 0&&(l instanceof j?o=!0:l instanceof Le&&(o=!1))}}this.renderer.setRenderTarget(t)}reset(e){if(e===void 0){const t=this.renderer.getSize(new s.Vector2);this._pixelRatio=this.renderer.getPixelRatio(),this._width=t.width,this._height=t.height,e=this.renderTarget1.clone(),e.setSize(this._width*this._pixelRatio,this._height*this._pixelRatio)}this.renderTarget1.dispose(),this.renderTarget2.dispose(),this.renderTarget1=e,this.renderTarget2=e.clone(),this.writeBuffer=this.renderTarget1,this.readBuffer=this.renderTarget2}setSize(e,t){this._width=e,this._height=t;const o=this._width*this._pixelRatio,a=this._height*this._pixelRatio;this.renderTarget1.setSize(o,a),this.renderTarget2.setSize(o,a);for(let n=0;n<this.passes.length;n++)this.passes[n].setSize(o,a)}setPixelRatio(e){this._pixelRatio=e,this.setSize(this._width,this._height)}dispose(){this.renderTarget1.dispose(),this.renderTarget2.dispose(),this.copyPass.dispose()}}class Re extends A{constructor(e,t,o=null,a=null,n=null){super(),this.scene=e,this.camera=t,this.overrideMaterial=o,this.clearColor=a,this.clearAlpha=n,this.clear=!0,this.clearDepth=!1,this.needsSwap=!1,this._oldClearColor=new s.Color}render(e,t,o){const a=e.autoClear;e.autoClear=!1;let n,l;this.overrideMaterial!==null&&(l=this.scene.overrideMaterial,this.scene.overrideMaterial=this.overrideMaterial),this.clearColor!==null&&(e.getClearColor(this._oldClearColor),e.setClearColor(this.clearColor,e.getClearAlpha())),this.clearAlpha!==null&&(n=e.getClearAlpha(),e.setClearAlpha(this.clearAlpha)),this.clearDepth==!0&&e.clearDepth(),e.setRenderTarget(this.renderToScreen?null:o),this.clear===!0&&e.clear(e.autoClearColor,e.autoClearDepth,e.autoClearStencil),e.render(this.scene,this.camera),this.clearColor!==null&&e.setClearColor(this._oldClearColor),this.clearAlpha!==null&&e.setClearAlpha(n),this.overrideMaterial!==null&&(this.scene.overrideMaterial=l),e.autoClear=a}}const Y=Symbol("effectComposerThree"),Oe=r.defineComponent({__name:"EffectComposer",props:{enabled:{type:Boolean,default:!0},withoutRenderPass:{type:Boolean}},setup(i,{expose:e}){const t=i,o=r.shallowRef(null);r.provide(Y,o),e({composer:o});const{renderer:a,sizes:n,scene:l,camera:c,render:f}=x.useTresContext(),m=()=>{var h;(h=o.value)==null||h.dispose(),o.value=new Fe(a.value)};r.watchEffect(m),r.watchEffect(()=>{var y;const{width:h,height:S}=n;S.value&&h.value&&((y=o.value)==null||y.setSize(h.value,S.value))});const{pixelRatio:g}=N.useDevicePixelRatio();r.watchEffect(()=>{var h;(h=o.value)==null||h.setPixelRatio(g.value)}),t.withoutRenderPass||r.watchEffect(()=>{c.value&&l.value&&o.value&&o.value.addPass(new Re(l.value,c.value))});const{render:b}=x.useLoop();return b(()=>{f.frames.value>0&&o.value&&t.enabled&&o.value.render(),f.frames.value=f.mode.value==="always"?1:Math.max(0,f.frames.value-1)}),r.onUnmounted(()=>{var h;(h=o.value)==null||h.dispose()}),(h,S)=>r.renderSlot(h.$slots,"default")}}),T=(i,e,t)=>{if(!e&&t)throw new Error("passDependencies is required when dependencyFieldsTriggeringRecreation is provided");const o=r.inject(Y),a=r.shallowRef(i()),{sizes:n,invalidate:l}=x.useTresContext();e&&r.watch(e,()=>l());const c=()=>{var m;(m=o==null?void 0:o.value)==null||m.removePass(a.value),a.value.dispose()},f=r.watchEffect(()=>{!(o!=null&&o.value)||!n.height.value||!n.width.value||(o.value.addPass(a.value),r.nextTick(()=>f()))});return t&&r.watch(()=>t.map(m=>e==null?void 0:e[m]),()=>{if(!(o!=null&&o.value))return;const m=o.value.passes.findIndex(g=>g===a.value);~m&&(c(),a.value=i(),o.value.insertPass(a.value,m))}),r.onUnmounted(()=>{c()}),{pass:a}},Be={uniforms:{tDiffuse:{value:null},tDisp:{value:null},byp:{value:0},amount:{value:.08},angle:{value:.02},seed:{value:.02},seed_x:{value:.02},seed_y:{value:.02},distortion_x:{value:.5},distortion_y:{value:.6},col_s:{value:.05}},vertexShader:` varying vec2 vUv; void main() { vUv = uv; gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); }`,fragmentShader:` uniform int byp; //should we apply the glitch ? uniform sampler2D tDiffuse; uniform sampler2D tDisp; uniform float amount; uniform float angle; uniform float seed; uniform float seed_x; uniform float seed_y; uniform float distortion_x; uniform float distortion_y; uniform float col_s; varying vec2 vUv; float rand(vec2 co){ return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); } void main() { if(byp<1) { vec2 p = vUv; float xs = floor(gl_FragCoord.x / 0.5); float ys = floor(gl_FragCoord.y / 0.5); //based on staffantans glitch shader for unity https://github.com/staffantan/unityglitch float disp = texture2D(tDisp, p*seed*seed).r; if(p.y<distortion_x+col_s && p.y>distortion_x-col_s*seed) { if(seed_x>0.){ p.y = 1. - (p.y + distortion_y); } else { p.y = distortion_y; } } if(p.x<distortion_y+col_s && p.x>distortion_y-col_s*seed) { if(seed_y>0.){ p.x=distortion_x; } else { p.x = 1. - (p.x + distortion_x); } } p.x+=disp*seed_x*(seed/5.); p.y+=disp*seed_y*(seed/5.); //base from RGB shift shader vec2 offset = amount * vec2( cos(angle), sin(angle)); vec4 cr = texture2D(tDiffuse, p + offset); vec4 cga = texture2D(tDiffuse, p); vec4 cb = texture2D(tDiffuse, p - offset); gl_FragColor = vec4(cr.r, cga.g, cb.b, cga.a); //add noise vec4 snow = 200.*amount*vec4(rand(vec2(xs * seed,ys * seed*50.))*0.2); gl_FragColor = gl_FragColor+ snow; } else { gl_FragColor=texture2D (tDiffuse, vUv); } }`};class k extends A{constructor(e=64){super();const t=Be;this.uniforms=s.UniformsUtils.clone(t.uniforms),this.heightMap=this.generateHeightmap(e),this.uniforms.tDisp.value=this.heightMap,this.material=new s.ShaderMaterial({uniforms:this.uniforms,vertexShader:t.vertexShader,fragmentShader:t.fragmentShader}),this.fsQuad=new M(this.material),this.goWild=!1,this.curF=0,this.generateTrigger()}render(e,t,o){this.uniforms.tDiffuse.value=o.texture,this.uniforms.seed.value=Math.random(),this.uniforms.byp.value=0,this.curF%this.randX==0||this.goWild==!0?(this.uniforms.amount.value=Math.random()/30,this.uniforms.angle.value=s.MathUtils.randFloat(-Math.PI,Math.PI),this.uniforms.seed_x.value=s.MathUtils.randFloat(-1,1),this.uniforms.seed_y.value=s.MathUtils.randFloat(-1,1),this.uniforms.distortion_x.value=s.MathUtils.randFloat(0,1),this.uniforms.distortion_y.value=s.MathUtils.randFloat(0,1),this.curF=0,this.generateTrigger()):this.curF%this.randX<this.randX/5?(this.uniforms.amount.value=Math.random()/90,this.uniforms.angle.value=s.MathUtils.randFloat(-Math.PI,Math.PI),this.uniforms.distortion_x.value=s.MathUtils.randFloat(0,1),this.uniforms.distortion_y.value=s.MathUtils.randFloat(0,1),this.uniforms.seed_x.value=s.MathUtils.randFloat(-.3,.3),this.uniforms.seed_y.value=s.MathUtils.randFloat(-.3,.3)):this.goWild==!1&&(this.uniforms.byp.value=1),this.curF++,this.renderToScreen?(e.setRenderTarget(null),this.fsQuad.render(e)):(e.setRenderTarget(t),this.clear&&e.clear(),this.fsQuad.render(e))}generateTrigger(){this.randX=s.MathUtils.randInt(120,240)}generateHeightmap(e){const t=new Float32Array(e*e),o=e*e;for(let n=0;n<o;n++){const l=s.MathUtils.randFloat(0,1);t[n]=l}const a=new s.DataTexture(t,e,e,s.RedFormat,s.FloatType);return a.needsUpdate=!0,a}dispose(){this.material.dispose(),this.heightMap.dispose(),this.fsQuad.dispose()}}const Ne=r.defineComponent({__name:"Glitch",props:{dtSize:{},goWild:{type:Boolean}},setup(i,{expose:e}){const t=i,{pass:o}=T(()=>new k(t.dtSize),t,["dtSize"]);e({pass:o});const{onBeforeRender:a}=x.useLoop();return a(({invalidate:n})=>n()),v([[()=>t.goWild,"goWild"]],o,()=>new k),()=>{}}}),D={name:"HalftoneShader",uniforms:{tDiffuse:{value:null},shape:{value:1},radius:{value:4},rotateR:{value:Math.PI/12*1},rotateG:{value:Math.PI/12*2},rotateB:{value:Math.PI/12*3},scatter:{value:0},width:{value:1},height:{value:1},blending:{value:1},blendingMode:{value:1},greyscale:{value:!1},disable:{value:!1}},vertexShader:` varying vec2 vUV; void main() { vUV = uv; gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); }`,fragmentShader:` #define SQRT2_MINUS_ONE 0.41421356 #define SQRT2_HALF_MINUS_ONE 0.20710678 #define PI2 6.28318531 #define SHAPE_DOT 1 #define SHAPE_ELLIPSE 2 #define SHAPE_LINE 3 #define SHAPE_SQUARE 4 #define BLENDING_LINEAR 1 #define BLENDING_MULTIPLY 2 #define BLENDING_ADD 3 #define BLENDING_LIGHTER 4 #define BLENDING_DARKER 5 uniform sampler2D tDiffuse; uniform float radius; uniform float rotateR; uniform float rotateG; uniform float rotateB; uniform float scatter; uniform float width; uniform float height; uniform int shape; uniform bool disable; uniform float blending; uniform int blendingMode; varying vec2 vUV; uniform bool greyscale; const int samples = 8; float blend( float a, float b, float t ) { // linear blend return a * ( 1.0 - t ) + b * t; } float hypot( float x, float y ) { // vector magnitude return sqrt( x * x + y * y ); } float rand( vec2 seed ){ // get pseudo-random number return fract( sin( dot( seed.xy, vec2( 12.9898, 78.233 ) ) ) * 43758.5453 ); } float distanceToDotRadius( float channel, vec2 coord, vec2 normal, vec2 p, float angle, float rad_max ) { // apply shape-specific transforms float dist = hypot( coord.x - p.x, coord.y - p.y ); float rad = channel; if ( shape == SHAPE_DOT ) { rad = pow( abs( rad ), 1.125 ) * rad_max; } else if ( shape == SHAPE_ELLIPSE ) { rad = pow( abs( rad ), 1.125 ) * rad_max; if ( dist != 0.0 ) { float dot_p = abs( ( p.x - coord.x ) / dist * normal.x + ( p.y - coord.y ) / dist * normal.y ); dist = ( dist * ( 1.0 - SQRT2_HALF_MINUS_ONE ) ) + dot_p * dist * SQRT2_MINUS_ONE; } } else if ( shape == SHAPE_LINE ) { rad = pow( abs( rad ), 1.5) * rad_max; float dot_p = ( p.x - coord.x ) * normal.x + ( p.y - coord.y ) * normal.y; dist = hypot( normal.x * dot_p, normal.y * dot_p ); } else if ( shape == SHAPE_SQUARE ) { float theta = atan( p.y - coord.y, p.x - coord.x ) - angle; float sin_t = abs( sin( theta ) ); float cos_t = abs( cos( theta ) ); rad = pow( abs( rad ), 1.4 ); rad = rad_max * ( rad + ( ( sin_t > cos_t ) ? rad - sin_t * rad : rad - cos_t * rad ) ); } return rad - dist; } struct Cell { // grid sample positions vec2 normal; vec2 p1; vec2 p2; vec2 p3; vec2 p4; float samp2; float samp1; float samp3; float samp4; }; vec4 getSample( vec2 point ) { // multi-sampled point vec4 tex = texture2D( tDiffuse, vec2( point.x / width, point.y / height ) ); float base = rand( vec2( floor( point.x ), floor( point.y ) ) ) * PI2; float step = PI2 / float( samples ); float dist = radius * 0.66; for ( int i = 0; i < samples; ++i ) { float r = base + step * float( i ); vec2 coord = point + vec2( cos( r ) * dist, sin( r ) * dist ); tex += texture2D( tDiffuse, vec2( coord.x / width, coord.y / height ) ); } tex /= float( samples ) + 1.0; return tex; } float getDotColour( Cell c, vec2 p, int channel, float angle, float aa ) { // get colour for given point float dist_c_1, dist_c_2, dist_c_3, dist_c_4, res; if ( channel == 0 ) { c.samp1 = getSample( c.p1 ).r; c.samp2 = getSample( c.p2 ).r; c.samp3 = getSample( c.p3 ).r; c.samp4 = getSample( c.p4 ).r; } else if (channel == 1) { c.samp1 = getSample( c.p1 ).g; c.samp2 = getSample( c.p2 ).g; c.samp3 = getSample( c.p3 ).g; c.samp4 = getSample( c.p4 ).g; } else { c.samp1 = getSample( c.p1 ).b; c.samp3 = getSample( c.p3 ).b; c.samp2 = getSample( c.p2 ).b; c.samp4 = getSample( c.p4 ).b; } dist_c_1 = distanceToDotRadius( c.samp1, c.p1, c.normal, p, angle, radius ); dist_c_2 = distanceToDotRadius( c.samp2, c.p2, c.normal, p, angle, radius ); dist_c_3 = distanceToDotRadius( c.samp3, c.p3, c.normal, p, angle, radius ); dist_c_4 = distanceToDotRadius( c.samp4, c.p4, c.normal, p, angle, radius ); res = ( dist_c_1 > 0.0 ) ? clamp( dist_c_1 / aa, 0.0, 1.0 ) : 0.0; res += ( dist_c_2 > 0.0 ) ? clamp( dist_c_2 / aa, 0.0, 1.0 ) : 0.0; res += ( dist_c_3 > 0.0 ) ? clamp( dist_c_3 / aa, 0.0, 1.0 ) : 0.0; res += ( dist_c_4 > 0.0 ) ? clamp( dist_c_4 / aa, 0.0, 1.0 ) : 0.0; res = clamp( res, 0.0, 1.0 ); return res; } Cell getReferenceCell( vec2 p, vec2 origin, float grid_angle, float step ) { // get containing cell Cell c; // calc grid vec2 n = vec2( cos( grid_angle ), sin( grid_angle ) ); float threshold = step * 0.5; float dot_normal = n.x * ( p.x - origin.x ) + n.y * ( p.y - origin.y ); float dot_line = -n.y * ( p.x - origin.x ) + n.x * ( p.y - origin.y ); vec2 offset = vec2( n.x * dot_normal, n.y * dot_normal ); float offset_normal = mod( hypot( offset.x, offset.y ), step ); float normal_dir = ( dot_normal < 0.0 ) ? 1.0 : -1.0; float normal_scale = ( ( offset_normal < threshold ) ? -offset_normal : step - offset_normal ) * normal_dir; float offset_line = mod( hypot( ( p.x - offset.x ) - origin.x, ( p.y - offset.y ) - origin.y ), step ); float line_dir = ( dot_line < 0.0 ) ? 1.0 : -1.0; float line_scale = ( ( offset_line < threshold ) ? -offset_line : step - offset_line ) * line_dir; // get closest corner c.normal = n; c.p1.x = p.x - n.x * normal_scale + n.y * line_scale; c.p1.y = p.y - n.y * normal_scale - n.x * line_scale; // scatter if ( scatter != 0.0 ) { float off_mag = scatter * threshold * 0.5; float off_angle = rand( vec2( floor( c.p1.x ), floor( c.p1.y ) ) ) * PI2; c.p1.x += cos( off_angle ) * off_mag; c.p1.y += sin( off_angle ) * off_mag; } // find corners float normal_step = normal