diff --git a/materialsLibrary/src/cell/babylon.cellMaterial.ts b/materialsLibrary/src/cell/babylon.cellMaterial.ts index 7d69838e0fb..2574c8de1eb 100644 --- a/materialsLibrary/src/cell/babylon.cellMaterial.ts +++ b/materialsLibrary/src/cell/babylon.cellMaterial.ts @@ -18,6 +18,7 @@ module BABYLON { public NDOTL = true; public CUSTOMUSERLIGHTING = true; public CELLBASIC = true; + public USERIGHTHANDEDSYSTEM = false; constructor() { super(); diff --git a/materialsLibrary/src/fur/babylon.furMaterial.ts b/materialsLibrary/src/fur/babylon.furMaterial.ts index a836b1cecbf..a7fe7a7dc87 100644 --- a/materialsLibrary/src/fur/babylon.furMaterial.ts +++ b/materialsLibrary/src/fur/babylon.furMaterial.ts @@ -17,6 +17,7 @@ module BABYLON { public BonesPerMesh = 0; public INSTANCES = false; public HIGHLEVEL = false; + public USERIGHTHANDEDSYSTEM = false; constructor() { super(); diff --git a/materialsLibrary/src/gradient/babylon.gradientMaterial.ts b/materialsLibrary/src/gradient/babylon.gradientMaterial.ts index d684bca91cf..692a4cfec92 100644 --- a/materialsLibrary/src/gradient/babylon.gradientMaterial.ts +++ b/materialsLibrary/src/gradient/babylon.gradientMaterial.ts @@ -48,6 +48,7 @@ module BABYLON { public NUM_BONE_INFLUENCERS = 0; public BonesPerMesh = 0; public INSTANCES = false; + public USERIGHTHANDEDSYSTEM = false; constructor() { super(); diff --git a/materialsLibrary/src/grid/babylon.gridmaterial.ts b/materialsLibrary/src/grid/babylon.gridmaterial.ts index e80b730a841..34665c6643f 100644 --- a/materialsLibrary/src/grid/babylon.gridmaterial.ts +++ b/materialsLibrary/src/grid/babylon.gridmaterial.ts @@ -6,6 +6,8 @@ module BABYLON { public FOG = false; + public USERIGHTHANDEDSYSTEM = false; + constructor() { super(); this.rebuild(); diff --git a/materialsLibrary/src/lava/babylon.lavaMaterial.ts b/materialsLibrary/src/lava/babylon.lavaMaterial.ts index 3acd8fd908a..794e33b66a2 100644 --- a/materialsLibrary/src/lava/babylon.lavaMaterial.ts +++ b/materialsLibrary/src/lava/babylon.lavaMaterial.ts @@ -48,6 +48,7 @@ module BABYLON { public NUM_BONE_INFLUENCERS = 0; public BonesPerMesh = 0; public INSTANCES = false; + public USERIGHTHANDEDSYSTEM = false; constructor() { super(); diff --git a/materialsLibrary/src/normal/babylon.normalMaterial.ts b/materialsLibrary/src/normal/babylon.normalMaterial.ts index 6be4c5a72f9..252e0ee4537 100644 --- a/materialsLibrary/src/normal/babylon.normalMaterial.ts +++ b/materialsLibrary/src/normal/babylon.normalMaterial.ts @@ -48,6 +48,7 @@ module BABYLON { public NUM_BONE_INFLUENCERS = 0; public BonesPerMesh = 0; public INSTANCES = false; + public USERIGHTHANDEDSYSTEM = false; constructor() { super(); diff --git a/materialsLibrary/src/shadowOnly/babylon.shadowOnlyMaterial.ts b/materialsLibrary/src/shadowOnly/babylon.shadowOnlyMaterial.ts index 34244911c3f..39cc252cab5 100644 --- a/materialsLibrary/src/shadowOnly/babylon.shadowOnlyMaterial.ts +++ b/materialsLibrary/src/shadowOnly/babylon.shadowOnlyMaterial.ts @@ -9,6 +9,7 @@ module BABYLON { public NUM_BONE_INFLUENCERS = 0; public BonesPerMesh = 0; public INSTANCES = false; + public USERIGHTHANDEDSYSTEM = false; constructor() { super(); diff --git a/materialsLibrary/src/simple/babylon.simpleMaterial.ts b/materialsLibrary/src/simple/babylon.simpleMaterial.ts index 8ab2be89ebe..6dbc035da62 100644 --- a/materialsLibrary/src/simple/babylon.simpleMaterial.ts +++ b/materialsLibrary/src/simple/babylon.simpleMaterial.ts @@ -15,6 +15,7 @@ module BABYLON { public NUM_BONE_INFLUENCERS = 0; public BonesPerMesh = 0; public INSTANCES = false; + public USERIGHTHANDEDSYSTEM = false; constructor() { super(); diff --git a/materialsLibrary/src/sky/babylon.skyMaterial.ts b/materialsLibrary/src/sky/babylon.skyMaterial.ts index 757885bd0ce..d339c8e0311 100644 --- a/materialsLibrary/src/sky/babylon.skyMaterial.ts +++ b/materialsLibrary/src/sky/babylon.skyMaterial.ts @@ -7,6 +7,7 @@ module BABYLON { public FOG = false; public VERTEXCOLOR = false; public VERTEXALPHA = false; + public USERIGHTHANDEDSYSTEM = false; constructor() { super(); diff --git a/materialsLibrary/src/terrain/babylon.terrainMaterial.ts b/materialsLibrary/src/terrain/babylon.terrainMaterial.ts index d52d8b0de90..60e93fc595e 100644 --- a/materialsLibrary/src/terrain/babylon.terrainMaterial.ts +++ b/materialsLibrary/src/terrain/babylon.terrainMaterial.ts @@ -18,6 +18,7 @@ module BABYLON { public NUM_BONE_INFLUENCERS = 0; public BonesPerMesh = 0; public INSTANCES = false; + public USERIGHTHANDEDSYSTEM = false; constructor() { super(); diff --git a/materialsLibrary/src/triPlanar/babylon.triPlanarMaterial.ts b/materialsLibrary/src/triPlanar/babylon.triPlanarMaterial.ts index 636f78df3c2..7349dae5c6c 100644 --- a/materialsLibrary/src/triPlanar/babylon.triPlanarMaterial.ts +++ b/materialsLibrary/src/triPlanar/babylon.triPlanarMaterial.ts @@ -21,6 +21,7 @@ module BABYLON { public NUM_BONE_INFLUENCERS = 0; public BonesPerMesh = 0; public INSTANCES = false; + public USERIGHTHANDEDSYSTEM = false; constructor() { super(); diff --git a/materialsLibrary/src/water/babylon.waterMaterial.ts b/materialsLibrary/src/water/babylon.waterMaterial.ts index 17bfa304a9f..6f2bf6cc93c 100644 --- a/materialsLibrary/src/water/babylon.waterMaterial.ts +++ b/materialsLibrary/src/water/babylon.waterMaterial.ts @@ -21,7 +21,7 @@ module BABYLON { public FRESNELSEPARATE = false; public BUMPSUPERIMPOSE = false; public BUMPAFFECTSREFLECTION = false; - + public USERIGHTHANDEDSYSTEM = false; constructor() { super(); diff --git a/src/Materials/babylon.materialHelper.ts b/src/Materials/babylon.materialHelper.ts index 9c683516e58..4ea3def2ba1 100644 --- a/src/Materials/babylon.materialHelper.ts +++ b/src/Materials/babylon.materialHelper.ts @@ -6,6 +6,7 @@ defines["LOGARITHMICDEPTH"] = useLogarithmicDepth; defines["POINTSIZE"] = (pointsCloud || scene.forcePointsCloud); defines["FOG"] = (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE && fogEnabled); + defines["USERIGHTHANDEDSYSTEM"] = scene.useRightHandedSystem; } } diff --git a/src/Materials/babylon.pbrMaterial.ts b/src/Materials/babylon.pbrMaterial.ts index ec44c60a1a8..5bac0d45dd8 100644 --- a/src/Materials/babylon.pbrMaterial.ts +++ b/src/Materials/babylon.pbrMaterial.ts @@ -66,6 +66,7 @@ public INVERTNORMALMAPY = false; public TWOSIDEDLIGHTING = false; public SHADOWFULLFLOAT = false; + public USERIGHTHANDEDSYSTEM = false; public METALLICWORKFLOW = false; public METALLICMAP = false; @@ -763,7 +764,11 @@ if (scene._mirroredCameraPosition) { this._defines.INVERTNORMALMAPX = !this._defines.INVERTNORMALMAPX; this._defines.INVERTNORMALMAPY = !this._defines.INVERTNORMALMAPY; - } + } + + if (scene.useRightHandedSystem) { + this._defines.USERIGHTHANDEDSYSTEM = true; + } } if (this.refractionTexture && StandardMaterial.RefractionTextureEnabled) { diff --git a/src/Materials/babylon.standardMaterial.ts b/src/Materials/babylon.standardMaterial.ts index 117e4dd542a..85ddb319668 100644 --- a/src/Materials/babylon.standardMaterial.ts +++ b/src/Materials/babylon.standardMaterial.ts @@ -63,6 +63,7 @@ module BABYLON { public MORPHTARGETS_NORMAL = false; public MORPHTARGETS_TANGENT = false; public NUM_MORPH_INFLUENCERS = 0; + public USERIGHTHANDEDSYSTEM = false; constructor() { super(); diff --git a/src/Shaders/ShadersInclude/bumpFragmentFunctions.fx b/src/Shaders/ShadersInclude/bumpFragmentFunctions.fx index bf112b1b351..70567c72142 100644 --- a/src/Shaders/ShadersInclude/bumpFragmentFunctions.fx +++ b/src/Shaders/ShadersInclude/bumpFragmentFunctions.fx @@ -23,6 +23,10 @@ vec3 tangent = dp2perp * duv1.x + dp1perp * duv2.x; vec3 binormal = dp2perp * duv1.y + dp1perp * duv2.y; + #ifdef USERIGHTHANDEDSYSTEM + binormal = -binormal; + #endif + // construct a scale-invariant frame float invmax = inversesqrt(max(dot(tangent, tangent), dot(binormal, binormal))); return mat3(tangent * invmax, binormal * invmax, normal); diff --git a/src/babylon.scene.ts b/src/babylon.scene.ts index dc0a07c23ee..29067748022 100644 --- a/src/babylon.scene.ts +++ b/src/babylon.scene.ts @@ -206,7 +206,6 @@ public clipPlane: Plane; public animationsEnabled = true; public constantlyUpdateMeshUnderPointer = false; - public useRightHandedSystem = false; public hoverCursor = "pointer"; @@ -414,6 +413,23 @@ private _onKeyDown: (evt: Event) => void; private _onKeyUp: (evt: Event) => void; + // Coordinate system + /** + * use right-handed coordinate system on this scene. + * @type {boolean} + */ + private _useRightHandedSystem = false; + public set useRightHandedSystem(value: boolean) { + if (this._useRightHandedSystem === value) { + return; + } + this._useRightHandedSystem = value; + this.markAllMaterialsAsDirty(Material.MiscDirtyFlag); + } + public get useRightHandedSystem(): boolean { + return this._useRightHandedSystem; + } + // Fog /** * is fog enabled on this scene.