# Invert CubeTextures

**URL:** <https://forum.babylonjs.com/t/invert-cubetextures/1611>\
**Category:** Questions\
**Created:** [February 26, 2019, 4:15am UTC](https://forum.babylonjs.com/t/invert-cubetextures/1611 "2019-02-26T04:15:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![MackeyK24](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mackeyk24/32/3741_2.png) [@MackeyK24](https://forum.babylonjs.com/u/MackeyK24)\
**Post date:** [February 26, 2019, 4:15am UTC](https://forum.babylonjs.com/t/invert-cubetextures/1611/1 "2019-02-26T04:15:30Z")

</div>

Yo @Deltakosh and @trevordev … I got a situation where i need to FLIP HORIZONTAL the CubeTextures used for 6 Sided Skyboxes as well as Pre Filtered Environments.

I am using GLTF as a scene file. that means it has a **root** node with a negative Z scale.

Well the negative Z scaling messes up physics simulations. If i where to drop a cylinder shape on to a slightly rotated forward cube shape. The cylinder would contact the cube and fall forward to the ground as expected. But with negative z scaling, the cylinder would fall behind the cube even though the cube is rotated forward.

@trevordev pointed out this negative z scale is messing with physics and i should FORCE the scene into right handed mode using scene.useRighHandedSystem = true BEFORE loading the scene. That worked… now physics object fall the right way.

But this now FLIPPED all my cubemap textures in the scene. Both the skybox and the environment. Is there some kind of property of function that can used to flip the textures horizontally. If o manually use my Mac using Preview to open the textures in the scene file and do Tools-\>Flip Horizontal that fixes the issues… So i know is a horizontal flip issue with the CubeTexture and the scene being forced into right hand mode.

Here is the original Unity shot. Not the horizontal rotation of the clouds in the sky and the little brown bush reflected in the sphere:

 ![26%20PM](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/1X/9400e3faab8606515c47457373b24d36e921770d.jpeg)

IF I DO NOT FORCE RIGHT HANDED:

 ![41%20PM](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/1X/391b0ea410edecf6517ceba5ddaab8c56c9499ea.jpeg)

AND FINALLY WHEN I FORCE RIGHT HANDED:

 ![16%20PM](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/1X/8978a1e8032a2bb774d87b358590d4361527e175.jpeg)

As you can see the force right handed cube textures are flipped horizontally. The Rotation-Y is fine. Its at 3.14 so the skybox and reflection show the proper orientation on the world… Again they are just flipped horizontally.

UPDATE: Also note the shadow have HOLES in them.

Can you please show me how to fix this 🙂

---

<div class="post-metadata">

**Author:** ![Gijs](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/gijs/32/44_2.png) [@Gijs](https://forum.babylonjs.com/u/Gijs)\
**Post date:** [February 26, 2019, 5:09pm UTC](https://forum.babylonjs.com/t/invert-cubetextures/1611/2 "2019-02-26T17:09:43Z")

</div>

I don’t know about the shadows, but this seems to work for inverting:

The skybox (skybox.scaling.x = -1;)  
[https://www.babylonjs-playground.com/#UU7RQ#296](https://www.babylonjs-playground.com/#UU7RQ#296)

The prefiltered (hdrTexture.invertZ = true;):

[https://playground.babylonjs.com/#CGA05F#44](https://playground.babylonjs.com/#CGA05F#44)

---

<div class="post-metadata">

**Author:** ![trevordev](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/trevordev/32/16_2.png) [@trevordev](https://forum.babylonjs.com/u/trevordev)\
**Post date:** [February 26, 2019, 5:54pm UTC](https://forum.babylonjs.com/t/invert-cubetextures/1611/3 "2019-02-26T17:54:58Z")

</div>

@MackeyK24 can you repro the shadow issue on the playground. I am not seeing it [https://www.babylonjs-playground.com/#IFYDRS#32](https://www.babylonjs-playground.com/#IFYDRS#32) .

How are you loading the skybox/textures? Some may be bugs in babylon as some the loaders should look at the handedness of the scene but there is also a chance you should do it manually how Gijs mentioned. If you could create a playground that repros each issue it would be easier to determine which is solution is ideal.

---

<div class="post-metadata">

**Author:** ![MackeyK24](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mackeyk24/32/3741_2.png) [@MackeyK24](https://forum.babylonjs.com/u/MackeyK24)\
**Post date:** [February 26, 2019, 8:59pm UTC](https://forum.babylonjs.com/t/invert-cubetextures/1611/4 "2019-02-26T20:59:36Z")

</div>

Yo @Gijs … The skybox.scaling.x \*= -1 worked perfect… But the ddsTexture.invertZ DID NOT flip the image reflected.

FYI… Here is how i create environments:

```auto
                // Setup Default Scene Environment
                if (skybox.hasOwnProperty("environment") && skybox.environment != null) {
                    const environment:any = skybox.environment;
                    if (environment != null) {
                        const envname:string = (environment.hasOwnProperty("name") && environment.name != null && environment.name !== "") ? environment.name : "SkyboxEnvironment";
                        const envtype:string = (environment.hasOwnProperty("type") && environment.type != null && environment.type !== "") ? environment.type : null;
                        const envpath:string = (environment.hasOwnProperty("url") && environment.url != null && environment.url !== "") ? (skyurl + environment.url) : null;
                        if (envtype != null && envtype !== "") {
                            try {
                                if (envtype === "image/dds") {
                                    var ddsTexture = BABYLON.CubeTexture.CreateFromPrefilteredData(envpath, this._loader.babylonScene);
                                    ddsTexture.name = envname;
                                    ddsTexture.gammaSpace = false;
                                    if (BABYLON.SceneManager.HandSystem <= 0) { 
                                        ddsTexture.rotationY = Math.PI;
                                        ddsTexture.invertZ = true;
                                    }
                                    this._loader.babylonScene.environmentTexture = ddsTexture;
                                } else if (envtype === "image/env") {
                                    var envTexture = new BABYLON.CubeTexture(envpath, this._loader.babylonScene);
                                    envTexture.name = envname;
                                    envTexture.gammaSpace = false;
                                    if (BABYLON.SceneManager.HandSystem <= 0) { 
                                        envTexture.rotationY = Math.PI;
                                        envTexture.invertZ = true;
                                    }
                                    this._loader.babylonScene.environmentTexture = envTexture;
                                } else {
                                    BABYLON.Tools.Warn("Unsupported environment texture type: " + envtype);
                                }
                                // Support Spherical Polynomial Scaling
                                if (this._loader.babylonScene.environmentTexture != null && polynomial !== 1.0) {
                                    const scene:BABYLON.Scene = this._loader.babylonScene;
                                    if (scene.isReady()) scene.environmentTexture.sphericalPolynomial.scale(polynomial);
                                    else scene.onReadyObservable.addOnce(() => { scene.environmentTexture.sphericalPolynomial.scale(polynomial); });
                                }    
                            } catch (e2) {
                                console.warn(e2);
                            }
                        }
                    }
                }

```

---

<div class="post-metadata">

**Author:** ![MackeyK24](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mackeyk24/32/3741_2.png) [@MackeyK24](https://forum.babylonjs.com/u/MackeyK24)\
**Post date:** [February 26, 2019, 10:19pm UTC](https://forum.babylonjs.com/t/invert-cubetextures/1611/5 "2019-02-26T22:19:05Z")

</div>

Yo @Gijs … It look like the invertZ DOES flip from left to right … But only shows correctly when useRightHandSystem = false.

Example Shot… Notice the PROJECTION of the background in sphere… its strait and clear and the bushes are on the RIGHT:

 ![36%20PM](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/1X/1be0ad12985d297bb4a21aefbbbfbe8ce7758d9b.jpeg)

Now this is the original unity shot … which looks good of course:

 ![01%20PM](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/1X/3980a23e7d243849b985607dfdff37bf56f283fb.jpeg)

But when i set scene.useRightHandSystem = true; /// Which i need for GLTF physics to work right… I also do a ddsTexture.invertZ = true… Which does flip it… But the PROJECTION of the reflected backgound looks all funky… Like the cubemab BOX and POS are out of wack:

 ![05%20PM](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/1X/a90935b8d7e477403652ee50ce9b779d8a7710a2.jpeg)

Yo @Deltakosh or @sebavan or @trevordev … If you see anything… Let me know 🙂

---

<div class="post-metadata">

**Author:** ![trevordev](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/trevordev/32/16_2.png) [@trevordev](https://forum.babylonjs.com/u/trevordev)\
**Post date:** [February 26, 2019, 11:00pm UTC](https://forum.babylonjs.com/t/invert-cubetextures/1611/6 "2019-02-26T23:00:32Z")

</div>

Are you able to repro this? I tried here [https://playground.babylonjs.com/#8MGKWK#127](https://playground.babylonjs.com/#8MGKWK#127) but no luck.

---

<div class="post-metadata">

**Author:** ![MackeyK24](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mackeyk24/32/3741_2.png) [@MackeyK24](https://forum.babylonjs.com/u/MackeyK24)\
**Post date:** [February 27, 2019, 2:08am UTC](https://forum.babylonjs.com/t/invert-cubetextures/1611/7 "2019-02-27T02:08:50Z")

</div>

I will try to repo on playground… gonna take a sec … its a toolkit project

---

<div class="post-metadata">

**Author:** ![Jez](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jez/32/2219_2.png) [@Jez](https://forum.babylonjs.com/u/Jez)\
**Post date:** [July 2, 2019, 10:12am UTC](https://forum.babylonjs.com/t/invert-cubetextures/1611/8 "2019-07-02T10:12:13Z")

</div>

Hey hello did you find a solution finally? I have the same problem on a cubetexture projected into a mesh.
