<p>Suppose you have a function <span class="math-container">$f$</span> (think a height field) of <span class="math-container">$(x,y)$</span>. A derivative map contains point samples of <span class="math-container">$\left( {\partial f\over \partial x}, {\partial f\over \partial y}\right)$</span>, typically as a two-component texture.</p>
<p>What this means is that at a point <span class="math-container">$(x,y)$</span> the 3D vector <span class="math-container">$\left( 1, 0, {\partial f\over \partial x}\right)$</span> is parallel to the surface <span class="math-container">$z = f(x,y)$</span>. Likewise, the vector <span class="math-container">$\left(0,1, {\partial f\over \partial y}\right)$</span> is parallel to said surface.</p>
<p>Now, a vector orthogonal to the surface <span class="math-container">$z = f(x,y)$</span> can be computed as the cross product of these two vectors, which expands into</p>
<p><span class="math-container">$$\left(-{\partial f\over \partial x}, -{\partial f\over \partial y}, 1\right)$$</span>
Normalizing this vector (dividing by its length) will give you precisely the normal.</p>

CC BY-SA 4.0
2022-06-04T00:35:41.303Z
Here's the thing though, both these maps are encoded as colors, meaning the value of each component has to be in the [0,255] range, right? If the derivative map has a `df/dx` component and the normal map has a `-df/dx` component (even if normalized), doesn't one of them have to be negative? How do we encode negative values in the [0,255] range of a color?
Vinicius Vendramini
CC BY-SA 4.0
2022-06-04T00:43:08.187Z
Also, I get why the derivative map wouldn't need a blue component, but in the maps I'm seeing here (and in [this example](https://docs.knaldtech.com/doku.php?id=derivative_maps_knald)) the blue component is never zero. Am I maybe decoding the images incorrectly? Am I supposed to just ignore the blue component?
Vinicius Vendramini
CC BY-SA 4.0
2022-06-04T02:17:03.110Z
Never mind, I think got it working. For future reference: the mapping from colors to vectors is linear, with a 255 being a 1, a 127 being a 0, and a 0 being a -1. As for the blue component, it turns out AppKit's NSImage decodes the image correctly (with all blues as 0), even though in the monitor it displays blue tones in the colors - that's what confused me. Thanks for the help @lisyarus!
Vinicius Vendramini
CC BY-SA 4.0
2022-05-22T19:31:21.103Z
2022-05-22T19:31:21.103Z
lisyarus
<p>I recently came across a set of models that include Derivative Maps. I'd like to use them in Blender, but from what I've seen so far Blender only supports exporting baked Derivative Maps, not importing them. Therefore I'm trying to convert these Derivative Maps into tangent space Normal Maps for use in Blender.</p>
<p>So far all the programs that I've seen (like xNormal etc) also only support exporting Derivative Maps (not importing them) so they haven't worked for me, but if anyone knows a program that can be used for this conversion that would be great.</p>
<p>As for developing a converter myself, I've done some research on Derivative Maps to try to understand the logic behind them, including reading <a href="https://computergraphics.stackexchange.com/questions/4937/derivative-maps-vs-tangent-space-normal-maps">these links</a> and the <a href="https://www.dropbox.com/s/l1yl164jb3rhomq/mm_sfgrad_bump.pdf?dl=0" rel="nofollow noreferrer">original paper</a>, but it's been a while since I've seen math in this level and I'm just not understanding it well enough to develop an algorithm that works.</p>
<p>Can anyone help be understand how I can turn a Derivative Map's pixels into a Normal Map's pixels? A simple explanation of the necessary equations, or even some pseudocode algorithm, would be a lot of help.</p>

<texture><normal-mapping>
How do I convert Derivative Maps to Normal Maps?
Vinicius Vendramini
# How do I convert Derivative Maps to Normal Maps?

(Asked by: username_0 on 2022-05-21)

I recently came across a set of models that include Derivative Maps. I'd like to use them in Blender, but from what I've seen so far Blender only supports exporting baked Derivative Maps, not importing them. Therefore I'm trying to convert these Derivative Maps into tangent space Normal Maps for use in Blender.

So far all the programs that I've seen (like xNormal etc) also only support exporting Derivative Maps (not importing them) so they haven't worked for me, but if anyone knows a program that can be used for this conversion that would be great.

As for developing a converter myself, I've done some research on Derivative Maps to try to understand the logic behind them, including reading [these links](https://computergraphics.stackexchange.com/questions/4937/derivative-maps-vs-tangent-space-normal-maps) and the [original paper](https://www.dropbox.com/s/l1yl164jb3rhomq/mm_sfgrad_bump.pdf?dl=0), but it's been a while since I've seen math in this level and I'm just not understanding it well enough to develop an algorithm that works.

Can anyone help be understand how I can turn a Derivative Map's pixels into a Normal Map's pixels? A simple explanation of the necessary equations, or even some pseudocode algorithm, would be a lot of help.

**Tags:** texture, normal-mapping


---

## 1 answers

### Answer by username_1 on 2022-05-22. Score: 0 | Accepted answer

Suppose you have a function $f$ (think a height field) of $(x,y)$. A derivative map contains point samples of $\left( {\partial f\over \partial x}, {\partial f\over \partial y}\right)$, typically as a two-component texture.

What this means is that at a point $(x,y)$ the 3D vector $\left( 1, 0, {\partial f\over \partial x}\right)$ is parallel to the surface $z = f(x,y)$. Likewise, the vector $\left(0,1, {\partial f\over \partial y}\right)$ is parallel to said surface.

Now, a vector orthogonal to the surface $z = f(x,y)$ can be computed as the cross product of these two vectors, which expands into

$$\left(-{\partial f\over \partial x}, -{\partial f\over \partial y}, 1\right)$$
Normalizing this vector (dividing by its length) will give you precisely the normal.

> **Comments:**
> **username_0**: Here's the thing though, both these maps are encoded as colors, meaning the value of each component has to be in the [0,255] range, right? If the derivative map has a `df/dx` component and the normal map has a `-df/dx` component (even if normalized), doesn't one of them have to be negative? How do we encode negative values in the [0,255] range of a color?  
> **username_0**: Also, I get why the derivative map wouldn't need a blue component, but in the maps I'm seeing here (and in [this example](https://docs.knaldtech.com/doku.php?id=derivative_maps_knald)) the blue component is never zero. Am I maybe decoding the images incorrectly? Am I supposed to just ignore the blue component?  
> **username_0**: Never mind, I think got it working. For future reference: the mapping from colors to vectors is linear, with a 255 being a 1, a 127 being a 0, and a 0 being a -1. As for the blue component, it turns out AppKit's NSImage decodes the image correctly (with all blues as 0), even though in the monitor it displays blue tones in the colors - that's what confused me. Thanks for the help @username_1!  

---

