public MegarayIntersectionDevice(RayEngineScene scene, NVContext ctx) { this.scene = scene; wallclock = new Stopwatch(); this.todoRayBuffers = new InputRayBufferCollection<RayBuffer>(); this.doneRayBuffers = new OutputRayBufferCollection<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(@"H:\Git\RayDen\CudaMegaRay\x64\Release\MegarayKernels.cu.ptx")) { intersectKernel = cudaContext.Context.LoadKernelPTX(sr.BaseStream, "Intersect"); } this.rays = new CudaDeviceVariable<RayRecord>(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)); }
public void SetScene(IRayEngineScene scn) { Tracer.TraceLine("Setting scene"); this.scene = (RayEngineScene)scn; 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; } }