Yo @Deltakosh or @sebavan … i am having trouble creating spherical polynomial diffuse ibl lighting from harmonics array i serialize from Unity:
"sh": [
0.180283263,
-0.00568266725,
-0.0125605986,
0.00725202262,
0.00569990976,
-0.009872374,
0.01033011,
-0.0104362741,
0.0250354819,
0.225713328,
0.0413432159,
-0.0197532848,
0.011403271,
0.00911192,
-0.0157832224,
0.0143798534,
-0.01522373,
0.0344359651,
0.306922019,
0.127484113,
-0.0340535268,
0.0196564719,
0.0163650271,
-0.02834928,
0.017715618,
-0.02208532,
0.0404653475
],
I try to create the diffuse lighting like this… Are you supposed to be manually create IBL Diffuse Lighting ?
// Extract RGB channels from the Unity SH array (9 coefficients per channel)
const rCoeffs = shCoeffs.slice(0, 9); // Red channel
const gCoeffs = shCoeffs.slice(9, 18); // Green channel
const bCoeffs = shCoeffs.slice(18, 27); // Blue channel
// Create spherical harmonics from Unity SH data
const sh = new BABYLON.SphericalHarmonics();
// Set the SH coefficients directly on the harmonics structure
// Unity order: L00, L1-1, L10, L11, L2-2, L2-1, L20, L21, L22
sh.l00 = new BABYLON.Vector3(rCoeffs[0], gCoeffs[0], bCoeffs[0]);
sh.l1_1 = new BABYLON.Vector3(rCoeffs[1], gCoeffs[1], bCoeffs[1]);
sh.l10 = new BABYLON.Vector3(rCoeffs[2], gCoeffs[2], bCoeffs[2]);
sh.l11 = new BABYLON.Vector3(rCoeffs[3], gCoeffs[3], bCoeffs[3]);
sh.l2_2 = new BABYLON.Vector3(rCoeffs[4], gCoeffs[4], bCoeffs[4]);
sh.l2_1 = new BABYLON.Vector3(rCoeffs[5], gCoeffs[5], bCoeffs[5]);
sh.l20 = new BABYLON.Vector3(rCoeffs[6], gCoeffs[6], bCoeffs[6]);
sh.l21 = new BABYLON.Vector3(rCoeffs[7], gCoeffs[7], bCoeffs[7]);
sh.l22 = new BABYLON.Vector3(rCoeffs[8], gCoeffs[8], bCoeffs[8]);
// Unity SH coefficients need to be scaled - they're not pre-scaled
// Let Babylon.js apply its own scaling during FromHarmonics conversion
sh.preScaled = false;
// Scale by IBL intensity if needed
if (iblIntensity !== 1.0) {
console.log("Scaling SH coefficients by IBL intensity:", iblIntensity);
sh.scaleInPlace(iblIntensity);
}
// Convert to spherical polynomial using Babylon's conversion
const sp = BABYLON.SphericalPolynomial.FromHarmonics(sh);
// Apply to the cube texture using public API
babylonScene.environmentTexture.sphericalPolynomial = sp;
// Force ALL materials to pick up the new environment diffuse IBL path
babylonScene.markAllMaterialsAsDirty(BABYLON.Material.AllDirtyFlag);
I get no ambient light at all, amd i creating it right ?







