<p>Huge thanks to @MJP who answered this.<br>
The aim is to avoid the simplification made when using tangent space normals.
Here is the paper : <a href="http://blog.selfshadow.com/publications/blending-in-detail/" rel="nofollow">Blending in detail</a></p>

<p>But only implement equation (<a href="http://blog.selfshadow.com/publications/blending-in-detail/#mjx-eqn-eqrotation" rel="nofollow">4</a>) which gives you this.</p>

<pre><code>float3 ReorientNormal(in float3 u, in float3 t, in float3 s)
{
    // Build the shortest-arc quaternion
    float4 q = float4(cross(s, t), dot(s, t) + 1) / sqrt(2 * (dot(s, t) + 1));
    // Rotate the normal
    return u * (q.w * q.w - dot(q.xyz, q.xyz)) + 2 * q.xyz * dot(q.xyz, u) + 2 * q.w * cross(q.xyz, u);
}
</code></pre>

<p>Original answer is <a href="http://www.gamedev.net/topic/678043-how-to-blend-world-space-normals/?view=findpost&amp;p=5287707" rel="nofollow">here</a>.</p>

CC BY-SA 3.0
2016-04-21T18:09:25.737Z
2016-04-21T18:09:25.737Z
MaT
<p>I am trying to blend two world space normals inside a shader. One comes from a tangent space normal map converted into world space using a classic TBN matrix and the other one is a mesh normal map in world space.</p>

<p>I found some interesting resources here :</p>

<ul>
<li><a href="http://blog.selfshadow.com/publications/blending-in-detail/" rel="nofollow noreferrer">Blending in Detail</a></li>
<li><a href="https://www.shadertoy.com/view/4t2SzR#" rel="nofollow noreferrer">Shadertoy - Normal Map Blending</a></li>
</ul>

<p>But those blending technics seem to be only available for tangent space normals, especially the Reoriented Normal Mapping (RNM).
I tried to apply the RNM technic with unpack already done.</p>

<pre><code>n1 += vec3(0, 0, 1);
n2 *= vec3(-1, -1, 1);

return n1 * dot(n1, n2) / n1.z - n2;
</code></pre>

<p>But this doesn't give expected results and I don't get why. Is there a way to apply the RNM blending on world space normals ?</p>

<p>Thanks a lot.</p>

<p><strong>Edit:</strong> Here are some output and the result I am having with RNM. The A normal is not disturbed by the B normal, it gives some strange massively reoriented results.</p>

<pre><code>float3 nv = dot(normal, viewDir);
color.rgb = nv;
</code></pre>

<p><a href="https://i.sstatic.net/iFPZp.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/iFPZp.jpg" alt=""></a></p>

CC BY-SA 3.0
2016-04-19T14:17:41.263Z
Do you have any physical interpretation for the two normal maps? e.g. one is high-frequency and one is low-frequency and applied "on top of it" (which is the Reoriented Normal Mapping case)?

I would expect that you would need to feed the mesh's normal/tangent/bitangent into the equation somehow. You might consider simply transforming the world space normal into tangent space, applying RNM, then transforming the result to world space—that's only one extra 3x3 mul.
John Calsbeek
CC BY-SA 3.0
2016-04-19T19:24:20.670Z
Thanks for your answer @JohnCalsbeek but using baked tangent space normal doesn't provide good enough results that's why I am using a world space normal, especially a world space bent normal map, and I try to apply on top of if the regular normal map.
MaT
CC BY-SA 3.0
2016-04-19T20:01:02.903Z
I've added some screenshot to illustrate the issue I am having.
MaT
<opengl><rendering><shader><texture><normal-mapping>
How to blend World Space Normals
MaT
# How to blend World Space Normals

(Asked by: username_0 on 2016-04-19)

I am trying to blend two world space normals inside a shader. One comes from a tangent space normal map converted into world space using a classic TBN matrix and the other one is a mesh normal map in world space.

I found some interesting resources here :

* [Blending in Detail](http://blog.selfshadow.com/publications/blending-in-detail/)
* [Shadertoy - Normal Map Blending](https://www.shadertoy.com/view/4t2SzR#)

But those blending technics seem to be only available for tangent space normals, especially the Reoriented Normal Mapping (RNM).
I tried to apply the RNM technic with unpack already done.

```
n1 += vec3(0, 0, 1);
n2 *= vec3(-1, -1, 1);

return n1 * dot(n1, n2) / n1.z - n2;

```

But this doesn't give expected results and I don't get why. Is there a way to apply the RNM blending on world space normals ?

Thanks a lot.

**Edit:** Here are some output and the result I am having with RNM. The A normal is not disturbed by the B normal, it gives some strange massively reoriented results.

```
float3 nv = dot(normal, viewDir);
color.rgb = nv;

```

[![](https://i.sstatic.net/iFPZp.jpg)](https://i.sstatic.net/iFPZp.jpg)

**Tags:** opengl, rendering, shader, texture, normal-mapping

> **Comments:**
> **username_1**: Do you have any physical interpretation for the two normal maps? e.g. one is high-frequency and one is low-frequency and applied "on top of it" (which is the Reoriented Normal Mapping case)?  I would expect that you would need to feed the mesh's normal/tangent/bitangent into the equation somehow. You might consider simply transforming the world space normal into tangent space, applying RNM, then transforming the result to world space—that's only one extra 3x3 mul.  
> **username_0**: Thanks for your answer @username_1 but using baked tangent space normal doesn't provide good enough results that's why I am using a world space normal, especially a world space bent normal map, and I try to apply on top of if the regular normal map.  
> **username_0**: I've added some screenshot to illustrate the issue I am having.  

---

## 1 answers

### Answer by username_0 on 2016-04-21. Score: 2 | Accepted answer

Huge thanks to @MJP who answered this.  
The aim is to avoid the simplification made when using tangent space normals.
Here is the paper : [Blending in detail](http://blog.selfshadow.com/publications/blending-in-detail/)

But only implement equation ([4](http://blog.selfshadow.com/publications/blending-in-detail/#mjx-eqn-eqrotation)) which gives you this.

```
float3 ReorientNormal(in float3 u, in float3 t, in float3 s)
{
    // Build the shortest-arc quaternion
    float4 q = float4(cross(s, t), dot(s, t) + 1) / sqrt(2 * (dot(s, t) + 1));
    // Rotate the normal
    return u * (q.w * q.w - dot(q.xyz, q.xyz)) + 2 * q.xyz * dot(q.xyz, u) + 2 * q.w * cross(q.xyz, u);
}

```

Original answer is [here](http://www.gamedev.net/topic/678043-how-to-blend-world-space-normals/?view=findpost&p=5287707).


---

