   Calculating the B channel for a normal map...
  I posted on this a while back in my other thread, but I haven't gotten a response. I recently started back up on the project, and this is the last thing I need to to to finish the tool...I have two values from 0 to 255 as the R and G channels, and I need to calculate the third one. Here is what I'm doing, but it isn't working right...double tempd;double tempr = (((double)Color1R / 255) * 2.0) - 1.0;double tempg = (((double)Color1G / 255) * 2.0) - 1.0;tempd = System.Math.Sqrt(1 - (tempr * tempr) + (tempg * tempg));Color1B = (int)(((tempd + 1) / 2) * 255);It works fine when R and G are 127 and 128, returning a B value of 255. But when the next values, 95 and 52, it returns a B value of 272.I'm not really sure how to go about this. Thanks for any help!   
  Is that plus inside the square root a copy and paste error?  Because it should be a minus:tempd = System.Math.Sqrt(1 - (tempr * tempr) - (tempg * tempg));Other than that I don't see anything wrong with your code.  I'd also like to point out that since B is never negative, you might want to get some precision back by ignoring negative values and doing:Color1B = (int)(tempd * 255);   ;  Well, That fixed one thing... This is what happens when you are up at three in the morning writing code!Here is my revised code:double tempd;double tempr = (((double)Color1R / 255) * 2) -1;double tempg = (((double)Color1G / 255) * 2) -1;tempd = System.Math.Sqrt(1 - ((tempr * tempr) - (tempg * tempg)));Color1B = (int)(tempd * 255);But now when it gets a set of values like 137 and 38, it will return for blue a value of 310... Am I still missing something? Does anyone have working code that I could see?[Edited by - Tanasoo on September 16, 2007 11:41:15 PM]