Ejemplo n.º 1
0
        public static void RayTrace <T>(Texture2D texture, Scene <T, MyMaterial <T> > scene, Raytracer <MyRTRayPayload, T, MyMaterial <T> > raycaster, float4x4 viewMatrix, float4x4 projectionMatrix, int rendStep = 1, int gridXDiv = 8, int gridYDiv = 8) where T : struct, IVertex <T>, INormalVertex <T>, ICoordinatesVertex <T>, IColorable, ITransformable <T>
        {
            var start = new Stopwatch();

            start.Start();

            var tasks = new List <Task>();
            int id = 0, xStep = texture.Width / gridXDiv, yStep = texture.Height / gridYDiv;

            for (int i = 0; i *yStep < texture.Height; i++)
            {
                for (int j = 0; j *xStep < texture.Width; j++)
                {
                    int threadId = id, x0 = j * xStep, y0 = i * yStep, maxX = Math.Min((j + 1) * xStep, texture.Width), maxY = Math.Min((i + 1) * yStep, texture.Height);
                    tasks.Add(Task.Run(() => RenderUtils.RaytracePassDrawArea(threadId, x0, y0, maxX, maxY, raycaster, texture, viewMatrix, projectionMatrix, scene, rendStep)));
                    id++;
                }
            }
            Task.WaitAll(tasks.ToArray());
            start.Stop();
            Console.WriteLine($"Elapsed {start.ElapsedMilliseconds} milliseconds");
        }
Ejemplo n.º 2
0
        public static void Draw <T, M>(Texture2D texture, Raytracer <DefaultRayPayload, T, M> raytracer, Scene <T, M> scene, float4x4 viewMatrix, float4x4 projectionMatrix, int rendStep = 1, int gridXDiv = 8, int gridYDiv = 8) where T : struct where M : struct
        {
            var start = new Stopwatch();

            start.Start();

            var tasks = new List <Task>();
            int id = 0, xStep = texture.Width / gridXDiv, yStep = texture.Height / gridYDiv;

            for (int i = 0; i *yStep < texture.Height; i++)
            {
                for (int j = 0; j *xStep < texture.Width; j++)
                {
                    int threadId = id, x0 = j * xStep, y0 = i * yStep, maxX = Math.Min((j + 1) * xStep, texture.Width), maxY = Math.Min((i + 1) * yStep, texture.Height);
                    tasks.Add(Task.Run(() => RenderUtils.DrawArea(threadId, x0, y0, maxX, maxY, raytracer, texture, viewMatrix, projectionMatrix, scene, rendStep)));
                    id++;
                }
            }
            Task.WaitAll(tasks.ToArray());
            start.Stop();
            Console.WriteLine($"Elapsed {start.ElapsedMilliseconds} milliseconds");
        }