public Vector3D GetVector(int x, int y) { if (UsingNormalMap) { var v = new Vector3D(NormalMap.GetPixel(x, y).R - 128, NormalMap.GetPixel(x, y).G - 128, NormalMap.GetPixel(x, y).B); v = v / v.Length; return(v); } else { return(new Vector3D(0, 0, 1)); } }
public Vector3 GetNormalVector(int x, int y) { Vector3 normalVec; Vector3 disturbanceVector; if (!UseFixedNormalVector && !UseMouseFollowNormalVector && NormalMap != null) { var normalColor = NormalMap.GetPixel(y % NormalMap.Height, x % NormalMap.Width); normalVec = new Vector3(normalColor.R - 127, normalColor.G - 127, normalColor.B - 127); normalVec.X /= 127; normalVec.Y /= 127; normalVec.Z /= 127; normalVec = Vector3.Normalize(normalVec); } else if (UseMouseFollowNormalVector) { var dx = mousePosition.X - x; var dy = mousePosition.Y - y; var z = 100 * 100 - dx * dx - dy * dy; z = z < 0 ? 0 : (float)Math.Sqrt(z); normalVec = Vector3.Normalize(new Vector3(dx, dy, z)); } else { normalVec = new Vector3(0, 0, 1); } if (!UseEmptyDisturbanceVector && HeightMap != null) { var hCol = HeightMap.GetPixel(y % HeightMap.Height, x % HeightMap.Width); var rightHCol = HeightMap.GetPixel(y % HeightMap.Height, (x + 1) % HeightMap.Width); var downHCol = HeightMap.GetPixel((y + 1) % HeightMap.Height, x % HeightMap.Width); var dhx = (rightHCol.R - hCol.R + rightHCol.G - hCol.G + rightHCol.B - hCol.B) * Factor; var dhy = (downHCol.R - hCol.R + downHCol.G - hCol.G + downHCol.B - hCol.B) * Factor; disturbanceVector = new Vector3(dhx, 0, -normalVec.X + dhx) + new Vector3(dhy, 0, -normalVec.Y * dhy); } else { disturbanceVector = new Vector3(0, 0, 0); } var normalPrim = normalVec + disturbanceVector; return(Vector3.Normalize(normalPrim)); }
public Vector3 Normal(Vector2 vec) { var color = NormalMap.GetPixel((int)(vec.X * NormalMap.Width), (int)(vec.Y * NormalMap.Height)); return(new Vector3(color.R, color.G, color.B)); }