2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2018-04-05 08:02:36 +00:00
|
|
|
* @author Felipe Alfonso <@bitnenfer>
|
2018-02-12 16:01:20 +00:00
|
|
|
* @copyright 2018 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2018-01-26 23:17:11 +00:00
|
|
|
var Class = require('../../../utils/Class');
|
2018-05-08 22:04:57 +00:00
|
|
|
var ShaderSourceFS = require('../shaders/ForwardDiffuse-frag.js');
|
2018-02-09 19:19:21 +00:00
|
|
|
var TextureTintPipeline = require('./TextureTintPipeline');
|
|
|
|
|
2018-01-30 22:46:43 +00:00
|
|
|
var LIGHT_COUNT = 10;
|
2018-01-26 23:17:11 +00:00
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
|
|
|
* @classdesc
|
2018-04-24 19:52:57 +00:00
|
|
|
* ForwardDiffuseLightPipeline implements a forward rendering approach for 2D lights.
|
|
|
|
* This pipeline extends TextureTintPipeline so it implements all it's rendering functions
|
|
|
|
* and batching system.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @class ForwardDiffuseLightPipeline
|
2018-04-18 11:13:49 +00:00
|
|
|
* @extends Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline
|
|
|
|
* @memberOf Phaser.Renderer.WebGL.Pipelines
|
2018-02-09 19:19:21 +00:00
|
|
|
* @constructor
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-03-05 15:28:59 +00:00
|
|
|
* @param {object} config - [description]
|
2018-02-09 19:19:21 +00:00
|
|
|
*/
|
2018-01-26 23:17:11 +00:00
|
|
|
var ForwardDiffuseLightPipeline = new Class({
|
|
|
|
|
|
|
|
Extends: TextureTintPipeline,
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
2018-03-05 14:29:48 +00:00
|
|
|
function ForwardDiffuseLightPipeline (config)
|
2018-01-26 23:17:11 +00:00
|
|
|
{
|
2018-10-02 10:09:58 +00:00
|
|
|
LIGHT_COUNT = config.maxLights;
|
|
|
|
|
2018-03-05 14:29:48 +00:00
|
|
|
config.fragShader = ShaderSourceFS.replace('%LIGHT_COUNT%', LIGHT_COUNT.toString());
|
|
|
|
|
|
|
|
TextureTintPipeline.call(this, config);
|
2018-07-13 10:14:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Default normal map texture to use.
|
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.Pipelines.ForwardDiffuseLightPipeline#defaultNormalMap
|
|
|
|
* @type {Phaser.Texture.Frame}
|
|
|
|
* @private
|
|
|
|
* @since 3.11.0
|
|
|
|
*/
|
|
|
|
this.defaultNormalMap;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the Game has fully booted and the Renderer has finished setting up.
|
|
|
|
*
|
|
|
|
* By this stage all Game level systems are now in place and you can perform any final
|
|
|
|
* tasks that the pipeline may need that relied on game systems such as the Texture Manager.
|
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.Pipelines.ForwardDiffuseLightPipeline#boot
|
|
|
|
* @override
|
|
|
|
* @since 3.11.0
|
|
|
|
*/
|
|
|
|
boot: function ()
|
|
|
|
{
|
|
|
|
this.defaultNormalMap = this.game.textures.getFrame('__DEFAULT');
|
2018-01-26 23:17:11 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-07-11 15:24:58 +00:00
|
|
|
* This function binds its base class resources and this lights 2D resources.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2018-04-18 11:13:49 +00:00
|
|
|
* @method Phaser.Renderer.WebGL.Pipelines.ForwardDiffuseLightPipeline#onBind
|
2018-04-19 12:28:10 +00:00
|
|
|
* @override
|
2018-02-09 19:19:21 +00:00
|
|
|
* @since 3.0.0
|
2018-07-11 15:24:58 +00:00
|
|
|
*
|
|
|
|
* @param {Phaser.GameObjects.GameObject} [gameObject] - The Game Object that invoked this pipeline, if any.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2018-09-25 10:36:36 +00:00
|
|
|
* @return {this} This WebGLPipeline instance.
|
2018-02-09 19:19:21 +00:00
|
|
|
*/
|
2018-07-11 15:24:58 +00:00
|
|
|
onBind: function (gameObject)
|
2018-01-26 23:17:11 +00:00
|
|
|
{
|
|
|
|
TextureTintPipeline.prototype.onBind.call(this);
|
|
|
|
|
|
|
|
var renderer = this.renderer;
|
2018-01-30 03:38:31 +00:00
|
|
|
var program = this.program;
|
2018-01-26 23:17:11 +00:00
|
|
|
|
|
|
|
this.mvpUpdate();
|
|
|
|
|
2018-01-30 03:38:31 +00:00
|
|
|
renderer.setInt1(program, 'uNormSampler', 1);
|
2018-01-26 23:17:11 +00:00
|
|
|
renderer.setFloat2(program, 'uResolution', this.width, this.height);
|
|
|
|
|
2018-07-11 15:24:58 +00:00
|
|
|
if (gameObject)
|
|
|
|
{
|
|
|
|
this.setNormalMap(gameObject);
|
|
|
|
}
|
|
|
|
|
2018-01-26 23:17:11 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-04-24 19:52:57 +00:00
|
|
|
* This function sets all the needed resources for each camera pass.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2018-04-18 11:13:49 +00:00
|
|
|
* @method Phaser.Renderer.WebGL.Pipelines.ForwardDiffuseLightPipeline#onRender
|
2018-02-09 19:19:21 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {Phaser.Scene} scene - [description]
|
|
|
|
* @param {Phaser.Cameras.Scene2D.Camera} camera - [description]
|
|
|
|
*
|
2018-09-25 10:36:36 +00:00
|
|
|
* @return {this} This WebGLPipeline instance.
|
2018-02-09 19:19:21 +00:00
|
|
|
*/
|
2018-01-29 21:46:48 +00:00
|
|
|
onRender: function (scene, camera)
|
|
|
|
{
|
2018-05-31 15:57:21 +00:00
|
|
|
this.active = false;
|
|
|
|
|
2018-03-12 12:55:09 +00:00
|
|
|
var lightManager = scene.sys.lights;
|
2018-01-31 01:11:51 +00:00
|
|
|
|
2018-05-31 15:57:21 +00:00
|
|
|
if (!lightManager || lightManager.lights.length <= 0 || !lightManager.active)
|
2018-03-12 02:22:42 +00:00
|
|
|
{
|
2018-05-31 15:57:21 +00:00
|
|
|
// Passthru
|
2018-03-12 02:22:42 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2018-05-31 15:57:21 +00:00
|
|
|
var lights = lightManager.cull(camera);
|
|
|
|
var lightCount = Math.min(lights.length, LIGHT_COUNT);
|
2018-01-31 01:11:51 +00:00
|
|
|
|
2018-05-31 15:57:21 +00:00
|
|
|
if (lightCount === 0)
|
2018-01-31 01:11:51 +00:00
|
|
|
{
|
2018-05-31 15:57:21 +00:00
|
|
|
return this;
|
2018-01-31 01:11:51 +00:00
|
|
|
}
|
|
|
|
|
2018-05-31 15:57:21 +00:00
|
|
|
this.active = true;
|
|
|
|
|
2018-01-30 03:38:31 +00:00
|
|
|
var renderer = this.renderer;
|
|
|
|
var program = this.program;
|
2018-01-30 22:46:43 +00:00
|
|
|
var cameraMatrix = camera.matrix;
|
|
|
|
var point = {x: 0, y: 0};
|
|
|
|
var height = renderer.height;
|
2018-02-16 18:44:07 +00:00
|
|
|
var index;
|
2018-01-30 22:46:43 +00:00
|
|
|
|
2018-02-16 18:44:07 +00:00
|
|
|
for (index = 0; index < LIGHT_COUNT; ++index)
|
2018-01-31 01:11:51 +00:00
|
|
|
{
|
2018-05-31 15:57:21 +00:00
|
|
|
// Reset lights
|
|
|
|
renderer.setFloat1(program, 'uLights[' + index + '].radius', 0);
|
2018-01-31 01:11:51 +00:00
|
|
|
}
|
|
|
|
|
2018-01-30 22:46:43 +00:00
|
|
|
renderer.setFloat4(program, 'uCamera', camera.x, camera.y, camera.rotation, camera.zoom);
|
|
|
|
renderer.setFloat3(program, 'uAmbientLightColor', lightManager.ambientColor.r, lightManager.ambientColor.g, lightManager.ambientColor.b);
|
|
|
|
|
2018-02-16 18:44:07 +00:00
|
|
|
for (index = 0; index < lightCount; ++index)
|
2018-01-30 22:46:43 +00:00
|
|
|
{
|
|
|
|
var light = lights[index];
|
|
|
|
var lightName = 'uLights[' + index + '].';
|
2018-05-31 15:57:21 +00:00
|
|
|
|
2018-01-30 22:46:43 +00:00
|
|
|
cameraMatrix.transformPoint(light.x, light.y, point);
|
2018-05-31 15:57:21 +00:00
|
|
|
|
2018-01-30 22:46:43 +00:00
|
|
|
renderer.setFloat2(program, lightName + 'position', point.x - (camera.scrollX * light.scrollFactorX * camera.zoom), height - (point.y - (camera.scrollY * light.scrollFactorY) * camera.zoom));
|
|
|
|
renderer.setFloat3(program, lightName + 'color', light.r, light.g, light.b);
|
|
|
|
renderer.setFloat1(program, lightName + 'intensity', light.intensity);
|
|
|
|
renderer.setFloat1(program, lightName + 'radius', light.radius);
|
|
|
|
}
|
2018-01-31 01:11:51 +00:00
|
|
|
|
2018-01-29 21:46:48 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-07-13 10:14:22 +00:00
|
|
|
/**
|
|
|
|
* Generic function for batching a textured quad
|
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#batchTexture
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {Phaser.GameObjects.GameObject} gameObject - Source GameObject
|
|
|
|
* @param {WebGLTexture} texture - Raw WebGLTexture associated with the quad
|
|
|
|
* @param {integer} textureWidth - Real texture width
|
|
|
|
* @param {integer} textureHeight - Real texture height
|
|
|
|
* @param {number} srcX - X coordinate of the quad
|
|
|
|
* @param {number} srcY - Y coordinate of the quad
|
|
|
|
* @param {number} srcWidth - Width of the quad
|
|
|
|
* @param {number} srcHeight - Height of the quad
|
|
|
|
* @param {number} scaleX - X component of scale
|
|
|
|
* @param {number} scaleY - Y component of scale
|
|
|
|
* @param {number} rotation - Rotation of the quad
|
|
|
|
* @param {boolean} flipX - Indicates if the quad is horizontally flipped
|
|
|
|
* @param {boolean} flipY - Indicates if the quad is vertically flipped
|
|
|
|
* @param {number} scrollFactorX - By which factor is the quad affected by the camera horizontal scroll
|
|
|
|
* @param {number} scrollFactorY - By which factor is the quad effected by the camera vertical scroll
|
|
|
|
* @param {number} displayOriginX - Horizontal origin in pixels
|
|
|
|
* @param {number} displayOriginY - Vertical origin in pixels
|
|
|
|
* @param {number} frameX - X coordinate of the texture frame
|
|
|
|
* @param {number} frameY - Y coordinate of the texture frame
|
|
|
|
* @param {number} frameWidth - Width of the texture frame
|
|
|
|
* @param {number} frameHeight - Height of the texture frame
|
|
|
|
* @param {integer} tintTL - Tint for top left
|
|
|
|
* @param {integer} tintTR - Tint for top right
|
|
|
|
* @param {integer} tintBL - Tint for bottom left
|
|
|
|
* @param {integer} tintBR - Tint for bottom right
|
|
|
|
* @param {number} tintEffect - The tint effect (0 for additive, 1 for replacement)
|
|
|
|
* @param {number} uOffset - Horizontal offset on texture coordinate
|
|
|
|
* @param {number} vOffset - Vertical offset on texture coordinate
|
|
|
|
* @param {Phaser.Cameras.Scene2D.Camera} camera - Current used camera
|
|
|
|
* @param {Phaser.GameObjects.Components.TransformMatrix} parentTransformMatrix - Parent container
|
|
|
|
*/
|
|
|
|
batchTexture: function (
|
|
|
|
gameObject,
|
|
|
|
texture,
|
|
|
|
textureWidth, textureHeight,
|
|
|
|
srcX, srcY,
|
|
|
|
srcWidth, srcHeight,
|
|
|
|
scaleX, scaleY,
|
|
|
|
rotation,
|
|
|
|
flipX, flipY,
|
|
|
|
scrollFactorX, scrollFactorY,
|
|
|
|
displayOriginX, displayOriginY,
|
|
|
|
frameX, frameY, frameWidth, frameHeight,
|
|
|
|
tintTL, tintTR, tintBL, tintBR, tintEffect,
|
|
|
|
uOffset, vOffset,
|
|
|
|
camera,
|
|
|
|
parentTransformMatrix)
|
|
|
|
{
|
|
|
|
if (!this.active)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.renderer.setPipeline(this);
|
|
|
|
|
|
|
|
var normalTexture;
|
|
|
|
|
2018-08-23 16:30:27 +00:00
|
|
|
if (gameObject.displayTexture)
|
|
|
|
{
|
|
|
|
normalTexture = gameObject.displayTexture.dataSource[gameObject.displayFrame.sourceIndex];
|
|
|
|
}
|
|
|
|
else if (gameObject.texture)
|
2018-07-13 10:14:22 +00:00
|
|
|
{
|
|
|
|
normalTexture = gameObject.texture.dataSource[gameObject.frame.sourceIndex];
|
|
|
|
}
|
|
|
|
else if (gameObject.tileset)
|
|
|
|
{
|
|
|
|
normalTexture = gameObject.tileset.image.dataSource[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!normalTexture)
|
|
|
|
{
|
2018-08-23 16:30:27 +00:00
|
|
|
console.warn('Normal map missing or invalid');
|
|
|
|
return;
|
2018-07-13 10:14:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.setTexture2D(normalTexture.glTexture, 1);
|
|
|
|
|
|
|
|
var camMatrix = this._tempMatrix1;
|
|
|
|
var spriteMatrix = this._tempMatrix2;
|
|
|
|
var calcMatrix = this._tempMatrix3;
|
|
|
|
|
2018-08-23 16:30:27 +00:00
|
|
|
var u0 = (frameX / textureWidth) + uOffset;
|
|
|
|
var v0 = (frameY / textureHeight) + vOffset;
|
|
|
|
var u1 = (frameX + frameWidth) / textureWidth + uOffset;
|
|
|
|
var v1 = (frameY + frameHeight) / textureHeight + vOffset;
|
|
|
|
|
2018-07-13 10:14:22 +00:00
|
|
|
var width = srcWidth;
|
|
|
|
var height = srcHeight;
|
|
|
|
|
2018-08-23 16:30:27 +00:00
|
|
|
// var x = -displayOriginX + frameX;
|
|
|
|
// var y = -displayOriginY + frameY;
|
|
|
|
|
2018-07-13 10:14:22 +00:00
|
|
|
var x = -displayOriginX;
|
|
|
|
var y = -displayOriginY;
|
|
|
|
|
2018-08-23 16:30:27 +00:00
|
|
|
if (gameObject.isCropped)
|
|
|
|
{
|
|
|
|
var crop = gameObject._crop;
|
|
|
|
|
|
|
|
width = crop.width;
|
|
|
|
height = crop.height;
|
|
|
|
|
|
|
|
srcWidth = crop.width;
|
|
|
|
srcHeight = crop.height;
|
|
|
|
|
|
|
|
frameX = crop.x;
|
|
|
|
frameY = crop.y;
|
|
|
|
|
|
|
|
var ox = frameX;
|
|
|
|
var oy = frameY;
|
|
|
|
|
|
|
|
if (flipX)
|
|
|
|
{
|
|
|
|
ox = (frameWidth - crop.x - crop.width);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flipY && !texture.isRenderTexture)
|
|
|
|
{
|
|
|
|
oy = (frameHeight - crop.y - crop.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
u0 = (ox / textureWidth) + uOffset;
|
|
|
|
v0 = (oy / textureHeight) + vOffset;
|
|
|
|
u1 = (ox + crop.width) / textureWidth + uOffset;
|
|
|
|
v1 = (oy + crop.height) / textureHeight + vOffset;
|
|
|
|
|
|
|
|
x = -displayOriginX + frameX;
|
|
|
|
y = -displayOriginY + frameY;
|
|
|
|
}
|
|
|
|
|
2018-07-13 10:14:22 +00:00
|
|
|
// Invert the flipY if this is a RenderTexture
|
|
|
|
flipY = flipY ^ (texture.isRenderTexture ? 1 : 0);
|
|
|
|
|
|
|
|
if (flipX)
|
|
|
|
{
|
|
|
|
width *= -1;
|
|
|
|
x += srcWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flipY)
|
|
|
|
{
|
|
|
|
height *= -1;
|
|
|
|
y += srcHeight;
|
|
|
|
}
|
|
|
|
|
2018-08-23 16:30:27 +00:00
|
|
|
// Do we need this? (doubt it)
|
|
|
|
// if (camera.roundPixels)
|
|
|
|
// {
|
|
|
|
// x |= 0;
|
|
|
|
// y |= 0;
|
|
|
|
// }
|
2018-07-13 10:14:22 +00:00
|
|
|
|
|
|
|
var xw = x + width;
|
|
|
|
var yh = y + height;
|
|
|
|
|
|
|
|
spriteMatrix.applyITRS(srcX, srcY, rotation, scaleX, scaleY);
|
|
|
|
|
|
|
|
camMatrix.copyFrom(camera.matrix);
|
|
|
|
|
|
|
|
if (parentTransformMatrix)
|
|
|
|
{
|
|
|
|
// Multiply the camera by the parent matrix
|
|
|
|
camMatrix.multiplyWithOffset(parentTransformMatrix, -camera.scrollX * scrollFactorX, -camera.scrollY * scrollFactorY);
|
|
|
|
|
|
|
|
// Undo the camera scroll
|
|
|
|
spriteMatrix.e = srcX;
|
|
|
|
spriteMatrix.f = srcY;
|
|
|
|
|
|
|
|
// Multiply by the Sprite matrix, store result in calcMatrix
|
|
|
|
camMatrix.multiply(spriteMatrix, calcMatrix);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
spriteMatrix.e -= camera.scrollX * scrollFactorX;
|
|
|
|
spriteMatrix.f -= camera.scrollY * scrollFactorY;
|
|
|
|
|
|
|
|
// Multiply by the Sprite matrix, store result in calcMatrix
|
|
|
|
camMatrix.multiply(spriteMatrix, calcMatrix);
|
|
|
|
}
|
|
|
|
|
2018-08-23 16:30:27 +00:00
|
|
|
var tx0 = calcMatrix.getX(x, y);
|
|
|
|
var ty0 = calcMatrix.getY(x, y);
|
2018-07-13 10:14:22 +00:00
|
|
|
|
2018-08-23 16:30:27 +00:00
|
|
|
var tx1 = calcMatrix.getX(x, yh);
|
|
|
|
var ty1 = calcMatrix.getY(x, yh);
|
2018-07-13 10:14:22 +00:00
|
|
|
|
2018-08-23 16:30:27 +00:00
|
|
|
var tx2 = calcMatrix.getX(xw, yh);
|
|
|
|
var ty2 = calcMatrix.getY(xw, yh);
|
2018-07-13 10:14:22 +00:00
|
|
|
|
2018-08-23 16:30:27 +00:00
|
|
|
var tx3 = calcMatrix.getX(xw, y);
|
|
|
|
var ty3 = calcMatrix.getY(xw, y);
|
2018-07-13 10:14:22 +00:00
|
|
|
|
|
|
|
if (camera.roundPixels)
|
|
|
|
{
|
|
|
|
tx0 |= 0;
|
|
|
|
ty0 |= 0;
|
|
|
|
|
|
|
|
tx1 |= 0;
|
|
|
|
ty1 |= 0;
|
|
|
|
|
|
|
|
tx2 |= 0;
|
|
|
|
ty2 |= 0;
|
|
|
|
|
|
|
|
tx3 |= 0;
|
|
|
|
ty3 |= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setTexture2D(texture, 0);
|
|
|
|
|
2018-08-23 16:30:27 +00:00
|
|
|
this.batchQuad(tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3, u0, v0, u1, v1, tintTL, tintTR, tintBL, tintBR, tintEffect);
|
2018-07-13 10:14:22 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-07-11 15:55:18 +00:00
|
|
|
* Sets the Game Objects normal map as the active texture.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2018-07-11 15:55:18 +00:00
|
|
|
* @method Phaser.Renderer.WebGL.Pipelines.ForwardDiffuseLightPipeline#setNormalMap
|
|
|
|
* @since 3.11.0
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2018-07-11 15:55:18 +00:00
|
|
|
* @param {Phaser.GameObjects.GameObject} gameObject - [description]
|
2018-02-09 19:19:21 +00:00
|
|
|
*/
|
2018-07-11 15:24:58 +00:00
|
|
|
setNormalMap: function (gameObject)
|
|
|
|
{
|
2018-07-13 10:14:22 +00:00
|
|
|
if (!this.active || !gameObject)
|
2018-07-11 15:24:58 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-13 10:14:22 +00:00
|
|
|
var normalTexture;
|
2018-07-11 15:24:58 +00:00
|
|
|
|
2018-07-13 10:14:22 +00:00
|
|
|
if (gameObject.texture)
|
2018-07-11 15:24:58 +00:00
|
|
|
{
|
2018-07-13 10:14:22 +00:00
|
|
|
normalTexture = gameObject.texture.dataSource[gameObject.frame.sourceIndex];
|
2018-07-11 15:24:58 +00:00
|
|
|
}
|
2018-07-11 15:55:18 +00:00
|
|
|
|
2018-07-13 10:14:22 +00:00
|
|
|
if (!normalTexture)
|
|
|
|
{
|
|
|
|
normalTexture = this.defaultNormalMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setTexture2D(normalTexture.glTexture, 1);
|
|
|
|
|
2018-07-11 15:55:18 +00:00
|
|
|
this.renderer.setPipeline(gameObject.defaultPipeline);
|
2018-07-11 15:24:58 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
2018-04-18 11:13:49 +00:00
|
|
|
* @method Phaser.Renderer.WebGL.Pipelines.ForwardDiffuseLightPipeline#batchSprite
|
2018-02-09 19:19:21 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {Phaser.GameObjects.Sprite} sprite - [description]
|
|
|
|
* @param {Phaser.Cameras.Scene2D.Camera} camera - [description]
|
2018-04-18 21:40:27 +00:00
|
|
|
* @param {Phaser.GameObjects.Components.TransformMatrix} parentTransformMatrix - [description]
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2018-07-11 15:55:18 +00:00
|
|
|
*/
|
2018-04-18 21:40:27 +00:00
|
|
|
batchSprite: function (sprite, camera, parentTransformMatrix)
|
2018-01-30 03:38:31 +00:00
|
|
|
{
|
2018-05-31 15:57:21 +00:00
|
|
|
if (!this.active)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-04 13:31:19 +00:00
|
|
|
var normalTexture = sprite.texture.dataSource[sprite.frame.sourceIndex];
|
2018-01-30 03:38:31 +00:00
|
|
|
|
|
|
|
if (normalTexture)
|
|
|
|
{
|
2018-02-14 02:46:34 +00:00
|
|
|
this.renderer.setPipeline(this);
|
2018-05-31 15:57:21 +00:00
|
|
|
|
2018-02-14 02:46:34 +00:00
|
|
|
this.setTexture2D(normalTexture.glTexture, 1);
|
2018-01-30 03:38:31 +00:00
|
|
|
|
2018-07-11 15:55:18 +00:00
|
|
|
TextureTintPipeline.prototype.batchSprite.call(this, sprite, camera, parentTransformMatrix);
|
2018-01-30 03:38:31 +00:00
|
|
|
}
|
2018-01-26 23:17:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2018-01-31 01:11:51 +00:00
|
|
|
ForwardDiffuseLightPipeline.LIGHT_COUNT = LIGHT_COUNT;
|
|
|
|
|
2018-01-26 23:17:11 +00:00
|
|
|
module.exports = ForwardDiffuseLightPipeline;
|