Accounting for scaled geometry in normals?

Hey all –

Say I had a pyramid. Normally, the sides that made their way to the top would have normals facing diagonally outward & up. However, if I scaled the pyramid so it was nearly flat in one direction, those side normals should now point parallel to the ground (e.g. not up). How do I account for this in shaders? Is this already suppose to be accounted for in the uniform, WorldMatrixInverseTranspose?

Basically, this is the problem I am getting:

These tall walls are being scaled large & flattened… the normals look as expected in Blender. I calculate the normals like this in the shader:

vNormal = normalize(g_WorldMatrixInverseTranspose * inNormal);  

… and I have some brightness calculation on it:

    // set color
    gl_FragColor.rgb = texcolor.rgb * m_Color.rgb;
    // add in light for sun direction
    gl_FragColor.rgb *= 1.0 + (vNormal.z * m_LightDir.z * 0.7 + min(0.0, vNormal.y) * m_LightDir.y * 0.7);
    // add some variation based on normal
    gl_FragColor.rgb *= 0.9 + vNormal.x * 0.4;

… so why does the brightness look so different in the end result? :frowning:

As a fix for this specific instance, I pre-scale the objects in Blender, so they don’t need to be scaled within the application. This solves the normals rendering funny. However, I have other objects that do need to be dynamically scaled, and I would like normals to adjust correctly (somehow).

This is always what I’ve used the normal transform for… forget the name but g_NormalViewMatrix maybe. Not sure if it’s different than the inverse transpose or not and don’t have time to look… but I thought I’d drop a hint in case it helps.

Thanks for the tip… there is NormalMatrixInverse and NormalMatrix. When multiplied with inNormal, the result is dependent on where the camera is looking (e.g. the “view”). I don’t want the object’s normals to change when the camera looks around (e.g. I want the normals to be in world space, not view space). g_WorldMatrixInverseTranspose is the only one that does this, as far as I know, with the results above.