# How do I convert Derivative Maps to Normal Maps?

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 and the original paper, 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.

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.
• 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? Commented Jun 4, 2022 at 0:35