예제 #1
0
        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 void Run()
        {
            Renderer renderer = new Renderer(new OrthoRenderManager(new Math.Vector3f(0, 0, 1), width, height), new PhongDirectContributionModel());

            Scene scene = new Scene();
            scene.AddRenderObject(new Sphere(new Math.Vector3f(320, 320, 650), 150, new Color(1, 0, 1)));
            scene.AddRenderObject(new Sphere(new Math.Vector3f(320, 500, 800), 150, new Color(1, 0, 1)));
            OutputData data = renderer.RenderScene(scene);

            ImageOutput imageOut = new ImageOutput(width, height, data);

            imageOut.WriteOutput(@"C:\users\Ethan\Desktop\RayTraceSceneTest.png");
        }
예제 #3
0
        public RenderData CastEyeRay(Ray ray, Scene scene)
        {
            RayLifetimeManager rayManager = new RayLifetimeManager(ray, scene, renderModel);

            RenderData rayCastResult = rayManager.DoRayCast();

            if (rayCastResult == null)
            {
                return new RenderData(new Color(0, 0, 0));
            }

            return rayCastResult;
        }