Fix incorrect lighting with rotated cameras.

This commit is contained in:
Ben Richards 2024-07-30 18:12:02 +12:00
parent 9454d1a11a
commit d5de498ea4
4 changed files with 21 additions and 12 deletions

View file

@ -45,6 +45,7 @@ var Lighting = {
* @webglOnly * @webglOnly
* @since 3.90.0 * @since 3.90.0
* @param {boolean} enable - `true` to use lighting, or `false` to disable it. * @param {boolean} enable - `true` to use lighting, or `false` to disable it.
* @return {this} This Game Object instance.
*/ */
setLighting: function (enable) setLighting: function (enable)
{ {

View file

@ -184,13 +184,17 @@ var BatchHandlerQuadLight = new Class({
var lightName = 'uLights[' + i + '].'; 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( program.setUniform(
lightName + 'position', lightName + 'position',
[ [
vec.x - (camera.scrollX * light.scrollFactorX * camera.zoom), vec.x,
height - (vec.y - (camera.scrollY * light.scrollFactorY * camera.zoom)), height - (vec.y),
light.z * camera.zoom light.z * camera.zoom
] ]
); );
@ -289,6 +293,7 @@ var BatchHandlerQuadLight = new Class({
currentBatchEntry.unit = 2; currentBatchEntry.unit = 2;
// Normal map rotation // Normal map rotation
normalMapRotation = -normalMapRotation - currentContext.camera.rotation;
if (this._normalMapRotation !== normalMapRotation) if (this._normalMapRotation !== normalMapRotation)
{ {
// Complete the entire batch if the normal map rotation changes. // Complete the entire batch if the normal map rotation changes.
@ -299,9 +304,8 @@ var BatchHandlerQuadLight = new Class({
if (normalMapRotation) if (normalMapRotation)
{ {
var rot = -normalMapRotation; var c = Math.cos(normalMapRotation);
var c = Math.cos(rot); var s = Math.sin(normalMapRotation);
var s = Math.sin(rot);
inverseRotationMatrix[1] = s; inverseRotationMatrix[1] = s;
inverseRotationMatrix[3] = -s; inverseRotationMatrix[3] = -s;

View file

@ -209,6 +209,7 @@ var BatchHandlerTileSpriteLight = new Class({
currentBatchEntry.unit = 2; currentBatchEntry.unit = 2;
// Normal map rotation // Normal map rotation
normalMapRotation = -normalMapRotation - currentContext.camera.rotation;
if (this._normalMapRotation !== normalMapRotation) if (this._normalMapRotation !== normalMapRotation)
{ {
// Complete the entire batch if the normal map rotation changes. // Complete the entire batch if the normal map rotation changes.
@ -219,9 +220,8 @@ var BatchHandlerTileSpriteLight = new Class({
if (normalMapRotation) if (normalMapRotation)
{ {
var rot = -normalMapRotation; var c = Math.cos(normalMapRotation);
var c = Math.cos(rot); var s = Math.sin(normalMapRotation);
var s = Math.sin(rot);
inverseRotationMatrix[1] = s; inverseRotationMatrix[1] = s;
inverseRotationMatrix[3] = -s; inverseRotationMatrix[3] = -s;

View file

@ -179,13 +179,17 @@ var BatchHandlerTriFlatLight = new Class({
var lightName = 'uLights[' + i + '].'; 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( program.setUniform(
lightName + 'position', lightName + 'position',
[ [
vec.x - (camera.scrollX * light.scrollFactorX * camera.zoom), vec.x,
height - (vec.y - (camera.scrollY * light.scrollFactorY * camera.zoom)) height - vec.y
] ]
); );
program.setUniform( program.setUniform(