Hi everyone,
I’ve been trying to set up realistic lighting and background in my Babylon.js scene using an HDR environment map, but I’ve run into some confusing issues. Here’s what I’ve tried and where I’m stuck:
Initially, I used PhotoDome with a panoramic HDR image—it was super easy to get a spherical background working.
Later, I read that scene.createDefaultEnvironment() is supposed to be a more complete, “all-in-one” solution that handles environment lighting, skybox, and image-based lighting (IBL) automatically. So I switched to that, hoping it would simplify everything.
To optimize performance, I converted my original equirectangular HDR file into a prefiltered .env file (using standard IBL tools). At this point, I started noticing that environment lighting (reflections), glass transmission, and the skybox background are actually three separate things—not just “lighting vs. skybox” as I originally thought:
-
Reflections appeared as soon as I created a
CubeTexture. -
Correct glass/refraction rendering only worked after I assigned the texture to
scene.environmentTexture. -
The skybox background needed to be set up separately.
Now, many sources claim that if you pass an environmentTexture to createDefaultEnvironment() and set createSkybox: true, it should automatically use the same texture for the skybox and keep everything aligned with the lighting.
But in practice, this doesn’t work with .env files. Even though the IBL (reflections and transmission) works perfectly, no skybox appears.
I tried explicitly passing the same .env file via the skyboxTexture option, using both:
-
CubeTexture.CreateFromPrefilteredData() -
new CubeTexture()
Result? The skybox does show up when I provide skyboxTexture, but it’s visibly misaligned—the cube seams are obvious, and it looks like a literal box rather than a seamless environment.
Interestingly, when I use scene.createDefaultSkybox() directly (without createDefaultEnvironment), it works flawlessly and creates a proper seamless skybox.
So my question is:
Is
createDefaultEnvironment()actually not suitable for creating a synchronized skybox + IBL setup when using.envfiles?
It’s supposed to be the “recommended integrated solution,” but it seems to have significant limitations in practice. Am I missing something? Or is it simply not designed to handle skybox rendering from .env files (which typically lack the base mip level needed for background display)?
Any guidance or best practices would be greatly appreciated!
Finally, here’s a link to my test code for reference: https://playground.babylonjs.com/?inspectorv2=true#BH23ZD#831
