I'm working on texture normal maps. I tried to compute the blue channel out of the red and green channel.
Got the Term from this website.
discourse.techart.online/t/how-to-calculate-the-blue-channel-for-normal-map/4436/7
This original Term works on GPU shader programs. Could be possible that GPU shader doesn't report sqrt errors and simply ignore them.
_____________________________________________________
JM Melanson worked so far with a small change.
b = Sqrt(1 - (((x * 2) - 1) ^ 2 + ((y * 2) - 1) ^ 2) / 2) + 1 (instead of 0.5)
_____________________________________________________
Webus worked only with
Try b = Sqrt(1 - ((2 * x - 1) ^ 2 + (2 * y - 1) ^ 2)) / 2 + 0.5 Catch
and results in some errors in white pixels at the top area.
It seems the term inside if Sqrt() must be clamped to 0 and 1 perhaps to prevent floating-point errors in GB32.
_____________________________________________________
Today I found a term that works so far but only when the input normalized -1.0 to 1.0. But took me some long time to find out.
Does anyone of you have some more acknowledge of trigonometry?
Here is the problem to solve. The colored texture colors RGB represent Vectors in 3d space X,Y,Z simply.
Pre-info:
If we add the calculated blue channel to red and green we got a normal texture. Like this:
The green - red colors in the image are 2 vectors. Red represent z vector (0-1) and green x vector (0-1).
And the y vector (blue color) goes straight down from top to bottom through the center.
Normalized 0 to 1 means: The color value of R = 128, then the normalized value is 0.5 (r=128 /256).
If we represent it in 3D and arrows it would look like this in 3d space.
Problem description:
I use some normal textures for my 3d Project, but these normal textures has wrong roated vectors. This cause wrong lighting behaviors. Here is an example:
The left circle is correct, and the right one is wrong rotated (mine). Now I try to find a solution to rotate them for any degrees.
The solution:
Each of the pixel colors represent a 3d vector or angle. If we calculate the angle vector(x,y,z) of that pixel, we can simply rotate this vector around the y axis.
The result of the rotation is another angle vector(x,y,z). The new angle-vector correspond with a color as well. We set the old pixel to the new color and viola we are done!
If someone has a bit experience with algebra, is only to create a 3d vector of rgb like Vector3(x=green, y=blue, z=red) :
GB32 pseudo-code:
Type Vector3
- double x
- double y
- double z
Endtype
Dim v3In as Vector3
v3In.x = green channel
v3In.z = red channel
v3In.y = blue channel
// rotate
Dim v3out as Vector3
v3out = @rotate_around_y(v3In, degree as double // or Rad or something that works for fine rotation )
// I will create the pixel color from the result angle-vector
newRGBColor = GetColorFromHistoram(v3out)
I think it not to difficultly because the vectors for rotation are already available.
What do you think?