- Home /
Standard assets Skybox and cubemap are mirrored along X towards each other?
Hi,
I have a problem when using a skybox and an envmap created from the same images. When I try to use the envmap to create reflections of the skybox, the reflections are wrong, they are mirrored along the X-axis, as you can see in the following image:

I'm using Unity 4.5.4. The scene has a skybox created using the standard assets skybox Sunny 2 (with an extra sun drawn into it by myself) There's a single plane in the X-Z plane (so Y is still up), with the following (much simplified for this testcase) shader on it:
Shader "My Water"
{
Properties
{
_EnvMap ("EnvMap", CUBE) = "envmap" {}
}
SubShader
{
Cull off
Tags { "Queue" = "Opaque" }
CGPROGRAM
#pragma surface surf BlinnPhong
#pragma target 3.0
struct Input
{
float3 worldRefl;
INTERNAL_DATA
};
samplerCUBE _EnvMap;
void surf (Input IN, inout SurfaceOutput o)
{
o.Albedo = float4( 0.0, 0.0, 0.0, 0.0 );
o.Emission = texCUBE (_EnvMap, WorldReflectionVector (IN, o.Normal)).rgb;
}
ENDCG
}
Fallback "Diffuse"
}
The envmap is created from the same textures as the skybox. One thing that's weird is that when you compare the properties of the skybox with the ones from the cubemap, you can see that their definitions of left and right are different. The skybox defines left as -X, and the cubemap defines left as +X, so that's probably the reason for the mismatch right there.
The question then becomes how to fix this? I'd rather not store two different sets of textures for the same thing (physically mirrored along X), so maybe I can fix it in the shader, by fiddling with the reflection normal? I tried some of that, but I don't know which space we're in by the time Unity calls the surface shader (model space, world space, camera space?) and could not get that to work.
Thanks Nils Desle
Answer by Nils-Desle · Feb 12, 2015 at 12:09 PM
Unfortunately, no-one knew the answer to this one. Fortunately, I figured it out on my own! :) I'll post the solution here for future seekers...
The part where Emission is calculated should be:
float3 reflected_normal = WorldReflectionVector (IN, o.Normal);
reflected_normal = float3( -reflected_normal.x, reflected_normal.y, reflected_normal.z );
o.Emission = texCUBE (_EnvMap, reflected_normal ).rgb;
So basically you flip the reflected normal along its X axis.
Your answer