コード例 #1
0
        public static AngleFunc MeshToAngleFunc(IRayTracer rayTracer, Point3D point, int nMu, int nPhi)
        {
            var result = new AngleFunc(nMu, nPhi, true);
            var pi2    = Math.PI / 2;

            for (int iMu = 0; iMu < result.Mu.Count; iMu++)
            {
                for (int iPhi = 0; iPhi < nPhi; iPhi++)
                {
                    var    theta     = (float)(pi2 - Math.Acos(result.Mu[iMu]));
                    var    phi       = result.Phi[iPhi];
                    Vector direction = new Vector(theta, phi);

                    var intersection = rayTracer.Trace(point, direction, Constants.Epsilon);

                    if (intersection == null)
                    {
                        //RayDebugStaticCollection.Add( new Ray( point, direction ), System.Drawing.Color.Red );
                    }
                    else
                    {
                        var r = (intersection.Point - point).Length;
                        result.R[iMu][iPhi] = r;
                        //RayDebugStaticCollection.Add( new Ray( point, intersection.Point ), System.Drawing.Color.Green );
                    }
                }
            }

            return(result);
        }
コード例 #2
0
 public DoubleLocalEstimationCalculator( Scene scene, IRayTracer rayTracer, int nRays, float wMin )
 {
     Scene = scene;
     RayTracer = rayTracer;
     NRays = nRays;
     WMin = wMin;
 }
コード例 #3
0
        public override Spectrum GetIlluminance(IRayTracer rayTracer, IMaterial material, Point3D point, Vector normal, Vector view)
        {
            var fakePoint = new Point3D(0, 0, (this.Position - point).Length);

            var formFactor = this.GetFormFactor(point, fakePoint);

            // если нет расчетных точек, то генерим их на источнике
            if (this.LightSamplePoints == null)
            {
                this.GenerateLightSamplePoints();
            }

            var result = new Spectrum();

            var toLightVector = new Vector(point, this.Position);
            //var toLightRay = new Ray( point, this.Position );

            var cosR = Math.Abs(-Vector.Dot(toLightVector, this.Direction));

            result += material.Reflectance.BRDF(toLightVector, normal, view) * cosR;

            // форм фактор уменьшаяется за счет не попавших лучей
            // (float) Math.PI - из ядра уравнения
            result = this.Illuminance * result * formFactor / Constants.PI;

            //result = result * this.Illuminance / (float)( this.Samples );
            return(result);
        }
コード例 #4
0
        private static void RenderFunc(
            IRayTracer rayTracer,
            int pixelWidth,
            ConcurrentQueue <int> rowQueue,
            ConcurrentQueue <RenderLineResult> resultQueue,
            AutoResetEvent queueDataAvailableEvent)
        {
            try
            {
                while (rowQueue.TryDequeue(out int y))
                {
                    var rowPixels = new List <PixelData>();
                    for (var x = 0; x < pixelWidth; x++)
                    {
                        rowPixels.Add(rayTracer.GetPixelColor(x, y));
                    }

                    resultQueue.Enqueue(new RenderLineResult(y, rowPixels));
                    queueDataAvailableEvent.Set();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
コード例 #5
0
 public DoubleLocalEstimation(IRayTracer rayTracer, int nPackets, int nRays, float wMin)
 {
     RayTracer = rayTracer;
     scene     = rayTracer.Scene;
     NPackets  = nPackets;
     NRays     = nRays;
     WMin      = wMin;
 }
コード例 #6
0
 public MRenderDoubleLocalEst(MScene scene, IRayTracer rayTracer, int nRays, float wMin, ILog log = null)
 {
     NRays     = nRays;
     WMin      = wMin;
     Scene     = scene;
     RayTracer = rayTracer;
     Log       = log;
 }
コード例 #7
0
        static void Main()
        {
            scene = (Scene)Activator.CreateInstance(Constants.SceneIndex);

            //Create the RayTracer setup you want to use here
            IRayTracer tracer = (IRayTracer)Activator.CreateInstance(Constants.RayTracer, scene);

            tracer.Render();
        }
コード例 #8
0
 /// <summary>
 /// Sorts out all vertices form the relevantVertices list which
 /// aren't hit directly by a ray from the IRayTracer.
 /// </summary>
 public void SortOutUnhittedVertices(IRayTracer tracer)
 {
     for (int i = RelevantVertices.Count - 1; i >= 0; i--)
     {
         if (!tracer.CreateRay(GetRelevantVertexPosition(i)))
         {
             RelevantVertices.Remove(RelevantVertices[i]);
         }
     }
 }
コード例 #9
0
        private static async Task Render(IRayTracer rayTracer, RayTraceRenderData renderData, string filePath)
        {
            var pixelArray = new PixelArray(renderData.Width, renderData.Height);
            var renderer   = new SceneRenderer();

            renderer.Progress += (sender, eventArgs) => Console.Write($"...{eventArgs.PercentComplete}%");
            await renderer.RayTraceSceneAsync(rayTracer.GetPixelColor, pixelArray, renderData.MaxParallelism).ConfigureAwait(false);

            pixelArray.SaveToPng(filePath);
            Console.WriteLine();
            Console.WriteLine($"Saved image to {filePath}");
        }
コード例 #10
0
        public virtual Spectrum GetIlluminance(IRayTracer rayTracer, IMaterial material, Point3D point, Vector normal, Vector view)
        {
            // проверяем что нормали сонаправлены

            var xx = Vector.Dot(normal, this.Direction);

            if (xx > Constants.Epsilon || point.Z > this.Position.Z)
            {
                return(new Spectrum());
            }

            var formFactor = this.GetFormFactor(point);

            // если нет расчетных точек, то генерим их на источнике
            if (this.LightSamplePoints == null)
            {
                this.GenerateLightSamplePoints();
            }

            var result = new Spectrum();

            // цикл по всем расчетным точкам на источнике
            int raysHited = 0;

            foreach (var lightSamplePoint in this.LightSamplePoints)
            {
                var toLight       = lightSamplePoint.Point - point;
                var toLightVector = new Vector(toLight, true);
                //var toLightRay = new Ray( point, lightSamplePoint.Point );
                if (!rayTracer.Occluded(point, toLightVector, Constants.Epsilon, toLight.Length - Constants.Epsilon))
                {
                    // источник косинусный
                    var cosR = Math.Abs(-Vector.Dot(toLightVector, this.Direction));
                    result += material.Reflectance.BRDF(toLightVector.Reverse(), normal, view) * cosR;
                    raysHited++;
                }
            }

            if (raysHited == 0)
            {
                return(new Spectrum());
            }

            // усредняем BRDF
            result = result / (float)raysHited;

            // форм фактор уменьшаяется за счет не попавших лучей
            // (float) Math.PI - из ядра уравнения
            result = this.Illuminance * result * formFactor * (raysHited / (float)(this.Samples));

            //result = result * this.Illuminance / (float)( this.Samples );
            return(result);
        }
コード例 #11
0
ファイル: PointLight.cs プロジェクト: Zheltov/Illuminarium
        public Spectrum GetIlluminance(IRayTracer rayTracer, IMaterial material, Point3D point, Vector normal, Vector view)
        {
            var toLight       = this.Position - point;
            var toLightVector = new Vector(toLight, true);

            //var toLightRay = new Ray( point + normal * Constants.Epsilon, this.Position );

            if (!rayTracer.Occluded(point + normal * Constants.Epsilon, toLightVector, 0, toLight.Length))
            {
                return(this.Intensity * material.Reflectance.BRDF(toLightVector, normal, view) / toLight.Length2);
            }
            else
            {
                return(new Spectrum());
            }
        }
コード例 #12
0
ファイル: Renderer.cs プロジェクト: MarkZuber/raynet
        private static void RenderFunc(
            IRayTracer rayTracer,
            ConcurrentQueue <int> rowQueue,
            ConcurrentQueue <RenderLineResult> resultQueue,
            AutoResetEvent queueDataAvailableEvent)
        {
            while (rowQueue.TryDequeue(out var y))
            {
                // Console.WriteLine($"Thread {Thread.CurrentThread.ManagedThreadId} starting to render row: {y}");
                var rowPixels = new List <ColorVector>();
                for (var x = 0; x < rayTracer.RenderData.Width; x++)
                {
                    rowPixels.Add(rayTracer.GetPixelColor(x, y));
                }

                resultQueue.Enqueue(new RenderLineResult(y, rowPixels));
                queueDataAvailableEvent.Set();
            }
        }
コード例 #13
0
ファイル: PerPixelRenderer.cs プロジェクト: MarkZuber/wkndray
 private static void RenderFunc(
     IRayTracer rayTracer,
     ConcurrentQueue <RenderInput> inputQueue,
     ConcurrentQueue <RenderResult> resultQueue,
     AutoResetEvent queueDataAvailableEvent)
 {
     try
     {
         while (inputQueue.TryDequeue(out RenderInput input))
         {
             var pixelData = rayTracer.GetPixelColor(input.X, input.Y);
             resultQueue.Enqueue(new RenderResult(input.X, input.Y, pixelData));
             queueDataAvailableEvent.Set();
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
     }
 }
コード例 #14
0
    public void SortOutUnhittedVerticesForZeroVerticesHitted_Test()
    {
        // setup
        SetUp();

        controller.RelevantVertices = new List <int>()
        {
            0, 1, 2
        };
        int expected = 0;

        IRayTracer rt = Substitute.For <IRayTracer>();

        rt.CreateRay(controller.GetRelevantVerticePositions()[0]).Returns(false);
        rt.CreateRay(controller.GetRelevantVerticePositions()[1]).Returns(false);
        rt.CreateRay(controller.GetRelevantVerticePositions()[2]).Returns(false);

        // perform
        controller.SortOutUnhittedVertices(rt);

        // assert
        Assert.AreEqual(expected, controller.RelevantVertices.Count);
    }
コード例 #15
0
 public LoggingRayTracer(IRayTracer rayTracer)
 {
     this.rayTracer = rayTracer;
 }
コード例 #16
0
 public DoubleLocalEstimation(IRayTracer rayTracer, int nPackets, int nRays, float wMin, ILog log)
     : this(rayTracer, nPackets, nRays, wMin)
 {
     this.Log = log;
 }
コード例 #17
0
ファイル: Scene.cs プロジェクト: tincann/AGR
 public Scene(IRayTracer tracer, bool constructBVH)
 {
     _tracer = tracer;
     _constructBvh = constructBVH;
 }
コード例 #18
0
 public DoubleLocalEstimationCalculator( Scene scene, IRayTracer rayTracer, int nRays, float wMin, ILog log )
     : this( scene, rayTracer, nRays, wMin )
 {
     this.Log = log;
 }
コード例 #19
0
ファイル: App.cs プロジェクト: DrHopping/ComputerGraphics
 public App(IRayTracer rayTracer, ISceneProvider sceneProvider)
 {
     _rayTracer     = rayTracer;
     _sceneProvider = sceneProvider;
 }
コード例 #20
0
 public SimpleRenderer(IRayTracer rayTracer)
 {
     this.RayTracer = rayTracer;
 }
コード例 #21
0
 public Scene(IRayTracer tracer, bool constructBVH)
 {
     _tracer       = tracer;
     _constructBvh = constructBVH;
 }
コード例 #22
0
 public RayTraceProcessHandler(IRayTraceConfigurationModel confguration, IRayTracer rayTracer, IRayTraceTarget target)
 {
     this.confguration = confguration;
     this.rayTracer    = rayTracer;
     this.target       = target;
 }
コード例 #23
0
ファイル: PointLight.cs プロジェクト: Zheltov/Illuminarium
 public IList <Spectrum> GetIlluminance(IRayTracer rayTracer, IMaterial material, Point3D point, Vector normal, IList <Vector> view)
 {
     throw new NotImplementedException();
 }
コード例 #24
0
 public MRenderDirectLight(MScene scene, IRayTracer rayTracer, ILog log = null)
 {
     Scene     = scene;
     RayTracer = rayTracer;
     Log       = log;
 }