diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 00866f2..00a4ba2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -219,10 +219,10 @@ /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. - * In PIXI a regular mask must be a PIXI.Graphics object. This allows for much faster masking in canvas as it utilises shape clipping. + * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. * To remove a mask, set this property to null. * - * @member {Graphics} + * @member {Graphics | Sprite} * @memberof PIXI.DisplayObject# */ mask: { diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 00866f2..00a4ba2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -219,10 +219,10 @@ /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. - * In PIXI a regular mask must be a PIXI.Graphics object. This allows for much faster masking in canvas as it utilises shape clipping. + * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. * To remove a mask, set this property to null. * - * @member {Graphics} + * @member {Graphics | Sprite} * @memberof PIXI.DisplayObject# */ mask: { diff --git a/src/filters/index.js b/src/filters/index.js index 3dba827..08e532c 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -25,7 +25,6 @@ DropShadowFilter: require('./dropshadow/DropShadowFilter'), InvertFilter: require('./invert/InvertFilter'), NoiseFilter: require('./noise/NoiseFilter'), - NormalMapFilter: require('./normal/NormalMapFilter'), PixelateFilter: require('./pixelate/PixelateFilter'), RGBSplitFilter: require('./rgb/RGBSplitFilter'), ShockwaveFilter: require('./shockwave/ShockwaveFilter'), diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 00866f2..00a4ba2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -219,10 +219,10 @@ /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. - * In PIXI a regular mask must be a PIXI.Graphics object. This allows for much faster masking in canvas as it utilises shape clipping. + * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. * To remove a mask, set this property to null. * - * @member {Graphics} + * @member {Graphics | Sprite} * @memberof PIXI.DisplayObject# */ mask: { diff --git a/src/filters/index.js b/src/filters/index.js index 3dba827..08e532c 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -25,7 +25,6 @@ DropShadowFilter: require('./dropshadow/DropShadowFilter'), InvertFilter: require('./invert/InvertFilter'), NoiseFilter: require('./noise/NoiseFilter'), - NormalMapFilter: require('./normal/NormalMapFilter'), PixelateFilter: require('./pixelate/PixelateFilter'), RGBSplitFilter: require('./rgb/RGBSplitFilter'), ShockwaveFilter: require('./shockwave/ShockwaveFilter'), diff --git a/src/filters/normal/NormalMapFilter.js b/src/filters/normal/NormalMapFilter.js deleted file mode 100644 index 89d1097..0000000 --- a/src/filters/normal/NormalMapFilter.js +++ /dev/null @@ -1,111 +0,0 @@ -var core = require('../../core'); -// @see https://github.com/substack/brfs/issues/25 -var fs = require('fs'); - -/** - * The NormalMapFilter class uses the pixel values from the specified texture (called the normal map) - * to project lighting onto an object. - * - * @class - * @extends PIXI.AbstractFilter - * @memberof PIXI.filters - * @param texture {Texture} The texture used for the normal map, must be power of 2 texture at the moment - */ -function NormalMapFilter(texture) -{ - core.AbstractFilter.call(this, - // vertex shader - null, - // fragment shader - fs.readFileSync(__dirname + '/normalMap.frag', 'utf8'), - // custom uniforms - { - displacementMap: { type: 'sampler2D', value: texture }, - scale: { type: '2f', value: { x: 15, y: 15 } }, - offset: { type: '2f', value: { x: 0, y: 0 } }, - mapDimensions: { type: '2f', value: { x: 1, y: 1 } }, - dimensions: { type: '4f', value: [0, 0, 0, 0] }, - // LightDir: { type: 'f3', value: [0, 1, 0] }, - LightPos: { type: '3f', value: [0, 1, 0] } - } - ); - - texture.baseTexture._powerOf2 = true; - - if (texture.baseTexture.hasLoaded) - { - this.onTextureLoaded(); - } - else - { - texture.baseTexture.once('loaded', this.onTextureLoaded, this); - } -} - -NormalMapFilter.prototype = Object.create(core.AbstractFilter.prototype); -NormalMapFilter.prototype.constructor = NormalMapFilter; -module.exports = NormalMapFilter; - -/** - * Sets the map dimensions uniforms when the texture becomes available. - * - * @private - */ -NormalMapFilter.prototype.onTextureLoaded = function () -{ - this.uniforms.mapDimensions.value.x = this.uniforms.displacementMap.value.width; - this.uniforms.mapDimensions.value.y = this.uniforms.displacementMap.value.height; -}; - -Object.defineProperties(NormalMapFilter.prototype, { - /** - * The texture used for the displacement map. Must be power of 2 texture. - * - * @member {Texture} - * @memberof NormalMapFilter# - */ - map: { - get: function () - { - return this.uniforms.displacementMap.value; - }, - set: function (value) - { - this.uniforms.displacementMap.value = value; - } - }, - - /** - * The multiplier used to scale the displacement result from the map calculation. - * - * @member {Point} - * @memberof NormalMapFilter# - */ - scale: { - get: function () - { - return this.uniforms.scale.value; - }, - set: function (value) - { - this.uniforms.scale.value = value; - } - }, - - /** - * The offset used to move the displacement map. - * - * @member {Point} - * @memberof NormalMapFilter# - */ - offset: { - get: function () - { - return this.uniforms.offset.value; - }, - set: function (value) - { - this.uniforms.offset.value = value; - } - } -}); diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 00866f2..00a4ba2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -219,10 +219,10 @@ /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. - * In PIXI a regular mask must be a PIXI.Graphics object. This allows for much faster masking in canvas as it utilises shape clipping. + * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. * To remove a mask, set this property to null. * - * @member {Graphics} + * @member {Graphics | Sprite} * @memberof PIXI.DisplayObject# */ mask: { diff --git a/src/filters/index.js b/src/filters/index.js index 3dba827..08e532c 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -25,7 +25,6 @@ DropShadowFilter: require('./dropshadow/DropShadowFilter'), InvertFilter: require('./invert/InvertFilter'), NoiseFilter: require('./noise/NoiseFilter'), - NormalMapFilter: require('./normal/NormalMapFilter'), PixelateFilter: require('./pixelate/PixelateFilter'), RGBSplitFilter: require('./rgb/RGBSplitFilter'), ShockwaveFilter: require('./shockwave/ShockwaveFilter'), diff --git a/src/filters/normal/NormalMapFilter.js b/src/filters/normal/NormalMapFilter.js deleted file mode 100644 index 89d1097..0000000 --- a/src/filters/normal/NormalMapFilter.js +++ /dev/null @@ -1,111 +0,0 @@ -var core = require('../../core'); -// @see https://github.com/substack/brfs/issues/25 -var fs = require('fs'); - -/** - * The NormalMapFilter class uses the pixel values from the specified texture (called the normal map) - * to project lighting onto an object. - * - * @class - * @extends PIXI.AbstractFilter - * @memberof PIXI.filters - * @param texture {Texture} The texture used for the normal map, must be power of 2 texture at the moment - */ -function NormalMapFilter(texture) -{ - core.AbstractFilter.call(this, - // vertex shader - null, - // fragment shader - fs.readFileSync(__dirname + '/normalMap.frag', 'utf8'), - // custom uniforms - { - displacementMap: { type: 'sampler2D', value: texture }, - scale: { type: '2f', value: { x: 15, y: 15 } }, - offset: { type: '2f', value: { x: 0, y: 0 } }, - mapDimensions: { type: '2f', value: { x: 1, y: 1 } }, - dimensions: { type: '4f', value: [0, 0, 0, 0] }, - // LightDir: { type: 'f3', value: [0, 1, 0] }, - LightPos: { type: '3f', value: [0, 1, 0] } - } - ); - - texture.baseTexture._powerOf2 = true; - - if (texture.baseTexture.hasLoaded) - { - this.onTextureLoaded(); - } - else - { - texture.baseTexture.once('loaded', this.onTextureLoaded, this); - } -} - -NormalMapFilter.prototype = Object.create(core.AbstractFilter.prototype); -NormalMapFilter.prototype.constructor = NormalMapFilter; -module.exports = NormalMapFilter; - -/** - * Sets the map dimensions uniforms when the texture becomes available. - * - * @private - */ -NormalMapFilter.prototype.onTextureLoaded = function () -{ - this.uniforms.mapDimensions.value.x = this.uniforms.displacementMap.value.width; - this.uniforms.mapDimensions.value.y = this.uniforms.displacementMap.value.height; -}; - -Object.defineProperties(NormalMapFilter.prototype, { - /** - * The texture used for the displacement map. Must be power of 2 texture. - * - * @member {Texture} - * @memberof NormalMapFilter# - */ - map: { - get: function () - { - return this.uniforms.displacementMap.value; - }, - set: function (value) - { - this.uniforms.displacementMap.value = value; - } - }, - - /** - * The multiplier used to scale the displacement result from the map calculation. - * - * @member {Point} - * @memberof NormalMapFilter# - */ - scale: { - get: function () - { - return this.uniforms.scale.value; - }, - set: function (value) - { - this.uniforms.scale.value = value; - } - }, - - /** - * The offset used to move the displacement map. - * - * @member {Point} - * @memberof NormalMapFilter# - */ - offset: { - get: function () - { - return this.uniforms.offset.value; - }, - set: function (value) - { - this.uniforms.offset.value = value; - } - } -}); diff --git a/src/filters/normal/normalMap.frag b/src/filters/normal/normalMap.frag deleted file mode 100644 index 383d0ac..0000000 --- a/src/filters/normal/normalMap.frag +++ /dev/null @@ -1,88 +0,0 @@ -precision mediump float; - -varying vec2 vTextureCoord; -varying vec4 vColor; - -uniform sampler2D displacementMap; -uniform sampler2D uSampler; - -uniform vec4 dimensions; - -const vec2 Resolution = vec2(1.0,1.0); //resolution of screen -uniform vec3 LightPos; //light position, normalized -const vec4 LightColor = vec4(1.0, 1.0, 1.0, 1.0); //light RGBA -- alpha is intensity -const vec4 AmbientColor = vec4(1.0, 1.0, 1.0, 0.5); //ambient RGBA -- alpha is intensity -const vec3 Falloff = vec3(0.0, 1.0, 0.2); //attenuation coefficients - -uniform vec3 LightDir; // = vec3(1.0, 0.0, 1.0); - -uniform vec2 mapDimensions; // = vec2(256.0, 256.0); - - -void main(void) -{ - vec2 mapCords = vTextureCoord.xy; - - vec4 color = texture2D(uSampler, vTextureCoord.st); - vec3 nColor = texture2D(displacementMap, vTextureCoord.st).rgb; - - - mapCords *= vec2(dimensions.x/512.0, dimensions.y/512.0); - - mapCords.y *= -1.0; - mapCords.y += 1.0; - - // RGBA of our diffuse color - vec4 DiffuseColor = texture2D(uSampler, vTextureCoord); - - // RGB of our normal map - vec3 NormalMap = texture2D(displacementMap, mapCords).rgb; - - // The delta position of light - // vec3 LightDir = vec3(LightPos.xy - (gl_FragCoord.xy / Resolution.xy), LightPos.z); - vec3 LightDir = vec3(LightPos.xy - (mapCords.xy), LightPos.z); - - // Correct for aspect ratio - // LightDir.x *= Resolution.x / Resolution.y; - - // Determine distance (used for attenuation) BEFORE we normalize our LightDir - float D = length(LightDir); - - // normalize our vectors - vec3 N = normalize(NormalMap * 2.0 - 1.0); - vec3 L = normalize(LightDir); - - // Pre-multiply light color with intensity - // Then perform 'N dot L' to determine our diffuse term - vec3 Diffuse = (LightColor.rgb * LightColor.a) * max(dot(N, L), 0.0); - - // pre-multiply ambient color with intensity - vec3 Ambient = AmbientColor.rgb * AmbientColor.a; - - // calculate attenuation - float Attenuation = 1.0 / ( Falloff.x + (Falloff.y*D) + (Falloff.z*D*D) ); - - // the calculation which brings it all together - vec3 Intensity = Ambient + Diffuse * Attenuation; - vec3 FinalColor = DiffuseColor.rgb * Intensity; - gl_FragColor = vColor * vec4(FinalColor, DiffuseColor.a); - - // gl_FragColor = vec4(1.0, 0.0, 0.0, Attenuation); // vColor * vec4(FinalColor, DiffuseColor.a); - -/* - // normalise color - vec3 normal = normalize(nColor * 2.0 - 1.0); - - vec3 deltaPos = vec3( (light.xy - gl_FragCoord.xy) / resolution.xy, light.z ); - - float lambert = clamp(dot(normal, lightDir), 0.0, 1.0); - - float d = sqrt(dot(deltaPos, deltaPos)); - float att = 1.0 / ( attenuation.x + (attenuation.y*d) + (attenuation.z*d*d) ); - - vec3 result = (ambientColor * ambientIntensity) + (lightColor.rgb * lambert) * att; - result *= color.rgb; - - gl_FragColor = vec4(result, 1.0); -*/ -}