/*! * pixi-lights - v2.0.3 * Compiled Fri, 05 Aug 2022 19:58:51 UTC * * pixi-lights is licensed under the MIT License. * http://www.opensource.org/licenses/mit-license */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t.PIXI=t.PIXI||{},t.PIXI.lights={}))}(this,function(t){"use strict";PIXI.Circle.prototype.getMesh=function(t,e,r){void 0===t&&(t=40),e=e||new Float32Array(2*(t+1)),r=r||new Uint16Array(t+1);var i=2*Math.PI/t,o=-1;r[++o]=o;for(var n=0;n<=t;++n){var a=2*n,s=i*n;e[a]=Math.cos(s)*this.radius,e[a+1]=Math.sin(s)*this.radius,r[++o]=o}return r[o]=1,{vertices:e,indices:r}};var e={},r=new PIXI.display.Group,i=new PIXI.display.Group,o=new PIXI.display.Group;function n(t,r){e[t]=r}r.useRenderTexture=!0,i.useRenderTexture=!0;var a=function(t){function e(e,r,i,n){t.call(this),this.vertices=i||new Float32Array(8),this.indices=n||new Uint16Array([0,1,2,0,2,3]),this.blendMode=PIXI.BLEND_MODES.ADD,this.drawMode=PIXI.DRAW_MODES.TRIANGLES,this.dirty=0,this.lightHeight=.075,this.falloff=[.75,3,20],this.shaderName=null,this.useViewportQuad=!0,this._color=5066073,this._colorRgba=[.3,.3,.35,.8],(e||0===e)&&(this.color=e),(r||0===r)&&(this.brightness=r),this.parentGroup=o,this._glDatas={},this.shaderName="lights"}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={color:{configurable:!0},brightness:{configurable:!0}};return r.color.get=function(){return this._color},r.color.set=function(t){this._color=t,PIXI.utils.hex2rgb(t,this._colorRgba)},r.brightness.get=function(){return this._colorRgba[3]},r.brightness.set=function(t){this._colorRgba[3]=t},e.prototype.syncShader=function(t){t.uniforms.uUseViewportQuad=this.useViewportQuad;var e=t.uniforms.uLightColor;e&&(e[0]=this._colorRgba[0],e[1]=this._colorRgba[1],e[2]=this._colorRgba[2],e[3]=this._colorRgba[3],t.uniforms.uLightColor=e),t.uniforms.uLightHeight=this.lightHeight;var r=t.uniforms.uLightFalloff;r&&(r[0]=this.falloff[0],r[1]=this.falloff[1],r[2]=this.falloff[2],t.uniforms.uLightFalloff=r)},e.prototype._renderWebGL=function(t){t.setObjectRenderer(t.plugins.lights),t.plugins.lights.render(this)},Object.defineProperties(e.prototype,r),e}(PIXI.Container),s=function(t){function e(r,i,o,n,a){var s={translationMatrix:{type:"mat3",value:new Float32Array(9)},projectionMatrix:{type:"mat3",value:new Float32Array(9)},uSampler:{type:"sampler2D",value:null},uNormalSampler:{type:"sampler2D",value:null},uUseViewportQuad:{type:"bool",value:!0},uViewSize:{type:"2f",value:new Float32Array(2)},uViewPixels:{type:"2f",value:new Float32Array(2)},uLightColor:{type:"4f",value:new Float32Array([1,1,1,1])},uLightFalloff:{type:"3f",value:new Float32Array([0,0,0])},uLightHeight:{type:"1f",value:.075}};if(n)for(var l in n)s[l]=n[l];var u={aVertexPosition:0};if(a)for(var h in a)u[h]=a[h];t.call(this,r,i||e.defaultVertexSrc,o,u)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e}(PIXI.Shader);s.defaultVertexSrc="attribute vec2 aVertexPosition;\n\nuniform bool uUseViewportQuad;\nuniform mat3 translationMatrix;\nuniform mat3 projectionMatrix;\n\nvoid main(void) {\n if (uUseViewportQuad) {\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n }\n else\n {\n gl_Position = vec4((projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n }\n}\n";var l=function(t){function e(e,r){void 0===e&&(e=16777215),void 0===r&&(r=.5),t.call(this,e,r),this.shaderName="ambientLightShader"}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e}(a),u="uniform sampler2D uSampler;\nuniform sampler2D uNormalSampler;\n\nuniform mat3 translationMatrix;\n\nuniform vec2 uViewPixels; // size of the viewport, in pixels\nuniform vec2 uViewSize; // size of the viewport, in CSS\n\nuniform vec4 uLightColor; // light color, alpha channel used for intensity.\nuniform vec3 uLightFalloff; // light attenuation coefficients (constant, linear, quadratic)\nuniform float uLightHeight; // light height above the viewport\nuniform float uFlipY; // whether we use renderTexture, FBO is flipped\n",h="vec2 texCoord = gl_FragCoord.xy / uViewPixels;\ntexCoord.y = (1.0 - texCoord.y) * uFlipY + texCoord.y * (1.0 - uFlipY); // FBOs positions are flipped.\n",c="vec4 normalColor = texture2D(uNormalSampler, texCoord);\nnormalColor.g = 1.0 - normalColor.g; // Green layer is flipped Y coords.\n\n// bail out early when normal has no data\nif (normalColor.a == 0.0) discard;\n",f="precision highp float;\n\n"+u+"\n\nvoid main(void)\n{\n"+h+"\n"+c+"\n // simplified lambert shading that makes assumptions for ambient color\n vec3 diffuse = uLightColor.rgb * uLightColor.a;\n vec4 diffuseColor = texture2D(uSampler, texCoord);\n vec3 finalColor = diffuseColor.rgb * diffuse;\n \n gl_FragColor = vec4(finalColor, diffuseColor.a);\n}\n",d=function(t){function e(e){t.call(this,e,null,f)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e}(s);n("ambientLightShader",d);var p=function(t){function e(e,r,i){if(void 0===e&&(e=16777215),void 0===r&&(r=1),void 0===i&&(i=1/0),i!==1/0){var o=new PIXI.Circle(0,0,i).getMesh(),n=o.vertices,a=o.indices;t.call(this,e,r,n,a),this.useViewportQuad=!1,this.drawMode=PIXI.DRAW_MODES.TRIANGLE_FAN}else t.call(this,e,r);this.radius=i,this.shaderName="pointLightShader"}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.syncShader=function(e){t.prototype.syncShader.call(this,e),e.uniforms.uLightRadius=this.radius},e}(a),g='// normalize vectors\nvec3 N = normalize(normalColor.xyz * 2.0 - 1.0);\nvec3 L = normalize(lightVector);\n\n// pre-multiply light color with intensity\n// then perform "N dot L" to determine our diffuse\nvec3 diffuse = (uLightColor.rgb * uLightColor.a) * max(dot(N, L), 0.0);\n',v="// calculate final intesity and color, then combine\nvec3 intensity = diffuse * attenuation;\nvec4 diffuseColor = texture2D(uSampler, texCoord);\nvec3 finalColor = diffuseColor.rgb * intensity;\n\ngl_FragColor = vec4(finalColor, diffuseColor.a);\n",y="precision highp float;\n\n// imports the common uniforms like samplers, and ambient color\n"+u+"\n\nuniform float uLightRadius;\n\nvoid main()\n{\n"+h+"\n"+c+"\n\n vec2 lightPosition = translationMatrix[2].xy / uViewSize;\n\n // the directional vector of the light\n vec3 lightVector = vec3(lightPosition - texCoord, uLightHeight);\n\n // correct for aspect ratio\n lightVector.x *= uViewSize.x / uViewSize.y;\n\n // compute Distance\n float D = length(lightVector);\n\n // bail out early when pixel outside of light sphere\n if (D > uLightRadius) discard;\n\n"+g+"\n\n // calculate attenuation\n float attenuation = 1.0 / (uLightFalloff.x + (uLightFalloff.y * D) + (uLightFalloff.z * D * D));\n\n"+v+"\n}\n",m=function(t){function e(e){t.call(this,e,null,y,{uLightRadius:{type:"1f",value:1}})}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e}(s);n("pointLightShader",m);var _=function(t){function e(e,r,i){void 0===e&&(e=16777215),void 0===r&&(r=1),t.call(this,e,r),this.target=i,this._directionVector=new PIXI.Point,this.shaderName="directionalLightShader"}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.updateTransform=function(){this.containerUpdateTransform();var t=this._directionVector,e=this.worldTransform,r=this.target.worldTransform?this.target.worldTransform.tx:this.target.x,i=this.target.worldTransform?this.target.worldTransform.ty:this.target.y;t.x=e.tx-r,t.y=e.ty-i;var o=Math.sqrt(t.x*t.x+t.y*t.y);t.x/=o,t.y/=o},e.prototype.syncShader=function(e){t.prototype.syncShader.call(this,e);var r=e.uniforms.uLightDirection;r[0]=this._directionVector.x,r[1]=this._directionVector.y,e.uniforms.uLightDirection=r},e}(a),x="precision highp float;\n\n// imports the common uniforms like samplers, and ambient/light color\n"+u+"\n\nuniform vec2 uLightDirection;\n\nvoid main()\n{\n"+h+"\n"+c+"\n\n // the directional vector of the light\n vec3 lightVector = vec3(uLightDirection, uLightHeight);\n\n // compute Distance\n float D = length(lightVector);\n\n"+g+"\n\n // calculate attenuation\n float attenuation = 1.0;\n\n"+v+"\n}\n",b=function(t){function e(e){t.call(this,e,null,x,{uLightDirection:{type:"2f",value:new Float32Array(2)}})}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e}(s);n("directionalLightShader",b);var w=function(t){function o(e){t.call(this,e);var r=6*o.MAX_LIGHTS;this.indices=new Uint16Array(r);for(var i=0,n=0;i