three-stdlib 2.20.0 → 2.20.2
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/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),r=require("./Pass.cjs.js"),t=require("../shaders/CopyShader.cjs.js"),i=require("../shaders/LuminosityHighPassShader.cjs.js");require("@babel/runtime/helpers/defineProperty");var a=function(a,o,s,l){this.strength=void 0!==o?o:1,this.radius=s,this.threshold=l,this.resolution=void 0!==a?new e.Vector2(a.x,a.y):new e.Vector2(256,256),this.clearColor=new e.Color(0,0,0);var n={minFilter:e.LinearFilter,magFilter:e.LinearFilter,format:e.RGBAFormat};this.renderTargetsHorizontal=[],this.renderTargetsVertical=[],this.nMips=5;var u=Math.round(this.resolution.x/2),h=Math.round(this.resolution.y/2);this.renderTargetBright=new e.WebGLRenderTarget(u,h,n),this.renderTargetBright.texture.name="UnrealBloomPass.bright",this.renderTargetBright.texture.generateMipmaps=!1;for(let r=0;r<this.nMips;r++){var m=new e.WebGLRenderTarget(u,h,n);m.texture.name="UnrealBloomPass.h"+r,m.texture.generateMipmaps=!1,this.renderTargetsHorizontal.push(m);var d=new e.WebGLRenderTarget(u,h,n);d.texture.name="UnrealBloomPass.v"+r,d.texture.generateMipmaps=!1,this.renderTargetsVertical.push(d),u=Math.round(u/2),h=Math.round(h/2)}void 0===i.LuminosityHighPassShader&&console.error("THREE.UnrealBloomPass relies on LuminosityHighPassShader");var c=i.LuminosityHighPassShader;this.highPassUniforms=e.UniformsUtils.clone(c.uniforms),this.highPassUniforms.luminosityThreshold.value=l,this.highPassUniforms.smoothWidth.value=.01,this.materialHighPassFilter=new e.ShaderMaterial({uniforms:this.highPassUniforms,vertexShader:c.vertexShader,fragmentShader:c.fragmentShader,defines:{}}),this.separableBlurMaterials=[];var f=[3,5,7,9,11];u=Math.round(this.resolution.x/2),h=Math.round(this.resolution.y/2);for(let r=0;r<this.nMips;r++)this.separableBlurMaterials.push(this.getSeperableBlurMaterial(f[r])),this.separableBlurMaterials[r].uniforms.texSize.value=new e.Vector2(u,h),u=Math.round(u/2),h=Math.round(h/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=o,this.compositeMaterial.uniforms.bloomRadius.value=.1,this.compositeMaterial.needsUpdate=!0;this.compositeMaterial.uniforms.bloomFactors.value=[1,.8,.6,.4,.2],this.bloomTintColors=[new e.Vector3(1,1,1),new e.Vector3(1,1,1),new e.Vector3(1,1,1),new e.Vector3(1,1,1),new e.Vector3(1,1,1)],this.compositeMaterial.uniforms.bloomTintColors.value=this.bloomTintColors,void 0===t.CopyShader&&console.error("THREE.UnrealBloomPass relies on CopyShader");var v=t.CopyShader;this.copyUniforms=e.UniformsUtils.clone(v.uniforms),this.copyUniforms.opacity.value=1,this.materialCopy=new e.ShaderMaterial({uniforms:this.copyUniforms,vertexShader:v.vertexShader,fragmentShader:v.fragmentShader,blending:e.AdditiveBlending,depthTest:!1,depthWrite:!1,transparent:!0}),this.enabled=!0,this.needsSwap=!1,this._oldClearColor=new e.Color,this.oldClearAlpha=1,this.basic=new e.MeshBasicMaterial,this.fsQuad=new r.FullScreenQuad(null)};a.prototype=Object.assign(Object.create(r.Pass.prototype),{constructor:a,dispose:function(){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()},setSize:function(r,t){var i=Math.round(r/2),a=Math.round(t/2);this.renderTargetBright.setSize(i,a);for(let r=0;r<this.nMips;r++)this.renderTargetsHorizontal[r].setSize(i,a),this.renderTargetsVertical[r].setSize(i,a),this.separableBlurMaterials[r].uniforms.texSize.value=new e.Vector2(i,a),i=Math.round(i/2),a=Math.round(a/2)},render:function(e,r,t,i,o){e.getClearColor(this._oldClearColor),this.oldClearAlpha=e.getClearAlpha();var s=e.autoClear;e.autoClear=!1,e.setClearColor(this.clearColor,0),o&&e.state.buffers.stencil.setTest(!1),this.renderToScreen&&(this.fsQuad.material=this.basic,this.basic.map=t.texture,e.setRenderTarget(null),e.clear(),this.fsQuad.render(e)),this.highPassUniforms.tDiffuse.value=t.texture,this.highPassUniforms.luminosityThreshold.value=this.threshold,this.fsQuad.material=this.materialHighPassFilter,e.setRenderTarget(this.renderTargetBright),e.clear(),this.fsQuad.render(e);var l=this.renderTargetBright;for(let r=0;r<this.nMips;r++)this.fsQuad.material=this.separableBlurMaterials[r],this.separableBlurMaterials[r].uniforms.colorTexture.value=l.texture,this.separableBlurMaterials[r].uniforms.direction.value=a.BlurDirectionX,e.setRenderTarget(this.renderTargetsHorizontal[r]),e.clear(),this.fsQuad.render(e),this.separableBlurMaterials[r].uniforms.colorTexture.value=this.renderTargetsHorizontal[r].texture,this.separableBlurMaterials[r].uniforms.direction.value=a.BlurDirectionY,e.setRenderTarget(this.renderTargetsVertical[r]),e.clear(),this.fsQuad.render(e),l=this.renderTargetsVertical[r];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.materialCopy,this.copyUniforms.tDiffuse.value=this.renderTargetsHorizontal[0].texture,o&&e.state.buffers.stencil.setTest(!0),this.renderToScreen?(e.setRenderTarget(null),this.fsQuad.render(e)):(e.setRenderTarget(t),this.fsQuad.render(e)),e.setClearColor(this._oldClearColor,this.oldClearAlpha),e.autoClear=s},getSeperableBlurMaterial:function(r){return new e.ShaderMaterial({defines:{KERNEL_RADIUS:r,SIGMA:r},uniforms:{colorTexture:{value:null},texSize:{value:new e.Vector2(.5,.5)},direction:{value:new e.Vector2(.5,.5)}},vertexShader:"varying vec2 vUv;\nvoid main() {\n\tvUv = uv;\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",fragmentShader:"#include <common>varying vec2 vUv;\nuniform sampler2D colorTexture;\nuniform vec2 texSize;uniform vec2 direction;\nfloat gaussianPdf(in float x, in float sigma) {\treturn 0.39894 * exp( -0.5 * x * x/( sigma * sigma))/sigma;}void main() {\n\tvec2 invSize = 1.0 / texSize;\tfloat fSigma = float(SIGMA);\tfloat weightSum = gaussianPdf(0.0, fSigma);\tvec3 diffuseSum = texture2D( colorTexture, vUv).rgb * weightSum;\tfor( int i = 1; i < KERNEL_RADIUS; i ++ ) {\t\tfloat x = float(i);\t\tfloat w = gaussianPdf(x, fSigma);\t\tvec2 uvOffset = direction * invSize * x;\t\tvec3 sample1 = texture2D( colorTexture, vUv + uvOffset).rgb;\t\tvec3 sample2 = texture2D( colorTexture, vUv - uvOffset).rgb;\t\tdiffuseSum += (sample1 + sample2) * w;\t\tweightSum += 2.0 * w;\t}\tgl_FragColor = vec4(diffuseSum/weightSum, 1.0);\n}"})},getCompositeMaterial:function(r){return new e.ShaderMaterial({defines:{NUM_MIPS:r},uniforms:{blurTexture1:{value:null},blurTexture2:{value:null},blurTexture3:{value:null},blurTexture4:{value:null},blurTexture5:{value:null},dirtTexture:{value:null},bloomStrength:{value:1},bloomFactors:{value:null},bloomTintColors:{value:null},bloomRadius:{value:0}},vertexShader:"varying vec2 vUv;\nvoid main() {\n\tvUv = uv;\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",fragmentShader:"varying vec2 vUv;uniform sampler2D blurTexture1;uniform sampler2D blurTexture2;uniform sampler2D blurTexture3;uniform sampler2D blurTexture4;uniform sampler2D blurTexture5;uniform sampler2D dirtTexture;uniform float bloomStrength;uniform float bloomRadius;uniform float bloomFactors[NUM_MIPS];uniform vec3 bloomTintColors[NUM_MIPS];float lerpBloomFactor(const in float factor) { \tfloat mirrorFactor = 1.2 - factor;\treturn mix(factor, mirrorFactor, bloomRadius);}void main() {\tgl_FragColor = bloomStrength * ( lerpBloomFactor(bloomFactors[0]) * vec4(bloomTintColors[0], 1.0) * texture2D(blurTexture1, vUv) + \t\t\t\t\t\t\t\t\t lerpBloomFactor(bloomFactors[1]) * vec4(bloomTintColors[1], 1.0) * texture2D(blurTexture2, vUv) + \t\t\t\t\t\t\t\t\t lerpBloomFactor(bloomFactors[2]) * vec4(bloomTintColors[2], 1.0) * texture2D(blurTexture3, vUv) + \t\t\t\t\t\t\t\t\t lerpBloomFactor(bloomFactors[3]) * vec4(bloomTintColors[3], 1.0) * texture2D(blurTexture4, vUv) + \t\t\t\t\t\t\t\t\t lerpBloomFactor(bloomFactors[4]) * vec4(bloomTintColors[4], 1.0) * texture2D(blurTexture5, vUv) );}"})}}),a.BlurDirectionX=new e.Vector2(1,0),a.BlurDirectionY=new e.Vector2(0,1),exports.UnrealBloomPass=a;
|
|
@@ -221,36 +221,8 @@ UnrealBloomPass.prototype = Object.assign(Object.create(Pass.prototype), {
|
|
|
221
221
|
value: new Vector2(0.5, 0.5)
|
|
222
222
|
}
|
|
223
223
|
},
|
|
224
|
-
vertexShader: 'varying vec2 vUv;\n\
|
|
225
|
-
|
|
226
|
-
vUv = uv;\n\
|
|
227
|
-
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\
|
|
228
|
-
}',
|
|
229
|
-
fragmentShader: '#include <common>\
|
|
230
|
-
varying vec2 vUv;\n\
|
|
231
|
-
uniform sampler2D colorTexture;\n\
|
|
232
|
-
uniform vec2 texSize;\
|
|
233
|
-
uniform vec2 direction;\
|
|
234
|
-
\
|
|
235
|
-
float gaussianPdf(in float x, in float sigma) {\
|
|
236
|
-
return 0.39894 * exp( -0.5 * x * x/( sigma * sigma))/sigma;\
|
|
237
|
-
}\
|
|
238
|
-
void main() {\n\
|
|
239
|
-
vec2 invSize = 1.0 / texSize;\
|
|
240
|
-
float fSigma = float(SIGMA);\
|
|
241
|
-
float weightSum = gaussianPdf(0.0, fSigma);\
|
|
242
|
-
vec3 diffuseSum = texture2D( colorTexture, vUv).rgb * weightSum;\
|
|
243
|
-
for( int i = 1; i < KERNEL_RADIUS; i ++ ) {\
|
|
244
|
-
float x = float(i);\
|
|
245
|
-
float w = gaussianPdf(x, fSigma);\
|
|
246
|
-
vec2 uvOffset = direction * invSize * x;\
|
|
247
|
-
vec3 sample1 = texture2D( colorTexture, vUv + uvOffset).rgb;\
|
|
248
|
-
vec3 sample2 = texture2D( colorTexture, vUv - uvOffset).rgb;\
|
|
249
|
-
diffuseSum += (sample1 + sample2) * w;\
|
|
250
|
-
weightSum += 2.0 * w;\
|
|
251
|
-
}\
|
|
252
|
-
gl_FragColor = vec4(diffuseSum/weightSum, 1.0);\n\
|
|
253
|
-
}'
|
|
224
|
+
vertexShader: 'varying vec2 vUv;\n' + 'void main() {\n' + ' vUv = uv;\n' + ' gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n' + '}',
|
|
225
|
+
fragmentShader: '#include <common>' + 'varying vec2 vUv;\n' + 'uniform sampler2D colorTexture;\n' + 'uniform vec2 texSize;' + 'uniform vec2 direction;' + '\n' + 'float gaussianPdf(in float x, in float sigma) {' + ' return 0.39894 * exp( -0.5 * x * x/( sigma * sigma))/sigma;' + '}' + 'void main() {\n' + ' vec2 invSize = 1.0 / texSize;' + ' float fSigma = float(SIGMA);' + ' float weightSum = gaussianPdf(0.0, fSigma);' + ' vec3 diffuseSum = texture2D( colorTexture, vUv).rgb * weightSum;' + ' for( int i = 1; i < KERNEL_RADIUS; i ++ ) {' + ' float x = float(i);' + ' float w = gaussianPdf(x, fSigma);' + ' vec2 uvOffset = direction * invSize * x;' + ' vec3 sample1 = texture2D( colorTexture, vUv + uvOffset).rgb;' + ' vec3 sample2 = texture2D( colorTexture, vUv - uvOffset).rgb;' + ' diffuseSum += (sample1 + sample2) * w;' + ' weightSum += 2.0 * w;' + ' }' + ' gl_FragColor = vec4(diffuseSum/weightSum, 1.0);\n' + '}'
|
|
254
226
|
});
|
|
255
227
|
},
|
|
256
228
|
getCompositeMaterial: function (nMips) {
|
|
@@ -290,35 +262,8 @@ UnrealBloomPass.prototype = Object.assign(Object.create(Pass.prototype), {
|
|
|
290
262
|
value: 0.0
|
|
291
263
|
}
|
|
292
264
|
},
|
|
293
|
-
vertexShader: 'varying vec2 vUv;\n\
|
|
294
|
-
|
|
295
|
-
vUv = uv;\n\
|
|
296
|
-
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\
|
|
297
|
-
}',
|
|
298
|
-
fragmentShader: 'varying vec2 vUv;\
|
|
299
|
-
uniform sampler2D blurTexture1;\
|
|
300
|
-
uniform sampler2D blurTexture2;\
|
|
301
|
-
uniform sampler2D blurTexture3;\
|
|
302
|
-
uniform sampler2D blurTexture4;\
|
|
303
|
-
uniform sampler2D blurTexture5;\
|
|
304
|
-
uniform sampler2D dirtTexture;\
|
|
305
|
-
uniform float bloomStrength;\
|
|
306
|
-
uniform float bloomRadius;\
|
|
307
|
-
uniform float bloomFactors[NUM_MIPS];\
|
|
308
|
-
uniform vec3 bloomTintColors[NUM_MIPS];\
|
|
309
|
-
\
|
|
310
|
-
float lerpBloomFactor(const in float factor) { \
|
|
311
|
-
float mirrorFactor = 1.2 - factor;\
|
|
312
|
-
return mix(factor, mirrorFactor, bloomRadius);\
|
|
313
|
-
}\
|
|
314
|
-
\
|
|
315
|
-
void main() {\
|
|
316
|
-
gl_FragColor = bloomStrength * ( lerpBloomFactor(bloomFactors[0]) * vec4(bloomTintColors[0], 1.0) * texture2D(blurTexture1, vUv) + \
|
|
317
|
-
lerpBloomFactor(bloomFactors[1]) * vec4(bloomTintColors[1], 1.0) * texture2D(blurTexture2, vUv) + \
|
|
318
|
-
lerpBloomFactor(bloomFactors[2]) * vec4(bloomTintColors[2], 1.0) * texture2D(blurTexture3, vUv) + \
|
|
319
|
-
lerpBloomFactor(bloomFactors[3]) * vec4(bloomTintColors[3], 1.0) * texture2D(blurTexture4, vUv) + \
|
|
320
|
-
lerpBloomFactor(bloomFactors[4]) * vec4(bloomTintColors[4], 1.0) * texture2D(blurTexture5, vUv) );\
|
|
321
|
-
}'
|
|
265
|
+
vertexShader: 'varying vec2 vUv;\n' + 'void main() {\n' + ' vUv = uv;\n' + ' gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n' + '}',
|
|
266
|
+
fragmentShader: 'varying vec2 vUv;' + 'uniform sampler2D blurTexture1;' + 'uniform sampler2D blurTexture2;' + 'uniform sampler2D blurTexture3;' + 'uniform sampler2D blurTexture4;' + 'uniform sampler2D blurTexture5;' + 'uniform sampler2D dirtTexture;' + 'uniform float bloomStrength;' + 'uniform float bloomRadius;' + 'uniform float bloomFactors[NUM_MIPS];' + 'uniform vec3 bloomTintColors[NUM_MIPS];' + '' + 'float lerpBloomFactor(const in float factor) { ' + ' float mirrorFactor = 1.2 - factor;' + ' return mix(factor, mirrorFactor, bloomRadius);' + '}' + '' + 'void main() {' + ' gl_FragColor = bloomStrength * ( lerpBloomFactor(bloomFactors[0]) * vec4(bloomTintColors[0], 1.0) * texture2D(blurTexture1, vUv) + ' + ' lerpBloomFactor(bloomFactors[1]) * vec4(bloomTintColors[1], 1.0) * texture2D(blurTexture2, vUv) + ' + ' lerpBloomFactor(bloomFactors[2]) * vec4(bloomTintColors[2], 1.0) * texture2D(blurTexture3, vUv) + ' + ' lerpBloomFactor(bloomFactors[3]) * vec4(bloomTintColors[3], 1.0) * texture2D(blurTexture4, vUv) + ' + ' lerpBloomFactor(bloomFactors[4]) * vec4(bloomTintColors[4], 1.0) * texture2D(blurTexture5, vUv) );' + '}'
|
|
322
267
|
});
|
|
323
268
|
}
|
|
324
269
|
});
|