mirror of
https://github.com/photonstorm/phaser
synced 2024-09-20 06:21:54 +00:00
Fix incorrect lighting with rotated cameras.
This commit is contained in:
parent
9454d1a11a
commit
d5de498ea4
4 changed files with 21 additions and 12 deletions
|
@ -45,6 +45,7 @@ var Lighting = {
|
|||
* @webglOnly
|
||||
* @since 3.90.0
|
||||
* @param {boolean} enable - `true` to use lighting, or `false` to disable it.
|
||||
* @return {this} This Game Object instance.
|
||||
*/
|
||||
setLighting: function (enable)
|
||||
{
|
||||
|
|
|
@ -184,13 +184,17 @@ var BatchHandlerQuadLight = new Class({
|
|||
|
||||
var lightName = 'uLights[' + i + '].';
|
||||
|
||||
cameraMatrix.transformPoint(light.x, light.y, vec);
|
||||
cameraMatrix.transformPoint(
|
||||
light.x - (camera.scrollX * light.scrollFactorX * camera.zoom),
|
||||
light.y - (camera.scrollY * light.scrollFactorY * camera.zoom),
|
||||
vec
|
||||
);
|
||||
|
||||
program.setUniform(
|
||||
lightName + 'position',
|
||||
[
|
||||
vec.x - (camera.scrollX * light.scrollFactorX * camera.zoom),
|
||||
height - (vec.y - (camera.scrollY * light.scrollFactorY * camera.zoom)),
|
||||
vec.x,
|
||||
height - (vec.y),
|
||||
light.z * camera.zoom
|
||||
]
|
||||
);
|
||||
|
@ -289,6 +293,7 @@ var BatchHandlerQuadLight = new Class({
|
|||
currentBatchEntry.unit = 2;
|
||||
|
||||
// Normal map rotation
|
||||
normalMapRotation = -normalMapRotation - currentContext.camera.rotation;
|
||||
if (this._normalMapRotation !== normalMapRotation)
|
||||
{
|
||||
// Complete the entire batch if the normal map rotation changes.
|
||||
|
@ -299,9 +304,8 @@ var BatchHandlerQuadLight = new Class({
|
|||
|
||||
if (normalMapRotation)
|
||||
{
|
||||
var rot = -normalMapRotation;
|
||||
var c = Math.cos(rot);
|
||||
var s = Math.sin(rot);
|
||||
var c = Math.cos(normalMapRotation);
|
||||
var s = Math.sin(normalMapRotation);
|
||||
|
||||
inverseRotationMatrix[1] = s;
|
||||
inverseRotationMatrix[3] = -s;
|
||||
|
|
|
@ -209,6 +209,7 @@ var BatchHandlerTileSpriteLight = new Class({
|
|||
currentBatchEntry.unit = 2;
|
||||
|
||||
// Normal map rotation
|
||||
normalMapRotation = -normalMapRotation - currentContext.camera.rotation;
|
||||
if (this._normalMapRotation !== normalMapRotation)
|
||||
{
|
||||
// Complete the entire batch if the normal map rotation changes.
|
||||
|
@ -219,9 +220,8 @@ var BatchHandlerTileSpriteLight = new Class({
|
|||
|
||||
if (normalMapRotation)
|
||||
{
|
||||
var rot = -normalMapRotation;
|
||||
var c = Math.cos(rot);
|
||||
var s = Math.sin(rot);
|
||||
var c = Math.cos(normalMapRotation);
|
||||
var s = Math.sin(normalMapRotation);
|
||||
|
||||
inverseRotationMatrix[1] = s;
|
||||
inverseRotationMatrix[3] = -s;
|
||||
|
|
|
@ -179,13 +179,17 @@ var BatchHandlerTriFlatLight = new Class({
|
|||
|
||||
var lightName = 'uLights[' + i + '].';
|
||||
|
||||
cameraMatrix.transformPoint(light.x, light.y, vec);
|
||||
cameraMatrix.transformPoint(
|
||||
light.x - camera.scrollX * light.scrollFactorX * camera.zoom,
|
||||
light.y - camera.scrollY * light.scrollFactorY * camera.zoom,
|
||||
vec
|
||||
);
|
||||
|
||||
program.setUniform(
|
||||
lightName + 'position',
|
||||
[
|
||||
vec.x - (camera.scrollX * light.scrollFactorX * camera.zoom),
|
||||
height - (vec.y - (camera.scrollY * light.scrollFactorY * camera.zoom))
|
||||
vec.x,
|
||||
height - vec.y
|
||||
]
|
||||
);
|
||||
program.setUniform(
|
||||
|
|
Loading…
Reference in a new issue