softbox 4.6.0 → 4.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/dist/CopyShader-DPSZNOxL.cjs +24 -0
- package/dist/CopyShader-DVL8Bcar.js +41 -0
- package/dist/EffectComposer-BdHnHszK.js +188 -0
- package/dist/EffectComposer-D2IQ0sek.cjs +1 -0
- package/dist/OutputPass-Dy4KNHYF.cjs +72 -0
- package/dist/OutputPass-Tt8WbC_B.js +125 -0
- package/dist/Pass-C1mreNp8.cjs +1 -0
- package/dist/Pass-DOcH4lwV.js +88 -0
- package/dist/RenderPass-B57TYmjs.js +37 -0
- package/dist/RenderPass-BVzyKWsC.cjs +1 -0
- package/dist/ShaderPass-BQRqK8zp.cjs +1 -0
- package/dist/ShaderPass-C2HX8lsT.js +45 -0
- package/dist/{ThreePathTracingService-DdrIay3N.cjs → ThreePathTracingService-BgK90Qzi.cjs} +62 -62
- package/dist/{ThreePathTracingService-DlCiqA08.js → ThreePathTracingService-yfJv1Gh-.js} +446 -488
- package/dist/UnrealBloomPass-Kx7djcld.cjs +115 -0
- package/dist/UnrealBloomPass-rjyQu37v.js +281 -0
- package/dist/VignetteShader-BG_QwoTp.js +45 -0
- package/dist/VignetteShader-Drpo9YxI.cjs +27 -0
- package/dist/{index-DoB8YjQ9.js → index-C4Vga5nj.js} +2468 -2278
- package/dist/index-CPZ7CXqQ.cjs +29 -0
- package/dist/index.d.cts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/simple-viewer.cjs +1 -1
- package/dist/simple-viewer.es.js +1 -1
- package/package.json +1 -1
- package/dist/index-BA_1qZxy.cjs +0 -11
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("three"),d=require("./Pass-C1mreNp8.cjs"),c=require("./CopyShader-DPSZNOxL.cjs"),g={uniforms:{tDiffuse:{value:null},luminosityThreshold:{value:1},smoothWidth:{value:1},defaultColor:{value:new t.Color(0)},defaultOpacity:{value:0}},vertexShader:`
|
|
2
|
+
|
|
3
|
+
varying vec2 vUv;
|
|
4
|
+
|
|
5
|
+
void main() {
|
|
6
|
+
|
|
7
|
+
vUv = uv;
|
|
8
|
+
|
|
9
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
10
|
+
|
|
11
|
+
}`,fragmentShader:`
|
|
12
|
+
|
|
13
|
+
uniform sampler2D tDiffuse;
|
|
14
|
+
uniform vec3 defaultColor;
|
|
15
|
+
uniform float defaultOpacity;
|
|
16
|
+
uniform float luminosityThreshold;
|
|
17
|
+
uniform float smoothWidth;
|
|
18
|
+
|
|
19
|
+
varying vec2 vUv;
|
|
20
|
+
|
|
21
|
+
void main() {
|
|
22
|
+
|
|
23
|
+
vec4 texel = texture2D( tDiffuse, vUv );
|
|
24
|
+
|
|
25
|
+
float v = luminance( texel.xyz );
|
|
26
|
+
|
|
27
|
+
vec4 outputColor = vec4( defaultColor.rgb, defaultOpacity );
|
|
28
|
+
|
|
29
|
+
float alpha = smoothstep( luminosityThreshold, luminosityThreshold + smoothWidth, v );
|
|
30
|
+
|
|
31
|
+
gl_FragColor = mix( outputColor, texel, alpha );
|
|
32
|
+
|
|
33
|
+
}`};class h extends d.Pass{constructor(e,u=1,i,o){super(),this.strength=u,this.radius=i,this.threshold=o,this.resolution=e!==void 0?new t.Vector2(e.x,e.y):new t.Vector2(256,256),this.clearColor=new t.Color(0,0,0),this.needsSwap=!1,this.renderTargetsHorizontal=[],this.renderTargetsVertical=[],this.nMips=5;let r=Math.round(this.resolution.x/2),s=Math.round(this.resolution.y/2);this.renderTargetBright=new t.WebGLRenderTarget(r,s,{type:t.HalfFloatType}),this.renderTargetBright.texture.name="UnrealBloomPass.bright",this.renderTargetBright.texture.generateMipmaps=!1;for(let l=0;l<this.nMips;l++){const m=new t.WebGLRenderTarget(r,s,{type:t.HalfFloatType});m.texture.name="UnrealBloomPass.h"+l,m.texture.generateMipmaps=!1,this.renderTargetsHorizontal.push(m);const f=new t.WebGLRenderTarget(r,s,{type:t.HalfFloatType});f.texture.name="UnrealBloomPass.v"+l,f.texture.generateMipmaps=!1,this.renderTargetsVertical.push(f),r=Math.round(r/2),s=Math.round(s/2)}const n=g;this.highPassUniforms=t.UniformsUtils.clone(n.uniforms),this.highPassUniforms.luminosityThreshold.value=o,this.highPassUniforms.smoothWidth.value=.01,this.materialHighPassFilter=new t.ShaderMaterial({uniforms:this.highPassUniforms,vertexShader:n.vertexShader,fragmentShader:n.fragmentShader}),this.separableBlurMaterials=[];const a=[6,10,14,18,22];r=Math.round(this.resolution.x/2),s=Math.round(this.resolution.y/2);for(let l=0;l<this.nMips;l++)this.separableBlurMaterials.push(this._getSeparableBlurMaterial(a[l])),this.separableBlurMaterials[l].uniforms.invSize.value=new t.Vector2(1/r,1/s),r=Math.round(r/2),s=Math.round(s/2);this.compositeMaterial=this._getCompositeMaterial(this.nMips),this.compositeMaterial.uniforms.blurTexture1.value=this.renderTargetsVertical[0].texture,this.compositeMaterial.uniforms.blurTexture2.value=this.renderTargetsVertical[1].texture,this.compositeMaterial.uniforms.blurTexture3.value=this.renderTargetsVertical[2].texture,this.compositeMaterial.uniforms.blurTexture4.value=this.renderTargetsVertical[3].texture,this.compositeMaterial.uniforms.blurTexture5.value=this.renderTargetsVertical[4].texture,this.compositeMaterial.uniforms.bloomStrength.value=u,this.compositeMaterial.uniforms.bloomRadius.value=.1;const v=[1,.8,.6,.4,.2];this.compositeMaterial.uniforms.bloomFactors.value=v,this.bloomTintColors=[new t.Vector3(1,1,1),new t.Vector3(1,1,1),new t.Vector3(1,1,1),new t.Vector3(1,1,1),new t.Vector3(1,1,1)],this.compositeMaterial.uniforms.bloomTintColors.value=this.bloomTintColors,this.copyUniforms=t.UniformsUtils.clone(c.CopyShader.uniforms),this.blendMaterial=new t.ShaderMaterial({uniforms:this.copyUniforms,vertexShader:c.CopyShader.vertexShader,fragmentShader:c.CopyShader.fragmentShader,premultipliedAlpha:!0,blending:t.AdditiveBlending,depthTest:!1,depthWrite:!1,transparent:!0}),this._oldClearColor=new t.Color,this._oldClearAlpha=1,this._basic=new t.MeshBasicMaterial,this._fsQuad=new d.FullScreenQuad(null)}dispose(){for(let e=0;e<this.renderTargetsHorizontal.length;e++)this.renderTargetsHorizontal[e].dispose();for(let e=0;e<this.renderTargetsVertical.length;e++)this.renderTargetsVertical[e].dispose();this.renderTargetBright.dispose();for(let e=0;e<this.separableBlurMaterials.length;e++)this.separableBlurMaterials[e].dispose();this.compositeMaterial.dispose(),this.blendMaterial.dispose(),this._basic.dispose(),this._fsQuad.dispose()}setSize(e,u){let i=Math.round(e/2),o=Math.round(u/2);this.renderTargetBright.setSize(i,o);for(let r=0;r<this.nMips;r++)this.renderTargetsHorizontal[r].setSize(i,o),this.renderTargetsVertical[r].setSize(i,o),this.separableBlurMaterials[r].uniforms.invSize.value=new t.Vector2(1/i,1/o),i=Math.round(i/2),o=Math.round(o/2)}render(e,u,i,o,r){e.getClearColor(this._oldClearColor),this._oldClearAlpha=e.getClearAlpha();const s=e.autoClear;e.autoClear=!1,e.setClearColor(this.clearColor,0),r&&e.state.buffers.stencil.setTest(!1),this.renderToScreen&&(this._fsQuad.material=this._basic,this._basic.map=i.texture,e.setRenderTarget(null),e.clear(),this._fsQuad.render(e)),this.highPassUniforms.tDiffuse.value=i.texture,this.highPassUniforms.luminosityThreshold.value=this.threshold,this._fsQuad.material=this.materialHighPassFilter,e.setRenderTarget(this.renderTargetBright),e.clear(),this._fsQuad.render(e);let n=this.renderTargetBright;for(let a=0;a<this.nMips;a++)this._fsQuad.material=this.separableBlurMaterials[a],this.separableBlurMaterials[a].uniforms.colorTexture.value=n.texture,this.separableBlurMaterials[a].uniforms.direction.value=h.BlurDirectionX,e.setRenderTarget(this.renderTargetsHorizontal[a]),e.clear(),this._fsQuad.render(e),this.separableBlurMaterials[a].uniforms.colorTexture.value=this.renderTargetsHorizontal[a].texture,this.separableBlurMaterials[a].uniforms.direction.value=h.BlurDirectionY,e.setRenderTarget(this.renderTargetsVertical[a]),e.clear(),this._fsQuad.render(e),n=this.renderTargetsVertical[a];this._fsQuad.material=this.compositeMaterial,this.compositeMaterial.uniforms.bloomStrength.value=this.strength,this.compositeMaterial.uniforms.bloomRadius.value=this.radius,this.compositeMaterial.uniforms.bloomTintColors.value=this.bloomTintColors,e.setRenderTarget(this.renderTargetsHorizontal[0]),e.clear(),this._fsQuad.render(e),this._fsQuad.material=this.blendMaterial,this.copyUniforms.tDiffuse.value=this.renderTargetsHorizontal[0].texture,r&&e.state.buffers.stencil.setTest(!0),this.renderToScreen?(e.setRenderTarget(null),this._fsQuad.render(e)):(e.setRenderTarget(i),this._fsQuad.render(e)),e.setClearColor(this._oldClearColor,this._oldClearAlpha),e.autoClear=s}_getSeparableBlurMaterial(e){const u=[],i=e/3;for(let o=0;o<e;o++)u.push(.39894*Math.exp(-.5*o*o/(i*i))/i);return new t.ShaderMaterial({defines:{KERNEL_RADIUS:e},uniforms:{colorTexture:{value:null},invSize:{value:new t.Vector2(.5,.5)},direction:{value:new t.Vector2(.5,.5)},gaussianCoefficients:{value:u}},vertexShader:`
|
|
34
|
+
|
|
35
|
+
varying vec2 vUv;
|
|
36
|
+
|
|
37
|
+
void main() {
|
|
38
|
+
|
|
39
|
+
vUv = uv;
|
|
40
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
41
|
+
|
|
42
|
+
}`,fragmentShader:`
|
|
43
|
+
|
|
44
|
+
#include <common>
|
|
45
|
+
|
|
46
|
+
varying vec2 vUv;
|
|
47
|
+
|
|
48
|
+
uniform sampler2D colorTexture;
|
|
49
|
+
uniform vec2 invSize;
|
|
50
|
+
uniform vec2 direction;
|
|
51
|
+
uniform float gaussianCoefficients[KERNEL_RADIUS];
|
|
52
|
+
|
|
53
|
+
void main() {
|
|
54
|
+
|
|
55
|
+
float weightSum = gaussianCoefficients[0];
|
|
56
|
+
vec3 diffuseSum = texture2D( colorTexture, vUv ).rgb * weightSum;
|
|
57
|
+
|
|
58
|
+
for ( int i = 1; i < KERNEL_RADIUS; i ++ ) {
|
|
59
|
+
|
|
60
|
+
float x = float( i );
|
|
61
|
+
float w = gaussianCoefficients[i];
|
|
62
|
+
vec2 uvOffset = direction * invSize * x;
|
|
63
|
+
vec3 sample1 = texture2D( colorTexture, vUv + uvOffset ).rgb;
|
|
64
|
+
vec3 sample2 = texture2D( colorTexture, vUv - uvOffset ).rgb;
|
|
65
|
+
diffuseSum += ( sample1 + sample2 ) * w;
|
|
66
|
+
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
gl_FragColor = vec4( diffuseSum, 1.0 );
|
|
70
|
+
|
|
71
|
+
}`})}_getCompositeMaterial(e){return new t.ShaderMaterial({defines:{NUM_MIPS:e},uniforms:{blurTexture1:{value:null},blurTexture2:{value:null},blurTexture3:{value:null},blurTexture4:{value:null},blurTexture5:{value:null},bloomStrength:{value:1},bloomFactors:{value:null},bloomTintColors:{value:null},bloomRadius:{value:0}},vertexShader:`
|
|
72
|
+
|
|
73
|
+
varying vec2 vUv;
|
|
74
|
+
|
|
75
|
+
void main() {
|
|
76
|
+
|
|
77
|
+
vUv = uv;
|
|
78
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
79
|
+
|
|
80
|
+
}`,fragmentShader:`
|
|
81
|
+
|
|
82
|
+
varying vec2 vUv;
|
|
83
|
+
|
|
84
|
+
uniform sampler2D blurTexture1;
|
|
85
|
+
uniform sampler2D blurTexture2;
|
|
86
|
+
uniform sampler2D blurTexture3;
|
|
87
|
+
uniform sampler2D blurTexture4;
|
|
88
|
+
uniform sampler2D blurTexture5;
|
|
89
|
+
uniform float bloomStrength;
|
|
90
|
+
uniform float bloomRadius;
|
|
91
|
+
uniform float bloomFactors[NUM_MIPS];
|
|
92
|
+
uniform vec3 bloomTintColors[NUM_MIPS];
|
|
93
|
+
|
|
94
|
+
float lerpBloomFactor( const in float factor ) {
|
|
95
|
+
|
|
96
|
+
float mirrorFactor = 1.2 - factor;
|
|
97
|
+
return mix( factor, mirrorFactor, bloomRadius );
|
|
98
|
+
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
void main() {
|
|
102
|
+
|
|
103
|
+
// 3.0 for backwards compatibility with previous alpha-based intensity
|
|
104
|
+
vec3 bloom = 3.0 * bloomStrength * (
|
|
105
|
+
lerpBloomFactor( bloomFactors[ 0 ] ) * bloomTintColors[ 0 ] * texture2D( blurTexture1, vUv ).rgb +
|
|
106
|
+
lerpBloomFactor( bloomFactors[ 1 ] ) * bloomTintColors[ 1 ] * texture2D( blurTexture2, vUv ).rgb +
|
|
107
|
+
lerpBloomFactor( bloomFactors[ 2 ] ) * bloomTintColors[ 2 ] * texture2D( blurTexture3, vUv ).rgb +
|
|
108
|
+
lerpBloomFactor( bloomFactors[ 3 ] ) * bloomTintColors[ 3 ] * texture2D( blurTexture4, vUv ).rgb +
|
|
109
|
+
lerpBloomFactor( bloomFactors[ 4 ] ) * bloomTintColors[ 4 ] * texture2D( blurTexture5, vUv ).rgb
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
float bloomAlpha = max( bloom.r, max( bloom.g, bloom.b ) );
|
|
113
|
+
gl_FragColor = vec4( bloom, bloomAlpha );
|
|
114
|
+
|
|
115
|
+
}`})}}h.BlurDirectionX=new t.Vector2(1,0);h.BlurDirectionY=new t.Vector2(0,1);exports.UnrealBloomPass=h;
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { Color as b, Vector2 as u, WebGLRenderTarget as v, HalfFloatType as p, UniformsUtils as T, ShaderMaterial as f, Vector3 as h, AdditiveBlending as M, MeshBasicMaterial as C } from "three";
|
|
2
|
+
import { P as S, F as _ } from "./Pass-DOcH4lwV.js";
|
|
3
|
+
import { C as g } from "./CopyShader-DVL8Bcar.js";
|
|
4
|
+
const U = {
|
|
5
|
+
uniforms: {
|
|
6
|
+
tDiffuse: { value: null },
|
|
7
|
+
luminosityThreshold: { value: 1 },
|
|
8
|
+
smoothWidth: { value: 1 },
|
|
9
|
+
defaultColor: { value: new b(0) },
|
|
10
|
+
defaultOpacity: { value: 0 }
|
|
11
|
+
},
|
|
12
|
+
vertexShader: (
|
|
13
|
+
/* glsl */
|
|
14
|
+
`
|
|
15
|
+
|
|
16
|
+
varying vec2 vUv;
|
|
17
|
+
|
|
18
|
+
void main() {
|
|
19
|
+
|
|
20
|
+
vUv = uv;
|
|
21
|
+
|
|
22
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
23
|
+
|
|
24
|
+
}`
|
|
25
|
+
),
|
|
26
|
+
fragmentShader: (
|
|
27
|
+
/* glsl */
|
|
28
|
+
`
|
|
29
|
+
|
|
30
|
+
uniform sampler2D tDiffuse;
|
|
31
|
+
uniform vec3 defaultColor;
|
|
32
|
+
uniform float defaultOpacity;
|
|
33
|
+
uniform float luminosityThreshold;
|
|
34
|
+
uniform float smoothWidth;
|
|
35
|
+
|
|
36
|
+
varying vec2 vUv;
|
|
37
|
+
|
|
38
|
+
void main() {
|
|
39
|
+
|
|
40
|
+
vec4 texel = texture2D( tDiffuse, vUv );
|
|
41
|
+
|
|
42
|
+
float v = luminance( texel.xyz );
|
|
43
|
+
|
|
44
|
+
vec4 outputColor = vec4( defaultColor.rgb, defaultOpacity );
|
|
45
|
+
|
|
46
|
+
float alpha = smoothstep( luminosityThreshold, luminosityThreshold + smoothWidth, v );
|
|
47
|
+
|
|
48
|
+
gl_FragColor = mix( outputColor, texel, alpha );
|
|
49
|
+
|
|
50
|
+
}`
|
|
51
|
+
)
|
|
52
|
+
};
|
|
53
|
+
class m extends S {
|
|
54
|
+
/**
|
|
55
|
+
* Constructs a new Unreal Bloom pass.
|
|
56
|
+
*
|
|
57
|
+
* @param {Vector2} [resolution] - The effect's resolution.
|
|
58
|
+
* @param {number} [strength=1] - The Bloom strength.
|
|
59
|
+
* @param {number} radius - The Bloom radius.
|
|
60
|
+
* @param {number} threshold - The luminance threshold limits which bright areas contribute to the Bloom effect.
|
|
61
|
+
*/
|
|
62
|
+
constructor(e, l = 1, r, i) {
|
|
63
|
+
super(), this.strength = l, this.radius = r, this.threshold = i, this.resolution = e !== void 0 ? new u(e.x, e.y) : new u(256, 256), this.clearColor = new b(0, 0, 0), this.needsSwap = !1, this.renderTargetsHorizontal = [], this.renderTargetsVertical = [], this.nMips = 5;
|
|
64
|
+
let t = Math.round(this.resolution.x / 2), a = Math.round(this.resolution.y / 2);
|
|
65
|
+
this.renderTargetBright = new v(t, a, { type: p }), this.renderTargetBright.texture.name = "UnrealBloomPass.bright", this.renderTargetBright.texture.generateMipmaps = !1;
|
|
66
|
+
for (let s = 0; s < this.nMips; s++) {
|
|
67
|
+
const c = new v(t, a, { type: p });
|
|
68
|
+
c.texture.name = "UnrealBloomPass.h" + s, c.texture.generateMipmaps = !1, this.renderTargetsHorizontal.push(c);
|
|
69
|
+
const d = new v(t, a, { type: p });
|
|
70
|
+
d.texture.name = "UnrealBloomPass.v" + s, d.texture.generateMipmaps = !1, this.renderTargetsVertical.push(d), t = Math.round(t / 2), a = Math.round(a / 2);
|
|
71
|
+
}
|
|
72
|
+
const n = U;
|
|
73
|
+
this.highPassUniforms = T.clone(n.uniforms), this.highPassUniforms.luminosityThreshold.value = i, this.highPassUniforms.smoothWidth.value = 0.01, this.materialHighPassFilter = new f({
|
|
74
|
+
uniforms: this.highPassUniforms,
|
|
75
|
+
vertexShader: n.vertexShader,
|
|
76
|
+
fragmentShader: n.fragmentShader
|
|
77
|
+
}), this.separableBlurMaterials = [];
|
|
78
|
+
const o = [6, 10, 14, 18, 22];
|
|
79
|
+
t = Math.round(this.resolution.x / 2), a = Math.round(this.resolution.y / 2);
|
|
80
|
+
for (let s = 0; s < this.nMips; s++)
|
|
81
|
+
this.separableBlurMaterials.push(this._getSeparableBlurMaterial(o[s])), this.separableBlurMaterials[s].uniforms.invSize.value = new u(1 / t, 1 / a), t = Math.round(t / 2), a = Math.round(a / 2);
|
|
82
|
+
this.compositeMaterial = this._getCompositeMaterial(this.nMips), this.compositeMaterial.uniforms.blurTexture1.value = this.renderTargetsVertical[0].texture, this.compositeMaterial.uniforms.blurTexture2.value = this.renderTargetsVertical[1].texture, this.compositeMaterial.uniforms.blurTexture3.value = this.renderTargetsVertical[2].texture, this.compositeMaterial.uniforms.blurTexture4.value = this.renderTargetsVertical[3].texture, this.compositeMaterial.uniforms.blurTexture5.value = this.renderTargetsVertical[4].texture, this.compositeMaterial.uniforms.bloomStrength.value = l, this.compositeMaterial.uniforms.bloomRadius.value = 0.1;
|
|
83
|
+
const x = [1, 0.8, 0.6, 0.4, 0.2];
|
|
84
|
+
this.compositeMaterial.uniforms.bloomFactors.value = x, this.bloomTintColors = [new h(1, 1, 1), new h(1, 1, 1), new h(1, 1, 1), new h(1, 1, 1), new h(1, 1, 1)], this.compositeMaterial.uniforms.bloomTintColors.value = this.bloomTintColors, this.copyUniforms = T.clone(g.uniforms), this.blendMaterial = new f({
|
|
85
|
+
uniforms: this.copyUniforms,
|
|
86
|
+
vertexShader: g.vertexShader,
|
|
87
|
+
fragmentShader: g.fragmentShader,
|
|
88
|
+
premultipliedAlpha: !0,
|
|
89
|
+
blending: M,
|
|
90
|
+
depthTest: !1,
|
|
91
|
+
depthWrite: !1,
|
|
92
|
+
transparent: !0
|
|
93
|
+
}), this._oldClearColor = new b(), this._oldClearAlpha = 1, this._basic = new C(), this._fsQuad = new _(null);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Frees the GPU-related resources allocated by this instance. Call this
|
|
97
|
+
* method whenever the pass is no longer used in your app.
|
|
98
|
+
*/
|
|
99
|
+
dispose() {
|
|
100
|
+
for (let e = 0; e < this.renderTargetsHorizontal.length; e++)
|
|
101
|
+
this.renderTargetsHorizontal[e].dispose();
|
|
102
|
+
for (let e = 0; e < this.renderTargetsVertical.length; e++)
|
|
103
|
+
this.renderTargetsVertical[e].dispose();
|
|
104
|
+
this.renderTargetBright.dispose();
|
|
105
|
+
for (let e = 0; e < this.separableBlurMaterials.length; e++)
|
|
106
|
+
this.separableBlurMaterials[e].dispose();
|
|
107
|
+
this.compositeMaterial.dispose(), this.blendMaterial.dispose(), this._basic.dispose(), this._fsQuad.dispose();
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Sets the size of the pass.
|
|
111
|
+
*
|
|
112
|
+
* @param {number} width - The width to set.
|
|
113
|
+
* @param {number} height - The height to set.
|
|
114
|
+
*/
|
|
115
|
+
setSize(e, l) {
|
|
116
|
+
let r = Math.round(e / 2), i = Math.round(l / 2);
|
|
117
|
+
this.renderTargetBright.setSize(r, i);
|
|
118
|
+
for (let t = 0; t < this.nMips; t++)
|
|
119
|
+
this.renderTargetsHorizontal[t].setSize(r, i), this.renderTargetsVertical[t].setSize(r, i), this.separableBlurMaterials[t].uniforms.invSize.value = new u(1 / r, 1 / i), r = Math.round(r / 2), i = Math.round(i / 2);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Performs the Bloom pass.
|
|
123
|
+
*
|
|
124
|
+
* @param {WebGLRenderer} renderer - The renderer.
|
|
125
|
+
* @param {WebGLRenderTarget} writeBuffer - The write buffer. This buffer is intended as the rendering
|
|
126
|
+
* destination for the pass.
|
|
127
|
+
* @param {WebGLRenderTarget} readBuffer - The read buffer. The pass can access the result from the
|
|
128
|
+
* previous pass from this buffer.
|
|
129
|
+
* @param {number} deltaTime - The delta time in seconds.
|
|
130
|
+
* @param {boolean} maskActive - Whether masking is active or not.
|
|
131
|
+
*/
|
|
132
|
+
render(e, l, r, i, t) {
|
|
133
|
+
e.getClearColor(this._oldClearColor), this._oldClearAlpha = e.getClearAlpha();
|
|
134
|
+
const a = e.autoClear;
|
|
135
|
+
e.autoClear = !1, e.setClearColor(this.clearColor, 0), t && e.state.buffers.stencil.setTest(!1), this.renderToScreen && (this._fsQuad.material = this._basic, this._basic.map = r.texture, e.setRenderTarget(null), e.clear(), this._fsQuad.render(e)), this.highPassUniforms.tDiffuse.value = r.texture, this.highPassUniforms.luminosityThreshold.value = this.threshold, this._fsQuad.material = this.materialHighPassFilter, e.setRenderTarget(this.renderTargetBright), e.clear(), this._fsQuad.render(e);
|
|
136
|
+
let n = this.renderTargetBright;
|
|
137
|
+
for (let o = 0; o < this.nMips; o++)
|
|
138
|
+
this._fsQuad.material = this.separableBlurMaterials[o], this.separableBlurMaterials[o].uniforms.colorTexture.value = n.texture, this.separableBlurMaterials[o].uniforms.direction.value = m.BlurDirectionX, e.setRenderTarget(this.renderTargetsHorizontal[o]), e.clear(), this._fsQuad.render(e), this.separableBlurMaterials[o].uniforms.colorTexture.value = this.renderTargetsHorizontal[o].texture, this.separableBlurMaterials[o].uniforms.direction.value = m.BlurDirectionY, e.setRenderTarget(this.renderTargetsVertical[o]), e.clear(), this._fsQuad.render(e), n = this.renderTargetsVertical[o];
|
|
139
|
+
this._fsQuad.material = this.compositeMaterial, this.compositeMaterial.uniforms.bloomStrength.value = this.strength, this.compositeMaterial.uniforms.bloomRadius.value = this.radius, this.compositeMaterial.uniforms.bloomTintColors.value = this.bloomTintColors, e.setRenderTarget(this.renderTargetsHorizontal[0]), e.clear(), this._fsQuad.render(e), this._fsQuad.material = this.blendMaterial, this.copyUniforms.tDiffuse.value = this.renderTargetsHorizontal[0].texture, t && e.state.buffers.stencil.setTest(!0), this.renderToScreen ? (e.setRenderTarget(null), this._fsQuad.render(e)) : (e.setRenderTarget(r), this._fsQuad.render(e)), e.setClearColor(this._oldClearColor, this._oldClearAlpha), e.autoClear = a;
|
|
140
|
+
}
|
|
141
|
+
// internals
|
|
142
|
+
_getSeparableBlurMaterial(e) {
|
|
143
|
+
const l = [], r = e / 3;
|
|
144
|
+
for (let i = 0; i < e; i++)
|
|
145
|
+
l.push(0.39894 * Math.exp(-0.5 * i * i / (r * r)) / r);
|
|
146
|
+
return new f({
|
|
147
|
+
defines: {
|
|
148
|
+
KERNEL_RADIUS: e
|
|
149
|
+
},
|
|
150
|
+
uniforms: {
|
|
151
|
+
colorTexture: { value: null },
|
|
152
|
+
invSize: { value: new u(0.5, 0.5) },
|
|
153
|
+
// inverse texture size
|
|
154
|
+
direction: { value: new u(0.5, 0.5) },
|
|
155
|
+
gaussianCoefficients: { value: l }
|
|
156
|
+
// precomputed Gaussian coefficients
|
|
157
|
+
},
|
|
158
|
+
vertexShader: (
|
|
159
|
+
/* glsl */
|
|
160
|
+
`
|
|
161
|
+
|
|
162
|
+
varying vec2 vUv;
|
|
163
|
+
|
|
164
|
+
void main() {
|
|
165
|
+
|
|
166
|
+
vUv = uv;
|
|
167
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
168
|
+
|
|
169
|
+
}`
|
|
170
|
+
),
|
|
171
|
+
fragmentShader: (
|
|
172
|
+
/* glsl */
|
|
173
|
+
`
|
|
174
|
+
|
|
175
|
+
#include <common>
|
|
176
|
+
|
|
177
|
+
varying vec2 vUv;
|
|
178
|
+
|
|
179
|
+
uniform sampler2D colorTexture;
|
|
180
|
+
uniform vec2 invSize;
|
|
181
|
+
uniform vec2 direction;
|
|
182
|
+
uniform float gaussianCoefficients[KERNEL_RADIUS];
|
|
183
|
+
|
|
184
|
+
void main() {
|
|
185
|
+
|
|
186
|
+
float weightSum = gaussianCoefficients[0];
|
|
187
|
+
vec3 diffuseSum = texture2D( colorTexture, vUv ).rgb * weightSum;
|
|
188
|
+
|
|
189
|
+
for ( int i = 1; i < KERNEL_RADIUS; i ++ ) {
|
|
190
|
+
|
|
191
|
+
float x = float( i );
|
|
192
|
+
float w = gaussianCoefficients[i];
|
|
193
|
+
vec2 uvOffset = direction * invSize * x;
|
|
194
|
+
vec3 sample1 = texture2D( colorTexture, vUv + uvOffset ).rgb;
|
|
195
|
+
vec3 sample2 = texture2D( colorTexture, vUv - uvOffset ).rgb;
|
|
196
|
+
diffuseSum += ( sample1 + sample2 ) * w;
|
|
197
|
+
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
gl_FragColor = vec4( diffuseSum, 1.0 );
|
|
201
|
+
|
|
202
|
+
}`
|
|
203
|
+
)
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
_getCompositeMaterial(e) {
|
|
207
|
+
return new f({
|
|
208
|
+
defines: {
|
|
209
|
+
NUM_MIPS: e
|
|
210
|
+
},
|
|
211
|
+
uniforms: {
|
|
212
|
+
blurTexture1: { value: null },
|
|
213
|
+
blurTexture2: { value: null },
|
|
214
|
+
blurTexture3: { value: null },
|
|
215
|
+
blurTexture4: { value: null },
|
|
216
|
+
blurTexture5: { value: null },
|
|
217
|
+
bloomStrength: { value: 1 },
|
|
218
|
+
bloomFactors: { value: null },
|
|
219
|
+
bloomTintColors: { value: null },
|
|
220
|
+
bloomRadius: { value: 0 }
|
|
221
|
+
},
|
|
222
|
+
vertexShader: (
|
|
223
|
+
/* glsl */
|
|
224
|
+
`
|
|
225
|
+
|
|
226
|
+
varying vec2 vUv;
|
|
227
|
+
|
|
228
|
+
void main() {
|
|
229
|
+
|
|
230
|
+
vUv = uv;
|
|
231
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
232
|
+
|
|
233
|
+
}`
|
|
234
|
+
),
|
|
235
|
+
fragmentShader: (
|
|
236
|
+
/* glsl */
|
|
237
|
+
`
|
|
238
|
+
|
|
239
|
+
varying vec2 vUv;
|
|
240
|
+
|
|
241
|
+
uniform sampler2D blurTexture1;
|
|
242
|
+
uniform sampler2D blurTexture2;
|
|
243
|
+
uniform sampler2D blurTexture3;
|
|
244
|
+
uniform sampler2D blurTexture4;
|
|
245
|
+
uniform sampler2D blurTexture5;
|
|
246
|
+
uniform float bloomStrength;
|
|
247
|
+
uniform float bloomRadius;
|
|
248
|
+
uniform float bloomFactors[NUM_MIPS];
|
|
249
|
+
uniform vec3 bloomTintColors[NUM_MIPS];
|
|
250
|
+
|
|
251
|
+
float lerpBloomFactor( const in float factor ) {
|
|
252
|
+
|
|
253
|
+
float mirrorFactor = 1.2 - factor;
|
|
254
|
+
return mix( factor, mirrorFactor, bloomRadius );
|
|
255
|
+
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
void main() {
|
|
259
|
+
|
|
260
|
+
// 3.0 for backwards compatibility with previous alpha-based intensity
|
|
261
|
+
vec3 bloom = 3.0 * bloomStrength * (
|
|
262
|
+
lerpBloomFactor( bloomFactors[ 0 ] ) * bloomTintColors[ 0 ] * texture2D( blurTexture1, vUv ).rgb +
|
|
263
|
+
lerpBloomFactor( bloomFactors[ 1 ] ) * bloomTintColors[ 1 ] * texture2D( blurTexture2, vUv ).rgb +
|
|
264
|
+
lerpBloomFactor( bloomFactors[ 2 ] ) * bloomTintColors[ 2 ] * texture2D( blurTexture3, vUv ).rgb +
|
|
265
|
+
lerpBloomFactor( bloomFactors[ 3 ] ) * bloomTintColors[ 3 ] * texture2D( blurTexture4, vUv ).rgb +
|
|
266
|
+
lerpBloomFactor( bloomFactors[ 4 ] ) * bloomTintColors[ 4 ] * texture2D( blurTexture5, vUv ).rgb
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
float bloomAlpha = max( bloom.r, max( bloom.g, bloom.b ) );
|
|
270
|
+
gl_FragColor = vec4( bloom, bloomAlpha );
|
|
271
|
+
|
|
272
|
+
}`
|
|
273
|
+
)
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
m.BlurDirectionX = new u(1, 0);
|
|
278
|
+
m.BlurDirectionY = new u(0, 1);
|
|
279
|
+
export {
|
|
280
|
+
m as UnrealBloomPass
|
|
281
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const e = {
|
|
2
|
+
name: "VignetteShader",
|
|
3
|
+
uniforms: {
|
|
4
|
+
tDiffuse: { value: null },
|
|
5
|
+
offset: { value: 1 },
|
|
6
|
+
darkness: { value: 1 }
|
|
7
|
+
},
|
|
8
|
+
vertexShader: (
|
|
9
|
+
/* glsl */
|
|
10
|
+
`
|
|
11
|
+
|
|
12
|
+
varying vec2 vUv;
|
|
13
|
+
|
|
14
|
+
void main() {
|
|
15
|
+
|
|
16
|
+
vUv = uv;
|
|
17
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
18
|
+
|
|
19
|
+
}`
|
|
20
|
+
),
|
|
21
|
+
fragmentShader: (
|
|
22
|
+
/* glsl */
|
|
23
|
+
`
|
|
24
|
+
|
|
25
|
+
uniform float offset;
|
|
26
|
+
uniform float darkness;
|
|
27
|
+
|
|
28
|
+
uniform sampler2D tDiffuse;
|
|
29
|
+
|
|
30
|
+
varying vec2 vUv;
|
|
31
|
+
|
|
32
|
+
void main() {
|
|
33
|
+
|
|
34
|
+
// Eskil's vignette
|
|
35
|
+
|
|
36
|
+
vec4 texel = texture2D( tDiffuse, vUv );
|
|
37
|
+
vec2 uv = ( vUv - vec2( 0.5 ) ) * vec2( offset );
|
|
38
|
+
gl_FragColor = vec4( mix( texel.rgb, vec3( 1.0 - darkness ), dot( uv, uv ) ), texel.a );
|
|
39
|
+
|
|
40
|
+
}`
|
|
41
|
+
)
|
|
42
|
+
};
|
|
43
|
+
export {
|
|
44
|
+
e as VignetteShader
|
|
45
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e={name:"VignetteShader",uniforms:{tDiffuse:{value:null},offset:{value:1},darkness:{value:1}},vertexShader:`
|
|
2
|
+
|
|
3
|
+
varying vec2 vUv;
|
|
4
|
+
|
|
5
|
+
void main() {
|
|
6
|
+
|
|
7
|
+
vUv = uv;
|
|
8
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
9
|
+
|
|
10
|
+
}`,fragmentShader:`
|
|
11
|
+
|
|
12
|
+
uniform float offset;
|
|
13
|
+
uniform float darkness;
|
|
14
|
+
|
|
15
|
+
uniform sampler2D tDiffuse;
|
|
16
|
+
|
|
17
|
+
varying vec2 vUv;
|
|
18
|
+
|
|
19
|
+
void main() {
|
|
20
|
+
|
|
21
|
+
// Eskil's vignette
|
|
22
|
+
|
|
23
|
+
vec4 texel = texture2D( tDiffuse, vUv );
|
|
24
|
+
vec2 uv = ( vUv - vec2( 0.5 ) ) * vec2( offset );
|
|
25
|
+
gl_FragColor = vec4( mix( texel.rgb, vec3( 1.0 - darkness ), dot( uv, uv ) ), texel.a );
|
|
26
|
+
|
|
27
|
+
}`};exports.VignetteShader=e;
|