<p><a href="https://i.sstatic.net/veFQr.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/veFQr.jpg" alt="enter image description here" /></a></p>
<p>I have been trying to apply normal maps to a rotating sphere with light shining directing from above the sphere (0,1,0). but lighting does not look correct under rotation as one side of the sphere appears darker and the top side of sphere does not seem lit as expected.</p>
<p>I have tried using a fake normal of (0,0,1) and multiplying that by my TBN matrix to ensure the T,B,N are correct and that all seems to work as expected so I have run of ideas of what the issue might be.</p>
<pre><code> if(has_normal_map){
        simd_float3 colour = flatMap.sample(textureSampler, in.tex).rgb;
        simd_float3 tangent = normalize(in.tangent - dot(in.tangent, in.normal) * in.normal);
        simd_float3 bitangent = normalize(cross(in.normal, tangent));
        simd_float3x3 TBN = simd_float3x3(normalize(tangent),bitangent,normalize(in.normal));
        float3 normal = (normalMap.sample(textureSampler, in.tex)).rgb;
        normal = (normal * 2.0 - 1.0);
        normal = normalize(normal);
        //normal = simd_float3(0,0,1);
        normal = normalize(TBN * normal);
        float attenuation = saturate(dot(light_vector,normal));
        return float4(attenuation*colour,1);
        
    }
</code></pre>

CC BY-SA 4.0
2023-03-25T21:56:19.997Z
The matrix multiplication order might be wrong, but I can't really tell if you create the TBN matrix column-wise or row-wise. Try normal*TBN
Mathis
CC BY-SA 4.0
2023-03-26T09:03:36.560Z
simd-float3x3 constructor makes the matrix column wise so that multiplication is okay
Sina Dasht
CC BY-SA 4.0
2023-03-26T10:18:23.623Z
Ok! Some other questions: are you sure that your tangent vector is calculated correctly? You are removing the contribution of the normal vector from in.tangent? Maybe try to calculate it naively as "normalize(cross(vec3(0,1,0),normal))", just to check. Are your normals in the [0-1] range or maybe stored as [-1,1]? Otherwise, sorry that I couldn't help and good luck!
Mathis
CC BY-SA 4.0
2023-03-29T12:15:28.713Z
Usually when computing the bitangent we pass in a sigma value indicating the handedness of the TBN coordinate frame. `bitangent = normalize(cross(norm,tang))*sigma` Where sigma is computed at the same time as the tangent and bitangent. And is always either +1 or -1. I don't see this being applied anywhere in the posted code sample.
pmw1234
<texture><transformations><lighting><normal-mapping><metal>
Normal Map Under rotation Issue
Sina Dasht
# Normal Map Under rotation Issue

(Asked by: username_0 on 2023-03-25)

[![enter image description here](https://i.sstatic.net/veFQr.jpg)](https://i.sstatic.net/veFQr.jpg)

I have been trying to apply normal maps to a rotating sphere with light shining directing from above the sphere (0,1,0). but lighting does not look correct under rotation as one side of the sphere appears darker and the top side of sphere does not seem lit as expected.

I have tried using a fake normal of (0,0,1) and multiplying that by my TBN matrix to ensure the T,B,N are correct and that all seems to work as expected so I have run of ideas of what the issue might be.

```
 if(has_normal_map){
        simd_float3 colour = flatMap.sample(textureSampler, in.tex).rgb;
        simd_float3 tangent = normalize(in.tangent - dot(in.tangent, in.normal) * in.normal);
        simd_float3 bitangent = normalize(cross(in.normal, tangent));
        simd_float3x3 TBN = simd_float3x3(normalize(tangent),bitangent,normalize(in.normal));
        float3 normal = (normalMap.sample(textureSampler, in.tex)).rgb;
        normal = (normal * 2.0 - 1.0);
        normal = normalize(normal);
        //normal = simd_float3(0,0,1);
        normal = normalize(TBN * normal);
        float attenuation = saturate(dot(light_vector,normal));
        return float4(attenuation*colour,1);
        
    }

```

**Tags:** texture, transformations, lighting, normal-mapping, metal

> **Comments:**
> **username_1**: The matrix multiplication order might be wrong, but I can't really tell if you create the TBN matrix column-wise or row-wise. Try normal*TBN  
> **username_0**: simd-float3x3 constructor makes the matrix column wise so that multiplication is okay  
> **username_1**: Ok! Some other questions: are you sure that your tangent vector is calculated correctly? You are removing the contribution of the normal vector from in.tangent? Maybe try to calculate it naively as "normalize(cross(vec3(0,1,0),normal))", just to check. Are your normals in the [0-1] range or maybe stored as [-1,1]? Otherwise, sorry that I couldn't help and good luck!  
> **username_2**: Usually when computing the bitangent we pass in a sigma value indicating the handedness of the TBN coordinate frame. `bitangent = normalize(cross(norm,tang))*sigma` Where sigma is computed at the same time as the tangent and bitangent. And is always either +1 or -1. I don't see this being applied anywhere in the posted code sample.  

---

## 0 answers

