private void PutPixel(DirectBitmap bitmap, int x, int y) { if (!(x >= 0 && x < bitmap.Width && y >= 0 && y < bitmap.Height)) { return; } int R, G, B; double cos; Vector normal; if (NormalOn && NormalMap != null) { normal = NormalMap[x % NormalMap.GetLength(0), y % NormalMap.GetLength(1)]; } else { normal = new Vector(0, 0, 1); } if (HeightMapOn && HeightMap != null) { normal.Add(HeightMap[x % HeightMap.GetLength(0), y % HeightMap.GetLength(1)]); normal.Normalise(); } cos = LightSettings.GetVectorToPoint(x, y).GetAngle(normal); if (TextureOn && Texture != null) { R = (int)((double)LightSettings.LightColor.R * Texture[x % Texture.GetLength(0), y % Texture.GetLength(1)].R / 255 * cos); G = (int)((double)LightSettings.LightColor.G * Texture[x % Texture.GetLength(0), y % Texture.GetLength(1)].G / 255 * cos); B = (int)((double)LightSettings.LightColor.B * Texture[x % Texture.GetLength(0), y % Texture.GetLength(1)].B / 255 * cos); } else { R = (int)(polygonColor.R * (double)LightSettings.LightColor.R / 255 * cos); G = (int)(polygonColor.G * (double)LightSettings.LightColor.G / 255 * cos); B = (int)(polygonColor.B * (double)LightSettings.LightColor.B / 255 * cos); } bitmap.SetPixel(x, y, Color.FromArgb(Cut(R), Cut(G), Cut(B))); }
public Vector3 NormalAt(int x, int y) { if (x >= NormalMap.GetLength(0)) { x = NormalMap.GetLength(0) - 1; } if (y >= NormalMap.GetLength(1)) { y = NormalMap.GetLength(1) - 1; } if (x < 0) { x = 0; } if (y < 0) { y = 0; } return(NormalMap[x, y]); }