public static Vector3[,] BitmapToVectors(Bitmap bitmap) { Vector3[,] textureVectors = new Vector3[bitmap.Width, bitmap.Height]; for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { textureVectors[i, j] = LibrariesConverters.ColorToVector(bitmap.GetPixel(i, j)); } } return(textureVectors); }
public void CalculateNMap() { Vector3 N; for (int i = 0; i < Width; i++) { for (int j = 0; j < Height; j++) { N = IsNormalConst ? NormalVector : IsNormalFunction?CalculateNormalFromFunction(i, j) : LibrariesConverters.ColorToNormalVector(NormalMap[i % NormalMap.Width, j % NormalMap.Height].Color); N = Vector3.Normalize(N); if (!IsHeightConst) { Vector3 TV = new Vector3(1, 0, -N.X / N.Z); Vector3 BV = new Vector3(0, 1, -N.Y / N.Z); float dX = HeightMap[(i + 1) % HeightMap.Width, j % HeightMap.Height].Color.R - HeightMap[i % HeightMap.Width, j % HeightMap.Height].Color.R; float dY = HeightMap[i % HeightMap.Width, (j + 1) % HeightMap.Height].Color.R - HeightMap[i % HeightMap.Width, j % HeightMap.Height].Color.R; Vector3 D = TV * dX + BV * dY; N += D * HeightRate; N = Vector3.Normalize(N); } if (float.IsNaN(N.X) || float.IsNaN(N.Y) || float.IsNaN(N.Z)) { N = new Vector3(0, 0, 1); } NMap[i, j] = N; } } }