@pixi/filter-simple-lightmap
Advanced tools
Comparing version 2.7.0 to 3.0.0
/*! | ||
* @pixi/filter-simple-lightmap - v2.7.0 | ||
* Compiled Sun, 13 Jan 2019 22:51:52 UTC | ||
* Compiled Fri, 10 May 2019 22:56:42 UTC | ||
* | ||
@@ -8,3 +8,115 @@ * @pixi/filter-simple-lightmap is licensed under the MIT License. | ||
*/ | ||
import{utils as o,Filter as r}from"pixi.js";var t="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\n\nuniform mat3 projectionMatrix;\n\nvarying vec2 vTextureCoord;\n\nvoid main(void)\n{\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e="varying vec2 vTextureCoord;\nuniform sampler2D uSampler;\nuniform sampler2D uLightmap;\nuniform vec4 filterArea;\nuniform vec2 dimensions;\nuniform vec4 ambientColor;\nvoid main() {\n vec4 diffuseColor = texture2D(uSampler, vTextureCoord);\n vec2 lightCoord = (vTextureCoord * filterArea.xy) / dimensions;\n vec4 light = texture2D(uLightmap, lightCoord);\n vec3 ambient = ambientColor.rgb * ambientColor.a;\n vec3 intensity = ambient + light.rgb;\n vec3 finalColor = diffuseColor.rgb * intensity;\n gl_FragColor = vec4(finalColor, diffuseColor.a);\n}\n",i=function(r){function i(o,i,n){void 0===i&&(i=0),void 0===n&&(n=1),r.call(this,t,e),this.uniforms.dimensions=new Float32Array(2),this.uniforms.ambientColor=new Float32Array([0,0,0,n]),this.texture=o,this.color=i}r&&(i.__proto__=r),i.prototype=Object.create(r&&r.prototype),i.prototype.constructor=i;var n={texture:{configurable:!0},color:{configurable:!0},alpha:{configurable:!0}};return i.prototype.apply=function(o,r,t,e){this.uniforms.dimensions[0]=r.sourceFrame.width,this.uniforms.dimensions[1]=r.sourceFrame.height,o.applyFilter(this,r,t,e)},n.texture.get=function(){return this.uniforms.uLightmap},n.texture.set=function(o){this.uniforms.uLightmap=o},n.color.set=function(r){var t=this.uniforms.ambientColor;"number"==typeof r?(o.hex2rgb(r,t),this._color=r):(t[0]=r[0],t[1]=r[1],t[2]=r[2],t[3]=r[3],this._color=o.rgb2hex(t))},n.color.get=function(){return this._color},n.alpha.get=function(){return this.uniforms.ambientColor[3]},n.alpha.set=function(o){this.uniforms.ambientColor[3]=o},Object.defineProperties(i.prototype,n),i}(r);export{i as SimpleLightmapFilter}; | ||
import { Filter } from '@pixi/core'; | ||
import { hex2rgb, rgb2hex } from '@pixi/utils'; | ||
var vertex = "attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\n\nuniform mat3 projectionMatrix;\n\nvarying vec2 vTextureCoord;\n\nvoid main(void)\n{\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}"; | ||
var fragment = "varying vec2 vTextureCoord;\nuniform sampler2D uSampler;\nuniform sampler2D uLightmap;\nuniform vec4 filterArea;\nuniform vec2 dimensions;\nuniform vec4 ambientColor;\nvoid main() {\n vec4 diffuseColor = texture2D(uSampler, vTextureCoord);\n vec2 lightCoord = (vTextureCoord * filterArea.xy) / dimensions;\n vec4 light = texture2D(uLightmap, lightCoord);\n vec3 ambient = ambientColor.rgb * ambientColor.a;\n vec3 intensity = ambient + light.rgb;\n vec3 finalColor = diffuseColor.rgb * intensity;\n gl_FragColor = vec4(finalColor, diffuseColor.a);\n}\n"; | ||
/** | ||
* SimpleLightmap, originally by Oza94 | ||
* http://www.html5gamedevs.com/topic/20027-pixijs-simple-lightmapping/ | ||
* http://codepen.io/Oza94/pen/EPoRxj | ||
* | ||
* You have to specify filterArea, or suffer consequences. | ||
* You may have to use it with `filter.dontFit = true`, | ||
* until we rewrite this using same approach as for DisplacementFilter. | ||
* | ||
* ![original](../tools/screenshots/dist/original.png)![filter](../tools/screenshots/dist/simple-lightmap.png) | ||
* @class | ||
* @extends PIXI.Filter | ||
* @memberof PIXI.filters | ||
* @see {@link https://www.npmjs.com/package/@pixi/filter-simple-lightmap|@pixi/filter-simple-lightmap} | ||
* @see {@link https://www.npmjs.com/package/pixi-filters|pixi-filters} | ||
* @param {PIXI.Texture} texture a texture where your lightmap is rendered | ||
* @param {Array<number>|number} [color=0x000000] An RGBA array of the ambient color | ||
* @param {number} [alpha=1] Default alpha set independent of color (if it's a number, not array). | ||
* | ||
* @example | ||
* displayObject.filters = [new SimpleLightmapFilter(texture, 0x666666)]; | ||
*/ | ||
var SimpleLightmapFilter = /*@__PURE__*/(function (Filter) { | ||
function SimpleLightmapFilter(texture, color, alpha) { | ||
if ( color === void 0 ) color = 0x000000; | ||
if ( alpha === void 0 ) alpha = 1; | ||
Filter.call(this, vertex, fragment); | ||
this.uniforms.dimensions = new Float32Array(2); | ||
this.uniforms.ambientColor = new Float32Array([0, 0, 0, alpha]); | ||
this.texture = texture; | ||
this.color = color; | ||
} | ||
if ( Filter ) SimpleLightmapFilter.__proto__ = Filter; | ||
SimpleLightmapFilter.prototype = Object.create( Filter && Filter.prototype ); | ||
SimpleLightmapFilter.prototype.constructor = SimpleLightmapFilter; | ||
var prototypeAccessors = { texture: { configurable: true },color: { configurable: true },alpha: { configurable: true } }; | ||
/** | ||
* Applies the filter. | ||
* @private | ||
* @param {PIXI.FilterManager} filterManager - The manager. | ||
* @param {PIXI.RenderTarget} input - The input target. | ||
* @param {PIXI.RenderTarget} output - The output target. | ||
*/ | ||
SimpleLightmapFilter.prototype.apply = function apply (filterManager, input, output, clear) { | ||
this.uniforms.dimensions[0] = input.filterFrame.width; | ||
this.uniforms.dimensions[1] = input.filterFrame.height; | ||
// draw the filter... | ||
filterManager.applyFilter(this, input, output, clear); | ||
}; | ||
/** | ||
* a texture where your lightmap is rendered | ||
* @member {PIXI.Texture} | ||
*/ | ||
prototypeAccessors.texture.get = function () { | ||
return this.uniforms.uLightmap; | ||
}; | ||
prototypeAccessors.texture.set = function (value) { | ||
this.uniforms.uLightmap = value; | ||
}; | ||
/** | ||
* An RGBA array of the ambient color or a hex color without alpha | ||
* @member {Array<number>|number} | ||
*/ | ||
prototypeAccessors.color.set = function (value) { | ||
var arr = this.uniforms.ambientColor; | ||
if (typeof value === 'number') { | ||
hex2rgb(value, arr); | ||
this._color = value; | ||
} | ||
else { | ||
arr[0] = value[0]; | ||
arr[1] = value[1]; | ||
arr[2] = value[2]; | ||
arr[3] = value[3]; | ||
this._color = rgb2hex(arr); | ||
} | ||
}; | ||
prototypeAccessors.color.get = function () { | ||
return this._color; | ||
}; | ||
/** | ||
* When setting `color` as hex, this can be used to set alpha independently. | ||
* @member {number} | ||
*/ | ||
prototypeAccessors.alpha.get = function () { | ||
return this.uniforms.ambientColor[3]; | ||
}; | ||
prototypeAccessors.alpha.set = function (value) { | ||
this.uniforms.ambientColor[3] = value; | ||
}; | ||
Object.defineProperties( SimpleLightmapFilter.prototype, prototypeAccessors ); | ||
return SimpleLightmapFilter; | ||
}(Filter)); | ||
export { SimpleLightmapFilter }; | ||
//# sourceMappingURL=filter-simple-lightmap.esm.js.map |
{ | ||
"name": "@pixi/filter-simple-lightmap", | ||
"version": "2.7.0", | ||
"main": "lib/filter-simple-lightmap.js", | ||
"description": "PixiJS v4 filter to create a light-map from a texture", | ||
"version": "3.0.0", | ||
"main": "lib/filter-simple-lightmap.cjs.js", | ||
"bundle": "dist/filter-simple-lightmap.js", | ||
"description": "PixiJS filter to create a light-map from a texture", | ||
"author": "Mat Groves", | ||
@@ -24,11 +25,13 @@ "contributors": [ | ||
"lib", | ||
"dist", | ||
"types.d.ts" | ||
], | ||
"peerDependencies": { | ||
"pixi.js": ">=4.0.0" | ||
"dependencies": { | ||
"@pixi/core": "^5.0.0-X", | ||
"@pixi/utils": "^5.0.0-X" | ||
}, | ||
"devDependencies": { | ||
"@tools/fragments": "^2.0.0" | ||
"@tools/fragments": "^3.0.0" | ||
}, | ||
"gitHead": "a1329fadd2910c48842c92f254be77d971a823ca" | ||
"gitHead": "0902eca3fe476dd7dacc9330f504d8e2ade6c9bd" | ||
} |
# SimpleLightmapFilter | ||
PixiJS v4 filter to create a light-map from a texture. | ||
PixiJS filter to create a light-map from a texture. | ||
@@ -5,0 +5,0 @@ ## Installation |
/// <reference types="pixi.js" /> | ||
declare namespace PIXI.filters { | ||
class SimpleLightmapFilter extends PIXI.Filter<{}> { | ||
declare module "@pixi/filter-simple-lightmap" { | ||
export class SimpleLightmapFilter extends PIXI.Filter { | ||
constructor(texture:PIXI.Texture, color?:number[]|number); | ||
@@ -10,5 +10,1 @@ alpha:number; | ||
} | ||
declare module "@pixi/filter-simple-lightmap" { | ||
export = PIXI.filters; | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
29812
10
245
0
2
1
+ Added@pixi/core@^5.0.0-X
+ Added@pixi/utils@^5.0.0-X
+ Added@pixi/constants@5.3.12(transitive)
+ Added@pixi/core@5.3.12(transitive)
+ Added@pixi/math@5.3.12(transitive)
+ Added@pixi/runner@5.3.12(transitive)
+ Added@pixi/settings@5.3.12(transitive)
+ Added@pixi/ticker@5.3.12(transitive)
+ Added@pixi/utils@5.3.12(transitive)
+ Addedcall-bind-apply-helpers@1.0.1(transitive)
+ Addedcall-bound@1.0.3(transitive)
+ Addeddunder-proto@1.0.1(transitive)
+ Addedes-define-property@1.0.1(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.0.0(transitive)
+ Addedeventemitter3@3.1.2(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.6(transitive)
+ Addedgopd@1.2.0(transitive)
+ Addedhas-symbols@1.1.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedmath-intrinsics@1.0.0(transitive)
+ Addedobject-inspect@1.13.3(transitive)
+ Addedpunycode@1.4.1(transitive)
+ Addedqs@6.13.1(transitive)
+ Addedside-channel@1.1.0(transitive)
+ Addedside-channel-list@1.0.0(transitive)
+ Addedside-channel-map@1.0.1(transitive)
+ Addedside-channel-weakmap@1.0.2(transitive)
+ Addedurl@0.11.4(transitive)
- Removed@pixi/colord@2.9.6(transitive)
- Removed@types/css-font-loading-module@0.0.12(transitive)
- Removed@types/earcut@2.1.4(transitive)
- Removed@webgpu/types@0.1.51(transitive)
- Removed@xmldom/xmldom@0.8.10(transitive)
- Removedeventemitter3@5.0.1(transitive)
- Removedparse-svg-path@0.1.2(transitive)
- Removedpixi.js@8.6.5(transitive)