Exemplo n.º 1
0
        public void Init(RayEngineScene scene, Data.TriangleMesh[] geometry)
        {
            var sceneModel = scene;
            meshes = new List<ITriangleMesh>();
            meshes.AddRange(scene.Meshes);
            this.sceneVertices = sceneModel.Vertices;
            this.triangles = scene.Triangles.ToArray();
            bvhPrimitives = this.triangles.Select((item, i) =>
                {
                    var result = new BvhPrimitive() {Bounds = item.WorldBound(sceneVertices), Index = i};
                    result.Bounds.Expand(MathLab.RAY_EPSILON);
                    return result;
                }).ToList();

            this.BuildTree();

            /*
            var tris = new List<TriangleInfo>(triangles.Count());
            tris.AddRange(bvhPrimitives.Select(bvhPrimitive => triangles[bvhPrimitive.Index]));
            this.triangles = tris.ToArray();
            */
            Tracer.TraceLine("Linearize BVH");
            this.LinearizeBVH();
            Tracer.TraceLine("Complete");
            


            Tracer.TraceLine("Tree is builded, {0} nodes total", bvhNodesCount);
        }
Exemplo n.º 2
0
        public override void InitPath(IPathProcessor buffer)
        {
            base.InitPath(buffer);
            MaxRaysPerPath = 1;
            this.scene = pathIntegrator.Scene;
            var pssSampler = (PsMltSampler)this.pathIntegrator.Sampler;

            this.Radiance = new RgbSpectrum(0f);
            this.Throughput = new RgbSpectrum(1f);
            if (this.Sample == null || this.Sample.LargeStep || pssSampler.BurnInPhase ||this.Sample.MutationsCount > (pssSampler.MaxMutations))
            {
                this.Sample = (PsSample)pssSampler.GetSample(this.Sample);
            }
            else
            {
                this.Sample.imageX = MC.Mutate(this.Sample.imageX, pssSampler.NextFloat(), pssSampler.NextFloat(),2.0f/(2000),0.1f);
                this.Sample.imageY = MC.Mutate(this.Sample.imageY, pssSampler.NextFloat(), pssSampler.NextFloat(), 2.0f / (2000), 0.1f);
                pssSampler.TotalSamples++;
            }
            IRay ray;
            pathIntegrator.Scene.Camera.GetRay(Sample.imageX, Sample.imageY, out ray);
            this.PathRay = (RayData)ray;
            this.RayIndex = -1;
            this.pathWeight = 1.0f;
            this.tracedShadowRayCount = 0;
            this.depth = 0;
            this.specularBounce = true;
        }
Exemplo n.º 3
0
        public override void InitPath(IPathProcessor buffer)
        {
            base.InitPath(buffer);
            this.scene = pathIntegrator.Scene;
            this.PathState = PathTracerPathState.EyeVertex;
            if (this.secRays == null)
                this.secRays = new ConnectRayInfo[MaxEyeRays];
            this.RayIndex = -1;
            this.pathWeight = 1.0f;
            this.tracedShadowRayCount = 0;
            this.depth = 0;
            this.specularBounce = true;
            this.Radiance = new RgbSpectrum(0f);

            this.Sample = pathIntegrator.Sampler.GetSample(null);
            LightSample ls;
            var light = scene.Lights[scene.SampleLights(Sample.GetLazyValue())];
            light.EvaluatePhoton(scene, Sample.GetLazyValue(), Sample.GetLazyValue(), Sample.GetLazyValue(), Sample.GetLazyValue(), Sample.GetLazyValue(), out ls);
            PathRay = ls.LightRay;
            var lightPdf = ls.Pdf;
            Throughput = (RgbSpectrum)(ls.Spectrum);
            //* scene.Lights.Length) / lightPdf;

            //buffer.Scene.Camera.GetRay(Sample.imageX, Sample.imageY, out this.PathRay);
        }
Exemplo n.º 4
0
 protected virtual PathIntegrator CreatePathBuffer(int maxPath, RayEngineScene scene, ImageFilmBase pixelDevice,
                                           IPrimarySpaceSampler sampler, SurfaceSampler ss)
 {
     var integrator = new PathIntegrator();
     integrator.Init(maxPath, scene, pixelDevice, sampler, ss);
     return integrator;
 }
Exemplo n.º 5
0
        public override void InitPath(IPathProcessor buffer)
        {
            base.InitPath(buffer);
            this.scene = pathIntegrator.Scene;
            this.Radiance = new RgbSpectrum(0f);
            this.waveRadiance = 0f;
            this.waveThroughput = 1f;
            this.PathState = PathTracerPathState.EyeVertex;
            if (this.secRays == null)
                this.secRays = new ShadowRayInfo[scene.ShadowRaysPerSample];

            if (lambdaSample == 0)
            {
                this.Sample = pathIntegrator.Sampler.GetSample(this.Sample);
                this.Sample.InitSample(scene.MaxPathDepth*8);
                pathIntegrator.Scene.Camera.GetRay(Sample.imageX, Sample.imageY, out this.PathRay);
            }

            this.HeroWavelength = this.wlSampler.SampleWavelength(
                lambdaSample);
                //Sample.GetLazyValue(0));
            this.RayIndex = -1;
            this.pathWeight = 1.0f;
            this.tracedShadowRayCount = 0;
            this.depth = 0;
            this.specularBounce = true;
        }
Exemplo n.º 6
0
        public override void InitPath(IPathProcessor buffer)
        {
            base.InitPath(buffer);
            this.scene = pathIntegrator.Scene;

            this.Radiance = new RgbSpectrum(0f);
            this.PathState = BDPTSamplerState.InitPath;
            if (this.connectRays == null)
                this.connectRays = new ConnectRayInfo[scene.MaxPathDepth * scene.MaxPathDepth];
            lightPath = new VertexInfo[MaxLightDepth];
            this.Sample = pathIntegrator.Sampler.GetSample(null);
            lightVertices = 0;

            //Init eye ray
            this.EyeThroughput = new RgbSpectrum(1f);
            pathIntegrator.Scene.Camera.GetRay(Sample.imageX, Sample.imageY, out this.PathRay);
            this.RayIndex = -1;
            this.LightRayIndex = -1;
            this.eyePdf = 1f;

            //Init light path
            LightSample ls;
            var light = scene.Lights[scene.SampleLights(Sample.GetLazyValue())];
            light.EvaluatePhoton(scene, Sample.GetLazyValue(), Sample.GetLazyValue(), Sample.GetLazyValue(), Sample.GetLazyValue(), Sample.GetLazyValue(), out ls);
            LightRay = ls.LightRay;
            lightPdf = ls.Pdf * (1f / scene.Lights.Length);
            LightThroughput = (RgbSpectrum)(ls.Spectrum);


            this.tracedConnectRayCount = 0;
            this.eyeDepth = 0;
            this.lightDepth = 0;
            this.eyeStop = false;
            this.lightStop = false;
        }
Exemplo n.º 7
0
        public CudaIntersectionDevice(RayEngineScene scene, NVContext ctx)
            : base(scene)
        {
            wallclock = new Stopwatch();
            this.todoRayBuffers = new ConcurrentQueue<Tuple<int, RayBuffer>>();
            this.doneRayBuffers = new List<ConcurrentQueue<RayBuffer>>() { { new ConcurrentQueue<RayBuffer>() } };
            this.started = false;
            if (ctx != null)
            {
                this.cudaContext = ctx;
            }
            else
            {
                this.cudaContext = new NVContext() { Context = new CudaContext(CudaContext.GetMaxGflopsDeviceId()) };
            }
            using (var sr = new StreamReader(@"G:\Git\RayDen\CudaMegaRay\x64\Release\kernel.cu.ptx"))
            {
                intersectKernel = cudaContext.Context.LoadKernelPTX(sr.BaseStream, "IntersectLBvh");
            }

            this.rays = new CudaDeviceVariable<RayData>(RayBuffer.RayBufferSize);
            this.hits = new CudaDeviceVariable<RayHit>(RayBuffer.RayBufferSize);
            verts = scene.Vertices.ToArray();
            //scene.Triangles.Select(i => i.GetInfo()).ToArray();

            var ti = scene.Triangles.Select(i => i.GetInfo()).ToArray();
            var da = new BvhDataAdapter(scene);
            var treeData = da.GetMpData();
            bvh = treeData;
            trianglesCount = ti.Length;
            tris = ti; 

            nodesCount = treeData.Length;
            Tracer.TraceLine("BVH Data Size {0:F3} MBytes", (treeData.Length * 32f) / (1024f * 1024f));
        }
Exemplo n.º 8
0
        public override void InitPath(IPathProcessor buffer)
        {
            base.InitPath(buffer);
            scene = pathIntegrator.Scene;

            this.Sample = new Sample(pathIntegrator.Sampler);
            this.RayIndex = -1;
            float lspdf;

            int li = scene.SampleLights(this.Sample.GetLazyValue(), out lspdf);
            var ls = new LightSample();
            bool done = false;
            while (!done)
            {
                scene.Lights[li].EvaluatePhoton(
                    scene,
                    Sample.GetLazyValue(),
                    Sample.GetLazyValue(),
                    Sample.GetLazyValue(),
                    Sample.GetLazyValue(),
                    Sample.GetLazyValue(),
                    out ls);

                done = ls.Pdf > 0f;

            }

            var pathWeight =  (ls.Pdf *  lspdf);

            this.ThroughtPut = ((RgbSpectrum)(ls.Spectrum) / pathWeight);
            this.PathRay = ls.LightRay;
        }
 public ProductionPathTracerEngine(RayEngineScene scene) : base(scene)
 {
     if (!GlobalConfiguration.Instance.AdaptiveFilm)
     {
         throw new ApplicationException("Adaptive film should be used");
     }
 }
Exemplo n.º 10
0
 public override void InitPath(IPathProcessor buffer)
 {
     base.InitPath(buffer);
     this.scene = pathIntegrator.Scene;
     this.Radiance = new RgbSpectrum(0f);
     this.Throughput = new RgbSpectrum(1f);
     this.PathState = PathTracerPathState.EyeVertex;
     if (this.secRays == null)
         this.secRays = new ShadowRayInfo[scene.ShadowRayCount];
     if (this.volumeComp == null)
     {
         this.volumeComp = scene.GetVolumeComputation();
     }
     else
     {
         this.volumeComp.Reset();
     }
     this.Sample = pathIntegrator.Sampler.GetSample(null);
     IRay ray;
     pathIntegrator.Scene.Camera.GetRay(Sample.imageX, Sample.imageY, out ray);
     this.PathRay = (RayData)ray;
     this.RayIndex = -1;
     this.pathWeight = 1.0f;
     this.tracedShadowRayCount = 0;
     this.depth = 0;
     this.specularBounce = true;
     this.rayID = (int)(Sample.imageX + Sample.imageY * 640f);
 }
Exemplo n.º 11
0
 public override void InitPath(IPathProcessor buffer)
 {
     base.InitPath(buffer);
     this.scene = pathIntegrator.Scene;
     this.Radiance = new RgbSpectrum(0f);
     this.Throughput = new RgbSpectrum(1f);
     this.PathState = PathTracerPathState.EyeVertex;
     if (this.secRays == null)
     {
         this.secRays = new ShadowRayInfo[scene.ShadowRaysPerSample];
         continueRays = new ShadowRayInfo[scene.ShadowRaysPerSample];
     }
     if (volumeComp == null)
     {
         volumeComp = new VolumeComputation(scene.VolumeIntegrator);
     }
     contCount = 0;
     this.Sample = pathIntegrator.Sampler.GetSample(this.Sample);
     pathIntegrator.Scene.Camera.GetRay(Sample.imageX, Sample.imageY, out this.PathRay);
     this.RayIndex = -1;
     this.pathWeight = 1.0f;
     this.tracedShadowRayCount = 0;
     this.depth = 0;
     this.specularBounce = true;
     this.inVolume = false;
 }
Exemplo n.º 12
0
        public BvhAccelHelper(RayEngineScene scn) {
            this.da = new BvhDataAdapter(scn);
            this.bvhData = this.da.BuildData().ToArray();

            int leafc = this.bvhData.Count(i => i.primitive != RayBuffer.NotHit);
            int branches = this.bvhData.Length - leafc;
            Tracer.TraceLine("Leafs {0} Branches {1}", leafc, branches);
        }
Exemplo n.º 13
0
 public SurfaceSampler(RayEngineScene scene, bool notFillLight = true)
 {
     this.scene = scene;
     this.vm = new VolumeSampler(scene);
     this.vmSampler = new VolumeMaterialSampler();
     this.texSampler = new TextureSamplingManager(scene.TextureSamplingQuality);
     this.notFillLights = notFillLight;
 }
Exemplo n.º 14
0
 public CpuBvhIntersectionEngine(RayEngineScene scene) : base(scene) {
     doneRayBuffers = new ConcurrentQueue<RayBuffer>();
     todoRayBuffers = new ConcurrentQueue<RayBuffer>();
     accel = new BvhAccelHelper(scene);
     /*
     accel = new BoundingVolumeHierarchyAccelerationStructure();
     accel.Init(scene, scene.MaterialProvider);
      * */
 }
Exemplo n.º 15
0
 public PathSampleProcessor(int maxpaths, RayEngineScene rayEngineScene, CorrectorImageFilm pixelDevice, GlobalSamplingContext samplers)
 {
     this.maxPaths = maxpaths;
     this.rayEngineScene = rayEngineScene;
     this.pixelDevice = pixelDevice;
     this.samplers = samplers;
     this.sampleBuffer = pixelDevice.GetFreeSampleBuffer();
     this.paths = new List<PathSampler>(maxPaths);
 }
Exemplo n.º 16
0
 public override RenderThread CreateRenderThread(int threadIndex, IntersectionEngine intersectionDevice,
                                                 RayEngineScene scene, IImageFilm film, IFrameManager frameManager, SamplingContext samplingContext)
 {
     if (this.Context == null)
     {
         Context = new PhotonMappingContext() { Film = film, surfaceSampler = (SurfaceSampler)samplingContext.SurfaceSampler };
     }
     return new PhotonMappingRenderThread(threadIndex, intersectionDevice, scene, LowLatencySampling, film, Context, samplingContext ,frameManager);
 }
Exemplo n.º 17
0
 protected DeviceRenderThreadBase(int index,
                                IIntersectionEngine device,
                                RayEngineScene scn,
                                bool lowLatency,
                                ImageFilmBase pixelDevice,
                                IPrimarySpaceSampler sampler, SurfaceSampler ss)
     : this(index, scn)
 {
     Init(device, lowLatency, pixelDevice, sampler, ss);
 }
Exemplo n.º 18
0
 public TriangleLight(IRayEngineScene sc, string meshName, RgbSpectrum gain = new RgbSpectrum())
 {
     this.scene = (RayEngineScene)sc;
     this.meshName = meshName;
     this.Gain = (RgbSpectrumInfo)gain;
     //cie.stdillum.F1.spd
     //@"F:\3D\spds\cie.stdillum.F1.spd"
     //cie.stdillum.A.spd
     //macbeth-1.spd
     //FromFile(@"F:\3D\spds\cie.stdillum.F9.spd")
     spectra = SPD_Data.FromSampled(SPD_Data.FromFile(@"F:\3D\spds\cie.stdillum.D5000.spd"), SpectrumType.Illuminant);
 }
Exemplo n.º 19
0
 public CorrectorRenderThread(int index,
                                IIntersectionEngine device,
                                RayEngineScene scn,
                                bool lowLatency,
                                CorrectorImageFilm pixelDevice,
                                GlobalSamplingContext sc, IFrameManager fM)
     : base(index, scn)
 {
     this.pixelDevice = pixelDevice;
     this.frameManager = fM;
     Init(device, lowLatency, pixelDevice, sc);
 }
Exemplo n.º 20
0
 public override void InitPath(PathBuffer buffer) {
     base.InitPath(buffer);
     this.scene = buffer.Scene;
     this.Radiance = new RgbSpectrum(0f);
     this.Throughput = new RgbSpectrum(1f);
     this.PathState = PathTracerPathState.EyeVertex;
     this.Sample = buffer.Sampler.GetSample();
     this.PathRay = new RayData ( scene.Camera.GetRay(Sample.imageX, Sample.imageY));
     this.RayIndex = -1;
     this.pathWeight = 1.0f;
     this.tracedShadowRayCount = 0;
     this.depth = 0;
     this.specularBounce = true;
 }
Exemplo n.º 21
0
 public override void InitPath(IPathProcessor buffer)
 {
     base.InitPath(buffer);
     depth = 0;
     specularBounce = false;
     pathWeight = 1.0f;
     this.Sample = pathIntegrator.Sampler.GetSample(null);
     scene = pathIntegrator.Scene;             
     if (this.engine == null)
     {
         var ppb = buffer as PPMPathBuffer;
         this.engine = ppb.context;
     }
 }
Exemplo n.º 22
0
 public override void InitPath(IPathProcessor buffer)
 {
     base.InitPath(buffer);
     this.scene = pathIntegrator.Scene;
     this.Radiance = new SampledSpectrum(0f);
     this.Throughput = new SampledSpectrum(1f);
     this.PathState = PathTracerPathState.EyeVertex;
     if (this.secRays == null)
         this.secRays = new SpectralShadowRayInfo[scene.ShadowRaysPerSample];
     this.Sample = pathIntegrator.Sampler.GetSample(null);
     pathIntegrator.Scene.Camera.GetRay(Sample.imageX, Sample.imageY, out this.PathRay);
     this.RayIndex = -1;
     this.pathWeight = 1.0f;
     this.tracedShadowRayCount = 0;
     this.depth = 0;
     this.specularBounce = true;
 }
Exemplo n.º 23
0
        public DadeCudaIntersectionDevice(RayEngineScene scene, NVContext ctx)
            : base(scene)
        {
            this.scene = scene;
            wallclock = new Stopwatch();
            this.todoRayBuffers = new InputRayBufferCollection();
            this.doneRayBuffers = new OutputRayBufferCollection();
            this.started = false;
            if (ctx != null)
            {
                this.cudaContext = ctx;
            }
            else
            {
                this.cudaContext = new NVContext() { Context = new CudaContext(CudaContext.GetMaxGflopsDeviceId()) };
            }
            using (var sr = new StreamReader(@"G:\Git\RayDen\CudaMegaRay\x64\Release\Intersection.cu.ptx"))
            {
                intersectKernel = cudaContext.Context.LoadKernelPTX(sr.BaseStream, "Intersect");
            }

            this.rays = new CudaDeviceVariable<RayData>(RayBuffer.RayBufferSize);
            this.hits = new CudaDeviceVariable<RayHit>(RayBuffer.RayBufferSize);
            verts = scene.Vertices.ToArray();
            tris=scene.Triangles.Select(i => i.GetInfo()).ToArray();

            if (GlobalConfiguration.Instance.UseSceneCaching && scene.Cache != null)
            {
                bvh = scene.Cache.BvhData;
                nodesCount = scene.Cache.BvhData.Length;
            }
            else
            {
                var da = new BvhDataAdapter(scene);
                var treeData = da.BuildData();
                bvh = treeData;
                nodesCount = treeData.Length;

            }

            Tracer.TraceLine("BVH Data Size {0:F3} MBytes", (nodesCount * 32f) / (1024f * 1024f));
        }
Exemplo n.º 24
0
        public override void InitPath(IPathProcessor buffer)
        {
            base.InitPath(buffer);
            this.scene = pathIntegrator.Scene;

            if (Vertices == null)
            {
                Vertices = new PathVertex[scene.MaxPathDepth * 3];
                Xvertices = new PathVertex[scene.MaxPathDepth * 3];
            }
            this.pathDensity = 1.0f;
            this.Radiance = new RgbSpectrum(0f);
            this.Throughput = new RgbSpectrum(1f);
            this.PathState = PathTracerPathState.EyeVertex;
            if (!mutate)
            {
                this.Sample = pathIntegrator.Sampler.GetSample(this.Sample);
                pathIntegrator.Scene.Camera.GetRay(Sample.imageX, Sample.imageY, out this.PathRay);
                pathStart = PathRay.Org;
                XRadiance = new RgbSpectrum();
                xPathDensity = 1.0f;
            }
            else
            {
                PathRay.Org = pathStart;
                PathRay.Dir = -Vertices[0].Wo;
                this.BackupPath();
                this.MutatePath();
                mutationCount++;
                if (mutationCount > MaxMutations)
                {
                    this.mutate = false;
                    this.mutationCount = 0;
                    this.InitPath(buffer);
                }
            }
            this.RayIndex = -1;
            this.depth = 0;
            this.bsdfEvent = BsdfEvent.Specular;
            this.prevEvent = BsdfEvent.None;
            shadowRayEvent = BsdfEvent.None;
        }
Exemplo n.º 25
0
        public ClIntersectionDevice(RayEngineScene scene, bool lowLatency, int index)
            : base(scene) {
            wallclock = new Stopwatch();
            this.todoRayBuffers = new ConcurrentQueue<RayBuffer>();
            this.doneRayBuffers = new ConcurrentQueue<RayBuffer>();
            this.started = false;
            clContext = new ClDeviceContext() { KernelSrc = Kernels.PbrtBVHKernel };
            clContext.Initialize();
            clContext.SetupDevice("Intersect");

            var rayBufferSize = lowLatency ? (RayBuffer.RayBufferSize / 8) : RayBuffer.RayBufferSize;
            var sceneVertices = scene.Vertices.ToArray();
            var sceneTriangles = scene.Triangles.ToArray();
            Tracer.TraceLine("Vertices Data Size {0:F3} MBytes", (sceneVertices.Length * 12f) / (1024f * 1024f));
            Tracer.TraceLine("Indexes Data Size {0:F3} MBytes", (sceneTriangles.Length * 12f) / (1024f * 1024f));
            var da = new BvhDataAdapter(scene);
            var st = DateTime.UtcNow;
            TriangleDataInfo[] triData = null;
            var treeData = da.BuildLData(out triData);
            //scene.Triangles = triData.ToList();
            var dc = treeData.Count(item => item.IsLeaf);
            Tracer.TraceLine("Bvh Leaf nodes {0}", dc);
            verts = new ComputeBuffer<Point>(clContext.context, ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.CopyHostPointer, sceneVertices);
            tris = new ComputeBuffer<TriangleInfo>(clContext.context, ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.CopyHostPointer, triData.Select(item=>item.GetInfo()).ToArray());

          
            
            Tracer.TraceLine("BVH Data Size {0:F3} MBytes" ,(treeData.Length*32f) / (1024f*1024f));
            tree = new ComputeBuffer<LNode>(clContext.context, ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.CopyHostPointer, treeData);
            rays = new ComputeBuffer<RayData>(clContext.context, ComputeMemoryFlags.ReadOnly, rayBufferSize);
            rayHits = new ComputeBuffer<RayHit>(clContext.context, ComputeMemoryFlags.WriteOnly, rayBufferSize);
            Tracer.TraceLine("Bvh Build and Load Time {0}", DateTime.UtcNow - st);

            clContext.kernel.SetMemoryArgument(0, rays);
            clContext.kernel.SetMemoryArgument(1, rayHits);
            clContext.kernel.SetMemoryArgument(2, verts);
            clContext.kernel.SetMemoryArgument(3, tris);
            clContext.kernel.SetValueArgument(4, (uint)tris.Count);
            clContext.kernel.SetValueArgument(5, (uint)tree.Count);
            clContext.kernel.SetMemoryArgument(6, tree);
        }
Exemplo n.º 26
0
        public override void InitPath(IPathProcessor buffer)
        {
            base.InitPath(buffer);
            this.scene = pathIntegrator.Scene;
            this.Radiance = new RgbSpectrum(0f);
            this.Throughput = new RgbSpectrum(1f);
            this.PathState = PathTracerPathState.EyeVertex;
            if (this.secRays == null)
            {
                this.secRays = new ShadowRayInfo[scene.ShadowRaysPerSample];
                continueRays = new ShadowRayInfo[scene.ShadowRaysPerSample];
            }
            if (paths == null)
            {
                paths = new List<PathInfo>();
            }
            if (CurrentVertices == null)
            {
                CurrentVertices = new List<PathVertex>();
            }
            else
            {
                CurrentVertices.Clear();
            }

            contCount = 0;
            this.Sample = pathIntegrator.Sampler.GetSample(this.Sample);

            pathIntegrator.Scene.Camera.GetRay(Sample.imageX, Sample.imageY, out this.PathRay);
            this.EyeSample = new CameraSample()
            {
                imageX = (float)Sample.imageX,
                imageY = (float)Sample.imageY,
                EyeRay = this.PathRay
            };
            this.RayIndex = -1;
            this.pathWeight = 1.0f;
            this.tracedShadowRayCount = 0;
            this.depth = 0;
            this.specularBounce = true;
        }
        public override void SetScene(IRayEngineScene secn)
        {

            Tracer.TraceLine("OptixIntersectionDevice  -  Initializing Optix");
            this.scene = (RayEngineScene)secn;
            this.vertices = scene.Vertices.ToFloatList().ToArray();

             indices =
                    scene.Triangles.ToList()
                         .SelectMany(tri => new []
                             {
                                 tri.v0.VertexIndex,
                                 tri.v1.VertexIndex,
                                 tri.v2.VertexIndex
                             })
                         .ToArray();
            if (trav == null)
                trav = new OptixPrime(Context, QueryType.ClosestHit, RayFormat.OriginDirectionMinMaxInterleaved, TriFormat.Mesh, TraversalOutput.Normal, InitOptions.GpuOnly);

            trav.SetTriangles(indices, vertices);
        }
Exemplo n.º 28
0
        public override void InitPath(IPathProcessor buffer)
        {
            base.InitPath(buffer);
            this.scene = pathIntegrator.Scene;
            this.Radiance = new RgbSpectrum(0f);
            this.Throughput = new RgbSpectrum(1f);
            this.PathState = PathTracerPathState.EyeVertex;
            this.secRays = new ShadowRayInfo[scene.ShadowRayCount];
            this.sampler = (MarkovChainSampler)pathIntegrator.Sampler;

            this.Sample = this.sampler.EvalNextSample(this.Sample, xImportance);
            IRay ray;
            pathIntegrator.Scene.Camera.GetRay(Sample.imageX, Sample.imageY, out ray);
            this.PathRay = (RayData)ray;
            this.RayIndex = -1;
            this.pathWeight = 1.0f;

            this.tracedShadowRayCount = 0;
            this.depth = 0;
            this.specularBounce = true;
        }
Exemplo n.º 29
0
 public override void InitPath(PathBufferBase buffer)
 {
     base.InitPath(buffer);
     this.scene = buffer.Scene;
     this.Radiance = new RgbSpectrum(0f);
     this.Throughput = new RgbSpectrum(1f);
     this.PathState = GenericPathSamplerState.Initialized;
     //vertices = new PathVertex[scene.MaxPathDepth * 2];
     this.Sample = buffer.Sampler.GetSample();
     IRay ray;
     buffer.Scene.Camera.GetRay(Sample.imageX, Sample.imageY, out ray);
     currentVertice = 0;
     vertices[currentVertice] = new ObserverPathElement() { CameraSample = new CameraSample() { EyeRay = (RayData)ray, imageX = Sample.imageX, imageY = Sample.imageY } };
     currentVertice++;
     this.PathRay = (RayData)ray;
     this.RayIndex = -1;
     this.pathWeight = 1.0f;
     this.depth = 0;
     this.verticesCount = 0;
     this.specularBounce = true;
 }
Exemplo n.º 30
0
        public TriangleLight(RayEngineScene sc, int triIndex, ITriangleMesh mesh, RgbSpectrum gain = new RgbSpectrum())
            : this(sc, string.Empty, gain)
        {
            Gain = (RgbSpectrumInfo)gain;

            triangleIndex = triIndex;

            this.Owner = mesh;


            //Configuration.Instance.Get("Integrator.ComputeNormals", false);
            //Configuration.Instance.Get("Integrator.InverseLightNormals", false);

            var multiplicator = normalInverse ? -1f : 1f;
            this.TriangleNormal = multiplicator * ((computeNormal || !mesh.HasNormals) ? scene.Triangles[triangleIndex].ComputeNormal(scene.Vertices)
                : (Normal)scene.SceneGeometry.Normals[Math.Min(scene.SceneGeometry.Normals.Length - 1, triIndex)]);
            this.area = Math.Max(scene.Triangles[triangleIndex].AreaV(scene.Vertices), 0.00001f);
            Assert.IsNotNaN(this.TriangleNormal.x);
            Assert.IsTrue(this.area > 0f);
            lightSpectra = GlobalConfiguration.Instance.SpectralRendering ? (ISpectrum)spectra : gain;

        }