public OutputData RenderScene(Scene scene) { ISet<Task<RenderData>> results = new HashSet<Task<RenderData>>(); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { Vector3f rayDirection = renderManager.CalculateEyeRayDirection(x, y); Vector3f rayStart = new Vector3f(x, y, 0.0f); results.Add(taskFactory.StartNew(() => CastEyeRay(new Ray(rayStart, rayDirection), scene))); } } Task<RenderData>[] resultsArray = new Task<RenderData>[results.Count]; results.CopyTo(resultsArray, 0); Task.WaitAll(resultsArray); BasicOutputConverter coverter = new BasicOutputConverter(1, width, height); RenderData[] finalData = new RenderData[resultsArray.Length]; for (int i = 0; i < finalData.Length; i++) { finalData[i] = resultsArray[i].Result; } return coverter.DoConversion(finalData); }
public Vector3f CalculateSpecularReflectionDirection(RayIntersection data, Scene scene) { Vector3f normal = new Vector3f(data.Normal).Normalize(); Vector3f eyeVec = new Vector3f(-data.Position).Normalize(); //Eye position is always (0,0,0) return Vector3f.ReflectVector(eyeVec, normal).Normalize(); }
public Vector3f CalculateDirectShading(RayIntersection data, Light l) { Vector3f eyeVec = new Vector3f(-data.Position).Normalize(); //Eye position must be at (0,0,0) MaterialData md = data.MaterialData; //Vector3f outputColor = new Vector3f(); //foreach (Light l in scene.Lights) //Foreach light, compute direct diffuse reflection and direct specular highlight //{ Vector3f norm = data.Normal; Vector3f lVec = (data.Position - l.Position).Normalize(); float lambert = (lVec * norm) * 0.3f * md.Diffuse; //Specular Vector3f reflect = -Vector3f.ReflectVector(lVec, norm); float spec = md.Specular * MathUtil.Pow(MathUtil.Max(reflect * eyeVec, 0.0f), 1); //outputColor = (spec * md.SpecularColor.AsVector3()) + (lambert * md.DiffuseColor.AsVector3()); //} return new Vector3f((spec * md.SpecularColor.AsVector3()) + (lambert * md.DiffuseColor.AsVector3())); }
public Vector3f(Vector3f vec) : this(vec.x, vec.y, vec.z) { }
public static Vector3f ReflectVector(Vector3f vec, Vector3f reflector) { Vector3f norm = new Vector3f(reflector).Normalize(); return vec - (2 * (vec * norm) * norm); }
public static float Distance2(Vector3f a, Vector3f b) { return (a - b).Mag2(); }
private Vector3f CalculateSurfaceNormal(Vector3f point) { return new Vector3f(position - point).Normalize(); }
public Sphere(Vector3f position, float radius, Color color) { this.position = position; this.radius = radius; materialData = new MaterialData(color, new Color(1.0f, 1.0f, 1.0f), 0.3f, 0.3f, 0.3f, 0.3f); }
public Color(Vector3f src) { this.data = new Vector3f(src); }
public Color(float grayscale) { data = new Vector3f(grayscale); }
public Color(float r, float g, float b) { data = new Vector3f(r, g, b); }
public Ray(Vector3f start, Vector3f direction) { this.start = new Vector3f(start); this.direction = new Vector3f(direction); }