Fix MAX world normals in .fx shader?

I’m wondering how to ‘turn’ Max’s world normals from Z up to Y up. I’m mapping a cube map to the world normals (for diffuse lighting) and it’s pointing up the Y axis in MAX rather than up the Z axis. I’m sure there’s a simple transform for it, but I can’t figure it out.

Swizzle your reflection vector before doing the cubemap lookup to swap that Y and Z axis. I think you might also have to negate the Y axis once you’ve done the swizzle.

I added a cubemap to a shader the other day, I still don’t know if I really got a great result, but I didnt need anything “perfect” as it was placeholder for realtime reflections in the engine.

I don’t have the shader code to post, but it was pretty much like Ben says I think.

I did have a problem where my normal map looked too strong, so I ended up multiplying it with something like 0.02.

Anyway I would be interested to see other examples as I gave up with mine :slight_smile:

ShaderFX does this conversion for you, so set up a reflection map there and then look at the code that it generates for use inside Max.

I’ve been working on a ridiculous shader that has a ton of world space cube maps (diffuse, normal, reflection, specular, refraction, etc.). Here’s the diffuse lookup:

float3 calculateWorldSpaceCubeMap (float3 normal, float3 difColor, float lightMask, float3 lightColor)
{
float4 WSCube = texCUBE(g_WSCubeMapSampler, normal);
#ifdef 3DSMAX
WSCube = texCUBE(g_WSCubeMapSampler, normal.xzy);
#endif
return (difColor * (1 - WSCube.a) + (WSCube * WSCube.a) * lightMask * lightColor);
}

Cube map alpha blends cube map into diffuse, it does not affect diffuse alpha.
“normal” is world space normal.
“difColor” is diffuse.rgb.
“lightMask” is diffuse lighting mask (lambert or whatever).