Parcourir la source

Merge pull request #7610 from BabylonJS/drigax/fixRightHandedLightDirection

Fix Right Handed light and shadow orientation regression.
Nicholas Barlow il y a 5 ans
Parent
commit
41a18aadc5

+ 1 - 0
dist/preview release/what's new.md

@@ -329,6 +329,7 @@
 - Fix shadows not rendered correctly when using point lights ([Popov72](https://github.com/Popov72))
 - Prevent depth buffer clear in shadow maps ([Sebavan](https://github.com/sebavan/)
 - Fix for bug where the light gizmo causes lights to flip orientation ([#7603](https://github.com/BabylonJS/Babylon.js/issues/7603)) ([drigax](https://github.com/drigax))
+- Fix for bug where directional lights are inverted when using a right handed scene coordinate system. ([drigax](https://github.com/drigax))
 
 ## Breaking changes
 

+ 7 - 30
src/Lights/directionalLight.ts

@@ -203,15 +203,9 @@ export class DirectionalLight extends ShadowLight {
         var xOffset = this._orthoRight - this._orthoLeft;
         var yOffset = this._orthoTop - this._orthoBottom;
 
-        if (this.getScene().useRightHandedSystem) {
-            Matrix.OrthoOffCenterRHToRef(this._orthoLeft - xOffset * this.shadowOrthoScale, this._orthoRight + xOffset * this.shadowOrthoScale,
-                this._orthoBottom - yOffset * this.shadowOrthoScale, this._orthoTop + yOffset * this.shadowOrthoScale,
-                this.shadowMinZ !== undefined ? this.shadowMinZ : activeCamera.minZ, this.shadowMaxZ !== undefined ? this.shadowMaxZ : activeCamera.maxZ, matrix);
-        } else {
-            Matrix.OrthoOffCenterLHToRef(this._orthoLeft - xOffset * this.shadowOrthoScale, this._orthoRight + xOffset * this.shadowOrthoScale,
-                this._orthoBottom - yOffset * this.shadowOrthoScale, this._orthoTop + yOffset * this.shadowOrthoScale,
-                this.shadowMinZ !== undefined ? this.shadowMinZ : activeCamera.minZ, this.shadowMaxZ !== undefined ? this.shadowMaxZ : activeCamera.maxZ, matrix);
-        }
+        Matrix.OrthoOffCenterLHToRef(this._orthoLeft - xOffset * this.shadowOrthoScale, this._orthoRight + xOffset * this.shadowOrthoScale,
+            this._orthoBottom - yOffset * this.shadowOrthoScale, this._orthoTop + yOffset * this.shadowOrthoScale,
+            this.shadowMinZ !== undefined ? this.shadowMinZ : activeCamera.minZ, this.shadowMaxZ !== undefined ? this.shadowMaxZ : activeCamera.maxZ, matrix);
     }
 
     protected _buildUniformLayout(): void {
@@ -231,37 +225,20 @@ export class DirectionalLight extends ShadowLight {
      */
     public transferToEffect(effect: Effect, lightIndex: string): DirectionalLight {
         if (this.computeTransformedInformation()) {
-            if (this.getScene().useRightHandedSystem) {
-                this._uniformBuffer.updateFloat4("vLightData", -this.transformedDirection.x, -this.transformedDirection.y, -this.transformedDirection.z, 1, lightIndex);
-            } else {
-                this._uniformBuffer.updateFloat4("vLightData", this.transformedDirection.x, this.transformedDirection.y, this.transformedDirection.z, 1, lightIndex);
-            }
+            this._uniformBuffer.updateFloat4("vLightData", this.transformedDirection.x, this.transformedDirection.y, this.transformedDirection.z, 1, lightIndex);
             return this;
         }
-        if (this.getScene().useRightHandedSystem) {
-            this._uniformBuffer.updateFloat4("vLightData", -this.direction.x, -this.direction.y, -this.direction.z, 1, lightIndex);
-        } else {
-            this._uniformBuffer.updateFloat4("vLightData", this.direction.x, this.direction.y, this.direction.z, 1, lightIndex);
-        }
-
+        this._uniformBuffer.updateFloat4("vLightData", this.direction.x, this.direction.y, this.direction.z, 1, lightIndex);
         return this;
     }
 
     public transferToNodeMaterialEffect(effect: Effect, lightDataUniformName: string): Light {
         if (this.computeTransformedInformation()) {
-            if (this.getScene().useRightHandedSystem) {
-                effect.setFloat3(lightDataUniformName, -this.transformedDirection.x, -this.transformedDirection.y, -this.transformedDirection.z);
-            } else {
-                effect.setFloat3(lightDataUniformName, this.transformedDirection.x, this.transformedDirection.y, this.transformedDirection.z);
-            }
+            effect.setFloat3(lightDataUniformName, this.transformedDirection.x, this.transformedDirection.y, this.transformedDirection.z);
             return this;
         }
-        if (this.getScene().useRightHandedSystem) {
-            effect.setFloat3(lightDataUniformName, -this.direction.x, -this.direction.y, -this.direction.z);
-        } else {
-            effect.setFloat3(lightDataUniformName, this.direction.x, this.direction.y, this.direction.z);
-        }
 
+        effect.setFloat3(lightDataUniformName, this.direction.x, this.direction.y, this.direction.z);
         return this;
     }
 

BIN
tests/validation/ReferenceImages/softShadowsRightHanded.png


+ 7 - 2
tests/validation/config.json

@@ -287,6 +287,11 @@
             "referenceImage": "softShadows.png"
         },
         {
+            "title": "Soft Shadows (Right Handed)",
+            "playgroundId": "#0YYQ3N#2",
+            "referenceImage": "softShadowsRightHanded.png"
+        },
+        {
             "title": "Fresnel",
             "playgroundId": "#603JUZ#1",
             "referenceImage": "fresnel.png"
@@ -552,13 +557,13 @@
         },
         {
             "title": "GLTF Serializer with Negative World Matrix",
-            "playgroundId": "#KX53VK#27",
+            "playgroundId": "#KX53VK#35",
             "referenceImage": "glTFSerializerNegativeWorldMatrix.png",
             "errorRatio": 1.1
         },
         {
             "title": "GLTF Serializer with Negative World Matrix (Right Handed)",
-            "playgroundId": "#KX53VK#30",
+            "playgroundId": "#KX53VK#36",
             "referenceImage": "glTFSerializerNegativeWorldMatrix_Right.png",
             "errorRatio": 1.1
         },