Skip to content

Commit

Permalink
Merge pull request #2222 from bghgary/fix-calc-tangent
Browse files Browse the repository at this point in the history
Fix calculated tangent when using right handed system
  • Loading branch information
deltakosh authored Jun 2, 2017
2 parents 988813f + d827032 commit db588ba
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 3 deletions.
1 change: 1 addition & 0 deletions materialsLibrary/src/cell/babylon.cellMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module BABYLON {
public NDOTL = true;
public CUSTOMUSERLIGHTING = true;
public CELLBASIC = true;
public USERIGHTHANDEDSYSTEM = false;

constructor() {
super();
Expand Down
1 change: 1 addition & 0 deletions materialsLibrary/src/fur/babylon.furMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module BABYLON {
public BonesPerMesh = 0;
public INSTANCES = false;
public HIGHLEVEL = false;
public USERIGHTHANDEDSYSTEM = false;

constructor() {
super();
Expand Down
1 change: 1 addition & 0 deletions materialsLibrary/src/gradient/babylon.gradientMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ module BABYLON {
public NUM_BONE_INFLUENCERS = 0;
public BonesPerMesh = 0;
public INSTANCES = false;
public USERIGHTHANDEDSYSTEM = false;

constructor() {
super();
Expand Down
2 changes: 2 additions & 0 deletions materialsLibrary/src/grid/babylon.gridmaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ module BABYLON {

public FOG = false;

public USERIGHTHANDEDSYSTEM = false;

constructor() {
super();
this.rebuild();
Expand Down
1 change: 1 addition & 0 deletions materialsLibrary/src/lava/babylon.lavaMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ module BABYLON {
public NUM_BONE_INFLUENCERS = 0;
public BonesPerMesh = 0;
public INSTANCES = false;
public USERIGHTHANDEDSYSTEM = false;

constructor() {
super();
Expand Down
1 change: 1 addition & 0 deletions materialsLibrary/src/normal/babylon.normalMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ module BABYLON {
public NUM_BONE_INFLUENCERS = 0;
public BonesPerMesh = 0;
public INSTANCES = false;
public USERIGHTHANDEDSYSTEM = false;

constructor() {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module BABYLON {
public NUM_BONE_INFLUENCERS = 0;
public BonesPerMesh = 0;
public INSTANCES = false;
public USERIGHTHANDEDSYSTEM = false;

constructor() {
super();
Expand Down
1 change: 1 addition & 0 deletions materialsLibrary/src/simple/babylon.simpleMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module BABYLON {
public NUM_BONE_INFLUENCERS = 0;
public BonesPerMesh = 0;
public INSTANCES = false;
public USERIGHTHANDEDSYSTEM = false;

constructor() {
super();
Expand Down
1 change: 1 addition & 0 deletions materialsLibrary/src/sky/babylon.skyMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module BABYLON {
public FOG = false;
public VERTEXCOLOR = false;
public VERTEXALPHA = false;
public USERIGHTHANDEDSYSTEM = false;

constructor() {
super();
Expand Down
1 change: 1 addition & 0 deletions materialsLibrary/src/terrain/babylon.terrainMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module BABYLON {
public NUM_BONE_INFLUENCERS = 0;
public BonesPerMesh = 0;
public INSTANCES = false;
public USERIGHTHANDEDSYSTEM = false;

constructor() {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module BABYLON {
public NUM_BONE_INFLUENCERS = 0;
public BonesPerMesh = 0;
public INSTANCES = false;
public USERIGHTHANDEDSYSTEM = false;

constructor() {
super();
Expand Down
2 changes: 1 addition & 1 deletion materialsLibrary/src/water/babylon.waterMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module BABYLON {
public FRESNELSEPARATE = false;
public BUMPSUPERIMPOSE = false;
public BUMPAFFECTSREFLECTION = false;

public USERIGHTHANDEDSYSTEM = false;

constructor() {
super();
Expand Down
1 change: 1 addition & 0 deletions src/Materials/babylon.materialHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/Materials/babylon.pbrMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
public INVERTNORMALMAPY = false;
public TWOSIDEDLIGHTING = false;
public SHADOWFULLFLOAT = false;
public USERIGHTHANDEDSYSTEM = false;

public METALLICWORKFLOW = false;
public METALLICMAP = false;
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/Materials/babylon.standardMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ module BABYLON {
public MORPHTARGETS_NORMAL = false;
public MORPHTARGETS_TANGENT = false;
public NUM_MORPH_INFLUENCERS = 0;
public USERIGHTHANDEDSYSTEM = false;

constructor() {
super();
Expand Down
4 changes: 4 additions & 0 deletions src/Shaders/ShadersInclude/bumpFragmentFunctions.fx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 17 additions & 1 deletion src/babylon.scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@
public clipPlane: Plane;
public animationsEnabled = true;
public constantlyUpdateMeshUnderPointer = false;
public useRightHandedSystem = false;

public hoverCursor = "pointer";

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit db588ba

Please sign in to comment.