private Color ComputeLight(Color finalColor, Vector3 hitPosition, Vector3 hitNormal, PotatoPointLight light) { Vector3 directionToLight = light.GetDirection(hitPosition); if (light.InRange(hitPosition)) { double normalAng = DiffuseAngle(hitPosition, hitNormal, light); if (normalAng > 0) { finalColor = Color.FromArgb((int)Math.Round((light.Color.R + finalColor.R) * 0.5f * normalAng * light.Intensity), (int)Math.Round((light.Color.G + finalColor.G) * 0.5f * normalAng * light.Intensity), (int)Math.Round((light.Color.B + finalColor.B) * 0.5f * normalAng * light.Intensity)); } else { finalColor = Color.Black; } } return(finalColor); }
public static double DiffuseAngle(Vector3 hitPoint, Vector3 normal, PotatoPointLight light) { Vector3 dir = Vector3.Normalize(light.Position - hitPoint); return(Vector3.Dot(dir, normal)); }
public static float DiffuseAngle(Vector3 hitPoint, Vector3 normal, PotatoPointLight light) { Vector3 dir = Vector3.Normalize(Vector3.Subtract(light.Position, hitPoint)); return(Vector3.Dot(dir, normal)); }