<p>Normals are represented as <a href="https://en.wikipedia.org/wiki/Unit_vector" rel="nofollow noreferrer"><strong>unit vectors</strong></a>; that is, considered as coordinates of a point they land somewhere on a sphere with radius 1. Therefore, the coordinates satisfy the equation</p>
<p><span class="math-container">$$
x^2 + y^2 + z^2 = 1
$$</span></p>
<p>Since you want <span class="math-container">$z$</span> and don’t have it, solve that equation for <span class="math-container">$z$</span>:</p>
<p><span class="math-container">$$
z = \sqrt{1 - x^2 - y^2}
$$</span></p>
<p>This formula is undefined if <span class="math-container">$x^2 + y^2$</span> is greater than one, which it may sometimes be, due to either rounding error or mistakes in authoring the normal map. In that case, you should simply substitute zero.</p>
<p><span class="math-container">$$
z = \sqrt{\max\left(0, 1 - x^2 - y^2\right)}
$$</span></p>
<p>Here’s what this function looks like (viewed from the side in two dimensions):</p>
<p><a href="https://i.sstatic.net/byIV64Ur.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/byIV64Ur.png" alt="Graph of the above function" /></a></p>
<p>It’s not an accident that it looks like a half-circle (or a cross section through a 3D hemisphere); that is exactly what we’re computing.</p>
<p>In typical programming syntax, the above function is:</p>
<pre><code>z = sqrt(max(0.0, 1.0 - x * x - y * y))
</code></pre>
<p>Note that the raw data in your normal map pixels will likely have a range like 0 to 255 rather than −1 to 1. If you are starting with that data, you will need to <a href="https://computergraphics.stackexchange.com/questions/10387/how-to-draw-surface-normals-from-surface-normal-maps">rescale it first</a>, and also rescale the computed Z to match if you’re planning to write the Z back into an image file.</p>

CC BY-SA 4.0
2024-12-04T20:05:41.663Z
I'm not good at maths, but thank you so much. I do appreciate a good technical response.

Ultimately, I'm trying to "flatten/level out", as much as possible, a bit of geometry (grooves and a small hexagonal hole) in a model (a model which is unmodifiable to me) with clever normals (I heard you can take the "difference" between the actual geometry's normal, and the desired geometry's normal, then invert that, to achieve this effect).

If you could guide me in the right direction regarding this more defined problem, that would be awesome. Any theory or math behind it is of course welcome!
experimenting_with_graphics
CC BY-SA 4.0
2024-12-05T05:57:34.600Z
@experimenting_with_graphics Sorry, I have no information to share on that. It's a very different problem than merely recovering the redundant Z coordinate in a normal map. You should post a separate question with more details.
Kevin Reid
CC BY-SA 4.0
2024-12-04T16:15:17.030Z
2024-12-04T16:15:17.030Z
Kevin Reid
<p>How does one do this?</p>
<p>Is it manipulating the RGB channels in each normal map in some manner, then combining them somehow? I'm finding it really hard to research this on my own, especially given my limited knowledge in the field in general (I'm fairly new).</p>
<p>For what it's worth: I've baked some normal maps before, and modified normal maps manually on a pixel-by-pixel basis at a basic level, but nothing too advanced beyond that.</p>

<normal-mapping>
Take normal map X, and normal map Y, and calculate the "difference" between them, resulting in normal map Z; how to figure out normal map Z?
experimenting_with_graphics
# Take normal map X, and normal map Y, and calculate the "difference" between them, resulting in normal map Z; how to figure out normal map Z?

(Asked by: username_0 on 2024-12-03)

How does one do this?

Is it manipulating the RGB channels in each normal map in some manner, then combining them somehow? I'm finding it really hard to research this on my own, especially given my limited knowledge in the field in general (I'm fairly new).

For what it's worth: I've baked some normal maps before, and modified normal maps manually on a pixel-by-pixel basis at a basic level, but nothing too advanced beyond that.

**Tags:** normal-mapping


---

## 1 answers

### Answer by username_1 on 2024-12-04. Score: 0

Normals are represented as [**unit vectors**](https://en.wikipedia.org/wiki/Unit_vector); that is, considered as coordinates of a point they land somewhere on a sphere with radius 1. Therefore, the coordinates satisfy the equation

$$
x^2 + y^2 + z^2 = 1
$$

Since you want $z$ and don’t have it, solve that equation for $z$:

$$
z = \sqrt{1 - x^2 - y^2}
$$

This formula is undefined if $x^2 + y^2$ is greater than one, which it may sometimes be, due to either rounding error or mistakes in authoring the normal map. In that case, you should simply substitute zero.

$$
z = \sqrt{\max\left(0, 1 - x^2 - y^2\right)}
$$

Here’s what this function looks like (viewed from the side in two dimensions):

[![Graph of the above function](https://i.sstatic.net/byIV64Ur.png)](https://i.sstatic.net/byIV64Ur.png)

It’s not an accident that it looks like a half-circle (or a cross section through a 3D hemisphere); that is exactly what we’re computing.

In typical programming syntax, the above function is:

```
z = sqrt(max(0.0, 1.0 - x * x - y * y))

```

Note that the raw data in your normal map pixels will likely have a range like 0 to 255 rather than −1 to 1. If you are starting with that data, you will need to [rescale it first](https://computergraphics.stackexchange.com/questions/10387/how-to-draw-surface-normals-from-surface-normal-maps), and also rescale the computed Z to match if you’re planning to write the Z back into an image file.

> **Comments:**
> **username_0**: I'm not good at maths, but thank you so much. I do appreciate a good technical response.  Ultimately, I'm trying to "flatten/level out", as much as possible, a bit of geometry (grooves and a small hexagonal hole) in a model (a model which is unmodifiable to me) with clever normals (I heard you can take the "difference" between the actual geometry's normal, and the desired geometry's normal, then invert that, to achieve this effect).  If you could guide me in the right direction regarding this more defined problem, that would be awesome. Any theory or math behind it is of course welcome!  
> **username_1**: @username_0 Sorry, I have no information to share on that. It's a very different problem than merely recovering the redundant Z coordinate in a normal map. You should post a separate question with more details.  

---

