|
@@ -1,7 +1,6 @@
|
|
module BABYLON.Internals {
|
|
module BABYLON.Internals {
|
|
|
|
|
|
- class FileFaceOrientation
|
|
|
|
- {
|
|
|
|
|
|
+ class FileFaceOrientation {
|
|
public name: string;
|
|
public name: string;
|
|
public worldAxisForNormal: Vector3; // the world axis corresponding to the normal to the face
|
|
public worldAxisForNormal: Vector3; // the world axis corresponding to the normal to the face
|
|
public worldAxisForFileX: Vector3; // the world axis corresponding to texture right x-axis in file
|
|
public worldAxisForFileX: Vector3; // the world axis corresponding to texture right x-axis in file
|
|
@@ -15,7 +14,7 @@ module BABYLON.Internals {
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
- export class CubeMapToSphericalPolynomialTools {
|
|
|
|
|
|
+ export class CubeMapToSphericalPolynomialTools {
|
|
|
|
|
|
private static FileFaces: FileFaceOrientation[] = [
|
|
private static FileFaces: FileFaceOrientation[] = [
|
|
new FileFaceOrientation("right", new Vector3(1, 0, 0), new Vector3(0, 0, -1), new Vector3(0, -1, 0)), // +X east
|
|
new FileFaceOrientation("right", new Vector3(1, 0, 0), new Vector3(0, 0, -1), new Vector3(0, -1, 0)), // +X east
|
|
@@ -25,7 +24,7 @@ module BABYLON.Internals {
|
|
new FileFaceOrientation("front", new Vector3(0, 0, 1), new Vector3(1, 0, 0), new Vector3(0, -1, 0)), // +Z top
|
|
new FileFaceOrientation("front", new Vector3(0, 0, 1), new Vector3(1, 0, 0), new Vector3(0, -1, 0)), // +Z top
|
|
new FileFaceOrientation("back", new Vector3(0, 0, -1), new Vector3(-1, 0, 0), new Vector3(0, -1, 0))// -Z bottom
|
|
new FileFaceOrientation("back", new Vector3(0, 0, -1), new Vector3(-1, 0, 0), new Vector3(0, -1, 0))// -Z bottom
|
|
];
|
|
];
|
|
-
|
|
|
|
|
|
+
|
|
public static ConvertCubeMapToSphericalPolynomial(cubeInfo: CubeMapInfo): SphericalPolynomial {
|
|
public static ConvertCubeMapToSphericalPolynomial(cubeInfo: CubeMapInfo): SphericalPolynomial {
|
|
var sphericalHarmonics = new SphericalHarmonics();
|
|
var sphericalHarmonics = new SphericalHarmonics();
|
|
var totalSolidAngle = 0.0;
|
|
var totalSolidAngle = 0.0;
|
|
@@ -37,8 +36,7 @@ module BABYLON.Internals {
|
|
// The (u,v) of the first texel is half a texel from the corner (-1,-1).
|
|
// The (u,v) of the first texel is half a texel from the corner (-1,-1).
|
|
var minUV = du * 0.5 - 1.0;
|
|
var minUV = du * 0.5 - 1.0;
|
|
|
|
|
|
- for (var faceIndex = 0; faceIndex < 6; faceIndex++)
|
|
|
|
- {
|
|
|
|
|
|
+ for (var faceIndex = 0; faceIndex < 6; faceIndex++) {
|
|
var fileFace = this.FileFaces[faceIndex];
|
|
var fileFace = this.FileFaces[faceIndex];
|
|
var dataArray = cubeInfo[fileFace.name];
|
|
var dataArray = cubeInfo[fileFace.name];
|
|
var v = minUV;
|
|
var v = minUV;
|
|
@@ -47,17 +45,15 @@ module BABYLON.Internals {
|
|
// This is possible because during the summation we do not need the SH-specific properties, e.g. orthogonality.
|
|
// This is possible because during the summation we do not need the SH-specific properties, e.g. orthogonality.
|
|
// Because SP is still linear, so summation is fine in that basis.
|
|
// Because SP is still linear, so summation is fine in that basis.
|
|
|
|
|
|
- for (var y = 0; y < cubeInfo.size; y++)
|
|
|
|
- {
|
|
|
|
|
|
+ for (var y = 0; y < cubeInfo.size; y++) {
|
|
var u = minUV;
|
|
var u = minUV;
|
|
|
|
|
|
- for (var x = 0; x < cubeInfo.size; x++)
|
|
|
|
- {
|
|
|
|
|
|
+ for (var x = 0; x < cubeInfo.size; x++) {
|
|
// World direction (not normalised)
|
|
// World direction (not normalised)
|
|
var worldDirection =
|
|
var worldDirection =
|
|
fileFace.worldAxisForFileX.scale(u).add(
|
|
fileFace.worldAxisForFileX.scale(u).add(
|
|
- fileFace.worldAxisForFileY.scale(v)).add(
|
|
|
|
- fileFace.worldAxisForNormal);
|
|
|
|
|
|
+ fileFace.worldAxisForFileY.scale(v)).add(
|
|
|
|
+ fileFace.worldAxisForNormal);
|
|
worldDirection.normalize();
|
|
worldDirection.normalize();
|
|
|
|
|
|
var deltaSolidAngle = Math.pow(1.0 + u * u + v * v, -3.0 / 2.0);
|
|
var deltaSolidAngle = Math.pow(1.0 + u * u + v * v, -3.0 / 2.0);
|
|
@@ -69,14 +65,14 @@ module BABYLON.Internals {
|
|
|
|
|
|
var color = new Color3(r, g, b);
|
|
var color = new Color3(r, g, b);
|
|
|
|
|
|
- sphericalHarmonics.addLight(worldDirection, color, deltaSolidAngle);
|
|
|
|
|
|
+ sphericalHarmonics.addLight(worldDirection, color, deltaSolidAngle);
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
|
|
|
|
if (faceIndex == 0) {
|
|
if (faceIndex == 0) {
|
|
dataArray[(y * cubeInfo.size * 3) + (x * 3) + 0] = 1;
|
|
dataArray[(y * cubeInfo.size * 3) + (x * 3) + 0] = 1;
|
|
dataArray[(y * cubeInfo.size * 3) + (x * 3) + 1] = 0;
|
|
dataArray[(y * cubeInfo.size * 3) + (x * 3) + 1] = 0;
|
|
- dataArray[(y * cubeInfo.size * 3) + (x * 3) + 2] = 0;
|
|
|
|
|
|
+ dataArray[(y * cubeInfo.size * 3) + (x * 3) + 2] = 0;
|
|
}
|
|
}
|
|
else if (faceIndex == 1) {
|
|
else if (faceIndex == 1) {
|
|
dataArray[(y * cubeInfo.size * 3) + (x * 3) + 0] = 0;
|
|
dataArray[(y * cubeInfo.size * 3) + (x * 3) + 0] = 0;
|
|
@@ -104,8 +100,8 @@ module BABYLON.Internals {
|
|
dataArray[(y * cubeInfo.size * 3) + (x * 3) + 2] = 1;
|
|
dataArray[(y * cubeInfo.size * 3) + (x * 3) + 2] = 1;
|
|
}
|
|
}
|
|
|
|
|
|
- var color = new Color3(dataArray[(y * cubeInfo.size * 3) + (x * 3) + 0],
|
|
|
|
- dataArray[(y * cubeInfo.size * 3) + (x * 3) + 1],
|
|
|
|
|
|
+ var color = new Color3(dataArray[(y * cubeInfo.size * 3) + (x * 3) + 0],
|
|
|
|
+ dataArray[(y * cubeInfo.size * 3) + (x * 3) + 1],
|
|
dataArray[(y * cubeInfo.size * 3) + (x * 3) + 2]);
|
|
dataArray[(y * cubeInfo.size * 3) + (x * 3) + 2]);
|
|
|
|
|
|
sphericalHarmonics.addLight(worldDirection, color, deltaSolidAngle);
|
|
sphericalHarmonics.addLight(worldDirection, color, deltaSolidAngle);
|