### PBS Math question

Posted:

**Tue Dec 01, 2015 5:07 pm**I was reviewing the PBS implementation and I stumbled upon this line in the getTSNormal function:
Shouldn't this be:
(Note the plus sign in the equation).

And in this case the max isn't necessary there, reducing it to:
Or:
Is it possible that this is an error due to the following:

Z² + X² + Y² = 1

Z² = 1 - X² - Y²

Z = sqrt(1 - X² - Y²)

Z = sqrt(1 - (X² + Y²))

Note that if you fail to switch the signal the equation gets invalidated, this isn't the same as:

Z = sqrt(1 - (X² - Y²))

And this last line doesn't equate to this: Z² + X² + Y² = 1, meaning that the vector isn't normalized anymore, instead, it seems the normal vectors from the normalmaps could be having lengths equal to (1 - 2Y²), and not 1.

I couldn't find a reason why the first version is there, for me it makes more sense doing the latter, am I missing something here?

Code: Select all

```
tsNormal.z = sqrt( 1.0 - max( 0, tsNormal.x * tsNormal.x - tsNormal.y * tsNormal.y ) );
```

Code: Select all

```
tsNormal.z = sqrt( 1.0 - max( 0, tsNormal.x * tsNormal.x + tsNormal.y * tsNormal.y ) );
```

And in this case the max isn't necessary there, reducing it to:

Code: Select all

```
tsNormal.z = sqrt( 1.0 - ( tsNormal.x * tsNormal.x + tsNormal.y * tsNormal.y ) );
```

Code: Select all

```
tsNormal.z = sqrt( 1.0 - tsNormal.x * tsNormal.x - tsNormal.y * tsNormal.y );
```

Z² + X² + Y² = 1

Z² = 1 - X² - Y²

Z = sqrt(1 - X² - Y²)

Z = sqrt(1 - (X² + Y²))

Note that if you fail to switch the signal the equation gets invalidated, this isn't the same as:

Z = sqrt(1 - (X² - Y²))

And this last line doesn't equate to this: Z² + X² + Y² = 1, meaning that the vector isn't normalized anymore, instead, it seems the normal vectors from the normalmaps could be having lengths equal to (1 - 2Y²), and not 1.

I couldn't find a reason why the first version is there, for me it makes more sense doing the latter, am I missing something here?