@tresjs/post-processing
Version:
Post-processing library for TresJS
391 lines (303 loc) • 139 kB
JavaScript
/**
* name: @tresjs/post-processing
* version: v2.4.0
* (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,b,i,W){"use strict";class G{static isWebGL2Available(){try{const t=document.createElement("canvas");return!!(window.WebGL2RenderingContext&&t.getContext("webgl2"))}catch{return!1}}static isColorSpaceAvailable(t){try{const e=document.createElement("canvas"),a=window.WebGL2RenderingContext&&e.getContext("webgl2");return a.drawingBufferColorSpace=t,a.drawingBufferColorSpace===t}catch{return!1}}static getWebGL2ErrorMessage(){return this.getErrorMessage(2)}static getErrorMessage(t){const e={1:"WebGL",2:"WebGL 2"},a={1:window.WebGLRenderingContext,2:window.WebGL2RenderingContext};let o='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",a[t]?o=o.replace("$0","graphics card"):o=o.replace("$0","browser"),o=o.replace("$1",e[t]),n.innerHTML=o,n}static isWebGLAvailable(){console.warn("isWebGLAvailable() has been deprecated and will be removed in r178. Use isWebGL2Available() instead.");try{const t=document.createElement("canvas");return!!(window.WebGLRenderingContext&&(t.getContext("webgl")||t.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 F=Symbol("effectComposerPmndrs"),_=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:i.HalfFloatType}},emits:["render"],setup(l,{expose:t,emit:e}){const a=l,o=e,{scene:n,camera:s,renderer:c,sizes:f,render:m}=b.useTresContext(),g=r.shallowRef(null);let S=null,h=null;r.provide(F,g),t({composer:g});const A=()=>{g.value&&(h=new u.NormalPass(n.value,s.value),h.enabled=!1,g.value.addPass(h),a.resolutionScale!==void 0&&G.isWebGL2Available()&&(S=new u.DepthDownsamplingPass({normalBuffer:h.texture,resolutionScale:a.resolutionScale}),S.enabled=!1,g.value.addPass(S)))},v=r.computed(()=>{const w=new u.EffectComposer,L={depthBuffer:a.depthBuffer!==void 0?a.depthBuffer:w.inputBuffer.depthBuffer,stencilBuffer:a.stencilBuffer!==void 0?a.stencilBuffer:w.inputBuffer.stencilBuffer,multisampling:G.isWebGL2Available()?a.multisampling!==void 0?a.multisampling:w.multisampling:0,frameBufferType:a.frameBufferType!==void 0?a.frameBufferType:i.HalfFloatType};return w.dispose(),L}),y=()=>{var w;!c.value&&!n.value&&!s.value||((w=g.value)==null||w.dispose(),g.value=new u.EffectComposer(c.value,v.value),g.value.addPass(new u.RenderPass(n.value,s.value)),a.disableNormalPass||A())};r.watch([c,n,s,()=>a.disableNormalPass],()=>{!f.width.value||!f.height.value||y()}),r.watch(()=>[f.width.value,f.height.value],([w,L])=>{!w&&!L||(g.value?g.value.setSize(w,L):y())},{immediate:!0});const{render:T}=b.useLoop();return T(()=>{if(a.enabled&&c.value&&g.value&&f.width.value&&f.height.value&&m.frames.value>0){const w=c.value.autoClear;c.value.autoClear=a.autoClear,a.stencilBuffer&&!a.autoClear&&c.value.clearStencil(),g.value.render(),o("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,L)=>r.renderSlot(w.$slots,"default")}}),p=(l,t,e)=>{const a=r.inject(F),o=r.shallowRef(null),n=r.shallowRef(null),{scene:s,camera:c,invalidate:f}=b.useTresContext();r.watch(t,()=>f());const m=()=>{var h,A,v;o.value&&((h=a==null?void 0:a.value)==null||h.removePass(o.value)),(A=n.value)==null||A.dispose(),(v=o.value)==null||v.dispose()},g=h=>{!c.value||!(a!=null&&a.value)||!s.value||(n.value=l(),o.value=new u.EffectPass(c.value,n.value),a.value.addPass(o.value,h))};e&&r.watch(()=>e.map(h=>t[h]),()=>{var A;if(!(a!=null&&a.value))return;const h=(A=a.value)==null?void 0:A.passes.findIndex(v=>v===o.value);~h&&(m(),g(h))}),r.watchEffect(()=>{!c.value||!(n!=null&&n.value)||(n.value.mainCamera=c.value)});const S=r.watchEffect(()=>{!c.value||!(a!=null&&a.value)||!s.value||(r.nextTick(()=>S()),!n.value&&g())});return r.onUnmounted(()=>{m()}),{pass:o,effect:n}},H=/([^[.\]])+/g,$=(l,t)=>{if(!t)return;const e=Array.isArray(t)?t:t.match(H);return e==null?void 0:e.reduce((a,o)=>a&&a[o],l)},V=(l,t,e)=>{const a=Array.isArray(t)?t:t.match(H);a&&a.reduce((o,n,s)=>(o[n]===void 0&&(o[n]={}),s===a.length-1&&(o[n]=e),o[n]),l)},ee=(l,t)=>{const e={...l};return t.forEach(a=>delete e[a]),e},D=(l,t,e,a,o={})=>r.watch(l,n=>{var s;if(t.value)if(n===void 0){const c=a();V(t.value,e,$(c,e)),(s=c.dispose)==null||s.call(c)}else V(t.value,e,l())},o),x=(l,t,e)=>l.map(([a,o])=>D(a,t,o,e)),N=(l,t,e)=>Object.keys(l).map(a=>D(()=>l[a],t,a,e)),te=r.defineComponent({__name:"BloomPmndrs",props:{blendFunction:{},intensity:{},kernelSize:{},luminanceThreshold:{},luminanceSmoothing:{},mipmapBlur:{type:Boolean,default:void 0}},setup(l,{expose:t}){const e=l,{pass:a,effect:o}=p(()=>new u.BloomEffect(e),e,["mipmapBlur"]);return t({pass:a,effect:o}),x([[()=>e.blendFunction,"blendMode.blendFunction"],[()=>e.intensity,"intensity"],[()=>e.kernelSize,"kernelSize"],[()=>e.luminanceSmoothing,"luminanceMaterial.smoothing"],[()=>e.luminanceThreshold,"luminanceMaterial.threshold"]],o,()=>new u.BloomEffect),()=>{}}}),ae=r.defineComponent({__name:"DepthOfFieldPmndrs",props:{blendFunction:{},worldFocusDistance:{},worldFocusRange:{},focusDistance:{},focusRange:{},bokehScale:{},resolutionScale:{},resolutionX:{},resolutionY:{}},setup(l,{expose:t}){const e=l,{camera:a}=b.useTresContext(),{pass:o,effect:n}=p(()=>new u.DepthOfFieldEffect(a.value,e),e);return t({pass:o,effect:n}),x([[()=>e.blendFunction,"blendMode.blendFunction"],[()=>e.worldFocusDistance,"circleOfConfusionMaterial.worldFocusDistance"],[()=>e.focusDistance,"circleOfConfusionMaterial.focusDistance"],[()=>e.worldFocusRange,"circleOfConfusionMaterial.worldFocusRange"],[()=>e.focusRange,"circleOfConfusionMaterial.focusRange"],[()=>e.bokehScale,"bokehScale"],[()=>e.resolutionScale,"blurPass.resolution.scale"],[()=>e.resolutionX,"resolution.width"],[()=>e.resolutionY,"resolution.height"]],n,()=>new u.DepthOfFieldEffect),()=>{}}}),oe=r.defineComponent({__name:"GlitchPmndrs",props:{blendFunction:{},delay:{},duration:{},strength:{},mode:{},active:{type:Boolean},ratio:{},columns:{},chromaticAberrationOffset:{},perturbationMap:{},dtSize:{}},setup(l,{expose:t}){const e=l,{pass:a,effect:o}=p(()=>new u.GlitchEffect(e),e,["dtSize"]);t({pass:a,effect:o});const{onBeforeRender:n}=b.useLoop();return n(({invalidate:s})=>s()),r.watchEffect(()=>{const s=()=>{if(e.mode!==void 0)return e.active===!1?u.GlitchMode.DISABLED:e.mode;const c=new u.GlitchEffect,f=c.mode;return c.dispose(),f};o.value&&(o.value.mode=s())}),D(()=>e.blendFunction,o,"blendMode.blendFunction",()=>new u.GlitchEffect),N(ee(e,["active","blendFunction"]),o,()=>new u.GlitchEffect),()=>{}}}),ne=r.defineComponent({__name:"NoisePmndrs",props:{premultiply:{type:Boolean,default:void 0},blendFunction:{}},setup(l,{expose:t}){const e=l,{pass:a,effect:o}=p(()=>new u.NoiseEffect(e),e);t({pass:a,effect:o});const{onBeforeRender:n}=b.useLoop();return n(({invalidate:s})=>s()),x([[()=>e.blendFunction,"blendMode.blendFunction"],[()=>e.premultiply,"premultiply"]],o,()=>new u.NoiseEffect),()=>{}}}),ie=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(l,{expose:t}){const e=l,a=m=>m!==void 0?b.normalizeColor(m).getHex():void 0,{camera:o,scene:n}=b.useTresContext(),{pass:s,effect:c}=p(()=>new u.OutlineEffect(n.value,o.value,{blur:e.blur,xRay:e.xRay,kernelSize:e.kernelSize,pulseSpeed:e.pulseSpeed,resolutionX:e.resolutionX,resolutionY:e.resolutionY,patternScale:e.patternScale,edgeStrength:e.edgeStrength,blendFunction:e.blendFunction,multisampling:e.multisampling,patternTexture:e.patternTexture,resolutionScale:e.resolutionScale,hiddenEdgeColor:a(e.hiddenEdgeColor),visibleEdgeColor:a(e.visibleEdgeColor)}),e);t({pass:s,effect:c}),r.watch([()=>e.outlinedObjects,c],()=>{var m;(m=c.value)==null||m.selection.set(e.outlinedObjects||[])},{immediate:!0});const f=r.computed(()=>({hiddenEdgeColor:e.hiddenEdgeColor?b.normalizeColor(e.hiddenEdgeColor):void 0,visibleEdgeColor:e.visibleEdgeColor?b.normalizeColor(e.visibleEdgeColor):void 0}));return x([[()=>e.blendFunction,"blendMode.blendFunction"],[()=>e.blur,"blur"],[()=>e.xRay,"xRay"],[()=>e.pulseSpeed,"pulseSpeed"],[()=>e.kernelSize,"kernelSize"],[()=>e.edgeStrength,"edgeStrength"],[()=>e.patternScale,"patternScale"],[()=>e.multisampling,"multisampling"],[()=>e.resolutionX,"resolution.width"],[()=>e.resolutionY,"resolution.height"],[()=>e.patternTexture,"patternTexture"],[()=>e.resolutionScale,"resolution.scale"],[()=>f.value.hiddenEdgeColor,"hiddenEdgeColor"],[()=>f.value.visibleEdgeColor,"visibleEdgeColor"]],c,()=>new u.OutlineEffect),()=>{}}}),se=r.defineComponent({__name:"PixelationPmndrs",props:{granularity:{}},setup(l,{expose:t}){const e=l,{pass:a,effect:o}=p(()=>new u.PixelationEffect(e.granularity),e);return t({pass:a,effect:o}),N(e,o,()=>new u.PixelationEffect),()=>{}}}),re=r.defineComponent({__name:"VignettePmndrs",props:{technique:{},blendFunction:{},offset:{},darkness:{}},setup(l,{expose:t}){const e=l,{pass:a,effect:o}=p(()=>new u.VignetteEffect(e),e);return t({pass:a,effect:o}),x([[()=>e.blendFunction,"blendMode.blendFunction"],[()=>e.offset,"offset"],[()=>e.darkness,"darkness"],[()=>e.technique,"technique"]],o,()=>new u.VignetteEffect),()=>{}}});class I extends u.Effect{constructor({blendFunction:t=u.BlendFunction.NORMAL,amount:e=.15,offset:a=new i.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:t,uniforms:new Map([["amount",new i.Uniform(e)],["offset",new i.Uniform(a)]])})}get amount(){var t;return(t=this.uniforms.get("amount"))==null?void 0:t.value}set amount(t){this.uniforms.get("amount").value=t}get offset(){var t;return(t=this.uniforms.get("offset"))==null?void 0:t.value}set offset(t){this.uniforms.get("offset").value=t}}const le=r.defineComponent({__name:"BarrelBlurPmndrs",props:{blendFunction:{},amount:{},offset:{}},setup(l,{expose:t}){const e=l,{pass:a,effect:o}=p(()=>new I({...e,offset:Array.isArray(e.offset)?new i.Vector2(...e.offset):e.offset}),e);return t({pass:a,effect:o}),x([[()=>e.blendFunction,"blendMode.blendFunction"],[()=>e.amount,"amount"],[()=>e.offset,"offset"]],o,()=>new I),()=>{}}}),ce=r.defineComponent({__name:"ToneMappingPmndrs",props:{mode:{},blendFunction:{},resolution:{},averageLuminance:{},middleGrey:{},minLuminance:{},whitePoint:{}},setup(l,{expose:t}){const e=l,{pass:a,effect:o}=p(()=>new u.ToneMappingEffect(e),e);return t({pass:a,effect:o}),x([[()=>e.mode,"mode"],[()=>e.blendFunction,"blendMode.blendFunction"],[()=>e.resolution,"resolution"],[()=>e.averageLuminance,"averageLuminance"],[()=>e.middleGrey,"middleGrey"],[()=>e.minLuminance,"adaptiveLuminanceMaterial.minLuminance"],[()=>e.whitePoint,"whitePoint"]],o,()=>new u.ToneMappingEffect),()=>{}}}),ue=r.defineComponent({__name:"ChromaticAberrationPmndrs",props:{blendFunction:{},offset:{},radialModulation:{type:Boolean,default:void 0},modulationOffset:{}},setup(l,{expose:t}){const e=l,a=new u.ChromaticAberrationEffect,{pass:o,effect:n}=p(()=>new u.ChromaticAberrationEffect({...e,radialModulation:e.radialModulation??a.radialModulation,modulationOffset:e.modulationOffset??a.modulationOffset}),e);return a.dispose(),t({pass:o,effect:n}),x([[()=>e.blendFunction,"blendMode.blendFunction"],[()=>e.offset,"offset"],[()=>e.radialModulation,"radialModulation"],[()=>e.modulationOffset,"modulationOffset"]],n,()=>new u.ChromaticAberrationEffect),()=>{}}}),de=r.defineComponent({__name:"HueSaturationPmndrs",props:{saturation:{},hue:{},blendFunction:{}},setup(l,{expose:t}){const e=l,{pass:a,effect:o}=p(()=>new u.HueSaturationEffect(e),e);return t({pass:a,effect:o}),x([[()=>e.blendFunction,"blendMode.blendFunction"],[()=>e.hue,"hue"],[()=>e.saturation,"saturation"]],o,()=>new u.HueSaturationEffect),()=>{}}}),fe=r.defineComponent({__name:"ScanlinePmndrs",props:{blendFunction:{},density:{},scrollSpeed:{},opacity:{}},setup(l,{expose:t}){const e=l,{pass:a,effect:o}=p(()=>new u.ScanlineEffect(e),e);return t({pass:a,effect:o}),x([[()=>e.blendFunction,"blendMode.blendFunction"],[()=>e.density,"density"],[()=>e.scrollSpeed,"scrollSpeed"]],o,()=>new u.ScanlineEffect),r.watch([()=>e.opacity],()=>{var n,s;if(e.opacity!==void 0)(n=o.value)==null||n.blendMode.setOpacity(e.opacity);else{const c=new u.ScanlineEffect;(s=o.value)==null||s.blendMode.setOpacity(c.blendMode.getOpacity()),c.dispose()}},{immediate:!0}),()=>{}}}),he=`
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 X extends u.Effect{constructor({blendFunction:t=u.BlendFunction.NORMAL,radius:e=1,sectorCount:a=4}={}){super("KuwaharaEffect",he,{blendFunction:t,uniforms:new Map([["radius",new i.Uniform(e)],["sectorCount",new i.Uniform(a)]])})}get radius(){var t;return(t=this.uniforms.get("radius"))==null?void 0:t.value}set radius(t){this.uniforms.get("radius").value=t}get sectorCount(){var t;return(t=this.uniforms.get("sectorCount"))==null?void 0:t.value}set sectorCount(t){this.uniforms.get("sectorCount").value=t}}const me=r.defineComponent({__name:"KuwaharaPmndrs",props:{blendFunction:{},radius:{},sectorCount:{}},setup(l,{expose:t}){const e=l,{pass:a,effect:o}=p(()=>new X(e),e);return t({pass:a,effect:o}),x([[()=>e.blendFunction,"blendMode.blendFunction"],[()=>e.radius,"radius"],[()=>e.sectorCount,"sectorCount"]],o,()=>new X),()=>{}}}),pe=r.defineComponent({__name:"ColorAveragePmndrs",props:{blendFunction:{},opacity:{}},setup(l,{expose:t}){const e=l,{pass:a,effect:o}=p(()=>new u.ColorAverageEffect(e.blendFunction),e);return t({pass:a,effect:o}),D(()=>e.blendFunction,o,"blendMode.blendFunction",()=>new u.ColorAverageEffect),r.watch([o,()=>e.opacity],()=>{var n,s;if(o.value)if(e.opacity!==void 0)(n=o.value)==null||n.blendMode.setOpacity(e.opacity);else{const c=new u.ColorAverageEffect;(s=o.value)==null||s.blendMode.setOpacity(c.blendMode.getOpacity()),c.dispose()}}),()=>{}}}),ge=r.defineComponent({__name:"LensDistortionPmndrs",props:{distortion:{},principalPoint:{},focalLength:{},skew:{}},setup(l,{expose:t}){const e=l,{pass:a,effect:o}=p(()=>new u.LensDistortionEffect({...e,distortion:e.distortion?Array.isArray(e.distortion)?new i.Vector2(...e.distortion):e.distortion:new i.Vector2,principalPoint:e.principalPoint?Array.isArray(e.principalPoint)?new i.Vector2(...e.principalPoint):e.principalPoint:new i.Vector2,focalLength:e.focalLength?Array.isArray(e.focalLength)?new i.Vector2(...e.focalLength):e.focalLength:new i.Vector2}),e);return t({pass:a,effect:o}),N(e,o,()=>new u.LensDistortionEffect),()=>{}}}),ve=r.defineComponent({__name:"ShockWavePmndrs",props:{position:{},amplitude:{},speed:{},maxRadius:{},waveSize:{}},setup(l,{expose:t}){const e=l,{camera:a}=b.useTresContext(),{pass:o,effect:n}=p(()=>new u.ShockWaveEffect(a.value,Array.isArray(e.position)?new i.Vector3(...e.position):e.position,e),e);return t({pass:o,effect:n}),r.watch(()=>e.position,s=>{n.value&&(Array.isArray(s)?n.value.position.set(...s):s instanceof i.Vector3&&n.value.position.copy(s))},{immediate:!0}),x([[()=>e.amplitude,"amplitude"],[()=>e.waveSize,"waveSize"],[()=>e.maxRadius,"maxRadius"],[()=>e.speed,"speed"]],n,()=>new u.ShockWaveEffect),()=>{}}}),xe=r.defineComponent({__name:"TiltShiftPmndrs",props:{blendFunction:{},offset:{},rotation:{},focusArea:{},feather:{},kernelSize:{},resolutionScale:{},resolutionX:{},resolutionY:{}},setup(l,{expose:t}){const e=l,{pass:a,effect:o}=p(()=>new u.TiltShiftEffect(e),e);return t({pass:a,effect:o}),x([[()=>e.blendFunction,"blendMode.blendFunction"],[()=>e.offset,"offset"],[()=>e.rotation,"rotation"],[()=>e.focusArea,"focusArea"],[()=>e.feather,"feather"],[()=>e.kernelSize,"kernelSize"],[()=>e.resolutionScale,"resolution.scale"],[()=>e.resolutionX,"resolution.width"],[()=>e.resolutionY,"resolution.height"]],o,()=>new u.TiltShiftEffect),()=>{}}}),be=r.defineComponent({__name:"DotScreenPmndrs",props:{angle:{},scale:{},blendFunction:{}},setup(l,{expose:t}){const e=l,{pass:a,effect:o}=p(()=>new u.DotScreenEffect(e),e);return t({pass:a,effect:o}),x([[()=>e.blendFunction,"blendMode.blendFunction"],[()=>e.angle,"angle"],[()=>e.scale,"scale"]],o,()=>new u.DotScreenEffect),()=>{}}}),we=r.defineComponent({__name:"SepiaPmndrs",props:{blendFunction:{},intensity:{}},setup(l,{expose:t}){const e=l,{pass:a,effect:o}=p(()=>new u.SepiaEffect(e),e);return t({pass:a,effect:o}),x([[()=>e.blendFunction,"blendMode.blendFunction"],[()=>e.intensity,"intensity"]],o,()=>new u.SepiaEffect),()=>{}}});class j extends u.Effect{constructor({blendFunction:t=u.BlendFunction.NORMAL,scale:e=.85,noiseScale:a=0,center:o=[.5,.5],rotation:n=0}={}){const s=Array.isArray(o)?new i.Vector2().fromArray(o):o;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:t,uniforms:new Map([["scale",new i.Uniform(e)],["noiseScale",new i.Uniform(a)],["center",new i.Uniform(s)],["rotation",new i.Uniform(n)]])})}get scale(){var t;return(t=this.uniforms.get("scale"))==null?void 0:t.value}set scale(t){this.uniforms.get("scale").value=t}get noiseScale(){var t;return(t=this.uniforms.get("noiseScale"))==null?void 0:t.value}set noiseScale(t){this.uniforms.get("noiseScale").value=t}get center(){var t;return(t=this.uniforms.get("center"))==null?void 0:t.value}set center(t){this.uniforms.get("center").value=Array.isArray(t)?new i.Vector2().fromArray(t):t}get rotation(){var t;return(t=this.uniforms.get("rotation"))==null?void 0:t.value}set rotation(t){this.uniforms.get("rotation").value=t}}const Se=r.defineComponent({__name:"LinocutPmndrs",props:{blendFunction:{},scale:{},noiseScale:{},center:{},rotation:{}},setup(l,{expose:t}){const e=l,{pass:a,effect:o}=p(()=>new j({...e,center:e.center instanceof i.Vector2?[e.center.x,e.center.y]:e.center}),e);return t({pass:a,effect:o}),x([[()=>e.blendFunction,"blendMode.blendFunction"],[()=>e.scale,"scale"],[()=>e.noiseScale,"noiseScale"],[()=>e.center,"center"],[()=>e.rotation,"rotation"]],o,()=>new j),()=>{}}}),Ae=r.defineComponent({__name:"DepthPickingPassPmndrs",props:{depthPacking:{},mode:{}},setup(l,{expose:t}){const e=l,a=r.inject(F),o=new u.DepthPickingPass(e),n=r.watchEffect(()=>{a!=null&&a.value&&(r.nextTick(()=>n()),a.value.addPass(o))});return r.onUnmounted(()=>{var s;!(a!=null&&a.value)||!o||((s=a==null?void 0:a.value)==null||s.removePass(o),o.dispose())}),t({pass:o}),()=>{}}}),ye=r.defineComponent({__name:"GodRaysPmndrs",props:{blendFunction:{},lightSource:{},opacity:{},density:{},decay:{},kernelSize:{},resolutionScale:{},blur:{type:Boolean},resolutionX:{},resolutionY:{},weight:{},exposure:{},samples:{},clampMax:{}},setup(l,{expose:t}){const e=l,{camera:a}=b.useTresContext(),o=r.computed(()=>e.lightSource??new i.Mesh(new i.SphereGeometry(1e-5),new i.MeshBasicMaterial({visible:!1}))),{pass:n,effect:s}=p(()=>new u.GodRaysEffect(a.value,o.value,e),e);return t({pass:n,effect:s}),x([[()=>e.blendFunction,"blendMode.blendFunction"],[()=>e.density,"godRaysMaterial.density"],[()=>e.decay,"godRaysMaterial.decay"],[()=>e.weight,"godRaysMaterial.weight"],[()=>e.exposure,"godRaysMaterial.exposure"],[()=>e.samples,"godRaysMaterial.samples"],[()=>e.clampMax,"godRaysMaterial.maxIntensity"],[()=>e.resolutionScale,"resolution.scale"],[()=>e.resolutionX,"resolution.width"],[()=>e.resolutionY,"resolution.height"],[()=>e.kernelSize,"blurPass.kernelSize"],[()=>e.blur,"blurPass.enabled"]],s,()=>new u.GodRaysEffect),r.watch([()=>e.lightSource,s],()=>{s.value&&(s.value.lightSource=r.toRaw(o.value))},{immediate:!0}),r.watch([()=>e.opacity],()=>{var c,f;if(e.opacity!==void 0)(c=s.value)==null||c.blendMode.setOpacity(e.opacity);else{const m=new u.GodRaysEffect(a.value,r.toRaw(o.value));(f=s.value)==null||f.blendMode.setOpacity(m.blendMode.getOpacity()),m.dispose()}},{immediate:!0}),()=>{}}}),Me=r.defineComponent({__name:"ColorDepthPmndrs",props:{blendFunction:{},bits:{},opacity:{}},setup(l,{expose:t}){const e=l,{pass:a,effect:o}=p(()=>new u.ColorDepthEffect(e),e);return t({pass:a,effect:o}),D(()=>e.blendFunction,o,"blendMode.blendFunction",()=>new u.ColorDepthEffect),r.watch([o,()=>e.bits],()=>{var n,s;if(o.value)if(e.bits!==void 0)(n=o.value)==null||n.setBitDepth(e.bits);else{const c=new u.ColorDepthEffect;(s=o.value)==null||s.setBitDepth(c.getBitDepth()),c.dispose()}}),r.watch([o,()=>e.opacity],()=>{var n,s;if(o.value)if(e.opacity!==void 0)(n=o.value)==null||n.blendMode.setOpacity(e.opacity);else{const c=new u.ColorDepthEffect;(s=o.value)==null||s.blendMode.setOpacity(c.blendMode.getOpacity()),c.dispose()}}),()=>{}}}),Te=r.defineComponent({__name:"GridPmndrs",props:{blendFunction:{},scale:{},lineWidth:{}},setup(l,{expose:t}){const e=l,{pass:a,effect:o}=p(()=>new u.GridEffect(e),e);return t({pass:a,effect:o}),x([[()=>e.blendFunction,"blendMode.blendFunction"],[()=>e.scale,"scale"],[()=>e.lineWidth,"lineWidth"]],o,()=>new u.GridEffect),()=>{}}});class Y extends u.Effect{constructor({blendFunction:t=u.BlendFunction.NORMAL,lensS:e=new i.Vector2(1,1),lensF:a=new i.Vector2(0,1),scale:o=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:t,uniforms:new Map([["lensS",new i.Uniform(e)],["lensF",new i.Uniform(a)],["scale",new i.Uniform(o)]])})}get lensS(){var t;return(t=this.uniforms.get("lensS"))==null?void 0:t.value}set lensS(t){this.uniforms.get("lensS").value=t}get lensF(){var t;return(t=this.uniforms.get("lensF"))==null?void 0:t.value}set lensF(t){this.uniforms.get("lensF").value=t}get scale(){var t;return(t=this.uniforms.get("scale"))==null?void 0:t.value}set scale(t){this.uniforms.get("scale").value=t}}const Ce=r.defineComponent({__name:"FishEyePmndrs",props:{blendFunction:{},lensS:{},lensF:{},scale:{}},setup(l,{expose:t}){const e=l,a=r.computed(()=>Array.isArray(e.lensS)?new i.Vector2(...e.lensS):e.lensS),o=r.computed(()=>Array.isArray(e.lensF)?new i.Vector2(...e.lensF):e.lensF),{pass:n,effect:s}=p(()=>new Y({...e,lensS:a.value,lensF:o.value}),e);return t({pass:n,effect:s}),x([[()=>e.blendFunction,"blendMode.blendFunction"],[()=>a.value,"lensS"],[()=>o.value,"lensF"],[()=>e.scale,"scale"]],s,()=>new Y),()=>{}}}),Ee=r.defineComponent({__name:"BrightnessContrastPmndrs",props:{blendFunction:{},brightness:{},contrast:{}},setup(l,{expose:t}){const e=l,{pass:a,effect:o}=p(()=>new u.BrightnessContrastEffect(e),e);return t({pass:a,effect:o}),x([[()=>e.blendFunction,"blendMode.blendFunction"],[()=>e.brightness,"brightness"],[()=>e.contrast,"contrast"]],o,()=>new u.BrightnessContrastEffect),()=>{}}}),z={OFF:0,EDGES:1,WEIGHTS:2},Pe=r.defineComponent({__name:"SMAAPmndrs",props:{blendFunction:{},opacity:{},preset:{},edgeDetectionMode:{},predicationMode:{},debug:{}},setup(l,{expose:t}){const e=l,{pass:a,effect:o}=p(()=>new u.SMAAEffect(e),e),{camera:n}=b.useTresContext(),s=r.inject(F);t({pass:a,effect:o});const c=new u.SMAAEffect;x([[()=>Number(e.blendFunction),"blendMode.blendFunction"],[()=>Number(e.predicationMode),"edgeDetectionMaterial.predicationMode"],[()=>Number(e.edgeDetectionMode),"edgeDetectionMaterial.edgeDetectionMode"]],o,()=>new u.SMAAEffect),r.watch([o,()=>e.opacity],()=>{o.value&&(e.opacity!==void 0?o.value.blendMode.setOpacity(e.opacity):o.value.blendMode.setOpacity(c.blendMode.getOpacity()))},{immediate:!0}),r.watch([o,()=>e.preset],()=>{o.value&&o.value.applyPreset(Number(e.preset))});let f=null,m=null;const g=v=>{if(!o.value)return null;const y=v==="edges"?o.value.edgesTexture:o.value.weightsTexture,T=new u.EffectPass(n.value,o.value,new u.TextureEffect({texture:y}));return T.renderToScreen=!1,T.enabled=!1,T.fullscreenMaterial.encodeOutput=!1,T},S=v=>{v==="edges"&&!f?f=g("edges"):v==="weights"&&!m&&(m=g("weights"))},h=(v,y)=>{!v||!(s!=null&&s.value)||v.enabled!==y&&(v.enabled=y,v.renderToScreen=y,y&&!(s!=null&&s.value.passes.includes(v))?s==null||s.value.addPass(v):!y&&(s!=null&&s.value.passes.includes(v))&&(s==null||s.value.removePass(v),v.dispose()))},A=v=>{if(!a.value)return;const y=v===z.OFF,T=v===z.EDGES,w=v===z.WEIGHTS;a.value.enabled=y,a.value.renderToScreen=y,T&&S("edges"),w&&S("weights"),h(f,T),h(m,w),T||(f=null),w||(m=null)};return r.watch(()=>e.debug,()=>{!a.value||e.debug===void 0||A(e.debug)},{immediate:!0}),()=>{}}}),De=r.defineComponent({__name:"FXAAPmndrs",props:{blendFunction:{},opacity:{},samples:{},minEdgeThreshold:{},maxEdgeThreshold:{},subpixelQuality:{}},setup(l,{expose:t}){const e=l,{pass:a,effect:o}=p(()=>new u.FXAAEffect(e),e);return t({pass:a,effect:o}),x([[()=>e.blendFunction,"blendMode.blendFunction"],[()=>e.samples,"samples"],[()=>e.minEdgeThreshold,"minEdgeThreshold"],[()=>e.maxEdgeThreshold,"maxEdgeThreshold"],[()=>e.subpixelQuality,"subpixelQuality"]],o,()=>new u.FXAAEffect),r.watch([o,()=>e.opacity],()=>{var n,s;if(o.value)if(e.opacity!==void 0)(n=o.value)==null||n.blendMode.setOpacity(e.opacity);else{const c=new u.FXAAEffect;(s=o.value)==null||s.blendMode.setOpacity(c.blendMode.getOpacity()),c.dispose()}},{immediate:!0}),()=>{}}}),Le=r.defineComponent({__name:"TexturePmndrs",props:{blendFunction:{},texture:{},opacity:{}},setup(l,{expose:t}){const e=l,{pass:a,effect:o}=p(()=>new u.TextureEffect(e),e);return t({pass:a,effect:o}),x([[()=>e.blendFunction,"blendMode.blendFunction"]],o,()=>new u.TextureEffect),r.watch([()=>e.opacity],()=>{var n,s;if(e.opacity!==void 0)(n=o.value)==null||n.blendMode.setOpacity(e.opacity);else{const c=new u.TextureEffect;(s=o.value)==null||s.blendMode.setOpacity(c.blendMode.getOpacity()),c.dispose()}},{immediate:!0}),()=>{}}}),Fe=r.defineComponent({__name:"ASCIIPmndrs",props:{blendFunction:{},opacity:{},cellSize:{},inverted:{type:Boolean},color:{},useSceneColor:{type:Boolean},asciiTexture:{}},setup(l,{expose:t}){const e=l,a=new u.ASCIIEffect,{asciiTexture:o,...n}=e,{pass:s,effect:c}=p(()=>new u.ASCIIEffect(n),e);return t({pass:s,effect:c}),r.onUnmounted(()=>{a.dispose()}),x([[()=>e.blendFunction,"blendMode.blendFunction"],[()=>e.cellSize,"cellSize"],[()=>e.inverted,"inverted"]],c,()=>new u.ASCIIEffect),r.watch([c,()=>e.useSceneColor],()=>{c.value&&(e.useSceneColor?c.value.color=null:c.value.color=e.color??a.color)},{immediate:!0}),r.watch([c,()=>e.opacity],()=>{c.value&&c.value.blendMode.setOpacity(e.opacity??a.blendMode.getOpacity())},{immediate:!0}),r.watch([c,()=>e.color],()=>{c.value&&(e.useSceneColor||(c.value.color=e.color??null))},{immediate:!0}),r.watch([c,()=>e.asciiTexture],()=>{if(!c.value)return;const f=e.asciiTexture?new u.ASCIITexture(e.asciiTexture):a.asciiTexture;c.value.asciiTexture=f},{immediate:!0}),r.watch([c,()=>e.blendFunction],()=>{c.value&&(c.value.blendMode.blendFunction=e.blendFunction?Number(e.blendFunction):Number(a.blendMode.blendFunction))},{immediate:!0}),()=>{}}}),k={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 M{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 Oe=new i.OrthographicCamera(-1,1,1,-1,0,1);class Re extends i.BufferGeometry{constructor(){super(),this.setAttribute("position",new i.Float32BufferAttribute([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new i.Float32BufferAttribute([0,2,0,0,2,0],2))}}const Be=new Re;class C{constructor(t){this._mesh=new i.Mesh(Be,t)}dispose(){this._mesh.geometry.dispose()}render(t){t.render(this._mesh,Oe)}get material(){return this._mesh.material}set material(t){this._mesh.material=t}}class Ne extends M{constructor(t,e){super(),this.textureID=e!==void 0?e:"tDiffuse",t instanceof i.ShaderMaterial?(this.uniforms=t.uniforms,this.material=t):t&&(this.uniforms=i.UniformsUtils.clone(t.uniforms),this.material=new i.ShaderMaterial({name:t.name!==void 0?t.name:"unspecified",defines:Object.assign({},t.defines),uniforms:this.uniforms,vertexShader:t.vertexShader,fragmentShader:t.fragmentShader})),this.fsQuad=new C(this.material)}render(t,e,a){this.uniforms[this.textureID]&&(this.uniforms[this.textureID].value=a.texture),this.fsQuad.material=this.material,this.renderToScreen?(t.setRenderTarget(null),this.fsQuad.render(t)):(t.setRenderTarget(e),this.clear&&t.clear(t.autoClearColor,t.autoClearDepth,t.autoClearStencil),this.fsQuad.render(t))}dispose(){this.material.dispose(),this.fsQuad.dispose()}}class q extends M{constructor(t,e){super(),this.scene=t,this.camera=e,this.clear=!0,this.needsSwap=!1,this.inverse=!1}render(t,e,a){const o=t.getContext(),n=t.state;n.buffers.color.setMask(!1),n.buffers.depth.setMask(!1),n.buffers.color.setLocked(!0),n.buffers.depth.setLocked(!0);let s,c;this.inverse?(s=0,c=1):(s=1,c=0),n.buffers.stencil.setTest(!0),n.buffers.stencil.setOp(o.REPLACE,o.REPLACE,o.REPLACE),n.buffers.stencil.setFunc(o.ALWAYS,s,4294967295),n.buffers.stencil.setClear(c),n.buffers.stencil.setLocked(!0),t.setRenderTarget(a),this.clear&&t.clear(),t.render(this.scene,this.camera),t.setRenderTarget(e),this.clear&&t.clear(),t.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(o.EQUAL,1,4294967295),n.buffers.stencil.setOp(o.KEEP,o.KEEP,o.KEEP),n.buffers.stencil.setLocked(!0)}}class ze extends M{constructor(){super(),this.needsSwap=!1}render(t){t.state.buffers.stencil.setLocked(!1),t.state.buffers.stencil.setTest(!1)}}class Ue{constructor(t,e){if(this.renderer=t,this._pixelRatio=t.getPixelRatio(),e===void 0){const a=t.getSize(new i.Vector2);this._width=a.width,this._height=a.height,e=new i.WebGLRenderTarget(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:i.HalfFloatType}),e.texture.name="EffectComposer.rt1"}else this._width=e.width,this._height=e.height;this.renderTarget1=e,this.renderTarget2=e.clone(),this.renderTarget2.texture.name="EffectComposer.rt2",this.writeBuffer=this.renderTarget1,this.readBuffer=this.renderTarget2,this.renderToScreen=!0,this.passes=[],this.copyPass=new Ne(k),this.copyPass.material.blending=i.NoBlending,this.clock=new i.Clock}swapBuffers(){const t=this.readBuffer;this.readBuffer=this.writeBuffer,this.writeBuffer=t}addPass(t){this.passes.push(t),t.setSize(this._width*this._pixelRatio,this._height*this._pixelRatio)}insertPass(t,e){this.passes.splice(e,0,t),t.setSize(this._width*this._pixelRatio,this._height*this._pixelRatio)}removePass(t){const e=this.passes.indexOf(t);e!==-1&&this.passes.splice(e,1)}isLastEnabledPass(t){for(let e=t+1;e<this.passes.length;e++)if(this.passes[e].enabled)return!1;return!0}render(t){t===void 0&&(t=this.clock.getDelta());const e=this.renderer.getRenderTarget();let a=!1;for(let o=0,n=this.passes.length;o<n;o++){const s=this.passes[o];if(s.enabled!==!1){if(s.renderToScreen=this.renderToScreen&&this.isLastEnabledPass(o),s.render(this.renderer,this.writeBuffer,this.readBuffer,t,a),s.needsSwap){if(a){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,t),f.setFunc(c.EQUAL,1,4294967295)}this.swapBuffers()}q!==void 0&&(s instanceof q?a=!0:s instanceof ze&&(a=!1))}}this.renderer.setRenderTarget(e)}reset(t){if(t===void 0){const e=this.renderer.getSize(new i.Vector2);this._pixelRatio=this.renderer.getPixelRatio(),this._width=e.width,this._height=e.height,t=this.renderTarget1.clone(),t.setSize(this._width*this._pixelRatio,this._height*this._pixelRatio)}this.renderTarget1.dispose(),this.renderTarget2.dispose(),this.renderTarget1=t,this.renderTarget2=t.clone(),this.writeBuffer=this.renderTarget1,this.readBuffer=this.renderTarget2}setSize(t,e){this._width=t,this._height=e;const a=this._width*this._pixelRatio,o=this._height*this._pixelRatio;this.renderTarget1.setSize(a,o),this.renderTarget2.setSize(a,o);for(let n=0;n<this.passes.length;n++)this.passes[n].setSize(a,o)}setPixelRatio(t){this._pixelRatio=t,this.setSize(this._width,this._height)}dispose(){this.renderTarget1.dispose(),this.renderTarget2.dispose(),this.copyPass.dispose()}}class We extends M{constructor(t,e,a=null,o=null,n=null){super(),this.scene=t,this.camera=e,this.overrideMaterial=a,this.clearColor=o,this.clearAlpha=n,this.clear=!0,this.clearDepth=!1,this.needsSwap=!1,this._oldClearColor=new i.Color}render(t,e,a){const o=t.autoClear;t.autoClear=!1;let n,s;this.overrideMaterial!==null&&(s=this.scene.overrideMaterial,this.scene.overrideMaterial=this.overrideMaterial),this.clearColor!==null&&(t.getClearColor(this._oldClearColor),t.setClearColor(this.clearColor,t.getClearAlpha())),this.clearAlpha!==null&&(n=t.getClearAlpha(),t.setClearAlpha(this.clearAlpha)),this.clearDepth==!0&&t.clearDepth(),t.setRenderTarget(this.renderToScreen?null:a),this.clear===!0&&t.clear(t.autoClearColor,t.autoClearDepth,t.autoClearStencil),t.render(this.scene,this.camera),this.clearColor!==null&&t.setClearColor(this._oldClearColor),this.clearAlpha!==null&&t.setClearAlpha(n),this.overrideMaterial!==null&&(this.scene.overrideMaterial=s),t.autoClear=o}}const Q=Symbol("effectComposerThree"),Ge=r.defineComponent({__name:"EffectComposer",props:{enabled:{type:Boolean,default:!0},withoutRenderPass:{type:Boolean}},setup(l,{expose:t}){const e=l,a=r.shallowRef(null);r.provide(Q,a),t({composer:a});const{renderer:o,sizes:n,scene:s,camera:c,render:f}=b.useTresContext(),m=()=>{var h;(h=a.value)==null||h.dispose(),a.value=new Ue(o.value)};r.watchEffect(m),r.watchEffect(()=>{var v;const{width:h,height:A}=n;A.value&&h.value&&((v=a.value)==null||v.setSize(h.value,A.value))});const{pixelRatio:g}=W.useDevicePixelRatio();r.watchEffect(()=>{var h;(h=a.value)==null||h.setPixelRatio(g.value)}),e.withoutRenderPass||r.watchEffect(()=>{c.value&&s.value&&a.value&&a.value.addPass(new We(s.value,c.value))});const{render:S}=b.useLoop();return S(()=>{f.frames.value>0&&a.value&&e.enabled&&a.value.render(),f.frames.value=f.mode.value==="always"?1:Math.max(0,f.frames.value-1)}),r.onUnmounted(()=>{var h;(h=a.value)==null||h.dispose()}),(h,A)=>r.renderSlot(h.$slots,"default")}}),E=(l,t,e)=>{if(!t&&e)throw new Error("passDependencies is required when dependencyFieldsTriggeringRecreation is provided");const a=r.inject(Q),o=r.shallowRef(l()),{sizes:n,invalidate:s}=b.useTresContext();t&&r.watch(t,()=>s());const c=()=>{var m;(m=a==null?void 0:a.value)==null||m.removePass(o.value),o.value.dispose()},f=r.watchEffect(()=>{!(a!=null&&a.value)||!n.height.value||!n.width.value||(a.value.addPass(o.value),r.nextTick(()=>f()))});return e&&r.watch(()=>e.map(m=>t==null?void 0:t[m]),()=>{if(!(a!=null&&a.value))return;const m=a.value.passes.findIndex(g=>g===o.value);~m&&(c(),o.value=l(),a.value.insertPass(o.value,m))}),r.onUnmounted(()=>{c()}),{pass:o}},He={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 M{constructor(t=64){super();const e=He;this.uniforms=i.UniformsUtils.clone(e.uniforms),this.heightMap=this.generateHeightmap(t),this.uniforms.tDisp.value=this.heightMap,this.material=new i.ShaderMaterial({uniforms:this.uniforms,vertexShader:e.vertexShader,fragmentShader:e.fragmentShader}),this.fsQuad=new C(this.material),this.goWild=!1,this.curF=0,this.generateTrigger()}render(t,e,a){this.uniforms.tDiffuse.value=a.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=i.MathUtils.randFloat(-Math.PI,Math.PI),this.uniforms.seed_x.value=i.MathUtils.randFloat(-1,1),this.uniforms.seed_y.value=i.MathUtils.randFloat(-1,1),this.uniforms.distortion_x.value=i.MathUtils.randFloat(0,1),this.uniforms.distortion_y.value=i.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=i.MathUtils.randFloat(-Math.PI,Math.PI),this.uniforms.distortion_x.value=i.MathUtils.randFloat(0,1),this.uniforms.distortion_y.value=i.MathUtils.randFloat(0,1),this.uniforms.seed_x.value=i.MathUtils.randFloat(-.3,.3),this.uniforms.seed_y.value=i.MathUtils.randFloat(-.3,.3)):this.goWild==!1&&(this.uniforms.byp.value=1),this.curF++,this.renderToScreen?(t.setRenderTarget(null),this.fsQuad.render(t)):(t.setRenderTarget(e),this.clear&&t.clear(),this.fsQuad.render(t))}generateTrigger(){this.randX=i.MathUtils.randInt(120,240)}generateHeightmap(t){const e=new Float32Array(t*t),a=t*t;for(let n=0;n<a;n++){const s=i.MathUtils.randFloat(0,1);e[n]=s}const o=new i.DataTexture(e,t,t,i.RedFormat,i.FloatType);return o.needsUpdate=!0,o}dispose(){this.material.dispose(),this.heightMap.dispose(),this.fsQuad.dispose()}}const Ve=r.defineComponent({__name:"Glitch",props:{dtSize:{},goWild:{type:Boolean}},setup(l,{expose:t}){const e=l,{pass:a}=E(()=>new K(e.dtSize),e,["dtSize"]);t({pass:a});const{onBeforeRender:o}=b.useLoop();return o(({invalidate:n})=>n()),x([[()=>e.goWild,"goWild"]],a,()=>new K),()=>{}}}),O={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 - coor